add: two methods to check if a user exists or not in the database
authorRicardo Velhote <rvelhote@gmail.com>
Thu, 27 May 2010 23:54:41 +0000 (00:54 +0100)
committerRicardo Velhote <rvelhote@gmail.com>
Thu, 27 May 2010 23:54:41 +0000 (00:54 +0100)
swat/lib/samr_manager.py

index b7ce5f3ad249515aa4fc35b251b6ed3fdab3ab8e..d129f849c56a5d9379961a8d7f4a4b6111bd1d45 100644 (file)
@@ -264,6 +264,48 @@ class SAMPipeManager:
             group.description = self.get_lsa_string(query_info.description)
         
         return group
+    
+    def group_exists(self, id):
+        """ Checks if a certain Group (identified by its ID) exists in the
+        Database
+        
+        Keyword arguments:
+        id -- The ID of the Group to check
+        
+        Returns:
+        Boolean indicating if the Group exists or not
+        
+        """
+        exists = False
+        
+        try:
+            self.pipe.OpenGroup(self.domain_handle, security.SEC_FLAG_MAXIMUM_ALLOWED, id)
+            exists = True
+        except RuntimeError:
+            pass
+        
+        return exists
+    
+    def user_exists(self, id):
+        """ Checks if a certain User (identified by its ID) exists in the
+        Database
+        
+        Keyword arguments:
+        id -- The ID of the User to check
+        
+        Returns:
+        Boolean indicating if the User exists or not
+        
+        """
+        exists = False
+        
+        try:
+            self.pipe.OpenUser(self.domain_handle, security.SEC_FLAG_MAXIMUM_ALLOWED, id)
+            exists = True
+        except RuntimeError:
+            pass
+        
+        return exists
 
     @staticmethod
     def toArray((handle, array, num_entries)):