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

Commit

Permalink
error: Improvements part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ZronekM committed Jun 22, 2019
1 parent 8cc923e commit b06dc27
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/libs/elektra/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int elektraProcessPlugin (Key * cur, int * pluginNumber, char ** pluginName, cha
*pluginNumber = fullname[1] - '0';
if (*pluginNumber > NR_OF_PLUGINS)
{
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Tried to set more plugins than %s (NR_OF_PLUGINS). Pluginname: %s",
ELEKTRA_ADD_INSTALLATION_WARNINGF (errorKey, "Tried to set more plugins than %d (NR_OF_PLUGINS). Pluginname: %s",
NR_OF_PLUGINS, fullname);
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/pluginprocess/pluginprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ 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)
{
ELEKTRA_SET_PLUGIN_MISBEHAVIOR_ERRORF (key, "Received invalid return code or no KeySet from child process: %s", keyString (resultKey));
ELEKTRA_SET_PLUGIN_MISBEHAVIOR_ERRORF (key, "Received invalid return code or no KeySet from child process: %s",
keyString (resultKey));
lresult = ELEKTRA_PLUGIN_STATUS_ERROR;
}
else // Copy everything back into the actual keysets
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/augeas/augeas.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,7 @@ int elektraAugeasGet (Plugin * handle, KeySet * returned, Key * parentKey)
if (!conversionData)
{
fclose (fh);
ELEKTRA_SET_OUT_OF_MEMORY_ERRORF (
parentKey, "Out of memory. Errno: %s",
strerror (errno));
ELEKTRA_SET_OUT_OF_MEMORY_ERRORF (parentKey, "Out of memory. Errno: %s", strerror (errno));
}

conversionData->currentOrder = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/base64/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int decode (Key * key, Key * parent, bool metaMode)
else if (result == -1)
{
// Decoding error
ELEKTRA_ADD_VALIDATION_SYNTACTIC_WARNINGF (parent, "Not Base64 encoded: %s", strVal);
ELEKTRA_ADD_VALIDATION_SYNTACTIC_WARNINGF (parent, "Key %s was not Base64 encoded: %s", keyName (key), strVal);
}
else if (result == -2)
{
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/blockresolver/blockresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int elektraBlockresolverGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
struct stat buf;
if (stat (data->realFile, &buf))
{
ELEKTRA_ADD_RESOURCE_WARNINGF (parentKey, "Failed to stat file %s\n", data->realFile);
ELEKTRA_ADD_RESOURCE_WARNINGF (parentKey, "Failed to stat file %s\n. Reason: %s", data->realFile, strerror (errno));
return -1;
}
if (buf.st_mtime == data->mtime) return 0;
Expand All @@ -264,7 +264,7 @@ int elektraBlockresolverGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
fin = fopen (data->realFile, "r");
if (!fin)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for reading", data->realFile);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for reading. Reason: %s", data->realFile, strerror (errno));
goto GET_CLEANUP;
}

