Commit graph

1064 commits

Author SHA1 Message Date
Thomas Haller
8ccba8d09f ifcfg-rh/tests/trivial: remove self-explanatory comments 2016-03-04 18:11:45 +01:00
Beniamino Galvani
4090716d96 core: use hostnamed to set the transient hostname
In commit 6dc35e66d4 ("settings: add hostnamed support") we started
to use systemd-hostnamed for setting the system static hostname
(i.e. the one written to /etc/hostname), but nm-policy.c still called
sethostname() to set the transient (dynamic) hostname when this needs
to be changed, for example after a reverse lookup of our dynamic IP
address.

Thus, when using systemd the hostname change failed because process'
capabilities are restricted and sethostname() requires CAP_SYS_ADMIN.

We should set also the transient hostname through hostnamed when this
is available.

https://bugzilla.redhat.com/show_bug.cgi?id=1308974
2016-03-04 14:27:09 +01:00
Beniamino Galvani
505faf0d6d settings: use logging helpers 2016-03-04 11:53:04 +01:00
Thomas Haller
1bf76b784f ifcfg-rh/tests: remove call to nm_connection_normalize()
Coverity complains that the return value is not checked.
Normaliziation here is not necessary.
2016-03-04 08:37:54 +01:00
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Dan Winship
6265398b6e all: use g_error_matches()
Use g_error_matches() where we're testing error codes. In particular,
use it rather than looking at only ->code and not also ->domain, which
is just wrong.

[thaller@redhat.com: rebase and modify original patch]
2016-03-03 18:54:20 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Beniamino Galvani
c30627f106 settings: set @error on failure of nm_settings_plugin_add_connection() 2016-03-03 18:54:20 +01:00
Thomas Haller
24582b65e1 logging: change logging format to drop "[file:line] func():" part
Choose a new logging format.

- the logging format must not be configurable and it must be the
  same for all backends. It is neat that journal supports additional
  fields, but an average user still posts the output of plain
  journalctl, without "--output verbose" (which would also be hard
  to read).
  Also, we get used to a certain logging format, so having different
  formats is confusing. If one format is better then another, it should
  be used for all backends: syslog, journal and debug.
  The only question is, what is the best format.

- the timestamp: I find it useful to see how much time between two
  events passed. The timestamp printed by syslog doesn't have sufficient
  granularity, and the internal journal fields are not readily available.
  We used to print the timestamps for <error>, <debug> and <trace>,
  but ommited them for <info> and <warn> levels. We now print them for
  all levels, which has a uniform alignment.

- the location: the "[file:line] func():" part is mostly redundant
  and results in wide lines. It also causes a misalignment of the
  logging lines, or -- as I recently added alignment of the location --
  it results in awkward whitespace and truncation.
  But the location is really just necessary because our logging messages
  are bad:
    "<debug> [1456397604.038226] (9) 11-dhclient succeeded"
  The solution to this is not
    "<debug> [1456397604.038226] [nm-dispatcher.c:358] dispatcher_results_process(): (9) 11-dhclient succeeded"
  but a properly worded message:
    "<debug> [1456397604.038226] dispatcher: request #9, script 11-dhclient succeeded"

- logging-message: we need to write better logging messages.
  I like some form of "tags" that are easy to grep:
    "platform: signal: link changed: 4: ..."
  Downside is, that this is not nice to read as a full sentence.
  So, especially for <info> and <warn> logging, more human readable
  messages are better.
  We should find a compromise, where the log message explains what
  happens, but is still concise and contains patterns that are easy
  to grep and identify visually.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00077.html
2016-03-01 15:20:57 +01:00
Beniamino Galvani
da70fbd7d5 libnm-core: remove special handling of missing VLAN_FLAGS
On older NM versions the default value for vlan.flags was 0, but then
the actual value set on interfaces was REORDER_HDR. In order to
maintain backwards compatibility in behavior, remove the special
handling of vlan.flags so that a missing key is treated as the default
value REORDER_HDR.

https://bugzilla.gnome.org/show_bug.cgi?id=762626
2016-02-29 18:11:17 +01:00
Beniamino Galvani
2e5e7285a8 ifcfg-rh: change the handling of REORDER_HDR flag
On NM 1.0 connections were created by default without the REORDER_HDR
flag, but then due to a bug in platform code (fixed in [1]), the
kernel interface always had the flag set.

Now that the setting is honored, users upgrading to the new version of
NM will see a change from the previous behavior, since interfaces will
not have REORDER_HDR and this will certainly break functionality.

