diff options
author | michael <michael@82007160-df01-0410-b94d-b575c5fd34c7> | 2012-11-04 17:09:47 +0000 |
---|---|---|
committer | michael <michael@82007160-df01-0410-b94d-b575c5fd34c7> | 2012-11-04 17:09:47 +0000 |
commit | 7d878fff67e99f144aa1df6c43c5ac8fe957bee6 (patch) | |
tree | 9864755e4a8346eafa07ad4e393c69b432ae181c | |
parent | b718094b79a1f3619a2269e67f9a492105c2cf70 (diff) |
- Cleanup configuration subsystem
- Fixed broken CIDR support for /challenge
git-svn-id: svn://svn.ircd-hybrid.org/svnroot/ircd-hybrid/trunk@1636 82007160-df01-0410-b94d-b575c5fd34c7
-rw-r--r-- | contrib/m_webirc.c | 2 | ||||
-rw-r--r-- | include/conf.h | 6 | ||||
-rw-r--r-- | modules/m_challenge.c | 7 | ||||
-rw-r--r-- | modules/m_connect.c | 39 | ||||
-rw-r--r-- | modules/m_testline.c | 6 | ||||
-rw-r--r-- | src/client.c | 4 | ||||
-rw-r--r-- | src/conf.c | 382 | ||||
-rwxr-xr-x | src/conf_class.c | 3 | ||||
-rw-r--r-- | src/s_serv.c | 2 |
9 files changed, 42 insertions, 409 deletions
diff --git a/contrib/m_webirc.c b/contrib/m_webirc.c index cd6b761..1c6083b 100644 --- a/contrib/m_webirc.c +++ b/contrib/m_webirc.c @@ -166,7 +166,7 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, char *parv if ((conf = find_dline_conf(&client_p->localClient->ip, client_p->localClient->aftype))) { - if (!(conf->status & CONF_EXEMPT)) + if (!(conf->type == CONF_EXEMPT)) { exit_client(client_p, &me, "D-lined"); return; diff --git a/include/conf.h b/include/conf.h index 81648d4..ac17aa2 100644 --- a/include/conf.h +++ b/include/conf.h @@ -90,7 +90,6 @@ struct MaskItem enum maskitem_type type; unsigned int dns_failed; unsigned int dns_pending; - unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ unsigned int flags; unsigned int modes; unsigned int port; @@ -132,9 +131,9 @@ struct CidrItem }; -#define IsConfOperator(x) ((x)->type & CONF_OPER) +#define IsConfOperator(x) ((x)->type == CONF_OPER) #define IsConfKill(x) ((x)->type == CONF_KLINE) -#define IsConfClient(x) ((x)->type & CONF_CLIENT) +#define IsConfClient(x) ((x)->type == CONF_CLIENT) #define IsConfGline(x) ((x)->type == CONF_GLINE) /* MaskItem->flags */ @@ -363,7 +362,6 @@ extern int get_conf_ping(const struct MaskItem *, int *); extern void detach_conf(struct Client *, enum maskitem_type); extern struct MaskItem *find_conf_name(dlink_list *, const char *, enum maskitem_type); -extern struct MaskItem *find_conf_exact(enum maskitem_type, const char *, const char *, const char *); extern struct MaskItem *find_kill(struct Client *); extern struct MaskItem *find_gline(struct Client *); extern int conf_connect_allowed(struct irc_ssaddr *, int); diff --git a/modules/m_challenge.c b/modules/m_challenge.c index 2327ee7..7293e7b 100644 --- a/modules/m_challenge.c +++ b/modules/m_challenge.c @@ -123,12 +123,7 @@ m_challenge(struct Client *client_p, struct Client *source_p, source_p->localClient->response = NULL; source_p->localClient->auth_oper = NULL; - if ((conf = find_conf_exact(CONF_OPER, - parv[1], source_p->username, source_p->host))) - ; - else if ((conf = find_conf_exact(CONF_OPER, parv[1], source_p->username, - source_p->sockhost))) - ; + conf = find_exact_name_conf(CONF_OPER, source_p, parv[1], NULL, NULL); if (!conf) { diff --git a/modules/m_connect.c b/modules/m_connect.c index b769d8b..1d27f53 100644 --- a/modules/m_connect.c +++ b/modules/m_connect.c @@ -90,17 +90,15 @@ mo_connect(struct Client *client_p, struct Client *source_p, /* * try to find the name, then host, if both fail notify ops and bail */ - if ((conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0))) - ; - else if ((conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0))) - ; - - if (!conf) + if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0))) { - sendto_one(source_p, - ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", - me.name, source_p->name, parv[1]); - return; + if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0))) + { + sendto_one(source_p, + ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", + me.name, source_p->name, parv[1]); + return; + } } /* Get port number from user, if given. If not specified, @@ -207,18 +205,15 @@ ms_connect(struct Client *client_p, struct Client *source_p, /* * try to find the name, then host, if both fail notify ops and bail */ - - if ((conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0))) - ; - else if ((conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0))) - ; - - if (!conf) - { - sendto_one(source_p, - ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", - me.name, source_p->name, parv[1]); - return; + if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0))) + { + if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0))) + { + sendto_one(source_p, + ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", + me.name, source_p->name, parv[1]); + return; + } } /* Get port number from user, if given. If not specified, diff --git a/modules/m_testline.c b/modules/m_testline.c index 4164b2d..086b141 100644 --- a/modules/m_testline.c +++ b/modules/m_testline.c @@ -114,7 +114,7 @@ mo_testline(struct Client *client_p, struct Client *source_p, if (conf != NULL) { ++matches; - if (conf->status & CONF_EXEMPT) + if (conf->type == CONF_EXEMPT) sendto_one(source_p, ":%s NOTICE %s :Exempt D-line host [%s] reason [%s]", me.name, source_p->name, conf->host, conf->reason); @@ -143,14 +143,14 @@ mo_testline(struct Client *client_p, struct Client *source_p, { snprintf(userhost, sizeof(userhost), "%s@%s", conf->user, conf->host); - if (conf->status & CONF_CLIENT) + if (conf->type == CONF_CLIENT) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, 'I', 0L, userhost, conf->class ? conf->class->name : "<default>", ""); ++matches; } - else if (conf->status & CONF_KLINE) + else if (conf->type == CONF_KLINE) { sendto_one(source_p, form_str(RPL_TESTLINE), me.name, source_p->name, diff --git a/src/client.c b/src/client.c index 33f8dc6..890e893 100644 --- a/src/client.c +++ b/src/client.c @@ -367,7 +367,7 @@ check_conf_klines(void) if ((conf = find_dline_conf(&client_p->localClient->ip, client_p->localClient->aftype)) != NULL) { - if (conf->status & CONF_EXEMPT) + if (conf->type == CONF_EXEMPT) continue; ban_them(client_p, conf); @@ -422,7 +422,7 @@ check_conf_klines(void) if ((conf = find_dline_conf(&client_p->localClient->ip, client_p->localClient->aftype))) { - if (conf->status & CONF_EXEMPT) + if (conf->type == CONF_EXEMPT) continue; exit_client(client_p, &me, "D-lined"); @@ -171,7 +171,12 @@ void conf_free(struct MaskItem *conf) { dlink_node *ptr = NULL, *ptr_next = NULL; - + dlink_list *list = NULL; + + if (conf->node.next) + if ((list = map_to_list(conf->type))) + dlinkDelete(&conf->node, list); + MyFree(conf->name); if (conf->dns_pending) @@ -188,6 +193,8 @@ conf_free(struct MaskItem *conf) MyFree(conf->reason); MyFree(conf->user); MyFree(conf->host); + MyFree(conf->regexuser); + MyFree(conf->regexhost); #ifdef HAVE_LIBCRYPTO MyFree(conf->cipher_list); @@ -207,325 +214,10 @@ conf_free(struct MaskItem *conf) MyFree(ptr->data); free_dlink_node(ptr); } -} -#if 0 -/* make_conf_item() - * - * inputs - type of item - * output - pointer to new conf entry - * side effects - none - */ -struct ConfItem * -make_conf_item(ConfType type) -{ - struct ConfItem *conf = NULL; - struct AccessItem *aconf = NULL; - struct ClassItem *aclass = NULL; - int status = 0; - - switch (type) - { - case DLINE_TYPE: - case EXEMPTDLINE_TYPE: - case GLINE_TYPE: - case KLINE_TYPE: - case CLIENT_TYPE: - case OPER_TYPE: - case SERVER_TYPE: - conf = MyMalloc(sizeof(struct ConfItem) + - sizeof(struct AccessItem)); - aconf = map_to_conf(conf); - aconf->aftype = AF_INET; - - /* Yes, sigh. switch on type again */ - switch (type) - { - case EXEMPTDLINE_TYPE: - status = CONF_EXEMPTDLINE; - break; - - case DLINE_TYPE: - status = CONF_DLINE; - break; - - case KLINE_TYPE: - status = CONF_KLINE; - break; - - case GLINE_TYPE: - status = CONF_GLINE; - break; - - case CLIENT_TYPE: - status = CONF_CLIENT; - break; - - case OPER_TYPE: - status = CONF_OPERATOR; - dlinkAdd(conf, &conf->node, &oconf_items); - break; - - case SERVER_TYPE: - status = CONF_SERVER; - dlinkAdd(conf, &conf->node, &server_items); - break; - - default: - break; - } - aconf->status = status; - break; - - case ULINE_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + - sizeof(struct MatchItem)); - dlinkAdd(conf, &conf->node, &uconf_items); - break; - - case XLINE_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + - sizeof(struct MatchItem)); - dlinkAdd(conf, &conf->node, &xconf_items); - break; -#ifdef HAVE_LIBPCRE - case RXLINE_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + - sizeof(struct MatchItem)); - dlinkAdd(conf, &conf->node, &rxconf_items); - break; - - case RKLINE_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + - sizeof(struct AccessItem)); - aconf = map_to_conf(conf); - aconf->status = CONF_KLINE; - dlinkAdd(conf, &conf->node, &rkconf_items); - break; -#endif - case CLUSTER_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem)); - dlinkAdd(conf, &conf->node, &cluster_items); - break; - - case CRESV_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + - sizeof(struct ResvChannel)); - break; - - case NRESV_TYPE: - conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + - sizeof(struct MatchItem)); - dlinkAdd(conf, &conf->node, &nresv_items); - break; - - case SERVICE_TYPE: - status = CONF_SERVICE; - conf = MyMalloc(sizeof(struct ConfItem)); - dlinkAdd(conf, &conf->node, &service_items); - break; - - case CONF_CLASS: - conf = MyMalloc(sizeof(struct ConfItem) + - sizeof(struct ClassItem)); - dlinkAdd(conf, &conf->node, &class_items); - - aclass = map_to_conf(conf); - aclass->active = 1; - aclass->con_freq = DEFAULT_CONNECTFREQUENCY; - aclass->ping_freq = DEFAULT_PINGFREQUENCY; - aclass->max_total = MAXIMUM_LINKS_DEFAULT; - aclass->max_sendq = DEFAULT_SENDQ; - aclass->max_recvq = DEFAULT_RECVQ; - - break; - - default: - conf = NULL; - break; - } - /* XXX Yes, this will core if default is hit. I want it to for now - db */ - conf->type = type; - - return conf; + MyFree(conf); } -void -delete_conf_item(struct ConfItem *conf) -{ - dlink_node *m = NULL, *m_next = NULL; - struct MatchItem *match_item; - struct AccessItem *aconf; - ConfType type = conf->type; - - MyFree(conf->name); - conf->name = NULL; - - switch(type) - { - case DLINE_TYPE: - case EXEMPTDLINE_TYPE: - case GLINE_TYPE: - case KLINE_TYPE: - case CLIENT_TYPE: - case OPER_TYPE: - case SERVER_TYPE: - aconf = map_to_conf(conf); - - if (aconf->dns_pending) - delete_resolver_queries(aconf); - if (aconf->passwd != NULL) - memset(aconf->passwd, 0, strlen(aconf->passwd)); - if (aconf->spasswd != NULL) - memset(aconf->spasswd, 0, strlen(aconf->spasswd)); - aconf->class_ptr = NULL; - - MyFree(aconf->passwd); - MyFree(aconf->spasswd); - MyFree(aconf->reason); - MyFree(aconf->user); - MyFree(aconf->host); -#ifdef HAVE_LIBCRYPTO - MyFree(aconf->cipher_list); - - if (aconf->rsa_public_key) - RSA_free(aconf->rsa_public_key); - MyFree(aconf->rsa_public_key_file); -#endif - - /* Yes, sigh. switch on type again */ - switch(type) - { - case EXEMPTDLINE_TYPE: - case DLINE_TYPE: - case GLINE_TYPE: - case KLINE_TYPE: - case CLIENT_TYPE: - MyFree(conf); - break; - - case OPER_TYPE: - aconf = map_to_conf(conf); - if (!IsConfIllegal(aconf)) - dlinkDelete(&conf->node, &oconf_items); - MyFree(conf); - break; - - case SERVER_TYPE: - aconf = map_to_conf(conf); - - DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head) - { - MyFree(m->data); - free_dlink_node(m); - } - - DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head) - { - MyFree(m->data); - free_dlink_node(m); - } - - if (!IsConfIllegal(aconf)) - dlinkDelete(&conf->node, &server_items); - MyFree(conf); - break; - - default: - break; - } - break; - - case ULINE_TYPE: - match_item = map_to_conf(conf); - MyFree(match_item->user); - MyFree(match_item->host); - MyFree(match_item->reason); - dlinkDelete(&conf->node, &uconf_items); - MyFree(conf); - break; - - case XLINE_TYPE: - match_item = map_to_conf(conf); - MyFree(match_item->user); - MyFree(match_item->host); - MyFree(match_item->reason); - dlinkDelete(&conf->node, &xconf_items); - MyFree(conf); - break; -#ifdef HAVE_LIBPCRE - case RKLINE_TYPE: - aconf = map_to_conf(conf); - MyFree(aconf->regexuser); - MyFree(aconf->regexhost); - MyFree(aconf->user); - MyFree(aconf->host); - MyFree(aconf->reason); - dlinkDelete(&conf->node, &rkconf_items); - MyFree(conf); - break; - - case RXLINE_TYPE: - MyFree(conf->regexpname); - match_item = map_to_conf(conf); - MyFree(match_item->user); - MyFree(match_item->host); - MyFree(match_item->reason); - dlinkDelete(&conf->node, &rxconf_items); - MyFree(conf); - break; -#endif - case NRESV_TYPE: - match_item = map_to_conf(conf); - MyFree(match_item->user); - MyFree(match_item->host); - MyFree(match_item->reason); - dlinkDelete(&conf->node, &nresv_items); - MyFree(conf); - break; - - case CLUSTER_TYPE: - dlinkDelete(&conf->node, &cluster_items); - MyFree(conf); - break; - - case CRESV_TYPE: - MyFree(conf); - break; - - case CLASS_TYPE: - dlinkDelete(&conf->node, &class_items); - MyFree(conf); - break; - - case SERVICE_TYPE: - dlinkDelete(&conf->node, &service_items); - MyFree(conf); - break; - - default: - break; - } -} - -/* free_access_item() - * - * inputs - pointer to conf to free - * output - none - * side effects - crucial password fields are zeroed, conf is freed - */ -void -free_access_item(struct AccessItem *aconf) -{ - struct ConfItem *conf; - - if (aconf == NULL) - return; - conf = unmap_conf_item(aconf); - delete_conf_item(conf); -} -#endif - static const unsigned int shared_bit_table[] = { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0}; @@ -1285,56 +977,6 @@ attach_connect_block(struct Client *client_p, const char *name, return 0; } -/* find_conf_exact() - * - * inputs - type of MaskItem - * - pointer to name to find - * - pointer to username to find - * - pointer to host to find - * output - NULL or pointer to conf found - * side effects - find a conf entry which matches the hostname - * and has the same name. - */ -struct MaskItem * -find_conf_exact(enum maskitem_type type, const char *name, const char *user, - const char *host) -{ - dlink_node *ptr; - dlink_list *list_p; - struct MaskItem *conf = NULL; - - /* Only valid for OPER_TYPE and ...? */ - list_p = map_to_list(type); - - DLINK_FOREACH(ptr, (*list_p).head) - { - conf = ptr->data; - - if (conf->name == NULL) - continue; - if (conf->host == NULL) - continue; - - if (irccmp(conf->name, name) != 0) - continue; - - /* - ** Accept if the *real* hostname (usually sockethost) - ** socket host) matches *either* host or name field - ** of the configuration. - */ - if (!match(conf->host, host) || !match(conf->user, user)) - continue; - if (type == CONF_OPER) - if (conf->clients >= conf->class->max_total) - continue; - - return conf; - } - - return NULL; -} - /* find_conf_name() * * inputs - pointer to conf link list to search @@ -1543,10 +1185,12 @@ find_exact_name_conf(enum maskitem_type type, const struct Client *who, const ch if (!irccmp(conf->name, name)) { + if (conf->class->ref_count >= conf->class->max_total) + continue; if (!who) return conf; if (EmptyString(conf->user) || EmptyString(conf->host)) - return conf; + return NULL; if (match(conf->user, who->username)) { switch (conf->htype) @@ -1857,7 +1501,7 @@ conf_connect_allowed(struct irc_ssaddr *addr, int aftype) struct MaskItem *conf = find_dline_conf(addr, aftype); /* DLINE exempt also gets you out of static limits/pacing... */ - if (conf && (conf->status & CONF_EXEMPT)) + if (conf && (conf->type == CONF_EXEMPT)) return 0; if (conf != NULL) diff --git a/src/conf_class.c b/src/conf_class.c index 0022b4e..ee2a2b3 100755 --- a/src/conf_class.c +++ b/src/conf_class.c @@ -94,8 +94,9 @@ class_init(void) { class_default = class_make(); - class_default->active = 1; DupString(class_default->name, "default"); + + class_default->active = 1; class_default->con_freq = DEFAULT_CONNECTFREQUENCY; class_default->ping_freq = DEFAULT_PINGFREQUENCY; class_default->max_total = MAXIMUM_LINKS_DEFAULT; diff --git a/src/s_serv.c b/src/s_serv.c index 69e40cb..cf787f8 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -283,7 +283,7 @@ try_connections(void *unused) { conf = ptr->data; - assert(conf->status & CONF_SERVER); + assert(conf->type == CONF_SERVER); /* Also when already connecting! (update holdtimes) --SRB */ |