2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
23 #include <tizen_type.h>
25 #include <dpm/pil/policy-client.h>
29 #define RET_ON_FAILURE(cond, ret) \
39 Array(std::vector<T> &&list) : list(std::move(list)), it(this->list.begin())
43 Array(const std::vector<T> &list) : list(list), it(this->list.begin())
48 if (it != list.end()) {
55 return it == list.end();
60 typename std::vector<T>::iterator it;
63 EXPORT_API int dpm_password_set_quality(void* handle, int quality)
65 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
66 RET_ON_FAILURE(quality >= 0, DPM_ERROR_INVALID_PARAMETER);
68 DevicePolicyClient &client = GetDevicePolicyClient(handle);
71 Status<int> ret { -1 };
72 ret = client.methodCall<int>("Password::setQuality", quality);
79 EXPORT_API int dpm_password_get_quality(void* handle, int *quality)
81 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
82 RET_ON_FAILURE(quality, DPM_ERROR_INVALID_PARAMETER);
84 DevicePolicyClient &client = GetDevicePolicyClient(handle);
87 Status<int> ret { 0 };
88 ret = client.methodCall<int>("Password::getQuality");
98 return DPM_ERROR_NONE;
101 EXPORT_API int dpm_password_set_minimum_length(void* handle, int value)
103 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
104 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
106 DevicePolicyClient &client = GetDevicePolicyClient(handle);
109 Status<int> ret { 0 };
110 ret = client.methodCall<int>("Password::setMinimumLength", value);
117 EXPORT_API int dpm_password_get_minimum_length(void* handle, int *value)
119 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
120 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
122 DevicePolicyClient &client = GetDevicePolicyClient(handle);
125 Status<int> ret { 0 };
126 ret = client.methodCall<int>("Password::getMinimumLength");
137 return DPM_ERROR_NONE;
140 EXPORT_API int dpm_password_set_min_complex_chars(void* handle, int value)
142 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
143 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
145 DevicePolicyClient &client = GetDevicePolicyClient(handle);
148 Status<int> ret { -1 };
149 ret = client.methodCall<int>("Password::setMinComplexChars", value);
156 EXPORT_API int dpm_password_get_min_complex_chars(void* handle, int *value)
158 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
159 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
161 DevicePolicyClient &client = GetDevicePolicyClient(handle);
164 Status<int> ret { 0 };
165 ret = client.methodCall<int>("Password::getMinComplexChars");
175 return DPM_ERROR_NONE;
178 EXPORT_API int dpm_password_set_maximum_failed_attempts_for_wipe(void* handle, int value)
180 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
181 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
183 DevicePolicyClient &client = GetDevicePolicyClient(handle);
186 Status<int> ret { -1 };
187 ret = client.methodCall<int>("Password::setMaximumFailedForWipe", value);
194 EXPORT_API int dpm_password_get_maximum_failed_attempts_for_wipe(void* handle, int *value)
196 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
197 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
199 DevicePolicyClient &client = GetDevicePolicyClient(handle);
202 Status<int> ret { 0 };
203 ret = client.methodCall<int>("Password::getMaximumFailedForWipe");
213 return DPM_ERROR_NONE;
216 EXPORT_API int dpm_password_set_expires(void* handle, int value)
218 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
219 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
221 DevicePolicyClient &client = GetDevicePolicyClient(handle);
224 Status<int> ret { -1 };
225 ret = client.methodCall<int>("Password::setExpires", value);
232 EXPORT_API int dpm_password_get_expires(void* handle, int *value)
234 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
235 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
237 DevicePolicyClient &client = GetDevicePolicyClient(handle);
240 Status<int> ret { 0 };
241 ret = client.methodCall<int>("Password::getExpires");
251 return DPM_ERROR_NONE;
254 EXPORT_API int dpm_password_set_history(void* handle, int value)
256 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
257 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
259 DevicePolicyClient &client = GetDevicePolicyClient(handle);
262 Status<int> ret { -1 };
263 ret = client.methodCall<int>("Password::setHistory", value);
270 EXPORT_API int dpm_password_get_history(void* handle, int *value)
272 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
273 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
275 DevicePolicyClient &client = GetDevicePolicyClient(handle);
278 Status<int> ret { 0 };
279 ret = client.methodCall<int>("Password::getHistory");
289 return DPM_ERROR_NONE;
292 EXPORT_API int dpm_password_set_pattern(void* handle, const char *pattern)
294 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
295 RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER);
297 DevicePolicyClient &client = GetDevicePolicyClient(handle);
300 Status<int> ret { -1 };
301 ret = client.methodCall<int>("Password::setPattern", pattern);
308 EXPORT_API int dpm_password_reset(void* handle, const char *passwd)
310 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
311 RET_ON_FAILURE(passwd, DPM_ERROR_INVALID_PARAMETER);
313 DevicePolicyClient &client = GetDevicePolicyClient(handle);
316 Status<int> ret { -1 };
317 ret = client.methodCall<int>("Password::reset", passwd);
324 EXPORT_API int dpm_password_enforce_change(void* handle)
326 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
328 DevicePolicyClient &client = GetDevicePolicyClient(handle);
331 Status<int> ret { -1 };
332 ret = client.methodCall<int>("Password::enforceChange");
339 EXPORT_API int dpm_password_set_max_inactivity_time_device_lock(void* handle, int value)
341 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
342 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
344 DevicePolicyClient &client = GetDevicePolicyClient(handle);
347 Status<int> ret { -1 };
348 ret = client.methodCall<int>("Password::setMaxInactivityTimeDeviceLock", value);
355 EXPORT_API int dpm_password_get_max_inactivity_time_device_lock(void* handle, int *value)
357 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
358 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
360 DevicePolicyClient &client = GetDevicePolicyClient(handle);
363 Status<int> ret { 0 };
364 ret = client.methodCall<int>("Password::getMaxInactivityTimeDeviceLock");;
374 return DPM_ERROR_NONE;
377 EXPORT_API int dpm_password_set_status(void* handle, dpm_password_status_e status)
379 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
380 RET_ON_FAILURE(status >= DPM_PASSWORD_STATUS_NORMAL &&
381 status <= DPM_PASSWORD_STATUS_PATTERN_CHANGED,
382 DPM_ERROR_INVALID_PARAMETER);
384 DevicePolicyClient &client = GetDevicePolicyClient(handle);
387 Status<int> ret { -1 };
388 ret = client.methodCall<int>("Password::setStatus", (int)status);
395 EXPORT_API int dpm_password_get_ret(void* handle, dpm_password_status_e *status)
397 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
398 RET_ON_FAILURE(status, DPM_ERROR_INVALID_PARAMETER);
400 DevicePolicyClient &client = GetDevicePolicyClient(handle);
403 Status<int> ret { 0 };
404 ret = client.methodCall<int>("Password::getStatus");
409 *status = (dpm_password_status_e)ret.get();
414 return DPM_ERROR_NONE;
417 EXPORT_API int dpm_password_delete_pattern(void* handle)
419 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
421 DevicePolicyClient &client = GetDevicePolicyClient(handle);
424 Status<int> ret { -1 };
425 ret = client.methodCall<int>("Password::deletePattern");
432 EXPORT_API int dpm_password_get_pattern(void* handle, char **pattern)
434 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
435 RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER);
437 DevicePolicyClient &client = GetDevicePolicyClient(handle);
440 Status<std::string> ret { std::string() };
441 ret = client.methodCall<std::string>("Password::getPattern");
442 *pattern = ::strdup(ret.get().c_str());
447 return DPM_ERROR_NONE;
450 EXPORT_API int dpm_password_set_maximum_character_occurrences(void* handle, int value)
452 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
453 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
455 DevicePolicyClient &client = GetDevicePolicyClient(handle);
458 Status<int> ret { -1 };
459 ret = client.methodCall<int>("Password::setMaximumCharacterOccurrences", value);
466 EXPORT_API int dpm_password_get_maximum_character_occurrences(void* handle, int *value)
468 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
469 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
471 DevicePolicyClient &client = GetDevicePolicyClient(handle);
474 Status<int> ret { 0 };
475 ret = client.methodCall<int>("Password::getMaximumCharacterOccurrences");
485 return DPM_ERROR_NONE;
488 EXPORT_API int dpm_password_set_maximum_numeric_sequence_length(void* handle, int value)
490 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
491 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
493 DevicePolicyClient &client = GetDevicePolicyClient(handle);
496 Status<int> ret { -1 };
497 ret = client.methodCall<int>("Password::setMaximumNumericSequenceLength", value);
504 EXPORT_API int dpm_password_get_maximum_numeric_sequence_length(void* handle, int *value)
506 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
507 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
509 DevicePolicyClient &client = GetDevicePolicyClient(handle);
512 Status<int> ret { 0 };
513 ret = client.methodCall<int>("Password::getMaximumNumericSequenceLength");
523 return DPM_ERROR_NONE;
526 typedef Array<std::string> dpm_password_iterator;
528 EXPORT_API dpm_password_iterator_h dpm_password_create_iterator(void* handle)
530 RET_ON_FAILURE(handle, NULL);
532 DevicePolicyClient &client = GetDevicePolicyClient(handle);
534 Status<std::vector<std::string>> status { std::vector<std::string>() };
535 status = client.methodCall<std::vector<std::string>>("Password::getForbiddenStrings");
537 dpm_password_iterator *iter = new dpm_password_iterator(status.get());
538 return reinterpret_cast<dpm_password_iterator_h>(iter);
541 EXPORT_API int dpm_password_iterator_next(dpm_password_iterator_h iter, const char **result)
543 RET_ON_FAILURE(iter, DPM_ERROR_INVALID_PARAMETER);
544 RET_ON_FAILURE(result, DPM_ERROR_INVALID_PARAMETER);
546 dpm_password_iterator *it = reinterpret_cast<dpm_password_iterator *>(iter);
551 *result = it->next()->c_str();
553 return DPM_ERROR_NONE;
556 EXPORT_API int dpm_password_destroy_iterator(dpm_password_iterator_h iter)
558 RET_ON_FAILURE(iter, DPM_ERROR_INVALID_PARAMETER);
560 delete reinterpret_cast<dpm_password_iterator *>(iter);
562 return DPM_ERROR_NONE;
565 EXPORT_API int dpm_password_set_forbidden_strings(void* handle, const char *strings[], int length)
567 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
569 DevicePolicyClient &client = GetDevicePolicyClient(handle);
570 std::vector<std::string> forbiddenStrings;
572 for (int i = 0; i < length; i++)
573 forbiddenStrings.push_back(strings[i]);
576 Status<int> ret { -1 };
577 ret = client.methodCall<int>("Password::setForbiddenStrings", forbiddenStrings);
584 EXPORT_API int dpm_password_set_recovery(void* handle, int enable)
586 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
588 DevicePolicyClient &client = GetDevicePolicyClient(handle);
591 Status<int> ret { -1 };
592 ret = client.methodCall<int>("Password::setRecovery", enable);
599 EXPORT_API int dpm_password_get_recovery(void* handle, int *enable)
601 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
602 RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
604 DevicePolicyClient &client = GetDevicePolicyClient(handle);
607 Status<int> ret { false };
608 ret = client.methodCall<int>("Password::getRecovery");
618 return DPM_ERROR_NONE;