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