Expand All @@ -289,7 +289,7 @@ int elektraBlockresolverGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
fout = fopen (data->tmpFile, "w");
if (!fout)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for writing", data->tmpFile);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for writing. Reason: %s", data->tmpFile, strerror (errno));
retVal = -1;
goto GET_CLEANUP;
}
Expand All @@ -312,7 +312,7 @@ int elektraBlockresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
struct stat buf;
if (stat (data->realFile, &buf))
{
ELEKTRA_ADD_RESOURCE_WARNINGF (parentKey, "Failed to stat file %s\n", data->realFile);
ELEKTRA_ADD_RESOURCE_WARNINGF (parentKey, "Failed to stat file %s\n. Reason: %s", data->realFile, strerror (errno));
return -1;
}
if (buf.st_mtime > data->mtime)
Expand All @@ -337,13 +337,15 @@ int elektraBlockresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
fout = fopen (mergeFile, "w");
if (!fout)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for writing", data->realFile);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for writing. Reason: %s", data->realFile,
strerror (errno));
goto SET_CLEANUP;
}
fin = fopen (data->realFile, "r");
if (!fin)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for reading", data->realFile);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for reading. Reason: %s", data->realFile,
strerror (errno));
goto SET_CLEANUP;
}
block = (char *) getBlock (fin, 0, data->startPos);
Expand All @@ -367,7 +369,7 @@ int elektraBlockresolverSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned E
fin = fopen (data->tmpFile, "r");
if (!fin)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for reading", data->tmpFile);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open %s for reading Reason: %s", data->tmpFile, strerror (errno));
goto SET_CLEANUP;
}
char buffer[BUFSIZE_MAX];
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/cachefilter/cachefilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ int elektraCachefilterSet (Plugin * handle, KeySet * returned, Key * parentKey)
void * cache = elektraPluginGetData (handle);
if (cache == NULL)
{
ELEKTRA_SET_INSTALLATION_ERROR (parentKey, "Cache was not initialized.");
// TODO: Solution (Call kdbGet() to initialize Cache)
ELEKTRA_SET_INTERFACE_ERROR (parentKey, "Cache was not initialized.");
return -1; // did not call kdbGet() before and therefore
// also no elektraCachefilterGet()
}
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/crypto/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromMetakey) (Key * errorKey, Key * k, kdb_o
const Key * meta = keyGetMeta (k, ELEKTRA_CRYPTO_META_SALT);
if (!meta)
{
ELEKTRA_SET_INTERFACE_ERRORF (errorKey, "Missing salt as metakey %s in key %s", ELEKTRA_CRYPTO_META_SALT, keyName (k));
ELEKTRA_SET_VALIDATION_SEMANTIC_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)
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERROR (errorKey, "Salt was not stored Base64 encoded.");
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "Salt was not stored Base64 encoded in key %s", keyName (k));
return -1;
}
else if (result == -2)
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/curlget/curlget.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ int elektraCurlgetOpen (Plugin * handle, Key * errorKey ELEKTRA_UNUSED)
{
if (!data->password)
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERROR (errorKey, "No password specified for SSH password authentication");
ELEKTRA_SET_VALIDATION_SEMANTIC_ERROR (
errorKey, "No password specified for SSH password authentication in plugin configuration");
if (data->uploadFileName) elektraFree (data->__uploadFileName);
elektraFree (data);
data = NULL;
Expand Down Expand Up @@ -620,7 +621,7 @@ int elektraCurlgetGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA

if (fd == -1)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for reading", data->path);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for reading. Reason: %s", data->path, strerror (errno));
return -1;
}
FILE * fp = fetchFile (data, fd);
Expand All @@ -637,7 +638,7 @@ int elektraCurlgetGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
}
else
{
ELEKTRA_SET_RESOURCE_ERROR (parentKey, "Failed to read configuration\n");
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to read configuration. Reason: %s\n", strerror (errno));
return -1;
}
}
Expand Down Expand Up @@ -762,7 +763,7 @@ int elektraCurlgetSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA
fp = fopen (tmpFile, "rb");
if (!fp)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for reading", tmpFile);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for reading. Reason: %s", tmpFile, strerror (errno));
return -1;
}
fseek (fp, 0L, SEEK_END);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dump/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ int unserialise (std::istream & is, ckdb::Key * errorKey, ckdb::KeySet * ks)
}
else
{
// TODO: Solution
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (
errorKey,
"Unknown command detected in dumpfile: %s.\nMaybe you use a different file format? "
Expand Down
13 changes: 9 additions & 4 deletions src/plugins/fcrypt/fcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ static int shredTemporaryFile (int fd, Key * errorKey)

if (fstat (fd, &tmpStat))
{
ELEKTRA_SET_RESOURCE_ERROR (errorKey, "Failed to retrieve the file status of the temporary file.");
ELEKTRA_SET_RESOURCE_ERRORF (
errorKey,
"Failed to overwrite the temporary data. Cannot retrieve file status Unencrypted data may leak. Errno: %s",
strerror (errno));
return -1;
}

Expand All @@ -146,7 +149,8 @@ static int shredTemporaryFile (int fd, Key * errorKey)
return 1;

error:
ELEKTRA_SET_RESOURCE_ERROR (errorKey, "Failed to overwrite the temporary file.");
ELEKTRA_SET_RESOURCE_ERRORF (errorKey, "Failed to overwrite the temporary data. Unencrypted data may leak. Errno: %s",
strerror (errno));
return -1;
}

Expand Down Expand Up @@ -226,7 +230,8 @@ static int fcryptGpgCallAndCleanup (Key * parentKey, KeySet * pluginConfig, char
// gpg call returned success, overwrite the original file with the gpg payload data
if (rename (tmpFile, keyString (parentKey)) != 0)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Renaming file %s to %s failed.", tmpFile, keyString (parentKey));
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Renaming file %s to %s failed. Reason: %s", tmpFile, keyString (parentKey),
strerror (errno));
result = -1;
}
}
Expand Down Expand Up @@ -572,7 +577,7 @@ int ELEKTRA_PLUGIN_FUNCTION (get) (Plugin * handle, KeySet * ks ELEKTRA_UNUSED,
fcryptState * s = (fcryptState *) elektraPluginGetData (handle);
if (!s)
{
ELEKTRA_SET_PLUGIN_MISBEHAVIOR_ERROR (parentKey, "No plugin state is available.");
ELEKTRA_SET_INSTALLATION_ERROR (parentKey, "No plugin state is available.");
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/file/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ int elektraFileGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UN

if (!buffer)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to allocate buffer of %lld bytes for %s", fileSize, fileName);
ELEKTRA_SET_OUT_OF_MEMORY_ERRORF (parentKey, "Failed to allocate buffer of %lld bytes for %s", fileSize, fileName);
return -1;
}

FILE * fp = NULL;
fp = fopen (fileName, "rb");
if (!fp)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open file %s", fileName);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open file %s. Reason: %s", fileName, strerror (errno));
elektraFree (buffer);
return -1;
}
Expand All @@ -87,7 +87,7 @@ int elektraFileGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UN

