ifnet: plugin updates and shared connection support
This commit is contained in:
@@ -57,8 +57,15 @@ update_connection_id (NMConnection *connection, const char *conn_name)
|
|||||||
gchar *idstr = NULL;
|
gchar *idstr = NULL;
|
||||||
gchar *uuid_base = NULL;
|
gchar *uuid_base = NULL;
|
||||||
gchar *uuid = NULL;
|
gchar *uuid = NULL;
|
||||||
|
int name_len;
|
||||||
NMSettingConnection *setting;
|
NMSettingConnection *setting;
|
||||||
|
|
||||||
|
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);
|
idstr = g_strdup_printf ("%s (%s)", get_prefix (), conn_name);
|
||||||
uuid_base = idstr;
|
uuid_base = idstr;
|
||||||
uuid = nm_utils_uuid_generate_from_string (uuid_base);
|
uuid = nm_utils_uuid_generate_from_string (uuid_base);
|
||||||
@@ -570,7 +577,7 @@ make_ip4_setting (NMConnection *connection,
|
|||||||
|
|
||||||
NMSettingIP4Config *ip4_setting =
|
NMSettingIP4Config *ip4_setting =
|
||||||
NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
|
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);
|
gboolean is_static_block = is_static_ip4 (conn_name);
|
||||||
ip_block *iblock = NULL;
|
ip_block *iblock = NULL;
|
||||||
|
|
||||||
@@ -582,12 +589,40 @@ make_ip4_setting (NMConnection *connection,
|
|||||||
&& strstr (value, "nogateway") ? TRUE : FALSE, NULL);
|
&& strstr (value, "nogateway") ? TRUE : FALSE, NULL);
|
||||||
|
|
||||||
if (!is_static_block) {
|
if (!is_static_block) {
|
||||||
|
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,
|
g_object_set (ip4_setting,
|
||||||
NM_SETTING_IP4_CONFIG_METHOD,
|
NM_SETTING_IP4_CONFIG_METHOD,
|
||||||
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||||
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
|
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
|
||||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using DHCP for %s",
|
else if (!strcmp (method, "autoip")){
|
||||||
conn_name);
|
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 {
|
}else {
|
||||||
iblock = convert_ip4_config_block (conn_name);
|
iblock = convert_ip4_config_block (conn_name);
|
||||||
if (!iblock) {
|
if (!iblock) {
|
||||||
@@ -612,18 +647,9 @@ make_ip4_setting (NMConnection *connection,
|
|||||||
g_object_set (ip4_setting,
|
g_object_set (ip4_setting,
|
||||||
NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES,
|
NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES,
|
||||||
TRUE, NULL);
|
TRUE, NULL);
|
||||||
if (nm_setting_ip4_config_add_address
|
if (!nm_setting_ip4_config_add_address (ip4_setting, ip4_addr))
|
||||||
(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 {
|
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||||
"ignoring duplicate IP4 address");
|
"ignoring duplicate IP4 address");
|
||||||
}
|
|
||||||
nm_ip4_address_unref (ip4_addr);
|
nm_ip4_address_unref (ip4_addr);
|
||||||
current_iblock = iblock;
|
current_iblock = iblock;
|
||||||
iblock = iblock->next;
|
iblock = iblock->next;
|
||||||
@@ -637,7 +663,7 @@ make_ip4_setting (NMConnection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add dhcp hostname and client id */
|
/* add dhcp hostname and client id */
|
||||||
if (!is_static_block) {
|
if (!is_static_block && !strcmp (method, "dhcp")) {
|
||||||
gchar *dhcp_hostname, *client_id;
|
gchar *dhcp_hostname, *client_id;
|
||||||
|
|
||||||
get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
|
get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
|
||||||
@@ -1253,7 +1279,6 @@ make_wep_setting (const char *ssid, GError **error)
|
|||||||
static char *
|
static char *
|
||||||
parse_wpa_psk (const char *psk, GError **error)
|
parse_wpa_psk (const char *psk, GError **error)
|
||||||
{
|
{
|
||||||
const char *p = psk;
|
|
||||||
char *hashed = NULL;
|
char *hashed = NULL;
|
||||||
gboolean quoted = FALSE;
|
gboolean quoted = FALSE;
|
||||||
|
|
||||||
@@ -1286,7 +1311,7 @@ parse_wpa_psk (const char *psk, GError **error)
|
|||||||
strip_string (stripped, '"');
|
strip_string (stripped, '"');
|
||||||
|
|
||||||
/* Length check */
|
/* 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,
|
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||||
"Invalid WPA_PSK (passphrases must be between "
|
"Invalid WPA_PSK (passphrases must be between "
|
||||||
"8 and 63 characters long (inclusive))");
|
"8 and 63 characters long (inclusive))");
|
||||||
@@ -2123,7 +2148,8 @@ write_wireless_security_setting (NMConnection * connection,
|
|||||||
} else if (!strcmp (key_mgmt, "wpa-eap")) {
|
} else if (!strcmp (key_mgmt, "wpa-eap")) {
|
||||||
wpa_set_data (conn_name, "key_mgmt", "WPA-EAP");
|
wpa_set_data (conn_name, "key_mgmt", "WPA-EAP");
|
||||||
wpa = TRUE;
|
wpa = TRUE;
|
||||||
}
|
} else
|
||||||
|
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Unknown key_mgmt: %s", key_mgmt);
|
||||||
|
|
||||||
if (auth_alg) {
|
if (auth_alg) {
|
||||||
if (!strcmp (auth_alg, "shared"))
|
if (!strcmp (auth_alg, "shared"))
|
||||||
@@ -2218,6 +2244,8 @@ write_wireless_security_setting (NMConnection * connection,
|
|||||||
g_string_append (quoted, psk);
|
g_string_append (quoted, psk);
|
||||||
g_string_append_c (quoted, '"');
|
g_string_append_c (quoted, '"');
|
||||||
}
|
}
|
||||||
|
/* psk will be lost here if we don't check it for NULL */
|
||||||
|
if (psk)
|
||||||
wpa_set_data (conn_name, "psk",
|
wpa_set_data (conn_name, "psk",
|
||||||
quoted ? quoted->str : (gchar *) psk);
|
quoted ? quoted->str : (gchar *) psk);
|
||||||
if (quoted)
|
if (quoted)
|
||||||
@@ -2235,10 +2263,12 @@ update_wireless_ssid (NMConnection *connection,
|
|||||||
const char *ssid,
|
const char *ssid,
|
||||||
gboolean hex)
|
gboolean hex)
|
||||||
{
|
{
|
||||||
|
if(strcmp (conn_name, ssid)){
|
||||||
ifnet_delete_network (conn_name);
|
ifnet_delete_network (conn_name);
|
||||||
wpa_delete_security (conn_name);
|
wpa_delete_security (conn_name);
|
||||||
|
}
|
||||||
|
|
||||||
ifnet_add_connection (ssid, "wireless");
|
ifnet_add_network (ssid, "wireless");
|
||||||
wpa_add_security (ssid);
|
wpa_add_security (ssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2279,11 +2309,12 @@ write_wireless_setting (NMConnection *connection,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the SSID contains any non-printable characters, we need to use the
|
/* If the SSID contains any non-alnum characters, we need to use
|
||||||
* hex notation of the SSID instead.
|
* the hex notation of the SSID instead. (Because openrc doesn't
|
||||||
|
* support these characters, see bug #356337)
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ssid->len; i++) {
|
for (i = 0; i < ssid->len; i++) {
|
||||||
if (!isprint (ssid->data[i])) {
|
if (!isalnum (ssid->data[i])) {
|
||||||
hex_ssid = TRUE;
|
hex_ssid = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2482,11 +2513,14 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err
|
|||||||
}
|
}
|
||||||
ifnet_set_data (conn_name, "config", ips->str);
|
ifnet_set_data (conn_name, "config", ips->str);
|
||||||
g_string_free (ips, TRUE);
|
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");
|
ifnet_set_data (conn_name, "config", "dhcp");
|
||||||
|
|
||||||
/* DNS Servers */
|
/* DNS Servers */
|
||||||
ifnet_set_data (conn_name, "dns_servers", NULL);
|
|
||||||
num = nm_setting_ip4_config_get_num_dns (s_ip4);
|
num = nm_setting_ip4_config_get_num_dns (s_ip4);
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
dns = g_string_new (NULL);
|
dns = g_string_new (NULL);
|
||||||
@@ -2779,7 +2813,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection,
|
|||||||
const char *conn_name,
|
const char *conn_name,
|
||||||
const char *config_file,
|
const char *config_file,
|
||||||
const char *wpa_file,
|
const char *wpa_file,
|
||||||
const char **out_new_name,
|
gchar **out_new_name,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
@@ -2800,6 +2834,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type = nm_setting_connection_get_connection_type (s_con);
|
type = nm_setting_connection_get_connection_type (s_con);
|
||||||
if (!type) {
|
if (!type) {
|
||||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
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);
|
wpa_flush_to_file (wpa_file);
|
||||||
|
|
||||||
if (out_new_name)
|
if (out_new_name)
|
||||||
*out_new_name = new_name;
|
*out_new_name = g_strdup (conn_name);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return success;
|
return success;
|
||||||
@@ -2901,7 +2936,7 @@ get_wired_name ()
|
|||||||
for (; i < 256; i++) {
|
for (; i < 256; i++) {
|
||||||
gchar *conn_name = g_strdup_printf ("eth%d", 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;
|
return conn_name;
|
||||||
} else
|
} else
|
||||||
g_free (conn_name);
|
g_free (conn_name);
|
||||||
@@ -2918,7 +2953,7 @@ get_ppp_name ()
|
|||||||
for (; i < 256; i++) {
|
for (; i < 256; i++) {
|
||||||
gchar *conn_name = g_strdup_printf ("ppp%d", 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;
|
return conn_name;
|
||||||
} else
|
} else
|
||||||
g_free (conn_name);
|
g_free (conn_name);
|
||||||
@@ -3015,7 +3050,7 @@ ifnet_add_new_connection (NMConnection *connection,
|
|||||||
goto out;
|
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,
|
success = ifnet_update_parsers_by_connection (connection,
|
||||||
new_name,
|
new_name,
|
||||||
config_file,
|
config_file,
|
||||||
|
@@ -32,7 +32,7 @@ gboolean ifnet_update_parsers_by_connection (NMConnection *connection,
|
|||||||
const char *conn_name,
|
const char *conn_name,
|
||||||
const char *config_file,
|
const char *config_file,
|
||||||
const char *wpa_file,
|
const char *wpa_file,
|
||||||
const char **out_new_name,
|
gchar **out_new_name,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean ifnet_delete_connection_in_parsers (const char *conn_name,
|
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
|
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)) {
|
if (add_new_connection_config (type, name)) {
|
||||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding network for %s", name);
|
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding network for %s", name);
|
||||||
net_parser_data_changed = TRUE;
|
net_parser_data_changed = TRUE;
|
||||||
@@ -69,7 +71,7 @@ ifnet_add_connection (const char *name, const char *type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
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;
|
return g_hash_table_lookup (conn_table, conn_name) != NULL;
|
||||||
}
|
}
|
||||||
@@ -375,23 +377,31 @@ ifnet_get_data (const char *conn_name, const char *key)
|
|||||||
void
|
void
|
||||||
ifnet_set_data (const char *conn_name, const char *key, const char *value)
|
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);
|
GHashTable *conn = g_hash_table_lookup (conn_table, conn_name);
|
||||||
|
gchar * stripped = NULL;
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME, "%s does not exsit!", conn_name);
|
||||||
"%s does not exsit!", conn_name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Remove existing key value pair */
|
if (value){
|
||||||
if (g_hash_table_lookup_extended (conn, key, &orin_key, &orin_value)) {
|
stripped = g_strdup (value);
|
||||||
g_hash_table_remove (conn, orin_key);
|
strip_string (stripped, '"');
|
||||||
g_free (orin_key);
|
|
||||||
g_free (orin_value);
|
|
||||||
}
|
}
|
||||||
if (value)
|
/* Remove existing key value pair */
|
||||||
g_hash_table_insert (conn, g_strdup (key),
|
if (g_hash_table_lookup_extended (conn, key, &old_key, &old_value)) {
|
||||||
strip_string (g_strdup (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;
|
net_parser_data_changed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +471,7 @@ ifnet_flush_to_file (const char *config_file)
|
|||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
|
||||||
if (!net_parser_data_changed)
|
if (!net_parser_data_changed)
|
||||||
return FALSE;
|
return TRUE;
|
||||||
if (!conn_table || !global_settings_table)
|
if (!conn_table || !global_settings_table)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@@ -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_data (const char *conn_name, const char *key);
|
||||||
const char *ifnet_get_global_data (const char *key);
|
const char *ifnet_get_global_data (const char *key);
|
||||||
const char *ifnet_get_global_setting (const char *group, 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 */
|
/* Writer functions */
|
||||||
gboolean ifnet_flush_to_file (const char *config_file);
|
gboolean ifnet_flush_to_file (const char *config_file);
|
||||||
void ifnet_set_data (const char *conn_name, const char *key, const char *value);
|
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);
|
gboolean ifnet_delete_network (const char *conn_name);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -274,6 +274,10 @@ is_static_ip4 (const char *conn_name)
|
|||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
if (!strcmp (data, "shared"))
|
||||||
|
return FALSE;
|
||||||
|
if (!strcmp (data, "autoip"))
|
||||||
|
return FALSE;
|
||||||
dhcp6 = strstr (data, "dhcp6");
|
dhcp6 = strstr (data, "dhcp6");
|
||||||
if (dhcp6) {
|
if (dhcp6) {
|
||||||
gchar *dhcp4;
|
gchar *dhcp4;
|
||||||
@@ -946,8 +950,8 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id)
|
|||||||
else if ((tmp = strstr (line, "send host-name")) != NULL) {
|
else if ((tmp = strstr (line, "send host-name")) != NULL) {
|
||||||
tmp += strlen ("send host-name");
|
tmp += strlen ("send host-name");
|
||||||
g_strstrip (tmp);
|
g_strstrip (tmp);
|
||||||
strip_string (tmp, '"');
|
|
||||||
strip_string (tmp, ';');
|
strip_string (tmp, ';');
|
||||||
|
strip_string (tmp, '"');
|
||||||
if (tmp[0] != '\0')
|
if (tmp[0] != '\0')
|
||||||
*hostname = g_strdup (tmp);
|
*hostname = g_strdup (tmp);
|
||||||
else
|
else
|
||||||
|
@@ -61,17 +61,19 @@ nm_ifnet_connection_new (const char *conn_name, NMConnection *source)
|
|||||||
{
|
{
|
||||||
NMConnection *tmp;
|
NMConnection *tmp;
|
||||||
GObject *object;
|
GObject *object;
|
||||||
GError **error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (conn_name != NULL, NULL);
|
g_return_val_if_fail (conn_name != NULL, NULL);
|
||||||
|
|
||||||
if (source)
|
if (source)
|
||||||
tmp = g_object_ref (source);
|
tmp = g_object_ref (source);
|
||||||
else {
|
else {
|
||||||
tmp = ifnet_update_connection_from_config_block (conn_name, error);
|
tmp = ifnet_update_connection_from_config_block (conn_name, &error);
|
||||||
if (!tmp)
|
if (!tmp){
|
||||||
|
g_error_free (error);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL);
|
object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL);
|
||||||
if (!object) {
|
if (!object) {
|
||||||
@@ -98,7 +100,7 @@ commit_changes (NMSettingsConnection *connection,
|
|||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection);
|
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);
|
g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0);
|
||||||
if (!ifnet_update_parsers_by_connection (NM_CONNECTION (connection),
|
if (!ifnet_update_parsers_by_connection (NM_CONNECTION (connection),
|
||||||
@@ -116,7 +118,7 @@ commit_changes (NMSettingsConnection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_free (priv->conn_name);
|
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);
|
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);
|
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully updated %s", priv->conn_name);
|
||||||
|
@@ -88,8 +88,7 @@ update_system_hostname (gpointer config)
|
|||||||
{
|
{
|
||||||
SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);
|
SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);
|
||||||
|
|
||||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Updating hostname");
|
if (priv->hostname)
|
||||||
|
|
||||||
g_free (priv->hostname);
|
g_free (priv->hostname);
|
||||||
priv->hostname = read_hostname (IFNET_SYSTEM_HOSTNAME_FILE);
|
priv->hostname = read_hostname (IFNET_SYSTEM_HOSTNAME_FILE);
|
||||||
|
|
||||||
@@ -170,8 +169,6 @@ monitor_file_changes (const char *filename,
|
|||||||
info);
|
info);
|
||||||
g_signal_connect (monitor, "changed", G_CALLBACK (file_changed),
|
g_signal_connect (monitor, "changed", G_CALLBACK (file_changed),
|
||||||
info);
|
info);
|
||||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Monitoring %s", filename);
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||||
"Monitoring %s failed, error: %s", filename,
|
"Monitoring %s failed, error: %s", filename,
|
||||||
@@ -288,7 +285,7 @@ reload_connections (gpointer config)
|
|||||||
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (old));
|
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (old));
|
||||||
g_hash_table_remove (priv->config_connections, conn_name);
|
g_hash_table_remove (priv->config_connections, conn_name);
|
||||||
g_hash_table_insert (priv->config_connections, g_strdup (conn_name), 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_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, new);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -301,7 +298,7 @@ reload_connections (gpointer config)
|
|||||||
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
|
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
|
||||||
} else if (new) {
|
} else if (new) {
|
||||||
g_hash_table_insert (priv->config_connections, g_strdup (conn_name), 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_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);
|
g_hash_table_insert (new_conn_names, (gpointer) conn_name, (gpointer) conn_name);
|
||||||
@@ -389,21 +386,6 @@ SCPluginIfnet_init (NMSystemConfigInterface * config)
|
|||||||
// GFileMonitor setup
|
// GFileMonitor setup
|
||||||
setup_monitors (NULL, config);
|
setup_monitors (NULL, config);
|
||||||
reload_connections (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 */
|
/* Read hostname */
|
||||||
update_system_hostname (self);
|
update_system_hostname (self);
|
||||||
|
|
||||||
|
@@ -367,7 +367,7 @@ wpa_flush_to_file (const char *config_file)
|
|||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
|
||||||
if (!wpa_parser_data_changed)
|
if (!wpa_parser_data_changed)
|
||||||
return FALSE;
|
return TRUE;
|
||||||
if (!wsec_table || !wsec_global_table)
|
if (!wsec_table || !wsec_global_table)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@@ -449,28 +449,35 @@ wpa_flush_to_file (const char *config_file)
|
|||||||
void
|
void
|
||||||
wpa_set_data (const char *ssid, const char *key, const char *value)
|
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);
|
GHashTable *security = g_hash_table_lookup (wsec_table, ssid);
|
||||||
|
gchar * stripped = NULL;
|
||||||
|
|
||||||
g_return_if_fail (security != NULL);
|
g_return_if_fail (security != NULL);
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add new key value */
|
|
||||||
if (value){
|
if (value){
|
||||||
gchar *new_value = g_strdup (value);
|
stripped = g_strdup(value);
|
||||||
|
|
||||||
if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
|
if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
|
||||||
&& !g_str_has_prefix (key, "wep_key"))
|
&& !g_str_has_prefix (key, "wep_key"))
|
||||||
strip_string (new_value, '"');
|
strip_string (stripped, '"');
|
||||||
g_hash_table_insert (security, g_strdup (key), new_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remove old key value pairs */
|
||||||
|
if (g_hash_table_lookup_extended
|
||||||
|
(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 (stripped)
|
||||||
|
g_hash_table_insert (security, g_strdup (key), stripped);
|
||||||
wpa_parser_data_changed = TRUE;
|
wpa_parser_data_changed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,7 +491,7 @@ gboolean
|
|||||||
wpa_add_security (const char *ssid)
|
wpa_add_security (const char *ssid)
|
||||||
{
|
{
|
||||||
if (wpa_has_security (ssid))
|
if (wpa_has_security (ssid))
|
||||||
return FALSE;
|
return TRUE;
|
||||||
else {
|
else {
|
||||||
GHashTable *security =
|
GHashTable *security =
|
||||||
g_hash_table_new (g_str_hash, g_str_equal);
|
g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
@@ -511,16 +518,16 @@ wpa_add_security (const char *ssid)
|
|||||||
gboolean
|
gboolean
|
||||||
wpa_delete_security (const char *ssid)
|
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);
|
g_return_val_if_fail (wsec_table != NULL && ssid != NULL, FALSE);
|
||||||
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting security for %s", ssid);
|
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting security for %s", ssid);
|
||||||
if (!g_hash_table_lookup_extended
|
if (!g_hash_table_lookup_extended
|
||||||
(wsec_table, ssid, &orig_key, &orig_value))
|
(wsec_table, ssid, &old_key, &old_value))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
g_hash_table_remove (wsec_table, orig_key);
|
g_hash_table_remove (wsec_table, old_key);
|
||||||
g_free (orig_key);
|
g_free (old_key);
|
||||||
destroy_security ((GHashTable *) orig_value);
|
destroy_security ((GHashTable *) old_value);
|
||||||
wpa_parser_data_changed = TRUE;
|
wpa_parser_data_changed = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user