From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 12:09:00 +0000 (+0200) Subject: Use client error codes in admin libraries X-Git-Tag: submit/R4/20141115.054144~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=426deba8e8db72050eeef6044b170015b10260e4;p=platform%2Fcore%2Fsecurity%2Fcynara.git Use client error codes in admin libraries We need to have one unified set of error codes. Client error codes have been adjusted to serve admin errors too. Then client error codes were used in admin libraries keeping following mapping: CYNARA_ADMIN_API_SUCCESS -> CYNARA_API_SUCCESS CYNARA_ADMIN_API_OUT_OF_MEMORY -> CYNARA_API_OUT_OF_MEMORY CYNARA_ADMIN_API_INVALID_PARAM -> CYNARA_API_INVALID_PARAM CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE -> CYNARA_API_SERVICE_NOT_AVAILABLE CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR -> CYNARA_API_UNKNOWN_ERROR CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED -> CYNARA_API_OPERATION_NOT_ALLOWED CYNARA_ADMIN_API_BUCKET_NOT_FOUND -> CYNARA_API_BUCKET_NOT_FOUND Remove not needed anymore old admin error codes file: src/include/cynara-admin-error.h Change-Id: Ice8990a2b354bd489c67c2a004344a5c60fc15ee --- diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 6abd205..17746c8 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -106,6 +106,7 @@ admin client library for setting, listing and removing policies %package -n libcynara-admin-devel Summary: Cynara - admin client library (devel) Requires: libcynara-admin = %{version}-%{release} +Requires: libcynara-commons-devel = %{version}-%{release} %description -n libcynara-admin-devel admin client library (devel) for setting, listing and removing policies @@ -440,7 +441,6 @@ fi %files -n libcynara-admin-devel %{_includedir}/cynara/cynara-admin.h -%{_includedir}/cynara/cynara-admin-error.h %{_includedir}/cynara/cynara-admin-types.h %{_libdir}/libcynara-admin.so %{_libdir}/pkgconfig/cynara-admin.pc diff --git a/src/admin/api/admin-api.cpp b/src/admin/api/admin-api.cpp index fe426fb..929b075 100644 --- a/src/admin/api/admin-api.cpp +++ b/src/admin/api/admin-api.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include @@ -55,35 +55,35 @@ struct cynara_admin { CYNARA_API int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) { if (!pp_cynara_admin) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; try { *pp_cynara_admin = new cynara_admin(new Cynara::Logic); } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } init_log(); LOGD("Cynara admin initialized"); - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } CYNARA_API int cynara_admin_finish(struct cynara_admin *p_cynara_admin) { delete p_cynara_admin; - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } CYNARA_API int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, const struct cynara_admin_policy *const *policies) { if (!p_cynara_admin || !p_cynara_admin->impl) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!policies) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; std::map> insertOrUpdate; std::map> remove; @@ -106,7 +106,7 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, for (auto i = policies; *i; i++) { const cynara_admin_policy *policy = *i; if(!policy->bucket || !policy->client || !policy->user || !policy->privilege) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; switch (policy->result) { case CYNARA_ADMIN_DELETE: @@ -122,7 +122,7 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, break; case CYNARA_ADMIN_BUCKET: if (!policy->result_extra) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; insertOrUpdate[policy->bucket].push_back(Cynara::Policy(key(policy), Cynara::PolicyResult( Cynara::PredefinedPolicyType::BUCKET, @@ -130,11 +130,11 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, break; case CYNARA_ADMIN_NONE: default: - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; } } } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } return p_cynara_admin->impl->setPolicies(insertOrUpdate, remove); @@ -144,15 +144,15 @@ CYNARA_API int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *bucket, int operation, const char *extra) { if (!p_cynara_admin || !p_cynara_admin->impl) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!bucket) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; std::string extraStr; try { extraStr = extra ? extra : ""; } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } switch (operation) { case CYNARA_ADMIN_DELETE: @@ -168,10 +168,10 @@ int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *buc return p_cynara_admin->impl->insertOrUpdateBucket(bucket, Cynara::PolicyResult(Cynara::PredefinedPolicyType::NONE)); } - return CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED; + return CYNARA_API_OPERATION_NOT_ALLOWED; case CYNARA_ADMIN_BUCKET: default: - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; } } @@ -181,13 +181,13 @@ int cynara_admin_check(struct cynara_admin *p_cynara_admin, const char *client, const char *user, const char *privilege, int *result, char **result_extra) { if (!p_cynara_admin || !p_cynara_admin->impl) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!start_bucket) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!client || !user || !privilege) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; if (!result || !result_extra) - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; Cynara::PolicyResult policyResult; @@ -195,22 +195,22 @@ int cynara_admin_check(struct cynara_admin *p_cynara_admin, int ret = p_cynara_admin->impl->adminCheck(start_bucket, recursive != 0, Cynara::PolicyKey(client, user, privilege), policyResult); - if (ret != CYNARA_ADMIN_API_SUCCESS) + if (ret != CYNARA_API_SUCCESS) return ret; } catch (const std::bad_alloc &ex) { - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } catch (const std::length_error &ex) { - return CYNARA_ADMIN_API_INVALID_PARAM; + return CYNARA_API_INVALID_PARAM; } char *str = nullptr; if (!policyResult.metadata().empty()) { str = strdup(policyResult.metadata().c_str()); if (!str) - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } *result = static_cast(policyResult.policyType()); *result_extra = str; - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 3b004d9..d36651e 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { try { if (!ensureConnection()) { LOGE("Cannot connect to cynara. Service not available."); - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); @@ -77,37 +77,37 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) { ResponsePtr response; while (!(response = m_socketClient->askCynaraServer(request))) { if (!m_socketClient->connect()) - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } codeResponse = std::dynamic_pointer_cast(response); if (!codeResponse) { LOGC("Critical error. Casting Response to CodeResponse failed."); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } LOGD("codeResponse: code [%" PRIu16 "]", codeResponse->m_code); switch (codeResponse->m_code) { case CodeResponse::Code::OK: LOGI("Policies set successfully."); - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; case CodeResponse::Code::NOT_ALLOWED: LOGE("Cynara service answered: Operation not allowed."); - return CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED; + return CYNARA_API_OPERATION_NOT_ALLOWED; case CodeResponse::Code::NO_BUCKET: LOGE("Trying to use unexisting bucket."); - return CYNARA_ADMIN_API_BUCKET_NOT_FOUND; + return CYNARA_API_BUCKET_NOT_FOUND; default: LOGE("Unexpected response code from server: [%d]", static_cast(codeResponse->m_code)); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } } catch (const std::bad_alloc &ex) { LOGE("Cynara admin client out of memory."); - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } catch (const std::exception &ex) { LOGE("Unexpected client error: <%s>", ex.what()); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } } @@ -130,7 +130,7 @@ int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const P try { if (!ensureConnection()) { LOGE("Cannot connect to cynara. Service not available."); - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber(); @@ -143,13 +143,13 @@ int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const P ResponsePtr response; while (!(response = m_socketClient->askCynaraServer(request))) { if (!m_socketClient->connect()) - return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE; + return CYNARA_API_SERVICE_NOT_AVAILABLE; } checkResponse = std::dynamic_pointer_cast(response); if (!checkResponse) { LOGC("Casting Response to CheckResponse failed."); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } LOGD("checkResponse: policyType [%" PRIu16 "], metadata <%s>", @@ -157,16 +157,16 @@ int Logic::adminCheck(const PolicyBucketId &startBucket, bool recursive, const P checkResponse->m_resultRef.metadata().c_str()); result = checkResponse->m_resultRef; - return CYNARA_ADMIN_API_SUCCESS; + return CYNARA_API_SUCCESS; } catch (const UnexpectedErrorException &ex) { LOGE(ex.what()); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } catch (const std::bad_alloc &ex) { LOGE("Cynara admin client out of memory."); - return CYNARA_ADMIN_API_OUT_OF_MEMORY; + return CYNARA_API_OUT_OF_MEMORY; } catch (const std::exception &ex) { LOGE("Unexpected client error: <%s>", ex.what()); - return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR; + return CYNARA_API_UNKNOWN_ERROR; } } diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index cb9d00c..a6c1945 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -18,7 +18,6 @@ INSTALL(FILES ${CYNARA_PATH}/include/cynara-admin.h - ${CYNARA_PATH}/include/cynara-admin-error.h ${CYNARA_PATH}/include/cynara-admin-types.h ${CYNARA_PATH}/include/cynara-client.h ${CYNARA_PATH}/include/cynara-client-async.h diff --git a/src/include/cynara-admin-error.h b/src/include/cynara-admin-error.h deleted file mode 100644 index 4b9cad9..0000000 --- a/src/include/cynara-admin-error.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2014 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 - */ -/** - * @file src/include/cynara-admin-error.h - * @author Lukasz Wojciechowski - * @author Zofia Abramowska - * @version 1.0 - * @brief This file contains error codes of administration APIs of Cynara. - */ - -#ifndef CYNARA_ADMIN_ERROR_H -#define CYNARA_ADMIN_ERROR_H - -/** - * \name Return Codes - * exported by the foundation API. - * result codes begin with the start error code and extend into negative direction. - * @{ -*/ - -/*! \brief indicating the result of the one specific API is successful or access is allowed */ -#define CYNARA_ADMIN_API_SUCCESS 0 - -/*! \brief indicating client process is running out of memory */ -#define CYNARA_ADMIN_API_OUT_OF_MEMORY -1 - -/*! \brief indicating the API's parameter is malformed */ -#define CYNARA_ADMIN_API_INVALID_PARAM -2 - -/*! \brief service not available (cannot connect to cynara service) */ -#define CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE -3 - -/*! \brief unexpected error in client library */ -#define CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR -4 - -/*! \brief cynara service does not allow to perform requested operation */ -#define CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED -5 - -/*! \brief cynara service hasn't found requested bucket */ -#define CYNARA_ADMIN_API_BUCKET_NOT_FOUND -6 -/** @}*/ - -#endif // CYNARA_ADMIN_ERROR_H diff --git a/src/include/cynara-admin.h b/src/include/cynara-admin.h index a31b1c5..6f5bc9e 100644 --- a/src/include/cynara-admin.h +++ b/src/include/cynara-admin.h @@ -23,8 +23,8 @@ #ifndef CYNARA_ADMIN_H #define CYNARA_ADMIN_H -#include #include +#include #ifdef __cplusplus extern "C" { @@ -63,7 +63,7 @@ struct cynara_admin; * * \param[out] pp_cynara_admin address of pointer for created cynara_admin structure. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Initialize cynara-admin library. */ @@ -92,7 +92,7 @@ int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin); * * \param[in] p_cynara_admin cynara_admin structure created in cynara_admin_initialize. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Release cynara-admin library. */ @@ -144,7 +144,7 @@ int cynara_admin_finish(struct cynara_admin *p_cynara_admin); * \param[in] p_cynara_admin cynara admin structure. * \param[in] policies NULL terminated array of pointers to policy structures. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Insert, update or delete policies in cynara database. */ @@ -191,7 +191,7 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, * \param[in] operation type of operation (default policy or CYNARA_ADMIN_DELETE) * \param[in] extra additional data for default policy (will be available with cynara extensions) * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Add, remove or update buckets in cynara database. */ @@ -238,7 +238,7 @@ int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *buc * \param[out] result placeholder for matched policy type. * \param[out] result_extra placeholder for matched policy additional data (see Important Notes!). * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Raw check client and user access for given privilege without using plugins extensions. */ diff --git a/src/include/cynara-client-error.h b/src/include/cynara-client-error.h index 8dd344f..d4d8bcc 100644 --- a/src/include/cynara-client-error.h +++ b/src/include/cynara-client-error.h @@ -58,8 +58,14 @@ /*! \brief indicating that provided method is not supported by library */ #define CYNARA_API_METHOD_NOT_SUPPORTED -6 +/*! \brief cynara service does not allow to perform requested operation */ +#define CYNARA_API_OPERATION_NOT_ALLOWED -7 + +/*! \brief cynara service hasn't found requested bucket */ +#define CYNARA_API_BUCKET_NOT_FOUND -8 + /*! \brief indicating an unknown error */ -#define CYNARA_API_UNKNOWN_ERROR -7 +#define CYNARA_API_UNKNOWN_ERROR -9 /** @}*/ diff --git a/src/include/cynara-offline-admin.h b/src/include/cynara-offline-admin.h index 1b26901..079ebd3 100644 --- a/src/include/cynara-offline-admin.h +++ b/src/include/cynara-offline-admin.h @@ -25,8 +25,8 @@ #ifndef CYNARA_OFFLINE_ADMIN_H #define CYNARA_OFFLINE_ADMIN_H -#include #include +#include #ifdef __cplusplus extern "C" { @@ -66,7 +66,7 @@ struct cynara_offline_admin; * \param[out] pp_cynara_offline_admin address of pointer for created cynara_offline_admin * structure. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Initialize cynara-offline-admin library. */ @@ -96,7 +96,7 @@ int cynara_offline_admin_initialize(struct cynara_offline_admin **pp_cynara_offl * \param[in] p_cynara_offline_admin cynara_offline_admin structure created * in cynara_offline_admin_initialize. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Release cynara-offline-admin library. */ @@ -146,7 +146,7 @@ int cynara_offline_admin_finish(struct cynara_offline_admin *p_cynara_offline_ad * \param[in] p_cynara_offline_admin cynara offline admin structure. * \param[in] policies NULL terminated array of pointers to policy structures. * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Insert, update or delete policies in cynara database. */ @@ -193,7 +193,7 @@ int cynara_offline_admin_set_policies(struct cynara_offline_admin *p_cynara_offl * \param[in] operation type of operation (default policy or CYNARA_ADMIN_DELETE) * \param[in] extra additional data for default policy (will be available with cynara extensions) * - * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise. + * \return CYNARA_API_SUCCESS on success, or negative error code otherwise. * * \brief Add, remove or update buckets in cynara database. */ @@ -240,7 +240,7 @@ int cynara_offline_admin_set_bucket(struct cynara_offline_admin *p_cynara_offlin * \param[out] result placeholder for matched policy type * \param[out] result_extra placeholder for matched policy additional data (see Important Notes!) * - * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise. + * \return CYNARA_API_SUCCESS on success, or error code otherwise. * * \brief Raw check client, user access for given privilege without using plugins extensions. */