WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] pygrub: trap exception when python module

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] pygrub: trap exception when python module import fails
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 07 Sep 2009 06:35:16 -0700
Delivery-date: Mon, 07 Sep 2009 06:35:26 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1252327855 -3600
# Node ID a28c9c2fa8de05ebd0284f578289e96d2d15d574
# Parent  b81e375e03922cd72d6e1404bc62a05059a4fe61
pygrub: trap exception when python module import fails

Fix the issue when importing 'crypt' module or crypt.crypt fails in
pygrub. The exception is written on the same line like "Failed!"
message but only if there is an exception. If there is no exception,
we don't bother users with details (probably the password they entered
was wrong) so we just display "Failed!" message. Also, the code for
hasPassword() was rewritten not to have try/except block here.

Signed-off-by: Michal Novotny <minovotn@xxxxxxxxxx>
---
 tools/pygrub/src/GrubConf.py |   35 +++++++++++++++++++----------------
 tools/pygrub/src/pygrub      |    6 +++++-
 2 files changed, 24 insertions(+), 17 deletions(-)

diff -r b81e375e0392 -r a28c9c2fa8de tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py      Mon Sep 07 13:49:35 2009 +0100
+++ b/tools/pygrub/src/GrubConf.py      Mon Sep 07 13:50:55 2009 +0100
@@ -158,6 +158,7 @@ class GrubConfigFile(object):
         self.timeout = -1
         self._default = 0
         self.passwordAccess = True
+        self.passExc = None
 
         if fn is not None:
             self.parse()
@@ -197,7 +198,6 @@ class GrubConfigFile(object):
             if self.commands.has_key(com):
                 if self.commands[com] is not None:
                     setattr(self, self.commands[com], arg.strip())
-                    #print "%s = %s => %s" % (com, self.commands[com], 
arg.strip() )
                 else:
                     logging.info("Ignored directive %s" %(com,))
             else:
@@ -216,25 +216,28 @@ class GrubConfigFile(object):
         self.passwordAccess = val
 
     def hasPassword(self):
-        try:
-            getattr(self, self.commands['password'])
+        return hasattr(self, 'password')
+
+    def checkPassword(self, password):
+        # Always allow if no password defined in grub.conf
+        if not self.hasPassword:
             return True
-        except:
-            return False
-
-    def checkPassword(self, password):
-        try:
-            pwd = getattr(self, self.commands['password']).split()
-            if pwd[0] == '--md5':
+
+        # If we're here, we're having 'password' attribute set
+        pwd = getattr(self, 'password').split()
+
+        # We check whether password is in MD5 hash for comparison
+        if pwd[0] == '--md5':
+            try:
                 import crypt
                 if crypt.crypt(password, pwd[1]) == pwd[1]:
                     return True
-
-            if pwd[0] == password:
-                return True
-
-            return False
-        except:
+            except Exception, e:
+                self.passExc = "Can't verify password: %s" % str(e)
+                return False
+
+        # ... and if not, we compare it as a plain text
+        if pwd[0] == password:
             return True
 
     def set(self, line):
diff -r b81e375e0392 -r a28c9c2fa8de tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub   Mon Sep 07 13:49:35 2009 +0100
+++ b/tools/pygrub/src/pygrub   Mon Sep 07 13:50:55 2009 +0100
@@ -483,7 +483,11 @@ class Grub:
                 pwd = self.text_win.getstr(6, 8)
                 if not self.cf.checkPassword(pwd):
                     self.text_win.addstr(6, 1, "Password: ")
-                    self.text_win.addstr(7, 0, "Failed!")
+                    if self.cf.passExc is not None:
+                        self.text_win.addstr(7, 0, "Exception: %s"
+                                                  % self.cf.passExc)
+                    else:
+                        self.text_win.addstr(7, 0, "Failed!")
                     self.cf.setPasswordAccess( False )
                 else:
                     self.cf.setPasswordAccess( True )

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] pygrub: trap exception when python module import fails, Xen patchbot-unstable <=