authd: be more anal about errors

This commit is contained in:
Elizabeth Myers 2016-03-28 19:22:02 -05:00
parent d8f8474dfd
commit 34b96d7f76
6 changed files with 55 additions and 44 deletions

View File

@ -147,7 +147,7 @@ parse_request(rb_helper *helper)
static void
error_cb(rb_helper *helper)
{
exit(1);
exit(EX_ERROR);
}
#ifndef _WIN32
@ -196,7 +196,7 @@ main(int argc, char *argv[])
if(authd_helper == NULL)
{
fprintf(stderr, "authd is not meant to be invoked by end users\n");
exit(1);
exit(EX_ERROR);
}
rb_set_time();

View File

@ -28,6 +28,13 @@
#include "setup.h"
#include "ircd_defs.h"
typedef enum exit_reasons
{
EX_ERROR = 1,
EX_DNS_ERROR = 2,
EX_PROVIDER_ERROR = 3,
} exit_reasons;
typedef void (*provider_opts_handler_t)(const char *, int, const char **);
struct auth_opts_handler

View File

@ -122,8 +122,11 @@ handle_lookup_ip_reply(void *data, struct DNSReply *reply)
char ip[HOSTIPLEN] = "*";
if(query == NULL)
{
/* Shouldn't happen */
exit(2);
warn_opers(L_CRIT, "DNS: handle_lookup_ip_reply: query == NULL!");
exit(EX_DNS_ERROR);
}
if(reply == NULL)
goto end;
@ -148,7 +151,9 @@ handle_lookup_ip_reply(void *data, struct DNSReply *reply)
break;
#endif
default:
exit(3);
warn_opers(L_CRIT, "DNS: handle_lookup_ip_reply: unknown query type %d",
query->type);
exit(EX_DNS_ERROR);
}
end:
@ -166,8 +171,11 @@ handle_lookup_hostname_reply(void *data, struct DNSReply *reply)
char *hostname = NULL;
if(query == NULL)
{
/* Shouldn't happen */
exit(4);
warn_opers(L_CRIT, "DNS: handle_lookup_hostname_reply: query == NULL!");
exit(EX_DNS_ERROR);
}
if(reply == NULL)
goto end;
@ -193,8 +201,12 @@ handle_lookup_hostname_reply(void *data, struct DNSReply *reply)
}
#endif
else
{
/* Shouldn't happen */
exit(5);
warn_opers(L_CRIT, "DNS: handle_lookup_hostname_reply: unknown query type %d",
query->type);
exit(EX_DNS_ERROR);
}
end:
if(query->callback)
query->callback(hostname, hostname != NULL, query->type, query->data);
@ -208,7 +220,10 @@ submit_dns_answer(const char *reply, bool status, query_type type, void *data)
char *id = data;
if(!id || type == QUERY_INVALID)
exit(6);
{
warn_opers(L_CRIT, "DNS: submit_dns_answer gave us a bad query");
exit(EX_DNS_ERROR);
}
if(reply == NULL || status == false)
{
@ -247,7 +262,8 @@ handle_resolve_dns(int parc, char *parv[])
submit_dns_answer(NULL, false, qtype, NULL);
break;
default:
exit(7);
warn_opers(L_CRIT, "DNS: handle_resolve_dns got an unknown query: %c", qtype);
exit(EX_DNS_ERROR);
}
}
@ -260,8 +276,9 @@ enumerate_nameservers(uint32_t rid, const char letter)
if (!irc_nscount)
{
/* Shouldn't happen */
warn_opers(L_CRIT, "DNS: no name servers!");
stats_error(rid, letter, "NONAMESERVERS");
return;
exit(EX_DNS_ERROR);
}
for(int i = 0; i < irc_nscount; i++)
@ -274,8 +291,9 @@ enumerate_nameservers(uint32_t rid, const char letter)
if (!addr[0])
{
/* Shouldn't happen */
warn_opers(L_CRIT, "DNS: bad nameserver!");
stats_error(rid, letter, "INVALIDNAMESERVER");
return;
exit(EX_DNS_ERROR);
}
addrlen = strlen(addr) + 1;

View File

