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
24 * $Id: m_nick.c 3518 2007-06-22 21:59:09Z jilles $
48 #include "s_newconf.h"
51 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
52 * all servers for each nick-user pair, also if a user with a UID nick changes
53 * their nick but is collided again (the server detecting the collision will
54 * not propagate the nick change further). -- jilles
56 #define SAVE_NICKTS 100
58 static int mr_nick(struct Client
*, struct Client
*, int, const char **);
59 static int m_nick(struct Client
*, struct Client
*, int, const char **);
60 static int mc_nick(struct Client
*, struct Client
*, int, const char **);
61 static int ms_nick(struct Client
*, struct Client
*, int, const char **);
62 static int ms_uid(struct Client
*, struct Client
*, int, const char **);
63 static int ms_euid(struct Client
*, struct Client
*, int, const char **);
64 static int ms_save(struct Client
*, struct Client
*, int, const char **);
65 static int can_save(struct Client
*);
66 static void save_user(struct Client
*, struct Client
*, struct Client
*);
67 static void bad_nickname(struct Client
*, const char *);
69 struct Message nick_msgtab
= {
70 "NICK", 0, 0, 0, MFLG_SLOW
,
71 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
73 struct Message uid_msgtab
= {
74 "UID", 0, 0, 0, MFLG_SLOW
,
75 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
77 struct Message euid_msgtab
= {
78 "EUID", 0, 0, 0, MFLG_SLOW
,
79 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
81 struct Message save_msgtab
= {
82 "SAVE", 0, 0, 0, MFLG_SLOW
,
83 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
86 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
89 DECLARE_MODULE_AV1(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, "$Revision: 3518 $");
91 static int change_remote_nick(struct Client
*, struct Client
*, time_t,
94 static int clean_nick(const char *, int loc_client
);
95 static int clean_username(const char *);
96 static int clean_host(const char *);
97 static int clean_uid(const char *uid
);
99 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
100 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
101 static int register_client(struct Client
*client_p
, struct Client
*server
,
102 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
104 static int perform_nick_collides(struct Client
*, struct Client
*,
105 struct Client
*, int, const char **,
106 time_t, const char *, const char *);
107 static int perform_nickchange_collides(struct Client
*, struct Client
*,
108 struct Client
*, int, const char **, time_t, const char *);
114 mr_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
116 struct Client
*target_p
;
120 if (strlen(client_p
->id
) == 3)
122 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
126 if(parc
< 2 || EmptyString(parv
[1]) || (parv
[1][0] == '~'))
128 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
129 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
133 /* due to the scandinavian origins, (~ being uppercase of ^) and ~
134 * being disallowed as a nick char, we need to chop the first ~
135 * instead of just erroring.
137 if((s
= strchr(parv
[1], '~')))
140 /* copy the nick and terminate it */
141 rb_strlcpy(nick
, parv
[1], sizeof(nick
));
143 /* check the nickname is ok */
144 if(!clean_nick(nick
, 1))
146 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
147 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
151 /* check if the nick is resv'd */
152 if(find_nick_resv(nick
))
154 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
155 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
159 if(irc_dictionary_find(nd_dict
, nick
))
161 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
162 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
166 if((target_p
= find_named_client(nick
)) == NULL
)
167 set_initial_nick(client_p
, source_p
, nick
);
168 else if(source_p
== target_p
)
169 strcpy(source_p
->name
, nick
);
171 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
180 m_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
182 struct Client
*target_p
;
186 if(parc
< 2 || EmptyString(parv
[1]) || (parv
[1][0] == '~'))
188 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
192 /* due to the scandinavian origins, (~ being uppercase of ^) and ~
193 * being disallowed as a nick char, we need to chop the first ~
194 * instead of just erroring.
196 if((s
= strchr(parv
[1], '~')))
199 /* mark end of grace period, to prevent nickflooding */
200 if(!IsFloodDone(source_p
))
201 flood_endgrace(source_p
);
203 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
204 rb_strlcpy(nick
, parv
[1], sizeof(nick
));
206 /* check the nickname is ok */
207 if(!clean_nick(nick
, 1))
209 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
213 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
215 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
219 if(irc_dictionary_find(nd_dict
, nick
))
221 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
222 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
226 if((target_p
= find_named_client(nick
)))
228 /* If(target_p == source_p) the client is changing nicks between
229 * equivalent nicknames ie: [nick] -> {nick}
231 if(target_p
== source_p
)
233 /* check the nick isnt exactly the same */
234 if(strcmp(target_p
->name
, nick
))
235 change_local_nick(client_p
, source_p
, nick
, 1);
239 /* drop unregged client */
240 else if(IsUnknown(target_p
))
242 exit_client(NULL
, target_p
, &me
, "Overridden");
243 change_local_nick(client_p
, source_p
, nick
, 1);
246 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
251 change_local_nick(client_p
, source_p
, nick
, 1);
258 * server -> server nick change
260 * parv[2] = TS when nick change
263 mc_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
265 struct Client
*target_p
;
268 /* if nicks erroneous, or too long, kill */
269 if(!clean_nick(parv
[1], 0))
271 bad_nickname(client_p
, parv
[1]);
275 newts
= atol(parv
[2]);
276 target_p
= find_named_client(parv
[1]);
278 /* if the nick doesnt exist, allow it and process like normal */
281 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
283 else if(IsUnknown(target_p
))
285 exit_client(NULL
, target_p
, &me
, "Overridden");
286 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
288 else if(target_p
== source_p
)
290 /* client changing case of nick */
291 if(strcmp(target_p
->name
, parv
[1]))
292 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
294 /* we've got a collision! */
296 perform_nickchange_collides(source_p
, client_p
, target_p
,
297 parc
, parv
, newts
, parv
[1]);
303 ms_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
305 const char *nick
, *server
;
307 nick
= parc
> 1 ? parv
[1] : "?";
308 server
= parc
> 7 ? parv
[7] : "?";
310 sendto_wallops_flags(UMODE_WALLOP
, &me
,
311 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
312 client_p
->name
, nick
, server
);
313 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
314 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
315 me
.id
, client_p
->name
, nick
, server
);
316 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
317 client_p
->name
, nick
, server
);
319 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
336 ms_uid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
338 struct Client
*target_p
;
340 char squitreason
[120];
342 newts
= atol(parv
[3]);
346 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
347 "Dropping server %s due to (invalid) command 'UID' "
348 "with %d arguments (expecting 10)", client_p
->name
, parc
);
349 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
350 parc
, client_p
->name
);
351 rb_snprintf(squitreason
, sizeof squitreason
,
352 "Excess parameters (%d) to %s command, expecting %d",
354 exit_client(client_p
, client_p
, client_p
, squitreason
);
358 /* if nicks erroneous, or too long, kill */
359 if(!clean_nick(parv
[1], 0))
361 bad_nickname(client_p
, parv
[1]);
365 if(!clean_uid(parv
[8]))
367 rb_snprintf(squitreason
, sizeof squitreason
,
368 "Invalid UID %s for nick %s on %s",
369 parv
[8], parv
[1], source_p
->name
);
370 exit_client(client_p
, client_p
, client_p
, squitreason
);
374 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
376 ServerStats
.is_kill
++;
377 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
378 "Bad user@host: %s@%s From: %s(via %s)",
379 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
380 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
384 /* check length of clients gecos */
385 if(strlen(parv
[9]) > REALLEN
)
387 char *s
= LOCAL_COPY(parv
[9]);
388 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
389 source_p
->name
, parv
[1]);
394 target_p
= find_named_client(parv
[1]);
398 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
400 else if(IsUnknown(target_p
))
402 exit_client(NULL
, target_p
, &me
, "Overridden");
403 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
405 /* we've got a collision! */
407 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
408 newts
, parv
[1], parv
[8]);
427 ms_euid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
429 struct Client
*target_p
;
431 char squitreason
[120];
433 newts
= atol(parv
[3]);
437 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
438 "Dropping server %s due to (invalid) command 'EUID' "
439 "with %d arguments (expecting 12)", client_p
->name
, parc
);
440 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
441 parc
, client_p
->name
);
442 rb_snprintf(squitreason
, sizeof squitreason
,
443 "Excess parameters (%d) to %s command, expecting %d",
445 exit_client(client_p
, client_p
, client_p
, squitreason
);
449 /* if nicks erroneous, or too long, kill */
450 if(!clean_nick(parv
[1], 0))
452 bad_nickname(client_p
, parv
[1]);
456 if(!clean_uid(parv
[8]))
458 rb_snprintf(squitreason
, sizeof squitreason
,
459 "Invalid UID %s for nick %s on %s",
460 parv
[8], parv
[1], source_p
->name
);
461 exit_client(client_p
, client_p
, client_p
, squitreason
);
465 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
467 ServerStats
.is_kill
++;
468 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
469 "Bad user@host: %s@%s From: %s(via %s)",
470 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
471 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
475 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
477 ServerStats
.is_kill
++;
478 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
479 "Bad realhost: %s From: %s(via %s)",
480 parv
[9], source_p
->name
, client_p
->name
);
481 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
485 /* check length of clients gecos */
486 if(strlen(parv
[11]) > REALLEN
)
488 char *s
= LOCAL_COPY(parv
[11]);
489 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
490 source_p
->name
, parv
[1]);
495 target_p
= find_named_client(parv
[1]);
499 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
501 else if(IsUnknown(target_p
))
503 exit_client(NULL
, target_p
, &me
, "Overridden");
504 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
506 /* we've got a collision! */
508 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
509 newts
, parv
[1], parv
[8]);
519 ms_save(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
521 struct Client
*target_p
;
523 target_p
= find_id(parv
[1]);
524 if (target_p
== NULL
)
526 if (!IsPerson(target_p
))
527 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
528 "Ignored SAVE message for non-person %s from %s",
529 target_p
->name
, source_p
->name
);
530 else if (IsDigit(target_p
->name
[0]))
531 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
532 "Ignored noop SAVE message for %s from %s",
533 target_p
->name
, source_p
->name
);
534 else if (target_p
->tsinfo
== atol(parv
[2]))
535 save_user(client_p
, source_p
, target_p
);
537 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
538 "Ignored SAVE message for %s from %s",
539 target_p
->name
, source_p
->name
);
545 * input - nickname to check
546 * output - 0 if erroneous, else 1
550 clean_nick(const char *nick
, int loc_client
)
554 /* nicks cant start with a digit or -, and must have a length */
555 if(*nick
== '-' || *nick
== '\0')
558 if(loc_client
&& IsDigit(*nick
))
564 if(!IsNickChar(*nick
))
577 * input - username to check
578 * output - 0 if erroneous, else 0
582 clean_username(const char *username
)
586 for(; *username
; username
++)
590 if(!IsUserChar(*username
))
602 * input - host to check
603 * output - 0 if erroneous, else 0
607 clean_host(const char *host
)
615 if(!IsHostChar(*host
))
626 clean_uid(const char *uid
)
648 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
650 char buf
[USERLEN
+ 1];
651 char note
[NICKLEN
+ 10];
653 /* This had to be copied here to avoid problems.. */
654 source_p
->tsinfo
= rb_current_time();
655 if(source_p
->name
[0])
656 del_from_client_hash(source_p
->name
, source_p
);
658 strcpy(source_p
->name
, nick
);
659 add_to_client_hash(nick
, source_p
);
661 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
662 rb_note(client_p
->localClient
->F
, note
);
664 if(source_p
->flags
& FLAGS_SENTUSER
)
666 rb_strlcpy(buf
, source_p
->username
, sizeof(buf
));
668 /* got user, heres nick. */
669 register_local_user(client_p
, source_p
, buf
);
675 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
676 char *nick
, int dosend
)
678 struct Client
*target_p
;
679 rb_dlink_node
*ptr
, *next_ptr
;
680 struct Channel
*chptr
;
681 char note
[NICKLEN
+ 10];
686 chptr
= find_bannickchange_channel(source_p
);
689 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
690 form_str(ERR_BANNICKCHANGE
),
691 nick
, chptr
->chname
);
695 chptr
= find_nonickchange_channel(source_p
);
698 sendto_one_numeric(source_p
, ERR_NONICK
,
699 form_str(ERR_NONICK
),
704 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
705 source_p
->localClient
->number_of_nick_changes
= 0;
707 source_p
->localClient
->last_nick_change
= rb_current_time();
708 source_p
->localClient
->number_of_nick_changes
++;
710 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
711 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
713 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
714 me
.name
, source_p
->name
, source_p
->name
,
715 nick
, ConfigFileEntry
.max_nick_time
);
720 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
722 /* dont reset TS if theyre just changing case of nick */
725 /* force the TS to increase -- jilles */
726 if (source_p
->tsinfo
>= rb_current_time())
729 source_p
->tsinfo
= rb_current_time();
730 monitor_signoff(source_p
);
731 /* we only do bancache for local users -- jilles */
733 invalidate_bancache_user(source_p
);
736 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
737 "Nick change: From %s to %s [%s@%s]",
738 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
740 /* send the nick change to the users channels */
741 sendto_common_channels_local(source_p
, ":%s!%s@%s NICK :%s",
742 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
744 /* send the nick change to servers.. */
747 add_history(source_p
, 1);
751 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
752 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
756 /* Finally, add to hash */
757 del_from_client_hash(source_p
->name
, source_p
);
758 strcpy(source_p
->name
, nick
);
759 add_to_client_hash(nick
, source_p
);
762 monitor_signon(source_p
);
764 /* Make sure everyone that has this client on its accept list
765 * loses that reference.
767 /* we used to call del_all_accepts() here, but theres no real reason
768 * to clear a clients own list of accepted clients. So just remove
769 * them from everyone elses list --anfl
771 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
773 target_p
= ptr
->data
;
775 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
776 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
779 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
780 rb_note(client_p
->localClient
->F
, note
);
786 * change_remote_nick()
789 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
790 time_t newts
, const char *nick
, int dosend
)
793 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
795 /* client changing their nick - dont reset ts if its same */
798 source_p
->tsinfo
= newts
? newts
: rb_current_time();
799 monitor_signoff(source_p
);
802 sendto_common_channels_local(source_p
, ":%s!%s@%s NICK :%s",
803 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
807 add_history(source_p
, 1);
810 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
811 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
815 del_from_client_hash(source_p
->name
, source_p
);
817 /* invalidate nick delay when a remote client uses the nick.. */
818 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
821 strcpy(source_p
->name
, nick
);
822 add_to_client_hash(nick
, source_p
);
825 monitor_signon(source_p
);
827 /* remove all accepts pointing to the client */
828 del_all_accepts(source_p
);
834 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
835 struct Client
*target_p
, int parc
, const char *parv
[],
836 time_t newts
, const char *nick
, const char *uid
)
842 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
843 uid
!= NULL
&& can_save(source_p
);
844 action
= use_save
? "saved" : "killed";
846 /* if we dont have a ts, or their TS's are the same, kill both */
847 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
849 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
850 "Nick collision on %s(%s <- %s)(both %s)",
851 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
855 save_user(&me
, &me
, target_p
);
856 ServerStats
.is_save
++;
857 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
859 register_client(client_p
, source_p
,
860 uid
, SAVE_NICKTS
, parc
, parv
);
864 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
865 form_str(ERR_NICKCOLLISION
), target_p
->name
);
867 /* if the new client being introduced has a UID, we need to
868 * issue a KILL for it..
871 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
872 me
.id
, uid
, me
.name
);
874 /* we then need to KILL the old client everywhere */
875 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
876 ServerStats
.is_kill
++;
878 target_p
->flags
|= FLAGS_KILLED
;
879 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
883 /* the timestamps are different */
886 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
887 && !irccmp(target_p
->host
, parv
[6]);
889 if((sameuser
&& newts
< target_p
->tsinfo
) ||
890 (!sameuser
&& newts
> target_p
->tsinfo
))
892 /* if we have a UID, then we need to issue a KILL,
893 * otherwise we do nothing and hope that the other
894 * client will collide it..
898 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
900 register_client(client_p
, source_p
,
901 uid
, SAVE_NICKTS
, parc
, parv
);
905 ":%s KILL %s :%s (Nick collision (new))",
906 me
.id
, uid
, me
.name
);
912 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
913 "Nick collision on %s(%s <- %s)(older %s)",
914 target_p
->name
, target_p
->from
->name
,
915 client_p
->name
, action
);
917 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
918 "Nick collision on %s(%s <- %s)(newer %s)",
919 target_p
->name
, target_p
->from
->name
,
920 client_p
->name
, action
);
924 ServerStats
.is_save
++;
925 save_user(&me
, &me
, target_p
);
929 ServerStats
.is_kill
++;
930 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
931 form_str(ERR_NICKCOLLISION
), target_p
->name
);
933 /* now we just need to kill the existing client */
934 kill_client_serv_butone(client_p
, target_p
,
935 "%s (Nick collision (new))", me
.name
);
937 target_p
->flags
|= FLAGS_KILLED
;
938 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
941 register_client(client_p
, source_p
,
942 nick
, newts
, parc
, parv
);
951 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
952 struct Client
*target_p
, int parc
,
953 const char *parv
[], time_t newts
, const char *nick
)
959 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
961 action
= use_save
? "saved" : "killed";
963 /* its a client changing nick and causing a collide */
964 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
966 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
967 "Nick change collision from %s to %s(%s <- %s)(both %s)",
968 source_p
->name
, target_p
->name
, target_p
->from
->name
,
969 client_p
->name
, action
);
973 ServerStats
.is_save
+= 2;
974 save_user(&me
, &me
, target_p
);
975 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
976 source_p
->id
, (long)newts
);
977 /* don't send a redundant nick change */
978 if (!IsDigit(source_p
->name
[0]))
979 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
983 ServerStats
.is_kill
++;
984 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
985 form_str(ERR_NICKCOLLISION
), target_p
->name
);
987 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
989 ServerStats
.is_kill
++;
991 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
993 target_p
->flags
|= FLAGS_KILLED
;
994 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
995 source_p
->flags
|= FLAGS_KILLED
;
996 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1002 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
1003 !irccmp(target_p
->host
, source_p
->host
);
1005 if((sameuser
&& newts
< target_p
->tsinfo
) ||
1006 (!sameuser
&& newts
> target_p
->tsinfo
))
1009 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1010 "Nick change collision from %s to %s(%s <- %s)(older %s)",
1011 source_p
->name
, target_p
->name
,
1012 target_p
->from
->name
, client_p
->name
, action
);
1014 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1015 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
1016 source_p
->name
, target_p
->name
,
1017 target_p
->from
->name
, client_p
->name
, action
);
1021 ServerStats
.is_save
++;
1022 /* can't broadcast a SAVE because the
1023 * nickchange has happened at client_p
1024 * but not in other directions -- jilles */
1025 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1026 source_p
->id
, (long)newts
);
1027 /* send a :<id> NICK <id> <ts> (!) */
1028 if (!IsDigit(source_p
->name
[0]))
1029 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1033 ServerStats
.is_kill
++;
1035 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1036 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1038 /* kill the client issuing the nickchange */
1039 kill_client_serv_butone(client_p
, source_p
,
1040 "%s (Nick change collision)", me
.name
);
1042 source_p
->flags
|= FLAGS_KILLED
;
1045 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1047 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1054 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1055 "Nick collision on %s(%s <- %s)(older %s)",
1056 target_p
->name
, target_p
->from
->name
,
1057 client_p
->name
, action
);
1059 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1060 "Nick collision on %s(%s <- %s)(newer %s)",
1061 target_p
->name
, target_p
->from
->name
,
1062 client_p
->name
, action
);
1066 ServerStats
.is_save
++;
1067 save_user(&me
, &me
, target_p
);
1071 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1072 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1074 /* kill the client who existed before hand */
1075 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1077 ServerStats
.is_kill
++;
1079 target_p
->flags
|= FLAGS_KILLED
;
1080 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1085 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1091 register_client(struct Client
*client_p
, struct Client
*server
,
1092 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1094 struct Client
*source_p
;
1096 struct nd_entry
*nd
;
1100 source_p
= make_client(client_p
);
1101 user
= make_user(source_p
);
1102 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1104 source_p
->hopcount
= atoi(parv
[2]);
1105 source_p
->tsinfo
= newts
;
1107 strcpy(source_p
->name
, nick
);
1108 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1109 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1110 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1114 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1115 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1116 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1117 add_to_id_hash(source_p
->id
, source_p
);
1118 if (strcmp(parv
[9], "*"))
1120 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1121 if (irccmp(source_p
->host
, source_p
->orighost
))
1122 SetDynSpoof(source_p
);
1124 if (strcmp(parv
[10], "*"))
1125 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1129 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1130 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1131 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1132 add_to_id_hash(source_p
->id
, source_p
);
1139 /* remove any nd entries for this nick */
1140 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1143 add_to_client_hash(nick
, source_p
);
1144 add_to_hostname_hash(source_p
->orighost
, source_p
);
1145 monitor_signon(source_p
);
1150 flag
= user_modes
[(unsigned char) *m
];
1152 if(flag
& UMODE_SERVICE
)
1157 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1159 if(!irccmp((const char *) ptr
->data
, server
->name
))
1173 /* increment +i count if theyre invis */
1174 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1177 /* increment opered count if theyre opered */
1178 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1181 source_p
->umodes
|= flag
;
1185 if(IsOper(source_p
) && !IsService(source_p
))
1186 rb_dlinkAddAlloc(source_p
, &oper_list
);
1188 SetRemoteClient(source_p
);
1190 if(++Count
.total
> Count
.max_tot
)
1191 Count
.max_tot
= Count
.total
;
1193 source_p
->servptr
= server
;
1195 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1197 call_hook(h_new_remote_user
, source_p
);
1199 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1202 /* Check if we can do SAVE. target_p can be a client to save or a
1203 * server introducing a client -- jilles */
1205 can_save(struct Client
*target_p
)
1207 struct Client
*serv_p
;
1209 if (MyClient(target_p
))
1211 if (!has_id(target_p
))
1213 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1214 while (serv_p
!= NULL
&& serv_p
!= &me
)
1216 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1218 serv_p
= serv_p
->servptr
;
1220 return serv_p
== &me
;
1224 save_user(struct Client
*client_p
, struct Client
*source_p
,
1225 struct Client
*target_p
)
1227 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1229 /* This shouldn't happen */
1230 /* Note we only need SAVE support in this direction */
1231 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1232 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1233 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1234 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1235 ServerStats
.is_kill
++;
1237 target_p
->flags
|= FLAGS_KILLED
;
1238 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1241 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1242 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1243 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1244 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1245 if (!IsMe(client_p
))
1246 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1247 "Received SAVE message for %s from %s",
1248 target_p
->name
, source_p
->name
);
1249 if (MyClient(target_p
))
1251 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1252 form_str(RPL_SAVENICK
), target_p
->id
);
1253 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1254 target_p
->tsinfo
= SAVE_NICKTS
;
1257 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1260 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1262 char squitreason
[100];
1264 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1265 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1266 client_p
->name
, nick
);
1267 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1268 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1269 me
.id
, client_p
->name
, nick
);
1270 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1271 client_p
->name
, nick
);
1273 rb_snprintf(squitreason
, sizeof squitreason
,
1274 "Bad nickname introduced [%s]", nick
);
1275 exit_client(client_p
, client_p
, &me
, squitreason
);