summaryrefslogtreecommitdiffstats
path: root/bin/mv
diff options
context:
space:
mode:
authorcsjp <csjp@FreeBSD.org>2005-09-05 04:36:08 +0000
committercsjp <csjp@FreeBSD.org>2005-09-05 04:36:08 +0000
commit549c6812a94339302b34e899ce15d452ed69ef23 (patch)
tree4d654ae429b6264f02e5490e9c9b223e74cd7b60 /bin/mv
parent57d500e0a77c3bb556a8303725a9195b630c5771 (diff)
downloadFreeBSD-src-549c6812a94339302b34e899ce15d452ed69ef23.zip
FreeBSD-src-549c6812a94339302b34e899ce15d452ed69ef23.tar.gz
Attempt to complete the userspace integration of POSIX.1e extended ACLs.
This includes adding support for ACLs into cp(1) and mv(1) userspace utilities. For mv(1), if _PC_ACL_EXTENDED is in effect for the source AND destination operands, the destination file's ACLs shall reflect the source. For cp(1), if _PC_ACL_EXTENDED is in effect for both source and destination operands, and -p has been specified, the ACLs from the source shall be preserved on the destination. MFC after: 1 month
Diffstat (limited to 'bin/mv')
-rw-r--r--bin/mv/mv.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index e400729..54c035d 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+#include <sys/acl.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/wait.h>
@@ -252,6 +254,7 @@ fastcopy(char *from, char *to, struct stat *sbp)
static char *bp;
mode_t oldmode;
int nread, from_fd, to_fd;
+ acl_t acl;
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
warn("%s", from);
@@ -288,7 +291,6 @@ err: if (unlink(to))
(void)close(to_fd);
return (1);
}
- (void)close(from_fd);
oldmode = sbp->st_mode & ALLPERMS;
if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
@@ -301,6 +303,21 @@ err: if (unlink(to))
sbp->st_mode &= ~(S_ISUID | S_ISGID);
}
}
+ /*
+ * POSIX 1003.2c states that if _POSIX_ACL_EXTENDED is in effect
+ * for dest_file, then it's ACLs shall reflect the ACLs of the
+ * source_file.
+ */
+ if (fpathconf(to_fd, _PC_ACL_EXTENDED) == 1 &&
+ fpathconf(from_fd, _PC_ACL_EXTENDED) == 1) {
+ acl = acl_get_fd(from_fd);
+ if (acl == NULL)
+ warn("failed to get acl entries while setting %s",
+ from);
+ else if (acl_set_fd(to_fd, acl) < 0)
+ warn("failed to set acl entries for %s", to);
+ }
+ (void)close(from_fd);
if (fchmod(to_fd, sbp->st_mode))
warn("%s: set mode (was: 0%03o)", to, oldmode);
/*
OpenPOWER on IntegriCloud