summaryrefslogtreecommitdiff
path: root/src/backend/libpq/auth.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2013-12-18 12:16:16 -0500
committerBruce Momjian <bruce@momjian.us>2013-12-18 12:16:21 -0500
commit613c6d26bd42dd8c2dd0664315be9551475b8864 (patch)
treee0eb178bf76220fc9b082d9e849bee67c03f9e13 /src/backend/libpq/auth.c
parent11ac4c73cb89551d7e0d0180b58d82186f072f8d (diff)
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/backend/libpq/auth.c')
-rw-r--r--src/backend/libpq/auth.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 2dbf7e53a12..6d11e576a4b 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -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);
}