|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <ctype.h> ! 3: #include "mail.h" ! 4: #include "string.h" ! 5: #include "aux.h" ! 6: ! 7: #define GFLIST "forwardlist" ! 8: #define LFLIST "forwardlist.lo" ! 9: ! 10: /* predeclared */ ! 11: static int ok(); ! 12: static int okfile(); ! 13: ! 14: /* return true if ok to forward for this address. ! 15: * `addr' is a list of ! delimited systems. ! 16: */ ! 17: extern int ! 18: ok_to_forward(addr) ! 19: char *addr; ! 20: { ! 21: char system[128]; ! 22: char *ap, *sp; ! 23: static FILE *lfp; ! 24: static FILE *gfp; ! 25: ! 26: for (ap = addr; *ap; ap++){ ! 27: for (sp = system; *ap && *ap!='!'; sp++, ap++) ! 28: *sp = *ap; ! 29: *sp = '\0'; ! 30: if (*ap != '!') ! 31: return 1; ! 32: switch(lookup(system, LFLIST, &lfp, GFLIST, &gfp)){ ! 33: case -1: ! 34: /* no files */ ! 35: return 1; ! 36: case 1: ! 37: /* found */ ! 38: break; ! 39: case 0: ! 40: /* not found */ ! 41: return 0; ! 42: default: ! 43: /* call presotto */ ! 44: break; ! 45: } ! 46: } ! 47: return 1; ! 48: } ! 49: ! 50: /* return 1 if name found in one of the files ! 51: * 0 if name not found in one of the files ! 52: * -1 if neither file exists ! 53: */ ! 54: int ! 55: lookup(cp, local, lfpp, global, gfpp) ! 56: char *cp; ! 57: char *local; ! 58: FILE **lfpp; ! 59: char *global; ! 60: FILE **gfpp; ! 61: { ! 62: static string *file = NULL; ! 63: ! 64: if (local) { ! 65: if (file == NULL) ! 66: file = s_new(); ! 67: abspath(local, UPASROOT, s_restart(file)); ! 68: if (*lfpp != NULL || (*lfpp = fopen(s_to_c(file), "r")) != NULL) { ! 69: fseek(*lfpp, (long)0, 0); ! 70: if (okfile(cp, *lfpp)) ! 71: return 1; ! 72: } else ! 73: local = 0; ! 74: } ! 75: if (global) { ! 76: abspath(global, UPASROOT, s_restart(file)); ! 77: if (*gfpp != NULL || (*gfpp = fopen(s_to_c(file), "r")) != NULL) { ! 78: fseek(*gfpp, (long)0, 0); ! 79: if (okfile(cp, *gfpp)) ! 80: return 1; ! 81: } else ! 82: global = 0; ! 83: } ! 84: return (local || global)? 0 : -1; ! 85: } ! 86: ! 87: static ! 88: okfile(cp, fp) ! 89: char *cp; ! 90: FILE *fp; ! 91: { ! 92: char buf[128]; ! 93: int len; ! 94: char *bp; ! 95: int c; ! 96: ! 97: len = strlen(cp); ! 98: ! 99: /* one iteration per system name in the file */ ! 100: while (fgets (buf, sizeof buf, fp) != NULL) { ! 101: buf[strlen(buf)-1] = '\0'; ! 102: for(bp=buf; *bp;){ ! 103: while(isspace(*bp) || *bp==',') ! 104: bp++; ! 105: if (strncmp (bp, cp, len) == 0) { ! 106: c = *(bp+len); ! 107: if(isspace(c) || c=='\0' || c==',') ! 108: return 1; ! 109: } ! 110: while(*bp && (!isspace(*bp)) && *bp!=',') ! 111: bp++; ! 112: } ! 113: } ! 114: ! 115: /* didn't find it, prohibit forwarding */ ! 116: return 0; ! 117: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.