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