|
|
Power 6/32 Unix version 1.21
/* D.L.Buck and Associates, Inc. - January, 1984
*
* COPYRIGHT NOTICE:
* Copyright c 1984 - An unpublished work by
* D.L.Buck and Associates, Inc.
*
* PROPRIETARY RIGHTS NOTICE:
* All rights reserved. This document and program contains
* proprietary information of D.L.Buck and Associates,Inc.
* of San Jose, California, U.S.A., embodying confidential
* information, ideas, and expressions, no part of which
* may be reproduced, or transmitted in any form or by any
* means, electronic, mechanical, or otherwise, without
* the written permission of D.L.Buck and Associates, Inc.
*
* NAME
* get_cnfig
*
* SYNOPSIS
* get_cnfig(cfgfile)
* char *cfgfile
*
* DESCRIPTION
* Get host communications device and printer configuration parameters
* from host's configuration file.
*
*/
#include <stdio.h>
#include "local.h"
#include <bsc/bscio.h>
#include <sys/time.h>
#define YES 1
#define NO 0
extern struct bscio p;
extern char devname[], hostname[];
extern char sys_admin[];
extern int rviab, pt_to_pt, ascii, chk_hostid, chk_termid, primary;
extern char termid;
extern char note[];
extern FILE *aud, *outfd;
extern int prtype,buffered,vfc,tprint,ctype,linesperpage;
extern char outtype; /* type of output destination - P=pipe, F=file */
char output[50]; /* printer output destination */
struct tm *localtime(), *t;
long time(),currtime;
int had_error; /* set to # errors encountered in config file */
get_cnfig(cfgfile)
register char *cfgfile;
{
static char sccsid[] = "@(#)emprcnfig.c 1.4 "; /* sccs id */
FILE *popen(),*fopen();
FILE *fptr; /* file pointer returned by fopen */
register int counter; /* tracks line of config file being read */
register int i; /* general purpose int */
register char *pos; /* convenient line position pointer */
char *index();
char cline[80]; /* contains one configuration line */
/* default b_flags parameter values */
int fulldup = NO;
/* set defaults for communications device */
p.b_blks = 254; /* default block size */
rviab = BSCRVIABT; /* abort on receiving rvi */
p.b_nbid = 0; /* default number of bids limit */
p.b_nnak = 16; /* default number of naks allowed */
p.b_nretry = 15; /* default number of retrys allowed */
p.b_nttd = 150; /* default number of temp. txt delays */
p.b_nwack = 150; /* default number of wacks allowed */
p.b_nor = 30; /* default timeout */
pt_to_pt = NO; /* default to multi-point communications */
chk_hostid = NO; /* don't check hostid */
chk_termid = NO; /* don't check termid */
ascii = NO; /* default transmission code is EBCDIC */
counter = 0; /* current line number within configuration file */
strcpy(devname,"/dev/bsc"); /* default device name */
/* set defaults for printer */
buffered = YES;
ctype = 1; /* default to 3271 control unit */
linesperpage=60; /* 60 lines per page */
outtype = 'P'; /* printer destination is a pipe (program) */
strcpy(output,"/usr/bin/lpr"); /* program to pipe print output to */
prtype = 4; /* 3284 printer is default printer type */
tprint = NO; /* text print option for 3288 only */
vfc = YES; /* does printer have vertical forms unit? */
/* read host configuration file for actual parameters */
if ((fptr = fopen(cfgfile,"r")) == (FILE *)0) {
fprintf(stderr,
"em3280: can't open <%s> configuration file\n",hostname);
return(1); }
while ((fgets(cline,sizeof cline,fptr)) != NULL) {
++counter;
cline[strlen(cline)-1] = '\0';
if (strncmp(cline,"BUFFERED=",9) == 0) {
pos = &cline[9];
buffered = (strncmp(pos,"YES",3))?0:1;
continue;
}
if (strncmp(cline,"CODE=",5) == 0) {
if(strcmp(&cline[5],"ASCII") != 0 &&
strcmp(&cline[5],"EBCDIC") != 0)
param_err("CODE",cfgfile);
ascii = strcmp(&cline[5],"ASCII") == 0?BSCASCII:NO;
continue;
}
if (strncmp(cline,"CTYPE=",6) == 0) {
pos = &cline[6];
ctype = atoi(pos);
if (ctype != 1 && ctype != 5) {
param_err("CTYPE",cfgfile);
exit(0);
}
continue;
}
if (strncmp(cline,"DEVICE=",7) == 0) {
gninit(&cline[7]); /* initialize getnext */
continue;
}
if(strncmp(cline,"DUPLEX=",7) == 0) {
if (strcmp(&cline[7],"HALF") != 0 &&
strcmp(&cline[7],"FULL") != 0)
param_err("DUPLEX",cfgfile);
fulldup =strcmp(&cline[7],"HALF")==0?NO:BSCFDX;
continue; }
if (strncmp(cline,"IDCHECK=",8) ==0) {
strcpy(p.b_hostid,&cline[8]);
chk_hostid = BSCCKHOST;
continue; }
if (strncmp(cline,"LINESPERPAGE=",13) == 0) {
pos = &cline[13];
linesperpage = atoi(pos);
continue;
}
if (strncmp(cline, "MAIL=", 5) == 0) {
pos = &cline[5];
strcpy(sys_admin,pos);
continue;
}
if (strncmp(cline,"MPTADDR=",8) == 0) {
strcpy(p.b_termid,&cline[8]);
chk_termid = YES;
pt_to_pt = BSCMPT;
continue; }
if (strncmp(cline,"NBID=",5) == 0) {
i = atoi(&cline[5]);
if (i > 255)
param_err("NBID",cfgfile);
else
p.b_nbid = i;
continue; }
if (strncmp(cline,"NNAK=",5) == 0) {
i = atoi(&cline[5]);
if (i > 255)
param_err("NNAK",cfgfile);
else
p.b_nnak = i;
continue; }
if (strncmp(cline,"NRETRY=",7) == 0) {
i = atoi(&cline[7]);
if (i > 255)
param_err("NRETRY",cfgfile);
else
p.b_nretry = i;
continue; }
if (strncmp(cline,"NTTD=",5) == 0) {
i = atoi(&cline[5]);
if (i > 255)
param_err("NTTD",cfgfile);
else
p.b_nttd = i;
continue; }
if (strncmp(cline,"NWACK=",6) == 0) {
i = atoi(&cline[6]);
if (i > 255)
param_err("NWACK",cfgfile);
else
p.b_nwack = i;
continue; }
/* format for the OUTPUT parameter is: OUTPUT=<type>,<destination>
where type may be P (pipe to a program) or F (write to a file or
device). */
if (strncmp(cline,"OUTPUT=",7) == 0) {
pos = &cline[7];
outtype = *pos;
pos += 2;
strcpy(output,pos);
if (outtype != 'P' && outtype != 'F') {
param_err("OUTPUT",cfgfile);
exit(0);
}
continue;
}
if (strncmp(cline,"PTYPE=",6) == 0) {
pos = &cline[6];
prtype = atoi(pos);
if ((prtype < 6 || prtype > 8) && prtype != 4) {
param_err("PTYPE",cfgfile);
exit(0);
}
continue;
}
if (strncmp(cline,"RVIMODE=",8) == 0) {
if (strcmp(&cline[8],"ABORT") != 0 &&
strcmp(&cline[8],"IGNORE") != 0)
param_err("RVIMODE",cfgfile);
rviab =strcmp(&cline[8],"ABORT")==0?BSCRVIABT:NO;
continue; }
if (strncmp(cline,"TERMID=",7) == 0) {
strcpy(p.b_termid,&cline[8]);
chk_termid = YES;
continue; }
if (strncmp(cline,"TIMEOUT=",8) == 0) {
p.b_nor = atoi(&cline[8]);
continue; }
if (strncmp(cline,"TPRINT=",7) == 0) {
pos = &cline[7];
tprint = (strncmp(pos,"YES",3))?0:1;
continue;
}
if (strncmp(cline,"VFC=",4) == 0) {
pos = &cline[4];
vfc = (strncmp(pos,"YES",3))?0:1;
continue;
}
/* invalid keyword parameter */
fprintf(stderr,
"em3280 <%s>: Unrecognized keyword, line %d in <%s>\n",
hostname,counter,cfgfile);
}
if ((fulldup == BSCFDX) && (pt_to_pt == BSCMPT))
fulldup = NO;
p.b_flags = ascii | fulldup | rviab | primary | chk_hostid | pt_to_pt;
/* translate termid if one given and ebcdic */
if (!ascii && chk_termid)
ascebc(p.b_termid,strlen(p.b_termid));
termid = p.b_termid[0]; /* cluster address */
fclose(fptr);
return(had_error);
}
char *usr_name; /* ptr returned by getlogin */
/* write_aud - write message to audit file */
write_aud(type,msg)
register char *type;
register char *msg;
{
char *getlogin(); /* returns ptr to login name for this
process */
if (aud == NULL) return;
/* if first time, get login name */
if (usr_name == NULL)
usr_name = getlogin();
if (usr_name == NULL) /* who is this guy, anyway? */
usr_name = "unknown";
/* get current time */
currtime = time((long*)0);
t = localtime(&currtime);
fprintf (aud, "%s %s %02d%02d%02d%02d%02d %s\n",
usr_name, type, t->tm_year, (t->tm_mon) + 1,
t->tm_mday, t->tm_hour, t->tm_min, msg);
/* make sure message gets written out */
fflush(aud);
}
/* param_err -- invalid keyword parameter error */
param_err(kword,fname)
char *kword,*fname;
{
fprintf(stderr,
"em3277 <%s>: Invalid parameter for keyword <%s> in <%s>\n",
hostname,kword,fname);
++had_error;
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.