mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
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
This commit is contained in:
@ -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"));
|
||||
|
Reference in New Issue
Block a user