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