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/>. */
24 #include <sys/types.h>
31 #include <support/support.h>
32 #include <support/check.h>
33 #include <support/xunistd.h>
38 # define PATH_MAX 1024
41 static struct passwd pwd_table1
[] =
43 PWD_N (1234, "test1"),
44 PWD_N (4321, "test2"),
48 static const char *group_4
[] = {
49 "alpha", "beta", "gamma", "fred", NULL
52 static struct group group_table_data1
[] =
59 _nss_test1_init_hook (test_tables
*t
)
61 t
->pwd_table
= pwd_table1
;
62 t
->grp_table
= group_table_data1
;
65 static struct passwd pwd_table2
[] =
68 PWD_N (2468, "test2"),
72 static const char *group_5
[] = {
76 static struct group group_table_data2
[] =
83 _nss_test2_init_hook (test_tables
*t
)
85 t
->pwd_table
= pwd_table2
;
86 t
->grp_table
= group_table_data2
;
98 sprintf (buf1
, "/subdir%s", support_slibdir_prefix
);
101 /* Copy this DSO into the chroot so it *could* be loaded. */
102 sprintf (buf1
, "%s/libnss_files.so.2", support_slibdir_prefix
);
103 sprintf (buf2
, "/subdir%s/libnss_files.so.2", support_slibdir_prefix
);
104 support_copy_file (buf1
, buf2
);
106 /* Check we're using the "outer" nsswitch.conf. */
108 /* This uses the test1 DSO. */
109 pw
= getpwnam ("test1");
110 TEST_VERIFY (pw
!= NULL
);
112 TEST_COMPARE (pw
->pw_uid
, 1234);
114 /* This just loads the test2 DSO. */
116 TEST_VERIFY (gr
!= NULL
);
119 /* Change the root dir. */
121 TEST_VERIFY (chroot ("/subdir") == 0);
124 /* Check we're NOT using the "inner" nsswitch.conf. */
126 /* Both DSOs are loaded, which is used? */
127 pw
= getpwnam ("test2");
128 TEST_VERIFY (pw
!= NULL
);
130 TEST_VERIFY (pw
->pw_uid
!= 2468);
132 /* We should still be using the old configuration. */
133 pw
= getpwnam ("test1");
134 TEST_VERIFY (pw
!= NULL
);
136 TEST_COMPARE (pw
->pw_uid
, 1234);
138 TEST_VERIFY (gr
!= NULL
);
139 gr
= getgrnam ("name4");
140 TEST_VERIFY (gr
== NULL
);
142 /* hosts in the outer nsswitch is files; the inner one is test1.
143 Verify that we're still using the outer nsswitch *and* that we
144 can load the files DSO. */
145 he
= gethostbyname ("test2");
146 TEST_VERIFY (he
!= NULL
);
151 #include <support/test-driver.c>