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

View file

@ -28,6 +28,13 @@
#include "setup.h" #include "setup.h"
#include "ircd_defs.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 **); typedef void (*provider_opts_handler_t)(const char *, int, const char **);
struct auth_opts_handler struct auth_opts_handler

View file

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

View file

@ -205,9 +205,9 @@ blacklist_check_reply(struct blacklist_lookup *bllookup, const char *ipaddr)
cmpstr = lastoctet; cmpstr = lastoctet;
else 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); bl->host, filter->type);
continue; exit(EX_PROVIDER_ERROR);
} }
if (strcmp(cmpstr, filter->filter) == 0) 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)); struct blacklist_filter *filter = rb_malloc(sizeof(struct blacklist_filter));
int dot_c = 0; int dot_c = 0;
filter_t type = FILTER_LAST; filter_t type = FILTER_LAST;
bool valid = true;
/* Check blacklist filter type and for validity */ /* Check blacklist filter type and for validity */
for(char *c = elem; *c != '\0'; c++) 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) if(++dot_c > 3)
{ {
warn_opers(L_CRIT, "addr_conf_blacklist got a bad filter (too many octets)"); warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a bad filter (too many octets)");
valid = false; exit(EX_PROVIDER_ERROR);
break;
} }
type = FILTER_ALL; type = FILTER_ALL;
} }
else if(!isdigit(*c)) else if(!isdigit(*c))
{ {
warn_opers(L_CRIT, "addr_conf_blacklist got a bad filter (invalid character in blacklist filter: %c)", *c); warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a bad filter (invalid character in blacklist filter: %c)",
valid = false; *c);
break; 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)"); warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a bad filter (insufficient octets)");
valid = false; exit(EX_PROVIDER_ERROR);
}
if(!valid)
{
rb_free(filter);
continue;
} }
filter->type = type; filter->type = type;
@ -499,15 +491,8 @@ end:
iptype = atoi(parv[1]) & 0x3; iptype = atoi(parv[1]) & 0x3;
if(new_blacklist(parv[0], parv[3], iptype, &filters) == NULL) if(new_blacklist(parv[0], parv[3], iptype, &filters) == NULL)
{ {
rb_dlink_node *ptr, *nptr; warn_opers(L_CRIT, "Blacklist: addr_conf_blacklist got a malformed blacklist");
exit(EX_PROVIDER_ERROR);
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);
}
} }
} }
@ -517,7 +502,8 @@ del_conf_blacklist(const char *key, int parc, const char **parv)
struct blacklist *bl = find_blacklist(parv[0]); struct blacklist *bl = find_blacklist(parv[0]);
if(bl == NULL) 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; return;
} }
@ -537,8 +523,8 @@ add_conf_blacklist_timeout(const char *key, int parc, const char **parv)
if(timeout < 0) if(timeout < 0)
{ {
warn_opers(L_CRIT, "BUG: blacklist timeout < 0 (value: %d)", timeout); warn_opers(L_CRIT, "Blacklist: blacklist timeout < 0 (value: %d)", timeout);
return; exit(EX_PROVIDER_ERROR);
} }
blacklist_timeout = timeout; 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) if(timeout < 0)
{ {
warn_opers(L_CRIT, "BUG: ident timeout < 0 (value: %d)", timeout); warn_opers(L_CRIT, "Ident: ident timeout < 0 (value: %d)", timeout);
return; exit(EX_PROVIDER_ERROR);
} }
ident_timeout = timeout; ident_timeout = timeout;

View file

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