From 1997a2d19506e2070fddf5b07e604d629cf01da3 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 23 Aug 2013 20:12:41 -0700 Subject: [PATCH] jailsetup: use portable getent implementation Not all systems have a getent utility. Since this utility is only used by the jailsetup.sh script, replace it with a limited emulation of getent that should compile on all systems and supports the use jailsetup.sh makes of it. --- install.sh | 7 ++++- jailsetup.sh | 8 +++--- src/.gitignore | 3 +++ src/Makefile | 6 ++++- src/getent.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 src/getent.c diff --git a/install.sh b/install.sh index 302f9fb..f00b9f6 100755 --- a/install.sh +++ b/install.sh @@ -23,11 +23,16 @@ fi echo "*** Checking for compiled utilities..." -if [ ! -f src/can_user_push ]; then +if [ ! -x src/can_user_push ]; then echo "ERROR: src/can_user_push is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi +if [ ! -x src/getent ]; then + echo "ERROR: src/getent is not built! Did you _REALLY_ read INSTALL?" >&2 + echo "ERROR: perhaps you forgot to run make?" >&2 + exit 1 +fi echo "*** Checking for ezcert..." diff --git a/jailsetup.sh b/jailsetup.sh index 37582cd..baedf9b 100755 --- a/jailsetup.sh +++ b/jailsetup.sh @@ -43,13 +43,13 @@ if ! "$getent" passwd "$cfg_mirror_user" >/dev/null; then echo "*** Error: You do not have \"$cfg_mirror_user\" user in system yet." >&2 exit 1 fi -if ! getent passwd "$cfg_cgi_user" >/dev/null; then +if ! "$getent" passwd "$cfg_cgi_user" >/dev/null; then echo "*** Error: You do not have \"$cfg_cgi_user\" user in system yet." >&2 exit 1 fi if [ -n "$dbonly" -a -z "$cfg_owning_group" ]; then - cfg_owning_group="$(getent passwd "$cfg_mirror_user" | cut -d : -f 4)" -elif ! getent group "$cfg_owning_group" >/dev/null; then + cfg_owning_group="$("$getent" passwd "$cfg_mirror_user" | cut -d : -f 4)" +elif ! "$getent" group "$cfg_owning_group" >/dev/null; then echo "*** Error: You do not have \"$cfg_owning_group\" group in system yet." >&2 exit 1 fi @@ -87,7 +87,7 @@ fi if [ ! -s etc/group ]; then cat >etc/group < +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + const char *db; + const char *key; + int found = 0; + + if (argc != 3) + return 1; + + db = argv[1]; + key = argv[2]; + if (!db || !*db || !key || !*key) + return 1; + + if (!strcmp(db, "passwd")) { + struct passwd *pwent = getpwnam(key); + if (pwent) { + found = 1; + printf("%s:%s:%d:%d:%s:%s:%s\n", pwent->pw_name, pwent->pw_passwd, + (int)pwent->pw_uid, (int)pwent->pw_gid, pwent->pw_gecos, pwent->pw_dir, + pwent->pw_shell); + } + } else if (!strcmp(db, "group")) { + struct group *grent = getgrnam(key); + if (grent) { + char **memb = grent->gr_mem; + found = 1; + printf("%s:%s:%d:", grent->gr_name, grent->gr_passwd, grent->gr_gid); + if (memb) { + int first = 1; + for (; *memb; ++memb) { + if (first) + first = 0; + else + putchar(','); + fputs(*memb, stdout); + } + } + putchar('\n'); + } + } else { + return 1; + } + return found ? 0 : 2; +} -- 2.11.4.GIT