]>
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 | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "client.h" | |
27 | #include "hash.h" | |
4562c604 | 28 | #include "match.h" |
212380e3 AC |
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" | |
4016731b | 39 | #include "logger.h" |
212380e3 AC |
40 | #include "msg.h" |
41 | #include "parse.h" | |
42 | #include "modules.h" | |
212380e3 AC |
43 | #include "packet.h" |
44 | #include "scache.h" | |
45 | #include "s_newconf.h" | |
46 | #include "monitor.h" | |
77d3d2db | 47 | #include "s_assert.h" |
212380e3 | 48 | |
3f7e0642 JT |
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 | ||
3c7d6fcc EM |
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 *); | |
212380e3 | 64 | static void save_user(struct Client *, struct Client *, struct Client *); |
ad35b2cd | 65 | static void bad_nickname(struct Client *, const char *); |
3c7d6fcc EM |
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 *); | |
212380e3 | 81 | |
f32b9ebd SB |
82 | static int h_local_nick_change; |
83 | static int h_remote_nick_change; | |
84 | ||
212380e3 | 85 | struct Message nick_msgtab = { |
7baa37a9 | 86 | "NICK", 0, 0, 0, 0, |
6c77f1f7 | 87 | {{mr_nick, 0}, {m_nick, 0}, {mc_nick, 3}, {ms_nick, 0}, mg_ignore, {m_nick, 0}} |
212380e3 AC |
88 | }; |
89 | struct Message uid_msgtab = { | |
7baa37a9 | 90 | "UID", 0, 0, 0, 0, |
212380e3 AC |
91 | {mg_ignore, mg_ignore, mg_ignore, {ms_uid, 9}, mg_ignore, mg_ignore} |
92 | }; | |
93 | struct Message euid_msgtab = { | |
7baa37a9 | 94 | "EUID", 0, 0, 0, 0, |
212380e3 AC |
95 | {mg_ignore, mg_ignore, mg_ignore, {ms_euid, 12}, mg_ignore, mg_ignore} |
96 | }; | |
97 | struct Message save_msgtab = { | |
7baa37a9 | 98 | "SAVE", 0, 0, 0, 0, |
212380e3 AC |
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 | ||
f32b9ebd SB |
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 | ||
ee6dcb05 EM |
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 | ||
f32b9ebd | 114 | DECLARE_MODULE_AV2(nick, NULL, NULL, nick_clist, nick_hlist, NULL, NULL, NULL, nick_desc); |
212380e3 | 115 | |
212380e3 | 116 | /* mr_nick() |
212380e3 AC |
117 | * parv[1] = nickname |
118 | */ | |
3c7d6fcc | 119 | static void |
428ca87b | 120 | mr_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
121 | { |
122 | struct Client *target_p; | |
123 | char nick[NICKLEN]; | |
212380e3 | 124 | |
d5d52a99 | 125 | if (strlen(client_p->id) == 3 || (source_p->preClient && !EmptyString(source_p->preClient->id))) |
212380e3 AC |
126 | { |
127 | exit_client(client_p, client_p, client_p, "Mixing client and server protocol"); | |
3c7d6fcc | 128 | return; |
212380e3 AC |
129 | } |
130 | ||
fda96b89 | 131 | if(parc < 2 || EmptyString(parv[1])) |
212380e3 AC |
132 | { |
133 | sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), | |
134 | me.name, EmptyString(source_p->name) ? "*" : source_p->name); | |
3c7d6fcc | 135 | return; |
212380e3 AC |
136 | } |
137 | ||
212380e3 | 138 | /* copy the nick and terminate it */ |
b583faf9 | 139 | rb_strlcpy(nick, parv[1], ConfigFileEntry.nicklen); |
212380e3 AC |
140 | |
141 | /* check the nickname is ok */ | |
142 | if(!clean_nick(nick, 1)) | |
143 | { | |
144 | sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), | |
3dfaa671 | 145 | me.name, EmptyString(source_p->name) ? "*" : source_p->name, parv[1]); |
3c7d6fcc | 146 | return; |
212380e3 AC |
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); | |
3c7d6fcc | 154 | return; |
212380e3 AC |
155 | } |
156 | ||
a4bf26dd | 157 | if(rb_dictionary_find(nd_dict, nick)) |
212380e3 AC |
158 | { |
159 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
160 | me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); | |
3c7d6fcc | 161 | return; |
212380e3 AC |
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) | |
4d5a902f | 167 | rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); |
212380e3 AC |
168 | else |
169 | sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick); | |
212380e3 AC |
170 | } |
171 | ||
172 | /* m_nick() | |
212380e3 AC |
173 | * parv[1] = nickname |
174 | */ | |
3c7d6fcc | 175 | static void |
428ca87b | 176 | m_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
177 | { |
178 | struct Client *target_p; | |
179 | char nick[NICKLEN]; | |
212380e3 | 180 | |
fda96b89 | 181 | if(parc < 2 || EmptyString(parv[1])) |
212380e3 AC |
182 | { |
183 | sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name); | |
3c7d6fcc | 184 | return; |
212380e3 AC |
185 | } |
186 | ||
212380e3 AC |
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! */ | |
b583faf9 | 192 | rb_strlcpy(nick, parv[1], ConfigFileEntry.nicklen); |
212380e3 AC |
193 | |
194 | /* check the nickname is ok */ | |
195 | if(!clean_nick(nick, 1)) | |
196 | { | |
3dfaa671 | 197 | sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, source_p->name, nick); |
3c7d6fcc | 198 | return; |
212380e3 AC |
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); | |
3c7d6fcc | 204 | return; |
212380e3 AC |
205 | } |
206 | ||
a4bf26dd | 207 | if(rb_dictionary_find(nd_dict, nick)) |
212380e3 AC |
208 | { |
209 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
210 | me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick); | |
3c7d6fcc | 211 | return; |
212380e3 AC |
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 | |
3dfaa671 | 234 | sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, source_p->name, nick); |
212380e3 | 235 | |
3c7d6fcc | 236 | return; |
212380e3 AC |
237 | } |
238 | else | |
239 | change_local_nick(client_p, source_p, nick, 1); | |
212380e3 AC |
240 | } |
241 | ||
6c77f1f7 | 242 | /* mc_nick() |
55abcbb2 | 243 | * |
212380e3 | 244 | * server -> server nick change |
212380e3 AC |
245 | * parv[1] = nickname |
246 | * parv[2] = TS when nick change | |
212380e3 | 247 | */ |
3c7d6fcc | 248 | static void |
428ca87b | 249 | mc_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
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 | { | |
ad35b2cd | 257 | bad_nickname(client_p, parv[1]); |
3c7d6fcc | 258 | return; |
212380e3 AC |
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]); | |
212380e3 AC |
284 | } |
285 | ||
3c7d6fcc | 286 | static void |
428ca87b | 287 | ms_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 288 | { |
6c77f1f7 | 289 | const char *nick, *server; |
212380e3 | 290 | |
6c77f1f7 JT |
291 | nick = parc > 1 ? parv[1] : "?"; |
292 | server = parc > 7 ? parv[7] : "?"; | |
212380e3 | 293 | |
6c77f1f7 JT |
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); | |
212380e3 | 302 | |
6c77f1f7 | 303 | exit_client(client_p, client_p, &me, "TS5 nickname introduced"); |
212380e3 AC |
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 | */ | |
3c7d6fcc | 317 | static void |
428ca87b | 318 | ms_uid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
319 | { |
320 | struct Client *target_p; | |
321 | time_t newts = 0; | |
4a5655b2 | 322 | char squitreason[120]; |
212380e3 AC |
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); | |
5203cba5 | 333 | snprintf(squitreason, sizeof squitreason, |
56023eb2 JT |
334 | "Excess parameters (%d) to %s command, expecting %d", |
335 | parc, "UID", 10); | |
336 | exit_client(client_p, client_p, client_p, squitreason); | |
3c7d6fcc | 337 | return; |
212380e3 AC |
338 | } |
339 | ||
340 | /* if nicks erroneous, or too long, kill */ | |
341 | if(!clean_nick(parv[1], 0)) | |
342 | { | |
ad35b2cd | 343 | bad_nickname(client_p, parv[1]); |
3c7d6fcc | 344 | return; |
212380e3 AC |
345 | } |
346 | ||
561d7efc | 347 | if(!clean_uid(parv[8], source_p->id)) |
212380e3 | 348 | { |
5203cba5 | 349 | snprintf(squitreason, sizeof squitreason, |
e0c7937a JT |
350 | "Invalid UID %s for nick %s on %s/%s", |
351 | parv[8], parv[1], source_p->name, source_p->id); | |
4a5655b2 | 352 | exit_client(client_p, client_p, client_p, squitreason); |
3c7d6fcc | 353 | return; |
212380e3 AC |
354 | } |
355 | ||
4a5655b2 | 356 | if(!clean_username(parv[5]) || !clean_host(parv[6])) |
212380e3 | 357 | { |
47adde3d | 358 | ServerStats.is_kill++; |
212380e3 | 359 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
4a5655b2 JT |
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); | |
3c7d6fcc | 363 | return; |
212380e3 AC |
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", | |
3dfaa671 | 371 | source_p->name, parv[1]); |
212380e3 AC |
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]); | |
212380e3 AC |
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 | */ | |
3c7d6fcc | 406 | static void |
428ca87b | 407 | ms_euid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
408 | { |
409 | struct Client *target_p; | |
410 | time_t newts = 0; | |
4a5655b2 | 411 | char squitreason[120]; |
212380e3 AC |
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); | |
5203cba5 | 422 | snprintf(squitreason, sizeof squitreason, |
56023eb2 JT |
423 | "Excess parameters (%d) to %s command, expecting %d", |
424 | parc, "EUID", 12); | |
425 | exit_client(client_p, client_p, client_p, squitreason); | |
3c7d6fcc | 426 | return; |
212380e3 AC |
427 | } |
428 | ||
429 | /* if nicks erroneous, or too long, kill */ | |
430 | if(!clean_nick(parv[1], 0)) | |
431 | { | |
ad35b2cd | 432 | bad_nickname(client_p, parv[1]); |
3c7d6fcc | 433 | return; |
212380e3 AC |
434 | } |
435 | ||
561d7efc | 436 | if(!clean_uid(parv[8], source_p->id)) |
212380e3 | 437 | { |
5203cba5 | 438 | snprintf(squitreason, sizeof squitreason, |
e0c7937a JT |
439 | "Invalid UID %s for nick %s on %s/%s", |
440 | parv[8], parv[1], source_p->name, source_p->id); | |
4a5655b2 | 441 | exit_client(client_p, client_p, client_p, squitreason); |
3c7d6fcc | 442 | return; |
212380e3 AC |
443 | } |
444 | ||
4a5655b2 | 445 | if(!clean_username(parv[5]) || !clean_host(parv[6])) |
212380e3 | 446 | { |
47adde3d | 447 | ServerStats.is_kill++; |
212380e3 | 448 | sendto_realops_snomask(SNO_DEBUG, L_ALL, |
4a5655b2 JT |
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); | |
3c7d6fcc | 452 | return; |
212380e3 AC |
453 | } |
454 | ||
455 | if(strcmp(parv[9], "*") && !clean_host(parv[9])) | |
456 | { | |
47adde3d | 457 | ServerStats.is_kill++; |
212380e3 AC |
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); | |
3c7d6fcc | 462 | return; |
212380e3 AC |
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", | |
3dfaa671 | 470 | source_p->name, parv[1]); |
212380e3 AC |
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]); | |
212380e3 AC |
490 | } |
491 | ||
492 | /* ms_save() | |
493 | * parv[1] - UID | |
494 | * parv[2] - TS | |
495 | */ | |
3c7d6fcc | 496 | static void |
428ca87b | 497 | ms_save(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
498 | { |
499 | struct Client *target_p; | |
500 | ||
501 | target_p = find_id(parv[1]); | |
502 | if (target_p == NULL) | |
3c7d6fcc | 503 | return; |
212380e3 AC |
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); | |
212380e3 AC |
518 | } |
519 | ||
212380e3 AC |
520 | /* clean_username() |
521 | * | |
522 | * input - username to check | |
3c7d6fcc | 523 | * output - false if erroneous, else true |
212380e3 AC |
524 | * side effects - |
525 | */ | |
3c7d6fcc | 526 | static bool |
212380e3 AC |
527 | clean_username(const char *username) |
528 | { | |
529 | int len = 0; | |
530 | ||
531 | for(; *username; username++) | |
532 | { | |
533 | len++; | |
534 | ||
535 | if(!IsUserChar(*username)) | |
3c7d6fcc | 536 | return false; |
212380e3 AC |
537 | } |
538 | ||
539 | if(len > USERLEN) | |
3c7d6fcc | 540 | return false; |
212380e3 | 541 | |
3c7d6fcc | 542 | return true; |
212380e3 AC |
543 | } |
544 | ||
545 | /* clean_host() | |
546 | * | |
547 | * input - host to check | |
3c7d6fcc | 548 | * output - false if erroneous, else true |
212380e3 AC |
549 | * side effects - |
550 | */ | |
3c7d6fcc | 551 | static bool |
212380e3 AC |
552 | clean_host(const char *host) |
553 | { | |
554 | int len = 0; | |
555 | ||
556 | for(; *host; host++) | |
557 | { | |
558 | len++; | |
559 | ||
560 | if(!IsHostChar(*host)) | |
3c7d6fcc | 561 | return false; |
212380e3 AC |
562 | } |
563 | ||
564 | if(len > HOSTLEN) | |
3c7d6fcc | 565 | return false; |
212380e3 | 566 | |
3c7d6fcc | 567 | return true; |
212380e3 AC |
568 | } |
569 | ||
3c7d6fcc | 570 | static bool |
561d7efc | 571 | clean_uid(const char *uid, const char *sid) |
212380e3 AC |
572 | { |
573 | int len = 1; | |
574 | ||
561d7efc | 575 | if(strncmp(uid, sid, strlen(sid))) |
3c7d6fcc | 576 | return false; |
561d7efc | 577 | |
212380e3 | 578 | if(!IsDigit(*uid++)) |
3c7d6fcc | 579 | return false; |
212380e3 AC |
580 | |
581 | for(; *uid; uid++) | |
582 | { | |
583 | len++; | |
584 | ||
585 | if(!IsIdChar(*uid)) | |
3c7d6fcc | 586 | return false; |
212380e3 AC |
587 | } |
588 | ||
589 | if(len != IDLEN - 1) | |
3c7d6fcc | 590 | return false; |
212380e3 | 591 | |
3c7d6fcc | 592 | return true; |
212380e3 AC |
593 | } |
594 | ||
595 | static void | |
596 | set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick) | |
597 | { | |
0e7cb7e6 | 598 | char note[NICKLEN + 10]; |
212380e3 AC |
599 | |
600 | /* This had to be copied here to avoid problems.. */ | |
e3354945 | 601 | source_p->tsinfo = rb_current_time(); |
212380e3 AC |
602 | if(source_p->name[0]) |
603 | del_from_client_hash(source_p->name, source_p); | |
604 | ||
4d5a902f | 605 | rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); |
212380e3 AC |
606 | add_to_client_hash(nick, source_p); |
607 | ||
5203cba5 | 608 | snprintf(note, sizeof(note), "Nick: %s", nick); |
0e7cb7e6 | 609 | rb_note(client_p->localClient->F, note); |
212380e3 AC |
610 | |
611 | if(source_p->flags & FLAGS_SENTUSER) | |
612 | { | |
212380e3 | 613 | /* got user, heres nick. */ |
21251822 | 614 | register_local_user(client_p, source_p); |
212380e3 AC |
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; | |
637c4932 | 623 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 624 | struct Channel *chptr; |
0e7cb7e6 | 625 | char note[NICKLEN + 10]; |
212380e3 | 626 | int samenick; |
5bc95eaf | 627 | hook_cdata hook_info; |
212380e3 AC |
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 | } | |
e3354945 | 639 | if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < rb_current_time()) |
212380e3 AC |
640 | source_p->localClient->number_of_nick_changes = 0; |
641 | ||
e3354945 | 642 | source_p->localClient->last_nick_change = rb_current_time(); |
212380e3 AC |
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 | { | |
95ffa685 | 660 | /* force the TS to increase -- jilles */ |
e3354945 | 661 | if (source_p->tsinfo >= rb_current_time()) |
95ffa685 JT |
662 | source_p->tsinfo++; |
663 | else | |
e3354945 | 664 | source_p->tsinfo = rb_current_time(); |
212380e3 AC |
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 | ||
f32b9ebd SB |
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 | ||
212380e3 AC |
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 */ | |
583f064f | 681 | sendto_common_channels_local(source_p, NOCAPS, NOCAPS, ":%s!%s@%s NICK :%s", |
212380e3 AC |
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 | { | |
b47f8a4f | 687 | whowas_add_history(source_p, 1); |
212380e3 AC |
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); | |
212380e3 AC |
693 | } |
694 | } | |
695 | ||
696 | /* Finally, add to hash */ | |
697 | del_from_client_hash(source_p->name, source_p); | |
4d5a902f | 698 | rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); |
212380e3 AC |
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 | |
55abcbb2 | 705 | * loses that reference. |
212380e3 AC |
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 | */ | |
637c4932 | 711 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->on_allow_list.head) |
212380e3 AC |
712 | { |
713 | target_p = ptr->data; | |
714 | ||
555ac41f JT |
715 | rb_dlinkFindDestroy(source_p, &target_p->localClient->allow_list); |
716 | rb_dlinkDestroy(ptr, &source_p->on_allow_list); | |
212380e3 AC |
717 | } |
718 | ||
5203cba5 | 719 | snprintf(note, sizeof(note), "Nick: %s", nick); |
0e7cb7e6 | 720 | rb_note(client_p->localClient->F, note); |
212380e3 AC |
721 | |
722 | return; | |
723 | } | |
724 | ||
725 | /* | |
726 | * change_remote_nick() | |
727 | */ | |
3c7d6fcc | 728 | static void |
212380e3 AC |
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; | |
5bc95eaf | 734 | hook_cdata hook_info; |
212380e3 AC |
735 | |
736 | /* client changing their nick - dont reset ts if its same */ | |
737 | if(!samenick) | |
738 | { | |
e3354945 | 739 | source_p->tsinfo = newts ? newts : rb_current_time(); |
212380e3 AC |
740 | monitor_signoff(source_p); |
741 | } | |
742 | ||
f32b9ebd SB |
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 | ||
583f064f | 748 | sendto_common_channels_local(source_p, NOCAPS, NOCAPS, ":%s!%s@%s NICK :%s", |
212380e3 AC |
749 | source_p->name, source_p->username, source_p->host, nick); |
750 | ||
751 | if(source_p->user) | |
752 | { | |
b47f8a4f | 753 | whowas_add_history(source_p, 1); |
212380e3 AC |
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); | |
212380e3 AC |
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.. */ | |
a4bf26dd | 764 | if((nd = rb_dictionary_retrieve(nd_dict, nick))) |
212380e3 AC |
765 | free_nd_entry(nd); |
766 | ||
4d5a902f | 767 | rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); |
212380e3 AC |
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); | |
212380e3 AC |
775 | } |
776 | ||
3c7d6fcc | 777 | static void |
212380e3 AC |
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 | { | |
9d107a71 | 793 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
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); | |
47adde3d | 800 | ServerStats.is_save++; |
212380e3 AC |
801 | sendto_one(client_p, ":%s SAVE %s %ld", me.id, |
802 | uid, (long)newts); | |
803 | register_client(client_p, source_p, | |
3f7e0642 | 804 | uid, SAVE_NICKTS, parc, parv); |
212380e3 AC |
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); | |
47adde3d | 820 | ServerStats.is_kill++; |
212380e3 AC |
821 | |
822 | target_p->flags |= FLAGS_KILLED; | |
823 | exit_client(client_p, target_p, &me, "Nick collision (new)"); | |
824 | } | |
3c7d6fcc | 825 | return; |
212380e3 AC |
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, | |
3f7e0642 | 845 | uid, SAVE_NICKTS, parc, parv); |
212380e3 AC |
846 | } |
847 | else if(uid) | |
848 | sendto_one(client_p, | |
849 | ":%s KILL %s :%s (Nick collision (new))", | |
850 | me.id, uid, me.name); | |
3c7d6fcc | 851 | return; |
212380e3 AC |
852 | } |
853 | else | |
854 | { | |
855 | if(sameuser) | |
9d107a71 | 856 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
857 | "Nick collision on %s(%s <- %s)(older %s)", |
858 | target_p->name, target_p->from->name, | |
859 | client_p->name, action); | |
860 | else | |
9d107a71 | 861 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
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 | { | |
47adde3d | 868 | ServerStats.is_save++; |
212380e3 AC |
869 | save_user(&me, &me, target_p); |
870 | } | |
871 | else | |
872 | { | |
47adde3d | 873 | ServerStats.is_kill++; |
212380e3 AC |
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 | ||
463947ad | 885 | register_client(client_p, source_p, |
212380e3 | 886 | nick, newts, parc, parv); |
212380e3 AC |
887 | } |
888 | } | |
889 | } | |
890 | ||
891 | ||
3c7d6fcc | 892 | static void |
212380e3 AC |
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 | { | |
9d107a71 | 908 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
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 | { | |
47adde3d | 915 | ServerStats.is_save += 2; |
212380e3 AC |
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])) | |
3f7e0642 | 921 | change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); |
212380e3 AC |
922 | } |
923 | else | |
924 | { | |
47adde3d | 925 | ServerStats.is_kill++; |
212380e3 AC |
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 | ||
47adde3d | 931 | ServerStats.is_kill++; |
212380e3 AC |
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 | } | |
3c7d6fcc | 940 | return; |
212380e3 AC |
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) | |
9d107a71 | 951 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
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 | |
9d107a71 | 956 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
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 | { | |
47adde3d | 963 | ServerStats.is_save++; |
212380e3 AC |
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); | |
212380e3 AC |
969 | /* send a :<id> NICK <id> <ts> (!) */ |
970 | if (!IsDigit(source_p->name[0])) | |
3f7e0642 | 971 | change_remote_nick(client_p, source_p, SAVE_NICKTS, source_p->id, 1); |
212380e3 AC |
972 | } |
973 | else | |
974 | { | |
47adde3d | 975 | ServerStats.is_kill++; |
212380e3 | 976 | |
ce782b68 JT |
977 | sendto_one_numeric(source_p, ERR_NICKCOLLISION, |
978 | form_str(ERR_NICKCOLLISION), source_p->name); | |
212380e3 AC |
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 | } | |
3c7d6fcc | 991 | return; |
212380e3 AC |
992 | } |
993 | else | |
994 | { | |
995 | if(sameuser) | |
9d107a71 | 996 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
997 | "Nick collision on %s(%s <- %s)(older %s)", |
998 | target_p->name, target_p->from->name, | |
999 | client_p->name, action); | |
1000 | else | |
9d107a71 | 1001 | sendto_realops_snomask(SNO_SKILL, L_ALL, |
212380e3 AC |
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 | { | |
47adde3d | 1008 | ServerStats.is_save++; |
212380e3 AC |
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 | ||
47adde3d | 1019 | ServerStats.is_kill++; |
212380e3 AC |
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); | |
212380e3 AC |
1028 | } |
1029 | ||
3c7d6fcc | 1030 | static void |
212380e3 AC |
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); | |
0e7cb7e6 | 1042 | rb_dlinkAddTail(source_p, &source_p->node, &global_client_list); |
212380e3 AC |
1043 | |
1044 | source_p->hopcount = atoi(parv[2]); | |
1045 | source_p->tsinfo = newts; | |
1046 | ||
4d5a902f | 1047 | rb_strlcpy(source_p->name, nick, sizeof(source_p->name)); |
f427c8b0 VY |
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)); | |
212380e3 AC |
1051 | |
1052 | if(parc == 12) | |
1053 | { | |
f427c8b0 VY |
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)); | |
212380e3 AC |
1057 | add_to_id_hash(source_p->id, source_p); |
1058 | if (strcmp(parv[9], "*")) | |
1059 | { | |
f427c8b0 | 1060 | rb_strlcpy(source_p->orighost, parv[9], sizeof(source_p->orighost)); |
212380e3 AC |
1061 | if (irccmp(source_p->host, source_p->orighost)) |
1062 | SetDynSpoof(source_p); | |
1063 | } | |
1064 | if (strcmp(parv[10], "*")) | |
f427c8b0 | 1065 | rb_strlcpy(source_p->user->suser, parv[10], sizeof(source_p->user->suser)); |
212380e3 AC |
1066 | } |
1067 | else if(parc == 10) | |
1068 | { | |
f427c8b0 VY |
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)); | |
212380e3 AC |
1072 | add_to_id_hash(source_p->id, source_p); |
1073 | } | |
1074 | else | |
1075 | { | |
463947ad | 1076 | s_assert(0); |
212380e3 AC |
1077 | } |
1078 | ||
1079 | /* remove any nd entries for this nick */ | |
a4bf26dd | 1080 | if((nd = rb_dictionary_retrieve(nd_dict, nick))) |
212380e3 AC |
1081 | free_nd_entry(nd); |
1082 | ||
1083 | add_to_client_hash(nick, source_p); | |
66b4a7ae | 1084 | add_to_hostname_hash(source_p->orighost, source_p); |
212380e3 AC |
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; | |
5b96d9a6 | 1095 | rb_dlink_node *ptr; |
212380e3 | 1096 | |
5b96d9a6 | 1097 | RB_DLINK_FOREACH(ptr, service_list.head) |
212380e3 | 1098 | { |
c88cdb00 | 1099 | if(!irccmp((const char *) ptr->data, server->name)) |
212380e3 AC |
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)) | |
0e7cb7e6 | 1126 | rb_dlinkAddAlloc(source_p, &oper_list); |
212380e3 AC |
1127 | |
1128 | SetRemoteClient(source_p); | |
1129 | ||
1130 | if(++Count.total > Count.max_tot) | |
1131 | Count.max_tot = Count.total; | |
1132 | ||
64449595 | 1133 | source_p->servptr = server; |
212380e3 | 1134 | |
0e7cb7e6 | 1135 | rb_dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users); |
212380e3 | 1136 | |
212380e3 AC |
1137 | call_hook(h_new_remote_user, source_p); |
1138 | ||
6287d57f | 1139 | introduce_client(client_p, source_p, user, nick, parc == 12); |
212380e3 AC |
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 */ | |
3c7d6fcc | 1144 | static bool |
212380e3 AC |
1145 | can_save(struct Client *target_p) |
1146 | { | |
1147 | struct Client *serv_p; | |
1148 | ||
1149 | if (MyClient(target_p)) | |
3c7d6fcc | 1150 | return true; |
212380e3 | 1151 | if (!has_id(target_p)) |
3c7d6fcc | 1152 | return false; |
212380e3 AC |
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)) | |
3c7d6fcc | 1157 | return false; |
212380e3 AC |
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); | |
47adde3d | 1175 | ServerStats.is_kill++; |
212380e3 AC |
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", | |
3f7e0642 | 1184 | target_p->id, target_p->id, (long)SAVE_NICKTS); |
212380e3 AC |
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); | |
3f7e0642 | 1194 | target_p->tsinfo = SAVE_NICKTS; |
212380e3 AC |
1195 | } |
1196 | else | |
3f7e0642 | 1197 | change_remote_nick(target_p, target_p, SAVE_NICKTS, target_p->id, 0); |
212380e3 | 1198 | } |
ad35b2cd JT |
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); | |
4dd5d304 JT |
1210 | ilog(L_SERVER, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)", |
1211 | client_p->name, nick); | |
ad35b2cd | 1212 | |
5203cba5 | 1213 | snprintf(squitreason, sizeof squitreason, |
ad35b2cd JT |
1214 | "Bad nickname introduced [%s]", nick); |
1215 | exit_client(client_p, client_p, &me, squitreason); | |
1216 | } |