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 3215 by michael, Tue Mar 25 19:23:15 2014 UTC vs.
Revision 8451 by michael, Fri Mar 30 15:15:15 2018 UTC

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

Comparing ircd-hybrid/trunk/src/conf.c (property svn:keywords):
Revision 3215 by michael, Tue Mar 25 19:23:15 2014 UTC vs.
Revision 8451 by michael, Fri Mar 30 15:15:15 2018 UTC

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

Diff Legend

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