Add implementation of password checking in the zone 21/77621/2 accepted/tizen/ivi/20160701.033800 accepted/tizen/mobile/20160701.033913 accepted/tizen/tv/20160701.033719 accepted/tizen/wearable/20160701.033818 submit/tizen/20160630.103245
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 30 Jun 2016 09:30:10 +0000 (18:30 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 30 Jun 2016 10:22:00 +0000 (19:22 +0900)
Change-Id: I68c06a29ad0b712bfa7794ecbf2b766a01aa088b
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
policy/zone/zone.hxx
server/zone/zone.cpp
zone/apps/keyguard/src/main.c
zone/apps/keyguard/src/ui.c
zone/apps/setup-wizard/include/zone-setup.h
zone/apps/setup-wizard/src/main.c
zone/apps/setup-wizard/src/security.c
zone/libs/zone.cpp
zone/libs/zone/zone.cpp
zone/libs/zone/zone.h

index 7b314b1..bcbe02c 100644 (file)
@@ -41,6 +41,8 @@ public:
 
     std::vector<std::string> getZoneList(int state);
 
+    int resetZonePassword(const std::string& name, const std::string& newPassword);
+
 private:
     PolicyControlContext& context;
 };
index e161d1a..4c50481 100644 (file)
@@ -21,6 +21,7 @@
 #include <notification.h>
 #include <notification_internal.h>
 #include <tzplatform_config.h>
+#include <auth-passwd-admin.h>
 
 #include "zone/zone.hxx"
 
@@ -543,6 +544,7 @@ ZoneManager::ZoneManager(PolicyControlContext& ctx)
     context.registerParametricMethod(this, (int)(ZoneManager::unlockZone)(std::string));
     context.registerParametricMethod(this, (int)(ZoneManager::getZoneState)(std::string));
     context.registerParametricMethod(this, (std::vector<std::string>)(ZoneManager::getZoneList)(int));
+    context.registerParametricMethod(this, (int)(ZoneManager::resetZonePassword)(std::string, std::string));
 
     context.createNotification("ZoneManager::created");
     context.createNotification("ZoneManager::removed");
@@ -730,6 +732,22 @@ std::vector<std::string> ZoneManager::getZoneList(int state)
     return list;
 }
 
+int ZoneManager::resetZonePassword(const std::string& name, const std::string& newPassword)
+{
+    try {
+        runtime::User user(name);
+        int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, user.getUid(), newPassword.c_str());
+        if (ret != AUTH_PASSWD_API_SUCCESS) {
+            throw runtime::Exception("Failed to reset password for " + name);
+        }
+    } catch (runtime::Exception& e) {
+        ERROR(e.what());
+        return -1;
+    }
+
+    return 0;
+}
+
 ZoneManager zoneManager(Server::instance());
 
 } // namespace DevicePolicyManager
index 0fcc24f..48f4a5b 100644 (file)
@@ -29,17 +29,35 @@ void _launch_req_app()
 
 bool _check_password(const char* password)
 {
-       return true;
+       unsigned int attempt, max_attempt, expire_sec;
+       int ret;
+
+       ret = auth_passwd_check_passwd(AUTH_PWD_NORMAL, password, &attempt, &max_attempt, &expire_sec);
+
+       return ret == AUTH_PASSWD_API_SUCCESS;
 }
 
 bool _has_password()
 {
-       return true;
+       unsigned int attempt, max_attempt, expire_sec;
+       int ret;
+
+       ret = auth_passwd_check_passwd_state(AUTH_PWD_NORMAL, &attempt, &max_attempt, &expire_sec);
+
+       return ret != AUTH_PASSWD_API_ERROR_NO_PASSWORD;
 }
 
 unsigned int _get_left_attempts()
 {
-       return 10;
+       unsigned int attempt = 0, max_attempt = 0, expire_sec;
+
+        auth_passwd_check_passwd_state(AUTH_PWD_NORMAL, &attempt, &max_attempt, &expire_sec);
+
+       if (max_attempt == 0) {
+               return 0xffffffff;
+       }
+
+       return max_attempt - attempt;
 }
 
 static void __launch_zone_app(const char* zone_name, app_control_h app_control)
