Skip to content

Commit

Permalink
Merge pull request systemd#30196 from YHNdnzj/fchmodat2-no-symlink
Browse files Browse the repository at this point in the history
Revert "nspawn-patch-uid: try fchmodat2() to restore mode of symlink"
  • Loading branch information
yuwata authored Nov 25, 2023
2 parents 22be476 + 0cdffad commit 8add4a9
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/nspawn/nspawn-patch-uid.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "fileio.h"
#include "fs-util.h"
#include "missing_magic.h"
#include "missing_syscall.h"
#include "nspawn-def.h"
#include "nspawn-patch-uid.h"
#include "stat-util.h"
Expand Down Expand Up @@ -240,18 +239,14 @@ static int patch_fd(int fd, const char *name, const struct stat *st, uid_t shift

/* The Linux kernel alters the mode in some cases of chown(). Let's undo this. */
if (name) {
/* It looks like older glibc (before 2016) did not support AT_SYMLINK_NOFOLLOW. */
if (!S_ISLNK(st->st_mode))
r = RET_NERRNO(fchmodat(fd, name, st->st_mode, 0));
else {
r = RET_NERRNO(fchmodat2(fd, name, st->st_mode, AT_SYMLINK_NOFOLLOW));
if (IN_SET(r, -ENOSYS, -EPERM))
r = 0;
}
r = fchmodat(fd, name, st->st_mode, 0);
else /* Changing the mode of a symlink is not supported by Linux kernel. Don't bother. */
r = 0;
} else
r = RET_NERRNO(fchmod(fd, st->st_mode));
r = fchmod(fd, st->st_mode);
if (r < 0)
return r;
return -errno;

changed = true;
}
Expand Down

0 comments on commit 8add4a9

Please sign in to comment.