source: trunk/third/moira/gen/ca.gen @ 23740

Revision 23740, 1.9 KB checked in by broder, 16 years ago (diff)
In moira: * New CVS snapshot (Trac: #195) * Drop patches that have been incorporated upstream. * Update to build without krb4 on systems that no longer have it. This doesn't build yet on squeeze, which lacks a krb4 library, but I'm committing now before I start hacking away at a patch to fix that.
  • Property svn:executable set to *
RevLine 
[23095]1#!/moira/bin/perl -Tw
2
[23740]3# $Id: ca.gen,v 1.3 2006-05-11 16:55:28 zacheiss Exp $
[23095]4
5# The following exit codes are defined and MUST BE CONSISTENT with the
6# error codes the library uses:
7$MR_DBMS_ERR = 47836421;
8$MR_OCONFIG = 47836460;
9
10$outfile = '/moira/dcm/ca.out';
11
12use DBI;
13$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
14    || exit $MR_DBMS_ERR;
15
16# First, let's do people with NFS homedirs, since it's not hard.
17$sth = $dbh->prepare("SELECT n.nfsphys_id, n.dir, m.name ".
18                     "FROM nfsphys n, machine m ".
19                     "WHERE m.mach_id = n.mach_id ".
20                     "ORDER BY n.nfsphys_id") || exit $MR_DBMS_ERR;
21
22$sth->execute || exit $MR_DBMS_ERR;
23
24umask 022;
25open(OUT, ">$outfile") || exit $MR_OCONFIG;
26
27while (($id, $dir, $machname) = $sth->fetchrow_array) {
28    next if ($id == 0);
29    $foo = $dbh->prepare("SELECT u.login, u.fullname ".
30                         "FROM users u, filesys f ".
31                         "WHERE f.label = u.login AND u.status = 1 ".
32                         "AND f.phys_id = " . $dbh->quote($id));
33    $first = 1;
34    $foo->execute || exit $MR_DBMS_ERR;
35    while (($login, $fullname) = $foo->fetchrow_array) {
36        if ($first) {
37            $first = 0;
38            $row = "*$machname:$dir\n";
39            $row =~ s/\0//g;
40            print OUT $row;
41        }
42        $row = "$login,$fullname\n";
43        $row =~ s/\0//g;
44        print OUT $row;
45    }
46}
47
48#Now, let's do all the AFS homedirs.  This will take a while longer.
49$sth = $dbh->prepare("SELECT UNIQUE u.login, u.fullname, f.name ".
50                     "FROM users u, filesys f ".
51                     "WHERE f.label = u.login AND u.status = 1 ".
52                     "AND f.type = 'AFS' ".
53                     "ORDER BY u.login") || exit $MR_DBMS_ERR;
54
55$sth->execute || exit $MR_DBMS_ERR;
56
57$last = "";
58while (($login, $name, $dir) = $sth->fetchrow_array) {
59    $dir =~ /(\/.*)\//;
60    $path = $1;
61    if ($path ne $last) {
62        $last = $path;
63        $row = "*AFS:$path\n";
64        $row =~ s/\0//g;
65        print OUT $row;
66    }
67    $row = "$login,$name\n";
68    $row =~ s/\0//g;
69    print OUT $row;
70}
71
72close(OUT);
73$dbh->disconnect;
74
75exit 0;
Note: See TracBrowser for help on using the repository browser.