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