pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/pkginstall Linux shadow-utils provides a useradd th...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3fc2f0d9166a
branches:  trunk
changeset: 519968:3fc2f0d9166a
user:      ben <ben%pkgsrc.org@localhost>
date:      Thu Oct 12 23:10:55 2006 +0000

description:
Linux shadow-utils provides a useradd that fails when creating a home
directory under a base directory hat does not exist.  Add workaround
to ensure that the base directory does exist.  This addresses PR#34779

diffstat:

 mk/pkginstall/usergroupfuncs.Linux |  146 +++++++++++++++++++++++++++++++++++++
 1 files changed, 146 insertions(+), 0 deletions(-)

diffs (150 lines):

diff -r 5d8e91632ba4 -r 3fc2f0d9166a mk/pkginstall/usergroupfuncs.Linux
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/pkginstall/usergroupfuncs.Linux        Thu Oct 12 23:10:55 2006 +0000
@@ -0,0 +1,146 @@
+# $NetBSD: usergroupfuncs.Linux,v 1.1 2006/10/12 23:10:55 ben Exp $
+#
+# Platform-specific adduser and addgroup functionality
+# on top of shadow-utils.  (Not libuser)
+
+# group_exists group [groupid]
+#      Returns 0 if $group exists and has gid $groupid
+#      Returns 1 if neither $group nor $groupid exist
+#      Returns 2 if $group or $groupid exist but don't match
+#      Returns 3 for all errors
+#      
+group_exists()
+{
+       _group="$1"; _groupid="$2"
+       ${TEST} -n "$_group" || return 3
+
+       # Check using chgrp to work properly in an NSS/NIS environment.
+       _tmpdir="./.pkginstall.$$"
+       ${MKDIR} -p $_tmpdir 2>/dev/null || return 3
+       ${CHMOD} 0700 $_tmpdir
+       _testpath="$_tmpdir/group_exists"
+       ${ECHO} > $_testpath
+       if ${CHGRP} $_group $_testpath >/dev/null 2>&1; then
+               # $_group exists
+               _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $4 }'`
+               ${TEST} -n "$_groupid" || _groupid=$_id
+               if ${TEST} "$_groupid" = "$_id"; then
+                       ${RM} -fr $_tmpdir; return 0
+               fi
+               ${RM} -fr $_tmpdir; return 2
+       elif ${TEST} -z "$_groupid"; then
+               # $_group doesn't exist and $_groupid is not set
+               ${RM} -fr $_tmpdir; return 1
+       elif ${CHGRP} $_groupid $_testpath >/dev/null 2>&1; then
+               _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $4 }'`
+               if ${TEST} "$_name" != "$_groupid"; then
+                       # $_group doesn't exist, but $_groupid exists
+                       ${RM} -fr $_tmpdir; return 2
+               fi
+               # neither $_group nor $_groupid exist
+               ${RM} -fr $_tmpdir; return 1
+       fi
+       ${RM} -fr $_tmpdir; return 3
+}
+
+# user_exists user [userid]
+#      Returns 0 if $user exists and has uid $userid
+#      Returns 1 if neither $user nor $userid exist
+#      Returns 2 if $user or $userid exist but don't match
+#      Returns 3 for all errors
+#      
+user_exists()
+{
+       _user="$1"; _userid="$2"
+       ${TEST} -n "$_user" || return 3
+
+       # Check using chown to work properly in an NSS/NIS environment.
+       _tmpdir="./.pkginstall.$$"
+       ${MKDIR} -p $_tmpdir 2>/dev/null || return 3
+       ${CHMOD} 0700 $_tmpdir
+       _testpath="$_tmpdir/user_exists"
+       ${ECHO} > $_testpath
+       if ${CHOWN} $_user $_testpath >/dev/null 2>&1; then
+               # $_user exists
+               _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $3 }'`
+               ${TEST} -n "$_userid" || _userid=$_id
+               if ${TEST} "$_userid" = "$_id"; then
+                       ${RM} -fr $_tmpdir; return 0
+               fi
+               ${RM} -fr $_tmpdir; return 2
+       elif ${TEST} -z "$_userid"; then
+               # $_user doesn't exist and $_userid is not set
+               ${RM} -fr $_tmpdir; return 1
+       elif ${CHOWN} $_userid $_testpath >/dev/null 2>&1; then
+               _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $3 }'`
+               if ${TEST} "$_name" != "$_userid"; then
+                       # $_user doesn't exist, but $_userid exists
+                       ${RM} -fr $_tmpdir; return 2
+               fi
+               # neither $_user nor $_userid exist
+               ${RM} -fr $_tmpdir; return 1
+       fi
+       ${RM} -fr $_tmpdir; return 3
+}
+
+# adduser user group [userid] [descr] [home] [shell]
+adduser()
+{
+       user="$1"; group="$2"; userid="$3"
+       descr="$4"; home="$5" shell="$6"
+       ${TEST} $# -eq 6 || return 1
+       ${TEST} -n "$user" || return 2
+       ${TEST} -n "$group" || return 2
+
+       USERADD="@USERADD@"
+
+       case $user in
+       ${PKGNAME%-[0-9]*})     descr_dflt="$user user" ;;
+       *)                      descr_dflt="${PKGNAME%-[0-9]*} $user user" ;;
+       esac
+       : ${descr:="$descr_dflt"}
+       : ${home:="@PKG_USER_HOME@"}
+       : ${shell:="@PKG_USER_SHELL@"}
+
+       if ${TEST} -n "${USERADD}" -a -x "${USERADD}"; then
+               ${ECHO} "Creating user: $user"
+               # if home directory is missing, make and remove it
+               # ensures that the base directory exists, for shadow-utils
+               if ! ${TEST} -d "$home"; then
+                       ${MKDIR} -p "$home"
+                       ${RMDIR} "$home" 2>/dev/null
+               fi
+               case $userid in
+               "")
+                       ${USERADD}                                      \
+                               -c "$descr" -d "$home" -s "$shell"      \
+                               -g $group $user
+                       ;;
+               *)
+                       ${USERADD}                                      \
+                               -c "$descr" -d "$home" -s "$shell"      \
+                               -g $group -u $userid $user
+                       ;;
+               esac
+       fi
+       return 0
+}
+
+# adduser group [groupid]
+addgroup()
+{
+       group="$1"; groupid="$2"
+       ${TEST} $# -eq 2 || return 1
+       ${TEST} -n "$group" || return 2
+
+       GROUPADD="@GROUPADD@"
+
+       if ${TEST} -n "${GROUPADD}" -a -x "${GROUPADD}"; then
+               ${ECHO} "Creating group: $group";
+               case $groupid in
+               "")     ${GROUPADD} $group ;;
+               *)      ${GROUPADD} -g $groupid $group ;;
+               esac
+       fi
+       return 0
+}



Home | Main Index | Thread Index | Old Index