CAPI: add ERROR returns if one of the params is null 09/63509/5
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 24 Mar 2016 10:55:53 +0000 (19:55 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 25 Mar 2016 05:54:33 +0000 (14:54 +0900)
Change-Id: I21acb3d8528d0df2d6cf179da6b9a4e3cd27c04a
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
libs/dpm/capi-assert.h [new file with mode: 0644]
libs/dpm/password.cpp
libs/dpm/security.cpp
libs/dpm/zone.cpp

diff --git a/libs/dpm/capi-assert.h b/libs/dpm/capi-assert.h
new file mode 100644 (file)
index 0000000..fd73f67
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __CAPI_DPM_ASSERT_H__
+#define __CAPI_DPM_ASSERT_H__
+
+#define RET_ON_FAILURE(cond, ret) \
+        { \
+            if (!(cond)) \
+                return (ret); \
+        }
+
+#endif //! __CAPI_DPM_ASSERT_H__
index efa0b08..ac681fa 100644 (file)
  *  limitations under the License
  */
 
-#include <string.h>
+#include <cstring>
 
 #include "password.h"
-
 #include "password.hxx"
 
+#include "capi-assert.h"
 #include "policy-client.h"
 
 using namespace DevicePolicyManager;
@@ -28,6 +28,8 @@ int dpm_set_password_quality(dpm_client_h handle, const char *username, dpm_pass
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -43,6 +45,9 @@ int dpm_set_password_minimum_length(dpm_client_h handle, const char *username, c
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -58,6 +63,9 @@ int dpm_set_min_password_complex_chars(dpm_client_h handle, const char *username
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -73,6 +81,9 @@ int dpm_set_maximum_failed_password_for_wipe(dpm_client_h handle, const char *us
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -88,6 +99,9 @@ int dpm_set_password_expires(dpm_client_h handle, const char *username, const in
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -103,6 +117,9 @@ int dpm_set_password_history(dpm_client_h handle, const char *username, const in
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -118,6 +135,10 @@ int dpm_set_password_pattern(dpm_client_h handle, const char *username, const ch
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -133,6 +154,10 @@ int dpm_reset_password(dpm_client_h handle, const char *username, const char *pa
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(passwd, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -148,6 +173,9 @@ int dpm_enforce_password_change(dpm_client_h handle, const char *username)
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -163,6 +191,9 @@ int dpm_set_max_inactivity_time_device_lock(dpm_client_h handle, const char *use
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -178,6 +209,10 @@ int dpm_get_max_inactivity_time_device_lock(dpm_client_h handle, const char *use
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(p_value, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -195,6 +230,9 @@ int dpm_set_password_status(dpm_client_h handle, const char *username, const int
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -210,6 +248,9 @@ int dpm_delete_password_pattern(dpm_client_h handle, const char *username)
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -223,6 +264,9 @@ int dpm_delete_password_pattern(dpm_client_h handle, const char *username)
 
 char *dpm_get_password_pattern(dpm_client_h handle, const char *username)
 {
+    RET_ON_FAILURE(handle, NULL);
+    RET_ON_FAILURE(username, NULL);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -237,6 +281,9 @@ int dpm_set_maximum_character_occurrences(dpm_client_h handle, const char *usern
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -252,6 +299,10 @@ int dpm_get_maximum_character_occurrences(dpm_client_h handle, const char *usern
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(p_value, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
     *p_value = password.getMaximumCharacterOccurrences(username);
@@ -268,6 +319,9 @@ int dpm_set_maximum_numeric_sequence_length(dpm_client_h handle, const char *use
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
 
@@ -283,6 +337,10 @@ int dpm_get_maximum_numeric_sequence_length(dpm_client_h handle, const char *use
 {
     int ret = 0;
 
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(username, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
+
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Password password = client.createPolicyInterface<Password>();
     *value = password.getMaximumNumericSequenceLength(username);
index 303f3d3..d219100 100644 (file)
  *  limitations under the License
  */
 
-#include <cassert>
-
+#include "security.h"
 #include "security.hxx"
 
-#include "security.h"
+#include "capi-assert.h"
 #include "policy-client.h"
 
 using namespace DevicePolicyManager;
 
 int dpm_lockout_device(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -34,7 +33,7 @@ int dpm_lockout_device(dpm_client_h handle)
 
 int dpm_lockout_screen(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -43,7 +42,7 @@ int dpm_lockout_screen(dpm_client_h handle)
 
 int dpm_wipe_data(dpm_client_h handle, const dpm_wipe_type_e type)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -52,7 +51,7 @@ int dpm_wipe_data(dpm_client_h handle, const dpm_wipe_type_e type)
 
 int dpm_reboot(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -61,7 +60,7 @@ int dpm_reboot(dpm_client_h handle)
 
 int dpm_poweroff_device(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -70,7 +69,7 @@ int dpm_poweroff_device(dpm_client_h handle)
 
 int dpm_set_internal_storage_encryption(dpm_client_h handle, const int encrypt)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -79,7 +78,7 @@ int dpm_set_internal_storage_encryption(dpm_client_h handle, const int encrypt)
 
 int dpm_is_internal_storage_encrypted(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -88,7 +87,7 @@ int dpm_is_internal_storage_encrypted(dpm_client_h handle)
 
 int dpm_set_external_storage_encryption(dpm_client_h handle, const int encrypt)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
@@ -97,7 +96,7 @@ int dpm_set_external_storage_encryption(dpm_client_h handle, const int encrypt)
 
 int dpm_is_external_storage_encrypted(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Security security = client.createPolicyInterface<Security>();
index 011d299..9acef36 100644 (file)
  *  limitations under the License
  */
 
-#include <cassert>
-
-#include "dpm/zone.h"
-
+#include "zone.h"
 #include "zone.hxx"
+
 #include "array.h"
+#include "capi-assert.h"
 #include "policy-client.h"
 
 using namespace DevicePolicyManager;
 
 int dpm_create_zone(dpm_client_h handle, const char* name, const char* pkgid)
 {
-    assert(handle);
-    assert(name);
-    assert(pkgid);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Zone zone = client.createPolicyInterface<Zone>();
@@ -37,8 +36,8 @@ int dpm_create_zone(dpm_client_h handle, const char* name, const char* pkgid)
 
 int dpm_remove_zone(dpm_client_h handle, const char* name)
 {
-    assert(handle);
-    assert(name);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Zone zone = client.createPolicyInterface<Zone>();
@@ -49,7 +48,7 @@ typedef runtime::Array<std::string> dpm_zone_iterator;
 
 dpm_zone_iterator_h dpm_get_zone_iterator(dpm_client_h handle)
 {
-    assert(handle);
+    RET_ON_FAILURE(handle, NULL);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Zone zone = client.createPolicyInterface<Zone>();
@@ -59,26 +58,26 @@ dpm_zone_iterator_h dpm_get_zone_iterator(dpm_client_h handle)
 
 const char* dpm_zone_iterator_next(dpm_zone_iterator_h iter)
 {
-    assert(iter);
+    RET_ON_FAILURE(iter, NULL);
 
     std::string* result = reinterpret_cast<dpm_zone_iterator*>(iter)->next();
 
-    if (result == NULL) {
-        return NULL;
-    }
+    RET_ON_FAILURE(result, NULL);
 
     return result->c_str();
 }
 
 void dpm_free_zone_iterator(dpm_zone_iterator_h iter)
 {
+    RET_ON_FAILURE(iter, void());
+
     delete reinterpret_cast<dpm_zone_iterator*>(iter);
 }
 
 int dpm_get_zone_state(dpm_client_h handle, const char* name)
 {
-    assert(handle);
-    assert(name);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER);
 
     DevicePolicyClient &client = GetDevicePolicyClient(handle);
     Zone zone = client.createPolicyInterface<Zone>();
@@ -90,8 +89,8 @@ int dpm_get_zone_state(dpm_client_h handle, const char* name)
 
 int dpm_subscribe_zone_signal(dpm_client_h handle, dpm_zone_signal_cb callback, void* user_data)
 {
-    assert(handle);
-    assert(callback);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(callback, DPM_ERROR_INVALID_PARAMETER);
 
     /* TODO : should implement */
 
@@ -100,8 +99,8 @@ int dpm_subscribe_zone_signal(dpm_client_h handle, dpm_zone_signal_cb callback,
 
 int dpm_unsubscribe_zone_signal(dpm_client_h handle, dpm_zone_signal_cb callback)
 {
-    assert(handle);
-    assert(callback);
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(callback, DPM_ERROR_INVALID_PARAMETER);
 
     /* TODO : should implement */