summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-07-08 22:40:25 -0400
committerAllan McRae <allan@archlinux.org>2011-07-19 10:27:54 +1000
commitdf7b390514efa0ae6b84e8404806dee63d3524ad (patch)
treefd5492f555226623cdd901892571668c73788d76
parent0e85c4989b7a7a20978ba0dcc7b56f0f1853b974 (diff)
downloadpacman-df7b390514efa0ae6b84e8404806dee63d3524ad.tar.xz
pacman-key: refactor get_from
This function had a variety of pitfalls, including the inability to successfully find a key=value pair where no whitespace surrounded the equals sign. Make it more robust by splitting the line on the equals itself, and performing whitespace trimming on the resulting key/value pair. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--scripts/pacman-key.sh.in18
1 files changed, 10 insertions, 8 deletions
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
index 937dcad5..0ce0ea24 100644
--- a/scripts/pacman-key.sh.in
+++ b/scripts/pacman-key.sh.in
@@ -76,17 +76,19 @@ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")"
}
-# Read provided file and search for values matching the given key
-# The contents of the file are expected to be in this format: key = value
-# 'key', 'equal sign' and 'value' can be surrounded by random whitespace
-# Usage: get_from "$file" "$key" # returns the value for the first matching key in the file
+# read the config file "$1" which has key=value pairs, and return the key which
+# matches "$2". the equals sign between pairs may be surrounded by any amount
+# of whitespace.
get_from() {
- while read key _ value; do
- if [[ $key = $2 ]]; then
- echo "$value"
- break
+ while IFS='=' read -r key value; do
+ [[ -z $key || ${key:0:1} = '#' ]] && continue
+
+ if [[ ${key%% *} = "$2" && -n ${value##* } ]]; then
+ echo "${value##* }"
+ return 0
fi
done < "$1"
+ return 1
}
verify_keyring_input() {