blob: e6ac316e57a1597c93dd0982a34e431e2bc94075 [file] [log] [blame]
Eric Andersen9f0fedb2001-04-24 18:07:19 +00001/* vi: set sw=4 ts=4: */
2/*
Eric Andersenbdfd0d72001-10-24 05:00:29 +00003 * Mini chgrp implementation for busybox
Eric Andersen9f0fedb2001-04-24 18:07:19 +00004 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen9f0fedb2001-04-24 18:07:19 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen9f0fedb2001-04-24 18:07:19 +00008 */
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +01009//config:config CHGRP
Denys Vlasenkob097a842018-12-28 03:20:17 +010010//config: bool "chgrp (7.6 kb)"
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010011//config: default y
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: chgrp is used to change the group ownership of files.
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010014
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 Andersen9f0fedb2001-04-24 18:07:19 +000018
Denis Vlasenko02f0c4c2007-03-09 10:08:53 +000019/* BB_AUDIT SUSv3 defects - none? */
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000020/* BB_AUDIT GNU defects - unsupported long options. */
Manuel Novoa III cad53642003-03-19 09:13:01 +000021/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
22
Pere Orga34425382011-03-31 14:43:25 +020023//usage:#define chgrp_trivial_usage
Liu, Shuang (ADITG/ESM)af6bc542019-11-13 14:36:20 +000024//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... GROUP FILE..."
Pere Orga34425382011-03-31 14:43:25 +020025//usage:#define chgrp_full_usage "\n\n"
Denys Vlasenkoe2b92152021-06-14 20:47:20 +020026//usage: "Change the group membership of FILEs to GROUP"
27//usage: "\n"
Pere Orga34425382011-03-31 14:43:25 +020028//usage: "\n -h Affect symlinks instead of symlink targets"
Liu, Shuang (ADITG/ESM)af6bc542019-11-13 14:36:20 +000029//usage: IF_DESKTOP(
Pere Orga34425382011-03-31 14:43:25 +020030//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 Vlasenkoe2b92152021-06-14 20:47:20 +020033//usage: )
34//next 4 options are the same for chmod/chown/chgrp:
35//usage: "\n -R Recurse"
36//usage: IF_DESKTOP(
Pere Orga34425382011-03-31 14:43:25 +020037//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 Vlasenkob6adbf12007-05-26 19:00:18 +000049#include "libbb.h"
Eric Andersen9f0fedb2001-04-24 18:07:19 +000050
Denis Vlasenko99912ca2007-04-10 15:43:37 +000051/* This is a NOEXEC applet. Be very careful! */
52
53
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000054int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Eric Andersen9f0fedb2001-04-24 18:07:19 +000055int chgrp_main(int argc, char **argv)
56{
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000057 /* "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 Andersen9f0fedb2001-04-24 18:07:19 +000063 }
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000064 }
65 return chown_main(argc, argv);
Eric Andersen9f0fedb2001-04-24 18:07:19 +000066}