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