Commit Graph

34 Commits

Author SHA1 Message Date
Ed Schouten
d35fcc6826 Mark global functions and/or variables in chown(8) static where possible.
This allows compilers and static analyzers to do more thorough analysis.
2011-11-06 19:01:41 +00:00
Edward Tomasz Napierala
3e6ce93ee1 Plug resource leak.
Found with:	Coverity Prevent
CID:		7040
2010-06-05 08:11:11 +00:00
Edward Tomasz Napierala
ab3bbb3b18 Make chown(1) emit more useful error message when user/group name is invalid. 2010-06-03 20:46:23 +00:00
Gavin Atkinson
1901b12462 Add a "-x" option to chown(8)/chgrp(1) similar to the same option in
du(1), cp(1) etc, to prevent the crossing of mountpoints whilst using the
commands recursively.

PR:		bin/130855
Submitted by:	keramida
MFC after:	1 month
2010-02-21 10:14:06 +00:00
Brooks Davis
54404cfb13 In preparation for raising NGROUPS and NGROUPS_MAX, change base
system callers of getgroups(), getgrouplist(), and setgroups() to
allocate buffers dynamically.  Specifically, allocate a buffer of size
sysconf(_SC_NGROUPS_MAX)+1 (+2 in a few cases to allow for overflow).

This (or similar gymnastics) is required for the code to actually follow
the POSIX.1-2008 specification where {NGROUPS_MAX} may differ at runtime
and where getgroups may return {NGROUPS_MAX}+1 results on systems like
FreeBSD which include the primary group.

In id(1), don't pointlessly add the primary group to the list of all
groups, it is always the first result from getgroups().  In principle
the old code was more portable, but this was only done in one of the two
places where getgroups() was called to the overall effect was pointless.

Document the actual POSIX requirements in the getgroups(2) and
setgroups(2) manpages.  We do not yet support a dynamic NGROUPS, but we
may in the future.

MFC after:	2 weeks
2009-06-19 15:58:24 +00:00
Warner Losh
23717fc46a Per letter dated July 22, 1999, delete clause 3 from code directly
from Berkeley.
2004-08-07 04:19:37 +00:00
Philippe Charnier
0c806fab67 Use uid_t. 2003-09-07 16:43:53 +00:00
David E. O'Brien
b728350ee6 Use __FBSDID over rcsid[]. Protect copyright[] where needed. 2003-05-03 21:06:42 +00:00
Johan Karlsson
ae29e30076 Similar to chmod(1); make -v -v mean very verbose and show
the old and new uid/gid.

PR:		41341
Submitted by:	Edward Brocklesby <nighthawk@unrealircd.com>
Reviewed by:	bde@ (an older version)
2003-04-25 08:57:55 +00:00
David E. O'Brien
987d3799f3 Use basename(3). 2002-12-30 10:16:56 +00:00
David Malone
999feccf15 Fix a spelling mistake.
PR:		40695
Submitted by:	Maxim Maximov <mcsi@agava.com>
MFC after:	1 week
2002-07-17 16:22:24 +00:00
Juli Mallett
7aed2b41a4 Kill __P(), use ANSI C function declarations, remove local prototype for main,
and add a __FBSDID() while I'm here.
2002-06-30 15:30:14 +00:00
Juli Mallett
ec6c14f6eb In the SUPPORT_DOT case, warn that seperation with a period is deprecated.
In -STABLE, this is default, in -CURRENT it is not, which leads to many a
headache for a user coming to -CURRENT without remembering this fact.  It
is one of the POLA violations we have not avoided by preparing the users
for it appopriately.  Therefore, a warnx(3) is added here, explicitly to
be MFC'd shortly to start the re-education process rolling.

Reviewed by:	General murmurs of approval in that IRC channel.
MFC after:	3 days
2002-06-27 21:23:16 +00:00
Tim J. Robbins
dcafd7c96a Don't exit immediately if an error occurs, continue but exit non-zero. 2002-06-02 09:32:39 +00:00
Luigi Rizzo
69393d0646 Add prototypes for main() so that these programs compile with -Werror
(which somehow now seems to be the default for compiling -current).
This error popped up while doing a PicoBSD cross-compile on a 4.3-ish system,
it may well be that there are other apps which have similar problems,
but I did not spot them as they are not included in my picobsd config.

Whether adding prototypes for main() is the correct solution or not
I have no idea, a request to -current on the matter went basically
unanswered. Those who have better ideas are welcome to back this out
and replace it with the correct fix.
2001-12-14 16:22:41 +00:00
Ruslan Ermilov
8f9dacc2e6 Clean up, WARNSify, unbreak -v option handling. 2001-09-13 14:55:59 +00:00
Ruslan Ermilov
01b4e93eff Fixed the bug from the previous revision.
``chown -h owner symlink'' did not set the symlink's owner
if the file the symlink points to already had that owner:

