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"
52 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
53 * all servers for each nick-user pair, also if a user with a UID nick changes
54 * their nick but is collided again (the server detecting the collision will
55 * not propagate the nick change further). -- jilles
57 #define SAVE_NICKTS 100
59 static int mr_nick(struct Client
*, struct Client
*, int, const char **);
60 static int m_nick(struct Client
*, struct Client
*, int, const char **);
61 static int mc_nick(struct Client
*, struct Client
*, int, const char **);
62 static int ms_nick(struct Client
*, struct Client
*, int, const char **);
63 static int ms_uid(struct Client
*, struct Client
*, int, const char **);
64 static int ms_euid(struct Client
*, struct Client
*, int, const char **);
65 static int ms_save(struct Client
*, struct Client
*, int, const char **);
66 static int can_save(struct Client
*);
67 static void save_user(struct Client
*, struct Client
*, struct Client
*);
68 static void bad_nickname(struct Client
*, const char *);
70 struct Message nick_msgtab
= {
71 "NICK", 0, 0, 0, MFLG_SLOW
,
72 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
74 struct Message uid_msgtab
= {
75 "UID", 0, 0, 0, MFLG_SLOW
,
76 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
78 struct Message euid_msgtab
= {
79 "EUID", 0, 0, 0, MFLG_SLOW
,
80 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
82 struct Message save_msgtab
= {
83 "SAVE", 0, 0, 0, MFLG_SLOW
,
84 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
87 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
90 DECLARE_MODULE_AV1(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, "$Revision: 3518 $");
92 static int change_remote_nick(struct Client
*, struct Client
*, time_t,
95 static int clean_nick(const char *, int loc_client
);
96 static int clean_username(const char *);
97 static int clean_host(const char *);
98 static int clean_uid(const char *uid
, const char *sid
);
100 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
101 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
102 static int register_client(struct Client
*client_p
, struct Client
*server
,
103 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
105 static int perform_nick_collides(struct Client
*, struct Client
*,
106 struct Client
*, int, const char **,
107 time_t, const char *, const char *);
108 static int perform_nickchange_collides(struct Client
*, struct Client
*,
109 struct Client
*, int, const char **, time_t, const char *);
115 mr_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
117 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]))
128 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
129 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
133 /* copy the nick and terminate it */
134 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
136 /* check the nickname is ok */
137 if(!clean_nick(nick
, 1))
139 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
140 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
144 /* check if the nick is resv'd */
145 if(find_nick_resv(nick
))
147 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
148 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
152 if(irc_dictionary_find(nd_dict
, nick
))
154 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
155 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
159 if((target_p
= find_named_client(nick
)) == NULL
)
160 set_initial_nick(client_p
, source_p
, nick
);
161 else if(source_p
== target_p
)
162 strcpy(source_p
->name
, nick
);
164 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
173 m_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
175 struct Client
*target_p
;
178 if(parc
< 2 || EmptyString(parv
[1]))
180 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
184 /* mark end of grace period, to prevent nickflooding */
185 if(!IsFloodDone(source_p
))
186 flood_endgrace(source_p
);
188 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
189 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
191 /* check the nickname is ok */
192 if(!clean_nick(nick
, 1))
194 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
198 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
200 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
204 if(irc_dictionary_find(nd_dict
, nick
))
206 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
207 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
211 if((target_p
= find_named_client(nick
)))
213 /* If(target_p == source_p) the client is changing nicks between
214 * equivalent nicknames ie: [nick] -> {nick}
216 if(target_p
== source_p
)
218 /* check the nick isnt exactly the same */
219 if(strcmp(target_p
->name
, nick
))
220 change_local_nick(client_p
, source_p
, nick
, 1);
224 /* drop unregged client */
225 else if(IsUnknown(target_p
))
227 exit_client(NULL
, target_p
, &me
, "Overridden");
228 change_local_nick(client_p
, source_p
, nick
, 1);
231 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
236 change_local_nick(client_p
, source_p
, nick
, 1);
243 * server -> server nick change
245 * parv[2] = TS when nick change
248 mc_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
250 struct Client
*target_p
;
253 /* if nicks erroneous, or too long, kill */
254 if(!clean_nick(parv
[1], 0))
256 bad_nickname(client_p
, parv
[1]);
260 newts
= atol(parv
[2]);
261 target_p
= find_named_client(parv
[1]);
263 /* if the nick doesnt exist, allow it and process like normal */
266 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
268 else if(IsUnknown(target_p
))
270 exit_client(NULL
, target_p
, &me
, "Overridden");
271 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
273 else if(target_p
== source_p
)
275 /* client changing case of nick */
276 if(strcmp(target_p
->name
, parv
[1]))
277 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
279 /* we've got a collision! */
281 perform_nickchange_collides(source_p
, client_p
, target_p
,
282 parc
, parv
, newts
, parv
[1]);
288 ms_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
290 const char *nick
, *server
;
292 nick
= parc
> 1 ? parv
[1] : "?";
293 server
= parc
> 7 ? parv
[7] : "?";
295 sendto_wallops_flags(UMODE_WALLOP
, &me
,
296 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
297 client_p
->name
, nick
, server
);
298 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
299 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
300 me
.id
, client_p
->name
, nick
, server
);
301 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
302 client_p
->name
, nick
, server
);
304 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
321 ms_uid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
323 struct Client
*target_p
;
325 char squitreason
[120];
327 newts
= atol(parv
[3]);
331 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
332 "Dropping server %s due to (invalid) command 'UID' "
333 "with %d arguments (expecting 10)", client_p
->name
, parc
);
334 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
335 parc
, client_p
->name
);
336 rb_snprintf(squitreason
, sizeof squitreason
,
337 "Excess parameters (%d) to %s command, expecting %d",
339 exit_client(client_p
, client_p
, client_p
, squitreason
);
343 /* if nicks erroneous, or too long, kill */
344 if(!clean_nick(parv
[1], 0))
346 bad_nickname(client_p
, parv
[1]);
350 if(!clean_uid(parv
[8], source_p
->id
))
352 rb_snprintf(squitreason
, sizeof squitreason
,
353 "Invalid UID %s for nick %s on %s/%s",
354 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
355 exit_client(client_p
, client_p
, client_p
, squitreason
);
359 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
361 ServerStats
.is_kill
++;
362 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
363 "Bad user@host: %s@%s From: %s(via %s)",
364 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
365 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
369 /* check length of clients gecos */
370 if(strlen(parv
[9]) > REALLEN
)
372 char *s
= LOCAL_COPY(parv
[9]);
373 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
374 source_p
->name
, parv
[1]);
379 target_p
= find_named_client(parv
[1]);
383 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
385 else if(IsUnknown(target_p
))
387 exit_client(NULL
, target_p
, &me
, "Overridden");
388 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
390 /* we've got a collision! */
392 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
393 newts
, parv
[1], parv
[8]);
412 ms_euid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
414 struct Client
*target_p
;
416 char squitreason
[120];
418 newts
= atol(parv
[3]);
422 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
423 "Dropping server %s due to (invalid) command 'EUID' "
424 "with %d arguments (expecting 12)", client_p
->name
, parc
);
425 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
426 parc
, client_p
->name
);
427 rb_snprintf(squitreason
, sizeof squitreason
,
428 "Excess parameters (%d) to %s command, expecting %d",
430 exit_client(client_p
, client_p
, client_p
, squitreason
);
434 /* if nicks erroneous, or too long, kill */
435 if(!clean_nick(parv
[1], 0))
437 bad_nickname(client_p
, parv
[1]);
441 if(!clean_uid(parv
[8], source_p
->id
))
443 rb_snprintf(squitreason
, sizeof squitreason
,
444 "Invalid UID %s for nick %s on %s/%s",
445 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
446 exit_client(client_p
, client_p
, client_p
, squitreason
);
450 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
452 ServerStats
.is_kill
++;
453 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
454 "Bad user@host: %s@%s From: %s(via %s)",
455 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
456 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
460 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
462 ServerStats
.is_kill
++;
463 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
464 "Bad realhost: %s From: %s(via %s)",
465 parv
[9], source_p
->name
, client_p
->name
);
466 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
470 /* check length of clients gecos */
471 if(strlen(parv
[11]) > REALLEN
)
473 char *s
= LOCAL_COPY(parv
[11]);
474 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
475 source_p
->name
, parv
[1]);
480 target_p
= find_named_client(parv
[1]);
484 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
486 else if(IsUnknown(target_p
))
488 exit_client(NULL
, target_p
, &me
, "Overridden");
489 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
491 /* we've got a collision! */
493 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
494 newts
, parv
[1], parv
[8]);
504 ms_save(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
506 struct Client
*target_p
;
508 target_p
= find_id(parv
[1]);
509 if (target_p
== NULL
)
511 if (!IsPerson(target_p
))
512 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
513 "Ignored SAVE message for non-person %s from %s",
514 target_p
->name
, source_p
->name
);
515 else if (IsDigit(target_p
->name
[0]))
516 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
517 "Ignored noop SAVE message for %s from %s",
518 target_p
->name
, source_p
->name
);
519 else if (target_p
->tsinfo
== atol(parv
[2]))
520 save_user(client_p
, source_p
, target_p
);
522 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
523 "Ignored SAVE message for %s from %s",
524 target_p
->name
, source_p
->name
);
530 * input - nickname to check
531 * output - 0 if erroneous, else 1
535 clean_nick(const char *nick
, int loc_client
)
539 /* nicks cant start with a digit or -, and must have a length */
540 if(*nick
== '-' || *nick
== '\0')
543 if(loc_client
&& IsDigit(*nick
))
549 if(!IsNickChar(*nick
))
554 if(len
>= NICKLEN
&& (unsigned int)len
>= ConfigFileEntry
.nicklen
)
562 * input - username to check
563 * output - 0 if erroneous, else 0
567 clean_username(const char *username
)
571 for(; *username
; username
++)
575 if(!IsUserChar(*username
))
587 * input - host to check
588 * output - 0 if erroneous, else 0
592 clean_host(const char *host
)
600 if(!IsHostChar(*host
))
611 clean_uid(const char *uid
, const char *sid
)
615 if(strncmp(uid
, sid
, strlen(sid
)))
636 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
638 char buf
[USERLEN
+ 1];
639 char note
[NICKLEN
+ 10];
641 /* This had to be copied here to avoid problems.. */
642 source_p
->tsinfo
= rb_current_time();
643 if(source_p
->name
[0])
644 del_from_client_hash(source_p
->name
, source_p
);
646 strcpy(source_p
->name
, nick
);
647 add_to_client_hash(nick
, source_p
);
649 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
650 rb_note(client_p
->localClient
->F
, note
);
652 if(source_p
->flags
& FLAGS_SENTUSER
)
654 rb_strlcpy(buf
, source_p
->username
, sizeof(buf
));
656 /* got user, heres nick. */
657 register_local_user(client_p
, source_p
, buf
);
663 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
664 char *nick
, int dosend
)
666 struct Client
*target_p
;
667 rb_dlink_node
*ptr
, *next_ptr
;
668 struct Channel
*chptr
;
669 char note
[NICKLEN
+ 10];
674 chptr
= find_bannickchange_channel(source_p
);
677 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
678 form_str(ERR_BANNICKCHANGE
),
679 nick
, chptr
->chname
);
682 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
683 source_p
->localClient
->number_of_nick_changes
= 0;
685 source_p
->localClient
->last_nick_change
= rb_current_time();
686 source_p
->localClient
->number_of_nick_changes
++;
688 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
689 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
691 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
692 me
.name
, source_p
->name
, source_p
->name
,
693 nick
, ConfigFileEntry
.max_nick_time
);
698 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
700 /* dont reset TS if theyre just changing case of nick */
703 /* force the TS to increase -- jilles */
704 if (source_p
->tsinfo
>= rb_current_time())
707 source_p
->tsinfo
= rb_current_time();
708 monitor_signoff(source_p
);
709 /* we only do bancache for local users -- jilles */
711 invalidate_bancache_user(source_p
);
714 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
715 "Nick change: From %s to %s [%s@%s]",
716 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
718 /* send the nick change to the users channels */
719 sendto_common_channels_local(source_p
, NOCAPS
, ":%s!%s@%s NICK :%s",
720 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
722 /* send the nick change to servers.. */
725 add_history(source_p
, 1);
729 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
730 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
734 /* Finally, add to hash */
735 del_from_client_hash(source_p
->name
, source_p
);
736 strcpy(source_p
->name
, nick
);
737 add_to_client_hash(nick
, source_p
);
740 monitor_signon(source_p
);
742 /* Make sure everyone that has this client on its accept list
743 * loses that reference.
745 /* we used to call del_all_accepts() here, but theres no real reason
746 * to clear a clients own list of accepted clients. So just remove
747 * them from everyone elses list --anfl
749 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
751 target_p
= ptr
->data
;
753 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
754 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
757 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
758 rb_note(client_p
->localClient
->F
, note
);
764 * change_remote_nick()
767 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
768 time_t newts
, const char *nick
, int dosend
)
771 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
773 /* client changing their nick - dont reset ts if its same */
776 source_p
->tsinfo
= newts
? newts
: rb_current_time();
777 monitor_signoff(source_p
);
780 sendto_common_channels_local(source_p
, NOCAPS
, ":%s!%s@%s NICK :%s",
781 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
785 add_history(source_p
, 1);
788 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
789 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
793 del_from_client_hash(source_p
->name
, source_p
);
795 /* invalidate nick delay when a remote client uses the nick.. */
796 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
799 strcpy(source_p
->name
, nick
);
800 add_to_client_hash(nick
, source_p
);
803 monitor_signon(source_p
);
805 /* remove all accepts pointing to the client */
806 del_all_accepts(source_p
);
812 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
813 struct Client
*target_p
, int parc
, const char *parv
[],
814 time_t newts
, const char *nick
, const char *uid
)
820 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
821 uid
!= NULL
&& can_save(source_p
);
822 action
= use_save
? "saved" : "killed";
824 /* if we dont have a ts, or their TS's are the same, kill both */
825 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
827 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
828 "Nick collision on %s(%s <- %s)(both %s)",
829 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
833 save_user(&me
, &me
, target_p
);
834 ServerStats
.is_save
++;
835 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
837 register_client(client_p
, source_p
,
838 uid
, SAVE_NICKTS
, parc
, parv
);
842 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
843 form_str(ERR_NICKCOLLISION
), target_p
->name
);
845 /* if the new client being introduced has a UID, we need to
846 * issue a KILL for it..
849 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
850 me
.id
, uid
, me
.name
);
852 /* we then need to KILL the old client everywhere */
853 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
854 ServerStats
.is_kill
++;
856 target_p
->flags
|= FLAGS_KILLED
;
857 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
861 /* the timestamps are different */
864 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
865 && !irccmp(target_p
->host
, parv
[6]);
867 if((sameuser
&& newts
< target_p
->tsinfo
) ||
868 (!sameuser
&& newts
> target_p
->tsinfo
))
870 /* if we have a UID, then we need to issue a KILL,
871 * otherwise we do nothing and hope that the other
872 * client will collide it..
876 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
878 register_client(client_p
, source_p
,
879 uid
, SAVE_NICKTS
, parc
, parv
);
883 ":%s KILL %s :%s (Nick collision (new))",
884 me
.id
, uid
, me
.name
);
890 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
891 "Nick collision on %s(%s <- %s)(older %s)",
892 target_p
->name
, target_p
->from
->name
,
893 client_p
->name
, action
);
895 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
896 "Nick collision on %s(%s <- %s)(newer %s)",
897 target_p
->name
, target_p
->from
->name
,
898 client_p
->name
, action
);
902 ServerStats
.is_save
++;
903 save_user(&me
, &me
, target_p
);
907 ServerStats
.is_kill
++;
908 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
909 form_str(ERR_NICKCOLLISION
), target_p
->name
);
911 /* now we just need to kill the existing client */
912 kill_client_serv_butone(client_p
, target_p
,
913 "%s (Nick collision (new))", me
.name
);
915 target_p
->flags
|= FLAGS_KILLED
;
916 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
919 register_client(client_p
, source_p
,
920 nick
, newts
, parc
, parv
);
929 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
930 struct Client
*target_p
, int parc
,
931 const char *parv
[], time_t newts
, const char *nick
)
937 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
939 action
= use_save
? "saved" : "killed";
941 /* its a client changing nick and causing a collide */
942 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
944 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
945 "Nick change collision from %s to %s(%s <- %s)(both %s)",
946 source_p
->name
, target_p
->name
, target_p
->from
->name
,
947 client_p
->name
, action
);
951 ServerStats
.is_save
+= 2;
952 save_user(&me
, &me
, target_p
);
953 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
954 source_p
->id
, (long)newts
);
955 /* don't send a redundant nick change */
956 if (!IsDigit(source_p
->name
[0]))
957 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
961 ServerStats
.is_kill
++;
962 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
963 form_str(ERR_NICKCOLLISION
), target_p
->name
);
965 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
967 ServerStats
.is_kill
++;
969 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
971 target_p
->flags
|= FLAGS_KILLED
;
972 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
973 source_p
->flags
|= FLAGS_KILLED
;
974 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
980 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
981 !irccmp(target_p
->host
, source_p
->host
);
983 if((sameuser
&& newts
< target_p
->tsinfo
) ||
984 (!sameuser
&& newts
> target_p
->tsinfo
))
987 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
988 "Nick change collision from %s to %s(%s <- %s)(older %s)",
989 source_p
->name
, target_p
->name
,
990 target_p
->from
->name
, client_p
->name
, action
);
992 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
993 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
994 source_p
->name
, target_p
->name
,
995 target_p
->from
->name
, client_p
->name
, action
);
999 ServerStats
.is_save
++;
1000 /* can't broadcast a SAVE because the
1001 * nickchange has happened at client_p
1002 * but not in other directions -- jilles */
1003 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1004 source_p
->id
, (long)newts
);
1005 /* send a :<id> NICK <id> <ts> (!) */
1006 if (!IsDigit(source_p
->name
[0]))
1007 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1011 ServerStats
.is_kill
++;
1013 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
1014 form_str(ERR_NICKCOLLISION
), source_p
->name
);
1016 /* kill the client issuing the nickchange */
1017 kill_client_serv_butone(client_p
, source_p
,
1018 "%s (Nick change collision)", me
.name
);
1020 source_p
->flags
|= FLAGS_KILLED
;
1023 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1025 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1032 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1033 "Nick collision on %s(%s <- %s)(older %s)",
1034 target_p
->name
, target_p
->from
->name
,
1035 client_p
->name
, action
);
1037 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1038 "Nick collision on %s(%s <- %s)(newer %s)",
1039 target_p
->name
, target_p
->from
->name
,
1040 client_p
->name
, action
);
1044 ServerStats
.is_save
++;
1045 save_user(&me
, &me
, target_p
);
1049 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1050 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1052 /* kill the client who existed before hand */
1053 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1055 ServerStats
.is_kill
++;
1057 target_p
->flags
|= FLAGS_KILLED
;
1058 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1063 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1069 register_client(struct Client
*client_p
, struct Client
*server
,
1070 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1072 struct Client
*source_p
;
1074 struct nd_entry
*nd
;
1078 source_p
= make_client(client_p
);
1079 user
= make_user(source_p
);
1080 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1082 source_p
->hopcount
= atoi(parv
[2]);
1083 source_p
->tsinfo
= newts
;
1085 strcpy(source_p
->name
, nick
);
1086 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1087 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1088 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1092 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1093 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1094 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1095 add_to_id_hash(source_p
->id
, source_p
);
1096 if (strcmp(parv
[9], "*"))
1098 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1099 if (irccmp(source_p
->host
, source_p
->orighost
))
1100 SetDynSpoof(source_p
);
1102 if (strcmp(parv
[10], "*"))
1103 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1107 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1108 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1109 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1110 add_to_id_hash(source_p
->id
, source_p
);
1117 /* remove any nd entries for this nick */
1118 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1121 add_to_client_hash(nick
, source_p
);
1122 add_to_hostname_hash(source_p
->orighost
, source_p
);
1123 monitor_signon(source_p
);
1128 flag
= user_modes
[(unsigned char) *m
];
1130 if(flag
& UMODE_SERVICE
)
1135 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1137 if(!irccmp((const char *) ptr
->data
, server
->name
))
1151 /* increment +i count if theyre invis */
1152 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1155 /* increment opered count if theyre opered */
1156 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1159 source_p
->umodes
|= flag
;
1163 if(IsOper(source_p
) && !IsService(source_p
))
1164 rb_dlinkAddAlloc(source_p
, &oper_list
);
1166 SetRemoteClient(source_p
);
1168 if(++Count
.total
> Count
.max_tot
)
1169 Count
.max_tot
= Count
.total
;
1171 source_p
->servptr
= server
;
1173 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1175 call_hook(h_new_remote_user
, source_p
);
1177 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1180 /* Check if we can do SAVE. target_p can be a client to save or a
1181 * server introducing a client -- jilles */
1183 can_save(struct Client
*target_p
)
1185 struct Client
*serv_p
;
1187 if (MyClient(target_p
))
1189 if (!has_id(target_p
))
1191 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1192 while (serv_p
!= NULL
&& serv_p
!= &me
)
1194 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1196 serv_p
= serv_p
->servptr
;
1198 return serv_p
== &me
;
1202 save_user(struct Client
*client_p
, struct Client
*source_p
,
1203 struct Client
*target_p
)
1205 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1207 /* This shouldn't happen */
1208 /* Note we only need SAVE support in this direction */
1209 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1210 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1211 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1212 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1213 ServerStats
.is_kill
++;
1215 target_p
->flags
|= FLAGS_KILLED
;
1216 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1219 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1220 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1221 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1222 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1223 if (!IsMe(client_p
))
1224 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1225 "Received SAVE message for %s from %s",
1226 target_p
->name
, source_p
->name
);
1227 if (MyClient(target_p
))
1229 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1230 form_str(RPL_SAVENICK
), target_p
->id
);
1231 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1232 target_p
->tsinfo
= SAVE_NICKTS
;
1235 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1238 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1240 char squitreason
[100];
1242 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1243 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1244 client_p
->name
, nick
);
1245 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1246 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1247 me
.id
, client_p
->name
, nick
);
1248 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1249 client_p
->name
, nick
);
1251 rb_snprintf(squitreason
, sizeof squitreason
,
1252 "Bad nickname introduced [%s]", nick
);
1253 exit_client(client_p
, client_p
, &me
, squitreason
);