3 * (c) Copyright 2007 by the Massachusetts Institute of Technology.
6 #include <mit-copyright.h>
8 #include <moira_site.h>
19 EXEC SQL INCLUDE sqlca;
21 #define DEFAULT_REALM "@ATHENA.MIT.EDU"
23 char *whoami = "events.gen";
24 char *db = "moira/moira";
28 void output_list(int id, void *list, void *out);
30 int main(int argc, char **argv)
32 char filename[MAXPATHLEN], *targetfile, *l;
35 EXEC SQL BEGIN DECLARE SECTION;
37 char lname[LIST_NAME_SIZE];
38 EXEC SQL END DECLARE SECTION;
45 sprintf(filename, "%s~", targetfile);
46 if (!(out = fopen(filename, "w")))
48 fprintf(stderr, "unable to open %s for output\n", filename);
54 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
58 lists = create_hash(15000);
60 EXEC SQL DECLARE l_cursor CURSOR FOR
61 SELECT l.list_id, l.name FROM list l
62 WHERE l.active = 1 and l.maillist = 1;
63 EXEC SQL OPEN l_cursor;
66 EXEC SQL FETCH l_cursor INTO :lid, :lname;
69 l = strdup(strtrim(lname));
70 if (hash_store(lists, lid, l) < 0)
72 fprintf(stderr, "Out of memory!\n");
77 EXEC SQL CLOSE l_cursor;
78 fprintf(stderr, "Loaded %d lists\n", cnt);
80 hash_step(lists, output_list, out);
84 perror("close failed");
93 void output_list(int id, void *list, void *out)
95 EXEC SQL BEGIN DECLARE SECTION;
98 char login[USERS_LOGIN_SIZE];
99 char principal[STRINGS_STRING_SIZE];
100 EXEC SQL END DECLARE SECTION;
101 char *maybecomma = "";
103 fprintf(out, "%s:", list);
105 EXEC SQL DECLARE u_cursor CURSOR FOR
106 SELECT UNIQUE u.login FROM users u, imembers i, list l
107 WHERE l.list_id = :lid AND l.list_id = i.list_id AND
108 i.member_type = 'USER' AND i.member_id = u.users_id;
109 EXEC SQL OPEN u_cursor;
112 EXEC SQL FETCH u_cursor INTO :login;
115 fprintf(out, "%s%s", maybecomma, strtrim(login));
118 EXEC SQL CLOSE u_cursor;
120 EXEC SQL DECLARE k_cursor CURSOR FOR
121 SELECT UNIQUE s.string FROM strings s, imembers i, list l
122 WHERE l.list_id = :lid AND l.list_id = i.list_id AND
123 i.member_type = 'KERBEROS' AND i.member_id = s.string_id;
124 EXEC SQL OPEN k_cursor;
127 EXEC SQL FETCH k_cursor INTO :principal;
130 if (strstr(principal, DEFAULT_REALM))
132 *strstr(principal, DEFAULT_REALM) = '\0';
133 fprintf(out, "%s%s", maybecomma, strtrim(principal));
137 EXEC SQL CLOSE k_cursor;