advpack: add two missing stubs

Robert Reif reif at earthlink.net
Tue Jan 11 07:02:52 CST 2005


Dmitry Timoshkov wrote:

>"Steven Edwards" <steven_ed4153 at yahoo.com> wrote:
>
>  
>
>>--- Robert Reif <reif at earthlink.net> wrote:
>>    
>>
>>>Some of the new code was borrowed from reactos. GetVersionFromFile*
>>>      
>>>
>>Its nice to note where the code came from. We always try to do it in ReactOS so please credit Jim
>>for his advpack function.
>>    
>>
>
>It's sad to say that, but unfortunately that's not the case on the ReactOS
>side sometimes, especially for Wine code borrowed at the early stage.
>
>  
>
New patch with tests and credit to ReactOS.  I don't know who wrote
the code and the credit is not in the file.  The Author column of the
CVSweb page lists  jimtabor.  Please let me know if this is adequate
credit or not.   It would be nice if someone could give me Jim's e-mail
or notify Jim of these changes.  GetVersionFromFileEx in ReactOS is
broken.

Please also look over the changes to see if they make sense on win9x
and non-english systems.  The only documentation I could find on the
web is the Microsoft header file.

Changelog
- Add stubs for NeedReboot and NeedRebootInit.
- Add Implementation for GetVersionFromFileEx.  Inspired by
  ReactOS advpack.c code and from Wine version.dll tests.
- Add IsNTAdmin borrowed from ReactOS advpack.c.
- Add missing prototypes to advpub.h.
-------------- next part --------------
diff -u wine.cvs/dlls/advpack/advpack.c wine/dlls/advpack/advpack.c
--- wine.cvs/dlls/advpack/advpack.c	2004-12-28 12:21:48.000000000 -0500
+++ wine/dlls/advpack/advpack.c	2005-01-11 07:51:55.000000000 -0500
@@ -2,6 +2,7 @@
  * Advpack main
  *
  * Copyright 2004 Huw D M Davies
+ * Copyright (C) 2004 ReactOS Team
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,6 +25,8 @@
 #include "winbase.h"
 #include "winuser.h"
 #include "winreg.h"
+#include "winver.h"
+#include "winnls.h"
 #include "setupapi.h"
 #include "advpub.h"
 #include "wine/debug.h"
@@ -96,3 +99,138 @@
 
     return ret;
 }
