diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-24 03:22:57 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-24 03:22:57 +0000 |
commit | eebcc1d98a9901ff69ffb97ba99bccd36666000f (patch) | |
tree | ad1e21191b4aef5ff0c0fa9c30717e77d023cc5d | |
parent | d72e34c7524a947ba004afff91272c27549b3085 (diff) | |
download | busybox-w32-eebcc1d98a9901ff69ffb97ba99bccd36666000f.tar.gz busybox-w32-eebcc1d98a9901ff69ffb97ba99bccd36666000f.tar.bz2 busybox-w32-eebcc1d98a9901ff69ffb97ba99bccd36666000f.zip |
Add the "install" applet, move get_ug_id to libbb as its used by chown,
chgrp and install.
-rw-r--r-- | coreutils/Config.in | 6 | ||||
-rw-r--r-- | coreutils/Makefile.in | 1 | ||||
-rw-r--r-- | coreutils/chgrp.c | 5 | ||||
-rw-r--r-- | coreutils/chown.c | 13 | ||||
-rw-r--r-- | coreutils/install.c | 102 | ||||
-rw-r--r-- | include/applets.h | 3 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | include/usage.h | 12 | ||||
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/get_ug_id.c | 28 |
10 files changed, 155 insertions, 18 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in index 074312b6e..c2ae399ef 100644 --- a/coreutils/Config.in +++ b/coreutils/Config.in | |||
@@ -218,6 +218,12 @@ config CONFIG_ID | |||
218 | help | 218 | help |
219 | id displays the current user and group ID names. | 219 | id displays the current user and group ID names. |
220 | 220 | ||
221 | config CONFIG_INSTALL | ||
222 | bool "install" | ||
223 | default n | ||
224 | help | ||
225 | Copy files and set attributes. | ||
226 | |||
221 | config CONFIG_LENGTH | 227 | config CONFIG_LENGTH |
222 | bool "length" | 228 | bool "length" |
223 | default n | 229 | default n |
diff --git a/coreutils/Makefile.in b/coreutils/Makefile.in index 95eda1ac7..b672f08f7 100644 --- a/coreutils/Makefile.in +++ b/coreutils/Makefile.in | |||
@@ -47,6 +47,7 @@ COREUTILS-$(CONFIG_FOLD) += fold.o | |||
47 | COREUTILS-$(CONFIG_HEAD) += head.o | 47 | COREUTILS-$(CONFIG_HEAD) += head.o |
48 | COREUTILS-$(CONFIG_HOSTID) += hostid.o | 48 | COREUTILS-$(CONFIG_HOSTID) += hostid.o |
49 | COREUTILS-$(CONFIG_ID) += id.o | 49 | COREUTILS-$(CONFIG_ID) += id.o |
50 | COREUTILS-$(CONFIG_INSTALL) += install.o | ||
50 | COREUTILS-$(CONFIG_LENGTH) += length.o | 51 | COREUTILS-$(CONFIG_LENGTH) += length.o |
51 | COREUTILS-$(CONFIG_LN) += ln.o | 52 | COREUTILS-$(CONFIG_LN) += ln.o |
52 | COREUTILS-$(CONFIG_LOGNAME) += logname.o | 53 | COREUTILS-$(CONFIG_LOGNAME) += logname.o |
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c index 2f3fa4197..8c969d7b6 100644 --- a/coreutils/chgrp.c +++ b/coreutils/chgrp.c | |||
@@ -59,10 +59,7 @@ int chgrp_main(int argc, char **argv) | |||
59 | argv += optind; | 59 | argv += optind; |
60 | 60 | ||
61 | /* Find the selected group */ | 61 | /* Find the selected group */ |
62 | gid = strtoul(*argv, &p, 10); /* maybe it's already numeric */ | 62 | gid = get_ug_id(*argv, my_getgrnam); |
63 | if (*p || (p == *argv)) { /* trailing chars or nonnumeric */ | ||
64 | gid = my_getgrnam(*argv); | ||
65 | } | ||
66 | ++argv; | 63 | ++argv; |
67 | 64 | ||
68 | /* Ok, ready to do the deed now */ | 65 | /* Ok, ready to do the deed now */ |
diff --git a/coreutils/chown.c b/coreutils/chown.c index 02b752474..07d673f28 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
@@ -53,19 +53,6 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
53 | #define FLAG_R 1 | 53 | #define FLAG_R 1 |
54 | #define FLAG_h 2 | 54 | #define FLAG_h 2 |
55 | 55 | ||
56 | static unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *)) | ||
57 | { | ||
58 | unsigned long r; | ||
59 | char *p; | ||
60 | |||
61 | r = strtoul(s, &p, 10); | ||
62 | if (*p || (s == p)) { | ||
63 | r = my_getxxnam(s); | ||
64 | } | ||
65 | |||
66 | return r; | ||
67 | } | ||
68 | |||
69 | int chown_main(int argc, char **argv) | 56 | int chown_main(int argc, char **argv) |
70 | { | 57 | { |
71 | int flags; | 58 | int flags; |
diff --git a/coreutils/install.c b/coreutils/install.c new file mode 100644 index 000000000..b235817cc --- /dev/null +++ b/coreutils/install.c | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003 by Glenn McGrath <bug1@optushome.com.au> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU Library General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
17 | * | ||
18 | * | ||
19 | * TODO: -d option, need a way of recursively making directories and changing | ||
20 | * owner/group, will probably modify bb_make_directory(...) | ||
21 | * Use bb_getopt_ulflags(...) ? | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <sys/stat.h> | ||
26 | #include <sys/types.h> | ||
27 | #include <errno.h> | ||
28 | #include <getopt.h> | ||
29 | #include <stdlib.h> | ||
30 | #include <unistd.h> | ||
31 | |||
32 | #include "libbb.h" | ||
33 | |||
34 | extern int install_main(int argc, char **argv) | ||
35 | { | ||
36 | struct stat statbuf; | ||
37 | int i; | ||
38 | int ret = EXIT_SUCCESS; | ||
39 | uid_t uid = -1; | ||
40 | gid_t gid = -1; | ||
41 | int copy_flags = 0; | ||
42 | int strip_flag = 0; | ||
43 | mode_t mode = 0755; | ||
44 | |||
45 | /* -c exists for backwards compatability, its needed */ | ||
46 | while ((i = getopt(argc, argv, "cg:m:o:ps")) != -1) { | ||
47 | switch (i) { | ||
48 | case 'g': /* group */ | ||
49 | gid = get_ug_id(optarg, my_getgrnam); | ||
50 | break; | ||
51 | case 'm': /* mode */ | ||
52 | bb_parse_mode(optarg, &mode); | ||
53 | break; | ||
54 | case 'o': /* owner */ | ||
55 | uid = get_ug_id(optarg, my_getpwnam); | ||
56 | break; | ||
57 | case 'p': /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */ | ||
58 | copy_flags |= FILEUTILS_PRESERVE_STATUS; | ||
59 | break; | ||
60 | case 's': /* Strip binaries */ | ||
61 | strip_flag = 1; | ||
62 | break; | ||
63 | default: | ||
64 | bb_show_usage(); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | if ((stat(argv[argc - 1], &statbuf) == -1) && (errno != ENOENT)) { | ||
69 | bb_perror_msg_and_die("stat failed for %s: ", argv[argc - 1]); | ||
70 | } | ||
71 | |||
72 | for (i = optind; i < argc - 1; i++) { | ||
73 | unsigned char *dest; | ||
74 | |||
75 | if (S_ISDIR(statbuf.st_mode)) { | ||
76 | dest = concat_path_file(argv[argc - 1], argv[i]); | ||
77 | } else { | ||
78 | dest = argv[argc - 1]; | ||
79 | } | ||
80 | ret |= copy_file(argv[i], dest, copy_flags); | ||
81 | |||
82 | /* Set the file mode */ | ||
83 | if (chmod(dest, mode) == -1) { | ||
84 | bb_perror_msg("cannot change permissions of %s", dest); | ||
85 | ret |= EXIT_FAILURE; | ||
86 | } | ||
87 | |||
88 | /* Set the user and group id */ | ||
89 | if (chown(dest, uid, gid) == -1) { | ||
90 | bb_perror_msg("cannot change ownership of %s", dest); | ||
91 | ret |= EXIT_FAILURE; | ||
92 | } | ||
93 | if (strip_flag) { | ||
94 | if (execlp("strip", "strip", dest, NULL) == -1) { | ||
95 | bb_error_msg("strip failed"); | ||
96 | ret |= EXIT_FAILURE; | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | return(ret); | ||
102 | } | ||
diff --git a/include/applets.h b/include/applets.h index 0b65266f3..b1425fa81 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -283,6 +283,9 @@ | |||
283 | #ifdef CONFIG_INSMOD | 283 | #ifdef CONFIG_INSMOD |
284 | APPLET(insmod, insmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER) | 284 | APPLET(insmod, insmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER) |
285 | #endif | 285 | #endif |
286 | #ifdef CONFIG_INSTALL | ||
287 | APPLET(install, install_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) | ||
288 | #endif | ||
286 | #ifdef CONFIG_IP | 289 | #ifdef CONFIG_IP |
287 | APPLET(ip, ip_main, _BB_DIR_BIN, _BB_SUID_NEVER) | 290 | APPLET(ip, ip_main, _BB_DIR_BIN, _BB_SUID_NEVER) |
288 | #endif | 291 | #endif |
diff --git a/include/libbb.h b/include/libbb.h index a6ccff421..2bb5ce02d 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -467,5 +467,6 @@ extern void print_login_prompt(void); | |||
467 | 467 | ||
468 | extern void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt); | 468 | extern void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt); |
469 | extern void get_terminal_width_height(int fd, int *width, int *height); | 469 | extern void get_terminal_width_height(int fd, int *width, int *height); |
470 | extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *)); | ||
470 | 471 | ||
471 | #endif /* __LIBCONFIG_H__ */ | 472 | #endif /* __LIBCONFIG_H__ */ |
diff --git a/include/usage.h b/include/usage.h index ba8fdde84..ba808d39a 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1239,6 +1239,18 @@ | |||
1239 | USAGE_INSMOD_MAP("\t-m\tOutput load map to stdout") \ | 1239 | USAGE_INSMOD_MAP("\t-m\tOutput load map to stdout") \ |
1240 | "\t-x\tdo not export externs\n" | 1240 | "\t-x\tdo not export externs\n" |
1241 | 1241 | ||
1242 | #define install_trivial_usage \ | ||
1243 | "[cgmops] [sources] <dest|directory>" | ||
1244 | #define install_full_usage \ | ||
1245 | "copy files and set attributes\n\n" \ | ||
1246 | "Options:\n" \ | ||
1247 | "\t-c\tcopy the file, default\n" \ | ||
1248 | "\t-g\tset group ownership\n" \ | ||
1249 | "\t-m\tset permission modes\n" \ | ||
1250 | "\t-o\tset ownership\n" \ | ||
1251 | "\t-p\tpreserve date\n" \ | ||
1252 | "\t-s\tstrip symbol tables\n" | ||
1253 | |||
1242 | #define ip_trivial_usage \ | 1254 | #define ip_trivial_usage \ |
1243 | "[ OPTIONS ] { address | link | route | tunnel } { COMMAND | help }" | 1255 | "[ OPTIONS ] { address | link | route | tunnel } { COMMAND | help }" |
1244 | #define ip_full_usage \ | 1256 | #define ip_full_usage \ |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 9da0f3af3..854bfc368 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -30,7 +30,7 @@ LIBBB_SRC:= \ | |||
30 | create_icmp6_socket.c device_open.c dump.c error_msg.c \ | 30 | create_icmp6_socket.c device_open.c dump.c error_msg.c \ |
31 | error_msg_and_die.c find_mount_point.c find_pid_by_name.c \ | 31 | error_msg_and_die.c find_mount_point.c find_pid_by_name.c \ |
32 | find_root_device.c fgets_str.c full_read.c full_write.c get_console.c \ | 32 | find_root_device.c fgets_str.c full_read.c full_write.c get_console.c \ |
33 | get_last_path_component.c get_line_from_file.c \ | 33 | get_last_path_component.c get_line_from_file.c get_ug_id.c \ |
34 | get_terminal_width_height.c herror_msg.c herror_msg_and_die.c \ | 34 | get_terminal_width_height.c herror_msg.c herror_msg_and_die.c \ |
35 | human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \ | 35 | human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \ |
36 | kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \ | 36 | kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \ |
diff --git a/libbb/get_ug_id.c b/libbb/get_ug_id.c new file mode 100644 index 000000000..24ed136f8 --- /dev/null +++ b/libbb/get_ug_id.c | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU Library General Public License for more details. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public License | ||
13 | * along with this program; if not, write to the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
15 | */ | ||
16 | |||
17 | extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *)) | ||
18 | { | ||
19 | unsigned long r; | ||
20 | char *p; | ||
21 | |||
22 | r = strtoul(s, &p, 10); | ||
23 | if (*p || (s == p)) { | ||
24 | r = my_getxxnam(s); | ||
25 | } | ||
26 | |||
27 | return r; | ||
28 | } | ||