]> jfr.im git - solanum.git/blame - src/s_user.c
Apply extended-join client cap to QJM joins
[solanum.git] / src / s_user.c
CommitLineData
212380e3
AC
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
AC
25 */
26
27#include "stdinc.h"
212380e3
AC
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"
4562c604 34#include "match.h"
212380e3
AC
35#include "ircd.h"
36#include "listener.h"
37#include "msg.h"
38#include "numeric.h"
212380e3
AC
39#include "s_conf.h"
40#include "s_newconf.h"
4016731b 41#include "logger.h"
212380e3
AC
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
AC
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"
c18cb68b 56#include "chmode.h"
212380e3
AC
57
58static void report_and_set_user_flags(struct Client *, struct ConfItem *);
59void user_welcome(struct Client *source_p);
60
212380e3
AC
61char umodebuf[128];
62
a8086a7c 63static int orphaned_umodes = 0;
212380e3
AC
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 */
3318e109 95 UMODE_SSLCLIENT, /* Z */
212380e3
AC
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{
330fc5c1
AC
145 if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount)
146 MaxClientCount = rb_dlink_list_length(&lclient_list);
2f15f871 147
330fc5c1 148 if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) >
2f15f871 149 (unsigned long)MaxConnectionCount)
330fc5c1
AC
150 MaxConnectionCount = rb_dlink_list_length(&lclient_list) +
151 rb_dlink_list_length(&serv_list);
2f15f871 152
212380e3
AC
153 sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT),
154 (Count.total - Count.invisi),
330fc5c1 155 Count.invisi, rb_dlink_list_length(&global_serv_list));
212380e3 156
330fc5c1 157 if(rb_dlink_list_length(&oper_list) > 0)
212380e3 158 sendto_one_numeric(source_p, RPL_LUSEROP,
330fc5c1 159 form_str(RPL_LUSEROP), rb_dlink_list_length(&oper_list));
212380e3 160
330fc5c1 161 if(rb_dlink_list_length(&unknown_list) > 0)
212380e3
AC
162 sendto_one_numeric(source_p, RPL_LUSERUNKNOWN,
163 form_str(RPL_LUSERUNKNOWN),
330fc5c1 164 rb_dlink_list_length(&unknown_list));
212380e3 165
330fc5c1 166 if(rb_dlink_list_length(&global_channel_list) > 0)
212380e3
AC
167 sendto_one_numeric(source_p, RPL_LUSERCHANNELS,
168 form_str(RPL_LUSERCHANNELS),
330fc5c1 169 rb_dlink_list_length(&global_channel_list));
212380e3
AC
170
171 sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME),
330fc5c1
AC
172 rb_dlink_list_length(&lclient_list),
173 rb_dlink_list_length(&serv_list));
212380e3
AC
174
175 sendto_one_numeric(source_p, RPL_LOCALUSERS,
176 form_str(RPL_LOCALUSERS),
330fc5c1 177 rb_dlink_list_length(&lclient_list),
212380e3 178 Count.max_loc,
330fc5c1 179 rb_dlink_list_length(&lclient_list),
212380e3
AC
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
AC
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
AC
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 }
095328a7 248 if(!(source_p->flags & FLAGS_PING_COOKIE))
212380e3
AC
249 {
250 return -1;
251 }
252 }
253
254 /* hasnt finished client cap negotiation */
095328a7 255 if(source_p->flags & FLAGS_CLICAP)
212380e3
AC
256 return -1;
257
258 /* still has DNSbls to validate against */
330fc5c1 259 if(rb_dlink_list_length(&source_p->preClient->dnsbl_queries) > 0)
212380e3
AC
260 return -1;
261
e3354945 262 client_p->localClient->last = rb_current_time();
212380e3
AC
263
264 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
265 if(!IsGotId(source_p) && (strchr(username, '[') != NULL))
266 {
267 const char *p;
268 int i = 0;
269
270 p = username;
271
272 while(*p && i < USERLEN)
273 {
274 if(*p != '[')
275 myusername[i++] = *p;
276 p++;
277 }
278
279 myusername[i] = '\0';
280 username = myusername;
281 }
282
283 if((status = check_client(client_p, source_p, username)) < 0)
284 return (CLIENT_EXITED);
285
286 /* Apply nick override */
287 if(*source_p->preClient->spoofnick)
288 {
fa94d8fb
AC
289 char note[NICKLEN + 10];
290
212380e3 291 del_from_client_hash(source_p->name, source_p);
f427c8b0 292 rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1);
212380e3 293 add_to_client_hash(source_p->name, source_p);
fa94d8fb
AC
294
295 rb_snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name);
296 rb_note(source_p->localClient->F, note);
212380e3
AC
297 }
298
299 if(!valid_hostname(source_p->host))
300 {
5366977b 301 sendto_one_notice(source_p, ":*** Notice -- You have an illegal character in your hostname");
212380e3 302
f427c8b0 303 rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
212380e3
AC
304 }
305
306
307 aconf = source_p->localClient->att_conf;
308
309 if(aconf == NULL)
310 {
311 exit_client(client_p, source_p, &me, "*** Not Authorised");
312 return (CLIENT_EXITED);
313 }
314
b1594414
JT
315 if(IsConfSSLNeeded(aconf) && !IsSSL(source_p))
316 {
317 ServerStats.is_ref++;
318 sendto_one_notice(source_p, ":*** Notice -- You need to use SSL/TLS to use this server");
319 exit_client(client_p, source_p, &me, "Use SSL/TLS");
320 return (CLIENT_EXITED);
321 }
322
212380e3
AC
323 if(!IsGotId(source_p))
324 {
325 const char *p;
326 int i = 0;
327
328 if(IsNeedIdentd(aconf))
329 {
47adde3d 330 ServerStats.is_ref++;
5366977b 331 sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server");
212380e3
AC
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 */
27f616dd 337 if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@'))
212380e3
AC
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 {
47adde3d 357 ServerStats.is_ref++;
5366977b 358 sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server");
212380e3
AC
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))
ba8b3ff1 371 encr = rb_crypt(source_p->localClient->passwd, aconf->passwd);
212380e3
AC
372 else
373 encr = source_p->localClient->passwd;
374
375 if(strcmp(encr, aconf->passwd))
376 {
47adde3d 377 ServerStats.is_ref++;
212380e3
AC
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));
637c4932 388 rb_free(source_p->localClient->passwd);
212380e3
AC
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 */
330fc5c1 405 if(rb_dlink_list_length(&lclient_list) >=
5ca543e7 406 (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf))
212380e3
AC
407 {
408 sendto_realops_snomask(SNO_FULL, L_ALL,
409 "Too many clients, rejecting %s[%s].", source_p->name, source_p->host);
410
47adde3d 411 ServerStats.is_ref++;
212380e3
AC
412 exit_client(client_p, source_p, &me, "Sorry, server is full - try later");
413 return (CLIENT_EXITED);
414 }
415
212380e3
AC
416 /* kline exemption extends to xline too */
417 if(!IsExemptKline(source_p) &&
35f6f850 418 (xconf = find_xline(source_p->info, 1)) != NULL)
212380e3 419 {
47adde3d 420 ServerStats.is_ref++;
70ea02eb 421 add_reject(source_p, xconf->host, NULL);
212380e3
AC
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 {
330fc5c1 434 rb_dlink_list varlist = { NULL, NULL, 0 };
92fb5c31
AC
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
47adde3d 442 ServerStats.is_ref++;
92fb5c31 443
212380e3
AC
444 sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP),
445 me.name, source_p->name,
92fb5c31
AC
446 substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist));
447
448 substitution_free(&varlist);
449
212380e3
AC
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++;
54ac8b60 453 add_reject(source_p, NULL, NULL);
212380e3
AC
454 exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)");
455 return CLIENT_EXITED;
456 }
457 }
458
0734f634
JT
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);
47adde3d 466 ServerStats.is_ref++;
cc32202d
AC
467 sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains "
468 "only alphanumeric characters.");
b2f0da88 469 rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username);
0734f634
JT
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 */
f427c8b0 477 rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1);
212380e3
AC
478
479 /* Spoof user@host */
480 if(*source_p->preClient->spoofuser)
f427c8b0 481 rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1);
212380e3
AC
482 if(*source_p->preClient->spoofhost)
483 {
f427c8b0 484 rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1);
212380e3
AC
485 if (irccmp(source_p->host, source_p->orighost))
486 SetDynSpoof(source_p);
487 }
488
e2b44358
JT
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
AC
496 return CLIENT_EXITED;
497
e2b44358
JT
498 /* To avoid inconsistencies, do not abort the registration
499 * starting from this point -- jilles
500 */
caa4d9d2 501 rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
212380e3
AC
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
AC
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
3318e109
AC
529 if (IsSSL(source_p))
530 source_p->umodes |= UMODE_SSLCLIENT;
531
212380e3
AC
532 if (source_p->umodes & UMODE_INVISIBLE)
533 Count.invisi++;
534
535 s_assert(!IsClient(source_p));
330fc5c1 536 rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list);
212380e3
AC
537 SetClient(source_p);
538
0a61720a 539 source_p->servptr = &me;
330fc5c1 540 rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
0a61720a 541
212380e3
AC
542 /* Increment our total user count here */
543 if(++Count.total > Count.max_tot)
544 Count.max_tot = Count.total;
0a61720a 545
212380e3
AC
546 Count.totalrestartcount++;
547
548 s_assert(source_p->localClient != NULL);
549
330fc5c1 550 if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc)
212380e3 551 {
330fc5c1 552 Count.max_loc = rb_dlink_list_length(&lclient_list);
212380e3
AC
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))
179becdf
JT
560 source_p->localClient->targets_free = TGCHANGE_INITIAL_LOW;
561 else
562 source_p->localClient->targets_free = TGCHANGE_INITIAL;
212380e3 563
212380e3
AC
564 monitor_signon(source_p);
565 user_welcome(source_p);
566
567 free_pre_client(source_p);
568
569 return (introduce_client(client_p, source_p, user, source_p->name, 1));
570}
571
572/*
573 * introduce_clients
574 *
575 * inputs -
576 * output -
577 * side effects - This common function introduces a client to the rest
578 * of the net, either from a local client connect or
579 * from a remote connect.
580 */
581int
582introduce_client(struct Client *client_p, struct Client *source_p, struct User *user, const char *nick, int use_euid)
583{
584 static char ubuf[12];
585 struct Client *identifyservice_p;
586 char *p;
587 hook_data_umode_changed hdata;
588 hook_data_client hdata2;
ca273a1c 589 char sockhost[HOSTLEN];
212380e3
AC
590
591 if(MyClient(source_p))
592 send_umode(source_p, source_p, 0, 0, ubuf);
593 else
594 send_umode(NULL, source_p, 0, 0, ubuf);
595
596 if(!*ubuf)
597 {
598 ubuf[0] = '+';
599 ubuf[1] = '\0';
600 }
601
ca273a1c
AC
602 s_assert(has_id(source_p));
603
604 if(source_p->sockhost[0] == ':')
212380e3 605 {
ca273a1c
AC
606 sockhost[0] = '0';
607 sockhost[1] = '\0';
608 rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost));
609 } else
610 strcpy(sockhost, source_p->sockhost);
212380e3 611
ca273a1c
AC
612 if (use_euid)
613 sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS,
614 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
615 source_p->servptr->id, nick,
616 source_p->hopcount + 1,
617 (long) source_p->tsinfo, ubuf,
618 source_p->username, source_p->host,
619 IsIPSpoof(source_p) ? "0" : sockhost,
620 source_p->id,
621 IsDynSpoof(source_p) ? source_p->orighost : "*",
622 EmptyString(source_p->user->suser) ? "*" : source_p->user->suser,
623 source_p->info);
624
625 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS,
626 ":%s UID %s %d %ld %s %s %s %s %s :%s",
627 source_p->servptr->id, nick,
628 source_p->hopcount + 1,
629 (long) source_p->tsinfo, ubuf,
630 source_p->username, source_p->host,
631 IsIPSpoof(source_p) ? "0" : sockhost,
632 source_p->id, source_p->info);
212380e3 633
8eda114a
JT
634 if(!EmptyString(source_p->certfp))
635 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
636 ":%s ENCAP * CERTFP :%s",
637 use_id(source_p), source_p->certfp);
638
212380e3
AC
639 if (IsDynSpoof(source_p))
640 {
641 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s",
642 use_id(source_p), source_p->orighost);
212380e3 643 }
ca273a1c 644
212380e3
AC
645 if (!EmptyString(source_p->user->suser))
646 {
647 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s",
648 use_id(source_p), source_p->user->suser);
212380e3
AC
649 }
650
651 if(MyConnect(source_p) && source_p->localClient->passwd)
652 {
0a01ecfa
JT
653 if (!EmptyString(ConfigFileEntry.identifyservice) &&
654 !EmptyString(ConfigFileEntry.identifycommand))
212380e3
AC
655 {
656 /* use user@server */
657 p = strchr(ConfigFileEntry.identifyservice, '@');
658 if (p != NULL)
659 identifyservice_p = find_named_client(p + 1);
660 else
661 identifyservice_p = NULL;
662 if (identifyservice_p != NULL)
12f4addb
SB
663 {
664 if (!EmptyString(source_p->localClient->auth_user))
665 sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s",
666 get_id(source_p, identifyservice_p),
667 ConfigFileEntry.identifyservice,
668 ConfigFileEntry.identifycommand,
669 source_p->localClient->auth_user,
670 source_p->localClient->passwd);
671 else
672 sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s",
673 get_id(source_p, identifyservice_p),
674 ConfigFileEntry.identifyservice,
675 ConfigFileEntry.identifycommand,
676 source_p->localClient->passwd);
677 }
212380e3
AC
678 }
679 memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd));
637c4932 680 rb_free(source_p->localClient->passwd);
212380e3
AC
681 source_p->localClient->passwd = NULL;
682 }
683
684 /* let modules providing usermodes know that we've got a new user,
685 * why is this here? -- well, some modules need to be able to send out new
686 * information about a client, so this was the best place to do it
687 * --nenolod
688 */
689 hdata.client = source_p;
690 hdata.oldumodes = 0;
691 hdata.oldsnomask = 0;
692 call_hook(h_umode_changed, &hdata);
693
694 /* On the other hand, some modules need to know when a client is
695 * being introduced, period.
696 * --gxti
697 */
698 hdata2.client = client_p;
699 hdata2.target = source_p;
700 call_hook(h_introduce_client, &hdata2);
701
702 return 0;
703}
704
705/*
706 * valid_hostname - check hostname for validity
707 *
708 * Inputs - pointer to user
709 * Output - YES if valid, NO if not
710 * Side effects - NONE
711 *
712 * NOTE: this doesn't allow a hostname to begin with a dot and
713 * will not allow more dots than chars.
714 */
715int
716valid_hostname(const char *hostname)
717{
9a180ae3 718 const char *p = hostname, *last_slash = 0;
212380e3
AC
719 int found_sep = 0;
720
721 s_assert(NULL != p);
722
723 if(hostname == NULL)
724 return NO;
725
9a180ae3 726 if('.' == *p || ':' == *p || '/' == *p)
212380e3
AC
727 return NO;
728
729 while (*p)
730 {
731 if(!IsHostChar(*p))
732 return NO;
733 if(*p == '.' || *p == ':')
734 found_sep++;
9a180ae3
SB
735 else if(*p == '/')
736 {
737 found_sep++;
738 last_slash = p;
739 }
212380e3
AC
740 p++;
741 }
742
743 if(found_sep == 0)
9a180ae3
SB
744 return NO;
745
746 if(last_slash && IsDigit(last_slash[1]))
747 return NO;
212380e3 748
9a180ae3 749 return YES;
212380e3
AC
750}
751
752/*
753 * valid_username - check username for validity
754 *
755 * Inputs - pointer to user
756 * Output - YES if valid, NO if not
757 * Side effects - NONE
758 *
759 * Absolutely always reject any '*' '!' '?' '@' in an user name
760 * reject any odd control characters names.
761 * Allow '.' in username to allow for "first.last"
762 * style of username
763 */
764int
765valid_username(const char *username)
766{
767 int dots = 0;
768 const char *p = username;
769
770 s_assert(NULL != p);
771
772 if(username == NULL)
773 return NO;
774
775 if('~' == *p)
776 ++p;
777
778 /* reject usernames that don't start with an alphanum
779 * i.e. reject jokers who have '-@somehost' or '.@somehost'
780 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
781 */
782 if(!IsAlNum(*p))
783 return NO;
784
785 while (*++p)
786 {
787 if((*p == '.') && ConfigFileEntry.dots_in_ident)
788 {
789 dots++;
790 if(dots > ConfigFileEntry.dots_in_ident)
791 return NO;
792 if(!IsUserChar(p[1]))
793 return NO;
794 }
795 else if(!IsUserChar(*p))
796 return NO;
797 }
798 return YES;
799}
800
801/* report_and_set_user_flags
802 *
803 * Inputs - pointer to source_p
804 * - pointer to aconf for this user
805 * Output - NONE
806 * Side effects -
807 * Report to user any special flags they are getting, and set them.
808 */
809
810static void
811report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf)
812{
813 /* If this user is being spoofed, tell them so */
814 if(IsConfDoSpoofIp(aconf))
815 {
e07de82c 816 sendto_one_notice(source_p, ":*** Spoofing your IP");
212380e3
AC
817 }
818
819 /* If this user is in the exception class, Set it "E lined" */
820 if(IsConfExemptKline(aconf))
821 {
822 SetExemptKline(source_p);
5c16ab05 823 sendto_one_notice(source_p, ":*** You are exempt from K/X lines");
212380e3
AC
824 }
825
212380e3
AC
826 if(IsConfExemptDNSBL(aconf))
827 /* kline exempt implies this, don't send both */
828 if(!IsConfExemptKline(aconf))
e07de82c 829 sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists");
212380e3
AC
830
831 /* If this user is exempt from user limits set it F lined" */
832 if(IsConfExemptLimits(aconf))
833 {
e07de82c 834 sendto_one_notice(source_p, ":*** You are exempt from user limits");
212380e3
AC
835 }
836
212380e3
AC
837 if(IsConfExemptFlood(aconf))
838 {
839 SetExemptFlood(source_p);
e07de82c 840 sendto_one_notice(source_p, ":*** You are exempt from flood limits");
212380e3
AC
841 }
842
843 if(IsConfExemptSpambot(aconf))
844 {
845 SetExemptSpambot(source_p);
e07de82c 846 sendto_one_notice(source_p, ":*** You are exempt from spambot checks");
212380e3
AC
847 }
848
849 if(IsConfExemptJupe(aconf))
850 {
851 SetExemptJupe(source_p);
e07de82c 852 sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings");
212380e3
AC
853 }
854
855 if(IsConfExemptResv(aconf))
856 {
857 SetExemptResv(source_p);
e07de82c 858 sendto_one_notice(source_p, ":*** You are exempt from resvs");
212380e3
AC
859 }
860
861 if(IsConfExemptShide(aconf))
862 {
863 SetExemptShide(source_p);
e07de82c 864 sendto_one_notice(source_p, ":*** You are exempt from serverhiding");
212380e3
AC
865 }
866}
867
681ddf64
JT
868static void
869show_other_user_mode(struct Client *source_p, struct Client *target_p)
870{
871 int i;
872 char buf[BUFSIZE];
873 char *m;
874
875 m = buf;
876 *m++ = '+';
877
878 for (i = 0; i < 128; i++) /* >= 127 is extended ascii */
879 if (target_p->umodes & user_modes[i])
880 *m++ = (char) i;
881 *m = '\0';
882
883 if (MyConnect(target_p) && target_p->snomask != 0)
884 sendto_one_notice(source_p, ":Modes for %s are %s %s",
885 target_p->name, buf,
886 construct_snobuf(target_p->snomask));
887 else
888 sendto_one_notice(source_p, ":Modes for %s are %s",
889 target_p->name, buf);
890}
891
212380e3
AC
892/*
893 * user_mode - set get current users mode
894 *
895 * m_umode() added 15/10/91 By Darren Reed.
212380e3
AC
896 * parv[1] - username to change mode for
897 * parv[2] - modes to change
898 */
899int
900user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
901{
902 int flag;
903 int i;
904 char *m;
905 const char *pm;
906 struct Client *target_p;
907 int what, setflags;
908 int badflag = NO; /* Only send one bad flag notice */
909 int showsnomask = NO;
910 unsigned int setsnomask;
911 char buf[BUFSIZE];
912 hook_data_umode_changed hdata;
913
914 what = MODE_ADD;
915
916 if(parc < 2)
917 {
918 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE");
919 return 0;
920 }
921
922 if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL)
923 {
924 if(MyConnect(source_p))
925 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
926 form_str(ERR_NOSUCHCHANNEL), parv[1]);
927 return 0;
928 }
929
930 /* Dont know why these were commented out..
931 * put them back using new sendto() funcs
932 */
933
934 if(IsServer(source_p))
935 {
936 sendto_realops_snomask(SNO_GENERAL, L_ADMIN,
937 "*** Mode for User %s from %s", parv[1], source_p->name);
938 return 0;
939 }
940
c98c2c89 941 if(source_p != target_p)
212380e3 942 {
681ddf64
JT
943 if (MyOper(source_p) && parc < 3)
944 show_other_user_mode(source_p, target_p);
945 else
946 sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name);
212380e3
AC
947 return 0;
948 }
949
950 if(parc < 3)
951 {
952 m = buf;
953 *m++ = '+';
954
955 for (i = 0; i < 128; i++) /* >= 127 is extended ascii */
956 if (source_p->umodes & user_modes[i])
957 *m++ = (char) i;
958
959 *m = '\0';
e8a2d50d 960 sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf);
88520303 961
212380e3 962 if (source_p->snomask != 0)
88520303 963 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
212380e3 964 construct_snobuf(source_p->snomask));
88520303 965
212380e3
AC
966 return 0;
967 }
968
969 /* find flags already set for user */
970 setflags = source_p->umodes;
971 setsnomask = source_p->snomask;
972
973 /*
974 * parse mode change string(s)
975 */
976 for (pm = parv[2]; *pm; pm++)
977 switch (*pm)
978 {
979 case '+':
980 what = MODE_ADD;
981 break;
982 case '-':
983 what = MODE_DEL;
984 break;
985
986 case 'o':
987 if(what == MODE_ADD)
988 {
989 if(IsServer(client_p) && !IsOper(source_p))
990 {
991 ++Count.oper;
992 SetOper(source_p);
330fc5c1 993 rb_dlinkAddAlloc(source_p, &oper_list);
212380e3
AC
994 }
995 }
996 else
997 {
998 /* Only decrement the oper counts if an oper to begin with
999 * found by Pat Szuta, Perly , perly@xnet.com
1000 */
1001
1002 if(!IsOper(source_p))
1003 break;
1004
1005 ClearOper(source_p);
1006
1007 Count.oper--;
1008
1009 if(MyConnect(source_p))
1010 {
1011 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
1012 if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0)
1013 {
1014 source_p->snomask = 0;
1015 showsnomask = YES;
1016 }
1017 source_p->flags2 &= ~OPER_FLAGS;
1018
637c4932 1019 rb_free(source_p->localClient->opername);
212380e3
AC
1020 source_p->localClient->opername = NULL;
1021
330fc5c1 1022 rb_dlinkFindDestroy(source_p, &local_oper_list);
83dfad0e
JT
1023 privilegeset_unref(source_p->localClient->privset);
1024 source_p->localClient->privset = NULL;
212380e3
AC
1025 }
1026
330fc5c1 1027 rb_dlinkFindDestroy(source_p, &oper_list);
212380e3
AC
1028 }
1029 break;
1030
1031 /* we may not get these,
1032 * but they shouldnt be in default
1033 */
1034
1035 /* can only be set on burst */
1036 case 'S':
3318e109 1037 case 'Z':
212380e3
AC
1038 case ' ':
1039 case '\n':
1040 case '\r':
1041 case '\t':
1042 break;
1043
1044 case 's':
1045 if (MyConnect(source_p))
1046 {
1047 if(!IsOper(source_p)
1048 && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE))
1049 {
1050 if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE)
1051 badflag = YES;
1052 continue;
1053 }
1054 showsnomask = YES;
1055 if(what == MODE_ADD)
1056 {
1057 if (parc > 3)
1058 source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]);
1059 else
1060 source_p->snomask |= SNO_GENERAL;
1061 }
1062 else
1063 source_p->snomask = 0;
1064 if (source_p->snomask != 0)
1065 source_p->umodes |= UMODE_SERVNOTICE;
1066 else
1067 source_p->umodes &= ~UMODE_SERVNOTICE;
1068 break;
1069 }
1070 /* FALLTHROUGH */
1071 default:
2da6f6eb
JT
1072 if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward)
1073 {
1074 badflag = YES;
1075 break;
1076 }
1077
212380e3
AC
1078 if((flag = user_modes[(unsigned char) *pm]))
1079 {
1080 if(MyConnect(source_p)
a8086a7c
JT
1081 && ((!IsOper(source_p)
1082 && (ConfigFileEntry.oper_only_umodes & flag))
1083 || (orphaned_umodes & flag)))
212380e3
AC
1084 {
1085 if (what == MODE_ADD || source_p->umodes & flag)
1086 badflag = YES;
1087 }
1088 else
1089 {
1090 if(what == MODE_ADD)
1091 source_p->umodes |= flag;
1092 else
1093 source_p->umodes &= ~flag;
1094 }
1095 }
1096 else
1097 {
1098 if(MyConnect(source_p))
1099 badflag = YES;
1100 }
1101 break;
1102 }
1103
1104 if(badflag)
1105 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name);
1106
1107 if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p))
1108 {
b4838ccd 1109 sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n");
212380e3
AC
1110 source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */
1111 }
1112
1113 if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p))
1114 {
5366977b 1115 sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z");
212380e3
AC
1116 source_p->umodes &= ~UMODE_OPERWALL;
1117 }
1118
1119 if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
1120 (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p)))
1121 {
b4838ccd 1122 sendto_one_notice(source_p, ":*** You need oper and admin flag for +a");
212380e3
AC
1123 source_p->umodes &= ~UMODE_ADMIN;
1124 }
1125
1126 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1127 hdata.client = source_p;
1128 hdata.oldumodes = setflags;
1129 hdata.oldsnomask = setsnomask;
1130 call_hook(h_umode_changed, &hdata);
1131
1132 if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
1133 ++Count.invisi;
1134 if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
1135 --Count.invisi;
1136 /*
1137 * compare new flags with old flags and send string which
1138 * will cause servers to update correctly.
1139 */
1140 send_umode_out(client_p, source_p, setflags);
1141 if (showsnomask && MyConnect(source_p))
88520303 1142 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
212380e3
AC
1143 construct_snobuf(source_p->snomask));
1144
1145 return (0);
1146}
1147
1148/*
1149 * send the MODE string for user (user) to connection client_p
1150 * -avalon
1151 */
1152void
1153send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf)
1154{
1155 int i;
1156 int flag;
1157 char *m;
1158 int what = 0;
1159
1160 /*
1161 * build a string in umode_buf to represent the change in the user's
1162 * mode between the new (source_p->flag) and 'old'.
1163 */
1164 m = umode_buf;
1165 *m = '\0';
1166
1167 for (i = 0; i < 128; i++)
1168 {
1169 flag = user_modes[i];
1170
1171 if((flag & old) && !(source_p->umodes & flag))
1172 {
1173 if(what == MODE_DEL)
1174 *m++ = (char) i;
1175 else
1176 {
1177 what = MODE_DEL;
1178 *m++ = '-';
1179 *m++ = (char) i;
1180 }
1181 }
1182 else if(!(flag & old) && (source_p->umodes & flag))
1183 {
1184 if(what == MODE_ADD)
1185 *m++ = (char) i;
1186 else
1187 {
1188 what = MODE_ADD;
1189 *m++ = '+';
1190 *m++ = (char) i;
1191 }
1192 }
1193 }
1194 *m = '\0';
1195
1196 if(*umode_buf && client_p)
1197 sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf);
1198}
1199
1200/*
1201 * send_umode_out
1202 *
1203 * inputs -
1204 * output - NONE
1205 * side effects -
1206 */
1207void
1208send_umode_out(struct Client *client_p, struct Client *source_p, int old)
1209{
1210 struct Client *target_p;
1211 char buf[BUFSIZE];
330fc5c1 1212 rb_dlink_node *ptr;
212380e3
AC
1213
1214 send_umode(NULL, source_p, old, 0, buf);
1215
5cefa1d6 1216 RB_DLINK_FOREACH(ptr, serv_list.head)
212380e3
AC
1217 {
1218 target_p = ptr->data;
1219
1220 if((target_p != client_p) && (target_p != source_p) && (*buf))
1221 {
1222 sendto_one(target_p, ":%s MODE %s :%s",
1223 get_id(source_p, target_p),
1224 get_id(source_p, target_p), buf);
1225 }
1226 }
1227
1228 if(client_p && MyClient(client_p))
1229 send_umode(client_p, source_p, old, 0, buf);
1230}
1231
1232/*
1233 * user_welcome
1234 *
1235 * inputs - client pointer to client to welcome
1236 * output - NONE
1237 * side effects -
1238 */
1239void
1240user_welcome(struct Client *source_p)
1241{
88520303
AC
1242 sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name);
1243 sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST),
212380e3 1244 get_listener_name(source_p->localClient->listener), ircd_version);
88520303 1245 sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation);
c18cb68b 1246 sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo);
212380e3
AC
1247
1248 show_isupport(source_p);
1249
1250 show_lusers(source_p);
1251
1252 if(ConfigFileEntry.short_motd)
1253 {
5366977b
AC
1254 sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed);
1255 sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it");
212380e3
AC
1256
1257 sendto_one(source_p, form_str(RPL_MOTDSTART),
1258 me.name, source_p->name, me.name);
1259
1260 sendto_one(source_p, form_str(RPL_MOTD),
1261 me.name, source_p->name, "*** This is the short motd ***");
1262
1263 sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name);
1264 }
1265 else
1266 send_user_motd(source_p);
1267}
1268
1269/* oper_up()
1270 *
1271 * inputs - pointer to given client to oper
1272 * - pointer to ConfItem to use
1273 * output - none
1274 * side effects - opers up source_p using aconf for reference
1275 */
1276int
1277oper_up(struct Client *source_p, struct oper_conf *oper_p)
1278{
1279 unsigned int old = source_p->umodes, oldsnomask = source_p->snomask;
1280 hook_data_umode_changed hdata;
1281
1282 SetOper(source_p);
1283
1284 if(oper_p->umodes)
1285 source_p->umodes |= oper_p->umodes;
1286 else if(ConfigFileEntry.oper_umodes)
1287 source_p->umodes |= ConfigFileEntry.oper_umodes;
1288 else
1289 source_p->umodes |= DEFAULT_OPER_UMODES;
1290
1291 if (oper_p->snomask)
1292 {
1293 source_p->snomask |= oper_p->snomask;
1294 source_p->umodes |= UMODE_SERVNOTICE;
1295 }
1296 else if (source_p->umodes & UMODE_SERVNOTICE)
1297 {
1298 /* Only apply these if +s is already set -- jilles */
1299 if (ConfigFileEntry.oper_snomask)
1300 source_p->snomask |= ConfigFileEntry.oper_snomask;
1301 else
1302 source_p->snomask |= DEFAULT_OPER_SNOMASK;
1303 }
1304
1305 Count.oper++;
1306
1307 SetExemptKline(source_p);
1308
1309 source_p->flags2 |= oper_p->flags;
47a03750 1310 source_p->localClient->opername = rb_strdup(oper_p->name);
ef242716 1311 source_p->localClient->privset = privilegeset_ref(oper_p->privset);
212380e3 1312
330fc5c1
AC
1313 rb_dlinkAddAlloc(source_p, &local_oper_list);
1314 rb_dlinkAddAlloc(source_p, &oper_list);
212380e3
AC
1315
1316 if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
1317 source_p->umodes |= UMODE_ADMIN;
1318 if(!IsOperN(source_p))
1319 source_p->snomask &= ~SNO_NCHANGE;
1320 if(!IsOperOperwall(source_p))
1321 source_p->umodes &= ~UMODE_OPERWALL;
1322 hdata.client = source_p;
1323 hdata.oldumodes = old;
1324 hdata.oldsnomask = oldsnomask;
1325 call_hook(h_umode_changed, &hdata);
1326
1327 sendto_realops_snomask(SNO_GENERAL, L_ALL,
5cca545c 1328 "%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name,
212380e3 1329 source_p->username, source_p->host);
652b8478
JT
1330 if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1331 ++Count.invisi;
1332 if((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1333 --Count.invisi;
212380e3 1334 send_umode_out(source_p, source_p, old);
88520303 1335 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
212380e3
AC
1336 construct_snobuf(source_p->snomask));
1337 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
22c3b270
AC
1338 sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name);
1339 sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs);
212380e3
AC
1340 send_oper_motd(source_p);
1341
1342 return (1);
1343}
1344
01cebbd8
JT
1345/*
1346 * find_umode_slot
1347 *
1348 * inputs - NONE
1349 * outputs - an available umode bitmask or
1350 * 0 if no umodes are available
1351 * side effects - NONE
1352 */
1353unsigned int
1354find_umode_slot(void)
1355{
1356 unsigned int all_umodes = 0, my_umode = 0, i;
1357
1358 for (i = 0; i < 128; i++)
1359 all_umodes |= user_modes[i];
1360
1361 for (my_umode = 1; my_umode && (all_umodes & my_umode);
1362 my_umode <<= 1);
1363
1364 return my_umode;
1365}
1366
212380e3
AC
1367void
1368construct_umodebuf(void)
1369{
1370 int i;
1371 char *ptr = umodebuf;
a8086a7c 1372 static int prev_user_modes[128];
212380e3
AC
1373
1374 *ptr = '\0';
1375
1376 for (i = 0; i < 128; i++)
a8086a7c
JT
1377 {
1378 if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i])
1379 {
1380 if (user_modes[i] == 0)
1381 {
1382 orphaned_umodes |= prev_user_modes[i];
1383 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i);
1384 }
1385 else
1386 {
1387 orphaned_umodes &= ~prev_user_modes[i];
1388 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i);
1389 }
1390 user_modes[i] = prev_user_modes[i];
1391 }
1392 else
1393 prev_user_modes[i] = user_modes[i];
212380e3
AC
1394 if (user_modes[i])
1395 *ptr++ = (char) i;
a8086a7c 1396 }
212380e3
AC
1397
1398 *ptr++ = '\0';
1399}
1400
1401void
1402change_nick_user_host(struct Client *target_p, const char *nick, const char *user,
82622732 1403 const char *host, int newts, const char *format, ...)
212380e3 1404{
330fc5c1 1405 rb_dlink_node *ptr;
212380e3
AC
1406 struct Channel *chptr;
1407 struct membership *mscptr;
1408 int changed = irccmp(target_p->name, nick);
1409 int changed_case = strcmp(target_p->name, nick);
1410 int do_qjm = irccmp(target_p->username, user) || irccmp(target_p->host, host);
1411 char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr;
1412 va_list ap;
1413
1414 modeval[0] = '\0';
1415
1416 if(changed)
1417 {
1418 target_p->tsinfo = newts;
1419 monitor_signoff(target_p);
1420 }
1421 invalidate_bancache_user(target_p);
1422
1423 if(do_qjm)
1424 {
1425 va_start(ap, format);
1426 vsnprintf(reason, 255, format, ap);
1427 va_end(ap);
1428
7a948bda 1429 sendto_common_channels_local_butone(target_p, NOCAPS, ":%s!%s@%s QUIT :%s",
212380e3
AC
1430 target_p->name, target_p->username, target_p->host,
1431 reason);
1432
5cefa1d6 1433 RB_DLINK_FOREACH(ptr, target_p->user->channel.head)
212380e3
AC
1434 {
1435 mscptr = ptr->data;
1436 chptr = mscptr->chptr;
1437 mptr = mode;
1438
1439 if(is_chanop(mscptr))
1440 {
1441 *mptr++ = 'o';
1442 strcat(modeval, nick);
1443 strcat(modeval, " ");
1444 }
1445
1446 if(is_voiced(mscptr))
1447 {
1448 *mptr++ = 'v';
1449 strcat(modeval, nick);
1450 }
1451
1452 *mptr = '\0';
1453
a695b0e4
SB
1454 sendto_channel_local_with_capability_butone(target_p, ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN, chptr,
1455 ":%s!%s@%s JOIN %s", nick, user, host, chptr->chname);
1456 sendto_channel_local_with_capability_butone(target_p, ALL_MEMBERS, CLICAP_EXTENDED_JOIN, NOCAPS, chptr,
1457 ":%s!%s@%s JOIN %s %s :%s", nick, user, host, chptr->chname,
1458 EmptyString(target_p->user->suser) ? "*" : target_p->user->suser,
1459 target_p->info);
1460
212380e3
AC
1461 if(*mode)
1462 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr,
1463 ":%s MODE %s +%s %s",
1464 target_p->servptr->name,
1465 chptr->chname, mode, modeval);
1466
1467 *modeval = '\0';
1468 }
1469
1470 if(MyClient(target_p) && changed_case)
1471 sendto_one(target_p, ":%s!%s@%s NICK %s",
1472 target_p->name, target_p->username, target_p->host, nick);
1473 }
1474 else if(changed_case)
1475 {
7a948bda 1476 sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s",
212380e3
AC
1477 target_p->name, target_p->username,
1478 target_p->host, nick);
1479 }
1480
f427c8b0
VY
1481 rb_strlcpy(target_p->username, user, sizeof target_p->username);
1482 rb_strlcpy(target_p->host, host, sizeof target_p->host);
212380e3
AC
1483
1484 if (changed)
1485 add_history(target_p, 1);
1486
1487 del_from_client_hash(target_p->name, target_p);
f427c8b0 1488 rb_strlcpy(target_p->name, nick, NICKLEN);
212380e3
AC
1489 add_to_client_hash(target_p->name, target_p);
1490
1491 if(changed)
1492 {
1493 monitor_signon(target_p);
1494 del_all_accepts(target_p);
1495 }
1496}