|
|
1.1 ! root 1: /* D.L.Buck and Associates, Inc. - January, 1984 ! 2: * ! 3: * COPYRIGHT NOTICE: ! 4: * Copyright c 1984 - An unpublished work by ! 5: * D.L.Buck and Associates, Inc. ! 6: * ! 7: * PROPRIETARY RIGHTS NOTICE: ! 8: * All rights reserved. This document and program contains ! 9: * proprietary information of D.L.Buck and Associates,Inc. ! 10: * of San Jose, California, U.S.A., embodying confidential ! 11: * information, ideas, and expressions, no part of which ! 12: * may be reproduced, or transmitted in any form or by any ! 13: * means, electronic, mechanical, or otherwise, without ! 14: * the written permission of D.L.Buck and Associates, Inc. ! 15: * ! 16: * NAME ! 17: * get_cnfig ! 18: * ! 19: * SYNOPSIS ! 20: * get_cnfig(cfgfile) ! 21: * char *cfgfile ! 22: * ! 23: * DESCRIPTION ! 24: * Get host communications device and printer configuration parameters ! 25: * from host's configuration file. ! 26: * ! 27: */ ! 28: ! 29: #include <stdio.h> ! 30: #include "local.h" ! 31: #include <bsc/bscio.h> ! 32: #include <sys/time.h> ! 33: ! 34: #define YES 1 ! 35: #define NO 0 ! 36: ! 37: extern struct bscio p; ! 38: extern char devname[], hostname[]; ! 39: extern char sys_admin[]; ! 40: extern int rviab, pt_to_pt, ascii, chk_hostid, chk_termid, primary; ! 41: extern char termid; ! 42: extern char note[]; ! 43: extern FILE *aud, *outfd; ! 44: ! 45: extern int prtype,buffered,vfc,tprint,ctype,linesperpage; ! 46: extern char outtype; /* type of output destination - P=pipe, F=file */ ! 47: char output[50]; /* printer output destination */ ! 48: ! 49: struct tm *localtime(), *t; ! 50: long time(),currtime; ! 51: ! 52: int had_error; /* set to # errors encountered in config file */ ! 53: ! 54: get_cnfig(cfgfile) ! 55: register char *cfgfile; ! 56: { ! 57: static char sccsid[] = "@(#)emprcnfig.c 1.4 "; /* sccs id */ ! 58: FILE *popen(),*fopen(); ! 59: FILE *fptr; /* file pointer returned by fopen */ ! 60: ! 61: register int counter; /* tracks line of config file being read */ ! 62: register int i; /* general purpose int */ ! 63: ! 64: register char *pos; /* convenient line position pointer */ ! 65: ! 66: char *index(); ! 67: char cline[80]; /* contains one configuration line */ ! 68: ! 69: /* default b_flags parameter values */ ! 70: int fulldup = NO; ! 71: ! 72: /* set defaults for communications device */ ! 73: p.b_blks = 254; /* default block size */ ! 74: rviab = BSCRVIABT; /* abort on receiving rvi */ ! 75: p.b_nbid = 0; /* default number of bids limit */ ! 76: p.b_nnak = 16; /* default number of naks allowed */ ! 77: p.b_nretry = 15; /* default number of retrys allowed */ ! 78: p.b_nttd = 150; /* default number of temp. txt delays */ ! 79: p.b_nwack = 150; /* default number of wacks allowed */ ! 80: p.b_nor = 30; /* default timeout */ ! 81: pt_to_pt = NO; /* default to multi-point communications */ ! 82: chk_hostid = NO; /* don't check hostid */ ! 83: chk_termid = NO; /* don't check termid */ ! 84: ascii = NO; /* default transmission code is EBCDIC */ ! 85: counter = 0; /* current line number within configuration file */ ! 86: ! 87: strcpy(devname,"/dev/bsc"); /* default device name */ ! 88: ! 89: /* set defaults for printer */ ! 90: buffered = YES; ! 91: ctype = 1; /* default to 3271 control unit */ ! 92: linesperpage=60; /* 60 lines per page */ ! 93: outtype = 'P'; /* printer destination is a pipe (program) */ ! 94: strcpy(output,"/usr/bin/lpr"); /* program to pipe print output to */ ! 95: prtype = 4; /* 3284 printer is default printer type */ ! 96: tprint = NO; /* text print option for 3288 only */ ! 97: vfc = YES; /* does printer have vertical forms unit? */ ! 98: ! 99: /* read host configuration file for actual parameters */ ! 100: if ((fptr = fopen(cfgfile,"r")) == (FILE *)0) { ! 101: fprintf(stderr, ! 102: "em3280: can't open <%s> configuration file\n",hostname); ! 103: return(1); } ! 104: ! 105: while ((fgets(cline,sizeof cline,fptr)) != NULL) { ! 106: ++counter; ! 107: cline[strlen(cline)-1] = '\0'; ! 108: ! 109: if (strncmp(cline,"BUFFERED=",9) == 0) { ! 110: pos = &cline[9]; ! 111: buffered = (strncmp(pos,"YES",3))?0:1; ! 112: continue; ! 113: } ! 114: ! 115: if (strncmp(cline,"CODE=",5) == 0) { ! 116: if(strcmp(&cline[5],"ASCII") != 0 && ! 117: strcmp(&cline[5],"EBCDIC") != 0) ! 118: param_err("CODE",cfgfile); ! 119: ascii = strcmp(&cline[5],"ASCII") == 0?BSCASCII:NO; ! 120: continue; ! 121: } ! 122: ! 123: if (strncmp(cline,"CTYPE=",6) == 0) { ! 124: pos = &cline[6]; ! 125: ctype = atoi(pos); ! 126: if (ctype != 1 && ctype != 5) { ! 127: param_err("CTYPE",cfgfile); ! 128: exit(0); ! 129: } ! 130: continue; ! 131: } ! 132: ! 133: if (strncmp(cline,"DEVICE=",7) == 0) { ! 134: gninit(&cline[7]); /* initialize getnext */ ! 135: continue; ! 136: } ! 137: ! 138: if(strncmp(cline,"DUPLEX=",7) == 0) { ! 139: if (strcmp(&cline[7],"HALF") != 0 && ! 140: strcmp(&cline[7],"FULL") != 0) ! 141: param_err("DUPLEX",cfgfile); ! 142: fulldup =strcmp(&cline[7],"HALF")==0?NO:BSCFDX; ! 143: continue; } ! 144: ! 145: if (strncmp(cline,"IDCHECK=",8) ==0) { ! 146: strcpy(p.b_hostid,&cline[8]); ! 147: chk_hostid = BSCCKHOST; ! 148: continue; } ! 149: ! 150: if (strncmp(cline,"LINESPERPAGE=",13) == 0) { ! 151: pos = &cline[13]; ! 152: linesperpage = atoi(pos); ! 153: continue; ! 154: } ! 155: ! 156: if (strncmp(cline, "MAIL=", 5) == 0) { ! 157: pos = &cline[5]; ! 158: strcpy(sys_admin,pos); ! 159: continue; ! 160: } ! 161: ! 162: if (strncmp(cline,"MPTADDR=",8) == 0) { ! 163: strcpy(p.b_termid,&cline[8]); ! 164: chk_termid = YES; ! 165: pt_to_pt = BSCMPT; ! 166: continue; } ! 167: ! 168: if (strncmp(cline,"NBID=",5) == 0) { ! 169: i = atoi(&cline[5]); ! 170: if (i > 255) ! 171: param_err("NBID",cfgfile); ! 172: else ! 173: p.b_nbid = i; ! 174: continue; } ! 175: ! 176: if (strncmp(cline,"NNAK=",5) == 0) { ! 177: i = atoi(&cline[5]); ! 178: if (i > 255) ! 179: param_err("NNAK",cfgfile); ! 180: else ! 181: p.b_nnak = i; ! 182: continue; } ! 183: ! 184: if (strncmp(cline,"NRETRY=",7) == 0) { ! 185: i = atoi(&cline[7]); ! 186: if (i > 255) ! 187: param_err("NRETRY",cfgfile); ! 188: else ! 189: p.b_nretry = i; ! 190: continue; } ! 191: ! 192: if (strncmp(cline,"NTTD=",5) == 0) { ! 193: i = atoi(&cline[5]); ! 194: if (i > 255) ! 195: param_err("NTTD",cfgfile); ! 196: else ! 197: p.b_nttd = i; ! 198: continue; } ! 199: ! 200: if (strncmp(cline,"NWACK=",6) == 0) { ! 201: i = atoi(&cline[6]); ! 202: if (i > 255) ! 203: param_err("NWACK",cfgfile); ! 204: else ! 205: p.b_nwack = i; ! 206: continue; } ! 207: ! 208: /* format for the OUTPUT parameter is: OUTPUT=<type>,<destination> ! 209: where type may be P (pipe to a program) or F (write to a file or ! 210: device). */ ! 211: if (strncmp(cline,"OUTPUT=",7) == 0) { ! 212: pos = &cline[7]; ! 213: outtype = *pos; ! 214: pos += 2; ! 215: strcpy(output,pos); ! 216: ! 217: if (outtype != 'P' && outtype != 'F') { ! 218: param_err("OUTPUT",cfgfile); ! 219: exit(0); ! 220: } ! 221: ! 222: continue; ! 223: } ! 224: ! 225: if (strncmp(cline,"PTYPE=",6) == 0) { ! 226: pos = &cline[6]; ! 227: prtype = atoi(pos); ! 228: if ((prtype < 6 || prtype > 8) && prtype != 4) { ! 229: param_err("PTYPE",cfgfile); ! 230: exit(0); ! 231: } ! 232: continue; ! 233: } ! 234: ! 235: if (strncmp(cline,"RVIMODE=",8) == 0) { ! 236: if (strcmp(&cline[8],"ABORT") != 0 && ! 237: strcmp(&cline[8],"IGNORE") != 0) ! 238: param_err("RVIMODE",cfgfile); ! 239: rviab =strcmp(&cline[8],"ABORT")==0?BSCRVIABT:NO; ! 240: continue; } ! 241: ! 242: if (strncmp(cline,"TERMID=",7) == 0) { ! 243: strcpy(p.b_termid,&cline[8]); ! 244: chk_termid = YES; ! 245: continue; } ! 246: ! 247: if (strncmp(cline,"TIMEOUT=",8) == 0) { ! 248: p.b_nor = atoi(&cline[8]); ! 249: continue; } ! 250: ! 251: if (strncmp(cline,"TPRINT=",7) == 0) { ! 252: pos = &cline[7]; ! 253: tprint = (strncmp(pos,"YES",3))?0:1; ! 254: continue; ! 255: } ! 256: if (strncmp(cline,"VFC=",4) == 0) { ! 257: pos = &cline[4]; ! 258: vfc = (strncmp(pos,"YES",3))?0:1; ! 259: continue; ! 260: } ! 261: /* invalid keyword parameter */ ! 262: fprintf(stderr, ! 263: "em3280 <%s>: Unrecognized keyword, line %d in <%s>\n", ! 264: hostname,counter,cfgfile); ! 265: } ! 266: if ((fulldup == BSCFDX) && (pt_to_pt == BSCMPT)) ! 267: fulldup = NO; ! 268: p.b_flags = ascii | fulldup | rviab | primary | chk_hostid | pt_to_pt; ! 269: /* translate termid if one given and ebcdic */ ! 270: if (!ascii && chk_termid) ! 271: ascebc(p.b_termid,strlen(p.b_termid)); ! 272: termid = p.b_termid[0]; /* cluster address */ ! 273: fclose(fptr); ! 274: return(had_error); ! 275: } ! 276: ! 277: char *usr_name; /* ptr returned by getlogin */ ! 278: /* write_aud - write message to audit file */ ! 279: write_aud(type,msg) ! 280: register char *type; ! 281: register char *msg; ! 282: { ! 283: char *getlogin(); /* returns ptr to login name for this ! 284: process */ ! 285: ! 286: if (aud == NULL) return; ! 287: ! 288: /* if first time, get login name */ ! 289: if (usr_name == NULL) ! 290: usr_name = getlogin(); ! 291: if (usr_name == NULL) /* who is this guy, anyway? */ ! 292: usr_name = "unknown"; ! 293: ! 294: /* get current time */ ! 295: currtime = time((long*)0); ! 296: t = localtime(&currtime); ! 297: ! 298: fprintf (aud, "%s %s %02d%02d%02d%02d%02d %s\n", ! 299: usr_name, type, t->tm_year, (t->tm_mon) + 1, ! 300: t->tm_mday, t->tm_hour, t->tm_min, msg); ! 301: /* make sure message gets written out */ ! 302: fflush(aud); ! 303: } ! 304: ! 305: /* param_err -- invalid keyword parameter error */ ! 306: param_err(kword,fname) ! 307: char *kword,*fname; ! 308: { ! 309: fprintf(stderr, ! 310: "em3277 <%s>: Invalid parameter for keyword <%s> in <%s>\n", ! 311: hostname,kword,fname); ! 312: ++had_error; ! 313: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.