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