source: trunk/third/moira/gen/ldap.gen @ 25817

Revision 25817, 3.3 KB checked in by jdreed, 12 years ago (diff)
In moira: * Re-snapshot moira at r4097 to pick up Status 10 (Suspended) (Trac: #1295) * Remove our addusr.1 and namespace.1 in favor of upstreams (Trac: #918) * Build-dep on OpenSSL and pass new configure flag per moira r4091
  • Property svn:executable set to *
Line 
1#!/moira/bin/perl -Tw
2
3# $Id: ldap.gen 4097 2013-02-11 14:54:53Z zacheiss $
4
5use DBI;
6
7# The following exit codes are defined and MUST BE CONSISTENT with the
8# error codes the library uses:
9$MR_DBMS_ERR = 47836421;
10$MR_OCONFIG = 47836460;
11
12$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
13
14$outdir = '/moira/dcm/ldap';
15$outfile = '/moira/dcm/ldap.out';
16umask 022;
17
18$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
19    || exit $MR_DBMS_ERR;
20
21$sth0 = $dbh->prepare("SELECT u.login, u.first, u.middle, u.last, " .
22                      "u.clearid, u.unix_uid, u.shell FROM users u " .
23                      "WHERE (u.status = 1 OR u.status = 9 OR u.status = 10)")
24    || exit $MR_DBMS_ERR;
25
26
27$sth0->execute;
28
29open(OUT, ">$outdir/users") || exit $MR_OCONFIG;
30
31while(($login, $first, $middle, $last, $clearid, $unix_uid,
32       $shell) = $sth0->fetchrow_array) {
33    $row = "dn: uid=$login,ou=users,dc=mit,dc=edu\n";
34    $row .= "objectclass: top\n";
35    $row .= "objectclass: person\n";
36    $row .= "objectclass: organizationalperson\n";
37    $row .= "objectclass: inetorgperson\n";
38    $row .= "objectClass: krb5Principal\n";
39    $row .= "uid: $login\n";
40    $row .= "krb5PrincipalName: $login\@ATHENA.MIT.EDU\n";
41    $row .= "userPassword: {KERBEROS}$login\@ATHENA.MIT.EDU\n";
42    $row .= "employeeNumber: $clearid\n";
43    $row .= "loginShell: $shell\n";
44    $row .= "uidNumber: $unix_uid\n";
45    $row .= "gidNumber: 101\n";
46
47    if($last) {
48       $sn = "sn: $last\n";
49    }
50    else {
51       $sn = "sn: NONE\n";
52    }
53
54    if($first) {
55       $cn = "cn: $first";
56       $givenName = "givenName: $first";
57    }
58    else {
59       $cn = "cn:";
60       $givenName = "givenName:";
61    }
62
63    if($middle) {
64       $cn .= " $middle\n";
65       $givenName .= " $middle\n";
66    }
67    else {
68       $cn .= "\n";
69       $givenName .= "\n";
70    }
71
72    $sth = $dbh->prepare("SELECT f.type, f.name FROM filesys f " .
73                         "WHERE f.label = '$login'") || exit $MR_DBMS_ERR;
74   
75    $sth->execute;
76   
77    if(($f_type, $f_name) = $sth->fetchrow_array) {
78        if($f_type eq "AFS") {
79            $row .= "homeDirectory: $f_name\n";
80        }
81    }
82
83    $row .= $sn;
84    $row .= $cn;
85    $row .= $givenName;
86    $row .= "ou: user\n";
87    $row .= "description: user\n\n";
88    $row =~ s/\0//g;
89
90    print OUT $row;
91}
92close(OUT);
93
94open(OUT, ">$outdir/groups") || exit $MR_OCONFIG;
95
96$sth0 = $dbh->prepare("SELECT name FROM list WHERE active = 1 " .
97                      "AND grouplist = 1")
98    || exit $MR_DBMS_ERR;
99
100$sth0->execute;
101
102while (($name) = $sth0->fetchrow_array) {
103    $sth = $dbh->prepare("SELECT UNIQUE u.login FROM users u, imembers i, " .
104                         "list l WHERE l.name = " . $dbh->quote($name) .
105                         "AND l.list_id = i.list_id " .
106                         "AND i.member_type = 'USER' " .
107                         "AND (u.status = 1 OR u.status = 9 OR u.status = 10) " .
108                         "AND i.member_id = u.users_id") || exit $MR_DBMS_ERR;
109    $sth->execute;
110
111    $members = 0;
112    while (($member) = $sth->fetchrow_array) {
113        if(!$members) {
114            $row = "dn: cn=$name,ou=groups,dc=mit,dc=edu\n";
115            $row .= "objectClass: top\n";
116            $row .= "objectClass: groupOfUniqueNames\n";
117            $row .= "cn: $name\n";
118            $row =~ s/\0//g;
119            print OUT $row;
120
121            $members = 1;
122        }
123
124        $row = "uniqueMember: uid=$member,ou=users,dc=mit,dc=edu\n";
125        $row =~ s/\0//g;
126        print OUT $row;
127    }
128
129    print OUT "\n";
130}
131close(OUT);
132
133system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
134
135$dbh->disconnect;
136
137exit 0;
Note: See TracBrowser for help on using the repository browser.