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 3869 by michael, Thu Jun 5 22:19:27 2014 UTC vs.
Revision 6956 by michael, Thu Dec 17 10:54:07 2015 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-2015 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 "conf_pseudo.h"
32   #include "server.h"
33   #include "resv.h"
34   #include "channel.h"
# Line 44 | Line 45
45   #include "log.h"
46   #include "send.h"
47   #include "memory.h"
47 #include "mempool.h"
48   #include "res.h"
49   #include "userhost.h"
50   #include "user.h"
# Line 54 | Line 54
54   #include "conf_db.h"
55   #include "conf_class.h"
56   #include "motd.h"
57 + #include "ipcache.h"
58 + #include "isupport.h"
59  
60  
61   struct config_channel_entry ConfigChannel;
62 < struct config_server_hide ConfigServerHide;
63 < struct config_file_entry ConfigFileEntry;
64 < struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
65 < struct server_info ServerInfo;
66 < struct admin_info AdminInfo;
62 > struct config_serverhide_entry ConfigServerHide;
63 > struct config_general_entry ConfigGeneral;
64 > struct config_log_entry ConfigLog = { .use_logging = 1 };
65 > struct config_serverinfo_entry ConfigServerInfo;
66 > struct config_admin_entry ConfigAdminInfo;
67 > struct conf_parser_context conf_parser_ctx;
68  
69   /* general conf items link list root, other than k lines etc. */
70 < dlink_list service_items = { NULL, NULL, 0 };
71 < dlink_list server_items  = { NULL, NULL, 0 };
72 < dlink_list cluster_items = { NULL, NULL, 0 };
73 < dlink_list oconf_items   = { NULL, NULL, 0 };
74 < dlink_list uconf_items   = { NULL, NULL, 0 };
75 < dlink_list xconf_items   = { NULL, NULL, 0 };
76 < dlink_list nresv_items   = { NULL, NULL, 0 };
77 < dlink_list cresv_items = { NULL, NULL, 0 };
70 > dlink_list service_items;
71 > dlink_list server_items;
72 > dlink_list cluster_items;
73 > dlink_list operator_items;
74 > dlink_list shared_items;
75 > dlink_list gecos_items;
76 > dlink_list nresv_items;
77 > dlink_list cresv_items;
78  
79   extern unsigned int lineno;
80   extern char linebuf[];
81   extern char conffilebuf[IRCD_BUFSIZE];
82   extern int yyparse(); /* defined in y.tab.c */
83  
81 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
82
83 /* internally defined functions */
84 static void read_conf(FILE *);
85 static void clear_out_old_conf(void);
86 static void expire_tklines(dlink_list *);
87 static void garbage_collect_ip_entries(void);
88 static int hash_ip(struct irc_ssaddr *);
89 static int verify_access(struct Client *);
90 static int attach_iline(struct Client *, struct MaskItem *);
91 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
92 static dlink_list *map_to_list(enum maskitem_type);
93 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
94
95
96 /* usually, with hash tables, you use a prime number...
97 * but in this case I am dealing with ip addresses,
98 * not ascii strings.
99 */
100 #define IP_HASH_SIZE 0x1000
101
102 struct ip_entry
103 {
104  struct irc_ssaddr ip;
105  unsigned int count;
106  time_t last_attempt;
107  struct ip_entry *next;
108 };
109
110 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
111 static mp_pool_t *ip_entry_pool = NULL;
112 static int ip_entries_count = 0;
113
84  
85   /* conf_dns_callback()
86   *
# Line 123 | Line 93 | static int ip_entries_count = 0;
93   * if successful save hp in the conf item it was called with
94   */
95   static void
96 < conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
96 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
97   {
98 <  struct MaskItem *conf = vptr;
98 >  struct MaskItem *const conf = vptr;
99  
100    conf->dns_pending = 0;
101  
# Line 144 | Line 114 | conf_dns_callback(void *vptr, const stru
114   static void
115   conf_dns_lookup(struct MaskItem *conf)
116   {
117 <  if (!conf->dns_pending)
117 >  if (conf->dns_pending)
118 >    return;
119 >
120 >  conf->dns_pending = 1;
121 >
122 >  if (conf->aftype == AF_INET)
123 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
124 >  else
125 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
126 > }
127 >
128 > /* map_to_list()
129 > *
130 > * inputs       - ConfType conf
131 > * output       - pointer to dlink_list to use
132 > * side effects - none
133 > */
134 > static dlink_list *
135 > map_to_list(enum maskitem_type type)
136 > {
137 >  switch (type)
138    {
139 <    conf->dns_pending = 1;
140 <    gethost_byname(conf_dns_callback, conf, conf->host);
139 >    case CONF_XLINE:
140 >      return &gecos_items;
141 >      break;
142 >    case CONF_SHARED:
143 >      return &shared_items;
144 >      break;
145 >    case CONF_NRESV:
146 >      return &nresv_items;
147 >      break;
148 >    case CONF_CRESV:
149 >      return &cresv_items;
150 >      break;
151 >    case CONF_OPER:
152 >      return &operator_items;
153 >      break;
154 >    case CONF_SERVER:
155 >      return &server_items;
156 >      break;
157 >    case CONF_SERVICE:
158 >      return &service_items;
159 >      break;
160 >    case CONF_CLUSTER:
161 >      return &cluster_items;
162 >      break;
163 >    default:
164 >      return NULL;
165    }
166   }
167  
168   struct MaskItem *
169   conf_make(enum maskitem_type type)
170   {
171 <  struct MaskItem *conf = MyCalloc(sizeof(*conf));
171 >  struct MaskItem *const conf = MyCalloc(sizeof(*conf));
172    dlink_list *list = NULL;
173  
174    conf->type   = type;
# Line 169 | Line 183 | conf_make(enum maskitem_type type)
183   void
184   conf_free(struct MaskItem *conf)
185   {
186 <  dlink_node *ptr = NULL, *ptr_next = NULL;
186 >  dlink_node *node = NULL, *node_next = NULL;
187    dlink_list *list = NULL;
188  
189 <  if (conf->node.next)
190 <    if ((list = map_to_list(conf->type)))
177 <      dlinkDelete(&conf->node, list);
189 >  if ((list = map_to_list(conf->type)))
190 >    dlinkFindDelete(list, conf);
191  
192    MyFree(conf->name);
193  
# Line 191 | Line 204 | conf_free(struct MaskItem *conf)
204    MyFree(conf->spasswd);
205    MyFree(conf->reason);
206    MyFree(conf->certfp);
207 +  MyFree(conf->whois);
208    MyFree(conf->user);
209    MyFree(conf->host);
210   #ifdef HAVE_LIBCRYPTO
# Line 199 | Line 213 | conf_free(struct MaskItem *conf)
213    if (conf->rsa_public_key)
214      RSA_free(conf->rsa_public_key);
215   #endif
216 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
216 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
217    {
218 <    MyFree(ptr->data);
219 <    dlinkDelete(ptr, &conf->hub_list);
220 <    free_dlink_node(ptr);
218 >    MyFree(node->data);
219 >    dlinkDelete(node, &conf->hub_list);
220 >    free_dlink_node(node);
221    }
222  
223 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
223 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
224    {
225 <    MyFree(ptr->data);
226 <    dlinkDelete(ptr, &conf->leaf_list);
227 <    free_dlink_node(ptr);
225 >    MyFree(node->data);
226 >    dlinkDelete(node, &conf->leaf_list);
227 >    free_dlink_node(node);
228    }
229  
230 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
230 >  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
231    {
232 <    struct exempt *exptr = ptr->data;
232 >    struct exempt *exptr = node->data;
233  
234 <    dlinkDelete(ptr, &conf->exempt_list);
234 >    dlinkDelete(node, &conf->exempt_list);
235      MyFree(exptr->name);
236      MyFree(exptr->user);
237      MyFree(exptr->host);
# Line 227 | Line 241 | conf_free(struct MaskItem *conf)
241    MyFree(conf);
242   }
243  
230 /* check_client()
231 *
232 * inputs       - pointer to client
233 * output       - 0 = Success
234 *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
235 *                IRCD_SOCKET_ERROR (-2) = Bad socket.
236 *                I_LINE_FULL       (-3) = I-line is full
237 *                TOO_MANY          (-4) = Too many connections from hostname
238 *                BANNED_CLIENT     (-5) = K-lined
239 * side effects - Ordinary client access check.
240 *                Look for conf lines which have the same
241 *                status as the flags passed.
242 */
243 int
244 check_client(struct Client *source_p)
245 {
246  int i;
247
248  if ((i = verify_access(source_p)))
249    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
250         source_p->name, source_p->sockhost);
251
252  switch (i)
253  {
254    case TOO_MANY:
255      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
256                           "Too many on IP for %s (%s).",
257                           get_client_name(source_p, SHOW_IP),
258                           source_p->sockhost);
259      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
260           get_client_name(source_p, SHOW_IP));
261      ++ServerStats.is_ref;
262      exit_client(source_p, "No more connections allowed on that IP");
263      break;
264
265    case I_LINE_FULL:
266      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
267                           "auth{} block is full for %s (%s).",
268                           get_client_name(source_p, SHOW_IP),
269                           source_p->sockhost);
270      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
271           get_client_name(source_p, SHOW_IP));
272      ++ServerStats.is_ref;
273      exit_client(source_p, "No more connections allowed in your connection class");
274      break;
275
276    case NOT_AUTHORIZED:
277      ++ServerStats.is_ref;
278      /* jdc - lists server name & port connections are on */
279      /*       a purely cosmetical change */
280      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
281                           "Unauthorized client connection from %s [%s] on [%s/%u].",
282                           get_client_name(source_p, SHOW_IP),
283                           source_p->sockhost,
284                           source_p->localClient->listener->name,
285                           source_p->localClient->listener->port);
286      ilog(LOG_TYPE_IRCD,
287           "Unauthorized client connection from %s on [%s/%u].",
288           get_client_name(source_p, SHOW_IP),
289           source_p->localClient->listener->name,
290           source_p->localClient->listener->port);
291
292      exit_client(source_p, "You are not authorized to use this server");
293      break;
294
295   case BANNED_CLIENT:
296     exit_client(source_p, "Banned");
297     ++ServerStats.is_ref;
298     break;
299
300   case 0:
301   default:
302     break;
303  }
304
305  return (i < 0 ? 0 : 1);
306 }
307
308 /* verify_access()
309 *
310 * inputs       - pointer to client to verify
311 * output       - 0 if success -'ve if not
312 * side effect  - find the first (best) I line to attach.
313 */
314 static int
315 verify_access(struct Client *client_p)
316 {
317  struct MaskItem *conf = NULL;
318  char non_ident[USERLEN + 1] = "~";
319
320  if (IsGotId(client_p))
321  {
322    conf = find_address_conf(client_p->host, client_p->username,
323                             &client_p->localClient->ip,
324                             client_p->localClient->aftype,
325                             client_p->localClient->passwd);
326  }
327  else
328  {
329    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
330    conf = find_address_conf(client_p->host,non_ident,
331                             &client_p->localClient->ip,
332                             client_p->localClient->aftype,
333                             client_p->localClient->passwd);
334  }
335
336  if (conf)
337  {
338    if (IsConfClient(conf))
339    {
340      if (IsConfRedir(conf))
341      {
342        sendto_one_numeric(client_p, &me, RPL_REDIR,
343                           conf->name ? conf->name : "",
344                           conf->port);
345        return NOT_AUTHORIZED;
346      }
347
348      if (IsConfDoIdentd(conf))
349        SetNeedId(client_p);
350
351      /* Thanks for spoof idea amm */
352      if (IsConfDoSpoofIp(conf))
353      {
354        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
355          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
356                               "%s spoofing: %s as %s",
357                               client_p->name, client_p->host, conf->name);
358        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
359        AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
360      }
361
362      return attach_iline(client_p, conf);
363    }
364    else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
365    {
366      if (IsConfGline(conf))
367        sendto_one_notice(client_p, &me, ":*** G-lined");
368      sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
369      return BANNED_CLIENT;
370    }
371  }
372
373  return NOT_AUTHORIZED;
374 }
375
244   /* attach_iline()
245   *
246 < * inputs       - client pointer
247 < *              - conf pointer
248 < * output       -
249 < * side effects - do actual attach
246 > * inputs       - client pointer
247 > *              - conf pointer
248 > * output       -
249 > * side effects - do actual attach
250   */
251   static int
252   attach_iline(struct Client *client_p, struct MaskItem *conf)
253   {
254 <  struct ClassItem *class = NULL;
254 >  const struct ClassItem *const class = conf->class;
255    struct ip_entry *ip_found;
256    int a_limit_reached = 0;
257    unsigned int local = 0, global = 0, ident = 0;
258  
259 <  assert(conf->class);
392 <
393 <  ip_found = find_or_add_ip(&client_p->localClient->ip);
259 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
260    ip_found->count++;
261 <  SetIpHash(client_p);
396 <
397 <  class = conf->class;
261 >  AddFlag(client_p, FLAGS_IPHASH);
262  
263 <  count_user_host(client_p->username, client_p->host,
264 <                  &global, &local, &ident);
263 >  userhost_count(client_p->username, client_p->host,
264 >                 &global, &local, &ident);
265  
266    /* XXX blah. go down checking the various silly limits
267     * setting a_limit_reached if any limit is reached.
# Line 427 | Line 291 | attach_iline(struct Client *client_p, st
291    return attach_conf(client_p, conf);
292   }
293  
294 < /* init_ip_hash_table()
431 < *
432 < * inputs               - NONE
433 < * output               - NONE
434 < * side effects         - allocate memory for ip_entry(s)
435 < *                      - clear the ip hash table
436 < */
437 < void
438 < init_ip_hash_table(void)
439 < {
440 <  ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
441 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
442 < }
443 <
444 < /* find_or_add_ip()
445 < *
446 < * inputs       - pointer to struct irc_ssaddr
447 < * output       - pointer to a struct ip_entry
448 < * side effects -
294 > /* verify_access()
295   *
296 < * If the ip # was not found, a new struct ip_entry is created, and the ip
297 < * count set to 0.
296 > * inputs       - pointer to client to verify
297 > * output       - 0 if success -'ve if not
298 > * side effect  - find the first (best) I line to attach.
299   */
300 < static struct ip_entry *
301 < find_or_add_ip(struct irc_ssaddr *ip_in)
300 > static int
301 > verify_access(struct Client *client_p)
302   {
303 <  struct ip_entry *ptr, *newptr;
457 <  int hash_index = hash_ip(ip_in), res;
458 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
459 < #ifdef IPV6
460 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
461 < #endif
303 >  struct MaskItem *conf = NULL;
304  
305 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
305 >  if (HasFlag(client_p, FLAGS_GOTID))
306    {
307 < #ifdef IPV6
308 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
309 <      continue;
310 <    if (ip_in->ss.ss_family == AF_INET6)
469 <    {
470 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
471 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
472 <    }
473 <    else
474 < #endif
475 <    {
476 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
477 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
478 <    }
479 <    if (res == 0)
480 <    {
481 <      /* Found entry already in hash, return it. */
482 <      return ptr;
483 <    }
307 >    conf = find_address_conf(client_p->host, client_p->username,
308 >                             &client_p->connection->ip,
309 >                             client_p->connection->aftype,
310 >                             client_p->connection->password);
311    }
312 +  else
313 +  {
314 +    char non_ident[USERLEN + 1] = "~";
315  
316 <  if (ip_entries_count >= 2 * hard_fdlimit)
317 <    garbage_collect_ip_entries();
318 <
319 <  newptr = mp_pool_get(ip_entry_pool);
320 <  memset(newptr, 0, sizeof(*newptr));
321 <  ip_entries_count++;
492 <  memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
316 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
317 >    conf = find_address_conf(client_p->host, non_ident,
318 >                             &client_p->connection->ip,
319 >                             client_p->connection->aftype,
320 >                             client_p->connection->password);
321 >  }
322  
323 <  newptr->next = ip_hash_table[hash_index];
324 <  ip_hash_table[hash_index] = newptr;
323 >  if (!conf)
324 >    return NOT_AUTHORIZED;
325  
326 <  return newptr;
498 < }
326 >  assert(IsConfClient(conf) || IsConfKill(conf));
327  
328 < /* remove_one_ip()
501 < *
502 < * inputs        - unsigned long IP address value
503 < * output        - NONE
504 < * side effects  - The ip address given, is looked up in ip hash table
505 < *                 and number of ip#'s for that ip decremented.
506 < *                 If ip # count reaches 0 and has expired,
507 < *                 the struct ip_entry is returned to the ip_entry_heap
508 < */
509 < void
510 < remove_one_ip(struct irc_ssaddr *ip_in)
511 < {
512 <  struct ip_entry *ptr;
513 <  struct ip_entry *last_ptr = NULL;
514 <  int hash_index = hash_ip(ip_in), res;
515 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
516 < #ifdef IPV6
517 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
518 < #endif
519 <
520 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
328 >  if (IsConfClient(conf))
329    {
330 < #ifdef IPV6
523 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
524 <      continue;
525 <    if (ip_in->ss.ss_family == AF_INET6)
526 <    {
527 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
528 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
529 <    }
530 <    else
531 < #endif
330 >    if (IsConfRedir(conf))
331      {
332 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
333 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
332 >      sendto_one_numeric(client_p, &me, RPL_REDIR,
333 >                         conf->name ? conf->name : "",
334 >                         conf->port);
335 >      return NOT_AUTHORIZED;
336      }
337 <    if (res)
338 <      continue;
538 <    if (ptr->count > 0)
539 <      ptr->count--;
540 <    if (ptr->count == 0 &&
541 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
337 >
338 >    if (IsConfDoSpoofIp(conf))
339      {
340 <      if (last_ptr != NULL)
341 <        last_ptr->next = ptr->next;
342 <      else
546 <        ip_hash_table[hash_index] = ptr->next;
340 >      if (IsConfSpoofNotice(conf))
341 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
342 >                             client_p->name, client_p->host, conf->name);
343  
344 <      mp_pool_release(ptr);
549 <      ip_entries_count--;
550 <      return;
344 >      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
345      }
552    last_ptr = ptr;
553  }
554 }
346  
347 < /* hash_ip()
557 < *
558 < * input        - pointer to an irc_inaddr
559 < * output       - integer value used as index into hash table
560 < * side effects - hopefully, none
561 < */
562 < static int
563 < hash_ip(struct irc_ssaddr *addr)
564 < {
565 <  if (addr->ss.ss_family == AF_INET)
566 <  {
567 <    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
568 <    int hash;
569 <    uint32_t ip;
570 <
571 <    ip   = ntohl(v4->sin_addr.s_addr);
572 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
573 <    return hash;
574 <  }
575 < #ifdef IPV6
576 <  else
577 <  {
578 <    int hash;
579 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
580 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
581 <
582 <    hash  = ip[0] ^ ip[3];
583 <    hash ^= hash >> 16;
584 <    hash ^= hash >> 8;
585 <    hash  = hash & (IP_HASH_SIZE - 1);
586 <    return hash;
347 >    return attach_iline(client_p, conf);
348    }
349 < #else
350 <  return 0;
351 < #endif
349 >
350 >  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
351 >  return BANNED_CLIENT;
352   }
353  
354 < /* count_ip_hash()
594 < *
595 < * inputs        - pointer to counter of number of ips hashed
596 < *               - pointer to memory used for ip hash
597 < * output        - returned via pointers input
598 < * side effects  - NONE
354 > /* check_client()
355   *
356 < * number of hashed ip #'s is counted up, plus the amount of memory
357 < * used in the hash.
356 > * inputs       - pointer to client
357 > * output       - 0 = Success
358 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
359 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
360 > *                I_LINE_FULL       (-3) = I-line is full
361 > *                TOO_MANY          (-4) = Too many connections from hostname
362 > *                BANNED_CLIENT     (-5) = K-lined
363 > * side effects - Ordinary client access check.
364 > *                Look for conf lines which have the same
365 > *                status as the flags passed.
366   */
367 < void
368 < count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
367 > int
368 > check_client(struct Client *source_p)
369   {
370 <  struct ip_entry *ptr;
370 >  int i;
371  
372 <  *number_ips_stored = 0;
373 <  *mem_ips_stored    = 0;
372 >  if ((i = verify_access(source_p)))
373 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
374 >         source_p->name, source_p->sockhost);
375  
376 <  for (unsigned int i = 0; i < IP_HASH_SIZE; ++i)
376 >  switch (i)
377    {
378 <    for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
379 <    {
380 <      *number_ips_stored += 1;
381 <      *mem_ips_stored += sizeof(struct ip_entry);
382 <    }
383 <  }
384 < }
378 >    case TOO_MANY:
379 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
380 >                           "Too many on IP for %s (%s).",
381 >                           get_client_name(source_p, SHOW_IP),
382 >                           source_p->sockhost);
383 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
384 >           get_client_name(source_p, SHOW_IP));
385 >      ++ServerStats.is_ref;
386 >      exit_client(source_p, "No more connections allowed on that IP");
387 >      break;
388  
389 < /* garbage_collect_ip_entries()
390 < *
391 < * input        - NONE
392 < * output       - NONE
393 < * side effects - free up all ip entries with no connections
394 < */
395 < static void
396 < garbage_collect_ip_entries(void)
397 < {
398 <  struct ip_entry *ptr;
631 <  struct ip_entry *last_ptr;
632 <  struct ip_entry *next_ptr;
389 >    case I_LINE_FULL:
390 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
391 >                           "auth {} block is full for %s (%s).",
392 >                           get_client_name(source_p, SHOW_IP),
393 >                           source_p->sockhost);
394 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
395 >           get_client_name(source_p, SHOW_IP));
396 >      ++ServerStats.is_ref;
397 >      exit_client(source_p, "No more connections allowed in your connection class");
398 >      break;
399  
400 <  for (unsigned int i = 0; i < IP_HASH_SIZE; ++i)
401 <  {
402 <    last_ptr = NULL;
400 >    case NOT_AUTHORIZED:
401 >      /* jdc - lists server name & port connections are on */
402 >      /*       a purely cosmetical change */
403 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
404 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
405 >                           get_client_name(source_p, SHOW_IP),
406 >                           source_p->sockhost,
407 >                           source_p->connection->listener->name,
408 >                           source_p->connection->listener->port);
409 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
410 >           get_client_name(source_p, SHOW_IP),
411 >           source_p->connection->listener->name,
412 >           source_p->connection->listener->port);
413  
414 <    for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
415 <    {
416 <      next_ptr = ptr->next;
414 >      ++ServerStats.is_ref;
415 >      exit_client(source_p, "You are not authorized to use this server");
416 >      break;
417  
418 <      if (ptr->count == 0 &&
419 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
420 <      {
421 <        if (last_ptr != NULL)
422 <          last_ptr->next = ptr->next;
423 <        else
424 <          ip_hash_table[i] = ptr->next;
425 <        mp_pool_release(ptr);
650 <        ip_entries_count--;
651 <      }
652 <      else
653 <        last_ptr = ptr;
654 <    }
418 >    case BANNED_CLIENT:
419 >      ++ServerStats.is_ref;
420 >      exit_client(source_p, "Banned");
421 >      break;
422 >
423 >    case 0:
424 >    default:
425 >      break;
426    }
427 +
428 +  return !(i < 0);
429   }
430  
431   /* detach_conf()
# Line 666 | Line 439 | garbage_collect_ip_entries(void)
439   void
440   detach_conf(struct Client *client_p, enum maskitem_type type)
441   {
442 <  dlink_node *ptr = NULL, *ptr_next = NULL;
442 >  dlink_node *node = NULL, *node_next = NULL;
443  
444 <  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->confs.head)
444 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
445    {
446 <    struct MaskItem *conf = ptr->data;
446 >    struct MaskItem *conf = node->data;
447  
448      assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
449      assert(conf->ref_count > 0);
# Line 679 | Line 452 | detach_conf(struct Client *client_p, enu
452      if (!(conf->type & type))
453        continue;
454  
455 <    dlinkDelete(ptr, &client_p->localClient->confs);
456 <    free_dlink_node(ptr);
455 >    dlinkDelete(node, &client_p->connection->confs);
456 >    free_dlink_node(node);
457  
458      if (conf->type == CONF_CLIENT)
459 <      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
459 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
460  
461      if (--conf->class->ref_count == 0 && conf->class->active == 0)
462      {
# Line 709 | Line 482 | detach_conf(struct Client *client_p, enu
482   int
483   attach_conf(struct Client *client_p, struct MaskItem *conf)
484   {
485 <  if (dlinkFind(&client_p->localClient->confs, conf))
485 >  if (dlinkFind(&client_p->connection->confs, conf))
486      return 1;
487  
488    if (conf->type == CONF_CLIENT)
489      if (cidr_limit_reached(IsConfExemptLimits(conf),
490 <                           &client_p->localClient->ip, conf->class))
490 >                           &client_p->connection->ip, conf->class))
491        return TOO_MANY;    /* Already at maximum allowed */
492  
493    conf->class->ref_count++;
494    conf->ref_count++;
495  
496 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
496 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
497  
498    return 0;
499   }
# Line 737 | Line 510 | int
510   attach_connect_block(struct Client *client_p, const char *name,
511                       const char *host)
512   {
513 <  dlink_node *ptr;
741 <  struct MaskItem *conf = NULL;
513 >  dlink_node *node = NULL;
514  
515 <  assert(client_p != NULL);
744 <  assert(host != NULL);
515 >  assert(host);
516  
517 <  if (client_p == NULL || host == NULL)
747 <    return 0;
748 <
749 <  DLINK_FOREACH(ptr, server_items.head)
517 >  DLINK_FOREACH(node, server_items.head)
518    {
519 <    conf = ptr->data;
519 >    struct MaskItem *conf = node->data;
520  
521      if (match(conf->name, name) || match(conf->host, host))
522        continue;
523  
524      attach_conf(client_p, conf);
525 <    return -1;
525 >    return 1;
526    }
527  
528    return 0;
# Line 772 | Line 540 | attach_connect_block(struct Client *clie
540   struct MaskItem *
541   find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
542   {
543 <  dlink_node *ptr;
776 <  struct MaskItem* conf;
543 >  dlink_node *node = NULL;
544  
545 <  DLINK_FOREACH(ptr, list->head)
545 >  DLINK_FOREACH(node, list->head)
546    {
547 <    conf = ptr->data;
547 >    struct MaskItem *conf = node->data;
548  
549      if (conf->type == type)
550      {
551 <      if (conf->name && (!irccmp(conf->name, name) ||
552 <                         !match(conf->name, name)))
786 <      return conf;
551 >      if (conf->name && !irccmp(conf->name, name))
552 >        return conf;
553      }
554    }
555  
556    return NULL;
557   }
558  
793 /* map_to_list()
794 *
795 * inputs       - ConfType conf
796 * output       - pointer to dlink_list to use
797 * side effects - none
798 */
799 static dlink_list *
800 map_to_list(enum maskitem_type type)
801 {
802  switch(type)
803  {
804  case CONF_XLINE:
805    return(&xconf_items);
806    break;
807  case CONF_ULINE:
808    return(&uconf_items);
809    break;
810  case CONF_NRESV:
811    return(&nresv_items);
812    break;
813  case CONF_CRESV:
814    return(&cresv_items);
815  case CONF_OPER:
816    return(&oconf_items);
817    break;
818  case CONF_SERVER:
819    return(&server_items);
820    break;
821  case CONF_SERVICE:
822    return(&service_items);
823    break;
824  case CONF_CLUSTER:
825    return(&cluster_items);
826    break;
827  default:
828    return NULL;
829  }
830 }
831
559   /* find_matching_name_conf()
560   *
561   * inputs       - type of link list to look in
# Line 843 | Line 570 | struct MaskItem *
570   find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
571                          const char *host, unsigned int flags)
572   {
573 <  dlink_node *ptr=NULL;
574 <  struct MaskItem *conf=NULL;
575 <  dlink_list *list_p = map_to_list(type);
573 >  dlink_node *node = NULL;
574 >  dlink_list *list = map_to_list(type);
575 >  struct MaskItem *conf = NULL;
576  
577    switch (type)
578    {
579    case CONF_SERVICE:
580 <    DLINK_FOREACH(ptr, list_p->head)
580 >    DLINK_FOREACH(node, list->head)
581      {
582 <      conf = ptr->data;
582 >      conf = node->data;
583  
584        if (EmptyString(conf->name))
585          continue;
586 <      if ((name != NULL) && !irccmp(name, conf->name))
586 >      if (name && !irccmp(name, conf->name))
587          return conf;
588      }
589      break;
590  
591    case CONF_XLINE:
592 <  case CONF_ULINE:
592 >  case CONF_SHARED:
593    case CONF_NRESV:
594    case CONF_CRESV:
595 <    DLINK_FOREACH(ptr, list_p->head)
595 >    DLINK_FOREACH(node, list->head)
596      {
597 <      conf = ptr->data;
597 >      conf = node->data;
598  
599        if (EmptyString(conf->name))
600          continue;
601 <      if ((name != NULL) && !match(conf->name, name))
601 >      if (name && !match(conf->name, name))
602        {
603          if ((user == NULL && (host == NULL)))
604            return conf;
# Line 886 | Line 613 | find_matching_name_conf(enum maskitem_ty
613        break;
614  
615    case CONF_SERVER:
616 <    DLINK_FOREACH(ptr, list_p->head)
616 >    DLINK_FOREACH(node, list->head)
617      {
618 <      conf = ptr->data;
618 >      conf = node->data;
619  
620 <      if ((name != NULL) && !match(name, conf->name))
620 >      if (name && !match(name, conf->name))
621          return conf;
622 <      else if ((host != NULL) && !match(host, conf->host))
622 >      if (host && !match(host, conf->host))
623          return conf;
624      }
625      break;
# Line 916 | Line 643 | struct MaskItem *
643   find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
644                       const char *user, const char *host)
645   {
646 <  dlink_node *ptr = NULL;
647 <  struct MaskItem *conf;
648 <  dlink_list *list_p = map_to_list(type);
646 >  dlink_node *node = NULL;
647 >  dlink_list *list = map_to_list(type);
648 >  struct MaskItem *conf = NULL;
649  
650    switch(type)
651    {
652    case CONF_XLINE:
653 <  case CONF_ULINE:
653 >  case CONF_SHARED:
654    case CONF_NRESV:
655    case CONF_CRESV:
656  
657 <    DLINK_FOREACH(ptr, list_p->head)
657 >    DLINK_FOREACH(node, list->head)
658      {
659 <      conf = ptr->data;
659 >      conf = node->data;
660  
661        if (EmptyString(conf->name))
662          continue;
# Line 947 | Line 674 | find_exact_name_conf(enum maskitem_type
674      break;
675  
676    case CONF_OPER:
677 <    DLINK_FOREACH(ptr, list_p->head)
677 >    DLINK_FOREACH(node, list->head)
678      {
679 <      conf = ptr->data;
679 >      conf = node->data;
680  
681        if (EmptyString(conf->name))
682          continue;
# Line 970 | Line 697 | find_exact_name_conf(enum maskitem_type
697                    return conf;
698                break;
699              case HM_IPV4:
700 <              if (who->localClient->aftype == AF_INET)
701 <                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
700 >              if (who->connection->aftype == AF_INET)
701 >                if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
702                    if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
703                      return conf;
704                break;
978 #ifdef IPV6
705              case HM_IPV6:
706 <              if (who->localClient->aftype == AF_INET6)
707 <                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
706 >              if (who->connection->aftype == AF_INET6)
707 >                if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
708                    if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
709                      return conf;
710                break;
985 #endif
711              default:
712                assert(0);
713            }
# Line 993 | Line 718 | find_exact_name_conf(enum maskitem_type
718      break;
719  
720    case CONF_SERVER:
721 <    DLINK_FOREACH(ptr, list_p->head)
721 >    DLINK_FOREACH(node, list->head)
722      {
723 <      conf = ptr->data;
723 >      conf = node->data;
724  
725        if (EmptyString(conf->name))
726          continue;
# Line 1020 | Line 745 | find_exact_name_conf(enum maskitem_type
745    return NULL;
746   }
747  
1023 /* rehash()
1024 *
1025 * Actual REHASH service routine. Called with sig == 0 if it has been called
1026 * as a result of an operator issuing this command, else assume it has been
1027 * called as a result of the server receiving a HUP signal.
1028 */
1029 int
1030 rehash(int sig)
1031 {
1032  if (sig)
1033    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1034                         "Got signal SIGHUP, reloading configuration file(s)");
1035
1036  restart_resolver();
1037
1038  /* don't close listeners until we know we can go ahead with the rehash */
1039
1040  /* Check to see if we magically got(or lost) IPv6 support */
1041  check_can_use_v6();
1042
1043  read_conf_files(0);
1044
1045  if (ServerInfo.description)
1046    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1047
1048  load_conf_modules();
1049
1050  rehashed_klines = 1;
1051
1052  return 0;
1053 }
1054
748   /* set_default_conf()
749   *
750   * inputs       - NONE
# Line 1070 | Line 763 | set_default_conf(void)
763    assert(class_default == class_get_list()->tail->data);
764  
765   #ifdef HAVE_LIBCRYPTO
766 <  ServerInfo.rsa_private_key = NULL;
767 <  ServerInfo.rsa_private_key_file = NULL;
766 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
767 >  {
768 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
769 >
770 >    if (key)
771 >    {
772 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
773 >      EC_KEY_free(key);
774 >    }
775 >  }
776 >
777 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
778 > #endif
779 >
780 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
781 >  ConfigServerInfo.message_digest_algorithm = EVP_sha256();
782   #endif
783  
784 <  /* ServerInfo.name is not rehashable */
785 <  /* ServerInfo.name = ServerInfo.name; */
786 <  ServerInfo.description = NULL;
787 <  ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
788 <  ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
789 <
790 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
791 <  ServerInfo.specific_ipv4_vhost = 0;
792 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
793 <  ServerInfo.specific_ipv6_vhost = 0;
794 <
795 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
1089 <  ServerInfo.max_nick_length = 9;
1090 <  ServerInfo.max_topic_length = 80;
1091 <
1092 <  ServerInfo.hub = 0;
1093 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
1094 <  ServerInfo.dns_host.sin_port = 0;
1095 <  AdminInfo.name = NULL;
1096 <  AdminInfo.email = NULL;
1097 <  AdminInfo.description = NULL;
784 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
785 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
786 >
787 >  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
788 >  ConfigServerInfo.specific_ipv4_vhost = 0;
789 >  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
790 >  ConfigServerInfo.specific_ipv6_vhost = 0;
791 >
792 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
793 >  ConfigServerInfo.max_nick_length = 9;
794 >  ConfigServerInfo.max_topic_length = 80;
795 >  ConfigServerInfo.hub = 0;
796  
797    log_del_all();
798  
799 <  ConfigLoggingEntry.use_logging = 1;
799 >  ConfigLog.use_logging = 1;
800  
801    ConfigChannel.disable_fake_channels = 0;
802    ConfigChannel.invite_client_count = 10;
803    ConfigChannel.invite_client_time = 300;
804 +  ConfigChannel.invite_delay_channel = 5;
805    ConfigChannel.knock_client_count = 1;
806    ConfigChannel.knock_client_time = 300;
807    ConfigChannel.knock_delay_channel = 60;
808 <  ConfigChannel.max_chans_per_user = 25;
1110 <  ConfigChannel.max_chans_per_oper = 50;
808 >  ConfigChannel.max_channels = 25;
809    ConfigChannel.max_bans = 25;
810 <  ConfigChannel.default_split_user_count = 0;
811 <  ConfigChannel.default_split_server_count = 0;
1114 <  ConfigChannel.no_join_on_split = 0;
1115 <  ConfigChannel.no_create_on_split = 0;
810 >  ConfigChannel.default_join_flood_count = 18;
811 >  ConfigChannel.default_join_flood_time = 6;
812  
813    ConfigServerHide.flatten_links = 0;
814 <  ConfigServerHide.links_delay = 300;
814 >  ConfigServerHide.flatten_links_delay = 300;
815    ConfigServerHide.hidden = 0;
816    ConfigServerHide.hide_servers = 0;
817    ConfigServerHide.hide_services = 0;
# Line 1123 | Line 819 | set_default_conf(void)
819    ConfigServerHide.hide_server_ips = 0;
820    ConfigServerHide.disable_remote_commands = 0;
821  
822 <  ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
823 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
824 <  ConfigFileEntry.cycle_on_host_change = 1;
825 <  ConfigFileEntry.glines = 0;
826 <  ConfigFileEntry.gline_time = 12 * 3600;
827 <  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
828 <  ConfigFileEntry.gline_min_cidr = 16;
829 <  ConfigFileEntry.gline_min_cidr6 = 48;
830 <  ConfigFileEntry.invisible_on_connect = 1;
831 <  ConfigFileEntry.tkline_expire_notices = 1;
832 <  ConfigFileEntry.hide_spoof_ips = 1;
833 <  ConfigFileEntry.ignore_bogus_ts = 0;
834 <  ConfigFileEntry.disable_auth = 0;
835 <  ConfigFileEntry.kill_chase_time_limit = 90;
836 <  ConfigFileEntry.default_floodcount = 8;
837 <  ConfigFileEntry.failed_oper_notice = 1;
838 <  ConfigFileEntry.dots_in_ident = 0;
839 <  ConfigFileEntry.min_nonwildcard = 4;
840 <  ConfigFileEntry.min_nonwildcard_simple = 3;
841 <  ConfigFileEntry.max_accept = 20;
842 <  ConfigFileEntry.anti_nick_flood = 0;
843 <  ConfigFileEntry.max_nick_time = 20;
844 <  ConfigFileEntry.max_nick_changes = 5;
845 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
846 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
847 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
848 <  ConfigFileEntry.warn_no_connect_block = 1;
849 <  ConfigFileEntry.stats_e_disabled = 0;
850 <  ConfigFileEntry.stats_o_oper_only = 0;
851 <  ConfigFileEntry.stats_k_oper_only = 1;  /* 1 = masked */
852 <  ConfigFileEntry.stats_i_oper_only = 1;  /* 1 = masked */
853 <  ConfigFileEntry.stats_P_oper_only = 0;
854 <  ConfigFileEntry.stats_u_oper_only = 0;
855 <  ConfigFileEntry.caller_id_wait = 60;
856 <  ConfigFileEntry.opers_bypass_callerid = 0;
857 <  ConfigFileEntry.pace_wait = 10;
858 <  ConfigFileEntry.pace_wait_simple = 1;
859 <  ConfigFileEntry.short_motd = 0;
860 <  ConfigFileEntry.ping_cookie = 0;
861 <  ConfigFileEntry.no_oper_flood = 0;
862 <  ConfigFileEntry.true_no_oper_flood = 0;
863 <  ConfigFileEntry.oper_pass_resv = 1;
864 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
865 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
866 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
867 <  ConfigFileEntry.use_egd = 0;
868 <  ConfigFileEntry.egdpool_path = NULL;
1173 <  ConfigFileEntry.throttle_time = 10;
822 >  ConfigGeneral.away_count = 2;
823 >  ConfigGeneral.away_time = 10;
824 >  ConfigGeneral.max_watch = 50;
825 >  ConfigGeneral.cycle_on_host_change = 1;
826 >  ConfigGeneral.dline_min_cidr = 16;
827 >  ConfigGeneral.dline_min_cidr6 = 48;
828 >  ConfigGeneral.kline_min_cidr = 16;
829 >  ConfigGeneral.kline_min_cidr6 = 48;
830 >  ConfigGeneral.invisible_on_connect = 1;
831 >  ConfigGeneral.tkline_expire_notices = 1;
832 >  ConfigGeneral.ignore_bogus_ts = 0;
833 >  ConfigGeneral.disable_auth = 0;
834 >  ConfigGeneral.kill_chase_time_limit = 90;
835 >  ConfigGeneral.default_floodcount = 8;
836 >  ConfigGeneral.failed_oper_notice = 1;
837 >  ConfigGeneral.dots_in_ident = 0;
838 >  ConfigGeneral.min_nonwildcard = 4;
839 >  ConfigGeneral.min_nonwildcard_simple = 3;
840 >  ConfigGeneral.max_accept = 50;
841 >  ConfigGeneral.anti_nick_flood = 0;
842 >  ConfigGeneral.max_nick_time = 20;
843 >  ConfigGeneral.max_nick_changes = 5;
844 >  ConfigGeneral.anti_spam_exit_message_time = 0;
845 >  ConfigGeneral.ts_warn_delta = 30;
846 >  ConfigGeneral.ts_max_delta = 600;
847 >  ConfigGeneral.warn_no_connect_block = 1;
848 >  ConfigGeneral.stats_e_disabled = 0;
849 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
850 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
851 >  ConfigGeneral.stats_o_oper_only = 1;
852 >  ConfigGeneral.stats_m_oper_only = 1;
853 >  ConfigGeneral.stats_P_oper_only = 0;
854 >  ConfigGeneral.stats_u_oper_only = 0;
855 >  ConfigGeneral.caller_id_wait = 60;
856 >  ConfigGeneral.opers_bypass_callerid = 0;
857 >  ConfigGeneral.pace_wait = 10;
858 >  ConfigGeneral.pace_wait_simple = 1;
859 >  ConfigGeneral.short_motd = 0;
860 >  ConfigGeneral.ping_cookie = 0;
861 >  ConfigGeneral.no_oper_flood = 0;
862 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
863 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
864 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
865 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
866 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
867 >  ConfigGeneral.throttle_count = 1;
868 >  ConfigGeneral.throttle_time = 1;
869   }
870  
871   static void
872   validate_conf(void)
873   {
874 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
875 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1181 <
1182 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1183 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1184 <
1185 <  if (ServerInfo.network_name == NULL)
1186 <    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1187 <
1188 <  if (ServerInfo.network_desc == NULL)
1189 <    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1190 <
1191 <  if (ConfigFileEntry.service_name == NULL)
1192 <    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
874 >  if (EmptyString(ConfigServerInfo.network_name))
875 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
876  
877 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
877 >  if (EmptyString(ConfigServerInfo.network_desc))
878 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
879   }
880  
881   /* read_conf()
# Line 1218 | Line 902 | read_conf(FILE *file)
902    class_delete_marked();  /* Delete unused classes that are marked for deletion */
903   }
904  
905 + /* conf_rehash()
906 + *
907 + * Actual REHASH service routine. Called with sig == 0 if it has been called
908 + * as a result of an operator issuing this command, else assume it has been
909 + * called as a result of the server receiving a HUP signal.
910 + */
911 + void
912 + conf_rehash(int sig)
913 + {
914 +  if (sig)
915 +    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
916 +                         "Got signal SIGHUP, reloading configuration file(s)");
917 +
918 +  restart_resolver();
919 +
920 +  /* don't close listeners until we know we can go ahead with the rehash */
921 +
922 +  read_conf_files(0);
923 +
924 +  load_conf_modules();
925 +  check_conf_klines();
926 + }
927 +
928   /* lookup_confhost()
929   *
930   * start DNS lookups of all hostnames in the conf
# Line 1265 | Line 972 | lookup_confhost(struct MaskItem *conf)
972   int
973   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
974   {
975 <  struct ip_entry *ip_found;
976 <  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;
975 >  struct ip_entry *ip_found = NULL;
976 >  const struct MaskItem *conf = find_dline_conf(addr, aftype);
977  
978    if (conf)
979 +  {
980 +    /* DLINE exempt also gets you out of static limits/pacing... */
981 +    if (conf->type == CONF_EXEMPT)
982 +      return 0;
983      return BANNED_CLIENT;
984 +  }
985  
986 <  ip_found = find_or_add_ip(addr);
986 >  ip_found = ipcache_find_or_add_address(addr);
987  
988 <  if ((CurrentTime - ip_found->last_attempt) <
1281 <      ConfigFileEntry.throttle_time)
988 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
989    {
990 <    ip_found->last_attempt = CurrentTime;
991 <    return TOO_FAST;
990 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
991 >      return TOO_FAST;
992 >
993 >    ++ip_found->connection_count;
994    }
995 +  else
996 +    ip_found->connection_count = 1;
997  
998    ip_found->last_attempt = CurrentTime;
999    return 0;
1000   }
1001  
1291 /* cleanup_tklines()
1292 *
1293 * inputs       - NONE
1294 * output       - NONE
1295 * side effects - call function to expire temporary k/d lines
1296 *                This is an event started off in ircd.c
1297 */
1298 void
1299 cleanup_tklines(void *notused)
1300 {
1301  hostmask_expire_temporary();
1302  expire_tklines(&xconf_items);
1303  expire_tklines(&nresv_items);
1304  expire_tklines(&cresv_items);
1305 }
1306
1002   /* expire_tklines()
1003   *
1004   * inputs       - tkline list pointer
# Line 1311 | Line 1006 | cleanup_tklines(void *notused)
1006   * side effects - expire tklines
1007   */
1008   static void
1009 < expire_tklines(dlink_list *tklist)
1009 > expire_tklines(dlink_list *list)
1010   {
1011 <  dlink_node *ptr = NULL, *ptr_next = NULL;
1317 <  struct MaskItem *conf = NULL;
1011 >  dlink_node *node = NULL, *node_next = NULL;
1012  
1013 <  DLINK_FOREACH_SAFE(ptr, ptr_next, tklist->head)
1013 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
1014    {
1015 <    conf = ptr->data;
1015 >    struct MaskItem *conf = node->data;
1016  
1017      if (!conf->until || conf->until > CurrentTime)
1018        continue;
1019  
1020 <    if (conf->type == CONF_XLINE)
1021 <    {
1022 <      if (ConfigFileEntry.tkline_expire_notices)
1023 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1330 <                               "Temporary X-line for [%s] expired", conf->name);
1331 <      conf_free(conf);
1332 <    }
1333 <    else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1334 <    {
1335 <      if (ConfigFileEntry.tkline_expire_notices)
1336 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1337 <                               "Temporary RESV for [%s] expired", conf->name);
1338 <      conf_free(conf);
1339 <    }
1020 >    if (ConfigGeneral.tkline_expire_notices)
1021 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary %s for [%s] expired",
1022 >                           (conf->type == CONF_XLINE) ? "X-line" : "RESV", conf->name);
1023 >    conf_free(conf);
1024    }
1025   }
1026  
1027 + /* cleanup_tklines()
1028 + *
1029 + * inputs       - NONE
1030 + * output       - NONE
1031 + * side effects - call function to expire temporary k/d lines
1032 + *                This is an event started off in ircd.c
1033 + */
1034 + void
1035 + cleanup_tklines(void *unused)
1036 + {
1037 +  hostmask_expire_temporary();
1038 +  expire_tklines(&gecos_items);
1039 +  expire_tklines(&nresv_items);
1040 +  expire_tklines(&cresv_items);
1041 + }
1042 +
1043   /* oper_privs_as_string()
1044   *
1045   * inputs        - pointer to client_p
# Line 1352 | Line 1052 | static const struct oper_privs
1052    const unsigned char c;
1053   } flag_list[] = {
1054    { OPER_FLAG_ADMIN,          'A' },
1055 <  { OPER_FLAG_REMOTEBAN,      'B' },
1056 <  { OPER_FLAG_DIE,            'D' },
1057 <  { OPER_FLAG_GLINE,          'G' },
1058 <  { OPER_FLAG_REHASH,         'H' },
1059 <  { OPER_FLAG_K,              'K' },
1060 <  { OPER_FLAG_KILL,           'N' },
1061 <  { OPER_FLAG_KILL_REMOTE,    'O' },
1062 <  { OPER_FLAG_CONNECT,        'P' },
1063 <  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1064 <  { OPER_FLAG_SQUIT,          'R' },
1065 <  { OPER_FLAG_SQUIT_REMOTE,   'S' },
1066 <  { OPER_FLAG_UNKLINE,        'U' },
1067 <  { OPER_FLAG_XLINE,          'X' },
1055 >  { OPER_FLAG_CLOSE,          'B' },
1056 >  { OPER_FLAG_CONNECT,        'C' },
1057 >  { OPER_FLAG_CONNECT_REMOTE, 'D' },
1058 >  { OPER_FLAG_DIE,            'E' },
1059 >  { OPER_FLAG_DLINE,          'F' },
1060 >  { OPER_FLAG_GLOBOPS,        'G' },
1061 >  { OPER_FLAG_JOIN_RESV,      'H' },
1062 >  { OPER_FLAG_KILL,           'I' },
1063 >  { OPER_FLAG_KILL_REMOTE,    'J' },
1064 >  { OPER_FLAG_KLINE,          'K' },
1065 >  { OPER_FLAG_LOCOPS,         'L' },
1066 >  { OPER_FLAG_MODULE,         'M' },
1067 >  { OPER_FLAG_NICK_RESV,      'N' },
1068 >  { OPER_FLAG_OPME,           'O' },
1069 >  { OPER_FLAG_REHASH,         'P' },
1070 >  { OPER_FLAG_REMOTEBAN,      'Q' },
1071 >  { OPER_FLAG_RESTART,        'R' },
1072 >  { OPER_FLAG_RESV,           'S' },
1073 >  { OPER_FLAG_SET,            'T' },
1074 >  { OPER_FLAG_SQUIT,          'U' },
1075 >  { OPER_FLAG_SQUIT_REMOTE,   'V' },
1076 >  { OPER_FLAG_UNDLINE,        'W' },
1077 >  { OPER_FLAG_UNKLINE,        'X' },
1078 >  { OPER_FLAG_UNRESV,         'Y' },
1079 >  { OPER_FLAG_UNXLINE,        'Z' },
1080 >  { OPER_FLAG_WALLOPS,        'a' },
1081 >  { OPER_FLAG_XLINE,          'b' },
1082    { 0, '\0' }
1083   };
1084  
1085 < char *
1085 > const char *
1086   oper_privs_as_string(const unsigned int port)
1087   {
1088    static char privs_out[IRCD_BUFSIZE];
1089    char *privs_ptr = privs_out;
1090  
1091    for (const struct oper_privs *opriv = flag_list; opriv->flag; ++opriv)
1378  {
1092      if (port & opriv->flag)
1093        *privs_ptr++ = opriv->c;
1094 <    else
1095 <      *privs_ptr++ = ToLower(opriv->c);
1096 <  }
1094 >
1095 >  if (privs_ptr == privs_out)
1096 >    *privs_ptr++ = '0';
1097  
1098    *privs_ptr = '\0';
1099  
# Line 1388 | Line 1101 | oper_privs_as_string(const unsigned int
1101   }
1102  
1103   /*
1104 < * Input: A client to find the active oper{} name for.
1104 > * Input: A client to find the active operator {} name for.
1105   * Output: The nick!user@host{oper} of the oper.
1106   *         "oper" is server name for remote opers
1107   * Side effects: None.
# Line 1396 | Line 1109 | oper_privs_as_string(const unsigned int
1109   const char *
1110   get_oper_name(const struct Client *client_p)
1111   {
1112 <  const dlink_node *cnode = NULL;
1113 <  /* +5 for !,@,{,} and null */
1114 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1112 >  static char buffer[IRCD_BUFSIZE];
1113 >
1114 >  if (IsServer(client_p))
1115 >    return client_p->name;
1116  
1117    if (MyConnect(client_p))
1118    {
1119 <    if ((cnode = client_p->localClient->confs.head))
1119 >    const dlink_node *const node = client_p->connection->confs.head;
1120 >
1121 >    if (node)
1122      {
1123 <      const struct MaskItem *conf = cnode->data;
1123 >      const struct MaskItem *const conf = node->data;
1124  
1125 <      if (IsConfOperator(conf))
1125 >      if (conf->type == CONF_OPER)
1126        {
1127          snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1128                   client_p->username, client_p->host, conf->name);
# Line 1414 | Line 1130 | get_oper_name(const struct Client *clien
1130        }
1131      }
1132  
1133 <    /* Probably should assert here for now. If there is an oper out there
1134 <     * with no oper{} conf attached, it would be good for us to know...
1133 >    /*
1134 >     * Probably should assert here for now. If there is an oper out there
1135 >     * with no operator {} conf attached, it would be good for us to know...
1136       */
1137 <    assert(0); /* Oper without oper conf! */
1137 >    assert(0);  /* Oper without oper conf! */
1138    }
1139  
1140    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
# Line 1425 | Line 1142 | get_oper_name(const struct Client *clien
1142    return buffer;
1143   }
1144  
1145 + /* clear_out_old_conf()
1146 + *
1147 + * inputs       - none
1148 + * output       - none
1149 + * side effects - Clear out the old configuration
1150 + */
1151 + static void
1152 + clear_out_old_conf(void)
1153 + {
1154 +  dlink_node *node = NULL, *node_next = NULL;
1155 +  dlink_list *free_items [] = {
1156 +    &server_items,   &operator_items,
1157 +     &shared_items,   &gecos_items,
1158 +     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1159 +  };
1160 +
1161 +  dlink_list ** iterator = free_items; /* C is dumb */
1162 +
1163 +  /* We only need to free anything allocated by yyparse() here.
1164 +   * Resetting structs, etc, is taken care of by set_default_conf().
1165 +   */
1166 +
1167 +  for (; *iterator; iterator++)
1168 +  {
1169 +    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1170 +    {
1171 +      struct MaskItem *conf = node->data;
1172 +
1173 +      conf->active = 0;
1174 +
1175 +      if (!IsConfDatabase(conf))
1176 +      {
1177 +        dlinkDelete(&conf->node, *iterator);
1178 +
1179 +        if (!conf->ref_count)
1180 +          conf_free(conf);
1181 +      }
1182 +    }
1183 +  }
1184 +
1185 +  motd_clear();
1186 +
1187 +  /*
1188 +   * Don't delete the class table, rather mark all entries for deletion.
1189 +   * The table is cleaned up by class_delete_marked. - avalon
1190 +   */
1191 +  class_mark_for_deletion();
1192 +
1193 +  clear_out_address_conf();
1194 +
1195 +  /* Clean out module paths */
1196 +  mod_clear_paths();
1197 +
1198 +  pseudo_clear();
1199 +
1200 +  /* Clean out ConfigServerInfo */
1201 +  MyFree(ConfigServerInfo.description);
1202 +  ConfigServerInfo.description = NULL;
1203 +  MyFree(ConfigServerInfo.network_name);
1204 +  ConfigServerInfo.network_name = NULL;
1205 +  MyFree(ConfigServerInfo.network_desc);
1206 +  ConfigServerInfo.network_desc = NULL;
1207 + #ifdef HAVE_LIBCRYPTO
1208 +  if (ConfigServerInfo.rsa_private_key)
1209 +  {
1210 +    RSA_free(ConfigServerInfo.rsa_private_key);
1211 +    ConfigServerInfo.rsa_private_key = NULL;
1212 +  }
1213 +
1214 +  MyFree(ConfigServerInfo.rsa_private_key_file);
1215 +  ConfigServerInfo.rsa_private_key_file = NULL;
1216 + #endif
1217 +
1218 +  /* Clean out ConfigAdminInfo */
1219 +  MyFree(ConfigAdminInfo.name);
1220 +  ConfigAdminInfo.name = NULL;
1221 +  MyFree(ConfigAdminInfo.email);
1222 +  ConfigAdminInfo.email = NULL;
1223 +  MyFree(ConfigAdminInfo.description);
1224 +  ConfigAdminInfo.description = NULL;
1225 +
1226 +  MyFree(ConfigServerHide.flatten_links_file);
1227 +  ConfigServerHide.flatten_links_file = NULL;
1228 +
1229 +  /* Clean out listeners */
1230 +  listener_close_marked();
1231 + }
1232 +
1233   /* read_conf_files()
1234   *
1235   * inputs       - cold start YES or NO
# Line 1439 | Line 1244 | read_conf_files(int cold)
1244    char chanlimit[IRCD_BUFSIZE] = "";
1245  
1246    conf_parser_ctx.boot = cold;
1247 <  filename = ConfigFileEntry.configfile;
1247 >  filename = ConfigGeneral.configfile;
1248  
1249    /* We need to know the initial filename for the yyerror() to report
1250       FIXME: The full path is in conffilenamebuf first time since we
1251 <             dont know anything else
1251 >             don't know anything else
1252  
1253       - Gozem 2002-07-21
1254    */
# Line 1455 | Line 1260 | read_conf_files(int cold)
1260      {
1261        ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1262             filename, strerror(errno));
1263 <      exit(-1);
1263 >      exit(EXIT_FAILURE);
1264      }
1265      else
1266      {
1267 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1267 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1268                             "Unable to read configuration file '%s': %s",
1269                             filename, strerror(errno));
1270        return;
# Line 1474 | Line 1279 | read_conf_files(int cold)
1279  
1280    log_reopen_all();
1281  
1282 <  add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1283 <  add_isupport("NETWORK", ServerInfo.network_name, -1);
1282 >  isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1283 >  isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1284  
1285 <  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1286 <  add_isupport("MAXLIST", chanmodes, -1);
1287 <  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1288 <  add_isupport("CHANTYPES", "#", -1);
1289 <
1290 <  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1291 <           ConfigChannel.max_chans_per_user);
1292 <  add_isupport("CHANLIMIT", chanlimit, -1);
1293 <  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1294 <  add_isupport("CHANNELLEN", NULL, CHANNELLEN);
1295 <  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1296 <  add_isupport("CHANMODES", chanmodes, -1);
1285 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1286 >  isupport_add("MAXLIST", chanmodes, -1);
1287 >  isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1288 >  isupport_add("CHANTYPES", "#", -1);
1289 >
1290 >  snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1291 >           ConfigChannel.max_channels);
1292 >  isupport_add("CHANLIMIT", chanlimit, -1);
1293 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1294 >  isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1295 >  isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1296 >  isupport_add("CHANMODES", chanmodes, -1);
1297  
1298    /*
1299     * message_locale may have changed.  rebuild isupport since it relies
1300     * on strlen(form_str(RPL_ISUPPORT))
1301     */
1302 <  rebuild_isupport_message_line();
1498 < }
1499 <
1500 < /* clear_out_old_conf()
1501 < *
1502 < * inputs       - none
1503 < * output       - none
1504 < * side effects - Clear out the old configuration
1505 < */
1506 < static void
1507 < clear_out_old_conf(void)
1508 < {
1509 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1510 <  struct MaskItem *conf;
1511 <  dlink_list *free_items [] = {
1512 <    &server_items,   &oconf_items,
1513 <     &uconf_items,   &xconf_items,
1514 <     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1515 <  };
1516 <
1517 <  dlink_list ** iterator = free_items; /* C is dumb */
1518 <
1519 <  /* We only need to free anything allocated by yyparse() here.
1520 <   * Resetting structs, etc, is taken care of by set_default_conf().
1521 <   */
1522 <
1523 <  for (; *iterator != NULL; iterator++)
1524 <  {
1525 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1526 <    {
1527 <      conf = ptr->data;
1528 <
1529 <      dlinkDelete(&conf->node, map_to_list(conf->type));
1530 <
1531 <      /* XXX This is less than pretty */
1532 <      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1533 <      {
1534 <        if (!conf->ref_count)
1535 <          conf_free(conf);
1536 <      }
1537 <      else if (conf->type == CONF_XLINE)
1538 <      {
1539 <        if (!conf->until)
1540 <          conf_free(conf);
1541 <      }
1542 <      else
1543 <        conf_free(conf);
1544 <    }
1545 <  }
1546 <
1547 <  motd_clear();
1548 <
1549 <  /*
1550 <   * don't delete the class table, rather mark all entries
1551 <   * for deletion. The table is cleaned up by class_delete_marked. - avalon
1552 <   */
1553 <  class_mark_for_deletion();
1554 <
1555 <  clear_out_address_conf();
1556 <
1557 <  /* clean out module paths */
1558 <  mod_clear_paths();
1559 <
1560 <  /* clean out ServerInfo */
1561 <  MyFree(ServerInfo.description);
1562 <  ServerInfo.description = NULL;
1563 <  MyFree(ServerInfo.network_name);
1564 <  ServerInfo.network_name = NULL;
1565 <  MyFree(ServerInfo.network_desc);
1566 <  ServerInfo.network_desc = NULL;
1567 <  MyFree(ConfigFileEntry.egdpool_path);
1568 <  ConfigFileEntry.egdpool_path = NULL;
1569 < #ifdef HAVE_LIBCRYPTO
1570 <  if (ServerInfo.rsa_private_key)
1571 <  {
1572 <    RSA_free(ServerInfo.rsa_private_key);
1573 <    ServerInfo.rsa_private_key = NULL;
1574 <  }
1575 <
1576 <  MyFree(ServerInfo.rsa_private_key_file);
1577 <  ServerInfo.rsa_private_key_file = NULL;
1578 <
1579 <  if (ServerInfo.server_ctx)
1580 <    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1581 <                                               SSL_OP_NO_SSLv3|
1582 <                                               SSL_OP_NO_TLSv1);
1583 <  if (ServerInfo.client_ctx)
1584 <    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1585 <                                               SSL_OP_NO_SSLv3|
1586 <                                               SSL_OP_NO_TLSv1);
1587 < #endif
1588 <
1589 <  /* clean out AdminInfo */
1590 <  MyFree(AdminInfo.name);
1591 <  AdminInfo.name = NULL;
1592 <  MyFree(AdminInfo.email);
1593 <  AdminInfo.email = NULL;
1594 <  MyFree(AdminInfo.description);
1595 <  AdminInfo.description = NULL;
1596 <
1597 <  /* clean out listeners */
1598 <  close_listeners();
1599 <
1600 <  /* clean out general */
1601 <  MyFree(ConfigFileEntry.service_name);
1602 <  ConfigFileEntry.service_name = NULL;
1302 >  isupport_rebuild();
1303   }
1304  
1305   /* conf_add_class_to_conf()
# Line 1609 | Line 1309 | clear_out_old_conf(void)
1309   * side effects - Add a class pointer to a conf
1310   */
1311   void
1312 < conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1312 > conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1313   {
1314 <  if (class_name == NULL)
1314 >  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1315    {
1316      conf->class = class_default;
1317  
1318 <    if (conf->type == CONF_CLIENT)
1319 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1620 <                           "Warning *** Defaulting to default class for %s@%s",
1621 <                           conf->user, conf->host);
1622 <    else
1623 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1624 <                           "Warning *** Defaulting to default class for %s",
1625 <                           conf->name);
1626 <  }
1627 <  else
1628 <    conf->class = class_find(class_name, 1);
1629 <
1630 <  if (conf->class == NULL)
1631 <  {
1632 <    if (conf->type == CONF_CLIENT)
1633 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1318 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1319 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1320                             "Warning *** Defaulting to default class for %s@%s",
1321                             conf->user, conf->host);
1322      else
1323 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1323 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1324                             "Warning *** Defaulting to default class for %s",
1325                             conf->name);
1640    conf->class = class_default;
1326    }
1327   }
1328  
# Line 1656 | Line 1341 | yyerror(const char *msg)
1341      return;
1342  
1343    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1344 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1344 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1345                         "\"%s\", line %u: %s: %s",
1346                         conffilebuf, lineno + 1, msg, newlinebuf);
1347    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
# Line 1669 | Line 1354 | conf_error_report(const char *msg)
1354    char newlinebuf[IRCD_BUFSIZE];
1355  
1356    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1357 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1357 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1358                         "\"%s\", line %u: %s: %s",
1359                         conffilebuf, lineno + 1, msg, newlinebuf);
1360    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
# Line 1704 | Line 1389 | valid_tkline(const char *data, const int
1389  
1390    /*
1391     * In the degenerate case where oper does a /quote kline 0 user@host :reason
1392 <   * i.e. they specifically use 0, I am going to return 1 instead
1393 <   * as a return value of non-zero is used to flag it as a temporary kline
1392 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1393 >   * value of non-zero is used to flag it as a temporary kline
1394     */
1395    if (result == 0)
1396      result = 1;
# Line 1720 | Line 1405 | valid_tkline(const char *data, const int
1405    if (result > MAX_TDKLINE_TIME)
1406      result = MAX_TDKLINE_TIME;
1407  
1408 <  result = result * 60;  /* turn it into seconds */
1408 >  result = result * 60;  /* Turn it into seconds */
1409  
1410    return result;
1411   }
# Line 1736 | Line 1421 | valid_wild_card_simple(const char *data)
1421   {
1422    const unsigned char *p = (const unsigned char *)data;
1423    unsigned char tmpch = '\0';
1424 <  int nonwild = 0;
1424 >  unsigned int nonwild = 0, wild = 0;
1425  
1426    while ((tmpch = *p++))
1427    {
1428 <    if (tmpch == '\\')
1428 >    if (tmpch == '\\' && *p)
1429      {
1430        ++p;
1431 <      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1431 >      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1432          return 1;
1433      }
1434      else if (!IsMWildChar(tmpch))
1435      {
1436 <      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1436 >      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1437          return 1;
1438      }
1439 +    else
1440 +      ++wild;
1441    }
1442  
1443 <  return 0;
1443 >  return !wild;
1444   }
1445  
1446   /* valid_wild_card()
# Line 1765 | Line 1452 | valid_wild_card_simple(const char *data)
1452   * side effects - NOTICE is given to source_p if warn is 1
1453   */
1454   int
1455 < valid_wild_card(struct Client *source_p, int warn, int count, ...)
1455 > valid_wild_card(struct Client *source_p, int count, ...)
1456   {
1457 <  char tmpch;
1458 <  int nonwild = 0;
1457 >  unsigned char tmpch = '\0';
1458 >  unsigned int nonwild = 0;
1459    va_list args;
1460  
1461    /*
# Line 1787 | Line 1474 | valid_wild_card(struct Client *source_p,
1474  
1475    while (count--)
1476    {
1477 <    const char *p = va_arg(args, const char *);
1477 >    const unsigned char *p = va_arg(args, const unsigned char *);
1478      if (p == NULL)
1479        continue;
1480  
# Line 1799 | Line 1486 | valid_wild_card(struct Client *source_p,
1486           * If we find enough non-wild characters, we can
1487           * break - no point in searching further.
1488           */
1489 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1489 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1490          {
1491            va_end(args);
1492            return 1;
# Line 1808 | Line 1495 | valid_wild_card(struct Client *source_p,
1495      }
1496    }
1497  
1498 <  if (warn)
1498 >  if (IsClient(source_p))
1499      sendto_one_notice(source_p, &me,
1500 <                      ":Please include at least %d non-wildcard characters with the mask",
1501 <                      ConfigFileEntry.min_nonwildcard);
1500 >                      ":Please include at least %u non-wildcard characters with the mask",
1501 >                      ConfigGeneral.min_nonwildcard);
1502    va_end(args);
1503    return 0;
1504   }
1505  
1506 + /* find_user_host()
1507 + *
1508 + * inputs       - pointer to client placing kline
1509 + *              - pointer to user_host_or_nick
1510 + *              - pointer to user buffer
1511 + *              - pointer to host buffer
1512 + * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1513 + * side effects -
1514 + */
1515 + static int
1516 + find_user_host(struct Client *source_p, char *user_host_or_nick,
1517 +               char *luser, char *lhost)
1518 + {
1519 +  struct Client *target_p = NULL;
1520 +  char *hostp = NULL;
1521 +
1522 +  if (lhost == NULL)
1523 +  {
1524 +    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1525 +    return 1;
1526 +  }
1527 +
1528 +  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1529 +  {
1530 +    /* Explicit user@host mask given */
1531 +    if (hostp)                            /* I'm a little user@host */
1532 +    {
1533 +      *(hostp++) = '\0';                       /* short and squat */
1534 +
1535 +      if (*user_host_or_nick)
1536 +        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1537 +      else
1538 +        strcpy(luser, "*");
1539 +
1540 +      if (*hostp)
1541 +        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1542 +      else
1543 +        strcpy(lhost, "*");
1544 +    }
1545 +    else
1546 +    {
1547 +      luser[0] = '*';             /* no @ found, assume its *@somehost */
1548 +      luser[1] = '\0';
1549 +      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1550 +    }
1551 +
1552 +    return 1;
1553 +  }
1554 +  else
1555 +  {
1556 +    /* Try to find user@host mask from nick */
1557 +    /* Okay to use source_p as the first param, because source_p == client_p */
1558 +    if ((target_p =
1559 +        find_chasing(source_p, user_host_or_nick)) == NULL)
1560 +      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1561 +
1562 +    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1563 +    {
1564 +      if (IsClient(source_p))
1565 +        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1566 +      return 0;
1567 +    }
1568 +
1569 +    /*
1570 +     * Turn the "user" bit into "*user", blow away '~'
1571 +     * if found in original user name (non-idented)
1572 +     */
1573 +    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1574 +
1575 +    if (target_p->username[0] == '~')
1576 +      luser[0] = '*';
1577 +
1578 +    strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1579 +    return 1;
1580 +  }
1581 +
1582 +  return 0;
1583 + }
1584 +
1585   /* XXX should this go into a separate file ? -Dianora */
1586   /* parse_aline
1587   *
# Line 1830 | Line 1596 | valid_wild_card(struct Client *source_p,
1596   *              - pointer to target_server to parse into if non NULL
1597   *              - pointer to reason to parse into
1598   *
1599 < * output       - 1 if valid, -1 if not valid
1599 > * output       - 1 if valid, 0 if not valid
1600   * side effects - A generalised k/d/x etc. line parser,
1601   *               "ALINE [time] user@host|string [ON] target :reason"
1602   *                will parse returning a parsed user, host if
# Line 1853 | Line 1619 | parse_aline(const char *cmd, struct Clie
1619              char **target_server, char **reason)
1620   {
1621    int found_tkline_time=0;
1622 <  static char def_reason[] = CONF_NOREASON;
1622 >  static char default_reason[] = CONF_NOREASON;
1623    static char user[USERLEN*4+1];
1624    static char host[HOSTLEN*4+1];
1625  
# Line 1862 | Line 1628 | parse_aline(const char *cmd, struct Clie
1628  
1629    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1630  
1631 <  if (found_tkline_time != 0)
1631 >  if (found_tkline_time)
1632    {
1633      parv++;
1634      parc--;
1635  
1636 <    if (tkline_time != NULL)
1636 >    if (tkline_time)
1637        *tkline_time = found_tkline_time;
1638      else
1639      {
1640        sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1641 <      return -1;
1641 >      return 0;
1642      }
1643    }
1644  
1645    if (parc == 0)
1646    {
1647      sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1648 <    return -1;
1648 >    return 0;
1649    }
1650  
1651    if (h_p == NULL)
1652      *up_p = *parv;
1653    else
1654    {
1655 <    if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1656 <      return -1;
1655 >    if (find_user_host(source_p, *parv, user, host) == 0)
1656 >      return 0;
1657  
1658      *up_p = user;
1659      *h_p = host;
# Line 1896 | Line 1662 | parse_aline(const char *cmd, struct Clie
1662    parc--;
1663    parv++;
1664  
1665 <  if (parc != 0)
1665 >  if (parc)
1666    {
1667      if (irccmp(*parv, "ON") == 0)
1668      {
1669        parc--;
1670        parv++;
1671  
1906      if (target_server == NULL)
1907      {
1908        sendto_one_notice(source_p, &me, ":ON server not supported by %s", cmd);
1909        return -1;
1910      }
1911
1672        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1673        {
1674          sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1675 <        return -1;
1675 >        return 0;
1676        }
1677  
1678        if (parc == 0 || EmptyString(*parv))
1679        {
1680          sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1681 <        return -1;
1681 >        return 0;
1682        }
1683  
1684        *target_server = *parv;
# Line 1930 | Line 1690 | parse_aline(const char *cmd, struct Clie
1690        /* Make sure target_server *is* NULL if no ON server found
1691         * caller probably NULL'd it first, but no harm to do it again -db
1692         */
1693 <      if (target_server != NULL)
1693 >      if (target_server)
1694          *target_server = NULL;
1695      }
1696    }
1697  
1698 <  if (h_p != NULL)
1698 >  if (h_p)
1699    {
1700 <    if (strchr(user, '!') != NULL)
1700 >    if (strchr(user, '!'))
1701      {
1702        sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1703 <      return -1;
1703 >      return 0;
1704      }
1705  
1706 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1707 <      return -1;
1706 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p))
1707 >      return 0;
1708    }
1709    else
1710 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1711 <      return -1;
1710 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p))
1711 >      return 0;
1712  
1713 <  if (reason != NULL)
1713 >  if (reason)
1714    {
1715 <    if (parc != 0 && !EmptyString(*parv))
1956 <    {
1715 >    if (parc && !EmptyString(*parv))
1716        *reason = *parv;
1958      if (!valid_comment(source_p, *reason, 1))
1959        return -1;
1960    }
1717      else
1718 <      *reason = def_reason;
1718 >      *reason = default_reason;
1719    }
1720  
1721    return 1;
1722   }
1723  
1968 /* find_user_host()
1969 *
1970 * inputs       - pointer to client placing kline
1971 *              - pointer to user_host_or_nick
1972 *              - pointer to user buffer
1973 *              - pointer to host buffer
1974 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1975 * side effects -
1976 */
1977 static int
1978 find_user_host(struct Client *source_p, char *user_host_or_nick,
1979               char *luser, char *lhost, unsigned int flags)
1980 {
1981  struct Client *target_p = NULL;
1982  char *hostp = NULL;
1983
1984  if (lhost == NULL)
1985  {
1986    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1987    return 1;
1988  }
1989
1990  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1991  {
1992    /* Explicit user@host mask given */
1993
1994    if (hostp != NULL)                            /* I'm a little user@host */
1995    {
1996      *(hostp++) = '\0';                       /* short and squat */
1997      if (*user_host_or_nick)
1998        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1999      else
2000        strcpy(luser, "*");
2001
2002      if (*hostp)
2003        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2004      else
2005        strcpy(lhost, "*");
2006    }
2007    else
2008    {
2009      luser[0] = '*';             /* no @ found, assume its *@somehost */
2010      luser[1] = '\0';
2011      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2012    }
2013
2014    return 1;
2015  }
2016  else
2017  {
2018    /* Try to find user@host mask from nick */
2019    /* Okay to use source_p as the first param, because source_p == client_p */
2020    if ((target_p =
2021        find_chasing(source_p, user_host_or_nick)) == NULL)
2022      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
2023
2024    if (IsExemptKline(target_p))
2025    {
2026      if (!IsServer(source_p))
2027        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
2028      return 0;
2029    }
2030
2031    /*
2032     * turn the "user" bit into "*user", blow away '~'
2033     * if found in original user name (non-idented)
2034     */
2035    strlcpy(luser, target_p->username, USERLEN*4 + 1);
2036
2037    if (target_p->username[0] == '~')
2038      luser[0] = '*';
2039
2040    if (target_p->sockhost[0] == '\0' ||
2041        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2042      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2043    else
2044      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2045    return 1;
2046  }
2047
2048  return 0;
2049 }
2050
2051 /* valid_comment()
2052 *
2053 * inputs       - pointer to client
2054 *              - pointer to comment
2055 * output       - 0 if no valid comment,
2056 *              - 1 if valid
2057 * side effects - truncates reason where necessary
2058 */
2059 int
2060 valid_comment(struct Client *source_p, char *comment, int warn)
2061 {
2062  if (strlen(comment) > REASONLEN)
2063    comment[REASONLEN-1] = '\0';
2064
2065  return 1;
2066 }
2067
1724   /* match_conf_password()
1725   *
1726   * inputs       - pointer to given password
# Line 2093 | Line 1749 | match_conf_password(const char *password
1749   *
1750   * inputs       - client sending the cluster
1751   *              - command name "KLINE" "XLINE" etc.
1752 < *              - capab -- CAP_KLN etc. from server.h
1752 > *              - capab -- CAPAB_KLN etc. from server.h
1753   *              - cluster type -- CLUSTER_KLINE etc. from conf.h
1754   *              - pattern and args to send along
1755   * output       - none
# Line 2101 | Line 1757 | match_conf_password(const char *password
1757   *                along to all servers that match capab and cluster type
1758   */
1759   void
1760 < cluster_a_line(struct Client *source_p, const char *command,
1761 <               int capab, int cluster_type, const char *pattern, ...)
1760 > cluster_a_line(struct Client *source_p, const char *command, unsigned int capab,
1761 >               unsigned int cluster_type, const char *pattern, ...)
1762   {
1763    va_list args;
1764    char buffer[IRCD_BUFSIZE] = "";
1765 <  const dlink_node *ptr = NULL;
1765 >  const dlink_node *node = NULL;
1766  
1767    va_start(args, pattern);
1768    vsnprintf(buffer, sizeof(buffer), pattern, args);
1769    va_end(args);
1770  
1771 <  DLINK_FOREACH(ptr, cluster_items.head)
1771 >  DLINK_FOREACH(node, cluster_items.head)
1772    {
1773 <    const struct MaskItem *conf = ptr->data;
1773 >    const struct MaskItem *conf = node->data;
1774  
1775      if (conf->flags & cluster_type)
1776 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
1776 >      sendto_match_servs(source_p, conf->name, CAPAB_CLUSTER | capab,
1777                           "%s %s %s", command, conf->name, buffer);
1778    }
1779   }
# Line 2157 | Line 1813 | split_nuh(struct split_nuh_item *const i
1813  
1814    if (iptr->nickptr)
1815      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1816 +
1817    if (iptr->userptr)
1818      strlcpy(iptr->userptr, "*", iptr->usersize);
1819 +
1820    if (iptr->hostptr)
1821      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1822  
# Line 2201 | Line 1859 | split_nuh(struct split_nuh_item *const i
1859      }
1860      else
1861      {
1862 <      /* no @ found */
1862 >      /* No @ found */
1863        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1864          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1865        else

Diff Legend

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