From 2fec3cabba3f55579a21daebf46ce83c1e7022e0 Mon Sep 17 00:00:00 2001 From: Jaemin Ryu Date: Mon, 19 Sep 2016 18:58:09 +0900 Subject: [PATCH] Fix password policy comparator Change-Id: I2bd2811c045b276f3f564e325e2968cd0a0bd2c3 Signed-off-by: Jaemin Ryu --- server/password.cpp | 16 ++++++++-------- server/policy-manager.cpp | 16 ++++++---------- server/server.cpp | 1 + 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/server/password.cpp b/server/password.cpp index b2cd1e5..03233fb 100644 --- a/server/password.cpp +++ b/server/password.cpp @@ -265,13 +265,13 @@ int PasswordPolicy::setMaximumFailedForWipe(int value) return -1; } - return setPasswordPolicy(context, "password-maximum-failure-count", (value == 0) ? UINT_MAX : value); + return setPasswordPolicy(context, "password-maximum-failure-count", (value == 0) ? INT_MAX : value); } int PasswordPolicy::getMaximumFailedForWipe() { unsigned int result = getPasswordPolicy(context, "password-maximum-failure-count"); - return (result == UINT_MAX) ? 0 : result; + return (result == INT_MAX) ? 0 : result; } int PasswordPolicy::setExpires(int value) @@ -285,13 +285,13 @@ int PasswordPolicy::setExpires(int value) return -1; } - return setPasswordPolicy(context, "password-expired", (value == 0) ? UINT_MAX : value); + return setPasswordPolicy(context, "password-expired", (value == 0) ? INT_MAX : value); } int PasswordPolicy::getExpires() { unsigned int result = getPasswordPolicy(context, "password-expired"); - return (result == UINT_MAX) ? 0 : result; + return (result == INT_MAX) ? 0 : result; } int PasswordPolicy::setHistory(int value) @@ -443,14 +443,14 @@ int PasswordPolicy::setMaximumCharacterOccurrences(int value) return -1; } - return setPasswordPolicy(context, "password-maximum-character-occurrences", (value == 0) ? UINT_MAX : value); + return setPasswordPolicy(context, "password-maximum-character-occurrences", (value == 0) ? INT_MAX : value); } int PasswordPolicy::getMaximumCharacterOccurrences() { unsigned int result = getPasswordPolicy(context, "password-maximum-character-occurrences"); - return (result == UINT_MAX) ? 0 : result; + return (result == INT_MAX) ? 0 : result; } int PasswordPolicy::setMaximumNumericSequenceLength(int value) @@ -464,13 +464,13 @@ int PasswordPolicy::setMaximumNumericSequenceLength(int value) return -1; } - return setPasswordPolicy(context, "password-numeric-sequences-length", (value == 0) ? UINT_MAX : value); + return setPasswordPolicy(context, "password-numeric-sequences-length", (value == 0) ? INT_MAX : value); } int PasswordPolicy::getMaximumNumericSequenceLength() { unsigned int result = getPasswordPolicy(context, "password-numeric-sequences-length"); - return (result == UINT_MAX) ? 0 : result; + return (result == INT_MAX) ? 0 : result; } int PasswordPolicy::setForbiddenStrings(const std::vector &forbiddenStrings) diff --git a/server/policy-manager.cpp b/server/policy-manager.cpp index 69d5bc9..031546d 100644 --- a/server/policy-manager.cpp +++ b/server/policy-manager.cpp @@ -36,11 +36,6 @@ namespace { struct ManagedPolicy { - ManagedPolicy(int sc, int val) : - scope(sc), value(val) - { - } - ManagedPolicy(int sc, int val, PolicyManager::PolicyComparator pred) : scope(sc), value(val), compare(pred) { @@ -75,11 +70,11 @@ std::unordered_map managedPolicyMap = { DEFINE_GLOBAL_POLICY("password-history", 0, MaximizeIntegerComparator), DEFINE_GLOBAL_POLICY("password-minimum-length", 0, MaximizeIntegerComparator), DEFINE_GLOBAL_POLICY("password-minimum-complexity", 0, MaximizeIntegerComparator), - DEFINE_GLOBAL_POLICY("password-inactivity-timeout", 1000, MaximizeIntegerComparator), - DEFINE_GLOBAL_POLICY("password-expired",0, MinimizeIntegerComparator), - DEFINE_GLOBAL_POLICY("password-maximum-failure-count", 0, MinimizeIntegerComparator), - DEFINE_GLOBAL_POLICY("password-numeric-sequences-length", 0, MinimizeIntegerComparator), - DEFINE_GLOBAL_POLICY("password-maximum-character-occurrences", 0, MinimizeIntegerComparator), + DEFINE_GLOBAL_POLICY("password-inactivity-timeout", INT_MAX, MinimizeIntegerComparator), + DEFINE_GLOBAL_POLICY("password-expired", INT_MAX, MinimizeIntegerComparator), + DEFINE_GLOBAL_POLICY("password-maximum-failure-count", INT_MAX, MinimizeIntegerComparator), + DEFINE_GLOBAL_POLICY("password-numeric-sequences-length", INT_MAX, MinimizeIntegerComparator), + DEFINE_GLOBAL_POLICY("password-maximum-character-occurrences", INT_MAX, MinimizeIntegerComparator), DEFINE_GLOBAL_POLICY("password-quality", 0, MaximizeIntegerComparator), DEFINE_GLOBAL_POLICY("bluetooth", 1, StateComparator), DEFINE_GLOBAL_POLICY("bluetooth-tethering", 1, StateComparator), @@ -376,6 +371,7 @@ bool PolicyManager::setPolicy(const std::string& pkgid, uid_t uid, const std::string& name, int value) { if (managedPolicyMap.count(name) == 0) { + ERROR("Unknown policy: " + name); return false; } diff --git a/server/server.cpp b/server/server.cpp index 9b90a55..7b7ac48 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -123,6 +123,7 @@ int Server::setPolicy(const std::string& name, int value, const std::string& eve } } } catch (runtime::Exception& e) { + ERROR(e.what()); return -1; } -- 2.7.4