glibc/nss/nss_db/db-netgrp.c
Paul Eggert 5a82c74822 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 02:43:31 -07:00

123 lines
3.2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Netgroup file parser in nss_db modules.
Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <ctype.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <netgroup.h>
#include <string.h>
#include <stdint.h>
#include <libc-lock.h>
#include <paths.h>
#include <stdlib.h>
#include "nsswitch.h"
#include "nss_db.h"
/* The hashing function we use. */
#include "../intl/hash-string.h"
#define DBFILE _PATH_VARDB "netgroup.db"
/* Maintenance of the shared handle open on the database. */
enum nss_status
_nss_db_setnetgrent (const char *group, struct __netgrent *result)
{
struct nss_db_map state;
enum nss_status status = internal_setent (DBFILE, &state);
if (status == NSS_STATUS_SUCCESS)
{
const struct nss_db_header *header = state.header;
const stridx_t *hashtable
= (const stridx_t *) ((const char *) header
+ header->dbs[0].hashoffset);
const char *valstrtab = (const char *) header + header->valstroffset;
uint32_t hashval = __hash_string (group);
size_t grouplen = strlen (group);
size_t hidx = hashval % header->dbs[0].hashsize;
size_t hval2 = 1 + hashval % (header->dbs[0].hashsize - 2);
status = NSS_STATUS_NOTFOUND;
while (hashtable[hidx] != ~((stridx_t) 0))
{
const char *valstr = valstrtab + hashtable[hidx];
if (strncmp (valstr, group, grouplen) == 0
&& isblank (valstr[grouplen]))
{
const char *cp = &valstr[grouplen + 1];
while (isblank (*cp))
++cp;
if (*cp != '\0')
{
result->data = strdup (cp);
if (result->data == NULL)
status = NSS_STATUS_TRYAGAIN;
else
{
status = NSS_STATUS_SUCCESS;
result->cursor = result->data;
}
break;
}
}
if ((hidx += hval2) >= header->dbs[0].hashsize)
hidx -= header->dbs[0].hashsize;
}
internal_endent (&state);
}
return status;
}
enum nss_status
_nss_db_endnetgrent (struct __netgrent *result)
{
free (result->data);
result->data = NULL;
result->data_size = 0;
result->cursor = NULL;
return NSS_STATUS_SUCCESS;
}
extern enum nss_status _nss_netgroup_parseline (char **cursor,
struct __netgrent *result,
char *buffer, size_t buflen,
int *errnop);
enum nss_status
_nss_db_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
int *errnop)
{
enum nss_status status;
status = _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,
errnop);
return status;
}