Add offline mode to security_manager_user_add 60/32360/7
authorJan Cybulski <j.cybulski@samsung.com>
Wed, 17 Dec 2014 08:53:19 +0000 (09:53 +0100)
committerJan Cybulski <j.cybulski@samsung.com>
Tue, 20 Jan 2015 13:06:56 +0000 (14:06 +0100)
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 <j.cybulski@samsung.com>
src/client/client-security-manager.cpp

index 51b0ad0..c3f72d9 100644 (file)
@@ -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<int>(SecurityModuleCall::USER_ADD));
+            //put data into buffer
+            Serialization::Serialize(send, static_cast<int>(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;