Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
error: added unsure cateogisation Todos
Browse files Browse the repository at this point in the history
  • Loading branch information
ZronekM committed Jun 22, 2019
1 parent 42d7def commit 7f3c92c
Show file tree
Hide file tree
Showing 46 changed files with 128 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/bindings/cpp/include/kdbplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Delegator
catch (const char * msg)
{
#ifdef KDBERRORS_H
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Could not create C++ plugin: %s", msg);
#endif
return -1;
Expand Down
1 change: 1 addition & 0 deletions src/libs/elektra/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Backend * backendOpen (KeySet * elektraConfig, KeySet * modules, KeySet * global
{
// no one cares about that config
if (!failure)
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Unrecognised Config Tree: %s", keyBaseName (cur));
ksDel (cut);
}
Expand Down
7 changes: 7 additions & 0 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
if (splitBuildup (split, handle, parentKey) == -1)
{
clearError (parentKey);
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERROR (parentKey, "error in splitBuildup");
goto error;
}
Expand Down Expand Up @@ -1075,6 +1076,7 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)

if (splitGet (split, parentKey, handle) == -1)
{
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (parentKey, "Wrong keys in postprocessing: %s", keyName (ksCurrent (ks)));
// continue, because sizes are already updated
}
Expand Down Expand Up @@ -1110,6 +1112,7 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
/* Now post-process the updated keysets */
if (splitGet (split, parentKey, handle) == -1)
{
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (parentKey, "Wrong keys in postprocessing: %s", keyName (ksCurrent (ks)));
// continue, because sizes are already updated
}
Expand Down Expand Up @@ -1426,6 +1429,7 @@ int kdbSet (KDB * handle, KeySet * ks, Key * parentKey)
if (ns == KEY_NS_META)
{
clearError (parentKey); // clear previous error to set new one
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (parentKey, "metakey with name \"%s\" passed to kdbSet", keyName (parentKey));
keyDel (oldError);
ELEKTRA_LOG ("ns == KEY_NS_META");
Expand Down Expand Up @@ -1497,6 +1501,7 @@ int kdbSet (KDB * handle, KeySet * ks, Key * parentKey)
}
else if (syncstate < -1)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (parentKey,
"Sync state is wrong, maybe kdbSet() is executed without prior kdbGet() on %s",
keyName (split->parents[-syncstate - 2]));
Expand Down Expand Up @@ -1945,6 +1950,7 @@ int kdbEnsure (KDB * handle, KeySet * contract, Key * parentKey)

if (elektraStrCmp (pluginName, "list") == 0)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERROR (parentKey, "Cannot specify clauses for the list plugin!!");
keyDel (cutpoint);
ksDel (pluginsContract);
Expand All @@ -1966,6 +1972,7 @@ int kdbEnsure (KDB * handle, KeySet * contract, Key * parentKey)
}
else
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (
parentKey,
"The key '%s' contained the value '%s', but only 'unmounted', 'mounted' or 'remounted' may be used.",
Expand Down
1 change: 1 addition & 0 deletions src/libs/elektra/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ int elektraProcessPlugins (Plugin ** plugins, KeySet * modules, KeySet * referen
}
else
{
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Unknown additional entries in plugin: %s", keyString (cur));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libs/elektra/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ static void elektraDropCurrentKey (KeySet * ks, Key * warningKey, const Backend
}
strcat (warningMsg, "\" because ");
strcat (warningMsg, msg);
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (warningKey, "Postcondition of backend was violated: %s", warningMsg);
elektraFree (warningMsg);
cursor_t c = ksGetCursor (ks);
Expand Down
5 changes: 4 additions & 1 deletion src/libs/loader/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ elektraPluginFactory elektraModulesLoad (KeySet * modules, const char * name, Ke
module.symbol.v = dlsym (module.handle, "elektraPluginSymbol");
if (module.symbol.v == NULL)
{
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "could not get pointer to factory, dlsym failed. Module: %s, because: %s",
moduleName, dlerror ());
dlclose (module.handle);
Expand All @@ -119,7 +120,8 @@ int elektraModulesClose (KeySet * modules, Key * errorKey)

if (!root)
{
ELEKTRA_ADD_RESOURCE_WARNING (errorKey, "no key system/elektra/modules");
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNING (errorKey, "no key system/elektra/modules");
return -1;
}

Expand All @@ -135,6 +137,7 @@ int elektraModulesClose (KeySet * modules, Key * errorKey)
ksAppendKey (newModules, root);
}
ret = -1;
// TODO: Correct?
ELEKTRA_ADD_RESOURCE_WARNINGF (errorKey, "Could not close a module, dlclose failed: %s", dlerror ());

ksAppendKey (newModules, cur);
Expand Down
2 changes: 2 additions & 0 deletions src/libs/pluginprocess/pluginprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void elektraPluginProcessStart (Plugin * handle, ElektraPluginProcess * pp)
else
{
ELEKTRA_LOG_DEBUG ("Child: Unrecognized command %s", keyString (commandKey));
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (key, "Received invalid command code or no KeySet: %s", keyString (commandKey));
}
errno = prevErrno;
Expand Down Expand Up @@ -329,6 +330,7 @@ int elektraPluginProcessSend (const ElektraPluginProcess * pp, pluginprocess_t c
long lresult = strtol (keyString (resultKey), &endPtr, 10);
if (*endPtr != '\0' || errno == ERANGE || lresult > INT_MAX || lresult < INT_MIN)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (key, "Received invalid return code or no KeySet: %s", keyString (resultKey));
lresult = ELEKTRA_PLUGIN_STATUS_ERROR;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/augeas/augeas.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int elektraAugeasGenConf (KeySet * ks, Key * errorKey ELEKTRA_UNUSED)
}
else
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Could not glob %s", f);
retval = -1;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/cpptemplate/cpptemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ int elektraCppTemplateOpen (Plugin * handle, Key * key)
}
catch (exception const & error)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (key, "Uncaught Exception: %s", error.what ());
}

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/crypto/botan_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
}
catch (std::exception const & e)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to create a cryptographic key for encryption because: %s", e.what ());
return -1;
}
Expand Down Expand Up @@ -139,6 +140,7 @@ static int getKeyIvForDecryption (KeySet * config, Key * errorKey, Key * masterK
}
catch (std::exception const & e)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to restore the cryptographic key for decryption because: %s", e.what ());
return -1;
}
Expand All @@ -152,7 +154,7 @@ int elektraCryptoBotanInit (Key * errorKey)
}
catch (std::exception const & e)
{
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Botan initialization failed: %s", e.what ());
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Botan initialization failed: %s", e.what ());
return -1; // failure
}
return 1; // success
Expand Down Expand Up @@ -308,6 +310,7 @@ int elektraCryptoBotanDecrypt (KeySet * pluginConfig, Key * k, Key * errorKey, K
}
catch (std::exception const & e)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Decryption failed because: %s", e.what ());
return -1; // failure
}
Expand Down Expand Up @@ -338,6 +341,7 @@ char * elektraCryptoBotanCreateRandomString (Key * errorKey, const kdb_unsigned_
}
catch (std::exception const & e)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to generate random string because: %s", e.what ());
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static int checkPayloadVersion (Key * k, Key * errorKey)
const size_t versionOffset = ELEKTRA_CRYPTO_MAGIC_NUMBER_LEN - 2;
if (memcmp (&value[versionOffset], ELEKTRA_CRYPTO_PAYLOAD_VERSION, 2))
{
// TODO: Correct?
ELEKTRA_SET_PARSING_ERRORF (
errorKey, "The version of the cryptographic payload is not compatible with the version of the plugin. Keyname: %s",
keyName (k));
Expand Down Expand Up @@ -157,6 +158,7 @@ static kdb_unsigned_short_t elektraCryptoGetRandomPasswordLength (Key * errorKey
}
else
{
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNING (errorKey,
"Master password length provided at " ELEKTRA_CRYPTO_PARAM_MASTER_PASSWORD_LEN
" is invalid. Using default value instead.");
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/crypto/gcrypt_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
if ((gcry_err = gcry_kdf_derive (keyValue (masterKey), keyGetValueSize (masterKey), GCRY_KDF_PBKDF2, GCRY_MD_SHA512, salt,
sizeof (salt), iterations, KEY_BUFFER_SIZE, keyBuffer)))
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to create a cryptographic key for encryption because: %s",
gcry_strerror (gcry_err));
return -1;
Expand Down Expand Up @@ -233,6 +234,7 @@ int elektraCryptoGcryHandleCreate (elektraCryptoHandle ** handle, KeySet * confi
error:
memset (keyBuffer, 0, sizeof (keyBuffer));
memset (ivBuffer, 0, sizeof (ivBuffer));
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to create handle because: %s", gcry_strerror (gcry_err));
gcry_cipher_close (**handle);
elektraFree (*handle);
Expand Down Expand Up @@ -316,6 +318,7 @@ int elektraCryptoGcryEncrypt (elektraCryptoHandle * handle, Key * k, Key * error
gcry_err = gcry_cipher_encrypt (*handle, current, ELEKTRA_CRYPTO_GCRY_BLOCKSIZE, NULL, 0);
if (gcry_err != 0)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption failed because: %s", gcry_strerror (gcry_err));
memset (output, 0, outputLen);
elektraFree (output);
Expand All @@ -331,6 +334,7 @@ int elektraCryptoGcryEncrypt (elektraCryptoHandle * handle, Key * k, Key * error
gcry_err = gcry_cipher_encrypt (*handle, current, dataLen, NULL, 0);
if (gcry_err != 0)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption failed because: %s", gcry_strerror (gcry_err));
memset (output, 0, outputLen);
elektraFree (output);
Expand Down Expand Up @@ -365,7 +369,7 @@ int elektraCryptoGcryDecrypt (elektraCryptoHandle * handle, Key * k, Key * error
// plausibility check
if (payloadLen % ELEKTRA_CRYPTO_GCRY_BLOCKSIZE != 0)
{
ELEKTRA_SET_LOGICAL_ERROR (errorKey, "value length is not a multiple of the block size");
ELEKTRA_SET_PARSING_ERROR (errorKey, "value length is not a multiple of the block size");
return -1;
}

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/crypto/gpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int isExecutable (const char * file, Key * errorKey)
{
if (errorKey)
{
ELEKTRA_SET_RESOURCE_ERRORF (errorKey, "gpg binary %s not found", file);
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "gpg binary %s not found", file);
}
return -1;
}
Expand Down Expand Up @@ -658,6 +658,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK
{
case -1:
// fork() failed
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "fork failed");
closePipe (pipe_stdin);
closePipe (pipe_stdout);
Expand Down Expand Up @@ -718,6 +719,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK
{
if (write (pipe_stdin[1], keyValue (msgKey), sendMessageSize) != sendMessageSize)
{
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "The communication with the GPG process failed.");
closePipe (pipe_stdin);
closePipe (pipe_stdout);
Expand Down Expand Up @@ -748,6 +750,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK

case 1:
// bad signature
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "GPG reported a bad signature");
break;

Expand All @@ -774,6 +777,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK
{
errorBuffer[0] = '\0';
}
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "GPG failed with return value %d. %s", status, errorBuffer);
break;
}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/crypto/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromMetakey) (Key * errorKey, Key * k, kdb_o
const Key * meta = keyGetMeta (k, ELEKTRA_CRYPTO_META_SALT);
if (!meta)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "missing salt as metakey %s in key %s", ELEKTRA_CRYPTO_META_SALT, keyName (k));
return -1;
}

