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