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