USD: Add service for asking user for permission
authorJan Cybulski <j.cybulski@samsung.com>
Fri, 31 Jul 2015 12:57:50 +0000 (14:57 +0200)
committerStanislaw Wadas <s.wadas@samsung.com>
Thu, 3 Sep 2015 13:36:59 +0000 (15:36 +0200)
Change-Id: Idc5f9f58e2804c37466a7ad58dee92d4414d53c8
Signed-off-by: Jan Cybulski <j.cybulski@samsung.com>
Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
19 files changed:
USD/src/CMakeLists.txt
USD/src/client/client-common.cpp
USD/src/client/usb-ask-user-client.cpp [new file with mode: 0644]
USD/src/common/protocols.cpp
USD/src/common/protocols.h
USD/src/include/usb-security-daemon.h
USD/src/main/dbus-manager.cpp
USD/src/main/server2-main.cpp
USD/src/main/socket-manager.cpp
USD/src/service/add-permission.cpp [new file with mode: 0644]
USD/src/service/add-permission.h [new file with mode: 0644]
USD/src/service/usb-access.cpp
USD/src/service/usb-access.h
USD/src/service/usb-ask-user-service.cpp [new file with mode: 0644]
USD/src/service/usb-ask-user-service.h [new file with mode: 0644]
USD/systemd/CMakeLists.txt
USD/systemd/usd-ask-user.socket [new file with mode: 0644]
USD/systemd/usd.service
packaging/capi-system-usbhost.spec