int result = ELEKTRA_PLUGIN_FUNCTION (base64Decode) (errorKey, keyString (meta), salt, &saltLenInternal);
if (result == -1)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERROR (errorKey, "Salt was not stored Base64 encoded.");
return -1;
}
Expand Down Expand Up @@ -154,6 +156,7 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromPayload) (Key * errorKey, Key * k, kdb_o
// validate payload length
if ((size_t) payloadLen < sizeof (size_t) || payloadLen < 0)
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "payload is too small to contain a salt (payload length is: %zu)", payloadLen);
if (salt) *salt = NULL;
return -1;
Expand All @@ -170,6 +173,7 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromPayload) (Key * errorKey, Key * k, kdb_o
// validate restored salt length
if (restoredSaltLen < 1 || restoredSaltLen > (payloadLen - headerLen))
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "restored salt has invalid length of %u (payload length is: %zu)", restoredSaltLen,
payloadLen);
if (salt) *salt = NULL;
Expand All @@ -193,7 +197,7 @@ Key * ELEKTRA_PLUGIN_FUNCTION (getMasterPassword) (Key * errorKey, KeySet * conf
Key * master = ksLookupByName (config, ELEKTRA_CRYPTO_PARAM_MASTER_PASSWORD, 0);
if (!master)
{
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "missing %s in plugin configuration", ELEKTRA_CRYPTO_PARAM_MASTER_PASSWORD);
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "missing %s in plugin configuration", ELEKTRA_CRYPTO_PARAM_MASTER_PASSWORD);
return NULL;
}
Key * msg = keyDup (master);
Expand Down Expand Up @@ -223,6 +227,7 @@ kdb_unsigned_long_t ELEKTRA_PLUGIN_FUNCTION (getIterationCount) (Key * errorKey,
}
else
{
// TODO: Correct?
ELEKTRA_ADD_INSTALLATION_WARNING (errorKey, "iteration count provided at " ELEKTRA_CRYPTO_PARAM_ITERATION_COUNT
" is invalid. Using default value instead.");
}
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/crypto/openssl_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
pthread_mutex_lock (&mutex_ssl);
if (!RAND_bytes (salt, ELEKTRA_CRYPTO_DEFAULT_SALT_LEN - 1))
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "failed to generate random salt with error code %lu", ERR_get_error ());
pthread_mutex_unlock (&mutex_ssl);
return -1;
Expand Down Expand Up @@ -87,6 +88,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
if (!PKCS5_PBKDF2_HMAC_SHA1 (keyValue (masterKey), keyGetValueSize (masterKey), salt, sizeof (salt), iterations, KEY_BUFFER_SIZE,
keyBuffer))
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey,
"Failed to create a cryptographic key for encryption. Libcrypto returned error code: %lu",
ERR_get_error ());
Expand Down Expand Up @@ -133,6 +135,7 @@ static int getKeyIvForDecryption (KeySet * config, Key * errorKey, Key * masterK
if (!PKCS5_PBKDF2_HMAC_SHA1 (keyValue (masterKey), keyGetValueSize (masterKey), saltBuffer, saltBufferLen, iterations,
KEY_BUFFER_SIZE, keyBuffer))
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (
errorKey, "Failed to restore the cryptographic key for decryption. Libcrypto returned the error code: %lu",
ERR_get_error ());
Expand Down Expand Up @@ -207,6 +210,7 @@ int elektraCryptoOpenSSLHandleCreate (elektraCryptoHandle ** handle, KeySet * co
{
keyDel (key);
keyDel (iv);
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERROR (errorKey, "Failed to create handle! Invalid IV length.");
return -1;
}
Expand Down Expand Up @@ -239,6 +243,7 @@ int elektraCryptoOpenSSLHandleCreate (elektraCryptoHandle ** handle, KeySet * co

if (ERR_peek_error ())
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to create handle! libcrypto error code was: %lu", ERR_get_error ());
elektraFree (*handle);
*handle = NULL;
Expand Down Expand Up @@ -387,6 +392,7 @@ int elektraCryptoOpenSSLEncrypt (elektraCryptoHandle * handle, Key * k, Key * er
return 1;

error:
// TODO: Correct?
ELEKTRA_SET_INSTALLATION_ERRORF (errorKey, "Encryption error! libcrypto error code was: %lu", ERR_get_error ());
BIO_free_all (encrypted);
pthread_mutex_unlock (&mutex_ssl);
Expand Down Expand Up @@ -502,6 +508,7 @@ int elektraCryptoOpenSSLDecrypt (elektraCryptoHandle * handle, Key * k, Key * er
return 1;

error:
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Decryption error! libcrypto error code was: %lu", ERR_get_error ());
BIO_free_all (decrypted);
pthread_mutex_unlock (&mutex_ssl);
Expand All @@ -521,6 +528,7 @@ char * elektraCryptoOpenSSLCreateRandomString (Key * errorKey, const kdb_unsigne
pthread_mutex_lock (&mutex_ssl);
if (!RAND_bytes (buffer, length))
{
// TODO: Correct?
ELEKTRA_SET_LOGICAL_ERRORF (errorKey, "Failed to generate random string. libcrypto error code was: %lu", ERR_get_error ());
pthread_mutex_unlock (&mutex_ssl);
return NULL;
Expand Down
Loading

0 comments on commit 7f3c92c

Please sign in to comment.