pgpool2.git / summary / log / commit / refs

commit    41061153c616fc0a8ada8bea8a359d9c3f33f107
Author:   Toshihiro Kitagawa <kitagawa at sraoss.co.jp>
Date:     Tue Oct 12 11:05:00 2010 +0000

    Cancel previous commit.


pg_md5.c | 56 ++++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/pg_md5.c b/pg_md5.c index e6270d77c..32b8e9850 100644 --- a/pg_md5.c +++ b/pg_md5.c @@ -42,12 +42,10 @@ /* Maximum number of characters allowed for input. */ #define MAX_INPUT_SIZE 32 -/* Maximum length of a user name */ -#define MAX_USERNAME_LEN 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 *username, char *password); +static void update_pool_passwd(char *conf_file, char *password); int main(int argc, char *argv[]) @@ -55,7 +53,6 @@ main(int argc, char *argv[]) #define PRINT_USAGE(exit_code) print_usage(argv[0], exit_code) char conf_file[POOLMAXPATHLEN+1]; - char username[MAX_USERNAME_LEN+1] = ""; int opt; int optindex; bool md5auth = false; @@ -65,14 +62,14 @@ main(int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"prompt", no_argument, NULL, 'p'}, {"md5auth", no_argument, NULL, 'm'}, - {"username", required_argument, NULL, 'U'}, + {"md5auth", no_argument, NULL, 'm'}, {"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, "hpmU:f:", long_options, &optindex)) != -1) + while ((opt = getopt_long(argc, argv, "hpmf:", long_options, &optindex)) != -1) { switch (opt) { @@ -84,14 +81,6 @@ main(int argc, char *argv[]) md5auth = true; break; - case 'U': /* specify user name */ - if (!optarg) - { - PRINT_USAGE(EXIT_SUCCESS); - } - strncpy(username, optarg, sizeof(username)); - break; - case 'f': /* specify configuration file */ if (!optarg) { @@ -136,12 +125,12 @@ main(int argc, char *argv[]) if (md5auth) { - update_pool_passwd(conf_file, username, buf); + update_pool_passwd(conf_file, buf); } else { pool_md5_hash(buf, len, md5); - printf("\n%s\n", md5); + printf("%s\n", md5); } } @@ -166,7 +155,7 @@ main(int argc, char *argv[]) if (md5auth) { - update_pool_passwd(conf_file, username, argv[optind]); + update_pool_passwd(conf_file, argv[optind]); } else { @@ -178,7 +167,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -static void update_pool_passwd(char *conf_file, char *username, char *password) +static void update_pool_passwd(char *conf_file, char *password) { struct passwd *pw; char md5[MD5_PASSWD_LEN+1]; @@ -199,19 +188,14 @@ static void update_pool_passwd(char *conf_file, char *username, char *password) dirname(conf_file), pool_config->pool_passwd); pool_init_pool_passwd(pool_passwd); - if (*username == '\0') + pw = getpwuid(getuid()); + if (!pw) { - pw = getpwuid(getuid()); - if (!pw) - { - fprintf(stderr, "getpwuid() failed\n\n"); - exit(EXIT_FAILURE); - } - strncpy(username, pw->pw_name, sizeof(username)); + fprintf(stderr, "getpwuid() failed\n\n"); + exit(EXIT_FAILURE); } - pg_md5_encrypt(password, username, strlen(username), md5); - pool_create_passwdent(username, md5); - + pg_md5_encrypt(password, pw->pw_name, strlen(pw->pw_name), md5); + pool_create_passwdent(pw->pw_name, md5); pool_finish_pool_passwd(); } @@ -220,19 +204,19 @@ print_usage(const char prog[], int exit_code) { fprintf(((exit_code == EXIT_SUCCESS) ? stdout : stderr), "Usage:\n\ - %s [OPTIONS]... [PASSWORD]\n\ \n\ -Options:\n\ - -p, --prompt Prompt password using standard input.\n\ - -m, --md5auth Produce md5 authentication password.\n\ - -U, --username=NAME Database user name for md5 authentication.\n\ - -h, --help This help menu.\n\ + %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\ \n\ Warning: At most %d characters are allowed for input.\n\ Warning: Plain password argument is deprecated for security concerns\n\ and kept for compatibility. Please prefer using password\n\ prompt.\n", - prog, MAX_INPUT_SIZE); + prog, prog, MAX_INPUT_SIZE); exit(exit_code); } [parent: 8e8aea5037c7]