pgpool2.git / summary / log / commit / refs
commit e664693a2ee131165b9f73f9225952925b2ff213
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Sat Mar 14 08:50:57 2015 +0000
Allow to open pool_passwd file in read only mode by pgpool-II main process.
Since pgpool-II process does not write to the file, it should be
allowed to open the file in read only mode by the pgpool-II
process. To implement this, now pool_init_pool_passwd has an
additional parameter "mode" which specifies in which mode caller want
to open pool_passwd. Also new static variable "pool_passwd_mode" is
introduced to remember in which mode the current file descriptor has
been created.
src/auth/pool_passwd.c | 24 ++++++++++++++++++------
src/include/auth/pool_passwd.h | 9 +++++++--
src/main/main.c | 2 +-
src/tools/pgmd5/pg_md5.c | 2 +-
4 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/auth/pool_passwd.c b/src/auth/pool_passwd.c
index 971506d53..660a6c5f9 100644
--- a/src/auth/pool_passwd.c
+++ b/src/auth/pool_passwd.c
@@ -6,7 +6,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2013 PgPool Global Development Group
+ * Copyright (c) 2003-2015 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
@@ -34,21 +34,24 @@
#include "utils/fe_ports.h"
#endif
-
-
static FILE *passwd_fd = NULL; /* File descriptor for pool_passwd */
static char saved_passwd_filename[POOLMAXPATHLEN+1];
+static POOL_PASSWD_MODE pool_passwd_mode;
/*
* Initialize this module.
* If pool_passwd does not exist yet, create it.
* Open pool_passwd.
*/
-void pool_init_pool_passwd(char *pool_passwd_filename)
+void pool_init_pool_passwd(char *pool_passwd_filename, POOL_PASSWD_MODE mode)
{
+ char *openmode;
+
if (passwd_fd)
return;
+ pool_passwd_mode = mode;
+
if (saved_passwd_filename[0] == '\0')
{
int len = strlen(pool_passwd_filename);
@@ -56,7 +59,12 @@ void pool_init_pool_passwd(char *pool_passwd_filename)
saved_passwd_filename[len] = '\0';
}
- passwd_fd = fopen(pool_passwd_filename, "r+");
+ if (mode == POOL_PASSWD_R)
+ openmode = "r";
+ else
+ openmode = "r+";
+
+ passwd_fd = fopen(pool_passwd_filename, openmode);
if (!passwd_fd)
{
if (errno == ENOENT)
@@ -88,6 +96,10 @@ int pool_create_passwdent(char *username, char *passwd)
ereport(ERROR,
(errmsg("error updating password, password file descriptor is NULL")));
+ if (pool_passwd_mode != POOL_PASSWD_RW)
+ ereport(ERROR,
+ (errmsg("pool_create_passwdent should be called with pool_passwd opened with read/write mode")));
+
len = strlen(passwd);
if (len != POOL_PASSWD_LEN)
ereport(ERROR,
@@ -244,5 +256,5 @@ void pool_finish_pool_passwd(void)
void pool_reopen_passwd_file(void)
{
pool_finish_pool_passwd();
- pool_init_pool_passwd(saved_passwd_filename);
+ pool_init_pool_passwd(saved_passwd_filename, pool_passwd_mode);
}
diff --git a/src/include/auth/pool_passwd.h b/src/include/auth/pool_passwd.h
index 0a5001537..15b1c27d1 100644
--- a/src/include/auth/pool_passwd.h
+++ b/src/include/auth/pool_passwd.h
@@ -6,7 +6,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2010 PgPool Global Development Group
+ * Copyright (c) 2003-2015 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
@@ -31,7 +31,12 @@
#define POOL_PASSWD_FILENAME "pool_passwd"
#define POOL_PASSWD_LEN 35
-extern void pool_init_pool_passwd(char *pool_passwd_filename);
+typedef enum {
+ POOL_PASSWD_R, /* open pool_passwd in read only mode. used by pgpool-II child main process */
+ POOL_PASSWD_RW, /* open pool_passwd in read/write mode. used by pg_md5 command */
+} POOL_PASSWD_MODE;
+
+extern void pool_init_pool_passwd(char *pool_passwd_filename, POOL_PASSWD_MODE mode);
extern int pool_create_passwdent(char *username, char *passwd);
extern char *pool_get_passwd(char *username);
extern void pool_delete_passwdent(char *username);
diff --git a/src/main/main.c b/src/main/main.c
index d098e62dd..f4ced7512 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -311,7 +311,7 @@ int main(int argc, char **argv)
dirp = dirname(dirnamebuf);
snprintf(pool_passwd, sizeof(pool_passwd), "%s/%s",
dirp, pool_config->pool_passwd);
- pool_init_pool_passwd(pool_passwd);
+ pool_init_pool_passwd(pool_passwd, POOL_PASSWD_R);
}
pool_semaphore_create(MAX_NUM_SEMAPHORES);
diff --git a/src/tools/pgmd5/pg_md5.c b/src/tools/pgmd5/pg_md5.c
index 1af84ddc2..907566443 100644
--- a/src/tools/pgmd5/pg_md5.c
+++ b/src/tools/pgmd5/pg_md5.c
@@ -211,7 +211,7 @@ static void update_pool_passwd(char *conf_file, char *username, char *password)
dirp = dirname(dirnamebuf);
snprintf(pool_passwd, sizeof(pool_passwd), "%s/%s",
dirp, pool_config->pool_passwd);
- pool_init_pool_passwd(pool_passwd);
+ pool_init_pool_passwd(pool_passwd, POOL_PASSWD_RW);
if (strlen(username))
{
[parent: accb2b28ca2f]