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