3 * (c) Copyright 2008 by the Massachusetts Institute of Technology.
6 #include <mit-copyright.h>
8 #include <moira_site.h>
19 EXEC SQL INCLUDE sqlca;
21 char *whoami = "warehouse-lists.gen";
22 char *db = "moira/moira";
26 void output_list(int id, void *list, void *out);
28 int main(int argc, char **argv)
30 char filename[MAXPATHLEN], *targetfile, *l;
33 EXEC SQL BEGIN DECLARE SECTION;
35 char lname[LIST_NAME_SIZE];
36 EXEC SQL END DECLARE SECTION;
43 sprintf(filename, "%s~", targetfile);
44 if (!(out = fopen(filename, "w")))
46 fprintf(stderr, "unable to open %s for output\n", filename);
52 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
56 lists = create_hash(15000);
58 EXEC SQL DECLARE l_cursor CURSOR FOR
59 SELECT l.list_id, l.name FROM list l
60 WHERE l.active = 1 and l.hidden = 0;
61 EXEC SQL OPEN l_cursor;
64 EXEC SQL FETCH l_cursor INTO :lid, :lname;
67 l = strdup(strtrim(lname));
68 if (hash_store(lists, lid, l) < 0)
70 fprintf(stderr, "Out of memory!\n");
75 EXEC SQL CLOSE l_cursor;
76 fprintf(stderr, "Loaded %d lists\n", cnt);
78 hash_step(lists, output_list, out);
82 perror("close failed");
91 void output_list(int id, void *list, void *out)
93 EXEC SQL BEGIN DECLARE SECTION;
96 char acl_type[LIST_ACL_TYPE_SIZE], modtime[LIST_MODTIME_SIZE];
97 char acl_name[STRINGS_STRING_SIZE], login[USERS_LOGIN_SIZE];
98 char principal[STRINGS_STRING_SIZE];
100 EXEC SQL END DECLARE SECTION;
101 char *maybecomma = "";
103 EXEC SQL SELECT acl_type, acl_id, modtime INTO :acl_type, :acl_id, :modtime
104 FROM list WHERE list_id = :lid;
109 strcpy(acl_name, "NONE");
110 if (strcmp(acl_type, "LIST") == 0)
111 EXEC SQL SELECT name into :acl_name FROM list WHERE list_id = :acl_id;
112 else if (strcmp(acl_type, "USER") == 0)
113 EXEC SQL SELECT login into :acl_name FROM users WHERE users_id = :acl_id;
114 else if (strcmp(acl_type, "KERBEROS") == 0)
115 EXEC SQL SELECT string into :acl_name FROM strings WHERE string_id = :acl_id;
118 fprintf(out, "%s|%s|%s|", list, acl_type, acl_name);
120 EXEC SQL DECLARE u_cursor CURSOR FOR
121 SELECT UNIQUE u.login FROM users u, imembers i, list l
122 WHERE l.list_id = :lid AND l.list_id = i.list_id AND
123 i.member_type = 'USER' AND i.member_id = u.users_id;
124 EXEC SQL OPEN u_cursor;
127 EXEC SQL FETCH u_cursor INTO :login;
130 fprintf(out, "%s%s", maybecomma, strtrim(login));
133 EXEC SQL CLOSE u_cursor;
135 EXEC SQL DECLARE k_cursor CURSOR FOR
136 SELECT UNIQUE s.string FROM strings s, imembers i, list l
137 WHERE l.list_id = :lid AND l.list_id = i.list_id AND
138 (i.member_type = 'KERBEROS' OR i.member_type = 'STRING')
139 and i.member_id = s.string_id;
140 EXEC SQL OPEN k_cursor;
143 EXEC SQL FETCH k_cursor INTO :principal;
146 fprintf(out, "%s%s", maybecomma, strtrim(principal));
149 EXEC SQL CLOSE k_cursor;
151 fprintf(out, "|%s\n", modtime);