summaryrefslogtreecommitdiffstats
path: root/lib/shells.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/shells.c103
1 files changed, 73 insertions, 30 deletions
diff --git a/lib/shells.c b/lib/shells.c
index 6693ab0..18e4cca 100644
--- a/lib/shells.c
+++ b/lib/shells.c
@@ -9,20 +9,11 @@
#include "closestream.h"
#include "shells.h"
-/*
- * is_known_shell() -- if the given shell appears in /etc/shells
- * or vendor defined files.
- * Return 1 if found and return 0 if not found.
- */
-extern int is_known_shell(const char *shell_name)
-{
- int ret = 0;
-
#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
- size_t size = 0;
+static econf_file *open_etc_shells(void)
+{
econf_err error;
- char **keys;
- econf_file *key_file;
+ econf_file *key_file = NULL;
error = econf_readDirs(&key_file,
_PATH_VENDORDIR,
@@ -35,31 +26,84 @@ extern int is_known_shell(const char *shell_name)
syslog(LOG_ALERT,
_("Cannot parse shells files: %s"),
econf_errString(error));
- exit(EXIT_FAILURE);
+ return NULL;
}
- error = econf_getKeys(key_file, NULL, &size, &keys);
- if (error) {
- syslog(LOG_ALERT,
- _("Cannot evaluate entries in shells files: %s"),
- econf_errString(error));
- econf_free (key_file);
- exit(EXIT_FAILURE);
- }
+ return key_file;
+}
+#endif
- for (size_t i = 0; i < size; i++) {
- if (strcmp (keys[i], shell_name) == 0) {
- ret = 1;
- break;
- }
- }
- econf_free (key_file);
+/*
+ * print_shells () -- /etc/shells is outputted to stdout.
+ */
+extern void print_shells(FILE *out, const char *format)
+{
+#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
+ size_t size = 0;
+ econf_err error;
+ char **keys = NULL;
+ econf_file *key_file = open_etc_shells();
+
+ if (!key_file)
+ return;
+
+ error = econf_getKeys(key_file, NULL, &size, &keys);
+ if (error) {
+ econf_free(key_file);
+ errx(EXIT_FAILURE,
+ _("Cannot evaluate entries in shells files: %s"),
+ econf_errString(error));
+ }
+
+ for (size_t i = 0; i < size; i++) {
+ fprintf(out, format, keys[i]);
+ }
+ econf_free(keys);
+ econf_free(key_file);
#else
- char *s;
+ char *s;
+
+ while ((s = getusershell()))
+ fprintf(out, format, s);
+ endusershell();
+#endif
+}
+
+
+/*
+ * is_known_shell() -- if the given shell appears in /etc/shells
+ * or vendor defined files.
+ * Return 1 if found and return 0 if not found.
+ */
+extern int is_known_shell(const char *shell_name)
+{
+ int ret = 0;
if (!shell_name)
return 0;
+#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
+ char *val = NULL;
+ econf_err error;
+ econf_file *key_file = open_etc_shells();
+
+ if (!key_file)
+ return 0;
+
+ error = econf_getStringValue (key_file, NULL, shell_name, &val);
+ if (error) {
+ if (error != ECONF_NOKEY)
+ syslog(LOG_ALERT,
+ _("Cannot evaluate entries in shells files: %s"),
+ econf_errString(error));
+ } else
+ ret = 1;
+
+ free(val);
+ econf_free(key_file);
+#else
+ char *s;
+
setusershell();
while ((s = getusershell())) {
if (*s != '#' && strcmp(shell_name, s) == 0) {
@@ -71,4 +115,3 @@ extern int is_known_shell(const char *shell_name)
#endif
return ret;
}
-