LogDebug("security_server_app_enable_permissions() called");
- try {
+ return try_catch([&] {
if ((NULL == app_id) || (strlen(app_id) == 0)) {
LogDebug("App_id is NULL");
return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
//receive response from server
Deserialization::Deserialize(recv, result);
return result;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
LogDebug("security_server_app_disable_permissions() called");
- try {
+ return try_catch([&] {
if ((NULL == app_id) || (strlen(app_id) == 0)) {
LogDebug("App_id is NULL");
return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
//receive response from server
Deserialization::Deserialize(recv, result);
return result;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
return SECURITY_SERVER_API_SUCCESS;
}
+int try_catch(const std::function<int()>& func)
+{
+ try {
+ return func();
+ } catch (MessageBuffer::Exception::Base &e) {
+ LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
+ } catch (std::exception &e) {
+ LogError("STD exception " << e.what());
+ } catch (...) {
+ LogError("Unknown exception occured");
+ }
+ return SECURITY_SERVER_API_ERROR_UNKNOWN;
+}
} // namespace SecurityServer
#define _SECURITY_SERVER_CLIENT_
#include <vector>
+#include <functional>
#include <message-buffer.h>
*/
int sendToServerAncData(char const * const interface, const RawBuffer &send, struct msghdr &hdr);
+/*
+ * Decorator function that performs frequently repeated exception handling in
+ * SS client API functions. Accepts lambda expression as an argument.
+ */
+int try_catch(const std::function<int()>& func);
+
} // namespace SecuritySever
#endif // _SECURITY_SERVER_CLIENT_
LogDebug("security_server_request_cookie() called");
- try {
+ return try_catch([&] {
//checking parameters
if (bufferSize < COOKIE_SIZE) {
LogDebug("Buffer for cookie too small");
memcpy(cookie, &receivedCookie[0], receivedCookie.size());
return retval;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
//preprae cookie to send
std::vector<char> key(cookie, cookie + COOKIE_SIZE);
- try {
+ return try_catch([&] {
//put data into buffer
Serialization::Serialize(send, (int)CookieCall::CHECK_PID);
Serialization::Serialize(send, key);
Deserialization::Deserialize(recv, pid);
return pid;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
//preprae cookie to send
std::vector<char> key(cookie, cookie + COOKIE_SIZE);
- try {
+ return try_catch([&] {
//put data into buffer
Serialization::Serialize(send, (int)CookieCall::CHECK_PRIVILEGE_GID);
Serialization::Serialize(send, key);
//receive response from server
Deserialization::Deserialize(recv, retval);
return retval;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
std::string obj(object);
std::string access(access_rights);
- try {
+ return try_catch([&] {
//put data into buffer
Serialization::Serialize(send, (int)CookieCall::CHECK_PRIVILEGE);
Serialization::Serialize(send, key);
//receive response from server
Deserialization::Deserialize(recv, retval);
return retval;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
//preprae cookie to send
std::vector<char> key(cookie, cookie + COOKIE_SIZE);
- try {
+ return try_catch([&] {
//put data into buffer
Serialization::Serialize(send, (int)CookieCall::CHECK_UID);
Serialization::Serialize(send, key);
}
return retval;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
//preprae cookie to send
std::vector<char> key(cookie, cookie + COOKIE_SIZE);
- try {
+ return try_catch([&] {
//put data into buffer
Serialization::Serialize(send, (int)CookieCall::CHECK_GID);
Serialization::Serialize(send, key);
}
return retval;
-
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
-
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
int security_server_get_gid(const char *objectName) {
using namespace SecurityServer;
- try {
+
+ return try_catch([&] {
if (NULL == objectName){
LogDebug("Objects name is NULL");
return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
// No errors, return gid
gid_t gid;
Deserialization::Deserialize(recv, gid);
- return gid;
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ return static_cast<int>(gid);
+ });
}
int security_server_get_object_name(gid_t gid, char *pObjectName, size_t maxObjectSize)
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (pObjectName == NULL){
LogDebug("Objects name is NULL or empty");
return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
return result;
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
#include <protocols.h>
#include <security-server.h>
+#include <security-server-common.h>
inline bool isPasswordIncorrect(const char* pwd)
{
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (NULL == current_attempts || NULL == max_attempts ||
NULL == valid_secs) {
}
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (current_attempts == NULL || max_attempts == NULL || valid_secs == NULL ||
isPasswordIncorrect(challenge)) {
LogError("Wrong input param");
}
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (NULL == cur_pwd)
cur_pwd = "";
Deserialization::Deserialize(recv, retCode);
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
MessageBuffer send, recv;
Serialization::Serialize(send, static_cast<int>(PasswordHdrs::HDR_SET_PWD_VALIDITY));
Deserialization::Deserialize(recv, retCode);
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
MessageBuffer send, recv;
Serialization::Serialize(send, static_cast<int>(PasswordHdrs::HDR_SET_PWD_MAX_CHALLENGE));
Deserialization::Deserialize(recv, retCode);
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (isPasswordIncorrect(new_pwd)) {
LogError("Wrong input param.");
return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
Deserialization::Deserialize(recv, retCode);
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
{
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (history_size > static_cast<int>(MAX_PASSWORD_HISTORY) || history_size < 0) {
LogError("Wrong input param.");
return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
Deserialization::Deserialize(recv, retCode);
return retCode;
- } catch (MessageBuffer::Exception::Base &e) {
- LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogError("STD exception " << e.what());
- } catch (...) {
- LogError("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
const char *object,
const char *access_rights) {
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (1 != smack_check())
return SECURITY_SERVER_API_SUCCESS;
Deserialization::Deserialize(recv, result);
return result;
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}
SECURITY_SERVER_API
int security_server_app_give_access(const char *customer_label, int customer_pid) {
using namespace SecurityServer;
- try {
+ return try_catch([&] {
if (1 != smack_check())
return SECURITY_SERVER_API_SUCCESS;
Deserialization::Deserialize(recv, result);
return result;
- } catch (MessageBuffer::Exception::Base &e) {
- LogDebug("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
- } catch (std::exception &e) {
- LogDebug("STD exception " << e.what());
- } catch (...) {
- LogDebug("Unknown exception occured");
- }
- return SECURITY_SERVER_API_ERROR_UNKNOWN;
+ });
}