The only solution here seems to be to ignore the REORDER_HDR variable
in ifcfg files (since it never had any effect) and introduce a new
NO_REORDER_HDR option for the VLAN_FLAGS variable which allows to turn
the flag off. The consequence is that the flag will be set for all old
connections.

This change introduces an incompatibility with initscripts, however is
necessary to avoid breaking user functionality upon upgrade.
Connections created through NetworkManager will still be parsed
correctly by initscripts (since we always write the REORDER_HDR
variable).

[1] db62fc9d72 ("platform: fix adding VLAN flags")

https://bugzilla.gnome.org/show_bug.cgi?id=762626
2016-02-29 18:11:17 +01:00
Lubomir Rintel
36573225b6 ifcfg-rh: add test for BOOTPROTO=autoip
Previous commit fixed parsing of these connection; let's check that we don't
regress there.
2016-02-24 16:54:27 +01:00
Lubomir Rintel
2e2f56697f ifcfg-rh: short circuit the IP configuration parsing on IPv4LL
We need the other keys, such as may_fail, too.
2016-02-24 16:54:27 +01:00
Thomas Haller
d3e776b0e2 ifcfg-rh: fix leaking unmanaged_spec/unhandled_spec in NMIfcfgConnection 2016-02-22 15:36:12 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
c38c4dce3e ifcfg-rh/tests: pass arguments to tests via nmtst_add_test_func()
And call all tests via g_test_run().
2016-02-18 01:46:56 +01:00
Dan Williams
304575e671 ifcfg-rh: more testcase cleanups 2016-02-17 16:43:13 -06:00
Beniamino Galvani
1bb3b6a4c6 libnm-core: make ipvx.dhcp-timeout signed
Change the dhcp-timeout property in NMSettingIPConfig to int type for
consistency with the dad-timeout property. For dad-timeout -1 means
"use default value", while for dhcp-timeout probably we will never use
negative values, but it seems more correct to use the same type for
the two properties.
2016-02-16 11:37:26 +01:00
Beniamino Galvani
206e074863 libnm,core,cli: move dhcp-timeout property to generic NMSettingIPConfig
The property applies to both IPv4 and IPv6 and so it should not be in
NMSettingIP4Config but in the base class.
2016-02-16 11:37:26 +01:00
Thomas Haller
4b76d86698 core/trivial: rename local function in "nm-settings-connection.c"
Only D-Bus implementations should be named "^impl_.*", not a helper
function.
2016-02-16 11:24:22 +01:00
Beniamino Galvani
10b222288e wifi: don't touch by default current powersave setting
Some drivers (or things outside NM like 'powertop') may turn powersave
on, so don't touch it unless explicitly configured by user.

To achieve this, add new 'default' and 'ignore' options; the former
can be used to fall back to a globally configured setting, while the
latter tells NM not to touch the current setting.

When 'default' is specified, a missing global default configuration is
equivalent to 'ignore'.

It is possible to enable Wi-Fi power saving for all connections by
dropping a file in /etc/NetworkManager/conf.d with the following
content:

 [connection]
 wifi.powersave=3

https://bugzilla.gnome.org/show_bug.cgi?id=760125
2016-02-16 00:18:06 +01:00
Thomas Haller
87a3df2e57 device: remove default-unmanaged and refactor unmanaged flags
Get rid of NM_UNMANAGED_DEFAULT and refine the interaction between
unmanaged flags, device state and managed property.

Previously, the NM_UNMANAGED_DEFAULT was special in that a device was
still considered managed if it had solely the NM_UNMANAGED_DEFAULT flag
set and its state was managed. Thus, whether the device (state) was managed,
depended on the device state too.

Now, a device is considered managed (or unmanaged) based on the unmanaged
flags and realization state alone. At the same time, the device state
directly corresponds to the managed property of the device. Of course,
while changing the unmanaged flags, that invariant is shortly violated
until the state transistion is complete.

Introduce more unmanaged flags whereas some of them are non-authorative.
For example, the EXTERNAL_DOWN flag has only effect as long as the user
didn't explicitly manage the device (NM_UNMANAGED_USER_EXPLICIT). In other
words, certain flags can render other flags ineffective. Whether the device
is considered managed depends on the flags but also at the explicitly unset flags.
In a way, this is similar to previous where NM_UNMANAGED_DEFAULT was ignored
(if no other flags were present).

