1*48652Sbostic /*- 2*48652Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*48652Sbostic * All rights reserved. 4*48652Sbostic * 5*48652Sbostic * %sccs.include.proprietary.c% 6*48652Sbostic */ 7*48652Sbostic 813644Ssam #ifndef lint 9*48652Sbostic static char sccsid[] = "@(#)expfile.c 5.6 (Berkeley) 04/24/91"; 10*48652Sbostic #endif /* not lint */ 1113644Ssam 1213644Ssam #include "uucp.h" 1313644Ssam #include <sys/stat.h> 1413644Ssam 1523598Sbloom /*LINTLIBRARY*/ 1623598Sbloom 1718620Sralph /* 1818620Sralph * expand file name 1913644Ssam * 2013644Ssam * return codes: 0 - Ordinary spool area file 2113644Ssam * 1 - Other normal file 2213644Ssam * FAIL - no Wrkdir name available 2313644Ssam */ 2413644Ssam 2513644Ssam expfile(file) 2613644Ssam char *file; 2713644Ssam { 2813644Ssam register char *fpart, *p; 2917835Sralph char user[WKDSIZE], *up; 3017131Sralph char full[MAXFULLNAME]; 3113644Ssam int uid; 3213644Ssam 3313644Ssam switch(file[0]) { 3413644Ssam case '/': 3518620Sralph return 1; 3613644Ssam case '~': 3713644Ssam for (fpart = file + 1, up = user; *fpart != '\0' 3823598Sbloom && *fpart != '/'; fpart++) 3913644Ssam *up++ = *fpart; 4013644Ssam *up = '\0'; 4113644Ssam if (!*user || gninfo(user, &uid, full) != 0) { 4213644Ssam strcpy(full, PUBDIR); 4313644Ssam } 4413644Ssam 4513644Ssam strcat(full, fpart); 4613644Ssam strcpy(file, full); 4717835Sralph return 1; 4813644Ssam default: 4913644Ssam p = index(file, '/'); 5017835Sralph strcpy(full, Wrkdir); 5117835Sralph strcat(full, "/"); 5217835Sralph strcat(full, file); 5313644Ssam strcpy(file, full); 5413644Ssam if (Wrkdir[0] == '\0') 5517835Sralph return FAIL; 5613644Ssam else if (p != NULL) 5717835Sralph return 1; 5817835Sralph return 0; 5913644Ssam } 6013644Ssam } 6113644Ssam 6213644Ssam 6318620Sralph /* 6418620Sralph * check if directory name 6513644Ssam * 6613644Ssam * return codes: 0 - not directory | 1 - is directory 6713644Ssam */ 6813644Ssam 6913644Ssam isdir(name) 7013644Ssam char *name; 7113644Ssam { 7213644Ssam register int ret; 7313644Ssam struct stat s; 7413644Ssam 7513644Ssam ret = stat(subfile(name), &s); 7613644Ssam if (ret < 0) 7717835Sralph return 0; 7813644Ssam if ((s.st_mode & S_IFMT) == S_IFDIR) 7917835Sralph return 1; 8017835Sralph return 0; 8113644Ssam } 8213644Ssam 8313644Ssam 8418620Sralph /* 8518620Sralph * make all necessary directories 8613644Ssam * 8718620Sralph * return SUCCESS | FAIL 8813644Ssam */ 8913644Ssam 9013644Ssam mkdirs(name) 9113644Ssam char *name; 9213644Ssam { 9313644Ssam int ret, mask; 9418620Sralph char dir[MAXFULLNAME]; 9513644Ssam register char *p; 9613644Ssam 9713644Ssam for (p = dir + 1;; p++) { 9813644Ssam strcpy(dir, name); 9913644Ssam if ((p = index(p, '/')) == NULL) 10018620Sralph return SUCCESS; 10113644Ssam *p = '\0'; 10213644Ssam if (isdir(dir)) 10313644Ssam continue; 10413644Ssam 10513644Ssam DEBUG(4, "mkdir - %s\n", dir); 10613644Ssam mask = umask(0); 10718620Sralph ret = mkdir(dir, 0777); 10813644Ssam umask(mask); 10913644Ssam if (ret != 0) 11017835Sralph return FAIL; 11113644Ssam } 11217835Sralph /* NOTREACHED */ 11313644Ssam } 11413644Ssam 11518620Sralph /* 11618620Sralph * expfile and check return 11713644Ssam * print error if it failed. 11813644Ssam * 11918620Sralph * return code - SUCCESS - ok; FAIL if expfile failed 12013644Ssam */ 12113644Ssam 12213644Ssam ckexpf(file) 12313644Ssam register char *file; 12413644Ssam { 12513644Ssam 12613644Ssam if (expfile(file) != FAIL) 12718620Sralph return SUCCESS; 12813644Ssam 12913644Ssam /* could not expand file name */ 13013644Ssam /* the gwd routine failed */ 13113644Ssam 13217835Sralph logent("CAN'T EXPAND FILENAME - PWD FAILED", file+1); 13317835Sralph return FAIL; 13413644Ssam } 135