Commit graph

616 commits

Author SHA1 Message Date
Joel Holdsworth 312c72f761 crypto_gnutls: removed dead code
https://mail.gnome.org/archives/networkmanager-list/2015-November/msg00061.html
2015-11-19 13:58:12 +01:00
Dan Williams 4b412218e6 libnm/wwan: add GSM setting device-id, sim-id, and sim-operator-id properties
These properties limit whether the connection applies to a certain WWAN modem
based on the modem's device ID or SIM ID (as reported by the WWAN management
service), or through the MCC/MNC ID of the operator that issued the SIM card.
2015-11-18 15:50:52 +01:00
Thomas Haller 4f6c91d696 wifi: enable mac-address-randomization by default for new connections
But ensure that old keyfiles that did not yet understand
the new key continue to have it disabled.
2015-11-18 15:37:42 +01:00
Thomas Haller 6a46dfca26 ifcfg-rh: add support for NMSettingWireless:mac-address-randomization
Old init-scripts that did not yet understand this key will have
mac-address-randomization explicitly disabled. This is to ensure
that old connections don't change behavior.
Thus, the writer must always write the value explicitly.

Downside is, if somebody creates a quick ifcfg-file, the feature
is disabled by default.
2015-11-18 15:37:42 +01:00
Dan Williams 0222822134 libnm: add Wi-Fi MAC address randomization property 2015-11-18 15:37:42 +01:00
Thomas Haller 37824def11 all: add C99's "bool" define
https://mail.gnome.org/archives/networkmanager-list/2015-November/msg00036.html
2015-11-18 13:25:21 +01:00
Jiří Klimeš b92397f925 all: fix typos in the code and update translations for that (bgo #758102)
Found by Anders Jonsson <anders.jonsson@norsjovallen.se>

https://bugzilla.gnome.org/show_bug.cgi?id=758102
2015-11-16 14:29:14 +01:00
Beniamino Galvani ac78c18855 libnm-core/tests: fix bit shift
Use a maximum shift amount of 63 for guint64.

Fixes: 0a3c1f5774
2015-11-15 11:13:41 +01:00
Thomas Haller 549ec35d7b libnm/keyfile: fix leak in ip6-addr-gen-mode writer
Fixes: f70c8f3d29
2015-11-11 16:15:41 +01:00
Lubomir Rintel 05dad07978 libnm-core: fix make dist with --enable-tests=no
We still need BUILT_SOURCES.
2015-11-02 21:05:11 +01:00
Lubomir Rintel e9dfdfe9fe libnm-core: default to ip6.addr-gen-mode=stable-privacy
Take a missing value in keyfile/ifcfg-rh as EUI-64 to keep the compatibility
with the old conneciton. Nevertheless, the new connections should default to
the RFC7217 addresses.
2015-11-02 20:27:36 +01:00
Lubomir Rintel f70c8f3d29 keyfile: add support for addr-gen-mode property 2015-11-02 20:27:00 +01:00
Lubomir Rintel 60811b4809 setting-ip6-config: add addr-gen-mode property 2015-11-02 20:27:00 +01:00
Lubomir Rintel cde053c0b0 vpn-plugin-info: add vpn plugin service aliases 2015-11-02 16:01:21 +01:00
Lubomir Rintel 3517084b92 vpn-plugin-info: drop nm_vpn_plugin_info_get_service()
It is not used externally and its use might be confusing and undesired when we
add plugin aliases. The external users should only use the name when idenfiying
the plugin and nm_vpn_plugin_info_list_find_by_service() when matchin the plugin.
2015-11-02 16:01:21 +01:00
Thomas Haller 5feda42813 vlan: handle vlan flags, ingress and egress map in NMDeviceVlan
In update_connection(), pickup the configuration of
the vlan interface from platform and create the proper
NMSettingVlan setting.

And during stage1, configure the flags of the device.

Also, change all the ingress/egress mappings at once
instead of having a netlink request for each mapping.
Also, ensure we *clear* all other mappings so that
only those are set, that were configured (done by
the *gress_reset_all argument).
2015-11-02 13:57:02 +01:00
Thomas Haller d2650a88bd libnm: don't re-sort the vlan priorities every time in set_map() 2015-11-02 13:57:02 +01:00
Thomas Haller 17aa8c0fc8 libnm: internally expose NMVlanQosMapping struct in "nm-core-internal.h" 2015-11-02 13:57:02 +01:00
Thomas Haller d61875c960 libnm: add internal header file "nm-core-types-internal.h"
This shall contain type definitions, with similar use
to "nm-core-internal.h".

However, it should contain a minimal set, so that we can include this
header in other headers under "src/", without including the whole
"nm-core-internal.h" in headers.
2015-11-02 13:57:02 +01:00
Thomas Haller 204fcd33d8 macros: add nm_clear_g_cancellable() utility 2015-11-01 17:28:07 +01:00
Thomas Haller da7cc97f5e libnm/tests: avoid invalid compiler warning about uninitialized variable
make[5]: Entering directory './NetworkManager/libnm-core/tests'
    CC       test-general.o
  test-general.c: In function ‘test_g_hash_table_get_keys_as_array’:
  test-general.c:4552:69: error: ‘length’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  test-general.c:4543:8: note: ‘length’ was declared here
    guint length;
          ^
2015-10-31 13:42:51 +01:00
Thomas Haller ee7414ebc8 platform: NM defines for vlan header flags equal the linux headers 2015-10-27 17:24:52 +01:00
Jiří Klimeš 689de5c94a vlan: (all) add VLAN MVRP flag
http://patchwork.ozlabs.org/patch/219364/
2015-10-27 17:17:05 +01:00
Jiří Klimeš 93b8871f56 libnm: sort INGRESS_PRIORITY_MAP, EGRESS_PRIORITY_MAP properties
This fixes comparing the properties.

Priority map { 1:2, 2:5 } is actually the same as { 2:5, 1:2 }.
2015-10-27 17:17:05 +01:00
Jiří Klimeš 704930a045 libnm: do not add duplicates to VLAN priority mappings 2015-10-27 16:31:29 +01:00
Jiří Klimeš 22a0136bcb ifcfg-rh: read/write VLAN GVRP flags with GVRP= ifcfg file variable
initscripts uses GVRP variable for the flag (since 2011):
https://git.fedorahosted.org/cgit/initscripts.git/commit/?id=f662d4777625cd3bedea19cccabea7741a8b45c9

But continue reading "GVRP" from VLAN_FLAG= if GVRP= is missing.
2015-10-27 16:26:37 +01:00
Thomas Haller 21674d5bfb libnm: treat missing NMSettingVlan:flags property as old default value
We changed the default value of MSettingVlan:flags from 0 to
1 (NM_VLAN_FLAG_REORDER_HEADERS). That means, that old libnm
clients will not serialize 0 (their default).
This change broke the D-Bus API. The D-Bus API allows to omit a value
when meaning the default value. That means, we cannot change the
default value (in the D-Bus API!) without breaking previous assumptions.

A newer libnm version should treat a missing flags argument as the
old default value and thus preserve the original default value (in the
D-Bus API).

This has the downside that for the future we will continue to treat a missing
value as the old default value (0), and in order to get the new default
value (1), the client must explicitly set the flags.

We also must restore the original default value in libnm-glib.
libnm-glib does not support _nm_setting_class_override_property()
and thus it must keep thinking that the default value for the GObject
property continues to be 0. Otherwise, it would not serialize a 1, which
a new libnm would now interpret as 0.

https://bugzilla.redhat.com/show_bug.cgi?id=1250225

Fixes: 687b651598
2015-10-23 11:23:46 +02:00
Thomas Haller 7a14f19e09 libnm: always serialize NMSettingVlan:flags property for D-Bus
We changed the default value for the NMSettingVlan:flags from 0 to
1 (NM_VLAN_FLAG_REORDER_HEADERS). That means, we will no longer serialize
a value of 1 over D-Bus.

This breaks older libnm clients, which treat a missing flags property as
the old default (0).

-- old clients here means: clients that still use an older version of libnm
   or clients that don't use libnm, but depend on the previous default value
   in the D-Bus API.

Enforce to always serialize the flags properties. This workaround has almost
no downsides except that for new clients we serialize more then absolutely
necessary.
But it ensures that old clients still receive the proper value.

https://bugzilla.redhat.com/show_bug.cgi?id=1250225

Fixes: 687b651598
2015-10-23 11:22:59 +02:00
Beniamino Galvani 1136de4221 libnm,libnm-core: fix GTK-Doc warnings 2015-10-16 17:33:12 +02:00
Beniamino Galvani e587dcb16e wake-on-lan: add option to keep existing settings
Add a new 'ignore' option to NMSettingWired.wake-on-lan which disables
management of wake-on-lan by NetworkManager (i.e. the pre-existing
option will not be touched). Also, change the default behavior to be
'ignore' instead of 'disabled'.

https://bugzilla.gnome.org/show_bug.cgi?id=755182
2015-10-16 17:11:26 +02:00
Lubomir Rintel 5b48befaad vpn-manager: support multiple VPN connections of the same type
A separate instance of the support plugin is spawned for each connection with
a different bus name. The bus name is passed via --bus-name <name> argument.
Plugins that support the feature indicate it with
support-multiple-connections=true key in the [VPN Connection] section.

The bus name is currently generated by adding a .<connection.uuid> to the VPN
service name. It's guarranteed unique, but if it proves to be too long or ugly
it can easily be replaced with something more meaningful (such as the same number
as is used for connection's DBus name).

NMVpnService has been removed and folded into NMVpnConnection. A
NMVpnConnection will spawn a service plugin instance whenever it is activated
and notices the bus name it needs is not provided.

The NMVpnManager no longer needs to keep track of the connections in use apart
for compatibility purposes with plugins that don't support the feature.
2015-10-13 18:20:56 +02:00
Lubomir Rintel 6c213e3cb4 libnm-core/vpn-plugin-info: add nm_vpn_plugin_info_supports_multiple() 2015-10-13 18:20:56 +02:00
Beniamino Galvani 0650b0b147 libnm-core: fix documentation for DHCP_TIMEOUT ifcfg-rh variable
Fixes: 3f0d595cc8
2015-10-13 15:36:46 +02:00
Beniamino Galvani 5966e14abf ifcfg-rh: add support for 'LLDP' connection property 2015-10-12 14:44:31 +02:00
Beniamino Galvani 07a9364d9c device: export list of LLDP neighbors through D-Bus
This adds a LldpNeighbors property to the Device D-Bus interface
carrying information about devices discovered through LLDP. The
property is an array of hashes and each hash describes the values of
LLDP TLVs for a specific neighbor.
2015-10-12 14:44:30 +02:00
Beniamino Galvani c364ef0b97 libnm: add 'lldp' property to NMSettingConnection
Add the 'lldp' property to NMSettingConnection, which specifies
whether the reception and parsing of LLDP frames to discover neighbor
devices should be enabled.
2015-10-12 14:44:19 +02:00
Jiří Klimeš 237030ce2b libnm: specify (transfer none) introspection annotation (bgo #756380)
Otherwise the callers would free the address and it would result in
double-free.

Ideally, the function would return const pointer, but changing it now
would require changing also other prototypes and much code due to
snowball effect of const.

https://bugzilla.gnome.org/show_bug.cgi?id=756380
2015-10-12 12:29:31 +02:00
Thomas Haller 68b3790ad3 libnm: explicitly cast enum type for g_object_set()
Fixes: 687b651598
2015-10-08 13:11:44 +02:00
Jiří Klimeš 687b651598 libnm/vlan: default to vlan.flags=REORDER_HDR for new connections (rh #1250225)
The kernel defaults REORDER_HDR to 1 when creating a new VLAN, but
NetworkManager's VLAN flags property defaulted to 0. Thus REORDER_HDR was not
set for NM-created VLANs with default values.

We want to match the kernel default, so we change the default value for the
vlan.flags property. However, we do not want to change the flags for existing
connections if the property is missing in connection files. Thus we have to
update plugins for that. We also make sure that vlan.flags is always written
by 'keyfile' when the value is default. That way new connections have flags
property explicitly written and it will be loaded as expected.

https://bugzilla.redhat.com/show_bug.cgi?id=1250225
2015-10-07 13:45:30 +02:00
Lubomir Rintel 3f0d595cc8 libnm,ip4-config: add ipv4.dhcp-timeout property
This is intentionally IPv4 specific since this is used for a quick fallback to
method=link-local -- something that's not needed for IPv6 since the link local
address is always there.

https://bugzilla.redhat.com/show_bug.cgi?id=1262922
2015-10-06 14:16:55 +02:00
Beniamino Galvani bd27c110a3 glib-compat: add g_hash_table_get_keys_as_array() compat function 2015-10-01 09:05:08 +02:00
Thomas Haller 7bf10a75db build: extract version macros from "nm-version.h" to new header file "nm-version-macros.h"
For libnm library, "nm-dbus-interface.h" contains defines like the D-Bus
paths of NetworkManager. It is desirable to have this header usable without
having a dependency on "glib.h", for example for a QT application. For that,
commit c0852964a8 removed that dependancy.

For libnm-glib library, the analog to "nm-dbus-interface.h" is
"NetworkManager.h", and the same applies there. Commit
159e827a72 removed that include.
However, that broke build on PackageKit [1] which expected to get the
version macros by including "NetworkManager.h". So at least for libnm-glib,
we need to preserve old behavior so that a user including
"NetworkManager.h" gets the version macros, but not "glib.h".

Extract the version macros to a new header file "nm-version-macros.h".
This header doesn't include "glib.h" and can be included from
"NetworkManager.h". This gives as previous behavior and a glib-free
include.

For libnm we still don't include "nm-version-macros.h" to "nm-dbus-interface.h".
Very few users will actually need the version macros, but not using
libnm.
Users that use libnm, should just include (libnm's) "NetworkManager.h" to
get all headers.
As a special case, a user who doesn't want to use glib/libnm, but still
needs both "nm-dbus-interface.h" and "nm-version-macros.h", can include
them both separately.

[1] https://github.com/hughsie/PackageKit/issues/85

Fixes: 4545a7fe96
2015-09-30 23:10:29 +02:00
Thomas Haller c60ff9e7e0 libnm: add NM_AVAILABLE_IN_1_2 to "nm-dbus-interface.h"
"nm-dbus-interface.h" can be used without glib/libnm, hence we must
workaround a missing NM_AVAILABLE_IN_1_2 macro.
2015-09-25 16:22:47 +02:00
Jiří Klimeš 12e6cf1f20 libnm-core/libnm-util: fix an erroneous error message
ipv6.dns: 'this property is not allowed for '%s=%s'' not allowed for method=ignore
2015-09-25 16:11:24 +02:00
Thomas Haller 0e223d4961 libnm: include "glib.h" in "nm-version.h"
This is a forward port of commit 6f616d4c4b
which added this patch on nm-1-0 branch.

However, the reason stated there is wrong because we don't need this
to fix Qt examples. Building Qt examples was fixed in that "nm-dbus-interface.h"
no longer drags in "nm-version.h".

On the other hand, we still want "nm-version.h" to be self-contained,
and include "glib.h" as it needs it.
2015-09-25 15:48:09 +02:00
Thomas Haller c0852964a8 libnm: don't include "nm-version.h" in "nm-dbus-interface.h"
We want "nm-dbus-interface.h" to have no dependancy on libnm and glib.
That way, it is usable for example in the QT examples without dragging
in dependencies to glib.

Also drop all the unneccessary include to "nm-dbus-interface.h", which
we already get by directly or indirectly including "nm-core-types.h".
2015-09-25 15:42:15 +02:00
Jiří Klimeš ffe16c958f libnm-core: add vpn.timeout property for establishing connections
[1] https://mail.gnome.org/archives/networkmanager-list/2015-April/msg00007.html
2015-09-21 16:59:04 +02:00
Jiří Klimeš 3d64d45d16 libnm-core/libnm-util: fix an assertion in adsl setting
(process:7799): GLib-CRITICAL **: g_ascii_strdown: assertion 'str != NULL' failed
2015-09-21 15:21:50 +02:00
Thomas Haller c9b3617c35 libnm: mark properties that take effect immediately on active connection (REAPPLY_IMMEDIATELY)
The flag is still unused.
2015-09-18 17:31:51 +02:00
Thomas Haller b1ebbf4c80 libnm: use NM_FLAGS_HAS() in nm_setting_compare() 2015-09-18 16:37:48 +02:00
Thomas Haller af180da625 libnm: don't assert in nm_connection_get_*() for verified connection
Those getters are convenience methods to retrieve the id/type from
the NMSettingConnection. If the NMSettingConnection was missing
(and thus the connection invalid) we would raise an assertion.

Don't be so strict and just silently return NULL.
Otherwise, the caller cannot use the functions on unverified
connections.
2015-09-18 16:12:36 +02:00
Jiří Klimeš 4485b4ec2f nmcli: wake-on-lan property set/get fixes
- accept a numeric value (decimal or hex (0x prefix))
- display a numeric value of the property in addition to the strings
- add/accept spaces between string names

to behave similar to other flags' properties.
2015-09-15 11:46:37 +02:00
Lubomir Rintel 874f455d6d test: fix duplicate test names
New glib complains.
2015-09-04 12:08:40 +02:00
Jiří Klimeš 71c8c2e587 libnm-core: fix a crash in priority_strv_to_maplist()
strv can be NULL.

Reproducer:
$ nmcli con mod my-vlan vlan.ingress 1:5
2015-09-01 16:09:08 +02:00
Jiří Klimeš 5e3582c6b1 doc: fix the names of [in|e]gress-priority-map properties in ifcfg-rh man page 2015-08-31 08:44:10 +02:00
Thomas Haller 9cace5b411 libnm/trivial: add code comment to _nm_dbus_error_has_name() 2015-08-25 16:37:43 +02:00
Beniamino Galvani 0bc335cfbe libnm: backport NMSettingWired Wake-on-LAN symbols to 1.0.6
Backport to 1.0.6 the following symbols:

  - nm_setting_wired_get_wake_on_lan
  - nm_setting_wired_get_wake_on_lan_password
  - nm_setting_wired_wake_on_lan_get_type

added to 1.0.6 with commit d449d82304
2015-08-25 10:23:57 +02:00
Beniamino Galvani 0969d16ad8 libnm: backport enum conversion utilities to 1.0.6
Backport to 1.0.6 the following symbols:

  - nm_utils_enum_from_str
  - nm_utils_enum_to_str

added to 1.0.6 with commit f4ce6760e0
2015-08-25 10:23:57 +02:00
Thomas Haller b2a66d59c8 Revert "all: change "Since: 1.2" to "Since: 1.0.4"/"Since: 1.0.6" for backported API"
API should be added with "Since:" of the next release on the same branch.
That means, new API on 1.1 branch (development), should be "Since: 1.2"
and new API on 1.0 branch (stable) will be "Since: 1.0.x". Similarly, new
API on master is NM_AVAILABLE_IN_1_2 and will be added with the linker
version libnl_1_2 -- never the versions of minor releases.

It is also strongly advised that for the 1.0 branch, we only add API
that was previously formerly added on master. IOW, that we only do true
backports of API that already exists on master.

API that gets backported, must also be added to master via NM_BACKPORT_SYMBOL().
That gives ABI compatibility and an application that was build against 1.0.x
will work with 1.y.z version (y > 0) without need for recompiling -- provided
that 1.y.z also contains that API.

There is one important caveat: if a major branch (e.g. current master) has a
linker section of backported APIs (e.g. libnm_1_0_6), we must do the minor release
(1.0.6) before the next major release (1.2). The reason is that after the major
release, the linker section (libnm_1_0_6) must not be extended and thus
the minor release (1.0.6) must be already released at that point.

In general, users should avoid using backported API because it limits
the ability to upgrade to arbitrary later versions. But together with the
previous point (that we only backport API to minor releases), a user that
uses backported API can be sure that a 1.y.z version is ABI compatible with
1.0.x, if the 1.y.z release date was after the release date of 1.0.x.

This reverts commit 02a136682c.
2015-08-25 09:04:35 +02:00
Lubomir Rintel 00b73a9f10 libnm,vpn-editor-plugin: don't assert the plugin name is the same as service name
It's not. It's meant to be human readable (e.g. "IPSec network that sometimes
works").
2015-08-21 16:06:39 +02:00
Lubomir Rintel 4b9f56ecfb Revert "libnm,vpn-editor-plugin: don't assert the plugin name is the same as service name"
This reverts commit 7583f6fc5e.
2015-08-21 16:00:37 +02:00
Lubomir Rintel 7583f6fc5e libnm,vpn-editor-plugin: don't assert the plugin name is the same as service name
It's not. It's meant to be human readable (e.g. "IPSec network that sometimes
works").
2015-08-21 13:37:24 +02:00
Jiří Klimeš 02a136682c all: change "Since: 1.2" to "Since: 1.0.4"/"Since: 1.0.6" for backported API 2015-08-21 10:43:53 +02:00
Jiří Klimeš 3d044b443a libnm: symbols for getting Wi-Fi frequencies have been backported to 1.0.6
Backport to 1.0.6 the following symbols:
  - nm_utils_wifi_2ghz_freqs;
  - nm_utils_wifi_5ghz_freqs;

Backported by commit 77bf69c3dc
2015-08-21 10:22:31 +02:00
Jiří Klimeš 1a6b631690 libnm: add utility functions for getting 2.4 GHz and 5 GHz Wi-Fi frequencies
nm_utils_wifi_2ghz_freqs()
nm_utils_wifi_5ghz_freqs()
2015-08-21 09:32:09 +02:00
Thomas Haller 1889e9c568 libnm/vpn: set special error code when loading vpn plugin fails due to missing file
VPN plugins are usually split into different packages. It might
be that the plugin file is simply not installed. We want the caller
to be able to recognize that conditation to fail gracefully.
Thus return a certain error code.
2015-08-20 12:42:20 +02:00
Thomas Haller 3dfbbb227e libnm: require exact vpn plugin filename
Originally, nm-applet loaded the vpn plugins by passing the filename
to g_module_open(). Thereby, g_module_open() allowed for missing file
extension and tries to complete the name with a system-dependent suffix.

When porting to libnm, we kept that behavior but did more elaborate
checks on the file, like checking owner and permissions.

Change to no longer trying to append the system suffix, but require
an exact path. That is no usability problem, because the plugin path
is specified in the .name files, and we just require them now to be the
full path (including the .so extension).
Note also, that this only affects new, libnm-based vpn plugins, thus there
is no change in behavior for legacy libnm-glib based plugins.

Fixes: eed0d0c58f
2015-08-18 12:08:11 +02:00
Thomas Haller 96cacc07e8 macros: use short-circuit evaluation in NM_IN_SET()
All current users of NM_IN_SET() would rather use short-circuit evalation
(or don't care). It seems that doing it by default seems favorable.

The only downside is, that this might have somewhat unexpected behavior
to a user who expects a regular function (which would evaluate always
all arguments).

Fixes: 7860ef959a
2015-08-12 16:04:17 +02:00
Thomas Haller 7860ef959a macros: rework NM_IN_SET() macro to expand to a plain logical expression
Let the preprocessor do more work, but generate a simple expression that
the compiler can optimize (presumably) better.
2015-08-12 14:30:18 +02:00
Thomas Haller 97ec44f593 libnm: fix gtkdoc for nm_utils_enum_to_str() and nm_utils_enum_from_str()
Fixes: 8be9814793
2015-08-05 16:35:26 +02:00
Thomas Haller 1766ab6e21 libnm: fix gtkdoc for _nm_utils_dns_option_*()
Fixes: 019943bb5d
2015-08-05 16:33:44 +02:00
Thomas Haller d81e8b96d2 libnm: fix gtkdoc for nm_setting_ip_config_next_valid_dns_option()
Fixes: 019943bb5d
2015-08-05 16:32:00 +02:00
Thomas Haller eef0342bcc libnm/test: use (void) for empty parentheses in function prototype
Fixes: ec92ecedae
2015-08-05 16:24:12 +02:00
Dan Winship 22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller 7363dc94c6 nm-default: include i18n headers via "nm-default.h" 2015-08-05 15:32:40 +02:00
Thomas Haller 19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Thomas Haller 780e9a3f43 libnm: include header in public header file with angle brackets 2015-08-05 15:25:30 +02:00
Thomas Haller e0bded93f3 libnm: avoid deprecated warning for NMVpnPluginInfo
When merely including "nm-vpn-plugin-info.h" (or "NetworkManager.h")
gcc raises warnings like:
  "Not available before 1.2 [-Werror=deprecated-declarations]"

The problem is that the NMVpnPluginInfo typedef itself is marked as
deprecated but also used by other functions like nm_vpn_plugin_info_get_name().

    typedef struct {
        int field;
    } Foo G_UNAVAILABLE(1,2);

    G_UNAVAILABLE(1,2)
    void deprecated_function (Foo *foo);

    warning: ‘Foo’ is deprecated: Not available before 1.2 [-Wdeprecated-declarations]

I think that when a function is itself deprecated, gcc should not warn about
the use of a deprecated typedef.
Gcc's documentation states: "Note that the warnings only occur for
uses and then only if the type is being applied to an identifier
that itself is not being declared as deprecated.".
Apparently, this only works for structs, but not for typedef of structs.

Anyway. Remove the deprecation from NMVpnPluginInfo to avoid the compiler
warning.

https://bugzilla.gnome.org/show_bug.cgi?id=753098

Fixes: d6226bd987
2015-08-04 15:59:32 +02:00
Beniamino Galvani f8ae5f1671 libnm-core: trivial: fix glib-mkenums parse warning
Avoid a new line in the definition of enum value to fix the following
glib-mkenums warning:

  glib-mkenums: nm-setting-wired.h:71:
  Failed to parse ` - 1 - NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) '

Fixes: 5622461c04
2015-08-04 14:50:30 +02:00
Beniamino Galvani d49fcd07d1 libnm-core: add _nm_utils_strv_equal() 2015-08-04 08:46:11 +02:00
Dan Williams 3a7db0dd9e introspection: fix some annotations
Fixes: eafa6c3584
Fixes: eed0d0c58f
Fixes: b5cc017ba4
Fixes: bce040daa2
2015-07-31 14:19:14 -05:00
Beniamino Galvani e65854f609 libnm-core: strip nm_utils_enum_from_str() input string 2015-07-30 16:56:27 +02:00
Thomas Haller eafa6c3584 libnm: add load method to NMVpnPluginInfo
https://bugzilla.gnome.org/show_bug.cgi?id=749877
2015-07-29 22:34:35 +02:00
Thomas Haller eed0d0c58f libnm: add nm_vpn_editor_plugin_load_from_file() function 2015-07-29 22:34:35 +02:00
Thomas Haller b5cc017ba4 libnm: add _nm_utils_check_module_file() 2015-07-29 22:34:35 +02:00
Thomas Haller bce040daa2 libnm: move NMVpnEditorPlugin to libnm-core/
Split the content of libnm/nm-vpn-editor-plugin.h and
move NMVpnEditorPlugin to libnm-core/nm-vpn-editor-plugin.h.

VPN plugins allow us to extend functionality about VPNs.
This can be also useful for NetworkManager core, hence
move that part to libnm-core.

The name NMVpnEditorPlugin is slightly misleading but not completely
wrong. The "editor" part stands no longer for bringing nm-applet
functionality (alone), but enable general VPN functionality in
the client.

Especially because we already have NMVpnPluginOld with a different
meaning (i.e. a base class of the plugin server implementation).
2015-07-29 22:34:35 +02:00
Thomas Haller d6226bd987 libnm: add NMVpnPluginInfo class
NMVpnPluginInfo is little more then a wrapper around
the GKeyFile that describes the VPN plugin settings,
i.e. the name files under "/etc/NetworkManager/VPN/".

Add this class to make the VPN API more explicit. Clients
now can use NMVpnPluginInfo instead of concerning themselves
with loading the keyfile and the meaning of its properties.

Also add support for a new VPN plugins directory
"/usr/lib/NetworkManager/VPN", which should replace
"/etc/NetworkManager/VPN" in the future. But we have to
consider both locations for backward compatibility.

The content of the VPN directory is not user configuration,
hence it should not be under "/etc". See related bug 738853.
2015-07-29 22:34:35 +02:00
Thomas Haller ed381cb1e2 libnm: add _nm_utils_check_file() util 2015-07-29 22:34:35 +02:00
Thomas Haller ec92ecedae libnm: add NMUtilsStrStrDictKey utility
When having a hash-of-hashes where each hash is indexed by a name,
(such as GKeyFile), you can either implement it as a hash-of-hashes
or define your own version of indexes that pack both levels of names
into one key.

This is an implementation of such a key. Use it as:

  GHashTable *hash = g_hash_table_new_full (_nm_utils_strstrdictkey_hash,
                                            _nm_utils_strstrdictkey_equal,
                                            g_free, _destroy_value);

and create keys via:

  NMUtilsStrStrDictKey *k = _nm_utils_strstrdictkey_create (s1, s2);

For lookup you can use static strings (note that the static string
might increase the size of the binary):

  g_hash_table_contains (hash, _nm_utils_strstrdictkey_static ("outer", "inner"))
2015-07-29 22:34:34 +02:00
Dan Winship 3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller a67c1ec4b5 libnm-core: fix return value in nm_utils_enum_to_str()
Fixes: 8be9814793
2015-07-24 15:48:29 +02:00
Beniamino Galvani 5622461c04 libnm-core: add Wake-on-LAN properties to NMSettingWired 2015-07-24 14:02:59 +02:00
Beniamino Galvani 8be9814793 libnm-core: add enum conversion utilities
Add functions nm_utils_enum_to_str() and nm_utils_enum_from_str()
which can be used to perform conversions between enum values and
strings, passing the GType automatically generated for every enum by
glib-mkenums.
2015-07-24 14:02:59 +02:00
Beniamino Galvani 3a7c641b02 libnm: backport symbols for metered connections support to 1.0.6
Backport to 1.0.6 the following symbols:
 - nm_device_get_metered
 - nm_metered_get_type
 - nm_setting_connection_get_metered
2015-07-22 14:06:31 +02:00
Thomas Haller 7f129b976c libnm-core: don't assert against non-NULL @ip argument to canonicalize_ip()
Remove an assertion in canonicalize_ip() to assert that either a
non-NULL @ip is given, or @null_any is TRUE.

The condition of the assert is not easy to understand without context.
Instead the caller should already handle %NULL properly.

All callers that pass @null_any=FALSE to canonicalize_ip(), already assert
that the argument is not %NULL. With the exception of nm_ip_route_new()
which however checks for a valid @dest early on.
2015-07-22 13:49:17 +02:00
Lubomir Rintel f14fd048ff libnm-core: 0.0.0.0 is a valid gateway too
It makes sense for point-to point links.

https://bugzilla.redhat.com/show_bug.cgi?id=1244483
2015-07-22 13:49:17 +02:00
Thomas Haller 9342568694 libnm-core: fix nm-setting-ip-config.c:valid_ip() to handle %NULL argument
We call valid_ip() from nm_ip_route_new() to check whether an untrusted string
is a valid ip address. Properly handle %NULL argument.

Fixes: 21c8a6b20e
2015-07-22 13:49:17 +02:00
Thomas Haller 2b55de8560 libnm-core: properly handle %NULL @ip in nm_utils_ipaddr_valid()
A is_valid() function should just accept NULL as input and
return "invalid". It certainly should not crash.

Fixes: 21c8a6b20e
2015-07-22 13:49:17 +02:00
Dan Williams 4e47d36d73 libnm-core: fix GOI annotations after 019943bb
Fixes: 019943bb
2015-07-17 17:31:17 -05:00
Jiří Klimeš 2af10ef444 docs: fix a copy/paste error in description of VLAN flags 2015-07-17 09:20:29 +02:00
David Shea 568b4ad31f libnm: handle illegal characters in nm_utils_ssid_to_utf8() (rh #1243078)
g_convert_with_fallback() will fail if the SSID contains characters that
are not legal in the source encoding, which, if $LANG is not set, will
be ASCII. If this happens, replace all non-ASCII and non-printable
characters with '?'. It is possible that nm_utils_ssid_to_utf8() will
now return an empty string (e.g., the source string is actually
big-endian UTF-16 and g_strcanon() stops on the first byte), but it will
not return NULL.

https://bugzilla.redhat.com/show_bug.cgi?id=1243078
2015-07-16 14:22:03 +02:00
Thomas Haller 61eed191a9 libnm-core: don't assert in nm_connection_get_uuid() for valid connection
We want to call nm_connection_get_uuid() also on connections that don't verify.
Otherwise it is chumbersome to check first for verified connection.
2015-07-12 13:56:52 +02:00
Thomas Haller 904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller 7a3ab5c02f test: initialize tests with nmtst_init() 2015-07-12 13:56:52 +02:00
Jiří Klimeš 640eb8f284 supplicant: allow with_system_ca_path to be a file name (rh #1236548)
NetworkManager uses wpa_supplicant, which in turn calls OpenSSL for verifying
certificates. wpa_supplicant calls
SSL_CTX_load_verify_locations(ctx, CAfile, CApath)
using its ca_cert and ca_path options as CAfile and CApath parameters.

We have a configure time option with_system_ca_path to override ca_path.
However, it doesn't work when a system (like Fedora) only uses bundled PEM
certificates instead of a directory with hashed certificates ([1], [2]).

So this commit allows setting --with_system_ca_path to a file name (the
trusted certificate bundle). Then the name is used to populate wpa_supplicant's
ca_cert instead of ca_path.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1053882
[2] https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/

https://bugzilla.redhat.com/show_bug.cgi?id=1236548
2015-07-08 17:07:02 +02:00
Thomas Haller 47551df352 libnm/keyfile: fix compile warning about uninitialized variable
Fixes: 71323122c6
2015-07-02 16:53:35 +02:00
Thomas Haller ed632207cd libnm: add @deep_copy argument to _nm_utils_strv_to_slist() and _nm_utils_slist_to_strv() 2015-07-02 15:50:04 +02:00
Thomas Haller 93e4a8d102 libnm: expose strv utils function in internal header nm-core-internal.h 2015-07-02 15:50:04 +02:00
Thomas Haller 7fbfaf567d libnm: consider ordering for _nm_keyfile_equals()
GKeyFile considers the order of the files, so add a possibility
to check whether to keyfiles are equal -- also with respect to
the order of the elements.
2015-07-02 15:50:03 +02:00
Thomas Haller e1b0195c67 libnm-keyfile/test: fix missing assertion in test 2015-07-02 15:50:03 +02:00
Thomas Haller 71323122c6 libnm: add keyfile utility functions 2015-07-02 15:50:03 +02:00
Thomas Haller 885d187d23 libnm: add _nm_utils_strv_cleanup() function 2015-07-02 15:50:03 +02:00
Thomas Haller aa7a53bc67 libnm-keyfile: ensure g_key_file_get_groups() sets the length argument
Under certain cases, if g_key_file_get_groups() fails, it might not set the
out argument @length. Play it safe and initialize it.
2015-07-02 15:50:03 +02:00
Thomas Haller 650fec81e2 libnm: add _nm_utils_ptrarray_find_binary_search() helper 2015-07-01 16:02:09 +02:00
Beniamino Galvani e86f8354a7 device: restart ping process when it exits with an error
When ping is launched to check the connectivity to the gateway it may
return earlier than the given timeout in case of error. When this
happens we need to respawn it until the timeout is reached.

While at it, increase maximum timeout value to 600 seconds.

https://bugzilla.redhat.com/show_bug.cgi?id=1128581
2015-07-01 13:42:41 +02:00
Thomas Haller f5cc6da8cf libnm: backport autoconnect-slaves symbols to libnm_1_0_4
https://bugzilla.gnome.org/show_bug.cgi?id=751535
2015-06-26 16:28:33 +02:00
Jiří Klimeš 2dc27a99d7 all: fix additional compiler warningis about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments
2015-06-19 13:06:37 +02:00
Jiří Klimeš 2a497eeadc ifcfg-rh: read/write autoconnect-slaves property as AUTOCONNECT_SLAVES
AUTOCONNECT_SLAVES is an NetworkManager extension. initscripts always activate
slaves with the master connection for bond and team, and doesn't activate
automatically slaves for bridge.
NetworkManager behaviour is controlled by this variable. If the variable is
missing the default value from configuration file is used.
2015-06-19 09:32:58 +02:00
Jiří Klimeš 6caafab258 libnm: add autoconnect-slaves property to NMSettingConnection
The property is used for controlling whether slaves should be brought up with
a master connection. If 0, activating the master will not activate slaves.
But if set to 1, activating the master will bring up slaves as well.
The property can have the third state (-1), meaning that the value is default.
That is either a value set in the configuration file for the property, or 0.
2015-06-19 09:32:58 +02:00
Thomas Haller 2f4301bd26 glib-compat: add g_ptr_array_insert() 2015-06-17 11:41:43 +02:00
Thomas Haller 3377cd7e18 libnm: add _nm_utils_ptrarray_find_first() utility function 2015-06-17 11:41:43 +02:00
Thomas Haller 0a3c1f5774 utils: add nm_utils_is_power_of_two() macro 2015-06-17 11:41:43 +02:00
Thomas Haller ef4e017cfa libnm/utils: add _nm_utils_strv_find_first() function 2015-06-11 19:58:51 +02:00
Jiří Klimeš 94a393e9ed all: fix a compiler warning about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments
2015-06-10 10:01:49 +02:00
Beniamino Galvani 7e5e624daf ifcfg-rh: add support for CONNECTION_METERED 2015-06-09 18:18:45 +02:00
Beniamino Galvani 6f647fe689 libnm-core: add 'metered' property to NMSettingConnection
Add a 'metered' enum property to NMSettingConnection with possible
values: unknown,yes,no. The value indicates the presence of limitations
in the amount of traffic flowing through the connection.
2015-06-09 18:11:25 +02:00
Beniamino Galvani bbbf522941 core,libnm: add 'metered' property to NMDevice 2015-06-09 18:11:25 +02:00
Thomas Haller f3c61f8141 device: remove reading ipv6 privacy setting from sysctl
Since introduction for support of ip6-privacy (use_tempaddr,
RFC4941) with commit d376270bfe,
the sysctl value from /etc was always read first.

This is problematic, because an explicit setting in the
connection should not be ignored over a global configuration.

Drop that old behavior. It was also problematic, because we did
not read any files under /etc/sysctl.d (except for sysctl.conf).
Also, we did not honor per-interface configurations.

Now we also use as last fallback the value from
/proc/sys/net/ipv6/conf/default/use_tempaddr
That has the advantage of falling back to the system default value
so that NM doesn't need to have it's own default policy
(Related: https://bugzilla.redhat.com/show_bug.cgi?id=1187525).

This is a change in behavior.
2015-06-05 12:38:30 +02:00
Thomas Haller e729dd70ae device: add global configuration default for ip6-privacy (use_tempaddr, RFC4941)
Support default value for setting 'ipv6.ip6-privacy' in
NetworkManager.conf.

If the global value is unset, preserve old behavior of looking into
/etc/sycctl.conf first. That behavior was introduced with commit
d376270bfe, since we support ip6-privacy
setting.

If the global value is set to "unknown", add a new fallback
that instead reads the runtime value from
  "/proc/sys/net/ipv6/conf/default/use_tempaddr"
This seems more sensible behavior because we fallback to sysctl,
but instead of looking at static files in /etc, read /proc.
But to preserve the old behavior, we only do that when a global
value is configured at all.

https://bugzilla.gnome.org/show_bug.cgi?id=721200
2015-06-05 12:38:30 +02:00
Thomas Haller e4293788fc libnm/doc: document behavior of setting ip6-privacy in /etc/sysctl.conf
https://bugzilla.gnome.org/show_bug.cgi?id=721200
2015-06-05 12:38:30 +02:00
Thomas Haller d5e948e482 libnm/test: test compare_property() to handle default values
Add a test case to check whether compare/diff works correctly.
2015-06-05 12:26:48 +02:00
Thomas Haller a8dd1b5358 libnm: make dns-options support an "undefined" default value
We want to distinguish between "no-options/empty" and "unset/default".
The latter can be interpreted by NM to use a default set of options.
2015-06-05 12:26:48 +02:00
Thomas Haller 7478c4b54a libnm: fix compare_property() to handle default values
Before, get_property_for_dbus() would @ignore_defaults.
That is for example wrong for properties of type G_TYPE_STRV.

In this case, if one operand has the property at its default
(NULL) and the other has it to an empty string list, both would
compare equal.

This has the effect that different settings might compare equal.
2015-06-05 12:26:48 +02:00
Lubomir Rintel ccb0ca4493 libnm-core,libnm-util: avoid calling a constructor
It yields completely unpredictable results on Ubuntu 12.04 (the global variable
successfully comparing to NULL despite demonstrably not NULL). Possibly a
toolchain bug.
2015-06-02 12:30:03 +02:00
Lubomir Rintel eb2b8c2798 build: use compat version of g_clear_pointer()
Ubuntu 12.04 has an ancient version of glib, which we nevertheless support.
2015-06-02 12:30:03 +02:00
Thomas Haller b8b1a01d96 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.
2015-06-01 14:47:08 +02:00
Lubomir Rintel c47c06470a builds: only enable TAP driver for glib >= 2.37.6
No TAP support for previous versions and --tap argument is silently ignored,
confusing the TAP driver.
2015-05-28 12:51:24 +02:00
Lubomir Rintel 6463ce5dd9 tests: use the TAP formatter
The test results in standard format are easily integrated into CI systems.
2015-05-26 13:51:45 +02:00
Lubomir Rintel f627d6db8e tests: move all asserts into tests
Otherwise the TAP formatter would produce a plan-less output.
2015-05-26 13:51:44 +02:00
Thomas Haller 89c6abc7ab libnm/test: include "nm-keyfile-internal.h" in test-general.c
This enables special code in "nm-test-utils.h" that is useful
for tests.
2015-05-20 18:39:04 +02:00
Thomas Haller d43be83aaa libnm: enforce that "nm-utils-private.h" header is not used inside src/
Let "nm-utils-private.h" and "nm-types.h" conflict.
2015-05-20 12:42:19 +02:00
Thomas Haller 670ca44721 libnm: rename DNSOptionDesc and @dns_option_descs to have an "nm"-prefix
Declarations in header files should always have an "nm" related
prefix.

Fixes: 019943bb5d
2015-05-20 12:42:19 +02:00
Thomas Haller 533f9fa2d2 libnm: move internal dns-option helpers to "nm-core-internal.h"
"nm-utils-private.h" should not be used outside of libnm-core/.
core/ should only use public API or "nm-core-internal.h".

Also, "nm-setting-ip-config.h" is a public header and should
not contain internal defines. Move them to "nm-core-internal.h"
too.

Fixes: 019943bb5d
2015-05-20 12:42:14 +02:00
Beniamino Galvani 8d9776997b libnm-core/trivial: rename 'i' function argument to 'idx' 2015-05-13 17:15:34 +02:00
Beniamino Galvani 262c27935d libnm-core/test: add tests for DNS option utilities 2015-05-13 17:15:34 +02:00
Beniamino Galvani 019943bb5d libnm-core: add dns-options property to NMSettingIPConfig 2015-05-13 17:15:34 +02:00
Jiří Klimeš e07efa836f libnm: add ifcfg-rh description for 802-11-wireless.powersave property
so that it is displayed in nm-settings-ifcfg-rh manual page.
2015-05-12 15:42:51 +02:00
Dan Williams cd3df12c8f vlan: don't fail if parent isn't found at construct time for existing devices
For existing devices, depending on the order that netlink sends interfaces to
us, the parent may be found after the VLAN interface and not be available when
the VLAN interface is constructed.  Instead of failing construction, when a
NMDeviceVlan has no parent keep it unavailable for activation.  Then have
the Manager notify existing devices when a new device is found, and let
NMDeviceVlan find the parent later and become available via that mechanism.

This doesn't apply to VLANs created by NM itself, because the kernel requires
a parent ifindex when creating a VLAN device.  Thus this fix only applies to
VLANs created outside NetworkManager, or existing when NM starts up.
2015-05-06 16:14:24 -05:00
Yuri Chornoivan f851a741a6 fix typo and do not translate an empty string
https://bugzilla.gnome.org/show_bug.cgi?id=748906
2015-05-04 18:36:54 +02:00
Dan Winship 4bac5afa2b libnm-core: trivial error message fixes 2015-04-17 14:55:42 -04:00
Dan Winship 721e917cb6 wimax: drop WiMAX support (bgo #747846)
Even Fedora is no longer shipping the WiMAX SDK, so it's likely we'll
eventually accidentally break some of the code in src/devices/wimax/
(if we haven't already). Discussion on the list showed a consensus for
dropping support for WiMAX.

So, remove the SDK checks from configure.ac, remove the WiMAX device
plugin and associated manager support, and deprecate all the APIs.

For compatibility reasons, it is still possible to create and save
WiMAX connections, to toggle the software WiMAX rfkill state, and to
change the "WIMAX" log level, although none of these have any effect,
since no NMDeviceWimax will ever be created.

nmcli was only compiling in support for most WiMAX operations when NM
as a whole was built with WiMAX support, so that code has been removed
now as well. (It is still possible to use nmcli to create and edit
WiMAX connections, but those connections will never be activatable.)
2015-04-17 12:42:23 -04:00
Thomas Haller 1eaddced10 make use of NM_MORE_ASSERTS, nm_assert() and NM_MORE_LOGGING 2015-04-10 18:09:32 +02:00
Beniamino Galvani aabc6fc57b wifi: indicate 2ghz and 5ghz wifi device capabilities
Add new capabilities CAP_FREQ_2GHZ and CAP_FREQ_5GHZ to indicate the
frequency bands supported by a Wifi device.

Add also CAP_FREQ_VALID, which is set when the values of the other 2
capabilities are available.

Original patch by Dan Williams <dcbw@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=723295
2015-04-08 10:48:38 +02:00
Lubomir Rintel 1ad193a017 device,libnm,cli: add "new-activation" reason for device state change
It will be used when the device is disconnected for new connection activation.
2015-04-08 10:00:11 +02:00
Dan Winship 773f047eef libnm-core: fix VPN error domain (bgo #745997)
In theory, NM_VPN_PLUGIN_ERROR should have names under
org.freedesktop.NetworkManager.VPN.Plugin, but for historical reasons,
it's actually org.freedesktop.NetworkManager.VPN.Error.
2015-04-07 11:30:36 -04:00
Dan Winship ec6f350f44 libnm-core: add _nm_dbus_error_has_name()
Add a method for checking the D-Bus error name of an error.
2015-04-03 16:58:40 -04:00
Dan Winship 9668bfd682 libnm-core: add _nm_dbus_proxy_call_sync(), _nm_dbus_proxy_call_finish()
Add versions of g_dbus_proxy_call_sync() and
g_dbus_proxy_call_finish() that also typecheck the response and return
an error if it is incorrect.
2015-04-03 16:58:40 -04:00
Dan Winship 4e61f4bf35 libnm-core: add _nm_dbus_signal_connect()
Add _nm_dbus_signal_connect(), for connecting to D-Bus signals on a
GDBusProxy, with typechecking and pre-parsing of the parameters
variant.
2015-04-03 16:58:40 -04:00
Jiří Klimeš b6f5f03033 crypto: only use gnutls crypto API, remove libgcrypt dependency (bgo #730294)
We don't need libgcrypt, because gnutls provides an API for encryption and
hashing. (Anyway gnutls itself now uses nettle instead of libgcrypt).

https://bugzilla.gnome.org/show_bug.cgi?id=730294
2015-04-01 13:23:45 +02:00
Thomas Haller a928ff860f libnl/trivial: add code comment to NM_UTILS_UUID_NS
Clearify, that the value was choosen arbitrarily.
2015-03-30 10:46:49 +02:00
Thomas Haller c6011cde14 trivial: remove semicolon after macro definition
Fixes: 58f08c8c9c
2015-03-20 13:38:44 +01:00
Thomas Haller 58f08c8c9c libnm: sort properties for nm_setting_enumerate_values()
The sort order of nm_setting_enumerate_values() affects the
order in which keyfile writer serializes the properties.

Have a defined, stable sort order by sorting the properties
by name (with prefering id,uuid,type for NMSettingConnection).
2015-03-20 13:19:20 +01:00
Thomas Haller e50fbe466b libnm: sort settings for nm_connection_for_each_setting_value()
nm_connection_for_each_setting_value() is used by keyfile writer to iterate
over the settings and write the keyfile entires. The order there is important
as g_key_file_to_data() prints the groups in the order they were created.

To have a stable order and to have the [connection] entry first, sort the
settings.
2015-03-20 13:19:20 +01:00
Thomas Haller 81119c69d8 keyfile/test: refactor and cleanup _keyfile_convert()
_keyfile_convert() should really test for successful round-trip
conversion of keyfile-connection and vice versa.
2015-03-20 13:19:20 +01:00
Thomas Haller 628f47285d libnm: accept unknown WEP key type in nm_utils_wep_key_valid()
libnm-core treated the UNKNOWN WEP key type as KEY. Relax that
and try to guess the correct type based on the key.

This is for example important if you have a valid connection with
  wep-key-type=0 (unknown)
If you request passwords for such a connection, the user cannot
enter them in password format -- but there is no UI indication
that the password must be KEY.
2015-03-20 13:02:04 +01:00
Thomas Haller dbbedce21f libnm: don't check for valid passwords in NMSetting:verify()
We must never fail verification of a connection based on a password
because the password is re-requested during activation.

Otherwise, if the user enters an invalid password for a (previously)
valid connection, the connection becomes invalid. NetworkManager does
not expect or handle that requesting password can make a connection
invalid.
Invalid passwords should be treated as wrong passwords. Only a UI
(such as nm-connection-editor or nmcli) should validate passwords
against a certain scheme.

Note that there is need_secrets() which on the contrary must check for
valid passwords.

Error scenario:

  Connect to a WEP Wi-Fi, via `nmcli device wifi connect SSID`. The
  generated connection has wep-key-type=0 (UNKNOWN) and wep-key-flags=0.
  When trying to connect, NM will ask for secrets and set the wep-key0
  field. After that, verification can fail (e.g. if the password is longer
  then 64 chars).
2015-03-20 13:01:04 +01:00
Thomas Haller d05bedbc0d libnm/keyfile: fix format string for unsigned integer
Fixes: 04df4edf48
2015-03-17 13:00:16 +01:00
Thomas Haller d198618aa7 libnm: fix error prefix in NMSettingGsm:verify() 2015-03-17 11:49:55 +01:00
Thomas Haller 997fc07ca5 test: add nmtst_create_connection_from_keyfile() 2015-03-12 18:16:58 +01:00
Thomas Haller c9a8764ad2 keyfile: support writing certificates as blob inside the keyfile
keyfile should become our main import/export format. It is desirable,
that a keyfile can contain every aspect of a connection.

For blob certificates, the writer in core daemon would always write
them to a file and convert the scheme to path.
This behavior is not great for a (hyptetical) `nmcli connection export`
command because it would have to export them somehow outside of keyfile,
e.g. by writing them to temporary files.

Instead, if the write handler does not handle a certificate, use a
default implementation in nm_keyfile_write() which adds the blob inside
the keyfile.

Interestingly, keyfile reader already supported reading certificate
blobs. But this legacy format accepts the blob as arbitrary
binary without marking the format and without scheme prefix.
Instead of writing the binary data directly, write it with a new
uri scheme "data:;base64," and encode it in base64.

Also go through some lengths to make sure that whatever path
keyfile plugin writes, can be read back again. That is, because
keyfile writer preferably writes relative paths without prefix.
Add nm_keyfile_detect_unqualified_path_scheme() to encapsulate
the detection of pathnames without file:// prefix and use it to
check whether the path name must be fully qualified.
2015-03-12 18:16:58 +01:00
Thomas Haller a49680dacd libnm: add define for cert scheme prefix file:// for NMSetting8021x 2015-03-12 18:12:27 +01:00
Thomas Haller 57a432fa8a keyfile: refactor to use reading and writing of keyfile from libnm-core 2015-03-12 18:12:26 +01:00
Thomas Haller 5e5afcffce libnm: merge nm-keyfile-reader.h and nm-keyfile-writer.h to internal header
These headers are not entirely private to libnm-core as they are also
used by keyfile plugin. Merge them to a new header file
nm-keyfile-internal.h so that the name makes the internal nature of the
header more apparent.
2015-03-12 18:12:26 +01:00
Thomas Haller 04df4edf48 libnm: add keyfile support to libnm-core
https://bugzilla.gnome.org/show_bug.cgi?id=744699
2015-03-12 18:12:26 +01:00
Thomas Haller 1fc9bc401e keyfile: copy read/writer files to libnm-core
This is the first step to move keyfile to libnm. For now, only
copy the files to make later changes nicer in git-history.

  /bin/cp src/settings/plugins/keyfile/reader.c libnm-core/nm-keyfile-reader.c
  /bin/cp src/settings/plugins/keyfile/reader.h libnm-core/nm-keyfile-reader.h
  /bin/cp src/settings/plugins/keyfile/utils.c  libnm-core/nm-keyfile-utils.c
  /bin/cp src/settings/plugins/keyfile/utils.h  libnm-core/nm-keyfile-utils.h
  /bin/cp src/settings/plugins/keyfile/writer.c libnm-core/nm-keyfile-writer.c
  /bin/cp src/settings/plugins/keyfile/writer.h libnm-core/nm-keyfile-writer.h
2015-03-12 18:12:26 +01:00
Thomas Haller e82293ebf6 libnm: move _nm_utils_uuid_generate_from_strings() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller c5d23737fd libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller 15926e9eb3 libnm: add function nm_setting_802_1x_check_cert_scheme()
When setting the certificate glib properties directly,
we raise a g_warning() when the binary data is invalid.
But since the caller has no access to the validation function,
he cannot easily check whether his action will result
in a warning. Add nm_setting_802_1x_check_cert_scheme() for
that.
2015-03-12 18:12:26 +01:00
Thomas Haller 0f1fe69422 trivial: add FIXME code comment about potential race 2015-03-12 18:12:26 +01:00
Thomas Haller 11371b5470 libnm: only call strlen() once in NMSetting8021x:path_to_scheme_value()
Also assert that path is not empty.
2015-03-12 18:12:25 +01:00
Thomas Haller 88a79625a6 libnm: fix clearing memory in file_to_secure_bytes()
If we go through the lengths of clearing the allocated
memory, we must not forget @contents.
2015-03-12 18:12:25 +01:00
Thomas Haller cda7b158e2 libnm: ensure valid blob for nm_setting_802_1x_set_*_cert()
A valid blob cannot start with "file://", otherwise it would
break the implementation of the certificate properties in
NMSetting8021x. Simply reject every blob in nm_setting_802_1x_set_ca_cert()
et al. that is not valid according to get_cert_scheme().
2015-03-12 18:12:25 +01:00
Thomas Haller e59e68c528 libnm: combine get_cert_scheme() and verify_cert() and ensure valid paths for NMSetting8021x
get_cert_scheme() would return PATH scheme for binary data that
later will be rejected by verify_cert(). Even worse, get_cert_scheme()
would not check whether the path is NUL terminated, hence the following
can crash for an invalid connection:

  if (nm_setting_802_1x_get_ca_cert_scheme (s_8021x) == NM_SETTING_802_1X_CK_SCHEME_PATH)
      g_print ("path: %s", nm_setting_802_1x_get_ca_cert_path (s_8021x))

Combine the two functions so that already get_cert_scheme() does
the same validation as verify_cert().

Also change behavior and be more strict about invalid paths:

 - Now, the value is considered a PATH candidate if it starts with "file://",
   (sans NUL character).
   A change is that before, the "file://" (without NUL) would have
   been treated as BLOB, now it is an invalid PATH (UNKNOWN).

 - If the binary starts with "file://" it is considered as PATH but it
   is only valid, if all the fllowing is true:
   (a) the last character must be NUL.
   (b) there is no other intermediate NUL character.
       Before, an intermediate NUL character would have been accepted
       and the remainder would be ignored.
   (c) there is at least one non-NUL character after "file://".
   (d) the string must be fully valid utf8.

   The conditions (b) and (c) are new and some invalid(?) paths
   might no longer validate.
   Checking (d) moved from verify_cert() to get_cert_scheme().
   As set_cert_prop_helper() already called verify_cert(), this
   causes no additional change beyond (b).
2015-03-12 18:12:25 +01:00
Thomas Haller ad4e6f7fad build/trivial: cleanup Makefile.am by sorting EXTRA_DIST entries 2015-03-12 18:12:25 +01:00
Jiří Klimeš 11efde3b40 libnm-core: add multicast-snooping property to bridge setting 2015-02-26 09:08:13 +01:00
Lubomir Rintel 2981839bde test: initialize auto-destructed pointers
Otherwise the compiler complains that they could be left uninitialized in case
the function returns too early.

Fixes: 76745817c3
2015-02-09 15:19:30 +01:00
Thomas Haller c50f30e79c tests: enable valgrind tests for tests 2015-02-09 11:51:07 +01:00
Thomas Haller ae73320b8c libnm/tests: fix memleaks in tests for valgrind 2015-02-09 11:51:07 +01:00
Thomas Haller 137e496ef1 libnm: fix memleaks in nm_setting_802_1x 2015-02-09 11:51:05 +01:00
Thomas Haller 7a82d64e47 libnm: fix memleak in nm_setting_wired_get_s390_option() and refactor
@keys was leaked. Also refactor the function to iterate the hash only
once.
2015-02-09 11:51:05 +01:00
Thomas Haller f1bfe459ee libnm: fix memleak in find_virtual_interface_name() 2015-02-09 11:51:05 +01:00
Thomas Haller fffd93b5c4 libnm: fix memleak in nm_connection_replace_settings() 2015-02-09 11:51:05 +01:00
Thomas Haller 66be46309a libnm: fix memleak in nm_utils_ip_addresses_from_variant() 2015-02-09 11:51:05 +01:00
Thomas Haller 8cb6d70e5b libnm: fix memleak for config in NMSettingTeamPort 2015-02-09 11:51:05 +01:00
Thomas Haller 052198f4b9 libnm: fix memleak for app_fcoe_mode in NMSettingDcb 2015-02-09 11:51:04 +01:00
Thomas Haller c4e197d064 libnm: fix memleak in nm_utils_hwaddr_canonical() 2015-01-29 14:59:42 +01:00
Dan Winship 3debf80d82 libnm-core: fix docs typo 2015-01-29 07:01:41 -05:00
Jiří Klimeš 0acdd0e1e3 libnm-core: coverity fix
var_deref_op: Dereferencing null pointer "property->param_spec".
2015-01-28 08:57:23 +01:00
Dan Williams 5293683e4a libnm/libnm-util: add Wi-Fi 'powersave' property 2015-01-21 14:31:04 -06:00
Dan Winship 6da3b3a5a5 libnm: fix versioning on new APIs, bump soname
The newly added bond mode APIs in nm-utils will be new in 1.2, so mark
them as such in the headers and docs, move them to a new section in
libnm.ver.

Since we're adding the new section to libnm.ver, this also seems like
a good time to bump the soname.
2015-01-21 12:54:36 -05:00
Dan Winship 5756c65c6f libnm-core, libnm-util: belatedly update version macros
Add version macros for NM 1.2, and change NM_VERSION_CUR_STABLE to
1.0, and NEXT_STABLE to 1.2.
2015-01-21 12:54:36 -05:00
Thomas Haller 05212419e1 libnm-core: fix compile error in set_property_from_dbus() for missing return value
Fixes: 76d9fc9167
2015-01-16 13:39:33 +01:00
Dan Winship 76d9fc9167 libnm-core: validate property types from D-Bus (rh #1182567)
In _nm_setting_new_from_dbus(), verify that the properties have the
right types, and return an error if not. (In particular, don't crash
if someone tries to assign a GBytes-valued property a non-'ay' value.)
2015-01-15 14:46:30 -05:00
Dan Winship d80e100179 libnm-core: simplify _nm_setting_new_from_dbus()
libnm-util's nm_setting_new_from_hash() needed to call
g_type_class_ref(setting_type) to ensure that the class had been
initialized by the time we fetched its properties. But in libnm-core's
version, we create the setting object before fetching the list of
properties, so we know the class will already have been initialized by
that point.
2015-01-15 14:46:30 -05:00
Dan Winship bbbbca2778 libnm-core: fix a leak in _nm_setting_new_from_dbus() 2015-01-15 14:46:30 -05:00
Jiří Klimeš 3d1b6bd4d8 bond: normalize bond mode to string notation (rh #1171009)
Use descriptive string value as preferred bond mode representation.
Numeric modes still verify but with NM_SETTING_VERIFY_NORMALIZABLE,
suggesting a normalization action.

https://bugzilla.redhat.com/show_bug.cgi?id=1171009
2015-01-13 09:35:49 +01:00
Jiří Klimeš 93438dd092 libnm-core: accept numeric bond modes (bgo #704666) (rh #1133544)
https://bugzilla.gnome.org/show_bug.cgi?id=704666
https://bugzilla.redhat.com/show_bug.cgi?id=1133544
2015-01-13 09:35:49 +01:00
Jiří Klimeš d787f0391b utils: add functions for converting string <-> numeric bonding modes 2015-01-13 09:35:49 +01:00
Thomas Haller 3e33a5a6c5 ifcfg-rh: support ipvx.route-metric property as IPVX_ROUTE_METRIC
Write ipv4.route-metric and ipv6.route-metric property of
NMSettingConnection as IPV4_ROUTE_METRIC and IPV6_ROUTE_METRIC,
respectively.
2015-01-10 21:10:52 +01:00
Lubomir Rintel 2f82bf537b bridge: Properly check range of STP properties (rh #1160815)
If zero is out of range, only allow it when STP is disabled.

https://bugzilla.redhat.com/show_bug.cgi?id=1160815
2015-01-09 12:13:53 +01:00
Thomas Haller fc5a66b14b libnm: fix documentation for nm_utils_file_search_in_paths() 2015-01-08 13:08:56 +01:00
Thomas Haller 1bef194302 libnm/tests: make tested IPv4 addresses non-palindromic
For IPv4 addresses, the binary representation is in network-order,
contrary to host-order. It's better to choose addresses for testing
that are differently on big and little endian systems.
2014-12-19 13:53:26 +01:00
Thomas Haller 7990add493 libnm/tests: fix build failure on big-endian machines
`make check` fails:

  make  check-TESTS
  make[4]: Entering directory `/builddir/build/BUILD/NetworkManager-1.1.0/libnm-core/tests'
  ...
  /core/general/test_setting_802_1x_changed_signal: OK
  /core/general/test_setting_ip4_gateway: **
  ERROR:test-general.c:3652:test_setting_ip4_gateway: assertion failed (nm_setting_ip_config_get_gateway (s_ip4) == "192.168.1.1"): ("1.1.168.192" == "192.168.1.1")
  /bin/sh: line 5: 44957 Aborted                 (core dumped) ${dir}$tst
2014-12-19 13:53:26 +01:00
Dan Winship 2d29c0527e docs: misc small fixes
Cleans up all of the warnings that aren't overly annoying to clean up.
2014-12-18 13:47:03 -05:00
Thomas Haller 924f7b2064 build: embed git-commit-id as string inside libnm binary
In the 'configure.ac' script we already detect the git commit id
for the current source version. When creating a tarball, it is also
included inside the generated 'configure' script.

Add the commit id as a  static string to nm-utils.c. That way, having
a build of libnm.so or NetworkManager, you can quickly find the
corresponding git commit:

    strings src/NetworkManager | grep NM_GIT_SHA

Note that this only works after a new `autogen.sh` run. Only rebuilding
is not enough. Hence, you must rebuild all to ensure that the correct
commit id is embedded.

https://bugzilla.gnome.org/show_bug.cgi?id=741651
2014-12-18 17:36:57 +01:00
Jiří Klimeš 6603e7ffde tests: mute coverity for CHECKED_RETURN (CWE-252) in tests
Error: CHECKED_RETURN (CWE-252): [#def12]
NetworkManager-0.9.11.0/libnm-core/tests/test-general.c:348: check_return: Calling "nm_setting_verify" without checking return value (as is done elsewhere 37 out of 45 times).
...
2014-12-15 14:11:03 +01:00
Jiří Klimeš afb0e2c53c libnm-core: mute coverity for RESOURCE_LEAK (CWE-772) in g_return_val_if_fail()
Error: RESOURCE_LEAK (CWE-772): [#def10]
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:225: alloc_fn: Storage is returned from allocation function "priority_map_new_from_str".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:154:4: alloc_fn: Storage is returned from allocation function "g_malloc0".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:154:4: var_assign: Assigning: "p" = "g_malloc0(8UL)".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:164:2: return_alloc: Returning allocated memory "p".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:225: var_assign: Assigning: "item" = storage returned from "priority_map_new_from_str(map, str)".
NetworkManager-0.9.11.0/libnm-core/nm-setting-vlan.c:226: leaked_storage: Variable "item" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK (CWE-772): [#def11]
NetworkManager-0.9.11.0/libnm-core/nm-utils.c:2056: alloc_fn: Storage is returned from allocation function "crypto_make_des_aes_key".
NetworkManager-0.9.11.0/libnm-core/crypto.c:405:2: alloc_fn: Storage is returned from allocation function "g_malloc0".
NetworkManager-0.9.11.0/libnm-core/crypto.c:405:2: var_assign: Assigning: "key" = "g_malloc0(digest_len + 1U)".
NetworkManager-0.9.11.0/libnm-core/crypto.c:407:2: noescape: Resource "key" is not freed or pointed-to in function "crypto_md5_hash".
NetworkManager-0.9.11.0/libnm-core/crypto.c:769:24: noescape: "crypto_md5_hash(char const *, gssize, char const *, gssize, char *, gsize)" does not free or save its pointer parameter "buffer".
NetworkManager-0.9.11.0/libnm-core/crypto.c:415:2: return_alloc: Returning allocated memory "key".
NetworkManager-0.9.11.0/libnm-core/nm-utils.c:2056: var_assign: Assigning: "key" = storage returned from "crypto_make_des_aes_key("DES-EDE3-CBC", &salt[0], salt_len, in_password, &key_len, NULL)".
NetworkManager-0.9.11.0/libnm-core/nm-utils.c:2057: leaked_storage: Variable "key" going out of scope leaks the storage it points to.
2014-12-15 14:10:55 +01:00
Lubomir Rintel a3f9e51927 agent-manager: don't ever fail the secrets requests from GetSecrets()
VPN connections always return true for nm_connection_need_secrets(), but the
documented behavior of GetSecrets() is just to return any secrets we have
(otherwise nmcli c --show-secrets would not be useful for VPN connections).
2014-12-11 11:15:53 +01:00
Thomas Haller 937a5639fc libnm: return 0 for empty address in hwaddr_binary_len()
Motivated by avoiding compiler warning with -O2 -Wstrict-overflow (gcc-4.8.3):

    make[4]: Entering directory `./NetworkManager/libnm-core'
      CC       nm-utils.lo
    ../libnm-core/nm-utils.c: In function 'nm_utils_hwaddr_valid':
    ../libnm-core/nm-utils.c:2725:14: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
       if (length == 0 || length > NM_UTILS_HWADDR_LEN_MAX)
                  ^
    ../libnm-core/nm-utils.c: In function 'nm_utils_hwaddr_canonical':
    ../libnm-core/nm-utils.c:2755:14: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
       if (length == 0 || length > NM_UTILS_HWADDR_LEN_MAX)
                  ^

https://bugzilla.gnome.org/show_bug.cgi?id=741168
2014-12-08 19:02:55 +01:00
Thomas Haller 820e41645f libnm: fix wrong g_return_if_fail() in nm_utils_file_search_in_paths()
Fixes: 6399170ff3
https://bugzilla.gnome.org/show_bug.cgi?id=740783
2014-12-05 15:01:01 +01:00
Thomas Haller 005b83de47 libnm: fix gtkdoc annotations for nm_utils_file_search_in_paths()
Fixes: 6399170ff3
2014-12-05 11:53:29 +01:00
Thomas Haller 6399170ff3 libnm: add function nm_utils_file_search_in_paths()
We now also use a similar function in VPN plugins. It makes
sense to provide a generic implementation in libnm.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=740783
2014-12-05 11:07:42 +01:00
Thomas Haller cd025f05f7 libnm: normalize connections in nm_simple_connection_new_from_dbus()
Before we would just call verify() and only return valid connections
without attempting to fix them.

It is better to use normalize(), because that function is especially there to
accept and repair deprecated configurations that would no longer verify().

This changes behavior in the way that the function now accepts connections
that would have been rejected before.

Since commit b88715e05b normalize() also
adds a missing UUID. Hence this also affects the DBUS method 'AddConnection'
in that it now accepts connections without UUID. Previously, clients were
required to set a UUID for the new connection, now NM core can create a random
one if no UUID is set.

https://bugzilla.gnome.org/show_bug.cgi?id=740813
2014-12-05 11:04:20 +01:00
Jiří Klimeš 0da3b96ab5 libnm-core: do not access array if it is NULL
Coverity:
Defect type: FORWARD_NULL
libnm-core/nm-setting-8021x.c:1684: var_deref_op: Dereferencing null pointer "array".
2014-12-05 09:38:40 +01:00
Thomas Haller 69860e5d3a libnm: don't allocate temporary buffer in nm_utils_uuid_generate_from_strings()
crypto_md5_sum() already accepts two separate strings: salt and password.
No need to allocate a temporary buffer. Just pass @ns_uuid and @s
separately.
2014-12-04 17:44:11 +01:00
Thomas Haller 440b9d85b4 libnm: fix leak in nm_utils_uuid_generate_from_strings()
Did not free the GString instance @str. Thereby,
also don't use GString. Just malloc() the temporary
buffer.

Fixes: e7661c9b52
2014-12-04 17:22:40 +01:00
Thomas Haller 924fd189b8 libnm: allow empty strings for nm_utils_uuid_generate_from_string()
Since commit ef3de46c43
crypto_md5_hash() allows empty password. Also support
empty strings for nm_utils_uuid_generate_from_string().
2014-12-04 17:02:22 +01:00
Thomas Haller 74bdaf1ad8 libnm: hide nm_utils_uuid_generate_from_string() from public API 2014-12-04 17:02:22 +01:00
Thomas Haller b88715e05b libnm: normalize missing connection UUID
Extend nm_connection_normalize() to add a connection UUID
in case it is unset.
2014-12-04 17:02:22 +01:00
Thomas Haller e7661c9b52 libnm: implement variant3 UUIDs according to rfc4122
Compare the results:
  perl -e 'use UUID::Tiny ":std"; print(uuid_to_string(create_uuid(UUID_V3, UUID_NS_DNS, "test"))."\n");'
  python -c 'from uuid import *; print(uuid3(UUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), "test"))'
2014-12-04 17:02:22 +01:00
Thomas Haller 1e313e000d libnm: add a type argument to nm_utils_uuid_generate_from_string()
There are different types (variants) of UUIDs defined.
Especially variants 3 and 5 are name based variants (rfc4122).

The way we create our UUIDs in nm_utils_uuid_generate_from_string()
however does not create them according to RFC and does not set
the flags to indicate the variant.

Modify the signature of nm_utils_uuid_generate_from_string() to accept
a "uuid_type" argument, so that we later can add other algorithms without
breaking API.
2014-12-04 17:02:22 +01:00
Thomas Haller 21eb6b5d0d libnm: accept additional length argument in nm_utils_uuid_generate_from_string()
This makes the function also useful for non C-strings,
non UTF-8-strings, and generic blobs.
2014-12-04 17:02:22 +01:00
Thomas Haller 50d1de13cb libnm: don't heap allocate uuid temporary variable 2014-12-04 17:02:22 +01:00
Thomas Haller e67425347a libnm/test: add test for nm_utils_uuid_generate_from_string() 2014-12-04 17:02:22 +01:00
Thomas Haller ea14a0136f crypto/test: test crypto_md5_hash() for empty passwords
Empty passwords are allowed since commit
ef3de46c43 .
2014-12-04 17:00:55 +01:00
Thomas Haller 94af5e76bc libnm/crypto: fix uninitialized variable in crypto_md5_hash()
@digest_len passed to g_checksum_get_digest() must be
initialized to the size of the digest. It is an in-out paramter.

Fixes: 48ff21b5bc
2014-12-04 16:24:05 +01:00
Dan Winship d91bcc4960 libnm-core: drop nm_utils_rsa_key_encrypt(), _encrypt_aes()
In general, we shouldn't end up with an unencrypted copy of a
certificate key anyway, so this function ought to be unnecessary (or
at least, not broadly useful enough to be in the public API).
nm-applet's GConf migration tool needs it, but that will eventually go
away, and until then it can just use libnm-util.
2014-12-04 08:39:54 -05:00
Thomas Haller ef3de46c43 libnm-core: relax restrictions on input arguments for crypto_md5_hash()
crypto_md5_hash() only has two users:
 (a) crypto_make_des_aes_key()
 (b) nm_utils_uuid_generate_from_string()

For (b) it is just a complicated way to compute the MD5 hash. The
restrictions on salt and password don't matter. Actually they
are harmful because we cannot compute the MD5 hash of the empty
word.
For (a), the caller should make sure to pass whatever restrictions
he wants to enforce on the data.

For example, it is counterintuitive, that crypto_md5_hash() would
require @salt_len, enforce it to be at least 8 bytes, and then just
use the first 8 bytes. If the caller (a) wants that behavior, he
should make sure that he passes in 8 bytes.
Likewise for the empty word. If the caller does not want to compute
the hash of empty passwords, he must not hash them.

Indeed, all of this was enforced by assertions, any caller already
did the right thing.
2014-12-04 08:39:54 -05:00
Thomas Haller 4460386800 libnm-core: combine duplicate crypto_make_des_aes_key() function 2014-12-04 08:39:54 -05:00
Dan Winship 3b86cc047e libnm: remove nm_utils_init() from the public API
Remove nm_utils_init() from the public API, and just do it as a
constructor instead.
2014-12-04 08:39:54 -05:00
Dan Winship bddc0de51e libnm-core: call crypto_init() on the fly
Rather than requiring crypto_init() to have been called beforehand,
just have every method that depends on it call it itself.

This required adding a GError argument to crypto_is_pkcs12_data(),
which in turn required a few other changes elsewhere.
2014-12-04 08:39:54 -05:00
Dan Winship 48ff21b5bc libnm-core: reimplement crypto_md5_hash() using GChecksum
Reimplement crypto_md5_hash() using GChecksum. Remove the gboolean
return value and GError argument, since it cannot fail now.
2014-12-04 08:39:54 -05:00
Dan Winship 34519eee13 tests: add a test of libnm-core's crypto_md5_hash() 2014-12-04 08:39:54 -05:00
Dan Winship 926f4e1473 libnm: drop nm_utils_deinit()
It was a no-op anyway.
2014-12-04 08:39:54 -05:00
Dan Winship cb025dba5b libnm-core: fix the rule for parsing 'gateway' out of 'addresses' (rh #1170199)
We were always using the gateway field of the first address in
ipv4.addresses / ipv6.addresses to set the gateway, but to be
compatible with old behavior, we should actually be using the first
non-0 gateway field (if the first one is 0).
2014-12-03 16:31:50 -05:00
Thomas Haller 6d6c433bab ifcfg-rh: don't include nm-utils-private.h outside of libnm-core/ 2014-12-03 17:36:08 +01:00
Thomas Haller a2e93f2de4 libnm: allow zero prefix length for NMIPRoute
NMIPRoute is used by NMSettingIPConfig, but also
NMIPConfig. In the former case, default routes are (still)
disallowed. But in the NMIPConfig use-case, it can make sense
to expose default routes as NMIPRoute instances.

Relax the restriction on the NMIPRoute API to allow this
future change.

No code actually supports having NMIPRoute instances with
prefix length zero (default routes). Up to now, all such uses
would be a bug.

https://bugzilla.gnome.org/show_bug.cgi?id=739969

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-24 18:02:46 +01:00
Lubomir Rintel abcb3184b3 libnm-core: Add a missing initializer
/libnm/crypto/PKCS#8: OK
/libnm/crypto/cert/pem: ==16241== Conditional jump or move depends on uninitialised value(s)
==16241==    at 0x121967: crypto_load_and_verify_certificate (crypto.c:605)
==16241==    by 0x12512E: nm_utils_file_is_certificate (nm-utils.c:2279)
==16241==    by 0x1201F1: test_cert (test-crypto.c:113)
2014-11-21 16:00:19 +01:00
Dan Winship 1c4f41c610 libnm-core: add nm_utils_file_is_certificate() and _file_is_private_key()
Add nm-utils methods to check if a file is a certificate or private
key file.

nm-applet currently has its own internal versions of these, but they
ended up having to duplicate a bunch of logic that we already have in
crypto.c.
2014-11-21 08:46:07 -05:00
Dan Winship 7c74e71e91 libnm-core: tweak crypto.c APIs
Update crypto_verify_private_key() and
crypto_verify_private_key_data() to indicate whether the key was
encrypted or not.

Rename crypto_decrypt_private_key() and
crypto_decrypt_private_key_data() to
crypto_decrypt_openssl_private_key*, since that's the only private key
format they deal with, and the old names made them sound more generic
than they were. Also, update the openssl private key parsing code to
recognize unencrypted private keys as well. (Previously we accepted
unencrypted PKCS#8 keys, but not unencrypted openssl-style keys.)
2014-11-21 08:46:07 -05:00