blob: 4da43c45e4a6388eb40da168a9ec1e876d3aeeb6 [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"
26//usage: "Change the group membership of each FILE to GROUP\n"
Pere Orga34425382011-03-31 14:43:25 +020027//usage: "\n -R Recurse"
28//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)"
Pere Orga34425382011-03-31 14:43:25 +020033//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
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000045#include "libbb.h"
Eric Andersen9f0fedb2001-04-24 18:07:19 +000046
Denis Vlasenko99912ca2007-04-10 15:43:37 +000047/* This is a NOEXEC applet. Be very careful! */
48
49
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000050int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Eric Andersen9f0fedb2001-04-24 18:07:19 +000051int chgrp_main(int argc, char **argv)
52{
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000053 /* "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;
Eric Andersen9f0fedb2001-04-24 18:07:19 +000059 }
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000060 }
61 return chown_main(argc, argv);
Eric Andersen9f0fedb2001-04-24 18:07:19 +000062}