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
45 #include "s_newconf.h"
49 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
50 * all servers for each nick-user pair, also if a user with a UID nick changes
51 * their nick but is collided again (the server detecting the collision will
52 * not propagate the nick change further). -- jilles
54 #define SAVE_NICKTS 100
56 static void mr_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
57 static void m_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
58 static void mc_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
59 static void ms_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
60 static void ms_uid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
61 static void ms_euid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
62 static void ms_save(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
63 static bool can_save(struct Client
*);
64 static void save_user(struct Client
*, struct Client
*, struct Client
*);
65 static void bad_nickname(struct Client
*, const char *);
66 static void change_remote_nick(struct Client
*, struct Client
*, time_t,
68 static bool clean_username(const char *);
69 static bool clean_host(const char *);
70 static bool clean_uid(const char *uid
, const char *sid
);
72 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
73 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
74 static void register_client(struct Client
*client_p
, struct Client
*server
,
75 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
76 static void perform_nick_collides(struct Client
*, struct Client
*,
77 struct Client
*, int, const char **,
78 time_t, const char *, const char *);
79 static void perform_nickchange_collides(struct Client
*, struct Client
*,
80 struct Client
*, int, const char **, time_t, const char *);
82 static int h_local_nick_change
;
83 static int h_remote_nick_change
;
85 struct Message nick_msgtab
= {
87 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
89 struct Message uid_msgtab
= {
91 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
93 struct Message euid_msgtab
= {
95 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
97 struct Message save_msgtab
= {
99 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
102 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
103 &save_msgtab
, NULL
};
105 mapi_hlist_av1 nick_hlist
[] = {
106 { "local_nick_change", &h_local_nick_change
},
107 { "remote_nick_change", &h_remote_nick_change
},
111 static const char nick_desc
[] =
112 "Provides the NICK client and server commands as well as the UID, EUID, and SAVE TS6 server commands";
114 DECLARE_MODULE_AV2(nick
, NULL
, NULL
, nick_clist
, nick_hlist
, NULL
, NULL
, NULL
, nick_desc
);
120 mr_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
122 struct Client
*target_p
;
125 if (strlen(client_p
->id
) == 3 || (source_p
->preClient
&& !EmptyString(source_p
->preClient
->id
)))
127 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
131 if(parc
< 2 || EmptyString(parv
[1]))
133 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
134 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
138 /* copy the nick and terminate it */
139 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
141 /* check the nickname is ok */
142 if(!clean_nick(nick
, 1))
144 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
145 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
149 /* check if the nick is resv'd */
150 if(find_nick_resv(nick
))
152 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
153 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
157 if(rb_dictionary_find(nd_dict
, nick
))
159 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
160 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
164 if((target_p
= find_named_client(nick
)) == NULL
)
165 set_initial_nick(client_p
, source_p
, nick
);
166 else if(source_p
== target_p
)
167 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
169 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
176 m_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
178 struct Client
*target_p
;
181 if(parc
< 2 || EmptyString(parv
[1]))
183 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
187 /* mark end of grace period, to prevent nickflooding */
188 if(!IsFloodDone(source_p
))
189 flood_endgrace(source_p
);
191 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
192 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
194 /* check the nickname is ok */
195 if(!clean_nick(nick
, 1))
197 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
201 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
203 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
207 if(rb_dictionary_find(nd_dict
, nick
))
209 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
210 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
214 if((target_p
= find_named_client(nick
)))
216 /* If(target_p == source_p) the client is changing nicks between
217 * equivalent nicknames ie: [nick] -> {nick}
219 if(target_p
== source_p
)
221 /* check the nick isnt exactly the same */
222 if(strcmp(target_p
->name
, nick
))
223 change_local_nick(client_p
, source_p
, nick
, 1);
227 /* drop unregged client */
228 else if(IsUnknown(target_p
))
230 exit_client(NULL
, target_p
, &me
, "Overridden");
231 change_local_nick(client_p
, source_p
, nick
, 1);
234 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
239 change_local_nick(client_p
, source_p
, nick
, 1);
244 * server -> server nick change
246 * parv[2] = TS when nick change
249 mc_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
251 struct Client
*target_p
;
254 /* if nicks erroneous, or too long, kill */
255 if(!clean_nick(parv
[1], 0))
257 bad_nickname(client_p
, parv
[1]);
261 newts
= atol(parv
[2]);
262 target_p
= find_named_client(parv
[1]);
264 /* if the nick doesnt exist, allow it and process like normal */
267 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
269 else if(IsUnknown(target_p
))
271 exit_client(NULL
, target_p
, &me
, "Overridden");
272 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
274 else if(target_p
== source_p
)
276 /* client changing case of nick */
277 if(strcmp(target_p
->name
, parv
[1]))
278 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
280 /* we've got a collision! */
282 perform_nickchange_collides(source_p
, client_p
, target_p
,
283 parc
, parv
, newts
, parv
[1]);
287 ms_nick(struct MsgBuf
*msgbuf_p
, 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");
318 ms_uid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
320 struct Client
*target_p
;
322 char squitreason
[120];
324 newts
= atol(parv
[3]);
328 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
329 "Dropping server %s due to (invalid) command 'UID' "
330 "with %d arguments (expecting 10)", client_p
->name
, parc
);
331 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
332 parc
, client_p
->name
);
333 snprintf(squitreason
, sizeof squitreason
,
334 "Excess parameters (%d) to %s command, expecting %d",
336 exit_client(client_p
, client_p
, client_p
, squitreason
);
340 /* if nicks erroneous, or too long, kill */
341 if(!clean_nick(parv
[1], 0))
343 bad_nickname(client_p
, parv
[1]);
347 if(!clean_uid(parv
[8], source_p
->id
))
349 snprintf(squitreason
, sizeof squitreason
,
350 "Invalid UID %s for nick %s on %s/%s",
351 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
352 exit_client(client_p
, client_p
, client_p
, squitreason
);
356 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
358 ServerStats
.is_kill
++;
359 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
360 "Bad user@host: %s@%s From: %s(via %s)",
361 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
362 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
366 /* check length of clients gecos */
367 if(strlen(parv
[9]) > REALLEN
)
369 char *s
= LOCAL_COPY(parv
[9]);
370 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
371 source_p
->name
, parv
[1]);
376 target_p
= find_named_client(parv
[1]);
380 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
382 else if(IsUnknown(target_p
))
384 exit_client(NULL
, target_p
, &me
, "Overridden");
385 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
387 /* we've got a collision! */
389 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
390 newts
, parv
[1], parv
[8]);
407 ms_euid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
409 struct Client
*target_p
;
411 char squitreason
[120];
413 newts
= atol(parv
[3]);
417 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
418 "Dropping server %s due to (invalid) command 'EUID' "
419 "with %d arguments (expecting 12)", client_p
->name
, parc
);
420 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
421 parc
, client_p
->name
);
422 snprintf(squitreason
, sizeof squitreason
,
423 "Excess parameters (%d) to %s command, expecting %d",
425 exit_client(client_p
, client_p
, client_p
, squitreason
);
429 /* if nicks erroneous, or too long, kill */
430 if(!clean_nick(parv
[1], 0))
432 bad_nickname(client_p
, parv
[1]);
436 if(!clean_uid(parv
[8], source_p
->id
))
438 snprintf(squitreason
, sizeof squitreason
,
439 "Invalid UID %s for nick %s on %s/%s",
440 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
441 exit_client(client_p
, client_p
, client_p
, squitreason
);
445 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
447 ServerStats
.is_kill
++;
448 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
449 "Bad user@host: %s@%s From: %s(via %s)",
450 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
451 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
455 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
457 ServerStats
.is_kill
++;
458 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
459 "Bad realhost: %s From: %s(via %s)",
460 parv
[9], source_p
->name
, client_p
->name
);
461 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
465 /* check length of clients gecos */
466 if(strlen(parv
[11]) > REALLEN
)
468 char *s
= LOCAL_COPY(parv
[11]);
469 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
470 source_p
->name
, parv
[1]);
475 target_p
= find_named_client(parv
[1]);
479 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
481 else if(IsUnknown(target_p
))
483 exit_client(NULL
, target_p
, &me
, "Overridden");
484 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
486 /* we've got a collision! */
488 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
489 newts
, parv
[1], parv
[8]);
497 ms_save(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
499 struct Client
*target_p
;
501 target_p
= find_id(parv
[1]);
502 if (target_p
== NULL
)
504 if (!IsPerson(target_p
))
505 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
506 "Ignored SAVE message for non-person %s from %s",
507 target_p
->name
, source_p
->name
);
508 else if (IsDigit(target_p
->name
[0]))
509 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
510 "Ignored noop SAVE message for %s from %s",
511 target_p
->name
, source_p
->name
);
512 else if (target_p
->tsinfo
== atol(parv
[2]))
513 save_user(client_p
, source_p
, target_p
);
515 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
516 "Ignored SAVE message for %s from %s",
517 target_p
->name
, source_p
->name
);
522 * input - username to check
523 * output - false if erroneous, else true
527 clean_username(const char *username
)
531 for(; *username
; username
++)
535 if(!IsUserChar(*username
))
547 * input - host to check
548 * output - false if erroneous, else true
552 clean_host(const char *host
)
560 if(!IsHostChar(*host
))
571 clean_uid(const char *uid
, const char *sid
)
575 if(strncmp(uid
, sid
, strlen(sid
)))
596 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
598 char note
[NICKLEN
+ 10];
600 /* This had to be copied here to avoid problems.. */
601 source_p
->tsinfo
= rb_current_time();
602 if(source_p
->name
[0])
603 del_from_client_hash(source_p
->name
, source_p
);
605 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
606 add_to_client_hash(nick
, source_p
);
608 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
609 rb_note(client_p
->localClient
->F
, note
);
611 if(source_p
->flags
& FLAGS_SENTUSER
)
613 /* got user, heres nick. */
614 register_local_user(client_p
, source_p
);
619 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
620 char *nick
, int dosend
)
622 struct Client
*target_p
;
623 rb_dlink_node
*ptr
, *next_ptr
;
624 struct Channel
*chptr
;
625 char note
[NICKLEN
+ 10];
627 hook_cdata hook_info
;
631 chptr
= find_bannickchange_channel(source_p
);
634 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
635 form_str(ERR_BANNICKCHANGE
),
636 nick
, chptr
->chname
);
639 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
640 source_p
->localClient
->number_of_nick_changes
= 0;
642 source_p
->localClient
->last_nick_change
= rb_current_time();
643 source_p
->localClient
->number_of_nick_changes
++;
645 if(ConfigFileEntry
.anti_nick_flood
&& !IsOperGeneral(source_p
) &&
646 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
648 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
649 me
.name
, source_p
->name
, source_p
->name
,
650 nick
, ConfigFileEntry
.max_nick_time
);
655 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
657 /* dont reset TS if theyre just changing case of nick */
660 /* force the TS to increase -- jilles */
661 if (source_p
->tsinfo
>= rb_current_time())
664 source_p
->tsinfo
= rb_current_time();
665 monitor_signoff(source_p
);
666 /* we only do bancache for local users -- jilles */
668 invalidate_bancache_user(source_p
);
671 hook_info
.client
= source_p
;
672 hook_info
.arg1
= source_p
->name
;
673 hook_info
.arg2
= nick
;
674 call_hook(h_local_nick_change
, &hook_info
);
676 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
677 "Nick change: From %s to %s [%s@%s]",
678 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
680 /* send the nick change to the users channels */
681 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
682 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
684 /* send the nick change to servers.. */
687 whowas_add_history(source_p
, 1);
691 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
692 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
696 /* Finally, add to hash */
697 del_from_client_hash(source_p
->name
, source_p
);
698 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
699 add_to_client_hash(nick
, source_p
);
702 monitor_signon(source_p
);
704 /* Make sure everyone that has this client on its accept list
705 * loses that reference.
707 /* we used to call del_all_accepts() here, but theres no real reason
708 * to clear a clients own list of accepted clients. So just remove
709 * them from everyone elses list --anfl
711 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
713 target_p
= ptr
->data
;
715 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
716 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
719 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
720 rb_note(client_p
->localClient
->F
, note
);
726 * change_remote_nick()
729 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
730 time_t newts
, const char *nick
, int dosend
)
733 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
734 hook_cdata hook_info
;
736 /* client changing their nick - dont reset ts if its same */
739 source_p
->tsinfo
= newts
? newts
: rb_current_time();
740 monitor_signoff(source_p
);
743 hook_info
.client
= source_p
;
744 hook_info
.arg1
= source_p
->name
;
745 hook_info
.arg2
= nick
;
746 call_hook(h_remote_nick_change
, &hook_info
);
748 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
749 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
753 whowas_add_history(source_p
, 1);
756 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
757 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
761 del_from_client_hash(source_p
->name
, source_p
);
763 /* invalidate nick delay when a remote client uses the nick.. */
764 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
767 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
768 add_to_client_hash(nick
, source_p
);
771 monitor_signon(source_p
);
773 /* remove all accepts pointing to the client */
774 del_all_accepts(source_p
);
778 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
779 struct Client
*target_p
, int parc
, const char *parv
[],
780 time_t newts
, const char *nick
, const char *uid
)
786 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
787 uid
!= NULL
&& can_save(source_p
);
788 action
= use_save
? "saved" : "killed";
790 /* if we dont have a ts, or their TS's are the same, kill both */
791 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
793 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
794 "Nick collision on %s(%s <- %s)(both %s)",
795 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
799 save_user(&me
, &me
, target_p
);
800 ServerStats
.is_save
++;
801 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
803 register_client(client_p
, source_p
,
804 uid
, SAVE_NICKTS
, parc
, parv
);
808 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
809 form_str(ERR_NICKCOLLISION
), target_p
->name
);
811 /* if the new client being introduced has a UID, we need to
812 * issue a KILL for it..
815 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
816 me
.id
, uid
, me
.name
);
818 /* we then need to KILL the old client everywhere */
819 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
820 ServerStats
.is_kill
++;
822 target_p
->flags
|= FLAGS_KILLED
;
823 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
827 /* the timestamps are different */
830 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
831 && !irccmp(target_p
->host
, parv
[6]);
833 if((sameuser
&& newts
< target_p
->tsinfo
) ||
834 (!sameuser
&& newts
> target_p
->tsinfo
))
836 /* if we have a UID, then we need to issue a KILL,
837 * otherwise we do nothing and hope that the other
838 * client will collide it..
842 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
844 register_client(client_p
, source_p
,
845 uid
, SAVE_NICKTS
, parc
, parv
);
849 ":%s KILL %s :%s (Nick collision (new))",
850 me
.id
, uid
, me
.name
);
856 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
857 "Nick collision on %s(%s <- %s)(older %s)",
858 target_p
->name
, target_p
->from
->name
,
859 client_p
->name
, action
);
861 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
862 "Nick collision on %s(%s <- %s)(newer %s)",
863 target_p
->name
, target_p
->from
->name
,
864 client_p
->name
, action
);
868 ServerStats
.is_save
++;
869 save_user(&me
, &me
, target_p
);
873 ServerStats
.is_kill
++;
874 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
875 form_str(ERR_NICKCOLLISION
), target_p
->name
);
877 /* now we just need to kill the existing client */
878 kill_client_serv_butone(client_p
, target_p
,
879 "%s (Nick collision (new))", me
.name
);
881 target_p
->flags
|= FLAGS_KILLED
;
882 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
885 register_client(client_p
, source_p
,
886 nick
, newts
, parc
, parv
);
893 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
894 struct Client
*target_p
, int parc
,
895 const char *parv
[], time_t newts
, const char *nick
)
901 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
903 action
= use_save
? "saved" : "killed";
905 /* its a client changing nick and causing a collide */
906 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
908 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
909 "Nick change collision from %s to %s(%s <- %s)(both %s)",
910 source_p
->name
, target_p
->name
, target_p
->from
->name
,
911 client_p
->name
, action
);
915 ServerStats
.is_save
+= 2;
916 save_user(&me
, &me
, target_p
);
917 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
918 source_p
->id
, (long)newts
);
919 /* don't send a redundant nick change */
920 if (!IsDigit(source_p
->name
[0]))
921 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
925 ServerStats
.is_kill
++;
926 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
927 form_str(ERR_NICKCOLLISION
), target_p
->name
);
929 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
931 ServerStats
.is_kill
++;
933 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
935 target_p
->flags
|= FLAGS_KILLED
;
936 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
937 source_p
->flags
|= FLAGS_KILLED
;
938 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
944 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
945 !irccmp(target_p
->host
, source_p
->host
);
947 if((sameuser
&& newts
< target_p
->tsinfo
) ||
948 (!sameuser
&& newts
> target_p
->tsinfo
))
951 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
952 "Nick change collision from %s to %s(%s <- %s)(older %s)",
953 source_p
->name
, target_p
->name
,
954 target_p
->from
->name
, client_p
->name
, action
);
956 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
957 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
958 source_p
->name
, target_p
->name
,
959 target_p
->from
->name
, client_p
->name
, action
);
963 ServerStats
.is_save
++;
964 /* can't broadcast a SAVE because the
965 * nickchange has happened at client_p
966 * but not in other directions -- jilles */
967 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
968 source_p
->id
, (long)newts
);
969 /* send a :<id> NICK <id> <ts> (!) */
970 if (!IsDigit(source_p
->name
[0]))
971 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
975 ServerStats
.is_kill
++;
977 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
978 form_str(ERR_NICKCOLLISION
), source_p
->name
);
980 /* kill the client issuing the nickchange */
981 kill_client_serv_butone(client_p
, source_p
,
982 "%s (Nick change collision)", me
.name
);
984 source_p
->flags
|= FLAGS_KILLED
;
987 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
989 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
996 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
997 "Nick collision on %s(%s <- %s)(older %s)",
998 target_p
->name
, target_p
->from
->name
,
999 client_p
->name
, action
);
1001 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1002 "Nick collision on %s(%s <- %s)(newer %s)",
1003 target_p
->name
, target_p
->from
->name
,
1004 client_p
->name
, action
);
1008 ServerStats
.is_save
++;
1009 save_user(&me
, &me
, target_p
);
1013 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1014 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1016 /* kill the client who existed before hand */
1017 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1019 ServerStats
.is_kill
++;
1021 target_p
->flags
|= FLAGS_KILLED
;
1022 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1027 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1031 register_client(struct Client
*client_p
, struct Client
*server
,
1032 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1034 struct Client
*source_p
;
1036 struct nd_entry
*nd
;
1040 source_p
= make_client(client_p
);
1041 user
= make_user(source_p
);
1042 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1044 source_p
->hopcount
= atoi(parv
[2]);
1045 source_p
->tsinfo
= newts
;
1047 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
1048 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1049 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1050 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1054 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1055 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1056 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1057 add_to_id_hash(source_p
->id
, source_p
);
1058 if (strcmp(parv
[9], "*"))
1060 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1061 if (irccmp(source_p
->host
, source_p
->orighost
))
1062 SetDynSpoof(source_p
);
1064 if (strcmp(parv
[10], "*"))
1065 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1069 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1070 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1071 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1072 add_to_id_hash(source_p
->id
, source_p
);
1079 /* remove any nd entries for this nick */
1080 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
1083 add_to_client_hash(nick
, source_p
);
1084 add_to_hostname_hash(source_p
->orighost
, source_p
);
1085 monitor_signon(source_p
);
1090 flag
= user_modes
[(unsigned char) *m
];
1092 if(flag
& UMODE_SERVICE
)
1097 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1099 if(!irccmp((const char *) ptr
->data
, server
->name
))
1113 /* increment +i count if theyre invis */
1114 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1117 /* increment opered count if theyre opered */
1118 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1121 source_p
->umodes
|= flag
;
1125 if(IsOper(source_p
) && !IsService(source_p
))
1126 rb_dlinkAddAlloc(source_p
, &oper_list
);
1128 SetRemoteClient(source_p
);
1130 if(++Count
.total
> Count
.max_tot
)
1131 Count
.max_tot
= Count
.total
;
1133 source_p
->servptr
= server
;
1135 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1137 call_hook(h_new_remote_user
, source_p
);
1139 introduce_client(client_p
, source_p
, user
, nick
, parc
== 12);
1142 /* Check if we can do SAVE. target_p can be a client to save or a
1143 * server introducing a client -- jilles */
1145 can_save(struct Client
*target_p
)
1147 struct Client
*serv_p
;
1149 if (MyClient(target_p
))
1151 if (!has_id(target_p
))
1153 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1154 while (serv_p
!= NULL
&& serv_p
!= &me
)
1156 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1158 serv_p
= serv_p
->servptr
;
1160 return serv_p
== &me
;
1164 save_user(struct Client
*client_p
, struct Client
*source_p
,
1165 struct Client
*target_p
)
1167 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1169 /* This shouldn't happen */
1170 /* Note we only need SAVE support in this direction */
1171 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1172 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1173 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1174 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1175 ServerStats
.is_kill
++;
1177 target_p
->flags
|= FLAGS_KILLED
;
1178 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1181 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1182 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1183 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1184 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1185 if (!IsMe(client_p
))
1186 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1187 "Received SAVE message for %s from %s",
1188 target_p
->name
, source_p
->name
);
1189 if (MyClient(target_p
))
1191 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1192 form_str(RPL_SAVENICK
), target_p
->id
);
1193 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1194 target_p
->tsinfo
= SAVE_NICKTS
;
1197 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1200 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1202 char squitreason
[100];
1204 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1205 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1206 client_p
->name
, nick
);
1207 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1208 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1209 me
.id
, client_p
->name
, nick
);
1210 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1211 client_p
->name
, nick
);
1213 snprintf(squitreason
, sizeof squitreason
,
1214 "Bad nickname introduced [%s]", nick
);
1215 exit_client(client_p
, client_p
, &me
, squitreason
);