Commit graph

1802 commits

Author SHA1 Message Date
Thomas Haller
866ac505a8 libnm,core: various cleanups of _nm_connection_for_each_secret()
- use cleanup attribute to free memory

- return floating reference from _nm_connection_for_each_secret().
  It's more idiomatic that a function that constructs a variant and
  returns it, returns a floating variant.
2019-02-04 20:15:20 +01:00
Thomas Haller
79a0238c5e libnm,core: move _nm_connection_for_each_secret() from core to libnm-core
_nm_connection_for_each_secret() (formerly for_each_secret()) and
_nm_connection_find_secret() (formerly find_secret()) operate on a
GVariant of secrets. For that, they implement certain assumptions
of how to handle secrets. For example, it must special-case VPN settings,
because there is no generic abstraction to handle regular secret and VPN
secrets the same.

Such special casing should only be done in libnm-core, at one place.

Move the code to libnm-core as internal API.
2019-02-04 20:15:20 +01:00
Thomas Haller
4ea6c83e9b settings: fix handling of VPN secrets in for_each_secret()
nm_setting_get_secret_flags() looks whether we have a suitable "-flags"
data value, or whether we have a secret with that name.

In fact, we know this is a valid secret-name. Even if there are no secret-flags
and the secret (currently) does not exists. We shall not care about the
return value.

Note that nm_setting_get_secret_flags() also for non-secrets will set
the flags to "NONE", which is just what we need.
2019-02-04 20:15:20 +01:00
Thomas Haller
5eac241578 settings: fix for_each_secret() to check variant type of VPN secrets
We cannot just blindly assume that the variant is of the right type
to iterate over it.
2019-02-04 20:15:20 +01:00
Thomas Haller
cabc1ddca5 settings: fix leaking variant in for_each_secret()
Fixes: df6706813a
2019-02-04 20:15:20 +01:00
Thomas Haller
c7b3c23af2 ifcfg-rh/tests: avoid duplicate const warning for NO_EXPECTED
../src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c:126:19: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
     static const char const NO_EXPECTED[1];
                       ^~~~~

Fixes: f04bf45e84
2019-02-04 16:55:43 +01:00
Rafael Fontenelle
d81e10942f all: fix misspellings
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/64
2019-01-24 17:19:44 +01:00
Thomas Haller
7771473f46 libnm,core: add _nm_connection_aggregate() to replace nm_connection_for_each_setting_value()
We should no longer use nm_connection_for_each_setting_value() and
nm_setting_for_each_value(). It's fundamentally broken as it does
not work with properties that are not backed by a GObject property
and it cannot be fixed because it is public API.

Add an internal function _nm_connection_aggregate() to replace it.

Compare the implementation of the aggregation functionality inside
libnm with the previous two checks for secret-flags that it replaces:

- previous approach broke abstraction and require detailed knowledge of
  secret flags. Meaning, they must special case NMSettingVpn and
  GObject-property based secrets.
  If we implement a new way for implementing secrets (like we will need
  for WireGuard), then this the new way should only affect libnm-core,
  not require changes elsewhere.

- it's very inefficient to itereate over all settings. It involves
  cloning and sorting the list of settings, and retrieve and clone all
  GObject properties. Only to look at secret properties alone.

_nm_connection_aggregate() is supposed to be more flexible then just
the two new aggregate types that perform a "find-any" search. The
@arg argument and boolean return value can suffice to implement
different aggregation types in the future.

Also fixes the check of NMAgentManager for secret flags for VPNs
(NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS). A secret for VPNs
is a property that either has a secret or a secret-flag. The previous
implementation would only look at present secrets and
check their flags. It wouldn't check secret-flags that are
NM_SETTING_SECRET_FLAG_NONE, but have no secret.
2019-01-07 10:54:28 +01:00
Thomas Haller
b54d695e98 libnm/gtk-doc: fix transfer-none annotation for nm_settings_get_connections()
Fixes: 6e54057bf7
2018-12-30 15:17:11 +01:00
Iñigo Martínez
35171b3c3f build: meson: Add trailing commas
Add missing trailing commas that avoids getting noise when another
file/parameter is added and eases reviewing changes[0].

