diff options
| author | Simon Rettberg | 2013-02-22 19:29:50 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2013-02-22 19:29:50 +0100 |
| commit | 6d4a6b5304ec40a31d60277d7299596125148d0e (patch) | |
| tree | ef3293e51c401655f56a019c6b1e70b98d4bb9fd | |
| parent | Check if passwd/group/shadow exists when trying to add a user (diff) | |
| download | tm-scripts-6d4a6b5304ec40a31d60277d7299596125148d0e.tar.gz tm-scripts-6d4a6b5304ec40a31d60277d7299596125148d0e.tar.xz tm-scripts-6d4a6b5304ec40a31d60277d7299596125148d0e.zip | |
[helper] Fix password replacement sed expression in add_user, fix return value checking in tarcopy
| -rw-r--r-- | helper/fileutil.inc | 9 | ||||
| -rw-r--r-- | helper/useradd.inc | 10 |
2 files changed, 10 insertions, 9 deletions
diff --git a/helper/fileutil.inc b/helper/fileutil.inc index 40bc42d5..3c165d99 100644 --- a/helper/fileutil.inc +++ b/helper/fileutil.inc @@ -6,12 +6,11 @@ tarcopy () { return fi local SHORT=$1 - [ ${#SHORT} -gt 18 ] && SHORT=$(echo "$SHORT" | cut -c-13)...$(echo "$SHORT" | cut -c${#SHORT}-) + [ ${#SHORT} -gt 23 ] && SHORT=$(echo "$SHORT" | cut -c-18)...$(echo "$SHORT" | cut -c$[${#SHORT} - 4]-) [ -z $2 ] && perror "tarcopy called with empty destination." tar -cp "$1" | tar -xp -C "$2" - local PS1=$PIPESTATUS[0] - local PS2=$PIPESTATUS[1] - [ $PS1 -ne 0 ] && perror "packing-part of tar-copy from '$SHORT' to '$2' failed." - [ $PS2 -ne 0 ] && perror "unpacking-part of tar-copy from '$SHORT' to '$2' failed." + local PS=(${PIPESTATUS[*]}) + [ "x${PS[0]}" != "x0" ] && perror "packing-part of tar-copy from '$SHORT' to '$2' failed. (${PS[0]})" + [ "x${PS[1]}" != "x0" ] && perror "unpacking-part of tar-copy from '$SHORT' to '$2' failed. (${PS[1]})" } diff --git a/helper/useradd.inc b/helper/useradd.inc index bc139021..c9ab6b38 100644 --- a/helper/useradd.inc +++ b/helper/useradd.inc @@ -130,9 +130,11 @@ add_user() { then local PASSWORD='*' else - PASSWORD=$(sha1pass "${PASSWORD}") - [ -z "${PASSWORD}" ] && PASSWORD=$(openssl passwd -1 "${PASSWORD}") - [ -z "${PASSWORD}" ] && perror "Error generating hashed password for $USER" + pdebug "Hashing password '$PASSWORD' for '$USER'" + local PW=$(sha1pass "${PASSWORD}") + [ -z "${PW}" ] && PASSWORD=$(openssl passwd -1 "${PASSWORD}") + [ -z "${PW}" ] && perror "Error generating hashed password for $USER" + PASSWORD=$PW fi # add user, or replace password if [ -z "${_UID}" ]; then @@ -142,7 +144,7 @@ add_user() { pinfo "Created user $USER" elif [ "$PASSWORD" != "*" ]; then # update user's password - sed -i -r "s/^${USER}:[^:]*:(.*)\$/${USER}:${PASSWORD}:\1/g" "${_SHADOW}" + sed -i -r 's/^'"${USER}"':[^:]*:(.*)$/'"${USER}"':'"${PASSWORD}"':\1/g' "${_SHADOW}" pinfo "Updated password of $USER" fi [ -z "${_GID}" ] && pinfo "Created group $GROUP" && echo "${GROUP}:x:${GROUPID}:" >> "${_GROUP}" |
