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