https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dc65db7c1318675dfbfcbdf1e1f55fd2f865c290

commit dc65db7c1318675dfbfcbdf1e1f55fd2f865c290
Author:     Pierre Schweitzer <[email protected]>
AuthorDate: Tue Dec 11 23:39:00 2018 +0100
Commit:     Pierre Schweitzer <[email protected]>
CommitDate: Tue Dec 11 23:41:01 2018 +0100

    [ADVAPI32_APITEST] If TEB SubProcessTag is set, query ADVAPI32 to validate 
its correctness
    
    This is based on: 
https://wj32.org/wp/2010/03/30/howto-use-i_querytaginformation/
    and properly works in W2K3 SP2.
    Thanks to Joachim for his tests.
---
 modules/rostests/apitests/advapi32/ServiceEnv.c | 33 +++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/modules/rostests/apitests/advapi32/ServiceEnv.c 
b/modules/rostests/apitests/advapi32/ServiceEnv.c
index fd3520452f..f71d25541d 100644
--- a/modules/rostests/apitests/advapi32/ServiceEnv.c
+++ b/modules/rostests/apitests/advapi32/ServiceEnv.c
@@ -106,6 +106,39 @@ service_main(DWORD dwArgc, LPWSTR* lpszArgv)
 
     Teb = NtCurrentTeb();
     service_ok(Teb->SubProcessTag != 0, "SubProcessTag is not defined!\n");
+    if (Teb->SubProcessTag != 0)
+    {
+        ULONG (NTAPI *_I_QueryTagInformation)(PVOID, DWORD, PVOID) = 
(PVOID)GetProcAddress(GetModuleHandle("advapi32.dll"), "I_QueryTagInformation");
+        if (_I_QueryTagInformation != NULL)
+        {
+            /* IN/OUT parameter structure for I_QueryTagInformation() function
+             * See: 
https://wj32.org/wp/2010/03/30/howto-use-i_querytaginformation/
+             */
+            struct
+            {
+                ULONG ProcessId;
+                PVOID ServiceTag;
+                ULONG Unknown;
+                PWSTR Buffer;
+            } ServiceQuery;
+
+            /* Set our input parameters */
+            ServiceQuery.ProcessId = GetCurrentProcessId();
+            ServiceQuery.ServiceTag = Teb->SubProcessTag;
+            ServiceQuery.Unknown = 0;
+            ServiceQuery.Buffer = NULL;
+            /* Call ADVAPI32 to query the correctness of our tag */
+            _I_QueryTagInformation(NULL, 1, &ServiceQuery);
+
+            /* If buffer is not NULL, call succeed */
+            if (ServiceQuery.Buffer != NULL)
+            {
+                /* It should match our service name */
+                service_ok(wcscmp(lpszArgv[0], ServiceQuery.Buffer) == 0, 
"Mismatching info: %S - %S\n", lpszArgv[0], ServiceQuery.Buffer);
+                LocalFree(ServiceQuery.Buffer);
+            }
+        }
+    }
 
     /* Work is done */
     report_service_status(SERVICE_STOPPED, NO_ERROR, 0);

Reply via email to