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 4513 by michael, Sun Aug 17 18:25:52 2014 UTC vs.
Revision 5039 by michael, Sat Dec 13 16:08:37 2014 UTC

# 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 57 | Line 58
58  
59  
60   /* general conf items link list root, other than k lines etc. */
61 < dlink_list service_items = { NULL, NULL, 0 };
62 < dlink_list server_items  = { NULL, NULL, 0 };
63 < dlink_list cluster_items = { NULL, NULL, 0 };
64 < dlink_list oconf_items   = { NULL, NULL, 0 };
65 < dlink_list uconf_items   = { NULL, NULL, 0 };
66 < dlink_list xconf_items   = { NULL, NULL, 0 };
67 < dlink_list nresv_items   = { NULL, NULL, 0 };
68 < dlink_list cresv_items   = { NULL, NULL, 0 };
61 > dlink_list service_items;
62 > dlink_list server_items;
63 > dlink_list cluster_items;
64 > dlink_list oconf_items;
65 > dlink_list uconf_items;
66 > dlink_list xconf_items;
67 > dlink_list nresv_items;
68 > dlink_list cresv_items;
69  
70   extern unsigned int lineno;
71   extern char linebuf[];
72   extern char conffilebuf[IRCD_BUFSIZE];
73   extern int yyparse(); /* defined in y.tab.c */
74  
74 /* internally defined functions */
75 static void read_conf(FILE *);
76 static void clear_out_old_conf(void);
77 static void expire_tklines(dlink_list *);
78 static int verify_access(struct Client *);
79 static int attach_iline(struct Client *, struct MaskItem *);
80 static dlink_list *map_to_list(enum maskitem_type);
81 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
82
75  
76   /* conf_dns_callback()
77   *
# Line 94 | Line 86 | static int find_user_host(struct Client
86   static void
87   conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
88   {
89 <  struct MaskItem *conf = vptr;
89 >  struct MaskItem *const conf = vptr;
90  
91    conf->dns_pending = 0;
92  
# Line 113 | Line 105 | conf_dns_callback(void *vptr, const stru
105   static void
106   conf_dns_lookup(struct MaskItem *conf)
107   {
108 <  if (!conf->dns_pending)
109 <  {
118 <    conf->dns_pending = 1;
108 >  if (conf->dns_pending)
109 >    return;
110  
111 <    if (conf->aftype == AF_INET)
112 <      gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
113 <    else
114 <      gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
111 >  conf->dns_pending = 1;
112 >
113 >  if (conf->aftype == AF_INET)
114 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
115 >  else
116 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
117 > }
118 >
119 > /* map_to_list()
120 > *
121 > * inputs       - ConfType conf
122 > * output       - pointer to dlink_list to use
123 > * side effects - none
124 > */
125 > static dlink_list *
126 > map_to_list(enum maskitem_type type)
127 > {
128 >  switch (type)
129 >  {
130 >    case CONF_XLINE:
131 >      return &xconf_items;
132 >      break;
133 >    case CONF_ULINE:
134 >      return &uconf_items;
135 >      break;
136 >    case CONF_NRESV:
137 >      return &nresv_items;
138 >      break;
139 >    case CONF_CRESV:
140 >      return &cresv_items;
141 >      break;
142 >    case CONF_OPER:
143 >      return &oconf_items;
144 >      break;
145 >    case CONF_SERVER:
146 >      return &server_items;
147 >      break;
148 >    case CONF_SERVICE:
149 >      return &service_items;
150 >      break;
151 >    case CONF_CLUSTER:
152 >      return &cluster_items;
153 >      break;
154 >    default:
155 >      return NULL;
156    }
157   }
158  
159   struct MaskItem *
160   conf_make(enum maskitem_type type)
161   {
162 <  struct MaskItem *conf = MyCalloc(sizeof(*conf));
162 >  struct MaskItem *const conf = MyCalloc(sizeof(*conf));
163    dlink_list *list = NULL;
164  
165    conf->type   = type;
# Line 142 | Line 174 | conf_make(enum maskitem_type type)
174   void
175   conf_free(struct MaskItem *conf)
176   {
177 <  dlink_node *ptr = NULL, *ptr_next = NULL;
177 >  dlink_node *node = NULL, *node_next = NULL;
178    dlink_list *list = NULL;
179  
148  assert(conf->node.data);
149
180    if ((list = map_to_list(conf->type)))
181 <    dlinkDelete(&conf->node, list);
181 >    dlinkFindDelete(list, conf);
182  
183    MyFree(conf->name);
184  
# Line 173 | Line 203 | conf_free(struct MaskItem *conf)
203    if (conf->rsa_public_key)
204      RSA_free(conf->rsa_public_key);
205   #endif
206 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
206 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
207    {
208 <    MyFree(ptr->data);
209 <    dlinkDelete(ptr, &conf->hub_list);
210 <    free_dlink_node(ptr);
208 >    MyFree(node->data);
209 >    dlinkDelete(node, &conf->hub_list);
210 >    free_dlink_node(node);
211    }
212  
213 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
213 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
214    {
215 <    MyFree(ptr->data);
216 <    dlinkDelete(ptr, &conf->leaf_list);
217 <    free_dlink_node(ptr);
215 >    MyFree(node->data);
216 >    dlinkDelete(node, &conf->leaf_list);
217 >    free_dlink_node(node);
218    }
219  
220 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
220 >  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
221    {
222 <    struct exempt *exptr = ptr->data;
222 >    struct exempt *exptr = node->data;
223  
224 <    dlinkDelete(ptr, &conf->exempt_list);
224 >    dlinkDelete(node, &conf->exempt_list);
225      MyFree(exptr->name);
226      MyFree(exptr->user);
227      MyFree(exptr->host);
# Line 201 | Line 231 | conf_free(struct MaskItem *conf)
231    MyFree(conf);
232   }
233  
234 < /* check_client()
234 > /* attach_iline()
235   *
236 < * inputs       - pointer to client
237 < * output       - 0 = Success
238 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
239 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
210 < *                I_LINE_FULL       (-3) = I-line is full
211 < *                TOO_MANY          (-4) = Too many connections from hostname
212 < *                BANNED_CLIENT     (-5) = K-lined
213 < * side effects - Ordinary client access check.
214 < *                Look for conf lines which have the same
215 < *                status as the flags passed.
236 > * inputs       - client pointer
237 > *              - conf pointer
238 > * output       -
239 > * side effects - do actual attach
240   */
241 < int
242 < check_client(struct Client *source_p)
241 > static int
242 > attach_iline(struct Client *client_p, struct MaskItem *conf)
243   {
244 <  int i;
245 <
246 <  if ((i = verify_access(source_p)))
247 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
224 <         source_p->name, source_p->sockhost);
225 <
226 <  switch (i)
227 <  {
228 <    case TOO_MANY:
229 <      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
230 <                           "Too many on IP for %s (%s).",
231 <                           get_client_name(source_p, SHOW_IP),
232 <                           source_p->sockhost);
233 <      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
234 <           get_client_name(source_p, SHOW_IP));
235 <      ++ServerStats.is_ref;
236 <      exit_client(source_p, "No more connections allowed on that IP");
237 <      break;
244 >  const struct ClassItem *const class = conf->class;
245 >  struct ip_entry *ip_found;
246 >  int a_limit_reached = 0;
247 >  unsigned int local = 0, global = 0, ident = 0;
248  
249 <    case I_LINE_FULL:
250 <      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
251 <                           "auth{} block is full for %s (%s).",
242 <                           get_client_name(source_p, SHOW_IP),
243 <                           source_p->sockhost);
244 <      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
245 <           get_client_name(source_p, SHOW_IP));
246 <      ++ServerStats.is_ref;
247 <      exit_client(source_p, "No more connections allowed in your connection class");
248 <      break;
249 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
250 >  ip_found->count++;
251 >  AddFlag(client_p, FLAGS_IPHASH);
252  
253 <    case NOT_AUTHORIZED:
254 <      ++ServerStats.is_ref;
252 <      /* jdc - lists server name & port connections are on */
253 <      /*       a purely cosmetical change */
254 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
255 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
256 <                           get_client_name(source_p, SHOW_IP),
257 <                           source_p->sockhost,
258 <                           source_p->localClient->listener->name,
259 <                           source_p->localClient->listener->port);
260 <      ilog(LOG_TYPE_IRCD,
261 <           "Unauthorized client connection from %s on [%s/%u].",
262 <           get_client_name(source_p, SHOW_IP),
263 <           source_p->localClient->listener->name,
264 <           source_p->localClient->listener->port);
253 >  count_user_host(client_p->username, client_p->host,
254 >                  &global, &local, &ident);
255  
256 <      exit_client(source_p, "You are not authorized to use this server");
257 <      break;
256 >  /* XXX blah. go down checking the various silly limits
257 >   * setting a_limit_reached if any limit is reached.
258 >   * - Dianora
259 >   */
260 >  if (class->max_total && class->ref_count >= class->max_total)
261 >    a_limit_reached = 1;
262 >  else if (class->max_perip && ip_found->count > class->max_perip)
263 >    a_limit_reached = 1;
264 >  else if (class->max_local && local >= class->max_local)
265 >    a_limit_reached = 1;
266 >  else if (class->max_global && global >= class->max_global)
267 >    a_limit_reached = 1;
268 >  else if (class->max_ident && ident >= class->max_ident &&
269 >           client_p->username[0] != '~')
270 >    a_limit_reached = 1;
271  
272 <   case BANNED_CLIENT:
273 <     exit_client(source_p, "Banned");
274 <     ++ServerStats.is_ref;
275 <     break;
272 >  if (a_limit_reached)
273 >  {
274 >    if (!IsConfExemptLimits(conf))
275 >      return TOO_MANY;   /* Already at maximum allowed */
276  
277 <   case 0:
278 <   default:
276 <     break;
277 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
278 >                      "but you have exceed_limit = yes;");
279    }
280  
281 <  return (i < 0 ? 0 : 1);
281 >  return attach_conf(client_p, conf);
282   }
283  
284   /* verify_access()
285   *
286 < * inputs       - pointer to client to verify
287 < * output       - 0 if success -'ve if not
288 < * side effect  - find the first (best) I line to attach.
286 > * inputs       - pointer to client to verify
287 > * output       - 0 if success -'ve if not
288 > * side effect  - find the first (best) I line to attach.
289   */
290   static int
291   verify_access(struct Client *client_p)
# Line 294 | Line 296 | verify_access(struct Client *client_p)
296    if (IsGotId(client_p))
297    {
298      conf = find_address_conf(client_p->host, client_p->username,
299 <                             &client_p->localClient->ip,
300 <                             client_p->localClient->aftype,
301 <                             client_p->localClient->password);
299 >                             &client_p->connection->ip,
300 >                             client_p->connection->aftype,
301 >                             client_p->connection->password);
302    }
303    else
304    {
305      strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
306 <    conf = find_address_conf(client_p->host,non_ident,
307 <                             &client_p->localClient->ip,
308 <                             client_p->localClient->aftype,
309 <                             client_p->localClient->password);
306 >    conf = find_address_conf(client_p->host, non_ident,
307 >                             &client_p->connection->ip,
308 >                             client_p->connection->aftype,
309 >                             client_p->connection->password);
310    }
311  
312    if (conf)
# Line 319 | Line 321 | verify_access(struct Client *client_p)
321          return NOT_AUTHORIZED;
322        }
323  
322      if (IsConfDoIdentd(conf))
323        SetNeedId(client_p);
324
324        /* Thanks for spoof idea amm */
325        if (IsConfDoSpoofIp(conf))
326        {
327 <        if (!ConfigGeneral.hide_spoof_ips && IsConfSpoofNotice(conf))
328 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
330 <                               "%s spoofing: %s as %s",
327 >        if (IsConfSpoofNotice(conf))
328 >          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
329                                 client_p->name, client_p->host, conf->name);
330 +
331          strlcpy(client_p->host, conf->name, sizeof(client_p->host));
333        AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
332        }
333  
334        return attach_iline(client_p, conf);
# Line 339 | Line 337 | verify_access(struct Client *client_p)
337      {
338        if (IsConfGline(conf))
339          sendto_one_notice(client_p, &me, ":*** G-lined");
340 +
341        sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
342        return BANNED_CLIENT;
343      }
# Line 347 | Line 346 | verify_access(struct Client *client_p)
346    return NOT_AUTHORIZED;
347   }
348  
349 < /* attach_iline()
349 > /* check_client()
350   *
351 < * inputs       - client pointer
352 < *              - conf pointer
353 < * output       -
354 < * side effects - do actual attach
351 > * inputs       - pointer to client
352 > * output       - 0 = Success
353 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
354 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
355 > *                I_LINE_FULL       (-3) = I-line is full
356 > *                TOO_MANY          (-4) = Too many connections from hostname
357 > *                BANNED_CLIENT     (-5) = K-lined
358 > * side effects - Ordinary client access check.
359 > *                Look for conf lines which have the same
360 > *                status as the flags passed.
361   */
362 < static int
363 < attach_iline(struct Client *client_p, struct MaskItem *conf)
362 > int
363 > check_client(struct Client *source_p)
364   {
365 <  const struct ClassItem *class = conf->class;
361 <  struct ip_entry *ip_found;
362 <  int a_limit_reached = 0;
363 <  unsigned int local = 0, global = 0, ident = 0;
365 >  int i;
366  
367 <  ip_found = ipcache_find_or_add_address(&client_p->localClient->ip);
368 <  ip_found->count++;
369 <  AddFlag(client_p, FLAGS_IPHASH);
367 >  if ((i = verify_access(source_p)))
368 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
369 >         source_p->name, source_p->sockhost);
370  
371 <  count_user_host(client_p->username, client_p->host,
372 <                  &global, &local, &ident);
371 >  switch (i)
372 >  {
373 >    case TOO_MANY:
374 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
375 >                           "Too many on IP for %s (%s).",
376 >                           get_client_name(source_p, SHOW_IP),
377 >                           source_p->sockhost);
378 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
379 >           get_client_name(source_p, SHOW_IP));
380 >      ++ServerStats.is_ref;
381 >      exit_client(source_p, "No more connections allowed on that IP");
382 >      break;
383  
384 <  /* XXX blah. go down checking the various silly limits
385 <   * setting a_limit_reached if any limit is reached.
386 <   * - Dianora
387 <   */
388 <  if (class->max_total && class->ref_count >= class->max_total)
389 <    a_limit_reached = 1;
390 <  else if (class->max_perip && ip_found->count > class->max_perip)
391 <    a_limit_reached = 1;
392 <  else if (class->max_local && local >= class->max_local)
393 <    a_limit_reached = 1;
382 <  else if (class->max_global && global >= class->max_global)
383 <    a_limit_reached = 1;
384 <  else if (class->max_ident && ident >= class->max_ident &&
385 <           client_p->username[0] != '~')
386 <    a_limit_reached = 1;
384 >    case I_LINE_FULL:
385 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
386 >                           "auth {} block is full for %s (%s).",
387 >                           get_client_name(source_p, SHOW_IP),
388 >                           source_p->sockhost);
389 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
390 >           get_client_name(source_p, SHOW_IP));
391 >      ++ServerStats.is_ref;
392 >      exit_client(source_p, "No more connections allowed in your connection class");
393 >      break;
394  
395 <  if (a_limit_reached)
396 <  {
397 <    if (!IsConfExemptLimits(conf))
398 <      return TOO_MANY;   /* Already at maximum allowed */
395 >    case NOT_AUTHORIZED:
396 >      /* jdc - lists server name & port connections are on */
397 >      /*       a purely cosmetical change */
398 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
399 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
400 >                           get_client_name(source_p, SHOW_IP),
401 >                           source_p->sockhost,
402 >                           source_p->connection->listener->name,
403 >                           source_p->connection->listener->port);
404 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
405 >           get_client_name(source_p, SHOW_IP),
406 >           source_p->connection->listener->name,
407 >           source_p->connection->listener->port);
408  
409 <    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
410 <                      "but you have exceed_limit = yes;");
409 >      ++ServerStats.is_ref;
410 >      exit_client(source_p, "You are not authorized to use this server");
411 >      break;
412 >
413 >    case BANNED_CLIENT:
414 >      ++ServerStats.is_ref;
415 >      exit_client(source_p, "Banned");
416 >      break;
417 >
418 >    case 0:
419 >    default:
420 >      break;
421    }
422  
423 <  return attach_conf(client_p, conf);
423 >  return !(i < 0);
424   }
425  
426   /* detach_conf()
# Line 408 | Line 434 | attach_iline(struct Client *client_p, st
434   void
435   detach_conf(struct Client *client_p, enum maskitem_type type)
436   {
437 <  dlink_node *ptr = NULL, *ptr_next = NULL;
437 >  dlink_node *node = NULL, *node_next = NULL;
438  
439 <  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->confs.head)
439 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
440    {
441 <    struct MaskItem *conf = ptr->data;
441 >    struct MaskItem *conf = node->data;
442  
443      assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
444      assert(conf->ref_count > 0);
# Line 421 | Line 447 | detach_conf(struct Client *client_p, enu
447      if (!(conf->type & type))
448        continue;
449  
450 <    dlinkDelete(ptr, &client_p->localClient->confs);
451 <    free_dlink_node(ptr);
450 >    dlinkDelete(node, &client_p->connection->confs);
451 >    free_dlink_node(node);
452  
453      if (conf->type == CONF_CLIENT)
454 <      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
454 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
455  
456      if (--conf->class->ref_count == 0 && conf->class->active == 0)
457      {
# Line 451 | Line 477 | detach_conf(struct Client *client_p, enu
477   int
478   attach_conf(struct Client *client_p, struct MaskItem *conf)
479   {
480 <  if (dlinkFind(&client_p->localClient->confs, conf))
480 >  if (dlinkFind(&client_p->connection->confs, conf))
481      return 1;
482  
483    if (conf->type == CONF_CLIENT)
484      if (cidr_limit_reached(IsConfExemptLimits(conf),
485 <                           &client_p->localClient->ip, conf->class))
485 >                           &client_p->connection->ip, conf->class))
486        return TOO_MANY;    /* Already at maximum allowed */
487  
488    conf->class->ref_count++;
489    conf->ref_count++;
490  
491 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
491 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
492  
493    return 0;
494   }
# Line 479 | Line 505 | int
505   attach_connect_block(struct Client *client_p, const char *name,
506                       const char *host)
507   {
508 <  dlink_node *ptr;
483 <  struct MaskItem *conf = NULL;
508 >  dlink_node *node = NULL;
509  
510 <  assert(client_p != NULL);
486 <  assert(host != NULL);
510 >  assert(host);
511  
512 <  if (client_p == NULL || host == NULL)
489 <    return 0;
490 <
491 <  DLINK_FOREACH(ptr, server_items.head)
512 >  DLINK_FOREACH(node, server_items.head)
513    {
514 <    conf = ptr->data;
514 >    struct MaskItem *conf = node->data;
515  
516      if (match(conf->name, name) || match(conf->host, host))
517        continue;
# Line 514 | Line 535 | attach_connect_block(struct Client *clie
535   struct MaskItem *
536   find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
537   {
538 <  dlink_node *ptr;
518 <  struct MaskItem* conf;
538 >  dlink_node *node = NULL;
539  
540 <  DLINK_FOREACH(ptr, list->head)
540 >  DLINK_FOREACH(node, list->head)
541    {
542 <    conf = ptr->data;
542 >    struct MaskItem *conf = node->data;
543  
544      if (conf->type == type)
545      {
546 <      if (conf->name && (!irccmp(conf->name, name) ||
547 <                         !match(conf->name, name)))
528 <      return conf;
546 >      if (conf->name && !irccmp(conf->name, name))
547 >        return conf;
548      }
549    }
550  
551    return NULL;
552   }
553  
535 /* map_to_list()
536 *
537 * inputs       - ConfType conf
538 * output       - pointer to dlink_list to use
539 * side effects - none
540 */
541 static dlink_list *
542 map_to_list(enum maskitem_type type)
543 {
544  switch(type)
545  {
546  case CONF_XLINE:
547    return(&xconf_items);
548    break;
549  case CONF_ULINE:
550    return(&uconf_items);
551    break;
552  case CONF_NRESV:
553    return(&nresv_items);
554    break;
555  case CONF_CRESV:
556    return(&cresv_items);
557  case CONF_OPER:
558    return(&oconf_items);
559    break;
560  case CONF_SERVER:
561    return(&server_items);
562    break;
563  case CONF_SERVICE:
564    return(&service_items);
565    break;
566  case CONF_CLUSTER:
567    return(&cluster_items);
568    break;
569  default:
570    return NULL;
571  }
572 }
573
554   /* find_matching_name_conf()
555   *
556   * inputs       - type of link list to look in
# Line 585 | Line 565 | struct MaskItem *
565   find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
566                          const char *host, unsigned int flags)
567   {
568 <  dlink_node *ptr=NULL;
569 <  struct MaskItem *conf=NULL;
570 <  dlink_list *list_p = map_to_list(type);
568 >  dlink_node *node = NULL;
569 >  dlink_list *list = map_to_list(type);
570 >  struct MaskItem *conf = NULL;
571  
572    switch (type)
573    {
574    case CONF_SERVICE:
575 <    DLINK_FOREACH(ptr, list_p->head)
575 >    DLINK_FOREACH(node, list->head)
576      {
577 <      conf = ptr->data;
577 >      conf = node->data;
578  
579        if (EmptyString(conf->name))
580          continue;
581 <      if ((name != NULL) && !irccmp(name, conf->name))
581 >      if (name && !irccmp(name, conf->name))
582          return conf;
583      }
584      break;
# Line 607 | Line 587 | find_matching_name_conf(enum maskitem_ty
587    case CONF_ULINE:
588    case CONF_NRESV:
589    case CONF_CRESV:
590 <    DLINK_FOREACH(ptr, list_p->head)
590 >    DLINK_FOREACH(node, list->head)
591      {
592 <      conf = ptr->data;
592 >      conf = node->data;
593  
594        if (EmptyString(conf->name))
595          continue;
596 <      if ((name != NULL) && !match(conf->name, name))
596 >      if (name && !match(conf->name, name))
597        {
598          if ((user == NULL && (host == NULL)))
599            return conf;
# Line 628 | Line 608 | find_matching_name_conf(enum maskitem_ty
608        break;
609  
610    case CONF_SERVER:
611 <    DLINK_FOREACH(ptr, list_p->head)
611 >    DLINK_FOREACH(node, list->head)
612      {
613 <      conf = ptr->data;
613 >      conf = node->data;
614  
615 <      if ((name != NULL) && !match(name, conf->name))
615 >      if (name && !match(name, conf->name))
616          return conf;
617 <      else if ((host != NULL) && !match(host, conf->host))
617 >      if (host && !match(host, conf->host))
618          return conf;
619      }
620      break;
# Line 658 | Line 638 | struct MaskItem *
638   find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
639                       const char *user, const char *host)
640   {
641 <  dlink_node *ptr = NULL;
642 <  struct MaskItem *conf;
643 <  dlink_list *list_p = map_to_list(type);
641 >  dlink_node *node = NULL;
642 >  dlink_list *list = map_to_list(type);
643 >  struct MaskItem *conf = NULL;
644  
645    switch(type)
646    {
# Line 669 | Line 649 | find_exact_name_conf(enum maskitem_type
649    case CONF_NRESV:
650    case CONF_CRESV:
651  
652 <    DLINK_FOREACH(ptr, list_p->head)
652 >    DLINK_FOREACH(node, list->head)
653      {
654 <      conf = ptr->data;
654 >      conf = node->data;
655  
656        if (EmptyString(conf->name))
657          continue;
# Line 689 | Line 669 | find_exact_name_conf(enum maskitem_type
669      break;
670  
671    case CONF_OPER:
672 <    DLINK_FOREACH(ptr, list_p->head)
672 >    DLINK_FOREACH(node, list->head)
673      {
674 <      conf = ptr->data;
674 >      conf = node->data;
675  
676        if (EmptyString(conf->name))
677          continue;
# Line 712 | Line 692 | find_exact_name_conf(enum maskitem_type
692                    return conf;
693                break;
694              case HM_IPV4:
695 <              if (who->localClient->aftype == AF_INET)
696 <                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
695 >              if (who->connection->aftype == AF_INET)
696 >                if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
697                    if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
698                      return conf;
699                break;
700              case HM_IPV6:
701 <              if (who->localClient->aftype == AF_INET6)
702 <                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
701 >              if (who->connection->aftype == AF_INET6)
702 >                if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
703                    if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
704                      return conf;
705                break;
# Line 733 | Line 713 | find_exact_name_conf(enum maskitem_type
713      break;
714  
715    case CONF_SERVER:
716 <    DLINK_FOREACH(ptr, list_p->head)
716 >    DLINK_FOREACH(node, list->head)
717      {
718 <      conf = ptr->data;
718 >      conf = node->data;
719  
720        if (EmptyString(conf->name))
721          continue;
# Line 760 | Line 740 | find_exact_name_conf(enum maskitem_type
740    return NULL;
741   }
742  
763 /* rehash()
764 *
765 * Actual REHASH service routine. Called with sig == 0 if it has been called
766 * as a result of an operator issuing this command, else assume it has been
767 * called as a result of the server receiving a HUP signal.
768 */
769 int
770 rehash(int sig)
771 {
772  if (sig)
773    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
774                         "Got signal SIGHUP, reloading configuration file(s)");
775
776  restart_resolver();
777
778  /* don't close listeners until we know we can go ahead with the rehash */
779
780  read_conf_files(0);
781
782  load_conf_modules();
783  check_conf_klines();
784
785  return 0;
786 }
787
743   /* set_default_conf()
744   *
745   * inputs       - NONE
# Line 803 | Line 758 | set_default_conf(void)
758    assert(class_default == class_get_list()->tail->data);
759  
760   #ifdef HAVE_LIBCRYPTO
761 < #if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH)
761 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
762    {
763      EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
764  
# Line 817 | Line 772 | set_default_conf(void)
772    SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
773   #endif
774  
775 +  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
776    ConfigServerInfo.message_digest_algorithm = EVP_sha256();
777    ConfigServerInfo.rsa_private_key = NULL;
778    ConfigServerInfo.rsa_private_key_file = NULL;
# Line 870 | Line 826 | set_default_conf(void)
826  
827    ConfigGeneral.away_count = 2;
828    ConfigGeneral.away_time = 10;
873  ConfigGeneral.service_name = xstrdup(SERVICE_NAME_DEFAULT);
829    ConfigGeneral.max_watch = WATCHSIZE_DEFAULT;
830    ConfigGeneral.cycle_on_host_change = 1;
831    ConfigGeneral.glines = 0;
# Line 880 | Line 835 | set_default_conf(void)
835    ConfigGeneral.gline_min_cidr6 = 48;
836    ConfigGeneral.invisible_on_connect = 1;
837    ConfigGeneral.tkline_expire_notices = 1;
883  ConfigGeneral.hide_spoof_ips = 1;
838    ConfigGeneral.ignore_bogus_ts = 0;
839    ConfigGeneral.disable_auth = 0;
840    ConfigGeneral.kill_chase_time_limit = 90;
# Line 898 | Line 852 | set_default_conf(void)
852    ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
853    ConfigGeneral.warn_no_connect_block = 1;
854    ConfigGeneral.stats_e_disabled = 0;
901  ConfigGeneral.stats_o_oper_only = 0;
902  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
855    ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
856 +  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
857 +  ConfigGeneral.stats_o_oper_only = 1;
858 +  ConfigGeneral.stats_m_oper_only = 1;
859    ConfigGeneral.stats_P_oper_only = 0;
860    ConfigGeneral.stats_u_oper_only = 0;
861    ConfigGeneral.caller_id_wait = 60;
# Line 910 | Line 865 | set_default_conf(void)
865    ConfigGeneral.short_motd = 0;
866    ConfigGeneral.ping_cookie = 0;
867    ConfigGeneral.no_oper_flood = 0;
913  ConfigGeneral.true_no_oper_flood = 0;
868    ConfigGeneral.oper_pass_resv = 1;
869    ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
870    ConfigGeneral.oper_only_umodes = UMODE_DEBUG;
# Line 928 | Line 882 | validate_conf(void)
882    if (ConfigGeneral.ts_max_delta < TS_MAX_DELTA_MIN)
883      ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
884  
885 <  if (ConfigServerInfo.network_name == NULL)
885 >  if (EmptyString(ConfigServerInfo.network_name))
886      ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
887  
888 <  if (ConfigServerInfo.network_desc == NULL)
888 >  if (EmptyString(ConfigServerInfo.network_desc))
889      ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
890  
937  if (ConfigGeneral.service_name == NULL)
938    ConfigGeneral.service_name = xstrdup(SERVICE_NAME_DEFAULT);
939
891    ConfigGeneral.max_watch = IRCD_MAX(ConfigGeneral.max_watch, WATCHSIZE_MIN);
892   }
893  
# Line 964 | Line 915 | read_conf(FILE *file)
915    class_delete_marked();  /* Delete unused classes that are marked for deletion */
916   }
917  
918 + /* conf_rehash()
919 + *
920 + * Actual REHASH service routine. Called with sig == 0 if it has been called
921 + * as a result of an operator issuing this command, else assume it has been
922 + * called as a result of the server receiving a HUP signal.
923 + */
924 + int
925 + conf_rehash(int sig)
926 + {
927 +  if (sig)
928 +    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
929 +                         "Got signal SIGHUP, reloading configuration file(s)");
930 +
931 +  restart_resolver();
932 +
933 +  /* don't close listeners until we know we can go ahead with the rehash */
934 +
935 +  read_conf_files(0);
936 +
937 +  load_conf_modules();
938 +  check_conf_klines();
939 +
940 +  return 0;
941 + }
942 +
943   /* lookup_confhost()
944   *
945   * start DNS lookups of all hostnames in the conf
# Line 1012 | Line 988 | int
988   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
989   {
990    struct ip_entry *ip_found = NULL;
991 <  struct MaskItem *conf = find_dline_conf(addr, aftype);
991 >  struct MaskItem *const conf = find_dline_conf(addr, aftype);
992  
993    /* DLINE exempt also gets you out of static limits/pacing... */
994    if (conf && (conf->type == CONF_EXEMPT))
# Line 1037 | Line 1013 | conf_connect_allowed(struct irc_ssaddr *
1013    return 0;
1014   }
1015  
1040 /* cleanup_tklines()
1041 *
1042 * inputs       - NONE
1043 * output       - NONE
1044 * side effects - call function to expire temporary k/d lines
1045 *                This is an event started off in ircd.c
1046 */
1047 void
1048 cleanup_tklines(void *unused)
1049 {
1050  hostmask_expire_temporary();
1051  expire_tklines(&xconf_items);
1052  expire_tklines(&nresv_items);
1053  expire_tklines(&cresv_items);
1054 }
1055
1016   /* expire_tklines()
1017   *
1018   * inputs       - tkline list pointer
# Line 1060 | Line 1020 | cleanup_tklines(void *unused)
1020   * side effects - expire tklines
1021   */
1022   static void
1023 < expire_tklines(dlink_list *tklist)
1023 > expire_tklines(dlink_list *list)
1024   {
1025 <  dlink_node *ptr = NULL, *ptr_next = NULL;
1066 <  struct MaskItem *conf = NULL;
1025 >  dlink_node *node = NULL, *node_next = NULL;
1026  
1027 <  DLINK_FOREACH_SAFE(ptr, ptr_next, tklist->head)
1027 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
1028    {
1029 <    conf = ptr->data;
1029 >    struct MaskItem *conf = node->data;
1030  
1031      if (!conf->until || conf->until > CurrentTime)
1032        continue;
# Line 1089 | Line 1048 | expire_tklines(dlink_list *tklist)
1048    }
1049   }
1050  
1051 + /* cleanup_tklines()
1052 + *
1053 + * inputs       - NONE
1054 + * output       - NONE
1055 + * side effects - call function to expire temporary k/d lines
1056 + *                This is an event started off in ircd.c
1057 + */
1058 + void
1059 + cleanup_tklines(void *unused)
1060 + {
1061 +  hostmask_expire_temporary();
1062 +  expire_tklines(&xconf_items);
1063 +  expire_tklines(&nresv_items);
1064 +  expire_tklines(&cresv_items);
1065 + }
1066 +
1067   /* oper_privs_as_string()
1068   *
1069   * inputs        - pointer to client_p
# Line 1145 | Line 1120 | oper_privs_as_string(const unsigned int
1120   const char *
1121   get_oper_name(const struct Client *client_p)
1122   {
1148  const dlink_node *cnode = NULL;
1123    /* +5 for !,@,{,} and null */
1124    static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1125  
1126 +  if (IsServer(client_p))
1127 +    return client_p->name;
1128 +
1129    if (MyConnect(client_p))
1130    {
1131 <    if ((cnode = client_p->localClient->confs.head))
1131 >    const dlink_node *const node = client_p->connection->confs.head;
1132 >
1133 >    if (node)
1134      {
1135 <      const struct MaskItem *conf = cnode->data;
1135 >      const struct MaskItem *const conf = node->data;
1136  
1137 <      if (IsConfOperator(conf))
1137 >      if (conf->type == CONF_OPER)
1138        {
1139          snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1140                   client_p->username, client_p->host, conf->name);
# Line 1175 | Line 1154 | get_oper_name(const struct Client *clien
1154    return buffer;
1155   }
1156  
1178 /* read_conf_files()
1179 *
1180 * inputs       - cold start YES or NO
1181 * output       - none
1182 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1183 */
1184 void
1185 read_conf_files(int cold)
1186 {
1187  const char *filename = NULL;
1188  char chanmodes[IRCD_BUFSIZE] = "";
1189  char chanlimit[IRCD_BUFSIZE] = "";
1190
1191  conf_parser_ctx.boot = cold;
1192  filename = ConfigGeneral.configfile;
1193
1194  /* We need to know the initial filename for the yyerror() to report
1195     FIXME: The full path is in conffilenamebuf first time since we
1196             don't know anything else
1197
1198     - Gozem 2002-07-21
1199  */
1200  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1201
1202  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1203  {
1204    if (cold)
1205    {
1206      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1207           filename, strerror(errno));
1208      exit(-1);
1209    }
1210    else
1211    {
1212      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1213                           "Unable to read configuration file '%s': %s",
1214                           filename, strerror(errno));
1215      return;
1216    }
1217  }
1218
1219  if (!cold)
1220    clear_out_old_conf();
1221
1222  read_conf(conf_parser_ctx.conf_file);
1223  fclose(conf_parser_ctx.conf_file);
1224
1225  log_reopen_all();
1226
1227  add_isupport("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1228  add_isupport("NETWORK", ConfigServerInfo.network_name, -1);
1229
1230  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1231  add_isupport("MAXLIST", chanmodes, -1);
1232  add_isupport("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1233  add_isupport("CHANTYPES", "#", -1);
1234
1235  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1236           ConfigChannel.max_channels);
1237  add_isupport("CHANLIMIT", chanlimit, -1);
1238  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstMORS");
1239  add_isupport("CHANNELLEN", NULL, CHANNELLEN);
1240  add_isupport("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1241  add_isupport("CHANMODES", chanmodes, -1);
1242
1243  /*
1244   * message_locale may have changed.  rebuild isupport since it relies
1245   * on strlen(form_str(RPL_ISUPPORT))
1246   */
1247  rebuild_isupport_message_line();
1248 }
1249
1157   /* clear_out_old_conf()
1158   *
1159   * inputs       - none
# Line 1256 | Line 1163 | read_conf_files(int cold)
1163   static void
1164   clear_out_old_conf(void)
1165   {
1166 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1260 <  struct MaskItem *conf;
1166 >  dlink_node *node = NULL, *node_next = NULL;
1167    dlink_list *free_items [] = {
1168      &server_items,   &oconf_items,
1169       &uconf_items,   &xconf_items,
# Line 1270 | Line 1176 | clear_out_old_conf(void)
1176     * Resetting structs, etc, is taken care of by set_default_conf().
1177     */
1178  
1179 <  for (; *iterator != NULL; iterator++)
1179 >  for (; *iterator; iterator++)
1180    {
1181 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1181 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1182      {
1183 <      conf = ptr->data;
1183 >      struct MaskItem *conf = node->data;
1184  
1185 <      dlinkDelete(&conf->node, map_to_list(conf->type));
1185 >      conf->active = 0;
1186 >      dlinkDelete(&conf->node, *iterator);
1187  
1188        /* XXX This is less than pretty */
1189        if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
# Line 1307 | Line 1214 | clear_out_old_conf(void)
1214    /* clean out module paths */
1215    mod_clear_paths();
1216  
1217 +  pseudo_clear();
1218 +
1219    /* clean out ConfigServerInfo */
1220    MyFree(ConfigServerInfo.description);
1221    ConfigServerInfo.description = NULL;
# Line 1335 | Line 1244 | clear_out_old_conf(void)
1244  
1245    /* clean out listeners */
1246    close_listeners();
1247 + }
1248 +
1249 + /* read_conf_files()
1250 + *
1251 + * inputs       - cold start YES or NO
1252 + * output       - none
1253 + * side effects - read all conf files needed, ircd.conf kline.conf etc.
1254 + */
1255 + void
1256 + read_conf_files(int cold)
1257 + {
1258 +  const char *filename = NULL;
1259 +  char chanmodes[IRCD_BUFSIZE] = "";
1260 +  char chanlimit[IRCD_BUFSIZE] = "";
1261  
1262 <  /* clean out general */
1263 <  MyFree(ConfigGeneral.service_name);
1264 <  ConfigGeneral.service_name = NULL;
1262 >  conf_parser_ctx.boot = cold;
1263 >  filename = ConfigGeneral.configfile;
1264 >
1265 >  /* We need to know the initial filename for the yyerror() to report
1266 >     FIXME: The full path is in conffilenamebuf first time since we
1267 >             don't know anything else
1268 >
1269 >     - Gozem 2002-07-21
1270 >  */
1271 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1272 >
1273 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1274 >  {
1275 >    if (cold)
1276 >    {
1277 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1278 >           filename, strerror(errno));
1279 >      exit(-1);
1280 >    }
1281 >    else
1282 >    {
1283 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1284 >                           "Unable to read configuration file '%s': %s",
1285 >                           filename, strerror(errno));
1286 >      return;
1287 >    }
1288 >  }
1289 >
1290 >  if (!cold)
1291 >    clear_out_old_conf();
1292 >
1293 >  read_conf(conf_parser_ctx.conf_file);
1294 >  fclose(conf_parser_ctx.conf_file);
1295 >
1296 >  log_reopen_all();
1297 >
1298 >  add_isupport("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1299 >  add_isupport("NETWORK", ConfigServerInfo.network_name, -1);
1300 >
1301 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1302 >  add_isupport("MAXLIST", chanmodes, -1);
1303 >  add_isupport("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1304 >  add_isupport("CHANTYPES", "#", -1);
1305 >
1306 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1307 >           ConfigChannel.max_channels);
1308 >  add_isupport("CHANLIMIT", chanlimit, -1);
1309 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstMORS");
1310 >  add_isupport("CHANNELLEN", NULL, CHANNELLEN);
1311 >  add_isupport("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1312 >  add_isupport("CHANMODES", chanmodes, -1);
1313 >
1314 >  /*
1315 >   * message_locale may have changed.  rebuild isupport since it relies
1316 >   * on strlen(form_str(RPL_ISUPPORT))
1317 >   */
1318 >  rebuild_isupport_message_line();
1319   }
1320  
1321   /* conf_add_class_to_conf()
# Line 1354 | Line 1331 | conf_add_class_to_conf(struct MaskItem *
1331    {
1332      conf->class = class_default;
1333  
1334 <    if (conf->type == CONF_CLIENT)
1334 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1335        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1336                             "Warning *** Defaulting to default class for %s@%s",
1337                             conf->user, conf->host);
# Line 1368 | Line 1345 | conf_add_class_to_conf(struct MaskItem *
1345  
1346    if (conf->class == NULL)
1347    {
1348 <    if (conf->type == CONF_CLIENT)
1348 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1349        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1350                             "Warning *** Defaulting to default class for %s@%s",
1351                             conf->user, conf->host);
# Line 1555 | Line 1532 | valid_wild_card(struct Client *source_p,
1532    return 0;
1533   }
1534  
1535 + /* find_user_host()
1536 + *
1537 + * inputs       - pointer to client placing kline
1538 + *              - pointer to user_host_or_nick
1539 + *              - pointer to user buffer
1540 + *              - pointer to host buffer
1541 + * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1542 + * side effects -
1543 + */
1544 + static int
1545 + find_user_host(struct Client *source_p, char *user_host_or_nick,
1546 +               char *luser, char *lhost, unsigned int flags)
1547 + {
1548 +  struct Client *target_p = NULL;
1549 +  char *hostp = NULL;
1550 +
1551 +  if (lhost == NULL)
1552 +  {
1553 +    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1554 +    return 1;
1555 +  }
1556 +
1557 +  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1558 +  {
1559 +    /* Explicit user@host mask given */
1560 +    if (hostp)                            /* I'm a little user@host */
1561 +    {
1562 +      *(hostp++) = '\0';                       /* short and squat */
1563 +
1564 +      if (*user_host_or_nick)
1565 +        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1566 +      else
1567 +        strcpy(luser, "*");
1568 +
1569 +      if (*hostp)
1570 +        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1571 +      else
1572 +        strcpy(lhost, "*");
1573 +    }
1574 +    else
1575 +    {
1576 +      luser[0] = '*';             /* no @ found, assume its *@somehost */
1577 +      luser[1] = '\0';
1578 +      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1579 +    }
1580 +
1581 +    return 1;
1582 +  }
1583 +  else
1584 +  {
1585 +    /* Try to find user@host mask from nick */
1586 +    /* Okay to use source_p as the first param, because source_p == client_p */
1587 +    if ((target_p =
1588 +        find_chasing(source_p, user_host_or_nick)) == NULL)
1589 +      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1590 +
1591 +    if (IsExemptKline(target_p))
1592 +    {
1593 +      if (IsClient(source_p))
1594 +        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1595 +      return 0;
1596 +    }
1597 +
1598 +    /*
1599 +     * turn the "user" bit into "*user", blow away '~'
1600 +     * if found in original user name (non-idented)
1601 +     */
1602 +    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1603 +
1604 +    if (target_p->username[0] == '~')
1605 +      luser[0] = '*';
1606 +
1607 +    if (!strcmp(target_p->sockhost, "0"))
1608 +      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1609 +    else
1610 +      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1611 +    return 1;
1612 +  }
1613 +
1614 +  return 0;
1615 + }
1616 +
1617   /* XXX should this go into a separate file ? -Dianora */
1618   /* parse_aline
1619   *
# Line 1601 | Line 1660 | parse_aline(const char *cmd, struct Clie
1660  
1661    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1662  
1663 <  if (found_tkline_time != 0)
1663 >  if (found_tkline_time)
1664    {
1665      parv++;
1666      parc--;
1667  
1668 <    if (tkline_time != NULL)
1668 >    if (tkline_time)
1669        *tkline_time = found_tkline_time;
1670      else
1671      {
# Line 1635 | Line 1694 | parse_aline(const char *cmd, struct Clie
1694    parc--;
1695    parv++;
1696  
1697 <  if (parc != 0)
1697 >  if (parc)
1698    {
1699      if (irccmp(*parv, "ON") == 0)
1700      {
# Line 1669 | Line 1728 | parse_aline(const char *cmd, struct Clie
1728        /* Make sure target_server *is* NULL if no ON server found
1729         * caller probably NULL'd it first, but no harm to do it again -db
1730         */
1731 <      if (target_server != NULL)
1731 >      if (target_server)
1732          *target_server = NULL;
1733      }
1734    }
1735  
1736 <  if (h_p != NULL)
1736 >  if (h_p)
1737    {
1738 <    if (strchr(user, '!') != NULL)
1738 >    if (strchr(user, '!'))
1739      {
1740        sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1741        return -1;
# Line 1689 | Line 1748 | parse_aline(const char *cmd, struct Clie
1748      if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1749        return -1;
1750  
1751 <  if (reason != NULL)
1751 >  if (reason)
1752    {
1753 <    if (parc != 0 && !EmptyString(*parv))
1753 >    if (parc && !EmptyString(*parv))
1754      {
1755        *reason = *parv;
1756 +
1757        if (!valid_comment(source_p, *reason, 1))
1758          return -1;
1759      }
# Line 1704 | Line 1764 | parse_aline(const char *cmd, struct Clie
1764    return 1;
1765   }
1766  
1707 /* find_user_host()
1708 *
1709 * inputs       - pointer to client placing kline
1710 *              - pointer to user_host_or_nick
1711 *              - pointer to user buffer
1712 *              - pointer to host buffer
1713 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1714 * side effects -
1715 */
1716 static int
1717 find_user_host(struct Client *source_p, char *user_host_or_nick,
1718               char *luser, char *lhost, unsigned int flags)
1719 {
1720  struct Client *target_p = NULL;
1721  char *hostp = NULL;
1722
1723  if (lhost == NULL)
1724  {
1725    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1726    return 1;
1727  }
1728
1729  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1730  {
1731    /* Explicit user@host mask given */
1732
1733    if (hostp != NULL)                            /* I'm a little user@host */
1734    {
1735      *(hostp++) = '\0';                       /* short and squat */
1736      if (*user_host_or_nick)
1737        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1738      else
1739        strcpy(luser, "*");
1740
1741      if (*hostp)
1742        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1743      else
1744        strcpy(lhost, "*");
1745    }
1746    else
1747    {
1748      luser[0] = '*';             /* no @ found, assume its *@somehost */
1749      luser[1] = '\0';
1750      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1751    }
1752
1753    return 1;
1754  }
1755  else
1756  {
1757    /* Try to find user@host mask from nick */
1758    /* Okay to use source_p as the first param, because source_p == client_p */
1759    if ((target_p =
1760        find_chasing(source_p, user_host_or_nick)) == NULL)
1761      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1762
1763    if (IsExemptKline(target_p))
1764    {
1765      if (!IsServer(source_p))
1766        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1767      return 0;
1768    }
1769
1770    /*
1771     * turn the "user" bit into "*user", blow away '~'
1772     * if found in original user name (non-idented)
1773     */
1774    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1775
1776    if (target_p->username[0] == '~')
1777      luser[0] = '*';
1778
1779    if (target_p->sockhost[0] == '\0' ||
1780        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
1781      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1782    else
1783      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1784    return 1;
1785  }
1786
1787  return 0;
1788 }
1789
1767   /* valid_comment()
1768   *
1769   * inputs       - pointer to client
# Line 1845 | Line 1822 | cluster_a_line(struct Client *source_p,
1822   {
1823    va_list args;
1824    char buffer[IRCD_BUFSIZE] = "";
1825 <  const dlink_node *ptr = NULL;
1825 >  const dlink_node *node = NULL;
1826  
1827    va_start(args, pattern);
1828    vsnprintf(buffer, sizeof(buffer), pattern, args);
1829    va_end(args);
1830  
1831 <  DLINK_FOREACH(ptr, cluster_items.head)
1831 >  DLINK_FOREACH(node, cluster_items.head)
1832    {
1833 <    const struct MaskItem *conf = ptr->data;
1833 >    const struct MaskItem *conf = node->data;
1834  
1835      if (conf->flags & cluster_type)
1836        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
# Line 1896 | Line 1873 | split_nuh(struct split_nuh_item *const i
1873  
1874    if (iptr->nickptr)
1875      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1876 +
1877    if (iptr->userptr)
1878      strlcpy(iptr->userptr, "*", iptr->usersize);
1879 +
1880    if (iptr->hostptr)
1881      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1882  

Diff Legend

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