Hello Mirek,

This part:
+        selinux_ctx = None
+        if type(self.options.selinux_context) != None:
+            selinux_ctx = self.options.selinux_context
+        else:
+            selinux_ctx = ''

and

+        if type(selinux_ctx) == str:
+            params.update({
+                'selinux_ctx'   : selinux_ctx,
+            )}

means that you always override selinux context. Empty string is string as well.
If you remove that else branch, it will work.
And that
+if type(selinux_ctx) == str
is not good too.
You generaly never know if that string is str or unicode. So checking for type of string is better to be done like:

if isinstance(selinux_ctx, basestring):

but since isinstance is painfully slow, I would use in this case:

if selinux_ctx is not None:

The second patch seems ok.

Please fix the issue I mentioned and I would be happy to commit it.

Thanks your guidelines.

 I merged all the fixes into a unique patch which follow attached.

 Please let me know if some change is still needed.

 Thanks again.

Best,
mmello

From: Marcelo Moreira de Mello <mme...@redhat.com>
Date: Tue, 13 Dec 2011 14:25:44 -0200
Subject: [PATCH] 765816 - Added the option --selinux-context to rhncfg-manager 
which 
  allows to overwrite the SELinux context from a file

---
 .../rhncfg/config_management/rhncfg-manager.sgml   |    2 ++
 .../tools/rhncfg/config_management/rhncfg_add.py   |   11 ++++++++++-
 .../rhncfg/config_management/rpc_repository.py     |    7 ++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/client/tools/rhncfg/config_management/rhncfg-manager.sgml 
b/client/tools/rhncfg/config_management/rhncfg-manager.sgml
index 9b2a2e5..81ab536 100644
--- a/client/tools/rhncfg/config_management/rhncfg-manager.sgml
+++ b/client/tools/rhncfg/config_management/rhncfg-manager.sgml
@@ -96,6 +96,7 @@
             <para>-t<replaceable>TOPDIR</replaceable>, 
--topdir=<replaceable>TOPDIR</replaceable> -- make all files relative to this 
string</para>
             <para>--delim-start=<replaceable>DELIM_START</replaceable> -- 
start delimiter for variable interpolation</para>
             <para>--delim-end=<replaceable>DELIM_END</replaceable> -- end 
delimiter for variable interpolation</para>
+            <para>--selinux-context=<replaceable>SELINUX_CONTEXT</replaceable> 
-- overwrite the SELinux context label to this string</para>
         </listitem>
     </varlistentry>
     <varlistentry>
@@ -209,6 +210,7 @@
             <para>-t<replaceable>TOPDIR</replaceable>, 
--topdir=<replaceable>TOPDIR</replaceable> -- make all files relative to this 
string</para>
             <para>--delim-start=<replaceable>DELIM_START</replaceable> -- 
start delimiter for variable interpolation</para>
             <para>--delim-end=<replaceable>DELIM_END</replaceable> -- end 
delimiter for variable interpolation</para>
+            <para>--selinux-context=<replaceable>SELINUX_CONTEXT</replaceable> 
-- overwrite the SELinux context label to this string</para>
         </listitem>
     </varlistentry>
     <varlistentry>
diff --git a/client/tools/rhncfg/config_management/rhncfg_add.py 
b/client/tools/rhncfg/config_management/rhncfg_add.py
index b88fbc1..c6f24f9 100644
--- a/client/tools/rhncfg/config_management/rhncfg_add.py
+++ b/client/tools/rhncfg/config_management/rhncfg_add.py
@@ -48,6 +48,10 @@ class Handler(handler_base.HandlerBase):
             '-i', '--ignore-missing',       action="store_true",
              help="Ignore missing local files",
          ),
+        handler_base.HandlerBase._option_class(
+            '--selinux-context',       action="store_true",
+             help="Overwrite the SELinux context",
+         ),
     ]
                                                     
     def run(self):
@@ -110,13 +114,18 @@ class Handler(handler_base.HandlerBase):
 
         delim_start = self.options.delim_start
         delim_end = self.options.delim_end
+
+        selinux_ctx = None
+        if type(self.options.selinux_context) != None:
+            selinux_ctx = self.options.selinux_context
         
         for (local_file, remote_file) in files_to_push:
             try:
                 r.put_file(channel, remote_file, local_file, 
                     is_first_revision=self.is_first_revision,
                     delim_start=delim_start,
-                    delim_end=delim_end)
+                    delim_end=delim_end,
+                    selinux_ctx=selinux_ctx)
             except cfg_exceptions.RepositoryFileExistsError, e:
                 log_error("Error: %s is already in channel %s" %
                           (remote_file, channel))
diff --git a/client/tools/rhncfg/config_management/rpc_repository.py 
b/client/tools/rhncfg/config_management/rpc_repository.py
index 2206db1..4046deb 100644
--- a/client/tools/rhncfg/config_management/rpc_repository.py
+++ b/client/tools/rhncfg/config_management/rpc_repository.py
@@ -135,7 +135,7 @@ class Repository(repository.RPC_Repository):
 
     def put_file(self, config_channel, repopath, localfile=None, 
             is_first_revision=None, old_revision=None, delim_start=None, 
-            delim_end=None):
+            delim_end=None, selinux_ctx=None):
         """
         Insert a given file into the repo, overwriting if necessary.
         localfile defaults to the repopath
@@ -151,6 +151,11 @@ class Repository(repository.RPC_Repository):
             error_msg = "%s too large (%s bytes, %s bytes max allowed)"  
             raise cfg_exceptions.ConfigFileTooLargeError(error_msg % 
(localfile, params['size'], max_file_size))
 
+        if selinux_ctx is not None:
+            params.update({
+                'selinux_ctx'   : selinux_ctx,
+                )}
+
         params.update({
             'session'           : self.session,
             'config_channel'    : config_channel,
-- 
1.7.7.4

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to