/[svn]/ircd-hybrid/trunk/modules/core/m_nick.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/core/m_nick.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1838 - (show annotations)
Sun Apr 21 09:36:19 2013 UTC (7 years, 3 months ago) by michael
File MIME type: text/x-chdr
File size: 30940 byte(s)
- Numeric 432 now shows the actual reason of quarantined nicknames

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_nick.c: Sets a users nick.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "client.h"
28 #include "hash.h"
29 #include "fdlist.h"
30 #include "irc_string.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "s_user.h"
35 #include "whowas.h"
36 #include "s_serv.h"
37 #include "send.h"
38 #include "channel.h"
39 #include "channel_mode.h"
40 #include "log.h"
41 #include "resv.h"
42 #include "parse.h"
43 #include "modules.h"
44 #include "packet.h"
45 #include "watch.h"
46 #include "s_misc.h"
47
48
49 static void nick_from_server(struct Client *, struct Client *, int, char **,
50 time_t, const char *, char *, char *);
51 static void uid_from_server(struct Client *, struct Client *, int, char **,
52 time_t, const char *, char *, char *);
53 static int check_clean_nick(struct Client *client_p, struct Client *source_p,
54 char *nick, struct Client *server_p);
55 static int check_clean_user(struct Client *client_p, char *nick, char *user,
56 struct Client *server_p);
57 static int check_clean_host(struct Client *client_p, char *nick, char *host,
58 struct Client *server_p);
59
60 static int clean_user_name(const char *);
61 static void perform_nick_collides(struct Client *, struct Client *, struct Client *,
62 int, char **, time_t, const char *, char *, char *, char *);
63
64
65 /* set_initial_nick()
66 *
67 * inputs
68 * output
69 * side effects -
70 *
71 * This function is only called to set up an initially registering
72 * client.
73 */
74 static void
75 set_initial_nick(struct Client *source_p, const char *nick)
76 {
77 /* Client setting NICK the first time */
78
79 /* This had to be copied here to avoid problems.. */
80 source_p->tsinfo = CurrentTime;
81 source_p->localClient->registration &= ~REG_NEED_NICK;
82
83 if (source_p->name[0])
84 hash_del_client(source_p);
85
86 strlcpy(source_p->name, nick, sizeof(source_p->name));
87 hash_add_client(source_p);
88
89 /* fd_desc is long enough */
90 fd_note(&source_p->localClient->fd, "Nick: %s", nick);
91
92 if (!source_p->localClient->registration)
93 register_local_user(source_p);
94 }
95
96 /* change_local_nick()
97 *
98 * inputs - pointer to server
99 * - pointer to client
100 * - nick
101 * output -
102 * side effects - changes nick of a LOCAL user
103 */
104 static void
105 change_local_nick(struct Client *source_p, const char *nick)
106 {
107 assert(source_p->name[0] && !EmptyString(nick));
108 assert(MyConnect(source_p));
109
110 /*
111 * Client just changing his/her nick. If he/she is
112 * on a channel, send note of change to all clients
113 * on that channel. Propagate notice to other servers.
114 */
115 if ((source_p->localClient->last_nick_change +
116 ConfigFileEntry.max_nick_time) < CurrentTime)
117 source_p->localClient->number_of_nick_changes = 0;
118 source_p->localClient->last_nick_change = CurrentTime;
119 source_p->localClient->number_of_nick_changes++;
120
121 if ((ConfigFileEntry.anti_nick_flood &&
122 (source_p->localClient->number_of_nick_changes
123 <= ConfigFileEntry.max_nick_changes)) ||
124 !ConfigFileEntry.anti_nick_flood ||
125 (HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.no_oper_flood))
126 {
127 int samenick = !irccmp(source_p->name, nick);
128
129 if (!samenick)
130 {
131 source_p->tsinfo = CurrentTime;
132 clear_ban_cache_client(source_p);
133 watch_check_hash(source_p, RPL_LOGOFF);
134
135 if (HasUMode(source_p, UMODE_REGISTERED))
136 {
137 unsigned int oldmodes = source_p->umodes;
138 char modebuf[IRCD_BUFSIZE] = { '\0' };
139
140 DelUMode(source_p, UMODE_REGISTERED);
141 send_umode(source_p, source_p, oldmodes, 0xffffffff, modebuf);
142 }
143 }
144
145 /* XXX - the format of this notice should eventually be changed
146 * to either %s[%s@%s], or even better would be get_client_name() -bill
147 */
148 sendto_realops_flags(UMODE_NCHANGE, L_ALL, SEND_NOTICE,
149 "Nick change: From %s to %s [%s@%s]",
150 source_p->name, nick, source_p->username, source_p->host);
151 sendto_common_channels_local(source_p, 1, 0, ":%s!%s@%s NICK :%s",
152 source_p->name, source_p->username,
153 source_p->host, nick);
154 add_history(source_p, 1);
155
156 sendto_server(source_p, CAP_TS6, NOCAPS,
157 ":%s NICK %s :%lu",
158 ID(source_p), nick, (unsigned long)source_p->tsinfo);
159 sendto_server(source_p, NOCAPS, CAP_TS6,
160 ":%s NICK %s :%lu",
161 source_p->name, nick, (unsigned long)source_p->tsinfo);
162
163 hash_del_client(source_p);
164 strcpy(source_p->name, nick);
165 hash_add_client(source_p);
166
167 if (!samenick)
168 watch_check_hash(source_p, RPL_LOGON);
169
170 /* fd_desc is long enough */
171 fd_note(&source_p->localClient->fd, "Nick: %s", nick);
172 }
173 else
174 sendto_one(source_p, form_str(ERR_NICKTOOFAST),
175 me.name, source_p->name, source_p->name,
176 nick, ConfigFileEntry.max_nick_time);
177 }
178
179 /*! \brief NICK command handler (called by unregistered,
180 * locally connected clients)
181 *
182 * \param client_p Pointer to allocated Client struct with physical connection
183 * to this server, i.e. with an open socket connected.
184 * \param source_p Pointer to allocated Client struct from which the message
185 * originally comes from. This can be a local or remote client.
186 * \param parc Integer holding the number of supplied arguments.
187 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
188 * pointers.
189 * \note Valid arguments for this command are:
190 * - parv[0] = sender prefix
191 * - parv[1] = nickname
192 */
193 static void
194 mr_nick(struct Client *client_p, struct Client *source_p,
195 int parc, char *parv[])
196 {
197 struct Client *target_p = NULL;
198 struct MaskItem *conf = NULL;
199 char nick[NICKLEN + 1];
200 char *s = NULL;
201
202 if (parc < 2 || EmptyString(parv[1]))
203 {
204 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name,
205 source_p->name[0] ? source_p->name : "*");
206 return;
207 }
208
209 /* Terminate the nick at the first ~ */
210 if ((s = strchr(parv[1], '~')) != NULL)
211 *s = '\0';
212
213 /* copy the nick and terminate it */
214 strlcpy(nick, parv[1], IRCD_MIN(sizeof(nick), ServerInfo.max_nick_length + 1));
215
216 /* check the nickname is ok */
217 if (!valid_nickname(nick, 1))
218 {
219 sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name,
220 source_p->name[0] ? source_p->name : "*", parv[1],
221 "Erroneous Nickname");
222 return;
223 }
224
225 /* check if the nick is resv'd */
226 if ((conf = find_matching_name_conf(CONF_NRESV, nick, NULL, NULL, 0)))
227 {
228 ++conf->count;
229 sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name,
230 source_p->name[0] ? source_p->name : "*", nick, conf->reason);
231 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
232 "Forbidding reserved nick [%s] from user %s",
233 nick, get_client_name(client_p, HIDE_IP));
234 return;
235 }
236
237 if ((target_p = hash_find_client(nick)) == NULL)
238 set_initial_nick(source_p, nick);
239 else if (source_p == target_p)
240 strlcpy(source_p->name, nick, sizeof(source_p->name));
241 else
242 sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick);
243 }
244
245
246 /*! \brief NICK command handler (called by already registered,
247 * locally connected clients)
248 *
249 * \param client_p Pointer to allocated Client struct with physical connection
250 * to this server, i.e. with an open socket connected.
251 * \param source_p Pointer to allocated Client struct from which the message
252 * originally comes from. This can be a local or remote client.
253 * \param parc Integer holding the number of supplied arguments.
254 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
255 * pointers.
256 * \note Valid arguments for this command are:
257 * - parv[0] = sender prefix
258 * - parv[1] = nickname
259 */
260 static void
261 m_nick(struct Client *client_p, struct Client *source_p,
262 int parc, char *parv[])
263 {
264 char nick[NICKLEN + 1];
265 struct Client *target_p = NULL;
266 struct MaskItem *conf = NULL;
267
268 assert(source_p == client_p);
269
270 if (parc < 2 || EmptyString(parv[1]))
271 {
272 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
273 me.name, source_p->name);
274 return;
275 }
276
277 /* mark end of grace period, to prevent nickflooding */
278 if (!IsFloodDone(source_p))
279 flood_endgrace(source_p);
280
281 /* terminate nick to NICKLEN */
282 strlcpy(nick, parv[1], IRCD_MIN(sizeof(nick), ServerInfo.max_nick_length + 1));
283
284 /* check the nickname is ok */
285 if (!valid_nickname(nick, 1))
286 {
287 sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name,
288 source_p->name, nick, "Erroneous Nickname");
289 return;
290 }
291
292
293 if (!IsExemptResv(source_p) &&
294 !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) &&
295 (conf = find_matching_name_conf(CONF_NRESV, nick, NULL, NULL, 0)))
296 {
297 ++conf->count;
298 sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME),
299 me.name, source_p->name, nick, conf->reason);
300 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
301 "Forbidding reserved nick [%s] from user %s",
302 nick, get_client_name(client_p, HIDE_IP));
303 return;
304 }
305
306 if ((target_p = hash_find_client(nick)) == NULL)
307 change_local_nick(source_p, nick);
308 else if (target_p == source_p)
309 {
310 /*
311 * If (target_p == source_p) the client is changing nicks between
312 * equivalent nicknames ie: [nick] -> {nick}
313 */
314
315 /* check the nick isnt exactly the same */
316 if (strcmp(target_p->name, nick))
317 change_local_nick(source_p, nick);
318 }
319 else if (IsUnknown(target_p))
320 {
321 /*
322 * if the client that has the nick isn't registered yet (nick but no
323 * user) then drop the unregged client
324 */
325 exit_client(target_p, &me, "Overridden");
326 change_local_nick(source_p, nick);
327 }
328 else
329 sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name,
330 source_p->name, nick);
331 }
332
333
334 /*! \brief NICK command handler (called by servers and remotely
335 * connected clients)
336 *
337 * \param client_p Pointer to allocated Client struct with physical connection
338 * to this server, i.e. with an open socket connected.
339 * \param source_p Pointer to allocated Client struct from which the message
340 * originally comes from. This can be a local or remote client.
341 * \param parc Integer holding the number of supplied arguments.
342 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
343 * pointers.
344 * \note Valid arguments for this command are:
345 *
346 * server -> server nick change
347 * - parv[0] = sender prefix
348 * - parv[1] = nickname
349 * - parv[2] = TS when nick change
350 *
351 * server introducing new nick (without services support)
352 * - parv[0] = sender prefix
353 * - parv[1] = nickname
354 * - parv[2] = hop count
355 * - parv[3] = TS
356 * - parv[4] = umode
357 * - parv[5] = username
358 * - parv[6] = hostname
359 * - parv[7] = server
360 * - parv[8] = ircname
361 *
362 * server introducing new nick (with services support)
363 * - parv[0] = sender prefix
364 * - parv[1] = nickname
365 * - parv[2] = hop count
366 * - parv[3] = TS
367 * - parv[4] = umode
368 * - parv[5] = username
369 * - parv[6] = hostname
370 * - parv[7] = server
371 * - parv[8] = services id (timestamp)
372 * - parv[9] = ircname
373 */
374 static void
375 ms_nick(struct Client *client_p, struct Client *source_p,
376 int parc, char *parv[])
377 {
378 struct Client *target_p = NULL;
379 time_t newts = 0;
380 const char *svsid = "0";
381
382 if (parc < 3 || EmptyString(parv[parc - 1]))
383 return;
384
385 if (parc >= 9)
386 {
387 struct Client *server_p = hash_find_server(parv[7]);
388
389 if (server_p == NULL)
390 {
391 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
392 "Invalid server %s from %s for NICK %s",
393 parv[7], source_p->name, parv[1]);
394 sendto_one(client_p, ":%s KILL %s :%s (Server doesn't exist!)",
395 me.name, parv[1], me.name);
396 return;
397 }
398
399 if (check_clean_nick(client_p, source_p, parv[1], server_p) ||
400 check_clean_user(client_p, parv[1], parv[5], server_p) ||
401 check_clean_host(client_p, parv[1], parv[6], server_p))
402 return;
403
404 if (IsServer(source_p))
405 newts = atol(parv[3]);
406 if (IsServer(source_p) && parc == 10)
407 svsid = parv[8];
408 }
409 else if (parc == 3)
410 {
411 if (IsServer(source_p))
412 /* Servers can't change nicks.. */
413 return;
414
415 if (check_clean_nick(client_p, source_p, parv[1],
416 source_p->servptr))
417 return;
418
419 newts = atol(parv[2]);
420 }
421
422 /* if the nick doesnt exist, allow it and process like normal */
423 if ((target_p = hash_find_client(parv[1])) == NULL)
424 nick_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]);
425 else if (IsUnknown(target_p))
426 {
427 /* we're not living in the past anymore, an unknown client is local only. */
428 exit_client(target_p, &me, "Overridden");
429 nick_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]);
430 }
431 else if (target_p == source_p)
432 {
433 if (strcmp(target_p->name, parv[1]))
434 nick_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]);
435 }
436 else
437 perform_nick_collides(source_p, client_p, target_p, parc, parv,
438 newts, svsid, parv[1], parv[parc-1], NULL);
439 }
440
441
442 /*! \brief UID command handler (called by servers)
443 *
444 * \param client_p Pointer to allocated Client struct with physical connection
445 * to this server, i.e. with an open socket connected.
446 * \param source_p Pointer to allocated Client struct from which the message
447 * originally comes from. This can be a local or remote client.
448 * \param parc Integer holding the number of supplied arguments.
449 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
450 * pointers.
451 * \note Valid arguments for this command are:
452 *
453 * server introducing new nick (without services support)
454 * - parv[0] = sender prefix
455 * - parv[1] = nickname
456 * - parv[2] = hop count
457 * - parv[3] = TS
458 * - parv[4] = umode
459 * - parv[5] = username
460 * - parv[6] = hostname
461 * - parv[7] = ip
462 * - parv[8] = uid
463 * - parv[9] = ircname (gecos)
464 *
465 * server introducing new nick (with services support)
466 * - parv[ 0] = sender prefix
467 * - parv[ 1] = nickname
468 * - parv[ 2] = hop count
469 * - parv[ 3] = TS
470 * - parv[ 4] = umode
471 * - parv[ 5] = username
472 * - parv[ 6] = hostname
473 * - parv[ 7] = ip
474 * - parv[ 8] = uid
475 * - parv[ 9] = services id (timestamp)
476 * - parv[10] = ircname (gecos)
477 */
478 static void
479 ms_uid(struct Client *client_p, struct Client *source_p,
480 int parc, char *parv[])
481 {
482 struct Client *target_p = NULL;
483 time_t newts = 0;
484 const char *svsid = "0";
485
486 if (parc < 10 || EmptyString(parv[parc-1]))
487 return;
488
489 if (check_clean_nick(client_p, source_p, parv[1], source_p) ||
490 check_clean_user(client_p, parv[1], parv[5], source_p) ||
491 check_clean_host(client_p, parv[1], parv[6], source_p))
492 return;
493
494 newts = atol(parv[3]);
495 svsid = parc == 11 ? parv[9] : "0";
496
497 /*
498 * if there is an ID collision, kill our client, and kill theirs.
499 * this may generate 401's, but it ensures that both clients always
500 * go, even if the other server refuses to do the right thing.
501 */
502 if ((target_p = hash_find_id(parv[8])) != NULL)
503 {
504 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
505 "ID collision on %s(%s <- %s)(both killed)",
506 target_p->name, target_p->from->name,
507 client_p->name);
508 kill_client_ll_serv_butone(NULL, target_p, "%s (ID collision)",
509 me.name);
510
511 ++ServerStats.is_kill;
512 AddFlag(target_p, FLAGS_KILLED);
513 exit_client(target_p, &me, "ID Collision");
514 return;
515 }
516
517 if ((target_p = hash_find_client(parv[1])) == NULL)
518 uid_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]);
519 else if (IsUnknown(target_p))
520 {
521 exit_client(target_p, &me, "Overridden");
522 uid_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]);
523 }
524 else
525 perform_nick_collides(source_p, client_p, target_p, parc, parv, newts, svsid, parv[1],
526 parv[parc-1], parv[8]);
527 }
528
529 /* check_clean_nick()
530 *
531 * input - pointer to source
532 * -
533 * - nickname
534 * - truncated nickname
535 * - origin of client
536 * - pointer to server nick is coming from
537 * output - none
538 * side effects - if nickname is erroneous, or a different length to
539 * truncated nickname, return 1
540 */
541 static int
542 check_clean_nick(struct Client *client_p, struct Client *source_p,
543 char *nick, struct Client *server_p)
544 {
545 /* the old code did some wacky stuff here, if the nick is invalid, kill it
546 * and dont bother messing at all
547 */
548 if (!valid_nickname(nick, 0))
549 {
550 ++ServerStats.is_kill;
551 sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
552 "Bad/long Nick: %s From: %s(via %s)",
553 nick, server_p->name, client_p->name);
554
555 sendto_one(client_p, ":%s KILL %s :%s (Bad Nickname)",
556 me.name, nick, me.name);
557
558 /* bad nick change */
559 if (source_p != client_p)
560 {
561 kill_client_ll_serv_butone(client_p, source_p,
562 "%s (Bad Nickname)",
563 me.name);
564 AddFlag(source_p, FLAGS_KILLED);
565 exit_client(source_p, &me, "Bad Nickname");
566 }
567
568 return 1;
569 }
570
571 return 0;
572 }
573
574 /* check_clean_user()
575 *
576 * input - pointer to client sending data
577 * - nickname
578 * - username to check
579 * - origin of NICK
580 * output - none
581 * side effects - if username is erroneous, return 1
582 */
583 static int
584 check_clean_user(struct Client *client_p, char *nick,
585 char *user, struct Client *server_p)
586 {
587 if (!clean_user_name(user))
588 {
589 ++ServerStats.is_kill;
590 sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
591 "Bad/Long Username: %s Nickname: %s From: %s(via %s)",
592 user, nick, server_p->name, client_p->name);
593 sendto_one(client_p, ":%s KILL %s :%s (Bad Username)",
594 me.name, nick, me.name);
595 return 1;
596 }
597
598 return 0;
599 }
600
601 /* check_clean_host()
602 *
603 * input - pointer to client sending us data
604 * - nickname
605 * - hostname to check
606 * - source name
607 * output - none
608 * side effects - if hostname is erroneous, return 1
609 */
610 static int
611 check_clean_host(struct Client *client_p, char *nick,
612 char *host, struct Client *server_p)
613 {
614 if (!valid_hostname(host))
615 {
616 ++ServerStats.is_kill;
617 sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
618 "Bad/Long Hostname: %s Nickname: %s From: %s(via %s)",
619 host, nick, server_p->name, client_p->name);
620 sendto_one(client_p, ":%s KILL %s :%s (Bad Hostname)",
621 me.name, nick, me.name);
622 return 1;
623 }
624
625 return 0;
626 }
627
628 /* clean_user_name()
629 *
630 * input - username
631 * output - none
632 * side effects - walks through the username, returning 0 if erroneous
633 */
634 static int
635 clean_user_name(const char *user)
636 {
637 const char *p = user;
638
639 assert(user && *user);
640
641 for (; *p; ++p)
642 if (!IsUserChar(*p))
643 return 0;
644
645 return p - user <= USERLEN;
646 }
647
648 /*
649 * nick_from_server()
650 */
651 static void
652 nick_from_server(struct Client *client_p, struct Client *source_p, int parc,
653 char *parv[], time_t newts, const char *svsid, char *nick, char *ngecos)
654 {
655 int samenick = 0;
656
657 if (IsServer(source_p))
658 {
659 /* A server introducing a new client, change source */
660 source_p = make_client(client_p);
661 dlinkAdd(source_p, &source_p->node, &global_client_list);
662
663 if (parc > 2)
664 source_p->hopcount = atoi(parv[2]);
665 if (newts)
666 source_p->tsinfo = newts;
667 else
668 {
669 newts = source_p->tsinfo = CurrentTime;
670 ts_warn("Remote nick %s (%s) introduced without a TS", nick, parv[0]);
671 }
672
673 strlcpy(source_p->svid, svsid, sizeof(source_p->svid));
674 strlcpy(source_p->info, ngecos, sizeof(source_p->info));
675 /* copy the nick in place */
676 strlcpy(source_p->name, nick, sizeof(source_p->name));
677 hash_add_client(source_p);
678
679 if (parc > 8)
680 {
681 const char *m;
682
683 /* parse usermodes */
684 for (m = &parv[4][1]; *m; ++m)
685 {
686 unsigned int flag = user_modes[(unsigned char)*m];
687
688 if ((flag & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
689 ++Count.invisi;
690 if ((flag & UMODE_OPER) && !HasUMode(source_p, UMODE_OPER))
691 ++Count.oper;
692
693 source_p->umodes |= flag & SEND_UMODES;
694 }
695
696 register_remote_user(source_p, parv[5], parv[6],
697 parv[7], ngecos);
698 return;
699 }
700 }
701 else if (source_p->name[0])
702 {
703 samenick = !irccmp(source_p->name, nick);
704
705 /* client changing their nick */
706 if (!samenick)
707 {
708 DelUMode(source_p, UMODE_REGISTERED);
709 watch_check_hash(source_p, RPL_LOGOFF);
710 source_p->tsinfo = newts ? newts : CurrentTime;
711 }
712
713 sendto_common_channels_local(source_p, 1, 0, ":%s!%s@%s NICK :%s",
714 source_p->name,source_p->username,
715 source_p->host, nick);
716
717 add_history(source_p, 1);
718 sendto_server(client_p, CAP_TS6, NOCAPS,
719 ":%s NICK %s :%lu",
720 ID(source_p), nick, (unsigned long)source_p->tsinfo);
721 sendto_server(client_p, NOCAPS, CAP_TS6,
722 ":%s NICK %s :%lu",
723 source_p->name, nick, (unsigned long)source_p->tsinfo);
724 }
725
726 /* set the new nick name */
727 if (source_p->name[0])
728 hash_del_client(source_p);
729
730 strlcpy(source_p->name, nick, sizeof(source_p->name));
731 hash_add_client(source_p);
732
733 if (!samenick)
734 watch_check_hash(source_p, RPL_LOGON);
735 }
736
737 /*
738 * client_from_server()
739 */
740 static void
741 uid_from_server(struct Client *client_p, struct Client *source_p, int parc,
742 char *parv[], time_t newts, const char *svsid, char *nick, char *ugecos)
743 {
744 const char *m = NULL;
745 const char *servername = source_p->name;
746
747 source_p = make_client(client_p);
748 dlinkAdd(source_p, &source_p->node, &global_client_list);
749
750 source_p->hopcount = atoi(parv[2]);
751 source_p->tsinfo = newts;
752 strlcpy(source_p->svid, svsid, sizeof(source_p->svid));
753
754 /* copy the nick in place */
755 strcpy(source_p->name, nick);
756 strlcpy(source_p->id, parv[8], sizeof(source_p->id));
757 strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost));
758 strlcpy(source_p->info, ugecos, sizeof(source_p->info));
759
760 hash_add_client(source_p);
761 hash_add_id(source_p);
762
763 /* parse usermodes */
764 for (m = &parv[4][1]; *m; ++m)
765 {
766 unsigned int flag = user_modes[(unsigned char)*m];
767
768 if ((flag & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
769 ++Count.invisi;
770 if ((flag & UMODE_OPER) && !HasUMode(source_p, UMODE_OPER))
771 ++Count.oper;
772
773 source_p->umodes |= flag & SEND_UMODES;
774 }
775
776 register_remote_user(source_p, parv[5], parv[6],
777 servername, ugecos);
778 }
779
780 static void
781 perform_nick_collides(struct Client *source_p, struct Client *client_p,
782 struct Client *target_p, int parc, char *parv[],
783 time_t newts, const char *svsid, char *nick, char *gecos, char *uid)
784 {
785 int sameuser;
786
787 /* server introducing new nick */
788 if (IsServer(source_p))
789 {
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))
792 {
793 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
794 "Nick collision on %s(%s <- %s)(both killed)",
795 target_p->name, target_p->from->name,
796 client_p->name);
797
798 /* if we have a UID, issue a kill for it */
799 if (uid)
800 sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))",
801 me.id, uid, me.name);
802
803 kill_client_ll_serv_butone(NULL, target_p,
804 "%s (Nick collision (new))",
805 me.name);
806 ++ServerStats.is_kill;
807 sendto_one(target_p, form_str(ERR_NICKCOLLISION),
808 me.name, target_p->name, target_p->name);
809
810 AddFlag(target_p, FLAGS_KILLED);
811 exit_client(target_p, &me, "Nick collision (new)");
812 return;
813 }
814 /* the timestamps are different */
815 else
816 {
817 sameuser = !irccmp(target_p->username, parv[5]) &&
818 !irccmp(target_p->host, parv[6]);
819
820 /* if the users are the same (loaded a client on a different server)
821 * and the new users ts is older, or the users are different and the
822 * new users ts is newer, ignore the new client and let it do the kill
823 */
824 if ((sameuser && newts < target_p->tsinfo) ||
825 (!sameuser && newts > target_p->tsinfo))
826 {
827 if (uid)
828 sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))",
829 me.id, uid, me.name);
830 return;
831 }
832 else
833 {
834 if (sameuser)
835 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
836 "Nick collision on %s(%s <- %s)(older killed)",
837 target_p->name, target_p->from->name,
838 client_p->name);
839 else
840 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
841 "Nick collision on %s(%s <- %s)(newer killed)",
842 target_p->name, target_p->from->name,
843 client_p->name);
844
845 ++ServerStats.is_kill;
846 sendto_one(target_p, form_str(ERR_NICKCOLLISION),
847 me.name, target_p->name, target_p->name);
848
849 /* if it came from a LL server, itd have been source_p,
850 * so we dont need to mark target_p as known
851 */
852 kill_client_ll_serv_butone(source_p, target_p,
853 "%s (Nick collision (new))",
854 me.name);
855
856 AddFlag(target_p, FLAGS_KILLED);
857 exit_client(target_p, &me, "Nick collision");
858
859 if (!uid && (parc == 9 || parc == 10))
860 nick_from_server(client_p, source_p, parc, parv, newts, svsid, nick, gecos);
861 else if (uid && (parc == 10 || parc == 11))
862 uid_from_server(client_p, source_p, parc, parv, newts, svsid, nick, gecos);
863
864 return;
865 }
866 }
867 }
868
869 /* its a client changing nick and causing a collide */
870 if (!newts || !target_p->tsinfo || (newts == target_p->tsinfo))
871 {
872 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
873 "Nick change collision from %s to %s(%s <- %s)(both killed)",
874 source_p->name, target_p->name, target_p->from->name,
875 client_p->name);
876
877 sendto_one(target_p, form_str(ERR_NICKCOLLISION), me.name,
878 target_p->name, target_p->name);
879
880 ++ServerStats.is_kill;
881 kill_client_ll_serv_butone(NULL, source_p, "%s (Nick change collision)",
882 me.name);
883
884 ++ServerStats.is_kill;
885 kill_client_ll_serv_butone(NULL, target_p, "%s (Nick change collision)",
886 me.name);
887
888 AddFlag(target_p, FLAGS_KILLED);
889 exit_client(target_p, &me, "Nick collision (new)");
890
891 AddFlag(source_p, FLAGS_KILLED);
892 exit_client(source_p, &me, "Nick collision (old)");
893 return;
894 }
895 else
896 {
897 sameuser = !irccmp(target_p->username, source_p->username) &&
898 !irccmp(target_p->host, source_p->host);
899
900 if ((sameuser && newts < target_p->tsinfo) ||
901 (!sameuser && newts > target_p->tsinfo))
902 {
903 if (sameuser)
904 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
905 "Nick change collision from %s to %s(%s <- %s)(older killed)",
906 source_p->name, target_p->name, target_p->from->name,
907 client_p->name);
908 else
909 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
910 "Nick change collision from %s to %s(%s <- %s)(newer killed)",
911 source_p->name, target_p->name, target_p->from->name,
912 client_p->name);
913
914 ++ServerStats.is_kill;
915 kill_client_ll_serv_butone(client_p, source_p,
916 "%s (Nick change collision)",
917 me.name);
918
919 AddFlag(source_p, FLAGS_KILLED);
920
921 if (sameuser)
922 exit_client(source_p, &me, "Nick collision (old)");
923 else
924 exit_client(source_p, &me, "Nick collision (new)");
925 return;
926 }
927 else
928 {
929 if (sameuser)
930 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
931 "Nick collision on %s(%s <- %s)(older killed)",
932 target_p->name, target_p->from->name,
933 client_p->name);
934 else
935 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
936 "Nick collision on %s(%s <- %s)(newer killed)",
937 target_p->name, target_p->from->name,
938 client_p->name);
939
940 kill_client_ll_serv_butone(source_p, target_p,
941 "%s (Nick collision)",
942 me.name);
943
944 ++ServerStats.is_kill;
945 sendto_one(target_p, form_str(ERR_NICKCOLLISION),
946 me.name, target_p->name, target_p->name);
947
948 AddFlag(target_p, FLAGS_KILLED);
949 exit_client(target_p, &me, "Nick collision");
950 }
951 }
952
953 /* we should only ever call nick_from_server() here, as
954 * this is a client changing nick, not a new client
955 */
956 nick_from_server(client_p, source_p, parc, parv, newts, svsid, nick, gecos);
957 }
958
959 static struct Message nick_msgtab = {
960 "NICK", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
961 {mr_nick, m_nick, ms_nick, m_ignore, m_nick, m_ignore}
962 };
963
964 static struct Message uid_msgtab = {
965 "UID", 0, 0, 10, MAXPARA, MFLG_SLOW, 0,
966 {m_ignore, m_ignore, ms_uid, m_ignore, m_ignore, m_ignore}
967 };
968
969 static void
970 module_init(void)
971 {
972 mod_add_cmd(&uid_msgtab);
973 mod_add_cmd(&nick_msgtab);
974 }
975
976 static void
977 module_exit(void)
978 {
979 mod_del_cmd(&uid_msgtab);
980 mod_del_cmd(&nick_msgtab);
981 }
982
983 struct module module_entry = {
984 .node = { NULL, NULL, NULL },
985 .name = NULL,
986 .version = "$Revision$",
987 .handle = NULL,
988 .modinit = module_init,
989 .modexit = module_exit,
990 .flags = MODULE_FLAG_CORE
991 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28