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-7.3/src/s_user.c (file contents), Revision 1126 by michael, Sun Feb 20 14:30:12 2011 UTC vs.
ircd-hybrid/trunk/src/s_user.c (file contents), Revision 3318 by michael, Tue Apr 15 14:26:38 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 "common.h"
33 #include "fdlist.h"
34   #include "hash.h"
35   #include "irc_string.h"
36 #include "sprintf_irc.h"
37 #include "s_bsd.h"
36   #include "ircd.h"
37   #include "listener.h"
38   #include "motd.h"
39   #include "numeric.h"
40 < #include "s_conf.h"
41 < #include "s_log.h"
40 > #include "conf.h"
41 > #include "log.h"
42   #include "s_serv.h"
43   #include "send.h"
44   #include "supported.h"
47 #include "whowas.h"
45   #include "memory.h"
46   #include "packet.h"
47   #include "rng_mt.h"
48   #include "userhost.h"
52 #include "hook.h"
49   #include "s_misc.h"
50 < #include "msg.h"
50 > #include "parse.h"
51   #include "watch.h"
52  
57 unsigned int MaxClientCount     = 1;
58 unsigned int MaxConnectionCount = 1;
59 struct Callback *entering_umode_cb = NULL;
60 struct Callback *umode_cb = NULL;
61
53   static char umode_buffer[IRCD_BUFSIZE];
63
64 static void user_welcome(struct Client *);
65 static void report_and_set_user_flags(struct Client *, const struct AccessItem *);
66 static int check_xline(struct Client *);
67 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 <
74 < struct Isupport
59 > struct Isupport
60   {
61    dlink_node node;
62    char *name;
# Line 79 | Line 64 | struct Isupport
64    int number;
65   };
66  
67 < static dlink_list support_list = { NULL, NULL, 0 };
68 < MessageFile *isupportFile;
67 > static dlink_list support_list;
68 > static dlink_list support_list_lines;
69  
70   /* memory is cheap. map 0-255 to equivalent mode */
71 < unsigned int user_modes[256] =
71 > const unsigned int user_modes[256] =
72   {
73    /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x0F */
74    /* 0x10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1F */
# Line 92 | Line 77 | unsigned int user_modes[256] =
77    0,                  /* @ */
78    0,                  /* A */
79    0,                  /* B */
80 <  UMODE_CCONN_FULL,   /* C */
80 >  0,                  /* C */
81    UMODE_DEAF,         /* D */
82    0,                  /* E */
83 <  0,                  /* F */
83 >  UMODE_FARCONNECT,   /* F */
84    UMODE_SOFTCALLERID, /* G */
85 <  0,                  /* H */
85 >  UMODE_HIDDEN,       /* H */
86    0,                  /* I */
87    0,                  /* J */
88    0,                  /* K */
# Line 107 | Line 92 | unsigned int user_modes[256] =
92    0,                  /* O */
93    0,                  /* P */
94    0,                  /* Q */
95 <  0,                  /* R */
96 <  0,                  /* S */
95 >  UMODE_REGONLY,      /* R */
96 >  UMODE_SSL,          /* S */
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 */
108    UMODE_CCONN,        /* c */
109    UMODE_DEBUG,        /* d */
110 <  0,                  /* e */
110 >  UMODE_EXTERNAL,     /* e */
111    UMODE_FULL,         /* f */
112    UMODE_CALLERID,     /* g */
113    0,                  /* h */
114    UMODE_INVISIBLE,    /* i */
115 <  0,                  /* j */
115 >  UMODE_REJ,          /* j */
116    UMODE_SKILL,        /* k */
117    UMODE_LOCOPS,       /* l */
118    0,                  /* m */
# Line 135 | Line 120 | unsigned int user_modes[256] =
120    UMODE_OPER,         /* o */
121    0,                  /* p */
122    0,                  /* q */
123 <  UMODE_REJ,          /* r */
123 >  UMODE_REGISTERED,   /* r */
124    UMODE_SERVNOTICE,   /* s */
125    0,                  /* t */
126    UMODE_UNAUTH,       /* u */
127    0,                  /* v */
128    UMODE_WALLOP,       /* w */
129 <  UMODE_EXTERNAL,     /* x */
129 >  UMODE_HIDDENHOST,   /* x */
130    UMODE_SPY,          /* y */
131    UMODE_OPERWALL,     /* z      0x7A */
132    0,0,0,0,0,          /* 0x7B - 0x7F */
# Line 176 | 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   {
166 <  const char *from, *to;
167 <
168 <  if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
184 <  {
185 <    from = me.id;
186 <    to = source_p->id;
187 <  }
188 <  else
189 <  {
190 <    from = me.name;
191 <    to = source_p->name;
192 <  }
193 <
194 <  if (!ConfigServerHide.hide_servers || IsOper(source_p))
195 <    sendto_one(source_p, form_str(RPL_LUSERCLIENT),
196 <               from, to, (Count.total-Count.invisi),
197 <               Count.invisi, dlink_list_length(&global_serv_list));
166 >  if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
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),
204 <               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),
208 <               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),
212 <               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 || IsOper(source_p))
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);
218 <    sendto_one(source_p, form_str(RPL_LOCALUSERS),
219 <               from, to, Count.local, Count.max_loc,
220 <               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);
191 <    sendto_one(source_p, form_str(RPL_LOCALUSERS),
192 <               from, to, Count.total, Count.max_tot,
193 <               Count.total, Count.max_tot);
229 <  }
230 <
231 <  sendto_one(source_p, form_str(RPL_GLOBALUSERS),
232 <             from, to, Count.total, Count.max_tot,
233 <             Count.total, Count.max_tot);
234 <
235 <  if (!ConfigServerHide.hide_servers || IsOper(source_p))
236 <    sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
237 <               MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
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_numeric(source_p, &me, RPL_GLOBALUSERS, Count.total, Count.max_tot);
194  
195 <  if (Count.local > MaxClientCount)
196 <    MaxClientCount = Count.local;
195 >  if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
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.myserver) > MaxConnectionCount)
200 <    MaxConnectionCount = Count.local + Count.myserver;
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;
204   }
205  
206   /* show_isupport()
# Line 250 | 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 <  send_message_file(source_p, isupportFile);
215 >  const dlink_node *ptr = NULL;
216 >
217 >  DLINK_FOREACH(ptr, support_list_lines.head)
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 AccessItem *aconf = NULL;
286 <  dlink_node *ptr = NULL;
416 >  const struct MaskItem *conf = NULL;
417  
288  assert(source_p != NULL);
418    assert(source_p == source_p->from);
419    assert(MyConnect(source_p));
420    assert(!source_p->localClient->registration);
# Line 294 | 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 439 | register_local_user(struct Client *sourc
439        return;
440    }
441  
442 <  source_p->localClient->last = CurrentTime;
442 >  source_p->localClient->last_privmsg = CurrentTime;
443    /* Straight up the maximum rate of flooding... */
444    source_p->localClient->allow_read = MAX_FLOOD_BURST;
445  
446 <  if (!execute_callback(client_check_cb, source_p, source_p->username))
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    }
456  
457 <  ptr   = source_p->localClient->confs.head;
329 <  aconf = map_to_conf(ptr->data);
457 >  conf = source_p->localClient->confs.head->data;
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(aconf))
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  
474      strlcpy(username, source_p->username, sizeof(username));
475  
476 <    if (!IsNoTilde(aconf))
476 >    if (!IsNoTilde(conf))
477        source_p->username[i++] = '~';
478  
479      for (; *p && i < USERLEN; ++p)
# Line 355 | Line 483 | register_local_user(struct Client *sourc
483      source_p->username[i] = '\0';
484    }
485  
486 <  /* password check */
487 <  if (!EmptyString(aconf->passwd))
486 >  /* Password check */
487 >  if (!EmptyString(conf->passwd))
488    {
489      const char *pass = source_p->localClient->passwd;
490  
491 <    if (!match_conf_password(pass, aconf))
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 */
508 <  report_and_set_user_flags(source_p, aconf);
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     */
391  /* Except "F:" clients */
523    if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) ||
524        (Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p)))
525    {
526 <    sendto_realops_flags(UMODE_FULL, L_ALL,
526 >    sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
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 */
404 <  if (valid_username(source_p->username) == 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, "Invalid username: %s (%s@%s)",
538 >    sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
539 >                         "Invalid username: %s (%s@%s)",
540                           source_p->name, source_p->username, source_p->host);
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));
555    hash_add_id(source_p);
556  
557 <  sendto_realops_flags(UMODE_CCONN, L_ALL,
558 <                       "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
428 <                       source_p->name, source_p->username, source_p->host,
429 <                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
430 <                       "255.255.255.255" : source_p->sockhost,
431 <                       get_client_class(source_p),
432 <                       source_p->info);
433 <
434 <  sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
435 <                       "CLICONN %s %s %s %s %s %s %s 0 %s",
557 >  sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
558 >                       "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
559                         source_p->name, source_p->username, source_p->host,
560                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
561                         "255.255.255.255" : source_p->sockhost,
562 <                       get_client_class(source_p),
563 <                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
441 <                           "<hidden>" : source_p->localClient->client_host,
442 <                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
443 <                           "<hidden>" : source_p->localClient->client_server,
444 <                       source_p->info);
445 <
562 >                       get_client_class(&source_p->localClient->confs),
563 >                       source_p->info, source_p->id);
564  
565    if (ConfigFileEntry.invisible_on_connect)
566    {
567 <    source_p->umodes |= UMODE_INVISIBLE;
567 >    AddUMode(source_p, UMODE_INVISIBLE);
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  
575      if (!(Count.max_loc % 10))
576 <      sendto_realops_flags(UMODE_ALL, L_ALL, "New Max Local Clients: %d",
576 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
577 >                           "New Max Local Clients: %d",
578                             Count.max_loc);
579    }
580  
462  /* Increment our total user count here */
581    if (++Count.total > Count.max_tot)
582      Count.max_tot = Count.total;
583    ++Count.totalrestartcount;
# Line 488 | Line 606 | register_local_user(struct Client *sourc
606   *              - username to register as
607   *              - host name to register as
608   *              - server name
491 *              - 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,
499 <                     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  
503  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 = find_server(server);
627 >  source_p->servptr = hash_find_server(server);
628  
629 <  /* Super GhostDetect:
629 >  /*
630 >   * Super GhostDetect:
631     * If we can't find the server the user is supposed to be on,
632     * then simply blow the user away.        -Taner
633     */
634    if (source_p->servptr == NULL)
635    {
636 <    sendto_realops_flags(UMODE_ALL, L_ALL,
636 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
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 <    SetKilled(source_p);
645 <    exit_client(source_p, &me, "Ghosted Client");
644 >    AddFlag(source_p, FLAGS_KILLED);
645 >    exit_client(source_p, "Ghosted Client");
646      return;
647    }
648  
649    if ((target_p = source_p->servptr) && target_p->from != source_p->from)
650    {
651 <    sendto_realops_flags(UMODE_DEBUG, L_ALL,
651 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
652                           "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
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);
659 <    SetKilled(source_p);
660 <    exit_client(source_p, &me, "USER server wrong direction");
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, "USER server wrong direction");
663      return;
664    }
665  
666 <  /* Increment our total user count here */
666 >  /*
667 >   * If the nick has been introduced by a services server,
668 >   * make it a service as well.
669 >   */
670 >  if (HasFlag(source_p->servptr, FLAGS_SERVICE))
671 >    AddFlag(source_p, FLAGS_SERVICE);
672 >
673    if (++Count.total > Count.max_tot)
674      Count.max_tot = Count.total;
675  
# Line 552 | Line 678 | register_remote_user(struct Client *sour
678    add_user_host(source_p->username, source_p->host, 1);
679    SetUserHost(source_p);
680  
681 <  introduce_client(source_p);
682 < }
683 <
684 < /* introduce_client()
685 < *
686 < * inputs       - source_p
561 < * output       - NONE
562 < * side effects - This common function introduces a client to the rest
563 < *                of the net, either from a local client connect or
564 < *                from a remote connect.
565 < */
566 < static void
567 < introduce_client(struct Client *source_p)
568 < {
569 <  dlink_node *server_node = NULL;
570 <  static char ubuf[12];
571 <
572 <  if (MyClient(source_p))
573 <    send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
574 <  else
575 <    send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
576 <
577 <  watch_check_hash(source_p, RPL_LOGON);
578 <
579 <  if (*ubuf == '\0')
580 <  {
581 <    ubuf[0] = '+';
582 <    ubuf[1] = '\0';
583 <  }
584 <
585 <  DLINK_FOREACH(server_node, serv_list.head)
586 <  {
587 <    struct Client *server = server_node->data;
588 <
589 <    if (server == source_p->from)
590 <        continue;
681 >  if (HasFlag(source_p->servptr, FLAGS_EOB))
682 >    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
683 >                         "Client connecting at %s: %s (%s@%s) [%s] <%s>",
684 >                         source_p->servptr->name,
685 >                         source_p->name, source_p->username, source_p->host,
686 >                         source_p->info, source_p->id);
687  
688 <    if (IsCapable(server, CAP_TS6) && HasID(source_p))
593 <      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
594 <                 source_p->servptr->id,
595 <                 source_p->name, source_p->hopcount+1,
596 <                 (unsigned long)source_p->tsinfo,
597 <                 ubuf, source_p->username, source_p->host,
598 <                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
599 <                 "0" : source_p->sockhost, source_p->id, source_p->info);
600 <    else
601 <      sendto_one(server, "NICK %s %d %lu %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->info);
606 <  }
688 >  introduce_client(source_p);
689   }
690  
691   /* valid_hostname()
# Line 620 | 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)
711      if (!IsHostChar(*p))
712        return 0;
713  
714 <  return 1;
714 >  return p - hostname <= HOSTLEN;
715   }
716  
717   /* valid_username()
# Line 644 | Line 726 | valid_hostname(const char *hostname)
726   * style of username
727   */
728   int
729 < valid_username(const char *username)
729 > valid_username(const char *username, const int local)
730   {
731    int dots      = 0;
732    const char *p = username;
733  
734 <  assert(p != NULL);
734 >  assert(p);
735  
736    if (*p == '~')
737      ++p;
738  
739 <  /* reject usernames that don't start with an alphanum
739 >  /*
740 >   * Reject usernames that don't start with an alphanum
741     * i.e. reject jokers who have '-@somehost' or '.@somehost'
742     * or "-hi-@somehost", "h-----@somehost" would still be accepted.
743     */
744    if (!IsAlNum(*p))
745      return 0;
746  
747 <  while (*++p)
747 >  if (local)
748    {
749 <    if ((*p == '.') && ConfigFileEntry.dots_in_ident)
749 >    while (*++p)
750      {
751 <      if (++dots > ConfigFileEntry.dots_in_ident)
752 <        return 0;
753 <      if (!IsUserChar(*(p + 1)))
751 >      if ((*p == '.') && ConfigFileEntry.dots_in_ident)
752 >      {
753 >        if (++dots > ConfigFileEntry.dots_in_ident)
754 >          return 0;
755 >        if (!IsUserChar(*(p + 1)))
756 >          return 0;
757 >      }
758 >      else if (!IsUserChar(*p))
759          return 0;
760      }
673    else if (!IsUserChar(*p))
674      return 0;
675  }
676
677  return 1;
678 }
679
680 /* report_and_set_user_flags()
681 *
682 * inputs       - pointer to source_p
683 *              - pointer to aconf for this user
684 * output       - NONE
685 * side effects - Report to user any special flags
686 *                they are getting, and set them.
687 */
688 static void
689 report_and_set_user_flags(struct Client *source_p, const struct AccessItem *aconf)
690 {
691  /* If this user is being spoofed, tell them so */
692  if (IsConfDoSpoofIp(aconf))
693  {
694    sendto_one(source_p,
695               ":%s NOTICE %s :*** Spoofing your IP. congrats.",
696               me.name, source_p->name);
697  }
698
699  /* If this user is in the exception class, Set it "E lined" */
700  if (IsConfExemptKline(aconf))
701  {
702    SetExemptKline(source_p);
703    sendto_one(source_p,
704               ":%s NOTICE %s :*** You are exempt from K/D/G lines. congrats.",
705               me.name, source_p->name);
706  }
707
708  /* The else here is to make sure that G line exempt users
709   * do not get noticed twice.
710   */
711  else if (IsConfExemptGline(aconf))
712  {
713    SetExemptGline(source_p);
714    sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from G lines.",
715               me.name, source_p->name);
761    }
762 <
718 <  if (IsConfExemptResv(aconf))
719 <  {
720 <    SetExemptResv(source_p);
721 <    sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from resvs.",
722 <               me.name, source_p->name);
723 <  }
724 <
725 <  /* If this user is exempt from user limits set it "F lined" */
726 <  if (IsConfExemptLimits(aconf))
727 <  {
728 <    SetExemptLimits(source_p);
729 <    sendto_one(source_p,
730 <               ":%s NOTICE %s :*** You are exempt from user limits. congrats.",
731 <               me.name,source_p->name);
732 <  }
733 <
734 <  /* If this user is exempt from idle time outs */
735 <  if (IsConfIdlelined(aconf))
736 <  {
737 <    SetIdlelined(source_p);
738 <    sendto_one(source_p,
739 <               ":%s NOTICE %s :*** You are exempt from idle limits. congrats.",
740 <               me.name, source_p->name);
741 <  }
742 <
743 <  if (IsConfCanFlood(aconf))
762 >  else
763    {
764 <    SetCanFlood(source_p);
765 <    sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from flood "
766 <               "protection, aren't you fearsome.",
748 <               me.name, source_p->name);
764 >    while (*++p)
765 >      if (!IsUserChar(*p))
766 >        return 0;
767    }
750 }
751
752 /* change_simple_umode()
753 *
754 * this callback can be hooked to allow special handling of
755 * certain usermodes
756 */
757 static void *
758 change_simple_umode(va_list args)
759 {
760  struct Client *client_p;
761  struct Client *source_p;
762  int what;
763  unsigned int flag;
764
765  client_p = va_arg(args, struct Client *);
766  source_p = va_arg(args, struct Client *);
767  what = va_arg(args, int);
768  flag = va_arg(args, unsigned int);
769
770  if (what == MODE_ADD)
771    source_p->umodes |= flag;
772  else
773    source_p->umodes &= ~flag;
768  
769 <  return NULL;
769 >  return  p - username <= USERLEN;;
770   }
771  
772 < /* set_user_mode()
772 > /* clean_nick_name()
773   *
774 < * added 15/10/91 By Darren Reed.
775 < * parv[0] - sender
776 < * parv[1] - username to change mode for
777 < * parv[2] - modes to change
774 > * input        - nickname
775 > *              - whether it's a local nick (1) or remote (0)
776 > * output       - none
777 > * side effects - walks through the nickname, returning 0 if erroneous
778   */
779 < void
780 < set_user_mode(struct Client *client_p, struct Client *source_p,
787 <              int parc, char *parv[])
779 > int
780 > valid_nickname(const char *nickname, const int local)
781   {
782 <  unsigned int flag, setflags;
790 <  char **p, *m, buf[IRCD_BUFSIZE];
791 <  struct Client *target_p;
792 <  int what = MODE_ADD, badflag = 0, i;
793 <
794 <  assert(!(parc < 2));
795 <
796 <  if ((target_p = find_person(client_p, parv[1])) == NULL)
797 <  {
798 <    if (MyConnect(source_p))
799 <      sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
800 <                 me.name, source_p->name, parv[1]);
801 <    return;
802 <  }
803 <
804 <  if (IsServer(source_p))
805 <  {
806 <     sendto_realops_flags(UMODE_ALL, L_ADMIN, "*** Mode for User %s from %s",
807 <                          parv[1], source_p->name);
808 <     return;
809 <  }
810 <
811 <  if (source_p != target_p)
812 <  {
813 <     sendto_one(source_p, form_str(ERR_USERSDONTMATCH),
814 <                me.name, source_p->name);
815 <     return;
816 <  }
817 <
818 <  if (parc < 3)
819 <  {
820 <    m = buf;
821 <    *m++ = '+';
822 <
823 <    for (i = 0; i < 128; i++)
824 <      if (source_p->umodes & user_modes[i])
825 <        *m++ = (char)i;
826 <    *m = '\0';
827 <
828 <    sendto_one(source_p, form_str(RPL_UMODEIS),
829 <               me.name, source_p->name, buf);
830 <    return;
831 <  }
832 <
833 <  execute_callback(entering_umode_cb, client_p, source_p);
834 <
835 <  /* find flags already set for user */
836 <  setflags = source_p->umodes;
837 <
838 <  /* parse mode change string(s) */
839 <  for (p = &parv[2]; p && *p; p++)
840 <  {
841 <    for (m = *p; *m; m++)
842 <    {
843 <      switch (*m)
844 <      {
845 <        case '+':
846 <          what = MODE_ADD;
847 <          break;
848 <        case '-':
849 <          what = MODE_DEL;
850 <          break;
851 <        case 'o':
852 <          if (what == MODE_ADD)
853 <          {
854 <            if (IsServer(client_p) && !IsOper(source_p))
855 <            {
856 <              ++Count.oper;
857 <              SetOper(source_p);
858 <            }
859 <          }
860 <          else
861 <          {
862 <            /* Only decrement the oper counts if an oper to begin with
863 <             * found by Pat Szuta, Perly , perly@xnet.com
864 <             */
865 <            if (!IsOper(source_p))
866 <              break;
867 <
868 <            ClearOper(source_p);
869 <            Count.oper--;
870 <
871 <            if (MyConnect(source_p))
872 <            {
873 <              dlink_node *dm;
874 <
875 <              detach_conf(source_p, OPER_TYPE);
876 <              ClearOperFlags(source_p);
877 <              source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
878 <
879 <              if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
880 <                free_dlink_node(dm);
881 <            }
882 <          }
883 <
884 <          break;
885 <
886 <        /* we may not get these,
887 <         * but they shouldnt be in default
888 <         */
889 <        case ' ' :
890 <        case '\n':
891 <        case '\r':
892 <        case '\t':
893 <          break;
894 <
895 <        default:
896 <          if ((flag = user_modes[(unsigned char)*m]))
897 <          {
898 <            if (MyConnect(source_p) && !IsOper(source_p) &&
899 <                (ConfigFileEntry.oper_only_umodes & flag))
900 <            {
901 <              badflag = 1;
902 <            }
903 <            else
904 <              execute_callback(umode_cb, client_p, source_p, what, flag);
905 <          }
906 <          else
907 <          {
908 <            if (MyConnect(source_p))
909 <              badflag = 1;
910 <          }
911 <
912 <          break;
913 <      }
914 <    }
915 <  }
916 <
917 <  if (badflag)
918 <    sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG),
919 <               me.name, source_p->name);
920 <
921 <  if ((source_p->umodes & UMODE_NCHANGE) && !IsOperN(source_p))
922 <  {
923 <    sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
924 <               me.name, source_p->name);
925 <    source_p->umodes &= ~UMODE_NCHANGE; /* only tcm's really need this */
926 <  }
927 <
928 <  if (MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
929 <      !IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
930 <  {
931 <    sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
932 <               me.name, source_p->name);
933 <    source_p->umodes &= ~UMODE_ADMIN;
934 <  }
782 >  const char *p = nickname;
783  
784 <  if (!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
937 <    ++Count.invisi;
938 <  if ((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
939 <    --Count.invisi;
784 >  assert(nickname && *nickname);
785  
786    /*
787 <   * compare new flags with old flags and send string which
943 <   * will cause servers to update correctly.
787 >   * Nicks can't start with a digit or - or be 0 length.
788     */
789 <  send_umode_out(client_p, source_p, setflags);
789 >  if (*p == '-' || (IsDigit(*p) && local) || *p == '\0')
790 >    return 0;
791 >
792 >  for (; *p; ++p)
793 >    if (!IsNickChar(*p))
794 >      return 0;
795 >
796 >  return p - nickname <= NICKLEN;
797   }
798  
799   /* send_umode()
# Line 966 | Line 817 | send_umode(struct Client *client_p, stru
817    unsigned int flag;
818  
819    /*
820 <   * build a string in umode_buf to represent the change in the user's
820 >   * Build a string in umode_buf to represent the change in the user's
821     * mode between the new (source_p->umodes) and 'old'.
822     */
823 <  for (i = 0; i < 128; i++)
823 >  for (i = 0; i < 128; ++i)
824    {
825      flag = user_modes[i];
826      if (!flag)
# Line 978 | Line 829 | send_umode(struct Client *client_p, stru
829      if (MyClient(source_p) && !(flag & sendmask))
830        continue;
831  
832 <    if ((flag & old) && !(source_p->umodes & flag))
832 >    if ((flag & old) && !HasUMode(source_p, flag))
833      {
834        if (what == MODE_DEL)
835          *m++ = (char)i;
# Line 989 | Line 840 | send_umode(struct Client *client_p, stru
840          *m++ = (char)i;
841        }
842      }
843 <    else if (!(flag & old) && (source_p->umodes & flag))
843 >    else if (!(flag & old) && HasUMode(source_p, flag))
844      {
845        if (what == MODE_ADD)
846          *m++ = (char)i;
# Line 1020 | Line 871 | void
871   send_umode_out(struct Client *client_p, struct Client *source_p,
872                 unsigned int old)
873   {
874 <  char buf[IRCD_BUFSIZE] = { '\0' };
1024 <  dlink_node *ptr = NULL;
874 >  char buf[IRCD_BUFSIZE] = "";
875  
876 <  send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1027 <             SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
876 >  send_umode(NULL, source_p, old, SEND_UMODES, buf);
877  
878    if (buf[0])
879 <  {
880 <    DLINK_FOREACH(ptr, serv_list.head)
1032 <    {
1033 <      struct Client *target_p = ptr->data;
1034 <
1035 <      if ((target_p != client_p) && (target_p != source_p))
1036 <        sendto_one(target_p, ":%s MODE %s :%s",
1037 <                   ID_or_name(source_p, target_p),
1038 <                   ID_or_name(source_p, target_p), buf);
1039 <    }
1040 <  }
879 >    sendto_server(source_p, NOCAPS, NOCAPS, ":%s MODE %s :%s",
880 >                  source_p->id, source_p->id, buf);
881  
882    if (client_p && MyClient(client_p))
883      send_umode(client_p, source_p, old, 0xffffffff, buf);
884   }
885  
886 < /* user_welcome()
887 < *
1048 < * inputs       - client pointer to client to welcome
1049 < * output       - NONE
1050 < * side effects -
1051 < */
1052 < static void
1053 < user_welcome(struct Client *source_p)
886 > void
887 > user_set_hostmask(struct Client *target_p, const char *hostname, const int what)
888   {
889 < #if defined(__TIME__) && defined(__DATE__)
1056 <  static const char built_date[] = __DATE__ " at " __TIME__;
1057 < #else
1058 <  static const char built_date[] = "unknown";
1059 < #endif
889 >  dlink_node *ptr = NULL;
890  
891 < #ifdef HAVE_LIBCRYPTO
892 <  if (source_p->localClient->fd.ssl != NULL)
1063 <    sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s",
1064 <               me.name, source_p->name,
1065 <               ssl_get_cipher(source_p->localClient->fd.ssl));
1066 < #endif
891 >  if (!strcmp(target_p->host, hostname))
892 >    return;
893  
894 <  sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name,
895 <             ServerInfo.network_name, source_p->name);
896 <  sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name,
897 <             get_listener_name(source_p->localClient->listener), ircd_version);
898 <  sendto_one(source_p, form_str(RPL_CREATED),
899 <             me.name, source_p->name, built_date);
900 <  sendto_one(source_p, form_str(RPL_MYINFO),
901 <             me.name, source_p->name, me.name, ircd_version, umode_buffer);
902 <  show_isupport(source_p);
894 >  switch (what)
895 >  {
896 >    case MODE_ADD:
897 >      AddUMode(target_p, UMODE_HIDDENHOST);
898 >      AddFlag(target_p, FLAGS_IP_SPOOFING);
899 >      break;
900 >    case MODE_DEL:
901 >      DelUMode(target_p, UMODE_HIDDENHOST);
902 >
903 >      if (!HasFlag(target_p, FLAGS_AUTH_SPOOF))
904 >        DelFlag(target_p, FLAGS_IP_SPOOFING);
905 >      break;
906 >    default: return;
907 >  }
908  
909 <  if (source_p->id[0] != '\0')
910 <    sendto_one(source_p, form_str(RPL_YOURID), me.name,
911 <               source_p->name, source_p->id);
909 >  if (ConfigFileEntry.cycle_on_host_change)
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);
912  
913 <  show_lusers(source_p);
913 >  if (IsUserHostIp(target_p))
914 >    delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
915 >
916 >  strlcpy(target_p->host, hostname, sizeof(target_p->host));
917  
918 <  if (ConfigFileEntry.short_motd)
918 >  add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
919 >  SetUserHost(target_p);
920 >
921 >  if (MyClient(target_p))
922    {
923 <    sendto_one(source_p, ":%s NOTICE %s :*** Notice -- motd was last changed at %s",
924 <               me.name, source_p->name, ConfigFileEntry.motd.lastChangedDate);
1088 <    sendto_one(source_p,
1089 <               ":%s NOTICE %s :*** Notice -- Please read the motd if you haven't "
1090 <               "read it", me.name, source_p->name);
1091 <    sendto_one(source_p, form_str(RPL_MOTDSTART),
1092 <               me.name, source_p->name, me.name);
1093 <    sendto_one(source_p, form_str(RPL_MOTD),
1094 <               me.name, source_p->name,
1095 <               "*** This is the short motd ***");
1096 <    sendto_one(source_p, form_str(RPL_ENDOFMOTD),
1097 <               me.name, source_p->name);
923 >    sendto_one_numeric(target_p, &me, RPL_NEWHOSTIS, target_p->host);
924 >    clear_ban_cache_client(target_p);
925    }
1099  else  
1100    send_message_file(source_p, &ConfigFileEntry.motd);
1101 }
926  
927 < /* check_xline()
928 < *
1105 < * inputs       - pointer to client to test
1106 < * outupt       - 1 if exiting 0 if ok
1107 < * side effects -
1108 < */
1109 < static int
1110 < check_xline(struct Client *source_p)
1111 < {
1112 <  struct ConfItem *conf = NULL;
1113 <  const char *reason = NULL;
927 >  if (!ConfigFileEntry.cycle_on_host_change)
928 >    return;
929  
930 <  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1116 <      (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
930 >  DLINK_FOREACH(ptr, target_p->channel.head)
931    {
932 <    struct MatchItem *reg = map_to_conf(conf);
933 <
934 <    ++reg->count;
932 >    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = "";
933 >    char *p = modebuf;
934 >    int len = 0;
935 >    const struct Membership *ms = ptr->data;
936  
937 <    if (reg->reason != NULL)
938 <      reason = reg->reason;
939 <    else
940 <      reason = "No Reason";
937 >    if (has_member_flags(ms, CHFL_CHANOP))
938 >    {
939 >      *p++ = 'o';
940 >      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
941 >    }
942  
943 <    sendto_realops_flags(UMODE_REJ, L_ALL,
944 <                         "X-line Rejecting [%s] [%s], user %s [%s]",
945 <                         source_p->info, reason,
946 <                         get_client_name(source_p, HIDE_IP),
947 <                         source_p->sockhost);
943 >    if (has_member_flags(ms, CHFL_HALFOP))
944 >    {
945 >      *p++ = 'h';
946 >      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
947 >    }
948  
949 <    ++ServerStats.is_ref;
1134 <    if (REJECT_HOLD_TIME > 0)
949 >    if (has_member_flags(ms, CHFL_VOICE))
950      {
951 <      sendto_one(source_p, ":%s NOTICE %s :Bad user info",
952 <                 me.name, source_p->name);
1138 <      source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
1139 <      SetCaptured(source_p);
951 >      *p++ = 'v';
952 >      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
953      }
1141    else
1142      exit_client(source_p, &me, "Bad user info");
1143    return 1;
1144  }
954  
955 <  return 0;
1147 < }
955 >    *p = '\0';
956  
957 < /* oper_up()
958 < *
959 < * inputs       - pointer to given client to oper
960 < * output       - NONE
961 < * side effects - Blindly opers up given source_p, using aconf info
962 < *                all checks on passwords have already been done.
963 < *                This could also be used by rsa oper routines.
957 >    sendto_channel_local_butone(target_p, 0, 0, ms->chptr, ":%s!%s@%s JOIN :%s",
958 >                                target_p->name, target_p->username, target_p->host,
959 >                                ms->chptr->chname);
960 >    if (nickbuf[0])
961 >      sendto_channel_local_butone(target_p, 0, 0, ms->chptr, ":%s MODE %s +%s %s",
962 >                                  target_p->servptr->name, ms->chptr->chname,
963 >                                  modebuf, nickbuf);
964 >
965 >  }
966 >
967 >  if (target_p->away[0])
968 >    sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY,
969 >                                 ":%s!%s@%s AWAY :%s",
970 >                                 target_p->name, target_p->username,
971 >                                 target_p->host, target_p->away);
972 > }
973 >
974 > /*! \brief Blindly opers up given source_p, using conf info.
975 > *         All checks on passwords have already been done.
976 > * \param source_p Pointer to given client to oper
977   */
978   void
979   oper_up(struct Client *source_p)
980   {
981 <  unsigned int old = source_p->umodes;
982 <  const char *operprivs = "";
1162 <  const struct AccessItem *oconf = NULL;
981 >  const unsigned int old = source_p->umodes;
982 >  const struct MaskItem *conf = source_p->localClient->confs.head->data;
983  
984    assert(source_p->localClient->confs.head);
1165  oconf = map_to_conf((source_p->localClient->confs.head)->data);
985  
986    ++Count.oper;
987    SetOper(source_p);
988  
989 <  if (oconf->modes)
990 <    source_p->umodes |= oconf->modes;
989 >  if (conf->modes)
990 >    AddUMode(source_p, conf->modes);
991    else if (ConfigFileEntry.oper_umodes)
992 <    source_p->umodes |= ConfigFileEntry.oper_umodes;
1174 <  else
1175 <    source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1176 <                         UMODE_WALLOP|UMODE_LOCOPS);
992 >    AddUMode(source_p, ConfigFileEntry.oper_umodes);
993  
994 <  if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
994 >  if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
995      ++Count.invisi;
996 <  if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
996 >  if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
997      --Count.invisi;
998  
999    assert(dlinkFind(&oper_list, source_p) == NULL);
1000    dlinkAdd(source_p, make_dlink_node(), &oper_list);
1001  
1002 <  operprivs = oper_privs_as_string(oconf->port);
1002 >  AddOFlag(source_p, conf->port);
1003  
1004 <  SetOFlag(source_p, oconf->port);
1004 >  if (HasOFlag(source_p, OPER_FLAG_ADMIN))
1005 >    AddUMode(source_p, UMODE_ADMIN);
1006  
1007 <  if (IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))
1008 <    source_p->umodes |= UMODE_ADMIN;
1192 <  if (!IsOperN(source_p))
1193 <    source_p->umodes &= ~UMODE_NCHANGE;
1194 <
1195 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s (%s@%s) is now an operator",
1196 <                       source_p->name, source_p->username, source_p->host);
1007 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
1008 >                       get_oper_name(source_p));
1009    send_umode_out(source_p, source_p, old);
1010 <  sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1199 <  sendto_one(source_p, ":%s NOTICE %s :*** Oper privs are %s",
1200 <             me.name, source_p->name, operprivs);
1201 <  send_message_file(source_p, &ConfigFileEntry.opermotd);
1010 >  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
1011   }
1012  
1013   static char new_uid[TOTALSIDUID + 1];     /* allow for \0 */
# Line 1216 | Line 1025 | valid_sid(const char *sid)
1025  
1026   /*
1027   * init_uid()
1028 < *
1028 > *
1029   * inputs       - NONE
1030   * output       - NONE
1031   * side effects - new_uid is filled in with server id portion (sid)
# Line 1226 | Line 1035 | valid_sid(const char *sid)
1035   void
1036   init_uid(void)
1037   {
1229  int i;
1230
1038    memset(new_uid, 0, sizeof(new_uid));
1039  
1040    if (!EmptyString(ServerInfo.sid))
1041      strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1042  
1043 <  for (i = 0; i < IRC_MAXSID; ++i)
1044 <    if (new_uid[i] == '\0')
1043 >  for (unsigned int i = 0; i < IRC_MAXSID; ++i)
1044 >    if (new_uid[i] == '\0')
1045        new_uid[i] = 'A';
1046  
1047    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1241  /* Yes nenolod, I have known it was off by one ever since I wrote it
1242   * But *JUST* for you, though, it really doesn't look as *pretty*
1243   * -Dianora
1244   */
1048    memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1246
1247  entering_umode_cb = register_callback("entering_umode", NULL);
1248  umode_cb = register_callback("changing_umode", change_simple_umode);
1049   }
1050  
1051   /*
# Line 1305 | Line 1105 | uid_get(void)
1105   void
1106   init_isupport(void)
1107   {
1308  isupportFile = init_MessageLine();
1309
1108    add_isupport("CALLERID", NULL, -1);
1109    add_isupport("CASEMAPPING", CASEMAP, -1);
1110    add_isupport("DEAF", "D", -1);
1111    add_isupport("KICKLEN", NULL, KICKLEN);
1112    add_isupport("MODES", NULL, MAXMODEPARAMS);
1315  add_isupport("NICKLEN", NULL, NICKLEN-1);
1113   #ifdef HALFOPS
1114    add_isupport("PREFIX", "(ohv)@%+", -1);
1115    add_isupport("STATUSMSG", "@%+", -1);
# Line 1320 | Line 1117 | init_isupport(void)
1117    add_isupport("PREFIX", "(ov)@+", -1);
1118    add_isupport("STATUSMSG", "@+", -1);
1119   #endif
1120 <  add_isupport("TOPICLEN", NULL, TOPICLEN);
1120 >  add_isupport("EXCEPTS", "e", -1);
1121 >  add_isupport("INVEX", "I", -1);
1122   }
1123  
1124   /*
# Line 1355 | Line 1153 | add_isupport(const char *name, const cha
1153      dlinkAddTail(support, &support->node, &support_list);
1154    }
1155  
1156 <  DupString(support->name, name);
1156 >  support->name = xstrdup(name);
1157    if (options != NULL)
1158 <    DupString(support->options, options);
1158 >    support->options = xstrdup(options);
1159    support->number = n;
1160  
1161    rebuild_isupport_message_line();
# Line 1404 | Line 1202 | rebuild_isupport_message_line(void)
1202   {
1203    char isupportbuffer[IRCD_BUFSIZE];
1204    char *p = isupportbuffer;
1205 <  dlink_node *ptr = NULL;
1205 >  dlink_node *ptr = NULL, *ptr_next = NULL;
1206    int n = 0;
1207    int tokens = 0;
1208    size_t len = 0;
1209 <  size_t reserve = strlen(me.name) + HOSTLEN + strlen(form_str(RPL_ISUPPORT));
1209 >  size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1210  
1211 <  destroy_MessageLine(isupportFile);
1211 >  DLINK_FOREACH_SAFE(ptr, ptr_next, support_list_lines.head)
1212 >  {
1213 >    dlinkDelete(ptr, &support_list_lines);
1214 >    MyFree(ptr->data);
1215 >    free_dlink_node(ptr);
1216 >  }
1217  
1218    DLINK_FOREACH(ptr, support_list.head)
1219    {
1220      struct Isupport *support = ptr->data;
1221  
1222 <    p += (n = ircsprintf(p, "%s", support->name));
1222 >    p += (n = sprintf(p, "%s", support->name));
1223      len += n;
1224  
1225      if (support->options != NULL)
1226      {
1227 <      p += (n = ircsprintf(p, "=%s", support->options));
1227 >      p += (n = sprintf(p, "=%s", support->options));
1228        len += n;
1229      }
1230  
1231      if (support->number > 0)
1232      {
1233 <      p += (n = ircsprintf(p, "=%d", support->number));
1233 >      p += (n = sprintf(p, "=%d", support->number));
1234        len += n;
1235      }
1236  
# Line 1440 | Line 1243 | rebuild_isupport_message_line(void)
1243        if (*--p == ' ')
1244          *p = '\0';
1245  
1246 <      addto_MessageLine(isupportFile, isupportbuffer);
1246 >      dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1247        p = isupportbuffer;
1248        len = 0;
1249        n = tokens = 0;
# Line 1451 | Line 1254 | rebuild_isupport_message_line(void)
1254    {
1255      if (*--p == ' ')
1256        *p = '\0';
1257 <    addto_MessageLine(isupportFile, isupportbuffer);
1257 >    dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1258    }
1259   }

Diff Legend

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