mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-13 16:16:45 +00:00
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:
parent
9915a41bb6
commit
9cccad5e3e
@ -1587,7 +1587,16 @@ sub tempfile {
|
|||||||
# default permissions are stricter than with file_set_contents
|
# default permissions are stricter than with file_set_contents
|
||||||
$perm = 0600 if !defined($perm);
|
$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;
|
my $mode = $opts{mode} // O_RDWR;
|
||||||
$mode |= O_EXCL if !$opts{allow_links};
|
$mode |= O_EXCL if !$opts{allow_links};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user