>From a414779a9c49f8c6d1d8ebf3e897641596fa805b Mon Sep 17 00:00:00 2001
From: Lukasz Zalewski <lukas@eecs.qmul.ac.uk>
Date: Wed, 9 May 2012 14:24:01 +0100
Subject: [PATCH] When listing group members allow fallback to cn attribute when samAccountName is not available

---
 source4/scripting/python/samba/netcmd/group.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/source4/scripting/python/samba/netcmd/group.py b/source4/scripting/python/samba/netcmd/group.py
index 265170d..0f4a744 100644
--- a/source4/scripting/python/samba/netcmd/group.py
+++ b/source4/scripting/python/samba/netcmd/group.py
@@ -346,13 +346,16 @@ samba-tool group listmembers \"Domain Users\" -H ldap://samba.samdom.example.com
             search_filter = "(|(primaryGroupID=%s)(memberOf=%s))" % (rid, group_dn)
             res = samdb.search(samdb.domain_dn(), scope=ldb.SCOPE_SUBTREE,
                                expression=(search_filter),
-                               attrs=["samAccountName"])
+                               attrs=["samAccountName", "cn"])
 
             if (len(res) == 0):
                 return
 
             for msg in res:
-                self.outf.write("%s\n" % msg.get("samAccountName", idx=0))
+                member_name = msg.get("samAccountName", idx=0)
+                if member_name is None:
+                    member_name = msg.get("cn", idx=0)
+                self.outf.write("%s\n" % member_name)
 
         except Exception, e:
             raise CommandError('Failed to list members of "%s" group ' % groupname, e)
-- 
1.7.1

