mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-04 12:52:15 +00:00
Use thread-safe getgrnam_r() and getpwnam_r(); dynamically size
the buffer used by this.
This commit is contained in:
parent
946733c26e
commit
5f8af33b11
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=191168
@ -118,12 +118,34 @@ lookup_gid(void *private_data, const char *gname, gid_t gid)
|
|||||||
b->hash = h;
|
b->hash = h;
|
||||||
#if HAVE_GRP_H
|
#if HAVE_GRP_H
|
||||||
{
|
{
|
||||||
struct group *grent = getgrnam(gname);
|
char _buffer[128];
|
||||||
if (grent != NULL)
|
size_t bufsize = 128;
|
||||||
gid = grent->gr_gid;
|
char *buffer = _buffer;
|
||||||
|
struct group grent, *result;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
r = getgrnam_r(gname, &grent, buffer, bufsize, &result);
|
||||||
|
if (r == 0)
|
||||||
|
break;
|
||||||
|
if (r != ERANGE)
|
||||||
|
break;
|
||||||
|
bufsize *= 2;
|
||||||
|
if (buffer != _buffer)
|
||||||
|
free(buffer);
|
||||||
|
buffer = malloc(bufsize);
|
||||||
|
if (buffer == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result != NULL)
|
||||||
|
gid = result->gr_gid;
|
||||||
|
if (buffer != _buffer)
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32) && !defined(__CYGWIN__)
|
#elif defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
/* TODO: do a gname->gid lookup for Windows. */
|
/* TODO: do a gname->gid lookup for Windows. */
|
||||||
|
#else
|
||||||
|
#error No way to perform gid lookups on this platform
|
||||||
#endif
|
#endif
|
||||||
b->id = gid;
|
b->id = gid;
|
||||||
|
|
||||||
@ -155,12 +177,34 @@ lookup_uid(void *private_data, const char *uname, uid_t uid)
|
|||||||
b->hash = h;
|
b->hash = h;
|
||||||
#if HAVE_PWD_H
|
#if HAVE_PWD_H
|
||||||
{
|
{
|
||||||
struct passwd *pwent = getpwnam(uname);
|
char _buffer[128];
|
||||||
if (pwent != NULL)
|
size_t bufsize = 128;
|
||||||
uid = pwent->pw_uid;
|
char *buffer = _buffer;
|
||||||
|
struct passwd pwent, *result;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
r = getpwnam_r(uname, &pwent, buffer, bufsize, &result);
|
||||||
|
if (r == 0)
|
||||||
|
break;
|
||||||
|
if (r != ERANGE)
|
||||||
|
break;
|
||||||
|
bufsize *= 2;
|
||||||
|
if (buffer != _buffer)
|
||||||
|
free(buffer);
|
||||||
|
buffer = malloc(bufsize);
|
||||||
|
if (buffer == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result != NULL)
|
||||||
|
uid = result->pw_uid;
|
||||||
|
if (buffer != _buffer)
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32) && !defined(__CYGWIN__)
|
#elif defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
/* TODO: do a uname->uid lookup for Windows. */
|
/* TODO: do a uname->uid lookup for Windows. */
|
||||||
|
#else
|
||||||
|
#error No way to look up uids on this platform
|
||||||
#endif
|
#endif
|
||||||
b->id = uid;
|
b->id = uid;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user