From 414b916d07f4a1b475d53627092d24cd5a2a0517 Mon Sep 17 00:00:00 2001 From: venaas Date: Thu, 3 May 2007 14:42:40 +0000 Subject: using debug() some more places git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@70 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- radsecproxy.c | 44 +++++++++++++++++--------------------------- util.c | 3 ++- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/radsecproxy.c b/radsecproxy.c index c7d65f5..aceb9d3 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -201,7 +201,7 @@ int resolvepeer(struct peer *peer, int ai_flags) { hints.ai_family = AF_UNSPEC; hints.ai_flags = ai_flags; if (getaddrinfo(peer->host, peer->port, &hints, &addrinfo)) { - err("resolvepeer: can't resolve %s port %s", peer->host, peer->port); + debug(DBG_WARN, "resolvepeer: can't resolve %s port %s", peer->host, peer->port); return 0; } @@ -1601,35 +1601,28 @@ char *parsehostport(char *s, struct peer *peer) { p++; field = p; for (; *p && *p != ']' && *p != ' ' && *p != '\t' && *p != '\n'; p++); - if (*p != ']') { - printf("no ] matching initial [\n"); - exit(1); - } + if (*p != ']') + debug(DBG_ERR, "no ] matching initial ["); ipv6 = 1; } else { field = p; for (; *p && *p != ':' && *p != ' ' && *p != '\t' && *p != '\n'; p++); } - if (field == p) { - printf("missing host/address\n"); - exit(1); - } + if (field == p) + debug(DBG_ERR, "missing host/address"); + peer->host = stringcopy(field, p - field); if (ipv6) { p++; - if (*p && *p != ':' && *p != ' ' && *p != '\t' && *p != '\n') { - printf("unexpected character after ]\n"); - exit(1); - } + if (*p && *p != ':' && *p != ' ' && *p != '\t' && *p != '\n') + debug(DBG_ERR, "unexpected character after ]"); } if (*p == ':') { /* port number or service name is specified */; field = ++p; for (; *p && *p != ' ' && *p != '\t' && *p != '\n'; p++); - if (field == p) { - printf("syntax error, : but no following port\n"); - exit(1); - } + if (field == p) + debug(DBG_ERR, "syntax error, : but no following port"); peer->port = stringcopy(field, p - field); } else peer->port = stringcopy(peer->type == 'U' ? DEFAULT_UDP_PORT : DEFAULT_TLS_PORT, 0); @@ -1645,14 +1638,13 @@ char *parserealmlist(char *s, struct server *server) { if (*p == ';') n++; l = p - s; - if (!l) { - printf("realm list must be specified\n"); - exit(1); - } + if (!l) + debug(DBG_ERR, "realm list must be specified"); + server->realmdata = stringcopy(s, l); server->realms = malloc((1+n) * sizeof(char *)); if (!server->realms) - errx("malloc failed"); + debug(DBG_ERR, "malloc failed"); server->realms[0] = server->realmdata; for (n = 1, i = 0; i < l; i++) if (server->realmdata[i] == ';') { @@ -1825,7 +1817,7 @@ struct peer *server_create(char type) { server = malloc(sizeof(struct peer)); if (!server) - errx("malloc failed"); + debug(DBG_ERR, "malloc failed"); memset(server, 0, sizeof(struct peer)); server->type = type; conf = (type == 'T' ? options.listentcp : options.listenudp); @@ -1837,10 +1829,8 @@ struct peer *server_create(char type) { } } else server->port = stringcopy(type == 'T' ? DEFAULT_TLS_PORT : DEFAULT_UDP_PORT, 0); - if (!resolvepeer(server, AI_PASSIVE)) { - printf("failed to resolve host %s port %s, exiting\n", server->host, server->port); - exit(1); - } + if (!resolvepeer(server, AI_PASSIVE)) + debug(DBG_ERR, "failed to resolve host %s port %s, exiting", server->host, server->port); return server; } diff --git a/util.c b/util.c index ae733eb..77fa004 100644 --- a/util.c +++ b/util.c @@ -15,6 +15,7 @@ #include #include #include +#include "debug.h" void errx(char *format, ...) { extern int errno; @@ -53,7 +54,7 @@ char *stringcopy(char *s, int len) { len = strlen(s); r = malloc(len + 1); if (!r) - errx("stringcopy: malloc failed"); + debug(DBG_ERR, "stringcopy: malloc failed"); memcpy(r, s, len); r[len] = '\0'; return r; -- cgit v1.1