]> jfr.im git - irc/rqf/shadowircd.git/blob - src/s_user.c
Automated merge with ssh://hg.atheme.org//hg/charybdis
[irc/rqf/shadowircd.git] / src / s_user.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * s_user.c: User related functions.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: s_user.c 3586 2007-11-20 11:16:43Z nenolod $
25 */
26
27 #include "stdinc.h"
28 #include "s_user.h"
29 #include "channel.h"
30 #include "class.h"
31 #include "client.h"
32 #include "common.h"
33 #include "hash.h"
34 #include "match.h"
35 #include "ircd.h"
36 #include "listener.h"
37 #include "msg.h"
38 #include "numeric.h"
39 #include "s_conf.h"
40 #include "s_newconf.h"
41 #include "logger.h"
42 #include "s_serv.h"
43 #include "s_stats.h"
44 #include "scache.h"
45 #include "send.h"
46 #include "supported.h"
47 #include "whowas.h"
48 #include "packet.h"
49 #include "reject.h"
50 #include "cache.h"
51 #include "hook.h"
52 #include "monitor.h"
53 #include "snomask.h"
54 #include "blacklist.h"
55 #include "substitution.h"
56
57 static void report_and_set_user_flags(struct Client *, struct ConfItem *);
58 void user_welcome(struct Client *source_p);
59
60 extern char *crypt();
61
62 char umodebuf[128];
63
64 static int orphaned_umodes = 0;
65 int user_modes[256] = {
66 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
67 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
68 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
69 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
70 0, /* @ */
71 0, /* A */
72 0, /* B */
73 0, /* C */
74 UMODE_DEAF, /* D */
75 0, /* E */
76 0, /* F */
77 0, /* G */
78 0, /* H */
79 0, /* I */
80 0, /* J */
81 0, /* K */
82 0, /* L */
83 0, /* M */
84 0, /* N */
85 0, /* O */
86 0, /* P */
87 UMODE_NOFORWARD, /* Q */
88 UMODE_REGONLYMSG, /* R */
89 UMODE_SERVICE, /* S */
90 0, /* T */
91 0, /* U */
92 0, /* V */
93 0, /* W */
94 0, /* X */
95 0, /* Y */
96 UMODE_SSLCLIENT, /* Z */
97 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
98 UMODE_ADMIN, /* a */
99 0, /* b */
100 0, /* c */
101 0, /* d */
102 0, /* e */
103 0, /* f */
104 UMODE_CALLERID, /* g */
105 0, /* h */
106 UMODE_INVISIBLE, /* i */
107 0, /* j */
108 0, /* k */
109 UMODE_LOCOPS, /* l */
110 0, /* m */
111 0, /* n */
112 UMODE_OPER, /* o */
113 0, /* p */
114 0, /* q */
115 0, /* r */
116 UMODE_SERVNOTICE, /* s */
117 0, /* t */
118 0, /* u */
119 0, /* v */
120 UMODE_WALLOP, /* w */
121 0, /* x */
122 0, /* y */
123 UMODE_OPERWALL, /* z */
124 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
125 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
126 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
127 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
128 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
129 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
130 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
131 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
132 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
133 };
134 /* *INDENT-ON* */
135
136 /*
137 * show_lusers -
138 *
139 * inputs - pointer to client
140 * output -
141 * side effects - display to client user counts etc.
142 */
143 int
144 show_lusers(struct Client *source_p)
145 {
146 if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount)
147 MaxClientCount = rb_dlink_list_length(&lclient_list);
148
149 if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) >
150 (unsigned long)MaxConnectionCount)
151 MaxConnectionCount = rb_dlink_list_length(&lclient_list) +
152 rb_dlink_list_length(&serv_list);
153
154 sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT),
155 (Count.total - Count.invisi),
156 Count.invisi, rb_dlink_list_length(&global_serv_list));
157
158 if(rb_dlink_list_length(&oper_list) > 0)
159 sendto_one_numeric(source_p, RPL_LUSEROP,
160 form_str(RPL_LUSEROP), rb_dlink_list_length(&oper_list));
161
162 if(rb_dlink_list_length(&unknown_list) > 0)
163 sendto_one_numeric(source_p, RPL_LUSERUNKNOWN,
164 form_str(RPL_LUSERUNKNOWN),
165 rb_dlink_list_length(&unknown_list));
166
167 if(rb_dlink_list_length(&global_channel_list) > 0)
168 sendto_one_numeric(source_p, RPL_LUSERCHANNELS,
169 form_str(RPL_LUSERCHANNELS),
170 rb_dlink_list_length(&global_channel_list));
171
172 sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME),
173 rb_dlink_list_length(&lclient_list),
174 rb_dlink_list_length(&serv_list));
175
176 sendto_one_numeric(source_p, RPL_LOCALUSERS,
177 form_str(RPL_LOCALUSERS),
178 rb_dlink_list_length(&lclient_list),
179 Count.max_loc,
180 rb_dlink_list_length(&lclient_list),
181 Count.max_loc);
182
183 sendto_one_numeric(source_p, RPL_GLOBALUSERS, form_str(RPL_GLOBALUSERS),
184 Count.total, Count.max_tot,
185 Count.total, Count.max_tot);
186
187 sendto_one_numeric(source_p, RPL_STATSCONN,
188 form_str(RPL_STATSCONN),
189 MaxConnectionCount, MaxClientCount,
190 Count.totalrestartcount);
191
192 return 0;
193 }
194
195 /*
196 ** register_local_user
197 ** This function is called when both NICK and USER messages
198 ** have been accepted for the client, in whatever order. Only
199 ** after this, is the USER message propagated.
200 **
201 ** NICK's must be propagated at once when received, although
202 ** it would be better to delay them too until full info is
203 ** available. Doing it is not so simple though, would have
204 ** to implement the following:
205 **
206 ** (actually it has been implemented already for a while) -orabidoo
207 **
208 ** 1) user telnets in and gives only "NICK foobar" and waits
209 ** 2) another user far away logs in normally with the nick
210 ** "foobar" (quite legal, as this server didn't propagate
211 ** it).
212 ** 3) now this server gets nick "foobar" from outside, but
213 ** has alread the same defined locally. Current server
214 ** would just issue "KILL foobar" to clean out dups. But,
215 ** this is not fair. It should actually request another
216 ** nick from local user or kill him/her...
217 */
218
219 int
220 register_local_user(struct Client *client_p, struct Client *source_p, const char *username)
221 {
222 struct ConfItem *aconf, *xconf;
223 struct User *user = source_p->user;
224 char tmpstr2[IRCD_BUFSIZE];
225 char ipaddr[HOSTIPLEN];
226 char myusername[USERLEN+1];
227 int status;
228
229 s_assert(NULL != source_p);
230 s_assert(MyConnect(source_p));
231 s_assert(source_p->username != username);
232
233 if(source_p == NULL)
234 return -1;
235
236 if(IsAnyDead(source_p))
237 return -1;
238
239 if(ConfigFileEntry.ping_cookie)
240 {
241 if(!(source_p->flags & FLAGS_PINGSENT) && source_p->localClient->random_ping == 0)
242 {
243 source_p->localClient->random_ping = (unsigned long) (rand() * rand()) << 1;
244 sendto_one(source_p, "PING :%08lX",
245 (unsigned long) source_p->localClient->random_ping);
246 source_p->flags |= FLAGS_PINGSENT;
247 return -1;
248 }
249 if(!(source_p->flags & FLAGS_PING_COOKIE))
250 {
251 return -1;
252 }
253 }
254
255 /* hasnt finished client cap negotiation */
256 if(source_p->flags & FLAGS_CLICAP)
257 return -1;
258
259 /* still has DNSbls to validate against */
260 if(rb_dlink_list_length(&source_p->preClient->dnsbl_queries) > 0)
261 return -1;
262
263 client_p->localClient->last = rb_current_time();
264 /* Straight up the maximum rate of flooding... */
265 source_p->localClient->allow_read = MAX_FLOOD_BURST;
266
267 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
268 if(!IsGotId(source_p) && (strchr(username, '[') != NULL))
269 {
270 const char *p;
271 int i = 0;
272
273 p = username;
274
275 while(*p && i < USERLEN)
276 {
277 if(*p != '[')
278 myusername[i++] = *p;
279 p++;
280 }
281
282 myusername[i] = '\0';
283 username = myusername;
284 }
285
286 if((status = check_client(client_p, source_p, username)) < 0)
287 return (CLIENT_EXITED);
288
289 /* Apply nick override */
290 if(*source_p->preClient->spoofnick)
291 {
292 char note[NICKLEN + 10];
293
294 del_from_client_hash(source_p->name, source_p);
295 rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1);
296 add_to_client_hash(source_p->name, source_p);
297
298 rb_snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name);
299 rb_note(source_p->localClient->F, note);
300 }
301
302 if(!valid_hostname(source_p->host))
303 {
304 sendto_one_notice(source_p, ":*** Notice -- You have an illegal character in your hostname");
305
306 rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
307 }
308
309
310 aconf = source_p->localClient->att_conf;
311
312 if(aconf == NULL)
313 {
314 exit_client(client_p, source_p, &me, "*** Not Authorised");
315 return (CLIENT_EXITED);
316 }
317
318 if(!IsGotId(source_p))
319 {
320 const char *p;
321 int i = 0;
322
323 if(IsNeedIdentd(aconf))
324 {
325 ServerStats.is_ref++;
326 sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server");
327 exit_client(client_p, source_p, &me, "Install identd");
328 return (CLIENT_EXITED);
329 }
330
331 /* dont replace username if its supposed to be spoofed --fl */
332 if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->name, '@'))
333 {
334 p = username;
335
336 if(!IsNoTilde(aconf))
337 source_p->username[i++] = '~';
338
339 while (*p && i < USERLEN)
340 {
341 if(*p != '[')
342 source_p->username[i++] = *p;
343 p++;
344 }
345
346 source_p->username[i] = '\0';
347 }
348 }
349
350 if(IsNeedSasl(aconf) && !*user->suser)
351 {
352 ServerStats.is_ref++;
353 sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server");
354 exit_client(client_p, source_p, &me, "SASL access only");
355 return (CLIENT_EXITED);
356 }
357
358 /* password check */
359 if(!EmptyString(aconf->passwd))
360 {
361 const char *encr;
362
363 if(EmptyString(source_p->localClient->passwd))
364 encr = "";
365 else if(IsConfEncrypted(aconf))
366 encr = crypt(source_p->localClient->passwd, aconf->passwd);
367 else
368 encr = source_p->localClient->passwd;
369
370 if(strcmp(encr, aconf->passwd))
371 {
372 ServerStats.is_ref++;
373 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
374 exit_client(client_p, source_p, &me, "Bad Password");
375 return (CLIENT_EXITED);
376 }
377
378 /* clear password only if used now, otherwise send it
379 * to services -- jilles */
380 if(source_p->localClient->passwd)
381 {
382 memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd));
383 rb_free(source_p->localClient->passwd);
384 source_p->localClient->passwd = NULL;
385 }
386 }
387
388 /* report if user has &^>= etc. and set flags as needed in source_p */
389 report_and_set_user_flags(source_p, aconf);
390
391 /* Limit clients */
392 /*
393 * We want to be able to have servers and F-line clients
394 * connect, so save room for "buffer" connections.
395 * Smaller servers may want to decrease this, and it should
396 * probably be just a percentage of the MAXCLIENTS...
397 * -Taner
398 */
399 /* Except "F:" clients */
400 if(rb_dlink_list_length(&lclient_list) >=
401 (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf))
402 {
403 sendto_realops_snomask(SNO_FULL, L_ALL,
404 "Too many clients, rejecting %s[%s].", source_p->name, source_p->host);
405
406 ServerStats.is_ref++;
407 exit_client(client_p, source_p, &me, "Sorry, server is full - try later");
408 return (CLIENT_EXITED);
409 }
410
411 /* kline exemption extends to xline too */
412 if(!IsExemptKline(source_p) &&
413 (xconf = find_xline(source_p->info, 1)) != NULL)
414 {
415 ServerStats.is_ref++;
416 add_reject(source_p, xconf->name, NULL);
417 exit_client(client_p, source_p, &me, "Bad user info");
418 return CLIENT_EXITED;
419 }
420
421 /* dnsbl check */
422 if (source_p->preClient->dnsbl_listed != NULL)
423 {
424 if (IsExemptKline(source_p) || IsConfExemptDNSBL(aconf))
425 sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s, but you are exempt",
426 source_p->sockhost, source_p->preClient->dnsbl_listed->host);
427 else
428 {
429 rb_dlink_list varlist = { NULL, NULL, 0 };
430
431 substitution_append_var(&varlist, "nick", source_p->name);
432 substitution_append_var(&varlist, "ip", source_p->sockhost);
433 substitution_append_var(&varlist, "host", source_p->host);
434 substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->dnsbl_listed->host);
435 substitution_append_var(&varlist, "network-name", ServerInfo.network_name);
436
437 ServerStats.is_ref++;
438
439 sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP),
440 me.name, source_p->name,
441 substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist));
442
443 substitution_free(&varlist);
444
445 sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s",
446 source_p->sockhost, source_p->preClient->dnsbl_listed->host);
447 source_p->preClient->dnsbl_listed->hits++;
448 add_reject(source_p, NULL, NULL);
449 exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)");
450 return CLIENT_EXITED;
451 }
452 }
453
454 /* valid user name check */
455
456 if(!valid_username(source_p->username))
457 {
458 sendto_realops_snomask(SNO_REJ, L_ALL,
459 "Invalid username: %s (%s@%s)",
460 source_p->name, source_p->username, source_p->host);
461 ServerStats.is_ref++;
462 sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains "
463 "only alphanumeric characters.");
464 rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username);
465 exit_client(client_p, source_p, &me, tmpstr2);
466 return (CLIENT_EXITED);
467 }
468
469 /* end of valid user name check */
470
471 /* Store original hostname -- jilles */
472 rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1);
473
474 /* Spoof user@host */
475 if(*source_p->preClient->spoofuser)
476 rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1);
477 if(*source_p->preClient->spoofhost)
478 {
479 rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1);
480 if (irccmp(source_p->host, source_p->orighost))
481 SetDynSpoof(source_p);
482 }
483
484 source_p->umodes |= ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes & ~orphaned_umodes;
485
486 call_hook(h_new_local_user, source_p);
487
488 /* If they have died in send_* or were thrown out by the
489 * new_local_user hook don't do anything. */
490 if(IsAnyDead(source_p))
491 return CLIENT_EXITED;
492
493 /* To avoid inconsistencies, do not abort the registration
494 * starting from this point -- jilles
495 */
496 rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
497
498 sendto_realops_snomask(SNO_CCONN, L_ALL,
499 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
500 source_p->name, source_p->username, source_p->orighost,
501 show_ip(NULL, source_p) ? ipaddr : "255.255.255.255",
502 get_client_class(source_p), source_p->info);
503
504 sendto_realops_snomask(SNO_CCONNEXT, L_ALL,
505 "CLICONN %s %s %s %s %s %s 0 %s",
506 source_p->name, source_p->username, source_p->orighost,
507 show_ip(NULL, source_p) ? ipaddr : "255.255.255.255",
508 get_client_class(source_p),
509 /* mirc can sometimes send ips here */
510 show_ip(NULL, source_p) ? source_p->localClient->fullcaps : "<hidden> <hidden>",
511 source_p->info);
512
513 add_to_hostname_hash(source_p->orighost, source_p);
514
515 /* Allocate a UID if it was not previously allocated.
516 * If this already occured, it was probably during SASL auth...
517 */
518 if(!*source_p->id)
519 {
520 strcpy(source_p->id, generate_uid());
521 add_to_id_hash(source_p->id, source_p);
522 }
523
524 if (IsSSL(source_p))
525 source_p->umodes |= UMODE_SSLCLIENT;
526
527 if (source_p->umodes & UMODE_INVISIBLE)
528 Count.invisi++;
529
530 s_assert(!IsClient(source_p));
531 del_unknown_ip(source_p);
532 rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list);
533 SetClient(source_p);
534
535 source_p->servptr = &me;
536 rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
537
538 /* Increment our total user count here */
539 if(++Count.total > Count.max_tot)
540 Count.max_tot = Count.total;
541
542 source_p->localClient->allow_read = MAX_FLOOD_BURST;
543
544 Count.totalrestartcount++;
545
546 s_assert(source_p->localClient != NULL);
547
548 if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc)
549 {
550 Count.max_loc = rb_dlink_list_length(&lclient_list);
551 if(!(Count.max_loc % 10))
552 sendto_realops_snomask(SNO_GENERAL, L_ALL,
553 "New Max Local Clients: %d", Count.max_loc);
554 }
555
556 /* they get a reduced limit */
557 if(find_tgchange(source_p->sockhost))
558 USED_TARGETS(source_p) = 6;
559
560 monitor_signon(source_p);
561 user_welcome(source_p);
562
563 free_pre_client(source_p);
564
565 return (introduce_client(client_p, source_p, user, source_p->name, 1));
566 }
567
568 /*
569 * introduce_clients
570 *
571 * inputs -
572 * output -
573 * side effects - This common function introduces a client to the rest
574 * of the net, either from a local client connect or
575 * from a remote connect.
576 */
577 int
578 introduce_client(struct Client *client_p, struct Client *source_p, struct User *user, const char *nick, int use_euid)
579 {
580 static char ubuf[12];
581 struct Client *identifyservice_p;
582 char *p;
583 hook_data_umode_changed hdata;
584 hook_data_client hdata2;
585
586 if(MyClient(source_p))
587 send_umode(source_p, source_p, 0, 0, ubuf);
588 else
589 send_umode(NULL, source_p, 0, 0, ubuf);
590
591 if(!*ubuf)
592 {
593 ubuf[0] = '+';
594 ubuf[1] = '\0';
595 }
596
597 /* if it has an ID, introduce it with its id to TS6 servers,
598 * otherwise introduce it normally to all.
599 */
600 if(has_id(source_p))
601 {
602 char sockhost[HOSTLEN];
603 if(source_p->sockhost[0] == ':')
604 {
605 sockhost[0] = '0';
606 sockhost[1] = '\0';
607 rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost));
608 } else
609 strcpy(sockhost, source_p->sockhost);
610
611 if (use_euid)
612 sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS,
613 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
614 source_p->servptr->id, nick,
615 source_p->hopcount + 1,
616 (long) source_p->tsinfo, ubuf,
617 source_p->username, source_p->host,
618 IsIPSpoof(source_p) ? "0" : sockhost,
619 source_p->id,
620 IsDynSpoof(source_p) ? source_p->orighost : "*",
621 EmptyString(source_p->user->suser) ? "*" : source_p->user->suser,
622 source_p->info);
623
624 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS,
625 ":%s UID %s %d %ld %s %s %s %s %s :%s",
626 source_p->servptr->id, nick,
627 source_p->hopcount + 1,
628 (long) source_p->tsinfo, ubuf,
629 source_p->username, source_p->host,
630 IsIPSpoof(source_p) ? "0" : sockhost,
631 source_p->id, source_p->info);
632
633 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
634 "NICK %s %d %ld %s %s %s %s :%s",
635 nick, source_p->hopcount + 1,
636 (long) source_p->tsinfo,
637 ubuf, source_p->username, source_p->host,
638 source_p->servptr->name, source_p->info);
639 }
640 else
641 sendto_server(client_p, NULL, NOCAPS, NOCAPS,
642 "NICK %s %d %ld %s %s %s %s :%s",
643 nick, source_p->hopcount + 1,
644 (long) source_p->tsinfo,
645 ubuf, source_p->username, source_p->host,
646 source_p->servptr->name, source_p->info);
647
648 if (IsDynSpoof(source_p))
649 {
650 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s",
651 use_id(source_p), source_p->orighost);
652 sendto_server(client_p, NULL, NOCAPS, CAP_TS6, ":%s ENCAP * REALHOST %s",
653 source_p->name, source_p->orighost);
654 }
655 if (!EmptyString(source_p->user->suser))
656 {
657 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s",
658 use_id(source_p), source_p->user->suser);
659 sendto_server(client_p, NULL, NOCAPS, CAP_TS6, ":%s ENCAP * LOGIN %s",
660 source_p->name, source_p->user->suser);
661 }
662
663 if(MyConnect(source_p) && source_p->localClient->passwd)
664 {
665 if (ConfigFileEntry.identifyservice[0] != '\0' &&
666 ConfigFileEntry.identifycommand[0] != '\0')
667 {
668 /* use user@server */
669 p = strchr(ConfigFileEntry.identifyservice, '@');
670 if (p != NULL)
671 identifyservice_p = find_named_client(p + 1);
672 else
673 identifyservice_p = NULL;
674 if (identifyservice_p != NULL)
675 sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s",
676 get_id(source_p, identifyservice_p),
677 ConfigFileEntry.identifyservice,
678 ConfigFileEntry.identifycommand,
679 source_p->localClient->passwd);
680 }
681 memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd));
682 rb_free(source_p->localClient->passwd);
683 source_p->localClient->passwd = NULL;
684 }
685
686 /* let modules providing usermodes know that we've got a new user,
687 * why is this here? -- well, some modules need to be able to send out new
688 * information about a client, so this was the best place to do it
689 * --nenolod
690 */
691 hdata.client = source_p;
692 hdata.oldumodes = 0;
693 hdata.oldsnomask = 0;
694 call_hook(h_umode_changed, &hdata);
695
696 /* On the other hand, some modules need to know when a client is
697 * being introduced, period.
698 * --gxti
699 */
700 hdata2.client = client_p;
701 hdata2.target = source_p;
702 call_hook(h_introduce_client, &hdata2);
703
704 return 0;
705 }
706
707 /*
708 * valid_hostname - check hostname for validity
709 *
710 * Inputs - pointer to user
711 * Output - YES if valid, NO if not
712 * Side effects - NONE
713 *
714 * NOTE: this doesn't allow a hostname to begin with a dot and
715 * will not allow more dots than chars.
716 */
717 int
718 valid_hostname(const char *hostname)
719 {
720 const char *p = hostname;
721 int found_sep = 0;
722
723 s_assert(NULL != p);
724
725 if(hostname == NULL)
726 return NO;
727
728 if('.' == *p || ':' == *p)
729 return NO;
730
731 while (*p)
732 {
733 if(!IsHostChar(*p))
734 return NO;
735 if(*p == '.' || *p == ':')
736 found_sep++;
737 p++;
738 }
739
740 if(found_sep == 0)
741 return(NO);
742
743 return (YES);
744 }
745
746 /*
747 * valid_username - check username for validity
748 *
749 * Inputs - pointer to user
750 * Output - YES if valid, NO if not
751 * Side effects - NONE
752 *
753 * Absolutely always reject any '*' '!' '?' '@' in an user name
754 * reject any odd control characters names.
755 * Allow '.' in username to allow for "first.last"
756 * style of username
757 */
758 int
759 valid_username(const char *username)
760 {
761 int dots = 0;
762 const char *p = username;
763
764 s_assert(NULL != p);
765
766 if(username == NULL)
767 return NO;
768
769 if('~' == *p)
770 ++p;
771
772 /* reject usernames that don't start with an alphanum
773 * i.e. reject jokers who have '-@somehost' or '.@somehost'
774 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
775 */
776 if(!IsAlNum(*p))
777 return NO;
778
779 while (*++p)
780 {
781 if((*p == '.') && ConfigFileEntry.dots_in_ident)
782 {
783 dots++;
784 if(dots > ConfigFileEntry.dots_in_ident)
785 return NO;
786 if(!IsUserChar(p[1]))
787 return NO;
788 }
789 else if(!IsUserChar(*p))
790 return NO;
791 }
792 return YES;
793 }
794
795 /* report_and_set_user_flags
796 *
797 * Inputs - pointer to source_p
798 * - pointer to aconf for this user
799 * Output - NONE
800 * Side effects -
801 * Report to user any special flags they are getting, and set them.
802 */
803
804 static void
805 report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf)
806 {
807 /* If this user is being spoofed, tell them so */
808 if(IsConfDoSpoofIp(aconf))
809 {
810 sendto_one_notice(source_p, ":*** Spoofing your IP. congrats.");
811 }
812
813 /* If this user is in the exception class, Set it "E lined" */
814 if(IsConfExemptKline(aconf))
815 {
816 SetExemptKline(source_p);
817 sendto_one_notice(source_p, ":*** You are exempt from K/X lines. congrats.");
818 }
819
820 if(IsConfExemptDNSBL(aconf))
821 /* kline exempt implies this, don't send both */
822 if(!IsConfExemptKline(aconf))
823 sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists.");
824
825 /* If this user is exempt from user limits set it F lined" */
826 if(IsConfExemptLimits(aconf))
827 {
828 sendto_one_notice(source_p, ":*** You are exempt from user limits. congrats.");
829 }
830
831 if(IsConfExemptFlood(aconf))
832 {
833 SetExemptFlood(source_p);
834 sendto_one_notice(source_p, ":*** You are exempt from flood limits.");
835 }
836
837 if(IsConfExemptSpambot(aconf))
838 {
839 SetExemptSpambot(source_p);
840 sendto_one_notice(source_p, ":*** You are exempt from spambot checks.");
841 }
842
843 if(IsConfExemptJupe(aconf))
844 {
845 SetExemptJupe(source_p);
846 sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings.");
847 }
848
849 if(IsConfExemptResv(aconf))
850 {
851 SetExemptResv(source_p);
852 sendto_one_notice(source_p, ":*** You are exempt from resvs.");
853 }
854
855 if(IsConfExemptShide(aconf))
856 {
857 SetExemptShide(source_p);
858 sendto_one_notice(source_p, ":*** You are exempt from serverhiding.");
859 }
860 }
861
862 /*
863 * user_mode - set get current users mode
864 *
865 * m_umode() added 15/10/91 By Darren Reed.
866 * parv[0] - sender
867 * parv[1] - username to change mode for
868 * parv[2] - modes to change
869 */
870 int
871 user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
872 {
873 int flag;
874 int i;
875 char *m;
876 const char *pm;
877 struct Client *target_p;
878 int what, setflags;
879 int badflag = NO; /* Only send one bad flag notice */
880 int showsnomask = NO;
881 unsigned int setsnomask;
882 char buf[BUFSIZE];
883 hook_data_umode_changed hdata;
884
885 what = MODE_ADD;
886
887 if(parc < 2)
888 {
889 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE");
890 return 0;
891 }
892
893 if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL)
894 {
895 if(MyConnect(source_p))
896 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
897 form_str(ERR_NOSUCHCHANNEL), parv[1]);
898 return 0;
899 }
900
901 /* Dont know why these were commented out..
902 * put them back using new sendto() funcs
903 */
904
905 if(IsServer(source_p))
906 {
907 sendto_realops_snomask(SNO_GENERAL, L_ADMIN,
908 "*** Mode for User %s from %s", parv[1], source_p->name);
909 return 0;
910 }
911
912 if(source_p != target_p || target_p->from != source_p->from)
913 {
914 sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name);
915 return 0;
916 }
917
918 if(parc < 3)
919 {
920 m = buf;
921 *m++ = '+';
922
923 for (i = 0; i < 128; i++) /* >= 127 is extended ascii */
924 if (source_p->umodes & user_modes[i])
925 *m++ = (char) i;
926
927 *m = '\0';
928 sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf);
929
930 if (source_p->snomask != 0)
931 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
932 construct_snobuf(source_p->snomask));
933
934 return 0;
935 }
936
937 /* find flags already set for user */
938 setflags = source_p->umodes;
939 setsnomask = source_p->snomask;
940
941 /*
942 * parse mode change string(s)
943 */
944 for (pm = parv[2]; *pm; pm++)
945 switch (*pm)
946 {
947 case '+':
948 what = MODE_ADD;
949 break;
950 case '-':
951 what = MODE_DEL;
952 break;
953
954 case 'o':
955 if(what == MODE_ADD)
956 {
957 if(IsServer(client_p) && !IsOper(source_p))
958 {
959 ++Count.oper;
960 SetOper(source_p);
961 rb_dlinkAddAlloc(source_p, &oper_list);
962 }
963 }
964 else
965 {
966 /* Only decrement the oper counts if an oper to begin with
967 * found by Pat Szuta, Perly , perly@xnet.com
968 */
969
970 if(!IsOper(source_p))
971 break;
972
973 ClearOper(source_p);
974
975 Count.oper--;
976
977 if(MyConnect(source_p))
978 {
979 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
980 if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0)
981 {
982 source_p->snomask = 0;
983 showsnomask = YES;
984 }
985 source_p->flags2 &= ~OPER_FLAGS;
986
987 rb_free(source_p->localClient->opername);
988 source_p->localClient->opername = NULL;
989
990 rb_dlinkFindDestroy(source_p, &local_oper_list);
991 }
992
993 rb_dlinkFindDestroy(source_p, &oper_list);
994 }
995 break;
996
997 /* we may not get these,
998 * but they shouldnt be in default
999 */
1000
1001 /* can only be set on burst */
1002 case 'S':
1003 case 'Z':
1004 case ' ':
1005 case '\n':
1006 case '\r':
1007 case '\t':
1008 break;
1009
1010 case 's':
1011 if (MyConnect(source_p))
1012 {
1013 if(!IsOper(source_p)
1014 && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE))
1015 {
1016 if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE)
1017 badflag = YES;
1018 continue;
1019 }
1020 showsnomask = YES;
1021 if(what == MODE_ADD)
1022 {
1023 if (parc > 3)
1024 source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]);
1025 else
1026 source_p->snomask |= SNO_GENERAL;
1027 }
1028 else
1029 source_p->snomask = 0;
1030 if (source_p->snomask != 0)
1031 source_p->umodes |= UMODE_SERVNOTICE;
1032 else
1033 source_p->umodes &= ~UMODE_SERVNOTICE;
1034 break;
1035 }
1036 /* FALLTHROUGH */
1037 default:
1038 if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) {
1039 badflag = YES;
1040 break;
1041 }
1042
1043 if((flag = user_modes[(unsigned char) *pm]))
1044 {
1045 if(MyConnect(source_p)
1046 && ((!IsOper(source_p)
1047 && (ConfigFileEntry.oper_only_umodes & flag))
1048 || (orphaned_umodes & flag)))
1049 {
1050 if (what == MODE_ADD || source_p->umodes & flag)
1051 badflag = YES;
1052 }
1053 else
1054 {
1055 if(what == MODE_ADD)
1056 source_p->umodes |= flag;
1057 else
1058 source_p->umodes &= ~flag;
1059 }
1060 }
1061 else
1062 {
1063 if(MyConnect(source_p))
1064 badflag = YES;
1065 }
1066 break;
1067 }
1068
1069 if(badflag)
1070 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name);
1071
1072 if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p))
1073 {
1074 sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n");
1075 source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */
1076 }
1077
1078 if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p))
1079 {
1080 sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z");
1081 source_p->umodes &= ~UMODE_OPERWALL;
1082 }
1083
1084 if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
1085 (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p)))
1086 {
1087 sendto_one_notice(source_p, ":*** You need oper and admin flag for +a");
1088 source_p->umodes &= ~UMODE_ADMIN;
1089 }
1090
1091 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1092 hdata.client = source_p;
1093 hdata.oldumodes = setflags;
1094 hdata.oldsnomask = setsnomask;
1095 call_hook(h_umode_changed, &hdata);
1096
1097 if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
1098 ++Count.invisi;
1099 if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
1100 --Count.invisi;
1101 /*
1102 * compare new flags with old flags and send string which
1103 * will cause servers to update correctly.
1104 */
1105 send_umode_out(client_p, source_p, setflags);
1106 if (showsnomask && MyConnect(source_p))
1107 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
1108 construct_snobuf(source_p->snomask));
1109
1110 return (0);
1111 }
1112
1113 /*
1114 * send the MODE string for user (user) to connection client_p
1115 * -avalon
1116 */
1117 void
1118 send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf)
1119 {
1120 int i;
1121 int flag;
1122 char *m;
1123 int what = 0;
1124
1125 /*
1126 * build a string in umode_buf to represent the change in the user's
1127 * mode between the new (source_p->flag) and 'old'.
1128 */
1129 m = umode_buf;
1130 *m = '\0';
1131
1132 for (i = 0; i < 128; i++)
1133 {
1134 flag = user_modes[i];
1135
1136 if((flag & old) && !(source_p->umodes & flag))
1137 {
1138 if(what == MODE_DEL)
1139 *m++ = (char) i;
1140 else
1141 {
1142 what = MODE_DEL;
1143 *m++ = '-';
1144 *m++ = (char) i;
1145 }
1146 }
1147 else if(!(flag & old) && (source_p->umodes & flag))
1148 {
1149 if(what == MODE_ADD)
1150 *m++ = (char) i;
1151 else
1152 {
1153 what = MODE_ADD;
1154 *m++ = '+';
1155 *m++ = (char) i;
1156 }
1157 }
1158 }
1159 *m = '\0';
1160
1161 if(*umode_buf && client_p)
1162 sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf);
1163 }
1164
1165 /*
1166 * send_umode_out
1167 *
1168 * inputs -
1169 * output - NONE
1170 * side effects -
1171 */
1172 void
1173 send_umode_out(struct Client *client_p, struct Client *source_p, int old)
1174 {
1175 struct Client *target_p;
1176 char buf[BUFSIZE];
1177 rb_dlink_node *ptr;
1178
1179 send_umode(NULL, source_p, old, 0, buf);
1180
1181 RB_DLINK_FOREACH(ptr, serv_list.head)
1182 {
1183 target_p = ptr->data;
1184
1185 if((target_p != client_p) && (target_p != source_p) && (*buf))
1186 {
1187 sendto_one(target_p, ":%s MODE %s :%s",
1188 get_id(source_p, target_p),
1189 get_id(source_p, target_p), buf);
1190 }
1191 }
1192
1193 if(client_p && MyClient(client_p))
1194 send_umode(client_p, source_p, old, 0, buf);
1195 }
1196
1197 /*
1198 * user_welcome
1199 *
1200 * inputs - client pointer to client to welcome
1201 * output - NONE
1202 * side effects -
1203 */
1204 void
1205 user_welcome(struct Client *source_p)
1206 {
1207 sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name);
1208 sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST),
1209 get_listener_name(source_p->localClient->listener), ircd_version);
1210 sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation);
1211 sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf);
1212
1213 show_isupport(source_p);
1214
1215 show_lusers(source_p);
1216
1217 if(ConfigFileEntry.short_motd)
1218 {
1219 sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed);
1220 sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it");
1221
1222 sendto_one(source_p, form_str(RPL_MOTDSTART),
1223 me.name, source_p->name, me.name);
1224
1225 sendto_one(source_p, form_str(RPL_MOTD),
1226 me.name, source_p->name, "*** This is the short motd ***");
1227
1228 sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name);
1229 }
1230 else
1231 send_user_motd(source_p);
1232 }
1233
1234 /* oper_up()
1235 *
1236 * inputs - pointer to given client to oper
1237 * - pointer to ConfItem to use
1238 * output - none
1239 * side effects - opers up source_p using aconf for reference
1240 */
1241 int
1242 oper_up(struct Client *source_p, struct oper_conf *oper_p)
1243 {
1244 unsigned int old = source_p->umodes, oldsnomask = source_p->snomask;
1245 hook_data_umode_changed hdata;
1246
1247 SetOper(source_p);
1248
1249 if(oper_p->umodes)
1250 source_p->umodes |= oper_p->umodes;
1251 else if(ConfigFileEntry.oper_umodes)
1252 source_p->umodes |= ConfigFileEntry.oper_umodes;
1253 else
1254 source_p->umodes |= DEFAULT_OPER_UMODES;
1255
1256 if (oper_p->snomask)
1257 {
1258 source_p->snomask |= oper_p->snomask;
1259 source_p->umodes |= UMODE_SERVNOTICE;
1260 }
1261 else if (source_p->umodes & UMODE_SERVNOTICE)
1262 {
1263 /* Only apply these if +s is already set -- jilles */
1264 if (ConfigFileEntry.oper_snomask)
1265 source_p->snomask |= ConfigFileEntry.oper_snomask;
1266 else
1267 source_p->snomask |= DEFAULT_OPER_SNOMASK;
1268 }
1269
1270 Count.oper++;
1271
1272 SetExemptKline(source_p);
1273
1274 source_p->flags2 |= oper_p->flags;
1275 source_p->localClient->opername = rb_strdup(oper_p->name);
1276
1277 rb_dlinkAddAlloc(source_p, &local_oper_list);
1278 rb_dlinkAddAlloc(source_p, &oper_list);
1279
1280 if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
1281 source_p->umodes |= UMODE_ADMIN;
1282 if(!IsOperN(source_p))
1283 source_p->snomask &= ~SNO_NCHANGE;
1284 if(!IsOperOperwall(source_p))
1285 source_p->umodes &= ~UMODE_OPERWALL;
1286 hdata.client = source_p;
1287 hdata.oldumodes = old;
1288 hdata.oldsnomask = oldsnomask;
1289 call_hook(h_umode_changed, &hdata);
1290
1291 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1292 "%s (%s@%s) is now an operator", source_p->name,
1293 source_p->username, source_p->host);
1294 if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1295 ++Count.invisi;
1296 if((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1297 --Count.invisi;
1298 send_umode_out(source_p, source_p, old);
1299 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
1300 construct_snobuf(source_p->snomask));
1301 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1302 sendto_one_notice(source_p, ":*** Oper privs are %s", get_oper_privs(oper_p->flags));
1303 send_oper_motd(source_p);
1304
1305 return (1);
1306 }
1307
1308 /*
1309 * find_umode_slot
1310 *
1311 * inputs - NONE
1312 * outputs - an available umode bitmask or
1313 * 0 if no umodes are available
1314 * side effects - NONE
1315 */
1316 unsigned int
1317 find_umode_slot(void)
1318 {
1319 unsigned int all_umodes = 0, my_umode = 0, i;
1320
1321 for (i = 0; i < 128; i++)
1322 all_umodes |= user_modes[i];
1323
1324 for (my_umode = 1; my_umode && (all_umodes & my_umode);
1325 my_umode <<= 1);
1326
1327 return my_umode;
1328 }
1329
1330 void
1331 construct_umodebuf(void)
1332 {
1333 int i;
1334 char *ptr = umodebuf;
1335 static int prev_user_modes[128];
1336
1337 *ptr = '\0';
1338
1339 for (i = 0; i < 128; i++)
1340 {
1341 if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i])
1342 {
1343 if (user_modes[i] == 0)
1344 {
1345 orphaned_umodes |= prev_user_modes[i];
1346 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i);
1347 }
1348 else
1349 {
1350 orphaned_umodes &= ~prev_user_modes[i];
1351 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i);
1352 }
1353 user_modes[i] = prev_user_modes[i];
1354 }
1355 else
1356 prev_user_modes[i] = user_modes[i];
1357 if (user_modes[i])
1358 *ptr++ = (char) i;
1359 }
1360
1361 *ptr++ = '\0';
1362 }
1363
1364 void
1365 change_nick_user_host(struct Client *target_p, const char *nick, const char *user,
1366 const char *host, int newts, const char *format, ...)
1367 {
1368 rb_dlink_node *ptr;
1369 struct Channel *chptr;
1370 struct membership *mscptr;
1371 int changed = irccmp(target_p->name, nick);
1372 int changed_case = strcmp(target_p->name, nick);
1373 int do_qjm = irccmp(target_p->username, user) || irccmp(target_p->host, host);
1374 char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr;
1375 va_list ap;
1376
1377 modeval[0] = '\0';
1378
1379 if(changed)
1380 {
1381 target_p->tsinfo = newts;
1382 monitor_signoff(target_p);
1383 }
1384 invalidate_bancache_user(target_p);
1385
1386 if(do_qjm)
1387 {
1388 va_start(ap, format);
1389 vsnprintf(reason, 255, format, ap);
1390 va_end(ap);
1391
1392 sendto_common_channels_local_butone(target_p, ":%s!%s@%s QUIT :%s",
1393 target_p->name, target_p->username, target_p->host,
1394 reason);
1395
1396 RB_DLINK_FOREACH(ptr, target_p->user->channel.head)
1397 {
1398 mscptr = ptr->data;
1399 chptr = mscptr->chptr;
1400 mptr = mode;
1401
1402 if(is_chanop(mscptr))
1403 {
1404 *mptr++ = 'o';
1405 strcat(modeval, nick);
1406 strcat(modeval, " ");
1407 }
1408
1409 if(is_voiced(mscptr))
1410 {
1411 *mptr++ = 'v';
1412 strcat(modeval, nick);
1413 }
1414
1415 *mptr = '\0';
1416
1417 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
1418 nick, user, host, chptr->chname);
1419 if(*mode)
1420 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr,
1421 ":%s MODE %s +%s %s",
1422 target_p->servptr->name,
1423 chptr->chname, mode, modeval);
1424
1425 *modeval = '\0';
1426 }
1427
1428 if(MyClient(target_p) && changed_case)
1429 sendto_one(target_p, ":%s!%s@%s NICK %s",
1430 target_p->name, target_p->username, target_p->host, nick);
1431 }
1432 else if(changed_case)
1433 {
1434 sendto_common_channels_local(target_p, ":%s!%s@%s NICK :%s",
1435 target_p->name, target_p->username,
1436 target_p->host, nick);
1437 }
1438
1439 rb_strlcpy(target_p->username, user, sizeof target_p->username);
1440 rb_strlcpy(target_p->host, host, sizeof target_p->host);
1441
1442 if (changed)
1443 add_history(target_p, 1);
1444
1445 del_from_client_hash(target_p->name, target_p);
1446 rb_strlcpy(target_p->name, nick, NICKLEN);
1447 add_to_client_hash(target_p->name, target_p);
1448
1449 if(changed)
1450 {
1451 monitor_signon(target_p);
1452 del_all_accepts(target_p);
1453 }
1454 }