Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First cut at DATASET-780, permit existing users.

There should be an option with packages to re-use an existing user or
group, even if a specific uid/gid is provided.  This commit introduces a
user variable to configure this: PKGINSTALL_IGNORE_UIDGID.

When PKGINSTALL_IGNORE_UIDGID is true then pkg_install will not try to
create the user/group as specified.  If the user/group does not exist
but the specified uid/gid is, then the uid/gid will be stripped so that
the system can allocate one at random.
  • Loading branch information...
commit e9d7ae57d011bdd9e1768848da6403ec72b2d599 1 parent c8cd552
@jperkin jperkin authored
View
15 mk/pkginstall/bsd.pkginstall.mk
@@ -7,6 +7,17 @@
#
# User-settable variables:
#
+# PKGINSTALL_IGNORE_UIDGID
+# Whether or not to treat the specific uid/gid provided by the package as
+# simply advisory. In the case where either the user/group already
+# exists but the uid/gid does not match, or the uid/gid is already taken
+# by a different user:
+#
+# * "yes" will add the user/group if necessary with an unspecified uid/gid
+# * "no" will not add the user/group and fail the install.
+#
+# Default value: no
+#
# PKGINSTALL_VERBOSE
# A list of scriptlets that will be verbose and output a message
# noting the actions taken.
@@ -20,6 +31,7 @@
_VARGROUPS+= pkginstall
_USER_VARS.pkginstall= \
+ PKGINSTALL_IGNORE_UIDGID \
PKGINSTALL_VERBOSE \
PKG_CREATE_USERGROUP \
PKG_CONFIG PKG_CONFIG_PERMS \
@@ -998,6 +1010,9 @@ FILES_SUBST+= PKG_RCD_SCRIPTS=${PKG_RCD_SCRIPTS:Q}
FILES_SUBST+= PKG_REGISTER_SHELLS=${PKG_REGISTER_SHELLS:Q}
FILES_SUBST+= PKG_UPDATE_FONTS_DB=${PKG_UPDATE_FONTS_DB:Q}
+PKGINSTALL_IGNORE_UIDGID?= no
+FILES_SUBST+= PKGINSTALL_IGNORE_UIDGID=${PKGINSTALL_IGNORE_UIDGID:Q}
+
.if defined(PKG_DEVELOPER) && ${PKG_DEVELOPER} != "no"
PKGINSTALL_VERBOSE?= all
.else
View
65 mk/pkginstall/usergroup
@@ -74,6 +74,15 @@ PKG_METADATA_DIR="${2-${CURDIR}}"
PKG_REFCOUNT_USERS_DBDIR="${PKG_REFCOUNT_DBDIR}/users"
PKG_REFCOUNT_GROUPS_DBDIR="${PKG_REFCOUNT_DBDIR}/groups"
+case "${PKGINSTALL_IGNORE_UIDGID:-@PKGINSTALL_IGNORE_UIDGID@}" in
+[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+ _PKGINSTALL_IGNORE_UIDGID=yes
+ ;;
+[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+ _PKGINSTALL_IGNORE_UIDGID=no
+ ;;
+esac
+
case "${PKG_CREATE_USERGROUP:-@PKG_CREATE_USERGROUP@}" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
_PKG_CREATE_USERGROUP=yes
@@ -126,8 +135,10 @@ ADD)
token="$shadow_dir/${PKGNAME}"
if ${TEST} ! -d "$shadow_dir"; then
${MKDIR} $shadow_dir
- group_exists $group $groupid &&
- ${ECHO} "${PKGNAME}" > $preexist
+ group_exists $group $groupid
+ case $? in
+ 0|2) ${ECHO} "${PKGNAME}" > $preexist ;;
+ esac
fi
if ${TEST} -f "$token" && \
${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
@@ -139,8 +150,11 @@ ADD)
yes)
group_exists $group $groupid
case $? in
- 0) ;;
1) addgroup "$group" "$groupid" ;;
+ 3) case ${_PKGINSTALL_IGNORE_UIDGID} in
+ yes) addgroup "$group" "" ;;
+ esac
+ ;;
esac
;;
esac
@@ -163,8 +177,10 @@ ADD)
token="$shadow_dir/${PKGNAME}"
if ${TEST} ! -d "$shadow_dir"; then
${MKDIR} $shadow_dir
- user_exists $user $userid &&
- ${ECHO} "${PKGNAME}" > $preexist
+ user_exists $user $userid
+ case $? in
+ 0|2) ${ECHO} "${PKGNAME}" > $preexist ;;
+ esac
fi
if ${TEST} -f "$token" && \
${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
@@ -177,10 +193,16 @@ ADD)
group_exists $group || continue
user_exists $user $userid
case $? in
- 0) ;;
1) adduser "$user" "$group" "$userid" \
"$descr" "$home" "$shell"
;;
+ 3) case ${_PKGINSTALL_IGNORE_UIDGID} in
+ yes)
+ adduser "$user" "$group" "" \
+ "$descr" "$home" "$shell"
+ ;;
+ esac
+ ;;
esac
;;
esac
@@ -254,7 +276,14 @@ CHECK-ADD)
IFS="$SAVEIFS"
case $group in
"") continue ;;
- *) group_exists $group $groupid && continue ;;
+ *) group_exists $group $groupid
+ case $? in
+ 0|3) case ${_PKGINSTALL_IGNORE_UIDGID} in
+ yes) continue ;;
+ esac
+ ;;
+ esac
+ ;;
esac
case "$printed_header" in
yes) ;;
@@ -285,7 +314,15 @@ CHECK-ADD)
IFS="$SAVEIFS"
case $user in
"") continue ;;
- *) user_exists $user $userid && continue ;;
+ *) user_exists $user $userid
+ case $? in
+ 0) continue ;;
+ 3) case ${_PKGINSTALL_IGNORE_UIDGID} in
+ yes) continue ;;
+ esac
+ ;;
+ esac
+ ;;
esac
case "$printed_header" in
yes) ;;
@@ -321,7 +358,11 @@ CHECK-REMOVE)
IFS="$SAVEIFS"
case $user in
"") continue ;;
- *) user_exists $user $userid || continue ;;
+ *) user_exists $user $userid
+ case $? in
+ 0|2) continue ;;
+ esac
+ ;;
esac
shadow_dir="${PKG_REFCOUNT_USERS_DBDIR}/$user"
${TEST} ! -d "$shadow_dir" || continue # refcount isn't zero
@@ -348,7 +389,11 @@ CHECK-REMOVE)
IFS="$SAVEIFS"
case $group in
"") continue ;;
- *) group_exists $group $groupid || continue ;;
+ *) group_exists $group $groupid
+ case $? in
+ 0|2) continue ;;
+ esac
+ ;;
esac
shadow_dir="${PKG_REFCOUNT_GROUPS_DBDIR}/$group"
${TEST} ! -d "$shadow_dir" || continue # refcount isn't zero
View
48 mk/pkginstall/usergroupfuncs
@@ -14,81 +14,89 @@
# 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
+# Returns 2 if $group exists but $groupid does not match
+# Returns 3 if $group does not exist but $groupid does
+# Returns 4 for all errors
#
group_exists()
{
_group="$1"; _groupid="$2"
- ${TEST} -n "$_group" || return 3
+ ${TEST} -n "$_group" || return 4
# Check using chgrp to work properly in an NSS/NIS environment.
_tmpdir="./.pkginstall.$$"
- ${MKDIR} -p $_tmpdir 2>/dev/null || return 3
+ ${MKDIR} -p $_tmpdir 2>/dev/null || return 4
${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 }'`
+ ${RM} -fr $_tmpdir
${TEST} -n "$_groupid" || _groupid=$_id
if ${TEST} "$_groupid" = "$_id"; then
- ${RM} -fr $_tmpdir; return 0
+ return 0
fi
- ${RM} -fr $_tmpdir; return 2
+ return 2
elif ${TEST} -z "$_groupid"; then
+ ${RM} -fr $_tmpdir
# $_group doesn't exist and $_groupid is not set
- ${RM} -fr $_tmpdir; return 1
+ return 1
elif ${CHGRP} $_groupid $_testpath >/dev/null 2>&1; then
_name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $4 }'`
+ ${RM} -fr $_tmpdir
if ${TEST} "$_name" != "$_groupid"; then
# $_group doesn't exist, but $_groupid exists
- ${RM} -fr $_tmpdir; return 2
+ return 3
fi
# neither $_group nor $_groupid exist
- ${RM} -fr $_tmpdir; return 1
+ return 1
fi
- ${RM} -fr $_tmpdir; return 3
+ ${RM} -fr $_tmpdir; return 4
}
# 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
+# Returns 2 if $user exists but $userid does not match
+# Returns 3 if $user does not exist but $userid does
+# Returns 4 for all errors
#
user_exists()
{
_user="$1"; _userid="$2"
- ${TEST} -n "$_user" || return 3
+ ${TEST} -n "$_user" || return 4
# Check using chown to work properly in an NSS/NIS environment.
_tmpdir="./.pkginstall.$$"
- ${MKDIR} -p $_tmpdir 2>/dev/null || return 3
+ ${MKDIR} -p $_tmpdir 2>/dev/null || return 4
${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 }'`
+ ${RM} -fr $_tmpdir
${TEST} -n "$_userid" || _userid=$_id
if ${TEST} "$_userid" = "$_id"; then
- ${RM} -fr $_tmpdir; return 0
+ return 0
fi
- ${RM} -fr $_tmpdir; return 2
+ return 2
elif ${TEST} -z "$_userid"; then
+ ${RM} -fr $_tmpdir
# $_user doesn't exist and $_userid is not set
- ${RM} -fr $_tmpdir; return 1
+ return 1
elif ${CHOWN} $_userid $_testpath >/dev/null 2>&1; then
_name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $3 }'`
+ ${RM} -fr $_tmpdir
if ${TEST} "$_name" != "$_userid"; then
# $_user doesn't exist, but $_userid exists
- ${RM} -fr $_tmpdir; return 2
+ return 3
fi
# neither $_user nor $_userid exist
- ${RM} -fr $_tmpdir; return 1
+ return 1
fi
- ${RM} -fr $_tmpdir; return 3
+ ${RM} -fr $_tmpdir; return 4
}
# adduser user group [userid] [descr] [home] [shell]
Please sign in to comment.
Something went wrong with that request. Please try again.