dbus polich : modified to check priviliege. 57/190357/2 accepted/tizen/4.0/unified/20181004.120025 submit/tizen_4.0/20181001.080238
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 1 Oct 2018 06:17:38 +0000 (15:17 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 1 Oct 2018 07:54:10 +0000 (16:54 +0900)
Change-Id: Ib0e613109507cf2f0d7c9691bfd27bf4a92bf3e5
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
(cherry picked from commit 4de53f3e66193d10e0e6da6d6194335641450855)

include/wifi-mesh_dbus.h
include/wifi-mesh_private.h
src/wifi-mesh-dbus.c
src/wifi-mesh.c

index 348a9b7..a45d55c 100644 (file)
@@ -76,6 +76,7 @@ int _wifi_mesh_get_mpath_info(wifi_mesh_h handle, mesh_found_mpath_cb cb, void *
 int _wifi_mesh_set_interfaces(wifi_mesh_h handle, const char *mesh, const char *gate, const char *softap);
 int _wifi_mesh_get_meshconf_info(wifi_mesh_h handle,
                                wifi_mesh_meshconf_info_h *meshconf);
+int wifi_mesh_check_privilege();
 
 #ifdef __cplusplus
 }
index d257aaa..f5d93de 100644 (file)
@@ -32,7 +32,7 @@
                return WIFI_MESH_ERROR_INVALID_PARAMETER; \
        }
 
-#if 0
+#ifdef CHECK_WIFI_MESH_FEATURE
 #define CHECK_FEATURE_SUPPORTED(feature_name) { \
        bool mesh_supported = FALSE; \
        if (!system_info_get_platform_bool(feature_name, &mesh_supported)) { \
 }
 #else
 #define CHECK_FEATURE_SUPPORTED(feature_name) { \
