LogDebug("privilege_name: " << privilege_name);
//put data into buffer
- Serialization::Serialize(send, static_cast<int>(PrivilegeCheckCall::CHECK_GIVEN_APP));
+ Serialization::Serialize(send, static_cast<int>(PrivilegeCheckHdrs::CHECK_GIVEN_APP));
Serialization::Serialize(send, std::string(app_id));
Serialization::Serialize(send, static_cast<int>(app_type));
Serialization::Serialize(send, std::string(privilege_name));
LogDebug("privilege_name: " << privilege_name);
//put data into buffer
- Serialization::Serialize(send, static_cast<int>(PrivilegeCheckCall::CHECK_CALLER_APP));
+ Serialization::Serialize(send, static_cast<int>(PrivilegeCheckHdrs::CHECK_CALLER_APP));
Serialization::Serialize(send, static_cast<int>(app_type));
Serialization::Serialize(send, std::string(privilege_name));
--- /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 connection-info.h
+ * @author Lukasz Kostyra (l.kostyra@partner.samsung.com)
+ * @version 1.0
+ * @brief Definition of ConnectionInfo structure and ConnectionInfoMap type.
+ */
+
+#ifndef _CONNECTION_INFO_H_
+#define _CONNECTION_INFO_H_
+
+#include <map>
+#include <generic-socket-manager.h>
+#include <message-buffer.h>
+
+namespace SecurityServer
+{
+ struct ConnectionInfo {
+ InterfaceID interfaceID;
+ MessageBuffer buffer;
+ };
+
+ typedef std::map<int, ConnectionInfo> ConnectionInfoMap;
+} //namespace SecurityServer
+
+#endif //_CONNECTION_INFO_H_
CHECK_UID
};
-enum class PrivilegeCheckCall
+enum class PrivilegeCheckHdrs
{
CHECK_GIVEN_APP,
CHECK_CALLER_APP
#include <security-server.h>
#include <security-server-common.h>
+namespace SecurityServer {
namespace {
return SECURITY_SERVER_API_ERROR_UNKNOWN;
}
-} // namespace anonymous
+// interface ids
+const InterfaceID CHANGE_APP_PERMISSIONS = 0;
+const InterfaceID CHECK_APP_PRIVILEGE = 1;
-namespace SecurityServer {
+} // namespace anonymous
GenericSocketService::ServiceDescriptionVector AppPermissionsService::GetServiceDescription() {
return ServiceDescriptionVector {
{ SERVICE_SOCKET_APP_PERMISSIONS,
"security-server::api-app-permissions",
- static_cast<int>(InterfaceType::CHANGE_APP_PERMISSIONS) },
+ CHANGE_APP_PERMISSIONS },
{ SERVICE_SOCKET_APP_PRIVILEGE_BY_NAME,
"security-server::api-app-privilege-by-name",
- static_cast<int>(InterfaceType::CHECK_APP_PRIVILEGE) }
+ CHECK_APP_PRIVILEGE }
};
}
LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock
<< " ConnectionID.counter: " << event.connectionID.counter
<< " ServiceID: " << event.interfaceID);
- auto &info = m_socketInfoMap[event.connectionID.counter];
- info.interfaceID = static_cast<InterfaceType>(event.interfaceID);
+ auto &info = m_connectionInfoMap[event.connectionID.counter];
+ info.interfaceID = event.interfaceID;
}
void AppPermissionsService::write(const WriteEvent &event) {
void AppPermissionsService::process(const ReadEvent &event) {
LogDebug("Read event for counter: " << event.connectionID.counter);
- auto &info = m_socketInfoMap[event.connectionID.counter];
+ auto &info = m_connectionInfoMap[event.connectionID.counter];
info.buffer.Push(event.rawBuffer);
// We can get several requests in one package.
void AppPermissionsService::close(const CloseEvent &event) {
LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
- m_socketInfoMap.erase(event.connectionID.counter);
+ m_connectionInfoMap.erase(event.connectionID.counter);
}
bool AppPermissionsService::processOne(const ConnectionID &conn,
MessageBuffer &buffer,
- InterfaceType interfaceID)
+ InterfaceID interfaceID)
{
LogDebug("Iteration begin");
LogDebug("Entering app_permissions server side handler");
switch(interfaceID) {
- case InterfaceType::CHANGE_APP_PERMISSIONS:
+ case CHANGE_APP_PERMISSIONS:
return processPermissionsChange(conn, buffer);
- case InterfaceType::CHECK_APP_PRIVILEGE:
+ case CHECK_APP_PRIVILEGE:
return processCheckAppPrivilege(conn, buffer);
default:
int result = SECURITY_SERVER_API_ERROR_SERVER_ERROR;
app_type_t app_type;
bool has_permission = false;
- PrivilegeCheckCall checkType = PrivilegeCheckCall::CHECK_GIVEN_APP;
+ PrivilegeCheckHdrs checkType = PrivilegeCheckHdrs::CHECK_GIVEN_APP;
LogDebug("Processing app privilege check request");
Try {
int temp;
Deserialization::Deserialize(buffer, temp); // call type
- checkType = static_cast<PrivilegeCheckCall>(temp);
+ checkType = static_cast<PrivilegeCheckHdrs>(temp);
LogDebug("App privilege check call type: "
- << (checkType == PrivilegeCheckCall::CHECK_GIVEN_APP ?
+ << (checkType == PrivilegeCheckHdrs::CHECK_GIVEN_APP ?
"CHECK_GIVEN_APP":"CHECK_CALLER_APP"));
- if (checkType == PrivilegeCheckCall::CHECK_GIVEN_APP) { //app_id present only in this case
+ if (checkType == PrivilegeCheckHdrs::CHECK_GIVEN_APP) { //app_id present only in this case
Deserialization::Deserialize(buffer, app_id); //get app id
}
Deserialization::Deserialize(buffer, temp); //get app type
return false;
}
- if (checkType == PrivilegeCheckCall::CHECK_CALLER_APP) { //get sender app_id in this case
+ if (checkType == PrivilegeCheckHdrs::CHECK_CALLER_APP) { //get sender app_id in this case
char *label = NULL;
if (smack_new_label_from_socket(conn.sock, &label) < 0) {
LogDebug("Error in smack_new_label_from_socket(): "
#include <generic-socket-manager.h>
#include <dpl/serialization.h>
#include <message-buffer.h>
+#include <connection-info.h>
#include <security-server-common.h>
namespace SecurityServer {
, public SecurityServer::ServiceThread<AppPermissionsService>
{
public:
- enum class InterfaceType {
- CHANGE_APP_PERMISSIONS,
- CHECK_APP_PRIVILEGE,
- };
-
- struct SocketInfo {
- InterfaceType interfaceID;
- MessageBuffer buffer;
- };
-
- typedef std::map<int, SocketInfo> SocketInfoMap;
-
ServiceDescriptionVector GetServiceDescription();
DECLARE_THREAD_EVENT(AcceptEvent, accept)
void close(const CloseEvent &event);
private:
- bool processOne(const ConnectionID &conn, MessageBuffer &buffer, InterfaceType interfaceID);
+ bool processOne(const ConnectionID &conn, MessageBuffer &buffer, InterfaceID interfaceID);
bool processPermissionsChange(const ConnectionID &conn, MessageBuffer &buffer);
bool processCheckAppPrivilege(const ConnectionID &conn, MessageBuffer &buffer);
- SocketInfoMap m_socketInfoMap;
+ ConnectionInfoMap m_connectionInfoMap;
};
} // namespace SecurityServer
LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock
<< " ConnectionID.counter: " << event.connectionID.counter
<< " ServiceID: " << event.interfaceID);
- auto &info = m_socketInfoMap[event.connectionID.counter];
+ auto &info = m_connectionInfoMap[event.connectionID.counter];
info.interfaceID = event.interfaceID;
}
void CookieService::process(const ReadEvent &event) {
LogDebug("Read event for counter: " << event.connectionID.counter);
- auto &info = m_socketInfoMap[event.connectionID.counter];
+ auto &info = m_connectionInfoMap[event.connectionID.counter];
info.buffer.Push(event.rawBuffer);
// We can get several requests in one package.
void CookieService::close(const CloseEvent &event) {
LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
- m_socketInfoMap.erase(event.connectionID.counter);
+ m_connectionInfoMap.erase(event.connectionID.counter);
}
-bool CookieService::processOne(const ConnectionID &conn, MessageBuffer &buffer, int interfaceID)
+bool CookieService::processOne(const ConnectionID &conn, MessageBuffer &buffer, InterfaceID interfaceID)
{
LogDebug("Iteration begin");
MessageBuffer send, recv;
#include <generic-socket-manager.h>
#include <dpl/serialization.h>
#include <message-buffer.h>
+#include <connection-info.h>
#include <security-server-common.h>
#include <cookie-jar.h>
, public SecurityServer::ServiceThread<CookieService>
{
public:
- struct SocketInfo
- {
- int interfaceID;
- MessageBuffer buffer;
- };
-
- typedef std::map<int, SocketInfo> SocketInfoMap;
ServiceDescriptionVector GetServiceDescription();
void close(const CloseEvent &event);
private:
- bool processOne(const ConnectionID &conn, MessageBuffer &buffer, int interfaceID);
+ bool processOne(const ConnectionID &conn, MessageBuffer &buffer, InterfaceID interfaceID);
bool cookieRequest(MessageBuffer &send, int socket);
CookieJar m_cookieJar;
- SocketInfoMap m_socketInfoMap;
+ ConnectionInfoMap m_connectionInfoMap;
};
} // namespace SecurityServer
#include <protocols.h>
#include <open-for.h>
#include <unistd.h>
+#include <algorithm>
#include <security-server.h>
#include <security-server-util.h>
namespace SecurityServer {
+OpenForService::OpenForConnInfo::~OpenForConnInfo() {
+ std::for_each(descriptorsVector.begin(),descriptorsVector.end(), ::close);
+}
+
GenericSocketService::ServiceDescriptionVector OpenForService::GetServiceDescription() {
return ServiceDescriptionVector
{{SERVICE_SOCKET_OPEN_FOR, "security-server::api-open-for", SERVICE_SOCKET_ID, true}};
void OpenForService::process(const ReadEvent &event)
{
LogDebug("Read event for counter: " << event.connectionID.counter);
- auto &info = m_socketInfoMap[event.connectionID.counter];
+ auto &info = m_connectionInfoMap[event.connectionID.counter];
info.buffer.Push(event.rawBuffer);
// We can get several requests in one package.
void OpenForService::close(const CloseEvent &event)
{
LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
- auto &descVector = m_socketInfoMap[event.connectionID.counter].descriptorsVector;
+ auto &descVector = m_connectionInfoMap[event.connectionID.counter].descriptorsVector;
for (auto iter = descVector.begin(); iter != descVector.end(); ++iter)
TEMP_FAILURE_RETRY(::close(*iter));
- m_socketInfoMap.erase(event.connectionID.counter);
+ m_connectionInfoMap.erase(event.connectionID.counter);
}
bool OpenForService::processOne(const ConnectionID &conn, MessageBuffer &buffer, std::vector<int> &descVector)
namespace SecurityServer
{
- typedef std::vector<int> DescriptorVector;
-
- struct SocketInfo {
- DescriptorVector descriptorsVector;
- MessageBuffer buffer;
- };
-
- typedef std::map<int, SocketInfo> SocketInfoMap;
-
class OpenForService
: public SecurityServer::GenericSocketService
, public SecurityServer::ServiceThread<OpenForService>
void close(const CloseEvent &event);
private:
+ typedef std::vector<int> DescriptorVector;
+
+ struct OpenForConnInfo {
+ ~OpenForConnInfo();
+
+ DescriptorVector descriptorsVector;
+ MessageBuffer buffer;
+ };
+
+ typedef std::map<int, OpenForConnInfo> OpenForConnInfoMap;
+
//internal service functions
bool processOne(const ConnectionID &conn, MessageBuffer &buffer, DescriptorVector &descVector);
- SocketInfoMap m_socketInfoMap;
+ OpenForConnInfoMap m_connectionInfoMap;
SharedFile m_sharedFile;
};
} // namespace SecurityServer