]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
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 AC |
25 | */ |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "client.h" | |
29 | #include "hash.h" | |
4562c604 | 30 | #include "match.h" |
212380e3 AC |
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" | |
4016731b | 41 | #include "logger.h" |
212380e3 AC |
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 JT |
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 AC |
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 *); | |
ad35b2cd | 67 | static void bad_nickname(struct Client *, const char *); |
212380e3 AC |
68 | |
69 | struct Message nick_msgtab = { | |
70 | "NICK", 0, 0, 0, MFLG_SLOW, | |
71 | {{mr_nick, 0}, {m_nick, 0}, {mc_nick, 3}, {ms_nick, 8}, mg_ignore, {m_nick, 0}} | |
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 AC |
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 */ | |
f427c8b0 | 142 | rb_strlcpy(nick, parv[1], sizeof(nick)); |
212380e3 AC |
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 AC |
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! */ | |
f427c8b0 | 206 | rb_strlcpy(nick, parv[1], sizeof(nick)); |
212380e3 AC |
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 AC |
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 | ||
258 | /* ms_nick() | |
259 | * | |
260 | * server -> server nick change | |
261 | * parv[0] = sender prefix | |
262 | * parv[1] = nickname | |
263 | * parv[2] = TS when nick change | |
264 | * | |
265 | * server introducing new nick | |
266 | * parv[0] = sender prefix | |
267 | * parv[1] = nickname | |
268 | * parv[2] = hop count | |
269 | * parv[3] = TS | |
270 | * parv[4] = umode | |
271 | * parv[5] = username | |
272 | * parv[6] = hostname | |
273 | * parv[7] = server | |
274 | * parv[8] = ircname | |
275 | */ | |
276 | static int | |
277 | mc_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
278 | { | |
279 | struct Client *target_p; | |
280 | time_t newts = 0; | |
281 | ||
282 | /* if nicks erroneous, or too long, kill */ | |
283 | if(!clean_nick(parv[1], 0)) | |
284 | { | |
ad35b2cd | 285 | bad_nickname(client_p, parv[1]); |
212380e3 AC |
286 | return 0; |
287 | } | |
288 | ||
289 | newts = atol(parv[2]); | |
290 | target_p = find_named_client(parv[1]); | |
291 | ||
292 | /* if the nick doesnt exist, allow it and process like normal */ | |
293 | if(target_p == NULL) | |
294 | { | |
295 | change_remote_nick(client_p, source_p, newts, parv[1], 1); | |
296 | } | |
297 | else if(IsUnknown(target_p)) | |
298 | { | |
299 | exit_client(NULL, target_p, &me, "Overridden"); | |
300 | change_remote_nick(client_p, source_p, newts, parv[1], 1); | |
301 | } | |
302 | else if(target_p == source_p) | |
303 | { | |
304 | /* client changing case of nick */ | |
305 | if(strcmp(target_p->name, parv[1])) | |
306 | change_remote_nick(client_p, source_p, newts, parv[1], 1); | |
307 | } | |
308 | /* we've got a collision! */ | |
309 | else | |
310 | perform_nickchange_collides(source_p, client_p, target_p, | |
311 | parc, parv, newts, parv[1]); | |
312 | ||
313 | return 0; | |
314 | } | |
315 | ||
316 | static int | |
317 | ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
318 | { | |
319 | struct Client *target_p; | |
320 | time_t newts = 0; | |
321 | ||
322 | if(parc != 9) | |
323 | { | |
324 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
325 | "Dropping server %s due to (invalid) command 'NICK' " | |
326 | "with %d arguments (expecting 9)", client_p->name, parc); | |
327 | ilog(L_SERVER, "Excess parameters (%d) for command 'NICK' from %s.", | |
328 | parc, client_p->name); | |
329 | exit_client(client_p, client_p, client_p, "Excess parameters to NICK command"); | |
330 | return 0; | |
331 | } | |
332 | ||
333 | /* if nicks empty, erroneous, or too long, kill */ | |
334 | if(!clean_nick(parv[1], 0)) | |
335 | { | |
ad35b2cd | 336 | bad_nickname(client_p, parv[1]); |
212380e3 AC |
337 | return 0; |
338 | } | |
339 | ||
340 | /* invalid username or host? */ | |
341 | if(!clean_username(parv[5]) || !clean_host(parv[6])) | |
342 | { | |
47adde3d | 343 | ServerStats.is_kill++; |
212380e3 AC |
344 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
345 | "Bad user@host: %s@%s From: %s(via %s)", | |
346 | parv[5], parv[6], parv[7], client_p->name); | |
347 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.name, parv[1], me.name); | |
348 | return 0; | |
349 | } | |
350 | ||
351 | /* check the length of the clients gecos */ | |
352 | if(strlen(parv[8]) > REALLEN) | |
353 | { | |
354 | char *s = LOCAL_COPY(parv[8]); | |
355 | /* why exactly do we care? --fl */ | |
356 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
357 | "Long realname from server %s for %s", parv[7], parv[1]); | |
358 | ||
359 | s[REALLEN] = '\0'; | |
360 | parv[8] = s; | |
361 | } | |
362 | ||
363 | newts = atol(parv[3]); | |
364 | ||
365 | target_p = find_named_client(parv[1]); | |
366 | ||
367 | /* if the nick doesnt exist, allow it and process like normal */ | |
368 | if(target_p == NULL) | |
369 | { | |
370 | register_client(client_p, NULL, parv[1], newts, parc, parv); | |
371 | } | |
372 | else if(IsUnknown(target_p)) | |
373 | { | |
374 | exit_client(NULL, target_p, &me, "Overridden"); | |
375 | register_client(client_p, NULL, parv[1], newts, parc, parv); | |
376 | } | |
377 | else if(target_p == source_p) | |
378 | { | |
379 | /* client changing case of nick */ | |
380 | if(strcmp(target_p->name, parv[1])) | |
381 | register_client(client_p, NULL, parv[1], newts, parc, parv); | |
382 | } | |
383 | /* we've got a collision! */ | |
384 | else | |
385 | perform_nick_collides(source_p, client_p, target_p, parc, parv, | |
386 | newts, parv[1], NULL); | |
387 | ||
388 | return 0; | |
389 | } | |
390 | ||
391 | /* ms_uid() | |
392 | * parv[1] - nickname | |
393 | * parv[2] - hops | |
394 | * parv[3] - TS | |
395 | * parv[4] - umodes | |
396 | * parv[5] - username | |
397 | * parv[6] - hostname | |
398 | * parv[7] - IP | |
399 | * parv[8] - UID | |
400 | * parv[9] - gecos | |
401 | */ | |
402 | static int | |
403 | ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
404 | { | |
405 | struct Client *target_p; | |
406 | time_t newts = 0; | |
4a5655b2 | 407 | char squitreason[120]; |
212380e3 AC |
408 | |
409 | newts = atol(parv[3]); | |
410 | ||
411 | if(parc != 10) | |
412 | { | |
413 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
414 | "Dropping server %s due to (invalid) command 'UID' " | |
415 | "with %d arguments (expecting 10)", client_p->name, parc); | |
416 | ilog(L_SERVER, "Excess parameters (%d) for command 'UID' from %s.", | |
417 | parc, client_p->name); | |
418 | exit_client(client_p, client_p, client_p, "Excess parameters to UID command"); | |
419 | return 0; | |
420 | } | |
421 | ||
422 | /* if nicks erroneous, or too long, kill */ | |
423 | if(!clean_nick(parv[1], 0)) | |
424 | { | |
ad35b2cd | 425 | bad_nickname(client_p, parv[1]); |
212380e3 AC |
426 | return 0; |
427 | } | |
428 | ||
4a5655b2 | 429 | if(!clean_uid(parv[8])) |
212380e3 | 430 | { |
4a5655b2 JT |
431 | rb_snprintf(squitreason, sizeof squitreason, |
432 | "Invalid UID %s for nick %s on %s", | |
433 | parv[8], parv[1], source_p->name); | |
434 | exit_client(client_p, client_p, client_p, squitreason); | |
212380e3 AC |
435 | return 0; |
436 | } | |
437 | ||
4a5655b2 | 438 | if(!clean_username(parv[5]) || !clean_host(parv[6])) |
212380e3 | 439 | { |
47adde3d | 440 | ServerStats.is_kill++; |
212380e3 | 441 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
4a5655b2 JT |
442 | "Bad user@host: %s@%s From: %s(via %s)", |
443 | parv[5], parv[6], source_p->name, client_p->name); | |
444 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); | |
212380e3 AC |
445 | return 0; |
446 | } | |
447 | ||
448 | /* check length of clients gecos */ | |
449 | if(strlen(parv[9]) > REALLEN) | |
450 | { | |
451 | char *s = LOCAL_COPY(parv[9]); | |
452 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", | |
453 | parv[0], parv[1]); | |
454 | s[REALLEN] = '\0'; | |
455 | parv[9] = s; | |
456 | } | |
457 | ||
458 | target_p = find_named_client(parv[1]); | |
459 | ||
460 | if(target_p == NULL) | |
461 | { | |
462 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
463 | } | |
464 | else if(IsUnknown(target_p)) | |
465 | { | |
466 | exit_client(NULL, target_p, &me, "Overridden"); | |
467 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
468 | } | |
469 | /* we've got a collision! */ | |
470 | else | |
471 | perform_nick_collides(source_p, client_p, target_p, parc, parv, | |
472 | newts, parv[1], parv[8]); | |
473 | ||
474 | return 0; | |
475 | } | |
476 | ||
477 | /* ms_euid() | |
478 | * parv[1] - nickname | |
479 | * parv[2] - hops | |
480 | * parv[3] - TS | |
481 | * parv[4] - umodes | |
482 | * parv[5] - username | |
483 | * parv[6] - hostname | |
484 | * parv[7] - IP | |
485 | * parv[8] - UID | |
486 | * parv[9] - realhost | |
487 | * parv[10] - account | |
488 | * parv[11] - gecos | |
489 | */ | |
490 | static int | |
491 | ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
492 | { | |
493 | struct Client *target_p; | |
494 | time_t newts = 0; | |
4a5655b2 | 495 | char squitreason[120]; |
212380e3 AC |
496 | |
497 | newts = atol(parv[3]); | |
498 | ||
499 | if(parc != 12) | |
500 | { | |
501 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
502 | "Dropping server %s due to (invalid) command 'EUID' " | |
503 | "with %d arguments (expecting 12)", client_p->name, parc); | |
504 | ilog(L_SERVER, "Excess parameters (%d) for command 'EUID' from %s.", | |
505 | parc, client_p->name); | |
506 | exit_client(client_p, client_p, client_p, "Excess parameters to EUID command"); | |
507 | return 0; | |
508 | } | |
509 | ||
510 | /* if nicks erroneous, or too long, kill */ | |
511 | if(!clean_nick(parv[1], 0)) | |
512 | { | |
ad35b2cd | 513 | bad_nickname(client_p, parv[1]); |
212380e3 AC |
514 | return 0; |
515 | } | |
516 | ||
4a5655b2 | 517 | if(!clean_uid(parv[8])) |
212380e3 | 518 | { |
4a5655b2 JT |
519 | rb_snprintf(squitreason, sizeof squitreason, |
520 | "Invalid UID %s for nick %s on %s", | |
521 | parv[8], parv[1], source_p->name); | |
522 | exit_client(client_p, client_p, client_p, squitreason); | |
212380e3 AC |
523 | return 0; |
524 | } | |
525 | ||
4a5655b2 | 526 | if(!clean_username(parv[5]) || !clean_host(parv[6])) |
212380e3 | 527 | { |
47adde3d | 528 | ServerStats.is_kill++; |
212380e3 | 529 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
4a5655b2 JT |
530 | "Bad user@host: %s@%s From: %s(via %s)", |
531 | parv[5], parv[6], source_p->name, client_p->name); | |
532 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); | |
212380e3 AC |
533 | return 0; |
534 | } | |
535 | ||
536 | if(strcmp(parv[9], "*") && !clean_host(parv[9])) | |
537 | { | |
47adde3d | 538 | ServerStats.is_kill++; |
212380e3 AC |
539 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
540 | "Bad realhost: %s From: %s(via %s)", | |
541 | parv[9], source_p->name, client_p->name); | |
542 | sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name); | |
543 | return 0; | |
544 | } | |
545 | ||
546 | /* check length of clients gecos */ | |
547 | if(strlen(parv[11]) > REALLEN) | |
548 | { | |
549 | char *s = LOCAL_COPY(parv[11]); | |
550 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s", | |
551 | parv[0], parv[1]); | |
552 | s[REALLEN] = '\0'; | |
553 | parv[11] = s; | |
554 | } | |
555 | ||
556 | target_p = find_named_client(parv[1]); | |
557 | ||
558 | if(target_p == NULL) | |
559 | { | |
560 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
561 | } | |
562 | else if(IsUnknown(target_p)) | |
563 | { | |
564 | exit_client(NULL, target_p, &me, "Overridden"); | |
565 | register_client(client_p, source_p, parv[1], newts, parc, parv); | |
566 | } | |
567 | /* we've got a collision! */ | |
568 | else | |
569 | perform_nick_collides(source_p, client_p, target_p, parc, parv, | |
570 | newts, parv[1], parv[8]); | |
571 | ||
572 | return 0; | |
573 | } | |
574 | ||
575 | /* ms_save() | |
576 | * parv[1] - UID | |
577 | * parv[2] - TS | |
578 | */ | |
579 | static int | |
580 | ms_save(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
581 | { | |
582 | struct Client *target_p; | |
583 | ||
584 | target_p = find_id(parv[1]); | |
585 | if (target_p == NULL) | |
586 | return 0; | |
587 | if (!IsPerson(target_p)) | |
588 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
589 | "Ignored SAVE message for non-person %s from %s", | |
590 | target_p->name, source_p->name); | |
591 | else if (IsDigit(target_p->name[0])) | |
592 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
593 | "Ignored noop SAVE message for %s from %s", | |
594 | target_p->name, source_p->name); | |
595 | else if (target_p->tsinfo == atol(parv[2])) | |
596 | save_user(client_p, source_p, target_p); | |
597 | else | |
598 | sendto_realops_snomask(SNO_SKILL, L_ALL, | |
599 | "Ignored SAVE message for %s from %s", | |
600 | target_p->name, source_p->name); | |
601 | return 0; | |
602 | } | |
603 | ||
604 | /* clean_nick() | |
605 | * | |
606 | * input - nickname to check | |
607 | * output - 0 if erroneous, else 1 | |
608 | * side effects - | |
609 | */ | |
610 | static int | |
611 | clean_nick(const char *nick, int loc_client) | |
612 | { | |
613 | int len = 0; | |
614 | ||
615 | /* nicks cant start with a digit or -, and must have a length */ | |
616 | if(*nick == '-' || *nick == '\0') | |
617 | return 0; | |
618 | ||
619 | if(loc_client && IsDigit(*nick)) | |
620 | return 0; | |
621 | ||
622 | for(; *nick; nick++) | |
623 | { | |
624 | len++; | |
625 | if(!IsNickChar(*nick)) | |
626 | return 0; | |
627 | } | |
628 | ||
629 | /* nicklen is +1 */ | |
630 | if(len >= NICKLEN) | |
631 | return 0; | |
632 | ||
633 | return 1; | |
634 | } | |
635 | ||
636 | /* clean_username() | |
637 | * | |
638 | * input - username to check | |
639 | * output - 0 if erroneous, else 0 | |
640 | * side effects - | |
641 | */ | |
642 | static int | |
643 | clean_username(const char *username) | |
644 | { | |
645 | int len = 0; | |
646 | ||
647 | for(; *username; username++) | |
648 | { | |
649 | len++; | |
650 | ||
651 | if(!IsUserChar(*username)) | |
652 | return 0; | |
653 | } | |
654 | ||
655 | if(len > USERLEN) | |
656 | return 0; | |
657 | ||
658 | return 1; | |
659 | } | |
660 | ||
661 | /* clean_host() | |
662 | * | |
663 | * input - host to check | |
664 | * output - 0 if erroneous, else 0 | |
665 | * side effects - | |
666 | */ | |
667 | static int | |
668 | clean_host(const char *host) | |
669 | { | |
670 | int len = 0; | |
671 | ||
672 | for(; *host; host++) | |
673 | { | |
674 | len++; | |
675 | ||
676 | if(!IsHostChar(*host)) | |
677 | return 0; | |
678 | } | |
679 | ||
680 | if(len > HOSTLEN) | |
681 | return 0; | |
682 | ||
683 | return 1; | |
684 | } | |
685 | ||
686 | static int | |
687 | clean_uid(const char *uid) | |
688 | { | |
689 | int len = 1; | |
690 | ||
691 | if(!IsDigit(*uid++)) | |
692 | return 0; | |
693 | ||
694 | for(; *uid; uid++) | |
695 | { | |
696 | len++; | |
697 | ||
698 | if(!IsIdChar(*uid)) | |
699 | return 0; | |
700 | } | |
701 | ||
702 | if(len != IDLEN - 1) | |
703 | return 0; | |
704 | ||
705 | return 1; | |
706 | } | |
707 | ||
708 | static void | |
709 | set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) | |
710 | { | |
711 | char buf[USERLEN + 1]; | |
0e7cb7e6 | 712 | char note[NICKLEN + 10]; |
212380e3 AC |
713 | |
714 | /* This had to be copied here to avoid problems.. */ | |
e3354945 | 715 | source_p->tsinfo = rb_current_time(); |
212380e3 AC |
716 | if(source_p->name[0]) |
717 | del_from_client_hash(source_p->name, source_p); | |
718 | ||
719 | strcpy(source_p->name, nick); | |
720 | add_to_client_hash(nick, source_p); | |
721 | ||
0e7cb7e6 JT |
722 | rb_snprintf(note, sizeof(note), "Nick: %s", nick); |
723 | rb_note(client_p->localClient->F, note); | |
212380e3 AC |
724 | |
725 | if(source_p->flags & FLAGS_SENTUSER) | |
726 | { | |
f427c8b0 | 727 | rb_strlcpy(buf, source_p->username, sizeof(buf)); |
212380e3 AC |
728 | |
729 | /* got user, heres nick. */ | |
730 | register_local_user(client_p, source_p, buf); | |
731 | ||
732 | } | |
733 | } | |
734 | ||
735 | static void | |
736 | change_local_nick(struct Client *client_p, struct Client *source_p, | |
737 | char *nick, int dosend) | |
738 | { | |
739 | struct Client *target_p; | |
637c4932 | 740 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 741 | struct Channel *chptr; |
0e7cb7e6 | 742 | char note[NICKLEN + 10]; |
212380e3 AC |
743 | int samenick; |
744 | ||
745 | if (dosend) | |
746 | { | |
747 | chptr = find_bannickchange_channel(source_p); | |
748 | if (chptr != NULL) | |
749 | { | |
750 | sendto_one_numeric(source_p, ERR_BANNICKCHANGE, | |
751 | form_str(ERR_BANNICKCHANGE), | |
752 | nick, chptr->chname); | |
753 | return; | |
754 | } | |
e3354945 | 755 | if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < rb_current_time()) |
212380e3 AC |
756 | source_p->localClient->number_of_nick_changes = 0; |
757 | ||
e3354945 | 758 | source_p->localClient->last_nick_change = rb_current_time(); |
212380e3 AC |
759 | source_p->localClient->number_of_nick_changes++; |
760 | ||
761 | if(ConfigFileEntry.anti_nick_flood && !IsOper(source_p) && | |
762 | source_p->localClient->number_of_nick_changes > ConfigFileEntry.max_nick_changes) | |
763 | { | |
764 | sendto_one(source_p, form_str(ERR_NICKTOOFAST), | |
765 | me.name, source_p->name, source_p->name, | |
766 | nick, ConfigFileEntry.max_nick_time); | |
767 | return; | |
768 | } | |
769 | } | |
770 | ||
771 | samenick = irccmp(source_p->name, nick) ? 0 : 1; | |
772 | ||
773 | /* dont reset TS if theyre just changing case of nick */ | |
774 | if(!samenick) | |
775 | { | |
95ffa685 | 776 | /* force the TS to increase -- jilles */ |
e3354945 | 777 | if (source_p->tsinfo >= rb_current_time()) |
95ffa685 JT |
778 | source_p->tsinfo++; |
779 | else | |
e3354945 | 780 | source_p->tsinfo = rb_current_time(); |
212380e3 AC |
781 | monitor_signoff(source_p); |
782 | /* we only do bancache for local users -- jilles */ | |
783 | if(source_p->user) | |
784 | invalidate_bancache_user(source_p); | |
785 | } | |
786 | ||
787 | sendto_realops_snomask(SNO_NCHANGE, L_ALL, | |
788 | "Nick change: From %s to %s [%s@%s]", | |
789 | source_p->name, nick, source_p->username, source_p->host); | |
790 | ||
791 | /* send the nick change to the users channels */ | |
792 | sendto_common_channels_local(source_p, ":%s!%s@%s NICK :%s", | |
793 | source_p->name, source_p->username, source_p->host, nick); | |
794 | ||
795 | /* send the nick change to servers.. */ | |
796 | if(source_p->user) | |
797 | { | |
798 | add_history(source_p, 1); | |
799 | ||
800 | if (dosend) | |
801 | { | |
802 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", | |
803 | use_id(source_p), nick, (long) source_p->tsinfo); | |
212380e3 AC |
804 | } |
805 | } | |
806 | ||
807 | /* Finally, add to hash */ | |
808 | del_from_client_hash(source_p->name, source_p); | |
809 | strcpy(source_p->name, nick); | |
810 | add_to_client_hash(nick, source_p); | |
811 | ||
812 | if(!samenick) | |
813 | monitor_signon(source_p); | |
814 | ||
815 | /* Make sure everyone that has this client on its accept list | |
816 | * loses that reference. | |
817 | */ | |
818 | /* we used to call del_all_accepts() here, but theres no real reason | |
819 | * to clear a clients own list of accepted clients. So just remove | |
820 | * them from everyone elses list --anfl | |
821 | */ | |
637c4932 | 822 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) |
212380e3 AC |
823 | { |
824 | target_p = ptr->data; | |
825 | ||
555ac41f JT |
826 | rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list); |
827 | rb_dlinkDestroy(ptr, &source_p->on_allow_list); | |
212380e3 AC |
828 | } |
829 | ||
0e7cb7e6 JT |
830 | rb_snprintf(note, sizeof(note), "Nick: %s", nick); |
831 | rb_note(client_p->localClient->F, note); | |
212380e3 AC |
832 | |
833 | return; | |
834 | } | |
835 | ||
836 | /* | |
837 | * change_remote_nick() | |
838 | */ | |
839 | static int | |
840 | change_remote_nick(struct Client *client_p, struct Client *source_p, | |
841 | time_t newts, const char *nick, int dosend) | |
842 | { | |
843 | struct nd_entry *nd; | |
844 | int samenick = irccmp(source_p->name, nick) ? 0 : 1; | |
845 | ||
846 | /* client changing their nick - dont reset ts if its same */ | |
847 | if(!samenick) | |
848 | { | |
e3354945 | 849 | source_p->tsinfo = newts ? newts : rb_current_time(); |
212380e3 AC |
850 | monitor_signoff(source_p); |
851 | } | |
852 | ||
853 | sendto_common_channels_local(source_p, ":%s!%s@%s NICK :%s", | |
854 | source_p->name, source_p->username, source_p->host, nick); | |
855 | ||
856 | if(source_p->user) | |
857 | { | |
858 | add_history(source_p, 1); | |
859 | if (dosend) | |
860 | { | |
861 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld", | |
862 | use_id(source_p), nick, (long) source_p->tsinfo); | |
212380e3 AC |
863 | } |
864 | } | |
865 | ||
866 | del_from_client_hash(source_p->name, source_p); | |
867 | ||
868 | /* invalidate nick delay when a remote client uses the nick.. */ | |
b37021a4 | 869 | if((nd = irc_dictionary_retrieve(nd_dict, nick))) |
212380e3 AC |
870 | free_nd_entry(nd); |
871 | ||
872 | strcpy(source_p->name, nick); | |
873 | add_to_client_hash(nick, source_p); | |
874 | ||
875 | if(!samenick) | |
876 | monitor_signon(source_p); | |
877 | ||
878 | /* remove all accepts pointing to the client */ | |
879 | del_all_accepts(source_p); | |
880 | ||
881 | return 0; | |
882 | } | |
883 | ||
884 | static int | |
885 | perform_nick_collides(struct Client *source_p, struct Client *client_p, | |
886 | struct Client *target_p, int parc, const char *parv[], | |
887 | time_t newts, const char *nick, const char *uid) | |
888 | { | |
889 | int sameuser; | |
890 | int use_save; | |
891 | const char *action; | |
892 | ||
893 | use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && | |
894 | uid != NULL && can_save(source_p); | |
895 | action = use_save ? "saved" : "killed"; | |
896 | ||
897 | /* if we dont have a ts, or their TS's are the same, kill both */ | |
898 | if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo)) | |
899 | { | |
9d107a71 | 900 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
901 | "Nick collision on %s(%s <- %s)(both %s)", |
902 | target_p->name, target_p->from->name, client_p->name, action); | |
903 | ||
904 | if (use_save) | |
905 | { | |
906 | save_user(&me, &me, target_p); | |
47adde3d | 907 | ServerStats.is_save++; |
212380e3 AC |
908 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, |
909 | uid, (long)newts); | |
910 | register_client(client_p, source_p, | |
3f7e0642 | 911 | uid, SAVE_NICKTS, parc, parv); |
212380e3 AC |
912 | } |
913 | else | |
914 | { | |
915 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, | |
916 | form_str(ERR_NICKCOLLISION), target_p->name); | |
917 | ||
918 | /* if the new client being introduced has a UID, we need to | |
919 | * issue a KILL for it.. | |
920 | */ | |
921 | if(uid) | |
922 | sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))", | |
923 | me.id, uid, me.name); | |
924 | ||
925 | /* we then need to KILL the old client everywhere */ | |
926 | kill_client_serv_butone(NULL, target_p, "%s (Nick collision (new))", me.name); | |
47adde3d | 927 | ServerStats.is_kill++; |
212380e3 AC |
928 | |
929 | target_p->flags |= FLAGS_KILLED; | |
930 | exit_client(client_p, target_p, &me, "Nick collision (new)"); | |
931 | } | |
932 | return 0; | |
933 | } | |
934 | /* the timestamps are different */ | |
935 | else | |
936 | { | |
937 | sameuser = (target_p->user) && !irccmp(target_p->username, parv[5]) | |
938 | && !irccmp(target_p->host, parv[6]); | |
939 | ||
940 | if((sameuser && newts < target_p->tsinfo) || | |
941 | (!sameuser && newts > target_p->tsinfo)) | |
942 | { | |
943 | /* if we have a UID, then we need to issue a KILL, | |
944 | * otherwise we do nothing and hope that the other | |
945 | * client will collide it.. | |
946 | */ | |
947 | if (use_save) | |
948 | { | |
949 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, | |
950 | uid, (long)newts); | |
951 | register_client(client_p, source_p, | |
3f7e0642 | 952 | uid, SAVE_NICKTS, parc, parv); |
212380e3 AC |
953 | } |
954 | else if(uid) | |
955 | sendto_one(client_p, | |
956 | ":%s KILL %s :%s (Nick collision (new))", | |
957 | me.id, uid, me.name); | |
958 | return 0; | |
959 | } | |
960 | else | |
961 | { | |
962 | if(sameuser) | |
9d107a71 | 963 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
964 | "Nick collision on %s(%s <- %s)(older %s)", |
965 | target_p->name, target_p->from->name, | |
966 | client_p->name, action); | |
967 | else | |
9d107a71 | 968 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
969 | "Nick collision on %s(%s <- %s)(newer %s)", |
970 | target_p->name, target_p->from->name, | |
971 | client_p->name, action); | |
972 | ||
973 | if (use_save) | |
974 | { | |
47adde3d | 975 | ServerStats.is_save++; |
212380e3 AC |
976 | save_user(&me, &me, target_p); |
977 | } | |
978 | else | |
979 | { | |
47adde3d | 980 | ServerStats.is_kill++; |
212380e3 AC |
981 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, |
982 | form_str(ERR_NICKCOLLISION), target_p->name); | |
983 | ||
984 | /* now we just need to kill the existing client */ | |
985 | kill_client_serv_butone(client_p, target_p, | |
986 | "%s (Nick collision (new))", me.name); | |
987 | ||
988 | target_p->flags |= FLAGS_KILLED; | |
989 | (void) exit_client(client_p, target_p, &me, "Nick collision"); | |
990 | } | |
991 | ||
992 | register_client(client_p, parc >= 10 ? source_p : NULL, | |
993 | nick, newts, parc, parv); | |
994 | ||
995 | return 0; | |
996 | } | |
997 | } | |
998 | } | |
999 | ||
1000 | ||
1001 | static int | |
1002 | perform_nickchange_collides(struct Client *source_p, struct Client *client_p, | |
1003 | struct Client *target_p, int parc, | |
1004 | const char *parv[], time_t newts, const char *nick) | |
1005 | { | |
1006 | int sameuser; | |
1007 | int use_save; | |
1008 | const char *action; | |
1009 | ||
1010 | use_save = ConfigFileEntry.collision_fnc && can_save(target_p) && | |
1011 | can_save(source_p); | |
1012 | action = use_save ? "saved" : "killed"; | |
1013 | ||
1014 | /* its a client changing nick and causing a collide */ | |
1015 | if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user) | |
1016 | { | |
9d107a71 | 1017 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
1018 | "Nick change collision from %s to %s(%s <- %s)(both %s)", |
1019 | source_p->name, target_p->name, target_p->from->name, | |
1020 | client_p->name, action); | |
1021 | ||
1022 | if (use_save) | |
1023 | { | |
47adde3d | 1024 | ServerStats.is_save += 2; |
212380e3 AC |
1025 | save_user(&me, &me, target_p); |
1026 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, | |
1027 | source_p->id, (long)newts); | |
1028 | /* don't send a redundant nick change */ | |
1029 | if (!IsDigit(source_p->name[0])) | |
3f7e0642 | 1030 | change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); |
212380e3 AC |
1031 | } |
1032 | else | |
1033 | { | |
47adde3d | 1034 | ServerStats.is_kill++; |
212380e3 AC |
1035 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, |
1036 | form_str(ERR_NICKCOLLISION), target_p->name); | |
1037 | ||
1038 | kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); | |
1039 | ||
47adde3d | 1040 | ServerStats.is_kill++; |
212380e3 AC |
1041 | |
1042 | kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); | |
1043 | ||
1044 | target_p->flags |= FLAGS_KILLED; | |
1045 | exit_client(NULL, target_p, &me, "Nick collision(new)"); | |
1046 | source_p->flags |= FLAGS_KILLED; | |
1047 | exit_client(client_p, source_p, &me, "Nick collision(old)"); | |
1048 | } | |
1049 | return 0; | |
1050 | } | |
1051 | else | |
1052 | { | |
1053 | sameuser = !irccmp(target_p->username, source_p->username) && | |
1054 | !irccmp(target_p->host, source_p->host); | |
1055 | ||
1056 | if((sameuser && newts < target_p->tsinfo) || | |
1057 | (!sameuser && newts > target_p->tsinfo)) | |
1058 | { | |
1059 | if(sameuser) | |
9d107a71 | 1060 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
1061 | "Nick change collision from %s to %s(%s <- %s)(older %s)", |
1062 | source_p->name, target_p->name, | |
1063 | target_p->from->name, client_p->name, action); | |
1064 | else | |
9d107a71 | 1065 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
1066 | "Nick change collision from %s to %s(%s <- %s)(newer %s)", |
1067 | source_p->name, target_p->name, | |
1068 | target_p->from->name, client_p->name, action); | |
1069 | ||
1070 | if (use_save) | |
1071 | { | |
47adde3d | 1072 | ServerStats.is_save++; |
212380e3 AC |
1073 | /* can't broadcast a SAVE because the |
1074 | * nickchange has happened at client_p | |
1075 | * but not in other directions -- jilles */ | |
1076 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, | |
1077 | source_p->id, (long)newts); | |
212380e3 AC |
1078 | /* send a :<id> NICK <id> <ts> (!) */ |
1079 | if (!IsDigit(source_p->name[0])) | |
3f7e0642 | 1080 | change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); |
212380e3 AC |
1081 | } |
1082 | else | |
1083 | { | |
47adde3d | 1084 | ServerStats.is_kill++; |
212380e3 AC |
1085 | |
1086 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, | |
1087 | form_str(ERR_NICKCOLLISION), target_p->name); | |
1088 | ||
1089 | /* kill the client issuing the nickchange */ | |
1090 | kill_client_serv_butone(client_p, source_p, | |
1091 | "%s (Nick change collision)", me.name); | |
1092 | ||
1093 | source_p->flags |= FLAGS_KILLED; | |
1094 | ||
1095 | if(sameuser) | |
1096 | exit_client(client_p, source_p, &me, "Nick collision(old)"); | |
1097 | else | |
1098 | exit_client(client_p, source_p, &me, "Nick collision(new)"); | |
1099 | } | |
1100 | return 0; | |
1101 | } | |
1102 | else | |
1103 | { | |
1104 | if(sameuser) | |
9d107a71 | 1105 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
1106 | "Nick collision on %s(%s <- %s)(older %s)", |
1107 | target_p->name, target_p->from->name, | |
1108 | client_p->name, action); | |
1109 | else | |
9d107a71 | 1110 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
1111 | "Nick collision on %s(%s <- %s)(newer %s)", |
1112 | target_p->name, target_p->from->name, | |
1113 | client_p->name, action); | |
1114 | ||
1115 | if (use_save) | |
1116 | { | |
47adde3d | 1117 | ServerStats.is_save++; |
212380e3 AC |
1118 | save_user(&me, &me, target_p); |
1119 | } | |
1120 | else | |
1121 | { | |
1122 | sendto_one_numeric(target_p, ERR_NICKCOLLISION, | |
1123 | form_str(ERR_NICKCOLLISION), target_p->name); | |
1124 | ||
1125 | /* kill the client who existed before hand */ | |
1126 | kill_client_serv_butone(client_p, target_p, "%s (Nick collision)", me.name); | |
1127 | ||
47adde3d | 1128 | ServerStats.is_kill++; |
212380e3 AC |
1129 | |
1130 | target_p->flags |= FLAGS_KILLED; | |
1131 | (void) exit_client(client_p, target_p, &me, "Nick collision"); | |
1132 | } | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | change_remote_nick(client_p, source_p, newts, nick, 1); | |
1137 | ||
1138 | return 0; | |
1139 | } | |
1140 | ||
1141 | static int | |
1142 | register_client(struct Client *client_p, struct Client *server, | |
1143 | const char *nick, time_t newts, int parc, const char *parv[]) | |
1144 | { | |
1145 | struct Client *source_p; | |
1146 | struct User *user; | |
1147 | struct nd_entry *nd; | |
1148 | const char *m; | |
1149 | int flag; | |
1150 | ||
64449595 JT |
1151 | if(server == NULL) |
1152 | { | |
1153 | if((server = find_server(NULL, parv[7])) == NULL) | |
1154 | { | |
1155 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1156 | "Ghost killed: %s on invalid server %s", | |
1157 | nick, parv[7]); | |
1158 | sendto_one(client_p, ":%s KILL %s :%s (Server doesn't exist)", | |
1159 | get_id(&me, client_p), nick, me.name); | |
1160 | return 0; | |
1161 | } | |
1162 | } | |
1163 | ||
212380e3 AC |
1164 | source_p = make_client(client_p); |
1165 | user = make_user(source_p); | |
0e7cb7e6 | 1166 | rb_dlinkAddTail(source_p, &source_p->node, &global_client_list); |
212380e3 AC |
1167 | |
1168 | source_p->hopcount = atoi(parv[2]); | |
1169 | source_p->tsinfo = newts; | |
1170 | ||
1171 | strcpy(source_p->name, nick); | |
f427c8b0 VY |
1172 | rb_strlcpy(source_p->username, parv[5], sizeof(source_p->username)); |
1173 | rb_strlcpy(source_p->host, parv[6], sizeof(source_p->host)); | |
1174 | rb_strlcpy(source_p->orighost, source_p->host, sizeof(source_p->orighost)); | |
212380e3 AC |
1175 | |
1176 | if(parc == 12) | |
1177 | { | |
f427c8b0 VY |
1178 | rb_strlcpy(source_p->info, parv[11], sizeof(source_p->info)); |
1179 | rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); | |
1180 | rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); | |
212380e3 AC |
1181 | add_to_id_hash(source_p->id, source_p); |
1182 | if (strcmp(parv[9], "*")) | |
1183 | { | |
f427c8b0 | 1184 | rb_strlcpy(source_p->orighost, parv[9], sizeof(source_p->orighost)); |
212380e3 AC |
1185 | if (irccmp(source_p->host, source_p->orighost)) |
1186 | SetDynSpoof(source_p); | |
1187 | } | |
1188 | if (strcmp(parv[10], "*")) | |
f427c8b0 | 1189 | rb_strlcpy(source_p->user->suser, parv[10], sizeof(source_p->user->suser)); |
212380e3 AC |
1190 | } |
1191 | else if(parc == 10) | |
1192 | { | |
f427c8b0 VY |
1193 | rb_strlcpy(source_p->info, parv[9], sizeof(source_p->info)); |
1194 | rb_strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); | |
1195 | rb_strlcpy(source_p->id, parv[8], sizeof(source_p->id)); | |
212380e3 AC |
1196 | add_to_id_hash(source_p->id, source_p); |
1197 | } | |
1198 | else | |
1199 | { | |
f427c8b0 | 1200 | rb_strlcpy(source_p->info, parv[8], sizeof(source_p->info)); |
212380e3 AC |
1201 | } |
1202 | ||
1203 | /* remove any nd entries for this nick */ | |
b37021a4 | 1204 | if((nd = irc_dictionary_retrieve(nd_dict, nick))) |
212380e3 AC |
1205 | free_nd_entry(nd); |
1206 | ||
1207 | add_to_client_hash(nick, source_p); | |
66b4a7ae | 1208 | add_to_hostname_hash(source_p->orighost, source_p); |
212380e3 AC |
1209 | monitor_signon(source_p); |
1210 | ||
1211 | m = &parv[4][1]; | |
1212 | while(*m) | |
1213 | { | |
1214 | flag = user_modes[(unsigned char) *m]; | |
1215 | ||
1216 | if(flag & UMODE_SERVICE) | |
1217 | { | |
1218 | int hit = 0; | |
5b96d9a6 | 1219 | rb_dlink_node *ptr; |
212380e3 | 1220 | |
5b96d9a6 | 1221 | RB_DLINK_FOREACH(ptr, service_list.head) |
212380e3 | 1222 | { |
c88cdb00 | 1223 | if(!irccmp((const char *) ptr->data, server->name)) |
212380e3 AC |
1224 | { |
1225 | hit++; | |
1226 | break; | |
1227 | } | |
1228 | } | |
1229 | ||
1230 | if(!hit) | |
1231 | { | |
1232 | m++; | |
1233 | continue; | |
1234 | } | |
1235 | } | |
1236 | ||
1237 | /* increment +i count if theyre invis */ | |
1238 | if(!(source_p->umodes & UMODE_INVISIBLE) && (flag & UMODE_INVISIBLE)) | |
1239 | Count.invisi++; | |
1240 | ||
1241 | /* increment opered count if theyre opered */ | |
1242 | if(!(source_p->umodes & UMODE_OPER) && (flag & UMODE_OPER)) | |
1243 | Count.oper++; | |
1244 | ||
1245 | source_p->umodes |= flag; | |
1246 | m++; | |
1247 | } | |
1248 | ||
1249 | if(IsOper(source_p) && !IsService(source_p)) | |
0e7cb7e6 | 1250 | rb_dlinkAddAlloc(source_p, &oper_list); |
212380e3 AC |
1251 | |
1252 | SetRemoteClient(source_p); | |
1253 | ||
1254 | if(++Count.total > Count.max_tot) | |
1255 | Count.max_tot = Count.total; | |
1256 | ||
64449595 | 1257 | source_p->servptr = server; |
212380e3 | 1258 | |
0e7cb7e6 | 1259 | rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); |
212380e3 AC |
1260 | |
1261 | /* fake direction */ | |
1262 | if(source_p->servptr->from != source_p->from) | |
1263 | { | |
1264 | struct Client *target_p = source_p->servptr->from; | |
1265 | ||
1266 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
1267 | "Bad User [%s] :%s USER %s@%s %s, != %s[%s]", | |
1268 | client_p->name, source_p->name, | |
1269 | source_p->username, source_p->host, | |
c88cdb00 | 1270 | server->name, target_p->name, target_p->from->name); |
212380e3 AC |
1271 | kill_client(client_p, source_p, |
1272 | "%s (NICK from wrong direction (%s != %s))", | |
c88cdb00 | 1273 | me.name, server->name, target_p->from->name); |
212380e3 AC |
1274 | source_p->flags |= FLAGS_KILLED; |
1275 | return exit_client(source_p, source_p, &me, "USER server wrong direction"); | |
1276 | } | |
1277 | ||
1278 | call_hook(h_new_remote_user, source_p); | |
1279 | ||
1280 | return (introduce_client(client_p, source_p, user, nick, parc == 12)); | |
1281 | } | |
1282 | ||
1283 | /* Check if we can do SAVE. target_p can be a client to save or a | |
1284 | * server introducing a client -- jilles */ | |
1285 | static int | |
1286 | can_save(struct Client *target_p) | |
1287 | { | |
1288 | struct Client *serv_p; | |
1289 | ||
1290 | if (MyClient(target_p)) | |
1291 | return 1; | |
1292 | if (!has_id(target_p)) | |
1293 | return 0; | |
1294 | serv_p = IsServer(target_p) ? target_p : target_p->servptr; | |
1295 | while (serv_p != NULL && serv_p != &me) | |
1296 | { | |
1297 | if (!(serv_p->serv->caps & CAP_SAVE)) | |
1298 | return 0; | |
1299 | serv_p = serv_p->servptr; | |
1300 | } | |
1301 | return serv_p == &me; | |
1302 | } | |
1303 | ||
1304 | static void | |
1305 | save_user(struct Client *client_p, struct Client *source_p, | |
1306 | struct Client *target_p) | |
1307 | { | |
1308 | if (!MyConnect(target_p) && (!has_id(target_p) || !IsCapable(target_p->from, CAP_SAVE))) | |
1309 | { | |
1310 | /* This shouldn't happen */ | |
1311 | /* Note we only need SAVE support in this direction */ | |
1312 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1313 | "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)", | |
1314 | target_p->name, target_p->username, target_p->host, source_p->name, target_p->from->name); | |
1315 | kill_client_serv_butone(NULL, target_p, "%s (Nick collision (no SAVE support))", me.name); | |
47adde3d | 1316 | ServerStats.is_kill++; |
212380e3 AC |
1317 | |
1318 | target_p->flags |= FLAGS_KILLED; | |
1319 | (void) exit_client(NULL, target_p, &me, "Nick collision (no SAVE support)"); | |
1320 | return; | |
1321 | } | |
1322 | sendto_server(client_p, NULL, CAP_SAVE|CAP_TS6, NOCAPS, ":%s SAVE %s %ld", | |
1323 | source_p->id, target_p->id, (long)target_p->tsinfo); | |
1324 | sendto_server(client_p, NULL, CAP_TS6, CAP_SAVE, ":%s NICK %s :%ld", | |
3f7e0642 | 1325 | target_p->id, target_p->id, (long)SAVE_NICKTS); |
212380e3 AC |
1326 | if (!IsMe(client_p)) |
1327 | sendto_realops_snomask(SNO_SKILL, L_ALL, | |
1328 | "Received SAVE message for %s from %s", | |
1329 | target_p->name, source_p->name); | |
1330 | if (MyClient(target_p)) | |
1331 | { | |
1332 | sendto_one_numeric(target_p, RPL_SAVENICK, | |
1333 | form_str(RPL_SAVENICK), target_p->id); | |
1334 | change_local_nick(target_p, target_p, target_p->id, 0); | |
3f7e0642 | 1335 | target_p->tsinfo = SAVE_NICKTS; |
212380e3 AC |
1336 | } |
1337 | else | |
3f7e0642 | 1338 | change_remote_nick(target_p, target_p, SAVE_NICKTS, target_p->id, 0); |
212380e3 | 1339 | } |
ad35b2cd JT |
1340 | |
1341 | static void bad_nickname(struct Client *client_p, const char *nick) | |
1342 | { | |
1343 | char squitreason[100]; | |
1344 | ||
1345 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
1346 | "Squitting %s because of bad nickname %s (NICKLEN mismatch?)", | |
1347 | client_p->name, nick); | |
1348 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, | |
1349 | ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)", | |
1350 | me.id, client_p->name, nick); | |
ad35b2cd JT |
1351 | |
1352 | rb_snprintf(squitreason, sizeof squitreason, | |
1353 | "Bad nickname introduced [%s]", nick); | |
1354 | exit_client(client_p, client_p, &me, squitreason); | |
1355 | } |