diff options
author | Nick Kralevich <nnk@google.com> | 2014-01-28 21:07:13 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-01-28 21:07:13 +0000 |
commit | f286938177390ec058ea39b308c9b9498b011c7c (patch) | |
tree | 1e8115ee79e4037bc97b41c3f2d0a54f8a826607 /init/util.c | |
parent | 58a9cd1681688e031ef0642842d326da7d2a4934 (diff) | |
parent | 11322efdc63003ba7e2ba73dbbb2621e916a3773 (diff) | |
download | system_core-f286938177390ec058ea39b308c9b9498b011c7c.zip system_core-f286938177390ec058ea39b308c9b9498b011c7c.tar.gz system_core-f286938177390ec058ea39b308c9b9498b011c7c.tar.bz2 |
am 11322efd: am acd96b11: am 12db3eb6: Merge "Move restorecon and restorecon_recursive code to libselinux."
* commit '11322efdc63003ba7e2ba73dbbb2621e916a3773':
Move restorecon and restorecon_recursive code to libselinux.
Diffstat (limited to 'init/util.c')
-rw-r--r-- | init/util.c | 55 |
1 files changed, 4 insertions, 51 deletions
diff --git a/init/util.c b/init/util.c index 5efd5be..e772342 100644 --- a/init/util.c +++ b/init/util.c @@ -25,6 +25,7 @@ #include <ftw.h> #include <selinux/label.h> +#include <selinux/android.h> #include <sys/stat.h> #include <sys/types.h> @@ -524,60 +525,12 @@ int make_dir(const char *path, mode_t mode) return rc; } -static int restorecon_sb(const char *pathname, const struct stat *sb) +int restorecon(const char* pathname) { - char *secontext = NULL; - char *oldsecontext = NULL; - int i; - - if (selabel_lookup(sehandle, &secontext, pathname, sb->st_mode) < 0) - return -errno; - - if (lgetfilecon(pathname, &oldsecontext) < 0) { - freecon(secontext); - return -errno; - } - - if (strcmp(oldsecontext, secontext) != 0) { - if (lsetfilecon(pathname, secontext) < 0) { - freecon(oldsecontext); - freecon(secontext); - return -errno; - } - } - freecon(oldsecontext); - freecon(secontext); - return 0; -} - -int restorecon(const char *pathname) -{ - struct stat sb; - - if (is_selinux_enabled() <= 0 || !sehandle) - return 0; - - if (lstat(pathname, &sb) < 0) - return -errno; - - return restorecon_sb(pathname, &sb); -} - -static int nftw_restorecon(const char* filename, const struct stat* statptr, - int fileflags __attribute__((unused)), - struct FTW* pftw __attribute__((unused))) -{ - restorecon_sb(filename, statptr); - return 0; + return selinux_android_restorecon(pathname); } int restorecon_recursive(const char* pathname) { - int fd_limit = 20; - int flags = FTW_DEPTH | FTW_MOUNT | FTW_PHYS; - - if (is_selinux_enabled() <= 0 || !sehandle) - return 0; - - return nftw(pathname, nftw_restorecon, fd_limit, flags); + return selinux_android_restorecon_recursive(pathname); } |