linux: Return unsupported if procfs can not be mount on tst-ttyname-namespace
[glibc.git] / shadow / tst-shadow.c
blob48f7167baa2e3f219cd1c127c47ea7b61ad186fe
1 #include <shadow.h>
2 #include <stdio.h>
3 #include <string.h>
6 static const struct spwd data[] =
8 { (char *) "one", (char *) "pwdone", 1, 2, 3, 4, 5, 6, 7 },
9 { (char *) "two", (char *) "pwdtwo", 11, 12, 13, 14, 15, 16, 17 },
10 { (char *) "three", (char *) "pwdthree", -1, 22, 23, 24, 25, 26, 27 },
11 { (char *) "four", (char *) "pwdfour", 31, -1, 33, 34, 35, 36, 37 },
12 { (char *) "five", (char *) "pwdfive", 41, 42, -1, 44, 45, 46, 47 },
13 { (char *) "six", (char *) "pwdsix", 51, 52, 53, -1, 55, 56, 57 },
14 { (char *) "seven", (char *) "pwdseven", 61, 62, 63, 64, -1, 66, 67 },
15 { (char *) "eight", (char *) "pwdeigth", 71, 72, 73, 74, 75, -1, 77 },
16 { (char *) "nine", (char *) "pwdnine", 81, 82, 83, 84, 85, 86, ~0ul },
18 #define ndata (sizeof (data) / sizeof (data[0]))
21 static int
22 do_test (void)
24 FILE *fp = tmpfile ();
25 if (fp == NULL)
27 puts ("cannot open temporary file");
28 return 1;
31 for (size_t i = 0; i < ndata; ++i)
32 if (putspent (&data[i], fp) != 0)
34 printf ("putspent call %zu failed\n", i + 1);
35 return 1;
38 rewind (fp);
40 int result = 0;
41 int seen = -1;
42 struct spwd *p;
43 while ((p = fgetspent (fp)) != NULL)
45 ++seen;
46 if (strcmp (p->sp_namp, data[seen].sp_namp) != 0)
48 printf ("sp_namp of entry %d does not match: %s vs %s\n",
49 seen + 1, p->sp_namp, data[seen].sp_namp);
50 result = 1;
52 if (strcmp (p->sp_pwdp, data[seen].sp_pwdp) != 0)
54 printf ("sp_pwdp of entry %d does not match: %s vs %s\n",
55 seen + 1, p->sp_pwdp, data[seen].sp_pwdp);
56 result = 1;
58 #define T(f) \
59 if (p->f != data[seen].f) \
60 { \
61 printf ("%s of entry %d wrong: %ld vs %ld\n", \
62 #f, seen + 1, p->f, data[seen].f); \
63 result = 1; \
65 T (sp_lstchg);
66 T (sp_min);
67 T (sp_max);
68 T (sp_warn);
69 T (sp_expire);
70 if (p->sp_flag != data[seen].sp_flag)
72 printf ("sp_flag of entry %d wrong: %lu vs %lu\n",
73 seen + 1, p->sp_flag, data[seen].sp_flag);
74 result = 1;
78 fclose (fp);
80 return result;
83 #define TEST_FUNCTION do_test ()
84 #include "../test-skeleton.c"