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