From 5cf1addbdf20779d8b9f39f4f30ab8394c47e9c8 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 1 Jul 2011 14:56:07 -0500 Subject: [PATCH] core: add utility function to get a connection's shared wifi permission If the connection is a shared wifi connection, return the appropriate permission the user must obtain to use the connection. --- src/NetworkManagerUtils.c | 30 ++++++++++++++++++++++++++++++ src/NetworkManagerUtils.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 5a6a61b643..f96f2aadb1 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -39,6 +39,9 @@ #include "nm-setting-connection.h" #include "nm-setting-ip4-config.h" #include "nm-setting-ip6-config.h" +#include "nm-setting-wireless.h" +#include "nm-setting-wireless-security.h" +#include "nm-manager-auth.h" #include #include @@ -709,6 +712,33 @@ nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels) return FALSE; } +const char * +nm_utils_get_shared_wifi_permission (NMConnection *connection) +{ + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSettingIP4Config *s_ip4; + const char *method = NULL; + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + if (s_ip4) + method = nm_setting_ip4_config_get_method (s_ip4); + + if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) + return NULL; /* Not shared */ + + s_wifi = nm_connection_get_setting_wireless (connection); + if (s_wifi) { + s_wsec = nm_connection_get_setting_wireless_security (connection); + if (nm_setting_wireless_get_security (s_wifi) || s_wsec) + return NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED; + else + return NM_AUTH_PERMISSION_WIFI_SHARE_OPEN; + } + + return NULL; +} + /*********************************/ static void diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index aaa267fb0f..1bf741ed3b 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -52,6 +52,7 @@ void nm_utils_call_dispatcher (const char *action, gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr); gboolean nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels); +const char *nm_utils_get_shared_wifi_permission (NMConnection *connection); GHashTable *value_hash_create (void); void value_hash_add (GHashTable *hash,