diff options
author | Bruce Momjian <bruce@momjian.us> | 2013-12-18 12:16:16 -0500 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2013-12-18 12:16:21 -0500 |
commit | 613c6d26bd42dd8c2dd0664315be9551475b8864 (patch) | |
tree | e0eb178bf76220fc9b082d9e849bee67c03f9e13 /src/bin/psql/help.c | |
parent | 11ac4c73cb89551d7e0d0180b58d82186f072f8d (diff) | |
download | postgresql-613c6d26bd42dd8c2dd0664315be9551475b8864.tar.gz postgresql-613c6d26bd42dd8c2dd0664315be9551475b8864.zip |
Fix incorrect error message reported for non-existent users
Previously, lookups of non-existent user names could return "Success";
it will now return "User does not exist" by resetting errno. This also
centralizes the user name lookup code in libpgport.
Report and analysis by Nicolas Marchildon; patch by me
Diffstat (limited to 'src/bin/psql/help.c')
-rw-r--r-- | src/bin/psql/help.c | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 30530f2e37c..80b1ec0dfc7 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -8,9 +8,6 @@ #include "postgres_fe.h" #ifndef WIN32 -#ifdef HAVE_PWD_H -#include <pwd.h> /* for getpwuid() */ -#endif #include <sys/types.h> /* (ditto) */ #include <unistd.h> /* for geteuid() */ #else @@ -52,31 +49,18 @@ usage(void) { const char *env; const char *user; - -#ifndef WIN32 - struct passwd *pw = NULL; -#endif + char *errstr; /* Find default user, in case we need it. */ user = getenv("PGUSER"); if (!user) { -#if !defined(WIN32) && !defined(__OS2__) - pw = getpwuid(geteuid()); - if (pw) - user = pw->pw_name; - else + user = get_user_name(&errstr); + if (!user) { - psql_error("could not get current user name: %s\n", strerror(errno)); + psql_error("%s\n", errstr); exit(EXIT_FAILURE); } -#else /* WIN32 */ - char buf[128]; - DWORD bufsize = sizeof(buf) - 1; - - if (GetUserName(buf, &bufsize)) - user = buf; -#endif /* WIN32 */ } printf(_("psql is the PostgreSQL interactive terminal.\n\n")); |