chiark / gitweb /
util-lib: rework /tmp and /var/tmp handling code
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Jul 2016 15:23:28 +0000 (17:23 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 5 Jul 2017 06:50:49 +0000 (08:50 +0200)
commite4b8356a39a6afcc0b1439397f8c3790332def12
treec001e2bbaa84d072e1c718eedc39a6b1db24f2b7
parent16235f049fb67ba1756aeaab04eff1f1b5b1cf97
util-lib: rework /tmp and /var/tmp handling code

Beef up the existing var_tmp() call, rename it to var_tmp_dir() and add a
matching tmp_dir() call (the former looks for the place for /var/tmp, the
latter for /tmp).

Both calls check $TMPDIR, $TEMP, $TMP, following the algorithm Python3 uses.
All dirs are validated before use. secure_getenv() is used in order to limite
exposure in suid binaries.

This also ports a couple of users over to these new APIs.

The var_tmp() return parameter is changed from an allocated buffer the caller
will own to a const string either pointing into environ[], or into a static
const buffer. Given that environ[] is mostly considered constant (and this is
exposed in the very well-known getenv() call), this should be OK behaviour and
allows us to avoid memory allocations in most cases.

Note that $TMPDIR and friends override both /var/tmp and /tmp usage if set.
src/basic/fileio.c
src/basic/fs-util.c
src/basic/fs-util.h