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