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