Permalink
Browse files

Merge pull request #2368 from kodebach/2352

KDB_DB_SPEC improvements
  • Loading branch information...
markus2330 committed Feb 7, 2019
2 parents 921f063 + ba4a1d3 commit a1c8e9307671e2ce790cb4be35c422a74ef60ba9
@@ -67,6 +67,16 @@ set (SO_VERSION_GETENV 0)
# needs version above
include (cmake/ElektraPackaging.cmake)

# ensure KDB_DB_SYSTEM is an absolute path
if (NOT IS_ABSOLUTE "${KDB_DB_SYSTEM}")
set (KDB_DB_SYSTEM "${CMAKE_INSTALL_PREFIX}/${KDB_DB_SYSTEM}")
endif ()

# process KDB_DB_SPEC so it is available everywhere
if (NOT IS_ABSOLUTE "${KDB_DB_SPEC}")
set (KDB_DB_SPEC "${CMAKE_INSTALL_PREFIX}/${KDB_DB_SPEC}")
endif ()

# now add all directories
add_subdirectory (cmake)

@@ -109,7 +109,7 @@ set (TOOLS
set (KDB_DB_SYSTEM
"/etc/kdb"
CACHE STRING
"The path to the system key database.")
"The path to the system key database. Relative paths are append to CMAKE_INSTALL_PREFIX.")

set (KDB_DB_HOME
"/home"
@@ -84,22 +84,28 @@ function (add_plugintest testname)
"${MULTI_VALUE_KEYWORDS}" # multi value keywords
${ARGN})

if (ARG_LINK_PLUGIN)
set (testplugin "${ARG_LINK_PLUGIN}")
else (ARG_LINK_PLUGIN)
set (testplugin "${testname}")
endif (ARG_LINK_PLUGIN)

list (FIND ADDED_PLUGINS
"${testname}"
"${testplugin}"
FOUND_NAME)
if (FOUND_NAME EQUAL -1)
if (NOT ARG_LINK_PLUGIN)
message (
FATAL_ERROR
"Trying to add plugintest ${testname} but no such plugin was added (try to use LINK_PLUGIN)"
"Trying to add plugintest ${testplugin} but no such plugin was added (try to use LINK_PLUGIN)"
)
endif ()

# plugin for test was not added in previous phase or removed because of missing deps, exit quietly
return ()
endif ()

