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