#include "common/dbus_service.h"
+#include <cynara-creds-gdbus.h>
#include <glib.h>
#include <gio/gio.h>
#include <sys/types.h>
namespace capmgr {
+struct GDBusCredentials : public SecurityManager::Credentials {
+ public:
+ GDBusCredentials() { init_ = false; }
+ GDBusCredentials(int pid, const char* user, const char* smack_label);
+ ~GDBusCredentials();
+ bool Init(const gchar* sender, GDBusConnection* conn);
+ private:
+ gchar* sender_;
+ GDBusConnection* conn_;
+};
+
+GDBusCredentials::GDBusCredentials(int pid, const char* user,
+ const char* smack_label) {
+ pid_ = pid;
+ init_ = false;
+ smack_label_ = strdup(smack_label);
+ if (!smack_label_) {
+ return;
+ }
+
+ user_ = strdup(user);
+ if (!user_) {
+ free(smack_label_);
+ smack_label_ = nullptr;
+ return;
+ }
+}
+
+SecurityManager::Credentials GetCredentials(
+ GDBusConnection* conn, const gchar* sender) {
+ int ret = 0;
+ int pid = 0;
+ char* user = nullptr;
+ char* client = nullptr;
+
+ ret = cynara_creds_gdbus_get_user(conn, sender, USER_METHOD_DEFAULT, &user);
+ if (ret != CYNARA_API_SUCCESS) {
+ LOG(ERROR) << "cynara_creds_gdbus_get_user() failed: " << ret;
+ return GDBusCredentials();
+ }
+
+ ret = cynara_creds_gdbus_get_client(conn, sender, CLIENT_METHOD_DEFAULT,
+ &client);
+ if (ret != CYNARA_API_SUCCESS) {
+ LOG(ERROR) << "cynara_creds_gdbus_get_client() failed: " << ret;
+ return GDBusCredentials();
+ }
+
+ ret = cynara_creds_gdbus_get_pid(conn, sender, &pid);
+ if (ret != CYNARA_API_SUCCESS) {
+ LOG(ERROR) << "cynara_creds_gdbus_get_pid() failed: " << ret;
+ return GDBusCredentials();
+ }
+
+ GDBusCredentials c = GDBusCredentials(pid, client, user);
+ if (!c.Init(sender, conn))
+ return GDBusCredentials();
+
+ return c;
+}
+
+GDBusCredentials::~GDBusCredentials() {
+ if (smack_label_)
+ free(smack_label_);
+
+ if (user_)
+ free(user_);
+
+ if (sender_)
+ g_free(sender_);
+
+ if (conn_)
+ g_object_unref(conn_);
+}
+
+bool GDBusCredentials::Init(const gchar* sender, GDBusConnection* conn) {
+ sender_ = g_strdup(sender);
+ if (!sender_) {
+ init_ = false;
+ return false;
+ }
+
+ conn_ = reinterpret_cast<GDBusConnection*>(g_object_ref(conn));
+ init_ = true;
+
+ return true;
+}
+
DBusService::DBusService() {
node_info_ = g_dbus_node_info_new_for_xml(kDBusInstropectionXml, nullptr);
if (node_info_) {
return false;
}
- SecurityManager::Credentials c = SecurityManager::GetCredentials(connection,
- sender);
+ SecurityManager::Credentials c = GetCredentials(connection, sender);
if (!SecurityManager::CheckFilePermission(file_path_str, c)) {
LOG(ERROR) << "File permission error: " << file_path_str;
g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", -1));
\r
#include "common/security_manager.h"\r
\r
-#include <cynara-creds-gdbus.h>\r
-#include <gio/gio.h>\r
#include <sys/smack.h>\r
\r
#include "common/utils/logging.h"\r
\r
namespace capmgr {\r
\r
-struct GDBusCredentials : public SecurityManager::Credentials {\r
- public:\r
- GDBusCredentials() { init_ = false; }\r
- GDBusCredentials(int pid, const char* user, const char* smack_label);\r
- ~GDBusCredentials();\r
- bool Init(const gchar* sender, GDBusConnection* conn);\r
- private:\r
- gchar* sender_;\r
- GDBusConnection* conn_;\r
-};\r
-\r
-GDBusCredentials::GDBusCredentials(int pid, const char* user,\r
- const char* smack_label) {\r
- pid_ = pid;\r
- init_ = false;\r
- smack_label_ = strdup(smack_label);\r
- if (!smack_label_) {\r
- return;\r
- }\r
-\r
- user_ = strdup(user);\r
- if (!user_) {\r
- free(smack_label_);\r
- smack_label_ = nullptr;\r
- return;\r
- }\r
-}\r
-\r
-GDBusCredentials::~GDBusCredentials() {\r
- if (smack_label_)\r
- free(smack_label_);\r
-\r
- if (user_)\r
- free(user_);\r
-\r
- if (sender_)\r
- g_free(sender_);\r
-\r
- if (conn_)\r
- g_object_unref(conn_);\r
-}\r
-\r
-bool GDBusCredentials::Init(const gchar* sender, GDBusConnection* conn) {\r
- sender_ = g_strdup(sender);\r
- if (!sender_) {\r
- init_ = false;\r
- return false;\r
- }\r
-\r
- conn_ = reinterpret_cast<GDBusConnection*>(g_object_ref(conn));\r
- init_ = true;\r
-\r
- return true;\r
-}\r
-\r
bool SecurityManager::Credentials::IsInit() {\r
return this->init_;\r
}\r
return this->user_;\r
}\r
\r
-SecurityManager::Credentials SecurityManager::GetCredentials(\r
- GDBusConnection* conn, const gchar* sender) {\r
- int ret = 0;\r
- int pid = 0;\r
- char* user = nullptr;\r
- char* client = nullptr;\r
-\r
- ret = cynara_creds_gdbus_get_user(conn, sender, USER_METHOD_DEFAULT, &user);\r
- if (ret != CYNARA_API_SUCCESS) {\r
- LOG(ERROR) << "cynara_creds_gdbus_get_user() failed: " << ret;\r
- return GDBusCredentials();\r
- }\r
-\r
- ret = cynara_creds_gdbus_get_client(conn, sender, CLIENT_METHOD_DEFAULT,\r
- &client);\r
- if (ret != CYNARA_API_SUCCESS) {\r
- LOG(ERROR) << "cynara_creds_gdbus_get_client() failed: " << ret;\r
- return GDBusCredentials();\r
- }\r
-\r
- ret = cynara_creds_gdbus_get_pid(conn, sender, &pid);\r
- if (ret != CYNARA_API_SUCCESS) {\r
- LOG(ERROR) << "cynara_creds_gdbus_get_pid() failed: " << ret;\r
- return GDBusCredentials();\r
- }\r
-\r
- GDBusCredentials c = GDBusCredentials(pid, client, user);\r
- if (!c.Init(sender, conn))\r
- return GDBusCredentials();\r
-\r
- return c;\r
-}\r
-\r
bool SecurityManager::CheckFilePermission(const std::string& file_path,\r
SecurityManager::Credentials c) {\r
char* real_file_path = nullptr;\r
#ifndef COMMON_SECURITY_MANAGER_H_
#define COMMON_SECURITY_MANAGER_H_
-#include <gio/gio.h>
-
-#include <memory>
#include <string>
namespace capmgr {
char* smack_label_;
};
- static SecurityManager::Credentials GetCredentials(GDBusConnection* conn,
- const gchar* sender);
static bool CheckFilePermission(const std::string& file_path,
SecurityManager::Credentials c);
};