bin/130855: [PATCH] a chown/chgrp -x option to avoid crossing mount
points
Giorgos Keramidas
keramida at FreeBSD.org
Wed Jan 21 21:20:02 PST 2009
>Number: 130855
>Category: bin
>Synopsis: [PATCH] a chown/chgrp -x option to avoid crossing mount points
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu Jan 22 05:20:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator: Giorgos Keramidas
>Release: FreeBSD 8.0-CURRENT i386
>Organization:
<organization of PR author (multiple lines)>
>Environment:
System: FreeBSD kobe 8.0-CURRENT FreeBSD 8.0-CURRENT #0: \
Wed Jan 14 02:12:50 EET 2009 build at kobe:/usr/obj/usr/src/sys/KOBE i386
>Description:
Some time ago, I hacked a -x option into my local chown/chgrp
version, to avoid crossing file system mount points. This is
really a trivial patch, but if it is useful to anyone else we
can commit it to the src-tree too.
>How-To-Repeat:
>Fix:
--- chown-xdev.patch begins here ---
Add a new -x option to chown and chgrp, to inhibit file system
mount point traversal. The -x option is documented, like -v, as
a non-standard option in the COMPATIBILITY manpage sections.
diff -r e8506b2ac7ae -r bc9edfda4335 usr.sbin/chown/chown.c
--- a/usr.sbin/chown/chown.c Wed Jan 21 21:31:33 2009 +0200
+++ b/usr.sbin/chown/chown.c Thu Jan 22 07:08:29 2009 +0200
@@ -73,14 +73,14 @@
{
FTS *ftsp;
FTSENT *p;
- int Hflag, Lflag, Rflag, fflag, hflag, vflag;
+ int Hflag, Lflag, Rflag, fflag, hflag, vflag, xflag;
int ch, fts_options, rval;
char *cp;
ischown = (strcmp(basename(argv[0]), "chown") == 0);
- Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
- while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
+ Hflag = Lflag = Rflag = fflag = hflag = vflag = xflag = 0;
+ while ((ch = getopt(argc, argv, "HLPRfhvx")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -105,6 +105,9 @@
case 'v':
vflag++;
break;
+ case 'x':
+ xflag = 1;
+ break;
case '?':
default:
usage();
@@ -126,8 +129,11 @@
fts_options &= ~FTS_PHYSICAL;
fts_options |= FTS_LOGICAL;
}
- } else
+ } else {
fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
+ }
+ if (xflag)
+ fts_options |= FTS_XDEV;
uid = (uid_t)-1;
gid = (gid_t)-1;
@@ -297,11 +303,11 @@
if (ischown)
(void)fprintf(stderr, "%s\n%s\n",
- "usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group]"
+ "usage: chown [-fhvx] [-R [-H | -L | -P]] owner[:group]"
" file ...",
- " chown [-fhv] [-R [-H | -L | -P]] :group file ...");
+ " chown [-fhvx] [-R [-H | -L | -P]] :group file ...");
else
(void)fprintf(stderr, "%s\n",
- "usage: chgrp [-fhv] [-R [-H | -L | -P]] group file ...");
+ "usage: chgrp [-fhvx] [-R [-H | -L | -P]] group file ...");
exit(1);
}
diff -r e8506b2ac7ae -r bc9edfda4335 usr.sbin/chown/chgrp.1
--- a/usr.sbin/chown/chgrp.1 Wed Jan 21 21:31:33 2009 +0200
+++ b/usr.sbin/chown/chgrp.1 Thu Jan 22 07:08:29 2009 +0200
@@ -31,7 +31,7 @@
.\" @(#)chgrp.1 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$
.\"
-.Dd April 25, 2003
+.Dd January 22, 2009
.Dt CHGRP 1
.Os
.Sh NAME
@@ -39,7 +39,7 @@
.Nd change group
.Sh SYNOPSIS
.Nm
-.Op Fl fhv
+.Op Fl fhvx
.Oo
.Fl R
.Op Fl H | Fl L | Fl P
@@ -89,6 +89,8 @@
flag is specified more than once,
.Nm
will print the filename, followed by the old and new numeric group ID.
+.It Fl x
+File system mount points are not traversed.
.El
.Pp
The
@@ -125,7 +127,9 @@
.Pp
The
.Fl v
-option is non-standard and its use in scripts is not recommended.
+and
+.Fl x
+options are non-standard and their use in scripts is not recommended.
.Sh SEE ALSO
.Xr chown 2 ,
.Xr fts 3 ,
diff -r e8506b2ac7ae -r bc9edfda4335 usr.sbin/chown/chown.8
--- a/usr.sbin/chown/chown.8 Wed Jan 21 21:31:33 2009 +0200
+++ b/usr.sbin/chown/chown.8 Thu Jan 22 07:08:29 2009 +0200
@@ -28,7 +28,7 @@
.\" @(#)chown.8 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$
.\"
-.Dd April 25, 2003
+.Dd January 22, 2009
.Dt CHOWN 8
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Nd change file owner and group
.Sh SYNOPSIS
.Nm
-.Op Fl fhv
+.Op Fl fhvx
.Oo
.Fl R
.Op Fl H | Fl L | Fl P
@@ -44,7 +44,7 @@
.Ar owner Ns Op : Ns Ar group
.Ar
.Nm
-.Op Fl fhv
+.Op Fl fhvx
.Oo
.Fl R
.Op Fl H | Fl L | Fl P
@@ -97,6 +97,8 @@
flag is specified more than once,
.Nm
will print the filename, followed by the old and new numeric user/group ID.
+.It Fl x
+File system mount points are not traversed.
.El
.Pp
The
@@ -146,7 +148,9 @@
.Pp
The
.Fl v
-option is non-standard and its use in scripts is not recommended.
+and
+.Fl x
+options are non-standard and their use in scripts is not recommended.
.Sh SEE ALSO
.Xr chgrp 1 ,
.Xr find 1 ,
--- chown-xdev.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list