aboutsummaryrefslogtreecommitdiffstats
path: root/init/util.c
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2012-11-18 19:19:50 -0800
committerSteve Kondik <shade@chemlab.org>2012-11-18 19:19:50 -0800
commit39d33d8d54ba55e49f9b430f842647a84751cb85 (patch)
treef5a3756ea25d3b87902ae6a6a8df2428509e4246 /init/util.c
parentd8aa8ab7424be375e4408ab360c000ac8b05d15d (diff)
parent31da9db0d1bf3227e3c383aa6ac28bde3c6409e5 (diff)
downloadsystem_core-39d33d8d54ba55e49f9b430f842647a84751cb85.tar.gz
system_core-39d33d8d54ba55e49f9b430f842647a84751cb85.tar.bz2
system_core-39d33d8d54ba55e49f9b430f842647a84751cb85.zip
Merge branch 'jb-mr1-release' of https://android.googlesource.com/platform/system/core into mr1
Conflicts: adb/Android.mk adb/usb_vendors.c include/private/android_filesystem_config.h include/system/audio.h include/system/camera.h init/property_service.c libnetutils/ifc_utils.c mkbootimg/mkbootimg.c rootdir/init.rc Change-Id: Ie42f0c14808e9f8cabd24854bfe15b6667955229
Diffstat (limited to 'init/util.c')
-rwxr-xr-xinit/util.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/init/util.c b/init/util.c
index 136a9ecb..2b993bbc 100755
--- a/init/util.c
+++ b/init/util.c
@@ -47,7 +47,7 @@
*/
static unsigned int android_name_to_id(const char *name)
{
- struct android_id_info *info = android_ids;
+ const struct android_id_info *info = android_ids;
unsigned int n;
for (n = 0; n < android_id_count; n++) {
@@ -302,12 +302,12 @@ int mkdir_recursive(const char *pathname, mode_t mode)
memcpy(buf, pathname, width);
buf[width] = 0;
if (stat(buf, &info) != 0) {
- ret = mkdir(buf, mode);
+ ret = make_dir(buf, mode);
if (ret && errno != EEXIST)
return ret;
}
}
- ret = mkdir(pathname, mode);
+ ret = make_dir(pathname, mode);
if (ret && errno != EEXIST)
return ret;
return 0;
@@ -462,3 +462,52 @@ void import_kernel_cmdline(int in_qemu,
ptr = x;
}
}
+
+int make_dir(const char *path, mode_t mode)
+{
+ int rc;
+
+#ifdef HAVE_SELINUX
+ char *secontext = NULL;
+
+ if (sehandle) {
+ selabel_lookup(sehandle, &secontext, path, mode);
+ setfscreatecon(secontext);
+ }
+#endif
+
+ rc = mkdir(path, mode);
+
+#ifdef HAVE_SELINUX
+ if (secontext) {
+ int save_errno = errno;
+ freecon(secontext);
+ setfscreatecon(NULL);
+ errno = save_errno;
+ }
+#endif
+ return rc;
+}
+
+int restorecon(const char *pathname)
+{
+#ifdef HAVE_SELINUX
+ char *secontext = NULL;
+ struct stat sb;
+ int i;
+
+ if (is_selinux_enabled() <= 0 || !sehandle)
+ return 0;
+
+ if (lstat(pathname, &sb) < 0)
+ return -errno;
+ if (selabel_lookup(sehandle, &secontext, pathname, sb.st_mode) < 0)
+ return -errno;
+ if (lsetfilecon(pathname, secontext) < 0) {
+ freecon(secontext);
+ return -errno;
+ }
+ freecon(secontext);
+#endif
+ return 0;
+}