]>
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 | ||
b1594414 JT |
317 | if(IsConfSSLNeeded(aconf) && !IsSSL(source_p)) |
318 | { | |
319 | ServerStats.is_ref++; | |
320 | sendto_one_notice(source_p, ":*** Notice -- You need to use SSL/TLS to use this server"); | |
321 | exit_client(client_p, source_p, &me, "Use SSL/TLS"); | |
322 | return (CLIENT_EXITED); | |
323 | } | |
324 | ||
212380e3 AC |
325 | if(!IsGotId(source_p)) |
326 | { | |
327 | const char *p; | |
328 | int i = 0; | |
329 | ||
330 | if(IsNeedIdentd(aconf)) | |
331 | { | |
47adde3d | 332 | ServerStats.is_ref++; |
5366977b | 333 | sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server"); |
212380e3 AC |
334 | exit_client(client_p, source_p, &me, "Install identd"); |
335 | return (CLIENT_EXITED); | |
336 | } | |
337 | ||
338 | /* dont replace username if its supposed to be spoofed --fl */ | |
27f616dd | 339 | if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')) |
212380e3 AC |
340 | { |
341 | p = username; | |
342 | ||
343 | if(!IsNoTilde(aconf)) | |
344 | source_p->username[i++] = '~'; | |
345 | ||
346 | while (*p && i < USERLEN) | |
347 | { | |
348 | if(*p != '[') | |
349 | source_p->username[i++] = *p; | |
350 | p++; | |
351 | } | |
352 | ||
353 | source_p->username[i] = '\0'; | |
354 | } | |
355 | } | |
356 | ||
357 | if(IsNeedSasl(aconf) && !*user->suser) | |
358 | { | |
47adde3d | 359 | ServerStats.is_ref++; |
5366977b | 360 | sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server"); |
212380e3 AC |
361 | exit_client(client_p, source_p, &me, "SASL access only"); |
362 | return (CLIENT_EXITED); | |
363 | } | |
364 | ||
365 | /* password check */ | |
366 | if(!EmptyString(aconf->passwd)) | |
367 | { | |
368 | const char *encr; | |
369 | ||
370 | if(EmptyString(source_p->localClient->passwd)) | |
371 | encr = ""; | |
372 | else if(IsConfEncrypted(aconf)) | |
ba8b3ff1 | 373 | encr = rb_crypt(source_p->localClient->passwd, aconf->passwd); |
212380e3 AC |
374 | else |
375 | encr = source_p->localClient->passwd; | |
376 | ||
377 | if(strcmp(encr, aconf->passwd)) | |
378 | { | |
47adde3d | 379 | ServerStats.is_ref++; |
212380e3 AC |
380 | sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); |
381 | exit_client(client_p, source_p, &me, "Bad Password"); | |
382 | return (CLIENT_EXITED); | |
383 | } | |
384 | ||
385 | /* clear password only if used now, otherwise send it | |
386 | * to services -- jilles */ | |
387 | if(source_p->localClient->passwd) | |
388 | { | |
389 | memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); | |
637c4932 | 390 | rb_free(source_p->localClient->passwd); |
212380e3 AC |
391 | source_p->localClient->passwd = NULL; |
392 | } | |
393 | } | |
394 | ||
395 | /* report if user has &^>= etc. and set flags as needed in source_p */ | |
396 | report_and_set_user_flags(source_p, aconf); | |
397 | ||
398 | /* Limit clients */ | |
399 | /* | |
400 | * We want to be able to have servers and F-line clients | |
401 | * connect, so save room for "buffer" connections. | |
402 | * Smaller servers may want to decrease this, and it should | |
403 | * probably be just a percentage of the MAXCLIENTS... | |
404 | * -Taner | |
405 | */ | |
406 | /* Except "F:" clients */ | |
330fc5c1 | 407 | if(rb_dlink_list_length(&lclient_list) >= |
5ca543e7 | 408 | (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf)) |
212380e3 AC |
409 | { |
410 | sendto_realops_snomask(SNO_FULL, L_ALL, | |
411 | "Too many clients, rejecting %s[%s].", source_p->name, source_p->host); | |
412 | ||
47adde3d | 413 | ServerStats.is_ref++; |
212380e3 AC |
414 | exit_client(client_p, source_p, &me, "Sorry, server is full - try later"); |
415 | return (CLIENT_EXITED); | |
416 | } | |
417 | ||
212380e3 AC |
418 | /* kline exemption extends to xline too */ |
419 | if(!IsExemptKline(source_p) && | |
35f6f850 | 420 | (xconf = find_xline(source_p->info, 1)) != NULL) |
212380e3 | 421 | { |
47adde3d | 422 | ServerStats.is_ref++; |
70ea02eb | 423 | add_reject(source_p, xconf->host, NULL); |
212380e3 AC |
424 | exit_client(client_p, source_p, &me, "Bad user info"); |
425 | return CLIENT_EXITED; | |
426 | } | |
427 | ||
428 | /* dnsbl check */ | |
429 | if (source_p->preClient->dnsbl_listed != NULL) | |
430 | { | |
431 | if (IsExemptKline(source_p) || IsConfExemptDNSBL(aconf)) | |
432 | sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s, but you are exempt", | |
433 | source_p->sockhost, source_p->preClient->dnsbl_listed->host); | |
434 | else | |
435 | { | |
330fc5c1 | 436 | rb_dlink_list varlist = { NULL, NULL, 0 }; |
92fb5c31 AC |
437 | |
438 | substitution_append_var(&varlist, "nick", source_p->name); | |
439 | substitution_append_var(&varlist, "ip", source_p->sockhost); | |
440 | substitution_append_var(&varlist, "host", source_p->host); | |
441 | substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->dnsbl_listed->host); | |
442 | substitution_append_var(&varlist, "network-name", ServerInfo.network_name); | |
443 | ||
47adde3d | 444 | ServerStats.is_ref++; |
92fb5c31 | 445 | |
212380e3 AC |
446 | sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP), |
447 | me.name, source_p->name, | |
92fb5c31 AC |
448 | substitution_parse(source_p->preClient->dnsbl_listed->reject_reason, &varlist)); |
449 | ||
450 | substitution_free(&varlist); | |
451 | ||
212380e3 AC |
452 | sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s", |
453 | source_p->sockhost, source_p->preClient->dnsbl_listed->host); | |
454 | source_p->preClient->dnsbl_listed->hits++; | |
54ac8b60 | 455 | add_reject(source_p, NULL, NULL); |
212380e3 AC |
456 | exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)"); |
457 | return CLIENT_EXITED; | |
458 | } | |
459 | } | |
460 | ||
0734f634 JT |
461 | /* valid user name check */ |
462 | ||
463 | if(!valid_username(source_p->username)) | |
464 | { | |
465 | sendto_realops_snomask(SNO_REJ, L_ALL, | |
466 | "Invalid username: %s (%s@%s)", | |
467 | source_p->name, source_p->username, source_p->host); | |
47adde3d | 468 | ServerStats.is_ref++; |
cc32202d AC |
469 | sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains " |
470 | "only alphanumeric characters."); | |
b2f0da88 | 471 | rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username); |
0734f634 JT |
472 | exit_client(client_p, source_p, &me, tmpstr2); |
473 | return (CLIENT_EXITED); | |
474 | } | |
475 | ||
476 | /* end of valid user name check */ | |
477 | ||
212380e3 | 478 | /* Store original hostname -- jilles */ |
f427c8b0 | 479 | rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1); |
212380e3 AC |
480 | |
481 | /* Spoof user@host */ | |
482 | if(*source_p->preClient->spoofuser) | |
f427c8b0 | 483 | rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1); |
212380e3 AC |
484 | if(*source_p->preClient->spoofhost) |
485 | { | |
f427c8b0 | 486 | rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1); |
212380e3 AC |
487 | if (irccmp(source_p->host, source_p->orighost)) |
488 | SetDynSpoof(source_p); | |
489 | } | |
490 | ||
e2b44358 JT |
491 | source_p->umodes |= ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes & ~orphaned_umodes; |
492 | ||
493 | call_hook(h_new_local_user, source_p); | |
494 | ||
495 | /* If they have died in send_* or were thrown out by the | |
496 | * new_local_user hook don't do anything. */ | |
497 | if(IsAnyDead(source_p)) | |
212380e3 AC |
498 | return CLIENT_EXITED; |
499 | ||
e2b44358 JT |
500 | /* To avoid inconsistencies, do not abort the registration |
501 | * starting from this point -- jilles | |
502 | */ | |
caa4d9d2 | 503 | rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); |
212380e3 AC |
504 | |
505 | sendto_realops_snomask(SNO_CCONN, L_ALL, | |
506 | "Client connecting: %s (%s@%s) [%s] {%s} [%s]", | |
507 | source_p->name, source_p->username, source_p->orighost, | |
508 | show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", | |
509 | get_client_class(source_p), source_p->info); | |
510 | ||
511 | sendto_realops_snomask(SNO_CCONNEXT, L_ALL, | |
512 | "CLICONN %s %s %s %s %s %s 0 %s", | |
513 | source_p->name, source_p->username, source_p->orighost, | |
514 | show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", | |
515 | get_client_class(source_p), | |
516 | /* mirc can sometimes send ips here */ | |
517 | show_ip(NULL, source_p) ? source_p->localClient->fullcaps : "<hidden> <hidden>", | |
518 | source_p->info); | |
519 | ||
212380e3 AC |
520 | add_to_hostname_hash(source_p->orighost, source_p); |
521 | ||
522 | /* Allocate a UID if it was not previously allocated. | |
523 | * If this already occured, it was probably during SASL auth... | |
524 | */ | |
525 | if(!*source_p->id) | |
526 | { | |
527 | strcpy(source_p->id, generate_uid()); | |
528 | add_to_id_hash(source_p->id, source_p); | |
529 | } | |
530 | ||
3318e109 AC |
531 | if (IsSSL(source_p)) |
532 | source_p->umodes |= UMODE_SSLCLIENT; | |
533 | ||
212380e3 AC |
534 | if (source_p->umodes & UMODE_INVISIBLE) |
535 | Count.invisi++; | |
536 | ||
537 | s_assert(!IsClient(source_p)); | |
330fc5c1 | 538 | rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list); |
212380e3 AC |
539 | SetClient(source_p); |
540 | ||
0a61720a | 541 | source_p->servptr = &me; |
330fc5c1 | 542 | rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); |
0a61720a | 543 | |
212380e3 AC |
544 | /* Increment our total user count here */ |
545 | if(++Count.total > Count.max_tot) | |
546 | Count.max_tot = Count.total; | |
0a61720a | 547 | |
212380e3 AC |
548 | source_p->localClient->allow_read = MAX_FLOOD_BURST; |
549 | ||
550 | Count.totalrestartcount++; | |
551 | ||
552 | s_assert(source_p->localClient != NULL); | |
553 | ||
330fc5c1 | 554 | if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc) |
212380e3 | 555 | { |
330fc5c1 | 556 | Count.max_loc = rb_dlink_list_length(&lclient_list); |
212380e3 AC |
557 | if(!(Count.max_loc % 10)) |
558 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
559 | "New Max Local Clients: %d", Count.max_loc); | |
560 | } | |
561 | ||
562 | /* they get a reduced limit */ | |
563 | if(find_tgchange(source_p->sockhost)) | |
179becdf JT |
564 | source_p->localClient->targets_free = TGCHANGE_INITIAL_LOW; |
565 | else | |
566 | source_p->localClient->targets_free = TGCHANGE_INITIAL; | |
212380e3 | 567 | |
212380e3 AC |
568 | monitor_signon(source_p); |
569 | user_welcome(source_p); | |
570 | ||
571 | free_pre_client(source_p); | |
572 | ||
573 | return (introduce_client(client_p, source_p, user, source_p->name, 1)); | |
574 | } | |
575 | ||
576 | /* | |
577 | * introduce_clients | |
578 | * | |
579 | * inputs - | |
580 | * output - | |
581 | * side effects - This common function introduces a client to the rest | |
582 | * of the net, either from a local client connect or | |
583 | * from a remote connect. | |
584 | */ | |
585 | int | |
586 | introduce_client(struct Client *client_p, struct Client *source_p, struct User *user, const char *nick, int use_euid) | |
587 | { | |
588 | static char ubuf[12]; | |
589 | struct Client *identifyservice_p; | |
590 | char *p; | |
591 | hook_data_umode_changed hdata; | |
592 | hook_data_client hdata2; | |
ca273a1c | 593 | char sockhost[HOSTLEN]; |
212380e3 AC |
594 | |
595 | if(MyClient(source_p)) | |
596 | send_umode(source_p, source_p, 0, 0, ubuf); | |
597 | else | |
598 | send_umode(NULL, source_p, 0, 0, ubuf); | |
599 | ||
600 | if(!*ubuf) | |
601 | { | |
602 | ubuf[0] = '+'; | |
603 | ubuf[1] = '\0'; | |
604 | } | |
605 | ||
ca273a1c AC |
606 | s_assert(has_id(source_p)); |
607 | ||
608 | if(source_p->sockhost[0] == ':') | |
212380e3 | 609 | { |
ca273a1c AC |
610 | sockhost[0] = '0'; |
611 | sockhost[1] = '\0'; | |
612 | rb_strlcat(sockhost, source_p->sockhost, sizeof(sockhost)); | |
613 | } else | |
614 | strcpy(sockhost, source_p->sockhost); | |
212380e3 | 615 | |
ca273a1c AC |
616 | if (use_euid) |
617 | sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS, | |
618 | ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", | |
619 | source_p->servptr->id, nick, | |
620 | source_p->hopcount + 1, | |
621 | (long) source_p->tsinfo, ubuf, | |
622 | source_p->username, source_p->host, | |
623 | IsIPSpoof(source_p) ? "0" : sockhost, | |
624 | source_p->id, | |
625 | IsDynSpoof(source_p) ? source_p->orighost : "*", | |
626 | EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, | |
627 | source_p->info); | |
628 | ||
629 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, | |
630 | ":%s UID %s %d %ld %s %s %s %s %s :%s", | |
631 | source_p->servptr->id, nick, | |
632 | source_p->hopcount + 1, | |
633 | (long) source_p->tsinfo, ubuf, | |
634 | source_p->username, source_p->host, | |
635 | IsIPSpoof(source_p) ? "0" : sockhost, | |
636 | source_p->id, source_p->info); | |
212380e3 | 637 | |
8eda114a JT |
638 | if(!EmptyString(source_p->certfp)) |
639 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, | |
640 | ":%s ENCAP * CERTFP :%s", | |
641 | use_id(source_p), source_p->certfp); | |
642 | ||
212380e3 AC |
643 | if (IsDynSpoof(source_p)) |
644 | { | |
645 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s", | |
646 | use_id(source_p), source_p->orighost); | |
212380e3 | 647 | } |
ca273a1c | 648 | |
212380e3 AC |
649 | if (!EmptyString(source_p->user->suser)) |
650 | { | |
651 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s", | |
652 | use_id(source_p), source_p->user->suser); | |
212380e3 AC |
653 | } |
654 | ||
655 | if(MyConnect(source_p) && source_p->localClient->passwd) | |
656 | { | |
0a01ecfa JT |
657 | if (!EmptyString(ConfigFileEntry.identifyservice) && |
658 | !EmptyString(ConfigFileEntry.identifycommand)) | |
212380e3 AC |
659 | { |
660 | /* use user@server */ | |
661 | p = strchr(ConfigFileEntry.identifyservice, '@'); | |
662 | if (p != NULL) | |
663 | identifyservice_p = find_named_client(p + 1); | |
664 | else | |
665 | identifyservice_p = NULL; | |
666 | if (identifyservice_p != NULL) | |
12f4addb SB |
667 | { |
668 | if (!EmptyString(source_p->localClient->auth_user)) | |
669 | sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s", | |
670 | get_id(source_p, identifyservice_p), | |
671 | ConfigFileEntry.identifyservice, | |
672 | ConfigFileEntry.identifycommand, | |
673 | source_p->localClient->auth_user, | |
674 | source_p->localClient->passwd); | |
675 | else | |
676 | sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s", | |
677 | get_id(source_p, identifyservice_p), | |
678 | ConfigFileEntry.identifyservice, | |
679 | ConfigFileEntry.identifycommand, | |
680 | source_p->localClient->passwd); | |
681 | } | |
212380e3 AC |
682 | } |
683 | memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); | |
637c4932 | 684 | rb_free(source_p->localClient->passwd); |
212380e3 AC |
685 | source_p->localClient->passwd = NULL; |
686 | } | |
687 | ||
688 | /* let modules providing usermodes know that we've got a new user, | |
689 | * why is this here? -- well, some modules need to be able to send out new | |
690 | * information about a client, so this was the best place to do it | |
691 | * --nenolod | |
692 | */ | |
693 | hdata.client = source_p; | |
694 | hdata.oldumodes = 0; | |
695 | hdata.oldsnomask = 0; | |
696 | call_hook(h_umode_changed, &hdata); | |
697 | ||
698 | /* On the other hand, some modules need to know when a client is | |
699 | * being introduced, period. | |
700 | * --gxti | |
701 | */ | |
702 | hdata2.client = client_p; | |
703 | hdata2.target = source_p; | |
704 | call_hook(h_introduce_client, &hdata2); | |
705 | ||
706 | return 0; | |
707 | } | |
708 | ||
709 | /* | |
710 | * valid_hostname - check hostname for validity | |
711 | * | |
712 | * Inputs - pointer to user | |
713 | * Output - YES if valid, NO if not | |
714 | * Side effects - NONE | |
715 | * | |
716 | * NOTE: this doesn't allow a hostname to begin with a dot and | |
717 | * will not allow more dots than chars. | |
718 | */ | |
719 | int | |
720 | valid_hostname(const char *hostname) | |
721 | { | |
9a180ae3 | 722 | const char *p = hostname, *last_slash = 0; |
212380e3 AC |
723 | int found_sep = 0; |
724 | ||
725 | s_assert(NULL != p); | |
726 | ||
727 | if(hostname == NULL) | |
728 | return NO; | |
729 | ||
9a180ae3 | 730 | if('.' == *p || ':' == *p || '/' == *p) |
212380e3 AC |
731 | return NO; |
732 | ||
733 | while (*p) | |
734 | { | |
735 | if(!IsHostChar(*p)) | |
736 | return NO; | |
737 | if(*p == '.' || *p == ':') | |
738 | found_sep++; | |
9a180ae3 SB |
739 | else if(*p == '/') |
740 | { | |
741 | found_sep++; | |
742 | last_slash = p; | |
743 | } | |
212380e3 AC |
744 | p++; |
745 | } | |
746 | ||
747 | if(found_sep == 0) | |
9a180ae3 SB |
748 | return NO; |
749 | ||
750 | if(last_slash && IsDigit(last_slash[1])) | |
751 | return NO; | |
212380e3 | 752 | |
9a180ae3 | 753 | return YES; |
212380e3 AC |
754 | } |
755 | ||
756 | /* | |
757 | * valid_username - check username for validity | |
758 | * | |
759 | * Inputs - pointer to user | |
760 | * Output - YES if valid, NO if not | |
761 | * Side effects - NONE | |
762 | * | |
763 | * Absolutely always reject any '*' '!' '?' '@' in an user name | |
764 | * reject any odd control characters names. | |
765 | * Allow '.' in username to allow for "first.last" | |
766 | * style of username | |
767 | */ | |
768 | int | |
769 | valid_username(const char *username) | |
770 | { | |
771 | int dots = 0; | |
772 | const char *p = username; | |
773 | ||
774 | s_assert(NULL != p); | |
775 | ||
776 | if(username == NULL) | |
777 | return NO; | |
778 | ||
779 | if('~' == *p) | |
780 | ++p; | |
781 | ||
782 | /* reject usernames that don't start with an alphanum | |
783 | * i.e. reject jokers who have '-@somehost' or '.@somehost' | |
784 | * or "-hi-@somehost", "h-----@somehost" would still be accepted. | |
785 | */ | |
786 | if(!IsAlNum(*p)) | |
787 | return NO; | |
788 | ||
789 | while (*++p) | |
790 | { | |
791 | if((*p == '.') && ConfigFileEntry.dots_in_ident) | |
792 | { | |
793 | dots++; | |
794 | if(dots > ConfigFileEntry.dots_in_ident) | |
795 | return NO; | |
796 | if(!IsUserChar(p[1])) | |
797 | return NO; | |
798 | } | |
799 | else if(!IsUserChar(*p)) | |
800 | return NO; | |
801 | } | |
802 | return YES; | |
803 | } | |
804 | ||
805 | /* report_and_set_user_flags | |
806 | * | |
807 | * Inputs - pointer to source_p | |
808 | * - pointer to aconf for this user | |
809 | * Output - NONE | |
810 | * Side effects - | |
811 | * Report to user any special flags they are getting, and set them. | |
812 | */ | |
813 | ||
814 | static void | |
815 | report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf) | |
816 | { | |
817 | /* If this user is being spoofed, tell them so */ | |
818 | if(IsConfDoSpoofIp(aconf)) | |
819 | { | |
e07de82c | 820 | sendto_one_notice(source_p, ":*** Spoofing your IP"); |
212380e3 AC |
821 | } |
822 | ||
823 | /* If this user is in the exception class, Set it "E lined" */ | |
824 | if(IsConfExemptKline(aconf)) | |
825 | { | |
826 | SetExemptKline(source_p); | |
5c16ab05 | 827 | sendto_one_notice(source_p, ":*** You are exempt from K/X lines"); |
212380e3 AC |
828 | } |
829 | ||
212380e3 AC |
830 | if(IsConfExemptDNSBL(aconf)) |
831 | /* kline exempt implies this, don't send both */ | |
832 | if(!IsConfExemptKline(aconf)) | |
e07de82c | 833 | sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists"); |
212380e3 AC |
834 | |
835 | /* If this user is exempt from user limits set it F lined" */ | |
836 | if(IsConfExemptLimits(aconf)) | |
837 | { | |
e07de82c | 838 | sendto_one_notice(source_p, ":*** You are exempt from user limits"); |
212380e3 AC |
839 | } |
840 | ||
212380e3 AC |
841 | if(IsConfExemptFlood(aconf)) |
842 | { | |
843 | SetExemptFlood(source_p); | |
e07de82c | 844 | sendto_one_notice(source_p, ":*** You are exempt from flood limits"); |
212380e3 AC |
845 | } |
846 | ||
847 | if(IsConfExemptSpambot(aconf)) | |
848 | { | |
849 | SetExemptSpambot(source_p); | |
e07de82c | 850 | sendto_one_notice(source_p, ":*** You are exempt from spambot checks"); |
212380e3 AC |
851 | } |
852 | ||
853 | if(IsConfExemptJupe(aconf)) | |
854 | { | |
855 | SetExemptJupe(source_p); | |
e07de82c | 856 | sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings"); |
212380e3 AC |
857 | } |
858 | ||
859 | if(IsConfExemptResv(aconf)) | |
860 | { | |
861 | SetExemptResv(source_p); | |
e07de82c | 862 | sendto_one_notice(source_p, ":*** You are exempt from resvs"); |
212380e3 AC |
863 | } |
864 | ||
865 | if(IsConfExemptShide(aconf)) | |
866 | { | |
867 | SetExemptShide(source_p); | |
e07de82c | 868 | sendto_one_notice(source_p, ":*** You are exempt from serverhiding"); |
212380e3 AC |
869 | } |
870 | } | |
871 | ||
681ddf64 JT |
872 | static void |
873 | show_other_user_mode(struct Client *source_p, struct Client *target_p) | |
874 | { | |
875 | int i; | |
876 | char buf[BUFSIZE]; | |
877 | char *m; | |
878 | ||
879 | m = buf; | |
880 | *m++ = '+'; | |
881 | ||
882 | for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ | |
883 | if (target_p->umodes & user_modes[i]) | |
884 | *m++ = (char) i; | |
885 | *m = '\0'; | |
886 | ||
887 | if (MyConnect(target_p) && target_p->snomask != 0) | |
888 | sendto_one_notice(source_p, ":Modes for %s are %s %s", | |
889 | target_p->name, buf, | |
890 | construct_snobuf(target_p->snomask)); | |
891 | else | |
892 | sendto_one_notice(source_p, ":Modes for %s are %s", | |
893 | target_p->name, buf); | |
894 | } | |
895 | ||
212380e3 AC |
896 | /* |
897 | * user_mode - set get current users mode | |
898 | * | |
899 | * m_umode() added 15/10/91 By Darren Reed. | |
212380e3 AC |
900 | * parv[1] - username to change mode for |
901 | * parv[2] - modes to change | |
902 | */ | |
903 | int | |
904 | user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
905 | { | |
906 | int flag; | |
907 | int i; | |
908 | char *m; | |
909 | const char *pm; | |
910 | struct Client *target_p; | |
911 | int what, setflags; | |
912 | int badflag = NO; /* Only send one bad flag notice */ | |
913 | int showsnomask = NO; | |
914 | unsigned int setsnomask; | |
915 | char buf[BUFSIZE]; | |
916 | hook_data_umode_changed hdata; | |
917 | ||
918 | what = MODE_ADD; | |
919 | ||
920 | if(parc < 2) | |
921 | { | |
922 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); | |
923 | return 0; | |
924 | } | |
925 | ||
926 | if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL) | |
927 | { | |
928 | if(MyConnect(source_p)) | |
929 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
930 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
931 | return 0; | |
932 | } | |
933 | ||
934 | /* Dont know why these were commented out.. | |
935 | * put them back using new sendto() funcs | |
936 | */ | |
937 | ||
938 | if(IsServer(source_p)) | |
939 | { | |
940 | sendto_realops_snomask(SNO_GENERAL, L_ADMIN, | |
941 | "*** Mode for User %s from %s", parv[1], source_p->name); | |
942 | return 0; | |
943 | } | |
944 | ||
c98c2c89 | 945 | if(source_p != target_p) |
212380e3 | 946 | { |
681ddf64 JT |
947 | if (MyOper(source_p) && parc < 3) |
948 | show_other_user_mode(source_p, target_p); | |
949 | else | |
950 | sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name); | |
212380e3 AC |
951 | return 0; |
952 | } | |
953 | ||
954 | if(parc < 3) | |
955 | { | |
956 | m = buf; | |
957 | *m++ = '+'; | |
958 | ||
959 | for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ | |
960 | if (source_p->umodes & user_modes[i]) | |
961 | *m++ = (char) i; | |
962 | ||
963 | *m = '\0'; | |
e8a2d50d | 964 | sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf); |
88520303 | 965 | |
212380e3 | 966 | if (source_p->snomask != 0) |
88520303 | 967 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 | 968 | construct_snobuf(source_p->snomask)); |
88520303 | 969 | |
212380e3 AC |
970 | return 0; |
971 | } | |
972 | ||
973 | /* find flags already set for user */ | |
974 | setflags = source_p->umodes; | |
975 | setsnomask = source_p->snomask; | |
976 | ||
977 | /* | |
978 | * parse mode change string(s) | |
979 | */ | |
980 | for (pm = parv[2]; *pm; pm++) | |
981 | switch (*pm) | |
982 | { | |
983 | case '+': | |
984 | what = MODE_ADD; | |
985 | break; | |
986 | case '-': | |
987 | what = MODE_DEL; | |
988 | break; | |
989 | ||
990 | case 'o': | |
991 | if(what == MODE_ADD) | |
992 | { | |
993 | if(IsServer(client_p) && !IsOper(source_p)) | |
994 | { | |
995 | ++Count.oper; | |
996 | SetOper(source_p); | |
330fc5c1 | 997 | rb_dlinkAddAlloc(source_p, &oper_list); |
212380e3 AC |
998 | } |
999 | } | |
1000 | else | |
1001 | { | |
1002 | /* Only decrement the oper counts if an oper to begin with | |
1003 | * found by Pat Szuta, Perly , perly@xnet.com | |
1004 | */ | |
1005 | ||
1006 | if(!IsOper(source_p)) | |
1007 | break; | |
1008 | ||
1009 | ClearOper(source_p); | |
1010 | ||
1011 | Count.oper--; | |
1012 | ||
1013 | if(MyConnect(source_p)) | |
1014 | { | |
1015 | source_p->umodes &= ~ConfigFileEntry.oper_only_umodes; | |
1016 | if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0) | |
1017 | { | |
1018 | source_p->snomask = 0; | |
1019 | showsnomask = YES; | |
1020 | } | |
1021 | source_p->flags2 &= ~OPER_FLAGS; | |
1022 | ||
637c4932 | 1023 | rb_free(source_p->localClient->opername); |
212380e3 AC |
1024 | source_p->localClient->opername = NULL; |
1025 | ||
330fc5c1 | 1026 | rb_dlinkFindDestroy(source_p, &local_oper_list); |
83dfad0e JT |
1027 | privilegeset_unref(source_p->localClient->privset); |
1028 | source_p->localClient->privset = NULL; | |
212380e3 AC |
1029 | } |
1030 | ||
330fc5c1 | 1031 | rb_dlinkFindDestroy(source_p, &oper_list); |
212380e3 AC |
1032 | } |
1033 | break; | |
1034 | ||
1035 | /* we may not get these, | |
1036 | * but they shouldnt be in default | |
1037 | */ | |
1038 | ||
1039 | /* can only be set on burst */ | |
1040 | case 'S': | |
3318e109 | 1041 | case 'Z': |
212380e3 AC |
1042 | case ' ': |
1043 | case '\n': | |
1044 | case '\r': | |
1045 | case '\t': | |
1046 | break; | |
1047 | ||
1048 | case 's': | |
1049 | if (MyConnect(source_p)) | |
1050 | { | |
1051 | if(!IsOper(source_p) | |
1052 | && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE)) | |
1053 | { | |
1054 | if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE) | |
1055 | badflag = YES; | |
1056 | continue; | |
1057 | } | |
1058 | showsnomask = YES; | |
1059 | if(what == MODE_ADD) | |
1060 | { | |
1061 | if (parc > 3) | |
1062 | source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]); | |
1063 | else | |
1064 | source_p->snomask |= SNO_GENERAL; | |
1065 | } | |
1066 | else | |
1067 | source_p->snomask = 0; | |
1068 | if (source_p->snomask != 0) | |
1069 | source_p->umodes |= UMODE_SERVNOTICE; | |
1070 | else | |
1071 | source_p->umodes &= ~UMODE_SERVNOTICE; | |
1072 | break; | |
1073 | } | |
1074 | /* FALLTHROUGH */ | |
1075 | default: | |
2da6f6eb JT |
1076 | if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) |
1077 | { | |
1078 | badflag = YES; | |
1079 | break; | |
1080 | } | |
1081 | ||
212380e3 AC |
1082 | if((flag = user_modes[(unsigned char) *pm])) |
1083 | { | |
1084 | if(MyConnect(source_p) | |
a8086a7c JT |
1085 | && ((!IsOper(source_p) |
1086 | && (ConfigFileEntry.oper_only_umodes & flag)) | |
1087 | || (orphaned_umodes & flag))) | |
212380e3 AC |
1088 | { |
1089 | if (what == MODE_ADD || source_p->umodes & flag) | |
1090 | badflag = YES; | |
1091 | } | |
1092 | else | |
1093 | { | |
1094 | if(what == MODE_ADD) | |
1095 | source_p->umodes |= flag; | |
1096 | else | |
1097 | source_p->umodes &= ~flag; | |
1098 | } | |
1099 | } | |
1100 | else | |
1101 | { | |
1102 | if(MyConnect(source_p)) | |
1103 | badflag = YES; | |
1104 | } | |
1105 | break; | |
1106 | } | |
1107 | ||
1108 | if(badflag) | |
1109 | sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name); | |
1110 | ||
1111 | if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p)) | |
1112 | { | |
b4838ccd | 1113 | sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n"); |
212380e3 AC |
1114 | source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */ |
1115 | } | |
1116 | ||
1117 | if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p)) | |
1118 | { | |
5366977b | 1119 | sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z"); |
212380e3 AC |
1120 | source_p->umodes &= ~UMODE_OPERWALL; |
1121 | } | |
1122 | ||
1123 | if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) && | |
1124 | (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))) | |
1125 | { | |
b4838ccd | 1126 | sendto_one_notice(source_p, ":*** You need oper and admin flag for +a"); |
212380e3 AC |
1127 | source_p->umodes &= ~UMODE_ADMIN; |
1128 | } | |
1129 | ||
1130 | /* let modules providing usermodes know that we've changed our usermode --nenolod */ | |
1131 | hdata.client = source_p; | |
1132 | hdata.oldumodes = setflags; | |
1133 | hdata.oldsnomask = setsnomask; | |
1134 | call_hook(h_umode_changed, &hdata); | |
1135 | ||
1136 | if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p)) | |
1137 | ++Count.invisi; | |
1138 | if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p)) | |
1139 | --Count.invisi; | |
1140 | /* | |
1141 | * compare new flags with old flags and send string which | |
1142 | * will cause servers to update correctly. | |
1143 | */ | |
1144 | send_umode_out(client_p, source_p, setflags); | |
1145 | if (showsnomask && MyConnect(source_p)) | |
88520303 | 1146 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 AC |
1147 | construct_snobuf(source_p->snomask)); |
1148 | ||
1149 | return (0); | |
1150 | } | |
1151 | ||
1152 | /* | |
1153 | * send the MODE string for user (user) to connection client_p | |
1154 | * -avalon | |
1155 | */ | |
1156 | void | |
1157 | send_umode(struct Client *client_p, struct Client *source_p, int old, int sendmask, char *umode_buf) | |
1158 | { | |
1159 | int i; | |
1160 | int flag; | |
1161 | char *m; | |
1162 | int what = 0; | |
1163 | ||
1164 | /* | |
1165 | * build a string in umode_buf to represent the change in the user's | |
1166 | * mode between the new (source_p->flag) and 'old'. | |
1167 | */ | |
1168 | m = umode_buf; | |
1169 | *m = '\0'; | |
1170 | ||
1171 | for (i = 0; i < 128; i++) | |
1172 | { | |
1173 | flag = user_modes[i]; | |
1174 | ||
1175 | if((flag & old) && !(source_p->umodes & flag)) | |
1176 | { | |
1177 | if(what == MODE_DEL) | |
1178 | *m++ = (char) i; | |
1179 | else | |
1180 | { | |
1181 | what = MODE_DEL; | |
1182 | *m++ = '-'; | |
1183 | *m++ = (char) i; | |
1184 | } | |
1185 | } | |
1186 | else if(!(flag & old) && (source_p->umodes & flag)) | |
1187 | { | |
1188 | if(what == MODE_ADD) | |
1189 | *m++ = (char) i; | |
1190 | else | |
1191 | { | |
1192 | what = MODE_ADD; | |
1193 | *m++ = '+'; | |
1194 | *m++ = (char) i; | |
1195 | } | |
1196 | } | |
1197 | } | |
1198 | *m = '\0'; | |
1199 | ||
1200 | if(*umode_buf && client_p) | |
1201 | sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf); | |
1202 | } | |
1203 | ||
1204 | /* | |
1205 | * send_umode_out | |
1206 | * | |
1207 | * inputs - | |
1208 | * output - NONE | |
1209 | * side effects - | |
1210 | */ | |
1211 | void | |
1212 | send_umode_out(struct Client *client_p, struct Client *source_p, int old) | |
1213 | { | |
1214 | struct Client *target_p; | |
1215 | char buf[BUFSIZE]; | |
330fc5c1 | 1216 | rb_dlink_node *ptr; |
212380e3 AC |
1217 | |
1218 | send_umode(NULL, source_p, old, 0, buf); | |
1219 | ||
5cefa1d6 | 1220 | RB_DLINK_FOREACH(ptr, serv_list.head) |
212380e3 AC |
1221 | { |
1222 | target_p = ptr->data; | |
1223 | ||
1224 | if((target_p != client_p) && (target_p != source_p) && (*buf)) | |
1225 | { | |
1226 | sendto_one(target_p, ":%s MODE %s :%s", | |
1227 | get_id(source_p, target_p), | |
1228 | get_id(source_p, target_p), buf); | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | if(client_p && MyClient(client_p)) | |
1233 | send_umode(client_p, source_p, old, 0, buf); | |
1234 | } | |
1235 | ||
1236 | /* | |
1237 | * user_welcome | |
1238 | * | |
1239 | * inputs - client pointer to client to welcome | |
1240 | * output - NONE | |
1241 | * side effects - | |
1242 | */ | |
1243 | void | |
1244 | user_welcome(struct Client *source_p) | |
1245 | { | |
88520303 AC |
1246 | sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name); |
1247 | sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST), | |
212380e3 | 1248 | get_listener_name(source_p->localClient->listener), ircd_version); |
88520303 | 1249 | sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation); |
c18cb68b | 1250 | sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo); |
212380e3 AC |
1251 | |
1252 | show_isupport(source_p); | |
1253 | ||
1254 | show_lusers(source_p); | |
1255 | ||
1256 | if(ConfigFileEntry.short_motd) | |
1257 | { | |
5366977b AC |
1258 | sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed); |
1259 | sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it"); | |
212380e3 AC |
1260 | |
1261 | sendto_one(source_p, form_str(RPL_MOTDSTART), | |
1262 | me.name, source_p->name, me.name); | |
1263 | ||
1264 | sendto_one(source_p, form_str(RPL_MOTD), | |
1265 | me.name, source_p->name, "*** This is the short motd ***"); | |
1266 | ||
1267 | sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name); | |
1268 | } | |
1269 | else | |
1270 | send_user_motd(source_p); | |
1271 | } | |
1272 | ||
1273 | /* oper_up() | |
1274 | * | |
1275 | * inputs - pointer to given client to oper | |
1276 | * - pointer to ConfItem to use | |
1277 | * output - none | |
1278 | * side effects - opers up source_p using aconf for reference | |
1279 | */ | |
1280 | int | |
1281 | oper_up(struct Client *source_p, struct oper_conf *oper_p) | |
1282 | { | |
1283 | unsigned int old = source_p->umodes, oldsnomask = source_p->snomask; | |
1284 | hook_data_umode_changed hdata; | |
1285 | ||
1286 | SetOper(source_p); | |
1287 | ||
1288 | if(oper_p->umodes) | |
1289 | source_p->umodes |= oper_p->umodes; | |
1290 | else if(ConfigFileEntry.oper_umodes) | |
1291 | source_p->umodes |= ConfigFileEntry.oper_umodes; | |
1292 | else | |
1293 | source_p->umodes |= DEFAULT_OPER_UMODES; | |
1294 | ||
1295 | if (oper_p->snomask) | |
1296 | { | |
1297 | source_p->snomask |= oper_p->snomask; | |
1298 | source_p->umodes |= UMODE_SERVNOTICE; | |
1299 | } | |
1300 | else if (source_p->umodes & UMODE_SERVNOTICE) | |
1301 | { | |
1302 | /* Only apply these if +s is already set -- jilles */ | |
1303 | if (ConfigFileEntry.oper_snomask) | |
1304 | source_p->snomask |= ConfigFileEntry.oper_snomask; | |
1305 | else | |
1306 | source_p->snomask |= DEFAULT_OPER_SNOMASK; | |
1307 | } | |
1308 | ||
1309 | Count.oper++; | |
1310 | ||
1311 | SetExemptKline(source_p); | |
1312 | ||
1313 | source_p->flags2 |= oper_p->flags; | |
47a03750 | 1314 | source_p->localClient->opername = rb_strdup(oper_p->name); |
ef242716 | 1315 | source_p->localClient->privset = privilegeset_ref(oper_p->privset); |
212380e3 | 1316 | |
330fc5c1 AC |
1317 | rb_dlinkAddAlloc(source_p, &local_oper_list); |
1318 | rb_dlinkAddAlloc(source_p, &oper_list); | |
212380e3 AC |
1319 | |
1320 | if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p)) | |
1321 | source_p->umodes |= UMODE_ADMIN; | |
1322 | if(!IsOperN(source_p)) | |
1323 | source_p->snomask &= ~SNO_NCHANGE; | |
1324 | if(!IsOperOperwall(source_p)) | |
1325 | source_p->umodes &= ~UMODE_OPERWALL; | |
1326 | hdata.client = source_p; | |
1327 | hdata.oldumodes = old; | |
1328 | hdata.oldsnomask = oldsnomask; | |
1329 | call_hook(h_umode_changed, &hdata); | |
1330 | ||
1331 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
5cca545c | 1332 | "%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name, |
212380e3 | 1333 | source_p->username, source_p->host); |
652b8478 JT |
1334 | if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p)) |
1335 | ++Count.invisi; | |
1336 | if((old & UMODE_INVISIBLE) && !IsInvisible(source_p)) | |
1337 | --Count.invisi; | |
212380e3 | 1338 | send_umode_out(source_p, source_p, old); |
88520303 | 1339 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 AC |
1340 | construct_snobuf(source_p->snomask)); |
1341 | sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); | |
22c3b270 AC |
1342 | sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name); |
1343 | sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs); | |
212380e3 AC |
1344 | send_oper_motd(source_p); |
1345 | ||
1346 | return (1); | |
1347 | } | |
1348 | ||
01cebbd8 JT |
1349 | /* |
1350 | * find_umode_slot | |
1351 | * | |
1352 | * inputs - NONE | |
1353 | * outputs - an available umode bitmask or | |
1354 | * 0 if no umodes are available | |
1355 | * side effects - NONE | |
1356 | */ | |
1357 | unsigned int | |
1358 | find_umode_slot(void) | |
1359 | { | |
1360 | unsigned int all_umodes = 0, my_umode = 0, i; | |
1361 | ||
1362 | for (i = 0; i < 128; i++) | |
1363 | all_umodes |= user_modes[i]; | |
1364 | ||
1365 | for (my_umode = 1; my_umode && (all_umodes & my_umode); | |
1366 | my_umode <<= 1); | |
1367 | ||
1368 | return my_umode; | |
1369 | } | |
1370 | ||
212380e3 AC |
1371 | void |
1372 | construct_umodebuf(void) | |
1373 | { | |
1374 | int i; | |
1375 | char *ptr = umodebuf; | |
a8086a7c | 1376 | static int prev_user_modes[128]; |
212380e3 AC |
1377 | |
1378 | *ptr = '\0'; | |
1379 | ||
1380 | for (i = 0; i < 128; i++) | |
a8086a7c JT |
1381 | { |
1382 | if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i]) | |
1383 | { | |
1384 | if (user_modes[i] == 0) | |
1385 | { | |
1386 | orphaned_umodes |= prev_user_modes[i]; | |
1387 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i); | |
1388 | } | |
1389 | else | |
1390 | { | |
1391 | orphaned_umodes &= ~prev_user_modes[i]; | |
1392 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i); | |
1393 | } | |
1394 | user_modes[i] = prev_user_modes[i]; | |
1395 | } | |
1396 | else | |
1397 | prev_user_modes[i] = user_modes[i]; | |
212380e3 AC |
1398 | if (user_modes[i]) |
1399 | *ptr++ = (char) i; | |
a8086a7c | 1400 | } |
212380e3 AC |
1401 | |
1402 | *ptr++ = '\0'; | |
1403 | } | |
1404 | ||
1405 | void | |
1406 | change_nick_user_host(struct Client *target_p, const char *nick, const char *user, | |
82622732 | 1407 | const char *host, int newts, const char *format, ...) |
212380e3 | 1408 | { |
330fc5c1 | 1409 | rb_dlink_node *ptr; |
212380e3 AC |
1410 | struct Channel *chptr; |
1411 | struct membership *mscptr; | |
1412 | int changed = irccmp(target_p->name, nick); | |
1413 | int changed_case = strcmp(target_p->name, nick); | |
1414 | int do_qjm = irccmp(target_p->username, user) || irccmp(target_p->host, host); | |
1415 | char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr; | |
1416 | va_list ap; | |
1417 | ||
1418 | modeval[0] = '\0'; | |
1419 | ||
1420 | if(changed) | |
1421 | { | |
1422 | target_p->tsinfo = newts; | |
1423 | monitor_signoff(target_p); | |
1424 | } | |
1425 | invalidate_bancache_user(target_p); | |
1426 | ||
1427 | if(do_qjm) | |
1428 | { | |
1429 | va_start(ap, format); | |
1430 | vsnprintf(reason, 255, format, ap); | |
1431 | va_end(ap); | |
1432 | ||
7a948bda | 1433 | sendto_common_channels_local_butone(target_p, NOCAPS, ":%s!%s@%s QUIT :%s", |
212380e3 AC |
1434 | target_p->name, target_p->username, target_p->host, |
1435 | reason); | |
1436 | ||
5cefa1d6 | 1437 | RB_DLINK_FOREACH(ptr, target_p->user->channel.head) |
212380e3 AC |
1438 | { |
1439 | mscptr = ptr->data; | |
1440 | chptr = mscptr->chptr; | |
1441 | mptr = mode; | |
1442 | ||
1443 | if(is_chanop(mscptr)) | |
1444 | { | |
1445 | *mptr++ = 'o'; | |
1446 | strcat(modeval, nick); | |
1447 | strcat(modeval, " "); | |
1448 | } | |
1449 | ||
1450 | if(is_voiced(mscptr)) | |
1451 | { | |
1452 | *mptr++ = 'v'; | |
1453 | strcat(modeval, nick); | |
1454 | } | |
1455 | ||
1456 | *mptr = '\0'; | |
1457 | ||
1458 | sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
1459 | nick, user, host, chptr->chname); | |
1460 | if(*mode) | |
1461 | sendto_channel_local_butone(target_p, ALL_MEMBERS, chptr, | |
1462 | ":%s MODE %s +%s %s", | |
1463 | target_p->servptr->name, | |
1464 | chptr->chname, mode, modeval); | |
1465 | ||
1466 | *modeval = '\0'; | |
1467 | } | |
1468 | ||
1469 | if(MyClient(target_p) && changed_case) | |
1470 | sendto_one(target_p, ":%s!%s@%s NICK %s", | |
1471 | target_p->name, target_p->username, target_p->host, nick); | |
1472 | } | |
1473 | else if(changed_case) | |
1474 | { | |
7a948bda | 1475 | sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s", |
212380e3 AC |
1476 | target_p->name, target_p->username, |
1477 | target_p->host, nick); | |
1478 | } | |
1479 | ||
f427c8b0 VY |
1480 | rb_strlcpy(target_p->username, user, sizeof target_p->username); |
1481 | rb_strlcpy(target_p->host, host, sizeof target_p->host); | |
212380e3 AC |
1482 | |
1483 | if (changed) | |
1484 | add_history(target_p, 1); | |
1485 | ||
1486 | del_from_client_hash(target_p->name, target_p); | |
f427c8b0 | 1487 | rb_strlcpy(target_p->name, nick, NICKLEN); |
212380e3 AC |
1488 | add_to_client_hash(target_p->name, target_p); |
1489 | ||
1490 | if(changed) | |
1491 | { | |
1492 | monitor_signon(target_p); | |
1493 | del_all_accepts(target_p); | |
1494 | } | |
1495 | } |