From 4d845b3feaf14f413e768256d20983491d9567f9 Mon Sep 17 00:00:00 2001 From: Matt Coddington Date: Tue, 7 Feb 2012 10:27:28 -0500 Subject: [PATCH 1/2] fix for changing a user's group by name --- conf/type/__user/gencode-remote | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/conf/type/__user/gencode-remote b/conf/type/__user/gencode-remote index 595c7f64..077562f4 100755 --- a/conf/type/__user/gencode-remote +++ b/conf/type/__user/gencode-remote @@ -28,6 +28,7 @@ cd "$__object/parameter" if grep -q "^${name}:" "$__object/explorer/passwd"; then for property in $(ls .); do new_value="$(cat "$property")" + unset current_value file="$__object/explorer/passwd" @@ -36,9 +37,15 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then field=4 else - # group name - file="$__object/explorer/group" - field=1 + # we were passed a group name. compare to current gid and + # set $current_value to $oldgid if it needs changing. + newgid=$(awk -F: '{ print $3 }' "$__object/explorer/group") + oldgid=$(awk -F: '{ print $4 }' "$file") + if [ "$newgid" != "$oldgid" ]; then + current_value="$oldgid" + else + current_value=$new_value + fi fi ;; password) @@ -51,8 +58,10 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then uid) field=3 ;; esac - export field - current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")" + if [ -z "$current_value" ]; then + export field + current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")" + fi if [ "$new_value" != "$current_value" ]; then set -- "$@" "--$property" \'$new_value\' From 908e74689c19c08534cc946949051a4ca11081e0 Mon Sep 17 00:00:00 2001 From: Matt Coddington Date: Tue, 7 Feb 2012 12:38:21 -0500 Subject: [PATCH 2/2] improve comments and use better variable names --- conf/type/__user/gencode-remote | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/conf/type/__user/gencode-remote b/conf/type/__user/gencode-remote index 077562f4..8979c56e 100755 --- a/conf/type/__user/gencode-remote +++ b/conf/type/__user/gencode-remote @@ -37,14 +37,15 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then field=4 else - # we were passed a group name. compare to current gid and - # set $current_value to $oldgid if it needs changing. - newgid=$(awk -F: '{ print $3 }' "$__object/explorer/group") - oldgid=$(awk -F: '{ print $4 }' "$file") - if [ "$newgid" != "$oldgid" ]; then - current_value="$oldgid" + # We were passed a group name. Compare the gid in + # the user's /etc/passwd entry with the gid of the + # group returned by the group explorer. + gid_from_group=$(awk -F: '{ print $3 }' "$__object/explorer/group") + gid_from_passwd=$(awk -F: '{ print $4 }' "$file") + if [ "$gid_from_group" != "$gid_from_passwd" ]; then + current_value="$gid_from_passwd" else - current_value=$new_value + current_value="$new_value" fi fi ;; @@ -58,6 +59,8 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then uid) field=3 ;; esac + # If we haven't already set $current_value above, pull it from the + # appropriate file/field. if [ -z "$current_value" ]; then export field current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")"