|
|
1.1 ! root 1: /* cvlsys.c: convert the information in L.sys and Permissions to ! 2: * Taylor uucp sys file format. This will also peek into L-devices ! 3: * if we find an ACU entry in our L.sys entry. ! 4: */ ! 5: ! 6: #include <stdio.h> ! 7: #include <string.h> ! 8: #include <ctype.h> ! 9: ! 10: #define PERMISSIONS "/usr/lib/uucp/Permissions" ! 11: #define LSYS "/usr/lib/uucp/L.sys" ! 12: #define TSYS "/usr/lib/uucp/sys" ! 13: ! 14: ! 15: #define MAX 175 ! 16: #define BEHEMOTH 1024 ! 17: ! 18: /* this is what we need to parse from our L.sys entry */ ! 19: ! 20: char system[9]; /* name of system to call/be called by */ ! 21: char calltime[45]; /* valid time(s) to call */ ! 22: char device[10]; /* device to call on */ ! 23: char speed[7]; /* baud rate */ ! 24: char telno[51]; /* phone number */ ! 25: char chat_script[128]; /* chat script to log in with */ ! 26: char acudev[15]; /* store ACU device from L-devices*/ ! 27: char lsys[254]; /* line read from L.sys */ ! 28: ! 29: /* stuff from Permissions file: */ ! 30: ! 31: char request[4]; /* REQUEST files from Permissions */ ! 32: char transfer[4]; /* SEND files from Permissions */ ! 33: char readpath[MAX]; /* READ from Permissions */ ! 34: char no_readpath[MAX]; /* NOREAD from Permissions */ ! 35: char writepath[MAX]; /* WRITE from Permissions */ ! 36: char no_writepath[MAX]; /* NOWRITE from Permissions */ ! 37: char commands[MAX]; /* COMMANDS from Permissions */ ! 38: char myname[10]; /* MYNAME from Permissions */ ! 39: ! 40: char parseline[BEHEMOTH]; /* this will be our concatenated Permissions */ ! 41: ! 42: int getrest(); /* complete concatenating Permissions string */ ! 43: int parseperm(); /* parse a field out of Permissions string */ ! 44: int cvnowritwe(); /* convert NOREAD and NOWRITE to useable format */ ! 45: int lsysentry(); /* read entry from L.sys file */ ! 46: int permentry(); /* read entry from Permissions */ ! 47: int parselsys(); /* parse L.sys entry */ ! 48: int parseperm(); /* parse Permissions entry */ ! 49: int getACU(); /* get ACU device from L-devices */ ! 50: int readperm(); /* read Permissions file */ ! 51: int printsys(); /* write sys file entry */ ! 52: ! 53: ! 54: main() ! 55: { ! 56: FILE *infp; ! 57: ! 58: if((infp = fopen(LSYS,"r")) == NULL){ ! 59: printf("Error opening %s for input.\n",LSYS); ! 60: exit(1); ! 61: } ! 62: ! 63: if(getACU()){ ! 64: printf("failed to find ACU device!\n"); ! 65: exit(1); ! 66: } ! 67: ! 68: while(lsysentry(infp)){ ! 69: if(lsys[0] != '#'){ /* we don't want to process a comment */ ! 70: readperm(system); /* get Permissions information */ ! 71: printsys(); /* print sys file entry */ ! 72: lsys[0] = '\0'; /* the terminator... he's back */ ! 73: }else{ ! 74: printf("Skipping comment line in L.sys\n"); ! 75: } ! 76: } ! 77: ! 78: fclose(infp); ! 79: } ! 80: ! 81: ! 82: /* lsysentry(): read a line from L.sys and pass it on to be parsed ! 83: * into sys entries for use by Taylor uucp. ! 84: */ ! 85: ! 86: lsysentry(infp) ! 87: FILE *infp; ! 88: { ! 89: ! 90: char next_line[80]; /* dummy for possible line continuation */ ! 91: ! 92: if(fgets(lsys,sizeof(lsys),infp) == NULL){ ! 93: return(0); /* probably hit EOF */ ! 94: } ! 95: #ifdef DEBUG ! 96: printf("got %s",lsys); ! 97: #endif ! 98: if(lsys[0] == '#'){ /* skip comments */ ! 99: return(1); ! 100: } ! 101: ! 102: ! 103: /* check for line continuation. we will read the next line and ! 104: * concatenate it to the just read lsys line. ! 105: */ ! 106: ! 107: if(lsys[strlen(lsys) -2] == 92){ /* 92 = \ */ ! 108: if(fgets(next_line, sizeof(next_line),infp) == NULL){ ! 109: printf("Error reading continued line in %s.\n",LSYS); ! 110: exit(1); ! 111: }else{ ! 112: /* the next to last character should be the line continuation ! 113: * character followed by a newline. We'll just terminate our ! 114: * our string where we expect the continuation to be. ! 115: */ ! 116: lsys[strlen(lsys) -2] = '\0'; ! 117: strcat(lsys,next_line); ! 118: } ! 119: #ifdef DEBUG ! 120: printf("Line continuation detected. Just added:\n"); ! 121: printf("%s",next_line); ! 122: printf("%s",lsys); ! 123: #endif ! 124: } ! 125: ! 126: return(parselsys(lsys)); ! 127: } ! 128: ! 129: ! 130: /* parselsys(): parses the lsys line just read into the fields needed ! 131: * to build a Taylor sys entry. ! 132: */ ! 133: ! 134: parselsys(lsys) ! 135: char *lsys; ! 136: { ! 137: char *ptrlsys; ! 138: char *ptrlentry; ! 139: ! 140: strcpy(system,""); ! 141: strcpy(calltime,""); ! 142: strcpy(device,""); ! 143: strcpy(speed,""); ! 144: strcpy(telno,""); ! 145: strcpy(chat_script,""); ! 146: ! 147: ptrlsys = lsys; ! 148: ! 149: /* parse out system name */ ! 150: ptrlentry = system; ! 151: *ptrlentry = '\0'; ! 152: while(!isspace(*ptrlsys)) ! 153: *ptrlentry++ = *ptrlsys++; ! 154: *ptrlentry = '\0'; ! 155: ! 156: printf("Converting L.sys and Permissions entries for system %s.\n", ! 157: system); ! 158: ! 159: while(isspace(*ptrlsys++)) /* skip whitespace */ ! 160: ; ! 161: ! 162: /* get calltime */ ! 163: ptrlentry = calltime; ! 164: *ptrlentry = '\0'; ! 165: ! 166: ptrlsys--; ! 167: ! 168: while(!isspace(*ptrlsys)){ ! 169: *ptrlentry++ = *ptrlsys++; ! 170: } ! 171: *ptrlentry = '\0'; ! 172: ! 173: while(isspace(*ptrlsys++)) /* skip whitespace */ ! 174: ; ! 175: ! 176: ptrlsys--; ! 177: ! 178: /* get our device */ ! 179: ptrlentry = device; ! 180: *ptrlentry = '\0'; ! 181: while(!isspace(*ptrlsys)) ! 182: *ptrlentry++ = *ptrlsys++; ! 183: *ptrlentry = '\0'; ! 184: ! 185: /* if this is a modem, which would be indicated by ACU in this field, ! 186: * then copy the name of the ACU device previously fetched into device ! 187: */ ! 188: ! 189: if(device[0] == 'A'){ ! 190: if(0 == strcmp(acudev,NULL)){ ! 191: printf("FATAL Configuration error. No ACU device was.\n"); ! 192: printf("found in L-devices, yet you have defined an\n"); ! 193: printf("L.sys entry with an ACU device. Aborting...\n"); ! 194: exit(1); ! 195: } ! 196: strcpy(device, acudev); ! 197: } ! 198: ! 199: ! 200: while(isspace(*ptrlsys++)) /* skip whitespace */ ! 201: ; ! 202: ! 203: ! 204: ptrlsys--; ! 205: ! 206: /* get the speed (baud rate) */ ! 207: ptrlentry = speed; ! 208: *ptrlentry = '\0'; ! 209: while(!isspace(*ptrlsys)) ! 210: *ptrlentry++ = *ptrlsys++; ! 211: *ptrlentry = '\0'; ! 212: ! 213: while(isspace(*ptrlsys++)) /* skip whitespace */ ! 214: ; ! 215: ! 216: ! 217: ptrlsys--; ! 218: ! 219: /* get telephone number */ ! 220: ptrlentry = telno; ! 221: while(!isspace(*ptrlsys)) ! 222: *ptrlentry++ = *ptrlsys++; ! 223: *ptrlentry = '\0'; ! 224: ! 225: /* if no telephone number is found, then make sure the string is NULL */ ! 226: if(strcmp(telno,"\"\"") == 0) ! 227: strcpy(telno,""); ! 228: ! 229: while(isspace(*ptrlsys++)) /* skip whitespace */ ! 230: ; ! 231: ! 232: /* the rest is our chat script. We copy up to the newline. */ ! 233: ptrlentry = chat_script; ! 234: *ptrlentry = '\0'; ! 235: ptrlsys--; ! 236: while(*ptrlsys != '\n'){ ! 237: *ptrlentry++ = *ptrlsys++; ! 238: } ! 239: *ptrlentry = '\0'; ! 240: ! 241: #ifdef DEBUG ! 242: printf("system %s\n",system); ! 243: printf("time %s\n",calltime); ! 244: printf("port %s\n",device); ! 245: printf("baud %s\n",speed); ! 246: printf("phone %s\n",telno); ! 247: printf("chat {%s}\n", chat_script); ! 248: #endif ! 249: ! 250: return(1); ! 251: } ! 252: ! 253: ! 254: ! 255: /* printsys(): print out system information to Taylor sys file */ ! 256: ! 257: printsys() ! 258: { ! 259: ! 260: FILE *outfp; ! 261: ! 262: if((outfp = fopen(TSYS,"a")) == NULL){ ! 263: printf("Could not open %s for writing!\n",TSYS); ! 264: exit(1); ! 265: } ! 266: ! 267: fprintf(outfp,"system %s\n",system); ! 268: fprintf(outfp,"time %s\n",calltime); ! 269: fprintf(outfp,"baud %s\n",speed); ! 270: fprintf(outfp,"port %s\n",device); ! 271: ! 272: if(telno[0] != '\0') ! 273: fprintf(outfp,"phone %s\n",telno); ! 274: ! 275: fprintf(outfp,"chat %s\n",chat_script); ! 276: fprintf(outfp,"protocol g\nprotocol-parameter g window 3\n"); ! 277: fprintf(outfp,"protocol-parameter g packet-size 64\n"); ! 278: ! 279: if(myname[0] != '\0') ! 280: fprintf(outfp,"myname %s\n", myname); ! 281: ! 282: if(request[0] != '\0') ! 283: fprintf(outfp,"request %s\n",request); ! 284: ! 285: if(transfer[0] != '\0') ! 286: fprintf(outfp,"transfer %s\n",transfer); ! 287: ! 288: if(readpath[0] != '\0') ! 289: fprintf(outfp,"remote-send %s %s\n",readpath, no_readpath); ! 290: ! 291: if(writepath[0] != '\0') ! 292: fprintf(outfp,"remote-receive %s %s\n",writepath, no_writepath); ! 293: ! 294: if(commands[0] != '\0') ! 295: fprintf(outfp,"commands %s\n",commands); ! 296: ! 297: fprintf(outfp,"\n"); ! 298: fclose(outfp); ! 299: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.