[yum-cvs] 2 commits - plugins/security

Tim Lauridsen timlau at linux.duke.edu
Thu Sep 20 06:19:59 UTC 2007


 plugins/security/security.py |  106 ++++++++++++++++++++++++++-----------------
 1 file changed, 66 insertions(+), 40 deletions(-)

New commits:
commit db6e045d6c8f4f4dffe016e41ac7dff6a0c41826
Merge: 7394103... 3d3c496...
Author: James Antill <james at code.and.org>
Date:   Wed Sep 19 14:49:08 2007 -0400

    Fix merge

diff --cc plugins/security/security.py
index b5129b0,a2d0ff4..1ce4b86
--- a/plugins/security/security.py
+++ b/plugins/security/security.py
@@@ -189,51 -174,46 +192,52 @@@ class SecurityListCommands
          def msg_warn(x):
              logger.warn(x)
  
 -        opts,cmdline = base.plugins.cmdline
 +        opts, cmdline = base.plugins.cmdline
          ygh.updates.sort(key=lambda x: x.name)
 +        filt_type = None
 +        show_type = None
 +        if len(extcmds) >= 1:
 +            filt_type = extcmds.pop(0)
 +            
 +            if False:
 +                pass
 +
 +            elif filt_type == "bugzillas":
 +                filt_type = "bugzilla"
 +            elif filt_type == "bzs":
 +                filt_type = "bugzilla"
 +            elif filt_type == "bz":
 +                filt_type = "bugzilla"
 +            elif filt_type == "bugzilla":
 +                pass
 +            
 +            elif filt_type == "sec":
 +                filt_type = "security"
 +            elif filt_type == "security":
 +                pass
 +            
 +            elif filt_type == "cves":
 +                filt_type = "cve"
 +            elif filt_type == "cve":
 +                pass
 +            else:
 +                extcmds = [filt_type] + extcmds
 +                filt_type = None
 +            show_type = filt_type
 +            if filt_type and filt_type == "security":
 +                show_type = None
 +            
 +        opts.sec_cmds = extcmds
          used_map = ysp_gen_used_map(opts)
 -        if False:
 -            pass
 -        elif len(extcmds) == 1 and (extcmds[0] == "bugzillas" or \
 -                                    extcmds[0] == "bzs"):
 -            for pkg in ygh.updates:
 -                md = ysp_should_show_pkg(opts, pkg, md_info, used_map,
 -                                         "bugzilla")
 -                if not md:
 -                    continue
 -                self.show_pkg(msg, pkg, md, "bugzilla")
 -        elif len(extcmds) == 1 and extcmds[0] == "cves":
 -            for pkg in ygh.updates:
 -                md = ysp_should_show_pkg(opts, pkg, md_info, used_map, "cve")
 -                if not md:
 -                    continue
 -                self.show_pkg(msg, pkg, md, "cve")
 -        elif len(extcmds) == 1 and (extcmds[0] == "security" or \
 -                                    extcmds[0] == "sec"):
 -            for pkg in ygh.updates:
 -                md = ysp_should_show_pkg(opts, pkg, md_info, used_map,
 -                                         "security")
 -                if not md:
 -                    continue
 -                self.show_pkg(msg, pkg, md)
 -        else:
 -            opts.advisory += extcmds
 -            used_map = ysp_gen_used_map(opts)
 -            for pkg in ygh.updates:
 -                md = ysp_should_show_pkg(opts, pkg, md_info, used_map)
 -                if not md:
 -                    continue                
 -                self.show_pkg(msg, pkg, md)
 +        for pkg in ygh.updates:
 +            md = ysp_should_show_pkg(opts, pkg, md_info, used_map,
 +                                     filt_type)
 +            if not md:
 +                continue
 +            self.show_pkg(msg, pkg, md, show_type)
          ysp_chk_used_map(used_map, msg)
  
+         self.show_pkg_exit()
 -#        else:
 -#            return 1, [str(PluginYumExit('Bad %s commands' % basecmd))]
          return 0, [basecmd + ' done']
              
  class SecurityInfoCommands(SecurityListCommands):
commit 7394103d1795dd05178866a8af8162acc17791f0
Author: James Antill <james at code.and.org>
Date:   Wed Sep 19 13:18:39 2007 -0400

    Allow package name globs on the list-sec/info-sec lines

diff --git a/plugins/security/security.py b/plugins/security/security.py
index f8f1cf8..b5129b0 100755
--- a/plugins/security/security.py
+++ b/plugins/security/security.py
@@ -37,6 +37,7 @@
 import yum
 import time
 import textwrap
+import fnmatch
 import sys
 from yum.plugins import TYPE_INTERACTIVE
 from yum.update_md import UpdateMetadata
@@ -80,8 +81,19 @@ def ysp_should_filter_pkg(opts, pkg, md, used_map):
             used_map[ref_type][ref['id']] = True
             return ref
         return None
-
-    if opts.advisory and md['update_id'] in opts.advisory:
+    def match_sec_cmd(sec_cmds, pkg, md):
+        for i in sec_cmds:
+            if fnmatch.fnmatch(pkg.name, i):
+                return i
+            if md['update_id'] == i:
+                return i
+        return None
+    
+    rcmd = match_sec_cmd(opts.sec_cmds, pkg, md)
+    if rcmd:
+        used_map['cmd'][rcmd] = True
+        return md        
+    elif opts.advisory and md['update_id'] in opts.advisory:
         used_map['id'][md['update_id']] = True
         return md
     elif opts.cve and has_id(md['references'], "cve", opts.cve):
