|
|
1.1 ! root 1: /* readperm(): Read the Permissions file, looking for the entry that matches ! 2: * our system. Continue reading and concatenating until we ! 3: * hit EOF or the next MACHINE line. ! 4: */ ! 5: ! 6: #include <stdio.h> ! 7: #include <string.h> ! 8: #include <ctype.h> ! 9: ! 10: #define MAX 175 ! 11: #define PERMISSIONS "/usr/lib/uucp/Permissions" ! 12: ! 13: /* fields needed for our sys file entry: */ ! 14: ! 15: extern char request[]; /* REQUEST files from Permissions */ ! 16: extern char transfer[]; /* SEND files from Permissions */ ! 17: extern char readpath[]; /* READ from Permissions */ ! 18: extern char no_readpath[]; /* NOREAD from Permissions */ ! 19: extern char writepath[]; /* WRITE from Permissions */ ! 20: extern char no_writepath[]; /* NOWRITE from Permissions */ ! 21: extern char commands[]; /* COMMANDS from Permissions */ ! 22: extern char myname[]; /* MYNAME from Permissions */ ! 23: ! 24: extern char parseline[]; /* this will be our concatenated Permissions */ ! 25: ! 26: extern int getrest(); /* complete concatenating Permissions string */ ! 27: extern int parseperm(); /* parse a field out of Permissions string */ ! 28: extern int cvnowritwe(); /* convert NOREAD and NOWRITE to useable format */ ! 29: ! 30: readperm(sys) ! 31: char *sys; ! 32: { ! 33: ! 34: FILE *infp; ! 35: char rdline[MAX]; /* line read from Permissions */ ! 36: char chksys[15]; /* used to look for MACHINE= */ ! 37: char chkmch[8]; /* holds MACHINE */ ! 38: char *endname; /* Points to end of parsed name */ ! 39: ! 40: if( (infp = fopen(PERMISSIONS,"r")) == NULL){ ! 41: printf("Error opening %s!\n",PERMISSIONS); ! 42: exit(1); ! 43: } ! 44: ! 45: /* initialize our stuff */ ! 46: ! 47: strcpy(parseline,""); ! 48: strcpy(request,""); ! 49: strcpy(transfer,""); ! 50: strcpy(readpath,""); ! 51: strcpy(no_readpath,""); ! 52: strcpy(writepath,""); ! 53: strcpy(no_writepath,""); ! 54: strcpy(commands,""); ! 55: strcpy(myname,""); ! 56: ! 57: ! 58: /* Read Permissions one line at a time until we find a ! 59: * line that has MACHINE="SYSTEM". ! 60: */ ! 61: strcpy(chkmch,"MACHINE="); ! 62: sprintf(chksys,"%s%s",chkmch,sys); ! 63: ! 64: while(fgets(rdline,MAX,infp)!= NULL){ ! 65: if((endname = strstr(rdline, chksys)) != NULL ! 66: && (isspace(endname[strlen(chksys)]) ! 67: || endname == '\0') ! 68: ){ /* matched MACHINE=sys */ ! 69: strcpy(parseline, rdline); ! 70: getrest(infp); /* get rest of Permissions entrry */ ! 71: break; ! 72: } ! 73: } ! 74: ! 75: fclose(infp); ! 76: ! 77: if(parseline[0] == '\0'){ /* no line found */ ! 78: printf("No Permissions entry for system %s found!\n",sys); ! 79: printf("Default settings will be assigned to this site.\n"); ! 80: return; ! 81: } ! 82: ! 83: ! 84: /* we will now call parseperm(), giving it a pointer to the Permissions ! 85: * line, pointer to the Permissions field to find and pointer to ! 86: * sys field to fill. We pray that NOREAD and NOWRITE follow ! 87: * READ= and WRITE=, or we will not correctly parse this entry. ! 88: */ ! 89: ! 90: parseperm(parseline, "MYNAME",myname); ! 91: parseperm(parseline, "COMMANDS", commands); ! 92: parseperm(parseline, "READ",readpath); ! 93: parseperm(parseline, "NOREAD",no_readpath); ! 94: parseperm(parseline, "WRITE",writepath); ! 95: parseperm(parseline, "NOWRITE",no_writepath); ! 96: parseperm(parseline, "REQUEST",request); ! 97: parseperm(parseline, "SENDFILES",transfer); ! 98: ! 99: ! 100: if(no_readpath[0] != '\0') ! 101: cvnowrite(no_readpath); ! 102: ! 103: if(no_writepath[0] != '\0') ! 104: cvnowrite(no_writepath); ! 105: ! 106: ! 107: #ifdef DEBUG ! 108: printf("myname is {%s} ",myname); ! 109: printf("commands are {%s}\n",commands); ! 110: printf("read paths are {%s} {%s}\n",readpath, no_readpath); ! 111: printf("write paths are {%s} {%s}\n",writepath, no_writepath); ! 112: printf("transfer {%s} request {%s}\n",transfer, request); ! 113: #endif ! 114: ! 115: } ! 116: ! 117: ! 118: /* getrest(): get the rest of the Permissions entry for the current ! 119: * system. We will stop concatenating when we find the ! 120: * next MACHINE line. ! 121: */ ! 122: ! 123: ! 124: getrest(infp) ! 125: FILE *infp; ! 126: { ! 127: char rdline[MAX]; ! 128: ! 129: while((fgets(rdline, MAX, infp))!= NULL){ ! 130: if(strstr(rdline,"MACHINE") == NULL){ ! 131: strcat(parseline, rdline); ! 132: }else{ ! 133: return; ! 134: } ! 135: } ! 136: } ! 137: ! 138: ! 139: ! 140: /* parseperm(): given a Permissions line, field to look for and field ! 141: * to fill, find the field in the line and fill it for sys ! 142: */ ! 143: ! 144: parseperm(line, srchname, fillname) ! 145: char *line; /* master permissions entry */ ! 146: char *srchname; /* Permissions field we are looking for */ ! 147: char *fillname; /* sys field to fill with Permissions data */ ! 148: ! 149: { ! 150: char *fldptr; /* point to field we will fill. */ ! 151: char *lineptr; /* point to master Permissions line */ ! 152: ! 153: ! 154: /* set pointer to field to fill for sys file */ ! 155: fldptr = fillname; ! 156: *fldptr = '\0'; ! 157: ! 158: if((lineptr = strstr(line,srchname)) == NULL){ ! 159: #ifdef DEBUG ! 160: printf("No %s entry found.\n", srchname); ! 161: #endif /* DEBUG */ ! 162: return; ! 163: }else{ ! 164: /* Check to make sure it's not a NOxxxxx variation */ ! 165: if(!isspace(*(lineptr - 1)) && srchname[0] != 'N') { ! 166: if((lineptr = strstr(lineptr + strlen(srchname) , srchname)) == NULL) ! 167: return; ! 168: } ! 169: lineptr += strlen(srchname); ! 170: while(isspace(*lineptr)) ! 171: lineptr++; ! 172: if(*lineptr == '=') ! 173: lineptr++; ! 174: while(isspace(*lineptr)) ! 175: lineptr++; ! 176: while(!isspace(*lineptr) && *lineptr != EOF){ ! 177: if(*lineptr == ':'){ /* convert colon to space */ ! 178: *lineptr = ' '; ! 179: } ! 180: *fldptr++ = *lineptr++; ! 181: } ! 182: *fldptr = '\0'; ! 183: } ! 184: ! 185: return; ! 186: } ! 187: ! 188: ! 189: /* cvnowrite(): convert the NOWRITE and NOREAD strings to something ! 190: * useable in the sys file. In this instance, we are ! 191: * going to walk down the string and convert SPACES ! 192: * to SPACE! ( !) ! 193: */ ! 194: ! 195: cvnowrite(line) ! 196: char *line; ! 197: { ! 198: char *ptrline; ! 199: char *ptrnew; ! 200: char newline[MAX]; ! 201: ! 202: ptrline = line; ! 203: ptrnew = newline; ! 204: *ptrnew++='!'; /* set up our string to begin with '!' */ ! 205: ! 206: while(*ptrline != '\0'){ ! 207: if(*ptrline == ' '){ ! 208: *ptrnew++ = ' '; ! 209: *ptrnew++ = '!'; ! 210: *ptrline++; ! 211: }else{ ! 212: *ptrnew++ = *ptrline++; ! 213: } ! 214: } ! 215: *ptrnew = '\0'; ! 216: ! 217: strcpy(line, newline); /* copy new line over old one */ ! 218: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.