[type/__uci_section] Add more parameter checks
This commit is contained in:
parent
0840afce03
commit
49e867fab4
1 changed files with 31 additions and 11 deletions
|
@ -19,11 +19,15 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
grep_line() { echo "$2" | grep -qxF "$1"; }
|
grep_line() { echo "$2" | grep -qxF "$1"; }
|
||||||
|
uci_validate_name() {
|
||||||
|
# like util.c uci_validate_name()
|
||||||
|
test -n "$*" && test -z "$(printf %s "$*" | tr -d '[:alnum:]_' | tr -c '' .)"
|
||||||
|
}
|
||||||
|
validate_options() { grep -shv -e '^[[:alnum:]_]\{1,\}=' "$@"; }
|
||||||
unquote_lines() {
|
unquote_lines() {
|
||||||
sed -e '/^".*"$/{s/^"//;s/"$//}' \
|
sed -e '/^".*"$/{s/^"//;s/"$//}' \
|
||||||
-e '/'"^'.*'"'$/{s/'"^'"'//;s/'"'$"'//}'
|
-e '/'"^'.*'"'$/{s/'"^'"'//;s/'"'$"'//}'
|
||||||
}
|
}
|
||||||
|
|
||||||
append_values() {
|
append_values() {
|
||||||
while read -r _value
|
while read -r _value
|
||||||
do
|
do
|
||||||
|
@ -32,11 +36,22 @@ append_values() {
|
||||||
unset _value
|
unset _value
|
||||||
"$@" </dev/null
|
"$@" </dev/null
|
||||||
}
|
}
|
||||||
|
print_errors() {
|
||||||
uci_validate_name() {
|
awk -v prefix="${1:-Found errors:}" -v suffix="${2-}" '
|
||||||
# like util.c uci_validate_name()
|
BEGIN {
|
||||||
test -n "$*" && test -z "$(echo "$*" | tr -d '[:alnum:]_')"
|
if (getline) {
|
||||||
|
print prefix
|
||||||
|
print
|
||||||
|
rc = 1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
END {
|
||||||
|
if (rc && suffix) print suffix
|
||||||
|
exit rc
|
||||||
|
}' >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
## Check section name and error if invalid!
|
## Check section name and error if invalid!
|
||||||
case ${__object_id:?}
|
case ${__object_id:?}
|
||||||
|
@ -74,12 +89,6 @@ in
|
||||||
type_is=$(cat "${__object:?}/explorer/type")
|
type_is=$(cat "${__object:?}/explorer/type")
|
||||||
type_should=$(cat "${__object:?}/parameter/type")
|
type_should=$(cat "${__object:?}/parameter/type")
|
||||||
|
|
||||||
if test -f "${__object:?}/parameter/option"
|
|
||||||
then
|
|
||||||
optnames_should=$(
|
|
||||||
sed -e 's/=.*$//' "${__object:?}/parameter/option" | sort -u)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -n "${type_is}"
|
if test -n "${type_is}"
|
||||||
then
|
then
|
||||||
if test "${type_is}" != "${type_should##*.}"
|
if test "${type_is}" != "${type_should##*.}"
|
||||||
|
@ -105,6 +114,17 @@ in
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check options for syntax errors
|
||||||
|
validate_options "${__object:?}/parameter/object" \
|
||||||
|
| print_errors 'Found erroneous options in arguments:'
|
||||||
|
|
||||||
|
# Collect option names
|
||||||
|
if test -f "${__object:?}/parameter/option"
|
||||||
|
then
|
||||||
|
optnames_should=$(
|
||||||
|
sed -e 's/=.*$//' "${__object:?}/parameter/option" | sort -u)
|
||||||
|
fi
|
||||||
|
|
||||||
# Make sure the section itself is present
|
# Make sure the section itself is present
|
||||||
__uci "${section}" --state present --transaction "${transaction_name}" \
|
__uci "${section}" --state present --transaction "${transaction_name}" \
|
||||||
--value "${sect_type}"
|
--value "${sect_type}"
|
||||||
|
|
Loading…
Reference in a new issue