Adapt to security-manager API changes 51/138151/2 accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen_4.0_unified accepted/tizen_5.0_unified accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_3.0 tizen_3.0.m2 tizen_5.0 tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/3.0/common/20170714.175006 accepted/tizen/3.0/ivi/20170714.074200 accepted/tizen/3.0/mobile/20170714.074109 accepted/tizen/3.0/tv/20170714.074123 accepted/tizen/3.0/wearable/20170714.074134 accepted/tizen/4.0/unified/20170816.012849 accepted/tizen/4.0/unified/20170816.015555 accepted/tizen/4.0/unified/20170829.015913 accepted/tizen/5.0/unified/20181102.021753 accepted/tizen/5.5/unified/20191031.023230 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090828 accepted/tizen/5.5/unified/wearable/hotfix/20201027.113439 accepted/tizen/6.0/unified/20201030.115218 accepted/tizen/6.0/unified/hotfix/20201103.002958 accepted/tizen/unified/20170713.153302 submit/tizen/20170712.102507 submit/tizen_3.0/20170712.095854 submit/tizen_3.0/20170714.011431 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0/20170828.100004 submit/tizen_4.0/20170828.110004 submit/tizen_4.0_unified/20170814.115522 submit/tizen_5.0/20181101.000004 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185104 submit/tizen_5.5_wearable_hotfix/20201026.184304 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m2_release tizen_5.5.m2_release tizen_6.0.m2_release
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 11 Jul 2017 07:30:10 +0000 (09:30 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 11 Jul 2017 08:46:04 +0000 (10:46 +0200)
Group names were replaced by gids. security_manager_groups_free() has been
replaced by free(). Audit allows both gid and group name as "obj_gid" value
(actually it translates the group name to gid_t anyway).

Tests updated.

Change-Id: Ibcd8d70d1741fe7c2191e95bda8d4c6d68d8b5e2

src/SecurityManager/BaseSecurityManagerWrapper.h
src/SecurityManager/DataProvider.cpp
src/SecurityManager/SecurityManagerWrapper.cpp
src/SecurityManager/SecurityManagerWrapper.h
tests/SecurityManager/FakeSecurityManagerWrapper.h
tests/SecurityManager/data_provider.cpp

index 3cbaaf5..f792977 100644 (file)
 #ifndef SRC_SECURITYMANAGER_BASESECURITYMANAGERWRAPPER_H
 #define SRC_SECURITYMANAGER_BASESECURITYMANAGERWRAPPER_H
 
+#include <sys/types.h>
+
 namespace SecurityManager {
 
 class BaseSecurityManagerWrapper {
 public:
     virtual ~BaseSecurityManagerWrapper() = default;
-    virtual int security_manager_groups_get(char ***groups, size_t *groups_count) = 0;
-    virtual void security_manager_groups_free(char **groups, size_t groups_count) = 0;
+    virtual int security_manager_groups_get(gid_t **groups, size_t *groups_count) = 0;
 
     virtual int SECURITY_MANAGER_SUCCESS_CONST(void) const = 0;
 };
index d861cec..6703db3 100644 (file)
  * @version     1.0
  */
 
-#include <functional>
+#include <stdlib.h>
+
 #include <memory>
+#include <string>
 
 #include <Log/log.h>
 
@@ -35,7 +37,7 @@ DataProvider::DataProvider(BaseSecurityManagerWrapper &smApi) : m_smApi(smApi) {
 Lad::DataProvider::GroupsList DataProvider::getResourceGroups(void) {
     Lad::DataProvider::GroupsList retGroups;
 
-    char **groups = nullptr;
+    gid_t *groups = nullptr;
     size_t groupsLen = 0;
 
     auto getRet = m_smApi.security_manager_groups_get(&groups, &groupsLen);
@@ -44,12 +46,10 @@ Lad::DataProvider::GroupsList DataProvider::getResourceGroups(void) {
         throw ErrorException("Could not get groups from Security Manager");
     }
 
-    auto groupsDeleter = std::bind(&BaseSecurityManagerWrapper::security_manager_groups_free,
-                                   &m_smApi, std::placeholders::_1, groupsLen);
-    std::unique_ptr<char *, std::function<void(char **)>> groupsPtr(groups, groupsDeleter);
+    std::unique_ptr<gid_t, decltype(&::free)> groupsPtr(groups, ::free);
 
     for (size_t i = 0; i < groupsLen; ++i) {
-        retGroups.push_back(groups[i]);
+        retGroups.push_back(std::to_string(groups[i]));
     }
 
     return retGroups;
index 34ed8a6..c6f6465 100644 (file)
 
 namespace SecurityManager {
 
-int SecurityManagerWrapper::security_manager_groups_get(char ***groups, size_t *groups_count) {
+int SecurityManagerWrapper::security_manager_groups_get(gid_t **groups, size_t *groups_count) {
     return ::security_manager_groups_get(groups, groups_count);
 }
 
-void SecurityManagerWrapper::security_manager_groups_free(char **groups, size_t groups_count) {
-    return ::security_manager_groups_free(groups, groups_count);
-}
-
 int SecurityManagerWrapper::SECURITY_MANAGER_SUCCESS_CONST(void) const {
     return ::SECURITY_MANAGER_SUCCESS;
 }
index 8072f8e..f9e963b 100644 (file)
@@ -30,8 +30,7 @@ class SecurityManagerWrapper : public BaseSecurityManagerWrapper {
 public:
     virtual ~SecurityManagerWrapper() = default;
 
-    virtual int security_manager_groups_get(char ***groups, size_t *groups_count);
-    virtual void security_manager_groups_free(char **groups, size_t groups_count);
+    virtual int security_manager_groups_get(gid_t **groups, size_t *groups_count);
 
     virtual int SECURITY_MANAGER_SUCCESS_CONST(void) const;
 };
index d428528..7450d72 100644 (file)
@@ -31,8 +31,7 @@ class FakeSecurityManagerWrapper : public SecurityManager::BaseSecurityManagerWr
 public:
     using BaseSecurityManagerWrapper::BaseSecurityManagerWrapper;
 
-    MOCK_METHOD2(security_manager_groups_get, int(char ***groups, size_t *groups_count));
-    MOCK_METHOD2(security_manager_groups_free, void(char **groups, size_t groups_count));
+    MOCK_METHOD2(security_manager_groups_get, int(gid_t **groups, size_t *groups_count));
 
     MOCK_CONST_METHOD0(SECURITY_MANAGER_SUCCESS_CONST, int(void));
 };
index dad2394..47539de 100644 (file)
  * @version     1.0
  */
 
+#include <stdlib.h>
+
 #include <memory>
 #include <new>
 #include <string>
 #include <vector>
+#include <algorithm>
 
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
@@ -65,7 +68,6 @@ TEST(SecurityManager, getResourceGroups_error) {
  * - call SecurityManager::DataProvider::getResourceGroups()
  * - check if security_manager_groups_get() was called with proper args
  * - check if correct groups are returned by security_manager_groups_get()
- * - check if groups were freed with security_manager_groups_free()
  */
 TEST(SecurityManager, getResourceGroups) {
     using ::testing::DoAll;
@@ -76,36 +78,17 @@ TEST(SecurityManager, getResourceGroups) {
     using ::testing::ElementsAreArray;
     using ::testing::NiceMock;
 
-    std::vector<std::string> expectedGroups = {
-        "group1", "group2"
-    };
-
-    auto groupsDeleter = [] (char **groups) {
-        if (groups == nullptr)
-            return;
-        for (size_t i = 0; groups[i] != nullptr; ++i)
-            free(groups[i]);
-        free(groups);
-    };
-
-    std::unique_ptr<char *, decltype(groupsDeleter)> groups(
-        static_cast<char **>(calloc(expectedGroups.size(), sizeof(char *))),
-        groupsDeleter);
-
-    if (groups == nullptr)
-        throw std::bad_alloc();
-
-    auto freeGroups = [&groups] () {
-        groups.reset();
-    };
-
-    size_t i = 0;
-    for (const auto &g : expectedGroups) {
-        groups.get()[i] = strdup(g.c_str());
-        if (groups.get()[i] == nullptr)
-            throw std::bad_alloc();
-        ++i;
-    }
+    const size_t SIZE = 3;
+
+    // getResourceGroups should free it
+    gid_t *groups = static_cast<gid_t*>(calloc(SIZE, sizeof(gid_t)));
+    groups[0] = 3;
+    groups[1] = 45;
+    groups[2] = 21;
+
+    std::vector<std::string> expectedGroups(SIZE);
+    for (size_t i = 0; i < SIZE; i++)
+        expectedGroups[i] = std::to_string(groups[i]);
 
     NiceMock<FakeSecurityManagerWrapper> smApi;
 
@@ -115,11 +98,9 @@ TEST(SecurityManager, getResourceGroups) {
         .WillByDefault(Return(SECURITY_MANAGER_SUCCESS_CONST));
 
     EXPECT_CALL(smApi, security_manager_groups_get(NotNull(), NotNull()))
-        .WillOnce(DoAll(SetArgPointee<0>(groups.get()),
-                        SetArgPointee<1>(expectedGroups.size()),
+        .WillOnce(DoAll(SetArgPointee<0>(groups),
+                        SetArgPointee<1>(SIZE),
                         Return(SECURITY_MANAGER_SUCCESS_CONST)));
-    EXPECT_CALL(smApi, security_manager_groups_free(groups.get(), expectedGroups.size()))
-        .WillOnce(InvokeWithoutArgs(freeGroups));
 
     SecurityManager::DataProvider dp(smApi);