diff options
Diffstat (limited to 'src')
251 files changed, 3366 insertions, 3369 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index b208ffc6..a3bd6013 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -23,6 +23,8 @@ #include "NetworkManagerUtils.h" +#include "nm-utils/nm-c-list.h" + #include "nm-common-macros.h" #include "nm-utils.h" #include "nm-setting-connection.h" @@ -907,4 +909,90 @@ nm_match_spec_device_by_pllink (const NMPlatformLink *pllink, return no_match_value; } +/*****************************************************************************/ + +struct _NMShutdownWaitObjHandle { + CList lst; + GObject *watched_obj; + const char *msg_reason; +}; + +static CList _shutdown_waitobj_lst_head; + +static void +_shutdown_waitobj_unregister (NMShutdownWaitObjHandle *handle) +{ + c_list_unlink_stale (&handle->lst); + g_slice_free (NMShutdownWaitObjHandle, handle); + + /* FIXME(shutdown): check whether the object list is empty, and + * signal shutdown-complete */ +} + +static void +_shutdown_waitobj_cb (gpointer user_data, + GObject *where_the_object_was) +{ + NMShutdownWaitObjHandle *handle = user_data; + + nm_assert (handle); + nm_assert (handle->watched_obj == where_the_object_was); + _shutdown_waitobj_unregister (handle); +} +/** + * _nm_shutdown_wait_obj_register: + * @watched_obj: the object to watch. Takes a weak reference on the object + * to be notified when it gets destroyed. + * @msg_reason: a reason message, for debugging and logging purposes. It + * must be a static string. Or at least, be alive at least as long as + * @watched_obj. So, theoretically, if you need a dynamic @msg_reason, + * you could attach it to @watched_obj's user-data. + * + * Keep track of @watched_obj until it gets destroyed. During shutdown, + * we wait until all watched objects are destroyed. This is useful, if + * this object still conducts some asynchronous action, which needs to + * complete before NetworkManager is allowed to terminate. We re-use + * the reference-counter of @watched_obj as signal, that the object + * is still used. + * + * FIXME(shutdown): proper shutdown is not yet implemented, and registering + * an object (currently) has no effect. + * + * Returns: a handle to unregister the object. The caller may choose to ignore + * the handle, in which case, the object will be automatically unregistered, + * once it gets destroyed. + */ +NMShutdownWaitObjHandle * +_nm_shutdown_wait_obj_register (GObject *watched_obj, + const char *msg_reason) +{ + NMShutdownWaitObjHandle *handle; + + g_return_val_if_fail (G_IS_OBJECT (watched_obj), NULL); + + if (G_UNLIKELY (!_shutdown_waitobj_lst_head.next)) + c_list_init (&_shutdown_waitobj_lst_head); + + handle = g_slice_new (NMShutdownWaitObjHandle); + handle->watched_obj = watched_obj; + /* we don't clone the string. We require the caller to use pass a static message. + * If he really cannot do that, he should attach the string to the watched_obj + * as user-data. */ + handle->msg_reason = msg_reason; + c_list_link_tail (&_shutdown_waitobj_lst_head, &handle->lst); + g_object_weak_ref (watched_obj, _shutdown_waitobj_cb, handle); + return handle; +} + +void +nm_shutdown_wait_obj_unregister (NMShutdownWaitObjHandle *handle) +{ + g_return_if_fail (handle); + + nm_assert (G_IS_OBJECT (handle->watched_obj)); + nm_assert (nm_c_list_contains_entry (&_shutdown_waitobj_lst_head, handle, lst)); + + g_object_weak_unref (handle->watched_obj, _shutdown_waitobj_cb, handle); + _shutdown_waitobj_unregister (handle); +} diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 13bdb67e..b26d08bd 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -53,6 +53,37 @@ int nm_match_spec_device_by_pllink (const NMPlatformLink *pllink, const GSList *specs, int no_match_value); + +/*****************************************************************************/ + +/* during shutdown, there are two relevant timeouts. One is + * NM_SHUTDOWN_TIMEOUT_MS which is plenty of time, that we give for all + * actions to complete. Of course, during shutdown components should hurry + * to cleanup. + * + * When we initiate shutdown, we should start killing child processes + * with SIGTERM. If they don't complete within NM_SHUTDOWN_TIMEOUT_MS, we send + * SIGKILL. + * + * After NM_SHUTDOWN_TIMEOUT_MS, NetworkManager will however not yet terminate right + * away. It iterates the mainloop for another NM_SHUTDOWN_TIMEOUT_MS_EXTRA. This + * should give time to reap the child process (after SIGKILL). + * + * So, the maxiumum time we should wait before sending SIGKILL should be at most + * NM_SHUTDOWN_TIMEOUT_MS. + */ +#define NM_SHUTDOWN_TIMEOUT_MS 1500 +#define NM_SHUTDOWN_TIMEOUT_MS_WATCHDOG 500 + +typedef struct _NMShutdownWaitObjHandle NMShutdownWaitObjHandle; + +NMShutdownWaitObjHandle *_nm_shutdown_wait_obj_register (GObject *watched_obj, + const char *msg_reason); + +#define nm_shutdown_wait_obj_register(watched_obj, msg_reason) _nm_shutdown_wait_obj_register((watched_obj), (""msg_reason"")) + +void nm_shutdown_wait_obj_unregister (NMShutdownWaitObjHandle *handle); + /*****************************************************************************/ #endif /* __NETWORKMANAGER_UTILS_H__ */ diff --git a/src/devices/adsl/meson.build b/src/devices/adsl/meson.build index 4b0fade0..ee804d23 100644 --- a/src/devices/adsl/meson.build +++ b/src/devices/adsl/meson.build @@ -15,7 +15,7 @@ libnm_device_plugin_adsl = shared_module( link_args: ldflags_linker_script_devices, link_depends: linker_script_devices, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_device_plugin_adsl diff --git a/src/devices/adsl/nm-atm-manager.c b/src/devices/adsl/nm-atm-manager.c index 32c4c386..0ff4603d 100644 --- a/src/devices/adsl/nm-atm-manager.c +++ b/src/devices/adsl/nm-atm-manager.c @@ -236,7 +236,7 @@ handle_uevent (NMUdevClient *client, ifindex = udev_device_get_property_value (device, "IFINDEX"); seqnum = udev_device_get_seqnum (device); nm_log_dbg (LOGD_PLATFORM, "UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, - action, subsys, udev_device_get_sysname (device), ifindex ? ifindex : "unknown", seqnum); + action, subsys, udev_device_get_sysname (device), ifindex ?: "unknown", seqnum); if (!strcmp (action, "add")) adsl_add (self, device); diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 91331376..1450a836 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -194,7 +194,7 @@ br2684_assign_vcc (NMDeviceAdsl *self, NMSettingAdsl *s_adsl) _LOGD (LOGD_ADSL, "assigning address %d.%d.%d encapsulation %s", priv->atm_index, addr.sap_addr.vpi, addr.sap_addr.vci, - encapsulation ? encapsulation : "(none)"); + encapsulation ?: "(none)"); err = connect (priv->brfd, (struct sockaddr*) &addr, sizeof (addr)); if (err != 0) { @@ -525,7 +525,7 @@ adsl_cleanup (NMDeviceAdsl *self) if (priv->ppp_manager) { g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_state_changed), self); g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_ip4_config), self); - nm_ppp_manager_stop_sync (priv->ppp_manager); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); g_clear_object (&priv->ppp_manager); } diff --git a/src/devices/bluetooth/meson.build b/src/devices/bluetooth/meson.build index eb200679..30284f9e 100644 --- a/src/devices/bluetooth/meson.build +++ b/src/devices/bluetooth/meson.build @@ -26,7 +26,7 @@ libnm_device_plugin_bluetooth = shared_module( link_args: ldflags_linker_script_devices, link_depends: linker_script_devices, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_device_plugin_bluetooth diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index cc9e38c8..d8e40d6f 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -494,7 +494,7 @@ nm_bluez_device_disconnect (NMBluezDevice *self) priv->path, dbus_iface, "Disconnect", - args ? args : g_variant_new ("()"), + args ?: g_variant_new("()"), NULL, G_DBUS_CALL_FLAGS_NONE, 10000, diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index 96e80245..c74ecd81 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -125,7 +125,6 @@ async_data_unpack (struct AsyncData *async_data) return self; } - /** * Cancel any current attempt to detect the version and cleanup * the related fields. @@ -145,7 +144,6 @@ cleanup_checking (NMBluezManager *self, gboolean do_unwatch_name) } } - static void manager_bdaddr_added_cb (GObject *manager, NMBluezDevice *bt_device, @@ -244,7 +242,6 @@ setup_bluez5 (NMBluezManager *self) nm_bluez5_manager_query_devices (manager); } - static void watch_name_on_appeared (GDBusConnection *connection, const gchar *name, @@ -254,7 +251,6 @@ watch_name_on_appeared (GDBusConnection *connection, check_bluez_and_try_setup (NM_BLUEZ_MANAGER (user_data)); } - static void check_bluez_and_try_setup_final_step (NMBluezManager *self, int bluez_version, const char *reason) { diff --git a/src/devices/nm-acd-manager.c b/src/devices/nm-acd-manager.c index 1bade4ff..035487a3 100644 --- a/src/devices/nm-acd-manager.c +++ b/src/devices/nm-acd-manager.c @@ -274,7 +274,11 @@ acd_probe_start (NMAcdManager *self, return FALSE; } - _LOGD ("start probe for %s", nm_utils_inet4_ntop (info->address, NULL)); + if (timeout) { + _LOGD ("started probe for %s with timeout %llu", + nm_utils_inet4_ntop (info->address, NULL), + (unsigned long long) timeout); + } return TRUE; } diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 2dd9494a..22f7cdde 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -314,7 +314,7 @@ apply_bonding_config (NMDevice *device) /* Primary */ value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_PRIMARY); - set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ? value : ""); + set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ?: ""); /* ARP targets: clear and initialize the list */ contents = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, @@ -591,7 +591,7 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_n /* Primary */ value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_PRIMARY); - set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ? value : ""); + set_bond_attr (device, mode, NM_SETTING_BOND_OPTION_PRIMARY, value ?: ""); /* Active slave */ set_simple_option (device, mode, s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE); diff --git a/src/devices/nm-device-dummy.c b/src/devices/nm-device-dummy.c index f8bc8e75..9be4d29f 100644 --- a/src/devices/nm-device-dummy.c +++ b/src/devices/nm-device-dummy.c @@ -187,7 +187,6 @@ nm_device_dummy_class_init (NMDeviceDummyClass *klass) device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; } - /*****************************************************************************/ #define NM_TYPE_DUMMY_DEVICE_FACTORY (nm_dummy_device_factory_get_type ()) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 9b46545b..6c5e33e4 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1117,7 +1117,6 @@ dcb_state (NMDevice *device, gboolean timeout) g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_CONFIG); - carrier = nm_platform_link_is_connected (nm_device_get_platform (device), nm_device_get_ifindex (device)); _LOGD (LOGD_DCB, "dcb_state() wait %d carrier %d timeout %d", priv->dcb_wait, carrier, timeout); @@ -1344,7 +1343,7 @@ deactivate (NMDevice *device) nm_clear_g_source (&priv->pppoe_wait_id); if (priv->ppp_manager) { - nm_ppp_manager_stop_sync (priv->ppp_manager); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); g_clear_object (&priv->ppp_manager); } diff --git a/src/devices/nm-device-macsec.c b/src/devices/nm-device-macsec.c index 895ea34f..4eaf5469 100644 --- a/src/devices/nm-device-macsec.c +++ b/src/devices/nm-device-macsec.c @@ -731,7 +731,6 @@ link_changed (NMDevice *device, update_properties (device); } - static void device_state_changed (NMDevice *device, NMDeviceState new_state, diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index b8e748d6..dc4fb3e8 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -389,7 +389,6 @@ update_connection (NMDevice *device, NMConnection *connection) if (priv->props.no_promisc == nm_setting_macvlan_get_promiscuous (s_macvlan)) g_object_set (s_macvlan, NM_SETTING_MACVLAN_PROMISCUOUS, !priv->props.no_promisc, NULL); - if (priv->props.tap != nm_setting_macvlan_get_tap (s_macvlan)) g_object_set (s_macvlan, NM_SETTING_MACVLAN_TAP, !!priv->props.tap, NULL); diff --git a/src/devices/nm-device-ppp.c b/src/devices/nm-device-ppp.c index 94df0cae..a6abb228 100644 --- a/src/devices/nm-device-ppp.c +++ b/src/devices/nm-device-ppp.c @@ -239,7 +239,7 @@ deactivate (NMDevice *device) NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); if (priv->ppp_manager) { - nm_ppp_manager_stop_sync (priv->ppp_manager); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); g_clear_object (&priv->ppp_manager); } } diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index b0d3ffa4..0b844411 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -43,6 +43,8 @@ enum NMActStageReturn { #define NM_DEVICE_CAP_INTERNAL_MASK 0xc0000000 +void nm_device_arp_announce (NMDevice *self); + NMSettings *nm_device_get_settings (NMDevice *self); gboolean nm_device_set_ip_ifindex (NMDevice *self, int ifindex); diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index c3ce4b73..3846676c 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -480,7 +480,6 @@ nm_device_tun_class_init (NMDeviceTunClass *klass) g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); } - /*****************************************************************************/ #define NM_TYPE_TUN_DEVICE_FACTORY (nm_tun_device_factory_get_type ()) diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index ae6a0f36..a7f4c4bc 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -110,15 +110,15 @@ parent_hwaddr_maybe_changed (NMDevice *parent, if (nm_device_sys_iface_state_is_external_or_assume (device)) return; - connection = nm_device_get_applied_connection ((NMDevice *) self); + connection = nm_device_get_applied_connection (device); if (!connection) return; /* Update the VLAN MAC only if configuration does not specify one */ - if (nm_device_hw_addr_is_explict ((NMDevice *) self)) + if (nm_device_hw_addr_is_explict (device)) return; - old_mac = nm_device_get_hw_address ((NMDevice *) self); + old_mac = nm_device_get_hw_address (device); new_mac = nm_device_get_hw_address (parent); if (nm_streq0 (old_mac, new_mac)) return; @@ -126,13 +126,14 @@ parent_hwaddr_maybe_changed (NMDevice *parent, _LOGD (LOGD_VLAN, "parent hardware address changed to %s%s%s", NM_PRINT_FMT_QUOTE_STRING (new_mac)); if (new_mac) { - nm_device_hw_addr_set ((NMDevice *) self, new_mac, "vlan-parent", TRUE); + nm_device_hw_addr_set (device, new_mac, "vlan-parent", TRUE); + nm_device_arp_announce (device); /* When changing the hw address the interface is taken down, * removing the IPv6 configuration; reapply it. */ s_ip6 = nm_connection_get_setting_ip6_config (connection); if (s_ip6) - nm_device_reactivate_ip6_config (NM_DEVICE (self), s_ip6, s_ip6); + nm_device_reactivate_ip6_config (device, s_ip6, s_ip6); } } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 815de29a..9a40a0dd 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1177,8 +1177,9 @@ _get_stable_id (NMDevice *self, uuid = nm_connection_get_uuid (connection); stable_type = nm_utils_stable_id_parse (stable_id, - uuid, + nm_device_get_ip_iface (self), NULL, + uuid, &generated); /* current_stable_id_type is a bitfield! */ @@ -1357,7 +1358,7 @@ nm_device_get_ip_iface (NMDevice *self) priv = NM_DEVICE_GET_PRIVATE (self); /* If it's not set, default to iface */ - return priv->ip_iface ? priv->ip_iface : priv->iface; + return priv->ip_iface ?: priv->iface; } int @@ -2133,8 +2134,20 @@ get_type_description (NMDevice *self) nm_assert (NM_IS_DEVICE (self)); + /* the default implementation for the description just returns the (modified) + * class name and depends entirely on the type of self. Note that we cache the + * description in the klass itself. + * + * Also note, that as the GObject class gets inited, it inherrits the fields + * of the parent class. That means, if NMDeviceVethClass was initialized after + * NMDeviceEthernetClass already has the description cached in the class + * (because we already fetched the description for an ethernet device), + * then default_type_description will wrongly contain "ethernet". + * To avoid that, and catch the situation, also cache the klass for + * which the description was cached. If that doesn't match, it was + * inherited and we need to reset it. */ klass = NM_DEVICE_GET_CLASS (self); - if (G_UNLIKELY (!klass->default_type_description)) { + if (G_UNLIKELY (klass->default_type_description_klass != klass)) { const char *typename; gs_free char *s = NULL; @@ -2143,8 +2156,10 @@ get_type_description (NMDevice *self) typename += 8; s = g_ascii_strdown (typename, -1); klass->default_type_description = g_intern_string (s); + klass->default_type_description_klass = klass; } + nm_assert (klass->default_type_description); return klass->default_type_description; } @@ -2220,6 +2235,7 @@ nm_device_get_physical_port_id (NMDevice *self) typedef enum { CONCHECK_SCHEDULE_UPDATE_INTERVAL, + CONCHECK_SCHEDULE_UPDATE_INTERVAL_RESTART, CONCHECK_SCHEDULE_CHECK_EXTERNAL, CONCHECK_SCHEDULE_CHECK_PERIODIC, CONCHECK_SCHEDULE_RETURNED_MIN, @@ -2263,10 +2279,11 @@ concheck_is_possible (NMDevice *self) } static gboolean -concheck_periodic_schedule_do (NMDevice *self, gint64 interval_ns) +concheck_periodic_schedule_do (NMDevice *self, gint64 now_ns) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); gboolean periodic_check_disabled = FALSE; + gint64 expiry, tdiff; /* we always cancel whatever was pending. */ if (nm_clear_g_source (&priv->concheck_p_cur_id)) @@ -2277,18 +2294,25 @@ concheck_periodic_schedule_do (NMDevice *self, gint64 interval_ns) goto out; } - nm_assert (interval_ns >= 0); - if (!concheck_is_possible (self)) goto out; - _LOGT (LOGD_CONCHECK, "connectivity: periodic-check: %sscheduled in %u milliseconds (%u seconds interval)", + nm_assert (now_ns > 0); + nm_assert (priv->concheck_p_cur_interval > 0); + + /* we schedule the timeout based on our current settings cur-interval and cur-basetime. + * Before calling concheck_periodic_schedule_do(), make sure that these properties are + * correct. */ + + expiry = priv->concheck_p_cur_basetime_ns + (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND); + tdiff = expiry - now_ns; + + _LOGT (LOGD_CONCHECK, "connectivity: periodic-check: %sscheduled in %lld milliseconds (%u seconds interval)", periodic_check_disabled ? "re-" : "", - (guint) (interval_ns / NM_UTILS_NS_PER_MSEC), + (long long) (tdiff / NM_UTILS_NS_PER_MSEC), priv->concheck_p_cur_interval); - nm_assert (priv->concheck_p_cur_interval > 0); - priv->concheck_p_cur_id = g_timeout_add (interval_ns / NM_UTILS_NS_PER_MSEC, + priv->concheck_p_cur_id = g_timeout_add (NM_MAX ((gint64) 0, tdiff) / NM_UTILS_NS_PER_MSEC, concheck_periodic_timeout_cb, self); return TRUE; @@ -2316,18 +2340,23 @@ concheck_periodic_schedule_set (NMDevice *self, if (!priv->concheck_p_cur_id) { /* we currently don't have a timeout scheduled. No need to reschedule * another one... */ - if (mode == CONCHECK_SCHEDULE_UPDATE_INTERVAL) { - /* ... unless, we are initalizing. In this case, setup the current current - * interval and schedule a perform a check right away. */ - priv->concheck_p_cur_interval = NM_MIN (priv->concheck_p_max_interval, CONCHECK_P_PROBE_INTERVAL); - priv->concheck_p_cur_basetime_ns = nm_utils_get_monotonic_timestamp_ns_cached (&now_ns); - if (concheck_periodic_schedule_do (self, priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND)) - concheck_start (self, NULL, NULL, TRUE); - } - return; + if (NM_IN_SET (mode, CONCHECK_SCHEDULE_UPDATE_INTERVAL, + CONCHECK_SCHEDULE_UPDATE_INTERVAL_RESTART)) { + /* ... unless, we are about to start periodic checks after update-interval. + * In this case, fall through and restart the periodic checks below. */ + mode = CONCHECK_SCHEDULE_UPDATE_INTERVAL_RESTART; + } else + return; } switch (mode) { + case CONCHECK_SCHEDULE_UPDATE_INTERVAL_RESTART: + priv->concheck_p_cur_interval = NM_MIN (priv->concheck_p_max_interval, CONCHECK_P_PROBE_INTERVAL); + priv->concheck_p_cur_basetime_ns = nm_utils_get_monotonic_timestamp_ns_cached (&now_ns); + if (concheck_periodic_schedule_do (self, now_ns)) + concheck_start (self, NULL, NULL, TRUE); + return; + case CONCHECK_SCHEDULE_UPDATE_INTERVAL: /* called with "UPDATE_INTERVAL" and already have a concheck_p_cur_id scheduled. */ @@ -2352,7 +2381,7 @@ concheck_periodic_schedule_set (NMDevice *self, * new max_interval passed. We need to start a check right away (and * schedule a timeout in cur-interval in the future). */ priv->concheck_p_cur_basetime_ns = now_ns; - if (concheck_periodic_schedule_do (self, priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND)) + if (concheck_periodic_schedule_do (self, now_ns)) concheck_start (self, NULL, NULL, TRUE); } else { /* we are reducing the max-interval to a shorter interval that we have currently @@ -2361,14 +2390,14 @@ concheck_periodic_schedule_set (NMDevice *self, * However, since the last time we scheduled the check, not even the new max-interval * expired. All we need to do, is reschedule the timer to expire sooner. The cur_basetime * is unchanged. */ - concheck_periodic_schedule_do (self, cur_expiry - now_ns); + concheck_periodic_schedule_do (self, now_ns); } return; case CONCHECK_SCHEDULE_CHECK_EXTERNAL: /* a external connectivity check delays our periodic check. We reset the counter. */ priv->concheck_p_cur_basetime_ns = nm_utils_get_monotonic_timestamp_ns_cached (&now_ns); - concheck_periodic_schedule_do (self, priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND); + concheck_periodic_schedule_do (self, now_ns); return; case CONCHECK_SCHEDULE_CHECK_PERIODIC: @@ -2401,15 +2430,16 @@ concheck_periodic_schedule_set (NMDevice *self, new_expiry = exp_expiry + (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND); tdiff = NM_MAX (new_expiry - now_ns, 0); priv->concheck_p_cur_basetime_ns = (now_ns + tdiff) - (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND); - concheck_periodic_schedule_do (self, tdiff); - handle = concheck_start (self, NULL, NULL, TRUE); - if (old_interval != priv->concheck_p_cur_interval) { - /* we just bumped the interval already when scheduling this check. - * When the handle returns, don't bump a second time. - * - * But if we reach the timeout again before the handle returns (this - * code here) we will still bump the interval. */ - handle->is_periodic_bump_on_complete = FALSE; + if (concheck_periodic_schedule_do (self, now_ns)) { + handle = concheck_start (self, NULL, NULL, TRUE); + if (old_interval != priv->concheck_p_cur_interval) { + /* we just bumped the interval already when scheduling this check. + * When the handle returns, don't bump a second time. + * + * But if we reach the timeout again before the handle returns (this + * code here) we will still bump the interval. */ + handle->is_periodic_bump_on_complete = FALSE; + } } return; } @@ -2436,11 +2466,11 @@ concheck_periodic_schedule_set (NMDevice *self, new_expiry = priv->concheck_p_cur_basetime_ns + (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND); tdiff = NM_MAX (new_expiry - nm_utils_get_monotonic_timestamp_ns_cached (&now_ns), 0); priv->concheck_p_cur_basetime_ns = now_ns + tdiff - (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND); - concheck_periodic_schedule_do (self, tdiff); + concheck_periodic_schedule_do (self, now_ns); } -void -nm_device_check_connectivity_update_interval (NMDevice *self) +static void +concheck_update_interval (NMDevice *self, gboolean check_now) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); guint new_interval; @@ -2455,7 +2485,8 @@ nm_device_check_connectivity_update_interval (NMDevice *self) } if (!new_interval) { - /* this will cancel any potentially pending timeout. */ + /* this will cancel any potentially pending timeout because max-interval is zero. + * But it logs a nice message... */ concheck_periodic_schedule_do (self, 0); /* also update the fake connectivity state. */ @@ -2463,7 +2494,16 @@ nm_device_check_connectivity_update_interval (NMDevice *self) return; } - concheck_periodic_schedule_set (self, CONCHECK_SCHEDULE_UPDATE_INTERVAL); + concheck_periodic_schedule_set (self, + check_now + ? CONCHECK_SCHEDULE_UPDATE_INTERVAL_RESTART + : CONCHECK_SCHEDULE_UPDATE_INTERVAL); +} + +void +nm_device_check_connectivity_update_interval (NMDevice *self) +{ + concheck_update_interval (self, FALSE); } static void @@ -3054,12 +3094,12 @@ carrier_changed (NMDevice *self, gboolean carrier) * is restored. */ if (priv->state == NM_DEVICE_STATE_ACTIVATED) nm_device_update_dynamic_ip_setup (self); - else { - if (nm_device_activate_ip4_state_in_wait (self)) - nm_device_activate_stage3_ip4_start (self); - if (nm_device_activate_ip6_state_in_wait (self)) - nm_device_activate_stage3_ip6_start (self); - } + /* If needed, also resume IP configuration that is + * waiting for carrier. */ + if (nm_device_activate_ip4_state_in_wait (self)) + nm_device_activate_stage3_ip4_start (self); + if (nm_device_activate_ip6_state_in_wait (self)) + nm_device_activate_stage3_ip6_start (self); return; } /* fall-through and change state of device */ @@ -4179,7 +4219,6 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error) g_return_val_if_fail (priv->iface != NULL, FALSE); g_return_val_if_fail (priv->real, FALSE); - ifindex = nm_device_get_ifindex (self); _LOGD (LOGD_DEVICE, "unrealize (ifindex %d)", ifindex > 0 ? ifindex : 0); @@ -5829,7 +5868,6 @@ activate_stage1_device_prepare (NMDevice *self) nm_device_activate_schedule_stage2_device_config (self); } - /* * nm_device_activate_schedule_stage1_device_prepare * @@ -6031,7 +6069,6 @@ activate_stage2_device_config (NMDevice *self) nm_device_activate_schedule_stage3_ip_config_start (self); } - /* * nm_device_activate_schedule_stage2_device_config * @@ -7036,6 +7073,8 @@ dhcp4_get_client_id (NMDevice *self, NMConnection *connection) guint8 buf[20]; gsize buf_size; guint32 salted_header; + const guint8 *secret_key; + gsize secret_key_len; stable_id = _get_stable_id (self, connection, &stable_type); if (!stable_id) @@ -7043,10 +7082,13 @@ dhcp4_get_client_id (NMDevice *self, NMConnection *connection) salted_header = htonl (2011610591 + stable_type); + nm_utils_secret_key_get (&secret_key, &secret_key_len); + sum = g_checksum_new (G_CHECKSUM_SHA1); g_checksum_update (sum, (const guchar *) &salted_header, sizeof (salted_header)); - g_checksum_update (sum, (const guchar *) stable_id, strlen (stable_id)); + g_checksum_update (sum, (const guchar *) stable_id, strlen (stable_id) + 1); + g_checksum_update (sum, (const guchar *) secret_key, secret_key_len); buf_size = sizeof (buf); g_checksum_get_digest (sum, buf, &buf_size); @@ -9325,8 +9367,8 @@ arp_cleanup (NMDevice *self) } } -static void -arp_announce (NMDevice *self) +void +nm_device_arp_announce (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection; @@ -9425,8 +9467,7 @@ activate_stage5_ip4_config_result (NMDevice *self) NULL, NULL, NULL); } - arp_announce (self); - + nm_device_arp_announce (self); nm_device_remove_pending_action (self, NM_PENDING_ACTION_DHCP4, FALSE); /* Enter the IP_CHECK state if this is the first method to complete */ @@ -10800,23 +10841,37 @@ _carrier_wait_check_act_request_must_queue (NMDevice *self, NMActRequest *req) } void -nm_device_steal_connection (NMDevice *self, NMSettingsConnection *connection) +nm_device_disconnect_active_connection (NMActiveConnection *active) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDevice *self; + NMDevicePrivate *priv; - _LOGI (LOGD_DEVICE, "disconnecting connection '%s' for new activation request", - nm_settings_connection_get_id (connection)); + g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active)); - if ( priv->queued_act_request - && connection == nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (priv->queued_act_request))) - _clear_queued_act_request (priv); + self = nm_active_connection_get_device (active); - if ( priv->act_request.obj - && connection == nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (priv->act_request.obj)) - && priv->state < NM_DEVICE_STATE_DEACTIVATING) { - nm_device_state_changed (self, - NM_DEVICE_STATE_DEACTIVATING, - NM_DEVICE_STATE_REASON_NEW_ACTIVATION); + if (!self) { + /* hm, no device? Just fail the active connection. */ + nm_active_connection_set_state_fail (active, + NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN, + NULL); + return; + } + + priv = NM_DEVICE_GET_PRIVATE (self); + + if (NM_ACTIVE_CONNECTION (priv->queued_act_request) == active) { + _clear_queued_act_request (priv); + return; + } + if (NM_ACTIVE_CONNECTION (priv->act_request.obj) == active) { + if (priv->state < NM_DEVICE_STATE_DEACTIVATING) { + nm_device_state_changed (self, + NM_DEVICE_STATE_DEACTIVATING, + NM_DEVICE_STATE_REASON_NEW_ACTIVATION); + } else { + /* it's going down already... */ + } } } @@ -10931,7 +10986,6 @@ nm_device_get_ip4_config (NMDevice *self) return NM_DEVICE_GET_PRIVATE (self)->ip_config_4; } - static gboolean nm_device_set_ip_config (NMDevice *self, int addr_family, @@ -13887,7 +13941,8 @@ _set_state_full (NMDevice *self, if (ip_config_valid (old_state) && !ip_config_valid (state)) notify_ip_properties (self); - nm_device_check_connectivity_update_interval (self); + concheck_update_interval (self, + state == NM_DEVICE_STATE_ACTIVATED); /* Dispose of the cached activation request */ if (req) diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 66720f01..0d4d5cf8 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -73,7 +73,6 @@ nm_device_state_reason_check (NMDeviceStateReason reason) #define NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "queued-state-change-" #define NM_PENDING_ACTIONPREFIX_ACTIVATION "activation-" - /* Properties */ #define NM_DEVICE_UDI "udi" #define NM_DEVICE_IFACE "interface" @@ -189,9 +188,10 @@ typedef enum { /*< skip >*/ NM_DEVICE_CHECK_DEV_AVAILABLE_ALL = (1L << 1) - 1, } NMDeviceCheckDevAvailableFlags; -typedef struct { +typedef struct _NMDeviceClass { NMDBusObjectClass parent; + struct _NMDeviceClass *default_type_description_klass; const char *default_type_description; const char *connection_type; @@ -717,7 +717,7 @@ void nm_device_queue_state (NMDevice *self, gboolean nm_device_get_firmware_missing (NMDevice *self); -void nm_device_steal_connection (NMDevice *device, NMSettingsConnection *connection); +void nm_device_disconnect_active_connection (NMActiveConnection *active); void nm_device_queue_activation (NMDevice *device, NMActRequest *req); diff --git a/src/devices/ovs/meson.build b/src/devices/ovs/meson.build index 7b1c4617..f4edd57c 100644 --- a/src/devices/ovs/meson.build +++ b/src/devices/ovs/meson.build @@ -19,7 +19,7 @@ libnm_device_plugin_ovs = shared_module( link_args: ldflags_linker_script_devices, link_depends: linker_script_devices, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_device_plugin_ovs diff --git a/src/devices/ovs/nm-device-ovs-port.c b/src/devices/ovs/nm-device-ovs-port.c index 3f1fe974..91cf4f4d 100644 --- a/src/devices/ovs/nm-device-ovs-port.c +++ b/src/devices/ovs/nm-device-ovs-port.c @@ -70,7 +70,6 @@ get_generic_capabilities (NMDevice *device) return NM_DEVICE_CAP_IS_SOFTWARE; } - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { diff --git a/src/devices/ovs/nm-ovsdb.c b/src/devices/ovs/nm-ovsdb.c index b8f5a935..a9cb5703 100644 --- a/src/devices/ovs/nm-ovsdb.c +++ b/src/devices/ovs/nm-ovsdb.c @@ -363,7 +363,7 @@ _insert_interface (json_t *params, NMConnection *interface) json_pack ("{s:s, s:s, s:{s:s, s:s, s:o, s:[s, [[s, s]]]}, s:s}", "op", "insert", "table", "Interface", "row", "name", nm_connection_get_interface_name (interface), - "type", type ? type : "", + "type", type ?: "", "options", options, "external_ids", "map", "NM.connection.uuid", nm_connection_get_uuid (interface), "uuid-name", "rowInterface")); @@ -891,7 +891,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) _LOGT ("removed an '%s' interface: %s%s%s", ovs_interface->type, ovs_interface->name, ovs_interface->connection_uuid ? ", " : "", - ovs_interface->connection_uuid ? ovs_interface->connection_uuid : ""); + ovs_interface->connection_uuid ?: ""); if (g_strcmp0 (ovs_interface->type, "internal") == 0) { /* Currently the factory only creates NMDevices for * internal interfaces. Ignore the rest. */ @@ -910,14 +910,14 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) if (old) { _LOGT ("changed an '%s' interface: %s%s%s", type, ovs_interface->name, ovs_interface->connection_uuid ? ", " : "", - ovs_interface->connection_uuid ? ovs_interface->connection_uuid : ""); + ovs_interface->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_CHANGED], 0, "ovs-interface", ovs_interface->name); } else { _LOGT ("added an '%s' interface: %s%s%s", ovs_interface->type, ovs_interface->name, ovs_interface->connection_uuid ? ", " : "", - ovs_interface->connection_uuid ? ovs_interface->connection_uuid : ""); + ovs_interface->connection_uuid ?: ""); if (g_strcmp0 (ovs_interface->type, "internal") == 0) { /* Currently the factory only creates NMDevices for * internal interfaces. Ignore the rest. */ @@ -949,7 +949,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) old = FALSE; _LOGT ("removed a port: %s%s%s", ovs_port->name, ovs_port->connection_uuid ? ", " : "", - ovs_port->connection_uuid ? ovs_port->connection_uuid : ""); + ovs_port->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_REMOVED], 0, ovs_port->name, NM_DEVICE_TYPE_OVS_PORT); } @@ -965,13 +965,13 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) if (old) { _LOGT ("changed a port: %s%s%s", ovs_port->name, ovs_port->connection_uuid ? ", " : "", - ovs_port->connection_uuid ? ovs_port->connection_uuid : ""); + ovs_port->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_CHANGED], 0, NM_SETTING_OVS_PORT_SETTING_NAME, ovs_port->name); } else { _LOGT ("added a port: %s%s%s", ovs_port->name, ovs_port->connection_uuid ? ", " : "", - ovs_port->connection_uuid ? ovs_port->connection_uuid : ""); + ovs_port->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_ADDED], 0, ovs_port->name, NM_DEVICE_TYPE_OVS_PORT); } @@ -999,7 +999,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) old = FALSE; _LOGT ("removed a bridge: %s%s%s", ovs_bridge->name, ovs_bridge->connection_uuid ? ", " : "", - ovs_bridge->connection_uuid ? ovs_bridge->connection_uuid : ""); + ovs_bridge->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_REMOVED], 0, ovs_bridge->name, NM_DEVICE_TYPE_OVS_BRIDGE); } @@ -1015,13 +1015,13 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) if (old) { _LOGT ("changed a bridge: %s%s%s", ovs_bridge->name, ovs_bridge->connection_uuid ? ", " : "", - ovs_bridge->connection_uuid ? ovs_bridge->connection_uuid : ""); + ovs_bridge->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_CHANGED], 0, NM_SETTING_OVS_BRIDGE_SETTING_NAME, ovs_bridge->name); } else { _LOGT ("added a bridge: %s%s%s", ovs_bridge->name, ovs_bridge->connection_uuid ? ", " : "", - ovs_bridge->connection_uuid ? ovs_bridge->connection_uuid : ""); + ovs_bridge->connection_uuid ?: ""); g_signal_emit (self, signals[DEVICE_ADDED], 0, ovs_bridge->name, NM_DEVICE_TYPE_OVS_BRIDGE); } @@ -1153,7 +1153,6 @@ ovsdb_got_msg (NMOvsdb *self, json_t *msg) return; } - /* This is a message we are not interested in. */ _LOGW ("got an unknown message, ignoring"); } diff --git a/src/devices/team/meson.build b/src/devices/team/meson.build index 4a533bc5..159c182a 100644 --- a/src/devices/team/meson.build +++ b/src/devices/team/meson.build @@ -16,7 +16,7 @@ libnm_device_plugin_team = shared_module( link_args: ldflags_linker_script_devices, link_depends: linker_script_devices, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_device_plugin_team diff --git a/src/devices/tests/test-lldp.c b/src/devices/tests/test-lldp.c index 5d0625f8..c2ac8e19 100644 --- a/src/devices/tests/test-lldp.c +++ b/src/devices/tests/test-lldp.c @@ -169,7 +169,6 @@ _test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener) TEST_RECV_DATA_DEFINE (_test_recv_data0, 1, _test_recv_data0_check, &_test_recv_data0_frame0); TEST_RECV_DATA_DEFINE (_test_recv_data0_twice, 1, _test_recv_data0_check, &_test_recv_data0_frame0, &_test_recv_data0_frame0); - TEST_RECV_FRAME_DEFINE (_test_recv_data1_frame0, /* lldp.detailed.pcap from * https://wiki.wireshark.org/SampleCaptures#Link_Layer_Discovery_Protocol_.28LLDP.29 */ diff --git a/src/devices/wifi/meson.build b/src/devices/wifi/meson.build index 27eaeea6..a27f8e6a 100644 --- a/src/devices/wifi/meson.build +++ b/src/devices/wifi/meson.build @@ -28,7 +28,7 @@ libnm_device_plugin_wifi = shared_module( link_args: ldflags_linker_script_devices, link_depends: linker_script_devices, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_device_plugin_wifi diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c index eeff5bd3..d3c5ae9a 100644 --- a/src/devices/wifi/nm-device-iwd.c +++ b/src/devices/wifi/nm-device-iwd.c @@ -236,7 +236,7 @@ get_ordered_networks_cb (GObject *source, GAsyncResult *res, gpointer user_data) GVariantIter *networks; const gchar *path, *name, *type; int16_t signal; - NMWifiAP *ap, *ap_safe; + NMWifiAP *ap, *ap_safe, *new_ap; gboolean changed = FALSE; GHashTableIter ap_iter; gs_unref_hashtable GHashTable *new_aps = NULL; @@ -309,10 +309,10 @@ get_ordered_networks_cb (GObject *source, GAsyncResult *res, gpointer user_data) c_list_for_each_entry_safe (ap, ap_safe, &priv->aps_lst_head, aps_lst) { - ap = g_hash_table_lookup (new_aps, - nm_wifi_ap_get_supplicant_path (ap)); - if (ap) { - if (nm_wifi_ap_set_strength (ap, nm_wifi_ap_get_strength (ap))) { + new_ap = g_hash_table_lookup (new_aps, + nm_wifi_ap_get_supplicant_path (ap)); + if (new_ap) { + if (nm_wifi_ap_set_strength (ap, nm_wifi_ap_get_strength (new_ap))) { _ap_dump (self, LOGL_TRACE, ap, "updated", 0); changed = TRUE; } diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index cd2c68af..fd7bf3f7 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -177,7 +177,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) nm_device_get_iface (priv->companion)); } - /* wait with continuing configuration untill the companion device is done scanning */ g_object_get (priv->companion, NM_DEVICE_WIFI_SCANNING, &scanning, NULL); if (scanning) { diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index de4af42c..90f94557 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -2147,9 +2147,9 @@ supplicant_iface_notify_current_bss (NMSupplicantInterface *iface, } _LOGD (LOGD_WIFI, "roamed from BSSID %s (%s) to %s (%s)", - old_bssid ? old_bssid : "(none)", + old_bssid ?: "(none)", old_ssid ? nm_utils_escape_ssid (old_ssid->data, old_ssid->len) : "(none)", - new_bssid ? new_bssid : "(none)", + new_bssid ?: "(none)", new_ssid ? nm_utils_escape_ssid (new_ssid->data, new_ssid->len) : "(none)"); set_current_ap (self, new_ap, TRUE); @@ -2833,7 +2833,6 @@ handle_ip_config_timeout (NMDeviceWifi *self, return ret; } - static NMActStageReturn act_stage4_ip4_config_timeout (NMDevice *device, NMDeviceStateReason *out_failure_reason) { diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c index 450009f0..39db3a04 100644 --- a/src/devices/wifi/nm-iwd-manager.c +++ b/src/devices/wifi/nm-iwd-manager.c @@ -157,7 +157,6 @@ return_error: "No PSK available for this connection"); } - static guint psk_agent_export (GDBusConnection *connection, gpointer user_data, gchar **agent_path, GError **error) diff --git a/src/devices/wifi/nm-wifi-common.c b/src/devices/wifi/nm-wifi-common.c index 47c0ce67..e5e16f03 100644 --- a/src/devices/wifi/nm-wifi-common.c +++ b/src/devices/wifi/nm-wifi-common.c @@ -69,6 +69,7 @@ _dispatch_request_scan (NMDevice *device, _nm_device_iwd_request_scan (NM_DEVICE_IWD (device), options, invocation); + return; } #endif _nm_device_wifi_request_scan (NM_DEVICE_WIFI (device), diff --git a/src/devices/wwan/meson.build b/src/devices/wwan/meson.build index 032b3585..abf58594 100644 --- a/src/devices/wwan/meson.build +++ b/src/devices/wwan/meson.build @@ -25,7 +25,7 @@ libnm_wwan = shared_module( ], link_depends: linker_script, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) libnm_wwan_dep = declare_dependency( @@ -54,7 +54,7 @@ libnm_device_plugin_wwan = shared_module( link_args: ldflags_linker_script_devices, link_depends: linker_script_devices, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_device_plugin_wwan diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 9a3744db..e5678b96 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -286,7 +286,7 @@ create_gsm_connect_properties (NMConnection *connection) /* Blank APN ("") means the default subscription APN */ str = nm_setting_gsm_get_apn (setting); - mm_simple_connect_properties_set_apn (properties, str ? str : ""); + mm_simple_connect_properties_set_apn (properties, str ?: ""); str = nm_setting_gsm_get_network_id (setting); if (str) @@ -924,7 +924,6 @@ static_stage3_ip4_done (NMModemBroadband *self) _LOGI (" address %s/%d", address_string, address.plen); - nm_modem_get_route_parameters (NM_MODEM (self), &ip4_route_table, &ip4_route_metric, @@ -1283,7 +1282,6 @@ get_sim_ready (MMModem *modem, GError *error = NULL; MMSim *new_sim; - new_sim = mm_modem_get_sim_finish (modem, res, &error); if (new_sim != self->_priv.sim_iface) { g_clear_object (&self->_priv.sim_iface); diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index a1c6aef2..8b81ac41 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -278,7 +278,6 @@ deactivate_cleanup (NMModem *modem, NMDevice *device) NM_MODEM_CLASS (nm_modem_ofono_parent_class)->deactivate_cleanup (modem, device); } - static gboolean check_connection_compatible (NMModem *modem, NMConnection *connection) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 61b7247e..fbe99cc3 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -205,7 +205,7 @@ nm_modem_set_state (NMModem *self, _LOGI ("modem state changed, '%s' --> '%s' (reason: %s)", nm_modem_state_to_string (old_state), nm_modem_state_to_string (new_state), - reason ? reason : "none"); + reason ?: "none"); priv->state = new_state; _notify (self, PROP_STATE); @@ -1131,6 +1131,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device) if (priv->ppp_manager) { g_signal_handlers_disconnect_by_data (priv->ppp_manager, self); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); g_clear_object (&priv->ppp_manager); } @@ -1176,11 +1177,19 @@ typedef struct { GSimpleAsyncResult *result; DeactivateContextStep step; NMPPPManager *ppp_manager; + NMPPPManagerStopHandle *ppp_stop_handle; + gulong ppp_stop_cancellable_id; } DeactivateContext; static void deactivate_context_complete (DeactivateContext *ctx) { + if (ctx->ppp_stop_handle) + nm_ppp_manager_stop_cancel (ctx->ppp_stop_handle); + + nm_assert (!ctx->ppp_stop_handle); + nm_assert (ctx->ppp_stop_cancellable_id == 0); + if (ctx->ppp_manager) g_object_unref (ctx->ppp_manager); if (ctx->cancellable) @@ -1222,26 +1231,37 @@ disconnect_ready (NMModem *self, static void ppp_manager_stop_ready (NMPPPManager *ppp_manager, - GAsyncResult *res, - DeactivateContext *ctx) + NMPPPManagerStopHandle *handle, + gboolean was_cancelled, + gpointer user_data) { - NMModem *self = ctx->self; - GError *error = NULL; + DeactivateContext *ctx = user_data; - if (!nm_ppp_manager_stop_finish (ppp_manager, res, &error)) { - _LOGW ("cannot stop PPP manager: %s", - error->message); - g_simple_async_result_take_error (ctx->result, error); - deactivate_context_complete (ctx); - return; + nm_assert (ctx->ppp_stop_handle == handle); + ctx->ppp_stop_handle = NULL; + + if (ctx->ppp_stop_cancellable_id) { + g_cancellable_disconnect (ctx->cancellable, + nm_steal_int (&ctx->ppp_stop_cancellable_id)); } - /* Go on */ + if (was_cancelled) + return; + ctx->step++; deactivate_step (ctx); } static void +ppp_manager_stop_cancelled (GCancellable *cancellable, + gpointer user_data) +{ + DeactivateContext *ctx = user_data; + + nm_ppp_manager_stop_cancel (ctx->ppp_stop_handle); +} + +static void deactivate_step (DeactivateContext *ctx) { NMModem *self = ctx->self; @@ -1270,10 +1290,16 @@ deactivate_step (DeactivateContext *ctx) case DEACTIVATE_CONTEXT_STEP_PPP_MANAGER_STOP: /* If we have a PPP manager, stop it */ if (ctx->ppp_manager) { - nm_ppp_manager_stop_async (ctx->ppp_manager, - ctx->cancellable, - (GAsyncReadyCallback) ppp_manager_stop_ready, - ctx); + nm_assert (!ctx->ppp_stop_handle); + if (ctx->cancellable) { + ctx->ppp_stop_cancellable_id = g_cancellable_connect (ctx->cancellable, + G_CALLBACK (ppp_manager_stop_cancelled), + ctx, + NULL); + } + ctx->ppp_stop_handle = nm_ppp_manager_stop (ctx->ppp_manager, + ppp_manager_stop_ready, + ctx); return; } ctx->step++; @@ -1312,7 +1338,9 @@ nm_modem_deactivate_async (NMModem *self, callback, user_data, nm_modem_deactivate_async); - ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; + /* FIXME(shutdown): we always require a cancellable, otherwise we cannot + * do a coordinated shutdown. */ + ctx->cancellable = nm_g_object_ref (cancellable); /* Start */ ctx->step = DEACTIVATE_CONTEXT_STEP_FIRST; diff --git a/src/devices/wwan/nm-wwan-factory.c b/src/devices/wwan/nm-wwan-factory.c index f0aae040..a561b58a 100644 --- a/src/devices/wwan/nm-wwan-factory.c +++ b/src/devices/wwan/nm-wwan-factory.c @@ -105,7 +105,6 @@ modem_added_cb (NMModemManager *manager, g_object_unref (device); } - static NMDevice * create_device (NMDeviceFactory *factory, const char *iface, diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index 96c02653..ba517606 100644 --- a/src/dhcp/nm-dhcp-client.c +++ b/src/dhcp/nm-dhcp-client.c @@ -334,7 +334,7 @@ nm_dhcp_client_stop_pid (pid_t pid, const char *iface) g_return_if_fail (pid > 1); - nm_utils_kill_child_sync (pid, SIGTERM, LOGD_DHCP, name ? name : "dhcp-client", NULL, + nm_utils_kill_child_sync (pid, SIGTERM, LOGD_DHCP, name ?: "dhcp-client", NULL, 1000 / 2, 1000 / 20); g_free (name); } @@ -359,26 +359,25 @@ stop (NMDhcpClient *self, gboolean release, GBytes *duid) void nm_dhcp_client_set_state (NMDhcpClient *self, NMDhcpState new_state, - GObject *ip_config, + NMIPConfig *ip_config, GHashTable *options) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self); gs_free char *event_id = NULL; + if (new_state == NM_DHCP_STATE_BOUND) { + g_return_if_fail (NM_IS_IP_CONFIG (ip_config, priv->addr_family)); + g_return_if_fail (options); + } else { + g_return_if_fail (!ip_config); + g_return_if_fail (!options); + } + if (new_state >= NM_DHCP_STATE_BOUND) timeout_cleanup (self); if (new_state >= NM_DHCP_STATE_TIMEOUT) watch_cleanup (self); - if (new_state == NM_DHCP_STATE_BOUND) { - g_assert ( (priv->addr_family == AF_INET && NM_IS_IP4_CONFIG (ip_config)) - || (priv->addr_family == AF_INET6 && NM_IS_IP6_CONFIG (ip_config))); - g_assert (options); - } else { - g_assert (ip_config == NULL); - g_assert (options == NULL); - } - /* The client may send same-state transitions for RENEW/REBIND events and * the lease may have changed, so handle same-state transitions for the * BOUND state. Ignore same-state transitions for other events since @@ -660,8 +659,10 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name) out: if (remove (pid_file) == -1) { - nm_log_dbg (LOGD_DHCP, "dhcp: could not remove pid file \"%s\": %d (%s)", - pid_file, errno, g_strerror (errno)); + int errsv = errno; + + nm_log_dbg (LOGD_DHCP, "dhcp: could not remove pid file \"%s\": %s (%d)", + pid_file, g_strerror (errsv), errsv); } } @@ -736,14 +737,6 @@ maybe_add_option (NMDhcpClient *self, GVariant *value) { char *str_value = NULL; - const char **p; - static const char *ignored_keys[] = { - "interface", - "pid", - "reason", - "dhcp_message_type", - NULL - }; g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_BYTESTRING)); @@ -751,10 +744,11 @@ maybe_add_option (NMDhcpClient *self, return; /* Filter out stuff that's not actually new DHCP options */ - for (p = ignored_keys; *p; p++) { - if (!strcmp (*p, key)) - return; - } + if (NM_IN_STRSET (key, "interface", + "pid", + "reason", + "dhcp_message_type")) + return; if (g_str_has_prefix (key, NEW_TAG)) key += NM_STRLEN (NEW_TAG); @@ -777,8 +771,8 @@ nm_dhcp_client_handle_event (gpointer unused, NMDhcpClientPrivate *priv; guint32 old_state; guint32 new_state; - GHashTable *str_options = NULL; - GObject *ip_config = NULL; + gs_unref_hashtable GHashTable *str_options = NULL; + gs_unref_object NMIPConfig *ip_config = NULL; NMPlatformIP6Address prefix = { 0, }; g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE); @@ -822,24 +816,24 @@ nm_dhcp_client_handle_event (gpointer unused, } /* Create the IP config */ - g_warn_if_fail (g_hash_table_size (str_options)); - if (g_hash_table_size (str_options)) { + if (g_hash_table_size (str_options) > 0) { if (priv->addr_family == AF_INET) { - ip_config = (GObject *) nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self), - priv->ifindex, - priv->iface, - str_options, - priv->route_table, - priv->route_metric); + ip_config = NM_IP_CONFIG_CAST (nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self), + priv->ifindex, + priv->iface, + str_options, + priv->route_table, + priv->route_metric)); } else { prefix = nm_dhcp_utils_ip6_prefix_from_options (str_options); - ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self), - priv->ifindex, - priv->iface, - str_options, - priv->info_only); + ip_config = NM_IP_CONFIG_CAST (nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self), + priv->ifindex, + priv->iface, + str_options, + priv->info_only)); } - } + } else + g_warn_if_reached (); } if (!IN6_IS_ADDR_UNSPECIFIED (&prefix.address)) { @@ -851,7 +845,8 @@ nm_dhcp_client_handle_event (gpointer unused, &prefix); } else { /* Fail if no valid IP config was received */ - if (new_state == NM_DHCP_STATE_BOUND && ip_config == NULL) { + if ( new_state == NM_DHCP_STATE_BOUND + && !ip_config) { _LOGW ("client bound but IP config not received"); new_state = NM_DHCP_STATE_FAIL; g_clear_pointer (&str_options, g_hash_table_unref); @@ -860,10 +855,6 @@ nm_dhcp_client_handle_event (gpointer unused, nm_dhcp_client_set_state (self, new_state, ip_config, str_options); } - if (str_options) - g_hash_table_destroy (str_options); - g_clear_object (&ip_config); - return TRUE; } diff --git a/src/dhcp/nm-dhcp-client.h b/src/dhcp/nm-dhcp-client.h index 0d92d743..111b063b 100644 --- a/src/dhcp/nm-dhcp-client.h +++ b/src/dhcp/nm-dhcp-client.h @@ -48,7 +48,6 @@ #define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed" #define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated" - typedef enum { NM_DHCP_STATE_UNKNOWN = 0, NM_DHCP_STATE_BOUND, /* new lease or lease changed */ @@ -169,7 +168,7 @@ void nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid); void nm_dhcp_client_set_state (NMDhcpClient *self, NMDhcpState new_state, - GObject *ip_config, /* NMIP4Config or NMIP6Config */ + NMIPConfig *ip_config, GHashTable *options); /* str:str hash */ gboolean nm_dhcp_client_handle_event (gpointer unused, diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index 52923310..16a76d23 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -95,7 +95,6 @@ grab_request_options (GPtrArray *store, const char* line) return end; } - static void add_hostname4 (GString *str, const char *hostname, gboolean use_fqdn) { diff --git a/src/dhcp/nm-dhcp-dhclient.c b/src/dhcp/nm-dhcp-dhclient.c index 738e9f91..93306ddd 100644 --- a/src/dhcp/nm-dhcp-dhclient.c +++ b/src/dhcp/nm-dhcp-dhclient.c @@ -127,11 +127,13 @@ get_dhclient_leasefile (int addr_family, _addr_family_to_path_part (addr_family), uuid, iface); - if (out_preferred_path) - *out_preferred_path = g_strdup (path); - if (g_file_test (path, G_FILE_TEST_EXISTS)) + if (g_file_test (path, G_FILE_TEST_EXISTS)) { + NM_SET_OUT (out_preferred_path, g_strdup (path)); return path; + } + + NM_SET_OUT (out_preferred_path, g_steal_pointer (&path)); /* If the leasefile we're looking for doesn't exist yet in the new location * (eg, /var/lib/NetworkManager) then look in old locations to maintain @@ -262,7 +264,6 @@ find_existing_config (NMDhcpDhclient *self, int addr_family, const char *iface, return NULL; } - /* NM provides interface-specific options; thus the same dhclient config * file cannot be used since DHCP transactions can happen in parallel. * Since some distros don't have default per-interface dhclient config files, @@ -308,7 +309,6 @@ create_dhclient_config (NMDhcpDhclient *self, return new; } - static gboolean dhclient_start (NMDhcpClient *client, const char *mode_opt, @@ -319,20 +319,23 @@ dhclient_start (NMDhcpClient *client, { NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client); NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self); - GPtrArray *argv = NULL; + gs_unref_ptrarray GPtrArray *argv = NULL; pid_t pid; GError *error = NULL; - const char *iface, *uuid, *system_bus_address, *dhclient_path = NULL; - char *binary_name, *cmd_str, *pid_file = NULL, *system_bus_address_env = NULL; - int addr_family; - gboolean success; - char *escaped, *preferred_leasefile_path = NULL; + const char *iface; + const char *uuid; + const char *system_bus_address; + const char *dhclient_path; + char *binary_name; + gs_free char *cmd_str = NULL; + gs_free char *pid_file = NULL; + gs_free char *system_bus_address_env = NULL; + gs_free char *preferred_leasefile_path = NULL; + const int addr_family = nm_dhcp_client_get_addr_family (client); - g_return_val_if_fail (priv->pid_file == NULL, FALSE); + g_return_val_if_fail (!priv->pid_file, FALSE); - iface = nm_dhcp_client_get_iface (client); - uuid = nm_dhcp_client_get_uuid (client); - addr_family = nm_dhcp_client_get_addr_family (client); + NM_SET_OUT (out_pid, 0); dhclient_path = nm_dhcp_dhclient_get_path (); if (!dhclient_path) { @@ -340,6 +343,9 @@ dhclient_start (NMDhcpClient *client, return FALSE; } + iface = nm_dhcp_client_get_iface (client); + uuid = nm_dhcp_client_get_uuid (client); + pid_file = g_strdup_printf (RUNSTATEDIR "/dhclient%s-%s.pid", _addr_family_to_path_part (addr_family), iface); @@ -351,18 +357,18 @@ dhclient_start (NMDhcpClient *client, if (release) { /* release doesn't use the pidfile after killing an old client */ - g_free (pid_file); - pid_file = NULL; + nm_clear_g_free (&pid_file); } g_free (priv->lease_file); priv->lease_file = get_dhclient_leasefile (addr_family, iface, uuid, &preferred_leasefile_path); + nm_assert (preferred_leasefile_path); if (!priv->lease_file) { /* No existing leasefile, dhclient will create one at the preferred path */ - priv->lease_file = g_strdup (preferred_leasefile_path); - } else if (g_strcmp0 (priv->lease_file, preferred_leasefile_path) != 0) { - GFile *src = g_file_new_for_path (priv->lease_file); - GFile *dst = g_file_new_for_path (preferred_leasefile_path); + priv->lease_file = g_steal_pointer (&preferred_leasefile_path); + } else if (!nm_streq0 (priv->lease_file, preferred_leasefile_path)) { + gs_unref_object GFile *src = g_file_new_for_path (priv->lease_file); + gs_unref_object GFile *dst = g_file_new_for_path (preferred_leasefile_path); /* Try to copy the existing leasefile to the preferred location */ if (g_file_copy (src, dst, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) { @@ -376,19 +382,16 @@ dhclient_start (NMDhcpClient *client, error->message); g_clear_error (&error); } - g_object_unref (src); - g_object_unref (dst); } - g_free (preferred_leasefile_path); /* Save the DUID to the leasefile dhclient will actually use */ if (addr_family == AF_INET6) { + gs_free char *escaped = NULL; + escaped = nm_dhcp_dhclient_escape_duid (duid); - success = nm_dhcp_dhclient_save_duid (priv->lease_file, escaped, &error); - g_free (escaped); - if (!success) { + if (!nm_dhcp_dhclient_save_duid (priv->lease_file, escaped, &error)) { _LOGW ("failed to save DUID to %s: %s", priv->lease_file, error->message); - g_free (pid_file); + g_clear_error (&error); return FALSE; } } @@ -440,34 +443,29 @@ dhclient_start (NMDhcpClient *client, g_ptr_array_add (argv, (gpointer) system_bus_address_env); } - g_ptr_array_add (argv, (gpointer) iface); g_ptr_array_add (argv, NULL); - cmd_str = g_strjoinv (" ", (gchar **) argv->pdata); - _LOGD ("running: %s", cmd_str); - g_free (cmd_str); - - if (g_spawn_async (NULL, (char **) argv->pdata, NULL, - G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, - nm_utils_setpgid, NULL, &pid, &error)) { - g_assert (pid > 0); - _LOGI ("dhclient started with pid %d", pid); - if (release == FALSE) - nm_dhcp_client_watch_child (client, pid); - priv->pid_file = pid_file; - } else { + _LOGD ("running: %s", + (cmd_str = g_strjoinv (" ", (gchar **) argv->pdata))); + + if (!g_spawn_async (NULL, (char **) argv->pdata, NULL, + G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, + nm_utils_setpgid, NULL, &pid, &error)) { _LOGW ("dhclient failed to start: '%s'", error->message); g_error_free (error); - g_free (pid_file); + return FALSE; } - if (out_pid) - *out_pid = pid; + _LOGI ("dhclient started with pid %lld", (long long int) pid); + + if (!release) + nm_dhcp_client_watch_child (client, pid); + + priv->pid_file = g_steal_pointer (&pid_file); - g_ptr_array_free (argv, TRUE); - g_free (system_bus_address_env); - return pid > 0 ? TRUE : FALSE; + NM_SET_OUT (out_pid, pid); + return TRUE; } static gboolean @@ -547,10 +545,12 @@ stop (NMDhcpClient *client, gboolean release, GBytes *duid) if (remove (priv->conf_file) == -1) _LOGD ("could not remove dhcp config file \"%s\": %d (%s)", priv->conf_file, errno, g_strerror (errno)); if (priv->pid_file) { - if (remove (priv->pid_file) == -1) - _LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno)); - g_free (priv->pid_file); - priv->pid_file = NULL; + if (remove (priv->pid_file) == -1) { + int errsv = errno; + + _LOGD ("could not remove dhcp pid file \"%s\": %s (%d)", priv->pid_file, g_strerror (errsv), errsv); + } + nm_clear_g_free (&priv->pid_file); } if (release) { @@ -607,7 +607,7 @@ get_duid (NMDhcpClient *client) g_free (leasefile); } - if (!duid && priv->def_leasefile) { + if (!duid) { /* Otherwise read the default machine-wide DUID */ _LOGD ("looking for default DUID in '%s'", priv->def_leasefile); duid = nm_dhcp_dhclient_read_duid (priv->def_leasefile, &error); @@ -625,31 +625,25 @@ get_duid (NMDhcpClient *client) /*****************************************************************************/ -static const char *def_leasefiles[] = { - SYSCONFDIR "/dhclient6.leases", - LOCALSTATEDIR "/lib/dhcp/dhclient6.leases", - LOCALSTATEDIR "/lib/dhclient/dhclient6.leases", - NULL -}; - static void nm_dhcp_dhclient_init (NMDhcpDhclient *self) { + static const char *const FILES[] = { + SYSCONFDIR "/dhclient6.leases", /* default */ + LOCALSTATEDIR "/lib/dhcp/dhclient6.leases", + LOCALSTATEDIR "/lib/dhclient/dhclient6.leases", + }; NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self); - const char **iter = &def_leasefiles[0]; + int i; - while (iter && *iter) { - if (g_file_test (*iter, G_FILE_TEST_EXISTS)) { - priv->def_leasefile = *iter; + priv->def_leasefile = FILES[0]; + for (i = 0; i < G_N_ELEMENTS (FILES); i++) { + if (g_file_test (FILES[i], G_FILE_TEST_EXISTS)) { + priv->def_leasefile = FILES[i]; break; } - iter++; } - /* Fallback option */ - if (!priv->def_leasefile) - priv->def_leasefile = SYSCONFDIR "/dhclient6.leases"; - priv->dhcp_listener = g_object_ref (nm_dhcp_listener_get ()); g_signal_connect (priv->dhcp_listener, NM_DHCP_LISTENER_EVENT, diff --git a/src/dhcp/nm-dhcp-dhcpcanon.c b/src/dhcp/nm-dhcp-dhcpcanon.c index 82b3db4f..12aa57aa 100644 --- a/src/dhcp/nm-dhcp-dhcpcanon.c +++ b/src/dhcp/nm-dhcp-dhcpcanon.c @@ -76,7 +76,6 @@ nm_dhcp_dhcpcanon_get_path (void) return nm_utils_find_helper ("dhcpcanon", DHCPCANON_PATH, NULL); } - static gboolean dhcpcanon_start (NMDhcpClient *client, const char *mode_opt, @@ -142,7 +141,6 @@ dhcpcanon_start (NMDhcpClient *client, g_ptr_array_add (argv, (gpointer) system_bus_address_env); } - g_ptr_array_add (argv, (gpointer) iface); g_ptr_array_add (argv, NULL); diff --git a/src/dhcp/nm-dhcp-listener.c b/src/dhcp/nm-dhcp-listener.c index d7d38e54..1770ead3 100644 --- a/src/dhcp/nm-dhcp-listener.c +++ b/src/dhcp/nm-dhcp-listener.c @@ -160,7 +160,7 @@ _method_call_handle (NMDhcpListener *self, pid_str = get_option (options, "pid"); pid = _nm_utils_ascii_str_to_int64 (pid_str, 10, 0, G_MAXINT32, -1); if (pid == -1) { - _LOGW ("dhcp-event: couldn't convert PID '%s' to an integer", pid_str ? pid_str : "(null)"); + _LOGW ("dhcp-event: couldn't convert PID '%s' to an integer", pid_str ?: "(null)"); return; } diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index bf22872d..aa40e803 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -311,7 +311,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self, if (send_hostname) { /* Always prefer the explicit dhcp-hostname if given */ - hostname = dhcp_hostname ? dhcp_hostname : priv->default_hostname; + hostname = dhcp_hostname ?: priv->default_hostname; } return client_start (self, AF_INET6, multi_idx, iface, ifindex, hwaddr, uuid, route_table, route_metric, ll_addr, diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index 4f37f069..2d0202bb 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -513,7 +513,7 @@ bound4_handle (NMDhcpSystemd *self) nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_BOUND, - G_OBJECT (ip4_config), + NM_IP_CONFIG_CAST (ip4_config), options); } else { _LOGW ("%s", error->message); @@ -667,7 +667,6 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last } } - /* Add requested options */ for (i = 0; dhcp4_requests[i].name; i++) { if (dhcp4_requests[i].include) @@ -823,7 +822,7 @@ bound6_handle (NMDhcpSystemd *self) if (ip6_config) { nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_BOUND, - G_OBJECT (ip6_config), + NM_IP_CONFIG_CAST (ip6_config), options); } else { _LOGW ("%s", error->message); diff --git a/src/dhcp/tests/meson.build b/src/dhcp/tests/meson.build index 32badae8..9d8be427 100644 --- a/src/dhcp/tests/meson.build +++ b/src/dhcp/tests/meson.build @@ -8,7 +8,7 @@ foreach test_unit: test_units test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: '-DTESTDIR="@0@"'.format(meson.current_source_dir()) + c_args: nm_build_cflags, ) test( diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index 25af51a1..a8284b23 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -36,6 +36,8 @@ #include "nm-test-utils-core.h" +#define TEST_DIR NM_BUILD_SRCDIR"/src/dhcp/tests" + static void test_config (const char *orig, const char *expected, @@ -736,7 +738,7 @@ test_read_duid_from_leasefile (void) gconstpointer duid_arr; gsize duid_len; - duid = nm_dhcp_dhclient_read_duid (TESTDIR "/test-dhclient-duid.leases", &error); + duid = nm_dhcp_dhclient_read_duid (TEST_DIR"/test-dhclient-duid.leases", &error); g_assert_no_error (error); g_assert (duid); duid_arr = g_bytes_get_data (duid, &duid_len); @@ -750,7 +752,7 @@ test_read_commented_duid_from_leasefile (void) GBytes *duid; GError *error = NULL; - duid = nm_dhcp_dhclient_read_duid (TESTDIR "/test-dhclient-commented-duid.leases", &error); + duid = nm_dhcp_dhclient_read_duid (TEST_DIR"/test-dhclient-commented-duid.leases", &error); g_assert_no_error (error); g_assert (duid == NULL); } diff --git a/src/dns/nm-dns-dnsmasq.c b/src/dns/nm-dns-dnsmasq.c index d0753078..b5b93280 100644 --- a/src/dns/nm-dns-dnsmasq.c +++ b/src/dns/nm-dns-dnsmasq.c @@ -75,53 +75,6 @@ G_DEFINE_TYPE (NMDnsDnsmasq, nm_dns_dnsmasq, NM_TYPE_DNS_PLUGIN) /*****************************************************************************/ -static char ** -get_ip_rdns_domains (NMIPConfig *ip_config) -{ - int addr_family = nm_ip_config_get_addr_family (ip_config); - char **strv; - GPtrArray *domains = NULL; - NMDedupMultiIter ipconf_iter; - - nm_assert_addr_family (addr_family); - - domains = g_ptr_array_sized_new (5); - - if (addr_family == AF_INET) { - NMIP4Config *ip4 = (gpointer) ip_config; - const NMPlatformIP4Address *address; - const NMPlatformIP4Route *route; - - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &address) - nm_utils_get_reverse_dns_domains_ip4 (address->address, address->plen, domains); - - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route) { - if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) - nm_utils_get_reverse_dns_domains_ip4 (route->network, route->plen, domains); - } - } else { - NMIP6Config *ip6 = (gpointer) ip_config; - const NMPlatformIP6Address *address; - const NMPlatformIP6Route *route; - - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &address) - nm_utils_get_reverse_dns_domains_ip6 (&address->address, address->plen, domains); - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route) { - if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) - nm_utils_get_reverse_dns_domains_ip6 (&route->network, route->plen, domains); - } - } - - /* Terminating NULL so we can use g_strfreev() to free it */ - g_ptr_array_add (domains, NULL); - - /* Free the array and return NULL if the only element was the ending NULL */ - strv = (char **) g_ptr_array_free (domains, (domains->len == 1)); - - return _nm_utils_strv_cleanup (strv, FALSE, FALSE, TRUE); -} - static void add_dnsmasq_nameserver (NMDnsDnsmasq *self, GVariantBuilder *servers, @@ -206,91 +159,34 @@ add_global_config (NMDnsDnsmasq *self, GVariantBuilder *dnsmasq_servers, const N } static void -add_ip_config (NMDnsDnsmasq *self, - GVariantBuilder *servers, - int ifindex, - NMIPConfig *ip_config, - gboolean split) +add_ip_config (NMDnsDnsmasq *self, GVariantBuilder *servers, const NMDnsIPConfigData *ip_data) { - int addr_family; + NMIPConfig *ip_config = ip_data->ip_config; gconstpointer addr; - gboolean added = FALSE; - guint nnameservers, i_nameserver, n, i; + const char *iface, *domain; char ip_addr_to_string_buf[IP_ADDR_TO_STRING_BUFLEN]; - char **domains, **iter; - gboolean iface_resolved = FALSE; - const char *iface = NULL, *domain; + int addr_family; + guint i, j, num; + iface = nm_platform_link_get_name (NM_PLATFORM_GET, ip_data->data->ifindex); addr_family = nm_ip_config_get_addr_family (ip_config); - g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); - nm_assert (ifindex > 0); - nm_assert (ifindex == nm_ip_config_get_ifindex (ip_config)); - - nnameservers = nm_ip_config_get_num_nameservers (ip_config); - - if (split) { - if (nnameservers == 0) - return; - - if (!iface_resolved) { - iface = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex); - iface_resolved = TRUE; + num = nm_ip_config_get_num_nameservers (ip_config); + for (i = 0; i < num; i++) { + addr = nm_ip_config_get_nameserver (ip_config, i); + ip_addr_to_string (addr_family, addr, iface, ip_addr_to_string_buf); + for (j = 0; ip_data->domains.search[j]; j++) { + domain = nm_utils_parse_dns_domain (ip_data->domains.search[j], NULL); + add_dnsmasq_nameserver (self, + servers, + ip_addr_to_string_buf, + domain[0] ? domain : NULL); } - if (iface) { - for (i_nameserver = 0; i_nameserver < nnameservers; i_nameserver++) { - addr = nm_ip_config_get_nameserver (ip_config, i_nameserver); - - ip_addr_to_string (addr_family, addr, iface, ip_addr_to_string_buf); - - /* searches are preferred over domains */ - n = nm_ip_config_get_num_searches (ip_config); - for (i = 0; i < n; i++) { - domain = nm_utils_parse_dns_domain (nm_ip_config_get_search (ip_config, i), NULL); - add_dnsmasq_nameserver (self, - servers, - ip_addr_to_string_buf, - domain); - added = TRUE; - } - - if (n == 0) { - /* If not searches, use any domains */ - n = nm_ip_config_get_num_domains (ip_config); - domain = nm_utils_parse_dns_domain (nm_ip_config_get_domain (ip_config, i), NULL); - for (i = 0; i < n; i++) { - add_dnsmasq_nameserver (self, - servers, - ip_addr_to_string_buf, - domain); - added = TRUE; - } - } - - /* Ensure reverse-DNS works by directing queries for in-addr4.arpa/ip6.arpa - * domains to the split domain's nameserver. - */ - domains = get_ip_rdns_domains (ip_config); - if (domains) { - for (iter = domains; *iter; iter++) - add_dnsmasq_nameserver (self, servers, ip_addr_to_string_buf, *iter); - g_strfreev (domains); - } - } - } - } - - /* If no searches or domains, just add the nameservers */ - if (!added) { - if (!iface_resolved) - iface = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex); - if (iface) { - for (i = 0; i < nnameservers; i++) { - addr = nm_ip_config_get_nameserver (ip_config, i); - ip_addr_to_string (addr_family, addr, iface, ip_addr_to_string_buf); - add_dnsmasq_nameserver (self, servers, ip_addr_to_string_buf, NULL); - } + for (j = 0; ip_data->domains.reverse[j]; j++) { + add_dnsmasq_nameserver (self, servers, + ip_addr_to_string_buf, + ip_data->domains.reverse[j]); } } } @@ -487,9 +383,7 @@ update (NMDnsPlugin *plugin, NMDnsDnsmasq *self = NM_DNS_DNSMASQ (plugin); NMDnsDnsmasqPrivate *priv = NM_DNS_DNSMASQ_GET_PRIVATE (self); GVariantBuilder servers; - int prio, first_prio = 0; const NMDnsIPConfigData *ip_data; - gboolean is_first = TRUE; start_dnsmasq (self); @@ -498,19 +392,8 @@ update (NMDnsPlugin *plugin, if (global_config) add_global_config (self, &servers, global_config); else { - c_list_for_each_entry (ip_data, ip_config_lst_head, ip_config_lst) { - prio = nm_ip_config_get_dns_priority (ip_data->ip_config); - if (is_first) { - is_first = FALSE; - first_prio = prio; - } else if (first_prio < 0 && first_prio != prio) - break; - add_ip_config (self, - &servers, - ip_data->data->ifindex, - ip_data->ip_config, - ip_data->ip_config_type == NM_DNS_IP_CONFIG_TYPE_VPN); - } + c_list_for_each_entry (ip_data, ip_config_lst_head, ip_config_lst) + add_ip_config (self, &servers, ip_data); } g_clear_pointer (&priv->set_server_ex_args, g_variant_unref); diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c index 10a16e57..f5500ee7 100644 --- a/src/dns/nm-dns-manager.c +++ b/src/dns/nm-dns-manager.c @@ -232,7 +232,7 @@ _ASSERT_ip_config_data (const NMDnsIPConfigData *ip_data) { nm_assert (ip_data); _ASSERT_config_data (ip_data->data); - nm_assert (NM_IS_IP_CONFIG (ip_data->ip_config)); + nm_assert (NM_IS_IP_CONFIG (ip_data->ip_config, AF_UNSPEC)); nm_assert (c_list_contains (&ip_data->data->data_lst_head, &ip_data->data_lst)); nm_assert (ip_data->data->ifindex == nm_ip_config_get_ifindex (ip_data->ip_config)); } @@ -245,7 +245,7 @@ _ip_config_data_new (NMDnsConfigData *data, NMDnsIPConfigData *ip_data; _ASSERT_config_data (data); - nm_assert (NM_IS_IP_CONFIG (ip_config)); + nm_assert (NM_IS_IP_CONFIG (ip_config, AF_UNSPEC)); nm_assert (ip_config_type != NM_DNS_IP_CONFIG_TYPE_REMOVED); ip_data = g_slice_new0 (NMDnsIPConfigData); @@ -273,6 +273,9 @@ _ip_config_data_free (NMDnsIPConfigData *ip_data) c_list_unlink_stale (&ip_data->data_lst); c_list_unlink_stale (&ip_data->ip_config_lst); + g_free (ip_data->domains.search); + g_strfreev (ip_data->domains.reverse); + g_signal_handlers_disconnect_by_func (ip_data->ip_config, _ip_config_dns_priority_changed, ip_data); @@ -1136,6 +1139,197 @@ _collect_resolv_conf_data (NMDnsManager *self, *out_nis_domain = rc.nis_domain; } +static char ** +get_ip_rdns_domains (NMIPConfig *ip_config) +{ + int addr_family = nm_ip_config_get_addr_family (ip_config); + char **strv; + GPtrArray *domains = NULL; + NMDedupMultiIter ipconf_iter; + + nm_assert_addr_family (addr_family); + + domains = g_ptr_array_sized_new (5); + + if (addr_family == AF_INET) { + NMIP4Config *ip4 = (gpointer) ip_config; + const NMPlatformIP4Address *address; + const NMPlatformIP4Route *route; + + nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &address) + nm_utils_get_reverse_dns_domains_ip4 (address->address, address->plen, domains); + + nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route) { + if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) + nm_utils_get_reverse_dns_domains_ip4 (route->network, route->plen, domains); + } + } else { + NMIP6Config *ip6 = (gpointer) ip_config; + const NMPlatformIP6Address *address; + const NMPlatformIP6Route *route; + + nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &address) + nm_utils_get_reverse_dns_domains_ip6 (&address->address, address->plen, domains); + + nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route) { + if (!NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) + nm_utils_get_reverse_dns_domains_ip6 (&route->network, route->plen, domains); + } + } + + /* Terminating NULL so we can use g_strfreev() to free it */ + g_ptr_array_add (domains, NULL); + + /* Free the array and return NULL if the only element was the ending NULL */ + strv = (char **) g_ptr_array_free (domains, (domains->len == 1)); + + return _nm_utils_strv_cleanup (strv, FALSE, FALSE, TRUE); +} + +/* Check if the domain is shadowed by a parent domain with more negative priority */ +static gboolean +domain_is_shadowed (GHashTable *ht, + const char *domain, int priority, + const char **out_parent, int *out_parent_priority) +{ + char *parent; + int parent_priority; + + nm_assert (!g_hash_table_contains (ht, domain)); + + parent_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, "")); + if (parent_priority < 0 && parent_priority < priority) { + *out_parent = ""; + *out_parent_priority = parent_priority; + return TRUE; + } + + parent = strchr (domain, '.'); + while (parent && parent[1]) { + parent++; + parent_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, parent)); + if (parent_priority < 0 && parent_priority < priority) { + *out_parent = parent; + *out_parent_priority = parent_priority; + return TRUE; + } + parent = strchr (parent, '.'); + } + + return FALSE; +} + +static void +rebuild_domain_lists (NMDnsManager *self) +{ + NMDnsIPConfigData *ip_data; + gs_unref_hashtable GHashTable *ht = NULL; + gboolean default_route_found = FALSE; + CList *head; + + ht = g_hash_table_new (nm_str_hash, g_str_equal); + + head = _ip_config_lst_head (self); + c_list_for_each_entry (ip_data, head, ip_config_lst) { + NMIPConfig *ip_config = ip_data->ip_config; + + if (!nm_ip_config_get_num_nameservers (ip_config)) + continue; + if (nm_ip_config_best_default_route_get (ip_config)) { + default_route_found = TRUE; + break; + } + } + + c_list_for_each_entry (ip_data, head, ip_config_lst) { + NMIPConfig *ip_config = ip_data->ip_config; + int priority, old_priority; + guint i, n, n_domains = 0; + const char **domains; + + if (!nm_ip_config_get_num_nameservers (ip_config)) + continue; + + priority = nm_ip_config_get_dns_priority (ip_config); + nm_assert (priority != 0); + g_free (ip_data->domains.search); + domains = g_new0 (const char *, + 2 + NM_MAX (nm_ip_config_get_num_searches (ip_config), + nm_ip_config_get_num_domains (ip_config))); + ip_data->domains.search = domains; + + /* Add wildcard lookup domain to connections with the default route. + * If there is no default route, add the wildcard domain to all non-VPN + * connections */ + if (default_route_found) { + if (nm_ip_config_best_default_route_get (ip_config)) + domains[n_domains++] = "~"; + } else { + if (ip_data->ip_config_type != NM_DNS_IP_CONFIG_TYPE_VPN) + domains[n_domains++] = "~"; + } + + /* searches are preferred over domains */ + n = nm_ip_config_get_num_searches (ip_config); + for (i = 0; i < n; i++) + domains[n_domains++] = nm_ip_config_get_search (ip_config, i); + + if (n == 0) { + /* If not searches, use any domains */ + n = nm_ip_config_get_num_domains (ip_config); + for (i = 0; i < n; i++) + domains[n_domains++] = nm_ip_config_get_domain (ip_config, i); + } + + n = 0; + for (i = 0; i < n_domains; i++) { + const char *domain_clean; + const char *parent; + int parent_priority; + + domain_clean = nm_utils_parse_dns_domain (domains[i], NULL); + + /* Remove domains with lower priority */ + old_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, domain_clean)); + if (old_priority) { + if (old_priority < priority) { + _LOGT ("plugin: drop domain '%s' (i=%d, p=%d) because it already exists with p=%d", + domains[i], ip_data->data->ifindex, + priority, old_priority); + continue; + } + } else if (domain_is_shadowed (ht, domain_clean, priority, &parent, &parent_priority)) { + _LOGT ("plugin: drop domain '%s' (i=%d, p=%d) shadowed by '%s' (p=%d)", + domains[i], + ip_data->data->ifindex, priority, + parent, parent_priority); + continue; + } + + _LOGT ("plugin: add domain '%s' (i=%d, p=%d)", domains[i], ip_data->data->ifindex, priority); + g_hash_table_insert (ht, (gpointer) domain_clean, GINT_TO_POINTER (priority)); + domains[n++] = domains[i]; + } + domains[n] = NULL; + + g_strfreev (ip_data->domains.reverse); + ip_data->domains.reverse = get_ip_rdns_domains (ip_config); + } +} + +static void +clear_domain_lists (NMDnsManager *self) +{ + NMDnsIPConfigData *ip_data; + CList *head; + + head = _ip_config_lst_head (self); + c_list_for_each_entry (ip_data, head, ip_config_lst) { + g_clear_pointer (&ip_data->domains.search, g_free); + g_clear_pointer (&ip_data->domains.reverse, g_strfreev); + } +} + static gboolean update_dns (NMDnsManager *self, gboolean no_caching, @@ -1198,6 +1392,7 @@ update_dns (NMDnsManager *self, } _LOGD ("update-dns: updating plugin %s", plugin_name); + rebuild_domain_lists (self); if (!nm_dns_plugin_update (plugin, global_config, _ip_config_lst_head (self), @@ -1209,6 +1404,10 @@ update_dns (NMDnsManager *self, */ caching = FALSE; } + /* Clear the generated search list as it points to + * strings owned by IP configurations and we can't + * guarantee they stay alive. */ + clear_domain_lists (self); skip: ; @@ -1363,7 +1562,7 @@ nm_dns_manager_set_ip_config (NMDnsManager *self, NMDnsIPConfigData **p_best; g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE); - g_return_val_if_fail (NM_IS_IP_CONFIG (ip_config), FALSE); + g_return_val_if_fail (NM_IS_IP_CONFIG (ip_config, AF_UNSPEC), FALSE); ifindex = nm_ip_config_get_ifindex (ip_config); g_return_val_if_fail (ifindex > 0, FALSE); @@ -1951,7 +2150,6 @@ _get_config_variant (NMDnsManager *self) "nameservers", g_variant_builder_end (&strv_builder)); - num = nm_ip_config_get_num_domains (ip_config); num += nm_ip_config_get_num_searches (ip_config); if (num > 0) { diff --git a/src/dns/nm-dns-manager.h b/src/dns/nm-dns-manager.h index 56889367..ed1974a5 100644 --- a/src/dns/nm-dns-manager.h +++ b/src/dns/nm-dns-manager.h @@ -50,6 +50,10 @@ typedef struct { CList data_lst; CList ip_config_lst; NMDnsIPConfigType ip_config_type; + struct { + const char **search; + char **reverse; + } domains; } NMDnsIPConfigData; typedef struct _NMDnsConfigData { diff --git a/src/dns/nm-dns-systemd-resolved.c b/src/dns/nm-dns-systemd-resolved.c index 7da27e5f..1a73aae1 100644 --- a/src/dns/nm-dns-systemd-resolved.c +++ b/src/dns/nm-dns-systemd-resolved.c @@ -139,47 +139,36 @@ static void update_add_ip_config (NMDnsSystemdResolved *self, GVariantBuilder *dns, GVariantBuilder *domains, - NMIPConfig *config) + NMDnsIPConfigData *data) { int addr_family; gsize addr_size; guint i, n; gboolean is_routing; + const char **iter; const char *domain; - addr_family = nm_ip_config_get_addr_family (config); + addr_family = nm_ip_config_get_addr_family (data->ip_config); addr_size = nm_utils_addr_family_to_size (addr_family); - n = nm_ip_config_get_num_nameservers (config); + if (!data->domains.search || !data->domains.search[0]) + return; + + n = nm_ip_config_get_num_nameservers (data->ip_config); for (i = 0 ; i < n; i++) { g_variant_builder_open (dns, G_VARIANT_TYPE ("(iay)")); g_variant_builder_add (dns, "i", addr_family); g_variant_builder_add_value (dns, g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, - nm_ip_config_get_nameserver (config, i), + nm_ip_config_get_nameserver (data->ip_config, i), addr_size, 1)); g_variant_builder_close (dns); } - n = nm_ip_config_get_num_searches (config); - if (n > 0) { - for (i = 0; i < n; i++) { - domain = nm_utils_parse_dns_domain (nm_ip_config_get_search (config, i), - &is_routing); - g_variant_builder_add (domains, "(sb)", - domain, - is_routing); - } - } else { - n = nm_ip_config_get_num_domains (config); - for (i = 0; i < n; i++) { - domain = nm_utils_parse_dns_domain (nm_ip_config_get_domain (config, i), - &is_routing); - g_variant_builder_add (domains, "(sb)", - domain, - is_routing); - } + for (iter = data->domains.search; *iter; iter++) { + domain = nm_utils_parse_dns_domain (*iter, &is_routing); + g_variant_builder_add (domains, "(sb)", domain[0] ? domain : ".", is_routing); } } @@ -214,9 +203,10 @@ prepare_one_interface (NMDnsSystemdResolved *self, InterfaceConfig *ic) g_variant_builder_open (&domains, G_VARIANT_TYPE ("a(sb)")); c_list_for_each_entry (elem, &ic->configs_lst_head, lst) { - NMIPConfig *ip_config = elem->data; + NMDnsIPConfigData *data = elem->data; + NMIPConfig *ip_config = data->ip_config; - update_add_ip_config (self, &dns, &domains, ip_config); + update_add_ip_config (self, &dns, &domains, data); if (NM_IS_IP4_CONFIG (ip_config)) mdns = NM_MAX (mdns, nm_ip4_config_mdns_get (NM_IP4_CONFIG (ip_config))); @@ -292,25 +282,15 @@ update (NMDnsPlugin *plugin, gs_free gpointer *interfaces_keys = NULL; guint interfaces_len; guint i; - int prio, first_prio = 0; NMDnsIPConfigData *ip_data; - gboolean is_first = TRUE; interfaces = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) _interface_config_free); c_list_for_each_entry (ip_data, ip_config_lst_head, ip_config_lst) { - gboolean skip = FALSE; InterfaceConfig *ic = NULL; int ifindex; - prio = nm_ip_config_get_dns_priority (ip_data->ip_config); - if (is_first) { - is_first = FALSE; - first_prio = prio; - } else if (first_prio < 0 && first_prio != prio) - skip = TRUE; - ifindex = ip_data->data->ifindex; nm_assert (ifindex == nm_ip_config_get_ifindex (ip_data->ip_config)); @@ -322,10 +302,8 @@ update (NMDnsPlugin *plugin, g_hash_table_insert (interfaces, GINT_TO_POINTER (ifindex), ic); } - if (!skip) { - c_list_link_tail (&ic->configs_lst_head, - &nm_c_list_elem_new_stale (ip_data->ip_config)->lst); - } + c_list_link_tail (&ic->configs_lst_head, + &nm_c_list_elem_new_stale (ip_data)->lst); } free_pending_updates (self); diff --git a/src/dnsmasq/tests/meson.build b/src/dnsmasq/tests/meson.build index 40f42f6f..12106c52 100644 --- a/src/dnsmasq/tests/meson.build +++ b/src/dnsmasq/tests/meson.build @@ -4,7 +4,6 @@ exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: '-DTESTDIR="@0@"'.format(meson.source_root()) ) test( diff --git a/src/main.c b/src/main.c index bd8e26a5..c1267b27 100644 --- a/src/main.c +++ b/src/main.c @@ -214,7 +214,7 @@ do_early_setup (int *argc, char **argv[], NMConfigCmdLineOptions *config_cli) _("NetworkManager monitors all network connections and automatically\nchooses the best connection to use. It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with."))) exit (1); - global_opt.pidfile = global_opt.pidfile ? global_opt.pidfile : g_strdup (NM_DEFAULT_PID_FILE); + global_opt.pidfile = global_opt.pidfile ?: g_strdup(NM_DEFAULT_PID_FILE); } /* @@ -225,7 +225,7 @@ int main (int argc, char *argv[]) { gboolean success = FALSE; - NMManager *manager; + NMManager *manager = NULL; NMConfig *config; GError *error = NULL; gboolean wrote_pidfile = FALSE; @@ -395,12 +395,13 @@ main (int argc, char *argv[]) NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT, NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT_BOOL)); - manager = nm_manager_setup (); + if (!nm_dbus_manager_acquire_bus (nm_dbus_manager_get ())) + goto done_no_manager; - if (!nm_dbus_manager_start (nm_dbus_manager_get (), - nm_manager_dbus_set_property_handle, - manager)) - goto done; + manager = nm_manager_setup (); + nm_dbus_manager_start (nm_dbus_manager_get(), + nm_manager_dbus_set_property_handle, + manager); nm_dispatcher_init (); @@ -442,17 +443,13 @@ done: * it misses to update the state. */ nm_manager_write_device_state (manager); - /* FIXME: we don't properly shut down on exit. That is a bug. - * NMDBusObject have an assertion that they get unexported before disposing. - * We need this workaround and disable the assertion during our leaky shutdown. */ - nm_dbus_object_set_quitting (); - nm_manager_stop (manager); nm_config_state_set (config, TRUE, TRUE); nm_dns_manager_stop (nm_dns_manager_get ()); +done_no_manager: if (global_opt.pidfile && wrote_pidfile) unlink (global_opt.pidfile); diff --git a/src/meson.build b/src/meson.build index 591c9c79..e60ab93f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -29,7 +29,7 @@ cflags = nm_cflags + [ '-DRUNDIR="@0@"'.format(nm_pkgrundir), '-DNMCONFDIR="@0@"'.format(nm_pkgconfdir), '-DNMLOCALEDIR="@0@"'.format(nm_localedir), - '-DNMPLUGINDIR="@0@"'.format(nm_pkglibdir), + '-DNMPLUGINDIR="@0@"'.format(nm_plugindir), '-DNMRUNDIR="@0@"'.format(nm_pkgrundir), '-DNMSTATEDIR="@0@"'.format(nm_pkgstatedir), '-DNMLIBDIR="@0@"'.format(nm_pkglibdir) diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index c6d6645d..aa83d6d5 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -55,7 +55,12 @@ typedef struct _NMActiveConnectionPrivate { bool master_ready:1; NMActivationType activation_type:3; - NMActivationReason activation_reason:3; + + /* capture the original reason why the connection was activated. + * For example with NM_ACTIVATION_REASON_ASSUME, the connection + * will later change to become fully managed. But the original + * reason never changes. */ + NMActivationReason activation_reason:4; NMAuthSubject *subject; NMActiveConnection *master; @@ -67,8 +72,7 @@ typedef struct _NMActiveConnectionPrivate { NMAuthManagerCallId *call_id_wifi_shared_permission; NMActiveConnectionAuthResultFunc result_func; - gpointer user_data1; - gpointer user_data2; + gpointer user_data; } auth; } NMActiveConnectionPrivate; @@ -125,6 +129,8 @@ static void _settings_connection_flags_changed (NMSettingsConnection *settings_c NMActiveConnection *self); static void _set_activation_type_managed (NMActiveConnection *self); +static void auth_complete (NMActiveConnection *self, gboolean result, const char *message); + /*****************************************************************************/ #define _NMLOG_DOMAIN LOGD_DEVICE @@ -236,13 +242,13 @@ nm_active_connection_set_state (NMActiveConnection *self, NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); NMActiveConnectionState old_state; + /* DEACTIVATED is a terminal state */ + g_return_if_fail ( priv->state != NM_ACTIVE_CONNECTION_STATE_DEACTIVATED + || new_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); + if (priv->state == new_state) return; - /* DEACTIVATED is a terminal state */ - if (priv->state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) - g_return_if_fail (new_state != NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); - _LOGD ("set state %s (was %s)", state_to_string (new_state), state_to_string (priv->state)); @@ -288,6 +294,10 @@ nm_active_connection_set_state (NMActiveConnection *self, } if (priv->state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { + _nm_unused gs_unref_object NMActiveConnection *self_keep_alive = g_object_ref (self); + + auth_complete (self, FALSE, "Authorization request cancelled"); + /* Device is no longer relevant when deactivated. So remove it and * emit property change notification so clients re-read the value, * which will be NULL due to conditions in get_property(). @@ -426,7 +436,7 @@ _set_applied_connection_take (NMActiveConnection *self, if (nm_setting_connection_get_master (s_con)) flags_val |= NM_ACTIVATION_STATE_FLAG_IS_SLAVE; - if (+_nm_connection_type_is_master (nm_setting_connection_get_connection_type (s_con))) + if (_nm_connection_type_is_master (nm_setting_connection_get_connection_type (s_con))) flags_val |= NM_ACTIVATION_STATE_FLAG_IS_MASTER; nm_active_connection_set_state_flags_full (self, @@ -986,9 +996,11 @@ nm_active_connection_set_parent (NMActiveConnection *self, NMActiveConnection *p /*****************************************************************************/ static void -auth_cancel (NMActiveConnection *self) +auth_complete (NMActiveConnection *self, gboolean result, const char *message) { NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); + NMActiveConnectionAuthResultFunc result_func; + gpointer user_data; if (priv->auth.call_id_network_control) nm_auth_manager_check_authorization_cancel (priv->auth.call_id_network_control); @@ -998,23 +1010,27 @@ auth_cancel (NMActiveConnection *self) else nm_auth_manager_check_authorization_cancel (priv->auth.call_id_wifi_shared_permission); } - priv->auth.result_func = NULL; - priv->auth.user_data1 = NULL; - priv->auth.user_data2 = NULL; + + nm_assert (!priv->auth.call_id_network_control); + nm_assert (!priv->auth.call_id_wifi_shared_permission); + if (priv->auth.result_func) { + result_func = priv->auth.result_func; + priv->auth.result_func = NULL; + user_data = g_steal_pointer (&priv->auth.user_data); + + result_func (self, + result, + message, + user_data); + } } static void -auth_complete (NMActiveConnection *self, gboolean result, const char *message) +auth_complete_keep_alive (NMActiveConnection *self, gboolean result, const char *message) { _nm_unused gs_unref_object NMActiveConnection *self_keep_alive = g_object_ref (self); - NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); - priv->auth.result_func (self, - result, - message, - priv->auth.user_data1, - priv->auth.user_data2); - auth_cancel (self); + auth_complete (self, result, message); } static void @@ -1048,7 +1064,7 @@ auth_done (NMAuthManager *auth_mgr, if (auth_call_id == priv->auth.call_id_network_control) { priv->auth.call_id_network_control = NULL; if (result != NM_AUTH_CALL_RESULT_YES) { - auth_complete (self, FALSE, "Not authorized to control networking."); + auth_complete_keep_alive (self, FALSE, "Not authorized to control networking."); return; } } else { @@ -1068,11 +1084,11 @@ auth_done (NMAuthManager *auth_mgr, if (priv->auth.call_id_wifi_shared_permission) { if (priv->auth.call_id_wifi_shared_permission == AUTH_CALL_ID_SHARED_WIFI_PERMISSION_FAILED) - auth_complete (self, FALSE, "Not authorized to share connections via wifi."); + auth_complete_keep_alive (self, FALSE, "Not authorized to share connections via wifi."); return; } - auth_complete (self, TRUE, NULL); + auth_complete_keep_alive (self, TRUE, NULL); } /** @@ -1082,8 +1098,7 @@ auth_done (NMAuthManager *auth_mgr, * is no @settings_connection available when creating the active connection. * Instead pass an alternative connection. * @result_func: function to be called on success or error - * @user_data1: pointer passed to @result_func - * @user_data2: additional pointer passed to @result_func + * @user_data: pointer passed to @result_func * * Checks whether the subject that initiated the active connection (read from * the #NMActiveConnection::subject property) is authorized to complete this @@ -1093,8 +1108,7 @@ void nm_active_connection_authorize (NMActiveConnection *self, NMConnection *initial_connection, NMActiveConnectionAuthResultFunc result_func, - gpointer user_data1, - gpointer user_data2) + gpointer user_data) { NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); const char *wifi_permission = NULL; @@ -1133,10 +1147,8 @@ nm_active_connection_authorize (NMActiveConnection *self, self); } - /* Wait for authorization */ priv->auth.result_func = result_func; - priv->auth.user_data1 = user_data1; - priv->auth.user_data2 = user_data2; + priv->auth.user_data = user_data; } /*****************************************************************************/ @@ -1416,6 +1428,7 @@ constructed (GObject *object) } g_return_if_fail (priv->subject); + g_return_if_fail (priv->activation_reason != NM_ACTIVATION_REASON_UNSET); } static void @@ -1428,7 +1441,7 @@ dispose (GObject *object) _LOGD ("disposing"); - auth_cancel (self); + auth_complete (self, FALSE, "Authorization aborted"); nm_clear_g_free (&priv->specific_object); diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index c3d08b64..b28c2b02 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -109,14 +109,12 @@ GType nm_active_connection_get_type (void); typedef void (*NMActiveConnectionAuthResultFunc) (NMActiveConnection *self, gboolean success, const char *error_desc, - gpointer user_data1, - gpointer user_data2); + gpointer user_data); void nm_active_connection_authorize (NMActiveConnection *self, NMConnection *initial_connection, NMActiveConnectionAuthResultFunc result_func, - gpointer user_data1, - gpointer user_data2); + gpointer user_data); NMSettingsConnection *nm_active_connection_get_settings_connection (NMActiveConnection *self); NMConnection *nm_active_connection_get_applied_connection (NMActiveConnection *self); diff --git a/src/nm-audit-manager.c b/src/nm-audit-manager.c index 45d068f9..93bd9551 100644 --- a/src/nm-audit-manager.c +++ b/src/nm-audit-manager.c @@ -157,7 +157,6 @@ build_message (GPtrArray *fields, AuditBackend backend) return g_string_free (string, FALSE); } - static void nm_audit_log (NMAuditManager *self, GPtrArray *fields, const char *file, guint line, const char *func, gboolean success) diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c index 199a2e40..09a217ea 100644 --- a/src/nm-auth-manager.c +++ b/src/nm-auth-manager.c @@ -498,7 +498,7 @@ _dbus_new_proxy_cb (GObject *source_object, { NMAuthManager *self; NMAuthManagerPrivate *priv; - gs_free GError *error = NULL; + gs_free_error GError *error = NULL; GDBusProxy *proxy; NMAuthManagerCallId *call_id; diff --git a/src/nm-auth-subject.h b/src/nm-auth-subject.h index a9921dbd..9267dfd4 100644 --- a/src/nm-auth-subject.h +++ b/src/nm-auth-subject.h @@ -49,23 +49,18 @@ NMAuthSubject *nm_auth_subject_new_unix_process_from_context (GDBusMethodInvocat NMAuthSubject *nm_auth_subject_new_unix_process_from_message (GDBusConnection *connection, GDBusMessage *message); - NMAuthSubjectType nm_auth_subject_get_subject_type (NMAuthSubject *subject); - gboolean nm_auth_subject_is_internal (NMAuthSubject *subject); - gboolean nm_auth_subject_is_unix_process (NMAuthSubject *subject); gulong nm_auth_subject_get_unix_process_pid (NMAuthSubject *subject); const char *nm_auth_subject_get_unix_process_dbus_sender (NMAuthSubject *subject); - gulong nm_auth_subject_get_unix_process_uid (NMAuthSubject *subject); - const char *nm_auth_subject_to_string (NMAuthSubject *self, char *buf, gsize buf_len); GVariant * nm_auth_subject_unix_process_to_polkit_gvariant (NMAuthSubject *self); diff --git a/src/nm-checkpoint-manager.c b/src/nm-checkpoint-manager.c index 8ba19db9..7e8c8aea 100644 --- a/src/nm-checkpoint-manager.c +++ b/src/nm-checkpoint-manager.c @@ -224,7 +224,7 @@ nm_checkpoint_manager_destroy (NMCheckpointManager *self, g_return_val_if_fail (path && path[0] == '/', FALSE); g_return_val_if_fail (!error || !*error, FALSE); - if (!nm_streq (path, "/")) { + if (nm_streq (path, "/")) { nm_checkpoint_manager_destroy_all (self); return TRUE; } diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 5f19eabe..813ef9c8 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -1001,7 +1001,6 @@ load_global_dns (GKeyFile *keyfile, gboolean internal) return dns_config; } - void nm_global_dns_config_to_dbus (const NMGlobalDnsConfig *dns_config, GValue *value) { diff --git a/src/nm-config-data.h b/src/nm-config-data.h index a11b38b2..650fbe14 100644 --- a/src/nm-config-data.h +++ b/src/nm-config-data.h @@ -100,7 +100,6 @@ typedef enum { /*< flags >*/ /* main-file or config-description changed */ NM_CONFIG_CHANGE_CONFIG_FILES = (1L << 10), - /* any configuration on disk changed */ NM_CONFIG_CHANGE_VALUES = (1L << 11), @@ -110,7 +109,6 @@ typedef enum { /*< flags >*/ /* any internal configuration on disk changed (NetworkManager-intern.conf) */ NM_CONFIG_CHANGE_VALUES_INTERN = (1L << 13), - /* configuration regarding connectivity changed */ NM_CONFIG_CHANGE_CONNECTIVITY = (1L << 14), diff --git a/src/nm-config.c b/src/nm-config.c index bef05fc7..d4682ed6 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -579,7 +579,7 @@ ignore_config_snippet (GKeyFile *keyfile, gboolean is_base_config) const char *e; e = g_getenv ("NM_CONFIG_ENABLE_TAG"); - _nm_config_match_env = g_strdup (e ? e : ""); + _nm_config_match_env = g_strdup (e ?: ""); } /* second, interpret the value as match-spec. */ @@ -2407,7 +2407,7 @@ _set_config_data (NMConfig *self, NMConfigData *new_data, NMConfigChangeFlags re else _LOGI ("signal: %s", nm_config_change_flags_to_string (changes, NULL, 0)); g_signal_emit (self, signals[SIGNAL_CONFIG_CHANGED], 0, - new_data ? new_data : old_data, + new_data ?: old_data, changes, old_data); if (new_data) g_object_unref (old_data); diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index b97be0b8..b1a4cc25 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2044,8 +2044,8 @@ _log_connection_sort_hashes_fcn (gconstpointer a, gconstpointer b) NMSettingPriority p1, p2; NMSetting *s1, *s2; - s1 = v1->setting ? v1->setting : v1->diff_base_setting; - s2 = v2->setting ? v2->setting : v2->diff_base_setting; + s1 = v1->setting ?: v1->diff_base_setting; + s2 = v2->setting ?: v2->diff_base_setting; g_assert (s1 && s2); @@ -2279,13 +2279,13 @@ nm_utils_log_connection_diff (NMConnection *connection, g_string_printf (str1, "%s.%s", setting_data->name, item->item_name); switch (item->diff_result & (NM_SETTING_DIFF_RESULT_IN_A | NM_SETTING_DIFF_RESULT_IN_B)) { case NM_SETTING_DIFF_RESULT_IN_B: - nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s < %s", prefix, str1->str, str_diff ? str_diff : "NULL"); + nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s < %s", prefix, str1->str, str_diff ?: "NULL"); break; case NM_SETTING_DIFF_RESULT_IN_A: - nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s", prefix, str1->str, str_conn ? str_conn : "NULL"); + nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s", prefix, str1->str, str_conn ?: "NULL"); break; default: - nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s < %s", prefix, str1->str, str_conn ? str_conn : "NULL", str_diff ? str_diff : "NULL"); + nm_log (level, domain, NULL, NULL, "%s%"_NM_LOG_ALIGN"s = %s < %s", prefix, str1->str, str_conn ?: "NULL", str_diff ?: "NULL"); break; #undef _NM_LOG_ALIGN } @@ -2344,7 +2344,6 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ return timestamp - offset; } - #define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/" #define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/" G_STATIC_ASSERT (sizeof (IPV4_PROPERTY_DIR) == sizeof (IPV6_PROPERTY_DIR)); @@ -2798,53 +2797,103 @@ nm_utils_file_get_contents (int dirfd, /*****************************************************************************/ -guint8 * -nm_utils_secret_key_read (gsize *out_key_len, GError **error) +static gboolean +_secret_key_read (guint8 **out_secret_key, + gsize *out_key_len) { - guint8 *secret_key = NULL; + guint8 *secret_key; + gboolean success = TRUE; gsize key_len; - - /* out_key_len is not optional, because without it you cannot safely - * access the returned memory. */ - *out_key_len = 0; + gs_free_error GError *error = NULL; /* Let's try to load a saved secret key first. */ - if (g_file_get_contents (NMSTATEDIR "/secret_key", (char **) &secret_key, &key_len, NULL)) { - if (key_len < 16) { - g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, - "Key is too short to be usable"); - key_len = 0; - } + if (g_file_get_contents (NMSTATEDIR "/secret_key", (char **) &secret_key, &key_len, &error)) { + if (key_len >= 16) + goto out; + + /* the secret key is borked. Log a warning, but proceed below to generate + * a new one. */ + nm_log_warn (LOGD_CORE, "secret-key: too short secret key in \"%s\" (generate new key)", NMSTATEDIR "/secret_key"); + nm_clear_g_free (&secret_key); } else { - mode_t key_mask; + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { + nm_log_warn (LOGD_CORE, "secret-key: failure reading secret key in \"%s\": %s (generate new key)", + NMSTATEDIR "/secret_key", error->message); + } + g_clear_error (&error); + } - /* RFC7217 mandates the key SHOULD be at least 128 bits. - * Let's use twice as much. */ - key_len = 32; - secret_key = g_malloc (key_len); + /* RFC7217 mandates the key SHOULD be at least 128 bits. + * Let's use twice as much. */ + key_len = 32; + secret_key = g_malloc (key_len + 1); - if (!nm_utils_random_bytes (secret_key, key_len)) { - g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, - "Can't get random data to generate secret key"); - key_len = 0; - goto out; - } + /* the secret-key is binary. Still, ensure that it's NULL terminated, just like + * g_file_set_contents() does. */ + secret_key[32] = '\0'; - key_mask = umask (0077); - if (!g_file_set_contents (NMSTATEDIR "/secret_key", (char *) secret_key, key_len, error)) { - g_prefix_error (error, "Can't write " NMSTATEDIR "/secret_key: "); - key_len = 0; - } - umask (key_mask); + if (!nm_utils_random_bytes (secret_key, key_len)) { + nm_log_warn (LOGD_CORE, "secret-key: failure to generate good random data for secret-key (use non-persistent key)"); + success = FALSE; + goto out; + } + + if (!nm_utils_file_set_contents (NMSTATEDIR "/secret_key", (char *) secret_key, key_len, 0077, &error)) { + nm_log_warn (LOGD_CORE, "secret-key: failure to persist secret key in \"%s\" (%s) (use non-persistent key)", + NMSTATEDIR "/secret_key", error->message); + success = FALSE; + goto out; } out: - if (key_len) { - *out_key_len = key_len; - return secret_key; + /* regardless of success or failue, we always return a secret-key. The + * caller may choose to ignore the error and proceed. */ + *out_key_len = key_len; + *out_secret_key = secret_key; + return success; +} + +typedef struct { + const guint8 *secret_key; + gsize key_len; + bool is_good:1; +} SecretKeyData; + +gboolean +nm_utils_secret_key_get (const guint8 **out_secret_key, + gsize *out_key_len) +{ + static volatile const SecretKeyData *secret_key_static; + const SecretKeyData *secret_key; + + secret_key = g_atomic_pointer_get (&secret_key_static); + if (G_UNLIKELY (!secret_key)) { + static gsize init_value = 0; + static SecretKeyData secret_key_data; + gboolean tmp_success; + gs_free guint8 *tmp_secret_key = NULL; + gsize tmp_key_len; + + tmp_success = _secret_key_read (&tmp_secret_key, &tmp_key_len); + if (g_once_init_enter (&init_value)) { + secret_key_data.secret_key = tmp_secret_key; + secret_key_data.key_len = tmp_key_len; + secret_key_data.is_good = tmp_success; + + if (g_atomic_pointer_compare_and_exchange (&secret_key_static, NULL, &secret_key_data)) { + g_steal_pointer (&tmp_secret_key); + secret_key = &secret_key_data; + } + + g_once_init_leave (&init_value, 1); + } + if (!secret_key) + secret_key = g_atomic_pointer_get (&secret_key_static); } - g_free (secret_key); - return NULL; + + *out_secret_key = secret_key->secret_key; + *out_key_len = secret_key->key_len; + return secret_key->is_good; } /*****************************************************************************/ @@ -3132,8 +3181,9 @@ _stable_id_append (GString *str, NMUtilsStableType nm_utils_stable_id_parse (const char *stable_id, - const char *uuid, + const char *deviceid, const char *bootid, + const char *uuid, char **out_generated) { gsize i, idx_start; @@ -3208,6 +3258,8 @@ nm_utils_stable_id_parse (const char *stable_id, _stable_id_append (str, uuid); else if (CHECK_PREFIX ("${BOOT}")) _stable_id_append (str, bootid ?: nm_utils_get_boot_id ()); + else if (CHECK_PREFIX ("${DEVICE}")) + _stable_id_append (str, deviceid); else if (g_str_has_prefix (&stable_id[i], "${RANDOM}")) { /* RANDOM makes not so much sense for cloned-mac-address * as the result is simmilar to specyifing "cloned-mac-address=random". @@ -3284,7 +3336,7 @@ _set_stable_privacy (NMUtilsStableType stable_type, const char *ifname, const char *network_id, guint32 dad_counter, - guint8 *secret_key, + const guint8 *secret_key, gsize key_len, GError **error) { @@ -3383,8 +3435,8 @@ nm_utils_ipv6_addr_set_stable_privacy (NMUtilsStableType stable_type, guint32 dad_counter, GError **error) { - gs_free guint8 *secret_key = NULL; - gsize key_len = 0; + const guint8 *secret_key; + gsize key_len; g_return_val_if_fail (network_id, FALSE); @@ -3394,9 +3446,7 @@ nm_utils_ipv6_addr_set_stable_privacy (NMUtilsStableType stable_type, return FALSE; } - secret_key = nm_utils_secret_key_read (&key_len, error); - if (!secret_key) - return FALSE; + nm_utils_secret_key_get (&secret_key, &key_len); return _set_stable_privacy (stable_type, addr, ifname, network_id, dad_counter, secret_key, key_len, error); @@ -3532,14 +3582,12 @@ nm_utils_hw_addr_gen_stable_eth (NMUtilsStableType stable_type, const char *current_mac_address, const char *generate_mac_address_mask) { - gs_free guint8 *secret_key = NULL; - gsize key_len = 0; + const guint8 *secret_key; + gsize key_len; g_return_val_if_fail (stable_id, NULL); - secret_key = nm_utils_secret_key_read (&key_len, NULL); - if (!secret_key) - return NULL; + nm_utils_secret_key_get (&secret_key, &key_len); return _hw_addr_gen_stable_eth (stable_type, stable_id, @@ -4087,7 +4135,7 @@ nm_utils_read_plugin_paths (const char *dirname, const char *prefix) if (!g_str_has_prefix (item, prefix)) continue; - if (g_str_has_suffix (item, ".la")) + if (!g_str_has_suffix (item, ".so")) continue; data.path = g_build_filename (dirname, item, NULL); @@ -4173,6 +4221,28 @@ nm_utils_parse_dns_domain (const char *domain, gboolean *is_routing) /*****************************************************************************/ +GVariant * +nm_utils_strdict_to_variant (GHashTable *options) +{ + GVariantBuilder builder; + gs_free const char **keys = NULL; + guint i; + guint nkeys; + + keys = nm_utils_strdict_get_keys (options, TRUE, &nkeys); + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + for (i = 0; i < nkeys; i++) { + g_variant_builder_add (&builder, + "{sv}", + keys[i], + g_variant_new_string (g_hash_table_lookup (options, keys[i]))); + } + return g_variant_builder_end (&builder); +} + +/*****************************************************************************/ + NM_UTILS_ENUM2STR_DEFINE (nm_icmpv6_router_pref_to_string, NMIcmpv6RouterPref, NM_UTILS_ENUM2STR (NM_ICMPV6_ROUTER_PREF_LOW, "low"), NM_UTILS_ENUM2STR (NM_ICMPV6_ROUTER_PREF_MEDIUM, "medium"), diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index ec9e2947..7f406d21 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -158,7 +158,7 @@ double nm_utils_exp10 (gint16 e); static inline guint32 nm_utils_ip6_route_metric_normalize (guint32 metric) { - return metric ? metric : 1024 /*NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6*/; + return metric ?: 1024 /*NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6*/; } static inline guint32 @@ -283,7 +283,8 @@ gboolean nm_utils_file_set_contents (const gchar *filename, char *nm_utils_machine_id_read (void); gboolean nm_utils_machine_id_parse (const char *id_str, /*uuid_t*/ guchar *out_uuid); -guint8 *nm_utils_secret_key_read (gsize *out_key_len, GError **error); +gboolean nm_utils_secret_key_get (const guint8 **out_secret_key, + gsize *out_key_len); const char *nm_utils_get_boot_id (void); @@ -339,8 +340,9 @@ typedef enum { } NMUtilsStableType; NMUtilsStableType nm_utils_stable_id_parse (const char *stable_id, - const char *uuid, + const char *deviceid, const char *bootid, + const char *uuid, char **out_generated); char *nm_utils_stable_id_random (void); @@ -432,6 +434,8 @@ gboolean nm_utils_validate_plugin (const char *path, struct stat *stat, GError * char **nm_utils_read_plugin_paths (const char *dirname, const char *prefix); char *nm_utils_format_con_diff_for_audit (GHashTable *diff); +GVariant *nm_utils_strdict_to_variant (GHashTable *options); + /*****************************************************************************/ /* this enum is compatible with ICMPV6_ROUTER_PREF_* (from <linux/icmpv6.h>, diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 3e369129..7f1121f6 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -83,6 +83,8 @@ typedef struct { GDBusConnection *connection; GDBusProxy *proxy; guint objmgr_registration_id; + bool started:1; + bool shutting_down:1; } NMDBusManagerPrivate; struct _NMDBusManager { @@ -787,6 +789,8 @@ dbus_vtable_method_call (GDBusConnection *connection, GDBusMethodInvocation *invocation, gpointer user_data) { + NMDBusManager *self; + NMDBusManagerPrivate *priv; RegistrationData *reg_data = user_data; NMDBusObject *obj = reg_data->obj; const NMDBusInterfaceInfoExtended *interface_info = _reg_data_get_interface_info (reg_data); @@ -799,13 +803,14 @@ dbus_vtable_method_call (GDBusConnection *connection, if ( !on_same_interface && nm_streq (interface_name, DBUS_INTERFACE_PROPERTIES) && nm_streq (method_name, "Set")) { - NMDBusManager *self = nm_dbus_object_get_manager (obj); - NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); const NMDBusPropertyInfoExtended *property_info = NULL; const char *property_interface; const char *property_name; gs_unref_variant GVariant *value = NULL; + self = nm_dbus_object_get_manager (obj); + priv = NM_DBUS_MANAGER_GET_PRIVATE (self); + g_variant_get (parameters, "(&s&sv)", &property_interface, &property_name, &value); nm_assert (nm_streq (property_interface, interface_info->parent.name)); @@ -850,6 +855,17 @@ dbus_vtable_method_call (GDBusConnection *connection, return; } + self = nm_dbus_object_get_manager (obj); + priv = NM_DBUS_MANAGER_GET_PRIVATE (self); + if ( priv->shutting_down + && !method_info->allow_during_shutdown) { + g_dbus_method_invocation_return_error_literal (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_FAILED, + "NetworkManager is exiting"); + return; + } + method_info->handle (reg_data->obj, interface_info, method_info, @@ -930,6 +946,7 @@ _obj_register (NMDBusManager *self, nm_assert (c_list_is_empty (&obj->internal.registration_lst_head)); nm_assert (priv->connection); + nm_assert (priv->started); n_klasses = 0; gtype = G_OBJECT_TYPE (obj); @@ -1107,7 +1124,7 @@ _nm_dbus_manager_obj_export (NMDBusObject *obj) nm_assert_not_reached (); c_list_link_tail (&priv->objects_lst_head, &obj->internal.objects_lst); - if (priv->connection) + if (priv->connection && priv->started) _obj_register (self, obj); } @@ -1306,7 +1323,7 @@ _nm_dbus_manager_obj_emit_signal (NMDBusObject *obj, self = obj->internal.bus_manager; priv = NM_DBUS_MANAGER_GET_PRIVATE (self); - if (!priv->connection) { + if (!priv->connection || !priv->started) { nm_g_variant_unref_floating (args); return; } @@ -1453,29 +1470,41 @@ static const GDBusInterfaceInfo interface_info_objmgr = NM_DEFINE_GDBUS_INTERFAC /*****************************************************************************/ -gboolean +void nm_dbus_manager_start (NMDBusManager *self, NMDBusManagerSetPropertyHandler set_property_handler, gpointer set_property_handler_data) { NMDBusManagerPrivate *priv; + NMDBusObject *obj; + + g_return_if_fail (NM_IS_DBUS_MANAGER (self)); + priv = NM_DBUS_MANAGER_GET_PRIVATE (self); + g_return_if_fail (priv->connection); + + priv->set_property_handler = set_property_handler; + priv->set_property_handler_data = set_property_handler_data; + priv->started = TRUE; + + c_list_for_each_entry (obj, &priv->objects_lst_head, internal.objects_lst) + _obj_register (self, obj); +} + +gboolean +nm_dbus_manager_acquire_bus (NMDBusManager *self) +{ + NMDBusManagerPrivate *priv; gs_free_error GError *error = NULL; gs_unref_variant GVariant *ret = NULL; gs_unref_object GDBusConnection *connection = NULL; gs_unref_object GDBusProxy *proxy = NULL; guint32 result; guint registration_id; - NMDBusObject *obj; g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), FALSE); priv = NM_DBUS_MANAGER_GET_PRIVATE (self); - priv->set_property_handler = set_property_handler; - priv->set_property_handler_data = set_property_handler_data; - - g_return_val_if_fail (!priv->connection, FALSE); - /* we will create the D-Bus connection and registering the name synchronously. * The reason why that is necessary is because: * (1) if we are unable to create a D-Bus connection, it means D-Bus is not @@ -1527,7 +1556,7 @@ nm_dbus_manager_start (NMDBusManager *self, NULL, &error); if (!ret) { - _LOGE ("fatal failure to aquire D-Bus service \"%s"": %s", + _LOGE ("fatal failure to acquire D-Bus service \"%s"": %s", NM_DBUS_SERVICE, error->message); return FALSE; } @@ -1555,14 +1584,32 @@ nm_dbus_manager_start (NMDBusManager *self, priv->connection = g_steal_pointer (&connection); priv->proxy = g_steal_pointer (&proxy); - _LOGI ("aquired D-Bus service \"%s\"", NM_DBUS_SERVICE); - - c_list_for_each_entry (obj, &priv->objects_lst_head, internal.objects_lst) - _obj_register (self, obj); + _LOGI ("acquired D-Bus service \"%s\"", NM_DBUS_SERVICE); return TRUE; } +void +nm_dbus_manager_stop (NMDBusManager *self) +{ + NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); + + priv->shutting_down = TRUE; + + /* during shutdown we also clear the set-property-handler. It's no longer + * possible to set a property, because doing so would require authorization, + * which is async, which is just complicated to get right. No more property + * setting from now on. */ + priv->set_property_handler = NULL; + priv->set_property_handler_data = NULL; +} + +gboolean +nm_dbus_manager_is_stopping (NMDBusManager *self) +{ + return NM_DBUS_MANAGER_GET_PRIVATE (self)->shutting_down; +} + /*****************************************************************************/ static void diff --git a/src/nm-dbus-manager.h b/src/nm-dbus-manager.h index 617f8a67..a0741316 100644 --- a/src/nm-dbus-manager.h +++ b/src/nm-dbus-manager.h @@ -49,9 +49,15 @@ typedef void (*NMDBusManagerSetPropertyHandler) (NMDBusObject *obj, GVariant *value, gpointer user_data); -gboolean nm_dbus_manager_start (NMDBusManager *self, - NMDBusManagerSetPropertyHandler handler, - gpointer handler_data); +gboolean nm_dbus_manager_acquire_bus (NMDBusManager *self); + +void nm_dbus_manager_start (NMDBusManager *self, + NMDBusManagerSetPropertyHandler set_property_handler, + gpointer set_property_handler_data); + +void nm_dbus_manager_stop (NMDBusManager *self); + +gboolean nm_dbus_manager_is_stopping (NMDBusManager *self); GDBusConnection *nm_dbus_manager_get_connection (NMDBusManager *self); diff --git a/src/nm-dbus-object.c b/src/nm-dbus-object.c index 514fda49..e92a8f5f 100644 --- a/src/nm-dbus-object.c +++ b/src/nm-dbus-object.c @@ -26,17 +26,6 @@ /*****************************************************************************/ -static gboolean quitting = FALSE; - -void -nm_dbus_object_set_quitting (void) -{ - nm_assert (!quitting); - quitting = TRUE; -} - -/*****************************************************************************/ - enum { EXPORTED_CHANGED, @@ -291,7 +280,7 @@ dispose (GObject *object) * we are quitting, where many objects stick around until exit. */ if (self->internal.path) { - if (!quitting) + if (!nm_dbus_manager_is_stopping (nm_dbus_object_get_manager (self))) g_warn_if_reached (); nm_dbus_object_unexport (self); } diff --git a/src/nm-dbus-object.h b/src/nm-dbus-object.h index 43613630..8b3ffdbd 100644 --- a/src/nm-dbus-object.h +++ b/src/nm-dbus-object.h @@ -28,10 +28,6 @@ /*****************************************************************************/ -void nm_dbus_object_set_quitting (void); - -/*****************************************************************************/ - typedef struct { const char *path; diff --git a/src/nm-dbus-utils.h b/src/nm-dbus-utils.h index e7e930e9..1f8e96c4 100644 --- a/src/nm-dbus-utils.h +++ b/src/nm-dbus-utils.h @@ -122,6 +122,7 @@ typedef struct _NMDBusMethodInfoExtended { const char *sender, GDBusMethodInvocation *invocation, GVariant *parameters); + bool allow_during_shutdown; } NMDBusMethodInfoExtended; #define NM_DEFINE_DBUS_METHOD_INFO_EXTENDED(parent_, ...) \ diff --git a/src/nm-dhcp4-config.c b/src/nm-dhcp4-config.c index 08becf3c..ceafddf5 100644 --- a/src/nm-dhcp4-config.c +++ b/src/nm-dhcp4-config.c @@ -27,6 +27,7 @@ #include "nm-dbus-interface.h" #include "nm-utils.h" #include "nm-dbus-object.h" +#include "nm-core-utils.h" /*****************************************************************************/ @@ -58,22 +59,14 @@ nm_dhcp4_config_set_options (NMDhcp4Config *self, GHashTable *options) { NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self); - GHashTableIter iter; - const char *key, *value; - GVariantBuilder builder; + GVariant *val; g_return_if_fail (NM_IS_DHCP4_CONFIG (self)); - g_return_if_fail (options != NULL); + g_return_if_fail (options); + val = nm_utils_strdict_to_variant (options); g_variant_unref (priv->options); - - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - g_hash_table_iter_init (&iter, options); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) - g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value)); - - priv->options = g_variant_builder_end (&builder); - g_variant_ref_sink (priv->options); + priv->options = g_variant_ref_sink (val); _notify (self, PROP_OPTIONS); } diff --git a/src/nm-dhcp6-config.c b/src/nm-dhcp6-config.c index 5bb6c740..d477521a 100644 --- a/src/nm-dhcp6-config.c +++ b/src/nm-dhcp6-config.c @@ -27,6 +27,7 @@ #include "nm-dbus-interface.h" #include "nm-utils.h" #include "nm-dbus-object.h" +#include "nm-core-utils.h" /*****************************************************************************/ @@ -58,22 +59,14 @@ nm_dhcp6_config_set_options (NMDhcp6Config *self, GHashTable *options) { NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (self); - GHashTableIter iter; - const char *key, *value; - GVariantBuilder builder; + GVariant *val; g_return_if_fail (NM_IS_DHCP6_CONFIG (self)); - g_return_if_fail (options != NULL); + g_return_if_fail (options); + val = nm_utils_strdict_to_variant (options); g_variant_unref (priv->options); - - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - g_hash_table_iter_init (&iter, options); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) - g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value)); - - priv->options = g_variant_builder_end (&builder); - g_variant_ref_sink (priv->options); + priv->options = g_variant_ref_sink (val); _notify (self, PROP_OPTIONS); } diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 235134c8..368b781a 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -547,7 +547,7 @@ _dispatcher_call (NMDispatcherAction action, _LOGD ("(%u) (%s) dispatching action '%s'%s", reqid, - vpn_iface ? vpn_iface : nm_device_get_iface (device), + vpn_iface ?: nm_device_get_iface(device), action_to_string (action), blocking ? " (blocking)" @@ -650,7 +650,7 @@ _dispatcher_call (NMDispatcherAction action, device_dhcp4_props, device_dhcp6_props, connectivity_state_string, - vpn_iface ? vpn_iface : "", + vpn_iface ?: "", &vpn_proxy_props, &vpn_ip4_props, &vpn_ip6_props, @@ -688,7 +688,7 @@ _dispatcher_call (NMDispatcherAction action, device_dhcp4_props, device_dhcp6_props, connectivity_state_string, - vpn_iface ? vpn_iface : "", + vpn_iface ?: "", &vpn_proxy_props, &vpn_ip4_props, &vpn_ip6_props, diff --git a/src/nm-dispatcher.h b/src/nm-dispatcher.h index 4448e817..1cdeeb88 100644 --- a/src/nm-dispatcher.h +++ b/src/nm-dispatcher.h @@ -82,7 +82,6 @@ gboolean nm_dispatcher_call_connectivity (NMConnectivityState state, gpointer user_data, guint *out_call_id); - void nm_dispatcher_call_cancel (guint call_id); void nm_dispatcher_init (void); diff --git a/src/nm-firewall-manager.c b/src/nm-firewall-manager.c index 134a46f7..5b5e7cfa 100644 --- a/src/nm-firewall-manager.c +++ b/src/nm-firewall-manager.c @@ -174,7 +174,7 @@ _cb_info_create (NMFirewallManager *self, if (priv->running || priv->proxy_cancellable) { info->mode_mutable = CB_INFO_MODE_DBUS_WAITING; - info->dbus.arg = g_variant_new ("(ss)", zone ? zone : "", iface); + info->dbus.arg = g_variant_new ("(ss)", zone ?: "", iface); } else info->mode_mutable = CB_INFO_MODE_IDLE; diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 601c72ac..58d766c1 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -635,6 +635,12 @@ nm_dbus_manager_get (void) return NULL; } +gboolean +nm_dbus_manager_is_stopping (NMDBusManager *self) +{ + return FALSE; +} + void _nm_dbus_manager_obj_export (NMDBusObject *obj) { diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 0a9591d2..6ae81b57 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -2333,6 +2333,31 @@ _nm_ip4_config_get_nameserver (const NMIP4Config *self, guint i) /*****************************************************************************/ +gboolean +_nm_ip_config_check_and_add_domain (GPtrArray *array, const char *domain) +{ + char *copy = NULL; + size_t len; + + g_return_val_if_fail (domain, FALSE); + g_return_val_if_fail (domain[0] != '\0', FALSE); + + if (domain[0] == '.' || strstr (domain, "..")) + return FALSE; + + len = strlen (domain); + if (domain[len - 1] == '.') + domain = copy = g_strndup (domain, len - 1); + + if (nm_utils_strv_find_first ((char **) array->pdata, array->len, domain) >= 0) { + g_free (copy); + return FALSE; + } + + g_ptr_array_add (array, copy ?: g_strdup (domain)); + return TRUE; +} + void nm_ip4_config_reset_domains (NMIP4Config *self) { @@ -2348,17 +2373,9 @@ void nm_ip4_config_add_domain (NMIP4Config *self, const char *domain) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - int i; - - g_return_if_fail (domain != NULL); - g_return_if_fail (domain[0] != '\0'); - - for (i = 0; i < priv->domains->len; i++) - if (!g_strcmp0 (g_ptr_array_index (priv->domains, i), domain)) - return; - g_ptr_array_add (priv->domains, g_strdup (domain)); - _notify (self, PROP_DOMAINS); + if (_nm_ip_config_check_and_add_domain (priv->domains, domain)) + _notify (self, PROP_DOMAINS); } void @@ -2402,35 +2419,12 @@ nm_ip4_config_reset_searches (NMIP4Config *self) } void -nm_ip4_config_add_search (NMIP4Config *self, const char *new) +nm_ip4_config_add_search (NMIP4Config *self, const char *search) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - char *search; - size_t len; - - g_return_if_fail (new != NULL); - g_return_if_fail (new[0] != '\0'); - - search = g_strdup (new); - - /* Remove trailing dot as it has no effect */ - len = strlen (search); - if (search[len - 1] == '.') - search[len - 1] = 0; - if (!search[0]) { - g_free (search); - return; - } - - if (nm_utils_strv_find_first ((char **) priv->searches->pdata, - priv->searches->len, search) >= 0) { - g_free (search); - return; - } - - g_ptr_array_add (priv->searches, search); - _notify (self, PROP_SEARCHES); + if (_nm_ip_config_check_and_add_domain (priv->searches, search)) + _notify (self, PROP_SEARCHES); } void diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 1c5222df..78aca14e 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -151,7 +151,6 @@ typedef struct _NMIP4ConfigClass NMIP4ConfigClass; GType nm_ip4_config_get_type (void); - NMIP4Config * nm_ip4_config_new (NMDedupMultiIndex *multi_idx, int ifindex); @@ -178,7 +177,6 @@ void nm_ip4_config_merge_setting (NMIP4Config *self, guint32 route_metric); NMSetting *nm_ip4_config_create_setting (const NMIP4Config *self); - void nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFlags merge_flags, @@ -290,14 +288,22 @@ gboolean nm_ip4_config_nmpobj_remove (NMIP4Config *self, void nm_ip4_config_hash (const NMIP4Config *self, GChecksum *sum, gboolean dns_only); gboolean nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b); +gboolean _nm_ip_config_check_and_add_domain (GPtrArray *array, const char *domain); + /*****************************************************************************/ #include "nm-ip6-config.h" static inline gboolean -NM_IS_IP_CONFIG (gconstpointer config) +NM_IS_IP_CONFIG (gconstpointer config, int addr_family) { - return NM_IS_IP4_CONFIG (config) || NM_IS_IP6_CONFIG (config); + if (addr_family == AF_UNSPEC) + return NM_IS_IP4_CONFIG (config) || NM_IS_IP6_CONFIG (config); + if (addr_family == AF_INET) + return NM_IS_IP4_CONFIG (config); + if (addr_family == AF_INET6) + return NM_IS_IP6_CONFIG (config); + g_return_val_if_reached (FALSE); } #if _NM_CC_SUPPORT_GENERIC @@ -334,7 +340,7 @@ NM_IS_IP_CONFIG (gconstpointer config) NMIP6Config * : (NM_IS_IP6_CONFIG (_config))); \ }) #else -#define _NM_IS_IP_CONFIG(typeexpr, config) NM_IS_IP_CONFIG(config) +#define _NM_IS_IP_CONFIG(typeexpr, config) NM_IS_IP_CONFIG(config, AF_UNSPEC) #endif #define NM_IP_CONFIG_CAST(config) \ @@ -501,6 +507,12 @@ nm_ip_config_get_dns_option (const NMIPConfig *self, guint i) _NM_IP_CONFIG_DISPATCH (self, nm_ip4_config_get_dns_option, nm_ip6_config_get_dns_option, i); } +static inline const NMPObject * +nm_ip_config_best_default_route_get (const NMIPConfig *self) +{ + _NM_IP_CONFIG_DISPATCH (self, nm_ip4_config_best_default_route_get, nm_ip6_config_best_default_route_get); +} + #define _NM_IP_CONFIG_DISPATCH_SET_OP(_return, dst, src, v4_func, v6_func, ...) \ G_STMT_START { \ gpointer _dst = (dst); \ diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index c76da995..9807d388 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -2044,7 +2044,6 @@ nm_ip6_config_get_subnet_for_host (const NMIP6Config *self, const struct in6_add return subnet; } - /*****************************************************************************/ void @@ -2118,17 +2117,9 @@ void nm_ip6_config_add_domain (NMIP6Config *self, const char *domain) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); - int i; - - g_return_if_fail (domain != NULL); - g_return_if_fail (domain[0] != '\0'); - - for (i = 0; i < priv->domains->len; i++) - if (!g_strcmp0 (g_ptr_array_index (priv->domains, i), domain)) - return; - g_ptr_array_add (priv->domains, g_strdup (domain)); - _notify (self, PROP_DOMAINS); + if (_nm_ip_config_check_and_add_domain (priv->domains, domain)) + _notify (self, PROP_DOMAINS); } void @@ -2172,35 +2163,12 @@ nm_ip6_config_reset_searches (NMIP6Config *self) } void -nm_ip6_config_add_search (NMIP6Config *self, const char *new) +nm_ip6_config_add_search (NMIP6Config *self, const char *search) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); - char *search; - size_t len; - - g_return_if_fail (new != NULL); - g_return_if_fail (new[0] != '\0'); - search = g_strdup (new); - - /* Remove trailing dot as it has no effect */ - len = strlen (search); - if (search[len - 1] == '.') - search[len - 1] = 0; - - if (!search[0]) { - g_free (search); - return; - } - - if (nm_utils_strv_find_first ((char **) priv->searches->pdata, - priv->searches->len, search) >= 0) { - g_free (search); - return; - } - - g_ptr_array_add (priv->searches, search); - _notify (self, PROP_SEARCHES); + if (_nm_ip_config_check_and_add_domain (priv->searches, search)) + _notify (self, PROP_SEARCHES); } void diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index cd01ed02..9762ef48 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -96,7 +96,6 @@ typedef struct _NMIP6ConfigClass NMIP6ConfigClass; GType nm_ip6_config_get_type (void); - NMIP6Config * nm_ip6_config_new (struct _NMDedupMultiIndex *multi_idx, int ifindex); NMIP6Config * nm_ip6_config_new_cloned (const NMIP6Config *src); @@ -122,7 +121,6 @@ void nm_ip6_config_merge_setting (NMIP6Config *self, guint32 route_metric); NMSetting *nm_ip6_config_create_setting (const NMIP6Config *self); - void nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src, NMIPConfigMergeFlags merge_flags, diff --git a/src/nm-logging.h b/src/nm-logging.h index 36ba6a5a..069d1d0d 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -142,7 +142,6 @@ typedef enum { /*< skip >*/ } \ } G_STMT_END - #define _nm_log_ptr(level, domain, ifname, con_uuid, self, prefix, ...) \ nm_log ((level), \ (domain), \ @@ -182,7 +181,6 @@ _nm_log_ptr_is_debug (NMLogLevel level) } \ } G_STMT_END - #define _nm_log_obj(level, domain, ifname, con_uuid, self, prefix, ...) \ _nm_log_ptr ((level), \ (domain), \ diff --git a/src/nm-manager.c b/src/nm-manager.c index 1ccfad8e..9f0891a7 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -29,6 +29,8 @@ #include <string.h> #include <unistd.h> +#include "nm-utils/nm-c-list.h" + #include "nm-common-macros.h" #include "nm-dbus-manager.h" #include "vpn/nm-vpn-manager.h" @@ -73,6 +75,32 @@ typedef struct { const char *hw_prop; } RadioState; +typedef enum { + ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_INTERNAL, + ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_USER, + ASYNC_OP_TYPE_AC_AUTH_ADD_AND_ACTIVATE, +} AsyncOpType; + +typedef struct { + CList async_op_lst; + NMManager *self; + AsyncOpType async_op_type; + union { + struct { + NMActiveConnection *active; + union { + struct { + GDBusMethodInvocation *invocation; + } activate_user; + struct { + GDBusMethodInvocation *invocation; + NMConnection *connection; + } add_and_activate; + }; + } ac_auth; + }; +} AsyncOpData; + enum { DEVICE_ADDED, INTERNAL_DEVICE_ADDED, @@ -122,7 +150,7 @@ typedef struct { GArray *capabilities; CList active_connections_lst_head; - GSList *authorizing_connections; + CList async_op_lst_head; guint ac_cleanup_id; NMActiveConnection *primary_connection; NMActiveConnection *activating_connection; @@ -324,16 +352,31 @@ static void active_connection_parent_active (NMActiveConnection *active, NMActiveConnection *parent_ac, NMManager *self); -static NMActiveConnection *active_connection_find_first (NMManager *self, - NMSettingsConnection *settings_connection, - const char *uuid, - NMActiveConnectionState max_state); +static NMActiveConnection *active_connection_find (NMManager *self, + NMSettingsConnection *settings_connection, + const char *uuid, + NMActiveConnectionState max_state, + GPtrArray **out_all_matching); static NMConnectivity *concheck_get_mgr (NMManager *self); -/*****************************************************************************/ +static void _internal_activation_auth_done (NMManager *self, + NMActiveConnection *active, + gboolean success, + const char *error_desc); +static void _add_and_activate_auth_done (NMManager *self, + NMActiveConnection *active, + NMConnection *connection, + GDBusMethodInvocation *invocation, + gboolean success, + const char *error_desc); +static void _activation_auth_done (NMManager *self, + NMActiveConnection *active, + GDBusMethodInvocation *invocation, + gboolean success, + const char *error_desc); -static NM_CACHED_QUARK_FCN ("active-connection-add-and-activate", active_connection_add_and_activate_quark) +/*****************************************************************************/ static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark) @@ -406,6 +449,104 @@ concheck_get_mgr (NMManager *self) /*****************************************************************************/ +static AsyncOpData * +_async_op_data_new_authorize_activate_internal (NMManager *self, NMActiveConnection *active_take) +{ + AsyncOpData *async_op_data; + + async_op_data = g_slice_new0 (AsyncOpData); + async_op_data->async_op_type = ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_INTERNAL; + async_op_data->self = g_object_ref (self); + async_op_data->ac_auth.active = active_take; + c_list_link_tail (&NM_MANAGER_GET_PRIVATE (self)->async_op_lst_head, &async_op_data->async_op_lst); + return async_op_data; +} + +static AsyncOpData * +_async_op_data_new_ac_auth_activate_user (NMManager *self, + NMActiveConnection *active_take, + GDBusMethodInvocation *invocation_take) +{ + AsyncOpData *async_op_data; + + async_op_data = g_slice_new0 (AsyncOpData); + async_op_data->async_op_type = ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_USER; + async_op_data->self = g_object_ref (self); + async_op_data->ac_auth.active = active_take; + async_op_data->ac_auth.activate_user.invocation = invocation_take; + c_list_link_tail (&NM_MANAGER_GET_PRIVATE (self)->async_op_lst_head, &async_op_data->async_op_lst); + return async_op_data; +} + +static AsyncOpData * +_async_op_data_new_ac_auth_add_and_activate (NMManager *self, + NMActiveConnection *active_take, + GDBusMethodInvocation *invocation_take, + NMConnection *connection_take) +{ + AsyncOpData *async_op_data; + + async_op_data = g_slice_new0 (AsyncOpData); + async_op_data->async_op_type = ASYNC_OP_TYPE_AC_AUTH_ADD_AND_ACTIVATE; + async_op_data->self = g_object_ref (self); + async_op_data->ac_auth.active = active_take; + async_op_data->ac_auth.add_and_activate.invocation = invocation_take; + async_op_data->ac_auth.add_and_activate.connection = connection_take; + c_list_link_tail (&NM_MANAGER_GET_PRIVATE (self)->async_op_lst_head, &async_op_data->async_op_lst); + return async_op_data; +} + +static void +_async_op_complete_ac_auth_cb (NMActiveConnection *active, + gboolean success, + const char *error_desc, + gpointer user_data) +{ + AsyncOpData *async_op_data = user_data; + + nm_assert (async_op_data); + nm_assert (NM_IS_MANAGER (async_op_data->self)); + nm_assert (nm_c_list_contains_entry (&NM_MANAGER_GET_PRIVATE (async_op_data->self)->async_op_lst_head, async_op_data, async_op_lst)); + nm_assert (NM_IS_ACTIVE_CONNECTION (active)); + nm_assert (active == async_op_data->ac_auth.active); + + c_list_unlink (&async_op_data->async_op_lst); + + switch (async_op_data->async_op_type) { + case ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_INTERNAL: + _internal_activation_auth_done (async_op_data->self, + async_op_data->ac_auth.active, + success, + error_desc); + break; + case ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_USER: + _activation_auth_done (async_op_data->self, + async_op_data->ac_auth.active, + async_op_data->ac_auth.activate_user.invocation, + success, + error_desc); + break; + case ASYNC_OP_TYPE_AC_AUTH_ADD_AND_ACTIVATE: + _add_and_activate_auth_done (async_op_data->self, + async_op_data->ac_auth.active, + async_op_data->ac_auth.add_and_activate.connection, + async_op_data->ac_auth.add_and_activate.invocation, + success, + error_desc); + g_object_unref (async_op_data->ac_auth.add_and_activate.connection); + break; + default: + nm_assert_not_reached (); + break; + } + + g_object_unref (async_op_data->ac_auth.active); + g_object_unref (async_op_data->self); + g_slice_free (AsyncOpData, async_op_data); +} + +/*****************************************************************************/ + typedef struct { int ifindex; guint32 aspired_metric; @@ -659,10 +800,11 @@ _delete_volatile_connection_do (NMManager *self, if (!NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE)) return; - if (active_connection_find_first (self, - connection, - NULL, - NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)) + if (active_connection_find (self, + connection, + NULL, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, + NULL)) return; if (!nm_settings_has_connection (priv->settings, connection)) return; @@ -804,15 +946,19 @@ nm_manager_get_active_connections (NMManager *manager) } static NMActiveConnection * -active_connection_find_first (NMManager *self, - NMSettingsConnection *settings_connection, - const char *uuid, - NMActiveConnectionState max_state) +active_connection_find (NMManager *self, + NMSettingsConnection *settings_connection, + const char *uuid, + NMActiveConnectionState max_state /* candidates in state @max_state will be found */, + GPtrArray **out_all_matching) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMActiveConnection *ac; + NMActiveConnection *best_ac = NULL; + GPtrArray *all = NULL; nm_assert (!settings_connection || NM_IS_SETTINGS_CONNECTION (settings_connection)); + nm_assert (!out_all_matching || !*out_all_matching); c_list_for_each_entry (ac, &priv->active_connections_lst_head, active_connections_lst) { NMSettingsConnection *con; @@ -824,15 +970,44 @@ active_connection_find_first (NMManager *self, continue; if (nm_active_connection_get_state (ac) > max_state) continue; - return ac; + + if (!out_all_matching) + return ac; + + if (!best_ac) { + best_ac = ac; + continue; + } + + if (!all) { + all = g_ptr_array_new_with_free_func (g_object_unref); + g_ptr_array_add (all, g_object_ref (best_ac)); + } + g_ptr_array_add (all, g_object_ref (ac)); } - return NULL; + if (!best_ac) + return NULL; + + /* as an optimization, we only allocate out_all_matching, if there are more + * than one result. If there is only one result, we only return the single + * element and don't bother allocating an array. That's the common case. + * + * Also, in case we have multiple results, we return the *first* one + * as @best_ac. */ + nm_assert ( !all + || ( all->len >= 2 + && all->pdata[0] == best_ac)); + + *out_all_matching = all; + return best_ac; } static NMActiveConnection * -active_connection_find_first_by_connection (NMManager *self, - NMConnection *connection) +active_connection_find_by_connection (NMManager *self, + NMConnection *connection, + NMActiveConnectionState max_state, + GPtrArray **out_all_matching) { gboolean is_settings_connection; @@ -842,10 +1017,11 @@ active_connection_find_first_by_connection (NMManager *self, is_settings_connection = NM_IS_SETTINGS_CONNECTION (connection); /* Depending on whether connection is a settings connection, * either lookup by object-identity of @connection, or compare the UUID */ - return active_connection_find_first (self, - is_settings_connection ? NM_SETTINGS_CONNECTION (connection) : NULL, - is_settings_connection ? NULL : nm_connection_get_uuid (connection), - NM_ACTIVE_CONNECTION_STATE_DEACTIVATING); + return active_connection_find (self, + is_settings_connection ? NM_SETTINGS_CONNECTION (connection) : NULL, + is_settings_connection ? NULL : nm_connection_get_uuid (connection), + max_state, + out_all_matching); } static gboolean @@ -856,7 +1032,10 @@ _get_activatable_connections_filter (NMSettings *settings, if (NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE)) return FALSE; - return !active_connection_find_first (user_data, connection, NULL, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING); + + /* the connection is activatable, if it has no active-connections that are in state + * activated, activating, or waiting to be activated. */ + return !active_connection_find (user_data, connection, NULL, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, NULL); } NMSettingsConnection ** @@ -1891,8 +2070,8 @@ connection_flags_changed (NMSettings *settings, NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE)) return; - if (active_connection_find_first (self, connection, NULL, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)) { - /* the connection still have an active-connection. It will be purged + if (active_connection_find (self, connection, NULL, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, NULL)) { + /* the connection still has an active-connection. It will be purged * when the active connection(s) get(s) removed. */ return; } @@ -2265,8 +2444,9 @@ get_existing_connection (NMManager *self, */ if ( assume_state_connection_uuid && (connection_checked = nm_settings_get_connection_by_uuid (priv->settings, assume_state_connection_uuid)) - && !active_connection_find_first (self, connection_checked, NULL, - NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) + && !active_connection_find (self, connection_checked, NULL, + NM_ACTIVE_CONNECTION_STATE_ACTIVATED, + NULL) && nm_device_check_connection_compatible (device, NM_CONNECTION (connection_checked))) { if (connection) { @@ -2422,7 +2602,7 @@ recheck_assume_connection (NMManager *self, device, subject, generated ? NM_ACTIVATION_TYPE_EXTERNAL : NM_ACTIVATION_TYPE_ASSUME, - NM_ACTIVATION_REASON_AUTOCONNECT, + generated ? NM_ACTIVATION_REASON_EXTERNAL : NM_ACTIVATION_REASON_ASSUME, &error); if (!active) { @@ -3046,19 +3226,83 @@ nm_manager_get_best_device_for_connection (NMManager *self, GHashTable *unavailable_devices) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); + NMActiveConnectionState ac_state; NMActiveConnection *ac; - NMDevice *act_device; + NMDevice *ac_device; NMDevice *device; NMDeviceCheckConAvailableFlags flags; + gs_unref_ptrarray GPtrArray *all_ac_arr = NULL; + + flags = for_user_request ? NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST : NM_DEVICE_CHECK_CON_AVAILABLE_NONE; - ac = active_connection_find_first_by_connection (self, connection); + ac = active_connection_find_by_connection (self, connection, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, &all_ac_arr); if (ac) { - act_device = nm_active_connection_get_device (ac); - if (act_device) - return act_device; - } - flags = for_user_request ? NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST : NM_DEVICE_CHECK_CON_AVAILABLE_NONE; + ac_device = nm_active_connection_get_device (ac); + if ( ac_device + && ( (unavailable_devices && g_hash_table_contains (unavailable_devices, ac_device)) + || !nm_device_check_connection_available (ac_device, connection, flags, NULL))) + ac_device = NULL; + + if (all_ac_arr) { + guint i; + + ac_state = nm_active_connection_get_state (ac); + + /* we found several active connections. See which one is the most suitable... */ + nm_assert (ac == all_ac_arr->pdata[0]); + for (i = 1; i < all_ac_arr->len; i++) { + NMActiveConnection *ac2 = all_ac_arr->pdata[i]; + NMDevice *ac_device2 = nm_active_connection_get_device (ac2); + NMActiveConnectionState ac_state2; + + if ( !ac_device2 + || (unavailable_devices && g_hash_table_contains (unavailable_devices, ac_device2)) + || !nm_device_check_connection_available (ac_device2, connection, flags, NULL)) + continue; + + ac_state2 = nm_active_connection_get_state (ac2); + + if (!ac_device) + goto found_better; + + if (ac_state == ac_state2) { + /* active-connections are in their list in the order in which they are connected. + * If we have two with same state, the later (newer) one is preferred. */ + goto found_better; + } + + switch (ac_state) { + case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: + if (NM_IN_SET (ac_state2, NM_ACTIVE_CONNECTION_STATE_ACTIVATING, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING)) + goto found_better; + break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + if (NM_IN_SET (ac_state2, NM_ACTIVE_CONNECTION_STATE_ACTIVATED)) + goto found_better; + break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: + break; + case NM_ACTIVE_CONNECTION_STATE_DEACTIVATING: + if (NM_IN_SET (ac_state2, NM_ACTIVE_CONNECTION_STATE_ACTIVATING, NM_ACTIVE_CONNECTION_STATE_ACTIVATED)) + goto found_better; + break; + default: + nm_assert_not_reached (); + goto found_better; + } + + continue; +found_better: + ac = ac2; + ac_state = ac_state2; + ac_device = ac_device2; + } + } + + if (ac_device) + return ac_device; + } /* Pick the first device that's compatible with the connection. */ c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { @@ -3288,8 +3532,9 @@ find_master (NMManager *self, if (out_master_device) *out_master_device = master_device; if (out_master_ac && master_connection) { - *out_master_ac = active_connection_find_first (self, master_connection, NULL, - NM_ACTIVE_CONNECTION_STATE_DEACTIVATING); + *out_master_ac = active_connection_find (self, master_connection, NULL, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, + NULL); } if (master_device || master_connection) @@ -3773,8 +4018,7 @@ active_connection_parent_active (NMActiveConnection *active, static gboolean _internal_activate_device (NMManager *self, NMActiveConnection *active, GError **error) { - NMDevice *device, *existing, *master_device = NULL; - NMActiveConnection *existing_ac; + NMDevice *device, *master_device = NULL; NMConnection *applied; NMSettingsConnection *connection; NMSettingsConnection *master_connection = NULL; @@ -3938,12 +4182,23 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError * /* Check slaves for master connection and possibly activate them */ autoconnect_slaves (self, connection, device, nm_active_connection_get_subject (active)); - /* Disconnect the connection if connected or queued on another device */ - existing_ac = active_connection_find_first (self, connection, NULL, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING); - if (existing_ac) { - existing = nm_active_connection_get_device (existing_ac); - if (existing) - nm_device_steal_connection (existing, connection); + { + gs_unref_ptrarray GPtrArray *all_ac_arr = NULL; + NMActiveConnection *ac; + guint i, n_all; + + /* Disconnect the connection if already connected or queued for activation. + * The connection cannot be active multiple times (at the same time). */ + ac = active_connection_find (self, connection, NULL, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, + &all_ac_arr); + if (ac) { + n_all = all_ac_arr ? all_ac_arr->len : ((guint) 1); + for (i = 0; i < n_all; i++) { + nm_device_disconnect_active_connection ( all_ac_arr + ? all_ac_arr->pdata[i] + : ac); + } + } } /* If the device is there, we can ready it for the activation. */ @@ -4035,7 +4290,7 @@ _new_active_connection (NMManager *self, /* FIXME: for VPN connections, we don't allow re-activating an * already active connection. It's a bug, and should be fixed together * when reworking VPN handling. */ - if (active_connection_find_first_by_connection (self, connection)) { + if (active_connection_find_by_connection (self, connection, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, NULL)) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_ALREADY_ACTIVE, "Connection '%s' is already active", nm_connection_get_id (connection)); @@ -4097,31 +4352,28 @@ _new_active_connection (NMManager *self, } static void -_internal_activation_auth_done (NMActiveConnection *active, +_internal_activation_auth_done (NMManager *self, + NMActiveConnection *active, gboolean success, - const char *error_desc, - gpointer user_data1, - gpointer user_data2) + const char *error_desc) { - _nm_unused gs_unref_object NMActiveConnection *active_to_free = active; - NMManager *self = user_data1; NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMActiveConnection *ac; gs_free_error GError *error = NULL; - priv->authorizing_connections = g_slist_remove (priv->authorizing_connections, active); + nm_assert (NM_IS_ACTIVE_CONNECTION (active)); if (!success) goto fail; - /* Don't continue with an internal activation if an equivalent active - * connection already exists. Note that slave autoconnections always force a - * reconnection. We also check this earlier, but there we may fail to - * detect a duplicate if the existing active connection is undergoing - * authorization in impl_manager_activate_connection(). + /* Don't continue with an autoconnect-activation if a more important activation + * already exists. + * We also check this earlier, but there we may fail to detect a duplicate + * if the existing active connection was undergoing authorization. */ - if ( nm_auth_subject_is_internal (nm_active_connection_get_subject (active)) - && nm_active_connection_get_activation_reason (active) != NM_ACTIVATION_REASON_AUTOCONNECT_SLAVES) { + if (NM_IN_SET (nm_active_connection_get_activation_reason (active), NM_ACTIVATION_REASON_EXTERNAL, + NM_ACTIVATION_REASON_ASSUME, + NM_ACTIVATION_REASON_AUTOCONNECT)) { c_list_for_each_entry (ac, &priv->active_connections_lst_head, active_connections_lst) { if ( nm_active_connection_get_device (ac) == nm_active_connection_get_device (active) && nm_active_connection_get_settings_connection (ac) == nm_active_connection_get_settings_connection (active) @@ -4154,7 +4406,7 @@ fail: * @connection: the #NMSettingsConnection to activate on @device * @applied: (allow-none): the applied connection to activate on @device * @specific_object: the specific object path, if any, for the activation - * @device: the #NMDevice to activate @connection on + * @device: the #NMDevice to activate @connection on. Can be %NULL for VPNs. * @subject: the subject which requested activation * @activation_type: whether to assume the connection. That is, take over gracefully, * non-destructible. @@ -4184,11 +4436,13 @@ nm_manager_activate_connection (NMManager *self, { NMManagerPrivate *priv; NMActiveConnection *active; - GSList *iter; + AsyncOpData *async_op_data; + gboolean is_vpn; g_return_val_if_fail (NM_IS_MANAGER (self), NULL); g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), NULL); - g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + is_vpn = _connection_is_vpn (NM_CONNECTION (connection)); + g_return_val_if_fail (is_vpn || NM_IS_DEVICE (device), NULL); g_return_val_if_fail (!error || !*error, NULL); nm_assert (!nm_streq0 (specific_object, "/")); @@ -4206,12 +4460,15 @@ nm_manager_activate_connection (NMManager *self, * otherwise race and cause the device to disconnect and reconnect repeatedly. * In particular, this allows the master and multiple slaves to concurrently auto-activate * while all the slaves would use the same active-connection. */ - for (iter = priv->authorizing_connections; iter; iter = g_slist_next (iter)) { - active = iter->data; + c_list_for_each_entry (async_op_data, &priv->async_op_lst_head, async_op_lst) { + + if (async_op_data->async_op_type != ASYNC_OP_TYPE_AC_AUTH_ACTIVATE_INTERNAL) + continue; + active = async_op_data->ac_auth.active; if ( connection == nm_active_connection_get_settings_connection (active) && nm_streq0 (nm_active_connection_get_specific_object (active), specific_object) - && nm_active_connection_get_device (active) == device + && (!device || nm_active_connection_get_device (active) == device) && nm_auth_subject_is_internal (nm_active_connection_get_subject (active)) && nm_auth_subject_is_internal (subject) && nm_active_connection_get_activation_reason (active) == activation_reason) @@ -4219,7 +4476,7 @@ nm_manager_activate_connection (NMManager *self, } active = _new_active_connection (self, - _connection_is_vpn (NM_CONNECTION (connection)), + is_vpn, NM_CONNECTION (connection), applied, specific_object, @@ -4231,8 +4488,11 @@ nm_manager_activate_connection (NMManager *self, if (!active) return NULL; - priv->authorizing_connections = g_slist_prepend (priv->authorizing_connections, active); - nm_active_connection_authorize (active, NULL, _internal_activation_auth_done, self, NULL); + nm_active_connection_authorize (active, + NULL, + _async_op_complete_ac_auth_cb, + _async_op_data_new_authorize_activate_internal (self, + active)); return active; } @@ -4362,18 +4622,15 @@ validate_activation_request (NMManager *self, /*****************************************************************************/ static void -_activation_auth_done (NMActiveConnection *active, +_activation_auth_done (NMManager *self, + NMActiveConnection *active, + GDBusMethodInvocation *invocation, gboolean success, - const char *error_desc, - gpointer user_data1, - gpointer user_data2) + const char *error_desc) { - NMManager *self = user_data1; - GDBusMethodInvocation *context = user_data2; GError *error = NULL; NMAuthSubject *subject; NMSettingsConnection *connection; - _nm_unused gs_unref_object NMActiveConnection *active_free = active; subject = nm_active_connection_get_subject (active); connection = nm_active_connection_get_settings_connection (active); @@ -4391,7 +4648,7 @@ _activation_auth_done (NMActiveConnection *active, nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST, FALSE); - g_dbus_method_invocation_return_value (context, + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", nm_dbus_object_get_path (NM_DBUS_OBJECT (active)))); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ACTIVATE, connection, TRUE, NULL, @@ -4405,7 +4662,7 @@ fail: NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN, error->message); - g_dbus_method_invocation_take_error (context, error); + g_dbus_method_invocation_take_error (invocation, error); } static void @@ -4490,14 +4747,12 @@ impl_manager_activate_connection (NMDBusObject *obj, if (!active) goto error; - /* FIXME: nm_active_connection_authorize() is not cancellable, - * and we pass on the only reference to @active. This construct - * is unsuitable for a coordinated shutdown. */ nm_active_connection_authorize (g_steal_pointer (&active), NULL, - _activation_auth_done, - self, - invocation); + _async_op_complete_ac_auth_cb, + _async_op_data_new_ac_auth_activate_user (self, + active, + invocation)); return; error: @@ -4510,11 +4765,6 @@ error: /*****************************************************************************/ -typedef struct { - NMManager *manager; - NMActiveConnection *active; -} AddAndActivateInfo; - static void activation_add_done (NMSettings *settings, NMSettingsConnection *new_connection, @@ -4523,14 +4773,11 @@ activation_add_done (NMSettings *settings, NMAuthSubject *subject, gpointer user_data) { - AddAndActivateInfo *info = user_data; NMManager *self; gs_unref_object NMActiveConnection *active = NULL; gs_free_error GError *local = NULL; - self = info->manager; - active = info->active; - g_slice_free (AddAndActivateInfo, info); + nm_utils_user_data_unpack (user_data, &self, &active); if (!error) { nm_active_connection_set_settings_connection (active, new_connection); @@ -4575,21 +4822,15 @@ activation_add_done (NMSettings *settings, } static void -_add_and_activate_auth_done (NMActiveConnection *active, +_add_and_activate_auth_done (NMManager *self, + NMActiveConnection *active, + NMConnection *connection, + GDBusMethodInvocation *invocation, gboolean success, - const char *error_desc, - gpointer user_data1, - gpointer user_data2) + const char *error_desc) { - NMManager *self = user_data1; - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - GDBusMethodInvocation *context = user_data2; - AddAndActivateInfo *info; + NMManagerPrivate *priv; GError *error = NULL; - gs_unref_object NMConnection *connection = NULL; - - connection = g_object_steal_qdata (G_OBJECT (active), - active_connection_add_and_activate_quark ()); if (!success) { error = g_error_new_literal (NM_MANAGER_ERROR, @@ -4601,24 +4842,23 @@ _add_and_activate_auth_done (NMActiveConnection *active, NULL, nm_active_connection_get_subject (active), error->message); - g_dbus_method_invocation_take_error (context, error); - g_object_unref (active); + g_dbus_method_invocation_take_error (invocation, error); return; } - info = g_slice_new (AddAndActivateInfo); - info->manager = self; - - /* we pass on the reference to @active. */ - info->active = active; + priv = NM_MANAGER_GET_PRIVATE (self); - /* Basic sender auth checks performed; try to add the connection */ + /* FIXME(shutdown): nm_settings_add_connection_dbus() cannot be cancelled. It should be made + * cancellable and tracked via AsyncOpData to be able to do a clean + * shutdown. */ nm_settings_add_connection_dbus (priv->settings, connection, FALSE, - context, + nm_active_connection_get_subject (active), + invocation, activation_add_done, - info); + nm_utils_user_data_pack (self, + g_object_ref (active))); } static void @@ -4709,19 +4949,14 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj, if (!active) goto error; - /* FIXME: nm_active_connection_authorize() already has two user-data pointers - * to piggyback additional data. Instead of attaching the third argument to - * @active's user-data, add a third paramter. - * Or alternatively, allocate a data structure to pass on additional data. - * Then we don't need two user-data pointers. */ - g_object_set_qdata_full (G_OBJECT (active), - active_connection_add_and_activate_quark (), - connection, - g_object_unref); - - nm_active_connection_authorize (active, connection, _add_and_activate_auth_done, self, invocation); + nm_active_connection_authorize (active, connection, + _async_op_complete_ac_auth_cb, + _async_op_data_new_ac_auth_add_and_activate (self, + active, + invocation, + connection)); - /* we passed the pointers on to the callback of authorize. */ + /* we passed the pointers on to _async_op_data_new_ac_auth_add_and_activate() */ g_steal_pointer (&connection); g_steal_pointer (&active); return; @@ -5799,6 +6034,21 @@ nm_manager_stop (NMManager *self) NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMDevice *device; + /* FIXME(shutdown): we don't do a proper shutdown yet: + * - need to ensure that all pending async operations are cancelled + * - e.g. operations in priv->async_op_lst_head + * - need to ensure that no more asynchronous requests are started, + * or that they complete quickly, or that they fail quickly. + * - note that cancelling some operations is not possible synchronously. + * Hence, stop() only prepares shutdown and tells everybody to not + * accept new work, and to complete in a timely manner. + * We need to still iterate the mainloop for a bit, to give everybody + * the chance to complete. + * - e.g. see comment at nm_auth_manager_force_shutdown() + */ + + nm_dbus_manager_stop (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self))); + while ((device = c_list_first_entry (&priv->devices_lst_head, NMDevice, devices_lst))) remove_device (self, device, TRUE, TRUE); @@ -6577,6 +6827,7 @@ nm_manager_init (NMManager *self) c_list_init (&priv->link_cb_lst); c_list_init (&priv->devices_lst_head); c_list_init (&priv->active_connections_lst_head); + c_list_init (&priv->async_op_lst_head); c_list_init (&priv->delete_volatile_connection_lst_head); priv->platform = g_object_ref (NM_PLATFORM_GET); @@ -6726,7 +6977,7 @@ get_property (GObject *object, guint prop_id, if (con) type = nm_connection_get_connection_type (con); } - g_value_set_string (value, type ? type : ""); + g_value_set_string (value, type ?: ""); break; case PROP_ACTIVATING_CONNECTION: nm_dbus_utils_g_value_set_object_path (value, priv->activating_connection); @@ -6824,6 +7075,8 @@ dispose (GObject *object) CList *iter, *iter_safe; NMActiveConnection *ac, *ac_safe; + nm_assert (c_list_is_empty (&priv->async_op_lst_head)); + g_signal_handlers_disconnect_by_func (priv->platform, G_CALLBACK (platform_link_cb), self); diff --git a/src/nm-manager.h b/src/nm-manager.h index 54444532..5a462846 100644 --- a/src/nm-manager.h +++ b/src/nm-manager.h @@ -71,7 +71,6 @@ #define NM_MANAGER_INTERNAL_DEVICE_ADDED "internal-device-added" #define NM_MANAGER_INTERNAL_DEVICE_REMOVED "internal-device-removed" - GType nm_manager_get_type (void); /* nm_manager_setup() should only be used by main.c */ diff --git a/src/nm-pacrunner-manager.c b/src/nm-pacrunner-manager.c index caae8b20..af43edbe 100644 --- a/src/nm-pacrunner-manager.c +++ b/src/nm-pacrunner-manager.c @@ -421,7 +421,6 @@ nm_pacrunner_manager_send (NMPacrunnerManager *self, g_variant_new_string ("direct")); } - /* Extract stuff from configs */ add_proxy_config (&proxy_data, proxy_config); diff --git a/src/nm-policy.c b/src/nm-policy.c index 55b6caf6..fe16cda5 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1169,9 +1169,11 @@ pending_ac_state_changed (NMActiveConnection *ac, guint state, guint reason, NMP * device, but block the current connection to avoid an activation * loop. */ - con = nm_active_connection_get_settings_connection (ac); - nm_settings_connection_autoconnect_blocked_reason_set (con, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, TRUE); - schedule_activate_check (self, nm_active_connection_get_device (ac)); + if (reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED) { + con = nm_active_connection_get_settings_connection (ac); + nm_settings_connection_autoconnect_blocked_reason_set (con, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, TRUE); + schedule_activate_check (self, nm_active_connection_get_device (ac)); + } /* Cleanup */ g_signal_handlers_disconnect_by_func (ac, pending_ac_state_changed, self); @@ -1910,8 +1912,8 @@ device_ip_config_changed (NMDevice *device, int addr_family; nm_assert (new_config || old_config); - nm_assert (!new_config || NM_IS_IP_CONFIG (new_config)); - nm_assert (!old_config || NM_IS_IP_CONFIG (old_config)); + nm_assert (!new_config || NM_IS_IP_CONFIG (new_config, AF_UNSPEC)); + nm_assert (!old_config || NM_IS_IP_CONFIG (old_config, AF_UNSPEC)); if (new_config) { addr_family = nm_ip_config_get_addr_family (new_config); @@ -2119,7 +2121,7 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *self) &error)) { _LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s", nm_settings_connection_get_id (connection), - error->message ? error->message : "unknown"); + error->message ?: "unknown"); g_clear_error (&error); } } diff --git a/src/nm-rfkill-manager.c b/src/nm-rfkill-manager.c index e655e67c..b2909e9d 100644 --- a/src/nm-rfkill-manager.c +++ b/src/nm-rfkill-manager.c @@ -296,7 +296,7 @@ add_one_killswitch (NMRfkillManager *self, struct udev_device *device) rfkill_type_to_desc (rtype), ks->path, ks->platform ? "platform " : "", - ks->driver ? ks->driver : "<unknown>"); + ks->driver ?: "<unknown>"); } static void diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 13ccbd48..23d41d7e 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -141,7 +141,7 @@ st_sd_finalize (NMSessionMonitor *monitor) sd_login_monitor_unref (monitor->sd.monitor); monitor->sd.monitor = NULL; } - g_source_remove (monitor->sd.watch); + nm_clear_g_source (&monitor->sd.watch); } #endif /* SESSION_TRACKING_SYSTEMD */ diff --git a/src/nm-sleep-monitor.c b/src/nm-sleep-monitor.c index 7a373874..a7e3a7c3 100644 --- a/src/nm-sleep-monitor.c +++ b/src/nm-sleep-monitor.c @@ -29,7 +29,6 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" - #if defined (SUSPEND_RESUME_UPOWER) #define SUSPEND_DBUS_NAME "org.freedesktop.UPower" diff --git a/src/nm-test-utils-core.h b/src/nm-test-utils-core.h index da24992e..c76f510f 100644 --- a/src/nm-test-utils-core.h +++ b/src/nm-test-utils-core.h @@ -308,7 +308,6 @@ nmtst_platform_ip6_routes_equal_aptr (const NMPObject *const*a, const NMPlatform #endif - #ifdef __NETWORKMANAGER_IP4_CONFIG_H__ #include "nm-utils/nm-dedup-multi.h" @@ -323,7 +322,6 @@ nmtst_ip4_config_new (int ifindex) #endif - #ifdef __NETWORKMANAGER_IP6_CONFIG_H__ #include "nm-utils/nm-dedup-multi.h" diff --git a/src/nm-types.h b/src/nm-types.h index e1991c28..1477d226 100644 --- a/src/nm-types.h +++ b/src/nm-types.h @@ -75,10 +75,12 @@ typedef enum { } NMActivationType; typedef enum { - NM_ACTIVATION_REASON_UNSET = 0, - NM_ACTIVATION_REASON_AUTOCONNECT = 1, - NM_ACTIVATION_REASON_AUTOCONNECT_SLAVES = 2, - NM_ACTIVATION_REASON_USER_REQUEST = 3, + NM_ACTIVATION_REASON_UNSET, + NM_ACTIVATION_REASON_EXTERNAL, + NM_ACTIVATION_REASON_ASSUME, + NM_ACTIVATION_REASON_AUTOCONNECT, + NM_ACTIVATION_REASON_AUTOCONNECT_SLAVES, + NM_ACTIVATION_REASON_USER_REQUEST, } NMActivationReason; typedef enum { @@ -212,7 +214,6 @@ typedef enum { NM_IP_CONFIG_MERGE_NO_DNS = (1LL << 2), } NMIPConfigMergeFlags; - /** * NMIPRouteTableSyncMode: * @NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN: only the main table is synced. For all @@ -228,7 +229,6 @@ typedef enum { NM_IP_ROUTE_TABLE_SYNC_MODE_ALL = 3, } NMIPRouteTableSyncMode; - /* settings */ typedef struct _NMAgentManager NMAgentManager; typedef struct _NMSecretAgent NMSecretAgent; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 0ed8fa06..3a671acf 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -181,7 +181,6 @@ G_STATIC_ASSERT (RTA_MAX == (__RTA_MAX - 1)); #define _NMLOG2(level, ...) _LOG ( level, _NMLOG2_DOMAIN, NULL, __VA_ARGS__) #define _NMLOG2_err(errsv, level, ...) _LOG_err (errsv, level, _NMLOG2_DOMAIN, NULL, __VA_ARGS__) - #define _LOG_print(__level, __domain, __errsv, self, ...) \ G_STMT_START { \ char __prefix[32]; \ @@ -226,7 +225,6 @@ G_STATIC_ASSERT (RTA_MAX == (__RTA_MAX - 1)); } \ } G_STMT_END - #define LOG_FMT_IP_TUNNEL "adding %s '%s' parent %u local %s remote %s" /****************************************************************** @@ -1536,7 +1534,6 @@ _parse_lnk_vlan (const char *kind, struct nlattr *info_data) &obj->_lnk_vlan.n_egress_qos_map)) return NULL; - obj_result = obj; obj = NULL; return obj_result; @@ -6983,7 +6980,7 @@ handle_udev_event (NMUdevClient *udev_client, seqnum = udev_device_get_seqnum (udevice); _LOGD ("UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, action, subsys, udev_device_get_sysname (udevice), - ifindex ? ifindex : "unknown", seqnum); + ifindex ?: "unknown", seqnum); if (NM_IN_STRSET (action, "add", "move")) udev_device_added (platform, udevice); diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h index ea25470e..97f5630a 100644 --- a/src/platform/nm-platform-utils.h +++ b/src/platform/nm-platform-utils.h @@ -24,7 +24,6 @@ #include "nm-platform.h" #include "nm-setting-wired.h" - const char *nmp_utils_ethtool_get_driver (int ifindex); gboolean nmp_utils_ethtool_supports_carrier_detect (int ifindex); gboolean nmp_utils_ethtool_supports_vlans (int ifindex); @@ -60,10 +59,8 @@ gboolean nmp_utils_ethtool_get_permanent_address (int ifindex, guint8 *buf, size_t *length); - gboolean nmp_utils_mii_supports_carrier_detect (int ifindex); - struct udev_device; const char *nmp_utils_udev_get_driver (struct udev_device *udevice); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 84d862d2..1a94ce28 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -2396,7 +2396,6 @@ nm_platform_link_infiniband_delete (NMPlatform *self, return _infiniband_add_add_or_delete (self, parent, p_key, FALSE, NULL); } - gboolean nm_platform_link_infiniband_get_properties (NMPlatform *self, int ifindex, @@ -3596,6 +3595,25 @@ delete_and_next2: return TRUE; } +static guint +ip6_address_scope_priority (const struct in6_addr *addr) +{ + if (IN6_IS_ADDR_LINKLOCAL (addr)) + return 1; + if (IN6_IS_ADDR_SITELOCAL (addr)) + return 2; + return 3; +} + +static gint +ip6_address_scope_cmp (gconstpointer a, gconstpointer b) +{ + const NMPlatformIP6Address *x = NMP_OBJECT_CAST_IP6_ADDRESS (*(const void **) a); + const NMPlatformIP6Address *y = NMP_OBJECT_CAST_IP6_ADDRESS (*(const void **) b); + + return ip6_address_scope_priority (&x->address) - ip6_address_scope_priority (&y->address); +} + /** * nm_platform_ip6_address_sync: * @self: platform instance @@ -3629,6 +3647,13 @@ nm_platform_ip6_address_sync (NMPlatform *self, NMPLookup lookup; guint32 ifa_flags; + /* The order we want to enforce is only among addresses with the same + * scope, as the kernel keeps addresses sorted by scope. Therefore, + * apply the same sorting to known addresses, so that we don't try to + * unnecessary change the order of addresses with different scopes. */ + if (known_addresses) + g_ptr_array_sort (known_addresses, ip6_address_scope_cmp); + if (!_addr_array_clean_expired (AF_INET6, ifindex, known_addresses, now, &known_addresses_idx)) known_addresses = NULL; @@ -4019,6 +4044,7 @@ sync_route_add: nmp_object_stackinit (&oo, NMP_OBJECT_TYPE_IP4_ROUTE, &((NMPlatformIP4Route) { + .ifindex = r->ifindex, .network = r->gateway, .plen = 32, .metric = r->metric, @@ -4031,6 +4057,7 @@ sync_route_add: nmp_object_stackinit (&oo, NMP_OBJECT_TYPE_IP6_ROUTE, &((NMPlatformIP6Route) { + .ifindex = r->ifindex, .network = r->gateway, .plen = 128, .metric = r->metric, @@ -4651,7 +4678,6 @@ nm_platform_qdisc_sync (NMPlatform *self, ifindex), NULL, NULL); - if (plat_qdiscs) { for (i = 0; i < plat_qdiscs->len; i++) { const NMPObject *q = g_ptr_array_index (plat_qdiscs, i); @@ -4717,7 +4743,6 @@ nm_platform_tfilter_sync (NMPlatform *self, ifindex), NULL, NULL); - if (plat_tfilters) { for (i = 0; i < plat_tfilters->len; i++) { const NMPObject *q = g_ptr_array_index (plat_tfilters, i); @@ -4786,7 +4811,6 @@ _lifetime_to_string (guint32 timestamp, guint32 lifetime, gint32 now, char *buf, return buf; } - static const char * _lifetime_summary_to_string (gint32 now, guint32 timestamp, guint32 preferred, guint32 lifetime, char *buf, size_t buf_size) { @@ -4884,11 +4908,11 @@ nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len) link->inet6_addr_gen_mode_inv ? " addrgenmode " : "", link->inet6_addr_gen_mode_inv ? nm_platform_link_inet6_addrgenmode2str (_nm_platform_uint8_inv (link->inet6_addr_gen_mode_inv), str_addrmode, sizeof (str_addrmode)) : "", str_addr ? " addr " : "", - str_addr ? str_addr : "", + str_addr ?: "", link->inet6_token.id ? " inet6token " : "", link->inet6_token.id ? nm_utils_inet6_interface_identifier_to_token (link->inet6_token, str_inet6_token) : "", link->driver ? " driver " : "", - link->driver ? link->driver : "", + link->driver ?: "", link->rx_packets, link->rx_bytes, link->tx_packets, link->tx_bytes); g_string_free (str_flags, TRUE); @@ -5300,7 +5324,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu str_label[0] = 0; str_lft_p = _lifetime_to_string (address->timestamp, - address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT, + address->lifetime ?: NM_PLATFORM_LIFETIME_PERMANENT, now, str_lft, sizeof (str_lft)), str_pref_p = (address->lifetime == address->preferred) ? str_lft_p @@ -5312,7 +5336,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu g_snprintf (buf, len, "%s/%d lft %s pref %s%s%s%s%s%s src %s", s_address, address->plen, str_lft_p, str_pref_p, str_time_p, - str_peer ? str_peer : "", + str_peer ?: "", str_dev, _to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)), str_label, @@ -5407,7 +5431,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu _to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev)); str_lft_p = _lifetime_to_string (address->timestamp, - address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT, + address->lifetime ?: NM_PLATFORM_LIFETIME_PERMANENT, now, str_lft, sizeof (str_lft)), str_pref_p = (address->lifetime == address->preferred) ? str_lft_p @@ -5419,7 +5443,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu g_snprintf (buf, len, "%s/%d lft %s pref %s%s%s%s%s src %s", s_address, address->plen, str_lft_p, str_pref_p, str_time_p, - str_peer ? str_peer : "", + str_peer ?: "", str_dev, _to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)), nmp_utils_ip_config_source_to_string (address->addr_source, s_source, sizeof (s_source))); @@ -5492,7 +5516,6 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route, char *buf, gsi _to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev)); - g_snprintf (buf, len, "%s" /* table */ "%s/%d" diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index e6cef63b..2d2bfaab 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -375,7 +375,6 @@ typedef union { #undef __NMPlatformIPAddress_COMMON - /* Default value for adding an IPv4 route. This is also what iproute2 does. * Note that contrary to IPv6, you can add routes with metric 0 and it is even * the default. @@ -471,7 +470,6 @@ typedef union { \ /*end*/ - typedef struct { __NMPlatformIPRoute_COMMON; union { @@ -595,7 +593,6 @@ typedef struct { #undef __NMPlatformObject_COMMON - typedef struct { gboolean is_ip4; NMPObjectType obj_type; diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 29bb999b..50e6825b 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -2387,7 +2387,6 @@ out: return ops_type; } - NMPCacheOpsType nmp_cache_update_link_udev (NMPCache *cache, int ifindex, diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index 7885c083..42569d5b 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -28,7 +28,7 @@ #include "test-common.h" #define SIGNAL_DATA_FMT "'%s-%s' ifindex %d%s%s%s (%d times received)" -#define SIGNAL_DATA_ARG(data) (data)->name, nm_platform_signal_change_type_to_string ((data)->change_type), (data)->ifindex, (data)->ifname ? " ifname '" : "", (data)->ifname ? (data)->ifname : "", (data)->ifname ? "'" : "", (data)->received_count +#define SIGNAL_DATA_ARG(data) (data)->name, nm_platform_signal_change_type_to_string ((data)->change_type), (data)->ifindex, (data)->ifname ? " ifname '" : "", (data)->ifname ?: "", (data)->ifname ? "'" : "", (data)->received_count int NMTSTP_ENV1_IFINDEX = -1; int NMTSTP_ENV1_EX = -1; @@ -1258,7 +1258,7 @@ nmtstp_link_gre_add (NMPlatform *platform, success = !nmtstp_run_command ("ip tunnel add %s mode gre %s local %s remote %s ttl %u tos %02x %s", name, - dev ? dev : "", + dev ?: "", nm_utils_inet4_ntop (lnk->local, NULL), nm_utils_inet4_ntop (lnk->remote, buffer), lnk->ttl, @@ -1568,7 +1568,7 @@ nmtstp_link_vxlan_add (NMPlatform *platform, err = nmtstp_run_command ("ip link add %s type vxlan id %u %s local %s group %s ttl %u tos %02x dstport %u srcport %u %u ageing %u", name, lnk->id, - dev ? dev : "", + dev ?: "", local, remote, lnk->ttl, diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c index 342aa0d6..8708c80f 100644 --- a/src/platform/tests/test-general.c +++ b/src/platform/tests/test-general.c @@ -27,7 +27,6 @@ #include "nm-test-utils-core.h" - /*****************************************************************************/ static void diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index dcd600ee..cd5880e3 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -1070,6 +1070,14 @@ test_software_detect (gconstpointer user_data) if (lnk) g_assert (memcmp (plnk, &lnk_tun2, sizeof (NMPlatformLnkTun)) == 0); + if (i_step == 0) { + /* Before we upped the device for the first time the kernel didn't notify + * us of the owner set after the link creation: + * https://bugzilla.redhat.com/show_bug.cgi?id=1566062 + */ + break; + } + g_assert (nm_platform_lnk_tun_cmp (plnk, &lnk_tun) == 0); break; } @@ -1513,7 +1521,6 @@ test_vlan_set_xgress (void) 6, 7); } - { const NMVlanQosMapping ingress_map[] = { { .from = 1, .to = 5 }, @@ -1826,14 +1833,12 @@ test_nl_bugs_veth (void) } g_assert_cmpint (pllink_veth0->parent, ==, ifindex_veth1); - /* The following tests whether we have a workaround for kernel bug * https://bugzilla.redhat.com/show_bug.cgi?id=1285827 in place. */ pllink_veth1 = nm_platform_link_get (NM_PLATFORM_GET, ifindex_veth1); g_assert (pllink_veth1); g_assert_cmpint (pllink_veth1->parent, ==, ifindex_veth0); - /* move one veth peer to another namespace and check that the * parent/IFLA_LINK of the remaining peer properly updates * (https://bugzilla.redhat.com/show_bug.cgi?id=1262908). */ @@ -2381,7 +2386,6 @@ test_netns_push (gpointer fixture, gconstpointer test_data) g_assert_not_reached (); } - for (i = nstack; i >= 1; ) { i--; nmp_netns_pop (nm_platform_netns_get (stack[i].pl->platform)); diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c index db187a1f..767e23a9 100644 --- a/src/platform/wifi/wifi-utils-nl80211.c +++ b/src/platform/wifi/wifi-utils-nl80211.c @@ -250,8 +250,7 @@ wifi_nl80211_set_mode (WifiData *data, const NM80211Mode mode) err = nl80211_send_and_recv (nl80211, msg, NULL, NULL); return err >= 0; - nla_put_failure: - nlmsg_free (msg); +nla_put_failure: return FALSE; } @@ -269,7 +268,6 @@ wifi_nl80211_set_powersave (WifiData *data, guint32 powersave) return err >= 0; nla_put_failure: - nlmsg_free (msg); return FALSE; } @@ -542,8 +540,7 @@ nl80211_get_ap_info (WifiDataNl80211 *nl80211, return; - nla_put_failure: - nlmsg_free (msg); +nla_put_failure: return; } @@ -597,7 +594,6 @@ wifi_nl80211_indicate_addressing_running (WifiData *data, gboolean running) return err >= 0; nla_put_failure: - nlmsg_free (msg); return FALSE; } diff --git a/src/platform/wifi/wifi-utils.h b/src/platform/wifi/wifi-utils.h index 2633e965..8acc35fc 100644 --- a/src/platform/wifi/wifi-utils.h +++ b/src/platform/wifi/wifi-utils.h @@ -66,7 +66,6 @@ gboolean wifi_utils_get_wowlan (WifiData *data); gboolean wifi_utils_set_powersave (WifiData *data, guint32 powersave); - /* OLPC Mesh-only functions */ guint32 wifi_utils_get_mesh_channel (WifiData *data); diff --git a/src/ppp/meson.build b/src/ppp/meson.build index 20edb9d0..38f9a0f1 100644 --- a/src/ppp/meson.build +++ b/src/ppp/meson.build @@ -37,5 +37,5 @@ core_plugins += shared_module( ], link_depends: linker_script, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) diff --git a/src/ppp/nm-ppp-manager-call.c b/src/ppp/nm-ppp-manager-call.c index ed70f687..3d6fee49 100644 --- a/src/ppp/nm-ppp-manager-call.c +++ b/src/ppp/nm-ppp-manager-call.c @@ -82,9 +82,8 @@ nm_ppp_manager_create (const char *iface, GError **error) nm_assert (ops); nm_assert (ops->create); nm_assert (ops->start); - nm_assert (ops->stop_async); - nm_assert (ops->stop_finish); - nm_assert (ops->stop_sync); + nm_assert (ops->stop); + nm_assert (ops->stop_cancel); ppp_ops = ops; @@ -125,32 +124,21 @@ nm_ppp_manager_start (NMPPPManager *self, return ppp_ops->start (self, req, ppp_name, timeout_secs, baud_override, err); } -void -nm_ppp_manager_stop_async (NMPPPManager *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +NMPPPManagerStopHandle * +nm_ppp_manager_stop (NMPPPManager *self, + NMPPPManagerStopCallback callback, + gpointer user_data) { - g_return_if_fail (ppp_ops); + g_return_val_if_fail (ppp_ops, NULL); - ppp_ops->stop_async (self, cancellable, callback, user_data); -} - -gboolean -nm_ppp_manager_stop_finish (NMPPPManager *self, - GAsyncResult *res, - GError **error) -{ - g_return_val_if_fail (ppp_ops, FALSE); - - return ppp_ops->stop_finish (self, res, error); + return ppp_ops->stop (self, callback, user_data); } void -nm_ppp_manager_stop_sync (NMPPPManager *self) +nm_ppp_manager_stop_cancel (NMPPPManagerStopHandle *handle) { g_return_if_fail (ppp_ops); + g_return_if_fail (handle); - ppp_ops->stop_sync (self); + ppp_ops->stop_cancel (handle); } - diff --git a/src/ppp/nm-ppp-manager-call.h b/src/ppp/nm-ppp-manager-call.h index 2258ae08..daf8a82e 100644 --- a/src/ppp/nm-ppp-manager-call.h +++ b/src/ppp/nm-ppp-manager-call.h @@ -38,13 +38,11 @@ gboolean nm_ppp_manager_start (NMPPPManager *self, guint32 timeout_secs, guint baud_override, GError **error); -void nm_ppp_manager_stop_async (NMPPPManager *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_ppp_manager_stop_finish (NMPPPManager *self, - GAsyncResult *res, - GError **error); -void nm_ppp_manager_stop_sync (NMPPPManager *self); + +NMPPPManagerStopHandle *nm_ppp_manager_stop (NMPPPManager *self, + NMPPPManagerStopCallback callback, + gpointer user_data); + +void nm_ppp_manager_stop_cancel (NMPPPManagerStopHandle *handle); #endif /* __NM_PPP_MANAGER_CALL_H__ */ diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index 7d1eb408..fc658bec 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -134,8 +134,11 @@ G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_DBUS_OBJECT) /*****************************************************************************/ -static void _ppp_cleanup (NMPPPManager *manager); -static void _ppp_kill (NMPPPManager *manager); +static void _ppp_cleanup (NMPPPManager *self); + +static NMPPPManagerStopHandle *_ppp_manager_stop (NMPPPManager *self, + NMPPPManagerStopCallback callback, + gpointer user_data); /*****************************************************************************/ @@ -173,8 +176,8 @@ _ppp_manager_set_route_parameters (NMPPPManager *self, static gboolean monitor_cb (gpointer user_data) { - NMPPPManager *manager = NM_PPP_MANAGER (user_data); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManager *self = NM_PPP_MANAGER (user_data); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); const char *ifname; ifname = nm_platform_link_get_name (NM_PLATFORM_GET, priv->ifindex); @@ -190,7 +193,7 @@ monitor_cb (gpointer user_data) if (errno != ENODEV) _LOGW ("could not read ppp stats: %s", strerror (errno)); } else { - g_signal_emit (manager, signals[STATS], 0, + g_signal_emit (self, signals[STATS], 0, (guint) stats.p.ppp_ibytes, (guint) stats.p.ppp_obytes); } @@ -200,9 +203,9 @@ monitor_cb (gpointer user_data) } static void -monitor_stats (NMPPPManager *manager) +monitor_stats (NMPPPManager *self) { - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); /* already monitoring */ if (priv->monitor_fd >= 0) @@ -213,7 +216,7 @@ monitor_stats (NMPPPManager *manager) g_warn_if_fail (priv->monitor_id == 0); if (priv->monitor_id) g_source_remove (priv->monitor_id); - priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, manager); + priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, self); } else _LOGW ("could not monitor PPP stats: %s", strerror (errno)); } @@ -351,8 +354,8 @@ impl_ppp_manager_need_secrets (NMDBusObject *obj, GDBusMethodInvocation *invocation, GVariant *parameters) { - NMPPPManager *manager = NM_PPP_MANAGER (obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManager *self = NM_PPP_MANAGER (obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); NMConnection *applied_connection; const char *username = NULL; const char *password = NULL; @@ -371,7 +374,7 @@ impl_ppp_manager_need_secrets (NMDBusObject *obj, if (extract_details_from_connection (applied_connection, NULL, &username, &password, &error)) { /* Send existing secrets to the PPP plugin */ priv->pending_secrets_context = invocation; - ppp_secrets_cb (priv->act_req, priv->secrets_id, NULL, NULL, manager); + ppp_secrets_cb (priv->act_req, priv->secrets_id, NULL, NULL, self); } else { _LOGW ("%s", error->message); g_dbus_method_invocation_take_error (priv->pending_secrets_context, error); @@ -393,7 +396,7 @@ impl_ppp_manager_need_secrets (NMDBusObject *obj, flags, hints ? g_ptr_array_index (hints, 0) : NULL, ppp_secrets_cb, - manager); + self); g_object_set_qdata (G_OBJECT (applied_connection), ppp_manager_secret_tries_quark (), GUINT_TO_POINTER (++tries)); priv->pending_secrets_context = invocation; @@ -410,11 +413,11 @@ impl_ppp_manager_set_state (NMDBusObject *obj, GDBusMethodInvocation *invocation, GVariant *parameters) { - NMPPPManager *manager = NM_PPP_MANAGER (obj); + NMPPPManager *self = NM_PPP_MANAGER (obj); guint32 state; g_variant_get (parameters, "(u)", &state); - g_signal_emit (manager, signals[STATE_CHANGED], 0, (guint) state); + g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) state); g_dbus_method_invocation_return_value (invocation, NULL); } @@ -427,8 +430,8 @@ impl_ppp_manager_set_ifindex (NMDBusObject *obj, GDBusMethodInvocation *invocation, GVariant *parameters) { - NMPPPManager *manager = NM_PPP_MANAGER (obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManager *self = NM_PPP_MANAGER (obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); const NMPlatformLink *plink = NULL; nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL; gint32 ifindex; @@ -459,7 +462,7 @@ impl_ppp_manager_set_ifindex (NMDBusObject *obj, obj_keep_alive = nmp_object_ref (NMP_OBJECT_UP_CAST (plink)); - g_signal_emit (manager, signals[IFINDEX_SET], 0, ifindex, plink->name); + g_signal_emit (self, signals[IFINDEX_SET], 0, ifindex, plink->name); g_dbus_method_invocation_return_value (invocation, NULL); } @@ -498,8 +501,8 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, GDBusMethodInvocation *invocation, GVariant *parameters) { - NMPPPManager *manager = NM_PPP_MANAGER (obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManager *self = NM_PPP_MANAGER (obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); gs_unref_object NMIP4Config *config = NULL; NMPlatformIP4Address address; guint32 u32, mtu; @@ -512,7 +515,7 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, nm_clear_g_source (&priv->ppp_timeout_handler); - if (!set_ip_config_common (manager, config_dict, &mtu)) + if (!set_ip_config_common (self, config_dict, &mtu)) goto out; config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), priv->ifindex); @@ -564,7 +567,7 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, } /* Push the IP4 config up to the device */ - g_signal_emit (manager, signals[IP4_CONFIG], 0, config); + g_signal_emit (self, signals[IP4_CONFIG], 0, config); out: g_dbus_method_invocation_return_value (invocation, NULL); @@ -608,8 +611,8 @@ impl_ppp_manager_set_ip6_config (NMDBusObject *obj, GDBusMethodInvocation *invocation, GVariant *parameters) { - NMPPPManager *manager = NM_PPP_MANAGER (obj); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManager *self = NM_PPP_MANAGER (obj); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); gs_unref_object NMIP6Config *config = NULL; NMPlatformIP6Address addr; struct in6_addr a; @@ -623,7 +626,7 @@ impl_ppp_manager_set_ip6_config (NMDBusObject *obj, nm_clear_g_source (&priv->ppp_timeout_handler); - if (!set_ip_config_common (manager, config_dict, NULL)) + if (!set_ip_config_common (self, config_dict, NULL)) goto out; config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), priv->ifindex); @@ -651,7 +654,7 @@ impl_ppp_manager_set_ip6_config (NMDBusObject *obj, nm_ip6_config_add_address (config, &addr); /* Push the IPv6 config and interface identifier up to the device */ - g_signal_emit (manager, signals[IP6_CONFIG], 0, &iid, config); + g_signal_emit (self, signals[IP6_CONFIG], 0, &iid, config); } else _LOGE ("invalid IPv6 address received!"); @@ -744,8 +747,8 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (pppd_exit_code_to_str, int, static void ppp_watch_cb (GPid pid, int status, gpointer user_data) { - NMPPPManager *manager = NM_PPP_MANAGER (user_data); - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManager *self = NM_PPP_MANAGER (user_data); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); int err; const long long lpid = (long long) pid; @@ -770,20 +773,19 @@ ppp_watch_cb (GPid pid, int status, gpointer user_data) priv->pid = 0; priv->ppp_watch_id = 0; - _ppp_cleanup (manager); - g_signal_emit (manager, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); + _ppp_cleanup (self); + g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); } static gboolean pppd_timed_out (gpointer data) { - NMPPPManager *manager = NM_PPP_MANAGER (data); + NMPPPManager *self = NM_PPP_MANAGER (data); _LOGW ("pppd timed out or didn't initialize our dbus module"); - _ppp_cleanup (manager); - _ppp_kill (manager); + _ppp_manager_stop (self, NULL, NULL); - g_signal_emit (manager, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); + g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); return FALSE; } @@ -1008,7 +1010,7 @@ pppoe_fill_defaults (NMSettingPpp *setting) } static gboolean -_ppp_manager_start (NMPPPManager *manager, +_ppp_manager_start (NMPPPManager *self, NMActRequest *req, const char *ppp_name, guint32 timeout_secs, @@ -1028,10 +1030,10 @@ _ppp_manager_start (NMPPPManager *manager, gboolean ip6_enabled = FALSE; gboolean ip4_enabled = FALSE; - g_return_val_if_fail (NM_IS_PPP_MANAGER (manager), FALSE); + g_return_val_if_fail (NM_IS_PPP_MANAGER (self), FALSE); g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE); - priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + priv = NM_PPP_MANAGER_GET_PRIVATE (self); #if !WITH_PPP /* PPP support disabled */ @@ -1042,7 +1044,7 @@ _ppp_manager_start (NMPPPManager *manager, return FALSE; #endif - nm_dbus_object_export (NM_DBUS_OBJECT (manager)); + nm_dbus_object_export (NM_DBUS_OBJECT (self)); priv->pid = 0; @@ -1077,7 +1079,7 @@ _ppp_manager_start (NMPPPManager *manager, ip6_method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG); ip6_enabled = g_strcmp0 (ip6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0; - ppp_cmd = create_pppd_cmd_line (manager, + ppp_cmd = create_pppd_cmd_line (self, s_ppp, pppoe_setting, adsl_setting, @@ -1107,8 +1109,8 @@ _ppp_manager_start (NMPPPManager *manager, _LOGI ("pppd started with pid %lld", (long long) priv->pid); - priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, manager); - priv->ppp_timeout_handler = g_timeout_add_seconds (timeout_secs, pppd_timed_out, manager); + priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, self); + priv->ppp_timeout_handler = g_timeout_add_seconds (timeout_secs, pppd_timed_out, self); priv->act_req = g_object_ref (req); out: @@ -1116,42 +1118,27 @@ out: nm_cmd_line_destroy (ppp_cmd); if (priv->pid <= 0) - nm_dbus_object_unexport (NM_DBUS_OBJECT (manager)); + nm_dbus_object_unexport (NM_DBUS_OBJECT (self)); return priv->pid > 0; } static void -_ppp_kill (NMPPPManager *manager) +_ppp_cleanup (NMPPPManager *self) { NMPPPManagerPrivate *priv; - g_return_if_fail (NM_IS_PPP_MANAGER (manager)); - - priv = NM_PPP_MANAGER_GET_PRIVATE (manager); - - if (priv->pid) { - nm_utils_kill_child_async (priv->pid, SIGTERM, LOGD_PPP, "pppd", 2000, NULL, NULL); - priv->pid = 0; - } -} - -static void -_ppp_cleanup (NMPPPManager *manager) -{ - NMPPPManagerPrivate *priv; - - g_return_if_fail (NM_IS_PPP_MANAGER (manager)); + g_return_if_fail (NM_IS_PPP_MANAGER (self)); - priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + priv = NM_PPP_MANAGER_GET_PRIVATE (self); - cancel_get_secrets (manager); + cancel_get_secrets (self); nm_clear_g_source (&priv->monitor_id); if (priv->monitor_fd >= 0) { /* Get the stats one last time */ - monitor_cb (manager); + monitor_cb (self); nm_close (priv->monitor_fd); priv->monitor_fd = -1; } @@ -1162,108 +1149,133 @@ _ppp_cleanup (NMPPPManager *manager) /*****************************************************************************/ -typedef struct { - NMPPPManager *manager; - GSimpleAsyncResult *result; - GCancellable *cancellable; -} StopContext; +struct _NMPPPManagerStopHandle { + NMPPPManager *self; + NMPPPManagerStopCallback callback; + gpointer user_data; + + /* this object delays shutdown, because we still need to wait until + * pppd process terminated. */ + GObject *shutdown_waitobj; + + guint idle_id; +}; static void -stop_context_complete (StopContext *ctx) +_stop_handle_complete (NMPPPManagerStopHandle *handle, gboolean was_cancelled) { - if (ctx->cancellable) - g_object_unref (ctx->cancellable); - g_simple_async_result_complete_in_idle (ctx->result); - g_object_unref (ctx->result); - g_object_unref (ctx->manager); - g_slice_free (StopContext, ctx); -} + gs_unref_object NMPPPManager *self = NULL; + NMPPPManagerStopCallback callback; -static gboolean -stop_context_complete_if_cancelled (StopContext *ctx) -{ - GError *error = NULL; + self = g_steal_pointer (&handle->self); + if (!self) + return; - if (g_cancellable_set_error_if_cancelled (ctx->cancellable, &error)) { - g_simple_async_result_take_error (ctx->result, error); - stop_context_complete (ctx); - return TRUE; - } - return FALSE; + if (!handle->callback) + return; + + callback = handle->callback; + handle->callback = NULL; + callback (self, handle, was_cancelled, handle->user_data); } -static gboolean -_ppp_manager_stop_finish (NMPPPManager *manager, - GAsyncResult *res, - GError **error) +static void +_stop_handle_destroy (NMPPPManagerStopHandle *handle, gboolean was_cancelled) { - return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); + _stop_handle_complete (handle, was_cancelled); + nm_clear_g_source (&handle->idle_id); + g_clear_object (&handle->shutdown_waitobj); + g_slice_free (NMPPPManagerStopHandle, handle); } static void -kill_child_ready (pid_t pid, - gboolean success, - int child_status, - StopContext *ctx) +_stop_child_cb (pid_t pid, + gboolean success, + int child_status, + gpointer user_data) { - if (stop_context_complete_if_cancelled (ctx)) - return; - stop_context_complete (ctx); + _stop_handle_destroy (user_data, FALSE); } -static void -_ppp_manager_stop_async (NMPPPManager *manager, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +static gboolean +_stop_idle_cb (gpointer user_data) { - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); - StopContext *ctx; + NMPPPManagerStopHandle *handle = user_data; - nm_dbus_object_unexport (NM_DBUS_OBJECT (manager)); + handle->idle_id = 0; + _stop_handle_destroy (handle, FALSE); + return G_SOURCE_REMOVE; +} - ctx = g_slice_new0 (StopContext); - ctx->manager = g_object_ref (manager); - ctx->result = g_simple_async_result_new (G_OBJECT (manager), - callback, - user_data, - _ppp_manager_stop_async); +static NMPPPManagerStopHandle * +_ppp_manager_stop (NMPPPManager *self, + NMPPPManagerStopCallback callback, + gpointer user_data) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); + NMDBusObject *dbus = NM_DBUS_OBJECT (self); + NMPPPManagerStopHandle *handle; - /* Setup cancellable */ - ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - if (stop_context_complete_if_cancelled (ctx)) - return; + if (nm_dbus_object_is_exported (dbus)) + nm_dbus_object_unexport (dbus); - /* Cleanup internals */ - _ppp_cleanup (manager); + _ppp_cleanup (self); + + if ( !priv->pid + && !callback) { + /* nothing to do further... + * + * In this case, we return a %NULL handle. The caller cannot cancel this + * event, but clearly he is not waiting for a callback anyway. */ + return NULL; + } + + handle = g_slice_new0 (NMPPPManagerStopHandle); + handle->self = g_object_ref (self); + handle->callback = callback; + handle->user_data = user_data; - /* If no pppd running, we're done */ if (!priv->pid) { - stop_context_complete (ctx); - return; + /* No PID. There is nothing to kill, however, invoke the callback in + * an idle handler. + * + * Note that we don't register nm_shutdown_wait_obj_register(). + * In order for shutdown to work properly, the caller must always + * explicitly cancel the action to go down. With the idle-handler, + * cancelling the handle completes the request. */ + handle->idle_id = g_idle_add (_stop_idle_cb, handle); + return handle; } - /* No cancellable operation, so just wait until it returns always */ - nm_utils_kill_child_async (priv->pid, - SIGTERM, - LOGD_PPP, - "pppd", - 2000, - (NMUtilsKillChildAsyncCb) kill_child_ready, - ctx); - priv->pid = 0; + /* we really want to kill the process and delay shutdown of NetworkManager + * until the process terminated. We do that, by registering an object + * that delays shutdown. */ + handle->shutdown_waitobj = g_object_new (G_TYPE_OBJECT, NULL); + nm_shutdown_wait_obj_register (handle->shutdown_waitobj, "ppp-manager-wait-kill-pppd"); + nm_utils_kill_child_async (nm_steal_int (&priv->pid), + SIGTERM, LOGD_PPP, "pppd", + NM_SHUTDOWN_TIMEOUT_MS, + _stop_child_cb, handle); + + return handle; } static void -_ppp_manager_stop_sync (NMPPPManager *manager) +_ppp_manager_stop_cancel (NMPPPManagerStopHandle *handle) { - NMDBusObject *dbus = NM_DBUS_OBJECT (manager); + g_return_if_fail (handle); + g_return_if_fail (NM_IS_PPP_MANAGER (handle->self)); - if (nm_dbus_object_is_exported (dbus)) - nm_dbus_object_unexport (dbus); + if (handle->idle_id) { + /* we can complete this fake handle right away. */ + _stop_handle_destroy (handle, TRUE); + return; + } - _ppp_cleanup (manager); - _ppp_kill (manager); + /* a real handle. Only invoke the callback (synchronously). This marks + * the handle as handled, but it keeps shutdown_waitobj around, until + * nm_utils_kill_child_async() returns. */ + _stop_handle_complete (handle, TRUE); } /*****************************************************************************/ @@ -1304,9 +1316,9 @@ set_property (GObject *object, guint prop_id, /*****************************************************************************/ static void -nm_ppp_manager_init (NMPPPManager *manager) +nm_ppp_manager_init (NMPPPManager *self) { - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); priv->ifindex = -1; priv->monitor_fd = -1; @@ -1330,14 +1342,13 @@ static void dispose (GObject *object) { NMPPPManager *self = (NMPPPManager *) object; - NMDBusObject *dbus = NM_DBUS_OBJECT (self); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - if (nm_dbus_object_is_exported (dbus)) - nm_dbus_object_unexport (dbus); - - _ppp_cleanup (self); - _ppp_kill (self); + /* we expect the user to first stop the manager. As fallback, + * still stop. */ + g_warn_if_fail (!priv->pid); + g_warn_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (self))); + _ppp_manager_stop (self, NULL, NULL); g_clear_object (&priv->act_req); @@ -1483,7 +1494,6 @@ NMPPPOps ppp_ops = { .create = _ppp_manager_new, .set_route_parameters = _ppp_manager_set_route_parameters, .start = _ppp_manager_start, - .stop_async = _ppp_manager_stop_async, - .stop_finish = _ppp_manager_stop_finish, - .stop_sync = _ppp_manager_stop_sync, + .stop = _ppp_manager_stop, + .stop_cancel = _ppp_manager_stop_cancel, }; diff --git a/src/ppp/nm-ppp-manager.h b/src/ppp/nm-ppp-manager.h index 5457726e..ec0ca46e 100644 --- a/src/ppp/nm-ppp-manager.h +++ b/src/ppp/nm-ppp-manager.h @@ -32,4 +32,11 @@ typedef struct _NMPPPManager NMPPPManager; +typedef struct _NMPPPManagerStopHandle NMPPPManagerStopHandle; + +typedef void (*NMPPPManagerStopCallback) (NMPPPManager *manager, + NMPPPManagerStopHandle *handle, + gboolean was_cancelled, + gpointer user_data); + #endif /* __NM_PPP_MANAGER_H__ */ diff --git a/src/ppp/nm-ppp-plugin-api.h b/src/ppp/nm-ppp-plugin-api.h index bb53690c..558de2c2 100644 --- a/src/ppp/nm-ppp-plugin-api.h +++ b/src/ppp/nm-ppp-plugin-api.h @@ -21,6 +21,8 @@ #ifndef __NM_PPP_PLUGIN_API_H__ #define __NM_PPP_PLUGIN_API_H__ +#include "nm-ppp-manager.h" + typedef const struct { NMPPPManager *(*create) (const char *iface); @@ -37,16 +39,12 @@ typedef const struct { guint baud_override, GError **err); - void (*stop_async) (NMPPPManager *manager, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); + NMPPPManagerStopHandle *(*stop) (NMPPPManager *manager, + NMPPPManagerStopCallback callback, + gpointer user_data); - gboolean (*stop_finish) (NMPPPManager *manager, - GAsyncResult *res, - GError **error); + void (*stop_cancel) (NMPPPManagerStopHandle *handle); - void (*stop_sync) (NMPPPManager *manager); } NMPPPOps; #endif /* __NM_PPP_PLUGIN_API_H__ */ diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 0b998372..6526abc7 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -135,7 +135,7 @@ G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_D const char *__uuid = (self) ? nm_settings_connection_get_uuid (self) : NULL; \ \ if (self) { \ - g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _NMLOG_PREFIX_NAME, self, __uuid ? "," : "", __uuid ? __uuid : ""); \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p%s%s]", _NMLOG_PREFIX_NAME, self, __uuid ? "," : "", __uuid ?: ""); \ __p_prefix = __prefix; \ } \ _nm_log (__level, _NMLOG_DOMAIN, 0, NULL, __uuid, \ @@ -463,7 +463,7 @@ update_agent_secrets_cache (NMSettingsConnection *self, NMConnection *new) if (priv->agent_secrets) g_object_unref (priv->agent_secrets); - priv->agent_secrets = nm_simple_connection_new_clone (new ? new : NM_CONNECTION (self)); + priv->agent_secrets = nm_simple_connection_new_clone (new ?: NM_CONNECTION(self)); /* Clear out non-system-owned secrets */ nm_connection_clear_secrets_with_flags (priv->agent_secrets, @@ -817,10 +817,8 @@ nm_settings_connection_delete (NMSettingsConnection *self, return TRUE; } - /*****************************************************************************/ - typedef enum { CALL_ID_TYPE_REQ, CALL_ID_TYPE_IDLE, @@ -1810,7 +1808,6 @@ update_auth_cb (NMSettingsConnection *self, update_complete (self, info, local); } - static const char * get_update_modify_permission (NMConnection *old, NMConnection *new) { @@ -1886,7 +1883,7 @@ settings_connection_update (NMSettingsConnection *self, * that's sending the update request. You can't make a connection * invisible to yourself. */ - if (!nm_auth_is_subject_in_acl_set_error (tmp ? tmp : NM_CONNECTION (self), + if (!nm_auth_is_subject_in_acl_set_error (tmp ?: NM_CONNECTION(self), subject, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, @@ -1902,7 +1899,7 @@ settings_connection_update (NMSettingsConnection *self, info->new_settings = tmp; permission = get_update_modify_permission (NM_CONNECTION (self), - tmp ? tmp : NM_CONNECTION (self)); + tmp ?: NM_CONNECTION(self)); auth_start (self, context, subject, permission, update_auth_cb, info); return; diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 58901699..70518687 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -48,7 +48,6 @@ #define NM_SETTINGS_CONNECTION_FLAGS "flags" #define NM_SETTINGS_CONNECTION_FILENAME "filename" - /** * NMSettingsConnectionIntFlags: * @NM_SETTINGS_CONNECTION_INT_FLAGS_NONE: no flag set diff --git a/src/settings/nm-settings-plugin.c b/src/settings/nm-settings-plugin.c index 234e345f..f6dd2cfb 100644 --- a/src/settings/nm-settings-plugin.c +++ b/src/settings/nm-settings-plugin.c @@ -35,30 +35,6 @@ nm_settings_plugin_default_init (NMSettingsPluginInterface *g_iface) if (initialized) return; - /* Properties */ - g_object_interface_install_property - (g_iface, - g_param_spec_string (NM_SETTINGS_PLUGIN_NAME, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_interface_install_property - (g_iface, - g_param_spec_string (NM_SETTINGS_PLUGIN_INFO, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_interface_install_property - (g_iface, - g_param_spec_uint (NM_SETTINGS_PLUGIN_CAPABILITIES, "", "", - NM_SETTINGS_PLUGIN_CAP_NONE, - NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS, - NM_SETTINGS_PLUGIN_CAP_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - /* Signals */ g_signal_new (NM_SETTINGS_PLUGIN_CONNECTION_ADDED, iface_type, diff --git a/src/settings/nm-settings-plugin.h b/src/settings/nm-settings-plugin.h index 97bb7b65..6fba25e7 100644 --- a/src/settings/nm-settings-plugin.h +++ b/src/settings/nm-settings-plugin.h @@ -34,33 +34,10 @@ GObject * nm_settings_plugin_factory (void); #define NM_IS_SETTINGS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTINGS_PLUGIN)) #define NM_SETTINGS_PLUGIN_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_SETTINGS_PLUGIN, NMSettingsPluginInterface)) - -#define NM_SETTINGS_PLUGIN_NAME "name" -#define NM_SETTINGS_PLUGIN_INFO "info" -#define NM_SETTINGS_PLUGIN_CAPABILITIES "capabilities" - #define NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED "unmanaged-specs-changed" #define NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED "unrecognized-specs-changed" #define NM_SETTINGS_PLUGIN_CONNECTION_ADDED "connection-added" -typedef enum { - NM_SETTINGS_PLUGIN_CAP_NONE = 0x00000000, - NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS = 0x00000001, - - /* When adding more capabilities, be sure to update the "Capabilities" - * property max value in nm-settings-plugin.c. - */ -} NMSettingsPluginCapabilities; - -typedef enum { - NM_SETTINGS_PLUGIN_PROP_FIRST = 0x1000, - - NM_SETTINGS_PLUGIN_PROP_NAME = NM_SETTINGS_PLUGIN_PROP_FIRST, - NM_SETTINGS_PLUGIN_PROP_INFO, - NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, -} NMSettingsPluginProp; - - typedef struct _NMSettingsPlugin NMSettingsPlugin; typedef struct { diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 2c6b7101..94018734 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -493,21 +493,28 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path) gboolean nm_settings_has_connection (NMSettings *self, NMSettingsConnection *connection) { - NMSettingsConnection *candidate = NULL; - const char *path; + gboolean has; g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE); g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE); - path = nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)); - if (path) - candidate = nm_settings_get_connection_by_path (self, path); + has = !c_list_is_empty (&connection->_connections_lst); + + nm_assert (has == nm_c_list_contains_entry (&NM_SETTINGS_GET_PRIVATE (self)->connections_lst_head, + connection, + _connections_lst)); + nm_assert (({ + NMSettingsConnection *candidate = NULL; + const char *path; + + path = nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)); + if (path) + candidate = nm_settings_get_connection_by_path (self, path); + + (has == (connection == candidate)); + })); - nm_assert (!candidate || candidate == connection); - nm_assert (!!candidate == nm_c_list_contains_entry (&NM_SETTINGS_GET_PRIVATE (self)->connections_lst_head, - connection, - _connections_lst)); - return !!candidate; + return has; } const GSList * @@ -519,7 +526,7 @@ nm_settings_get_unmanaged_specs (NMSettings *self) } static NMSettingsPlugin * -get_plugin (NMSettings *self, NMSettingsPluginCapabilities capability) +get_plugin (NMSettings *self, gboolean has_add_connection) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GSList *iter; @@ -528,11 +535,13 @@ get_plugin (NMSettings *self, NMSettingsPluginCapabilities capability) /* Do any of the plugins support the given capability? */ for (iter = priv->plugins; iter; iter = iter->next) { - NMSettingsPluginCapabilities caps = NM_SETTINGS_PLUGIN_CAP_NONE; + NMSettingsPlugin *plugin = NM_SETTINGS_PLUGIN (iter->data); + + if (!has_add_connection) + return plugin; - g_object_get (G_OBJECT (iter->data), NM_SETTINGS_PLUGIN_CAPABILITIES, &caps, NULL); - if (NM_FLAGS_ALL (caps, capability)) - return NM_SETTINGS_PLUGIN (iter->data); + if (NM_SETTINGS_PLUGIN_GET_INTERFACE (iter->data)->add_connection != NULL) + return plugin; } return NULL; @@ -602,8 +611,6 @@ static gboolean add_plugin (NMSettings *self, NMSettingsPlugin *plugin) { NMSettingsPrivate *priv; - char *pname = NULL; - char *pinfo = NULL; const char *path; g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE); @@ -619,44 +626,102 @@ add_plugin (NMSettings *self, NMSettingsPlugin *plugin) priv->plugins = g_slist_append (priv->plugins, g_object_ref (plugin)); nm_settings_plugin_init (plugin); - g_object_get (G_OBJECT (plugin), - NM_SETTINGS_PLUGIN_NAME, &pname, - NM_SETTINGS_PLUGIN_INFO, &pinfo, - NULL); path = g_object_get_qdata (G_OBJECT (plugin), plugin_module_path_quark ()); - _LOGI ("loaded plugin %s: %s%s%s%s", pname, pinfo, - NM_PRINT_FMT_QUOTED (path, " (", path, ")", "")); - g_free (pname); - g_free (pinfo); + _LOGI ("Loaded settings plugin: %s (%s)", G_OBJECT_TYPE_NAME (plugin), path ?: "internal"); return TRUE; } -static GObject * -find_plugin (GSList *list, const char *pname) +static gboolean +plugin_loaded (GSList *list, const char *path) { GSList *iter; - GObject *obj = NULL; - g_return_val_if_fail (pname != NULL, NULL); + g_return_val_if_fail (path != NULL, TRUE); - for (iter = list; iter && !obj; iter = g_slist_next (iter)) { - NMSettingsPlugin *plugin = NM_SETTINGS_PLUGIN (iter->data); - char *list_pname = NULL; + for (iter = list; iter; iter = g_slist_next (iter)) { + const char *list_path = g_object_get_qdata (G_OBJECT (iter->data), + plugin_module_path_quark ()); + + if (g_strcmp0 (path, list_path) == 0) + return TRUE; + } + + return FALSE; +} + +static gboolean +load_plugin (NMSettings *self, GSList *list, const char *pname, GError **error) +{ + gs_free char *full_name = NULL; + gs_free char *path = NULL; + gs_unref_object GObject *obj = NULL; + GModule *plugin; + GObject * (*factory_func) (void); + struct stat st; + int errsv; + + full_name = g_strdup_printf ("nm-settings-plugin-%s", pname); + path = g_module_build_path (NMPLUGINDIR, full_name); + + if (plugin_loaded (list, path)) + return TRUE; + + if (stat (path, &st) != 0) { + errsv = errno; + _LOGW ("could not load plugin '%s' from file '%s': %s", pname, path, strerror (errsv)); + return TRUE; + } + if (!S_ISREG (st.st_mode)) { + _LOGW ("could not load plugin '%s' from file '%s': not a file", pname, path); + return TRUE; + } + if (st.st_uid != 0) { + _LOGW ("could not load plugin '%s' from file '%s': file must be owned by root", pname, path); + return TRUE; + } + if (st.st_mode & (S_IWGRP | S_IWOTH | S_ISUID)) { + _LOGW ("could not load plugin '%s' from file '%s': invalid file permissions", pname, path); + return TRUE; + } + + plugin = g_module_open (path, G_MODULE_BIND_LOCAL); + if (!plugin) { + _LOGW ("could not load plugin '%s' from file '%s': %s", + pname, path, g_module_error ()); + return TRUE; + } + + /* errors after this point are fatal, because we loaded the shared library already. */ + + if (!g_module_symbol (plugin, "nm_settings_plugin_factory", (gpointer) (&factory_func))) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Could not find plugin '%s' factory function.", + pname); + g_module_close (plugin); + return FALSE; + } - g_object_get (G_OBJECT (plugin), - NM_SETTINGS_PLUGIN_NAME, - &list_pname, - NULL); - if (list_pname && !strcmp (pname, list_pname)) - obj = G_OBJECT (plugin); + /* after accessing the plugin we cannot unload it anymore, because the glib + * types cannot be properly unregistered. */ + g_module_make_resident (plugin); - g_free (list_pname); + obj = (*factory_func) (); + if (!obj || !NM_IS_SETTINGS_PLUGIN (obj)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Plugin '%s' returned invalid system config object.", + pname); + return FALSE; } - return obj; + g_object_set_qdata_full (obj, plugin_module_path_quark (), path, g_free); + path = NULL; + if (add_plugin (self, NM_SETTINGS_PLUGIN (obj))) + list = g_slist_append (list, g_steal_pointer (&obj)); + + return TRUE; } static void @@ -689,7 +754,6 @@ load_plugins (NMSettings *self, const char **plugins, GError **error) for (iter = plugins; iter && *iter; iter++) { const char *pname = *iter; - GObject *obj; if (!*pname || strchr (pname, '/')) { _LOGW ("ignore invalid plugin \"%s\"", pname); @@ -723,84 +787,19 @@ load_plugins (NMSettings *self, const char **plugins, GError **error) continue; } - if (find_plugin (list, pname)) - continue; - -load_plugin: - { - GModule *plugin; - gs_free char *full_name = NULL; - gs_free char *path = NULL; - GObject * (*factory_func) (void); - struct stat st; - int errsv; - - full_name = g_strdup_printf ("nm-settings-plugin-%s", pname); - path = g_module_build_path (NMPLUGINDIR, full_name); - - if (stat (path, &st) != 0) { - errsv = errno; - _LOGW ("could not load plugin '%s' from file '%s': %s", pname, path, strerror (errsv)); - goto next; - } - if (!S_ISREG (st.st_mode)) { - _LOGW ("could not load plugin '%s' from file '%s': not a file", pname, path); - goto next; - } - if (st.st_uid != 0) { - _LOGW ("could not load plugin '%s' from file '%s': file must be owned by root", pname, path); - goto next; - } - if (st.st_mode & (S_IWGRP | S_IWOTH | S_ISUID)) { - _LOGW ("could not load plugin '%s' from file '%s': invalid file permissions", pname, path); - goto next; - } - - plugin = g_module_open (path, G_MODULE_BIND_LOCAL); - if (!plugin) { - _LOGW ("could not load plugin '%s' from file '%s': %s", - pname, path, g_module_error ()); - goto next; - } - - /* errors after this point are fatal, because we loaded the shared library already. */ - - if (!g_module_symbol (plugin, "nm_settings_plugin_factory", (gpointer) (&factory_func))) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not find plugin '%s' factory function.", - pname); - success = FALSE; - g_module_close (plugin); - break; - } + success = load_plugin (self, list, pname, error); + if (!success) + break; - /* after accessing the plugin we cannot unload it anymore, because the glib - * types cannot be properly unregistered. */ - g_module_make_resident (plugin); - - obj = (*factory_func) (); - if (!obj || !NM_IS_SETTINGS_PLUGIN (obj)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Plugin '%s' returned invalid system config object.", - pname); - success = FALSE; - break; - } - - g_object_set_qdata_full (obj, plugin_module_path_quark (), path, g_free); - path = NULL; - if (add_plugin (self, NM_SETTINGS_PLUGIN (obj))) - list = g_slist_append (list, obj); - else - g_object_unref (obj); - } -next: if (add_ibft && !strcmp (pname, "ifcfg-rh")) { /* The plugin ibft is not explicitly mentioned but we just enabled "ifcfg-rh". * Enable "ibft" by default after "ifcfg-rh". */ pname = "ibft"; add_ibft = FALSE; - goto load_plugin; + + success = load_plugin (self, list, "ibft", error); + if (!success) + break; } } @@ -1239,19 +1238,20 @@ void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, gboolean save_to_disk, + NMAuthSubject *subject, GDBusMethodInvocation *context, NMSettingsAddCallback callback, gpointer user_data) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingConnection *s_con; - NMAuthSubject *subject = NULL; NMAuthChain *chain; GError *error = NULL, *tmp_error = NULL; const char *perm; - g_return_if_fail (connection != NULL); - g_return_if_fail (context != NULL); + g_return_if_fail (NM_IS_CONNECTION (connection)); + g_return_if_fail (NM_IS_AUTH_SUBJECT (subject)); + g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (context)); /* Connection must be valid, of course */ if (!nm_connection_verify (connection, &tmp_error)) { @@ -1275,21 +1275,13 @@ nm_settings_add_connection_dbus (NMSettings *self, } /* Do any of the plugins support adding? */ - if (!get_plugin (self, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS)) { + if (!get_plugin (self, TRUE)) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_NOT_SUPPORTED, "None of the registered plugins support add."); goto done; } - subject = nm_auth_subject_new_unix_process_from_context (context); - if (!subject) { - error = g_error_new_literal (NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Unable to determine UID of request."); - goto done; - } - if (!nm_auth_is_subject_in_acl_set_error (connection, subject, NM_SETTINGS_ERROR, @@ -1318,20 +1310,19 @@ nm_settings_add_connection_dbus (NMSettings *self, } priv->auths = g_slist_append (priv->auths, chain); - nm_auth_chain_add_call (chain, perm, TRUE); nm_auth_chain_set_data (chain, "perm", (gpointer) perm, NULL); nm_auth_chain_set_data (chain, "connection", g_object_ref (connection), g_object_unref); nm_auth_chain_set_data (chain, "callback", callback, NULL); nm_auth_chain_set_data (chain, "callback-data", user_data, NULL); nm_auth_chain_set_data (chain, "subject", g_object_ref (subject), g_object_unref); nm_auth_chain_set_data (chain, "save-to-disk", GUINT_TO_POINTER (save_to_disk), NULL); + nm_auth_chain_add_call (chain, perm, TRUE); + return; done: - if (error) - callback (self, NULL, error, context, subject, user_data); - - g_clear_error (&error); - g_clear_object (&subject); + nm_assert (error); + callback (self, NULL, error, context, subject, user_data); + g_error_free (error); } static void @@ -1362,6 +1353,7 @@ settings_add_connection_helper (NMSettings *self, { gs_unref_object NMConnection *connection = NULL; GError *error = NULL; + gs_unref_object NMAuthSubject *subject = NULL; connection = _nm_simple_connection_new_from_dbus (settings, NM_SETTING_PARSE_FLAGS_STRICT @@ -1374,9 +1366,19 @@ settings_add_connection_helper (NMSettings *self, return; } + subject = nm_auth_subject_new_unix_process_from_context (context); + if (!subject) { + g_dbus_method_invocation_return_error_literal (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_PERMISSION_DENIED, + "Unable to determine UID of request."); + return; + } + nm_settings_add_connection_dbus (self, connection, save_to_disk, + subject, context, settings_add_connection_add_cb, NULL); @@ -1857,7 +1859,7 @@ get_property (GObject *object, guint prop_id, : NULL); break; case PROP_CAN_MODIFY: - g_value_set_boolean (value, !!get_plugin (self, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS)); + g_value_set_boolean (value, !!get_plugin (self, TRUE)); break; case PROP_CONNECTIONS: if (priv->connections_loaded) { diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index 7d56f7b4..021512fd 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -80,6 +80,7 @@ typedef void (*NMSettingsAddCallback) (NMSettings *settings, void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, gboolean save_to_disk, + NMAuthSubject *subject, GDBusMethodInvocation *context, NMSettingsAddCallback callback, gpointer user_data); diff --git a/src/settings/plugins/ibft/meson.build b/src/settings/plugins/ibft/meson.build index da9f5566..1b6ff28a 100644 --- a/src/settings/plugins/ibft/meson.build +++ b/src/settings/plugins/ibft/meson.build @@ -26,7 +26,7 @@ libnm_settings_plugin_ibft = shared_module( link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_settings_plugin_ibft diff --git a/src/settings/plugins/ibft/nms-ibft-plugin.c b/src/settings/plugins/ibft/nms-ibft-plugin.c index ea4d1524..77ce208f 100644 --- a/src/settings/plugins/ibft/nms-ibft-plugin.c +++ b/src/settings/plugins/ibft/nms-ibft-plugin.c @@ -121,28 +121,6 @@ get_connections (NMSettingsPlugin *config) /*****************************************************************************/ static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case NM_SETTINGS_PLUGIN_PROP_NAME: - g_value_set_string (value, "iBFT"); - break; - case NM_SETTINGS_PLUGIN_PROP_INFO: - g_value_set_string (value, "(c) 2014 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."); - break; - case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: - g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_NONE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - -static void init (NMSettingsPlugin *config) { } @@ -175,19 +153,6 @@ nms_ibft_plugin_class_init (NMSIbftPluginClass *req_class) GObjectClass *object_class = G_OBJECT_CLASS (req_class); object_class->dispose = dispose; - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_NAME, - NM_SETTINGS_PLUGIN_NAME); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_INFO, - NM_SETTINGS_PLUGIN_INFO); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, - NM_SETTINGS_PLUGIN_CAPABILITIES); } static void diff --git a/src/settings/plugins/ibft/nms-ibft-reader.c b/src/settings/plugins/ibft/nms-ibft-reader.c index d26c8334..cf849e28 100644 --- a/src/settings/plugins/ibft/nms-ibft-reader.c +++ b/src/settings/plugins/ibft/nms-ibft-reader.c @@ -128,7 +128,7 @@ nms_ibft_reader_load_blocks (const char *iscsiadm_path, } g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "iBFT: %s exited with error %d. Message: '%s'", - iscsiadm_path, WEXITSTATUS (status), err ? err : "(none)"); + iscsiadm_path, WEXITSTATUS (status), err ?: "(none)"); goto done; } @@ -392,15 +392,15 @@ connection_setting_add (const GPtrArray *block, id = g_strdup_printf ("iBFT%s%s %s", prefix ? " " : "", - prefix ? prefix : "", + prefix ?: "", iface); uuid = _nm_utils_uuid_generate_from_strings ("ibft", s_hwaddr, s_vlanid ? "V" : "v", - s_vlanid ? s_vlanid : "", + s_vlanid ?: "", s_ip4addr ? "A" : "DHCP", - s_ip4addr ? s_ip4addr : "", + s_ip4addr ?: "", NULL); s_con = nm_setting_connection_new (); diff --git a/src/settings/plugins/ibft/tests/meson.build b/src/settings/plugins/ibft/tests/meson.build index 7a9445dd..59f49c31 100644 --- a/src/settings/plugins/ibft/tests/meson.build +++ b/src/settings/plugins/ibft/tests/meson.build @@ -2,16 +2,11 @@ test_unit = 'test-ibft' test_ibft_dir = meson.current_source_dir() -cflags = [ - '-DTEST_IBFT_DIR="@0@"'.format(test_ibft_dir), - '-DTEST_SCRATCH_DIR="@0@"'.format(test_ibft_dir) -] - exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: cflags, + c_args: nm_build_cflags, link_with: libnms_ibft_core ) diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c index fd2ec61b..5e46be2e 100644 --- a/src/settings/plugins/ibft/tests/test-ibft.c +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -36,6 +36,8 @@ #include "nm-test-utils-core.h" +#define TEST_DIR NM_BUILD_SRCDIR"/src/settings/plugins/ibft/tests" + static GPtrArray * read_block (const char *iscsiadm_path, const char *expected_mac) { @@ -78,7 +80,7 @@ test_read_ibft_dhcp (void) const char *expected_mac_address = "00:33:21:98:b9:f1"; GPtrArray *block; - block = read_block (TEST_IBFT_DIR "/iscsiadm-test-dhcp", expected_mac_address); + block = read_block (TEST_DIR "/iscsiadm-test-dhcp", expected_mac_address); connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_no_error (error); @@ -125,7 +127,7 @@ test_read_ibft_static (void) NMIPAddress *ip4_addr; GPtrArray *block; - block = read_block (TEST_IBFT_DIR "/iscsiadm-test-static", expected_mac_address); + block = read_block (TEST_DIR "/iscsiadm-test-static", expected_mac_address); connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_no_error (error); @@ -227,7 +229,7 @@ test_read_ibft_vlan (void) GError *error = NULL; GPtrArray *block; - block = read_block (TEST_IBFT_DIR "/iscsiadm-test-vlan", expected_mac_address); + block = read_block (TEST_DIR "/iscsiadm-test-vlan", expected_mac_address); connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_no_error (error); @@ -280,12 +282,12 @@ int main (int argc, char **argv) g_test_add_func (TPATH "ibft/dhcp", test_read_ibft_dhcp); g_test_add_func (TPATH "ibft/static", test_read_ibft_static); g_test_add_func (TPATH "ibft/vlan", test_read_ibft_vlan); - g_test_add_data_func (TPATH "ibft/bad-record-read", TEST_IBFT_DIR "/iscsiadm-test-bad-record", test_read_ibft_malformed); - g_test_add_data_func (TPATH "ibft/bad-entry-read", TEST_IBFT_DIR "/iscsiadm-test-bad-entry", test_read_ibft_malformed); - g_test_add_data_func (TPATH "ibft/bad-ipaddr-read", TEST_IBFT_DIR "/iscsiadm-test-bad-ipaddr", test_read_ibft_bad_address); - g_test_add_data_func (TPATH "ibft/bad-gateway-read", TEST_IBFT_DIR "/iscsiadm-test-bad-gateway", test_read_ibft_bad_address); - g_test_add_data_func (TPATH "ibft/bad-dns1-read", TEST_IBFT_DIR "/iscsiadm-test-bad-dns1", test_read_ibft_bad_address); - g_test_add_data_func (TPATH "ibft/bad-dns2-read", TEST_IBFT_DIR "/iscsiadm-test-bad-dns2", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-record-read", TEST_DIR "/iscsiadm-test-bad-record", test_read_ibft_malformed); + g_test_add_data_func (TPATH "ibft/bad-entry-read", TEST_DIR "/iscsiadm-test-bad-entry", test_read_ibft_malformed); + g_test_add_data_func (TPATH "ibft/bad-ipaddr-read", TEST_DIR "/iscsiadm-test-bad-ipaddr", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-gateway-read", TEST_DIR "/iscsiadm-test-bad-gateway", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-dns1-read", TEST_DIR "/iscsiadm-test-bad-dns1", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-dns2-read", TEST_DIR "/iscsiadm-test-bad-dns2", test_read_ibft_bad_address); return g_test_run (); } diff --git a/src/settings/plugins/ifcfg-rh/meson.build b/src/settings/plugins/ifcfg-rh/meson.build index fdf308be..964ce22d 100644 --- a/src/settings/plugins/ifcfg-rh/meson.build +++ b/src/settings/plugins/ifcfg-rh/meson.build @@ -55,7 +55,7 @@ libnm_settings_plugin_ifcfg_rh = shared_module( link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_settings_plugin_ifcfg_rh diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h index d850ac4e..eaff2db4 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h @@ -38,9 +38,6 @@ #define IFCFG_DIR SYSCONFDIR "/sysconfig/network-scripts" -#define IFCFG_PLUGIN_NAME "ifcfg-rh" -#define IFCFG_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." - #define TYPE_ETHERNET "Ethernet" #define TYPE_WIRELESS "Wireless" #define TYPE_INFINIBAND "InfiniBand" diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index c7207297..0fb77b9d 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -125,7 +125,6 @@ connection_ifcfg_changed (NMIfcfgConnection *connection, gpointer user_data) path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection)); g_return_if_fail (path != NULL); - if (!priv->ifcfg_monitor) { _LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "ignore event"); return; @@ -419,7 +418,7 @@ ifcfg_dir_changed (GFileMonitor *monitor, path = g_file_get_path (file); ifcfg_path = utils_detect_ifcfg_path (path, FALSE); - _LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ? ifcfg_path : "(none)"); + _LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ?: "(none)"); if (ifcfg_path) { connection = find_by_path (plugin, ifcfg_path); switch (event_type) { @@ -892,7 +891,7 @@ _dbus_request_name_done (GObject *source_object, } } - _LOGD ("dbus: aquired D-Bus service %s and exported %s object", + _LOGD ("dbus: acquired D-Bus service %s and exported %s object", IFCFGRH1_BUS_NAME, IFCFGRH1_OBJECT_PATH); } @@ -999,28 +998,6 @@ config_changed_cb (NMConfig *config, /*****************************************************************************/ static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case NM_SETTINGS_PLUGIN_PROP_NAME: - g_value_set_string (value, IFCFG_PLUGIN_NAME); - break; - case NM_SETTINGS_PLUGIN_PROP_INFO: - g_value_set_string (value, IFCFG_PLUGIN_INFO); - break; - case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: - g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - -static void init (NMSettingsPlugin *config) { } @@ -1088,19 +1065,6 @@ settings_plugin_ifcfg_class_init (SettingsPluginIfcfgClass *req_class) object_class->constructed = constructed; object_class->dispose = dispose; - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_NAME, - NM_SETTINGS_PLUGIN_NAME); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_INFO, - NM_SETTINGS_PLUGIN_INFO); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, - NM_SETTINGS_PLUGIN_CAPABILITIES); } static void diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 6ef3f660..722d4e36 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -256,7 +256,6 @@ make_connection_setting (const char *file, } } - nm_clear_g_free (&value); v = svGetValueStr (ifcfg, "ZONE", &value); g_object_set (s_con, NM_SETTING_CONNECTION_ZONE, v, NULL); @@ -387,7 +386,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) { int i, ignore, *ret_idx; - ret_idx = idx ? idx : &ignore; + ret_idx = idx ?: &ignore; for (i = -1; i <= 2; i++) { gs_free char *value = NULL; @@ -503,7 +502,7 @@ parse_route_line_is_comment (const char *line) * * initscripts compares: "$line" =~ '^[[:space:]]*(\#.*)?$' */ - while (NM_IN_SET (line[0], ' ', '\t')) + while (nm_utils_is_separator (line[0])) line++; if (NM_IN_SET (line[0], '\0', '#')) return TRUE; @@ -1848,8 +1847,8 @@ make_ip6_setting (shvarFile *ifcfg, ipv6addr_secondaries = svGetValueStr_cp (ifcfg, "IPV6ADDR_SECONDARIES"); value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL, - ipv6addr ? ipv6addr : "", - ipv6addr_secondaries ? ipv6addr_secondaries : "", + ipv6addr ?: "", + ipv6addr_secondaries ?: "", NULL); g_free (ipv6addr); g_free (ipv6addr_secondaries); @@ -4420,7 +4419,6 @@ parse_infiniband_p_key (shvarFile *ifcfg, return ret; } - static NMSetting * make_infiniband_setting (shvarFile *ifcfg, const char *file, @@ -4526,9 +4524,9 @@ handle_bond_option (NMSettingBond *s_bond, } } - if (!nm_setting_bond_add_option (s_bond, key, sanitized ? sanitized : value)) + if (!nm_setting_bond_add_option (s_bond, key, sanitized ?: value)) PARSE_WARNING ("invalid bonding option '%s' = %s", - key, sanitized ? sanitized : value); + key, sanitized ?: value); g_free (sanitized); } diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 8584772e..bdad7389 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -777,7 +777,6 @@ write_wireless_security_setting (NMConnection *connection, "WPA_PSK_FLAGS", wpa ? nm_setting_wireless_security_get_psk_flags (s_wsec) : NM_SETTING_SECRET_FLAG_NONE); - if (nm_setting_wireless_security_get_pmf (s_wsec) == NM_SETTING_WIRELESS_SECURITY_PMF_DEFAULT) svUnsetValue (ifcfg, "PMF"); else { @@ -2164,7 +2163,6 @@ write_tc_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) n++; } - num = nm_setting_tc_config_get_num_tfilters (s_tc); for (n = 1, i = 0; i < num; i++) { NMTCTfilter *tfilter; diff --git a/src/settings/plugins/ifcfg-rh/tests/meson.build b/src/settings/plugins/ifcfg-rh/tests/meson.build index 3596b642..3d72d892 100644 --- a/src/settings/plugins/ifcfg-rh/tests/meson.build +++ b/src/settings/plugins/ifcfg-rh/tests/meson.build @@ -2,16 +2,11 @@ test_unit = 'test-ifcfg-rh' test_ifcfg_dir = meson.current_source_dir() -cflags = [ - '-DTEST_IFCFG_DIR="@0@"'.format(test_ifcfg_dir), - '-DTEST_SCRATCH_DIR="@0@"'.format(test_ifcfg_dir) -] - exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: cflags, + c_args: nm_build_cflags, link_with: libnms_ifcfg_rh_core ) diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 57bd96e9..1331391d 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -59,7 +59,11 @@ #include "nm-test-utils-core.h" -#define TEST_SCRATCH_DIR_TMP TEST_SCRATCH_DIR"/network-scripts/tmp" +#define TEST_IFCFG_DIR NM_BUILD_SRCDIR"/src/settings/plugins/ifcfg-rh/tests/network-scripts" +#define TEST_SCRATCH_DIR NM_BUILD_BUILDDIR"/src/settings/plugins/ifcfg-rh/tests/network-scripts" +#define TEST_SCRATCH_DIR_TMP TEST_SCRATCH_DIR"/tmp" + +#define TEST_SCRATCH_ALIAS_BASE TEST_SCRATCH_DIR"/ifcfg-alias0" /*****************************************************************************/ @@ -411,7 +415,7 @@ test_read_netmask_1 (void) NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; NMIPAddress *ip4_addr; - const char *FILENAME = TEST_IFCFG_DIR "/network-scripts/ifcfg-netmask-1"; + const char *FILENAME = TEST_IFCFG_DIR"/ifcfg-netmask-1"; connection = _connection_from_file (FILENAME, NULL, TYPE_ETHERNET, NULL); @@ -431,14 +435,14 @@ test_read_netmask_1 (void) content = nmtst_file_get_contents (FILENAME); - testfile = g_strdup (TEST_SCRATCH_DIR "/network-scripts/ifcfg-netmask-1.copy"); + testfile = g_strdup (TEST_SCRATCH_DIR"/ifcfg-netmask-1.copy"); nmtst_file_set_contents (testfile, content); _writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, testfile, - TEST_IFCFG_DIR "/network-scripts/ifcfg-netmask-1.cexpected"); + TEST_IFCFG_DIR"/ifcfg-netmask-1.cexpected"); } /*****************************************************************************/ @@ -542,7 +546,6 @@ verify_cert_or_key (NMSetting8021x *s_compare, return TRUE; } - static void test_read_basic (void) { @@ -554,7 +557,7 @@ test_read_basic (void) const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-minimal", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-minimal", NULL, TYPE_ETHERNET, NULL); /* ===== CONNECTION SETTING ===== */ @@ -607,7 +610,7 @@ test_read_miscellaneous_variables (void) guint64 expected_timestamp = 0; NMTST_EXPECT_NM_WARN ("*invalid MAC in HWADDR_BLACKLIST 'XX:aa:invalid'*"); - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-misc-variables", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-misc-variables", NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); @@ -648,7 +651,7 @@ test_read_variables_corner_cases (void) const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-variables-corner-cases-1", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-variables-corner-cases-1", NULL, TYPE_ETHERNET, NULL); /* ===== CONNECTION SETTING ===== */ @@ -686,7 +689,7 @@ test_read_unmanaged (void) char *unhandled_spec = NULL; guint64 expected_timestamp = 0; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-nm-controlled", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-nm-controlled", NULL, TYPE_ETHERNET, &unhandled_spec); g_assert_cmpstr (unhandled_spec, ==, "unmanaged:mac:00:11:22:33:f8:9f"); @@ -710,7 +713,7 @@ test_read_unmanaged_unrecognized (void) gs_free char *unhandled_spec = NULL; guint64 expected_timestamp = 0; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-nm-controlled-unrecognized", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-nm-controlled-unrecognized", NULL, NULL, &unhandled_spec); g_assert_cmpstr (unhandled_spec, ==, "unmanaged:interface-name:ipoac0"); @@ -732,7 +735,7 @@ test_read_unrecognized (void) gs_free char *unhandled_spec = NULL; guint64 expected_timestamp = 0; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-unrecognized", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-unrecognized", NULL, NULL, &unhandled_spec); g_assert_cmpstr (unhandled_spec, ==, "unrecognized:mac:00:11:22:33"); @@ -856,7 +859,7 @@ test_read_wired_static_no_prefix (gconstpointer user_data) NMIPAddress *ip4_addr; char *file, *expected_id; - file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); + file = g_strdup_printf (TEST_IFCFG_DIR"/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); expected_id = g_strdup_printf ("System test-wired-static-no-prefix-%u", expected_prefix); NMTST_EXPECT_NM_WARN ("*missing PREFIX, assuming*"); @@ -897,7 +900,7 @@ test_read_wired_dhcp (void) char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee }; const char *mac; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-dhcp", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-dhcp", NULL, TYPE_ETHERNET, &unmanaged); g_assert (unmanaged == NULL); @@ -940,7 +943,7 @@ test_read_wired_dhcp_plus_ip (void) NMIPAddress *ip4_addr; NMIPAddress *ip6_addr; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); /* ===== IPv4 SETTING ===== */ @@ -1007,7 +1010,7 @@ test_read_wired_shared_plus_ip (void) NMSettingIPConfig *s_ip4; NMIPAddress *ip4_addr; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-shared-plus-ip", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-shared-plus-ip", NULL, TYPE_ETHERNET, NULL); /* ===== IPv4 SETTING ===== */ @@ -1039,8 +1042,8 @@ test_read_wired_global_gateway (void) NMIPAddress *ip4_addr; char *unmanaged = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-global-gateway", - TEST_IFCFG_DIR"/network-scripts/network-test-wired-global-gateway", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-global-gateway", + TEST_IFCFG_DIR"/network-test-wired-global-gateway", TYPE_ETHERNET, &unmanaged); g_assert (unmanaged == NULL); @@ -1081,8 +1084,8 @@ test_read_wired_global_gateway_ignore (void) char *unmanaged = NULL; NMTST_EXPECT_NM_WARN ("*ignoring GATEWAY (/etc/sysconfig/network) for * because the connection has no static addresses"); - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-global-gateway-ignore", - TEST_IFCFG_DIR"/network-scripts/network-test-wired-global-gateway-ignore", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-global-gateway-ignore", + TEST_IFCFG_DIR"/network-test-wired-global-gateway-ignore", TYPE_ETHERNET, &unmanaged); g_test_assert_expected_messages (); g_assert (unmanaged == NULL); @@ -1117,7 +1120,7 @@ test_read_wired_obsolete_gateway_n (void) NMSettingIPConfig *s_ip4; NMIPAddress *ip4_addr; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-obsolete-gateway-n", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-obsolete-gateway-n", NULL, TYPE_ETHERNET, NULL); /* ===== IPv4 SETTING ===== */ @@ -1185,8 +1188,8 @@ test_user_1 (void) nm_connection_add_setting (connection, NM_SETTING (s_user)); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_User_1.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_User_1.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -1201,8 +1204,8 @@ test_read_wired_never_default (void) NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-never-default", - TEST_IFCFG_DIR"/network-scripts/network-test-wired-never-default", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-never-default", + TEST_IFCFG_DIR"/network-test-wired-never-default", TYPE_ETHERNET, NULL); /* ===== WIRED SETTING ===== */ @@ -1233,7 +1236,7 @@ test_read_wired_defroute_no (void) NMSettingIPConfig *s_ip6; char *unmanaged = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-defroute-no", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-defroute-no", NULL, TYPE_ETHERNET, &unmanaged); g_assert (unmanaged == NULL); @@ -1265,8 +1268,8 @@ test_read_wired_defroute_no_gatewaydev_yes (void) NMSettingIPConfig *s_ip6; char *unmanaged = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes", - TEST_IFCFG_DIR"/network-scripts/network-test-wired-defroute-no-gatewaydev-yes", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-defroute-no-gatewaydev-yes", + TEST_IFCFG_DIR"/network-test-wired-defroute-no-gatewaydev-yes", TYPE_ETHERNET, &unmanaged); @@ -1298,7 +1301,7 @@ test_read_wired_static_routes (void) NMSettingIPConfig *s_ip4; NMIPRoute *ip4_route; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static-routes", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-static-routes", NULL, TYPE_ETHERNET, NULL); /* ===== CONNECTION SETTING ===== */ @@ -1371,7 +1374,7 @@ test_read_wired_static_routes_legacy (void) char *unmanaged = NULL; NMIPRoute *ip4_route; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static-routes-legacy", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-static-routes-legacy", NULL, TYPE_ETHERNET, &unmanaged); g_assert (!unmanaged); @@ -1513,7 +1516,7 @@ test_read_wired_ipv6_manual (void) NMIPRoute *ip6_route; NMTST_EXPECT_NM_WARN ("*ignoring manual default route*"); - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-ipv6-manual", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-ipv6-manual", NULL, TYPE_ETHERNET, &unmanaged); g_test_assert_expected_messages (); g_assert (!unmanaged); @@ -1689,7 +1692,7 @@ test_read_wired_dhcp6_only (void) char *unmanaged = NULL; const char *method; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp6-only", NULL, TYPE_ETHERNET, &unmanaged); + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-dhcp6-only", NULL, TYPE_ETHERNET, &unmanaged); g_assert (!unmanaged); /* ===== CONNECTION SETTING ===== */ @@ -1727,7 +1730,7 @@ test_read_wired_autoip (void) NMSettingIPConfig *s_ip4; char *unmanaged = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-autoip", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-autoip", NULL, TYPE_ETHERNET, &unmanaged); g_assert (unmanaged == NULL); @@ -1746,7 +1749,7 @@ test_read_onboot_no (void) NMSettingConnection *s_con; char *unmanaged = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-onboot-no", NULL, TYPE_ETHERNET, &unmanaged); + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-onboot-no", NULL, TYPE_ETHERNET, &unmanaged); g_assert (!unmanaged); s_con = nm_connection_get_setting_connection (connection); @@ -1764,7 +1767,7 @@ test_read_noip (void) NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-noip", NULL, TYPE_ETHERNET, NULL); + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-noip", NULL, TYPE_ETHERNET, NULL); s_ip4 = nm_connection_get_setting_ip4_config (connection); g_assert (s_ip4); @@ -1779,7 +1782,7 @@ test_read_noip (void) g_object_unref (connection); } -#define TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT TEST_IFCFG_DIR "/network-scripts/test_ca_cert.pem" +#define TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT TEST_IFCFG_DIR"/test_ca_cert.pem" static void test_read_wired_8021x_peap_mschapv2 (void) @@ -1795,7 +1798,7 @@ test_read_wired_8021x_peap_mschapv2 (void) const char *expected_ca_cert_path; const char *read_ca_cert_path; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-8021x-peap-mschapv2", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-8021x-peap-mschapv2", NULL, TYPE_ETHERNET, &unmanaged); g_assert (!unmanaged); @@ -1896,7 +1899,7 @@ test_read_write_802_1X_subj_matches (void) NMSetting8021x *s_8021x; NMTST_EXPECT_NM_WARN ("*missing IEEE_8021X_CA_CERT*peap*"); - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-802-1X-subj-matches", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-802-1X-subj-matches", NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); @@ -1918,8 +1921,8 @@ test_read_write_802_1X_subj_matches (void) NMTST_EXPECT_NM_WARN ("*missing IEEE_8021X_CA_CERT for EAP method 'peap'; this is insecure!"); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-System_test-wired-802-1X-subj-matches.cexpected", &testfile); g_test_assert_expected_messages (); @@ -1956,7 +1959,7 @@ test_read_802_1x_ttls_eapgtc (void) * NMSetting8021x::autheap property. */ - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-802-1x-ttls-eapgtc", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-802-1x-ttls-eapgtc", NULL, TYPE_WIRELESS, NULL); /* ===== 802.1x SETTING ===== */ @@ -1988,7 +1991,7 @@ test_read_write_802_1x_password_raw (void) /* Test that the 802-1x.password-raw is correctly read and written. */ - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-802-1x-password-raw", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-802-1x-password-raw", NULL, TYPE_ETHERNET, NULL); /* ===== 802.1x SETTING ===== */ @@ -2005,7 +2008,7 @@ test_read_write_802_1x_password_raw (void) NM_SETTING_SECRET_FLAG_NONE); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); keyfile = utils_get_keys_path (testfile); @@ -2035,7 +2038,7 @@ test_read_wired_aliases_good (gconstpointer test_data) expected_label = N == 0 ? expected_label_0 : expected_label_3; expected_num_addresses = g_strv_length ((char **) expected_address); - nm_sprintf_buf (path, TEST_IFCFG_DIR "/network-scripts/ifcfg-aliasem%d", N); + nm_sprintf_buf (path, TEST_IFCFG_DIR"/ifcfg-aliasem%d", N); connection = _connection_from_file (path, NULL, TYPE_ETHERNET, NULL); @@ -2138,14 +2141,14 @@ static void test_read_wired_aliases_bad_1 (void) { NMTST_EXPECT_NM_WARN ("*aliasem1:1*has no DEVICE*"); - test_read_wired_aliases_bad (TEST_IFCFG_DIR "/network-scripts/ifcfg-aliasem1", "System aliasem1"); + test_read_wired_aliases_bad (TEST_IFCFG_DIR"/ifcfg-aliasem1", "System aliasem1"); } static void test_read_wired_aliases_bad_2 (void) { NMTST_EXPECT_NM_WARN ("*aliasem2:1*has invalid DEVICE*"); - test_read_wired_aliases_bad (TEST_IFCFG_DIR "/network-scripts/ifcfg-aliasem2", "System aliasem2"); + test_read_wired_aliases_bad (TEST_IFCFG_DIR"/ifcfg-aliasem2", "System aliasem2"); } static void @@ -2159,7 +2162,7 @@ test_read_dns_options (void) const char *options6[] = { "inet6" }; guint32 i, num; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dns-options", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-dns-options", NULL, TYPE_ETHERNET, &unmanaged); g_assert_cmpstr (unmanaged, ==, NULL); @@ -2199,7 +2202,7 @@ test_clear_master (void) shvarFile *f; /* 1. load the bridge slave connection from disk */ - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-component", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bridge-component", NULL, TYPE_ETHERNET, &unmanaged); g_assert_cmpstr (unmanaged, ==, NULL); @@ -2211,8 +2214,8 @@ test_clear_master (void) /* 2. write the connection to a new file */ _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-System_test-bridge-component-a.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-System_test-bridge-component-a.cexpected", &testfile); /* 3. clear master and slave-type */ @@ -2228,9 +2231,9 @@ test_clear_master (void) /* 4. update the connection on disk */ _writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, testfile, - TEST_IFCFG_DIR "/network-scripts/ifcfg-System_test-bridge-component-b.cexpected"); + TEST_IFCFG_DIR"/ifcfg-System_test-bridge-component-b.cexpected"); keyfile = utils_get_keys_path (testfile); g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); @@ -2315,7 +2318,7 @@ test_write_dns_options (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -2336,7 +2339,7 @@ test_read_wifi_open (void) char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; const char *expected_ssid = "blahblah"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-open", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-open", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2399,7 +2402,7 @@ test_read_wifi_open_auto (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-open-auto", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-open-auto", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2424,7 +2427,7 @@ test_read_wifi_open_ssid_hex (void) GBytes *ssid; const char *expected_ssid = "blahblah"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-open-ssid-hex", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-open-ssid-hex", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2454,7 +2457,7 @@ test_read_wifi_open_ssid_hex_bad (void) GBytes *ssid; const char *expected_ssid = "0x626cxx"; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-open-ssid-bad-hex", NULL, TYPE_WIRELESS, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -2484,7 +2487,7 @@ test_read_wifi_open_ssid_quoted (void) GBytes *ssid; const char *expected_ssid = "foo\"bar\\"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-open-ssid-quoted", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-open-ssid-quoted", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2519,7 +2522,7 @@ test_read_wifi_wep (void) const char *expected_ssid = "blahblah"; NMWepKeyType key_type; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2593,7 +2596,7 @@ test_read_wifi_wep_adhoc (void) GBytes *ssid; const char *expected_ssid = "blahblah"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-adhoc", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-adhoc", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2660,7 +2663,7 @@ test_read_wifi_wep_passphrase (void) NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-passphrase", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-passphrase", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2697,7 +2700,7 @@ test_read_wifi_wep_40_ascii (void) NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-40-ascii", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-40-ascii", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2737,7 +2740,7 @@ test_read_wifi_wep_104_ascii (void) NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-104-ascii", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-104-ascii", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2776,7 +2779,7 @@ test_read_wifi_leap (void) NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-leap", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-leap", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2838,7 +2841,7 @@ test_ifcfg_no_trailing_newline (void) { shvarFile *sv; - sv = _svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk"); + sv = _svOpenFile (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk"); _svGetValue_check (sv, "LAST_ENTRY", "no-newline"); svCloseFile (sv); } @@ -2865,7 +2868,7 @@ test_read_wifi_wpa_psk (void) gboolean found_proto_wpa = FALSE; gboolean found_proto_rsn = FALSE; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -2974,7 +2977,7 @@ test_read_wifi_wpa_psk_2 (void) NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-2", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk-2", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -3005,7 +3008,7 @@ test_read_wifi_wpa_psk_unquoted (void) NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk-unquoted", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -3033,7 +3036,7 @@ test_read_wifi_wpa_psk_unquoted2 (void) { gs_unref_object NMConnection *connection = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk-unquoted2", NULL, TYPE_WIRELESS, NULL); } @@ -3046,7 +3049,7 @@ test_read_wifi_wpa_psk_adhoc (void) NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; - connection = _connection_from_file(TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-adhoc", + connection = _connection_from_file(TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk-adhoc", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -3098,7 +3101,7 @@ test_read_wifi_wpa_psk_hex (void) GBytes *ssid; const char *expected_ssid = "blahblah"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-hex", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-psk-hex", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -3133,9 +3136,9 @@ test_read_wifi_wpa_psk_hex (void) g_object_unref (connection); } -#define TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT TEST_IFCFG_DIR "/network-scripts/test_ca_cert.pem" -#define TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT TEST_IFCFG_DIR "/network-scripts/test1_key_and_cert.pem" -#define TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY TEST_IFCFG_DIR "/network-scripts/test1_key_and_cert.pem" +#define TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT TEST_IFCFG_DIR"/test_ca_cert.pem" +#define TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT TEST_IFCFG_DIR"/test1_key_and_cert.pem" +#define TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY TEST_IFCFG_DIR"/test1_key_and_cert.pem" static void test_read_wifi_wpa_eap_tls (void) @@ -3147,7 +3150,7 @@ test_read_wifi_wpa_eap_tls (void) char *unmanaged = NULL; const char *expected_privkey_password = "test1"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-eap-tls", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-eap-tls", NULL, TYPE_ETHERNET, &unmanaged); g_assert (!unmanaged); @@ -3205,7 +3208,7 @@ test_read_wifi_wpa_eap_ttls_tls (void) char *unmanaged = NULL; const char *expected_privkey_password = "test1"; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wpa-eap-ttls-tls", NULL, TYPE_WIRELESS, &unmanaged); g_assert (!unmanaged); @@ -3229,7 +3232,7 @@ test_read_wifi_wpa_eap_ttls_tls (void) /* CA Cert */ verify_cert_or_key (s_8021x, - TEST_IFCFG_DIR "/network-scripts/test_ca_cert.pem", + TEST_IFCFG_DIR"/test_ca_cert.pem", NULL, NM_SETTING_802_1X_CA_CERT); @@ -3268,7 +3271,7 @@ test_read_wifi_dynamic_wep_leap (void) NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-dynamic-wep-leap", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-dynamic-wep-leap", NULL, TYPE_WIRELESS, NULL); /* ===== WIRELESS SETTING ===== */ @@ -3317,7 +3320,7 @@ test_read_wifi_wep_eap_ttls_chap (void) NMSetting8021x *s_8021x; char *unmanaged = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-eap-ttls-chap", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-eap-ttls-chap", NULL, TYPE_WIRELESS, &unmanaged); g_assert (!unmanaged); @@ -3347,7 +3350,7 @@ test_read_wifi_wep_eap_ttls_chap (void) /* CA Cert */ verify_cert_or_key (s_8021x, - TEST_IFCFG_DIR "/network-scripts/test_ca_cert.pem", + TEST_IFCFG_DIR"/test_ca_cert.pem", NULL, NM_SETTING_802_1X_CA_CERT); @@ -3365,7 +3368,7 @@ test_read_wired_wake_on_lan (void) NMSettingConnection *s_con; NMSettingWired *s_wired; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-wake-on-lan", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-wake-on-lan", NULL, TYPE_WIRELESS, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -3394,7 +3397,7 @@ test_read_wired_auto_negotiate_off (void) NMSettingConnection *s_con; NMSettingWired *s_wired; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-wake-on-lan", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-wake-on-lan", NULL, TYPE_ETHERNET, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -3416,7 +3419,7 @@ test_read_wired_auto_negotiate_on (void) NMSettingConnection *s_con; NMSettingWired *s_wired; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-auto-negotiate-on", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-auto-negotiate-on", NULL, TYPE_ETHERNET, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -3438,7 +3441,7 @@ test_read_wired_unknown_ethtool_opt (void) NMSettingConnection *s_con; NMSettingWired *s_wired; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-unknown-ethtool-opt", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-unknown-ethtool-opt", NULL, TYPE_ETHERNET, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -3469,7 +3472,7 @@ test_read_wifi_hidden (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-hidden", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-hidden", NULL, TYPE_WIRELESS, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -3523,8 +3526,8 @@ test_write_wifi_hidden (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_WiFi_Hidden.cexpected", &testfile); f = _svOpenFile (testfile); @@ -3549,7 +3552,7 @@ test_read_wifi_mac_random (gconstpointer user_data) nmtst_test_data_unpack (user_data, &name, &value_p); value = GPOINTER_TO_INT (value_p); - path = g_strdup_printf (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-mac-random-%s", name); + path = g_strdup_printf (TEST_IFCFG_DIR"/ifcfg-test-wifi-mac-random-%s", name); connection = _connection_from_file (path, NULL, TYPE_WIRELESS, NULL); s_wifi = nm_connection_get_setting_wireless (connection); @@ -3608,8 +3611,8 @@ test_write_wifi_mac_random (gconstpointer user_data) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - nm_sprintf_buf (cexpected, TEST_IFCFG_DIR"/network-scripts/ifcfg-Test_Write_WiFi_MAC_%s.cexpected", name), + TEST_SCRATCH_DIR, + nm_sprintf_buf (cexpected, TEST_IFCFG_DIR"/ifcfg-Test_Write_WiFi_MAC_%s.cexpected", name), &testfile); f = _svOpenFile (testfile); @@ -3661,8 +3664,8 @@ test_write_wired_wake_on_lan (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Wired_Wake-on-LAN.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Wired_Wake-on-LAN.cexpected", &testfile); f = _svOpenFile (testfile); @@ -3697,8 +3700,8 @@ test_write_wired_auto_negotiate_off (void) NULL); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Wired_Auto-Negotiate.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Wired_Auto-Negotiate.cexpected", &testfile); f = _svOpenFile (testfile); @@ -3732,7 +3735,7 @@ test_write_wired_auto_negotiate_on (void) NULL); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); f = _svOpenFile (testfile); @@ -3756,7 +3759,7 @@ test_read_wifi_band_a (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-band-a", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-band-a", NULL, TYPE_WIRELESS, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -3811,8 +3814,8 @@ test_write_wifi_band_a (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_WiFi_Band_A.cexpected", &testfile); f = _svOpenFile (testfile); @@ -3829,7 +3832,7 @@ test_read_wifi_band_a_channel_mismatch (void) { gs_free_error GError *error = NULL; - _connection_from_file_fail (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-wifi-band-a-channel-mismatch", NULL, TYPE_WIRELESS, &error); g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); } @@ -3839,7 +3842,7 @@ test_read_wifi_band_bg_channel_mismatch (void) { gs_free_error GError *error = NULL; - _connection_from_file_fail (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-wifi-band-bg-channel-mismatch", NULL, TYPE_WIRELESS, &error); g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); } @@ -3854,7 +3857,7 @@ test_read_wired_qeth_static (void) char *unmanaged = NULL; const char * const *subchannels; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-qeth-static", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-qeth-static", NULL, TYPE_ETHERNET, &unmanaged); g_assert (!unmanaged); @@ -3903,7 +3906,7 @@ test_read_wired_ctc_static (void) char *unmanaged = NULL; const char * const *subchannels; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-ctc-static", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-ctc-static", NULL, TYPE_ETHERNET, &unmanaged); g_assert (unmanaged == NULL); @@ -3941,7 +3944,7 @@ test_read_wifi_wep_no_keys (void) NMSettingWirelessSecurity *s_wsec; NMWepKeyType key_type; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-no-keys", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-no-keys", NULL, TYPE_WIRELESS, NULL); /* ===== CONNECTION SETTING ===== */ @@ -3990,7 +3993,7 @@ test_read_permissions (void) guint32 num; const char *tmp; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-permissions", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-permissions", NULL, TYPE_ETHERNET, NULL); /* ===== CONNECTION SETTING ===== */ @@ -4029,7 +4032,7 @@ test_read_wifi_wep_agent_keys (void) NMWepKeyType key_type; NMSettingSecretFlags flags; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wep-agent-keys", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wifi-wep-agent-keys", NULL, TYPE_WIRELESS, NULL); /* Ensure the connection is still marked for wifi security even though @@ -4180,7 +4183,7 @@ test_write_wired_static (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); route6file = utils_get_route6_path (testfile); @@ -4320,7 +4323,7 @@ test_write_wired_static_with_generic (void) nmtst_assert_connection_verifies (connection); _writer_new_connection_FIXME (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); route6file = utils_get_route6_path (testfile); @@ -4405,7 +4408,7 @@ test_write_wired_dhcp (void) NULL); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4420,11 +4423,11 @@ test_write_wired_dhcp_plus_ip (void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4442,7 +4445,7 @@ test_read_write_wired_dhcp_send_hostname (void) NMSettingIPConfig *s_ip6; const char * dhcp_hostname = "kamil-patka"; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-send-hostname", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-dhcp-send-hostname", NULL, TYPE_ETHERNET, NULL); /* Check dhcp-hostname and dhcp-send-hostname */ @@ -4460,7 +4463,7 @@ test_read_write_wired_dhcp_send_hostname (void) g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4483,7 +4486,7 @@ test_read_wired_dhcpv6_hostname_fallback (void) gs_unref_object NMConnection *connection = NULL; NMSettingIPConfig *s_ip6; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-wired-dhcpv6-hostname-fallback", NULL, TYPE_ETHERNET, NULL); s_ip6 = nm_connection_get_setting_ip6_config (connection); @@ -4552,7 +4555,7 @@ test_write_wired_static_ip6_only (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4591,7 +4594,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL"); + id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ?: "NULL"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), @@ -4635,7 +4638,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4676,7 +4679,7 @@ test_read_write_static_routes_legacy (void) NMSettingIPConfig *s_ip4; const char *tmp; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-static-routes-legacy", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-static-routes-legacy", NULL, TYPE_ETHERNET, NULL); /* ===== CONNECTION SETTING ===== */ @@ -4710,7 +4713,7 @@ test_read_write_static_routes_legacy (void) */ _writer_new_connec_exp (connection, TEST_SCRATCH_DIR_TMP, - TEST_IFCFG_DIR "/network-scripts/ifcfg-test-static-routes-legacy.cexpected", + TEST_IFCFG_DIR"/ifcfg-test-static-routes-legacy.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4812,9 +4815,9 @@ test_write_wired_static_routes (void) nmtst_assert_connection_verifies (connection); _writer_new_connection_reread (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile, - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected", + TEST_IFCFG_DIR"/ifcfg-Test_Write_Wired_Static_Routes.cexpected", &reread, &reread_same); /* ifcfg does not support setting onlink=0. It gets lost during write+re-read. @@ -4907,7 +4910,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -4981,7 +4984,7 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* CA cert */ success = nm_setting_802_1x_set_ca_cert (s_8021x, - TEST_IFCFG_DIR "/network-scripts/test_ca_cert.pem", + TEST_IFCFG_DIR"/test_ca_cert.pem", scheme, &format, &error); @@ -4992,7 +4995,7 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* Client cert */ format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; success = nm_setting_802_1x_set_client_cert (s_8021x, - TEST_IFCFG_DIR "/network-scripts/test1_key_and_cert.pem", + TEST_IFCFG_DIR"/test1_key_and_cert.pem", scheme, &format, &error); @@ -5003,7 +5006,7 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* Private key */ format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; success = nm_setting_802_1x_set_private_key (s_8021x, - TEST_IFCFG_DIR "/network-scripts/test1_key_and_cert.pem", + TEST_IFCFG_DIR"/test1_key_and_cert.pem", "test1", scheme, &format, @@ -5018,7 +5021,7 @@ test_write_wired_8021x_tls (gconstpointer test_data) nmtst_assert_connection_verifies (connection); _writer_new_connection_FIXME (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5080,8 +5083,6 @@ test_write_wired_8021x_tls (gconstpointer test_data) g_free (tmp); } -#define TEST_SCRATCH_ALIAS_BASE TEST_SCRATCH_DIR "/network-scripts/ifcfg-alias0" - static void test_write_wired_aliases (void) { @@ -5157,7 +5158,7 @@ test_write_wired_aliases (void) g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); _writer_new_connection_FIXME (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); /* Re-check the alias files */ @@ -5259,7 +5260,7 @@ test_write_gateway (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); f = _svOpenFile (testfile); @@ -5279,7 +5280,6 @@ test_write_gateway (void) nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); } - static void test_write_wifi_open (void) { @@ -5343,7 +5343,7 @@ test_write_wifi_open (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5412,7 +5412,7 @@ test_write_wifi_open_hex_ssid (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5494,7 +5494,7 @@ test_write_wifi_wep (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5587,7 +5587,7 @@ test_write_wifi_wep_adhoc (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5672,7 +5672,7 @@ test_write_wifi_wep_passphrase (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5760,7 +5760,7 @@ test_write_wifi_wep_40_ascii (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5848,8 +5848,8 @@ test_write_wifi_wep_104_ascii (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -5933,8 +5933,8 @@ test_write_wifi_leap (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Wifi_LEAP.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6016,7 +6016,7 @@ test_write_wifi_leap_secret_flags (gconstpointer data) nmtst_assert_connection_verifies (connection); _writer_new_connection_FIXME (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6124,7 +6124,7 @@ test_write_wifi_wpa_psk (gconstpointer test_data) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6220,7 +6220,7 @@ test_write_wifi_wpa_psk_adhoc (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6338,7 +6338,7 @@ test_write_wifi_wpa_eap_tls (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6465,7 +6465,7 @@ test_write_wifi_wpa_eap_ttls_tls (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6569,7 +6569,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6657,7 +6657,7 @@ test_write_wifi_wpa_then_open (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6673,9 +6673,9 @@ test_write_wifi_wpa_then_open (void) /* Write it back out */ _writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, testfile, - TEST_IFCFG_DIR "/network-scripts/ifcfg-random_wifi_connection.cexpected"); + TEST_IFCFG_DIR"/ifcfg-random_wifi_connection.cexpected"); keyfile = utils_get_keys_path (testfile); g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); @@ -6771,7 +6771,7 @@ test_write_wifi_wpa_then_wep_with_perms (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6793,9 +6793,9 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Write it back out */ _writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, testfile, - TEST_IFCFG_DIR "/network-scripts/ifcfg-random_wifi_connection_2.cexpected"); + TEST_IFCFG_DIR"/ifcfg-random_wifi_connection_2.cexpected"); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6883,7 +6883,7 @@ test_write_wifi_dynamic_wep_leap (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6963,7 +6963,7 @@ test_write_wired_qeth_dhcp (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7025,7 +7025,7 @@ test_write_wired_ctc_dhcp (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); /* Ensure the CTCPROT item gets written out as its own option */ @@ -7095,8 +7095,8 @@ test_write_permissions (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Permissions.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Permissions.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7170,7 +7170,7 @@ test_write_wifi_wep_agent_keys (void) nmtst_assert_connection_verifies (connection); _writer_new_connection_FIXME (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -7241,7 +7241,7 @@ test_write_wired_pppoe (void) nmtst_assert_connection_verifies (connection); _writer_new_connection_fail (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, NULL); g_object_unref (connection); @@ -7293,7 +7293,7 @@ test_write_vpn (void) nmtst_assert_connection_verifies (connection); _writer_new_connection_fail (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, NULL); g_object_unref (connection); @@ -7366,7 +7366,7 @@ test_write_mobile_broadband (gconstpointer data) nmtst_assert_connection_verifies (connection); _writer_new_connection_fail (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, NULL); g_object_unref (connection); @@ -7382,7 +7382,7 @@ test_read_bridge_main (void) const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-main", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bridge-main", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "br0"); @@ -7480,7 +7480,7 @@ test_write_bridge_main (void) nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BRIDGE, NULL); @@ -7495,7 +7495,7 @@ test_read_bridge_component (void) NMSettingConnection *s_con; NMSettingBridgePort *s_port; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-component", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bridge-component", NULL, TYPE_ETHERNET, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -7560,8 +7560,8 @@ test_write_bridge_component (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Bridge_Component.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7575,7 +7575,7 @@ test_read_bridge_missing_stp (void) NMConnection *connection; NMSettingBridge *s_bridge; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bridge-missing-stp", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bridge-missing-stp", NULL, TYPE_BRIDGE, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "br0"); @@ -7589,7 +7589,7 @@ test_read_bridge_missing_stp (void) g_object_unref (connection); } -#define TEST_IFCFG_VLAN_INTERFACE TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-interface" +#define TEST_IFCFG_VLAN_INTERFACE TEST_IFCFG_DIR"/ifcfg-test-vlan-interface" static void test_read_vlan_interface (void) @@ -7640,7 +7640,7 @@ test_read_vlan_interface (void) g_object_unref (connection); } -#define TEST_IFCFG_VLAN_ONLY_VLANID TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-only-vlanid" +#define TEST_IFCFG_VLAN_ONLY_VLANID TEST_IFCFG_DIR"/ifcfg-test-vlan-only-vlanid" static void test_read_vlan_only_vlan_id (void) @@ -7668,7 +7668,7 @@ test_read_vlan_only_device (void) NMConnection *connection; NMSettingVlan *s_vlan; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-vlan-only-device", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-only-device", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "eth0.9"); @@ -7688,7 +7688,7 @@ test_read_vlan_physdev (void) NMConnection *connection; NMSettingVlan *s_vlan; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-physdev", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-physdev", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan0.3"); @@ -7709,7 +7709,7 @@ test_read_vlan_reorder_hdr_1 (void) NMSettingVlan *s_vlan; NMTST_EXPECT_NM_WARN ("*REORDER_HDR key is deprecated, use VLAN_FLAGS*"); - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-reorder-hdr-1", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-reorder-hdr-1", NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); @@ -7732,7 +7732,7 @@ test_read_vlan_reorder_hdr_2 (void) NMConnection *connection; NMSettingVlan *s_vlan; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-reorder-hdr-2", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-reorder-hdr-2", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan0.3"); @@ -7754,7 +7754,7 @@ test_read_vlan_flags_1 (void) NMConnection *connection; NMSettingVlan *s_vlan; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-flags-1", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-flags-1", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "super-vlan"); @@ -7777,7 +7777,7 @@ test_read_vlan_flags_2 (void) NMConnection *connection; NMSettingVlan *s_vlan; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-flags-2", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-flags-2", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "super-vlan"); @@ -7805,8 +7805,8 @@ test_write_vlan (void) NULL, TYPE_VLAN, NULL); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Vlan_test-vlan-interface.cexpected", &testfile); } @@ -7817,11 +7817,11 @@ test_write_vlan_flags (void) gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-flags-2", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-vlan-flags-2", NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7840,7 +7840,7 @@ test_write_vlan_only_vlanid (void) NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7886,8 +7886,8 @@ test_write_vlan_reorder_hdr (void) NULL); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_VLAN_reorder_hdr.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_VLAN_reorder_hdr.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7942,7 +7942,7 @@ test_write_ethernet_missing_ipv6 (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -7955,7 +7955,7 @@ test_read_ibft_ignored (void) { gs_free_error GError *error = NULL; - _connection_from_file_fail (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-ibft", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-ibft", NULL, TYPE_ETHERNET, &error); g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); } @@ -7966,7 +7966,7 @@ test_read_bond_main (void) NMConnection *connection; NMSettingBond *s_bond; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-main", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bond-main", NULL, TYPE_ETHERNET,NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "bond0"); @@ -7987,7 +7987,7 @@ test_read_bond_eth_type (void) NMConnection *connection; NMSettingBond *s_bond; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-eth-type", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bond-eth-type", NULL, TYPE_ETHERNET,NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "bond0"); @@ -8071,8 +8071,8 @@ test_write_bond_main (void) nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Bond_Main.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BOND, NULL); @@ -8086,7 +8086,7 @@ test_read_bond_slave (void) NMConnection *connection; NMSettingConnection *s_con; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-slave", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bond-slave", NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); @@ -8138,7 +8138,7 @@ test_write_bond_slave (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -8156,7 +8156,7 @@ test_read_infiniband (void) char expected_mac_address[INFINIBAND_ALEN] = { 0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22 }; const char *transport_mode; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-infiniband", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-infiniband", NULL, TYPE_INFINIBAND, &unmanaged); g_assert (!unmanaged); @@ -8242,7 +8242,7 @@ test_write_infiniband (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_INFINIBAND, NULL); @@ -8256,7 +8256,7 @@ test_read_bond_slave_ib (void) gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-slave-ib", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bond-slave-ib", NULL, NULL, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -8304,7 +8304,7 @@ test_write_bond_slave_ib (void) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); reread = _connection_from_file (testfile, NULL, NULL, NULL); @@ -8319,7 +8319,7 @@ test_read_bond_opts_mode_numeric (void) NMSettingConnection *s_con; NMSettingBond *s_bond; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-mode-numeric", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-bond-mode-numeric", NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "bond0"); @@ -8352,7 +8352,7 @@ test_read_dcb_basic (void) guint expected_traffic_classes[8] = { 7, 6, 5, 4, 3, 2, 1, 0 }; gboolean expected_pfcs[8] = { TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE }; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-dcb", NULL, TYPE_ETHERNET, NULL); s_dcb = nm_connection_get_setting_dcb (connection); @@ -8466,8 +8466,8 @@ test_write_dcb_basic (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts//ifcfg-dcb-test.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"//ifcfg-dcb-test.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); @@ -8481,7 +8481,7 @@ test_read_dcb_default_app_priorities (void) gs_unref_object NMConnection *connection = NULL; NMSettingDcb *s_dcb; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-default-app-priorities", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-dcb-default-app-priorities", NULL, TYPE_ETHERNET, NULL); s_dcb = nm_connection_get_setting_dcb (connection); @@ -8503,7 +8503,7 @@ test_read_dcb_bad_booleans (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*invalid DCB_PG_STRICT value*not all 0s and 1s*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-bad-booleans", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-bad-booleans", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8517,7 +8517,7 @@ test_read_dcb_short_booleans (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*DCB_PG_STRICT value*8 characters*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-short-booleans", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-short-booleans", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8531,7 +8531,7 @@ test_read_dcb_bad_uints (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*invalid DCB_PG_UP2TC value*not 0 - 7*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-bad-uints", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-bad-uints", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8545,7 +8545,7 @@ test_read_dcb_short_uints (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*DCB_PG_UP2TC value*8 characters*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-short-uints", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-short-uints", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8559,7 +8559,7 @@ test_read_dcb_bad_percent (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*invalid DCB_PG_PCT percentage value*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-bad-percent", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-bad-percent", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8573,7 +8573,7 @@ test_read_dcb_short_percent (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*invalid DCB_PG_PCT percentage list value*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-short-percent", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-short-percent", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8587,7 +8587,7 @@ test_read_dcb_pgpct_not_100 (void) gs_free_error GError *error = NULL; NMTST_EXPECT_NM_WARN ("*DCB_PG_PCT percentages do not equal 100*"); - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-pgpct-not-100", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-dcb-pgpct-not-100", NULL, TYPE_ETHERNET, &error); g_test_assert_expected_messages (); @@ -8603,7 +8603,7 @@ test_read_fcoe_mode (gconstpointer user_data) const char *expected_mode = user_data; NMSettingDcb *s_dcb; - file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-fcoe-%s", expected_mode); + file = g_strdup_printf (TEST_IFCFG_DIR"/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file (file, NULL, TYPE_ETHERNET, NULL); s_dcb = nm_connection_get_setting_dcb (connection); @@ -8663,7 +8663,7 @@ test_write_fcoe_mode (gconstpointer user_data) nmtst_assert_connection_verifies (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); ifcfg = _svOpenFile (testfile); @@ -8784,7 +8784,7 @@ test_write_team_master (void) nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile); f = _svOpenFile (testfile); @@ -8858,8 +8858,8 @@ test_write_team_port (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Team_Port.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Team_Port.cexpected", &testfile); f = _svOpenFile (testfile); @@ -8915,8 +8915,8 @@ test_write_team_infiniband_port (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Team_Infiniband_Port.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Team_Infiniband_Port.cexpected", &testfile); f = _svOpenFile (testfile); @@ -8938,7 +8938,7 @@ test_read_team_port_empty_config (void) NMConnection *connection; NMSettingConnection *s_con; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port-empty-config", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-team-port-empty-config", NULL, TYPE_ETHERNET, NULL); s_con = nm_connection_get_setting_connection (connection); @@ -9003,9 +9003,9 @@ test_team_reread_slave (void) nmtst_assert_connection_equals (connection_1, FALSE, connection_2, FALSE); _writer_new_connection_reread ((nmtst_get_rand_int () % 2) ? connection_1 : connection_2, - TEST_SCRATCH_DIR "/network-scripts/", + TEST_SCRATCH_DIR, &testfile, - TEST_IFCFG_DIR "/network-scripts/ifcfg-team-slave-enp31s0f1-142.cexpected", + TEST_IFCFG_DIR"/ifcfg-team-slave-enp31s0f1-142.cexpected", &reread, &reread_same); _assert_reread_same ((nmtst_get_rand_int () % 2) ? connection_1 : connection_2, reread); @@ -9026,7 +9026,7 @@ test_read_proxy_basic (void) /* Test basic proxy configuration */ - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-read-proxy-basic", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-read-proxy-basic", NULL, TYPE_ETHERNET, NULL); /* ===== Proxy setting ===== */ @@ -9078,8 +9078,8 @@ test_write_proxy_basic (void) nmtst_assert_connection_verifies (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-Test_Write_Proxy_Basic.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-Test_Write_Proxy_Basic.cexpected", &testfile); f = _svOpenFile (testfile); @@ -9474,7 +9474,7 @@ test_write_unknown (gconstpointer test_data) static void test_read_vlan_trailing_spaces (void) { - const char *testfile = TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-trailing-spaces"; + const char *testfile = TEST_IFCFG_DIR"/ifcfg-test-vlan-trailing-spaces"; NMConnection *connection; gboolean success; GError *error = NULL; @@ -9512,7 +9512,7 @@ test_sit_read_ignore (void) { gs_free_error GError *error = NULL; - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-sit-ignore", + _connection_from_file_fail (TEST_IFCFG_DIR"/ifcfg-test-sit-ignore", NULL, TYPE_ETHERNET, &error); nmtst_assert_error (error, 0, 0, "*Ignoring unsupported connection due to IPV6TUNNELIPV4*"); } @@ -9641,7 +9641,7 @@ test_tc_read (void) NMTCTfilter *filter; char *str; - connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-tc", + connection = _connection_from_file (TEST_IFCFG_DIR"/ifcfg-test-tc", NULL, TYPE_ETHERNET,NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "eth0"); @@ -9742,8 +9742,8 @@ test_tc_write (void) nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connec_exp (connection, - TEST_SCRATCH_DIR "/network-scripts/", - TEST_IFCFG_DIR "/network-scripts/ifcfg-test-tc-write.cexpected", + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR"/ifcfg-test-tc-write.cexpected", &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BOND, NULL); @@ -9755,8 +9755,8 @@ test_tc_write (void) #define TPATH "/settings/plugins/ifcfg-rh/" -#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted" -#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-hex" +#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/ifcfg-test-wifi-open-ssid-long-quoted" +#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR"/ifcfg-test-wifi-open-ssid-long-hex" #define DEFAULT_HEX_PSK "7d308b11df1b4243b0f78e5f3fc68cdbb9a264ed0edf4c188edf329ff5b467f0" @@ -9771,10 +9771,10 @@ int main (int argc, char **argv) g_test_add_func (TPATH "svUnescape", test_svUnescape); - g_test_add_data_func (TPATH "write-unknown/1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-1", test_write_unknown); - g_test_add_data_func (TPATH "write-unknown/2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-2", test_write_unknown); - g_test_add_data_func (TPATH "write-unknown/3", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-3", test_write_unknown); - g_test_add_data_func (TPATH "write-unknown/4", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-4", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/1", TEST_IFCFG_DIR"/ifcfg-test-write-unknown-1", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/2", TEST_IFCFG_DIR"/ifcfg-test-write-unknown-2", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/3", TEST_IFCFG_DIR"/ifcfg-test-write-unknown-3", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/4", TEST_IFCFG_DIR"/ifcfg-test-write-unknown-4", test_write_unknown); g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); @@ -9794,8 +9794,8 @@ int main (int argc, char **argv) g_test_add_func (TPATH "read-dns-options", test_read_dns_options); g_test_add_func (TPATH "clear-master", test_clear_master); - nmtst_add_test_func (TPATH "read-static", test_read_wired_static, TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static", "System test-wired-static", GINT_TO_POINTER (TRUE)); - nmtst_add_test_func (TPATH "read-static-bootproto", test_read_wired_static, TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static-bootproto", "System test-wired-static-bootproto", GINT_TO_POINTER (FALSE)); + nmtst_add_test_func (TPATH "read-static", test_read_wired_static, TEST_IFCFG_DIR"/ifcfg-test-wired-static", "System test-wired-static", GINT_TO_POINTER (TRUE)); + nmtst_add_test_func (TPATH "read-static-bootproto", test_read_wired_static, TEST_IFCFG_DIR"/ifcfg-test-wired-static-bootproto", "System test-wired-static-bootproto", GINT_TO_POINTER (FALSE)); g_test_add_func (TPATH "read-netmask-1", test_read_netmask_1); @@ -9813,17 +9813,17 @@ int main (int argc, char **argv) g_test_add_func (TPATH "routes/read-static", test_read_wired_static_routes); g_test_add_func (TPATH "routes/read-static-legacy", test_read_wired_static_routes_legacy); - nmtst_add_test_func (TPATH "wired/read/manual/1", test_read_wired_ipv4_manual, TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-ipv4-manual-1", "System test-wired-ipv4-manual-1"); - nmtst_add_test_func (TPATH "wired/read/manual/2", test_read_wired_ipv4_manual, TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-ipv4-manual-2", "System test-wired-ipv4-manual-2"); - nmtst_add_test_func (TPATH "wired/read/manual/3", test_read_wired_ipv4_manual, TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-ipv4-manual-3", "System test-wired-ipv4-manual-3"); - nmtst_add_test_func (TPATH "wired/read/manual/4", test_read_wired_ipv4_manual, TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-ipv4-manual-4", "System test-wired-ipv4-manual-4"); + nmtst_add_test_func (TPATH "wired/read/manual/1", test_read_wired_ipv4_manual, TEST_IFCFG_DIR"/ifcfg-test-wired-ipv4-manual-1", "System test-wired-ipv4-manual-1"); + nmtst_add_test_func (TPATH "wired/read/manual/2", test_read_wired_ipv4_manual, TEST_IFCFG_DIR"/ifcfg-test-wired-ipv4-manual-2", "System test-wired-ipv4-manual-2"); + nmtst_add_test_func (TPATH "wired/read/manual/3", test_read_wired_ipv4_manual, TEST_IFCFG_DIR"/ifcfg-test-wired-ipv4-manual-3", "System test-wired-ipv4-manual-3"); + nmtst_add_test_func (TPATH "wired/read/manual/4", test_read_wired_ipv4_manual, TEST_IFCFG_DIR"/ifcfg-test-wired-ipv4-manual-4", "System test-wired-ipv4-manual-4"); g_test_add_func (TPATH "user/1", test_user_1); g_test_add_func (TPATH "wired/ipv6-manual", test_read_wired_ipv6_manual); - nmtst_add_test_func (TPATH "wired-ipv6-only/0", test_read_wired_ipv6_only, TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-ipv6-only", "System test-wired-ipv6-only"); - nmtst_add_test_func (TPATH "wired-ipv6-only/1", test_read_wired_ipv6_only, TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-ipv6-only-1", "System test-wired-ipv6-only-1"); + nmtst_add_test_func (TPATH "wired-ipv6-only/0", test_read_wired_ipv6_only, TEST_IFCFG_DIR"/ifcfg-test-wired-ipv6-only", "System test-wired-ipv6-only"); + nmtst_add_test_func (TPATH "wired-ipv6-only/1", test_read_wired_ipv6_only, TEST_IFCFG_DIR"/ifcfg-test-wired-ipv6-only-1", "System test-wired-ipv6-only-1"); g_test_add_func (TPATH "wired/dhcpv6-only", test_read_wired_dhcp6_only); g_test_add_func (TPATH "wired/autoip", test_read_wired_autoip); @@ -9831,8 +9831,8 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wired/no-ip", test_read_noip); g_test_add_func (TPATH "802-1x/peap/mschapv2", test_read_wired_8021x_peap_mschapv2); - nmtst_add_test_func (TPATH "test-wired-8021x-tls/agent", test_read_wired_8021x_tls_secret_flags, TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-8021x-tls-agent", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED)); - nmtst_add_test_func (TPATH "test-wired-8021x-tls/always", test_read_wired_8021x_tls_secret_flags, TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-8021x-tls-always", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED)); + nmtst_add_test_func (TPATH "test-wired-8021x-tls/agent", test_read_wired_8021x_tls_secret_flags, TEST_IFCFG_DIR"/ifcfg-test-wired-8021x-tls-agent", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED)); + nmtst_add_test_func (TPATH "test-wired-8021x-tls/always", test_read_wired_8021x_tls_secret_flags, TEST_IFCFG_DIR"/ifcfg-test-wired-8021x-tls-always", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED)); g_test_add_func (TPATH "802-1x/subj-matches", test_read_write_802_1X_subj_matches); g_test_add_func (TPATH "802-1x/ttls-eapgtc", test_read_802_1x_ttls_eapgtc); @@ -9855,8 +9855,8 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wifi/read/wep/104-ascii", test_read_wifi_wep_104_ascii); g_test_add_func (TPATH "wifi/read/leap", test_read_wifi_leap); - nmtst_add_test_func (TPATH "wifi-leap-secret-flags/agent", test_read_wifi_leap_secret_flags, TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-leap-agent", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED)); - nmtst_add_test_func (TPATH "wifi-leap-secret-flags/ask", test_read_wifi_leap_secret_flags, TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-leap-always-ask", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED)); + nmtst_add_test_func (TPATH "wifi-leap-secret-flags/agent", test_read_wifi_leap_secret_flags, TEST_IFCFG_DIR"/ifcfg-test-wifi-leap-agent", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED)); + nmtst_add_test_func (TPATH "wifi-leap-secret-flags/ask", test_read_wifi_leap_secret_flags, TEST_IFCFG_DIR"/ifcfg-test-wifi-leap-always-ask", GINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED)); g_test_add_func (TPATH "wifi/read/wpa-psk", test_read_wifi_wpa_psk); g_test_add_func (TPATH "wifi/read/wpa-psk/2", test_read_wifi_wpa_psk_2); @@ -10005,12 +10005,12 @@ int main (int argc, char **argv) g_test_add_func (TPATH "bridge/write-component", test_write_bridge_component); g_test_add_func (TPATH "bridge/read-missing-stp", test_read_bridge_missing_stp); - g_test_add_data_func (TPATH "team/read-master-1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master-1", test_read_team_master); - g_test_add_data_func (TPATH "team/read-master-2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master-2", test_read_team_master); - g_test_add_data_func (TPATH "team/read-master-invalid", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master-invalid", test_read_team_master_invalid); + g_test_add_data_func (TPATH "team/read-master-1", TEST_IFCFG_DIR"/ifcfg-test-team-master-1", test_read_team_master); + g_test_add_data_func (TPATH "team/read-master-2", TEST_IFCFG_DIR"/ifcfg-test-team-master-2", test_read_team_master); + g_test_add_data_func (TPATH "team/read-master-invalid", TEST_IFCFG_DIR"/ifcfg-test-team-master-invalid", test_read_team_master_invalid); g_test_add_func (TPATH "team/write-master", test_write_team_master); - g_test_add_data_func (TPATH "team/read-port-1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port-1", test_read_team_port); - g_test_add_data_func (TPATH "team/read-port-2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port-2", test_read_team_port); + g_test_add_data_func (TPATH "team/read-port-1", TEST_IFCFG_DIR"/ifcfg-test-team-port-1", test_read_team_port); + g_test_add_data_func (TPATH "team/read-port-2", TEST_IFCFG_DIR"/ifcfg-test-team-port-2", test_read_team_port); g_test_add_func (TPATH "team/write-port", test_write_team_port); g_test_add_func (TPATH "team/write-infiniband-port", test_write_team_infiniband_port); g_test_add_func (TPATH "team/read-port-empty-config", test_read_team_port_empty_config); diff --git a/src/settings/plugins/ifupdown/meson.build b/src/settings/plugins/ifupdown/meson.build index 87b5bea2..fd028f4d 100644 --- a/src/settings/plugins/ifupdown/meson.build +++ b/src/settings/plugins/ifupdown/meson.build @@ -31,7 +31,7 @@ libnm_settings_plugin_ifupdown = shared_module( link_args: ldflags_linker_script_settings, link_depends: linker_script_settings, install: true, - install_dir: nm_pkglibdir + install_dir: nm_plugindir ) core_plugins += libnm_settings_plugin_ifupdown diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c index 014998a6..94a65ecb 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c @@ -126,7 +126,6 @@ _recursive_ifparser (const char *eni_file, int quiet) if (!quiet) nm_log_info (LOGD_SETTINGS, " interface-parser: parsing file %s\n", eni_file); - while (!feof(inp)) { char *token[128]; /* 255 chars can only be split into 127 tokens */ diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h index bf9c4465..7e6c8e34 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h +++ b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h @@ -20,7 +20,6 @@ * (C) Copyright 2004 Tom Parker */ - #ifndef _INTERFACE_PARSER_H #define _INTERFACE_PARSER_H diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c index 99879c92..884c6591 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -37,7 +37,6 @@ #include "nms-ifupdown-plugin.h" #include "nms-ifupdown-parser.h" - static const gchar* _ifupdownplugin_guess_connection_type (if_block *block) { @@ -63,7 +62,6 @@ _ifupdownplugin_guess_connection_type (if_block *block) return ret_type; } - struct _Mapping { const gchar *domain; const gpointer target; @@ -340,7 +338,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, } g_object_set(wireless_security_setting, - newkey, typed_property_value ? typed_property_value : property_value, + newkey, typed_property_value ?: property_value, NULL); security = TRUE; @@ -388,7 +386,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, } g_object_set(wireless_security_setting, - newkey, typed_property_value ? typed_property_value : property_value, + newkey, typed_property_value ?: property_value, NULL); security = TRUE; @@ -401,7 +399,6 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, curr = curr->next; } - if (security) nm_connection_add_setting (connection, NM_SETTING (wireless_security_setting)); } diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index bfad9d15..8bd72d02 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -50,9 +50,6 @@ #define ENI_INTERFACES_FILE "/etc/network/interfaces" -#define IFUPDOWN_PLUGIN_NAME "ifupdown" -#define IFUPDOWN_PLUGIN_INFO "(C) 2008 Canonical Ltd. To report bugs please use the NetworkManager mailing list." - #define IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT TRUE /* #define ALWAYS_UNMANAGE TRUE */ @@ -303,28 +300,6 @@ get_unmanaged_specs (NMSettingsPlugin *config) /*****************************************************************************/ static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case NM_SETTINGS_PLUGIN_PROP_NAME: - g_value_set_string (value, IFUPDOWN_PLUGIN_NAME); - break; - case NM_SETTINGS_PLUGIN_PROP_INFO: - g_value_set_string (value, IFUPDOWN_PLUGIN_INFO); - break; - case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: - g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_NONE); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - -static void _udev_device_unref (gpointer ptr) { udev_device_unref (ptr); @@ -513,19 +488,6 @@ settings_plugin_ifupdown_class_init (SettingsPluginIfupdownClass *req_class) GObjectClass *object_class = G_OBJECT_CLASS (req_class); object_class->dispose = dispose; - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_NAME, - NM_SETTINGS_PLUGIN_NAME); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_INFO, - NM_SETTINGS_PLUGIN_INFO); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, - NM_SETTINGS_PLUGIN_CAPABILITIES); } static void diff --git a/src/settings/plugins/ifupdown/tests/meson.build b/src/settings/plugins/ifupdown/tests/meson.build index 7f210034..ee3b6a34 100644 --- a/src/settings/plugins/ifupdown/tests/meson.build +++ b/src/settings/plugins/ifupdown/tests/meson.build @@ -1,12 +1,10 @@ test_unit = 'test-ifupdown' -cflags = '-DTEST_ENI_DIR="@0@"'.format(meson.current_source_dir()) - exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: cflags, + c_args: nm_build_cflags, link_with: libnms_ifupdown_core ) diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index 56515438..18bad65e 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -29,6 +29,10 @@ #include "nm-test-utils-core.h" +#define TEST_DIR NM_BUILD_SRCDIR"/src/settings/plugins/ifupdown/tests" + +/*****************************************************************************/ + typedef struct { char *key; char *data; @@ -659,45 +663,45 @@ main (int argc, char **argv) if (0) dump_blocks (); - g_test_add_data_func ("/ifupdate/ignore_line_before_first_block", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/ignore_line_before_first_block", TEST_DIR, (GTestDataFunc) test1_ignore_line_before_first_block); - g_test_add_data_func ("/ifupdate/wrapped_line", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/wrapped_line", TEST_DIR, (GTestDataFunc) test2_wrapped_line); - g_test_add_data_func ("/ifupdate/wrapped_multiline_multiarg", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/wrapped_multiline_multiarg", TEST_DIR, (GTestDataFunc) test3_wrapped_multiline_multiarg); - g_test_add_data_func ("/ifupdate/allow_auto_is_auto", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/allow_auto_is_auto", TEST_DIR, (GTestDataFunc) test4_allow_auto_is_auto); - g_test_add_data_func ("/ifupdate/allow_auto_multiarg", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/allow_auto_multiarg", TEST_DIR, (GTestDataFunc) test5_allow_auto_multiarg); - g_test_add_data_func ("/ifupdate/mixed_whitespace", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/mixed_whitespace", TEST_DIR, (GTestDataFunc) test6_mixed_whitespace); - g_test_add_data_func ("/ifupdate/long_line", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/long_line", TEST_DIR, (GTestDataFunc) test7_long_line); - g_test_add_data_func ("/ifupdate/long_line_wrapped", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/long_line_wrapped", TEST_DIR, (GTestDataFunc) test8_long_line_wrapped); - g_test_add_data_func ("/ifupdate/wrapped_lines_in_block", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/wrapped_lines_in_block", TEST_DIR, (GTestDataFunc) test9_wrapped_lines_in_block); - g_test_add_data_func ("/ifupdate/complex_wrap", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/complex_wrap", TEST_DIR, (GTestDataFunc) test11_complex_wrap); - g_test_add_data_func ("/ifupdate/complex_wrap_split_word", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/complex_wrap_split_word", TEST_DIR, (GTestDataFunc) test12_complex_wrap_split_word); - g_test_add_data_func ("/ifupdate/more_mixed_whitespace", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/more_mixed_whitespace", TEST_DIR, (GTestDataFunc) test13_more_mixed_whitespace); - g_test_add_data_func ("/ifupdate/mixed_whitespace_block_start", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/mixed_whitespace_block_start", TEST_DIR, (GTestDataFunc) test14_mixed_whitespace_block_start); - g_test_add_data_func ("/ifupdate/trailing_space", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/trailing_space", TEST_DIR, (GTestDataFunc) test15_trailing_space); - g_test_add_data_func ("/ifupdate/missing_newline", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/missing_newline", TEST_DIR, (GTestDataFunc) test16_missing_newline); - g_test_add_data_func ("/ifupdate/read_static_ipv4", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/read_static_ipv4", TEST_DIR, (GTestDataFunc) test17_read_static_ipv4); - g_test_add_data_func ("/ifupdate/read_static_ipv6", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/read_static_ipv6", TEST_DIR, (GTestDataFunc) test18_read_static_ipv6); - g_test_add_data_func ("/ifupdate/read_static_ipv4_plen", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/read_static_ipv4_plen", TEST_DIR, (GTestDataFunc) test19_read_static_ipv4_plen); - g_test_add_data_func ("/ifupdate/source_stanza", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/source_stanza", TEST_DIR, (GTestDataFunc) test20_source_stanza); - g_test_add_data_func ("/ifupdate/source_dir_stanza", TEST_ENI_DIR, + g_test_add_data_func ("/ifupdate/source_dir_stanza", TEST_DIR, (GTestDataFunc) test21_source_dir_stanza); return g_test_run (); diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index df2c05b7..3723db94 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -562,28 +562,6 @@ get_unmanaged_specs (NMSettingsPlugin *config) /*****************************************************************************/ static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case NM_SETTINGS_PLUGIN_PROP_NAME: - g_value_set_string (value, NMS_KEYFILE_PLUGIN_NAME); - break; - case NM_SETTINGS_PLUGIN_PROP_INFO: - g_value_set_string (value, NMS_KEYFILE_PLUGIN_INFO); - break; - case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: - g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - -static void nms_keyfile_plugin_init (NMSKeyfilePlugin *plugin) { NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (plugin); @@ -644,19 +622,6 @@ nms_keyfile_plugin_class_init (NMSKeyfilePluginClass *req_class) object_class->constructed = constructed; object_class->dispose = dispose; - object_class->get_property = get_property; - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_NAME, - NM_SETTINGS_PLUGIN_NAME); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_INFO, - NM_SETTINGS_PLUGIN_INFO); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, - NM_SETTINGS_PLUGIN_CAPABILITIES); } static void diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h index be7d668a..cd3f42b9 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.h +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h @@ -23,9 +23,6 @@ #include "NetworkManagerUtils.h" -#define NMS_KEYFILE_PLUGIN_NAME "keyfile" -#define NMS_KEYFILE_PLUGIN_INFO "(c) 2007 - 2016 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." - #define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") #define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")" #define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) diff --git a/src/settings/plugins/keyfile/tests/meson.build b/src/settings/plugins/keyfile/tests/meson.build index 54b4ee0d..33aaa264 100644 --- a/src/settings/plugins/keyfile/tests/meson.build +++ b/src/settings/plugins/keyfile/tests/meson.build @@ -2,16 +2,11 @@ test_unit = 'test-keyfile' test_keyfiles_dir = join_paths(meson.current_source_dir(), 'keyfiles') -cflags = [ - '-DTEST_KEYFILES_DIR="@0@"'.format(test_keyfiles_dir), - '-DTEST_SCRATCH_DIR="@0@"'.format(test_keyfiles_dir) -] - exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: cflags + c_args: nm_build_cflags, ) test( diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index b46475e8..a3045f7d 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -37,6 +37,9 @@ #include "nm-test-utils-core.h" +#define TEST_KEYFILES_DIR NM_BUILD_SRCDIR"/src/settings/plugins/keyfile/tests/keyfiles" +#define TEST_SCRATCH_DIR NM_BUILD_BUILDDIR"/src/settings/plugins/keyfile/tests/keyfiles" + /*****************************************************************************/ static void @@ -400,7 +403,6 @@ add_one_ip_route (NMSettingIPConfig *s_ip, nm_ip_route_unref (route); } - static void test_write_wired_connection (void) { @@ -2415,7 +2417,6 @@ test_read_minimal (void) &s_con); nmtst_connection_normalize (con_archetype); - connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_1"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), @@ -2424,7 +2425,6 @@ test_read_minimal (void) nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); g_clear_object (&connection); - connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_2"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), @@ -2451,7 +2451,6 @@ test_read_minimal_slave (void) NULL); nmtst_connection_normalize (con_archetype); - connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_slave_1"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), @@ -2460,7 +2459,6 @@ test_read_minimal_slave (void) nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); g_clear_object (&connection); - connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_slave_2"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), diff --git a/src/supplicant/nm-supplicant-config.c b/src/supplicant/nm-supplicant-config.c index 14f5cac8..80db5baa 100644 --- a/src/supplicant/nm-supplicant-config.c +++ b/src/supplicant/nm-supplicant-config.c @@ -144,7 +144,7 @@ nm_supplicant_config_add_option_with_type (NMSupplicantConfig *self, memset (&buf[0], 0, sizeof (buf)); memcpy (&buf[0], value, len > 254 ? 254 : len); g_set_error (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG, - "key '%s' and/or value '%s' invalid", key, hidden ? hidden : buf); + "key '%s' and/or value '%s' invalid", key, hidden ?: buf); return FALSE; } } @@ -168,7 +168,7 @@ nm_supplicant_config_add_option_with_type (NMSupplicantConfig *self, char buf[255]; memset (&buf[0], 0, sizeof (buf)); memcpy (&buf[0], opt->value, opt->len > 254 ? 254 : opt->len); - nm_log_info (LOGD_SUPPLICANT, "Config: added '%s' value '%s'", key, hidden ? hidden : &buf[0]); + nm_log_info (LOGD_SUPPLICANT, "Config: added '%s' value '%s'", key, hidden ?: &buf[0]); } g_hash_table_insert (priv->config, g_strdup (key), opt); @@ -275,7 +275,6 @@ nm_supplicant_config_finalize (GObject *object) G_OBJECT_CLASS (nm_supplicant_config_parent_class)->finalize (object); } - static void nm_supplicant_config_class_init (NMSupplicantConfigClass *klass) { @@ -980,7 +979,7 @@ add_pkcs11_uri_with_pin (NMSupplicantConfig *self, tmp = g_strdup_printf ("%s%s%s", split[0], (pin_qattr ? "?" : ""), - (pin_qattr ? pin_qattr : "")); + (pin_qattr ?: "")); tmp_log = g_strdup_printf ("%s%s%s", split[0], (pin_qattr ? "?" : ""), @@ -1172,7 +1171,7 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, /* CA path */ path = nm_setting_802_1x_get_ca_path (setting); - path = ca_path_override ? ca_path_override : path; + path = ca_path_override ?: path; if (path) { if (!add_string_val (self, path, "ca_path", FALSE, NULL, error)) return FALSE; @@ -1180,7 +1179,7 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self, /* Phase2 CA path */ path = nm_setting_802_1x_get_phase2_ca_path (setting); - path = ca_path_override ? ca_path_override : path; + path = ca_path_override ?: path; if (path) { if (!add_string_val (self, path, "ca_path2", FALSE, NULL, error)) return FALSE; diff --git a/src/supplicant/nm-supplicant-settings-verify.c b/src/supplicant/nm-supplicant-settings-verify.c index 5198d75f..317afff9 100644 --- a/src/supplicant/nm-supplicant-settings-verify.c +++ b/src/supplicant/nm-supplicant-settings-verify.c @@ -36,7 +36,6 @@ struct Opt { const char ** str_allowed; }; - static gboolean validate_type_int (const struct Opt * opt, const char * value, const guint32 len); @@ -67,7 +66,6 @@ static const struct validate_entry validate_table[] = { { TYPE_KEYWORD, validate_type_keyword }, }; - const char * pairwise_allowed[] = { "CCMP", "TKIP", "NONE", NULL }; const char * group_allowed[] = { "CCMP", "TKIP", "WEP104", "WEP40", NULL }; const char * proto_allowed[] = { "WPA", "RSN", NULL }; @@ -155,7 +153,6 @@ static const struct Opt opt_table[] = { { "ieee80211w", TYPE_INT, 0, 2, FALSE, NULL }, }; - static gboolean validate_type_int (const struct Opt * opt, const char * value, @@ -190,7 +187,7 @@ validate_type_bytes (const struct Opt * opt, g_return_val_if_fail (opt != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); - check_len = opt->int_high ? opt->int_high : 255; + check_len = opt->int_high ?: 255; if (len > check_len) return FALSE; @@ -207,7 +204,7 @@ validate_type_utf8 (const struct Opt *opt, g_return_val_if_fail (opt != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); - check_len = opt->int_high ? opt->int_high : 255; + check_len = opt->int_high ?: 255; /* Note that we deliberately don't validate the UTF-8, because some "UTF-8" fields, such as 8021x.password, do not actually have to be valid UTF-8 */ diff --git a/src/supplicant/nm-supplicant-settings-verify.h b/src/supplicant/nm-supplicant-settings-verify.h index 920343ba..1eec136d 100644 --- a/src/supplicant/nm-supplicant-settings-verify.h +++ b/src/supplicant/nm-supplicant-settings-verify.h @@ -34,5 +34,4 @@ OptType nm_supplicant_settings_verify_setting (const char * key, const char * value, const guint32 len); - #endif /* __NETWORKMANAGER_SUPPLICANT_SETTINGS_VERIFY_H__ */ diff --git a/src/supplicant/tests/meson.build b/src/supplicant/tests/meson.build index e6a86b20..b8bad7f3 100644 --- a/src/supplicant/tests/meson.build +++ b/src/supplicant/tests/meson.build @@ -4,7 +4,7 @@ exe = executable( test_unit, test_unit + '.c', dependencies: test_nm_dep, - c_args: '-DTEST_CERT_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'certs')) + c_args: nm_build_cflags, ) test( diff --git a/src/supplicant/tests/test-supplicant-config.c b/src/supplicant/tests/test-supplicant-config.c index 60ca5258..36831e67 100644 --- a/src/supplicant/tests/test-supplicant-config.c +++ b/src/supplicant/tests/test-supplicant-config.c @@ -37,6 +37,10 @@ #include "nm-test-utils-core.h" +#define TEST_CERT_DIR NM_BUILD_SRCDIR"/src/supplicant/tests/certs" + +/*****************************************************************************/ + static gboolean validate_opt (const char *detail, GVariant *config, @@ -138,7 +142,6 @@ build_supplicant_config (NMConnection *connection, g_assert_no_error (error); g_assert (success); - success = nm_supplicant_config_add_bgscan (config, connection, &error); g_assert_no_error (error); g_assert (success); @@ -146,7 +149,6 @@ build_supplicant_config (NMConnection *connection, return nm_supplicant_config_to_variant (config); } - static NMConnection * new_basic_connection (const char *id, GBytes *ssid, diff --git a/src/systemd/meson.build b/src/systemd/meson.build index fe3d88d3..0c7d0aec 100644 --- a/src/systemd/meson.build +++ b/src/systemd/meson.build @@ -20,6 +20,7 @@ sources = files( 'src/basic/process-util.c', 'src/basic/random-util.c', 'src/basic/socket-util.c', + 'src/basic/stat-util.c', 'src/basic/string-table.c', 'src/basic/string-util.c', 'src/basic/strv.c', diff --git a/src/systemd/nm-sd.c b/src/systemd/nm-sd.c index 43ae0a8b..e05b345b 100644 --- a/src/systemd/nm-sd.c +++ b/src/systemd/nm-sd.c @@ -116,7 +116,6 @@ event_attach (sd_event *event, GMainContext *context) id = g_source_attach ((GSource *) source, context); g_source_unref ((GSource *) source); - if (!event) { *p_default_source_id = id; sd_event_unref (e); diff --git a/src/systemd/sd-adapt/nm-sd-adapt.h b/src/systemd/sd-adapt/nm-sd-adapt.h index 3a4125a0..380cbc60 100644 --- a/src/systemd/sd-adapt/nm-sd-adapt.h +++ b/src/systemd/sd-adapt/nm-sd-adapt.h @@ -142,6 +142,8 @@ G_STMT_START { \ # endif #endif +#define VALGRIND 0 + static inline pid_t raw_getpid (void) { #if defined(__alpha__) @@ -178,7 +180,6 @@ sd_notify (int unset_environment, const char *state) #define MAX_HANDLE_SZ 128 #endif - /* * Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export * CLOCK_BOOTTIME even though the kernel supports it, so provide a diff --git a/src/systemd/sd-adapt/unaligned.h b/src/systemd/sd-adapt/unaligned.h new file mode 100644 index 00000000..17dc0444 --- /dev/null +++ b/src/systemd/sd-adapt/unaligned.h @@ -0,0 +1,3 @@ +#pragma once + +#include "nm-utils/unaligned.h" diff --git a/src/systemd/src/basic/alloc-util.c b/src/systemd/src/basic/alloc-util.c index 1a058d2f..79b823de 100644 --- a/src/systemd/src/basic/alloc-util.c +++ b/src/systemd/src/basic/alloc-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/alloc-util.h b/src/systemd/src/basic/alloc-util.h index b1e0edbb..bae6a284 100644 --- a/src/systemd/src/basic/alloc-util.h +++ b/src/systemd/src/basic/alloc-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <alloca.h> @@ -31,9 +18,17 @@ #define new0(t, n) ((t*) calloc((n), sizeof(t))) -#define newa(t, n) ((t*) alloca(sizeof(t)*(n))) +#define newa(t, n) \ + ({ \ + assert(!size_multiply_overflow(sizeof(t), n)); \ + (t*) alloca(sizeof(t)*(n)); \ + }) -#define newa0(t, n) ((t*) alloca0(sizeof(t)*(n))) +#define newa0(t, n) \ + ({ \ + assert(!size_multiply_overflow(sizeof(t), n)); \ + (t*) alloca0(sizeof(t)*(n)); \ + }) #define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n))) diff --git a/src/systemd/src/basic/async.h b/src/systemd/src/basic/async.h index 01c975bb..36f33377 100644 --- a/src/systemd/src/basic/async.h +++ b/src/systemd/src/basic/async.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2013 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ int asynchronous_job(void* (*func)(void *p), void *arg); diff --git a/src/systemd/src/basic/escape.c b/src/systemd/src/basic/escape.c index fac618dd..f51de788 100644 --- a/src/systemd/src/basic/escape.c +++ b/src/systemd/src/basic/escape.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -203,7 +190,7 @@ int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit) /* C++11 style 16bit unicode */ int a[4]; - unsigned i; + size_t i; uint32_t c; if (length != (size_t) -1 && length < 5) @@ -230,7 +217,7 @@ int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit) /* C++11 style 32bit unicode */ int a[8]; - unsigned i; + size_t i; char32_t c; if (length != (size_t) -1 && length < 9) diff --git a/src/systemd/src/basic/escape.h b/src/systemd/src/basic/escape.h index cd5c49fa..80b0946e 100644 --- a/src/systemd/src/basic/escape.h +++ b/src/systemd/src/basic/escape.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <inttypes.h> diff --git a/src/systemd/src/basic/ether-addr-util.c b/src/systemd/src/basic/ether-addr-util.c index 93922a28..75de9a19 100644 --- a/src/systemd/src/basic/ether-addr-util.c +++ b/src/systemd/src/basic/ether-addr-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2014 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -48,19 +35,23 @@ char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR return buffer; } -bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) { +int ether_addr_compare(const void *a, const void *b) { assert(a); assert(b); - return a->ether_addr_octet[0] == b->ether_addr_octet[0] && - a->ether_addr_octet[1] == b->ether_addr_octet[1] && - a->ether_addr_octet[2] == b->ether_addr_octet[2] && - a->ether_addr_octet[3] == b->ether_addr_octet[3] && - a->ether_addr_octet[4] == b->ether_addr_octet[4] && - a->ether_addr_octet[5] == b->ether_addr_octet[5]; + return memcmp(a, b, ETH_ALEN); } -int ether_addr_from_string(const char *s, struct ether_addr *ret, size_t *offset) { +static void ether_addr_hash_func(const void *p, struct siphash *state) { + siphash24_compress(p, sizeof(struct ether_addr), state); +} + +const struct hash_ops ether_addr_hash_ops = { + .hash = ether_addr_hash_func, + .compare = ether_addr_compare +}; + +int ether_addr_from_string(const char *s, struct ether_addr *ret) { size_t pos = 0, n, field; char sep = '\0'; const char *hex = HEXDIGITS, *hexoff; @@ -99,31 +90,35 @@ int ether_addr_from_string(const char *s, struct ether_addr *ret, size_t *offset assert(s); assert(ret); + s += strspn(s, WHITESPACE); sep = s[strspn(s, hex)]; - if (sep == '\n') - return -EINVAL; - if (!strchr(":.-", sep)) - return -EINVAL; if (sep == '.') { uint16_t shorts[3] = { 0 }; parse_fields(shorts); + if (s[pos] != '\0') + return -EINVAL; + for (n = 0; n < ELEMENTSOF(shorts); n++) { ret->ether_addr_octet[2*n] = ((shorts[n] & (uint16_t)0xff00) >> 8); ret->ether_addr_octet[2*n + 1] = (shorts[n] & (uint16_t)0x00ff); } - } else { - struct ether_addr out = { .ether_addr_octet = { 0 } }; + + } else if (IN_SET(sep, ':', '-')) { + struct ether_addr out = ETHER_ADDR_NULL; parse_fields(out.ether_addr_octet); + if (s[pos] != '\0') + return -EINVAL; + for (n = 0; n < ELEMENTSOF(out.ether_addr_octet); n++) ret->ether_addr_octet[n] = out.ether_addr_octet[n]; - } - if (offset) - *offset = pos; + } else + return -EINVAL; + return 0; } diff --git a/src/systemd/src/basic/ether-addr-util.h b/src/systemd/src/basic/ether-addr-util.h index 08d05a13..f7e0de54 100644 --- a/src/systemd/src/basic/ether-addr-util.h +++ b/src/systemd/src/basic/ether-addr-util.h @@ -5,31 +5,23 @@ This file is part of systemd. Copyright 2014 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <net/ethernet.h> #include <stdbool.h> +#include "hash-funcs.h" + #define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X" #define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5] #define ETHER_ADDR_TO_STRING_MAX (3*6) char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]); -bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b); +int ether_addr_compare(const void *a, const void *b); +static inline bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) { + return ether_addr_compare(a, b) == 0; +} #define ETHER_ADDR_NULL ((const struct ether_addr){}) @@ -37,4 +29,6 @@ static inline bool ether_addr_is_null(const struct ether_addr *addr) { return ether_addr_equal(addr, ÐER_ADDR_NULL); } -int ether_addr_from_string(const char *s, struct ether_addr *ret, size_t *offset); +int ether_addr_from_string(const char *s, struct ether_addr *ret); + +extern const struct hash_ops ether_addr_hash_ops; diff --git a/src/systemd/src/basic/extract-word.c b/src/systemd/src/basic/extract-word.c index e52c376b..2adb8966 100644 --- a/src/systemd/src/basic/extract-word.c +++ b/src/systemd/src/basic/extract-word.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/extract-word.h b/src/systemd/src/basic/extract-word.h index 300c51bb..d2113948 100644 --- a/src/systemd/src/basic/extract-word.h +++ b/src/systemd/src/basic/extract-word.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "macro.h" diff --git a/src/systemd/src/basic/fd-util.c b/src/systemd/src/basic/fd-util.c index ff480f51..6a753195 100644 --- a/src/systemd/src/basic/fd-util.c +++ b/src/systemd/src/basic/fd-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -100,8 +87,8 @@ void safe_close_pair(int p[]) { p[1] = safe_close(p[1]); } -void close_many(const int fds[], unsigned n_fd) { - unsigned i; +void close_many(const int fds[], size_t n_fd) { + size_t i; assert(fds || n_fd <= 0); @@ -194,8 +181,8 @@ int fd_cloexec(int fd, bool cloexec) { } #if 0 /* NM_IGNORED */ -_pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) { - unsigned i; +_pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) { + size_t i; assert(n_fdset == 0 || fdset); @@ -206,7 +193,7 @@ _pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) { return false; } -int close_all_fds(const int except[], unsigned n_except) { +int close_all_fds(const int except[], size_t n_except) { _cleanup_closedir_ DIR *d = NULL; struct dirent *de; int r = 0; @@ -215,15 +202,22 @@ int close_all_fds(const int except[], unsigned n_except) { d = opendir("/proc/self/fd"); if (!d) { - int fd; struct rlimit rl; + int fd, max_fd; - /* When /proc isn't available (for example in chroots) - * the fallback is brute forcing through the fd + /* When /proc isn't available (for example in chroots) the fallback is brute forcing through the fd * table */ assert_se(getrlimit(RLIMIT_NOFILE, &rl) >= 0); - for (fd = 3; fd < (int) rl.rlim_max; fd ++) { + + if (rl.rlim_max == 0) + return -EINVAL; + + /* Let's take special care if the resource limit is set to unlimited, or actually larger than the range + * of 'int'. Let's avoid implicit overflows. */ + max_fd = (rl.rlim_max == RLIM_INFINITY || rl.rlim_max > INT_MAX) ? INT_MAX : (int) (rl.rlim_max - 1); + + for (fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -1) { int q; if (fd_in_set(fd, except, n_except)) diff --git a/src/systemd/src/basic/fd-util.h b/src/systemd/src/basic/fd-util.h index 163b096b..89c3f34c 100644 --- a/src/systemd/src/basic/fd-util.h +++ b/src/systemd/src/basic/fd-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <dirent.h> @@ -42,7 +29,7 @@ static inline int safe_close_above_stdio(int fd) { return safe_close(fd); } -void close_many(const int fds[], unsigned n_fd); +void close_many(const int fds[], size_t n_fd); int fclose_nointr(FILE *f); FILE* safe_fclose(FILE *f); @@ -72,7 +59,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir); int fd_nonblock(int fd, bool nonblock); int fd_cloexec(int fd, bool cloexec); -int close_all_fds(const int except[], unsigned n_except); +int close_all_fds(const int except[], size_t n_except); int same_fd(int a, int b); @@ -98,6 +85,10 @@ int acquire_data_fd(const void *data, size_t size, unsigned flags); #define ERRNO_IS_DISCONNECT(r) \ IN_SET(r, ENOTCONN, ECONNRESET, ECONNREFUSED, ECONNABORTED, EPIPE, ENETUNREACH) +/* Resource exhaustion, could be our fault or general system trouble */ +#define ERRNO_IS_RESOURCE(r) \ + IN_SET(r, ENOMEM, EMFILE, ENFILE) + int fd_move_above_stdio(int fd); int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd); diff --git a/src/systemd/src/basic/fileio.c b/src/systemd/src/basic/fileio.c index c7b4b241..4f71384e 100644 --- a/src/systemd/src/basic/fileio.c +++ b/src/systemd/src/basic/fileio.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -66,6 +53,7 @@ int write_string_stream_ts( struct timespec *ts) { bool needs_nl; + int r; assert(f); assert(line); @@ -90,6 +78,13 @@ int write_string_stream_ts( if (fputc('\n', f) == EOF) return -errno; + if (flags & WRITE_STRING_FILE_SYNC) + r = fflush_sync_and_check(f); + else + r = fflush_and_check(f); + if (r < 0) + return r; + if (ts) { struct timespec twice[2] = {*ts, *ts}; @@ -97,10 +92,7 @@ int write_string_stream_ts( return -errno; } - if (flags & WRITE_STRING_FILE_SYNC) - return fflush_sync_and_check(f); - else - return fflush_and_check(f); + return 0; } static int write_string_file_atomic( @@ -1619,8 +1611,7 @@ int read_line(FILE *f, size_t limit, char **ret) { if (ret) { buffer[n] = 0; - *ret = buffer; - buffer = NULL; + *ret = TAKE_PTR(buffer); } return (int) count; diff --git a/src/systemd/src/basic/fileio.h b/src/systemd/src/basic/fileio.h index da5d5c66..bed7c8fb 100644 --- a/src/systemd/src/basic/fileio.h +++ b/src/systemd/src/basic/fileio.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <dirent.h> diff --git a/src/systemd/src/basic/fs-util.c b/src/systemd/src/basic/fs-util.c index ffd9996a..049b238e 100644 --- a/src/systemd/src/basic/fs-util.c +++ b/src/systemd/src/basic/fs-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -261,6 +248,21 @@ int fchmod_umask(int fd, mode_t m) { } #if 0 /* NM_IGNORED */ +int fchmod_opath(int fd, mode_t m) { + char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; + + /* This function operates also on fd that might have been opened with + * O_PATH. Indeed fchmodat() doesn't have the AT_EMPTY_PATH flag like + * fchownat() does. */ + + xsprintf(procfs_path, "/proc/self/fd/%i", fd); + + if (chmod(procfs_path, m) < 0) + return -errno; + + return 0; +} + int fd_warn_permissions(const char *path, int fd) { struct stat st; @@ -584,10 +586,6 @@ int inotify_add_watch_fd(int fd, int what, uint32_t mask) { return r; } -static bool noop_root(const char *root) { - return isempty(root) || path_equal(root, "/"); -} - static bool safe_transition(const struct stat *a, const struct stat *b) { /* Returns true if the transition from a to b is safe, i.e. that we never transition from unprivileged to * privileged files or directories. Why bother? So that unprivileged code can't symlink to privileged files @@ -602,7 +600,7 @@ static bool safe_transition(const struct stat *a, const struct stat *b) { int chase_symlinks(const char *path, const char *original_root, unsigned flags, char **ret) { _cleanup_free_ char *buffer = NULL, *done = NULL, *root = NULL; _cleanup_close_ int fd = -1; - unsigned max_follow = 32; /* how many symlinks to follow before giving up and returning ELOOP */ + unsigned max_follow = CHASE_SYMLINKS_MAX; /* how many symlinks to follow before giving up and returning ELOOP */ struct stat previous_stat; bool exists = true; char *todo; @@ -614,6 +612,9 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, if ((flags & (CHASE_NONEXISTENT|CHASE_OPEN)) == (CHASE_NONEXISTENT|CHASE_OPEN)) return -EINVAL; + if ((flags & (CHASE_STEP|CHASE_OPEN)) == (CHASE_STEP|CHASE_OPEN)) + return -EINVAL; + if (isempty(path)) return -EINVAL; @@ -635,13 +636,34 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, * Suggested usage: whenever you want to canonicalize a path, use this function. Pass the absolute path you got * as-is: fully qualified and relative to your host's root. Optionally, specify the root parameter to tell this * function what to do when encountering a symlink with an absolute path as directory: prefix it by the - * specified path. */ + * specified path. + * + * There are three ways to invoke this function: + * + * 1. Without CHASE_STEP or CHASE_OPEN: in this case the path is resolved and the normalized path is returned + * in `ret`. The return value is < 0 on error. If CHASE_NONEXISTENT is also set 0 is returned if the file + * doesn't exist, > 0 otherwise. If CHASE_NONEXISTENT is not set >= 0 is returned if the destination was + * found, -ENOENT if it doesn't. + * + * 2. With CHASE_OPEN: in this case the destination is opened after chasing it as O_PATH and this file + * descriptor is returned as return value. This is useful to open files relative to some root + * directory. Note that the returned O_PATH file descriptors must be converted into a regular one (using + * fd_reopen() or such) before it can be used for reading/writing. CHASE_OPEN may not be combined with + * CHASE_NONEXISTENT. + * + * 3. With CHASE_STEP: in this case only a single step of the normalization is executed, i.e. only the first + * symlink or ".." component of the path is resolved, and the resulting path is returned. This is useful if + * a caller wants to trace the a path through the file system verbosely. Returns < 0 on error, > 0 if the + * path is fully normalized, and == 0 for each normalization step. This may be combined with + * CHASE_NONEXISTENT, in which case 1 is returned when a component is not found. + * + * */ /* A root directory of "/" or "" is identical to none */ - if (noop_root(original_root)) + if (empty_or_root(original_root)) original_root = NULL; - if (!original_root && !ret && (flags & (CHASE_NONEXISTENT|CHASE_NO_AUTOFS|CHASE_SAFE|CHASE_OPEN)) == CHASE_OPEN) { + if (!original_root && !ret && (flags & (CHASE_NONEXISTENT|CHASE_NO_AUTOFS|CHASE_SAFE|CHASE_OPEN|CHASE_STEP)) == CHASE_OPEN) { /* Shortcut the CHASE_OPEN case if the caller isn't interested in the actual path and has no root set * and doesn't care about any of the other special features we provide either. */ r = open(path, O_PATH|O_CLOEXEC); @@ -723,7 +745,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, /* If we already are at the top, then going up will not change anything. This is in-line with * how the kernel handles this. */ - if (isempty(done) || path_equal(done, "/")) + if (empty_or_root(done)) continue; parent = dirname_malloc(done); @@ -738,6 +760,9 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, free_and_replace(done, parent); + if (flags & CHASE_STEP) + goto chased_one; + fd_parent = openat(fd, "..", O_CLOEXEC|O_NOFOLLOW|O_PATH); if (fd_parent < 0) return -errno; @@ -854,6 +879,9 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, free(buffer); todo = buffer = joined; + if (flags & CHASE_STEP) + goto chased_one; + continue; } @@ -892,7 +920,23 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, return TAKE_FD(fd); } + if (flags & CHASE_STEP) + return 1; + return exists; + +chased_one: + if (ret) { + char *c; + + c = strjoin(strempty(done), todo); + if (!c) + return -ENOMEM; + + *ret = c; + } + + return 0; } int chase_symlinks_and_open( @@ -909,7 +953,7 @@ int chase_symlinks_and_open( if (chase_flags & CHASE_NONEXISTENT) return -EINVAL; - if (noop_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) { + if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) { /* Shortcut this call if none of the special features of this call are requested */ r = open(path, open_flags); if (r < 0) @@ -949,7 +993,7 @@ int chase_symlinks_and_opendir( if (chase_flags & CHASE_NONEXISTENT) return -EINVAL; - if (noop_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) { + if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) { /* Shortcut this call if none of the special features of this call are requested */ d = opendir(path); if (!d) @@ -975,6 +1019,46 @@ int chase_symlinks_and_opendir( return 0; } +int chase_symlinks_and_stat( + const char *path, + const char *root, + unsigned chase_flags, + char **ret_path, + struct stat *ret_stat) { + + _cleanup_close_ int path_fd = -1; + _cleanup_free_ char *p = NULL; + + assert(path); + assert(ret_stat); + + if (chase_flags & CHASE_NONEXISTENT) + return -EINVAL; + + if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) { + /* Shortcut this call if none of the special features of this call are requested */ + if (stat(path, ret_stat) < 0) + return -errno; + + return 1; + } + + path_fd = chase_symlinks(path, root, chase_flags|CHASE_OPEN, ret_path ? &p : NULL); + if (path_fd < 0) + return path_fd; + + if (fstat(path_fd, ret_stat) < 0) + return -errno; + + if (ret_path) + *ret_path = TAKE_PTR(p); + + if (chase_flags & CHASE_OPEN) + return TAKE_FD(path_fd); + + return 1; +} + int access_fd(int fd, int mode) { char p[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1]; int r; diff --git a/src/systemd/src/basic/fs-util.h b/src/systemd/src/basic/fs-util.h index 2225b7e7..6157fe81 100644 --- a/src/systemd/src/basic/fs-util.h +++ b/src/systemd/src/basic/fs-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <dirent.h> @@ -46,6 +33,7 @@ int readlink_and_make_absolute(const char *p, char **r); int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); int fchmod_umask(int fd, mode_t mode); +int fchmod_opath(int fd, mode_t m); int fd_warn_permissions(const char *path, int fd); @@ -88,12 +76,17 @@ enum { CHASE_SAFE = 1U << 3, /* If set, return EPERM if we ever traverse from unprivileged to privileged files or directories */ CHASE_OPEN = 1U << 4, /* If set, return an O_PATH object to the final component */ CHASE_TRAIL_SLASH = 1U << 5, /* If set, any trailing slash will be preserved */ + CHASE_STEP = 1U << 6, /* If set, just execute a single step of the normalization */ }; +/* How many iterations to execute before returning -ELOOP */ +#define CHASE_SYMLINKS_MAX 32 + int chase_symlinks(const char *path_with_prefix, const char *root, unsigned flags, char **ret); int chase_symlinks_and_open(const char *path, const char *root, unsigned chase_flags, int open_flags, char **ret_path); int chase_symlinks_and_opendir(const char *path, const char *root, unsigned chase_flags, char **ret_path, DIR **ret_dir); +int chase_symlinks_and_stat(const char *path, const char *root, unsigned chase_flags, char **ret_path, struct stat *ret_stat); /* Useful for usage with _cleanup_(), removes a directory and frees the pointer */ static inline void rmdir_and_free(char *p) { diff --git a/src/systemd/src/basic/hash-funcs.c b/src/systemd/src/basic/hash-funcs.c index 234565ed..cb763f56 100644 --- a/src/systemd/src/basic/hash-funcs.c +++ b/src/systemd/src/basic/hash-funcs.c @@ -4,19 +4,6 @@ Copyright 2010 Lennart Poettering Copyright 2014 Michal Schmidt - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -40,7 +27,6 @@ const struct hash_ops string_hash_ops = { .compare = string_compare_func }; - void path_hash_func(const void *p, struct siphash *state) { const char *q = p; size_t n; diff --git a/src/systemd/src/basic/hash-funcs.h b/src/systemd/src/basic/hash-funcs.h index 945b4c25..0c963af8 100644 --- a/src/systemd/src/basic/hash-funcs.h +++ b/src/systemd/src/basic/hash-funcs.h @@ -6,19 +6,6 @@ Copyright 2010 Lennart Poettering Copyright 2014 Michal Schmidt - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "macro.h" diff --git a/src/systemd/src/basic/hashmap.c b/src/systemd/src/basic/hashmap.c index a76ec8e8..b8a8e37b 100644 --- a/src/systemd/src/basic/hashmap.c +++ b/src/systemd/src/basic/hashmap.c @@ -4,19 +4,6 @@ Copyright 2010 Lennart Poettering Copyright 2014 Michal Schmidt - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -296,7 +283,7 @@ static const struct hashmap_type_info hashmap_type_info[_HASHMAP_TYPE_MAX] = { }, }; -#ifdef VALGRIND +#if VALGRIND __attribute__((destructor)) static void cleanup_pools(void) { _cleanup_free_ char *t = NULL; int r; diff --git a/src/systemd/src/basic/hashmap.h b/src/systemd/src/basic/hashmap.h index b6749103..701eecbd 100644 --- a/src/systemd/src/basic/hashmap.h +++ b/src/systemd/src/basic/hashmap.h @@ -6,19 +6,6 @@ Copyright 2010 Lennart Poettering Copyright 2014 Michal Schmidt - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <limits.h> diff --git a/src/systemd/src/basic/hexdecoct.c b/src/systemd/src/basic/hexdecoct.c index e8e82b5f..1fe410f5 100644 --- a/src/systemd/src/basic/hexdecoct.c +++ b/src/systemd/src/basic/hexdecoct.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -92,33 +79,69 @@ char *hexmem(const void *p, size_t l) { return r; } -int unhexmem(const char *p, size_t l, void **mem, size_t *len) { - _cleanup_free_ uint8_t *r = NULL; - uint8_t *z; +static int unhex_next(const char **p, size_t *l) { + int r; + + assert(p); + assert(l); + + /* Find the next non-whitespace character, and decode it. We + * greedily skip all preceeding and all following whitespace. */ + + for (;;) { + if (*l == 0) + return -EPIPE; + + if (!strchr(WHITESPACE, **p)) + break; + + /* Skip leading whitespace */ + (*p)++, (*l)--; + } + + r = unhexchar(**p); + if (r < 0) + return r; + + for (;;) { + (*p)++, (*l)--; + + if (*l == 0 || !strchr(WHITESPACE, **p)) + break; + + /* Skip following whitespace */ + } + + return r; +} + +int unhexmem(const char *p, size_t l, void **ret, size_t *ret_len) { + _cleanup_free_ uint8_t *buf = NULL; const char *x; + uint8_t *z; - assert(mem); - assert(len); + assert(ret); + assert(ret_len); assert(p || l == 0); if (l == (size_t) -1) l = strlen(p); - if (l % 2 != 0) - return -EINVAL; - - z = r = malloc((l + 1) / 2 + 1); - if (!r) + /* Note that the calculation of memory size is an upper boundary, as we ignore whitespace while decoding */ + buf = malloc((l + 1) / 2 + 1); + if (!buf) return -ENOMEM; - for (x = p; x < p + l; x += 2) { + for (x = p, z = buf;;) { int a, b; - a = unhexchar(x[0]); + a = unhex_next(&x, &l); + if (a == -EPIPE) /* End of string */ + break; if (a < 0) return a; - b = unhexchar(x[1]); + b = unhex_next(&x, &l); if (b < 0) return b; @@ -127,9 +150,8 @@ int unhexmem(const char *p, size_t l, void **mem, size_t *len) { *z = 0; - *mem = r; - r = NULL; - *len = (l + 1) / 2; + *ret_len = (size_t) (z - buf); + *ret = TAKE_PTR(buf); return 0; } @@ -198,7 +220,7 @@ char *base32hexmem(const void *p, size_t l, bool padding) { for (x = p; x < (const uint8_t*) p + (l / 5) * 5; x += 5) { /* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ - x[3] == QQQQQQQQ; x[4] == WWWWWWWW */ + * x[3] == QQQQQQQQ; x[4] == WWWWWWWW */ *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ @@ -298,7 +320,7 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l } /* a group of eight input bytes needs five output bytes, in case of - padding we need to add some extra bytes */ + * padding we need to add some extra bytes */ len = (l / 8) * 5; switch (l % 8) { @@ -326,7 +348,7 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l for (x = p; x < p + (l / 8) * 8; x += 8) { /* a == 000XXXXX; b == 000YYYYY; c == 000ZZZZZ; d == 000WWWWW - e == 000SSSSS; f == 000QQQQQ; g == 000VVVVV; h == 000RRRRR */ + * e == 000SSSSS; f == 000QQQQQ; g == 000VVVVV; h == 000RRRRR */ a = unbase32hexchar(x[0]); if (a < 0) return -EINVAL; @@ -485,8 +507,7 @@ int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l *z = 0; - *mem = r; - r = NULL; + *mem = TAKE_PTR(r); *_len = len; return 0; @@ -683,7 +704,7 @@ int unbase64mem(const char *p, size_t l, void **ret, size_t *ret_size) { l = strlen(p); /* A group of four input bytes needs three output bytes, in case of padding we need to add two or three extra - bytes. Note that this calculation is an upper boundary, as we ignore whitespace while decoding */ + * bytes. Note that this calculation is an upper boundary, as we ignore whitespace while decoding */ len = (l / 4) * 3 + (l % 4 != 0 ? (l % 4) - 1 : 0); buf = malloc(len + 1); @@ -751,11 +772,8 @@ int unbase64mem(const char *p, size_t l, void **ret, size_t *ret_size) { *z = 0; - if (ret_size) - *ret_size = (size_t) (z - buf); - - *ret = buf; - buf = NULL; + *ret_size = (size_t) (z - buf); + *ret = TAKE_PTR(buf); return 0; } diff --git a/src/systemd/src/basic/hexdecoct.h b/src/systemd/src/basic/hexdecoct.h index 08d0a522..c2f11013 100644 --- a/src/systemd/src/basic/hexdecoct.h +++ b/src/systemd/src/basic/hexdecoct.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> diff --git a/src/systemd/src/basic/hostname-util.c b/src/systemd/src/basic/hostname-util.c index 66b80727..0feeaa5d 100644 --- a/src/systemd/src/basic/hostname-util.c +++ b/src/systemd/src/basic/hostname-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2015 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/hostname-util.h b/src/systemd/src/basic/hostname-util.h index edae52e3..8e29e9e1 100644 --- a/src/systemd/src/basic/hostname-util.h +++ b/src/systemd/src/basic/hostname-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010-2015 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> diff --git a/src/systemd/src/basic/in-addr-util.c b/src/systemd/src/basic/in-addr-util.c index b2b68089..65748615 100644 --- a/src/systemd/src/basic/in-addr-util.c +++ b/src/systemd/src/basic/in-addr-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2014 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/in-addr-util.h b/src/systemd/src/basic/in-addr-util.h index acaae6d2..acd567c9 100644 --- a/src/systemd/src/basic/in-addr-util.h +++ b/src/systemd/src/basic/in-addr-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2014 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <netinet/in.h> diff --git a/src/systemd/src/basic/io-util.c b/src/systemd/src/basic/io-util.c index 0f10ad7f..1bc5c345 100644 --- a/src/systemd/src/basic/io-util.c +++ b/src/systemd/src/basic/io-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/io-util.h b/src/systemd/src/basic/io-util.h index d81610ad..e4717b6f 100644 --- a/src/systemd/src/basic/io-util.h +++ b/src/systemd/src/basic/io-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> @@ -41,9 +28,8 @@ int fd_wait_for_event(int fd, int event, usec_t timeout); ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length); -static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { - unsigned j; - size_t r = 0; +static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) { + size_t j, r = 0; for (j = 0; j < n; j++) r += i[j].iov_len; @@ -51,8 +37,8 @@ static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { return r; } -static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { - unsigned j; +static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) { + size_t j; for (j = 0; j < n; j++) { size_t sub; diff --git a/src/systemd/src/basic/list.h b/src/systemd/src/basic/list.h index 7006c3e2..3ec7e73f 100644 --- a/src/systemd/src/basic/list.h +++ b/src/systemd/src/basic/list.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ /* The head of the linked list. Use this in the structure that shall diff --git a/src/systemd/src/basic/log.h b/src/systemd/src/basic/log.h index b0e963b0..e7d7c8b1 100644 --- a/src/systemd/src/basic/log.h +++ b/src/systemd/src/basic/log.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdarg.h> diff --git a/src/systemd/src/basic/macro.h b/src/systemd/src/basic/macro.h index 025a5db7..c89fb84e 100644 --- a/src/systemd/src/basic/macro.h +++ b/src/systemd/src/basic/macro.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <inttypes.h> @@ -372,7 +359,7 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { ({ \ typeof(x) _x_ = (x); \ unsigned ans = 1; \ - while (_x_ /= 10) \ + while ((_x_ /= 10) != 0) \ ans++; \ ans; \ }) diff --git a/src/systemd/src/basic/mempool.c b/src/systemd/src/basic/mempool.c index 43ae59c9..07096766 100644 --- a/src/systemd/src/basic/mempool.c +++ b/src/systemd/src/basic/mempool.c @@ -4,19 +4,6 @@ Copyright 2010-2014 Lennart Poettering Copyright 2014 Michal Schmidt - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -30,12 +17,12 @@ struct pool { struct pool *next; - unsigned n_tiles; - unsigned n_used; + size_t n_tiles; + size_t n_used; }; void* mempool_alloc_tile(struct mempool *mp) { - unsigned i; + size_t i; /* When a tile is released we add it to the list and simply * place the next pointer at its offset 0. */ @@ -53,8 +40,7 @@ void* mempool_alloc_tile(struct mempool *mp) { if (_unlikely_(!mp->first_pool) || _unlikely_(mp->first_pool->n_used >= mp->first_pool->n_tiles)) { - unsigned n; - size_t size; + size_t size, n; struct pool *p; n = mp->first_pool ? mp->first_pool->n_tiles : 0; @@ -92,7 +78,7 @@ void mempool_free_tile(struct mempool *mp, void *p) { mp->freelist = p; } -#ifdef VALGRIND +#if VALGRIND void mempool_drop(struct mempool *mp) { struct pool *p = mp->first_pool; diff --git a/src/systemd/src/basic/mempool.h b/src/systemd/src/basic/mempool.h index c9235c83..68249cd8 100644 --- a/src/systemd/src/basic/mempool.h +++ b/src/systemd/src/basic/mempool.h @@ -6,19 +6,6 @@ Copyright 2011-2014 Lennart Poettering Copyright 2014 Michal Schmidt - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stddef.h> @@ -43,6 +30,6 @@ static struct mempool pool_name = { \ } -#ifdef VALGRIND +#if VALGRIND void mempool_drop(struct mempool *mp); #endif diff --git a/src/systemd/src/basic/parse-util.c b/src/systemd/src/basic/parse-util.c index 44fae932..ae43a041 100644 --- a/src/systemd/src/basic/parse-util.c +++ b/src/systemd/src/basic/parse-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -26,12 +13,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/socket.h> #include "alloc-util.h" #include "errno-list.h" #include "extract-word.h" #include "locale-util.h" #include "macro.h" +#include "missing.h" #include "parse-util.h" #include "process-util.h" #include "string-util.h" @@ -109,6 +98,30 @@ int parse_ifindex(const char *s, int *ret) { return 0; } +int parse_mtu(int family, const char *s, uint32_t *ret) { + uint64_t u; + size_t m; + int r; + + r = parse_size(s, 1024, &u); + if (r < 0) + return r; + + if (u > UINT32_MAX) + return -ERANGE; + + if (family == AF_INET6) + m = IPV6_MIN_MTU; /* This is 1280 */ + else + m = IPV4_MIN_MTU; /* For all other protocols, including 'unspecified' we assume the IPv4 minimal MTU */ + + if (u < m) + return -ERANGE; + + *ret = (uint32_t) u; + return 0; +} + int parse_size(const char *t, uint64_t base, uint64_t *size) { /* Soo, sometimes we want to parse IEC binary suffixes, and @@ -668,4 +681,21 @@ int parse_dev(const char *s, dev_t *ret) { *ret = d; return 0; } + +int parse_oom_score_adjust(const char *s, int *ret) { + int r, v; + + assert(s); + assert(ret); + + r = safe_atoi(s, &v); + if (r < 0) + return r; + + if (v < OOM_SCORE_ADJ_MIN || v > OOM_SCORE_ADJ_MAX) + return -ERANGE; + + *ret = v; + return 0; +} #endif /* NM_IGNORED */ diff --git a/src/systemd/src/basic/parse-util.h b/src/systemd/src/basic/parse-util.h index 1605cc4f..2b75b938 100644 --- a/src/systemd/src/basic/parse-util.h +++ b/src/systemd/src/basic/parse-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <inttypes.h> @@ -35,6 +22,7 @@ int parse_dev(const char *s, dev_t *ret); int parse_pid(const char *s, pid_t* ret_pid); int parse_mode(const char *s, mode_t *ret); int parse_ifindex(const char *s, int *ret); +int parse_mtu(int family, const char *s, uint32_t *ret); int parse_size(const char *t, uint64_t base, uint64_t *size); int parse_range(const char *t, unsigned *lower, unsigned *upper); @@ -130,3 +118,5 @@ int parse_percent(const char *p); int parse_nice(const char *p, int *ret); int parse_ip_port(const char *s, uint16_t *ret); + +int parse_oom_score_adjust(const char *s, int *ret); diff --git a/src/systemd/src/basic/path-util.c b/src/systemd/src/basic/path-util.c index 23827c19..567fc61c 100644 --- a/src/systemd/src/basic/path-util.c +++ b/src/systemd/src/basic/path-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010-2012 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -658,7 +645,7 @@ char *prefix_root(const char *root, const char *path) { while (path[0] == '/' && path[1] == '/') path++; - if (isempty(root) || path_equal(root, "/")) + if (empty_or_root(root)) return strdup(path); l = strlen(root) + 1 + strlen(path) + 1; @@ -703,11 +690,12 @@ int parse_path_argument_and_warn(const char *path, bool suppress_root, char **ar return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path); path_kill_slashes(p); - if (suppress_root && path_equal(p, "/")) + if (suppress_root && empty_or_root(p)) p = mfree(p); free(*arg); *arg = p; + return 0; } @@ -733,16 +721,23 @@ char* dirname_malloc(const char *path) { } const char *last_path_component(const char *path) { - /* Finds the last component of the path, preserving the - * optional trailing slash that signifies a directory. + + /* Finds the last component of the path, preserving the optional trailing slash that signifies a directory. + * * a/b/c → c * a/b/c/ → c/ + * x → x + * x/ → x/ + * /y → y + * /y/ → y/ * / → / * // → / * /foo/a → a * /foo/a/ → a/ - * This is different than basename, which returns "" when - * a trailing slash is present. + * + * Also, the empty string is mapped to itself. + * + * This is different than basename(), which returns "" when a trailing slash is present. */ unsigned l, k; @@ -979,3 +974,14 @@ bool dot_or_dot_dot(const char *path) { return path[2] == 0; } + +bool empty_or_root(const char *root) { + + /* For operations relative to some root directory, returns true if the specified root directory is redundant, + * i.e. either / or NULL or the empty string or any equivalent. */ + + if (!root) + return true; + + return root[strspn(root, "/")] == 0; +} diff --git a/src/systemd/src/basic/path-util.h b/src/systemd/src/basic/path-util.h index 8848abe9..79db819e 100644 --- a/src/systemd/src/basic/path-util.h +++ b/src/systemd/src/basic/path-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010-2012 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <alloca.h> @@ -29,19 +16,32 @@ #include "time-util.h" #if 0 /* NM_IGNORED */ +#define PATH_SPLIT_SBIN_BIN(x) x "sbin:" x "bin" +#define PATH_SPLIT_SBIN_BIN_NULSTR(x) x "sbin\0" x "bin\0" + +#define PATH_NORMAL_SBIN_BIN(x) x "bin" +#define PATH_NORMAL_SBIN_BIN_NULSTR(x) x "bin\0" + #if HAVE_SPLIT_BIN -# define PATH_SBIN_BIN(x) x "sbin:" x "bin" +# define PATH_SBIN_BIN(x) PATH_SPLIT_SBIN_BIN(x) +# define PATH_SBIN_BIN_NULSTR(x) PATH_SPLIT_SBIN_BIN_NULSTR(x) #else -# define PATH_SBIN_BIN(x) x "bin" +# define PATH_SBIN_BIN(x) PATH_NORMAL_SBIN_BIN(x) +# define PATH_SBIN_BIN_NULSTR(x) PATH_NORMAL_SBIN_BIN_NULSTR(x) #endif #define DEFAULT_PATH_NORMAL PATH_SBIN_BIN("/usr/local/") ":" PATH_SBIN_BIN("/usr/") +#define DEFAULT_PATH_NORMAL_NULSTR PATH_SBIN_BIN_NULSTR("/usr/local/") PATH_SBIN_BIN_NULSTR("/usr/") #define DEFAULT_PATH_SPLIT_USR DEFAULT_PATH_NORMAL ":" PATH_SBIN_BIN("/") +#define DEFAULT_PATH_SPLIT_USR_NULSTR DEFAULT_PATH_NORMAL_NULSTR PATH_SBIN_BIN_NULSTR("/") +#define DEFAULT_PATH_COMPAT PATH_SPLIT_SBIN_BIN("/usr/local/") ":" PATH_SPLIT_SBIN_BIN("/usr/") ":" PATH_SPLIT_SBIN_BIN("/") #if HAVE_SPLIT_USR # define DEFAULT_PATH DEFAULT_PATH_SPLIT_USR +# define DEFAULT_PATH_NULSTR DEFAULT_PATH_SPLIT_USR_NULSTR #else # define DEFAULT_PATH DEFAULT_PATH_NORMAL +# define DEFAULT_PATH_NULSTR DEFAULT_PATH_NORMAL_NULSTR #endif #endif /* NM_IGNORED */ @@ -120,7 +120,7 @@ char *prefix_root(const char *root, const char *path); size_t _l; \ while (_path[0] == '/' && _path[1] == '/') \ _path ++; \ - if (isempty(_root) || path_equal(_root, "/")) \ + if (empty_or_root(_root)) \ _ret = _path; \ else { \ _l = strlen(_root) + 1 + strlen(_path) + 1; \ @@ -164,3 +164,8 @@ static inline const char *skip_dev_prefix(const char *p) { return e ?: p; } + +bool empty_or_root(const char *root); +static inline const char *empty_to_root(const char *path) { + return isempty(path) ? "/" : path; +} diff --git a/src/systemd/src/basic/prioq.c b/src/systemd/src/basic/prioq.c index 1e81bc71..805a6174 100644 --- a/src/systemd/src/basic/prioq.c +++ b/src/systemd/src/basic/prioq.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2013 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ /* diff --git a/src/systemd/src/basic/prioq.h b/src/systemd/src/basic/prioq.h index a222955d..e348c646 100644 --- a/src/systemd/src/basic/prioq.h +++ b/src/systemd/src/basic/prioq.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2013 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> diff --git a/src/systemd/src/basic/process-util.c b/src/systemd/src/basic/process-util.c index 4128ac54..4af99957 100644 --- a/src/systemd/src/basic/process-util.c +++ b/src/systemd/src/basic/process-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -898,7 +885,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) { do { char line[LINE_MAX]; - unsigned i; + size_t i; for (i = 0; i < sizeof(line)-1; i++) { int c; @@ -1397,9 +1384,9 @@ int safe_fork_full( return 0; } -int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *ret_pid, const char *path, ...) { +int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) { bool stdout_is_tty, stderr_is_tty; - unsigned n, i; + size_t n, i; va_list ap; char **l; int r; @@ -1455,7 +1442,7 @@ int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *r va_end(ap); /* Allocate strv */ - l = alloca(sizeof(char *) * (n + 1)); + l = newa(char*, n + 1); /* Fill in arguments */ va_start(ap, path); @@ -1467,6 +1454,15 @@ int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *r _exit(EXIT_FAILURE); } +int set_oom_score_adjust(int value) { + char t[DECIMAL_STR_MAX(int)]; + + sprintf(t, "%i", value); + + return write_string_file("/proc/self/oom_score_adj", t, + WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER); +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", diff --git a/src/systemd/src/basic/process-util.h b/src/systemd/src/basic/process-util.h index 3525c2d6..e3bf36bf 100644 --- a/src/systemd/src/basic/process-util.h +++ b/src/systemd/src/basic/process-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <alloca.h> @@ -186,7 +173,9 @@ static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret_pid) { return safe_fork_full(name, NULL, 0, flags, ret_pid); } -int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *pid, const char *path, ...); +int fork_agent(const char *name, const int except[], size_t n_except, pid_t *pid, const char *path, ...); + +int set_oom_score_adjust(int value); #if SIZEOF_PID_T == 4 /* The highest possibly (theoretic) pid_t value on this architecture. */ @@ -206,3 +195,11 @@ int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *p #endif assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX) + +/* Like TAKE_PTR() but for child PIDs, resetting them to 0 */ +#define TAKE_PID(pid) \ + ({ \ + pid_t _pid_ = (pid); \ + (pid) = 0; \ + _pid_; \ + }) diff --git a/src/systemd/src/basic/random-util.c b/src/systemd/src/basic/random-util.c index 29ee3b45..d80751cf 100644 --- a/src/systemd/src/basic/random-util.c +++ b/src/systemd/src/basic/random-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -50,7 +37,7 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) { static int have_syscall = -1; _cleanup_close_ int fd = -1; - unsigned already_done = 0; + size_t already_done = 0; int r; /* Gathers some randomness from the kernel. This call will never block. If @@ -131,7 +118,6 @@ void initialize_srand(void) { #endif x = 0; - x ^= (unsigned) now(CLOCK_REALTIME); x ^= (unsigned) gettid(); diff --git a/src/systemd/src/basic/random-util.h b/src/systemd/src/basic/random-util.h index dd870151..72391705 100644 --- a/src/systemd/src/basic/random-util.h +++ b/src/systemd/src/basic/random-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> diff --git a/src/systemd/src/basic/refcnt.h b/src/systemd/src/basic/refcnt.h index ae2e446d..0d5b3f4e 100644 --- a/src/systemd/src/basic/refcnt.h +++ b/src/systemd/src/basic/refcnt.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2013 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ /* A type-safe atomic refcounter. diff --git a/src/systemd/src/basic/set.h b/src/systemd/src/basic/set.h index 156ab4b0..dc0f1e17 100644 --- a/src/systemd/src/basic/set.h +++ b/src/systemd/src/basic/set.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "extract-word.h" @@ -149,5 +136,3 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free); #define _cleanup_set_free_ _cleanup_(set_freep) #define _cleanup_set_free_free_ _cleanup_(set_free_freep) - -int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, void *add, ...); diff --git a/src/systemd/src/basic/signal-util.h b/src/systemd/src/basic/signal-util.h index f6c3396e..0c43467b 100644 --- a/src/systemd/src/basic/signal-util.h +++ b/src/systemd/src/basic/signal-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010-2015 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <signal.h> @@ -37,8 +24,6 @@ int sigprocmask_many(int how, sigset_t *old, ...); const char *signal_to_string(int i) _const_; int signal_from_string(const char *s) _pure_; -int signal_from_string_try_harder(const char *s); - void nop_signal_handler(int sig); static inline void block_signals_reset(sigset_t *ss) { diff --git a/src/systemd/src/basic/siphash24.h b/src/systemd/src/basic/siphash24.h new file mode 100644 index 00000000..77bb9a8c --- /dev/null +++ b/src/systemd/src/basic/siphash24.h @@ -0,0 +1,53 @@ +#pragma once + +#include <inttypes.h> +#include <stddef.h> +#include <stdint.h> +#include <sys/types.h> + +#if 0 /* NM_IGNORED */ +struct siphash { + uint64_t v0; + uint64_t v1; + uint64_t v2; + uint64_t v3; + uint64_t padding; + size_t inlen; +}; +#else /* NM_IGNORED */ +struct siphash { + CSipHash _csiphash; +}; + +static inline void +siphash24_init (struct siphash *state, const uint8_t k[16]) +{ + c_siphash_init ((CSipHash *) state, k); +} + +static inline void +siphash24_compress (const void *in, size_t inlen, struct siphash *state) +{ + c_siphash_append ((CSipHash *) state, in, inlen); +} + +static inline uint64_t +siphash24_finalize (struct siphash *state) +{ + return c_siphash_finalize ((CSipHash *) state); +} + +static inline uint64_t +siphash24 (const void *in, size_t inlen, const uint8_t k[16]) +{ + return c_siphash_hash (k, in, inlen); +} +#endif /* NM_IGNORED */ + +void siphash24_init(struct siphash *state, const uint8_t k[16]); +void siphash24_compress(const void *in, size_t inlen, struct siphash *state); +#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state)) + +uint64_t siphash24_finalize(struct siphash *state); + +uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[16]); diff --git a/src/systemd/src/basic/socket-util.c b/src/systemd/src/basic/socket-util.c index 8ae68b6f..aa06070e 100644 --- a/src/systemd/src/basic/socket-util.c +++ b/src/systemd/src/basic/socket-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -680,7 +667,6 @@ int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ return -EOPNOTSUPP; } - *ret = p; return 0; } @@ -1020,8 +1006,7 @@ int getpeergroups(int fd, gid_t **ret) { if ((socklen_t) (int) n != n) return -E2BIG; - *ret = d; - d = NULL; + *ret = TAKE_PTR(d); return (int) n; } @@ -1146,7 +1131,6 @@ int flush_accept(int fd) { }; int r; - /* Similar to flush_fd() but flushes all incoming connection by accepting them and immediately closing them. */ for (;;) { diff --git a/src/systemd/src/basic/socket-util.h b/src/systemd/src/basic/socket-util.h index ac957a76..c2d21b45 100644 --- a/src/systemd/src/basic/socket-util.h +++ b/src/systemd/src/basic/socket-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <netinet/ether.h> diff --git a/src/systemd/src/basic/stat-util.c b/src/systemd/src/basic/stat-util.c new file mode 100644 index 00000000..28e75618 --- /dev/null +++ b/src/systemd/src/basic/stat-util.c @@ -0,0 +1,292 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/*** + This file is part of systemd. + + Copyright 2010-2012 Lennart Poettering +***/ + +#include "nm-sd-adapt.h" + +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <linux/magic.h> +#include <sched.h> +#include <sys/stat.h> +#include <sys/statvfs.h> +#include <sys/types.h> +#include <unistd.h> + +#include "dirent-util.h" +#include "fd-util.h" +#include "fs-util.h" +#include "macro.h" +#include "missing.h" +#include "stat-util.h" +#include "string-util.h" + +#if 0 /* NM_IGNORED */ +int is_symlink(const char *path) { + struct stat info; + + assert(path); + + if (lstat(path, &info) < 0) + return -errno; + + return !!S_ISLNK(info.st_mode); +} + +int is_dir(const char* path, bool follow) { + struct stat st; + int r; + + assert(path); + + if (follow) + r = stat(path, &st); + else + r = lstat(path, &st); + if (r < 0) + return -errno; + + return !!S_ISDIR(st.st_mode); +} + +int is_device_node(const char *path) { + struct stat info; + + assert(path); + + if (lstat(path, &info) < 0) + return -errno; + + return !!(S_ISBLK(info.st_mode) || S_ISCHR(info.st_mode)); +} + +int dir_is_empty(const char *path) { + _cleanup_closedir_ DIR *d; + struct dirent *de; + + d = opendir(path); + if (!d) + return -errno; + + FOREACH_DIRENT(de, d, return -errno) + return 0; + + return 1; +} + +bool null_or_empty(struct stat *st) { + assert(st); + + if (S_ISREG(st->st_mode) && st->st_size <= 0) + return true; + + /* We don't want to hardcode the major/minor of /dev/null, + * hence we do a simpler "is this a device node?" check. */ + + if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) + return true; + + return false; +} + +int null_or_empty_path(const char *fn) { + struct stat st; + + assert(fn); + + if (stat(fn, &st) < 0) + return -errno; + + return null_or_empty(&st); +} + +int null_or_empty_fd(int fd) { + struct stat st; + + assert(fd >= 0); + + if (fstat(fd, &st) < 0) + return -errno; + + return null_or_empty(&st); +} + +int path_is_read_only_fs(const char *path) { + struct statvfs st; + + assert(path); + + if (statvfs(path, &st) < 0) + return -errno; + + if (st.f_flag & ST_RDONLY) + return true; + + /* On NFS, statvfs() might not reflect whether we can actually + * write to the remote share. Let's try again with + * access(W_OK) which is more reliable, at least sometimes. */ + if (access(path, W_OK) < 0 && errno == EROFS) + return true; + + return false; +} + +int path_is_os_tree(const char *path) { + int r; + + assert(path); + + /* Does the path exist at all? If not, generate an error immediately. This is useful so that a missing root dir + * always results in -ENOENT, and we can properly distuingish the case where the whole root doesn't exist from + * the case where just the os-release file is missing. */ + if (laccess(path, F_OK) < 0) + return -errno; + + /* We use /usr/lib/os-release as flag file if something is an OS */ + r = chase_symlinks("/usr/lib/os-release", path, CHASE_PREFIX_ROOT, NULL); + if (r == -ENOENT) { + + /* Also check for the old location in /etc, just in case. */ + r = chase_symlinks("/etc/os-release", path, CHASE_PREFIX_ROOT, NULL); + if (r == -ENOENT) + return 0; /* We got nothing */ + } + if (r < 0) + return r; + + return 1; +} + +int files_same(const char *filea, const char *fileb, int flags) { + struct stat a, b; + + assert(filea); + assert(fileb); + + if (fstatat(AT_FDCWD, filea, &a, flags) < 0) + return -errno; + + if (fstatat(AT_FDCWD, fileb, &b, flags) < 0) + return -errno; + + return a.st_dev == b.st_dev && + a.st_ino == b.st_ino; +} + +bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) { + assert(s); + assert_cc(sizeof(statfs_f_type_t) >= sizeof(s->f_type)); + + return F_TYPE_EQUAL(s->f_type, magic_value); +} + +int fd_is_fs_type(int fd, statfs_f_type_t magic_value) { + struct statfs s; + + if (fstatfs(fd, &s) < 0) + return -errno; + + return is_fs_type(&s, magic_value); +} + +int path_is_fs_type(const char *path, statfs_f_type_t magic_value) { + _cleanup_close_ int fd = -1; + + fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH); + if (fd < 0) + return -errno; + + return fd_is_fs_type(fd, magic_value); +} + +bool is_temporary_fs(const struct statfs *s) { + return is_fs_type(s, TMPFS_MAGIC) || + is_fs_type(s, RAMFS_MAGIC); +} + +bool is_network_fs(const struct statfs *s) { + return is_fs_type(s, CIFS_MAGIC_NUMBER) || + is_fs_type(s, CODA_SUPER_MAGIC) || + is_fs_type(s, NCP_SUPER_MAGIC) || + is_fs_type(s, NFS_SUPER_MAGIC) || + is_fs_type(s, SMB_SUPER_MAGIC) || + is_fs_type(s, V9FS_MAGIC) || + is_fs_type(s, AFS_SUPER_MAGIC) || + is_fs_type(s, OCFS2_SUPER_MAGIC); +} + +int fd_is_temporary_fs(int fd) { + struct statfs s; + + if (fstatfs(fd, &s) < 0) + return -errno; + + return is_temporary_fs(&s); +} + +int fd_is_network_fs(int fd) { + struct statfs s; + + if (fstatfs(fd, &s) < 0) + return -errno; + + return is_network_fs(&s); +} + +int fd_is_network_ns(int fd) { + int r; + + r = fd_is_fs_type(fd, NSFS_MAGIC); + if (r <= 0) + return r; + + r = ioctl(fd, NS_GET_NSTYPE); + if (r < 0) + return -errno; + + return r == CLONE_NEWNET; +} + +int path_is_temporary_fs(const char *path) { + _cleanup_close_ int fd = -1; + + fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH); + if (fd < 0) + return -errno; + + return fd_is_temporary_fs(fd); +} +#endif /* NM_IGNORED */ + +int stat_verify_regular(const struct stat *st) { + assert(st); + + /* Checks whether the specified stat() structure refers to a regular file. If not returns an appropriate error + * code. */ + + if (S_ISDIR(st->st_mode)) + return -EISDIR; + + if (S_ISLNK(st->st_mode)) + return -ELOOP; + + if (!S_ISREG(st->st_mode)) + return -EBADFD; + + return 0; +} + +int fd_verify_regular(int fd) { + struct stat st; + + assert(fd >= 0); + + if (fstat(fd, &st) < 0) + return -errno; + + return stat_verify_regular(&st); +} diff --git a/src/systemd/src/basic/stat-util.h b/src/systemd/src/basic/stat-util.h new file mode 100644 index 00000000..d1e8d330 --- /dev/null +++ b/src/systemd/src/basic/stat-util.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010-2012 Lennart Poettering +***/ + +#include <stdbool.h> +#include <stddef.h> +#include <sys/stat.h> +#include <sys/statfs.h> +#include <sys/types.h> +#include <sys/vfs.h> + +#include "macro.h" + +int is_symlink(const char *path); +int is_dir(const char *path, bool follow); +int is_device_node(const char *path); + +int dir_is_empty(const char *path); + +static inline int dir_is_populated(const char *path) { + int r; + r = dir_is_empty(path); + if (r < 0) + return r; + return !r; +} + +bool null_or_empty(struct stat *st) _pure_; +int null_or_empty_path(const char *fn); +int null_or_empty_fd(int fd); + +int path_is_read_only_fs(const char *path); +int path_is_os_tree(const char *path); + +int files_same(const char *filea, const char *fileb, int flags); + +/* The .f_type field of struct statfs is really weird defined on + * different archs. Let's give its type a name. */ +typedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t; + +bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_; +int fd_is_fs_type(int fd, statfs_f_type_t magic_value); +int path_is_fs_type(const char *path, statfs_f_type_t magic_value); + +bool is_temporary_fs(const struct statfs *s) _pure_; +bool is_network_fs(const struct statfs *s) _pure_; + +int fd_is_temporary_fs(int fd); +int fd_is_network_fs(int fd); + +int fd_is_network_ns(int fd); + +int path_is_temporary_fs(const char *path); + +/* Because statfs.t_type can be int on some architectures, we have to cast + * the const magic to the type, otherwise the compiler warns about + * signed/unsigned comparison, because the magic can be 32 bit unsigned. + */ +#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b) + +int stat_verify_regular(const struct stat *st); +int fd_verify_regular(int fd); diff --git a/src/systemd/src/basic/stdio-util.h b/src/systemd/src/basic/stdio-util.h index d3fed365..5330789a 100644 --- a/src/systemd/src/basic/stdio-util.h +++ b/src/systemd/src/basic/stdio-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <printf.h> diff --git a/src/systemd/src/basic/string-table.c b/src/systemd/src/basic/string-table.c index 8ec3b266..34723b4c 100644 --- a/src/systemd/src/basic/string-table.c +++ b/src/systemd/src/basic/string-table.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/string-table.h b/src/systemd/src/basic/string-table.h index e78a6dbd..a39206fb 100644 --- a/src/systemd/src/basic/string-table.h +++ b/src/systemd/src/basic/string-table.h @@ -6,19 +6,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <errno.h> diff --git a/src/systemd/src/basic/string-util.c b/src/systemd/src/basic/string-util.c index a8e595db..a60c7dcc 100644 --- a/src/systemd/src/basic/string-util.c +++ b/src/systemd/src/basic/string-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -30,11 +17,13 @@ #include "alloc-util.h" #include "gunicode.h" +#include "locale-util.h" #include "macro.h" #include "string-util.h" #include "terminal-util.h" #include "utf8.h" #include "util.h" +#include "fileio.h" int strcmp_ptr(const char *a, const char *b) { @@ -470,62 +459,104 @@ bool string_has_cc(const char *p, const char *ok) { #if 0 /* NM_IGNORED */ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) { - size_t x; + size_t x, need_space; char *r; assert(s); assert(percent <= 100); - assert(new_length >= 3); + assert(new_length != (size_t) -1); - if (old_length <= 3 || old_length <= new_length) + if (old_length <= new_length) return strndup(s, old_length); - r = new0(char, new_length+3); + /* Special case short ellipsations */ + switch (new_length) { + + case 0: + return strdup(""); + + case 1: + if (is_locale_utf8()) + return strdup("…"); + else + return strdup("."); + + case 2: + if (!is_locale_utf8()) + return strdup(".."); + + break; + + default: + break; + } + + /* Calculate how much space the ellipsis will take up. If we are in UTF-8 mode we only need space for one + * character ("…"), otherwise for three characters ("..."). Note that in both cases we need 3 bytes of storage, + * either for the UTF-8 encoded character or for three ASCII characters. */ + need_space = is_locale_utf8() ? 1 : 3; + + r = new(char, new_length+3); if (!r) return NULL; - x = (new_length * percent) / 100; + assert(new_length >= need_space); - if (x > new_length - 3) - x = new_length - 3; + x = ((new_length - need_space) * percent + 50) / 100; + assert(x <= new_length - need_space); memcpy(r, s, x); - r[x] = 0xe2; /* tri-dot ellipsis: … */ - r[x+1] = 0x80; - r[x+2] = 0xa6; + + if (is_locale_utf8()) { + r[x+0] = 0xe2; /* tri-dot ellipsis: … */ + r[x+1] = 0x80; + r[x+2] = 0xa6; + } else { + r[x+0] = '.'; + r[x+1] = '.'; + r[x+2] = '.'; + } + memcpy(r + x + 3, - s + old_length - (new_length - x - 1), - new_length - x - 1); + s + old_length - (new_length - x - need_space), + new_length - x - need_space + 1); return r; } char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) { - size_t x; - char *e; + size_t x, k, len, len2; const char *i, *j; - unsigned k, len, len2; + char *e; int r; + /* Note that 'old_length' refers to bytes in the string, while 'new_length' refers to character cells taken up + * on screen. This distinction doesn't matter for ASCII strings, but it does matter for non-ASCII UTF-8 + * strings. + * + * Ellipsation is done in a locale-dependent way: + * 1. If the string passed in is fully ASCII and the current locale is not UTF-8, three dots are used ("...") + * 2. Otherwise, a unicode ellipsis is used ("…") + * + * In other words: you'll get a unicode ellipsis as soon as either the string contains non-ASCII characters or + * the current locale is UTF-8. + */ + assert(s); assert(percent <= 100); if (new_length == (size_t) -1) return strndup(s, old_length); - assert(new_length >= 3); + if (new_length == 0) + return strdup(""); - /* if no multibyte characters use ascii_ellipsize_mem for speed */ + /* If no multibyte characters use ascii_ellipsize_mem for speed */ if (ascii_is_valid(s)) return ascii_ellipsize_mem(s, old_length, new_length, percent); - if (old_length <= 3 || old_length <= new_length) - return strndup(s, old_length); - - x = (new_length * percent) / 100; - - if (x > new_length - 3) - x = new_length - 3; + x = ((new_length - 1) * percent) / 100; + assert(x <= new_length - 1); k = 0; for (i = s; k < x && i < s + old_length; i = utf8_next_char(i)) { @@ -570,7 +601,7 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne */ memcpy(e, s, len); - e[len] = 0xe2; /* tri-dot ellipsis: … */ + e[len + 0] = 0xe2; /* tri-dot ellipsis: … */ e[len + 1] = 0x80; e[len + 2] = 0xa6; @@ -670,7 +701,8 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) { enum { STATE_OTHER, STATE_ESCAPE, - STATE_BRACKET + STATE_CSI, + STATE_CSO, } state = STATE_OTHER; char *obuf = NULL; size_t osz = 0, isz, shift[2] = {}; @@ -679,7 +711,17 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) { assert(ibuf); assert(*ibuf); - /* Strips ANSI color and replaces TABs by 8 spaces */ + /* This does three things: + * + * 1. Replaces TABs by 8 spaces + * 2. Strips ANSI color sequences (a subset of CSI), i.e. ESC '[' … 'm' sequences + * 3. Strips ANSI operating system sequences (CSO), i.e. ESC ']' … BEL sequences + * + * Everything else will be left as it is. In particular other ANSI sequences are left as they are, as are any + * other special characters. Truncated ANSI sequences are left-as is too. This call is supposed to suppress the + * most basic formatting noise, but nothing else. + * + * Why care for CSO sequences? Well, to undo what terminal_urlify() and friends generate. */ isz = _isz ? *_isz : strlen(*ibuf); @@ -714,8 +756,11 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) { fputc('\x1B', f); advance_offsets(i - *ibuf, highlight, shift, 1); break; - } else if (*i == '[') { - state = STATE_BRACKET; + } else if (*i == '[') { /* ANSI CSI */ + state = STATE_CSI; + begin = i + 1; + } else if (*i == ']') { /* ANSI CSO */ + state = STATE_CSO; begin = i + 1; } else { fputc('\x1B', f); @@ -726,10 +771,10 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) { break; - case STATE_BRACKET: + case STATE_CSI: - if (i >= *ibuf + isz || /* EOT */ - (!(*i >= '0' && *i <= '9') && !IN_SET(*i, ';', 'm'))) { + if (i >= *ibuf + isz || /* EOT … */ + !strchr("01234567890;m", *i)) { /* … or invalid chars in sequence */ fputc('\x1B', f); fputc('[', f); advance_offsets(i - *ibuf, highlight, shift, 2); @@ -737,11 +782,26 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) { i = begin-1; } else if (*i == 'm') state = STATE_OTHER; + + break; + + case STATE_CSO: + + if (i >= *ibuf + isz || /* EOT … */ + (*i != '\a' && (uint8_t) *i < 32U) || (uint8_t) *i > 126U) { /* … or invalid chars in sequence */ + fputc('\x1B', f); + fputc(']', f); + advance_offsets(i - *ibuf, highlight, shift, 2); + state = STATE_OTHER; + i = begin-1; + } else if (*i == '\a') + state = STATE_OTHER; + break; } } - if (ferror(f)) { + if (fflush_and_check(f) < 0) { fclose(f); return mfree(obuf); } diff --git a/src/systemd/src/basic/string-util.h b/src/systemd/src/basic/string-util.h index 08eda4fc..5a10eeab 100644 --- a/src/systemd/src/basic/string-util.h +++ b/src/systemd/src/basic/string-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <alloca.h> @@ -71,7 +58,7 @@ static inline const char *empty_to_null(const char *p) { return isempty(p) ? NULL : p; } -static inline const char *strdash_if_empty(const char *str) { +static inline const char *empty_to_dash(const char *str) { return isempty(str) ? "-" : str; } @@ -122,7 +109,7 @@ char *strjoin_real(const char *x, ...) _sentinel_; const char *_appendees_[] = { a, __VA_ARGS__ }; \ char *_d_, *_p_; \ size_t _len_ = 0; \ - unsigned _i_; \ + size_t _i_; \ for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \ _len_ += strlen(_appendees_[_i_]); \ _p_ = _d_ = alloca(_len_ + 1); \ diff --git a/src/systemd/src/basic/strv.c b/src/systemd/src/basic/strv.c index dee5bbd7..9d5000aa 100644 --- a/src/systemd/src/basic/strv.c +++ b/src/systemd/src/basic/strv.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -122,8 +109,8 @@ char **strv_copy(char * const *l) { return r; } -unsigned strv_length(char * const *l) { - unsigned n = 0; +size_t strv_length(char * const *l) { + size_t n = 0; if (!l) return 0; @@ -136,8 +123,8 @@ unsigned strv_length(char * const *l) { char **strv_new_ap(const char *x, va_list ap) { const char *s; - char **a; - unsigned n = 0, i = 0; + _cleanup_strv_free_ char **a = NULL; + size_t n = 0, i = 0; va_list aq; /* As a special trick we ignore all listed strings that equal @@ -167,7 +154,7 @@ char **strv_new_ap(const char *x, va_list ap) { if (x != STRV_IGNORE) { a[i] = strdup(x); if (!a[i]) - goto fail; + return NULL; i++; } @@ -178,7 +165,7 @@ char **strv_new_ap(const char *x, va_list ap) { a[i] = strdup(s); if (!a[i]) - goto fail; + return NULL; i++; } @@ -186,11 +173,7 @@ char **strv_new_ap(const char *x, va_list ap) { a[i] = NULL; - return a; - -fail: - strv_free(a); - return NULL; + return TAKE_PTR(a); } char **strv_new(const char *x, ...) { @@ -272,7 +255,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) { char **strv_split(const char *s, const char *separator) { const char *word, *state; size_t l; - unsigned n, i; + size_t n, i; char **r; assert(s); @@ -302,7 +285,7 @@ char **strv_split(const char *s, const char *separator) { char **strv_split_newlines(const char *s) { char **l; - unsigned n; + size_t n; assert(s); @@ -397,7 +380,7 @@ char *strv_join(char **l, const char *separator) { int strv_push(char ***l, char *value) { char **c; - unsigned n, m; + size_t n, m; if (!value) return 0; @@ -422,7 +405,7 @@ int strv_push(char ***l, char *value) { int strv_push_pair(char ***l, char *a, char *b) { char **c; - unsigned n, m; + size_t n, m; if (!a && !b) return 0; @@ -448,9 +431,9 @@ int strv_push_pair(char ***l, char *a, char *b) { return 0; } -int strv_insert(char ***l, unsigned position, char *value) { +int strv_insert(char ***l, size_t position, char *value) { char **c; - unsigned n, m, i; + size_t n, m, i; if (!value) return 0; @@ -618,7 +601,7 @@ char **strv_parse_nulstr(const char *s, size_t l) { */ const char *p; - unsigned c = 0, i = 0; + size_t c = 0, i = 0; char **v; assert(s || l <= 0); @@ -782,7 +765,7 @@ int strv_extendf(char ***l, const char *format, ...) { } char **strv_reverse(char **l) { - unsigned n, i; + size_t n, i; n = strv_length(l); if (n <= 1) diff --git a/src/systemd/src/basic/strv.h b/src/systemd/src/basic/strv.h index f169ac5d..958c5f3a 100644 --- a/src/systemd/src/basic/strv.h +++ b/src/systemd/src/basic/strv.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <fnmatch.h> @@ -45,7 +32,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase); void strv_clear(char **l); char **strv_copy(char * const *l); -unsigned strv_length(char * const *l) _pure_; +size_t strv_length(char * const *l) _pure_; int strv_extend_strv(char ***a, char **b, bool filter_duplicates); int strv_extend_strv_concat(char ***a, char **b, const char *suffix); @@ -54,7 +41,7 @@ int strv_extendf(char ***l, const char *format, ...) _printf_(2,0); int strv_extend_front(char ***l, const char *value); int strv_push(char ***l, char *value); int strv_push_pair(char ***l, char *a, char *b); -int strv_insert(char ***l, unsigned position, char *value); +int strv_insert(char ***l, size_t position, char *value); static inline int strv_push_prepend(char ***l, char *value) { return strv_insert(l, 0, value); @@ -126,7 +113,7 @@ void strv_print(char **l); if (!first) \ _l = (char**) &first; \ else { \ - unsigned _n; \ + size_t _n; \ va_list _ap; \ \ _n = 1; \ diff --git a/src/systemd/src/basic/time-util.c b/src/systemd/src/basic/time-util.c index 95fbbd91..fa9f66f2 100644 --- a/src/systemd/src/basic/time-util.c +++ b/src/systemd/src/basic/time-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -36,11 +23,13 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "io-util.h" #include "log.h" #include "macro.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" +#include "stat-util.h" #include "string-util.h" #include "strv.h" #include "time-util.h" @@ -451,7 +440,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { { "us", 1 }, }; - unsigned i; + size_t i; char *p = buf; bool something = false; @@ -630,10 +619,9 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { time_t x; usec_t x_usec, plus = 0, minus = 0, ret; int r, weekday = -1, dst = -1; - unsigned i; + size_t i; - /* - * Allowed syntaxes: + /* Allowed syntaxes: * * 2012-09-22 16:34:22 * 2012-09-22 16:34 (seconds will be set to 0) @@ -647,7 +635,6 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { * +5min * -5days * @2147483647 (seconds since epoch) - * */ assert(t); @@ -706,10 +693,10 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { tzset(); /* See if the timestamp is suffixed by either the DST or non-DST local timezone. Note that we only - * support the local timezones here, nothing else. Not because we wouldn't want to, but simply because - * there are no nice APIs available to cover this. By accepting the local time zone strings, we make - * sure that all timestamps written by format_timestamp() can be parsed correctly, even though we don't - * support arbitrary timezone specifications. */ + * support the local timezones here, nothing else. Not because we wouldn't want to, but simply because + * there are no nice APIs available to cover this. By accepting the local time zone strings, we make + * sure that all timestamps written by format_timestamp() can be parsed correctly, even though we don't + * support arbitrary timezone specifications. */ for (j = 0; j <= 1; j++) { @@ -895,7 +882,7 @@ int parse_timestamp(const char *t, usec_t *usec) { int r; last_space = strrchr(t, ' '); - if (last_space != NULL && timezone_is_valid(last_space + 1)) + if (last_space != NULL && timezone_is_valid(last_space + 1, LOG_DEBUG)) tz = last_space + 1; if (!tz || endswith_no_case(t, " UTC")) @@ -921,10 +908,10 @@ int parse_timestamp(const char *t, usec_t *usec) { tzset(); /* If there is a timezone that matches the tzname fields, leave the parsing to the implementation. - * Otherwise just cut it off */ + * Otherwise just cut it off. */ with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]); - /*cut off the timezone if we dont need it*/ + /* Cut off the timezone if we dont need it. */ if (with_tz) t = strndupa(t, last_space - t); @@ -978,7 +965,7 @@ static char* extract_multiplier(char *p, usec_t *multiplier) { { "us", 1ULL }, { "µs", 1ULL }, }; - unsigned i; + size_t i; for (i = 0; i < ELEMENTSOF(table); i++) { char *e; @@ -1152,8 +1139,8 @@ int parse_nsec(const char *t, nsec_t *nsec) { for (;;) { long long l, z = 0; + size_t n = 0, i; char *e; - unsigned i, n = 0; p += strspn(p, WHITESPACE); @@ -1288,17 +1275,18 @@ int get_timezones(char ***ret) { } else if (errno != ENOENT) return -errno; - *ret = zones; - zones = NULL; + *ret = TAKE_PTR(zones); return 0; } #endif /* NM_IGNORED */ -bool timezone_is_valid(const char *name) { +bool timezone_is_valid(const char *name, int log_level) { bool slash = false; const char *p, *t; - struct stat st; + _cleanup_close_ int fd = -1; + char buf[4]; + int r; if (isempty(name)) return false; @@ -1327,11 +1315,30 @@ bool timezone_is_valid(const char *name) { return false; t = strjoina("/usr/share/zoneinfo/", name); - if (stat(t, &st) < 0) + + fd = open(t, O_RDONLY|O_CLOEXEC); + if (fd < 0) { + log_full_errno(log_level, errno, "Failed to open timezone file '%s': %m", t); + return false; + } + + r = fd_verify_regular(fd); + if (r < 0) { + log_full_errno(log_level, r, "Timezone file '%s' is not a regular file: %m", t); + return false; + } + + r = loop_read_exact(fd, buf, 4, false); + if (r < 0) { + log_full_errno(log_level, r, "Failed to read from timezone file '%s': %m", t); return false; + } - if (!S_ISREG(st.st_mode)) + /* Magic from tzfile(5) */ + if (memcmp(buf, "TZif", 4) != 0) { + log_full(log_level, "Timezone file '%s' has wrong magic bytes", t); return false; + } return true; } @@ -1403,7 +1410,7 @@ int get_timezone(char **tz) { if (!e) return -EINVAL; - if (!timezone_is_valid(e)) + if (!timezone_is_valid(e, LOG_DEBUG)) return -EINVAL; z = strdup(e); diff --git a/src/systemd/src/basic/time-util.h b/src/systemd/src/basic/time-util.h index a8c5a837..e720688c 100644 --- a/src/systemd/src/basic/time-util.h +++ b/src/systemd/src/basic/time-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <inttypes.h> @@ -141,7 +128,7 @@ int parse_nsec(const char *t, nsec_t *nsec); bool ntp_synced(void); int get_timezones(char ***l); -bool timezone_is_valid(const char *name); +bool timezone_is_valid(const char *name, int log_level); bool clock_boottime_supported(void); bool clock_supported(clockid_t clock); diff --git a/src/systemd/src/basic/umask-util.h b/src/systemd/src/basic/umask-util.h index 638b37d7..ce705247 100644 --- a/src/systemd/src/basic/umask-util.h +++ b/src/systemd/src/basic/umask-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> diff --git a/src/systemd/src/basic/utf8.c b/src/systemd/src/basic/utf8.c index c88eef38..7a382204 100644 --- a/src/systemd/src/basic/utf8.c +++ b/src/systemd/src/basic/utf8.c @@ -4,19 +4,6 @@ Copyright 2008-2011 Kay Sievers Copyright 2012 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ /* Parts of this file are based on the GLIB utf8 validation functions. The @@ -50,6 +37,7 @@ #include <string.h> #include "alloc-util.h" +#include "gunicode.h" #include "hexdecoct.h" #include "macro.h" #include "utf8.h" @@ -429,3 +417,25 @@ size_t utf8_n_codepoints(const char *str) { return n; } + +#if 0 /* NM_IGNORED */ +size_t utf8_console_width(const char *str) { + size_t n = 0; + + /* Returns the approximate width a string will take on screen when printed on a character cell + * terminal/console. */ + + while (*str != 0) { + char32_t c; + + if (utf8_encoded_to_unichar(str, &c) < 0) + return (size_t) -1; + + str = utf8_next_char(str); + + n += unichar_iswide(c) ? 2 : 1; + } + + return n; +} +#endif /* NM_IGNORED */ diff --git a/src/systemd/src/basic/utf8.h b/src/systemd/src/basic/utf8.h index c5243c24..0ebe36d9 100644 --- a/src/systemd/src/basic/utf8.h +++ b/src/systemd/src/basic/utf8.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2012 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> @@ -63,3 +50,4 @@ static inline char32_t utf16_surrogate_pair_to_unichar(char16_t lead, char16_t t } size_t utf8_n_codepoints(const char *str); +size_t utf8_console_width(const char *str); diff --git a/src/systemd/src/basic/util.c b/src/systemd/src/basic/util.c index d8c9e82d..12e2f451 100644 --- a/src/systemd/src/basic/util.c +++ b/src/systemd/src/basic/util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/basic/util.h b/src/systemd/src/basic/util.h index 19e9eae1..ad1931f7 100644 --- a/src/systemd/src/basic/util.h +++ b/src/systemd/src/basic/util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <alloca.h> @@ -116,6 +103,22 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_ qsort(base, nmemb, size, compar); } +/* A wrapper around the above, but that adds typesafety: the element size is automatically derived from the type and so + * is the prototype for the comparison function */ +#define typesafe_qsort(p, n, func) \ + ({ \ + int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \ + qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \ + }) + +static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void *userdata) { + if (nmemb <= 1) + return; + + assert(base); + qsort_r(base, nmemb, size, compar, userdata); +} + /** * Normal memcpy requires src to be nonnull. We do nothing if n is 0. */ diff --git a/src/systemd/src/libsystemd-network/arp-util.c b/src/systemd/src/libsystemd-network/arp-util.c index 9b721ee6..26db7ea8 100644 --- a/src/systemd/src/libsystemd-network/arp-util.c +++ b/src/systemd/src/libsystemd-network/arp-util.c @@ -4,19 +4,6 @@ Copyright (C) 2014 Axis Communications AB. All rights reserved. Copyright (C) 2015 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd-network/arp-util.h b/src/systemd/src/libsystemd-network/arp-util.h index decfce3f..86864e9f 100644 --- a/src/systemd/src/libsystemd-network/arp-util.h +++ b/src/systemd/src/libsystemd-network/arp-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright (C) 2014 Axis Communications AB. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <netinet/if_ether.h> diff --git a/src/systemd/src/libsystemd-network/dhcp-identifier.c b/src/systemd/src/libsystemd-network/dhcp-identifier.c index df4d8afb..6f8adfa6 100644 --- a/src/systemd/src/libsystemd-network/dhcp-identifier.c +++ b/src/systemd/src/libsystemd-network/dhcp-identifier.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2015 Tom Gundersen <teg@jklmen> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -99,7 +86,7 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i #if 0 /* NM_IGNORED */ /* name is a pointer to memory in the udev_device struct, so must have the same scope */ - _cleanup_udev_device_unref_ struct udev_device *device = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *device = NULL; #else /* NM_IGNORED */ char name_buf[IF_NAMESIZE]; #endif /* NM_IGNORED */ @@ -109,7 +96,7 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i #if 0 /* NM_IGNORED */ if (detect_container() <= 0) { /* not in a container, udev will be around */ - _cleanup_udev_unref_ struct udev *udev; + _cleanup_(udev_unrefp) struct udev *udev; char ifindex_str[2 + DECIMAL_STR_MAX(int)]; udev = udev_new(); diff --git a/src/systemd/src/libsystemd-network/dhcp-identifier.h b/src/systemd/src/libsystemd-network/dhcp-identifier.h index 0ccee7a7..c0a10b6c 100644 --- a/src/systemd/src/libsystemd-network/dhcp-identifier.h +++ b/src/systemd/src/libsystemd-network/dhcp-identifier.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright (C) 2015 Tom Gundersen <teg@jklmen> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "sd-id128.h" diff --git a/src/systemd/src/libsystemd-network/dhcp-internal.h b/src/systemd/src/libsystemd-network/dhcp-internal.h index a5352695..f8276222 100644 --- a/src/systemd/src/libsystemd-network/dhcp-internal.h +++ b/src/systemd/src/libsystemd-network/dhcp-internal.h @@ -6,19 +6,6 @@ Copyright (C) 2013 Intel Corporation. All rights reserved. Copyright (C) 2014 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <linux/if_packet.h> diff --git a/src/systemd/src/libsystemd-network/dhcp-lease-internal.h b/src/systemd/src/libsystemd-network/dhcp-lease-internal.h index 65c182f4..66c213e2 100644 --- a/src/systemd/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/systemd/src/libsystemd-network/dhcp-lease-internal.h @@ -6,19 +6,6 @@ Copyright (C) 2013 Intel Corporation. All rights reserved. Copyright (C) 2014 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdint.h> diff --git a/src/systemd/src/libsystemd-network/dhcp-network.c b/src/systemd/src/libsystemd-network/dhcp-network.c index d9067ffb..37c1ba19 100644 --- a/src/systemd/src/libsystemd-network/dhcp-network.c +++ b/src/systemd/src/libsystemd-network/dhcp-network.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2013 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd-network/dhcp-option.c b/src/systemd/src/libsystemd-network/dhcp-option.c index 08ed8a9f..86e67358 100644 --- a/src/systemd/src/libsystemd-network/dhcp-option.c +++ b/src/systemd/src/libsystemd-network/dhcp-option.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2013 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -27,6 +14,7 @@ #include "alloc-util.h" #include "utf8.h" +#include "strv.h" #include "dhcp-internal.h" @@ -50,6 +38,34 @@ static int option_append(uint8_t options[], size_t size, size_t *offset, *offset += 1; break; + case SD_DHCP_OPTION_USER_CLASS: { + size_t len = 0; + char **s; + + STRV_FOREACH(s, (char **) optval) + len += strlen(*s) + 1; + + if (size < *offset + len + 2) + return -ENOBUFS; + + options[*offset] = code; + options[*offset + 1] = len; + *offset += 2; + + STRV_FOREACH(s, (char **) optval) { + len = strlen(*s); + + if (len > 255) + return -ENAMETOOLONG; + + options[*offset] = len; + + memcpy_safe(&options[*offset + 1], *s, len); + *offset += len + 1; + } + + break; + } default: if (size < *offset + optlen + 2) return -ENOBUFS; diff --git a/src/systemd/src/libsystemd-network/dhcp-packet.c b/src/systemd/src/libsystemd-network/dhcp-packet.c index 6d8f01f2..136bab9d 100644 --- a/src/systemd/src/libsystemd-network/dhcp-packet.c +++ b/src/systemd/src/libsystemd-network/dhcp-packet.c @@ -4,19 +4,6 @@ Copyright (C) 2013 Intel Corporation. All rights reserved. Copyright (C) 2014 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd-network/dhcp-protocol.h b/src/systemd/src/libsystemd-network/dhcp-protocol.h index 73a9f75e..2230e094 100644 --- a/src/systemd/src/libsystemd-network/dhcp-protocol.h +++ b/src/systemd/src/libsystemd-network/dhcp-protocol.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright (C) 2013 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <netinet/ip.h> diff --git a/src/systemd/src/libsystemd-network/dhcp6-internal.h b/src/systemd/src/libsystemd-network/dhcp6-internal.h index 13844a86..33c43320 100644 --- a/src/systemd/src/libsystemd-network/dhcp6-internal.h +++ b/src/systemd/src/libsystemd-network/dhcp6-internal.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright (C) 2014-2015 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <net/ethernet.h> diff --git a/src/systemd/src/libsystemd-network/dhcp6-lease-internal.h b/src/systemd/src/libsystemd-network/dhcp6-lease-internal.h index 45e0e824..2bf54997 100644 --- a/src/systemd/src/libsystemd-network/dhcp6-lease-internal.h +++ b/src/systemd/src/libsystemd-network/dhcp6-lease-internal.h @@ -6,19 +6,6 @@ Copyright (C) 2014 Tom Gundersen Copyright (C) 2014-2015 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdint.h> diff --git a/src/systemd/src/libsystemd-network/dhcp6-network.c b/src/systemd/src/libsystemd-network/dhcp6-network.c index 85231084..2c6dc713 100644 --- a/src/systemd/src/libsystemd-network/dhcp6-network.c +++ b/src/systemd/src/libsystemd-network/dhcp6-network.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2014 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd-network/dhcp6-option.c b/src/systemd/src/libsystemd-network/dhcp6-option.c index d449a9c7..87ae96a2 100644 --- a/src/systemd/src/libsystemd-network/dhcp6-option.c +++ b/src/systemd/src/libsystemd-network/dhcp6-option.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2014-2015 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd-network/dhcp6-protocol.h b/src/systemd/src/libsystemd-network/dhcp6-protocol.h index 5f7e809b..18417062 100644 --- a/src/systemd/src/libsystemd-network/dhcp6-protocol.h +++ b/src/systemd/src/libsystemd-network/dhcp6-protocol.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright (C) 2014 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <netinet/ip6.h> diff --git a/src/systemd/src/libsystemd-network/lldp-internal.h b/src/systemd/src/libsystemd-network/lldp-internal.h index 2673aa1c..06cf7e8d 100644 --- a/src/systemd/src/libsystemd-network/lldp-internal.h +++ b/src/systemd/src/libsystemd-network/lldp-internal.h @@ -6,19 +6,6 @@ Copyright (C) 2014 Tom Gundersen Copyright (C) 2014 Susant Sahani - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "sd-event.h" diff --git a/src/systemd/src/libsystemd-network/lldp-neighbor.c b/src/systemd/src/libsystemd-network/lldp-neighbor.c index cffbfb98..373e34c8 100644 --- a/src/systemd/src/libsystemd-network/lldp-neighbor.c +++ b/src/systemd/src/libsystemd-network/lldp-neighbor.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2016 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -343,7 +330,6 @@ int lldp_neighbor_parse(sd_lldp_neighbor *n) { break; } - p += length, left -= length; } @@ -676,8 +662,7 @@ _public_ int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw, if (r < 0) return r; - *ret = n; - n = NULL; + *ret = TAKE_PTR(n); return r; } diff --git a/src/systemd/src/libsystemd-network/lldp-neighbor.h b/src/systemd/src/libsystemd-network/lldp-neighbor.h index 76d4c0c7..fae49c59 100644 --- a/src/systemd/src/libsystemd-network/lldp-neighbor.h +++ b/src/systemd/src/libsystemd-network/lldp-neighbor.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2016 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <inttypes.h> diff --git a/src/systemd/src/libsystemd-network/lldp-network.c b/src/systemd/src/libsystemd-network/lldp-network.c index b8a10d54..307cf6c3 100644 --- a/src/systemd/src/libsystemd-network/lldp-network.c +++ b/src/systemd/src/libsystemd-network/lldp-network.c @@ -4,19 +4,6 @@ Copyright (C) 2014 Tom Gundersen Copyright (C) 2014 Susant Sahani - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd-network/lldp-network.h b/src/systemd/src/libsystemd-network/lldp-network.h index c0f8cbe1..7a1e8b10 100644 --- a/src/systemd/src/libsystemd-network/lldp-network.h +++ b/src/systemd/src/libsystemd-network/lldp-network.h @@ -6,19 +6,6 @@ Copyright (C) 2014 Tom Gundersen Copyright (C) 2014 Susant Sahani - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "sd-event.h" diff --git a/src/systemd/src/libsystemd-network/network-internal.c b/src/systemd/src/libsystemd-network/network-internal.c index a8a5658b..e05f52d4 100644 --- a/src/systemd/src/libsystemd-network/network-internal.c +++ b/src/systemd/src/libsystemd-network/network-internal.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2013 Tom Gundersen <teg@jklm.no> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -99,7 +86,7 @@ static bool net_condition_test_strv(char * const *raw_patterns, /* If the patterns begin with "!", edit it out and negate the test. */ if (raw_patterns[0][0] == '!') { char **patterns; - unsigned i, length; + size_t i, length; length = strv_length(raw_patterns) + 1; /* Include the NULL. */ patterns = newa(char*, length); @@ -113,7 +100,7 @@ static bool net_condition_test_strv(char * const *raw_patterns, return string && strv_fnmatch(raw_patterns, string, 0); } -bool net_match_config(const struct ether_addr *match_mac, +bool net_match_config(Set *match_mac, char * const *match_paths, char * const *match_drivers, char * const *match_types, @@ -145,7 +132,7 @@ bool net_match_config(const struct ether_addr *match_mac, if (match_arch && condition_test(match_arch) <= 0) return false; - if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN))) + if (match_mac && dev_mac && !set_contains(match_mac, dev_mac)) return false; if (!net_condition_test_strv(match_paths, dev_path)) @@ -297,10 +284,9 @@ int config_parse_hwaddr(const char *unit, const char *rvalue, void *data, void *userdata) { + + _cleanup_free_ struct ether_addr *n = NULL; struct ether_addr **hwaddr = data; - struct ether_addr *n; - const char *start; - size_t offset; int r; assert(filename); @@ -312,17 +298,86 @@ int config_parse_hwaddr(const char *unit, if (!n) return log_oom(); - start = rvalue + strspn(rvalue, WHITESPACE); - r = ether_addr_from_string(start, n, &offset); + r = ether_addr_from_string(rvalue, n); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Not a valid MAC address, ignoring assignment: %s", rvalue); + return 0; + } + + *hwaddr = TAKE_PTR(n); + + return 0; +} + +int config_parse_hwaddrs(const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + _cleanup_set_free_free_ Set *s = NULL; + const char *p = rvalue; + Set **hwaddrs = data; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); - if (r || (start[offset + strspn(start + offset, WHITESPACE)] != '\0')) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue); - free(n); + if (isempty(rvalue)) { + /* Empty assignment resets the list */ + *hwaddrs = set_free_free(*hwaddrs); return 0; } - free(*hwaddr); - *hwaddr = n; + s = set_new(ðer_addr_hash_ops); + if (!s) + return log_oom(); + + for (;;) { + _cleanup_free_ char *word = NULL; + _cleanup_free_ struct ether_addr *n = NULL; + + r = extract_first_word(&p, &word, NULL, 0); + if (r == 0) + break; + if (r == -ENOMEM) + return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); + return 0; + } + + n = new(struct ether_addr, 1); + if (!n) + return log_oom(); + + r = ether_addr_from_string(word, n); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring: %s", word); + continue; + } + + r = set_put(s, n); + if (r < 0) + return log_oom(); + if (r > 0) + n = NULL; /* avoid cleanup */ + } + + r = set_ensure_allocated(hwaddrs, ðer_addr_hash_ops); + if (r < 0) + return log_oom(); + + r = set_move(*hwaddrs, s); + if (r < 0) + return log_oom(); return 0; } @@ -396,7 +451,6 @@ int config_parse_bridge_port_priority( } #endif /* NM_IGNORED */ - void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) { unsigned i; @@ -606,14 +660,3 @@ int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t siz return 0; } - -int deserialize_dhcp_option(void **data, size_t *data_len, const char *string) { - assert(data); - assert(data_len); - assert(string); - - if (strlen(string) % 2) - return -EINVAL; - - return unhexmem(string, strlen(string), (void **)data, data_len); -} diff --git a/src/systemd/src/libsystemd-network/network-internal.h b/src/systemd/src/libsystemd-network/network-internal.h index 4e69f1a5..d0076f45 100644 --- a/src/systemd/src/libsystemd-network/network-internal.h +++ b/src/systemd/src/libsystemd-network/network-internal.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright (C) 2013 Tom Gundersen <teg@jklm.no> - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> @@ -25,12 +12,13 @@ #include "sd-dhcp-lease.h" #include "condition.h" +#include "set.h" #include "udev.h" #define LINK_BRIDGE_PORT_PRIORITY_INVALID 128 #define LINK_BRIDGE_PORT_PRIORITY_MAX 63 -bool net_match_config(const struct ether_addr *match_mac, +bool net_match_config(Set *match_mac, char * const *match_path, char * const *match_driver, char * const *match_type, @@ -55,6 +43,10 @@ int config_parse_hwaddr(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_hwaddrs(const char *unit, const char *filename, unsigned line, + const char *section, unsigned section_line, const char *lvalue, + int ltype, const char *rvalue, void *data, void *userdata); + int config_parse_ifnames(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); @@ -86,5 +78,5 @@ struct sd_dhcp_route; void serialize_dhcp_routes(FILE *f, const char *key, sd_dhcp_route **routes, size_t size); int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t *ret_allocated, const char *string); +/* It is not necessary to add deserialize_dhcp_option(). Use unhexmem() instead. */ int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t size); -int deserialize_dhcp_option(void **data, size_t *data_len, const char *string); diff --git a/src/systemd/src/libsystemd-network/sd-dhcp-client.c b/src/systemd/src/libsystemd-network/sd-dhcp-client.c index b93b7334..ef2620f4 100644 --- a/src/systemd/src/libsystemd-network/sd-dhcp-client.c +++ b/src/systemd/src/libsystemd-network/sd-dhcp-client.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2013 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -42,6 +29,7 @@ #include "random-util.h" #include "string-util.h" #include "util.h" +#include "strv.h" #define MAX_CLIENT_ID_LEN (sizeof(uint32_t) + MAX_DUID_LEN) /* Arbitrary limit */ #define MAX_MAC_ADDR_LEN CONST_MAX(INFINIBAND_ALEN, ETH_ALEN) @@ -98,6 +86,7 @@ struct sd_dhcp_client { size_t client_id_len; char *hostname; char *vendor_class_identifier; + char **user_class; uint32_t mtu; uint32_t xid; usec_t start_time; @@ -458,6 +447,26 @@ int sd_dhcp_client_set_vendor_class_identifier( return free_and_strdup(&client->vendor_class_identifier, vci); } +int sd_dhcp_client_set_user_class( + sd_dhcp_client *client, + const char* const* user_class) { + + _cleanup_strv_free_ char **s = NULL; + char **p; + + STRV_FOREACH(p, (char **) user_class) + if (strlen(*p) > 255) + return -ENAMETOOLONG; + + s = strv_copy((char **) user_class); + if (!s) + return -ENOMEM; + + client->user_class = TAKE_PTR(s); + + return 0; +} + int sd_dhcp_client_set_client_port( sd_dhcp_client *client, uint16_t port) { @@ -687,8 +696,7 @@ static int client_message_init( *_optlen = optlen; *_optoffset = optoffset; - *ret = packet; - packet = NULL; + *ret = TAKE_PTR(packet); return 0; } @@ -782,6 +790,15 @@ static int client_send_discover(sd_dhcp_client *client) { return r; } + if (client->user_class) { + r = dhcp_option_append(&discover->dhcp, optlen, &optoffset, 0, + SD_DHCP_OPTION_USER_CLASS, + strv_length(client->user_class), + client->user_class); + if (r < 0) + return r; + } + r = dhcp_option_append(&discover->dhcp, optlen, &optoffset, 0, SD_DHCP_OPTION_END, 0, NULL); if (r < 0) @@ -1293,8 +1310,7 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer, size_ } sd_dhcp_lease_unref(client->lease); - client->lease = lease; - lease = NULL; + client->lease = TAKE_PTR(lease); log_dhcp_client(client, "OFFER"); @@ -1375,8 +1391,7 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack, size_t le client->lease = sd_dhcp_lease_unref(client->lease); } - client->lease = lease; - lease = NULL; + client->lease = TAKE_PTR(lease); log_dhcp_client(client, "ACK"); @@ -1939,6 +1954,7 @@ sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client) { free(client->req_opts); free(client->hostname); free(client->vendor_class_identifier); + client->user_class = strv_free(client->user_class); return mfree(client); } @@ -1971,8 +1987,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) { if (!client->req_opts) return -ENOMEM; - *ret = client; - client = NULL; + *ret = TAKE_PTR(client); return 0; } diff --git a/src/systemd/src/libsystemd-network/sd-dhcp-lease.c b/src/systemd/src/libsystemd-network/sd-dhcp-lease.c index c272a61e..d92c5126 100644 --- a/src/systemd/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/systemd/src/libsystemd-network/sd-dhcp-lease.c @@ -4,19 +4,6 @@ Copyright (C) 2013 Intel Corporation. All rights reserved. Copyright (C) 2014 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -236,7 +223,7 @@ int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, sd_dhcp_route ***routes) { } int sd_dhcp_lease_get_search_domains(sd_dhcp_lease *lease, char ***domains) { - unsigned r; + size_t r; assert_return(lease, -EINVAL); assert_return(domains, -EINVAL); @@ -682,7 +669,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void return 0; } - if (!timezone_is_valid(tz)) { + if (!timezone_is_valid(tz, LOG_DEBUG)) { log_debug_errno(r, "Timezone is not valid, ignoring: %m"); return 0; } @@ -1208,13 +1195,13 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { } if (client_id_hex) { - r = deserialize_dhcp_option(&lease->client_id, &lease->client_id_len, client_id_hex); + r = unhexmem(client_id_hex, (size_t) -1, &lease->client_id, &lease->client_id_len); if (r < 0) log_debug_errno(r, "Failed to parse client ID %s, ignoring: %m", client_id_hex); } if (vendor_specific_hex) { - r = deserialize_dhcp_option(&lease->vendor_specific, &lease->vendor_specific_len, vendor_specific_hex); + r = unhexmem(vendor_specific_hex, (size_t) -1, &lease->vendor_specific, &lease->vendor_specific_len); if (r < 0) log_debug_errno(r, "Failed to parse vendor specific data %s, ignoring: %m", vendor_specific_hex); } @@ -1226,7 +1213,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { if (!options[i]) continue; - r = deserialize_dhcp_option(&data, &len, options[i]); + r = unhexmem(options[i], (size_t) -1, &data, &len); if (r < 0) { log_debug_errno(r, "Failed to parse private DHCP option %s, ignoring: %m", options[i]); continue; @@ -1237,8 +1224,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { return r; } - *ret = lease; - lease = NULL; + *ret = TAKE_PTR(lease); return 0; } diff --git a/src/systemd/src/libsystemd-network/sd-dhcp6-client.c b/src/systemd/src/libsystemd-network/sd-dhcp6-client.c index f22daa3c..1cec6022 100644 --- a/src/systemd/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/systemd/src/libsystemd-network/sd-dhcp6-client.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright (C) 2014-2015 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -1470,8 +1457,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) { for (t = 0; t < client->req_opts_len; t++) client->req_opts[t] = htobe16(default_req_opts[t]); - *ret = client; - client = NULL; + *ret = TAKE_PTR(client); return 0; } diff --git a/src/systemd/src/libsystemd-network/sd-dhcp6-lease.c b/src/systemd/src/libsystemd-network/sd-dhcp6-lease.c index 00b9fdf0..3952cd99 100644 --- a/src/systemd/src/libsystemd-network/sd-dhcp6-lease.c +++ b/src/systemd/src/libsystemd-network/sd-dhcp6-lease.c @@ -4,19 +4,6 @@ Copyright (C) 2014 Tom Gundersen Copyright (C) 2014-2015 Intel Corporation. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -263,8 +250,7 @@ int dhcp6_lease_set_domains(sd_dhcp6_lease *lease, uint8_t *optval, if (r < 0) return 0; - strv_free(lease->domains); - lease->domains = domains; + strv_free_and_replace(lease->domains, domains); lease->domains_count = r; return r; @@ -323,8 +309,7 @@ int dhcp6_lease_set_ntp(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) { if (r < 0) return 0; - lease->ntp_fqdn = strv_free(lease->ntp_fqdn); - lease->ntp_fqdn = servers; + strv_free_and_replace(lease->ntp_fqdn, servers); lease->ntp_fqdn_count = r; break; diff --git a/src/systemd/src/libsystemd-network/sd-ipv4acd.c b/src/systemd/src/libsystemd-network/sd-ipv4acd.c index 08f46dd2..ed98c0b6 100644 --- a/src/systemd/src/libsystemd-network/sd-ipv4acd.c +++ b/src/systemd/src/libsystemd-network/sd-ipv4acd.c @@ -4,19 +4,6 @@ Copyright (C) 2014 Axis Communications AB. All rights reserved. Copyright (C) 2015 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -155,8 +142,7 @@ int sd_ipv4acd_new(sd_ipv4acd **ret) { acd->ifindex = -1; acd->fd = -1; - *ret = acd; - acd = NULL; + *ret = TAKE_PTR(acd); return 0; } @@ -209,8 +195,7 @@ static int ipv4acd_set_next_wakeup(sd_ipv4acd *acd, usec_t usec, usec_t random_u (void) sd_event_source_set_description(timer, "ipv4acd-timer"); sd_event_source_unref(acd->timer_event_source); - acd->timer_event_source = timer; - timer = NULL; + acd->timer_event_source = TAKE_PTR(timer); return 0; } diff --git a/src/systemd/src/libsystemd-network/sd-ipv4ll.c b/src/systemd/src/libsystemd-network/sd-ipv4ll.c index f1e7b404..001ebbd8 100644 --- a/src/systemd/src/libsystemd-network/sd-ipv4ll.c +++ b/src/systemd/src/libsystemd-network/sd-ipv4ll.c @@ -4,19 +4,6 @@ Copyright (C) 2014 Axis Communications AB. All rights reserved. Copyright (C) 2015 Tom Gundersen - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -117,8 +104,7 @@ int sd_ipv4ll_new(sd_ipv4ll **ret) { if (r < 0) return r; - *ret = ll; - ll = NULL; + *ret = TAKE_PTR(ll); return 0; } diff --git a/src/systemd/src/libsystemd-network/sd-lldp.c b/src/systemd/src/libsystemd-network/sd-lldp.c index 20956041..d88a0c6f 100644 --- a/src/systemd/src/libsystemd-network/sd-lldp.c +++ b/src/systemd/src/libsystemd-network/sd-lldp.c @@ -4,19 +4,6 @@ Copyright (C) 2014 Tom Gundersen Copyright (C) 2014 Susant Sahani - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -404,8 +391,7 @@ _public_ int sd_lldp_new(sd_lldp **ret) { if (r < 0) return r; - *ret = lldp; - lldp = NULL; + *ret = TAKE_PTR(lldp); return 0; } @@ -418,15 +404,15 @@ static int neighbor_compare_func(const void *a, const void *b) { static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) { sd_lldp *lldp = userdata; - int r, q; + int r; r = lldp_make_space(lldp, 0); if (r < 0) return log_lldp_errno(r, "Failed to make space: %m"); - q = lldp_start_timer(lldp, NULL); - if (q < 0) - return log_lldp_errno(q, "Failed to restart timer: %m"); + r = lldp_start_timer(lldp, NULL); + if (r < 0) + return log_lldp_errno(r, "Failed to restart timer: %m"); return 0; } diff --git a/src/systemd/src/libsystemd/sd-event/sd-event.c b/src/systemd/src/libsystemd/sd-event/sd-event.c index 4fb8ed7f..8a9b8055 100644 --- a/src/systemd/src/libsystemd/sd-event/sd-event.c +++ b/src/systemd/src/libsystemd/sd-event/sd-event.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2013 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -2407,6 +2394,7 @@ static int event_prepare(sd_event *e) { static int dispatch_exit(sd_event *e) { sd_event_source *p; + _cleanup_(sd_event_unrefp) sd_event *ref = NULL; int r; assert(e); @@ -2417,15 +2405,11 @@ static int dispatch_exit(sd_event *e) { return 0; } - sd_event_ref(e); + ref = sd_event_ref(e); e->iteration++; e->state = SD_EVENT_EXITING; - r = source_dispatch(p); - e->state = SD_EVENT_INITIAL; - sd_event_unref(e); - return r; } @@ -2665,14 +2649,12 @@ _public_ int sd_event_dispatch(sd_event *e) { p = event_next_pending(e); if (p) { - sd_event_ref(e); + _cleanup_(sd_event_unrefp) sd_event *ref = NULL; + ref = sd_event_ref(e); e->state = SD_EVENT_RUNNING; r = source_dispatch(p); e->state = SD_EVENT_INITIAL; - - sd_event_unref(e); - return r; } @@ -2739,6 +2721,7 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) { } _public_ int sd_event_loop(sd_event *e) { + _cleanup_(sd_event_unrefp) sd_event *ref = NULL; int r; assert_return(e, -EINVAL); @@ -2746,19 +2729,15 @@ _public_ int sd_event_loop(sd_event *e) { assert_return(!event_pid_changed(e), -ECHILD); assert_return(e->state == SD_EVENT_INITIAL, -EBUSY); - sd_event_ref(e); + ref = sd_event_ref(e); while (e->state != SD_EVENT_FINISHED) { r = sd_event_run(e, (uint64_t) -1); if (r < 0) - goto finish; + return r; } - r = e->exit_code; - -finish: - sd_event_unref(e); - return r; + return e->exit_code; } _public_ int sd_event_get_fd(sd_event *e) { diff --git a/src/systemd/src/libsystemd/sd-id128/id128-util.c b/src/systemd/src/libsystemd/sd-id128/id128-util.c index f1033346..26eef0fd 100644 --- a/src/systemd/src/libsystemd/sd-id128/id128-util.c +++ b/src/systemd/src/libsystemd/sd-id128/id128-util.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2016 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/libsystemd/sd-id128/id128-util.h b/src/systemd/src/libsystemd/sd-id128/id128-util.h index 9f3340e5..9aeb27a2 100644 --- a/src/systemd/src/libsystemd/sd-id128/id128-util.h +++ b/src/systemd/src/libsystemd/sd-id128/id128-util.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2016 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <stdbool.h> diff --git a/src/systemd/src/libsystemd/sd-id128/sd-id128.c b/src/systemd/src/libsystemd/sd-id128/sd-id128.c index e5bd447a..de0ae600 100644 --- a/src/systemd/src/libsystemd/sd-id128/sd-id128.c +++ b/src/systemd/src/libsystemd/sd-id128/sd-id128.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2011 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" diff --git a/src/systemd/src/shared/dns-domain.c b/src/systemd/src/shared/dns-domain.c index cfc1f3b3..3f41be62 100644 --- a/src/systemd/src/shared/dns-domain.c +++ b/src/systemd/src/shared/dns-domain.c @@ -3,19 +3,6 @@ This file is part of systemd. Copyright 2014 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include "nm-sd-adapt.h" @@ -416,10 +403,9 @@ int dns_name_concat(const char *a, const char *b, char **_ret) { if (a) p = a; - else if (b) { - p = b; - b = NULL; - } else + else if (b) + p = TAKE_PTR(b); + else goto finish; for (;;) { @@ -434,8 +420,7 @@ int dns_name_concat(const char *a, const char *b, char **_ret) { if (b) { /* Now continue with the second string, if there is one */ - p = b; - b = NULL; + p = TAKE_PTR(b); continue; } @@ -485,8 +470,7 @@ finish: } ret[n] = 0; - *_ret = ret; - ret = NULL; + *_ret = TAKE_PTR(ret); } return 0; @@ -684,8 +668,8 @@ int dns_name_change_suffix(const char *name, const char *old_suffix, const char /* Not the same, let's jump back, and try with the next label again */ s = old_suffix; - n = saved_after; - saved_after = saved_before = NULL; + n = TAKE_PTR(saved_after); + saved_before = NULL; } } @@ -1122,20 +1106,14 @@ finish: if (r < 0) return r; - if (_domain) { - *_domain = domain; - domain = NULL; - } + if (_domain) + *_domain = TAKE_PTR(domain); - if (_type) { - *_type = type; - type = NULL; - } + if (_type) + *_type = TAKE_PTR(type); - if (_name) { - *_name = name; - name = NULL; - } + if (_name) + *_name = TAKE_PTR(name); return 0; } @@ -1318,8 +1296,8 @@ int dns_name_apply_idna(const char *name, char **ret) { } } - *ret = t; - t = NULL; + *ret = TAKE_PTR(t); + return 1; /* *ret has been written */ } @@ -1376,8 +1354,7 @@ int dns_name_apply_idna(const char *name, char **ret) { return -ENOMEM; buf[n] = 0; - *ret = buf; - buf = NULL; + *ret = TAKE_PTR(buf); return 1; #else diff --git a/src/systemd/src/shared/dns-domain.h b/src/systemd/src/shared/dns-domain.h index 3ebd4018..47bd5357 100644 --- a/src/systemd/src/shared/dns-domain.h +++ b/src/systemd/src/shared/dns-domain.h @@ -5,19 +5,6 @@ This file is part of systemd. Copyright 2014 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ #include <errno.h> diff --git a/src/systemd/src/systemd/sd-dhcp-client.h b/src/systemd/src/systemd/sd-dhcp-client.h index 789cc501..fd0a5693 100644 --- a/src/systemd/src/systemd/sd-dhcp-client.h +++ b/src/systemd/src/systemd/sd-dhcp-client.h @@ -82,6 +82,7 @@ enum { SD_DHCP_OPTION_REBINDING_T2_TIME = 59, SD_DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60, SD_DHCP_OPTION_CLIENT_IDENTIFIER = 61, + SD_DHCP_OPTION_USER_CLASS = 77, SD_DHCP_OPTION_FQDN = 81, SD_DHCP_OPTION_NEW_POSIX_TIMEZONE = 100, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE = 101, @@ -154,6 +155,9 @@ int sd_dhcp_client_set_hostname( int sd_dhcp_client_set_vendor_class_identifier( sd_dhcp_client *client, const char *vci); +int sd_dhcp_client_set_user_class( + sd_dhcp_client *client, + const char* const *user_class); int sd_dhcp_client_get_lease( sd_dhcp_client *client, sd_dhcp_lease **ret); diff --git a/src/tests/config/meson.build b/src/tests/config/meson.build index fb40d9a9..f542c453 100644 --- a/src/tests/config/meson.build +++ b/src/tests/config/meson.build @@ -7,16 +7,11 @@ sources = files( test_config_dir = meson.current_source_dir() -cflags = [ - '-DSRCDIR="@0@"'.format(test_config_dir), - '-DBUILDDIR="@0@"'.format(test_config_dir) -] - exe = executable( test_unit, sources, dependencies: test_nm_dep, - c_args: cflags + c_args: nm_build_cflags, ) test( diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c index 50215756..75fef4fa 100644 --- a/src/tests/config/test-config.c +++ b/src/tests/config/test-config.c @@ -30,6 +30,9 @@ #include "nm-test-utils-core.h" +#define TEST_DIR NM_BUILD_SRCDIR"/src/tests/config" +#define BUILD_DIR NM_BUILD_BUILDDIR"/src/tests/config" + /*****************************************************************************/ static void @@ -133,9 +136,9 @@ test_config_simple (void) gs_unref_object NMDevice *dev51 = nm_test_device_new ("00:00:00:00:00:51"); gs_unref_object NMDevice *dev52 = nm_test_device_new ("00:00:00:00:00:52"); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", NULL); + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", NULL); - g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, SRCDIR "/NetworkManager.conf"); + g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, TEST_DIR "/NetworkManager.conf"); g_assert_cmpstr (_config_get_dhcp_client_a (config), ==, "dhclient"); g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO"); g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 100); @@ -164,12 +167,10 @@ test_config_simple (void) g_assert_cmpstr (value, ==, "51"); g_free (value); - value = nm_config_data_get_connection_default (nm_config_get_data_orig (config), "ipv6.route-metric", NULL); g_assert_cmpstr (value, ==, NULL); g_free (value); - value = nm_config_data_get_connection_default (nm_config_get_data_orig (config), "ipv4.route-metric", NULL); g_assert_cmpstr (value, ==, "50"); g_free (value); @@ -186,7 +187,6 @@ test_config_simple (void) g_assert_cmpstr (value, ==, "52"); g_free (value); - value = nm_config_data_get_connection_default (nm_config_get_data_orig (config), "dummy.test1", dev51); g_assert_cmpstr (value, ==, "yes"); g_free (value); @@ -209,7 +209,7 @@ test_config_non_existent (void) { GError *error = NULL; - setup_config (&error, SRCDIR "/no-such-file", "", NULL, "/no/such/dir", "", NULL); + setup_config (&error, TEST_DIR "/no-such-file", "", NULL, "/no/such/dir", "", NULL); g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND); g_clear_error (&error); } @@ -219,7 +219,7 @@ test_config_parse_error (void) { GError *error = NULL; - setup_config (&error, SRCDIR "/bad.conf", "", NULL, "/no/such/dir", "", NULL); + setup_config (&error, TEST_DIR "/bad.conf", "", NULL, "/no/such/dir", "", NULL); g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE); g_clear_error (&error); } @@ -230,12 +230,12 @@ test_config_override (void) gs_unref_object NMConfig *config = NULL; gs_strfreev char **plugins = NULL; - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", "--plugins", "alpha,beta,gamma,delta", "--connectivity-interval", "12", NULL); - g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, SRCDIR "/NetworkManager.conf"); + g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, TEST_DIR "/NetworkManager.conf"); g_assert_cmpstr (_config_get_dhcp_client_a (config), ==, "dhclient"); g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO"); g_assert_cmpint (nm_config_data_get_connectivity_interval (nm_config_get_data_orig (config)), ==, 12); @@ -256,7 +256,7 @@ test_config_global_dns (void) NMGlobalDnsDomain *domain; const char *const*strv; - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", NULL); dns = nm_config_data_get_global_dns_config (nm_config_get_data_orig (config)); @@ -311,7 +311,7 @@ test_config_global_dns (void) g_object_unref (config); /* Check that a file without a default domain section gives a NULL configuration */ - config = setup_config (NULL, SRCDIR "/global-dns-invalid.conf", "", NULL, + config = setup_config (NULL, TEST_DIR "/global-dns-invalid.conf", "", NULL, "/no/such/dir", "", NULL); dns = nm_config_data_get_global_dns_config (nm_config_get_data_orig (config)); g_assert (!dns); @@ -322,12 +322,12 @@ static void test_config_connectivity_check (void) { #if WITH_CONCHECK - const char *CONFIG_INTERN = BUILDDIR"/test-connectivity-check-intern.conf"; + const char *CONFIG_INTERN = BUILD_DIR"/test-connectivity-check-intern.conf"; NMConfig *config; NMConnectivity *connectivity; g_assert (g_file_set_contents (CONFIG_INTERN, "", 0, NULL)); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", CONFIG_INTERN, NULL, + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", CONFIG_INTERN, NULL, "/no/such/dir", "", NULL); connectivity = nm_connectivity_get(); @@ -374,7 +374,7 @@ test_config_no_auto_default (void) g_assert_cmpint (nwrote, ==, 18); nm_close (fd); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", "--no-auto-default", state_file, NULL); @@ -396,7 +396,7 @@ test_config_no_auto_default (void) g_object_unref (config); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, "/no/such/dir", "", "--no-auto-default", state_file, NULL); @@ -424,9 +424,9 @@ test_config_confdir (void) char *value; GSList *specs; - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", NULL); + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", NULL); - g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, SRCDIR "/NetworkManager.conf"); + g_assert_cmpstr (nm_config_data_get_config_main_file (nm_config_get_data_orig (config)), ==, TEST_DIR "/NetworkManager.conf"); g_assert_cmpstr (_config_get_dhcp_client_a (config), ==, "dhcpcd"); g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO"); g_assert_cmpstr (nm_config_get_log_domains (config), ==, "PLATFORM,DNS,WIFI"); @@ -527,8 +527,8 @@ test_config_confdir_parse_error (void) { GError *error = NULL; - /* Using SRCDIR as the conf dir will pick up bad.conf */ - setup_config (&error, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR, "", NULL); + /* Using TEST_DIR as the conf dir will pick up bad.conf */ + setup_config (&error, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR, "", NULL); g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE); g_clear_error (&error); } @@ -811,8 +811,8 @@ static void test_config_set_values (void) { gs_unref_object NMConfig *config = NULL; - const char *CONFIG_USER = BUILDDIR"/test-set-values-user.conf"; - const char *CONFIG_INTERN = BUILDDIR"/test-set-values-intern.conf"; + const char *CONFIG_USER = BUILD_DIR"/test-set-values-user.conf"; + const char *CONFIG_INTERN = BUILD_DIR"/test-set-values-intern.conf"; const char *atomic_section_prefixes[] = { "atomic-prefix-1.", "atomic-prefix-2.", @@ -896,7 +896,7 @@ test_config_signal (void) NMConfigChangeFlags expected; gs_unref_object NMConfigData *config_data_orig = NULL; - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", NULL); + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", NULL); config_data_orig = g_object_ref (nm_config_get_data_orig (config)); @@ -917,7 +917,6 @@ test_config_signal (void) NMTST_EXPECT_NM_INFO ("config: signal: SIGHUP (no changes from disk)*"); nm_config_reload (config, expected); - /* test with subscribing two signals... * * This test exposes glib bug https://bugzilla.redhat.com/show_bug.cgi?id=1260577 @@ -931,7 +930,6 @@ test_config_signal (void) nm_config_reload (config, NM_CONFIG_CHANGE_CAUSE_SIGUSR2); g_signal_handlers_disconnect_by_func (config, _test_signal_config_changed_cb2, &expected); - g_signal_handlers_disconnect_by_func (config, _test_signal_config_changed_cb, &expected); g_assert (config_data_orig == nm_config_get_data (config)); @@ -950,19 +948,19 @@ test_config_enable (void) _nm_config_match_env = g_strdup ("something-else"); _nm_config_match_nm_version = nm_encode_version (1, 3, 4); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", NULL); + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", NULL); assert_config_value (nm_config_get_data_orig (config), "test-group-config-enable-1", "key1", NULL); g_clear_object (&config); _nm_config_match_nm_version = nm_encode_version (1, 5, 32); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", NULL); + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", NULL); assert_config_value (nm_config_get_data_orig (config), "test-group-config-enable-1", "key1", "enabled"); g_clear_object (&config); _nm_config_match_nm_version = nm_encode_version (1, 5, 3); g_clear_pointer (&_nm_config_match_env, g_free); _nm_config_match_env = g_strdup ("test-match-env-1"); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", NULL); + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", NULL); assert_config_value (nm_config_get_data_orig (config), "test-group-config-enable-1", "key1", "enabled"); g_clear_object (&config); @@ -982,14 +980,14 @@ test_config_state_file (void) gboolean ret; gs_free char *file_data = NULL; gsize file_size; - const char *const TMP_FILE = BUILDDIR "/tmp.state"; + const char *const TMP_FILE = BUILD_DIR "/tmp.state"; - ret = g_file_get_contents (SRCDIR "/NetworkManager.state", &file_data, &file_size, &error); + ret = g_file_get_contents (TEST_DIR "/NetworkManager.state", &file_data, &file_size, &error); nmtst_assert_success (ret, error); ret = g_file_set_contents (TMP_FILE, file_data, file_size, &error); nmtst_assert_success (ret, error); - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", "--state-file", TMP_FILE, NULL); g_assert (config); @@ -1015,7 +1013,7 @@ test_config_state_file (void) g_object_unref (config); /* Reload configuration */ - config = setup_config (NULL, SRCDIR "/NetworkManager.conf", "", NULL, SRCDIR "/conf.d", "", + config = setup_config (NULL, TEST_DIR "/NetworkManager.conf", "", NULL, TEST_DIR "/conf.d", "", "--state-file", TMP_FILE, NULL); g_assert (config); diff --git a/src/tests/meson.build b/src/tests/meson.build index 386ede87..430ffe43 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -33,7 +33,7 @@ cflags = [ exe = executable( test_unit, - [test_unit + '.c'] + shared_siphash, + [test_unit + '.c'], include_directories: src_inc, dependencies: nm_core_dep, c_args: cflags, diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index f67c332b..a78b5311 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -313,7 +313,6 @@ do_test_nm_utils_kill_child (void) NMTST_EXPECT_NM_DEBUG ("kill child process 'test-s-4' (*): after sending SIGTERM (15) and SIGKILL, process * exited by signal 9 (* usec elapsed)"); test_nm_utils_kill_child_sync_do ("test-s-4", pid4s, SIGTERM, 1, TRUE, &expected_signal_KILL); - NMTST_EXPECT_NM_DEBUG ("kill child process 'test-a-1-1' (*): wait for process to terminate after sending SIGTERM (15) (send SIGKILL in 3000 milliseconds)..."); NMTST_EXPECT_NM_DEBUG ("kill child process 'test-a-1-1' (*): terminated by signal 15 (* usec elapsed)"); test_nm_utils_kill_child_async_do ("test-a-1-1", pid1a_1, SIGTERM, 3000, TRUE, &expected_signal_TERM); diff --git a/src/tests/test-general.c b/src/tests/test-general.c index 38eaf25e..4db05ac8 100644 --- a/src/tests/test-general.c +++ b/src/tests/test-general.c @@ -709,7 +709,6 @@ test_connection_no_match_ip4_addr (void) NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - s_ip4 = nm_connection_get_setting_ip4_config (orig); g_assert (s_ip4); g_object_set (G_OBJECT (s_ip4), @@ -1232,7 +1231,6 @@ _do_test_match_spec_config (const char *file, gint line, const char *spec_str, g GSList *specs2 = g_slist_append (NULL, sss); NMMatchSpecMatchType match_result2; - match_result2 = nm_match_spec_config (specs2, version, NULL); if (match_result == NM_MATCH_SPEC_NO_MATCH) g_assert_cmpint (match_result2, ==, NM_MATCH_SPEC_NO_MATCH); @@ -1289,7 +1287,6 @@ test_match_spec_config (void) do_test_match_spec_config ("nm-version-min:1", 1, 3, 30, NM_MATCH_SPEC_MATCH); do_test_match_spec_config ("nm-version-min:1", 1, 4, 30, NM_MATCH_SPEC_MATCH); - do_test_match_spec_config ("nm-version-max:1.2.3", 0, 2, 30, NM_MATCH_SPEC_NO_MATCH); do_test_match_spec_config ("nm-version-max:1.2.3", 1, 1, 1, NM_MATCH_SPEC_NO_MATCH); do_test_match_spec_config ("nm-version-max:1.2.3", 1, 2, 0, NM_MATCH_SPEC_MATCH); @@ -1624,7 +1621,7 @@ do_test_stable_id_parse (const char *stable_id, else g_assert (stable_id); - stable_type = nm_utils_stable_id_parse (stable_id, "_CONNECTION", "_BOOT", &generated); + stable_type = nm_utils_stable_id_parse (stable_id, "_DEVICE", "_BOOT", "_CONNECTION", &generated); g_assert_cmpint (expected_stable_type, ==, stable_type); diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c index 4c3c344e..9fea6af5 100644 --- a/src/tests/test-ip4-config.c +++ b/src/tests/test-ip4-config.c @@ -319,11 +319,15 @@ test_strip_search_trailing_dot (void) nm_ip4_config_add_search (config, "bar."); nm_ip4_config_add_search (config, "baz.com"); nm_ip4_config_add_search (config, "baz.com."); + nm_ip4_config_add_search (config, "foobar.."); + nm_ip4_config_add_search (config, ".foobar"); + nm_ip4_config_add_search (config, "~."); - g_assert_cmpuint (nm_ip4_config_get_num_searches (config), ==, 3); + g_assert_cmpuint (nm_ip4_config_get_num_searches (config), ==, 4); g_assert_cmpstr (nm_ip4_config_get_search (config, 0), ==, "foo"); g_assert_cmpstr (nm_ip4_config_get_search (config, 1), ==, "bar"); g_assert_cmpstr (nm_ip4_config_get_search (config, 2), ==, "baz.com"); + g_assert_cmpstr (nm_ip4_config_get_search (config, 3), ==, "~"); g_object_unref (config); } diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c index 816a816f..a03d89b0 100644 --- a/src/tests/test-ip6-config.c +++ b/src/tests/test-ip6-config.c @@ -340,11 +340,15 @@ test_strip_search_trailing_dot (void) nm_ip6_config_add_search (config, "bar."); nm_ip6_config_add_search (config, "baz.com"); nm_ip6_config_add_search (config, "baz.com."); + nm_ip6_config_add_search (config, "foobar.."); + nm_ip6_config_add_search (config, ".foobar"); + nm_ip6_config_add_search (config, "~."); - g_assert_cmpuint (nm_ip6_config_get_num_searches (config), ==, 3); + g_assert_cmpuint (nm_ip6_config_get_num_searches (config), ==, 4); g_assert_cmpstr (nm_ip6_config_get_search (config, 0), ==, "foo"); g_assert_cmpstr (nm_ip6_config_get_search (config, 1), ==, "bar"); g_assert_cmpstr (nm_ip6_config_get_search (config, 2), ==, "baz.com"); + g_assert_cmpstr (nm_ip6_config_get_search (config, 3), ==, "~"); g_object_unref (config); } diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index 436fc68b..ad752c4c 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -1022,7 +1022,7 @@ print_vpn_config (NMVpnConnection *self) if (nm_ip4_config_get_num_domains (priv->ip4_config) > 0) dns_domain = (char *) nm_ip4_config_get_domain (priv->ip4_config, 0); - _LOGI ("Data: DNS Domain: '%s'", dns_domain ? dns_domain : "(none)"); + _LOGI ("Data: DNS Domain: '%s'", dns_domain ?: "(none)"); } else _LOGI ("Data: No IPv4 configuration"); @@ -1056,7 +1056,7 @@ print_vpn_config (NMVpnConnection *self) if (nm_ip6_config_get_num_domains (priv->ip6_config) > 0) dns_domain = (char *) nm_ip6_config_get_domain (priv->ip6_config, 0); - _LOGI ("Data: DNS Domain: '%s'", dns_domain ? dns_domain : "(none)"); + _LOGI ("Data: DNS Domain: '%s'", dns_domain ?: "(none)"); } else _LOGI ("Data: No IPv6 configuration"); @@ -2143,7 +2143,6 @@ _name_owner_changed (GObject *object, g_free (owner); } - static gboolean _daemon_exec_timeout (gpointer data) { @@ -2822,7 +2821,7 @@ get_property (GObject *object, guint prop_id, g_value_set_uint (value, _state_to_nm_vpn_state (priv->vpn_state)); break; case PROP_BANNER: - g_value_set_string (value, priv->banner ? priv->banner : ""); + g_value_set_string (value, priv->banner ?: ""); break; case PROP_IP4_CONFIG: nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->vpn_state) ? priv->ip4_config : NULL); |