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 $
30 #include "irc_string.h"
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
, 8}, mg_ignore
, {m_nick
, 0}}
73 struct Message uid_msgtab
= {
74 "UID", 0, 0, 0, MFLG_SLOW
,
75 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
77 struct Message euid_msgtab
= {
78 "EUID", 0, 0, 0, MFLG_SLOW
,
79 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
81 struct Message save_msgtab
= {
82 "SAVE", 0, 0, 0, MFLG_SLOW
,
83 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
86 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
89 DECLARE_MODULE_AV1(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, "$Revision: 3518 $");
91 static int change_remote_nick(struct Client
*, struct Client
*, time_t,
94 static int clean_nick(const char *, int loc_client
);
95 static int clean_username(const char *);
96 static int clean_host(const char *);
97 static int clean_uid(const char *uid
);
99 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
100 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
101 static int register_client(struct Client
*client_p
, struct Client
*server
,
102 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
104 static int perform_nick_collides(struct Client
*, struct Client
*,
105 struct Client
*, int, const char **,
106 time_t, const char *, const char *);
107 static int perform_nickchange_collides(struct Client
*, struct Client
*,
108 struct Client
*, int, const char **, time_t, const char *);
111 * parv[0] = sender prefix
115 mr_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
117 struct Client
*target_p
;
121 if (strlen(client_p
->id
) == 3)
123 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
127 if(parc
< 2 || EmptyString(parv
[1]) || (parv
[1][0] == '~'))
129 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
130 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
134 /* due to the scandinavian origins, (~ being uppercase of ^) and ~
135 * being disallowed as a nick char, we need to chop the first ~
136 * instead of just erroring.
138 if((s
= strchr(parv
[1], '~')))
141 /* copy the nick and terminate it */
142 strlcpy(nick
, parv
[1], sizeof(nick
));
144 /* check the nickname is ok */
145 if(!clean_nick(nick
, 1))
147 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
148 me
.name
, EmptyString(parv
[0]) ? "*" : parv
[0], parv
[1]);
152 /* check if the nick is resv'd */
153 if(find_nick_resv(nick
))
155 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
156 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
160 if(irc_dictionary_find(nd_dict
, nick
))
162 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
163 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
167 if((target_p
= find_named_client(nick
)) == NULL
)
168 set_initial_nick(client_p
, source_p
, nick
);
169 else if(source_p
== target_p
)
170 strcpy(source_p
->name
, nick
);
172 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
178 * parv[0] = sender prefix
182 m_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
184 struct Client
*target_p
;
188 if(parc
< 2 || EmptyString(parv
[1]) || (parv
[1][0] == '~'))
190 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
194 /* due to the scandinavian origins, (~ being uppercase of ^) and ~
195 * being disallowed as a nick char, we need to chop the first ~
196 * instead of just erroring.
198 if((s
= strchr(parv
[1], '~')))
201 /* mark end of grace period, to prevent nickflooding */
202 if(!IsFloodDone(source_p
))
203 flood_endgrace(source_p
);
205 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
206 strlcpy(nick
, parv
[1], sizeof(nick
));
208 /* check the nickname is ok */
209 if(!clean_nick(nick
, 1))
211 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, parv
[0], nick
);
215 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
217 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
221 if(irc_dictionary_find(nd_dict
, nick
))
223 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
224 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
228 if((target_p
= find_named_client(nick
)))
230 /* If(target_p == source_p) the client is changing nicks between
231 * equivalent nicknames ie: [nick] -> {nick}
233 if(target_p
== source_p
)
235 /* check the nick isnt exactly the same */
236 if(strcmp(target_p
->name
, nick
))
237 change_local_nick(client_p
, source_p
, nick
, 1);
241 /* drop unregged client */
242 else if(IsUnknown(target_p
))
244 exit_client(NULL
, target_p
, &me
, "Overridden");
245 change_local_nick(client_p
, source_p
, nick
, 1);
248 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, parv
[0], nick
);
253 change_local_nick(client_p
, source_p
, nick
, 1);
260 * server -> server nick change
261 * parv[0] = sender prefix
263 * parv[2] = TS when nick change
265 * server introducing new nick
266 * parv[0] = sender prefix
268 * parv[2] = hop count
277 mc_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
279 struct Client
*target_p
;
282 /* if nicks erroneous, or too long, kill */
283 if(!clean_nick(parv
[1], 0))
285 bad_nickname(client_p
, parv
[1]);
289 newts
= atol(parv
[2]);
290 target_p
= find_named_client(parv
[1]);
292 /* if the nick doesnt exist, allow it and process like normal */
295 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
297 else if(IsUnknown(target_p
))
299 exit_client(NULL
, target_p
, &me
, "Overridden");
300 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
302 else if(target_p
== source_p
)
304 /* client changing case of nick */
305 if(strcmp(target_p
->name
, parv
[1]))
306 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
308 /* we've got a collision! */
310 perform_nickchange_collides(source_p
, client_p
, target_p
,
311 parc
, parv
, newts
, parv
[1]);
317 ms_nick(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
319 struct Client
*target_p
;
324 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
325 "Dropping server %s due to (invalid) command 'NICK' "
326 "with %d arguments (expecting 9)", client_p
->name
, parc
);
327 ilog(L_SERVER
, "Excess parameters (%d) for command 'NICK' from %s.",
328 parc
, client_p
->name
);
329 exit_client(client_p
, client_p
, client_p
, "Excess parameters to NICK command");
333 /* if nicks empty, erroneous, or too long, kill */
334 if(!clean_nick(parv
[1], 0))
336 bad_nickname(client_p
, parv
[1]);
340 /* invalid username or host? */
341 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
343 ServerStats
.is_kill
++;
344 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
345 "Bad user@host: %s@%s From: %s(via %s)",
346 parv
[5], parv
[6], parv
[7], client_p
->name
);
347 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.name
, parv
[1], me
.name
);
351 /* check the length of the clients gecos */
352 if(strlen(parv
[8]) > REALLEN
)
354 char *s
= LOCAL_COPY(parv
[8]);
355 /* why exactly do we care? --fl */
356 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
357 "Long realname from server %s for %s", parv
[7], parv
[1]);
363 newts
= atol(parv
[3]);
365 target_p
= find_named_client(parv
[1]);
367 /* if the nick doesnt exist, allow it and process like normal */
370 register_client(client_p
, NULL
, parv
[1], newts
, parc
, parv
);
372 else if(IsUnknown(target_p
))
374 exit_client(NULL
, target_p
, &me
, "Overridden");
375 register_client(client_p
, NULL
, parv
[1], newts
, parc
, parv
);
377 else if(target_p
== source_p
)
379 /* client changing case of nick */
380 if(strcmp(target_p
->name
, parv
[1]))
381 register_client(client_p
, NULL
, parv
[1], newts
, parc
, parv
);
383 /* we've got a collision! */
385 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
386 newts
, parv
[1], NULL
);
403 ms_uid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
405 struct Client
*target_p
;
408 newts
= atol(parv
[3]);
412 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
413 "Dropping server %s due to (invalid) command 'UID' "
414 "with %d arguments (expecting 10)", client_p
->name
, parc
);
415 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
416 parc
, client_p
->name
);
417 exit_client(client_p
, client_p
, client_p
, "Excess parameters to UID command");
421 /* if nicks erroneous, or too long, kill */
422 if(!clean_nick(parv
[1], 0))
424 bad_nickname(client_p
, parv
[1]);
428 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
430 ServerStats
.is_kill
++;
431 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
432 "Bad user@host: %s@%s From: %s(via %s)",
433 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
434 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
438 if(!clean_uid(parv
[8]))
440 ServerStats
.is_kill
++;
441 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
442 "Bad UID: %s From: %s(via %s)",
443 parv
[8], source_p
->name
, client_p
->name
);
444 sendto_one(client_p
, ":%s KILL %s :%s (Bad UID)", me
.id
, parv
[8], me
.name
);
448 /* check length of clients gecos */
449 if(strlen(parv
[9]) > REALLEN
)
451 char *s
= LOCAL_COPY(parv
[9]);
452 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
458 target_p
= find_named_client(parv
[1]);
462 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
464 else if(IsUnknown(target_p
))
466 exit_client(NULL
, target_p
, &me
, "Overridden");
467 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
469 /* we've got a collision! */
471 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
472 newts
, parv
[1], parv
[8]);
491 ms_euid(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
493 struct Client
*target_p
;
496 newts
= atol(parv
[3]);
500 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
501 "Dropping server %s due to (invalid) command 'EUID' "
502 "with %d arguments (expecting 12)", client_p
->name
, parc
);
503 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
504 parc
, client_p
->name
);
505 exit_client(client_p
, client_p
, client_p
, "Excess parameters to EUID command");
509 /* if nicks erroneous, or too long, kill */
510 if(!clean_nick(parv
[1], 0))
512 bad_nickname(client_p
, parv
[1]);
516 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
518 ServerStats
.is_kill
++;
519 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
520 "Bad user@host: %s@%s From: %s(via %s)",
521 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
522 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
526 if(!clean_uid(parv
[8]))
528 ServerStats
.is_kill
++;
529 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
530 "Bad UID: %s From: %s(via %s)",
531 parv
[8], source_p
->name
, client_p
->name
);
532 sendto_one(client_p
, ":%s KILL %s :%s (Bad UID)", me
.id
, parv
[8], me
.name
);
536 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
538 ServerStats
.is_kill
++;
539 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
540 "Bad realhost: %s From: %s(via %s)",
541 parv
[9], source_p
->name
, client_p
->name
);
542 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
546 /* check length of clients gecos */
547 if(strlen(parv
[11]) > REALLEN
)
549 char *s
= LOCAL_COPY(parv
[11]);
550 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
556 target_p
= find_named_client(parv
[1]);
560 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
562 else if(IsUnknown(target_p
))
564 exit_client(NULL
, target_p
, &me
, "Overridden");
565 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
567 /* we've got a collision! */
569 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
570 newts
, parv
[1], parv
[8]);
580 ms_save(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
582 struct Client
*target_p
;
584 target_p
= find_id(parv
[1]);
585 if (target_p
== NULL
)
587 if (!IsPerson(target_p
))
588 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
589 "Ignored SAVE message for non-person %s from %s",
590 target_p
->name
, source_p
->name
);
591 else if (IsDigit(target_p
->name
[0]))
592 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
593 "Ignored noop SAVE message for %s from %s",
594 target_p
->name
, source_p
->name
);
595 else if (target_p
->tsinfo
== atol(parv
[2]))
596 save_user(client_p
, source_p
, target_p
);
598 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
599 "Ignored SAVE message for %s from %s",
600 target_p
->name
, source_p
->name
);
606 * input - nickname to check
607 * output - 0 if erroneous, else 1
611 clean_nick(const char *nick
, int loc_client
)
615 /* nicks cant start with a digit or -, and must have a length */
616 if(*nick
== '-' || *nick
== '\0')
619 if(loc_client
&& IsDigit(*nick
))
625 if(!IsNickChar(*nick
))
638 * input - username to check
639 * output - 0 if erroneous, else 0
643 clean_username(const char *username
)
647 for(; *username
; username
++)
651 if(!IsUserChar(*username
))
663 * input - host to check
664 * output - 0 if erroneous, else 0
668 clean_host(const char *host
)
676 if(!IsHostChar(*host
))
687 clean_uid(const char *uid
)
709 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
711 char buf
[USERLEN
+ 1];
712 char note
[NICKLEN
+ 10];
714 /* This had to be copied here to avoid problems.. */
715 source_p
->tsinfo
= rb_current_time();
716 if(source_p
->name
[0])
717 del_from_client_hash(source_p
->name
, source_p
);
719 strcpy(source_p
->name
, nick
);
720 add_to_client_hash(nick
, source_p
);
722 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
723 rb_note(client_p
->localClient
->F
, note
);
725 if(source_p
->flags
& FLAGS_SENTUSER
)
727 strlcpy(buf
, source_p
->username
, sizeof(buf
));
729 /* got user, heres nick. */
730 register_local_user(client_p
, source_p
, buf
);
736 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
737 char *nick
, int dosend
)
739 struct Client
*target_p
;
740 rb_dlink_node
*ptr
, *next_ptr
;
741 struct Channel
*chptr
;
742 char note
[NICKLEN
+ 10];
747 chptr
= find_bannickchange_channel(source_p
);
750 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
751 form_str(ERR_BANNICKCHANGE
),
752 nick
, chptr
->chname
);
755 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
756 source_p
->localClient
->number_of_nick_changes
= 0;
758 source_p
->localClient
->last_nick_change
= rb_current_time();
759 source_p
->localClient
->number_of_nick_changes
++;
761 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
762 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
764 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
765 me
.name
, source_p
->name
, source_p
->name
,
766 nick
, ConfigFileEntry
.max_nick_time
);
771 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
773 /* dont reset TS if theyre just changing case of nick */
776 /* force the TS to increase -- jilles */
777 if (source_p
->tsinfo
>= rb_current_time())
780 source_p
->tsinfo
= rb_current_time();
781 monitor_signoff(source_p
);
782 /* we only do bancache for local users -- jilles */
784 invalidate_bancache_user(source_p
);
787 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
788 "Nick change: From %s to %s [%s@%s]",
789 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
791 /* send the nick change to the users channels */
792 sendto_common_channels_local(source_p
, ":%s!%s@%s NICK :%s",
793 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
795 /* send the nick change to servers.. */
798 add_history(source_p
, 1);
802 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
803 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
804 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s NICK %s :%ld",
805 source_p
->name
, nick
, (long) source_p
->tsinfo
);
809 /* Finally, add to hash */
810 del_from_client_hash(source_p
->name
, source_p
);
811 strcpy(source_p
->name
, nick
);
812 add_to_client_hash(nick
, source_p
);
815 monitor_signon(source_p
);
817 /* Make sure everyone that has this client on its accept list
818 * loses that reference.
820 /* we used to call del_all_accepts() here, but theres no real reason
821 * to clear a clients own list of accepted clients. So just remove
822 * them from everyone elses list --anfl
824 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
826 target_p
= ptr
->data
;
828 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
829 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
832 rb_snprintf(note
, sizeof(note
), "Nick: %s", nick
);
833 rb_note(client_p
->localClient
->F
, note
);
839 * change_remote_nick()
842 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
843 time_t newts
, const char *nick
, int dosend
)
846 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
848 /* client changing their nick - dont reset ts if its same */
851 source_p
->tsinfo
= newts
? newts
: rb_current_time();
852 monitor_signoff(source_p
);
855 sendto_common_channels_local(source_p
, ":%s!%s@%s NICK :%s",
856 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
860 add_history(source_p
, 1);
863 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
864 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
865 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s NICK %s :%ld",
866 source_p
->name
, nick
, (long) source_p
->tsinfo
);
870 del_from_client_hash(source_p
->name
, source_p
);
872 /* invalidate nick delay when a remote client uses the nick.. */
873 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
876 strcpy(source_p
->name
, nick
);
877 add_to_client_hash(nick
, source_p
);
880 monitor_signon(source_p
);
882 /* remove all accepts pointing to the client */
883 del_all_accepts(source_p
);
889 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
890 struct Client
*target_p
, int parc
, const char *parv
[],
891 time_t newts
, const char *nick
, const char *uid
)
897 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
898 uid
!= NULL
&& can_save(source_p
);
899 action
= use_save
? "saved" : "killed";
901 /* if we dont have a ts, or their TS's are the same, kill both */
902 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
904 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
905 "Nick collision on %s(%s <- %s)(both %s)",
906 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
910 save_user(&me
, &me
, target_p
);
911 ServerStats
.is_save
++;
912 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
914 register_client(client_p
, source_p
,
915 uid
, SAVE_NICKTS
, parc
, parv
);
919 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
920 form_str(ERR_NICKCOLLISION
), target_p
->name
);
922 /* if the new client being introduced has a UID, we need to
923 * issue a KILL for it..
926 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
927 me
.id
, uid
, me
.name
);
929 /* we then need to KILL the old client everywhere */
930 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
931 ServerStats
.is_kill
++;
933 target_p
->flags
|= FLAGS_KILLED
;
934 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
938 /* the timestamps are different */
941 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
942 && !irccmp(target_p
->host
, parv
[6]);
944 if((sameuser
&& newts
< target_p
->tsinfo
) ||
945 (!sameuser
&& newts
> target_p
->tsinfo
))
947 /* if we have a UID, then we need to issue a KILL,
948 * otherwise we do nothing and hope that the other
949 * client will collide it..
953 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
955 register_client(client_p
, source_p
,
956 uid
, SAVE_NICKTS
, parc
, parv
);
960 ":%s KILL %s :%s (Nick collision (new))",
961 me
.id
, uid
, me
.name
);
967 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
968 "Nick collision on %s(%s <- %s)(older %s)",
969 target_p
->name
, target_p
->from
->name
,
970 client_p
->name
, action
);
972 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
973 "Nick collision on %s(%s <- %s)(newer %s)",
974 target_p
->name
, target_p
->from
->name
,
975 client_p
->name
, action
);
979 ServerStats
.is_save
++;
980 save_user(&me
, &me
, target_p
);
984 ServerStats
.is_kill
++;
985 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
986 form_str(ERR_NICKCOLLISION
), target_p
->name
);
988 /* now we just need to kill the existing client */
989 kill_client_serv_butone(client_p
, target_p
,
990 "%s (Nick collision (new))", me
.name
);
992 target_p
->flags
|= FLAGS_KILLED
;
993 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
996 register_client(client_p
, parc
>= 10 ? source_p
: NULL
,
997 nick
, newts
, parc
, parv
);
1006 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
1007 struct Client
*target_p
, int parc
,
1008 const char *parv
[], time_t newts
, const char *nick
)
1014 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
1016 action
= use_save
? "saved" : "killed";
1018 /* its a client changing nick and causing a collide */
1019 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
1021 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1022 "Nick change collision from %s to %s(%s <- %s)(both %s)",
1023 source_p
->name
, target_p
->name
, target_p
->from
->name
,
1024 client_p
->name
, action
);
1028 ServerStats
.is_save
+= 2;
1029 save_user(&me
, &me
, target_p
);
1030 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1031 source_p
->id
, (long)newts
);
1032 /* don't send a redundant nick change */
1033 if (!IsDigit(source_p
->name
[0]))
1034 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1038 ServerStats
.is_kill
++;
1039 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1040 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1042 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
1044 ServerStats
.is_kill
++;
1046 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
1048 target_p
->flags
|= FLAGS_KILLED
;
1049 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
1050 source_p
->flags
|= FLAGS_KILLED
;
1051 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1057 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
1058 !irccmp(target_p
->host
, source_p
->host
);
1060 if((sameuser
&& newts
< target_p
->tsinfo
) ||
1061 (!sameuser
&& newts
> target_p
->tsinfo
))
1064 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1065 "Nick change collision from %s to %s(%s <- %s)(older %s)",
1066 source_p
->name
, target_p
->name
,
1067 target_p
->from
->name
, client_p
->name
, action
);
1069 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1070 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
1071 source_p
->name
, target_p
->name
,
1072 target_p
->from
->name
, client_p
->name
, action
);
1076 ServerStats
.is_save
++;
1077 /* can't broadcast a SAVE because the
1078 * nickchange has happened at client_p
1079 * but not in other directions -- jilles */
1080 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
1081 source_p
->id
, (long)newts
);
1082 /* send a :<id> NICK <id> <ts> (!) */
1083 if (!IsDigit(source_p
->name
[0]))
1084 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
1088 ServerStats
.is_kill
++;
1090 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1091 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1093 /* kill the client issuing the nickchange */
1094 kill_client_serv_butone(client_p
, source_p
,
1095 "%s (Nick change collision)", me
.name
);
1097 source_p
->flags
|= FLAGS_KILLED
;
1100 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1102 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1109 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1110 "Nick collision on %s(%s <- %s)(older %s)",
1111 target_p
->name
, target_p
->from
->name
,
1112 client_p
->name
, action
);
1114 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1115 "Nick collision on %s(%s <- %s)(newer %s)",
1116 target_p
->name
, target_p
->from
->name
,
1117 client_p
->name
, action
);
1121 ServerStats
.is_save
++;
1122 save_user(&me
, &me
, target_p
);
1126 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1127 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1129 /* kill the client who existed before hand */
1130 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1132 ServerStats
.is_kill
++;
1134 target_p
->flags
|= FLAGS_KILLED
;
1135 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1140 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1146 register_client(struct Client
*client_p
, struct Client
*server
,
1147 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1149 struct Client
*source_p
;
1151 struct nd_entry
*nd
;
1157 if((server
= find_server(NULL
, parv
[7])) == NULL
)
1159 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1160 "Ghost killed: %s on invalid server %s",
1162 sendto_one(client_p
, ":%s KILL %s :%s (Server doesn't exist)",
1163 get_id(&me
, client_p
), nick
, me
.name
);
1168 source_p
= make_client(client_p
);
1169 user
= make_user(source_p
);
1170 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1172 source_p
->hopcount
= atoi(parv
[2]);
1173 source_p
->tsinfo
= newts
;
1175 strcpy(source_p
->name
, nick
);
1176 strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1177 strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1178 strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1182 strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1183 strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1184 strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1185 add_to_id_hash(source_p
->id
, source_p
);
1186 if (strcmp(parv
[9], "*"))
1188 strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1189 if (irccmp(source_p
->host
, source_p
->orighost
))
1190 SetDynSpoof(source_p
);
1192 if (strcmp(parv
[10], "*"))
1193 strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1197 strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1198 strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1199 strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1200 add_to_id_hash(source_p
->id
, source_p
);
1204 strlcpy(source_p
->info
, parv
[8], sizeof(source_p
->info
));
1207 /* remove any nd entries for this nick */
1208 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1211 add_to_client_hash(nick
, source_p
);
1212 add_to_hostname_hash(source_p
->orighost
, source_p
);
1213 monitor_signon(source_p
);
1218 flag
= user_modes
[(unsigned char) *m
];
1220 if(flag
& UMODE_SERVICE
)
1225 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1227 if(!irccmp((const char *) ptr
->data
, server
->name
))
1241 /* increment +i count if theyre invis */
1242 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1245 /* increment opered count if theyre opered */
1246 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1249 source_p
->umodes
|= flag
;
1253 if(IsOper(source_p
) && !IsService(source_p
))
1254 rb_dlinkAddAlloc(source_p
, &oper_list
);
1256 SetRemoteClient(source_p
);
1258 if(++Count
.total
> Count
.max_tot
)
1259 Count
.max_tot
= Count
.total
;
1261 source_p
->servptr
= server
;
1263 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1265 /* fake direction */
1266 if(source_p
->servptr
->from
!= source_p
->from
)
1268 struct Client
*target_p
= source_p
->servptr
->from
;
1270 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
1271 "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
1272 client_p
->name
, source_p
->name
,
1273 source_p
->username
, source_p
->host
,
1274 server
->name
, target_p
->name
, target_p
->from
->name
);
1275 kill_client(client_p
, source_p
,
1276 "%s (NICK from wrong direction (%s != %s))",
1277 me
.name
, server
->name
, target_p
->from
->name
);
1278 source_p
->flags
|= FLAGS_KILLED
;
1279 return exit_client(source_p
, source_p
, &me
, "USER server wrong direction");
1282 call_hook(h_new_remote_user
, source_p
);
1284 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1287 /* Check if we can do SAVE. target_p can be a client to save or a
1288 * server introducing a client -- jilles */
1290 can_save(struct Client
*target_p
)
1292 struct Client
*serv_p
;
1294 if (MyClient(target_p
))
1296 if (!has_id(target_p
))
1298 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1299 while (serv_p
!= NULL
&& serv_p
!= &me
)
1301 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1303 serv_p
= serv_p
->servptr
;
1305 return serv_p
== &me
;
1309 save_user(struct Client
*client_p
, struct Client
*source_p
,
1310 struct Client
*target_p
)
1312 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1314 /* This shouldn't happen */
1315 /* Note we only need SAVE support in this direction */
1316 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1317 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1318 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1319 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1320 ServerStats
.is_kill
++;
1322 target_p
->flags
|= FLAGS_KILLED
;
1323 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1326 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1327 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1328 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1329 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1330 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s NICK %s :%ld",
1331 target_p
->name
, target_p
->id
, (long)SAVE_NICKTS
);
1332 if (!IsMe(client_p
))
1333 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1334 "Received SAVE message for %s from %s",
1335 target_p
->name
, source_p
->name
);
1336 if (MyClient(target_p
))
1338 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1339 form_str(RPL_SAVENICK
), target_p
->id
);
1340 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1341 target_p
->tsinfo
= SAVE_NICKTS
;
1344 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1347 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1349 char squitreason
[100];
1351 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1352 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1353 client_p
->name
, nick
);
1354 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1355 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1356 me
.id
, client_p
->name
, nick
);
1357 sendto_server(NULL
, NULL
, NOCAPS
, CAP_TS6
,
1358 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1359 me
.name
, client_p
->name
, nick
);
1361 rb_snprintf(squitreason
, sizeof squitreason
,
1362 "Bad nickname introduced [%s]", nick
);
1363 exit_client(client_p
, client_p
, &me
, squitreason
);