Commit graph

1152 commits

Author SHA1 Message Date
Beniamino Galvani
a77ed0de97 core: drop root requirement for load_connection(s)/set_logging D-Bus calls
The D-Bus configuration already ensures that only root can do that;
enforcing the permission at policy level seems better than doing it in
the daemon itself because it allows users to change the policy and
also because callers can exit immediately after issuing the request.

(cherry picked from commit 4c7fa8dfdc)
2016-08-20 10:45:53 +02:00
Beniamino Galvani
0944a86182 ifcfg-rh: ensure master is cleared when updating a connection
If the connection is not a slave we must clear any existing variable
indicating the connection's master.

https://bugzilla.redhat.com/show_bug.cgi?id=1355656
(cherry picked from commit 2750714802)
2016-08-19 18:56:59 +02:00
Thomas Haller
0bdcab100c all: cleanup includes in header files
- don't include "nm-default.h" in header files. Every source file must
  include as first header "nm-default.h", thus our headers get the
  default include already implicitly.

- we don't support compiling NetworkManager itself with a C++ compiler. Remove
  G_BEGIN_DECLS/G_END_DECLS from internal headers. We do however support
  users of libnm to use C++, thus they stay in public headers.

(cherry picked from commit f19aff8909)
2016-08-17 19:51:17 +02:00
Thomas Haller
d23f43f2b9 core: add nm_bus_manager_ensure_root() helper 2016-08-11 11:54:18 +02:00
Beniamino Galvani
10c5352855 secret-agent: increase timeout for GetSecrets D-Bus call
The default value of 25 seconds is too short, bump it to 120.

https://bugzilla.gnome.org/show_bug.cgi?id=767321
https://bugzilla.redhat.com/show_bug.cgi?id=1349740
2016-07-08 11:55:55 +02:00
Thomas Haller
e81d4f2b64 ifcfg: downgrade warning about NM_CONTROLLED=no
NM_CONTROLLED=no is an explicit user configuration. There is no point in
issuing a warning that the user doesn't want to manage a device.

   <warn>  [1467722628.7388] ifcfg-rh: Ignoring connection /etc/sysconfig/network-scripts/ifcfg-eth0 (5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03,"System eth0") / device 'eth0' due to NM_CONTROLLED=no.

Also, don't truncate the device spec, instead show the full
device spec, it may contains a MAC address or a s390 subchannel.
2016-07-05 23:08:23 +02:00
Thomas Haller
96cabbcbb8 all: make MAC address randomization algorithm configurable
For the per-connection settings "ethernet.cloned-mac-address"
and "wifi.cloned-mac-address", and for the per-device setting
"wifi.scan-rand-mac-address", we may generate MAC addresses using
either the "random" or "stable" algorithm.

Add new properties "generate-mac-address-mask" that allow to configure
which bits of the MAC address will be scrambled.

By default, the "random" and "stable" algorithms scamble all bits
of the MAC address, including the OUI part and generate a locally-
administered, unicast address.

By specifying a MAC address mask, we can now configure to perserve
parts of the current MAC address of the device. For example, setting
"FF:FF:FF:00:00:00" will preserve the first 3 octects of the current
MAC address.

One can also explicitly specify a MAC address to use instead of the
current MAC address. For example, "FF:FF:FF:00:00:00 68:F7:28:00:00:00"
sets the OUI part of the MAC address to "68:F7:28" while scrambling
the last 3 octects.
Similarly, "02:00:00:00:00:00 00:00:00:00:00:00" will scamble
all bits of the MAC address, except clearing the second-least
significant bit. Thus, creating a burned-in address, globally
administered.

One can also supply a list of MAC addresses like
"FF:FF:FF:00:00:00 68:F7:28:00:00:00 00:0C:29:00:00:00 ..." in which
case a MAC address is choosen randomly.

To fully scamble the MAC address one can configure
"02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00".
which also randomly creates either a locally or globally administered
address.

