network: amend SendOption= to take a c-escaped string

No need to punish users by forcing them to do base64 encodings.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-10-30 09:13:38 +01:00
parent 864edb39cf
commit a2cc708a88
2 changed files with 15 additions and 12 deletions

View file

@ -1642,10 +1642,14 @@
<varlistentry> <varlistentry>
<term><varname>SendOption=</varname></term> <term><varname>SendOption=</varname></term>
<listitem> <listitem>
<para>Send a raw option with value via DHCPv4 client. Takes a DHCP option and base64 encoded <para>Send an arbitrary option in the DHCPv4 request. Takes a DHCP option number and an arbitrary
data separated with a colon (option:value). The option ranges [1-254]. This option can be data string separated with a colon
specified multiple times. If an empty string is specified, then all options specified earlier (<literal><replaceable>option</replaceable>:<replaceable>value</replaceable></literal>). The
are cleared. Defaults to unset.</para> option number must be an interger in the range 1..254. Special characters in the data string may
be escaped using
<ulink url="https://en.wikipedia.org/wiki/Escape_sequences_in_C#Table_of_escape_sequences">C-style
escapes</ulink>. This option can be specified multiple times. If an empty string is specified,
then all options specified earlier are cleared. Defaults to unset.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>

View file

@ -6,7 +6,7 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "dhcp-client-internal.h" #include "dhcp-client-internal.h"
#include "hexdecoct.h" #include "escape.h"
#include "hostname-util.h" #include "hostname-util.h"
#include "parse-util.h" #include "parse-util.h"
#include "network-internal.h" #include "network-internal.h"
@ -1579,12 +1579,11 @@ int config_parse_dhcp_send_option(
void *userdata) { void *userdata) {
_cleanup_(sd_dhcp_option_unrefp) sd_dhcp_option *opt = NULL, *old = NULL; _cleanup_(sd_dhcp_option_unrefp) sd_dhcp_option *opt = NULL, *old = NULL;
_cleanup_free_ char *word = NULL; _cleanup_free_ char *word = NULL, *q = NULL;
_cleanup_free_ void *q = NULL;
Network *network = data; Network *network = data;
const char *p; const char *p;
uint8_t u; uint8_t u;
size_t sz; ssize_t sz;
int r; int r;
assert(filename); assert(filename);
@ -1619,10 +1618,10 @@ int config_parse_dhcp_send_option(
return 0; return 0;
} }
r = unbase64mem(p, (size_t) -1, &q, &sz); sz = cunescape(p, 0, &q);
if (r < 0) { if (sz < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, log_syntax(unit, LOG_ERR, filename, line, sz,
"Failed to decode base64 data, ignoring assignment: %s", p); "Failed to decode option data, ignoring assignment: %s", p);
return 0; return 0;
} }