Bug 1120802 - From spacewalk webUI, Config file compare doesn't check for user, group and permissions.
Summary: From spacewalk webUI, Config file compare doesn't check for user, group and p...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Spacewalk
Classification: Community
Component: Clients
Version: 2.2
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: Stephen Herr
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On: 1004746
Blocks: space23
TreeView+ depends on / blocked
 
Reported: 2014-07-17 18:09 UTC by Stephen Herr
Modified: 2015-04-14 19:03 UTC (History)
5 users (show)

Fixed In Version: rhncfg-5.10.74-1
Doc Type: Bug Fix
Doc Text:
Clone Of: 1004746
Environment:
Last Closed: 2015-04-14 19:03:15 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1021930 0 unspecified CLOSED From webUI, Config file compare doesn't check for user, group and permissions. 2021-02-22 00:41:40 UTC

Internal Links: 1021930

Description Stephen Herr 2014-07-17 18:09:46 UTC
+++ This bug was initially created as a clone of Bug #1004746 +++

Description of problem:
From satellite WebUI, config file comparison doesnt check for user, mode and permissions.

It displays compare results for only selinux and file content. 

Other way when checking from client side
rhncfg-client verify

It display results for user, group, permissions, selinux and file content.
 
Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. change in file's user, group and permissions
2. Schedule compare from satellite GUI 
3. Check for results from event -> history 

Actual results:
It should display differences in user, group and permissions

Expected results:
It will display "No Differences"

Additional info:

--- Additional comment from Neha on 2013-09-05 08:05:59 EDT ---

Current code for diff functionality 

   else:
            result = ''.join(diff(temp_file, path))

        os.unlink(temp_file)
        return sectx_result + result


It displays results -> content diff + selinux diff


And from cmd line:

rhncfg-client verify 

                                  /root/nerawat/nerawat2/test1
                                  /root/nerawat/nerawat2/test2
                    mode,modified /root/nerawat/test1
 user,group,mode,selinux,modified /root/nerawat/test2
                                  /root/nerawat/test3
                          selinux /root/nerawat/test4
                                  /root/test

--- Additional comment from Neha on 2013-09-05 08:15:10 EDT ---

I tried to change code according to cli functionality, Will do some more testing and will try to submit patch for the same 

--- file_utils_orig.py  2013-08-30 06:23:04.000000000 -0400
+++ file_utils.py       2013-09-05 11:38:32.000000000 -0400
@@ -19,6 +19,8 @@
 import tempfile
 import base64
 import difflib
+import pwd
+import grp
 try:
     from selinux import lgetfilecon, is_selinux_enabled
 except:
@@ -96,10 +98,73 @@
         self._validate_struct(file_struct)
 
         temp_file, temp_dirs = self.process(file_struct)
         path = file_struct['path']
+       owner_result = ''
+       group_result = ''
+       perm_result = ''
         sectx_result = ''
         result = ''
 
+       stat_err = 0
+        
+       try:
+            cur_stat = os.lstat(path)
+        except:
+            stat_err = 1
+
+       if file_struct['filetype'] != 'symlink':
+           if not stat_err:
+                #check for owner differences
+                 cur_uid = cur_stat[stat.ST_UID]
+                 try:
+                     cur_user = pwd.getpwuid(cur_uid)[0]
+                 except KeyError:
+                     #Orphan UID with no name,return unknown
+                     cur_user = "unknown(UID %d)" % (cur_uid,)
+            else:
+                 cur_user = "missing"
+              
+           if cur_user == file_struct['username']:
+                owner_result = ""
+
+            else:
+                 owner_result = "User name differ: actual: [%s], expected: [%s]\n" % (cur_user, file_struct['username'])
+            
+           if not stat_err:
+                #check for group differences
+                cur_gid = cur_stat[stat.ST_GID]
+                try:
+                    cur_group = grp.getgrgid(cur_gid)[0]
+                except KeyError:
+                    #Orphan GID with no name,return unknown
+                    cur_group = "unknown(GID %d)" % (cur_gid,)
+            else:
+                cur_group = "missing"
+
+            if cur_group == file_struct['groupname']:
+                group_result = ""
+            else:
+                group_result = "Group name differ: actual: [%s], expected: [%s]\n" % (cur_group, file_struct['groupname'])
+
+           #check for permissions differences
+            if not stat_err:
+                cur_perm = str(oct(stat.S_IMODE(cur_stat[stat.ST_MODE])))
+               print cur_perm
+            else:
+                cur_perm = "missing"
+
+            #rip off the leading '0' from the mode returned by stat()
+            if cur_perm[0] == '0':
+                cur_perm = cur_perm[1:]
+
+            #perm_status gets displayed with the verbose option.
+            if cur_perm == file_struct['filemode']:
+                perm_result = ""
+            else:
+                perm_result = "File mode differ: actual: [%s], expected: [%s]\n" % (cur_perm, file_struct['filemode'])
+
         try:
             cur_sectx = lgetfilecon(path)[1]
         except OSError: # workarounding BZ 690238
@@ -131,7 +196,7 @@
             result = ''.join(diff(temp_file, path))
 
         os.unlink(temp_file)
-        return sectx_result + result
+        return owner_result + group_result + perm_result + sectx_result + result
 
     def _validate_struct(self, file_struct):
         for k in self.file_struct_fields.keys():

--- Additional comment from Neha on 2013-10-22 07:25:13 EDT ---

According to current functionality only selinux check and check for links

SELinux contexts differ:  actual: [root:object_r:user_home_dir_t], expected: [user_u:role_r]


After adding diff functionality for group, user and mod:

User name differ: actual: [nerawat], expected: [root]
Group name differ: actual: [nerawat], expected: [root]
File mode differ: actual: [777], expected: [775]

~ Neha

Comment 1 Stephen Herr 2014-07-17 18:29:37 UTC
Committing patch with minor changes:
276531ce4d5c9e8827331e9708ab8efb8c5f1a7f
3d49d0647e53090b4863029a3323ecae3c4c256b

Thanks!

Comment 2 Neha 2014-07-18 04:48:12 UTC
Thank you sherr.

I had cretaed below BZ for spacewalk 
https://bugzilla.redhat.com/show_bug.cgi?id=1021930

I think we can close as duplicate.

~ Neha

Comment 3 Stephen Herr 2014-07-18 12:26:49 UTC
Oh, sorry I didn't notice that earlier. I'll close your bz as the duplicate since I've already put this bz number in the commit messages.

Comment 4 Stephen Herr 2014-07-18 12:27:03 UTC
*** Bug 1021930 has been marked as a duplicate of this bug. ***

Comment 5 Stephen Herr 2014-07-18 13:21:32 UTC
Actually I'm going to release this change in Spacewalk 2.2, so I'll use your bug for that.

Comment 6 Stephen Herr 2014-07-22 19:12:37 UTC
Comparing directories was not working properly, they were always displaying as being correct even when they weren't.

Fixed in Spacewalk master:
0cc679bce2150bda64af88ca962622d0180bbdb1

Comment 7 Grant Gainey 2015-03-23 16:59:07 UTC
Moving bugs to ON_QA as we move to release Spacewalk 2.3

Comment 8 Grant Gainey 2015-04-14 19:03:15 UTC
Spacewalk 2.3 has been released. See

https://fedorahosted.org/spacewalk/wiki/ReleaseNotes23


Note You need to log in before you can comment on or make changes to this bug.