aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-24 18:07:19 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-24 18:07:19 +0000
commit9f0fedb8f693829e7869439a2ad43cc1c21a3786 (patch)
tree10aa156e8cefad985eb3c9e5dafd68c22eb1e632
parent3a4aef5a4c145515a53c7d21a8d977fbc0892e32 (diff)
downloadbusybox-w32-9f0fedb8f693829e7869439a2ad43cc1c21a3786.tar.gz
busybox-w32-9f0fedb8f693829e7869439a2ad43cc1c21a3786.tar.bz2
busybox-w32-9f0fedb8f693829e7869439a2ad43cc1c21a3786.zip
Split up chmod_chown_chgrp.c into 3 separate apps. This unfortunately
adds 384 bytes to the overall size. But having each app be standalone is the Right Thing(tm) so we will just have to live with it. -Erik
-rw-r--r--Config.h4
-rw-r--r--Config.h.Hurd4
-rw-r--r--applets.h12
-rw-r--r--chgrp.c94
-rw-r--r--chmod.c87
-rw-r--r--chmod_chown_chgrp.c167
-rw-r--r--chown.c108
-rw-r--r--coreutils/chgrp.c94
-rw-r--r--coreutils/chmod.c87
-rw-r--r--coreutils/chown.c108
-rw-r--r--debian/Config.h-deb4
-rw-r--r--debian/Config.h-static4
-rw-r--r--debian/Config.h-udeb4
-rw-r--r--include/applets.h12
14 files changed, 605 insertions, 184 deletions
diff --git a/Config.h b/Config.h
index cbcf58d16..f7859479d 100644
--- a/Config.h
+++ b/Config.h
@@ -11,7 +11,9 @@
11//#define BB_AR 11//#define BB_AR
12#define BB_BASENAME 12#define BB_BASENAME
13#define BB_CAT 13#define BB_CAT
14#define BB_CHMOD_CHOWN_CHGRP 14#define BB_CHGRP
15#define BB_CHMOD
16#define BB_CHOWN
15#define BB_CHROOT 17#define BB_CHROOT
16#define BB_CHVT 18#define BB_CHVT
17#define BB_CLEAR 19#define BB_CLEAR
diff --git a/Config.h.Hurd b/Config.h.Hurd
index 3736b5789..f94e4a9e5 100644
--- a/Config.h.Hurd
+++ b/Config.h.Hurd
@@ -14,7 +14,9 @@
14#define BB_AR 14#define BB_AR
15#define BB_BASENAME 15#define BB_BASENAME
16#define BB_CAT 16#define BB_CAT
17#define BB_CHMOD_CHOWN_CHGRP 17#define BB_CHGRP
18#define BB_CHMOD
19#define BB_CHOWN
18#define BB_CHROOT 20#define BB_CHROOT
19//#define BB_CHVT /* not needed */ 21//#define BB_CHVT /* not needed */
20#define BB_CLEAR 22#define BB_CLEAR
diff --git a/applets.h b/applets.h
index d3399b9af..0fd89c71a 100644
--- a/applets.h
+++ b/applets.h
@@ -59,14 +59,14 @@
59#ifdef BB_CAT 59#ifdef BB_CAT
60 APPLET(cat, cat_main, _BB_DIR_BIN) 60 APPLET(cat, cat_main, _BB_DIR_BIN)
61#endif 61#endif
62#ifdef BB_CHMOD_CHOWN_CHGRP 62#ifdef BB_CHGRP
63 APPLET(chgrp, chmod_chown_chgrp_main, _BB_DIR_BIN) 63 APPLET(chgrp, chgrp_main, _BB_DIR_BIN)
64#endif 64#endif
65#ifdef BB_CHMOD_CHOWN_CHGRP 65#ifdef BB_CHMOD
66 APPLET(chmod, chmod_chown_chgrp_main, _BB_DIR_BIN) 66 APPLET(chmod, chmod_main, _BB_DIR_BIN)
67#endif 67#endif
68#ifdef BB_CHMOD_CHOWN_CHGRP 68#ifdef BB_CHOWN
69 APPLET(chown, chmod_chown_chgrp_main, _BB_DIR_BIN) 69 APPLET(chown, chown_main, _BB_DIR_BIN)
70#endif 70#endif
71#ifdef BB_CHROOT 71#ifdef BB_CHROOT
72 APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN) 72 APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN)
diff --git a/chgrp.c b/chgrp.c
new file mode 100644
index 000000000..739d09fb6
--- /dev/null
+++ b/chgrp.c
@@ -0,0 +1,94 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include "busybox.h"
30#define BB_DECLARE_EXTERN
31#define bb_need_invalid_option
32#define bb_need_too_few_args
33#include "messages.c"
34
35/* Don't use lchown for libc5 or glibc older then 2.1.x */
36#if (__GLIBC__ < 2) && (__GLIBC_MINOR__ < 1)
37#define lchown chown
38#endif
39
40
41static long gid = -1;
42
43static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
44{
45 if (lchown(fileName, statbuf->st_uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
46 return (TRUE);
47 }
48 perror(fileName);
49 return (FALSE);
50}
51
52int chgrp_main(int argc, char **argv)
53{
54 int opt;
55 int recursiveFlag = FALSE;
56 char *p=NULL;
57
58 /* do normal option parsing */
59 while ((opt = getopt(argc, argv, "R")) > 0) {
60 switch (opt) {
61 case 'R':
62 recursiveFlag = TRUE;
63 default:
64 show_usage();
65 }
66 }
67
68 if (argc > optind && argc > 2 && argv[optind]) {
69 /* Find the selected group */
70 gid = strtoul(argv[optind], &p, 10); /* maybe it's already numeric */
71 if (argv[optind] == p)
72 gid = my_getgrnam(argv[optind]);
73 } else {
74 error_msg_and_die(too_few_args);
75 }
76
77 /* Ok, ready to do the deed now */
78 while (optind++ < argc) {
79 if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
80 fileAction, fileAction, NULL) == FALSE) {
81 return EXIT_FAILURE;
82 }
83 }
84 return EXIT_SUCCESS;
85
86}
87
88/*
89Local Variables:
90c-file-style: "linux"
91c-basic-offset: 4
92tab-width: 4
93End:
94*/
diff --git a/chmod.c b/chmod.c
new file mode 100644
index 000000000..c3bef4ebe
--- /dev/null
+++ b/chmod.c
@@ -0,0 +1,87 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include <getopt.h>
30#include "busybox.h"
31#define BB_DECLARE_EXTERN
32#define bb_need_too_few_args
33#include "messages.c"
34
35
36struct stat *theMode;
37
38
39static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
40{
41 if (chmod(fileName, theMode->st_mode) == 0)
42 return (TRUE);
43 perror(fileName);
44 return (FALSE);
45}
46
47int chmod_main(int argc, char **argv)
48{
49 int opt;
50 int recursiveFlag = FALSE;
51
52 /* do normal option parsing */
53 while ((opt = getopt(argc, argv, "R")) > 0) {
54 switch (opt) {
55 case 'R':
56 recursiveFlag = TRUE;
57 default:
58 show_usage();
59 }
60 }
61
62 if (argc > optind && argc > 2 && argv[optind]) {
63 /* Parse the specified mode */
64 if (parse_mode(argv[optind], &(theMode->st_mode)) == FALSE) {
65 error_msg_and_die( "unknown mode: %s", argv[optind]);
66 }
67 } else {
68 error_msg_and_die(too_few_args);
69 }
70
71 /* Ok, ready to do the deed now */
72 while (optind++ < argc) {
73 if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
74 fileAction, fileAction, NULL) == FALSE) {
75 return EXIT_FAILURE;
76 }
77 }
78 return EXIT_SUCCESS;
79}
80
81/*
82Local Variables:
83c-file-style: "linux"
84c-basic-offset: 4
85tab-width: 4
86End:
87*/
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
deleted file mode 100644
index 9714e1ca5..000000000
--- a/chmod_chown_chgrp.c
+++ /dev/null
@@ -1,167 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include "busybox.h"
30#define BB_DECLARE_EXTERN
31#define bb_need_invalid_option
32#define bb_need_too_few_args
33#include "messages.c"
34
35
36
37static long uid = -1;
38static long gid = -1;
39static int whichApp;
40static char *theMode = NULL;
41
42
43#define CHGRP_APP 1
44#define CHOWN_APP 2
45#define CHMOD_APP 3
46
47static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
48{
49 switch (whichApp) {
50 case CHGRP_APP:
51 case CHOWN_APP:
52 /* Don't use lchown for libc5 or glibc older then 2.1.x */
53#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
54 if (lchown
55 (fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
56 (gid == -1) ? statbuf->st_gid : gid) == 0)
57#else
58 if (chown
59 (fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
60 (gid == -1) ? statbuf->st_gid : gid) == 0)
61#endif
62 {
63 return (TRUE);
64 }
65 break;
66 case CHMOD_APP:
67 /* Parse the specified modes */
68 if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) {
69 error_msg_and_die( "unknown mode: %s", theMode);
70 }
71 if (chmod(fileName, statbuf->st_mode) == 0)
72 return (TRUE);
73 break;
74 }
75 perror(fileName);
76 return (FALSE);
77}
78
79int chmod_chown_chgrp_main(int argc, char **argv)
80{
81 int stopIt = FALSE;
82 int recursiveFlag = FALSE;
83 char *groupName=NULL;
84 char *p=NULL;
85
86 whichApp = (applet_name[2]=='o')? /* chown */
87 CHOWN_APP : (applet_name[2]=='m')? /* chmod */
88 CHMOD_APP : CHGRP_APP;
89
90 if (argc < 2)
91 show_usage();
92 argv++;
93
94 /* Parse options */
95 while (--argc >= 0 && *argv && (**argv == '-')) {
96 while (stopIt==FALSE && *++(*argv)) {
97 switch (**argv) {
98 case 'R':
99 recursiveFlag = TRUE;
100 break;
101 default:
102 theMode=*argv-1;
103 stopIt = TRUE;
104 }
105 }
106 if (stopIt==TRUE)
107 break;
108 argv++;
109 }
110
111 if (argc == 0 || *argv == NULL) {
112 error_msg(too_few_args);
113 }
114
115 if (whichApp == CHMOD_APP) {
116 if (theMode==NULL)
117 theMode = *argv;
118 } else {
119
120 /* Find the selected group */
121 if (whichApp == CHGRP_APP) {
122 groupName = *argv;
123 gid = strtoul(groupName, &p, 10); /* maybe it's already numeric */
124 if (groupName == p)
125 gid = my_getgrnam(groupName);
126 } else {
127 groupName = strchr(*argv, '.');
128 if (groupName == NULL)
129 groupName = strchr(*argv, ':');
130 if (groupName) {
131 *groupName++ = '\0';
132 gid = strtoul(groupName, &p, 10);
133 if (groupName == p)
134 gid = my_getgrnam(groupName);
135 } else
136 gid = -1;
137 }
138
139
140 /* Find the selected user (if appropriate) */
141 if (whichApp == CHOWN_APP) {
142 uid = strtoul(*argv, &p, 10); /* if numeric ... */
143 if (*argv == p)
144 uid = my_getpwnam(*argv);
145 }
146 }
147
148 /* Ok, ready to do the deed now */
149 if (argc < 1) {
150 error_msg_and_die(too_few_args);
151 }
152 while (argc-- > 1) {
153 if (recursive_action (*(++argv), recursiveFlag, FALSE, FALSE,
154 fileAction, fileAction, NULL) == FALSE)
155 return EXIT_FAILURE;
156 }
157 return EXIT_SUCCESS;
158
159}
160
161/*
162Local Variables:
163c-file-style: "linux"
164c-basic-offset: 4
165tab-width: 4
166End:
167*/
diff --git a/chown.c b/chown.c
new file mode 100644
index 000000000..f044a7527
--- /dev/null
+++ b/chown.c
@@ -0,0 +1,108 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include "busybox.h"
30#define BB_DECLARE_EXTERN
31#define bb_need_too_few_args
32#include "messages.c"
33
34
35/* Don't use lchown for libc5 or glibc older then 2.1.x */
36#if (__GLIBC__ < 2) && (__GLIBC_MINOR__ < 1)
37#define lchown chown
38#endif
39
40static long uid = -1;
41static long gid = -1;
42
43static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
44{
45 if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
46 return (TRUE);
47 }
48 perror(fileName);
49 return (FALSE);
50}
51
52int chown_main(int argc, char **argv)
53{
54 int opt;
55 int recursiveFlag = FALSE;
56 char *groupName=NULL;
57 char *p=NULL;
58
59 /* do normal option parsing */
60 while ((opt = getopt(argc, argv, "R")) > 0) {
61 switch (opt) {
62 case 'R':
63 recursiveFlag = TRUE;
64 default:
65 show_usage();
66 }
67 }
68
69 if (argc > optind && argc > 2 && argv[optind]) {
70 /* First, check if there is a group name here */
71 groupName = strchr(argv[optind], '.');
72 if (groupName == NULL)
73 groupName = strchr(argv[optind], ':');
74 if (groupName) {
75 *groupName++ = '\0';
76 gid = strtoul(groupName, &p, 10);
77 if (groupName == p)
78 gid = my_getgrnam(groupName);
79 } else {
80 gid = -1;
81 }
82 /* Now check for the username */
83 uid = strtoul(argv[optind], &p, 10); /* Is is numeric? */
84 if (argv[optind] == p) {
85 uid = my_getpwnam(argv[optind]);
86 }
87 } else {
88 error_msg_and_die(too_few_args);
89 }
90
91 /* Ok, ready to do the deed now */
92 while (optind++ < argc) {
93 if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
94 fileAction, fileAction, NULL) == FALSE) {
95 return EXIT_FAILURE;
96 }
97 }
98 return EXIT_SUCCESS;
99
100}
101
102/*
103Local Variables:
104c-file-style: "linux"
105c-basic-offset: 4
106tab-width: 4
107End:
108*/
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c
new file mode 100644
index 000000000..739d09fb6
--- /dev/null
+++ b/coreutils/chgrp.c
@@ -0,0 +1,94 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include "busybox.h"
30#define BB_DECLARE_EXTERN
31#define bb_need_invalid_option
32#define bb_need_too_few_args
33#include "messages.c"
34
35/* Don't use lchown for libc5 or glibc older then 2.1.x */
36#if (__GLIBC__ < 2) && (__GLIBC_MINOR__ < 1)
37#define lchown chown
38#endif
39
40
41static long gid = -1;
42
43static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
44{
45 if (lchown(fileName, statbuf->st_uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
46 return (TRUE);
47 }
48 perror(fileName);
49 return (FALSE);
50}
51
52int chgrp_main(int argc, char **argv)
53{
54 int opt;
55 int recursiveFlag = FALSE;
56 char *p=NULL;
57
58 /* do normal option parsing */
59 while ((opt = getopt(argc, argv, "R")) > 0) {
60 switch (opt) {
61 case 'R':
62 recursiveFlag = TRUE;
63 default:
64 show_usage();
65 }
66 }
67
68 if (argc > optind && argc > 2 && argv[optind]) {
69 /* Find the selected group */
70 gid = strtoul(argv[optind], &p, 10); /* maybe it's already numeric */
71 if (argv[optind] == p)
72 gid = my_getgrnam(argv[optind]);
73 } else {
74 error_msg_and_die(too_few_args);
75 }
76
77 /* Ok, ready to do the deed now */
78 while (optind++ < argc) {
79 if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
80 fileAction, fileAction, NULL) == FALSE) {
81 return EXIT_FAILURE;
82 }
83 }
84 return EXIT_SUCCESS;
85
86}
87
88/*
89Local Variables:
90c-file-style: "linux"
91c-basic-offset: 4
92tab-width: 4
93End:
94*/
diff --git a/coreutils/chmod.c b/coreutils/chmod.c
new file mode 100644
index 000000000..c3bef4ebe
--- /dev/null
+++ b/coreutils/chmod.c
@@ -0,0 +1,87 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include <getopt.h>
30#include "busybox.h"
31#define BB_DECLARE_EXTERN
32#define bb_need_too_few_args
33#include "messages.c"
34
35
36struct stat *theMode;
37
38
39static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
40{
41 if (chmod(fileName, theMode->st_mode) == 0)
42 return (TRUE);
43 perror(fileName);
44 return (FALSE);
45}
46
47int chmod_main(int argc, char **argv)
48{
49 int opt;
50 int recursiveFlag = FALSE;
51
52 /* do normal option parsing */
53 while ((opt = getopt(argc, argv, "R")) > 0) {
54 switch (opt) {
55 case 'R':
56 recursiveFlag = TRUE;
57 default:
58 show_usage();
59 }
60 }
61
62 if (argc > optind && argc > 2 && argv[optind]) {
63 /* Parse the specified mode */
64 if (parse_mode(argv[optind], &(theMode->st_mode)) == FALSE) {
65 error_msg_and_die( "unknown mode: %s", argv[optind]);
66 }
67 } else {
68 error_msg_and_die(too_few_args);
69 }
70
71 /* Ok, ready to do the deed now */
72 while (optind++ < argc) {
73 if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
74 fileAction, fileAction, NULL) == FALSE) {
75 return EXIT_FAILURE;
76 }
77 }
78 return EXIT_SUCCESS;
79}
80
81/*
82Local Variables:
83c-file-style: "linux"
84c-basic-offset: 4
85tab-width: 4
86End:
87*/
diff --git a/coreutils/chown.c b/coreutils/chown.c
new file mode 100644
index 000000000..f044a7527
--- /dev/null
+++ b/coreutils/chown.c
@@ -0,0 +1,108 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chown/chmod/chgrp implementation for busybox
4 *
5 *
6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
7 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29#include "busybox.h"
30#define BB_DECLARE_EXTERN
31#define bb_need_too_few_args
32#include "messages.c"
33
34
35/* Don't use lchown for libc5 or glibc older then 2.1.x */
36#if (__GLIBC__ < 2) && (__GLIBC_MINOR__ < 1)
37#define lchown chown
38#endif
39
40static long uid = -1;
41static long gid = -1;
42
43static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
44{
45 if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
46 return (TRUE);
47 }
48 perror(fileName);
49 return (FALSE);
50}
51
52int chown_main(int argc, char **argv)
53{
54 int opt;
55 int recursiveFlag = FALSE;
56 char *groupName=NULL;
57 char *p=NULL;
58
59 /* do normal option parsing */
60 while ((opt = getopt(argc, argv, "R")) > 0) {
61 switch (opt) {
62 case 'R':
63 recursiveFlag = TRUE;
64 default:
65 show_usage();
66 }
67 }
68
69 if (argc > optind && argc > 2 && argv[optind]) {
70 /* First, check if there is a group name here */
71 groupName = strchr(argv[optind], '.');
72 if (groupName == NULL)
73 groupName = strchr(argv[optind], ':');
74 if (groupName) {
75 *groupName++ = '\0';
76 gid = strtoul(groupName, &p, 10);
77 if (groupName == p)
78 gid = my_getgrnam(groupName);
79 } else {
80 gid = -1;
81 }
82 /* Now check for the username */
83 uid = strtoul(argv[optind], &p, 10); /* Is is numeric? */
84 if (argv[optind] == p) {
85 uid = my_getpwnam(argv[optind]);
86 }
87 } else {
88 error_msg_and_die(too_few_args);
89 }
90
91 /* Ok, ready to do the deed now */
92 while (optind++ < argc) {
93 if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
94 fileAction, fileAction, NULL) == FALSE) {
95 return EXIT_FAILURE;
96 }
97 }
98 return EXIT_SUCCESS;
99
100}
101
102/*
103Local Variables:
104c-file-style: "linux"
105c-basic-offset: 4
106tab-width: 4
107End:
108*/
diff --git a/debian/Config.h-deb b/debian/Config.h-deb
index 038fd7c37..ff912ef6a 100644
--- a/debian/Config.h-deb
+++ b/debian/Config.h-deb
@@ -10,7 +10,9 @@
10#define BB_AR 10#define BB_AR
11#define BB_BASENAME 11#define BB_BASENAME
12#define BB_CAT 12#define BB_CAT
13#define BB_CHMOD_CHOWN_CHGRP 13#define BB_CHGRP
14#define BB_CHMOD
15#define BB_CHOWN
14#define BB_CHROOT 16#define BB_CHROOT
15#define BB_CHVT 17#define BB_CHVT
16#define BB_CLEAR 18#define BB_CLEAR
diff --git a/debian/Config.h-static b/debian/Config.h-static
index ad26f8b15..4068290a6 100644
--- a/debian/Config.h-static
+++ b/debian/Config.h-static
@@ -10,7 +10,9 @@
10#define BB_AR 10#define BB_AR
11#define BB_BASENAME 11#define BB_BASENAME
12#define BB_CAT 12#define BB_CAT
13#define BB_CHMOD_CHOWN_CHGRP 13#define BB_CHGRP
14#define BB_CHMOD
15#define BB_CHOWN
14#define BB_CHROOT 16#define BB_CHROOT
15#define BB_CHVT 17#define BB_CHVT
16#define BB_CLEAR 18#define BB_CLEAR
diff --git a/debian/Config.h-udeb b/debian/Config.h-udeb
index b669bb156..dee98f2cc 100644
--- a/debian/Config.h-udeb
+++ b/debian/Config.h-udeb
@@ -10,7 +10,9 @@
10//#define BB_AR 10//#define BB_AR
11#define BB_BASENAME 11#define BB_BASENAME
12#define BB_CAT 12#define BB_CAT
13#define BB_CHMOD_CHOWN_CHGRP 13#define BB_CHGRP
14#define BB_CHMOD
15#define BB_CHOWN
14#define BB_CHROOT 16#define BB_CHROOT
15#define BB_CHVT 17#define BB_CHVT
16#define BB_CLEAR 18#define BB_CLEAR
diff --git a/include/applets.h b/include/applets.h
index d3399b9af..0fd89c71a 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -59,14 +59,14 @@
59#ifdef BB_CAT 59#ifdef BB_CAT
60 APPLET(cat, cat_main, _BB_DIR_BIN) 60 APPLET(cat, cat_main, _BB_DIR_BIN)
61#endif 61#endif
62#ifdef BB_CHMOD_CHOWN_CHGRP 62#ifdef BB_CHGRP
63 APPLET(chgrp, chmod_chown_chgrp_main, _BB_DIR_BIN) 63 APPLET(chgrp, chgrp_main, _BB_DIR_BIN)
64#endif 64#endif
65#ifdef BB_CHMOD_CHOWN_CHGRP 65#ifdef BB_CHMOD
66 APPLET(chmod, chmod_chown_chgrp_main, _BB_DIR_BIN) 66 APPLET(chmod, chmod_main, _BB_DIR_BIN)
67#endif 67#endif
68#ifdef BB_CHMOD_CHOWN_CHGRP 68#ifdef BB_CHOWN
69 APPLET(chown, chmod_chown_chgrp_main, _BB_DIR_BIN) 69 APPLET(chown, chown_main, _BB_DIR_BIN)
70#endif 70#endif
71#ifdef BB_CHROOT 71#ifdef BB_CHROOT
72 APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN) 72 APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN)