diff options
Diffstat (limited to 'src/cfg.c')
-rw-r--r-- | src/cfg.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -70,6 +70,27 @@ static int parse_json_db(struct og_server_cfg *cfg, json_t *element) return 0; } +static int parse_json_samba(struct og_server_cfg *cfg, json_t *element) +{ + const char *key; + json_t *value; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "user")) { + if (og_json_parse_string(value, &cfg->smb.user) < 0) + return -1; + } else if (!strcmp(key, "pass")) { + if (og_json_parse_string(value, &cfg->smb.pass) < 0) + return -1; + } else { + syslog(LOG_ERR, "unknown key `%s' in samba\n", key); + return -1; + } + } + + return 0; +} + static int parse_json_wol(struct og_server_cfg *cfg, json_t *element) { const char *key; @@ -110,6 +131,7 @@ static int parse_json_repo(struct og_server_cfg *cfg, json_t *element) #define OG_SERVER_CFG_DB (1 << 1) #define OG_SERVER_CFG_WOL (1 << 2) #define OG_SERVER_CFG_REPO (1 << 3) +#define OG_SERVER_CFG_SAMBA (1 << 4) int parse_json_config(const char *filename, struct og_server_cfg *cfg) { @@ -157,6 +179,12 @@ int parse_json_config(const char *filename, struct og_server_cfg *cfg) break; } flags |= OG_SERVER_CFG_DB; + } else if (!strcmp(key, "samba")) { + if (parse_json_samba(cfg, value) < 0) { + ret = -1; + break; + } + flags |= OG_SERVER_CFG_SAMBA; } else if (!strcmp(key, "repository")) { if (parse_json_repo(cfg, value) < 0) return -1; @@ -181,6 +209,9 @@ int parse_json_config(const char *filename, struct og_server_cfg *cfg) ret = -1; } + if (!(flags & OG_SERVER_CFG_SAMBA)) + syslog(LOG_WARNING, "Missing samba configuration in ogserver.json file"); + if (ret < 0) json_decref(root); else |