#include <srv.h>
+#include <winuser.h>
+
#define NDEBUG
#include <debug.h>
/* PRIVATE FUNCTIONS **********************************************************/
/*++
- * @name CsrpSetToNormalPriority
+ * @name CsrSetToNormalPriority
*
- * The CsrpSetToNormalPriority routine sets the current NT Process'
+ * The CsrSetToNormalPriority routine sets the current NT Process'
* priority to the normal priority for CSR Processes.
*
* @param None.
*
* @return None.
*
- * @remarks The "Normal" Priority corresponds to the Normal Forground
+ * @remarks The "Normal" Priority corresponds to the Normal Foreground
* Priority (9) plus a boost of 4.
*
*--*/
VOID
NTAPI
-CsrSetToNormalPriority(VOID) // CsrpSetToNormalPriority
+CsrSetToNormalPriority(VOID)
{
KPRIORITY BasePriority = (8 + 1) + 4;
NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
&BasePriority,
- sizeof(KPRIORITY));
+ sizeof(BasePriority));
}
/*++
- * @name CsrpSetToShutdownPriority
+ * @name CsrSetToShutdownPriority
*
- * The CsrpSetToShutdownPriority routine sets the current NT Process'
+ * The CsrSetToShutdownPriority routine sets the current NT Process'
* priority to the boosted priority for CSR Processes doing shutdown.
* Additonally, it acquires the Shutdown Privilege required for shutdown.
*
*
* @return None.
*
- * @remarks The "Shutdown" Priority corresponds to the Normal Forground
+ * @remarks The "Shutdown" Priority corresponds to the Normal Foreground
* Priority (9) plus a boost of 6.
*
*--*/
VOID
NTAPI
-CsrSetToShutdownPriority(VOID) // CsrpSetToShutdownPriority
+CsrSetToShutdownPriority(VOID)
{
- KPRIORITY SetBasePriority = (8 + 1) + 6;
+ KPRIORITY BasePriority = (8 + 1) + 6;
BOOLEAN Old;
/* Get the shutdown privilege */
/* Set the Priority */
NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
- &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;
+ &BasePriority,
+ sizeof(BasePriority));
}
-
- return ReturnCsrProcess;
}
/*++
/* Decrease reference count */
LockCount = --CsrProcess->ReferenceCount;
ASSERT(LockCount >= 0);
- if (!LockCount)
+ if (LockCount == 0)
{
/* Call the generic cleanup code */
DPRINT1("Should kill process: %p\n", CsrProcess);
- CsrProcessRefcountZero(CsrProcess);
CsrAcquireProcessLock();
+ CsrProcessRefcountZero(CsrProcess);
}
}
if (CsrProcessSequenceCount < 5) CsrProcessSequenceCount = 5;
/* Increase the reference count */
- CsrProcess->ReferenceCount++;
+ CsrLockedReferenceProcess(CsrProcess);
/* Initialize the Thread List */
InitializeListHead(&CsrProcess->ThreadList);
*
* @param None.
*
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- * otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
CsrRootProcess->ClientId = NtCurrentTeb()->ClientId;
/* Initialize the Thread Hash List */
- for (i = 0; i < 256; i++) InitializeListHead(&CsrThreadHashTable[i]);
+ for (i = 0; i < NUMBER_THREAD_HASH_BUCKETS; i++) InitializeListHead(&CsrThreadHashTable[i]);
/* Initialize the Wait Lock */
return RtlInitializeCriticalSection(&CsrWaitListsLock);
* The CsrInsertProcess routine inserts a CSR Process into the Process List
* and notifies Server DLLs of the creation of a new CSR Process.
*
- * @param Parent
- * Optional pointer to the CSR Process creating this CSR Process.
- *
- * @param CurrentProcess
- * Optional pointer to the current CSR Process.
+ * @param ParentProcess
+ * Optional pointer to the Parent Process creating this CSR Process.
*
* @param CsrProcess
* Pointer to the CSR Process which is to be inserted.
*--*/
VOID
NTAPI
-CsrInsertProcess(IN PCSR_PROCESS Parent OPTIONAL, // ParentProcess
- IN PCSR_PROCESS CurrentProcess OPTIONAL, // CallingProcess
- IN PCSR_PROCESS CsrProcess) // Process
+CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL,
+ IN PCSR_PROCESS CsrProcess)
{
PCSR_SERVER_DLL ServerDll;
ULONG i;
ASSERT(ProcessStructureListLocked());
- /* Set the parent */
- CsrProcess->Parent = Parent;
-
/* Insert it into the Root List */
InsertTailList(&CsrRootProcess->ListLink, &CsrProcess->ListLink);
/* Make sure it's valid and that it has callback */
if (ServerDll && ServerDll->NewProcessCallback)
{
- ServerDll->NewProcessCallback(CurrentProcess, CsrProcess);
+ ServerDll->NewProcessCallback(ParentProcess, CsrProcess);
}
}
}
* @name CsrCreateProcess
* @implemented NT4
*
- * Do nothing for 500ms.
+ * The CsrCreateProcess routine creates a CSR Process object for an NT Process.
+ *
+ * @param hProcess
+ * Handle to an existing NT Process to which to associate this
+ * CSR Process.
+ *
+ * @param hThread
+ * Handle to an existing NT Thread to which to create its
+ * corresponding CSR Thread for this CSR Process.
*
- * @param ArgumentCount
- * Description of the parameter. Wrapped to more lines on ~70th
- * column.
+ * @param ClientId
+ * Pointer to the Client ID structure of the NT Process to associate
+ * with this CSR Process.
*
- * @param Arguments
- * Description of the parameter. Wrapped to more lines on ~70th
- * column.
+ * @param NtSession
+ * @param Flags
+ * @param DebugCid
*
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- * otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
}
}
- /* Set the Exception port for us */
+ /* Set the Exception Port for us */
Status = NtSetInformationProcess(hProcess,
ProcessExceptionPort,
&CsrApiPort,
- sizeof(HANDLE));
+ sizeof(CsrApiPort));
if (!NT_SUCCESS(Status))
{
/* Failed */
}
/* Check if CreateProcess got CREATE_NEW_PROCESS_GROUP */
- if (!(Flags & CsrProcessCreateNewGroup))
+ if (Flags & CsrProcessCreateNewGroup)
{
- /* Create new data */
+ /*
+ * We create the process group leader of a new process group, therefore
+ * its process group ID and sequence number are its own ones.
+ */
CsrProcess->ProcessGroupId = HandleToUlong(ClientId->UniqueProcess);
CsrProcess->ProcessGroupSequence = CsrProcess->SequenceNumber;
}
else
{
- /* Copy it from the current process */
+ /* Inherit the process group ID and sequence number from the current process */
CsrProcess->ProcessGroupId = CurrentProcess->ProcessGroupId;
CsrProcess->ProcessGroupSequence = CurrentProcess->ProcessGroupSequence;
}
Status = NtSetInformationProcess(hProcess,
ProcessDebugPort,
&CsrApiPort,
- sizeof(HANDLE));
+ sizeof(CsrApiPort));
ASSERT(NT_SUCCESS(Status));
if (!NT_SUCCESS(Status))
{
/* Get the Thread Create Time */
Status = NtQueryInformationThread(hThread,
ThreadTimes,
- (PVOID)&KernelTimes,
+ &KernelTimes,
sizeof(KernelTimes),
NULL);
if (!NT_SUCCESS(Status))
CsrThread->Flags = 0;
/* Insert the Thread into the Process */
- CsrInsertThread(CsrProcess, CsrThread);
+ Status = CsrInsertThread(CsrProcess, CsrThread);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Bail out */
+ CsrDeallocateProcess(CsrProcess);
+ CsrDeallocateThread(CsrThread);
+ CsrReleaseProcessLock();
+ return Status;
+ }
/* Reference the session */
CsrReferenceNtSession(NtSession);
CsrSetBackgroundPriority(CsrProcess);
/* Insert the Process */
- CsrInsertProcess(NULL, CurrentProcess, CsrProcess);
+ CsrInsertProcess(CurrentProcess, CsrProcess);
/* Release lock and return */
CsrReleaseProcessLock();
CsrDebugProcess(IN PCSR_PROCESS CsrProcess)
{
/* CSR does not handle debugging anymore */
- DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__, CsrProcess);
+ DPRINT("CSRSRV: %s(0x%p) called\n", __FUNCTION__, CsrProcess);
return STATUS_UNSUCCESSFUL;
}
CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess)
{
/* CSR does not handle debugging anymore */
- DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__, CsrProcess);
+ DPRINT("CSRSRV: %s(0x%p) called\n", __FUNCTION__, CsrProcess);
return STATUS_UNSUCCESSFUL;
}
/* Decrease reference count */
LockCount = --CsrProcess->ReferenceCount;
ASSERT(LockCount >= 0);
- if (!LockCount)
+ if (LockCount == 0)
{
/* Call the generic cleanup code */
CsrProcessRefcountZero(CsrProcess);
/* Get the current thread entry */
CsrThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
+ /* Move to the next entry */
+ NextEntry = NextEntry->Flink;
+
/* Make sure the thread isn't already dead */
if (CsrThread->Flags & CsrThreadTerminated)
{
- NextEntry = NextEntry->Flink;
+ /* Go the the next thread */
continue;
}
/* Dereference the thread */
CsrLockedDereferenceThread(CsrThread);
- NextEntry = CsrProcess->ThreadList.Flink;
}
/* Release the Process Lock and return success */
* @name CsrGetProcessLuid
* @implemented NT4
*
- * Do nothing for 500ms.
+ * The CsrGetProcessLuid routine gets the LUID of the given process.
*
* @param hProcess
* Optional handle to the process whose LUID should be returned.
*
* @param Luid
- * Pointer to a LUID Pointer which will receive the CSR Process' LUID
+ * Pointer to a LUID Pointer which will receive the CSR Process' LUID.
*
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- * otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks If hProcess is not supplied, then the current thread's token will
* be used. If that too is missing, then the current process' token
* @param CsrThread
* Pointer to the CSR Thread to impersonate.
*
- * @return TRUE if impersionation suceeded, false otherwise.
+ * @return TRUE if impersonation succeeded, FALSE otherwise.
*
* @remarks Impersonation can be recursive.
*
if (!NT_SUCCESS(Status))
{
/* Failure */
-/*
+#ifdef CSR_DBG
DPRINT1("CSRSS: Can't impersonate client thread - Status = %lx\n", Status);
- if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
-*/
+ // if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
+#endif
return FALSE;
}
* Optional pointer to a CSR Process pointer which will hold the
* CSR Process corresponding to the given Process ID.
*
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- * otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks Locking a CSR Process is defined as acquiring an extra
* reference to it and returning with the Process Lock held.
{
PLIST_ENTRY NextEntry;
PCSR_PROCESS CurrentProcess = NULL;
- NTSTATUS Status;
+ NTSTATUS Status = STATUS_UNSUCCESSFUL;
/* Acquire the lock */
CsrAcquireProcessLock();
break;
}
- /* Next entry */
+ /* Move to the next entry */
NextEntry = NextEntry->Flink;
} while (NextEntry != &CsrRootProcess->ListLink);
CsrLockedReferenceProcess(CurrentProcess);
*CsrProcess = CurrentProcess;
}
-
+
/* Return the result */
return Status;
}
*
* @param None.
*
- * @return TRUE if the reversion was succesful, false otherwise.
+ * @return TRUE if the reversion was succesful, FALSE otherwise.
*
* @remarks Impersonation can be recursive; as such, the impersonation token
* will only be deleted once the CSR Thread's impersonaton count
/* Make sure impersonation is on */
if (!CurrentThread->ImpersonationCount)
{
- // DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
+ DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
// DbgBreakPoint();
return FALSE;
}
- else if (--CurrentThread->ImpersonationCount > 0)
+ else if ((--CurrentThread->ImpersonationCount) > 0)
{
/* Success; impersonation count decreased but still not zero */
return TRUE;
Status = NtSetInformationThread(NtCurrentThread(),
ThreadImpersonationToken,
&ImpersonationToken,
- sizeof(HANDLE));
+ sizeof(ImpersonationToken));
/* Return TRUE or FALSE */
return NT_SUCCESS(Status);
NTAPI
CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
{
- PROCESS_PRIORITY_CLASS PriorityClass;
+ PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
/* Set the Foreground bit off */
- PriorityClass.Foreground = FALSE;
+ ProcessPriority.Foreground = FALSE;
- /* Set the new Priority */
+ /* Set the new priority */
NtSetInformationProcess(CsrProcess->ProcessHandle,
- ProcessPriorityClass,
- &PriorityClass,
- sizeof(PriorityClass));
+ ProcessForegroundInformation,
+ &ProcessPriority,
+ sizeof(ProcessPriority));
}
/*++
NTAPI
CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess)
{
- PROCESS_PRIORITY_CLASS PriorityClass;
+ PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
/* Set the Foreground bit on */
- PriorityClass.Foreground = TRUE;
+ ProcessPriority.Foreground = TRUE;
- /* Set the new Priority */
+ /* Set the new priority */
NtSetInformationProcess(CsrProcess->ProcessHandle,
- ProcessPriorityClass,
- &PriorityClass,
- sizeof(PriorityClass));
+ ProcessForegroundInformation,
+ &ProcessPriority,
+ sizeof(ProcessPriority));
+}
+
+/*++
+ * @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;
}
/*++
* @param Flags
* Flags to send to the shutdown notification routine.
*
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- * otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
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();
/* Get the Process */
CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
- /* Remove the skip flag, set shutdown flags to 0*/
+ /* Move to the next entry */
+ NextEntry = NextEntry->Flink;
+
+ /* Remove the skip flag, set shutdown flags to 0 */
CsrProcess->Flags &= ~CsrProcessSkipShutdown;
CsrProcess->ShutdownFlags = 0;
-
- /* Move to the next */
- NextEntry = NextEntry->Flink;
}
- /* Set shudown Priority */
- // CsrpSetToShutdownPriority();
+ /* Set shutdown Priority */
CsrSetToShutdownPriority();
/* Start looping */
if (!CsrProcess) break;
/* Increase reference to process */
- CsrProcess->ReferenceCount++;
+ CsrLockedReferenceProcess(CsrProcess);
FirstTry = TRUE;
while (TRUE)
}
else if (Result == CsrShutdownCancelled)
{
+#ifdef CSR_DBG
/* Check if this was a forced shutdown */
if (Flags & EWX_FORCE)
{
CsrProcess->ClientId.UniqueProcess, i);
DbgBreakPoint();
}
+#endif
/* Shutdown was cancelled, unlock and exit */
CsrReleaseProcessLock();
}
/* No matches during the first try, so loop again */
- if ((FirstTry) && (Result == CsrShutdownNonCsrProcess))
+ if (FirstTry && (Result == CsrShutdownNonCsrProcess))
{
FirstTry = FALSE;
continue;
}
/* We've reached the final loop here, so dereference */
- if (i == CSR_SERVER_DLL_MAX) CsrLockedDereferenceProcess(CsrProcess);
+ if (i == CSR_SERVER_DLL_MAX)
+ CsrLockedDereferenceProcess(CsrProcess);
}
/* Success path */
Quickie:
/* Return to normal priority */
- // CsrpSetToNormalPriority();
CsrSetToNormalPriority();
return Status;
}
-/* FIXME: Temporary hack. This is really "CsrShutdownProcess", 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);
-
- /* Remove the skip flag, set shutdown flags to 0*/
- CsrProcess->Flags &= ~CsrProcessSkipShutdown;
- CsrProcess->ShutdownFlags = 0;
-
- /* Move to the next */
- NextEntry = NextEntry->Flink;
- }
-
- /* 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