Activate the -h flag which tells chown/chgrp to work on the symlink itself
using lchown(). Most of the code was already here, the option was recognised but ignored for SYSV/POSIX.2(?) compatability.
This commit is contained in:
parent
743c3e66c8
commit
2e08522b02
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=24446
@ -47,6 +47,7 @@
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl f
|
||||
.Op Fl h
|
||||
.Ar group
|
||||
.Ar files ...
|
||||
.Sh DESCRIPTION
|
||||
@ -77,15 +78,11 @@ in the files instead of just the files themselves.
|
||||
.It Fl f
|
||||
The force option ignores errors, except for usage errors and doesn't
|
||||
query about strange modes (unless the user does not have proper permissions).
|
||||
.It Fl h
|
||||
If the file is a symbolic link, the group ID of the link itself is changed
|
||||
rather than the file that is pointed to.
|
||||
.El
|
||||
.Pp
|
||||
Symbolic links don't have groups, so unless the
|
||||
.Fl H
|
||||
or
|
||||
.Fl L
|
||||
option is set,
|
||||
.Nm chgrp
|
||||
on a symbolic link always succeeds and has no effect.
|
||||
The
|
||||
.Fl H ,
|
||||
.Fl L
|
||||
@ -113,11 +110,7 @@ The
|
||||
.Nm chgrp
|
||||
utility exits 0 on success, and >0 if an error occurs.
|
||||
.Sh COMPATIBILITY
|
||||
Previous versions of the
|
||||
.Nm chgrp
|
||||
utility changed the group of symbolic links specified on the command
|
||||
line.
|
||||
In this system, symbolic links do not have groups.
|
||||
In previous versions of this system, symbolic links did not have groups.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /etc/group -compact
|
||||
.It Pa /etc/group
|
||||
|
@ -30,7 +30,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)chown.8 8.3 (Berkeley) 3/31/94
|
||||
.\" $Id$
|
||||
.\" $Id: chown.8,v 1.4 1997/02/22 16:04:35 peter Exp $
|
||||
.\"
|
||||
.Dd March 31, 1994
|
||||
.Dt CHOWN 8
|
||||
@ -45,6 +45,7 @@
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl f
|
||||
.Op Fl h
|
||||
.Ar owner Op Ar :group
|
||||
.Ar file ...
|
||||
.Nm chown
|
||||
@ -53,6 +54,7 @@
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl f
|
||||
.Op Fl h
|
||||
.Ar :group
|
||||
.Ar file ...
|
||||
.Sh DESCRIPTION
|
||||
@ -80,15 +82,11 @@ in the files instead of just the files themselves.
|
||||
.It Fl f
|
||||
Don't report any failure to change file owner or group, nor modify
|
||||
the exit status to reflect such failures.
|
||||
.It Fl h
|
||||
If the file is a symbolic link, change the user ID and/or the group ID
|
||||
of the link itself rather than the file that the link points to.
|
||||
.El
|
||||
.Pp
|
||||
Symbolic links don't have owners, so unless the
|
||||
.Fl H
|
||||
or
|
||||
.Fl L
|
||||
option is set,
|
||||
.Nm chown
|
||||
on a symbolic link always succeeds and has no effect.
|
||||
The
|
||||
.Fl H ,
|
||||
.Fl L
|
||||
@ -133,11 +131,8 @@ utility used the dot (``.'') character to distinguish the group name.
|
||||
This has been changed to be a colon (``:'') character so that user and
|
||||
group names may contain the dot character.
|
||||
.Pp
|
||||
Previous versions of the
|
||||
.Nm chown
|
||||
utility changed the owner of symbolic links specified on the command
|
||||
line.
|
||||
In this system, symbolic links do not have owners.
|
||||
On previous versions of this system, symbolic links did not have
|
||||
owners.
|
||||
.Sh SEE ALSO
|
||||
.Xr chgrp 1 ,
|
||||
.Xr find 1 ,
|
||||
|
@ -64,7 +64,7 @@ void usage __P((void));
|
||||
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
int Rflag, ischown, fflag;
|
||||
int Rflag, ischown, fflag, hflag;
|
||||
char *gname, *myname;
|
||||
|
||||
int
|
||||
@ -102,13 +102,6 @@ main(argc, argv)
|
||||
fflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
/*
|
||||
* In System V (and probably POSIX.2) the -h option
|
||||
* causes chown/chgrp to change the owner/group of
|
||||
* the symbolic link. 4.4BSD's symbolic links don't
|
||||
* have owners/groups, so it's an undocumented noop.
|
||||
* Do syntax checking, though.
|
||||
*/
|
||||
hflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
@ -175,13 +168,23 @@ main(argc, argv)
|
||||
* don't point to anything and ones that we found
|
||||
* doing a physical walk.
|
||||
*/
|
||||
continue;
|
||||
if (hflag)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (chown(p->fts_accpath, uid, gid) && !fflag) {
|
||||
chownerr(p->fts_path);
|
||||
rval = 1;
|
||||
if (hflag) {
|
||||
if (lchown(p->fts_accpath, uid, gid) && !fflag) {
|
||||
chownerr(p->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
} else {
|
||||
if (chown(p->fts_accpath, uid, gid) && !fflag) {
|
||||
chownerr(p->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errno)
|
||||
@ -266,7 +269,7 @@ void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-R [-H | -L | -P]] [-f] %s file ...\n",
|
||||
"usage: %s [-R [-H | -L | -P]] [-f] [-h] %s file ...\n",
|
||||
myname, ischown ? "[owner][:group]" : "group");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user