diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-23 01:16:38 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-23 01:16:38 +0000 |
commit | ea9b028dc77e961b290087972b9bfbe8e91ce82f (patch) | |
tree | b71ed0d93dfd0f180020275ca3906c2f50aa94d8 /src/bin/psql/command.c | |
parent | e80f9dfa8095656c0d671d89663439c66b806288 (diff) | |
download | postgresql-ea9b028dc77e961b290087972b9bfbe8e91ce82f.tar.gz postgresql-ea9b028dc77e961b290087972b9bfbe8e91ce82f.zip |
Add an officially exported libpq function to encrypt passwords, and
modify the previous \password patch to use it instead of depending
on a not-officially-exported function. Per discussion.
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 35da9cdf829..6e5ddf53696 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.156 2005/12/18 02:17:16 petere Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.157 2005/12/23 01:16:38 tgl Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -12,7 +12,6 @@ #undef mkdir #endif -#include <errno.h> #include <ctype.h> #ifdef HAVE_PWD_H #include <pwd.h> @@ -35,7 +34,6 @@ #include "libpq-fe.h" #include "pqexpbuffer.h" -#include "libpq/crypt.h" #include "dumputils.h" #include "common.h" @@ -638,14 +636,16 @@ exec_command(const char *cmd, { char *opt0 = psql_scan_slash_option(scan_state, OT_SQLID, NULL, true); char *user; - char encrypted_password[MD5_PASSWD_LEN + 1]; + char *encrypted_password; if (opt0) user = opt0; else user = PQuser(pset.db); - if (!pg_md5_encrypt(pw1, user, strlen(user), encrypted_password)) + encrypted_password = pg_make_encrypted_password(pw1, user); + + if (!encrypted_password) { fprintf(stderr, _("Password encryption failed.\n")); success = false; @@ -656,7 +656,7 @@ exec_command(const char *cmd, PGresult *res; initPQExpBuffer(&buf); - printfPQExpBuffer(&buf, "ALTER ROLE %s PASSWORD '%s';", + printfPQExpBuffer(&buf, "ALTER USER %s PASSWORD '%s';", fmtId(user), encrypted_password); res = PSQLexec(buf.data, false); termPQExpBuffer(&buf); @@ -664,6 +664,7 @@ exec_command(const char *cmd, success = false; else PQclear(res); + PQfreemem(encrypted_password); } } |