# ls -l alink afile
-rw-r--r--  1 nobody  ru  0 May 31 14:14 afile
lrwxr-xr-x  1 root    ru  5 May 31 14:14 alink -> afile
# ./chown -h -v nobody alink
# ls -l alink afile
-rw-r--r--  1 nobody  ru  0 May 31 14:14 afile
lrwxr-xr-x  1 root    ru  5 May 31 14:14 alink -> afile

Similarly for chgrp(1) and chmod(1).
2001-05-31 11:47:20 +00:00
Ruslan Ermilov
8e46d9c279 Follow symbolic links named as command line arguments if run without -R.
This is required by symlink(7), ``Commands not traversing a file tree''
subsection, third paragraph:

: It is important to realize that this rule includes commands which may
: optionally traverse file trees, e.g. the command ``chown file'' is
: included in this rule, while the command ``chown -R file'' is not.

For chown(8) and chgrp(1), this is also is compliance with the latest
POSIX 1003.1-200x draft.

MFC after:	1 week
2001-05-28 12:58:10 +00:00
Peter Wemm
cc8660c75b Initialize vflag like the rest (not necessary, but this keeps it together)
Optimize out chown(2) syscalls if there is no change in uid or gid.
2000-07-29 22:22:11 +00:00
David E. O'Brien
0be12df092 Somehow I didn't get all the "-v" code commited.
Submitted by:	Arindum Mukerji <rmukerji@execpc.com>
Approved by:	JKH

Make the manpage more style(9) complient.
2000-03-08 16:31:42 +00:00
David E. O'Brien
5bb83b98db Add "-v". 1999-11-27 19:25:08 +00:00
Peter Wemm
97d92980a9 $Id$ -> $FreeBSD$ 1999-08-28 01:35:59 +00:00
Bruce Evans
ccee498fca Backed out previous commit. chown(8) doesn't follow symlinks by
default, at least in BSD.  This used to be automatic, because chown(2)
didn't follow symlinks.  When chown(2) was changed to follow symlinks
in BSD4.4, chown(8) was changed to not follow symlinks by default.
The previous commit broke this.  The first victim was bsd.prog.mk,
which uses a plain chown in an attempt to change the ownership of the
symlinks to `dm' in /usr/games.  This fails when it is done before
dm is installed, or messes up the ownership of dm if dm is installed.

Unfixed problems:
1. When lchown(2) was implemented, chown(8) wasn't changed to implement
   the historical behaviour of changing ownership of symlinks.  I'm not
   sure if it should have been.  The -HLP options give more complete
   control, but they unfortunately don't apply unless the -R option is
   specified (a problem shared with other commands, e.g., cp; I guess
   we're supposed to use -R even for non-recursive traversals).
2. If we implement the historical behaviour, then -h would become a no-op
   and should be left undocumented.
3. The man page suggests that without option -h, all symlinks (to files
   specified in the command line?) are followed.  It's not clear what
   "the file" is.  These bugs were introduced when -h was documented.
4. The correct interaction of -h with the other flags is not clear.
1998-05-03 04:17:48 +00:00
Wolfgang Helbig
3dd0615ba4 Don't ignore symbolic links in the absence of -h, -H or -L options.
Instead change the user ID/group ID of the file that the link points to.
1998-05-02 12:57:57 +00:00
Jordan K. Hubbard
6408ef3c4a Allow -R and -h to be combined as long as no symlink-following flags
are also requested.
Submitted by:	Andre Albsmeier <andre.albsmeier@mchp.siemens.de>
1998-03-09 08:54:31 +00:00
Wolfram Schneider
d95fc683ed Chown(8) compiled with -DSUPPORT_DOT (backward compatibility) does
first check for a `.' and then for `:' as a delimiter.
Usernames with a dot will fail.

# chown r.r:bin /tmp/bla
chown: r:bin: illegal group name

Fix: first check for a `:' and then for a `.'
1997-09-21 09:13:57 +00:00
Philippe Charnier
cc09f59a1e Cosmetic in man page. Sync usage() with man page. 1997-09-04 11:55:45 +00:00
Steve Price
573414e0c1 Correct error message when the superuser tries to change
the group of immutable files.

PR:		bin/3445
Submitted by:	Pius Fischer <pius@ienet.com>
1997-08-24 02:10:29 +00:00
Peter Wemm
2e08522b02 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.
1997-03-31 13:03:49 +00:00
Warner Losh
6c3f552a31 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-31 05:11:47 +00:00
Adam David
7ba57172c1 chown(8) and chgrp(1) directories once only 1996-08-14 18:13:58 +00:00
Rodney W. Grimes
709e8f9ae1 Remove trailing whitespace. 1995-05-30 03:57:47 +00:00
David Greenman
25738fbcc5 groups[] is of type gid_t. 1994-09-23 10:02:21 +00:00
Rodney W. Grimes
dea673e932 BSD 4.4 Lite usr.sbin Sources 1994-05-26 05:23:31 +00:00