#include <cstring>
#include <iomanip>
#include <iostream>
-#include <sys/smack.h> // SMACK_LABEL_LEN
+
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include <app-runtime.h>
#include "dcm_client.h"
#include "device_certificate_manager.h"
return __libc_malloc(size);
}
-class Fd {
- int fd;
-public:
- explicit Fd(int fd) : fd(fd) { BOOST_REQUIRE_GE(fd, 0); }
- operator int() const { return fd; }
- ~Fd() { BOOST_CHECK_EQUAL(close(fd), 0); }
-};
-
-class OverrideSmackLabel {
- Fd fd;
- char old_label[SMACK_LABEL_LEN];
- boost::uint_value_t<SMACK_LABEL_LEN>::least old_label_len;
-public:
- explicit OverrideSmackLabel(const char *override_label)
- : fd(open("/proc/thread-self/attr/current", O_RDWR)) {
- const auto ret = read(fd, old_label, sizeof old_label);
- BOOST_REQUIRE_GT(ret, 0);
- BOOST_REQUIRE_LE(ret, sizeof old_label);
- old_label_len = ret;
-
- // subsequent write()s fail without the seek
- BOOST_REQUIRE_EQUAL(lseek(fd, 0, SEEK_SET), 0);
-
- const auto len = strlen(override_label);
- BOOST_REQUIRE_EQUAL(write(fd, override_label, len), len);
- }
-
- ~OverrideSmackLabel() {
- BOOST_CHECK_EQUAL(write(fd, old_label, old_label_len), old_label_len);
- }
-};
-
} // namespace
BOOST_AUTO_TEST_SUITE(API_TEST)
// checked during the "method-with-a-privilege-not-granted" call.
// Grep backend code for /method-with-a-privilege-not-granted/ for details.
//
- // Sdb uses User::Shell but one can switch to System::Privileged, then back.
- OverrideSmackLabel _("System::Privileged");
-
- int ret = dcm_ext_call_api("method-with-a-privilege-not-granted", NULL, 0, NULL, NULL);
- BOOST_REQUIRE_EQUAL(ret, DCM_EXT_ERROR_PERMISSION_DENIED);
+ // Sdb uses User::Shell but one can switch to System::Privileged in the separate child process.
+ pid_t p;
+ int stat;
+
+ /* split this program into two processes */
+ p = fork();
+
+ if(p == 0) { // child process is running
+ int ret = security_manager_set_identity(SM_PROCESS_TYPE_SYSTEM_PRIVILEGED, NULL);
+ if(ret != SECURITY_MANAGER_SUCCESS) {
+ std::cout << "security_manager_set_identity() failed... ret=" << ret << std::endl;
+ exit(2); // error case
+ }
+ ret = dcm_ext_call_api("method-with-a-privilege-not-granted", NULL, 0, NULL, NULL);
+ if(ret != DCM_EXT_ERROR_PERMISSION_DENIED) {
+ std::cout << "dcm_ext_call_api() failed..."
+ << "expected=" << DCM_EXT_ERROR_PERMISSION_DENIED
+ << "actual=" << ret
+ << std::endl;
+ exit(2); // error case
+ }
+ exit(0);
+ } else { // parent process is runnin
+ wait(&stat); // wait for the child
+ BOOST_REQUIRE(WIFEXITED(stat) & (WEXITSTATUS(stat) == 0)); // check result from child
+ }
}
POSITIVE_TEST_CASE(test09_dcm_ext_api_normal_call)