From 530e6143fd43c29e9566a8bc8ac132cb621c9e38 Mon Sep 17 00:00:00 2001 From: Jan Cybulski Date: Wed, 17 Dec 2014 09:53:19 +0100 Subject: [PATCH] Add offline mode to security_manager_user_add There must be an offline mode for registering user for sake of adding users during image creation time. Change-Id: I295a207c52cfb34fc1464cd1a1214118c1eb3dd7 Signed-off-by: Jan Cybulski --- src/client/client-security-manager.cpp | 38 +++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index 51b0ad0..c3f72d9 100644 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -555,26 +555,40 @@ SECURITY_MANAGER_API int security_manager_user_add(const user_req *p_req) { using namespace SecurityManager; + bool offlineMode; MessageBuffer send, recv; if (!p_req) return SECURITY_MANAGER_ERROR_INPUT_PARAM; return try_catch([&] { + int retval; + try { + SecurityManager::FileLocker serviceLock(SecurityManager::SERVICE_LOCK_FILE); + if ((offlineMode = serviceLock.Locked())) { + LogInfo("Working in offline mode."); + retval = SecurityManager::ServiceImpl::userAdd(p_req->uid, p_req->utype, geteuid()); + } + } catch (const SecurityManager::FileLocker::Exception::Base &e) { + offlineMode = false; + } + if (!offlineMode) { + //server is working - //put data into buffer - Serialization::Serialize(send, static_cast(SecurityModuleCall::USER_ADD)); + //put data into buffer + Serialization::Serialize(send, static_cast(SecurityModuleCall::USER_ADD)); - Serialization::Serialize(send, p_req->uid); - Serialization::Serialize(send, p_req->utype); + Serialization::Serialize(send, p_req->uid); + Serialization::Serialize(send, p_req->utype); - //send buffer to server - int retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv); - if (retval != SECURITY_MANAGER_API_SUCCESS) { - LogError("Error in sendToServer. Error code: " << retval); - return SECURITY_MANAGER_ERROR_UNKNOWN; - } + //send buffer to server + retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv); + if (retval != SECURITY_MANAGER_API_SUCCESS) { + LogError("Error in sendToServer. Error code: " << retval); + return SECURITY_MANAGER_ERROR_UNKNOWN; + } - //receive response from server - Deserialization::Deserialize(recv, retval); + //receive response from server + Deserialization::Deserialize(recv, retval); + } switch(retval) { case SECURITY_MANAGER_API_SUCCESS: return SECURITY_MANAGER_SUCCESS; -- 2.7.4