Remove hardcode uid's & gid's
authorMarek Smolinski <m.smolinski@samsung.com>
Tue, 24 Sep 2013 06:24:45 +0000 (08:24 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 14:19:10 +0000 (15:19 +0100)
    [Issue#]       SSDWSSP-532
    [Feature/Bug]  N/A
    [Cause]
    [Solution]     Add gid's & uid's in common header

    [Verification] Build, run tests

Change-Id: I80aae956613896de6f19f82b417cd3a54214a08e

tests/common/tests_common.h
tests/libprivilege-control-tests/test_cases_nosmack.cpp
tests/security-server-tests/security_server_tests_client_smack.cpp
tests/security-server-tests/security_server_tests_server.cpp
tests/security-server-tests/security_server_tests_weird_arguments.cpp

index 77a63fa..bca0da2 100644 (file)
 int smack_runtime_check(void);
 int smack_check(void);
 
+const uid_t APP_UID = 5000;
+const gid_t APP_GID = 5000;
+
+const uid_t DB_ALARM_UID = 6001;
+const gid_t DB_ALARM_GID = 6001;
+
 #define RUNNER_TEST_SMACK(Proc)                                                     \
     void Proc();                                                                    \
     static int Static##Proc##Init()                                                 \
index 7185034..75cb01f 100644 (file)
@@ -41,9 +41,6 @@
 #include <tests_common.h>
 #include <libprivilege-control_test_common.h>
 
-#define APP_GID       5000
-#define APP_UID       5000
-
 #define APP_USER_NAME "app"
 #define APP_HOME_DIR  "/opt/home/app"
 
index d0ac8e0..2cefdb5 100644 (file)
@@ -82,13 +82,13 @@ int drop_root_privileges()
 {
     if (getuid() == 0) {
         /* process is running as root, drop privileges */
-        if (setgid(5000) != 0)
+        if (setgid(APP_GID) != 0)
             return 1;
-        if (setuid(5000) != 0)
+        if (setuid(APP_UID) != 0)
             return 1;
     }
-    int uid = getuid();
-    if (uid == 5000)
+    uid_t uid = getuid();
+    if (uid == APP_UID)
         return 0;
 
     return 1;
@@ -654,7 +654,7 @@ RUNNER_CHILD_TEST_SMACK(tc11_security_server_get_uid_by_cookie_smack)
     RUNNER_ASSERT_MSG(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
     RUNNER_ASSERT_MSG(smack_revoke_subject("BialyMis") == 0, "Error in smack_revoke_subject");
     //drop privileges
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     //checking function
     uid_t cookieUid;
@@ -677,7 +677,7 @@ RUNNER_CHILD_TEST_SMACK(tc12_security_server_get_uid_by_cookie_smack)
     RUNNER_ASSERT_MSG(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
     RUNNER_ASSERT_MSG(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
     //drop privileges
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     //checking function
     uid_t cookieUid;
@@ -698,7 +698,7 @@ RUNNER_CHILD_TEST_NOSMACK(tc12_security_server_get_uid_by_cookie_nosmack)
     RUNNER_ASSERT_MSG(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
 
     //drop privileges
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     //checking function
     uid_t cookieUid;
@@ -717,7 +717,7 @@ RUNNER_CHILD_TEST_SMACK(tc13_security_server_get_uid_by_cookie_smack)
     RUNNER_ASSERT_MSG(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
     RUNNER_ASSERT_MSG(apply_smack_rule("BialyMis", "security-server::api-cookie-get", "w") == 0, "Error in adding rule");
     //drop privileges
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     std::vector<char> cookie(cookieSize);
     int retval = security_server_request_cookie(&cookie[0], cookieSize);
@@ -736,7 +736,7 @@ RUNNER_CHILD_TEST_NOSMACK(tc13_security_server_get_uid_by_cookie_nosmack)
     RUNNER_ASSERT_MSG(cookieSize == 20, "Wrong cookie size");
 
     //drop privileges
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     std::vector<char> cookie(cookieSize);
     int retval = security_server_request_cookie(&cookie[0], cookieSize);
@@ -786,8 +786,8 @@ RUNNER_CHILD_TEST_SMACK(tc15_security_server_get_gid_by_cookie_smack)
     RUNNER_ASSERT_MSG(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
     RUNNER_ASSERT_MSG(smack_revoke_subject("BialyMis") == 0, "Error in smack_revoke_subject");
     //drop privileges
-    RUNNER_ASSERT_MSG(setgid(5000) == 0, "Unable to drop privileges");
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setgid(APP_GID) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     //checking function
     gid_t cookieGid, realGid;
@@ -811,8 +811,8 @@ RUNNER_CHILD_TEST_SMACK(tc16_security_server_get_gid_by_cookie_smack)
     RUNNER_ASSERT_MSG(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
     RUNNER_ASSERT_MSG(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
     //drop privileges
-    RUNNER_ASSERT_MSG(setgid(5000) == 0, "Unable to drop privileges");
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setgid(APP_GID) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     //checking function
     gid_t cookieGid;
@@ -833,8 +833,8 @@ RUNNER_CHILD_TEST_NOSMACK(tc16_security_server_get_gid_by_cookie_nosmack)
     RUNNER_ASSERT_MSG(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
 
     //drop privileges
-    RUNNER_ASSERT_MSG(setgid(5000) == 0, "Unable to drop privileges");
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setgid(APP_GID) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     //checking function
     gid_t cookieGid;
@@ -853,8 +853,8 @@ RUNNER_CHILD_TEST_SMACK(tc17_security_server_get_gid_by_cookie_smack)
     RUNNER_ASSERT_MSG(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
     RUNNER_ASSERT_MSG(apply_smack_rule("BialyMis", "security-server::api-cookie-get", "w") == 0, "Error in adding rule");
     //drop privileges
-    RUNNER_ASSERT_MSG(setgid(5000) == 0, "Unable to drop privileges");
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setgid(APP_GID) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     std::vector<char> cookie(cookieSize);
     int retval = security_server_request_cookie(&cookie[0], cookieSize);
@@ -873,8 +873,8 @@ RUNNER_CHILD_TEST_NOSMACK(tc17_security_server_get_gid_by_cookie_nosmack)
     RUNNER_ASSERT_MSG(cookieSize == 20, "Wrong cookie size");
 
     //drop privileges
-    RUNNER_ASSERT_MSG(setgid(5000) == 0, "Unable to drop privileges");
-    RUNNER_ASSERT_MSG(setuid(5000) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setgid(APP_GID) == 0, "Unable to drop privileges");
+    RUNNER_ASSERT_MSG(setuid(APP_UID) == 0, "Unable to drop privileges");
 
     std::vector<char> cookie(cookieSize);
     int retval = security_server_request_cookie(&cookie[0], cookieSize);
index 4ef5f87..ff1e634 100644 (file)
@@ -83,13 +83,13 @@ int drop_root_privileges()
 {
     if (getuid() == 0) {
         /* process is running as root, drop privileges */
-        if (setgid(5000) != 0)
+        if (setgid(APP_GID) != 0)
             return 1;
-        if (setuid(5000) != 0)
+        if (setuid(APP_UID) != 0)
             return 1;
     }
-    int uid = getuid();
-    if (uid == 5000)
+    uid_t uid = getuid();
+    if (uid == APP_UID)
         return 0;
 
     return 1;
@@ -411,14 +411,14 @@ RUNNER_TEST(tc_security_server_get_gid_wrong_object_name_teltel)
 
 RUNNER_TEST(tc_security_server_get_object_name_normal_case_trying_6001)
 {
-    ret = security_server_get_object_name(6001, obj_name, sizeof(obj_name));
+    ret = security_server_get_object_name(DB_ALARM_GID, obj_name, sizeof(obj_name));
     SLOGD("Result: %s\n", obj_name);
     RUNNER_ASSERT(ret == SECURITY_SERVER_API_SUCCESS);
 }
 
 RUNNER_TEST(tc_security_server_get_object_name_too_small_buffer_size)
 {
-    ret = security_server_get_object_name(6001, obj_name, 5);
+    ret = security_server_get_object_name(DB_ALARM_GID, obj_name, 5);
     RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL);
 }
 
@@ -690,7 +690,6 @@ RUNNER_CHILD_TEST_SMACK(tc05_check_API_middleware_allow)
     int ret = -1;
     const char *subject_allow = TEST05_SUBJECT;
     size_t cookie_size = security_server_get_cookie_size();
-    gid_t gid = 5000;
     char cookie[20];
     char *ss_label = NULL;
     char object[SECURITY_SERVER_MAX_OBJ_NAME];
@@ -720,7 +719,7 @@ RUNNER_CHILD_TEST_SMACK(tc05_check_API_middleware_allow)
     ret = security_server_check_privilege(cookie, ret);
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
 
-    ret = security_server_get_object_name(gid, object, sizeof(object));
+    ret = security_server_get_object_name(APP_GID, object, sizeof(object));
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
 
     ret = security_server_get_gid("root");
@@ -743,7 +742,6 @@ RUNNER_CHILD_TEST(tc06_check_API_middleware_denied)
     int ret = -1;
     const char *subject_denied = TEST06_SUBJECT;
     size_t cookie_size = security_server_get_cookie_size();
-    gid_t gid = 6001;
     char cookie[20];
     char *ss_label = NULL;
     char object[SECURITY_SERVER_MAX_OBJ_NAME];
@@ -757,10 +755,10 @@ RUNNER_CHILD_TEST(tc06_check_API_middleware_denied)
     ret = security_server_request_cookie(cookie, cookie_size);
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
 
-    ret = security_server_check_privilege(cookie, gid);
+    ret = security_server_check_privilege(cookie, DB_ALARM_GID);
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "ret: " << ret);
 
-    ret = security_server_get_object_name(gid, object, sizeof(object));
+    ret = security_server_get_object_name(DB_ALARM_GID, object, sizeof(object));
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "ret: " << ret);
 
     ret = security_server_get_gid("root");
@@ -1001,7 +999,6 @@ RUNNER_CHILD_TEST_NOSMACK(tc05_check_API_middleware_allow_nosmack)
 {
     int ret = -1;
     size_t cookie_size = security_server_get_cookie_size();
-    gid_t gid = 5000;
     char cookie[20];
     char* ss_label = NULL;
     char object[SECURITY_SERVER_MAX_OBJ_NAME];
@@ -1022,7 +1019,7 @@ RUNNER_CHILD_TEST_NOSMACK(tc05_check_API_middleware_allow_nosmack)
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
             "check_privilege failed. Result: " << ret);
 
-    ret = security_server_get_object_name(gid, object, sizeof(object));
+    ret = security_server_get_object_name(APP_GID, object, sizeof(object));
     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
             "get_object_name failed. Result: " << ret);
 
index 8b53ec4..cc9ba25 100644 (file)
@@ -52,7 +52,7 @@ RUNNER_TEST(tc01_security_server_get_gid_weird_input_case)
 RUNNER_TEST(tc02_security_server_get_object_name_weird_input_case)
 {
     int ret = 0;
-    gid_t gid = 6001;
+    gid_t gid = DB_ALARM_GID;
 
     /* null object case */
     char *object = NULL;
@@ -111,7 +111,7 @@ RUNNER_TEST(tc04_security_server_check_privilege_weird_input_case)
 {
     int ret = 0;
     size_t cookie_size = security_server_get_cookie_size();
-    gid_t gid = 6001;
+    gid_t gid = DB_ALARM_GID;
 
     /* null cookie case */
     char *cookie = NULL;