+
+/***********************************************************************
+ *		NeedRebootInit	(ADVPACK.@)
+ */
+DWORD WINAPI NeedRebootInit(VOID)
+{
+    FIXME("() stub!\n");
+
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+
+    return 0;
+}
+
+/***********************************************************************
+ *		NeedReboot	(ADVPACK.@)
+ */
+BOOL WINAPI NeedReboot(DWORD dwRebootCheck)
+{
+    FIXME("(0x%08lx) stub!\n", dwRebootCheck);
+
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+
+    return FALSE;
+}
+
+/***********************************************************************
+ *		GetVersionFromFileEx	(ADVPACK.@)
+ */
+HRESULT WINAPI GetVersionFromFileEx( LPSTR lpszFilename, LPDWORD pdwMSVer,
+                                     LPDWORD pdwLSVer, BOOL bVersion )
+{
+    DWORD hdl, retval;
+    LPVOID pVersionInfo;
+    BOOL boolret;
+    VS_FIXEDFILEINFO *pFixedVersionInfo;
+    UINT uiLength;
+    TRACE("(%s, %p, %p, %d)\n", lpszFilename, pdwMSVer, pdwLSVer, bVersion);
+
+    if (bVersion)
+    {
+        retval = GetFileVersionInfoSizeA(lpszFilename, &hdl);
+        if (retval == 0 || hdl != 0)
+            return E_FAIL;
+
+        pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
+        if (pVersionInfo == NULL)
+             return E_FAIL;
+
+        GetFileVersionInfoA( lpszFilename, 0, retval, pVersionInfo);
+
+        boolret = VerQueryValueA(pVersionInfo, "\\",
+                                 (LPVOID) &pFixedVersionInfo, &uiLength);
+
+        HeapFree(GetProcessHeap(), 0, pVersionInfo);
+
+	if (boolret)
+        {
+            *pdwMSVer = pFixedVersionInfo->dwFileVersionMS;
+            *pdwLSVer = pFixedVersionInfo->dwFileVersionLS;
+        }
+        else
+            return E_FAIL;
+    }
+    else
+    {
+        *pdwMSVer = GetUserDefaultUILanguage();
+        *pdwLSVer = GetACP();
+    }
+
+    return S_OK;
+}
+
+/***********************************************************************
+ *		GetVersionFromFile	(ADVPACK.@)
+ */
+HRESULT WINAPI GetVersionFromFile( LPSTR Filename, LPDWORD MajorVer,
+                                   LPDWORD MinorVer, BOOL Version )
+{
+    TRACE("(%s, %p, %p, %d)\n", Filename, MajorVer, MinorVer, Version);
+
+    return GetVersionFromFileEx(Filename, MajorVer, MinorVer, Version);
+}
+
+/***********************************************************************
+ *              IsNTAdmin	(ADVPACK.@)
+ */
+BOOL WINAPI IsNTAdmin( DWORD Reserved, PDWORD PReserved )
+{
+    HANDLE Process, Token;
+    INT i;
+    BOOL Good = FALSE;
+    DWORD Buffer[4096];
+    DWORD Size;
+    PTOKEN_GROUPS TokenGrp = (PTOKEN_GROUPS) Buffer;
+    SID_IDENTIFIER_AUTHORITY AuthSid = {SECURITY_NT_AUTHORITY};
+    PSID psid = NULL;
+
+    Process = GetCurrentProcess();
+
+    if ( OpenProcessToken(Process, TOKEN_QUERY, &Token) == FALSE)
+    {
+        CloseHandle(Process);
+        return FALSE;
+    }
+
+    if ( GetTokenInformation( Token, TokenGroups, Buffer, 4096, &Size) == FALSE)
+    {
+        CloseHandle(Process);
+        CloseHandle(Token);
+        return FALSE;
+    }
+
+    CloseHandle(Process);
+    CloseHandle(Token);
+
+    if ( AllocateAndInitializeSid( &AuthSid, 2, SECURITY_BUILTIN_DOMAIN_RID,
+                                   DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
+                                   &psid) == FALSE)
+    {
+        return FALSE;
+    }
+
+    for ( i = 0; i < TokenGrp->GroupCount; i++ )
+    {
+         if ( EqualSid( psid , TokenGrp->Groups[i].Sid) != FALSE )
+         {
+             Good = TRUE;
+             break;
+         }
+    }
+
+    FreeSid( psid);
+
+    return Good;
+}
diff -u wine.cvs/dlls/advpack/advpack.spec wine/dlls/advpack/advpack.spec
--- wine.cvs/dlls/advpack/advpack.spec	2004-12-28 12:21:48.000000000 -0500
+++ wine/dlls/advpack/advpack.spec	2005-01-10 20:42:37.000000000 -0500
@@ -10,13 +10,13 @@
 @ stub FileSaveMarkNotExist
 @ stub FileSaveRestore
 @ stub FileSaveRestoreOnINF
-@ stub GetVersionFromFile
-@ stub GetVersionFromFileEx
-@ stub IsNTAdmin
+@ stdcall GetVersionFromFile(str ptr ptr long)
+@ stdcall GetVersionFromFileEx(str ptr ptr long)
+@ stdcall IsNTAdmin(long ptr)
 @ stdcall LaunchINFSection(ptr ptr str long)
 @ stdcall LaunchINFSectionEx(ptr ptr str long)
-@ stub NeedReboot
-@ stub NeedRebootInit
+@ stdcall NeedReboot(long)
+@ stdcall NeedRebootInit()
 @ stub OpenINFEngine
 @ stub RebootCheckOnInstall
 @ stdcall RegInstall(ptr str ptr)
