]> andersk Git - moira.git/blob - db/newmoira.dc
finish writing program; use MList widget
[moira.git] / db / newmoira.dc
1 /* $Header$
2  *
3  * Creates a new sms database
4  *
5  * Copyright 1988 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 <stdio.h>
12 #include "../server/query.h"
13 EXEC SQL INCLUDE sqlca;
14
15 extern char *tables[];
16 extern struct query Queries2[];
17 extern int QueryCount2;
18
19 char *values[] = { "users_id", "mach_id", "clu_id", "list_id",
20                    "nfsphys_id", "filsys_id", "strings_id", "dcm_enable",
21                    0 };
22
23 struct alias { char *name;
24                char *type;
25                char *trans;
26            } aliases[] = {
27                    {"ace_type", "TYPE", "KERBEROS"},
28                    {"ace_type", "TYPE", "LIST"},
29                    {"ace_type", "TYPE", "NONE"},
30                    {"ace_type", "TYPE", "USER"},
31                    {"alias", "TYPE", "FILESYS"},
32                    {"alias", "TYPE", "PALLADIUM"},
33                    {"alias", "TYPE", "TYPE"},
34                    {"alias", "TYPE", "SERVICE"},
35                    {"alias", "TYPE", "TYPEDATA"},
36                    {"alias", "TYPE", "VALUE"},
37                    {"boolean", "TYPE", "FALSE"},
38                    {"boolean", "TYPE", "DONTCARE"},
39                    {"boolean", "TYPE", "TRUE"},
40                    {"class", "TYPE", "STAFF"},
41                    {"class", "TYPE", "1990"},
42                    {"class", "TYPE", "1991"},
43                    {"class", "TYPE", "1992"},
44                    {"class", "TYPE", "1993"},
45                    {"class", "TYPE", "FACULTY"},
46                    {"class", "TYPE", "G"},
47                    {"class", "TYPE", "GUEST"},
48                    {"class", "TYPE", "TEST"},
49                    {"class", "TYPE", "SYSTEM"},
50                    {"filesys", "TYPE", "ERR"},
51                    {"filesys", "TYPE", "FSGROUP"},
52                    {"filesys", "TYPE", "NFS"},
53                    {"filesys", "TYPE", "RVD"},
54                    {"filesys", "TYPE", "AFS"},
55                    {"fs_access_AFS", "TYPE", "w"},
56                    {"fs_access_AFS", "TYPE", "n"},
57                    {"fs_access_NFS", "TYPE", "r"},
58                    {"fs_access_NFS", "TYPE", "n"},
59                    {"fs_access_NFS", "TYPE", "w"},
60                    {"fs_access_RVD", "TYPE", "r"},
61                    {"fs_access_RVD", "TYPE", "x"},
62                    {"gaus", "TYPE", "LIST"},
63                    {"gaus", "TYPE", "USER"},
64                    {"gaus", "TYPE", "RLIST"},
65                    {"gaus", "TYPE", "RUSER"},
66                    {"lockertype", "TYPE", "COURSE"},
67                    {"lockertype", "TYPE", "HOMEDIR"},
68                    {"lockertype", "TYPE", "OTHER"},
69                    {"lockertype", "TYPE", "PROJECT"},
70                    {"lockertype", "TYPE", "SYSTEM"},
71                    {"mac_type", "TYPE", "MAC"},
72                    {"mac_type", "TYPE", "NEXT"},
73                    {"mac_type", "TYPE", "PMAX"},
74                    {"mac_type", "TYPE", "RT"},
75                    {"mac_type", "TYPE", "VAX"},
76                    {"member", "TYPE", "KERBEROS"},
77                    {"member", "TYPE", "LIST"},
78                    {"member", "TYPE", "STRING"},
79                    {"member", "TYPE", "USER"},
80                    {"pobox", "TYPE", "SMTP"},
81                    {"pobox", "TYPE", "NONE"},
82                    {"pobox", "TYPE", "POP"},
83                    {"quota_type", "TYPE", "USER"},
84                    {"quota_type", "TYPE", "GROUP"},
85                    {"quota_type", "TYPE", "ANY"},
86                    {"rmember", "TYPE", "LIST"},
87                    {"rmember", "TYPE", "STRING"},
88                    {"rmember", "TYPE", "USER"},
89                    {"rmember", "TYPE", "KERBEROS"},
90                    {"rmember", "TYPE", "RLIST"},
91                    {"rmember", "TYPE", "RSTRING"},
92                    {"rmember", "TYPE", "RUSER"},
93                    {"rmember", "TYPE", "RKERBEROS"},
94                    {"service", "TYPE", "REPLICAT"},
95                    {"service", "TYPE", "REPLICATED"},
96                    {"service", "TYPE", "UNIQUE"},
97                    {"slabel", "TYPE", "LPR"},
98                    {"slabel", "TYPE", "KERBEROS"},
99                    {"slabel", "TYPE", "USRLIB"},
100                    {"slabel", "TYPE", "SYSLIB"},
101                    {"slabel", "TYPE", "ZEPHYR"},
102                    {"ANY", "TYPEDATA", "none"},
103                    {"KERBEROS", "TYPEDATA", "string"},
104                    {"GROUP", "TYPEDATA", "list"},
105                    {"LIST", "TYPEDATA", "list"},
106                    {"NONE", "TYPEDATA", "none"},
107                    {"POP", "TYPEDATA", "machine"},
108                    {"RLIST", "TYPEDATA", "list"},
109                    {"RSTRING", "TYPEDATA", "string"},
110                    {"RUSER", "TYPEDATA", "user"},
111                    {"SMTP", "TYPEDATA", "string"},
112                    {"STRING", "TYPEDATA", "string"},
113                    {"USER", "TYPEDATA", "user"},        
114                    0 };
115
116
117 int ingres_errno = 0;
118
119 main(argc, argv)
120 int argc;
121 char **argv;
122 {
123     EXEC SQL BEGIN DECLARE SECTION;
124     char buffer[256];
125     char *db, *tbl, *value, *user, *query, *trans, *type;
126     int i, list;
127     EXEC SQL END DECLARE SECTION;
128
129     if (argc == 2)
130       db = argv[1];
131     else
132       db = "sms";
133 #ifsql INGRES
134     EXEC SQL CONNECT db;
135 #endsql
136 #ifsql INFORMIX
137     EXEC SQL DATABASE db;
138 #endsql
139     EXEC SQL WHENEVER SQLERROR CALL ingerr;
140
141     strcpy(buffer, "root");
142     user = buffer;
143     while (buffer[0]) {
144         for (i = 0; tbl = tables[i]; i++) {
145 #ifsql INGRES
146 /*          EXEC SQL define permit all on table to user; */
147 #endsql
148             if (ingres_errno) {
149                 printf("Unable to give %s permission to access table %s\n",
150                        user, tbl);
151                 exit(1);
152             }
153         }
154         printf("Enter the name of another user to be given direct access to\n");
155         printf("the database, or [RETURN] if none: ");
156         fflush(stdout);
157         gets(user);
158     }
159
160     for (i = 0; tbl = tables[i]; i++) {
161         EXEC SQL INSERT INTO tblstats
162           (table_name, modtime, appends, updates, deletes)
163           VALUES (:tbl, 'now', 0, 0, 0);
164         if (ingres_errno) {
165             printf("Unable to initialize tblstats for %s\n", tbl);
166             EXEC SQL INQUIRE_SQL (:buffer = ERRORTEXT);
167             printf("SQL error: %s\n",buffer);
168             exit(1);
169         }
170     }
171
172     for (i = 0; value = values[i]; i++) {
173         EXEC SQL INSERT INTO numvalues (name, value)
174           VALUES (:value, 1);
175         if (ingres_errno) {
176             printf("Unable to install initial value of %s\n", value);
177             exit(1);
178         }
179     }
180
181     printf("What is the starting UID to assign: ");
182     fflush(stdout);
183     gets(buffer);
184     i = atoi(buffer);
185     EXEC SQL INSERT INTO numvalues (name, value)
186       VALUES ('uid', :i);
187     if (ingres_errno) {
188         printf("Unable to install value for uid\n");
189         exit(1);
190     }
191
192     printf("What is the starting GID to assign: ");
193     fflush(stdout);
194     gets(buffer);
195     i = atoi(buffer);
196     EXEC SQL INSERT INTO numvalues (name, value)
197       VALUES ('gid', :i);
198     if (ingres_errno) {
199         printf("Unable to install value for gid\n");
200         exit(1);
201     }
202
203     printf("What is the default NFS quota to assign: ");
204     fflush(stdout);
205     gets(buffer);
206     i = atoi(buffer);
207     EXEC SQL INSERT INTO numvalues (name, value)
208       VALUES ('def_quota', :i);
209     if (ingres_errno) {
210         printf("Unable to install value for def_quota\n");
211         exit(1);
212     }
213
214     /* place holder records */
215     EXEC SQL INSERT INTO users (login, potype, users_id)
216       VALUES ('[nobody]', 'NONE', 0);
217     if (ingres_errno) {
218         printf("Unable to install 0 user\n");
219         exit(1);
220     }
221     EXEC SQL INSERT INTO machine (name, type)
222       VALUES ('[NONE]', 'NONE');
223     if (ingres_errno) {
224         printf("Unable to install 0 machine\n");
225         exit(1);
226     }
227     EXEC SQL INSERT INTO cluster (name)
228       VALUES ('[unassigned]');
229     if (ingres_errno) {
230         printf("Unable to install 0 cluster\n");
231         exit(1);
232     }
233     EXEC SQL INSERT INTO list (name, acl_type)
234       VALUES ('[none]', 'NONE');
235     if (ingres_errno) {
236         printf("Unable to install 0 list\n");
237         exit(1);
238     }
239     EXEC SQL INSERT INTO filesys (label, type)
240       VALUES ('[none]', 'NONE');
241     if (ingres_errno) {
242         printf("Unable to install 0 filesys\n");
243         exit(1);
244     }
245     EXEC SQL INSERT INTO nfsphys (device)
246       VALUES ('/dev/null');
247     if (ingres_errno) {
248         printf("Unable to install 0 nfsphys\n");
249         exit(1);
250     }
251
252     /* magic for ALL_USERS */
253     EXEC SQL INSERT INTO users (login, users_id, potype)
254       VALUES ('default', 1, 'NONE');
255     if (ingres_errno) {
256         printf("Unable to install default user\n");
257         exit(1);
258     }
259     EXEC SQL INSERT INTO list (name, list_id, acl_type)
260       VALUES ('default', 1, 'NONE');
261     if (ingres_errno) {
262         printf("Unable to install default list\n");
263         exit(1);
264     }
265     EXEC SQL INSERT INTO imembers
266       (list_id, member_type, member_id, ref_count, direct)
267       VALUES (1, 'USER', 1, 1, 1);
268     if (ingres_errno) {
269         printf("Unable to install default user on default list\n");
270         exit(1);
271     }
272
273     /* Privileged users */
274     EXEC SQL INSERT INTO users (login, users_id, potype)
275       VALUES ('root', 2, 'NONE');
276     if (ingres_errno) {
277         printf("Unable to install root user\n");
278         exit(1);
279     }
280     EXEC SQL INSERT INTO list (name, list_id, acl_type, acl_id)
281       VALUES ('dbadmin', 2, 'LIST', 2);
282     if (ingres_errno) {
283         printf("Unable to install default dbadmin list\n");
284         exit(1);
285     }
286
287     printf("What is the name of a privileged user: ");
288     fflush(stdout);
289     gets(buffer);
290     user = buffer;
291     EXEC SQL INSERT INTO users (login, users_id, potype)
292       VALUES (:user, 3, 'NONE');
293     if (ingres_errno) {
294         printf("Unable to install user %s\n", buffer);
295         exit(1);
296     }
297     EXEC SQL INSERT INTO imembers
298       (list_id, member_type, member_id, ref_count, direct)
299       VALUES (2, 'USER', 2, 1, 1);
300     if (ingres_errno) {
301         printf("Unable to put user root on list dbadmin\n");
302         exit(1);
303     }
304     EXEC SQL INSERT INTO imembers
305       (list_id, member_type, member_id, ref_count, direct)
306       VALUES (2, 'USER', 3, 1, 1);
307     if (ingres_errno) {
308         printf("Unable to put user %s on list dbadmin\n", buffer);
309         exit(1);
310     }
311
312     /* And the capacls */
313     for (i = 0; i < QueryCount2; i++) {
314         query = Queries2[i].name;
315         value = Queries2[i].shortname;
316         list = 2;
317         if (!strcmp(value, "gali") || !strcmp(value, "glig") ||
318             !strcmp(value, "glim") || !strcmp(value, "gval"))
319           list = 1;
320         EXEC SQL INSERT INTO capacls (capability, tag, list_id)
321           VALUES (:query, :value, :list);
322         if (ingres_errno) {
323             printf("Unable to install query ACL for %s (%s)\n", query, value);
324             exit(1);
325         }
326     }
327     EXEC SQL INSERT INTO capacls (capability, tag, list_id)
328       VALUES ('trigger_dcm', 'tdcm', 2);
329
330     /* and the aliases */
331     for (i = 0; aliases[i].name ; i++) {
332         value = aliases[i].name;
333         type = aliases[i].type;
334         trans = aliases[i].trans;
335         EXEC SQL INSERT INTO alias (name, type, trans)
336           VALUES (:value, :type, :trans);
337     }
338
339     printf("done.\n");
340     exit(0);
341 }
342
343
344 /*
345  * ingerr: (supposedly) called when Ingres indicates an error.
346  * I have not yet been able to get this to work to intercept a
347  * database open error.
348  */
349
350 int ingerr()
351 {
352     ingres_errno = -sqlca.sqlcode;
353     return ingres_errno;
354 }
355
356
357 /* dummy routines */
358 int access_user() {}
359 int access_login() {}
360 int access_list() {}
361 int access_visible_list() {}
362 int access_vis_list_by_name() {}
363 int access_member() {}
364 int access_qgli() {}
365 int access_service() {}
366 int access_filesys() {}
367 int setup_ausr() {}
368 int setup_dusr() {}
369 int setup_spop() {}
370 int setup_dpob() {}
371 int setup_dmac() {}
372 int setup_dclu() {}
373 int setup_alis() {}
374 int setup_dlis() {}
375 int setup_dsin() {}
376 int setup_dshi() {}
377 int setup_afil() {}
378 int setup_ufil() {}
379 int setup_dfil() {}
380 int setup_dnfp() {}
381 int setup_dqot() {}
382 int setup_sshi() {}
383 int setup_akum() {}
384 int followup_fix_modby() {}
385 int followup_ausr() {}
386 int followup_gpob() {}
387 int followup_glin() {}
388 int followup_aqot() {}
389 int followup_gzcl() {}
390 int followup_gsha() {}
391 int followup_gqot() {}
392 int set_modtime() {}
393 int set_modtime_by_id() {}
394 int set_finger_modtime() {}
395 int set_pobox_modtime() {}
396 int set_uppercase_modtime() {}
397 int set_mach_modtime_by_id() {}
398 int set_cluster_modtime_by_id() {}
399 int set_serverhost_modtime() {}
400 int set_nfsphys_modtime() {}
401 int set_filesys_modtime() {}
402 int set_zephyr_modtime() {}
403 int set_pobox() {}
404 int get_list_info() {}
405 int add_member_to_list() {}
406 int delete_member_from_list() {}
407 int get_ace_use() {}
408 int qualified_get_lists() {}
409 int get_members_of_list() {}
410 int qualified_get_server() {}
411 int qualified_get_serverhost() {}
412 int trigger_dcm() {}
413 int count_members_of_list() {}
414 int get_lists_of_member() {}
415 int register_user() {}
416 int followup_gpce() {}
This page took 0.062033 seconds and 5 git commands to generate.