Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
105254a15b libnm/crypto: rework _nm_crypto_verify_cert() to return boolean
Rename _nm_crypto_verify_cert() to _nm_crypto_verify_x509().
Also, don't let it return a NMCryptoFileFormat result. This
function only checks for a particular format, hence it
should only return true/false.

Also, fix setting error output argument when the function fails.
2018-09-04 07:38:30 +02:00
Thomas Haller
6b8280f6a9 build/travis: build both against crypto "gnutls" and "nss"
We already do matrix-builds with autotools|meson and gcc|clang.

Make the selected crypto backend depending on the compiler, so
that we get more coverage.
2018-09-04 07:38:30 +02:00
Thomas Haller
e01f7f2c6d build: enable building both crypto backends for tests
If the library is available, let's at least compile both
crypto backends.

That is helpful when developing on crypto backends, so that
one does not have to configure the build twice.

With autotools, the build is only run during `make check`.
Not for meson, but that is generally the case with our meson
setup, that it also builds tests during the regular build step.
2018-09-04 07:38:30 +02:00
Thomas Haller
c172675c13 libnm/crypto: rename libnm crypto API to have consistent NM prefix
Follow our convention, that items in headers are all named with
an "NM" prefix.

Also, "nm-crypto-impl.h" contains internal functions that are to be implemented
by the corresponding crypto backends. Distinguish their names as well.
2018-09-04 07:38:30 +02:00
Thomas Haller
6435040881 libnm/crypto: add header "nm-crypto-impl.h" for crypto implementation
There are two aspects: the public crypto API that is provided by
"nm-crypto.h" header, and the internal header which crypto backends
need to implement. Split them.
2018-09-04 07:38:30 +02:00
Thomas Haller
4106f2968d libnm/crypto: rename libnm's crypto files
"crypto.h" did not follow our common NM style naming. Rename
the files.
2018-09-04 07:38:30 +02:00
Thomas Haller
3c157d186c libnm/crypto: refactor decrypt_key() to use NMSecretPtr 2018-09-04 07:38:30 +02:00
Thomas Haller
eef298108f libnm/crypto: refactor parse_pkcs8_key_file() to bzero loaded data 2018-09-04 07:38:30 +02:00
Thomas Haller
6550b36ed4 libnm/crypto: refactor parse_old_openssl_key_file() to bzero loaded data
Ensure that data processed by parse_old_openssl_key_file() is cleared
from memory.
2018-09-04 07:38:30 +02:00
Thomas Haller
09d43b3959 libnm/crypto: clear data loaded from files
Data that we load from crypto files should be cleared once it's
no longer used.

Just a small step. There are many other places where we copy the data
and leave it around.
2018-09-04 07:38:30 +02:00
Thomas Haller
fbc0f599bc libnm/crypto: rename crypto functions that are only used by tests
These functions are only used by tests, hence they are much less important.
Mark them as such, by naming them accordingly.
2018-09-04 07:38:30 +02:00
Thomas Haller
5ff12dc86d libnm/crypto: cleanup convert_iv() and handle more errors
crypto_make_des_aes_key() asserts that iv-lenght is at least
8 characters. Whatever the reason. That means, decrypt_key()
must check for that condition first, and gracefully fail.

Also, don't use strtol() to convert a pair of hex digits to
integer.

Also, don't keep the IV in memory. Yes, it's not very critical,
but this is crypto code, we should not leave data behind.
2018-09-04 07:38:30 +02:00
Thomas Haller
9ca12145a3 libnm/crypto: adjust argument types for crypto_md5_hash()
There should be a clear distinction between whether an array
is a NUL terminated string or binary with a length.

crypto_md5_hash() is already complicated enough. Adjust it's
API to only support binary arguments, and thus have "guint8 *" type.
2018-09-04 07:38:30 +02:00
Thomas Haller
3f7db94ffb libnm/crypto: cleanup error paths and use cleanup-attribute 2018-09-04 07:38:30 +02:00
Thomas Haller
3536960eb7 libnm/crypto: minor cleanup confusing comment in crypto_decrypt_openssl_private_key_data()
the comment and code made it sound like parse_old_openssl_key_file() would
set @key_type if the parsing was only done partially. That is not the case,
@key_type is only set, if parsing was successful. Adjust the code.

