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