diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2016-09-22 13:08:21 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2016-09-22 13:08:21 +0000 |
commit | 3e724a847a3a2f96d39c24a4e8184d63ba85b46b (patch) | |
tree | 16d0722b5672a5024b8971fbfcbb76e176c2175c | |
parent | 170a442702fc92692138f7d1d3e913a7e67dc134 (diff) |
Make sure we don't have conflicting UIDs/GIDs when adding user/group.
reported by florian@
-rw-r--r-- | usr.sbin/sysmerge/sysmerge.sh | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.sbin/sysmerge/sysmerge.sh b/usr.sbin/sysmerge/sysmerge.sh index 4a87d7acc39..28d3e856a66 100644 --- a/usr.sbin/sysmerge/sysmerge.sh +++ b/usr.sbin/sysmerge/sysmerge.sh @@ -1,6 +1,6 @@ #!/bin/ksh - # -# $OpenBSD: sysmerge.sh,v 1.227 2016/07/30 06:31:17 ajacoutot Exp $ +# $OpenBSD: sysmerge.sh,v 1.228 2016/09/22 13:08:20 ajacoutot Exp $ # # Copyright (c) 2008-2014 Antoine Jacoutot <ajacoutot@openbsd.org> # Copyright (c) 1998-2003 Douglas Barton <DougB@FreeBSD.org> @@ -343,7 +343,7 @@ sm_install() { } sm_add_user_grp() { - local _g _p _gid _l _u _rest + local _g _p _gid _u _rest local _gr=./etc/group local _pw=./etc/master.passwd @@ -351,17 +351,22 @@ sm_add_user_grp() { while IFS=: read -r -- _g _p _gid _rest; do if ! grep -Eq "^${_g}:" /etc/group; then + getent group ${_gid} >/dev/null && \ + sm_warn "Not adding group ${_g}, GID ${_gid} already exists" && \ + continue echo "===> Adding the ${_g} group" groupadd -g ${_gid} ${_g} fi done <${_gr} - while read _l; do - _u=${_l%%:*} + while IFS=: read -r -- _u _p _uid _rest; do if [[ ${_u} != root ]]; then if ! grep -Eq "^${_u}:" /etc/master.passwd; then + getent passwd ${_uid} >/dev/null && \ + sm_warn "Not adding user ${_u}, UID ${_uid} already exists" && \ + continue echo "===> Adding the ${_u} user" - chpass -a "${_l}" + chpass -a "${_u}:${_p}:${_uid}:${_rest}" fi fi done <${_pw} |