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

Comparing ircd-hybrid/trunk/src/conf.c (file contents):
Revision 2525 by michael, Sat Nov 2 17:07:38 2013 UTC vs.
Revision 8279 by michael, Tue Feb 20 19:30:13 2018 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  conf.c: Configuration file 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-2018 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 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file conf.c
23 > * \brief Configuration file functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "ircd_defs.h"
30   #include "conf.h"
31 < #include "s_serv.h"
32 < #include "resv.h"
31 > #include "conf_cluster.h"
32 > #include "conf_gecos.h"
33 > #include "conf_pseudo.h"
34 > #include "conf_resv.h"
35 > #include "conf_service.h"
36 > #include "conf_shared.h"
37 > #include "server.h"
38   #include "channel.h"
39   #include "client.h"
40   #include "event.h"
34 #include "hook.h"
41   #include "irc_string.h"
42   #include "s_bsd.h"
43   #include "ircd.h"
# Line 42 | Line 48
48   #include "fdlist.h"
49   #include "log.h"
50   #include "send.h"
45 #include "s_gline.h"
51   #include "memory.h"
52 < #include "mempool.h"
48 < #include "irc_res.h"
52 > #include "res.h"
53   #include "userhost.h"
54 < #include "s_user.h"
54 > #include "user.h"
55   #include "channel_mode.h"
56   #include "parse.h"
57 < #include "s_misc.h"
57 > #include "misc.h"
58   #include "conf_db.h"
59   #include "conf_class.h"
60   #include "motd.h"
61 + #include "ipcache.h"
62 + #include "isupport.h"
63 + #include "whowas.h"
64  
65 < struct config_server_hide ConfigServerHide;
65 >
66 > struct config_channel_entry ConfigChannel;
67 > struct config_serverhide_entry ConfigServerHide;
68 > struct config_general_entry ConfigGeneral;
69 > struct config_log_entry ConfigLog = { .use_logging = 1 };
70 > struct config_serverinfo_entry ConfigServerInfo;
71 > struct config_admin_entry ConfigAdminInfo;
72 > struct conf_parser_context conf_parser_ctx;
73  
74   /* general conf items link list root, other than k lines etc. */
75 < dlink_list service_items = { NULL, NULL, 0 };
76 < dlink_list server_items  = { NULL, NULL, 0 };
63 < dlink_list cluster_items = { NULL, NULL, 0 };
64 < dlink_list oconf_items   = { NULL, NULL, 0 };
65 < dlink_list uconf_items   = { NULL, NULL, 0 };
66 < dlink_list xconf_items   = { NULL, NULL, 0 };
67 < dlink_list nresv_items   = { NULL, NULL, 0 };
68 < dlink_list cresv_items = { NULL, NULL, 0 };
75 > dlink_list connect_items;
76 > dlink_list operator_items;
77  
78   extern unsigned int lineno;
79   extern char linebuf[];
80   extern char conffilebuf[IRCD_BUFSIZE];
81   extern int yyparse(); /* defined in y.tab.c */
82  
75 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
76
77 /* internally defined functions */
78 static void read_conf(FILE *);
79 static void clear_out_old_conf(void);
80 static void expire_tklines(dlink_list *);
81 static void garbage_collect_ip_entries(void);
82 static int hash_ip(struct irc_ssaddr *);
83 static int verify_access(struct Client *);
84 static int attach_iline(struct Client *, struct MaskItem *);
85 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
86 static dlink_list *map_to_list(enum maskitem_type);
87 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
88
89
90 /* usually, with hash tables, you use a prime number...
91 * but in this case I am dealing with ip addresses,
92 * not ascii strings.
93 */
94 #define IP_HASH_SIZE 0x1000
95
96 struct ip_entry
97 {
98  struct irc_ssaddr ip;
99  unsigned int count;
100  time_t last_attempt;
101  struct ip_entry *next;
102 };
103
104 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
105 static mp_pool_t *ip_entry_pool = NULL;
106 static int ip_entries_count = 0;
107
83  
84   /* conf_dns_callback()
85   *
# Line 117 | Line 92 | static int ip_entries_count = 0;
92   * if successful save hp in the conf item it was called with
93   */
94   static void
95 < conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
95 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
96   {
97 <  struct MaskItem *conf = vptr;
97 >  struct MaskItem *const conf = vptr;
98  
99    conf->dns_pending = 0;
100  
101 <  if (addr != NULL)
101 >  if (addr)
102      memcpy(&conf->addr, addr, sizeof(conf->addr));
103    else
104      conf->dns_failed = 1;
# Line 138 | Line 113 | conf_dns_callback(void *vptr, const stru
113   static void
114   conf_dns_lookup(struct MaskItem *conf)
115   {
116 <  if (!conf->dns_pending)
116 >  if (conf->dns_pending)
117 >    return;
118 >
119 >  conf->dns_pending = 1;
120 >
121 >  if (conf->aftype == AF_INET)
122 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
123 >  else
124 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
125 > }
126 >
127 > /* map_to_list()
128 > *
129 > * inputs       - ConfType conf
130 > * output       - pointer to dlink_list to use
131 > * side effects - none
132 > */
133 > static dlink_list *
134 > map_to_list(enum maskitem_type type)
135 > {
136 >  switch (type)
137    {
138 <    conf->dns_pending = 1;
139 <    gethost_byname(conf_dns_callback, conf, conf->host);
138 >    case CONF_OPER:
139 >      return &operator_items;
140 >      break;
141 >    case CONF_SERVER:
142 >      return &connect_items;
143 >      break;
144 >    default:
145 >      return NULL;
146    }
147   }
148  
149   struct MaskItem *
150   conf_make(enum maskitem_type type)
151   {
152 <  struct MaskItem *conf = MyMalloc(sizeof(*conf));
152 >  struct MaskItem *const conf = xcalloc(sizeof(*conf));
153    dlink_list *list = NULL;
154  
155    conf->type   = type;
# Line 163 | Line 164 | conf_make(enum maskitem_type type)
164   void
165   conf_free(struct MaskItem *conf)
166   {
167 <  dlink_node *ptr = NULL, *ptr_next = NULL;
167 >  dlink_node *node = NULL, *node_next = NULL;
168    dlink_list *list = NULL;
169  
170 <  if (conf->node.next)
171 <    if ((list = map_to_list(conf->type)))
171 <      dlinkDelete(&conf->node, list);
170 >  if ((list = map_to_list(conf->type)))
171 >    dlinkFindDelete(list, conf);
172  
173 <  MyFree(conf->name);
173 >  xfree(conf->name);
174  
175    if (conf->dns_pending)
176      delete_resolver_queries(conf);
177 <  if (conf->passwd != NULL)
177 >  if (conf->passwd)
178      memset(conf->passwd, 0, strlen(conf->passwd));
179 <  if (conf->spasswd != NULL)
179 >  if (conf->spasswd)
180      memset(conf->spasswd, 0, strlen(conf->spasswd));
181  
182    conf->class = NULL;
183  
184 <  MyFree(conf->passwd);
185 <  MyFree(conf->spasswd);
186 <  MyFree(conf->reason);
187 <  MyFree(conf->certfp);
188 <  MyFree(conf->user);
189 <  MyFree(conf->host);
190 < #ifdef HAVE_LIBCRYPTO
191 <  MyFree(conf->cipher_list);
184 >  xfree(conf->passwd);
185 >  xfree(conf->spasswd);
186 >  xfree(conf->reason);
187 >  xfree(conf->certfp);
188 >  xfree(conf->whois);
189 >  xfree(conf->user);
190 >  xfree(conf->host);
191 >  xfree(conf->cipher_list);
192  
193 <  if (conf->rsa_public_key)
194 <    RSA_free(conf->rsa_public_key);
195 < #endif
196 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
193 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
194    {
195 <    MyFree(ptr->data);
196 <    free_dlink_node(ptr);
195 >    xfree(node->data);
196 >    dlinkDelete(node, &conf->hub_list);
197 >    free_dlink_node(node);
198    }
199  
200 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
200 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
201    {
202 <    MyFree(ptr->data);
203 <    free_dlink_node(ptr);
202 >    xfree(node->data);
203 >    dlinkDelete(node, &conf->leaf_list);
204 >    free_dlink_node(node);
205    }
206  
207 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
209 <  {
210 <    struct exempt *exptr = ptr->data;
211 <
212 <    MyFree(exptr->name);
213 <    MyFree(exptr->user);
214 <    MyFree(exptr->host);
215 <    MyFree(exptr);
216 <  }
217 <
218 <  MyFree(conf);
219 < }
220 <
221 < /* check_client()
222 < *
223 < * inputs       - pointer to client
224 < * output       - 0 = Success
225 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
226 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
227 < *                I_LINE_FULL       (-3) = I-line is full
228 < *                TOO_MANY          (-4) = Too many connections from hostname
229 < *                BANNED_CLIENT     (-5) = K-lined
230 < * side effects - Ordinary client access check.
231 < *                Look for conf lines which have the same
232 < *                status as the flags passed.
233 < */
234 < int
235 < check_client(struct Client *source_p)
236 < {
237 <  int i;
238 <
239 <  if ((i = verify_access(source_p)))
240 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
241 <         source_p->name, source_p->sockhost);
242 <
243 <  switch (i)
244 <  {
245 <    case TOO_MANY:
246 <      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
247 <                           "Too many on IP for %s (%s).",
248 <                           get_client_name(source_p, SHOW_IP),
249 <                           source_p->sockhost);
250 <      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
251 <           get_client_name(source_p, SHOW_IP));
252 <      ++ServerStats.is_ref;
253 <      exit_client(source_p, &me, "No more connections allowed on that IP");
254 <      break;
255 <
256 <    case I_LINE_FULL:
257 <      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
258 <                           "auth{} block is full for %s (%s).",
259 <                           get_client_name(source_p, SHOW_IP),
260 <                           source_p->sockhost);
261 <      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
262 <           get_client_name(source_p, SHOW_IP));
263 <      ++ServerStats.is_ref;
264 <      exit_client(source_p, &me,
265 <                  "No more connections allowed in your connection class");
266 <      break;
267 <
268 <    case NOT_AUTHORIZED:
269 <      ++ServerStats.is_ref;
270 <      /* jdc - lists server name & port connections are on */
271 <      /*       a purely cosmetical change */
272 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
273 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
274 <                           get_client_name(source_p, SHOW_IP),
275 <                           source_p->sockhost,
276 <                           source_p->localClient->listener->name,
277 <                           source_p->localClient->listener->port);
278 <      ilog(LOG_TYPE_IRCD,
279 <           "Unauthorized client connection from %s on [%s/%u].",
280 <           get_client_name(source_p, SHOW_IP),
281 <           source_p->localClient->listener->name,
282 <           source_p->localClient->listener->port);
283 <
284 <      exit_client(source_p, &me, "You are not authorized to use this server");
285 <      break;
286 <
287 <   case BANNED_CLIENT:
288 <     exit_client(source_p, &me, "Banned");
289 <     ++ServerStats.is_ref;
290 <     break;
291 <
292 <   case 0:
293 <   default:
294 <     break;
295 <  }
296 <
297 <  return (i < 0 ? 0 : 1);
298 < }
299 <
300 < /* verify_access()
301 < *
302 < * inputs       - pointer to client to verify
303 < * output       - 0 if success -'ve if not
304 < * side effect  - find the first (best) I line to attach.
305 < */
306 < static int
307 < verify_access(struct Client *client_p)
308 < {
309 <  struct MaskItem *conf = NULL;
310 <  char non_ident[USERLEN + 1] = { '~', '\0' };
311 <
312 <  if (IsGotId(client_p))
313 <  {
314 <    conf = find_address_conf(client_p->host, client_p->username,
315 <                             &client_p->localClient->ip,
316 <                             client_p->localClient->aftype,
317 <                             client_p->localClient->passwd);
318 <  }
319 <  else
320 <  {
321 <    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
322 <    conf = find_address_conf(client_p->host,non_ident,
323 <                             &client_p->localClient->ip,
324 <                             client_p->localClient->aftype,
325 <                             client_p->localClient->passwd);
326 <  }
327 <
328 <  if (conf != NULL)
329 <  {
330 <    if (IsConfClient(conf))
331 <    {
332 <      if (IsConfRedir(conf))
333 <      {
334 <        sendto_one(client_p, form_str(RPL_REDIR),
335 <                   me.name, client_p->name,
336 <                   conf->name ? conf->name : "",
337 <                   conf->port);
338 <        return NOT_AUTHORIZED;
339 <      }
340 <
341 <      if (IsConfDoIdentd(conf))
342 <        SetNeedId(client_p);
343 <
344 <      /* Thanks for spoof idea amm */
345 <      if (IsConfDoSpoofIp(conf))
346 <      {
347 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
348 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
349 <                               "%s spoofing: %s as %s",
350 <                               client_p->name, client_p->host, conf->name);
351 <        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
352 <        AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
353 <      }
354 <
355 <      return attach_iline(client_p, conf);
356 <    }
357 <    else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
358 <    {
359 <      if (IsConfGline(conf))
360 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
361 <                   client_p->name);
362 <      sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
363 <                 me.name, client_p->name, conf->reason);
364 <      return BANNED_CLIENT;
365 <    }
366 <  }
367 <
368 <  return NOT_AUTHORIZED;
207 >  xfree(conf);
208   }
209  
210   /* attach_iline()
211   *
212 < * inputs       - client pointer
213 < *              - conf pointer
214 < * output       -
215 < * side effects - do actual attach
212 > * inputs       - client pointer
213 > *              - conf pointer
214 > * output       -
215 > * side effects - do actual attach
216   */
217   static int
218   attach_iline(struct Client *client_p, struct MaskItem *conf)
219   {
220 <  struct ClassItem *class = NULL;
220 >  const struct ClassItem *const class = conf->class;
221    struct ip_entry *ip_found;
222    int a_limit_reached = 0;
223 <  unsigned int local = 0, global = 0, ident = 0;
385 <
386 <  assert(conf->class);
223 >  unsigned int local = 0, global = 0;
224  
225 <  ip_found = find_or_add_ip(&client_p->localClient->ip);
225 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
226    ip_found->count++;
227 <  SetIpHash(client_p);
227 >  AddFlag(client_p, FLAGS_IPHASH);
228  
229 <  class = conf->class;
393 <
394 <  count_user_host(client_p->username, client_p->host,
395 <                  &global, &local, &ident);
229 >  userhost_count(client_p->sockhost, &global, &local);
230  
231    /* XXX blah. go down checking the various silly limits
232     * setting a_limit_reached if any limit is reached.
233     * - Dianora
234     */
235 <  if (class->max_total != 0 && class->ref_count >= class->max_total)
402 <    a_limit_reached = 1;
403 <  else if (class->max_perip != 0 && ip_found->count > class->max_perip)
235 >  if (class->max_total && class->ref_count >= class->max_total)
236      a_limit_reached = 1;
237 <  else if (class->max_local != 0 && local >= class->max_local)
237 >  else if (class->max_perip && ip_found->count > class->max_perip)
238      a_limit_reached = 1;
239 <  else if (class->max_global != 0 && global >= class->max_global)
239 >  else if (class->max_local && local >= class->max_local) /* XXX: redundant */
240      a_limit_reached = 1;
241 <  else if (class->max_ident != 0 && ident >= class->max_ident &&
410 <           client_p->username[0] != '~')
241 >  else if (class->max_global && global >= class->max_global)
242      a_limit_reached = 1;
243  
244    if (a_limit_reached)
# Line 415 | Line 246 | attach_iline(struct Client *client_p, st
246      if (!IsConfExemptLimits(conf))
247        return TOO_MANY;   /* Already at maximum allowed */
248  
249 <    sendto_one(client_p,
250 <               ":%s NOTICE %s :*** Your connection class is full, "
420 <               "but you have exceed_limit = yes;", me.name, client_p->name);
249 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
250 >                      "but you have exceed_limit = yes;");
251    }
252  
253    return attach_conf(client_p, conf);
254   }
255  
256 < /* init_ip_hash_table()
427 < *
428 < * inputs               - NONE
429 < * output               - NONE
430 < * side effects         - allocate memory for ip_entry(s)
431 < *                      - clear the ip hash table
432 < */
433 < void
434 < init_ip_hash_table(void)
435 < {
436 <  ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
437 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
438 < }
439 <
440 < /* find_or_add_ip()
441 < *
442 < * inputs       - pointer to struct irc_ssaddr
443 < * output       - pointer to a struct ip_entry
444 < * side effects -
256 > /* verify_access()
257   *
258 < * If the ip # was not found, a new struct ip_entry is created, and the ip
259 < * count set to 0.
258 > * inputs       - pointer to client to verify
259 > * output       - 0 if success -'ve if not
260 > * side effect  - find the first (best) I line to attach.
261   */
262 < static struct ip_entry *
263 < find_or_add_ip(struct irc_ssaddr *ip_in)
262 > static int
263 > verify_access(struct Client *client_p)
264   {
265 <  struct ip_entry *ptr, *newptr;
453 <  int hash_index = hash_ip(ip_in), res;
454 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
455 < #ifdef IPV6
456 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
457 < #endif
265 >  struct MaskItem *conf = NULL;
266  
267 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
267 >  if (HasFlag(client_p, FLAGS_GOTID))
268    {
269 < #ifdef IPV6
270 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
271 <      continue;
272 <    if (ip_in->ss.ss_family == AF_INET6)
465 <    {
466 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
467 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
468 <    }
469 <    else
470 < #endif
471 <    {
472 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
473 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
474 <    }
475 <    if (res == 0)
476 <    {
477 <      /* Found entry already in hash, return it. */
478 <      return ptr;
479 <    }
269 >    conf = find_address_conf(client_p->host, client_p->username,
270 >                             &client_p->connection->ip,
271 >                             client_p->connection->aftype,
272 >                             client_p->connection->password);
273    }
274 +  else
275 +  {
276 +    char non_ident[USERLEN + 1] = "~";
277  
278 <  if (ip_entries_count >= 2 * hard_fdlimit)
279 <    garbage_collect_ip_entries();
280 <
281 <  newptr = mp_pool_get(ip_entry_pool);
282 <  memset(newptr, 0, sizeof(*newptr));
283 <  ip_entries_count++;
488 <  memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
489 <
490 <  newptr->next = ip_hash_table[hash_index];
491 <  ip_hash_table[hash_index] = newptr;
278 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
279 >    conf = find_address_conf(client_p->host, non_ident,
280 >                             &client_p->connection->ip,
281 >                             client_p->connection->aftype,
282 >                             client_p->connection->password);
283 >  }
284  
285 <  return newptr;
286 < }
285 >  if (!conf)
286 >    return NOT_AUTHORIZED;
287  
288 < /* remove_one_ip()
497 < *
498 < * inputs        - unsigned long IP address value
499 < * output        - NONE
500 < * side effects  - The ip address given, is looked up in ip hash table
501 < *                 and number of ip#'s for that ip decremented.
502 < *                 If ip # count reaches 0 and has expired,
503 < *                 the struct ip_entry is returned to the ip_entry_heap
504 < */
505 < void
506 < remove_one_ip(struct irc_ssaddr *ip_in)
507 < {
508 <  struct ip_entry *ptr;
509 <  struct ip_entry *last_ptr = NULL;
510 <  int hash_index = hash_ip(ip_in), res;
511 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
512 < #ifdef IPV6
513 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
514 < #endif
288 >  assert(IsConfClient(conf) || IsConfKill(conf));
289  
290 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
290 >  if (IsConfClient(conf))
291    {
292 < #ifdef IPV6
519 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
520 <      continue;
521 <    if (ip_in->ss.ss_family == AF_INET6)
292 >    if (IsConfRedir(conf))
293      {
294 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
295 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
294 >      sendto_one_numeric(client_p, &me, RPL_REDIR,
295 >                         conf->name ? conf->name : "",
296 >                         conf->port);
297 >      return NOT_AUTHORIZED;
298      }
299 <    else
300 < #endif
528 <    {
529 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
530 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
531 <    }
532 <    if (res)
533 <      continue;
534 <    if (ptr->count > 0)
535 <      ptr->count--;
536 <    if (ptr->count == 0 &&
537 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
299 >
300 >    if (IsConfDoSpoofIp(conf))
301      {
302 <      if (last_ptr != NULL)
303 <        last_ptr->next = ptr->next;
304 <      else
542 <        ip_hash_table[hash_index] = ptr->next;
302 >      if (IsConfSpoofNotice(conf))
303 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
304 >                             client_p->name, client_p->host, conf->name);
305  
306 <      mp_pool_release(ptr);
545 <      ip_entries_count--;
546 <      return;
306 >      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
307      }
548    last_ptr = ptr;
549  }
550 }
551
552 /* hash_ip()
553 *
554 * input        - pointer to an irc_inaddr
555 * output       - integer value used as index into hash table
556 * side effects - hopefully, none
557 */
558 static int
559 hash_ip(struct irc_ssaddr *addr)
560 {
561  if (addr->ss.ss_family == AF_INET)
562  {
563    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
564    int hash;
565    uint32_t ip;
308  
309 <    ip   = ntohl(v4->sin_addr.s_addr);
568 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
569 <    return hash;
309 >    return attach_iline(client_p, conf);
310    }
311 < #ifdef IPV6
312 <  else
313 <  {
574 <    int hash;
575 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
576 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
577 <
578 <    hash  = ip[0] ^ ip[3];
579 <    hash ^= hash >> 16;  
580 <    hash ^= hash >> 8;  
581 <    hash  = hash & (IP_HASH_SIZE - 1);
582 <    return hash;
583 <  }
584 < #else
585 <  return 0;
586 < #endif
311 >
312 >  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
313 >  return BANNED_CLIENT;
314   }
315  
316 < /* count_ip_hash()
590 < *
591 < * inputs        - pointer to counter of number of ips hashed
592 < *               - pointer to memory used for ip hash
593 < * output        - returned via pointers input
594 < * side effects  - NONE
316 > /* check_client()
317   *
318 < * number of hashed ip #'s is counted up, plus the amount of memory
319 < * used in the hash.
318 > * inputs       - pointer to client
319 > * output       - 0 = Success
320 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
321 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
322 > *                I_LINE_FULL       (-3) = I-line is full
323 > *                TOO_MANY          (-4) = Too many connections from hostname
324 > *                BANNED_CLIENT     (-5) = K-lined
325 > * side effects - Ordinary client access check.
326 > *                Look for conf lines which have the same
327 > *                status as the flags passed.
328   */
329 < void
330 < count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
329 > int
330 > check_client(struct Client *source_p)
331   {
602  struct ip_entry *ptr;
332    int i;
333  
334 <  *number_ips_stored = 0;
335 <  *mem_ips_stored    = 0;
334 >  if ((i = verify_access(source_p)))
335 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
336 >         source_p->name, source_p->sockhost);
337  
338 <  for (i = 0; i < IP_HASH_SIZE; i++)
338 >  switch (i)
339    {
340 <    for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
341 <    {
342 <      *number_ips_stored += 1;
343 <      *mem_ips_stored += sizeof(struct ip_entry);
344 <    }
345 <  }
346 < }
340 >    case TOO_MANY:
341 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
342 >                           "Too many on IP for %s (%s).",
343 >                           client_get_name(source_p, SHOW_IP),
344 >                           source_p->sockhost);
345 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
346 >           client_get_name(source_p, SHOW_IP));
347 >      ++ServerStats.is_ref;
348 >      exit_client(source_p, "No more connections allowed on that IP");
349 >      break;
350  
351 < /* garbage_collect_ip_entries()
352 < *
353 < * input        - NONE
354 < * output       - NONE
355 < * side effects - free up all ip entries with no connections
356 < */
357 < static void
358 < garbage_collect_ip_entries(void)
359 < {
360 <  struct ip_entry *ptr;
628 <  struct ip_entry *last_ptr;
629 <  struct ip_entry *next_ptr;
630 <  int i;
351 >    case I_LINE_FULL:
352 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
353 >                           "auth {} block is full for %s (%s).",
354 >                           client_get_name(source_p, SHOW_IP),
355 >                           source_p->sockhost);
356 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
357 >           client_get_name(source_p, SHOW_IP));
358 >      ++ServerStats.is_ref;
359 >      exit_client(source_p, "No more connections allowed in your connection class");
360 >      break;
361  
362 <  for (i = 0; i < IP_HASH_SIZE; i++)
363 <  {
364 <    last_ptr = NULL;
362 >    case NOT_AUTHORIZED:
363 >      /* jdc - lists server name & port connections are on */
364 >      /*       a purely cosmetical change */
365 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
366 >                           "Unauthorized client connection from %s on [%s/%u].",
367 >                           client_get_name(source_p, SHOW_IP),
368 >                           source_p->connection->listener->name,
369 >                           source_p->connection->listener->port);
370 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
371 >           client_get_name(source_p, SHOW_IP),
372 >           source_p->connection->listener->name,
373 >           source_p->connection->listener->port);
374  
375 <    for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
376 <    {
377 <      next_ptr = ptr->next;
375 >      ++ServerStats.is_ref;
376 >      exit_client(source_p, "You are not authorized to use this server");
377 >      break;
378  
379 <      if (ptr->count == 0 &&
380 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
381 <      {
382 <        if (last_ptr != NULL)
383 <          last_ptr->next = ptr->next;
384 <        else
385 <          ip_hash_table[i] = ptr->next;
386 <        mp_pool_release(ptr);
648 <        ip_entries_count--;
649 <      }
650 <      else
651 <        last_ptr = ptr;
652 <    }
379 >    case BANNED_CLIENT:
380 >      ++ServerStats.is_ref;
381 >      exit_client(source_p, "Banned");
382 >      break;
383 >
384 >    case 0:
385 >    default:
386 >      break;
387    }
388 +
389 +  return !(i < 0);
390   }
391  
392   /* detach_conf()
# Line 664 | Line 400 | garbage_collect_ip_entries(void)
400   void
401   detach_conf(struct Client *client_p, enum maskitem_type type)
402   {
403 <  dlink_node *ptr = NULL, *next_ptr = NULL;
403 >  dlink_node *node = NULL, *node_next = NULL;
404  
405 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
405 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
406    {
407 <    struct MaskItem *conf = ptr->data;
407 >    struct MaskItem *conf = node->data;
408  
409      assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
410      assert(conf->ref_count > 0);
# Line 677 | Line 413 | detach_conf(struct Client *client_p, enu
413      if (!(conf->type & type))
414        continue;
415  
416 <    dlinkDelete(ptr, &client_p->localClient->confs);
417 <    free_dlink_node(ptr);
416 >    dlinkDelete(node, &client_p->connection->confs);
417 >    free_dlink_node(node);
418  
419      if (conf->type == CONF_CLIENT)
420 <      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
420 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
421  
422      if (--conf->class->ref_count == 0 && conf->class->active == 0)
423      {
# Line 707 | Line 443 | detach_conf(struct Client *client_p, enu
443   int
444   attach_conf(struct Client *client_p, struct MaskItem *conf)
445   {
446 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
446 >  if (dlinkFind(&client_p->connection->confs, conf))
447      return 1;
448  
449    if (conf->type == CONF_CLIENT)
450      if (cidr_limit_reached(IsConfExemptLimits(conf),
451 <                           &client_p->localClient->ip, conf->class))
451 >                           &client_p->connection->ip, conf->class))
452        return TOO_MANY;    /* Already at maximum allowed */
453  
454    conf->class->ref_count++;
455    conf->ref_count++;
456  
457 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
457 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
458  
459    return 0;
460   }
# Line 735 | Line 471 | int
471   attach_connect_block(struct Client *client_p, const char *name,
472                       const char *host)
473   {
474 <  dlink_node *ptr;
739 <  struct MaskItem *conf = NULL;
740 <
741 <  assert(client_p != NULL);
742 <  assert(host != NULL);
474 >  dlink_node *node = NULL;
475  
476 <  if (client_p == NULL || host == NULL)
745 <    return 0;
476 >  assert(host);
477  
478 <  DLINK_FOREACH(ptr, server_items.head)
478 >  DLINK_FOREACH(node, connect_items.head)
479    {
480 <    conf = ptr->data;
480 >    struct MaskItem *conf = node->data;
481  
482 <    if (match(conf->name, name) || match(conf->host, host))
482 >    if (irccmp(conf->name, name) ||
483 >        irccmp(conf->host, host))
484        continue;
485  
486      attach_conf(client_p, conf);
487 <    return -1;
487 >    return 1;
488    }
489  
490    return 0;
# Line 770 | Line 502 | attach_connect_block(struct Client *clie
502   struct MaskItem *
503   find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
504   {
505 <  dlink_node *ptr;
774 <  struct MaskItem* conf;
505 >  dlink_node *node = NULL;
506  
507 <  DLINK_FOREACH(ptr, list->head)
507 >  DLINK_FOREACH(node, list->head)
508    {
509 <    conf = ptr->data;
510 <    
509 >    struct MaskItem *conf = node->data;
510 >
511      if (conf->type == type)
512      {
513 <      if (conf->name && (irccmp(conf->name, name) == 0 ||
514 <                         !match(conf->name, name)))
784 <      return conf;
513 >      if (conf->name && !irccmp(conf->name, name))
514 >        return conf;
515      }
516    }
517  
518    return NULL;
519   }
520  
791 /* map_to_list()
792 *
793 * inputs       - ConfType conf
794 * output       - pointer to dlink_list to use
795 * side effects - none
796 */
797 static dlink_list *
798 map_to_list(enum maskitem_type type)
799 {
800  switch(type)
801  {
802  case CONF_XLINE:
803    return(&xconf_items);
804    break;
805  case CONF_ULINE:
806    return(&uconf_items);
807    break;
808  case CONF_NRESV:
809    return(&nresv_items);
810    break;
811  case CONF_CRESV:
812    return(&cresv_items);
813  case CONF_OPER:
814    return(&oconf_items);
815    break;
816  case CONF_SERVER:
817    return(&server_items);
818    break;
819  case CONF_SERVICE:
820    return(&service_items);
821    break;
822  case CONF_CLUSTER:
823    return(&cluster_items);
824    break;
825  default:
826    return NULL;
827  }
828 }
829
521   /* find_matching_name_conf()
522   *
523   * inputs       - type of link list to look in
# Line 838 | Line 529 | map_to_list(enum maskitem_type type)
529   * side effects - looks for a match on name field
530   */
531   struct MaskItem *
532 < find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
842 <                        const char *host, unsigned int flags)
532 > connect_find(const char *name, const char *host, int (*compare)(const char *, const char *))
533   {
534 <  dlink_node *ptr=NULL;
845 <  struct MaskItem *conf=NULL;
846 <  dlink_list *list_p = map_to_list(type);
534 >  dlink_node *node = NULL;
535  
536 <  switch (type)
536 >  DLINK_FOREACH(node, connect_items.head)
537    {
538 <  case CONF_SERVICE:
851 <    DLINK_FOREACH(ptr, list_p->head)
852 <    {
853 <      conf = ptr->data;
538 >    struct MaskItem *conf = node->data;
539  
540 <      if (EmptyString(conf->name))
541 <        continue;
542 <      if ((name != NULL) && !irccmp(name, conf->name))
543 <        return conf;
859 <    }
860 <    break;
861 <
862 <  case CONF_XLINE:
863 <  case CONF_ULINE:
864 <  case CONF_NRESV:
865 <  case CONF_CRESV:
866 <    DLINK_FOREACH(ptr, list_p->head)
867 <    {
868 <      conf = ptr->data;
869 <
870 <      if (EmptyString(conf->name))
871 <        continue;
872 <      if ((name != NULL) && !match(conf->name, name))
873 <      {
874 <        if ((user == NULL && (host == NULL)))
875 <          return conf;
876 <        if ((conf->flags & flags) != flags)
877 <          continue;
878 <        if (EmptyString(conf->user) || EmptyString(conf->host))
879 <          return conf;
880 <        if (!match(conf->user, user) && !match(conf->host, host))
881 <          return conf;
882 <      }
883 <    }
884 <      break;
885 <
886 <  case CONF_SERVER:
887 <    DLINK_FOREACH(ptr, list_p->head)
888 <    {
889 <      conf = ptr->data;
890 <
891 <      if ((name != NULL) && !match(name, conf->name))
892 <        return conf;
893 <      else if ((host != NULL) && !match(host, conf->host))
894 <        return conf;
895 <    }
896 <    break;
897 <  
898 <  default:
899 <    break;
540 >    if (name && !compare(name, conf->name))
541 >      return conf;
542 >    if (host && !compare(host, conf->host))
543 >      return conf;
544    }
545 +
546    return NULL;
547   }
548  
# Line 911 | Line 556 | find_matching_name_conf(enum maskitem_ty
556   * side effects - looks for an exact match on name field
557   */
558   struct MaskItem *
559 < find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
915 <                     const char *user, const char *host)
559 > operator_find(const struct Client *who, const char *name)
560   {
561 <  dlink_node *ptr = NULL;
918 <  struct MaskItem *conf;
919 <  dlink_list *list_p = map_to_list(type);
561 >  dlink_node *node = NULL;
562  
563 <  switch(type)
563 >  DLINK_FOREACH(node, operator_items.head)
564    {
565 <  case CONF_XLINE:
924 <  case CONF_ULINE:
925 <  case CONF_NRESV:
926 <  case CONF_CRESV:
927 <
928 <    DLINK_FOREACH(ptr, list_p->head)
929 <    {
930 <      conf = ptr->data;
931 <
932 <      if (EmptyString(conf->name))
933 <        continue;
934 <    
935 <      if (irccmp(conf->name, name) == 0)
936 <      {
937 <        if ((user == NULL && (host == NULL)))
938 <          return conf;
939 <        if (EmptyString(conf->user) || EmptyString(conf->host))
940 <          return conf;
941 <        if (!match(conf->user, user) && !match(conf->host, host))
942 <          return conf;
943 <      }
944 <    }
945 <    break;
565 >    struct MaskItem *conf = node->data;
566  
567 <  case CONF_OPER:
948 <    DLINK_FOREACH(ptr, list_p->head)
567 >    if (!irccmp(conf->name, name))
568      {
569 <      conf = ptr->data;
570 <
952 <      if (EmptyString(conf->name))
953 <        continue;
569 >      if (!who)
570 >        return conf;
571  
572 <      if (!irccmp(conf->name, name))
572 >      if (!match(conf->user, who->username))
573        {
574 <        if (!who)
958 <          return conf;
959 <        if (EmptyString(conf->user) || EmptyString(conf->host))
960 <          return NULL;
961 <        if (!match(conf->user, who->username))
574 >        switch (conf->htype)
575          {
576 <          switch (conf->htype)
577 <          {
578 <            case HM_HOST:
579 <              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
576 >          case HM_HOST:
577 >            if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
578 >              if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
579 >                return conf;
580 >            break;
581 >          case HM_IPV4:
582 >            if (who->connection->aftype == AF_INET)
583 >              if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
584                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
585                    return conf;
586 <              break;
587 <            case HM_IPV4:
588 <              if (who->localClient->aftype == AF_INET)
589 <                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
590 <                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
591 <                    return conf;
592 <              break;
593 < #ifdef IPV6
594 <            case HM_IPV6:
978 <              if (who->localClient->aftype == AF_INET6)
979 <                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
980 <                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
981 <                    return conf;
982 <              break;
983 < #endif
984 <            default:
985 <              assert(0);
986 <          }
586 >            break;
587 >          case HM_IPV6:
588 >            if (who->connection->aftype == AF_INET6)
589 >              if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
590 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
591 >                  return conf;
592 >            break;
593 >          default:
594 >            assert(0);
595          }
596        }
597      }
990
991    break;
992
993  case CONF_SERVER:
994    DLINK_FOREACH(ptr, list_p->head)
995    {
996      conf = ptr->data;
997
998      if (EmptyString(conf->name))
999        continue;
1000    
1001      if (name == NULL)
1002      {
1003        if (EmptyString(conf->host))
1004          continue;
1005        if (irccmp(conf->host, host) == 0)
1006          return conf;
1007      }
1008      else if (irccmp(conf->name, name) == 0)
1009        return conf;
1010    }
1011
1012    break;
1013
1014  default:
1015    break;
598    }
599  
600    return NULL;
601   }
602  
1021 /* rehash()
1022 *
1023 * Actual REHASH service routine. Called with sig == 0 if it has been called
1024 * as a result of an operator issuing this command, else assume it has been
1025 * called as a result of the server receiving a HUP signal.
1026 */
1027 int
1028 rehash(int sig)
1029 {
1030  if (sig != 0)
1031    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1032                         "Got signal SIGHUP, reloading ircd.conf file");
1033
1034  restart_resolver();
1035
1036  /* don't close listeners until we know we can go ahead with the rehash */
1037
1038  /* Check to see if we magically got(or lost) IPv6 support */
1039  check_can_use_v6();
1040
1041  read_conf_files(0);
1042
1043  if (ServerInfo.description != NULL)
1044    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1045
1046  load_conf_modules();
1047
1048  rehashed_klines = 1;
1049
1050  return 0;
1051 }
1052
603   /* set_default_conf()
604   *
605   * inputs       - NONE
# Line 1067 | Line 617 | set_default_conf(void)
617     */
618    assert(class_default == class_get_list()->tail->data);
619  
620 < #ifdef HAVE_LIBCRYPTO
621 <  ServerInfo.rsa_private_key = NULL;
1072 <  ServerInfo.rsa_private_key_file = NULL;
1073 < #endif
620 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
621 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
622  
623 <  /* ServerInfo.name is not rehashable */
624 <  /* ServerInfo.name = ServerInfo.name; */
625 <  ServerInfo.description = NULL;
626 <  ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
627 <  ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
628 <
629 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
630 <  ServerInfo.specific_ipv4_vhost = 0;
631 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
632 <  ServerInfo.specific_ipv6_vhost = 0;
1085 <
1086 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
1087 <  ServerInfo.max_nick_length = 9;
1088 <  ServerInfo.max_topic_length = 80;
1089 <
1090 <  ServerInfo.hub = 0;
1091 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
1092 <  ServerInfo.dns_host.sin_port = 0;
1093 <  AdminInfo.name = NULL;
1094 <  AdminInfo.email = NULL;
1095 <  AdminInfo.description = NULL;
623 >  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
624 >  ConfigServerInfo.specific_ipv4_vhost = 0;
625 >  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
626 >  ConfigServerInfo.specific_ipv6_vhost = 0;
627 >
628 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
629 >  ConfigServerInfo.max_nick_length = 9;
630 >  ConfigServerInfo.max_topic_length = 80;
631 >  ConfigServerInfo.hub = 0;
632 >  ConfigServerInfo.libgeoip_database_options = 0;
633  
634    log_del_all();
635  
636 <  ConfigLoggingEntry.use_logging = 1;
636 >  ConfigLog.use_logging = 1;
637  
638    ConfigChannel.disable_fake_channels = 0;
639 <  ConfigChannel.knock_delay = 300;
639 >  ConfigChannel.invite_client_count = 10;
640 >  ConfigChannel.invite_client_time = 300;
641 >  ConfigChannel.invite_delay_channel = 5;
642 >  ConfigChannel.invite_expire_time = 1800;
643 >  ConfigChannel.knock_client_count = 1;
644 >  ConfigChannel.knock_client_time = 300;
645    ConfigChannel.knock_delay_channel = 60;
646 <  ConfigChannel.max_chans_per_user = 25;
647 <  ConfigChannel.max_chans_per_oper = 50;
648 <  ConfigChannel.max_bans = 25;
649 <  ConfigChannel.default_split_user_count = 0;
650 <  ConfigChannel.default_split_server_count = 0;
651 <  ConfigChannel.no_join_on_split = 0;
1110 <  ConfigChannel.no_create_on_split = 0;
646 >  ConfigChannel.max_channels = 25;
647 >  ConfigChannel.max_invites = 20;
648 >  ConfigChannel.max_bans = 100;
649 >  ConfigChannel.max_bans_large = 500;
650 >  ConfigChannel.default_join_flood_count = 18;
651 >  ConfigChannel.default_join_flood_time = 6;
652  
653    ConfigServerHide.flatten_links = 0;
654 <  ConfigServerHide.links_delay = 300;
654 >  ConfigServerHide.flatten_links_delay = 300;
655    ConfigServerHide.hidden = 0;
656    ConfigServerHide.hide_servers = 0;
657    ConfigServerHide.hide_services = 0;
# Line 1118 | Line 659 | set_default_conf(void)
659    ConfigServerHide.hide_server_ips = 0;
660    ConfigServerHide.disable_remote_commands = 0;
661  
662 <  
663 <  ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
664 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
665 <  ConfigFileEntry.cycle_on_host_change = 1;
666 <  ConfigFileEntry.glines = 0;
667 <  ConfigFileEntry.gline_time = 12 * 3600;
668 <  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
669 <  ConfigFileEntry.gline_min_cidr = 16;
670 <  ConfigFileEntry.gline_min_cidr6 = 48;
671 <  ConfigFileEntry.invisible_on_connect = 1;
672 <  ConfigFileEntry.tkline_expire_notices = 1;
673 <  ConfigFileEntry.hide_spoof_ips = 1;
674 <  ConfigFileEntry.ignore_bogus_ts = 0;
675 <  ConfigFileEntry.disable_auth = 0;
676 <  ConfigFileEntry.kill_chase_time_limit = 90;
677 <  ConfigFileEntry.default_floodcount = 8;
678 <  ConfigFileEntry.failed_oper_notice = 1;
679 <  ConfigFileEntry.dots_in_ident = 0;
680 <  ConfigFileEntry.min_nonwildcard = 4;
681 <  ConfigFileEntry.min_nonwildcard_simple = 3;
682 <  ConfigFileEntry.max_accept = 20;
683 <  ConfigFileEntry.anti_nick_flood = 0;
684 <  ConfigFileEntry.max_nick_time = 20;
685 <  ConfigFileEntry.max_nick_changes = 5;
686 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
687 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
688 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
689 <  ConfigFileEntry.warn_no_nline = 1;
690 <  ConfigFileEntry.stats_o_oper_only = 0;
691 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
692 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
693 <  ConfigFileEntry.stats_P_oper_only = 0;
694 <  ConfigFileEntry.stats_u_oper_only = 0;
695 <  ConfigFileEntry.caller_id_wait = 60;
696 <  ConfigFileEntry.opers_bypass_callerid = 0;
697 <  ConfigFileEntry.pace_wait = 10;
698 <  ConfigFileEntry.pace_wait_simple = 1;
699 <  ConfigFileEntry.short_motd = 0;
700 <  ConfigFileEntry.ping_cookie = 0;
701 <  ConfigFileEntry.no_oper_flood = 0;
702 <  ConfigFileEntry.true_no_oper_flood = 0;
703 <  ConfigFileEntry.oper_pass_resv = 1;
704 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
705 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
706 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
707 <    UMODE_OPERWALL | UMODE_WALLOP;
708 <  ConfigFileEntry.use_egd = 0;
709 <  ConfigFileEntry.egdpool_path = NULL;
710 <  ConfigFileEntry.throttle_time = 10;
662 >  ConfigGeneral.away_count = 2;
663 >  ConfigGeneral.away_time = 10;
664 >  ConfigGeneral.max_watch = 50;
665 >  ConfigGeneral.whowas_history_length = 15000;
666 >  ConfigGeneral.cycle_on_host_change = 1;
667 >  ConfigGeneral.dline_min_cidr = 16;
668 >  ConfigGeneral.dline_min_cidr6 = 48;
669 >  ConfigGeneral.kline_min_cidr = 16;
670 >  ConfigGeneral.kline_min_cidr6 = 48;
671 >  ConfigGeneral.invisible_on_connect = 1;
672 >  ConfigGeneral.tkline_expire_notices = 1;
673 >  ConfigGeneral.ignore_bogus_ts = 0;
674 >  ConfigGeneral.disable_auth = 0;
675 >  ConfigGeneral.kill_chase_time_limit = 90;
676 >  ConfigGeneral.default_floodcount = 8;
677 >  ConfigGeneral.default_floodtime = 1;
678 >  ConfigGeneral.failed_oper_notice = 1;
679 >  ConfigGeneral.dots_in_ident = 0;
680 >  ConfigGeneral.min_nonwildcard = 4;
681 >  ConfigGeneral.min_nonwildcard_simple = 3;
682 >  ConfigGeneral.max_accept = 50;
683 >  ConfigGeneral.anti_nick_flood = 0;
684 >  ConfigGeneral.max_nick_time = 20;
685 >  ConfigGeneral.max_nick_changes = 5;
686 >  ConfigGeneral.anti_spam_exit_message_time = 0;
687 >  ConfigGeneral.ts_warn_delta = 30;
688 >  ConfigGeneral.ts_max_delta = 600;
689 >  ConfigGeneral.warn_no_connect_block = 1;
690 >  ConfigGeneral.stats_e_disabled = 0;
691 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
692 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
693 >  ConfigGeneral.stats_o_oper_only = 1;
694 >  ConfigGeneral.stats_m_oper_only = 1;
695 >  ConfigGeneral.stats_P_oper_only = 0;
696 >  ConfigGeneral.stats_u_oper_only = 0;
697 >  ConfigGeneral.caller_id_wait = 60;
698 >  ConfigGeneral.opers_bypass_callerid = 1;
699 >  ConfigGeneral.pace_wait = 10;
700 >  ConfigGeneral.pace_wait_simple = 1;
701 >  ConfigGeneral.short_motd = 0;
702 >  ConfigGeneral.ping_cookie = 0;
703 >  ConfigGeneral.no_oper_flood = 0;
704 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
705 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
706 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
707 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
708 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
709 >  ConfigGeneral.throttle_count = 1;
710 >  ConfigGeneral.throttle_time = 1;
711   }
712  
713   static void
714   validate_conf(void)
715   {
716 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
717 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1177 <
1178 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1179 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1180 <
1181 <  if (ServerInfo.network_name == NULL)
1182 <    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1183 <
1184 <  if (ServerInfo.network_desc == NULL)
1185 <    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
716 >  if (EmptyString(ConfigServerInfo.network_name))
717 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
718  
719 <  if (ConfigFileEntry.service_name == NULL)
720 <    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1189 <
1190 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
719 >  if (EmptyString(ConfigServerInfo.network_desc))
720 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
721   }
722  
723 < /* read_conf()
723 > /* read_conf()
724   *
725   * inputs       - file descriptor pointing to config file to use
726   * output       - None
# Line 1199 | Line 729 | validate_conf(void)
729   static void
730   read_conf(FILE *file)
731   {
732 <  lineno = 0;
732 >  lineno = 1;
733  
734 <  set_default_conf(); /* Set default values prior to conf parsing */
734 >  set_default_conf();  /* Set default values prior to conf parsing */
735    conf_parser_ctx.pass = 1;
736 <  yyparse();          /* pick up the classes first */
736 >  yyparse();  /* Pick up the classes first */
737  
738    rewind(file);
739  
740    conf_parser_ctx.pass = 2;
741 <  yyparse();          /* Load the values from the conf */
742 <  validate_conf();    /* Check to make sure some values are still okay. */
743 <                      /* Some global values are also loaded here. */
744 <  class_delete_marked();      /* Make sure classes are valid */
741 >  yyparse();  /* Load the values from the conf */
742 >  validate_conf();  /* Check to make sure some values are still okay. */
743 >                    /* Some global values are also loaded here. */
744 >  whowas_trim();  /* Attempt to trim whowas list if necessary */
745 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
746 > }
747 >
748 > /* conf_rehash()
749 > *
750 > * Actual REHASH service routine. Called with sig == 0 if it has been called
751 > * as a result of an operator issuing this command, else assume it has been
752 > * called as a result of the server receiving a HUP signal.
753 > */
754 > void
755 > conf_rehash(int sig)
756 > {
757 >  if (sig)
758 >  {
759 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
760 >                         "Got signal SIGHUP, reloading configuration file(s)");
761 >    ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)");
762 >  }
763 >
764 >  restart_resolver();
765 >
766 >  /* don't close listeners until we know we can go ahead with the rehash */
767 >
768 >  read_conf_files(0);
769 >
770 >  load_conf_modules();
771 >  check_conf_klines();
772   }
773  
774   /* lookup_confhost()
# Line 1224 | Line 781 | lookup_confhost(struct MaskItem *conf)
781   {
782    struct addrinfo hints, *res;
783  
784 <  /* Do name lookup now on hostnames given and store the
784 >  /*
785 >   * Do name lookup now on hostnames given and store the
786     * ip numbers in conf structure.
787     */
788    memset(&hints, 0, sizeof(hints));
# Line 1241 | Line 799 | lookup_confhost(struct MaskItem *conf)
799      return;
800    }
801  
802 <  assert(res != NULL);
802 >  assert(res);
803  
804    memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
805    conf->addr.ss_len = res->ai_addrlen;
# Line 1260 | Line 818 | lookup_confhost(struct MaskItem *conf)
818   int
819   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
820   {
821 <  struct ip_entry *ip_found;
822 <  struct MaskItem *conf = find_dline_conf(addr, aftype);
1265 <
1266 <  /* DLINE exempt also gets you out of static limits/pacing... */
1267 <  if (conf && (conf->type == CONF_EXEMPT))
1268 <    return 0;
821 >  struct ip_entry *ip_found = NULL;
822 >  const struct MaskItem *conf = find_dline_conf(addr, aftype);
823  
824 <  if (conf != NULL)
824 >  if (conf)
825 >  {
826 >    /* DLINE exempt also gets you out of static limits/pacing... */
827 >    if (conf->type == CONF_EXEMPT)
828 >      return 0;
829      return BANNED_CLIENT;
830 +  }
831  
832 <  ip_found = find_or_add_ip(addr);
832 >  ip_found = ipcache_find_or_add_address(addr);
833  
834 <  if ((CurrentTime - ip_found->last_attempt) <
1276 <      ConfigFileEntry.throttle_time)
834 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
835    {
836 <    ip_found->last_attempt = CurrentTime;
837 <    return TOO_FAST;
836 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
837 >      return TOO_FAST;
838 >
839 >    ++ip_found->connection_count;
840    }
841 +  else
842 +    ip_found->connection_count = 1;
843  
844    ip_found->last_attempt = CurrentTime;
845    return 0;
# Line 1291 | Line 853 | conf_connect_allowed(struct irc_ssaddr *
853   *                This is an event started off in ircd.c
854   */
855   void
856 < cleanup_tklines(void *notused)
856 > cleanup_tklines(void *unused)
857   {
858    hostmask_expire_temporary();
859 <  expire_tklines(&xconf_items);
860 <  expire_tklines(&nresv_items);
1299 <  expire_tklines(&cresv_items);
1300 < }
1301 <
1302 < /* expire_tklines()
1303 < *
1304 < * inputs       - tkline list pointer
1305 < * output       - NONE
1306 < * side effects - expire tklines
1307 < */
1308 < static void
1309 < expire_tklines(dlink_list *tklist)
1310 < {
1311 <  dlink_node *ptr;
1312 <  dlink_node *next_ptr;
1313 <  struct MaskItem *conf;
1314 <
1315 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1316 <  {
1317 <    conf = ptr->data;
1318 <
1319 <    if (!conf->until || conf->until > CurrentTime)
1320 <      continue;
1321 <
1322 <    if (conf->type == CONF_XLINE)
1323 <    {
1324 <      if (ConfigFileEntry.tkline_expire_notices)
1325 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1326 <                               "Temporary X-line for [%s] expired", conf->name);
1327 <      conf_free(conf);
1328 <    }
1329 <    else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1330 <    {
1331 <      if (ConfigFileEntry.tkline_expire_notices)
1332 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1333 <                               "Temporary RESV for [%s] expired", conf->name);
1334 <      conf_free(conf);
1335 <    }
1336 <  }
859 >  gecos_expire();
860 >  resv_expire();
861   }
862  
863   /* oper_privs_as_string()
# Line 1342 | Line 866 | expire_tklines(dlink_list *tklist)
866   * output        - pointer to static string showing oper privs
867   * side effects  - return as string, the oper privs as derived from port
868   */
869 < static const struct oper_privs
869 > static const struct oper_flags
870   {
871    const unsigned int flag;
872    const unsigned char c;
873 < } flag_list[] = {
873 > } flag_table[] = {
874    { OPER_FLAG_ADMIN,          'A' },
875 <  { OPER_FLAG_REMOTEBAN,      'B' },
876 <  { OPER_FLAG_DIE,            'D' },
877 <  { OPER_FLAG_GLINE,          'G' },
878 <  { OPER_FLAG_REHASH,         'H' },
879 <  { OPER_FLAG_K,              'K' },
880 <  { OPER_FLAG_OPERWALL,       'L' },
881 <  { OPER_FLAG_KILL,           'N' },
882 <  { OPER_FLAG_KILL_REMOTE,    'O' },
883 <  { OPER_FLAG_CONNECT,        'P' },
884 <  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
885 <  { OPER_FLAG_SQUIT,          'R' },
886 <  { OPER_FLAG_SQUIT_REMOTE,   'S' },
887 <  { OPER_FLAG_UNKLINE,        'U' },
888 <  { OPER_FLAG_X,              'X' },
875 >  { OPER_FLAG_CLOSE,          'B' },
876 >  { OPER_FLAG_CONNECT,        'C' },
877 >  { OPER_FLAG_CONNECT_REMOTE, 'D' },
878 >  { OPER_FLAG_DIE,            'E' },
879 >  { OPER_FLAG_DLINE,          'F' },
880 >  { OPER_FLAG_GLOBOPS,        'G' },
881 >  { OPER_FLAG_JOIN_RESV,      'H' },
882 >  { OPER_FLAG_KILL,           'I' },
883 >  { OPER_FLAG_KILL_REMOTE,    'J' },
884 >  { OPER_FLAG_KLINE,          'K' },
885 >  { OPER_FLAG_LOCOPS,         'L' },
886 >  { OPER_FLAG_MODULE,         'M' },
887 >  { OPER_FLAG_NICK_RESV,      'N' },
888 >  { OPER_FLAG_OPME,           'O' },
889 >  { OPER_FLAG_REHASH,         'P' },
890 >  { OPER_FLAG_REMOTEBAN,      'Q' },
891 >  { OPER_FLAG_RESTART,        'R' },
892 >  { OPER_FLAG_RESV,           'S' },
893 >  { OPER_FLAG_SET,            'T' },
894 >  { OPER_FLAG_SQUIT,          'U' },
895 >  { OPER_FLAG_SQUIT_REMOTE,   'V' },
896 >  { OPER_FLAG_UNDLINE,        'W' },
897 >  { OPER_FLAG_UNKLINE,        'X' },
898 >  { OPER_FLAG_UNRESV,         'Y' },
899 >  { OPER_FLAG_UNXLINE,        'Z' },
900 >  { OPER_FLAG_WALLOPS,        'a' },
901 >  { OPER_FLAG_XLINE,          'b' },
902    { 0, '\0' }
903   };
904  
905 < char *
906 < oper_privs_as_string(const unsigned int port)
905 > const char *
906 > oper_privs_as_string(const unsigned int flags)
907   {
908 <  static char privs_out[16];
909 <  char *privs_ptr = privs_out;
1373 <  const struct oper_privs *opriv = flag_list;
908 >  static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
909 >  char *p = buf;
910  
911 <  for (; opriv->flag; ++opriv)
912 <  {
913 <    if (port & opriv->flag)
914 <      *privs_ptr++ = opriv->c;
915 <    else
916 <      *privs_ptr++ = ToLower(opriv->c);
1381 <  }
911 >  for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
912 >    if (flags & tab->flag)
913 >      *p++ = tab->c;
914 >
915 >  if (p == buf)
916 >    *p++ = '0';
917  
918 <  *privs_ptr = '\0';
918 >  *p = '\0';
919  
920 <  return privs_out;
920 >  return buf;
921   }
922  
923   /*
924 < * Input: A client to find the active oper{} name for.
924 > * Input: A client to find the active operator {} name for.
925   * Output: The nick!user@host{oper} of the oper.
926   *         "oper" is server name for remote opers
927   * Side effects: None.
# Line 1394 | Line 929 | oper_privs_as_string(const unsigned int
929   const char *
930   get_oper_name(const struct Client *client_p)
931   {
932 <  dlink_node *cnode = NULL;
933 <  /* +5 for !,@,{,} and null */
934 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
932 >  static char buffer[IRCD_BUFSIZE];
933 >
934 >  if (IsServer(client_p))
935 >    return client_p->name;
936  
937    if (MyConnect(client_p))
938    {
939 <    if ((cnode = client_p->localClient->confs.head))
939 >    const dlink_node *const node = client_p->connection->confs.head;
940 >
941 >    if (node)
942      {
943 <      struct MaskItem *conf = cnode->data;
943 >      const struct MaskItem *const conf = node->data;
944  
945 <      if (IsConfOperator(conf))
945 >      if (conf->type == CONF_OPER)
946        {
947          snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
948                   client_p->username, client_p->host, conf->name);
# Line 1412 | Line 950 | get_oper_name(const struct Client *clien
950        }
951      }
952  
953 <    /* Probably should assert here for now. If there is an oper out there
954 <     * with no oper{} conf attached, it would be good for us to know...
953 >    /*
954 >     * Probably should assert here for now. If there is an oper out there
955 >     * with no operator {} conf attached, it would be good for us to know...
956       */
957 <    assert(0); /* Oper without oper conf! */
957 >    assert(0);  /* Oper without oper conf! */
958    }
959  
960    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
# Line 1423 | Line 962 | get_oper_name(const struct Client *clien
962    return buffer;
963   }
964  
965 + /* clear_out_old_conf()
966 + *
967 + * inputs       - none
968 + * output       - none
969 + * side effects - Clear out the old configuration
970 + */
971 + static void
972 + clear_out_old_conf(void)
973 + {
974 +  dlink_node *node = NULL, *node_next = NULL;
975 +  dlink_list *free_items [] = {
976 +    &connect_items, &operator_items, NULL
977 +  };
978 +
979 +  dlink_list ** iterator = free_items; /* C is dumb */
980 +
981 +  /* We only need to free anything allocated by yyparse() here.
982 +   * Resetting structs, etc, is taken care of by set_default_conf().
983 +   */
984 +
985 +  for (; *iterator; iterator++)
986 +  {
987 +    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
988 +    {
989 +      struct MaskItem *conf = node->data;
990 +
991 +      conf->active = 0;
992 +      dlinkDelete(&conf->node, *iterator);
993 +
994 +      if (!conf->ref_count)
995 +        conf_free(conf);
996 +    }
997 +  }
998 +
999 +  /*
1000 +   * Don't delete the class table, rather mark all entries for deletion.
1001 +   * The table is cleaned up by class_delete_marked. - avalon
1002 +   */
1003 +  class_mark_for_deletion();
1004 +
1005 +  clear_out_address_conf();
1006 +
1007 +  modules_conf_clear();  /* Clear modules {} items */
1008 +
1009 +  motd_clear();  /* Clear motd {} items and re-cache default motd */
1010 +
1011 +  cluster_clear();  /* Clear cluster {} items */
1012 +
1013 +  gecos_clear();  /* Clear gecos {} items */
1014 +
1015 +  resv_clear();  /* Clear resv {} items */
1016 +
1017 +  service_clear();  /* Clear service {} items */
1018 +
1019 +  shared_clear();  /* Clear shared {} items */
1020 +
1021 +  pseudo_clear();  /* Clear pseudo {} items */
1022 +
1023 + #ifdef HAVE_LIBGEOIP
1024 +  GeoIP_delete(GeoIPv4_ctx);
1025 +  GeoIPv4_ctx = NULL;
1026 +  GeoIP_delete(GeoIPv6_ctx);
1027 +  GeoIPv6_ctx = NULL;
1028 + #endif
1029 +
1030 +  /* Clean out ConfigServerInfo */
1031 +  xfree(ConfigServerInfo.description);
1032 +  ConfigServerInfo.description = NULL;
1033 +  xfree(ConfigServerInfo.network_name);
1034 +  ConfigServerInfo.network_name = NULL;
1035 +  xfree(ConfigServerInfo.network_desc);
1036 +  ConfigServerInfo.network_desc = NULL;
1037 +  xfree(ConfigServerInfo.libgeoip_ipv6_database_file);
1038 +  ConfigServerInfo.libgeoip_ipv6_database_file = NULL;
1039 +  xfree(ConfigServerInfo.libgeoip_ipv4_database_file);
1040 +  ConfigServerInfo.libgeoip_ipv4_database_file = NULL;
1041 +  xfree(ConfigServerInfo.rsa_private_key_file);
1042 +  ConfigServerInfo.rsa_private_key_file = NULL;
1043 +  xfree(ConfigServerInfo.ssl_certificate_file);
1044 +  ConfigServerInfo.ssl_certificate_file = NULL;
1045 +  xfree(ConfigServerInfo.ssl_dh_param_file);
1046 +  ConfigServerInfo.ssl_dh_param_file = NULL;
1047 +  xfree(ConfigServerInfo.ssl_dh_elliptic_curve);
1048 +  ConfigServerInfo.ssl_dh_elliptic_curve = NULL;
1049 +  xfree(ConfigServerInfo.ssl_cipher_list);
1050 +  ConfigServerInfo.ssl_cipher_list = NULL;
1051 +  xfree(ConfigServerInfo.ssl_message_digest_algorithm);
1052 +  ConfigServerInfo.ssl_message_digest_algorithm = NULL;
1053 +
1054 +  /* Clean out ConfigAdminInfo */
1055 +  xfree(ConfigAdminInfo.name);
1056 +  ConfigAdminInfo.name = NULL;
1057 +  xfree(ConfigAdminInfo.email);
1058 +  ConfigAdminInfo.email = NULL;
1059 +  xfree(ConfigAdminInfo.description);
1060 +  ConfigAdminInfo.description = NULL;
1061 +
1062 +  xfree(ConfigServerHide.flatten_links_file);
1063 +  ConfigServerHide.flatten_links_file = NULL;
1064 +
1065 +  /* Clean out listeners */
1066 +  listener_close_marked();
1067 + }
1068 +
1069 + static void
1070 + conf_handle_tls(int cold)
1071 + {
1072 +  if (!tls_new_cred())
1073 +  {
1074 +    if (cold)
1075 +    {
1076 +      ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1077 +      exit(EXIT_FAILURE);
1078 +    }
1079 +    else
1080 +    {
1081 +      /* Failed to load new settings/certs, old ones remain active */
1082 +      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
1083 +                           "Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this
1084 +    }
1085 +  }
1086 + }
1087 +
1088   /* read_conf_files()
1089   *
1090   * inputs       - cold start YES or NO
# Line 1432 | Line 1094 | get_oper_name(const struct Client *clien
1094   void
1095   read_conf_files(int cold)
1096   {
1097 <  const char *filename;
1098 <  char chanmodes[32];
1099 <  char chanlimit[32];
1097 >  const char *filename = NULL;
1098 >  char chanmodes[IRCD_BUFSIZE] = "";
1099 >  char chanlimit[IRCD_BUFSIZE] = "";
1100  
1101    conf_parser_ctx.boot = cold;
1102 <  filename = ConfigFileEntry.configfile;
1102 >  filename = ConfigGeneral.configfile;
1103  
1104    /* We need to know the initial filename for the yyerror() to report
1105       FIXME: The full path is in conffilenamebuf first time since we
1106 <             dont know anything else
1106 >             don't know anything else
1107  
1108 <     - Gozem 2002-07-21
1108 >     - Gozem 2002-07-21
1109    */
1110    strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1111  
# Line 1453 | Line 1115 | read_conf_files(int cold)
1115      {
1116        ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1117             filename, strerror(errno));
1118 <      exit(-1);
1118 >      exit(EXIT_FAILURE);
1119      }
1120      else
1121      {
1122 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1122 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1123                             "Unable to read configuration file '%s': %s",
1124                             filename, strerror(errno));
1125        return;
# Line 1471 | Line 1133 | read_conf_files(int cold)
1133    fclose(conf_parser_ctx.conf_file);
1134  
1135    log_reopen_all();
1136 +  conf_handle_tls(cold);
1137  
1138 <  add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1139 <  add_isupport("NETWORK", ServerInfo.network_name, -1);
1477 <
1478 <  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1479 <  add_isupport("MAXLIST", chanmodes, -1);
1480 <  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1481 <  add_isupport("CHANTYPES", "#", -1);
1482 <
1483 <  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1484 <           ConfigChannel.max_chans_per_user);
1485 <  add_isupport("CHANLIMIT", chanlimit, -1);
1486 <  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1487 <  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1488 <  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1489 <  add_isupport("CHANMODES", chanmodes, -1);
1490 <
1491 <  /*
1492 <   * message_locale may have changed.  rebuild isupport since it relies
1493 <   * on strlen(form_str(RPL_ISUPPORT))
1494 <   */
1495 <  rebuild_isupport_message_line();
1496 < }
1497 <
1498 < /* clear_out_old_conf()
1499 < *
1500 < * inputs       - none
1501 < * output       - none
1502 < * side effects - Clear out the old configuration
1503 < */
1504 < static void
1505 < clear_out_old_conf(void)
1506 < {
1507 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1508 <  struct MaskItem *conf;
1509 <  dlink_list *free_items [] = {
1510 <    &server_items,   &oconf_items,
1511 <     &uconf_items,   &xconf_items,
1512 <     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1513 <  };
1514 <
1515 <  dlink_list ** iterator = free_items; /* C is dumb */
1516 <
1517 <  /* We only need to free anything allocated by yyparse() here.
1518 <   * Resetting structs, etc, is taken care of by set_default_conf().
1519 <   */
1520 <  
1521 <  for (; *iterator != NULL; iterator++)
1522 <  {
1523 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1524 <    {
1525 <      conf = ptr->data;
1526 <
1527 <      dlinkDelete(&conf->node, map_to_list(conf->type));
1528 <
1529 <      /* XXX This is less than pretty */
1530 <      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1531 <      {
1532 <        if (!conf->ref_count)
1533 <          conf_free(conf);
1534 <      }
1535 <      else if (conf->type == CONF_XLINE)
1536 <      {
1537 <        if (!conf->until)
1538 <          conf_free(conf);
1539 <      }
1540 <      else
1541 <        conf_free(conf);
1542 <    }
1543 <  }
1544 <
1545 <  motd_clear();
1138 >  isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1139 >  isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1140  
1141 <  /*
1142 <   * don't delete the class table, rather mark all entries
1143 <   * for deletion. The table is cleaned up by class_delete_marked. - avalon
1144 <   */
1145 <  class_mark_for_deletion();
1146 <
1147 <  clear_out_address_conf();
1148 <
1149 <  /* clean out module paths */
1150 <  mod_clear_paths();
1151 <
1152 <  /* clean out ServerInfo */
1559 <  MyFree(ServerInfo.description);
1560 <  ServerInfo.description = NULL;
1561 <  MyFree(ServerInfo.network_name);
1562 <  ServerInfo.network_name = NULL;
1563 <  MyFree(ServerInfo.network_desc);
1564 <  ServerInfo.network_desc = NULL;
1565 <  MyFree(ConfigFileEntry.egdpool_path);
1566 <  ConfigFileEntry.egdpool_path = NULL;
1567 < #ifdef HAVE_LIBCRYPTO
1568 <  if (ServerInfo.rsa_private_key != NULL)
1569 <  {
1570 <    RSA_free(ServerInfo.rsa_private_key);
1571 <    ServerInfo.rsa_private_key = NULL;
1572 <  }
1573 <
1574 <  MyFree(ServerInfo.rsa_private_key_file);
1575 <  ServerInfo.rsa_private_key_file = NULL;
1576 <
1577 <  if (ServerInfo.server_ctx)
1578 <    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1579 <                                               SSL_OP_NO_SSLv3|
1580 <                                               SSL_OP_NO_TLSv1);
1581 <  if (ServerInfo.client_ctx)
1582 <    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1583 <                                               SSL_OP_NO_SSLv3|
1584 <                                               SSL_OP_NO_TLSv1);
1585 < #endif
1586 <
1587 <  /* clean out AdminInfo */
1588 <  MyFree(AdminInfo.name);
1589 <  AdminInfo.name = NULL;
1590 <  MyFree(AdminInfo.email);
1591 <  AdminInfo.email = NULL;
1592 <  MyFree(AdminInfo.description);
1593 <  AdminInfo.description = NULL;
1594 <
1595 <  /* clean out listeners */
1596 <  close_listeners();
1597 <
1598 <  /* clean out general */
1599 <  MyFree(ConfigFileEntry.service_name);
1600 <  ConfigFileEntry.service_name = NULL;
1141 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1142 >  isupport_add("MAXLIST", chanmodes, -1);
1143 >  isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1144 >  isupport_add("CHANTYPES", "#", -1);
1145 >
1146 >  snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1147 >           ConfigChannel.max_channels);
1148 >  isupport_add("CHANLIMIT", chanlimit, -1);
1149 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMORST");
1150 >  isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1151 >  isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1152 >  isupport_add("CHANMODES", chanmodes, -1);
1153   }
1154  
1155   /* conf_add_class_to_conf()
1156   *
1157   * inputs       - pointer to config item
1158   * output       - NONE
1159 < * side effects - Add a class pointer to a conf
1159 > * side effects - Add a class pointer to a conf
1160   */
1161   void
1162 < conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1162 > conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1163   {
1164 <  if (class_name == NULL)
1164 >  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1165    {
1166      conf->class = class_default;
1167  
1168 <    if (conf->type == CONF_CLIENT)
1169 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1618 <                           "Warning *** Defaulting to default class for %s@%s",
1619 <                           conf->user, conf->host);
1620 <    else
1621 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1622 <                           "Warning *** Defaulting to default class for %s",
1623 <                           conf->name);
1624 <  }
1625 <  else
1626 <    conf->class = class_find(class_name, 1);
1627 <
1628 <  if (conf->class == NULL)
1629 <  {
1630 <    if (conf->type == CONF_CLIENT)
1631 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1168 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1169 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1170                             "Warning *** Defaulting to default class for %s@%s",
1171                             conf->user, conf->host);
1172      else
1173 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1173 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1174                             "Warning *** Defaulting to default class for %s",
1175                             conf->name);
1638    conf->class = class_default;
1176    }
1177   }
1178  
# Line 1648 | Line 1185 | conf_add_class_to_conf(struct MaskItem *
1185   void
1186   yyerror(const char *msg)
1187   {
1651  char newlinebuf[IRCD_BUFSIZE];
1652
1188    if (conf_parser_ctx.pass != 1)
1189      return;
1190  
1191 <  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1192 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1191 >  const char *p = stripws(linebuf);
1192 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1193                         "\"%s\", line %u: %s: %s",
1194 <                       conffilebuf, lineno + 1, msg, newlinebuf);
1194 >                       conffilebuf, lineno, msg, p);
1195    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1196 <       conffilebuf, lineno + 1, msg, newlinebuf);
1196 >       conffilebuf, lineno, msg, p);
1197   }
1198  
1199   void
1200   conf_error_report(const char *msg)
1201   {
1202 <  char newlinebuf[IRCD_BUFSIZE];
1203 <
1669 <  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1670 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1202 >  const char *p = stripws(linebuf);
1203 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1204                         "\"%s\", line %u: %s: %s",
1205 <                       conffilebuf, lineno + 1, msg, newlinebuf);
1205 >                       conffilebuf, lineno, msg, p);
1206    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1207 <       conffilebuf, lineno + 1, msg, newlinebuf);
1207 >       conffilebuf, lineno, msg, p);
1208   }
1209  
1210   /*
1211   * valid_tkline()
1212 < *
1212 > *
1213   * inputs       - pointer to ascii string to check
1214   *              - whether the specified time is in seconds or minutes
1215   * output       - -1 not enough parameters
# Line 1684 | Line 1217 | conf_error_report(const char *msg)
1217   * side effects - none
1218   * Originally written by Dianora (Diane, db@db.net)
1219   */
1220 < time_t
1220 > uintmax_t
1221   valid_tkline(const char *data, const int minutes)
1222   {
1223    const unsigned char *p = (const unsigned char *)data;
1224    unsigned char tmpch = '\0';
1225 <  time_t result = 0;
1225 >  uintmax_t result = 0;
1226  
1227    while ((tmpch = *p++))
1228    {
# Line 1701 | Line 1234 | valid_tkline(const char *data, const int
1234    }
1235  
1236    /*
1237 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1238 <   * i.e. they specifically use 0, I am going to return 1 instead
1239 <   * as a return value of non-zero is used to flag it as a temporary kline
1237 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1238 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1239 >   * value of non-zero is used to flag it as a temporary kline
1240     */
1241    if (result == 0)
1242      result = 1;
1243  
1244 <  /*
1244 >  /*
1245     * If the incoming time is in seconds convert it to minutes for the purpose
1246     * of this calculation
1247     */
1248    if (!minutes)
1249 <    result = result / 60;
1249 >    result = result / 60;
1250  
1251    if (result > MAX_TDKLINE_TIME)
1252      result = MAX_TDKLINE_TIME;
1253  
1254 <  result = result * 60;  /* turn it into seconds */
1254 >  result = result * 60;  /* Turn it into seconds */
1255  
1256    return result;
1257   }
# Line 1734 | Line 1267 | valid_wild_card_simple(const char *data)
1267   {
1268    const unsigned char *p = (const unsigned char *)data;
1269    unsigned char tmpch = '\0';
1270 <  int nonwild = 0;
1270 >  unsigned int nonwild = 0, wild = 0;
1271  
1272    while ((tmpch = *p++))
1273    {
1274 <    if (tmpch == '\\')
1274 >    if (tmpch == '\\' && *p)
1275      {
1276        ++p;
1277 <      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1277 >      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1278          return 1;
1279      }
1280      else if (!IsMWildChar(tmpch))
1281      {
1282 <      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1282 >      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1283          return 1;
1284      }
1285 +    else
1286 +      ++wild;
1287    }
1288  
1289 <  return 0;
1289 >  return !wild;
1290   }
1291  
1292   /* valid_wild_card()
# Line 1763 | Line 1298 | valid_wild_card_simple(const char *data)
1298   * side effects - NOTICE is given to source_p if warn is 1
1299   */
1300   int
1301 < valid_wild_card(struct Client *source_p, int warn, int count, ...)
1301 > valid_wild_card(int count, ...)
1302   {
1303 <  char tmpch;
1304 <  int nonwild = 0;
1303 >  unsigned char tmpch = '\0';
1304 >  unsigned int nonwild = 0;
1305    va_list args;
1306  
1307    /*
# Line 1785 | Line 1320 | valid_wild_card(struct Client *source_p,
1320  
1321    while (count--)
1322    {
1323 <    const char *p = va_arg(args, const char *);
1323 >    const unsigned char *p = va_arg(args, const unsigned char *);
1324      if (p == NULL)
1325        continue;
1326  
# Line 1797 | Line 1332 | valid_wild_card(struct Client *source_p,
1332           * If we find enough non-wild characters, we can
1333           * break - no point in searching further.
1334           */
1335 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1335 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1336 >        {
1337 >          va_end(args);
1338            return 1;
1339 +        }
1340        }
1341      }
1342    }
1343  
1344 <  if (warn)
1345 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1346 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1344 >  va_end(args);
1345 >  return 0;
1346 > }
1347 >
1348 > /* find_user_host()
1349 > *
1350 > * inputs       - pointer to client placing kline
1351 > *              - pointer to user_host_or_nick
1352 > *              - pointer to user buffer
1353 > *              - pointer to host buffer
1354 > * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1355 > * side effects -
1356 > */
1357 > static int
1358 > find_user_host(struct Client *source_p, char *user_host_or_nick,
1359 >               char *luser, char *lhost)
1360 > {
1361 >  struct Client *target_p = NULL;
1362 >  char *hostp = NULL;
1363 >
1364 >  if (lhost == NULL)
1365 >  {
1366 >    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1367 >    return 1;
1368 >  }
1369 >
1370 >  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1371 >  {
1372 >    /* Explicit user@host mask given */
1373 >    if (hostp)                            /* I'm a little user@host */
1374 >    {
1375 >      *(hostp++) = '\0';                       /* short and squat */
1376 >
1377 >      if (*user_host_or_nick)
1378 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1379 >      else
1380 >        strcpy(luser, "*");
1381 >
1382 >      if (*hostp)
1383 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1384 >      else
1385 >        strcpy(lhost, "*");
1386 >    }
1387 >    else
1388 >    {
1389 >      luser[0] = '*';             /* no @ found, assume its *@somehost */
1390 >      luser[1] = '\0';
1391 >      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1392 >    }
1393 >
1394 >    return 1;
1395 >  }
1396 >  else
1397 >  {
1398 >    /* Try to find user@host mask from nick */
1399 >    /* Okay to use source_p as the first param, because source_p == client_p */
1400 >    if ((target_p =
1401 >        find_chasing(source_p, user_host_or_nick)) == NULL)
1402 >      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1403 >
1404 >    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1405 >    {
1406 >      if (IsClient(source_p))
1407 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1408 >      return 0;
1409 >    }
1410 >
1411 >    /*
1412 >     * Turn the "user" bit into "*user", blow away '~'
1413 >     * if found in original user name (non-idented)
1414 >     */
1415 >    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1416 >
1417 >    if (target_p->username[0] == '~')
1418 >      luser[0] = '*';
1419 >
1420 >    strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1421 >    return 1;
1422 >  }
1423 >
1424    return 0;
1425   }
1426  
# Line 1819 | Line 1434 | valid_wild_card(struct Client *source_p,
1434   *              - parse_flags bit map of things to test
1435   *              - pointer to user or string to parse into
1436   *              - pointer to host or NULL to parse into if non NULL
1437 < *              - pointer to optional tkline time or NULL
1437 > *              - pointer to optional tkline time or NULL
1438   *              - pointer to target_server to parse into if non NULL
1439   *              - pointer to reason to parse into
1440   *
1441 < * output       - 1 if valid, -1 if not valid
1441 > * output       - 1 if valid, 0 if not valid
1442   * side effects - A generalised k/d/x etc. line parser,
1443   *               "ALINE [time] user@host|string [ON] target :reason"
1444   *                will parse returning a parsed user, host if
# Line 1842 | Line 1457 | valid_wild_card(struct Client *source_p,
1457   int
1458   parse_aline(const char *cmd, struct Client *source_p,
1459              int parc, char **parv,
1460 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1460 >            char **up_p, char **h_p, uintmax_t *tkline_time,
1461              char **target_server, char **reason)
1462   {
1463 <  int found_tkline_time=0;
1464 <  static char def_reason[] = "No Reason";
1463 >  uintmax_t found_tkline_time=0;
1464 >  static char default_reason[] = CONF_NOREASON;
1465    static char user[USERLEN*4+1];
1466    static char host[HOSTLEN*4+1];
1467  
# Line 1855 | Line 1470 | parse_aline(const char *cmd, struct Clie
1470  
1471    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1472  
1473 <  if (found_tkline_time != 0)
1473 >  if (found_tkline_time)
1474    {
1475      parv++;
1476      parc--;
1477  
1478 <    if (tkline_time != NULL)
1478 >    if (tkline_time)
1479        *tkline_time = found_tkline_time;
1480      else
1481      {
1482 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1483 <                 me.name, source_p->name, cmd);
1869 <      return -1;
1482 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1483 >      return 0;
1484      }
1485    }
1486  
1487    if (parc == 0)
1488    {
1489 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1490 <               me.name, source_p->name, cmd);
1877 <    return -1;
1489 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1490 >    return 0;
1491    }
1492  
1493    if (h_p == NULL)
1494      *up_p = *parv;
1495    else
1496    {
1497 <    if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1498 <      return -1;
1497 >    if (find_user_host(source_p, *parv, user, host) == 0)
1498 >      return 0;
1499  
1500      *up_p = user;
1501      *h_p = host;
1502    }
1503 <
1503 >
1504    parc--;
1505    parv++;
1506  
1507 <  if (parc != 0)
1507 >  if (parc)
1508    {
1509      if (irccmp(*parv, "ON") == 0)
1510      {
1511        parc--;
1512        parv++;
1513  
1901      if (target_server == NULL)
1902      {
1903        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1904                   me.name, source_p->name, cmd);
1905        return -1;
1906      }
1907
1514        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1515        {
1516 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
1517 <                   me.name, source_p->name, "remoteban");
1912 <        return -1;
1516 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1517 >        return 0;
1518        }
1519  
1520        if (parc == 0 || EmptyString(*parv))
1521        {
1522 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1523 <                   me.name, source_p->name, cmd);
1919 <        return -1;
1522 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1523 >        return 0;
1524        }
1525  
1526        *target_server = *parv;
# Line 1928 | Line 1532 | parse_aline(const char *cmd, struct Clie
1532        /* Make sure target_server *is* NULL if no ON server found
1533         * caller probably NULL'd it first, but no harm to do it again -db
1534         */
1535 <      if (target_server != NULL)
1535 >      if (target_server)
1536          *target_server = NULL;
1537      }
1538    }
1539  
1540 <  if (h_p != NULL)
1540 >  if (reason)
1541    {
1542 <    if (strchr(user, '!') != NULL)
1939 <    {
1940 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1941 <                 me.name, source_p->name);
1942 <      return -1;
1943 <    }
1944 <
1945 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1946 <      return -1;
1947 <  }
1948 <  else
1949 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1950 <      return -1;
1951 <
1952 <  if (reason != NULL)
1953 <  {
1954 <    if (parc != 0 && !EmptyString(*parv))
1955 <    {
1542 >    if (parc && !EmptyString(*parv))
1543        *reason = *parv;
1957      if (!valid_comment(source_p, *reason, 1))
1958        return -1;
1959    }
1960    else
1961      *reason = def_reason;
1962  }
1963
1964  return 1;
1965 }
1966
1967 /* find_user_host()
1968 *
1969 * inputs       - pointer to client placing kline
1970 *              - pointer to user_host_or_nick
1971 *              - pointer to user buffer
1972 *              - pointer to host buffer
1973 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1974 * side effects -
1975 */
1976 static int
1977 find_user_host(struct Client *source_p, char *user_host_or_nick,
1978               char *luser, char *lhost, unsigned int flags)
1979 {
1980  struct Client *target_p = NULL;
1981  char *hostp = NULL;
1982
1983  if (lhost == NULL)
1984  {
1985    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1986    return 1;
1987  }
1988
1989  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1990  {
1991    /* Explicit user@host mask given */
1992
1993    if (hostp != NULL)                            /* I'm a little user@host */
1994    {
1995      *(hostp++) = '\0';                       /* short and squat */
1996      if (*user_host_or_nick)
1997        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1998      else
1999        strcpy(luser, "*");
2000
2001      if (*hostp)
2002        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2003      else
2004        strcpy(lhost, "*");
2005    }
2006    else
2007    {
2008      luser[0] = '*';             /* no @ found, assume its *@somehost */
2009      luser[1] = '\0';
2010      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2011    }
2012    
2013    return 1;
2014  }
2015  else
2016  {
2017    /* Try to find user@host mask from nick */
2018    /* Okay to use source_p as the first param, because source_p == client_p */
2019    if ((target_p =
2020        find_chasing(source_p, user_host_or_nick, NULL)) == NULL)
2021      return 0;
2022
2023    if (IsExemptKline(target_p))
2024    {
2025      if (!IsServer(source_p))
2026        sendto_one(source_p,
2027                   ":%s NOTICE %s :%s is E-lined",
2028                   me.name, source_p->name, target_p->name);
2029      return 0;
2030    }
2031
2032    /*
2033     * turn the "user" bit into "*user", blow away '~'
2034     * if found in original user name (non-idented)
2035     */
2036    strlcpy(luser, target_p->username, USERLEN*4 + 1);
2037
2038    if (target_p->username[0] == '~')
2039      luser[0] = '*';
2040
2041    if (target_p->sockhost[0] == '\0' ||
2042        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2043      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1544      else
1545 <      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2046 <    return 1;
1545 >      *reason = default_reason;
1546    }
1547  
2049  return 0;
2050 }
2051
2052 /* valid_comment()
2053 *
2054 * inputs       - pointer to client
2055 *              - pointer to comment
2056 * output       - 0 if no valid comment,
2057 *              - 1 if valid
2058 * side effects - truncates reason where necessary
2059 */
2060 int
2061 valid_comment(struct Client *source_p, char *comment, int warn)
2062 {
2063  if (strlen(comment) > REASONLEN)
2064    comment[REASONLEN-1] = '\0';
2065
1548    return 1;
1549   }
1550  
# Line 2086 | Line 1568 | match_conf_password(const char *password
1568    else
1569      encr = password;
1570  
1571 <  return !strcmp(encr, conf->passwd);
2090 < }
2091 <
2092 < /*
2093 < * cluster_a_line
2094 < *
2095 < * inputs       - client sending the cluster
2096 < *              - command name "KLINE" "XLINE" etc.
2097 < *              - capab -- CAP_KLN etc. from s_serv.h
2098 < *              - cluster type -- CLUSTER_KLINE etc. from conf.h
2099 < *              - pattern and args to send along
2100 < * output       - none
2101 < * side effects - Take source_p send the pattern with args given
2102 < *                along to all servers that match capab and cluster type
2103 < */
2104 < void
2105 < cluster_a_line(struct Client *source_p, const char *command,
2106 <               int capab, int cluster_type, const char *pattern, ...)
2107 < {
2108 <  va_list args;
2109 <  char buffer[IRCD_BUFSIZE];
2110 <  const dlink_node *ptr = NULL;
2111 <
2112 <  va_start(args, pattern);
2113 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
2114 <  va_end(args);
2115 <
2116 <  DLINK_FOREACH(ptr, cluster_items.head)
2117 <  {
2118 <    const struct MaskItem *conf = ptr->data;
2119 <
2120 <    if (conf->flags & cluster_type)
2121 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2122 <                         "%s %s %s", command, conf->name, buffer);
2123 <  }
1571 >  return encr && !strcmp(encr, conf->passwd);
1572   }
1573  
1574   /*
# Line 2158 | Line 1606 | split_nuh(struct split_nuh_item *const i
1606  
1607    if (iptr->nickptr)
1608      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1609 +
1610    if (iptr->userptr)
1611      strlcpy(iptr->userptr, "*", iptr->usersize);
1612 +
1613    if (iptr->hostptr)
1614      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1615  
# Line 2167 | Line 1617 | split_nuh(struct split_nuh_item *const i
1617    {
1618      *p = '\0';
1619  
1620 <    if (iptr->nickptr && *iptr->nuhmask != '\0')
1620 >    if (iptr->nickptr && *iptr->nuhmask)
1621        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1622  
1623      if ((q = strchr(++p, '@')))
1624      {
1625        *q++ = '\0';
1626  
1627 <      if (*p != '\0')
1627 >      if (*p)
1628          strlcpy(iptr->userptr, p, iptr->usersize);
1629  
1630 <      if (*q != '\0')
1630 >      if (*q)
1631          strlcpy(iptr->hostptr, q, iptr->hostsize);
1632      }
1633      else
1634      {
1635 <      if (*p != '\0')
1635 >      if (*p)
1636          strlcpy(iptr->userptr, p, iptr->usersize);
1637      }
1638    }
# Line 2194 | Line 1644 | split_nuh(struct split_nuh_item *const i
1644        /* if found a @ */
1645        *p++ = '\0';
1646  
1647 <      if (*iptr->nuhmask != '\0')
1647 >      if (*iptr->nuhmask)
1648          strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1649  
1650 <      if (*p != '\0')
1650 >      if (*p)
1651          strlcpy(iptr->hostptr, p, iptr->hostsize);
1652      }
1653      else
1654      {
1655 <      /* no @ found */
1655 >      /* No @ found */
1656        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1657          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1658        else

Comparing ircd-hybrid/trunk/src/conf.c (property svn:keywords):
Revision 2525 by michael, Sat Nov 2 17:07:38 2013 UTC vs.
Revision 8279 by michael, Tue Feb 20 19:30:13 2018 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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