[0] https://gitlab.gnome.org/GNOME/dconf/merge_requests/11#note_291585
2018-12-20 13:50:34 +01:00
Thomas Haller
a51c09dc12 all: don't use static buffer for nm_utils_inet*_ntop()
While nm_utils_inet*_ntop() accepts a %NULL buffer to fallback
to a static buffer, don't do that.

I find the possibility of using a static buffer here error prone
and something that should be avoided. There is of course the downside,
that in some cases it requires an additional line of code to allocate
the buffer on the stack as auto-variable.
2018-12-19 09:23:08 +01:00
Aleksander Morgado
6ed21e8342 settings,gsm: deprecate and stop using 'number' property
The 'number' property in GSM settings is a legacy thing that comes
from when ModemManager used user-provided numbers, if any, to connect
3GPP modems.

Since ModemManager 1.0, this property is completely unused for 3GPP
modems, and so it doesn't make sense to use it in the NetworkManager
settings. Ofono does not use it either.

For AT+PPP-based 3GPP modems, the 'number' to call to establish the
data connection is decided by ModemManager itself, e.g. for standard
GSM/UMTS/LTE modems it will connect a given predefined PDP context,
and for other modems like Iridium it will have the number to call
hardcoded in the plugin itself.

https://github.com/NetworkManager/NetworkManager/pull/261
2018-12-19 08:54:50 +01:00
Beniamino Galvani
0819563e01 ifcfg-rh: fix reading SR-IOV settings
Fixes: d48f389cbf
2018-12-13 18:06:43 +01:00
Beniamino Galvani
a3383726dc settings: apply agent-owned secrets from the new connection on update
When updating a connection passing agent-owned secret, they are lost
from @reread_connection after the settings-plugin persists the
connection. Therefore we need to cache and reapply them separately to
the connection so that they can be saved to secret agents later.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/82
2018-12-13 11:14:21 +01:00
Beniamino Galvani
d48f389cbf ifcfg-rh: fix persisting sriov setting
The writer should write all properties of the sriov setting when the
setting exists without additional logic. Likewise, the reader should
instantiate a sriov setting when any sriov key is present and blindly
set properties from keys.

The old code did not always preserve the presence of a sriov setting
after a write/read cycle.

Fixes: c02d1c488f
2018-12-12 14:20:32 +01:00
Beniamino Galvani
769e0726a8 cli: strictly validate SR-IOV attributes
Report an error when the user tries to add an unknown attribute
instead of silently accepting (and ignoring) it.

Note that this commit also changes the behavior of public API
nm_utils_sriov_vf_from_str() to return an error when an unknown
attribute is found. I think the previous behavior was buggy as wrong
attributes were simply ignored without any way for the user to know.

Fixes: a9b4532fa7
2018-12-12 14:18:53 +01:00
Thomas Haller
3fc5765e1b keyfile: add helper functions to record loaded UUID files
This code will be used later.

We want to remember which keyfiles are currently loaded (or hidden).

With the addition or multiple keyfile directories (soon), there are
two cases where this matters:

 - if there are multiple keyfiles which reference the same UUID,
   we can only load one of them. That is already a problem today
   with only one keyfile directory, where multiple files can reference
   the same UUID.
   The implementation will pick the file based on priorities (like
   the file modification date). However, the user may call explicitly
   call `nmcli connection load`. In that case, we cannot reload
   all files to find out whether the to be loaded file is hidden
   according to the defined priorities. We cannot do that, because we
   must not make decisions based on files on disk, which we are not told
   to reload. So, during a `nmcli connection load` we must look at
   unrelated files, to determine how to load the file.
   Instead, we do allow the user to load any file, even if it would be
   shadowed by other files. When we do that, we may want to persist which
   file is currently loaded, so that a service restart and a `nmcli connection
   reload` does not undo the load again. This can be later later be solved by
   writing a symlink

       "/var/run/NetworkManager/system-connections/.loaded-$UUID.nmkeyfile"

   which targets the currently active file.

 - if a profile was loaded from read-only persistant storage, the user
   may still delete the profile. We also need to remember the deletion
   of the file. That will be achieved by symlinking "/dev/null" as
   "/etc/NetworkManager/system-connections/.loaded-$UUID.nmkeyfile".

