|
|
1.1 root 1: # include <ingres.h>
2: # include <aux.h>
3: # include <lock.h>
4: # include <access.h>
5: # include <batch.h>
6: # include <pv.h>
7: # include <sccs.h>
8:
9: SCCSID(@(#)sysmod.c 7.1 2/5/81)
10:
11: extern int Status;
12: short tTdbu[100];
13:
14:
15: char *Fileset;
16: char Noupdt = FALSE;
17: char *Dummy;
18: char **Xparams = &Dummy;
19:
20: struct modtabl
21: {
22: char *rname;
23: char **parvec;
24: int goahead;
25: int normgo;
26: int optn;
27: };
28:
29: char *Relpar[] =
30: {
31: "relation", "hash", "name",
32: "relid", NULL
33: };
34:
35: char *Attpar[] =
36: {
37: "attribute", "hash", "name",
38: "attrelid", "attowner", "#attid",
39: NULL
40: };
41:
42: char *Indpar[] =
43: {
44: "indexes", "hash", "name",
45: "irelidp", "iownerp", "",
46: "minpages", "5", NULL
47: };
48:
49: char *Trepar[] =
50: {
51: "tree", "hash", "name",
52: "treerelid", "treeowner", "treetype",
53: NULL
54: };
55:
56: char *Propar[] =
57: {
58: "protect", "hash", "name",
59: "prorelid", "prorelown", NULL
60: };
61:
62: char *Intpar[] =
63: {
64: "integrities", "hash", "name",
65: "intrelid", "intrelowner", NULL
66: };
67:
68: struct modtabl Modtabl[] =
69: {
70: "relation", &Relpar[0], FALSE, TRUE, FALSE,
71: "attribute", &Attpar[0], FALSE, TRUE, FALSE,
72: "indexes", &Indpar[0], FALSE, TRUE, FALSE,
73: "tree", &Trepar[0], FALSE, TRUE, TRUE,
74: "protect", &Propar[0], FALSE, TRUE, TRUE,
75: "integrities", &Intpar[0], FALSE, TRUE, TRUE,
76: 0
77: };
78:
79:
80: /*
81: ** SYSMOD -- Modify system catalogs to a predetermined
82: ** storage structure with predetermined keys.
83: */
84:
85: main(argc, argv)
86: int argc;
87: char *argv[];
88: {
89: register int i;
90: register int j;
91: register char **av;
92: PARM newpvec[40];
93: char *p;
94: int retval;
95: char fileset[10], proctab[100];
96: extern char *Parmvect[];
97: extern char *Flagvect[];
98: extern char *Dbpath;
99: int superuser;
100:
101: argv[argc] = NULL;
102:
103: # ifdef xSTR1
104: tTrace(argv, 'T', tTdbu, 100);
105: # endif
106:
107: itoa(getpid(), fileset);
108: Fileset = fileset;
109: i = initucode(argc, argv, TRUE, NULL, M_EXCL);
110: switch (i)
111: {
112: case 0:
113: case 5:
114: break;
115:
116: case 1:
117: case 6:
118: printf("Database %s does not exist\n", Parmvect[0]);
119: exit(-1);
120:
121: case 2:
122: printf("You are not authorized for database %s\n", Parmvect[0]);
123: exit(-1);
124:
125: case 3:
126: printf("You are not a valid INGRES user\n");
127: exit(-1);
128:
129: case 4:
130: printf("No database name specified\n");
131: usage:
132: printf("Usage: sysmod [-s] [+-w] dbname [relation ...]\n");
133: exit(-1);
134:
135: default:
136: syserr("initucode %d", i);
137: }
138:
139: concat(Pathname, "/bin/ksort", proctab);
140: Dummy = proctab;
141:
142: superuser = FALSE;
143: for (av = Flagvect; (p = *av) != NULL; av++)
144: {
145: if (p[0] != '-')
146: {
147: badflag:
148: printf("Bad flag: %s\n", p);
149: goto usage;
150: }
151: switch (p[1])
152: {
153: case 's':
154: if ((Status & U_SUPER) == 0)
155: {
156: printf("Only INGRES can use the -s flag\n");
157: exit(-1);
158: }
159: superuser = TRUE;
160: break;
161:
162: case 'T':
163: break;
164:
165: default:
166: goto badflag;
167: }
168: }
169: if (chdir(Dbpath) < 0)
170: {
171: printf("data base %s does not exist\n", Parmvect[0]);
172: exit(1);
173: }
174: if (superuser)
175: bmove(Admin.adhdr.adowner, Usercode, 2);
176: if (!bequal(Usercode, Admin.adhdr.adowner, 2))
177: {
178: printf("you are not the dba for %s\n", Parmvect[0]);
179: exit(1);
180: }
181: /*
182: ** if there are any arguments, verify that they are valid
183: ** names of relations which can be modified by this program.
184: ** if there are no arguments, assume all system relations are to be
185: ** modified.
186: */
187: if (Parmvect[1] != NULL)
188: if ((Parmvect[2] == NULL) && sequal(Parmvect[1], "all"))
189: for (i = 0; Modtabl[i].rname; i++)
190: Modtabl[i].goahead = TRUE;
191: else
192: for (av = &Parmvect[1]; (p = *av) != NULL; av++)
193: {
194: for (j = 0; Modtabl[j].rname; j++)
195: {
196: if (sequal(p, Modtabl[j].rname))
197: {
198: if (Modtabl[j].goahead)
199: {
200: printf("%s duplicate relation name\n", p);
201: exit(1);
202: }
203: Modtabl[j].goahead = TRUE;
204: break;
205: }
206: }
207: if (!Modtabl[j].rname)
208: {
209: printf("%s is not a system relation\n", p);
210: exit(1);
211: }
212: }
213: else
214: for (i = 0; Modtabl[i].rname; i++)
215: Modtabl[i].goahead = Modtabl[i].normgo;
216: for (i = 0; Modtabl[i].rname; i++)
217: {
218: if (Modtabl[i].goahead == 0 || optn_rel(&Modtabl[i]))
219: continue;
220: printf("modifying %s\n", Modtabl[i].rname);
221: av = Modtabl[i].parvec;
222: j = 0;
223: while (*av != NULL)
224: {
225: newpvec[j].pv_type = PV_STR;
226: newpvec[j].pv_val.pv_str = *av;
227: newpvec[j].pv_len = length(*av) + 1;
228: j++;
229: av++;
230: }
231: newpvec[j].pv_type = PV_EOF;
232: smove(Fileset, Batchbuf.file_id);
233: # ifdef xSTR2
234: if (tTf(1, 0))
235: {
236: prvect(j, newpvec);
237: }
238: # endif
239: if (retval = modify(j, newpvec))
240: {
241: printf("Error %d on %s\n", retval, Modtabl[i].rname);
242: exit(1);
243: }
244: }
245: printf("sysmod done\n");
246: exit(0);
247: }
248:
249:
250: optn_rel(mx)
251: struct modtabl *mx;
252: {
253: register struct modtabl *m;
254: register int ret;
255:
256: struct descriptor des;
257:
258: m = mx;
259: ret = FALSE;
260:
261: if (m->optn)
262: {
263: if (openr(&des, -1, m->rname))
264: {
265: ret = TRUE;
266: }
267: }
268: return (ret);
269: }
270:
271: rubproc()
272: {
273: printf("sysmod interrupted\n");
274: exit(1);
275: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.