View | Details | Raw Unified | Return to bug 45333 | Differences between
and this patch

Collapse All | Expand All

(-)src/usr.sbin/chown/chgrp.1 (+11 lines)
Lines 50-55 Link Here
50
.Oc
50
.Oc
51
.Ar group
51
.Ar group
52
.Ar
52
.Ar
53
.Nm
54
.Op Fl fhv
55
.Oo
56
.Fl R
57
.Op Fl H | Fl L | Fl P
58
.Oc
59
.Fl r Ar rfile
60
.Ar
53
.Sh DESCRIPTION
61
.Sh DESCRIPTION
54
The
62
The
55
.Nm
63
.Nm
Lines 84-89 Link Here
84
.It Fl h
92
.It Fl h
85
If the file is a symbolic link, the group ID of the link itself is changed
93
If the file is a symbolic link, the group ID of the link itself is changed
86
rather than the file that is pointed to.
94
rather than the file that is pointed to.
95
.It Fl r Ar rfile
96
Sets the group ID to the group of the file
97
.Ar rfile .
87
.It Fl v
98
.It Fl v
88
Cause
99
Cause
89
.Nm
100
.Nm
(-)src/usr.sbin/chown/chown.8 (+24 lines)
Lines 55-60 Link Here
55
.Oc
55
.Oc
56
.No : Ns Ar group
56
.No : Ns Ar group
57
.Ar
57
.Ar
58
.Nm
59
.Op Fl fhv
60
.Oo
61
.Fl R
62
.Op Fl H | Fl L | Fl P
63
.Oc
64
.Fl r Ar rfile
65
.Op Fl g
66
.Ar
58
.Sh DESCRIPTION
67
.Sh DESCRIPTION
59
The
68
The
60
.Nm
69
.Nm
Lines 85-93 Link Here
85
.It Fl f
94
.It Fl f
86
Don't report any failure to change file owner or group, nor modify
95
Don't report any failure to change file owner or group, nor modify
87
the exit status to reflect such failures.
96
the exit status to reflect such failures.
97
.It Fl g
98
See the
99
.Fl r
100
option.
88
.It Fl h
101
.It Fl h
89
If the file is a symbolic link, change the user ID and/or the
102
If the file is a symbolic link, change the user ID and/or the
90
group ID of the link itself.
103
group ID of the link itself.
104
.It Fl r Ar rfile
105
Changes the user ID to the owner of the file
106
.Ar rfile .
107
If the 
108
.Fl g
109
option is also specified, change both user ID and group ID
110
to the owner and group of the file
111
.Ar rfile .
112
Use the
113
.Xr chgrp 1
114
utility to change the group ID only.
91
.It Fl v
115
.It Fl v
92
Cause
116
Cause
93
.Nm
117
.Nm
(-)src/usr.sbin/chown/chown.c (-12 / +36 lines)
Lines 75-90 Link Here
75
{
75
{
76
	FTS *ftsp;
76
	FTS *ftsp;
77
	FTSENT *p;
77
	FTSENT *p;
78
	int Hflag, Lflag, Rflag, fflag, hflag, vflag;
78
	int Hflag, Lflag, Rflag, fflag, gflag, hflag, rflag, vflag;
79
	int ch, fts_options, rval;
79
	int ch, fts_options, rval;
80
	char *cp;
80
	char *cp;
81
	char *rname;
81
82
82
	cp = strrchr(argv[0], '/');
83
	cp = strrchr(argv[0], '/');
83
	cp = (cp != NULL) ? cp + 1 : argv[0];
84
	cp = (cp != NULL) ? cp + 1 : argv[0];
84
	ischown = (strcmp(cp, "chown") == 0);
85
	ischown = (strcmp(cp, "chown") == 0);
85
86
86
	Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
87
	Hflag = Lflag = Rflag = fflag = gflag = hflag = rflag = vflag = 0;
87
	while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
88
	while ((ch = getopt(argc, argv, "HLPRfghr:v")) != -1)
88
		switch (ch) {
89
		switch (ch) {
89
		case 'H':
90
		case 'H':
90
			Hflag = 1;
91
			Hflag = 1;
Lines 103-111 Link Here
103
		case 'f':
104
		case 'f':
104
			fflag = 1;
105
			fflag = 1;
105
			break;
106
			break;
107
		case 'g':
108
			gflag = 1;
109
			break;
106
		case 'h':
110
		case 'h':
107
			hflag = 1;
111
			hflag = 1;
108
			break;
112
			break;
113
		case 'r':
114
			rflag = 1;
115
			rname = optarg;
116
			break;
109
		case 'v':
117
		case 'v':
110
			vflag = 1;
118
			vflag = 1;
111
			break;
119
			break;
Lines 116-122 Link Here
116
	argv += optind;
124
	argv += optind;
117
	argc -= optind;
125
	argc -= optind;
118
126
119
	if (argc < 2)
127
	if (argc < (rflag ? 1 : 2))
128
		usage();
129
	if (gflag && !ischown)
120
		usage();
130
		usage();
121
131
122
	if (Rflag) {
132
	if (Rflag) {
Lines 135-141 Link Here
135
145
136
	uid = (uid_t)-1;
146
	uid = (uid_t)-1;
137
	gid = (gid_t)-1;
147
	gid = (gid_t)-1;
138
	if (ischown) {
148
	if (rflag) {
149
		struct stat sb;
150
151
                if (stat(rname, &sb) == -1)
152
			err(EXIT_FAILURE, "%s", rname);
153
		if (ischown)
154
			uid = sb.st_uid;
155
		if (gflag || !ischown)
156
			gid = sb.st_gid;
157
	}
158
	else if (ischown) {
139
		if ((cp = strchr(*argv, ':')) != NULL) {
159
		if ((cp = strchr(*argv, ':')) != NULL) {
140
			*cp++ = '\0';
160
			*cp++ = '\0';
141
			a_gid(cp);
161
			a_gid(cp);
Lines 147-157 Link Here
147
			a_gid(cp);
167
			a_gid(cp);
148
		}
168
		}
149
#endif
169
#endif
150
		a_uid(*argv);
170
		a_uid(*argv++);
151
	} else
171
	} else
152
		a_gid(*argv);
172
		a_gid(*argv++);
153
173
154
	if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
174
	if ((ftsp = fts_open(argv, fts_options, 0)) == NULL)
155
		err(1, NULL);
175
		err(1, NULL);
156
176
157
	for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
177
	for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
Lines 273-284 Link Here
273
{
293
{
274
294
275
	if (ischown)
295
	if (ischown)
276
		(void)fprintf(stderr, "%s\n%s\n",
296
		(void)fprintf(stderr, "%s\n%s\n%s\n",
277
		    "usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group]"
297
		    "usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group]"
278
		    " file ...",
298
		    " file ...",
279
		    "       chown [-fhv] [-R [-H | -L | -P]] :group file ...");
299
		    "       chown [-fhv] [-R [-H | -L | -P]] :group file ...",
300
		    "       chown [-fhv] [-R [-H | -L | -P]] -r rfile [-g]"
301
		    " file ...");
280
	else
302
	else
281
		(void)fprintf(stderr, "%s\n",
303
		(void)fprintf(stderr, "%s\n%s\n",
282
		    "usage: chgrp [-fhv] [-R [-H | -L | -P]] group file ...");
304
		    "usage: chgrp [-fhv] [-R [-H | -L | -P]] group file ...",
305
		    "usage: chgrp [-fhv] [-R [-H | -L | -P]] -r rfile"
306
		    " file ...");
283
	exit(1);
307
	exit(1);
284
}
308
}

Return to bug 45333