std::vector<std::string> getZoneList(int state);
+ int resetZonePassword(const std::string& name, const std::string& newPassword);
+
private:
PolicyControlContext& context;
};
#include <notification.h>
#include <notification_internal.h>
#include <tzplatform_config.h>
+#include <auth-passwd-admin.h>
#include "zone/zone.hxx"
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");
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
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)
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);
}
typedef struct {
char *mode;
char *zone_name;
+ char *zone_password;
zone_manager_h zone_manager;
int zone_event_cb_id;
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);
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();
}
}
+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
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);
+}
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);
+
+/**
* @}
*/