ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_connect.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_connect.c
File size: 8829 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_connect.c: Connects to a remote IRC server.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "irc_string.h"
30     #include "numeric.h"
31     #include "fdlist.h"
32     #include "s_bsd.h"
33     #include "s_conf.h"
34     #include "s_log.h"
35     #include "s_serv.h"
36     #include "send.h"
37     #include "msg.h"
38     #include "parse.h"
39     #include "hash.h"
40     #include "modules.h"
41    
42 michael 971 static void mo_connect(struct Client *, struct Client *, int, char *[]);
43     static void ms_connect(struct Client *, struct Client *, int, char *[]);
44 adx 30
45     struct Message connect_msgtab = {
46 michael 1178 "CONNECT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
47 michael 971 { m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore }
48 adx 30 };
49    
50     void
51     _modinit(void)
52     {
53     mod_add_cmd(&connect_msgtab);
54     }
55    
56     void
57     _moddeinit(void)
58     {
59     mod_del_cmd(&connect_msgtab);
60     }
61    
62 knight 31 const char *_version = "$Revision$";
63 adx 30
64     /*
65     * mo_connect - CONNECT command handler
66     *
67     * Added by Jto 11 Feb 1989
68     *
69     * m_connect
70     * parv[0] = sender prefix
71     * parv[1] = servername
72     * parv[2] = port number
73     * parv[3] = remote server
74     */
75     static void
76 michael 971 mo_connect(struct Client *client_p, struct Client *source_p,
77     int parc, char *parv[])
78 adx 30 {
79     int port;
80     int tmpport;
81     struct ConfItem *conf = NULL;
82     struct AccessItem *aconf = NULL;
83 michael 971 const struct Client *target_p = NULL;
84 adx 30
85 michael 971 if (EmptyString(parv[1]))
86 adx 30 {
87 michael 971 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
88     me.name, source_p->name, "CONNECT");
89 adx 30 return;
90     }
91    
92 michael 971 if (parc > 3)
93     {
94     if (!IsOperRemote(source_p))
95     {
96     sendto_one(source_p, form_str(ERR_NOPRIVS),
97     me.name, source_p->name, "connect");
98     return;
99     }
100 adx 30
101 michael 971 if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3,
102     parc, parv) != HUNTED_ISME)
103     return;
104 adx 30 }
105    
106 michael 1169 if ((target_p = hash_find_server(parv[1])))
107 adx 30 {
108     sendto_one(source_p,
109     ":%s NOTICE %s :Connect: Server %s already exists from %s.",
110     me.name, source_p->name, parv[1], target_p->from->name);
111     return;
112     }
113    
114     /*
115     * try to find the name, then host, if both fail notify ops and bail
116     */
117     if ((conf = find_matching_name_conf(SERVER_TYPE,
118     parv[1], NULL, NULL, 0)) != NULL)
119     aconf = (struct AccessItem *)map_to_conf(conf);
120     else if ((conf = find_matching_name_conf(SERVER_TYPE,
121     NULL, NULL, parv[1], 0)) != NULL)
122     aconf = (struct AccessItem *)map_to_conf(conf);
123    
124 michael 971 if (conf == NULL || aconf == NULL)
125 adx 30 {
126     sendto_one(source_p,
127     ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
128     me.name, source_p->name, parv[1]);
129     return;
130     }
131 michael 971
132 adx 30 /* Get port number from user, if given. If not specified,
133     * use the default form configuration structure. If missing
134     * from there, then use the precompiled default.
135     */
136     tmpport = port = aconf->port;
137    
138     if (parc > 2 && !EmptyString(parv[2]))
139     {
140     if ((port = atoi(parv[2])) <= 0)
141     {
142     sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
143     me.name, source_p->name);
144     return;
145     }
146     }
147     else if (port <= 0 && (port = PORTNUM) <= 0)
148     {
149     sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
150     me.name, source_p->name);
151     return;
152     }
153    
154     if (find_servconn_in_progress(conf->name))
155     {
156     sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
157     "is already in progress.", me.name, source_p->name, conf->name);
158     return;
159     }
160    
161     /*
162     * Notify all operators about remote connect requests
163     */
164     ilog(L_TRACE, "CONNECT From %s : %s %s",
165     source_p->name, parv[1], parv[2] ? parv[2] : "");
166    
167     aconf->port = port;
168    
169     /* at this point we should be calling connect_server with a valid
170     * C:line and a valid port in the C:line
171     */
172     if (serv_connect(aconf, source_p))
173     {
174     if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
175     sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
176     me.name, source_p->name, aconf->host,
177     conf->name, aconf->port);
178     else
179     sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
180     me.name, source_p->name, conf->name, aconf->port);
181     }
182     else
183     {
184     sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
185     me.name, source_p->name, conf->name, aconf->port);
186     }
187    
188     /* client is either connecting with all the data it needs or has been
189     * destroyed
190     */
191     aconf->port = tmpport;
192     }
193    
194     /*
195     * ms_connect - CONNECT command handler
196     *
197     * Added by Jto 11 Feb 1989
198     *
199     * m_connect
200     * parv[0] = sender prefix
201     * parv[1] = servername
202     * parv[2] = port number
203     * parv[3] = remote server
204     */
205     static void
206     ms_connect(struct Client *client_p, struct Client *source_p,
207     int parc, char *parv[])
208     {
209     int port;
210     int tmpport;
211     struct ConfItem *conf = NULL;
212     struct AccessItem *aconf = NULL;
213 michael 971 const struct Client *target_p = NULL;
214 adx 30
215     if (hunt_server(client_p, source_p,
216     ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
217     return;
218    
219     if (*parv[1] == '\0')
220     {
221     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
222     me.name, source_p->name, "CONNECT");
223     return;
224     }
225    
226 michael 1169 if ((target_p = hash_find_server(parv[1])))
227 adx 30 {
228     sendto_one(source_p,
229     ":%s NOTICE %s :Connect: Server %s already exists from %s.",
230     me.name, source_p->name, parv[1], target_p->from->name);
231     return;
232     }
233    
234     /*
235     * try to find the name, then host, if both fail notify ops and bail
236     */
237     if ((conf = find_matching_name_conf(SERVER_TYPE,
238     parv[1], NULL, NULL, 0)) != NULL)
239 michael 971 aconf = map_to_conf(conf);
240 adx 30 else if ((conf = find_matching_name_conf(SERVER_TYPE,
241     NULL, NULL, parv[1], 0)) != NULL)
242 michael 971 aconf = map_to_conf(conf);
243 adx 30
244 michael 971 if (conf == NULL || aconf == NULL)
245 adx 30 {
246     sendto_one(source_p,
247     ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
248     me.name, source_p->name, parv[1]);
249     return;
250     }
251    
252     /* Get port number from user, if given. If not specified,
253     * use the default form configuration structure. If missing
254     * from there, then use the precompiled default.
255     */
256     tmpport = port = aconf->port;
257    
258     if (parc > 2 && !EmptyString(parv[2]))
259     {
260     port = atoi(parv[2]);
261    
262     /* if someone sends port 0, and we have a config port.. use it */
263     if (port == 0 && aconf->port)
264     port = aconf->port;
265     else if (port <= 0)
266     {
267     sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
268     me.name, source_p->name);
269     return;
270     }
271     }
272     else if (port <= 0 && (port = PORTNUM) <= 0)
273     {
274     sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
275     me.name, source_p->name);
276     return;
277     }
278    
279     if (find_servconn_in_progress(conf->name))
280     {
281     sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
282     "is already in progress.", me.name, source_p->name, conf->name);
283     return;
284     }
285    
286     /*
287     * Notify all operators about remote connect requests
288     */
289     sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
290     parv[1], port, source_p->name);
291 michael 885 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
292 adx 30 ":%s WALLOPS :Remote CONNECT %s %d from %s",
293     me.name, parv[1], port, source_p->name);
294    
295     ilog(L_TRACE, "CONNECT From %s : %s %d",
296     source_p->name, parv[1], port);
297    
298     aconf->port = port;
299    
300 michael 885 /*
301     * At this point we should be calling connect_server with a valid
302 adx 30 * C:line and a valid port in the C:line
303     */
304     if (serv_connect(aconf, source_p))
305     sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
306     me.name, source_p->name, conf->name, aconf->port);
307     else
308     sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
309     me.name, source_p->name, conf->name, aconf->port);
310 michael 885 /*
311     * Client is either connecting with all the data it needs or has been
312 adx 30 * destroyed
313     */
314     aconf->port = tmpport;
315     }
316    

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision