2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Rafal Krypa <r.krypa@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file master-service.cpp
20 * @author Lukasz Kostyra <l.kostyra@samsung.com>
21 * @author Rafal Krypa <r.krypa@samsung.com>
22 * @brief Implementation of security-manager master service.
25 #include <generic-socket-manager.h>
27 #include <dpl/log/log.h>
28 #include <dpl/serialization.h>
30 #include "protocols.h"
31 #include "master-service.h"
32 #include "service_impl.h"
34 namespace SecurityManager {
36 const InterfaceID IFACE = 1;
38 MasterService::MasterService()
42 GenericSocketService::ServiceDescriptionVector MasterService::GetServiceDescription()
44 return ServiceDescriptionVector {
45 {MASTER_SERVICE_SOCKET, "security-manager-master", IFACE},
49 bool MasterService::processOne(const ConnectionID &conn, MessageBuffer &buffer,
50 InterfaceID interfaceID)
52 LogDebug("Iteration begin. Interface = " << interfaceID);
54 //waiting for all data
55 if (!buffer.Ready()) {
65 if (!ServiceImpl::getPeerID(conn.sock, uid, pid)) {
66 LogError("Closing socket because of error: unable to get peer's uid and pid");
67 m_serviceManager->Close(conn);
71 if (IFACE == interfaceID) {
73 // deserialize API call type
75 Deserialization::Deserialize(buffer, call_type_int);
76 SecurityModuleCall call_type = static_cast<SecurityModuleCall>(call_type_int);
80 LogError("Invalid call: " << call_type_int);
81 Throw(MasterServiceException::InvalidAction);
83 // if we reach this point, the protocol is OK
85 } Catch (MessageBuffer::Exception::Base) {
86 LogError("Broken protocol.");
87 } Catch (MasterServiceException::Base) {
88 LogError("Broken protocol.");
89 } catch (const std::exception &e) {
90 LogError("STD exception " << e.what());
92 LogError("Unknown exception");
96 LogError("Wrong interface");
101 m_serviceManager->Write(conn, send.Pop());
103 LogError("Closing socket because of error");
104 m_serviceManager->Close(conn);
111 } // namespace SecurityManager