M K wrote:
> What I'm trying to do is build a program against a Microsoft Active
> Directory that will find all group memberships for the current user. 
> Because we have nested groups, it will need to do so recursively.
> 

> I wanted to share this before I delve any further to make sure I'm not
> making any newbie mistakes. My ultimate goal is to build a List of all 
> these Groups, and remove any duplicates that may show up.
> 
> Here's the current state:
> ____________________
> 
> import active_directory
> 
> def nestedlookup (group):
>    """ does a recursive lookup """
>    nested_list = group.memberOf
>    for members in nested_list:
>        print "DESCENDENT: ", members.cn
>        nestedlookup(members)
> 
> user = active_directory.find_user ()
> print "User:", user.cn
> 
> group_list = user.memberOf
> 
> for group in user.memberOf:
>    print "PARENT: ", group.cn
>    nestedlookup(group)
> 
> ______________________

Looks fine to me. Obviously you'll need to *return*
something from the nestedlookup function, not just
print, but I assume you have that already in hand.

I did toy with including this functionality (a sort
of inverse .walk) in the module's functionality, but
it dropped out somewhere along the way. If I did put
it in, the implementation would be pretty much like
yours eg:

<code>
def walkup (self):
   yield self
   for parent in self.memberOf:
     for ancestor in parent.walkup ():
       yield ancestor

</code>

even now, you could monkeypatch that function in if
you wanted:

<code>
import active_directory

def walkup (self):
   yield self
   for parent in self.memberOf:
     for ancestor in parent.walkup ():
       yield ancestor

active_directory._AD_group.walkup = walkup

me = active_directory.find_user ()
groups = set ()
for group in me.memberOf:
   groups.update (group.walkup ())


print "\n".join (g.cn for g in groups)

</code>

TJG
_______________________________________________
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to