]> andersk Git - moira.git/blame - db/newmoira.dc
[from genoa]
[moira.git] / db / newmoira.dc
CommitLineData
21e8ec7e 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"
13EXEC SQL INCLUDE sqlca;
14
15extern char *tables[];
16extern struct query Queries2[];
17extern int QueryCount2;
18
19char *values[] = { "users_id", "mach_id", "clu_id", "list_id",
20 "nfsphys_id", "filsys_id", "strings_id", "dcm_enable",
21 0 };
22
23struct 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
117int ingres_errno = 0;
118
119main(argc, argv)
120int argc;
121char **argv;
122{
21e8ec7e 123 EXEC SQL BEGIN DECLARE SECTION;
bbc27b1e 124 char buffer[256];
21e8ec7e 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)
529ecfa9 163 VALUES (:tbl, 'now', 0, 0, 0);
21e8ec7e 164 if (ingres_errno) {
165 printf("Unable to initialize tblstats for %s\n", tbl);
bbc27b1e 166 EXEC SQL INQUIRE_SQL (:buffer = ERRORTEXT);
167 printf("SQL error: %s\n",buffer);
21e8ec7e 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)
529ecfa9 186 VALUES ('uid', :i);
21e8ec7e 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)
529ecfa9 197 VALUES ('gid', :i);
21e8ec7e 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)
529ecfa9 208 VALUES ('def_quota', :i);
21e8ec7e 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)
529ecfa9 216 VALUES ('[nobody]', 'NONE', 0);
21e8ec7e 217 if (ingres_errno) {
218 printf("Unable to install 0 user\n");
219 exit(1);
220 }
221 EXEC SQL INSERT INTO machine (name, type)
529ecfa9 222 VALUES ('[NONE]', 'NONE');
21e8ec7e 223 if (ingres_errno) {
224 printf("Unable to install 0 machine\n");
225 exit(1);
226 }
227 EXEC SQL INSERT INTO cluster (name)
529ecfa9 228 VALUES ('[unassigned]');
21e8ec7e 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)
529ecfa9 234 VALUES ('[none]', 'NONE');
21e8ec7e 235 if (ingres_errno) {
236 printf("Unable to install 0 list\n");
237 exit(1);
238 }
239 EXEC SQL INSERT INTO filesys (label, type)
529ecfa9 240 VALUES ('[none]', 'NONE');
21e8ec7e 241 if (ingres_errno) {
242 printf("Unable to install 0 filesys\n");
243 exit(1);
244 }
245 EXEC SQL INSERT INTO nfsphys (device)
529ecfa9 246 VALUES ('/dev/null');
21e8ec7e 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)
529ecfa9 254 VALUES ('default', 1, 'NONE');
21e8ec7e 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)
529ecfa9 260 VALUES ('default', 1, 'NONE');
21e8ec7e 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)
529ecfa9 267 VALUES (1, 'USER', 1, 1, 1);
21e8ec7e 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)
529ecfa9 275 VALUES ('root', 2, 'NONE');
21e8ec7e 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)
529ecfa9 281 VALUES ('dbadmin', 2, 'LIST', 2);
21e8ec7e 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)
529ecfa9 292 VALUES (:user, 3, 'NONE');
21e8ec7e 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)
529ecfa9 299 VALUES (2, 'USER', 2, 1, 1);
21e8ec7e 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)
529ecfa9 306 VALUES (2, 'USER', 3, 1, 1);
21e8ec7e 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)
529ecfa9 328 VALUES ('trigger_dcm', 'tdcm', 2);
21e8ec7e 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
529ecfa9 350int ingerr()
21e8ec7e 351{
529ecfa9 352 ingres_errno = -sqlca.sqlcode;
353 return ingres_errno;
21e8ec7e 354}
355
356
357/* dummy routines */
358int access_user() {}
359int access_login() {}
360int access_list() {}
361int access_visible_list() {}
362int access_vis_list_by_name() {}
363int access_member() {}
364int access_qgli() {}
365int access_service() {}
366int access_filesys() {}
367int setup_ausr() {}
368int setup_dusr() {}
369int setup_spop() {}
370int setup_dpob() {}
371int setup_dmac() {}
372int setup_dclu() {}
373int setup_alis() {}
374int setup_dlis() {}
375int setup_dsin() {}
376int setup_dshi() {}
377int setup_afil() {}
378int setup_ufil() {}
379int setup_dfil() {}
380int setup_dnfp() {}
381int setup_dqot() {}
382int setup_sshi() {}
383int setup_akum() {}
384int followup_fix_modby() {}
385int followup_ausr() {}
386int followup_gpob() {}
387int followup_glin() {}
388int followup_aqot() {}
389int followup_gzcl() {}
390int followup_gsha() {}
391int followup_gqot() {}
392int set_modtime() {}
393int set_modtime_by_id() {}
394int set_finger_modtime() {}
395int set_pobox_modtime() {}
396int set_uppercase_modtime() {}
397int set_mach_modtime_by_id() {}
398int set_cluster_modtime_by_id() {}
399int set_serverhost_modtime() {}
400int set_nfsphys_modtime() {}
401int set_filesys_modtime() {}
402int set_zephyr_modtime() {}
403int set_pobox() {}
404int get_list_info() {}
405int add_member_to_list() {}
406int delete_member_from_list() {}
407int get_ace_use() {}
408int qualified_get_lists() {}
409int get_members_of_list() {}
410int qualified_get_server() {}
411int qualified_get_serverhost() {}
412int trigger_dcm() {}
413int count_members_of_list() {}
414int get_lists_of_member() {}
415int register_user() {}
416int followup_gpce() {}
This page took 0.106577 seconds and 5 git commands to generate.