/* * Copyright (C) 2002 Andreas Mohr * Copyright (C) 2002 Shachar Shemesh * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ /* Wine "bootup" handler application * * This app handles the various "hooks" windows allows for applications to perform * as part of the bootstrap process. These are roughly divided into three types. * Knowledge base articles that explain this are 137367, 179365, 232487 and 232509. * Also, 119941 has some info on grpconv.exe * The operations performed are (by order of execution): * * Preboot (prior to fully loading the Windows kernel): * - wininit.exe (rename operations left in wininit.ini - Win 9x only) * - PendingRenameOperations (rename operations left in the registry - Win NT+ only) * * Startup (before the user logs in) * - Services (NT) * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce (9x, asynch) * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices (9x, asynch) * * After log in * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, synch) * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run (all, asynch) * - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (all, asynch) * - Startup folders (all, ?asynch?) * - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, asynch) * * Somewhere in there is processing the RunOnceEx entries (also no imp) * * Bugs: * - If a pending rename registry does not start with \??\ the entry is * processed anyways. I'm not sure that is the Windows behaviour. * - Need to check what is the windows behaviour when trying to delete files * and directories that are read-only * - In the pending rename registry processing - there are no traces of the files * processed (requires translations from Unicode to Ansi). */ #include "config.h" #include "wine/port.h" #define COBJMACROS #define WIN32_LEAN_AND_MEAN #include #include #include #include #ifdef HAVE_GETOPT_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif #include #include #include #include #include #include #include #include #include #include #include #include "resource.h" WINE_DEFAULT_DEBUG_CHANNEL(wineboot); extern BOOL shutdown_close_windows( BOOL force ); extern BOOL shutdown_all_desktops( BOOL force ); extern void kill_processes( BOOL kill_desktop ); static WCHAR windowsdir[MAX_PATH]; static const BOOL is_64bit = sizeof(void *) > sizeof(int); /* retrieve the (unix) path to the wine.inf file */ static char *get_wine_inf_path(void) { const char *build_dir, *data_dir; char *name = NULL; if ((data_dir = wine_get_data_dir())) { if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(data_dir) + sizeof("/wine.inf") ))) return NULL; strcpy( name, data_dir ); strcat( name, "/wine.inf" ); } else if ((build_dir = wine_get_build_dir())) { if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(build_dir) + sizeof("/loader/wine.inf") ))) return NULL; strcpy( name, build_dir ); strcat( name, "/loader/wine.inf" ); } return name; } /* update the timestamp if different from the reference time */ static BOOL update_timestamp( const char *config_dir, unsigned long timestamp ) { BOOL ret = FALSE; int fd, count; char buffer[100]; char *file = HeapAlloc( GetProcessHeap(), 0, strlen(config_dir) + sizeof("/.update-timestamp") ); if (!file) return FALSE; strcpy( file, config_dir ); strcat( file, "/.update-timestamp" ); if ((fd = open( file, O_RDWR )) != -1) { if ((count = read( fd, buffer, sizeof(buffer) - 1 )) >= 0) { buffer[count] = 0; if (!strncmp( buffer, "disable", sizeof("disable")-1 )) goto done; if (timestamp == strtoul( buffer, NULL, 10 )) goto done; } lseek( fd, 0, SEEK_SET ); ftruncate( fd, 0 ); } else { if (errno != ENOENT) goto done; if ((fd = open( file, O_WRONLY | O_CREAT | O_TRUNC, 0666 )) == -1) goto done; } count = sprintf( buffer, "%lu\n", timestamp ); if (write( fd, buffer, count ) != count) { WINE_WARN( "failed to update timestamp in %s\n", file ); ftruncate( fd, 0 ); } else ret = TRUE; done: if (fd != -1) close( fd ); HeapFree( GetProcessHeap(), 0, file ); return ret; } /* wrapper for RegSetValueExW */ static DWORD set_reg_value( HKEY hkey, const WCHAR *name, const WCHAR *value ) { return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, (strlenW(value) + 1) * sizeof(WCHAR) ); } extern void do_cpuid( unsigned int ax, unsigned int *p ); #if defined(_MSC_VER) void do_cpuid( unsigned int ax, unsigned int *p ) { __cpuid( p, ax ); } #elif defined(__i386__) __ASM_GLOBAL_FUNC( do_cpuid, "pushl %esi\n\t" "pushl %ebx\n\t" "movl 12(%esp),%eax\n\t" "movl 16(%esp),%esi\n\t" "cpuid\n\t" "movl %eax,(%esi)\n\t" "movl %ebx,4(%esi)\n\t" "movl %ecx,8(%esi)\n\t" "movl %edx,12(%esi)\n\t" "popl %ebx\n\t" "popl %esi\n\t" "ret" ) #elif defined(__x86_64__) __ASM_GLOBAL_FUNC( do_cpuid, "pushq %rbx\n\t" "movl %edi,%eax\n\t" "cpuid\n\t" "movl %eax,(%rsi)\n\t" "movl %ebx,4(%rsi)\n\t" "movl %ecx,8(%rsi)\n\t" "movl %edx,12(%rsi)\n\t" "popq %rbx\n\t" "ret" ) #else void do_cpuid( unsigned int ax, unsigned int *p ) { FIXME("\n"); } #endif static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer ) { unsigned int i; unsigned char *p = (unsigned char *)regs; for (i = 0; i < len; i++) { buffer[i] = *p++; } buffer[i] = 0; } static unsigned int get_model( unsigned int reg0, unsigned int *stepping, unsigned int *family ) { unsigned int model, family_id = (reg0 & (0x0f << 8)) >> 8; model = (reg0 & (0x0f << 4)) >> 4; if (family_id == 6 || family_id == 15) model |= (reg0 & (0x0f << 16)) >> 12; *family = family_id; if (family_id == 15) *family += (reg0 & (0xff << 20)) >> 20; *stepping = reg0 & 0x0f; return model; } static void get_identifier( WCHAR *buf, const WCHAR *arch ) { static const WCHAR fmtW[] = {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ','M','o','d','e','l', ' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0}; unsigned int regs[4] = {0, 0, 0, 0}, family, model, stepping; do_cpuid( 1, regs ); model = get_model( regs[0], &stepping, &family ); sprintfW( buf, fmtW, arch, family, model, stepping ); } static void get_vendorid( WCHAR *buf ) { unsigned int tmp, regs[4] = {0, 0, 0, 0}; do_cpuid( 0, regs ); tmp = regs[2]; /* swap edx and ecx */ regs[2] = regs[3]; regs[3] = tmp; regs_to_str( regs + 1, 12, buf ); } static void get_namestring( WCHAR *buf ) { unsigned int regs[4] = {0, 0, 0, 0}; int i; do_cpuid( 0x80000000, regs ); if (regs[0] >= 0x80000004) { do_cpuid( 0x80000002, regs ); regs_to_str( regs, 16, buf ); do_cpuid( 0x80000003, regs ); regs_to_str( regs, 16, buf + 16 ); do_cpuid( 0x80000004, regs ); regs_to_str( regs, 16, buf + 32 ); } for (i = strlenW(buf) - 1; i >= 0 && buf[i] == ' '; i--) buf[i] = 0; } /* create the volatile hardware registry keys */ static void create_hardware_registry_keys(void) { static const WCHAR SystemW[] = {'H','a','r','d','w','a','r','e','\\','D','e','s','c','r','i','p','t','i','o','n','\\', 'S','y','s','t','e','m',0}; static const WCHAR fpuW[] = {'F','l','o','a','t','i','n','g','P','o','i','n','t','P','r','o','c','e','s','s','o','r',0}; static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0}; static const WCHAR FeatureSetW[] = {'F','e','a','t','u','r','e','S','e','t',0}; static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0}; static const WCHAR ProcessorNameStringW[] = {'P','r','o','c','e','s','s','o','r','N','a','m','e','S','t','r','i','n','g',0}; static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0}; static const WCHAR ARMSysidW[] = {'A','R','M',' ','p','r','o','c','e','s','s','o','r',' ','f','a','m','i','l','y',0}; static const WCHAR mhzKeyW[] = {'~','M','H','z',0}; static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0}; static const WCHAR PercentDW[] = {'%','d',0}; static const WCHAR ARMCpuDescrW[] = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d', ' ','R','e','v','i','s','i','o','n',' ','%','d',0}; static const WCHAR x86W[] = {'x','8','6',0}; static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0}; static const WCHAR amd64W[] = {'A','M','D','6','4',0}; static const WCHAR authenticamdW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; unsigned int i; HKEY hkey, system_key, cpu_key, fpu_key; SYSTEM_CPU_INFORMATION sci; PROCESSOR_POWER_INFORMATION* power_info; ULONG sizeof_power_info = sizeof(PROCESSOR_POWER_INFORMATION) * NtCurrentTeb()->Peb->NumberOfProcessors; WCHAR id[60], namestr[49], vendorid[13]; get_namestring( namestr ); get_vendorid( vendorid ); NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL ); power_info = HeapAlloc( GetProcessHeap(), 0, sizeof_power_info ); if (power_info == NULL) return; if (NtPowerInformation( ProcessorInformation, NULL, 0, power_info, sizeof_power_info )) memset( power_info, 0, sizeof_power_info ); switch (sci.Architecture) { case PROCESSOR_ARCHITECTURE_ARM: case PROCESSOR_ARCHITECTURE_ARM64: sprintfW( id, ARMCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) ); break; case PROCESSOR_ARCHITECTURE_AMD64: get_identifier( id, !strcmpW(vendorid, authenticamdW) ? amd64W : intel64W ); break; case PROCESSOR_ARCHITECTURE_INTEL: default: get_identifier( id, x86W ); break; } if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, SystemW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &system_key, NULL )) { HeapFree( GetProcessHeap(), 0, power_info ); return; } switch (sci.Architecture) { case PROCESSOR_ARCHITECTURE_ARM: case PROCESSOR_ARCHITECTURE_ARM64: set_reg_value( system_key, IdentifierW, ARMSysidW ); break; case PROCESSOR_ARCHITECTURE_INTEL: case PROCESSOR_ARCHITECTURE_AMD64: default: set_reg_value( system_key, IdentifierW, SysidW ); break; } if (sci.Architecture == PROCESSOR_ARCHITECTURE_ARM || sci.Architecture == PROCESSOR_ARCHITECTURE_ARM64 || RegCreateKeyExW( system_key, fpuW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &fpu_key, NULL )) fpu_key = 0; if (RegCreateKeyExW( system_key, cpuW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &cpu_key, NULL )) cpu_key = 0; for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++) { WCHAR numW[10]; sprintfW( numW, PercentDW, i ); if (!RegCreateKeyExW( cpu_key, numW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL )) { RegSetValueExW( hkey, FeatureSetW, 0, REG_DWORD, (BYTE *)&sci.FeatureSet, sizeof(DWORD) ); set_reg_value( hkey, IdentifierW, id ); /* TODO: report ARM properly */ set_reg_value( hkey, ProcessorNameStringW, namestr ); set_reg_value( hkey, VendorIdentifierW, vendorid ); RegSetValueExW( hkey, mhzKeyW, 0, REG_DWORD, (BYTE *)&power_info[i].MaxMhz, sizeof(DWORD) ); RegCloseKey( hkey ); } if (sci.Architecture != PROCESSOR_ARCHITECTURE_ARM && sci.Architecture != PROCESSOR_ARCHITECTURE_ARM64 && !RegCreateKeyExW( fpu_key, numW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL )) { set_reg_value( hkey, IdentifierW, id ); RegCloseKey( hkey ); } } RegCloseKey( fpu_key ); RegCloseKey( cpu_key ); RegCloseKey( system_key ); HeapFree( GetProcessHeap(), 0, power_info ); } /* create the DynData registry keys */ static void create_dynamic_registry_keys(void) { static const WCHAR StatDataW[] = {'P','e','r','f','S','t','a','t','s','\\', 'S','t','a','t','D','a','t','a',0}; static const WCHAR ConfigManagerW[] = {'C','o','n','f','i','g',' ','M','a','n','a','g','e','r','\\', 'E','n','u','m',0}; HKEY key; if (!RegCreateKeyExW( HKEY_DYN_DATA, StatDataW, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL )) RegCloseKey( key ); if (!RegCreateKeyExW( HKEY_DYN_DATA, ConfigManagerW, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL )) RegCloseKey( key ); } /* create the platform-specific environment registry keys */ static void create_environment_registry_keys( void ) { static const WCHAR EnvironW[] = {'S','y','s','t','e','m','\\', 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\', 'C','o','n','t','r','o','l','\\', 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\', 'E','n','v','i','r','o','n','m','e','n','t',0}; static const WCHAR NumProcW[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0}; static const WCHAR ProcArchW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0}; static const WCHAR x86W[] = {'x','8','6',0}; static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0}; static const WCHAR amd64W[] = {'A','M','D','6','4',0}; static const WCHAR authenticamdW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; static const WCHAR commaW[] = {',',' ',0}; static const WCHAR ProcIdW[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0}; static const WCHAR ProcLvlW[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0}; static const WCHAR ProcRevW[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0}; static const WCHAR PercentDW[] = {'%','d',0}; static const WCHAR Percent04XW[] = {'%','0','4','x',0}; static const WCHAR ARMCpuDescrW[] = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d', ' ','R','e','v','i','s','i','o','n',' ','%','d',0}; HKEY env_key; SYSTEM_CPU_INFORMATION sci; WCHAR buffer[60], vendorid[13]; const WCHAR *arch, *parch; if (RegCreateKeyW( HKEY_LOCAL_MACHINE, EnvironW, &env_key )) return; get_vendorid( vendorid ); NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL ); sprintfW( buffer, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors ); set_reg_value( env_key, NumProcW, buffer ); switch (sci.Architecture) { case PROCESSOR_ARCHITECTURE_AMD64: arch = amd64W; parch = !strcmpW(vendorid, authenticamdW) ? amd64W : intel64W; break; case PROCESSOR_ARCHITECTURE_INTEL: default: arch = parch = x86W; break; } set_reg_value( env_key, ProcArchW, arch ); switch (sci.Architecture) { case PROCESSOR_ARCHITECTURE_ARM: case PROCESSOR_ARCHITECTURE_ARM64: sprintfW( buffer, ARMCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) ); break; case PROCESSOR_ARCHITECTURE_AMD64: case PROCESSOR_ARCHITECTURE_INTEL: default: get_identifier( buffer, parch ); strcatW( buffer, commaW ); strcatW( buffer, vendorid ); break; } set_reg_value( env_key, ProcIdW, buffer ); sprintfW( buffer, PercentDW, sci.Level ); set_reg_value( env_key, ProcLvlW, buffer ); sprintfW( buffer, Percent04XW, sci.Revision ); set_reg_value( env_key, ProcRevW, buffer ); RegCloseKey( env_key ); } static void create_volatile_environment_registry_key(void) { static const WCHAR VolatileEnvW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0}; static const WCHAR AppDataW[] = {'A','P','P','D','A','T','A',0}; static const WCHAR ClientNameW[] = {'C','L','I','E','N','T','N','A','M','E',0}; static const WCHAR HomeDriveW[] = {'H','O','M','E','D','R','I','V','E',0}; static const WCHAR HomePathW[] = {'H','O','M','E','P','A','T','H',0}; static const WCHAR HomeShareW[] = {'H','O','M','E','S','H','A','R','E',0}; static const WCHAR LocalAppDataW[] = {'L','O','C','A','L','A','P','P','D','A','T','A',0}; static const WCHAR LogonServerW[] = {'L','O','G','O','N','S','E','R','V','E','R',0}; static const WCHAR SessionNameW[] = {'S','E','S','S','I','O','N','N','A','M','E',0}; static const WCHAR UserNameW[] = {'U','S','E','R','N','A','M','E',0}; static const WCHAR UserDomainW[] = {'U','S','E','R','D','O','M','A','I','N',0}; static const WCHAR UserProfileW[] = {'U','S','E','R','P','R','O','F','I','L','E',0}; static const WCHAR ConsoleW[] = {'C','o','n','s','o','l','e',0}; static const WCHAR EmptyW[] = {0}; WCHAR path[MAX_PATH]; WCHAR computername[MAX_COMPUTERNAME_LENGTH + 1 + 2]; DWORD size; HKEY hkey; HRESULT hr; if (RegCreateKeyExW( HKEY_CURRENT_USER, VolatileEnvW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL )) return; hr = SHGetFolderPathW( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path ); if (SUCCEEDED(hr)) set_reg_value( hkey, AppDataW, path ); set_reg_value( hkey, ClientNameW, ConsoleW ); /* Write the profile path's drive letter and directory components into * HOMEDRIVE and HOMEPATH respectively. */ hr = SHGetFolderPathW( NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path ); if (SUCCEEDED(hr)) { set_reg_value( hkey, UserProfileW, path ); set_reg_value( hkey, HomePathW, path + 2 ); path[2] = '\0'; set_reg_value( hkey, HomeDriveW, path ); } size = ARRAY_SIZE(path); if (GetUserNameW( path, &size )) set_reg_value( hkey, UserNameW, path ); set_reg_value( hkey, HomeShareW, EmptyW ); hr = SHGetFolderPathW( NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path ); if (SUCCEEDED(hr)) set_reg_value( hkey, LocalAppDataW, path ); size = ARRAY_SIZE(computername) - 2; if (GetComputerNameW(&computername[2], &size)) { set_reg_value( hkey, UserDomainW, &computername[2] ); computername[0] = computername[1] = '\\'; set_reg_value( hkey, LogonServerW, computername ); } set_reg_value( hkey, SessionNameW, ConsoleW ); RegCloseKey( hkey ); } /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini. * Returns FALSE if there was an error, or otherwise if all is ok. */ static BOOL wininit(void) { static const WCHAR nulW[] = {'N','U','L',0}; static const WCHAR renameW[] = {'r','e','n','a','m','e',0}; static const WCHAR wininitW[] = {'w','i','n','i','n','i','t','.','i','n','i',0}; static const WCHAR wininitbakW[] = {'w','i','n','i','n','i','t','.','b','a','k',0}; WCHAR initial_buffer[1024]; WCHAR *str, *buffer = initial_buffer; DWORD size = ARRAY_SIZE(initial_buffer); DWORD res; for (;;) { if (!(res = GetPrivateProfileSectionW( renameW, buffer, size, wininitW ))) return TRUE; if (res < size - 2) break; if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer ); size *= 2; if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE; } for (str = buffer; *str; str += strlenW(str) + 1) { WCHAR *value; if (*str == ';') continue; /* comment */ if (!(value = strchrW( str, '=' ))) continue; /* split the line into key and value */ *value++ = 0; if (!lstrcmpiW( nulW, str )) { WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value) ); if( !DeleteFileW( value ) ) WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value) ); } else { WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) ); if( !MoveFileExW(value, str, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) ) WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) ); } str = value; } if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer ); if( !MoveFileExW( wininitW, wininitbakW, MOVEFILE_REPLACE_EXISTING) ) { WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() ); return FALSE; } return TRUE; } static BOOL pendingRename(void) { static const WCHAR ValueName[] = {'P','e','n','d','i','n','g', 'F','i','l','e','R','e','n','a','m','e', 'O','p','e','r','a','t','i','o','n','s',0}; static const WCHAR SessionW[] = { 'S','y','s','t','e','m','\\', 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\', 'C','o','n','t','r','o','l','\\', 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0}; WCHAR *buffer=NULL; const WCHAR *src=NULL, *dst=NULL; DWORD dataLength=0; HKEY hSession=NULL; DWORD res; WINE_TRACE("Entered\n"); if( (res=RegOpenKeyExW( HKEY_LOCAL_MACHINE, SessionW, 0, KEY_ALL_ACCESS, &hSession )) !=ERROR_SUCCESS ) { WINE_TRACE("The key was not found - skipping\n"); return TRUE; } res=RegQueryValueExW( hSession, ValueName, NULL, NULL /* The value type does not really interest us, as it is not truly a REG_MULTI_SZ anyways */, NULL, &dataLength ); if( res==ERROR_FILE_NOT_FOUND ) { /* No value - nothing to do. Great! */ WINE_TRACE("Value not present - nothing to rename\n"); res=TRUE; goto end; } if( res!=ERROR_SUCCESS ) { WINE_ERR("Couldn't query value's length (%d)\n", res ); res=FALSE; goto end; } buffer=HeapAlloc( GetProcessHeap(),0,dataLength ); if( buffer==NULL ) { WINE_ERR("Couldn't allocate %u bytes for the value\n", dataLength ); res=FALSE; goto end; } res=RegQueryValueExW( hSession, ValueName, NULL, NULL, (LPBYTE)buffer, &dataLength ); if( res!=ERROR_SUCCESS ) { WINE_ERR("Couldn't query value after successfully querying before (%u),\n" "please report to wine-devel@winehq.org\n", res); res=FALSE; goto end; } /* Make sure that the data is long enough and ends with two NULLs. This * simplifies the code later on. */ if( dataLength<2*sizeof(buffer[0]) || buffer[dataLength/sizeof(buffer[0])-1]!='\0' || buffer[dataLength/sizeof(buffer[0])-2]!='\0' ) { WINE_ERR("Improper value format - doesn't end with NULL\n"); res=FALSE; goto end; } for( src=buffer; (src-buffer)*sizeof(src[0])