Move auth_password_policy to AuthPasswd namespace 93/61593/2
authorKyungwook Tak <k.tak@samsung.com>
Wed, 9 Mar 2016 05:19:37 +0000 (14:19 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Wed, 9 Mar 2016 05:23:59 +0000 (14:23 +0900)
Change-Id: I82725177a1c9f5e9a25e9a9c0f472075091adfc1
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
CMakeLists.txt
src/client/client-password-admin.cpp
src/common/include/policy.h
src/common/policy.cpp
src/include/auth-passwd-policy-types.h
src/server/service/include/policy-manager.h
src/server/service/password.cpp
src/server/service/policy-manager.cpp

index 6cfb316d5549860c5fef48ff1e8dbcbaa21991ff..e0d0f4def79a7c12118d285a35333d46d2bb6882 100644 (file)
@@ -43,7 +43,7 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-g -std=c++0x -O2 --coverage")
 ADD_DEFINITIONS("-fPIC")
 
 # Set compiler warning flags
-#ADD_DEFINITIONS("-Werror")                      # Make all warnings into errors.
+ADD_DEFINITIONS("-Werror")                      # Make all warnings into errors.
 ADD_DEFINITIONS("-Wall")                        # Generate all warnings
 ADD_DEFINITIONS("-Wextra")                      # Generate even more extra warnings
 
index 9b43edf3d9d172e78b9de0024ded29df9597a6fb..3a0b2035acea048544b7f29be3c4b85d6a6c0f6a 100644 (file)
@@ -85,14 +85,11 @@ int auth_passwd_new_policy(policy_h **pp_policy)
     if (!pp_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    try {
-        *pp_policy = new policy_h;
-
-    } catch (std::bad_alloc& ex) {
+    auto policy = new (std::nothrow) AuthPasswd::Policy;
+    if (policy == nullptr)
         return AUTH_PASSWD_API_ERROR_OUT_OF_MEMORY;
-    }
 
-    (*pp_policy)->policyFlag = 0;
+    *pp_policy = reinterpret_cast<policy_h *>(policy);
 
     return AUTH_PASSWD_API_SUCCESS;
 }
@@ -103,8 +100,10 @@ int auth_passwd_set_user(policy_h *p_policy, uid_t uid)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_USER);
-    p_policy->uid = uid;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_USER);
+    policy->uid = uid;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -114,8 +113,11 @@ int auth_passwd_set_max_attempts(policy_h *p_policy, unsigned int max_attempts)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_MAX_ATTEMPTS);
-    p_policy->maxAttempts = max_attempts;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    /* TODO: set flag & value in atomic operation */
+    policy->setFlag(POLICY_MAX_ATTEMPTS);
+    policy->maxAttempts = max_attempts;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -125,8 +127,10 @@ int auth_passwd_set_validity(policy_h *p_policy, unsigned int valid_days)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_VALID_PERIOD);
-    p_policy->validPeriod = valid_days;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_VALID_PERIOD);
+    policy->validPeriod = valid_days;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -136,8 +140,10 @@ int auth_passwd_set_history_size(policy_h *p_policy, unsigned int history_size)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_HISTORY_SIZE);
-    p_policy->historySize = history_size;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_HISTORY_SIZE);
+    policy->historySize = history_size;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -147,8 +153,10 @@ int auth_passwd_set_min_length(policy_h *p_policy, unsigned int min_length)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_MIN_LENGTH);
-    p_policy->minLength = min_length;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_MIN_LENGTH);
+    policy->minLength = min_length;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -158,8 +166,10 @@ int auth_passwd_set_min_complex_char_num(policy_h *p_policy, unsigned int val)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_MIN_COMPLEX_CHAR_NUMBER);
-    p_policy->minComplexCharNumber = val;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_MIN_COMPLEX_CHAR_NUMBER);
+    policy->minComplexCharNumber = val;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -169,8 +179,10 @@ int auth_passwd_set_max_char_occurrences(policy_h *p_policy, unsigned int val)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_MAX_CHAR_OCCURRENCES);
-    p_policy->maxCharOccurrences = val;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_MAX_CHAR_OCCURRENCES);
+    policy->maxCharOccurrences = val;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -180,8 +192,10 @@ int auth_passwd_set_max_num_seq_len(policy_h *p_policy, unsigned int val)
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_MAX_NUMERIC_SEQ_LENGTH);
-    p_policy->maxNumSeqLength = val;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_MAX_NUMERIC_SEQ_LENGTH);
+    policy->maxNumSeqLength = val;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -191,8 +205,10 @@ int auth_passwd_set_quality(policy_h *p_policy, password_quality_type quality_ty
     if (!p_policy)
         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_QUALITY_TYPE);
