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] [XEND] Add some docstrings about XendAuth

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [XEND] Add some docstrings about XendAuthSessions
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 02 Nov 2006 22:09:11 +0000
Delivery-date: Thu, 02 Nov 2006 21:42:55 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
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/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/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 Alastair Tse <atse@xxxxxxxxxxxxx>
# Node ID f0c7f258c19e0bd1f231dab4185287a0cff4db73
# Parent  f895b7c94f1044b737d7eeb718caa8da076419ed
[XEND] Add some docstrings about XendAuthSessions

Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAuthSessions.py |   33 +++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff -r f895b7c94f10 -r f0c7f258c19e tools/python/xen/xend/XendAuthSessions.py
--- a/tools/python/xen/xend/XendAuthSessions.py Thu Oct 19 17:46:08 2006 +0100
+++ b/tools/python/xen/xend/XendAuthSessions.py Thu Oct 19 17:46:54 2006 +0100
@@ -16,15 +16,21 @@
 #============================================================================
 
 import time
-import PAM
 
 from xen.xend import uuid
 from xen.xend.XendError import *
 from xen.xend.XendLogging import log
 
+try:
+    import PAM
+except ImportError:
+    log.warn("python-pam is required for XenAPI support.")
+
 class XendAuthSessions:
-    """Keeps track of Xen API Login Sessions. (Example only)"""
+    """Keeps track of Xen API Login Sessions using PAM.
 
+    Note: Login sessions are not valid across instances of Xend.
+    """
     def __init__(self):
         self.sessions = {}
 
@@ -32,6 +38,12 @@ class XendAuthSessions:
         pass
 
     def login_with_password(self, username, password):
+        """Returns a session UUID if valid, otherwise raises an error.
+
+        @raises XendError: If login fails.
+        @rtype: string
+        @return: Session UUID
+        """
         if self.is_authorized(username, password):
             new_session = uuid.createString()
             self.sessions[new_session] = (username, time.time())
@@ -40,16 +52,31 @@ class XendAuthSessions:
         raise XendError("Login failed")
 
     def logout(self, session):
+        """Delete session of it exists."""
         if self.is_session_valid(session):
             del self.sessions[session]
 
     def is_session_valid(self, session):
+        """Returns true is session is valid."""
         if type(session) == type(str()):
             return (session in self.sessions)
         return False
 
     def is_authorized(self, username, password):
-        pam_auth = PAM.pam()
+        """Returns true is a user is authorised via PAM.
+
+        Note: We use the 'login' PAM stack rather than inventing
+              our own.
+
+        @rtype: boolean
+        """
+        pam_auth = None
+        try:
+            pam_auth = PAM.pam()
+        except NameError:
+            # if PAM doesn't exist, let's ignore it
+            return False
+        
         pam_auth.start("login")
         pam_auth.set_item(PAM.PAM_USER, username)
 

_______________________________________________
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] [XEND] Add some docstrings about XendAuthSessions, Xen patchbot-unstable <=