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