{
using namespace SecurityServer;
SocketBuffer send, recv;
- Serialization serialization;
- Deserialization deserialization;
std::vector<std::string> permissions_list;
- int i;
- int ret;
LogDebug("security_server_app_enable_permissions() called");
LogDebug("app_id: " << app_id);
//put all strings in STL vector
- for (i = 0; perm_list[i] != NULL; i++) {
+ for (int i = 0; perm_list[i] != NULL; i++) {
LogDebug("perm_list[" << i << "]: " << perm_list[i]);
permissions_list.push_back(std::string(perm_list[i]));
}
//put data into buffer
- serialization.Serialize(send, (int)AppPermissionsAction::ENABLE); //works as a MSG_ID
- serialization.Serialize(send, persistent);
- serialization.Serialize(send, (int)app_type);
- serialization.Serialize(send, std::string(app_id));
- serialization.Serialize(send, permissions_list);
+ Serialization::Serialize(send, (int)AppPermissionsAction::ENABLE); //works as a MSG_ID
+ Serialization::Serialize(send, persistent);
+ Serialization::Serialize(send, (int)app_type);
+ Serialization::Serialize(send, std::string(app_id));
+ Serialization::Serialize(send, permissions_list);
//send buffer to server
- ret = sendToServer(SERVICE_SOCKET_APP_PERMISSIONS, send.Pop(), recv);
- if (ret != SECURITY_SERVER_API_SUCCESS) {
- LogDebug("Unable to send");
- return ret;
+ int result = sendToServer(SERVICE_SOCKET_APP_PERMISSIONS, send.Pop(), recv);
+ if (result != SECURITY_SERVER_API_SUCCESS) {
+ LogDebug("Error in sendToServer. Error code: " << result);
+ return result;
}
//receive response from server
- deserialization.Deserialize(recv, ret);
- if (ret != SECURITY_SERVER_API_SUCCESS) {
- LogDebug("Received error from server");
- return ret;
- }
+ Deserialization::Deserialize(recv, result);
+ return result;
} catch (SocketBuffer::Exception::Base &e) {
LogDebug("SecurityServer::SocketBuffer::Exception " << e.DumpToString());
{
using namespace SecurityServer;
SocketBuffer send, recv;
- Serialization serialization;
- Deserialization deserialization;
std::vector<std::string> permissions_list;
- int i;
- int ret;
LogDebug("security_server_app_disable_permissions() called");
LogDebug("app_id: " << app_id);
//put all strings in STL vector
- for (i = 0; perm_list[i] != NULL; i++) {
+ for (int i = 0; perm_list[i] != NULL; i++) {
LogDebug("perm_list[" << i << "]: " << perm_list[i]);
permissions_list.push_back(std::string(perm_list[i]));
}
//put data into buffer
- serialization.Serialize(send, (int)AppPermissionsAction::DISABLE); //works as a MSG_ID
- serialization.Serialize(send, (int)app_type);
- serialization.Serialize(send, std::string(app_id));
- serialization.Serialize(send, permissions_list);
+ Serialization::Serialize(send, (int)AppPermissionsAction::DISABLE); //works as a MSG_ID
+ Serialization::Serialize(send, (int)app_type);
+ Serialization::Serialize(send, std::string(app_id));
+ Serialization::Serialize(send, permissions_list);
//send buffer to server
- ret = sendToServer(SERVICE_SOCKET_APP_PERMISSIONS, send.Pop(), recv);
- if (ret != SECURITY_SERVER_API_SUCCESS) {
- LogDebug("Unable to send");
- return ret;
+ int result = sendToServer(SERVICE_SOCKET_APP_PERMISSIONS, send.Pop(), recv);
+ if (result != SECURITY_SERVER_API_SUCCESS) {
+ LogDebug("Error in sendToServer. Error code: " << result);
+ return result;
}
//receive response from server
- deserialization.Deserialize(recv, ret);
- if (ret != SECURITY_SERVER_API_SUCCESS) {
- LogDebug("Received error from server");
- return ret;
- }
+ Deserialization::Deserialize(recv, result);
+ return result;
} catch (SocketBuffer::Exception::Base &e) {
LogDebug("SecurityServer::SocketBuffer::Exception " << e.DumpToString());
#include <security-server-common.h>
#include <app-permissions.h>
+namespace {
+
+int privilegeToSecurityServerError(int error) {
+ switch (error) {
+ case PC_OPERATION_SUCCESS: return SECURITY_SERVER_API_SUCCESS;
+ case PC_ERR_FILE_OPERATION: return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ case PC_ERR_MEM_OPERATION: return SECURITY_SERVER_API_ERROR_OUT_OF_MEMORY;
+ case PC_ERR_NOT_PERMITTED: return SECURITY_SERVER_API_ERROR_ACCESS_DENIED;
+ case PC_ERR_INVALID_PARAM: return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
+ case PC_ERR_INVALID_OPERATION:
+ case PC_ERR_DB_OPERATION:
+ default:
+ ;
+ }
+ return SECURITY_SERVER_API_ERROR_UNKNOWN;
+}
+
+} // namespace anonymous
+
namespace SecurityServer {
GenericSocketService::ServiceDescriptionVector AppPermissionsService::GetServiceDescription() {
{
LogDebug("Iteration begin");
SocketBuffer send, recv;
- Serialization serialization;
- Deserialization deserialization;
std::vector<std::string> permissions_list;
std::string app_id;
int persistent;
- int i;
- int ret = SECURITY_SERVER_API_ERROR_SERVER_ERROR;
+ size_t iter;
+ int result = SECURITY_SERVER_API_ERROR_SERVER_ERROR;
app_type_t app_type;
AppPermissionsAction appPermAction;
//receive data from buffer and check MSG_ID
Try {
- deserialization.Deserialize(buffer, i); //receive MSG_ID
- appPermAction = (AppPermissionsAction)i;
+ int temp;
+ Deserialization::Deserialize(buffer, temp); //receive MSG_ID
+ appPermAction = (AppPermissionsAction)temp;
if (appPermAction == AppPermissionsAction::ENABLE) //persistent is only in APP_ENABLE frame
- deserialization.Deserialize(buffer, persistent);
+ Deserialization::Deserialize(buffer, persistent);
- deserialization.Deserialize(buffer, i);
- app_type = (app_type_t)i;
- deserialization.Deserialize(buffer, app_id);
- deserialization.Deserialize(buffer, permissions_list);
+ Deserialization::Deserialize(buffer, temp);
+ app_type = (app_type_t)temp;
+ Deserialization::Deserialize(buffer, app_id);
+ Deserialization::Deserialize(buffer, permissions_list);
} Catch (SocketBuffer::Exception::Base) {
LogDebug("Broken protocol. Closing socket.");
m_serviceManager->Close(conn);
LogDebug("app_id: " << app_id);
//left one free pointer for the NULL at the end
- for (i = 0; i < (int)permissions_list.size(); i++) {
- LogDebug("perm_list[" << i << "]: " << permissions_list[i]);
- perm_list[i] = (permissions_list[i]).c_str();
+ for (iter = 0; iter < permissions_list.size(); ++iter) {
+ LogDebug("perm_list[" << iter << "]: " << permissions_list[iter]);
+ perm_list[iter] = (permissions_list[iter]).c_str();
}
//put the NULL at the end
- perm_list[i] = NULL;
+ perm_list[iter] = NULL;
//use received data
if (appPermAction == AppPermissionsAction::ENABLE) {
LogDebug("Calling app_enable_permiossions()");
- ret = perm_app_enable_permissions(app_id.c_str(), app_type, perm_list.get(), persistent);
- LogDebug("app_enable_permissions() returned: " << ret);
+ result = perm_app_enable_permissions(app_id.c_str(), app_type, perm_list.get(), persistent);
+ LogDebug("app_enable_permissions() returned: " << result);
} else {
LogDebug("Calling app_disable_permiossions()");
- ret = perm_app_disable_permissions(app_id.c_str(), app_type, perm_list.get());
- LogDebug("app_disable_permissions() returned: " << ret);
+ result = perm_app_disable_permissions(app_id.c_str(), app_type, perm_list.get());
+ LogDebug("app_disable_permissions() returned: " << result);
}
//send response
- serialization.Serialize(send, ret);
+ Serialization::Serialize(send, privilegeToSecurityServerError(result));
m_serviceManager->Write(conn, send.Pop());
return true;
}