2 * Copyright (c) 2010, Frank Lahm <franklahm@googlemail.com>
3 * Copyright (c) 1988, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
7 * David Hitz of Auspex Systems Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Cp copies source files to target files.
37 * The global PATH_T structure "to" always contains the path to the
38 * current target file. Since fts(3) does not change directories,
39 * this path can be either absolute or dot-relative.
41 * The basic algorithm is to initialize "to" and use fts(3) to traverse
42 * the file hierarchy rooted in the argument list. A trivial case is the
43 * case of 'cp file1 file2'. The more interesting case is the case of
44 * 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
45 * path (relative to the root of the traversal) is appended to dir (stored
46 * in "to") to form the final target path.
51 #endif /* HAVE_CONFIG_H */
53 #include <sys/types.h>
63 #include <atalk/ftw.h>
64 #include <atalk/adouble.h>
65 #include <atalk/vfs.h>
66 #include <atalk/util.h>
67 #include <atalk/unix.h>
68 #include <atalk/volume.h>
69 #include <atalk/volinfo.h>
70 #include <atalk/bstrlib.h>
71 #include <atalk/bstradd.h>
72 #include <atalk/queue.h>
76 #define STRIP_TRAILING_SLASH(p) { \
77 while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
81 static char emptystring[] = "";
83 PATH_T to = { to.p_path, emptystring, "" };
84 enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
86 int fflag, iflag, lflag, nflag, pflag, vflag;
89 cnid_t ppdid, pdid, did; /* current dir CNID and parent did*/
91 static afpvol_t svolume, dvolume;
94 volatile sig_atomic_t sigint;
95 static int badcp, rval;
96 static int ftw_options = FTW_MOUNT | FTW_PHYS | FTW_ACTIONRETVAL;
98 static char *netatalk_dirs[] = {
105 /* Forward declarations */
106 static int copy(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf);
107 static void siginfo(int _U_);
108 static int ftw_copy_file(const struct FTW *, const char *, const struct stat *, int);
109 static int ftw_copy_link(const struct FTW *, const char *, const struct stat *, int);
110 static int setfile(const struct stat *, int);
111 static int preserve_dir_acls(const struct stat *, char *, char *);
112 static int preserve_fd_acls(int, int);
115 Check for netatalk special folders e.g. ".AppleDB" or ".AppleDesktop"
116 Returns pointer to name or NULL.
118 static const char *check_netatalk_dirs(const char *name)
122 for (c=0; netatalk_dirs[c]; c++) {
123 if ((strcmp(name, netatalk_dirs[c])) == 0)
124 return netatalk_dirs[c];
129 static void upfunc(void)
135 static void usage_cp(void)
138 "Usage: ad cp [-R [-P]] [-pvf] <source_file> <target_file>\n"
139 "Usage: ad cp [-R [-P]] [-pvfx] <source_file [source_file ...]> <target_directory>\n"
144 int ad_cp(int argc, char *argv[])
146 struct stat to_stat, tmp_stat;
147 int r, ch, have_trailing_slash;
154 ppdid = pdid = htonl(1);
157 while ((ch = getopt(argc, argv, "Rafilnpvx")) != -1)
188 ftw_options |= FTW_MOUNT;
200 (void)signal(SIGINT, siginfo);
204 /* Save the target base in "to". */
205 target = argv[--argc];
206 if ((strlcpy(to.p_path, target, PATH_MAX)) >= PATH_MAX)
207 ERROR("%s: name too long", target);
209 to.p_end = to.p_path + strlen(to.p_path);
210 if (to.p_path == to.p_end) {
214 have_trailing_slash = (to.p_end[-1] == '/');
215 if (have_trailing_slash)
216 STRIP_TRAILING_SLASH(to);
217 to.target_end = to.p_end;
219 /* Set end of argument list */
223 * Cp has two distinct cases:
225 * cp [-R] source target
226 * cp [-R] source1 ... sourceN directory
228 * In both cases, source can be either a file or a directory.
230 * In (1), the target becomes a copy of the source. That is, if the
231 * source is a file, the target will be a file, and likewise for
234 * In (2), the real target is not directory, but "directory/source".
236 r = stat(to.p_path, &to_stat);
237 if (r == -1 && errno != ENOENT)
238 ERROR("%s", to.p_path);
239 if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
241 * Case (1). Target is not a directory.
244 ERROR("%s is not a directory", to.p_path);
247 * Need to detect the case:
249 * Where dir is a directory and foo does not exist, where
250 * we want pathname concatenations turned on but not for
251 * the initial mkdir().
254 lstat(*argv, &tmp_stat);
256 if (S_ISDIR(tmp_stat.st_mode) && Rflag)
263 if (have_trailing_slash && type == FILE_TO_FILE) {
265 ERROR("directory %s does not exist", to.p_path);
267 ERROR("%s is not a directory", to.p_path);
271 * Case (2). Target is a directory.
276 * Keep an inverted copy of the umask, for use in correcting
277 * permissions on created directories when not using -p.
283 /* Inhereting perms in ad_mkdir etc requires this */
287 /* Load .volinfo file for destination*/
288 openvol(to.p_path, &dvolume);
290 for (int i = 0; argv[i] != NULL; i++) {
291 /* Load .volinfo file for source */
292 openvol(argv[i], &svolume);
294 if (nftw(argv[i], copy, upfunc, 20, ftw_options) == -1) {
295 ERROR("%s: %s", argv[i], strerror(errno));
304 static int copy(const char *path,
305 const struct stat *statp,
317 const char *dir = strrchr(path, '/');
322 if (check_netatalk_dirs(dir) != NULL)
323 return FTW_SKIP_SUBTREE;
326 * If we are in case (2) above, we need to append the
327 * source name to the target name.
329 if (type != FILE_TO_FILE) {
331 * Need to remember the roots of traversals to create
332 * correct pathnames. If there's a directory being
333 * copied to a non-existent directory, e.g.
334 * cp -R a/dir noexist
335 * the resulting path name should be noexist/foo, not
336 * noexist/dir/foo (where foo is a file in dir), which
337 * is the case where the target exists.
339 * Also, check for "..". This is for correct path
340 * concatenation for paths ending in "..", e.g.
342 * Paths ending in ".." are changed to ".". This is
343 * tricky, but seems the easiest way to fix the problem.
346 * Since the first level MUST be FTS_ROOTLEVEL, base
347 * is always initialized.
349 if (ftw->level == 0) {
350 if (type != DIR_TO_DNE) {
353 if (strcmp(&path[base], "..") == 0)
360 nlen = strlen(path) - base;
361 target_mid = to.target_end;
362 if (*p != '/' && target_mid[-1] != '/')
365 if (target_mid - to.p_path + nlen >= PATH_MAX) {
366 SLOG("%s%s: name too long (not copied)", to.p_path, p);
370 (void)strncat(target_mid, p, nlen);
371 to.p_end = target_mid + nlen;
373 STRIP_TRAILING_SLASH(to);
376 /* Not an error but need to remember it happened */
377 if (stat(to.p_path, &to_stat) == -1)
380 if (to_stat.st_dev == statp->st_dev &&
381 to_stat.st_ino == statp->st_ino) {
382 SLOG("%s and %s are identical (not copied).",
385 if (S_ISDIR(statp->st_mode))
386 /* without using glibc extension FTW_ACTIONRETVAL cant handle this */
389 if (!S_ISDIR(statp->st_mode) &&
390 S_ISDIR(to_stat.st_mode)) {
391 SLOG("cannot overwrite directory %s with "
400 switch (statp->st_mode & S_IFMT) {
402 if (ftw_copy_link(ftw, path, statp, !dne))
407 SLOG("%s is a directory", path);
412 * If the directory doesn't exist, create the new
413 * one with the from file mode plus owner RWX bits,
414 * modified by the umask. Trade-off between being
415 * able to write the directory (if from directory is
416 * 555) and not causing a permissions race. If the
417 * umask blocks owner writes, we fail..
420 if (mkdir(to.p_path, statp->st_mode | S_IRWXU) < 0)
421 ERROR("mkdir: %s: %s", to.p_path, strerror(errno));
422 } else if (!S_ISDIR(to_stat.st_mode)) {
424 ERROR("%s", to.p_path);
427 /* Create ad dir and copy ".Parent" */
428 if (dvolume.volinfo.v_path && dvolume.volinfo.v_adouble == AD_VERSION2) {
430 /* Create ".AppleDouble" dir */
431 mode_t omask = umask(0);
432 bstring addir = bfromcstr(to.p_path);
433 bcatcstr(addir, "/.AppleDouble");
434 mkdir(cfrombstr(addir), 02777);
437 if (svolume.volinfo.v_path && svolume.volinfo.v_adouble == AD_VERSION2) {
438 /* copy ".Parent" file */
439 SLOG("Copying adouble for %s -> %s", path, to.p_path);
440 if (dvolume.volume.vfs->vfs_copyfile(&dvolume.volume, -1, path, to.p_path)) {
441 SLOG("Error copying adouble for %s -> %s", path, to.p_path);
447 /* Get CNID of Parent and add new childir to CNID database */
449 did = cnid_for_path(&dvolume.volinfo, &dvolume.volume, to.p_path, &pdid);
453 if (stat(to.p_path, &st) != 0) {
457 ad_init(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
458 if (ad_open_metadata(to.p_path, ADFLAGS_DIR, O_RDWR | O_CREAT, &ad) != 0) {
459 ERROR("Error opening adouble for: %s", to.p_path);
461 SLOG("Setting CNID %u for %s", ntohl(did), to.p_path);
462 ad_setid( &ad, st.st_dev, st.st_ino, did, pdid, dvolume.db_stamp);
463 ad_setname(&ad, utompath(&dvolume.volinfo, basename(to.p_path)));
464 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime);
465 ad_setdate(&ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime);
466 ad_setdate(&ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
467 ad_setdate(&ad, AD_DATE_BACKUP, AD_DATE_START);
469 ad_close_metadata(&ad);
475 if (setfile(statp, -1))
478 if (preserve_dir_acls(statp, curr->fts_accpath, to.p_path) != 0)
486 SLOG("%s is a device file (not copied).", path);
489 SLOG("%s is a socket (not copied).", path);
492 SLOG("%s is a FIFO (not copied).", path);
495 if (ftw_copy_file(ftw, path, statp, dne))
498 if (dvolume.volinfo.v_path && dvolume.volinfo.v_adouble == AD_VERSION2) {
500 mode_t omask = umask(0);
501 if (svolume.volinfo.v_path && svolume.volinfo.v_adouble == AD_VERSION2) {
503 if (dvolume.volume.vfs->vfs_copyfile(&dvolume.volume, -1, path, to.p_path)) {
504 SLOG("Error copying adouble for %s -> %s", path, to.p_path);
510 /* Get CNID of Parent and add new childir to CNID database */
512 cnid_t cnid = cnid_for_path(&dvolume.volinfo, &dvolume.volume, to.p_path, &did);
516 if (stat(to.p_path, &st) != 0) {
520 ad_init(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
521 if (ad_open_metadata(to.p_path, 0, O_RDWR | O_CREAT, &ad) != 0) {
522 ERROR("Error opening adouble for: %s", to.p_path);
524 SLOG("setid: DID: %u, CNID: %u, %s", ntohl(did), ntohl(cnid), to.p_path);
525 ad_setid( &ad, st.st_dev, st.st_ino, cnid, did, dvolume.db_stamp);
526 ad_setname(&ad, utompath(&dvolume.volinfo, basename(to.p_path)));
527 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime);
528 ad_setdate(&ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime);
529 ad_setdate(&ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
530 ad_setdate(&ad, AD_DATE_BACKUP, AD_DATE_START);
532 ad_close_metadata(&ad);
538 (void)printf("%s -> %s\n", path, to.p_path);
543 static void siginfo(int sig _U_)
548 /* Memory strategy threshold, in pages: if physmem is larger then this, use a large buffer */
549 #define PHYSPAGES_THRESHOLD (32*1024)
551 /* Maximum buffer size in bytes - do not allow it to grow larger than this */
552 #define BUFSIZE_MAX (2*1024*1024)
554 /* Small (default) buffer size in bytes. It's inefficient for this to be smaller than MAXPHYS */
555 #define MAXPHYS (64 * 1024)
556 #define BUFSIZE_SMALL (MAXPHYS)
558 static int ftw_copy_file(const struct FTW *entp,
560 const struct stat *sp,
563 static char *buf = NULL;
564 static size_t bufsize;
568 int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
572 if ((from_fd = open(spath, O_RDONLY, 0)) == -1) {
573 SLOG("%s: %s", spath, strerror(errno));
578 * If the file exists and we're interactive, verify with the user.
579 * If the file DNE, set the mode to be the from file, minus setuid
580 * bits, modified by the umask; arguably wrong, but it makes copying
581 * executables work right and it's been that way forever. (The
582 * other choice is 666 or'ed with the execute bits on the from file
583 * modified by the umask.)
586 #define YESNO "(y/n [n]) "
589 printf("%s not overwritten\n", to.p_path);
590 (void)close(from_fd);
593 (void)fprintf(stderr, "overwrite %s? %s",
595 checkch = ch = getchar();
596 while (ch != '\n' && ch != EOF)
598 if (checkch != 'y' && checkch != 'Y') {
599 (void)close(from_fd);
600 (void)fprintf(stderr, "not overwritten\n");
606 /* remove existing destination file name,
607 * create a new file */
608 (void)unlink(to.p_path);
609 (void)dvolume.volume.vfs->vfs_deletefile(&dvolume.volume, -1, to.p_path);
611 to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
612 sp->st_mode & ~(S_ISUID | S_ISGID));
615 /* overwrite existing destination file name */
616 to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
620 to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
621 sp->st_mode & ~(S_ISUID | S_ISGID));
625 SLOG("%s: %s", to.p_path, strerror(errno));
626 (void)close(from_fd);
634 * Mmap and write if less than 8M (the limit is so we don't totally
635 * trash memory on big files. This is really a minor hack, but it
636 * wins some CPU back.
637 * Some filesystems, such as smbnetfs, don't support mmap,
638 * so this is a best-effort attempt.
641 if (S_ISREG(sp->st_mode) && sp->st_size > 0 &&
642 sp->st_size <= 8 * 1024 * 1024 &&
643 (p = mmap(NULL, (size_t)sp->st_size, PROT_READ,
644 MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) {
646 for (bufp = p, wresid = sp->st_size; ;
647 bufp += wcount, wresid -= (size_t)wcount) {
648 wcount = write(to_fd, bufp, wresid);
652 if (wcount >= (ssize_t)wresid)
655 if (wcount != (ssize_t)wresid) {
656 SLOG("%s: %s", to.p_path, strerror(errno));
659 /* Some systems don't unmap on close(2). */
660 if (munmap(p, sp->st_size) < 0) {
661 SLOG("%s: %s", spath, strerror(errno));
667 * Note that buf and bufsize are static. If
668 * malloc() fails, it will fail at the start
669 * and not copy only some files.
671 if (sysconf(_SC_PHYS_PAGES) >
673 bufsize = MIN(BUFSIZE_MAX, MAXPHYS * 8);
675 bufsize = BUFSIZE_SMALL;
676 buf = malloc(bufsize);
678 ERROR("Not enough memory");
682 while ((rcount = read(from_fd, buf, bufsize)) > 0) {
683 for (bufp = buf, wresid = rcount; ;
684 bufp += wcount, wresid -= wcount) {
685 wcount = write(to_fd, bufp, wresid);
689 if (wcount >= (ssize_t)wresid)
692 if (wcount != (ssize_t)wresid) {
693 SLOG("%s: %s", to.p_path, strerror(errno));
699 SLOG("%s: %s", spath, strerror(errno));
704 if (link(spath, to.p_path)) {
705 SLOG("%s", to.p_path);
711 * Don't remove the target even after an error. The target might
712 * not be a regular file, or its attributes might be important,
713 * or its contents might be irreplaceable. It would only be safe
714 * to remove it if we created it and its length is 0.
718 if (pflag && setfile(sp, to_fd))
720 if (pflag && preserve_fd_acls(from_fd, to_fd) != 0)
723 SLOG("%s: %s", to.p_path, strerror(errno));
728 (void)close(from_fd);
733 static int ftw_copy_link(const struct FTW *p,
735 const struct stat *sstp,
739 char llink[PATH_MAX];
741 if ((len = readlink(spath, llink, sizeof(llink) - 1)) == -1) {
742 SLOG("readlink: %s: %s", spath, strerror(errno));
746 if (exists && unlink(to.p_path)) {
747 SLOG("unlink: %s: %s", to.p_path, strerror(errno));
750 if (symlink(llink, to.p_path)) {
751 SLOG("symlink: %s: %s", llink, strerror(errno));
754 return (pflag ? setfile(sstp, -1) : 0);
757 static int setfile(const struct stat *fs, int fd)
759 static struct timeval tv[2];
761 int rval, gotstat, islink, fdval;
766 islink = !fdval && S_ISLNK(fs->st_mode);
767 mode = fs->st_mode & (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO);
769 TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
770 TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
771 if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
772 SLOG("%sutimes: %s", islink ? "l" : "", to.p_path);
775 if (fdval ? fstat(fd, &ts) :
776 (islink ? lstat(to.p_path, &ts) : stat(to.p_path, &ts)))
780 ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX |
781 S_IRWXU | S_IRWXG | S_IRWXO;
784 * Changing the ownership probably won't succeed, unless we're root
785 * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
786 * the mode; current BSD behavior is to remove all setuid bits on
787 * chown. If chown fails, lose setuid/setgid bits.
789 if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid)
790 if (fdval ? fchown(fd, fs->st_uid, fs->st_gid) :
791 (islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) :
792 chown(to.p_path, fs->st_uid, fs->st_gid))) {
793 if (errno != EPERM) {
794 SLOG("chown: %s: %s", to.p_path, strerror(errno));
797 mode &= ~(S_ISUID | S_ISGID);
800 if (!gotstat || mode != ts.st_mode)
801 if (fdval ? fchmod(fd, mode) : chmod(to.p_path, mode)) {
802 SLOG("chmod: %s: %s", to.p_path, strerror(errno));
807 if (!gotstat || fs->st_flags != ts.st_flags)
809 fchflags(fd, fs->st_flags) :
810 (islink ? lchflags(to.p_path, fs->st_flags) :
811 chflags(to.p_path, fs->st_flags))) {
812 SLOG("chflags: %s: %s", to.p_path, strerror(errno));
820 static int preserve_fd_acls(int source_fd, int dest_fd)
825 int acl_supported = 0, ret, trivial;
827 ret = fpathconf(source_fd, _PC_ACL_NFS4);
830 acl_type = ACL_TYPE_NFS4;
831 } else if (ret < 0 && errno != EINVAL) {
832 warn("fpathconf(..., _PC_ACL_NFS4) failed for %s", to.p_path);
835 if (acl_supported == 0) {
836 ret = fpathconf(source_fd, _PC_ACL_EXTENDED);
839 acl_type = ACL_TYPE_ACCESS;
840 } else if (ret < 0 && errno != EINVAL) {
841 warn("fpathconf(..., _PC_ACL_EXTENDED) failed for %s",
846 if (acl_supported == 0)
849 acl = acl_get_fd_np(source_fd, acl_type);
851 warn("failed to get acl entries while setting %s", to.p_path);
854 if (acl_is_trivial_np(acl, &trivial)) {
855 warn("acl_is_trivial() failed for %s", to.p_path);
863 if (acl_set_fd_np(dest_fd, acl, acl_type) < 0) {
864 warn("failed to set acl entries for %s", to.p_path);
873 static int preserve_dir_acls(const struct stat *fs, char *source_dir, char *dest_dir)
876 acl_t (*aclgetf)(const char *, acl_type_t);
877 int (*aclsetf)(const char *, acl_type_t, acl_t);
881 int acl_supported = 0, ret, trivial;
883 ret = pathconf(source_dir, _PC_ACL_NFS4);
886 acl_type = ACL_TYPE_NFS4;
887 } else if (ret < 0 && errno != EINVAL) {
888 warn("fpathconf(..., _PC_ACL_NFS4) failed for %s", source_dir);
891 if (acl_supported == 0) {
892 ret = pathconf(source_dir, _PC_ACL_EXTENDED);
895 acl_type = ACL_TYPE_ACCESS;
896 } else if (ret < 0 && errno != EINVAL) {
897 warn("fpathconf(..., _PC_ACL_EXTENDED) failed for %s",
902 if (acl_supported == 0)
906 * If the file is a link we will not follow it
908 if (S_ISLNK(fs->st_mode)) {
909 aclgetf = acl_get_link_np;
910 aclsetf = acl_set_link_np;
912 aclgetf = acl_get_file;
913 aclsetf = acl_set_file;
915 if (acl_type == ACL_TYPE_ACCESS) {
917 * Even if there is no ACL_TYPE_DEFAULT entry here, a zero
918 * size ACL will be returned. So it is not safe to simply
919 * check the pointer to see if the default ACL is present.
921 acl = aclgetf(source_dir, ACL_TYPE_DEFAULT);
923 warn("failed to get default acl entries on %s",
927 aclp = &acl->ats_acl;
928 if (aclp->acl_cnt != 0 && aclsetf(dest_dir,
929 ACL_TYPE_DEFAULT, acl) < 0) {
930 warn("failed to set default acl entries on %s",
937 acl = aclgetf(source_dir, acl_type);
939 warn("failed to get acl entries on %s", source_dir);
942 if (acl_is_trivial_np(acl, &trivial)) {
943 warn("acl_is_trivial() failed on %s", source_dir);
951 if (aclsetf(dest_dir, acl_type, acl) < 0) {
952 warn("failed to set acl entries on %s", dest_dir);