Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/chown support --reference=rfile
details: https://anonhg.NetBSD.org/src/rev/0a8c1ce1f12a
branches: trunk
changeset: 782239:0a8c1ce1f12a
user: christos <christos%NetBSD.org@localhost>
date: Mon Oct 22 18:02:26 2012 +0000
description:
support --reference=rfile
diffstat:
sbin/chown/chgrp.1 | 21 +++++++++++++++---
sbin/chown/chown.8 | 23 ++++++++++++++++----
sbin/chown/chown.c | 60 +++++++++++++++++++++++++++++++++++++----------------
3 files changed, 77 insertions(+), 27 deletions(-)
diffs (223 lines):
diff -r b88fe4199360 -r 0a8c1ce1f12a sbin/chown/chgrp.1
--- a/sbin/chown/chgrp.1 Mon Oct 22 18:00:46 2012 +0000
+++ b/sbin/chown/chgrp.1 Mon Oct 22 18:02:26 2012 +0000
@@ -29,9 +29,9 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)chgrp.1 8.3 (Berkeley) 3/31/94
-.\" $NetBSD: chgrp.1,v 1.4 2011/01/13 22:28:36 haad Exp $
+.\" $NetBSD: chgrp.1,v 1.5 2012/10/22 18:02:26 christos Exp $
.\"
-.Dd September 25, 2003
+.Dd October 22, 2012
.Dt CHGRP 1
.Os
.Sh NAME
@@ -45,7 +45,15 @@
.Oc
.Op Fl fhv
.Ar group
-.Ar file ...
+.Ar
+.Nm
+.Oo
+.Fl R
+.Op Fl H | Fl L | Fl P
+.Oc
+.Op Fl fhv
+.Fl Fl reference=rfile
+.Ar
.Sh DESCRIPTION
The
.Nm
@@ -53,7 +61,12 @@
.Ar file
operand to the
.Ar group
-ID specified by the group operand.
+ID specified by the group operand,
+or to the group of the given
+.Ar rfile ,
+specified by the
+.Fl Fl reference
+argument.
.Pp
Options:
.Bl -tag -width Ds
diff -r b88fe4199360 -r 0a8c1ce1f12a sbin/chown/chown.8
--- a/sbin/chown/chown.8 Mon Oct 22 18:00:46 2012 +0000
+++ b/sbin/chown/chown.8 Mon Oct 22 18:02:26 2012 +0000
@@ -26,9 +26,9 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)chown.8 8.3 (Berkeley) 3/31/94
-.\" $NetBSD: chown.8,v 1.4 2011/01/13 22:28:36 haad Exp $
+.\" $NetBSD: chown.8,v 1.5 2012/10/22 18:02:26 christos Exp $
.\"
-.Dd December 9, 2005
+.Dd October 22, 2012
.Dt CHOWN 8
.Os
.Sh NAME
@@ -42,7 +42,7 @@
.Oc
.Op Fl fhv
.Ar owner Ns Op Ar :group
-.Ar file ...
+.Ar
.Nm
.Oo
.Fl R
@@ -50,7 +50,15 @@
.Oc
.Op Fl fhv
.Ar :group
-.Ar file ...
+.Ar
+.Nm
+.Oo
+.Fl R
+.Op Fl H | Fl L | Fl P
+.Oc
+.Op Fl fhv
+.Fl Fl reference=rfile
+.Ar
.Sh DESCRIPTION
.Nm
sets the user ID and/or the group ID of the specified files.
@@ -107,7 +115,12 @@
.Ar owner
and
.Ar group
-operands are both optional, however, one must be specified.
+operands are both optional, however, one must be specified; alternative
+both the owner and group may be specified using a reference
+.Ar rfile
+specified using the
+.Fl Fl reference
+argument.
If the
.Ar group
operand is specified, it must be preceded by a colon (``:'') character.
diff -r b88fe4199360 -r 0a8c1ce1f12a sbin/chown/chown.c
--- a/sbin/chown/chown.c Mon Oct 22 18:00:46 2012 +0000
+++ b/sbin/chown/chown.c Mon Oct 22 18:02:26 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chown.c,v 1.5 2011/08/29 14:34:59 joerg Exp $ */
+/* $NetBSD: chown.c,v 1.6 2012/10/22 18:02:26 christos Exp $ */
/*
* Copyright (c) 1988, 1993, 1994, 2003
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)chown.c 8.8 (Berkeley) 4/4/94";
#else
-__RCSID("$NetBSD: chown.c,v 1.5 2011/08/29 14:34:59 joerg Exp $");
+__RCSID("$NetBSD: chown.c,v 1.6 2012/10/22 18:02:26 christos Exp $");
#endif
#endif /* not lint */
@@ -58,6 +58,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <getopt.h>
static void a_gid(const char *);
static void a_uid(const char *);
@@ -69,23 +70,35 @@
static int ischown;
static char *myname;
+struct option chown_longopts[] = {
+ { "reference", required_argument, 0,
+ 1 },
+ { NULL, 0, 0,
+ 0 },
+};
+
int
main(int argc, char **argv)
{
FTS *ftsp;
FTSENT *p;
int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval, vflag;
- char *cp;
+ char *cp, *reference;
int (*change_owner)(const char *, uid_t, gid_t);
(void)setlocale(LC_ALL, "");
myname = (cp = strrchr(*argv, '/')) ? cp + 1 : *argv;
ischown = (myname[2] == 'o');
+ reference = NULL;
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
- while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
+ while ((ch = getopt_long(argc, argv, "HLPRfhv",
+ chown_longopts, NULL)) != -1)
switch (ch) {
+ case 1:
+ reference = optarg;
+ break;
case 'H':
Hflag = 1;
Lflag = 0;
@@ -123,7 +136,7 @@
argv += optind;
argc -= optind;
- if (argc < 2)
+ if (argc == 0 || (argc == 1 && reference == NULL))
usage();
fts_options = FTS_PHYSICAL;
@@ -143,24 +156,35 @@
uid = (uid_t)-1;
gid = (gid_t)-1;
- if (ischown) {
- if ((cp = strchr(*argv, ':')) != NULL) {
- *cp++ = '\0';
- a_gid(cp);
- }
-#ifdef SUPPORT_DOT
- else if ((cp = strrchr(*argv, '.')) != NULL) {
- if (uid_from_user(*argv, &uid) == -1) {
+ if (reference == NULL) {
+ if (ischown) {
+ if ((cp = strchr(*argv, ':')) != NULL) {
*cp++ = '\0';
a_gid(cp);
}
- }
+#ifdef SUPPORT_DOT
+ else if ((cp = strrchr(*argv, '.')) != NULL) {
+ if (uid_from_user(*argv, &uid) == -1) {
+ *cp++ = '\0';
+ a_gid(cp);
+ }
+ }
#endif
- a_uid(*argv);
- } else
- a_gid(*argv);
+ a_uid(*argv);
+ } else
+ a_gid(*argv);
+ argv++;
+ } else {
+ struct stat st;
- if ((ftsp = fts_open(++argv, fts_options, NULL)) == NULL)
+ if (stat(reference, &st) == -1)
+ err(EXIT_FAILURE, "Cannot stat `%s'", reference);
+ uid = st.st_uid;
+ if (ischown)
+ gid = st.st_gid;
+ }
+
+ if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
err(EXIT_FAILURE, "fts_open");
for (rval = EXIT_SUCCESS; (p = fts_read(ftsp)) != NULL;) {
Home |
Main Index |
Thread Index |
Old Index