Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2008-04-05 23:16:13 +0200
committerArthur de Jong <arthur@arthurdejong.org>2008-04-05 23:16:13 +0200
commit553563e5012125dfb779e054bcc180ab2e0c0db4 (patch)
treed56fb6356afaf61039a44e601f45e25ceab1394d
parentf3fa4d975da8238553e900bfd724698057e99600 (diff)
handle case where value contains spaces properly
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@667 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--debian/libnss-ldapd.postinst33
1 files changed, 20 insertions, 13 deletions
diff --git a/debian/libnss-ldapd.postinst b/debian/libnss-ldapd.postinst
index d99b8a6..5ee151b 100644
--- a/debian/libnss-ldapd.postinst
+++ b/debian/libnss-ldapd.postinst
@@ -11,25 +11,30 @@ cfg_set()
value="$2"
# make matching of spaces better in parameter
# this is complicated becase of the "base [map] dn" keyword
- param_re=`echo "$parameter" | sed -s 's#[[:space:]][[:space:]]*#[[:space:]][[:space:]]*#g'`
+ param_re=`echo "$parameter" | sed 's#^#[[:space:]]*#;s#[[:space:]][[:space:]]*#[[:space:]][[:space:]]*#g'`
+ # lines to not match
+ nomatch_re="^$param_re[[:space:]][[:space:]]*\(aliases\|ethers\|group\|hosts\|netgroup\|networks\|passwd\|protocols\|rpc\|services\|shadow\)"
# check if the parameter is defined
- replace=`sed -n 's/^\('"$param_re"'\)[[:space:]]*\([^[:space:]]*\|".*"\)[[:space:]]*$/\1/ip' "$CONFFILE" | head -n 1`
- if [ -z "$replace" ]
+ line=`sed -n '/'"$nomatch_re"'/n;/^'"$param_re"'[[:space:]]/p' "$CONFFILE" | head -n 1`
+ if [ -z "$line" ]
then
# check if the parameter is commented out
- replace=`sed -n 's/^\(#[[:space:]]*'"$param_re"'\)[[:space:]]*\([^[:space:]]*\|".*"\)[[:space:]]*$/\1/ip' "$CONFFILE" | head -n 1`
+ param_re="#$param_re"
+ nomatch_re="^$param_re[[:space:]][[:space:]]*\(aliases\|ethers\|group\|hosts\|netgroup\|networks\|passwd\|protocols\|rpc\|services\|shadow\)"
+ line=`sed -n '/'"$nomatch_re"'/n;/^'"$param_re"'[[:space:]]/p' "$CONFFILE" | head -n 1`
fi
# decide what to do
- if [ -z "$replace" ]
+ if [ -z "$line" ]
then
# just append a new line
echo "$parameter $value" >> $CONFFILE
else
- # ($replace will not have have any funky characters, neither will $parameter)
- # escape value
- value=`echo "$value" | sed -s 's#\\\#\\\\\\\#g;s#|#\\\|#g;s#&#\\\&#g'`
- # replace the first occurrence of the parameter
- sed -i '1,\|^'"$replace"' .*$| s|^\('"$replace"'\) .*$|\1 '"$value"'|i' "$CONFFILE"
+ # escape line to replace
+ replace=`echo "$line" | sed 's#\\\#\\\\\\\#g;s#\([.*+?^$|]\)#\\\\\1#g'`
+ # escape value (parameter doesn't have any special stuff)
+ value=`echo "$value" | sed 's#\\\#\\\\\\\#g;s#|#\\\|#g;s#&#\\\&#g'`
+ # replace the first occurrence of the line
+ sed -i '1,\|^'"$replace"'$| s|^'"$replace"'$|'"$parameter"' '"$value"'|i' "$CONFFILE"
fi
# we're done
return 0
@@ -40,9 +45,11 @@ cfg_disable()
{
parameter="$1"
# make matching of spaces better in parameter
- param_re=`echo "$parameter" | sed -s 's#[[:space:]][[:space:]]*#[[:space:]][[:space:]]*#g'`
+ param_re=`echo "$parameter" | sed 's#^#[[:space:]]*#;s#[[:space:]][[:space:]]*#[[:space:]][[:space:]]*#g'`
+ # lines to not match
+ nomatch_re="^$param_re[[:space:]][[:space:]]*\(aliases\|ethers\|group\|hosts\|netgroup\|networks\|passwd\|protocols\|rpc\|services\|shadow\)"
# comment out the option
- sed -i 's/^\('"$param_re"'[[:space:]]*[^[:space:]]*\)[[:space:]]*$/#\1/i' "$CONFFILE"
+ sed -i '/'"$nomatch_re"'/n;s/^'"$param_re"'[[:space:]].*$/#&/i' "$CONFFILE"
# we're done
return 0
}
@@ -59,7 +66,7 @@ cfg_uris()
if grep -qi '^_uri_ ' $CONFFILE
then
# escape uri for use in regexp replacement
- uri=`echo "$uri" | sed -s 's#\\\#\\\\\\\#g;s#|#\\\|#g;s#&#\\\&#g'`
+ uri=`echo "$uri" | sed 's#\\\#\\\\\\\#g;s#|#\\\|#g;s#&#\\\&#g'`
# replace the first occurrence of _uri_
sed -i '1,/^_uri_ / s|^_uri_ .*$|uri '"$uri"'|i' "$CONFFILE"
else