-               LOGE("[Feature] Should be check !"); \
-       }
+       LOGE("[Feature] Should be check !"); \
+}
+#endif
+
+#ifdef CHECK_WIFI_MESH_PRIVILEGE
+#define CHECK_PRIVILEGE() { \
+       int wifi_mesh_check_priv = wifi_mesh_check_privilege(); \
+       if (wifi_mesh_check_priv != WIFI_MESH_ERROR_NONE) { \
+               return wifi_mesh_check_priv; \
+       } \
+}
+#else
+#define CHECK_PRIVILEGE() { \
+       LOGE("[Privilege] Should be check !"); \
+}
 #endif
 
 typedef struct mesh_handle {
index 191529b..4bfbdb2 100644 (file)
@@ -247,8 +247,12 @@ int _wifi_mesh_get_scan_result(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -315,8 +319,12 @@ int _wifi_mesh_find_peers(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -639,8 +647,12 @@ int _wifi_mesh_enable(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -687,8 +699,12 @@ int _wifi_mesh_disable(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
        h->event_handler = NULL;
@@ -729,8 +745,12 @@ int _wifi_mesh_scan(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -770,8 +790,12 @@ int _wifi_mesh_specific_scan(wifi_mesh_h handle, const char* ssid, int channel)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -811,8 +835,12 @@ int _wifi_mesh_cancel_scan(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -959,8 +987,12 @@ int _wifi_mesh_enable_mesh(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1000,8 +1032,12 @@ int _wifi_mesh_disable_mesh(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1010,6 +1046,7 @@ int _wifi_mesh_disable_mesh(wifi_mesh_h handle)
 
 int _wifi_mesh_is_started(wifi_mesh_h handle, bool* is_started)
 {
+       int result = WIFI_MESH_ERROR_NONE;
        GVariant *variant = NULL;
        GError *error = NULL;
        gboolean state;
@@ -1040,8 +1077,12 @@ int _wifi_mesh_is_started(wifi_mesh_h handle, bool* is_started)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1084,8 +1125,12 @@ int _wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1193,8 +1238,12 @@ int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _netw
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1234,8 +1283,12 @@ int _wifi_mesh_set_gate(wifi_mesh_h handle, bool gate_announce, int hwmp_root_mo
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1275,8 +1328,12 @@ int _wifi_mesh_unset_gate(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1320,8 +1377,12 @@ int _wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid,
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1373,8 +1434,12 @@ int _wifi_mesh_get_softap(wifi_mesh_h handle, char **ssid, int *channel,
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1414,8 +1479,12 @@ int _wifi_mesh_enable_softap(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1455,16 +1524,21 @@ int _wifi_mesh_disable_softap(wifi_mesh_h handle)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
        return result;
 }
 
-int _wifi_mesh_is_softap_started(wifi_mesh_h handle, bool *result)
+int _wifi_mesh_is_softap_started(wifi_mesh_h handle, bool *ret)
 {
+       int result = WIFI_MESH_ERROR_NONE;
        GVariant *variant = NULL;
        GError *error = NULL;
        struct mesh_handle *h = handle;
@@ -1487,13 +1561,17 @@ int _wifi_mesh_is_softap_started(wifi_mesh_h handle, bool *result)
                                "is_softap_enabled", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                &error);
        if (variant) {
-               g_variant_get(variant, "(b)", result);
-               LOGD("check_softap_status status %d", *result);
+               g_variant_get(variant, "(b)", ret);
+               LOGD("check_softap_status status %d", *ret);
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1534,8 +1612,12 @@ int _mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h _network)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1576,8 +1658,12 @@ int _mesh_connect_network(wifi_mesh_h handle, wifi_mesh_network_h _network)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1618,8 +1704,12 @@ int _mesh_disconnect_network(wifi_mesh_h handle, wifi_mesh_network_h _network)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1662,8 +1752,12 @@ int _mesh_forget_network(wifi_mesh_h handle, wifi_mesh_network_h _network)
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1824,8 +1918,12 @@ int _wifi_mesh_get_stations_info(wifi_mesh_h handle,
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -1926,8 +2024,12 @@ int _wifi_mesh_get_mpath_info(wifi_mesh_h handle, mesh_found_mpath_cb cb, void *
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -2026,8 +2128,12 @@ int _wifi_mesh_get_meshconf_info(wifi_mesh_h handle,
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
-               return WIFI_MESH_ERROR_IO_ERROR;
+               return result ;
                /* LCOV_EXCL_STOP */
        }
 
@@ -2067,11 +2173,45 @@ int _wifi_mesh_set_interfaces(wifi_mesh_h handle, const char *mesh, const char *
        } else if (error) {
                /* LCOV_EXCL_START */
                LOGE("Failed DBus call [%s]", error->message);
+               if (strstr(error->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
                g_error_free(error);
+               return result ;
+               /* LCOV_EXCL_STOP */
+       }
+
+       return result;
+}
+
+int wifi_mesh_check_privilege()
+{
+       int result = WIFI_MESH_ERROR_NONE;
+       GVariant *variant = NULL;
+       GError *dbus_err = NULL;
+
+       if (NULL == _gproxy_mesh_service) {
+               /* LCOV_EXCL_START */
+               LOGE("I/O error");
                return WIFI_MESH_ERROR_IO_ERROR;
                /* LCOV_EXCL_STOP */
        }
 
+       variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "check_privilege",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &dbus_err);
+       if (variant) {
+               g_variant_unref(variant);
+       } else if (dbus_err) {
+               LOGE("Failed to check wifi-mesh privilege [%s]", dbus_err->message);
+               if (strstr(dbus_err->message, "AccessDenied"))
+                       result = WIFI_MESH_ERROR_PERMISSION_DENIED;
+               else
+                       result = WIFI_MESH_ERROR_IO_ERROR;
+
+               g_error_free(dbus_err);
+       }
+
        return result;
 }
 
index fd9ade0..6bb9b89 100644 (file)
@@ -31,6 +31,7 @@ EXPORT_API int wifi_mesh_network_new(wifi_mesh_network_h* network)
        struct mesh_network_s *net;
 
        CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+       CHECK_PRIVILEGE();
 
        if (NULL == network) {
                /* LCOV_EXCL_START */
@@ -93,6 +94,7 @@ EXPORT_API int wifi_mesh_network_new_with(wifi_mesh_network_h* network, const ch
        struct mesh_network_s *net;
 
        CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+       CHECK_PRIVILEGE();
 
        if (NULL == network) {
                /* LCOV_EXCL_START */
@@ -711,8 +713,7 @@ EXPORT_API int wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid,
        if (channel <= 13) {
                buf[0] = 'g';
                buf[1] = 0;
-       }
-       else {
+       } else {
                buf[0] = 'a';
                buf[1] = 0;
        }