2004-09-18 08:16:14 +00:00
/*
Unix SMB / CIFS implementation .
POSIX NTVFS backend - filename resolution
Copyright ( C ) Andrew Tridgell 2004
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2004-09-18 08:16:14 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-09-18 08:16:14 +00:00
*/
/*
this is the core code for converting a filename from the format as
given by a client to a posix filename , including any case - matching
required , and checks for legal characters
*/
2004-11-05 07:29:02 +00:00
# include "includes.h"
2004-09-18 08:16:14 +00:00
# include "vfs_posix.h"
2004-11-02 00:24:21 +00:00
# include "system/dir.h"
2004-09-18 08:16:14 +00:00
/*
compare two filename components . This is where the name mangling hook will go
*/
2004-10-10 05:29:59 +00:00
static int component_compare ( struct pvfs_state * pvfs , const char * comp , const char * name )
2004-09-18 08:16:14 +00:00
{
2004-10-10 05:29:59 +00:00
int ret ;
2005-08-30 11:55:05 +00:00
ret = strcasecmp_m ( comp , name ) ;
2004-10-10 05:29:59 +00:00
2004-10-12 05:10:43 +00:00
if ( ret ! = 0 ) {
char * shortname = pvfs_short_name_component ( pvfs , name ) ;
if ( shortname ) {
2005-08-30 11:55:05 +00:00
ret = strcasecmp_m ( comp , shortname ) ;
2004-10-12 05:10:43 +00:00
talloc_free ( shortname ) ;
}
}
2004-10-10 05:29:59 +00:00
return ret ;
2004-09-18 08:16:14 +00:00
}
/*
search for a filename in a case insensitive fashion
TODO : add a cache for previously resolved case - insensitive names
TODO : add mangled name support
*/
static NTSTATUS pvfs_case_search ( struct pvfs_state * pvfs , struct pvfs_filename * name )
{
/* break into a series of components */
int num_components ;
char * * components ;
char * p , * partial_name ;
int i ;
/* break up the full name info pathname components */
num_components = 2 ;
p = name - > full_name + strlen ( pvfs - > base_directory ) + 1 ;
for ( ; * p ; p + + ) {
if ( * p = = ' / ' ) {
num_components + + ;
}
}
2005-01-27 07:08:20 +00:00
components = talloc_array ( name , char * , num_components ) ;
2004-09-18 08:16:14 +00:00
p = name - > full_name + strlen ( pvfs - > base_directory ) ;
* p + + = 0 ;
components [ 0 ] = name - > full_name ;
for ( i = 1 ; i < num_components ; i + + ) {
components [ i ] = p ;
p = strchr ( p , ' / ' ) ;
if ( p ) * p + + = 0 ;
2004-10-12 05:33:05 +00:00
if ( pvfs_is_reserved_name ( pvfs , components [ i ] ) ) {
return NT_STATUS_ACCESS_DENIED ;
}
2004-09-18 08:16:14 +00:00
}
partial_name = talloc_strdup ( name , components [ 0 ] ) ;
if ( ! partial_name ) {
return NT_STATUS_NO_MEMORY ;
}
/* for each component, check if it exists as-is, and if not then
do a directory scan */
for ( i = 1 ; i < num_components ; i + + ) {
char * test_name ;
DIR * dir ;
struct dirent * de ;
2004-10-12 05:10:43 +00:00
char * long_component ;
/* possibly remap from the short name cache */
long_component = pvfs_mangled_lookup ( pvfs , name , components [ i ] ) ;
if ( long_component ) {
components [ i ] = long_component ;
}
2004-09-18 08:16:14 +00:00
test_name = talloc_asprintf ( name , " %s/%s " , partial_name , components [ i ] ) ;
if ( ! test_name ) {
return NT_STATUS_NO_MEMORY ;
}
/* check if this component exists as-is */
if ( stat ( test_name , & name - > st ) = = 0 ) {
if ( i < num_components - 1 & & ! S_ISDIR ( name - > st . st_mode ) ) {
2004-10-27 08:36:51 +00:00
return NT_STATUS_OBJECT_PATH_NOT_FOUND ;
2004-09-18 08:16:14 +00:00
}
talloc_free ( partial_name ) ;
partial_name = test_name ;
if ( i = = num_components - 1 ) {
name - > exists = True ;
}
continue ;
}
2004-10-26 00:59:06 +00:00
/* the filesystem might be case insensitive, in which
case a search is pointless unless the name is
mangled */
if ( ( pvfs - > flags & PVFS_FLAG_CI_FILESYSTEM ) & &
! pvfs_is_mangled_component ( pvfs , components [ i ] ) ) {
if ( i < num_components - 1 ) {
return NT_STATUS_OBJECT_PATH_NOT_FOUND ;
}
partial_name = test_name ;
continue ;
}
2004-09-18 08:16:14 +00:00
dir = opendir ( partial_name ) ;
if ( ! dir ) {
return pvfs_map_errno ( pvfs , errno ) ;
}
while ( ( de = readdir ( dir ) ) ) {
2004-10-10 05:29:59 +00:00
if ( component_compare ( pvfs , components [ i ] , de - > d_name ) = = 0 ) {
2004-09-18 08:16:14 +00:00
break ;
}
}
if ( ! de ) {
2004-09-20 07:28:43 +00:00
if ( i < num_components - 1 ) {
closedir ( dir ) ;
2004-10-15 05:40:13 +00:00
return NT_STATUS_OBJECT_PATH_NOT_FOUND ;
2004-09-20 07:28:43 +00:00
}
} else {
components [ i ] = talloc_strdup ( name , de - > d_name ) ;
2004-09-18 08:16:14 +00:00
}
test_name = talloc_asprintf ( name , " %s/%s " , partial_name , components [ i ] ) ;
talloc_free ( partial_name ) ;
partial_name = test_name ;
closedir ( dir ) ;
}
if ( ! name - > exists ) {
if ( stat ( partial_name , & name - > st ) = = 0 ) {
name - > exists = True ;
}
}
talloc_free ( name - > full_name ) ;
name - > full_name = partial_name ;
2004-09-20 07:28:43 +00:00
if ( name - > exists ) {
2004-11-05 07:29:02 +00:00
return pvfs_fill_dos_info ( pvfs , name , - 1 ) ;
2004-09-20 07:28:43 +00:00
}
2004-09-18 08:16:14 +00:00
return NT_STATUS_OK ;
}
2004-11-17 05:58:04 +00:00
/*
parse a alternate data stream name
*/
static NTSTATUS parse_stream_name ( struct pvfs_filename * name , const char * s )
{
char * p ;
name - > stream_name = talloc_strdup ( name , s + 1 ) ;
if ( name - > stream_name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
p = strchr_m ( name - > stream_name , ' : ' ) ;
if ( p = = NULL ) {
name - > stream_id = pvfs_name_hash ( name - > stream_name ,
strlen ( name - > stream_name ) ) ;
return NT_STATUS_OK ;
}
2005-08-30 11:55:05 +00:00
if ( strcasecmp_m ( p , " :$DATA " ) ! = 0 ) {
2004-11-17 05:58:04 +00:00
return NT_STATUS_OBJECT_NAME_INVALID ;
}
* p = 0 ;
if ( strcmp ( name - > stream_name , " " ) = = 0 ) {
name - > stream_name = NULL ;
name - > stream_id = 0 ;
} else {
name - > stream_id = pvfs_name_hash ( name - > stream_name ,
strlen ( name - > stream_name ) ) ;
}
return NT_STATUS_OK ;
}
2004-09-18 08:16:14 +00:00
/*
convert a CIFS pathname to a unix pathname . Note that this does NOT
take into account case insensitivity , and in fact does not access
the filesystem at all . It is merely a reformatting and charset
checking routine .
errors are returned if the filename is illegal given the flags
*/
static NTSTATUS pvfs_unix_path ( struct pvfs_state * pvfs , const char * cifs_name ,
uint_t flags , struct pvfs_filename * name )
{
2004-10-25 06:23:28 +00:00
char * ret , * p , * p_start ;
2004-11-17 05:58:04 +00:00
NTSTATUS status ;
2004-09-18 08:16:14 +00:00
2004-09-20 07:28:43 +00:00
name - > original_name = talloc_strdup ( name , cifs_name ) ;
2004-09-18 08:16:14 +00:00
name - > stream_name = NULL ;
2004-11-17 05:58:04 +00:00
name - > stream_id = 0 ;
2004-09-18 08:16:14 +00:00
name - > has_wildcard = False ;
2004-09-23 07:44:42 +00:00
while ( * cifs_name = = ' \\ ' ) {
2004-09-18 08:16:14 +00:00
cifs_name + + ;
}
2004-09-23 07:44:42 +00:00
if ( * cifs_name = = 0 ) {
name - > full_name = talloc_asprintf ( name , " %s/. " , pvfs - > base_directory ) ;
if ( name - > full_name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
}
2004-09-18 08:16:14 +00:00
ret = talloc_asprintf ( name , " %s/%s " , pvfs - > base_directory , cifs_name ) ;
if ( ret = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
p = ret + strlen ( pvfs - > base_directory ) + 1 ;
/* now do an in-place conversion of '\' to '/', checking
for legal characters */
2004-10-25 06:23:28 +00:00
p_start = p ;
2004-10-27 08:36:51 +00:00
2004-10-12 06:07:55 +00:00
while ( * p ) {
size_t c_size ;
codepoint_t c = next_codepoint ( p , & c_size ) ;
switch ( c ) {
2004-09-18 08:16:14 +00:00
case ' \\ ' :
if ( name - > has_wildcard ) {
/* wildcards are only allowed in the last part
of a name */
return NT_STATUS_ILLEGAL_CHARACTER ;
}
2004-10-27 08:36:51 +00:00
if ( p > p_start & & p [ 1 ] = = 0 ) {
* p = 0 ;
} else {
* p = ' / ' ;
}
2004-09-18 08:16:14 +00:00
break ;
case ' : ' :
if ( ! ( flags & PVFS_RESOLVE_STREAMS ) ) {
return NT_STATUS_ILLEGAL_CHARACTER ;
}
2004-11-17 05:58:04 +00:00
if ( name - > has_wildcard ) {
return NT_STATUS_ILLEGAL_CHARACTER ;
}
status = parse_stream_name ( name , p ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2004-09-18 08:16:14 +00:00
}
* p - - = 0 ;
break ;
case ' * ' :
case ' > ' :
case ' < ' :
case ' ? ' :
case ' " ' :
2004-11-15 06:57:26 +00:00
if ( ! ( flags & PVFS_RESOLVE_WILDCARD ) ) {
2004-10-27 08:36:51 +00:00
return NT_STATUS_OBJECT_NAME_INVALID ;
2004-09-18 08:16:14 +00:00
}
name - > has_wildcard = True ;
break ;
case ' / ' :
case ' | ' :
return NT_STATUS_ILLEGAL_CHARACTER ;
2004-10-25 06:23:28 +00:00
case ' . ' :
2004-10-26 05:39:54 +00:00
/* see if it is definately a .. or
. component . If it is then fail here , and
let the next layer up try again after
pvfs_reduce_name ( ) if it wants to . This is
much more efficient on average than always
scanning for these separately */
if ( p [ 1 ] = = ' . ' & &
( p [ 2 ] = = 0 | | p [ 2 ] = = ' \\ ' ) & &
( p = = p_start | | p [ - 1 ] = = ' / ' ) ) {
return NT_STATUS_OBJECT_PATH_SYNTAX_BAD ;
2004-10-25 06:23:28 +00:00
}
2004-10-26 05:39:54 +00:00
if ( ( p [ 1 ] = = 0 | | p [ 1 ] = = ' \\ ' ) & &
( p = = p_start | | p [ - 1 ] = = ' / ' ) ) {
2004-10-25 06:23:28 +00:00
return NT_STATUS_OBJECT_PATH_SYNTAX_BAD ;
}
break ;
2004-09-18 08:16:14 +00:00
}
2004-10-12 06:07:55 +00:00
p + = c_size ;
2004-09-18 08:16:14 +00:00
}
name - > full_name = ret ;
return NT_STATUS_OK ;
}
2004-10-26 05:39:54 +00:00
/*
reduce a name that contains . . components or repeated \ separators
return NULL if it can ' t be reduced
*/
2004-10-27 08:36:51 +00:00
static NTSTATUS pvfs_reduce_name ( TALLOC_CTX * mem_ctx , const char * * fname , uint_t flags )
2004-10-26 05:39:54 +00:00
{
codepoint_t c ;
size_t c_size , len ;
2004-10-27 08:36:51 +00:00
int i , num_components , err_count ;
2004-10-26 05:39:54 +00:00
char * * components ;
char * p , * s , * ret ;
2004-10-27 08:36:51 +00:00
s = talloc_strdup ( mem_ctx , * fname ) ;
if ( s = = NULL ) return NT_STATUS_NO_MEMORY ;
2004-10-26 05:39:54 +00:00
for ( num_components = 1 , p = s ; * p ; p + = c_size ) {
c = next_codepoint ( p , & c_size ) ;
if ( c = = ' \\ ' ) num_components + + ;
}
2005-01-27 07:08:20 +00:00
components = talloc_array ( s , char * , num_components + 1 ) ;
2004-10-26 05:39:54 +00:00
if ( components = = NULL ) {
talloc_free ( s ) ;
2004-10-27 08:36:51 +00:00
return NT_STATUS_NO_MEMORY ;
2004-10-26 05:39:54 +00:00
}
components [ 0 ] = s ;
for ( i = 0 , p = s ; * p ; p + = c_size ) {
c = next_codepoint ( p , & c_size ) ;
if ( c = = ' \\ ' ) {
* p = 0 ;
components [ + + i ] = p + 1 ;
}
}
components [ i + 1 ] = NULL ;
2004-10-27 08:36:51 +00:00
/*
rather bizarre !
' . ' components are not allowed , but the rules for what error
code to give don ' t seem to make sense . This is a close
approximation .
*/
for ( err_count = i = 0 ; components [ i ] ; i + + ) {
if ( strcmp ( components [ i ] , " " ) = = 0 ) {
continue ;
}
2006-04-24 00:16:51 +00:00
if ( ISDOT ( components [ i ] ) | | err_count ) {
2004-10-27 08:36:51 +00:00
err_count + + ;
}
}
if ( err_count ) {
2004-11-15 06:57:26 +00:00
if ( flags & PVFS_RESOLVE_WILDCARD ) err_count - - ;
2004-10-27 08:36:51 +00:00
if ( err_count = = 1 ) {
return NT_STATUS_OBJECT_NAME_INVALID ;
} else {
return NT_STATUS_OBJECT_PATH_NOT_FOUND ;
}
}
2004-10-26 05:39:54 +00:00
/* remove any null components */
for ( i = 0 ; components [ i ] ; i + + ) {
2004-10-27 08:36:51 +00:00
if ( strcmp ( components [ i ] , " " ) = = 0 ) {
2004-10-26 05:39:54 +00:00
memmove ( & components [ i ] , & components [ i + 1 ] ,
sizeof ( char * ) * ( num_components - i ) ) ;
i - - ;
2005-06-10 08:24:34 +00:00
continue ;
2004-10-26 05:39:54 +00:00
}
2006-04-24 00:16:51 +00:00
if ( ISDOTDOT ( components [ i ] ) ) {
2004-10-27 08:36:51 +00:00
if ( i < 1 ) return NT_STATUS_OBJECT_PATH_SYNTAX_BAD ;
2004-10-26 05:39:54 +00:00
memmove ( & components [ i - 1 ] , & components [ i + 1 ] ,
sizeof ( char * ) * ( num_components - ( i + 1 ) ) ) ;
i - = 2 ;
2005-06-10 08:24:34 +00:00
continue ;
2004-10-26 05:39:54 +00:00
}
}
if ( components [ 0 ] = = NULL ) {
talloc_free ( s ) ;
2004-10-27 08:36:51 +00:00
* fname = talloc_strdup ( mem_ctx , " \\ " ) ;
return NT_STATUS_OK ;
2004-10-26 05:39:54 +00:00
}
for ( len = i = 0 ; components [ i ] ; i + + ) {
len + = strlen ( components [ i ] ) + 1 ;
}
/* rebuild the name */
2005-01-06 03:06:58 +00:00
ret = talloc_size ( mem_ctx , len + 1 ) ;
2004-10-26 05:39:54 +00:00
if ( ret = = NULL ) {
talloc_free ( s ) ;
2004-10-27 08:36:51 +00:00
return NT_STATUS_NO_MEMORY ;
2004-10-26 05:39:54 +00:00
}
for ( len = 0 , i = 0 ; components [ i ] ; i + + ) {
size_t len1 = strlen ( components [ i ] ) ;
ret [ len ] = ' \\ ' ;
memcpy ( ret + len + 1 , components [ i ] , len1 ) ;
len + = len1 + 1 ;
}
ret [ len ] = 0 ;
talloc_free ( s ) ;
2004-10-27 08:36:51 +00:00
* fname = ret ;
2004-10-26 05:39:54 +00:00
2004-10-27 08:36:51 +00:00
return NT_STATUS_OK ;
2004-10-26 05:39:54 +00:00
}
2004-09-18 08:16:14 +00:00
/*
resolve a name from relative client format to a struct pvfs_filename
the memory for the filename is made as a talloc child of ' name '
flags include :
PVFS_RESOLVE_NO_WILDCARD = wildcards are considered illegal characters
PVFS_RESOLVE_STREAMS = stream names are allowed
TODO : . . / collapsing , and outside share checking
*/
NTSTATUS pvfs_resolve_name ( struct pvfs_state * pvfs , TALLOC_CTX * mem_ctx ,
const char * cifs_name ,
uint_t flags , struct pvfs_filename * * name )
{
NTSTATUS status ;
2005-01-27 07:08:20 +00:00
* name = talloc ( mem_ctx , struct pvfs_filename ) ;
2004-09-18 08:16:14 +00:00
if ( * name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
( * name ) - > exists = False ;
2004-11-17 05:58:04 +00:00
( * name ) - > stream_exists = False ;
2004-09-18 08:16:14 +00:00
2004-11-17 06:30:06 +00:00
if ( ! ( pvfs - > fs_attribs & FS_ATTR_NAMED_STREAMS ) ) {
flags & = ~ PVFS_RESOLVE_STREAMS ;
}
2004-09-18 08:16:14 +00:00
/* do the basic conversion to a unix formatted path,
also checking for allowable characters */
status = pvfs_unix_path ( pvfs , cifs_name , flags , * name ) ;
2004-10-26 05:39:54 +00:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_OBJECT_PATH_SYNTAX_BAD ) ) {
/* it might contain .. components which need to be reduced */
2004-10-27 08:36:51 +00:00
status = pvfs_reduce_name ( * name , & cifs_name , flags ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2004-10-26 05:39:54 +00:00
}
2004-10-27 08:36:51 +00:00
status = pvfs_unix_path ( pvfs , cifs_name , flags , * name ) ;
2004-10-26 05:39:54 +00:00
}
2004-09-18 08:16:14 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2007-08-24 03:40:40 +00:00
/* if it has a wildcard then no point doing a stat() of the
full name . Instead We need check if the directory exists
*/
2004-09-18 08:16:14 +00:00
if ( ( * name ) - > has_wildcard ) {
2007-08-24 03:40:40 +00:00
const char * p ;
char * dir_name , * saved_name ;
p = strrchr ( ( * name ) - > full_name , ' / ' ) ;
if ( p = = NULL ) {
/* root directory wildcard is OK */
return NT_STATUS_OK ;
}
dir_name = talloc_strndup ( * name , ( * name ) - > full_name , ( p - ( * name ) - > full_name ) ) ;
if ( stat ( dir_name , & ( * name ) - > st ) = = 0 ) {
talloc_free ( dir_name ) ;
return NT_STATUS_OK ;
}
/* we need to search for a matching name */
saved_name = ( * name ) - > full_name ;
( * name ) - > full_name = dir_name ;
status = pvfs_case_search ( pvfs , * name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
/* the directory doesn't exist */
( * name ) - > full_name = saved_name ;
return status ;
}
/* it does exist, but might need a case change */
if ( dir_name ! = ( * name ) - > full_name ) {
( * name ) - > full_name = talloc_asprintf ( * name , " %s%s " ,
( * name ) - > full_name , p ) ;
NT_STATUS_HAVE_NO_MEMORY ( ( * name ) - > full_name ) ;
} else {
( * name ) - > full_name = saved_name ;
talloc_free ( dir_name ) ;
}
2004-09-18 08:16:14 +00:00
return NT_STATUS_OK ;
}
/* if we can stat() the full name now then we are done */
if ( stat ( ( * name ) - > full_name , & ( * name ) - > st ) = = 0 ) {
( * name ) - > exists = True ;
2004-11-05 07:29:02 +00:00
return pvfs_fill_dos_info ( pvfs , * name , - 1 ) ;
2004-09-18 08:16:14 +00:00
}
/* search for a matching filename */
status = pvfs_case_search ( pvfs , * name ) ;
return status ;
}
/*
do a partial resolve , returning a pvfs_filename structure given a
base path and a relative component . It is an error if the file does
not exist . No case - insensitive matching is done .
this is used in places like directory searching where we need a pvfs_filename
to pass to a function , but already know the unix base directory and component
*/
NTSTATUS pvfs_resolve_partial ( struct pvfs_state * pvfs , TALLOC_CTX * mem_ctx ,
const char * unix_dir , const char * fname ,
struct pvfs_filename * * name )
{
2004-09-20 07:28:43 +00:00
NTSTATUS status ;
2005-01-27 07:08:20 +00:00
* name = talloc ( mem_ctx , struct pvfs_filename ) ;
2004-09-18 08:16:14 +00:00
if ( * name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2004-09-20 07:28:43 +00:00
( * name ) - > full_name = talloc_asprintf ( * name , " %s/%s " , unix_dir , fname ) ;
2004-09-18 08:16:14 +00:00
if ( ( * name ) - > full_name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
if ( stat ( ( * name ) - > full_name , & ( * name ) - > st ) = = - 1 ) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
}
( * name ) - > exists = True ;
2004-11-17 05:58:04 +00:00
( * name ) - > stream_exists = True ;
2004-09-18 08:16:14 +00:00
( * name ) - > has_wildcard = False ;
2004-09-20 07:28:43 +00:00
( * name ) - > original_name = talloc_strdup ( * name , fname ) ;
2004-09-18 08:16:14 +00:00
( * name ) - > stream_name = NULL ;
2004-11-17 05:58:04 +00:00
( * name ) - > stream_id = 0 ;
2004-09-18 08:16:14 +00:00
2004-11-05 07:29:02 +00:00
status = pvfs_fill_dos_info ( pvfs , * name , - 1 ) ;
2004-09-20 07:28:43 +00:00
return status ;
}
/*
fill in the pvfs_filename info for an open file , given the current
info for a ( possibly ) non - open file . This is used by places that need
to update the pvfs_filename stat information , and by pvfs_open ( )
*/
NTSTATUS pvfs_resolve_name_fd ( struct pvfs_state * pvfs , int fd ,
struct pvfs_filename * name )
{
2006-04-30 13:54:03 +00:00
dev_t device = ( dev_t ) 0 ;
2004-12-02 04:51:56 +00:00
ino_t inode = 0 ;
2004-10-22 06:55:18 +00:00
if ( name - > exists ) {
device = name - > st . st_dev ;
inode = name - > st . st_ino ;
}
2004-11-10 12:40:33 +00:00
if ( fd = = - 1 ) {
2004-10-29 04:43:28 +00:00
if ( stat ( name - > full_name , & name - > st ) = = - 1 ) {
return NT_STATUS_INVALID_HANDLE ;
}
} else {
if ( fstat ( fd , & name - > st ) = = - 1 ) {
return NT_STATUS_INVALID_HANDLE ;
}
2004-09-20 07:28:43 +00:00
}
2004-10-22 06:55:18 +00:00
if ( name - > exists & &
( device ! = name - > st . st_dev | | inode ! = name - > st . st_ino ) ) {
/* the file we are looking at has changed! this could
be someone trying to exploit a race
condition . Certainly we don ' t want to continue
operating on this file */
2004-11-12 02:45:52 +00:00
DEBUG ( 0 , ( " pvfs: WARNING: file '%s' changed during resolve - failing \n " ,
2004-10-22 06:55:18 +00:00
name - > full_name ) ) ;
return NT_STATUS_UNEXPECTED_IO_ERROR ;
}
2004-09-20 07:28:43 +00:00
name - > exists = True ;
2004-11-05 07:29:02 +00:00
return pvfs_fill_dos_info ( pvfs , name , fd ) ;
2004-09-18 08:16:14 +00:00
}
2004-12-30 02:25:20 +00:00
/*
resolve the parent of a given name
*/
NTSTATUS pvfs_resolve_parent ( struct pvfs_state * pvfs , TALLOC_CTX * mem_ctx ,
const struct pvfs_filename * child ,
struct pvfs_filename * * name )
{
NTSTATUS status ;
char * p ;
2005-01-27 07:08:20 +00:00
* name = talloc ( mem_ctx , struct pvfs_filename ) ;
2004-12-30 02:25:20 +00:00
if ( * name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
( * name ) - > full_name = talloc_strdup ( * name , child - > full_name ) ;
if ( ( * name ) - > full_name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
p = strrchr_m ( ( * name ) - > full_name , ' / ' ) ;
if ( p = = NULL ) {
return NT_STATUS_OBJECT_PATH_SYNTAX_BAD ;
}
/* this handles the root directory */
if ( p = = ( * name ) - > full_name ) {
p [ 1 ] = 0 ;
} else {
p [ 0 ] = 0 ;
}
if ( stat ( ( * name ) - > full_name , & ( * name ) - > st ) = = - 1 ) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
}
( * name ) - > exists = True ;
( * name ) - > stream_exists = True ;
( * name ) - > has_wildcard = False ;
/* we can't get the correct 'original_name', but for the purposes
of this call this is close enough */
( * name ) - > original_name = talloc_reference ( * name , child - > original_name ) ;
( * name ) - > stream_name = NULL ;
( * name ) - > stream_id = 0 ;
status = pvfs_fill_dos_info ( pvfs , * name , - 1 ) ;
return status ;
}