Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e182701

Browse files
committed
Adjust getpwuid() fix commit to display errno string on failure
This adjusts patch 613c6d2.
1 parent a87c729 commit e182701

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/backend/libpq/auth.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,9 +1559,8 @@ auth_peer(hbaPort *port)
15591559
char ident_user[IDENT_USERNAME_MAX + 1];
15601560
uid_t uid;
15611561
gid_t gid;
1562-
struct passwd *pass;
1562+
struct passwd *pw;
15631563

1564-
errno = 0;
15651564
if (getpeereid(port->sock, &uid, &gid) != 0)
15661565
{
15671566
/* Provide special error message if getpeereid is a stub */
@@ -1576,17 +1575,17 @@ auth_peer(hbaPort *port)
15761575
return STATUS_ERROR;
15771576
}
15781577

1579-
pass = getpwuid(uid);
1580-
1581-
if (pass == NULL)
1578+
errno = 0; /* clear errno before call */
1579+
pw = getpwuid(uid);
1580+
if (!pw)
15821581
{
15831582
ereport(LOG,
1584-
(errmsg("local user with ID %d does not exist",
1585-
(int) uid)));
1583+
(errmsg("failed to look up local user id %ld: %s",
1584+
(long) uid, errno ? strerror(errno) : _("user does not exist"))));
15861585
return STATUS_ERROR;
15871586
}
15881587

1589-
strlcpy(ident_user, pass->pw_name, IDENT_USERNAME_MAX + 1);
1588+
strlcpy(ident_user, pw->pw_name, IDENT_USERNAME_MAX + 1);
15901589

15911590
return check_usermap(port->hba->usermap, port->user_name, ident_user, false);
15921591
}

0 commit comments

Comments
 (0)