forked from ungleich-public/cdist
		
	[type/__uci] Check __object_id for syntax errors
This commit is contained in:
		
					parent
					
						
							
								f782a5a370
							
						
					
				
			
			
				commit
				
					
						3a6b085145
					
				
			
		
					 1 changed files with 45 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -48,8 +48,53 @@ uci_cmd() {
 | 
			
		|||
	printf ' >>%s\n' "$(quote "${tmpfile}")"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uci_validate_name() {
 | 
			
		||||
	# like util.c uci_validate_name()
 | 
			
		||||
	test -n "$*" && test -z "$(echo "$*" | tr -d '[:alnum:]_')"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uci_validate_tuple() (
 | 
			
		||||
	tok=${1:?}
 | 
			
		||||
	case $tok
 | 
			
		||||
	in
 | 
			
		||||
		(*.*.*)
 | 
			
		||||
			# check option
 | 
			
		||||
			option=${tok##*.}
 | 
			
		||||
			uci_validate_name "${option}" || {
 | 
			
		||||
				printf 'Invalid option: %s\n' "${option}" >&2
 | 
			
		||||
				return 1
 | 
			
		||||
			}
 | 
			
		||||
			tok=${tok%.*}
 | 
			
		||||
			;;
 | 
			
		||||
		(*.*)
 | 
			
		||||
			# no option (section definition)
 | 
			
		||||
			;;
 | 
			
		||||
		(*)
 | 
			
		||||
			printf 'Invalid tuple: %s\n' "$1" >&2
 | 
			
		||||
			return 1
 | 
			
		||||
			;;
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
	case ${tok#*.}
 | 
			
		||||
	in
 | 
			
		||||
		(@*) section=$(expr "${tok#*.}" : '@\(.*\)\[-*[0-9]*\]$') ;;
 | 
			
		||||
		(*)  section=${tok#*.} ;;
 | 
			
		||||
	esac
 | 
			
		||||
	uci_validate_name "${section}" || {
 | 
			
		||||
		printf 'Invalid section: %s\n' "${1#*.}" >&2
 | 
			
		||||
		return 1
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config=${tok%%.*}
 | 
			
		||||
	uci_validate_name "${config}" || {
 | 
			
		||||
		printf 'Invalid config: %s\n' "${config}" >&2
 | 
			
		||||
		return 1
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
config=${__object_id:?}
 | 
			
		||||
uci_validate_tuple "${config}"
 | 
			
		||||
 | 
			
		||||
state_is=$(cat "${__object:?}/explorer/state")
 | 
			
		||||
state_should=$(cat "${__object:?}/parameter/state")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue