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