2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
5 * @file security_server_tests_pid_reuser.cpp
6 * @author Bumjin Im (bj.im@samsung.com)
7 * @author Mariusz Domanski (m.domanski@samsung.com)
9 * @brief Test cases for security server
16 #include <sys/types.h>
19 #include "security-server.h"
20 #include <dpl/test/test_runner.h>
24 unsigned int target_pid, target_uid;
25 unsigned char *prev_cookie, *new_cookie;
28 /* deprecated info for old c-style binary
29 * still useful for understanding the test itself
32 * cmd uid pid hexa_decimal_cookie
33 * pid: PID want to be reused
34 * hexa_decimal_cookie: Cookie value which is issued to the previous process
35 * with the [pid] for comparison\nThe cookie must be hexa
36 * decimal, with lower case and without whitespace and
38 * This test program must be executed as root process
41 void convert_prev_cookie(const char *cmdline, const char *prev, unsigned char *now)
44 char tmphexnum[3] = {0};
45 cnt = security_server_get_cookie_size();
47 if(strlen(prev) != cnt)
49 printf("%s\n", "Cookie length is wrong");
53 for(i=0, cnt=0 ; i<strlen(prev) ; i=i+2)
55 strncpy(tmphexnum, prev+i, 2);
58 now[cnt] = strtoul(tmphexnum, 0, 16);
61 printf("%s\n", "cannot convert hex cookie to binary");
72 ret = stat("/opt/home/root/pid_cycle", &statbuf);
75 printf("Interrupt encountered. exiting...\n");
81 void cycle_pid(int pid)
83 int cur_pid = getpid();
90 dotval = cur_pid % 1000;
100 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_PID);
102 RUNNER_TEST(tc_security_server_request_cookie)
104 RUNNER_IGNORED_MSG("needs FIX, check FIXME comment");
105 LOGD("Cycling PID to %d\n", target_pid);
106 cycle_pid(target_pid);
107 unlink("/opt/home/root/pid_cycle");
108 RUNNER_ASSERT(security_server_request_cookie((char *)new_cookie, 20) == SECURITY_SERVER_API_SUCCESS);
109 LOGD("\nTarget PID: %d, Target UID: %d\n", target_pid, target_uid);
110 LOGD("Previous cookie:\n");
111 printhex(prev_cookie, 20);
112 LOGD("Newly issued cookie:\n");
113 printhex(new_cookie, 20);
114 RUNNER_ASSERT_MSG(memcmp(prev_cookie, new_cookie, cookie_size) != 0, "cookies are the same");
117 int main(int argc, char *argv[])
119 /* FIXME: proper parameters needed (these below are fake)
120 * or better idea for this test case...*/
121 char *argvv[] = {argv[0], "12345", "5000" , "abcdefabcdefabcdefabcdefabcdefabcdefabcd"};
124 target_uid = getuid();
127 printf("Error: %s must be executed by root\n", argv[0]);
131 cookie_size = security_server_get_cookie_size();
132 unsigned char prev_cookie_tmp[cookie_size], new_cookie_tmp[cookie_size];
133 prev_cookie = prev_cookie_tmp;
134 new_cookie = new_cookie_tmp;
137 target_uid = strtoul(argvv[1], 0, 10);
140 printf("%s\n", "cannot convert string uid to integer");
143 LOGD("Target UID is %d. change user...\n", target_uid);
147 target_pid = strtoul(argvv[2], 0, 10);
150 printf("%s\n", "cannot convert string pid to integer");
153 convert_prev_cookie(argvv[0], argvv[3], prev_cookie);
157 DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);