From b3ea395681377265660e4bdc5df5b798f7a3f40e Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 17 Sep 2021 16:50:00 +0200 Subject: [PATCH] mountmgr: Support $HOME paths to define shell folders. Signed-off-by: Alexandre Julliard --- dlls/mountmgr.sys/mountmgr.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c index cf7c9d636f0..27f642df7e8 100644 --- a/dlls/mountmgr.sys/mountmgr.c +++ b/dlls/mountmgr.sys/mountmgr.c @@ -301,7 +301,8 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) UNICODE_STRING name; NTSTATUS status; ULONG size = 256; - char *buffer, *backup = NULL; + const char *home; + char *buffer = NULL, *backup = NULL, *homelink = NULL; struct stat st; unsigned int i; @@ -319,8 +320,21 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) if (!link[0]) link = NULL; } + if (link && (!strcmp( link, "$HOME" ) || !strncmp( link, "$HOME/", 6 )) && (home = getenv( "HOME" ))) + { + link += 5; + homelink = HeapAlloc( GetProcessHeap(), 0, strlen(home) + strlen(link) + 1 ); + strcpy( homelink, home ); + strcat( homelink, link ); + link = homelink; + } + /* ignore nonexistent link targets */ - if (link && stat( link, &st )) return STATUS_OBJECT_NAME_NOT_FOUND; + if (link && (stat( link, &st ) || !S_ISDIR( st.st_mode ))) + { + status = STATUS_OBJECT_NAME_NOT_FOUND; + goto done; + } name.Buffer = (WCHAR *)((char *)in_buff + input->folder_offset); name.Length = input->folder_size; @@ -328,11 +342,16 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) for (;;) { - if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) return STATUS_NO_MEMORY; - status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN ); - if (!status) break; + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) + { + status = STATUS_NO_MEMORY; + goto done; + } + status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN_IF ); + if (status == STATUS_NO_SUCH_FILE) status = STATUS_SUCCESS; + if (status == STATUS_SUCCESS) break; + if (status != STATUS_BUFFER_TOO_SMALL) goto done; HeapFree( GetProcessHeap(), 0, buffer ); - if (status != STATUS_BUFFER_TOO_SMALL) return status; } if (input->create_backup) @@ -376,6 +395,7 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) done: HeapFree( GetProcessHeap(), 0, buffer ); HeapFree( GetProcessHeap(), 0, backup ); + HeapFree( GetProcessHeap(), 0, homelink ); return status; }