aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-26 10:34:54 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-26 10:34:54 +0000
commit4dd4e6d6b98001d164cddbdfa8fe90460257884a (patch)
tree233777fb0e5e3455d7b51e4f070e1c79c6e3feb0
parent6a5377ac14bec2f2ae62c4ec085ff3b149cc11ad (diff)
downloadbusybox-w32-4dd4e6d6b98001d164cddbdfa8fe90460257884a.tar.gz
busybox-w32-4dd4e6d6b98001d164cddbdfa8fe90460257884a.tar.bz2
busybox-w32-4dd4e6d6b98001d164cddbdfa8fe90460257884a.zip
install: fix bug in "install -c file dir" (tries to copy dir into dir too)
install: 'support' (ignore) -v and -b
-rw-r--r--coreutils/install.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/coreutils/install.c b/coreutils/install.c
index 3cbae18a1..516208474 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -23,6 +23,8 @@ static const char install_longopts[] ALIGN1 =
23 "group\0" No_argument "g" 23 "group\0" No_argument "g"
24 "mode\0" No_argument "m" 24 "mode\0" No_argument "m"
25 "owner\0" No_argument "o" 25 "owner\0" No_argument "o"
26/* autofs build insists of using -b --suffix=.orig */
27/* TODO? (short option for --suffix is -S) */
26#if ENABLE_SELINUX 28#if ENABLE_SELINUX
27 "context\0" Required_argument "Z" 29 "context\0" Required_argument "Z"
28 "preserve_context\0" No_argument "\xff" 30 "preserve_context\0" No_argument "\xff"
@@ -33,8 +35,6 @@ static const char install_longopts[] ALIGN1 =
33 35
34 36
35#if ENABLE_SELINUX 37#if ENABLE_SELINUX
36static bool use_default_selinux_context = 1;
37
38static void setdefaultfilecon(const char *path) 38static void setdefaultfilecon(const char *path)
39{ 39{
40 struct stat s; 40 struct stat s;
@@ -83,18 +83,21 @@ int install_main(int argc, char **argv)
83 int isdir; 83 int isdir;
84#if ENABLE_SELINUX 84#if ENABLE_SELINUX
85 security_context_t scontext; 85 security_context_t scontext;
86 bool use_default_selinux_context = 1;
86#endif 87#endif
87 enum { 88 enum {
88 OPT_CMD = 0x1, 89 OPT_c = 1 << 0,
89 OPT_DIRECTORY = 0x2, 90 OPT_v = 1 << 1,
90 OPT_PRESERVE_TIME = 0x4, 91 OPT_b = 1 << 2,
91 OPT_STRIP = 0x8, 92 OPT_DIRECTORY = 1 << 3,
92 OPT_GROUP = 0x10, 93 OPT_PRESERVE_TIME = 1 << 4,
93 OPT_MODE = 0x20, 94 OPT_STRIP = 1 << 5,
94 OPT_OWNER = 0x40, 95 OPT_GROUP = 1 << 6,
96 OPT_MODE = 1 << 7,
97 OPT_OWNER = 1 << 8,
95#if ENABLE_SELINUX 98#if ENABLE_SELINUX
96 OPT_SET_SECURITY_CONTEXT = 0x80, 99 OPT_SET_SECURITY_CONTEXT = 1 << 9,
97 OPT_PRESERVE_SECURITY_CONTEXT = 0x100, 100 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 10,
98#endif 101#endif
99 }; 102 };
100 103
@@ -103,23 +106,24 @@ int install_main(int argc, char **argv)
103#endif 106#endif
104 opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z"); 107 opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
105 /* -c exists for backwards compatibility, it's needed */ 108 /* -c exists for backwards compatibility, it's needed */
106 109 /* -v is ignored ("print name of each created directory") */
107 flags = getopt32(argv, "cdpsg:m:o:" USE_SELINUX("Z:"), 110 /* -b is ignored ("make a backup of each existing destination file") */
111 flags = getopt32(argv, "cvb" "dpsg:m:o:" USE_SELINUX("Z:"),
108 &gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext)); 112 &gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext));
109 argc -= optind; 113 argc -= optind;
110 argv += optind; 114 argv += optind;
111 115
112#if ENABLE_SELINUX 116#if ENABLE_SELINUX
113 if (flags & OPT_PRESERVE_SECURITY_CONTEXT) { 117 if (flags & (OPT_PRESERVE_SECURITY_CONTEXT|OPT_SET_SECURITY_CONTEXT)) {
114 use_default_selinux_context = 0;
115 copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
116 selinux_or_die(); 118 selinux_or_die();
117 }
118 if (flags & OPT_SET_SECURITY_CONTEXT) {
119 selinux_or_die();
120 setfscreatecon_or_die(scontext);
121 use_default_selinux_context = 0; 119 use_default_selinux_context = 0;
122 copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT; 120 if (flags & OPT_PRESERVE_SECURITY_CONTEXT) {
121 copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
122 }
123 if (flags & OPT_SET_SECURITY_CONTEXT) {
124 setfscreatecon_or_die(scontext);
125 copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
126 }
123 } 127 }
124#endif 128#endif
125 129
@@ -172,6 +176,7 @@ int install_main(int argc, char **argv)
172 bb_show_usage(); 176 bb_show_usage();
173 177
174 last = argv[argc - 1]; 178 last = argv[argc - 1];
179 argv[argc - 1] = NULL;
175 /* coreutils install resolves link in this case, don't use lstat */ 180 /* coreutils install resolves link in this case, don't use lstat */
176 isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); 181 isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
177 182