]>
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" | |
4562c604 | 34 | #include "match.h" |
212380e3 AC |
35 | #include "ircd.h" |
36 | #include "listener.h" | |
37 | #include "msg.h" | |
38 | #include "numeric.h" | |
212380e3 AC |
39 | #include "s_conf.h" |
40 | #include "s_newconf.h" | |
4016731b | 41 | #include "logger.h" |
212380e3 AC |
42 | #include "s_serv.h" |
43 | #include "s_stats.h" | |
44 | #include "scache.h" | |
45 | #include "send.h" | |
46 | #include "supported.h" | |
47 | #include "whowas.h" | |
212380e3 AC |
48 | #include "packet.h" |
49 | #include "reject.h" | |
50 | #include "cache.h" | |
51 | #include "hook.h" | |
52 | #include "monitor.h" | |
53 | #include "snomask.h" | |
54 | #include "blacklist.h" | |
92fb5c31 | 55 | #include "substitution.h" |
c18cb68b | 56 | #include "chmode.h" |
212380e3 AC |
57 | |
58 | static void report_and_set_user_flags(struct Client *, struct ConfItem *); | |
59 | void user_welcome(struct Client *source_p); | |
60 | ||
212380e3 AC |
61 | char umodebuf[128]; |
62 | ||
a8086a7c | 63 | static int orphaned_umodes = 0; |
212380e3 AC |
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 */ | |
3318e109 | 95 | UMODE_SSLCLIENT, /* Z */ |
212380e3 AC |
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 | { | |
330fc5c1 AC |
145 | if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount) |
146 | MaxClientCount = rb_dlink_list_length(&lclient_list); | |
2f15f871 | 147 | |
330fc5c1 | 148 | if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > |
2f15f871 | 149 | (unsigned long)MaxConnectionCount) |
330fc5c1 AC |
150 | MaxConnectionCount = rb_dlink_list_length(&lclient_list) + |
151 | rb_dlink_list_length(&serv_list); | |
2f15f871 | 152 | |
212380e3 AC |
153 | sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT), |
154 | (Count.total - Count.invisi), | |
330fc5c1 | 155 | Count.invisi, rb_dlink_list_length(&global_serv_list)); |
212380e3 | 156 | |
330fc5c1 | 157 | if(rb_dlink_list_length(&oper_list) > 0) |
212380e3 | 158 | sendto_one_numeric(source_p, RPL_LUSEROP, |
330fc5c1 | 159 | form_str(RPL_LUSEROP), rb_dlink_list_length(&oper_list)); |
212380e3 | 160 | |
330fc5c1 | 161 | if(rb_dlink_list_length(&unknown_list) > 0) |
212380e3 AC |
162 | sendto_one_numeric(source_p, RPL_LUSERUNKNOWN, |
163 | form_str(RPL_LUSERUNKNOWN), | |
330fc5c1 | 164 | rb_dlink_list_length(&unknown_list)); |
212380e3 | 165 | |
330fc5c1 | 166 | if(rb_dlink_list_length(&global_channel_list) > 0) |
212380e3 AC |
167 | sendto_one_numeric(source_p, RPL_LUSERCHANNELS, |
168 | form_str(RPL_LUSERCHANNELS), | |
330fc5c1 | 169 | rb_dlink_list_length(&global_channel_list)); |
212380e3 AC |
170 | |
171 | sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME), | |
330fc5c1 AC |
172 | rb_dlink_list_length(&lclient_list), |
173 | rb_dlink_list_length(&serv_list)); | |
212380e3 AC |
174 | |
175 | sendto_one_numeric(source_p, RPL_LOCALUSERS, | |
176 | form_str(RPL_LOCALUSERS), | |
330fc5c1 | 177 | rb_dlink_list_length(&lclient_list), |
212380e3 | 178 | Count.max_loc, |
330fc5c1 | 179 | rb_dlink_list_length(&lclient_list), |
212380e3 AC |
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 AC |
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 AC |
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 | } | |
095328a7 | 248 | if(!(source_p->flags & FLAGS_PING_COOKIE)) |
212380e3 AC |
249 | { |
250 | return -1; | |
251 | } | |
252 | } | |
253 | ||
254 | /* hasnt finished client cap negotiation */ | |
095328a7 | 255 | if(source_p->flags & FLAGS_CLICAP) |
212380e3 AC |
256 | return -1; |
257 | ||
258 | /* still has DNSbls to validate against */ | |
330fc5c1 | 259 | if(rb_dlink_list_length(&source_p->preClient->dnsbl_queries) > 0) |
212380e3 AC |
260 | return -1; |
261 | ||
e3354945 | 262 | client_p->localClient->last = rb_current_time(); |
212380e3 AC |
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 | { | |
fa94d8fb AC |
291 | char note[NICKLEN + 10]; |
292 | ||
212380e3 | 293 | del_from_client_hash(source_p->name, source_p); |
f427c8b0 | 294 | rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1); |
212380e3 | 295 | add_to_client_hash(source_p->name, source_p); |
fa94d8fb AC |
296 | |
297 | rb_snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name); | |
298 | rb_note(source_p->localClient->F, note); | |
212380e3 AC |
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 | |
f427c8b0 | 305 | rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); |
212380e3 AC |
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 | { | |
47adde3d | 324 | ServerStats.is_ref++; |
5366977b | 325 | sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server"); |
212380e3 AC |
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 | { | |
47adde3d | 351 | ServerStats.is_ref++; |
5366977b | 352 | sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server"); |
212380e3 AC |
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)) | |
ba8b3ff1 | 365 | encr = rb_crypt(source_p->localClient->passwd, aconf->passwd); |
212380e3 AC |
366 | else |
367 | encr = source_p->localClient->passwd; | |
368 | ||
369 | if(strcmp(encr, aconf->passwd)) | |
370 | { | |
47adde3d | 371 | ServerStats.is_ref++; |
212380e3 AC |
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)); | |
637c4932 | 382 | rb_free(source_p->localClient->passwd); |
212380e3 AC |
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 */ | |
330fc5c1 | 399 | if(rb_dlink_list_length(&lclient_list) >= |
5ca543e7 | 400 | (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf)) |
212380e3 AC |
401 | { |
402 | sendto_realops_snomask(SNO_FULL, L_ALL, | |
403 | "Too many clients, rejecting %s[%s].", source_p->name, source_p->host); | |
404 | ||
47adde3d | 405 | ServerStats.is_ref++; |
212380e3 AC |
406 | exit_client(client_p, source_p, &me, "Sorry, server is full - try later"); |
407 | return (CLIENT_EXITED); | |
408 | } | |
409 | ||
212380e3 AC |
410 | /* kline exemption extends to xline too */ |
411 | if(!IsExemptKline(source_p) && | |
35f6f850 | 412 | (xconf = find_xline(source_p->info, 1)) != NULL) |
212380e3 | 413 | { |
47adde3d | 414 | ServerStats.is_ref++; |
54ac8b60 | 415 | add_reject(source_p, xconf->name, NULL); |
212380e3 AC |
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 | { | |
330fc5c1 | 428 | rb_dlink_list varlist = { NULL, NULL, 0 }; |
92fb5c31 AC |
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 | ||
47adde3d | 436 | ServerStats.is_ref++; |
92fb5c31 | 437 | |
212380e3 AC |
438 | sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP), |
439 | me.name, source_p->name, | |
92fb5c31 AC |
440 | substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist)); |
441 | ||
442 | substitution_free(&varlist); | |
443 | ||
212380e3 AC |
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++; | |
54ac8b60 | 447 | add_reject(source_p, NULL, NULL); |
212380e3 AC |
448 | exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)"); |
449 | return CLIENT_EXITED; | |
450 | } | |
451 | } | |
452 | ||
0734f634 JT |
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); | |
47adde3d | 460 | ServerStats.is_ref++; |
cc32202d AC |
461 | sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains " |
462 | "only alphanumeric characters."); | |
b2f0da88 | 463 | rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username); |
0734f634 JT |
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 */ |
f427c8b0 | 471 | rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1); |
212380e3 AC |
472 | |
473 | /* Spoof user@host */ | |
474 | if(*source_p->preClient->spoofuser) | |
f427c8b0 | 475 | rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1); |
212380e3 AC |
476 | if(*source_p->preClient->spoofhost) |
477 | { | |
f427c8b0 | 478 | rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1); |
212380e3 AC |
479 | if (irccmp(source_p->host, source_p->orighost)) |
480 | SetDynSpoof(source_p); | |
481 | } | |
482 | ||
e2b44358 JT |
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 AC |
490 | return CLIENT_EXITED; |
491 | ||
e2b44358 JT |
492 | /* To avoid inconsistencies, do not abort the registration |
493 | * starting from this point -- jilles | |
494 | */ | |
caa4d9d2 | 495 | rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); |
212380e3 AC |
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 AC |
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 | ||
3318e109 AC |
523 | if (IsSSL(source_p)) |
524 | source_p->umodes |= UMODE_SSLCLIENT; | |
525 | ||
212380e3 AC |
526 | if (source_p->umodes & UMODE_INVISIBLE) |
527 | Count.invisi++; | |
528 | ||
529 | s_assert(!IsClient(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; | |
ca273a1c | 583 | char sockhost[HOSTLEN]; |
212380e3 AC |
584 | |
585 | if(MyClient(source_p)) | |
586 | send_umode(source_p, source_p, 0, 0, ubuf); | |
587 | else | |
588 | send_umode(NULL, source_p, 0, 0, ubuf); | |
589 | ||
590 | if(!*ubuf) | |
591 | { | |
592 | ubuf[0] = '+'; | |
593 | ubuf[1] = '\0'; | |
594 | } | |
595 | ||
ca273a1c AC |
596 | s_assert(has_id(source_p)); |
597 | ||
598 | if(source_p->sockhost[0] == ':') | |
212380e3 | 599 | { |
ca273a1c AC |
600 | sockhost[0] = '0'; |
601 | sockhost[1] = '\0'; | |
602 | rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost)); | |
603 | } else | |
604 | strcpy(sockhost, source_p->sockhost); | |
212380e3 | 605 | |
ca273a1c AC |
606 | if (use_euid) |
607 | sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS, | |
608 | ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", | |
609 | source_p->servptr->id, nick, | |
610 | source_p->hopcount + 1, | |
611 | (long) source_p->tsinfo, ubuf, | |
612 | source_p->username, source_p->host, | |
613 | IsIPSpoof(source_p) ? "0" : sockhost, | |
614 | source_p->id, | |
615 | IsDynSpoof(source_p) ? source_p->orighost : "*", | |
616 | EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, | |
617 | source_p->info); | |
618 | ||
619 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, | |
620 | ":%s UID %s %d %ld %s %s %s %s %s :%s", | |
621 | source_p->servptr->id, nick, | |
622 | source_p->hopcount + 1, | |
623 | (long) source_p->tsinfo, ubuf, | |
624 | source_p->username, source_p->host, | |
625 | IsIPSpoof(source_p) ? "0" : sockhost, | |
626 | source_p->id, source_p->info); | |
212380e3 AC |
627 | |
628 | if (IsDynSpoof(source_p)) | |
629 | { | |
630 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s", | |
631 | use_id(source_p), source_p->orighost); | |
212380e3 | 632 | } |
ca273a1c | 633 | |
212380e3 AC |
634 | if (!EmptyString(source_p->user->suser)) |
635 | { | |
636 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s", | |
637 | use_id(source_p), source_p->user->suser); | |
212380e3 AC |
638 | } |
639 | ||
640 | if(MyConnect(source_p) && source_p->localClient->passwd) | |
641 | { | |
642 | if (ConfigFileEntry.identifyservice[0] != '\0' && | |
643 | ConfigFileEntry.identifycommand[0] != '\0') | |
644 | { | |
645 | /* use user@server */ | |
646 | p = strchr(ConfigFileEntry.identifyservice, '@'); | |
647 | if (p != NULL) | |
648 | identifyservice_p = find_named_client(p + 1); | |
649 | else | |
650 | identifyservice_p = NULL; | |
651 | if (identifyservice_p != NULL) | |
652 | sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s", | |
653 | get_id(source_p, identifyservice_p), | |
654 | ConfigFileEntry.identifyservice, | |
655 | ConfigFileEntry.identifycommand, | |
656 | source_p->localClient->passwd); | |
657 | } | |
658 | memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); | |
637c4932 | 659 | rb_free(source_p->localClient->passwd); |
212380e3 AC |
660 | source_p->localClient->passwd = NULL; |
661 | } | |
662 | ||
663 | /* let modules providing usermodes know that we've got a new user, | |
664 | * why is this here? -- well, some modules need to be able to send out new | |
665 | * information about a client, so this was the best place to do it | |
666 | * --nenolod | |
667 | */ | |
668 | hdata.client = source_p; | |
669 | hdata.oldumodes = 0; | |
670 | hdata.oldsnomask = 0; | |
671 | call_hook(h_umode_changed, &hdata); | |
672 | ||
673 | /* On the other hand, some modules need to know when a client is | |
674 | * being introduced, period. | |
675 | * --gxti | |
676 | */ | |
677 | hdata2.client = client_p; | |
678 | hdata2.target = source_p; | |
679 | call_hook(h_introduce_client, &hdata2); | |
680 | ||
681 | return 0; | |
682 | } | |
683 | ||
684 | /* | |
685 | * valid_hostname - check hostname for validity | |
686 | * | |
687 | * Inputs - pointer to user | |
688 | * Output - YES if valid, NO if not | |
689 | * Side effects - NONE | |
690 | * | |
691 | * NOTE: this doesn't allow a hostname to begin with a dot and | |
692 | * will not allow more dots than chars. | |
693 | */ | |
694 | int | |
695 | valid_hostname(const char *hostname) | |
696 | { | |
697 | const char *p = hostname; | |
698 | int found_sep = 0; | |
699 | ||
700 | s_assert(NULL != p); | |
701 | ||
702 | if(hostname == NULL) | |
703 | return NO; | |
704 | ||
705 | if('.' == *p || ':' == *p) | |
706 | return NO; | |
707 | ||
708 | while (*p) | |
709 | { | |
710 | if(!IsHostChar(*p)) | |
711 | return NO; | |
712 | if(*p == '.' || *p == ':') | |
713 | found_sep++; | |
714 | p++; | |
715 | } | |
716 | ||
717 | if(found_sep == 0) | |
718 | return(NO); | |
719 | ||
720 | return (YES); | |
721 | } | |
722 | ||
723 | /* | |
724 | * valid_username - check username for validity | |
725 | * | |
726 | * Inputs - pointer to user | |
727 | * Output - YES if valid, NO if not | |
728 | * Side effects - NONE | |
729 | * | |
730 | * Absolutely always reject any '*' '!' '?' '@' in an user name | |
731 | * reject any odd control characters names. | |
732 | * Allow '.' in username to allow for "first.last" | |
733 | * style of username | |
734 | */ | |
735 | int | |
736 | valid_username(const char *username) | |
737 | { | |
738 | int dots = 0; | |
739 | const char *p = username; | |
740 | ||
741 | s_assert(NULL != p); | |
742 | ||
743 | if(username == NULL) | |
744 | return NO; | |
745 | ||
746 | if('~' == *p) | |
747 | ++p; | |
748 | ||
749 | /* reject usernames that don't start with an alphanum | |
750 | * i.e. reject jokers who have '-@somehost' or '.@somehost' | |
751 | * or "-hi-@somehost", "h-----@somehost" would still be accepted. | |
752 | */ | |
753 | if(!IsAlNum(*p)) | |
754 | return NO; | |
755 | ||
756 | while (*++p) | |
757 | { | |
758 | if((*p == '.') && ConfigFileEntry.dots_in_ident) | |
759 | { | |
760 | dots++; | |
761 | if(dots > ConfigFileEntry.dots_in_ident) | |
762 | return NO; | |
763 | if(!IsUserChar(p[1])) | |
764 | return NO; | |
765 | } | |
766 | else if(!IsUserChar(*p)) | |
767 | return NO; | |
768 | } | |
769 | return YES; | |
770 | } | |
771 | ||
772 | /* report_and_set_user_flags | |
773 | * | |
774 | * Inputs - pointer to source_p | |
775 | * - pointer to aconf for this user | |
776 | * Output - NONE | |
777 | * Side effects - | |
778 | * Report to user any special flags they are getting, and set them. | |
779 | */ | |
780 | ||
781 | static void | |
782 | report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf) | |
783 | { | |
784 | /* If this user is being spoofed, tell them so */ | |
785 | if(IsConfDoSpoofIp(aconf)) | |
786 | { | |
5366977b | 787 | sendto_one_notice(source_p, ":*** Spoofing your IP. congrats."); |
212380e3 AC |
788 | } |
789 | ||
790 | /* If this user is in the exception class, Set it "E lined" */ | |
791 | if(IsConfExemptKline(aconf)) | |
792 | { | |
793 | SetExemptKline(source_p); | |
eae06274 | 794 | sendto_one_notice(source_p, ":*** You are exempt from K/X lines. congrats."); |
212380e3 AC |
795 | } |
796 | ||
212380e3 AC |
797 | if(IsConfExemptDNSBL(aconf)) |
798 | /* kline exempt implies this, don't send both */ | |
799 | if(!IsConfExemptKline(aconf)) | |
5366977b | 800 | sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists."); |
212380e3 AC |
801 | |
802 | /* If this user is exempt from user limits set it F lined" */ | |
803 | if(IsConfExemptLimits(aconf)) | |
804 | { | |
e4b9c8e1 | 805 | sendto_one_notice(source_p, ":*** You are exempt from user limits. congrats."); |
212380e3 AC |
806 | } |
807 | ||
212380e3 AC |
808 | if(IsConfExemptFlood(aconf)) |
809 | { | |
810 | SetExemptFlood(source_p); | |
5366977b | 811 | sendto_one_notice(source_p, ":*** You are exempt from flood limits."); |
212380e3 AC |
812 | } |
813 | ||
814 | if(IsConfExemptSpambot(aconf)) | |
815 | { | |
816 | SetExemptSpambot(source_p); | |
5366977b | 817 | sendto_one_notice(source_p, ":*** You are exempt from spambot checks."); |
212380e3 AC |
818 | } |
819 | ||
820 | if(IsConfExemptJupe(aconf)) | |
821 | { | |
822 | SetExemptJupe(source_p); | |
5366977b | 823 | sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings."); |
212380e3 AC |
824 | } |
825 | ||
826 | if(IsConfExemptResv(aconf)) | |
827 | { | |
828 | SetExemptResv(source_p); | |
5366977b | 829 | sendto_one_notice(source_p, ":*** You are exempt from resvs."); |
212380e3 AC |
830 | } |
831 | ||
832 | if(IsConfExemptShide(aconf)) | |
833 | { | |
834 | SetExemptShide(source_p); | |
5366977b | 835 | sendto_one_notice(source_p, ":*** You are exempt from serverhiding."); |
212380e3 AC |
836 | } |
837 | } | |
838 | ||
839 | /* | |
840 | * user_mode - set get current users mode | |
841 | * | |
842 | * m_umode() added 15/10/91 By Darren Reed. | |
843 | * parv[0] - sender | |
844 | * parv[1] - username to change mode for | |
845 | * parv[2] - modes to change | |
846 | */ | |
847 | int | |
848 | user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
849 | { | |
850 | int flag; | |
851 | int i; | |
852 | char *m; | |
853 | const char *pm; | |
854 | struct Client *target_p; | |
855 | int what, setflags; | |
856 | int badflag = NO; /* Only send one bad flag notice */ | |
857 | int showsnomask = NO; | |
858 | unsigned int setsnomask; | |
859 | char buf[BUFSIZE]; | |
860 | hook_data_umode_changed hdata; | |
861 | ||
862 | what = MODE_ADD; | |
863 | ||
864 | if(parc < 2) | |
865 | { | |
866 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); | |
867 | return 0; | |
868 | } | |
869 | ||
870 | if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL) | |
871 | { | |
872 | if(MyConnect(source_p)) | |
873 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
874 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
875 | return 0; | |
876 | } | |
877 | ||
878 | /* Dont know why these were commented out.. | |
879 | * put them back using new sendto() funcs | |
880 | */ | |
881 | ||
882 | if(IsServer(source_p)) | |
883 | { | |
884 | sendto_realops_snomask(SNO_GENERAL, L_ADMIN, | |
885 | "*** Mode for User %s from %s", parv[1], source_p->name); | |
886 | return 0; | |
887 | } | |
888 | ||
889 | if(source_p != target_p || target_p->from != source_p->from) | |
890 | { | |
891 | sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name); | |
892 | return 0; | |
893 | } | |
894 | ||
895 | if(parc < 3) | |
896 | { | |
897 | m = buf; | |
898 | *m++ = '+'; | |
899 | ||
900 | for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ | |
901 | if (source_p->umodes & user_modes[i]) | |
902 | *m++ = (char) i; | |
903 | ||
904 | *m = '\0'; | |
e8a2d50d | 905 | sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf); |
88520303 | 906 | |
212380e3 | 907 | if (source_p->snomask != 0) |
88520303 | 908 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 | 909 | construct_snobuf(source_p->snomask)); |
88520303 | 910 | |
212380e3 AC |
911 | return 0; |
912 | } | |
913 | ||
914 | /* find flags already set for user */ | |
915 | setflags = source_p->umodes; | |
916 | setsnomask = source_p->snomask; | |
917 | ||
918 | /* | |
919 | * parse mode change string(s) | |
920 | */ | |
921 | for (pm = parv[2]; *pm; pm++) | |
922 | switch (*pm) | |
923 | { | |
924 | case '+': | |
925 | what = MODE_ADD; | |
926 | break; | |
927 | case '-': | |
928 | what = MODE_DEL; | |
929 | break; | |
930 | ||
931 | case 'o': | |
932 | if(what == MODE_ADD) | |
933 | { | |
934 | if(IsServer(client_p) && !IsOper(source_p)) | |
935 | { | |
936 | ++Count.oper; | |
937 | SetOper(source_p); | |
330fc5c1 | 938 | rb_dlinkAddAlloc(source_p, &oper_list); |
212380e3 AC |
939 | } |
940 | } | |
941 | else | |
942 | { | |
943 | /* Only decrement the oper counts if an oper to begin with | |
944 | * found by Pat Szuta, Perly , perly@xnet.com | |
945 | */ | |
946 | ||
947 | if(!IsOper(source_p)) | |
948 | break; | |
949 | ||
950 | ClearOper(source_p); | |
951 | ||
952 | Count.oper--; | |
953 | ||
954 | if(MyConnect(source_p)) | |
955 | { | |
956 | source_p->umodes &= ~ConfigFileEntry.oper_only_umodes; | |
957 | if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0) | |
958 | { | |
959 | source_p->snomask = 0; | |
960 | showsnomask = YES; | |
961 | } | |
962 | source_p->flags2 &= ~OPER_FLAGS; | |
963 | ||
637c4932 | 964 | rb_free(source_p->localClient->opername); |
212380e3 AC |
965 | source_p->localClient->opername = NULL; |
966 | ||
330fc5c1 | 967 | rb_dlinkFindDestroy(source_p, &local_oper_list); |
212380e3 AC |
968 | } |
969 | ||
330fc5c1 | 970 | rb_dlinkFindDestroy(source_p, &oper_list); |
212380e3 AC |
971 | } |
972 | break; | |
973 | ||
974 | /* we may not get these, | |
975 | * but they shouldnt be in default | |
976 | */ | |
977 | ||
978 | /* can only be set on burst */ | |
979 | case 'S': | |
3318e109 | 980 | case 'Z': |
212380e3 AC |
981 | case ' ': |
982 | case '\n': | |
983 | case '\r': | |
984 | case '\t': | |
985 | break; | |
986 | ||
987 | case 's': | |
988 | if (MyConnect(source_p)) | |
989 | { | |
990 | if(!IsOper(source_p) | |
991 | && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE)) | |
992 | { | |
993 | if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE) | |
994 | badflag = YES; | |
995 | continue; | |
996 | } | |
997 | showsnomask = YES; | |
998 | if(what == MODE_ADD) | |
999 | { | |
1000 | if (parc > 3) | |
1001 | source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]); | |
1002 | else | |
1003 | source_p->snomask |= SNO_GENERAL; | |
1004 | } | |
1005 | else | |
1006 | source_p->snomask = 0; | |
1007 | if (source_p->snomask != 0) | |
1008 | source_p->umodes |= UMODE_SERVNOTICE; | |
1009 | else | |
1010 | source_p->umodes &= ~UMODE_SERVNOTICE; | |
1011 | break; | |
1012 | } | |
1013 | /* FALLTHROUGH */ | |
1014 | default: | |
1015 | if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) { | |
1016 | badflag = YES; | |
1017 | break; | |
1018 | } | |
1019 | ||
1020 | if((flag = user_modes[(unsigned char) *pm])) | |
1021 | { | |
1022 | if(MyConnect(source_p) | |
a8086a7c JT |
1023 | && ((!IsOper(source_p) |
1024 | && (ConfigFileEntry.oper_only_umodes & flag)) | |
1025 | || (orphaned_umodes & flag))) | |
212380e3 AC |
1026 | { |
1027 | if (what == MODE_ADD || source_p->umodes & flag) | |
1028 | badflag = YES; | |
1029 | } | |
1030 | else | |
1031 | { | |
1032 | if(what == MODE_ADD) | |
1033 | source_p->umodes |= flag; | |
1034 | else | |
1035 | source_p->umodes &= ~flag; | |
1036 | } | |
1037 | } | |
1038 | else | |
1039 | { | |
1040 | if(MyConnect(source_p)) | |
1041 | badflag = YES; | |
1042 | } | |
1043 | break; | |
1044 | } | |
1045 | ||
1046 | if(badflag) | |
1047 | sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name); | |
1048 | ||
1049 | if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p)) | |
1050 | { | |
b4838ccd | 1051 | sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n"); |
212380e3 AC |
1052 | source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */ |
1053 | } | |
1054 | ||
1055 | if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p)) | |
1056 | { | |
5366977b | 1057 | sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z"); |
212380e3 AC |
1058 | source_p->umodes &= ~UMODE_OPERWALL; |
1059 | } | |
1060 | ||
1061 | if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) && | |
1062 | (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))) | |
1063 | { | |
b4838ccd | 1064 | sendto_one_notice(source_p, ":*** You need oper and admin flag for +a"); |
212380e3 AC |
1065 | source_p->umodes &= ~UMODE_ADMIN; |
1066 | } | |
1067 | ||
1068 | /* let modules providing usermodes know that we've changed our usermode --nenolod */ | |
1069 | hdata.client = source_p; | |
1070 | hdata.oldumodes = setflags; | |
1071 | hdata.oldsnomask = setsnomask; | |
1072 | call_hook(h_umode_changed, &hdata); | |
1073 | ||
1074 | if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p)) | |
1075 | ++Count.invisi; | |
1076 | if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p)) | |
1077 | --Count.invisi; | |
1078 | /* | |
1079 | * compare new flags with old flags and send string which | |
1080 | * will cause servers to update correctly. | |
1081 | */ | |
1082 | send_umode_out(client_p, source_p, setflags); | |
1083 | if (showsnomask && MyConnect(source_p)) | |
88520303 | 1084 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 AC |
1085 | construct_snobuf(source_p->snomask)); |
1086 | ||
1087 | return (0); | |
1088 | } | |
1089 | ||
1090 | /* | |
1091 | * send the MODE string for user (user) to connection client_p | |
1092 | * -avalon | |
1093 | */ | |
1094 | void | |
1095 | send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf) | |
1096 | { | |
1097 | int i; | |
1098 | int flag; | |
1099 | char *m; | |
1100 | int what = 0; | |
1101 | ||
1102 | /* | |
1103 | * build a string in umode_buf to represent the change in the user's | |
1104 | * mode between the new (source_p->flag) and 'old'. | |
1105 | */ | |
1106 | m = umode_buf; | |
1107 | *m = '\0'; | |
1108 | ||
1109 | for (i = 0; i < 128; i++) | |
1110 | { | |
1111 | flag = user_modes[i]; | |
1112 | ||
1113 | if((flag & old) && !(source_p->umodes & flag)) | |
1114 | { | |
1115 | if(what == MODE_DEL) | |
1116 | *m++ = (char) i; | |
1117 | else | |
1118 | { | |
1119 | what = MODE_DEL; | |
1120 | *m++ = '-'; | |
1121 | *m++ = (char) i; | |
1122 | } | |
1123 | } | |
1124 | else if(!(flag & old) && (source_p->umodes & flag)) | |
1125 | { | |
1126 | if(what == MODE_ADD) | |
1127 | *m++ = (char) i; | |
1128 | else | |
1129 | { | |
1130 | what = MODE_ADD; | |
1131 | *m++ = '+'; | |
1132 | *m++ = (char) i; | |
1133 | } | |
1134 | } | |
1135 | } | |
1136 | *m = '\0'; | |
1137 | ||
1138 | if(*umode_buf && client_p) | |
1139 | sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf); | |
1140 | } | |
1141 | ||
1142 | /* | |
1143 | * send_umode_out | |
1144 | * | |
1145 | * inputs - | |
1146 | * output - NONE | |
1147 | * side effects - | |
1148 | */ | |
1149 | void | |
1150 | send_umode_out(struct Client *client_p, struct Client *source_p, int old) | |
1151 | { | |
1152 | struct Client *target_p; | |
1153 | char buf[BUFSIZE]; | |
330fc5c1 | 1154 | rb_dlink_node *ptr; |
212380e3 AC |
1155 | |
1156 | send_umode(NULL, source_p, old, 0, buf); | |
1157 | ||
5cefa1d6 | 1158 | RB_DLINK_FOREACH(ptr, serv_list.head) |
212380e3 AC |
1159 | { |
1160 | target_p = ptr->data; | |
1161 | ||
1162 | if((target_p != client_p) && (target_p != source_p) && (*buf)) | |
1163 | { | |
1164 | sendto_one(target_p, ":%s MODE %s :%s", | |
1165 | get_id(source_p, target_p), | |
1166 | get_id(source_p, target_p), buf); | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | if(client_p && MyClient(client_p)) | |
1171 | send_umode(client_p, source_p, old, 0, buf); | |
1172 | } | |
1173 | ||
1174 | /* | |
1175 | * user_welcome | |
1176 | * | |
1177 | * inputs - client pointer to client to welcome | |
1178 | * output - NONE | |
1179 | * side effects - | |
1180 | */ | |
1181 | void | |
1182 | user_welcome(struct Client *source_p) | |
1183 | { | |
88520303 AC |
1184 | sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name); |
1185 | sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST), | |
212380e3 | 1186 | get_listener_name(source_p->localClient->listener), ircd_version); |
88520303 | 1187 | sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation); |
c18cb68b | 1188 | sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo); |
212380e3 AC |
1189 | |
1190 | show_isupport(source_p); | |
1191 | ||
1192 | show_lusers(source_p); | |
1193 | ||
1194 | if(ConfigFileEntry.short_motd) | |
1195 | { | |
5366977b AC |
1196 | sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed); |
1197 | sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it"); | |
212380e3 AC |
1198 | |
1199 | sendto_one(source_p, form_str(RPL_MOTDSTART), | |
1200 | me.name, source_p->name, me.name); | |
1201 | ||
1202 | sendto_one(source_p, form_str(RPL_MOTD), | |
1203 | me.name, source_p->name, "*** This is the short motd ***"); | |
1204 | ||
1205 | sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name); | |
1206 | } | |
1207 | else | |
1208 | send_user_motd(source_p); | |
1209 | } | |
1210 | ||
1211 | /* oper_up() | |
1212 | * | |
1213 | * inputs - pointer to given client to oper | |
1214 | * - pointer to ConfItem to use | |
1215 | * output - none | |
1216 | * side effects - opers up source_p using aconf for reference | |
1217 | */ | |
1218 | int | |
1219 | oper_up(struct Client *source_p, struct oper_conf *oper_p) | |
1220 | { | |
1221 | unsigned int old = source_p->umodes, oldsnomask = source_p->snomask; | |
1222 | hook_data_umode_changed hdata; | |
1223 | ||
1224 | SetOper(source_p); | |
1225 | ||
1226 | if(oper_p->umodes) | |
1227 | source_p->umodes |= oper_p->umodes; | |
1228 | else if(ConfigFileEntry.oper_umodes) | |
1229 | source_p->umodes |= ConfigFileEntry.oper_umodes; | |
1230 | else | |
1231 | source_p->umodes |= DEFAULT_OPER_UMODES; | |
1232 | ||
1233 | if (oper_p->snomask) | |
1234 | { | |
1235 | source_p->snomask |= oper_p->snomask; | |
1236 | source_p->umodes |= UMODE_SERVNOTICE; | |
1237 | } | |
1238 | else if (source_p->umodes & UMODE_SERVNOTICE) | |
1239 | { | |
1240 | /* Only apply these if +s is already set -- jilles */ | |
1241 | if (ConfigFileEntry.oper_snomask) | |
1242 | source_p->snomask |= ConfigFileEntry.oper_snomask; | |
1243 | else | |
1244 | source_p->snomask |= DEFAULT_OPER_SNOMASK; | |
1245 | } | |
1246 | ||
1247 | Count.oper++; | |
1248 | ||
1249 | SetExemptKline(source_p); | |
1250 | ||
1251 | source_p->flags2 |= oper_p->flags; | |
47a03750 | 1252 | source_p->localClient->opername = rb_strdup(oper_p->name); |
212380e3 | 1253 | |
330fc5c1 AC |
1254 | rb_dlinkAddAlloc(source_p, &local_oper_list); |
1255 | rb_dlinkAddAlloc(source_p, &oper_list); | |
212380e3 AC |
1256 | |
1257 | if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p)) | |
1258 | source_p->umodes |= UMODE_ADMIN; | |
1259 | if(!IsOperN(source_p)) | |
1260 | source_p->snomask &= ~SNO_NCHANGE; | |
1261 | if(!IsOperOperwall(source_p)) | |
1262 | source_p->umodes &= ~UMODE_OPERWALL; | |
1263 | hdata.client = source_p; | |
1264 | hdata.oldumodes = old; | |
1265 | hdata.oldsnomask = oldsnomask; | |
1266 | call_hook(h_umode_changed, &hdata); | |
1267 | ||
1268 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1269 | "%s (%s@%s) is now an operator", source_p->name, | |
1270 | source_p->username, source_p->host); | |
652b8478 JT |
1271 | if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p)) |
1272 | ++Count.invisi; | |
1273 | if((old & UMODE_INVISIBLE) && !IsInvisible(source_p)) | |
1274 | --Count.invisi; | |
212380e3 | 1275 | send_umode_out(source_p, source_p, old); |
88520303 | 1276 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 AC |
1277 | construct_snobuf(source_p->snomask)); |
1278 | sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); | |
5366977b | 1279 | sendto_one_notice(source_p, ":*** Oper privs are %s", get_oper_privs(oper_p->flags)); |
212380e3 AC |
1280 | send_oper_motd(source_p); |
1281 | ||
1282 | return (1); | |
1283 | } | |
1284 | ||
01cebbd8 JT |
1285 | /* |
1286 | * find_umode_slot | |
1287 | * | |
1288 | * inputs - NONE | |
1289 | * outputs - an available umode bitmask or | |
1290 | * 0 if no umodes are available | |
1291 | * side effects - NONE | |
1292 | */ | |
1293 | unsigned int | |
1294 | find_umode_slot(void) | |
1295 | { | |
1296 | unsigned int all_umodes = 0, my_umode = 0, i; | |
1297 | ||
1298 | for (i = 0; i < 128; i++) | |
1299 | all_umodes |= user_modes[i]; | |
1300 | ||
1301 | for (my_umode = 1; my_umode && (all_umodes & my_umode); | |
1302 | my_umode <<= 1); | |
1303 | ||
1304 | return my_umode; | |
1305 | } | |
1306 | ||
212380e3 AC |
1307 | void |
1308 | construct_umodebuf(void) | |
1309 | { | |
1310 | int i; | |
1311 | char *ptr = umodebuf; | |
a8086a7c | 1312 | static int prev_user_modes[128]; |
212380e3 AC |
1313 | |
1314 | *ptr = '\0'; | |
1315 | ||
1316 | for (i = 0; i < 128; i++) | |
a8086a7c JT |
1317 | { |
1318 | if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i]) | |
1319 | { | |
1320 | if (user_modes[i] == 0) | |
1321 | { | |
1322 | orphaned_umodes |= prev_user_modes[i]; | |
1323 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i); | |
1324 | } | |
1325 | else | |
1326 | { | |
1327 | orphaned_umodes &= ~prev_user_modes[i]; | |
1328 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i); | |
1329 | } | |
1330 | user_modes[i] = prev_user_modes[i]; | |
1331 | } | |
1332 | else | |
1333 | prev_user_modes[i] = user_modes[i]; | |
212380e3 AC |
1334 | if (user_modes[i]) |
1335 | *ptr++ = (char) i; | |
a8086a7c | 1336 | } |
212380e3 AC |
1337 | |
1338 | *ptr++ = '\0'; | |
1339 | } | |
1340 | ||
1341 | void | |
1342 | change_nick_user_host(struct Client *target_p, const char *nick, const char *user, | |
82622732 | 1343 | const char *host, int newts, const char *format, ...) |
212380e3 | 1344 | { |
330fc5c1 | 1345 | rb_dlink_node *ptr; |
212380e3 AC |
1346 | struct Channel *chptr; |
1347 | struct membership *mscptr; | |
1348 | int changed = irccmp(target_p->name, nick); | |
1349 | int changed_case = strcmp(target_p->name, nick); | |
1350 | int do_qjm = irccmp(target_p->username, user) || irccmp(target_p->host, host); | |
1351 | char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr; | |
1352 | va_list ap; | |
1353 | ||
1354 | modeval[0] = '\0'; | |
1355 | ||
1356 | if(changed) | |
1357 | { | |
1358 | target_p->tsinfo = newts; | |
1359 | monitor_signoff(target_p); | |
1360 | } | |
1361 | invalidate_bancache_user(target_p); | |
1362 | ||
1363 | if(do_qjm) | |
1364 | { | |
1365 | va_start(ap, format); | |
1366 | vsnprintf(reason, 255, format, ap); | |
1367 | va_end(ap); | |
1368 | ||
1369 | sendto_common_channels_local_butone(target_p, ":%s!%s@%s QUIT :%s", | |
1370 | target_p->name, target_p->username, target_p->host, | |
1371 | reason); | |
1372 | ||
5cefa1d6 | 1373 | RB_DLINK_FOREACH(ptr, target_p->user->channel.head) |
212380e3 AC |
1374 | { |
1375 | mscptr = ptr->data; | |
1376 | chptr = mscptr->chptr; | |
1377 | mptr = mode; | |
1378 | ||
1379 | if(is_chanop(mscptr)) | |
1380 | { | |
1381 | *mptr++ = 'o'; | |
1382 | strcat(modeval, nick); | |
1383 | strcat(modeval, " "); | |
1384 | } | |
1385 | ||
1386 | if(is_voiced(mscptr)) | |
1387 | { | |
1388 | *mptr++ = 'v'; | |
1389 | strcat(modeval, nick); | |
1390 | } | |
1391 | ||
1392 | *mptr = '\0'; | |
1393 | ||
1394 | sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
1395 | nick, user, host, chptr->chname); | |
1396 | if(*mode) | |
1397 | sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, | |
1398 | ":%s MODE %s +%s %s", | |
1399 | target_p->servptr->name, | |
1400 | chptr->chname, mode, modeval); | |
1401 | ||
1402 | *modeval = '\0'; | |
1403 | } | |
1404 | ||
1405 | if(MyClient(target_p) && changed_case) | |
1406 | sendto_one(target_p, ":%s!%s@%s NICK %s", | |
1407 | target_p->name, target_p->username, target_p->host, nick); | |
1408 | } | |
1409 | else if(changed_case) | |
1410 | { | |
1411 | sendto_common_channels_local(target_p, ":%s!%s@%s NICK :%s", | |
1412 | target_p->name, target_p->username, | |
1413 | target_p->host, nick); | |
1414 | } | |
1415 | ||
f427c8b0 VY |
1416 | rb_strlcpy(target_p->username, user, sizeof target_p->username); |
1417 | rb_strlcpy(target_p->host, host, sizeof target_p->host); | |
212380e3 AC |
1418 | |
1419 | if (changed) | |
1420 | add_history(target_p, 1); | |
1421 | ||
1422 | del_from_client_hash(target_p->name, target_p); | |
f427c8b0 | 1423 | rb_strlcpy(target_p->name, nick, NICKLEN); |
212380e3 AC |
1424 | add_to_client_hash(target_p->name, target_p); |
1425 | ||
1426 | if(changed) | |
1427 | { | |
1428 | monitor_signon(target_p); | |
1429 | del_all_accepts(target_p); | |
1430 | } | |
1431 | } |