From a0d0d2fb1b321d65425951fc70f5c42c2dcfda41 Mon Sep 17 00:00:00 2001 From: Dave Olson Date: Fri, 6 Apr 2018 15:47:42 -0700 Subject: Fixed problem with 2nd config init, when no servers in config file Ticket: CM-20454 Reviewed By: nobody My code to avoid redoing all the config didn't work right when re-entered with no server listed in the config file. The result was I'd return an error the first time, and success the 2nd-Nth times, and then later code would try to dereference the NULL pointer server list, and segv in login or sshd, etc. Redid the logic in initialize() to fix that. --- src/pam_radius_auth.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/pam_radius_auth.c b/src/pam_radius_auth.c index 5bf93ea..c4274fa 100644 --- a/src/pam_radius_auth.c +++ b/src/pam_radius_auth.c @@ -903,14 +903,13 @@ static int setup_sock(pam_handle_t * pamh, radius_server_t * server, */ static int initialize(pam_handle_t * pamh, radius_conf_t * conf) { - int ret = PAM_SUCCESS, retsetup, nservers = 0; + int parse, retsetup, nservers = 0; + const int rfail = PAM_AUTHINFO_UNAVAIL; radius_server_t *server = NULL; - ret = parse_conffile(pamh, conf); - if (ret == -1) - return ret; - else if (ret == 1) - return PAM_SUCCESS; /* no changes to previous parse */ + parse = parse_conffile(pamh, conf); + if (parse == -1) + return rfail; /* setup the sockets, bind to them, etc. */ for (server = conf->server; server; server = server->next) { @@ -919,19 +918,20 @@ static int initialize(pam_handle_t * pamh, radius_conf_t * conf) nservers++; } - if (!nservers) { - _pam_log(pamh, LOG_ERR, "No valid server found in configuration" - " file %s", conf->conf_file); - ret = PAM_AUTHINFO_UNAVAIL; - } + retsetup = nservers ? PAM_SUCCESS : rfail; - if (conf->server) { - cleaned_up = 0; - pam_set_data(pamh, "rad_conf_cleanup", (void *)conf->server, - cleanup_conf); + if (parse != 1) { /* only on first call */ + if (!nservers) + _pam_log(pamh, LOG_ERR, "No valid server found in" + " configuration file %s", conf->conf_file); + else { + cleaned_up = 0; + pam_set_data(pamh, "rad_conf_cleanup", + (void *)conf->server, cleanup_conf); + } } - return ret; + return retsetup; } /* -- cgit v1.2.3