1 /* Test error checking for passwd entries.
2 Copyright (C) 2017 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 <http://www.gnu.org/licenses/>. */
25 #include <support/support.h>
29 /* The specific values and names used here are arbitrary, other than
30 correspondence (with suitable differences according to the tests as
31 commented) between the given and expected entries. */
33 static struct passwd pwd_table
[] = {
34 PWD (100), /* baseline, matches */
35 PWD (300), /* wrong name and uid */
36 PWD_N (200, NULL
), /* missing name */
37 PWD (60), /* unexpected name */
38 { .pw_name
= (char *)"name20000", .pw_passwd
= (char *) "*", .pw_uid
= 20000, \
39 .pw_gid
= 200, .pw_gecos
= (char *) "*", .pw_dir
= (char *) "*", \
40 .pw_shell
= (char *) "*" }, /* wrong gid */
41 { .pw_name
= (char *)"name2", .pw_passwd
= (char *) "x", .pw_uid
= 2, \
42 .pw_gid
= 2, .pw_gecos
= (char *) "y", .pw_dir
= (char *) "z", \
43 .pw_shell
= (char *) "*" }, /* spot check other text fields */
47 static struct passwd exp_table
[] = {
58 _nss_test1_init_hook(test_tables
*t
)
60 t
->pwd_table
= pwd_table
;
70 __nss_configure_lookup ("passwd", "test1");
76 p
!= NULL
&& ! PWD_ISLAST (& exp_table
[i
]);
78 retval
+= compare_passwds (i
, p
, & exp_table
[i
]);
85 printf ("FAIL: [?] passwd entry %u.%s unexpected\n", p
->pw_uid
, p
->pw_name
);
88 if (! PWD_ISLAST (& exp_table
[i
]))
90 printf ("FAIL: [%d] passwd entry %u.%s missing\n", i
,
91 exp_table
[i
].pw_uid
, exp_table
[i
].pw_name
);
96 if (retval
== EXPECTED
)
99 printf ("PASS: Found %d expected errors\n", retval
);
104 printf ("FAIL: Found %d errors, expected %d\n", retval
, EXPECTED
);
109 #include <support/test-driver.c>