static void compare_gvalue_hash (void) { GHashTable *hash1; GHashTable *hash2; GValue value1 = { 0 }; GValue value2 = { 0 }; g_value_init (&value1, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)); g_value_init (&value2, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)); hash1 = g_hash_table_new (g_str_hash, g_str_equal); hash2 = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (hash1, "key1", str_to_gvalue ("hello")); g_hash_table_insert (hash1, "key2", int_to_gvalue (5)); g_hash_table_insert (hash2, "key1", str_to_gvalue ("hello")); g_hash_table_insert (hash2, "key2", int_to_gvalue (5)); g_value_set_boxed (&value1, hash1); g_value_set_boxed (&value2, hash2); g_print ("Comparing identical gvalue hashes: %d\n", _gvalues_compare (&value1, &value2)); g_hash_table_remove (hash2, "key2"); g_value_set_boxed (&value2, hash2); g_print ("Comparing different length str hashes: %d\n", _gvalues_compare (&value1, &value2)); g_hash_table_insert (hash2, "key2", str_to_gvalue ("moon")); g_value_set_boxed (&value2, hash2); g_print ("Comparing different str hashes: %d\n", _gvalues_compare (&value1, &value2)); }
static gboolean nm_openssh_send_ip4_config (sshtun_handle_t handle) { DBusGConnection *connection; GError *err = NULL; GHashTable *config; GValue *val; struct in_addr temp_addr; const char *tmp; connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) return FALSE; config = g_hash_table_new (g_str_hash, g_str_equal); /* Gateway */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_GW_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY, val); else { helper_failed (connection, "VPN Gateway"); dbus_g_connection_unref (connection); return FALSE; } /* Tunnel device */ val = str_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_TUN_DEV), FALSE); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, val); else { helper_failed (connection, "Tunnel Device"); dbus_g_connection_unref (connection); return FALSE; } /* IP address */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, val); else { helper_failed (connection, "IP4 Address"); dbus_g_connection_unref (connection); return FALSE; } /* PTP address */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_PEER_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_PTP, val); /* Netmask */ tmp = sshtun_get_param (handle, SSHTUN_PARAM_NETMASK); if (tmp && inet_pton (AF_INET, tmp, &temp_addr) > 0) { val = uint_to_gvalue (nm_utils_ip4_netmask_to_prefix (temp_addr.s_addr)); g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, val); } /* MTU */ tmp = sshtun_get_param (handle, SSHTUN_PARAM_MTU); if (tmp && strlen (tmp)) { long int mtu; errno = 0; mtu = strtol (tmp, NULL, 10); if (errno || mtu < 0 || mtu > 20000) { nm_warning ("Ignoring invalid tunnel MTU '%s'", tmp); } else { val = uint_to_gvalue ((guint32) mtu); g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, val); } } send_ip4_config (connection, config); dbus_g_connection_unref (connection); return TRUE; }
static void nm_ip_up (void *data, int arg) { guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit); ipcp_options opts = ipcp_gotoptions[0]; ipcp_options peer_opts = ipcp_hisoptions[0]; GHashTable *hash; GArray *array; GValue *val; struct sockaddr_in addr; g_return_if_fail (DBUS_IS_G_PROXY (proxy)); g_message ("nm-sstp-ppp-plugin: (%s): ip-up event", __func__); if (!opts.ouraddr) { g_warning ("nm-sstp-ppp-plugin: (%s): didn't receive an internal IP from pppd!", __func__); return; } hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); /* Request the address of the server sstpc connected to */ if (0 == nm_sstp_getaddr(&addr)) { /* This will eliminate the need to have nm-sstp-service * insert a new entry for "gateway" as we have already set it. */ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, uint_to_gvalue (addr.sin_addr.s_addr)); } g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, str_to_gvalue (ifname)); /* Prefer the peer options remote address first, _unless_ pppd made the * address up, at which point prefer the local options remote address, * and if that's not right, use the made-up address as a last resort. */ if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) { g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP, uint_to_gvalue (peer_opts.hisaddr)); } else if (opts.hisaddr) { g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP, uint_to_gvalue (opts.hisaddr)); } else if (peer_opts.hisaddr == pppd_made_up_address) { /* As a last resort, use the made-up address */ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP, uint_to_gvalue (peer_opts.hisaddr)); } g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, uint_to_gvalue (opts.ouraddr)); g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, uint_to_gvalue (32)); if (opts.dnsaddr[0] || opts.dnsaddr[1]) { array = g_array_new (FALSE, FALSE, sizeof (guint32)); if (opts.dnsaddr[0]) g_array_append_val (array, opts.dnsaddr[0]); if (opts.dnsaddr[1]) g_array_append_val (array, opts.dnsaddr[1]); val = g_slice_new0 (GValue); g_value_init (val, DBUS_TYPE_G_UINT_ARRAY); g_value_set_boxed (val, array); g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val); } /* Default MTU to 1400, which is also what Windows XP/Vista use */ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_MTU, uint_to_gvalue (1400)); g_message ("nm-sstp-ppp-plugin: (%s): sending Ip4Config to NetworkManager-sstp...", __func__); dbus_g_proxy_call_no_reply (proxy, "SetIp4Config", DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID, G_TYPE_INVALID); g_hash_table_destroy (hash); }