#include <security-server.h>
#include <access_provider.h>
-#include <tracker.h>
#include "tests_common.h"
#include <summary_collector.h>
-
+#include <memory.h>
#define PROPER_COOKIE_SIZE 20
-#define ENVIRONMENT \
- do { \
- const char *subject_label = "mylabel"; \
- RUNNER_ASSERT_MSG_BT(-1 != system("touch /opt/home/root/pid_cycle"), \
- "Cannot prepare environment for test."); \
- RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(subject_label), \
- "Cannot prepare environment for test."); \
- RUNNER_ASSERT_MSG_BT(-1 != setgid(1), \
- "Cannot prepare environment for test."); \
- RUNNER_ASSERT_MSG_BT(-1 != setuid(1), \
- "Cannot prepare environment for test"); \
- } while (0)
-
-
-/**
- * Environment preparation should only differ in setting label. On NOSMACK system
- * smack_set_label_for_self returns error because of no access to /proc/self/attr/current.
- */
-#define ENVIRONMENT_NOSMACK \
- do { \
- int fd = open("/opt/home/root/pid_cycle", O_CREAT|O_APPEND, 0444);\
- RUNNER_ASSERT_MSG_BT(fd >= 0, \
- "Couldn't create pid_cycle file. errno: " << strerror(errno));\
- close(fd); \
- RUNNER_ASSERT_MSG_BT(-1 != setgid(1), \
- "Cannot prepare environment for test."); \
- RUNNER_ASSERT_MSG_BT(-1 != setuid(1), \
- "Cannot prepare environment for test"); \
- } while (0)
-
-
-/**
- * Unique_ptr typedef for NOSMACK version of tc06 test
- */
-void closesockfdptr(int* sockfd_ptr)
-{
- close(*sockfd_ptr);
-}
-typedef std::unique_ptr<int, std::function<void(int*)> > SockFDUniquePtr;
RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_CLIENT_SMACK)
/*
- * test: Check cookie size returned by security_server_get_cookie_size.
- * description: Cookie used by security-server is 20 bytes long.
- * Any other size of cookies should be treated as error.
- * expected: Function security_server_get_cookie_size returns 20.
- */
-RUNNER_CHILD_TEST_SMACK(tc01_security_server_get_cookie_size)
-{
- ENVIRONMENT;
-
- int ret = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(20 == ret, "ret = " << ret);
-}
-
-/*
- * test: security_server_request_cookie
- * description: Function security_server_request_cookie will return
- * 20 bytes long cookie.
- * expected: function will set up cookie in the array and return
- * SECURITY_SERVER_API_SUCCESS.
- */
-RUNNER_CHILD_TEST_SMACK(tc02_security_server_request_cookie_normal_case)
-{
- ENVIRONMENT;
-
- char cookie[20];
- int ret = security_server_request_cookie(cookie, 20);
- LogDebug("ret = " << ret);
- RUNNER_ASSERT_BT(SECURITY_SERVER_API_SUCCESS == ret);
-}
-
-/*
- * test: security_server_request_cookie
- * description: Function security_server_request_cookie will return
- * 20 bytes long cookie.
- * expected: function will set up cookie in the array and return
- * SECURITY_SERVER_API_SUCCESS.
- */
-RUNNER_CHILD_TEST_SMACK(tc03_security_server_request_cookie_too_small_buffer_size)
-{
- ENVIRONMENT;
-
- char cookie[20];
- int ret = security_server_request_cookie(cookie, 10);
- LogDebug("ret = " << ret);
- RUNNER_ASSERT_BT(SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL == ret);
-}
-
-/*
* test: tc04_security_server_get_gid
* description: Checking for security_server_get_gid
* with nonexisting gid and existing one
RUNNER_CHILD_TEST_SMACK(tc04_security_server_get_gid)
{
SecurityServer::AccessProvider provider("tc04mylabel");
- provider.allowFunction("security_server_get_gid", TRACE_FROM_HERE);
- provider.applyAndSwithToUser(APP_UID, APP_GID, TRACE_FROM_HERE);
+ provider.allowSS();
+ provider.applyAndSwithToUser(APP_UID, APP_GID);
int ret = security_server_get_gid("abc123xyz_pysiaczek");
LogDebug("ret = " << ret);
*/
RUNNER_CHILD_TEST_SMACK(tc05_check_privilege_by_cookie)
{
+ RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
char cookie[20];
const char *object_label = "tc05objectlabel";
const char *access_rights = "r";
const char *access_rights_ext = "rw";
const char *subject_label = "tc05subjectlabel";
- SmackAccess access;
- access.add(subject_label, object_label, access_rights, TRACE_FROM_HERE);
- access.add(subject_label, "security-server::api-cookie-check", "w", TRACE_FROM_HERE);
- access.apply(TRACE_FROM_HERE);
-
- RUNNER_ASSERT_BT(0 == smack_set_label_for_self(subject_label));
+ SecurityServer::AccessProvider provider(subject_label);
+ provider.allowSS();
+ provider.addObjectRule(object_label, access_rights);
+ provider.applyAndSwithToUser(APP_UID, APP_GID);
RUNNER_ASSERT_BT(SECURITY_SERVER_API_SUCCESS ==
security_server_request_cookie(cookie,20));
- RUNNER_ASSERT_MSG_BT(drop_root_privileges() == 0, "uid = " << getuid());
-
RUNNER_ASSERT_BT(SECURITY_SERVER_API_SUCCESS ==
security_server_check_privilege_by_cookie(
cookie,
*/
RUNNER_MULTIPROCESS_TEST_SMACK(tc06_check_privilege_by_sockfd)
{
+ RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
const char *object_label = "tc06objectlabel";
const char *access_rights = "r";
const char *access_rights_ext = "rw";
int sockfd = create_new_socket();
RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
- SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+ SockUniquePtr sockfd_ptr(&sockfd);
label = security_server_get_smacklabel_sockfd(sockfd);
RUNNER_ASSERT_MSG_BT(label != NULL, "security_server_get_smacklabel_sockfd failed");
int sockfd = connect_to_testserver();
RUNNER_ASSERT_MSG_BT(sockfd >= 0, "connect_to_testserver() failed");
- SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+ SockUniquePtr sockfd_ptr(&sockfd);
label = security_server_get_smacklabel_sockfd(sockfd);
RUNNER_ASSERT_MSG_BT(label != NULL, "security_server_get_smacklabel_sockfd failed");
*/
RUNNER_MULTIPROCESS_TEST_SMACK(tc07_check_privilege_by_sockfd)
{
+ RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
const char *object_label = "tc07objectlabel";
const char *access_rights = "r";
const char *access_rights_ext = "rw";
int result2 = -1;
SmackAccess access;
- access.add(subject_label, object_label, access_rights, TRACE_FROM_HERE);
- access.apply(TRACE_FROM_HERE);
+ access.add(subject_label, object_label, access_rights);
+ access.apply();
int pid = fork();
RUNNER_ASSERT_BT(-1 != pid);
int sockfd = create_new_socket();
RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
- SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+ SockUniquePtr sockfd_ptr(&sockfd);
RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
/////NOSMACK ENV TESTS/////
///////////////////////////
-/**
- * First four test cases are the same as their SMACK versions. The only difference is environment
- * preparation (described near ENVIRONMENT_NOSMACK macro).
- */
-RUNNER_CHILD_TEST_NOSMACK(tc01_security_server_get_cookie_size_nosmack)
-{
- ENVIRONMENT_NOSMACK;
-
- int ret = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(ret == 20, "ret = " << ret);
-}
-
-RUNNER_CHILD_TEST_NOSMACK(tc02_security_server_request_cookie_normal_case_nosmack)
-{
- ENVIRONMENT_NOSMACK;
-
- char cookie[20];
- int ret = security_server_request_cookie(cookie, 20);
- RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS, "ret = " << ret);
-}
-
-RUNNER_CHILD_TEST_NOSMACK(tc03_security_server_request_cookie_too_small_buffer_size_nosmack)
-{
- ENVIRONMENT_NOSMACK;
-
- char cookie[20];
- int ret = security_server_request_cookie(cookie, 10);
- RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL, "ret = " << ret);
-}
-
RUNNER_CHILD_TEST_NOSMACK(tc04_security_server_get_gid_nosmack)
{
- ENVIRONMENT_NOSMACK;
+ int ret;
+
+ ret = drop_root_privileges();
+ RUNNER_ASSERT_MSG_BT(ret == 0,
+ "Failed to drop root privileges. Result: " << ret << "uid = " << getuid());
- int ret = security_server_get_gid("definitely_not_existing_object");
+ ret = security_server_get_gid("definitely_not_existing_object");
RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret = " << ret);
ret = security_server_get_gid("root");
RUNNER_ASSERT_MSG_BT(ret == 0, "ret = " << ret);
*/
RUNNER_CHILD_TEST_NOSMACK(tc05_check_privilege_by_cookie_nosmack)
{
+ RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
char cookie[20];
const char* object_label = "tc05objectlabel";
*/
RUNNER_MULTIPROCESS_TEST_NOSMACK(tc06_check_privilege_by_sockfd_nosmack)
{
+ RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
const char* object_label = "tc06objectlabel";
int result1 = -1;
int sockfd = create_new_socket();
RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
- SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+ SockUniquePtr sockfd_ptr(&sockfd);
//check if get_smacklabel_sockfd works correctly
label = security_server_get_smacklabel_sockfd(sockfd);
int sockfd = connect_to_testserver();
RUNNER_ASSERT_MSG_BT(sockfd >= 0, "Failed to connect to server.");
- SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+ SockUniquePtr sockfd_ptr(&sockfd);
label = security_server_get_smacklabel_sockfd(sockfd);
RUNNER_ASSERT_MSG_BT(label != NULL, "get_smacklabel_sockfd failed.");
*/
RUNNER_MULTIPROCESS_TEST_NOSMACK(tc07_check_privilege_by_sockfd_nosmack)
{
+ RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
const char* object_label = "tc07objectlabel";
int result1 = -1;
int sockfd = create_new_socket();
RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
- SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+ SockUniquePtr sockfd_ptr(&sockfd);
//Drop privileges
RUNNER_ASSERT_MSG_BT(drop_root_privileges() == 0, "uid = " << getuid());
}
}
-int apply_smack_rule(const char *subject, const char *object, const char *rule)
-{
- struct smack_accesses *ruleHandler = NULL;
- if (smack_accesses_new(&ruleHandler) != 0)
- goto error;
- if (smack_accesses_add(ruleHandler, subject, object, rule) != 0)
- goto error;
- if (smack_accesses_apply(ruleHandler) != 0)
- goto error;
-
- smack_accesses_free(ruleHandler);
- return 0;
-
-error:
- smack_accesses_free(ruleHandler);
- return -1;
-}
-
-RUNNER_TEST(tc10_security_server_get_uid_by_cookie)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //checking function
- uid_t cookieUid, realUid;
- realUid = getuid();
- retval = security_server_get_uid_by_cookie(&cookie[0], &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get UID from cookie. My uid: " << realUid << " Server error: " << retval);
- RUNNER_ASSERT_MSG_BT(realUid == cookieUid, "No match in received UID");
-
- //checking for input parameters
- retval = security_server_get_uid_by_cookie(NULL, &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "Error in checking input parameters by function");
- retval = security_server_get_uid_by_cookie(&cookie[0], NULL);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "Error in checking input parameters by function");
-}
-
-RUNNER_CHILD_TEST_SMACK(tc11_security_server_get_uid_by_cookie_smack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //preapare SMACK environment
- RUNNER_ASSERT_MSG_BT(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
- RUNNER_ASSERT_MSG_BT(smack_revoke_subject("BialyMis") == 0, "Error in smack_revoke_subject");
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- //checking function
- uid_t cookieUid;
- retval = security_server_get_uid_by_cookie(&cookie[0], &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "Socket not protected by smack");
-}
-
-RUNNER_CHILD_TEST_SMACK(tc12_security_server_get_uid_by_cookie_smack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- uid_t realUid = getuid();
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //preapare SMACK environment
- RUNNER_ASSERT_MSG_BT(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
- RUNNER_ASSERT_MSG_BT(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- //checking function
- uid_t cookieUid;
- retval = security_server_get_uid_by_cookie(&cookie[0], &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get UID from cookie");
- RUNNER_ASSERT_MSG_BT(realUid == cookieUid, "No match in received UID");
-}
-
-RUNNER_CHILD_TEST_NOSMACK(tc12_security_server_get_uid_by_cookie_nosmack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- uid_t realUid = getuid();
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- //checking function
- uid_t cookieUid;
- retval = security_server_get_uid_by_cookie(&cookie[0], &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get UID from cookie");
- RUNNER_ASSERT_MSG_BT(realUid == cookieUid, "No match in received UID");
-}
-
-RUNNER_CHILD_TEST_SMACK(tc13_security_server_get_uid_by_cookie_smack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- //preapare SMACK environment
- RUNNER_ASSERT_MSG_BT(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
- RUNNER_ASSERT_MSG_BT(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
- RUNNER_ASSERT_MSG_BT(apply_smack_rule("BialyMis", "security-server::api-cookie-get", "w") == 0, "Error in adding rule");
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //checking function
- uid_t cookieUid, realUid = getuid();
- retval = security_server_get_uid_by_cookie(&cookie[0], &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get UID from cookie");
- RUNNER_ASSERT_MSG_BT(realUid == cookieUid, "No match in received UID");
-}
-
-RUNNER_CHILD_TEST_NOSMACK(tc13_security_server_get_uid_by_cookie_nosmack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //checking function
- uid_t cookieUid, realUid = getuid();
- retval = security_server_get_uid_by_cookie(&cookie[0], &cookieUid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get UID from cookie");
- RUNNER_ASSERT_MSG_BT(realUid == cookieUid, "No match in received UID");
-}
-
-RUNNER_TEST(tc14_security_server_get_gid_by_cookie)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //checking function
- gid_t cookieGid, realGid;
- realGid = getgid();
- retval = security_server_get_gid_by_cookie(&cookie[0], &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get GID from cookie");
- RUNNER_ASSERT_MSG_BT(realGid == cookieGid, "No match in received GID");
-
- //checking for input parameters
- retval = security_server_get_gid_by_cookie(NULL, &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "Error in checking input parameters by function");
- retval = security_server_get_gid_by_cookie(&cookie[0], NULL);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "Error in checking input parameters by function");
-
-}
-
-RUNNER_CHILD_TEST_SMACK(tc15_security_server_get_gid_by_cookie_smack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //preapare SMACK environment
- RUNNER_ASSERT_MSG_BT(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
- RUNNER_ASSERT_MSG_BT(smack_revoke_subject("BialyMis") == 0, "Error in smack_revoke_subject");
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setgid(APP_GID) == 0, "Unable to drop privileges");
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- //checking function
- gid_t cookieGid;
- retval = security_server_get_gid_by_cookie(&cookie[0], &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "Socket not protected by smack");
-}
-
-RUNNER_CHILD_TEST_SMACK(tc16_security_server_get_gid_by_cookie_smack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- std::vector<char> cookie(cookieSize);
-
- gid_t realGid = getgid();
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //preapare SMACK environment
- RUNNER_ASSERT_MSG_BT(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
- RUNNER_ASSERT_MSG_BT(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setgid(APP_GID) == 0, "Unable to drop privileges");
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- //checking function
- gid_t cookieGid;
- retval = security_server_get_gid_by_cookie(&cookie[0], &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get GID from cookie");
- RUNNER_ASSERT_MSG_BT(realGid == cookieGid, "No match in received GID. ReadGid: " << realGid << " CookieGid: " << cookieGid);
-}
-
-RUNNER_CHILD_TEST_NOSMACK(tc16_security_server_get_gid_by_cookie_nosmack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- std::vector<char> cookie(cookieSize);
-
- gid_t realGid = getgid();
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setgid(APP_GID) == 0, "Unable to drop privileges");
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- //checking function
- gid_t cookieGid;
- retval = security_server_get_gid_by_cookie(&cookie[0], &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get GID from cookie");
- RUNNER_ASSERT_MSG_BT(realGid == cookieGid, "No match in received GID. ReadGid: " << realGid << " CookieGid: " << cookieGid);
-}
-
-RUNNER_CHILD_TEST_SMACK(tc17_security_server_get_gid_by_cookie_smack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- //preapare SMACK environment
- RUNNER_ASSERT_MSG_BT(smack_set_label_for_self("BialyMis") == 0, "Unable to set label for self");
- RUNNER_ASSERT_MSG_BT(apply_smack_rule("BialyMis", "security-server::api-cookie-check", "w") == 0, "Error in adding rule");
- RUNNER_ASSERT_MSG_BT(apply_smack_rule("BialyMis", "security-server::api-cookie-get", "w") == 0, "Error in adding rule");
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setgid(APP_GID) == 0, "Unable to drop privileges");
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //checking function
- gid_t cookieGid, realGid = getgid();
- retval = security_server_get_gid_by_cookie(&cookie[0], &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get GID from cookie");
- RUNNER_ASSERT_MSG_BT(realGid == cookieGid, "No match in received GID. ReadGid: " << realGid << " CookieGid: " << cookieGid);
-}
-
-RUNNER_CHILD_TEST_NOSMACK(tc17_security_server_get_gid_by_cookie_nosmack)
-{
- int cookieSize = security_server_get_cookie_size();
- RUNNER_ASSERT_MSG_BT(cookieSize == 20, "Wrong cookie size");
-
- //drop privileges
- RUNNER_ASSERT_MSG_BT(setgid(APP_GID) == 0, "Unable to drop privileges");
- RUNNER_ASSERT_MSG_BT(setuid(APP_UID) == 0, "Unable to drop privileges");
-
- std::vector<char> cookie(cookieSize);
- int retval = security_server_request_cookie(&cookie[0], cookieSize);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get cookie");
-
- //checking function
- gid_t cookieGid, realGid = getgid();
- retval = security_server_get_gid_by_cookie(&cookie[0], &cookieGid);
- RUNNER_ASSERT_MSG_BT(retval == SECURITY_SERVER_API_SUCCESS, "Unable to get GID from cookie");
- RUNNER_ASSERT_MSG_BT(realGid == cookieGid, "No match in received GID. ReadGid: " << realGid << " CookieGid: " << cookieGid);
-}
-
RUNNER_TEST_SMACK(tc18_security_server_get_smacklabel_cookie) {
int res;
//Request cookie from SS
res = security_server_request_cookie(cookie, cookie_size);
- std::unique_ptr<char, std::function<void(char*)> > cookie_ptr(cookie, free);
+ CookieUniquePtr cookie_ptr(cookie);
cookie = NULL;
RUNNER_ASSERT_MSG_BT(res == SECURITY_SERVER_API_SUCCESS,
"Error in requesting cookie from security-server. Result: " << res);
label_ss = security_server_get_smacklabel_cookie(cookie_ptr.get());
RUNNER_ASSERT_MSG_BT(label_ss != NULL, "Error in getting label by cookie");
- //Check if label_ss is correct, that is only one NULL character.
- if (label_ss[0] != '\0') {
- free(label_ss);
- RUNNER_ASSERT_MSG_BT(label_ss[0] == '\0', "label_ss was not an empty string.");
- }
-
+ std::string label(label_ss);
free(label_ss);
+ RUNNER_ASSERT_MSG_BT(label.empty(), "label_ss is not an empty string.");
+
}
////////////////////