@@ -1881,192 +1881,9 @@ HOME=${HOME_BASEDIR}" ${ETC_DEFAULT_USERADD}
1881
1881
if [ -f ${USERADD} /${u} /Template ] ; then
1882
1882
continue
1883
1883
fi
1884
- cd ${USERADD} /${u} || ErrExit ${EX_OSERR} " cd ${USERADD} /${u} "
1885
- local uid=" "
1886
- local gid=" "
1887
- local shell_arg=" "
1888
- local shell
1889
- local shellpath
1890
- local groups
1891
- local group_arg
1892
- local dir_arg
1893
- local exists
1894
- local multiple=" "
1895
- local numeric=" ^[0-9]+$"
1896
-
1897
- if [ -d multiple ] ; then
1898
- multiple=$( echo $( ls multiple) )
1899
- fi
1900
- if [ -z " ${multiple} " ] ; then
1901
- multiple=1
1902
- fi
1903
- if ! [[ ${multiple} =~ ${numeric} ]] ; then
1904
- ErrExit ${EX_CONFIG} " user: ${multiple} , non-numeric"
1905
- fi
1906
-
1907
- if [ ! -d uid ] ; then
1908
- ErrExit ${EX_CONFIG} " user: ${u} , no uid"
1909
- fi
1910
- uid=$( echo $( ls uid) )
1911
- if [ ! -d gid ] ; then
1912
- ErrExit ${EX_CONFIG} " user: ${u} , no gid"
1913
- fi
1914
- gid=$( echo $( ls gid) )
1915
-
1916
- for m in $( echo $( seq 1 ${multiple} ) )
1917
- do
1918
- local U=${u}
1919
- local _uid
1920
- local _gid
1921
- local msg=" "
1922
-
1923
- _uid=$( expr ${uid} + ${m} - 1)
1924
- _gid=$( expr ${gid} + ${m} - 1)
1925
-
1926
- if [ " ${multiple} " -eq 1 ] ; then
1927
- U=${u}
1928
- else
1929
- U=" ${u}${m} "
1930
- fi
1931
- msg=" ${msg} ${U} : "
1932
-
1933
- if [ -d shell ] ; then
1934
- shell=$( ls shell)
1935
- shellpath=$( which $shell 2>&1 )
1936
- if [ -x " ${shellpath} " ] ; then
1937
- shell_arg=" -s ${shellpath} "
1938
- else
1939
- Verbose " Warning: ${shellpath} -- not executable"
1940
- fi
1941
- fi
1942
-
1943
- group_arg=" "
1944
- if [ -d groups ] ; then
1945
- local ls_groups=$( echo $( ls groups) )
1946
- groups=$( echo ${ls_groups} | sed ' s/ /,/g' )
1947
-
1948
- if [ -n " ${groups} " ] ; then
1949
- group_arg=" -G ${groups} "
1950
- msg=" ${msg} groups:${groups} "
1951
- fi
1952
- fi
1953
-
1954
- dir_arg=" "
1955
- dir=" "
1956
- if [ -d ${HOME_BASEDIR} -o -d ${HOME_BASEDIR} /${U} ] ; then
1957
- if [ -d ${HOME_BASEDIR} /${U} ] ; then
1958
- dir_arg=" -d ${HOME_BASEDIR} /${U} "
1959
- dir=${HOME_BASEDIR} /${U}
1960
- elif [ -d ${HOME_BASEDIR} ] ; then
1961
- dir_arg=" -b ${HOME_BASEDIR} "
1962
- dir=${HOME_BASEDIR} /${U}
1963
- fi
1964
- fi
1965
-
1966
- exists=$( echo $( getent passwd ${U} 2>&1 ) )
1967
- if [ -z " ${exists} " ] ; then
1968
- gid_explicit=" "
1969
- if (( ${uid} != ${gid} )) ; then
1970
- group_arg=" -G ${_gid} "
1971
- else
1972
- gid_explicit=" -U"
1973
- fi
1974
- Rc ErrExit ${EX_OSERR} " useradd -u ${_uid} ${gid_explicit} -o ${shell_arg} ${group_arg} ${dir_arg} ${U} "
1975
- else
1976
- if [ -n " ${shell_arg} " ] ; then
1977
- Rc ErrExit ${EX_OSERR} " chsh ${shell_arg} ${U} "
1978
- fi
1979
- if [ -n " ${group_arg} " ] ; then
1980
- Rc ErrExit ${EX_OSERR} " usermod ${group_arg} ${U} "
1981
- fi
1982
- if [[ ${dir_arg} =~ -d ]] ; then
1983
- Rc ErrExit ${EX_OSERR} " usermod ${dir_arg} ${U} "
1984
- fi
1985
- fi
1986
-
1987
- if [ -d " ${USERADD_PASSWD} " ] ; then
1988
- if [ ! -f " ${USERADD_PASSWD_CLEARTEXT} " -a ! -f " ${USERADD_PASSWD_ENCRYPTED} " ] ; then
1989
- msg=" ${msg} -passwd"
1990
- Rc ErrExit ${EX_OSERR} " passwd -d ${U} >/dev/null 2>&1"
1991
-
1992
- elif [ -f " ${USERADD_PASSWD_ENCRYPTED} " -a -s " ${USERADD_PASSWD_ENCRYPTED} " ] ; then
1993
- local pw=$( echo $( cat ${USERADD_PASSWD_ENCRYPTED} ) )
1994
- Rc ErrExit ${EX_OSERR} " echo \" ${U} :${pw} \" | chpasswd -e"
1995
-
1996
- elif [ -f " ${USERADD_PASSWD_CLEARTEXT} " -a -s " ${USERADD_PASSWD_CLEARTEXT} " ] ; then
1997
- local pw=$( echo $( cat ${USERADD_PASSWD_CLEARTEXT} ) )
1998
- Verbose " Note: setting cleartext passwd for user:${U} (Ensure PermitEmptyPasswords is allowed in sshd_config.)"
1999
- Rc ErrExit ${EX_OSERR} " echo \" ${U} :${pw} \" | chpasswd "
2000
-
2001
- else
2002
- ErrExit ${EX_CONFIG} " broken password config: ${USERADD} /${U} /${USERADD_PASSWD} "
2003
- fi
2004
- fi
2005
-
2006
- if [ -d ${USERADD} /${u} /secontext ] ; then
2007
- local u_secontext=$( echo $( ls ${USERADD} /${u} /secontext) )
2008
- if [ -n " ${u_secontext} " ] ; then
2009
- if [ -d ${dir} ] ; then
2010
- local fstyp=$( stat -f --format=" %T" .)
2011
- case " ${fstyp} " in
2012
- xfs|ext* |jfs|ffs|ufs|zfs)
2013
- Rc ErrExit ${EX_OSERR} " chcon -R ${u_secontext} ${dir} "
2014
- local u_setype=$( echo " ${u_secontext} " | sed ' s/:/ /g' | awk ' {print $3}' )
2015
- if [ -z " ${u_setype} " ] ; then
2016
- ErrExit ${EX_CONFIG} " ${u} :empty u_setype, u_secontext:${u_secontext} "
2017
- fi
2018
- Rc ErrExit ${EX_OSERR} " semanage fcontext -a -t ${u_setype} ${dir} /\(/.*\)\? ;"
2019
- ;;
2020
- nfs)
2021
- # silently skip
2022
- ;;
2023
- * )
2024
- Verbose " unable to set secontext:${u_secontext} "
2025
- Verbose " on dir: ${dir} , which has a file system type,"
2026
- Verbose " fstype:${fstyp} which does not implement secontext extended attributes."
2027
- ;;
2028
- esac
2029
- fi
2030
- fi
2031
- fi
2032
-
2033
- if [ -d ${dir} ] ; then
2034
- if [ ! -L /home/${U} ] ; then
2035
- Rc ErrExit ${EX_OSFILE} " ln -f -s ${dir} /home/${U} "
2036
- fi
2037
- Rc ErrExit ${EX_OSFILE} " chown -h ${U} /home/${U} >/dev/null 2>&1"
2038
- Rc ErrExit ${EX_OSFILE} " chown -R ${U} ${dir} >/dev/null 2>&1"
2039
- fi
2040
-
2041
- if [ ! -d " ${ETC_SUDOERS_D} " ] ; then
2042
- ErrExit ${EX_OSFILE} " ${ETC_SUDOERS_D} : not a directory or does not exist, ${u} "
2043
- fi
2044
- local u_sudoers_d=${USERADD} /${u} /${SUDOERS_D}
2045
- if [ -d " ${u_sudoers_d} " ] ; then
2046
- if [ -f " ${u_sudoers_d} /${u} " ] ; then
2047
- Rc ErrExit ${EX_OSFILE} " cp ${u_sudoers_d} /${u} ${ETC_SUDOERS_D} /${U} "
2048
- Rc ErrExit ${EX_OSFILE} " sed -i -e 's/${u} /${U} /' ${ETC_SUDOERS_D} /${U} ; "
2049
- msg=" ${msg} +sudo"
2050
- fi
2051
- fi
2052
- Verbose " ${msg} "
2053
- Verbose " "
2054
- msg=" "
2055
-
2056
- if [ -d " ${USERADD} /${U} " ] ; then
2057
- local _home=${HOME_BASEDIR} /${U}
2058
- local home_useradd=${_home} /useradd
2059
- local useradd_d=${USERADD} /${U}
2060
-
2061
- Rc ErrExit ${EX_OSFILE} " chown -R -h ${U} :${U} ${useradd_d} "
2062
- if [ -d " ${useradd_d} /useradd" ] ; then
2063
- Rc ErrExit ${EX_OSFILE} " ln -s ${useradd_d} ${home_useradd} "
2064
- Rc ErrExit ${EX_OSFILE} " chown -h ${U} :${U} ${home_useradd} "
2065
- fi
2066
- fi
2067
-
2068
- done
2069
- done
1884
+ # AddUserAccount() is in lib/useradd.sh
1885
+ AddUserAccount ${USERADD} /${u}
1886
+ done # u in ${users_add}
2070
1887
2071
1888
cd ${ORIGPWD} || ErrExit ${EX_OSERR} " cd ${ORIGPWD} "
2072
1889
return
0 commit comments