| 1 |
/* |
| 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 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "list.h" |
| 27 |
#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 |
#include "conf.h" /* struct AccessItem */ |
| 34 |
#include "log.h" /* log level defines */ |
| 35 |
#include "s_serv.h" /* server_estab, check_server */ |
| 36 |
#include "s_user.h" |
| 37 |
#include "send.h" /* sendto_one */ |
| 38 |
#include "parse.h" |
| 39 |
#include "modules.h" |
| 40 |
|
| 41 |
|
| 42 |
static void set_server_gecos(struct Client *, const 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 *name; |
| 55 |
struct Client *target_p; |
| 56 |
int hop; |
| 57 |
|
| 58 |
if (EmptyString(parv[3])) |
| 59 |
{ |
| 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 |
/* |
| 69 |
* Reject a direct nonTS server connection if we're TS_ONLY -orabidoo |
| 70 |
*/ |
| 71 |
if (!DoesTS(client_p)) |
| 72 |
{ |
| 73 |
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 |
exit_client(client_p, client_p, "Non-TS server"); |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
if (!valid_servname(name)) |
| 84 |
{ |
| 85 |
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 |
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 |
switch (check_server(name, client_p)) |
| 99 |
{ |
| 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 |
if ((client_p->id[0] && (target_p = hash_find_id(client_p->id))) |
| 147 |
|| (target_p = hash_find_server(name))) |
| 148 |
{ |
| 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 |
set_server_gecos(client_p, parv[3]); |
| 185 |
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 |
struct AccessItem *aconf; |
| 202 |
int hop; |
| 203 |
int hlined = 0; |
| 204 |
int llined = 0; |
| 205 |
dlink_node *ptr = NULL; |
| 206 |
|
| 207 |
/* Just to be sure -A1kmm. */ |
| 208 |
if (!IsServer(source_p)) |
| 209 |
return; |
| 210 |
|
| 211 |
if (EmptyString(parv[3])) |
| 212 |
{ |
| 213 |
sendto_one(client_p, "ERROR :No servername"); |
| 214 |
return; |
| 215 |
} |
| 216 |
|
| 217 |
name = parv[1]; |
| 218 |
hop = atoi(parv[2]); |
| 219 |
|
| 220 |
if (!valid_servname(name)) |
| 221 |
{ |
| 222 |
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 |
if ((target_p = hash_find_server(name))) |
| 234 |
{ |
| 235 |
/* 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 |
aconf = map_to_conf(client_p->localClient->confs.head->data); |
| 272 |
|
| 273 |
/* See if the newly found server is behind a guaranteed |
| 274 |
* leaf. If so, close the link. |
| 275 |
*/ |
| 276 |
DLINK_FOREACH(ptr, aconf->leaf_list.head) |
| 277 |
if (match(ptr->data, name)) |
| 278 |
{ |
| 279 |
llined = 1; |
| 280 |
break; |
| 281 |
} |
| 282 |
|
| 283 |
DLINK_FOREACH(ptr, aconf->hub_list.head) |
| 284 |
if (match(ptr->data, name)) |
| 285 |
{ |
| 286 |
hlined = 1; |
| 287 |
break; |
| 288 |
} |
| 289 |
|
| 290 |
/* 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 |
/* Ok, check client_p can hub the new server */ |
| 314 |
if (!hlined) |
| 315 |
{ |
| 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 |
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 |
} |
| 345 |
|
| 346 |
target_p = make_client(client_p); |
| 347 |
make_server(target_p); |
| 348 |
target_p->hopcount = hop; |
| 349 |
target_p->servptr = source_p; |
| 350 |
|
| 351 |
strlcpy(target_p->name, name, sizeof(target_p->name)); |
| 352 |
|
| 353 |
set_server_gecos(target_p, parv[3]); |
| 354 |
SetServer(target_p); |
| 355 |
|
| 356 |
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 |
|
| 359 |
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 |
|
| 363 |
hash_add_client(target_p); |
| 364 |
|
| 365 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s SERVER %s %d :%s%s", |
| 366 |
source_p->name, target_p->name, hop + 1, |
| 367 |
IsHidden(target_p) ? "(H) " : "", target_p->info); |
| 368 |
|
| 369 |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, |
| 370 |
"Server %s being introduced by %s", |
| 371 |
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 |
struct AccessItem *aconf = NULL; |
| 387 |
int hlined = 0; |
| 388 |
int llined = 0; |
| 389 |
dlink_node *ptr = NULL; |
| 390 |
int hop; |
| 391 |
|
| 392 |
/* Just to be sure -A1kmm. */ |
| 393 |
if (!IsServer(source_p)) |
| 394 |
return; |
| 395 |
|
| 396 |
if (EmptyString(parv[4])) |
| 397 |
{ |
| 398 |
sendto_one(client_p, "ERROR :No servername"); |
| 399 |
return; |
| 400 |
} |
| 401 |
|
| 402 |
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 |
/* collision on SID? */ |
| 431 |
if ((target_p = hash_find_id(parv[3]))) |
| 432 |
{ |
| 433 |
sendto_one(client_p, "ERROR :SID %s already exists", parv[3]); |
| 434 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 435 |
"Link %s cancelled, SID %s already exists", |
| 436 |
get_client_name(client_p, SHOW_IP), parv[3]); |
| 437 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 438 |
"Link %s cancelled, SID %s already exists", |
| 439 |
client_p->name, parv[3]); |
| 440 |
exit_client(client_p, &me, "SID Exists"); |
| 441 |
return; |
| 442 |
} |
| 443 |
|
| 444 |
/* collision on name? */ |
| 445 |
if ((target_p = hash_find_server(parv[1]))) |
| 446 |
{ |
| 447 |
sendto_one(client_p, "ERROR :Server %s already exists", parv[1]); |
| 448 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 449 |
"Link %s cancelled, server %s already exists", |
| 450 |
get_client_name(client_p, SHOW_IP), parv[1]); |
| 451 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 452 |
"Link %s cancelled, server %s already exists", |
| 453 |
client_p->name, parv[1]); |
| 454 |
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 |
if ((target_p = find_servconn_in_progress(parv[1]))) |
| 463 |
if (target_p != client_p) |
| 464 |
exit_client(target_p, &me, "Overridden"); |
| 465 |
|
| 466 |
aconf = map_to_conf(client_p->localClient->confs.head->data); |
| 467 |
|
| 468 |
/* See if the newly found server is behind a guaranteed |
| 469 |
* leaf. If so, close the link. |
| 470 |
*/ |
| 471 |
DLINK_FOREACH(ptr, aconf->leaf_list.head) |
| 472 |
if (match(ptr->data, parv[1])) |
| 473 |
{ |
| 474 |
llined = 1; |
| 475 |
break; |
| 476 |
} |
| 477 |
|
| 478 |
DLINK_FOREACH(ptr, aconf->hub_list.head) |
| 479 |
if (match(ptr->data, parv[1])) |
| 480 |
{ |
| 481 |
hlined = 1; |
| 482 |
break; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 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 |
if (!hlined) |
| 511 |
{ |
| 512 |
/* OOOPs nope can't HUB */ |
| 513 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, "Non-Hub link %s introduced %s.", |
| 514 |
get_client_name(client_p, SHOW_IP), parv[1]); |
| 515 |
sendto_realops_flags(UMODE_ALL, L_OPER, "Non-Hub link %s introduced %s.", |
| 516 |
get_client_name(client_p, MASK_IP), parv[1]); |
| 517 |
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 |
get_client_name(client_p, SHOW_IP), parv[1]); |
| 528 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 529 |
"Link %s introduced leafed server %s.", |
| 530 |
get_client_name(client_p, MASK_IP), parv[1]); |
| 531 |
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 |
target_p->servptr = source_p; |
| 539 |
|
| 540 |
strlcpy(target_p->name, parv[1], sizeof(target_p->name)); |
| 541 |
strlcpy(target_p->id, parv[3], sizeof(target_p->id)); |
| 542 |
|
| 543 |
set_server_gecos(target_p, parv[4]); |
| 544 |
SetServer(target_p); |
| 545 |
|
| 546 |
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 |
|
| 549 |
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 |
|
| 553 |
hash_add_client(target_p); |
| 554 |
hash_add_id(target_p); |
| 555 |
|
| 556 |
sendto_server(client_p, CAP_TS6, NOCAPS, ":%s SID %s %d %s :%s%s", |
| 557 |
ID_or_name(source_p, client_p), target_p->name, hop + 1, |
| 558 |
target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info); |
| 559 |
sendto_server(client_p, NOCAPS, CAP_TS6, ":%s SERVER %s %d :%s%s", |
| 560 |
source_p->name, target_p->name, hop + 1, |
| 561 |
IsHidden(target_p) ? "(H) " : "", target_p->info); |
| 562 |
|
| 563 |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, |
| 564 |
"Server %s being introduced by %s", |
| 565 |
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 |
set_server_gecos(struct Client *client_p, const char *info) |
| 576 |
{ |
| 577 |
const char *s = info; |
| 578 |
|
| 579 |
/* check for (H) which is a hidden server */ |
| 580 |
if (!strncmp(s, "(H) ", 4)) |
| 581 |
{ |
| 582 |
SetHidden(client_p); |
| 583 |
s = s + 4; |
| 584 |
} |
| 585 |
|
| 586 |
if (!EmptyString(s)) |
| 587 |
strlcpy(client_p->info, s, sizeof(client_p->info)); |
| 588 |
else |
| 589 |
strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); |
| 590 |
} |
| 591 |
|
| 592 |
static struct Message server_msgtab = { |
| 593 |
"SERVER", 0, 0, 4, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0, |
| 594 |
{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 |
}; |