Skip to content

Commit

Permalink
Adjusted selinux and tests for egrep to grep -E
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurphy18 committed Oct 23, 2024
1 parent 2c974a7 commit 335561c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions salt/modules/selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def fcontext_get_policy(
"[[:alpha:] ]+" if filetype is None else filetype_id_to_string(filetype)
)
cmd = (
"semanage fcontext -l | egrep "
"semanage fcontext -l | grep -E "
+ "'^{filespec}{spacer}{filetype}{spacer}{sel_user}:{sel_role}:{sel_type}:{sel_level}{ospacer}$'".format(
**cmd_kwargs
)
Expand Down Expand Up @@ -616,7 +616,7 @@ def _fcontext_add_or_delete_policy(
if "add" == action:
# need to use --modify if context for name file exists, otherwise ValueError
filespec = re.escape(name)
cmd = f"semanage fcontext -l | egrep '{filespec} '"
cmd = f"semanage fcontext -l | grep -E '{filespec}'"
current_entry_text = __salt__["cmd.shell"](cmd, ignore_retcode=True)
if current_entry_text != "":
action = "modify"
Expand Down Expand Up @@ -762,7 +762,7 @@ def port_get_policy(name, sel_type=None, protocol=None, port=None):
"port": port,
}
cmd = (
"semanage port -l | egrep "
"semanage port -l | grep -E "
+ "'^{sel_type}{spacer}{protocol}{spacer}((.*)*)[ ]{port}($|,)'".format(
**cmd_kwargs
)
Expand Down
4 changes: 2 additions & 2 deletions tests/pytests/unit/modules/test_selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def test_selinux_add_policy_regex(name, sel_type):
):
selinux.fcontext_add_policy(name, sel_type=sel_type)
filespec = re.escape(name)
expected_cmd_shell = f"semanage fcontext -l | egrep '{filespec}'"
expected_cmd_shell = f"semanage fcontext -l | grep -E '{filespec}'"
mock_cmd_shell.assert_called_once_with(
expected_cmd_shell,
ignore_retcode=True,
Expand Down Expand Up @@ -433,7 +433,7 @@ def test_selinux_add_policy_shorter_path(name, sel_type):
):
selinux.fcontext_add_policy(name, sel_type=sel_type)
filespec = re.escape(name)
expected_cmd_shell = f"semanage fcontext -l | egrep '{filespec}'"
expected_cmd_shell = f"semanage fcontext -l | grep -E '{filespec}'"
mock_cmd_shell.assert_called_once_with(
expected_cmd_shell,
ignore_retcode=True,
Expand Down

0 comments on commit 335561c

Please sign in to comment.