Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
fcrypt: consider the environment (TMPDIR) when looking for the tempor…
Browse files Browse the repository at this point in the history
…ary directory

See ElektraInitiative#1973 for further details
  • Loading branch information
petermax2 committed Jun 17, 2018
1 parent 23057d6 commit 3a60db9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Thanks to Michael Zronek and Vanessa Kos.

- The `crypto` plugin now uses Elektra's `libinvoke` and the `base64` plugin in order to encode and decode Base64 strings. This improvement reduces code duplication between the two plugins. *(Peter Nirschl)*

### fcrypt

- The `fcrypt` plugin will consider the environment variable `TMPDIR` in order to detect its temporary directory. See [#1973] *(Peter Nirschl)*

### fstab

- The `fstab` plugin now passes tests on musl builds. *(Lukas Winkler)*
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/fcrypt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ Textmode can be disabled by setting `fcrypt/textmode` to `0` in the plugin confi
### Temporary Directory

`fcrypt` uses the configuration option `fcrypt/tmpdir` to generate paths for temporary files during encryption and decryption.
The path is forwarded to GPG via the `-o` option, so GPG will output to this path.
The directory must be readable and writable by the user.
If no such configuration option is provided, `fcrypt` will try to use the environment variable `TMPDIR`.
If `TMPDIR` is not set in the environment, `/tmp` is used as default directory.

`/tmp` is used as default value.
The path of the temporary directory is forwarded to GPG via the `-o` option, so GPG will output to this path.
The directory must be readable and writable by the user.

We recommend to specify a path that is mounted to a RAM disk.
It is advisable to set restrictive access rules to this path, so that other users on the system can not access it.
15 changes: 14 additions & 1 deletion src/plugins/fcrypt/fcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,26 @@ typedef struct _fcryptState fcryptState;
static char * getTemporaryFileName (KeySet * conf, const char * file, int * fd)
{
// read the temporary directory to use from the plugin configuration
const char * tmpDir = ELEKTRA_FCRYPT_DEFAULT_TMPDIR;
// NOTE the string contained in tmpDir must not be modified!
char * tmpDir = NULL;
Key * k = ksLookupByName (conf, ELEKTRA_FCRYPT_CONFIG_TMPDIR, 0);
if (k)
{
tmpDir = keyString (k);
}

if (!tmpDir)
{
// check the environment; returns NULL if no match is found
tmpDir = getenv ("TMPDIR");
}

if (!tmpDir)
{
// fallback
tmpDir = ELEKTRA_FCRYPT_DEFAULT_TMPDIR;
}

// extract the file name (base name) from the path
char * fileDup = strdup (file);
if (!fileDup) goto error;
Expand Down

0 comments on commit 3a60db9

Please sign in to comment.