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