ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/s_user.c (file contents):
Revision 2283 by michael, Tue Jun 18 19:13:20 2013 UTC vs.
Revision 3317 by michael, Tue Apr 15 14:25:19 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_user.c: User related functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file s_user.c
23 > * \brief User related functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 29 | Line 31
31   #include "channel.h"
32   #include "channel_mode.h"
33   #include "client.h"
32 #include "fdlist.h"
34   #include "hash.h"
35   #include "irc_string.h"
35 #include "s_bsd.h"
36   #include "ircd.h"
37   #include "listener.h"
38   #include "motd.h"
# Line 42 | Line 42
42   #include "s_serv.h"
43   #include "send.h"
44   #include "supported.h"
45 #include "whowas.h"
45   #include "memory.h"
46   #include "packet.h"
47   #include "rng_mt.h"
48   #include "userhost.h"
50 #include "hook.h"
49   #include "s_misc.h"
50   #include "parse.h"
51   #include "watch.h"
52  
53   static char umode_buffer[IRCD_BUFSIZE];
56
57 static void user_welcome(struct Client *);
58 static void report_and_set_user_flags(struct Client *, const struct MaskItem *);
59 static int check_xline(struct Client *);
60 static void introduce_client(struct Client *);
54   static const char *uid_get(void);
55  
56   /* Used for building up the isupport string,
57   * used with init_isupport, add_isupport, delete_isupport
58   */
59 <
67 < struct Isupport
59 > struct Isupport
60   {
61    dlink_node node;
62    char *name;
# Line 105 | Line 97 | const unsigned int user_modes[256] =
97    0,                  /* T */
98    0,                  /* U */
99    0,                  /* V */
100 <  0,                  /* W */
100 >  UMODE_WEBIRC,       /* W */
101    0,                  /* X */
102    0,                  /* Y */
103    0,                  /* Z 0x5A */
104 <  0, 0, 0, 0, 0,      /* 0x5F   */
104 >  0, 0, 0, 0, 0,      /* 0x5F   */
105    0,                  /* 0x60   */
106    UMODE_ADMIN,        /* a */
107    UMODE_BOTS,         /* b */
# Line 169 | Line 161 | assemble_umode_buffer(void)
161   * side effects - display to client user counts etc.
162   */
163   void
164 < show_lusers(struct Client *source_p)
164 > show_lusers(struct Client *source_p)
165   {
174  const char *from, *to;
175
176  if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
177  {
178    from = me.id;
179    to = source_p->id;
180  }
181  else
182  {
183    from = me.name;
184    to = source_p->name;
185  }
186
166    if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
167 <    sendto_one(source_p, form_str(RPL_LUSERCLIENT),
168 <               from, to, (Count.total-Count.invisi),
190 <               Count.invisi, dlink_list_length(&global_serv_list));
167 >    sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total-Count.invisi),
168 >                       Count.invisi, dlink_list_length(&global_serv_list));
169    else
170 <    sendto_one(source_p, form_str(RPL_LUSERCLIENT), from, to,
171 <               (Count.total-Count.invisi), Count.invisi, 1);
170 >    sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT,
171 >                       (Count.total-Count.invisi), Count.invisi, 1);
172  
173    if (Count.oper > 0)
174 <    sendto_one(source_p, form_str(RPL_LUSEROP),
197 <               from, to, Count.oper);
174 >    sendto_one_numeric(source_p, &me, RPL_LUSEROP, Count.oper);
175  
176    if (dlink_list_length(&unknown_list) > 0)
177 <    sendto_one(source_p, form_str(RPL_LUSERUNKNOWN),
201 <               from, to, dlink_list_length(&unknown_list));
177 >    sendto_one_numeric(source_p, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list));
178  
179    if (dlink_list_length(&global_channel_list) > 0)
180 <    sendto_one(source_p, form_str(RPL_LUSERCHANNELS),
205 <               from, to, dlink_list_length(&global_channel_list));
180 >    sendto_one_numeric(source_p, &me, RPL_LUSERCHANNELS, dlink_list_length(&global_channel_list));
181  
182    if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
183    {
184 <    sendto_one(source_p, form_str(RPL_LUSERME),
185 <               from, to, Count.local, Count.myserver);
211 <    sendto_one(source_p, form_str(RPL_LOCALUSERS),
212 <               from, to, Count.local, Count.max_loc);
184 >    sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.local, Count.myserver);
185 >    sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.local, Count.max_loc);
186    }
187    else
188    {
189 <    sendto_one(source_p, form_str(RPL_LUSERME),
190 <               from, to, Count.total, 0);
218 <    sendto_one(source_p, form_str(RPL_LOCALUSERS),
219 <               from, to, Count.total, Count.max_tot);
189 >    sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.total, 0);
190 >    sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.total, Count.max_tot);
191    }
192  
193 <  sendto_one(source_p, form_str(RPL_GLOBALUSERS),
223 <             from, to, Count.total, Count.max_tot);
193 >  sendto_one_numeric(source_p, &me, RPL_GLOBALUSERS, Count.total, Count.max_tot);
194  
195    if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
196 <    sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
197 <               Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
196 >    sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
197 >                       Count.max_loc_cli, Count.totalrestartcount);
198  
199    if (Count.local > Count.max_loc_cli)
200      Count.max_loc_cli = Count.local;
201  
202    if ((Count.local + Count.myserver) > Count.max_loc_con)
203 <    Count.max_loc_con = Count.local + Count.myserver;
203 >    Count.max_loc_con = Count.local + Count.myserver;
204   }
205  
206   /* show_isupport()
# Line 240 | Line 210 | show_lusers(struct Client *source_p)
210   * side effects - display to client what we support (for them)
211   */
212   void
213 < show_isupport(struct Client *source_p)
213 > show_isupport(struct Client *source_p)
214   {
215    const dlink_node *ptr = NULL;
216  
217    DLINK_FOREACH(ptr, support_list_lines.head)
218 <    sendto_one(source_p, form_str(RPL_ISUPPORT), me.name,
249 <               source_p->name, ptr->data);
218 >    sendto_one_numeric(source_p, &me, RPL_ISUPPORT, ptr->data);
219   }
220  
221 < /*
222 < ** register_local_user
223 < **      This function is called when both NICK and USER messages
224 < **      have been accepted for the client, in whatever order. Only
225 < **      after this, is the USER message propagated.
226 < **
227 < **      NICK's must be propagated at once when received, although
228 < **      it would be better to delay them too until full info is
229 < **      available. Doing it is not so simple though, would have
230 < **      to implement the following:
231 < **
232 < **      (actually it has been implemented already for a while) -orabidoo
233 < **
234 < **      1) user telnets in and gives only "NICK foobar" and waits
235 < **      2) another user far away logs in normally with the nick
236 < **         "foobar" (quite legal, as this server didn't propagate
237 < **         it).
238 < **      3) now this server gets nick "foobar" from outside, but
239 < **         has alread the same defined locally. Current server
240 < **         would just issue "KILL foobar" to clean out dups. But,
241 < **         this is not fair. It should actually request another
242 < **         nick from local user or kill him/her...
243 < */
221 >
222 > /* report_and_set_user_flags()
223 > *
224 > * inputs       - pointer to source_p
225 > *              - pointer to conf for this user
226 > * output       - NONE
227 > * side effects - Report to user any special flags
228 > *                they are getting, and set them.
229 > */
230 > static void
231 > report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
232 > {
233 >  /* If this user is being spoofed, tell them so */
234 >  if (IsConfDoSpoofIp(conf))
235 >    sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats.");
236 >
237 >  /* If this user is in the exception class, Set it "E lined" */
238 >  if (IsConfExemptKline(conf))
239 >  {
240 >    SetExemptKline(source_p);
241 >    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D/G lines. Congrats.");
242 >  }
243 >
244 >  /*
245 >   * The else here is to make sure that G line exempt users
246 >   * do not get noticed twice.
247 >   */
248 >  else if (IsConfExemptGline(conf))
249 >  {
250 >    SetExemptGline(source_p);
251 >    sendto_one_notice(source_p, &me, ":*** You are exempt from G lines. Congrats.");
252 >  }
253 >
254 >  if (IsConfExemptResv(conf))
255 >  {
256 >    SetExemptResv(source_p);
257 >    sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
258 >  }
259 >
260 >  /* If this user is exempt from user limits set it "F lined" */
261 >  if (IsConfExemptLimits(conf))
262 >  {
263 >    SetExemptLimits(source_p);
264 >    sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
265 >  }
266 >
267 >  if (IsConfCanFlood(conf))
268 >  {
269 >    SetCanFlood(source_p);
270 >    sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
271 >                      "protection, aren't you fearsome.");
272 >  }
273 > }
274 >
275 > /* introduce_client()
276 > *
277 > * inputs       - source_p
278 > * output       - NONE
279 > * side effects - This common function introduces a client to the rest
280 > *                of the net, either from a local client connect or
281 > *                from a remote connect.
282 > */
283 > static void
284 > introduce_client(struct Client *source_p)
285 > {
286 >  dlink_node *ptr = NULL;
287 >  char ubuf[IRCD_BUFSIZE] = "";
288 >
289 >  if (MyClient(source_p))
290 >    send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
291 >  else
292 >    send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
293 >
294 >  watch_check_hash(source_p, RPL_LOGON);
295 >
296 >  if (ubuf[0] == '\0')
297 >  {
298 >    ubuf[0] = '+';
299 >    ubuf[1] = '\0';
300 >  }
301 >
302 >  DLINK_FOREACH(ptr, serv_list.head)
303 >  {
304 >    struct Client *server = ptr->data;
305 >
306 >    if (server == source_p->from)
307 >      continue;
308 >
309 >    if (IsCapable(server, CAP_SVS))
310 >      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
311 >                 source_p->servptr->id,
312 >                 source_p->name, source_p->hopcount+1,
313 >                 (unsigned long)source_p->tsinfo,
314 >                 ubuf, source_p->username, source_p->host,
315 >                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
316 >                 "0" : source_p->sockhost, source_p->id,
317 >                 source_p->svid,
318 >                 source_p->info);
319 >    else
320 >      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
321 >                 source_p->servptr->id,
322 >                 source_p->name, source_p->hopcount+1,
323 >                 (unsigned long)source_p->tsinfo,
324 >                 ubuf, source_p->username, source_p->host,
325 >                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
326 >                 "0" : source_p->sockhost, source_p->id, source_p->info);
327 >
328 >    if (!EmptyString(source_p->certfp))
329 >      sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp);
330 >  }
331 > }
332 >
333 > /* user_welcome()
334 > *
335 > * inputs       - client pointer to client to welcome
336 > * output       - NONE
337 > * side effects -
338 > */
339 > static void
340 > user_welcome(struct Client *source_p)
341 > {
342 > #if defined(__TIME__) && defined(__DATE__)
343 >  static const char built_date[] = __DATE__ " at " __TIME__;
344 > #else
345 >  static const char built_date[] = "unknown";
346 > #endif
347 >
348 > #ifdef HAVE_LIBCRYPTO
349 >  if (HasFlag(source_p, FLAGS_SSL))
350 >  {
351 >    AddUMode(source_p, UMODE_SSL);
352 >    sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
353 >                      ssl_get_cipher(source_p->localClient->fd.ssl));
354 >  }
355 > #endif
356 >
357 >  sendto_one_numeric(source_p, &me, RPL_WELCOME, ServerInfo.network_name,
358 >                     source_p->name);
359 >  sendto_one_numeric(source_p, &me, RPL_YOURHOST,
360 >                     get_listener_name(source_p->localClient->listener), ircd_version);
361 >  sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
362 >  sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
363 >  show_isupport(source_p);
364 >
365 >  if (source_p->id[0])
366 >    sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id);
367 >
368 >  show_lusers(source_p);
369 >  motd_signon(source_p);
370 > }
371 >
372 > /* check_xline()
373 > *
374 > * inputs       - pointer to client to test
375 > * outupt       - 1 if exiting 0 if ok
376 > * side effects -
377 > */
378 > static int
379 > check_xline(struct Client *source_p)
380 > {
381 >  struct MaskItem *conf = NULL;
382 >  const char *reason = NULL;
383 >
384 >  if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
385 >  {
386 >    ++conf->count;
387 >
388 >    if (conf->reason)
389 >      reason = conf->reason;
390 >    else
391 >      reason = CONF_NOREASON;
392 >
393 >    sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
394 >                         "X-line Rejecting [%s] [%s], user %s [%s]",
395 >                         source_p->info, reason,
396 >                         get_client_name(source_p, HIDE_IP),
397 >                         source_p->sockhost);
398 >
399 >    ++ServerStats.is_ref;
400 >    exit_client(source_p, "Bad user info");
401 >    return 1;
402 >  }
403 >
404 >  return 0;
405 > }
406 >
407 > /*! \brief This function is called when both NICK and USER messages
408 > *      have been accepted for the client, in whatever order. Only
409 > *      after this, is the UID message propagated.
410 > * \param source_p Pointer to given client to introduce
411 > */
412   void
413   register_local_user(struct Client *source_p)
414   {
415    const char *id = NULL;
416    const struct MaskItem *conf = NULL;
417  
281  assert(source_p != NULL);
418    assert(source_p == source_p->from);
419    assert(MyConnect(source_p));
420    assert(!source_p->localClient->registration);
# Line 287 | Line 423 | register_local_user(struct Client *sourc
423  
424    if (ConfigFileEntry.ping_cookie)
425    {
426 <    if (!IsPingSent(source_p) && source_p->localClient->random_ping == 0)
426 >    if (!IsPingSent(source_p) && !source_p->localClient->random_ping)
427      {
428        do
429          source_p->localClient->random_ping = genrand_int32();
# Line 310 | Line 446 | register_local_user(struct Client *sourc
446    if (!check_client(source_p))
447      return;
448  
449 <  if (valid_hostname(source_p->host) == 0)
449 >  if (!valid_hostname(source_p->host))
450    {
451 <    sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You have an illegal "
452 <               "character in your hostname", me.name, source_p->name);
451 >    sendto_one_notice(source_p, &me, ":*** Notice -- You have an illegal "
452 >                      "character in your hostname");
453      strlcpy(source_p->host, source_p->sockhost,
454              sizeof(source_p->host));
455    }
# Line 322 | Line 458 | register_local_user(struct Client *sourc
458  
459    if (!IsGotId(source_p))
460    {
461 <    char username[USERLEN + 1];
461 >    char username[USERLEN + 1] = "";
462      const char *p = username;
463      unsigned int i = 0;
464  
465      if (IsNeedIdentd(conf))
466      {
467        ++ServerStats.is_ref;
468 <      sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You need to install "
469 <                 "identd to use this server", me.name, source_p->name);
470 <      exit_client(source_p, &me, "Install identd");
468 >      sendto_one_notice(source_p, &me, ":*** Notice -- You need to install "
469 >                        "identd to use this server");
470 >      exit_client(source_p, "Install identd");
471        return;
472      }
473  
# Line 347 | Line 483 | register_local_user(struct Client *sourc
483      source_p->username[i] = '\0';
484    }
485  
486 <  /* password check */
486 >  /* Password check */
487    if (!EmptyString(conf->passwd))
488    {
489      const char *pass = source_p->localClient->passwd;
# Line 355 | Line 491 | register_local_user(struct Client *sourc
491      if (!match_conf_password(pass, conf))
492      {
493        ++ServerStats.is_ref;
494 <      sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
495 <                 me.name, source_p->name);
496 <      exit_client(source_p, &me, "Bad Password");
494 >
495 >      sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
496 >      exit_client(source_p, "Bad Password");
497        return;
498      }
499    }
500  
501 <  /* don't free source_p->localClient->passwd here - it can be required
501 >  /*
502 >   * Don't free source_p->localClient->passwd here - it can be required
503     * by masked /stats I if there are auth{} blocks with need_password = no;
504     * --adx
505     */
506  
507 <  /* report if user has &^>= etc. and set flags as needed in source_p */
507 >  /*
508 >   * Report if user has &^>= etc. and set flags as needed in source_p
509 >   */
510    report_and_set_user_flags(source_p, conf);
511  
512    if (IsDead(source_p))
513      return;
514  
515 <  /* Limit clients -
515 >  /*
516 >   * Limit clients -
517     * We want to be able to have servers and F-line clients
518     * connect, so save room for "buffer" connections.
519     * Smaller servers may want to decrease this, and it should
520     * probably be just a percentage of the MAXCLIENTS...
521     *   -Taner
522     */
383  /* Except "F:" clients */
523    if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) ||
524        (Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p)))
525    {
# Line 388 | Line 527 | register_local_user(struct Client *sourc
527                           "Too many clients, rejecting %s[%s].",
528                           source_p->name, source_p->host);
529      ++ServerStats.is_ref;
530 <    exit_client(source_p, &me, "Sorry, server is full - try later");
530 >    exit_client(source_p, "Sorry, server is full - try later");
531      return;
532    }
533  
534 <  /* valid user name check */
396 <  if (valid_username(source_p->username, 1) == 0)
534 >  if (!valid_username(source_p->username, 1))
535    {
536 <    char tmpstr2[IRCD_BUFSIZE];
536 >    char tmpstr2[IRCD_BUFSIZE] = "";
537  
538      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
539                           "Invalid username: %s (%s@%s)",
# Line 403 | Line 541 | register_local_user(struct Client *sourc
541      ++ServerStats.is_ref;
542      snprintf(tmpstr2, sizeof(tmpstr2), "Invalid username [%s]",
543               source_p->username);
544 <    exit_client(source_p, &me, tmpstr2);
544 >    exit_client(source_p, tmpstr2);
545      return;
546    }
547  
548    if (check_xline(source_p))
549      return;
550  
551 <  while (hash_find_id((id = uid_get())) != NULL)
551 >  while (hash_find_id((id = uid_get())))
552      ;
553  
554    strlcpy(source_p->id, id, sizeof(source_p->id));
# Line 430 | Line 568 | register_local_user(struct Client *sourc
568      ++Count.invisi;
569    }
570  
571 <  if ((++Count.local) > Count.max_loc)
571 >  if (++Count.local > Count.max_loc)
572    {
573      Count.max_loc = Count.local;
574  
# Line 440 | Line 578 | register_local_user(struct Client *sourc
578                             Count.max_loc);
579    }
580  
443  /* Increment our total user count here */
581    if (++Count.total > Count.max_tot)
582      Count.max_tot = Count.total;
583    ++Count.totalrestartcount;
# Line 469 | Line 606 | register_local_user(struct Client *sourc
606   *              - username to register as
607   *              - host name to register as
608   *              - server name
472 *              - realname (gecos)
609   * output       - NONE
610   * side effects - This function is called when a remote client
611   *                is introduced by a server.
612   */
613   void
614 < register_remote_user(struct Client *source_p,
615 <                     const char *username, const char *host, const char *server,
480 <                     const char *realname)
614 > register_remote_user(struct Client *source_p, const char *username,
615 >                     const char *host, const char *server)
616   {
617    struct Client *target_p = NULL;
618  
484  assert(source_p != NULL);
619    assert(source_p->username != username);
620  
621 <  strlcpy(source_p->host, host, sizeof(source_p->host));
621 >  strlcpy(source_p->host, host, sizeof(source_p->host));
622    strlcpy(source_p->username, username, sizeof(source_p->username));
623  
624    /*
625 <   * coming from another server, take the servers word for it
625 >   * Coming from another server, take the servers word for it
626     */
627    source_p->servptr = hash_find_server(server);
628  
# Line 503 | Line 637 | register_remote_user(struct Client *sour
637                           "No server %s for user %s[%s@%s] from %s",
638                           server, source_p->name, source_p->username,
639                           source_p->host, source_p->from->name);
640 <    kill_client(source_p->from, source_p, "%s (Server doesn't exist)", me.name);
640 >    sendto_one(source_p->from,
641 >               ":%s KILL %s :%s (Ghosted, server %s doesn't exist)",
642 >               me.id, source_p->id, me.name, server);
643  
644      AddFlag(source_p, FLAGS_KILLED);
645 <    exit_client(source_p, &me, "Ghosted Client");
645 >    exit_client(source_p, "Ghosted Client");
646      return;
647    }
648  
# Line 517 | Line 653 | register_remote_user(struct Client *sour
653                           source_p->from->name, source_p->name, source_p->username,
654                           source_p->host, source_p->servptr->name,
655                           target_p->name, target_p->from->name);
656 <    kill_client(source_p->from, source_p,
657 <                "%s (NICK from wrong direction (%s != %s))",
658 <                me.name, source_p->servptr->name, target_p->from->name);
656 >    sendto_one(source_p->from,
657 >               ":%s KILL %s :%s (NICK from wrong direction (%s != %s))",
658 >               me.id, source_p->id, me.name, source_p->servptr->name,
659 >               target_p->from->name);
660 >
661      AddFlag(source_p, FLAGS_KILLED);
662 <    exit_client(source_p, &me, "USER server wrong direction");
662 >    exit_client(source_p, "USER server wrong direction");
663      return;
664    }
665  
# Line 532 | Line 670 | register_remote_user(struct Client *sour
670    if (HasFlag(source_p->servptr, FLAGS_SERVICE))
671      AddFlag(source_p, FLAGS_SERVICE);
672  
535  /* Increment our total user count here */
673    if (++Count.total > Count.max_tot)
674      Count.max_tot = Count.total;
675  
# Line 551 | Line 688 | register_remote_user(struct Client *sour
688    introduce_client(source_p);
689   }
690  
554 /* introduce_client()
555 *
556 * inputs       - source_p
557 * output       - NONE
558 * side effects - This common function introduces a client to the rest
559 *                of the net, either from a local client connect or
560 *                from a remote connect.
561 */
562 static void
563 introduce_client(struct Client *source_p)
564 {
565  dlink_node *server_node = NULL;
566  static char ubuf[12];
567
568  if (MyClient(source_p))
569    send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
570  else
571    send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
572
573  watch_check_hash(source_p, RPL_LOGON);
574
575  if (*ubuf == '\0')
576  {
577    ubuf[0] = '+';
578    ubuf[1] = '\0';
579  }
580
581  DLINK_FOREACH(server_node, serv_list.head)
582  {
583    struct Client *server = server_node->data;
584
585    if (server == source_p->from)
586        continue;
587
588    if (IsCapable(server, CAP_SVS))
589    {
590      if (IsCapable(server, CAP_TS6) && HasID(source_p))
591        sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
592                   source_p->servptr->id,
593                   source_p->name, source_p->hopcount+1,
594                   (unsigned long)source_p->tsinfo,
595                   ubuf, source_p->username, source_p->host,
596                   (MyClient(source_p) && IsIPSpoof(source_p)) ?
597                   "0" : source_p->sockhost, source_p->id,
598                   source_p->svid,
599                   source_p->info);
600      else
601        sendto_one(server, "NICK %s %d %lu %s %s %s %s %s :%s",
602                   source_p->name, source_p->hopcount+1,
603                   (unsigned long)source_p->tsinfo,
604                   ubuf, source_p->username, source_p->host,
605                   source_p->servptr->name, source_p->svid,
606                   source_p->info);
607
608    }
609    else
610    {
611      if (IsCapable(server, CAP_TS6) && HasID(source_p))
612        sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
613                   source_p->servptr->id,
614                   source_p->name, source_p->hopcount+1,
615                   (unsigned long)source_p->tsinfo,
616                   ubuf, source_p->username, source_p->host,
617                   (MyClient(source_p) && IsIPSpoof(source_p)) ?
618                   "0" : source_p->sockhost, source_p->id, source_p->info);
619      else
620        sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
621                   source_p->name, source_p->hopcount+1,
622                   (unsigned long)source_p->tsinfo,
623                   ubuf, source_p->username, source_p->host,
624                   source_p->servptr->name, source_p->info);
625    }
626
627    if (!EmptyString(source_p->certfp))
628      sendto_one(server, ":%s CERTFP %s", ID(source_p), source_p->certfp);
629  }
630 }
631
691   /* valid_hostname()
692   *
693   * Inputs       - pointer to hostname
# Line 643 | Line 702 | valid_hostname(const char *hostname)
702   {
703    const char *p = hostname;
704  
705 <  assert(p != NULL);
705 >  assert(p);
706  
707 <  if (*p == '.' || *p == ':')
707 >  if (EmptyString(p) || *p == '.' || *p == ':')
708      return 0;
709  
710    for (; *p; ++p)
# Line 672 | Line 731 | valid_username(const char *username, con
731    int dots      = 0;
732    const char *p = username;
733  
734 <  assert(p != NULL);
734 >  assert(p);
735  
736    if (*p == '~')
737      ++p;
# Line 723 | Line 782 | valid_nickname(const char *nickname, con
782    const char *p = nickname;
783    assert(nickname && *nickname);
784  
785 <  /* nicks can't start with a digit or - or be 0 length */
786 <  /* This closer duplicates behaviour of hybrid-6 */
785 >  assert(p);
786 >
787 >  /*
788 >   * Nicks can't start with a digit or - or be 0 length.
789 >   */
790    if (*p == '-' || (IsDigit(*p) && local) || *p == '\0')
791      return 0;
792  
# Line 735 | Line 797 | valid_nickname(const char *nickname, con
797    return p - nickname <= NICKLEN;
798   }
799  
738 /* report_and_set_user_flags()
739 *
740 * inputs       - pointer to source_p
741 *              - pointer to conf for this user
742 * output       - NONE
743 * side effects - Report to user any special flags
744 *                they are getting, and set them.
745 */
746 static void
747 report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
748 {
749  /* If this user is being spoofed, tell them so */
750  if (IsConfDoSpoofIp(conf))
751    sendto_one(source_p,
752               ":%s NOTICE %s :*** Spoofing your IP. Congrats.",
753               me.name, source_p->name);
754
755  /* If this user is in the exception class, Set it "E lined" */
756  if (IsConfExemptKline(conf))
757  {
758    SetExemptKline(source_p);
759    sendto_one(source_p,
760               ":%s NOTICE %s :*** You are exempt from K/D/G lines. Congrats.",
761               me.name, source_p->name);
762  }
763
764  /* The else here is to make sure that G line exempt users
765   * do not get noticed twice.
766   */
767  else if (IsConfExemptGline(conf))
768  {
769    SetExemptGline(source_p);
770    sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from G lines. Congrats.",
771               me.name, source_p->name);
772  }
773
774  if (IsConfExemptResv(conf))
775  {
776    SetExemptResv(source_p);
777    sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from resvs. Congrats.",
778               me.name, source_p->name);
779  }
780
781  /* If this user is exempt from user limits set it "F lined" */
782  if (IsConfExemptLimits(conf))
783  {
784    SetExemptLimits(source_p);
785    sendto_one(source_p,
786               ":%s NOTICE %s :*** You are exempt from user limits. Congrats.",
787               me.name,source_p->name);
788  }
789
790  if (IsConfCanFlood(conf))
791  {
792    SetCanFlood(source_p);
793    sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from flood "
794               "protection, aren't you fearsome.",
795               me.name, source_p->name);
796  }
797 }
798
799 /* set_user_mode()
800 *
801 * added 15/10/91 By Darren Reed.
802 * parv[0] - sender
803 * parv[1] - username to change mode for
804 * parv[2] - modes to change
805 */
806 void
807 set_user_mode(struct Client *client_p, struct Client *source_p,
808              const int parc, char *parv[])
809 {
810  unsigned int flag, setflags;
811  char **p, *m, buf[IRCD_BUFSIZE];
812  struct Client *target_p;
813  int what = MODE_ADD, badflag = 0, i;
814
815  assert(!(parc < 2));
816
817  if ((target_p = find_person(client_p, parv[1])) == NULL)
818  {
819    if (MyConnect(source_p))
820      sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
821                 me.name, source_p->name, parv[1]);
822    return;
823  }
824
825  if (source_p != target_p)
826  {
827     sendto_one(source_p, form_str(ERR_USERSDONTMATCH),
828                me.name, source_p->name);
829     return;
830  }
831
832  if (parc < 3)
833  {
834    m = buf;
835    *m++ = '+';
836
837    for (i = 0; i < 128; i++)
838      if (HasUMode(source_p, user_modes[i]))
839        *m++ = (char)i;
840    *m = '\0';
841
842    sendto_one(source_p, form_str(RPL_UMODEIS),
843               me.name, source_p->name, buf);
844    return;
845  }
846
847  /* find flags already set for user */
848  setflags = source_p->umodes;
849
850  /* parse mode change string(s) */
851  for (p = &parv[2]; p && *p; p++)
852  {
853    for (m = *p; *m; m++)
854    {
855      switch (*m)
856      {
857        case '+':
858          what = MODE_ADD;
859          break;
860        case '-':
861          what = MODE_DEL;
862          break;
863        case 'o':
864          if (what == MODE_ADD)
865          {
866            if (IsServer(client_p) && !HasUMode(source_p, UMODE_OPER))
867            {
868              ++Count.oper;
869              SetOper(source_p);
870            }
871          }
872          else
873          {
874            /* Only decrement the oper counts if an oper to begin with
875             * found by Pat Szuta, Perly , perly@xnet.com
876             */
877            if (!HasUMode(source_p, UMODE_OPER))
878              break;
879
880            ClearOper(source_p);
881            Count.oper--;
882
883            if (MyConnect(source_p))
884            {
885              dlink_node *dm;
886
887              detach_conf(source_p, CONF_OPER);
888              ClrOFlag(source_p);
889              DelUMode(source_p, ConfigFileEntry.oper_only_umodes);
890
891              if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
892                free_dlink_node(dm);
893            }
894          }
895
896          break;
897
898        case 'S':  /* Only servers may set +S in a burst */
899        case 'r':  /* Only services may set +r */
900        case 'x':  /* Only services may set +x */
901          break;
902
903        default:
904          if ((flag = user_modes[(unsigned char)*m]))
905          {
906            if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER) &&
907                (ConfigFileEntry.oper_only_umodes & flag))
908              badflag = 1;
909            else
910            {
911              if (what == MODE_ADD)
912                AddUMode(source_p, flag);
913              else
914                DelUMode(source_p, flag);
915            }
916          }
917          else
918          {
919            if (MyConnect(source_p))
920              badflag = 1;
921          }
922
923          break;
924      }
925    }
926  }
927
928  if (badflag)
929    sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG),
930               me.name, source_p->name);
931
932  if (MyConnect(source_p) && HasUMode(source_p, UMODE_ADMIN) &&
933      !HasOFlag(source_p, OPER_FLAG_ADMIN))
934  {
935    sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
936               me.name, source_p->name);
937    DelUMode(source_p, UMODE_ADMIN);
938  }
939
940  if (!(setflags & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
941    ++Count.invisi;
942  if ((setflags & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
943    --Count.invisi;
944
945  /*
946   * compare new flags with old flags and send string which
947   * will cause servers to update correctly.
948   */
949  send_umode_out(client_p, source_p, setflags);
950 }
951
800   /* send_umode()
801   * send the MODE string for user (user) to connection client_p
802   * -avalon
# Line 970 | Line 818 | send_umode(struct Client *client_p, stru
818    unsigned int flag;
819  
820    /*
821 <   * build a string in umode_buf to represent the change in the user's
821 >   * Build a string in umode_buf to represent the change in the user's
822     * mode between the new (source_p->umodes) and 'old'.
823     */
824 <  for (i = 0; i < 128; i++)
824 >  for (i = 0; i < 128; ++i)
825    {
826      flag = user_modes[i];
827      if (!flag)
# Line 1024 | Line 872 | void
872   send_umode_out(struct Client *client_p, struct Client *source_p,
873                 unsigned int old)
874   {
875 <  char buf[IRCD_BUFSIZE] = { '\0' };
1028 <  dlink_node *ptr = NULL;
875 >  char buf[IRCD_BUFSIZE] = "";
876  
877    send_umode(NULL, source_p, old, SEND_UMODES, buf);
878  
879    if (buf[0])
880 <  {
881 <    DLINK_FOREACH(ptr, serv_list.head)
1035 <    {
1036 <      struct Client *target_p = ptr->data;
1037 <
1038 <      if ((target_p != client_p) && (target_p != source_p))
1039 <        sendto_one(target_p, ":%s MODE %s :%s",
1040 <                   ID_or_name(source_p, target_p),
1041 <                   ID_or_name(source_p, target_p), buf);
1042 <    }
1043 <  }
880 >    sendto_server(source_p, NOCAPS, NOCAPS, ":%s MODE %s :%s",
881 >                  source_p->id, source_p->id, buf);
882  
883    if (client_p && MyClient(client_p))
884      send_umode(client_p, source_p, old, 0xffffffff, buf);
# Line 1069 | Line 907 | user_set_hostmask(struct Client *target_
907      default: return;
908    }
909  
910 <  sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
911 <                               target_p->name, target_p->username, target_p->host);
910 >  if (ConfigFileEntry.cycle_on_host_change)
911 >    sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
912 >                                 target_p->name, target_p->username, target_p->host);
913  
914    if (IsUserHostIp(target_p))
915      delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
# Line 1082 | Line 921 | user_set_hostmask(struct Client *target_
921  
922    if (MyClient(target_p))
923    {
924 <    sendto_one(target_p, form_str(RPL_NEWHOSTIS), me.name,
1086 <               target_p->name, target_p->host);
924 >    sendto_one_numeric(target_p, &me, RPL_NEWHOSTIS, target_p->host);
925      clear_ban_cache_client(target_p);
926    }
927  
# Line 1092 | Line 930 | user_set_hostmask(struct Client *target_
930  
931    DLINK_FOREACH(ptr, target_p->channel.head)
932    {
933 <    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = { '\0' };
933 >    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = "";
934      char *p = modebuf;
935      int len = 0;
936      const struct Membership *ms = ptr->data;
# Line 1134 | Line 972 | user_set_hostmask(struct Client *target_
972                                   target_p->host, target_p->away);
973   }
974  
975 < /* user_welcome()
976 < *
977 < * inputs       - client pointer to client to welcome
1140 < * output       - NONE
1141 < * side effects -
1142 < */
1143 < static void
1144 < user_welcome(struct Client *source_p)
1145 < {
1146 < #if defined(__TIME__) && defined(__DATE__)
1147 <  static const char built_date[] = __DATE__ " at " __TIME__;
1148 < #else
1149 <  static const char built_date[] = "unknown";
1150 < #endif
1151 <
1152 < #ifdef HAVE_LIBCRYPTO
1153 <  if (HasFlag(source_p, FLAGS_SSL))
1154 <  {
1155 <    AddUMode(source_p, UMODE_SSL);
1156 <    sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s",
1157 <               me.name, source_p->name,
1158 <               ssl_get_cipher(source_p->localClient->fd.ssl));
1159 <  }
1160 < #endif
1161 <
1162 <  sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name,
1163 <             ServerInfo.network_name, source_p->name);
1164 <  sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name,
1165 <             get_listener_name(source_p->localClient->listener), ircd_version);
1166 <  sendto_one(source_p, form_str(RPL_CREATED),
1167 <             me.name, source_p->name, built_date);
1168 <  sendto_one(source_p, form_str(RPL_MYINFO),
1169 <             me.name, source_p->name, me.name, ircd_version, umode_buffer);
1170 <  show_isupport(source_p);
1171 <
1172 <  if (source_p->id[0] != '\0')
1173 <    sendto_one(source_p, form_str(RPL_YOURID), me.name,
1174 <               source_p->name, source_p->id);
1175 <
1176 <  show_lusers(source_p);
1177 <  motd_signon(source_p);
1178 < }
1179 <
1180 < /* check_xline()
1181 < *
1182 < * inputs       - pointer to client to test
1183 < * outupt       - 1 if exiting 0 if ok
1184 < * side effects -
1185 < */
1186 < static int
1187 < check_xline(struct Client *source_p)
1188 < {
1189 <  struct MaskItem *conf = NULL;
1190 <  const char *reason = NULL;
1191 <
1192 <  if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
1193 <  {
1194 <    ++conf->count;
1195 <
1196 <    if (conf->reason != NULL)
1197 <      reason = conf->reason;
1198 <    else
1199 <      reason = "No Reason";
1200 <
1201 <    sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
1202 <                         "X-line Rejecting [%s] [%s], user %s [%s]",
1203 <                         source_p->info, reason,
1204 <                         get_client_name(source_p, HIDE_IP),
1205 <                         source_p->sockhost);
1206 <
1207 <    ++ServerStats.is_ref;
1208 <    exit_client(source_p, &me, "Bad user info");
1209 <    return 1;
1210 <  }
1211 <
1212 <  return 0;
1213 < }
1214 <
1215 < /* oper_up()
1216 < *
1217 < * inputs       - pointer to given client to oper
1218 < * output       - NONE
1219 < * side effects - Blindly opers up given source_p, using conf info
1220 < *                all checks on passwords have already been done.
1221 < *                This could also be used by rsa oper routines.
975 > /*! \brief Blindly opers up given source_p, using conf info.
976 > *         All checks on passwords have already been done.
977 > * \param source_p Pointer to given client to oper
978   */
979   void
980   oper_up(struct Client *source_p)
# Line 1252 | Line 1008 | oper_up(struct Client *source_p)
1008    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
1009                         get_oper_name(source_p));
1010    send_umode_out(source_p, source_p, old);
1011 <  sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1011 >  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
1012   }
1013  
1014   static char new_uid[TOTALSIDUID + 1];     /* allow for \0 */
# Line 1270 | Line 1026 | valid_sid(const char *sid)
1026  
1027   /*
1028   * init_uid()
1029 < *
1029 > *
1030   * inputs       - NONE
1031   * output       - NONE
1032   * side effects - new_uid is filled in with server id portion (sid)
# Line 1280 | Line 1036 | valid_sid(const char *sid)
1036   void
1037   init_uid(void)
1038   {
1283  unsigned int i;
1284
1039    memset(new_uid, 0, sizeof(new_uid));
1040  
1041    if (!EmptyString(ServerInfo.sid))
1042      strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1043  
1044 <  for (i = 0; i < IRC_MAXSID; ++i)
1045 <    if (new_uid[i] == '\0')
1044 >  for (unsigned int i = 0; i < IRC_MAXSID; ++i)
1045 >    if (new_uid[i] == '\0')
1046        new_uid[i] = 'A';
1047  
1048    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1295  /* Yes nenolod, I have known it was off by one ever since I wrote it
1296   * But *JUST* for you, though, it really doesn't look as *pretty*
1297   * -Dianora
1298   */
1049    memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1050   }
1051  
# Line 1457 | Line 1207 | rebuild_isupport_message_line(void)
1207    int n = 0;
1208    int tokens = 0;
1209    size_t len = 0;
1210 <  size_t reserve = strlen(me.name) + HOSTLEN + strlen(form_str(RPL_ISUPPORT));
1210 >  size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1211  
1212    DLINK_FOREACH_SAFE(ptr, ptr_next, support_list_lines.head)
1213    {

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)