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