diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2007-08-19 11:19:58 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2007-08-19 11:19:58 +0000 |
commit | 02b288faf5f17c0b817578fd690ed2f9467b5bee (patch) | |
tree | 7c37a039897a7af10cf9139acdcf1a2b5f9c8fca | |
parent | 5593d70ef5b2a214d7b913ca70f4a0003e40327f (diff) |
fix some bugs in mangling of configfile and be more cautious about replacing values (only replace first occurrence and only match options with the correct number of options)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@353 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | debian/libnss-ldapd.config | 12 | ||||
-rw-r--r-- | debian/libnss-ldapd.postinst | 34 |
2 files changed, 14 insertions, 32 deletions
diff --git a/debian/libnss-ldapd.config b/debian/libnss-ldapd.config index e8e6dc5..aec5654 100644 --- a/debian/libnss-ldapd.config +++ b/debian/libnss-ldapd.config @@ -74,20 +74,20 @@ parsecfg() fi [ -n "$uris" ] && db_set libnss-ldapd/ldap-uris "$uris" # find base config - searchbase=`sed -n 's/^base[[:space:]]*//ip' "$cfgfile"` + searchbase=`sed -n 's/^base[[:space:]]*\([^[:space:]]*\)[[:space:]]*$/\1/ip' "$cfgfile"` [ -n "$searchbase" ] && db_set libnss-ldapd/ldap-base "$searchbase" # find binddb binddn=`sed -n 's/^binddn[[:space:]]*//ip' "$cfgfile"` - [ -n "$binddn" ] && db_set libnss-ldapd/ldap-binddn "$binddn" + db_set libnss-ldapd/ldap-binddn "$binddn" # find bindpw bindpw=`sed -n 's/^bindpw[[:space:]]*//ip' "$cfgfile"` - [ -n "$bindpw" ] && db_set libnss-ldapd/ldap-bindpw "$bindpw" + db_set libnss-ldapd/ldap-bindpw "$bindpw" # find rootbinddb rootbinddn=`sed -n 's/^rootbinddn[[:space:]]*//ip' "$cfgfile"` - [ -n "$rootbinddn" ] && db_set libnss-ldapd/ldap-rootbinddn "$rootbinddn" + db_set libnss-ldapd/ldap-rootbinddn "$rootbinddn" # find rootbindpw rootbindpw=`sed -n 's/^rootbindpw[[:space:]]*//ip' "$cfgfile"` - [ -n "$rootbindpw" ] && db_set libnss-ldapd/ldap-rootbindpw "$rootbindpw" + db_set libnss-ldapd/ldap-rootbindpw "$rootbindpw" # we're done return 0 } @@ -96,7 +96,7 @@ parsecfg() parsensswitch() { # find name services that currently use LDAP - configured=`sed -n 's/^\([^[:space:]]*\):.*[[:space:]]ldap\([[:space:]].*\)\?/\1/p' /etc/nsswitch.conf` + configured=`sed -n 's/^\([a-z]*\):.*[[:space:]]ldap\([[:space:]].*\)\?/\1/p' /etc/nsswitch.conf` # separate by commas configured=`echo $configured | sed 's/ /, /g'` # store configured services diff --git a/debian/libnss-ldapd.postinst b/debian/libnss-ldapd.postinst index 0a255fa..c7586cd 100644 --- a/debian/libnss-ldapd.postinst +++ b/debian/libnss-ldapd.postinst @@ -9,35 +9,21 @@ cfg_set() { parameter=$1 value=$2 - commented=0 - notthere=0 # check if the parameter is defined - grep -i -q "^$parameter " $CONFFILE || notthere=1 - if [ "$notthere" = "1" ] + replace=`sed -n 's/^\('"$parameter"'\)[[:space:]]*[^[:space:]]*[[:space:]]*$/\1/ip' "$CONFFILE" | head -n 1` + if [ -z "$replace" ] then # check if the parameter is commented out - if grep -i -q "^#$parameter" $CONFFILE - then - notthere=0 - commented=1 - fi + replace=`sed -n 's/^\(#[[:space:]]*'"$parameter"'\)[[:space:]]*[^[:space:]]*[[:space:]]*$/\1/ip' "$CONFFILE" | head -n 1` fi # decide what to do - if [ "$notthere" = "1" ] + if [ -z "$replace" ] then # just append a new line echo "$parameter $value" >> $CONFFILE else - # TODO: check if the option is already defined with the value we need - # replace the existing option - replacestring="$parameter" - if [ "$commented" = "1" ] - then - replacestring="# *$parameter" - fi - # this works as long as any option is specified only once - # FIXME: also work when option is commented out on multiple lines - sed -i 's%^'"$replacestring"' .*$%'"$parameter $value"'%i' "$CONFFILE" + # replace the first occurrence of the parameter + sed -i '1,\%^'"$replace"' .*$% s%^'"$replace"' .*$%'"$parameter $value"'%i' "$CONFFILE" fi # we're done return 0 @@ -47,12 +33,8 @@ cfg_set() cfg_disable() { parameter=$1 - # TODO add an option to also remove the option value - # (for passwords) - if grep -i -q "^$parameter " $CONFFILE - then - sed -i 's%^\('"$parameter"'.*\)$%#\1%i' "$CONFFILE" - fi + # comment out the option + sed -i 's/^\('"$parameter"'[[:space:]]*[^[:space:]]*\)[[:space:]]*$/#\1/i' "$CONFFILE" # we're done return 0 } |