From c6710abb4ec756c265225f03caeaea317400b4d1 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Mon, 9 Dec 2024 16:56:13 +0900 Subject: [PATCH] Fixed an issue where pg_md5 and pg_enc would not update the password file if a file other than the default value was specified in the pool_passwd parameter. This issue is reported by Sadhuprasad Patro. --- src/tools/pgenc/pg_enc.c | 17 ++++++++++++----- src/tools/pgmd5/pg_md5.c | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/tools/pgenc/pg_enc.c b/src/tools/pgenc/pg_enc.c index e39ddafc1..d548fd6df 100644 --- a/src/tools/pgenc/pg_enc.c +++ b/src/tools/pgenc/pg_enc.c @@ -412,16 +412,23 @@ update_pool_passwd(char *conf_file, char *username, char *password, char *key) fprintf(stderr, "pool_init_config() failed\n\n"); exit(EXIT_FAILURE); } - if (pool_get_config(conf_file, CFGCXT_RELOAD) == false) + if (pool_get_config(conf_file, CFGCXT_INIT) == false) { fprintf(stderr, "Unable to get configuration. Exiting...\n\n"); exit(EXIT_FAILURE); } - strlcpy(dirnamebuf, conf_file, sizeof(dirnamebuf)); - dirp = dirname(dirnamebuf); - snprintf(pool_passwd, sizeof(pool_passwd), "%s/%s", - dirp, pool_config->pool_passwd); + if (pool_config->pool_passwd[0] != '/') + { + strlcpy(dirnamebuf, conf_file, sizeof(dirnamebuf)); + dirp = dirname(dirnamebuf); + snprintf(pool_passwd, sizeof(pool_passwd), "%s/%s", + dirp, pool_config->pool_passwd); + } + else + strlcpy(pool_passwd, pool_config->pool_passwd, + sizeof(pool_passwd)); + pool_init_pool_passwd(pool_passwd, POOL_PASSWD_RW); if (username == NULL || strlen(username) == 0) diff --git a/src/tools/pgmd5/pg_md5.c b/src/tools/pgmd5/pg_md5.c index 25d36a4d2..e7d002757 100644 --- a/src/tools/pgmd5/pg_md5.c +++ b/src/tools/pgmd5/pg_md5.c @@ -308,16 +308,23 @@ update_pool_passwd(char *conf_file, char *username, char *password) fprintf(stderr, "pool_init_config() failed\n\n"); exit(EXIT_FAILURE); } - if (pool_get_config(conf_file, CFGCXT_RELOAD) == false) + if (pool_get_config(conf_file, CFGCXT_INIT) == false) { fprintf(stderr, "Unable to get configuration. Exiting...\n\n"); exit(EXIT_FAILURE); } - strlcpy(dirnamebuf, conf_file, sizeof(dirnamebuf)); - dirp = dirname(dirnamebuf); - snprintf(pool_passwd, sizeof(pool_passwd), "%s/%s", - dirp, pool_config->pool_passwd); + if (pool_config->pool_passwd[0] != '/') + { + strlcpy(dirnamebuf, conf_file, sizeof(dirnamebuf)); + dirp = dirname(dirnamebuf); + snprintf(pool_passwd, sizeof(pool_passwd), "%s/%s", + dirp, pool_config->pool_passwd); + } + else + strlcpy(pool_passwd, pool_config->pool_passwd, + sizeof(pool_passwd)); + pool_init_pool_passwd(pool_passwd, POOL_PASSWD_RW); if (strlen(username)) -- 2.39.5