diff options
| author | Stephen Smalley <sds@tycho.nsa.gov> | 2013-10-09 16:02:09 -0400 |
|---|---|---|
| committer | Stephen Smalley <sds@tycho.nsa.gov> | 2013-10-10 14:09:19 -0400 |
| commit | 726e8f7a8f3603f952055e440e21cc69c7340b36 (patch) | |
| tree | 1dfc822749574dde837c5eac22922c0800c94846 /init | |
| parent | 7dbe96602cde4822d22f17b85e33027563e8c521 (diff) | |
| download | system_core-726e8f7a8f3603f952055e440e21cc69c7340b36.zip system_core-726e8f7a8f3603f952055e440e21cc69c7340b36.tar.gz system_core-726e8f7a8f3603f952055e440e21cc69c7340b36.tar.bz2 | |
Add a restorecon_recursive built-in command to init.
Functionally equivalent to the restorecon -R toolbox command.
A use case is given by:
I48eaa2b9901ac8c978192c14493ba1058a089423
Also, fix error handling and documentation for restorecon command.
Change-Id: Ia7fbcc82645baf52c6bff0490d3492f458881cbb
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Diffstat (limited to 'init')
| -rw-r--r-- | init/builtins.c | 16 | ||||
| -rw-r--r-- | init/init_parser.c | 1 | ||||
| -rw-r--r-- | init/keywords.h | 2 | ||||
| -rw-r--r-- | init/readme.txt | 8 |
4 files changed, 24 insertions, 3 deletions
diff --git a/init/builtins.c b/init/builtins.c index 576f0d9..33fc6c6 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -747,12 +747,24 @@ int do_chmod(int nargs, char **args) { int do_restorecon(int nargs, char **args) { int i; + int ret = 0; for (i = 1; i < nargs; i++) { if (restorecon(args[i]) < 0) - return -errno; + ret = -errno; } - return 0; + return ret; +} + +int do_restorecon_recursive(int nargs, char **args) { + int i; + int ret = 0; + + for (i = 1; i < nargs; i++) { + if (restorecon_recursive(args[i]) < 0) + ret = -errno; + } + return ret; } int do_setsebool(int nargs, char **args) { diff --git a/init/init_parser.c b/init/init_parser.c index 2c2c91c..38582f5 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -133,6 +133,7 @@ int lookup_keyword(const char *s) case 'r': if (!strcmp(s, "estart")) return K_restart; if (!strcmp(s, "estorecon")) return K_restorecon; + if (!strcmp(s, "estorecon_recursive")) return K_restorecon_recursive; if (!strcmp(s, "mdir")) return K_rmdir; if (!strcmp(s, "m")) return K_rm; break; diff --git a/init/keywords.h b/init/keywords.h index f188db5..414db08 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -16,6 +16,7 @@ int do_mount_all(int nargs, char **args); int do_mount(int nargs, char **args); int do_restart(int nargs, char **args); int do_restorecon(int nargs, char **args); +int do_restorecon_recursive(int nargs, char **args); int do_rm(int nargs, char **args); int do_rmdir(int nargs, char **args); int do_setcon(int nargs, char **args); @@ -68,6 +69,7 @@ enum { KEYWORD(onrestart, OPTION, 0, 0) KEYWORD(restart, COMMAND, 1, do_restart) KEYWORD(restorecon, COMMAND, 1, do_restorecon) + KEYWORD(restorecon_recursive, COMMAND, 1, do_restorecon_recursive) KEYWORD(rm, COMMAND, 1, do_rm) KEYWORD(rmdir, COMMAND, 1, do_rmdir) KEYWORD(seclabel, OPTION, 0, 0) diff --git a/init/readme.txt b/init/readme.txt index 1e8c392..42a09cb 100644 --- a/init/readme.txt +++ b/init/readme.txt @@ -192,12 +192,18 @@ mount <type> <device> <dir> [ <mountoption> ]* device by name. <mountoption>s include "ro", "rw", "remount", "noatime", ... -restorecon <path> +restorecon <path> [ <path> ]* Restore the file named by <path> to the security context specified in the file_contexts configuration. Not required for directories created by the init.rc as these are automatically labeled correctly by init. +restorecon_recursive <path> [ <path> ]* + Recursively restore the directory tree named by <path> to the + security contexts specified in the file_contexts configuration. + Do NOT use this with paths leading to shell-writable or app-writable + directories, e.g. /data/local/tmp, /data/data or any prefix thereof. + setcon <securitycontext> Set the current process security context to the specified string. This is typically only used from early-init to set the init context |
