From b9f3fbed5e620329cf123b41ce2bce6551b7edda Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Mon, 2 May 2016 09:28:33 +0200 Subject: [PATCH] Path registration requests - client side implementation [Feature] Provide API for package path registration. [Solution] Add client side implementation + communication. [Verification] Run tests. TODO prepare tests. Change-Id: Iae9a03894a9780fb4b0a9242e278e940d2e2989d --- src/client/client-security-manager.cpp | 120 +++++++++++++++++++++++++++++++++ src/common/include/protocols.h | 1 + src/common/include/service_impl.h | 11 +++ src/common/service_impl.cpp | 6 ++ src/server/service/include/service.h | 9 +++ src/server/service/service.cpp | 14 ++++ 6 files changed, 161 insertions(+) diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index 9958c49..f88254e 100755 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -1304,3 +1304,123 @@ int security_manager_private_sharing_drop(const private_sharing_req *p_req) }); } +/***************************PATHS***************************************/ + +SECURITY_MANAGER_API +int security_manager_path_req_new(path_req **pp_req) +{ + if (!pp_req) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + + try { + *pp_req = new path_req; + } catch (const std::bad_alloc&) { + return SECURITY_MANAGER_ERROR_MEMORY; + } + (*pp_req)->uid = geteuid(); + + return SECURITY_MANAGER_SUCCESS; +} + +SECURITY_MANAGER_API +void security_manager_path_req_free(path_req *p_req) +{ + delete p_req; +} + +SECURITY_MANAGER_API +int security_manager_path_req_set_pkg_id(path_req *p_req, const char *pkg_id) +{ + if (!p_req || !pkg_id) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + + try { + p_req->pkgName.assign(pkg_id); + } catch (const std::bad_alloc&) { + return SECURITY_MANAGER_ERROR_MEMORY; + } catch (const std::length_error&) { + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + } + return SECURITY_MANAGER_SUCCESS; +} + +SECURITY_MANAGER_API +int security_manager_path_req_set_install_type(path_req *p_req, const enum app_install_type type) +{ + if (!p_req || (type <= SM_APP_INSTALL_NONE) || (type >= SM_APP_INSTALL_END)) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + + p_req->installationType = static_cast(type); + + return SECURITY_MANAGER_SUCCESS; +} + +SECURITY_MANAGER_API +int security_manager_path_req_add_path(path_req *p_req, const char *path, const int path_type) +{ + if (!p_req || !path || (path_type < 0) || (path_type >= SECURITY_MANAGER_ENUM_END)) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + + try { + p_req->pkgPaths.push_back(std::make_pair(path, path_type)); + } catch (const std::bad_alloc&) { + return SECURITY_MANAGER_ERROR_MEMORY; + } catch (const std::length_error&) { + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + } + + return SECURITY_MANAGER_SUCCESS; +} + +SECURITY_MANAGER_API +int security_manager_path_req_set_uid(path_req *p_req, const uid_t uid) +{ + if (!p_req) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + + p_req->uid = uid; + + return SECURITY_MANAGER_SUCCESS; +} + +SECURITY_MANAGER_API +int security_manager_paths_register(const path_req *p_req) +{ + using namespace SecurityManager; + + return try_catch([&]() -> int { + //checking parameters + if (!p_req) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + if (p_req->pkgName.empty()) + return SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE; + + int retval; + ClientOffline offlineMode; + if (offlineMode.isOffline()) { + Credentials creds = offlineMode.getCredentials(); + retval = SecurityManager::ServiceImpl().pathsRegister(creds, *p_req); + } else { + MessageBuffer send, recv; + + //put data into buffer + Serialization::Serialize(send, + (int)SecurityModuleCall::PATHS_REGISTER, + p_req->pkgName, + p_req->uid, + p_req->pkgPaths, + p_req->installationType); + + //send buffer to server + retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv); + if (retval != SECURITY_MANAGER_SUCCESS) { + LogError("Error in sendToServer. Error code: " << retval); + return retval; + } + + //receive response from server + Deserialization::Deserialize(recv, retval); + } + return retval; + }); +} diff --git a/src/common/include/protocols.h b/src/common/include/protocols.h index 3926606..1690f74 100644 --- a/src/common/include/protocols.h +++ b/src/common/include/protocols.h @@ -84,6 +84,7 @@ enum class SecurityModuleCall POLICY_GET_DESCRIPTIONS, GROUPS_GET, APP_HAS_PRIVILEGE, + PATHS_REGISTER, NOOP = 0x90, }; diff --git a/src/common/include/service_impl.h b/src/common/include/service_impl.h index 985bd4f..de7c9e3 100644 --- a/src/common/include/service_impl.h +++ b/src/common/include/service_impl.h @@ -31,6 +31,7 @@ #include "credentials.h" #include "security-manager.h" +#include "protocols.h" namespace SecurityManager { @@ -223,6 +224,16 @@ public: const std::string &ownerAppName, const std::string &targetAppName, const std::vector &paths); + + /** + * Process package paths registration. + * + * @param[in] creds credentials of the requesting process + * @param[in] p_req path registration request + * + * @return API return code, as defined in protocols.h + */ + int pathsRegister(const Credentials &creds, const path_req &p_req); }; } /* namespace SecurityManager */ diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index 576b644..49a99af 100755 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -1243,4 +1243,10 @@ int ServiceImpl::dropPrivatePathSharing( return errorRet; } +int ServiceImpl::pathsRegister(const Credentials &/*creds*/, const path_req &/*req*/) +{ + // TODO + return SECURITY_MANAGER_ERROR_UNKNOWN; +} + } /* namespace SecurityManager */ diff --git a/src/server/service/include/service.h b/src/server/service/include/service.h index 5b4aa8d..b7df7f3 100644 --- a/src/server/service/include/service.h +++ b/src/server/service/include/service.h @@ -171,6 +171,15 @@ private: * @param creds credentials of the requesting process */ void processDropPrivateSharing(MessageBuffer &recv, MessageBuffer &send, const Credentials &creds); + + /** + * Process package paths registration request + * + * @param recv Raw received data buffer + * @param send Raw data buffer to be sent + * @param creds credentials of the requesting process + */ + void processPathsRegister(MessageBuffer &recv, MessageBuffer &send, const Credentials &creds); }; } // namespace SecurityManager diff --git a/src/server/service/service.cpp b/src/server/service/service.cpp index a102801..97af66e 100644 --- a/src/server/service/service.cpp +++ b/src/server/service/service.cpp @@ -125,6 +125,9 @@ bool Service::processOne(const ConnectionID &conn, MessageBuffer &buffer, case SecurityModuleCall::APP_DROP_PRIVATE_SHARING: processDropPrivateSharing(buffer, send, creds); break; + case SecurityModuleCall::PATHS_REGISTER: + processPathsRegister(buffer, send, creds); + break; default: LogError("Invalid call: " << call_type_int); Throw(ServiceException::InvalidAction); @@ -340,4 +343,15 @@ void Service::processDropPrivateSharing(MessageBuffer &recv, MessageBuffer &send int ret = serviceImpl.dropPrivatePathSharing(creds, ownerAppName, targetAppName, paths); Serialization::Serialize(send, ret); } + +void Service::processPathsRegister(MessageBuffer &recv, MessageBuffer &send, const Credentials &creds) +{ + path_req req; + Deserialization::Deserialize(recv, req.pkgName); + Deserialization::Deserialize(recv, req.uid); + Deserialization::Deserialize(recv, req.pkgPaths); + Deserialization::Deserialize(recv, req.installationType); + int ret = serviceImpl.pathsRegister(creds, req); + Serialization::Serialize(send, ret); +} } // namespace SecurityManager -- 2.7.4