CKM: certificates refreshed (some were already expired).
[platform/core/test/security-tests.git] / tests / common / tests_common.cpp
index 555b8b5..1bf0236 100644 (file)
@@ -58,17 +58,17 @@ int smack_check(void)
  * Dropping root privileges
  * returns 0 on success, 1 on error
  */
-int drop_root_privileges(void)
+int drop_root_privileges(uid_t appUid, gid_t appGid)
 {
     if (getuid() == 0) {
         /* process is running as root, drop privileges */
-        if (setgid(APP_GID) != 0)
+        if (setgid(appGid) != 0)
             return 1;
-        if (setuid(APP_UID) != 0)
+        if (setuid(appUid) != 0)
             return 1;
     }
     uid_t uid = getuid();
-    if (uid == APP_UID)
+    if (uid == appUid)
         return 0;
 
     return 1;
@@ -77,7 +77,7 @@ int drop_root_privileges(void)
 void setLabelForSelf(const int line, const char *label)
 {
     int ret = smack_set_label_for_self(label);
-    RUNNER_ASSERT_MSG_BT(ret == 0, "Error in smack_set_label_for_self(): " << ret << ", line: " << line);
+    RUNNER_ASSERT_MSG(ret == 0, "Error in smack_set_label_for_self(): " << ret << ", line: " << line);
 }
 
 /*
@@ -87,11 +87,11 @@ void add_process_group(const char* group_name)
 {
     // get group ID by group name
     group *gr = getgrnam(group_name);
-    RUNNER_ASSERT_MSG_BT(gr != NULL, "Group '" << group_name << "' does not exist.");
+    RUNNER_ASSERT_ERRNO_MSG(gr != nullptr, "getgrnam failed on '" << group_name << "' group");
     const gid_t new_group_id = gr->gr_gid;
 
     // get number of groups that the current process belongs to
-    int ngroups = getgroups(0, NULL);
+    int ngroups = getgroups(0, nullptr);
 
     //allocate groups table + space for new group entry
     std::vector<gid_t> groups(ngroups + 1);
@@ -103,8 +103,7 @@ void add_process_group(const char* group_name)
     // add new group & apply change
     groups[ngroups] = new_group_id;
     int ret = setgroups(groups.size(), groups.data());
-    int error = errno;
-    RUNNER_ASSERT_MSG_BT(ret == 0, "setgroups() failed. " << strerror(error));
+    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "setgroups() failed");
 }
 
 /*
@@ -114,10 +113,10 @@ void remove_process_group(const char* group_name)
 {
     // get group ID by group name
     group *gr = getgrnam(group_name);
-    RUNNER_ASSERT_MSG_BT(gr != NULL, "Group '" << group_name << "' does not exist.");
+    RUNNER_ASSERT_ERRNO_MSG(gr != nullptr, "getgrnam failed on '" << group_name << "' group");
     const gid_t new_group_id = gr->gr_gid;
 
-    int ngroups = getgroups(0, NULL);
+    int ngroups = getgroups(0, nullptr);
     std::vector<gid_t> groups(ngroups);
     getgroups(ngroups, groups.data());
 
@@ -127,8 +126,7 @@ void remove_process_group(const char* group_name)
     if (groups.size() != (size_t)ngroups) {
         // apply change
         int ret = setgroups(groups.size(), groups.data());
-        int error = errno;
-        RUNNER_ASSERT_MSG_BT(ret == 0, "setgroups() failed. " << strerror(error));
+        RUNNER_ASSERT_ERRNO_MSG(ret == 0, "setgroups() failed");
     }
 }