Add helper functions to read and write these symlinks.
2018-12-03 12:09:57 +01:00
Thomas Haller
f7de10ac83 keyfile: cleanup nm_keyfile_utils_ignore_filename() 2018-12-03 12:09:57 +01:00
Thomas Haller
4d8ce80e78 keyfile/tests: add tests for ignoring keyfile filenames
In particular, have a full path (with slashes), and a filename
with trailing slash (a directory).
2018-12-03 12:09:57 +01:00
Lubomir Rintel
b385ad0159 all: say Wi-Fi instead of "wifi" or "WiFi"
Correct the spelling across the *entire* tree, including translations,
comments, etc. It's easier that way.

Even the places where it's not exposed to the user, such as tests, so
that we learn how is it spelled correctly.
2018-11-29 17:53:35 +01:00
Michael Biebl
8179b23d76 settings/ifupdown: fix block_name typo in initialize()
In commit f0938948bc a typo creeped in and
"block->name" got replaced by "block_name". Variable block_name is used
for a different purpose and not initialized at this point.
As a result g_str_has_prefix crashes with a segfault.

Spotted by Bernhard Übelacker <bernhardu@mailbox.org>

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911621
Fixes: f0938948bc

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/31
2018-10-23 22:58:44 +02:00
Thomas Haller
d49e88f716 Revert "keyfile: drop with_extension argument from _internal_write_connection()"
For upstream, we changed behavior here. However, I think certain
downstream don't want to do that, and revert patch "d37ad15f12 keyfile:
also add ".nmconnection" extension when writing keyfiles in /etc".

For that to make easier, keep the upstream sources closer to what
was. Revert.

This reverts commit e93d8cdb74.
2018-10-23 13:46:14 +02:00
Thomas Haller
83acb40a86 keyfile: move and rename NM_CONFIG_KEYFILE_PATH_DEFAULT define 2018-10-23 10:37:33 +02:00
Thomas Haller
e93d8cdb74 keyfile: drop with_extension argument from _internal_write_connection()
For non-test code, we always passed TRUE.

For test code, setting with_extension is fine too, so drop the
argument.
2018-10-23 10:37:33 +02:00
Thomas Haller
c36b5236b6 keyfile/trivial: rename keyfile related functions
NM_CONFIG_KEYFILE_PATH_IN_MEMORY is now called NMS_KEYFILE_PATH_NAME_RUN.
This name seems odd in the current context, it will be more suitable
when we also have NMS_KEYFILE_PATH_NAME_LIB (for /usr/lib).
2018-10-23 10:36:18 +02:00
Thomas Haller
410664967b keyfile: move keyfile utilities from src/ to libnm-core/
These utilities are concerned with valid file names (as NetworkManager
daemon requires it). This is relevant for everybody who wants to write
keyfile files directly. Hence, move it to libnm-core. Still as internal
API.
2018-10-23 10:36:07 +02:00
Thomas Haller
3c58fc1122 core: use nm_utils_file_is_in_path() for checking paths
For one, re-use the helper function instead of re-implementing
the check at multiple places.

Also, with this duplicate path separators are accepted.
2018-10-23 10:32:53 +02:00
Thomas Haller
43b28e06ed test/meson: increase timeout for some tests
During gitlab-ci, some tests may take a long time. Increase
the default timeout.
2018-10-22 16:16:52 +02:00
Thomas Haller
d37ad15f12 keyfile: also add ".nmconnection" extension when writing keyfiles in /etc
This is a change in behavior regarding the filename that we choose when
writing files to "/etc/NetworkManager/system-connections/".
2018-10-19 15:17:51 +02:00
Thomas Haller
648c256b90 keyfile: write keyfiles to "/run" directory with ".nmconnection" file suffix
For profiles in "/etc/NetworkManager/system-connections", we did not enforce
that the keyfiles have a special suffix, nor did we generate the
filenames in such a manner. In hindsight, I think that was a mistake.

Recently we added "/run/NetworkManager/system-connections" as additional
keyfile directory. Enforce a suffix and write keyfiles with such a name.

In principle, we could also start writing keyfiles in /etc with the
same suffix. But let's not do that, because we anyway cannot enforce
it.

