113644Ssam #ifndef lint 2*18620Sralph static char sccsid[] = "@(#)expfile.c 5.4 (Berkeley) 04/10/85"; 313644Ssam #endif 413644Ssam 513644Ssam #include "uucp.h" 613644Ssam #include <sys/stat.h> 713644Ssam 8*18620Sralph /* 9*18620Sralph * expand file name 1013644Ssam * 1113644Ssam * return codes: 0 - Ordinary spool area file 1213644Ssam * 1 - Other normal file 1313644Ssam * FAIL - no Wrkdir name available 1413644Ssam */ 1513644Ssam 1613644Ssam expfile(file) 1713644Ssam char *file; 1813644Ssam { 1913644Ssam register char *fpart, *p; 2017835Sralph char user[WKDSIZE], *up; 2117131Sralph char full[MAXFULLNAME]; 2213644Ssam int uid; 2313644Ssam 2413644Ssam switch(file[0]) { 2513644Ssam case '/': 26*18620Sralph return 1; 2713644Ssam case '~': 2813644Ssam for (fpart = file + 1, up = user; *fpart != '\0' 29*18620Sralph && *fpart != '/' && up < user+sizeof(user)-1; fpart++) 3013644Ssam *up++ = *fpart; 3113644Ssam *up = '\0'; 3213644Ssam if (!*user || gninfo(user, &uid, full) != 0) { 3313644Ssam strcpy(full, PUBDIR); 3413644Ssam } 3513644Ssam 3613644Ssam strcat(full, fpart); 3713644Ssam strcpy(file, full); 3817835Sralph return 1; 3913644Ssam default: 4013644Ssam p = index(file, '/'); 4117835Sralph strcpy(full, Wrkdir); 4217835Sralph strcat(full, "/"); 4317835Sralph strcat(full, file); 4413644Ssam strcpy(file, full); 4513644Ssam if (Wrkdir[0] == '\0') 4617835Sralph return FAIL; 4713644Ssam else if (p != NULL) 4817835Sralph return 1; 4917835Sralph return 0; 5013644Ssam } 5113644Ssam } 5213644Ssam 5313644Ssam 54*18620Sralph /* 55*18620Sralph * check if directory name 5613644Ssam * 5713644Ssam * return codes: 0 - not directory | 1 - is directory 5813644Ssam */ 5913644Ssam 6013644Ssam isdir(name) 6113644Ssam char *name; 6213644Ssam { 6313644Ssam register int ret; 6413644Ssam struct stat s; 6513644Ssam 6613644Ssam ret = stat(subfile(name), &s); 6713644Ssam if (ret < 0) 6817835Sralph return 0; 6913644Ssam if ((s.st_mode & S_IFMT) == S_IFDIR) 7017835Sralph return 1; 7117835Sralph return 0; 7213644Ssam } 7313644Ssam 7413644Ssam 75*18620Sralph /* 76*18620Sralph * make all necessary directories 7713644Ssam * 78*18620Sralph * return SUCCESS | FAIL 7913644Ssam */ 8013644Ssam 8113644Ssam mkdirs(name) 8213644Ssam char *name; 8313644Ssam { 8413644Ssam int ret, mask; 85*18620Sralph char dir[MAXFULLNAME]; 8613644Ssam register char *p; 8713644Ssam 8813644Ssam for (p = dir + 1;; p++) { 8913644Ssam strcpy(dir, name); 9013644Ssam if ((p = index(p, '/')) == NULL) 91*18620Sralph return SUCCESS; 9213644Ssam *p = '\0'; 9313644Ssam if (isdir(dir)) 9413644Ssam continue; 9513644Ssam 9613644Ssam DEBUG(4, "mkdir - %s\n", dir); 9713644Ssam mask = umask(0); 98*18620Sralph ret = mkdir(dir, 0777); 9913644Ssam umask(mask); 10013644Ssam if (ret != 0) 10117835Sralph return FAIL; 10213644Ssam } 10317835Sralph /* NOTREACHED */ 10413644Ssam } 10513644Ssam 106*18620Sralph /* 107*18620Sralph * expfile and check return 10813644Ssam * print error if it failed. 10913644Ssam * 110*18620Sralph * return code - SUCCESS - ok; FAIL if expfile failed 11113644Ssam */ 11213644Ssam 11313644Ssam ckexpf(file) 11413644Ssam register char *file; 11513644Ssam { 11613644Ssam 11713644Ssam if (expfile(file) != FAIL) 118*18620Sralph return SUCCESS; 11913644Ssam 12013644Ssam /* could not expand file name */ 12113644Ssam /* the gwd routine failed */ 12213644Ssam 12317835Sralph logent("CAN'T EXPAND FILENAME - PWD FAILED", file+1); 12417835Sralph return FAIL; 12513644Ssam } 126