]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * s_user.c: User related functions. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
212380e3 AC |
26 | #include "s_user.h" |
27 | #include "channel.h" | |
28 | #include "class.h" | |
29 | #include "client.h" | |
212380e3 | 30 | #include "hash.h" |
4562c604 | 31 | #include "match.h" |
212380e3 AC |
32 | #include "ircd.h" |
33 | #include "listener.h" | |
34 | #include "msg.h" | |
35 | #include "numeric.h" | |
212380e3 AC |
36 | #include "s_conf.h" |
37 | #include "s_newconf.h" | |
4016731b | 38 | #include "logger.h" |
212380e3 AC |
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" | |
212380e3 AC |
45 | #include "packet.h" |
46 | #include "reject.h" | |
47 | #include "cache.h" | |
48 | #include "hook.h" | |
49 | #include "monitor.h" | |
50 | #include "snomask.h" | |
92fb5c31 | 51 | #include "substitution.h" |
c18cb68b | 52 | #include "chmode.h" |
77d3d2db | 53 | #include "s_assert.h" |
212380e3 AC |
54 | |
55 | static void report_and_set_user_flags(struct Client *, struct ConfItem *); | |
56 | void user_welcome(struct Client *source_p); | |
57 | ||
212380e3 AC |
58 | char umodebuf[128]; |
59 | ||
a8086a7c | 60 | static int orphaned_umodes = 0; |
212380e3 AC |
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 | UMODE_REGONLYMSG, /* R */ | |
85 | UMODE_SERVICE, /* S */ | |
86 | 0, /* T */ | |
87 | 0, /* U */ | |
88 | 0, /* V */ | |
89 | 0, /* W */ | |
90 | 0, /* X */ | |
91 | 0, /* Y */ | |
3318e109 | 92 | UMODE_SSLCLIENT, /* Z */ |
212380e3 AC |
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 | UMODE_CALLERID, /* 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 | */ | |
6287d57f | 139 | void |
212380e3 AC |
140 | show_lusers(struct Client *source_p) |
141 | { | |
330fc5c1 AC |
142 | if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount) |
143 | MaxClientCount = rb_dlink_list_length(&lclient_list); | |
2f15f871 | 144 | |
330fc5c1 | 145 | if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > |
2f15f871 | 146 | (unsigned long)MaxConnectionCount) |
55abcbb2 | 147 | MaxConnectionCount = rb_dlink_list_length(&lclient_list) + |
330fc5c1 | 148 | rb_dlink_list_length(&serv_list); |
2f15f871 | 149 | |
212380e3 AC |
150 | sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT), |
151 | (Count.total - Count.invisi), | |
0cce01d3 JT |
152 | Count.invisi, |
153 | (int)rb_dlink_list_length(&global_serv_list)); | |
212380e3 | 154 | |
330fc5c1 | 155 | if(rb_dlink_list_length(&oper_list) > 0) |
55abcbb2 | 156 | sendto_one_numeric(source_p, RPL_LUSEROP, |
77910830 JT |
157 | form_str(RPL_LUSEROP), |
158 | (int)rb_dlink_list_length(&oper_list)); | |
212380e3 | 159 | |
330fc5c1 | 160 | if(rb_dlink_list_length(&unknown_list) > 0) |
55abcbb2 | 161 | sendto_one_numeric(source_p, RPL_LUSERUNKNOWN, |
212380e3 | 162 | form_str(RPL_LUSERUNKNOWN), |
0cce01d3 | 163 | (int)rb_dlink_list_length(&unknown_list)); |
212380e3 | 164 | |
330fc5c1 | 165 | if(rb_dlink_list_length(&global_channel_list) > 0) |
55abcbb2 | 166 | sendto_one_numeric(source_p, RPL_LUSERCHANNELS, |
212380e3 | 167 | form_str(RPL_LUSERCHANNELS), |
330fc5c1 | 168 | rb_dlink_list_length(&global_channel_list)); |
212380e3 AC |
169 | |
170 | sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME), | |
0cce01d3 JT |
171 | (int)rb_dlink_list_length(&lclient_list), |
172 | (int)rb_dlink_list_length(&serv_list)); | |
212380e3 | 173 | |
55abcbb2 | 174 | sendto_one_numeric(source_p, RPL_LOCALUSERS, |
212380e3 | 175 | form_str(RPL_LOCALUSERS), |
0cce01d3 | 176 | (int)rb_dlink_list_length(&lclient_list), |
212380e3 | 177 | Count.max_loc, |
0cce01d3 | 178 | (int)rb_dlink_list_length(&lclient_list), |
212380e3 AC |
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), | |
55abcbb2 | 187 | MaxConnectionCount, MaxClientCount, |
212380e3 | 188 | Count.totalrestartcount); |
212380e3 AC |
189 | } |
190 | ||
7a21fb5b EM |
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': /* Blacklists */ | |
217 | { | |
5e9a3f86 | 218 | struct BlacklistStats *stats; |
7a21fb5b EM |
219 | char *blacklist = source_p->preClient->auth.data; |
220 | ||
3c5f720c SA |
221 | if(bl_stats != NULL) |
222 | if((stats = rb_dictionary_retrieve(bl_stats, blacklist)) != NULL) | |
223 | stats->hits++; | |
7a21fb5b EM |
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, blacklist); | |
229 | break; | |
230 | } | |
231 | ||
232 | sendto_realops_snomask(SNO_REJ, L_NETWIDE, | |
233 | "Listed on DNSBL %s: %s (%s@%s) [%s] [%s]", | |
234 | blacklist, 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, blacklist); | |
243 | add_reject(source_p, NULL, NULL); | |
244 | exit_client(client_p, source_p, &me, "Banned (DNS blacklist)"); | |
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_ALL, | |
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); | |
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); | |
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 | ||
212380e3 AC |
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... | |
cbeab4bc | 346 | */ |
212380e3 | 347 | int |
21251822 | 348 | register_local_user(struct Client *client_p, struct Client *source_p) |
212380e3 | 349 | { |
35f6f850 | 350 | struct ConfItem *aconf, *xconf; |
82236a2a | 351 | char tmpstr2[BUFSIZE]; |
212380e3 AC |
352 | char ipaddr[HOSTIPLEN]; |
353 | char myusername[USERLEN+1]; | |
354 | int status; | |
355 | ||
356 | s_assert(NULL != source_p); | |
357 | s_assert(MyConnect(source_p)); | |
212380e3 AC |
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 | { | |
da20854e SA |
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); | |
212380e3 AC |
372 | source_p->flags |= FLAGS_PINGSENT; |
373 | return -1; | |
374 | } | |
095328a7 | 375 | if(!(source_p->flags & FLAGS_PING_COOKIE)) |
212380e3 AC |
376 | { |
377 | return -1; | |
378 | } | |
379 | } | |
380 | ||
381 | /* hasnt finished client cap negotiation */ | |
095328a7 | 382 | if(source_p->flags & FLAGS_CLICAP) |
212380e3 AC |
383 | return -1; |
384 | ||
d3f6b808 | 385 | /* Waiting on authd */ |
154dc91e | 386 | if(source_p->preClient->auth.cid) |
212380e3 AC |
387 | return -1; |
388 | ||
e3354945 | 389 | client_p->localClient->last = rb_current_time(); |
212380e3 AC |
390 | |
391 | /* XXX - fixme. we shouldnt have to build a users buffer twice.. */ | |
21251822 | 392 | if(!IsGotId(source_p) && (strchr(source_p->username, '[') != NULL)) |
212380e3 AC |
393 | { |
394 | const char *p; | |
395 | int i = 0; | |
396 | ||
21251822 | 397 | p = source_p->username; |
212380e3 AC |
398 | |
399 | while(*p && i < USERLEN) | |
400 | { | |
401 | if(*p != '[') | |
402 | myusername[i++] = *p; | |
403 | p++; | |
404 | } | |
405 | ||
406 | myusername[i] = '\0'; | |
212380e3 | 407 | } |
21251822 | 408 | else |
dd64bf8d | 409 | rb_strlcpy(myusername, source_p->username, sizeof myusername); |
212380e3 | 410 | |
21251822 | 411 | if((status = check_client(client_p, source_p, myusername)) < 0) |
212380e3 AC |
412 | return (CLIENT_EXITED); |
413 | ||
414 | /* Apply nick override */ | |
415 | if(*source_p->preClient->spoofnick) | |
416 | { | |
fe5fc851 | 417 | char note[NAMELEN + 10]; |
fa94d8fb | 418 | |
212380e3 | 419 | del_from_client_hash(source_p->name, source_p); |
f427c8b0 | 420 | rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1); |
212380e3 | 421 | add_to_client_hash(source_p->name, source_p); |
fa94d8fb | 422 | |
fe5fc851 | 423 | snprintf(note, sizeof(note), "Nick: %s", source_p->name); |
fa94d8fb | 424 | rb_note(source_p->localClient->F, note); |
212380e3 AC |
425 | } |
426 | ||
427 | if(!valid_hostname(source_p->host)) | |
428 | { | |
5366977b | 429 | sendto_one_notice(source_p, ":*** Notice -- You have an illegal character in your hostname"); |
212380e3 | 430 | |
f427c8b0 | 431 | rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); |
212380e3 | 432 | } |
55abcbb2 | 433 | |
212380e3 AC |
434 | aconf = source_p->localClient->att_conf; |
435 | ||
436 | if(aconf == NULL) | |
437 | { | |
438 | exit_client(client_p, source_p, &me, "*** Not Authorised"); | |
439 | return (CLIENT_EXITED); | |
440 | } | |
441 | ||
b1594414 JT |
442 | if(IsConfSSLNeeded(aconf) && !IsSSL(source_p)) |
443 | { | |
444 | ServerStats.is_ref++; | |
445 | sendto_one_notice(source_p, ":*** Notice -- You need to use SSL/TLS to use this server"); | |
446 | exit_client(client_p, source_p, &me, "Use SSL/TLS"); | |
447 | return (CLIENT_EXITED); | |
448 | } | |
449 | ||
c6ad9b0c SA |
450 | if(IsSCTP(source_p) && !IsConfAllowSCTP(aconf)) |
451 | { | |
452 | ServerStats.is_ref++; | |
453 | sendto_one_notice(source_p, ":*** Notice -- You are not allowed to use SCTP on this server"); | |
454 | exit_client(client_p, source_p, &me, "SCTP not allowed"); | |
455 | return (CLIENT_EXITED); | |
456 | } | |
457 | ||
212380e3 AC |
458 | if(!IsGotId(source_p)) |
459 | { | |
460 | const char *p; | |
461 | int i = 0; | |
462 | ||
463 | if(IsNeedIdentd(aconf)) | |
464 | { | |
47adde3d | 465 | ServerStats.is_ref++; |
5366977b | 466 | sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server"); |
212380e3 AC |
467 | exit_client(client_p, source_p, &me, "Install identd"); |
468 | return (CLIENT_EXITED); | |
469 | } | |
470 | ||
471 | /* dont replace username if its supposed to be spoofed --fl */ | |
27f616dd | 472 | if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')) |
212380e3 | 473 | { |
21251822 | 474 | p = myusername; |
212380e3 AC |
475 | |
476 | if(!IsNoTilde(aconf)) | |
477 | source_p->username[i++] = '~'; | |
478 | ||
479 | while (*p && i < USERLEN) | |
480 | { | |
481 | if(*p != '[') | |
482 | source_p->username[i++] = *p; | |
483 | p++; | |
484 | } | |
485 | ||
486 | source_p->username[i] = '\0'; | |
487 | } | |
488 | } | |
489 | ||
d8f0b5d7 | 490 | if(IsNeedSasl(aconf) && !*source_p->user->suser) |
212380e3 | 491 | { |
47adde3d | 492 | ServerStats.is_ref++; |
5366977b | 493 | sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server"); |
212380e3 AC |
494 | exit_client(client_p, source_p, &me, "SASL access only"); |
495 | return (CLIENT_EXITED); | |
496 | } | |
497 | ||
498 | /* password check */ | |
499 | if(!EmptyString(aconf->passwd)) | |
500 | { | |
501 | const char *encr; | |
502 | ||
503 | if(EmptyString(source_p->localClient->passwd)) | |
504 | encr = ""; | |
505 | else if(IsConfEncrypted(aconf)) | |
ba8b3ff1 | 506 | encr = rb_crypt(source_p->localClient->passwd, aconf->passwd); |
212380e3 AC |
507 | else |
508 | encr = source_p->localClient->passwd; | |
509 | ||
e69375f3 | 510 | if(encr == NULL || strcmp(encr, aconf->passwd)) |
212380e3 | 511 | { |
47adde3d | 512 | ServerStats.is_ref++; |
212380e3 AC |
513 | sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); |
514 | exit_client(client_p, source_p, &me, "Bad Password"); | |
515 | return (CLIENT_EXITED); | |
516 | } | |
517 | ||
518 | /* clear password only if used now, otherwise send it | |
519 | * to services -- jilles */ | |
520 | if(source_p->localClient->passwd) | |
521 | { | |
522 | memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); | |
637c4932 | 523 | rb_free(source_p->localClient->passwd); |
212380e3 AC |
524 | source_p->localClient->passwd = NULL; |
525 | } | |
526 | } | |
527 | ||
7a21fb5b | 528 | /* report and set flags (kline exempt etc.) as needed in source_p */ |
212380e3 AC |
529 | report_and_set_user_flags(source_p, aconf); |
530 | ||
531 | /* Limit clients */ | |
532 | /* | |
533 | * We want to be able to have servers and F-line clients | |
534 | * connect, so save room for "buffer" connections. | |
535 | * Smaller servers may want to decrease this, and it should | |
536 | * probably be just a percentage of the MAXCLIENTS... | |
537 | * -Taner | |
538 | */ | |
539 | /* Except "F:" clients */ | |
330fc5c1 | 540 | if(rb_dlink_list_length(&lclient_list) >= |
5ca543e7 | 541 | (unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf)) |
212380e3 AC |
542 | { |
543 | sendto_realops_snomask(SNO_FULL, L_ALL, | |
544 | "Too many clients, rejecting %s[%s].", source_p->name, source_p->host); | |
545 | ||
47adde3d | 546 | ServerStats.is_ref++; |
212380e3 AC |
547 | exit_client(client_p, source_p, &me, "Sorry, server is full - try later"); |
548 | return (CLIENT_EXITED); | |
549 | } | |
550 | ||
212380e3 AC |
551 | /* kline exemption extends to xline too */ |
552 | if(!IsExemptKline(source_p) && | |
35f6f850 | 553 | (xconf = find_xline(source_p->info, 1)) != NULL) |
212380e3 | 554 | { |
47adde3d | 555 | ServerStats.is_ref++; |
70ea02eb | 556 | add_reject(source_p, xconf->host, NULL); |
212380e3 AC |
557 | exit_client(client_p, source_p, &me, "Bad user info"); |
558 | return CLIENT_EXITED; | |
559 | } | |
560 | ||
d3f6b808 | 561 | /* authd rejection check */ |
7a21fb5b EM |
562 | if(authd_check(client_p, source_p)) |
563 | return CLIENT_EXITED; | |
212380e3 | 564 | |
0734f634 JT |
565 | /* valid user name check */ |
566 | ||
567 | if(!valid_username(source_p->username)) | |
568 | { | |
569 | sendto_realops_snomask(SNO_REJ, L_ALL, | |
570 | "Invalid username: %s (%s@%s)", | |
571 | source_p->name, source_p->username, source_p->host); | |
47adde3d | 572 | ServerStats.is_ref++; |
cc32202d AC |
573 | sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains " |
574 | "only alphanumeric characters."); | |
5203cba5 | 575 | sprintf(tmpstr2, "Invalid username [%s]", source_p->username); |
0734f634 JT |
576 | exit_client(client_p, source_p, &me, tmpstr2); |
577 | return (CLIENT_EXITED); | |
578 | } | |
579 | ||
580 | /* end of valid user name check */ | |
581 | ||
212380e3 | 582 | /* Store original hostname -- jilles */ |
f427c8b0 | 583 | rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1); |
212380e3 AC |
584 | |
585 | /* Spoof user@host */ | |
586 | if(*source_p->preClient->spoofuser) | |
f427c8b0 | 587 | rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1); |
212380e3 AC |
588 | if(*source_p->preClient->spoofhost) |
589 | { | |
f427c8b0 | 590 | rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1); |
212380e3 AC |
591 | if (irccmp(source_p->host, source_p->orighost)) |
592 | SetDynSpoof(source_p); | |
593 | } | |
594 | ||
e2b44358 JT |
595 | source_p->umodes |= ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes & ~orphaned_umodes; |
596 | ||
597 | call_hook(h_new_local_user, source_p); | |
598 | ||
599 | /* If they have died in send_* or were thrown out by the | |
600 | * new_local_user hook don't do anything. */ | |
601 | if(IsAnyDead(source_p)) | |
212380e3 AC |
602 | return CLIENT_EXITED; |
603 | ||
e2b44358 JT |
604 | /* To avoid inconsistencies, do not abort the registration |
605 | * starting from this point -- jilles | |
606 | */ | |
caa4d9d2 | 607 | rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); |
212380e3 AC |
608 | |
609 | sendto_realops_snomask(SNO_CCONN, L_ALL, | |
610 | "Client connecting: %s (%s@%s) [%s] {%s} [%s]", | |
611 | source_p->name, source_p->username, source_p->orighost, | |
612 | show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", | |
613 | get_client_class(source_p), source_p->info); | |
614 | ||
615 | sendto_realops_snomask(SNO_CCONNEXT, L_ALL, | |
616 | "CLICONN %s %s %s %s %s %s 0 %s", | |
617 | source_p->name, source_p->username, source_p->orighost, | |
618 | show_ip(NULL, source_p) ? ipaddr : "255.255.255.255", | |
619 | get_client_class(source_p), | |
620 | /* mirc can sometimes send ips here */ | |
621 | show_ip(NULL, source_p) ? source_p->localClient->fullcaps : "<hidden> <hidden>", | |
622 | source_p->info); | |
623 | ||
212380e3 AC |
624 | add_to_hostname_hash(source_p->orighost, source_p); |
625 | ||
626 | /* Allocate a UID if it was not previously allocated. | |
627 | * If this already occured, it was probably during SASL auth... | |
628 | */ | |
629 | if(!*source_p->id) | |
630 | { | |
4d5a902f | 631 | rb_strlcpy(source_p->id, generate_uid(), sizeof(source_p->id)); |
212380e3 AC |
632 | add_to_id_hash(source_p->id, source_p); |
633 | } | |
634 | ||
3318e109 AC |
635 | if (IsSSL(source_p)) |
636 | source_p->umodes |= UMODE_SSLCLIENT; | |
637 | ||
212380e3 AC |
638 | if (source_p->umodes & UMODE_INVISIBLE) |
639 | Count.invisi++; | |
640 | ||
641 | s_assert(!IsClient(source_p)); | |
330fc5c1 | 642 | rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list); |
212380e3 AC |
643 | SetClient(source_p); |
644 | ||
0a61720a | 645 | source_p->servptr = &me; |
330fc5c1 | 646 | rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); |
0a61720a | 647 | |
212380e3 AC |
648 | /* Increment our total user count here */ |
649 | if(++Count.total > Count.max_tot) | |
650 | Count.max_tot = Count.total; | |
0a61720a | 651 | |
212380e3 AC |
652 | Count.totalrestartcount++; |
653 | ||
654 | s_assert(source_p->localClient != NULL); | |
655 | ||
330fc5c1 | 656 | if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc) |
212380e3 | 657 | { |
330fc5c1 | 658 | Count.max_loc = rb_dlink_list_length(&lclient_list); |
212380e3 AC |
659 | if(!(Count.max_loc % 10)) |
660 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
661 | "New Max Local Clients: %d", Count.max_loc); | |
662 | } | |
663 | ||
664 | /* they get a reduced limit */ | |
665 | if(find_tgchange(source_p->sockhost)) | |
179becdf JT |
666 | source_p->localClient->targets_free = TGCHANGE_INITIAL_LOW; |
667 | else | |
668 | source_p->localClient->targets_free = TGCHANGE_INITIAL; | |
212380e3 | 669 | |
212380e3 AC |
670 | monitor_signon(source_p); |
671 | user_welcome(source_p); | |
672 | ||
673 | free_pre_client(source_p); | |
674 | ||
d8f0b5d7 | 675 | introduce_client(client_p, source_p, source_p->user, source_p->name, 1); |
6287d57f | 676 | return 0; |
212380e3 AC |
677 | } |
678 | ||
679 | /* | |
680 | * introduce_clients | |
681 | * | |
682 | * inputs - | |
683 | * output - | |
684 | * side effects - This common function introduces a client to the rest | |
685 | * of the net, either from a local client connect or | |
686 | * from a remote connect. | |
687 | */ | |
6287d57f | 688 | void |
212380e3 AC |
689 | introduce_client(struct Client *client_p, struct Client *source_p, struct User *user, const char *nick, int use_euid) |
690 | { | |
9744d53e | 691 | char ubuf[BUFSIZE]; |
212380e3 AC |
692 | struct Client *identifyservice_p; |
693 | char *p; | |
694 | hook_data_umode_changed hdata; | |
695 | hook_data_client hdata2; | |
696 | ||
697 | if(MyClient(source_p)) | |
29c92cf9 | 698 | send_umode(source_p, source_p, 0, ubuf); |
212380e3 | 699 | else |
29c92cf9 | 700 | send_umode(NULL, source_p, 0, ubuf); |
212380e3 AC |
701 | |
702 | if(!*ubuf) | |
703 | { | |
704 | ubuf[0] = '+'; | |
705 | ubuf[1] = '\0'; | |
706 | } | |
707 | ||
ca273a1c AC |
708 | s_assert(has_id(source_p)); |
709 | ||
ca273a1c AC |
710 | if (use_euid) |
711 | sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS, | |
712 | ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s", | |
713 | source_p->servptr->id, nick, | |
714 | source_p->hopcount + 1, | |
715 | (long) source_p->tsinfo, ubuf, | |
716 | source_p->username, source_p->host, | |
e9f86e32 | 717 | IsIPSpoof(source_p) ? "0" : source_p->sockhost, |
ca273a1c AC |
718 | source_p->id, |
719 | IsDynSpoof(source_p) ? source_p->orighost : "*", | |
720 | EmptyString(source_p->user->suser) ? "*" : source_p->user->suser, | |
721 | source_p->info); | |
722 | ||
723 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, | |
724 | ":%s UID %s %d %ld %s %s %s %s %s :%s", | |
725 | source_p->servptr->id, nick, | |
726 | source_p->hopcount + 1, | |
727 | (long) source_p->tsinfo, ubuf, | |
728 | source_p->username, source_p->host, | |
e9f86e32 | 729 | IsIPSpoof(source_p) ? "0" : source_p->sockhost, |
ca273a1c | 730 | source_p->id, source_p->info); |
212380e3 | 731 | |
8eda114a JT |
732 | if(!EmptyString(source_p->certfp)) |
733 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, | |
734 | ":%s ENCAP * CERTFP :%s", | |
735 | use_id(source_p), source_p->certfp); | |
736 | ||
212380e3 AC |
737 | if (IsDynSpoof(source_p)) |
738 | { | |
739 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s", | |
740 | use_id(source_p), source_p->orighost); | |
212380e3 | 741 | } |
ca273a1c | 742 | |
212380e3 AC |
743 | if (!EmptyString(source_p->user->suser)) |
744 | { | |
745 | sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s", | |
746 | use_id(source_p), source_p->user->suser); | |
212380e3 AC |
747 | } |
748 | ||
749 | if(MyConnect(source_p) && source_p->localClient->passwd) | |
750 | { | |
0a01ecfa JT |
751 | if (!EmptyString(ConfigFileEntry.identifyservice) && |
752 | !EmptyString(ConfigFileEntry.identifycommand)) | |
212380e3 AC |
753 | { |
754 | /* use user@server */ | |
755 | p = strchr(ConfigFileEntry.identifyservice, '@'); | |
756 | if (p != NULL) | |
757 | identifyservice_p = find_named_client(p + 1); | |
758 | else | |
759 | identifyservice_p = NULL; | |
760 | if (identifyservice_p != NULL) | |
12f4addb SB |
761 | { |
762 | if (!EmptyString(source_p->localClient->auth_user)) | |
763 | sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s", | |
764 | get_id(source_p, identifyservice_p), | |
765 | ConfigFileEntry.identifyservice, | |
766 | ConfigFileEntry.identifycommand, | |
767 | source_p->localClient->auth_user, | |
768 | source_p->localClient->passwd); | |
769 | else | |
770 | sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s", | |
771 | get_id(source_p, identifyservice_p), | |
772 | ConfigFileEntry.identifyservice, | |
773 | ConfigFileEntry.identifycommand, | |
774 | source_p->localClient->passwd); | |
775 | } | |
212380e3 AC |
776 | } |
777 | memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); | |
637c4932 | 778 | rb_free(source_p->localClient->passwd); |
212380e3 AC |
779 | source_p->localClient->passwd = NULL; |
780 | } | |
781 | ||
782 | /* let modules providing usermodes know that we've got a new user, | |
783 | * why is this here? -- well, some modules need to be able to send out new | |
784 | * information about a client, so this was the best place to do it | |
785 | * --nenolod | |
786 | */ | |
787 | hdata.client = source_p; | |
788 | hdata.oldumodes = 0; | |
789 | hdata.oldsnomask = 0; | |
790 | call_hook(h_umode_changed, &hdata); | |
791 | ||
792 | /* On the other hand, some modules need to know when a client is | |
793 | * being introduced, period. | |
794 | * --gxti | |
795 | */ | |
796 | hdata2.client = client_p; | |
797 | hdata2.target = source_p; | |
798 | call_hook(h_introduce_client, &hdata2); | |
212380e3 AC |
799 | } |
800 | ||
55abcbb2 | 801 | /* |
212380e3 AC |
802 | * valid_hostname - check hostname for validity |
803 | * | |
804 | * Inputs - pointer to user | |
6287d57f | 805 | * Output - true if valid, false if not |
212380e3 AC |
806 | * Side effects - NONE |
807 | * | |
808 | * NOTE: this doesn't allow a hostname to begin with a dot and | |
809 | * will not allow more dots than chars. | |
810 | */ | |
6287d57f | 811 | bool |
212380e3 AC |
812 | valid_hostname(const char *hostname) |
813 | { | |
9a180ae3 | 814 | const char *p = hostname, *last_slash = 0; |
212380e3 AC |
815 | int found_sep = 0; |
816 | ||
817 | s_assert(NULL != p); | |
818 | ||
819 | if(hostname == NULL) | |
6287d57f | 820 | return false; |
212380e3 | 821 | |
3c80b425 | 822 | if(!strcmp(hostname, "localhost")) |
6287d57f | 823 | return true; |
3c80b425 | 824 | |
9a180ae3 | 825 | if('.' == *p || ':' == *p || '/' == *p) |
6287d57f | 826 | return false; |
212380e3 AC |
827 | |
828 | while (*p) | |
829 | { | |
830 | if(!IsHostChar(*p)) | |
6287d57f | 831 | return false; |
212380e3 AC |
832 | if(*p == '.' || *p == ':') |
833 | found_sep++; | |
9a180ae3 SB |
834 | else if(*p == '/') |
835 | { | |
836 | found_sep++; | |
837 | last_slash = p; | |
838 | } | |
212380e3 AC |
839 | p++; |
840 | } | |
841 | ||
842 | if(found_sep == 0) | |
6287d57f | 843 | return false; |
9a180ae3 SB |
844 | |
845 | if(last_slash && IsDigit(last_slash[1])) | |
6287d57f | 846 | return false; |
212380e3 | 847 | |
6287d57f | 848 | return true; |
212380e3 AC |
849 | } |
850 | ||
55abcbb2 | 851 | /* |
212380e3 AC |
852 | * valid_username - check username for validity |
853 | * | |
854 | * Inputs - pointer to user | |
6287d57f | 855 | * Output - true if valid, false if not |
212380e3 | 856 | * Side effects - NONE |
55abcbb2 | 857 | * |
212380e3 AC |
858 | * Absolutely always reject any '*' '!' '?' '@' in an user name |
859 | * reject any odd control characters names. | |
860 | * Allow '.' in username to allow for "first.last" | |
861 | * style of username | |
862 | */ | |
6287d57f | 863 | bool |
212380e3 AC |
864 | valid_username(const char *username) |
865 | { | |
866 | int dots = 0; | |
867 | const char *p = username; | |
868 | ||
869 | s_assert(NULL != p); | |
870 | ||
871 | if(username == NULL) | |
6287d57f | 872 | return false; |
212380e3 AC |
873 | |
874 | if('~' == *p) | |
875 | ++p; | |
876 | ||
877 | /* reject usernames that don't start with an alphanum | |
878 | * i.e. reject jokers who have '-@somehost' or '.@somehost' | |
879 | * or "-hi-@somehost", "h-----@somehost" would still be accepted. | |
880 | */ | |
881 | if(!IsAlNum(*p)) | |
6287d57f | 882 | return false; |
212380e3 AC |
883 | |
884 | while (*++p) | |
885 | { | |
886 | if((*p == '.') && ConfigFileEntry.dots_in_ident) | |
887 | { | |
888 | dots++; | |
889 | if(dots > ConfigFileEntry.dots_in_ident) | |
6287d57f | 890 | return false; |
212380e3 | 891 | if(!IsUserChar(p[1])) |
6287d57f | 892 | return false; |
212380e3 AC |
893 | } |
894 | else if(!IsUserChar(*p)) | |
6287d57f | 895 | return false; |
212380e3 | 896 | } |
6287d57f | 897 | return true; |
212380e3 AC |
898 | } |
899 | ||
900 | /* report_and_set_user_flags | |
901 | * | |
902 | * Inputs - pointer to source_p | |
903 | * - pointer to aconf for this user | |
904 | * Output - NONE | |
905 | * Side effects - | |
906 | * Report to user any special flags they are getting, and set them. | |
907 | */ | |
908 | ||
909 | static void | |
910 | report_and_set_user_flags(struct Client *source_p, struct ConfItem *aconf) | |
911 | { | |
912 | /* If this user is being spoofed, tell them so */ | |
913 | if(IsConfDoSpoofIp(aconf)) | |
914 | { | |
e07de82c | 915 | sendto_one_notice(source_p, ":*** Spoofing your IP"); |
212380e3 AC |
916 | } |
917 | ||
918 | /* If this user is in the exception class, Set it "E lined" */ | |
919 | if(IsConfExemptKline(aconf)) | |
920 | { | |
921 | SetExemptKline(source_p); | |
5c16ab05 | 922 | sendto_one_notice(source_p, ":*** You are exempt from K/X lines"); |
212380e3 AC |
923 | } |
924 | ||
212380e3 AC |
925 | if(IsConfExemptDNSBL(aconf)) |
926 | /* kline exempt implies this, don't send both */ | |
927 | if(!IsConfExemptKline(aconf)) | |
e07de82c | 928 | sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists"); |
212380e3 AC |
929 | |
930 | /* If this user is exempt from user limits set it F lined" */ | |
931 | if(IsConfExemptLimits(aconf)) | |
932 | { | |
e07de82c | 933 | sendto_one_notice(source_p, ":*** You are exempt from user limits"); |
212380e3 AC |
934 | } |
935 | ||
212380e3 AC |
936 | if(IsConfExemptFlood(aconf)) |
937 | { | |
938 | SetExemptFlood(source_p); | |
e07de82c | 939 | sendto_one_notice(source_p, ":*** You are exempt from flood limits"); |
212380e3 AC |
940 | } |
941 | ||
942 | if(IsConfExemptSpambot(aconf)) | |
943 | { | |
944 | SetExemptSpambot(source_p); | |
e07de82c | 945 | sendto_one_notice(source_p, ":*** You are exempt from spambot checks"); |
212380e3 AC |
946 | } |
947 | ||
948 | if(IsConfExemptJupe(aconf)) | |
949 | { | |
950 | SetExemptJupe(source_p); | |
e07de82c | 951 | sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings"); |
212380e3 AC |
952 | } |
953 | ||
954 | if(IsConfExemptResv(aconf)) | |
955 | { | |
956 | SetExemptResv(source_p); | |
e07de82c | 957 | sendto_one_notice(source_p, ":*** You are exempt from resvs"); |
212380e3 AC |
958 | } |
959 | ||
960 | if(IsConfExemptShide(aconf)) | |
961 | { | |
962 | SetExemptShide(source_p); | |
e07de82c | 963 | sendto_one_notice(source_p, ":*** You are exempt from serverhiding"); |
212380e3 | 964 | } |
a4721f5e AC |
965 | |
966 | if(IsConfExtendChans(aconf)) | |
967 | { | |
968 | SetExtendChans(source_p); | |
969 | sendto_one_notice(source_p, ":*** You are exempt from normal channel limits"); | |
970 | } | |
212380e3 AC |
971 | } |
972 | ||
681ddf64 JT |
973 | static void |
974 | show_other_user_mode(struct Client *source_p, struct Client *target_p) | |
975 | { | |
976 | int i; | |
977 | char buf[BUFSIZE]; | |
978 | char *m; | |
979 | ||
980 | m = buf; | |
981 | *m++ = '+'; | |
982 | ||
983 | for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ | |
984 | if (target_p->umodes & user_modes[i]) | |
985 | *m++ = (char) i; | |
986 | *m = '\0'; | |
987 | ||
988 | if (MyConnect(target_p) && target_p->snomask != 0) | |
989 | sendto_one_notice(source_p, ":Modes for %s are %s %s", | |
990 | target_p->name, buf, | |
991 | construct_snobuf(target_p->snomask)); | |
992 | else | |
993 | sendto_one_notice(source_p, ":Modes for %s are %s", | |
994 | target_p->name, buf); | |
995 | } | |
996 | ||
212380e3 AC |
997 | /* |
998 | * user_mode - set get current users mode | |
999 | * | |
1000 | * m_umode() added 15/10/91 By Darren Reed. | |
212380e3 AC |
1001 | * parv[1] - username to change mode for |
1002 | * parv[2] - modes to change | |
1003 | */ | |
1004 | int | |
1005 | user_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
1006 | { | |
1007 | int flag; | |
1008 | int i; | |
1009 | char *m; | |
1010 | const char *pm; | |
1011 | struct Client *target_p; | |
1012 | int what, setflags; | |
6287d57f EM |
1013 | bool badflag = false; /* Only send one bad flag notice */ |
1014 | bool showsnomask = false; | |
212380e3 AC |
1015 | unsigned int setsnomask; |
1016 | char buf[BUFSIZE]; | |
1017 | hook_data_umode_changed hdata; | |
1018 | ||
1019 | what = MODE_ADD; | |
1020 | ||
1021 | if(parc < 2) | |
1022 | { | |
1023 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); | |
1024 | return 0; | |
1025 | } | |
1026 | ||
1027 | if((target_p = MyClient(source_p) ? find_named_person(parv[1]) : find_person(parv[1])) == NULL) | |
1028 | { | |
1029 | if(MyConnect(source_p)) | |
1030 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
1031 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
1032 | return 0; | |
1033 | } | |
1034 | ||
1035 | /* Dont know why these were commented out.. | |
1036 | * put them back using new sendto() funcs | |
1037 | */ | |
1038 | ||
1039 | if(IsServer(source_p)) | |
1040 | { | |
1041 | sendto_realops_snomask(SNO_GENERAL, L_ADMIN, | |
1042 | "*** Mode for User %s from %s", parv[1], source_p->name); | |
1043 | return 0; | |
1044 | } | |
1045 | ||
c98c2c89 | 1046 | if(source_p != target_p) |
212380e3 | 1047 | { |
681ddf64 JT |
1048 | if (MyOper(source_p) && parc < 3) |
1049 | show_other_user_mode(source_p, target_p); | |
1050 | else | |
1051 | sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name); | |
212380e3 AC |
1052 | return 0; |
1053 | } | |
1054 | ||
1055 | if(parc < 3) | |
1056 | { | |
1057 | m = buf; | |
1058 | *m++ = '+'; | |
1059 | ||
1060 | for (i = 0; i < 128; i++) /* >= 127 is extended ascii */ | |
1061 | if (source_p->umodes & user_modes[i]) | |
1062 | *m++ = (char) i; | |
1063 | ||
1064 | *m = '\0'; | |
e8a2d50d | 1065 | sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf); |
88520303 | 1066 | |
212380e3 | 1067 | if (source_p->snomask != 0) |
88520303 | 1068 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 | 1069 | construct_snobuf(source_p->snomask)); |
88520303 | 1070 | |
212380e3 AC |
1071 | return 0; |
1072 | } | |
1073 | ||
1074 | /* find flags already set for user */ | |
1075 | setflags = source_p->umodes; | |
1076 | setsnomask = source_p->snomask; | |
1077 | ||
1078 | /* | |
1079 | * parse mode change string(s) | |
1080 | */ | |
1081 | for (pm = parv[2]; *pm; pm++) | |
1082 | switch (*pm) | |
1083 | { | |
1084 | case '+': | |
1085 | what = MODE_ADD; | |
1086 | break; | |
1087 | case '-': | |
1088 | what = MODE_DEL; | |
1089 | break; | |
1090 | ||
1091 | case 'o': | |
1092 | if(what == MODE_ADD) | |
1093 | { | |
1094 | if(IsServer(client_p) && !IsOper(source_p)) | |
1095 | { | |
1096 | ++Count.oper; | |
1097 | SetOper(source_p); | |
330fc5c1 | 1098 | rb_dlinkAddAlloc(source_p, &oper_list); |
212380e3 AC |
1099 | } |
1100 | } | |
1101 | else | |
1102 | { | |
1103 | /* Only decrement the oper counts if an oper to begin with | |
55abcbb2 | 1104 | * found by Pat Szuta, Perly , perly@xnet.com |
212380e3 AC |
1105 | */ |
1106 | ||
1107 | if(!IsOper(source_p)) | |
1108 | break; | |
1109 | ||
1110 | ClearOper(source_p); | |
1111 | ||
1112 | Count.oper--; | |
1113 | ||
1114 | if(MyConnect(source_p)) | |
1115 | { | |
1116 | source_p->umodes &= ~ConfigFileEntry.oper_only_umodes; | |
1117 | if (!(source_p->umodes & UMODE_SERVNOTICE) && source_p->snomask != 0) | |
1118 | { | |
1119 | source_p->snomask = 0; | |
6287d57f | 1120 | showsnomask = true; |
212380e3 | 1121 | } |
66f7fe67 | 1122 | source_p->flags &= ~OPER_FLAGS; |
212380e3 | 1123 | |
330fc5c1 | 1124 | rb_dlinkFindDestroy(source_p, &local_oper_list); |
ed3ca2ff EK |
1125 | } |
1126 | ||
1127 | if(source_p->user->opername != NULL) | |
1128 | { | |
1129 | rb_free(source_p->user->opername); | |
1130 | source_p->user->opername = NULL; | |
1131 | } | |
1132 | ||
1133 | if(source_p->user->privset != NULL) | |
1134 | { | |
1135 | privilegeset_unref(source_p->user->privset); | |
1136 | source_p->user->privset = NULL; | |
212380e3 AC |
1137 | } |
1138 | ||
330fc5c1 | 1139 | rb_dlinkFindDestroy(source_p, &oper_list); |
212380e3 AC |
1140 | } |
1141 | break; | |
1142 | ||
1143 | /* we may not get these, | |
1144 | * but they shouldnt be in default | |
1145 | */ | |
1146 | ||
1147 | /* can only be set on burst */ | |
1148 | case 'S': | |
3318e109 | 1149 | case 'Z': |
212380e3 AC |
1150 | case ' ': |
1151 | case '\n': | |
1152 | case '\r': | |
1153 | case '\t': | |
1154 | break; | |
1155 | ||
1156 | case 's': | |
1157 | if (MyConnect(source_p)) | |
1158 | { | |
1159 | if(!IsOper(source_p) | |
1160 | && (ConfigFileEntry.oper_only_umodes & UMODE_SERVNOTICE)) | |
1161 | { | |
1162 | if (what == MODE_ADD || source_p->umodes & UMODE_SERVNOTICE) | |
6287d57f | 1163 | badflag = true; |
212380e3 AC |
1164 | continue; |
1165 | } | |
6287d57f | 1166 | showsnomask = true; |
212380e3 AC |
1167 | if(what == MODE_ADD) |
1168 | { | |
1169 | if (parc > 3) | |
1170 | source_p->snomask = parse_snobuf_to_mask(source_p->snomask, parv[3]); | |
1171 | else | |
1172 | source_p->snomask |= SNO_GENERAL; | |
1173 | } | |
1174 | else | |
1175 | source_p->snomask = 0; | |
1176 | if (source_p->snomask != 0) | |
1177 | source_p->umodes |= UMODE_SERVNOTICE; | |
1178 | else | |
1179 | source_p->umodes &= ~UMODE_SERVNOTICE; | |
1180 | break; | |
1181 | } | |
1182 | /* FALLTHROUGH */ | |
1183 | default: | |
2da6f6eb JT |
1184 | if (MyConnect(source_p) && *pm == 'Q' && !ConfigChannel.use_forward) |
1185 | { | |
6287d57f | 1186 | badflag = true; |
2da6f6eb JT |
1187 | break; |
1188 | } | |
1189 | ||
212380e3 AC |
1190 | if((flag = user_modes[(unsigned char) *pm])) |
1191 | { | |
1192 | if(MyConnect(source_p) | |
a8086a7c JT |
1193 | && ((!IsOper(source_p) |
1194 | && (ConfigFileEntry.oper_only_umodes & flag)) | |
1195 | || (orphaned_umodes & flag))) | |
212380e3 AC |
1196 | { |
1197 | if (what == MODE_ADD || source_p->umodes & flag) | |
6287d57f | 1198 | badflag = true; |
212380e3 AC |
1199 | } |
1200 | else | |
1201 | { | |
1202 | if(what == MODE_ADD) | |
1203 | source_p->umodes |= flag; | |
1204 | else | |
1205 | source_p->umodes &= ~flag; | |
1206 | } | |
1207 | } | |
1208 | else | |
1209 | { | |
1210 | if(MyConnect(source_p)) | |
6287d57f | 1211 | badflag = true; |
212380e3 AC |
1212 | } |
1213 | break; | |
1214 | } | |
1215 | ||
1216 | if(badflag) | |
1217 | sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name); | |
1218 | ||
1219 | if(MyClient(source_p) && (source_p->snomask & SNO_NCHANGE) && !IsOperN(source_p)) | |
1220 | { | |
b4838ccd | 1221 | sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n"); |
212380e3 AC |
1222 | source_p->snomask &= ~SNO_NCHANGE; /* only tcm's really need this */ |
1223 | } | |
1224 | ||
1225 | if(MyClient(source_p) && (source_p->umodes & UMODE_OPERWALL) && !IsOperOperwall(source_p)) | |
1226 | { | |
5366977b | 1227 | sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z"); |
212380e3 AC |
1228 | source_p->umodes &= ~UMODE_OPERWALL; |
1229 | } | |
1230 | ||
1231 | if(MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) && | |
1232 | (!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))) | |
1233 | { | |
b4838ccd | 1234 | sendto_one_notice(source_p, ":*** You need oper and admin flag for +a"); |
212380e3 AC |
1235 | source_p->umodes &= ~UMODE_ADMIN; |
1236 | } | |
1237 | ||
1238 | /* let modules providing usermodes know that we've changed our usermode --nenolod */ | |
1239 | hdata.client = source_p; | |
1240 | hdata.oldumodes = setflags; | |
1241 | hdata.oldsnomask = setsnomask; | |
1242 | call_hook(h_umode_changed, &hdata); | |
1243 | ||
1244 | if(!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p)) | |
1245 | ++Count.invisi; | |
1246 | if((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p)) | |
1247 | --Count.invisi; | |
1248 | /* | |
1249 | * compare new flags with old flags and send string which | |
1250 | * will cause servers to update correctly. | |
1251 | */ | |
1252 | send_umode_out(client_p, source_p, setflags); | |
1253 | if (showsnomask && MyConnect(source_p)) | |
88520303 | 1254 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 AC |
1255 | construct_snobuf(source_p->snomask)); |
1256 | ||
1257 | return (0); | |
1258 | } | |
1259 | ||
1260 | /* | |
1261 | * send the MODE string for user (user) to connection client_p | |
1262 | * -avalon | |
1263 | */ | |
1264 | void | |
29c92cf9 | 1265 | send_umode(struct Client *client_p, struct Client *source_p, int old, char *umode_buf) |
212380e3 AC |
1266 | { |
1267 | int i; | |
1268 | int flag; | |
1269 | char *m; | |
1270 | int what = 0; | |
1271 | ||
1272 | /* | |
1273 | * build a string in umode_buf to represent the change in the user's | |
1274 | * mode between the new (source_p->flag) and 'old'. | |
1275 | */ | |
1276 | m = umode_buf; | |
1277 | *m = '\0'; | |
1278 | ||
1279 | for (i = 0; i < 128; i++) | |
1280 | { | |
1281 | flag = user_modes[i]; | |
1282 | ||
1283 | if((flag & old) && !(source_p->umodes & flag)) | |
1284 | { | |
1285 | if(what == MODE_DEL) | |
1286 | *m++ = (char) i; | |
1287 | else | |
1288 | { | |
1289 | what = MODE_DEL; | |
1290 | *m++ = '-'; | |
1291 | *m++ = (char) i; | |
1292 | } | |
1293 | } | |
1294 | else if(!(flag & old) && (source_p->umodes & flag)) | |
1295 | { | |
1296 | if(what == MODE_ADD) | |
1297 | *m++ = (char) i; | |
1298 | else | |
1299 | { | |
1300 | what = MODE_ADD; | |
1301 | *m++ = '+'; | |
1302 | *m++ = (char) i; | |
1303 | } | |
1304 | } | |
1305 | } | |
1306 | *m = '\0'; | |
1307 | ||
1308 | if(*umode_buf && client_p) | |
1309 | sendto_one(client_p, ":%s MODE %s :%s", source_p->name, source_p->name, umode_buf); | |
1310 | } | |
1311 | ||
1312 | /* | |
1313 | * send_umode_out | |
1314 | * | |
1315 | * inputs - | |
1316 | * output - NONE | |
55abcbb2 | 1317 | * side effects - |
212380e3 AC |
1318 | */ |
1319 | void | |
1320 | send_umode_out(struct Client *client_p, struct Client *source_p, int old) | |
1321 | { | |
1322 | struct Client *target_p; | |
1323 | char buf[BUFSIZE]; | |
330fc5c1 | 1324 | rb_dlink_node *ptr; |
212380e3 | 1325 | |
29c92cf9 | 1326 | send_umode(NULL, source_p, old, buf); |
212380e3 | 1327 | |
5cefa1d6 | 1328 | RB_DLINK_FOREACH(ptr, serv_list.head) |
212380e3 AC |
1329 | { |
1330 | target_p = ptr->data; | |
1331 | ||
1332 | if((target_p != client_p) && (target_p != source_p) && (*buf)) | |
1333 | { | |
1334 | sendto_one(target_p, ":%s MODE %s :%s", | |
55abcbb2 | 1335 | get_id(source_p, target_p), |
212380e3 AC |
1336 | get_id(source_p, target_p), buf); |
1337 | } | |
1338 | } | |
1339 | ||
1340 | if(client_p && MyClient(client_p)) | |
29c92cf9 | 1341 | send_umode(client_p, source_p, old, buf); |
212380e3 AC |
1342 | } |
1343 | ||
55abcbb2 | 1344 | /* |
212380e3 AC |
1345 | * user_welcome |
1346 | * | |
1347 | * inputs - client pointer to client to welcome | |
1348 | * output - NONE | |
1349 | * side effects - | |
1350 | */ | |
1351 | void | |
1352 | user_welcome(struct Client *source_p) | |
1353 | { | |
88520303 AC |
1354 | sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name); |
1355 | sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST), | |
212380e3 | 1356 | get_listener_name(source_p->localClient->listener), ircd_version); |
88520303 | 1357 | sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), creation); |
c18cb68b | 1358 | sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, ircd_version, umodebuf, cflagsmyinfo); |
212380e3 AC |
1359 | |
1360 | show_isupport(source_p); | |
1361 | ||
1362 | show_lusers(source_p); | |
1363 | ||
1364 | if(ConfigFileEntry.short_motd) | |
1365 | { | |
5366977b AC |
1366 | sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", user_motd_changed); |
1367 | sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it"); | |
212380e3 | 1368 | |
55abcbb2 | 1369 | sendto_one(source_p, form_str(RPL_MOTDSTART), |
212380e3 AC |
1370 | me.name, source_p->name, me.name); |
1371 | ||
1372 | sendto_one(source_p, form_str(RPL_MOTD), | |
1373 | me.name, source_p->name, "*** This is the short motd ***"); | |
1374 | ||
1375 | sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name); | |
1376 | } | |
1377 | else | |
1378 | send_user_motd(source_p); | |
1379 | } | |
1380 | ||
1381 | /* oper_up() | |
1382 | * | |
1383 | * inputs - pointer to given client to oper | |
1384 | * - pointer to ConfItem to use | |
1385 | * output - none | |
1386 | * side effects - opers up source_p using aconf for reference | |
1387 | */ | |
6287d57f | 1388 | void |
212380e3 AC |
1389 | oper_up(struct Client *source_p, struct oper_conf *oper_p) |
1390 | { | |
1391 | unsigned int old = source_p->umodes, oldsnomask = source_p->snomask; | |
1392 | hook_data_umode_changed hdata; | |
1393 | ||
1394 | SetOper(source_p); | |
1395 | ||
1396 | if(oper_p->umodes) | |
1397 | source_p->umodes |= oper_p->umodes; | |
1398 | else if(ConfigFileEntry.oper_umodes) | |
1399 | source_p->umodes |= ConfigFileEntry.oper_umodes; | |
1400 | else | |
1401 | source_p->umodes |= DEFAULT_OPER_UMODES; | |
1402 | ||
1403 | if (oper_p->snomask) | |
1404 | { | |
1405 | source_p->snomask |= oper_p->snomask; | |
1406 | source_p->umodes |= UMODE_SERVNOTICE; | |
1407 | } | |
1408 | else if (source_p->umodes & UMODE_SERVNOTICE) | |
1409 | { | |
1410 | /* Only apply these if +s is already set -- jilles */ | |
1411 | if (ConfigFileEntry.oper_snomask) | |
1412 | source_p->snomask |= ConfigFileEntry.oper_snomask; | |
1413 | else | |
1414 | source_p->snomask |= DEFAULT_OPER_SNOMASK; | |
1415 | } | |
1416 | ||
1417 | Count.oper++; | |
1418 | ||
a4721f5e | 1419 | SetExtendChans(source_p); |
212380e3 AC |
1420 | SetExemptKline(source_p); |
1421 | ||
66f7fe67 | 1422 | source_p->flags |= oper_p->flags; |
ed3ca2ff EK |
1423 | source_p->user->opername = rb_strdup(oper_p->name); |
1424 | source_p->user->privset = privilegeset_ref(oper_p->privset); | |
212380e3 | 1425 | |
330fc5c1 AC |
1426 | rb_dlinkAddAlloc(source_p, &local_oper_list); |
1427 | rb_dlinkAddAlloc(source_p, &oper_list); | |
212380e3 AC |
1428 | |
1429 | if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p)) | |
1430 | source_p->umodes |= UMODE_ADMIN; | |
1431 | if(!IsOperN(source_p)) | |
1432 | source_p->snomask &= ~SNO_NCHANGE; | |
1433 | if(!IsOperOperwall(source_p)) | |
1434 | source_p->umodes &= ~UMODE_OPERWALL; | |
1435 | hdata.client = source_p; | |
1436 | hdata.oldumodes = old; | |
1437 | hdata.oldsnomask = oldsnomask; | |
1438 | call_hook(h_umode_changed, &hdata); | |
1439 | ||
1440 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
5cca545c | 1441 | "%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name, |
212380e3 | 1442 | source_p->username, source_p->host); |
ed3ca2ff EK |
1443 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s OPER %s %s", |
1444 | use_id(source_p), oper_p->name, oper_p->privset->name); | |
652b8478 JT |
1445 | if(!(old & UMODE_INVISIBLE) && IsInvisible(source_p)) |
1446 | ++Count.invisi; | |
1447 | if((old & UMODE_INVISIBLE) && !IsInvisible(source_p)) | |
1448 | --Count.invisi; | |
212380e3 | 1449 | send_umode_out(source_p, source_p, old); |
88520303 | 1450 | sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), |
212380e3 AC |
1451 | construct_snobuf(source_p->snomask)); |
1452 | sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); | |
22c3b270 AC |
1453 | sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name); |
1454 | sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs); | |
212380e3 | 1455 | send_oper_motd(source_p); |
212380e3 AC |
1456 | } |
1457 | ||
01cebbd8 JT |
1458 | /* |
1459 | * find_umode_slot | |
1460 | * | |
1461 | * inputs - NONE | |
1462 | * outputs - an available umode bitmask or | |
1463 | * 0 if no umodes are available | |
1464 | * side effects - NONE | |
1465 | */ | |
1466 | unsigned int | |
1467 | find_umode_slot(void) | |
1468 | { | |
1469 | unsigned int all_umodes = 0, my_umode = 0, i; | |
1470 | ||
1471 | for (i = 0; i < 128; i++) | |
1472 | all_umodes |= user_modes[i]; | |
1473 | ||
1474 | for (my_umode = 1; my_umode && (all_umodes & my_umode); | |
1475 | my_umode <<= 1); | |
1476 | ||
1477 | return my_umode; | |
1478 | } | |
1479 | ||
212380e3 AC |
1480 | void |
1481 | construct_umodebuf(void) | |
1482 | { | |
1483 | int i; | |
1484 | char *ptr = umodebuf; | |
a8086a7c | 1485 | static int prev_user_modes[128]; |
212380e3 AC |
1486 | |
1487 | *ptr = '\0'; | |
1488 | ||
1489 | for (i = 0; i < 128; i++) | |
a8086a7c JT |
1490 | { |
1491 | if (prev_user_modes[i] != 0 && prev_user_modes[i] != user_modes[i]) | |
1492 | { | |
1493 | if (user_modes[i] == 0) | |
1494 | { | |
1495 | orphaned_umodes |= prev_user_modes[i]; | |
5a15b976 | 1496 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Umode +%c is now orphaned", i); |
a8086a7c JT |
1497 | } |
1498 | else | |
5a15b976 | 1499 | { |
a8086a7c | 1500 | orphaned_umodes &= ~prev_user_modes[i]; |
5a15b976 SA |
1501 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned umode +%c is picked up by module", i); |
1502 | } | |
1503 | user_modes[i] = prev_user_modes[i]; | |
a8086a7c JT |
1504 | } |
1505 | else | |
1506 | prev_user_modes[i] = user_modes[i]; | |
212380e3 AC |
1507 | if (user_modes[i]) |
1508 | *ptr++ = (char) i; | |
a8086a7c | 1509 | } |
212380e3 AC |
1510 | |
1511 | *ptr++ = '\0'; | |
1512 | } | |
1513 | ||
1514 | void | |
1515 | change_nick_user_host(struct Client *target_p, const char *nick, const char *user, | |
82622732 | 1516 | const char *host, int newts, const char *format, ...) |
212380e3 | 1517 | { |
330fc5c1 | 1518 | rb_dlink_node *ptr; |
212380e3 AC |
1519 | struct Channel *chptr; |
1520 | struct membership *mscptr; | |
1521 | int changed = irccmp(target_p->name, nick); | |
1522 | int changed_case = strcmp(target_p->name, nick); | |
1523 | int do_qjm = irccmp(target_p->username, user) || irccmp(target_p->host, host); | |
1524 | char mode[10], modeval[NICKLEN * 2 + 2], reason[256], *mptr; | |
1525 | va_list ap; | |
1526 | ||
1527 | modeval[0] = '\0'; | |
55abcbb2 | 1528 | |
212380e3 AC |
1529 | if(changed) |
1530 | { | |
1531 | target_p->tsinfo = newts; | |
1532 | monitor_signoff(target_p); | |
1533 | } | |
1534 | invalidate_bancache_user(target_p); | |
1535 | ||
1536 | if(do_qjm) | |
1537 | { | |
1538 | va_start(ap, format); | |
1539 | vsnprintf(reason, 255, format, ap); | |
1540 | va_end(ap); | |
1541 | ||
4a5330bb | 1542 | sendto_common_channels_local_butone(target_p, NOCAPS, CLICAP_CHGHOST, ":%s!%s@%s QUIT :%s", |
212380e3 AC |
1543 | target_p->name, target_p->username, target_p->host, |
1544 | reason); | |
1545 | ||
5cefa1d6 | 1546 | RB_DLINK_FOREACH(ptr, target_p->user->channel.head) |
212380e3 AC |
1547 | { |
1548 | mscptr = ptr->data; | |
1549 | chptr = mscptr->chptr; | |
1550 | mptr = mode; | |
1551 | ||
1552 | if(is_chanop(mscptr)) | |
1553 | { | |
1554 | *mptr++ = 'o'; | |
1555 | strcat(modeval, nick); | |
1556 | strcat(modeval, " "); | |
1557 | } | |
1558 | ||
1559 | if(is_voiced(mscptr)) | |
1560 | { | |
1561 | *mptr++ = 'v'; | |
1562 | strcat(modeval, nick); | |
1563 | } | |
1564 | ||
1565 | *mptr = '\0'; | |
1566 | ||
4a5330bb | 1567 | sendto_channel_local_with_capability_butone(target_p, ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN | CLICAP_CHGHOST, chptr, |
a695b0e4 | 1568 | ":%s!%s@%s JOIN %s", nick, user, host, chptr->chname); |
4a5330bb | 1569 | sendto_channel_local_with_capability_butone(target_p, ALL_MEMBERS, CLICAP_EXTENDED_JOIN, CLICAP_CHGHOST, chptr, |
a695b0e4 SB |
1570 | ":%s!%s@%s JOIN %s %s :%s", nick, user, host, chptr->chname, |
1571 | EmptyString(target_p->user->suser) ? "*" : target_p->user->suser, | |
1572 | target_p->info); | |
1573 | ||
212380e3 | 1574 | if(*mode) |
ad9cbf9e MU |
1575 | sendto_channel_local_with_capability_butone(target_p, ALL_MEMBERS, NOCAPS, CLICAP_CHGHOST, chptr, |
1576 | ":%s MODE %s +%s %s", target_p->servptr->name, chptr->chname, mode, modeval); | |
212380e3 AC |
1577 | |
1578 | *modeval = '\0'; | |
1579 | } | |
1580 | ||
c5bbc603 KB |
1581 | /* Resend away message to away-notify enabled clients. */ |
1582 | if (target_p->user->away) | |
4a5330bb | 1583 | sendto_common_channels_local_butone(target_p, CLICAP_AWAY_NOTIFY, CLICAP_CHGHOST, ":%s!%s@%s AWAY :%s", |
0e17ce06 | 1584 | nick, user, host, |
c5bbc603 KB |
1585 | target_p->user->away); |
1586 | ||
4a5330bb AC |
1587 | sendto_common_channels_local_butone(target_p, CLICAP_CHGHOST, NOCAPS, |
1588 | ":%s!%s@%s CHGHOST %s %s", | |
1589 | target_p->name, target_p->username, target_p->host, user, host); | |
1590 | ||
212380e3 AC |
1591 | if(MyClient(target_p) && changed_case) |
1592 | sendto_one(target_p, ":%s!%s@%s NICK %s", | |
4a5330bb | 1593 | target_p->name, user, host, nick); |
ae4ce45f KB |
1594 | |
1595 | /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */ | |
212380e3 AC |
1596 | } |
1597 | else if(changed_case) | |
1598 | { | |
583f064f | 1599 | sendto_common_channels_local(target_p, NOCAPS, NOCAPS, ":%s!%s@%s NICK :%s", |
4a5330bb | 1600 | target_p->name, user, host, nick); |
ae4ce45f | 1601 | |
34616c3b JT |
1602 | if(MyConnect(target_p)) |
1603 | sendto_realops_snomask(SNO_NCHANGE, L_ALL, | |
1604 | "Nick change: From %s to %s [%s@%s]", | |
1605 | target_p->name, nick, | |
1606 | target_p->username, target_p->host); | |
212380e3 AC |
1607 | } |
1608 | ||
cd66c5b9 AC |
1609 | if (user != target_p->username) |
1610 | rb_strlcpy(target_p->username, user, sizeof target_p->username); | |
1611 | ||
f427c8b0 | 1612 | rb_strlcpy(target_p->host, host, sizeof target_p->host); |
212380e3 AC |
1613 | |
1614 | if (changed) | |
b47f8a4f | 1615 | whowas_add_history(target_p, 1); |
212380e3 AC |
1616 | |
1617 | del_from_client_hash(target_p->name, target_p); | |
f427c8b0 | 1618 | rb_strlcpy(target_p->name, nick, NICKLEN); |
212380e3 AC |
1619 | add_to_client_hash(target_p->name, target_p); |
1620 | ||
1621 | if(changed) | |
1622 | { | |
1623 | monitor_signon(target_p); | |
1624 | del_all_accepts(target_p); | |
1625 | } | |
1626 | } |