2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
5 * @file security_server_tests_clean_env.cpp
6 * @author Zbigniew Jasinski (z.jasinski@samsung.com)
8 * @brief Functions to prepare clean env for tests.
15 #include <ckm/ckm-control.h>
17 #include <service_manager.h>
18 #include <clean-env.h>
20 int restart_security_server() {
21 ServiceManager sm("security-server.service");
27 static int nftw_rmdir_contents(const char *fpath, const struct stat * /*sb*/,
28 int tflag, struct FTW *ftwbuf)
32 else if (tflag == FTW_DP && ftwbuf->level != 0)
39 * This function should be called at the begining of every SS test, so all the tests
40 * are independent of each other.
42 int reset_security_server()
44 const char* path = "/opt/data/security-server/";
45 const int max_descriptors = 10; //max number of open file descriptors by nftw function
47 // Clear /opt/data/security-server/ directory
48 if (access(path, F_OK) == 0) {
49 if (nftw(path, &nftw_rmdir_contents, max_descriptors, FTW_DEPTH) == -1) {
55 restart_security_server();
56 auto control = CKM::Control::create();
59 control->lockUserKey(5000);
60 control->removeUserData(5000);
61 control->unlockUserKey(5000, "");