From: Mu-Woong Lee Date: Wed, 5 Jul 2017 07:43:07 +0000 (+0900) Subject: Add IClient::getName() for getting the package id (or the executable path) of a client X-Git-Tag: submit/tizen/20170710.122951^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3545891bf59e3f6b0fb97f281008662952bd7f14;p=platform%2Fcore%2Fcontext%2Fcontext-service.git Add IClient::getName() for getting the package id (or the executable path) of a client Change-Id: I2c8143e8c69767123efc08c8d4e1cdcb278227c4 Signed-off-by: Mu-Woong Lee --- diff --git a/packaging/context-service.spec b/packaging/context-service.spec index f0ab6e3..aa23c13 100644 --- a/packaging/context-service.spec +++ b/packaging/context-service.spec @@ -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) diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 4b474cc..b0c8ba2 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -8,6 +8,7 @@ SET(DEPS gio-2.0 dlog capi-base-common + aul alarm-service cynara-creds-gdbus cynara-client diff --git a/src/server/Credential.cpp b/src/server/Credential.cpp index 445e569..6a29163 100644 --- a/src/server/Credential.cpp +++ b/src/server/Credential.cpp @@ -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; diff --git a/src/server/Credential.h b/src/server/Credential.h index 2c00f27..f5f01ad 100644 --- a/src/server/Credential.h +++ b/src/server/Credential.h @@ -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; diff --git a/src/server/MethodCall.cpp b/src/server/MethodCall.cpp index 6d50861..81f75df 100644 --- a/src/server/MethodCall.cpp +++ b/src/server/MethodCall.cpp @@ -90,7 +90,7 @@ uid_t MethodCall::getUid() const std::string& MethodCall::getCallerId() { - return getCaller().getId(); + return getCaller().getName(); } bool MethodCall::isSystem() diff --git a/src/server/ServiceClient.cpp b/src/server/ServiceClient.cpp index 757b787..fe8ced2 100644 --- a/src/server/ServiceClient.cpp +++ b/src/server/ServiceClient.cpp @@ -14,10 +14,14 @@ * limitations under the License. */ +#include +#include #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(); diff --git a/src/server/ServiceClient.h b/src/server/ServiceClient.h index f401539..3de5c58 100644 --- a/src/server/ServiceClient.h +++ b/src/server/ServiceClient.h @@ -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; };