hfaxd/FileSystem.c++
/*
 * Check if the client is permitted to do the
 * request operation on the specified file.
 * Operations are: X_OK (list/stat), R_OK (look
 * at the contents), W_OK (write/delete contents).
 *
 * If the operation is permitted the stat result
 * for the target file is returned to the caller
 * for use in futher checks (e.g. type of file).
 */
Check if the client is permitted to do the
request operation on the specified file.
Operations are: X_OK (list/stat), R_OK (look
at the contents), W_OK (write/delete contents).

If the operation is permitted the stat result
for the target file is returned to the caller
for use in futher checks .
Check if the client is permitted to do the request operation on the specified file . Operations are : X_OK ( list / stat ) R_OK ( look at the contents ) W_OK ( write / delete contents ) . If the operation is permitted the stat result for the target file is returned to the caller for use in futher checks .
SpoolDir*
HylaFAXServer::fileAccess(const char* path, int op, struct stat& sb)
{
    if (!FileCache::lookup(path, sb)) {			
	if (op != W_OK || errno != ENOENT) {
	    perror_reply(550, path, errno);
	    return (NULL);
	}
	sb.st_mode = S_IFREG|S_IRGRP|S_IWGRP;
	sb.st_gid = (gid_t) uid;
	sb.st_ino = 0;					
    }
    struct stat db;
    const char* cp = strrchr(path, '/');
    if (cp) {
	cp++;						
	if (!FileCache::lookup(fxStr(path, cp-path), db)) {
	    perror_reply(550, path, ENOENT);
	    return (NULL);
	}
    } else {
	if (!FileCache::lookup(cwd->pathname, db)) {	
	    perror_reply(550, path, ENOENT);
	    return (NULL);
	}
	cp = path;
    }
    SpoolDir* dir = dirLookup(db.st_ino);
    if (!dir) {						
	perror_reply(550, path, ENOENT);
	return (NULL);
    } else if (!IS(PRIVILEGED)) {			
	if (dir->adminOnly) {				
	    perror_reply(550, path, EPERM);
	    return (NULL);
	} else if (!fileVisible(*dir, cp, sb)) {	
	    perror_reply(550, path, EPERM);
	    return (NULL);
	} else if (op != X_OK) {			
	    if (S_ISDIR(sb.st_mode)) {			
		reply(550, "%s: not a plain file.", path);
		return (NULL);
	    } else if (sb.st_ino == 0 && !dir->storAble) {
		perror_reply(550, path, EPERM);		
		return (NULL);
	    }
	    if (!checkFileRights(op, sb)) {
		perror_reply(550, path, EPERM);
		return (NULL);
	    }
	}
    } else {						
	if (op != X_OK && S_ISDIR(sb.st_mode)) {	
	    reply(550, "%s: not a plain file.", path);
	    return (NULL);
	}
    }
    return (dir);
}
SpoolDir * HylaFAXServer :: fileAccess ( const char * path , int op , struct stat & sb ) { if ( ! FileCache :: lookup ( path , sb ) ) { if ( op != W_OK || errno != ENOENT ) { perror_reply ( 550 , path , errno ) ; return ( NULL ) ; } sb . st_mode = S_IFREG | S_IRGRP | S_IWGRP ; sb . st_gid = ( gid_t ) uid ; sb . st_ino = 0 ; } struct stat db ; const char * cp = strrchr ( path , ' ' ) ; if ( cp ) { cp ++ ; if ( ! FileCache :: lookup ( fxStr ( path , cp - path ) , db ) ) { perror_reply ( 550 , path , ENOENT ) ; return ( NULL ) ; } } else { if ( ! FileCache :: lookup ( cwd -> pathname , db ) ) { perror_reply ( 550 , path , ENOENT ) ; return ( NULL ) ; } cp = path ; } SpoolDir * dir = dirLookup ( db . st_ino ) ; if ( ! dir ) { perror_reply ( 550 , path , ENOENT ) ; return ( NULL ) ; } else if ( ! IS ( PRIVILEGED ) ) { if ( dir -> adminOnly ) { perror_reply ( 550 , path , EPERM ) ; return ( NULL ) ; } else if ( ! fileVisible ( * dir , cp , sb ) ) { perror_reply ( 550 , path , EPERM ) ; return ( NULL ) ; } else if ( op != X_OK ) { if ( S_ISDIR ( sb . st_mode ) ) { reply ( 550 , " " , path ) ; return ( NULL ) ; } else if ( sb . st_ino == 0 && ! dir -> storAble ) { perror_reply ( 550 , path , EPERM ) ; return ( NULL ) ; } if ( ! checkFileRights ( op , sb ) ) { perror_reply ( 550 , path , EPERM ) ; return ( NULL ) ; } } } else { if ( op != X_OK && S_ISDIR ( sb . st_mode ) ) { reply ( 550 , " " , path ) ; return ( NULL ) ; } } return ( dir ) ; }
Check if the client is permitted to do the
 request operation on the specified file.
Check if the client is permitted to do the request operation on the specified file .
// file not found /*
	 * The file does not exist, fake up the
	 * information that would result from a
	 * successful file creation--for use below.
	 */ // NB: to be created /*
     * Validate containing directory and target file.
     * The directory must exist and the client must
     * have permission to access it.  The target file
     * must not be a directory if the client is about
     * to do a read/write-style operation or the target
     * file must be owned by the client (other checks
     * are left to the caller).
     */ // include "/" // implicit ref to "." // no containing dir // unprivileged client // requires admin priv's // not visible w/o admin // client wants to r/w // cannot r/w directory // cannot stor in dir. // privileged client // cannot r/w directory