3 * This generates zephyr acl files
5 * Copyright (C) 1990-1999 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include <moira_site.h>
16 #include <sys/types.h>
22 EXEC SQL INCLUDE sqlca;
26 void do_class(TARFILE *tf, char *class);
27 void dump_zacl(FILE *out, char *type, int id);
30 char *whoami = "zephyr.gen";
31 char *db = "moira/moira";
35 int main(int argc, char **argv)
37 EXEC SQL BEGIN DECLARE SECTION;
38 char classbuf[ZEPHYR_CLASS_SIZE];
39 EXEC SQL END DECLARE SECTION;
42 struct save_queue *sq;
47 fprintf(stderr, "usage: %s outfile\n", argv[0]);
51 EXEC SQL WHENEVER SQLERROR DO sqlerr();
56 tf = tarfile_open(argv[1]);
57 out = tarfile_start(tf, "class-registry.acl", 0644, 0, 0,
61 EXEC SQL DECLARE csr_classes CURSOR FOR
62 SELECT class FROM zephyr;
63 EXEC SQL OPEN csr_classes;
66 EXEC SQL FETCH csr_classes INTO :classbuf;
70 class = strtrim(classbuf);
71 sq_save_data(sq, strdup(class));
72 fprintf(out, "%s:\n", class);
74 EXEC SQL CLOSE csr_classes;
77 while (sq_remove_data(sq, &class))
81 EXEC SQL COMMIT RELEASE;
86 void do_class(TARFILE *tf, char *class)
89 char filename[ZEPHYR_CLASS_SIZE + 9];
90 EXEC SQL BEGIN DECLARE SECTION;
91 char *zclass = class, zxtype[ZEPHYR_XMT_TYPE_SIZE];
92 char zstype[ZEPHYR_SUB_TYPE_SIZE], zwtype[ZEPHYR_IWS_TYPE_SIZE];
93 char zutype[ZEPHYR_IUI_TYPE_SIZE];
94 int zxid, zsid, zwid, zuid;
95 EXEC SQL END DECLARE SECTION;
97 EXEC SQL SELECT xmt_type, xmt_id, sub_type, sub_id,
98 iws_type, iws_id, iui_type, iui_id
99 INTO :zxtype, :zxid, :zstype, :zsid,
100 :zwtype, :zwid, :zutype, :zuid
102 WHERE class = :zclass;
106 sprintf(filename, "xmt-%s.acl", class);
107 out = tarfile_start(tf, filename, 0644, 0, 0, "root", "root", now);
108 dump_zacl(out, strtrim(zxtype), zxid);
111 sprintf(filename, "sub-%s.acl", class);
112 out = tarfile_start(tf, filename, 0644, 0, 0, "root", "root", now);
113 dump_zacl(out, strtrim(zstype), zsid);
116 sprintf(filename, "iws-%s.acl", class);
117 out = tarfile_start(tf, filename, 0644, 0, 0, "root", "root", now);
118 dump_zacl(out, strtrim(zwtype), zwid);
121 sprintf(filename, "iui-%s.acl", class);
122 out = tarfile_start(tf, filename, 0644, 0, 0, "root", "root", now);
123 dump_zacl(out, strtrim(zutype), zuid);
127 void dump_zacl(FILE *out, char *type, int id)
129 if (!strcmp(type, "ALL"))
130 fprintf(out, "*.*@*\n");
131 else if (strcmp(type, "NONE") != 0)
132 dump_krb_acl(out, type, id, 4);
137 db_error(sqlca.sqlcode);