Skip to content

Commit 708cdcb

Browse files
jnpkrnclumens
authored andcommitted
Refactor: check_config to no longer rely on global booth_conf variable
Signed-off-by: Jan Pokorný <[email protected]>
1 parent 333c237 commit 708cdcb

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/config.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -934,56 +934,57 @@ int read_config(struct booth_config **conf, const char *path, int type)
934934
return -1;
935935
}
936936

937-
938-
int check_config(int type)
937+
int check_config(struct booth_config *conf, int type)
939938
{
940939
struct passwd *pw;
941940
struct group *gr;
942941
char *cp, *input;
943942

944-
if (!booth_conf)
943+
if (conf == NULL) {
945944
return -1;
946-
945+
}
947946

948947
input = (type == ARBITRATOR)
949-
? booth_conf->arb_user
950-
: booth_conf->site_user;
948+
? conf->arb_user
949+
: conf->site_user;
951950
if (!*input)
952951
goto u_inval;
953952
if (isdigit(input[0])) {
954-
booth_conf->uid = strtol(input, &cp, 0);
953+
conf->uid = strtol(input, &cp, 0);
955954
if (*cp != 0) {
956955
u_inval:
957956
log_error("User \"%s\" cannot be resolved into a UID.", input);
958957
return ENOENT;
959958
}
960-
}
961-
else {
959+
} else {
962960
pw = getpwnam(input);
963961
if (!pw)
964962
goto u_inval;
965-
booth_conf->uid = pw->pw_uid;
963+
conf->uid = pw->pw_uid;
966964
}
967965

968966

969967
input = (type == ARBITRATOR)
970-
? booth_conf->arb_group
971-
: booth_conf->site_group;
972-
if (!*input)
968+
? conf->arb_group
969+
: conf->site_group;
970+
971+
if (!*input) {
973972
goto g_inval;
973+
}
974+
974975
if (isdigit(input[0])) {
975-
booth_conf->gid = strtol(input, &cp, 0);
976+
conf->gid = strtol(input, &cp, 0);
976977
if (*cp != 0) {
977978
g_inval:
978979
log_error("Group \"%s\" cannot be resolved into a UID.", input);
979980
return ENOENT;
980981
}
981-
}
982-
else {
982+
} else {
983983
gr = getgrnam(input);
984-
if (!gr)
984+
if (!gr) {
985985
goto g_inval;
986-
booth_conf->gid = gr->gr_gid;
986+
}
987+
conf->gid = gr->gr_gid;
987988
}
988989

989990
return 0;

src/config.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,19 @@ extern struct booth_config *booth_conf;
339339
*/
340340
int read_config(struct booth_config **conf, const char *path, int type);
341341

342-
int check_config(int type);
342+
/**
343+
* @internal
344+
* Check booth configuration
345+
*
346+
* Currently it means checking that login user/group indeed exists,
347+
* while converting it to respective numeric values for further use.
348+
*
349+
* @param[in,out] conf_ptr config object to check
350+
* @param[in] type role currently being acted as
351+
*
352+
* @return 0 or negative value (-1 or -errno) on error
353+
*/
354+
int check_config(struct booth_config *conf, int type);
343355

344356
int find_site_by_name(char *site, struct booth_site **node, int any_type);
345357
int find_site_by_id(uint32_t site_id, struct booth_site **node);

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int setup_config(struct booth_config **conf, int type)
404404
find_myself(NULL, type == CLIENT || type == GEOSTORE);
405405

406406

407-
rv = check_config(type);
407+
rv = check_config(booth_conf, type);
408408
if (rv < 0)
409409
goto out;
410410

0 commit comments

Comments
 (0)