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 note
[NICKLEN
+ 10];
640 /* This had to be copied here to avoid problems.. */
641 source_p
->tsinfo
= rb_current_time();
642 if(source_p
->name
[0])
643 del_from_client_hash(source_p
->name
, source_p
);
645 strcpy(source_p
->name
, nick
);
646 add_to_client_hash(nick
, source_p
);
648 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
649 rb_note(client_p
->localClient
->F
, note
);
651 if(source_p
->flags
& FLAGS_SENTUSER
)
653 /* got user, heres nick. */
654 register_local_user(client_p
, source_p
);
659 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
660 char *nick
, int dosend
)
662 struct Client
*target_p
;
663 rb_dlink_node
*ptr
, *next_ptr
;
664 struct Channel
*chptr
;
665 char note
[NICKLEN
+ 10];
670 chptr
= find_bannickchange_channel(source_p
);
673 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
674 form_str(ERR_BANNICKCHANGE
),
675 nick
, chptr
->chname
);
678 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
679 source_p
->localClient
->number_of_nick_changes
= 0;
681 source_p
->localClient
->last_nick_change
= rb_current_time();
682 source_p
->localClient
->number_of_nick_changes
++;
684 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
685 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
687 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
688 me
.name
, source_p
->name
, source_p
->name
,
689 nick
, ConfigFileEntry
.max_nick_time
);
694 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
696 /* dont reset TS if theyre just changing case of nick */
699 /* force the TS to increase -- jilles */
700 if (source_p
->tsinfo
>= rb_current_time())
703 source_p
->tsinfo
= rb_current_time();
704 monitor_signoff(source_p
);
705 /* we only do bancache for local users -- jilles */
707 invalidate_bancache_user(source_p
);
710 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
711 "Nick change: From %s to %s [%s@%s]",
712 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
714 /* send the nick change to the users channels */
715 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
716 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
718 /* send the nick change to servers.. */
721 add_history(source_p
, 1);
725 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
726 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
730 /* Finally, add to hash */
731 del_from_client_hash(source_p
->name
, source_p
);
732 strcpy(source_p
->name
, nick
);
733 add_to_client_hash(nick
, source_p
);
736 monitor_signon(source_p
);
738 /* Make sure everyone that has this client on its accept list
739 * loses that reference.
741 /* we used to call del_all_accepts() here, but theres no real reason
742 * to clear a clients own list of accepted clients. So just remove
743 * them from everyone elses list --anfl
745 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
747 target_p
= ptr
->data
;
749 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
750 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
753 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
754 rb_note(client_p
->localClient
->F
, note
);
760 * change_remote_nick()
763 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
764 time_t newts
, const char *nick
, int dosend
)
767 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
769 /* client changing their nick - dont reset ts if its same */
772 source_p
->tsinfo
= newts
? newts
: rb_current_time();
773 monitor_signoff(source_p
);
776 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
777 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
781 add_history(source_p
, 1);
784 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
785 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
789 del_from_client_hash(source_p
->name
, source_p
);
791 /* invalidate nick delay when a remote client uses the nick.. */
792 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
795 strcpy(source_p
->name
, nick
);
796 add_to_client_hash(nick
, source_p
);
799 monitor_signon(source_p
);
801 /* remove all accepts pointing to the client */
802 del_all_accepts(source_p
);
808 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
809 struct Client
*target_p
, int parc
, const char *parv
[],
810 time_t newts
, const char *nick
, const char *uid
)
816 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
817 uid
!= NULL
&& can_save(source_p
);
818 action
= use_save
? "saved" : "killed";
820 /* if we dont have a ts, or their TS's are the same, kill both */
821 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
823 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
824 "Nick collision on %s(%s <- %s)(both %s)",
825 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
829 save_user(&me
, &me
, target_p
);
830 ServerStats
.is_save
++;
831 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
833 register_client(client_p
, source_p
,
834 uid
, SAVE_NICKTS
, parc
, parv
);
838 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
839 form_str(ERR_NICKCOLLISION
), target_p
->name
);
841 /* if the new client being introduced has a UID, we need to
842 * issue a KILL for it..
845 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
846 me
.id
, uid
, me
.name
);
848 /* we then need to KILL the old client everywhere */
849 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
850 ServerStats
.is_kill
++;
852 target_p
->flags
|= FLAGS_KILLED
;
853 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
857 /* the timestamps are different */
860 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
861 && !irccmp(target_p
->host
, parv
[6]);
863 if((sameuser
&& newts
< target_p
->tsinfo
) ||
864 (!sameuser
&& newts
> target_p
->tsinfo
))
866 /* if we have a UID, then we need to issue a KILL,
867 * otherwise we do nothing and hope that the other
868 * client will collide it..
872 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
874 register_client(client_p
, source_p
,
875 uid
, SAVE_NICKTS
, parc
, parv
);
879 ":%s KILL %s :%s (Nick collision (new))",
880 me
.id
, uid
, me
.name
);
886 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
887 "Nick collision on %s(%s <- %s)(older %s)",
888 target_p
->name
, target_p
->from
->name
,
889 client_p
->name
, action
);
891 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
892 "Nick collision on %s(%s <- %s)(newer %s)",
893 target_p
->name
, target_p
->from
->name
,
894 client_p
->name
, action
);
898 ServerStats
.is_save
++;
899 save_user(&me
, &me
, target_p
);
903 ServerStats
.is_kill
++;
904 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
905 form_str(ERR_NICKCOLLISION
), target_p
->name
);
907 /* now we just need to kill the existing client */
908 kill_client_serv_butone(client_p
, target_p
,
909 "%s (Nick collision (new))", me
.name
);
911 target_p
->flags
|= FLAGS_KILLED
;
912 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
915 register_client(client_p
, source_p
,
916 nick
, newts
, parc
, parv
);
925 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
926 struct Client
*target_p
, int parc
,
927 const char *parv
[], time_t newts
, const char *nick
)
933 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
935 action
= use_save
? "saved" : "killed";
937 /* its a client changing nick and causing a collide */
938 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
940 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
941 "Nick change collision from %s to %s(%s <- %s)(both %s)",
942 source_p
->name
, target_p
->name
, target_p
->from
->name
,
943 client_p
->name
, action
);
947 ServerStats
.is_save
+= 2;
948 save_user(&me
, &me
, target_p
);
949 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
950 source_p
->id
, (long)newts
);
951 /* don't send a redundant nick change */
952 if (!IsDigit(source_p
->name
[0]))
953 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
957 ServerStats
.is_kill
++;
958 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
959 form_str(ERR_NICKCOLLISION
), target_p
->name
);
961 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
963 ServerStats
.is_kill
++;
965 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
967 target_p
->flags
|= FLAGS_KILLED
;
968 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
969 source_p
->flags
|= FLAGS_KILLED
;
970 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
976 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
977 !irccmp(target_p
->host
, source_p
->host
);
979 if((sameuser
&& newts
< target_p
->tsinfo
) ||
980 (!sameuser
&& newts
> target_p
->tsinfo
))
983 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
984 "Nick change collision from %s to %s(%s <- %s)(older %s)",
985 source_p
->name
, target_p
->name
,
986 target_p
->from
->name
, client_p
->name
, action
);
988 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
989 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
990 source_p
->name
, target_p
->name
,
991 target_p
->from
->name
, client_p
->name
, action
);
995 ServerStats
.is_save
++;
996 /* can't broadcast a SAVE because the
997 * nickchange has happened at client_p
998 * but not in other directions -- jilles */
999 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1000 source_p
->id
, (long)newts
);
1001 /* send a :<id> NICK <id> <ts> (!) */
1002 if (!IsDigit(source_p
->name
[0]))
1003 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1007 ServerStats
.is_kill
++;
1009 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
1010 form_str(ERR_NICKCOLLISION
), source_p
->name
);
1012 /* kill the client issuing the nickchange */
1013 kill_client_serv_butone(client_p
, source_p
,
1014 "%s (Nick change collision)", me
.name
);
1016 source_p
->flags
|= FLAGS_KILLED
;
1019 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1021 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1028 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1029 "Nick collision on %s(%s <- %s)(older %s)",
1030 target_p
->name
, target_p
->from
->name
,
1031 client_p
->name
, action
);
1033 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1034 "Nick collision on %s(%s <- %s)(newer %s)",
1035 target_p
->name
, target_p
->from
->name
,
1036 client_p
->name
, action
);
1040 ServerStats
.is_save
++;
1041 save_user(&me
, &me
, target_p
);
1045 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1046 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1048 /* kill the client who existed before hand */
1049 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1051 ServerStats
.is_kill
++;
1053 target_p
->flags
|= FLAGS_KILLED
;
1054 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1059 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1065 register_client(struct Client
*client_p
, struct Client
*server
,
1066 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1068 struct Client
*source_p
;
1070 struct nd_entry
*nd
;
1074 source_p
= make_client(client_p
);
1075 user
= make_user(source_p
);
1076 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1078 source_p
->hopcount
= atoi(parv
[2]);
1079 source_p
->tsinfo
= newts
;
1081 strcpy(source_p
->name
, nick
);
1082 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1083 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1084 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1088 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1089 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1090 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1091 add_to_id_hash(source_p
->id
, source_p
);
1092 if (strcmp(parv
[9], "*"))
1094 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1095 if (irccmp(source_p
->host
, source_p
->orighost
))
1096 SetDynSpoof(source_p
);
1098 if (strcmp(parv
[10], "*"))
1099 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1103 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1104 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1105 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1106 add_to_id_hash(source_p
->id
, source_p
);
1113 /* remove any nd entries for this nick */
1114 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1117 add_to_client_hash(nick
, source_p
);
1118 add_to_hostname_hash(source_p
->orighost
, source_p
);
1119 monitor_signon(source_p
);
1124 flag
= user_modes
[(unsigned char) *m
];
1126 if(flag
& UMODE_SERVICE
)
1131 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1133 if(!irccmp((const char *) ptr
->data
, server
->name
))
1147 /* increment +i count if theyre invis */
1148 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1151 /* increment opered count if theyre opered */
1152 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1155 source_p
->umodes
|= flag
;
1159 if(IsOper(source_p
) && !IsService(source_p
))
1160 rb_dlinkAddAlloc(source_p
, &oper_list
);
1162 SetRemoteClient(source_p
);
1164 if(++Count
.total
> Count
.max_tot
)
1165 Count
.max_tot
= Count
.total
;
1167 source_p
->servptr
= server
;
1169 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1171 call_hook(h_new_remote_user
, source_p
);
1173 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1176 /* Check if we can do SAVE. target_p can be a client to save or a
1177 * server introducing a client -- jilles */
1179 can_save(struct Client
*target_p
)
1181 struct Client
*serv_p
;
1183 if (MyClient(target_p
))
1185 if (!has_id(target_p
))
1187 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1188 while (serv_p
!= NULL
&& serv_p
!= &me
)
1190 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1192 serv_p
= serv_p
->servptr
;
1194 return serv_p
== &me
;
1198 save_user(struct Client
*client_p
, struct Client
*source_p
,
1199 struct Client
*target_p
)
1201 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1203 /* This shouldn't happen */
1204 /* Note we only need SAVE support in this direction */
1205 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1206 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1207 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1208 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1209 ServerStats
.is_kill
++;
1211 target_p
->flags
|= FLAGS_KILLED
;
1212 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1215 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1216 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1217 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1218 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1219 if (!IsMe(client_p
))
1220 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1221 "Received SAVE message for %s from %s",
1222 target_p
->name
, source_p
->name
);
1223 if (MyClient(target_p
))
1225 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1226 form_str(RPL_SAVENICK
), target_p
->id
);
1227 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1228 target_p
->tsinfo
= SAVE_NICKTS
;
1231 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1234 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1236 char squitreason
[100];
1238 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1239 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1240 client_p
->name
, nick
);
1241 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1242 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1243 me
.id
, client_p
->name
, nick
);
1244 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1245 client_p
->name
, nick
);
1247 rb_snprintf(squitreason
, sizeof squitreason
,
1248 "Bad nickname introduced [%s]", nick
);
1249 exit_client(client_p
, client_p
, &me
, squitreason
);