Commit Graph

21076 Commits

Author SHA1 Message Date
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
Thomas Haller
610ca87016 wifi: don't use :1 bitfield for gboolean type
gboolean is a typedef for "int".

While older compilers might treat such bitfields as unsigned ([1]),
commonly such a bitfield is signed and can only contain the values 0
and -1.

We only want to use numeric 1 for TRUE, hence, creating such bitfields
is wrong, or at least error prone.

In fact, in this case it's a bug, because later we compare
it with a regular gboolean

  if (priv->scanning != new_scanning)

[1] https://lgtm.com/rules/1506024027114/

Fixes: e0f9677018
2018-08-26 18:30:45 +02:00
Thomas Haller
8aa8d74710 systemd: update code from upstream (2018-08-26)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=56663345dfb1dd3ff23cac5fbc955aba54477efa

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/unaligned.h | \
  xargs -d '\n' rm -f

nm_copy_sd() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_shared() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd "src/basic/alloc-util.c"
nm_copy_sd "src/basic/alloc-util.h"
nm_copy_sd "src/basic/async.h"
nm_copy_sd "src/basic/env-util.c"
nm_copy_sd "src/basic/env-util.h"
nm_copy_sd "src/basic/escape.c"
nm_copy_sd "src/basic/escape.h"
nm_copy_sd "src/basic/ether-addr-util.c"
nm_copy_sd "src/basic/ether-addr-util.h"
nm_copy_sd "src/basic/extract-word.c"
nm_copy_sd "src/basic/extract-word.h"
nm_copy_sd "src/basic/fileio.c"
nm_copy_sd "src/basic/fileio.h"
nm_copy_sd "src/basic/fd-util.c"
nm_copy_sd "src/basic/fd-util.h"
nm_copy_sd "src/basic/fs-util.c"
nm_copy_sd "src/basic/fs-util.h"
nm_copy_sd "src/basic/hash-funcs.c"
nm_copy_sd "src/basic/hash-funcs.h"
nm_copy_sd "src/basic/hashmap.c"
nm_copy_sd "src/basic/hashmap.h"
nm_copy_sd "src/basic/hexdecoct.c"
nm_copy_sd "src/basic/hexdecoct.h"
nm_copy_sd "src/basic/hostname-util.c"
nm_copy_sd "src/basic/hostname-util.h"
nm_copy_sd "src/basic/in-addr-util.c"
nm_copy_sd "src/basic/in-addr-util.h"
nm_copy_sd "src/basic/io-util.c"
nm_copy_sd "src/basic/io-util.h"
nm_copy_sd "src/basic/list.h"
nm_copy_sd "src/basic/log.h"
nm_copy_sd "src/basic/macro.h"
nm_copy_sd "src/basic/mempool.h"
nm_copy_sd "src/basic/mempool.c"
nm_copy_sd "src/basic/parse-util.c"
nm_copy_sd "src/basic/parse-util.h"
nm_copy_sd "src/basic/path-util.c"
nm_copy_sd "src/basic/path-util.h"
nm_copy_sd "src/basic/prioq.h"
nm_copy_sd "src/basic/prioq.c"
nm_copy_sd "src/basic/process-util.h"
nm_copy_sd "src/basic/process-util.c"
nm_copy_sd "src/basic/random-util.c"
nm_copy_sd "src/basic/random-util.h"
nm_copy_sd "src/basic/refcnt.h"
nm_copy_sd "src/basic/set.h"
nm_copy_sd "src/basic/signal-util.h"
nm_copy_sd "src/basic/siphash24.h"
nm_copy_sd "src/basic/socket-util.c"
nm_copy_sd "src/basic/socket-util.h"
nm_copy_sd "src/basic/sparse-endian.h"
nm_copy_sd "src/basic/stat-util.c"
nm_copy_sd "src/basic/stat-util.h"
nm_copy_sd "src/basic/stdio-util.h"
nm_copy_sd "src/basic/string-table.c"
nm_copy_sd "src/basic/string-table.h"
nm_copy_sd "src/basic/string-util.c"
nm_copy_sd "src/basic/string-util.h"
nm_copy_sd "src/basic/strv.c"
nm_copy_sd "src/basic/strv.h"
nm_copy_sd "src/basic/time-util.c"
nm_copy_sd "src/basic/time-util.h"
nm_copy_sd "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/unaligned.h"
nm_copy_sd "src/basic/utf8.c"
nm_copy_sd "src/basic/utf8.h"
nm_copy_sd "src/basic/util.c"
nm_copy_sd "src/basic/util.h"
nm_copy_sd "src/libsystemd-network/arp-util.c"
nm_copy_sd "src/libsystemd-network/arp-util.h"
nm_copy_sd "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-network.c"
nm_copy_sd "src/libsystemd-network/dhcp-option.c"
nm_copy_sd "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd "src/libsystemd-network/lldp-internal.h"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd "src/libsystemd-network/lldp-network.c"
nm_copy_sd "src/libsystemd-network/lldp-network.h"
nm_copy_sd "src/libsystemd-network/network-internal.c"
nm_copy_sd "src/libsystemd-network/network-internal.h"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd "src/libsystemd-network/sd-lldp.c"
nm_copy_sd "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd "src/shared/dns-domain.c"
nm_copy_sd "src/shared/dns-domain.h"
nm_copy_sd "src/systemd/_sd-common.h"
nm_copy_sd "src/systemd/sd-dhcp6-client.h"
nm_copy_sd "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd "src/systemd/sd-dhcp-client.h"
nm_copy_sd "src/systemd/sd-dhcp-lease.h"
nm_copy_sd "src/systemd/sd-event.h"
nm_copy_sd "src/systemd/sd-ndisc.h"
nm_copy_sd "src/systemd/sd-id128.h"
nm_copy_sd "src/systemd/sd-ipv4acd.h"
nm_copy_sd "src/systemd/sd-ipv4ll.h"
nm_copy_sd "src/systemd/sd-lldp.h"
2018-08-26 15:48:17 +02:00
Lubomir Rintel
bd3472fb82 vpn-service-plugin: cancel the connect timer on has_ipv4=has_ipv6=false
NetworkManager considers a connection w/o L3 configuration fine and connected.
Don't make VPN plugins commit suicide in such case.
2018-08-23 17:15:38 +02:00
Thomas Haller
5f2c39fa29 wifi: merge branch 'th/wifi-gbytes-ssid'
https://github.com/NetworkManager/NetworkManager/pull/182
2018-08-22 11:13:10 +02:00
Thomas Haller
f1bc0f0bf2 wifi: refactor nm_wifi_ap_set_ssid() to accept GBytes
- have two variants of functions to set the SSID of an access point:
  one that passes SSID as GBytes, and one that passes it as plain
  data with length. Accepting a GBytes allows to share the immutable
  GBytes instance.

