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