From f927fd97dbfeb689c23e04fe868225c4cd2d1869 Mon Sep 17 00:00:00 2001 From: kn Date: Tue, 20 Jul 2021 11:20:09 +0000 Subject: [PATCH] Simplify DHCP lease file parer after switch to dhcpleased dhcpleased(8)'s lease files are much simpler than dhclient.leases(5): - exactly one lease per file (not many) - only option lines (not statement, declaration, etc.) - every option/value is separated by a single ": " (no optional leading "option ") - values are not quoted or escaped (like dhclient does) lease_value() is hard to read, mostly because it strips optional double quotes around option values as was required with dhclient. dhclient VIS_ALL's values if they contain backticks, backslashes and other characters, otherwise it VIS_SAFE's (and optionally quotes them). dhcpleased VIS_SAFE's all value strings equally. All install.sub users of lease_value() quote its output so they should be safe without any special unescaping as previously done. OK florian --- distrib/miniroot/install.sub | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 999c0b095aa..fb95222fef5 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sub,v 1.1168 2021/07/18 15:18:49 deraadt Exp $ +# $OpenBSD: install.sub,v 1.1169 2021/07/20 11:20:09 kn Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer @@ -244,21 +244,20 @@ prep_root_mail() { __EOT } -# Examine the contents of the DHCP lease file $1 for a line containing the -# field provided as parameters and return the value of the first field found. +# Examine the contents of the dhcpleased lease file $1 for a line containing the +# field(s) provided as parameters and return the value of the first field found. # -# Note that strings are unescaped but not unvis()'d. +# Note that value strings are VIS_SAFE'd. lease_value() { - local _lf=$1 _o + local _lf=$1 _o _opt _val [[ -s $_lf ]] || return shift for _o; do - sed -E \ - -e '/^'"$_o"': (.*)$/!d;s//\1/' \ - -e '/^"(.*)"$/{s//\1/;s/\\(.)/\1/g;};q' "$_lf" \ - | grep ^ && return + while read -r _opt _val; do + [[ $_opt == ${_o}: ]] && echo "$_val" && return + done < "$_lf" done } -- 2.20.1