S390: Add new hwcap values.
[glibc.git] / nss / tst-reload2.c
blob5dae16b4f05096e8d4a85ff331563014093f27fb
1 /* Test that reloading is disabled after a chroot.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <nss.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <limits.h>
24 #include <sys/types.h>
25 #include <errno.h>
26 #include <pwd.h>
27 #include <grp.h>
28 #include <unistd.h>
30 #include <support/support.h>
31 #include <support/check.h>
32 #include <support/xunistd.h>
34 #include "nss_test.h"
36 #ifndef PATH_MAX
37 # define PATH_MAX 1024
38 #endif
40 static struct passwd pwd_table1[] =
42 PWD_N (1234, "test1"),
43 PWD_N (4321, "test2"),
44 PWD_LAST ()
47 static const char *group_4[] = {
48 "alpha", "beta", "gamma", "fred", NULL
51 static struct group group_table_data[] =
53 GRP (4),
54 GRP_LAST ()
57 void
58 _nss_test1_init_hook (test_tables *t)
60 t->pwd_table = pwd_table1;
61 t->grp_table = group_table_data;
64 static struct passwd pwd_table2[] =
66 PWD_N (5, "test1"),
67 PWD_N (2468, "test2"),
68 PWD_LAST ()
71 void
72 _nss_test2_init_hook (test_tables *t)
74 t->pwd_table = pwd_table2;
77 static int
78 do_test (void)
80 struct passwd *pw;
81 struct group *gr;
82 char buf1[PATH_MAX];
83 char buf2[PATH_MAX];
85 sprintf (buf1, "/subdir%s", support_slibdir_prefix);
86 xmkdirp (buf1, 0777);
88 /* Copy this DSO into the chroot so it *could* be loaded. */
89 sprintf (buf1, "%s/libnss_files.so.2", support_slibdir_prefix);
90 sprintf (buf2, "/subdir%s/libnss_files.so.2", support_slibdir_prefix);
91 support_copy_file (buf1, buf2);
93 /* Check we're using the "outer" nsswitch.conf. */
95 /* This uses the test1 DSO. */
96 pw = getpwnam ("test1");
97 TEST_VERIFY (pw != NULL);
98 if (pw)
99 TEST_COMPARE (pw->pw_uid, 1234);
101 /* This just loads the test2 DSO. */
102 gr = getgrnam ("name4");
104 /* Change the root dir. */
106 TEST_VERIFY (chroot ("/subdir") == 0);
107 chdir ("/");
109 /* Check we're NOT using the "inner" nsswitch.conf. */
111 /* Both DSOs are loaded, which is used? */
112 pw = getpwnam ("test2");
113 TEST_VERIFY (pw != NULL);
114 if (pw)
115 TEST_VERIFY (pw->pw_uid != 2468);
117 /* The "files" DSO should not be loaded. */
118 gr = getgrnam ("test3");
119 TEST_VERIFY (gr == NULL);
121 /* We should still be using the old configuration. */
122 pw = getpwnam ("test1");
123 TEST_VERIFY (pw != NULL);
124 if (pw)
125 TEST_COMPARE (pw->pw_uid, 1234);
127 return 0;
130 #include <support/test-driver.c>