]> jfr.im git - irc/rqf/shadowircd.git/blob - src/s_user.c
ce4e3eca36b6d29fc95d527352e90ae7c69d5320
[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 3584 2007-11-20 11:08:23Z nenolod $
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 if(dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount)
151 MaxClientCount = dlink_list_length(&lclient_list);
152
153 if((dlink_list_length(&lclient_list) + dlink_list_length(&serv_list)) >
154 (unsigned long)MaxConnectionCount)
155 MaxConnectionCount = dlink_list_length(&lclient_list) +
156 dlink_list_length(&serv_list);
157
158 sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT),
159 (Count.total - Count.invisi),
160 Count.invisi, dlink_list_length(&global_serv_list));
161
162 if(dlink_list_length(&oper_list) > 0)
163 sendto_one_numeric(source_p, RPL_LUSEROP,
164 form_str(RPL_LUSEROP), dlink_list_length(&oper_list));
165
166 if(dlink_list_length(&unknown_list) > 0)
167 sendto_one_numeric(source_p, RPL_LUSERUNKNOWN,
168 form_str(RPL_LUSERUNKNOWN),
169 dlink_list_length(&unknown_list));
170
171 if(dlink_list_length(&global_channel_list) > 0)
172 sendto_one_numeric(source_p, RPL_LUSERCHANNELS,
173 form_str(RPL_LUSERCHANNELS),
174 dlink_list_length(&global_channel_list));
175
176 sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME),
177 dlink_list_length(&lclient_list),
178 dlink_list_length(&serv_list));
179
180 sendto_one_numeric(source_p, RPL_LOCALUSERS,
181 form_str(RPL_LOCALUSERS),
182 dlink_list_length(&lclient_list),
183 Count.max_loc,
184 dlink_list_length(&lclient_list),
185 Count.max_loc);
186
187 sendto_one_numeric(source_p, RPL_GLOBALUSERS, form_str(RPL_GLOBALUSERS),
188 Count.total, Count.max_tot,
189 Count.total, Count.max_tot);
190
191 sendto_one_numeric(source_p, RPL_STATSCONN,
192 form_str(RPL_STATSCONN),
193 MaxConnectionCount, MaxClientCount,
194 Count.totalrestartcount);
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) >=
406 (unsigned long)GlobalSetOptions.maxclients && !IsExemptLimits(source_p))
407 {
408 sendto_realops_snomask(SNO_FULL, L_ALL,
409 "Too many clients, rejecting %s[%s].", source_p->name, source_p->host);
410
411 ServerStats->is_ref++;
412 exit_client(client_p, source_p, &me, "Sorry, server is full - try later");
413 return (CLIENT_EXITED);
414 }
415
416 /* kline exemption extends to xline too */
417 if(!IsExemptKline(source_p) &&
418 find_xline(source_p->info, 1) != NULL)
419 {
420 ServerStats->is_ref++;
421 add_reject(source_p);
422 exit_client(client_p, source_p, &me, "Bad user info");
423 return CLIENT_EXITED;
424 }
425
426 /* dnsbl check */
427 if (source_p->preClient->dnsbl_listed != NULL)
428 {
429 if (IsExemptKline(source_p) || IsConfExemptDNSBL(aconf))
430 sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s, but you are exempt",
431 source_p->sockhost, source_p->preClient->dnsbl_listed->host);
432 else
433 {
434 dlink_list varlist = { NULL, NULL, 0 };
435
436 substitution_append_var(&varlist, "nick", source_p->name);
437 substitution_append_var(&varlist, "ip", source_p->sockhost);
438 substitution_append_var(&varlist, "host", source_p->host);
439 substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->dnsbl_listed->host);
440 substitution_append_var(&varlist, "network-name", ServerInfo.network_name);
441
442 ServerStats->is_ref++;
443
444 sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP),
445 me.name, source_p->name,
446 substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist));
447
448 substitution_free(&varlist);
449
450 sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s",
451 source_p->sockhost, source_p->preClient->dnsbl_listed->host);
452 source_p->preClient->dnsbl_listed->hits++;
453 add_reject(source_p);
454 exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)");
455 return CLIENT_EXITED;
456 }
457 }
458
459 /* valid user name check */
460
461 if(!valid_username(source_p->username))
462 {
463 sendto_realops_snomask(SNO_REJ, L_ALL,
464 "Invalid username: %s (%s@%s)",
465 source_p->name, source_p->username, source_p->host);
466 ServerStats->is_ref++;
467 sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains "
468 "only alphanumeric characters.");
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 source_p->umodes |= ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes & ~orphaned_umodes;
490
491 call_hook(h_new_local_user, source_p);
492
493 /* If they have died in send_* or were thrown out by the
494 * new_local_user hook don't do anything. */
495 if(IsAnyDead(source_p))
496 return CLIENT_EXITED;
497
498 /* To avoid inconsistencies, do not abort the registration
499 * starting from this point -- jilles
500 */
501 inetntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
502
503 sendto_realops_snomask(SNO_CCONN, L_ALL,
504 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
505 source_p->name, source_p->username, source_p->orighost,
506 show_ip(NULL, source_p) ? ipaddr : "255.255.255.255",
507 get_client_class(source_p), source_p->info);
508
509 sendto_realops_snomask(SNO_CCONNEXT, L_ALL,
510 "CLICONN %s %s %s %s %s %s 0 %s",
511 source_p->name, source_p->username, source_p->orighost,
512 show_ip(NULL, source_p) ? ipaddr : "255.255.255.255",
513 get_client_class(source_p),
514 /* mirc can sometimes send ips here */
515 show_ip(NULL, source_p) ? source_p->localClient->fullcaps : "<hidden> <hidden>",
516 source_p->info);
517
518 add_to_hostname_hash(source_p->orighost, source_p);
519
520 /* Allocate a UID if it was not previously allocated.
521 * If this already occured, it was probably during SASL auth...
522 */
523 if(!*source_p->id)
524 {
525 strcpy(source_p->id, generate_uid());
526 add_to_id_hash(source_p->id, source_p);
527 }
528
529 if (source_p->umodes & UMODE_INVISIBLE)
530 Count.invisi++;
531
532 s_assert(!IsClient(source_p));
533 del_unknown_ip(source_p);
534 dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list);
535 SetClient(source_p);
536
537 /* XXX source_p->servptr is &me, since local client */
538 source_p->servptr = find_server(NULL, user->server);
539 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
540 /* Increment our total user count here */
541 if(++Count.total > Count.max_tot)
542 Count.max_tot = Count.total;
543 source_p->localClient->allow_read = MAX_FLOOD_BURST;
544
545 Count.totalrestartcount++;
546
547 s_assert(source_p->localClient != NULL);
548
549 if(dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc)
550 {
551 Count.max_loc = 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 user->server, 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 user->server, 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 MyFree(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/D/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 SetExemptLimits(source_p);
839 sendto_one_notice(source_p, "*** You are exempt from user limits. congrats.");
840 }
841
842 /* If this user is exempt from idle time outs */
843 if(IsConfIdlelined(aconf))
844 {
845 SetIdlelined(source_p);
846 sendto_one_notice(source_p, ":*** You are exempt from idle limits. congrats.");
847 }
848
849 if(IsConfExemptFlood(aconf))
850 {
851 SetExemptFlood(source_p);
852 sendto_one_notice(source_p, ":*** You are exempt from flood limits.");
853 }
854
855 if(IsConfExemptSpambot(aconf))
856 {
857 SetExemptSpambot(source_p);
858 sendto_one_notice(source_p, ":*** You are exempt from spambot checks.");
859 }
860
861 if(IsConfExemptJupe(aconf))
862 {
863 SetExemptJupe(source_p);
864 sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings.");
865 }
866
867 if(IsConfExemptResv(aconf))
868 {
869 SetExemptResv(source_p);
870 sendto_one_notice(source_p, ":*** You are exempt from resvs.");
871 }
872
873 if(IsConfExemptShide(aconf))
874 {
875 SetExemptShide(source_p);
876 sendto_one_notice(source_p, ":*** You are exempt from serverhiding.");
877 }
878 }
879
880 /*
881 * user_mode - set get current users mode
882 *
883 * m_umode() added 15/10/91 By Darren Reed.
884 * parv[0] - sender
885 * parv[1] - username to change mode for
886 * parv[2] - modes to change
887 */
888 int
889 user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
890 {
891 int flag;
892 int i;
893 char *m;
894 const char *pm;
895 struct Client *target_p;
896 int what, setflags;
897 int badflag = NO; /* Only send one bad flag notice */
898 int showsnomask = NO;
899 unsigned int setsnomask;
900 char buf[BUFSIZE];
901 hook_data_umode_changed hdata;
902
903 what = MODE_ADD;
904
905 if(parc < 2)
906 {
907 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE");
908 return 0;
909 }
910
911 if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL)
912 {
913 if(MyConnect(source_p))
914 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
915 form_str(ERR_NOSUCHCHANNEL), parv[1]);
916 return 0;
917 }
918
919 /* Dont know why these were commented out..
920 * put them back using new sendto() funcs
921 */
922
923 if(IsServer(source_p))
924 {
925 sendto_realops_snomask(SNO_GENERAL, L_ADMIN,
926 "*** Mode for User %s from %s", parv[1], source_p->name);
927 return 0;
928 }
929
930 if(source_p != target_p || target_p->from != source_p->from)
931 {
932 sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name);
933 return 0;
934 }
935
936 if(parc < 3)
937 {
938 m = buf;
939 *m++ = '+';
940
941 for (i = 0; i < 128; i++) /* >= 127 is extended ascii */
942 if (source_p->umodes & user_modes[i])
943 *m++ = (char) i;
944
945 *m = '\0';
946 sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf);
947
948 if (source_p->snomask != 0)
949 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
950 construct_snobuf(source_p->snomask));
951
952 return 0;
953 }
954
955 /* find flags already set for user */
956 setflags = source_p->umodes;
957 setsnomask = source_p->snomask;
958
959 /*
960 * parse mode change string(s)
961 */
962 for (pm = parv[2]; *pm; pm++)
963 switch (*pm)
964 {
965 case '+':
966 what = MODE_ADD;
967 break;
968 case '-':
969 what = MODE_DEL;
970 break;
971
972 case 'o':
973 if(what == MODE_ADD)
974 {
975 if(IsServer(client_p) && !IsOper(source_p))
976 {
977 ++Count.oper;
978 SetOper(source_p);
979 dlinkAddAlloc(source_p, &oper_list);
980 }
981 }
982 else
983 {
984 /* Only decrement the oper counts if an oper to begin with
985 * found by Pat Szuta, Perly , perly@xnet.com
986 */
987
988 if(!IsOper(source_p))
989 break;
990
991 ClearOper(source_p);
992
993 Count.oper--;
994
995 if(MyConnect(source_p))
996 {
997 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
998 if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0)
999 {
1000 source_p->snomask = 0;
1001 showsnomask = YES;
1002 }
1003 source_p->flags2 &= ~OPER_FLAGS;
1004
1005 MyFree(source_p->localClient->opername);
1006 source_p->localClient->opername = NULL;
1007
1008 dlinkFindDestroy(source_p, &local_oper_list);
1009 }
1010
1011 dlinkFindDestroy(source_p, &oper_list);
1012 }
1013 break;
1014
1015 /* we may not get these,
1016 * but they shouldnt be in default
1017 */
1018
1019 /* can only be set on burst */
1020 case 'S':
1021 case ' ':
1022 case '\n':
1023 case '\r':
1024 case '\t':
1025 break;
1026
1027 case 's':
1028 if (MyConnect(source_p))
1029 {
1030 if(!IsOper(source_p)
1031 && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE))
1032 {
1033 if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE)
1034 badflag = YES;
1035 continue;
1036 }
1037 showsnomask = YES;
1038 if(what == MODE_ADD)
1039 {
1040 if (parc > 3)
1041 source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]);
1042 else
1043 source_p->snomask |= SNO_GENERAL;
1044 }
1045 else
1046 source_p->snomask = 0;
1047 if (source_p->snomask != 0)
1048 source_p->umodes |= UMODE_SERVNOTICE;
1049 else
1050 source_p->umodes &= ~UMODE_SERVNOTICE;
1051 break;
1052 }
1053 /* FALLTHROUGH */
1054 default:
1055 if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) {
1056 badflag = YES;
1057 break;
1058 }
1059
1060 if((flag = user_modes[(unsigned char) *pm]))
1061 {
1062 if(MyConnect(source_p)
1063 && ((!IsOper(source_p)
1064 && (ConfigFileEntry.oper_only_umodes & flag))
1065 || (orphaned_umodes & flag)))
1066 {
1067 if (what == MODE_ADD || source_p->umodes & flag)
1068 badflag = YES;
1069 }
1070 else
1071 {
1072 if(what == MODE_ADD)
1073 source_p->umodes |= flag;
1074 else
1075 source_p->umodes &= ~flag;
1076 }
1077 }
1078 else
1079 {
1080 if(MyConnect(source_p))
1081 badflag = YES;
1082 }
1083 break;
1084 }
1085
1086 if(badflag)
1087 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name);
1088
1089 if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p))
1090 {
1091 sendto_one_notice(source_p, ":*** You need oper and N flag for +s +n");
1092 source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */
1093 }
1094
1095 if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p))
1096 {
1097 sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z");
1098 source_p->umodes &= ~UMODE_OPERWALL;
1099 }
1100
1101 if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
1102 (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p)))
1103 {
1104 sendto_one_notice(source_p, ":*** You need oper and A flag for +a");
1105 source_p->umodes &= ~UMODE_ADMIN;
1106 }
1107
1108 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1109 hdata.client = source_p;
1110 hdata.oldumodes = setflags;
1111 hdata.oldsnomask = setsnomask;
1112 call_hook(h_umode_changed, &hdata);
1113
1114 if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
1115 ++Count.invisi;
1116 if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
1117 --Count.invisi;
1118 /*
1119 * compare new flags with old flags and send string which
1120 * will cause servers to update correctly.
1121 */
1122 send_umode_out(client_p, source_p, setflags);
1123 if (showsnomask && MyConnect(source_p))
1124 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
1125 construct_snobuf(source_p->snomask));
1126
1127 return (0);
1128 }
1129
1130 /*
1131 * send the MODE string for user (user) to connection client_p
1132 * -avalon
1133 */
1134 void
1135 send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf)
1136 {
1137 int i;
1138 int flag;
1139 char *m;
1140 int what = 0;
1141
1142 /*
1143 * build a string in umode_buf to represent the change in the user's
1144 * mode between the new (source_p->flag) and 'old'.
1145 */
1146 m = umode_buf;
1147 *m = '\0';
1148
1149 for (i = 0; i < 128; i++)
1150 {
1151 flag = user_modes[i];
1152
1153 if((flag & old) && !(source_p->umodes & flag))
1154 {
1155 if(what == MODE_DEL)
1156 *m++ = (char) i;
1157 else
1158 {
1159 what = MODE_DEL;
1160 *m++ = '-';
1161 *m++ = (char) i;
1162 }
1163 }
1164 else if(!(flag & old) && (source_p->umodes & flag))
1165 {
1166 if(what == MODE_ADD)
1167 *m++ = (char) i;
1168 else
1169 {
1170 what = MODE_ADD;
1171 *m++ = '+';
1172 *m++ = (char) i;
1173 }
1174 }
1175 }
1176 *m = '\0';
1177
1178 if(*umode_buf && client_p)
1179 sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf);
1180 }
1181
1182 /*
1183 * send_umode_out
1184 *
1185 * inputs -
1186 * output - NONE
1187 * side effects -
1188 */
1189 void
1190 send_umode_out(struct Client *client_p, struct Client *source_p, int old)
1191 {
1192 struct Client *target_p;
1193 char buf[BUFSIZE];
1194 dlink_node *ptr;
1195
1196 send_umode(NULL, source_p, old, 0, buf);
1197
1198 DLINK_FOREACH(ptr, serv_list.head)
1199 {
1200 target_p = ptr->data;
1201
1202 if((target_p != client_p) && (target_p != source_p) && (*buf))
1203 {
1204 sendto_one(target_p, ":%s MODE %s :%s",
1205 get_id(source_p, target_p),
1206 get_id(source_p, target_p), buf);
1207 }
1208 }
1209
1210 if(client_p && MyClient(client_p))
1211 send_umode(client_p, source_p, old, 0, buf);
1212 }
1213
1214 /*
1215 * user_welcome
1216 *
1217 * inputs - client pointer to client to welcome
1218 * output - NONE
1219 * side effects -
1220 */
1221 void
1222 user_welcome(struct Client *source_p)
1223 {
1224 sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name);
1225 sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST),
1226 get_listener_name(source_p->localClient->listener), ircd_version);
1227 sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation);
1228 sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf);
1229
1230 show_isupport(source_p);
1231
1232 show_lusers(source_p);
1233
1234 if(ConfigFileEntry.short_motd)
1235 {
1236 sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed);
1237 sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it");
1238
1239 sendto_one(source_p, form_str(RPL_MOTDSTART),
1240 me.name, source_p->name, me.name);
1241
1242 sendto_one(source_p, form_str(RPL_MOTD),
1243 me.name, source_p->name, "*** This is the short motd ***");
1244
1245 sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name);
1246 }
1247 else
1248 send_user_motd(source_p);
1249 }
1250
1251 /* oper_up()
1252 *
1253 * inputs - pointer to given client to oper
1254 * - pointer to ConfItem to use
1255 * output - none
1256 * side effects - opers up source_p using aconf for reference
1257 */
1258 int
1259 oper_up(struct Client *source_p, struct oper_conf *oper_p)
1260 {
1261 unsigned int old = source_p->umodes, oldsnomask = source_p->snomask;
1262 hook_data_umode_changed hdata;
1263
1264 SetOper(source_p);
1265
1266 if(oper_p->umodes)
1267 source_p->umodes |= oper_p->umodes;
1268 else if(ConfigFileEntry.oper_umodes)
1269 source_p->umodes |= ConfigFileEntry.oper_umodes;
1270 else
1271 source_p->umodes |= DEFAULT_OPER_UMODES;
1272
1273 if (oper_p->snomask)
1274 {
1275 source_p->snomask |= oper_p->snomask;
1276 source_p->umodes |= UMODE_SERVNOTICE;
1277 }
1278 else if (source_p->umodes & UMODE_SERVNOTICE)
1279 {
1280 /* Only apply these if +s is already set -- jilles */
1281 if (ConfigFileEntry.oper_snomask)
1282 source_p->snomask |= ConfigFileEntry.oper_snomask;
1283 else
1284 source_p->snomask |= DEFAULT_OPER_SNOMASK;
1285 }
1286
1287 Count.oper++;
1288
1289 SetExemptKline(source_p);
1290
1291 source_p->flags2 |= oper_p->flags;
1292 DupString(source_p->localClient->opername, oper_p->name);
1293
1294 dlinkAddAlloc(source_p, &local_oper_list);
1295 dlinkAddAlloc(source_p, &oper_list);
1296
1297 if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
1298 source_p->umodes |= UMODE_ADMIN;
1299 if(!IsOperN(source_p))
1300 source_p->snomask &= ~SNO_NCHANGE;
1301 if(!IsOperOperwall(source_p))
1302 source_p->umodes &= ~UMODE_OPERWALL;
1303 hdata.client = source_p;
1304 hdata.oldumodes = old;
1305 hdata.oldsnomask = oldsnomask;
1306 call_hook(h_umode_changed, &hdata);
1307
1308 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1309 "%s (%s@%s) is now an operator", source_p->name,
1310 source_p->username, source_p->host);
1311 if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1312 ++Count.invisi;
1313 if((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1314 --Count.invisi;
1315 send_umode_out(source_p, source_p, old);
1316 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
1317 construct_snobuf(source_p->snomask));
1318 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1319 sendto_one_notice(source_p, ":*** Oper privs are %s", get_oper_privs(oper_p->flags));
1320 send_oper_motd(source_p);
1321
1322 return (1);
1323 }
1324
1325 /*
1326 * find_umode_slot
1327 *
1328 * inputs - NONE
1329 * outputs - an available umode bitmask or
1330 * 0 if no umodes are available
1331 * side effects - NONE
1332 */
1333 unsigned int
1334 find_umode_slot(void)
1335 {
1336 unsigned int all_umodes = 0, my_umode = 0, i;
1337
1338 for (i = 0; i < 128; i++)
1339 all_umodes |= user_modes[i];
1340
1341 for (my_umode = 1; my_umode && (all_umodes & my_umode);
1342 my_umode <<= 1);
1343
1344 return my_umode;
1345 }
1346
1347 void
1348 construct_umodebuf(void)
1349 {
1350 int i;
1351 char *ptr = umodebuf;
1352 static int prev_user_modes[128];
1353
1354 *ptr = '\0';
1355
1356 for (i = 0; i < 128; i++)
1357 {
1358 if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i])
1359 {
1360 if (user_modes[i] == 0)
1361 {
1362 orphaned_umodes |= prev_user_modes[i];
1363 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i);
1364 }
1365 else
1366 {
1367 orphaned_umodes &= ~prev_user_modes[i];
1368 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i);
1369 }
1370 user_modes[i] = prev_user_modes[i];
1371 }
1372 else
1373 prev_user_modes[i] = user_modes[i];
1374 if (user_modes[i])
1375 *ptr++ = (char) i;
1376 }
1377
1378 *ptr++ = '\0';
1379 }
1380
1381 void
1382 change_nick_user_host(struct Client *target_p, const char *nick, const char *user,
1383 const char *host, int newts, char *format, ...)
1384 {
1385 dlink_node *ptr;
1386 struct Channel *chptr;
1387 struct membership *mscptr;
1388 int changed = irccmp(target_p->name, nick);
1389 int changed_case = strcmp(target_p->name, nick);
1390 int do_qjm = irccmp(target_p->username, user) || irccmp(target_p->host, host);
1391 char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr;
1392 va_list ap;
1393
1394 modeval[0] = '\0';
1395
1396 if(changed)
1397 {
1398 target_p->tsinfo = newts;
1399 monitor_signoff(target_p);
1400 }
1401 invalidate_bancache_user(target_p);
1402
1403 if(do_qjm)
1404 {
1405 va_start(ap, format);
1406 vsnprintf(reason, 255, format, ap);
1407 va_end(ap);
1408
1409 sendto_common_channels_local_butone(target_p, ":%s!%s@%s QUIT :%s",
1410 target_p->name, target_p->username, target_p->host,
1411 reason);
1412
1413 DLINK_FOREACH(ptr, target_p->user->channel.head)
1414 {
1415 mscptr = ptr->data;
1416 chptr = mscptr->chptr;
1417 mptr = mode;
1418
1419 if(is_chanop(mscptr))
1420 {
1421 *mptr++ = 'o';
1422 strcat(modeval, nick);
1423 strcat(modeval, " ");
1424 }
1425
1426 if(is_voiced(mscptr))
1427 {
1428 *mptr++ = 'v';
1429 strcat(modeval, nick);
1430 }
1431
1432 *mptr = '\0';
1433
1434 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
1435 nick, user, host, chptr->chname);
1436 if(*mode)
1437 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr,
1438 ":%s MODE %s +%s %s",
1439 target_p->servptr->name,
1440 chptr->chname, mode, modeval);
1441
1442 *modeval = '\0';
1443 }
1444
1445 if(MyClient(target_p) && changed_case)
1446 sendto_one(target_p, ":%s!%s@%s NICK %s",
1447 target_p->name, target_p->username, target_p->host, nick);
1448 }
1449 else if(changed_case)
1450 {
1451 sendto_common_channels_local(target_p, ":%s!%s@%s NICK :%s",
1452 target_p->name, target_p->username,
1453 target_p->host, nick);
1454 }
1455
1456 strlcpy(target_p->username, user, sizeof target_p->username);
1457 strlcpy(target_p->host, host, sizeof target_p->host);
1458
1459 if (changed)
1460 add_history(target_p, 1);
1461
1462 del_from_client_hash(target_p->name, target_p);
1463 strlcpy(target_p->name, nick, NICKLEN);
1464 add_to_client_hash(target_p->name, target_p);
1465
1466 if(changed)
1467 {
1468 monitor_signon(target_p);
1469 del_all_accepts(target_p);
1470 }
1471 }