diff --git a/include/error.h b/include/error.h index 7a27aef..5443c4b 100644 --- a/include/error.h +++ b/include/error.h @@ -150,6 +150,8 @@ typedef enum lm_error { LM_ERR_ExtractOldChdirFail = 148, LM_ERR_MPTPAcceptFail = 149, LM_ERR_MPTPListenFail = 150, + LM_ERR_PoolInfoBadName = 151, + LM_ERR_PoolInfoUnknown = 152, } lm_error_t; typedef struct lm_error_desc { diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index d5a3a4b..28b1f50 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-08 15:34+0300\n" +"POT-Creation-Date: 2024-08-08 16:08+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -642,3 +642,13 @@ msgstr "" #, c-format msgid "failed to listen the MPTP socket: %s" msgstr "" + +#: src/error.c:170 +#, c-format +msgid "pool name (%s) doesn't match with: %s" +msgstr "" + +#: src/error.c:171 +#, c-format +msgid "unknown key in the configuration: %s" +msgstr "" diff --git a/src/error.c b/src/error.c index 9cea151..e1cbbf8 100644 --- a/src/error.c +++ b/src/error.c @@ -167,6 +167,8 @@ void lm_error_set(lm_error_t code, ...) { {.code = LM_ERR_ExtractOldChdirFail, .desc = _("failed to change directory back from root during extraction")}, {.code = LM_ERR_MPTPAcceptFail, .desc = _("failed to accept the MPTP connection: %s") }, {.code = LM_ERR_MPTPListenFail, .desc = _("failed to listen the MPTP socket: %s") }, + {.code = LM_ERR_PoolInfoBadName, .desc = _("pool name (%s) doesn't match with: %s") }, + {.code = LM_ERR_PoolInfoUnknown, .desc = _("unknown key in the configuration: %s") }, }; char *fmt = NULL; diff --git a/src/pool/info.c b/src/pool/info.c index 8954a9d..0829403 100644 --- a/src/pool/info.c +++ b/src/pool/info.c @@ -12,17 +12,26 @@ int lm_pool_info_handler(void *data, const char *_section, const char *_key, con char *section = (char *)_section, *value = (char *)_value, *key = (char *)_key; lm_pool_t *pool = data; - if (!eq(pool->name, section)) + if (!eq(pool->name, section)){ + pdebug(__func__, "pool name (%s) doesn't match: %s", pool->name, section); + lm_error_set(LM_ERR_PoolInfoBadName, pool->name, section); return 0; + } if (eq(key, POOL_INFO_SIZE)) pool->info.size = atol(value); + else if (eq(key, POOL_INFO_MAINTAINER)) pool->info.maintainer = strdup(value); + else if (eq(key, POOL_INFO_PUBKEY)) pool->info.pubkey = strdup(value); - else + + else{ + pdebug(__func__, "pool info contains unknown key: %s", key); + lm_error_set(LM_ERR_PoolInfoUnknown, key); return 0; + } return 1; } @@ -45,15 +54,19 @@ bool lm_pool_info_load(lm_pool_t *pool) { return false; } + lm_error_clear(); + if (ini_parse(pool->info_file, lm_pool_info_handler, pool) < 0) { - lm_error_set(LM_ERR_PoolInfoBad); + if(lm_error() == LM_ERR_NoError) + lm_error_set(LM_ERR_PoolInfoBad); return false; } if(pool->info.size <= 0 || pool->info.pubkey == NULL || pool->info.maintainer == NULL){ - lm_error_set(LM_ERR_PoolInfoBad); + if(lm_error() == LM_ERR_NoError) + lm_error_set(LM_ERR_PoolInfoBad); return false; }