Per the systemd tmpfiles implementation, we need to watch out for umask during initial creation of files as well as potentially changing permissions later. Also do not abort if the items exist already, per truncate rules in tmpfiles.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
This commit is contained in:
parent
06b8084b2c
commit
426b94bd69
@ -55,11 +55,17 @@ typedef enum {
|
|||||||
|
|
||||||
extern const char *applet;
|
extern const char *applet;
|
||||||
|
|
||||||
|
/* TODO: SELinux
|
||||||
|
* This needs a LOT of SELinux loving
|
||||||
|
* See systemd's src/label.c:label_mkdir
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
do_check(char *path, uid_t uid, gid_t gid, mode_t mode, inode_t type, bool trunc)
|
do_check(char *path, uid_t uid, gid_t gid, mode_t mode, inode_t type, bool trunc)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int fd, flags;
|
int fd, flags;
|
||||||
|
int r;
|
||||||
|
int u;
|
||||||
|
|
||||||
if (stat(path, &st) || trunc) {
|
if (stat(path, &st) || trunc) {
|
||||||
if (type == inode_file) {
|
if (type == inode_file) {
|
||||||
@ -75,7 +81,10 @@ do_check(char *path, uid_t uid, gid_t gid, mode_t mode, inode_t type, bool trunc
|
|||||||
#endif
|
#endif
|
||||||
if (trunc)
|
if (trunc)
|
||||||
flags |= O_TRUNC;
|
flags |= O_TRUNC;
|
||||||
if ((fd = open(path, flags, mode)) == -1) {
|
u = umask(0);
|
||||||
|
fd = open(path, flags, mode);
|
||||||
|
umask(u);
|
||||||
|
if (fd == -1) {
|
||||||
eerror("%s: open: %s", applet, strerror(errno));
|
eerror("%s: open: %s", applet, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -84,7 +93,11 @@ do_check(char *path, uid_t uid, gid_t gid, mode_t mode, inode_t type, bool trunc
|
|||||||
einfo("%s: creating directory", path);
|
einfo("%s: creating directory", path);
|
||||||
if (!mode) /* 775 */
|
if (!mode) /* 775 */
|
||||||
mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
|
mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
|
||||||
if (mkdir(path, mode) == -1) {
|
u = umask(0);
|
||||||
|
/* We do not recursively create parents */
|
||||||
|
r = mkdir(path, mode);
|
||||||
|
umask(u);
|
||||||
|
if (r == -1 && errno != EEXIST) {
|
||||||
eerror("%s: mkdir: %s", applet,
|
eerror("%s: mkdir: %s", applet,
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -94,7 +107,10 @@ do_check(char *path, uid_t uid, gid_t gid, mode_t mode, inode_t type, bool trunc
|
|||||||
einfo("%s: creating fifo", path);
|
einfo("%s: creating fifo", path);
|
||||||
if (!mode) /* 600 */
|
if (!mode) /* 600 */
|
||||||
mode = S_IRUSR | S_IWUSR;
|
mode = S_IRUSR | S_IWUSR;
|
||||||
if (mkfifo(path, mode) == -1) {
|
u = umask(0);
|
||||||
|
r = mkfifo(path, mode);
|
||||||
|
umask(u);
|
||||||
|
if (r == -1 && errno != EEXIST) {
|
||||||
eerror("%s: mkfifo: %s", applet,
|
eerror("%s: mkfifo: %s", applet,
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user