ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_connect.c
Revision: 1834
Committed: Fri Apr 19 19:50:27 2013 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 8695 byte(s)
Log Message:
- Revert to -r1831

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 "client.h"
27     #include "ircd.h"
28     #include "irc_string.h"
29     #include "numeric.h"
30     #include "fdlist.h"
31     #include "s_bsd.h"
32 michael 1309 #include "conf.h"
33     #include "log.h"
34 adx 30 #include "s_serv.h"
35     #include "send.h"
36     #include "parse.h"
37     #include "hash.h"
38     #include "modules.h"
39    
40    
41     /*
42     * mo_connect - CONNECT command handler
43     *
44     * Added by Jto 11 Feb 1989
45     *
46     * m_connect
47     * parv[0] = sender prefix
48     * parv[1] = servername
49     * parv[2] = port number
50     * parv[3] = remote server
51     */
52     static void
53 michael 971 mo_connect(struct Client *client_p, struct Client *source_p,
54     int parc, char *parv[])
55 adx 30 {
56     int port;
57     int tmpport;
58 michael 1632 struct MaskItem *conf = NULL;
59 michael 971 const struct Client *target_p = NULL;
60 adx 30
61 michael 971 if (EmptyString(parv[1]))
62 adx 30 {
63 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
64 michael 971 me.name, source_p->name, "CONNECT");
65 adx 30 return;
66     }
67    
68 michael 971 if (parc > 3)
69     {
70 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_REMOTE))
71 michael 971 {
72 michael 1834 sendto_one(source_p, form_str(ERR_NOPRIVS),
73 michael 971 me.name, source_p->name, "connect");
74     return;
75     }
76 adx 30
77 michael 971 if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3,
78     parc, parv) != HUNTED_ISME)
79     return;
80 adx 30 }
81    
82 michael 1169 if ((target_p = hash_find_server(parv[1])))
83 adx 30 {
84     sendto_one(source_p,
85     ":%s NOTICE %s :Connect: Server %s already exists from %s.",
86     me.name, source_p->name, parv[1], target_p->from->name);
87     return;
88     }
89    
90     /*
91     * try to find the name, then host, if both fail notify ops and bail
92     */
93 michael 1636 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)))
94 adx 30 {
95 michael 1636 if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
96     {
97     sendto_one(source_p,
98     ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
99     me.name, source_p->name, parv[1]);
100     return;
101     }
102 adx 30 }
103 michael 971
104 adx 30 /* Get port number from user, if given. If not specified,
105     * use the default form configuration structure. If missing
106     * from there, then use the precompiled default.
107     */
108 michael 1632 tmpport = port = conf->port;
109 adx 30
110     if (parc > 2 && !EmptyString(parv[2]))
111     {
112     if ((port = atoi(parv[2])) <= 0)
113     {
114     sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
115     me.name, source_p->name);
116     return;
117     }
118     }
119     else if (port <= 0 && (port = PORTNUM) <= 0)
120     {
121     sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
122     me.name, source_p->name);
123     return;
124     }
125    
126     if (find_servconn_in_progress(conf->name))
127     {
128     sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
129     "is already in progress.", me.name, source_p->name, conf->name);
130     return;
131     }
132    
133     /*
134     * Notify all operators about remote connect requests
135     */
136 michael 1247 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %s",
137 adx 30 source_p->name, parv[1], parv[2] ? parv[2] : "");
138    
139 michael 1632 conf->port = port;
140 adx 30
141     /* at this point we should be calling connect_server with a valid
142     * C:line and a valid port in the C:line
143     */
144 michael 1632 if (serv_connect(conf, source_p))
145 adx 30 {
146 michael 1219 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
147 adx 30 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
148 michael 1632 me.name, source_p->name, conf->host,
149     conf->name, conf->port);
150 adx 30 else
151     sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
152 michael 1632 me.name, source_p->name, conf->name, conf->port);
153 adx 30 }
154     else
155     {
156     sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
157 michael 1632 me.name, source_p->name, conf->name, conf->port);
158 adx 30 }
159    
160     /* client is either connecting with all the data it needs or has been
161     * destroyed
162     */
163 michael 1632 conf->port = tmpport;
164 adx 30 }
165    
166     /*
167     * ms_connect - CONNECT command handler
168     *
169     * Added by Jto 11 Feb 1989
170     *
171     * m_connect
172     * parv[0] = sender prefix
173     * parv[1] = servername
174     * parv[2] = port number
175     * parv[3] = remote server
176     */
177     static void
178     ms_connect(struct Client *client_p, struct Client *source_p,
179     int parc, char *parv[])
180     {
181     int port;
182     int tmpport;
183 michael 1632 struct MaskItem *conf = NULL;
184 michael 971 const struct Client *target_p = NULL;
185 adx 30
186     if (hunt_server(client_p, source_p,
187     ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
188     return;
189    
190 michael 1413 if (EmptyString(parv[1]))
191 adx 30 {
192 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
193 adx 30 me.name, source_p->name, "CONNECT");
194     return;
195     }
196    
197 michael 1169 if ((target_p = hash_find_server(parv[1])))
198 adx 30 {
199     sendto_one(source_p,
200     ":%s NOTICE %s :Connect: Server %s already exists from %s.",
201     me.name, source_p->name, parv[1], target_p->from->name);
202     return;
203     }
204    
205     /*
206     * try to find the name, then host, if both fail notify ops and bail
207     */
208 michael 1636 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)))
209     {
210     if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
211     {
212     sendto_one(source_p,
213     ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
214     me.name, source_p->name, parv[1]);
215     return;
216     }
217 adx 30 }
218    
219     /* Get port number from user, if given. If not specified,
220     * use the default form configuration structure. If missing
221     * from there, then use the precompiled default.
222     */
223 michael 1632 tmpport = port = conf->port;
224 adx 30
225     if (parc > 2 && !EmptyString(parv[2]))
226     {
227     port = atoi(parv[2]);
228    
229     /* if someone sends port 0, and we have a config port.. use it */
230 michael 1632 if (port == 0 && conf->port)
231     port = conf->port;
232 adx 30 else if (port <= 0)
233     {
234     sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
235     me.name, source_p->name);
236     return;
237     }
238     }
239     else if (port <= 0 && (port = PORTNUM) <= 0)
240     {
241     sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
242     me.name, source_p->name);
243     return;
244     }
245    
246     if (find_servconn_in_progress(conf->name))
247     {
248     sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
249     "is already in progress.", me.name, source_p->name, conf->name);
250     return;
251     }
252    
253     /*
254     * Notify all operators about remote connect requests
255     */
256     sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
257     parv[1], port, source_p->name);
258 michael 1474 sendto_server(NULL, NOCAPS, CAP_TS6,
259 adx 30 ":%s WALLOPS :Remote CONNECT %s %d from %s",
260     me.name, parv[1], port, source_p->name);
261 michael 1474 sendto_server(NULL, CAP_TS6, NOCAPS,
262 michael 1463 ":%s WALLOPS :Remote CONNECT %s %d from %s",
263     me.id, parv[1], port, source_p->name);
264 adx 30
265 michael 1247 ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %d",
266 adx 30 source_p->name, parv[1], port);
267    
268 michael 1632 conf->port = port;
269 adx 30
270 michael 885 /*
271     * At this point we should be calling connect_server with a valid
272 adx 30 * C:line and a valid port in the C:line
273     */
274 michael 1632 if (serv_connect(conf, source_p))
275 adx 30 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
276 michael 1632 me.name, source_p->name, conf->name, conf->port);
277 adx 30 else
278     sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
279 michael 1632 me.name, source_p->name, conf->name, conf->port);
280 michael 885 /*
281     * Client is either connecting with all the data it needs or has been
282 adx 30 * destroyed
283     */
284 michael 1632 conf->port = tmpport;
285 adx 30 }
286 michael 1230
287     static struct Message connect_msgtab = {
288     "CONNECT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
289     { m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore }
290     };
291    
292     static void
293     module_init(void)
294     {
295     mod_add_cmd(&connect_msgtab);
296     }
297    
298     static void
299     module_exit(void)
300     {
301     mod_del_cmd(&connect_msgtab);
302     }
303    
304     struct module module_entry = {
305     .node = { NULL, NULL, NULL },
306     .name = NULL,
307     .version = "$Revision$",
308     .handle = NULL,
309     .modinit = module_init,
310     .modexit = module_exit,
311     .flags = 0
312     };

Properties

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