Do SSL when connecting to the ldap server.
[mirror/userdir-ldap.git] / ud-passchk
1 #!/usr/bin/env python
2 # -*- mode: python -*-
3 # Checks the passwd file to make sure all entries are in the directory
4
5 import ldap, getopt, sys, os;
6 from userdir_ldap import *;
7
8 def PassCheck(l,File,HomePrefix):
9    F = open(File,"r");
10    
11    # Fetch all the users and generate a map out of them
12    Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
13            ["uid","uidNumber","gidNumber","loginShell"]);
14    UIDMap = {};
15    for x in Attrs:
16       if x[1].has_key("uid") == 0:
17          continue;
18       UIDMap[x[1]["uid"][0]] = x[1];
19    
20    # Iterate over every user in the passwd file
21    while(1):
22       Line = F.readline();
23       if Line == "":
24          break;
25       
26       Split = Line.split(":")
27       if UIDMap.has_key(Split[0]) == 0:
28          print Line,
29          continue;
30
31       Ats = UIDMap[Split[0]];
32       Miss = [];
33       if Ats.has_key("uidNumber") and Ats["uidNumber"][0] != Split[2]: 
34           Miss.append("UID");
35       if Ats.has_key("uidNumber") and Ats["gidNumber"][0] != Split[3]: 
36           Miss.append("GID");
37       if Ats.has_key("homeDirectory") and \
38          split[5] != HomePrefix + Split[0]:
39          Miss.append("Home");
40       if len(Miss) != 0:
41          print "mismatch",Split[0],Miss;
42
43 # Connect to the ldap server
44 l = connectLDAP()
45 l.simple_bind_s("","");
46
47 PassCheck(l,sys.argv[1],sys.argv[2]);