Commit graph

891 commits

Author SHA1 Message Date
Francesco Giudici
f124048b80 ifcfg-rh/tests: avoid using g_assert_null() API
Fixes: 2852b50945
2016-12-15 13:34:54 +01:00
Lubomir Rintel
8b7b0d3fc2 ifcfg-rh: write the master device name even if the master property is an UUID
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
2016-12-15 11:45:34 +01:00
Lubomir Rintel
96988f8deb ifcfg-rh: add test case for remembering the unset values
Validates the previous commit.
2016-12-15 11:45:34 +01:00
Lubomir Rintel
d36c6d2892 ifcfg-rh: remember where the keys have been when we remove them
We may want to re-add them right away, let's remember the original
contents so that we can add it at the right place.
2016-12-15 11:45:34 +01:00
Francesco Giudici
2ee6b7bf82 ifcfg-rh: merge branch 'fg/dhcp_hostname_bgo775622'
https://bugzilla.gnome.org/show_bug.cgi?id=775622
2016-12-15 11:29:05 +01:00
Francesco Giudici
6bf69d0fa1 ifcfg-rh/tests: add ipv6 hostname legacy support read test 2016-12-14 16:21:26 +01:00
Francesco Giudici
2852b50945 ifcfg-rh: add DHCPV6_HOSTNAME and DHCPV6_SEND_HOSTNAME vars
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.
2016-12-14 16:21:26 +01:00
Francesco Giudici
08bd3feed0 ifcfg-rh: write [IPV6_]PEERDNS and [IPV6_]PEERROUTES only when they are "no"
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.
2016-12-14 16:14:24 +01:00
Francesco Giudici
dbb9cd3ca8 ifcfg-rh: save/restore dhcp related properties also when ip method != DHCP/AUTO
affected properties are: ipv4.dhcp-client-id, ipv4.fqdn,
ipv4.dhcp-timeout, ipvX.ignore-auto-routes, ipvX.ignore-auto-dns,
ipvX.dhcp-hostname and ipvX.dhcp-send-hostname.
2016-12-14 15:27:42 +01:00
Thomas Haller
4bdee37771 all: use O_CLOEXEC for file descriptors 2016-12-13 11:26:59 +01:00
Thomas Haller
61c6ccaad4 config: drop nm_config_get_dhcp_client() and access config directly
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.
2016-11-25 18:02:38 +01:00
Francesco Giudici
5da352c5e8 ifupdown/trivial: whitespace fixup 2016-11-24 18:31:02 +01:00
Francesco Giudici
3bcca564c7 ifcfg-rh/tests: add tests for link negotiation options
Thanks to Thomas Haller for making test code much more compact taking
advantage of the nmtst_create_minimal_connection function.
2016-11-22 15:24:47 +01:00
Francesco Giudici
12b9d30ae6 ifcfg-rh: add support to 802-3.[auto-negotiate,speed,duplex] properties
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.
2016-11-22 15:24:47 +01:00
Francesco Giudici
de88a46775 ifcfg-rh: rework ETHTOOL_OPT parsing function
This would allow to make easier adding support to more ETHTOOL options.
2016-11-22 15:24:47 +01:00
Thomas Haller
44ecb41593 build: don't add subdirectories to include search path but require qualified include
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.
2016-11-21 14:26:37 +01:00
Thomas Haller
88e18c9de8 ifcfg-rh: improve handling of empty strings in svUnescape()
- 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'
2016-11-11 12:55:01 +01:00
Beniamino Galvani
9430cf3e6b ifcfg-rh: accept 802.1x connection with empty EAP-TLS identity
An identity is not needed for EAP-TLS.

