58 |
|
unsigned int MaxConnectionCount = 1; |
59 |
|
struct Callback *entering_umode_cb = NULL; |
60 |
|
struct Callback *umode_cb = NULL; |
61 |
– |
struct Callback *uid_get_cb = NULL; |
61 |
|
|
62 |
|
static char umode_buffer[IRCD_BUFSIZE]; |
63 |
|
|
64 |
|
static void user_welcome(struct Client *); |
65 |
|
static void report_and_set_user_flags(struct Client *, const struct AccessItem *); |
66 |
|
static int check_xline(struct Client *); |
67 |
< |
static void introduce_client(struct Client *, struct Client *); |
68 |
< |
static void *uid_get(va_list); |
67 |
> |
static void introduce_client(struct Client *); |
68 |
> |
static const char *uid_get(void); |
69 |
|
|
70 |
|
/* Used for building up the isupport string, |
71 |
|
* used with init_isupport, add_isupport, delete_isupport |
279 |
|
** nick from local user or kill him/her... |
280 |
|
*/ |
281 |
|
void |
282 |
< |
register_local_user(struct Client *client_p, struct Client *source_p, |
284 |
< |
const char *nick, const char *username) |
282 |
> |
register_local_user(struct Client *source_p) |
283 |
|
{ |
284 |
|
const struct AccessItem *aconf = NULL; |
285 |
|
dlink_node *ptr = NULL; |
286 |
|
dlink_node *m = NULL; |
287 |
|
|
288 |
|
assert(source_p != NULL); |
289 |
+ |
assert(source_p == source_p->from); |
290 |
|
assert(MyConnect(source_p)); |
292 |
– |
assert(source_p->username != username); |
291 |
|
assert(!source_p->localClient->registration); |
292 |
|
|
293 |
< |
ClearCap(client_p, CAP_TS6); |
293 |
> |
ClearCap(source_p, CAP_TS6); |
294 |
|
|
295 |
|
if (ConfigFileEntry.ping_cookie) |
296 |
|
{ |
297 |
< |
if (!IsPingSent(source_p) && |
300 |
< |
source_p->localClient->random_ping == 0) |
297 |
> |
if (!IsPingSent(source_p) && source_p->localClient->random_ping == 0) |
298 |
|
{ |
299 |
|
do |
300 |
|
source_p->localClient->random_ping = genrand_int32(); |
314 |
|
/* Straight up the maximum rate of flooding... */ |
315 |
|
source_p->localClient->allow_read = MAX_FLOOD_BURST; |
316 |
|
|
317 |
< |
if (!execute_callback(client_check_cb, source_p, username)) |
317 |
> |
if (!execute_callback(client_check_cb, source_p, source_p->username)) |
318 |
|
return; |
319 |
|
|
320 |
|
if (valid_hostname(source_p->host) == 0) |
330 |
|
|
331 |
|
if (!IsGotId(source_p)) |
332 |
|
{ |
333 |
< |
const char *p = NULL; |
333 |
> |
char username[USERLEN + 1]; |
334 |
> |
const char *p = username; |
335 |
|
unsigned int i = 0; |
336 |
|
|
337 |
|
if (IsNeedIdentd(aconf)) |
343 |
|
return; |
344 |
|
} |
345 |
|
|
346 |
< |
p = username; |
346 |
> |
strlcpy(username, source_p->username, sizeof(username)); |
347 |
|
|
348 |
|
if (!IsNoTilde(aconf)) |
349 |
|
source_p->username[i++] = '~'; |
350 |
|
|
351 |
< |
while (*p && i < USERLEN) |
354 |
< |
{ |
351 |
> |
for (; *p && i < USERLEN; ++p) |
352 |
|
if (*p != '[') |
353 |
|
source_p->username[i++] = *p; |
357 |
– |
p++; |
358 |
– |
} |
354 |
|
|
355 |
|
source_p->username[i] = '\0'; |
356 |
|
} |
378 |
|
/* report if user has &^>= etc. and set flags as needed in source_p */ |
379 |
|
report_and_set_user_flags(source_p, aconf); |
380 |
|
|
381 |
< |
if (IsDead(client_p)) |
381 |
> |
if (IsDead(source_p)) |
382 |
|
return; |
383 |
|
|
384 |
|
/* Limit clients - |
394 |
|
{ |
395 |
|
sendto_realops_flags(UMODE_FULL, L_ALL, |
396 |
|
"Too many clients, rejecting %s[%s].", |
397 |
< |
nick, source_p->host); |
397 |
> |
source_p->name, source_p->host); |
398 |
|
++ServerStats.is_ref; |
399 |
|
exit_client(source_p, &me, "Sorry, server is full - try later"); |
400 |
|
return; |
406 |
|
char tmpstr2[IRCD_BUFSIZE]; |
407 |
|
|
408 |
|
sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)", |
409 |
< |
nick, source_p->username, source_p->host); |
409 |
> |
source_p->name, source_p->username, source_p->host); |
410 |
|
++ServerStats.is_ref; |
411 |
|
ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username); |
412 |
|
exit_client(source_p, &me, tmpstr2); |
413 |
|
return; |
414 |
|
} |
415 |
|
|
421 |
– |
assert(source_p == client_p); |
422 |
– |
|
416 |
|
if (check_xline(source_p)) |
417 |
|
return; |
418 |
|
|
419 |
|
if (me.id[0]) |
420 |
|
{ |
421 |
< |
const char *id = execute_callback(uid_get_cb, source_p); |
421 |
> |
const char *id = NULL; |
422 |
|
|
423 |
< |
while (hash_find_id(id) != NULL) |
424 |
< |
id = uid_get(NULL); |
423 |
> |
while (hash_find_id((id = uid_get())) != NULL) |
424 |
> |
; |
425 |
|
|
426 |
|
strlcpy(source_p->id, id, sizeof(source_p->id)); |
427 |
|
hash_add_id(source_p); |
429 |
|
|
430 |
|
sendto_realops_flags(UMODE_CCONN, L_ALL, |
431 |
|
"Client connecting: %s (%s@%s) [%s] {%s} [%s]", |
432 |
< |
nick, source_p->username, source_p->host, |
432 |
> |
source_p->name, source_p->username, source_p->host, |
433 |
|
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
434 |
|
"255.255.255.255" : source_p->sockhost, |
435 |
|
get_client_class(source_p), |
437 |
|
|
438 |
|
sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, |
439 |
|
"CLICONN %s %s %s %s %s %s %s 0 %s", |
440 |
< |
nick, source_p->username, source_p->host, |
440 |
> |
source_p->name, source_p->username, source_p->host, |
441 |
|
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
442 |
|
"255.255.255.255" : source_p->sockhost, |
443 |
|
get_client_class(source_p), |
463 |
|
Count.max_loc); |
464 |
|
} |
465 |
|
|
473 |
– |
SetClient(source_p); |
474 |
– |
|
475 |
– |
source_p->servptr = &me; |
476 |
– |
dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list); |
477 |
– |
|
466 |
|
/* Increment our total user count here */ |
467 |
|
if (++Count.total > Count.max_tot) |
468 |
|
Count.max_tot = Count.total; |
469 |
|
++Count.totalrestartcount; |
470 |
|
|
471 |
+ |
assert(source_p->servptr == &me); |
472 |
+ |
SetClient(source_p); |
473 |
+ |
dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list); |
474 |
+ |
|
475 |
|
source_p->localClient->allow_read = MAX_FLOOD_BURST; |
476 |
|
|
477 |
|
assert(dlinkFindDelete(&unknown_list, source_p)); |
486 |
|
add_user_host(source_p->username, source_p->host, 0); |
487 |
|
SetUserHost(source_p); |
488 |
|
|
489 |
< |
introduce_client(client_p, source_p); |
489 |
> |
introduce_client(source_p); |
490 |
|
} |
491 |
|
|
492 |
|
/* register_remote_user() |
493 |
|
* |
494 |
< |
* inputs - client_p directly connected client |
503 |
< |
* - source_p remote or directly connected client |
494 |
> |
* inputs - source_p remote or directly connected client |
495 |
|
* - username to register as |
496 |
|
* - host name to register as |
497 |
|
* - server name |
501 |
|
* is introduced by a server. |
502 |
|
*/ |
503 |
|
void |
504 |
< |
register_remote_user(struct Client *client_p, struct Client *source_p, |
504 |
> |
register_remote_user(struct Client *source_p, |
505 |
|
const char *username, const char *host, const char *server, |
506 |
|
const char *realname) |
507 |
|
{ |
528 |
|
"No server %s for user %s[%s@%s] from %s", |
529 |
|
server, source_p->name, source_p->username, |
530 |
|
source_p->host, source_p->from->name); |
531 |
< |
kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name); |
531 |
> |
kill_client(source_p->from, source_p, "%s (Server doesn't exist)", me.name); |
532 |
|
|
533 |
|
SetKilled(source_p); |
534 |
|
exit_client(source_p, &me, "Ghosted Client"); |
539 |
|
{ |
540 |
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, |
541 |
|
"Bad User [%s] :%s USER %s@%s %s, != %s[%s]", |
542 |
< |
client_p->name, source_p->name, source_p->username, |
542 |
> |
source_p->from->name, source_p->name, source_p->username, |
543 |
|
source_p->host, source_p->servptr->name, |
544 |
|
target_p->name, target_p->from->name); |
545 |
< |
kill_client(client_p, source_p, |
545 |
> |
kill_client(source_p->from, source_p, |
546 |
|
"%s (NICK from wrong direction (%s != %s))", |
547 |
|
me.name, source_p->servptr->name, target_p->from->name); |
548 |
|
SetKilled(source_p); |
559 |
|
add_user_host(source_p->username, source_p->host, 1); |
560 |
|
SetUserHost(source_p); |
561 |
|
|
562 |
< |
introduce_client(client_p, source_p); |
562 |
> |
introduce_client(source_p); |
563 |
|
} |
564 |
|
|
565 |
|
/* introduce_client() |
566 |
|
* |
567 |
< |
* inputs - client_p |
577 |
< |
* - source_p |
567 |
> |
* inputs - source_p |
568 |
|
* output - NONE |
569 |
|
* side effects - This common function introduces a client to the rest |
570 |
|
* of the net, either from a local client connect or |
571 |
|
* from a remote connect. |
572 |
|
*/ |
573 |
|
static void |
574 |
< |
introduce_client(struct Client *client_p, struct Client *source_p) |
574 |
> |
introduce_client(struct Client *source_p) |
575 |
|
{ |
576 |
|
dlink_node *server_node = NULL; |
577 |
|
static char ubuf[12]; |
593 |
|
{ |
594 |
|
struct Client *server = server_node->data; |
595 |
|
|
596 |
< |
if (server == client_p) |
596 |
> |
if (server == source_p->from) |
597 |
|
continue; |
598 |
|
|
599 |
|
if (IsCapable(server, CAP_TS6) && HasID(source_p)) |
629 |
|
|
630 |
|
assert(p != NULL); |
631 |
|
|
632 |
< |
if ('.' == *p || ':' == *p) |
632 |
> |
if (*p == '.' || *p == ':') |
633 |
|
return 0; |
634 |
|
|
635 |
< |
while (*p) |
646 |
< |
{ |
635 |
> |
for (; *p; ++p) |
636 |
|
if (!IsHostChar(*p)) |
637 |
|
return 0; |
649 |
– |
p++; |
650 |
– |
} |
638 |
|
|
639 |
|
return 1; |
640 |
|
} |
658 |
|
|
659 |
|
assert(p != NULL); |
660 |
|
|
661 |
< |
if ('~' == *p) |
661 |
> |
if (*p == '~') |
662 |
|
++p; |
663 |
|
|
664 |
|
/* reject usernames that don't start with an alphanum |
672 |
|
{ |
673 |
|
if ((*p == '.') && ConfigFileEntry.dots_in_ident) |
674 |
|
{ |
675 |
< |
dots++; |
689 |
< |
|
690 |
< |
if (dots > ConfigFileEntry.dots_in_ident) |
675 |
> |
if (++dots > ConfigFileEntry.dots_in_ident) |
676 |
|
return 0; |
677 |
< |
if (!IsUserChar(p[1])) |
677 |
> |
if (!IsUserChar(*(p + 1))) |
678 |
|
return 0; |
679 |
|
} |
680 |
|
else if (!IsUserChar(*p)) |
763 |
|
* side effects - |
764 |
|
*/ |
765 |
|
void |
766 |
< |
do_local_user(const char *nick, struct Client *client_p, struct Client *source_p, |
766 |
> |
do_local_user(struct Client *source_p, |
767 |
|
const char *username, const char *host, const char *server, |
768 |
|
const char *realname) |
769 |
|
{ |
770 |
|
assert(source_p != NULL); |
771 |
|
assert(source_p->username != username); |
772 |
< |
|
788 |
< |
if (source_p == NULL) |
789 |
< |
return; |
790 |
< |
|
791 |
< |
if (!IsUnknown(source_p)) |
792 |
< |
{ |
793 |
< |
sendto_one(source_p, form_str(ERR_ALREADYREGISTRED), |
794 |
< |
me.name, nick); |
795 |
< |
return; |
796 |
< |
} |
772 |
> |
assert(IsUnknown(source_p)); |
773 |
|
|
774 |
|
source_p->localClient->registration &= ~REG_NEED_USER; |
775 |
|
|
785 |
|
strlcpy(source_p->client_server, server, sizeof(source_p->client_server)); |
786 |
|
|
787 |
|
if (!IsGotId(source_p)) |
812 |
– |
{ |
813 |
– |
/* save the username in the client |
814 |
– |
* If you move this you'll break ping cookies..you've been warned |
815 |
– |
*/ |
788 |
|
strlcpy(source_p->username, username, sizeof(source_p->username)); |
817 |
– |
} |
789 |
|
|
790 |
|
if (!source_p->localClient->registration) |
791 |
< |
/* NICK already received, now I have USER... */ |
821 |
< |
register_local_user(client_p, source_p, source_p->name, username); |
791 |
> |
register_local_user(source_p); |
792 |
|
} |
793 |
|
|
794 |
|
/* change_simple_umode() |
1294 |
|
|
1295 |
|
entering_umode_cb = register_callback("entering_umode", NULL); |
1296 |
|
umode_cb = register_callback("changing_umode", change_simple_umode); |
1327 |
– |
uid_get_cb = register_callback("uid_get", uid_get); |
1297 |
|
} |
1298 |
|
|
1299 |
|
/* |
1336 |
|
* output - new UID is returned to caller |
1337 |
|
* side effects - new_uid is incremented by one. |
1338 |
|
*/ |
1339 |
< |
static void * |
1340 |
< |
uid_get(va_list args) |
1339 |
> |
static const char * |
1340 |
> |
uid_get(void) |
1341 |
|
{ |
1342 |
|
add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */ |
1343 |
|
return new_uid; |