* [PATCH] semanage: improve -e documentation and fix delete operation
@ 2024-12-30 13:50 Christian Göttsche
2025-01-08 16:29 ` Petr Lautrbach
0 siblings, 1 reply; 3+ messages in thread
From: Christian Göttsche @ 2024-12-30 13:50 UTC (permalink / raw)
To: selinux; +Cc: Christian Göttsche
From: Christian Göttsche <cgzones@googlemail.com>
Improve the documentation around the -e/--equal option for semanage
fcontext.
Add support for entry deletion.
Closes: https://github.com/SELinuxProject/selinux/issues/457
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
python/semanage/semanage | 15 ++++++++-------
python/semanage/semanage-fcontext.8 | 6 +++---
python/semanage/seobject.py | 13 +++++++++++++
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/python/semanage/semanage b/python/semanage/semanage
index b269b9fc..ec6fa2dd 100644
--- a/python/semanage/semanage
+++ b/python/semanage/semanage
@@ -54,7 +54,7 @@ usage_login = "semanage login [-h] [-n] [-N] [-S STORE] ["
usage_login_dict = {' --add': ('-s SEUSER', '-r RANGE', 'LOGIN',), ' --modify': ('-s SEUSER', '-r RANGE', 'LOGIN',), ' --delete': ('LOGIN',), ' --list': ('-C',), ' --extract': ('',), ' --deleteall': ('',)}
usage_fcontext = "semanage fcontext [-h] [-n] [-N] [-S STORE] ["
-usage_fcontext_dict = {' --add': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --delete': ('(', '-t TYPE', '-f FTYPE', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --modify': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --list': ('[-C]',), ' --extract': ('',), ' --deleteall': ('',)}
+usage_fcontext_dict = {' --add': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --delete': ('(', '-t TYPE', '-f FTYPE', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --modify': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --list': ('[-C]',), ' --extract': ('',), ' --deleteall': ('',)}
usage_user = "semanage user [-h] [-n] [-N] [-S STORE] ["
usage_user_dict = {' --add': ('(', '-L LEVEL', '-R ROLES', '-r RANGE', 'SEUSER', ')'), ' --delete': ('SEUSER',), ' --modify': ('(', '-L LEVEL', '-R ROLES', '-r RANGE', '-s SEUSER', 'SEUSER', ')'), ' --list': ('-C',), ' --extract': ('',), ' --deleteall': ('',)}
@@ -306,7 +306,7 @@ def setupLoginParser(subparsers):
def handleFcontext(args):
fcontext_args = {'list': [('equal', 'ftype', 'seuser', 'type'), ('')], 'add': [('locallist'), ('type', 'file_spec')], 'modify': [('locallist'), ('type', 'file_spec')], 'delete': [('locallist'), ('file_spec')], 'extract': [('locallist', 'equal', 'ftype', 'seuser', 'type'), ('')], 'deleteall': [('locallist'), ('')]}
# we can not use mutually for equal because we can define some actions together with equal
- fcontext_equal_args = {'equal': [('list', 'locallist', 'type', 'ftype', 'seuser', 'deleteall', 'extract'), ()]}
+ fcontext_equal_args = {'equal': [('list', 'locallist', 'type', 'ftype', 'seuser', 'deleteall', 'extract'), ('file_spec')]}
if args.action and args.equal:
handle_opts(args, fcontext_equal_args, "equal")
@@ -327,7 +327,7 @@ def handleFcontext(args):
OBJECT.modify(args.file_spec, args.type, args.ftype, args.range, args.seuser)
if args.action == "delete":
if args.equal:
- OBJECT.delete(args.file_spec, args.equal)
+ OBJECT.delete_equal(args.file_spec, args.equal)
else:
OBJECT.delete(args.file_spec, args.ftype)
if args.action == "list":
@@ -355,9 +355,10 @@ def setupFcontextParser(subparsers):
parser_add_extract(fcontext_action, "fcontext")
parser_add_deleteall(fcontext_action, "fcontext")
- fcontextParser.add_argument('-e', '--equal', help=_(
- 'Substitute target path with sourcepath when generating default label. This is used with fcontext. Requires source and target \
-path arguments. The context labeling for the target subtree is made equivalent to that defined for the source.'
+ fcontextParser.add_argument('-e', '--equal', metavar='TARGET_PATH' help=_(
+ 'Substitute FILE_SPEC with TARGET_PATH for file label lookup. This is used with fcontext. Requires source and target \
+path arguments to be path prefixes and does not support regular expressions. \
+The context labeling for the target subtree is made equivalent to that defined for the source.'
))
fcontextParser.add_argument('-f', '--ftype', default="", choices=["a", "f", "d", "c", "b", "s", "l", "p"], help=_(
'File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use d to match only \
@@ -368,7 +369,7 @@ If you do not specify a file type, the file type will default to "all files".'
parser_add_seuser(fcontextParser, "fcontext")
parser_add_type(fcontextParser, "fcontext")
parser_add_range(fcontextParser, "fcontext")
- fcontextParser.add_argument('file_spec', nargs='?', default=None, help=_('Path to be labeled (may be in the form of a Perl compatible regular expression)'))
+ fcontextParser.add_argument('file_spec', nargs='?', default=None, metavar='FILE_SPEC', help=_('Path to be labeled (may be in the form of a Perl compatible regular expression)'))
fcontextParser.set_defaults(func=handleFcontext)
diff --git a/python/semanage/semanage-fcontext.8 b/python/semanage/semanage-fcontext.8
index 3e327d88..3a96c62f 100644
--- a/python/semanage/semanage-fcontext.8
+++ b/python/semanage/semanage-fcontext.8
@@ -3,7 +3,7 @@
semanage\-fcontext \- SELinux Policy Management file context tool
.SH "SYNOPSIS"
-.B semanage fcontext [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e EQUAL ) FILE_SPEC | \-\-delete ( \-t TYPE \-f FTYPE | \-e EQUAL ) FILE_SPEC | \-\-deleteall | \-\-extract | \-\-list [\-C] | \-\-modify ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e EQUAL ) FILE_SPEC ]
+.B semanage fcontext [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e TARGET_PATH ) FILE_SPEC | \-\-delete ( \-t TYPE \-f FTYPE | \-e TARGET_PATH ) FILE_SPEC | \-\-deleteall | \-\-extract | \-\-list [\-C] | \-\-modify ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e TARGET_PATH ) FILE_SPEC ]
.SH "DESCRIPTION"
semanage is used to configure certain elements of
@@ -66,8 +66,8 @@ Extract customizable commands, for use within a transaction
.I \-D, \-\-deleteall
Remove all local customizations
.TP
-.I \-e EQUAL, \-\-equal EQUAL
-Substitute target path with sourcepath when generating default label. This is used with fcontext. Requires source and target path arguments. The context labeling for the target subtree is made equivalent to that defined for the source.
+.I \-e TARGET_PATH, \-\-equal TARGET_PATH
+Substitute FILE_SPEC with TARGET_PATH for file label lookup. This is used with fcontext. Requires source and target path arguments to be path prefixes and does not support regular expressions. The context labeling for the target subtree is made equivalent to that defined for the source.
.TP
.I \-f [{a,f,d,c,b,s,l,p}], \-\-ftype [{a,f,d,c,b,s,l,p}]
File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use 'd' to match only directories or 'f' to match only regular files. The following file type options can be passed: f (regular file),d (directory),c (character device), b (block device),s (socket),l (symbolic link),p (named pipe). If you do not specify a file type, the file type will default to "all files".
diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index 10963e81..854381d4 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -2453,6 +2453,19 @@ class fcontextRecords(semanageRecords):
self.commit()
+ def delete_equal(self, target, substitute):
+ self.begin()
+ if target not in self.equiv.keys():
+ raise ValueError(_("Equivalence class for %s does not exist") % target)
+ if substitute != self.equiv[target]:
+ raise ValueError(_("Equivalence class for %s does not match %s but %s") % (target, substitute, self.equiv[target]))
+ del self.equiv[target]
+ self.equal_ind = True
+
+ self.mylog.log_change("resrc=fcontext op=delete-equal %s %s" % (audit.audit_encode_nv_string("sglob", target, 0), audit.audit_encode_nv_string("tglob", substitute, 0)))
+
+ self.commit()
+
def createcon(self, target, seuser="system_u"):
(rc, con) = semanage_context_create(self.sh)
if rc < 0:
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] semanage: improve -e documentation and fix delete operation
2024-12-30 13:50 [PATCH] semanage: improve -e documentation and fix delete operation Christian Göttsche
@ 2025-01-08 16:29 ` Petr Lautrbach
2025-01-08 16:53 ` Christian Göttsche
0 siblings, 1 reply; 3+ messages in thread
From: Petr Lautrbach @ 2025-01-08 16:29 UTC (permalink / raw)
To: Christian Göttsche, selinux; +Cc: Christian Göttsche
Christian Göttsche <cgoettsche@seltendoof.de> writes:
> From: Christian Göttsche <cgzones@googlemail.com>
>
> Improve the documentation around the -e/--equal option for semanage
> fcontext.
>
> Add support for entry deletion.
>
> Closes: https://github.com/SELinuxProject/selinux/issues/457
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> python/semanage/semanage | 15 ++++++++-------
> python/semanage/semanage-fcontext.8 | 6 +++---
> python/semanage/seobject.py | 13 +++++++++++++
> 3 files changed, 24 insertions(+), 10 deletions(-)
>
> diff --git a/python/semanage/semanage b/python/semanage/semanage
> index b269b9fc..ec6fa2dd 100644
> --- a/python/semanage/semanage
> +++ b/python/semanage/semanage
> @@ -54,7 +54,7 @@ usage_login = "semanage login [-h] [-n] [-N] [-S STORE] ["
> usage_login_dict = {' --add': ('-s SEUSER', '-r RANGE', 'LOGIN',), ' --modify': ('-s SEUSER', '-r RANGE', 'LOGIN',), ' --delete': ('LOGIN',), ' --list': ('-C',), ' --extract': ('',), ' --deleteall': ('',)}
>
> usage_fcontext = "semanage fcontext [-h] [-n] [-N] [-S STORE] ["
> -usage_fcontext_dict = {' --add': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --delete': ('(', '-t TYPE', '-f FTYPE', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --modify': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --list': ('[-C]',), ' --extract': ('',), ' --deleteall': ('',)}
> +usage_fcontext_dict = {' --add': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --delete': ('(', '-t TYPE', '-f FTYPE', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --modify': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --list': ('[-C]',), ' --extract': ('',), ' --deleteall': ('',)}
>
> usage_user = "semanage user [-h] [-n] [-N] [-S STORE] ["
> usage_user_dict = {' --add': ('(', '-L LEVEL', '-R ROLES', '-r RANGE', 'SEUSER', ')'), ' --delete': ('SEUSER',), ' --modify': ('(', '-L LEVEL', '-R ROLES', '-r RANGE', '-s SEUSER', 'SEUSER', ')'), ' --list': ('-C',), ' --extract': ('',), ' --deleteall': ('',)}
> @@ -306,7 +306,7 @@ def setupLoginParser(subparsers):
> def handleFcontext(args):
> fcontext_args = {'list': [('equal', 'ftype', 'seuser', 'type'), ('')], 'add': [('locallist'), ('type', 'file_spec')], 'modify': [('locallist'), ('type', 'file_spec')], 'delete': [('locallist'), ('file_spec')], 'extract': [('locallist', 'equal', 'ftype', 'seuser', 'type'), ('')], 'deleteall': [('locallist'), ('')]}
> # we can not use mutually for equal because we can define some actions together with equal
> - fcontext_equal_args = {'equal': [('list', 'locallist', 'type', 'ftype', 'seuser', 'deleteall', 'extract'), ()]}
> + fcontext_equal_args = {'equal': [('list', 'locallist', 'type', 'ftype', 'seuser', 'deleteall', 'extract'), ('file_spec')]}
>
> if args.action and args.equal:
> handle_opts(args, fcontext_equal_args, "equal")
> @@ -327,7 +327,7 @@ def handleFcontext(args):
> OBJECT.modify(args.file_spec, args.type, args.ftype, args.range, args.seuser)
> if args.action == "delete":
> if args.equal:
> - OBJECT.delete(args.file_spec, args.equal)
> + OBJECT.delete_equal(args.file_spec, args.equal)
> else:
> OBJECT.delete(args.file_spec, args.ftype)
> if args.action == "list":
> @@ -355,9 +355,10 @@ def setupFcontextParser(subparsers):
> parser_add_extract(fcontext_action, "fcontext")
> parser_add_deleteall(fcontext_action, "fcontext")
>
> - fcontextParser.add_argument('-e', '--equal', help=_(
> - 'Substitute target path with sourcepath when generating default label. This is used with fcontext. Requires source and target \
> -path arguments. The context labeling for the target subtree is made equivalent to that defined for the source.'
> + fcontextParser.add_argument('-e', '--equal', metavar='TARGET_PATH' help=_(
> + 'Substitute FILE_SPEC with TARGET_PATH for file label lookup. This is used with fcontext. Requires source and target \
> +path arguments to be path prefixes and does not support regular expressions. \
> +The context labeling for the target subtree is made equivalent to that defined for the source.'
> ))
> fcontextParser.add_argument('-f', '--ftype', default="", choices=["a", "f", "d", "c", "b", "s", "l", "p"], help=_(
> 'File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use d to match only \
> @@ -368,7 +369,7 @@ If you do not specify a file type, the file type will default to "all files".'
> parser_add_seuser(fcontextParser, "fcontext")
> parser_add_type(fcontextParser, "fcontext")
> parser_add_range(fcontextParser, "fcontext")
> - fcontextParser.add_argument('file_spec', nargs='?', default=None, help=_('Path to be labeled (may be in the form of a Perl compatible regular expression)'))
> + fcontextParser.add_argument('file_spec', nargs='?', default=None, metavar='FILE_SPEC', help=_('Path to be labeled (may be in the form of a Perl compatible regular expression)'))
> fcontextParser.set_defaults(func=handleFcontext)
>
>
> diff --git a/python/semanage/semanage-fcontext.8 b/python/semanage/semanage-fcontext.8
> index 3e327d88..3a96c62f 100644
> --- a/python/semanage/semanage-fcontext.8
> +++ b/python/semanage/semanage-fcontext.8
> @@ -3,7 +3,7 @@
> semanage\-fcontext \- SELinux Policy Management file context tool
>
> .SH "SYNOPSIS"
> -.B semanage fcontext [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e EQUAL ) FILE_SPEC | \-\-delete ( \-t TYPE \-f FTYPE | \-e EQUAL ) FILE_SPEC | \-\-deleteall | \-\-extract | \-\-list [\-C] | \-\-modify ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e EQUAL ) FILE_SPEC ]
> +.B semanage fcontext [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e TARGET_PATH ) FILE_SPEC | \-\-delete ( \-t TYPE \-f FTYPE | \-e TARGET_PATH ) FILE_SPEC | \-\-deleteall | \-\-extract | \-\-list [\-C] | \-\-modify ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e TARGET_PATH ) FILE_SPEC ]
>
> .SH "DESCRIPTION"
> semanage is used to configure certain elements of
> @@ -66,8 +66,8 @@ Extract customizable commands, for use within a transaction
> .I \-D, \-\-deleteall
> Remove all local customizations
> .TP
> -.I \-e EQUAL, \-\-equal EQUAL
> -Substitute target path with sourcepath when generating default label. This is used with fcontext. Requires source and target path arguments. The context labeling for the target subtree is made equivalent to that defined for the source.
> +.I \-e TARGET_PATH, \-\-equal TARGET_PATH
> +Substitute FILE_SPEC with TARGET_PATH for file label lookup. This is used with fcontext. Requires source and target path arguments to be path prefixes and does not support regular expressions. The context labeling for the target subtree is made equivalent to that defined for the source.
> .TP
> .I \-f [{a,f,d,c,b,s,l,p}], \-\-ftype [{a,f,d,c,b,s,l,p}]
> File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use 'd' to match only directories or 'f' to match only regular files. The following file type options can be passed: f (regular file),d (directory),c (character device), b (block device),s (socket),l (symbolic link),p (named pipe). If you do not specify a file type, the file type will default to "all files".
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index 10963e81..854381d4 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -2453,6 +2453,19 @@ class fcontextRecords(semanageRecords):
>
> self.commit()
>
> + def delete_equal(self, target, substitute):
> + self.begin()
> + if target not in self.equiv.keys():
> + raise ValueError(_("Equivalence class for %s does not exist") % target)
> + if substitute != self.equiv[target]:
> + raise ValueError(_("Equivalence class for %s does not match %s but %s") % (target, substitute, self.equiv[target]))
> + del self.equiv[target]
> + self.equal_ind = True
> +
> + self.mylog.log_change("resrc=fcontext op=delete-equal %s %s" % (audit.audit_encode_nv_string("sglob", target, 0), audit.audit_encode_nv_string("tglob", substitute, 0)))
> +
> + self.commit()
> +
Why is this necessary?
It seems to work in current version:
[root@localhost ~]# semanage fcontext -a -e /home /domov
[root@localhost ~]# semanage fcontext -l | grep domov
/domov = /home
[root@localhost ~]# semanage fcontext -d -e /home /domov
[root@localhost ~]# semanage fcontext -l | grep domov
[root@localhost ~]#
> def createcon(self, target, seuser="system_u"):
> (rc, con) = semanage_context_create(self.sh)
> if rc < 0:
> --
> 2.45.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] semanage: improve -e documentation and fix delete operation
2025-01-08 16:29 ` Petr Lautrbach
@ 2025-01-08 16:53 ` Christian Göttsche
0 siblings, 0 replies; 3+ messages in thread
From: Christian Göttsche @ 2025-01-08 16:53 UTC (permalink / raw)
To: Petr Lautrbach; +Cc: Christian Göttsche, selinux
On Wed, 8 Jan 2025 at 17:29, Petr Lautrbach <lautrbach@redhat.com> wrote:
>
> Christian Göttsche <cgoettsche@seltendoof.de> writes:
>
> > From: Christian Göttsche <cgzones@googlemail.com>
> >
> > Improve the documentation around the -e/--equal option for semanage
> > fcontext.
> >
> > Add support for entry deletion.
> >
> > Closes: https://github.com/SELinuxProject/selinux/issues/457
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> > ---
> > python/semanage/semanage | 15 ++++++++-------
> > python/semanage/semanage-fcontext.8 | 6 +++---
> > python/semanage/seobject.py | 13 +++++++++++++
> > 3 files changed, 24 insertions(+), 10 deletions(-)
> >
> > diff --git a/python/semanage/semanage b/python/semanage/semanage
> > index b269b9fc..ec6fa2dd 100644
> > --- a/python/semanage/semanage
> > +++ b/python/semanage/semanage
> > @@ -54,7 +54,7 @@ usage_login = "semanage login [-h] [-n] [-N] [-S STORE] ["
> > usage_login_dict = {' --add': ('-s SEUSER', '-r RANGE', 'LOGIN',), ' --modify': ('-s SEUSER', '-r RANGE', 'LOGIN',), ' --delete': ('LOGIN',), ' --list': ('-C',), ' --extract': ('',), ' --deleteall': ('',)}
> >
> > usage_fcontext = "semanage fcontext [-h] [-n] [-N] [-S STORE] ["
> > -usage_fcontext_dict = {' --add': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --delete': ('(', '-t TYPE', '-f FTYPE', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --modify': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e EQUAL', ')', 'FILE_SPEC',), ' --list': ('[-C]',), ' --extract': ('',), ' --deleteall': ('',)}
> > +usage_fcontext_dict = {' --add': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --delete': ('(', '-t TYPE', '-f FTYPE', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --modify': ('(', '-t TYPE', '-f FTYPE', '-r RANGE', '-s SEUSER', '|', '-e TARGET_PATH', ')', 'FILE_SPEC',), ' --list': ('[-C]',), ' --extract': ('',), ' --deleteall': ('',)}
> >
> > usage_user = "semanage user [-h] [-n] [-N] [-S STORE] ["
> > usage_user_dict = {' --add': ('(', '-L LEVEL', '-R ROLES', '-r RANGE', 'SEUSER', ')'), ' --delete': ('SEUSER',), ' --modify': ('(', '-L LEVEL', '-R ROLES', '-r RANGE', '-s SEUSER', 'SEUSER', ')'), ' --list': ('-C',), ' --extract': ('',), ' --deleteall': ('',)}
> > @@ -306,7 +306,7 @@ def setupLoginParser(subparsers):
> > def handleFcontext(args):
> > fcontext_args = {'list': [('equal', 'ftype', 'seuser', 'type'), ('')], 'add': [('locallist'), ('type', 'file_spec')], 'modify': [('locallist'), ('type', 'file_spec')], 'delete': [('locallist'), ('file_spec')], 'extract': [('locallist', 'equal', 'ftype', 'seuser', 'type'), ('')], 'deleteall': [('locallist'), ('')]}
> > # we can not use mutually for equal because we can define some actions together with equal
> > - fcontext_equal_args = {'equal': [('list', 'locallist', 'type', 'ftype', 'seuser', 'deleteall', 'extract'), ()]}
> > + fcontext_equal_args = {'equal': [('list', 'locallist', 'type', 'ftype', 'seuser', 'deleteall', 'extract'), ('file_spec')]}
> >
> > if args.action and args.equal:
> > handle_opts(args, fcontext_equal_args, "equal")
> > @@ -327,7 +327,7 @@ def handleFcontext(args):
> > OBJECT.modify(args.file_spec, args.type, args.ftype, args.range, args.seuser)
> > if args.action == "delete":
> > if args.equal:
> > - OBJECT.delete(args.file_spec, args.equal)
> > + OBJECT.delete_equal(args.file_spec, args.equal)
> > else:
> > OBJECT.delete(args.file_spec, args.ftype)
> > if args.action == "list":
> > @@ -355,9 +355,10 @@ def setupFcontextParser(subparsers):
> > parser_add_extract(fcontext_action, "fcontext")
> > parser_add_deleteall(fcontext_action, "fcontext")
> >
> > - fcontextParser.add_argument('-e', '--equal', help=_(
> > - 'Substitute target path with sourcepath when generating default label. This is used with fcontext. Requires source and target \
> > -path arguments. The context labeling for the target subtree is made equivalent to that defined for the source.'
> > + fcontextParser.add_argument('-e', '--equal', metavar='TARGET_PATH' help=_(
> > + 'Substitute FILE_SPEC with TARGET_PATH for file label lookup. This is used with fcontext. Requires source and target \
> > +path arguments to be path prefixes and does not support regular expressions. \
> > +The context labeling for the target subtree is made equivalent to that defined for the source.'
> > ))
> > fcontextParser.add_argument('-f', '--ftype', default="", choices=["a", "f", "d", "c", "b", "s", "l", "p"], help=_(
> > 'File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use d to match only \
> > @@ -368,7 +369,7 @@ If you do not specify a file type, the file type will default to "all files".'
> > parser_add_seuser(fcontextParser, "fcontext")
> > parser_add_type(fcontextParser, "fcontext")
> > parser_add_range(fcontextParser, "fcontext")
> > - fcontextParser.add_argument('file_spec', nargs='?', default=None, help=_('Path to be labeled (may be in the form of a Perl compatible regular expression)'))
> > + fcontextParser.add_argument('file_spec', nargs='?', default=None, metavar='FILE_SPEC', help=_('Path to be labeled (may be in the form of a Perl compatible regular expression)'))
> > fcontextParser.set_defaults(func=handleFcontext)
> >
> >
> > diff --git a/python/semanage/semanage-fcontext.8 b/python/semanage/semanage-fcontext.8
> > index 3e327d88..3a96c62f 100644
> > --- a/python/semanage/semanage-fcontext.8
> > +++ b/python/semanage/semanage-fcontext.8
> > @@ -3,7 +3,7 @@
> > semanage\-fcontext \- SELinux Policy Management file context tool
> >
> > .SH "SYNOPSIS"
> > -.B semanage fcontext [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e EQUAL ) FILE_SPEC | \-\-delete ( \-t TYPE \-f FTYPE | \-e EQUAL ) FILE_SPEC | \-\-deleteall | \-\-extract | \-\-list [\-C] | \-\-modify ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e EQUAL ) FILE_SPEC ]
> > +.B semanage fcontext [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e TARGET_PATH ) FILE_SPEC | \-\-delete ( \-t TYPE \-f FTYPE | \-e TARGET_PATH ) FILE_SPEC | \-\-deleteall | \-\-extract | \-\-list [\-C] | \-\-modify ( \-t TYPE \-f FTYPE \-r RANGE \-s SEUSER | \-e TARGET_PATH ) FILE_SPEC ]
> >
> > .SH "DESCRIPTION"
> > semanage is used to configure certain elements of
> > @@ -66,8 +66,8 @@ Extract customizable commands, for use within a transaction
> > .I \-D, \-\-deleteall
> > Remove all local customizations
> > .TP
> > -.I \-e EQUAL, \-\-equal EQUAL
> > -Substitute target path with sourcepath when generating default label. This is used with fcontext. Requires source and target path arguments. The context labeling for the target subtree is made equivalent to that defined for the source.
> > +.I \-e TARGET_PATH, \-\-equal TARGET_PATH
> > +Substitute FILE_SPEC with TARGET_PATH for file label lookup. This is used with fcontext. Requires source and target path arguments to be path prefixes and does not support regular expressions. The context labeling for the target subtree is made equivalent to that defined for the source.
> > .TP
> > .I \-f [{a,f,d,c,b,s,l,p}], \-\-ftype [{a,f,d,c,b,s,l,p}]
> > File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use 'd' to match only directories or 'f' to match only regular files. The following file type options can be passed: f (regular file),d (directory),c (character device), b (block device),s (socket),l (symbolic link),p (named pipe). If you do not specify a file type, the file type will default to "all files".
> > diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> > index 10963e81..854381d4 100644
> > --- a/python/semanage/seobject.py
> > +++ b/python/semanage/seobject.py
> > @@ -2453,6 +2453,19 @@ class fcontextRecords(semanageRecords):
> >
> > self.commit()
> >
> > + def delete_equal(self, target, substitute):
> > + self.begin()
> > + if target not in self.equiv.keys():
> > + raise ValueError(_("Equivalence class for %s does not exist") % target)
> > + if substitute != self.equiv[target]:
> > + raise ValueError(_("Equivalence class for %s does not match %s but %s") % (target, substitute, self.equiv[target]))
> > + del self.equiv[target]
> > + self.equal_ind = True
> > +
> > + self.mylog.log_change("resrc=fcontext op=delete-equal %s %s" % (audit.audit_encode_nv_string("sglob", target, 0), audit.audit_encode_nv_string("tglob", substitute, 0)))
> > +
> > + self.commit()
> > +
>
> Why is this necessary?
>
> It seems to work in current version:
>
> [root@localhost ~]# semanage fcontext -a -e /home /domov
> [root@localhost ~]# semanage fcontext -l | grep domov
> /domov = /home
> [root@localhost ~]# semanage fcontext -d -e /home /domov
> [root@localhost ~]# semanage fcontext -l | grep domov
> [root@localhost ~]#
True, I somehow only tried `semanage fcontext -d -e /home`, which
fails with a spare error message of `KeyError: /home`.
> > def createcon(self, target, seuser="system_u"):
> > (rc, con) = semanage_context_create(self.sh)
> > if rc < 0:
> > --
> > 2.45.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-08 16:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-30 13:50 [PATCH] semanage: improve -e documentation and fix delete operation Christian Göttsche
2025-01-08 16:29 ` Petr Lautrbach
2025-01-08 16:53 ` Christian Göttsche
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.