#define LOG_TAG "NOTIFICATION_EX"
#define MAX_PACKAGE_STR_SIZE 512
+#define NORMAL_UID_BASE 5000
+
+#define DBUS_NAME "org.freedesktop.DBus"
+#define DBUS_OBJECT_PATH "/org/freedesktop/DBus"
+#define DBUS_INTERFACE_NAME "org.freedesktop.DBus"
using namespace std;
using namespace tizen_base;
LOGI("Dbus_event_listener impl created");
}
+uid_t DBusEventListener::Impl::GetSenderUid(GDBusConnection* connection,
+ const char* sender_name) {
+ GDBusMessage* msg = nullptr;
+ GDBusMessage* reply = nullptr;
+ GError* err = nullptr;
+ GVariant* body;
+ uid_t uid = 0;
+
+ msg = g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
+ DBUS_INTERFACE_NAME, "GetConnectionUnixUser");
+ if (!msg) {
+ LOGE("Failed to alloc new method call");
+ goto out;
+ }
+
+ g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
+ reply = g_dbus_connection_send_message_with_reply_sync(connection, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
+
+ if (!reply) {
+ if (err != nullptr) {
+ LOGE("Failed to get uid [%s]", err->message);
+ g_error_free(err);
+ }
+ goto out;
+ }
+
+ body = g_dbus_message_get_body(reply);
+ g_variant_get(body, "(u)", &uid);
+
+out:
+ if (msg)
+ g_object_unref(msg);
+ if (reply)
+ g_object_unref(reply);
+
+ return uid;
+}
+
+pid_t DBusEventListener::Impl::GetSenderPid(GDBusConnection* connection,
+ const char* sender_name) {
+ GDBusMessage* msg = nullptr;
+ GDBusMessage* reply = nullptr;
+ GError* err = nullptr;
+ GVariant* body;
+ pid_t pid = 0;
+
+ msg = g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
+ DBUS_INTERFACE_NAME, "GetConnectionUnixProcessID");
+ if (!msg) {
+ LOGE("Failed to alloc new method call");
+ goto out;
+ }
+
+ g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
+ reply = g_dbus_connection_send_message_with_reply_sync(connection, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
+
+ if (!reply) {
+ if (err != nullptr) {
+ LOGE("Failed to get uid [%s]", err->message);
+ g_error_free(err);
+ }
+ goto out;
+ }
+
+ body = g_dbus_message_get_body(reply);
+ g_variant_get(body, "(u)", &pid);
+
+out:
+ if (msg)
+ g_object_unref(msg);
+ if (reply)
+ g_object_unref(reply);
+
+ return pid;
+}
+
void DBusEventListener::Impl::SignalCb(GDBusConnection* connection,
const gchar* sender_name,
const gchar* object_path,
Bundle b(event_info_raw);
EventInfo info(b);
+
+ if (info.GetEventType() == EventInfo::Post
+ || info.GetEventType() == EventInfo::Update) {
+ uid_t uid = GetSenderUid(connection, sender_name);
+ if (uid >= NORMAL_UID_BASE) {
+ pid_t pid = GetSenderPid(connection, sender_name);
+ info.SetValidatedOwner(util::GetAppId(pid));
+ info.SetValidatedUid(uid);
+ }
+ }
+
dl->parent_->NotifyObserver(info, ret_list);
}
uid_ = getuid();
request_id_ = util::GetRequestId();
error_ = ERROR_NONE;
+ validated_uid_ = 0;
LOGI("EventInfo impl created");
}
return impl_->owner_;
}
+void EventInfo::SetValidatedOwner(std::string owner) {
+ impl_->validated_owner_ = owner;
+}
+
+string EventInfo::GetValidatedOwner() const {
+ return impl_->validated_owner_;
+}
+
string EventInfo::GetChannel() const {
return impl_->channel_;
}
impl_->uid_ = uid;
}
+uid_t EventInfo::GetValidatedUid() const {
+ return impl_->validated_uid_;
+}
+
+void EventInfo::SetValidatedUid(uid_t uid) {
+ impl_->validated_uid_ = uid;
+}
+
int EventInfo::GetRequestId() const {
return impl_->request_id_;
}
#include <string>
#include <memory>
+#include <map>
#include "notification-ex/ex_util.h"
#define LOG_TAG "NOTIFICATION_EX"
#define MAX_PACKAGE_STR_SIZE 512
+#define MAX_CACHE_SIZE 100
using namespace std;
namespace notification {
}
string GetAppId() {
- static string appid = "";
+ return GetAppId(getpid());
+}
+
+string GetAppId(pid_t pid) {
+ static map<pid_t, string> appid_cache;
+
+ string appid;
char appid_buf[MAX_PACKAGE_STR_SIZE] = {0, };
- if (!appid.empty()) {
- LOGI("appid(%s)", appid.c_str());
- return appid;
+ if (appid_cache.find(pid) != appid_cache.end()) {
+ LOGI("appid(%s)", appid_cache[pid].c_str());
+ return appid_cache[pid];
}
- int pid = getpid();
+ if (appid_cache.size() > MAX_CACHE_SIZE)
+ appid_cache.clear();
+
int ret = aul_app_get_appid_bypid(pid, appid_buf, sizeof(appid_buf));
if (ret == AUL_R_OK) {
appid = string(appid_buf);
}
LOGI("appid(%s)", appid.c_str());
+ appid_cache[pid] = appid;
return appid;
}