*/
int rpc_port_deregister_proc_info(void);
+/**
+ * @brief Gets the pid and uid of the connected rpc port.
+ * @since_tizen 8.0
+ * @param[in] h The rpc port handle
+ * @param[out] pid Process ID
+ * @param[out] uid User ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int rpc_port_get_peer_info(rpc_port_h h, pid_t *pid, uid_t *uid);
+
#ifdef __cplusplus
}
#endif
#include "include/rpc-port-internal.h"
#include "include/rpc-port.h"
+#include "peer-cred-internal.hh"
+#include "port-internal.hh"
#undef RPC_API
#define RPC_API extern "C" __attribute__((visibility("default")))
namespace {
+using namespace rpc_port::internal;
constexpr uid_t kRegularUidMin = 5000;
std::atomic<uid_t> __target_uid { getuid() };
return RPC_PORT_ERROR_NONE;
}
+
+RPC_API int rpc_port_get_peer_info(rpc_port_h h, pid_t* pid, uid_t* uid) {
+ if (h == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto port = static_cast<Port*>(h);
+ std::shared_ptr<PeerCred> cred(PeerCred::Get(port->GetFd()));
+ if (cred.get() == nullptr)
+ return RPC_PORT_ERROR_IO_ERROR;
+
+ if (pid)
+ *pid = cred->GetPid();
+
+ if (uid)
+ *uid = cred->GetUid();
+
+ return RPC_PORT_ERROR_NONE;
+}
+