if (bytesRead < fileSize)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Failed to read %s completely. got %lld of %lld bytes", fileName,
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Failed to read %s completely. Got %lld of %lld bytes", fileName,
bytesRead, fileSize);
elektraFree (buffer);
fclose (fp);
Expand Down Expand Up @@ -142,7 +142,7 @@ int elektraFileSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UN
fp = fopen (fileName, "wb");
if (!fp)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for writing", fileName);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for writing. Reason: %s", fileName, strerror (errno));
return -1;
}
ssize_t svalueSize = keyGetValueSize (key);
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/filecheck/filecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static long checkFile (Key * parentKey, const char * filename, checkStruct * che
FILE * fp = fopen (filename, "rb");
if (fp == NULL)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open file %s", filename);
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Couldn't open file %s. Reason: %s", filename, strerror (errno));
return -1;
}
iconv_t conv = NULL;
Expand Down Expand Up @@ -246,8 +246,8 @@ static long checkFile (Key * parentKey, const char * filename, checkStruct * che
le_ret = validateLineEnding (line, &(checkConf->validLE), 0);
if (le_ret)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Invalid lineending at position %zd",
bytesRead + le_ret);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Invalid lineending at position %zd in file %s",
bytesRead + le_ret, filename);
retVal = -1;
break;
}
Expand All @@ -257,8 +257,8 @@ static long checkFile (Key * parentKey, const char * filename, checkStruct * che
null_ret = checkNull (line, bytesRead);
if (null_ret)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Found null-byte at position %zd",
bytesRead + null_ret);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Found null-byte at position %zd in file %s",
bytesRead + null_ret, filename);
retVal = -1;
break;
}
Expand All @@ -268,8 +268,8 @@ static long checkFile (Key * parentKey, const char * filename, checkStruct * che
iconv_ret = validateEncoding (line, conv, bytesRead);
if (iconv_ret)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Invalid encoding at position %zd",
bytesRead + iconv_ret);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Invalid encoding at position %zd in file %s",
bytesRead + iconv_ret, filename);
retVal = -1;
break;
}
Expand All @@ -279,7 +279,7 @@ static long checkFile (Key * parentKey, const char * filename, checkStruct * che
bom_ret = checkBom (line);
if (bom_ret)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (parentKey, "Found BOM");
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Found no Byte Order Mark (BOM) in file %s", filename);
retVal = -1;
break;
}
Expand All @@ -290,8 +290,8 @@ static long checkFile (Key * parentKey, const char * filename, checkStruct * che
unprintable_ret = checkUnprintable (line);
if (unprintable_ret)
{
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Unprintable character at position %zd",
bytesRead + unprintable_ret);
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Unprintable character at position %zd in file %s",
bytesRead + unprintable_ret, filename);
retVal = -1;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/gpgme/gpgme.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static int transferGpgmeDataToElektraKey (gpgme_data_t src, Key * dst, Key * err
readCount = gpgme_data_read (src, buffer, ciphertextLen);
if (readCount != ciphertextLen)
{
ELEKTRA_SET_INTERNAL_ERROR (errorKey, "An error during occurred during the data transfer.");
ELEKTRA_SET_INTERNAL_ERRORF (errorKey, "An error during occurred during the data transfer. Reason: %s", strerror (errno));
returnValue = -1; // failure
goto cleanup;
}
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/passwd/passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ int elektraPasswdGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_
FILE * pwfile = fopen (keyString (parentKey), "r");
if (!pwfile)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open configuration file %s\n", keyString (parentKey));
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open configuration file %s. Reason: %s\n", keyString (parentKey),
strerror (errno));
return -1;
}
#if defined(USE_FGETPWENT)
Expand Down Expand Up @@ -296,7 +297,8 @@ static int writeKS (KeySet * returned, Key * parentKey, SortBy index)
FILE * pwfile = fopen (keyString (parentKey), "w");
if (!pwfile)
{
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for writing\n", keyString (parentKey));
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "Failed to open %s for writing\n. Reason: %s", keyString (parentKey),
strerror (errno));
return -1;
}
Key * cur;
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/path/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ static int validatePermission (Key * key, Key * parentKey)
name = p->pw_name;
if (uid != 0)
{
// TODO: Solution
ELEKTRA_SET_RESOURCE_ERRORF (parentKey,
"To check permissions for %s I need to be the root user."
" Are you running kdb as root?\"",
Expand Down Expand Up @@ -266,6 +267,7 @@ static int switchGroup (Key * key, Key * parentKey, const char * name, const str
int gidErr = setegid ((int) gr->gr_gid);
if (gidErr < 0)
{
// TODO: Solution
ELEKTRA_SET_RESOURCE_ERRORF (parentKey,
"Could not set egid of user \"%s\" for key \"%s\"."
" Are you running kdb as root?\"",
Expand All @@ -289,6 +291,7 @@ static int switchUser (Key * key, Key * parentKey, const struct passwd * p)
int err = seteuid ((int) p->pw_uid);
if (err < 0)
{
// TODO: Solution
ELEKTRA_SET_RESOURCE_ERRORF (parentKey,
"Could not set euid of user \"%s\" for key \"%s\"."
" Are you running kdb as root?\"",
Expand Down

0 comments on commit b06dc27

Please sign in to comment.