Commit in reactos on MAIN
include/ddk/status.h+21.24 -> 1.25
ntoskrnl/ps/job.c+64-51.6 -> 1.7
+66-5
2 modified files
implemented NtIsProcessInJob()

reactos/include/ddk
status.h 1.24 -> 1.25
diff -u -r1.24 -r1.25
--- status.h	15 May 2004 19:39:35 -0000	1.24
+++ status.h	23 Sep 2004 21:23:33 -0000	1.25
@@ -54,6 +54,8 @@
 #define STATUS_NOTIFY_ENUM_DIR                      ((NTSTATUS)0x0000010C)
 #define STATUS_NO_QUOTAS_NO_ACCOUNT                 ((NTSTATUS)0x0000010D)
 #define STATUS_PRIMARY_TRANSPORT_CONNECT_FAILED     ((NTSTATUS)0x0000010E)
+#define STATUS_PROCESS_NOT_IN_JOB                   ((NTSTATUS)0x00000123)
+#define STATUS_PROCESS_IN_JOB                       ((NTSTATUS)0x00000124)
 
 #define STATUS_OBJECT_EXISTS                        ((NTSTATUS)0x40000000)
 #define STATUS_THREAD_WAS_SUSPENDED                 ((NTSTATUS)0x40000001)

reactos/ntoskrnl/ps
job.c 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- job.c	23 Sep 2004 16:31:21 -0000	1.6
+++ job.c	23 Sep 2004 21:23:34 -0000	1.7
@@ -99,15 +99,74 @@
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 NTSTATUS
 STDCALL
-NtIsProcessInJob(IN HANDLE ProcessHandle, // ProcessHandle must PROCESS_QUERY_INFORMATION grant access.
-                 IN HANDLE JobHandle OPTIONAL) // JobHandle must grant JOB_OBJECT_QUERY access. Defaults to the current process's job object.
+NtIsProcessInJob(IN HANDLE ProcessHandle,
+                 IN HANDLE JobHandle OPTIONAL)
 {
-  UNIMPLEMENTED;
-  return STATUS_NOT_IMPLEMENTED;
+  KPROCESSOR_MODE PreviousMode;
+  PEPROCESS Process;
+  NTSTATUS Status;
+  
+  PreviousMode = ExGetPreviousMode();
+  
+  Status = ObReferenceObjectByHandle(ProcessHandle,
+                                     PROCESS_QUERY_INFORMATION,
+                                     PsProcessType,
+                                     PreviousMode,
+                                     (PVOID*)&Process,
+                                     NULL);
+  if(NT_SUCCESS(Status))
+  {
+    /* FIXME - make sure the job object doesn't get exchanged or deleted while trying to
+               reference it, e.g. by locking it somehow... */
+
+    PEJOB ProcessJob = Process->Job;
+
+    /* reference the object without caring about access rights as it does not necessarily
+       have to be accessible from the calling process */
+    Status = ObReferenceObjectByPointer(ProcessJob,
+                                        0,
+                                        PsJobType,
+                                        KernelMode);
+    if(NT_SUCCESS(Status))
+    {
+      if(JobHandle == NULL)
+      {
+        /* simply test whether the process is assigned to a job */
+        Status = ((Process->Job != NULL) ? STATUS_PROCESS_IN_JOB : STATUS_PROCESS_NOT_IN_JOB);
+      }
+      else if(ProcessJob != NULL)
+      {
+        PEJOB JobObject;
+
+        /* get the job object and compare the object pointer with the one assigned to the process */
+        Status = ObReferenceObjectByHandle(JobHandle,
+                                           JOB_OBJECT_QUERY,
+                                           PsJobType,
+                                           PreviousMode,
+                                           (PVOID*)&JobObject,
+                                           NULL);
+        if(NT_SUCCESS(Status))
+        {
+          Status = ((ProcessJob == JobObject) ? STATUS_PROCESS_IN_JOB : STATUS_PROCESS_NOT_IN_JOB);
+          ObDereferenceObject(JobObject);
+        }
+      }
+      else
+      {
+        /* the process is not assigned to any job */
+        Status = STATUS_PROCESS_NOT_IN_JOB;
+      }
+      
+      ObDereferenceObject(ProcessJob);
+    }
+    ObDereferenceObject(Process);
+  }
+
+  return Status;
 }
 
 
CVSspam 0.2.8