Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 3 | * Mini chgrp implementation for busybox |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 9 | //config:config CHGRP |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 10 | //config: bool "chgrp (7.6 kb)" |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 11 | //config: default y |
| 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: chgrp is used to change the group ownership of files. |
Denys Vlasenko | af3f420 | 2016-11-23 14:46:56 +0100 | [diff] [blame] | 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 |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 18 | |
Denis Vlasenko | 02f0c4c | 2007-03-09 10:08:53 +0000 | [diff] [blame] | 19 | /* BB_AUDIT SUSv3 defects - none? */ |
Denis Vlasenko | e80e2a3 | 2006-10-27 23:28:38 +0000 | [diff] [blame] | 20 | /* BB_AUDIT GNU defects - unsupported long options. */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 21 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ |
| 22 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 23 | //usage:#define chgrp_trivial_usage |
Liu, Shuang (ADITG/ESM) | af6bc54 | 2019-11-13 14:36:20 +0000 | [diff] [blame] | 24 | //usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... GROUP FILE..." |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 25 | //usage:#define chgrp_full_usage "\n\n" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 26 | //usage: "Change the group membership of FILEs to GROUP" |
| 27 | //usage: "\n" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 28 | //usage: "\n -h Affect symlinks instead of symlink targets" |
Liu, Shuang (ADITG/ESM) | af6bc54 | 2019-11-13 14:36:20 +0000 | [diff] [blame] | 29 | //usage: IF_DESKTOP( |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 30 | //usage: "\n -L Traverse all symlinks to directories" |
| 31 | //usage: "\n -H Traverse symlinks on command line only" |
| 32 | //usage: "\n -P Don't traverse symlinks (default)" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 33 | //usage: ) |
| 34 | //next 4 options are the same for chmod/chown/chgrp: |
| 35 | //usage: "\n -R Recurse" |
| 36 | //usage: IF_DESKTOP( |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 37 | //usage: "\n -c List changed files" |
| 38 | //usage: "\n -v Verbose" |
| 39 | //usage: "\n -f Hide errors" |
| 40 | //usage: ) |
| 41 | //usage: |
| 42 | //usage:#define chgrp_example_usage |
| 43 | //usage: "$ ls -l /tmp/foo\n" |
| 44 | //usage: "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" |
| 45 | //usage: "$ chgrp root /tmp/foo\n" |
| 46 | //usage: "$ ls -l /tmp/foo\n" |
| 47 | //usage: "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n" |
| 48 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 49 | #include "libbb.h" |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 50 | |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 51 | /* This is a NOEXEC applet. Be very careful! */ |
| 52 | |
| 53 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 54 | int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 55 | int chgrp_main(int argc, char **argv) |
| 56 | { |
Denis Vlasenko | e80e2a3 | 2006-10-27 23:28:38 +0000 | [diff] [blame] | 57 | /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */ |
| 58 | char **p = argv; |
| 59 | while (*++p) { |
| 60 | if (p[0][0] != '-') { |
| 61 | p[0] = xasprintf(":%s", p[0]); |
| 62 | break; |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 63 | } |
Denis Vlasenko | e80e2a3 | 2006-10-27 23:28:38 +0000 | [diff] [blame] | 64 | } |
| 65 | return chown_main(argc, argv); |
Eric Andersen | 9f0fedb | 2001-04-24 18:07:19 +0000 | [diff] [blame] | 66 | } |