Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fcontext detection fails if pattern contains square brackets #105

Closed
BrianSipos opened this issue Jul 1, 2016 · 3 comments
Closed

fcontext detection fails if pattern contains square brackets #105

BrianSipos opened this issue Jul 1, 2016 · 3 comments

Comments

@BrianSipos
Copy link

As of 0.4.0 the fcontext parameter pathname is passed directly to grep in order to detect if the path is already defined as a context. Unfortunately, this detection fails if the pathname contains square brackets used in the path expression itself. Because these grep-interpreted characters are not escaped, they will be treated as actual pattern modifiers by grep rather than as literal characters.

An example is my pathname /var/lib/trac/projects/[^/]+(/.*)? which should be escaped prior to using as parameter to grep as /var/lib/trac/projects/\[^/\]+(/.*)?.

@pietervogelaar
Copy link

I have this same problem. No escaping happened, so this will fail:

semanage fcontext -l | grep -E "^/var/www(/.*)?/cache(/.*)?.*:httpd_sys_rw_content_t:"

@EternalNoob0
Copy link

I have the same problem with the detection fails if the pathname contains square brackets used in the path expression itself.
Below is my example
Mkhomedir/Selinux::Fcontext[set-non-home-user-dir_type_d]/Exec[restorecond add_user_home_dir_t_/opshome/[^/]_type_d]: Failed to call refresh: restorecon /opshome/[^/] returned 255 instead of one of [0]

@TJM
Copy link
Contributor

TJM commented Aug 9, 2016

I am having the same issue with /web/[^/]+/\.ssh(/.*)?...

We will either need to have some sort of "regex_escape" capability, or maybe grep F

semanage fcontext -l | grep -F '/web/[^/]+/\.ssh(/.*)?' | grep ':ssh_home_t:'

... seems to work, but I don't know if "grep -F" can be depended upon to exist?

@ashishvadhau you and I are also having a different problem too: #107 ... restorecon is failing due to unescaped input ending up on the shell, but as I noted there, its probably not a good idea to run restorecon "like this" (wish I had a better solution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants