diff options
Diffstat (limited to 'libmisc/copydir.c')
-rw-r--r-- | libmisc/copydir.c | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/libmisc/copydir.c b/libmisc/copydir.c index 015e1b68..90ba2fcd 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -1,33 +1,10 @@ /* - * Copyright (c) 1991 - 1994, Julianne Frances Haugh - * Copyright (c) 1996 - 2001, Marek Michałkiewicz - * Copyright (c) 2003 - 2006, Tomasz Kłoczko - * Copyright (c) 2007 - 2010, Nicolas François - * All rights reserved. + * SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 1996 - 2001, Marek Michałkiewicz + * SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko + * SPDX-FileCopyrightText: 2007 - 2010, Nicolas François * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the copyright holders or contributors may not be used to - * endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * SPDX-License-Identifier: BSD-3-Clause */ #include <config.h> @@ -55,6 +32,7 @@ #ifdef WITH_ATTR #include <attr/libattr.h> #endif /* WITH_ATTR */ +#include "shadowlog.h" static /*@null@*/const char *src_orig; @@ -116,8 +94,9 @@ static int fchown_if_needed (int fdst, const struct stat *statp, static void error_acl (struct error_context *ctx, const char *fmt, ...) { va_list ap; + FILE *shadow_logfd = log_get_logfd(); - /* ignore the case when destination does not support ACLs + /* ignore the case when destination does not support ACLs * or extended attributes */ if (ENOTSUP == errno) { errno = 0; @@ -125,7 +104,7 @@ static void error_acl (struct error_context *ctx, const char *fmt, ...) } va_start (ap, fmt); - (void) fprintf (shadow_logfd, _("%s: "), Prog); + (void) fprintf (shadow_logfd, _("%s: "), log_get_progname()); if (vfprintf (shadow_logfd, fmt, ap) != 0) { (void) fputs (_(": "), shadow_logfd); } @@ -248,9 +227,9 @@ int copy_tree (const char *src_root, const char *dst_root, } if (!S_ISDIR (sb.st_mode)) { - fprintf (shadow_logfd, + fprintf (log_get_logfd(), "%s: %s is not a directory", - Prog, src_root); + log_get_progname(), src_root); return -1; } @@ -739,7 +718,7 @@ static int copy_file (const char *src, const char *dst, char buf[1024]; ssize_t cnt; - ifd = open (src, O_RDONLY); + ifd = open (src, O_RDONLY|O_NOFOLLOW); if (ifd < 0) { return -1; } @@ -749,7 +728,7 @@ static int copy_file (const char *src, const char *dst, return -1; } #endif /* WITH_SELINUX */ - ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC, statp->st_mode & 07777); + ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, statp->st_mode & 07777); if ( (ofd < 0) || (fchown_if_needed (ofd, statp, old_uid, new_uid, old_gid, new_gid) != 0) |