index 65ea827..27c812f 100644 (file)
@@ -35,8 +35,13 @@ static void __change_info_text(const char *text)
 static void __entry_change_cb(void *data, Evas_Object *obj, void *event_info)
 {
        char text[32];
+       unsigned int attempts = _get_left_attempts();
 
-       snprintf(text, 32, "%u attempts left", _get_left_attempts());
+       if (attempts == 0xffffffff) {
+               snprintf(text, 32, "No limit to attempt");
+       } else {
+               snprintf(text, 32, "%u attempts left", attempts);
+       }
        __change_info_text(text);
 }
 
index 4dbf954..daf50e0 100644 (file)
@@ -51,6 +51,7 @@
 typedef struct {
        char *mode;
        char *zone_name;
+        char *zone_password;
 
        zone_manager_h zone_manager;
        int zone_event_cb_id;
index 4773a30..efb36a9 100644 (file)
@@ -36,6 +36,8 @@ static void __zone_request_done(const char *from, const char *info, void *user_d
        appdata_s *ad = (appdata_s *) user_data;
 
        if (!strcmp(ad->mode, "create")) {
+               zone_manager_reset_zone_password(ad->zone_manager, ad->zone_name, ad->zone_password);
+
                app_control_create(&app_control);
                app_control_set_app_id(app_control, KEYGUARD_PACKAGE);
                snprintf(uri, sizeof(uri), "zone://setup/%s", ad->zone_name);
index 1d121d4..291ce19 100644 (file)
@@ -163,7 +163,7 @@ static void security_password_setup_cb(void *data, Evas_Object *obj, void *event
                return;
        }
 
-       /* [TBD] send password to authfw :: const char *pwd = elm_object_text_get(info.entry); */
+        ad->zone_password = security_password_setup_data;
 
        if (_send_zone_create_request(ad) != 0) {
                ui_app_exit();
index 2cb762d..cbc1aa8 100644 (file)
@@ -82,4 +82,13 @@ std::vector<std::string> ZoneManager::getZoneList(int state)
     }
 }
 
+int ZoneManager::resetZonePassword(const std::string& name, const std::string& newPassword)
+{
+    try {
+        return context->methodCall<int>("ZoneManager::resetZonePassword", name, newPassword);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
 } // namespace DevicePolicyManager
index d89cedd..2342f5e 100644 (file)
@@ -176,3 +176,18 @@ int zone_manager_foreach_name(zone_manager_h handle, zone_state_e state,
 
     return ZONE_ERROR_NONE;
 }
+
+int zone_manager_reset_zone_password(zone_manager_h handle, const char* name, const char* new_password)
+{
+    RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
+
+    if (new_password == NULL) {
+        new_password = "";
+    }
+
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    ZoneManager zone = client.createPolicyInterface<ZoneManager>();
+
+    return zone.resetZonePassword(name, new_password);
+}
index bde0220..2ae3c33 100644 (file)
@@ -342,6 +342,25 @@ ZONE_API int zone_manager_foreach_name(zone_manager_h handle,
                                        void* user_data);
 
 /**
+ * @brief       Reset password for the zone.
+ * @details     This API can be used to set password for the zone. The password
+ *              of the zone can be used for authenticating user.
+ * @since_tizen 3.0
+ * @param[in]   handle The zone policy handle
+ * @param[in]   name The zone name
+ * @param[out]  new_password new password if NULL, existing password will be removed
+ * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #ZONE_ERROR_NONE Successful
+ * @retval      #ZONE_ERROR_NO_DATA No such zone to get state
+ * @retval      #ZONE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #ZONE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by zone_manager_create().
+ * @see         zone_manager_create()
+ * @see         zone_manager_destroy()
+ */
+ZONE_API int zone_manager_reset_zone_password(zone_manager_h handle, const char* name, const char* new_password);
+
+/**
  * @}
  */