Skip to content

Commit 2647cc0

Browse files
RossComputerGuyjwcart2
authored andcommitted
libsemanage: add relabel_store config option
This flag allows for enabling or disabling automatic restorecon that semodule invokes. By default, we have it enabled to produce the same behavior as before. On NixOS, we need this as we're "baking" the module installation into a squashfs image and we cannot run restorecon inside the builder. Signed-off-by: Tristan Ross <[email protected] Acked-by: James Carter <[email protected]>
1 parent f1cfc6d commit 2647cc0

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

libsemanage/src/conf-parse.y

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int parse_errors;
6363

6464
%token MODULE_STORE VERSION EXPAND_CHECK FILE_MODE SAVE_PREVIOUS SAVE_LINKED TARGET_PLATFORM COMPILER_DIR IGNORE_MODULE_CACHE STORE_ROOT OPTIMIZE_POLICY MULTIPLE_DECLS
6565
%token LOAD_POLICY_START SETFILES_START SEFCONTEXT_COMPILE_START DISABLE_GENHOMEDIRCON HANDLE_UNKNOWN USEPASSWD IGNOREDIRS
66-
%token BZIP_BLOCKSIZE BZIP_SMALL REMOVE_HLL
66+
%token BZIP_BLOCKSIZE BZIP_SMALL RELABEL_STORE REMOVE_HLL
6767
%token VERIFY_MOD_START VERIFY_LINKED_START VERIFY_KERNEL_START BLOCK_END
6868
%token PROG_PATH PROG_ARGS
6969
%token <s> ARG
@@ -97,6 +97,7 @@ single_opt: module_store
9797
| bzip_blocksize
9898
| bzip_small
9999
| remove_hll
100+
| relabel_store
100101
| optimize_policy
101102
| multiple_decls
102103
;
@@ -291,6 +292,17 @@ remove_hll: REMOVE_HLL'=' ARG {
291292
free($3);
292293
}
293294

295+
relabel_store: RELABEL_STORE'=' ARG {
296+
if (strcasecmp($3, "false") == 0) {
297+
current_conf->relabel_store = 0;
298+
} else if (strcasecmp($3, "true") == 0) {
299+
current_conf->relabel_store = 1;
300+
} else {
301+
yyerror("relabel_store can only be 'true' or 'false'");
302+
}
303+
free($3);
304+
}
305+
294306
optimize_policy: OPTIMIZE_POLICY '=' ARG {
295307
if (strcasecmp($3, "false") == 0) {
296308
current_conf->optimize_policy = 0;
@@ -400,6 +412,7 @@ static int semanage_conf_init(semanage_conf_t * conf)
400412
conf->bzip_small = 0;
401413
conf->ignore_module_cache = 0;
402414
conf->remove_hll = 0;
415+
conf->relabel_store = 1;
403416
conf->optimize_policy = 1;
404417
conf->multiple_decls = 1;
405418

libsemanage/src/conf-scan.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ handle-unknown return HANDLE_UNKNOWN;
5454
bzip-blocksize return BZIP_BLOCKSIZE;
5555
bzip-small return BZIP_SMALL;
5656
remove-hll return REMOVE_HLL;
57+
relabel_store return RELABEL_STORE;
5758
optimize-policy return OPTIMIZE_POLICY;
5859
multiple-decls return MULTIPLE_DECLS;
5960
"[load_policy]" return LOAD_POLICY_START;

libsemanage/src/semanage_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef struct semanage_conf {
4949
int ignore_module_cache;
5050
int optimize_policy;
5151
int multiple_decls;
52+
int relabel_store;
5253
char *ignoredirs; /* ";" separated of list for genhomedircon to ignore */
5354
struct external_prog *load_policy;
5455
struct external_prog *setfiles;

libsemanage/src/semanage_store.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,8 +1823,11 @@ static int semanage_commit_sandbox(semanage_handle_t * sh)
18231823

18241824
cleanup:
18251825
semanage_release_active_lock(sh);
1826-
sehandle = selinux_restorecon_default_handle();
1827-
selinux_restorecon_set_sehandle(sehandle);
1826+
1827+
if (sh->conf->relabel_store) {
1828+
sehandle = selinux_restorecon_default_handle();
1829+
selinux_restorecon_set_sehandle(sehandle);
1830+
}
18281831
return retval;
18291832
}
18301833

0 commit comments

Comments
 (0)