diff --git a/doc/news/_preparation_next_release.md b/doc/news/_preparation_next_release.md index ea7fded124d..7f697ba78d8 100644 --- a/doc/news/_preparation_next_release.md +++ b/doc/news/_preparation_next_release.md @@ -112,6 +112,12 @@ The following text lists news about the [plugins](https://www.libelektra.org/plu - <> - <> +### mini + +- Fix a bug where writing meta keys will fail silently _(Juri Schreib @Bujuhu)_ +- <> +- <> + ### mmapstorage - Remove code duplication in the data block calculation _(Richard Stöckl @Eiskasten)_ diff --git a/src/plugins/mini/mini.c b/src/plugins/mini/mini.c index e2dc3d04aaa..801bc85d62f 100644 --- a/src/plugins/mini/mini.c +++ b/src/plugins/mini/mini.c @@ -317,9 +317,37 @@ int elektraMiniGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * par return parseFile (returned, parentKey); } + +static bool elektraCheckForInvalidMetaKey (Key * parentKey, KeySet * ks) +{ + Key * cur = 0; + for (elektraCursor it = 0; it < ksGetSize (ks); ++it) + { + cur = ksAtCursor (ks, it); + const KeySet * metaKeys = keyMeta (cur); + for (elektraCursor jt = 0; jt < ksGetSize (metaKeys); ++jt) + { + // We reach her iff we try to set a metakey. Therefore we should t + const Key * meta = ksAtCursor (metaKeys, jt); + const char * pos = (const char *) keyName (meta); + if (elektraStrNCmp (pos, "meta:/internal/mini", 19) != 0 && elektraStrCmp (pos, "meta:/origname") && elektraStrNCmp (pos, "meta:/rename", 12) != 0 && elektraStrCmp (pos, "meta:/binary") != 0) + { + ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "The mini storage Plugin doesn't support the met key %s", pos); + return false; + } + } + } + return true; +} + /** @see elektraDocSet */ int elektraMiniSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey) { + if (!elektraCheckForInvalidMetaKey (parentKey, returned)) + { + return ELEKTRA_PLUGIN_STATUS_ERROR; + } + ELEKTRA_LOG ("Write configuration data"); int errorNumber = errno; FILE * destination = fopen (keyString (parentKey), "w"); diff --git a/src/plugins/mini/testmod_mini.c b/src/plugins/mini/testmod_mini.c index 7c3e1185c30..503471c8f54 100644 --- a/src/plugins/mini/testmod_mini.c +++ b/src/plugins/mini/testmod_mini.c @@ -113,6 +113,21 @@ static void test_set (void) PLUGIN_CLOSE (); } +static void test_setMetaMustFail (void) +{ + char const * const prefix = "user:/mini/tests/writeMeta"; + + Key * parentKey = keyNew (prefix, KEY_VALUE, elektraFilename (), KEY_END); + KeySet * conf = ksNew (0, KS_END); + KeySet * ks = ksNew (1, keyNew ("user:/mini/tests/writeMeta", KEY_VALUE, "asdf", KEY_META, "asdf", "asdf", KEY_END), KS_END); + + PLUGIN_OPEN ("mini"); + succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "Attempting to write a Meta Key did not fail"); + keyDel (parentKey); + ksDel (ks); + PLUGIN_CLOSE (); +} + /* -- Main ------------------------------------------------------------------------------------------------------------------------------ */ int main (int argc, char ** argv) @@ -125,6 +140,7 @@ int main (int argc, char ** argv) test_basics (); test_get (); test_set (); + test_setMetaMustFail (); print_result ("testmod_mini"); diff --git a/stderr b/stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/stdout b/stdout new file mode 100644 index 00000000000..e69de29bb2d