Apply checking for loading of dpm 41/169941/8 accepted/tizen_4.0_unified tizen_4.0 accepted/tizen/4.0/unified/20181207.174722 accepted/tizen/5.0/unified/20181102.020643 accepted/tizen/unified/20180503.080755 submit/tizen/20180503.024702 submit/tizen_4.0/20181206.072604 submit/tizen_5.0/20181101.000004
authoryeji01.kim <yeji01.kim@samsung.com>
Mon, 12 Feb 2018 08:05:26 +0000 (17:05 +0900)
committeryeji01.kim <yeji01.kim@samsung.com>
Fri, 2 Mar 2018 04:49:17 +0000 (13:49 +0900)
Change-Id: I7ccb9e3cf5b18e1af0f2f39e71dfc2fc3853383c
Signed-off-by: yeji01.kim <yeji01.kim@samsung.com>
plugin/password.cpp

index 23763c1..5cadfb4 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/inotify.h>
 
 #include <unordered_map>
 
@@ -24,6 +25,9 @@
 #include <dpm/pil/app-bundle.h>
 #include <dpm/pil/launchpad.h>
 
+#include <klay/error.h>
+#include <klay/exception.h>
+
 #include "password-manager.h"
 
 typedef enum {
@@ -58,6 +62,9 @@ namespace {
 const int simplePasswordLength = 4;
 const int infinite = 32767;
 
+const std::string BootCompleted = "/tmp/.dpm-bootCompleted";
+int bootCompleted = -1;
+
 std::unordered_map<uid_t, int> passwordStatus;
 
 inline int inverse(int value)
@@ -95,6 +102,9 @@ public:
 
        bool apply(const DataType& value, uid_t domain)
        {
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        int auth = DPM_PASSWORD_QUALITY_UNSPECIFIED;
 
@@ -126,6 +136,10 @@ public:
        bool apply(const DataType& value, uid_t domain)
        {
                int v = value;
+
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        v = v == infinite ? 0 : v;
                        PasswordManager passwordManager(domain);
@@ -149,6 +163,10 @@ public:
        bool apply(const DataType& value, uid_t domain)
        {
                int v = value;
+
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        v = v == infinite ? 0 : v;
                        PasswordManager passwordManager(domain);
@@ -171,6 +189,9 @@ public:
 
        bool apply(const DataType& value, uid_t domain)
        {
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        PasswordManager passwordManager(domain);
                        passwordManager.setHistory(inverse(value));
@@ -192,6 +213,9 @@ public:
 
        bool apply(const DataType& value, uid_t domain)
        {
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        PasswordManager passwordManager(domain);
                        passwordManager.setExpires(value);
@@ -213,6 +237,9 @@ public:
 
        bool apply(const DataType& value, uid_t domain)
        {
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        PasswordManager passwordManager(domain);
                        passwordManager.setMaximumFailedForWipe(value);
@@ -234,6 +261,9 @@ public:
 
        bool apply(const DataType& value, uid_t domain)
        {
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        PasswordManager passwordManager(domain);
                        passwordManager.setMinimumComplexCharacters(inverse(value));
@@ -255,6 +285,9 @@ public:
 
        bool apply(const DataType& value, uid_t domain)
        {
+               if (bootCompleted < 0)
+                       return true;
+
                try {
                        PasswordManager passwordManager(domain);
                        passwordManager.setMinimumLength(inverse(value));
@@ -294,6 +327,32 @@ public:
 
 class Password : public AbstractPolicyProvider {
 public:
+       Password(PolicyControlContext& context) {
+               inotifyFd = ::inotify_init1(IN_NONBLOCK);
+               if (inotifyFd < 0) {
+                       throw runtime::Exception(runtime::GetSystemErrorMessage());
+               }
+
+               int wd = ::inotify_add_watch(inotifyFd, BootCompleted.c_str(), IN_MODIFY);
+               if (wd == -1) {
+                       throw runtime::Exception(runtime::GetSystemErrorMessage());
+               }
+
+               auto setBootCompleted = [&context, this](int fd, runtime::Mainloop::Event event) {
+                       bootCompleted = 1;
+                       context.mainloop.removeEventSource(inotifyFd);
+                       ::close(inotifyFd);
+                       inotifyFd = -1;
+               };
+
+               context.mainloop.addEventSource(inotifyFd, EPOLLIN | EPOLLHUP | EPOLLRDHUP, setBootCompleted);
+       }
+
+       ~Password() {
+               if (inotifyFd != -1)
+                       ::close(inotifyFd);
+       }
+
        int setQuality(int quality);
        int getQuality();
        int setMinimumLength(int value);
@@ -325,6 +384,8 @@ public:
        int getRecovery();
 
 private:
+       int inotifyFd;
+
        PasswordQuality      quality;
        PasswordHistory      history;
        PasswordLength       length;
@@ -583,7 +644,7 @@ extern "C" {
 
 AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context)
 {
-       Password *policy = new Password();
+       Password *policy = new Password(context);
 
        context.expose(policy, PRIVILEGE, (int)(Password::setQuality)(int));
        context.expose(policy, PRIVILEGE, (int)(Password::setMinimumLength)(int));