/[svn]/ircd-hybrid-7.2/modules/m_connect.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_connect.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 971 - (show annotations)
Sun Aug 2 23:27:42 2009 UTC (10 years, 3 months ago) by michael
File MIME type: text/x-chdr
File size: 8843 byte(s)
- cleanup m_connect() while reviewing: remove useless MyConnect() test
  in mo_connect().
- Fix possible core in mo_connect() in case if there is a ConfItem that doesn't
  have an AccessItem mapped.

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26