@ -205,9 +205,9 @@ blacklist_check_reply(struct blacklist_lookup *bllookup, const char *ipaddr)
cmpstr = lastoctet;
else
{
warn_opers(L_CRIT, "BUG: Unknown blacklist filter type on blacklist %s: %d",
warn_opers(L_CRIT, "Blacklist: Unknown blacklist filter type (host %s): %d",
bl->host, filter->type);
continue;
exit(EX_PROVIDER_ERROR);
}
if (strcmp(cmpstr, filter->filter) == 0)
@ -452,7 +452,6 @@ add_conf_blacklist(const char *key, int parc, const char **parv)
struct blacklist_filter *filter = rb_malloc(sizeof(struct blacklist_filter));
int dot_c = 0;
filter_t type = FILTER_LAST;
bool valid = true;
/* Check blacklist filter type and for validity */
for(char *c = elem; *c != '\0'; c++)
@ -461,31 +460,24 @@ add_conf_blacklist(const char *key, int parc, const char **parv)
{
if(++dot_c > 3)
{
warn_opers(L_CRIT, "addr_conf_blacklist got a bad filter (too many octets)");
valid = false;
break;
warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a bad filter (too many octets)");
exit(EX_PROVIDER_ERROR);
}
type = FILTER_ALL;
}
else if(!isdigit(*c))
{
warn_opers(L_CRIT, "addr_conf_blacklist got a bad filter (invalid character in blacklist filter: %c)", *c);
valid = false;
break;
warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a bad filter (invalid character in blacklist filter: %c)",
*c);
exit(EX_PROVIDER_ERROR);
}
}
if(valid && dot_c > 0 && dot_c < 3)
if(dot_c > 0 && dot_c < 3)
{
warn_opers(L_CRIT, "addr_conf_blacklist got a bad filter (insufficient octets)");
valid = false;
}
if(!valid)
{
rb_free(filter);
continue;
warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a bad filter (insufficient octets)");
exit(EX_PROVIDER_ERROR);
}
filter->type = type;
@ -499,15 +491,8 @@ end:
iptype = atoi(parv[1]) & 0x3;
if(new_blacklist(parv[0], parv[3], iptype, &filters) == NULL)
{
rb_dlink_node *ptr, *nptr;
warn_opers(L_CRIT, "addr_conf_blacklist got a malformed blacklist");
RB_DLINK_FOREACH_SAFE(ptr, nptr, filters.head)
{
rb_free(ptr->data);
rb_dlinkDelete(ptr, &filters);
}
warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a malformed blacklist");
exit(EX_PROVIDER_ERROR);
}
}
@ -517,7 +502,8 @@ del_conf_blacklist(const char *key, int parc, const char **parv)
struct blacklist *bl = find_blacklist(parv[0]);
if(bl == NULL)
{
warn_opers(L_CRIT, "BUG: tried to remove nonexistent blacklist %s", parv[0]);
/* Not fatal for now... */
warn_opers(L_WARN, "Blacklist: tried to remove nonexistent blacklist %s", parv[0]);
return;
}
@ -537,8 +523,8 @@ add_conf_blacklist_timeout(const char *key, int parc, const char **parv)
if(timeout < 0)
{
warn_opers(L_CRIT, "BUG: blacklist timeout < 0 (value: %d)", timeout);
return;
warn_opers(L_CRIT, "Blacklist: blacklist timeout < 0 (value: %d)", timeout);
exit(EX_PROVIDER_ERROR);
}
blacklist_timeout = timeout;

View File

@ -392,8 +392,8 @@ add_conf_ident_timeout(const char *key __unused, int parc __unused, const char *
if(timeout < 0)
{
warn_opers(L_CRIT, "BUG: ident timeout < 0 (value: %d)", timeout);
return;
warn_opers(L_CRIT, "Ident: ident timeout < 0 (value: %d)", timeout);
exit(EX_PROVIDER_ERROR);
}
ident_timeout = timeout;

View File

@ -180,8 +180,8 @@ add_conf_dns_timeout(const char *key, int parc, const char **parv)
if(timeout < 0)
{
warn_opers(L_CRIT, "BUG: DNS timeout < 0 (value: %d)", timeout);
return;
warn_opers(L_CRIT, "rDNS: DNS timeout < 0 (value: %d)", timeout);
exit(EX_PROVIDER_ERROR);
}
rdns_timeout = timeout;