diff options
author | Balint Reczey <balint@balintreczey.hu> | 2022-11-10 16:24:06 +0100 |
---|---|---|
committer | Balint Reczey <balint@balintreczey.hu> | 2022-11-10 16:24:06 +0100 |
commit | 3987cc788047570ecf10707dfc8958780d85c73c (patch) | |
tree | 109724175f07436696f51b14b5abbd3f4d704d6d /libmisc/copydir.c | |
parent | 8ead740677d19e48690d4f144ab090b83d47059f (diff) | |
download | shadow-3987cc788047570ecf10707dfc8958780d85c73c.tar.gz |
New upstream version 4.13+dfsg1upstream/4.13+dfsg1upstream
Diffstat (limited to 'libmisc/copydir.c')
-rw-r--r-- | libmisc/copydir.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/libmisc/copydir.c b/libmisc/copydir.c index 5605f6fe..b692aa95 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -126,12 +126,12 @@ static int perm_copy_path(const struct path_info *src, { int src_fd, dst_fd, ret; - src_fd = openat(src->dirfd, src->name, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + src_fd = openat(src->dirfd, src->name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC); if (src_fd < 0) { return -1; } - dst_fd = openat(dst->dirfd, dst->name, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + dst_fd = openat(dst->dirfd, dst->name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC); if (dst_fd < 0) { (void) close (src_fd); return -1; @@ -152,12 +152,12 @@ static int attr_copy_path(const struct path_info *src, { int src_fd, dst_fd, ret; - src_fd = openat(src->dirfd, src->name, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + src_fd = openat(src->dirfd, src->name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC); if (src_fd < 0) { return -1; } - dst_fd = openat(dst->dirfd, dst->name, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + dst_fd = openat(dst->dirfd, dst->name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC); if (dst_fd < 0) { (void) close (src_fd); return -1; @@ -354,12 +354,8 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * old_uid, new_uid, old_gid, new_gid); } - if (NULL != src_name) { - free (src_name); - } - if (NULL != dst_name) { - free (dst_name); - } + free (src_name); + free (dst_name); } } (void) closedir (dir); @@ -522,15 +518,14 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, return -1; } #endif /* WITH_SELINUX */ - if ( (mkdirat (dst->dirfd, dst->name, statp->st_mode) != 0) + if ( (mkdirat (dst->dirfd, dst->name, 0700) != 0) || (chownat_if_needed (dst, statp, old_uid, new_uid, old_gid, new_gid) != 0) + || (fchmodat (dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) != 0) #ifdef WITH_ACL || ( (perm_copy_path (src, dst, &ctx) != 0) && (errno != 0)) -#else /* !WITH_ACL */ - || (chmod (dst, statp->st_mode) != 0) -#endif /* !WITH_ACL */ +#endif /* WITH_ACL */ #ifdef WITH_ATTR /* * If the third parameter is NULL, all extended attributes @@ -719,12 +714,11 @@ static int copy_special (const struct path_info *src, const struct path_info *ds if ( (mknodat (dst->dirfd, dst->name, statp->st_mode & ~07777U, statp->st_rdev) != 0) || (chownat_if_needed (dst, statp, old_uid, new_uid, old_gid, new_gid) != 0) + || (fchmodat (dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) != 0) #ifdef WITH_ACL || ( (perm_copy_path (src, dst, &ctx) != 0) && (errno != 0)) -#else /* !WITH_ACL */ - || (fchmodat (dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) != 0) -#endif /* !WITH_ACL */ +#endif /* WITH_ACL */ #ifdef WITH_ATTR /* * If the third parameter is NULL, all extended attributes @@ -810,16 +804,15 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, return -1; } #endif /* WITH_SELINUX */ - ofd = openat (dst->dirfd, dst->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, statp->st_mode & 07777); + ofd = openat (dst->dirfd, dst->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); if ( (ofd < 0) || (fchown_if_needed (ofd, statp, old_uid, new_uid, old_gid, new_gid) != 0) + || (fchmod (ofd, statp->st_mode & 07777) != 0) #ifdef WITH_ACL || ( (perm_copy_fd (src->full_path, ifd, dst->full_path, ofd, &ctx) != 0) && (errno != 0)) -#else /* !WITH_ACL */ - || (fchmod (ofd, statp->st_mode & 07777) != 0) -#endif /* !WITH_ACL */ +#endif /* WITH_ACL */ #ifdef WITH_ATTR /* * If the third parameter is NULL, all extended attributes |