dnsmasq: quoted path variables

Prevents problems when variables contain spaces.

Tested on: 23.05.3

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/14975
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Paul Donald 2024-04-01 20:18:14 +02:00 committed by Hauke Mehrtens
parent bd81d97e19
commit 47ce5f7dd5

View File

@ -69,7 +69,7 @@ xappend() {
local opt="${value%%=*}" local opt="${value%%=*}"
if ! dnsmasq_ignore_opt "$opt"; then if ! dnsmasq_ignore_opt "$opt"; then
echo "$value" >>$CONFIGFILE_TMP echo "$value" >>"$CONFIGFILE_TMP"
fi fi
} }
@ -354,7 +354,7 @@ dhcp_host_add() {
config_get_bool dns "$cfg" dns 0 config_get_bool dns "$cfg" dns 0
[ "$dns" = "1" ] && [ -n "$ip" ] && [ -n "$name" ] && { [ "$dns" = "1" ] && [ -n "$ip" ] && [ -n "$name" ] && {
echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE_TMP echo "$ip $name${DOMAIN:+.$DOMAIN}" >> "$HOSTFILE_TMP"
} }
config_get mac "$cfg" mac config_get mac "$cfg" mac
@ -714,7 +714,7 @@ dhcp_domain_add() {
record="${record:+$record }$name" record="${record:+$record }$name"
done done
echo "$ip $record" >> $HOSTFILE_TMP echo "$ip $record" >> "$HOSTFILE_TMP"
} }
dhcp_srv_add() { dhcp_srv_add() {
@ -882,13 +882,13 @@ dnsmasq_start()
# before we can call xappend # before we can call xappend
umask u=rwx,g=rx,o=rx umask u=rwx,g=rx,o=rx
mkdir -p /var/run/dnsmasq/ mkdir -p /var/run/dnsmasq/
mkdir -p $(dirname $CONFIGFILE) mkdir -p "$(dirname "$CONFIGFILE")"
mkdir -p "$HOSTFILE_DIR" mkdir -p "$HOSTFILE_DIR"
mkdir -p /var/lib/misc mkdir -p /var/lib/misc
chown dnsmasq:dnsmasq /var/run/dnsmasq chown dnsmasq:dnsmasq /var/run/dnsmasq
echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE_TMP echo "# auto-generated config file from /etc/config/dhcp" > "$CONFIGFILE_TMP"
echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE_TMP echo "# auto-generated config file from /etc/config/dhcp" > "$HOSTFILE_TMP"
local dnsmasqconffile="/etc/dnsmasq.${cfg}.conf" local dnsmasqconffile="/etc/dnsmasq.${cfg}.conf"
if [ ! -r "$dnsmasqconffile" ]; then if [ ! -r "$dnsmasqconffile" ]; then
@ -1129,7 +1129,7 @@ dnsmasq_start()
[ ! -d "$dnsmasqconfdir" ] && mkdir -p "$dnsmasqconfdir" [ ! -d "$dnsmasqconfdir" ] && mkdir -p "$dnsmasqconfdir"
xappend "--user=dnsmasq" xappend "--user=dnsmasq"
xappend "--group=dnsmasq" xappend "--group=dnsmasq"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
# EXTRACONFFILE allows new dnsmasq parameters before they are natively handled in this init file # EXTRACONFFILE allows new dnsmasq parameters before they are natively handled in this init file
config_get extraconftext "$cfg" extraconftext config_get extraconftext "$cfg" extraconftext
@ -1142,7 +1142,7 @@ dnsmasq_start()
} }
config_foreach filter_dnsmasq host dhcp_host_add "$cfg" config_foreach filter_dnsmasq host dhcp_host_add "$cfg"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
config_get_bool dhcpbogushostname "$cfg" dhcpbogushostname 1 config_get_bool dhcpbogushostname "$cfg" dhcpbogushostname 1
[ "$dhcpbogushostname" -gt 0 ] && { [ "$dhcpbogushostname" -gt 0 ] && {
@ -1163,10 +1163,10 @@ dnsmasq_start()
config_foreach filter_dnsmasq hostrecord dhcp_hostrecord_add "$cfg" config_foreach filter_dnsmasq hostrecord dhcp_hostrecord_add "$cfg"
[ -n "$BOOT" ] || config_foreach filter_dnsmasq relay dhcp_relay_add "$cfg" [ -n "$BOOT" ] || config_foreach filter_dnsmasq relay dhcp_relay_add "$cfg"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
config_foreach filter_dnsmasq srvhost dhcp_srv_add "$cfg" config_foreach filter_dnsmasq srvhost dhcp_srv_add "$cfg"
config_foreach filter_dnsmasq mxhost dhcp_mx_add "$cfg" config_foreach filter_dnsmasq mxhost dhcp_mx_add "$cfg"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
config_get_bool boguspriv "$cfg" boguspriv 1 config_get_bool boguspriv "$cfg" boguspriv 1
[ "$boguspriv" -gt 0 ] && { [ "$boguspriv" -gt 0 ] && {
@ -1188,16 +1188,16 @@ dnsmasq_start()
fi fi
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg" config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg" config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
echo >> $CONFIGFILE_TMP echo >> "$CONFIGFILE_TMP"
mv -f $CONFIGFILE_TMP $CONFIGFILE mv -f "$CONFIGFILE_TMP" "$CONFIGFILE"
mv -f $HOSTFILE_TMP $HOSTFILE mv -f "$HOSTFILE_TMP" "$HOSTFILE"
[ "$localuse" -gt 0 ] && { [ "$localuse" -gt 0 ] && {
rm -f /tmp/resolv.conf rm -f /tmp/resolv.conf