# 2.11BSD#431 - /usr/src/new/notes/src/nfadmin.c

##### Functions

    main              X
    newval            X
    notesum           X
    usage             X
    yes               X

##### Variables

    flag              X

##### Macros

    MAINLINE          X

       1: #define     MAINLINE
       2: #include    "parms.h"
       3: #include    "structs.h"
       4:
       5: #ifdef  RCSIDENT
       6: static char rcsid[] = "$Header: nfadmin.c,v 1.8 87/07/01 13:47:49 paul Exp $";
       7: #endif	RCSIDENT
       8:
       9: /*
      10:  *	Any normal user can run this program. It only allows changes
      11:  *	to notesfiles the user is a director in.
      12:  *
      13:  */
      14:
      15:
      16: main (argc, argv)
      17: int     argc;
      18: char  **argv;
      19: {
      20:     struct io_f io;
      21:     int     argn;
      22:     struct nflist_f *nfptr;
      23:     int     change, newexp;
      24:     int     newanon, newopen, newnet, newarch, newlocal, newmod;
      25:     int     newwset, newdir, newact, newlen;
      26:
      27:     startup (argc, argv);               /* common init code */
      28:
      29:     newdir = newact = newwset = newlen = newexp = -2;
      30:     newanon = newopen = newnet = newarch = newlocal = newmod = change = 0;
      31:     for ( argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++)
      32:     {
      33:     switch(argv[0][1])
      34:     {
      35:     case 'f':
      36:         readrc(argv[1]);
      37:         argv++, argc--;
      38:         break;
      39:     case 'a':
      40:         change = 1;
      41:         newanon = newval(argv[0][2]);
      42:         break;
      43:     case 'n':
      44:         change = 1;
      45:         newnet = newval(argv[0][2]);
      46:         break;
      47:     case 'o':
      48:         change = 1;
      49:         newopen = newval(argv[0][2]);
      50:         break;
      51:     case 'L':
      52:         change = 1;
      53:         newlocal = newval(argv[0][2]);
      54:         break;
      55:     case 'M':
      56:         change = 1;
      57:         newmod = newval(argv[0][2]);
      58:         break;
      59:     case 'A':
      60:         change = 1;
      61:         newarch = newval(argv[0][2]);
      62:         break;
      63:     case 'e':
      64:         change = 1;
      65:         if (argv[0][2] == '=')
      66:         {
      67:             newexp = atoi(&argv[0][3]);
      68:         } else usage();
      69:         break;
      70:     case 'W':
      71:         change = 1;
      72:         if (argv[0][2] == '=')
      73:         {
      74:             newwset = atoi(&argv[0][3]);
      75:         } else usage();
      76:         break;
      77:     case 'l':
      78:         change = 1;
      79:         if (argv[0][2] == '=')
      80:         {
      81:             newlen = atoi(&argv[0][3]);
      82:         } else usage();
      83:         break;
      84:     case 'E':
      85:         change = 1;
      86:         if (argv[0][2] == '=')
      87:         {
      88:             if (strncmp(&argv[0][3], "arch", 4) == 0)
      89:                 newact = KEEPYES;
      90:             else if (strncmp(&argv[0][3], "del", 3) == 0)
      91:                 newact = KEEPNO;
      92:             else if (strncmp(&argv[0][3], "def", 3) == 0)
      93:                 newact = KEEPDFLT;
      94:             else if (strncmp(&argv[0][3], "dfl", 3) == 0)
      95:                 newact = KEEPDFLT;
      96:             else usage();
      97:         } else usage();
      98:         break;
      99:     case 'D':
     100:         change = 1;
     101:         if (argv[0][2] == '=')
     102:         {
     103:             if (strncmp(&argv[0][3], "on", 2) == 0)
     104:                 newdir = DIRON;
     105:             else if (strncmp(&argv[0][3], "off", 3) == 0)
     106:                 newdir = DIROFF;
     107:             else if (strncmp(&argv[0][3], "no", 2) == 0)
     108:                 newdir = DIRNOCARE;
     109:             else if (strncmp(&argv[0][3], "anyon", 5) == 0)
     110:                 newdir = DIRANYON;
     111:             else if (strncmp(&argv[0][3], "def", 3) == 0)
     112:                 newdir = DIRDFLT;
     113:             else if (strncmp(&argv[0][3], "dfl", 3) == 0)
     114:                 newdir = DIRDFLT;
     115:             else usage();
     116:         } else usage();
     117:         break;
     118:     default:
     119:         printf("Bad flag %c\n", argv[0][1]);
     120:         usage();
     121:         break;
     122:     }
     123:     }
     124:
     125:     for (argn = 0; argn < argc; argn++)
     126:     {
     127:     expand (argv[argn]);                /* load it */
     128:     }
     129:
     130:     while ((nfptr = nextgroup ()) != (struct nflist_f *) NULL)
     131:     {
     132:     if (init (&io, nfptr -> nf_name) < 0)       /* open */
     133:     {
     134:         printf ("%s:	couldn't open\n", nfptr -> nf_name);
     135:         continue;
     136:     }
     137:     if (change)
     138:     {
     139:         if (!allow (&io, DRCTOK))           /* a director? */
     140:         {
     141:         printf ("%s:	Not a director\n", nfptr -> nf_name);
     142:         closenf (&io);
     143:         continue;
     144:         }
     145:         locknf(&io, DSCRLOCK);
     146:         getdscr(&io, &io.descr);
     147:         if (newnet)
     148:         if (newnet > 0)
     149:             io.descr.d_stat |= NETWRKD;
     150:         else
     151:             io.descr.d_stat &= ~NETWRKD;
     152:         if (newanon)
     153:         if (newanon > 0)
     154:             io.descr.d_stat |= ANONOK;
     155:         else
     156:             io.descr.d_stat &= ~ANONOK;
     157:         if (newopen)
     158:         if (newopen > 0)
     159:             io.descr.d_stat |= OPEN;
     160:         else
     161:             io.descr.d_stat &= ~OPEN;
     162:         if (newlocal)
     163:         if (newlocal > 0)
     164:             io.descr.d_stat |= LOCAL;
     165:         else
     166:             io.descr.d_stat &= ~LOCAL;
     167:         if (newmod)
     168:         if (newmod > 0)
     169:             io.descr.d_stat |= MODERATED;
     170:         else
     171:             io.descr.d_stat &= ~MODERATED;
     172:         if (newarch)
     173:         if (newarch > 0)
     174:             io.descr.d_stat |= ISARCH;
     175:         else
     176:             io.descr.d_stat &= ~ISARCH;
     177:         if (newexp != -2)
     178:         io.descr.d_archtime = newexp;
     179:         if (newwset != -2)
     180:         io.descr.d_workset = newwset;
     181:         if (newlen != -2)
     182:         io.descr.d_longnote = newlen;
     183:         if (newact != -2)
     184:         io.descr.d_archkeep = newact;
     185:         if (newdir != -2)
     186:         io.descr.d_dmesgstat = newdir;
     187:
     188:         putdscr(&io, &io.descr);
     189:         unlocknf(&io, DSCRLOCK);
     190:
     191:     }
     192:     notesum(&io.descr);
     193:     closenf (&io);
     194:     }
     195:     exit (0);                       /* all done */
     196: }
     197:
     198: usage (name)                        /* how to invoke */
     199: char   *name;
     200: {
     201:     fprintf (stderr,
     202:         "Usage: %s <flags> <notesfile> [<notesfile>...]\n",
     203:         "nfadmin");
     204:     fprintf(stderr,
     205:         "-a+\tanonymous on\n-a-\tanonymous off\n-n+\tnetworked\n-n-\tnot networked\n-o+\topen\n-o-\tclosed\n-A+\tis archive\n-A-\tis not archive\n-e=n\texpiration time\n-e=-1\tnever expire\n");
     206:     exit (1);
     207: }
     208:
     209: char *yes(b)
     210: int b;
     211: {
     212:     if (b)
     213:         return "YES ";
     214:     else    return " NO ";
     215: }
     216:
     217: int flag = 0;
     218:
     219: notesum(d)
     220: struct descr_f *d;
     221: {
     222: /*
     223: notesfile name  NetW Open Anon Arch   Wset archt kp  msgst    #note
     224: xxxxxxxxxxxxxx: Y/N  Y/N  Y/N  Y/N   xxxxx xxxxx ARCH xxxx    xxxxx
     225: */
     226:
     227:     char archtime[10], archkeep[10], msgstat[10];
     228:
     229:     if (!flag)
     230:     {
     231:         printf("    notesfile title     NetW Open Anon Arch Locl Mod    WSet Arch. Keep DirM     #         Max\n");
     232:         printf("                        ------------status-----------   Size Time  Actn Stat   Notes       Size\n");
     233:     }
     234:     flag = 1;
     235:     switch((int) d->d_dmesgstat)
     236:     {
     237:     case DIRDFLT:   strcpy(msgstat, "DFLT");
     238:             break;
     239:     case DIRON: strcpy(msgstat, " ON ");
     240:             break;
     241:     case DIROFF:    strcpy(msgstat, "OFF ");
     242:             break;
     243:     case DIRANYON:  strcpy(msgstat, "ANY ");
     244:             break;
     245:     case DIRNOCARE: strcpy(msgstat, "IGNR");
     246:             break;
     247:     default:    strcpy(msgstat, "????");
     248:             break;
     249:     }
     250:     switch((int) d->d_archkeep)
     251:     {
     252:     case KEEPDFLT:  strcpy(archkeep, "DFLT");
     253:             break;
     254:     case KEEPNO:    strcpy(archkeep, "DEL ");
     255:             break;
     256:     case KEEPYES:   strcpy(archkeep, "ARCH");
     257:             break;
     258:     default:    strcpy(archkeep, "????");
     259:             break;
     260:     }
     261:     if (d->d_archtime == -1)
     262:         strcpy(archtime, "NEVER");
     263:     else if (d->d_archtime == 0)
     264:         strcpy(archtime, "DFLT ");
     265:     else    sprintf(archtime, "%4d ", d->d_archtime);
     266:
     267:
     268:     printf("%22.22s: %s %s %s %s %s %s  %5d %s %s %s   %5d%12d\n",
     269:         d->d_title, yes(d->d_stat & NETWRKD), yes(d->d_stat & OPEN),
     270:         yes(d->d_stat & ANONOK), yes(d->d_stat & ISARCH),
     271:         yes(d->d_stat & LOCAL), yes(d->d_stat & MODERATED),
     272:         d->d_workset, archtime, archkeep, msgstat, d->d_nnote,
     273:         d->d_longnote);
     274:
     275: }
     276: int newval(c)
     277: char    c;
     278: {
     279:     switch(c)
     280:     {
     281:     case '\0':
     282:     case '+':
     283:         return 1;
     284:     case '-':
     285:         return -1;
     286:     }
     287:     usage();
     288: }

#### Defined functions

main defined in line 16; never used
newval defined in line 276; used 6 times

- in line 41-61(6)

notesum defined in line 219; used 1 times

- in line 192

usage defined in line 198; used 9 times

- in line 68, 75, 82, 96-97(2), 115-120(3), 287

yes defined in line 209; used 6 times

- in line 269-271(6)

#### Defined variables

flag defined in line 217; used 2 times

- in line 229-234(2)

rcsid defined in line 6; never used

#### Defined macros

MAINLINE defined in line 1; never used

Last modified: 1989-07-09 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 896 |