examples: replace grep command in NM dispatcher script
Some grep implementations detect binary data and return success without matching whole line. This might be an issue for the DHCPv6 NTP FQDN check. The GNU grep in the C locale seems to check only for the NUL character, which cannot be passed in an environment variable, but other implementations might behave differently and there doesn't seem to be a portable way to force matching the whole line. Instead of the grep command, check for invalid characters by comparing the length of the input passed through "tr -d -c".
This commit is contained in:
parent
25f80a1a9d
commit
fca8966ada
1 changed files with 5 additions and 1 deletions
|
@ -19,7 +19,11 @@ add_servers_from_dhcp() {
|
||||||
rm -f "$dhcp_server_file"
|
rm -f "$dhcp_server_file"
|
||||||
for server in $dhcp_ntp_servers; do
|
for server in $dhcp_ntp_servers; do
|
||||||
# Check for invalid characters (from the DHCPv6 NTP FQDN suboption)
|
# Check for invalid characters (from the DHCPv6 NTP FQDN suboption)
|
||||||
printf '%s\n' "$server" | grep -E -q '^[-A-Za-z0-9:.]{1,255}$' || continue
|
len1=$(printf '%s' "$server" | wc -c)
|
||||||
|
len2=$(printf '%s' "$server" | tr -d -c 'A-Za-z0-9:.-' | wc -c)
|
||||||
|
if [ "$len1" -ne "$len2" ] || [ "$len2" -lt 1 ] || [ "$len2" -gt 255 ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
printf 'server %s %s\n' "$server" "$server_options" >> "$dhcp_server_file"
|
printf 'server %s %s\n' "$server" "$server_options" >> "$dhcp_server_file"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue