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