While at it, don't require the caller to initialize @out_key_type. It's
just an enum, if we care to always set it, just do it.
2018-09-04 07:38:30 +02:00
Thomas Haller
c366c155f1 shared: rename PROP_0 in NM_GOBJECT_PROPERTIES_DEFINE() and skip it in nm_gobject_notify_together()
PROP_0 is how we commonly name this property when we don't use
NM_GOBJECT_PROPERTIES_DEFINE(). Rename it.

Also, allow to skip PROP_0 in nm_gobject_notify_together(), that
is handy to optionally invoke a notification, like

  nm_gobject_notify_together (obj,
                              PROP_SOMETHING,
                              changed ? PROP_OTHER : PROP_0);
2018-09-04 07:38:30 +02:00
Thomas Haller
ff163d9d0d shared: move file-get-contents and file-set-contents helper to shared/
These functions are not specific to "src/". Also, they will be needed
by outside of "src/" soon.
2018-09-04 07:38:30 +02:00
Thomas Haller
6ee7453bc1 shared: add "nm-io-utils.h" 2018-09-04 07:38:30 +02:00
Thomas Haller
6b813b904f core: extend nm_utils_*_get_contents() to zero temporary memory
When reading a file, we may allocate intermediate buffers (realloc()).
Also, reading might fail halfway through the process.

Add a new flag that makes sure that this memory is cleared. The
point is when reading secrets, that we don't accidentally leave
private sensitive material in memory.
2018-09-04 07:38:30 +02:00
Thomas Haller
c5c0ffdfd0 shared: add nm_gbytes_equal0() helper
Like g_bytes_equal(), except that it accepts %NULL arguments.
2018-09-04 07:38:30 +02:00
Thomas Haller
4c4c85eab0 shared: add _NM_INT_NOT_NEGATIVE() helper 2018-09-04 07:38:30 +02:00
Thomas Haller
5bb8e2fa4d shared: add nm_utils_hexchar_to_int() 2018-09-04 07:38:30 +02:00
Thomas Haller
b232508707 shared: add nm-secret-utils.h helper
We already had nm_free_secret() to clear the secret out
of a NUL terminated string. That works well for secrets
which are strings, it can be used with a cleanup attribute
(nm_auto_free_secret) and as a cleanup function for a
GBytes.

However, it does not work for secrets which are binary.
For those, we must also track the length of the allocated
data and clear it.

Add two new structs NMSecretPtr and NMSecretBuf to help
with that.
2018-09-04 07:38:30 +02:00
Thomas Haller
74815fd8e0 shared: drop unnecessary NM_AUTO_DEFINE_FCN_STRUCT() macro
It serves no purpose, as it just directly calls the function. We don't
need to define this intermediary.
2018-09-04 07:38:30 +02:00
Thomas Haller
f15d82bc91 shared: add nm_auto_unref_bytearray macro
Internally, GByteArray is actually a GArray, so it would be safe to
use "gs_unref_array" macro. However, that is rather ugly, and means
to rely on an internal implementation detail of GByteArray.

Instead, add a cleanup macro for GByteArray.
2018-09-04 07:38:30 +02:00
Thomas Haller
fcf254c03a libnm/keyfile: fix double free in keyfile's get_bytes()
Fixes: 5e7b14af03
2018-09-04 07:38:30 +02:00
Thomas Haller
98ca7022e3 libnm: fix leaking private-key in nm_setting_802_1x_set_phase2_private_key() 2018-09-04 07:38:30 +02:00
Thomas Haller
5ef81dc0fb contrib/rpm: change default DHCP plugin to internal
... but keep "dhclient" on Fedora and RHEL <= 7.

https://bugzilla.redhat.com/show_bug.cgi?id=1571655
2018-09-03 21:23:47 +02:00
Thomas Haller
5d3f8a11dd all: merge branch 'th/gbytes_equal_mem'
https://github.com/NetworkManager/NetworkManager/pull/188
2018-08-30 14:44:43 +02:00
Thomas Haller
b8a57fb272 libnm-core: remove unused utlity functions for GSList
I think GSList is not a great data type. Most of the time when we used
it, we better had choosen another data type.

These utility functions were unused, and I think we should use GSList
less.