set (PLUGIN_NAME elektra-${testname})
set (PLUGIN_NAME elektra-${testplugin})
restore_variable (${PLUGIN_NAME} ARG_LINK_LIBRARIES)
restore_variable (${PLUGIN_NAME} ARG_COMPILE_DEFINITIONS)
restore_variable (${PLUGIN_NAME} ARG_INCLUDE_DIRECTORIES)
@@ -138,6 +138,10 @@ The new plugin [YAy PEG](https://www.libelektra.org/plugins/yaypeg) parses a sub
- [`resolver`](https://www.libelektra.org/plugins/resolver)

reported on FreeBSD. *(René Schwaiger)*
- The [`resolver` plugin](/src/plugins/resolver) and its tests now better support `KDB_DB_SYSTEM` and `KDB_DB_SPEC` paths
using `~` to refer to a home directory. *(Klemens Böswirth)*
- If `KDB_DB_SYSTEM` is set to a relative path, it is now treated as relative to `CMAKE_INSTALL_PREFIX`. This ensures that
`KDB_DB_SYSTEM` actually points to the same location no matter the current working directory. *(Klemens Böswirth)*

## Libraries

@@ -61,9 +61,6 @@ else (ENABLE_ASAN)
set (ELEKTRA_NO_SANITIZE_UNDEFINED "")
endif (ENABLE_ASAN)

set (BUILTIN_SPEC_FOLDER "${CMAKE_INSTALL_PREFIX}/${KDB_DB_SPEC}")
set (BUILTIN_SPEC_REAL_FOLDER "${KDB_DB_SPEC}")

if (ENABLE_OPTIMIZATIONS)
set (ELEKTRA_ENABLE_OPTIMIZATIONS "1")
endif (ENABLE_OPTIMIZATIONS)
@@ -21,9 +21,8 @@
#define KDB_DB_USER "@KDB_DB_USER@"

/** Prefix to search specification configuration (spec/). */
#define KDB_DB_SPEC "@BUILTIN_SPEC_FOLDER@"
#define KDB_DB_SPEC "@KDB_DB_SPEC@"

#define KDB_DB_SPEC_REAL "@BUILTIN_SPEC_REAL_FOLDER@"
/** The folder to add for directory namespace */
#define KDB_DB_DIR "@KDB_DB_DIR@"

@@ -533,29 +533,27 @@ static int elektraResolveSpec (ElektraResolved * handle, ElektraResolveTempfile
return -1;
}
}
else if (KDB_DB_SPEC[0] == '~')
{
char * oldPath = handle->relPath;
char * path = elektraMalloc (filenameSize);
strcpy (path, KDB_DB_SPEC);
strcat (path, "/");
strcat (path, handle->relPath);
handle->relPath = path;
elektraResolveSystemPasswd (handle, warningsKey);
elektraFree (path);
handle->relPath = oldPath;
}
else
{
if (KDB_DB_SPEC_REAL[0] == '~')
{
char * oldPath = handle->relPath;
char * path = elektraMalloc (filenameSize);
strcpy (path, KDB_DB_SPEC_REAL);
strcat (path, "/");
strcat (path, handle->relPath);
handle->relPath = path;
elektraResolveSystemPasswd (handle, warningsKey);
elektraFree (path);
handle->relPath = oldPath;
}
else
{
char * path = elektraMalloc (filenameSize);
strcpy (path, KDB_DB_SPEC);
strcat (path, "/");
strcat (path, handle->relPath);
handle->fullPath = path;
}
char * path = elektraMalloc (filenameSize);
strcpy (path, KDB_DB_SPEC);
strcat (path, "/");
strcat (path, handle->relPath);
handle->fullPath = path;
}

elektraResolveFinishByFilename (handle, tmpDir);
return 1;
}
@@ -54,7 +54,17 @@ void test_resolve (void)
resolverHandles * h = elektraPluginGetData (plugin);
exit_if_fail (h != 0, "no plugin handle");
succeed_if_same_string (h->system.path, "elektra.ecf");
succeed_if_same_string (h->system.filename, KDB_DB_SYSTEM "/elektra.ecf");
if (KDB_DB_SYSTEM[0] == '~')
{
// only check filename and issue warning
const char * lastSlash = strrchr (h->system.filename, '/');
warn_if_fail (0, "using home based KDB_DB_SYSTEM falls back to less strict testing");
succeed_if (lastSlash != NULL && strcmp (lastSlash, "/elektra.ecf") == 0, "wrong filename with home based KDB_DB_SYSTEM");
}
else
{
succeed_if_same_string (h->system.filename, KDB_DB_SYSTEM "/elektra.ecf");
}
succeed_if_same_string (h->user.path, "elektra.ecf");
succeed_if_same_string (h->user.filename, path);
plugin->kdbClose (plugin, parentKey);
@@ -64,7 +74,17 @@ void test_resolve (void)
h = elektraPluginGetData (plugin);
exit_if_fail (h != 0, "no plugin handle");
succeed_if_same_string (h->system.path, "elektra.ecf");
succeed_if_same_string (h->system.filename, KDB_DB_SYSTEM "/elektra.ecf");
if (KDB_DB_SYSTEM[0] == '~')
{
// only check filename and issue warning
const char * lastSlash = strrchr (h->system.filename, '/');
warn_if_fail (0, "using home based KDB_DB_SYSTEM falls back to less strict testing");
succeed_if (lastSlash != NULL && strcmp (lastSlash, "/elektra.ecf") == 0, "wrong filename with home based KDB_DB_SYSTEM");
}
else
{
succeed_if_same_string (h->system.filename, KDB_DB_SYSTEM "/elektra.ecf");
}
succeed_if (h->user.filename == NULL, "user was initialized, but is not needed");
plugin->kdbClose (plugin, parentKey);

@@ -104,7 +124,17 @@ void test_name (void)

Key * parentKey = keyNew ("system", KEY_END);
plugin->kdbGet (plugin, 0, parentKey);
succeed_if_same_string (keyString (parentKey), KDB_DB_SYSTEM "/elektra.ecf");
if (KDB_DB_SYSTEM[0] == '~')
{
// only check filename and issue warning
const char * lastSlash = strrchr (keyString (parentKey), '/');
warn_if_fail (0, "using home based KDB_DB_SYSTEM falls back to less strict testing");
succeed_if (lastSlash != NULL && strcmp (lastSlash, "/elektra.ecf") == 0, "wrong filename with home based KDB_DB_SYSTEM");
}
else
{
succeed_if_same_string (keyString (parentKey), KDB_DB_SYSTEM "/elektra.ecf");
}

keyDel (parentKey);
elektraPluginClose (plugin, 0);
@@ -141,7 +171,19 @@ void test_lockname (void)