An ugly part is, that during `nmcli connection load` we need to
determine whether the to-be-loaded connection is under /etc or /run.
Preferably, we would allow any kind of symlinking as what matters
is the file object (inode) and not the path. Anyway, we don't do
that but compare plain paths. That means, paths which are not
in an expected form, will be rejected. In particular, the paths
starting with "/run/..." and "/var/run/..." will be treated differently,
and one of them will be rejected.

Note that ifcfg-rh plugin strictly enforces that the path
starts with IFCFG_DIR as well. So, while this is a breaking
change for keyfile, I think it's reasonable.
2018-10-18 18:34:19 +02:00
Lubomir Rintel
02958bba80 all: remove \n endings from log calls
The extra newlines look bad when logging to the console.

https://github.com/NetworkManager/NetworkManager/pull/223
2018-10-12 14:34:58 +02:00
Thomas Haller
8de09bb119 keyfile/tests: drop unused variables
Fixes: e886e5364e
2018-10-10 12:38:33 +02:00
Thomas Haller
837d44ffa4 keyfile: split automatically setting ID/UUID for keyfile
keyfile already supports omitting the "connection.id" and
"connection.uuid". In that case, the ID would be taken from the
keyfile's name, and the UUID was generated by md5 hashing the
full filename.

No longer do this during nm_keyfile_read(), instead let all
callers call nm_keyfile_read_ensure_*() to their liking. This is done
for two reasons:

 - a minor reason is, that one day we want to expose keyfile API
   as public API. That means, we also want to read keyfiles from
   stdin, where there is no filename available. The implementation
   which parses stdio needs to define their own way of auto-generating
   ID and UUID. Note how nm_keyfile_read()'s API no longer takes a
   filename as argument, which would be awkward for the stdin case.

 - Currently, we only support one keyfile directory, which (configurably)
   is "/etc/NetworkManager/system-connections".
   In the future, we want to support multiple keyfile dirctories, like
   "/var/run/NetworkManager/profiles" or "/usr/lib/NetworkManager/profiles".
   Here we want that a file "foo" (which does not specify a UUID) gets the
   same UUID regardless of the directory it is in. That seems better, because
   then the UUID won't change as you move the file between directories.
   Yes, that means, that the same UUID will be provided by multiple
   files, but NetworkManager must already cope with that situation anyway.
   Unfortunately, the UUID generation scheme hashes the full path. That
   means, we must hash the path name of the file "foo" inside the
   original "system-connections" directory.
   Refactor the code so that it accounds for a difference between the
   filename of the keyfile, and the profile_dir used for generating
   the UUID.
2018-10-04 11:03:23 +02:00
Thomas Haller
2e5985f2e9 keyfile: refactor check whether filename starts with a dot
check_prefix() was only ever called with "." as prefix.
Simplify the implementation to explicitly check for a leading
dot.
2018-10-04 10:58:50 +02:00
Thomas Haller
345c91a0a4 keyfile: move file permission check of keyfile to helper function 2018-10-04 10:58:50 +02:00
Thomas Haller
2e0a95530f keyfile/tests: assert against auto generated UUID for keyfile
The algorithm for generating the UUID must be stable. Assert
against that.
2018-10-04 10:58:50 +02:00
Thomas Haller
e886e5364e keyfile/tests: refactor loading of keyfiles in tests 2018-10-04 10:58:50 +02:00
Thomas Haller
be6c7fa5f6 libnm: cleanup _nm_utils_hexstr2bin*() helper
Add 3 variants of _nm_utils_hexstr2bin*():

  - _nm_utils_hexstr2bin_full(), which takes a preallocated
    buffer and fills it.
  - _nm_utils_hexstr2bin_alloc() which returns a malloc'ed
    buffer
  - _nm_utils_hexstr2bin_buf(), which fills a preallocated
    buffer of a specific size.
2018-09-30 16:13:42 +02:00
Thomas Haller
6714440669 all/trivial: rename hexstr<>bin conversion functions
"bin2str" and "str2bin" are not very clear. These strings are
hex-strings. Rename.
2018-09-30 13:33:46 +02:00
Beniamino Galvani
34ffd9fcab build: meson: install ifcfg-rh files and directory 2018-09-28 17:25:46 +02:00
Thomas Haller
793afb7d95 core: improve logging why startup-complete is blocked
Before:

    "manager: check_if_startup_complete returns FALSE because of eth0"

Now:

    "manager: startup complete is waiting for device 'eth0' (autoactivate)"