diff -u wine.cvs/dlls/advpack/Makefile.in wine/dlls/advpack/Makefile.in
--- wine.cvs/dlls/advpack/Makefile.in	2004-09-27 16:39:40.000000000 -0400
+++ wine/dlls/advpack/Makefile.in	2005-01-10 21:16:54.000000000 -0500
@@ -3,13 +3,15 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = advpack.dll
-IMPORTS   = setupapi user32 kernel32 ntdll
+IMPORTS   = setupapi user32 kernel32 ntdll version advapi32
 EXTRALIBS = $(LIBUNICODE)
 
 C_SRCS = \
 	advpack.c \
 	reg.c
 
+SUBDIRS = tests
+
 @MAKE_DLL_RULES@
 
 ### Dependencies:
diff -u -N wine.cvs/dlls/advpack/tests/advpack.c wine/dlls/advpack/tests/advpack.c
--- wine.cvs/dlls/advpack/tests/advpack.c	1969-12-31 19:00:00.000000000 -0500
+++ wine/dlls/advpack/tests/advpack.c	2005-01-11 07:51:01.000000000 -0500
@@ -0,0 +1,66 @@
+/*
+ * Unit tests for advpack.dll
+ *
+ * Copyright (C) 2005 Robert Reif
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define NONAMELESSSTRUCT
+#define NONAMELESSUNION
+#include <windows.h>
+
+#include "wine/test.h"
+#include "advpub.h"
+
+static void version_test()
+{
+    HRESULT hr;
+    DWORD major, minor;
+
+    major = minor = 0;
+    hr = GetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
+    ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
+        "0x%08lx\n", hr);
+
+    trace("kernel32.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
+           major, minor);
+
+    major = minor = 0;
+    hr = GetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
+    ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
+        "0x%08lx\n", hr);
+
+    trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
+          HIWORD(minor), LOWORD(minor));
+}
+
+static void admin_test()
+{
+    BOOL res;
+    DWORD reserved;
+
+    res = IsNTAdmin(0, &reserved);
+    ok (res == TRUE || res == FALSE, "IsNTAdmin returned: 0x%08x\n", res);
+
+    trace("IsNTAdmin = %s\n", res == TRUE ? "TRUE" : res == FALSE ? "FALSE" :
+          "???");
+}
+
+START_TEST(advpack)
+{
+    version_test();
+    admin_test();
+}
diff -u -N wine.cvs/dlls/advpack/tests/.cvsignore wine/dlls/advpack/tests/.cvsignore
--- wine.cvs/dlls/advpack/tests/.cvsignore	1969-12-31 19:00:00.000000000 -0500
+++ wine/dlls/advpack/tests/.cvsignore	2005-01-10 21:17:35.000000000 -0500
@@ -0,0 +1,3 @@
+Makefile
+advpack.ok
+testlist.c
diff -u -N wine.cvs/dlls/advpack/tests/Makefile.in wine/dlls/advpack/tests/Makefile.in
--- wine.cvs/dlls/advpack/tests/Makefile.in	1969-12-31 19:00:00.000000000 -0500
+++ wine/dlls/advpack/tests/Makefile.in	2005-01-10 21:07:22.000000000 -0500
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = advpack.dll
+IMPORTS   = advpack user32 kernel32 version
+
+CTESTS = \
+	advpack.c
+
+ at MAKE_TEST_RULES@
+
+### Dependencies:
diff -u wine.cvs/include/advpub.h wine/include/advpub.h
--- wine.cvs/include/advpub.h	2004-09-27 16:39:40.000000000 -0400
+++ wine/include/advpub.h	2005-01-10 21:25:33.000000000 -0500
@@ -39,6 +39,10 @@
 typedef CSTRTABLE *LPCSTRTABLE;
 
 HRESULT WINAPI RegInstall(HMODULE hm, LPCSTR pszSection, LPCSTRTABLE pstTable);
+DWORD WINAPI NeedRebootInit(VOID);
+BOOL WINAPI NeedReboot(DWORD dwRebootCheck);
+HRESULT WINAPI GetVersionFromFile(LPSTR lpszFilename, LPDWORD pdwMSVer, LPDWORD pdwLSVer, BOOL bVersion);
+BOOL WINAPI IsNTAdmin(DWORD dwReserved, DWORD *lpdwReserved);
 
 #ifdef __cplusplus
 }


More information about the wine-devel mailing list