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 f0ab6e30d09a24fe699fdb7180154a236c341448..aa23c13f9c146ad18765dbb37201505ab7227207 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 4b474cc4631acda96154032b2387279f77ea3752..b0c8ba24b4c3d050ea9f34bbf67891b79dc382ee 100644 (file)
@@ -8,6 +8,7 @@ SET(DEPS
        gio-2.0
        dlog
        capi-base-common
+       aul
        alarm-service
        cynara-creds-gdbus
        cynara-client
index 445e5696640afdcc7d6c4f77aefab0fbe1f9bc24..6a29163a140ac816c57b94d31820938d6a27a4bc 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 2c00f27100e3713e74a3f060e4ccd3b72643ab50..f5f01add5b4b4293fbacad5495346ab672c89da7 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 6d50861c914618ae7f298f06bae02ca51df866f3..81f75df03001395cc9e92d5db8c32d57e7f95eb1 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 757b787d273755ffa8449bcaad8422d218e20117..fe8ced21dd09a40f0220c3352cbcfa0cb8fd9d66 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 f4015392eb17b534947b468b1cc7cc50475a0d56..3de5c58fd8a42f4454c6ddcf4edc27a67e4efc28 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;
        };