From 4a0b16fb987548675e9cbc58c281f3bc0192d9c0 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 25 Jun 2014 10:02:05 +0200 Subject: [PATCH] Forward the appropriate DNS and NBNS values when using a per-user/group config. --- src/worker-auth.c | 52 ++++++++++++++++++++++++++++------------------- src/worker.h | 6 +++--- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/worker-auth.c b/src/worker-auth.c index 4d6c7c0f..02666cc4 100644 --- a/src/worker-auth.c +++ b/src/worker-auth.c @@ -584,37 +584,47 @@ static int recv_cookie_auth_reply(worker_st * ws) ws->config->udp_port = 0; /* routes */ - ws->routes_size = msg->n_routes; + ws->routes = talloc_size(ws, msg->n_routes*sizeof(char*)); + if (ws->routes != NULL) { + ws->routes_size = msg->n_routes; + for (i = 0; i < ws->routes_size; i++) { + ws->routes[i] = + talloc_strdup(ws, msg->routes[i]); - for (i = 0; i < ws->routes_size; i++) { - ws->routes[i] = - talloc_strdup(ws, msg->routes[i]); + /* If a default route is detected */ + if (ws->routes[i] != NULL && + (strcmp(ws->routes[i], "default") == 0 || + strcmp(ws->routes[i], "0.0.0.0/0") == 0)) { - /* If a default route is detected */ - if (ws->routes[i] != NULL && - (strcmp(ws->routes[i], "default") == 0 || - strcmp(ws->routes[i], "0.0.0.0/0") == 0)) { - - /* disable all routes */ - ws->routes_size = 0; - ws->default_route = 1; - break; + /* disable all routes */ + ws->routes_size = 0; + ws->default_route = 1; + break; + } } } if (check_if_default_route(ws->routes, ws->routes_size)) ws->default_route = 1; - ws->dns_size = msg->n_dns; - - for (i = 0; i < ws->dns_size; i++) { - ws->dns[i] = talloc_strdup(ws, msg->dns[i]); + ws->dns = talloc_size(ws, msg->n_dns*sizeof(char*)); + if (ws->dns != NULL) { + ws->dns_size = msg->n_dns; + for (i = 0; i < ws->dns_size; i++) { + ws->dns[i] = talloc_strdup(ws, msg->dns[i]); + } + ws->vinfo.dns = ws->dns; + ws->vinfo.dns_size = ws->dns_size; } - ws->nbns_size = msg->n_nbns; - - for (i = 0; i < ws->nbns_size; i++) { - ws->nbns[i] = talloc_strdup(ws, msg->nbns[i]); + ws->nbns = talloc_size(ws, msg->n_nbns*sizeof(char*)); + if (ws->nbns != NULL) { + ws->nbns_size = msg->n_nbns; + for (i = 0; i < ws->nbns_size; i++) { + ws->nbns[i] = talloc_strdup(ws, msg->nbns[i]); + } + ws->vinfo.nbns = ws->nbns; + ws->vinfo.nbns_size = ws->nbns_size; } } else { oclog(ws, LOG_ERR, "error in received message"); diff --git a/src/worker.h b/src/worker.h index 636b6482..2b93ed03 100644 --- a/src/worker.h +++ b/src/worker.h @@ -225,11 +225,11 @@ typedef struct worker_st { /* additional data - received per user or per group */ unsigned routes_size; - char* routes[MAX_ROUTES]; + char** routes; unsigned dns_size; - char* dns[MAX_ROUTES]; + char** dns; unsigned nbns_size; - char* nbns[MAX_ROUTES]; + char** nbns; void *main_pool; /* to be used only on deinitialization */ } worker_st;