source: trunk/locker/sbin/delete-user @ 2759

Last change on this file since 2759 was 2759, checked in by andersk, 9 years ago
Remove all remaining traces of apacheConfig records
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/python
2import ldap
3import ldap.filter
4import pwd
5import sys
6
7actuallyRun = False
8
9def delete_record(l, full_name):
10    if actuallyRun:
11        print "Deleting %s..." % (full_name,)
12        l.delete_s(full_name)
13    else:
14        print "Would have deleted %s" % (full_name,)
15
16def findUser(l, username):
17    # Try to delete the
18    user_record, = ll.search_s(
19        "ou=People,dc=scripts,dc=mit,dc=edu",
20        ldap.SCOPE_SUBTREE,
21        ldap.filter.filter_format(
22            "(&(objectClass=posixAccount)" +
23            "(uid=%s))",
24            [username]))
25
26    return user_record
27
28def findGroup(l, username):
29    group_record, = ll.search_s(
30        "ou=Groups,dc=scripts,dc=mit,dc=edu",
31        ldap.SCOPE_SUBTREE,
32        ldap.filter.filter_format(
33            "(&(objectClass=posixGroup)" +
34            "(cn=%s))",
35            [username]))
36
37    return group_record
38
39def findVhost(l, full_name):
40    host_records = ll.search_s(
41        "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu",
42        ldap.SCOPE_SUBTREE,
43        ldap.filter.filter_format(
44            "(&(objectClass=scriptsVhost)" +
45            "(scriptsVhostAccount=%s))",
46            [full_name]))
47
48    return host_records
49
50if __name__ == '__main__':
51    (self, user) = sys.argv
52
53    print "Binding to ldap..."
54
55    ll = ldap.initialize("ldapi://%2fvar%2frun%2fslapd-scripts.socket/")
56    ll.simple_bind_s("cn=Directory Manager", open('/etc/signup-ldap-pw').read())
57
58    print "Finding user '%s'..." % (user,)
59    user_record = findUser(ll, user)
60
61    print "Finding group '%s'..." % (user,)
62    group_record = findGroup(ll, user)
63
64    print "Searching for vhost configurations..."
65    vhost_configs = findVhost(ll, user_record[0])
66
67    print "Deleting..."
68    delete_record(ll, user_record[0])
69    delete_record(ll, group_record[0])
70
71    for vhost in vhost_configs:
72        delete_record(ll, vhost[0])
Note: See TracBrowser for help on using the repository browser.