+def get_accounts(ldap_conn):
+ # Fetch all the users
+ passwd_attrs = ldap_conn.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "(&(uid=*)(!(uidNumber=0))(objectClass=shadowAccount))",\
+ ["uid", "uidNumber", "gidNumber", "supplementaryGid",\
+ "gecos", "loginShell", "userPassword", "shadowLastChange",\
+ "shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
+ "shadowExpire", "emailForward", "latitude", "longitude",\
+ "allowedHost", "sshRSAAuthKey", "dnsZoneEntry", "cn", "sn",\
+ "keyFingerPrint", "privateSub", "mailDisableMessage",\
+ "mailGreylisting", "mailCallout", "mailRBL", "mailRHSBL",\
+ "mailWhitelist", "sudoPassword", "objectClass", "accountStatus",\
+ "mailContentInspectionAction"])
+
+ if passwd_attrs is None:
+ raise UDEmptyList, "No Users"
+ accounts = map(lambda x: UDLdap.Account(x[0], x[1]), passwd_attrs)
+ accounts.sort(lambda x,y: cmp(x['uid'].lower(), y['uid'].lower()))
+
+ return accounts
+
+def get_hosts(ldap_conn):
+ # Fetch all the hosts
+ HostAttrs = ldap_conn.search_s(HostBaseDn, ldap.SCOPE_ONELEVEL, "objectClass=debianServer",\
+ ["hostname", "sshRSAHostKey", "purpose", "allowedGroups", "exportOptions",\
+ "mXRecord", "ipHostNumber", "dnsTTL", "machine", "architecture"])
+
+ if HostAttrs == None:
+ raise UDEmptyList, "No Hosts"
+
+ HostAttrs.sort(lambda x, y: cmp((GetAttr(x, "hostname")).lower(), (GetAttr(y, "hostname")).lower()))
+
+ return HostAttrs
+
+
+def make_ldap_conn():
+ # Connect to the ldap server
+ l = connectLDAP()
+ # for testing purposes it's sometimes useful to pass username/password
+ # via the environment
+ if 'UD_CREDENTIALS' in os.environ:
+ Pass = os.environ['UD_CREDENTIALS'].split()
+ else:
+ F = open(PassDir + "/pass-" + pwd.getpwuid(os.getuid())[0], "r")
+ Pass = F.readline().strip().split(" ")
+ F.close()
+ l.simple_bind_s("uid=" + Pass[0] + "," + BaseDn, Pass[1])