Also, the logging line is now more a human readable sentence, but still
follows the same pattern as later

    "manager: startup complete"

Meaning: grepping for "startup complete" becomes more helpful because
one first finds the reasons why startup-complete is not yet reached,
followed by the moment when it is reached.
2018-09-19 17:51:01 +02:00
Lubomir Rintel
b64ae759ad settings/ifupdown/tests: avoid asserting on an array
char[] is not a char *; it can not go NULL.

  test-ifupdown.c:147:27: error: address of array 'n->name' will always evaluate
                                 to 'true' [-Werror,-Wpointer-bool-conversion]
                g_assert (b->name && n->name);
  test-ifupdown.c:156:27: error: address of array 'm->key' will always evaluate
                                 to 'true' [-Werror,-Wpointer-bool-conversion]
                        g_assert (k->key && m->key);
2018-09-19 14:28:08 +02:00
Lubomir Rintel
c263f5355c config: add --configure-and-quit=initrd mode
We need a mode that:

* doesn't leave processes behind
* doesn't force an internal dhclient
* doesn't auto-generate default connections
* doesn't write out files into libdir, only /run

The original configure-and-quit mode doesn't really fit the initrd use. But
it's proobably not a good idea to just change its behavior.
2018-09-18 17:40:47 +02:00
Lubomir Rintel
ce4dbd7daf keyfile: write in-memory connections to /run
This is useful for in-memory connections to persist NetworkManager
restarts (as opposed to machine restarts).

Perhaps most improtantly, this allows generating in-memory connections outside
NetworkManager, e.g. passing configuration from early boot firmware in initrd.

Note that this does *not* aspire to do more than it says on the tin:
Notably, it doesn't touch the problem of provisioning connections in multiple
persistent connection directories and thus doesn't have to deal with the
problem of deleting or overlaying the connections tha (rh #772414) deals
with.
2018-09-18 17:40:47 +02:00
Thomas Haller
0b3197a3fd shared: let nm_utils_parse_inaddr_bin() return the detected address family
As we accept addr_family %AF_UNSPEC to detect the address family,
we also need to return it. Just returning the binary address without
the address family makes no sense.
2018-09-17 14:52:54 +02:00
luz.paz
f985b6944a docs: misc. typos
Found via `codespell -q 3 --skip="*.po"`

https://github.com/NetworkManager/NetworkManager/pull/203
2018-09-15 09:08:03 +02:00
Thomas Haller
fe866fbeb3 libnm: drop API nm_connection_get_setting_{6lowpan,sriov,wpan}()
Note that NMSettingEthtool and NMSettingMatch don't have such
functions either.

We have API

  nm_connection_get_setting (NMConnection *, GType)
  nm_connection_get_setting_by_name (NMConnection *, const char *)

which can be used generically, meaning: the requested setting type
is an argument to the function. That is generally more useful and
flexible.

Don't add API which duplicates existing functionality and is (arguably)
inferiour. Drop it now. This is an ABI/API break for the current development
cycle where the 1.14.0 API is still unstable. Indeed it's already after
1.14-rc1, which is ugly. But it's also unlikely that somebody already uses
this API/ABI and is badly impacted by this change.

Note that nm_connection_get_setting() and nm_connection_get_setting_by_name()
are slightly inconvenient in C still, because they usually require a cast.
We should fix that by changing the return type to "void *". Such
a change may be possibly any time without breaking API/ABI (almost, it'd
be an API change when taking a function pointer without casting).

(cherry picked from commit a10156f516)
2018-09-14 16:30:51 +02:00
Beniamino Galvani
6220bae2d3 ifcfg-rh: fix build with meson
The shared object was missing some files.

(cherry picked from commit bd556c8937)
2018-09-13 14:35:22 +02:00
Beniamino Galvani
44d77a7476 ifcfg-rh: add support for connection.llmnr 2018-09-06 09:07:41 +02:00
Thomas Haller
3091ffa50a settings/ifupdown: use _NMLOG() macros for logging
Does not address the issues that the existing logging is much too verbose
and does not provide necessary context for what it's complaining. The
logging messages should be improved.

At least, the logging macro gives all messages a "ifupdown: " prefix.
2018-09-06 07:41:22 +02:00