diff options
author | José Bollo <jose.bollo@iot.bzh> | 2019-10-03 17:58:02 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2019-10-04 16:02:32 +0200 |
commit | 9cffedba0dfcf845c34901051d24a4b967ec824d (patch) | |
tree | fb648b8c7056cd7f46e0c14589f12c5a857df150 | |
parent | b5bd40e1e68b739307e20e19d2164c5b370846df (diff) |
Move to CYNAGORA
Rename everything to match the new name of cynagora
Change-Id: I7e529def486ca5721164b338d2c615996fbc6ca4
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | CMakeLists.txt | 27 | ||||
-rw-r--r-- | README.md | 59 | ||||
-rw-r--r-- | compat/CMakeLists.txt | 3 | ||||
-rw-r--r-- | compat/README-compat.md | 1 | ||||
-rw-r--r-- | compat/src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | compat/src/lib-compat.c | 72 | ||||
-rw-r--r-- | cynagora.initial (renamed from cynara.initial) | 2 | ||||
-rw-r--r-- | pkgconfig/CMakeLists.txt | 4 | ||||
-rw-r--r-- | pkgconfig/cynagora.pc.in | 5 | ||||
-rw-r--r-- | pkgconfig/cynara.pc.in | 5 | ||||
-rw-r--r-- | src/CMakeLists.txt | 88 | ||||
-rw-r--r-- | src/README-src.md (renamed from src/SOURCES.md) | 0 | ||||
-rw-r--r-- | src/agent-at.c | 2 | ||||
-rw-r--r-- | src/cache.c | 10 | ||||
-rw-r--r-- | src/cache.h | 4 | ||||
-rw-r--r-- | src/cyn-protocol.c | 119 | ||||
-rw-r--r-- | src/cyn-protocol.h (renamed from src/rcyn-protocol.h) | 24 | ||||
-rw-r--r-- | src/cyn-server.c (renamed from src/rcyn-server.c) | 80 | ||||
-rw-r--r-- | src/cyn-server.h (renamed from src/rcyn-server.h) | 23 | ||||
-rw-r--r-- | src/cyn.c | 14 | ||||
-rw-r--r-- | src/cyn.h | 10 | ||||
-rw-r--r-- | src/cynagora-protocol.txt (renamed from src/rcyn-protocol.txt) | 24 | ||||
-rw-r--r-- | src/cynagora.c (renamed from src/rcyn-client.c) | 457 | ||||
-rw-r--r-- | src/cynagora.h (renamed from src/rcyn-client.h) | 122 | ||||
-rw-r--r-- | src/export-cynagora-core.map (renamed from src/export-cynara-core.map) | 0 | ||||
-rw-r--r-- | src/export-cynagora.map (renamed from src/export-cynara-client.map) | 2 | ||||
-rw-r--r-- | src/filedb.c | 30 | ||||
-rw-r--r-- | src/main-cynagorad.c (renamed from src/main-cynarad.c) | 44 | ||||
-rw-r--r-- | src/main-cynagoradm.c (renamed from src/main-cynadm.c) | 57 | ||||
-rw-r--r-- | src/rcyn-protocol.c | 119 | ||||
-rw-r--r-- | systemd/CMakeLists.txt | 16 | ||||
-rw-r--r-- | systemd/cynagora-admin.socket.in (renamed from systemd/cynara-admin.socket.in) | 8 | ||||
-rw-r--r-- | systemd/cynagora-agent.socket.in (renamed from systemd/cynara-agent.socket.in) | 8 | ||||
-rw-r--r-- | systemd/cynagora-check.socket.in (renamed from systemd/cynara-check.socket.in) | 8 | ||||
-rw-r--r-- | systemd/cynagora.service | 26 | ||||
-rw-r--r-- | systemd/cynagora.target (renamed from systemd/cynara.target) | 2 | ||||
-rw-r--r-- | systemd/cynara.service | 29 | ||||
l--------- | systemd/sockets.target.wants/cynagora-admin.socket | 1 | ||||
l--------- | systemd/sockets.target.wants/cynagora-agent.socket | 1 | ||||
l--------- | systemd/sockets.target.wants/cynagora-check.socket | 1 | ||||
l--------- | systemd/sockets.target.wants/cynara-admin.socket | 1 | ||||
l--------- | systemd/sockets.target.wants/cynara-agent.socket | 1 | ||||
l--------- | systemd/sockets.target.wants/cynara-check.socket | 1 | ||||
-rwxr-xr-x | tests/stress-cache.sh | 4 |
44 files changed, 741 insertions, 776 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f96a1d6..aeb3a53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,13 +18,12 @@ cmake_minimum_required(VERSION 3.0) -project(cynara C) - -set(PROJECT_NAME "Cynara") -set(PROJECT_PRETTY_NAME "Permission database") -set(PROJECT_DESCRIPTION "Secured permission database for applications") -set(PROJECT_VERSION "1.99.99") -set(PROJECT_URL "https://gerrit.automotivelinux.org/gerrit/gitweb?p=src/cynara.git;a=summary") +project(cynagora + DESCRIPTION "Secured permission database for applications" + HOMEPAGE_URL "https://gerrit.automotivelinux.org/gerrit/gitweb?p=src/cynagora.git;a=summary" + VERSION 2.0 + LANGUAGES C +) include(FindPkgConfig) include(CheckIncludeFiles) @@ -39,21 +38,19 @@ endif() ########################################################################### # possible settings -set(CYNARA_VERSION ${PROJECT_VERSION}) -set(CYNARA_SOVERSION 1.99) - -add_definitions(-DCYNARA_VERSION="${CYNARA_VERSION}") +set(CYNAGORA_VERSION ${PROJECT_VERSION}) +set(CYNAGORA_SOVERSION ${PROJECT_VERSION_MAJOR}) option(WITH_SYSTEMD "should include systemd compatibility" ON) option(WITH_CYNARA_COMPAT "produce artifacts for compatibility with cynara" OFF) -set(DEFAULT_DB_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/cynara" +set(DEFAULT_DB_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/cynagora" CACHE PATH "directory path of the database") -set(DEFAULT_SOCKET_DIR "${CMAKE_INSTALL_FULL_RUNSTATEDIR}/cynara" +set(DEFAULT_SOCKET_DIR "${CMAKE_INSTALL_FULL_RUNSTATEDIR}/cynagora" CACHE PATH "directory path of the sockets") set(DEFAULT_CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/security" CACHE PATH "directory of configuration") -set(DEFAULT_INIT_FILE "${DEFAULT_CONFIG_DIR}/cynara.initial") +set(DEFAULT_INIT_FILE "${DEFAULT_CONFIG_DIR}/cynagora.initial") ########################################################################### @@ -82,7 +79,7 @@ if(WITH_CYNARA_COMPAT) endif() install(FILES - ${CMAKE_CURRENT_SOURCE_DIR}/cynara.initial + ${CMAKE_CURRENT_SOURCE_DIR}/cynagora.initial DESTINATION ${DEFAULT_CONFIG_DIR} ) @@ -1,50 +1,27 @@ <pre> - -++- - yyyyyy/ - .syyyyyyyys. - .s/` yyyyyyyyyyyy `/s. - `yyyo-yyyyyyyyyyyyyy oyyy. - oyyy-syyyyyo++oyyyyys-yyyo - ` syyy oyys/+sddy+/syyo yyys ` - -hh//yyo s/ohddddddho s oyy//hh- - ydddh+/+./hddddddddddh+.+/+hdddh - .` `ddddddh sdddddddddddddds hdddddd. `. - hddy.dddddd/sdddddddddddddddds dddddd.sddd - yddd/sddddd.dddddddddddddddddd.dddddy dddh - +dddy-ddddd yddddddddddddddddy ddddd yddd+ - `yddd+oddddy ddddddhhhhdddddd yddddo/dddh` - .yddd/oddds-+++++oooooo+++++-sdddo/dddy. - --++./s/+dddddddddddddddddd+/s/.++-- - /ddhy++dddddddddddddddddd+/yhdd+ - `+ydd-hddddddddddddddddh-hdy+` - `--` +ossyyyyyysso+ `--` + ____ __ __ _ _ _ ____ ___ ____ _ + / ___| \ \ / / | \ | | / \ / ___| / _ \ | _ \ / \ + | | \ V / | \| | / _ \ | | _ | | | | | |_) | / _ \ + | |___ | | | |\ | / ___ \ | |_| | | |_| | | _ < / ___ \ + \____| |_| |_| \_| /_/ \_\ \____| \___/ |_| \_\ /_/ \_\ - - - -/++++/:`///// `////:-////. -////- ://- :///++//:` `///. - -oso:--:ss .+ss: /ss:``:ssss. `:ss:` :ssss. `/ss/-:oss. /ssso` - `sso` -- +ss.-ss- .ssoss- .ss. .ss-oso :ss- :ss- -ss-ss+ - -ss+ /ssss. .ss-/ss/-ss. `os/ -ss/ :sso+oso: .ss: :ss: - `sso +ss- .ss- :ssoss. +ssssssss- :ss:.+ss. ossssssss. - :sso:--:++ `+ss-` `-ss:` -ssss.`:ss/` `-sss-``/ss:` +ss-`.+ss-` `:sso. - `:/+o+/:` +++++- -++++: .+++`/++++- .+++++-/++++: `/++:+++++. -+++++. </pre> -# Cynara +# Cynagora -[Cynara][1] is fast, simple and safe permission database +[Cynagora][1] is fast, simple and safe permission database service. -Functions of Cynara are: +Functions of Cynagora are: * checking access for certain permission * holding permission database * simple, single function API - for checking permissions * thin client library - to make access control even more simple * ability to use external agent -(in case of policies that can't be full processed in cynara and plugins) +(in case of policies that can't be full processed in cynagora and plugins) ## API Overview -Please refer to a wiki page on [Cynara's API][2]. +Please refer to a wiki page on [Cynagora's API][2]. ## Documentation @@ -52,9 +29,9 @@ Documentation is kept on [wiki][1]. ## Repositories -Cynara repositories are available on: -* GitHub - [samsung/Cynara][3] repository -* tizen.org - [platform/core/security/cynara][4] repository - requires account on tizen.org +Cynagora repositories are available on: +* GitHub - [samsung/Cynagora][3] repository +* tizen.org - [platform/core/security/cynagora][4] repository - requires account on tizen.org ## Contact information @@ -65,11 +42,11 @@ Cynara repositories are available on: ## License -Cynara is licensed under a Apache License Version 2.0, January 2004. +Cynagora is licensed under a Apache License Version 2.0, January 2004. Available on Apache [website][5] or in LICENSE file. -[1]: https://wiki.tizen.org/wiki/Security:Cynara -[2]: https://wiki.tizen.org/wiki/Security:Cynara:API -[3]: https://github.com/Samsung/cynara -[4]: https://review.tizen.org/gerrit/#/admin/projects/platform/core/security/cynara +[1]: https://wiki.tizen.org/wiki/Security:Cynagora +[2]: https://wiki.tizen.org/wiki/Security:Cynagora:API +[3]: https://github.com/Samsung/cynagora +[4]: https://review.tizen.org/gerrit/#/admin/projects/platform/core/security/cynagora [5]: https://www.apache.org/licenses/ diff --git a/compat/CMakeLists.txt b/compat/CMakeLists.txt index 02af4a1..b91f84b 100644 --- a/compat/CMakeLists.txt +++ b/compat/CMakeLists.txt @@ -16,6 +16,9 @@ # limitations under the License. ########################################################################### +set(CYNARA_VERSION ${CYNAGORA_VERSION}) +set(CYNARA_SOVERSION ${CYNAGORA_SOVERSION}) + add_subdirectory(src) add_subdirectory(include) add_subdirectory(pkgconfig) diff --git a/compat/README-compat.md b/compat/README-compat.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/compat/README-compat.md @@ -0,0 +1 @@ + diff --git a/compat/src/CMakeLists.txt b/compat/src/CMakeLists.txt index 3bda2da..b033987 100644 --- a/compat/src/CMakeLists.txt +++ b/compat/src/CMakeLists.txt @@ -29,7 +29,7 @@ set_target_properties(cynara-compat SOVERSION ${CYNARA_SOVERSION} ) target_link_libraries(cynara-compat - PRIVATE cynara-client + PRIVATE cynagora ) target_link_options(cynara-compat PRIVATE @@ -44,4 +44,3 @@ add_executable(test-old-cynara main-test-old-cynara.c) target_link_libraries(test-old-cynara cynara-compat) install(TARGETS test-old-cynara RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) - diff --git a/compat/src/lib-compat.c b/compat/src/lib-compat.c index 63696fe..8035292 100644 --- a/compat/src/lib-compat.c +++ b/compat/src/lib-compat.c @@ -53,7 +53,7 @@ cynara_check(m_Cynara, # define CYNARA_ADMIN_ASK 11 #endif -#include "rcyn-client.h" +#include "cynagora.h" /******************** ADMIN ********************************/ @@ -151,12 +151,12 @@ struct cynara_admin; int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) { - return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 1, 0)); + return from_status(cynagora_open((cynagora_t**)pp_cynara_admin, cynagora_Admin, 1, 0)); } int cynara_admin_finish(struct cynara_admin *p_cynara_admin) { - rcyn_close((rcyn_t*)p_cynara_admin); + cynagora_close((cynagora_t*)p_cynara_admin); return CYNARA_API_SUCCESS; } @@ -165,12 +165,12 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, { int rc, rc2; const struct cynara_admin_policy *p; - rcyn_key_t key; - rcyn_value_t value; + cynagora_key_t key; + cynagora_value_t value; key.session = "*"; value.expire = 0; - rc = rcyn_enter((rcyn_t*)p_cynara_admin); + rc = cynagora_enter((cynagora_t*)p_cynara_admin); if (rc == 0) { p = *policies; while (rc == 0 && p != NULL) { @@ -178,14 +178,14 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, key.user = p->user; key.permission = p->privilege; if (p->result == CYNARA_ADMIN_DELETE) - rc = rcyn_drop((rcyn_t*)p_cynara_admin, &key); + rc = cynagora_drop((cynagora_t*)p_cynara_admin, &key); else if (p->result != CYNARA_ADMIN_BUCKET && p->result != CYNARA_ADMIN_NONE) { value.value = to_value(p->result); - rc = rcyn_set((rcyn_t*)p_cynara_admin, &key, &value); + rc = cynagora_set((cynagora_t*)p_cynara_admin, &key, &value); } p = *++policies; } - rc2 = rcyn_leave((rcyn_t*)p_cynara_admin, rc == 0); + rc2 = cynagora_leave((cynagora_t*)p_cynara_admin, rc == 0); if (rc == 0) rc = rc2; } @@ -194,8 +194,8 @@ int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, static void check_cb( void *closure, - const rcyn_key_t *key, - const rcyn_value_t *value + const cynagora_key_t *key, + const cynagora_value_t *value ) { *((int*)closure) = from_value(value->value); } @@ -205,11 +205,11 @@ int cynara_admin_check(struct cynara_admin *p_cynara_admin, const char *client, const char *user, const char *privilege, int *result, char **result_extra) { - rcyn_key_t key = { client, "*", user, privilege }; + cynagora_key_t key = { client, "*", user, privilege }; if (result_extra) *result_extra = NULL; *result = CYNARA_ADMIN_DENY; - return from_status(rcyn_get((rcyn_t*)p_cynara_admin, &key, check_cb, result)); + return from_status(cynagora_get((cynagora_t*)p_cynara_admin, &key, check_cb, result)); } struct list_data @@ -222,8 +222,8 @@ struct list_data static void list_cb( void *closure, - const rcyn_key_t *key, - const rcyn_value_t *value + const cynagora_key_t *key, + const cynagora_value_t *value ) { struct list_data *data = closure; struct cynara_admin_policy *pol; @@ -268,13 +268,13 @@ int cynara_admin_list_policies(struct cynara_admin *p_cynara_admin, const char * { int rc; struct list_data data; - rcyn_key_t key = { client, "*", user, privilege }; + cynagora_key_t key = { client, "*", user, privilege }; data.policies = NULL; data.bucket = bucket && strcmp(bucket, "#") && strcmp(bucket, "*") ? bucket : NULL; data.count = 0; data.error = 0; - rc = rcyn_get((rcyn_t*)p_cynara_admin, &key, list_cb, &data); + rc = cynagora_get((cynagora_t*)p_cynara_admin, &key, list_cb, &data); if (rc == 0 && data.error != 0) rc = data.error; if (rc == 0 && !data.error) { @@ -297,12 +297,12 @@ int cynara_admin_erase(struct cynara_admin *p_cynara_admin, const char *client, const char *user, const char *privilege) { int rc, rc2; - rcyn_key_t key = { client, "*", user, privilege }; + cynagora_key_t key = { client, "*", user, privilege }; - rc = rcyn_enter((rcyn_t*)p_cynara_admin); + rc = cynagora_enter((cynagora_t*)p_cynara_admin); if (rc == 0) { - rc = rcyn_drop((rcyn_t*)p_cynara_admin, &key); - rc2 = rcyn_leave((rcyn_t*)p_cynara_admin, rc == 0); + rc = cynagora_drop((cynagora_t*)p_cynara_admin, &key); + rc2 = cynagora_leave((cynagora_t*)p_cynara_admin, rc == 0); if (rc == 0) rc = rc2; } @@ -378,7 +378,7 @@ struct reqasync struct cynara_async { - rcyn_t *rcyn; + cynagora_t *rcyn; cynara_status_callback callback; void *user_status_data; struct reqasync *reqs; @@ -413,7 +413,7 @@ int cynara_async_initialize(cynara_async **pp_cynara, const cynara_async_configu if (p_cynara == NULL) ret = CYNARA_API_OUT_OF_MEMORY; else { - ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 1, 0)); + ret = from_status(cynagora_open(&p_cynara->rcyn, cynagora_Check, p_conf ? p_conf->szcache : 1, 0)); if (ret != CYNARA_API_SUCCESS) free(p_cynara); else { @@ -421,7 +421,7 @@ int cynara_async_initialize(cynara_async **pp_cynara, const cynara_async_configu p_cynara->user_status_data = user_status_data; p_cynara->reqs = NULL; p_cynara->ids = 0; - rcyn_async_setup(p_cynara->rcyn, async_control_cb, p_cynara); + cynagora_async_setup(p_cynara->rcyn, async_control_cb, p_cynara); *pp_cynara = p_cynara; } } @@ -439,7 +439,7 @@ void cynara_async_finish(cynara_async *p_cynara) } } - rcyn_close(p_cynara->rcyn); + cynagora_close(p_cynara->rcyn); while((req = p_cynara->reqs)) { p_cynara->reqs = req->next; @@ -452,8 +452,8 @@ int cynara_async_check_cache(cynara_async *p_cynara, const char *client, const c const char *user, const char *privilege) { int rc; - rcyn_key_t key = { client, client_session, user, privilege }; - rc = from_check_status(rcyn_cache_check(p_cynara->rcyn, &key)); + cynagora_key_t key = { client, client_session, user, privilege }; + rc = from_check_status(cynagora_cache_check(p_cynara->rcyn, &key)); return rc; } @@ -480,7 +480,7 @@ static int create_reqasync(cynara_async *p_cynara, const char *client, { int rc; struct reqasync *req; - rcyn_key_t key = { client, client_session, user, privilege }; + cynagora_key_t key = { client, client_session, user, privilege }; req = malloc(sizeof *req); if (req == NULL) @@ -493,7 +493,7 @@ static int create_reqasync(cynara_async *p_cynara, const char *client, req->id = ++p_cynara->ids; req->canceled = false; - rc = rcyn_async_check(p_cynara->rcyn, &key, simple, reqcb, req); + rc = cynagora_async_check(p_cynara->rcyn, &key, simple, reqcb, req); if (rc == 0) p_cynara->reqs = req; else @@ -525,7 +525,7 @@ int cynara_async_create_simple_request(cynara_async *p_cynara, const char *clien int cynara_async_process(cynara_async *p_cynara) { int rc; - rc = rcyn_async_process(p_cynara->rcyn); + rc = cynagora_async_process(p_cynara->rcyn); return rc; } @@ -569,27 +569,27 @@ int cynara_configuration_set_cache_size(cynara_configuration *p_conf, int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf) { - return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 1, 0)); + return from_status(cynagora_open((cynagora_t**)pp_cynara, cynagora_Check, p_conf ? p_conf->szcache : 1, 0)); } int cynara_finish(cynara *p_cynara) { - rcyn_close((rcyn_t*)p_cynara); + cynagora_close((cynagora_t*)p_cynara); return CYNARA_API_SUCCESS; } int cynara_check(cynara *p_cynara, const char *client, const char *client_session, const char *user, const char *privilege) { - rcyn_key_t key = { client, client_session, user, privilege }; - return from_check_status(rcyn_check((rcyn_t*)p_cynara, &key)); + cynagora_key_t key = { client, client_session, user, privilege }; + return from_check_status(cynagora_check((cynagora_t*)p_cynara, &key)); } int cynara_simple_check(cynara *p_cynara, const char *client, const char *client_session, const char *user, const char *privilege) { - rcyn_key_t key = { client, client_session, user, privilege }; - return from_check_status(rcyn_test((rcyn_t*)p_cynara, &key)); + cynagora_key_t key = { client, client_session, user, privilege }; + return from_check_status(cynagora_test((cynagora_t*)p_cynara, &key)); } /************************************* CREDS... & SESSION *********************************/ diff --git a/cynara.initial b/cynagora.initial index f2a88f8..c0430cd 100644 --- a/cynara.initial +++ b/cynagora.initial @@ -1,5 +1,5 @@ #-------------------------------------------------------------------- -# initial database for cynara +# initial database for cynagora # format: space/tab separated fields # fields: CLIENT SESSION USER PERMISSION ACTION EXPIRATION #-------------------------------------------------------------------- diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt index 14c05d5..4ca4ae9 100644 --- a/pkgconfig/CMakeLists.txt +++ b/pkgconfig/CMakeLists.txt @@ -16,7 +16,7 @@ # limitations under the License. ########################################################################### -configure_file(cynara.pc.in cynara.pc @ONLY) +configure_file(cynagora.pc.in cynagora.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cynara.pc +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cynagora.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/pkgconfig/cynagora.pc.in b/pkgconfig/cynagora.pc.in new file mode 100644 index 0000000..cef6de3 --- /dev/null +++ b/pkgconfig/cynagora.pc.in @@ -0,0 +1,5 @@ +Name: cynagora +Description: cynagora package +Version: @CYNAGORA_VERSION@ +Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lcynagora +Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@ -I@CMAKE_INSTALL_FULL_INCLUDEDIR@ diff --git a/pkgconfig/cynara.pc.in b/pkgconfig/cynara.pc.in deleted file mode 100644 index a92cbf4..0000000 --- a/pkgconfig/cynara.pc.in +++ /dev/null @@ -1,5 +0,0 @@ -Name: cynara -Description: cynara package -Version: @CYNARA_VERSION@ -Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lcynara-client -Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@ -I@CMAKE_INSTALL_FULL_INCLUDEDIR@/cynara diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2a17e8..cc7884c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,89 +31,79 @@ set(LIBCORE_SOURCES set(SERVER_SOURCES agent-at.c - main-cynarad.c + main-cynagorad.c prot.c - rcyn-protocol.c - rcyn-server.c + cyn-protocol.c + cyn-server.c socket.c ) set(LIBCLI_SOURCES cache.c - lib-compat.c prot.c - rcyn-client.c - rcyn-protocol.c - socket.c -) - -set(LIBCLI_SOURCES - cache.c - prot.c - rcyn-client.c - rcyn-protocol.c + cynagora.c + cyn-protocol.c socket.c ) add_compile_definitions(_GNU_SOURCE) ########################################### -# build and install libcynara-core +# build and install libcynagora-core ########################################### -add_library(cynara-core SHARED ${LIBCORE_SOURCES}) -target_include_directories(cynara-core PUBLIC .) -set_target_properties(cynara-core PROPERTIES - VERSION ${CYNARA_VERSION} - SOVERSION ${CYNARA_SOVERSION}) -target_link_libraries(cynara-core +add_library(cynagora-core SHARED ${LIBCORE_SOURCES}) +target_include_directories(cynagora-core PUBLIC .) +set_target_properties(cynagora-core PROPERTIES + VERSION ${CYNAGORA_VERSION} + SOVERSION ${CYNAGORA_SOVERSION}) +target_link_libraries(cynagora-core PRIVATE - -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export-cynara-core.map + -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export-cynagora-core.map ) -install(TARGETS cynara-core LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) +install(TARGETS cynagora-core LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) ########################################### -# build and install libcynara-client +# build and install libcynagora-client ########################################### -add_library(cynara-client SHARED ${LIBCLI_SOURCES}) -target_include_directories(cynara-client PUBLIC .) -target_compile_definitions(cynara-client PRIVATE - RCYN_DEFAULT_SOCKET_DIR="${DEFAULT_SOCKET_DIR}" +add_library(cynagora SHARED ${LIBCLI_SOURCES}) +target_include_directories(cynagora PUBLIC .) +target_compile_definitions(cynagora PRIVATE + DEFAULT_SOCKET_DIR="${DEFAULT_SOCKET_DIR}" ) -set_target_properties(cynara-client PROPERTIES - VERSION ${CYNARA_VERSION} - SOVERSION ${CYNARA_SOVERSION}) -target_link_options(cynara-client +set_target_properties(cynagora PROPERTIES + VERSION ${CYNAGORA_VERSION} + SOVERSION ${CYNAGORA_SOVERSION}) +target_link_options(cynagora PRIVATE - -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export-cynara-client.map + -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export-cynagora.map ) -install(TARGETS cynara-client LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) -install(FILES rcyn-client.h DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/cynara) +install(TARGETS cynagora LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) +install(FILES cynagora.h DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}) ########################################### -# build and install cynarad +# build and install cynagorad ########################################### -add_executable(cynarad ${SERVER_SOURCES}) -target_compile_definitions(cynarad PRIVATE +add_executable(cynagorad ${SERVER_SOURCES}) +target_compile_definitions(cynagorad PRIVATE DEFAULT_DB_DIR="${DEFAULT_DB_DIR}" DEFAULT_SOCKET_DIR="${DEFAULT_SOCKET_DIR}" DEFAULT_INIT_FILE="${DEFAULT_INIT_FILE}" - RCYN_DEFAULT_SOCKET_DIR="${DEFAULT_SOCKET_DIR}" ) if(WITH_SYSTEMD) - target_compile_definitions(cynarad PRIVATE WITH_SYSTEMD_ACTIVATION) - target_link_libraries(cynarad ${libsystemd_LDFLAGS} ${libsystemd_LINK_LIBRARIES}) - target_include_directories(cynarad PRIVATE ${libsystemd_INCLUDE_DIRS}) - target_compile_options(cynarad PRIVATE ${libsystemd_CFLAGS}) + target_compile_definitions(cynagorad PRIVATE WITH_SYSTEMD_ACTIVATION) + target_link_libraries(cynagorad ${libsystemd_LDFLAGS} ${libsystemd_LINK_LIBRARIES}) + target_include_directories(cynagorad PRIVATE ${libsystemd_INCLUDE_DIRS}) + target_compile_options(cynagorad PRIVATE ${libsystemd_CFLAGS}) endif() -target_link_libraries(cynarad cynara-core cap) -install(TARGETS cynarad +target_link_libraries(cynagorad cynagora-core cap) +install(TARGETS cynagorad RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) ########################################### -# build and install cynadm +# build and install cynagoradm ########################################### -add_executable(cynadm main-cynadm.c expire.c) -target_link_libraries(cynadm cynara-client) -install(TARGETS cynadm +add_executable(cynagoradm main-cynagoradm.c expire.c) +target_link_libraries(cynagoradm cynagora) +install(TARGETS cynagoradm RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) diff --git a/src/SOURCES.md b/src/README-src.md index e69de29..e69de29 100644 --- a/src/SOURCES.md +++ b/src/README-src.md diff --git a/src/agent-at.c b/src/agent-at.c index 21193f1..89e78d3 100644 --- a/src/agent-at.c +++ b/src/agent-at.c @@ -150,7 +150,7 @@ agent_at_cb( void *agent_closure, const data_key_t *key, const char *value, - cyn_query_t *query + cynagora_query_t *query ) { data_key_t atkey; char *block; diff --git a/src/cache.c b/src/cache.c index bed0b49..df346a8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -29,7 +29,7 @@ #include <time.h> #include <ctype.h> -#include "rcyn-client.h" +#include "cynagora.h" #include "cache.h" /** @@ -223,7 +223,7 @@ static bool match( const char *head, - const rcyn_key_t *key + const cynagora_key_t *key ) { head = cmp(head, key->client); if (head) { @@ -250,7 +250,7 @@ static item_t* search( cache_t *cache, - const rcyn_key_t *key + const cynagora_key_t *key ) { time_t now; item_t *item, *found; @@ -276,7 +276,7 @@ search( int cache_put( cache_t *cache, - const rcyn_key_t *key, + const cynagora_key_t *key, int value, time_t expire ) { @@ -318,7 +318,7 @@ cache_put( int cache_search( cache_t *cache, - const rcyn_key_t *key + const cynagora_key_t *key ) { item_t *item; diff --git a/src/cache.h b/src/cache.h index d694e9b..713efa4 100644 --- a/src/cache.h +++ b/src/cache.h @@ -34,7 +34,7 @@ extern int cache_search( cache_t *cache, - const rcyn_key_t *key + const cynagora_key_t *key ); /** @@ -51,7 +51,7 @@ extern int cache_put( cache_t *cache, - const rcyn_key_t *key, + const cynagora_key_t *key, int value, time_t expire ); diff --git a/src/cyn-protocol.c b/src/cyn-protocol.c new file mode 100644 index 0000000..b7f4c01 --- /dev/null +++ b/src/cyn-protocol.c @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author José Bollo <jose.bollo@iot.bzh> + * + * 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. + */ +/******************************************************************************/ +/******************************************************************************/ +/* IMPLEMENTATION OF COMMON PROTOCOL VALUES, CONSTANTS, PROCESSES */ +/******************************************************************************/ +/******************************************************************************/ + +#include <stdlib.h> + +#include "cyn-protocol.h" + +const char + _agent_[] = "agent", + _check_[] = "check", + _clear_[] = "clear", + _commit_[] = "commit", + _cynagora_[] = "cynagora", + _done_[] = "done", + _drop_[] = "drop", + _enter_[] = "enter", + _error_[] = "error", + _get_[] = "get", + _item_[] = "item", + _leave_[] = "leave", + _log_[] = "log", + _no_[] = "no", + _off_[] = "off", + _on_[] = "on", + _rollback_[] = "rollback", + _set_[] = "set", + _test_[] = "test", + _yes_[] = "yes"; + + +#if !defined(DEFAULT_SOCKET_SCHEME) +# define DEFAULT_SOCKET_SCHEME "unix" +#endif + +#if !defined(DEFAULT_SOCKET_DIR) +# define DEFAULT_SOCKET_DIR "/var/run/cynagora" +#endif + +#define DEF_PREFIX DEFAULT_SOCKET_SCHEME":"DEFAULT_SOCKET_DIR"/" + +#if !defined(DEFAULT_CHECK_SOCKET_BASE) +# define DEFAULT_CHECK_SOCKET_BASE "cynagora.check" +#endif +#if !defined(DEFAULT_ADMIN_SOCKET_BASE) +# define DEFAULT_ADMIN_SOCKET_BASE "cynagora.admin" +#endif +#if !defined(DEFAULT_AGENT_SOCKET_BASE) +# define DEFAULT_AGENT_SOCKET_BASE "cynagora.agent" +#endif + + +#if !defined(DEFAULT_CHECK_SOCKET_SPEC) +# define DEFAULT_CHECK_SOCKET_SPEC DEF_PREFIX DEFAULT_CHECK_SOCKET_BASE +#endif +#if !defined(DEFAULT_ADMIN_SOCKET_SPEC) +# define DEFAULT_ADMIN_SOCKET_SPEC DEF_PREFIX DEFAULT_ADMIN_SOCKET_BASE +#endif +#if !defined(DEFAULT_AGENT_SOCKET_SPEC) +# define DEFAULT_AGENT_SOCKET_SPEC DEF_PREFIX DEFAULT_AGENT_SOCKET_BASE +#endif + +const char + cyn_default_socket_scheme[] = DEFAULT_SOCKET_SCHEME, + cyn_default_socket_dir[] = DEFAULT_SOCKET_DIR, + cyn_default_check_socket_base[] = DEFAULT_CHECK_SOCKET_BASE, + cyn_default_admin_socket_base[] = DEFAULT_ADMIN_SOCKET_BASE, + cyn_default_agent_socket_base[] = DEFAULT_AGENT_SOCKET_BASE, + cyn_default_check_socket_spec[] = DEFAULT_CHECK_SOCKET_SPEC, + cyn_default_admin_socket_spec[] = DEFAULT_ADMIN_SOCKET_SPEC, + cyn_default_agent_socket_spec[] = DEFAULT_AGENT_SOCKET_SPEC; + +/* see cynagora-protocol.h */ +const char * +cyn_get_socket_check( + const char *value +) { + return value + ?: secure_getenv("CYNAGORA_SOCKET_CHECK") + ?: cyn_default_check_socket_spec; +} + +/* see cynagora-protocol.h */ +const char * +cyn_get_socket_admin( + const char *value +) { + return value + ?: secure_getenv("CYNAGORA_SOCKET_ADMIN") + ?: cyn_default_admin_socket_spec; +} + +/* see cynagora-protocol.h */ +const char * +cyn_get_socket_agent( + const char *value +) { + return value + ?: secure_getenv("CYNAGORA_SOCKET_AGENT") + ?: cyn_default_agent_socket_spec; +} diff --git a/src/rcyn-protocol.h b/src/cyn-protocol.h index 553a3df..d8bcca0 100644 --- a/src/rcyn-protocol.h +++ b/src/cyn-protocol.h @@ -27,6 +27,7 @@ extern const char _check_[], _clear_[], _commit_[], + _cynagora_[], _done_[], _drop_[], _enter_[], @@ -38,7 +39,6 @@ extern const char _no_[], _off_[], _on_[], - _rcyn_[], _rollback_[], _set_[], _test_[], @@ -46,14 +46,14 @@ extern const char /* predefined names */ extern const char - rcyn_default_socket_scheme[], - rcyn_default_socket_dir[], - rcyn_default_check_socket_base[], - rcyn_default_admin_socket_base[], - rcyn_default_agent_socket_base[], - rcyn_default_check_socket_spec[], - rcyn_default_admin_socket_spec[], - rcyn_default_agent_socket_spec[]; + cyn_default_socket_scheme[], + cyn_default_socket_dir[], + cyn_default_check_socket_base[], + cyn_default_admin_socket_base[], + cyn_default_agent_socket_base[], + cyn_default_check_socket_spec[], + cyn_default_admin_socket_spec[], + cyn_default_agent_socket_spec[]; /** * Get the socket specification for check usage @@ -63,7 +63,7 @@ extern const char */ extern const char * -rcyn_get_socket_check( +cyn_get_socket_check( const char *value ); @@ -75,7 +75,7 @@ rcyn_get_socket_check( */ extern const char * -rcyn_get_socket_admin( +cyn_get_socket_admin( const char *value ); @@ -87,6 +87,6 @@ rcyn_get_socket_admin( */ extern const char * -rcyn_get_socket_agent( +cyn_get_socket_agent( const char *value ); diff --git a/src/rcyn-server.c b/src/cyn-server.c index 378a07d..1921142 100644 --- a/src/rcyn-server.c +++ b/src/cyn-server.c @@ -16,7 +16,7 @@ */ /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF SERVER PART OF RCYN-PROTOCOL */ +/* IMPLEMENTATION OF SERVER PART OF CYNAGORA-PROTOCOL */ /******************************************************************************/ /******************************************************************************/ @@ -39,8 +39,8 @@ #include "data.h" #include "prot.h" #include "cyn.h" -#include "rcyn-protocol.h" -#include "rcyn-server.h" +#include "cyn-protocol.h" +#include "cyn-server.h" #include "socket.h" #include "pollitem.h" @@ -48,16 +48,16 @@ /** should log? */ bool -rcyn_server_log = 0; +cyn_server_log = 0; /** local enumeration of socket/client kind */ -typedef enum rcyn_type { - rcyn_Check, - rcyn_Agent, - rcyn_Admin -} rcyn_type_t; +typedef enum server_type { + server_Check, + server_Agent, + server_Admin +} server_type_t; -/** structure that represents a rcyn client */ +/** structure that represents a client */ struct client { /** a protocol structure */ @@ -90,7 +90,7 @@ struct client typedef struct client client_t; /** structure for servers */ -struct rcyn_server +struct cyn_server { /** the pollfd to use */ int pollfd; @@ -202,7 +202,7 @@ putx( va_end(l); /* emit the log */ - if (rcyn_server_log) + if (cyn_server_log) dolog(cli, 0, n, fields); /* send now */ @@ -360,12 +360,12 @@ onrequest( return; /* emit the log */ - if (rcyn_server_log) + if (cyn_server_log) dolog(cli, 1, count, args); /* version hand-shake */ if (!cli->version) { - if (!ckarg(args[0], _rcyn_, 0) || count != 2 || !ckarg(args[1], "1", 0)) + if (!ckarg(args[0], _cynagora_, 0) || count != 2 || !ckarg(args[1], "1", 0)) goto invalid; putx(cli, _yes_, "1", cyn_changeid_string(), NULL); flushw(cli); @@ -376,7 +376,7 @@ onrequest( switch(args[0][0]) { case 'a': /* agent */ if (ckarg(args[0], _agent_, 1) && count == 5) { - if (cli->type != rcyn_Agent) + if (cli->type != server_Agent) break; /* TODO */ break; return; @@ -395,7 +395,7 @@ onrequest( break; case 'd': /* drop */ if (ckarg(args[0], _drop_, 1) && count == 5) { - if (cli->type != rcyn_Admin) + if (cli->type != server_Admin) break; if (!cli->entered) break; @@ -410,7 +410,7 @@ onrequest( break; case 'e': /* enter */ if (ckarg(args[0], _enter_, 1) && count == 1) { - if (cli->type != rcyn_Admin) + if (cli->type != server_Admin) break; if (cli->entered || cli->entering) break; @@ -422,7 +422,7 @@ onrequest( break; case 'g': /* get */ if (ckarg(args[0], _get_, 1) && count == 5) { - if (cli->type != rcyn_Admin) + if (cli->type != server_Admin) break; key.client = args[1]; key.session = args[2]; @@ -435,7 +435,7 @@ onrequest( break; case 'l': /* leave */ if (ckarg(args[0], _leave_, 1) && count <= 2) { - if (cli->type != rcyn_Admin) + if (cli->type != server_Admin) break; if (count == 2 && !ckarg(args[1], _commit_, 0) && !ckarg(args[1], _rollback_, 0)) break; @@ -447,8 +447,8 @@ onrequest( return; } if (ckarg(args[0], _log_, 1) && count <= 2) { - nextlog = rcyn_server_log; - if (cli->type != rcyn_Admin) + nextlog = cyn_server_log; + if (cli->type != server_Admin) break; if (count == 2) { if (!ckarg(args[1], _on_, 0) && !ckarg(args[1], _off_, 0)) @@ -457,13 +457,13 @@ onrequest( } putx(cli, _done_, nextlog ? _on_ : _off_, NULL); flushw(cli); - rcyn_server_log = nextlog; + cyn_server_log = nextlog; return; } break; case 's': /* set */ if (ckarg(args[0], _set_, 1) && (count == 6 || count == 7)) { - if (cli->type != rcyn_Admin) + if (cli->type != server_Admin) break; if (!cli->entered) break; @@ -575,7 +575,7 @@ int create_client( client_t **pcli, int fd, - rcyn_type_t type + server_type_t type ) { client_t *cli; int rc; @@ -625,7 +625,7 @@ on_server_event( pollitem_t *pollitem, uint32_t events, int pollfd, - rcyn_type_t type + server_type_t type ) { int servfd = pollitem->fd; int fd, rc; @@ -678,7 +678,7 @@ on_check_server_event( uint32_t events, int pollfd ) { - on_server_event(pollitem, events, pollfd, rcyn_Check); + on_server_event(pollitem, events, pollfd, server_Check); } /** handle admin server events */ @@ -689,7 +689,7 @@ on_admin_server_event( uint32_t events, int pollfd ) { - on_server_event(pollitem, events, pollfd, rcyn_Admin); + on_server_event(pollitem, events, pollfd, server_Admin); } /** handle admin server events */ @@ -700,13 +700,13 @@ on_agent_server_event( uint32_t events, int pollfd ) { - on_server_event(pollitem, events, pollfd, rcyn_Agent); + on_server_event(pollitem, events, pollfd, server_Agent); } /** destroy a server */ void -rcyn_server_destroy( - rcyn_server_t *server +cyn_server_destroy( + cyn_server_t *server ) { if (server) { if (server->pollfd >= 0) @@ -721,13 +721,13 @@ rcyn_server_destroy( /** create a server */ int -rcyn_server_create( - rcyn_server_t **server, +cyn_server_create( + cyn_server_t **server, const char *admin_socket_spec, const char *check_socket_spec, const char *agent_socket_spec ) { - rcyn_server_t *srv; + cyn_server_t *srv; int rc; /* allocate the structure */ @@ -748,7 +748,7 @@ rcyn_server_create( } /* create the admin server socket */ - admin_socket_spec = rcyn_get_socket_admin(admin_socket_spec); + admin_socket_spec = cyn_get_socket_admin(admin_socket_spec); srv->admin.fd = socket_open(admin_socket_spec, 1); if (srv->admin.fd < 0) { rc = -errno; @@ -767,7 +767,7 @@ rcyn_server_create( } /* create the check server socket */ - check_socket_spec = rcyn_get_socket_check(check_socket_spec); + check_socket_spec = cyn_get_socket_check(check_socket_spec); srv->check.fd = socket_open(check_socket_spec, 1); if (srv->check.fd < 0) { rc = -errno; @@ -786,7 +786,7 @@ rcyn_server_create( } /* create the agent server socket */ - agent_socket_spec = rcyn_get_socket_agent(agent_socket_spec); + agent_socket_spec = cyn_get_socket_agent(agent_socket_spec); srv->agent.fd = socket_open(agent_socket_spec, 1); if (srv->agent.fd < 0) { rc = -errno; @@ -823,8 +823,8 @@ error: /** stop the server */ void -rcyn_server_stop( - rcyn_server_t *server, +cyn_server_stop( + cyn_server_t *server, int status ) { server->stopped = status ?: INT_MIN; @@ -832,8 +832,8 @@ rcyn_server_stop( /** create a server */ int -rcyn_server_serve( - rcyn_server_t *server +cyn_server_serve( + cyn_server_t *server ) { /* process inputs */ server->stopped = 0; diff --git a/src/rcyn-server.h b/src/cyn-server.h index 7982867..8117724 100644 --- a/src/rcyn-server.h +++ b/src/cyn-server.h @@ -17,27 +17,26 @@ #pragma once /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF SERVER PART OF RCYN-PROTOCOL */ +/* IMPLEMENTATION OF SERVER PART OF CYNAGORA-PROTOCOL */ /******************************************************************************/ /******************************************************************************/ -struct rcyn_server; -typedef struct rcyn_server rcyn_server_t; +typedef struct cyn_server cyn_server_t; extern bool -rcyn_server_log; +cyn_server_log; extern void -rcyn_server_destroy( - rcyn_server_t *server +cyn_server_destroy( + cyn_server_t *server ); extern int -rcyn_server_create( - rcyn_server_t **server, +cyn_server_create( + cyn_server_t **server, const char *admin_socket_spec, const char *check_socket_spec, const char *agent_socket_spec @@ -45,14 +44,14 @@ rcyn_server_create( extern int -rcyn_server_serve( - rcyn_server_t *server +cyn_server_serve( + cyn_server_t *server ); extern void -rcyn_server_stop( - rcyn_server_t *server, +cyn_server_stop( + cyn_server_t *server, int status ); @@ -16,7 +16,7 @@ */ /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF LOCAL CYNARA API */ +/* IMPLEMENTATION OF LOCAL CYNAGORA API */ /******************************************************************************/ /******************************************************************************/ @@ -88,7 +88,7 @@ struct agent /** * structure handling an asynchronous requests */ -struct cyn_query +struct cynagora_query { /** callback for handling result of the check */ on_result_cb_t *on_result_cb; @@ -412,7 +412,7 @@ required_agent( * @return the allocated structure or NULL in case of memory depletion */ static -cyn_query_t * +cynagora_query_t * alloc_query( on_result_cb_t *on_result_cb, void *closure, @@ -420,7 +420,7 @@ alloc_query( int maxdepth ) { size_t szcli, szses, szuse, szper; - cyn_query_t *query; + cynagora_query_t *query; void *ptr; /* allocate asynchronous query */ @@ -476,7 +476,7 @@ cyn_query_async( int rc; unsigned score; data_value_t value; - cyn_query_t *query; + cynagora_query_t *query; struct agent *agent; /* get the direct value */ @@ -538,7 +538,7 @@ cyn_check_async( /* see cyn.h */ int cyn_query_subquery_async( - cyn_query_t *query, + cynagora_query_t *query, on_result_cb_t *on_result_cb, void *closure, const data_key_t *key @@ -549,7 +549,7 @@ cyn_query_subquery_async( /* see cyn.h */ void cyn_query_reply( - cyn_query_t *query, + cynagora_query_t *query, const data_value_t *value ) { query->on_result_cb(query->closure, value); @@ -17,7 +17,7 @@ #pragma once /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF LOCAL CYNARA API */ +/* IMPLEMENTATION OF LOCAL CYNAGORA API */ /******************************************************************************/ /******************************************************************************/ @@ -57,7 +57,7 @@ typedef void (list_cb_t)( /** * Opaque structure for agent subqueries and responses. */ -typedef struct cyn_query cyn_query_t; +typedef struct cynagora_query cynagora_query_t; /** @@ -68,7 +68,7 @@ typedef int (agent_cb_t)( void *agent_closure, const data_key_t *key, const char *value, - cyn_query_t *query); + cynagora_query_t *query); /** * Enter in the critical recoverable section if possible @@ -314,7 +314,7 @@ cyn_check_async( extern int cyn_query_subquery_async( - cyn_query_t *query, + cynagora_query_t *query, on_result_cb_t *on_result_cb, void *closure, const data_key_t *key @@ -329,7 +329,7 @@ cyn_query_subquery_async( extern void cyn_query_reply( - cyn_query_t *query, + cynagora_query_t *query, const data_value_t *value ); diff --git a/src/rcyn-protocol.txt b/src/cynagora-protocol.txt index 70319f5..29e5b3a 100644 --- a/src/rcyn-protocol.txt +++ b/src/cynagora-protocol.txt @@ -3,7 +3,7 @@ protocol hello: - c->s rcyn 1 + c->s cynagora 1 s->c yes 1 CACHEID invalidate cache: @@ -20,6 +20,16 @@ check a permission: c->s check CLIENT SESSION USER PERMISSION s->c (yes|no) [EXPIRE] +enter critical (admin) + + c->s enter + s->c done + +leave critical (admin) + + c->s leave [commit|rollback] + s->c done|error ... + erase (admin): c->s drop CLIENT SESSION USER PERMISSION @@ -37,17 +47,7 @@ list permissions (admin): s->c ... s->c done -enter critical (admin) - - c->s enter - s->c done - -leave critical (admin) - - c->s leave [commit|rollback] - s->c done|error ... - -set/get logging status (admin) +logging set/get (admin) c->s log [on|off] s->c done (on|off) diff --git a/src/rcyn-client.c b/src/cynagora.c index e865888..1165e64 100644 --- a/src/rcyn-client.c +++ b/src/cynagora.c @@ -16,7 +16,7 @@ */ /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF CLIENT PART OF RCYN-PROTOCOL */ +/* IMPLEMENTATION OF CLIENT PART OF CYNAGORA-PROTOCOL */ /******************************************************************************/ /******************************************************************************/ @@ -37,22 +37,19 @@ #include <sys/epoll.h> #include "prot.h" -#include "rcyn-protocol.h" -#include "rcyn-client.h" +#include "cyn-protocol.h" +#include "cynagora.h" #include "cache.h" #include "socket.h" #define MIN_CACHE_SIZE 400 #define CACHESIZE(x) ((x) >= MIN_CACHE_SIZE ? (x) : (x) ? MIN_CACHE_SIZE : 0) -struct asreq; -typedef struct asreq asreq_t; - /** recording of asynchronous requests */ struct asreq { /** link to the next pending request */ - asreq_t *next; + struct asreq *next; /** callback function */ void (*callback)( @@ -62,14 +59,12 @@ struct asreq /** closure of the callback */ void *closure; }; - -struct rcyn; -typedef struct rcyn rcyn_t; +typedef struct asreq asreq_t; /** - * structure recording a rcyn client + * structure recording a client */ -struct rcyn +struct cynagora { /** file descriptor of the socket */ int fd; @@ -78,7 +73,7 @@ struct rcyn int pending; /** type of link */ - rcyn_type_t type; + cynagora_type_t type; /** spec of the socket */ const char *socketspec; @@ -101,17 +96,17 @@ struct rcyn /** async */ struct { /** control callback */ - rcyn_async_ctl_t controlcb; + cynagora_async_ctl_t controlcb; /** closure */ void *closure; - /** reqests */ + /** requests */ asreq_t *requests; } async; }; -static void disconnection(rcyn_t *rcyn); +static void disconnection(cynagora_t *cynagora); /** * Flush the write buffer @@ -119,18 +114,18 @@ static void disconnection(rcyn_t *rcyn); static int flushw( - rcyn_t *rcyn + cynagora_t *cynagora ) { int rc; struct pollfd pfd; for (;;) { - rc = prot_should_write(rcyn->prot); + rc = prot_should_write(cynagora->prot); if (!rc) break; - rc = prot_write(rcyn->prot, rcyn->fd); + rc = prot_write(cynagora->prot, cynagora->fd); if (rc == -EAGAIN) { - pfd.fd = rcyn->fd; + pfd.fd = cynagora->fd; pfd.events = POLLOUT; do { rc = poll(&pfd, 1, -1); } while (rc < 0 && errno == EINTR); if (rc < 0) @@ -151,17 +146,17 @@ flushw( static int putxkv( - rcyn_t *rcyn, + cynagora_t *cynagora, const char *command, const char *optarg, - const rcyn_key_t *optkey, - const rcyn_value_t *optval + const cynagora_key_t *optkey, + const cynagora_value_t *optval ) { int rc, trial; prot_t *prot; char text[30]; - prot = rcyn->prot; + prot = cynagora->prot; for(trial = 0 ; ; trial++) { rc = prot_put_field(prot, command); if (!rc && optarg) @@ -189,13 +184,13 @@ putxkv( rc = prot_put_end(prot); if (!rc) { /* client always flushes */ - rcyn->pending++; - return flushw(rcyn); + cynagora->pending++; + return flushw(cynagora); } prot_put_cancel(prot); if (trial >= 1) return rc; - rc = flushw(rcyn); + rc = flushw(cynagora); if (rc) return rc; } @@ -204,12 +199,12 @@ putxkv( static int wait_input( - rcyn_t *rcyn + cynagora_t *cynagora ) { int rc; struct pollfd pfd; - pfd.fd = rcyn->fd; + pfd.fd = cynagora->fd; pfd.events = POLLIN; do { rc = poll(&pfd, 1, -1); } while (rc < 0 && errno == EINTR); return rc < 0 ? -errno : 0; @@ -218,49 +213,49 @@ wait_input( static int get_reply( - rcyn_t *rcyn + cynagora_t *cynagora ) { int rc; - prot_next(rcyn->prot); - rc = prot_get(rcyn->prot, &rcyn->reply.fields); + prot_next(cynagora->prot); + rc = prot_get(cynagora->prot, &cynagora->reply.fields); if (rc > 0) { - if (0 == strcmp(rcyn->reply.fields[0], _clear_)) { - cache_clear(rcyn->cache, - rc > 1 ? (uint32_t)atol(rcyn->reply.fields[1]) : 0); + if (0 == strcmp(cynagora->reply.fields[0], _clear_)) { + cache_clear(cynagora->cache, + rc > 1 ? (uint32_t)atol(cynagora->reply.fields[1]) : 0); rc = 0; } else { - if (0 != strcmp(rcyn->reply.fields[0], _item_)) - rcyn->pending--; + if (0 != strcmp(cynagora->reply.fields[0], _item_)) + cynagora->pending--; } } - rcyn->reply.count = rc; + cynagora->reply.count = rc; return rc; } static int wait_reply( - rcyn_t *rcyn, + cynagora_t *cynagora, bool block ) { int rc; for(;;) { - prot_next(rcyn->prot); - rc = get_reply(rcyn); + prot_next(cynagora->prot); + rc = get_reply(cynagora); if (rc > 0) return rc; if (rc < 0) { - rc = prot_read(rcyn->prot, rcyn->fd); + rc = prot_read(cynagora->prot, cynagora->fd); while (rc <= 0) { if (rc == 0) return -(errno = EPIPE); if (rc == -EAGAIN && block) - rc = wait_input(rcyn); + rc = wait_input(cynagora); if (rc < 0) return rc; - rc = prot_read(rcyn->prot, rcyn->fd); + rc = prot_read(cynagora->prot, cynagora->fd); } } } @@ -269,41 +264,41 @@ wait_reply( static int flushr( - rcyn_t *rcyn + cynagora_t *cynagora ) { int rc; - do { rc = wait_reply(rcyn, false); } while(rc > 0); + do { rc = wait_reply(cynagora, false); } while(rc > 0); return rc; } static int status_done( - rcyn_t *rcyn + cynagora_t *cynagora ) { - return strcmp(rcyn->reply.fields[0], _done_) ? -ECANCELED : 0; + return strcmp(cynagora->reply.fields[0], _done_) ? -ECANCELED : 0; } static int status_check( - rcyn_t *rcyn, + cynagora_t *cynagora, time_t *expire ) { int rc; - if (!strcmp(rcyn->reply.fields[0], _yes_)) + if (!strcmp(cynagora->reply.fields[0], _yes_)) rc = 1; - else if (!strcmp(rcyn->reply.fields[0], _no_)) + else if (!strcmp(cynagora->reply.fields[0], _no_)) rc = 0; - else if (!strcmp(rcyn->reply.fields[0], _done_)) + else if (!strcmp(cynagora->reply.fields[0], _done_)) rc = -EEXIST; else rc = -EPROTO; - if (rcyn->reply.count >= 2) - *expire = strtoll(rcyn->reply.fields[1], NULL, 10); + if (cynagora->reply.count >= 2) + *expire = strtoll(cynagora->reply.fields[1], NULL, 10); else *expire = 0; @@ -313,14 +308,14 @@ status_check( static int wait_pending_reply( - rcyn_t *rcyn + cynagora_t *cynagora ) { int rc; for (;;) { - rc = wait_reply(rcyn, true); + rc = wait_reply(cynagora, true); if (rc < 0) return rc; - if (rc > 0 && rcyn->pending == 0) + if (rc > 0 && cynagora->pending == 0) return rc; } } @@ -328,426 +323,426 @@ wait_pending_reply( static int wait_done( - rcyn_t *rcyn + cynagora_t *cynagora ) { - int rc = wait_pending_reply(rcyn); + int rc = wait_pending_reply(cynagora); if (rc > 0) - rc = status_done(rcyn); + rc = status_done(cynagora); return rc; } static int async( - rcyn_t *rcyn, + cynagora_t *cynagora, int op, uint32_t events ) { - return rcyn->async.controlcb && rcyn->fd >= 0 - ? rcyn->async.controlcb(rcyn->async.closure, op, rcyn->fd, events) + return cynagora->async.controlcb && cynagora->fd >= 0 + ? cynagora->async.controlcb(cynagora->async.closure, op, cynagora->fd, events) : 0; } static void disconnection( - rcyn_t *rcyn + cynagora_t *cynagora ) { - if (rcyn->fd >= 0) { - async(rcyn, EPOLL_CTL_DEL, 0); - close(rcyn->fd); - rcyn->fd = -1; + if (cynagora->fd >= 0) { + async(cynagora, EPOLL_CTL_DEL, 0); + close(cynagora->fd); + cynagora->fd = -1; } } static int connection( - rcyn_t *rcyn + cynagora_t *cynagora ) { int rc; /* init the client */ - rcyn->pending = 0; - rcyn->reply.count = -1; - prot_reset(rcyn->prot); - rcyn->fd = socket_open(rcyn->socketspec, 0); - if (rcyn->fd < 0) + cynagora->pending = 0; + cynagora->reply.count = -1; + prot_reset(cynagora->prot); + cynagora->fd = socket_open(cynagora->socketspec, 0); + if (cynagora->fd < 0) return -errno; /* negociate the protocol */ - rc = putxkv(rcyn, _rcyn_, "1", 0, 0); + rc = putxkv(cynagora, _cynagora_, "1", 0, 0); if (rc >= 0) { - rc = wait_pending_reply(rcyn); + rc = wait_pending_reply(cynagora); if (rc >= 0) { rc = -EPROTO; - if (rcyn->reply.count >= 2 - && 0 == strcmp(rcyn->reply.fields[0], _yes_) - && 0 == strcmp(rcyn->reply.fields[1], "1")) { - cache_clear(rcyn->cache, - rcyn->reply.count > 2 ? (uint32_t)atol(rcyn->reply.fields[2]) : 0); - rc = async(rcyn, EPOLL_CTL_ADD, EPOLLIN); + if (cynagora->reply.count >= 2 + && 0 == strcmp(cynagora->reply.fields[0], _yes_) + && 0 == strcmp(cynagora->reply.fields[1], "1")) { + cache_clear(cynagora->cache, + cynagora->reply.count > 2 ? (uint32_t)atol(cynagora->reply.fields[2]) : 0); + rc = async(cynagora, EPOLL_CTL_ADD, EPOLLIN); if (rc >= 0) return 0; } } } - disconnection(rcyn); + disconnection(cynagora); return rc; } static int ensure_opened( - rcyn_t *rcyn + cynagora_t *cynagora ) { - if (rcyn->fd >= 0 && write(rcyn->fd, NULL, 0) < 0) - disconnection(rcyn); - return rcyn->fd < 0 ? connection(rcyn) : 0; + if (cynagora->fd >= 0 && write(cynagora->fd, NULL, 0) < 0) + disconnection(cynagora); + return cynagora->fd < 0 ? connection(cynagora) : 0; } /************************************************************************************/ int -rcyn_open( - rcyn_t **prcyn, - rcyn_type_t type, +cynagora_open( + cynagora_t **prcyn, + cynagora_type_t type, uint32_t cache_size, const char *socketspec ) { - rcyn_t *rcyn; + cynagora_t *cynagora; int rc; /* socket spec */ switch(type) { default: - case rcyn_Check: socketspec = rcyn_get_socket_check(socketspec); break; - case rcyn_Admin: socketspec = rcyn_get_socket_admin(socketspec); break; - case rcyn_Agent: socketspec = rcyn_get_socket_agent(socketspec); break; + case cynagora_Check: socketspec = cyn_get_socket_check(socketspec); break; + case cynagora_Admin: socketspec = cyn_get_socket_admin(socketspec); break; + case cynagora_Agent: socketspec = cyn_get_socket_agent(socketspec); break; } /* allocate the structure */ - *prcyn = rcyn = malloc(sizeof *rcyn + 1 + strlen(socketspec)); - if (rcyn == NULL) { + *prcyn = cynagora = malloc(sizeof *cynagora + 1 + strlen(socketspec)); + if (cynagora == NULL) { rc = -ENOMEM; goto error; } /* create a protocol object */ - rc = prot_create(&rcyn->prot); + rc = prot_create(&cynagora->prot); if (rc < 0) goto error2; /* socket spec */ - strcpy((char*)(rcyn+1), socketspec); + strcpy((char*)(cynagora+1), socketspec); /* record type and weakly create cache */ - cache_create(&rcyn->cache, CACHESIZE(cache_size)); - rcyn->type = type; - rcyn->socketspec = socketspec; - rcyn->async.controlcb = NULL; - rcyn->async.closure = 0; - rcyn->async.requests = NULL; + cache_create(&cynagora->cache, CACHESIZE(cache_size)); + cynagora->type = type; + cynagora->socketspec = socketspec; + cynagora->async.controlcb = NULL; + cynagora->async.closure = 0; + cynagora->async.requests = NULL; /* lazy connection */ - rcyn->fd = -1; + cynagora->fd = -1; /* done */ return 0; error2: - free(rcyn); + free(cynagora); error: *prcyn = NULL; return rc; } void -rcyn_disconnect( - rcyn_t *rcyn +cynagora_disconnect( + cynagora_t *cynagora ) { - disconnection(rcyn); + disconnection(cynagora); } void -rcyn_close( - rcyn_t *rcyn +cynagora_close( + cynagora_t *cynagora ) { - rcyn_async_setup(rcyn, NULL, NULL); - disconnection(rcyn); - prot_destroy(rcyn->prot); - free(rcyn->cache); - free(rcyn); + cynagora_async_setup(cynagora, NULL, NULL); + disconnection(cynagora); + prot_destroy(cynagora->prot); + free(cynagora->cache); + free(cynagora); } int -rcyn_enter( - rcyn_t *rcyn +cynagora_enter( + cynagora_t *cynagora ) { int rc; - if (rcyn->type != rcyn_Admin) + if (cynagora->type != cynagora_Admin) return -EPERM; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; - rc = putxkv(rcyn, _enter_, 0, 0, 0); + rc = putxkv(cynagora, _enter_, 0, 0, 0); if (rc >= 0) - rc = wait_done(rcyn); + rc = wait_done(cynagora); return rc; } int -rcyn_leave( - rcyn_t *rcyn, +cynagora_leave( + cynagora_t *cynagora, bool commit ) { int rc; - if (rcyn->type != rcyn_Admin) + if (cynagora->type != cynagora_Admin) return -EPERM; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; - rc = putxkv(rcyn, _leave_, commit ? _commit_ : 0/*default: rollback*/, 0, 0); + rc = putxkv(cynagora, _leave_, commit ? _commit_ : 0/*default: rollback*/, 0, 0); if (rc >= 0) - rc = wait_done(rcyn); + rc = wait_done(cynagora); return rc; } static int check_or_test( - rcyn_t *rcyn, - const rcyn_key_t *key, + cynagora_t *cynagora, + const cynagora_key_t *key, const char *action ) { int rc; time_t expire; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; /* ensure there is no clear cache pending */ - flushr(rcyn); + flushr(cynagora); /* check cache item */ - rc = cache_search(rcyn->cache, key); + rc = cache_search(cynagora->cache, key); if (rc >= 0) return rc; /* send the request */ - rc = putxkv(rcyn, action, 0, key, 0); + rc = putxkv(cynagora, action, 0, key, 0); if (rc >= 0) { /* get the response */ - rc = wait_pending_reply(rcyn); + rc = wait_pending_reply(cynagora); if (rc >= 0) { - rc = status_check(rcyn, &expire); - if (rcyn->cache && rc >= 0) - cache_put(rcyn->cache, key, rc, expire); + rc = status_check(cynagora, &expire); + if (cynagora->cache && rc >= 0) + cache_put(cynagora->cache, key, rc, expire); } } return rc; } int -rcyn_check( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_check( + cynagora_t *cynagora, + const cynagora_key_t *key ) { - return check_or_test(rcyn, key, _check_); + return check_or_test(cynagora, key, _check_); } int -rcyn_test( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_test( + cynagora_t *cynagora, + const cynagora_key_t *key ) { - return check_or_test(rcyn, key, _test_); + return check_or_test(cynagora, key, _test_); } int -rcyn_set( - rcyn_t *rcyn, - const rcyn_key_t *key, - const rcyn_value_t *value +cynagora_set( + cynagora_t *cynagora, + const cynagora_key_t *key, + const cynagora_value_t *value ) { int rc; - if (rcyn->type != rcyn_Admin) + if (cynagora->type != cynagora_Admin) return -EPERM; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; - rc = putxkv(rcyn, _set_, 0, key, value); + rc = putxkv(cynagora, _set_, 0, key, value); if (rc >= 0) - rc = wait_done(rcyn); + rc = wait_done(cynagora); return rc; } int -rcyn_get( - rcyn_t *rcyn, - const rcyn_key_t *key, +cynagora_get( + cynagora_t *cynagora, + const cynagora_key_t *key, void (*callback)( void *closure, - const rcyn_key_t *key, - const rcyn_value_t *value + const cynagora_key_t *key, + const cynagora_value_t *value ), void *closure ) { int rc; - rcyn_key_t k; - rcyn_value_t v; + cynagora_key_t k; + cynagora_value_t v; - if (rcyn->type != rcyn_Admin) + if (cynagora->type != cynagora_Admin) return -EPERM; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; - rc = putxkv(rcyn, _get_, 0, key, 0); + rc = putxkv(cynagora, _get_, 0, key, 0); if (rc >= 0) { - rc = wait_reply(rcyn, true); - while ((rc == 6 || rc == 7) && !strcmp(rcyn->reply.fields[0], _item_)) { - k.client = rcyn->reply.fields[1]; - k.session = rcyn->reply.fields[2]; - k.user = rcyn->reply.fields[3]; - k.permission = rcyn->reply.fields[4]; - v.value = rcyn->reply.fields[5]; - v.expire = rc == 6 ? 0 : (time_t)strtoll(rcyn->reply.fields[6], NULL, 10); + rc = wait_reply(cynagora, true); + while ((rc == 6 || rc == 7) && !strcmp(cynagora->reply.fields[0], _item_)) { + k.client = cynagora->reply.fields[1]; + k.session = cynagora->reply.fields[2]; + k.user = cynagora->reply.fields[3]; + k.permission = cynagora->reply.fields[4]; + v.value = cynagora->reply.fields[5]; + v.expire = rc == 6 ? 0 : (time_t)strtoll(cynagora->reply.fields[6], NULL, 10); callback(closure, &k, &v); - rc = wait_reply(rcyn, true); + rc = wait_reply(cynagora, true); } - rc = status_done(rcyn); + rc = status_done(cynagora); } return rc; } int -rcyn_log( - rcyn_t *rcyn, +cynagora_log( + cynagora_t *cynagora, int on, int off ) { int rc; - if (rcyn->type != rcyn_Admin) + if (cynagora->type != cynagora_Admin) return -EPERM; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; - rc = putxkv(rcyn, _log_, off ? _off_ : on ? _on_ : 0, 0, 0); + rc = putxkv(cynagora, _log_, off ? _off_ : on ? _on_ : 0, 0, 0); if (rc >= 0) - rc = wait_done(rcyn); + rc = wait_done(cynagora); - return rc < 0 ? rc : rcyn->reply.count < 2 ? 0 : !strcmp(rcyn->reply.fields[1], _on_); + return rc < 0 ? rc : cynagora->reply.count < 2 ? 0 : !strcmp(cynagora->reply.fields[1], _on_); } int -rcyn_drop( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_drop( + cynagora_t *cynagora, + const cynagora_key_t *key ) { int rc; - if (rcyn->type != rcyn_Admin) + if (cynagora->type != cynagora_Admin) return -EPERM; - if (rcyn->async.requests != NULL) + if (cynagora->async.requests != NULL) return -EINPROGRESS; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; - rc = putxkv(rcyn, _drop_, 0, key, 0); + rc = putxkv(cynagora, _drop_, 0, key, 0); if (rc >= 0) - rc = wait_done(rcyn); + rc = wait_done(cynagora); return rc; } /************************************************************************************/ int -rcyn_cache_resize( - rcyn_t *rcyn, +cynagora_cache_resize( + cynagora_t *cynagora, uint32_t size ) { - return cache_resize(&rcyn->cache, CACHESIZE(size)); + return cache_resize(&cynagora->cache, CACHESIZE(size)); } void -rcyn_cache_clear( - rcyn_t *rcyn +cynagora_cache_clear( + cynagora_t *cynagora ) { - cache_clear(rcyn->cache, 0); + cache_clear(cynagora->cache, 0); } int -rcyn_cache_check( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_cache_check( + cynagora_t *cynagora, + const cynagora_key_t *key ) { - return cache_search(rcyn->cache, key); + return cache_search(cynagora->cache, key); } /************************************************************************************/ int -rcyn_async_setup( - rcyn_t *rcyn, - rcyn_async_ctl_t controlcb, +cynagora_async_setup( + cynagora_t *cynagora, + cynagora_async_ctl_t controlcb, void *closure ) { asreq_t *ar; /* cancel pending requests */ - while((ar = rcyn->async.requests) != NULL) { - rcyn->async.requests = ar->next; + while((ar = cynagora->async.requests) != NULL) { + cynagora->async.requests = ar->next; ar->callback(ar->closure, -ECANCELED); free(ar); } /* remove existing polling */ - async(rcyn, EPOLL_CTL_DEL, 0); + async(cynagora, EPOLL_CTL_DEL, 0); /* records new data */ - rcyn->async.controlcb = controlcb; - rcyn->async.closure = closure; + cynagora->async.controlcb = controlcb; + cynagora->async.closure = closure; /* record to polling */ - return async(rcyn, EPOLL_CTL_ADD, EPOLLIN); + return async(cynagora, EPOLL_CTL_ADD, EPOLLIN); } int -rcyn_async_process( - rcyn_t *rcyn +cynagora_async_process( + cynagora_t *cynagora ) { int rc; const char *first; asreq_t *ar; time_t expire; - rcyn_key_t key; + cynagora_key_t key; for (;;) { /* non blocking wait for a reply */ - rc = wait_reply(rcyn, false); + rc = wait_reply(cynagora, false); if (rc < 0) return rc == -EAGAIN ? 0 : rc; @@ -756,25 +751,25 @@ rcyn_async_process( continue; /* skip done/error replies */ - first = rcyn->reply.fields[0]; + first = cynagora->reply.fields[0]; if (!strcmp(first, _done_) || !strcmp(first, _error_)) continue; /* ignore unexpected answers */ - ar = rcyn->async.requests; + ar = cynagora->async.requests; if (ar == NULL) continue; /* emit the asynchronous answer */ - rcyn->async.requests = ar->next; - rc = status_check(rcyn, &expire); + cynagora->async.requests = ar->next; + rc = status_check(cynagora, &expire); if (rc >= 0) { key.client = (const char*)(ar + 1); key.session = &key.client[1 + strlen(key.client)]; key.user = &key.session[1 + strlen(key.session)]; key.permission = &key.user[1 + strlen(key.user)]; - cache_put(rcyn->cache, &key, rc, expire); + cache_put(cynagora->cache, &key, rc, expire); } ar->callback(ar->closure, rc); free(ar); @@ -782,10 +777,10 @@ rcyn_async_process( } int -rcyn_async_check( - rcyn_t *rcyn, - const rcyn_key_t *key, - bool simple, +cynagora_async_check( + cynagora_t *cynagora, + const cynagora_key_t *key, + int simple, void (*callback)( void *closure, int status), @@ -794,7 +789,7 @@ rcyn_async_check( int rc; asreq_t **pr, *ar; - rc = ensure_opened(rcyn); + rc = ensure_opened(cynagora); if (rc < 0) return rc; @@ -810,16 +805,16 @@ rcyn_async_check( stpcpy(1 + stpcpy(1 + stpcpy(1 + stpcpy((char*)(ar + 1), key->client), key->session), key->user), key->permission); /* send the request */ - rc = putxkv(rcyn, simple ? _test_ : _check_, 0, key, 0); + rc = putxkv(cynagora, simple ? _test_ : _check_, 0, key, 0); if (rc >= 0) - rc = flushw(rcyn); + rc = flushw(cynagora); if (rc < 0) { free(ar); return rc; } /* record the request */ - pr = &rcyn->async.requests; + pr = &cynagora->async.requests; while(*pr != NULL) pr = &(*pr)->next; *pr = ar; diff --git a/src/rcyn-client.h b/src/cynagora.h index 5128c85..3b856da 100644 --- a/src/rcyn-client.h +++ b/src/cynagora.h @@ -17,132 +17,138 @@ #pragma once /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF CLIENT PART OF RCYN-PROTOCOL */ +/* IMPLEMENTATION OF CLIENT PART OF CYNAGORA-PROTOCOL */ /******************************************************************************/ /******************************************************************************/ +typedef struct cynagora cynagora_t; +typedef enum cynagora_type cynagora_type_t; +typedef struct cynagora_key cynagora_key_t; +typedef struct cynagora_value cynagora_value_t; -typedef struct rcyn rcyn_t; -typedef enum rcyn_type rcyn_type_t; -typedef struct rcyn_key rcyn_key_t; -typedef struct rcyn_value rcyn_value_t; - -enum rcyn_type { - rcyn_Check, - rcyn_Admin, - rcyn_Agent +enum cynagora_type { + cynagora_Check, + cynagora_Admin, + cynagora_Agent }; -struct rcyn_key { +struct cynagora_key { const char *client; const char *session; const char *user; const char *permission; }; -struct rcyn_value { +struct cynagora_value { const char *value; time_t expire; }; extern int -rcyn_open( - rcyn_t **rcyn, - rcyn_type_t type, +cynagora_open( + cynagora_t **cynagora, + cynagora_type_t type, uint32_t cache_size, const char *socketspec ); extern void -rcyn_disconnect( - rcyn_t *rcyn +cynagora_disconnect( + cynagora_t *cynagora ); extern void -rcyn_close( - rcyn_t *rcyn +cynagora_close( + cynagora_t *cynagora ); extern int -rcyn_enter( - rcyn_t *rcyn +cynagora_enter( + cynagora_t *cynagora ); extern int -rcyn_leave( - rcyn_t *rcyn, +cynagora_leave( + cynagora_t *cynagora, bool commit ); extern int -rcyn_check( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_check( + cynagora_t *cynagora, + const cynagora_key_t *key ); extern int -rcyn_test( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_test( + cynagora_t *cynagora, + const cynagora_key_t *key ); extern int -rcyn_set( - rcyn_t *rcyn, - const rcyn_key_t *key, - const rcyn_value_t *value +cynagora_set( + cynagora_t *cynagora, + const cynagora_key_t *key, + const cynagora_value_t *value ); extern int -rcyn_get( - rcyn_t *rcyn, - const rcyn_key_t *key, +cynagora_get( + cynagora_t *cynagora, + const cynagora_key_t *key, void (*callback)( void *closure, - const rcyn_key_t *key, - const rcyn_value_t *value + const cynagora_key_t *key, + const cynagora_value_t *value ), void *closure ); extern int -rcyn_log( - rcyn_t *rcyn, +cynagora_log( + cynagora_t *cynagora, int on, int off ); extern int -rcyn_drop( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_drop( + cynagora_t *cynagora, + const cynagora_key_t *key ); extern void -rcyn_cache_clear( - rcyn_t *rcyn +cynagora_cache_clear( + cynagora_t *cynagora +); + +extern +int +cynagora_cache_check( + cynagora_t *cynagora, + const cynagora_key_t *key ); extern int -rcyn_cache_check( - rcyn_t *rcyn, - const rcyn_key_t *key +cynagora_cache_resize( + cynagora_t *cynagora, + uint32_t size ); -typedef int (*rcyn_async_ctl_t)( +typedef int (*cynagora_async_ctl_t)( void *closure, int op, int fd, @@ -150,24 +156,24 @@ typedef int (*rcyn_async_ctl_t)( extern int -rcyn_async_setup( - rcyn_t *rcyn, - rcyn_async_ctl_t controlcb, +cynagora_async_setup( + cynagora_t *cynagora, + cynagora_async_ctl_t controlcb, void *closure ); extern int -rcyn_async_process( - rcyn_t *rcyn +cynagora_async_process( + cynagora_t *cynagora ); extern int -rcyn_async_check( - rcyn_t *rcyn, - const rcyn_key_t *key, - bool simple, +cynagora_async_check( + cynagora_t *cynagora, + const cynagora_key_t *key, + int simple, void (*callback)( void *closure, int status), diff --git a/src/export-cynara-core.map b/src/export-cynagora-core.map index 8193f44..8193f44 100644 --- a/src/export-cynara-core.map +++ b/src/export-cynagora-core.map diff --git a/src/export-cynara-client.map b/src/export-cynagora.map index 326de85..e7138de 100644 --- a/src/export-cynara-client.map +++ b/src/export-cynagora.map @@ -1,6 +1,6 @@ { global: - rcyn_*; + cynagora_*; local: *; }; diff --git a/src/filedb.c b/src/filedb.c index 9a57a68..86c302d 100644 --- a/src/filedb.c +++ b/src/filedb.c @@ -68,33 +68,33 @@ struct rule typedef struct rule rule_t; /* - * The cynara-agl database is made of 2 memory mapped files: + * The cynagora database is made of 2 memory mapped files: * - names: the zero terminated names * - rules: the rules based on name indexes as 32bits indexes - * These files are normally in /var/lib/cynara + * These files are normally in /var/lib/cynagora */ #if !defined(DEFAULT_DB_DIR) -# define DEFAULT_DB_DIR "/var/lib/cynara" +# define DEFAULT_DB_DIR "/var/lib/cynagora" #endif #if !defined(DEFAULT_DB_NAME) -# define DEFAULT_DB_NAME "cynara" +# define DEFAULT_DB_NAME "cynagora" #endif static const char filedb_default_directory[] = DEFAULT_DB_DIR; static const char filedb_default_name[] = DEFAULT_DB_NAME; -/** identification of names version 2 - * $> uuidgen --sha1 -n @url -N urn:AGL:cynara:db:names:2 - * $> uuid -v 5 ns:URL urn:AGL:cynara:db:names:2 +/** identification of names version 1 + * $> uuidgen --sha1 -n @url -N urn:AGL:cynagora:db:names:1 + * $> uuid -v 5 ns:URL urn:AGL:cynagora:db:names:1 */ -static const char uuid_names_v2[] = "6fa114d4-f3d9-58ab-a5d3-4674ee865c8d\n--\n"; +static const char uuid_names_v1[] = "b2c33494-995f-5cc2-9e5e-72ad412936a9\n--\n"; -/** identification of rules version 2 - * $> uuidgen --sha1 -n @url -N urn:AGL:cynara:db:rules:2 - * $> uuid -v 5 ns:URL urn:AGL:cynara:db:rules:2 +/** identification of rules version 1 + * $> uuidgen --sha1 -n @url -N urn:AGL:cynagora:db:rules:1 + * $> uuid -v 5 ns:URL urn:AGL:cynagora:db:rules:1 */ -static const char uuid_rules_v2[] = "6d48515a-3f64-52b1-9d15-4d13d073d48a\n--\n"; +static const char uuid_rules_v1[] = "73630c61-89a9-5e82-8b07-5e53eee785c8\n--\n"; -/** length of the identification */ +/** length of the identifications */ static const int uuidlen = 40; @@ -301,10 +301,10 @@ opendb( name = filedb_default_name; /* open the names */ - rc = open_identify(&filedb->fnames, directory, name, "names", uuid_names_v2, uuidlen); + rc = open_identify(&filedb->fnames, directory, name, "names", uuid_names_v1, uuidlen); if (rc == 0) { /* open the rules */ - rc = open_identify(&filedb->frules, directory, name, "rules", uuid_rules_v2, uuidlen); + rc = open_identify(&filedb->frules, directory, name, "rules", uuid_rules_v1, uuidlen); if (rc == 0) { /* connect internals */ rc = init_names(filedb); diff --git a/src/main-cynarad.c b/src/main-cynagorad.c index 6ed1878..66b5ea7 100644 --- a/src/main-cynarad.c +++ b/src/main-cynagorad.c @@ -16,7 +16,7 @@ */ /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF CYNARA SERVER */ +/* IMPLEMENTATION OF CYNAGORA SERVER */ /******************************************************************************/ /******************************************************************************/ @@ -44,22 +44,22 @@ #include "data.h" #include "db.h" #include "cyn.h" -#include "rcyn-server.h" -#include "rcyn-protocol.h" +#include "cyn-server.h" +#include "cyn-protocol.h" #include "dbinit.h" #include "agent-at.h" #if !defined(DEFAULT_DB_DIR) -# define DEFAULT_DB_DIR "/var/lib/cynara" +# define DEFAULT_DB_DIR "/var/lib/cynagora" #endif #if !defined(DEFAULT_INIT_FILE) -# define DEFAULT_INIT_FILE "/etc/security/cynara.initial" +# define DEFAULT_INIT_FILE "/etc/security/cynagora.initial" #endif -#if !defined(DEFAULT_CYNARA_USER) -# define DEFAULT_CYNARA_USER NULL +#if !defined(DEFAULT_CYNAGORA_USER) +# define DEFAULT_CYNAGORA_USER NULL #endif -#if !defined(DEFAULT_CYNARA_GROUP) -# define DEFAULT_CYNARA_GROUP NULL +#if !defined(DEFAULT_CYNAGORA_GROUP) +# define DEFAULT_CYNAGORA_GROUP NULL #endif #define _DBDIR_ 'd' @@ -109,7 +109,7 @@ static const char helptxt[] = "\n" - "usage: cynarad [options]...\n" + "usage: cynagorad [options]...\n" "\n" "otpions:\n" #if defined(WITH_SYSTEMD_ACTIVATION) @@ -138,7 +138,7 @@ helptxt[] = static const char versiontxt[] = - "cynarad version 1.99.99\n" + "cynagorad version 1.99.99\n" ; static int isid(const char *text); @@ -167,7 +167,7 @@ int main(int ac, char **av) struct passwd *pw; struct group *gr; cap_t caps = { 0 }; - rcyn_server_t *server; + cyn_server_t *server; char *spec_socket_admin, *spec_socket_check, *spec_socket_agent; /* scan arguments */ @@ -226,7 +226,7 @@ int main(int ac, char **av) /* handles help, version, error */ if (help) { - fprintf(stdout, helptxt, rcyn_default_socket_dir); + fprintf(stdout, helptxt, cyn_default_socket_dir); return 0; } if (version) { @@ -243,9 +243,9 @@ int main(int ac, char **av) /* set the defaults */ dbdir = dbdir ?: DEFAULT_DB_DIR; - socketdir = socketdir ?: rcyn_default_socket_dir; - user = user ?: DEFAULT_CYNARA_USER; - group = group ?: DEFAULT_CYNARA_GROUP; + socketdir = socketdir ?: cyn_default_socket_dir; + user = user ?: DEFAULT_CYNAGORA_USER; + group = group ?: DEFAULT_CYNAGORA_GROUP; init = init ?: DEFAULT_INIT_FILE; /* activate the agents */ @@ -258,9 +258,9 @@ int main(int ac, char **av) spec_socket_check = strdup("sd:check"); spec_socket_agent = strdup("sd:agent"); } else { - rc = asprintf(&spec_socket_admin, "%s:%s/%s", rcyn_default_socket_scheme, socketdir, rcyn_default_admin_socket_base); - rc = asprintf(&spec_socket_check, "%s:%s/%s", rcyn_default_socket_scheme, socketdir, rcyn_default_check_socket_base); - rc = asprintf(&spec_socket_agent, "%s:%s/%s", rcyn_default_socket_scheme, socketdir, rcyn_default_agent_socket_base); + rc = asprintf(&spec_socket_admin, "%s:%s/%s", cyn_default_socket_scheme, socketdir, cyn_default_admin_socket_base); + rc = asprintf(&spec_socket_check, "%s:%s/%s", cyn_default_socket_scheme, socketdir, cyn_default_check_socket_base); + rc = asprintf(&spec_socket_agent, "%s:%s/%s", cyn_default_socket_scheme, socketdir, cyn_default_agent_socket_base); } if (!spec_socket_admin || !spec_socket_check || !spec_socket_agent) { fprintf(stderr, "can't make socket paths\n"); @@ -337,9 +337,9 @@ int main(int ac, char **av) /* initialize server */ setvbuf(stderr, NULL, _IOLBF, 1000); - rcyn_server_log = (bool)flog; + cyn_server_log = (bool)flog; signal(SIGPIPE, SIG_IGN); /* avoid SIGPIPE! */ - rc = rcyn_server_create(&server, spec_socket_admin, spec_socket_check, spec_socket_agent); + rc = cyn_server_create(&server, spec_socket_admin, spec_socket_check, spec_socket_agent); if (rc < 0) { fprintf(stderr, "can't initialize server: %m\n"); return 1; @@ -352,7 +352,7 @@ int main(int ac, char **av) #endif /* serve */ - rc = rcyn_server_serve(server); + rc = cyn_server_serve(server); return rc ? 3 : 0; } diff --git a/src/main-cynadm.c b/src/main-cynagoradm.c index 9f3a179..216dd7e 100644 --- a/src/main-cynadm.c +++ b/src/main-cynagoradm.c @@ -16,7 +16,7 @@ */ /******************************************************************************/ /******************************************************************************/ -/* IMPLEMENTATION OF CYNARA ADMINISTRATION TOOL */ +/* IMPLEMENTATION OF CYNAGORA ADMINISTRATION TOOL */ /******************************************************************************/ /******************************************************************************/ @@ -34,8 +34,8 @@ #include <poll.h> #include <sys/epoll.h> -#include "rcyn-client.h" -#include "rcyn-protocol.h" +#include "cynagora.h" +#include "cyn-protocol.h" #include "expire.h" #define DEFAULT_CACHE_SIZE 5000 @@ -69,7 +69,6 @@ helptxt[] = "\n" "otpions:\n" " -s, --socket xxx set the base xxx for sockets\n" - " (default: %s)\n" " -e, --echo print the evaluated command\n" " -c, --cache xxx set the cache size to xxx bytes\n" " (default: %d)\n" @@ -302,7 +301,7 @@ help_expiration_text[] = "\n" ; -static rcyn_t *rcyn; +static cynagora_t *cynagora; static char buffer[4000]; static int bufill; static char *str[40]; @@ -310,8 +309,8 @@ static int nstr; static int pending; static int echo; -rcyn_key_t key; -rcyn_value_t value; +cynagora_key_t key; +cynagora_value_t value; int plink(int ac, char **av, int *used, int maxi) { @@ -405,7 +404,7 @@ struct listitem *listresult_sort(int count, struct listitem *head) return head; } -void listcb(void *closure, const rcyn_key_t *k, const rcyn_value_t *v) +void listcb(void *closure, const cynagora_key_t *k, const cynagora_value_t *v) { struct listresult *lr = closure; char buffer[100], *p; @@ -455,7 +454,7 @@ int do_list(int ac, char **av) rc = get_csup(ac, av, &uc, "#"); if (rc == 0) { memset(&lr, 0, sizeof lr); - rc = rcyn_get(rcyn, &key, listcb, &lr); + rc = cynagora_get(cynagora, &key, listcb, &lr); if (rc < 0) fprintf(stderr, "error %s\n", strerror(-rc)); else { @@ -490,10 +489,10 @@ int do_set(int ac, char **av) rc = get_csupve(ac, av, &uc, "*"); if (rc == 0) - rc = rcyn_enter(rcyn); + rc = cynagora_enter(cynagora); if (rc == 0) { - rc = rcyn_set(rcyn, &key, &value); - rcyn_leave(rcyn, !rc); + rc = cynagora_set(cynagora, &key, &value); + cynagora_leave(cynagora, !rc); } if (rc < 0) fprintf(stderr, "error %s\n", strerror(-rc)); @@ -506,28 +505,28 @@ int do_drop(int ac, char **av) rc = get_csup(ac, av, &uc, "#"); if (rc == 0) - rc = rcyn_enter(rcyn); + rc = cynagora_enter(cynagora); if (rc == 0) { - rc = rcyn_drop(rcyn, &key); - rcyn_leave(rcyn, !rc); + rc = cynagora_drop(cynagora, &key); + cynagora_leave(cynagora, !rc); } if (rc < 0) fprintf(stderr, "error %s\n", strerror(-rc)); return uc; } -int do_check(int ac, char **av, int (*f)(rcyn_t*,const rcyn_key_t*)) +int do_check(int ac, char **av, int (*f)(cynagora_t*,const cynagora_key_t*)) { int uc, rc; rc = get_csup(ac, av, &uc, NULL); if (rc == 0) { - rc = f(rcyn, &key); + rc = f(cynagora, &key); if (rc > 0) fprintf(stdout, "allowed\n"); else if (rc == 0) fprintf(stdout, "denied\n"); - else if (rc == -ENOENT && f == rcyn_cache_check) + else if (rc == -ENOENT && f == cynagora_cache_check) fprintf(stdout, "not in cache!\n"); else if (rc == -EEXIST) fprintf(stderr, "denied but an entry exist\n"); @@ -555,7 +554,7 @@ int do_acheck(int ac, char **av, bool simple) rc = get_csup(ac, av, &uc, NULL); if (rc == 0) { pending++; - rc = rcyn_async_check(rcyn, &key, simple, acheck_cb, NULL); + rc = cynagora_async_check(cynagora, &key, simple, acheck_cb, NULL); if (rc < 0) { fprintf(stderr, "error %s\n", strerror(-rc)); pending--; @@ -578,7 +577,7 @@ int do_log(int ac, char **av) return uc; } } - rc = rcyn_log(rcyn, on, off); + rc = cynagora_log(cynagora, on, off); if (rc < 0) fprintf(stderr, "error %s\n", strerror(-rc)); else @@ -636,25 +635,25 @@ int do_any(int ac, char **av) return do_drop(ac, av); if (!strcmp(av[0], "check")) - return do_check(ac, av, rcyn_check); + return do_check(ac, av, cynagora_check); if (!strcmp(av[0], "acheck")) return do_acheck(ac, av, 0); if (!strcmp(av[0], "test")) - return do_check(ac, av, rcyn_test); + return do_check(ac, av, cynagora_test); if (!strcmp(av[0], "atest")) return do_acheck(ac, av, 1); if (!strcmp(av[0], "cache")) - return do_check(ac, av, rcyn_cache_check); + return do_check(ac, av, cynagora_cache_check); if (!strcmp(av[0], "log")) return do_log(ac, av); if (!strcmp(av[0], "clear")) { - rcyn_cache_clear(rcyn); + cynagora_cache_clear(cynagora); return 1; } @@ -716,6 +715,8 @@ int main(int ac, char **av) struct pollfd fds[2]; char *p; + setlinebuf(stdout); + /* scan arguments */ for (;;) { opt = getopt_long(ac, av, shortopts, longopts, NULL); @@ -751,7 +752,7 @@ int main(int ac, char **av) /* handles help, version, error */ if (help) { - fprintf(stdout, helptxt, rcyn_default_admin_socket_spec, DEFAULT_CACHE_SIZE); + fprintf(stdout, helptxt, DEFAULT_CACHE_SIZE); return 0; } if (version) { @@ -763,14 +764,14 @@ int main(int ac, char **av) /* initialize server */ signal(SIGPIPE, SIG_IGN); /* avoid SIGPIPE! */ - rc = rcyn_open(&rcyn, rcyn_Admin, cachesize, socket); + rc = cynagora_open(&cynagora, cynagora_Admin, cachesize, socket); if (rc < 0) { fprintf(stderr, "initialization failed: %s\n", strerror(-rc)); return 1; } fds[1].fd = -1; - rc = rcyn_async_setup(rcyn, async_ctl, &fds[1].fd); + rc = cynagora_async_setup(cynagora, async_ctl, &fds[1].fd); if (rc < 0) { fprintf(stderr, "asynchronous setup failed: %s\n", strerror(-rc)); return 1; @@ -814,7 +815,7 @@ int main(int ac, char **av) fds[0].fd = -1; } if (fds[1].revents & POLLIN) { - rc = rcyn_async_process(rcyn); + rc = cynagora_async_process(cynagora); if (rc < 0) fprintf(stderr, "asynchronous processing failed: %s\n", strerror(-rc)); if (fds[0].fd < 0 && !pending) diff --git a/src/rcyn-protocol.c b/src/rcyn-protocol.c deleted file mode 100644 index 09db418..0000000 --- a/src/rcyn-protocol.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author José Bollo <jose.bollo@iot.bzh> - * - * 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. - */ -/******************************************************************************/ -/******************************************************************************/ -/* IMPLEMENTATION OF COMMON PROTOCOL VALUES, CONSTANTS, PROCESSES */ -/******************************************************************************/ -/******************************************************************************/ - -#include <stdlib.h> - -#include "rcyn-protocol.h" - -const char - _agent_[] = "agent", - _check_[] = "check", - _clear_[] = "clear", - _commit_[] = "commit", - _done_[] = "done", - _drop_[] = "drop", - _enter_[] = "enter", - _error_[] = "error", - _get_[] = "get", - _item_[] = "item", - _leave_[] = "leave", - _log_[] = "log", - _no_[] = "no", - _off_[] = "off", - _on_[] = "on", - _rcyn_[] = "rcyn", - _rollback_[] = "rollback", - _set_[] = "set", - _test_[] = "test", - _yes_[] = "yes"; - - -#if !defined(RCYN_DEFAULT_SOCKET_SCHEME) -# define RCYN_DEFAULT_SOCKET_SCHEME "unix" -#endif - -#if !defined(RCYN_DEFAULT_SOCKET_DIR) -# define RCYN_DEFAULT_SOCKET_DIR "/var/run/cynara" -#endif - -#define DEF_PREFIX RCYN_DEFAULT_SOCKET_SCHEME":"RCYN_DEFAULT_SOCKET_DIR"/" - -#if !defined(RCYN_DEFAULT_CHECK_SOCKET_BASE) -# define RCYN_DEFAULT_CHECK_SOCKET_BASE "cynara.check" -#endif -#if !defined(RCYN_DEFAULT_ADMIN_SOCKET_BASE) -# define RCYN_DEFAULT_ADMIN_SOCKET_BASE "cynara.admin" -#endif -#if !defined(RCYN_DEFAULT_AGENT_SOCKET_BASE) -# define RCYN_DEFAULT_AGENT_SOCKET_BASE "cynara.agent" -#endif - - -#if !defined(RCYN_DEFAULT_CHECK_SOCKET_SPEC) -# define RCYN_DEFAULT_CHECK_SOCKET_SPEC DEF_PREFIX RCYN_DEFAULT_CHECK_SOCKET_BASE -#endif -#if !defined(RCYN_DEFAULT_ADMIN_SOCKET_SPEC) -# define RCYN_DEFAULT_ADMIN_SOCKET_SPEC DEF_PREFIX RCYN_DEFAULT_ADMIN_SOCKET_BASE -#endif -#if !defined(RCYN_DEFAULT_AGENT_SOCKET_SPEC) -# define RCYN_DEFAULT_AGENT_SOCKET_SPEC DEF_PREFIX RCYN_DEFAULT_AGENT_SOCKET_BASE -#endif - -const char - rcyn_default_socket_scheme[] = RCYN_DEFAULT_SOCKET_SCHEME, - rcyn_default_socket_dir[] = RCYN_DEFAULT_SOCKET_DIR, - rcyn_default_check_socket_base[] = RCYN_DEFAULT_CHECK_SOCKET_BASE, - rcyn_default_admin_socket_base[] = RCYN_DEFAULT_ADMIN_SOCKET_BASE, - rcyn_default_agent_socket_base[] = RCYN_DEFAULT_AGENT_SOCKET_BASE, - rcyn_default_check_socket_spec[] = RCYN_DEFAULT_CHECK_SOCKET_SPEC, - rcyn_default_admin_socket_spec[] = RCYN_DEFAULT_ADMIN_SOCKET_SPEC, - rcyn_default_agent_socket_spec[] = RCYN_DEFAULT_AGENT_SOCKET_SPEC; - -/* see rcyn-protocol.h */ -const char * -rcyn_get_socket_check( - const char *value -) { - return value - ?: secure_getenv("CYNARA_SOCKET_CHECK") - ?: rcyn_default_check_socket_spec; -} - -/* see rcyn-protocol.h */ -const char * -rcyn_get_socket_admin( - const char *value -) { - return value - ?: secure_getenv("CYNARA_SOCKET_ADMIN") - ?: rcyn_default_admin_socket_spec; -} - -/* see rcyn-protocol.h */ -const char * -rcyn_get_socket_agent( - const char *value -) { - return value - ?: secure_getenv("CYNARA_SOCKET_AGENT") - ?: rcyn_default_agent_socket_spec; -} diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index 9ea1f7e..c68f7f5 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -19,16 +19,16 @@ set(SYSTEMD_UNIT_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/systemd/system" CACHE PATH "Path to systemd system unit files") -CONFIGURE_FILE(cynara-admin.socket.in cynara-admin.socket @ONLY) -CONFIGURE_FILE(cynara-check.socket.in cynara-check.socket @ONLY) -CONFIGURE_FILE(cynara-agent.socket.in cynara-agent.socket @ONLY) +CONFIGURE_FILE(cynagora-admin.socket.in cynagora-admin.socket @ONLY) +CONFIGURE_FILE(cynagora-check.socket.in cynagora-check.socket @ONLY) +CONFIGURE_FILE(cynagora-agent.socket.in cynagora-agent.socket @ONLY) INSTALL(FILES - ${CMAKE_CURRENT_SOURCE_DIR}/cynara.service - ${CMAKE_CURRENT_SOURCE_DIR}/cynara.target - ${CMAKE_CURRENT_BINARY_DIR}/cynara-admin.socket - ${CMAKE_CURRENT_BINARY_DIR}/cynara-check.socket - ${CMAKE_CURRENT_BINARY_DIR}/cynara-agent.socket + ${CMAKE_CURRENT_SOURCE_DIR}/cynagora.service + ${CMAKE_CURRENT_SOURCE_DIR}/cynagora.target + ${CMAKE_CURRENT_BINARY_DIR}/cynagora-admin.socket + ${CMAKE_CURRENT_BINARY_DIR}/cynagora-check.socket + ${CMAKE_CURRENT_BINARY_DIR}/cynagora-agent.socket DESTINATION ${SYSTEMD_UNIT_DIR} ) diff --git a/systemd/cynara-admin.socket.in b/systemd/cynagora-admin.socket.in index 25c3b2c..622c023 100644 --- a/systemd/cynara-admin.socket.in +++ b/systemd/cynagora-admin.socket.in @@ -1,15 +1,15 @@ [Socket] FileDescriptorName=admin -ListenStream=@DEFAULT_SOCKET_DIR@/cynara.admin +ListenStream=@DEFAULT_SOCKET_DIR@/cynagora.admin SocketMode=0600 SmackLabelIPIn=@ SmackLabelIPOut=@ -Service=cynara.service +Service=cynagora.service [Unit] -Wants=cynara.target -Before=cynara.target +Wants=cynagora.target +Before=cynagora.target [Install] WantedBy=sockets.target diff --git a/systemd/cynara-agent.socket.in b/systemd/cynagora-agent.socket.in index 12dd064..a5e66b8 100644 --- a/systemd/cynara-agent.socket.in +++ b/systemd/cynagora-agent.socket.in @@ -1,15 +1,15 @@ [Socket] FileDescriptorName=agent -ListenStream=@DEFAULT_SOCKET_DIR@/cynara.agent +ListenStream=@DEFAULT_SOCKET_DIR@/cynagora.agent SocketMode=0600 SmackLabelIPIn=@ SmackLabelIPOut=@ -Service=cynara.service +Service=cynagora.service [Unit] -Wants=cynara.target -Before=cynara.target +Wants=cynagora.target +Before=cynagora.target [Install] WantedBy=sockets.target diff --git a/systemd/cynara-check.socket.in b/systemd/cynagora-check.socket.in index b0606e0..fcd6ed1 100644 --- a/systemd/cynara-check.socket.in +++ b/systemd/cynagora-check.socket.in @@ -1,15 +1,15 @@ [Socket] FileDescriptorName=check -ListenStream=@DEFAULT_SOCKET_DIR@/cynara.check +ListenStream=@DEFAULT_SOCKET_DIR@/cynagora.check SocketMode=0666 SmackLabelIPIn=* SmackLabelIPOut=@ -Service=cynara.service +Service=cynagora.service [Unit] -Wants=cynara.target -Before=cynara.target +Wants=cynagora.target +Before=cynagora.target [Install] WantedBy=sockets.target diff --git a/systemd/cynagora.service b/systemd/cynagora.service new file mode 100644 index 0000000..97a0f36 --- /dev/null +++ b/systemd/cynagora.service @@ -0,0 +1,26 @@ +[Unit] +Description=Cynagora service +Requires=afm-system-setup.service +After=afm-system-setup.service + +[Service] +ExecStart=/usr/bin/cynagorad --systemd --user cynagora --group cynagora --make-db-dir --own-db-dir + +Type=notify + +KillMode=process +TimeoutStopSec=3 +Restart=always + +Sockets=cynagora-admin.socket +Sockets=cynagora-check.socket +Sockets=cynagora-agent.socket +SmackProcessLabel=System + +#UMask=0000 +#User=cynagora +#Group=cynagora +#NoNewPrivileges=true + +[Install] +WantedBy=multi-user.target diff --git a/systemd/cynara.target b/systemd/cynagora.target index 9b2dee4..e41ed4c 100644 --- a/systemd/cynara.target +++ b/systemd/cynagora.target @@ -1,4 +1,4 @@ [Unit] -Description=cynara sockets +Description=cynagora sockets DefaultDependencies=true diff --git a/systemd/cynara.service b/systemd/cynara.service deleted file mode 100644 index b7bfd5a..0000000 --- a/systemd/cynara.service +++ /dev/null @@ -1,29 +0,0 @@ -[Unit] -Description=Cynara service -Requires=afm-system-setup.service -After=afm-system-setup.service - -[Service] -ExecStart=/usr/bin/cynarad --systemd --user cynara --group cynara --make-db-dir --own-db-dir - -Type=notify - -KillMode=process -TimeoutStopSec=3 -Restart=always - -Sockets=cynara-admin.socket -Sockets=cynara-check.socket -Sockets=cynara-agent.socket -SmackProcessLabel=System - -#UMask=0000 -#User=cynara -#Group=cynara -#NoNewPrivileges=true - -#Environment="CYNARA_LOG_LEVEL=LOG_DEBUG" -#Environment="CYNARA_AUDIT_LEVEL=ALL" - -[Install] -WantedBy=multi-user.target diff --git a/systemd/sockets.target.wants/cynagora-admin.socket b/systemd/sockets.target.wants/cynagora-admin.socket new file mode 120000 index 0000000..d16bdde --- /dev/null +++ b/systemd/sockets.target.wants/cynagora-admin.socket @@ -0,0 +1 @@ +../cynagora-admin.socket
\ No newline at end of file diff --git a/systemd/sockets.target.wants/cynagora-agent.socket b/systemd/sockets.target.wants/cynagora-agent.socket new file mode 120000 index 0000000..e22a713 --- /dev/null +++ b/systemd/sockets.target.wants/cynagora-agent.socket @@ -0,0 +1 @@ +../cynagora-agent.socket
\ No newline at end of file diff --git a/systemd/sockets.target.wants/cynagora-check.socket b/systemd/sockets.target.wants/cynagora-check.socket new file mode 120000 index 0000000..ad41243 --- /dev/null +++ b/systemd/sockets.target.wants/cynagora-check.socket @@ -0,0 +1 @@ +../cynagora-check.socket
\ No newline at end of file diff --git a/systemd/sockets.target.wants/cynara-admin.socket b/systemd/sockets.target.wants/cynara-admin.socket deleted file mode 120000 index 3d0b1ce..0000000 --- a/systemd/sockets.target.wants/cynara-admin.socket +++ /dev/null @@ -1 +0,0 @@ -../cynara-admin.socket
\ No newline at end of file diff --git a/systemd/sockets.target.wants/cynara-agent.socket b/systemd/sockets.target.wants/cynara-agent.socket deleted file mode 120000 index 22b37dd..0000000 --- a/systemd/sockets.target.wants/cynara-agent.socket +++ /dev/null @@ -1 +0,0 @@ -../cynara-agent.socket
\ No newline at end of file diff --git a/systemd/sockets.target.wants/cynara-check.socket b/systemd/sockets.target.wants/cynara-check.socket deleted file mode 120000 index 921ca66..0000000 --- a/systemd/sockets.target.wants/cynara-check.socket +++ /dev/null @@ -1 +0,0 @@ -../cynara-check.socket
\ No newline at end of file diff --git a/tests/stress-cache.sh b/tests/stress-cache.sh index fdaa323..c2b022c 100755 --- a/tests/stress-cache.sh +++ b/tests/stress-cache.sh @@ -11,7 +11,7 @@ do done > $i # run daemon -cynarad -i $i -d $d -S $d -l & +cynagorad -i $i -d $d -S $d -l & pc=$! sleep 2 @@ -23,7 +23,7 @@ for((y = 0 ; y < 10 ; y++)); do sleep .05 done done | -valgrind cynadm -c 2000 -e -s $d/cynara.check +valgrind cynagoradm -c 2000 -e -s $d/cynagora.check echo ----------- STOP ------------------ # terminate |