1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_server.c: Introduces a 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 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "client.h" /* client struct */ |
28 |
|
|
#include "event.h" |
29 |
|
|
#include "hash.h" /* add_to_client_hash_table */ |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "ircd.h" /* me */ |
32 |
|
|
#include "numeric.h" /* ERR_xxx */ |
33 |
michael |
1309 |
#include "conf.h" /* struct AccessItem */ |
34 |
|
|
#include "log.h" /* log level defines */ |
35 |
michael |
1118 |
#include "s_serv.h" /* server_estab, check_server */ |
36 |
|
|
#include "s_user.h" |
37 |
adx |
30 |
#include "send.h" /* sendto_one */ |
38 |
|
|
#include "parse.h" |
39 |
|
|
#include "modules.h" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
static void set_server_gecos(struct Client *, char *); |
43 |
|
|
|
44 |
|
|
/* mr_server() |
45 |
|
|
* parv[0] = sender prefix |
46 |
|
|
* parv[1] = servername |
47 |
|
|
* parv[2] = serverinfo/hopcount |
48 |
|
|
* parv[3] = serverinfo |
49 |
|
|
*/ |
50 |
|
|
static void |
51 |
|
|
mr_server(struct Client *client_p, struct Client *source_p, |
52 |
|
|
int parc, char *parv[]) |
53 |
|
|
{ |
54 |
|
|
char info[REALLEN + 1]; |
55 |
|
|
char *name; |
56 |
|
|
struct Client *target_p; |
57 |
|
|
int hop; |
58 |
|
|
|
59 |
michael |
1178 |
if (EmptyString(parv[3])) |
60 |
adx |
30 |
{ |
61 |
|
|
sendto_one(client_p, "ERROR :No servername"); |
62 |
|
|
exit_client(client_p, client_p, "Wrong number of args"); |
63 |
|
|
return; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
name = parv[1]; |
67 |
|
|
hop = atoi(parv[2]); |
68 |
|
|
strlcpy(info, parv[3], sizeof(info)); |
69 |
|
|
|
70 |
michael |
1118 |
/* |
71 |
|
|
* Reject a direct nonTS server connection if we're TS_ONLY -orabidoo |
72 |
adx |
30 |
*/ |
73 |
|
|
if (!DoesTS(client_p)) |
74 |
|
|
{ |
75 |
michael |
1118 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
76 |
|
|
"Unauthorized server connection attempt from %s: Non-TS server " |
77 |
|
|
"for server %s", get_client_name(client_p, HIDE_IP), name); |
78 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
79 |
|
|
"Unauthorized server connection attempt from %s: Non-TS server " |
80 |
|
|
"for server %s", get_client_name(client_p, MASK_IP), name); |
81 |
adx |
30 |
exit_client(client_p, client_p, "Non-TS server"); |
82 |
|
|
return; |
83 |
|
|
} |
84 |
|
|
|
85 |
michael |
1118 |
if (!valid_servname(name)) |
86 |
adx |
30 |
{ |
87 |
michael |
1118 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
88 |
|
|
"Unauthorized server connection attempt from %s: Bogus server name " |
89 |
|
|
"for server %s", get_client_name(client_p, HIDE_IP), name); |
90 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
91 |
|
|
"Unauthorized server connection attempt from %s: Bogus server name " |
92 |
|
|
"for server %s", get_client_name(client_p, MASK_IP), name); |
93 |
adx |
30 |
exit_client(client_p, client_p, "Bogus server name"); |
94 |
|
|
return; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* Now we just have to call check_server and everything should |
98 |
|
|
* be check for us... -A1kmm. |
99 |
|
|
*/ |
100 |
michael |
1302 |
switch (check_server(name, client_p)) |
101 |
adx |
30 |
{ |
102 |
|
|
case -1: |
103 |
|
|
if (ConfigFileEntry.warn_no_nline) |
104 |
|
|
{ |
105 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
106 |
|
|
"Unauthorized server connection attempt from %s: No entry for " |
107 |
|
|
"servername %s", get_client_name(client_p, HIDE_IP), name); |
108 |
|
|
|
109 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
110 |
|
|
"Unauthorized server connection attempt from %s: No entry for " |
111 |
|
|
"servername %s", get_client_name(client_p, MASK_IP), name); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
exit_client(client_p, client_p, "Invalid servername."); |
115 |
|
|
return; |
116 |
|
|
/* NOT REACHED */ |
117 |
|
|
break; |
118 |
|
|
|
119 |
|
|
case -2: |
120 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
121 |
|
|
"Unauthorized server connection attempt from %s: Bad password " |
122 |
|
|
"for server %s", get_client_name(client_p, HIDE_IP), name); |
123 |
|
|
|
124 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
125 |
|
|
"Unauthorized server connection attempt from %s: Bad password " |
126 |
|
|
"for server %s", get_client_name(client_p, MASK_IP), name); |
127 |
|
|
|
128 |
|
|
exit_client(client_p, client_p, "Invalid password."); |
129 |
|
|
return; |
130 |
|
|
/* NOT REACHED */ |
131 |
|
|
break; |
132 |
|
|
|
133 |
|
|
case -3: |
134 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
135 |
|
|
"Unauthorized server connection attempt from %s: Invalid host " |
136 |
|
|
"for server %s", get_client_name(client_p, HIDE_IP), name); |
137 |
|
|
|
138 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
139 |
|
|
"Unauthorized server connection attempt from %s: Invalid host " |
140 |
|
|
"for server %s", get_client_name(client_p, MASK_IP), name); |
141 |
|
|
|
142 |
|
|
exit_client(client_p, client_p, "Invalid host."); |
143 |
|
|
return; |
144 |
|
|
/* NOT REACHED */ |
145 |
|
|
break; |
146 |
|
|
|
147 |
|
|
/* servername is > HOSTLEN */ |
148 |
|
|
case -4: |
149 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
150 |
|
|
"Invalid servername %s from %s", |
151 |
|
|
name, get_client_name(client_p, HIDE_IP)); |
152 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
153 |
|
|
"Invalid servername %s from %s", |
154 |
|
|
name, get_client_name(client_p, MASK_IP)); |
155 |
|
|
|
156 |
|
|
exit_client(client_p, client_p, "Invalid servername."); |
157 |
|
|
return; |
158 |
|
|
/* NOT REACHED */ |
159 |
|
|
break; |
160 |
|
|
} |
161 |
|
|
|
162 |
michael |
1115 |
if ((client_p->id[0] && (target_p = hash_find_id(client_p->id))) |
163 |
michael |
1169 |
|| (target_p = hash_find_server(name))) |
164 |
adx |
30 |
{ |
165 |
|
|
/* This link is trying feed me a server that I already have |
166 |
|
|
* access through another path -- multiple paths not accepted |
167 |
|
|
* currently, kill this link immediately!! |
168 |
|
|
* |
169 |
|
|
* Rather than KILL the link which introduced it, KILL the |
170 |
|
|
* youngest of the two links. -avalon |
171 |
|
|
* |
172 |
|
|
* Definitely don't do that here. This is from an unregistered |
173 |
|
|
* connect - A1kmm. |
174 |
|
|
*/ |
175 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
176 |
|
|
"Attempt to re-introduce server %s SID %s from %s", |
177 |
|
|
name, client_p->id, |
178 |
|
|
get_client_name(client_p, HIDE_IP)); |
179 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
180 |
|
|
"Attempt to re-introduce server %s SID %s from %s", |
181 |
|
|
name, client_p->id, |
182 |
|
|
get_client_name(client_p, MASK_IP)); |
183 |
|
|
sendto_one(client_p, "ERROR :Server ID already exists."); |
184 |
|
|
exit_client(client_p, client_p, "Server ID Exists"); |
185 |
|
|
return; |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
/* XXX If somehow there is a connect in progress and |
189 |
|
|
* a connect comes in with same name toss the pending one, |
190 |
|
|
* but only if it's not the same client! - Dianora |
191 |
|
|
*/ |
192 |
|
|
if ((target_p = find_servconn_in_progress(name))) |
193 |
|
|
if (target_p != client_p) |
194 |
|
|
exit_client(target_p, &me, "Overridden"); |
195 |
|
|
|
196 |
|
|
/* if we are connecting (Handshake), we already have the name from the |
197 |
|
|
* connect{} block in client_p->name |
198 |
|
|
*/ |
199 |
|
|
strlcpy(client_p->name, name, sizeof(client_p->name)); |
200 |
|
|
set_server_gecos(client_p, info); |
201 |
|
|
client_p->hopcount = hop; |
202 |
|
|
server_estab(client_p); |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
/* ms_server() |
206 |
|
|
* parv[0] = sender prefix |
207 |
|
|
* parv[1] = servername |
208 |
|
|
* parv[2] = serverinfo/hopcount |
209 |
|
|
* parv[3] = serverinfo |
210 |
|
|
*/ |
211 |
|
|
static void |
212 |
|
|
ms_server(struct Client *client_p, struct Client *source_p, |
213 |
|
|
int parc, char *parv[]) |
214 |
|
|
{ |
215 |
|
|
char info[REALLEN + 1]; |
216 |
|
|
char *name; |
217 |
|
|
struct Client *target_p; |
218 |
|
|
struct ConfItem *conf; |
219 |
|
|
struct MatchItem *match_item; |
220 |
|
|
int hop; |
221 |
|
|
int hlined = 0; |
222 |
|
|
int llined = 0; |
223 |
michael |
1321 |
dlink_node *ptr = NULL; |
224 |
adx |
30 |
|
225 |
|
|
/* Just to be sure -A1kmm. */ |
226 |
|
|
if (!IsServer(source_p)) |
227 |
|
|
return; |
228 |
|
|
|
229 |
michael |
1178 |
if (EmptyString(parv[3])) |
230 |
adx |
30 |
{ |
231 |
|
|
sendto_one(client_p, "ERROR :No servername"); |
232 |
|
|
return; |
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
name = parv[1]; |
236 |
|
|
hop = atoi(parv[2]); |
237 |
|
|
strlcpy(info, parv[3], sizeof(info)); |
238 |
|
|
|
239 |
michael |
1118 |
if (!valid_servname(name)) |
240 |
adx |
30 |
{ |
241 |
michael |
1118 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
242 |
|
|
"Link %s introduced server with bogus server name %s", |
243 |
|
|
get_client_name(client_p, SHOW_IP), name); |
244 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
245 |
|
|
"Link %s introduced server with bogus server name %s", |
246 |
|
|
get_client_name(client_p, MASK_IP), name); |
247 |
|
|
sendto_one(client_p, "ERROR :Bogus server name introduced"); |
248 |
|
|
exit_client(client_p, &me, "Bogus server name intoduced"); |
249 |
|
|
return; |
250 |
|
|
} |
251 |
|
|
|
252 |
michael |
1169 |
if ((target_p = hash_find_server(name))) |
253 |
michael |
1118 |
{ |
254 |
adx |
30 |
/* This link is trying feed me a server that I already have |
255 |
|
|
* access through another path -- multiple paths not accepted |
256 |
|
|
* currently, kill this link immediately!! |
257 |
|
|
* |
258 |
|
|
* Rather than KILL the link which introduced it, KILL the |
259 |
|
|
* youngest of the two links. -avalon |
260 |
|
|
* |
261 |
|
|
* I think that we should exit the link itself, not the introducer, |
262 |
|
|
* and we should always exit the most recently received(i.e. the |
263 |
|
|
* one we are receiving this SERVER for. -A1kmm |
264 |
|
|
* |
265 |
|
|
* You *cant* do this, if you link somewhere, it bursts you a server |
266 |
|
|
* that already exists, then sends you a client burst, you squit the |
267 |
|
|
* server, but you keep getting the burst of clients on a server that |
268 |
|
|
* doesnt exist, although ircd can handle it, its not a realistic |
269 |
|
|
* solution.. --fl_ |
270 |
|
|
*/ |
271 |
|
|
/* It is behind a host-masked server. Completely ignore the |
272 |
|
|
* server message(don't propagate or we will delink from whoever |
273 |
|
|
* we propagate to). -A1kmm |
274 |
|
|
*/ |
275 |
|
|
if (irccmp(target_p->name, name) && target_p->from == client_p) |
276 |
|
|
return; |
277 |
|
|
|
278 |
|
|
sendto_one(client_p, "ERROR :Server %s already exists", name); |
279 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
280 |
|
|
"Link %s cancelled, server %s already exists", |
281 |
|
|
get_client_name(client_p, SHOW_IP), name); |
282 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
283 |
|
|
"Link %s cancelled, server %s already exists", |
284 |
|
|
client_p->name, name); |
285 |
|
|
exit_client(client_p, &me, "Server Exists"); |
286 |
|
|
return; |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
/* XXX If somehow there is a connect in progress and |
290 |
|
|
* a connect comes in with same name toss the pending one, |
291 |
|
|
* but only if it's not the same client! - Dianora |
292 |
|
|
*/ |
293 |
|
|
if ((target_p = find_servconn_in_progress(name))) |
294 |
|
|
if (target_p != client_p) |
295 |
|
|
exit_client(target_p, &me, "Overridden"); |
296 |
|
|
|
297 |
|
|
/* See if the newly found server is behind a guaranteed |
298 |
|
|
* leaf. If so, close the link. |
299 |
|
|
*/ |
300 |
|
|
DLINK_FOREACH(ptr, leaf_items.head) |
301 |
|
|
{ |
302 |
|
|
conf = ptr->data; |
303 |
|
|
|
304 |
|
|
if (match(conf->name, client_p->name)) |
305 |
|
|
{ |
306 |
michael |
1118 |
match_item = map_to_conf(conf); |
307 |
|
|
|
308 |
adx |
30 |
if (match(match_item->host, name)) |
309 |
|
|
llined++; |
310 |
|
|
} |
311 |
|
|
} |
312 |
|
|
|
313 |
|
|
DLINK_FOREACH(ptr, hub_items.head) |
314 |
|
|
{ |
315 |
|
|
conf = ptr->data; |
316 |
|
|
|
317 |
|
|
if (match(conf->name, client_p->name)) |
318 |
|
|
{ |
319 |
michael |
1118 |
match_item = map_to_conf(conf); |
320 |
adx |
30 |
|
321 |
|
|
if (match(match_item->host, name)) |
322 |
|
|
hlined++; |
323 |
|
|
} |
324 |
|
|
} |
325 |
|
|
|
326 |
|
|
/* Ok, this way this works is |
327 |
|
|
* |
328 |
|
|
* A server can have a CONF_HUB allowing it to introduce servers |
329 |
|
|
* behind it. |
330 |
|
|
* |
331 |
|
|
* connect { |
332 |
|
|
* name = "irc.bighub.net"; |
333 |
|
|
* hub_mask="*"; |
334 |
|
|
* ... |
335 |
|
|
* |
336 |
|
|
* That would allow "irc.bighub.net" to introduce anything it wanted.. |
337 |
|
|
* |
338 |
|
|
* However |
339 |
|
|
* |
340 |
|
|
* connect { |
341 |
|
|
* name = "irc.somehub.fi"; |
342 |
|
|
* hub_mask="*"; |
343 |
|
|
* leaf_mask="*.edu"; |
344 |
|
|
*... |
345 |
|
|
* Would allow this server in finland to hub anything but |
346 |
|
|
* .edu's |
347 |
|
|
*/ |
348 |
|
|
|
349 |
michael |
885 |
/* Ok, check client_p can hub the new server */ |
350 |
|
|
if (!hlined) |
351 |
adx |
30 |
{ |
352 |
|
|
/* OOOPs nope can't HUB */ |
353 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, "Non-Hub link %s introduced %s.", |
354 |
|
|
get_client_name(client_p, HIDE_IP), name); |
355 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, "Non-Hub link %s introduced %s.", |
356 |
|
|
get_client_name(client_p, MASK_IP), name); |
357 |
|
|
exit_client(source_p, &me, "No matching hub_mask."); |
358 |
|
|
return; |
359 |
|
|
} |
360 |
|
|
|
361 |
|
|
/* Check for the new server being leafed behind this HUB */ |
362 |
|
|
if (llined) |
363 |
|
|
{ |
364 |
|
|
/* OOOPs nope can't HUB this leaf */ |
365 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
366 |
|
|
"Link %s introduced leafed server %s.", |
367 |
|
|
get_client_name(client_p, HIDE_IP), name); |
368 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
369 |
|
|
"Link %s introduced leafed server %s.", |
370 |
michael |
1118 |
get_client_name(client_p, MASK_IP), name); |
371 |
|
|
/* If it is new, we are probably misconfigured, so split the |
372 |
|
|
* non-hub server introducing this. Otherwise, split the new |
373 |
|
|
* server. -A1kmm. |
374 |
|
|
*/ |
375 |
|
|
/* wastes too much bandwidth, generates too many errors on |
376 |
|
|
* larger networks, dont bother. --fl_ |
377 |
|
|
*/ |
378 |
|
|
exit_client(client_p, &me, "Leafed Server."); |
379 |
|
|
return; |
380 |
adx |
30 |
} |
381 |
|
|
|
382 |
|
|
target_p = make_client(client_p); |
383 |
|
|
make_server(target_p); |
384 |
|
|
target_p->hopcount = hop; |
385 |
michael |
1118 |
target_p->servptr = source_p; |
386 |
adx |
30 |
|
387 |
|
|
strlcpy(target_p->name, name, sizeof(target_p->name)); |
388 |
|
|
|
389 |
|
|
set_server_gecos(target_p, info); |
390 |
|
|
SetServer(target_p); |
391 |
|
|
|
392 |
michael |
1219 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(SERVICE_TYPE, target_p->name, NULL, NULL, 0)) |
393 |
|
|
AddFlag(target_p, FLAGS_SERVICE); |
394 |
michael |
1157 |
|
395 |
michael |
1118 |
dlinkAdd(target_p, &target_p->node, &global_client_list); |
396 |
|
|
dlinkAdd(target_p, make_dlink_node(), &global_serv_list); |
397 |
|
|
dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list); |
398 |
adx |
30 |
|
399 |
|
|
hash_add_client(target_p); |
400 |
|
|
|
401 |
michael |
1239 |
sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s SERVER %s %d :%s%s", |
402 |
|
|
source_p->name, target_p->name, hop + 1, |
403 |
|
|
IsHidden(target_p) ? "(H) " : "", target_p->info); |
404 |
adx |
30 |
|
405 |
|
|
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, |
406 |
michael |
1118 |
"Server %s being introduced by %s", |
407 |
adx |
30 |
target_p->name, source_p->name); |
408 |
|
|
} |
409 |
|
|
|
410 |
|
|
/* ms_sid() |
411 |
|
|
* parv[0] = sender prefix |
412 |
|
|
* parv[1] = servername |
413 |
|
|
* parv[2] = serverinfo/hopcount |
414 |
|
|
* parv[3] = sid of new server |
415 |
|
|
* parv[4] = serverinfo |
416 |
|
|
*/ |
417 |
|
|
static void |
418 |
|
|
ms_sid(struct Client *client_p, struct Client *source_p, |
419 |
|
|
int parc, char *parv[]) |
420 |
|
|
{ |
421 |
|
|
char info[REALLEN + 1]; |
422 |
|
|
struct Client *target_p; |
423 |
|
|
struct ConfItem *conf; |
424 |
|
|
struct MatchItem *match_item; |
425 |
|
|
int hlined = 0; |
426 |
|
|
int llined = 0; |
427 |
michael |
1321 |
dlink_node *ptr = NULL; |
428 |
adx |
30 |
int hop; |
429 |
|
|
|
430 |
|
|
/* Just to be sure -A1kmm. */ |
431 |
|
|
if (!IsServer(source_p)) |
432 |
|
|
return; |
433 |
|
|
|
434 |
michael |
1178 |
if (EmptyString(parv[4])) |
435 |
michael |
1118 |
{ |
436 |
|
|
sendto_one(client_p, "ERROR :No servername"); |
437 |
|
|
return; |
438 |
|
|
} |
439 |
adx |
30 |
|
440 |
michael |
1118 |
hop = atoi(parv[2]); |
441 |
|
|
strlcpy(info, parv[4], sizeof(info)); |
442 |
|
|
|
443 |
|
|
if (!valid_servname(parv[1])) |
444 |
|
|
{ |
445 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
446 |
|
|
"Link %s introduced server with bogus server name %s", |
447 |
|
|
get_client_name(client_p, SHOW_IP), parv[1]); |
448 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
449 |
|
|
"Link %s introduced server with bogus server name %s", |
450 |
|
|
get_client_name(client_p, MASK_IP), parv[1]); |
451 |
|
|
sendto_one(client_p, "ERROR :Bogus server name introduced"); |
452 |
|
|
exit_client(client_p, &me, "Bogus server name intoduced"); |
453 |
|
|
return; |
454 |
|
|
} |
455 |
|
|
|
456 |
|
|
if (!valid_sid(parv[3])) |
457 |
|
|
{ |
458 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
459 |
|
|
"Link %s introduced server with bogus server ID %s", |
460 |
|
|
get_client_name(client_p, SHOW_IP), parv[3]); |
461 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
462 |
|
|
"Link %s introduced server with bogus server ID %s", |
463 |
|
|
get_client_name(client_p, MASK_IP), parv[3]); |
464 |
|
|
sendto_one(client_p, "ERROR :Bogus server ID introduced"); |
465 |
|
|
exit_client(client_p, &me, "Bogus server ID intoduced"); |
466 |
|
|
return; |
467 |
|
|
} |
468 |
|
|
|
469 |
adx |
30 |
/* collision on SID? */ |
470 |
michael |
1118 |
if ((target_p = hash_find_id(parv[3]))) |
471 |
adx |
30 |
{ |
472 |
michael |
1118 |
sendto_one(client_p, "ERROR :SID %s already exists", parv[3]); |
473 |
adx |
30 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
474 |
|
|
"Link %s cancelled, SID %s already exists", |
475 |
michael |
1118 |
get_client_name(client_p, SHOW_IP), parv[3]); |
476 |
adx |
30 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
477 |
|
|
"Link %s cancelled, SID %s already exists", |
478 |
michael |
1118 |
client_p->name, parv[3]); |
479 |
adx |
30 |
exit_client(client_p, &me, "Server Exists"); |
480 |
|
|
return; |
481 |
|
|
} |
482 |
|
|
|
483 |
|
|
/* collision on name? */ |
484 |
michael |
1169 |
if ((target_p = hash_find_server(parv[1]))) |
485 |
adx |
30 |
{ |
486 |
michael |
1118 |
sendto_one(client_p, "ERROR :Server %s already exists", parv[1]); |
487 |
adx |
30 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
488 |
|
|
"Link %s cancelled, server %s already exists", |
489 |
michael |
1118 |
get_client_name(client_p, SHOW_IP), parv[1]); |
490 |
adx |
30 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
491 |
|
|
"Link %s cancelled, server %s already exists", |
492 |
michael |
1118 |
client_p->name, parv[1]); |
493 |
adx |
30 |
exit_client(client_p, &me, "Server Exists"); |
494 |
|
|
return; |
495 |
|
|
} |
496 |
|
|
|
497 |
|
|
/* XXX If somehow there is a connect in progress and |
498 |
|
|
* a connect comes in with same name toss the pending one, |
499 |
|
|
* but only if it's not the same client! - Dianora |
500 |
|
|
*/ |
501 |
michael |
1118 |
if ((target_p = find_servconn_in_progress(parv[1]))) |
502 |
adx |
30 |
if (target_p != client_p) |
503 |
|
|
exit_client(target_p, &me, "Overridden"); |
504 |
|
|
|
505 |
|
|
/* See if the newly found server is behind a guaranteed |
506 |
|
|
* leaf. If so, close the link. |
507 |
|
|
*/ |
508 |
|
|
DLINK_FOREACH(ptr, leaf_items.head) |
509 |
|
|
{ |
510 |
|
|
conf = ptr->data; |
511 |
|
|
|
512 |
|
|
if (match(conf->name, client_p->name)) |
513 |
|
|
{ |
514 |
michael |
1118 |
match_item = map_to_conf(conf); |
515 |
|
|
|
516 |
|
|
if (match(match_item->host, parv[1])) |
517 |
adx |
30 |
llined++; |
518 |
|
|
} |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
DLINK_FOREACH(ptr, hub_items.head) |
522 |
|
|
{ |
523 |
|
|
conf = ptr->data; |
524 |
|
|
|
525 |
|
|
if (match(conf->name, client_p->name)) |
526 |
|
|
{ |
527 |
michael |
1118 |
match_item = map_to_conf(conf); |
528 |
adx |
30 |
|
529 |
michael |
1118 |
if (match(match_item->host, parv[1])) |
530 |
adx |
30 |
hlined++; |
531 |
|
|
} |
532 |
|
|
} |
533 |
|
|
|
534 |
|
|
/* Ok, this way this works is |
535 |
|
|
* |
536 |
|
|
* A server can have a CONF_HUB allowing it to introduce servers |
537 |
|
|
* behind it. |
538 |
|
|
* |
539 |
|
|
* connect { |
540 |
|
|
* name = "irc.bighub.net"; |
541 |
|
|
* hub_mask="*"; |
542 |
|
|
* ... |
543 |
|
|
* |
544 |
|
|
* That would allow "irc.bighub.net" to introduce anything it wanted.. |
545 |
|
|
* |
546 |
|
|
* However |
547 |
|
|
* |
548 |
|
|
* connect { |
549 |
|
|
* name = "irc.somehub.fi"; |
550 |
|
|
* hub_mask="*"; |
551 |
|
|
* leaf_mask="*.edu"; |
552 |
|
|
*... |
553 |
|
|
* Would allow this server in finland to hub anything but |
554 |
|
|
* .edu's |
555 |
|
|
*/ |
556 |
|
|
|
557 |
|
|
/* Ok, check client_p can hub the new server, and make sure it's not a LL */ |
558 |
michael |
885 |
if (!hlined) |
559 |
adx |
30 |
{ |
560 |
|
|
/* OOOPs nope can't HUB */ |
561 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, "Non-Hub link %s introduced %s.", |
562 |
michael |
1118 |
get_client_name(client_p, SHOW_IP), parv[1]); |
563 |
adx |
30 |
sendto_realops_flags(UMODE_ALL, L_OPER, "Non-Hub link %s introduced %s.", |
564 |
michael |
1118 |
get_client_name(client_p, MASK_IP), parv[1]); |
565 |
adx |
30 |
exit_client(source_p, &me, "No matching hub_mask."); |
566 |
|
|
return; |
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
/* Check for the new server being leafed behind this HUB */ |
570 |
|
|
if (llined) |
571 |
|
|
{ |
572 |
|
|
/* OOOPs nope can't HUB this leaf */ |
573 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
574 |
|
|
"Link %s introduced leafed server %s.", |
575 |
michael |
1118 |
get_client_name(client_p, SHOW_IP), parv[1]); |
576 |
adx |
30 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
577 |
|
|
"Link %s introduced leafed server %s.", |
578 |
michael |
1118 |
get_client_name(client_p, MASK_IP), parv[1]); |
579 |
adx |
30 |
exit_client(client_p, &me, "Leafed Server."); |
580 |
|
|
return; |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
target_p = make_client(client_p); |
584 |
|
|
make_server(target_p); |
585 |
|
|
target_p->hopcount = hop; |
586 |
michael |
1118 |
target_p->servptr = source_p; |
587 |
adx |
30 |
|
588 |
michael |
1118 |
strlcpy(target_p->name, parv[1], sizeof(target_p->name)); |
589 |
|
|
strlcpy(target_p->id, parv[3], sizeof(target_p->id)); |
590 |
adx |
30 |
|
591 |
|
|
set_server_gecos(target_p, info); |
592 |
|
|
SetServer(target_p); |
593 |
|
|
|
594 |
michael |
1219 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(SERVICE_TYPE, target_p->name, NULL, NULL, 0)) |
595 |
|
|
AddFlag(target_p, FLAGS_SERVICE); |
596 |
michael |
1157 |
|
597 |
michael |
1118 |
dlinkAdd(target_p, &target_p->node, &global_client_list); |
598 |
|
|
dlinkAdd(target_p, make_dlink_node(), &global_serv_list); |
599 |
|
|
dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list); |
600 |
adx |
30 |
|
601 |
|
|
hash_add_client(target_p); |
602 |
|
|
hash_add_id(target_p); |
603 |
|
|
|
604 |
michael |
1239 |
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s SID %s %d %s :%s%s", |
605 |
|
|
ID_or_name(source_p, client_p), target_p->name, hop + 1, |
606 |
|
|
IsHidden(target_p) ? "(H) " : "", target_p->info); |
607 |
|
|
sendto_server(client_p, NULL, NOCAPS, CAP_TS6, ":%s SERVER %s %d :%s%s", |
608 |
|
|
source_p->name, target_p->name, hop + 1, |
609 |
|
|
IsHidden(target_p) ? "(H) " : "", target_p->info); |
610 |
adx |
30 |
|
611 |
|
|
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, |
612 |
michael |
1118 |
"Server %s being introduced by %s", |
613 |
adx |
30 |
target_p->name, source_p->name); |
614 |
|
|
} |
615 |
|
|
|
616 |
|
|
/* set_server_gecos() |
617 |
|
|
* |
618 |
|
|
* input - pointer to client |
619 |
|
|
* output - NONE |
620 |
|
|
* side effects - servers gecos field is set |
621 |
|
|
*/ |
622 |
|
|
static void |
623 |
|
|
set_server_gecos(struct Client *client_p, char *info) |
624 |
|
|
{ |
625 |
|
|
/* check the info for [IP] */ |
626 |
|
|
if (info[0]) |
627 |
|
|
{ |
628 |
|
|
char *p; |
629 |
|
|
char *s; |
630 |
|
|
char *t; |
631 |
|
|
|
632 |
|
|
s = info; |
633 |
|
|
|
634 |
|
|
/* we should only check the first word for an ip */ |
635 |
|
|
if ((p = strchr(s, ' ')) != NULL) |
636 |
|
|
*p = '\0'; |
637 |
|
|
|
638 |
|
|
/* check for a ] which would symbolise an [IP] */ |
639 |
|
|
if ((t = strchr(s, ']')) != NULL) |
640 |
|
|
{ |
641 |
|
|
/* set s to after the first space */ |
642 |
|
|
if (p) |
643 |
|
|
s = ++p; |
644 |
|
|
else |
645 |
|
|
s = NULL; |
646 |
|
|
} |
647 |
|
|
/* no ], put the space back */ |
648 |
|
|
else if (p) |
649 |
|
|
*p = ' '; |
650 |
|
|
|
651 |
|
|
/* p may have been set to a trailing space, so check s exists and that |
652 |
|
|
* it isnt \0 */ |
653 |
|
|
if (s && (*s != '\0')) |
654 |
|
|
{ |
655 |
|
|
/* a space? if not (H) could be the last part of info.. */ |
656 |
|
|
if ((p = strchr(s, ' '))) |
657 |
|
|
*p = '\0'; |
658 |
|
|
|
659 |
|
|
/* check for (H) which is a hidden server */ |
660 |
|
|
if (!strcmp(s, "(H)")) |
661 |
|
|
{ |
662 |
|
|
SetHidden(client_p); |
663 |
|
|
|
664 |
|
|
/* if there was no space.. theres nothing to set info to */ |
665 |
|
|
if (p) |
666 |
|
|
s = ++p; |
667 |
|
|
else |
668 |
|
|
s = NULL; |
669 |
|
|
} |
670 |
|
|
else if (p) |
671 |
|
|
*p = ' '; |
672 |
|
|
|
673 |
|
|
/* if there was a trailing space, s could point to \0, so check */ |
674 |
|
|
if (s && (*s != '\0')) |
675 |
|
|
strlcpy(client_p->info, s, sizeof(client_p->info)); |
676 |
|
|
else |
677 |
|
|
strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); |
678 |
|
|
} |
679 |
|
|
else |
680 |
|
|
strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); |
681 |
|
|
} |
682 |
|
|
else |
683 |
|
|
strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); |
684 |
|
|
} |
685 |
michael |
1230 |
|
686 |
|
|
static struct Message server_msgtab = { |
687 |
|
|
"SERVER", 0, 0, 4, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0, |
688 |
|
|
{mr_server, m_registered, ms_server, m_ignore, m_registered, m_ignore} |
689 |
|
|
}; |
690 |
|
|
|
691 |
|
|
static struct Message sid_msgtab = { |
692 |
|
|
"SID", 0, 0, 5, MAXPARA, MFLG_SLOW, 0, |
693 |
|
|
{rfc1459_command_send_error, m_ignore, ms_sid, m_ignore, m_ignore, m_ignore} |
694 |
|
|
}; |
695 |
|
|
|
696 |
|
|
static void |
697 |
|
|
module_init(void) |
698 |
|
|
{ |
699 |
|
|
mod_add_cmd(&sid_msgtab); |
700 |
|
|
mod_add_cmd(&server_msgtab); |
701 |
|
|
} |
702 |
|
|
|
703 |
|
|
static void |
704 |
|
|
module_exit(void) |
705 |
|
|
{ |
706 |
|
|
mod_del_cmd(&sid_msgtab); |
707 |
|
|
mod_del_cmd(&server_msgtab); |
708 |
|
|
} |
709 |
|
|
|
710 |
|
|
struct module module_entry = { |
711 |
|
|
.node = { NULL, NULL, NULL }, |
712 |
|
|
.name = NULL, |
713 |
|
|
.version = "$Revision$", |
714 |
|
|
.handle = NULL, |
715 |
|
|
.modinit = module_init, |
716 |
|
|
.modexit = module_exit, |
717 |
|
|
.flags = MODULE_FLAG_CORE |
718 |
|
|
}; |