Key * parentKey = keyNew ("system", KEY_END);
plugin->kdbGet (plugin, 0, parentKey);
succeed_if (h && !strcmp (h->system.dirname, KDB_DB_SYSTEM), "resulting filename not correct");
if (h && KDB_DB_SYSTEM[0] == '~')
{
// issue warning and then only check if dirname ends with the user-independent part of KDB_DB_SYSTEM
const char * firstSlash = strchr (KDB_DB_SYSTEM, '/');
warn_if_fail (0, "using home based KDB_DB_SYSTEM falls back to less strict testing");
succeed_if (firstSlash == NULL ||
strcmp (h->system.dirname + strlen (h->system.dirname) - strlen (firstSlash), firstSlash) == 0,
"resulting filename not correct with home based KDB_DB_SYSTEM");
}
else
{
succeed_if (h && !strcmp (h->system.dirname, KDB_DB_SYSTEM), "resulting filename not correct");
}

keyDel (parentKey);
elektraPluginClose (plugin, 0);
@@ -178,8 +220,20 @@ void test_tempname (void)

Key * parentKey = keyNew ("system", KEY_END);
plugin->kdbGet (plugin, 0, parentKey);
succeed_if (h && !strncmp (h->system.tempfile, KDB_DB_SYSTEM "/elektra.ecf", sizeof (KDB_DB_SYSTEM)),
"resulting filename not correct");
if (h && KDB_DB_SYSTEM[0] == '~')
{
// only check filename and issue warning
const char * lastSlash = strrchr (h->system.tempfile, '/');
warn_if_fail (0, "using home based KDB_DB_SYSTEM falls back to less strict testing");
succeed_if (lastSlash != NULL && !strncmp (lastSlash, "/elektra.ecf", sizeof ("/elektra.ecf") - 1),
"resulting filename not correct with home based KDB_DB_SYSTEM");
}
else
{
succeed_if (h && !strncmp (h->system.tempfile, KDB_DB_SYSTEM "/elektra.ecf", sizeof (KDB_DB_SYSTEM "/elektra.ecf") - 1),
"resulting filename not correct");
}


keyDel (parentKey);
elektraPluginClose (plugin, 0);
@@ -147,7 +147,7 @@ fi # end of XDG tests

export ALLUSERSPROFILE="/C"
check_resolver spec w /app/config_file /C/app/config_file
check_resolver spec w app/config_file /C@CMAKE_INSTALL_PREFIX@/@KDB_DB_SPEC@/app/config_file
check_resolver spec w app/config_file /C@KDB_DB_SPEC@/app/config_file
check_resolver system w /app/config_file /C/app/config_file
check_resolver system w app/config_file /C@KDB_DB_SYSTEM@/app/config_file
unset ALLUSERSPROFILE
@@ -165,13 +165,17 @@ check_resolver dir w a $TMPPATH/a #@KDB_DB_DIR@ not impl
check_resolver dir w a/b $TMPPATH/a/b #@KDB_DB_DIR@ not impl
cd "$OD"

check_resolver system b x @KDB_DB_SYSTEM@/x
check_resolver system b x/a @KDB_DB_SYSTEM@/x/a
# resolve ~ in paths
SYSTEM_DIR=$(echo @KDB_DB_SYSTEM@)
SPEC_DIR=$(echo @KDB_DB_SPEC@)

check_resolver system b x "$SYSTEM_DIR/x"
check_resolver system b x/a "$SYSTEM_DIR/x/a"
check_resolver system b /a /a
check_resolver system b /a/b/c /a/b/c

check_resolver spec b x @CMAKE_INSTALL_PREFIX@/@KDB_DB_SPEC@/x
check_resolver spec b x/a @CMAKE_INSTALL_PREFIX@/@KDB_DB_SPEC@/x/a
check_resolver spec b x "$SPEC_DIR/x"
check_resolver spec b x/a "$SPEC_DIR/x/a"
check_resolver spec b /x /x
check_resolver spec b /x/a /x/a

@@ -183,11 +187,16 @@ check_resolver user b /a @KDB_DB_HOME@/a
export HOME=""
export USER=""

check_resolver system b x @KDB_DB_SYSTEM@/x
check_resolver system b x/a @KDB_DB_SYSTEM@/x/a
check_resolver system b x "$SYSTEM_DIR/x"
check_resolver system b x/a "$SYSTEM_DIR/x/a"
check_resolver system b /a /a
check_resolver system b /a/b/c /a/b/c

check_resolver spec b x "$SPEC_DIR/x"
check_resolver spec b x/a "$SPEC_DIR/x/a"
check_resolver spec b /x /x
check_resolver spec b /x/a /x/a

check_resolver user b x @KDB_DB_HOME@/@KDB_DB_USER@/x
check_resolver user b x/a @KDB_DB_HOME@/@KDB_DB_USER@/x/a
check_resolver user b /a @KDB_DB_HOME@/a
Oops, something went wrong.

0 comments on commit a1c8e93

Please sign in to comment.