|
Packit Service |
82fcde |
/* Prototype for the setgrent functions we use here. */
|
|
Packit Service |
82fcde |
typedef enum nss_status (*set_function) (void);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Prototype for the endgrent functions we use here. */
|
|
Packit Service |
82fcde |
typedef enum nss_status (*end_function) (void);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Prototype for the setgrent functions we use here. */
|
|
Packit Service |
82fcde |
typedef enum nss_status (*get_function) (struct group *, char *,
|
|
Packit Service |
82fcde |
size_t, int *);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static enum nss_status
|
|
Packit Service |
82fcde |
compat_call (service_user *nip, const char *user, gid_t group, long int *start,
|
|
Packit Service |
82fcde |
long int *size, gid_t **groupsp, long int limit, int *errnop)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
struct group grpbuf;
|
|
Packit Service |
82fcde |
enum nss_status status;
|
|
Packit Service |
82fcde |
set_function setgrent_fct;
|
|
Packit Service |
82fcde |
get_function getgrent_fct;
|
|
Packit Service |
82fcde |
end_function endgrent_fct;
|
|
Packit Service |
82fcde |
gid_t *groups = *groupsp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
getgrent_fct = __nss_lookup_function (nip, "getgrent_r");
|
|
Packit Service |
82fcde |
if (getgrent_fct == NULL)
|
|
Packit Service |
82fcde |
return NSS_STATUS_UNAVAIL;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
setgrent_fct = __nss_lookup_function (nip, "setgrent");
|
|
Packit Service |
82fcde |
if (setgrent_fct)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
status = DL_CALL_FCT (setgrent_fct, ());
|
|
Packit Service |
82fcde |
if (status != NSS_STATUS_SUCCESS)
|
|
Packit Service |
82fcde |
return status;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
endgrent_fct = __nss_lookup_function (nip, "endgrent");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
struct scratch_buffer tmpbuf;
|
|
Packit Service |
82fcde |
scratch_buffer_init (&tmpbuf);
|
|
Packit Service |
82fcde |
enum nss_status result = NSS_STATUS_SUCCESS;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
do
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
while ((status = DL_CALL_FCT (getgrent_fct,
|
|
Packit Service |
82fcde |
(&grpbuf, tmpbuf.data, tmpbuf.length,
|
|
Packit Service |
82fcde |
errnop)),
|
|
Packit Service |
82fcde |
status == NSS_STATUS_TRYAGAIN)
|
|
Packit Service |
82fcde |
&& *errnop == ERANGE)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (!scratch_buffer_grow (&tmpbuf))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
result = NSS_STATUS_TRYAGAIN;
|
|
Packit Service |
82fcde |
goto done;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (status != NSS_STATUS_SUCCESS)
|
|
Packit Service |
82fcde |
goto done;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (grpbuf.gr_gid != group)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
char **m;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
for (m = grpbuf.gr_mem; *m != NULL; ++m)
|
|
Packit Service |
82fcde |
if (strcmp (*m, user) == 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Check whether the group is already on the list. */
|
|
Packit Service |
82fcde |
long int cnt;
|
|
Packit Service |
82fcde |
for (cnt = 0; cnt < *start; ++cnt)
|
|
Packit Service |
82fcde |
if (groups[cnt] == grpbuf.gr_gid)
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (cnt == *start)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Matches user and not yet on the list. Insert
|
|
Packit Service |
82fcde |
this group. */
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (*start == *size))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Need a bigger buffer. */
|
|
Packit Service |
82fcde |
gid_t *newgroups;
|
|
Packit Service |
82fcde |
long int newsize;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (limit > 0 && *size == limit)
|
|
Packit Service |
82fcde |
/* We reached the maximum. */
|
|
Packit Service |
82fcde |
goto done;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (limit <= 0)
|
|
Packit Service |
82fcde |
newsize = 2 * *size;
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
newsize = MIN (limit, 2 * *size);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
newgroups = realloc (groups,
|
|
Packit Service |
82fcde |
newsize * sizeof (*groups));
|
|
Packit Service |
82fcde |
if (newgroups == NULL)
|
|
Packit Service |
82fcde |
goto done;
|
|
Packit Service |
82fcde |
*groupsp = groups = newgroups;
|
|
Packit Service |
82fcde |
*size = newsize;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
groups[*start] = grpbuf.gr_gid;
|
|
Packit Service |
82fcde |
*start += 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
while (status == NSS_STATUS_SUCCESS);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
done:
|
|
Packit Service |
82fcde |
scratch_buffer_free (&tmpbuf);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (endgrent_fct)
|
|
Packit Service |
82fcde |
DL_CALL_FCT (endgrent_fct, ());
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return result;
|
|
Packit Service |
82fcde |
}
|