代码拉取完成,页面将自动刷新
From 03140d5fbab026f122d90c4227730cfe58759f10 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Wed, 15 Jan 2020 20:33:20 +0100
Subject: [PATCH] Refactor: Remove global booth_conf variable in check_config
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Jan Pokorný <jpokorny@redhat.com>
---
src/config.c | 37 +++++++++++++++++++------------------
src/config.h | 16 +++++++++++++++-
src/main.c | 2 +-
3 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/src/config.c b/src/config.c
index 3f40c7a..0dcffdc 100644
--- a/src/config.c
+++ b/src/config.c
@@ -934,56 +934,57 @@ out:
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 0ee0ea5..ad7aed2 100644
--- a/src/config.h
+++ b/src/config.h
@@ -339,7 +339,21 @@ 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
+ *
+ * Checks include:
+ *
+ * - Verifying that the login user and group exist, and converting them to
+ * numeric values
+ *
+ * @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 8a76204..3ad0290 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;
--
2.25.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。