From 51c1a7dd950efef6a4d00df1878341777f8064ff Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Tue, 27 Aug 2019 18:56:46 +0100 Subject: [PATCH] Move key database backends into their own directory These logically sit together and are separate from the core code, so move them off to a separate directory. There are various bits of support that should be hived off the core libonak and move in here too, but that can wait until later. --- CMakeLists.txt | 89 +++++------------------- keydb/CMakeLists.txt | 61 ++++++++++++++++ keyd.8 => keydb/keyd.8 | 0 keyd.c => keydb/keyd.c | 0 keyd.h => keydb/keyd.h | 0 keydb.c => keydb/keydb.c | 0 keydb_db4.c => keydb/keydb_db4.c | 0 keydb_dynamic.c => keydb/keydb_dynamic.c | 0 keydb_file.c => keydb/keydb_file.c | 0 keydb_fs.c => keydb/keydb_fs.c | 0 keydb_hkp.c => keydb/keydb_hkp.c | 0 keydb_keyd.c => keydb/keydb_keyd.c | 0 keydb_keyring.c => keydb/keydb_keyring.c | 0 keydb_pg.c => keydb/keydb_pg.c | 0 keydb_stacked.c => keydb/keydb_stacked.c | 0 keydctl.8 => keydb/keydctl.8 | 0 keydctl.c => keydb/keydctl.c | 0 runtests | 4 +- t/test-in.ini | 2 +- 19 files changed, 80 insertions(+), 76 deletions(-) create mode 100644 keydb/CMakeLists.txt rename keyd.8 => keydb/keyd.8 (100%) rename keyd.c => keydb/keyd.c (100%) rename keyd.h => keydb/keyd.h (100%) rename keydb.c => keydb/keydb.c (100%) rename keydb_db4.c => keydb/keydb_db4.c (100%) rename keydb_dynamic.c => keydb/keydb_dynamic.c (100%) rename keydb_file.c => keydb/keydb_file.c (100%) rename keydb_fs.c => keydb/keydb_fs.c (100%) rename keydb_hkp.c => keydb/keydb_hkp.c (100%) rename keydb_keyd.c => keydb/keydb_keyd.c (100%) rename keydb_keyring.c => keydb/keydb_keyring.c (100%) rename keydb_pg.c => keydb/keydb_pg.c (100%) rename keydb_stacked.c => keydb/keydb_stacked.c (100%) rename keydctl.8 => keydb/keydctl.8 (100%) rename keydctl.c => keydb/keydctl.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b28688..bf819d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,70 +48,29 @@ else() target_sources(libonak PRIVATE md5.c sha1.c) endif() -# Backends - -# These have no dependencies and can always be compiled -set(BACKENDS "file" "fs" "keyring" "stacked") - -# DB4 backend (add check for existence) -LIST(APPEND BACKENDS db4) -set(BACKEND_db4_LIBS db-5.3) - -# HKP backend - needs libcurl -pkg_check_modules(CURL libcurl) -if (CURL_FOUND) - LIST(APPEND BACKENDS hkp) - set(BACKEND_hkp_INC ${CURL_INCLUDE_DIRS}) - set(BACKEND_hkp_LIBS ${CURL_LIBRARIES}) -endif() - -# PostgreSQL backend - needs libpq -pkg_check_modules(POSTGRESQL libpq) -if (POSTGRESQL_FOUND) - LIST(APPEND BACKENDS pg) - set(BACKEND_pg_INC ${POSTGRESQL_INCLUDE_DIRS}) - set(BACKEND_pg_LIBS ${POSTGRESQL_LIBRARIES}) -endif() +# Build files that have substitutions in them +include_directories(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) +configure_file("${CMAKE_SOURCE_DIR}/build-config.h.in" + "${CMAKE_BINARY_DIR}/build-config.h" @ONLY) -# keyd backend - can be disabled entirely -if (KEYD STREQUAL "ON") - LIST(APPEND BACKENDS keyd) - - add_executable(keyd keyd.c) - target_link_libraries(keyd libonak) - add_executable(keydctl keydctl.c onak-conf.c) - target_link_libraries(keydctl libonak) - target_compile_definitions(keydctl PRIVATE - CONFIGDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}") - - pkg_check_modules(SYSTEMD libsystemd) - if (SYSTEMD_FOUND) - set(HAVE_SYSTEMD true) - target_include_directories(keyd SYSTEM PUBLIC - ${SYSTEMD_INCLUDE_DIRS}) - target_link_libraries(keyd ${SYSTEMD_LIBRARIES}) - endif() +configure_file("${CMAKE_SOURCE_DIR}/onak.ini.in" + "${CMAKE_BINARY_DIR}/onak.ini" @ONLY) +install(FILES ${CMAKE_BINARY_DIR}/onak.ini + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) - install(TARGETS keydctl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(TARGETS keyd RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}) - install(FILES keyd.8 keydctl.8 - DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/) -endif() +configure_file("${CMAKE_SOURCE_DIR}/onak-mail.pl.in" + "${CMAKE_BINARY_DIR}/onak-mail.pl" @ONLY) +install(PROGRAMS ${CMAKE_BINARY_DIR}/onak-mail.pl + DESTINATION ${CMAKE_INSTALL_LIBDIR}/onak/) +install(FILES onak-mail.pl.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/) +# Key database backends +add_subdirectory(keydb) # Now we have the DB type confirmed we can tidy up the libonak options if (DBTYPE STREQUAL "dynamic") LIST(APPEND LIBONAK_LIBRARIES "dl") - foreach(BACKEND IN LISTS BACKENDS) - add_library(keydb_${BACKEND} SHARED keydb_${BACKEND}.c) - target_include_directories(keydb_${BACKEND} SYSTEM PUBLIC - ${BACKEND_${BACKEND}_INC}) - target_link_libraries(keydb_${BACKEND} libonak - ${BACKEND_${BACKEND}_LIBS}) - install(TARGETS keydb_${BACKEND} LIBRARY DESTINATION - ${CMAKE_INSTALL_LIBDIR}/onak/backends/) - endforeach(BACKEND) else() list (FIND BACKENDS ${DBTYPE} _index) if (${_index} LESS 0) @@ -127,25 +86,9 @@ target_compile_definitions(libonak PRIVATE DBINIT=keydb_${DBTYPE}_init) # DB Backend related options are known, so finish off libonak configuration -target_sources(libonak PRIVATE keydb_${DBTYPE}.c) +target_sources(libonak PRIVATE keydb/keydb_${DBTYPE}.c) target_link_libraries(libonak ${LIBONAK_LIBRARIES}) -# Build files that have substitutions in them -include_directories(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) -configure_file("${CMAKE_SOURCE_DIR}/build-config.h.in" - "${CMAKE_BINARY_DIR}/build-config.h" @ONLY) - -configure_file("${CMAKE_SOURCE_DIR}/onak.ini.in" - "${CMAKE_BINARY_DIR}/onak.ini" @ONLY) -install(FILES ${CMAKE_BINARY_DIR}/onak.ini - DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) - -configure_file("${CMAKE_SOURCE_DIR}/onak-mail.pl.in" - "${CMAKE_BINARY_DIR}/onak-mail.pl" @ONLY) -install(PROGRAMS ${CMAKE_BINARY_DIR}/onak-mail.pl - DESTINATION ${CMAKE_INSTALL_LIBDIR}/onak/) -install(FILES onak-mail.pl.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/) - # CGI directory add_subdirectory(cgi) diff --git a/keydb/CMakeLists.txt b/keydb/CMakeLists.txt new file mode 100644 index 0000000..35911f6 --- /dev/null +++ b/keydb/CMakeLists.txt @@ -0,0 +1,61 @@ +# Key database backends + +# These have no dependencies and can always be compiled +set(BACKENDS "file" "fs" "keyring" "stacked") + +# DB4 backend (add check for existence) +LIST(APPEND BACKENDS db4) +set(BACKEND_db4_LIBS db-5.3) + +# HKP backend - needs libcurl +pkg_check_modules(CURL libcurl) +if (CURL_FOUND) + LIST(APPEND BACKENDS hkp) + set(BACKEND_hkp_INC ${CURL_INCLUDE_DIRS}) + set(BACKEND_hkp_LIBS ${CURL_LIBRARIES}) +endif() + +# PostgreSQL backend - needs libpq +pkg_check_modules(POSTGRESQL libpq) +if (POSTGRESQL_FOUND) + LIST(APPEND BACKENDS pg) + set(BACKEND_pg_INC ${POSTGRESQL_INCLUDE_DIRS}) + set(BACKEND_pg_LIBS ${POSTGRESQL_LIBRARIES}) +endif() + +# keyd backend - can be disabled entirely +if (KEYD STREQUAL "ON") + LIST(APPEND BACKENDS keyd) + + add_executable(keyd keyd.c) + target_link_libraries(keyd libonak) + add_executable(keydctl keydctl.c ../onak-conf.c) + target_link_libraries(keydctl libonak) + target_compile_definitions(keydctl PRIVATE + CONFIGDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}") + + pkg_check_modules(SYSTEMD libsystemd) + if (SYSTEMD_FOUND) + set(HAVE_SYSTEMD true) + target_include_directories(keyd SYSTEM PUBLIC + ${SYSTEMD_INCLUDE_DIRS}) + target_link_libraries(keyd ${SYSTEMD_LIBRARIES}) + endif() + + install(TARGETS keydctl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(TARGETS keyd RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}) + install(FILES keyd.8 keydctl.8 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/) +endif() + +if (DBTYPE STREQUAL "dynamic") + foreach(BACKEND IN LISTS BACKENDS) + add_library(keydb_${BACKEND} SHARED keydb_${BACKEND}.c) + target_include_directories(keydb_${BACKEND} SYSTEM PUBLIC + ${BACKEND_${BACKEND}_INC}) + target_link_libraries(keydb_${BACKEND} libonak + ${BACKEND_${BACKEND}_LIBS}) + install(TARGETS keydb_${BACKEND} LIBRARY DESTINATION + ${CMAKE_INSTALL_LIBDIR}/onak/backends/) + endforeach(BACKEND) +endif() diff --git a/keyd.8 b/keydb/keyd.8 similarity index 100% rename from keyd.8 rename to keydb/keyd.8 diff --git a/keyd.c b/keydb/keyd.c similarity index 100% rename from keyd.c rename to keydb/keyd.c diff --git a/keyd.h b/keydb/keyd.h similarity index 100% rename from keyd.h rename to keydb/keyd.h diff --git a/keydb.c b/keydb/keydb.c similarity index 100% rename from keydb.c rename to keydb/keydb.c diff --git a/keydb_db4.c b/keydb/keydb_db4.c similarity index 100% rename from keydb_db4.c rename to keydb/keydb_db4.c diff --git a/keydb_dynamic.c b/keydb/keydb_dynamic.c similarity index 100% rename from keydb_dynamic.c rename to keydb/keydb_dynamic.c diff --git a/keydb_file.c b/keydb/keydb_file.c similarity index 100% rename from keydb_file.c rename to keydb/keydb_file.c diff --git a/keydb_fs.c b/keydb/keydb_fs.c similarity index 100% rename from keydb_fs.c rename to keydb/keydb_fs.c diff --git a/keydb_hkp.c b/keydb/keydb_hkp.c similarity index 100% rename from keydb_hkp.c rename to keydb/keydb_hkp.c diff --git a/keydb_keyd.c b/keydb/keydb_keyd.c similarity index 100% rename from keydb_keyd.c rename to keydb/keydb_keyd.c diff --git a/keydb_keyring.c b/keydb/keydb_keyring.c similarity index 100% rename from keydb_keyring.c rename to keydb/keydb_keyring.c diff --git a/keydb_pg.c b/keydb/keydb_pg.c similarity index 100% rename from keydb_pg.c rename to keydb/keydb_pg.c diff --git a/keydb_stacked.c b/keydb/keydb_stacked.c similarity index 100% rename from keydb_stacked.c rename to keydb/keydb_stacked.c diff --git a/keydctl.8 b/keydb/keydctl.8 similarity index 100% rename from keydctl.8 rename to keydb/keydctl.8 diff --git a/keydctl.c b/keydb/keydctl.c similarity index 100% rename from keydctl.c rename to keydb/keydctl.c diff --git a/runtests b/runtests index 6b5b830..3a74d24 100755 --- a/runtests +++ b/runtests @@ -29,8 +29,8 @@ echo "WORKDIR : ${WORKDIR}" fail=0 total=0 -for t in libkeydb_*.so; do - backend=${t##libkeydb_} +for t in keydb/libkeydb_*.so; do + backend=${t##keydb/libkeydb_} backend=${backend%%.so} if [ "`echo ${TESTSDIR}/$backend-*`" != "${TESTSDIR}/$backend-*" ]; then echo "* testing $backend backend" diff --git a/t/test-in.ini b/t/test-in.ini index e40c0e2..7d1b561 100644 --- a/t/test-in.ini +++ b/t/test-in.ini @@ -1,6 +1,6 @@ [main] backend=test-DB -backends_dir=BUILDDIR +backends_dir=BUILDDIR/keydb logfile=onak.log loglevel=7 use_keyd=false -- 2.39.5