Also, previously a device that was NM_UNMANAGED_DEFAULT and in disconnected
state would transition back to unmanaged. No longer do that. Once a device is
managed, it stays managed as long as the flags indicate it should be managed.
However, the user can also modify the unmanaged flags via the D-Bus API.

Also get rid or nm_device_finish_init(). That was previously called
by NMManager after add_device(). As we now realize devices (possibly
multiple times) this should be handled during realization.

https://bugzilla.gnome.org/show_bug.cgi?id=746566
2016-02-15 21:40:02 +01:00
Thomas Haller
16434c85f8 ifcfg-rh/tests: refactor test using helper functions and drop ASSERT() macro 2016-02-15 14:26:53 +01:00
Thomas Haller
e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Dan Williams
b73c0e2f6d keyfile: convert testcases to g_assert() 2016-02-11 10:44:41 -06:00
Dan Williams
e5dd4c6882 ifupdown: convert last tests to g_assert() 2016-02-11 10:03:42 -06:00
Thomas Haller
3fd414442e ifcfg-rh: ignore explicit IPv4 default routes in reader
NetworkManager does not allow default routes to be specified
as normal routes. They must be ignored. Especially, iproute2
which reads the ifcfg files in initscripts, does not allow
to specify a prefix length "default/x" except for "default/0".

https://bugzilla.gnome.org/show_bug.cgi?id=761631
2016-02-11 14:27:28 +01:00
Thomas Haller
c510323368 all/tests: fix messages for ASSERT() macro
These places pass an invalid arguments for the given
format string. Fix them, by dropping the overly verbose
ASSERT() macro.
2016-02-03 12:37:43 +01:00
Thomas Haller
c2709eac40 ifcfg-rh/tests: fix variable scope for test arguments
The @read_wired_static array is passed on as test function. But defining
it in a local scope is strictly speaking not correct because the lifetime
of the array ends before the test run. Move it to the outer scope, which
exists during the test runs.
2016-01-29 20:22:28 +01:00
Thomas Haller
a76a1abb49 ifcfg-rh/tests: fix test after changing behavior for setting NM_SETTING_IP_CONFIG_GATEWAY
Since commit bb868770, setting a gateway of "0.0.0.0"
or "::" in NMSettingIPConfig means to set the gateway
to NULL. There is indeed no difference between an unset
gateway and an any gateway. This change was done to have
a consistent behavior in NMSettingIPConfig.

Fixes: bb86877031
2016-01-29 20:22:28 +01:00
Lubomir Rintel
60b7ed3bdc ifcfg,keyfile: fix temporary file races (CVE-2016-0764)
Two of these raised Coverity's eyebrows.

