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

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