1: #define MAINLINE 2: 3: #ifdef RCSIDENT 4: static char rcsid[] = "$Header: nfrcv.c,v 1.7.0.1 85/08/04 06:41:51 notes Rel $"; 5: #endif RCSIDENT 6: 7: /* 8: * netrcv - load a notefile from the network 9: * accepts 2 parameters (1) the source system 10: * (2) the notefile to load into 11: * 12: * This program should be called only by the netload program 13: * or a suitably informed user/wizard 14: * 15: * Original author: Ray Essick december 1981 16: */ 17: 18: #include "parms.h" 19: #include "structs.h" 20: #include "net.h" 21: 22: main (argc, argv) 23: char **argv; 24: { 25: struct io_f io; 26: FILE * log, /* network logfile */ 27: *fopen (); 28: char fn[WDLEN]; /* network logfile */ 29: char nowtime[DATELEN]; 30: char buf[CMDLEN]; 31: struct when_f atime; 32: int fid; /* for close loop */ 33: 34: setuid (geteuid ()); /* force to notes */ 35: startup (argc, argv); /* common init */ 36: 37: /* 38: * make damn sure we have enough file descriptors 39: */ 40: for (fid = 3; fid < 20; fid++) 41: close (fid); 42: 43: if (argc != 3) 44: { 45: printf ("Usage: %s notefile fromsystem\n", argv[0]); 46: exit (BAD); 47: } 48: 49: sprintf (fn, "%s/%s/%s", Mstdir, UTILITY, NETLOG); 50: gettime (&atime); 51: sprdate (&atime, nowtime); 52: 53: if (init (&io, argv[1]) < 0) 54: { 55: #ifdef AUTOCREATE /* if making 'em */ 56: if (argv[1][0] == '/') /* absolute? */ 57: { 58: #ifdef NFMAINT 59: { 60: char tbuf[128]; /* title */ 61: sprintf (buf, "%s: non-existent notesfile from %s\nAborted by nfrcv\n", 62: argv[1], argv[2]); 63: sprintf (tbuf, "Nfrcv ignores %s", argv[1]); 64: nfcomment (NFMAINT, buf, tbuf, 0, 0); 65: } 66: #endif NFMAINT 67: printf ("Nfrcv: %s: no autocreate for absolute pathnames\n", 68: argv[1]); 69: exit (BAD); /* abort */ 70: } 71: buildnf (argv[1], Mstdir, 0, 1, 1); /* no anon, open, networked */ 72: x (init (&io, argv[1]) < 0, "nfrcv: couldn't create notesfile"); 73: #ifdef NFMAINT 74: { 75: char tbuf[128]; /* title */ 76: sprintf (buf, "%s: non-existent notesfile from %s created by nfrcv\n", 77: argv[1], argv[2]); 78: sprintf (tbuf, "Nfrcv creates %s", argv[1]); 79: nfcomment (NFMAINT, buf, tbuf, TRUE, 0); 80: } 81: #endif NFMAINT 82: 83: #else /* just tell about it */ 84: x ((log = fopen (fn, "a")) == NULL, "netrcv: bad log open"); 85: sprintf (buf, "%s: Non-existent notesfile received from %s at %s\n", 86: argv[1], argv[2], nowtime); 87: fprintf (log, "%s", buf); /* log it in the log */ 88: x (fclose (log) == EOF, "netrcv: bad close of log file"); 89: #ifdef NFMAINT /* log it in a nf also? */ 90: nfcomment (NFMAINT, buf, "non-notesfile to nfrcv", 0, 0); 91: #endif 92: exit (NONF); 93: #endif AUTOCREATE /* of autocreate else clause */ 94: } 95: 96: if ((io.descr.d_stat & NETWRKD) == 0) 97: { 98: printf ("%s is not a networked notefile on %s\n", argv[1], System); 99: finish (&io); 100: x ((log = fopen (fn, "a")) == NULL, "netrcv: bad log open"); 101: fprintf (log, "%s: Non-networked notesfile received from %s at %s\n", 102: argv[1], argv[2], nowtime); 103: x (fclose (log) == EOF, "netrcv: bad close of log file"); 104: exit (NONF); /* un-networked appears not there */ 105: } 106: 107: loadem (&io, stdin, LOCKIT, argv[2], NODETAIL, -1); 108: 109: x ((log = fopen (fn, "a")) == NULL, "netrcv: couldnt open log file"); 110: fprintf (log, "%s: insert (%d,%d), drop (%d,%d) from %s at %s\n", 111: argv[1], io.nnotrcvd, io.nrsprcvd, io.nnotdrop, io.nrspdrop, 112: argv[2], nowtime); 113: x (fclose (log) == EOF, "netrcv: bad close of log file"); 114: 115: #ifdef STATS 116: locknf (&io, DSCRLOCK); /* bump count of netowrk calls rcvd */ 117: getdscr (&io, &io.descr); 118: io.descr.netwrkins++; /* bump the count */ 119: putdscr (&io, &io.descr); 120: unlocknf (&io, DSCRLOCK); 121: #endif STATS 122: 123: printf ("%s: Inserted: (%d,%d) Dropped: (%d,%d)\n", 124: argv[1], io.nnotrcvd, io.nrsprcvd, io.nnotdrop, io.nrspdrop); 125: 126: finish (&io); 127: exit (GOOD); 128: }