]> andersk Git - moira.git/blob - gen/zephyr.pc
Command line printer manipulation client, and build goo.
[moira.git] / gen / zephyr.pc
1 /* $Id$
2  *
3  * This generates zephyr acl files
4  *
5  * Copyright (C) 1990-1999 by the Massachusetts Institute of Technology.
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include <moira_site.h>
13 #include "util.h"
14
15 #include <sys/stat.h>
16 #include <sys/types.h>
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 EXEC SQL INCLUDE sqlca;
23
24 RCSID("$Header$");
25
26 void do_class(TARFILE *tf, char *class);
27 void dump_zacl(FILE *out, char *type, int id);
28 void sqlerr(void);
29
30 char *whoami = "zephyr.gen";
31 char *db = "moira/moira";
32
33 time_t now;
34
35 int main(int argc, char **argv)
36 {
37   EXEC SQL BEGIN DECLARE SECTION;
38   char classbuf[ZEPHYR_CLASS_SIZE];
39   EXEC SQL END DECLARE SECTION;
40   TARFILE *tf;
41   FILE *out;
42   struct save_queue *sq;
43   char *class;
44  
45   if (argc != 2)
46     {
47       fprintf(stderr, "usage: %s outfile\n", argv[0]);
48       exit(MR_ARGS);
49     }
50
51   EXEC SQL WHENEVER SQLERROR DO sqlerr();
52   EXEC SQL CONNECT :db;
53   init_acls();
54   time(&now);
55
56   tf = tarfile_open(argv[1]);
57   out = tarfile_start(tf, "class-registry.acl", 0644, 0, 0,
58                       "root", "root", now);
59   sq = sq_create();
60
61   EXEC SQL DECLARE csr_classes CURSOR FOR
62     SELECT class FROM zephyr;
63   EXEC SQL OPEN csr_classes;
64   while (1)
65     {
66       EXEC SQL FETCH csr_classes INTO :classbuf;
67       if (sqlca.sqlcode)
68         break;
69
70       class = strtrim(classbuf);
71       sq_save_data(sq, strdup(class));
72       fprintf(out, "%s:\n", class);
73     }
74   EXEC SQL CLOSE csr_classes;
75   tarfile_end(tf);
76
77   while (sq_remove_data(sq, &class))
78     do_class(tf, class);
79
80   sq_destroy(sq);
81   EXEC SQL COMMIT RELEASE;
82   tarfile_close(tf);
83   exit(MR_SUCCESS);
84 }
85
86 void do_class(TARFILE *tf, char *class)
87 {
88   FILE *out;
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;
96
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
101     FROM zephyr
102     WHERE class = :zclass;
103   if (sqlca.sqlcode)
104     return;
105
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);
109   tarfile_end(tf);
110
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);
114   tarfile_end(tf);
115
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);
119   tarfile_end(tf);
120
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);
124   tarfile_end(tf);
125 }
126
127 void dump_zacl(FILE *out, char *type, int id)
128 {
129   if (!strcmp(type, "ALL"))
130     fprintf(out, "*.*@*\n");
131   else if (strcmp(type, "NONE") != 0)
132     dump_krb_acl(out, type, id, 4);
133 }
134
135 void sqlerr(void)
136 {
137   db_error(sqlca.sqlcode);
138   exit(MR_DBMS_ERR);
139 }
This page took 0.078969 seconds and 5 git commands to generate.