#include <functional>
#include <map>
#include <string>
+#include <sys/types.h>
#include <vector>
#include <unistd.h>
#include <security-manager-types.h>
-const uid_t OWNER_UID = 5001;
-
struct AppInstallHelper {
using TypePathsMap = std::map<app_install_path_type, std::vector<std::string>>;
std::string version = std::string(),
bool isHybrid = false)
: m_appName(appNamePrefix), m_pkgName(pkgNamePrefix), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
- m_installType(SM_APP_INSTALL_NONE), m_isHybrid(isHybrid)
+ m_installType(SM_APP_INSTALL_NONE), m_isHybrid(isHybrid), m_creatorPid(getpid())
{
setInstallPath();
}
std::string generatePkgLabel() const;
void revokeRules() const;
virtual ~AppInstallHelper() {
- removePaths();
+ if (m_creatorPid == getpid())
+ removePaths();
}
protected:
TypePathsMap m_fileTypeMap;
std::vector<std::string> m_privileges;
std::string m_author;
+
+ pid_t m_creatorPid;
};
RUNNER_CHILD_TEST(security_manager_21_security_manager_admin_deny_user_priv)
{
- const int BUFFER_SIZE = 128;
- struct message {
- uid_t uid;
- gid_t gid;
- char buf[BUFFER_SIZE];
- } msg;
-
const privileges_t adminRequiredPrivs = {
"http://tizen.org/privilege/notexist",
"http://tizen.org/privilege/internal/usermanagement"
};
const privileges_t allowedPrivsAfterChange = {"http://tizen.org/privilege/datasharing"};
const privileges_t deniedPrivsAfterChange = {"http://tizen.org/privilege/internet"};
+ TemporaryTestUser adminUser("sm_test_21_admin_user_name", GUM_USERTYPE_ADMIN, false);
+ TemporaryTestUser normalUser("sm_test_21_normal_user_name", GUM_USERTYPE_NORMAL, false);
- MessagePipe msgPipe;
-
- pid_t pid = fork();
- RUNNER_ASSERT_MSG(pid >= 0, "fork failed");
- if (pid != 0)//parent process
- {
- msgPipe.claimParentEp();
- TemporaryTestUser adminUser("sm_test_21_admin_user_name", GUM_USERTYPE_ADMIN, false);
- TemporaryTestUser normalUser("sm_test_21_normal_user_name", GUM_USERTYPE_NORMAL, false);
-
- adminUser.create();
- normalUser.create();
- std::string childUidStr = normalUser.getUidString();
-
- AppInstallHelper adminApp("sm_test_21_admin", adminUser.getUid());
- adminApp.createInstallDir();
- adminApp.addPrivileges(adminRequiredPrivs);
- ScopedInstaller adminAppInstall(adminApp);
+ adminUser.create();
+ normalUser.create();
+ std::string childUidStr = normalUser.getUidString();
- AppInstallHelper normalApp("sm_test_21_normal", normalUser.getUid());
- normalApp.createInstallDir();
- normalApp.addPrivileges(manifestPrivs);
+ AppInstallHelper adminApp("sm_test_21_admin", adminUser.getUid());
+ adminApp.createInstallDir();
+ adminApp.addPrivileges(adminRequiredPrivs);
+ ScopedInstaller adminAppInstall(adminApp);
- ScopedInstaller normalAppInstall(normalApp);
- check_app_permissions(normalApp.getAppId(), normalApp.getPkgId(), childUidStr,
- manifestPrivs, {});
+ AppInstallHelper normalApp("sm_test_21_normal", normalUser.getUid());
+ normalApp.createInstallDir();
+ normalApp.addPrivileges(manifestPrivs);
+ ScopedInstaller normalAppInstall(normalApp);
- //send info to child
- msg.uid = adminUser.getUid();
- msg.gid = adminUser.getGid();
- strncpy (msg.buf, childUidStr.c_str(), BUFFER_SIZE);
- msgPipe.write(msg);
+ check_app_permissions(normalApp.getAppId(), normalApp.getPkgId(), childUidStr,
+ manifestPrivs, {});
+ pid_t pid = fork();
+ RUNNER_ASSERT_MSG(pid >= 0, "fork failed");
+ if (pid != 0) { //parent process
waitPid(pid);
-
check_app_permissions(normalApp.getAppId(), normalApp.getPkgId(), childUidStr,
allowedPrivsAfterChange, deniedPrivsAfterChange);
- }
- if (pid == 0) {
- msgPipe.claimChildEp();
- // Get created user credentials
- msgPipe.read(msg);
-
- AppInstallHelper adminApp("sm_test_21_admin");
+ } else {
Api::setProcessLabel(adminApp.getAppId());
- RUNNER_ASSERT_ERRNO_MSG(drop_root_privileges(msg.uid, msg.gid) == 0, "drop_root_privileges failed");
+ RUNNER_ASSERT_ERRNO_MSG(drop_root_privileges(adminUser.getUid(),adminUser.getGid()) == 0,
+ "drop_root_privileges failed");
PolicyRequest addPolicyReq;
for (auto &deniedPriv : deniedPrivsAfterChange) {
- PolicyEntry entry(SECURITY_MANAGER_ANY, msg.buf, deniedPriv);
+ PolicyEntry entry(SECURITY_MANAGER_ANY, normalUser.getUidString(), deniedPriv);
entry.setMaxLevel("Deny");
addPolicyReq.addEntry(entry);
}