mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +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:
@ -1771,7 +1771,8 @@ auth_peer(hbaPort *port)
|
||||
char ident_user[IDENT_USERNAME_MAX + 1];
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
struct passwd *pass;
|
||||
const char *user_name;
|
||||
char *errstr;
|
||||
|
||||
errno = 0;
|
||||
if (getpeereid(port->sock, &uid, &gid) != 0)
|
||||
@ -1788,17 +1789,15 @@ auth_peer(hbaPort *port)
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
pass = getpwuid(uid);
|
||||
|
||||
if (pass == NULL)
|
||||
user_name = get_user_name(&errstr);
|
||||
if (!user_name)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("local user with ID %d does not exist",
|
||||
(int) uid)));
|
||||
ereport(LOG, (errmsg_internal("%s", errstr)));
|
||||
pfree(errstr);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1);
|
||||
strlcpy(ident_user, user_name, IDENT_USERNAME_MAX + 1);
|
||||
|
||||
return check_usermap(port->hba->usermap, port->user_name, ident_user, false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user