1: #
   2: 
   3: /*
   4: **  PR_PROT.C -- Print out a protection query
   5: **
   6: **	Defines:
   7: **		pr_prot() -- given a relation owner pair, prints protection
   8: **			queries issued on the relation
   9: **
  10: **	Required By:
  11: **		disp() -- [display.c]
  12: **
  13: **	Conditional Compilation:
  14: **		xZTR1 -- for trace flags
  15: **
  16: **	Trace Flags:
  17: **		11
  18: **
  19: **	History:
  20: **		11/15/78 -- (marc) written
  21: */
  22: 
  23: 
  24: 
  25: 
  26: # include   "../ingres.h"
  27: # include   "../tree.h"
  28: # include   "../aux.h"
  29: # include   "../unix.h"
  30: # include   "../catalog.h"
  31: # include   "../symbol.h"
  32: 
  33: 
  34: # define    QTREE       struct querytree
  35: 
  36: 
  37: QTREE   *gettree(); /* gets a tree from "tree" catalog [readtree.c] */
  38: 
  39: char    *Days [] =
  40: {
  41:     "sunday",
  42:     "monday",
  43:     "tuesday",
  44:     "wednesday",
  45:     "thursday",
  46:     "friday",
  47:     "saturday",
  48: };
  49: 
  50: # define    QTREE       struct querytree
  51: 
  52: struct rngtab
  53: {
  54:     char    relid [MAXNAME];
  55:     char    rowner [2];
  56:     char    rused;
  57: };
  58: 
  59: struct rngtab   Rangev[MAXVAR + 1];
  60: 
  61: 
  62: 
  63: /*
  64: **  PR_PROT -- print out protection info on a relation
  65: **
  66: **	Prints out a "define permit" statement for
  67: **	each permission on a relation.
  68: **	First calls pr_spec_permit() to print permissions
  69: **	indicated in the relation.relstat bits. Lower level pr_??
  70: **	routines look for these bits, so in the calls to pr_permit
  71: **	for tuples actually gotten from the "protect" catalog,
  72: **	pr_prot sets the relstat bits, thereby suppressing their special
  73: **	meaning (they are inverse bits: 0 means on).
  74: **
  75: **	Parameters:
  76: **		relid -- non-unique relation name used by user in DBU call
  77: **		rel -- relation tuple
  78: **
  79: **	Returns:
  80: **		0 -- some permissions on rel
  81: **		1 -- no permissions on rel
  82: **
  83: **	Side Effects:
  84: **		reads trees from protection catalog
  85: **
  86: **	Requires:
  87: **		pr_permit() -- to generate query from protection tuple
  88: **		pr_spec_permit() -- to print out relstat generated permissions
  89: **
  90: **	Called By:
  91: **		disp() [display.c]
  92: **
  93: **	Trace Flags:
  94: **		11, 0
  95: **
  96: **	Syserrs:
  97: **		on bad returns from find(), get(), and openr()
  98: **
  99: **	History:
 100: **		11/15/78 -- (marc) written
 101: **		12/19/78 -- (marc) modified to take into account S_PROT[12]
 102: **		1/9/79 -- (marc)    "		"	    "	S_PROT[ALL,RET]
 103: */
 104: 
 105: pr_prot(relid, rel)
 106: char            *relid;
 107: struct relation     *rel;
 108: {
 109:     extern struct descriptor    Prodes;
 110:     struct tup_id           hitid, lotid;
 111:     struct protect          key, tuple;
 112:     register            i;
 113:     int             flag;   /* indicates wether a special
 114: 						 * case occurred
 115: 						 */
 116:     register struct relation    *r;
 117: 
 118: #	ifdef xZTR1
 119:     if (tTf(11, 0))
 120:         printf("pr_prot: relation \"%s\" owner \"%s\"relstat 0%o\n",
 121:         rel->relid, rel->relowner, rel->relstat);
 122: #	endif
 123: 
 124:     r = rel;
 125:     flag = 0;
 126:     if (r->relstat & S_PROTUPS || !(r->relstat & S_PROTALL)
 127:        || !(r->relstat & S_PROTRET))
 128:         printf("Permissions on %s are:\n\n", relid);
 129:     /* print out special permissions, if any */
 130:     flag += pr_spec_permit(r, S_PROTALL);
 131:     flag += pr_spec_permit(r, S_PROTRET);
 132: 
 133:     if (!(r->relstat & S_PROTUPS))
 134:         if (flag)
 135:             return (0);
 136:         else
 137:             return (1);
 138:     opencatalog("protect", 0);
 139: 
 140:     /* get protect catalog tuples for "r", "owner" */
 141:     clearkeys(&Prodes);
 142:     setkey(&Prodes, &key, r->relid, PRORELID);
 143:     setkey(&Prodes, &key, r->relowner, PRORELOWN);
 144:     if (i = find(&Prodes, EXACTKEY, &lotid, &hitid, &key))
 145:         syserr("pr_prot: find %d", i);
 146:     /* ready for pr_user call to getuser() */
 147:     getuser(-1);
 148:     for ( ; ; )
 149:     {
 150:         if (i = get(&Prodes, &lotid, &hitid, &tuple, TRUE))
 151:             break;
 152:         /* print out protection info */
 153:         if (kcompare(&Prodes, &tuple, &key) == 0)
 154:             /* permission from real protect tuple, concoct
 155: 			 * neutral relstat
 156: 			 */
 157:             pr_permit(&tuple, r->relstat | S_PROTALL | S_PROTRET);
 158:     }
 159:     if (i != 1)
 160:         syserr("pr_prot: get %d", i);
 161: 
 162:     /* close user file opened by pr_user call to getuser */
 163:     getuser(0);
 164: }
 165: 
 166: /*
 167: **  PR_SPEC_PERMIT -- Print out special permissions
 168: **	Prints out permissios indicated by the relation.relstat field bits.
 169: **	Concocts a protection tuple for the permission and assigns a
 170: **	propermid-like number to it for printing. Passes to pr_permit()
 171: **	the concocted tuple, together with a relstat where the appropriate
 172: **	bit is 0, so that the special printing at the lower level pr_???
 173: **	routines takes place.
 174: **
 175: **	Parameters:
 176: **		rel -- relation relation tuple for the permitted relation
 177: **		relst_bit -- if this bit is 0 inthe relstat, prints the query
 178: **				{S_PROTALL, S_PROTRET}
 179: **
 180: **	Returns:
 181: **		1 -- if prints
 182: **		0 -- otherwise
 183: **
 184: **	Requires:
 185: **		pr_permit()
 186: **
 187: **	Called By:
 188: **		pr_prot()
 189: **
 190: **	Syserrs:
 191: **		relst_bit ! in {S_PROTALL, S_PROTRET}
 192: **
 193: **	History:
 194: **		1/9/79 -- (marc) written to handle S_PROTALL and S_PROTRET
 195: */
 196: 
 197: 
 198: pr_spec_permit(rel, relst_bit)
 199: struct relation     *rel;
 200: int         relst_bit;
 201: {
 202:     register struct relation    *r;
 203:     register struct protect     *p;
 204:     struct protect          prot;
 205: 
 206:     r = rel;
 207:     if (r->relstat & relst_bit)
 208:         return (0);
 209:     p = &prot;
 210:     p->protree = -1;
 211:     if (relst_bit == S_PROTALL)
 212:         p->propermid = 0;
 213:     else if (relst_bit == S_PROTRET)
 214:         p->propermid = 1;
 215:     else
 216:         syserr("pr_spec_permit(relst_bit == 0%o)", relst_bit);
 217: 
 218:     bmove(r->relid, p->prorelid, MAXNAME);
 219:     bmove("  ", p->prouser, 2);
 220:     bmove(" ", &p->proterm, 1);
 221:     pr_permit(p, (r->relstat | S_PROTRET | S_PROTALL) & ~relst_bit);
 222:     return (1);
 223: }
 224: 
 225: 
 226: /*
 227: **  PR_PERMIT -- print out a DEFINE PERMIT query for a protection tuple
 228: **
 229: **	Parameters:
 230: **		prot -- protection tuple
 231: **		relstat -- relstat from relation
 232: **
 233: **	Returns:
 234: **		none
 235: **
 236: **	Side Effects:
 237: **		reads in a tree from the "tree" catalog
 238: **		prints out a query
 239: **
 240: **	Requires:
 241: **		clrrange(), pr_range() -- to initialize and print range table
 242: **		gettree() -- to read in "tree" tree and fill range table
 243: **		pr_ops(),
 244: **		pr_doms(),
 245: **		pr_user(),
 246: **		pr_term(),
 247: **		pr_time(),
 248: **		pr_day() -- to print out parts of query
 249: **		pr_qual() -- [pr_tree.c] to print out qualification
 250: **
 251: **	Called By:
 252: **		pr_prot()
 253: **		pr_spec_permit()
 254: **
 255: **	Trace Flags:
 256: **		11, 1
 257: **
 258: **	History:
 259: **		11/15/78 -- (marc) written
 260: **		12/19/78 -- (marc) changed to deal with relstat
 261: **		1/9/79 -- (marc)    "		"	  "
 262: */
 263: 
 264: 
 265: pr_permit(prot, relstat)
 266: struct protect  *prot;
 267: int     relstat;
 268: {
 269:     register struct protect     *p;
 270:     register QTREE          *t;
 271:     extern int          Resultvar;
 272:     extern struct descriptor    Prodes;
 273: 
 274:     p = prot;
 275:     /*
 276: 	 * if there is a qualification then
 277: 	 * clear range table, then read in protect tree,
 278: 	 * the print out range statements
 279: 	 * else create single entry range table.
 280: 	 */
 281:     clrrange();
 282:     if (p->protree >= 0)
 283:         t = gettree(p->prorelid, p->prorelown, mdPROT, p->protree);
 284:     else
 285:     {
 286:         t = 0;
 287:         declare(0, p->prorelid, p->prorelown);
 288:         p->proresvar = 0;
 289:     }
 290:     printf("Permission %d -\n\n", p->propermid);
 291:     pr_range();
 292: 
 293: #	ifdef xZTR1
 294:     if (tTf(11, 1))
 295:     {
 296:         printf("pr_permit: prot=");
 297:         printup(&Prodes, p);
 298:         printf(", Resultvar=%d\n", Resultvar);
 299:     }
 300: #	endif
 301: 
 302:     /* print out query */
 303:     printf("define permit ");
 304:     pr_ops(p->proopset, relstat);
 305:     printf("on ");
 306:     pr_rv(Resultvar = p->proresvar);
 307:     putchar(' ');
 308:     pr_doms(p->prodomset, relstat);
 309:     printf("\n\t");
 310:     pr_user(p->prouser);
 311:     pr_term(p->proterm);
 312:     if ((relstat & S_PROTRET) && (relstat & S_PROTALL))
 313:     {
 314:         /* not special case */
 315:         pr_time(p->protodbgn, p->protodend);
 316:         pr_day(p->prodowbgn, p->prodowend);
 317:     }
 318:     if (t && t->right != QLEND)
 319:     {
 320:         printf("\nwhere ");
 321:         pr_qual(t->right);
 322:     }
 323:     printf("\n\n\n");
 324: }
 325: 
 326: /*
 327: **  PR_OPS -- Prints the the operation list defined by a protection opset
 328: **
 329: **	Eliminates the appropriate bits from a copy of the opset while printing
 330: **	out the appropriate operation list.
 331: **
 332: **	Parameters:
 333: **		opset -- protection.opset for the relation
 334: **		relstat
 335: **
 336: **	Returns:
 337: **		none
 338: **
 339: **	Side Effects:
 340: **		printing of permitted op list
 341: **
 342: **	Called By:
 343: **		pr_permit()
 344: **
 345: **	Trace Flags:
 346: **		11, 2
 347: **
 348: **
 349: **	History:
 350: **		11/15/78 -- (marc) written
 351: **		12/19/78 -- (marc) relstat added
 352: **		1/9/79 -- (marc) S_PROTALL and S_PROTRET handled
 353: */
 354: 
 355: pr_ops(opset, relstat)
 356: int     opset;
 357: int     relstat;
 358: {
 359:     register    op, j;
 360: 
 361: #	ifdef xZTR1
 362:     if (tTf(11, 2))
 363:         printf("pr_ops(0%o)\n", opset);
 364: #	endif
 365: 
 366:     if (!(relstat & S_PROTALL) || opset == -1)
 367:     {
 368:         printf("all ");
 369:         return;
 370:     }
 371:     if (!(relstat & S_PROTRET))
 372:     {
 373:         printf("retrieve ");
 374:         return;
 375:     }
 376: 
 377:     op = (opset & ~PRO_AGGR & ~PRO_TEST) & 077;
 378:     for ( ; ; )
 379:     {
 380:         if (op & (j = PRO_RETR))
 381:             printf("retrieve");
 382:         else if (op & (j = PRO_REPL))
 383:             printf("replace");
 384:         else if (op & (j = PRO_DEL))
 385:             printf("delete");
 386:         else if (op & (j = PRO_APP))
 387:             printf("append");
 388:         op ^= j;
 389:         if (op)
 390:             printf(", ");
 391:         else
 392:             break;
 393:     }
 394:     putchar(' ');
 395: }
 396: 
 397: /*
 398: **  PR_DOMS -- Print domains in permit target list
 399: **
 400: **	Parameters:
 401: **		doms -- an 8 byte integer array; a bit map of the domains
 402: **			if all 8 integers are -1, then "all" is printed fo
 403: **			for the target list
 404: **		relstat
 405: **
 406: **	Returns:
 407: **		none
 408: **
 409: **	Side Effects:
 410: **		prints out target list
 411: **
 412: **	Requires:
 413: **		pr_attname() -- to print out names given relation
 414: **				and domain number
 415: **
 416: **	Called By:
 417: **		pr_permit()
 418: **
 419: **	Trace Flags:
 420: **		11, 3
 421: **
 422: **	History:
 423: **		11/15/78 -- (marc) written
 424: **		1/9/79 -- (marc) modified so will assume all domains if
 425: **			special permission
 426: **		5/22/79 -- (marc) changed so bit of first word is unused
 427: */
 428: 
 429: pr_doms(doms, relstat)
 430: int doms [8];
 431: int relstat;
 432: {
 433:     register int        *d;
 434:     register int        flag, shift;
 435:     int         word;
 436:     char            *rel;
 437:     extern int      Resultvar;
 438: 
 439:     word = shift = 0;
 440:     d = doms;
 441:     rel = Rangev [Resultvar].relid;
 442: 
 443: #	ifdef xZTR1
 444:     if (tTf(11, 3))
 445:     {
 446:         printf("pr_doms: rel=\"%s\" ", rel);
 447:         for (word = 0; word < 8; )
 448:             printf("0%o ", d [word++]);
 449:         word = 0;
 450:         putchar('\n');
 451:     }
 452: #	endif
 453:     if (!(relstat & S_PROTALL) || !(relstat & S_PROTRET))
 454:         return;
 455:     flag = 1;
 456:     for (word = 0; word < 8; word++)
 457:         if (*d++ != -1)
 458:         {
 459:             flag = 0;
 460:             break;
 461:         }
 462: 
 463:     if (!flag)
 464:     {
 465:         putchar('(');
 466:         for (d = doms, word = 0; word < 8; word++, d++)
 467:         {
 468:             for (shift = 0; shift < 16; shift++, *d >>= 1)
 469:             {
 470:                 if (*d & 01)
 471:                 {
 472:                     if (flag++)
 473:                         printf(", ");
 474:                     pr_attname(rel, word * 16 + shift);
 475:                 }
 476:             }
 477:         }
 478:         putchar(')');
 479:     }
 480: }
 481: 
 482: /*
 483: **  PR_USER -- prints out permitted user's name
 484: **
 485: **	Parameters:
 486: **		user -- 2 char array, user's usercode as in
 487: **			users file
 488: **
 489: **	Returns:
 490: **		none
 491: **
 492: **	Side Effects:
 493: **		prints users name or "all" if user was "  "
 494: **
 495: **	Requires:
 496: **		getuser(UTIL) -- to get user login name.
 497: **
 498: **	Called By:
 499: **		pr_permit()
 500: **
 501: **	Trace Flags:
 502: **		11, 4
 503: **
 504: **	History:
 505: **		11/15/78 -- (marc) written
 506: */
 507: 
 508: pr_user(user)
 509: char        user [2];
 510: {
 511:     register        i;
 512:     char            buf [512];
 513:     register char       *c, *u;
 514: 
 515: #	ifdef xZTR1
 516:     if (tTf(11, 4))
 517:         printf("pr_user(\"%c%c\")\n", user [0], user [1]);
 518: #	endif
 519: 
 520:     c = buf;
 521:     u = user;
 522:     printf("to ");
 523:     if (bequal(u, "  ", 2))
 524:         printf("all ");
 525:     else
 526:     {
 527:         if (getuser(u, c))
 528:         {
 529:             printf("%c%c ", u[0], u[1]);
 530:             return;
 531:         }
 532:         while (*c != ':' && *c != '\n')
 533:             putchar(*c++);
 534:         putchar(' ');
 535:     }
 536: }
 537: 
 538: /*
 539: **  PR_TIME -- Prints out clock time range access is allowed
 540: **
 541: **	Parameters:
 542: **		bgn, end -- begin end times in seconds (if all day, returns)
 543: **
 544: **	Returns:
 545: **		none
 546: **
 547: **	Side Effects:
 548: **		prints out time
 549: **
 550: **	Called By:
 551: **		pr_permit()
 552: **
 553: **	Trace Flags:
 554: **		11, 5
 555: **
 556: **	History:
 557: **		11/15/78 -- (marc) written
 558: */
 559: 
 560: pr_time(bgn, end)
 561: int     bgn, end;
 562: {
 563:     char        time [3];
 564:     register char   *t;
 565:     register int    b, e;
 566: 
 567:     t = time;
 568:     b = bgn;
 569:     e = end;
 570: #	ifdef xZTR1
 571:     if (tTf(11, 5))
 572:         printf("pr_time(bgn=%d, end=%d)\n", b, e);
 573: #	endif
 574:     if (b == 0 && e == 24 * 60)
 575:         return;
 576:     printf("from %d:", b / 60);
 577:     itoa(b % 60, t);
 578:     if (!t [1])
 579:         putchar('0');
 580:     printf("%s to %d:", t, e / 60);
 581:     itoa(e % 60, t);
 582:     if (!t [1])
 583:         putchar('0');
 584:     printf("%s ", t);
 585: }
 586: 
 587: /*
 588: **  PR_DAY -- Prints day range permitted
 589: **
 590: **	Parameters:
 591: **		bgn, end -- bgn end days [0..6] (if all week returns)
 592: **
 593: **	Returns:
 594: **		none
 595: **
 596: **	Side Effects:
 597: **		prints days or nothing
 598: **
 599: **	Requires:
 600: **		Days [0..6] -- string array of day names
 601: **
 602: **	Called By:
 603: **		pr_permit()
 604: **
 605: **	Trace Flags:
 606: **		11, 6
 607: **
 608: **	History:
 609: **		11/15/78 -- (marc) written
 610: */
 611: 
 612: pr_day(bgn, end)
 613: int     bgn, end;
 614: {
 615: #	ifdef xZTR1
 616:     if (tTf(11, 6))
 617:         printf("pr_day(bgn=%d, end=%d)\n", bgn, end);
 618: #	endif
 619:     if (bgn == 0 && end >= 6)
 620:         return;
 621:     printf("on %s to %s ", Days [bgn], Days [end]);
 622: }
 623: 
 624: /*
 625: **  PR_TERM -- Print terminal from which access permitted
 626: **
 627: **	Parameters:
 628: **		term -- 1 char terminal id as in /etc/tty* (if ' ' the returns)
 629: **
 630: **	Returns:
 631: **		none
 632: **
 633: **	Side Effects:
 634: **		prints terminal or nothing
 635: **
 636: **	Called By:
 637: **		pr_permit()
 638: **
 639: **	Trace Flags:
 640: **		11, 7
 641: **
 642: **	History:
 643: **		11/15/78 -- (marc) written
 644: */
 645: 
 646: pr_term(term)
 647: # ifdef xV7_UNIX
 648: char        *term;
 649: # endif
 650: # ifndef xV7_UNIX
 651: char        term;
 652: # endif
 653: {
 654: #	ifdef xZTR1
 655:     if (tTf(11, 7))
 656: # ifdef xV7_UNIX
 657:         printf("pr_term(term='%2s')\n", term);
 658: # endif
 659: # ifndef xV7_UNIX
 660:         printf("pr_term(term='%c')\n", term);
 661: # endif
 662: #	endif
 663: 
 664: # ifndef xV7_UNIX
 665:     if (term != ' ')
 666:         printf("at tty%c ", term);
 667: # endif
 668: # ifdef xV7_UNIX
 669:     if (*term != ' ')
 670:         printf("at tty%2s ", term);
 671: # endif
 672: }

Defined functions

pr_day defined in line 612; used 1 times
pr_doms defined in line 429; used 1 times
pr_ops defined in line 355; used 1 times
pr_permit defined in line 265; used 2 times
pr_prot defined in line 105; used 1 times
pr_spec_permit defined in line 198; used 2 times
pr_term defined in line 646; used 1 times
pr_time defined in line 560; used 1 times
pr_user defined in line 508; used 1 times

Defined variables

Days defined in line 39; used 2 times
  • in line 621(2)
Rangev defined in line 59; used 10 times

Defined struct's

rngtab defined in line 52; used 2 times
  • in line 59(2)

Defined macros

QTREE defined in line 50; used 2 times
Last modified: 1995-06-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3743
Valid CSS Valid XHTML 1.0 Strict