tst-nss-db-endgrent.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Test for endgrent changing errno for BZ #24696
  2. Copyright (C) 2019-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <stdlib.h>
  16. #include <sys/types.h>
  17. #include <grp.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <support/check.h>
  21. #include <support/support.h>
  22. /* The following test verifies that if the db NSS Service is initialized
  23. with no database (getgrent), that a subsequent closure (endgrent) does
  24. not set errno. In the case of the db service it is not an error to close
  25. the service and so it should not set errno. */
  26. static int
  27. do_test (void)
  28. {
  29. /* Just make sure it's not there, although usually it won't be. */
  30. unlink ("/var/db/group.db");
  31. /* This, in conjunction with the testroot's nsswitch.conf, causes
  32. the nss_db module to be "connected" and initialized - but the
  33. testroot has no group.db, so no mapping will be created. */
  34. getgrent ();
  35. errno = 0;
  36. /* Before the fix, this would call munmap (NULL) and set errno. */
  37. endgrent ();
  38. if (errno != 0)
  39. FAIL_EXIT1 ("endgrent set errno to %d\n", errno);
  40. return 0;
  41. }
  42. #include <support/test-driver.c>