diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 0e4a95e68a..e6d6c69905 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -541,6 +541,8 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP) return (*out_to_free = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp)); else { + struct tm localtime_result; + if (!timestamp) { if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) return _("never"); @@ -548,7 +550,7 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) } timestamp_real = timestamp; s_mut = g_malloc0 (128); - strftime (s_mut, 64, "%c", localtime (×tamp_real)); + strftime (s_mut, 127, "%c", localtime_r (×tamp_real, &localtime_result)); return (*out_to_free = s_mut); } } @@ -1449,7 +1451,9 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) gboolean was_output = FALSE; if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) { + /* pass */ } else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; @@ -2074,6 +2078,7 @@ do_connections_show (const NMCCommand *cmd, NmCli *nmc, int argc, const char *co if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) fields_str = NMC_FIELDS_CON_SHOW_COMMON; else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; @@ -6280,7 +6285,7 @@ nmcli_editor_tab_completion (const char *text, int start, int end) rl_completion_append_character = '.'; } else generator_func = gen_property_names; - } else if (num >= 3) { + } else { if (num == 3 && should_complete_files (NULL, line)) rl_attempted_completion_over = 0; else if (should_complete_vpn_uuids (NULL, line)) { diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 7031b43756..2d79d2ae9a 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -1436,6 +1436,7 @@ show_device_info (NMDevice *device, NmCli *nmc) if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) fields_str = NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON; else if (g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; @@ -1749,6 +1750,7 @@ do_devices_status (const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) fields_str = "DEVICE,TYPE,STATE,CONNECTION"; else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; @@ -3149,6 +3151,7 @@ do_device_wifi_list (const NMCCommand *cmd, NmCli *nmc, int argc, const char *co if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) fields_str = NMC_FIELDS_DEV_WIFI_LIST_COMMON; else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; @@ -4651,6 +4654,7 @@ do_device_lldp_list (const NMCCommand *cmd, NmCli *nmc, int argc, const char *co if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) fields_str = NMC_FIELDS_DEV_LLDP_LIST_COMMON; else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; diff --git a/clients/cli/general.c b/clients/cli/general.c index 747203bb06..05ff4dee37 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -545,7 +545,9 @@ print_permissions (void *user_data) } if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) { + /* pass */ } else if (g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; @@ -694,7 +696,9 @@ show_general_logging (NmCli *nmc) }; if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) { + /* pass */ } else if (g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { + /* pass */ } else fields_str = nmc->required_fields; diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c index 77d5dfb729..7bed0c014e 100644 --- a/examples/C/glib/list-connections-libnm.c +++ b/examples/C/glib/list-connections-libnm.c @@ -30,10 +30,15 @@ show_connection (NMConnection *connection) s_con = nm_connection_get_setting_connection (connection); if (s_con) { + struct tm localtime_data; + /* Get various info from NMSettingConnection and show it */ timestamp = nm_setting_connection_get_timestamp (s_con); timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp); - strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) ×tamp)); + strftime (timestamp_real_str, + sizeof (timestamp_real_str), + "%c", + localtime_r ((time_t *) ×tamp, &localtime_data)); val1 = nm_setting_connection_get_id (s_con); val2 = nm_setting_connection_get_uuid (s_con); diff --git a/examples/python/dbus/checkpoint.py b/examples/python/dbus/checkpoint.py index 62c7573b8c..1ea1b1a7fc 100755 --- a/examples/python/dbus/checkpoint.py +++ b/examples/python/dbus/checkpoint.py @@ -41,7 +41,7 @@ devList = [] for arg in sys.argv[2:]: path = GetDevicePath(arg) - if path == None: + if path is None: raise Exception("NetworkManager knows nothing about %s" % arg) else: devList.append(path) diff --git a/examples/python/dbus/get-active-connection-uuids.py b/examples/python/dbus/get-active-connection-uuids.py index 8d0e5c15e7..dd168c0aab 100755 --- a/examples/python/dbus/get-active-connection-uuids.py +++ b/examples/python/dbus/get-active-connection-uuids.py @@ -4,7 +4,7 @@ # Copyright (C) 2010 Red Hat, Inc. # -import dbus, sys +import dbus # This example takes a device interface name as a parameter and tells # NetworkManager to disconnect that device, closing down any network diff --git a/examples/python/dbus/list-devices.py b/examples/python/dbus/list-devices.py index 4a9ebe4e53..aebc902bbe 100755 --- a/examples/python/dbus/list-devices.py +++ b/examples/python/dbus/list-devices.py @@ -4,7 +4,7 @@ # Copyright (C) 2011 - 2012 Red Hat, Inc. # -import dbus, sys +import dbus # This example lists basic information about network interfaces known to NM diff --git a/examples/python/dbus/vpn.py b/examples/python/dbus/vpn.py index 8939d26206..14fa2f1d2e 100755 --- a/examples/python/dbus/vpn.py +++ b/examples/python/dbus/vpn.py @@ -56,7 +56,6 @@ def get_active_connection_path(uuid): proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager') iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties') active_connections = iface.Get('org.freedesktop.NetworkManager', 'ActiveConnections') - all_connections = get_connections() for a in active_connections: proxy = bus.get_object('org.freedesktop.NetworkManager', a) diff --git a/examples/python/dbus/wifi-active-ap.py b/examples/python/dbus/wifi-active-ap.py index 790f11a9ef..b81c06a933 100755 --- a/examples/python/dbus/wifi-active-ap.py +++ b/examples/python/dbus/wifi-active-ap.py @@ -11,7 +11,7 @@ # https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -import dbus, sys, time +import dbus, sys bus = dbus.SystemBus() service_name = "org.freedesktop.NetworkManager" diff --git a/examples/python/gi/checkpoint.py b/examples/python/gi/checkpoint.py index b3b4e0f8a5..a695a64613 100755 --- a/examples/python/gi/checkpoint.py +++ b/examples/python/gi/checkpoint.py @@ -10,8 +10,6 @@ import gi gi.require_version('NM', '1.0') from gi.repository import GLib, NM -import os - ############################################################################### def usage(): @@ -136,7 +134,7 @@ def do_adjust_rollback_timeout(client): sys.exit("Missing timeout") try: add_timeout = int(sys.argv[3]) - except: + except Exception: sys.exit("Invalid timeout") path = validate_path(sys.argv[2], client) diff --git a/examples/python/gi/deactivate-all.py b/examples/python/gi/deactivate-all.py index 3af350e4c3..7e528d0b3e 100755 --- a/examples/python/gi/deactivate-all.py +++ b/examples/python/gi/deactivate-all.py @@ -57,7 +57,7 @@ if __name__ == "__main__": # deactivate the connections for ac in connections: - if ctype == None or ctype == ac.get_connection_type(): + if ctype is None or ctype == ac.get_connection_type(): sys.stdout.write("Deactivating %s (%s)" % (ac.get_id(), ac.get_uuid())) try: client.deactivate_connection(ac, None) diff --git a/examples/python/gi/dns.py b/examples/python/gi/dns.py index f93f97e514..da2a6a6c43 100755 --- a/examples/python/gi/dns.py +++ b/examples/python/gi/dns.py @@ -4,7 +4,6 @@ # Copyright (C) 2016 Red Hat, Inc. # -import sys import gi gi.require_version('NM', '1.0') from gi.repository import GLib, NM diff --git a/examples/python/gi/get-active-connections.py b/examples/python/gi/get-active-connections.py index 072f245ab0..6da8b61890 100755 --- a/examples/python/gi/get-active-connections.py +++ b/examples/python/gi/get-active-connections.py @@ -8,7 +8,7 @@ import gi gi.require_version('NM', '1.0') -from gi.repository import GLib, NM +from gi.repository import NM if __name__ == "__main__": client = NM.Client.new(None) diff --git a/examples/python/gi/get-devices.py b/examples/python/gi/get-devices.py index 113d384b30..88bcc8945b 100755 --- a/examples/python/gi/get-devices.py +++ b/examples/python/gi/get-devices.py @@ -8,7 +8,7 @@ import gi gi.require_version('NM', '1.0') -from gi.repository import GLib, NM +from gi.repository import NM if __name__ == "__main__": client = NM.Client.new(None) diff --git a/examples/python/gi/get-interface-flags.py b/examples/python/gi/get-interface-flags.py index 756999169b..e1d1721a4f 100755 --- a/examples/python/gi/get-interface-flags.py +++ b/examples/python/gi/get-interface-flags.py @@ -6,7 +6,7 @@ import gi gi.require_version('NM', '1.0') -from gi.repository import GLib, NM +from gi.repository import NM if __name__ == "__main__": client = NM.Client.new(None) diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py index 13b0a8b6db..75be2f8c5d 100755 --- a/examples/python/gi/get_ips.py +++ b/examples/python/gi/get_ips.py @@ -7,7 +7,7 @@ import sys, socket import gi gi.require_version('NM', '1.0') -from gi.repository import GLib, NM +from gi.repository import NM # # This example shows how to get addresses, routes and DNS information diff --git a/examples/python/gi/nm-add-connection2.py b/examples/python/gi/nm-add-connection2.py index 01c1ae7bd9..c5ec3f3bbe 100755 --- a/examples/python/gi/nm-add-connection2.py +++ b/examples/python/gi/nm-add-connection2.py @@ -5,7 +5,6 @@ # import sys -import re import gi gi.require_version('NM', '1.0') diff --git a/examples/python/gi/nm-update2.py b/examples/python/gi/nm-update2.py index 5a65879371..23e277c78d 100755 --- a/examples/python/gi/nm-update2.py +++ b/examples/python/gi/nm-update2.py @@ -5,7 +5,6 @@ # import sys -import re import gi gi.require_version('NM', '1.0') diff --git a/examples/python/gi/nm-wg-set b/examples/python/gi/nm-wg-set index ca31ac7207..1f5279ee69 100755 --- a/examples/python/gi/nm-wg-set +++ b/examples/python/gi/nm-wg-set @@ -58,7 +58,6 @@ # nm-wg-set id "$PROFILE" $WG_ARGS import sys -import re import os import gi @@ -443,7 +442,7 @@ if __name__ == '__main__': secrets = conn.get_secrets(NM.SETTING_WIREGUARD_SETTING_NAME) if secrets: conn.update_secrets(NM.SETTING_WIREGUARD_SETTING_NAME, secrets) - except: + except Exception: pass if not argv: diff --git a/examples/python/gi/wifi-p2p.py b/examples/python/gi/wifi-p2p.py index 746d8d7975..804df34c89 100755 --- a/examples/python/gi/wifi-p2p.py +++ b/examples/python/gi/wifi-p2p.py @@ -82,7 +82,7 @@ def scan_timeout_cb(device): def start_find_cb(device, async_result, user_data): try: - r = device.start_find_finish(async_result) + device.start_find_finish(async_result) except Exception as e: sys.stderr.write("Error: %s\n" % e) main_loop.quit() diff --git a/libnm/generate-setting-docs.py b/libnm/generate-setting-docs.py index 025689ea3c..38b914b3c9 100755 --- a/libnm/generate-setting-docs.py +++ b/libnm/generate-setting-docs.py @@ -10,7 +10,7 @@ import os import gi gi.require_version('GIRepository', '2.0') from gi.repository import GIRepository -import argparse, datetime, re, sys +import argparse, re, sys import xml.etree.ElementTree as ET try: @@ -47,7 +47,6 @@ dbus_type_name_map = { 'aay': 'array of byte array', 'a(ayuay)': 'array of legacy IPv6 address struct', 'a(ayuayu)': 'array of legacy IPv6 route struct', - 'aa{sv}': 'array of vardict', } ns_map = { diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index 06dbc72d71..04e8fb649b 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -3,6 +3,9 @@ * Copyright (C) 2014 - 2015 Red Hat, Inc. */ +#ifndef __NM_TEST_LIBNM_UTILS_H__ +#define __NM_TEST_LIBNM_UTILS_H__ + #include "NetworkManager.h" #include "nm-utils/nm-test-utils.h" @@ -82,3 +85,5 @@ nmtstc_client_new (gboolean allow_iterate_main_context) { return nmtstc_context_object_new (NM_TYPE_CLIENT, allow_iterate_main_context, NULL); } + +#endif /* __NM_TEST_LIBNM_UTILS_H__ */ diff --git a/src/devices/nm-acd-manager.c b/src/devices/nm-acd-manager.c index 735dd25b09..d9caadc6b6 100644 --- a/src/devices/nm-acd-manager.c +++ b/src/devices/nm-acd-manager.c @@ -81,7 +81,20 @@ _acd_event_to_string (unsigned int event) return NULL; } -#define acd_event_to_string_a(event) NM_UTILS_LOOKUP_STR_A (_acd_event_to_string, event) +#define ACD_EVENT_TO_STRING_BUF_SIZE 50 + +static const char * +_acd_event_to_string_buf (unsigned event, char buffer[ACD_EVENT_TO_STRING_BUF_SIZE]) +{ + const char *s; + + s = _acd_event_to_string (event); + if (s) + return s; + + g_snprintf (buffer, ACD_EVENT_TO_STRING_BUF_SIZE, "(%u)", event); + return buffer; +} static const char * acd_error_to_string (int error) @@ -172,6 +185,7 @@ acd_event (int fd, while ( !n_acd_pop_event (self->acd, &event) && event) { + char to_string_buffer[ACD_EVENT_TO_STRING_BUF_SIZE]; gs_free char *hwaddr_str = NULL; gboolean check_probing_done = FALSE; @@ -215,7 +229,7 @@ acd_event (int fd, nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex)); break; default: - _LOGD ("unhandled event '%s'", acd_event_to_string_a (event->event)); + _LOGD ("unhandled event '%s'", _acd_event_to_string_buf (event->event, to_string_buffer)); break; } diff --git a/src/ndisc/nm-lndp-ndisc.c b/src/ndisc/nm-lndp-ndisc.c index b698489c0d..cff3db827b 100644 --- a/src/ndisc/nm-lndp-ndisc.c +++ b/src/ndisc/nm-lndp-ndisc.c @@ -179,9 +179,9 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) */ #define NM_NDISC_VLTIME_MULT ((guint32) 48) clamp_pltime = ndp_msgra_router_lifetime (msgra); - clamp_vltime = (clamp_pltime < G_MAXUINT32 / NM_NDISC_VLTIME_MULT) - ? clamp_pltime * NM_NDISC_VLTIME_MULT - : G_MAXUINT32; + + /* clamp_pltime has at most 16 bit set, and multiplication cannot overflow. */ + clamp_vltime = clamp_pltime * NM_NDISC_VLTIME_MULT; ndp_msg_opt_for_each_offset (offset, msg, NDP_MSG_OPT_PREFIX) { guint8 r_plen; diff --git a/src/nm-config.c b/src/nm-config.c index 63347db7bb..9a16aa0374 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -2210,7 +2210,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf) gs_free char *perm_hw_addr_fake = NULL; gsize connection_uuid_len; gsize perm_hw_addr_fake_len; - int nm_owned = -1; + NMTernary nm_owned; char *p; guint32 route_metric_default_effective; guint32 route_metric_default_aspired; @@ -2252,7 +2252,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf) nm_owned = nm_config_keyfile_get_boolean (kf, DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE, DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED, - -1); + NM_TERNARY_DEFAULT); /* metric zero is not a valid metric. While zero valid for IPv4, for IPv6 it is an alias * for 1024. Since we handle here IPv4 and IPv6 the same, we cannot allow zero. */ @@ -2325,9 +2325,11 @@ nm_config_device_state_load (int ifindex) return NULL; device_state = _config_device_state_data_new (ifindex, kf); - nm_owned_str = device_state->nm_owned == TRUE ? - ", nm-owned=1" : - (device_state->nm_owned == FALSE ? ", nm-owned=0" : ""); + nm_owned_str = device_state->nm_owned == NM_TERNARY_TRUE + ? ", nm-owned=1" + : ( device_state->nm_owned == NM_TERNARY_FALSE + ? ", nm-owned=0" + : ""); _LOGT ("device-state: %s #%d (%s); managed=%s%s%s%s%s%s%s%s, route-metric-default=%"G_GUINT32_FORMAT"-%"G_GUINT32_FORMAT"", kf ? "read" : "miss", @@ -2390,7 +2392,7 @@ nm_config_device_state_write (int ifindex, NMConfigDeviceStateManagedType managed, const char *perm_hw_addr_fake, const char *connection_uuid, - int nm_owned, + NMTernary nm_owned, guint32 route_metric_default_aspired, guint32 route_metric_default_effective, const char *next_server, @@ -2429,7 +2431,7 @@ nm_config_device_state_write (int ifindex, DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_CONNECTION_UUID, connection_uuid); } - if (nm_owned >= 0) { + if (nm_owned != NM_TERNARY_DEFAULT) { g_key_file_set_boolean (kf, DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE, DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED, diff --git a/src/nm-config.h b/src/nm-config.h index b4478ceb04..0fce7ec0cb 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -243,7 +243,7 @@ struct _NMConfigDeviceStateData { /* whether the device was nm-owned (0/1) or -1 for * non-software devices. */ - int nm_owned:3; + NMTernary nm_owned:3; }; NMConfigDeviceStateData *nm_config_device_state_load (int ifindex); @@ -252,7 +252,7 @@ gboolean nm_config_device_state_write (int ifindex, NMConfigDeviceStateManagedType managed, const char *perm_hw_addr_fake, const char *connection_uuid, - int nm_owned, + NMTernary nm_owned, guint32 route_metric_default_aspired, guint32 route_metric_default_effective, const char *next_server, diff --git a/src/nm-manager.c b/src/nm-manager.c index bbe501259f..8cee206bef 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -6552,7 +6552,7 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifind gboolean perm_hw_addr_is_fake; guint32 route_metric_default_aspired; guint32 route_metric_default_effective; - int nm_owned; + NMTernary nm_owned; NMDhcpConfig *dhcp_config; const char *next_server = NULL; const char *root_path = NULL; @@ -6588,7 +6588,9 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifind if (perm_hw_addr_fake && !perm_hw_addr_is_fake) perm_hw_addr_fake = NULL; - nm_owned = nm_device_is_software (device) ? nm_device_is_nm_owned (device) : -1; + nm_owned = nm_device_is_software (device) + ? nm_device_is_nm_owned (device) + : NM_TERNARY_DEFAULT; route_metric_default_effective = _device_route_metric_get (self, ifindex, NM_DEVICE_TYPE_UNKNOWN, TRUE, &route_metric_default_aspired);