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