|
|
1.1 ! root 1: /* ! 2: setup.c ! 3: ! 4: support procedures used in setting up the network ! 5: ! 6: */ ! 7: ! 8: # include "defs.h" ! 9: ! 10: char logfile[] = LOGFILE; ! 11: ! 12: /* global variables */ ! 13: struct daemonparms netd; ! 14: ! 15: /* ! 16: called in netdaemon and debugging software ! 17: handles parameter lists to setup ! 18: remote machine and pipes ! 19: */ ! 20: setupdaemon(argc,argv) ! 21: char **argv;{ ! 22: long timev; ! 23: int timei; ! 24: FILE *cfile; ! 25: ! 26: parseargs(argc,argv); ! 27: ! 28: cfile = fopen(INITFILE,"r"); ! 29: rdnetfile(cfile); ! 30: fclose(cfile); ! 31: err("remote %c local %c link %s inspeed %d outspeed %d length %d\n", ! 32: remote,local,netd.dp_device,netd.dp_inspeed, ! 33: netd.dp_outspeed,netd.dp_datasize); ! 34: err("debug %d time %d count %d onlyuid %d usehispeed=%d hispeedlink='%s'\n", ! 35: debugflg,netd.dp_atime, netd.dp_maxbread,netd.dp_onlyuid, ! 36: netd.dp_usehispeed, netd.dp_hispeedlink); ! 37: err("sendonly %c rcvonly %c pipesim %c\n", ! 38: chfromf(netd.dp_sndorcv < 0),chfromf(netd.dp_sndorcv > 0), ! 39: chfromf(netd.dp_pipesim)); ! 40: setup(netd.dp_device); ! 41: timev = gettime(); ! 42: timei = timev >> 16; ! 43: srand(timei); ! 44: } ! 45: /* ! 46: ! 47: see comment in netdaemon.c about the arguments ! 48: ! 49: */ ! 50: parseargs(argc,argv) ! 51: char **argv; { ! 52: char stemp[30]; ! 53: remote = 0; ! 54: while(argc > 1 && argv[1][0] == '-'){ ! 55: argc--; argv++; ! 56: switch(argv[0][1]){ ! 57: case '8': ! 58: netd.dp_use8bit = 1; ! 59: break; ! 60: case 'd': ! 61: debugflg = 1; ! 62: break; ! 63: case 'h': ! 64: netd.dp_usehispeed = 1; ! 65: break; ! 66: case 'm': ! 67: harg(stemp,&argc,&argv); ! 68: remote = lookup(stemp); ! 69: break; ! 70: case 'o': /* only */ ! 71: if(argv[0][2] == 's') /* only send */ ! 72: netd.dp_sndorcv = -1; ! 73: else if(argv[0][2] == 'r') /* only receive */ ! 74: netd.dp_sndorcv = 1; ! 75: else if(argv[0][2] == 'u') /* only uid num */ ! 76: netd.dp_onlyuid = atoi(argv[1]); ! 77: break; ! 78: case 'p': ! 79: harg(stemp,&argc,&argv); ! 80: netd.dp_datasize = atol(stemp); ! 81: break; ! 82: case 'r': ! 83: harg(stemp,&argc,&argv); ! 84: netd.dp_rdfile = fdopen(atoi(stemp),"r"); ! 85: netd.dp_pipesim++; ! 86: break; ! 87: case 'w': ! 88: harg(stemp,&argc,&argv); ! 89: netd.dp_pwritefd = atoi(stemp); ! 90: netd.dp_pipesim++; ! 91: break; ! 92: /* ignore unknown options */ ! 93: } ! 94: } ! 95: if(remote == 0){ ! 96: fprintf(stderr,"Error- must specify machine - use -m option\n"); ! 97: exit(EX_USAGE); ! 98: } ! 99: } ! 100: /* ! 101: set the correct mode on the link device ! 102: */ ! 103: setup(str) ! 104: char *str; { ! 105: struct sgttyb stt; ! 106: # ifdef RAND ! 107: struct { ! 108: int t_xflags; ! 109: char t_col; ! 110: char t_delct; ! 111: char t_outqc_cc; ! 112: char t_rawqc_cc; ! 113: } exstt; ! 114: #define OUT8BIT 01 /* All 8 bits on output */ ! 115: #define IN8BIT 02 /* All 8 bits on input */ ! 116: # endif ! 117: ! 118: initseqno(); ! 119: /* nothing to set up if we're simulating with pipes */ ! 120: if(netd.dp_pipesim)return; ! 121: ! 122: if(netd.dp_usehispeed){ ! 123: str = netd.dp_hispeedlink; ! 124: netd.dp_datasize = SENDLEN - ACKLENGTH; ! 125: } ! 126: if(str == 0 || str[0] == 0){ ! 127: err("invalid net device\n"); ! 128: exit(EX_OSFILE); ! 129: } ! 130: netd.dp_linefd = open(str,2); ! 131: if(netd.dp_linefd < 0){ ! 132: perror(str); ! 133: exit(EX_OSERR); ! 134: } ! 135: /* set exclusive use for line */ ! 136: if(ioctl(netd.dp_linefd,TIOCEXCL,&stt) != 0 || ! 137: gtty(netd.dp_linefd,&stt) < 0){ ! 138: perror(str); ! 139: exit(EX_OSERR); ! 140: } ! 141: stt.sg_ispeed = netd.dp_inspeed; /* user set baud */ ! 142: stt.sg_ospeed = netd.dp_outspeed; /* user-set baud */ ! 143: stt.sg_erase = stt.sg_kill = 0; /* erase and kill off */ ! 144: stt.sg_flags = ANYP; /* even and odd parity, off everything else */ ! 145: if(stty(netd.dp_linefd,&stt) < 0){ ! 146: perror(str); ! 147: exit(EX_OSERR); ! 148: } ! 149: # ifdef RAND ! 150: /* set device into 8-bit mode */ ! 151: if(gtty((2<<8)|netd.dp_linefd,&exstt) < 0){ ! 152: perror(str); ! 153: exit(EX_OSERR); ! 154: } ! 155: exstt.t_xflags = OUT8BIT | IN8BIT; ! 156: if(stty((2<<8)|netd.dp_linefd, &exstt) < 0){ ! 157: perror(str); ! 158: exit(EX_OSERR); ! 159: } ! 160: # endif ! 161: /* set my own line discipline */ ! 162: /* NETLDISC is defined in sgtty.h on the CSVAX */ ! 163: /* setting the line discipline must be done AFTER the sttys */ ! 164: # ifdef NETLDISC ! 165: netd.dp_linedis = NETLDISC; ! 166: if(ioctl(netd.dp_linefd,TIOCSETD,&netd.dp_linedis) != 0){ ! 167: printf("error - line discipline\n"); ! 168: perror(str); ! 169: printf("proceeding...\n"); ! 170: netd.dp_linedis = 0; ! 171: } ! 172: if(netd.dp_linedis){ ! 173: /* set the line into RAW mode */ ! 174: netd.dp_linedis = 0; ! 175: ioctl(netd.dp_linefd,TIOCSETD,&netd.dp_linedis); ! 176: netd.dp_linedis = NETLDISC; ! 177: stt.sg_ispeed = netd.dp_inspeed; /* user set baud */ ! 178: stt.sg_ospeed = netd.dp_outspeed; /* user-set baud */ ! 179: stt.sg_erase = stt.sg_kill = 0; ! 180: stt.sg_flags = ANYP|RAW; /* in raw mode */ ! 181: if(stty(netd.dp_linefd,&stt) < 0){ ! 182: perror(str); ! 183: exit(EX_OSERR); ! 184: } ! 185: ioctl(netd.dp_linefd,TIOCSETD,&netd.dp_linedis); ! 186: } ! 187: # endif ! 188: } ! 189: /*VARARGS0*/ ! 190: error(s,a,b,c,d,e,f,g,h) ! 191: char *s; { ! 192: char buf[10]; ! 193: if(remote != 0) sprintf(buf,"%s",longname(remote)); ! 194: else buf[0] = 0; ! 195: fflush(stdout); ! 196: if(debugflg){ ! 197: fprintf(stderr,s,a,b,c,d,e,f,g,h); ! 198: putc('\n',stderr); ! 199: } ! 200: addtolog(remote,"Err %s: ",buf); ! 201: addtolog(remote,s,a,b,c,d,e,f,g,h); ! 202: addtolog(remote,"\n"); ! 203: } ! 204: /* this is really not right - we should use the rcslog format */ ! 205: /* also, the user must be able to write on the ! 206: public logfile to get error messages such as ! 207: directory not found after he has ! 208: setuid'd from root ! 209: */ ! 210: /*VARARGS0*/ ! 211: addtolog(mach,s,a,b,c,d,e,f,g,h,i,j,k,l,m,n) ! 212: char *s; ! 213: { ! 214: static FILE *log = NULL; ! 215: struct stat statbuf; ! 216: logfile[strlen(logfile)-1] = mach; ! 217: if(log == NULL){ ! 218: if(stat(logfile,&statbuf) < 0)return; ! 219: log = fopen(logfile,"a"); ! 220: } ! 221: if(log == NULL)return; ! 222: fseek(log,0L,2); ! 223: fprintf(log,s,a,b,c,d,e,f,g,h,i,j,k,l,m,n); ! 224: fflush(log); ! 225: debug(s,a,b,c,d,e,f,g,h,i,h,k,l,m,n); ! 226: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.