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