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