]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_user.c
Make KICK and INVITE send snotes on override.
[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 */
930629c5 71 UMODE_BOT, /* B */
2678f87a 72 UMODE_NOCTCP, /* C */
212380e3 73 UMODE_DEAF, /* D */
74 0, /* E */
75 0, /* F */
61ffa214 76 UMODE_SCALLERID, /* G */
212380e3 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 */
854f6bd0 91 UMODE_NOINVITE, /* V */
212380e3 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 */
13a467bb 112 UMODE_OVERRIDE, /* p */
212380e3 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++;
70c6c150 423 add_reject(source_p, xconf->host, 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))
30028776
JT
564 source_p->localClient->targets_free = TGCHANGE_INITIAL_LOW;
565 else
566 source_p->localClient->targets_free = TGCHANGE_INITIAL;
212380e3 567
212380e3 568 monitor_signon(source_p);
569 user_welcome(source_p);
570
571 free_pre_client(source_p);
572
573 return (introduce_client(client_p, source_p, user, source_p->name, 1));
574}
575
576/*
577 * introduce_clients
578 *
579 * inputs -
580 * output -
581 * side effects - This common function introduces a client to the rest
582 * of the net, either from a local client connect or
583 * from a remote connect.
584 */
585int
2c489d8e 586introduce_client(struct Client *client_p, struct Client *source_p, struct User *user, const char *nick, int use_euid)
212380e3 587{
588 static char ubuf[12];
589 struct Client *identifyservice_p;
590 char *p;
591 hook_data_umode_changed hdata;
592 hook_data_client hdata2;
a4857d78 593 char sockhost[HOSTLEN];
2c489d8e 594 struct ConfItem *aconf;
212380e3 595
596 if(MyClient(source_p))
597 send_umode(source_p, source_p, 0, 0, ubuf);
598 else
599 send_umode(NULL, source_p, 0, 0, ubuf);
600
601 if(!*ubuf)
602 {
603 ubuf[0] = '+';
604 ubuf[1] = '\0';
605 }
606
a4857d78
WP
607 s_assert(has_id(source_p));
608
609 if(source_p->sockhost[0] == ':')
212380e3 610 {
a4857d78
WP
611 sockhost[0] = '0';
612 sockhost[1] = '\0';
613 rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost));
614 } else
615 strcpy(sockhost, source_p->sockhost);
212380e3 616
a4857d78
WP
617 if (use_euid)
618 sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS,
619 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
620 source_p->servptr->id, nick,
621 source_p->hopcount + 1,
622 (long) source_p->tsinfo, ubuf,
623 source_p->username, source_p->host,
624 IsIPSpoof(source_p) ? "0" : sockhost,
625 source_p->id,
626 IsDynSpoof(source_p) ? source_p->orighost : "*",
627 EmptyString(source_p->user->suser) ? "*" : source_p->user->suser,
628 source_p->info);
629
630 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS,
631 ":%s UID %s %d %ld %s %s %s %s %s :%s",
632 source_p->servptr->id, nick,
633 source_p->hopcount + 1,
634 (long) source_p->tsinfo, ubuf,
635 source_p->username, source_p->host,
636 IsIPSpoof(source_p) ? "0" : sockhost,
637 source_p->id, source_p->info);
212380e3 638
54656d76
JT
639 if(!EmptyString(source_p->certfp))
640 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
641 ":%s ENCAP * CERTFP :%s",
642 use_id(source_p), source_p->certfp);
643
212380e3 644 if (IsDynSpoof(source_p))
645 {
646 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s",
647 use_id(source_p), source_p->orighost);
212380e3 648 }
a4857d78 649
212380e3 650 if (!EmptyString(source_p->user->suser))
651 {
652 sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s",
653 use_id(source_p), source_p->user->suser);
212380e3 654 }
655
656 if(MyConnect(source_p) && source_p->localClient->passwd)
657 {
658 if (ConfigFileEntry.identifyservice[0] != '\0' &&
659 ConfigFileEntry.identifycommand[0] != '\0')
660 {
661 /* use user@server */
662 p = strchr(ConfigFileEntry.identifyservice, '@');
663 if (p != NULL)
664 identifyservice_p = find_named_client(p + 1);
665 else
666 identifyservice_p = NULL;
667 if (identifyservice_p != NULL)
645103ac
SB
668 {
669 if (!EmptyString(source_p->localClient->auth_user))
670 sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s",
671 get_id(source_p, identifyservice_p),
672 ConfigFileEntry.identifyservice,
673 ConfigFileEntry.identifycommand,
674 source_p->localClient->auth_user,
675 source_p->localClient->passwd);
676 else
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 }
212380e3 683 }
684 memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd));
90a3c35b 685 rb_free(source_p->localClient->passwd);
212380e3 686 source_p->localClient->passwd = NULL;
687 }
688
689 /* let modules providing usermodes know that we've got a new user,
690 * why is this here? -- well, some modules need to be able to send out new
691 * information about a client, so this was the best place to do it
692 * --nenolod
693 */
694 hdata.client = source_p;
695 hdata.oldumodes = 0;
696 hdata.oldsnomask = 0;
697 call_hook(h_umode_changed, &hdata);
698
699 /* On the other hand, some modules need to know when a client is
700 * being introduced, period.
701 * --gxti
702 */
703 hdata2.client = client_p;
704 hdata2.target = source_p;
705 call_hook(h_introduce_client, &hdata2);
706
fa72cee1
JH
707 /* Do all the auth::autojoin wizardry once we're connected */
708 if(MyConnect(source_p))
709 {
710 aconf = source_p->localClient->att_conf;
711
712 if(aconf->autojoin != NULL)
713 {
074fe45a 714 user_join(client_p, source_p, aconf->autojoin, NULL);
fa72cee1
JH
715 }
716 }
717
212380e3 718 return 0;
719}
720
721/*
722 * valid_hostname - check hostname for validity
723 *
724 * Inputs - pointer to user
725 * Output - YES if valid, NO if not
726 * Side effects - NONE
727 *
728 * NOTE: this doesn't allow a hostname to begin with a dot and
729 * will not allow more dots than chars.
730 */
731int
732valid_hostname(const char *hostname)
733{
59bb8093 734 const char *p = hostname, *last_slash = 0;
212380e3 735 int found_sep = 0;
736
737 s_assert(NULL != p);
738
739 if(hostname == NULL)
740 return NO;
741
59bb8093 742 if('.' == *p || ':' == *p || '/' == *p)
212380e3 743 return NO;
744
745 while (*p)
746 {
747 if(!IsHostChar(*p))
748 return NO;
749 if(*p == '.' || *p == ':')
750 found_sep++;
59bb8093
SB
751 else if(*p == '/')
752 {
753 found_sep++;
754 last_slash = p;
755 }
212380e3 756 p++;
757 }
758
759 if(found_sep == 0)
59bb8093
SB
760 return NO;
761
762 if(last_slash && IsDigit(last_slash[1]))
763 return NO;
212380e3 764
59bb8093 765 return YES;
212380e3 766}
767
768/*
769 * valid_username - check username for validity
770 *
771 * Inputs - pointer to user
772 * Output - YES if valid, NO if not
773 * Side effects - NONE
774 *
775 * Absolutely always reject any '*' '!' '?' '@' in an user name
776 * reject any odd control characters names.
777 * Allow '.' in username to allow for "first.last"
778 * style of username
779 */
780int
781valid_username(const char *username)
782{
783 int dots = 0;
784 const char *p = username;
785
786 s_assert(NULL != p);
787
788 if(username == NULL)
789 return NO;
790
791 if('~' == *p)
792 ++p;
793
794 /* reject usernames that don't start with an alphanum
795 * i.e. reject jokers who have '-@somehost' or '.@somehost'
796 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
797 */
798 if(!IsAlNum(*p))
799 return NO;
800
801 while (*++p)
802 {
803 if((*p == '.') && ConfigFileEntry.dots_in_ident)
804 {
805 dots++;
806 if(dots > ConfigFileEntry.dots_in_ident)
807 return NO;
808 if(!IsUserChar(p[1]))
809 return NO;
810 }
811 else if(!IsUserChar(*p))
812 return NO;
813 }
814 return YES;
815}
816
817/* report_and_set_user_flags
818 *
819 * Inputs - pointer to source_p
820 * - pointer to aconf for this user
821 * Output - NONE
822 * Side effects -
823 * Report to user any special flags they are getting, and set them.
824 */
825
826static void
827report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf)
828{
829 /* If this user is being spoofed, tell them so */
830 if(IsConfDoSpoofIp(aconf))
831 {
51e1ce90 832 sendto_one_notice(source_p, ":*** Spoofing your IP");
212380e3 833 }
834
835 /* If this user is in the exception class, Set it "E lined" */
836 if(IsConfExemptKline(aconf))
837 {
838 SetExemptKline(source_p);
e7c88922 839 sendto_one_notice(source_p, ":*** You are exempt from K/X lines");
212380e3 840 }
841
212380e3 842 if(IsConfExemptDNSBL(aconf))
843 /* kline exempt implies this, don't send both */
844 if(!IsConfExemptKline(aconf))
51e1ce90 845 sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists");
212380e3 846
847 /* If this user is exempt from user limits set it F lined" */
848 if(IsConfExemptLimits(aconf))
849 {
51e1ce90 850 sendto_one_notice(source_p, ":*** You are exempt from user limits");
212380e3 851 }
852
212380e3 853 if(IsConfExemptFlood(aconf))
854 {
855 SetExemptFlood(source_p);
51e1ce90 856 sendto_one_notice(source_p, ":*** You are exempt from flood limits");
212380e3 857 }
858
859 if(IsConfExemptSpambot(aconf))
860 {
861 SetExemptSpambot(source_p);
51e1ce90 862 sendto_one_notice(source_p, ":*** You are exempt from spambot checks");
212380e3 863 }
864
865 if(IsConfExemptJupe(aconf))
866 {
867 SetExemptJupe(source_p);
51e1ce90 868 sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings");
212380e3 869 }
870
871 if(IsConfExemptResv(aconf))
872 {
873 SetExemptResv(source_p);
51e1ce90 874 sendto_one_notice(source_p, ":*** You are exempt from resvs");
212380e3 875 }
876
877 if(IsConfExemptShide(aconf))
878 {
879 SetExemptShide(source_p);
51e1ce90 880 sendto_one_notice(source_p, ":*** You are exempt from serverhiding");
212380e3 881 }
882}
883
3471ceb5
JT
884static void
885show_other_user_mode(struct Client *source_p, struct Client *target_p)
886{
887 int i;
888 char buf[BUFSIZE];
889 char *m;
890
891 m = buf;
892 *m++ = '+';
893
894 for (i = 0; i < 128; i++) /* >= 127 is extended ascii */
895 if (target_p->umodes & user_modes[i])
896 *m++ = (char) i;
897 *m = '\0';
898
899 if (MyConnect(target_p) && target_p->snomask != 0)
900 sendto_one_notice(source_p, ":Modes for %s are %s %s",
901 target_p->name, buf,
902 construct_snobuf(target_p->snomask));
903 else
904 sendto_one_notice(source_p, ":Modes for %s are %s",
905 target_p->name, buf);
906}
907
212380e3 908/*
909 * user_mode - set get current users mode
910 *
911 * m_umode() added 15/10/91 By Darren Reed.
212380e3 912 * parv[1] - username to change mode for
913 * parv[2] - modes to change
914 */
915int
916user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
917{
918 int flag;
919 int i;
920 char *m;
921 const char *pm;
922 struct Client *target_p;
923 int what, setflags;
924 int badflag = NO; /* Only send one bad flag notice */
925 int showsnomask = NO;
926 unsigned int setsnomask;
927 char buf[BUFSIZE];
928 hook_data_umode_changed hdata;
929
930 what = MODE_ADD;
931
932 if(parc < 2)
933 {
934 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE");
935 return 0;
936 }
937
938 if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL)
939 {
940 if(MyConnect(source_p))
941 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
942 form_str(ERR_NOSUCHCHANNEL), parv[1]);
943 return 0;
944 }
945
946 /* Dont know why these were commented out..
947 * put them back using new sendto() funcs
948 */
949
950 if(IsServer(source_p))
951 {
952 sendto_realops_snomask(SNO_GENERAL, L_ADMIN,
953 "*** Mode for User %s from %s", parv[1], source_p->name);
954 return 0;
955 }
956
53ece38b 957 if(source_p != target_p)
212380e3 958 {
3471ceb5
JT
959 if (MyOper(source_p) && parc < 3)
960 show_other_user_mode(source_p, target_p);
961 else
962 sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name);
212380e3 963 return 0;
964 }
965
966 if(parc < 3)
967 {
968 m = buf;
969 *m++ = '+';
970
971 for (i = 0; i < 128; i++) /* >= 127 is extended ascii */
972 if (source_p->umodes & user_modes[i])
973 *m++ = (char) i;
974
975 *m = '\0';
e8a2d50d 976 sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf);
88520303 977
212380e3 978 if (source_p->snomask != 0)
88520303 979 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
212380e3 980 construct_snobuf(source_p->snomask));
88520303 981
212380e3 982 return 0;
983 }
984
985 /* find flags already set for user */
986 setflags = source_p->umodes;
987 setsnomask = source_p->snomask;
988
989 /*
990 * parse mode change string(s)
991 */
992 for (pm = parv[2]; *pm; pm++)
993 switch (*pm)
994 {
995 case '+':
996 what = MODE_ADD;
997 break;
998 case '-':
999 what = MODE_DEL;
1000 break;
1001
1002 case 'o':
1003 if(what == MODE_ADD)
1004 {
1005 if(IsServer(client_p) && !IsOper(source_p))
1006 {
1007 ++Count.oper;
1008 SetOper(source_p);
af81d5a0 1009 rb_dlinkAddAlloc(source_p, &oper_list);
212380e3 1010 }
1011 }
1012 else
1013 {
1014 /* Only decrement the oper counts if an oper to begin with
1015 * found by Pat Szuta, Perly , perly@xnet.com
1016 */
1017
1018 if(!IsOper(source_p))
1019 break;
1020
1021 ClearOper(source_p);
1022
1023 Count.oper--;
1024
1025 if(MyConnect(source_p))
1026 {
1027 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
1028 if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0)
1029 {
1030 source_p->snomask = 0;
1031 showsnomask = YES;
1032 }
1033 source_p->flags2 &= ~OPER_FLAGS;
1034
90a3c35b 1035 rb_free(source_p->localClient->opername);
212380e3 1036 source_p->localClient->opername = NULL;
1037
af81d5a0 1038 rb_dlinkFindDestroy(source_p, &local_oper_list);
6acb39cb
JT
1039 privilegeset_unref(source_p->localClient->privset);
1040 source_p->localClient->privset = NULL;
212380e3 1041 }
1042
af81d5a0 1043 rb_dlinkFindDestroy(source_p, &oper_list);
212380e3 1044 }
1045 break;
1046
1047 /* we may not get these,
1048 * but they shouldnt be in default
1049 */
1050
1051 /* can only be set on burst */
1052 case 'S':
16cb94cc 1053 case 'Z':
212380e3 1054 case ' ':
1055 case '\n':
1056 case '\r':
1057 case '\t':
1058 break;
1059
1060 case 's':
1061 if (MyConnect(source_p))
1062 {
1063 if(!IsOper(source_p)
1064 && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE))
1065 {
1066 if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE)
1067 badflag = YES;
1068 continue;
1069 }
1070 showsnomask = YES;
1071 if(what == MODE_ADD)
1072 {
1073 if (parc > 3)
1074 source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]);
1075 else
1076 source_p->snomask |= SNO_GENERAL;
1077 }
1078 else
1079 source_p->snomask = 0;
1080 if (source_p->snomask != 0)
1081 source_p->umodes |= UMODE_SERVNOTICE;
1082 else
1083 source_p->umodes &= ~UMODE_SERVNOTICE;
1084 break;
1085 }
1086 /* FALLTHROUGH */
1087 default:
1088 if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) {
1089 badflag = YES;
1090 break;
1091 }
1092
1093 if((flag = user_modes[(unsigned char) *pm]))
1094 {
1095 if(MyConnect(source_p)
a8086a7c 1096 && ((!IsOper(source_p)
1097 && (ConfigFileEntry.oper_only_umodes & flag))
1098 || (orphaned_umodes & flag)))
212380e3 1099 {
1100 if (what == MODE_ADD || source_p->umodes & flag)
1101 badflag = YES;
1102 }
1103 else
1104 {
1105 if(what == MODE_ADD)
1106 source_p->umodes |= flag;
1107 else
1108 source_p->umodes &= ~flag;
1109 }
1110 }
1111 else
1112 {
1113 if(MyConnect(source_p))
1114 badflag = YES;
1115 }
1116 break;
1117 }
1118
1119 if(badflag)
1120 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name);
1121
1122 if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p))
1123 {
d180319a 1124 sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n");
212380e3 1125 source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */
1126 }
1127
1128 if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p))
1129 {
5366977b 1130 sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z");
212380e3 1131 source_p->umodes &= ~UMODE_OPERWALL;
1132 }
1133
1134 if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
1135 (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p)))
1136 {
d180319a 1137 sendto_one_notice(source_p, ":*** You need oper and admin flag for +a");
212380e3 1138 source_p->umodes &= ~UMODE_ADMIN;
1139 }
1140
13a467bb
JH
1141 if(MyConnect(source_p) && (source_p->umodes & UMODE_OVERRIDE) && (!IsOperOverride(source_p)))
1142 {
1143 sendto_one_notice(source_p, ":*** You need oper and the override flag for +p");
1144 source_p->umodes &= ~UMODE_OVERRIDE;
1145 }
1146
212380e3 1147 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1148 hdata.client = source_p;
1149 hdata.oldumodes = setflags;
1150 hdata.oldsnomask = setsnomask;
1151 call_hook(h_umode_changed, &hdata);
1152
1153 if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
1154 ++Count.invisi;
1155 if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
1156 --Count.invisi;
1157 /*
1158 * compare new flags with old flags and send string which
1159 * will cause servers to update correctly.
1160 */
1161 send_umode_out(client_p, source_p, setflags);
1162 if (showsnomask && MyConnect(source_p))
88520303 1163 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
212380e3 1164 construct_snobuf(source_p->snomask));
1165
1166 return (0);
1167}
1168
1169/*
1170 * send the MODE string for user (user) to connection client_p
1171 * -avalon
1172 */
1173void
1174send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf)
1175{
1176 int i;
1177 int flag;
1178 char *m;
1179 int what = 0;
1180
1181 /*
1182 * build a string in umode_buf to represent the change in the user's
1183 * mode between the new (source_p->flag) and 'old'.
1184 */
1185 m = umode_buf;
1186 *m = '\0';
1187
1188 for (i = 0; i < 128; i++)
1189 {
1190 flag = user_modes[i];
1191
1192 if((flag & old) && !(source_p->umodes & flag))
1193 {
1194 if(what == MODE_DEL)
1195 *m++ = (char) i;
1196 else
1197 {
1198 what = MODE_DEL;
1199 *m++ = '-';
1200 *m++ = (char) i;
1201 }
1202 }
1203 else if(!(flag & old) && (source_p->umodes & flag))
1204 {
1205 if(what == MODE_ADD)
1206 *m++ = (char) i;
1207 else
1208 {
1209 what = MODE_ADD;
1210 *m++ = '+';
1211 *m++ = (char) i;
1212 }
1213 }
1214 }
1215 *m = '\0';
1216
1217 if(*umode_buf && client_p)
1218 sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf);
1219}
1220
1221/*
1222 * send_umode_out
1223 *
1224 * inputs -
1225 * output - NONE
1226 * side effects -
1227 */
1228void
1229send_umode_out(struct Client *client_p, struct Client *source_p, int old)
1230{
1231 struct Client *target_p;
1232 char buf[BUFSIZE];
af81d5a0 1233 rb_dlink_node *ptr;
212380e3 1234
1235 send_umode(NULL, source_p, old, 0, buf);
1236
8e69bb4e 1237 RB_DLINK_FOREACH(ptr, serv_list.head)
212380e3 1238 {
1239 target_p = ptr->data;
1240
1241 if((target_p != client_p) && (target_p != source_p) && (*buf))
1242 {
1243 sendto_one(target_p, ":%s MODE %s :%s",
1244 get_id(source_p, target_p),
1245 get_id(source_p, target_p), buf);
1246 }
1247 }
1248
1249 if(client_p && MyClient(client_p))
1250 send_umode(client_p, source_p, old, 0, buf);
1251}
1252
1253/*
1254 * user_welcome
1255 *
1256 * inputs - client pointer to client to welcome
1257 * output - NONE
1258 * side effects -
1259 */
1260void
1261user_welcome(struct Client *source_p)
1262{
88520303 1263 sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name);
1264 sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST),
212380e3 1265 get_listener_name(source_p->localClient->listener), ircd_version);
88520303 1266 sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation);
2392eb24 1267 sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo);
212380e3 1268
1269 show_isupport(source_p);
1270
1271 show_lusers(source_p);
1272
1273 if(ConfigFileEntry.short_motd)
1274 {
5366977b 1275 sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed);
1276 sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it");
212380e3 1277
1278 sendto_one(source_p, form_str(RPL_MOTDSTART),
1279 me.name, source_p->name, me.name);
1280
1281 sendto_one(source_p, form_str(RPL_MOTD),
1282 me.name, source_p->name, "*** This is the short motd ***");
1283
1284 sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name);
1285 }
1286 else
1287 send_user_motd(source_p);
1288}
1289
1290/* oper_up()
1291 *
1292 * inputs - pointer to given client to oper
1293 * - pointer to ConfItem to use
1294 * output - none
1295 * side effects - opers up source_p using aconf for reference
1296 */
1297int
2c489d8e 1298oper_up(struct Client *source_p, struct oper_conf *oper_p)
212380e3 1299{
1300 unsigned int old = source_p->umodes, oldsnomask = source_p->snomask;
1301 hook_data_umode_changed hdata;
2c489d8e 1302 struct ConfItem *aconf;
212380e3 1303
1304 SetOper(source_p);
1305
1306 if(oper_p->umodes)
1307 source_p->umodes |= oper_p->umodes;
1308 else if(ConfigFileEntry.oper_umodes)
1309 source_p->umodes |= ConfigFileEntry.oper_umodes;
1310 else
1311 source_p->umodes |= DEFAULT_OPER_UMODES;
1312
220c9db5
G
1313 if(!EmptyString(ConfigFileEntry.default_operhost))
1314 {
1315 change_nick_user_host(source_p, source_p->name, source_p->username, ConfigFileEntry.default_operhost, 0, "Changing host");
1316
1317 sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host (set by %s)", source_p->host, source_p->servptr->name);
1318
1319 sendto_server(NULL, NULL,
1320 CAP_EUID | CAP_TS6, NOCAPS, ":%s CHGHOST %s :%s",
1321 use_id(&me), use_id(source_p), source_p->host);
1322 sendto_server(NULL, NULL,
1323 CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s",
1324 use_id(&me), use_id(source_p), source_p->host);
1325
1326 if (!IsDynSpoof(source_p))
1327 SetDynSpoof(source_p);
1328 }
1329
212380e3 1330 if (oper_p->snomask)
1331 {
1332 source_p->snomask |= oper_p->snomask;
1333 source_p->umodes |= UMODE_SERVNOTICE;
1334 }
1335 else if (source_p->umodes & UMODE_SERVNOTICE)
1336 {
1337 /* Only apply these if +s is already set -- jilles */
1338 if (ConfigFileEntry.oper_snomask)
1339 source_p->snomask |= ConfigFileEntry.oper_snomask;
1340 else
1341 source_p->snomask |= DEFAULT_OPER_SNOMASK;
1342 }
1343
1344 Count.oper++;
1345
1346 SetExemptKline(source_p);
1347
1348 source_p->flags2 |= oper_p->flags;
62d28946 1349 source_p->localClient->opername = rb_strdup(oper_p->name);
34cb09ce 1350 source_p->localClient->privset = privilegeset_ref(oper_p->privset);
212380e3 1351
af81d5a0
WP
1352 rb_dlinkAddAlloc(source_p, &local_oper_list);
1353 rb_dlinkAddAlloc(source_p, &oper_list);
212380e3 1354
1355 if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
1356 source_p->umodes |= UMODE_ADMIN;
1357 if(!IsOperN(source_p))
1358 source_p->snomask &= ~SNO_NCHANGE;
1359 if(!IsOperOperwall(source_p))
1360 source_p->umodes &= ~UMODE_OPERWALL;
1361 hdata.client = source_p;
1362 hdata.oldumodes = old;
1363 hdata.oldsnomask = oldsnomask;
1364 call_hook(h_umode_changed, &hdata);
1365
1366 sendto_realops_snomask(SNO_GENERAL, L_ALL,
022573be 1367 "%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name,
212380e3 1368 source_p->username, source_p->host);
652b8478 1369 if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1370 ++Count.invisi;
1371 if((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1372 --Count.invisi;
212380e3 1373 send_umode_out(source_p, source_p, old);
88520303 1374 sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
212380e3 1375 construct_snobuf(source_p->snomask));
1376 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
b8be4a3f
WP
1377 sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name);
1378 sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs);
212380e3 1379 send_oper_motd(source_p);
1380
87f58b4f
JH
1381 aconf = source_p->localClient->att_conf;
1382
1383 /* Do the auth::autojoin_opers wizardry here */
1384 if(aconf->autojoin_opers != NULL)
1385 {
1386 /* opers should never be banned from the opers channel.
1387 * Plus this is post-umode being set so you'll pass +I $o or +O.
1388 * Hence why we're making this a normal clean join. --jdhore
1389 */
074fe45a 1390 user_join(&me, source_p, aconf->autojoin_opers, NULL);
87f58b4f
JH
1391 }
1392
212380e3 1393 return (1);
1394}
1395
01cebbd8 1396/*
1397 * find_umode_slot
1398 *
1399 * inputs - NONE
1400 * outputs - an available umode bitmask or
1401 * 0 if no umodes are available
1402 * side effects - NONE
1403 */
1404unsigned int
1405find_umode_slot(void)
1406{
1407 unsigned int all_umodes = 0, my_umode = 0, i;
1408
1409 for (i = 0; i < 128; i++)
1410 all_umodes |= user_modes[i];
1411
1412 for (my_umode = 1; my_umode && (all_umodes & my_umode);
1413 my_umode <<= 1);
1414
1415 return my_umode;
1416}
1417
212380e3 1418void
1419construct_umodebuf(void)
1420{
1421 int i;
1422 char *ptr = umodebuf;
a8086a7c 1423 static int prev_user_modes[128];
212380e3 1424
1425 *ptr = '\0';
1426
1427 for (i = 0; i < 128; i++)
a8086a7c 1428 {
1429 if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i])
1430 {
1431 if (user_modes[i] == 0)
1432 {
1433 orphaned_umodes |= prev_user_modes[i];
1434 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i);
1435 }
1436 else
1437 {
1438 orphaned_umodes &= ~prev_user_modes[i];
1439 sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i);
1440 }
1441 user_modes[i] = prev_user_modes[i];
1442 }
1443 else
1444 prev_user_modes[i] = user_modes[i];
212380e3 1445 if (user_modes[i])
1446 *ptr++ = (char) i;
a8086a7c 1447 }
212380e3 1448
1449 *ptr++ = '\0';
1450}
1451
1452void
1453change_nick_user_host(struct Client *target_p, const char *nick, const char *user,
20961eea 1454 const char *host, int newts, const char *format, ...)
212380e3 1455{
af81d5a0 1456 rb_dlink_node *ptr;
212380e3 1457 struct Channel *chptr;
1458 struct membership *mscptr;
1459 int changed = irccmp(target_p->name, nick);
1460 int changed_case = strcmp(target_p->name, nick);
c3a0fde2 1461 int do_qjm = irccmp(target_p->username, user) || (irccmp(target_p->host, host) && ConfigChannel.cycle_host_change);
212380e3 1462 char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr;
1463 va_list ap;
1464
1465 modeval[0] = '\0';
1466
1467 if(changed)
1468 {
1469 target_p->tsinfo = newts;
1470 monitor_signoff(target_p);
1471 }
1472 invalidate_bancache_user(target_p);
1473
1474 if(do_qjm)
1475 {
1476 va_start(ap, format);
1477 vsnprintf(reason, 255, format, ap);
1478 va_end(ap);
1479
1480 sendto_common_channels_local_butone(target_p, ":%s!%s@%s QUIT :%s",
1481 target_p->name, target_p->username, target_p->host,
1482 reason);
1483
8e69bb4e 1484 RB_DLINK_FOREACH(ptr, target_p->user->channel.head)
212380e3 1485 {
1486 mscptr = ptr->data;
1487 chptr = mscptr->chptr;
1488 mptr = mode;
1489
da77e1ee
G
1490 if(is_owner(mscptr))
1491 {
1492 *mptr++ = 'a';
1493 strcat(modeval, nick);
1494 strcat(modeval, " ");
1495 }
1496
212380e3 1497 if(is_chanop(mscptr))
1498 {
1499 *mptr++ = 'o';
1500 strcat(modeval, nick);
1501 strcat(modeval, " ");
1502 }
1503
da77e1ee
G
1504 if(is_halfop(mscptr))
1505 {
1506 *mptr++ = 'h';
1507 strcat(modeval, nick);
1508 strcat(modeval, " ");
1509 }
1510
212380e3 1511 if(is_voiced(mscptr))
1512 {
1513 *mptr++ = 'v';
1514 strcat(modeval, nick);
1515 }
1516
1517 *mptr = '\0';
1518
1519 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
1520 nick, user, host, chptr->chname);
1521 if(*mode)
1522 sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr,
1523 ":%s MODE %s +%s %s",
1524 target_p->servptr->name,
1525 chptr->chname, mode, modeval);
1526
1527 *modeval = '\0';
1528 }
1529
1530 if(MyClient(target_p) && changed_case)
1531 sendto_one(target_p, ":%s!%s@%s NICK %s",
1532 target_p->name, target_p->username, target_p->host, nick);
1533 }
1534 else if(changed_case)
1535 {
1536 sendto_common_channels_local(target_p, ":%s!%s@%s NICK :%s",
1537 target_p->name, target_p->username,
1538 target_p->host, nick);
1539 }
1540
907468c4
VY
1541 rb_strlcpy(target_p->username, user, sizeof target_p->username);
1542 rb_strlcpy(target_p->host, host, sizeof target_p->host);
212380e3 1543
1544 if (changed)
1545 add_history(target_p, 1);
1546
1547 del_from_client_hash(target_p->name, target_p);
907468c4 1548 rb_strlcpy(target_p->name, nick, NICKLEN);
212380e3 1549 add_to_client_hash(target_p->name, target_p);
1550
1551 if(changed)
1552 {
1553 monitor_signon(target_p);
1554 del_all_accepts(target_p);
1555 }
1556}