index 223adfc2b901931a0b59c0e4bff7b0bc658f9d7b..db99d49c2a176c31e992ec7ffef294f92c6a1c2e 100644 (file)
@@ -18,6 +18,8 @@ SET(USD_SOURCES
     ${SERVER2_PATH}/main/dbus-manager.cpp
     ${SERVER2_PATH}/client/usb-access-client.cpp
     ${SERVER2_PATH}/client/client-common.cpp
+    ${SERVER2_PATH}/service/usb-ask-user-service.cpp
+    ${SERVER2_PATH}/service/add-permission.cpp
     )
 
 SET_SOURCE_FILES_PROPERTIES(
@@ -67,6 +69,7 @@ INCLUDE_DIRECTORIES(
 SET(USD_CLIENT_SOURCES
     ${SERVER2_PATH}/client/client-common.cpp
     ${SERVER2_PATH}/client/usb-access-client.cpp
+    ${SERVER2_PATH}/client/usb-ask-user-client.cpp
     )
 
 ADD_LIBRARY(${TARGET_USD_CLIENT} SHARED ${USD_CLIENT_SOURCES})
index b0ce9c6ea54e0448daaa80e7f6a3e19dd19d035e..103c249e1da0a5c719fdb4f7e8418254c2ed53ba 100644 (file)
@@ -42,7 +42,7 @@ IMPLEMENT_SAFE_SINGLETON(USD::Log::LogSystem);
 */
 namespace {
 
-const int POLL_TIMEOUT = 2000;
+const int POLL_TIMEOUT = 60000;
 
 void securityClientEnableLogSystem(void) {
     USD::Singleton<USD::Log::LogSystem>::Instance().SetTag("USD_CLIENT");
diff --git a/USD/src/client/usb-ask-user-client.cpp b/USD/src/client/usb-ask-user-client.cpp
new file mode 100644 (file)
index 0000000..a820253
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Karol Lewandowski <k.lewandowsk@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        usb-ask-user-client.cpp
+ * @author      Jan Cybulski <j.cybulski@samsung.com>
+ * @version     1.0
+ * @brief       This file is implementation of client side functions for service
+ * which manages popups to user.
+ */
+
+#include <stdio.h>
+
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+
+#include <message-buffer.h>
+#include <client-common.h>
+#include <protocols.h>
+
+#include <usb-security-daemon.h>
+
+_USD_API_
+int usd_ask_user_to_grant_permission(const char *path) {
+    using namespace USD;
+
+    return try_catch([&] {
+        if (NULL == path){
+            LogDebug("path is NULL");
+            return USD_API_ERROR_INPUT_PARAM;
+        }
+
+        MessageBuffer send, recv;
+        Serialization::Serialize(send, std::string(path));
+
+        int retCode = sendToServer(
+          SERVICE_SOCKET_ASK_USER,
+          send.Pop(),
+          recv);
+
+        if (retCode == USD_API_SUCCESS) {
+            Deserialization::Deserialize(recv, retCode);
+        }
+
+        return retCode;
+
+    });
+}
+
index 09b420cf13fd5c62a23401300582ea3378b1acc5..1c557d8ce13579defbfc1459cca8ed804ce302bb 100644 (file)
@@ -34,5 +34,8 @@ namespace USD {
 char const * const SERVICE_SOCKET_USB_ACCESS =
         SOCKET_PATH_PREFIX_USD "usd-api-usb-access.socket";
 
+char const * const SERVICE_SOCKET_ASK_USER =
+        SOCKET_PATH_PREFIX_USD "usd-api-ask-user.socket";
+
 } // namespace USD
 
index f417f60a4c2c02a71fb87d0fc163a47b0266a77b..072755df75c4610ba1a6baab812aedc7183309e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Bumjin Im <bj.im@samsung.com>
  *
@@ -29,6 +29,7 @@
 namespace USD {
 
 extern char const *const SERVICE_SOCKET_USB_ACCESS;
+extern char const *const SERVICE_SOCKET_ASK_USER;
 
 enum class USBAccessCall
 {
index 103d7b24df1e9334d711ce1724523d8f04359a95..d49b6b64be844ea4a22dae71d74d7c6dae0e5308 100644 (file)
 /*! \brief   indicating file read error  */
 #define USD_API_ERROR_FILE_READ_FAILED -28
 
+/*! \brief   indicating that there is yet policy set for device*/
+#define USD_API_ERROR_POLICY_UNKNOWN -29
+
 /*! \brief   indicating the error with unknown reason */
 #define USD_API_ERROR_UNKNOWN -255
 /** @}*/
@@ -207,6 +210,8 @@ int usd_open_usb_device(const char *devpath, int *fd);
 int usd_setup_usb_device_access(const char *topology, const char *smack,
                                bool allow);
 
+int usd_ask_user_to_grant_permission(const char *path);
+
 #ifdef __cplusplus
 }
 #endif
index 8c2a8525cf5113ff3de90985967ff56ae3caab03..ea268ab8f47014fd86f32b62fd30f43acc156582 100644 (file)
@@ -33,6 +33,7 @@
 #include <thread>
 #include <string>
 #include <dpl/log/log.h>
+#include <add-permission.h>
 
 
 namespace USD {
@@ -267,16 +268,15 @@ bool DbusManager::waitForPopupHandled(pid_t popup_pid) {
 bool DbusManager::handlePopup(pid_t pid, int popupResult) {
     std::lock_guard<std::mutex> lock(m_popupHandleMutex);
 
-    //PopupData *popupData;
+    USBAddPermission addPerm;
     auto it = m_popupMap.find(pid);
     if (it != m_popupMap.end()) {
-        //popupData = &*it;
         const char *device = getPopupDevice(pid);
         const char *application = getPopupApp(pid);
         bool allow = (popupResult == USB_DEVICE_CONFIRM_OK);
         LogDebug("Got popup answer notify from pid" << pid);
         this->m_popupMap.erase(pid);
-        usd_setup_usb_device_access(device, application, allow);
+        addPerm.writePermission(device, application, allow);
         return true;
     }
     LogWarning("Someone tries to fake popup answer data... ");
index 0431c3ff45e0702eb78acab4f25c8eadd9f89e63..a2d2f7b7eb2d69ed9a0c9355c72af32779a44368 100644 (file)
@@ -33,6 +33,7 @@
 
 
 #include <usb-access.h>
+#include <usb-ask-user-service.h>
 
 IMPLEMENT_SAFE_SINGLETON(USD::Log::LogSystem);
 
@@ -83,8 +84,8 @@ int main(void) {
         LogInfo("Start!");
         USD::SocketManager manager;
 
-
         REGISTER_SOCKET_SERVICE(manager, USD::USBAccessService);
+        REGISTER_SOCKET_SERVICE(manager, USD::UsbAskUserService);
         dbusmanager.Create();
         manager.MainLoop();
         dbusmanager.Join();
index fa073b40bfac6c62d8705c76dc6b4f65a312a739..ce021b7df282c0c7109462d99a8d9f1a9051ba46 100644 (file)
@@ -48,7 +48,7 @@
 
 namespace {
 
-const time_t SOCKET_TIMEOUT = 20;
+const time_t SOCKET_TIMEOUT = 60;
 
 } // namespace anonymous
 
diff --git a/USD/src/service/add-permission.cpp b/USD/src/service/add-permission.cpp
new file mode 100644 (file)
index 0000000..85a352e
--- /dev/null
@@ -0,0 +1,86 @@
+/*-*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-*/
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Stanislaw Wadas <s.wadas@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        add-permission.cpp
+ * @author      Stanislaw Wadas <s.wadas@samsung.com>
+ * @version     1.0
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/serialization.h>
+
+#include <protocols.h>
+#include <usb-security-daemon.h>
+#include <usd-util.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <add-permission.h>
+#include <usb-access.h>
+#include <usb-access-map.h>
+#include <dbus-manager.h>
+#include <cstdint>
+
+namespace USD {
+
+USBAccessMap m_accessMap;
+
+int USBAddPermission::writePermission(const char *path, const char *smack, bool policy)
+{
+    using namespace USD;
+
+    LogDebug("Processing writePermission");
+
+    int retCode = USD_API_ERROR_SERVER_ERROR;
+
+    try {
+        std::string smack1, path1;
+        bool valid;
+        path1 = std::string(path);
+        smack1 = std::string(smack);
+
+        USBAccessMapKey mk(smack1,
+                           USBDeviceId(path1, USBDevicePath::PATH_TYPE_SYSFS));
+
+        LogDebug("policy: " << policy
+                 << ", smack: " << smack << ", path: " << path1);
+
+        valid = mk.validate();
+        LogDebug("Validation" << (valid ? "ok" : "failed")
+                 <<" on: " << mk << ", policy: " << policy);
+
+        if (valid) {
+            std::lock_guard<std::mutex> lock(m_eventWriteDBMutex);
+            m_accessMap[mk] = policy;
+            retCode = USD_API_SUCCESS;
+        } else {
+            retCode = USD_API_ERROR_ACCESS_DENIED;
+            LogDebug("SD_API_ERROR_ACCESS_DENIED");
+        }
+    } catch(int e) {
+        LogDebug("Error occured on processing: " << e);
+        retCode = e;
+    }
+
+    return retCode;
+}
+
+} // namespace USD
diff --git a/USD/src/service/add-permission.h b/USD/src/service/add-permission.h
new file mode 100644 (file)
index 0000000..51e4da6
--- /dev/null
@@ -0,0 +1,56 @@
+/*-*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-*/
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Stanislaw Wadas <s.wadas@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        add-permission.h
+ * @author      Stanislaw Wadas <s.wadas@samsung.com>
+ * @version     1.0
+ */
+
+#ifndef USD_ADD_PERMISSION_H_
+#define USD_ADD_PERMISSION_H_
+
+#include <usb-access-map.h>
+#include <usb-access.h>
+#include <service-thread.h>
+#include <generic-socket-manager.h>
+
+#include <dpl/serialization.h>
+#include <message-buffer.h>
+#include <usb-access-map.h>
+#include <mutex>
+
+
+namespace USD {
+
+extern USBAccessMap m_accessMap;
+
+
+class USBAddPermission
+
+{
+public:
+       int writePermission(const char *topology, const char *smack, bool allow);
+
+private:
+       std::mutex m_eventWriteDBMutex;
+};
+
+} /* namespace USD */
+
+#endif /* USD_USB_ACCESS_H_ */
index c5d80e73e89077d27efbe09f87e1cded84bc0da2..509c04e06596abcf662c9cbb9b6986941d0a9d1f 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <usb-access.h>
 #include <usb-access-map.h>
+#include <dbus-manager.h>
+#include <add-permission.h>
 
 namespace {
 // Service may open more than one socket.
@@ -56,7 +58,7 @@ const int SERVICE_SOCKET_ID = 0;
 
 } // namespace anonymous
 
-
+extern USD::DbusManager dbusmanager;
 
 namespace USD {
 
@@ -98,7 +100,7 @@ void USBAccessService::write(const WriteEvent &event)
         m_serviceManager->Close(event.connectionID);
 }
 
-bool USBAccessService::checkAccessEntry(PolicySubjectId subjectId,
+int USBAccessService::checkAccessEntry(PolicySubjectId subjectId,
                                         const USBDeviceId &devId)
 {
     USBAccessMapKey key(subjectId, devId);
@@ -108,14 +110,14 @@ bool USBAccessService::checkAccessEntry(PolicySubjectId subjectId,
 
     auto it = m_accessMap.find(key);
     if (it == m_accessMap.end()) {
-        LogDebug("There is no entry in the database. Return deny.");
-        return false;
+        LogDebug("There is no entry in the database.");
+        return USD_API_ERROR_POLICY_UNKNOWN;
     }
 
     LogDebug("There is an entry in a database. "
-             "Return value of policy: " << it->second);
+             "Value of policy: " << it->second);
 
-    return it->second;
+    return it->second ? USD_API_SUCCESS : USD_API_ERROR_ACCESS_DENIED;
 }
 
 static inline int openFileForClient(const char *path, int &fd)
@@ -140,21 +142,32 @@ bool USBAccessService::processOpen(const ConnectionID &conn,
 
     try {
         std::string path;
-        bool accessGranted;
         PolicySubjectId peerId(conn.sock);
 
         Deserialization::Deserialize(buffer, path);
 
         USBDeviceId devId(path, USBDevicePath::PATH_TYPE_DEV);
 
-        accessGranted = checkAccessEntry(peerId, devId);
-        if (accessGranted || true) {
+        retCode = checkAccessEntry(peerId, devId);
+        if (retCode == USD_API_ERROR_POLICY_UNKNOWN) {
+            USBAccessMapKey mapkey(peerId, devId);
+            pid_t pid = dbusmanager.addPopupRequest(mapkey);
+            if (dbusmanager.waitForPopupHandled(pid))
+                retCode = checkAccessEntry(peerId, devId);
+            else
+                retCode = USD_API_ERROR_POLICY_UNKNOWN;
+        }
+
+        if (retCode == USD_API_SUCCESS) {
             LogDebug("Access granted for opening: "
                      << path << " which belongs to: " << devId
                      << " by: " << peerId);
             retCode = openFileForClient(path.c_str(), fd);
-        } else {
-            retCode = USD_API_ERROR_ACCESS_DENIED;
+        }
+        else {
+            LogDebug("Access denied for opening: "
+                     << path << " which belongs to: " << devId
+                     << " by: " << peerId << " Error code: " << retCode);
         }
     } catch(int e) {
         retCode = e;
@@ -192,6 +205,7 @@ bool USBAccessService::processSetupPolicy(const ConnectionID &conn,
         LogDebug("Validation" << (valid ? "ok" : "failed")
                  <<" on: " << mk << ", policy: " << policy);
         if (valid) {
+            std::lock_guard<std::mutex> lock(m_eventWriteDBMutex);
             m_accessMap[mk] = policy;
             retCode = USD_API_SUCCESS;
         } else {
index 23fa677b4f1db42e558f31c3525a7ace38f6134b..ab1e2162fdf6581c4cd4827aea046d365148739f 100644 (file)
@@ -60,10 +60,10 @@ private:
     bool processOne(const ConnectionID &conn, MessageBuffer &buffer);
     bool processOpen(const ConnectionID &conn, MessageBuffer &buffer);
     bool processSetupPolicy(const ConnectionID &conn, MessageBuffer &buffer);
-    bool checkAccessEntry(PolicySubjectId subjectId, const USBDeviceId &devId);
+    int checkAccessEntry(PolicySubjectId subjectId, const USBDeviceId &devId);
+       std::mutex m_eventWriteDBMutex;
 
     MessageBufferMap m_messageBufferMap;
-    USBAccessMap m_accessMap;
 };
 
 } /* namespace USD */
diff --git a/USD/src/service/usb-ask-user-service.cpp b/USD/src/service/usb-ask-user-service.cpp
new file mode 100644 (file)
index 0000000..bd63a14
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Karol Lewandowski <k.lewandowsk@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        usb-ask-user-service.cpp
+ * @author      Jan Cybulski <j.cybulski@samsung.com>
+ * @version     1.0
+ * @brief       Implementation of service asking users for access.
+ */
+
+#include <sys/smack.h>
+
+#include <dpl/log/log.h>
+#include <dpl/serialization.h>
+#include <dpl/exception.h>
+
+
+#include <protocols.h>
+#include <usb-ask-user-service.h>
+
+#include <usb-security-daemon.h>
+#include <usd-util.h>
+#include <smack-check.h>
+
+#include <usb-access-map.h>
+#include <dbus-manager.h>
+
+
+extern USD::DbusManager dbusmanager;
+
+
+namespace USD {
+
+
+
+UsbAskUserService::ServiceDescriptionVector UsbAskUserService::GetServiceDescription() {
+    return ServiceDescriptionVector
+        {{SERVICE_SOCKET_ASK_USER, "usd::api-ask-user" }};
+}
+
+void UsbAskUserService::accept(const AcceptEvent &event) {
+    LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock
+        << " ConnectionID.counter: " << event.connectionID.counter
+        << " ServiceID: " << event.interfaceID);
+}
+
+void UsbAskUserService::write(const WriteEvent &event) {
+    LogDebug("WriteEvent. ConnectionID: " << event.connectionID.sock <<
+        " Size: " << event.size << " Left: " << event.left);
+    if (event.left == 0)
+        m_serviceManager->Close(event.connectionID);
+}
+
+bool UsbAskUserService::processOne(const ConnectionID &conn, MessageBuffer &buffer) {
+    LogDebug("Iteration begin");
+
+    std::string path;
+
+
+    int retCode = USD_API_ERROR_SERVER_ERROR;
+
+
+    if (!buffer.Ready()) {
+        return false;
+    }
+
+    Try {
+        Deserialization::Deserialize(buffer, path);
+        PolicySubjectId subject(conn.sock);
+        USBDeviceId device(path, USBDevicePath::PATH_TYPE_DEV);
+        USBAccessMapKey mk(subject, device);
+        pid_t pid = dbusmanager.addPopupRequest(mk);
+        if (dbusmanager.waitForPopupHandled(pid))
+            retCode = USD_API_SUCCESS;
+        else
+            retCode = USD_API_ERROR_AUTHENTICATION_FAILED;
+    } Catch (MessageBuffer::Exception::Base) {
+        LogError("Broken protocol. Closing socket.");
+        m_serviceManager->Close(conn);
+        return false;
+    } catch (int e) {
+        LogError("Something wrong, ret code: " << e);
+    } catch (...) {
+        LogError("Something wrong.");
+    }
+    LogDebug("Processing finished, returning " << retCode);
+    MessageBuffer sendBuffer;
+    Serialization::Serialize(sendBuffer, retCode);
+    m_serviceManager->Write(conn, sendBuffer.Pop());
+
+    return true;
+}
+
+void UsbAskUserService::process(const ReadEvent &event) {
+    LogDebug("Read event for counter: " << event.connectionID.counter);
+    auto &buffer = m_messageBufferMap[event.connectionID.counter];
+    buffer.Push(event.rawBuffer);
+
+    // We can get several requests in one package.
+    // Extract and process them all
+    while(processOne(event.connectionID, buffer));
+}
+
+void UsbAskUserService::close(const CloseEvent &event) {
+    LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
+    m_messageBufferMap.erase(event.connectionID.counter);
+}
+
+} /* namespace USD */
+
diff --git a/USD/src/service/usb-ask-user-service.h b/USD/src/service/usb-ask-user-service.h
new file mode 100644 (file)
index 0000000..cbe574d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Karol Lewandowski <k.lewandowsk@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        usb-ask-user-service.cpp
+ * @author      Jan Cybulski <j.cybulski@samsung.com>
+ * @version     1.0
+ * @brief       Implementation of service asking users for access.
+ */
+
+#ifndef _USD_ASK_USER_SERVICE_
+#define _USD_ASK_USER_SERVICE_
+
+#include <service-thread.h>
+#include <generic-socket-manager.h>
+
+#include <dpl/serialization.h>
+#include <message-buffer.h>
+#include <usb-access-map.h>
+
+
+namespace USD {
+
+class UsbAskUserService  :
+    public USD::GenericSocketService
+  , public USD::ServiceThread<UsbAskUserService>
+{
+public:
+    typedef std::map<int, MessageBuffer> MessageBufferMap;
+
+    ServiceDescriptionVector GetServiceDescription();
+
+    DECLARE_THREAD_EVENT(AcceptEvent, accept)
+    DECLARE_THREAD_EVENT(WriteEvent, write)
+    DECLARE_THREAD_EVENT(ReadEvent, process)
+    DECLARE_THREAD_EVENT(CloseEvent, close)
+
+    void accept(const AcceptEvent &event);
+    void write(const WriteEvent &event);
+    void process(const ReadEvent &event);
+    void close(const CloseEvent &event);
+private:
+    bool processOne(const ConnectionID &conn, MessageBuffer &buffer);
+    MessageBufferMap m_messageBufferMap;
+
+
+};
+
+} /* namespace USD*/
+
+#endif
index 10cdc6557d61d22447152c601f1e4ed3a9052551..708bb8341168173bf5f68198fac1345d075ab634 100644 (file)
@@ -1,6 +1,7 @@
 INSTALL(FILES
     ${CMAKE_SOURCE_DIR}/USD/systemd/usd.service
     ${CMAKE_SOURCE_DIR}/USD/systemd/usd-access.socket
+    ${CMAKE_SOURCE_DIR}/USD/systemd/usd-ask-user.socket
     DESTINATION
     ${SYSTEMD_DIR}
 )
diff --git a/USD/systemd/usd-ask-user.socket b/USD/systemd/usd-ask-user.socket
new file mode 100644 (file)
index 0000000..5b54fce
--- /dev/null
@@ -0,0 +1,11 @@
+[Socket]
+ListenStream=/run/usd/usd-api-ask-user.socket
+SocketMode=0777
+SmackLabelIPIn=*
+SmackLabelIPOut=@
+
+Service=usd.service
+
+
+[Install]
+WantedBy=sockets.target
index 51dc8fafaeb686f6d706f50295cc31a4d448d313..e7629020de74955b32a98ab04490b7182534d47b 100644 (file)
@@ -5,6 +5,8 @@ Description=USB security daemon
 Type=notify
 ExecStart=/usr/bin/usd
 Sockets=usd-access.socket
+Sockets=usd-ask-user.socket
+
 
 [Install]
 WantedBy=multi-user.target
index 870aeaeb750572e012c988694e48ab4877bc3f21..3be62c0c95c7d5cccbecaa6401cdbefc3e9e1884 100644 (file)
@@ -70,6 +70,7 @@ mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants
 mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants
 ln -s ../usd.service %{buildroot}%{_unitdir}/multi-user.target.wants/usd.service
 ln -s ../usd-access.socket %{buildroot}%{_unitdir}/sockets.target.wants/usd-access.socket
+ln -s ../usd-ask-user.socket %{buildroot}%{_unitdir}/sockets.target.wants/usd-ask-user.socket
 
 
 %post -p /sbin/ldconfig
@@ -164,7 +165,9 @@ fi
 %attr(-,root,root) %{_unitdir}/multi-user.target.wants/usd.service
 %attr(-,root,root) %{_unitdir}/usd.service
 %attr(-,root,root) %{_unitdir}/sockets.target.wants/usd-access.socket
+%attr(-,root,root) %{_unitdir}/sockets.target.wants/usd-ask-user.socket
 %attr(-,root,root) %{_unitdir}/usd-access.socket
+%attr(-,root,root) %{_unitdir}/usd-ask-user.socket
 %{_datadir}/license/%{name}
 
 %files libusd-client