#include <grp.h>
#include <pwd.h>
-#include <tzplatform_config.h>
#include <security-manager.h>
#include <access_provider.h>
Api::setProcessLabel(PRIVILEGE_MANAGER_APP.c_str());
};
-static inline struct passwd *getUserStruct(const std::string &userName) {
- struct passwd *pw = nullptr;
- errno = 0;
-
- while(!(pw = getpwnam(userName.c_str()))) {
- RUNNER_ASSERT_ERRNO_MSG(errno == EINTR, "getpwnam() failed");
- };
-
- return pw;
-};
-
-static inline struct passwd *getUserStruct(const uid_t uid) {
- struct passwd *pw = nullptr;
- errno = 0;
-
- while(!(pw = getpwuid(uid))) {
- RUNNER_ASSERT_ERRNO_MSG(errno == EINTR, "getpwnam() failed");
- };
-
- return pw;
-};
-
void check_exact_access(const std::string& subject, const std::string& object, const std::string& access)
{
// check access
}
}
-
-
RUNNER_CHILD_TEST(security_manager_10_privacy_manager_fetch_whole_policy_for_self)
{
//TEST DATA
pipe.claimChildEp();
pipe.wait();
- struct passwd *pw = getUserStruct(username);
- std::string uidStr = std::to_string(pw->pw_uid);
- register_current_process_as_privilege_manager(pw->pw_uid);
- int result = drop_root_privileges(pw->pw_uid, pw->pw_gid);
+ uid_t uid; gid_t gid;
+ PasswdAccess::allUser(username, uid, gid);
+ std::string uidStr = std::to_string(uid);
+ register_current_process_as_privilege_manager(uid);
+ int result = drop_root_privileges(uid, gid);
RUNNER_ASSERT_MSG(result == 0, "drop_root_privileges failed");
std::vector<PolicyEntry> policyEntries;
pipe.claimChildEp();
pipe.wait();
- struct passwd *pw = getUserStruct(usernames.at(0));
- std::string uidStr = std::to_string(pw->pw_uid);
- register_current_process_as_privilege_manager(pw->pw_uid);
+ uid_t uid; gid_t gid;
+ PasswdAccess::allUser(usernames.at(0), uid, gid);
+ std::string uidStr = std::to_string(uid);
+ register_current_process_as_privilege_manager(uid);
//change uid to normal user
errno = 0;
- int result = drop_root_privileges(pw->pw_uid, pw->pw_gid);
+ int result = drop_root_privileges(uid, gid);
RUNNER_ASSERT_MSG(result == 0, "drop_root_privileges failed");
std::vector<PolicyEntry> policyEntries;
pipe.claimChildEp();
pipe.wait();
- struct passwd *pw = getUserStruct(usernames.at(1));
- uid_t myUid = pw->pw_uid;
- gid_t myGid = pw->pw_gid;
- std::string uidStr1 = std::to_string(myUid);
- pw = getUserStruct(usernames.at(0));
- std::string uidStr0 = std::to_string(pw->pw_uid);
- register_current_process_as_privilege_manager(myUid, true);
+ uid_t normalUid;
+ gid_t normalGid;
+ PasswdAccess::allUser(usernames.at(1), normalUid, normalUid);
+ std::string normalUidStr = std::to_string(normalUid);
+ uid_t adminUid = PasswdAccess::uid(usernames.at(0));
+ std::string adminUidStr = std::to_string(adminUid);
+ register_current_process_as_privilege_manager(normalUid, true);
//change uid to normal user
- int result = drop_root_privileges(myUid, myGid);
+ int result = drop_root_privileges(normalUid, normalGid);
RUNNER_ASSERT_MSG(result == 0, "drop_root_privileges failed");
std::string app = policyEntry.getAppId();
std::string privilege = policyEntry.getPrivilege();
- RUNNER_ASSERT_MSG(user == uidStr0 || user == uidStr1, "Unexpected user: " << user);
+ RUNNER_ASSERT_MSG(user == normalUid || user == adminUid, "Unexpected user: " << user);
- std::string uidStrToLook = user == uidStr0 ? usernames.at(0) : usernames.at(1);
+ std::string uidStrToLook = user == normalUid ? usernames.at(0) : usernames.at(1);
try {
std::set<std::string>::iterator tmp = users2AppsMap.at(uidStrToLook).at(app).find(privilege);
sync[0].claimChildEp();
sync[0].wait();
- struct passwd *pw = getUserStruct(usernames.at(0));
- register_current_process_as_privilege_manager(pw->pw_uid);
+ uid_t uid; gid_t gid;
+ PasswdAccess::allUser(usernames.at(0), uid, gid);
+ register_current_process_as_privilege_manager(uid);
//change uid to normal user
- int result = drop_root_privileges(pw->pw_uid, pw->pw_gid);
+ int result = drop_root_privileges(uid, gid);
RUNNER_ASSERT_MSG(result == 0, "drop_root_privileges failed");
PolicyEntry filter;
PolicyEntry policyEntry(
MANY_APPS[0],
- std::to_string(pw->pw_uid),
+ std::to_string(uid),
"http://tizen.org/privilege/internet"
);
policyEntry.setLevel("Deny");
policyRequest.addEntry(policyEntry);
policyEntry = PolicyEntry(
MANY_APPS[1],
- std::to_string(pw->pw_uid),
+ std::to_string(uid),
"http://tizen.org/privilege/display"
);
policyEntry.setLevel("Deny");
sync[1].claimChildEp();
sync[1].wait();
- struct passwd *pw = getUserStruct(usernames.at(0));
- uid_t target_uid = pw->pw_uid;
- pw = getUserStruct(usernames.at(1));
- uid_t my_uid = pw->pw_uid;
- gid_t my_gid = pw->pw_gid;
+ uid_t target_uid = PasswdAccess::uid(usernames.at(0));
+ uid_t my_uid;
+ gid_t my_gid;
+ PasswdAccess::allUser(usernames.at(1), my_uid, my_gid);
register_current_process_as_privilege_manager(my_uid);
pipe.claimChildEp();
pipe.wait();
- struct passwd *pw = getUserStruct(usernames.at(1));
- register_current_process_as_privilege_manager(pw->pw_uid, true);
+ uid_t uid; gid_t gid;
+ PasswdAccess::allUser(usernames.at(1), uid, gid);
+ register_current_process_as_privilege_manager(uid, true);
//change uid to normal user
- int result = drop_root_privileges(pw->pw_uid, pw->pw_gid);
+ int result = drop_root_privileges(uid, gid);
RUNNER_ASSERT_MSG(result == 0, "drop_root_privileges failed");
PolicyRequest *policyRequest = new PolicyRequest();
}
uid_t uid(void) const {
- return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+ return TzPlatformConfig::getGlobalUserId();
}
gid_t gid(void) const {