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