Drop them.
2018-08-30 11:17:09 +02:00
Thomas Haller
dd4a6f307c tests: minor code cleanup in tests
Use nmtst_assert_success(), nm_auto() macros, and minor
cleanups.
2018-08-30 11:17:09 +02:00
Thomas Haller
1b448aeb30 all: use nm_utils_gbytes_equal_mem() 2018-08-30 11:17:09 +02:00
Thomas Haller
f38cbce653 shared: add nm_utils_gbytes_equal_mem() util 2018-08-30 11:17:09 +02:00
Dingzhong Chen
dc4db093c7 po: update Chinese (zh_CN) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/10
2018-08-30 07:35:17 +02:00
Thomas Haller
d17d26887c core: merge branch 'th/settings-delegate-connection'
https://github.com/NetworkManager/NetworkManager/pull/184
2018-08-28 22:29:45 +02:00
Thomas Haller
38273a8871 settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).

NMSettingsConnection does a lot of things already:

  1) it "is-a" NMDBusObject and exports the API of a connection profile
     on D-Bus
  2) it interacts with NMSettings and contains functionality
     for tracking the profiles.
  3) it is the base-class of types like NMSKeyfileConnection and
     NMIfcfgConnection. These handle how the profile is persisted
     on disk.
  4) it implements NMConnection interface, to itself track the
     settings of the profile.

3) and 4) would be better implemented via delegation than inheritance.

Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.

Advantages:

  - by delegating, there is a clearer separation of what
    NMSettingsConnection does. For example, in C we often required
    casts from NMSettingsConnection to NMConnection. NMConnection
    is a very trivial object with very little logic. When we have
    a NMConnection instance at hand, it's good to know that it is
    *only* that simple instead of also being an entire
    NMSettingsConnection instance.

    The main purpose of this patch is to simplify the code by separating
    the NMConnection from the NMSettingsConnection. We should generally
    be aware whether we handle a NMSettingsConnection or a trivial
    NMConnection instance. Now, because NMSettingsConnection no longer
    "is-a" NMConnection, this distinction is apparent.

  - NMConnection is implemented as an interface and we create
    NMSimpleConnection instances whenever we need a real instance.
    In GLib, interfaces have a performance overhead, that we needlessly
    pay all the time. With this change, we no longer require
    NMConnection to be an interface. Thus, in the future we could compile
    a version of libnm-core for the daemon, where NMConnection is not an
    interface but a GObject implementation akin to NMSimpleConnection.

  - In the previous implementation, we cannot treat NMConnection immutable
    and copy-on-write.
    For example, when NMDevice needs a snapshot of the activated
    profile as applied-connection, all it can do is clone the entire
    NMSettingsConnection as a NMSimpleConnection.
    Likewise, when we get a NMConnection instance and want to keep
    a reference to it, we cannot do that, because we never know
    who also references and modifies the instance.
    By separating NMSettingsConnection we could in the future have
    NMConnection immutable and copy-on-write, to avoid all unnecessary
    clones.
2018-08-28 22:27:55 +02:00
Thomas Haller
3a99c343d8 device: don't limit try count in nm_device_ethernet_utils_get_default_wired_name()
The limit of trying up to 10000 was arbitrary. In practice, we are not expected
that we need that many searches. If that would be the case (and we would have
10000 conflicting connections that take all the names), then we anyway would
need to refactor the code not to scale with O(n^2).

Replace the arbitrary limit with an even larger one. The new limit is so
large that in practice it's impossible to reach it.
2018-08-28 22:27:54 +02:00
Thomas Haller
72de0afa35 device: refactor setting parent in device's update_connection()
Add a helper function nm_device_parent_find_for_connection() to
unify implementations of setting the parent in update_connection().

There is some change in behavior, in particular for nm-device-vlan.c,
which no longer compares the link information from platform. But
update_connection() is anyway a questionable concept, only used
for external assumed connection (which itself, is questionable). Meaning,
update_connection() is a hack not science, and it's not at all clear
what the correct behavior is.

Also, note how vlan's implementation differs from all others. Why?
Should we always resort to also check the information from platform?
Either way, one of the two approaches should be used consistently and
nm_device_parent_find_for_connection() opts to not consult platform
cache.
2018-08-28 22:27:54 +02:00
Beniamino Galvani
357edff198 examples: make 10-ifcfg-rh-routes.sh self-contained
Don't call the 'if{up,down}-routes' scripts because in next Fedora
versions network scripts will be deprecated and will not be present in
the default installation.

