2 * ircd-ratbox: A slightly useful ircd.
3 * m_nick.c: Sets a users nick.
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
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.
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.
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
47 #include "s_newconf.h"
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
55 #define SAVE_NICKTS 100
57 static int mr_nick(struct Client
*, struct Client
*, int, const char **);
58 static int m_nick(struct Client
*, struct Client
*, int, const char **);
59 static int mc_nick(struct Client
*, struct Client
*, int, const char **);
60 static int ms_nick(struct Client
*, struct Client
*, int, const char **);
61 static int ms_uid(struct Client
*, struct Client
*, int, const char **);
62 static int ms_euid(struct Client
*, struct Client
*, int, const char **);
63 static int ms_save(struct Client
*, struct Client
*, int, const char **);
64 static int can_save(struct Client
*);
65 static void save_user(struct Client
*, struct Client
*, struct Client
*);
66 static void bad_nickname(struct Client
*, const char *);
68 struct Message nick_msgtab
= {
69 "NICK", 0, 0, 0, MFLG_SLOW
,
70 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
72 struct Message uid_msgtab
= {
73 "UID", 0, 0, 0, MFLG_SLOW
,
74 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
76 struct Message euid_msgtab
= {
77 "EUID", 0, 0, 0, MFLG_SLOW
,
78 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
80 struct Message save_msgtab
= {
81 "SAVE", 0, 0, 0, MFLG_SLOW
,
82 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
85 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
88 DECLARE_MODULE_AV1(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, "$Revision: 3518 $");
90 static int change_remote_nick(struct Client
*, struct Client
*, time_t,
93 static int clean_nick(const char *, int loc_client
);
94 static int clean_username(const char *);
95 static int clean_host(const char *);
96 static int clean_uid(const char *uid
);
98 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
99 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
100 static int register_client(struct Client
*client_p
, struct Client
*server
,
101 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
103 static int perform_nick_collides(struct Client
*, struct Client
*,
104 struct Client
*, int, const char **,
105 time_t, const char *, const char *);
106 static int perform_nickchange_collides(struct Client
*, struct Client
*,
107 struct Client
*, int, const char **, time_t, const char *);
113 mr_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
115 struct Client
*target_p
;
119 if (strlen(client_p
->id
) == 3)
121 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
125 if(parc
< 2 || EmptyString(parv
[1]) || (parv
[1][0] == '~'))
127 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
128 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
132 /* due to the scandinavian origins, (~ being uppercase of ^) and ~
133 * being disallowed as a nick char, we need to chop the first ~
134 * instead of just erroring.
136 if((s
= strchr(parv
[1], '~')))
139 /* copy the nick and terminate it */
140 rb_strlcpy(nick
, parv
[1], sizeof(nick
));
142 /* check the nickname is ok */
143 if(!clean_nick(nick
, 1))
145 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
146 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
150 /* check if the nick is resv'd */
151 if(find_nick_resv(nick
))
153 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
154 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
158 if(irc_dictionary_find(nd_dict
, nick
))
160 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
161 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
165 if((target_p
= find_named_client(nick
)) == NULL
)
166 set_initial_nick(client_p
, source_p
, nick
);
167 else if(source_p
== target_p
)
168 strcpy(source_p
->name
, nick
);
170 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
179 m_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
181 struct Client
*target_p
;
185 if(parc
< 2 || EmptyString(parv
[1]) || (parv
[1][0] == '~'))
187 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
191 /* due to the scandinavian origins, (~ being uppercase of ^) and ~
192 * being disallowed as a nick char, we need to chop the first ~
193 * instead of just erroring.
195 if((s
= strchr(parv
[1], '~')))
198 /* mark end of grace period, to prevent nickflooding */
199 if(!IsFloodDone(source_p
))
200 flood_endgrace(source_p
);
202 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
203 rb_strlcpy(nick
, parv
[1], sizeof(nick
));
205 /* check the nickname is ok */
206 if(!clean_nick(nick
, 1))
208 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
212 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
214 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
218 if(irc_dictionary_find(nd_dict
, nick
))
220 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
221 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
225 if((target_p
= find_named_client(nick
)))
227 /* If(target_p == source_p) the client is changing nicks between
228 * equivalent nicknames ie: [nick] -> {nick}
230 if(target_p
== source_p
)
232 /* check the nick isnt exactly the same */
233 if(strcmp(target_p
->name
, nick
))
234 change_local_nick(client_p
, source_p
, nick
, 1);
238 /* drop unregged client */
239 else if(IsUnknown(target_p
))
241 exit_client(NULL
, target_p
, &me
, "Overridden");
242 change_local_nick(client_p
, source_p
, nick
, 1);
245 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
250 change_local_nick(client_p
, source_p
, nick
, 1);
257 * server -> server nick change
259 * parv[2] = TS when nick change
262 mc_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
264 struct Client
*target_p
;
267 /* if nicks erroneous, or too long, kill */
268 if(!clean_nick(parv
[1], 0))
270 bad_nickname(client_p
, parv
[1]);
274 newts
= atol(parv
[2]);
275 target_p
= find_named_client(parv
[1]);
277 /* if the nick doesnt exist, allow it and process like normal */
280 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
282 else if(IsUnknown(target_p
))
284 exit_client(NULL
, target_p
, &me
, "Overridden");
285 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
287 else if(target_p
== source_p
)
289 /* client changing case of nick */
290 if(strcmp(target_p
->name
, parv
[1]))
291 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
293 /* we've got a collision! */
295 perform_nickchange_collides(source_p
, client_p
, target_p
,
296 parc
, parv
, newts
, parv
[1]);
302 ms_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
304 const char *nick
, *server
;
306 nick
= parc
> 1 ? parv
[1] : "?";
307 server
= parc
> 7 ? parv
[7] : "?";
309 sendto_wallops_flags(UMODE_WALLOP
, &me
,
310 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
311 client_p
->name
, nick
, server
);
312 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
313 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
314 me
.id
, client_p
->name
, nick
, server
);
315 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
316 client_p
->name
, nick
, server
);
318 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
335 ms_uid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
337 struct Client
*target_p
;
339 char squitreason
[120];
341 newts
= atol(parv
[3]);
345 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
346 "Dropping server %s due to (invalid) command 'UID' "
347 "with %d arguments (expecting 10)", client_p
->name
, parc
);
348 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
349 parc
, client_p
->name
);
350 rb_snprintf(squitreason
, sizeof squitreason
,
351 "Excess parameters (%d) to %s command, expecting %d",
353 exit_client(client_p
, client_p
, client_p
, squitreason
);
357 /* if nicks erroneous, or too long, kill */
358 if(!clean_nick(parv
[1], 0))
360 bad_nickname(client_p
, parv
[1]);
364 if(!clean_uid(parv
[8]))
366 rb_snprintf(squitreason
, sizeof squitreason
,
367 "Invalid UID %s for nick %s on %s",
368 parv
[8], parv
[1], source_p
->name
);
369 exit_client(client_p
, client_p
, client_p
, squitreason
);
373 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
375 ServerStats
.is_kill
++;
376 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
377 "Bad user@host: %s@%s From: %s(via %s)",
378 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
379 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
383 /* check length of clients gecos */
384 if(strlen(parv
[9]) > REALLEN
)
386 char *s
= LOCAL_COPY(parv
[9]);
387 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
388 source_p
->name
, parv
[1]);
393 target_p
= find_named_client(parv
[1]);
397 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
399 else if(IsUnknown(target_p
))
401 exit_client(NULL
, target_p
, &me
, "Overridden");
402 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
404 /* we've got a collision! */
406 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
407 newts
, parv
[1], parv
[8]);
426 ms_euid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
428 struct Client
*target_p
;
430 char squitreason
[120];
432 newts
= atol(parv
[3]);
436 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
437 "Dropping server %s due to (invalid) command 'EUID' "
438 "with %d arguments (expecting 12)", client_p
->name
, parc
);
439 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
440 parc
, client_p
->name
);
441 rb_snprintf(squitreason
, sizeof squitreason
,
442 "Excess parameters (%d) to %s command, expecting %d",
444 exit_client(client_p
, client_p
, client_p
, squitreason
);
448 /* if nicks erroneous, or too long, kill */
449 if(!clean_nick(parv
[1], 0))
451 bad_nickname(client_p
, parv
[1]);
455 if(!clean_uid(parv
[8]))
457 rb_snprintf(squitreason
, sizeof squitreason
,
458 "Invalid UID %s for nick %s on %s",
459 parv
[8], parv
[1], source_p
->name
);
460 exit_client(client_p
, client_p
, client_p
, squitreason
);
464 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
466 ServerStats
.is_kill
++;
467 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
468 "Bad user@host: %s@%s From: %s(via %s)",
469 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
470 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
474 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
476 ServerStats
.is_kill
++;
477 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
478 "Bad realhost: %s From: %s(via %s)",
479 parv
[9], source_p
->name
, client_p
->name
);
480 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
484 /* check length of clients gecos */
485 if(strlen(parv
[11]) > REALLEN
)
487 char *s
= LOCAL_COPY(parv
[11]);
488 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
489 source_p
->name
, parv
[1]);
494 target_p
= find_named_client(parv
[1]);
498 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
500 else if(IsUnknown(target_p
))
502 exit_client(NULL
, target_p
, &me
, "Overridden");
503 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
505 /* we've got a collision! */
507 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
508 newts
, parv
[1], parv
[8]);
518 ms_save(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
520 struct Client
*target_p
;
522 target_p
= find_id(parv
[1]);
523 if (target_p
== NULL
)
525 if (!IsPerson(target_p
))
526 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
527 "Ignored SAVE message for non-person %s from %s",
528 target_p
->name
, source_p
->name
);
529 else if (IsDigit(target_p
->name
[0]))
530 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
531 "Ignored noop SAVE message for %s from %s",
532 target_p
->name
, source_p
->name
);
533 else if (target_p
->tsinfo
== atol(parv
[2]))
534 save_user(client_p
, source_p
, target_p
);
536 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
537 "Ignored SAVE message for %s from %s",
538 target_p
->name
, source_p
->name
);
544 * input - nickname to check
545 * output - 0 if erroneous, else 1
549 clean_nick(const char *nick
, int loc_client
)
553 /* nicks cant start with a digit or -, and must have a length */
554 if(*nick
== '-' || *nick
== '\0')
557 if(loc_client
&& IsDigit(*nick
))
563 if(!IsNickChar(*nick
))
576 * input - username to check
577 * output - 0 if erroneous, else 0
581 clean_username(const char *username
)
585 for(; *username
; username
++)
589 if(!IsUserChar(*username
))
601 * input - host to check
602 * output - 0 if erroneous, else 0
606 clean_host(const char *host
)
614 if(!IsHostChar(*host
))
625 clean_uid(const char *uid
)
647 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
649 char buf
[USERLEN
+ 1];
650 char note
[NICKLEN
+ 10];
652 /* This had to be copied here to avoid problems.. */
653 source_p
->tsinfo
= rb_current_time();
654 if(source_p
->name
[0])
655 del_from_client_hash(source_p
->name
, source_p
);
657 strcpy(source_p
->name
, nick
);
658 add_to_client_hash(nick
, source_p
);
660 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
661 rb_note(client_p
->localClient
->F
, note
);
663 if(source_p
->flags
& FLAGS_SENTUSER
)
665 rb_strlcpy(buf
, source_p
->username
, sizeof(buf
));
667 /* got user, heres nick. */
668 register_local_user(client_p
, source_p
, buf
);
674 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
675 char *nick
, int dosend
)
677 struct Client
*target_p
;
678 rb_dlink_node
*ptr
, *next_ptr
;
679 struct Channel
*chptr
;
680 char note
[NICKLEN
+ 10];
685 chptr
= find_bannickchange_channel(source_p
);
688 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
689 form_str(ERR_BANNICKCHANGE
),
690 nick
, chptr
->chname
);
694 chptr
= find_nonickchange_channel(source_p
);
697 sendto_one_numeric(source_p
, ERR_NONICK
,
698 form_str(ERR_NONICK
),
703 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
704 source_p
->localClient
->number_of_nick_changes
= 0;
706 source_p
->localClient
->last_nick_change
= rb_current_time();
707 source_p
->localClient
->number_of_nick_changes
++;
709 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
710 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
712 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
713 me
.name
, source_p
->name
, source_p
->name
,
714 nick
, ConfigFileEntry
.max_nick_time
);
719 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
721 /* dont reset TS if theyre just changing case of nick */
724 /* force the TS to increase -- jilles */
725 if (source_p
->tsinfo
>= rb_current_time())
728 source_p
->tsinfo
= rb_current_time();
729 monitor_signoff(source_p
);
730 /* we only do bancache for local users -- jilles */
732 invalidate_bancache_user(source_p
);
735 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
736 "Nick change: From %s to %s [%s@%s]",
737 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
739 /* send the nick change to the users channels */
740 sendto_common_channels_local(source_p
, ":%s!%s@%s NICK :%s",
741 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
743 /* send the nick change to servers.. */
746 add_history(source_p
, 1);
750 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
751 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
755 /* Finally, add to hash */
756 del_from_client_hash(source_p
->name
, source_p
);
757 strcpy(source_p
->name
, nick
);
758 add_to_client_hash(nick
, source_p
);
761 monitor_signon(source_p
);
763 /* Make sure everyone that has this client on its accept list
764 * loses that reference.
766 /* we used to call del_all_accepts() here, but theres no real reason
767 * to clear a clients own list of accepted clients. So just remove
768 * them from everyone elses list --anfl
770 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
772 target_p
= ptr
->data
;
774 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
775 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
778 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
779 rb_note(client_p
->localClient
->F
, note
);
785 * change_remote_nick()
788 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
789 time_t newts
, const char *nick
, int dosend
)
792 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
794 /* client changing their nick - dont reset ts if its same */
797 source_p
->tsinfo
= newts
? newts
: rb_current_time();
798 monitor_signoff(source_p
);
801 sendto_common_channels_local(source_p
, ":%s!%s@%s NICK :%s",
802 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
806 add_history(source_p
, 1);
809 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
810 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
814 del_from_client_hash(source_p
->name
, source_p
);
816 /* invalidate nick delay when a remote client uses the nick.. */
817 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
820 strcpy(source_p
->name
, nick
);
821 add_to_client_hash(nick
, source_p
);
824 monitor_signon(source_p
);
826 /* remove all accepts pointing to the client */
827 del_all_accepts(source_p
);
833 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
834 struct Client
*target_p
, int parc
, const char *parv
[],
835 time_t newts
, const char *nick
, const char *uid
)
841 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
842 uid
!= NULL
&& can_save(source_p
);
843 action
= use_save
? "saved" : "killed";
845 /* if we dont have a ts, or their TS's are the same, kill both */
846 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
848 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
849 "Nick collision on %s(%s <- %s)(both %s)",
850 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
854 save_user(&me
, &me
, target_p
);
855 ServerStats
.is_save
++;
856 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
858 register_client(client_p
, source_p
,
859 uid
, SAVE_NICKTS
, parc
, parv
);
863 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
864 form_str(ERR_NICKCOLLISION
), target_p
->name
);
866 /* if the new client being introduced has a UID, we need to
867 * issue a KILL for it..
870 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
871 me
.id
, uid
, me
.name
);
873 /* we then need to KILL the old client everywhere */
874 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
875 ServerStats
.is_kill
++;
877 target_p
->flags
|= FLAGS_KILLED
;
878 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
882 /* the timestamps are different */
885 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
886 && !irccmp(target_p
->host
, parv
[6]);
888 if((sameuser
&& newts
< target_p
->tsinfo
) ||
889 (!sameuser
&& newts
> target_p
->tsinfo
))
891 /* if we have a UID, then we need to issue a KILL,
892 * otherwise we do nothing and hope that the other
893 * client will collide it..
897 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
899 register_client(client_p
, source_p
,
900 uid
, SAVE_NICKTS
, parc
, parv
);
904 ":%s KILL %s :%s (Nick collision (new))",
905 me
.id
, uid
, me
.name
);
911 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
912 "Nick collision on %s(%s <- %s)(older %s)",
913 target_p
->name
, target_p
->from
->name
,
914 client_p
->name
, action
);
916 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
917 "Nick collision on %s(%s <- %s)(newer %s)",
918 target_p
->name
, target_p
->from
->name
,
919 client_p
->name
, action
);
923 ServerStats
.is_save
++;
924 save_user(&me
, &me
, target_p
);
928 ServerStats
.is_kill
++;
929 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
930 form_str(ERR_NICKCOLLISION
), target_p
->name
);
932 /* now we just need to kill the existing client */
933 kill_client_serv_butone(client_p
, target_p
,
934 "%s (Nick collision (new))", me
.name
);
936 target_p
->flags
|= FLAGS_KILLED
;
937 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
940 register_client(client_p
, source_p
,
941 nick
, newts
, parc
, parv
);
950 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
951 struct Client
*target_p
, int parc
,
952 const char *parv
[], time_t newts
, const char *nick
)
958 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
960 action
= use_save
? "saved" : "killed";
962 /* its a client changing nick and causing a collide */
963 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
965 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
966 "Nick change collision from %s to %s(%s <- %s)(both %s)",
967 source_p
->name
, target_p
->name
, target_p
->from
->name
,
968 client_p
->name
, action
);
972 ServerStats
.is_save
+= 2;
973 save_user(&me
, &me
, target_p
);
974 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
975 source_p
->id
, (long)newts
);
976 /* don't send a redundant nick change */
977 if (!IsDigit(source_p
->name
[0]))
978 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
982 ServerStats
.is_kill
++;
983 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
984 form_str(ERR_NICKCOLLISION
), target_p
->name
);
986 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
988 ServerStats
.is_kill
++;
990 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
992 target_p
->flags
|= FLAGS_KILLED
;
993 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
994 source_p
->flags
|= FLAGS_KILLED
;
995 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1001 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
1002 !irccmp(target_p
->host
, source_p
->host
);
1004 if((sameuser
&& newts
< target_p
->tsinfo
) ||
1005 (!sameuser
&& newts
> target_p
->tsinfo
))
1008 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1009 "Nick change collision from %s to %s(%s <- %s)(older %s)",
1010 source_p
->name
, target_p
->name
,
1011 target_p
->from
->name
, client_p
->name
, action
);
1013 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1014 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
1015 source_p
->name
, target_p
->name
,
1016 target_p
->from
->name
, client_p
->name
, action
);
1020 ServerStats
.is_save
++;
1021 /* can't broadcast a SAVE because the
1022 * nickchange has happened at client_p
1023 * but not in other directions -- jilles */
1024 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1025 source_p
->id
, (long)newts
);
1026 /* send a :<id> NICK <id> <ts> (!) */
1027 if (!IsDigit(source_p
->name
[0]))
1028 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1032 ServerStats
.is_kill
++;
1034 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1035 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1037 /* kill the client issuing the nickchange */
1038 kill_client_serv_butone(client_p
, source_p
,
1039 "%s (Nick change collision)", me
.name
);
1041 source_p
->flags
|= FLAGS_KILLED
;
1044 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1046 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1053 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1054 "Nick collision on %s(%s <- %s)(older %s)",
1055 target_p
->name
, target_p
->from
->name
,
1056 client_p
->name
, action
);
1058 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1059 "Nick collision on %s(%s <- %s)(newer %s)",
1060 target_p
->name
, target_p
->from
->name
,
1061 client_p
->name
, action
);
1065 ServerStats
.is_save
++;
1066 save_user(&me
, &me
, target_p
);
1070 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1071 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1073 /* kill the client who existed before hand */
1074 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1076 ServerStats
.is_kill
++;
1078 target_p
->flags
|= FLAGS_KILLED
;
1079 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1084 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1090 register_client(struct Client
*client_p
, struct Client
*server
,
1091 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1093 struct Client
*source_p
;
1095 struct nd_entry
*nd
;
1099 source_p
= make_client(client_p
);
1100 user
= make_user(source_p
);
1101 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1103 source_p
->hopcount
= atoi(parv
[2]);
1104 source_p
->tsinfo
= newts
;
1106 strcpy(source_p
->name
, nick
);
1107 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1108 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1109 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1113 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1114 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1115 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1116 add_to_id_hash(source_p
->id
, source_p
);
1117 if (strcmp(parv
[9], "*"))
1119 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1120 if (irccmp(source_p
->host
, source_p
->orighost
))
1121 SetDynSpoof(source_p
);
1123 if (strcmp(parv
[10], "*"))
1124 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1128 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1129 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1130 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1131 add_to_id_hash(source_p
->id
, source_p
);
1138 /* remove any nd entries for this nick */
1139 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1142 add_to_client_hash(nick
, source_p
);
1143 add_to_hostname_hash(source_p
->orighost
, source_p
);
1144 monitor_signon(source_p
);
1149 flag
= user_modes
[(unsigned char) *m
];
1151 if(flag
& UMODE_SERVICE
)
1156 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1158 if(!irccmp((const char *) ptr
->data
, server
->name
))
1172 /* increment +i count if theyre invis */
1173 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1176 /* increment opered count if theyre opered */
1177 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1180 source_p
->umodes
|= flag
;
1184 if(IsOper(source_p
) && !IsService(source_p
))
1185 rb_dlinkAddAlloc(source_p
, &oper_list
);
1187 SetRemoteClient(source_p
);
1189 if(++Count
.total
> Count
.max_tot
)
1190 Count
.max_tot
= Count
.total
;
1192 source_p
->servptr
= server
;
1194 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1196 call_hook(h_new_remote_user
, source_p
);
1198 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1201 /* Check if we can do SAVE. target_p can be a client to save or a
1202 * server introducing a client -- jilles */
1204 can_save(struct Client
*target_p
)
1206 struct Client
*serv_p
;
1208 if (MyClient(target_p
))
1210 if (!has_id(target_p
))
1212 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1213 while (serv_p
!= NULL
&& serv_p
!= &me
)
1215 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1217 serv_p
= serv_p
->servptr
;
1219 return serv_p
== &me
;
1223 save_user(struct Client
*client_p
, struct Client
*source_p
,
1224 struct Client
*target_p
)
1226 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1228 /* This shouldn't happen */
1229 /* Note we only need SAVE support in this direction */
1230 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1231 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1232 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1233 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1234 ServerStats
.is_kill
++;
1236 target_p
->flags
|= FLAGS_KILLED
;
1237 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1240 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1241 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1242 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1243 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1244 if (!IsMe(client_p
))
1245 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1246 "Received SAVE message for %s from %s",
1247 target_p
->name
, source_p
->name
);
1248 if (MyClient(target_p
))
1250 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1251 form_str(RPL_SAVENICK
), target_p
->id
);
1252 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1253 target_p
->tsinfo
= SAVE_NICKTS
;
1256 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1259 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1261 char squitreason
[100];
1263 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1264 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1265 client_p
->name
, nick
);
1266 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1267 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1268 me
.id
, client_p
->name
, nick
);
1269 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1270 client_p
->name
, nick
);
1272 rb_snprintf(squitreason
, sizeof squitreason
,
1273 "Bad nickname introduced [%s]", nick
);
1274 exit_client(client_p
, client_p
, &me
, squitreason
);