blob: 8dca63cf705db4580b768cbbf6414e4fefe9d411
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Mini chgrp implementation for busybox |
4 | * |
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ |
9 | //config:config CHGRP |
10 | //config: bool "chgrp" |
11 | //config: default y |
12 | //config: help |
13 | //config: chgrp is used to change the group ownership of files. |
14 | |
15 | //applet:IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp)) |
16 | |
17 | //kbuild:lib-$(CONFIG_CHGRP) += chgrp.o chown.o |
18 | |
19 | /* BB_AUDIT SUSv3 defects - none? */ |
20 | /* BB_AUDIT GNU defects - unsupported long options. */ |
21 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ |
22 | |
23 | //usage:#define chgrp_trivial_usage |
24 | //usage: "[-RhLHP"IF_DESKTOP("cvf")"]... GROUP FILE..." |
25 | //usage:#define chgrp_full_usage "\n\n" |
26 | //usage: "Change the group membership of each FILE to GROUP\n" |
27 | //usage: "\n -R Recurse" |
28 | //usage: "\n -h Affect symlinks instead of symlink targets" |
29 | //usage: "\n -L Traverse all symlinks to directories" |
30 | //usage: "\n -H Traverse symlinks on command line only" |
31 | //usage: "\n -P Don't traverse symlinks (default)" |
32 | //usage: IF_DESKTOP( |
33 | //usage: "\n -c List changed files" |
34 | //usage: "\n -v Verbose" |
35 | //usage: "\n -f Hide errors" |
36 | //usage: ) |
37 | //usage: |
38 | //usage:#define chgrp_example_usage |
39 | //usage: "$ ls -l /tmp/foo\n" |
40 | //usage: "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" |
41 | //usage: "$ chgrp root /tmp/foo\n" |
42 | //usage: "$ ls -l /tmp/foo\n" |
43 | //usage: "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n" |
44 | |
45 | #include "libbb.h" |
46 | |
47 | /* This is a NOEXEC applet. Be very careful! */ |
48 | |
49 | |
50 | int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
51 | int chgrp_main(int argc, char **argv) |
52 | { |
53 | /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */ |
54 | char **p = argv; |
55 | while (*++p) { |
56 | if (p[0][0] != '-') { |
57 | p[0] = xasprintf(":%s", p[0]); |
58 | break; |
59 | } |
60 | } |
61 | return chown_main(argc, argv); |
62 | } |
63 |