- both functions now also support clearing the SSID. In
  nm_wifi_ap_update_from_properties(), if the GVariant specifies
  a "SSID", we always update the access point. We already support
  chaging the SSID, so why not support changing it to *no* SSID
  (hidden).
2018-08-22 10:49:34 +02:00
Thomas Haller
5cd4e6f3e6 wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable.

Also, since at other places we use GBytes, having
different types is combersome and requires needless
conversions.

Also:

- avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string().
  We use nm_utils_escape_ssid() when we want to log the SSID. However, it
  does not escape newlines, which is bad.

- also no longer use nm_utils_same_ssid(). Since it no longer
  treated trailing NUL special, it is not different from
  g_bytes_equal().

- also, don't use nm_utils_ssid_to_utf8() for logging anymore.
  For logging, _nm_utils_ssid_escape_utf8safe() is better because
  it is loss-less escaping which can be unambigously reverted.
2018-08-22 10:49:34 +02:00
Thomas Haller
331d44afa6 wifi: don't ignore trailing NUL byte when comparing SSID
nm_utils_same_ssid() has a comment

 * Earlier versions of the Linux kernel added a NULL byte to the end of the
 * SSID to enable easy printing of the SSID on the console or in a terminal,
 * but this behavior was problematic (SSIDs are simply byte arrays, not strings)
 * and thus was changed.  This function compensates for that behavior at the
 * cost of some compatibility with odd SSIDs that may legitimately have trailing
 * NULLs, even though that is functionally pointless.

and the functionality was introduced by commit
ccb13f0bdd.

There was only place left that calls nm_utils_same_ssid().
I really don't think this is the right approach, nor is it clear
that this is still necessary. Also, it seems to only matter with
WEXT, and we should not have such an ugly hack in all cases.
2018-08-22 10:49:34 +02:00
Thomas Haller
57c371e32f shared: add nm_utils_buf_utf8safe_escape() util
We already have nm_utils_str_utf8safe_escape() to convert a
NUL termianted string to an UTF-8 string. nm_utils_str_utf8safe_escape()
operates under the assumption, that the input strig is already valid UTF-8
and returns the input string verbatim. That way, in the common expected
cases, the string just looks like a regular UTF-8 string.
However, in case there are invalid UTF-8 sequences (or a backslash
escape characters), the function will use backslash escaping to encode
the input string as a valid UTF-8 sequence. Note that the escaped
sequence, can be reverted to the original non-UTF-8 string via
unescape.
An example, where this is useful are file names or interface names.
Which are not in a defined encoding, but NUL terminated and commonly ASCII or
UTF-8 encoded.

Extend this, to also handle not NUL terminated buffers. The same
applies, except that the process cannot be reverted via g_strcompress()
-- because the NUL character cannot be unescaped.

This will be useful to escape a Wi-Fi SSID. Commonly we expect the SSID
to be in UTF-8/ASCII encoding and we want to print it verbatim. Only
if that is not the case, we fallback to backslash escaping. However, the
orginal value can be fully recovered via unescape(). The difference
between an SSID and a filename is, that the former can contain '\0'
bytes.
2018-08-22 10:49:34 +02:00
Thomas Haller
ced0dd2e4a wifi: use GBytes for ssids scan list
Use GBytes instead of GBytesArray. GBytes is immutable and
can be shared.

It is also the type that we natively get from
nm_setting_wireless_get_ssid(). This way we avoid some
conversions.
2018-08-22 10:49:34 +02:00
Thomas Haller
f5792881a0 device: avoid intermediary GByteArray when creating DUID GBytes
Creating it directly is simple enough.
2018-08-22 10:49:34 +02:00
Thomas Haller
5b5b651bcf dhcp/trivial: add fixme comments to nm_dhcp_dhclient_unescape_duid() 2018-08-22 10:49:34 +02:00
Thomas Haller
dba19ebd7d all: avoid useless cast of g_free() to GDestroyNotify 2018-08-22 10:49:34 +02:00