1: #include "parms.h" 2: #include "structs.h" 3: 4: #ifdef RCSIDENT 5: static char rcsid[] = "$Header: dump.c,v 1.7.0.1 85/10/09 18:11:12 notes Rel $"; 6: #endif RCSIDENT 7: 8: /* 9: * dumpnf(nfname) 10: * 11: * Dump a notesfile. Parameters are a notesfile name, a name 12: * for the descriptor information, and a name for the rest 13: * of the notesfile. 14: * 15: */ 16: 17: dumpnf (nfname, dfile) 18: char *nfname; /* name of notesfile */ 19: char *dfile; /* descriptor */ 20: { 21: struct io_f io; 22: struct note_f note; 23: FILE * dout; 24: int i; 25: 26: if ((i = init (&io, nfname)) < 0) 27: { 28: fprintf (stderr, "Problems opening notesfile %s\n", nfname); 29: return (i); /* die */ 30: } 31: if (!allow (&io, READOK)) /* no read access! */ 32: { 33: fprintf (stderr, "You aren't allowed to read %s\n", nfname); 34: closenf (&io); 35: return (-1); 36: } 37: if (!strcmp (dfile, "-")) /* use stdout */ 38: dout = stdout; 39: else 40: if ((dout = fopen (dfile, "w")) == NULL) /* a real file */ 41: { 42: closenf (&io); /* die */ 43: return (-1); 44: } 45: 46: dmpdescr (&io, dout); /* dump descriptor */ 47: dmpaccess (&io, dout); /* access list out */ 48: for (i = 1; i <= io.descr.d_nnote; i++) /* dump each note */ 49: { 50: getnrec (&io, i, ¬e); /* get record */ 51: if (note.n_stat & DELETED) 52: continue; /* ignore */ 53: dmpnote (&io, ¬e, i, dout, DETAIL, 0); /* base note */ 54: dmprall (&io, ¬e, i, dout, DETAIL, 0); /* and responses */ 55: } 56: 57: fclose (dout); /* close descriptor */ 58: closenf (&io); /* and notesfile */ 59: return (0); /* return nicely */ 60: } 61: 62: 63: /* 64: * dmpdescr 65: * 66: * Dump a notesfile descriptor and it's policy note if there is 67: * one. Send it to the supplied stdio file. 68: * 69: */ 70: 71: dmpdescr (io, dmpfile) 72: struct io_f *io; 73: FILE * dmpfile; 74: { 75: char buf[128]; /* hold strings */ 76: register int i; 77: 78: getdscr (io, &io -> descr); /* grab descriptor */ 79: fprintf (dmpfile, "NF-Title: %s\n", io -> descr.d_title); 80: fprintf (dmpfile, "NF-Director-Message: %s\n", io -> descr.d_drmes); 81: sprdate (&io -> descr.d_lastm, buf); 82: fprintf (dmpfile, "NF-Last-Modified: %s\n", buf); 83: fprintf (dmpfile, "NF-Status:"); /* status */ 84: { 85: if (io -> descr.d_stat & ANONOK) 86: fprintf (dmpfile, " Anonymous"); 87: if (io -> descr.d_stat & OPEN) 88: fprintf (dmpfile, " Open"); 89: if (io -> descr.d_stat & NETWRKD) 90: fprintf (dmpfile, " Networked"); 91: if (io -> descr.d_stat & ISARCH) 92: fprintf (dmpfile, " Archive"); 93: } 94: putc ('\n', dmpfile); /* end status line */ 95: fprintf (dmpfile, "NF-Id-Sequence: %ld@%s\n", 96: io -> descr.d_id.uniqid, io -> descr.d_id.sys); 97: fprintf (dmpfile, "NF-Number: %ld\n", (long) io -> descr.d_nfnum); 98: sprdate (&io -> descr.d_lstxmit, buf); 99: fprintf (dmpfile, "NF-Last-Transmit: %s\n", buf); 100: sprdate (&io -> descr.d_created, buf); 101: fprintf (dmpfile, "NF-Created: %s\n", buf); 102: sprdate (&io -> descr.d_lastuse, buf); 103: fprintf (dmpfile, "NF-Last-Used: %s\n", buf); 104: fprintf (dmpfile, "NF-Days-Used: %ld\n", io -> descr.d_daysused); 105: fprintf (dmpfile, "NF-Notes-Written: %ld\n", io -> descr.d_notwrit); 106: fprintf (dmpfile, "NF-Notes-Read: %ld\n", io -> descr.d_notread); 107: fprintf (dmpfile, "NF-Notes-Transmitted: %ld\n", io -> descr.d_notxmit); 108: fprintf (dmpfile, "NF-Notes-Received: %ld\n", io -> descr.d_notrcvd); 109: fprintf (dmpfile, "NF-Notes-Dropped: %ld\n", io -> descr.d_notdrop); 110: fprintf (dmpfile, "NF-Responses-Written: %ld\n", io -> descr.d_rspwrit); 111: fprintf (dmpfile, "NF-Responses-Read: %ld\n", io -> descr.d_rspread); 112: fprintf (dmpfile, "NF-Responses-Transmitted: %ld\n", 113: io -> descr.d_rspxmit); 114: fprintf (dmpfile, "NF-Responses-Received: %ld\n", io -> descr.d_rsprcvd); 115: fprintf (dmpfile, "NF-Responses-Dropped: %ld\n", io -> descr.d_rspdrop); 116: fprintf (dmpfile, "NF-Entries: %ld\n", io -> descr.entries); 117: fprintf (dmpfile, "NF-Walltime: %ld seconds\n", 118: io -> descr.walltime); 119: fprintf (dmpfile, "NF-Orphans-Received: %ld\n", io -> descr.d_orphans); 120: fprintf (dmpfile, "NF-Orphans-Adopted: %ld\n", io -> descr.d_adopted); 121: fprintf (dmpfile, "NF-Transmits: %ld\n", io -> descr.netwrkouts); 122: fprintf (dmpfile, "NF-Receives: %ld\n", io -> descr.netwrkins); 123: fprintf (dmpfile, "NF-Expiration-Age: %ld Days\n", io -> descr.d_archtime); 124: switch ((int) io -> descr.d_archkeep) 125: { 126: case KEEPYES: 127: strcpy (buf, "Archive"); 128: break; 129: case KEEPNO: 130: strcpy (buf, "Delete"); 131: break; 132: default: 133: strcpy (buf, "Default"); 134: break; 135: } 136: fprintf (dmpfile, "NF-Expiration-Action: %s\n", buf); 137: switch ((int) io -> descr.d_dmesgstat) 138: { 139: case DIRON: 140: strcpy (buf, "On"); 141: break; 142: case DIROFF: 143: strcpy (buf, "Off"); 144: break; 145: case DIRNOCARE: 146: strcpy (buf, "Either"); 147: break; 148: default: 149: strcpy (buf, "Default"); 150: break; 151: } 152: fprintf (dmpfile, "NF-Expiration-Status: %s\n", buf); 153: fprintf (dmpfile, "NF-Working-Set-Size: %ld\n", io -> descr.d_workset); 154: fprintf (dmpfile, "NF-Longest-Text: %ld bytes\n", io -> descr.d_longnote); 155: 156: fprintf (dmpfile, "NF-Policy-Exists: %s\n", 157: io -> descr.d_plcy ? "Yes" : "No"); 158: fprintf (dmpfile, "NF-Descriptor: Finished\n"); /* mark as done */ 159: /* 160: * dump the policy note if there is one 161: */ 162: if (io -> descr.d_plcy) /* if a policy note */ 163: { /* dump it */ 164: struct note_f note; 165: getnrec (io, 0, ¬e); 166: dmpnote (io, ¬e, 0, dmpfile, DETAIL, 0); /* dump it */ 167: } 168: } 169: 170: /* 171: * dmpaccess(&io) 172: * 173: * dump the access list. 174: * short circuited for now. 175: */ 176: 177: dmpaccess (io, dfile) 178: struct io_f *io; 179: FILE * dfile; 180: { 181: struct perm_f perms[NPERMS]; /* access rights */ 182: int nperms; /* and how many */ 183: char pathname[WDLEN]; 184: char *atype; 185: char mode[32]; /* at most 5 */ 186: int i; 187: FILE * afile; 188: 189: sprintf (pathname, "%s/%s/%s", io -> basedir, io -> nf, ACCESS); 190: x ((afile = fopen (pathname, "r")) == NULL, "dmpaccess: no access list"); 191: x ((nperms = fread (perms, sizeof (struct perm_f), NPERMS, afile)) == 0, 192: "dmpaccess: empty access list"); 193: fclose (afile); /* all done */ 194: for (i = 0; i < nperms; i++) 195: { 196: switch (perms[i].ptype) 197: { 198: case PERMUSER: 199: atype = "User"; 200: break; 201: case PERMGROUP: 202: atype = "Group"; 203: break; 204: case PERMSYSTEM: 205: atype = "System"; 206: break; 207: default: 208: atype = "Bizarro"; 209: break; 210: } 211: strcpy (mode, ""); /* build it up */ 212: if (perms[i].perms & DRCTOK) /* director */ 213: strcat (mode, "d"); 214: if (perms[i].perms & READOK) /* read */ 215: strcat (mode, "r"); 216: if (perms[i].perms & WRITOK) /* write */ 217: strcat (mode, "w"); 218: if (perms[i].perms & RESPOK) /* respond */ 219: strcat (mode, "a"); 220: fprintf (dfile, "Access-Right: %s:%s=%s\n", 221: atype, perms[i].name, mode); 222: } 223: fprintf (dfile, "NF-Access-Finished:\n"); 224: }