Support daemon proxy 83/253883/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 19 Feb 2021 04:36:46 +0000 (13:36 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 22 Feb 2021 00:31:31 +0000 (00:31 +0000)
After this patch is applied, daemons the services can be a proxy.

Change-Id: I47c60d923df74755c5ea0f1396964887fcbd8e85
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/fdbroker-internal.cc

index 033157f..481a054 100644 (file)
@@ -234,13 +234,6 @@ int FdBroker::Send(const std::string& target_appid,
   SocketPair main_sock_pair(mock_);
   SocketPair delegate_sock_pair(mock_);
   FdList fd_list;
-  char sender_appid[255];
-
-  if (!mock_ && aul_app_get_appid_bypid(getpid(),
-       sender_appid, sizeof(sender_appid)) < 0) {
-    _E("Can't get appid");  // LCOV_EXCL_LINE
-    return -1;  // LCOV_EXCL_LINE
-  }
 
   if (main_sock_pair.Request(target_appid, port_name) != 0)
     return -1;
@@ -315,18 +308,8 @@ int FdBroker::Send(const std::string& target_appid,
 int FdBroker::SendSync(const std::string& target_appid,
                        const std::string& port_name,
                        int (*fds)[2]) {
-  char sender_appid[255] = { 0, };
-  int ret;
-  if (!mock_) {
-    ret = aul_app_get_appid_bypid(getpid(), sender_appid, sizeof(sender_appid));
-    if (ret != AUL_R_OK) {
-      _E("Failed to get application ID. ret(%d)", ret);
-      return -1;
-    }
-  }
-
   SocketPair main_sock_pair(mock_);
-  ret = main_sock_pair.Request(target_appid, port_name);
+  int ret = main_sock_pair.Request(target_appid, port_name);
   if (ret != 0)
     return -1;
 
@@ -434,7 +417,7 @@ int FdBroker::SendSync(const std::string& target_appid,
 
   g_variant_get(reply_body, "(i)", &ret);
   if (ret != 0) {
-    _E("Access Denied[sender_appid: %s, result: %d]", sender_appid, ret);
+    _E("Access Denied[result: %d]", ret);
     g_object_unref(reply);
     return -EILLEGALACCESS;
   }
@@ -489,22 +472,27 @@ void FdBroker::OnReceiveDbusMethod(GDBusConnection* conn,
     return;
   }
 
-  int ret = -1;
-  char sender_appid[255];
-  int sender_pid;
+  std::string sender_id;
+  int sender_pid = broker->GetSenderPid(conn, sender);
+  char sender_appid[256];
+  int ret = aul_app_get_appid_bypid(sender_pid, sender_appid,
+      sizeof(sender_appid));
+  if (ret < 0)
+    sender_id = "Daemon";
+  else
+    sender_id = std::string(sender_appid);
 
-  sender_pid = broker->GetSenderPid(conn, sender);
-  if (aul_app_get_appid_bypid(sender_pid, sender_appid,
-      sizeof(sender_appid)) < 0) {
+  if (sender_id.empty()) {
+    ret = -1;
     g_dbus_method_invocation_return_value(invocation,
         g_variant_new("(i)", ret));
     return;
   }
 
   AccessController& ac = broker->GetAccessController();
-  ret = ac.Check(conn, sender, sender_appid);
+  ret = ac.Check(conn, sender, sender_id.c_str());
   if (ret == 0)
-    broker->ReceiveMessage(sender_appid, invocation);
+    broker->ReceiveMessage(sender_id.c_str(), invocation);
 
   g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret));
 }