Bug 45333

Summary: [patch] New option -r for chown(8) and chgrp(1)
Product: Base System Reporter: Oliver Fromme <olli>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me CC: olli
Priority: Normal Keywords: patch
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
chown.stable.diff
none
file.diff none

Description Oliver Fromme 2002-11-16 11:00:04 UTC
        The existing utilities touch(1) and truncate(1) support
        an -r option to specify a reference file from which
        information is to be taken (the time stamp in the case
        of touch(1) and the file size in the case of truncate(1)).

        However, the utilities chown and chgrp (actually hardlinks
        to the same binary) do not support such an option yet.
        In shell scripts it is sometimes useful to copy ownership
        and/or group membership from another file.  Ordinarily,
        you would have to use ls -l and parse the owner/group
        columns, which is awkward, error-prone and inefficient.

        The patch presented below adds an -r option to these
        utilities, which makes copying ownership and/or group
        membership easy.  It also improves consistency with the
        existing utilities touch(1) and truncate(1).

Fix: IMPORTANT:  I have attached TWO patch sets, one for
                    -stable and one for -current.  PLEASE
                    do not confuse them!  Each of the patch
                    sets contains patches for three files:

                    chgrp.1   -   chgrp(1) manpage
                    chown.8   -   chown(8) manpage
                    chown.c   -   chgrp(1) and chown(8) source

                    Note:  Because of lack of a -current box,
                    I have not been able to actually test the
                    -current patch set, but I'm confident that
                    it works fine, since the differences are
                    pretty trivial.  I have tested the -stable
                    patch set extensively.
How-To-Repeat: 
        N/A
Comment 1 olli 2002-11-16 20:59:30 UTC
Small addendum:

Thanks to David Wolfskill who tested the patch under -current,
two minor problems have been found (only style / cosmetic,
and only in the patch set for -current):

 - In line 151 of the patched chown.c, there are spaces
   instead of tabs, leading to a mis-aligned "if".
   Should be converted to tabs.

 - In line 305 of the same file, the second usage line
   for chgrp repeats the word "usage:".  Should be replaced
   by spaces.

Thanks again, David!

Regards
   Oliver
Comment 2 Peter Pentchev 2002-11-18 09:03:30 UTC
On Sat, Nov 16, 2002 at 11:56:37AM +0100, Oliver Fromme wrote:
> 
> >Number:         45333
> >Category:       bin
> >Synopsis:       [PATCH] New option -r for chown and chgrp
> >Originator:     Oliver Fromme
> >Release:        FreeBSD -stable and -current
> >Organization:
> secnetix GmbH & Co KG, Munich, http://www.secnetix.de/
> >Environment:
> 
>         The patch presented applies both to -stable and -current
>         as of the date of submission (2002-11-16).
> 
> >Description:
> 
>         The existing utilities touch(1) and truncate(1) support
>         an -r option to specify a reference file from which
>         information is to be taken (the time stamp in the case
>         of touch(1) and the file size in the case of truncate(1)).
> 
>         However, the utilities chown and chgrp (actually hardlinks
>         to the same binary) do not support such an option yet.
>         In shell scripts it is sometimes useful to copy ownership
>         and/or group membership from another file.  Ordinarily,
>         you would have to use ls -l and parse the owner/group
>         columns, which is awkward, error-prone and inefficient.

For the record, a cleaner way to do this would be to use the stat(1)
utility, which is only available in -current for the present.

[roam@ref5 ~]$ stat -f '%Su:%Sg' /etc/passwd
root:wheel
[roam@ref5 ~]$

Thus, something like "chown `stat -f '%Su:%Sg' $reffile` $file" would
probably do what you need.  Of course, a command-line option might be a
bit easier to use :)

G'luck,
Peter

-- 
Peter Pentchev	roam@ringlet.net	roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
This sentence contains exactly threee erors.
Comment 3 Garrett Cooper 2008-06-21 03:36:16 UTC
Don't think these sets of patches should be considered as using -r
would break compatibility with -R use in GNU-land =\...
Besides, Peter came up with a decent workaround [use stat(1)], which
has been in -STABLE for quite some time.
-Garrett
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:16 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 5 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:35:29 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>