Supporting vendor given -shells- configuration file

This commit is contained in:
Stefan Schubert
2022-11-28 17:18:09 +01:00
committed by Serge Hallyn
parent b2d202cb5d
commit a27d5c51f1
6 changed files with 126 additions and 10 deletions

View File

@@ -11,7 +11,8 @@ AM_CPPFLAGS = \
-I${top_srcdir}/lib \
-I$(top_srcdir)/libmisc \
-I$(top_srcdir) \
-DLOCALEDIR=\"$(datadir)/locale\"
-DLOCALEDIR=\"$(datadir)/locale\" \
$(ECONF_CPPFLAGS)
AM_CFLAGS = $(LIBBSD_CFLAGS)

View File

@@ -33,6 +33,13 @@
#ifndef SHELLS_FILE
#define SHELLS_FILE "/etc/shells"
#endif
#ifdef HAVE_VENDORDIR
#include <libeconf.h>
#define SHELLS "shells"
#define ETCDIR "/etc"
#endif
/*
* Global variables
*/
@@ -127,17 +134,59 @@ static bool is_restricted_shell (const char *sh)
* If getusershell() is available (Linux, *BSD, possibly others), use it
* instead of re-implementing it.
*/
#ifdef HAVE_VENDORDIR
static bool shell_is_listed (const char *sh)
{
char *cp;
bool found = false;
#ifndef HAVE_GETUSERSHELL
char buf[BUFSIZ];
FILE *fp;
#endif
size_t size = 0;
econf_err error;
char **keys;
econf_file *key_file;
error = econf_readDirs(&key_file,
VENDORDIR,
ETCDIR,
SHELLS,
NULL,
"", /* key only */
"#" /* comment */);
if (error) {
fprintf (stderr,
_("Cannot parse shell files: %s"),
econf_errString(error));
fail_exit (1);
}
error = econf_getKeys(key_file, NULL, &size, &keys);
if (error) {
fprintf (stderr,
_("Cannot evaluate entries in shell files: %s"),
econf_errString(error));
econf_free (key_file);
fail_exit (1);
}
for (size_t i = 0; i < size; i++) {
if (strcmp (keys[i], sh) == 0) {
found = true;
break;
}
}
econf_free (key_file);
return found;
}
#else /* without HAVE_VENDORDIR */
static bool shell_is_listed (const char *sh)
{
bool found = false;
#ifdef HAVE_GETUSERSHELL
char *cp;
setusershell ();
while ((cp = getusershell ())) {
if (strcmp (cp, sh) == 0) {
@@ -147,6 +196,9 @@ static bool shell_is_listed (const char *sh)
}
endusershell ();
#else
char buf[BUFSIZ];
FILE *fp;
fp = fopen (SHELLS_FILE, "r");
if (NULL == fp) {
return false;
@@ -171,6 +223,7 @@ static bool shell_is_listed (const char *sh)
#endif
return found;
}
#endif /* with HAVE_VENDORDIR */
/*
* process_flags - parse the command line options