]> andersk Git - moira.git/blob - db/newmoira.dc
7b16b1d749de73e8434965f34f1606ecc8ffd5ea
[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     char buffer[256];
124     EXEC SQL BEGIN DECLARE SECTION;
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             exit(1);
167         }
168     }
169
170     for (i = 0; value = values[i]; i++) {
171         EXEC SQL INSERT INTO numvalues (name, value)
172           VALUES (:value, 1);
173         if (ingres_errno) {
174             printf("Unable to install initial value of %s\n", value);
175             exit(1);
176         }
177     }
178
179     printf("What is the starting UID to assign: ");
180     fflush(stdout);
181     gets(buffer);
182     i = atoi(buffer);
183     EXEC SQL INSERT INTO numvalues (name, value)
184       VALUES ("uid", :i);
185     if (ingres_errno) {
186         printf("Unable to install value for uid\n");
187         exit(1);
188     }
189
190     printf("What is the starting GID to assign: ");
191     fflush(stdout);
192     gets(buffer);
193     i = atoi(buffer);
194     EXEC SQL INSERT INTO numvalues (name, value)
195       VALUES ("gid", :i);
196     if (ingres_errno) {
197         printf("Unable to install value for gid\n");
198         exit(1);
199     }
200
201     printf("What is the default NFS quota to assign: ");
202     fflush(stdout);
203     gets(buffer);
204     i = atoi(buffer);
205     EXEC SQL INSERT INTO numvalues (name, value)
206       VALUES ("def_quota", :i);
207     if (ingres_errno) {
208         printf("Unable to install value for def_quota\n");
209         exit(1);
210     }
211
212     /* place holder records */
213     EXEC SQL INSERT INTO users (login, potype, users_id)
214       VALUES ("[nobody]", "NONE", 0);
215     if (ingres_errno) {
216         printf("Unable to install 0 user\n");
217         exit(1);
218     }
219     EXEC SQL INSERT INTO machine (name, type)
220       VALUES ("[NONE]", "NONE");
221     if (ingres_errno) {
222         printf("Unable to install 0 machine\n");
223         exit(1);
224     }
225     EXEC SQL INSERT INTO cluster (name)
226       VALUES ("[unassigned]");
227     if (ingres_errno) {
228         printf("Unable to install 0 cluster\n");
229         exit(1);
230     }
231     EXEC SQL INSERT INTO list (name, acl_type)
232       VALUES ("[none]", "NONE");
233     if (ingres_errno) {
234         printf("Unable to install 0 list\n");
235         exit(1);
236     }
237     EXEC SQL INSERT INTO filesys (label, type)
238       VALUES ("[none]", "NONE");
239     if (ingres_errno) {
240         printf("Unable to install 0 filesys\n");
241         exit(1);
242     }
243     EXEC SQL INSERT INTO nfsphys (device)
244       VALUES ("/dev/null");
245     if (ingres_errno) {
246         printf("Unable to install 0 nfsphys\n");
247         exit(1);
248     }
249
250     /* magic for ALL_USERS */
251     EXEC SQL INSERT INTO users (login, users_id, potype)
252       VALUES ("default", 1, "NONE");
253     if (ingres_errno) {
254         printf("Unable to install default user\n");
255         exit(1);
256     }
257     EXEC SQL INSERT INTO list (name, list_id, acl_type)
258       VALUES ("default", 1, "NONE");
259     if (ingres_errno) {
260         printf("Unable to install default list\n");
261         exit(1);
262     }
263     EXEC SQL INSERT INTO imembers
264       (list_id, member_type, member_id, ref_count, direct)
265       VALUES (1, "USER", 1, 1, 1);
266     if (ingres_errno) {
267         printf("Unable to install default user on default list\n");
268         exit(1);
269     }
270
271     /* Privileged users */
272     EXEC SQL INSERT INTO users (login, users_id, potype)
273       VALUES ("root", 2, "NONE");
274     if (ingres_errno) {
275         printf("Unable to install root user\n");
276         exit(1);
277     }
278     EXEC SQL INSERT INTO list (name, list_id, acl_type, acl_id)
279       VALUES ("dbadmin", 2, "LIST", 2);
280     if (ingres_errno) {
281         printf("Unable to install default dbadmin list\n");
282         exit(1);
283     }
284
285     printf("What is the name of a privileged user: ");
286     fflush(stdout);
287     gets(buffer);
288     user = buffer;
289     EXEC SQL INSERT INTO users (login, users_id, potype)
290       VALUES (:user, 3, "NONE");
291     if (ingres_errno) {
292         printf("Unable to install user %s\n", buffer);
293         exit(1);
294     }
295     EXEC SQL INSERT INTO imembers
296       (list_id, member_type, member_id, ref_count, direct)
297       VALUES (2, "USER", 2, 1, 1);
298     if (ingres_errno) {
299         printf("Unable to put user root on list dbadmin\n");
300         exit(1);
301     }
302     EXEC SQL INSERT INTO imembers
303       (list_id, member_type, member_id, ref_count, direct)
304       VALUES (2, "USER", 3, 1, 1);
305     if (ingres_errno) {
306         printf("Unable to put user %s on list dbadmin\n", buffer);
307         exit(1);
308     }
309
310     /* And the capacls */
311     for (i = 0; i < QueryCount2; i++) {
312         query = Queries2[i].name;
313         value = Queries2[i].shortname;
314         list = 2;
315         if (!strcmp(value, "gali") || !strcmp(value, "glig") ||
316             !strcmp(value, "glim") || !strcmp(value, "gval"))
317           list = 1;
318         EXEC SQL INSERT INTO capacls (capability, tag, list_id)
319           VALUES (:query, :value, :list);
320         if (ingres_errno) {
321             printf("Unable to install query ACL for %s (%s)\n", query, value);
322             exit(1);
323         }
324     }
325     EXEC SQL INSERT INTO capacls (capability, tag, list_id)
326       VALUES ("trigger_dcm", "tdcm", 2);
327
328     /* and the aliases */
329     for (i = 0; aliases[i].name ; i++) {
330         value = aliases[i].name;
331         type = aliases[i].type;
332         trans = aliases[i].trans;
333         EXEC SQL INSERT INTO alias (name, type, trans)
334           VALUES (:value, :type, :trans);
335     }
336
337     printf("done.\n");
338     exit(0);
339 }
340
341
342 /*
343  * ingerr: (supposedly) called when Ingres indicates an error.
344  * I have not yet been able to get this to work to intercept a
345  * database open error.
346  */
347
348 int ingerr(num)
349     int *num;
350 {
351     ingres_errno = *num;
352     return *num;
353 }
354
355
356 /* dummy routines */
357 int access_user() {}
358 int access_login() {}
359 int access_list() {}
360 int access_visible_list() {}
361 int access_vis_list_by_name() {}
362 int access_member() {}
363 int access_qgli() {}
364 int access_service() {}
365 int access_filesys() {}
366 int setup_ausr() {}
367 int setup_dusr() {}
368 int setup_spop() {}
369 int setup_dpob() {}
370 int setup_dmac() {}
371 int setup_dclu() {}
372 int setup_alis() {}
373 int setup_dlis() {}
374 int setup_dsin() {}
375 int setup_dshi() {}
376 int setup_afil() {}
377 int setup_ufil() {}
378 int setup_dfil() {}
379 int setup_dnfp() {}
380 int setup_dqot() {}
381 int setup_sshi() {}
382 int setup_akum() {}
383 int followup_fix_modby() {}
384 int followup_ausr() {}
385 int followup_gpob() {}
386 int followup_glin() {}
387 int followup_aqot() {}
388 int followup_gzcl() {}
389 int followup_gsha() {}
390 int followup_gqot() {}
391 int set_modtime() {}
392 int set_modtime_by_id() {}
393 int set_finger_modtime() {}
394 int set_pobox_modtime() {}
395 int set_uppercase_modtime() {}
396 int set_mach_modtime_by_id() {}
397 int set_cluster_modtime_by_id() {}
398 int set_serverhost_modtime() {}
399 int set_nfsphys_modtime() {}
400 int set_filesys_modtime() {}
401 int set_zephyr_modtime() {}
402 int set_pobox() {}
403 int get_list_info() {}
404 int add_member_to_list() {}
405 int delete_member_from_list() {}
406 int get_ace_use() {}
407 int qualified_get_lists() {}
408 int get_members_of_list() {}
409 int qualified_get_server() {}
410 int qualified_get_serverhost() {}
411 int trigger_dcm() {}
412 int count_members_of_list() {}
413 int get_lists_of_member() {}
414 int register_user() {}
415 int followup_gpce() {}
This page took 0.085993 seconds and 3 git commands to generate.