Commit d3815dfd authored by linus's avatar linus Committed by linus

Reindent and remove trailing whitespace.

git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@517 e88ac4ed-0b26-0410-9574-a7f39faa03bf
parent 317902ce
......@@ -68,7 +68,7 @@ int debug_set_destination(char *dest) {
LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 };
extern int errno;
int i;
if (!strncasecmp(dest, "file:///", 8)) {
debug_filepath = stringcopy(dest + 7, 0);
debug_file = fopen(debug_filepath, "a");
......@@ -127,7 +127,7 @@ void debug_logit(uint8_t level, const char *format, va_list ap) {
struct timeval now;
char *timebuf;
int priority;
if (debug_syslogfacility) {
switch (level) {
case DBG_DBG:
......
......@@ -95,7 +95,7 @@ struct sessioncacheentry {
struct dtlsservernewparams {
struct sessioncacheentry *sesscache;
int sock;
struct sockaddr_storage addr;
struct sockaddr_storage addr;
};
void dtlssetsrcres() {
......@@ -109,7 +109,7 @@ int udp2bio(int s, struct gqueue *q, int cnt) {
if (cnt < 1)
return 0;
buf = malloc(cnt);
if (!buf) {
unsigned char err;
......@@ -162,7 +162,7 @@ BIO *getrbio(SSL *ssl, struct gqueue *q, int timeout) {
int dtlsread(SSL *ssl, struct gqueue *q, unsigned char *buf, int num, int timeout) {
int len, cnt;
BIO *rbio;
for (len = 0; len < num; len += cnt) {
cnt = SSL_read(ssl, buf + len, num - len);
if (cnt <= 0)
......@@ -171,7 +171,7 @@ int dtlsread(SSL *ssl, struct gqueue *q, unsigned char *buf, int num, int timeou
rbio = getrbio(ssl, q, timeout);
if (!rbio)
return 0;
BIO_free(ssl->rbio);
BIO_free(ssl->rbio);
ssl->rbio = rbio;
cnt = 0;
continue;
......@@ -199,7 +199,7 @@ SSL *dtlsacccon(uint8_t acc, SSL_CTX *ctx, int s, struct sockaddr *addr, struct
ssl = SSL_new(ctx);
if (!ssl)
return NULL;
mem0bio = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(mem0bio, -1);
wbio = BIO_new_dgram(s, BIO_NOCLOSE);
......@@ -244,21 +244,21 @@ unsigned char *raddtlsget(SSL *ssl, struct gqueue *rbios, int timeout) {
continue;
}
memcpy(rad, buf, 4);
cnt = dtlsread(ssl, rbios, rad + 4, len - 4, timeout);
if (cnt < 1) {
debug(DBG_DBG, cnt ? "raddtlsget: connection lost" : "raddtlsget: timeout");
free(rad);
return NULL;
}
if (len >= 20)
break;
free(rad);
debug(DBG_WARN, "raddtlsget: packet smaller than minimum radius size");
}
debug(DBG_DBG, "raddtlsget: got %d bytes", len);
return rad;
}
......@@ -269,13 +269,13 @@ void *dtlsserverwr(void *arg) {
struct client *client = (struct client *)arg;
struct gqueue *replyq;
struct request *reply;
debug(DBG_DBG, "dtlsserverwr: starting for %s", addr2string(client->addr));
replyq = client->replyq;
for (;;) {
pthread_mutex_lock(&replyq->mutex);
while (!list_first(replyq->entries)) {
if (client->ssl) {
if (client->ssl) {
debug(DBG_DBG, "dtlsserverwr: waiting for signal");
pthread_cond_wait(&replyq->cond, &replyq->mutex);
debug(DBG_DBG, "dtlsserverwr: got signal");
......@@ -305,7 +305,7 @@ void dtlsserverrd(struct client *client) {
struct request *rq;
uint8_t *buf;
pthread_t dtlsserverwrth;
debug(DBG_DBG, "dtlsserverrd: starting for %s", addr2string(client->addr));
if (pthread_create(&dtlsserverwrth, NULL, dtlsserverwr, (void *)client)) {
......@@ -332,7 +332,7 @@ void dtlsserverrd(struct client *client) {
break;
}
}
/* stop writer by setting ssl to NULL and give signal in case waiting for data */
client->ssl = NULL;
......@@ -392,7 +392,7 @@ void *dtlsservernew(void *arg) {
if (cert)
X509_free(cert);
exit:
exit:
if (ssl) {
SSL_shutdown(ssl);
SSL_free(ssl);
......@@ -413,7 +413,7 @@ void cacheexpire(struct hash *cache, struct timeval *last) {
struct timeval now;
struct hash_entry *he;
struct sessioncacheentry *e;
gettimeofday(&now, NULL);
if (now.tv_sec - last->tv_sec < 19)
return;
......@@ -448,12 +448,12 @@ void *udpdtlsserverrd(void *arg) {
pthread_t dtlsserverth;
struct hash *sessioncache;
struct sessioncacheentry *cacheentry;
sessioncache = hash_create();
if (!sessioncache)
debugx(1, DBG_ERR, "udpdtlsserverrd: malloc failed");
gettimeofday(&lastexpiry, NULL);
for (;;) {
FD_ZERO(&readfds);
FD_SET(s, &readfds);
......@@ -532,7 +532,7 @@ int dtlsconnect(struct server *server, struct timeval *when, int timeout, char *
X509 *cert;
SSL_CTX *ctx = NULL;
struct hostportres *hp;
debug(DBG_DBG, "dtlsconnect: called from %s", text);
pthread_mutex_lock(&server->lock);
if (when && memcmp(&server->lastconnecttry, when, sizeof(struct timeval))) {
......@@ -579,11 +579,11 @@ int dtlsconnect(struct server *server, struct timeval *when, int timeout, char *
if (!server->ssl)
continue;
debug(DBG_DBG, "dtlsconnect: DTLS: ok");
cert = verifytlscert(server->ssl);
if (!cert)
continue;
if (verifyconfcert(cert, server->conf))
break;
X509_free(cert);
......@@ -622,7 +622,7 @@ void *udpdtlsclientrd(void *arg) {
socklen_t fromlen = sizeof(from);
struct clsrvconf *conf;
fd_set readfds;
for (;;) {
FD_ZERO(&readfds);
FD_SET(s, &readfds);
......@@ -633,7 +633,7 @@ void *udpdtlsclientrd(void *arg) {
debug(DBG_WARN, "udpdtlsclientrd: recv failed");
continue;
}
conf = find_srvconf(handle, (struct sockaddr *)&from, NULL);
if (!conf) {
debug(DBG_WARN, "udpdtlsclientrd: got packet from wrong or unknown DTLS peer %s, ignoring", addr2string((struct sockaddr *)&from));
......@@ -650,7 +650,7 @@ void *dtlsclientrd(void *arg) {
unsigned char *buf;
struct timeval lastconnecttry;
int secs;
for (;;) {
/* yes, lastconnecttry is really necessary */
lastconnecttry = server->lastconnecttry;
......@@ -696,7 +696,7 @@ void initextradtls() {
freeaddrinfo(srcres);
srcres = NULL;
}
if (client4_sock >= 0)
if (pthread_create(&cl4th, NULL, udpdtlsclientrd, (void *)&client4_sock))
debugx(1, DBG_ERR, "pthread_create failed");
......
......@@ -87,7 +87,7 @@ FILE *pushgconffile(struct gconffile **cf, FILE *file, const char *description)
desc = stringcopy(description, 0);
if (!desc)
goto errmalloc;
if (!*cf) {
newcf = malloc(sizeof(struct gconffile) * 2);
if (!newcf)
......@@ -105,8 +105,8 @@ FILE *pushgconffile(struct gconffile **cf, FILE *file, const char *description)
newcf[0].path = desc;
*cf = newcf;
return file;
errmalloc:
errmalloc:
free(desc);
fclose(file);
debug(DBG_ERR, "malloc failed");
......@@ -125,7 +125,7 @@ FILE *pushgconfpaths(struct gconffile **cf, const char *cfgpath) {
FILE *f = NULL;
glob_t globbuf;
char *path, *curfile = NULL, *dir;
/* if cfgpath is relative, make it relative to current config */
if (*cfgpath == '/')
path = (char *)cfgpath;
......@@ -156,10 +156,10 @@ FILE *pushgconfpaths(struct gconffile **cf, const char *cfgpath) {
f = pushgconfpath(cf, globbuf.gl_pathv[i]);
if (!f)
break;
}
}
globfree(&globbuf);
exit:
exit:
if (curfile) {
free(curfile);
free(path);
......@@ -204,7 +204,7 @@ void freegconf(struct gconffile **cf) {
if (!*cf)
return;
for (i = 0; (*cf)[i].data || (*cf)[i].path; i++) {
if ((*cf)[i].file) {
fclose((*cf)[i].file);
......@@ -242,10 +242,10 @@ struct gconffile *openconfigfile(const char *file) {
int getlinefromcf(struct gconffile *cf, char *line, const size_t size) {
size_t i, pos;
if (!cf)
return 0;
if (cf->file)
return fgets(line, size, cf->file) ? 1 : 0;
else if (cf->data) {
......@@ -269,11 +269,11 @@ int getconfigline(struct gconffile **cf, char *block, char **opt, char **val, in
char line[1024];
char *tokens[3], *s;
int tcount;
*opt = NULL;
*val = NULL;
*conftype = 0;
if (!cf || !*cf || (!(*cf)->file && !(*cf)->data))
return 1;
......@@ -304,7 +304,7 @@ int getconfigline(struct gconffile **cf, char *block, char **opt, char **val, in
}
break;
}
switch (tcount) {
case 2:
*opt = stringcopy(tokens[0], 0);
......@@ -347,13 +347,13 @@ int getconfigline(struct gconffile **cf, char *block, char **opt, char **val, in
if (**val)
return 1;
debug(DBG_ERR, "configuration error, option %s needs a non-empty value", *opt);
goto errexit;
errmalloc:
errmalloc:
debug(DBG_ERR, "malloc failed");
errexit:
errexit:
free(*opt);
*opt = NULL;
free(*val);
......@@ -411,7 +411,7 @@ int getgenericconfig(struct gconffile **cf, char *block, ...) {
free(val);
continue;
}
va_start(ap, block);
while ((word = va_arg(ap, char *))) {
type = va_arg(ap, int);
......@@ -449,7 +449,7 @@ int getgenericconfig(struct gconffile **cf, char *block, ...) {
break;
}
va_end(ap);
if (!word) {
if (block)
debug(DBG_ERR, "configuration error in block %s, unknown option %s", block, opt);
......@@ -532,15 +532,15 @@ int getgenericconfig(struct gconffile **cf, char *block, ...) {
}
if (block)
debug(DBG_DBG, "getgenericconfig: block %s: %s = %s", block, opt, val);
else
else
debug(DBG_DBG, "getgenericconfig: %s = %s", opt, val);
if (type == CONF_BLN || type == CONF_LINT)
free(val);
}
errparam:
errparam:
debug(DBG_ERR, "getgenericconfig: internal parameter error");
errexit:
errexit:
free(opt);
free(val);
return 0;
......
......@@ -29,7 +29,7 @@ struct hash *hash_create() {
/* frees all memory associated with the hash */
void hash_destroy(struct hash *h) {
struct list_node *ln;
if (!h)
return;
for (ln = list_first(h->hashlist); ln; ln = list_next(ln)) {
......@@ -73,15 +73,15 @@ int hash_insert(struct hash *h, void *key, uint32_t keylen, void *data) {
void *hash_read(struct hash *h, void *key, uint32_t keylen) {
struct list_node *ln;
struct hash_entry *e;
if (!h)
return 0;
pthread_mutex_lock(&h->mutex);
for (ln = list_first(h->hashlist); ln; ln = list_next(ln)) {
e = (struct hash_entry *)ln->data;
if (e->keylen == keylen && !memcmp(e->key, key, keylen)) {
pthread_mutex_unlock(&h->mutex);
return e->data;
pthread_mutex_unlock(&h->mutex);
return e->data;
}
}
pthread_mutex_unlock(&h->mutex);
......@@ -92,7 +92,7 @@ void *hash_read(struct hash *h, void *key, uint32_t keylen) {
void *hash_extract(struct hash *h, void *key, uint32_t keylen) {
struct list_node *ln;
struct hash_entry *e;
if (!h)
return 0;
pthread_mutex_lock(&h->mutex);
......
......@@ -68,24 +68,24 @@ static int parsehostport(struct hostportres *hp, char *hostport, char *default_p
}
}
if (*p == ':') {
/* port number or service name is specified */;
field = ++p;
for (; *p && *p != ' ' && *p != '\t' && *p != '\n'; p++);
if (field == p) {
debug(DBG_ERR, "syntax error, : but no following port");
return 0;
}
hp->port = stringcopy(field, p - field);
/* port number or service name is specified */;
field = ++p;
for (; *p && *p != ' ' && *p != '\t' && *p != '\n'; p++);
if (field == p) {
debug(DBG_ERR, "syntax error, : but no following port");
return 0;
}
hp->port = stringcopy(field, p - field);
} else
hp->port = default_port ? stringcopy(default_port, 0) : NULL;
return 1;
}
struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok) {
struct hostportres *hp;
char *slash, *s;
int plen;
hp = malloc(sizeof(struct hostportres));
if (!hp) {
debug(DBG_ERR, "resolve_newhostport: malloc failed");
......@@ -127,7 +127,7 @@ struct hostportres *newhostport(char *hostport, char *default_port, uint8_t pref
hp->prefixlen = 255;
return hp;
errexit:
errexit:
freehostport(hp);
return NULL;
}
......@@ -140,7 +140,7 @@ int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) {
hints.ai_family = AF_UNSPEC;
if (passive)
hints.ai_flags = AI_PASSIVE;
if (!hp->host && !hp->port) {
/* getaddrinfo() doesn't like host and port to be NULL */
if (getaddrinfo(hp->host, "1812" /* can be anything */, &hints, &hp->addrinfo)) {
......@@ -174,11 +174,11 @@ int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) {
}
return 1;
errexit:
errexit:
if (hp->addrinfo)
freeaddrinfo(hp->addrinfo);
return 0;
}
}
int addhostport(struct list **hostports, char **hostport, char *portdefault, uint8_t prefixok) {
struct hostportres *hp;
......@@ -191,7 +191,7 @@ int addhostport(struct list **hostports, char **hostport, char *portdefault, uin
return 0;
}
}
for (i = 0; hostport[i]; i++) {
hp = newhostport(hostport[i], portdefault, prefixok);
if (!hp)
......@@ -216,7 +216,7 @@ void freehostports(struct list *hostports) {
int resolvehostports(struct list *hostports, int socktype) {
struct list_node *entry;
struct hostportres *hp;
for (entry = list_first(hostports); entry; entry = list_next(entry)) {
hp = (struct hostportres *)entry->data;
if (!hp->addrinfo && !resolvehostport(hp, socktype, 0))
......@@ -254,7 +254,7 @@ int addressmatches(struct list *hostports, struct sockaddr *addr, uint8_t checkp
struct addrinfo *res;
struct list_node *entry;
struct hostportres *hp = NULL;
if (addr->sa_family == AF_INET6) {
sa6 = (struct sockaddr_in6 *)addr;
if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr)) {
......
......@@ -24,7 +24,7 @@ void list_destroy(struct list *list) {
if (!list)
return;
for (node = list->first; node; node = next) {
free(node->data);
next = node->next;
......@@ -40,7 +40,7 @@ int list_push(struct list *list, void *data) {
node = malloc(sizeof(struct list_node));
if (!node)
return 0;
node->next = NULL;
node->data = data;
......@@ -58,10 +58,10 @@ int list_push(struct list *list, void *data) {
void *list_shift(struct list *list) {
struct list_node *node;
void *data;
if (!list || !list->first)
return NULL;
node = list->first;
list->first = node->next;
if (!list->first)
......@@ -75,7 +75,7 @@ void *list_shift(struct list *list) {
/* removes all entries with matching data pointer */
void list_removedata(struct list *list, void *data) {
struct list_node *node, *t;
if (!list || !list->first)
return;
......
......@@ -36,7 +36,7 @@ void *list_shift(struct list *list);
/* removes first entry with matching data pointer */
void list_removedata(struct list *list, void *data);
/* returns first node */
struct list_node *list_first(struct list *list);
......
......@@ -33,7 +33,7 @@ void radmsg_free(struct radmsg *msg) {
struct radmsg *radmsg_init(uint8_t code, uint8_t id, uint8_t *auth) {
struct radmsg *msg;
msg = malloc(sizeof(struct radmsg));
if (!msg)
return NULL;
......@@ -42,7 +42,7 @@ struct radmsg *radmsg_init(uint8_t code, uint8_t id, uint8_t *auth) {
if (!msg->attrs) {
free(msg);
return NULL;
}
}
msg->code = code;
msg->id = id;
if (auth)
......@@ -50,7 +50,7 @@ struct radmsg *radmsg_init(uint8_t code, uint8_t id, uint8_t *auth) {
else if (!RAND_bytes(msg->auth, 16)) {
free(msg);
return NULL;
}
}
return msg;
}
......@@ -83,7 +83,7 @@ int _checkmsgauth(unsigned char *rad, uint8_t *authattr, uint8_t *secret) {
static HMAC_CTX hmacctx;
unsigned int md_len;
uint8_t auth[16], hash[EVP_MAX_MD_SIZE];
pthread_mutex_lock(&lock);
if (first) {
HMAC_CTX_init(&hmacctx);
......@@ -107,8 +107,8 @@ int _checkmsgauth(unsigned char *rad, uint8_t *authattr, uint8_t *secret) {
debug(DBG_WARN, "message authenticator, wrong value");
pthread_mutex_unlock(&lock);
return 0;
}
}
pthread_mutex_unlock(&lock);
return 1;
}
......@@ -120,7 +120,7 @@ int _validauth(unsigned char *rad, unsigned char *reqauth, unsigned char *sec) {
unsigned char hash[EVP_MAX_MD_SIZE];
unsigned int len;
int result;
pthread_mutex_lock(&lock);
if (first) {
EVP_MD_CTX_init(&mdctx);
......@@ -128,7 +128,7 @@ int _validauth(unsigned char *rad, unsigned char *reqauth, unsigned char *sec) {
}
len = RADLEN(rad);
result = (EVP_DigestInit_ex(&mdctx, EVP_md5(), NULL) &&
EVP_DigestUpdate(&mdctx, rad, 4) &&
EVP_DigestUpdate(&mdctx, reqauth, 16) &&
......@@ -149,7 +149,7 @@ int _createmessageauth(unsigned char *rad, unsigned char *authattrval, uint8_t *
if (!authattrval)
return 1;
pthread_mutex_lock(&lock);
if (first) {
HMAC_CTX_init(&hmacctx);
......@@ -208,7 +208,7 @@ uint8_t *radmsg2buf(struct radmsg *msg, uint8_t *secret) {
buf = malloc(size);
if (!buf)
return NULL;
p = buf;
*p++ = msg->code;
*p++ = msg->id;
......@@ -246,7 +246,7 @@ struct radmsg *buf2radmsg(uint8_t *buf, uint8_t *secret, uint8_t *rqauth) {
uint8_t t, l, *v = NULL, *p, auth[16];
uint16_t len;
struct tlv *attr;
len = RADLEN(buf);
if (len < 20)
return NULL;
......@@ -263,7 +263,7 @@ struct radmsg *buf2radmsg(uint8_t *buf, uint8_t *secret, uint8_t *rqauth) {
debug(DBG_WARN, "buf2radmsg: Invalid auth, ignoring reply");
return NULL;
}
msg = radmsg_init(buf[0], buf[1], (uint8_t *)buf + 4);
if (!msg)
return NULL;
......@@ -287,7 +287,7 @@ struct radmsg *buf2radmsg(uint8_t *buf, uint8_t *secret, uint8_t *rqauth) {
v = p;
p += l;
}
if (t == RAD_Attr_Message_Authenticator && secret) {
if (rqauth)
memcpy(buf + 4, rqauth, 16);
......
This diff is collapsed.
......@@ -85,7 +85,7 @@ void tcpsetsrcres() {
int tcpconnect(struct server *server, struct timeval *when, int timeout, char *text) {
struct timeval now;
time_t elapsed;
debug(DBG_DBG, "tcpconnect: called from %s", text);
pthread_mutex_lock(&server->lock);
if (when && memcmp(&server->lastconnecttry, when, sizeof(struct timeval))) {
......@@ -136,7 +136,7 @@ int tcpreadtimeout(int s, unsigned char *buf, int num, int timeout) {
int ndesc, cnt, len;
fd_set readfds, writefds;
struct timeval timer;
if (s < 0)
return -1;
/* make socket non-blocking? */
......@@ -178,21 +178,21 @@ unsigned char *radtcpget(int s, int timeout) {
continue;
}
memcpy(rad, buf, 4);
cnt = tcpreadtimeout(s, rad + 4, len - 4, timeout);
if (cnt < 1) {
debug(DBG_DBG, cnt ? "radtcpget: connection lost" : "radtcpget: timeout");
free(rad);
return NULL;
}
if (len >= 20)
break;
free(rad);
debug(DBG_WARN, "radtcpget: packet smaller than minimum radius size");
}
debug(DBG_DBG, "radtcpget: got %d bytes", len);
return rad;
}
......@@ -217,7 +217,7 @@ void *tcpclientrd(void *arg) {
struct server *server = (struct server *)arg;
unsigned char *buf;
struct timeval lastconnecttry;
for (;;) {
/* yes, lastconnecttry is really necessary */
lastconnecttry = server->lastconnecttry;
......@@ -238,13 +238,13 @@ void *tcpserverwr(void *arg) {
struct client *client = (struct client *)arg;
struct gqueue *replyq;
struct request *reply;
debug(DBG_DBG, "tcpserverwr: starting for %s", addr2string(client->addr));
replyq = client->replyq;
for (;;) {
pthread_mutex_lock(&replyq->mutex);
while (!list_first(replyq->entries)) {
if (client->sock >= 0) {
if (client->sock >= 0) {
debug(DBG_DBG, "tcpserverwr: waiting for signal");
pthread_cond_wait(&replyq->cond, &replyq->mutex);
debug(DBG_DBG, "tcpserverwr: got signal");
......@@ -272,9 +272,9 @@ void tcpserverrd(struct client *client) {
struct request *rq;
uint8_t *buf;
pthread_t tcpserverwrth;
debug(DBG_DBG, "tcpserverrd: starting for %s", addr2string(client->addr));
if (pthread_create(&tcpserverwrth, NULL, tcpserverwr, (void *)client)) {
debug(DBG_ERR, "tcpserverrd: pthread_create failed");
return;
......@@ -336,7 +336,7 @@ void *tcpservernew(void *arg) {
} else
debug(DBG_WARN, "tcpservernew: ignoring request, no matching TCP client");
exit:
exit:
shutdown(s, SHUT_RDWR);
close(s);
pthread_exit(NULL);
......
......@@ -92,7 +92,7 @@ int tlsconnect(struct server *server, struct timeval *when, int timeout, char *t
X509 *cert;
SSL_CTX *ctx = NULL;
unsigned long error;