]> andersk Git - moira.git/commitdiff
Reimplement events.gen as a Pro*C application.
authorzacheiss <zacheiss>
Mon, 26 Mar 2007 18:14:41 +0000 (18:14 +0000)
committerzacheiss <zacheiss>
Mon, 26 Mar 2007 18:14:41 +0000 (18:14 +0000)
gen/Makefile.in
gen/events.gen [deleted file]
gen/events.pc [new file with mode: 0644]

index ecfb5bc2d0c3cda606bbb41c336ee15a1eea2c24..84c6bfa7fa4b40e8b5299cb48a28d8110884ec3a 100644 (file)
@@ -30,20 +30,20 @@ LIB_OBJS=util.o tar.o genacl.o
 LIB_CFILES=genacl.c
 LIB_TARGET=libdcm.a
 
-OBJS=  acl.o boot.o dhcp.o directory.o hesiod.o hosts.o mailhub.o \
+OBJS=  acl.o boot.o dhcp.o directory.o events.o hesiod.o hosts.o mailhub.o \
        ndb.o network.o nfs.o pobox.o postoffice.o print.o \
        winad.o www.o zephyr.o
 
-CFILES= acl.c boot.c dhcp.c directory.c hesiod.c hosts.c mailhub.c \
+CFILES= acl.c boot.c dhcp.c directory.c events.c hesiod.c hosts.c mailhub.c \
        ndb.c network.c nfs.c pobox.c postoffice.c print.c \
        winad.c www.c zephyr.c
 
-TARGET=        acl.gen boot.gen dhcp.gen directory.gen hesiod.gen hosts.gen \
+TARGET=        acl.gen boot.gen dhcp.gen directory.gen events.gen hesiod.gen hosts.gen \
        mailhub.gen ndb.gen network.gen nfs.gen pobox.gen \
        postoffice.gen print.gen winad.gen www.gen zephyr.gen
 
 SCRIPTS=access.gen access.sh acl.sh aliases.sh boot.sh ca.gen calendar.gen \
-       confluence.gen dhcp.sh events.gen events.sh hesiod.sh ip-billing.gen \
+       confluence.gen dhcp.sh events.sh hesiod.sh ip-billing.gen \
        ip-billing.sh ldap.gen longjobs.gen longjobs.sh mailhub.sh \
        mailman.gen mailman.sh nagios-printers.gen nagios-printers.sh ndb.sh \
        nfs.sh null.sh postoffice.sh print.sh sapprint.gen sapprint.sh \
@@ -91,6 +91,9 @@ dhcp.gen: dhcp.o libdcm.a $(MR_LIBDEP)
 directory.gen: directory.o libdcm.a $(MR_LIBDEP)
        $(CC) -o $@ $(LDFLAGS) directory.o libdcm.a $(SQL_LIBS) $(LIBS)
 
+events.gen: events.o libdcm.a $(MR_LIBDEP)
+       $(CC) -o $@ $(LDFLAGS) events.o libdcm.a $(SQL_LIBS) $(LIBS)
+
 ndb.gen: ndb.o libdcm.a $(MR_LIBDEP)
        $(CC) -o $@ $(LDFLAGS) ndb.o libdcm.a $(SQL_LIBS) $(LIBS)
 
diff --git a/gen/events.gen b/gen/events.gen
deleted file mode 100755 (executable)
index ab88312..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/moira/bin/perl -Tw
-
-# $Id$
-
-# The following exit codes are defined and MUST BE CONSISTENT with the
-# error codes the library uses:
-$MR_DBMS_ERR = 47836421;
-$MR_OCONFIG = 47836460;
-
-$outfile = '/moira/dcm/events.out';
-
-use DBI;
-
-$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
-  || exit $MR_DBMS_ERR;
-
-$sth = $dbh->prepare("SELECT name FROM list WHERE maillist = 1 AND active = 1")
-    || exit $MR_DBMS_ERR;
-
-$sth->execute || exit $MR_DBMS_ERR;
-
-umask 022;
-open(OUT, ">$outfile") || exit $MR_OCONFIG;
-
-while (($name) = $sth->fetchrow_array) {
-
-    $sth2 = $dbh->prepare("SELECT UNIQUE u.login FROM users u, imembers i, " .
-                         "list l WHERE l.name = " . $dbh->quote($name) .
-                         "AND l.list_id = i.list_id " .
-                         "AND i.member_type = 'USER' " .
-                         "AND i.member_id = u.users_id") || exit $MR_DBMS_ERR;
-
-    $sth2->execute || exit $MR_DBMS_ERR;
-                
-    $row = "$name:";
-    $row =~ s/\0//g;
-    print OUT $row;
-    $maybecomma = "";
-
-    while (($member) = $sth2->fetchrow_array) {
-       $row = "$maybecomma$member";
-       $row =~ s/\0//g;
-       print OUT $row;
-       $maybecomma = ",";
-    }
-
-    $sth3 = $dbh->prepare("SELECT UNIQUE s.string FROM strings s, " .
-                         "imembers i, list l WHERE l.name = " . 
-                         $dbh->quote($name) .
-                         "AND l.list_id = i.list_id " .
-                         "AND i.member_type = 'KERBEROS' " .
-                         "AND i.member_id = s.string_id") || exit $MR_DBMS_ERR;
-    $sth3->execute || exit $MR_DBMS_ERR;
-
-    while (($member) = $sth3->fetchrow_array) {
-       # If principal is @ATHENA.MIT.EDU, strip realm, otherwise skip.
-       if ($member =~ /\@ATHENA.MIT.EDU/) {
-           $member =~ s/\@ATHENA.MIT.EDU//;
-       } else {
-           next;
-       }
-       $row = "$maybecomma$member";
-       $row =~ s/\0//g;
-       print OUT $row;
-       $maybecomma = ",";
-    }
-
-    $row = "\n";
-    $row =~ s/\0//g;
-    print OUT $row;
-}
-
-close(OUT);
-$dbh->disconnect;
-
-exit 0;
diff --git a/gen/events.pc b/gen/events.pc
new file mode 100644 (file)
index 0000000..e6f4859
--- /dev/null
@@ -0,0 +1,140 @@
+/* $Id$
+ *
+ * (c) Copyright 2007 by the Massachusetts Institute of Technology.
+ */
+
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_site.h>
+
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+
+EXEC SQL INCLUDE sqlca;
+
+#define DEFAULT_REALM "@ATHENA.MIT.EDU"
+
+char *whoami = "events.gen";
+char *db = "moira/moira";
+
+struct hash *lists;
+
+void output_list(int id, void *list, void *out);
+
+int main(int argc, char **argv)
+{
+  char filename[MAXPATHLEN], *targetfile, *l;
+  FILE *out = stdout;
+  int cnt = 0;
+  EXEC SQL BEGIN DECLARE SECTION;
+  int lid;
+  char lname[LIST_NAME_SIZE];
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL CONNECT :db;
+
+  if (argc == 2)
+    {
+      targetfile = argv[1];
+      sprintf(filename, "%s~", targetfile);
+      if (!(out = fopen(filename, "w")))
+       {
+         fprintf(stderr, "unable to open %s for output\n", filename);
+         exit(MR_OCONFIG);
+       }
+    }
+  else if (argc != 1)
+    {
+      fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
+      exit(MR_ARGS);
+    }
+
+  lists = create_hash(15000);
+
+  EXEC SQL DECLARE l_cursor CURSOR FOR
+    SELECT l.list_id, l.name FROM list l
+    WHERE l.active = 1 and l.maillist = 1;
+  EXEC SQL OPEN l_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH l_cursor INTO :lid, :lname;
+      if (sqlca.sqlcode)
+       break;
+      l = strdup(strtrim(lname));
+      if (hash_store(lists, lid, l) < 0)
+       {
+         fprintf(stderr, "Out of memory!\n");
+         exit(MR_NO_MEM);
+       }
+      cnt++;
+    }
+  EXEC SQL CLOSE l_cursor;
+  fprintf(stderr, "Loaded %d lists\n", cnt);
+
+  hash_step(lists, output_list, out);
+
+  if (fclose(out))
+    {
+      perror("close failed");
+      exit(MR_CCONFIG);
+    }
+  
+  if (argc == 2)
+    fix_file(targetfile);
+  exit(MR_SUCCESS);
+}
+
+void output_list(int id, void *list, void *out)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  char *l = list;
+  int lid = id;
+  char login[USERS_LOGIN_SIZE];
+  char principal[STRINGS_STRING_SIZE];
+  EXEC SQL END DECLARE SECTION;
+  char *maybecomma = "";
+
+  fprintf(out, "%s:", list);
+
+  EXEC SQL DECLARE u_cursor CURSOR FOR
+    SELECT UNIQUE u.login FROM users u, imembers i, list l
+    WHERE l.list_id = :lid AND l.list_id = i.list_id AND
+    i.member_type = 'USER' AND i.member_id = u.users_id;
+  EXEC SQL OPEN u_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH u_cursor INTO :login;
+      if (sqlca.sqlcode)
+       break;
+      fprintf(out, "%s%s", maybecomma, strtrim(login));
+      maybecomma = ",";
+    }
+  EXEC SQL CLOSE u_cursor;
+
+  EXEC SQL DECLARE k_cursor CURSOR FOR
+    SELECT UNIQUE s.string FROM strings s, imembers i, list l
+    WHERE l.list_id = :lid AND l.list_id = i.list_id AND
+    i.member_type = 'KERBEROS' AND i.member_id = s.string_id;
+  EXEC SQL OPEN k_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH k_cursor INTO :principal;
+      if (sqlca.sqlcode)
+       break;
+      if (strstr(principal, DEFAULT_REALM))
+       {
+         *strstr(principal, DEFAULT_REALM) = '\0';
+         fprintf(out, "%s%s", maybecomma, strtrim(principal));
+         maybecomma = ",";
+       }
+    }
+  EXEC SQL CLOSE k_cursor;
+
+  fprintf(out, "\n");
+}
This page took 0.055311 seconds and 5 git commands to generate.