We used MASTER, BRIDGE and TEAM_MASTER keys for a differnet purpose than the
network.service did, confusing the legacy tooling. Let's do our best to write
compatible configuration files:
* Add *_UUID properties that won't clash with initscripts
* Ignore non-*_UUID keys on read if *_UUID is present
* If the connection.master is an UUID of a connection with a
connection.interface-name, write the uuid into the *_UUID key while setting
the non-*_UUID key to the interface name for compatibility
https://bugzilla.redhat.com/show_bug.cgi?id=1369091
Currently ipv4 and ipv6 settings share the ifcfg plugin vars for the
dhcp-hostname and dhcp-send-hostname options (DHCP_HOSTNAME and
DHCP_SEND_HOSTNAME). Add brand new vars DHCPV6_HOSTNAME and
DHCPV6_SEND_HOSTNAME to have var-property one to one mappings.
When those values are missing they are already considered as TRUE.
As they are written also when DHCP is not enabled, write them only
if they have a value different from the default.
Also, ifnet plugin would read the configuration value, which is just wrong
because:
- the configuration might not be set and ifnet would fail to fallback
to the compile time default.
- the configuration only is in effect if the plugin is also available.
Otherwise, we fallback to the next plugin.
Only the dhcp-manager knows which DHCP plugin is in use.
NOTE: changed the default value for auto-negotiate from TRUE to FALSE.
Normalization enforces that no values for speed and duplex are there
when autonegotiation is on. This is required as autoneg on with specific
speed and duplex set means to ethtool to use autonegotiation but
advertise that specific speed and duplex only.
autoneg off, speed 0 and duplex NULL means to ignore link negotiation.
Keep the include paths clean and separate. We use directories to group source
files together. That makes sense (I guess), but then we should use this
grouping also when including files. Thus require to #include files with their
path relative to "src/".
Also, we build various artifacts from the "src/" tree. Instead of having
individual CFLAGS for each artifact in Makefile.am, the CFLAGS should be
unified. Previously, the CFLAGS for each artifact differ and are inconsistent
in which paths they add to the search path. Fix the inconsistency by just
don't add the paths at all.
- a key
FOO=''
would still allocate a temporary GString and return the allocated
empty string. Don't do that. This saves the g_free() in
svGetValueString() for this common case. We should return
an allocated string only if it is necessary. It is not necessary
for the "" case, and it is inconsistent.
- when returning an empty string, always return the static string "".
No need to seek to the end of value, and return a pointer to that
string.
This happens for example in the case
FOO= # empty value, but trailing stuff
FOO=""
FOO=$'\Uxhallo'
I don't think that the compiler is able to optimize
strchr($SET_AS_STR, $CHAR)
Use NM_IN_SET() which expands to something that should be
easy for the compiler to optimize.
Now we could parse simple shell variable assignment properly, but old versions
of svEscape() wrote invalid double-quoted strings.
Add a hack to restore the broken behavior for that case only.
When introducing the macro _svGetValue_check() we replace
the call to svGetValueString() with svGetValue().
That makes a difference only when asserting against a %NULL
value. It's fair to assume that in such case we actually want
to assert that the value is unset, and not possibly empty.
svUnescape() can return a pointer to the input argument
(if the input argument requires no unescaping or truncation).
That is actually the predominant case because most often we
store values that don't require escaping.
Optimize for that case.
This is especially important because we don't support
line continuation. Thus, with
FOO='val
bar=3'
wrong line
F2=b
F3='b
XXX=adf'
XXX2=val2
'
we now write
FOO=
#NM: FOO='val
bar=
#NM: bar=3'
#NM: wrong line
F2=b
F3=
#NM: F3='b
XXX=
#NM: XXX=adf'
XXX2=val2
#NM: '
Basically, the writer will comment out any line that is
- not all-whitespace
- not a '#' comment (possibly proceeded by whitespace)
- not a valid variable assignment
This avoids that writer writes lines that are not understood by
ifcfg-rh plugin, but interferes with initscripts. E.g.
NAME=old-name'
rm -rf /
'
becomes
NAME=new-name
#NM: rm -rf /
#NM: '
'\'', '~': must not be escaped with backslash.
Also, within double quotes the backslash escape character is only
removed before special caracters like '$' or '`'. Not in general.
Yes, it means that older versions of svEscape produced invalid escape
sequences that we now treat differently. But that is not realy
avoidable, it was a bug that needs to be fixed.
This is especially important for the team config JSON, which is expected
to contain newlines.
ANSI C quotation is bash specific, but initscripts already use #!/bin/bash.
Unfortunately, g_strescape() doesn't escape '\'' and can thus not be
used.
Also add a test that svEscape() and svUnescape() do a round-trip.
Not only consider \r and \n as candidates for ANSI C quotation, but all
ANSI control characters.
Better support parsing of shell. Now we support:
- combining values, like
FOO=a"b"
FOO=$'\n'b
- bash style ANSI C quotation ($''). This will allow us to properly
handle newlines in string values.
- comments at the end of a line (after whitespace)
FOO=val #comment
Note that this is different from a # without space
FOO=val#with#hashes
- trailing spaces are ignored like
FOO=a[space]
FOR=[space]
- history expansion via ! is not done (this is not new).
We don't support:
- line continuation like
FOO='
'
FOO=a\
b
- any form of shell expansion via $, ``.
FOO="$a"
Such values are recognized to name a variable FOO, but with an
empty value, like
FOO=%{nil}
which is not the same as a valid empty value
FOO=
- any other form of (unquoted) shell meta characters, like ; < > ( ).
This especially means, that the command invocations are invalid, like
ls -1
LANG=C ls -1
FOO1=a; FOO2=b
This also means, that spaces immidiately after the assignment are invalid:
FOO= val
Also, svUnescape() can now return %NULL to signal an invalid line like
FOO='
When
- reading a key that is defined multiple times, accept
the last occurrence.
- when deleting such a key, delete all occurrences.
- when overwriting such a key, overwrite the last occurrence
and delete any previous definitions.
It was not used and it is bad style. Especially, because
in the next commit we want to remove multiple definitions
of a key. Thus, we usually always iterate until the end.
Move the g_strchomp() inside svUnescape(). It is part of the
escaping process (although of course wrong to do, because
it accepts "FOO= bar". That will be fixed later).
Thereby, change the signature to allow in the future
to do unescape without additional copy.
svGetValue() had the meaning of returning a string, except the
empty word "" was coerced to NULL.
svGetValueFull() had the meaing of returing the value as string,
including the empty word.
Rename those functions to better express what they do.
Same for svSetValue*().
It is wrong to allow access to unquoted ifcfg-rh values.
All users of this ~feature~ misused it to encode meaning
in the type of quotation, which is wrong.
Also, shvar.h is not able to fully parse shell. We can improve
that, but it should be handled internally, in one place. Not by
callers applying some quirks after getting a "verbatim" value.