tempfile: improve base path selection

The path is not /that/ relevant privacy wise as we try to use
`O_TMPFILE` anyway and defaulting to /run generates trouble for calls
from non-root processes.

Try the user session run dir first, then /run if root or /tmp else.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-10-15 11:23:22 +02:00
parent 9915a41bb6
commit 9cccad5e3e

View File

@ -1587,7 +1587,16 @@ sub tempfile {
# default permissions are stricter than with file_set_contents
$perm = 0600 if !defined($perm);
my $dir = $opts{dir} // '/run';
my $dir = $opts{dir};
if (!$dir) {
if (-d "/run/user/$<") {
$dir = "/run/user/$<";
} elsif ($< == 0) {
$dir = "/run";
} else {
$dir = "/tmp";
}
}
my $mode = $opts{mode} // O_RDWR;
$mode |= O_EXCL if !$opts{allow_links};