1: #define MAINLINE 2: #include "parms.h" 3: #include "structs.h" 4: #include "newsgate.h" 5: #include "net.h" 6: #ifdef SYSLOG 7: # include <syslog.h> 8: # undef stderr 9: # define fprintf syslog 10: # define stderr LOG_NOTICE 11: #endif SYSLOG 12: 13: #ifdef pdp11 14: #define gatesysnames _gtsysn 15: #define gatesyscount _gtsysc 16: #endif 17: 18: #ifdef RCSIDENT 19: static char rcsid[] = "$Header: /usr/local/src/usenet/notes/src/RCS/newsoutput.c,v 1.8 88/11/11 00:59:03 paul Exp $"; 20: #endif RCSIDENT 21: 22: 23: /* 24: * newsoutput - place the specified notesfiles out to the 25: * news susbsystem. 26: * 27: * Original Coding: Ray Essick April 1982 28: * Modified to better handle multiple system gateing 29: * Ray Essick September 1982 30: */ 31: 32: static char *whichsys; /* who dumping for */ 33: static int verbosity = 0; /* quiet */ 34: static int backward = 0; /* do old format */ 35: char rnewscmd[CMDLEN] = DFLTRNEWS; /* how to rnews */ 36: int sendclass = 0; /* classes to send */ 37: int usetime = NORMSEQ; /* user supplied */ 38: int gatesyscount = 0; /* actives slots in */ 39: char *gatesysnames[GATEMAX]; /* list of names */ 40: 41: newsone (nfname) 42: char *nfname; 43: { 44: if (verbosity) 45: { 46: printf ("\t%s\n", nfname); 47: fflush (stdout); 48: } 49: return newsout (nfname, backward, usetime, verbosity); 50: } 51: 52: 53: main (argc, argv) 54: char **argv; 55: { 56: int i; 57: struct nflist_f *nfptr; 58: struct nethow_f how; 59: struct when_f ztime; 60: char fmtdate[DATELEN]; /* formatted date */ 61: int aflag, 62: cflag, 63: sflag; 64: 65: startup (argc, argv); /* common init */ 66: 67: if (argc == 1) 68: { 69: printf ("Usage: %s [-ssitename | -a] [-v] [-b] [-f file] topic1 [topic2 ...]\n", argv[0]); 70: exit (BAD); 71: } 72: 73: if (globuid != Notesuid) 74: { 75: printf ("Sorry, only notes 'owner' can send notes to news\n"); 76: exit (BAD); 77: } 78: 79: #ifdef SYSLOG 80: openlog ("newsoutput", LOG_PID, SYSLOG); 81: #endif SYSLOG 82: whichsys = System; /* defaults to local */ 83: aflag = cflag = sflag = 0; /* none done */ 84: gatesyscount = 0; /* none there */ 85: verbosity = 0; /* no messages */ 86: backward = 0; /* just new format */ 87: usetime = NORMSEQ; /* non-seq time */ 88: strcpy (rnewscmd, DFLTRNEWS); /* default rnews */ 89: getnet (RNEWSNAME, NULL, &how); /* how to get there */ 90: if (how.nh_xmit != (char *) NULL) /* specified? */ 91: strcpy (rnewscmd, how.nh_xmit); /* load it */ 92: 93: for (i = 1; i < argc; i++) 94: { 95: if (argv[i][0] == '-') 96: switch (argv[i][1]) 97: { 98: 99: case 's': /* gateway for */ 100: sflag = 1; 101: if (argv[i][2] != '\0') /* -ssite */ 102: { 103: whichsys = &argv[i][2]; 104: } 105: else 106: { /* -s sitename */ 107: if (++i == argc) /* no sitename */ 108: { 109: fprintf (stderr, "-s must be followed by a sitename\n"); 110: exit (BAD); 111: } 112: whichsys = argv[i]; /* mark site */ 113: } 114: gatesyscount = 1; /* fill in table */ 115: gatesysnames[0] = whichsys; 116: break; 117: 118: case 'a': /* all non-local */ 119: sendclass |= NEWS_ALLSEND; 120: aflag = 1; 121: whichsys = NEWSSYS; /* it's sequencer */ 122: break; 123: 124: case 'c': /* file of systems */ 125: cflag = 1; 126: whichsys = NEWSSYS; /* use the global seq */ 127: if (++i == argc) 128: { 129: printf ("%s: -c option must be followed by filename\n", Invokedas); 130: exit (BAD); 131: } 132: loadgate (argv[i]); /* load the table */ 133: break; 134: 135: case 'v': /* messages per group */ 136: verbosity++; 137: break; 138: 139: case 'f': /* process a file */ 140: if (++i == argc) /* no filename */ 141: { 142: fprintf (stderr, "-f must be followed by a filename\n"); 143: exit (BAD); 144: } 145: readrc (argv[i]); /* read the file */ 146: break; 147: 148: case 'b': /* include old headers */ 149: backward++; 150: break; 151: 152: case 't': /* explicit time */ 153: case 'o': /* compatibility */ 154: if (++i == argc) 155: { 156: fprintf (stderr, "-t option requires following date\n"); 157: exit (BAD); 158: } 159: switch (parsetime (argv[i], &ztime)) 160: { 161: case 0: /* ok */ 162: usetime = BASESEQ; /* use this time */ 163: Basetime = ztime; /* store it */ 164: sprdate (&ztime, fmtdate); /* format */ 165: printf ("%s: Sending articles since %s\n", 166: Invokedas, fmtdate); 167: break; 168: case -1: /* no good */ 169: fprintf (stderr, "%s: unable to parse time `%s'\n", 170: Invokedas, argv[i]); 171: exit (BAD); 172: case -2: /* in future */ 173: fprintf (stderr, "%s: parsed date (%s) is in the future\n", 174: Invokedas, argv[i]); 175: exit (BAD); 176: } 177: break; 178: 179: 180: default: 181: printf ("Bad switch: %c\n", argv[i][1]); 182: exit (BAD); 183: } 184: else 185: expand (argv[i]); /* put it in the list */ 186: } 187: 188: /* 189: * now, run down the list and send each notesfile. 190: * check to make sure some things are used consistently first. 191: */ 192: 193: if (aflag + cflag + sflag > 1) 194: { /* -a and -s */ 195: fprintf (stderr, "%s: -a, -c and -s mutually exclusive\n", Invokedas); 196: exit (BAD); 197: } 198: if (gatesyscount == 0 && !cflag) /* default to local */ 199: { 200: /* 201: * check against cflag allows empty -c files to "work" 202: */ 203: gatesysnames[0] = whichsys; 204: gatesyscount = 1; /* just us */ 205: } 206: if (1) /* was verbosity */ 207: { /* now always... */ 208: printf ("%s: Sending news articles through command: %s\n", 209: Invokedas, rnewscmd); 210: if (sendclass & NEWS_ALLSEND) 211: { 212: printf ("Sending to News for any system\n"); 213: } 214: else 215: { 216: int col; /* count columns */ 217: 218: /* 219: * WE WANT TO SORT THE LIST AT THIS POINT 220: * so that the cansend() routine in newsout.c can do a binary 221: * search to make things faster. 222: */ 223: printf ("Gateway for the following %d system(s):\n", gatesyscount); 224: for (i = 0, col = 0; i < gatesyscount; i++) 225: { 226: printf (" %16s", gatesysnames[i]); 227: if (++col % 4 == 0) 228: putc ('\n', stdout); /* multi-column */ 229: } 230: } 231: printf ("\n================\n"); 232: } 233: fflush (stdout); /* make sure in order */ 234: sprintf (Seqname, "%s:%s", NEWSSEQ, whichsys); 235: while ((nfptr = nextgroup ()) != (struct nflist_f *) NULL) 236: newsone (nfptr -> nf_name); 237: 238: exit (GOOD); /* all done */ 239: } 240: 241: /* 242: * loadgate(filename) 243: * 244: * fill in the system table. 245: */ 246: 247: loadgate (filename) 248: char *filename; 249: { 250: FILE * fptr; 251: char onesystem[256]; /* system name */ 252: 253: if ((fptr = fopen (filename, "r")) == (FILE *) NULL) 254: return (-1); /* bah humbug */ 255: 256: while (fscanf (fptr, "%s", onesystem) == 1) 257: { 258: gatesysnames[gatesyscount++] = strsave (onesystem); 259: } 260: 261: fclose (onesystem); 262: return (0); 263: }