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