5 """Bind to the Texas A&M LDAP server."""
6 server = "operator.tamu.edu"
9 self.l = ldap.open(server)
10 self.l.simple_bind(who, cred)
11 #print "bound successfully"
13 def lookup(self,username=""):
14 """Look up person with netid <username> and return a dictionary of relevant attributes."""
16 scope = ldap.SCOPE_SUBTREE
20 filter = "tamuEduPersonUIN=" + username
22 filter = "tamuEduPersonNetID=" + username
23 retrieve_attributes = ["tamuEduPersonNetID", "sn", "givenName", "mail", "major", "classification"]
30 result_id = self.l.search(base, scope, filter, retrieve_attributes)
33 result_type, result_data = self.l.result(result_id, all, timeout)
34 if (result_data == []):
37 if result_type == ldap.RES_SEARCH_ENTRY:
38 result_set.append(result_data)
40 return { "netid" : username }
41 if len(result_set) == 0:
42 # print "No matching NetID"
44 toreturn["netid"] = username
45 for i in range(len(result_set)):
46 for entry in result_set[i]:
47 for attr in retrieve_attributes:
49 if entry[1][attr][0] == "":
51 # print attr,"=",entry[1][attr][0]
52 toreturn[attr] = entry[1][attr][0]
58 if __name__ == "__main__":
60 print a.lookup("drew.m.fisher")