ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_connect.c
Revision: 2345
Committed: Wed Jul 3 18:17:39 2013 UTC (13 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 8920 byte(s)
Log Message:
- White-space commit / style corrections

File Contents

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

Properties

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