Add a constructor accepting uid_t to Database 14/113714/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 8 Feb 2017 11:22:30 +0000 (20:22 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 8 Feb 2017 12:17:48 +0000 (21:17 +0900)
Change-Id: Icf0685048c12b81f4106505200811cd3ec45c1cf
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/Credential.h
include/Database.h
src/server/Credential.cpp
src/server/Database.cpp

index 257a6e8..9475371 100644 (file)
@@ -30,10 +30,14 @@ namespace ctx {
                bool valid() const;
                bool hasPrivilege(const char* privil) const;
 
-               std::string getUser() const;
+               uid_t getUid() const;
+               bool isSystem() const;
+
+               static bool isSystemUid(uid_t uid);
 
        private:
                pid_t __pid;
+               uid_t __uid;
                char* __clientId;       /* Tizen-Default: Smack label */
                char* __session;
                char* __user;           /* Tizen-Default: UID */
index b99dc2e..0e7cf64 100644 (file)
@@ -34,8 +34,10 @@ namespace ctx {
 
        class EXPORT_API Database {
        public:
+               Database(const std::string& dbName, uid_t uid);
                Database(const std::string& dbName, const Credential* credential);
                Database(const std::string& dbName);
+
                ~Database();
 
                bool open();
index 2869912..87f9fad 100644 (file)
@@ -20,7 +20,8 @@
 #include <ScopeMutex.h>
 #include <Credential.h>
 
-#define CACHE_SIZE 100
+#define CACHE_SIZE     100
+#define SYSTEM_UID_LIMIT       5000
 
 using namespace ctx;
 
@@ -85,6 +86,7 @@ namespace {
 
 Credential::Credential(GDBusConnection* conn, const std::string& busName) :
        __pid(0),
+       __uid(0),
        __clientId(NULL),
        __session(NULL),
        __user(NULL),
@@ -104,6 +106,8 @@ Credential::Credential(GDBusConnection* conn, const std::string& busName) :
                _E("Peer credentialing failed");
                __valid = false;
        }
+
+       __uid = static_cast<uid_t>(atoll(__user));
 }
 
 Credential::~Credential()
@@ -129,7 +133,17 @@ bool Credential::hasPrivilege(const char* privil) const
        return privilegeChecker.hasPrivilege(__clientId, __session, __user, privil);
 }
 
-std::string Credential::getUser() const
+uid_t Credential::getUid() const
+{
+       return __uid;
+}
+
+bool Credential::isSystem() const
+{
+       return isSystemUid(__uid);
+}
+
+bool Credential::isSystemUid(uid_t uid)
 {
-       return std::string(__user);
+       return (uid < SYSTEM_UID_LIMIT);
 }
index 222cd13..cdcb8ea 100644 (file)
@@ -21,7 +21,7 @@
 #include <Tuple.h>
 #include <Database.h>
 
-#define SYSTEM_UID_LIMIT       5000
+#define ROOT_UID       ((uid_t)0)
 
 using namespace ctx;
 
@@ -63,13 +63,11 @@ static std::string __getUserPath(const std::string& dbName, uid_t uid)
        return path;
 }
 
-Database::Database(const std::string& dbName, const Credential* credential) :
+Database::Database(const std::string& dbName, uid_t uid) :
        __dbHandle(NULL),
        __transactionOn(false)
 {
-       uid_t uid = static_cast<uid_t>(atoll(credential->getUser().c_str()));
-
-       if (uid < SYSTEM_UID_LIMIT) {
+       if (Credential::isSystemUid(uid)) {
                __dbPath = __getSystemPath(dbName);
        } else {
                __dbPath = __getUserPath(dbName, uid);
@@ -78,13 +76,14 @@ Database::Database(const std::string& dbName, const Credential* credential) :
        _I("Path: %s", __dbPath.c_str());
 }
 
-Database::Database(const std::string& dbName) :
-       __dbHandle(NULL),
-       __transactionOn(false)
+Database::Database(const std::string& dbName, const Credential* credential) :
+       Database(dbName, credential->getUid())
 {
-       __dbPath = __getSystemPath(dbName);
+}
 
-       _I("Path: %s", __dbPath.c_str());
+Database::Database(const std::string& dbName) :
+       Database(dbName, ROOT_UID)
+{
 }
 
 Database::~Database()