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_NETWIDE
,
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_NETWIDE
,
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_NETWIDE
, "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_NETWIDE
,
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_NETWIDE
,
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_NETWIDE
,
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_NETWIDE
, "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 if (!has_common_channel(source_p
, target_p
))
717 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
718 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
722 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
723 rb_note(client_p
->localClient
->F
, note
);
729 * change_remote_nick()
732 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
733 time_t newts
, const char *nick
, int dosend
)
735 struct Client
*target_p
;
736 rb_dlink_node
*ptr
, *next_ptr
;
738 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
739 hook_cdata hook_info
;
741 /* client changing their nick - dont reset ts if its same */
744 source_p
->tsinfo
= newts
? newts
: rb_current_time();
745 monitor_signoff(source_p
);
748 hook_info
.client
= source_p
;
749 hook_info
.arg1
= source_p
->name
;
750 hook_info
.arg2
= nick
;
751 call_hook(h_remote_nick_change
, &hook_info
);
753 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
754 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
758 whowas_add_history(source_p
, 1);
761 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
762 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
766 del_from_client_hash(source_p
->name
, source_p
);
768 /* invalidate nick delay when a remote client uses the nick.. */
769 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
772 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
773 add_to_client_hash(nick
, source_p
);
776 monitor_signon(source_p
);
778 /* remove all accepts pointing to the client */
779 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
781 target_p
= ptr
->data
;
783 if (!has_common_channel(source_p
, target_p
))
785 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
786 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
792 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
793 struct Client
*target_p
, int parc
, const char *parv
[],
794 time_t newts
, const char *nick
, const char *uid
)
800 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
801 uid
!= NULL
&& can_save(source_p
);
802 action
= use_save
? "saved" : "killed";
804 /* if we dont have a ts, or their TS's are the same, kill both */
805 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
807 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
808 "Nick collision on %s(%s <- %s)(both %s)",
809 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
813 save_user(&me
, &me
, target_p
);
814 ServerStats
.is_save
++;
815 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
817 register_client(client_p
, source_p
,
818 uid
, SAVE_NICKTS
, parc
, parv
);
822 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
823 form_str(ERR_NICKCOLLISION
), target_p
->name
);
825 /* if the new client being introduced has a UID, we need to
826 * issue a KILL for it..
829 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
830 me
.id
, uid
, me
.name
);
832 /* we then need to KILL the old client everywhere */
833 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
834 ServerStats
.is_kill
++;
836 target_p
->flags
|= FLAGS_KILLED
;
837 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
841 /* the timestamps are different */
844 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
845 && !irccmp(target_p
->host
, parv
[6]);
847 if((sameuser
&& newts
< target_p
->tsinfo
) ||
848 (!sameuser
&& newts
> target_p
->tsinfo
))
850 /* if we have a UID, then we need to issue a KILL,
851 * otherwise we do nothing and hope that the other
852 * client will collide it..
856 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
858 register_client(client_p
, source_p
,
859 uid
, SAVE_NICKTS
, parc
, parv
);
863 ":%s KILL %s :%s (Nick collision (new))",
864 me
.id
, uid
, me
.name
);
870 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
871 "Nick collision on %s(%s <- %s)(older %s)",
872 target_p
->name
, target_p
->from
->name
,
873 client_p
->name
, action
);
875 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
876 "Nick collision on %s(%s <- %s)(newer %s)",
877 target_p
->name
, target_p
->from
->name
,
878 client_p
->name
, action
);
882 ServerStats
.is_save
++;
883 save_user(&me
, &me
, target_p
);
887 ServerStats
.is_kill
++;
888 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
889 form_str(ERR_NICKCOLLISION
), target_p
->name
);
891 /* now we just need to kill the existing client */
892 kill_client_serv_butone(client_p
, target_p
,
893 "%s (Nick collision (new))", me
.name
);
895 target_p
->flags
|= FLAGS_KILLED
;
896 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
899 register_client(client_p
, source_p
,
900 nick
, newts
, parc
, parv
);
907 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
908 struct Client
*target_p
, int parc
,
909 const char *parv
[], time_t newts
, const char *nick
)
915 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
917 action
= use_save
? "saved" : "killed";
919 /* its a client changing nick and causing a collide */
920 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
922 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
923 "Nick change collision from %s to %s(%s <- %s)(both %s)",
924 source_p
->name
, target_p
->name
, target_p
->from
->name
,
925 client_p
->name
, action
);
929 ServerStats
.is_save
+= 2;
930 save_user(&me
, &me
, target_p
);
931 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
932 source_p
->id
, (long)newts
);
933 /* don't send a redundant nick change */
934 if (!IsDigit(source_p
->name
[0]))
935 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
939 ServerStats
.is_kill
++;
940 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
941 form_str(ERR_NICKCOLLISION
), target_p
->name
);
943 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
945 ServerStats
.is_kill
++;
947 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
949 target_p
->flags
|= FLAGS_KILLED
;
950 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
951 source_p
->flags
|= FLAGS_KILLED
;
952 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
958 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
959 !irccmp(target_p
->host
, source_p
->host
);
961 if((sameuser
&& newts
< target_p
->tsinfo
) ||
962 (!sameuser
&& newts
> target_p
->tsinfo
))
965 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
966 "Nick change collision from %s to %s(%s <- %s)(older %s)",
967 source_p
->name
, target_p
->name
,
968 target_p
->from
->name
, client_p
->name
, action
);
970 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
971 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
972 source_p
->name
, target_p
->name
,
973 target_p
->from
->name
, client_p
->name
, action
);
977 ServerStats
.is_save
++;
978 /* can't broadcast a SAVE because the
979 * nickchange has happened at client_p
980 * but not in other directions -- jilles */
981 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
982 source_p
->id
, (long)newts
);
983 /* send a :<id> NICK <id> <ts> (!) */
984 if (!IsDigit(source_p
->name
[0]))
985 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
989 ServerStats
.is_kill
++;
991 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
992 form_str(ERR_NICKCOLLISION
), source_p
->name
);
994 /* kill the client issuing the nickchange */
995 kill_client_serv_butone(client_p
, source_p
,
996 "%s (Nick change collision)", me
.name
);
998 source_p
->flags
|= FLAGS_KILLED
;
1001 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
1003 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
1010 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
1011 "Nick collision on %s(%s <- %s)(older %s)",
1012 target_p
->name
, target_p
->from
->name
,
1013 client_p
->name
, action
);
1015 sendto_realops_snomask(SNO_SKILL
, L_NETWIDE
,
1016 "Nick collision on %s(%s <- %s)(newer %s)",
1017 target_p
->name
, target_p
->from
->name
,
1018 client_p
->name
, action
);
1022 ServerStats
.is_save
++;
1023 save_user(&me
, &me
, target_p
);
1027 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1028 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1030 /* kill the client who existed before hand */
1031 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1033 ServerStats
.is_kill
++;
1035 target_p
->flags
|= FLAGS_KILLED
;
1036 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1041 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1045 register_client(struct Client
*client_p
, struct Client
*server
,
1046 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1048 struct Client
*source_p
;
1050 struct nd_entry
*nd
;
1054 source_p
= make_client(client_p
);
1055 user
= make_user(source_p
);
1056 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1058 source_p
->hopcount
= atoi(parv
[2]);
1059 source_p
->tsinfo
= newts
;
1061 rb_strlcpy(source_p
->name
, nick
, sizeof(source_p
->name
));
1062 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1063 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1064 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1068 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1069 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1070 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1071 add_to_id_hash(source_p
->id
, source_p
);
1072 if (strcmp(parv
[9], "*"))
1074 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1075 if (irccmp(source_p
->host
, source_p
->orighost
))
1076 SetDynSpoof(source_p
);
1078 if (strcmp(parv
[10], "*"))
1079 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1083 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1084 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1085 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1086 add_to_id_hash(source_p
->id
, source_p
);
1093 /* remove any nd entries for this nick */
1094 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
1097 add_to_client_hash(nick
, source_p
);
1098 add_to_hostname_hash(source_p
->orighost
, source_p
);
1099 monitor_signon(source_p
);
1104 flag
= user_modes
[(unsigned char) *m
];
1106 if(flag
& UMODE_SERVICE
)
1111 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1113 if(!irccmp((const char *) ptr
->data
, server
->name
))
1127 /* increment +i count if theyre invis */
1128 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1131 /* increment opered count if theyre opered */
1132 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1135 source_p
->umodes
|= flag
;
1139 if(IsOper(source_p
) && !IsService(source_p
))
1140 rb_dlinkAddAlloc(source_p
, &oper_list
);
1142 SetRemoteClient(source_p
);
1144 if(++Count
.total
> Count
.max_tot
)
1145 Count
.max_tot
= Count
.total
;
1147 source_p
->servptr
= server
;
1149 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1151 call_hook(h_new_remote_user
, source_p
);
1153 introduce_client(client_p
, source_p
, user
, nick
, parc
== 12);
1156 /* Check if we can do SAVE. target_p can be a client to save or a
1157 * server introducing a client -- jilles */
1159 can_save(struct Client
*target_p
)
1161 struct Client
*serv_p
;
1163 if (MyClient(target_p
))
1165 if (!has_id(target_p
))
1167 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1168 while (serv_p
!= NULL
&& serv_p
!= &me
)
1170 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1172 serv_p
= serv_p
->servptr
;
1174 return serv_p
== &me
;
1178 save_user(struct Client
*client_p
, struct Client
*source_p
,
1179 struct Client
*target_p
)
1181 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1183 /* This shouldn't happen */
1184 /* Note we only need SAVE support in this direction */
1185 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
1186 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1187 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1188 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1189 ServerStats
.is_kill
++;
1191 target_p
->flags
|= FLAGS_KILLED
;
1192 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1195 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1196 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1197 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1198 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1199 if (!IsMe(client_p
))
1200 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1201 "Received SAVE message for %s from %s",
1202 target_p
->name
, source_p
->name
);
1203 if (MyClient(target_p
))
1205 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1206 form_str(RPL_SAVENICK
), target_p
->id
);
1207 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1208 target_p
->tsinfo
= SAVE_NICKTS
;
1211 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1214 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1216 char squitreason
[100];
1218 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1219 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1220 client_p
->name
, nick
);
1221 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1222 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1223 me
.id
, client_p
->name
, nick
);
1224 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1225 client_p
->name
, nick
);
1227 snprintf(squitreason
, sizeof squitreason
,
1228 "Bad nickname introduced [%s]", nick
);
1229 exit_client(client_p
, client_p
, &me
, squitreason
);