Implement cynara-bootstrap version of libcynara-client 64/20464/9 accepted/tizen/common/20140521.234004 submit/tizen/20140521.102954
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 8 May 2014 14:27:51 +0000 (16:27 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 15 May 2014 10:37:33 +0000 (12:37 +0200)
This is temporary version - it's implementation is based on
security-server and libprivilege-control instead of cynara service.

[Bug/Feature]   N/A
[Cause]         First working version of cynara's client.
[Solution]      Implementation temporary based on security-server.
[Verification]  Should be build along with all other patches
                marked with topic:cynara-bootstrap.
Build needs: http://review.tizen.org/gerrit/#/c/20519/

Change-Id: I8468b6756c9844840f3b3bea37f498b08b7f7188
Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
build/cynara-client/cynara-client.pc.in
packaging/cynara.spec
src/client/CMakeLists.txt
src/client/bootstrap/cynara-client-bootstrap.cpp [new file with mode: 0644]
src/client/bootstrap/cynara-client-bootstrap.h [new file with mode: 0644]
src/client/client-api.cpp
src/client/cynara-client-interface.h [new file with mode: 0644]
src/common/attributes/attributes.h [new file with mode: 0644]
src/common/common.h [new file with mode: 0644]
src/include/cynara-client.h

index d81e8ab..d958ce6 100644 (file)
@@ -6,6 +6,6 @@ includedir=${prefix}/include
 Name: cynara-client
 Description: cynara-client package
 Version: 0.0.1
-Requires:
+Requires: security-server
 Libs: -L${libdir} -lcynara-client
 Cflags: -I${includedir}/cynara
index a3b212a..bbf664a 100644 (file)
@@ -22,6 +22,7 @@ Summary:    Cynara - client library
 Requires:   cynara = %{version}-%{release}
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
+BuildRequires: pkgconfig(security-server)
 
 %description -n libcynara-client
 client library for checking policies
index 0a28d6d..c7e9dbd 100644 (file)
@@ -23,6 +23,17 @@ SET(CYNARA_LIB_CYNARA_PATH ${CYNARA_PATH}/client)
 
 SET(LIB_CYNARA_SOURCES
     ${CYNARA_LIB_CYNARA_PATH}/client-api.cpp
+    ${CYNARA_LIB_CYNARA_PATH}/bootstrap/cynara-client-bootstrap.cpp
+    )
+
+PKG_CHECK_MODULES(CYNARA_CLIENT_DEP
+    REQUIRED
+    security-server
+    )
+
+INCLUDE_DIRECTORIES(
+    ${CYNARA_LIB_CYNARA_PATH}
+    ${CYNARA_CLIENT_DEP_INCLUDE_DIRS}
     )
 
 ADD_LIBRARY(${TARGET_LIB_CYNARA} SHARED ${LIB_CYNARA_SOURCES})
@@ -37,6 +48,7 @@ SET_TARGET_PROPERTIES(
 
 TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA}
     ${CYNARA_DEP_LIBRARIES}
+    ${CYNARA_CLIENT_DEP_LIBRARIES}
     ${TARGET_CYNARA_COMMON}
     )
 
diff --git a/src/client/bootstrap/cynara-client-bootstrap.cpp b/src/client/bootstrap/cynara-client-bootstrap.cpp
new file mode 100644 (file)
index 0000000..f3d2bef
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  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        cynara-client-bootstrap.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains bootstrap version of libcynara-client API implementation.
+ */
+
+#include <security-server.h>
+#include "cynara-client-bootstrap.h"
+
+CynaraClientBootstrap :: CynaraClientBootstrap() {
+}
+
+CynaraClientBootstrap :: ~CynaraClientBootstrap() {
+}
+
+cynara_api_result CynaraClientBootstrap :: check(const std::string& client,
+    const std::string& session UNUSED, const std::string& user UNUSED, const std::string& privilege)
+{
+    int is_enabled = 0;
+
+    int ret = security_server_app_has_privilege(client.c_str(), APP_TYPE_WGT, privilege.c_str(),
+                                                &is_enabled);
+
+    if(ret == PC_OPERATION_SUCCESS && is_enabled)
+        return cynara_api_result::CYNARA_API_SUCCESS;
+    return cynara_api_result::CYNARA_API_ACCESS_DENIED;
+}
diff --git a/src/client/bootstrap/cynara-client-bootstrap.h b/src/client/bootstrap/cynara-client-bootstrap.h
new file mode 100644 (file)
index 0000000..c398346
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  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        cynara-client-bootstrap.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains bootstrap version of libcynara-client API implementation.
+ */
+
+#ifndef CYNARA_CLIENT_BOOTSTRAP_H
+#define CYNARA_CLIENT_BOOTSTRAP_H
+
+#include <string>
+#include <common.h>
+#include <cynara-client.h>
+#include <cynara-client-interface.h>
+
+class CynaraClientBootstrap : public CynaraClientInterface {
+public:
+    CynaraClientBootstrap();
+    virtual ~CynaraClientBootstrap();
+    virtual cynara_api_result check(const std::string& client, const std::string& session,
+        const std::string& user, const std::string& privilege);
+};
+
+#endif /* CYNARA_CLIENT_BOOTSTRAP_H */
index 5b32690..0c477f9 100644 (file)
  * @brief       Implementation of external libcynara-client API
  */
 