With this, the following macchanger options can be implemented:

  `macchanger --random`
   This is the default if no mask is configured.
   -> ""
   while is the same as:
   -> "00:00:00:00:00:00"
   -> "02:00:00:00:00:00 02:00:00:00:00:00"

  `macchanger --random --bia`
   -> "02:00:00:00:00:00 00:00:00:00:00:00"

  `macchanger --ending`
   This option cannot be fully implemented, because macchanger
   uses the current MAC address but also implies --bia.
   -> "FF:FF:FF:00:00:00"
      This would yields the same result only if the current MAC address
      is already a burned-in address too. Otherwise, it has not the same
      effect as --ending.
   -> "FF:FF:FF:00:00:00 <MAC_ADDR>"
      Alternatively, instead of using the current MAC address,
      spell the OUI part out. But again, that is not really the
      same as macchanger does because you explictly have to name
      the OUI part to use.

  `machanger --another`
  `machanger --another_any`
  -> "FF:FF:FF:00:00:00 <MAC_ADDR> <MAC_ADDR> ..."
     "$(printf "FF:FF:FF:00:00:00 %s\n" "$(sed -n 's/^\([0-9a-fA-F][0-9a-fA-F]\) \([0-9a-fA-F][0-9a-fA-F]\) \([0-9a-fA-F][0-9a-fA-F]\) .*/\1:\2:\3:00:00:00/p' /usr/share/macchanger/wireless.list | xargs)")"
2016-06-30 08:32:50 +02:00
Thomas Haller
eb3247c097 core: fix comparing nm_setting_wired_get_mac_address() with permanent MAC address
`man nm-settings` says about ethernet.mac-address:

  If specified, this connection will only apply to the Ethernet device
  whose permanent MAC address matches.
2016-06-30 08:29:55 +02:00
Thomas Haller
dab657043c ifcfg-rh: explicitly clear HWADDR setting and others in write_wired_for_virtual()
When modifying an existing ifcfg-rh file, we always want to enforce
the absense of a certain setting. That is done, by calling svSetValue()
with a value of NULL.

Same for writing MTU value.
2016-06-30 08:29:54 +02:00
Thomas Haller
3f3ea1df21 libnm: add NMSettingConnection:stable-id property
This new property be used as token to generate stable-ids instead
of the connection's UUID.

Later, this will be used by ipv6.addr-gen-mode=stable-privacy,
ethernet.cloned-mac-address=stable, and wifi.cloned-mac-address=stable
setting. Those generate stable addresses based on the connection's
UUID, but allow to use the stable-id instead.

This allows multiple connections to generate the same addresses
-- on the same machine, because in the above cases a machine
dependant key is also hashed.
2016-06-30 08:29:54 +02:00
Thomas Haller
fa973afa19 tests: add macro NMTST_G_RETURN_MSG for expecting g_return*() failures
A failure to g_return*() by default prints a g_critical() with stringifing the
condition. Add a macro NMTST_G_RETURN_MSG() that reproduces that line to more
accurately match the failure message.
2016-06-09 12:03:39 +02:00
Beniamino Galvani
b5efd22c14 ifupdown/tests: fix memory leaks
Fix memory leaks in tests for the ifupdown plugin and re-enable valgrind.
2016-06-03 22:19:38 +02:00
Beniamino Galvani
963b72bccb ifnet: fix memory leaks
Fix memory leaks in ifnet plugin and tests, and re-enable valgrind for
tests.
2016-06-03 22:19:38 +02:00
Thomas Haller
8e54cfdb27 all: move NM_AUTH_PERMISSION_* defines to "nm-common-macros.h" header 2016-06-01 19:06:35 +02:00
Thomas Haller
eb6140a772 config: refactor change-flags to be a cause/reason which triggered the change
For the most part, this patch just renames some change-flags, but
doesn't change much about them. The new name should better express
what they are.

A config-change signal can be emitted for different reasons:
when we receive a signal (SIGHUP, SIGUSR1, SIGUSR2) or for internal
reasons like resetting of no-auto-default or setting internal
values.

Depending on the reason, we want to perform different actions.
For example:
 - we reload the configuration from disk on SIGHUP, but not for
   SIGUSR1.
 - For SIGUSR1 and SIGHUP, we want to update-dns, but not for SIGUSR2.

Another part of the change-flags encodes which part of the configuration
actually changed. Often, these parts can only change when re-reading
from disk (e.g. a SIGUSR1 will not change any configuration inside
NMConfig).

Later, we will have more causes, and accordingly more fine-grained
effects of what should be done on reload.
2016-06-01 19:06:34 +02:00
Lubomir Rintel
954d937b2f setting-ip6-config: add token property 2016-05-30 16:32:06 +02:00
Lubomir Rintel
d4831d3417 ifcfg-rh: drop IPV6_ADDR_GEN_MODE=stable-privacy when the mode is eui64 2016-05-30 16:14:04 +02:00
Thomas Haller
d7b4733d3e ifcfg-rh: avoid creating temporary string prefix for svGetValueFull() 2016-05-24 16:01:59 +02:00
Thomas Haller
5337003c4c core: drop NMConnectionProvider and use NMSettings directly
This is not C# but glib. Using interfaces is so cumbersome, that they
don't simplify code but make it more complicated.

E.g. following signals and its subscribers is complicated enough. It gets
more complicated by having NM_SETTINGS_SIGNAL_CONNECTION_ADDED and
NM_CP_SIGNAL_CONNECTION_ADDED. Of course, your favorite IDE has no idea
about glib interfaces, so figuring out who calls who gets more
complicated.

This undoes commit 4fe48b1273. Originally,
NMConnectionProvider had only one function get_best_connection(). But it
kept growing and more functions were added.

If we want to ~hide~ certain part of the NMSettings API, we should move them
to a separate header which gives internal access.
2016-05-24 12:35:58 +02:00
Thomas Haller
f20341a1fd core: drop interface function nm_connection_provider_get_best_connections()
... in favor of nm_settings_get_best_connections().
2016-05-24 12:35:58 +02:00
Thomas Haller
6e54057bf7 settings: add nm_settings_get_connections()
This will replace nm_connection_provider_get_connections(), but has
a different API.

Instead of returning a (const) GSList list, it returns a (cached) NULL
terminated array. The reason for this change is simply that I find
arrays more convenient to use (in this case) and it doesn't have the
overhead of a GSList instance per entry.

Like with nm_connection_provider_get_connections(), cache the result
internally. This for one is more convenient for the caller, which
doesn't need to free the result. On the other hand, the list of
connections is fairly static, this allows us to reuse the same list.
2016-05-24 12:35:58 +02:00
Thomas Haller
b4e8ce876d core: add nm_settings_get() singleton getter for NMSettings 2016-05-24 12:35:57 +02:00
Thomas Haller
c35164a6a3 settings/trivial: rename nm_settings_get_connections() to nm_settings_get_connections_sorted()
nm_settings_get_connections() returns a sorted list. We have many users
of nm_connection_provider_get_connection(), which returns the same result,
but undefined order.

Next NMConnectionProvider will be dropped. Thus, we don't want to
seamlessly replace nm_connection_provider_get_connection() by a sorted
version nm_settings_get_connections().

Rename nm_settings_get_connections() to make clear it is sorted.
2016-05-24 12:35:57 +02:00
Thomas Haller
a2c843499c all/tests: split core part out of "nm-test-utils.h"
A large part of "nm-test-utils.h" is only relevant for tests inside "src/"
directory, as they are helpers related to NetworkManager core part.

Split this part out of "nm-test-utils.h" header.
2016-05-17 16:48:52 +02:00
Thomas Haller
2d428bda35 ifcfg-rh: remove unused define ERR_GET_MSG() 2016-05-17 12:26:02 +02:00
Thomas Haller
4dcb5e5ba5 ifcfg-rh: cleanup includes
- don't include "nm-default.h" from headers. All source files
  include this header as first.

- drop G_BEGIN_DECLS/G_END_DECLS. This is not C++ nor public
  API.

- drop unnecessary includes from header files. They are either
  not required, or already provided via "nm-default.h".

- include in source files the corresponding header file as first
  after "nm-default.h". This should ensure that header files are
  self-contained (appart from "nm-default.h").
2016-05-17 12:25:55 +02:00
Thomas Haller
b503b37636 ifcfg-rh: don't print warning in svGetValueInt64()
Having a simple accessor print warnings is not nice. At that point there
is no context as to why we are trying to read the value.

Note that the function already handles and expects invalid values, it's
just not clear that printing warnings from a utility function is the right
thing to do.

