pgpool2.git / summary / log / commit / refs
commit abc6253d4bbeb1b2c7199a36dc5f2d434c4511f2
Author: Tatsuo Ishii <ishii at sraoss.co.jp>
Date: Sun Jun 12 09:20:33 2011 +0000
Add --username(or -u) option to pg_md5. This allows to manage users
which do not have UNIX accounts. Patch contributed by Nicolas Thauvin.
Japanese doc change by Tatsuo Ishii.
doc/pgpool-en.html | 2 +-
doc/pgpool-ja.html | 7 +++---
pg_md5.c | 64 ++++++++++++++++++++++++++++++++++++++++--------------
3 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html
index 05a13c1dd..f2a9c264f 100644
--- a/doc/pgpool-en.html
+++ b/doc/pgpool-en.html
@@ -2741,7 +2741,7 @@ recovery.
md5 authentication:
<ol>
<li>Login as the database's operating system user and type
- "pg_md5 --md5auth <your_passwd>"
+ "pg_md5 --md5auth --username=<your_username> <your_passwd>"
user name and md5 encrypted password are registered into
pool_passwd.
If pool_passwd does not exist yet, pg_md5 command will
diff --git a/doc/pgpool-ja.html b/doc/pgpool-ja.html
index 72c63095a..666a9e5d5 100644
--- a/doc/pgpool-ja.html
+++ b/doc/pgpool-ja.html
@@ -8,7 +8,7 @@
<body>
<!-- hhmts start -->
-Last modified: Sun May 1 18:23:46 JST 2011
+Last modified: Sun Jun 12 18:17:02 JST 2011
<!-- hhmts end -->
<body bgcolor="#ffffff">
@@ -2827,8 +2827,9 @@ Possible last query was:$B$N$"$H$K!"$3$N%(%i!<$rJV$9860x$H$J$C$?Ld$$9g$o$;$N(B
crypt$BG'>Z$OMxMQ$G$-$^$;$s!#(B
md5$BG'>Z$K4X$7$F$O!"(BPostgreSQL$B$K3:Ev%f!<%6$r(Bmd5$BG'>ZIU$G(BPostgreSQL$B$KEPO?$7!"<!$K(Bpgpool$B$KIUB0$9$k(Bpg_md5$B%3%^%s%I$r;H$C$F!"(Bpool_passwd$B$H$$$&G'>Z%U%!%$%k$r:n@.$9$k$3$H$K$h$jMxMQ$G$-$k$h$&$K$J$j$^$9!#(B
<ol>
-<li>DB$B%f!<%6$N%"%+%&%s%H$G%m%0%$%s$7!"(B"pg_md5 --md5auth $B%Q%9%o!<%I(B" $B$r<B9T$7$^$9!#(B
-<li>md5$B$K$h$j0E9f2=$5$l$?%Q%9%o!<%I$,(Bpool_passwd$B$KEPO?$5$l$^$9!#(B
+<li>DB$B%f!<%6$N%"%+%&%s%H$G%m%0%$%s$7!"(B"pg_md5 --md5auth $B%Q%9%o!<%I(B"
+$B$^$?$O(B "pg_md5 --md5auth --username=$B%f!<%6L>(B $B%Q%9%o!<%I(B" $B$r<B9T$7$^$9!#(B
+<li>md5$B$K$h$j0E9f2=$5$l$?%f!<%6L>$H%Q%9%o!<%I$,(Bpool_passwd$B$KEPO?$5$l$^$9!#(B
pool_passwd$B$,$^$@B8:_$7$J$1$l$P!"(Bpgpool.conf$B$HF1$8%G%#%l%/%H%jFb$K:n@.$5$l$^$9!#(B
<li>pool_passwd$B$N%U%)!<%^%C%H$O!"(B"$B%f!<%6L>(B:$B%Q%9%o!<%I(B"$B$H$J$C$F$$$^$9!#(B
<li>pool_hba.conf$B$K(Bmd5$BG'>Z$N%(%s%H%j$r:n@.$7$^$9!#(B
diff --git a/pg_md5.c b/pg_md5.c
index b2b90778e..e87f57b56 100644
--- a/pg_md5.c
+++ b/pg_md5.c
@@ -41,11 +41,11 @@
#include <libgen.h>
/* Maximum number of characters allowed for input. */
-#define MAX_INPUT_SIZE 32
+#define MAX_INPUT_SIZE 128
static void print_usage(const char prog[], int exit_code);
static void set_tio_attr(int enable);
-static void update_pool_passwd(char *conf_file, char *password);
+static void update_pool_passwd(char *conf_file, char *username, char *password);
int
main(int argc, char *argv[])
@@ -53,6 +53,7 @@ main(int argc, char *argv[])
#define PRINT_USAGE(exit_code) print_usage(argv[0], exit_code)
char conf_file[POOLMAXPATHLEN+1];
+ char username[MAX_INPUT_SIZE+1];
int opt;
int optindex;
bool md5auth = false;
@@ -62,14 +63,19 @@ main(int argc, char *argv[])
{"help", no_argument, NULL, 'h'},
{"prompt", no_argument, NULL, 'p'},
{"md5auth", no_argument, NULL, 'm'},
- {"md5auth", no_argument, NULL, 'm'},
+ {"username", required_argument, NULL, 'u'},
{"config-file", required_argument, NULL, 'f'},
{NULL, 0, NULL, 0}
};
snprintf(conf_file, sizeof(conf_file), "%s/%s", DEFAULT_CONFIGDIR, POOL_CONF_FILE_NAME);
- while ((opt = getopt_long(argc, argv, "hpmf:", long_options, &optindex)) != -1)
+ /* initialize username buffer with zeros so that we can use strlen on it later
+ to check if a username was given on the command line
+ */
+ memset(username, 0, MAX_INPUT_SIZE+1);
+
+ while ((opt = getopt_long(argc, argv, "hpmf:u:", long_options, &optindex)) != -1)
{
switch (opt)
{
@@ -89,6 +95,20 @@ main(int argc, char *argv[])
strncpy(conf_file, optarg, sizeof(conf_file));
break;
+ case 'u':
+ if (!optarg)
+ {
+ PRINT_USAGE(EXIT_SUCCESS);
+ }
+ /* check the input limit early */
+ if (strlen(optarg) > MAX_INPUT_SIZE)
+ {
+ fprintf(stderr, "Error: input exceeds maximum username length!\n\n");
+ exit(EXIT_FAILURE);
+ }
+ strncpy(username, optarg, sizeof(username));
+ break;
+
default:
PRINT_USAGE(EXIT_SUCCESS);
break;
@@ -125,7 +145,7 @@ main(int argc, char *argv[])
if (md5auth)
{
- update_pool_passwd(conf_file, buf);
+ update_pool_passwd(conf_file, username, buf);
}
else
{
@@ -155,7 +175,7 @@ main(int argc, char *argv[])
if (md5auth)
{
- update_pool_passwd(conf_file, argv[optind]);
+ update_pool_passwd(conf_file, username, argv[optind]);
}
else
{
@@ -167,7 +187,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
}
-static void update_pool_passwd(char *conf_file, char *password)
+static void update_pool_passwd(char *conf_file, char *username, char *password)
{
struct passwd *pw;
char md5[MD5_PASSWD_LEN+1];
@@ -192,14 +212,24 @@ static void update_pool_passwd(char *conf_file, char *password)
dirp, pool_config->pool_passwd);
pool_init_pool_passwd(pool_passwd);
- pw = getpwuid(getuid());
- if (!pw)
+ if (strlen(username))
{
- fprintf(stderr, "getpwuid() failed\n\n");
- exit(EXIT_FAILURE);
+ /* generate the hash for the given username */
+ pg_md5_encrypt(password, username, strlen(username), md5);
+ pool_create_passwdent(username, md5);
+ }
+ else
+ {
+ /* get the user information from the current uid */
+ pw = getpwuid(getuid());
+ if (!pw)
+ {
+ fprintf(stderr, "getpwuid() failed\n\n");
+ exit(EXIT_FAILURE);
+ }
+ pg_md5_encrypt(password, pw->pw_name, strlen(pw->pw_name), md5);
+ pool_create_passwdent(pw->pw_name, md5);
}
- pg_md5_encrypt(password, pw->pw_name, strlen(pw->pw_name), md5);
- pool_create_passwdent(pw->pw_name, md5);
pool_finish_pool_passwd();
}
@@ -212,9 +242,11 @@ print_usage(const char prog[], int exit_code)
%s [OPTIONS]\n\
%s <PASSWORD>\n\
\n\
- --prompt, -p Prompt password using standard input.\n\
- --md5auth, -m Produce md5 authentication password.\n\
- --help, -h This help menu.\n\
+ --prompt, -p Prompt password using standard input.\n\
+ --md5auth, -m Produce md5 authentication password.\n\
+ --username, -u USER When producing a md5 authentication password,\n\
+ create the pool_passwd entry for USER.\n\
+ --help, -h This help menu.\n\
\n\
Warning: At most %d characters are allowed for input.\n\
Warning: Plain password argument is deprecated for security concerns\n\
[parent: bb3b66ceaf26]