1 /* Test the getusershell, setusershell, endusershell functions.
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Collin Funk <collin.funk1@gmail.com>, 2024. */
24 #include "signature.h"
25 SIGNATURE_CHECK (getusershell
, char *, (void));
26 SIGNATURE_CHECK (setusershell
, void, (void));
27 SIGNATURE_CHECK (endusershell
, void, (void));
35 /* The shell names in the order they appear in '/etc/shells'. */
36 static char **shells
= NULL
;
37 static size_t shell_count
= 0;
39 /* Prepare the shells array. */
46 /* Avoid reallocation. */
48 shells
= malloc (shell_count
* sizeof (char *));
49 ASSERT (shells
!= NULL
);
51 for (; (ptr
= getusershell ()); ++i
)
53 /* Make sure comments and empty lines are ignored. */
54 ASSERT (ptr
[0] != '#');
55 ASSERT (ptr
[0] != '\0');
59 shells
= realloc (shells
, shell_count
* sizeof (char *));
60 ASSERT (shells
!= NULL
);
62 shells
[i
] = strdup (ptr
);
63 ASSERT (shells
[i
] != NULL
);
69 /* Assuming that '/etc/shells' does not change during the duration of this
70 test, check that setusershell puts us back at the start of the file. */
77 /* Return to the start of the file. */
80 /* Make sure order is preserved. */
81 for (i
= 0; i
< shell_count
; ++i
)
83 ptr
= getusershell ();
85 ASSERT (STREQ (ptr
, shells
[i
]));
91 ASSERT (getusershell () == NULL
);
104 return test_exit_status
;