diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-05 22:58:32 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-05 22:58:32 +0000 |
commit | 2b69c40e8060934c115922c012737bd471956f09 (patch) | |
tree | c92657a42b94419ab9579e8c52639c301764ec40 /coreutils | |
parent | cc8ed39b240180b58810784f844e253263594ac3 (diff) | |
download | busybox-w32-2b69c40e8060934c115922c012737bd471956f09.tar.gz busybox-w32-2b69c40e8060934c115922c012737bd471956f09.tar.bz2 busybox-w32-2b69c40e8060934c115922c012737bd471956f09.zip |
More stuff works.
-Erik
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cat.c | 8 | ||||
-rw-r--r-- | coreutils/chgrp.c | 89 | ||||
-rw-r--r-- | coreutils/chown.c | 156 | ||||
-rw-r--r-- | coreutils/chroot.c | 73 |
4 files changed, 166 insertions, 160 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 12faf55ab..0f2460eb7 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -31,7 +31,7 @@ extern int cat_more_main(int argc, char **argv) | |||
31 | 31 | ||
32 | if (argc < 2) { | 32 | if (argc < 2) { |
33 | fprintf(stderr, "Usage: %s %s", *argv, cat_usage); | 33 | fprintf(stderr, "Usage: %s %s", *argv, cat_usage); |
34 | return 1; | 34 | return(FALSE); |
35 | } | 35 | } |
36 | argc--; | 36 | argc--; |
37 | argv++; | 37 | argv++; |
@@ -39,8 +39,8 @@ extern int cat_more_main(int argc, char **argv) | |||
39 | while (argc-- > 0) { | 39 | while (argc-- > 0) { |
40 | file = fopen(*argv, "r"); | 40 | file = fopen(*argv, "r"); |
41 | if (file == NULL) { | 41 | if (file == NULL) { |
42 | name_and_error(*argv); | 42 | perror(*argv); |
43 | return 1; | 43 | return(FALSE); |
44 | } | 44 | } |
45 | while ((c = getc(file)) != EOF) | 45 | while ((c = getc(file)) != EOF) |
46 | putc(c, stdout); | 46 | putc(c, stdout); |
@@ -50,5 +50,5 @@ extern int cat_more_main(int argc, char **argv) | |||
50 | argc--; | 50 | argc--; |
51 | argv++; | 51 | argv++; |
52 | } | 52 | } |
53 | return 0; | 53 | return(TRUE); |
54 | } | 54 | } |
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c deleted file mode 100644 index 038c665dd..000000000 --- a/coreutils/chgrp.c +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | /* | ||
2 | * Mini chgrp implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include "internal.h" | ||
23 | #include <grp.h> | ||
24 | #include <stdio.h> | ||
25 | |||
26 | const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n" | ||
27 | "Change the group membership of each FILE to GROUP.\n" | ||
28 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | ||
29 | |||
30 | int chgrp_main(int argc, char **argv) | ||
31 | { | ||
32 | const char *cp; | ||
33 | int gid; | ||
34 | struct group *grp; | ||
35 | struct stat statBuf; | ||
36 | |||
37 | if (argc < 2) { | ||
38 | fprintf(stderr, "Usage: %s %s", *argv, chgrp_usage); | ||
39 | return 1; | ||
40 | } | ||
41 | argc--; | ||
42 | argv++; | ||
43 | |||
44 | cp = argv[1]; | ||
45 | if (isDecimal(*cp)) { | ||
46 | gid = 0; | ||
47 | while (isDecimal(*cp)) | ||
48 | gid = gid * 10 + (*cp++ - '0'); | ||
49 | if (*cp) { | ||
50 | fprintf(stderr, "Bad gid value\n"); | ||
51 | return -1; | ||
52 | } | ||
53 | } else { | ||
54 | grp = getgrnam(cp); | ||
55 | if (grp == NULL) { | ||
56 | fprintf(stderr, "Unknown group name\n"); | ||
57 | return -1; | ||
58 | } | ||
59 | gid = grp->gr_gid; | ||
60 | } | ||
61 | argc--; | ||
62 | argv++; | ||
63 | while (argc-- > 1) { | ||
64 | argv++; | ||
65 | if ((stat(*argv, &statBuf) < 0) || | ||
66 | (chown(*argv, statBuf.st_uid, gid) < 0)) { | ||
67 | perror(*argv); | ||
68 | } | ||
69 | } | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
80 | |||
81 | #if 0 | ||
82 | int | ||
83 | recursive(const char *fileName, BOOL followLinks, const char *pattern, | ||
84 | int (*fileAction) (const char *fileName, | ||
85 | const struct stat * statbuf), | ||
86 | int (*dirAction) (const char *fileName, | ||
87 | const struct stat * statbuf)) | ||
88 | |||
89 | #endif | ||
diff --git a/coreutils/chown.c b/coreutils/chown.c index a611f92f1..fc0c2424f 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
@@ -1,63 +1,125 @@ | |||
1 | #include "internal.h" | 1 | /* |
2 | #include <pwd.h> | 2 | * Mini chown/chgrp implementation for busybox |
3 | #include <grp.h> | 3 | * |
4 | #include <string.h> | 4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> |
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
5 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <grp.h> | ||
24 | #include <pwd.h> | ||
25 | #include "internal.h" | ||
6 | 26 | ||
7 | const char chown_usage[] = "chown [-R] user-name file [file ...]\n" | ||
8 | "\n\tThe group list is kept in the file /etc/groups.\n\n" | ||
9 | "\t-R:\tRecursively change the mode of all files and directories\n" | ||
10 | "\t\tunder the argument directory."; | ||
11 | 27 | ||
12 | int | 28 | static int uid=-1; |
13 | parse_user_name(const char * s, struct FileInfo * i) | 29 | static int gid=0; |
14 | { | 30 | static int chownApp; |
15 | struct passwd * p; | 31 | static char* invocationName=NULL; |
16 | char * dot = strchr(s, '.'); | ||
17 | 32 | ||
18 | if (! dot ) | ||
19 | dot = strchr(s, ':'); | ||
20 | 33 | ||
21 | if ( dot ) | 34 | const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n" |
22 | *dot = '\0'; | 35 | "Change the group membership of each FILE to GROUP.\n" |
36 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | ||
37 | const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n" | ||
38 | "Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" | ||
39 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | ||
23 | 40 | ||
24 | if ( (p = getpwnam(s)) == 0 ) { | 41 | |
25 | fprintf(stderr, "%s: no such user.\n", s); | 42 | |
26 | return 1; | 43 | static int fileAction(const char *fileName) |
27 | } | 44 | { |
28 | i->userID = p->pw_uid; | 45 | struct stat statBuf; |
29 | 46 | if ((stat(fileName, &statBuf) < 0) || | |
30 | if ( dot ) { | 47 | (chown(fileName, |
31 | struct group * g = getgrnam(++dot); | 48 | ((chownApp==TRUE)? uid: statBuf.st_uid), |
32 | if ( g == 0 ) { | 49 | gid) < 0)) { |
33 | fprintf(stderr, "%s: no such group.\n", dot); | 50 | perror(fileName); |
34 | return 1; | 51 | return( TRUE); |
35 | } | 52 | } |
36 | i->groupID = g->gr_gid; | 53 | return( FALSE); |
37 | i->changeGroupID = 1; | ||
38 | } | ||
39 | return 0; | ||
40 | } | 54 | } |
41 | 55 | ||
42 | extern int | 56 | int chown_main(int argc, char **argv) |
43 | chown_main(struct FileInfo * i, int argc, char * * argv) | ||
44 | { | 57 | { |
45 | int status; | 58 | struct group *grp; |
59 | struct passwd *pwd; | ||
60 | int recursiveFlag=FALSE; | ||
61 | char *groupName; | ||
46 | 62 | ||
47 | while ( argc >= 3 && strcmp("-R", argv[1]) == 0 ) { | ||
48 | i->recursive = 1; | ||
49 | argc--; | ||
50 | argv++; | ||
51 | } | ||
52 | 63 | ||
53 | if ( (status = parse_user_name(argv[1], i)) != 0 ) | 64 | chownApp = (strcmp(*argv, "chown")==0)? TRUE : FALSE; |
54 | return status; | ||
55 | 65 | ||
56 | argv++; | 66 | if (argc < 2) { |
67 | fprintf(stderr, "Usage: %s %s", *argv, | ||
68 | (chownApp==TRUE)? chown_usage : chgrp_usage); | ||
69 | return( FALSE); | ||
70 | } | ||
71 | invocationName=*argv; | ||
72 | argc--; | ||
73 | argv++; | ||
74 | |||
75 | /* Parse options */ | ||
76 | while (**argv == '-') { | ||
77 | while (*++(*argv)) switch (**argv) { | ||
78 | case 'R': | ||
79 | recursiveFlag = TRUE; | ||
80 | break; | ||
81 | default: | ||
82 | fprintf(stderr, "Unknown option: %c\n", **argv); | ||
83 | return( FALSE); | ||
84 | } | ||
57 | argc--; | 85 | argc--; |
86 | argv++; | ||
87 | } | ||
88 | |||
89 | /* Find the selected group */ | ||
90 | groupName = strchr(*argv, '.'); | ||
91 | if ( chownApp==TRUE && groupName ) | ||
92 | *groupName++ = '\0'; | ||
93 | else | ||
94 | groupName = *argv; | ||
95 | grp = getgrnam(groupName); | ||
96 | if (grp == NULL) { | ||
97 | fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName); | ||
98 | return( FALSE); | ||
99 | } | ||
100 | gid = grp->gr_gid; | ||
58 | 101 | ||
59 | i->changeUserID = 1; | 102 | /* Find the selected user (if appropriate) */ |
60 | i->complainInPostProcess = 1; | 103 | if (chownApp==TRUE) { |
104 | pwd = getpwnam(*argv); | ||
105 | if (pwd == NULL) { | ||
106 | fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv); | ||
107 | return( FALSE); | ||
108 | } | ||
109 | uid = pwd->pw_uid; | ||
110 | } | ||
61 | 111 | ||
62 | return monadic_main(i, argc, argv); | 112 | /* Ok, ready to do the deed now */ |
113 | if (argc <= 1) { | ||
114 | fprintf(stderr, "%s: too few arguments", invocationName); | ||
115 | return( FALSE); | ||
116 | } | ||
117 | while (argc-- > 1) { | ||
118 | argv++; | ||
119 | if (recursiveFlag==TRUE) | ||
120 | recursiveAction( *argv, TRUE, fileAction, fileAction); | ||
121 | else | ||
122 | fileAction( *argv); | ||
123 | } | ||
124 | return(TRUE); | ||
63 | } | 125 | } |
diff --git a/coreutils/chroot.c b/coreutils/chroot.c index ca0bfcf3f..d39549496 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c | |||
@@ -1,32 +1,65 @@ | |||
1 | /* | ||
2 | * Mini chroot implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
1 | #include "internal.h" | 22 | #include "internal.h" |
2 | #include <stdio.h> | 23 | #include <stdio.h> |
3 | #include <unistd.h> | 24 | #include <unistd.h> |
4 | 25 | ||
5 | 26 | ||
6 | const char chroot_usage[] = "chroot directory [command]\n" | 27 | static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" |
7 | "Run a command with special root directory.\n"; | 28 | "Run COMMAND with root directory set to NEWROOT.\n"; |
29 | |||
30 | |||
8 | 31 | ||
9 | extern int | 32 | int chroot_main(int argc, char **argv) |
10 | chroot_main (struct FileInfo *i, int argc, char **argv) | ||
11 | { | 33 | { |
12 | char *prog; | 34 | if (argc < 2) { |
35 | fprintf(stderr, "Usage: %s %s", *argv, chroot_usage); | ||
36 | return( FALSE); | ||
37 | } | ||
38 | argc--; | ||
39 | argv++; | ||
13 | 40 | ||
14 | if (chroot (argv[1])) | 41 | fprintf(stderr, "new root: %s\n", *argv); |
15 | { | 42 | |
16 | name_and_error ("cannot chroot to that directory"); | 43 | if (chroot (*argv) || (chdir ("/"))) { |
17 | return 1; | 44 | perror("cannot chroot"); |
45 | return( FALSE); | ||
18 | } | 46 | } |
19 | if (argc > 2) | 47 | |
20 | { | 48 | argc--; |
21 | execvp (argv[2], argv + 2); | 49 | argv++; |
50 | if (argc >= 1) { | ||
51 | fprintf(stderr, "command: %s\n", *argv); | ||
52 | execvp (*argv, argv); | ||
22 | } | 53 | } |
23 | else | 54 | else { |
24 | { | 55 | char *prog; |
25 | prog = getenv ("SHELL"); | 56 | prog = getenv ("SHELL"); |
26 | if (!prog) | 57 | if (!prog) |
27 | prog = "/bin/sh"; | 58 | prog = "/bin/sh"; |
28 | execlp (prog, prog, NULL); | 59 | fprintf(stderr, "no command. running: %s\n", prog); |
60 | execlp (prog, prog, NULL); | ||
29 | } | 61 | } |
30 | name_and_error ("cannot exec"); | 62 | perror("cannot exec"); |
31 | return 1; | 63 | return(FALSE); |
32 | } | 64 | } |
65 | |||