chownacl(3C)chownacl(3C)NAMEchownacl() - change owner and/or group represented in a file's access
control list (ACL) (HFS File Systems only)
SYNOPSIS
Remarks:
To ensure continued conformance with emerging industry standards, fea‐
tures described in this manual entry are likely to change in a future
release.
DESCRIPTION
This routine alters an access control list (ACL) to reflect the change
in a file's owner or group ID when an old file is copied to a new file
and the ACL is also copied. transfers ownership (that is, it modifies
base ACL entries) in a manner similar to (see chown(2)). The algorithm
is described below and also in acl(5).
The nentries parameter is the current number of ACL entries in the
array (zero or more; a negative value is treated as zero). The olduid
and oldgid values are the user and group IDs of the original file's
owner, typically the and values from (see stat(2)). The newuid and
newgid values are the user and group IDs of the new file's owner, typi‐
cally the return values from and (see geteuid(2) and getegid(2) in
getuid(2)).
If an ACL entry in has a uid of olduid and a gid of (that is, an owner
base ACL entry), changes uid to newuid (with exceptions − see below).
If an entry has a uid of and a gid of oldgid (that is, a group base ACL
entry), changes gid to newgid. In either case, only the last matching
ACL entry is altered; a valid ACL can have only one of each type.
As with chown(2), if the new user or group already has an ACL entry
(that is, a uid of newuid and a gid of or a uid of and a gid of
newgid), does not change the old user or group base ACL entry; both the
old and new ACL entries are preserved.
As a special case, if olduid (oldgid) is equal to newuid (newgid), does
not search for an old user (group) base ACL entry to change. Calling
it with both olduid equal to newuid and oldgid equal to newgid causes
to do nothing.
Suggested Use
This routine is useful in a program that creates a new or replacement
copy of a file whose original was (or possibly was) owned by a differ‐
ent user or group, and that copies the old file's ACL to the new file.
Copying another user's and/or group's file is equivalent to having the
original file's owner and/or group copy and then transfer a file to a
new owner and/or group using This routine is not needed for merely
changing a file's ownership; modifies the ACL appropriately in that
case.
If a program also copies file miscellaneous mode bits from an old file
to a new one, it must use (see chmod(2)). However, since deletes
optional ACL entries, it must be called before (see setacl(2)). Fur‐
thermore, to avoid leaving a new file temporarily unprotected, the call
should set only the file miscellaneous mode bits, with all access per‐
mission mode bits set to zero (that is, mask the mode with 07000). The
library call encapsulates this operation, and handles remote files
appropriately too.
EXAMPLES
The following code fragment gets information and the ACL from transfers
ownership of to the caller, and sets the revised ACL to
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/acl.h>
int nentries;
struct acl_entry acl [NACLENTRIES];
struct stat statbuf;
if (stat ("oldfile", & statbuf) < 0)
error (...);
if ((nentries = getacl ("oldfile", NACLENTRIES, acl)) < 0)
error (...);
chownacl (nentries, acl, statbuf.st_uid, statbuf.st_gid,
geteuid(), getegid());
if (setacl ("newfile", nentries, acl))
error (...);
DEPENDENCIES
is only supported on HFS file system on standard HP-UX operating sys‐
tem.
AUTHOR
was developed by HP.
SEE ALSOchown(2), getacl(2), getegid(2), geteuid(2), getuid(2), setacl(2),
stat(2), acltostr(3C), cpacl(3C), setaclentry(3C), strtoacl(3C),
acl(5), thread_safety(5).
chownacl(3C)