#include <tests_common.h>
#include <libprivilege-control_test_common.h>
#include "common/db.h"
+#include <memory.h>
#define APP_USER_NAME "app"
#define APP_HOME_DIR "/opt/home/app"
DB_BEGIN
result = perm_app_uninstall(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == 0,
+ RUNNER_ASSERT_MSG(result == 0,
"perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
result = perm_app_install(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == 0,
+ RUNNER_ASSERT_MSG(result == 0,
"perm_app_install returned " << result << ". Errno: " << strerror(errno));
//Add permissions
result = perm_app_enable_permissions(APP_ID, APP_TYPE_EFL, PRIVS_EFL, true);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error adding app permissions. Result: " << result);
DB_END
//Check if smack_have_access always fails on every rule
result = test_have_nosmack_accesses(rules_efl);
- RUNNER_ASSERT_MSG_BT(result == -1,
+ RUNNER_ASSERT_MSG(result == -1,
"Despite SMACK being off some accesses were added. Result: " << result);
TestLibPrivilegeControlDatabase db_test;
DB_BEGIN
result = perm_app_disable_permissions(USER_APP_ID, APP_TYPE_EFL, PRIVS_EFL);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error disabling permissions: " << perm_strerror(result));
DB_END
}
DB_BEGIN
result = perm_app_uninstall(app_id);
- RUNNER_ASSERT_MSG_BT(result == 0,
+ RUNNER_ASSERT_MSG(result == 0,
"perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
result = perm_app_install(app_id);
- RUNNER_ASSERT_MSG_BT(result == 0,
+ RUNNER_ASSERT_MSG(result == 0,
"perm_app_install returned " << result << ". Errno: " << strerror(errno));
result = perm_app_enable_permissions(app_id, app_type, privileges, 1);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
" Error enabling app permissions. Result: " << result);
DB_END
result = test_have_nosmack_accesses(rules);
- RUNNER_ASSERT_MSG_BT(result == -1,
+ RUNNER_ASSERT_MSG(result == -1,
" Permissions shouldn't be added. Result: " << result);
std::set<unsigned> groups_before;
read_user_gids(groups_before, APP_UID);
result = perm_app_set_privilege(app_id, type, app_path);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
" Error in perm_app_set_privilege. Error: " << result);
//Even though app privileges are set, no smack label should be extracted.
char* label = NULL;
result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG_BT(result == -1,
+ RUNNER_ASSERT_MSG(result == -1,
" new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG_BT(label == NULL,
+ RUNNER_ASSERT_MSG(label == NULL,
" new_label_from_self shouldn't allocate memory for label.");
check_groups(groups_before, dac_file);
//Set app privileges
result = perm_app_set_privilege(APP_ID, NULL, APP_SET_PRIV_PATH);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error in perm_app_set_privilege. Error: " << result);
//Even though app privileges are set, no smack label should be extracted.
char* label = NULL;
result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG_BT(result == -1,
+ RUNNER_ASSERT_MSG(result == -1,
"new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG_BT(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
+ RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
//Check if DAC privileges really set
- RUNNER_ASSERT_MSG_BT(getuid() == APP_UID, "Wrong UID");
- RUNNER_ASSERT_MSG_BT(getgid() == APP_GID, "Wrong GID");
+ RUNNER_ASSERT_MSG(getuid() == APP_UID, "Wrong UID");
+ RUNNER_ASSERT_MSG(getgid() == APP_GID, "Wrong GID");
result = strcmp(getenv("HOME"), APP_HOME_DIR);
- RUNNER_ASSERT_MSG_BT(result == 0, "Wrong HOME DIR. Result: " << result);
+ RUNNER_ASSERT_MSG(result == 0, "Wrong HOME DIR. Result: " << result);
result = strcmp(getenv("USER"), APP_USER_NAME);
- RUNNER_ASSERT_MSG_BT(result == 0, "Wrong user USER NAME. Result: " << result);
+ RUNNER_ASSERT_MSG(result == 0, "Wrong user USER NAME. Result: " << result);
check_groups(groups_before, NULL);
}
DB_BEGIN
result = perm_app_uninstall(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
result = perm_app_install(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"perm_app_install returned " << result << ". Errno: " << strerror(errno));
result = perm_app_revoke_permissions(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error revoking app permissions. Result: " << result);
result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2, 1);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error enabling app permissions. Result: " << result);
DB_END
//Check if accesses aren't added
result = test_have_nosmack_accesses(rules2);
- RUNNER_ASSERT_MSG_BT(result == -1, "Permissions shouldn't be added. Result: " << result);
+ RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
TestLibPrivilegeControlDatabase db_test;
db_test.test_db_after__perm_app_install(USER_APP_ID);
//Clean up
result = perm_app_revoke_permissions(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error revoking app permissions. Result: " << result);
DB_END
DB_BEGIN
result = perm_app_uninstall(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
result = perm_app_install(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"perm_app_install returned " << result << ". Errno: " << strerror(errno));
// Disable permissions
result = perm_app_disable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error disabling app permissions. Result: " << result);
// Prepare permissions to reset
result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2, true);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
" Error adding app permissions. Result: " << result);
// Reset permissions
result = perm_app_reset_permissions(WGT_APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error reseting app permissions. Result: " << result);
DB_END
result = test_have_nosmack_accesses(rules2);
- RUNNER_ASSERT_MSG_BT(result == -1, "Permissions shouldn't be changed. Result: " << result);
+ RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be changed. Result: " << result);
DB_BEGIN
// Disable permissions
result = perm_app_disable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
"Error disabling app permissions. Result: " << result);
DB_END
//Create our server and client with fork
pid = fork();
- RUNNER_ASSERT_MSG_BT(pid >= 0, "Fork failed");
+ RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
if (!pid) { //child (server)
int sock, result, fd;
//Create a socket
sock = socket(AF_UNIX, SOCK_STREAM, 0);
- RUNNER_ASSERT_MSG_BT(sock >= 0, "socket failed: " << strerror(errno));
+ RUNNER_ASSERT_ERRNO_MSG(sock >= 0, "socket failed");
//Bind socket to address
result = bind(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
- if (result != 0) {
- close(sock);
- RUNNER_ASSERT_MSG_BT(false, "bind failed: " << strerror(errno));
- }
+ RUNNER_ASSERT_ERRNO_MSG(result == 0, "bind failed");
//Prepare for listening
result = listen(sock, 1);
- if (result != 0) {
- close(sock);
- RUNNER_ASSERT_MSG_BT(false, "listen failed: " << strerror(errno));
- }
+ RUNNER_ASSERT_ERRNO_MSG(result == 0, "listen failed");
//Accept connection
alarm(2);
fd = accept(sock, NULL, NULL);
alarm(0);
- RUNNER_ASSERT_MSG_BT(fd >= 0, "accept failed: " << strerror(errno));
+ RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "accept failed");
//Wait a little bit for client to use perm_app_id_from_socket
usleep(200);
//cleanup
- close(sock);
exit(0);
} else { //parent (client)
// Give server some time to setup listening socket
//Create socket
sock = socket(AF_UNIX, SOCK_STREAM, 0);
- RUNNER_ASSERT_MSG_BT(sock >= 0, "socket failed: " << strerror(errno));
+ RUNNER_ASSERT_ERRNO_MSG(sock >= 0, "socket failed");
//Try connecting to address
result = connect(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
- if (result != 0) {
- close(sock);
- RUNNER_ASSERT_MSG_BT(0, "connect failed: " << strerror(errno));
- }
+ RUNNER_ASSERT_ERRNO_MSG(result == 0, "connect failed");
//Use perm_app_id_from_socket. Should fail and return NULL smack_label.
smack_label = perm_app_id_from_socket(sock);
- if (smack_label != NULL) {
- close(sock);
- RUNNER_ASSERT_MSG_BT(0, "perm_app_id_from_socket should fail.");
- }
+ RUNNER_ASSERT_MSG(!smack_label, "perm_app_id_from_socket should fail.");
//cleanup
- close(sock);
- RUNNER_ASSERT_MSG_BT(smack_label == NULL, "perm_app_id_from_socket should fail.");
+ RUNNER_ASSERT_MSG(smack_label == NULL, "perm_app_id_from_socket should fail.");
}
}