Instead, just copy and adapt the code from those scripts.

https://bugzilla.redhat.com/show_bug.cgi?id=1618419
2018-08-28 18:56:56 +02:00
Beniamino Galvani
93f85edcce libnm-core: support private keys encrypted with AES-{192,256}-CBC
https://github.com/NetworkManager/NetworkManager/pull/189
2018-08-28 11:05:01 +02:00
Thomas Haller
e763a07a6e build: merge branch 'th/build-ifdef-cleanup'
https://github.com/NetworkManager/NetworkManager/pull/187
2018-08-27 18:18:49 +02:00
Thomas Haller
1dd63580df build/meson: fix build options for suspend-resume
suspend-resume must be selectable, out of for possible options.
We can do auto-detection based on present libraries, but it
shall be selectable. Like it is with autotools.
2018-08-27 17:49:29 +02:00
Thomas Haller
1a9bc22460 build: cleanup build defines for session-tracking
- always define the SESSION_TRACKING_* defines to replace
  "#ifdef" with "#if".

- drop defining the consolekit database path CKDB_PATH in
  config.h. The path was not customizable via configure/meson.

- fix meson build to enable consolekit support for session tracking
  without also enabling logind/elogind session tracking.
  logind/elogind is mutually exclusive, but consolekit session tracking
  goes together just fine.
2018-08-27 17:49:29 +02:00
Thomas Haller
3b5f8c91fe build: always define NM_MORE_LOGGING define and don't check with #ifdef
Using '#ifdef' is generally error prone. It's better to always define
a define and check for it explicitly. This way, the compiler can issue
a warning if the define does not exist.

Also, note how meson would always define NM_MORE_LOGGING, possibly to
"0". That means, for meson, we unintentionally always enabled more
logging because the define was always present.

Fix that.
2018-08-27 17:49:29 +02:00
Beniamino Galvani
68691eb009 cli: merge branch 'bg/completion-fixes-rh1588952'
https://bugzilla.redhat.com/show_bug.cgi?id=1588952
https://github.com/NetworkManager/NetworkManager/pull/185
2018-08-27 15:16:11 +02:00
Beniamino Galvani
d868788ee4 cli: fix autocompletion for connection commands
Autocompletion doesn't work in some cases because we present a prompt
ending with ":", but compare it with the string without ":" in the
autocomplete function. Fix this.

While at it, also add missing colon after prompt where needed.
2018-08-27 15:14:01 +02:00
Beniamino Galvani
2f60fdf19e cli: autocomplete connection type even if it has an alias
Before, we would not autocomplete connection types that have an alias:

Connection type: <TAB><TAB>
6lowpan           cdma              macvlan           vlan
802-11-olpc-mesh  dummy             olpc-mesh         vpn
802-11-wireless   ethernet          ovs-bridge        vxlan
802-3-ethernet    generic           ovs-interface     wifi
adsl              gsm               ovs-port          wimax
bluetooth         infiniband        pppoe             wpan
bond              ip-tunnel         team
bridge            macsec            tun
Connection type: 8<TAB> [-> no completion]

Don't treat the default connection type (for example,
"802-3-ethernet") in a special way and allow it to be autocompleted,
because we already display it when the user did not enter any text.
2018-08-27 15:14:01 +02:00
Beniamino Galvani
1669377110 cli: fix connection type completion on connection add
The array returned by the completion function follows a special
convention. If the first element is set, it is used as the
completion. Otherwise, the remaining entries are the possible
completions.

_meta_abstract_complete() just returned an array of matching words and
so the first element was always used as completion. Instead, we must
use rl_completion_matches() to generate the array passing a generator
function.

https://bugzilla.redhat.com/show_bug.cgi?id=1588952
2018-08-27 15:14:01 +02:00
Lubomir Rintel
d70185ddf1 all: point git references to the GitLab instance
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/2
2018-08-27 11:36:56 +02:00
Thomas Haller
e3c944d565 systemd: merge branch systemd into master
https://github.com/NetworkManager/NetworkManager/pull/186
2018-08-27 10:40:34 +02:00