-    p_policy->qualityType = quality_type;
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_QUALITY_TYPE);
+    policy->qualityType = quality_type;
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -205,8 +221,10 @@ int auth_passwd_set_pattern(policy_h *p_policy, const char *pattern)
     if (!pattern)
         pattern = AuthPasswd::NO_PATTERN;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_PATTERN);
-    p_policy->pattern = std::string(pattern);
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_PATTERN);
+    policy->pattern = std::string(pattern);
+
     return AUTH_PASSWD_API_SUCCESS;
 
 }
@@ -220,8 +238,10 @@ int auth_passwd_set_forbidden_passwd(policy_h *p_policy, const char *forbidden_p
     if (!forbidden_passwd)
         forbidden_passwd = AuthPasswd::NO_FORBIDDEND_PASSWORD;
 
-    p_policy->policyFlag = p_policy->policyFlag | (1 << POLICY_FORBIDDEN_PASSWDS);
-    p_policy->forbiddenPasswds.push_back(forbidden_passwd);
+    auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+    policy->setFlag(POLICY_FORBIDDEN_PASSWDS);
+    policy->forbiddenPasswds.push_back(forbidden_passwd);
+
     return AUTH_PASSWD_API_SUCCESS;
 }
 
@@ -236,24 +256,26 @@ int auth_passwd_set_policy(policy_h *p_policy)
             return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
         }
 
-        if (!(p_policy->policyFlag & (1 << POLICY_USER)))
+        auto policy = reinterpret_cast<AuthPasswd::Policy *>(p_policy);
+
+        if (!policy->isFlagOn(POLICY_USER))
             return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
 
         MessageBuffer send, recv;
 
         Serialization::Serialize(send, static_cast<int>(PasswordHdrs::HDR_SET_PASSWD_POLICY));
