From 7482e3bc69c343b696c901127c894eeaf1ca93ef Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Wed, 27 Apr 2016 11:19:43 +0200 Subject: [PATCH] Add path registration API stub [Problem] Path registration is package specific and requires a separate processing. [Solution] Create API for package path registration. [Verification] Successfull compilation Change-Id: Ie31d756b7dc7ca9bca82305b03dd8000ba6b9bc5 --- src/client/client-security-manager.cpp | 4 +- src/cmd/security-manager-cmd.cpp | 8 ++-- src/common/include/protocols.h | 11 ++++- src/common/service_impl.cpp | 6 +-- src/include/app-manager.h | 76 ++++++++++++++++++++++++++++++++++ src/include/security-manager-types.h | 5 +++ src/server/service/service.cpp | 2 +- 7 files changed, 101 insertions(+), 11 deletions(-) diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index dd55443..9958c49 100755 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -173,7 +173,7 @@ int security_manager_app_inst_req_add_path(app_inst_req *p_req, const char *path if (!p_req || !path || (path_type < 0) || (path_type >= SECURITY_MANAGER_ENUM_END)) return SECURITY_MANAGER_ERROR_INPUT_PARAM; - p_req->appPaths.push_back(std::make_pair(path, path_type)); + p_req->pkgPaths.push_back(std::make_pair(path, path_type)); return SECURITY_MANAGER_SUCCESS; } @@ -215,7 +215,7 @@ int security_manager_app_install(const app_inst_req *p_req) p_req->appName, p_req->pkgName, p_req->privileges, - p_req->appPaths, + p_req->pkgPaths, p_req->uid, p_req->tizenVersion, p_req->authorName, diff --git a/src/cmd/security-manager-cmd.cpp b/src/cmd/security-manager-cmd.cpp index 0e9b5c5..762587b 100644 --- a/src/cmd/security-manager-cmd.cpp +++ b/src/cmd/security-manager-cmd.cpp @@ -192,7 +192,7 @@ static bool loadPaths(const std::vector &paths, LogDebug("Wrong paths size: " << paths.size()); return false; } - req.appPaths.clear(); + req.pkgPaths.clear(); for (std::vector::size_type i = 1; i < paths.size(); i += 2) { app_install_path_type pathType; LogDebug("path: " << paths[i - 1]); @@ -201,13 +201,13 @@ static bool loadPaths(const std::vector &paths, } catch (const std::out_of_range &e) { std::cout << "Invalid path type found." << std::endl; LogError("Invalid path type found."); - req.appPaths.clear(); + req.pkgPaths.clear(); return false; } LogDebug("path type: " << pathType << " (" << paths[i] << ")"); - req.appPaths.push_back(std::make_pair(paths[i - 1], pathType)); + req.pkgPaths.push_back(std::make_pair(paths[i - 1], pathType)); } - return (!req.appPaths.empty()); + return (!req.pkgPaths.empty()); } static void parseInstallOptions(int argc, char *argv[], diff --git a/src/common/include/protocols.h b/src/common/include/protocols.h index 2283205..3926606 100644 --- a/src/common/include/protocols.h +++ b/src/common/include/protocols.h @@ -32,11 +32,13 @@ #include #include +typedef std::vector> pkg_paths; + struct app_inst_req { std::string appName; std::string pkgName; std::vector privileges; - std::vector> appPaths; + pkg_paths pkgPaths; uid_t uid; std::string tizenVersion; std::string authorName; @@ -54,6 +56,13 @@ struct private_sharing_req { std::vector paths; }; +struct path_req { + std::string pkgName; + uid_t uid; + pkg_paths pkgPaths; + int installationType = SM_APP_INSTALL_NONE; +}; + namespace SecurityManager { extern char const * const SERVICE_SOCKET; diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index 9e4cb22..a961d24 100755 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -298,7 +298,7 @@ bool ServiceImpl::installRequestPathsCheck(const app_inst_req &req, std::string correctPath.append("/").append(req.pkgName); LogDebug("correctPath: " << correctPath); - for (const auto &path : req.appPaths) { + for (const auto &path : req.pkgPaths) { std::unique_ptr> real_path( realpath(path.first.c_str(), NULL), free); if (!real_path.get()) { @@ -402,11 +402,11 @@ int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req) } try { - if (!req.appPaths.empty()) + if (!req.pkgPaths.empty()) SmackLabels::setupAppBasePath(req.pkgName, appPath); // register paths - for (const auto &appPath : req.appPaths) { + for (const auto &appPath : req.pkgPaths) { const std::string &path = appPath.first; app_install_path_type pathType = static_cast(appPath.second); SmackLabels::setupPath(req.pkgName, path, pathType, authorId); diff --git a/src/include/app-manager.h b/src/include/app-manager.h index c297d75..02207b2 100644 --- a/src/include/app-manager.h +++ b/src/include/app-manager.h @@ -153,6 +153,82 @@ int security_manager_app_install(const app_inst_req *p_req); */ int security_manager_app_uninstall(const app_inst_req *p_req); +/* + * This function is responsible for initialize path_req data structure. It uses + * dynamic allocation inside and user responsibility is to call + * security_manager_path_req_free() for freeing allocated resources. + * + * \param[in] pp_req Address of pointer for handle path_req structure + * \return API return code or error code + */ +int security_manager_path_req_new(path_req **pp_req); + +/* + * This function is used to free resources allocated by calling + * security_manager_path_req_new(). + * \param[in] p_req Pointer handling allocated path_req structure + */ +void security_manager_path_req_free(path_req *p_req); + +/* + * This function is used to set up package identifier in path_req structure. + * + * \param[in] p_req Pointer handling path_req structure + * \param[in] pkg_id Package identifier + * \return API return code or error code + */ +int security_manager_path_req_set_pkg_id(path_req *p_req, const char *pkg_id); + +/* + * This function is used to set up installation type (global, local, preloaded). + * If type is not set and if installation is performed by global user, type is set to + * 'SM_APP_INSTALL_GLOBAL'. Otherwise installation type is set to 'SM_APP_INSTALL_LOCAL'. + * + * \param[in] p_req Pointer handling path_req structure + * \param[in] type Installation type + * \return API return code or error code + */ +int security_manager_path_req_set_install_type(path_req *p_req, const enum app_install_type type); + +/* + * This function is used to add a package path to path_req structure. It can be + * called multiple times. + * + * \param[in] p_req Pointer handling path_req structure + * \param[in] path Package path + * \param[in] path_type Package path type + * \return API return code or error code + */ +int security_manager_path_req_add_path(path_req *p_req, const char *path, const int path_type); + +/* + * This function is used to set up user identifier in path_req structure. + * This field simplifies support for online and offline modes. + * + * \param[in] p_req Pointer handling path_req structure + * \param[in] uid User identifier (UID) + * \return API return code or error code + */ +int security_manager_path_req_set_uid(path_req *p_req, const uid_t uid); + +/* + * This function is used to register a set of paths for given package using + * filled up path_req data structure. + * + * Required privileges: + * - http://tizen.org/privilege/notexist (if uid is not set or set to current user's uid) + * - http://tizen.org/privilege/notexist (if uid is set to some other user's uid) + * + * \param[in] p_req Pointer handling path_req structure + * + * \return API return code or error code: it would be + * - SECURITY_MANAGER_SUCCESS on success, + * - SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED when user does not + * have rights to install requested directories, + * - SECURITY_MANAGER_ERROR_UNKNOWN on other errors. + */ +int security_manager_paths_register(const path_req *p_req); + #ifdef __cplusplus } #endif diff --git a/src/include/security-manager-types.h b/src/include/security-manager-types.h index 01820b4..8f1c1db 100644 --- a/src/include/security-manager-types.h +++ b/src/include/security-manager-types.h @@ -115,6 +115,11 @@ typedef struct policy_entry policy_entry; struct private_sharing_req; typedef struct private_sharing_req private_sharing_req; +/*! brief data structure responsible for handling informations required to register + * a set of paths for given package. */ +struct path_req; +typedef struct path_req path_req; + /*! \brief wildcard to be used in requests to match all possible values of given field. * Use it, for example when it is desired to list or apply policy change for all * users or all apps for selected user. diff --git a/src/server/service/service.cpp b/src/server/service/service.cpp index a0607a0..a102801 100644 --- a/src/server/service/service.cpp +++ b/src/server/service/service.cpp @@ -163,7 +163,7 @@ void Service::processAppInstall(MessageBuffer &buffer, MessageBuffer &send, cons Deserialization::Deserialize(buffer, req.appName); Deserialization::Deserialize(buffer, req.pkgName); Deserialization::Deserialize(buffer, req.privileges); - Deserialization::Deserialize(buffer, req.appPaths); + Deserialization::Deserialize(buffer, req.pkgPaths); Deserialization::Deserialize(buffer, req.uid); Deserialization::Deserialize(buffer, req.tizenVersion); Deserialization::Deserialize(buffer, req.authorName); -- 2.7.4