Just ignore such cases silently (at this point). It's up to the caller
to print a warning or whatever.
2016-05-17 12:22:42 +02:00
Thomas Haller
f3bd778d6d ifcfg-rh: use _NMLOG() macro in writer
This gives every logging line a proper "ifcfg-rh" prefix.
But drop the "    " prefixes.
2016-05-17 12:22:42 +02:00
Thomas Haller
a519cc57b8 ifcfg-rh: use _NMLOG() macro in reader
This gives every logging line a proper "ifcfg-rh" prefix.
2016-05-17 12:22:42 +02:00
Thomas Haller
c949e1c429 ifcfg-rh: reject vlan id of value 4096
Maybe we should also reject 0 and 4095, but for now leave it.
2016-05-17 12:22:42 +02:00
Thomas Haller
a85c3db2f0 ifcfg-rh: use _nm_utils_ascii_str_to_int64() instead of strtol() 2016-05-17 12:22:42 +02:00
Thomas Haller
4b538ea8f1 ifcfg-rh: replace uses of get_int() 2016-05-17 12:22:42 +02:00
Thomas Haller
7328613d7b ifcfg-rh: don't use get_int() to parse MTU value
And print a warning also if the value is out of range.
2016-05-17 12:22:41 +02:00
Thomas Haller
ec639b5c63 ifcfg-rh: cast variadic arguments to proper int type 2016-05-17 12:22:41 +02:00
Thomas Haller
8e6d619c46 ifcfg-rh: use _nm_utils_ascii_str_to_int64() in reader's get_uint()/get_int() functions 2016-05-17 12:22:41 +02:00
Thomas Haller
7961e1bb8a core: add nm_connection_provider_get_unmanaged_specs() 2016-05-17 11:54:08 +02:00
Beniamino Galvani
c5f17531b9 ifcfg-rh: add support for DNS priority 2016-05-12 17:13:50 +02:00
Joel Holdsworth
8606060121 settings: Follow symbolic link when installing file monitor
https://bugzilla.gnome.org/show_bug.cgi?id=765645
2016-05-12 15:24:11 +02:00
Thomas Haller
6c2130382a session-monitor: remove wrapper functions to connect/disconnect signal
We don't add such wrappers anywhere else, and I think they are not
desired style.

Also, keep the signal-id in a "gulong session_changed_id", instead of
guint.
2016-05-12 09:50:21 +02:00
Thomas Haller
c5ac691744 build: cleanup includes of <gmodule.h>
<gmodule.h> is implicitly included by <gio/gio.h> which is available
everywhere. For that reason, we would not have to include this header
at all. However, it is recommended to explicitly include <gmodule.h>
where needed.

So, include it where needed -- if <gio/gio.h> wouldn't be there --
and drop it from where it is not needed.
2016-04-30 03:42:16 +02:00
Thomas Haller
c6a92224a4 settings: don't unload settings plugins on failure
Also, registering a weak-pointer to close the module that
was just made as resident is pointless.
2016-04-29 15:48:18 +02:00
Lubomir Rintel
76844c65d6 ifupdown: avoid calloc()
It can return NULL and makes Coverity upset:

CID 75369 (#1 of 1): Dereference null return value (NULL_RETURNS)
4.  dereference: Dereferencing a null pointer ret.
2016-04-29 12:47:34 +02:00
Lubomir Rintel
2e563d9c84 ifnet: fix error handling
CID 76722 (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
g_set_error(error, nm_setti....
2016-04-29 12:47:34 +02:00
Beniamino Galvani
5b70254ea0 ifcfg-rh: emit a warning when DEFROUTE=no and GATEWAY is set 2016-04-27 17:15:49 +02:00
Thomas Haller
7f7e1eb60b settings: fix write_hostname for relative-symbolic links
g_file_read_link() "reads" the symbolic link. If it's a relative path,
we get a relative path which is anchored on @file. We must resolve that
to be absolute.
2016-04-27 15:03:50 +02:00
Thomas Haller
d6e7fa164b settings: remove unnecessary "file" field for hostname from NMSettingPrivate 2016-04-27 14:51:55 +02:00
Francesco Giudici
19350c8975 settings: add notification after connections load
The notification was missing from a long time. The issue has been exposed only
now due to the c57e5a6b66 fix which properly
implemented the "startup-complete" notification substituting out of place code
which masked the bug.
2016-04-27 11:10:58 +02:00
Thomas Haller
767fa0ed3d settings: disconnect connection_ready_changed() handler when reaching startup_complete
We connect to notify::startup-complete signal of each connection,
but after we signal startup-complete once, we don't need that
signal anymore. Disconnect.
2016-04-26 15:48:20 +02:00
Thomas Haller
89cf9429a7 device: generate stable UUID for default-wired-connection
Generate a stable connection UUID for the default-wired-connection.
Otherwise, on every reboot, the UUID changes although the generated
connection is the same.

But also hash into the UUID the machine-id, the device name and the
hardware address. So, the UUID is only the same if the connection is
identical in every aspect.

Also, the UUID is used as Network_ID for the stable-privacy address
generation mode. It is bad to re-create different UUIDs on every boot
as it causes different addresses.
2016-04-26 12:50:16 +02:00
Thomas Haller
316359d8b6 settings: refactor read_hostname_*() 2016-04-25 15:26:26 +02:00