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
, const char *sid
);
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
;
119 if (strlen(client_p
->id
) == 3)
121 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
125 if(parc
< 2 || EmptyString(parv
[1]))
127 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
128 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
132 /* copy the nick and terminate it */
133 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
135 /* check the nickname is ok */
136 if(!clean_nick(nick
, 1))
138 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
139 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
143 /* check if the nick is resv'd */
144 if(find_nick_resv(nick
))
146 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
147 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
151 if(irc_dictionary_find(nd_dict
, nick
))
153 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
154 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
158 if((target_p
= find_named_client(nick
)) == NULL
)
159 set_initial_nick(client_p
, source_p
, nick
);
160 else if(source_p
== target_p
)
161 strcpy(source_p
->name
, nick
);
163 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
172 m_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
174 struct Client
*target_p
;
177 if(parc
< 2 || EmptyString(parv
[1]))
179 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
183 /* mark end of grace period, to prevent nickflooding */
184 if(!IsFloodDone(source_p
))
185 flood_endgrace(source_p
);
187 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
188 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
190 /* check the nickname is ok */
191 if(!clean_nick(nick
, 1))
193 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
197 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
199 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
203 if(irc_dictionary_find(nd_dict
, nick
))
205 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
206 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
210 if((target_p
= find_named_client(nick
)))
212 /* If(target_p == source_p) the client is changing nicks between
213 * equivalent nicknames ie: [nick] -> {nick}
215 if(target_p
== source_p
)
217 /* check the nick isnt exactly the same */
218 if(strcmp(target_p
->name
, nick
))
219 change_local_nick(client_p
, source_p
, nick
, 1);
223 /* drop unregged client */
224 else if(IsUnknown(target_p
))
226 exit_client(NULL
, target_p
, &me
, "Overridden");
227 change_local_nick(client_p
, source_p
, nick
, 1);
230 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
235 change_local_nick(client_p
, source_p
, nick
, 1);
242 * server -> server nick change
244 * parv[2] = TS when nick change
247 mc_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
249 struct Client
*target_p
;
252 /* if nicks erroneous, or too long, kill */
253 if(!clean_nick(parv
[1], 0))
255 bad_nickname(client_p
, parv
[1]);
259 newts
= atol(parv
[2]);
260 target_p
= find_named_client(parv
[1]);
262 /* if the nick doesnt exist, allow it and process like normal */
265 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
267 else if(IsUnknown(target_p
))
269 exit_client(NULL
, target_p
, &me
, "Overridden");
270 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
272 else if(target_p
== source_p
)
274 /* client changing case of nick */
275 if(strcmp(target_p
->name
, parv
[1]))
276 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
278 /* we've got a collision! */
280 perform_nickchange_collides(source_p
, client_p
, target_p
,
281 parc
, parv
, newts
, parv
[1]);
287 ms_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
289 const char *nick
, *server
;
291 nick
= parc
> 1 ? parv
[1] : "?";
292 server
= parc
> 7 ? parv
[7] : "?";
294 sendto_wallops_flags(UMODE_WALLOP
, &me
,
295 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
296 client_p
->name
, nick
, server
);
297 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
298 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
299 me
.id
, client_p
->name
, nick
, server
);
300 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
301 client_p
->name
, nick
, server
);
303 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
320 ms_uid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
322 struct Client
*target_p
;
324 char squitreason
[120];
326 newts
= atol(parv
[3]);
330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
331 "Dropping server %s due to (invalid) command 'UID' "
332 "with %d arguments (expecting 10)", client_p
->name
, parc
);
333 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
334 parc
, client_p
->name
);
335 rb_snprintf(squitreason
, sizeof squitreason
,
336 "Excess parameters (%d) to %s command, expecting %d",
338 exit_client(client_p
, client_p
, client_p
, squitreason
);
342 /* if nicks erroneous, or too long, kill */
343 if(!clean_nick(parv
[1], 0))
345 bad_nickname(client_p
, parv
[1]);
349 if(!clean_uid(parv
[8], source_p
->id
))
351 rb_snprintf(squitreason
, sizeof squitreason
,
352 "Invalid UID %s for nick %s on %s/%s",
353 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
354 exit_client(client_p
, client_p
, client_p
, squitreason
);
358 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
360 ServerStats
.is_kill
++;
361 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
362 "Bad user@host: %s@%s From: %s(via %s)",
363 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
364 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
368 /* check length of clients gecos */
369 if(strlen(parv
[9]) > REALLEN
)
371 char *s
= LOCAL_COPY(parv
[9]);
372 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
373 source_p
->name
, parv
[1]);
378 target_p
= find_named_client(parv
[1]);
382 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
384 else if(IsUnknown(target_p
))
386 exit_client(NULL
, target_p
, &me
, "Overridden");
387 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
389 /* we've got a collision! */
391 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
392 newts
, parv
[1], parv
[8]);
411 ms_euid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
413 struct Client
*target_p
;
415 char squitreason
[120];
417 newts
= atol(parv
[3]);
421 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
422 "Dropping server %s due to (invalid) command 'EUID' "
423 "with %d arguments (expecting 12)", client_p
->name
, parc
);
424 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
425 parc
, client_p
->name
);
426 rb_snprintf(squitreason
, sizeof squitreason
,
427 "Excess parameters (%d) to %s command, expecting %d",
429 exit_client(client_p
, client_p
, client_p
, squitreason
);
433 /* if nicks erroneous, or too long, kill */
434 if(!clean_nick(parv
[1], 0))
436 bad_nickname(client_p
, parv
[1]);
440 if(!clean_uid(parv
[8], source_p
->id
))
442 rb_snprintf(squitreason
, sizeof squitreason
,
443 "Invalid UID %s for nick %s on %s/%s",
444 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
445 exit_client(client_p
, client_p
, client_p
, squitreason
);
449 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
451 ServerStats
.is_kill
++;
452 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
453 "Bad user@host: %s@%s From: %s(via %s)",
454 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
455 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
459 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
461 ServerStats
.is_kill
++;
462 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
463 "Bad realhost: %s From: %s(via %s)",
464 parv
[9], source_p
->name
, client_p
->name
);
465 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
469 /* check length of clients gecos */
470 if(strlen(parv
[11]) > REALLEN
)
472 char *s
= LOCAL_COPY(parv
[11]);
473 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
474 source_p
->name
, parv
[1]);
479 target_p
= find_named_client(parv
[1]);
483 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
485 else if(IsUnknown(target_p
))
487 exit_client(NULL
, target_p
, &me
, "Overridden");
488 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
490 /* we've got a collision! */
492 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
493 newts
, parv
[1], parv
[8]);
503 ms_save(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
505 struct Client
*target_p
;
507 target_p
= find_id(parv
[1]);
508 if (target_p
== NULL
)
510 if (!IsPerson(target_p
))
511 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
512 "Ignored SAVE message for non-person %s from %s",
513 target_p
->name
, source_p
->name
);
514 else if (IsDigit(target_p
->name
[0]))
515 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
516 "Ignored noop SAVE message for %s from %s",
517 target_p
->name
, source_p
->name
);
518 else if (target_p
->tsinfo
== atol(parv
[2]))
519 save_user(client_p
, source_p
, target_p
);
521 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
522 "Ignored SAVE message for %s from %s",
523 target_p
->name
, source_p
->name
);
529 * input - nickname to check
530 * output - 0 if erroneous, else 1
534 clean_nick(const char *nick
, int loc_client
)
538 /* nicks cant start with a digit or -, and must have a length */
539 if(*nick
== '-' || *nick
== '\0')
542 if(loc_client
&& IsDigit(*nick
))
548 if(!IsNickChar(*nick
))
553 if(len
>= NICKLEN
&& len
>= ConfigFileEntry
.nicklen
)
561 * input - username to check
562 * output - 0 if erroneous, else 0
566 clean_username(const char *username
)
570 for(; *username
; username
++)
574 if(!IsUserChar(*username
))
586 * input - host to check
587 * output - 0 if erroneous, else 0
591 clean_host(const char *host
)
599 if(!IsHostChar(*host
))
610 clean_uid(const char *uid
, const char *sid
)
614 if(strncmp(uid
, sid
, strlen(sid
)))
635 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
637 char buf
[USERLEN
+ 1];
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 rb_strlcpy(buf
, source_p
->username
, sizeof(buf
));
655 /* got user, heres nick. */
656 register_local_user(client_p
, source_p
, buf
);
662 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
663 char *nick
, int dosend
)
665 struct Client
*target_p
;
666 rb_dlink_node
*ptr
, *next_ptr
;
667 struct Channel
*chptr
;
668 char note
[NICKLEN
+ 10];
673 chptr
= find_bannickchange_channel(source_p
);
676 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
677 form_str(ERR_BANNICKCHANGE
),
678 nick
, chptr
->chname
);
681 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
682 source_p
->localClient
->number_of_nick_changes
= 0;
684 source_p
->localClient
->last_nick_change
= rb_current_time();
685 source_p
->localClient
->number_of_nick_changes
++;
687 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
688 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
690 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
691 me
.name
, source_p
->name
, source_p
->name
,
692 nick
, ConfigFileEntry
.max_nick_time
);
697 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
699 /* dont reset TS if theyre just changing case of nick */
702 /* force the TS to increase -- jilles */
703 if (source_p
->tsinfo
>= rb_current_time())
706 source_p
->tsinfo
= rb_current_time();
707 monitor_signoff(source_p
);
708 /* we only do bancache for local users -- jilles */
710 invalidate_bancache_user(source_p
);
713 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
714 "Nick change: From %s to %s [%s@%s]",
715 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
717 /* send the nick change to the users channels */
718 sendto_common_channels_local(source_p
, NOCAPS
, ":%s!%s@%s NICK :%s",
719 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
721 /* send the nick change to servers.. */
724 add_history(source_p
, 1);
728 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
729 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
733 /* Finally, add to hash */
734 del_from_client_hash(source_p
->name
, source_p
);
735 strcpy(source_p
->name
, nick
);
736 add_to_client_hash(nick
, source_p
);
739 monitor_signon(source_p
);
741 /* Make sure everyone that has this client on its accept list
742 * loses that reference.
744 /* we used to call del_all_accepts() here, but theres no real reason
745 * to clear a clients own list of accepted clients. So just remove
746 * them from everyone elses list --anfl
748 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
750 target_p
= ptr
->data
;
752 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
753 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
756 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
757 rb_note(client_p
->localClient
->F
, note
);
763 * change_remote_nick()
766 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
767 time_t newts
, const char *nick
, int dosend
)
770 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
772 /* client changing their nick - dont reset ts if its same */
775 source_p
->tsinfo
= newts
? newts
: rb_current_time();
776 monitor_signoff(source_p
);
779 sendto_common_channels_local(source_p
, NOCAPS
, ":%s!%s@%s NICK :%s",
780 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
784 add_history(source_p
, 1);
787 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
788 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
792 del_from_client_hash(source_p
->name
, source_p
);
794 /* invalidate nick delay when a remote client uses the nick.. */
795 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
798 strcpy(source_p
->name
, nick
);
799 add_to_client_hash(nick
, source_p
);
802 monitor_signon(source_p
);
804 /* remove all accepts pointing to the client */
805 del_all_accepts(source_p
);
811 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
812 struct Client
*target_p
, int parc
, const char *parv
[],
813 time_t newts
, const char *nick
, const char *uid
)
819 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
820 uid
!= NULL
&& can_save(source_p
);
821 action
= use_save
? "saved" : "killed";
823 /* if we dont have a ts, or their TS's are the same, kill both */
824 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
826 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
827 "Nick collision on %s(%s <- %s)(both %s)",
828 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
832 save_user(&me
, &me
, target_p
);
833 ServerStats
.is_save
++;
834 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
836 register_client(client_p
, source_p
,
837 uid
, SAVE_NICKTS
, parc
, parv
);
841 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
842 form_str(ERR_NICKCOLLISION
), target_p
->name
);
844 /* if the new client being introduced has a UID, we need to
845 * issue a KILL for it..
848 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
849 me
.id
, uid
, me
.name
);
851 /* we then need to KILL the old client everywhere */
852 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
853 ServerStats
.is_kill
++;
855 target_p
->flags
|= FLAGS_KILLED
;
856 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
860 /* the timestamps are different */
863 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
864 && !irccmp(target_p
->host
, parv
[6]);
866 if((sameuser
&& newts
< target_p
->tsinfo
) ||
867 (!sameuser
&& newts
> target_p
->tsinfo
))
869 /* if we have a UID, then we need to issue a KILL,
870 * otherwise we do nothing and hope that the other
871 * client will collide it..
875 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
877 register_client(client_p
, source_p
,
878 uid
, SAVE_NICKTS
, parc
, parv
);
882 ":%s KILL %s :%s (Nick collision (new))",
883 me
.id
, uid
, me
.name
);
889 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
890 "Nick collision on %s(%s <- %s)(older %s)",
891 target_p
->name
, target_p
->from
->name
,
892 client_p
->name
, action
);
894 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
895 "Nick collision on %s(%s <- %s)(newer %s)",
896 target_p
->name
, target_p
->from
->name
,
897 client_p
->name
, action
);
901 ServerStats
.is_save
++;
902 save_user(&me
, &me
, target_p
);
906 ServerStats
.is_kill
++;
907 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
908 form_str(ERR_NICKCOLLISION
), target_p
->name
);
910 /* now we just need to kill the existing client */
911 kill_client_serv_butone(client_p
, target_p
,
912 "%s (Nick collision (new))", me
.name
);
914 target_p
->flags
|= FLAGS_KILLED
;
915 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
918 register_client(client_p
, source_p
,
919 nick
, newts
, parc
, parv
);
928 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
929 struct Client
*target_p
, int parc
,
930 const char *parv
[], time_t newts
, const char *nick
)
936 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
938 action
= use_save
? "saved" : "killed";
940 /* its a client changing nick and causing a collide */
941 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
943 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
944 "Nick change collision from %s to %s(%s <- %s)(both %s)",
945 source_p
->name
, target_p
->name
, target_p
->from
->name
,
946 client_p
->name
, action
);
950 ServerStats
.is_save
+= 2;
951 save_user(&me
, &me
, target_p
);
952 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
953 source_p
->id
, (long)newts
);
954 /* don't send a redundant nick change */
955 if (!IsDigit(source_p
->name
[0]))
956 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
960 ServerStats
.is_kill
++;
961 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
962 form_str(ERR_NICKCOLLISION
), target_p
->name
);
964 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
966 ServerStats
.is_kill
++;
968 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
970 target_p
->flags
|= FLAGS_KILLED
;
971 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
972 source_p
->flags
|= FLAGS_KILLED
;
973 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
979 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
980 !irccmp(target_p
->host
, source_p
->host
);
982 if((sameuser
&& newts
< target_p
->tsinfo
) ||
983 (!sameuser
&& newts
> target_p
->tsinfo
))
986 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
987 "Nick change collision from %s to %s(%s <- %s)(older %s)",
988 source_p
->name
, target_p
->name
,
989 target_p
->from
->name
, client_p
->name
, action
);
991 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
992 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
993 source_p
->name
, target_p
->name
,
994 target_p
->from
->name
, client_p
->name
, action
);
998 ServerStats
.is_save
++;
999 /* can't broadcast a SAVE because the
1000 * nickchange has happened at client_p
1001 * but not in other directions -- jilles */
1002 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1003 source_p
->id
, (long)newts
);
1004 /* send a :<id> NICK <id> <ts> (!) */
1005 if (!IsDigit(source_p
->name
[0]))
1006 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1010 ServerStats
.is_kill
++;
1012 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
1013 form_str(ERR_NICKCOLLISION
), source_p
->name
);
1015 /* kill the client issuing the nickchange */
1016 kill_client_serv_butone(client_p
, source_p
,
1017 "%s (Nick change collision)", me
.name
);
1019 source_p
->flags
|= FLAGS_KILLED
;
1022 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1024 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1031 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1032 "Nick collision on %s(%s <- %s)(older %s)",
1033 target_p
->name
, target_p
->from
->name
,
1034 client_p
->name
, action
);
1036 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1037 "Nick collision on %s(%s <- %s)(newer %s)",
1038 target_p
->name
, target_p
->from
->name
,
1039 client_p
->name
, action
);
1043 ServerStats
.is_save
++;
1044 save_user(&me
, &me
, target_p
);
1048 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1049 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1051 /* kill the client who existed before hand */
1052 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1054 ServerStats
.is_kill
++;
1056 target_p
->flags
|= FLAGS_KILLED
;
1057 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1062 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1068 register_client(struct Client
*client_p
, struct Client
*server
,
1069 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1071 struct Client
*source_p
;
1073 struct nd_entry
*nd
;
1077 source_p
= make_client(client_p
);
1078 user
= make_user(source_p
);
1079 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1081 source_p
->hopcount
= atoi(parv
[2]);
1082 source_p
->tsinfo
= newts
;
1084 strcpy(source_p
->name
, nick
);
1085 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1086 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1087 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1091 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1092 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1093 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1094 add_to_id_hash(source_p
->id
, source_p
);
1095 if (strcmp(parv
[9], "*"))
1097 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1098 if (irccmp(source_p
->host
, source_p
->orighost
))
1099 SetDynSpoof(source_p
);
1101 if (strcmp(parv
[10], "*"))
1102 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1106 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1107 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1108 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1109 add_to_id_hash(source_p
->id
, source_p
);
1116 /* remove any nd entries for this nick */
1117 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1120 add_to_client_hash(nick
, source_p
);
1121 add_to_hostname_hash(source_p
->orighost
, source_p
);
1122 monitor_signon(source_p
);
1127 flag
= user_modes
[(unsigned char) *m
];
1129 if(flag
& UMODE_SERVICE
)
1134 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1136 if(!irccmp((const char *) ptr
->data
, server
->name
))
1150 /* increment +i count if theyre invis */
1151 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1154 /* increment opered count if theyre opered */
1155 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1158 source_p
->umodes
|= flag
;
1162 if(IsOper(source_p
) && !IsService(source_p
))
1163 rb_dlinkAddAlloc(source_p
, &oper_list
);
1165 SetRemoteClient(source_p
);
1167 if(++Count
.total
> Count
.max_tot
)
1168 Count
.max_tot
= Count
.total
;
1170 source_p
->servptr
= server
;
1172 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1174 call_hook(h_new_remote_user
, source_p
);
1176 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1179 /* Check if we can do SAVE. target_p can be a client to save or a
1180 * server introducing a client -- jilles */
1182 can_save(struct Client
*target_p
)
1184 struct Client
*serv_p
;
1186 if (MyClient(target_p
))
1188 if (!has_id(target_p
))
1190 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1191 while (serv_p
!= NULL
&& serv_p
!= &me
)
1193 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1195 serv_p
= serv_p
->servptr
;
1197 return serv_p
== &me
;
1201 save_user(struct Client
*client_p
, struct Client
*source_p
,
1202 struct Client
*target_p
)
1204 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1206 /* This shouldn't happen */
1207 /* Note we only need SAVE support in this direction */
1208 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1209 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1210 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1211 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1212 ServerStats
.is_kill
++;
1214 target_p
->flags
|= FLAGS_KILLED
;
1215 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1218 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1219 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1220 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1221 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1222 if (!IsMe(client_p
))
1223 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1224 "Received SAVE message for %s from %s",
1225 target_p
->name
, source_p
->name
);
1226 if (MyClient(target_p
))
1228 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1229 form_str(RPL_SAVENICK
), target_p
->id
);
1230 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1231 target_p
->tsinfo
= SAVE_NICKTS
;
1234 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1237 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1239 char squitreason
[100];
1241 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1242 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1243 client_p
->name
, nick
);
1244 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1245 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1246 me
.id
, client_p
->name
, nick
);
1247 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1248 client_p
->name
, nick
);
1250 rb_snprintf(squitreason
, sizeof squitreason
,
1251 "Bad nickname introduced [%s]", nick
);
1252 exit_client(client_p
, client_p
, &me
, squitreason
);