+++ /dev/null
-/*
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Bumjin Im <bj.im@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 exec-path.cpp
- * @author Zofia Abramowska (z.abramowska@samsung.com)
- * @version 1.0
- * @brief Implementation of api-exec-path service.
- */
-
-#include <string>
-
-#include <unistd.h>
-#include <sys/smack.h>
-
-#include <dpl/log/log.h>
-#include <dpl/serialization.h>
-
-#include <protocols.h>
-#include <exec-path.h>
-#include <security-server.h>
-#include <security-server-util.h>
-#include <smack-check.h>
-
-namespace SecurityServer {
-
-GenericSocketService::ServiceDescriptionVector ExecPathService::GetServiceDescription() {
- return ServiceDescriptionVector
- {{SERVICE_SOCKET_EXEC_PATH, "security-server" }};
-}
-
-void ExecPathService::accept(const AcceptEvent &event) {
- LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock
- << " ConnectionID.counter: " << event.connectionID.counter
- << " ServiceID: " << event.interfaceID);
-}
-
-void ExecPathService::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 ExecPathService::processOne(const ConnectionID &conn, MessageBuffer &buffer) {
- LogDebug("Processing message");
-
- int pid = 0;
- char *exe;
-
- if (!buffer.Ready()) {
- return false;
- }
-
- Try {
- Deserialization::Deserialize(buffer, pid);
- } Catch (MessageBuffer::Exception::Base) {
- LogDebug("Broken protocol. Closing socket.");
- m_serviceManager->Close(conn);
- return false;
- }
-
- MessageBuffer sendBuffer;
- int retVal;
-
- // get executable path
- exe = read_exe_path_from_proc(pid);
- // quickly getting rid of allocated memory
- // when read_exe_path_from_proc will rewritten this won't be required
- std::string exec_path(exe ? exe : "");
- free(exe);
-
- if (exec_path.empty())
- {
- LogError("Server: Failed to read executable path for pid " << pid);
- retVal = SECURITY_SERVER_API_ERROR_SERVER_ERROR;
- Serialization::Serialize(sendBuffer, retVal);
- m_serviceManager->Write(conn, sendBuffer.Pop());
- return true;
- }
-
- retVal = SECURITY_SERVER_API_SUCCESS;
- Serialization::Serialize(sendBuffer, retVal);
- Serialization::Serialize(sendBuffer, exec_path);
- m_serviceManager->Write(conn, sendBuffer.Pop());
- return true;
-}
-
-void ExecPathService::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 ExecPathService::close(const CloseEvent &event) {
- LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
- m_messageBufferMap.erase(event.connectionID.counter);
-}
-
-} // namespace SecurityServer
-
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Bumjin Im <bj.im@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 exec-path.h
- * @author Zofia Abramowska (z.abramowska@samsung.com)
- * @version 1.0
- * @brief Implementation of api-exec-path
- */
-
-#ifndef _SECURITY_SERVER_EXEC_PATH_
-#define _SECURITY_SERVER_EXEC_PATH_
-
-#include <service-thread.h>
-#include <generic-socket-manager.h>
-
-#include <message-buffer.h>
-
-namespace SecurityServer {
-
-class ExecPathService
- : public SecurityServer::GenericSocketService
- , public SecurityServer::ServiceThread<ExecPathService>
-{
-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 SecurityServer
-
-#endif // _SECURITY_SERVER_EXEC_PATH_