CID 59389 (#1 of 1): Insecure temporary file (SECURE_TEMP)
5.  secure_temp: Calling mkstemp without securely setting umask first.

CID 59388 (#1 of 1): Insecure temporary file (SECURE_TEMP)
1.  secure_temp: Calling mkstemp without securely setting umask first.

Last one raised mine.

When a connection is edited and saved, there's a small window during which and
unprivileged authenticated local user can read out connection secrets (e.g. a
VPN or Wi-Fi password). The security impact is perhaps of low severity as
there's no way to force another user to save their connection.
2016-01-29 20:18:28 +01:00
Lubomir Rintel
a77ec45110 ifcfg: make Coverity happy
CID 59382 (#1 of 1): Dereference null return value (NULL_RETURNS)
10.  dereference: Dereferencing a pointer that might be null value
when calling strcmp.

Not exactly true, since we ruled out the posibility earlier; but
we could still get rid of a couple of strcmps.
2016-01-29 20:18:21 +01:00
Thomas Haller
301c747938 settings: coding style and use gs_free in write_hostname() 2016-01-29 17:36:27 +01:00
Joel Holdsworth
55a07b4ca4 settings: resolve path if hostname is a sym-link
If the hostname file is a symbolic link, follow it to find where the
real file is located, otherwise g_file_set_contents will attempt to
replace the link with a plain file.

https://mail.gnome.org/archives/networkmanager-list/2016-January/msg00061.html
https://mail.gnome.org/archives/networkmanager-list/2016-January/msg00073.html
2016-01-29 17:33:48 +01:00
Dan Williams
08bc51095c ifcfg-rh: convert more testcases to g_assert() 2016-01-22 09:47:16 -06:00
Jiří Klimeš
adbbf3aa5c ifcfg-rh: read/write ipv4.dad-timeout using ARPING_WAIT
ARPING_WAIT is used for DAD by Red Hat initscrips (ifup-eth).
2016-01-20 11:53:47 +01:00
Beniamino Galvani
24d8604637 core: use NM_PLATFORM_GET instead of nm_platform_get() in function calls
Replacement was done with command:

spatch --sp-file nm_platform_get.cocci --in-place --smpl-spacing --dir src

where nm_platform_get.cocci contains:

@@
identifier func;
expression list args;
@@
- func (nm_platform_get())
+ func (NM_PLATFORM_GET)

@@
identifier func;
expression list args;
@@
- func (nm_platform_get(), args)
+ func (NM_PLATFORM_GET, args)
2016-01-06 21:25:56 +01:00
Beniamino Galvani
ea1eb94d9b core: use nm_clear_g_signal_handler() where possible
Replacement was done with command:

spatch --sp-file nm_clear_g_signal_handler.cocci --in-place --smpl-spacing --dir src

where nm_clear_g_signal_handler.cocci contains:

@@
expression obj, id;
@@
- if (id) {
-    g_signal_handler_disconnect (obj, id);
-    id = 0;
- }
+ nm_clear_g_signal_handler (obj, &id);
2016-01-06 21:25:56 +01:00
Beniamino Galvani
f96abc8be5 core: always use gulong to store signal handler ids
We inconsistently use gulong,guint,int types to store signal handler
id, but the type returned by g_signal_connect() is a gulong.

This has no practical consequences because a int/guint is enough to
store the value, however it is better to use a consistent type, also
because nm_clear_g_signal_handler() accepts a pointer to the signal id
and thus it must be always called with the same pointer type.
2016-01-06 21:25:55 +01:00
Beniamino Galvani
fbd3286955 core,libnm: use nm_clear_g_source() where possible
Replacement was done with commands:

spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir src
spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir libnm

where nm_clear_g_source.cocci contains:

@@
expression e;
@@
- if (e) {
-    g_source_remove (e);
-    e = 0;
- }
+ nm_clear_g_source (&e);
2016-01-06 21:25:55 +01:00
Beniamino Galvani
272098e48b ifcfg-rh: fix utils_detect_ifcfg_path() argument
Fixes: 39e97c9339
2016-01-06 21:19:45 +01:00
Thomas Haller
39e97c9339 ifcfg-rh: only accept ifcfg base paths in impl_ifcfgrh_get_ifcfg_details()
Previously, we directly passed the @in_ifcfg path to find_by_path().
That means, @in_ifcfg must be the path to the base "ifcfg-" file,
not an alias or route file.

Add an additional pre-check, that the provided file name is really a
ifcfg base file.

This results in a more detailed error message when calling
GetIfcfgDetails not on the ifcfg base file. It's not that previously
the lookup would have succeeded.
2016-01-06 12:06:44 +01:00
Thomas Haller
db80ec05ab build: rename directory "include" to "shared"
Up to now, the "include" directory contained (only) header files that were
used project-wide by libs, core, clients, et al.

Since the directory now also contains a non-header file, the "include"
name is misleading. Instead of adding yet another directory that is
project-wide, with non-header-only content, rename the "include"
directory to "shared".
2015-12-24 11:42:37 +01:00
Thomas Haller
5201c3d8f9 trival: fix whitespace 2015-12-08 11:52:37 +01:00
Thomas Haller
3a3b32a9f6 config: add defines for key names for keyfile 2015-12-08 11:47:56 +01:00
Dan Williams
d6f9230beb core: add "real" NMDevice property
This property is TRUE for devices that exist either as a kernel device
or are backed by some other resource (eg, ModemManager object, Bluez
device, etc).  It will eventually be FALSE for software devices that
are not yet instantiated.
2015-12-04 12:15:12 +01:00
Thomas Haller
510e53ca16 platform: remove NMPlatformReason enum
This enum was unused and meaningless because the platform signals
are emitted as a consequence of netlink messages. It is not clear
whether a netlink message was received due to an external event
or an internal action.
2015-11-27 15:17:44 +01:00
Lubomir Rintel
3e0b590e10 build: Remove NM_CONFIG_KEYFILE_PATH_DEFAULT from config.h
Can't just substitute sysconfdir into a header file -- it's meant to be
expanded in a Makefile. Otherwise, unexpanded ${prefix} will end up in a
header file.

We do that for NMCONFDIR already, let's use it here too.

Fixes: 2144457fab
2015-11-27 10:04:10 +01:00
Thomas Haller
e2b9346d71 ifcfg-rh: remove unused selinux.h include from "plugin.c" 2015-11-24 12:20:55 +01:00