Add IClient::getName() for getting the package id (or the executable path) of a client 15/137315/3
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 5 Jul 2017 07:43:07 +0000 (16:43 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 7 Jul 2017 02:43:10 +0000 (11:43 +0900)
Change-Id: I2c8143e8c69767123efc08c8d4e1cdcb278227c4
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
packaging/context-service.spec
src/server/CMakeLists.txt
src/server/Credential.cpp
src/server/Credential.h
src/server/MethodCall.cpp
src/server/ServiceClient.cpp
src/server/ServiceClient.h

index f0ab6e3..aa23c13 100644 (file)
@@ -17,6 +17,7 @@ BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(alarm-service)
 BuildRequires: pkgconfig(cynara-creds-gdbus)
 BuildRequires: pkgconfig(cynara-client)
index 4b474cc..b0c8ba2 100644 (file)
@@ -8,6 +8,7 @@ SET(DEPS
        gio-2.0
        dlog
        capi-base-common
+       aul
        alarm-service
        cynara-creds-gdbus
        cynara-client
index 445e569..6a29163 100644 (file)
@@ -147,6 +147,11 @@ uid_t Credential::getUid() const
        return __uid;
 }
 
+pid_t Credential::getPid() const
+{
+       return __pid;
+}
+
 const std::string& Credential::getClientId() const
 {
        return __clientId;
index 2c00f27..f5f01ad 100644 (file)
@@ -33,6 +33,7 @@ namespace ctx {
                bool hasPrivilege(const char* privil) const;
 
                uid_t getUid() const;
+               pid_t getPid() const;
                const std::string& getClientId() const;
                bool isSystem() const;
 
index 6d50861..81f75df 100644 (file)
@@ -90,7 +90,7 @@ uid_t MethodCall::getUid()
 
 const std::string& MethodCall::getCallerId()
 {
-       return getCaller().getId();
+       return getCaller().getName();
 }
 
 bool MethodCall::isSystem()
index 757b787..fe8ced2 100644 (file)
  * limitations under the License.
  */
 
+#include <fstream>
+#include <aul.h>
 #include "Credential.h"
 #include "ServiceRunner.h"
 #include "ServiceClient.h"
 
+#define BUFFER_SIZE    256
+
 using namespace ctx;
 
 ServiceClient::ServiceClient(ServiceRunner* runner, const std::string& busName) :
@@ -39,16 +43,48 @@ void ServiceClient::setHandler(IMethodCallHandler* handler)
        __methodCallHandler = handler;
 }
 
-const std::string& ServiceClient::getBusName()
+const std::string& ServiceClient::getName()
 {
-       return __busName;
+       if (!__name.empty())
+               return __name;
+
+       char buffer[BUFFER_SIZE];
+
+       // Package ID
+       int err = aul_app_get_pkgid_bypid_for_uid(__credential->getPid(), buffer, BUFFER_SIZE, __credential->getUid());
+       if (IS_SUCCESS(err)) {
+               __name = buffer;
+               _I("PkgId: %s", __name.c_str());
+               return __name;
+       }
+
+       // Executable Path
+       char path[32];
+       g_snprintf(path, 32, "/proc/%d/cmdline", __credential->getPid());
+
+       std::ifstream cmdfile(path);
+       std::string cmdline;
+
+       if (std::getline(cmdfile, cmdline)) {
+               __name = cmdline;
+               _I("cmd: %s", __name.c_str());
+               return __name;
+       }
+
+       _E("Failed to get the client's name");
+       return __name;
 }
 
-const std::string& ServiceClient::getId()
+const std::string& ServiceClient::getSecurityLabel()
 {
        return __credential->getClientId();
 }
 
+const std::string& ServiceClient::getBusName()
+{
+       return __busName;
+}
+
 uid_t ServiceClient::getUid()
 {
        return __credential->getUid();
index f401539..3de5c58 100644 (file)
@@ -36,8 +36,9 @@ namespace ctx {
 
                void setHandler(IMethodCallHandler* handler);
 
+               const std::string& getName();
+               const std::string& getSecurityLabel();
                const std::string& getBusName();
-               const std::string& getId();
 
                uid_t getUid();
                bool isSystem();
@@ -60,6 +61,7 @@ namespace ctx {
 
                ServiceRunner* __serviceRunner;
                IMethodCallHandler* __methodCallHandler;
+               std::string __name;
                std::string __busName;
                Credential* __credential;
        };