@@ -91,7 +103,8 @@ def ysp_should_filter_pkg(opts, pkg, md, used_map):
     elif opts.security:
         if md['type'] == 'security':
             return md
-    elif not (opts.advisory or opts.cve or opts.bz or opts.security):
+    elif not (opts.advisory or opts.cve or opts.bz or opts.security or \
+              opts.sec_cmds):
         return md # This is only possible from should_show_pkg
     return None
 
@@ -116,7 +129,9 @@ def ysp_should_show_pkg(opts, pkg, md, used_map, rname=None):
     return ysp_should_filter_pkg(opts, pkg, md, used_map)
 
 def ysp_gen_used_map(opts):
-    used_map = {'bugzilla' : {}, 'cve' : {}, 'id' : {}}
+    used_map = {'bugzilla' : {}, 'cve' : {}, 'id' : {}, 'cmd' : {}}
+    for i in opts.sec_cmds:
+        used_map['cmd'][i] = False
     for i in opts.advisory:
         used_map['id'][i] = False
     for i in opts.bz:
@@ -126,6 +141,9 @@ def ysp_gen_used_map(opts):
     return used_map
 
 def ysp_chk_used_map(used_map, msg):
+    for i in used_map['cmd']:
+        if not used_map['cmd'][i]:
+            msg('Argument \"%s\" not found applicable for this system' % i)
     for i in used_map['id']:
         if not used_map['id'][i]:
             msg('Advisory \"%s\" not found applicable for this system' % i)
@@ -171,44 +189,51 @@ class SecurityListCommands:
         def msg_warn(x):
             logger.warn(x)
 
-        opts,cmdline = base.plugins.cmdline
+        opts, cmdline = base.plugins.cmdline
         ygh.updates.sort(key=lambda x: x.name)
+        filt_type = None
+        show_type = None
+        if len(extcmds) >= 1:
+            filt_type = extcmds.pop(0)
+            
+            if False:
+                pass
+
+            elif filt_type == "bugzillas":
+                filt_type = "bugzilla"
+            elif filt_type == "bzs":
+                filt_type = "bugzilla"
+            elif filt_type == "bz":
+                filt_type = "bugzilla"
+            elif filt_type == "bugzilla":
+                pass
+            
+            elif filt_type == "sec":
+                filt_type = "security"
+            elif filt_type == "security":
+                pass
+            
+            elif filt_type == "cves":
+                filt_type = "cve"
+            elif filt_type == "cve":
+                pass
+            else:
+                extcmds = [filt_type] + extcmds
+                filt_type = None
+            show_type = filt_type
+            if filt_type and filt_type == "security":
+                show_type = None
+            
+        opts.sec_cmds = extcmds
         used_map = ysp_gen_used_map(opts)
-        if False:
-            pass
-        elif len(extcmds) == 1 and (extcmds[0] == "bugzillas" or \
-                                    extcmds[0] == "bzs"):
-            for pkg in ygh.updates:
-                md = ysp_should_show_pkg(opts, pkg, md_info, used_map,
-                                         "bugzilla")
-                if not md:
-                    continue
-                self.show_pkg(msg, pkg, md, "bugzilla")
-        elif len(extcmds) == 1 and extcmds[0] == "cves":
-            for pkg in ygh.updates:
-                md = ysp_should_show_pkg(opts, pkg, md_info, used_map, "cve")
-                if not md:
-                    continue
-                self.show_pkg(msg, pkg, md, "cve")
-        elif len(extcmds) == 1 and (extcmds[0] == "security" or \
-                                    extcmds[0] == "sec"):
-            for pkg in ygh.updates:
-                md = ysp_should_show_pkg(opts, pkg, md_info, used_map,
-                                         "security")
-                if not md:
-                    continue
-                self.show_pkg(msg, pkg, md)
-        else:
-            opts.advisory += extcmds
-            used_map = ysp_gen_used_map(opts)
-            for pkg in ygh.updates:
-                md = ysp_should_show_pkg(opts, pkg, md_info, used_map)
-                if not md:
-                    continue                
-                self.show_pkg(msg, pkg, md)
+        for pkg in ygh.updates:
+            md = ysp_should_show_pkg(opts, pkg, md_info, used_map,
+                                     filt_type)
+            if not md:
+                continue
+            self.show_pkg(msg, pkg, md, show_type)
         ysp_chk_used_map(used_map, msg)
-#        else:
-#            return 1, [str(PluginYumExit('Bad %s commands' % basecmd))]
+
         return 0, [basecmd + ' done']
             
 class SecurityInfoCommands(SecurityListCommands):
@@ -288,7 +313,7 @@ def ysp_check_func_enter(conduit):
     opts, args = conduit.getCmdLine()
 
     ndata = not (opts.security or opts.advisory or opts.bz or opts.cve)
-
+    
     ret = None
     if len(args) >= 2:
         if ((args[0] == "list") and (args[1] == "updates")):
@@ -337,6 +362,7 @@ def exclude_hook(conduit):
                      (pkg,pkg.repoid))
         conduit.delPackage(pkg)
 
+    opts.sec_cmds = []
     used_map = ysp_gen_used_map(opts)
     # The official API is:
     #
@@ -385,6 +411,7 @@ def preresolve_hook(conduit):
 
     tot = 0
     cnt = 0
+    opts.sec_cmds = []
     used_map = ysp_gen_used_map(opts)
     tsinfo = conduit.getTsInfo()
     tspkgs = tsinfo.getMembers()



More information about the Yum-cvs-commits mailing list