From e0deb0c6275f771a2a357acc266697f223ae9584 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 19 Aug 2003 03:21:04 +0000 Subject: [PATCH] Replaced remaining calls to PROFILE_GetWineIniString/Bool by direct registry accesses. --- dlls/kernel/computername.c | 47 +++++++++-- documentation/samples/config | 2 +- files/directory.c | 58 ++++++++++--- files/dos_fs.c | 82 +++++++++++++++++-- files/drive.c | 153 +++++++++++++++++++++++----------- files/file.c | 46 ++++++++++- files/profile.c | 127 ----------------------------- include/file.h | 3 - misc/registry.c | 31 +++++-- msdos/ioports.c | 154 ++++++++++++++++++++--------------- 10 files changed, 419 insertions(+), 284 deletions(-) diff --git a/dlls/kernel/computername.c b/dlls/kernel/computername.c index 74a66cd7750..c9d65097a23 100644 --- a/dlls/kernel/computername.c +++ b/dlls/kernel/computername.c @@ -40,14 +40,9 @@ #include "wine/exception.h" #include "excpt.h" #include "wine/debug.h" -#include "file.h" WINE_DEFAULT_DEBUG_CHANNEL(computername); -/* Wine config options */ -static const WCHAR NetworkW[] = {'N','e','t','w','o','r','k',0}; -static const WCHAR UseDNSW[] = {'U','s','e','D','n','s','C','o','m','p','u','t','e','r','N','a','m','e',0}; - /* Registry key and value names */ static const WCHAR ComputerW[] = {'M','a','c','h','i','n','e','\\', 'S','y','s','t','e','m','\\', @@ -59,6 +54,8 @@ static const WCHAR ComputerNameW[] = {'C','o','m','p','u','t','e','r','N','a','m static const char default_ComputerName[] = "WINE"; +#define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1') + /* filter for page-fault exceptions */ static WINE_EXCEPTION_FILTER(page_fault) { @@ -189,6 +186,41 @@ inline static void _init_attr ( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *name ) attr->SecurityQualityOfService = NULL; } +/*********************************************************************** + * get_use_dns_option + */ +static BOOL get_use_dns_option(void) +{ + static const WCHAR NetworkW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','N','e','t','w','o','r','k',0}; + static const WCHAR UseDNSW[] = {'U','s','e','D','n','s','C','o','m','p','u','t','e','r','N','a','m','e',0}; + + char tmp[80]; + HKEY hkey; + DWORD dummy; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; + BOOL ret = TRUE; + + _init_attr( &attr, &nameW ); + RtlInitUnicodeString( &nameW, NetworkW ); + + if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) + { + RtlInitUnicodeString( &nameW, UseDNSW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + ret = IS_OPTION_TRUE( str[0] ); + } + NtClose( hkey ); + } + return ret; +} + + /*********************************************************************** * COMPUTERNAME_Init (INTERNAL) */ @@ -216,8 +248,7 @@ void COMPUTERNAME_Init (void) st = NtQueryValueKey( hsubkey, &nameW, KeyValuePartialInformation, buf, len, &len ); - if ( st == STATUS_OBJECT_NAME_NOT_FOUND || - ( st == STATUS_SUCCESS && PROFILE_GetWineIniBool( NetworkW, UseDNSW, 1 ) ) ) + if ( st == STATUS_OBJECT_NAME_NOT_FOUND || ( st == STATUS_SUCCESS && get_use_dns_option())) { char hbuf[256]; int hlen = sizeof (hbuf); @@ -539,7 +570,7 @@ BOOL WINAPI SetComputerNameW( LPCWSTR lpComputerName ) int i; NTSTATUS st = STATUS_INTERNAL_ERROR; - if ( PROFILE_GetWineIniBool ( NetworkW, UseDNSW, 1 ) ) + if (get_use_dns_option()) { /* This check isn't necessary, but may help debugging problems. */ WARN( "Disabled by Wine Configuration.\n" ); diff --git a/documentation/samples/config b/documentation/samples/config index d19e30a41ea..f7c84aa6da0 100644 --- a/documentation/samples/config +++ b/documentation/samples/config @@ -51,7 +51,7 @@ WINE REGISTRY Version 2 "Filesystem" = "win95" [Drive F] -"Path" = "${HOME}" +"Path" = "%HOME%" "Type" = "network" "Label" = "Home" "Filesystem" = "win95" diff --git a/files/directory.c b/files/directory.c index 1fc1accaf53..7f56786b769 100644 --- a/files/directory.c +++ b/files/directory.c @@ -69,14 +69,19 @@ inline static int FILE_contains_pathW (LPCWSTR name) * * Get a path name from the wine.ini file and make sure it is valid. */ -static int DIR_GetPath( LPCWSTR keyname, LPCWSTR defval, DOS_FULL_NAME *full_name, +static int DIR_GetPath( HKEY hkey, LPCWSTR keyname, LPCWSTR defval, DOS_FULL_NAME *full_name, LPWSTR longname, INT longname_len, BOOL warn ) { - WCHAR path[MAX_PATHNAME_LEN]; + UNICODE_STRING nameW; + DWORD dummy; + WCHAR tmp[MAX_PATHNAME_LEN]; BY_HANDLE_FILE_INFORMATION info; + const WCHAR *path = defval; const char *mess = "does not exist"; - PROFILE_GetWineIniString( wineW, keyname, defval, path, MAX_PATHNAME_LEN ); + RtlInitUnicodeString( &nameW, keyname ); + if (hkey && !NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + path = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; if (!DOSFS_GetFullName( path, TRUE, full_name ) || (!FILE_Stat( full_name->long_name, &info, NULL ) && (mess=strerror(errno)))|| @@ -97,11 +102,18 @@ static int DIR_GetPath( LPCWSTR keyname, LPCWSTR defval, DOS_FULL_NAME *full_nam */ int DIR_Init(void) { + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; + HKEY hkey; char path[MAX_PATHNAME_LEN]; WCHAR longpath[MAX_PATHNAME_LEN]; DOS_FULL_NAME tmp_dir, profile_dir; int drive; const char *cwd; + static const WCHAR wineW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','W','i','n','e',0}; static const WCHAR windowsW[] = {'w','i','n','d','o','w','s',0}; static const WCHAR systemW[] = {'s','y','s','t','e','m',0}; static const WCHAR tempW[] = {'t','e','m','p',0}; @@ -144,11 +156,22 @@ int DIR_Init(void) chdir("/"); /* change to root directory so as not to lock cdroms */ } - if (!(DIR_GetPath( windowsW, windows_dirW, &DIR_Windows, longpath, MAX_PATHNAME_LEN, TRUE )) || - !(DIR_GetPath( systemW, system_dirW, &DIR_System, longpath, MAX_PATHNAME_LEN, TRUE )) || - !(DIR_GetPath( tempW, windows_dirW, &tmp_dir, longpath, MAX_PATHNAME_LEN, TRUE ))) + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + + RtlInitUnicodeString( &nameW, wineW ); + if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) hkey = 0; + + if (!(DIR_GetPath( hkey, windowsW, windows_dirW, &DIR_Windows, longpath, MAX_PATHNAME_LEN, TRUE )) || + !(DIR_GetPath( hkey, systemW, system_dirW, &DIR_System, longpath, MAX_PATHNAME_LEN, TRUE )) || + !(DIR_GetPath( hkey, tempW, windows_dirW, &tmp_dir, longpath, MAX_PATHNAME_LEN, TRUE ))) { PROFILE_UsageWineIni(); + if (hkey) NtClose( hkey ); return 0; } if (-1 == access( tmp_dir.long_name, W_OK )) @@ -181,16 +204,27 @@ int DIR_Init(void) } /* set PATH only if not set already */ - if (!GetEnvironmentVariableW( path_capsW, longpath, MAX_PATHNAME_LEN )) + if (!GetEnvironmentVariableW( path_capsW, NULL, 0 )) { - PROFILE_GetWineIniString(wineW, pathW, path_dirW, longpath, MAX_PATHNAME_LEN); - if (strchrW(longpath, '/')) + WCHAR tmp[MAX_PATHNAME_LEN]; + DWORD dummy; + const WCHAR *path = path_dirW; + + RtlInitUnicodeString( &nameW, pathW ); + if (hkey && !NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, + tmp, sizeof(tmp), &dummy )) + { + path = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + } + + if (strchrW(path, '/')) { MESSAGE("Fix your wine config to use DOS drive syntax in [wine] 'Path=' statement! (no '/' allowed)\n"); PROFILE_UsageWineIni(); ExitProcess(1); } - SetEnvironmentVariableW( path_capsW, longpath ); + SetEnvironmentVariableW( path_capsW, path ); + TRACE("Path = %s\n", debugstr_w(path) ); } SetEnvironmentVariableW( temp_capsW, tmp_dir.short_name ); @@ -204,11 +238,10 @@ int DIR_Init(void) debugstr_w(DIR_System.short_name), DIR_System.long_name ); TRACE("TempDir = %s (%s)\n", debugstr_w(tmp_dir.short_name), tmp_dir.long_name ); - TRACE("Path = %s\n", debugstr_w(longpath) ); TRACE("Cwd = %c:\\%s\n", 'A' + drive, debugstr_w(DRIVE_GetDosCwd(drive)) ); - if (DIR_GetPath( profileW, empty_strW, &profile_dir, longpath, MAX_PATHNAME_LEN, FALSE )) + if (DIR_GetPath( hkey, profileW, empty_strW, &profile_dir, longpath, MAX_PATHNAME_LEN, FALSE )) { TRACE("USERPROFILE= %s\n", debugstr_w(longpath) ); SetEnvironmentVariableW( userprofileW, longpath ); @@ -216,6 +249,7 @@ int DIR_Init(void) TRACE("SYSTEMROOT = %s\n", debugstr_w(DIR_Windows.short_name) ); SetEnvironmentVariableW( systemrootW, DIR_Windows.short_name ); + if (hkey) NtClose( hkey ); return 1; } diff --git a/files/dos_fs.c b/files/dos_fs.c index 569d14ef45b..53c0602092b 100644 --- a/files/dos_fs.c +++ b/files/dos_fs.c @@ -84,6 +84,8 @@ typedef struct #undef VFAT_IOCTL_READDIR_BOTH /* just in case... */ #endif /* linux */ +#define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1') + /* Chars we don't want to see in DOS file names */ #define INVALID_DOS_CHARS "*?<>|\"+=,;[] \345" @@ -854,17 +856,41 @@ const DOS_DEVICE *DOSFS_GetDeviceByHandle( HANDLE hFile ) static HANDLE DOSFS_CreateCommPort(LPCWSTR name, DWORD access, DWORD attributes, LPSECURITY_ATTRIBUTES sa) { HANDLE ret; + HKEY hkey; + DWORD dummy; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; + WCHAR *devnameW; + char tmp[128]; char devname[40]; - WCHAR devnameW[40]; - static const WCHAR serialportsW[] = {'s','e','r','i','a','l','p','o','r','t','s',0}; - static const WCHAR empty_strW[] = { 0 }; + + static const WCHAR serialportsW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\', + 'S','e','r','i','a','l','P','o','r','t','s',0}; TRACE_(file)("%s %lx %lx\n", debugstr_w(name), access, attributes); - PROFILE_GetWineIniString(serialportsW, name, empty_strW, devnameW, 40); - if(!devnameW[0]) - return 0; + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + RtlInitUnicodeString( &nameW, serialportsW ); + if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return 0; + + RtlInitUnicodeString( &nameW, name ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + devnameW = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + else + devnameW = NULL; + + NtClose( hkey ); + + if (!devnameW) return 0; WideCharToMultiByte(CP_ACP, 0, devnameW, -1, devname, sizeof(devname), NULL, NULL); TRACE("opening %s as %s\n", devname, debugstr_w(name)); @@ -1692,6 +1718,46 @@ BOOL WINAPI wine_get_unix_file_name( LPCSTR dos, LPSTR buffer, DWORD len ) } +/*********************************************************************** + * get_show_dir_symlinks_option + */ +static BOOL get_show_dir_symlinks_option(void) +{ + static const WCHAR WineW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','W','i','n','e',0}; + static const WCHAR ShowDirSymlinksW[] = {'S','h','o','w','D','i','r','S','y','m','l','i','n','k','s',0}; + + char tmp[80]; + HKEY hkey; + DWORD dummy; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; + BOOL ret = FALSE; + + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + RtlInitUnicodeString( &nameW, WineW ); + + if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) + { + RtlInitUnicodeString( &nameW, ShowDirSymlinksW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + ret = IS_OPTION_TRUE( str[0] ); + } + NtClose( hkey ); + } + return ret; +} + + /*********************************************************************** * DOSFS_FindNextEx */ @@ -1774,11 +1840,9 @@ static int DOSFS_FindNextEx( FIND_FIRST_INFO *info, WIN32_FIND_DATAW *entry ) } if (is_symlink && (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - static const WCHAR wineW[] = {'w','i','n','e',0}; - static const WCHAR ShowDirSymlinksW[] = {'S','h','o','w','D','i','r','S','y','m','l','i','n','k','s',0}; static int show_dir_symlinks = -1; if (show_dir_symlinks == -1) - show_dir_symlinks = PROFILE_GetWineIniBool(wineW, ShowDirSymlinksW, 0); + show_dir_symlinks = get_show_dir_symlinks_option(); if (!show_dir_symlinks) continue; } diff --git a/files/drive.c b/files/drive.c index d873f54842e..bf29d75c6f8 100644 --- a/files/drive.c +++ b/files/drive.c @@ -138,27 +138,23 @@ inline static char *heap_strdup( const char *str ) return p; } +#define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1') + extern void CDROM_InitRegistry(int dev); /*********************************************************************** * DRIVE_GetDriveType */ -static UINT DRIVE_GetDriveType( LPCWSTR name ) +static inline UINT DRIVE_GetDriveType( INT drive, LPCWSTR value ) { - WCHAR buffer[20]; int i; - static const WCHAR TypeW[] = {'T','y','p','e',0}; - static const WCHAR hdW[] = {'h','d',0}; - PROFILE_GetWineIniString( name, TypeW, hdW, buffer, 20 ); - if(!buffer[0]) - strcpyW(buffer,hdW); for (i = 0; i < sizeof(DRIVE_Types)/sizeof(DRIVE_Types[0]); i++) { - if (!strcmpiW( buffer, DRIVE_Types[i] )) return i; + if (!strcmpiW( value, DRIVE_Types[i] )) return i; } - MESSAGE("%s: unknown drive type %s, defaulting to 'hd'.\n", - debugstr_w(name), debugstr_w(buffer) ); + MESSAGE("Drive %c: unknown drive type %s, defaulting to 'hd'.\n", + 'A' + drive, debugstr_w(value) ); return DRIVE_FIXED; } @@ -166,14 +162,14 @@ static UINT DRIVE_GetDriveType( LPCWSTR name ) /*********************************************************************** * DRIVE_GetFSFlags */ -static UINT DRIVE_GetFSFlags( LPCWSTR name, LPCWSTR value ) +static UINT DRIVE_GetFSFlags( INT drive, LPCWSTR value ) { const FS_DESCR *descr; for (descr = DRIVE_Filesystems; *descr->name; descr++) if (!strcmpiW( value, descr->name )) return descr->flags; - MESSAGE("%s: unknown filesystem type %s, defaulting to 'win95'.\n", - debugstr_w(name), debugstr_w(value) ); + MESSAGE("Drive %c: unknown filesystem type %s, defaulting to 'win95'.\n", + 'A' + drive, debugstr_w(value) ); return DRIVE_CASE_PRESERVING; } @@ -184,36 +180,59 @@ static UINT DRIVE_GetFSFlags( LPCWSTR name, LPCWSTR value ) int DRIVE_Init(void) { int i, len, count = 0; - WCHAR name[] = {'D','r','i','v','e',' ','A',0}; + WCHAR driveW[] = {'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','D','r','i','v','e',' ','A',0}; WCHAR drive_env[] = {'=','A',':',0}; WCHAR path[MAX_PATHNAME_LEN]; - WCHAR buffer[80]; + char tmp[MAX_PATHNAME_LEN*sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION)]; struct stat drive_stat_buffer; WCHAR *p; DOSDRIVE *drive; + HKEY hkey; + DWORD dummy; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; + static const WCHAR PathW[] = {'P','a','t','h',0}; - static const WCHAR empty_strW[] = { 0 }; static const WCHAR CodepageW[] = {'C','o','d','e','p','a','g','e',0}; static const WCHAR LabelW[] = {'L','a','b','e','l',0}; static const WCHAR SerialW[] = {'S','e','r','i','a','l',0}; - static const WCHAR zeroW[] = {'0',0}; - static const WCHAR def_serialW[] = {'1','2','3','4','5','6','7','8',0}; + static const WCHAR TypeW[] = {'T','y','p','e',0}; static const WCHAR FilesystemW[] = {'F','i','l','e','s','y','s','t','e','m',0}; - static const WCHAR win95W[] = {'w','i','n','9','5',0}; static const WCHAR DeviceW[] = {'D','e','v','i','c','e',0}; static const WCHAR ReadVolInfoW[] = {'R','e','a','d','V','o','l','I','n','f','o',0}; static const WCHAR FailReadOnlyW[] = {'F','a','i','l','R','e','a','d','O','n','l','y',0}; static const WCHAR driveC_labelW[] = {'D','r','i','v','e',' ','C',' ',' ',' ',' ',0}; - for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, name[6]++, drive++) + + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + + for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, drive++) { - PROFILE_GetWineIniString( name, PathW, empty_strW, path, MAX_PATHNAME_LEN ); - if (path[0]) + RtlInitUnicodeString( &nameW, driveW ); + nameW.Buffer[(nameW.Length / sizeof(WCHAR)) - 1] = 'A' + i; + if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) continue; + + /* Get the code page number */ + RtlInitUnicodeString( &nameW, CodepageW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) { - /* Get the code page number */ - PROFILE_GetWineIniString( name, CodepageW, zeroW, /* 0 == CP_ACP */ - buffer, 80 ); - drive->codepage = strtolW( buffer, NULL, 10 ); + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + drive->codepage = strtolW( data, NULL, 10 ); + } + + /* Get the root path */ + RtlInitUnicodeString( &nameW, PathW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + ExpandEnvironmentStringsW( data, path, sizeof(path)/sizeof(WCHAR) ); p = path + strlenW(path) - 1; while ((p > path) && (*p == '/')) *p-- = '\0'; @@ -232,7 +251,8 @@ int DRIVE_Init(void) len += WideCharToMultiByte(drive->codepage, 0, path, -1, NULL, 0, NULL, NULL) + 2; drive->root = HeapAlloc( GetProcessHeap(), 0, len ); len -= sprintf( drive->root, "%s/", config ); - WideCharToMultiByte(drive->codepage, 0, path, -1, drive->root + strlen(drive->root), len, NULL, NULL); + WideCharToMultiByte(drive->codepage, 0, path, -1, + drive->root + strlen(drive->root), len, NULL, NULL); } if (stat( drive->root, &drive_stat_buffer )) @@ -241,7 +261,7 @@ int DRIVE_Init(void) drive->root, strerror(errno), 'A' + i); HeapFree( GetProcessHeap(), 0, drive->root ); drive->root = NULL; - continue; + goto next; } if (!S_ISDIR(drive_stat_buffer.st_mode)) { @@ -249,19 +269,32 @@ int DRIVE_Init(void) drive->root, 'A' + i ); HeapFree( GetProcessHeap(), 0, drive->root ); drive->root = NULL; - continue; + goto next; } drive->dos_cwd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(drive->dos_cwd[0])); drive->unix_cwd = heap_strdup( "" ); - drive->type = DRIVE_GetDriveType( name ); drive->device = NULL; drive->flags = 0; drive->dev = drive_stat_buffer.st_dev; drive->ino = drive_stat_buffer.st_ino; + /* Get the drive type */ + RtlInitUnicodeString( &nameW, TypeW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + drive->type = DRIVE_GetDriveType( i, data ); + } + else drive->type = DRIVE_FIXED; + /* Get the drive label */ - PROFILE_GetWineIniString( name, LabelW, empty_strW, drive->label_conf, 12 ); + RtlInitUnicodeString( &nameW, LabelW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + lstrcpynW( drive->label_conf, data, 12 ); + } if ((len = strlenW(drive->label_conf)) < 11) { /* Pad label with spaces */ @@ -270,51 +303,73 @@ int DRIVE_Init(void) } /* Get the serial number */ - PROFILE_GetWineIniString( name, SerialW, def_serialW, buffer, 80 ); - drive->serial_conf = strtoulW( buffer, NULL, 16 ); + RtlInitUnicodeString( &nameW, SerialW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + drive->serial_conf = strtoulW( data, NULL, 16 ); + } + else drive->serial_conf = 12345678; /* Get the filesystem type */ - PROFILE_GetWineIniString( name, FilesystemW, win95W, buffer, 80 ); - drive->flags = DRIVE_GetFSFlags( name, buffer ); + RtlInitUnicodeString( &nameW, FilesystemW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + drive->flags = DRIVE_GetFSFlags( i, data ); + } + else drive->flags = DRIVE_CASE_PRESERVING; /* Get the device */ - PROFILE_GetWineIniString( name, DeviceW, empty_strW, buffer, 80 ); - if (buffer[0]) - { - int cd_fd; - len = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL); + RtlInitUnicodeString( &nameW, DeviceW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL); drive->device = HeapAlloc(GetProcessHeap(), 0, len); - WideCharToMultiByte(drive->codepage, 0, buffer, -1, drive->device, len, NULL, NULL); + WideCharToMultiByte(drive->codepage, 0, data, -1, drive->device, len, NULL, NULL); - if (PROFILE_GetWineIniBool( name, ReadVolInfoW, 1)) - drive->flags |= DRIVE_READ_VOL_INFO; + RtlInitUnicodeString( &nameW, ReadVolInfoW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + if (IS_OPTION_TRUE(data[0])) drive->flags |= DRIVE_READ_VOL_INFO; + } + else drive->flags |= DRIVE_READ_VOL_INFO; if (drive->type == DRIVE_CDROM) { + int cd_fd; if ((cd_fd = open(drive->device, O_RDONLY|O_NONBLOCK)) != -1) { CDROM_InitRegistry(cd_fd); close(cd_fd); } } - } + } /* Get the FailReadOnly flag */ - if (PROFILE_GetWineIniBool( name, FailReadOnlyW, 0 )) - drive->flags |= DRIVE_FAIL_READ_ONLY; + RtlInitUnicodeString( &nameW, FailReadOnlyW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + if (IS_OPTION_TRUE(data[0])) drive->flags |= DRIVE_FAIL_READ_ONLY; + } /* Make the first hard disk the current drive */ if ((DRIVE_CurDrive == -1) && (drive->type == DRIVE_FIXED)) DRIVE_CurDrive = i; count++; - TRACE("%s: path=%s type=%s label=%s serial=%08lx " + TRACE("Drive %c: path=%s type=%s label=%s serial=%08lx " "flags=%08x codepage=%u dev=%x ino=%x\n", - debugstr_w(name), drive->root, debugstr_w(DRIVE_Types[drive->type]), + 'A' + i, drive->root, debugstr_w(DRIVE_Types[drive->type]), debugstr_w(drive->label_conf), drive->serial_conf, drive->flags, drive->codepage, (int)drive->dev, (int)drive->ino ); } - else WARN("%s: not defined\n", debugstr_w(name) ); + + next: + NtClose( hkey ); } if (!count) diff --git a/files/file.c b/files/file.c index a53ed8d3a2c..3d2ad8b0b8c 100644 --- a/files/file.c +++ b/files/file.c @@ -81,6 +81,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(file); #define MAP_ANON MAP_ANONYMOUS #endif +#define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1') + HANDLE dos_handles[DOS_TABLE_SIZE]; mode_t FILE_umask; @@ -706,6 +708,46 @@ static void FILE_FillInfo( struct stat *st, BY_HANDLE_FILE_INFORMATION *info ) } +/*********************************************************************** + * get_show_dot_files_option + */ +static BOOL get_show_dot_files_option(void) +{ + static const WCHAR WineW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','W','i','n','e',0}; + static const WCHAR ShowDotFilesW[] = {'S','h','o','w','D','o','t','F','i','l','e','s',0}; + + char tmp[80]; + HKEY hkey; + DWORD dummy; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; + BOOL ret = FALSE; + + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + RtlInitUnicodeString( &nameW, WineW ); + + if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) + { + RtlInitUnicodeString( &nameW, ShowDotFilesW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + ret = IS_OPTION_TRUE( str[0] ); + } + NtClose( hkey ); + } + return ret; +} + + /*********************************************************************** * FILE_Stat * @@ -742,11 +784,9 @@ BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info, BOOL *is_syml p = p ? p + 1 : unixName; if (*p == '.' && *(p+1) && (*(p+1) != '.' || *(p+2))) { - static const WCHAR wineW[] = {'w','i','n','e',0}; - static const WCHAR ShowDotFilesW[] = {'S','h','o','w','D','o','t','F','i','l','e','s',0}; static int show_dot_files = -1; if (show_dot_files == -1) - show_dot_files = PROFILE_GetWineIniBool(wineW, ShowDotFilesW, 0); + show_dot_files = get_show_dot_files_option(); if (!show_dot_files) info->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN; } diff --git a/files/profile.c b/files/profile.c index 8d7f6e1d120..6630487dada 100644 --- a/files/profile.c +++ b/files/profile.c @@ -904,133 +904,6 @@ static BOOL PROFILE_SetString( LPCWSTR section_name, LPCWSTR key_name, } -/*********************************************************************** - * get_profile_key - */ -static HKEY get_profile_key(void) -{ - static HKEY profile_key; - - if (!profile_key) - { - OBJECT_ATTRIBUTES attr; - UNICODE_STRING nameW; - HKEY hkey; - - attr.Length = sizeof(attr); - attr.RootDirectory = 0; - attr.ObjectName = &nameW; - attr.Attributes = 0; - attr.SecurityDescriptor = NULL; - attr.SecurityQualityOfService = NULL; - - if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\Software\\Wine\\Wine\\Config" ) || - NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL )) - { - ERR("Cannot create config registry key\n" ); - ExitProcess( 1 ); - } - RtlFreeUnicodeString( &nameW ); - - if (InterlockedCompareExchangePointer( (void **)&profile_key, hkey, 0 )) - NtClose( hkey ); /* somebody beat us to it */ - } - return profile_key; -} - - -/*********************************************************************** - * PROFILE_GetWineIniString - * - * Get a config string from the wine.ini file. - */ -int PROFILE_GetWineIniString( LPCWSTR section, LPCWSTR key_name, - LPCWSTR def, LPWSTR buffer, int len ) -{ - HKEY hkey; - NTSTATUS err; - OBJECT_ATTRIBUTES attr; - UNICODE_STRING nameW; - - attr.Length = sizeof(attr); - attr.RootDirectory = get_profile_key(); - attr.ObjectName = &nameW; - attr.Attributes = 0; - attr.SecurityDescriptor = NULL; - attr.SecurityQualityOfService = NULL; - RtlInitUnicodeString( &nameW, section ); - if (!(err = NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))) - { - char tmp[PROFILE_MAX_LINE_LEN*sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION)]; - DWORD count; - - RtlInitUnicodeString( &nameW, key_name ); - if (!(err = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, - tmp, sizeof(tmp), &count ))) - { - WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; - PROFILE_CopyEntry( buffer, str, len, TRUE, TRUE ); - } - NtClose( hkey ); - } - - if (err) PROFILE_CopyEntry( buffer, def, len, TRUE, TRUE ); - TRACE( "(%s,%s,%s): returning %s\n", debugstr_w(section), - debugstr_w(key_name), debugstr_w(def), debugstr_w(buffer) ); - return strlenW(buffer); -} - - -/****************************************************************************** - * - * PROFILE_GetWineIniBool - * - * Reads a boolean value from the wine.ini file. This function attempts to - * be user-friendly by accepting 'n', 'N' (no), 'f', 'F' (false), or '0' - * (zero) for false, 'y', 'Y' (yes), 't', 'T' (true), or '1' (one) for - * true. Anything else results in the return of the default value. - * - * This function uses 1 to indicate true, and 0 for false. You can check - * for existence by setting def to something other than 0 or 1 and - * examining the return value. - */ -int PROFILE_GetWineIniBool( LPCWSTR section, LPCWSTR key_name, int def ) -{ - static const WCHAR def_valueW[] = {'~',0}; - WCHAR key_value[2]; - int retval; - - PROFILE_GetWineIniString(section, key_name, def_valueW, key_value, 2); - - switch(key_value[0]) { - case 'n': - case 'N': - case 'f': - case 'F': - case '0': - retval = 0; - break; - - case 'y': - case 'Y': - case 't': - case 'T': - case '1': - retval = 1; - break; - - default: - retval = def; - } - - TRACE("(%s, %s, %s), [%c], ret %s\n", debugstr_w(section), debugstr_w(key_name), - def ? "TRUE" : "FALSE", key_value[0], - retval ? "TRUE" : "FALSE"); - - return retval; -} - - /*********************************************************************** * PROFILE_UsageWineIni * diff --git a/include/file.h b/include/file.h index c0eda90741d..730500b859e 100644 --- a/include/file.h +++ b/include/file.h @@ -111,9 +111,6 @@ extern int DOSFS_FindNext( const char *path, const char *short_mask, /* profile.c */ extern void PROFILE_UsageWineIni(void); -extern int PROFILE_GetWineIniString( LPCWSTR section, LPCWSTR key_name, - LPCWSTR def, LPWSTR buffer, int len ); -extern int PROFILE_GetWineIniBool( LPCWSTR section, LPCWSTR key_name, int def ); /* win32/device.c */ extern HANDLE DEVICE_Open( LPCWSTR filename, DWORD access, LPSECURITY_ATTRIBUTES sa ); diff --git a/misc/registry.c b/misc/registry.c index 438376a595d..fe93b2e6597 100644 --- a/misc/registry.c +++ b/misc/registry.c @@ -1406,11 +1406,15 @@ static void _load_windows_registry( HKEY hkey_local_machine, HKEY hkey_current_u WCHAR path[MAX_PATHNAME_LEN]; OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; - HKEY hkey; + HKEY hkey, profile_key; + char tmp[1024]; + DWORD dummy; - static const WCHAR WineW[] = {'W','i','n','e',0}; + static const WCHAR WineW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','W','i','n','e',0}; static const WCHAR ProfileW[] = {'P','r','o','f','i','l','e',0}; - static const WCHAR empty_strW[] = { 0 }; static const WCHAR System[] = {'M','a','c','h','i','n','e','\\','S','y','s','t','e','m',0}; static const WCHAR Software[] = {'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e',0}; static const WCHAR Clone[] = {'M','a','c','h','i','n','e','\\', @@ -1424,12 +1428,14 @@ static void _load_windows_registry( HKEY hkey_local_machine, HKEY hkey_current_u attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; + RtlInitUnicodeString( &nameW, WineW ); + if (NtCreateKey( &profile_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) profile_key = 0; + GetWindowsDirectoryW(windir, MAX_PATHNAME_LEN); reg_type = _get_reg_type(); switch (reg_type) { case REG_WINNT: { - HKEY hkey; static const WCHAR ntuser_datW[] = {'\\','n','t','u','s','e','r','.','d','a','t',0}; static const WCHAR defaultW[] = {'\\','s','y','s','t','e','m','3','2','\\','c','o','n','f','i','g','\\','d','e','f','a','u','l','t',0}; static const WCHAR systemW[] = {'\\','s','y','s','t','e','m','3','2','\\','c','o','n','f','i','g','\\','s','y','s','t','e','m',0}; @@ -1438,7 +1444,11 @@ static void _load_windows_registry( HKEY hkey_local_machine, HKEY hkey_current_u static const WCHAR securityW[] = {'\\','s','y','s','t','e','m','3','2','\\','c','o','n','f','i','g','\\','s','e','c','u','r','i','t','y',0}; /* user specific ntuser.dat */ - if (PROFILE_GetWineIniString( WineW, ProfileW, empty_strW, path, MAX_PATHNAME_LEN )) { + RtlInitUnicodeString( &nameW, ProfileW ); + if (profile_key && !NtQueryValueKey( profile_key, &nameW, KeyValuePartialInformation, + tmp, sizeof(tmp), &dummy )) + { + strcpyW(path, (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data); strcatW(path, ntuser_datW); _convert_and_load_native_registry(path,hkey_current_user,REG_WINNT,1); } @@ -1514,9 +1524,13 @@ static void _load_windows_registry( HKEY hkey_local_machine, HKEY hkey_current_u NtClose( hkey ); } - if (PROFILE_GetWineIniString(WineW, ProfileW, empty_strW, path, MAX_PATHNAME_LEN)) { - /* user specific user.dat */ - strcatW(path, user_datW); + RtlInitUnicodeString( &nameW, ProfileW ); + if (profile_key && !NtQueryValueKey( profile_key, &nameW, KeyValuePartialInformation, + tmp, sizeof(tmp), &dummy )) + { + /* user specific user.dat */ + strcpyW(path, (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data); + strcatW(path, user_datW); _convert_and_load_native_registry(path,hkey_current_user,REG_WIN95,1); /* default user.dat */ @@ -1547,6 +1561,7 @@ static void _load_windows_registry( HKEY hkey_local_machine, HKEY hkey_current_u break; } + if (profile_key) NtClose( profile_key ); } /* load home registry files (stored in ~/.wine) [Internal] */ diff --git a/msdos/ioports.c b/msdos/ioports.c index f02e6aae7cb..21d72845474 100644 --- a/msdos/ioports.c +++ b/msdos/ioports.c @@ -38,9 +38,10 @@ #endif #include "windef.h" #include "winnls.h" +#include "winternl.h" #include "callback.h" -#include "file.h" #include "miscemu.h" +#include "wine/unicode.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(int); @@ -162,54 +163,54 @@ static void set_IO_permissions(int val1, int val, char rw) * Helper function for IO_port_init */ -static void do_IO_port_init_read_or_write(char* temp, char rw) +static void do_IO_port_init_read_or_write(const WCHAR *str, char rw) { - int val, val1, i, len; - if (!strcasecmp(temp, "all")) { - MESSAGE("Warning!!! Granting FULL IO port access to" - " windoze programs!\nWarning!!! " - "*** THIS IS NOT AT ALL " - "RECOMMENDED!!! ***\n"); - for (i=0; i < sizeof(port_permissions); i++) - port_permissions[i] |= rw; + int val, val1, i; + WCHAR *end; + static const WCHAR allW[] = {'a','l','l',0}; - } else if (!(!strcmp(temp, "*") || *temp == '\0')) { - len = strlen(temp); - val = -1; - val1 = -1; - for (i = 0; i < len; i++) { - switch (temp[i]) { - case '0': - if (temp[i+1] == 'x' || temp[i+1] == 'X') { - sscanf(temp+i, "%x", &val); - i += 2; - } else { - sscanf(temp+i, "%d", &val); - } - while (isxdigit(temp[i])) - i++; - i--; - break; - case ',': - case ' ': - case '\t': - set_IO_permissions(val1, val, rw); - val1 = -1; val = -1; - break; - case '-': - val1 = val; - if (val1 == -1) val1 = 0; - break; - default: - if (temp[i] >= '0' && temp[i] <= '9') { - sscanf(temp+i, "%d", &val); - while (isdigit(temp[i])) - i++; - } - } - } - set_IO_permissions(val1, val, rw); - } + if (!strcmpiW(str, allW)) + { + for (i=0; i < sizeof(port_permissions); i++) + port_permissions[i] |= rw; + } + else + { + val = -1; + val1 = -1; + while (*str) + { + switch(*str) + { + case ',': + case ' ': + case '\t': + set_IO_permissions(val1, val, rw); + val1 = -1; + val = -1; + str++; + break; + case '-': + val1 = val; + if (val1 == -1) val1 = 0; + str++; + break; + default: + if (isdigitW(*str)) + { + val = strtoulW( str, &end, 0 ); + if (end == str) + { + val = -1; + str++; + } + else str = end; + } + break; + } + } + set_IO_permissions(val1, val, rw); + } } static inline BYTE inb( WORD port ) @@ -250,25 +251,50 @@ static inline void outl( DWORD value, WORD port ) static void IO_port_init(void) { - char temp[1024]; - WCHAR tempW[1024]; - static const WCHAR portsW[] = {'p','o','r','t','s',0}; - static const WCHAR readW[] = {'r','e','a','d',0}; - static const WCHAR writeW[] = {'w','r','i','t','e',0}; - static const WCHAR asteriskW[] = {'*',0}; + char tmp[1024]; + HKEY hkey; + DWORD dummy; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW; - do_direct_port_access = 0; - /* Can we do that? */ - if (!iopl(3)) { - iopl(0); + static const WCHAR portsW[] = {'M','a','c','h','i','n','e','\\', + 'S','o','f','t','w','a','r','e','\\', + 'W','i','n','e','\\','W','i','n','e','\\', + 'C','o','n','f','i','g','\\','P','o','r','t','s',0}; + static const WCHAR readW[] = {'r','e','a','d',0}; + static const WCHAR writeW[] = {'w','r','i','t','e',0}; - PROFILE_GetWineIniString( portsW, readW, asteriskW, tempW, 1024 ); - WideCharToMultiByte(CP_ACP, 0, tempW, -1, temp, 1024, NULL, NULL); - do_IO_port_init_read_or_write(temp, IO_READ); - PROFILE_GetWineIniString( portsW, writeW, asteriskW, tempW, 1024 ); - WideCharToMultiByte(CP_ACP, 0, tempW, -1, temp, 1024, NULL, NULL); - do_IO_port_init_read_or_write(temp, IO_WRITE); - } + do_direct_port_access = 0; + /* Can we do that? */ + if (!iopl(3)) + { + iopl(0); + + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + RtlInitUnicodeString( &nameW, portsW ); + + if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) + { + RtlInitUnicodeString( &nameW, readW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + do_IO_port_init_read_or_write(str, IO_READ); + } + RtlInitUnicodeString( &nameW, writeW ); + if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy )) + { + WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data; + do_IO_port_init_read_or_write(str, IO_WRITE); + } + NtClose( hkey ); + } + } IO_FixCMOSCheckSum(); }