Modify rpc-port path creation 86/308786/10
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 1 Apr 2024 05:41:36 +0000 (14:41 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 3 Apr 2024 09:26:59 +0000 (18:26 +0900)
This patch is for linux daemon and service.
If the caller uid is less than 5000, the port creation function does not
use the uid to create the port path.
The aul library checks the prefix has a "d::" or not.
If it has the prefix, aul returns the port path without using base64 encoding.

Change-Id: I68431de1a37471f5f9d6089a27dcca4951b55b1c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/aul/aul_proc.cc
src/aul/aul_rpc_port.cc

index e592975..cbcf852 100644 (file)
@@ -19,6 +19,7 @@
 #include <bundle_cpp.h>
 #include <bundle_internal.h>
 #include <fcntl.h>
+#include <glib-unix.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -44,7 +45,10 @@ namespace {
 class ProcContext {
  public:
   ProcContext() {}
-  ~ProcContext() {}
+  ~ProcContext() {
+    if (source_ != 0)
+      g_source_remove(source_);
+  }
 
   void SetName(std::string name) {
     std::lock_guard<std::mutex> lock(mutex_);
@@ -69,6 +73,7 @@ class ProcContext {
   void SetFd(int fd) {
     std::lock_guard<std::mutex> lock(mutex_);
     fd_.Set(fd);
+    source_ = g_unix_fd_add(fd, G_IO_IN, UnixFdFunc, this);
   }
 
   void Close() {
@@ -82,10 +87,41 @@ class ProcContext {
   }
 
  private:
+  void Reset() {
+    std::lock_guard<std::mutex> lock(mutex_);
+    name_ = "";
+    fd_.Close();
+    extra_ = tizen_base::Bundle();
+    source_ = 0;
+  }
+
+  static gboolean UnixFdFunc(gint fd, GIOCondition condition,
+                             gpointer user_data) {
+    auto* proc_context = static_cast<ProcContext*>(user_data);
+
+    if (condition & G_IO_IN) {
+      int ret = aul_sock_recv_result_with_fd(fd);
+      if (ret != 0) {
+        _E("Failed to receive result. fd(%d)", fd);
+        proc_context->Reset();
+        return G_SOURCE_REMOVE;
+      }
+      _D("Result(%d) received", ret);
+    } else if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+      _E("Socket was disconnected. fd(%d)", fd);
+      proc_context->Reset();
+      return G_SOURCE_REMOVE;
+    }
+
+    return G_SOURCE_CONTINUE;
+  }
+
+ private:
   FileDescriptor fd_;
   std::string name_;
   tizen_base::Bundle extra_;
   mutable std::mutex mutex_;
+  guint source_;
 };
 
 int ReadFromPath(const std::string& path, char* buf, size_t buf_size) {
@@ -211,13 +247,6 @@ extern "C" API int aul_proc_register(const char* name, bundle* extra) {
     return ret;
   }
 
-  int res = aul_sock_recv_result_with_fd(ret);
-  if (res != 0) {
-    _E("Failed to receive the result. fd(%d)", res);
-    close(ret);
-    return AUL_R_ERROR;
-  }
-
   context.SetFd(ret);
   context.SetName(name);
   if (extra)
index 7a8d68b..592b1fe 100644 (file)
@@ -40,8 +40,10 @@ using namespace aul::internal;
 namespace {
 
 constexpr const char kEndpoint[] = "org.tizen.rpcport";
-constexpr const char kInterfacePrefix[] = "org.tizen.rpcport._";
+constexpr const char kInterfacePrefix[] = "org.tizen.rpcport_.";
 constexpr const char kPathRunAulRpcPort[] = "/run/aul/rpcport/";
+constexpr const char kDPrefix[] = "d::";
+constexpr const char kUdPrefix[] = "ud::";
 
 class WatchInfo {
  public:
@@ -119,6 +121,12 @@ class WatchInfo {
 
 std::string GetInterfaceName(const std::string& app_id,
     const std::string& port_name, uid_t uid) {
+  if (app_id.compare(0, strlen(kDPrefix), kDPrefix) == 0)
+    return app_id + "::" + port_name;
+
+  if (app_id.compare(0, strlen(kUdPrefix), kUdPrefix) == 0)
+    return std::to_string(uid) + "::" + app_id + "::" + port_name;
+
   std::string name = kInterfacePrefix + app_id + "_" + port_name;
   char* checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
       name.c_str(), name.length());