2019-01-01 00:11:28 +00:00
|
|
|
/* Copyright (C) 1997-2019 Free Software Foundation, Inc.
|
2006-10-06 17:49:27 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2006-10-06 17:49:27 +00:00
|
|
|
|
|
|
|
#include <atomic.h>
|
|
|
|
#include <nss.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2015-09-08 21:11:03 +00:00
|
|
|
#include <libc-lock.h>
|
2006-10-06 17:49:27 +00:00
|
|
|
#include <rpcsvc/nis.h>
|
|
|
|
|
|
|
|
#include "nss-nisplus.h"
|
|
|
|
#include "nisplus-parser.h"
|
|
|
|
#include <libnsl.h>
|
|
|
|
#include <nis_intern.h>
|
|
|
|
#include <nis_xdr.h>
|
|
|
|
|
|
|
|
#define NISOBJVAL(col, obj) \
|
|
|
|
((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
|
|
|
|
|
|
|
|
#define NISOBJLEN(col, obj) \
|
|
|
|
((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
|
|
|
|
|
|
|
|
extern nis_name grp_tablename_val attribute_hidden;
|
|
|
|
extern size_t grp_tablename_len attribute_hidden;
|
|
|
|
extern enum nss_status _nss_grp_create_tablename (int *errnop);
|
|
|
|
|
|
|
|
|
|
|
|
enum nss_status
|
|
|
|
_nss_nisplus_initgroups_dyn (const char *user, gid_t group, long int *start,
|
|
|
|
long int *size, gid_t **groupsp, long int limit,
|
|
|
|
int *errnop)
|
|
|
|
{
|
|
|
|
if (grp_tablename_val == NULL)
|
|
|
|
{
|
|
|
|
enum nss_status status = _nss_grp_create_tablename (errnop);
|
|
|
|
|
|
|
|
if (status != NSS_STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
nis_result *result;
|
|
|
|
char buf[strlen (user) + 12 + grp_tablename_len];
|
|
|
|
|
|
|
|
snprintf (buf, sizeof (buf), "[members=%s],%s", user, grp_tablename_val);
|
|
|
|
|
|
|
|
result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | ALL_RESULTS, NULL, NULL);
|
|
|
|
|
|
|
|
if (result == NULL)
|
|
|
|
{
|
|
|
|
*errnop = ENOMEM;
|
|
|
|
return NSS_STATUS_TRYAGAIN;
|
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
|
2006-10-06 17:49:27 +00:00
|
|
|
{
|
|
|
|
enum nss_status status = niserr2nss (result->status);
|
|
|
|
|
|
|
|
nis_freeresult (result);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NIS_RES_NUMOBJ (result) == 0)
|
|
|
|
{
|
|
|
|
errout:
|
|
|
|
nis_freeresult (result);
|
|
|
|
return NSS_STATUS_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
gid_t *groups = *groupsp;
|
|
|
|
nis_object *obj = NIS_RES_OBJECT (result);
|
|
|
|
for (unsigned int cnt = 0; cnt < NIS_RES_NUMOBJ (result); ++cnt, ++obj)
|
|
|
|
{
|
|
|
|
if (__type_of (obj) != NIS_ENTRY_OBJ
|
|
|
|
|| strcmp (obj->EN_data.en_type, "group_tbl") != 0
|
|
|
|
|| obj->EN_data.en_cols.en_cols_len < 4)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char *numstr = NISOBJVAL (2, obj);
|
|
|
|
size_t len = NISOBJLEN (2, obj);
|
|
|
|
if (len == 0 || numstr[0] == '\0')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gid_t gid;
|
|
|
|
char *endp;
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (numstr[len - 1] != '\0'))
|
2006-10-06 17:49:27 +00:00
|
|
|
{
|
|
|
|
char numstrbuf[len + 1];
|
|
|
|
memcpy (numstrbuf, numstr, len);
|
|
|
|
numstrbuf[len] = '\0';
|
|
|
|
gid = strtoul (numstrbuf, &endp, 10);
|
|
|
|
if (*endp)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gid = strtoul (numstr, &endp, 10);
|
|
|
|
if (*endp)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gid == group)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Insert this group. */
|
|
|
|
if (*start == *size)
|
|
|
|
{
|
|
|
|
/* Need a bigger buffer. */
|
|
|
|
long int newsize;
|
|
|
|
|
|
|
|
if (limit > 0 && *size == limit)
|
|
|
|
/* We reached the maximum. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (limit <= 0)
|
|
|
|
newsize = 2 * *size;
|
|
|
|
else
|
|
|
|
newsize = MIN (limit, 2 * *size);
|
|
|
|
|
|
|
|
gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
|
|
|
|
if (newgroups == NULL)
|
|
|
|
goto errout;
|
|
|
|
*groupsp = groups = newgroups;
|
|
|
|
*size = newsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
groups[*start] = gid;
|
|
|
|
*start += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nis_freeresult (result);
|
|
|
|
return NSS_STATUS_SUCCESS;
|
|
|
|
}
|