-//empty init commit
+#include <new>
+#include <common.h>
+#include <cynara-client.h>
+#include <cynara-client-interface.h>
+#include <bootstrap/cynara-client-bootstrap.h>
 
+struct cynara {
+    CynaraClientInterface* impl;
+
+    cynara(CynaraClientInterface *_impl) : impl(_impl) {
+    }
+    ~cynara() {
+        delete impl;
+    }
+};
+
+CYNARA_API
+int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNUSED)
+{
+    if (!pp_cynara)
+        return cynara_api_result::CYNARA_API_INVALID_PARAM;
+
+    try {
+        *pp_cynara = new cynara(new CynaraClientBootstrap);
+    } catch (std::bad_alloc& ex) {
+        return cynara_api_result::CYNARA_API_OUT_OF_MEMORY;
+    }
+
+    return cynara_api_result::CYNARA_API_SUCCESS;
+}
+
+CYNARA_API
+int cynara_finish(cynara *p_cynara)
+{
+    delete p_cynara;
+
+    return cynara_api_result::CYNARA_API_SUCCESS;
+}
+
+CYNARA_API
+int cynara_check(cynara *p_cynara, const char *client, const char *client_session, const char *user,
+    const char *privilege)
+{
+    if(!p_cynara || !p_cynara->impl)
+        return cynara_api_result::CYNARA_API_INVALID_PARAM;
+    if(!client || !client_session || !user || !privilege)
+        return cynara_api_result::CYNARA_API_INVALID_PARAM;
+
+    return p_cynara->impl->check(client, client_session, user, privilege);
+}
diff --git a/src/client/cynara-client-interface.h b/src/client/cynara-client-interface.h
new file mode 100644 (file)
index 0000000..cebf1bc
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  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        cynara-client-interface.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains interface for libcynara-client API implementation.
+ */
+
+
+#ifndef CYNARA_CLIENT_INTERFACE_H
+#define CYNARA_CLIENT_INTERFACE_H
+
+#include <string>
+#include <cynara-client.h>
+
+class CynaraClientInterface {
+public:
+    virtual ~CynaraClientInterface() {
+    }
+    virtual cynara_api_result check(const std::string& client, const std::string& session,
+        const std::string& user, const std::string& privilege) = 0;
+};
+
+#endif /* CYNARA_CLIENT_INTERFACE_H */
diff --git a/src/common/attributes/attributes.h b/src/common/attributes/attributes.h
new file mode 100644 (file)
index 0000000..9690595
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  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        attributes.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines common used attributes
+ */
+
+#ifndef ATTRIBUTES_ATTRIBUTES_H
+#define ATTRIBUTES_ATTRIBUTES_H
+
+#define CYNARA_API __attribute__((visibility("default")))
+#define UNUSED __attribute__((unused))
+
+#endif /* ATTRIBUTES_ATTRIBUTES_H */
diff --git a/src/common/common.h b/src/common/common.h
new file mode 100644 (file)
index 0000000..15829da
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  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        common.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file binds includes from cynara common library
+ */
+
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include "attributes/attributes.h"
+
+#endif /* COMMON_H */
index 5bcd1fa..d07c72b 100644 (file)
@@ -86,7 +86,7 @@ typedef struct cynara_configuration cynara_configuration;
  *
  * \return CYNARA_API_SUCCESS on success, or error code on error.
  */
-int cynara_initialize (cynara **pp_cynara, const cynara_configuration *p_conf);
+int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf);
 
 /**
  * \par Description: