ifnet: plugin updates and shared connection support
This commit is contained in:
@@ -57,9 +57,16 @@ update_connection_id (NMConnection *connection, const char *conn_name)
|
||||
gchar *idstr = NULL;
|
||||
gchar *uuid_base = NULL;
|
||||
gchar *uuid = NULL;
|
||||
int name_len;
|
||||
NMSettingConnection *setting;
|
||||
|
||||
idstr = g_strdup_printf ("%s (%s)", get_prefix (), conn_name);
|
||||
name_len = strlen (conn_name);
|
||||
if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x"))) {
|
||||
gchar * conn_name_printable = utils_hexstr2bin (conn_name + 2, name_len - 2);
|
||||
idstr = g_strdup_printf ("%s (%s)", get_prefix (), conn_name_printable);
|
||||
g_free (conn_name_printable);
|
||||
} else
|
||||
idstr = g_strdup_printf ("%s (%s)", get_prefix (), conn_name);
|
||||
uuid_base = idstr;
|
||||
uuid = nm_utils_uuid_generate_from_string (uuid_base);
|
||||
setting =
|
||||
@@ -281,7 +288,7 @@ eap_tls_reader (const char *eap_method,
|
||||
|
||||
success = TRUE;
|
||||
|
||||
done:
|
||||
done:
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -380,7 +387,7 @@ eap_peap_reader (const char *eap_method,
|
||||
|
||||
success = TRUE;
|
||||
|
||||
done:
|
||||
done:
|
||||
if (list)
|
||||
g_strfreev (list);
|
||||
return success;
|
||||
@@ -467,7 +474,7 @@ eap_ttls_reader (const char *eap_method,
|
||||
}
|
||||
|
||||
success = TRUE;
|
||||
done:
|
||||
done:
|
||||
if (list)
|
||||
g_strfreev (list);
|
||||
g_free (inner_auth);
|
||||
@@ -570,7 +577,7 @@ make_ip4_setting (NMConnection *connection,
|
||||
|
||||
NMSettingIP4Config *ip4_setting =
|
||||
NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
|
||||
const char *value;
|
||||
const char *value, *method;
|
||||
gboolean is_static_block = is_static_ip4 (conn_name);
|
||||
ip_block *iblock = NULL;
|
||||
|
||||
@@ -582,13 +589,41 @@ make_ip4_setting (NMConnection *connection,
|
||||
&& strstr (value, "nogateway") ? TRUE : FALSE, NULL);
|
||||
|
||||
if (!is_static_block) {
|
||||
g_object_set (ip4_setting,
|
||||
NM_SETTING_IP4_CONFIG_METHOD,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using DHCP for %s",
|
||||
conn_name);
|
||||
} else {
|
||||
method = ifnet_get_data (conn_name, "config");
|
||||
if (!method){
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
"Unknown config for %s", conn_name);
|
||||
g_object_unref (ip4_setting);
|
||||
return;
|
||||
}
|
||||
if (!strcmp (method, "dhcp"))
|
||||
g_object_set (ip4_setting,
|
||||
NM_SETTING_IP4_CONFIG_METHOD,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
|
||||
else if (!strcmp (method, "autoip")){
|
||||
g_object_set (ip4_setting,
|
||||
NM_SETTING_IP4_CONFIG_METHOD,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
|
||||
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
|
||||
nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
|
||||
return;
|
||||
} else if (!strcmp (method, "shared")){
|
||||
g_object_set (ip4_setting,
|
||||
NM_SETTING_IP4_CONFIG_METHOD,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_SHARED,
|
||||
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
|
||||
nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
|
||||
return;
|
||||
} else {
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
"Unknown config for %s", conn_name);
|
||||
g_object_unref (ip4_setting);
|
||||
return;
|
||||
}
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using %s method for %s",
|
||||
method, conn_name);
|
||||
}else {
|
||||
iblock = convert_ip4_config_block (conn_name);
|
||||
if (!iblock) {
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
@@ -612,18 +647,9 @@ make_ip4_setting (NMConnection *connection,
|
||||
g_object_set (ip4_setting,
|
||||
NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES,
|
||||
TRUE, NULL);
|
||||
if (nm_setting_ip4_config_add_address
|
||||
(ip4_setting, ip4_addr)) {
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME,
|
||||
"new address: %d", iblock->ip);
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME,
|
||||
"ipv4 addresses count: %d",
|
||||
nm_setting_ip4_config_get_num_addresses
|
||||
(ip4_setting));
|
||||
} else {
|
||||
if (!nm_setting_ip4_config_add_address (ip4_setting, ip4_addr))
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||
"ignoring duplicate IP4 address");
|
||||
}
|
||||
nm_ip4_address_unref (ip4_addr);
|
||||
current_iblock = iblock;
|
||||
iblock = iblock->next;
|
||||
@@ -637,7 +663,7 @@ make_ip4_setting (NMConnection *connection,
|
||||
}
|
||||
|
||||
/* add dhcp hostname and client id */
|
||||
if (!is_static_block) {
|
||||
if (!is_static_block && !strcmp (method, "dhcp")) {
|
||||
gchar *dhcp_hostname, *client_id;
|
||||
|
||||
get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
|
||||
@@ -871,11 +897,11 @@ make_ip6_setting (NMConnection *connection,
|
||||
destroy_ip6_block (current_iblock);
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
|
||||
return;
|
||||
|
||||
error:
|
||||
error:
|
||||
g_object_unref (s_ip6);
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME, " warning: Ignore IPv6 for %s",
|
||||
conn_name);
|
||||
@@ -1024,7 +1050,7 @@ make_wireless_connection_setting (const char *conn_name,
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "wireless_setting added for %s",
|
||||
conn_name);
|
||||
return NM_SETTING (wireless_setting);
|
||||
error:
|
||||
error:
|
||||
if (wireless_setting)
|
||||
g_object_unref (wireless_setting);
|
||||
return NULL;
|
||||
@@ -1067,7 +1093,7 @@ make_leap_setting (const char *ssid, GError **error)
|
||||
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", NULL);
|
||||
|
||||
return wsec;
|
||||
error:
|
||||
error:
|
||||
if (wsec)
|
||||
g_object_unref (wsec);
|
||||
return NULL;
|
||||
@@ -1244,7 +1270,7 @@ make_wep_setting (const char *ssid, GError **error)
|
||||
}
|
||||
return s_wireless_sec;
|
||||
|
||||
error:
|
||||
error:
|
||||
if (s_wireless_sec)
|
||||
g_object_unref (s_wireless_sec);
|
||||
return NULL;
|
||||
@@ -1253,7 +1279,6 @@ make_wep_setting (const char *ssid, GError **error)
|
||||
static char *
|
||||
parse_wpa_psk (const char *psk, GError **error)
|
||||
{
|
||||
const char *p = psk;
|
||||
char *hashed = NULL;
|
||||
gboolean quoted = FALSE;
|
||||
|
||||
@@ -1286,7 +1311,7 @@ parse_wpa_psk (const char *psk, GError **error)
|
||||
strip_string (stripped, '"');
|
||||
|
||||
/* Length check */
|
||||
if (strlen (p) < 8 || strlen (p) > 63) {
|
||||
if (strlen (stripped) < 8 || strlen (stripped) > 63) {
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
"Invalid WPA_PSK (passphrases must be between "
|
||||
"8 and 63 characters long (inclusive))");
|
||||
@@ -1426,7 +1451,7 @@ fill_8021x (const char *ssid,
|
||||
nm_setting_802_1x_add_eap_method (s_8021x, lower);
|
||||
found = TRUE;
|
||||
|
||||
next:
|
||||
next:
|
||||
eap++;
|
||||
}
|
||||
|
||||
@@ -1447,7 +1472,7 @@ fill_8021x (const char *ssid,
|
||||
|
||||
return s_8021x;
|
||||
|
||||
error:
|
||||
error:
|
||||
g_object_unref (s_8021x);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1535,7 +1560,7 @@ make_wpa_setting (const char *ssid,
|
||||
goto error;
|
||||
}
|
||||
return wsec;
|
||||
error:
|
||||
error:
|
||||
if (wsec)
|
||||
g_object_unref (wsec);
|
||||
return NULL;
|
||||
@@ -1587,7 +1612,7 @@ make_wireless_security_setting (const char *conn_name,
|
||||
}
|
||||
|
||||
return wsec;
|
||||
error:
|
||||
error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1971,7 +1996,7 @@ write_8021x_certs (NMSetting8021x *s_8021x,
|
||||
}
|
||||
|
||||
success = TRUE;
|
||||
out:
|
||||
out:
|
||||
if (generated_pw) {
|
||||
memset (generated_pw, 0, strlen (generated_pw));
|
||||
g_free (generated_pw);
|
||||
@@ -2123,7 +2148,8 @@ write_wireless_security_setting (NMConnection * connection,
|
||||
} else if (!strcmp (key_mgmt, "wpa-eap")) {
|
||||
wpa_set_data (conn_name, "key_mgmt", "WPA-EAP");
|
||||
wpa = TRUE;
|
||||
}
|
||||
} else
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Unknown key_mgmt: %s", key_mgmt);
|
||||
|
||||
if (auth_alg) {
|
||||
if (!strcmp (auth_alg, "shared"))
|
||||
@@ -2218,8 +2244,10 @@ write_wireless_security_setting (NMConnection * connection,
|
||||
g_string_append (quoted, psk);
|
||||
g_string_append_c (quoted, '"');
|
||||
}
|
||||
wpa_set_data (conn_name, "psk",
|
||||
quoted ? quoted->str : (gchar *) psk);
|
||||
/* psk will be lost here if we don't check it for NULL */
|
||||
if (psk)
|
||||
wpa_set_data (conn_name, "psk",
|
||||
quoted ? quoted->str : (gchar *) psk);
|
||||
if (quoted)
|
||||
g_string_free (quoted, TRUE);
|
||||
} else
|
||||
@@ -2235,10 +2263,12 @@ update_wireless_ssid (NMConnection *connection,
|
||||
const char *ssid,
|
||||
gboolean hex)
|
||||
{
|
||||
ifnet_delete_network (conn_name);
|
||||
wpa_delete_security (conn_name);
|
||||
if(strcmp (conn_name, ssid)){
|
||||
ifnet_delete_network (conn_name);
|
||||
wpa_delete_security (conn_name);
|
||||
}
|
||||
|
||||
ifnet_add_connection (ssid, "wireless");
|
||||
ifnet_add_network (ssid, "wireless");
|
||||
wpa_add_security (ssid);
|
||||
}
|
||||
|
||||
@@ -2279,11 +2309,12 @@ write_wireless_setting (NMConnection *connection,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If the SSID contains any non-printable characters, we need to use the
|
||||
* hex notation of the SSID instead.
|
||||
/* If the SSID contains any non-alnum characters, we need to use
|
||||
* the hex notation of the SSID instead. (Because openrc doesn't
|
||||
* support these characters, see bug #356337)
|
||||
*/
|
||||
for (i = 0; i < ssid->len; i++) {
|
||||
if (!isprint (ssid->data[i])) {
|
||||
if (!isalnum (ssid->data[i])) {
|
||||
hex_ssid = TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -2482,11 +2513,14 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
|
||||
}
|
||||
ifnet_set_data (conn_name, "config", ips->str);
|
||||
g_string_free (ips, TRUE);
|
||||
} else
|
||||
} else if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
|
||||
ifnet_set_data (conn_name, "config", "shared");
|
||||
else if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
|
||||
ifnet_set_data (conn_name, "config", "autoip");
|
||||
else
|
||||
ifnet_set_data (conn_name, "config", "dhcp");
|
||||
|
||||
/* DNS Servers */
|
||||
ifnet_set_data (conn_name, "dns_servers", NULL);
|
||||
num = nm_setting_ip4_config_get_num_dns (s_ip4);
|
||||
if (num > 0) {
|
||||
dns = g_string_new (NULL);
|
||||
@@ -2779,7 +2813,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection,
|
||||
const char *conn_name,
|
||||
const char *config_file,
|
||||
const char *wpa_file,
|
||||
const char **out_new_name,
|
||||
gchar **out_new_name,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
@@ -2800,6 +2834,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
type = nm_setting_connection_get_connection_type (s_con);
|
||||
if (!type) {
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
@@ -2867,7 +2902,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection,
|
||||
wpa_flush_to_file (wpa_file);
|
||||
|
||||
if (out_new_name)
|
||||
*out_new_name = new_name;
|
||||
*out_new_name = g_strdup (conn_name);
|
||||
|
||||
out:
|
||||
return success;
|
||||
@@ -2901,7 +2936,7 @@ get_wired_name ()
|
||||
for (; i < 256; i++) {
|
||||
gchar *conn_name = g_strdup_printf ("eth%d", i);
|
||||
|
||||
if (!ifnet_has_connection (conn_name)) {
|
||||
if (!ifnet_has_network (conn_name)) {
|
||||
return conn_name;
|
||||
} else
|
||||
g_free (conn_name);
|
||||
@@ -2918,7 +2953,7 @@ get_ppp_name ()
|
||||
for (; i < 256; i++) {
|
||||
gchar *conn_name = g_strdup_printf ("ppp%d", i);
|
||||
|
||||
if (!ifnet_has_connection (conn_name)) {
|
||||
if (!ifnet_has_network (conn_name)) {
|
||||
return conn_name;
|
||||
} else
|
||||
g_free (conn_name);
|
||||
@@ -3015,7 +3050,7 @@ ifnet_add_new_connection (NMConnection *connection,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ifnet_add_connection (new_name, new_type)) {
|
||||
if (ifnet_add_network (new_name, new_type)) {
|
||||
success = ifnet_update_parsers_by_connection (connection,
|
||||
new_name,
|
||||
config_file,
|
||||
|
@@ -32,7 +32,7 @@ gboolean ifnet_update_parsers_by_connection (NMConnection *connection,
|
||||
const char *conn_name,
|
||||
const char *config_file,
|
||||
const char *wpa_file,
|
||||
const char **out_new_name,
|
||||
gchar **out_new_name,
|
||||
GError **error);
|
||||
|
||||
gboolean ifnet_delete_connection_in_parsers (const char *conn_name,
|
||||
|
@@ -58,8 +58,10 @@ add_new_connection_config (const gchar * type, const gchar * name)
|
||||
}
|
||||
|
||||
gboolean
|
||||
ifnet_add_connection (const char *name, const char *type)
|
||||
ifnet_add_network (const char *name, const char *type)
|
||||
{
|
||||
if (ifnet_has_network (name))
|
||||
return TRUE;
|
||||
if (add_new_connection_config (type, name)) {
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding network for %s", name);
|
||||
net_parser_data_changed = TRUE;
|
||||
@@ -69,7 +71,7 @@ ifnet_add_connection (const char *name, const char *type)
|
||||
}
|
||||
|
||||
gboolean
|
||||
ifnet_has_connection (const char *conn_name)
|
||||
ifnet_has_network (const char *conn_name)
|
||||
{
|
||||
return g_hash_table_lookup (conn_table, conn_name) != NULL;
|
||||
}
|
||||
@@ -256,7 +258,7 @@ strip_function (GIOChannel * channel, gchar * line)
|
||||
g_free (tmp);
|
||||
}
|
||||
}
|
||||
done:
|
||||
done:
|
||||
functions_list =
|
||||
g_list_append (functions_list, g_strdup (function_str->str));
|
||||
g_string_free (function_str, TRUE);
|
||||
@@ -375,23 +377,31 @@ ifnet_get_data (const char *conn_name, const char *key)
|
||||
void
|
||||
ifnet_set_data (const char *conn_name, const char *key, const char *value)
|
||||
{
|
||||
gpointer orin_key = NULL, orin_value = NULL;
|
||||
gpointer old_key = NULL, old_value = NULL;
|
||||
GHashTable *conn = g_hash_table_lookup (conn_table, conn_name);
|
||||
gchar * stripped = NULL;
|
||||
|
||||
if (!conn) {
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||
"%s does not exsit!", conn_name);
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME, "%s does not exsit!", conn_name);
|
||||
return;
|
||||
}
|
||||
/* Remove existing key value pair */
|
||||
if (g_hash_table_lookup_extended (conn, key, &orin_key, &orin_value)) {
|
||||
g_hash_table_remove (conn, orin_key);
|
||||
g_free (orin_key);
|
||||
g_free (orin_value);
|
||||
if (value){
|
||||
stripped = g_strdup (value);
|
||||
strip_string (stripped, '"');
|
||||
}
|
||||
if (value)
|
||||
g_hash_table_insert (conn, g_strdup (key),
|
||||
strip_string (g_strdup (value), '"'));
|
||||
/* Remove existing key value pair */
|
||||
if (g_hash_table_lookup_extended (conn, key, &old_key, &old_value)) {
|
||||
if (stripped && !strcmp(old_value, stripped)){
|
||||
g_free (stripped);
|
||||
return;
|
||||
}
|
||||
g_hash_table_remove (conn, old_key);
|
||||
g_free (old_key);
|
||||
g_free (old_value);
|
||||
} else if (!value)
|
||||
return;
|
||||
if (stripped)
|
||||
g_hash_table_insert (conn, g_strdup (key), stripped);
|
||||
net_parser_data_changed = TRUE;
|
||||
}
|
||||
|
||||
@@ -443,7 +453,7 @@ format_ips (gchar * value, gchar ** out_line, gchar * key, gchar * name)
|
||||
"\t\"%s\"\n", ipset[i]);
|
||||
g_string_append (formated_string, ")\n");
|
||||
*out_line = g_strdup (formated_string->str);
|
||||
done:
|
||||
done:
|
||||
g_string_free (formated_string, TRUE);
|
||||
g_strfreev (ipset);
|
||||
}
|
||||
@@ -461,7 +471,7 @@ ifnet_flush_to_file (const char *config_file)
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (!net_parser_data_changed)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
if (!conn_table || !global_settings_table)
|
||||
return FALSE;
|
||||
|
||||
@@ -571,7 +581,7 @@ ifnet_flush_to_file (const char *config_file)
|
||||
}
|
||||
result = TRUE;
|
||||
net_parser_data_changed = FALSE;
|
||||
done:
|
||||
done:
|
||||
g_io_channel_shutdown (channel, FALSE, NULL);
|
||||
g_io_channel_unref (channel);
|
||||
return result;
|
||||
|
@@ -36,11 +36,11 @@ GList *ifnet_get_connection_names (void);
|
||||
const char *ifnet_get_data (const char *conn_name, const char *key);
|
||||
const char *ifnet_get_global_data (const char *key);
|
||||
const char *ifnet_get_global_setting (const char *group, const char *key);
|
||||
gboolean ifnet_has_connection (const char *conn_name);
|
||||
gboolean ifnet_has_network (const char *conn_name);
|
||||
|
||||
/* Writer functions */
|
||||
gboolean ifnet_flush_to_file (const char *config_file);
|
||||
void ifnet_set_data (const char *conn_name, const char *key, const char *value);
|
||||
gboolean ifnet_add_connection (const char *name, const char *type);
|
||||
gboolean ifnet_add_network (const char *name, const char *type);
|
||||
gboolean ifnet_delete_network (const char *conn_name);
|
||||
#endif
|
||||
|
@@ -274,6 +274,10 @@ is_static_ip4 (const char *conn_name)
|
||||
|
||||
if (!data)
|
||||
return FALSE;
|
||||
if (!strcmp (data, "shared"))
|
||||
return FALSE;
|
||||
if (!strcmp (data, "autoip"))
|
||||
return FALSE;
|
||||
dhcp6 = strstr (data, "dhcp6");
|
||||
if (dhcp6) {
|
||||
gchar *dhcp4;
|
||||
@@ -320,7 +324,7 @@ is_ip4_address (const char *in_address)
|
||||
*tmp = '\0';
|
||||
g_regex_match (regex, address, 0, &match_info);
|
||||
result = g_match_info_matches (match_info);
|
||||
done:
|
||||
done:
|
||||
if (match_info)
|
||||
g_match_info_free (match_info);
|
||||
g_regex_unref (regex);
|
||||
@@ -445,7 +449,7 @@ create_ip4_block (gchar * ip)
|
||||
}
|
||||
g_strfreev (ip_mask);
|
||||
return iblock;
|
||||
error:
|
||||
error:
|
||||
if (!is_ip6_address (ip))
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv4 address: %s",
|
||||
ip);
|
||||
@@ -480,7 +484,7 @@ create_ip6_block (gchar * ip)
|
||||
iblock->prefix = 64;
|
||||
g_free (dup_ip);
|
||||
return iblock;
|
||||
error:
|
||||
error:
|
||||
if (!is_ip4_address (ip))
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv6 address: %s",
|
||||
ip);
|
||||
@@ -514,7 +518,7 @@ get_ip4_gateway (gchar * gateway)
|
||||
goto error;
|
||||
g_free (tmp);
|
||||
return tmp_ip4_addr.s_addr;
|
||||
error:
|
||||
error:
|
||||
if (!is_ip6_address (tmp))
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv4 gateway: %s",
|
||||
tmp);
|
||||
@@ -544,7 +548,7 @@ get_ip6_next_hop (gchar * next_hop)
|
||||
goto error;
|
||||
g_free (tmp);
|
||||
return tmp_ip6_addr;
|
||||
error:
|
||||
error:
|
||||
if (!is_ip4_address (tmp))
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||
"Can't handle IPv6 next_hop: %s", tmp);
|
||||
@@ -946,8 +950,8 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id)
|
||||
else if ((tmp = strstr (line, "send host-name")) != NULL) {
|
||||
tmp += strlen ("send host-name");
|
||||
g_strstrip (tmp);
|
||||
strip_string (tmp, '"');
|
||||
strip_string (tmp, ';');
|
||||
strip_string (tmp, '"');
|
||||
if (tmp[0] != '\0')
|
||||
*hostname = g_strdup (tmp);
|
||||
else
|
||||
|
@@ -61,16 +61,18 @@ nm_ifnet_connection_new (const char *conn_name, NMConnection *source)
|
||||
{
|
||||
NMConnection *tmp;
|
||||
GObject *object;
|
||||
GError **error = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (conn_name != NULL, NULL);
|
||||
|
||||
if (source)
|
||||
tmp = g_object_ref (source);
|
||||
else {
|
||||
tmp = ifnet_update_connection_from_config_block (conn_name, error);
|
||||
if (!tmp)
|
||||
tmp = ifnet_update_connection_from_config_block (conn_name, &error);
|
||||
if (!tmp){
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL);
|
||||
@@ -98,7 +100,7 @@ commit_changes (NMSettingsConnection *connection,
|
||||
{
|
||||
GError *error = NULL;
|
||||
NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection);
|
||||
const char *new_name = NULL;
|
||||
gchar *new_name = NULL;
|
||||
|
||||
g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0);
|
||||
if (!ifnet_update_parsers_by_connection (NM_CONNECTION (connection),
|
||||
@@ -116,7 +118,7 @@ commit_changes (NMSettingsConnection *connection,
|
||||
}
|
||||
|
||||
g_free (priv->conn_name);
|
||||
priv->conn_name = g_strdup (new_name);
|
||||
priv->conn_name = new_name;
|
||||
|
||||
NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->commit_changes (connection, callback, user_data);
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully updated %s", priv->conn_name);
|
||||
|
@@ -88,9 +88,8 @@ update_system_hostname (gpointer config)
|
||||
{
|
||||
SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);
|
||||
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Updating hostname");
|
||||
|
||||
g_free (priv->hostname);
|
||||
if (priv->hostname)
|
||||
g_free (priv->hostname);
|
||||
priv->hostname = read_hostname (IFNET_SYSTEM_HOSTNAME_FILE);
|
||||
|
||||
g_object_notify (G_OBJECT (config),
|
||||
@@ -170,8 +169,6 @@ monitor_file_changes (const char *filename,
|
||||
info);
|
||||
g_signal_connect (monitor, "changed", G_CALLBACK (file_changed),
|
||||
info);
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Monitoring %s", filename);
|
||||
|
||||
} else
|
||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||
"Monitoring %s failed, error: %s", filename,
|
||||
@@ -288,7 +285,7 @@ reload_connections (gpointer config)
|
||||
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (old));
|
||||
g_hash_table_remove (priv->config_connections, conn_name);
|
||||
g_hash_table_insert (priv->config_connections, g_strdup (conn_name), new);
|
||||
if (is_managed (conn_name))
|
||||
if (is_managed_plugin () && is_managed (conn_name))
|
||||
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, new);
|
||||
}
|
||||
} else {
|
||||
@@ -301,7 +298,7 @@ reload_connections (gpointer config)
|
||||
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
|
||||
} else if (new) {
|
||||
g_hash_table_insert (priv->config_connections, g_strdup (conn_name), new);
|
||||
if (is_managed (conn_name))
|
||||
if (is_managed_plugin () && is_managed (conn_name))
|
||||
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, new);
|
||||
}
|
||||
g_hash_table_insert (new_conn_names, (gpointer) conn_name, (gpointer) conn_name);
|
||||
@@ -389,21 +386,6 @@ SCPluginIfnet_init (NMSystemConfigInterface * config)
|
||||
// GFileMonitor setup
|
||||
setup_monitors (NULL, config);
|
||||
reload_connections (config);
|
||||
/* Now if we're running in managed mode, let NM know there are new connections */
|
||||
if (!priv->unmanaged_well_known) {
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->config_connections);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
||||
if (is_managed ((gchar *) key))
|
||||
g_signal_emit_by_name
|
||||
(self,
|
||||
NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
|
||||
NM_CONNECTION (value));
|
||||
}
|
||||
}
|
||||
/* Read hostname */
|
||||
update_system_hostname (self);
|
||||
|
||||
|
@@ -367,7 +367,7 @@ wpa_flush_to_file (const char *config_file)
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (!wpa_parser_data_changed)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
if (!wsec_table || !wsec_global_table)
|
||||
return FALSE;
|
||||
|
||||
@@ -439,7 +439,7 @@ wpa_flush_to_file (const char *config_file)
|
||||
}
|
||||
wpa_parser_data_changed = FALSE;
|
||||
result = TRUE;
|
||||
done:
|
||||
done:
|
||||
g_io_channel_shutdown (channel, FALSE, NULL);
|
||||
g_io_channel_unref (channel);
|
||||
return result;
|
||||
@@ -449,28 +449,35 @@ wpa_flush_to_file (const char *config_file)
|
||||
void
|
||||
wpa_set_data (const char *ssid, const char *key, const char *value)
|
||||
{
|
||||
gpointer orig_key = NULL, orig_value = NULL;
|
||||
gpointer old_key = NULL, old_value = NULL;
|
||||
GHashTable *security = g_hash_table_lookup (wsec_table, ssid);
|
||||
gchar * stripped = NULL;
|
||||
|
||||
g_return_if_fail (security != NULL);
|
||||
|
||||
if (value){
|
||||
stripped = g_strdup(value);
|
||||
if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
|
||||
&& !g_str_has_prefix (key, "wep_key"))
|
||||
strip_string (stripped, '"');
|
||||
}
|
||||
|
||||
/* Remove old key value pairs */
|
||||
if (g_hash_table_lookup_extended
|
||||
(security, key, &orig_key, &orig_value)) {
|
||||
g_hash_table_remove (security, orig_key);
|
||||
g_free (orig_key);
|
||||
g_free (orig_value);
|
||||
}
|
||||
(security, key, &old_key, &old_value)) {
|
||||
if (stripped && !strcmp(old_value, stripped)){
|
||||
g_free (stripped);
|
||||
return;
|
||||
}
|
||||
g_hash_table_remove (security, old_key);
|
||||
g_free (old_key);
|
||||
g_free (old_value);
|
||||
} else if (!value)
|
||||
return;
|
||||
|
||||
/* Add new key value */
|
||||
if (value) {
|
||||
gchar *new_value = g_strdup (value);
|
||||
|
||||
if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
|
||||
&& !g_str_has_prefix (key, "wep_key"))
|
||||
strip_string (new_value, '"');
|
||||
g_hash_table_insert (security, g_strdup (key), new_value);
|
||||
}
|
||||
if (stripped)
|
||||
g_hash_table_insert (security, g_strdup (key), stripped);
|
||||
wpa_parser_data_changed = TRUE;
|
||||
}
|
||||
|
||||
@@ -484,7 +491,7 @@ gboolean
|
||||
wpa_add_security (const char *ssid)
|
||||
{
|
||||
if (wpa_has_security (ssid))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
else {
|
||||
GHashTable *security =
|
||||
g_hash_table_new (g_str_hash, g_str_equal);
|
||||
@@ -511,16 +518,16 @@ wpa_add_security (const char *ssid)
|
||||
gboolean
|
||||
wpa_delete_security (const char *ssid)
|
||||
{
|
||||
gpointer orig_key, orig_value;
|
||||
gpointer old_key, old_value;
|
||||
|
||||
g_return_val_if_fail (wsec_table != NULL && ssid != NULL, FALSE);
|
||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting security for %s", ssid);
|
||||
if (!g_hash_table_lookup_extended
|
||||
(wsec_table, ssid, &orig_key, &orig_value))
|
||||
(wsec_table, ssid, &old_key, &old_value))
|
||||
return FALSE;
|
||||
g_hash_table_remove (wsec_table, orig_key);
|
||||
g_free (orig_key);
|
||||
destroy_security ((GHashTable *) orig_value);
|
||||
g_hash_table_remove (wsec_table, old_key);
|
||||
g_free (old_key);
|
||||
destroy_security ((GHashTable *) old_value);
|
||||
wpa_parser_data_changed = TRUE;
|
||||
return TRUE;
|
||||
|
||||
|
Reference in New Issue
Block a user