diff --git a/src/config.c b/src/config.c index 3f40c7ae..0dcffdcf 100644 --- a/src/config.c +++ b/src/config.c @@ -934,56 +934,57 @@ int read_config(struct booth_config **conf, const char *path, int type) return -1; } - -int check_config(int type) +int check_config(struct booth_config *conf, int type) { struct passwd *pw; struct group *gr; char *cp, *input; - if (!booth_conf) + if (conf == NULL) { return -1; - + } input = (type == ARBITRATOR) - ? booth_conf->arb_user - : booth_conf->site_user; + ? conf->arb_user + : conf->site_user; if (!*input) goto u_inval; if (isdigit(input[0])) { - booth_conf->uid = strtol(input, &cp, 0); + conf->uid = strtol(input, &cp, 0); if (*cp != 0) { u_inval: log_error("User \"%s\" cannot be resolved into a UID.", input); return ENOENT; } - } - else { + } else { pw = getpwnam(input); if (!pw) goto u_inval; - booth_conf->uid = pw->pw_uid; + conf->uid = pw->pw_uid; } input = (type == ARBITRATOR) - ? booth_conf->arb_group - : booth_conf->site_group; - if (!*input) + ? conf->arb_group + : conf->site_group; + + if (!*input) { goto g_inval; + } + if (isdigit(input[0])) { - booth_conf->gid = strtol(input, &cp, 0); + conf->gid = strtol(input, &cp, 0); if (*cp != 0) { g_inval: log_error("Group \"%s\" cannot be resolved into a UID.", input); return ENOENT; } - } - else { + } else { gr = getgrnam(input); - if (!gr) + if (!gr) { goto g_inval; - booth_conf->gid = gr->gr_gid; + } + conf->gid = gr->gr_gid; } return 0; diff --git a/src/config.h b/src/config.h index 0ee0ea5e..220b4f0f 100644 --- a/src/config.h +++ b/src/config.h @@ -339,7 +339,19 @@ extern struct booth_config *booth_conf; */ int read_config(struct booth_config **conf, const char *path, int type); -int check_config(int type); +/** + * @internal + * Check booth configuration + * + * Currently it means checking that login user/group indeed exists, + * while converting it to respective numeric values for further use. + * + * @param[in,out] conf_ptr config object to check + * @param[in] type role currently being acted as + * + * @return 0 or negative value (-1 or -errno) on error + */ +int check_config(struct booth_config *conf, int type); int find_site_by_name(char *site, struct booth_site **node, int any_type); int find_site_by_id(uint32_t site_id, struct booth_site **node); diff --git a/src/main.c b/src/main.c index 8a762049..3ad0290f 100644 --- a/src/main.c +++ b/src/main.c @@ -404,7 +404,7 @@ static int setup_config(struct booth_config **conf, int type) find_myself(NULL, type == CLIENT || type == GEOSTORE); - rv = check_config(type); + rv = check_config(booth_conf, type); if (rv < 0) goto out;