Author: hbelusca
Date: Sun Jun 15 19:28:41 2014
New Revision: 63600
URL:
http://svn.reactos.org/svn/reactos?rev=63600&view=rev
Log:
[CSRSRV]
- Cleanup CSRSRV from the very last remnants of CsrEnumProcesses i.e. the old & buggy
way of shutdowning process (lots of work must be done in winsrv side).
- Fixup FindProcessForShutdown (reenable commented code in it, and set a proper status
error code if CsrImpersonateClient call fails).
Modified:
trunk/reactos/subsystems/win32/csrsrv/api.h
trunk/reactos/subsystems/win32/csrsrv/csrsrv.spec
trunk/reactos/subsystems/win32/csrsrv/procsup.c
Modified: trunk/reactos/subsystems/win32/csrsrv/api.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/ap…
==============================================================================
--- trunk/reactos/subsystems/win32/csrsrv/api.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrsrv/api.h [iso-8859-1] Sun Jun 15 19:28:41 2014
@@ -153,8 +153,6 @@
NTAPI
CsrInitializeProcessStructure(VOID);
-// NTSTATUS WINAPI CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc,
-// PVOID Context);
PCSR_THREAD
NTAPI
CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL,
Modified: trunk/reactos/subsystems/win32/csrsrv/csrsrv.spec
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/cs…
==============================================================================
--- trunk/reactos/subsystems/win32/csrsrv/csrsrv.spec [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrsrv/csrsrv.spec [iso-8859-1] Sun Jun 15 19:28:41
2014
@@ -12,7 +12,6 @@
@ stdcall CsrDereferenceWait(ptr)
@ stdcall CsrDestroyProcess(ptr long)
@ stdcall CsrDestroyThread(ptr)
-;@ stdcall CsrEnumProcesses(ptr ptr) ;;;;;;; Temporary hack used in win32csr, to be
removed
@ stdcall CsrExecServerThread(ptr long)
@ stdcall CsrGetProcessLuid(ptr ptr)
@ stdcall CsrImpersonateClient(ptr)
Modified: trunk/reactos/subsystems/win32/csrsrv/procsup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/pr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrsrv/procsup.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrsrv/procsup.c [iso-8859-1] Sun Jun 15 19:28:41 2014
@@ -94,109 +94,6 @@
&SetBasePriority,
sizeof(KPRIORITY));
}
-}
-
-/*++
- * @name FindProcessForShutdown
- *
- * The FindProcessForShutdown routine returns a CSR Process which is ready
- * to be shutdown, and sets the appropriate shutdown flags for it.
- *
- * @param CallerLuid
- * Pointer to the LUID of the CSR Process calling this routine.
- *
- * @return Pointer to a CSR Process which is ready to be shutdown.
- *
- * @remarks None.
- *
- *--*/
-PCSR_PROCESS
-NTAPI
-FindProcessForShutdown(IN PLUID CallerLuid)
-{
- PCSR_PROCESS CsrProcess, ReturnCsrProcess = NULL;
- // PCSR_THREAD CsrThread;
- NTSTATUS Status;
- ULONG Level = 0;
- LUID ProcessLuid;
- LUID SystemLuid = SYSTEM_LUID;
- // BOOLEAN IsSystemLuid = FALSE, IsOurLuid = FALSE;
- PLIST_ENTRY NextEntry;
-
- /* Set the List Pointers */
- NextEntry = CsrRootProcess->ListLink.Flink;
- while (NextEntry != &CsrRootProcess->ListLink)
- {
- /* Get the process */
- CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
-
- /* Move to the next entry */
- NextEntry = NextEntry->Flink;
-
- /* Skip this process if it's already been processed */
- if (CsrProcess->Flags & CsrProcessSkipShutdown) continue;
-
- /* Get the LUID of this Process */
- Status = CsrGetProcessLuid(CsrProcess->ProcessHandle, &ProcessLuid);
-
- /* Check if we didn't get access to the LUID */
- if (Status == STATUS_ACCESS_DENIED)
- {
- /* FIXME: Check if we have any threads */
-/*
- /\* Check if we have any threads *\/
- if (CsrProcess->ThreadCount)
- {
- /\* Impersonate one of the threads and retry *\/
- CsrThread = CONTAINING_RECORD(CsrProcess->ThreadList.Flink,
- CSR_THREAD,
- Link);
- CsrImpersonateClient(CsrThread);
- Status = CsrGetProcessLuid(NULL, &ProcessLuid);
- CsrRevertToSelf();
- }
-*/
- }
-
- if (!NT_SUCCESS(Status))
- {
- /* We didn't have access, so skip it */
- CsrProcess->Flags |= CsrProcessSkipShutdown;
- continue;
- }
-
- /* Check if this is the System LUID */
- if ((/*IsSystemLuid =*/ RtlEqualLuid(&ProcessLuid, &SystemLuid)))
- {
- /* Mark this process */
- CsrProcess->ShutdownFlags |= CsrShutdownSystem;
- }
- else if (!(/*IsOurLuid =*/ RtlEqualLuid(&ProcessLuid, CallerLuid)))
- {
- /* Our LUID doesn't match with the caller's */
- CsrProcess->ShutdownFlags |= CsrShutdownOther;
- }
-
- /* Check if we're past the previous level */
- // FIXME: if ((CsrProcess->ShutdownLevel > Level) || !(ReturnCsrProcess))
- if (CsrProcess->ShutdownLevel > Level /* || !ReturnCsrProcess */)
- {
- /* Update the level */
- Level = CsrProcess->ShutdownLevel;
-
- /* Set the final process */
- ReturnCsrProcess = CsrProcess;
- }
- }
-
- /* Check if we found a process */
- if (ReturnCsrProcess)
- {
- /* Skip this one next time */
- ReturnCsrProcess->Flags |= CsrProcessSkipShutdown;
- }
-
- return ReturnCsrProcess;
}
/*++
@@ -1244,6 +1141,110 @@
}
/*++
+ * @name FindProcessForShutdown
+ *
+ * The FindProcessForShutdown routine returns a CSR Process which is ready
+ * to be shutdown, and sets the appropriate shutdown flags for it.
+ *
+ * @param CallerLuid
+ * Pointer to the LUID of the CSR Process calling this routine.
+ *
+ * @return Pointer to a CSR Process which is ready to be shutdown.
+ *
+ * @remarks None.
+ *
+ *--*/
+PCSR_PROCESS
+NTAPI
+FindProcessForShutdown(IN PLUID CallerLuid)
+{
+ PCSR_PROCESS CsrProcess, ReturnCsrProcess = NULL;
+ PCSR_THREAD CsrThread;
+ NTSTATUS Status;
+ ULONG Level = 0;
+ LUID ProcessLuid;
+ LUID SystemLuid = SYSTEM_LUID;
+ PLIST_ENTRY NextEntry;
+
+ /* Set the List Pointers */
+ NextEntry = CsrRootProcess->ListLink.Flink;
+ while (NextEntry != &CsrRootProcess->ListLink)
+ {
+ /* Get the process */
+ CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
+
+ /* Move to the next entry */
+ NextEntry = NextEntry->Flink;
+
+ /* Skip this process if it's already been processed */
+ if (CsrProcess->Flags & CsrProcessSkipShutdown) continue;
+
+ /* Get the LUID of this process */
+ Status = CsrGetProcessLuid(CsrProcess->ProcessHandle, &ProcessLuid);
+
+ /* Check if we didn't get access to the LUID */
+ if (Status == STATUS_ACCESS_DENIED)
+ {
+ /* Check if we have any threads */
+ if (CsrProcess->ThreadCount)
+ {
+ /* Impersonate one of the threads and retry */
+ CsrThread = CONTAINING_RECORD(CsrProcess->ThreadList.Flink,
+ CSR_THREAD,
+ Link);
+ if (CsrImpersonateClient(CsrThread))
+ {
+ Status = CsrGetProcessLuid(NULL, &ProcessLuid);
+ CsrRevertToSelf();
+ }
+ else
+ {
+ Status = STATUS_BAD_IMPERSONATION_LEVEL;
+ }
+ }
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ /* We didn't have access, so skip it */
+ CsrProcess->Flags |= CsrProcessSkipShutdown;
+ continue;
+ }
+
+ /* Check if this is the System LUID */
+ if (RtlEqualLuid(&ProcessLuid, &SystemLuid))
+ {
+ /* Mark this process */
+ CsrProcess->ShutdownFlags |= CsrShutdownSystem;
+ }
+ else if (!RtlEqualLuid(&ProcessLuid, CallerLuid))
+ {
+ /* Our LUID doesn't match with the caller's */
+ CsrProcess->ShutdownFlags |= CsrShutdownOther;
+ }
+
+ /* Check if we're past the previous level */
+ if ((CsrProcess->ShutdownLevel > Level) || !ReturnCsrProcess)
+ {
+ /* Update the level */
+ Level = CsrProcess->ShutdownLevel;
+
+ /* Set the final process */
+ ReturnCsrProcess = CsrProcess;
+ }
+ }
+
+ /* Check if we found a process */
+ if (ReturnCsrProcess)
+ {
+ /* Skip this one next time */
+ ReturnCsrProcess->Flags |= CsrProcessSkipShutdown;
+ }
+
+ return ReturnCsrProcess;
+}
+
+/*++
* @name CsrShutdownProcesses
* @implemented NT4
*
@@ -1273,7 +1274,7 @@
BOOLEAN FirstTry;
ULONG i;
PCSR_SERVER_DLL ServerDll;
- ULONG Result = 0; /* Intentionally invalid enumeratee to silence compiler warning */
+ ULONG Result = 0;
/* Acquire process lock */
CsrAcquireProcessLock();
@@ -1353,7 +1354,7 @@
}
/* No matches during the first try, so loop again */
- if ((FirstTry) && (Result == CsrShutdownNonCsrProcess))
+ if (FirstTry && (Result == CsrShutdownNonCsrProcess))
{
FirstTry = FALSE;
continue;
@@ -1378,100 +1379,6 @@
return Status;
}
-/* HACK: Temporary hack. This is really "CsrShutdownProcesses", mostly. Used by
winsrv */
-#if 0
-NTSTATUS
-WINAPI
-CsrEnumProcesses(IN CSRSS_ENUM_PROCESS_PROC EnumProc,
- IN PVOID Context)
-{
- PVOID* RealContext = (PVOID*)Context;
- PLUID CallerLuid = RealContext[0];
- PCSR_PROCESS CsrProcess = NULL;
- NTSTATUS Status = STATUS_UNSUCCESSFUL;
- BOOLEAN FirstTry;
- PLIST_ENTRY NextEntry;
- ULONG Result = 0;
-
- /* Acquire process lock */
- CsrAcquireProcessLock();
-
- /* Get the list pointers */
- NextEntry = CsrRootProcess->ListLink.Flink;
- while (NextEntry != &CsrRootProcess->ListLink)
- {
- /* Get the Process */
- CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
-
- /* Move to the next entry */
- NextEntry = NextEntry->Flink;
-
- /* Remove the skip flag, set shutdown flags to 0 */
- CsrProcess->Flags &= ~CsrProcessSkipShutdown;
- CsrProcess->ShutdownFlags = 0;
- }
-
- /* Set shudown Priority */
- CsrSetToShutdownPriority();
-
- /* Loop all processes */
- //DPRINT1("Enumerating for LUID: %lx %lx\n", CallerLuid->HighPart,
CallerLuid->LowPart);
-
- /* Start looping */
- while (TRUE)
- {
- /* Find the next process to shutdown */
- FirstTry = TRUE;
- if (!(CsrProcess = FindProcessForShutdown(CallerLuid)))
- {
- /* Done, quit */
- CsrReleaseProcessLock();
- Status = STATUS_SUCCESS;
- goto Quickie;
- }
-
-LoopAgain:
- /* Release the lock, make the callback, and acquire it back */
- //DPRINT1("Found process: %lx\n",
CsrProcess->ClientId.UniqueProcess);
- CsrReleaseProcessLock();
- Result = (ULONG)EnumProc(CsrProcess, (PVOID)((ULONG_PTR)Context | FirstTry));
- CsrAcquireProcessLock();
-
- /* Check the result */
- //DPRINT1("Result: %d\n", Result);
- if (Result == CsrShutdownCsrProcess)
- {
- /* The callback unlocked the process */
- break;
- }
- else if (Result == CsrShutdownNonCsrProcess)
- {
- /* A non-CSR process, the callback didn't touch it */
- //continue;
- }
- else if (Result == CsrShutdownCancelled)
- {
- /* Shutdown was cancelled, unlock and exit */
- CsrReleaseProcessLock();
- Status = STATUS_CANCELLED;
- goto Quickie;
- }
-
- /* No matches during the first try, so loop again */
- if (FirstTry && Result == CsrShutdownNonCsrProcess)
- {
- FirstTry = FALSE;
- goto LoopAgain;
- }
- }
-
-Quickie:
- /* Return to normal priority */
- CsrSetToNormalPriority();
- return Status;
-}
-#endif
-
/*++
* @name CsrUnlockProcess
* @implemented NT4