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