

#include <sys/types.h> #include <unistd.h> int chown(const char *pathname, uid_t owner, gid_t group);
chown changes the owner or owning
group of a file. It can be used
with either regular files or special files, such as directories
or FIFO files.
pathname is the name of the file. owner is the user ID.
group is the group ID.
OpenEdition implements a restricted chown for all files.
A call
to chown can succeed in only one of two ways:
chown, and the group argument
is
the effective group ID or one of the user's supplementary ID's.
S_IXUSR,
S_IXGRP, or
S_IXOTH bit is set in the file permissions,
chown clears the S_ISUID and S_ISGID bits
of the permissions.
chown returns 0 if successful and
a -1 if not successful.
chown to
change a file's owner and group:
#include <sys/types.h>
#include <unistd.h>
#include <grp.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
struct group *billing;
int rc;
billing = getgrnam("BILLING");
if (!billing) {
perror("getgrnam error");
abort();
}
if (argc <= 1) {
printf("No file name specified.n");
exit(EXIT_FAILURE);
}
rc = chown(argv[1], geteuid(), billing->gr_gid);
if (rc == 0) {
printf("Ownership of %s assigned to BILLING.n", argv[1]);
exit(EXIT_SUCCESS);
}
else {
perror("chown error");
abort();
}
}
chmod, fchown
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.