Commit 35cd4115 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Always pass object attributes to nt_to_unix_file_name().

parent 90024e49
...@@ -3217,15 +3217,9 @@ static NTSTATUS lookup_unix_name( const WCHAR *name, int name_len, char **buffer ...@@ -3217,15 +3217,9 @@ static NTSTATUS lookup_unix_name( const WCHAR *name, int name_len, char **buffer
/****************************************************************************** /******************************************************************************
* nt_to_unix_file_name * nt_to_unix_file_name_no_root
*
* Convert a file name from NT namespace to Unix namespace.
*
* If disposition is not FILE_OPEN or FILE_OVERWRITE, the last path
* element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
* returned, but the unix name is still filled in properly.
*/ */
NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret, static NTSTATUS nt_to_unix_file_name_no_root( const UNICODE_STRING *nameW, char **unix_name_ret,
UNICODE_STRING *nt_name, UINT disposition ) UNICODE_STRING *nt_name, UINT disposition )
{ {
static const WCHAR unixW[] = {'u','n','i','x'}; static const WCHAR unixW[] = {'u','n','i','x'};
...@@ -3331,9 +3325,15 @@ NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret ...@@ -3331,9 +3325,15 @@ NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret
/****************************************************************************** /******************************************************************************
* nt_to_unix_file_name_attr * nt_to_unix_file_name
*
* Convert a file name from NT namespace to Unix namespace.
*
* If disposition is not FILE_OPEN or FILE_OVERWRITE, the last path
* element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
* returned, but the unix name is still filled in properly.
*/ */
static NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, char **name_ret, NTSTATUS nt_to_unix_file_name( const OBJECT_ATTRIBUTES *attr, char **name_ret,
UNICODE_STRING *nt_name, UINT disposition ) UNICODE_STRING *nt_name, UINT disposition )
{ {
enum server_fd_type type; enum server_fd_type type;
...@@ -3344,7 +3344,7 @@ static NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, char * ...@@ -3344,7 +3344,7 @@ static NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, char *
NTSTATUS status; NTSTATUS status;
if (!attr->RootDirectory) /* without root dir fall back to normal lookup */ if (!attr->RootDirectory) /* without root dir fall back to normal lookup */
return nt_to_unix_file_name( attr->ObjectName, name_ret, nt_name, disposition ); return nt_to_unix_file_name_no_root( attr->ObjectName, name_ret, nt_name, disposition );
name = attr->ObjectName->Buffer; name = attr->ObjectName->Buffer;
name_len = attr->ObjectName->Length / sizeof(WCHAR); name_len = attr->ObjectName->Length / sizeof(WCHAR);
...@@ -3406,7 +3406,11 @@ NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, char *nam ...@@ -3406,7 +3406,11 @@ NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, char *nam
UINT disposition ) UINT disposition )
{ {
char *buffer = NULL; char *buffer = NULL;
NTSTATUS status = nt_to_unix_file_name( nameW, &buffer, NULL, disposition ); NTSTATUS status;
OBJECT_ATTRIBUTES attr;
InitializeObjectAttributes( &attr, (UNICODE_STRING *)nameW, OBJ_CASE_INSENSITIVE, 0, NULL );
status = nt_to_unix_file_name( &attr, &buffer, NULL, disposition );
if (buffer) if (buffer)
{ {
...@@ -3716,7 +3720,7 @@ NTSTATUS WINAPI NtCreateFile( HANDLE *handle, ACCESS_MASK access, OBJECT_ATTRIBU ...@@ -3716,7 +3720,7 @@ NTSTATUS WINAPI NtCreateFile( HANDLE *handle, ACCESS_MASK access, OBJECT_ATTRIBU
if (options & FILE_OPEN_BY_FILE_ID) if (options & FILE_OPEN_BY_FILE_ID)
io->u.Status = file_id_to_unix_file_name( attr, &unix_name, &nt_name ); io->u.Status = file_id_to_unix_file_name( attr, &unix_name, &nt_name );
else else
io->u.Status = nt_to_unix_file_name_attr( attr, &unix_name, &nt_name, disposition ); io->u.Status = nt_to_unix_file_name( attr, &unix_name, &nt_name, disposition );
if (io->u.Status == STATUS_BAD_DEVICE_TYPE) if (io->u.Status == STATUS_BAD_DEVICE_TYPE)
{ {
...@@ -3903,7 +3907,7 @@ NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr, ...@@ -3903,7 +3907,7 @@ NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
char *unix_name; char *unix_name;
NTSTATUS status; NTSTATUS status;
if (!(status = nt_to_unix_file_name_attr( attr, &unix_name, NULL, FILE_OPEN ))) if (!(status = nt_to_unix_file_name( attr, &unix_name, NULL, FILE_OPEN )))
{ {
ULONG attributes; ULONG attributes;
struct stat st; struct stat st;
...@@ -3944,7 +3948,7 @@ NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC ...@@ -3944,7 +3948,7 @@ NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC
char *unix_name; char *unix_name;
NTSTATUS status; NTSTATUS status;
if (!(status = nt_to_unix_file_name_attr( attr, &unix_name, NULL, FILE_OPEN ))) if (!(status = nt_to_unix_file_name( attr, &unix_name, NULL, FILE_OPEN )))
{ {
ULONG attributes; ULONG attributes;
struct stat st; struct stat st;
...@@ -4506,7 +4510,7 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io, ...@@ -4506,7 +4510,7 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io,
attr.RootDirectory = info->RootDirectory; attr.RootDirectory = info->RootDirectory;
attr.Attributes = OBJ_CASE_INSENSITIVE; attr.Attributes = OBJ_CASE_INSENSITIVE;
io->u.Status = nt_to_unix_file_name_attr( &attr, &unix_name, &nt_name, FILE_OPEN_IF ); io->u.Status = nt_to_unix_file_name( &attr, &unix_name, &nt_name, FILE_OPEN_IF );
if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE) if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
break; break;
...@@ -4546,7 +4550,7 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io, ...@@ -4546,7 +4550,7 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io,
attr.RootDirectory = info->RootDirectory; attr.RootDirectory = info->RootDirectory;
attr.Attributes = OBJ_CASE_INSENSITIVE; attr.Attributes = OBJ_CASE_INSENSITIVE;
io->u.Status = nt_to_unix_file_name_attr( &attr, &unix_name, &nt_name, FILE_OPEN_IF ); io->u.Status = nt_to_unix_file_name( &attr, &unix_name, &nt_name, FILE_OPEN_IF );
if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE) if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
break; break;
......
...@@ -1104,13 +1104,15 @@ static NTSTATUS CDECL init_unix_lib( void *module, DWORD reason, const void *ptr ...@@ -1104,13 +1104,15 @@ static NTSTATUS CDECL init_unix_lib( void *module, DWORD reason, const void *ptr
static NTSTATUS CDECL load_so_dll( UNICODE_STRING *nt_name, void **module ) static NTSTATUS CDECL load_so_dll( UNICODE_STRING *nt_name, void **module )
{ {
static const WCHAR soW[] = {'.','s','o',0}; static const WCHAR soW[] = {'.','s','o',0};
OBJECT_ATTRIBUTES attr;
pe_image_info_t info; pe_image_info_t info;
char *unix_name; char *unix_name;
NTSTATUS status; NTSTATUS status;
DWORD len; DWORD len;
if (get_load_order( nt_name ) == LO_DISABLED) return STATUS_DLL_NOT_FOUND; if (get_load_order( nt_name ) == LO_DISABLED) return STATUS_DLL_NOT_FOUND;
if (nt_to_unix_file_name( nt_name, &unix_name, NULL, FILE_OPEN )) return STATUS_DLL_NOT_FOUND; InitializeObjectAttributes( &attr, nt_name, OBJ_CASE_INSENSITIVE, 0, 0 );
if (nt_to_unix_file_name( &attr, &unix_name, NULL, FILE_OPEN )) return STATUS_DLL_NOT_FOUND;
/* remove .so extension from Windows name */ /* remove .so extension from Windows name */
len = nt_name->Length / sizeof(WCHAR); len = nt_name->Length / sizeof(WCHAR);
...@@ -1437,7 +1439,7 @@ static NTSTATUS open_main_image( WCHAR *image, void **module, SECTION_IMAGE_INFO ...@@ -1437,7 +1439,7 @@ static NTSTATUS open_main_image( WCHAR *image, void **module, SECTION_IMAGE_INFO
init_unicode_string( &nt_name, image ); init_unicode_string( &nt_name, image );
InitializeObjectAttributes( &attr, &nt_name, OBJ_CASE_INSENSITIVE, 0, NULL ); InitializeObjectAttributes( &attr, &nt_name, OBJ_CASE_INSENSITIVE, 0, NULL );
if (nt_to_unix_file_name( &nt_name, &unix_name, NULL, FILE_OPEN )) return STATUS_DLL_NOT_FOUND; if (nt_to_unix_file_name( &attr, &unix_name, NULL, FILE_OPEN )) return STATUS_DLL_NOT_FOUND;
status = open_dll_file( unix_name, &attr, &mapping ); status = open_dll_file( unix_name, &attr, &mapping );
if (!status) if (!status)
......
...@@ -331,22 +331,20 @@ static BOOL get_so_file_info( HANDLE handle, pe_image_info_t *info ) ...@@ -331,22 +331,20 @@ static BOOL get_so_file_info( HANDLE handle, pe_image_info_t *info )
/*********************************************************************** /***********************************************************************
* get_pe_file_info * get_pe_file_info
*/ */
static NTSTATUS get_pe_file_info( UNICODE_STRING *path, HANDLE *handle, pe_image_info_t *info ) static NTSTATUS get_pe_file_info( OBJECT_ATTRIBUTES *attr, HANDLE *handle, pe_image_info_t *info )
{ {
NTSTATUS status; NTSTATUS status;
HANDLE mapping; HANDLE mapping;
OBJECT_ATTRIBUTES attr;
IO_STATUS_BLOCK io; IO_STATUS_BLOCK io;
*handle = 0; *handle = 0;
memset( info, 0, sizeof(*info) ); memset( info, 0, sizeof(*info) );
InitializeObjectAttributes( &attr, path, OBJ_CASE_INSENSITIVE, 0, 0 ); if ((status = NtOpenFile( handle, GENERIC_READ, attr, &io,
if ((status = NtOpenFile( handle, GENERIC_READ, &attr, &io,
FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_SYNCHRONOUS_IO_NONALERT ))) FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_SYNCHRONOUS_IO_NONALERT )))
{ {
if (is_builtin_path( path, &info->machine )) if (is_builtin_path( attr->ObjectName, &info->machine ))
{ {
TRACE( "assuming %04x builtin for %s\n", info->machine, debugstr_us(path)); TRACE( "assuming %04x builtin for %s\n", info->machine, debugstr_us(attr->ObjectName));
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
return status; return status;
...@@ -540,7 +538,7 @@ static NTSTATUS spawn_process( const RTL_USER_PROCESS_PARAMETERS *params, int so ...@@ -540,7 +538,7 @@ static NTSTATUS spawn_process( const RTL_USER_PROCESS_PARAMETERS *params, int so
* *
* Fork and exec a new Unix binary, checking for errors. * Fork and exec a new Unix binary, checking for errors.
*/ */
static NTSTATUS fork_and_exec( UNICODE_STRING *path, int unixdir, static NTSTATUS fork_and_exec( OBJECT_ATTRIBUTES *attr, int unixdir,
const RTL_USER_PROCESS_PARAMETERS *params ) const RTL_USER_PROCESS_PARAMETERS *params )
{ {
pid_t pid; pid_t pid;
...@@ -549,7 +547,7 @@ static NTSTATUS fork_and_exec( UNICODE_STRING *path, int unixdir, ...@@ -549,7 +547,7 @@ static NTSTATUS fork_and_exec( UNICODE_STRING *path, int unixdir,
char *unix_name; char *unix_name;
NTSTATUS status; NTSTATUS status;
status = nt_to_unix_file_name( path, &unix_name, NULL, FILE_OPEN ); status = nt_to_unix_file_name( attr, &unix_name, NULL, FILE_OPEN );
if (status) return status; if (status) return status;
#ifdef HAVE_PIPE2 #ifdef HAVE_PIPE2
...@@ -669,7 +667,7 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_ ...@@ -669,7 +667,7 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_
OBJECT_ATTRIBUTES *process_attr, OBJECT_ATTRIBUTES *thread_attr, OBJECT_ATTRIBUTES *process_attr, OBJECT_ATTRIBUTES *thread_attr,
ULONG process_flags, ULONG thread_flags, ULONG process_flags, ULONG thread_flags,
RTL_USER_PROCESS_PARAMETERS *params, PS_CREATE_INFO *info, RTL_USER_PROCESS_PARAMETERS *params, PS_CREATE_INFO *info,
PS_ATTRIBUTE_LIST *attr ) PS_ATTRIBUTE_LIST *ps_attr )
{ {
NTSTATUS status; NTSTATUS status;
BOOL success = FALSE; BOOL success = FALSE;
...@@ -684,36 +682,36 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_ ...@@ -684,36 +682,36 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_
CLIENT_ID id; CLIENT_ID id;
HANDLE parent = 0, debug = 0, token = 0; HANDLE parent = 0, debug = 0, token = 0;
UNICODE_STRING path = {0}; UNICODE_STRING path = {0};
OBJECT_ATTRIBUTES empty_attr = { sizeof(empty_attr) }; OBJECT_ATTRIBUTES attr, empty_attr = { sizeof(empty_attr) };
SIZE_T i, attr_count = (attr->TotalLength - sizeof(attr->TotalLength)) / sizeof(PS_ATTRIBUTE); SIZE_T i, attr_count = (ps_attr->TotalLength - sizeof(ps_attr->TotalLength)) / sizeof(PS_ATTRIBUTE);
const PS_ATTRIBUTE *handles_attr = NULL; const PS_ATTRIBUTE *handles_attr = NULL;
data_size_t handles_size; data_size_t handles_size;
obj_handle_t *handles; obj_handle_t *handles;
for (i = 0; i < attr_count; i++) for (i = 0; i < attr_count; i++)
{ {
switch (attr->Attributes[i].Attribute) switch (ps_attr->Attributes[i].Attribute)
{ {
case PS_ATTRIBUTE_PARENT_PROCESS: case PS_ATTRIBUTE_PARENT_PROCESS:
parent = attr->Attributes[i].ValuePtr; parent = ps_attr->Attributes[i].ValuePtr;
break; break;
case PS_ATTRIBUTE_DEBUG_PORT: case PS_ATTRIBUTE_DEBUG_PORT:
debug = attr->Attributes[i].ValuePtr; debug = ps_attr->Attributes[i].ValuePtr;
break; break;
case PS_ATTRIBUTE_IMAGE_NAME: case PS_ATTRIBUTE_IMAGE_NAME:
path.Length = attr->Attributes[i].Size; path.Length = ps_attr->Attributes[i].Size;
path.Buffer = attr->Attributes[i].ValuePtr; path.Buffer = ps_attr->Attributes[i].ValuePtr;
break; break;
case PS_ATTRIBUTE_TOKEN: case PS_ATTRIBUTE_TOKEN:
token = attr->Attributes[i].ValuePtr; token = ps_attr->Attributes[i].ValuePtr;
break; break;
case PS_ATTRIBUTE_HANDLE_LIST: case PS_ATTRIBUTE_HANDLE_LIST:
if (process_flags & PROCESS_CREATE_FLAGS_INHERIT_HANDLES) if (process_flags & PROCESS_CREATE_FLAGS_INHERIT_HANDLES)
handles_attr = &attr->Attributes[i]; handles_attr = &ps_attr->Attributes[i];
break; break;
default: default:
if (attr->Attributes[i].Attribute & PS_ATTRIBUTE_INPUT) if (ps_attr->Attributes[i].Attribute & PS_ATTRIBUTE_INPUT)
FIXME( "unhandled input attribute %lx\n", attr->Attributes[i].Attribute ); FIXME( "unhandled input attribute %lx\n", ps_attr->Attributes[i].Attribute );
break; break;
} }
} }
...@@ -724,9 +722,10 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_ ...@@ -724,9 +722,10 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_
unixdir = get_unix_curdir( params ); unixdir = get_unix_curdir( params );
if ((status = get_pe_file_info( &path, &file_handle, &pe_info ))) InitializeObjectAttributes( &attr, &path, OBJ_CASE_INSENSITIVE, 0, 0 );
if ((status = get_pe_file_info( &attr, &file_handle, &pe_info )))
{ {
if (status == STATUS_INVALID_IMAGE_NOT_MZ && !fork_and_exec( &path, unixdir, params )) if (status == STATUS_INVALID_IMAGE_NOT_MZ && !fork_and_exec( &attr, unixdir, params ))
{ {
memset( info, 0, sizeof(*info) ); memset( info, 0, sizeof(*info) );
return STATUS_SUCCESS; return STATUS_SUCCESS;
...@@ -860,28 +859,28 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_ ...@@ -860,28 +859,28 @@ NTSTATUS WINAPI NtCreateUserProcess( HANDLE *process_handle_ptr, HANDLE *thread_
for (i = 0; i < attr_count; i++) for (i = 0; i < attr_count; i++)
{ {
switch (attr->Attributes[i].Attribute) switch (ps_attr->Attributes[i].Attribute)
{ {
case PS_ATTRIBUTE_CLIENT_ID: case PS_ATTRIBUTE_CLIENT_ID:
{ {
SIZE_T size = min( attr->Attributes[i].Size, sizeof(id) ); SIZE_T size = min( ps_attr->Attributes[i].Size, sizeof(id) );
memcpy( attr->Attributes[i].ValuePtr, &id, size ); memcpy( ps_attr->Attributes[i].ValuePtr, &id, size );
if (attr->Attributes[i].ReturnLength) *attr->Attributes[i].ReturnLength = size; if (ps_attr->Attributes[i].ReturnLength) *ps_attr->Attributes[i].ReturnLength = size;
break; break;
} }
case PS_ATTRIBUTE_IMAGE_INFO: case PS_ATTRIBUTE_IMAGE_INFO:
{ {
SECTION_IMAGE_INFORMATION info; SECTION_IMAGE_INFORMATION info;
SIZE_T size = min( attr->Attributes[i].Size, sizeof(info) ); SIZE_T size = min( ps_attr->Attributes[i].Size, sizeof(info) );
virtual_fill_image_information( &pe_info, &info ); virtual_fill_image_information( &pe_info, &info );
memcpy( attr->Attributes[i].ValuePtr, &info, size ); memcpy( ps_attr->Attributes[i].ValuePtr, &info, size );
if (attr->Attributes[i].ReturnLength) *attr->Attributes[i].ReturnLength = size; if (ps_attr->Attributes[i].ReturnLength) *ps_attr->Attributes[i].ReturnLength = size;
break; break;
} }
case PS_ATTRIBUTE_TEB_ADDRESS: case PS_ATTRIBUTE_TEB_ADDRESS:
default: default:
if (!(attr->Attributes[i].Attribute & PS_ATTRIBUTE_INPUT)) if (!(ps_attr->Attributes[i].Attribute & PS_ATTRIBUTE_INPUT))
FIXME( "unhandled output attribute %lx\n", attr->Attributes[i].Attribute ); FIXME( "unhandled output attribute %lx\n", ps_attr->Attributes[i].Attribute );
break; break;
} }
} }
......
...@@ -249,7 +249,7 @@ extern NTSTATUS tape_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTI ...@@ -249,7 +249,7 @@ extern NTSTATUS tape_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTI
ULONG in_size, void *out_buffer, ULONG out_size ) DECLSPEC_HIDDEN; ULONG in_size, void *out_buffer, ULONG out_size ) DECLSPEC_HIDDEN;
extern NTSTATUS errno_to_status( int err ) DECLSPEC_HIDDEN; extern NTSTATUS errno_to_status( int err ) DECLSPEC_HIDDEN;
extern NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret, extern NTSTATUS nt_to_unix_file_name( const OBJECT_ATTRIBUTES *attr, char **name_ret,
UNICODE_STRING *nt_name, UINT disposition ) DECLSPEC_HIDDEN; UNICODE_STRING *nt_name, UINT disposition ) DECLSPEC_HIDDEN;
extern NTSTATUS unix_to_nt_file_name( const char *name, WCHAR **nt ) DECLSPEC_HIDDEN; extern NTSTATUS unix_to_nt_file_name( const char *name, WCHAR **nt ) DECLSPEC_HIDDEN;
extern NTSTATUS get_full_path( const WCHAR *name, const WCHAR *curdir, WCHAR **path ) DECLSPEC_HIDDEN; extern NTSTATUS get_full_path( const WCHAR *name, const WCHAR *curdir, WCHAR **path ) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment