* [PATCH] python: Split "semanage import" into two transactions
@ 2022-05-30 12:20 Vit Mojzis
2022-06-03 14:40 ` James Carter
0 siblings, 1 reply; 3+ messages in thread
From: Vit Mojzis @ 2022-05-30 12:20 UTC (permalink / raw)
To: selinux
First transaction applies all deletion operations, so that there are no
collisions when applying the rest of the changes.
Fixes:
# semanage port -a -t http_cache_port_t -r s0 -p tcp 3024
# semanage export | semanage import
ValueError: Port tcp/3024 already defined
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
python/semanage/semanage | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/python/semanage/semanage b/python/semanage/semanage
index 8f4e44a7..1d828128 100644
--- a/python/semanage/semanage
+++ b/python/semanage/semanage
@@ -852,10 +852,29 @@ def handleImport(args):
trans = seobject.semanageRecords(args)
trans.start()
+ deleteCommands = []
+ commands = []
+ # separate commands for deletion from the rest so they can be
+ # applied in a separate transaction
for l in sys.stdin.readlines():
if len(l.strip()) == 0:
continue
+ if "-d" in l or "-D" in l:
+ deleteCommands.append(l)
+ else:
+ commands.append(l)
+
+ if deleteCommands:
+ importHelper(deleteCommands)
+ trans.finish()
+ trans.start()
+
+ importHelper(commands)
+ trans.finish()
+
+def importHelper(commands):
+ for l in commands:
try:
commandParser = createCommandParser()
args = commandParser.parse_args(mkargv(l))
@@ -869,8 +888,6 @@ def handleImport(args):
except KeyboardInterrupt:
sys.exit(0)
- trans.finish()
-
def setupImportParser(subparsers):
importParser = subparsers.add_parser('import', help=_('Import local customizations'))
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] python: Split "semanage import" into two transactions
2022-05-30 12:20 [PATCH] python: Split "semanage import" into two transactions Vit Mojzis
@ 2022-06-03 14:40 ` James Carter
2022-06-06 20:43 ` James Carter
0 siblings, 1 reply; 3+ messages in thread
From: James Carter @ 2022-06-03 14:40 UTC (permalink / raw)
To: Vit Mojzis; +Cc: SElinux list
On Mon, May 30, 2022 at 9:32 AM Vit Mojzis <vmojzis@redhat.com> wrote:
>
> First transaction applies all deletion operations, so that there are no
> collisions when applying the rest of the changes.
>
> Fixes:
> # semanage port -a -t http_cache_port_t -r s0 -p tcp 3024
> # semanage export | semanage import
> ValueError: Port tcp/3024 already defined
>
> Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
Acked-by: James Carter <jwcart2@gmail.com>
> ---
> python/semanage/semanage | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/python/semanage/semanage b/python/semanage/semanage
> index 8f4e44a7..1d828128 100644
> --- a/python/semanage/semanage
> +++ b/python/semanage/semanage
> @@ -852,10 +852,29 @@ def handleImport(args):
> trans = seobject.semanageRecords(args)
> trans.start()
>
> + deleteCommands = []
> + commands = []
> + # separate commands for deletion from the rest so they can be
> + # applied in a separate transaction
> for l in sys.stdin.readlines():
> if len(l.strip()) == 0:
> continue
> + if "-d" in l or "-D" in l:
> + deleteCommands.append(l)
> + else:
> + commands.append(l)
> +
> + if deleteCommands:
> + importHelper(deleteCommands)
> + trans.finish()
> + trans.start()
> +
> + importHelper(commands)
> + trans.finish()
>
> +
> +def importHelper(commands):
> + for l in commands:
> try:
> commandParser = createCommandParser()
> args = commandParser.parse_args(mkargv(l))
> @@ -869,8 +888,6 @@ def handleImport(args):
> except KeyboardInterrupt:
> sys.exit(0)
>
> - trans.finish()
> -
>
> def setupImportParser(subparsers):
> importParser = subparsers.add_parser('import', help=_('Import local customizations'))
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] python: Split "semanage import" into two transactions
2022-06-03 14:40 ` James Carter
@ 2022-06-06 20:43 ` James Carter
0 siblings, 0 replies; 3+ messages in thread
From: James Carter @ 2022-06-06 20:43 UTC (permalink / raw)
To: Vit Mojzis; +Cc: SElinux list
On Fri, Jun 3, 2022 at 10:40 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, May 30, 2022 at 9:32 AM Vit Mojzis <vmojzis@redhat.com> wrote:
> >
> > First transaction applies all deletion operations, so that there are no
> > collisions when applying the rest of the changes.
> >
> > Fixes:
> > # semanage port -a -t http_cache_port_t -r s0 -p tcp 3024
> > # semanage export | semanage import
> > ValueError: Port tcp/3024 already defined
> >
> > Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>
Merged.
Thanks,
Jim
>
> > ---
> > python/semanage/semanage | 21 +++++++++++++++++++--
> > 1 file changed, 19 insertions(+), 2 deletions(-)
> >
> > diff --git a/python/semanage/semanage b/python/semanage/semanage
> > index 8f4e44a7..1d828128 100644
> > --- a/python/semanage/semanage
> > +++ b/python/semanage/semanage
> > @@ -852,10 +852,29 @@ def handleImport(args):
> > trans = seobject.semanageRecords(args)
> > trans.start()
> >
> > + deleteCommands = []
> > + commands = []
> > + # separate commands for deletion from the rest so they can be
> > + # applied in a separate transaction
> > for l in sys.stdin.readlines():
> > if len(l.strip()) == 0:
> > continue
> > + if "-d" in l or "-D" in l:
> > + deleteCommands.append(l)
> > + else:
> > + commands.append(l)
> > +
> > + if deleteCommands:
> > + importHelper(deleteCommands)
> > + trans.finish()
> > + trans.start()
> > +
> > + importHelper(commands)
> > + trans.finish()
> >
> > +
> > +def importHelper(commands):
> > + for l in commands:
> > try:
> > commandParser = createCommandParser()
> > args = commandParser.parse_args(mkargv(l))
> > @@ -869,8 +888,6 @@ def handleImport(args):
> > except KeyboardInterrupt:
> > sys.exit(0)
> >
> > - trans.finish()
> > -
> >
> > def setupImportParser(subparsers):
> > importParser = subparsers.add_parser('import', help=_('Import local customizations'))
> > --
> > 2.35.1
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-06 20:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30 12:20 [PATCH] python: Split "semanage import" into two transactions Vit Mojzis
2022-06-03 14:40 ` James Carter
2022-06-06 20:43 ` James Carter
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.