https://bugzilla.redhat.com/show_bug.cgi?id=1391477
2016-11-11 11:03:57 +01:00
Lubomir Rintel
3d7931bbf6 ifcfg-rh: fix a memory leak 2016-11-09 20:34:13 +01:00
Lubomir Rintel
611870347a ifcfg: add ability to save/restore ipv6.method=shared
We use IPV6_AUTOCONF=shared for this.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
2e8f40f2c9 ifcfg-rh: avoid parsing the IPV6_PRIVACY string twice
This saves a couple of CPU cycles that would be better used for
something more useful, such as looking for transmissions from aliens.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
577ba42e18 ifcfg-rh: get rid of an extra unused variable
This saves a couple of bits we could instead use to save memories of the
better days.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
888d8f4b10 ifcfg-rh: add parentheses
The code is now perfect.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
90beb7689a ifcfg-rh: drop an unused variable
Fixes: ecda08e1d1
2016-11-09 15:06:00 +01:00
Thomas Haller
92712d3b31 ifcfg-rh: optimize checking character types during svEscape()
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.
2016-11-09 12:07:35 +01:00
Thomas Haller
c5ac66d392 ifcfg-rh: restore previous behavior for svUnescape() stripping backslash from double-quoting
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.
2016-11-09 12:07:35 +01:00
Thomas Haller
ecda08e1d1 ifcfg-rh/tests: some refactoring of tests
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.
2016-11-09 12:07:35 +01:00
Thomas Haller
01f0e35b69 ifcfg-rh: remove unused keyfile argument from writer_update_connection()
writer_update_connection() retrieves the keyfile name based on the ifcfg-name.
No need to pass it in separately, the argument was unused.
2016-11-09 12:07:35 +01:00
Thomas Haller
1b03b59ac0 ifcfg-rh: set errno in svGetValueInt64() in case key does not exist 2016-11-09 12:07:35 +01:00
Thomas Haller
264e519779 ifcfg-rh/tests: add test for handling multiple occurances of a variable
This tests commit "ifcfg-rh: handle multiple definitions of the same key".
2016-11-09 12:07:35 +01:00
Thomas Haller
c20b795547 ifcfg-rh: let reader create lineList in O(n) using g_list_prepend() and g_list_reverse() 2016-11-09 12:07:35 +01:00
Thomas Haller
eb307bbbb6 ifcfg-rh: let reader preserve the last line even without newline at end of file 2016-11-09 12:07:35 +01:00
Thomas Haller
82ccec22ca ifcfg-rh: modify svGetString() signature to avoid copying of temporary value
Modify the signature of svGetString() to allow getting the internal
string without cloning the string after unescaping.
2016-11-09 12:07:35 +01:00
Thomas Haller
08a22f2eea ifcfg-rh: avoid copying temporary value after unescaping
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.
2016-11-09 12:07:35 +01:00
Thomas Haller
9843da7ce5 ifcfg-rh: comment out invalid lines during svWriteFile
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: '
2016-11-09 12:07:35 +01:00
Thomas Haller
d8c465a3cd ifcfg-rh: fix svEscape() to properly handle double quoting
'\'', '~': 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.
2016-11-09 12:07:34 +01:00
Thomas Haller
337fc582b2 ifcfg-rh: use macro _char_in_strset() for svEscape() 2016-11-09 12:07:34 +01:00
Thomas Haller
c55b7e866e ifcfg-rh: support storing newline '\n' and other ANSI control caracters
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.
2016-11-09 12:07:34 +01:00
Thomas Haller
7b548fb9a8 ifcfg-rh: rework parsing of shell (svUnescape())
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='
2016-11-09 12:07:34 +01:00
Thomas Haller
f3c7d009b5 ifcfg-rh: handle multiple definitions of the same key
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.
2016-11-09 12:07:34 +01:00
Thomas Haller
9719988674 ifcfg-rh: get rid of the internal "current" pointer
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.
2016-11-09 12:07:34 +01:00
Thomas Haller
1ae62854f5 ifcfg-rh: refactor svUnescape()
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.
2016-11-09 12:07:34 +01:00
Thomas Haller
85beac6dd4 ifcfg-rh: allow leading spaces before variable names 2016-11-09 12:07:34 +01:00
Thomas Haller
afc394b969 ifcfg-rh: assert that keys are valid shell names 2016-11-09 12:07:34 +01:00
Thomas Haller
806ffbbe14 ifcfg-rh: cleanup svEscape()
Use size_t type for string length and have character sets
as #define.
2016-11-09 12:07:34 +01:00
Thomas Haller
917ab8334b ifcfg-rh/trivial: rename svGetValue() and related
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*().
2016-11-09 12:07:34 +01:00
Thomas Haller
2a3b238d49 ifcfg-rh: add and use svSetValueBoolean() 2016-11-09 12:07:34 +01:00
Thomas Haller
b473256cfd ifcfg-rh: remove unused argument "verbatim" from shvar.h API
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.
2016-11-09 12:07:34 +01:00
Thomas Haller
1fb3d5d794 ifcfg-rh: don't call svSetValue with verbatim=TRUE
This is at best a performance optimization. In the next step
get rid of the verbatim argument, so ensure we pass FALSE everwhere.
2016-11-09 12:07:34 +01:00
Thomas Haller
58b69e2f90 ifcfg-rh/trivial: remove unused functions utils_single_quote_string() and unquote 2016-11-09 12:07:34 +01:00