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