From: Bo Peng Date: Mon, 9 Dec 2024 07:56:13 +0000 (+0900) Subject: Fixed an issue where pg_md5 and pg_enc would not update the password file if a file... X-Git-Tag: V4_2_21~12 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=57ec3fdc7a80912c17e87446030f673ae25a5e50;p=pgpool2.git 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. --- 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))