-        Serialization::Serialize(send, p_policy->policyFlag);
-        Serialization::Serialize(send, p_policy->uid);
-        Serialization::Serialize(send, p_policy->maxAttempts);
-        Serialization::Serialize(send, p_policy->validPeriod);
-        Serialization::Serialize(send, p_policy->historySize);
-        Serialization::Serialize(send, p_policy->minLength);
-        Serialization::Serialize(send, p_policy->minComplexCharNumber);
-        Serialization::Serialize(send, p_policy->maxCharOccurrences);
-        Serialization::Serialize(send, p_policy->maxNumSeqLength);
-        Serialization::Serialize(send, p_policy->qualityType);
-        Serialization::Serialize(send, p_policy->pattern);
-        Serialization::Serialize(send, p_policy->forbiddenPasswds);
+        Serialization::Serialize(send, policy->flag);
+        Serialization::Serialize(send, policy->uid);
+        Serialization::Serialize(send, policy->maxAttempts);
+        Serialization::Serialize(send, policy->validPeriod);
+        Serialization::Serialize(send, policy->historySize);
+        Serialization::Serialize(send, policy->minLength);
+        Serialization::Serialize(send, policy->minComplexCharNumber);
+        Serialization::Serialize(send, policy->maxCharOccurrences);
+        Serialization::Serialize(send, policy->maxNumSeqLength);
+        Serialization::Serialize(send, policy->qualityType);
+        Serialization::Serialize(send, policy->pattern);
+        Serialization::Serialize(send, policy->forbiddenPasswds);
 
         int retCode = sendToServer(SERVICE_SOCKET_PASSWD_POLICY, send.Pop(), recv);
         if (AUTH_PASSWD_API_SUCCESS != retCode) {
@@ -270,7 +292,7 @@ int auth_passwd_set_policy(policy_h *p_policy)
 AUTH_PASSWD_API
 void auth_passwd_free_policy(policy_h *p_policy)
 {
-    delete p_policy;
+    delete (reinterpret_cast<AuthPasswd::Policy *>(p_policy));
 }
 
 AUTH_PASSWD_API
index bae5c82e233a0f9ed8592dfd4a8e6a6a275de237..4016b4f7c0c09b2f74613784c17850db44d1a70f 100644 (file)
 #include <string>
 #include <auth-passwd-policy-types.h>
 
-struct auth_password_policy {
+namespace AuthPasswd {
+
+extern const size_t MAX_PASSWORD_LEN;
+extern const unsigned int MAX_PASSWORD_HISTORY;
+extern const unsigned int MAX_PASSWORD_ATTEMPTS;
+extern const unsigned int PASSWORD_INFINITE_EXPIRATION_DAYS;
+extern const unsigned int PASSWORD_INFINITE_ATTEMPT_COUNT;
+extern const unsigned int PASSWORD_API_NO_EXPIRATION;
+
+extern const char* NO_PASSWORD;
+extern const char* NO_PATTERN;
+extern const char* NO_FORBIDDEND_PASSWORD;
+
+extern const std::string REGEX_QUALITY_UNSPECIFIED;
+extern const std::string REGEX_QUALITY_SOMETHING;
+extern const std::string REGEX_QUALITY_NUMERIC;
+extern const std::string REGEX_QUALITY_ALPHABETIC;
+extern const std::string REGEX_QUALITY_ALPHANUMERIC;
+
+struct Policy {
+    Policy();
+    ~Policy();
+
+    inline void setFlag(password_policy_type field)
+    {
+        flag |= (1 << field);
+    }
 
-    int policyFlag;
+    inline bool isFlagOn(password_policy_type field)
+    {
+        return (flag & (1 << field)) ? true : false;
+    }
+
+    // XOR-ed value of password_policy_type enum
+    int flag;
 
     uid_t uid;
 
@@ -61,25 +93,6 @@ struct auth_password_policy {
     std::vector<std::string> forbiddenPasswds;
 };
 
-namespace AuthPasswd {
-
-extern const size_t MAX_PASSWORD_LEN;
-extern const unsigned int MAX_PASSWORD_HISTORY;
-extern const unsigned int MAX_PASSWORD_ATTEMPTS;
-extern const unsigned int PASSWORD_INFINITE_EXPIRATION_DAYS;
-extern const unsigned int PASSWORD_INFINITE_ATTEMPT_COUNT;
-extern const unsigned int PASSWORD_API_NO_EXPIRATION;
-
-extern const char* NO_PASSWORD;
-extern const char* NO_PATTERN;
-extern const char* NO_FORBIDDEND_PASSWORD;
-
-extern const std::string REGEX_QUALITY_UNSPECIFIED;
-extern const std::string REGEX_QUALITY_SOMETHING;
-extern const std::string REGEX_QUALITY_NUMERIC;
-extern const std::string REGEX_QUALITY_ALPHABETIC;
-extern const std::string REGEX_QUALITY_ALPHANUMERIC;
-
 }
 
 #endif // _AUTH_PASSWD_POLICY_H_
index 6f5190c64d090a8643959e6c8856aaaf51dbb48e..6fd033896a7083e5284fb65adb46c32f9618278f 100644 (file)
@@ -42,4 +42,12 @@ const std::string REGEX_QUALITY_NUMERIC = "^[0-9]+$";
 const std::string REGEX_QUALITY_ALPHABETIC = "^[A-Za-z]+$";
 const std::string REGEX_QUALITY_ALPHANUMERIC = "^[A-Za-z0-9]+$";
 
+Policy::Policy() : flag(0)
+{
+}
+
+Policy::~Policy()
+{
+}
+
 } // namespace AuthPasswd
index 6e8a22df791143bbcbee6b5054edbb506115c625..45a7c9dacac22d36dca042ce1a411c8d41600f62 100644 (file)
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-typedef struct auth_password_policy policy_h;
+typedef struct _policy_h policy_h;
 
 typedef enum {
     POLICY_USER,
index c2e0a7525b9fb9b72fed7918c6565dc6a47cbadb..43a46cbfaca2003eb0bb3929edf3fbe375073200 100644 (file)
@@ -46,7 +46,7 @@ namespace AuthPasswd
                         unsigned int user);
 
         // policy setting functions
-        int setPolicy(auth_password_policy policy);
+        int setPolicy(Policy policy);
 
         // policy disabling functions
         int disablePolicy(unsigned int user);
index 493d266b898ee27af489b5f3727a807bb2cb386e..e58f833e6587d49cfe6317b46d146b7c8ac89373 100644 (file)
@@ -218,9 +218,9 @@ int PasswordService::processPolicyFunctions(PasswordHdrs hdr, MessageBuffer& buf
 
     switch (hdr) {
         case PasswordHdrs::HDR_SET_PASSWD_POLICY: {
-            auth_password_policy policy;
+            Policy policy;
 
-            Deserialization::Deserialize(buffer, policy.policyFlag);
+            Deserialization::Deserialize(buffer, policy.flag);
             Deserialization::Deserialize(buffer, policy.uid);
             Deserialization::Deserialize(buffer, policy.maxAttempts);
             Deserialization::Deserialize(buffer, policy.validPeriod);
@@ -236,11 +236,11 @@ int PasswordService::processPolicyFunctions(PasswordHdrs hdr, MessageBuffer& buf
             result = m_policyManager.setPolicy(policy);
 
             if (result == AUTH_PASSWD_API_SUCCESS) {
-                if (policy.policyFlag & (1 << POLICY_MAX_ATTEMPTS))
+                if (policy.isFlagOn(POLICY_MAX_ATTEMPTS))
                     m_pwdManager.setPasswordMaxAttempts(policy.uid, policy.maxAttempts);
-                if (policy.policyFlag & (1 << POLICY_VALID_PERIOD))
+                if (policy.isFlagOn(POLICY_VALID_PERIOD))
                     m_pwdManager.setPasswordValidity(policy.uid, policy.validPeriod);
-                if (policy.policyFlag & (1 << POLICY_HISTORY_SIZE))
+                if (policy.isFlagOn(POLICY_HISTORY_SIZE))
                     m_pwdManager.setPasswordHistory(policy.uid, policy.historySize);
             }
             break;
index f3a7ca0e5632760f6672a1e7c34b1601de5b42b9..78f177103bc86a36897cc42c5a8c0684b6d3ae09 100644 (file)
@@ -112,7 +112,7 @@ namespace AuthPasswd
         return AUTH_PASSWD_API_SUCCESS;
     }
 
-    int PolicyManager::setPolicy(auth_password_policy policy)
+    int PolicyManager::setPolicy(Policy policy)
     {
         LogSecureDebug("Inside setPolicy function.");
 
@@ -121,136 +121,139 @@ namespace AuthPasswd
 
         // check if policies are correct
         for (int i = POLICY_TYPE_FIRST ; i < POLICY_TYPE_LAST+1 ; i++) {
-            if (policy.policyFlag & (1 << i)) {
-                switch (i) {
-                    case POLICY_MAX_ATTEMPTS:
-                        break;
-
-                    case POLICY_VALID_PERIOD: {
-                        time_t curTime = time(NULL);
-                        if (policy.validPeriod > ((UINT_MAX - curTime) / 86400)) {
-                           LogError("Incorrect input param.");
-                           return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
+            if (!policy.isFlagOn(static_cast<password_policy_type>(i)))
+                continue;
+
+            switch (i) {
+                case POLICY_MAX_ATTEMPTS:
+                    break;
+
+                case POLICY_VALID_PERIOD: {
+                    time_t curTime = time(NULL);
+                    if (policy.validPeriod > ((UINT_MAX - curTime) / 86400)) {
+                       LogError("Incorrect input param.");
+                       return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
                     }
+                    break;
+                }
 
-                    case POLICY_HISTORY_SIZE:
-                        if (policy.historySize > MAX_PASSWORD_HISTORY) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_MIN_LENGTH:
-                        if (policy.minLength > MAX_PASSWORD_LEN) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_MIN_COMPLEX_CHAR_NUMBER:
-                        if (policy.minComplexCharNumber > MAX_PASSWORD_LEN) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_MAX_CHAR_OCCURRENCES:
-                        if (policy.maxCharOccurrences > MAX_PASSWORD_LEN) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_MAX_NUMERIC_SEQ_LENGTH:
-                        if (policy.maxNumSeqLength > MAX_PASSWORD_LEN) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_QUALITY_TYPE:
-                        if (policy.qualityType > AUTH_PWD_QUALITY_LAST) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_PATTERN:
-                        if (!itPolicy->second.isValidPattern(policy.pattern)) {
-                            LogError("Incorrect input param.");
-                            return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                        }
-                        break;
-
-                    case POLICY_FORBIDDEN_PASSWDS:
-                        break;
-
-                    default:
-                        LogError("Not supported policy type.");
+                case POLICY_HISTORY_SIZE:
+                    if (policy.historySize > MAX_PASSWORD_HISTORY) {
+                        LogError("Incorrect input param.");
                         return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                }
+                    }
+                    break;
+
+                case POLICY_MIN_LENGTH:
+                    if (policy.minLength > MAX_PASSWORD_LEN) {
+                        LogError("Incorrect input param.");
+                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
+                    }
+                    break;
+
+                case POLICY_MIN_COMPLEX_CHAR_NUMBER:
+                    if (policy.minComplexCharNumber > MAX_PASSWORD_LEN) {
+                        LogError("Incorrect input param.");
+                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
+                    }
+                    break;
+
+                case POLICY_MAX_CHAR_OCCURRENCES:
+                    if (policy.maxCharOccurrences > MAX_PASSWORD_LEN) {
+                        LogError("Incorrect input param.");
+                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
+                    }
+                    break;
+
+                case POLICY_MAX_NUMERIC_SEQ_LENGTH:
+                    if (policy.maxNumSeqLength > MAX_PASSWORD_LEN) {
+                        LogError("Incorrect input param.");
+                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
+                    }
+                    break;
+
+                case POLICY_QUALITY_TYPE:
+                    if (policy.qualityType > AUTH_PWD_QUALITY_LAST) {
+                        LogError("Incorrect input param.");
+                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
+                    }
+                    break;
+
+                case POLICY_PATTERN:
+                    if (!itPolicy->second.isValidPattern(policy.pattern)) {
+                        LogError("Incorrect input param.");
+                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
+                    }
+                    break;
+
+                case POLICY_FORBIDDEN_PASSWDS:
+                    break;
+
+                default:
+                    LogError("Not supported policy type.");
+                    return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
             }
         }
 
         // update policies
         for (int i = POLICY_TYPE_FIRST ; i < POLICY_TYPE_LAST+1 ; i++) {
-            if (policy.policyFlag & (1 << i)) {
-                switch (i) {
-                    case POLICY_MAX_ATTEMPTS:
-                        LogSecureDebug("maxAttempts: " << policy.maxAttempts);
-                        break;
-
-                    case POLICY_VALID_PERIOD:
-                        LogSecureDebug("validPeriod: " << policy.validPeriod);
-                        break;
-
-                    case POLICY_HISTORY_SIZE:
-                        LogSecureDebug("historySize: " << policy.historySize);
-                        break;
-
-                    case POLICY_MIN_LENGTH:
-                        LogSecureDebug("minLength: " << policy.minLength);
-                        itPolicy->second.setMinLength(policy.minLength);
-                        break;
-
-                    case POLICY_MIN_COMPLEX_CHAR_NUMBER:
-                        LogSecureDebug("minComplexCharNumber: " << policy.minComplexCharNumber);
-                        itPolicy->second.setMinComplexCharNumber(policy.minComplexCharNumber);
-                        break;
-
-                    case POLICY_MAX_CHAR_OCCURRENCES:
-                        LogSecureDebug("maxCharOccurrences: " << policy.maxCharOccurrences);
-                        itPolicy->second.setMaxCharOccurrences(policy.maxCharOccurrences);
-                        break;
-
-                    case POLICY_MAX_NUMERIC_SEQ_LENGTH:
-                        LogSecureDebug("maxNumSeqLength: " << policy.maxNumSeqLength);
-                        itPolicy->second.setMaxNumSeqLength(policy.maxNumSeqLength);
-                        break;
-
-                    case POLICY_QUALITY_TYPE:
-                        LogSecureDebug("qualityType: " << policy.qualityType);
-                        itPolicy->second.setQualityType(policy.qualityType);
-                        break;
-
-                    case POLICY_PATTERN:
-                        LogSecureDebug("pattern: " << policy.pattern);
-                        itPolicy->second.setPattern(policy.pattern);
-                        break;
-
-                    case POLICY_FORBIDDEN_PASSWDS:
-                        LogSecureDebug("forbiddenPasswds number: " << policy.forbiddenPasswds.size());
-                        itPolicy->second.setForbiddenPasswds(policy.forbiddenPasswds);
-                        break;
-
-                    default:
-                        LogError("Not supported policy type.");
-                        return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
-                }
+            if (!policy.isFlagOn(static_cast<password_policy_type>(i)))
+                continue;
+
+            switch (i) {
+                case POLICY_MAX_ATTEMPTS:
+                    LogSecureDebug("maxAttempts: " << policy.maxAttempts);
+                    break;
+
+                case POLICY_VALID_PERIOD:
+                    LogSecureDebug("validPeriod: " << policy.validPeriod);
+                    break;
+
+                case POLICY_HISTORY_SIZE:
+                    LogSecureDebug("historySize: " << policy.historySize);
+                    break;
+
+                case POLICY_MIN_LENGTH:
+                    LogSecureDebug("minLength: " << policy.minLength);
+                    itPolicy->second.setMinLength(policy.minLength);
+                    break;
+
+                case POLICY_MIN_COMPLEX_CHAR_NUMBER:
+                    LogSecureDebug("minComplexCharNumber: " << policy.minComplexCharNumber);
+                    itPolicy->second.setMinComplexCharNumber(policy.minComplexCharNumber);
+                    break;
+
+                case POLICY_MAX_CHAR_OCCURRENCES:
+                    LogSecureDebug("maxCharOccurrences: " << policy.maxCharOccurrences);
+                    itPolicy->second.setMaxCharOccurrences(policy.maxCharOccurrences);
+                    break;
+
+                case POLICY_MAX_NUMERIC_SEQ_LENGTH:
+                    LogSecureDebug("maxNumSeqLength: " << policy.maxNumSeqLength);
+                    itPolicy->second.setMaxNumSeqLength(policy.maxNumSeqLength);
+                    break;
+
+                case POLICY_QUALITY_TYPE:
+                    LogSecureDebug("qualityType: " << policy.qualityType);
+                    itPolicy->second.setQualityType(policy.qualityType);
+                    break;
+
+                case POLICY_PATTERN:
+                    LogSecureDebug("pattern: " << policy.pattern);
+                    itPolicy->second.setPattern(policy.pattern);
+                    break;
+
+                case POLICY_FORBIDDEN_PASSWDS:
+                    LogSecureDebug("forbiddenPasswds number: " << policy.forbiddenPasswds.size());
+                    itPolicy->second.setForbiddenPasswds(policy.forbiddenPasswds);
+                    break;
+
+                default:
+                    LogError("Not supported policy type.");
+                    return AUTH_PASSWD_API_ERROR_INPUT_PARAM;
             }
         }
+
         itPolicy->second.enable();
         itPolicy->second.writeMemoryToFile();