Skip to content
Snippets Groups Projects
Commit b43b9d93 authored by Ove Kåven's avatar Ove Kåven Committed by Alexandre Julliard
Browse files

Follow symlinks when saving registry.

parent 9639a0a8
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_SYS_ERRNO_H
......@@ -186,10 +187,23 @@ static void save_key( HKEY hkey, const char *filename )
DWORD ret;
HANDLE handle;
char *p;
char *name = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 20 );
char *rname = HeapAlloc( GetProcessHeap(), 0, PATH_MAX );
char *name;
/* use realpath to resolve any symlinks
* I assume that rname is filled in correctly if the error is ENOENT */
if ((realpath(filename, rname) == NULL) && (errno != ENOENT))
{
ERR( "Failed to find real path of %s: ", filename );
perror( "realpath" );
HeapFree( GetProcessHeap(), 0, rname );
return;
}
name = HeapAlloc( GetProcessHeap(), 0, strlen(rname) + 20 );
if (!name) return;
strcpy( name, filename );
strcpy( name, rname );
if ((p = strrchr( name, '/' ))) p++;
else p = name;
......@@ -209,15 +223,16 @@ static void save_key( HKEY hkey, const char *filename )
ret = server_call_noerr( REQ_SAVE_REGISTRY );
CloseHandle( handle );
if (ret) unlink( name );
else if (rename( name, filename ) == -1)
else if (rename( name, rname ) == -1)
{
ERR( "Failed to move %s to %s: ", name, filename );
ERR( "Failed to move %s to %s: ", name, rname );
perror( "rename" );
unlink( name );
}
}
else ERR( "Failed to save registry to %s, err %ld\n", name, GetLastError() );
HeapFree( GetProcessHeap(), 0, rname );
HeapFree( GetProcessHeap(), 0, name );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment