diff options
author | Balint Reczey <balint@balintreczey.hu> | 2021-11-07 15:18:49 +0100 |
---|---|---|
committer | Balint Reczey <balint@balintreczey.hu> | 2021-11-07 15:18:49 +0100 |
commit | 749c1780621163ca5108f164861324bafa9e0ae8 (patch) | |
tree | 51001872624a692018c45bf39276df94b603fb19 /libmisc/copydir.c | |
parent | d906ecd3b652d95af6ffb974a2f6669501bb9496 (diff) | |
download | shadow-749c1780621163ca5108f164861324bafa9e0ae8.tar.gz |
New upstream version 4.9upstream/4.9
Diffstat (limited to 'libmisc/copydir.c')
-rw-r--r-- | libmisc/copydir.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/libmisc/copydir.c b/libmisc/copydir.c index e6aac6ec..015e1b68 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -125,11 +125,11 @@ static void error_acl (struct error_context *ctx, const char *fmt, ...) } va_start (ap, fmt); - (void) fprintf (stderr, _("%s: "), Prog); - if (vfprintf (stderr, fmt, ap) != 0) { - (void) fputs (_(": "), stderr); + (void) fprintf (shadow_logfd, _("%s: "), Prog); + if (vfprintf (shadow_logfd, fmt, ap) != 0) { + (void) fputs (_(": "), shadow_logfd); } - (void) fprintf (stderr, "%s\n", strerror (errno)); + (void) fprintf (shadow_logfd, "%s\n", strerror (errno)); va_end (ap); } @@ -248,7 +248,7 @@ int copy_tree (const char *src_root, const char *dst_root, } if (!S_ISDIR (sb.st_mode)) { - fprintf (stderr, + fprintf (shadow_logfd, "%s: %s is not a directory", Prog, src_root); return -1; @@ -484,7 +484,7 @@ static int copy_dir (const char *src, const char *dst, */ #ifdef WITH_SELINUX - if (set_selinux_file_context (dst) != 0) { + if (set_selinux_file_context (dst, S_IFDIR) != 0) { return -1; } #endif /* WITH_SELINUX */ @@ -605,7 +605,7 @@ static int copy_symlink (const char *src, const char *dst, } #ifdef WITH_SELINUX - if (set_selinux_file_context (dst) != 0) { + if (set_selinux_file_context (dst, S_IFLNK) != 0) { free (oldlink); return -1; } @@ -684,7 +684,7 @@ static int copy_special (const char *src, const char *dst, int err = 0; #ifdef WITH_SELINUX - if (set_selinux_file_context (dst) != 0) { + if (set_selinux_file_context (dst, statp->st_mode & S_IFMT) != 0) { return -1; } #endif /* WITH_SELINUX */ @@ -744,7 +744,8 @@ static int copy_file (const char *src, const char *dst, return -1; } #ifdef WITH_SELINUX - if (set_selinux_file_context (dst) != 0) { + if (set_selinux_file_context (dst, S_IFREG) != 0) { + (void) close (ifd); return -1; } #endif /* WITH_SELINUX */ @@ -771,12 +772,16 @@ static int copy_file (const char *src, const char *dst, && (errno != 0)) #endif /* WITH_ATTR */ ) { + if (ofd >= 0) { + (void) close (ofd); + } (void) close (ifd); return -1; } while ((cnt = read (ifd, buf, sizeof buf)) > 0) { if (write (ofd, buf, (size_t)cnt) != cnt) { + (void) close (ofd); (void) close (ifd); return -1; } @@ -786,6 +791,7 @@ static int copy_file (const char *src, const char *dst, #ifdef HAVE_FUTIMES if (futimes (ofd, mt) != 0) { + (void) close (ofd); return -1; } #endif /* HAVE_FUTIMES */ |