aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-10 16:58:49 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-10 16:58:49 +0000
commitebfa808b7e1fa0baa8f12184523dc9f96a294abd (patch)
tree892bb79b0ef031d729e688d6be4950f6d17f13b9 /libbb
parentee5eb106c8ab883ff5452a894d3f52b229a469af (diff)
downloadbusybox-w32-ebfa808b7e1fa0baa8f12184523dc9f96a294abd.tar.gz
busybox-w32-ebfa808b7e1fa0baa8f12184523dc9f96a294abd.tar.bz2
busybox-w32-ebfa808b7e1fa0baa8f12184523dc9f96a294abd.zip
selinux support by Yuichi Nakamura <ynakam@hitachisoft.jp> (HitachiSoft)
git-svn-id: svn://busybox.net/trunk/busybox@18062 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/copy_file.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index bd785b71c..6391824aa 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -3,6 +3,7 @@
3 * Mini copy_file implementation for busybox 3 * Mini copy_file implementation for busybox
4 * 4 *
5 * Copyright (C) 2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu> 5 * Copyright (C) 2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
6 * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
6 * 7 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * 9 *
@@ -62,6 +63,26 @@ int copy_file(const char *source, const char *dest, int flags)
62 dest_exists = 1; 63 dest_exists = 1;
63 } 64 }
64 65
66#if ENABLE_SELINUX
67 if ((flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) && is_selinux_enabled() > 0) {
68 security_context_t con;
69 if (lgetfilecon(source, &con) >= 0) {
70 if (setfscreatecon(con) < 0) {
71 bb_perror_msg("cannot set setfscreatecon %s", con);
72 freecon(con);
73 return -1;
74 }
75 } else {
76 if (errno == ENOTSUP || errno == ENODATA) {
77 setfscreatecon(NULL);
78 } else {
79 bb_perror_msg("cannot lgetfilecon %s", source);
80 return -1;
81 }
82 }
83 }
84#endif
85
65 if (S_ISDIR(source_stat.st_mode)) { 86 if (S_ISDIR(source_stat.st_mode)) {
66 DIR *dp; 87 DIR *dp;
67 struct dirent *d; 88 struct dirent *d;
@@ -204,6 +225,25 @@ int copy_file(const char *source, const char *dest, int flags)
204 } 225 }
205 } 226 }
206 227
228#if ENABLE_SELINUX
229 if (((flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT)
230 || (flags & FILEUTILS_SET_SECURITY_CONTEXT))
231 && is_selinux_enabled() > 0) {
232 security_context_t con;
233 if (getfscreatecon(&con) == -1) {
234 bb_perror_msg("getfscreatecon");
235 return -1;
236 }
237 if (con) {
238 if(setfilecon(dest, con) == -1) {
239 bb_perror_msg("setfilecon:%s,%s", dest, con);
240 freecon(con);
241 return -1;
242 }
243 freecon(con);
244 }
245 }
246#endif
207 if (bb_copyfd_eof(src_fd, dst_fd) == -1) 247 if (bb_copyfd_eof(src_fd, dst_fd) == -1)
208 status = -1; 248 status = -1;
209 if (close(dst_fd) < 0) { 249 if (close(dst_fd) < 0) {