Remove "[Add new features here]" for 2.27
[glibc.git] / nss / tst-nss-test3.c
blob308708f387aee6872e42730062230b20082c001a
1 /* Test error checking for group 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/>. */
19 #include <nss.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/signal.h>
25 #include "nss_test.h"
27 /* The names here are arbitrary, but the *lengths* of the arrays is
28 not, and groups 6 and 7 test for partial matches. */
30 static const char *group_2[] = {
31 "foo", "bar", NULL
34 static const char *group_3[] = {
35 "tom", "dick", "harry", NULL
38 static const char *group_4[] = {
39 "alpha", "beta", "gamma", "fred", NULL
42 static const char *group_6[] = {
43 "larry", "curly", "moe", NULL
46 static const char *group_7[] = {
47 "larry", "curly", "darryl", NULL
50 static const char *group_14[] = {
51 "huey", "dewey", "louis", NULL
54 /* Note that we're intentionally causing mis-matches here; the purpose
55 of this test case is to test each error check and make sure they
56 detect the errors they check for, and to ensure that the harness
57 can process all the error cases properly (i.e. a NULL gr_name
58 field). We check for the correct number of mismatches at the
59 end. */
61 /* This is the data we're giving the service. */
62 static struct group group_table_data[] = {
63 GRP(4), /* match */
64 GRP_N(8, "name6", group_6), /* wrong gid */
65 GRP_N(14, NULL, group_14), /* missing name */
66 GRP(14), /* unexpected name */
67 GRP_N(7, "name7_wrong", group_7), /* wrong name */
68 { .gr_name = (char *)"name5", .gr_passwd = (char *)"wilma", .gr_gid = 5, .gr_mem = NULL }, /* unexpected passwd */
69 { .gr_name = (char *)"name5", .gr_passwd = NULL, .gr_gid = 5, .gr_mem = NULL }, /* missing passwd */
70 { .gr_name = (char *)"name5", .gr_passwd = (char *)"wilma", .gr_gid = 5, .gr_mem = NULL }, /* wrong passwd */
71 GRP_N(3, "name3a", NULL), /* missing member list */
72 GRP_N(3, "name3b", group_3), /* unexpected member list */
73 GRP_N(3, "name3c", group_3), /* wrong/short member list */
74 GRP_N(3, "name3d", group_4), /* wrong/long member list */
75 GRP_LAST ()
78 /* This is the data we compare against. */
79 static struct group group_table[] = {
80 GRP(4),
81 GRP(6),
82 GRP(14),
83 GRP_N(14, NULL, group_14),
84 GRP(7),
85 { .gr_name = (char *)"name5", .gr_passwd = NULL, .gr_gid = 5, .gr_mem = NULL },
86 { .gr_name = (char *)"name5", .gr_passwd = (char *)"fred", .gr_gid = 5, .gr_mem = NULL },
87 { .gr_name = (char *)"name5", .gr_passwd = (char *)"fred", .gr_gid = 5, .gr_mem = NULL },
88 GRP_N(3, "name3a", group_3),
89 GRP_N(3, "name3b", NULL),
90 GRP_N(3, "name3c", group_4),
91 GRP_N(3, "name3d", group_3),
92 GRP(2),
93 GRP_LAST ()
96 void
97 _nss_test1_init_hook(test_tables *t)
99 t->grp_table = group_table_data;
102 static int
103 do_test (void)
105 int retval = 0;
106 int i;
107 struct group *g = NULL;
109 __nss_configure_lookup ("group", "test1");
111 setgrent ();
113 i = 0;
114 for (g = getgrent () ;
115 g != NULL && ! GRP_ISLAST(&group_table[i]);
116 ++i, g = getgrent ())
118 retval += compare_groups (i, g, & group_table[i]);
121 endgrent ();
123 if (g)
125 printf ("FAIL: [?] group entry %u.%s unexpected\n", g->gr_gid, g->gr_name);
126 ++retval;
128 if (group_table[i].gr_name || group_table[i].gr_gid)
130 printf ("FAIL: [%d] group entry %u.%s missing\n", i,
131 group_table[i].gr_gid, group_table[i].gr_name);
132 ++retval;
135 #define EXPECTED 18
136 if (retval == EXPECTED)
138 if (retval > 0)
139 printf ("PASS: Found %d expected errors\n", retval);
140 return 0;
142 else
144 printf ("FAIL: Found %d errors, expected %d\n", retval, EXPECTED);
145 return 1;
149 #define TEST_FUNCTION do_test ()
150 #include "../test-skeleton.c"