|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)expfile.c 5.1 (Berkeley) 7/2/83"; ! 3: #endif ! 4: ! 5: #include "uucp.h" ! 6: #include <sys/types.h> ! 7: #include <sys/stat.h> ! 8: ! 9: /******* ! 10: * expfile(file) expand file name ! 11: * char *file; ! 12: * ! 13: * return codes: 0 - Ordinary spool area file ! 14: * 1 - Other normal file ! 15: * FAIL - no Wrkdir name available ! 16: */ ! 17: ! 18: expfile(file) ! 19: char *file; ! 20: { ! 21: register char *fpart, *p; ! 22: char user[20], *up; ! 23: char full[100]; ! 24: int uid; ! 25: ! 26: switch(file[0]) { ! 27: case '/': ! 28: return(1); ! 29: case '~': ! 30: for (fpart = file + 1, up = user; *fpart != '\0' ! 31: && *fpart != '/'; fpart++) ! 32: *up++ = *fpart; ! 33: *up = '\0'; ! 34: /* ll1b.105, mn, Mark Nettleingham, defend against ! 35: * null login name in /etc/passwd ! 36: */ ! 37: if (!*user || gninfo(user, &uid, full) != 0) { ! 38: strcpy(full, PUBDIR); ! 39: } ! 40: ! 41: strcat(full, fpart); ! 42: strcpy(file, full); ! 43: return(1); ! 44: default: ! 45: p = index(file, '/'); ! 46: strcpy(full, Wrkdir); ! 47: strcat(full, "/"); ! 48: strcat(full, file); ! 49: strcpy(file, full); ! 50: if (Wrkdir[0] == '\0') ! 51: return(FAIL); ! 52: else if (p != NULL) ! 53: return(1); ! 54: return(0); ! 55: } ! 56: } ! 57: ! 58: ! 59: /*** ! 60: * isdir(name) check if directory name ! 61: * char *name; ! 62: * ! 63: * return codes: 0 - not directory | 1 - is directory ! 64: */ ! 65: ! 66: isdir(name) ! 67: char *name; ! 68: { ! 69: register int ret; ! 70: struct stat s; ! 71: ! 72: ret = stat(subfile(name), &s); ! 73: if (ret < 0) ! 74: return(0); ! 75: if ((s.st_mode & S_IFMT) == S_IFDIR) ! 76: return(1); ! 77: return(0); ! 78: } ! 79: ! 80: ! 81: /*** ! 82: * mkdirs(name) make all necessary directories ! 83: * char *name; ! 84: * ! 85: * return 0 | FAIL ! 86: */ ! 87: ! 88: mkdirs(name) ! 89: char *name; ! 90: { ! 91: int ret, mask; ! 92: char cmd[100], dir[100]; ! 93: register char *p; ! 94: ! 95: for (p = dir + 1;; p++) { ! 96: strcpy(dir, name); ! 97: if ((p = index(p, '/')) == NULL) ! 98: return(0); ! 99: *p = '\0'; ! 100: if (isdir(dir)) ! 101: continue; ! 102: ! 103: /* rti!trt: add chmod ala 4.1c uucp */ ! 104: sprintf(cmd, "mkdir %s;chmod 0777 %s", dir, dir); ! 105: DEBUG(4, "mkdir - %s\n", dir); ! 106: mask = umask(0); ! 107: ret = shio(cmd, CNULL, CNULL, User); ! 108: umask(mask); ! 109: if (ret != 0) ! 110: return(FAIL); ! 111: } ! 112: } ! 113: ! 114: /*** ! 115: * ckexpf - expfile and check return ! 116: * print error if it failed. ! 117: * ! 118: * return code - 0 - ok; FAIL if expfile failed ! 119: */ ! 120: ! 121: ckexpf(file) ! 122: register char *file; ! 123: { ! 124: ! 125: if (expfile(file) != FAIL) ! 126: return(0); ! 127: ! 128: /* could not expand file name */ ! 129: /* the gwd routine failed */ ! 130: ! 131: fprintf(stderr, "Can't expand filename (%s). Pwd failed.\n", file+1); ! 132: return(FAIL); ! 133: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.