]> git.ipfire.org Git - thirdparty/util-linux.git/blame - lib/shells.c
lib/timeutils: print error if timestamp can't be parsed
[thirdparty/util-linux.git] / lib / shells.c
CommitLineData
faeb1b64
KZ
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 */
825feef8
SS
4#include <sys/syslog.h>
5#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
6#include <libeconf.h>
7#endif
8
9#include "closestream.h"
10#include "shells.h"
11
12/*
13 * is_known_shell() -- if the given shell appears in /etc/shells
14 * or vendor defined files.
15 * Return 1 if found and return 0 if not found.
16 */
17extern int is_known_shell(const char *shell_name)
18{
19 int ret = 0;
20
21#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
22 size_t size = 0;
23 econf_err error;
f644f330
KZ
24 char **keys = NULL;
25 econf_file *key_file = NULL;
825feef8
SS
26
27 error = econf_readDirs(&key_file,
28 _PATH_VENDORDIR,
29 "/etc",
30 "shells",
31 NULL,
32 "", /* key only */
33 "#" /* comment */);
34 if (error) {
35 syslog(LOG_ALERT,
36 _("Cannot parse shells files: %s"),
37 econf_errString(error));
38 exit(EXIT_FAILURE);
39 }
40
41 error = econf_getKeys(key_file, NULL, &size, &keys);
42 if (error) {
43 syslog(LOG_ALERT,
44 _("Cannot evaluate entries in shells files: %s"),
45 econf_errString(error));
392d864b 46 econf_free(key_file);
825feef8
SS
47 exit(EXIT_FAILURE);
48 }
49
50 for (size_t i = 0; i < size; i++) {
392d864b 51 if (strcmp(keys[i], shell_name) == 0) {
825feef8
SS
52 ret = 1;
53 break;
54 }
55 }
392d864b
KZ
56 econf_free(keys);
57 econf_free(key_file);
825feef8
SS
58#else
59 char *s;
60
61 if (!shell_name)
62 return 0;
63
64 setusershell();
65 while ((s = getusershell())) {
5099e004 66 if (*s != '#' && strcmp(shell_name, s) == 0) {
825feef8
SS
67 ret = 1;
68 break;
69 }
70 }
71 endusershell();
72#endif
73 return ret;
74}
75