]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_nick.c: Sets a users nick. | |
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 | |
23 | * | |
66b4a7ae | 24 | * $Id: m_nick.c 3518 2007-06-22 21:59:09Z jilles $ |
212380e3 | 25 | */ |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "client.h" | |
29 | #include "hash.h" | |
13ae2f4b | 30 | #include "match.h" |
212380e3 | 31 | #include "ircd.h" |
32 | #include "numeric.h" | |
33 | #include "s_conf.h" | |
34 | #include "s_stats.h" | |
35 | #include "s_user.h" | |
36 | #include "hash.h" | |
37 | #include "whowas.h" | |
38 | #include "s_serv.h" | |
39 | #include "send.h" | |
40 | #include "channel.h" | |
d3455e2c | 41 | #include "logger.h" |
212380e3 | 42 | #include "msg.h" |
43 | #include "parse.h" | |
44 | #include "modules.h" | |
45 | #include "common.h" | |
46 | #include "packet.h" | |
47 | #include "scache.h" | |
48 | #include "s_newconf.h" | |
49 | #include "monitor.h" | |
50 | ||
3f7e0642 | 51 | /* Give all UID nicks the same TS. This ensures nick TS is always the same on |
52 | * all servers for each nick-user pair, also if a user with a UID nick changes | |
53 | * their nick but is collided again (the server detecting the collision will | |
54 | * not propagate the nick change further). -- jilles | |
55 | */ | |
56 | #define SAVE_NICKTS 100 | |
57 | ||
212380e3 | 58 | static int mr_nick(struct Client *, struct Client *, int, const char **); |
59 | static int m_nick(struct Client *, struct Client *, int, const char **); | |
60 | static int mc_nick(struct Client *, struct Client *, int, const char **); | |
61 | static int ms_nick(struct Client *, struct Client *, int, const char **); | |
62 | static int ms_uid(struct Client *, struct Client *, int, const char **); | |
63 | static int ms_euid(struct Client *, struct Client *, int, const char **); | |
64 | static int ms_save(struct Client *, struct Client *, int, const char **); | |
65 | static int can_save(struct Client *); | |
66 | static void save_user(struct Client *, struct Client *, struct Client *); | |
0624f969 | 67 | static void bad_nickname(struct Client *, const char *); |
212380e3 | 68 | |
69 | struct Message nick_msgtab = { | |
70 | "NICK", 0, 0, 0, MFLG_SLOW, | |
6eb9f03a | 71 | {{mr_nick, 0}, {m_nick, 0}, {mc_nick, 3}, {ms_nick, 0}, mg_ignore, {m_nick, 0}} |
212380e3 | 72 | }; |
73 | struct Message uid_msgtab = { | |
74 | "UID", 0, 0, 0, MFLG_SLOW, | |
75 | {mg_ignore, mg_ignore, mg_ignore, {ms_uid, 9}, mg_ignore, mg_ignore} | |
76 | }; | |
77 | struct Message euid_msgtab = { | |
78 | "EUID", 0, 0, 0, MFLG_SLOW, | |
79 | {mg_ignore, mg_ignore, mg_ignore, {ms_euid, 12}, mg_ignore, mg_ignore} | |
80 | }; | |
81 | struct Message save_msgtab = { | |
82 | "SAVE", 0, 0, 0, MFLG_SLOW, | |
83 | {mg_ignore, mg_ignore, mg_ignore, {ms_save, 3}, mg_ignore, mg_ignore} | |
84 | }; | |
85 | ||
86 | mapi_clist_av1 nick_clist[] = { &nick_msgtab, &uid_msgtab, &euid_msgtab, | |
87 | &save_msgtab, NULL }; | |
88 | ||
66b4a7ae | 89 | DECLARE_MODULE_AV1(nick, NULL, NULL, nick_clist, NULL, NULL, "$Revision: 3518 $"); |
212380e3 | 90 | |
91 | static int change_remote_nick(struct Client *, struct Client *, time_t, | |
92 | const char *, int); | |
93 | ||
94 | static int clean_nick(const char *, int loc_client); | |
95 | static int clean_username(const char *); | |
96 | static int clean_host(const char *); | |
97 | static int clean_uid(const char *uid); | |
98 | ||
99 | static void set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick); | |
100 | static void change_local_nick(struct Client *client_p, struct Client *source_p, char *nick, int); | |
101 | static int register_client(struct Client *client_p, struct Client *server, | |
102 | const char *nick, time_t newts, int parc, const char *parv[]); | |
103 | ||
104 | static int perform_nick_collides(struct Client *, struct Client *, | |
105 | struct Client *, int, const char **, | |
106 | time_t, const char *, const char *); | |
107 | static int perform_nickchange_collides(struct Client *, struct Client *, | |
108 | struct Client *, int, const char **, time_t, const char *); | |
109 | ||
110 | /* mr_nick() | |
111 | * parv[0] = sender prefix | |
112 | * parv[1] = nickname | |
113 | */ | |
114 | static int | |
115 | mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
116 | { | |
117 | struct Client *target_p; | |
118 | char nick[NICKLEN]; | |
119 | char *s; | |
120 | ||
121 | if (strlen(client_p->id) == 3) | |
122 | { | |
123 | exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); | |
124 | return 0; | |
125 | } | |
126 | ||
127 | if(parc < 2 || EmptyString(parv[1]) || (parv[1][0] == '~')) | |
128 | { | |
129 | sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), | |
130 | me.name, EmptyString(source_p->name) ? "*" : source_p->name); | |
131 | return 0; | |
132 | } | |
133 | ||
134 | /* due to the scandinavian origins, (~ being uppercase of ^) and ~ | |
135 | * being disallowed as a nick char, we need to chop the first ~ | |
136 | * instead of just erroring. | |
137 | */ | |
138 | if((s = strchr(parv[1], '~'))) | |
139 | *s = '\0'; | |
140 | ||
141 | /* copy the nick and terminate it */ | |
907468c4 | 142 | rb_strlcpy(nick, parv[1], sizeof(nick)); |
212380e3 | 143 | |
144 | /* check the nickname is ok */ | |
145 | if(!clean_nick(nick, 1)) | |
146 | { | |
147 | sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), | |
148 | me.name, EmptyString(parv[0]) ? "*" : parv[0], parv[1]); | |
149 | return 0; | |
150 | } | |
151 | ||
152 | /* check if the nick is resv'd */ | |
153 | if(find_nick_resv(nick)) | |
154 | { | |
155 | sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), | |
156 | me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); | |
157 | return 0; | |
158 | } | |
159 | ||
b37021a4 | 160 | if(irc_dictionary_find(nd_dict, nick)) |
212380e3 | 161 | { |
162 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
163 | me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); | |
164 | return 0; | |
165 | } | |
166 | ||
167 | if((target_p = find_named_client(nick)) == NULL) | |
168 | set_initial_nick(client_p, source_p, nick); | |
169 | else if(source_p == target_p) | |
170 | strcpy(source_p->name, nick); | |
171 | else | |
172 | sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick); | |
173 | ||
174 | return 0; | |
175 | } | |
176 | ||
177 | /* m_nick() | |
178 | * parv[0] = sender prefix | |
179 | * parv[1] = nickname | |
180 | */ | |
181 | static int | |
182 | m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
183 | { | |
184 | struct Client *target_p; | |
185 | char nick[NICKLEN]; | |
186 | char *s; | |
187 | ||
188 | if(parc < 2 || EmptyString(parv[1]) || (parv[1][0] == '~')) | |
189 | { | |
190 | sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name); | |
191 | return 0; | |
192 | } | |
193 | ||
194 | /* due to the scandinavian origins, (~ being uppercase of ^) and ~ | |
195 | * being disallowed as a nick char, we need to chop the first ~ | |
196 | * instead of just erroring. | |
197 | */ | |
198 | if((s = strchr(parv[1], '~'))) | |
199 | *s = '\0'; | |
200 | ||
201 | /* mark end of grace period, to prevent nickflooding */ | |
202 | if(!IsFloodDone(source_p)) | |
203 | flood_endgrace(source_p); | |
204 | ||
205 | /* terminate nick to NICKLEN, we dont want clean_nick() to error! */ | |
907468c4 | 206 | rb_strlcpy(nick, parv[1], sizeof(nick)); |
212380e3 | 207 | |
208 | /* check the nickname is ok */ | |
209 | if(!clean_nick(nick, 1)) | |
210 | { | |
211 | sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, parv[0], nick); | |
212 | return 0; | |
213 | } | |
214 | ||
215 | if(!IsExemptResv(source_p) && find_nick_resv(nick)) | |
216 | { | |
217 | sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); | |
218 | return 0; | |
219 | } | |
220 | ||
b37021a4 | 221 | if(irc_dictionary_find(nd_dict, nick)) |
212380e3 | 222 | { |
223 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
224 | me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); | |
225 | return 0; | |
226 | } | |
227 | ||
228 | if((target_p = find_named_client(nick))) | |
229 | { | |
230 | /* If(target_p == source_p) the client is changing nicks between | |
231 | * equivalent nicknames ie: [nick] -> {nick} | |
232 | */ | |
233 | if(target_p == source_p) | |
234 | { | |
235 | /* check the nick isnt exactly the same */ | |
236 | if(strcmp(target_p->name, nick)) | |
237 | change_local_nick(client_p, source_p, nick, 1); | |
238 | ||
239 | } | |
240 | ||
241 | /* drop unregged client */ | |
242 | else if(IsUnknown(target_p)) | |
243 | { | |
244 | exit_client(NULL, target_p, &me, "Overridden"); | |
245 | change_local_nick(client_p, source_p, nick, 1); | |
246 | } | |
247 | else | |
248 | sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, parv[0], nick); | |
249 | ||
250 | return 0; | |
251 | } | |
252 | else | |
253 | change_local_nick(client_p, source_p, nick, 1); | |
254 | ||
255 | return 0; | |
256 | } | |
257 | ||
6eb9f03a | 258 | /* mc_nick() |
212380e3 | 259 | * |
260 | * server -> server nick change | |
261 | * parv[0] = sender prefix | |
262 | * parv[1] = nickname | |
263 | * parv[2] = TS when nick change | |
212380e3 | 264 | */ |
265 | static int | |
266 | mc_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
267 | { | |
268 | struct Client *target_p; | |
269 | time_t newts = 0; | |
270 | ||
271 | /* if nicks erroneous, or too long, kill */ | |
272 | if(!clean_nick(parv[1], 0)) | |
273 | { | |
0624f969 | 274 | bad_nickname(client_p, parv[1]); |
212380e3 | 275 | return 0; |
276 | } | |
277 | ||
278 | newts = atol(parv[2]); | |
279 | target_p = find_named_client(parv[1]); | |
280 | ||
281 | /* if the nick doesnt exist, allow it and process like normal */ | |
282 | if(target_p == NULL) | |
283 | { | |
284 | change_remote_nick(client_p, source_p, newts, parv[1], 1); | |
285 | } | |
286 | else if(IsUnknown(target_p)) | |
287 | { | |
288 | exit_client(NULL, target_p, &me, "Overridden"); | |
289 | change_remote_nick(client_p, source_p, newts, parv[1], 1); | |
290 | } | |
291 | else if(target_p == source_p) | |
292 | { | |
293 | /* client changing case of nick */ | |
294 | if(strcmp(target_p->name, parv[1])) | |
295 | change_remote_nick(client_p, source_p, newts, parv[1], 1); | |
296 | } | |
297 | /* we've got a collision! */ | |
298 | else | |
299 | perform_nickchange_collides(source_p, client_p, target_p, | |
300 | parc, parv, newts, parv[1]); | |
301 | ||
302 | return 0; | |
303 | } | |
304 | ||
305 | static int | |
306 | ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
307 | { | |
6eb9f03a | 308 | const char *nick, *server; |
212380e3 | 309 | |
6eb9f03a JT |
310 | nick = parc > 1 ? parv[1] : "?"; |
311 | server = parc > 7 ? parv[7] : "?"; | |
212380e3 | 312 | |
6eb9f03a JT |
313 | sendto_wallops_flags(UMODE_WALLOP, &me, |
314 | "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", | |
315 | client_p->name, nick, server); | |
316 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, | |
317 | ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", | |
318 | me.id, client_p->name, nick, server); | |
319 | ilog(L_SERVER, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)", | |
320 | client_p->name, nick, server); | |
212380e3 | 321 | |
6eb9f03a | 322 | exit_client(client_p, client_p, &me, "TS5 nickname introduced"); |
212380e3 | 323 | |
324 | return 0; | |
325 | } | |
326 | ||
327 | /* ms_uid() | |
328 | * parv[1] - nickname | |
329 | * parv[2] - hops | |
330 | * parv[3] - TS | |
331 | * parv[4] - umodes | |
332 | * parv[5] - username | |
333 | * parv[6] - hostname | |
334 | * parv[7] - IP | |
335 | * parv[8] - UID | |
336 | * parv[9] - gecos | |
337 | */ | |
338 | static int | |
339 | ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
340 | { | |
341 | struct Client *target_p; | |
342 | time_t newts = 0; | |
4137c21c | 343 | char squitreason[120]; |
212380e3 | 344 | |
345 | newts = atol(parv[3]); | |
346 | ||
347 | if(parc != 10) | |
348 | { | |
349 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
350 | "Dropping server %s due to (invalid) command 'UID' " | |
351 | "with %d arguments (expecting 10)", client_p->name, parc); | |
352 | ilog(L_SERVER, "Excess parameters (%d) for command 'UID' from %s.", | |
353 | parc, client_p->name); | |
18c12212 JT |
354 | rb_snprintf(squitreason, sizeof squitreason, |
355 | "Excess parameters (%d) to %s command, expecting %d", | |
356 | parc, "UID", 10); | |
357 | exit_client(client_p, client_p, client_p, squitreason); | |
212380e3 | 358 | return 0; |
359 | } | |
360 | ||
361 | /* if nicks erroneous, or too long, kill */ | |
362 | if(!clean_nick(parv[1], 0)) | |
363 | { | |
0624f969 | 364 | bad_nickname(client_p, parv[1]); |
212380e3 | 365 | return 0; |
366 | } | |
367 | ||
4137c21c | 368 | if(!clean_uid(parv[8])) |
212380e3 | 369 | { |
4137c21c JT |
370 | rb_snprintf(squitreason, sizeof squitreason, |
371 | "Invalid UID %s for nick %s on %s", | |
372 | parv[8], parv[1], source_p->name); | |
373 | exit_client(client_p, client_p, client_p, squitreason); | |
212380e3 | 374 | return 0; |
375 | } | |
376 | ||
4137c21c | 377 | if(!clean_username(parv[5]) || !clean_host(parv[6])) |
212380e3 | 378 | { |
83251205 | 379 | ServerStats.is_kill++; |
212380e3 | 380 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
4137c21c JT |
381 | "Bad user@host: %s@%s From: %s(via %s)", |
382 | parv[5], parv[6], source_p->name, client_p->name); | |
383 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); | |
212380e3 | 384 | return 0; |
385 | } | |
386 | ||
387 | /* check length of clients gecos */ | |
388 | if(strlen(parv[9]) > REALLEN) | |
389 | { | |
390 | char *s = LOCAL_COPY(parv[9]); | |
391 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", | |
392 | parv[0], parv[1]); | |
393 | s[REALLEN] = '\0'; | |
394 | parv[9] = s; | |
395 | } | |
396 | ||
397 | target_p = find_named_client(parv[1]); | |
398 | ||
399 | if(target_p == NULL) | |
400 | { | |
401 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
402 | } | |
403 | else if(IsUnknown(target_p)) | |
404 | { | |
405 | exit_client(NULL, target_p, &me, "Overridden"); | |
406 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
407 | } | |
408 | /* we've got a collision! */ | |
409 | else | |
410 | perform_nick_collides(source_p, client_p, target_p, parc, parv, | |
411 | newts, parv[1], parv[8]); | |
412 | ||
413 | return 0; | |
414 | } | |
415 | ||
416 | /* ms_euid() | |
417 | * parv[1] - nickname | |
418 | * parv[2] - hops | |
419 | * parv[3] - TS | |
420 | * parv[4] - umodes | |
421 | * parv[5] - username | |
422 | * parv[6] - hostname | |
423 | * parv[7] - IP | |
424 | * parv[8] - UID | |
425 | * parv[9] - realhost | |
426 | * parv[10] - account | |
427 | * parv[11] - gecos | |
428 | */ | |
429 | static int | |
430 | ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
431 | { | |
432 | struct Client *target_p; | |
433 | time_t newts = 0; | |
4137c21c | 434 | char squitreason[120]; |
212380e3 | 435 | |
436 | newts = atol(parv[3]); | |
437 | ||
438 | if(parc != 12) | |
439 | { | |
440 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
441 | "Dropping server %s due to (invalid) command 'EUID' " | |
442 | "with %d arguments (expecting 12)", client_p->name, parc); | |
443 | ilog(L_SERVER, "Excess parameters (%d) for command 'EUID' from %s.", | |
444 | parc, client_p->name); | |
18c12212 JT |
445 | rb_snprintf(squitreason, sizeof squitreason, |
446 | "Excess parameters (%d) to %s command, expecting %d", | |
447 | parc, "EUID", 12); | |
448 | exit_client(client_p, client_p, client_p, squitreason); | |
212380e3 | 449 | return 0; |
450 | } | |
451 | ||
452 | /* if nicks erroneous, or too long, kill */ | |
453 | if(!clean_nick(parv[1], 0)) | |
454 | { | |
0624f969 | 455 | bad_nickname(client_p, parv[1]); |
212380e3 | 456 | return 0; |
457 | } | |
458 | ||
4137c21c | 459 | if(!clean_uid(parv[8])) |
212380e3 | 460 | { |
4137c21c JT |
461 | rb_snprintf(squitreason, sizeof squitreason, |
462 | "Invalid UID %s for nick %s on %s", | |
463 | parv[8], parv[1], source_p->name); | |
464 | exit_client(client_p, client_p, client_p, squitreason); | |
212380e3 | 465 | return 0; |
466 | } | |
467 | ||
4137c21c | 468 | if(!clean_username(parv[5]) || !clean_host(parv[6])) |
212380e3 | 469 | { |
83251205 | 470 | ServerStats.is_kill++; |
212380e3 | 471 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
4137c21c JT |
472 | "Bad user@host: %s@%s From: %s(via %s)", |
473 | parv[5], parv[6], source_p->name, client_p->name); | |
474 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); | |
212380e3 | 475 | return 0; |
476 | } | |
477 | ||
478 | if(strcmp(parv[9], "*") && !clean_host(parv[9])) | |
479 | { | |
83251205 | 480 | ServerStats.is_kill++; |
212380e3 | 481 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
482 | "Bad realhost: %s From: %s(via %s)", | |
483 | parv[9], source_p->name, client_p->name); | |
484 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); | |
485 | return 0; | |
486 | } | |
487 | ||
488 | /* check length of clients gecos */ | |
489 | if(strlen(parv[11]) > REALLEN) | |
490 | { | |
491 | char *s = LOCAL_COPY(parv[11]); | |
492 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", | |
493 | parv[0], parv[1]); | |
494 | s[REALLEN] = '\0'; | |
495 | parv[11] = s; | |
496 | } | |
497 | ||
498 | target_p = find_named_client(parv[1]); | |
499 | ||
500 | if(target_p == NULL) | |
501 | { | |
502 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
503 | } | |
504 | else if(IsUnknown(target_p)) | |
505 | { | |
506 | exit_client(NULL, target_p, &me, "Overridden"); | |
507 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
508 | } | |
509 | /* we've got a collision! */ | |
510 | else | |
511 | perform_nick_collides(source_p, client_p, target_p, parc, parv, | |
512 | newts, parv[1], parv[8]); | |
513 | ||
514 | return 0; | |
515 | } | |
516 | ||
517 | /* ms_save() | |
518 | * parv[1] - UID | |
519 | * parv[2] - TS | |
520 | */ | |
521 | static int | |
522 | ms_save(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
523 | { | |
524 | struct Client *target_p; | |
525 | ||
526 | target_p = find_id(parv[1]); | |
527 | if (target_p == NULL) | |
528 | return 0; | |
529 | if (!IsPerson(target_p)) | |
530 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
531 | "Ignored SAVE message for non-person %s from %s", | |
532 | target_p->name, source_p->name); | |
533 | else if (IsDigit(target_p->name[0])) | |
534 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
535 | "Ignored noop SAVE message for %s from %s", | |
536 | target_p->name, source_p->name); | |
537 | else if (target_p->tsinfo == atol(parv[2])) | |
538 | save_user(client_p, source_p, target_p); | |
539 | else | |
540 | sendto_realops_snomask(SNO_SKILL, L_ALL, | |
541 | "Ignored SAVE message for %s from %s", | |
542 | target_p->name, source_p->name); | |
543 | return 0; | |
544 | } | |
545 | ||
546 | /* clean_nick() | |
547 | * | |
548 | * input - nickname to check | |
549 | * output - 0 if erroneous, else 1 | |
550 | * side effects - | |
551 | */ | |
552 | static int | |
553 | clean_nick(const char *nick, int loc_client) | |
554 | { | |
555 | int len = 0; | |
556 | ||
557 | /* nicks cant start with a digit or -, and must have a length */ | |
558 | if(*nick == '-' || *nick == '\0') | |
559 | return 0; | |
560 | ||
561 | if(loc_client && IsDigit(*nick)) | |
562 | return 0; | |
563 | ||
564 | for(; *nick; nick++) | |
565 | { | |
566 | len++; | |
567 | if(!IsNickChar(*nick)) | |
568 | return 0; | |
569 | } | |
570 | ||
571 | /* nicklen is +1 */ | |
572 | if(len >= NICKLEN) | |
573 | return 0; | |
574 | ||
575 | return 1; | |
576 | } | |
577 | ||
578 | /* clean_username() | |
579 | * | |
580 | * input - username to check | |
581 | * output - 0 if erroneous, else 0 | |
582 | * side effects - | |
583 | */ | |
584 | static int | |
585 | clean_username(const char *username) | |
586 | { | |
587 | int len = 0; | |
588 | ||
589 | for(; *username; username++) | |
590 | { | |
591 | len++; | |
592 | ||
593 | if(!IsUserChar(*username)) | |
594 | return 0; | |
595 | } | |
596 | ||
597 | if(len > USERLEN) | |
598 | return 0; | |
599 | ||
600 | return 1; | |
601 | } | |
602 | ||
603 | /* clean_host() | |
604 | * | |
605 | * input - host to check | |
606 | * output - 0 if erroneous, else 0 | |
607 | * side effects - | |
608 | */ | |
609 | static int | |
610 | clean_host(const char *host) | |
611 | { | |
612 | int len = 0; | |
613 | ||
614 | for(; *host; host++) | |
615 | { | |
616 | len++; | |
617 | ||
618 | if(!IsHostChar(*host)) | |
619 | return 0; | |
620 | } | |
621 | ||
622 | if(len > HOSTLEN) | |
623 | return 0; | |
624 | ||
625 | return 1; | |
626 | } | |
627 | ||
628 | static int | |
629 | clean_uid(const char *uid) | |
630 | { | |
631 | int len = 1; | |
632 | ||
633 | if(!IsDigit(*uid++)) | |
634 | return 0; | |
635 | ||
636 | for(; *uid; uid++) | |
637 | { | |
638 | len++; | |
639 | ||
640 | if(!IsIdChar(*uid)) | |
641 | return 0; | |
642 | } | |
643 | ||
644 | if(len != IDLEN - 1) | |
645 | return 0; | |
646 | ||
647 | return 1; | |
648 | } | |
649 | ||
650 | static void | |
651 | set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) | |
652 | { | |
653 | char buf[USERLEN + 1]; | |
bfccb2c0 | 654 | char note[NICKLEN + 10]; |
212380e3 | 655 | |
656 | /* This had to be copied here to avoid problems.. */ | |
9f6bbe3c | 657 | source_p->tsinfo = rb_current_time(); |
212380e3 | 658 | if(source_p->name[0]) |
659 | del_from_client_hash(source_p->name, source_p); | |
660 | ||
661 | strcpy(source_p->name, nick); | |
662 | add_to_client_hash(nick, source_p); | |
663 | ||
bfccb2c0 JT |
664 | rb_snprintf(note, sizeof(note), "Nick: %s", nick); |
665 | rb_note(client_p->localClient->F, note); | |
212380e3 | 666 | |
667 | if(source_p->flags & FLAGS_SENTUSER) | |
668 | { | |
907468c4 | 669 | rb_strlcpy(buf, source_p->username, sizeof(buf)); |
212380e3 | 670 | |
671 | /* got user, heres nick. */ | |
672 | register_local_user(client_p, source_p, buf); | |
673 | ||
674 | } | |
675 | } | |
676 | ||
677 | static void | |
678 | change_local_nick(struct Client *client_p, struct Client *source_p, | |
679 | char *nick, int dosend) | |
680 | { | |
681 | struct Client *target_p; | |
90a3c35b | 682 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 683 | struct Channel *chptr; |
bfccb2c0 | 684 | char note[NICKLEN + 10]; |
212380e3 | 685 | int samenick; |
686 | ||
687 | if (dosend) | |
688 | { | |
689 | chptr = find_bannickchange_channel(source_p); | |
690 | if (chptr != NULL) | |
691 | { | |
692 | sendto_one_numeric(source_p, ERR_BANNICKCHANGE, | |
693 | form_str(ERR_BANNICKCHANGE), | |
694 | nick, chptr->chname); | |
695 | return; | |
696 | } | |
9f6bbe3c | 697 | if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < rb_current_time()) |
212380e3 | 698 | source_p->localClient->number_of_nick_changes = 0; |
699 | ||
9f6bbe3c | 700 | source_p->localClient->last_nick_change = rb_current_time(); |
212380e3 | 701 | source_p->localClient->number_of_nick_changes++; |
702 | ||
703 | if(ConfigFileEntry.anti_nick_flood && !IsOper(source_p) && | |
704 | source_p->localClient->number_of_nick_changes > ConfigFileEntry.max_nick_changes) | |
705 | { | |
706 | sendto_one(source_p, form_str(ERR_NICKTOOFAST), | |
707 | me.name, source_p->name, source_p->name, | |
708 | nick, ConfigFileEntry.max_nick_time); | |
709 | return; | |
710 | } | |
711 | } | |
712 | ||
713 | samenick = irccmp(source_p->name, nick) ? 0 : 1; | |
714 | ||
715 | /* dont reset TS if theyre just changing case of nick */ | |
716 | if(!samenick) | |
717 | { | |
95ffa685 | 718 | /* force the TS to increase -- jilles */ |
9f6bbe3c | 719 | if (source_p->tsinfo >= rb_current_time()) |
95ffa685 | 720 | source_p->tsinfo++; |
721 | else | |
9f6bbe3c | 722 | source_p->tsinfo = rb_current_time(); |
212380e3 | 723 | monitor_signoff(source_p); |
724 | /* we only do bancache for local users -- jilles */ | |
725 | if(source_p->user) | |
726 | invalidate_bancache_user(source_p); | |
727 | } | |
728 | ||
729 | sendto_realops_snomask(SNO_NCHANGE, L_ALL, | |
730 | "Nick change: From %s to %s [%s@%s]", | |
731 | source_p->name, nick, source_p->username, source_p->host); | |
732 | ||
733 | /* send the nick change to the users channels */ | |
734 | sendto_common_channels_local(source_p, ":%s!%s@%s NICK :%s", | |
735 | source_p->name, source_p->username, source_p->host, nick); | |
736 | ||
737 | /* send the nick change to servers.. */ | |
738 | if(source_p->user) | |
739 | { | |
740 | add_history(source_p, 1); | |
741 | ||
742 | if (dosend) | |
743 | { | |
744 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", | |
745 | use_id(source_p), nick, (long) source_p->tsinfo); | |
212380e3 | 746 | } |
747 | } | |
748 | ||
749 | /* Finally, add to hash */ | |
750 | del_from_client_hash(source_p->name, source_p); | |
751 | strcpy(source_p->name, nick); | |
752 | add_to_client_hash(nick, source_p); | |
753 | ||
754 | if(!samenick) | |
755 | monitor_signon(source_p); | |
756 | ||
757 | /* Make sure everyone that has this client on its accept list | |
758 | * loses that reference. | |
759 | */ | |
760 | /* we used to call del_all_accepts() here, but theres no real reason | |
761 | * to clear a clients own list of accepted clients. So just remove | |
762 | * them from everyone elses list --anfl | |
763 | */ | |
90a3c35b | 764 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) |
212380e3 | 765 | { |
766 | target_p = ptr->data; | |
767 | ||
9f6c3353 JT |
768 | rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list); |
769 | rb_dlinkDestroy(ptr, &source_p->on_allow_list); | |
212380e3 | 770 | } |
771 | ||
bfccb2c0 JT |
772 | rb_snprintf(note, sizeof(note), "Nick: %s", nick); |
773 | rb_note(client_p->localClient->F, note); | |
212380e3 | 774 | |
775 | return; | |
776 | } | |
777 | ||
778 | /* | |
779 | * change_remote_nick() | |
780 | */ | |
781 | static int | |
782 | change_remote_nick(struct Client *client_p, struct Client *source_p, | |
783 | time_t newts, const char *nick, int dosend) | |
784 | { | |
785 | struct nd_entry *nd; | |
786 | int samenick = irccmp(source_p->name, nick) ? 0 : 1; | |
787 | ||
788 | /* client changing their nick - dont reset ts if its same */ | |
789 | if(!samenick) | |
790 | { | |
9f6bbe3c | 791 | source_p->tsinfo = newts ? newts : rb_current_time(); |
212380e3 | 792 | monitor_signoff(source_p); |
793 | } | |
794 | ||
795 | sendto_common_channels_local(source_p, ":%s!%s@%s NICK :%s", | |
796 | source_p->name, source_p->username, source_p->host, nick); | |
797 | ||
798 | if(source_p->user) | |
799 | { | |
800 | add_history(source_p, 1); | |
801 | if (dosend) | |
802 | { | |
803 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", | |
804 | use_id(source_p), nick, (long) source_p->tsinfo); | |
212380e3 | 805 | } |
806 | } | |
807 | ||
808 | del_from_client_hash(source_p->name, source_p); | |
809 | ||
810 | /* invalidate nick delay when a remote client uses the nick.. */ | |
b37021a4 | 811 | if((nd = irc_dictionary_retrieve(nd_dict, nick))) |
212380e3 | 812 | free_nd_entry(nd); |
813 | ||
814 | strcpy(source_p->name, nick); | |
815 | add_to_client_hash(nick, source_p); | |
816 | ||
817 | if(!samenick) | |
818 | monitor_signon(source_p); | |
819 | ||
820 | /* remove all accepts pointing to the client */ | |
821 | del_all_accepts(source_p); | |
822 | ||
823 | return 0; | |
824 | } | |
825 | ||
826 | static int | |
827 | perform_nick_collides(struct Client *source_p, struct Client *client_p, | |
828 | struct Client *target_p, int parc, const char *parv[], | |
829 | time_t newts, const char *nick, const char *uid) | |
830 | { | |
831 | int sameuser; | |
832 | int use_save; | |
833 | const char *action; | |
834 | ||
835 | use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && | |
836 | uid != NULL && can_save(source_p); | |
837 | action = use_save ? "saved" : "killed"; | |
838 | ||
839 | /* if we dont have a ts, or their TS's are the same, kill both */ | |
840 | if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo)) | |
841 | { | |
dc4d5012 | 842 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 843 | "Nick collision on %s(%s <- %s)(both %s)", |
844 | target_p->name, target_p->from->name, client_p->name, action); | |
845 | ||
846 | if (use_save) | |
847 | { | |
848 | save_user(&me, &me, target_p); | |
83251205 | 849 | ServerStats.is_save++; |
212380e3 | 850 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, |
851 | uid, (long)newts); | |
852 | register_client(client_p, source_p, | |
3f7e0642 | 853 | uid, SAVE_NICKTS, parc, parv); |
212380e3 | 854 | } |
855 | else | |
856 | { | |
857 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, | |
858 | form_str(ERR_NICKCOLLISION), target_p->name); | |
859 | ||
860 | /* if the new client being introduced has a UID, we need to | |
861 | * issue a KILL for it.. | |
862 | */ | |
863 | if(uid) | |
864 | sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))", | |
865 | me.id, uid, me.name); | |
866 | ||
867 | /* we then need to KILL the old client everywhere */ | |
868 | kill_client_serv_butone(NULL, target_p, "%s (Nick collision (new))", me.name); | |
83251205 | 869 | ServerStats.is_kill++; |
212380e3 | 870 | |
871 | target_p->flags |= FLAGS_KILLED; | |
872 | exit_client(client_p, target_p, &me, "Nick collision (new)"); | |
873 | } | |
874 | return 0; | |
875 | } | |
876 | /* the timestamps are different */ | |
877 | else | |
878 | { | |
879 | sameuser = (target_p->user) && !irccmp(target_p->username, parv[5]) | |
880 | && !irccmp(target_p->host, parv[6]); | |
881 | ||
882 | if((sameuser && newts < target_p->tsinfo) || | |
883 | (!sameuser && newts > target_p->tsinfo)) | |
884 | { | |
885 | /* if we have a UID, then we need to issue a KILL, | |
886 | * otherwise we do nothing and hope that the other | |
887 | * client will collide it.. | |
888 | */ | |
889 | if (use_save) | |
890 | { | |
891 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, | |
892 | uid, (long)newts); | |
893 | register_client(client_p, source_p, | |
3f7e0642 | 894 | uid, SAVE_NICKTS, parc, parv); |
212380e3 | 895 | } |
896 | else if(uid) | |
897 | sendto_one(client_p, | |
898 | ":%s KILL %s :%s (Nick collision (new))", | |
899 | me.id, uid, me.name); | |
900 | return 0; | |
901 | } | |
902 | else | |
903 | { | |
904 | if(sameuser) | |
dc4d5012 | 905 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 906 | "Nick collision on %s(%s <- %s)(older %s)", |
907 | target_p->name, target_p->from->name, | |
908 | client_p->name, action); | |
909 | else | |
dc4d5012 | 910 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 911 | "Nick collision on %s(%s <- %s)(newer %s)", |
912 | target_p->name, target_p->from->name, | |
913 | client_p->name, action); | |
914 | ||
915 | if (use_save) | |
916 | { | |
83251205 | 917 | ServerStats.is_save++; |
212380e3 | 918 | save_user(&me, &me, target_p); |
919 | } | |
920 | else | |
921 | { | |
83251205 | 922 | ServerStats.is_kill++; |
212380e3 | 923 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, |
924 | form_str(ERR_NICKCOLLISION), target_p->name); | |
925 | ||
926 | /* now we just need to kill the existing client */ | |
927 | kill_client_serv_butone(client_p, target_p, | |
928 | "%s (Nick collision (new))", me.name); | |
929 | ||
930 | target_p->flags |= FLAGS_KILLED; | |
931 | (void) exit_client(client_p, target_p, &me, "Nick collision"); | |
932 | } | |
933 | ||
934 | register_client(client_p, parc >= 10 ? source_p : NULL, | |
935 | nick, newts, parc, parv); | |
936 | ||
937 | return 0; | |
938 | } | |
939 | } | |
940 | } | |
941 | ||
942 | ||
943 | static int | |
944 | perform_nickchange_collides(struct Client *source_p, struct Client *client_p, | |
945 | struct Client *target_p, int parc, | |
946 | const char *parv[], time_t newts, const char *nick) | |
947 | { | |
948 | int sameuser; | |
949 | int use_save; | |
950 | const char *action; | |
951 | ||
952 | use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && | |
953 | can_save(source_p); | |
954 | action = use_save ? "saved" : "killed"; | |
955 | ||
956 | /* its a client changing nick and causing a collide */ | |
957 | if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user) | |
958 | { | |
dc4d5012 | 959 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 960 | "Nick change collision from %s to %s(%s <- %s)(both %s)", |
961 | source_p->name, target_p->name, target_p->from->name, | |
962 | client_p->name, action); | |
963 | ||
964 | if (use_save) | |
965 | { | |
83251205 | 966 | ServerStats.is_save += 2; |
212380e3 | 967 | save_user(&me, &me, target_p); |
968 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, | |
969 | source_p->id, (long)newts); | |
970 | /* don't send a redundant nick change */ | |
971 | if (!IsDigit(source_p->name[0])) | |
3f7e0642 | 972 | change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); |
212380e3 | 973 | } |
974 | else | |
975 | { | |
83251205 | 976 | ServerStats.is_kill++; |
212380e3 | 977 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, |
978 | form_str(ERR_NICKCOLLISION), target_p->name); | |
979 | ||
980 | kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); | |
981 | ||
83251205 | 982 | ServerStats.is_kill++; |
212380e3 | 983 | |
984 | kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); | |
985 | ||
986 | target_p->flags |= FLAGS_KILLED; | |
987 | exit_client(NULL, target_p, &me, "Nick collision(new)"); | |
988 | source_p->flags |= FLAGS_KILLED; | |
989 | exit_client(client_p, source_p, &me, "Nick collision(old)"); | |
990 | } | |
991 | return 0; | |
992 | } | |
993 | else | |
994 | { | |
995 | sameuser = !irccmp(target_p->username, source_p->username) && | |
996 | !irccmp(target_p->host, source_p->host); | |
997 | ||
998 | if((sameuser && newts < target_p->tsinfo) || | |
999 | (!sameuser && newts > target_p->tsinfo)) | |
1000 | { | |
1001 | if(sameuser) | |
dc4d5012 | 1002 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 1003 | "Nick change collision from %s to %s(%s <- %s)(older %s)", |
1004 | source_p->name, target_p->name, | |
1005 | target_p->from->name, client_p->name, action); | |
1006 | else | |
dc4d5012 | 1007 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 1008 | "Nick change collision from %s to %s(%s <- %s)(newer %s)", |
1009 | source_p->name, target_p->name, | |
1010 | target_p->from->name, client_p->name, action); | |
1011 | ||
1012 | if (use_save) | |
1013 | { | |
83251205 | 1014 | ServerStats.is_save++; |
212380e3 | 1015 | /* can't broadcast a SAVE because the |
1016 | * nickchange has happened at client_p | |
1017 | * but not in other directions -- jilles */ | |
1018 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, | |
1019 | source_p->id, (long)newts); | |
212380e3 | 1020 | /* send a :<id> NICK <id> <ts> (!) */ |
1021 | if (!IsDigit(source_p->name[0])) | |
3f7e0642 | 1022 | change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); |
212380e3 | 1023 | } |
1024 | else | |
1025 | { | |
83251205 | 1026 | ServerStats.is_kill++; |
212380e3 | 1027 | |
1028 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, | |
1029 | form_str(ERR_NICKCOLLISION), target_p->name); | |
1030 | ||
1031 | /* kill the client issuing the nickchange */ | |
1032 | kill_client_serv_butone(client_p, source_p, | |
1033 | "%s (Nick change collision)", me.name); | |
1034 | ||
1035 | source_p->flags |= FLAGS_KILLED; | |
1036 | ||
1037 | if(sameuser) | |
1038 | exit_client(client_p, source_p, &me, "Nick collision(old)"); | |
1039 | else | |
1040 | exit_client(client_p, source_p, &me, "Nick collision(new)"); | |
1041 | } | |
1042 | return 0; | |
1043 | } | |
1044 | else | |
1045 | { | |
1046 | if(sameuser) | |
dc4d5012 | 1047 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 1048 | "Nick collision on %s(%s <- %s)(older %s)", |
1049 | target_p->name, target_p->from->name, | |
1050 | client_p->name, action); | |
1051 | else | |
dc4d5012 | 1052 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 | 1053 | "Nick collision on %s(%s <- %s)(newer %s)", |
1054 | target_p->name, target_p->from->name, | |
1055 | client_p->name, action); | |
1056 | ||
1057 | if (use_save) | |
1058 | { | |
83251205 | 1059 | ServerStats.is_save++; |
212380e3 | 1060 | save_user(&me, &me, target_p); |
1061 | } | |
1062 | else | |
1063 | { | |
1064 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, | |
1065 | form_str(ERR_NICKCOLLISION), target_p->name); | |
1066 | ||
1067 | /* kill the client who existed before hand */ | |
1068 | kill_client_serv_butone(client_p, target_p, "%s (Nick collision)", me.name); | |
1069 | ||
83251205 | 1070 | ServerStats.is_kill++; |
212380e3 | 1071 | |
1072 | target_p->flags |= FLAGS_KILLED; | |
1073 | (void) exit_client(client_p, target_p, &me, "Nick collision"); | |
1074 | } | |
1075 | } | |
1076 | } | |
1077 | ||
1078 | change_remote_nick(client_p, source_p, newts, nick, 1); | |
1079 | ||
1080 | return 0; | |
1081 | } | |
1082 | ||
1083 | static int | |
1084 | register_client(struct Client *client_p, struct Client *server, | |
1085 | const char *nick, time_t newts, int parc, const char *parv[]) | |
1086 | { | |
1087 | struct Client *source_p; | |
1088 | struct User *user; | |
1089 | struct nd_entry *nd; | |
1090 | const char *m; | |
1091 | int flag; | |
1092 | ||
64449595 JT |
1093 | if(server == NULL) |
1094 | { | |
1095 | if((server = find_server(NULL, parv[7])) == NULL) | |
1096 | { | |
1097 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1098 | "Ghost killed: %s on invalid server %s", | |
1099 | nick, parv[7]); | |
1100 | sendto_one(client_p, ":%s KILL %s :%s (Server doesn't exist)", | |
1101 | get_id(&me, client_p), nick, me.name); | |
1102 | return 0; | |
1103 | } | |
1104 | } | |
1105 | ||
212380e3 | 1106 | source_p = make_client(client_p); |
1107 | user = make_user(source_p); | |
bfccb2c0 | 1108 | rb_dlinkAddTail(source_p, &source_p->node, &global_client_list); |
212380e3 | 1109 | |
1110 | source_p->hopcount = atoi(parv[2]); | |
1111 | source_p->tsinfo = newts; | |
1112 | ||
1113 | strcpy(source_p->name, nick); | |
907468c4 VY |
1114 | rb_strlcpy(source_p->username, parv[5], sizeof(source_p->username)); |
1115 | rb_strlcpy(source_p->host, parv[6], sizeof(source_p->host)); | |
1116 | rb_strlcpy(source_p->orighost, source_p->host, sizeof(source_p->orighost)); | |
212380e3 | 1117 | |
1118 | if(parc == 12) | |
1119 | { | |
907468c4 VY |
1120 | rb_strlcpy(source_p->info, parv[11], sizeof(source_p->info)); |
1121 | rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); | |
1122 | rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); | |
212380e3 | 1123 | add_to_id_hash(source_p->id, source_p); |
1124 | if (strcmp(parv[9], "*")) | |
1125 | { | |
907468c4 | 1126 | rb_strlcpy(source_p->orighost, parv[9], sizeof(source_p->orighost)); |
212380e3 | 1127 | if (irccmp(source_p->host, source_p->orighost)) |
1128 | SetDynSpoof(source_p); | |
1129 | } | |
1130 | if (strcmp(parv[10], "*")) | |
907468c4 | 1131 | rb_strlcpy(source_p->user->suser, parv[10], sizeof(source_p->user->suser)); |
212380e3 | 1132 | } |
1133 | else if(parc == 10) | |
1134 | { | |
907468c4 VY |
1135 | rb_strlcpy(source_p->info, parv[9], sizeof(source_p->info)); |
1136 | rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); | |
1137 | rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); | |
212380e3 | 1138 | add_to_id_hash(source_p->id, source_p); |
1139 | } | |
1140 | else | |
1141 | { | |
907468c4 | 1142 | rb_strlcpy(source_p->info, parv[8], sizeof(source_p->info)); |
212380e3 | 1143 | } |
1144 | ||
1145 | /* remove any nd entries for this nick */ | |
b37021a4 | 1146 | if((nd = irc_dictionary_retrieve(nd_dict, nick))) |
212380e3 | 1147 | free_nd_entry(nd); |
1148 | ||
1149 | add_to_client_hash(nick, source_p); | |
66b4a7ae | 1150 | add_to_hostname_hash(source_p->orighost, source_p); |
212380e3 | 1151 | monitor_signon(source_p); |
1152 | ||
1153 | m = &parv[4][1]; | |
1154 | while(*m) | |
1155 | { | |
1156 | flag = user_modes[(unsigned char) *m]; | |
1157 | ||
1158 | if(flag & UMODE_SERVICE) | |
1159 | { | |
1160 | int hit = 0; | |
08d11e34 | 1161 | rb_dlink_node *ptr; |
212380e3 | 1162 | |
08d11e34 | 1163 | RB_DLINK_FOREACH(ptr, service_list.head) |
212380e3 | 1164 | { |
c88cdb00 | 1165 | if(!irccmp((const char *) ptr->data, server->name)) |
212380e3 | 1166 | { |
1167 | hit++; | |
1168 | break; | |
1169 | } | |
1170 | } | |
1171 | ||
1172 | if(!hit) | |
1173 | { | |
1174 | m++; | |
1175 | continue; | |
1176 | } | |
1177 | } | |
1178 | ||
1179 | /* increment +i count if theyre invis */ | |
1180 | if(!(source_p->umodes & UMODE_INVISIBLE) && (flag & UMODE_INVISIBLE)) | |
1181 | Count.invisi++; | |
1182 | ||
1183 | /* increment opered count if theyre opered */ | |
1184 | if(!(source_p->umodes & UMODE_OPER) && (flag & UMODE_OPER)) | |
1185 | Count.oper++; | |
1186 | ||
1187 | source_p->umodes |= flag; | |
1188 | m++; | |
1189 | } | |
1190 | ||
1191 | if(IsOper(source_p) && !IsService(source_p)) | |
bfccb2c0 | 1192 | rb_dlinkAddAlloc(source_p, &oper_list); |
212380e3 | 1193 | |
1194 | SetRemoteClient(source_p); | |
1195 | ||
1196 | if(++Count.total > Count.max_tot) | |
1197 | Count.max_tot = Count.total; | |
1198 | ||
64449595 | 1199 | source_p->servptr = server; |
212380e3 | 1200 | |
bfccb2c0 | 1201 | rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); |
212380e3 | 1202 | |
1203 | /* fake direction */ | |
1204 | if(source_p->servptr->from != source_p->from) | |
1205 | { | |
1206 | struct Client *target_p = source_p->servptr->from; | |
1207 | ||
1208 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
1209 | "Bad User [%s] :%s USER %s@%s %s, != %s[%s]", | |
1210 | client_p->name, source_p->name, | |
1211 | source_p->username, source_p->host, | |
c88cdb00 | 1212 | server->name, target_p->name, target_p->from->name); |
212380e3 | 1213 | kill_client(client_p, source_p, |
1214 | "%s (NICK from wrong direction (%s != %s))", | |
c88cdb00 | 1215 | me.name, server->name, target_p->from->name); |
212380e3 | 1216 | source_p->flags |= FLAGS_KILLED; |
1217 | return exit_client(source_p, source_p, &me, "USER server wrong direction"); | |
1218 | } | |
1219 | ||
1220 | call_hook(h_new_remote_user, source_p); | |
1221 | ||
1222 | return (introduce_client(client_p, source_p, user, nick, parc == 12)); | |
1223 | } | |
1224 | ||
1225 | /* Check if we can do SAVE. target_p can be a client to save or a | |
1226 | * server introducing a client -- jilles */ | |
1227 | static int | |
1228 | can_save(struct Client *target_p) | |
1229 | { | |
1230 | struct Client *serv_p; | |
1231 | ||
1232 | if (MyClient(target_p)) | |
1233 | return 1; | |
1234 | if (!has_id(target_p)) | |
1235 | return 0; | |
1236 | serv_p = IsServer(target_p) ? target_p : target_p->servptr; | |
1237 | while (serv_p != NULL && serv_p != &me) | |
1238 | { | |
1239 | if (!(serv_p->serv->caps & CAP_SAVE)) | |
1240 | return 0; | |
1241 | serv_p = serv_p->servptr; | |
1242 | } | |
1243 | return serv_p == &me; | |
1244 | } | |
1245 | ||
1246 | static void | |
1247 | save_user(struct Client *client_p, struct Client *source_p, | |
1248 | struct Client *target_p) | |
1249 | { | |
1250 | if (!MyConnect(target_p) && (!has_id(target_p) || !IsCapable(target_p->from, CAP_SAVE))) | |
1251 | { | |
1252 | /* This shouldn't happen */ | |
1253 | /* Note we only need SAVE support in this direction */ | |
1254 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1255 | "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)", | |
1256 | target_p->name, target_p->username, target_p->host, source_p->name, target_p->from->name); | |
1257 | kill_client_serv_butone(NULL, target_p, "%s (Nick collision (no SAVE support))", me.name); | |
83251205 | 1258 | ServerStats.is_kill++; |
212380e3 | 1259 | |
1260 | target_p->flags |= FLAGS_KILLED; | |
1261 | (void) exit_client(NULL, target_p, &me, "Nick collision (no SAVE support)"); | |
1262 | return; | |
1263 | } | |
1264 | sendto_server(client_p, NULL, CAP_SAVE|CAP_TS6, NOCAPS, ":%s SAVE %s %ld", | |
1265 | source_p->id, target_p->id, (long)target_p->tsinfo); | |
1266 | sendto_server(client_p, NULL, CAP_TS6, CAP_SAVE, ":%s NICK %s :%ld", | |
3f7e0642 | 1267 | target_p->id, target_p->id, (long)SAVE_NICKTS); |
212380e3 | 1268 | if (!IsMe(client_p)) |
1269 | sendto_realops_snomask(SNO_SKILL, L_ALL, | |
1270 | "Received SAVE message for %s from %s", | |
1271 | target_p->name, source_p->name); | |
1272 | if (MyClient(target_p)) | |
1273 | { | |
1274 | sendto_one_numeric(target_p, RPL_SAVENICK, | |
1275 | form_str(RPL_SAVENICK), target_p->id); | |
1276 | change_local_nick(target_p, target_p, target_p->id, 0); | |
3f7e0642 | 1277 | target_p->tsinfo = SAVE_NICKTS; |
212380e3 | 1278 | } |
1279 | else | |
3f7e0642 | 1280 | change_remote_nick(target_p, target_p, SAVE_NICKTS, target_p->id, 0); |
212380e3 | 1281 | } |
0624f969 JT |
1282 | |
1283 | static void bad_nickname(struct Client *client_p, const char *nick) | |
1284 | { | |
1285 | char squitreason[100]; | |
1286 | ||
1287 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
1288 | "Squitting %s because of bad nickname %s (NICKLEN mismatch?)", | |
1289 | client_p->name, nick); | |
1290 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, | |
1291 | ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)", | |
1292 | me.id, client_p->name, nick); | |
ffa772f3 JT |
1293 | ilog(L_SERVER, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)", |
1294 | client_p->name, nick); | |
0624f969 JT |
1295 | |
1296 | rb_snprintf(squitreason, sizeof squitreason, | |
1297 | "Bad nickname introduced [%s]", nick); | |
1298 | exit_client(client_p, client_p, &me, squitreason); | |
1299 | } |