diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-05 16:24:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-05 16:24:54 +0000 |
commit | cc8ed39b240180b58810784f844e253263594ac3 (patch) | |
tree | 15feebbb4be9a9168209609f48f0b100f9364420 /chown.c | |
download | busybox-w32-0_29alpha2.tar.gz busybox-w32-0_29alpha2.tar.bz2 busybox-w32-0_29alpha2.zip |
Initial revision0_29alpha2
Diffstat (limited to 'chown.c')
-rw-r--r-- | chown.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/chown.c b/chown.c new file mode 100644 index 000000000..a611f92f1 --- /dev/null +++ b/chown.c | |||
@@ -0,0 +1,63 @@ | |||
1 | #include "internal.h" | ||
2 | #include <pwd.h> | ||
3 | #include <grp.h> | ||
4 | #include <string.h> | ||
5 | #include <stdio.h> | ||
6 | |||
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 | |||
12 | int | ||
13 | parse_user_name(const char * s, struct FileInfo * i) | ||
14 | { | ||
15 | struct passwd * p; | ||
16 | char * dot = strchr(s, '.'); | ||
17 | |||
18 | if (! dot ) | ||
19 | dot = strchr(s, ':'); | ||
20 | |||
21 | if ( dot ) | ||
22 | *dot = '\0'; | ||
23 | |||
24 | if ( (p = getpwnam(s)) == 0 ) { | ||
25 | fprintf(stderr, "%s: no such user.\n", s); | ||
26 | return 1; | ||
27 | } | ||
28 | i->userID = p->pw_uid; | ||
29 | |||
30 | if ( dot ) { | ||
31 | struct group * g = getgrnam(++dot); | ||
32 | if ( g == 0 ) { | ||
33 | fprintf(stderr, "%s: no such group.\n", dot); | ||
34 | return 1; | ||
35 | } | ||
36 | i->groupID = g->gr_gid; | ||
37 | i->changeGroupID = 1; | ||
38 | } | ||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | extern int | ||
43 | chown_main(struct FileInfo * i, int argc, char * * argv) | ||
44 | { | ||
45 | int status; | ||
46 | |||
47 | while ( argc >= 3 && strcmp("-R", argv[1]) == 0 ) { | ||
48 | i->recursive = 1; | ||
49 | argc--; | ||
50 | argv++; | ||
51 | } | ||
52 | |||
53 | if ( (status = parse_user_name(argv[1], i)) != 0 ) | ||
54 | return status; | ||
55 | |||
56 | argv++; | ||
57 | argc--; | ||
58 | |||
59 | i->changeUserID = 1; | ||
60 | i->complainInPostProcess = 1; | ||
61 | |||
62 | return monadic_main(i, argc, argv); | ||
63 | } | ||