STATUS xfsetdirs(char *dir, char *frompath, char *intopath) { auto i2 dirflag; auto char *s; char *locbuf; STATUS status; locbuf = XF_REQMEM(MAX_LOC + 1, FALSE); if (dir == NULL || *dir == EOS) { /* Default to current directory. */ status = LOgt(locbuf, &Xf_dir); if(status != OK) { #ifdef UNIX status = LOfakepwd(locbuf, &Xf_dir); #endif if(status != OK) { IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0); return(FAIL); } } dir = NULL; } else { STlcopy(dir, locbuf, MAX_LOC); if (LOfroms(PATH, locbuf, &Xf_dir) != OK) { IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir); return (FAIL); } if (!LOisfull(&Xf_dir)) { auto LOCATION xloc; char xbuf[MAX_LOC + 1]; /* ** path spec. is a relative specification -- we must expand it ** to a full pathname. */ LOcopy(&Xf_dir, xbuf, &xloc); status = LOgt(locbuf, &Xf_dir); if(status != OK) { IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0); return(FAIL); } LOaddpath(&Xf_dir, &xloc, &Xf_dir); } /* LOisdir and LOexist are archaic and should be replaced by LOinfo. */ LOisdir(&Xf_dir, &dirflag); if (dirflag != ISDIR || LOexist(&Xf_dir) != OK) { IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir); return (FAIL); } } LOtos(&Xf_dir, &s); /* the COPY FROM path doesn't have to exist. */ if (frompath != NULL && *frompath != EOS) Xf_from_path = saveloc(frompath); /* the COPY INTO path doesn't have to exist. */ if (intopath != NULL && *intopath != EOS) Xf_into_path = saveloc(intopath); IIUGmsg(ERget(S_XF0064_Unload_Directory_is), FALSE, 1, (PTR)(Xf_into_path == NULL ? s : Xf_into_path)); IIUGmsg(ERget(S_XF0065_Reload_Directory_is), FALSE, 1, (PTR)(Xf_from_path == NULL ? s : Xf_from_path)); return (OK); }
/* ** Name: check_path ** ** Description: ** Function to test the specified path for: ** 1. Valid characters. ** 2. An existing or valid parent directory. ** 3. Write permissions for 2. ** ** Inputs: ** chkpath pointer to the path string for validation. ** eflags flags specifying the actions to be taken. ** ** Outputs: ** None. ** ** Returns: ** OK Path validation successful. ** !OK Path validation failed. ** ** History: ** 27-Jun-2005 (fanra01) ** Created. ** 11-Jul-2005 (fanra01) ** Return a more specific status code. */ static STATUS check_path( char* chkpath, int eflags ) { STATUS status = II_SUCCESSFUL; STATUS rc; int retcode = FAIL; LOCATION tloc; /* target location */ LOCATION wloc; /* working location */ LOCATION cloc; /* working location */ LOINFORMATION linfo; i4 info; char* temp = NULL; char* path = NULL; char* work = NULL; char* curr = NULL; char* d; char* p; char* f; char* e; char* v; char* s; while(TRUE) { /* ** Allocate working area up front. Saves declaring arrays on the ** stack. */ if ((temp = MEreqmem( 0, (MAX_LOC+1) * 8, TRUE, &status )) == NULL) { break; } /* ** Initialize working pointers with memory */ path = temp; work = temp + MAX_LOC + 1; curr = work + MAX_LOC + 1; d = curr + MAX_LOC + 1; p = d + MAX_LOC + 1; f = p + MAX_LOC + 1; e = f + MAX_LOC + 1; v = e + MAX_LOC + 1; /* ** Initialize a location structure with the specified path ** string. */ if ((eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM)) && (LOfroms( PATH, chkpath, &tloc ) != OK)) { status = II_BAD_PATH; break; } /* ** Perform an illegal characters check, for all path tests. */ if ((eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM)) && (check_path_chars( &tloc, &rc ))) { switch(rc) { case LO_BAD_DEVICE: status = II_BAD_PATH; break; case LO_NOT_PATH: case LO_NOT_FILE: default: status = II_INVAL_CHARS_IN_PATH; break; } break; } /* ** Duplicate the specified path location into a work location. */ LOcopy( &tloc, work, &wloc ); /* ** Create an empty location for the current working device, ** split the target path into components and ** create a location of the target device. */ if ((eflags & (II_CHK_PATHDIR | II_CHK_PATHPERM)) && ((status = LOfroms( PATH, curr, &cloc )) == OK) && ((status = LOdetail( &wloc, d, p, f, e, v )) == OK) && ((status = LOcompose( d, CURR_DIR, NULL, NULL, NULL, &cloc )) == OK)) { /* ** Save the current working directory */ LOsave(); /* ** Change working path to the target device */ status = LOchange( &cloc ); /* ** Starting with the whole path work backwards looking for ** a valid directory */ for (s=work, info=0; (status == OK) && (retcode != OK) && (s != NULL); ) { if ((status = LOfroms( PATH, p, &wloc )) != OK) { status = II_BAD_PATH; break; } /* ** Reset requested information flags for each iteration. */ info = (LO_I_TYPE | LO_I_PERMS); switch(retcode = LOinfo( &wloc, &info, &linfo )) { case OK: /* ** If the path or permission test is requested and ** type info is returned test for directory flag. */ if ((eflags & (II_CHK_PATHDIR | II_CHK_PATHPERM)) && ((info & LO_I_TYPE) == LO_I_TYPE)) status = (linfo.li_type == LO_IS_DIR) ? OK : II_PATH_NOT_DIR; /* ** If the permission test is requested and ** permissions are returned test the flags for read ** and write. */ if ((status == OK) && (eflags & II_CHK_PATHPERM)) { if (((info & LO_I_PERMS) == LO_I_PERMS) && (linfo.li_perms & (LO_P_READ|LO_P_WRITE)) == (LO_P_READ|LO_P_WRITE)) { /* ** Read and write permission */ break; } else { /* ** missing a permission */ status = II_PATH_CANNOT_WRITE; } } else { break; } case LO_NO_SUCH: /* ** Look backwards for the next path separator */ if((s = STrindex( p, PATH_SEPARATOR, 0 )) != NULL) { /* ** If separator found truncate the path ** otherwise the start of the path has ** been reached, update string to test the ** root directory. */ if (s != p) { *s = '\0'; } else { *(s+1) = '\0'; } } else { /* ** A root path character was included in the ** path that has been reached and still no ** installable area found. */ if (p && *p && *p == SLASH) { status = II_BAD_PATH; } else { /* ** A relative path was specified and no ** installable area has been found. ** Test the current working directory of the ** target device. */ if ((status = LOgt( p, &wloc )) == OK) { /* ** Reset temporary pointer to a work ** area to satisfy the loop condition. */ s = work; } } } break; default: status = II_BAD_PATH; break; } } break; } else { if (status != II_SUCCESSFUL) { status = II_BAD_PATH; } break; } } /* ** Free the working area */ if (temp != NULL) { MEfree( temp ); } return(status); }