diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2005-12-18 02:17:16 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2005-12-18 02:17:16 +0000 |
commit | b16566d77168540730d7ca26f8fe1832f15d450e (patch) | |
tree | a65b992c8e31be33e37fa9e1fde6d99601cdb626 /src/bin/scripts/createuser.c | |
parent | ea771743c80ca9c84ee4428e66f861ae8344061b (diff) | |
download | postgresql-b16566d77168540730d7ca26f8fe1832f15d450e.tar.gz postgresql-b16566d77168540730d7ca26f8fe1832f15d450e.zip |
Add new psql command \password for changing role password with client-side
password encryption. Also alter createuser command to the same effect.
Diffstat (limited to 'src/bin/scripts/createuser.c')
-rw-r--r-- | src/bin/scripts/createuser.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index bb68775fe99..adf9c41b3a2 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.23 2005/12/12 15:48:04 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.24 2005/12/18 02:17:16 petere Exp $ * *------------------------------------------------------------------------- */ @@ -13,6 +13,7 @@ #include "postgres_fe.h" #include "common.h" #include "dumputils.h" +#include "libpq/crypt.h" static void help(const char *progname); @@ -246,7 +247,20 @@ main(int argc, char *argv[]) if (encrypted == TRI_NO) appendPQExpBuffer(&sql, " UNENCRYPTED"); appendPQExpBuffer(&sql, " PASSWORD "); - appendStringLiteral(&sql, newpassword, false); + + if (encrypted != TRI_NO) + { + char encrypted_password[MD5_PASSWD_LEN + 1]; + + if (!pg_md5_encrypt(newpassword, newuser, strlen(newuser), encrypted_password)) + { + fprintf(stderr, _("Password encryption failed.\n")); + exit(1); + } + appendStringLiteral(&sql, encrypted_password, false); + } + else + appendStringLiteral(&sql, newpassword, false); } if (superuser == TRI_YES) appendPQExpBuffer(&sql, " SUPERUSER"); |