1: # include <ingres.h> 2: # include <tree.h> 3: # include <aux.h> 4: # include <catalog.h> 5: # include <symbol.h> 6: # include <sccs.h> 7: 8: SCCSID(@(#)pr_prot.c 8.3 2/8/85) 9: 10: /* 11: ** PR_PROT.C -- Print out a protection query 12: ** 13: ** Trace Flags: 14: ** 51 15: */ 16: 17: 18: 19: 20: 21: 22: extern QTREE *gettree(); /* gets a tree from "tree" catalog [readtree.c] */ 23: 24: char *Days [] = 25: { 26: "sunday", 27: "monday", 28: "tuesday", 29: "wednesday", 30: "thursday", 31: "friday", 32: "saturday", 33: }; 34: 35: struct rngtab 36: { 37: char relid [MAXNAME]; 38: char rowner [2]; 39: char rused; 40: }; 41: 42: 43: 44: 45: /* 46: ** PR_PROT -- print out protection info on a relation 47: ** 48: ** Prints out a "define permit" statement for 49: ** each permission on a relation. 50: ** First calls pr_spec_permit() to print permissions 51: ** indicated in the relation.relstat bits. Lower level pr_?? 52: ** routines look for these bits, so in the calls to pr_permit 53: ** for tuples actually gotten from the "protect" catalog, 54: ** pr_prot sets the relstat bits, thereby suppressing their special 55: ** meaning (they are inverse bits: 0 means on). 56: ** 57: ** Parameters: 58: ** relid -- non-unique relation name used by user in DBU call 59: ** r -- ptr to relation tuple 60: ** 61: ** Returns: 62: ** 0 -- some permissions on rel 63: ** 1 -- no permissions on rel 64: ** 65: ** Side Effects: 66: ** reads trees from protection catalog 67: ** 68: ** Trace Flags: 69: ** 39, 0 70: */ 71: 72: pr_prot(relid, r) 73: char *relid; 74: register struct relation *r; 75: { 76: extern DESC Prodes; 77: TID hitid, lotid; 78: struct protect key, tuple; 79: register int i; 80: int flag; /* indicates whether a special case occurred */ 81: 82: # ifdef xZTR1 83: if (tTf(51, 0)) 84: printf("pr_prot: relation \"%s\" owner \"%s\"relstat 0%o\n", 85: r->relid, r->relowner, r->relstat); 86: # endif 87: 88: flag = 0; 89: if (r->relstat & S_PROTUPS || !(r->relstat & S_PROTALL) 90: || !(r->relstat & S_PROTRET)) 91: printf("Permissions on %s are:\n\n", relid); 92: /* print out special permissions, if any */ 93: flag += pr_spec_permit(r, S_PROTALL); 94: flag += pr_spec_permit(r, S_PROTRET); 95: 96: if (!(r->relstat & S_PROTUPS)) 97: if (flag) 98: return (0); 99: else 100: return (1); 101: opencatalog("protect", OR_READ); 102: 103: /* get protect catalog tuples for "r", "owner" */ 104: clearkeys(&Prodes); 105: setkey(&Prodes, &key, r->relid, PRORELID); 106: setkey(&Prodes, &key, r->relowner, PRORELOWN); 107: if (i = find(&Prodes, EXACTKEY, &lotid, &hitid, &key)) 108: syserr("pr_prot: find %d", i); 109: /* ready for pr_user call to getuser() */ 110: getuser(-1); 111: for ( ; ; ) 112: { 113: if (i = get(&Prodes, &lotid, &hitid, &tuple, TRUE)) 114: break; 115: /* print out protection info */ 116: if (kcompare(&Prodes, &tuple, &key) == 0) 117: /* permission from real protect tuple, concoct 118: * neutral relstat 119: */ 120: pr_permit(&tuple, r->relstat | S_PROTALL | S_PROTRET); 121: } 122: if (i != 1) 123: syserr("pr_prot: get %d", i); 124: 125: /* close user file opened by pr_user call to getuser */ 126: getuser(0); 127: } 128: /* 129: ** PR_SPEC_PERMIT -- Print out special permissions 130: ** Prints out permissios indicated by the relation.relstat field bits. 131: ** Concocts a protection tuple for the permission and assigns a 132: ** propermid-like number to it for printing. Passes to pr_permit() 133: ** the concocted tuple, together with a relstat where the appropriate 134: ** bit is 0, so that the special printing at the lower level pr_??? 135: ** routines takes place. 136: ** 137: ** Parameters: 138: ** r -- relation relation tuple for the permitted relation 139: ** relst_bit -- if this bit is 0 inthe relstat, prints the query 140: ** {S_PROTALL, S_PROTRET} 141: ** 142: ** Returns: 143: ** 1 -- if prints 144: ** 0 -- otherwise 145: */ 146: 147: 148: pr_spec_permit(r, relst_bit) 149: register struct relation *r; 150: int relst_bit; 151: { 152: register struct protect *p; 153: struct protect prot; 154: 155: if (r->relstat & relst_bit) 156: return (0); 157: p = &prot; 158: clrmem(p, sizeof *p); 159: p->protree = -1; 160: if (relst_bit == S_PROTALL) 161: p->propermid = 0; 162: else if (relst_bit == S_PROTRET) 163: p->propermid = 1; 164: else 165: syserr("pr_spec_permit(relst_bit == 0%o)", relst_bit); 166: 167: bmove(r->relid, p->prorelid, MAXNAME); 168: bmove(" ", p->prouser, 2); 169: pmove("", p->proterm, sizeof p->proterm, ' '); 170: pr_permit(p, (r->relstat | S_PROTRET | S_PROTALL) & ~relst_bit); 171: return (1); 172: } 173: /* 174: ** PR_PERMIT -- print out a DEFINE PERMIT query for a protection tuple 175: ** 176: ** Parameters: 177: ** p -- ptr to protection tuple 178: ** relstat -- relstat from relation 179: ** 180: ** Returns: 181: ** none 182: ** 183: ** Side Effects: 184: ** reads in a tree from the "tree" catalog 185: ** prints out a query 186: */ 187: 188: 189: pr_permit(p, relstat) 190: register struct protect *p; 191: int relstat; 192: { 193: register QTREE *t; 194: extern DESC Prodes; 195: DESC pdesc; 196: 197: /* 198: * if there is a qualification then 199: * clear range table, then read in protect tree, 200: * the print out range statements 201: * else create single entry range table. 202: */ 203: clrrange(); 204: if (p->protree >= 0) 205: { 206: t = gettree(p->prorelid, p->prorelown, mdPROT, p->protree, TRUE); 207: } 208: else 209: { 210: t = 0; 211: bmove(p->prorelid, pdesc.reldum.relid, MAXNAME); 212: bmove(p->prorelown, pdesc.reldum.relowner, 2); 213: declare(0, &pdesc); 214: p->proresvar = 0; 215: } 216: printf("Permission %d -\n\n", p->propermid); 217: pr_range(); 218: 219: # ifdef xZTR1 220: if (tTf(51, 1)) 221: { 222: printf("pr_permit: prot="); 223: printup(&Prodes, p); 224: printf(", Qt.qt_resvar=%d\n", Qt.qt_resvar); 225: } 226: # endif 227: 228: /* print out query */ 229: printf("define permit "); 230: pr_ops(p->proopset, relstat); 231: printf("on "); 232: pr_rv(Qt.qt_resvar = p->proresvar); 233: putchar(' '); 234: pr_doms(p->prodomset, relstat); 235: printf("\n\t"); 236: pr_user(p->prouser); 237: pr_term(p->proterm); 238: if ((relstat & S_PROTRET) && (relstat & S_PROTALL)) 239: { 240: /* not special case */ 241: pr_time(p->protodbgn, p->protodend); 242: pr_day(p->prodowbgn, p->prodowend); 243: } 244: if (t && t->right->sym.type != QLEND) 245: { 246: printf("\nwhere "); 247: pr_qual(t->right); 248: } 249: printf("\n\n\n"); 250: 251: /* clear up the old range table */ 252: clrrange(); 253: } 254: /* 255: ** PR_OPS -- Prints the the operation list defined by a protection opset 256: ** 257: ** Eliminates the appropriate bits from a copy of the opset while printing 258: ** out the appropriate operation list. 259: ** 260: ** Parameters: 261: ** opset -- protection.opset for the relation 262: ** relstat 263: ** 264: ** Returns: 265: ** none 266: ** 267: ** Side Effects: 268: ** printing of permitted op list 269: */ 270: 271: pr_ops(opset, relstat) 272: int opset; 273: int relstat; 274: { 275: register int op, j; 276: 277: # ifdef xZTR1 278: if (tTf(51, 2)) 279: printf("pr_ops(0%o)\n", opset); 280: # endif 281: 282: if (!(relstat & S_PROTALL) || opset == -1) 283: { 284: printf("all "); 285: return; 286: } 287: if (!(relstat & S_PROTRET)) 288: { 289: printf("retrieve "); 290: return; 291: } 292: 293: op = (opset & ~PRO_AGGR & ~PRO_TEST) & 077; 294: for ( ; ; ) 295: { 296: if (op & (j = PRO_RETR)) 297: printf("retrieve"); 298: else if (op & (j = PRO_REPL)) 299: printf("replace"); 300: else if (op & (j = PRO_DEL)) 301: printf("delete"); 302: else if (op & (j = PRO_APP)) 303: printf("append"); 304: op ^= j; 305: if (op) 306: printf(", "); 307: else 308: break; 309: } 310: putchar(' '); 311: } 312: /* 313: ** PR_DOMS -- Print domains in permit target list 314: ** 315: ** Parameters: 316: ** doms -- an 8 byte integer array; a bit map of the domains 317: ** if all 8 integers are -1, then "all" is printed fo 318: ** for the target list 319: ** relstat 320: ** 321: ** Returns: 322: ** none 323: ** 324: ** Side Effects: 325: ** prints out target list 326: */ 327: 328: pr_doms(doms, relstat) 329: short doms[BITMAP_SZ]; 330: int relstat; 331: { 332: register short *d; 333: register int flag, shift; 334: int word; 335: char *rel; 336: 337: word = shift = 0; 338: d = doms; 339: rel = Qt.qt_rangev[Qt.qt_resvar].rngvdesc->reldum.relid; 340: 341: # ifdef xZTR1 342: if (tTf(51, 3)) 343: { 344: printf("pr_doms: rel=\"%s\" ", rel); 345: for (word = 0; word < BITMAP_SZ; ) 346: printf("0%o ", d [word++]); 347: word = 0; 348: putchar('\n'); 349: } 350: # endif 351: if (!(relstat & S_PROTALL) || !(relstat & S_PROTRET)) 352: return; 353: flag = 1; 354: for (word = 0; word < BITMAP_SZ; word++) 355: if (*d++ != -1) 356: { 357: flag = 0; 358: break; 359: } 360: 361: if (!flag) 362: { 363: putchar('('); 364: for (d = doms, word = 0; word < BITMAP_SZ; word++, d++) 365: { 366: for (shift = 0; shift < NUMSHIFTS; shift++, *d >>= 1) 367: { 368: if (*d & 01) 369: { 370: if (flag++) 371: printf(", "); 372: pr_attname(rel, word * NUMSHIFTS + shift); 373: } 374: } 375: } 376: putchar(')'); 377: } 378: } 379: /* 380: ** PR_USER -- prints out permitted user's name 381: ** 382: ** Parameters: 383: ** user -- 2 char array, user's usercode as in 384: ** users file 385: ** 386: ** Returns: 387: ** none 388: ** 389: ** Side Effects: 390: ** prints users name or "all" if user was " " 391: */ 392: 393: pr_user(user) 394: char user[2]; 395: { 396: register i; 397: char buf[MAXLINE]; 398: register char *c, *u; 399: 400: # ifdef xZTR1 401: if (tTf(51, 4)) 402: printf("pr_user(\"%c%c\")\n", user[0], user[1]); 403: # endif 404: 405: c = buf; 406: u = user; 407: printf("to "); 408: if (bequal(u, " ", 2)) 409: printf("all "); 410: else 411: { 412: if (getuser(u, c)) 413: { 414: printf("%c%c ", u[0], u[1]); 415: return; 416: } 417: while (*c != ':' && *c != '\n') 418: putchar(*c++); 419: putchar(' '); 420: } 421: } 422: /* 423: ** PR_TIME -- Prints out clock time range access is allowed 424: ** 425: ** Parameters: 426: ** bgn, end -- begin end times in seconds (if all day, returns) 427: ** 428: ** Returns: 429: ** none 430: ** 431: ** Side Effects: 432: ** prints out time 433: */ 434: 435: pr_time(bgn, end) 436: int bgn, end; 437: { 438: char time [3]; 439: register char *t; 440: register int b, e; 441: 442: t = time; 443: b = bgn; 444: e = end; 445: # ifdef xZTR1 446: if (tTf(51, 5)) 447: printf("pr_time(bgn=%d, end=%d)\n", b, e); 448: # endif 449: if (b == 0 && e == 24 * 60) 450: return; 451: printf("from %d:", b / 60); 452: itoa(b % 60, t); 453: if (!t [1]) 454: putchar('0'); 455: printf("%s to %d:", t, e / 60); 456: itoa(e % 60, t); 457: if (!t [1]) 458: putchar('0'); 459: printf("%s ", t); 460: } 461: /* 462: ** PR_DAY -- Prints day range permitted 463: ** 464: ** Parameters: 465: ** bgn, end -- bgn end days [0..6] (if all week returns) 466: ** 467: ** Returns: 468: ** none 469: ** 470: ** Side Effects: 471: ** prints days or nothing 472: */ 473: 474: pr_day(bgn, end) 475: int bgn, end; 476: { 477: # ifdef xZTR1 478: if (tTf(51, 6)) 479: printf("pr_day(bgn=%d, end=%d)\n", bgn, end); 480: # endif 481: if (bgn == 0 && end >= 6) 482: return; 483: printf("on %s to %s ", Days [bgn], Days [end]); 484: } 485: /* 486: ** PR_TERM -- Print terminal from which access permitted 487: ** 488: ** Parameters: 489: ** term -- 1 char terminal id as in /etc/tty* (if ' ' the returns) 490: ** 491: ** Returns: 492: ** none 493: ** 494: ** Side Effects: 495: ** prints terminal or nothing 496: */ 497: 498: pr_term(term) 499: char term[8]; 500: { 501: # ifdef xZTR1 502: if (tTf(51, 7)) 503: printf("pr_term(term='%.8s')\n", term); 504: # endif 505: 506: if (term[0] != ' ') 507: printf("at %8.8s ", term); 508: }