hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame nss/tst-nss-db-endgrent.c

Packit 78b636
/* Test for endgrent changing errno for BZ #24696
Packit 78b636
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit 78b636
   This file is part of the GNU C Library.
Packit 78b636
Packit 78b636
   The GNU C Library is free software; you can redistribute it and/or
Packit 78b636
   modify it under the terms of the GNU Lesser General Public
Packit 78b636
   License as published by the Free Software Foundation; either
Packit 78b636
   version 2.1 of the License, or (at your option) any later version.
Packit 78b636
Packit 78b636
   The GNU C Library is distributed in the hope that it will be useful,
Packit 78b636
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 78b636
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 78b636
   Lesser General Public License for more details.
Packit 78b636
Packit 78b636
   You should have received a copy of the GNU Lesser General Public
Packit 78b636
   License along with the GNU C Library; if not, see
Packit 78b636
   <http://www.gnu.org/licenses/>.  */
Packit 78b636
Packit 78b636
#include <stdlib.h>
Packit 78b636
#include <sys/types.h>
Packit 78b636
#include <grp.h>
Packit 78b636
#include <unistd.h>
Packit 78b636
#include <errno.h>
Packit 78b636
Packit 78b636
#include <support/check.h>
Packit 78b636
#include <support/support.h>
Packit 78b636
Packit 78b636
/* The following test verifies that if the db NSS Service is initialized
Packit 78b636
   with no database (getgrent), that a subsequent closure (endgrent) does
Packit 78b636
   not set errno. In the case of the db service it is not an error to close
Packit 78b636
   the service and so it should not set errno.  */
Packit 78b636
Packit 78b636
static int
Packit 78b636
do_test (void)
Packit 78b636
{
Packit 78b636
  /* Just make sure it's not there, although usually it won't be.  */
Packit 78b636
  unlink ("/var/db/group.db");
Packit 78b636
Packit 78b636
  /* This, in conjunction with the testroot's nsswitch.conf, causes
Packit 78b636
     the nss_db module to be "connected" and initialized - but the
Packit 78b636
     testroot has no group.db, so no mapping will be created.  */
Packit 78b636
  getgrent ();
Packit 78b636
Packit 78b636
  errno = 0;
Packit 78b636
Packit 78b636
  /* Before the fix, this would call munmap (NULL) and set errno.  */
Packit 78b636
  endgrent ();
Packit 78b636
Packit 78b636
  if (errno != 0)
Packit 78b636
    FAIL_EXIT1 ("endgrent set errno to %d\n", errno);
Packit 78b636
Packit 78b636
  return 0;
Packit 78b636
}
Packit 78b636
#include <support/test-driver.c>