2 * Unit test to verify that PROC_PIDUNIQIDENTIFIERINFO is an unprivilege operation.
4 * Test calls PROC_PIDTBSDINFO, PROC_PIDTASKINFO, PROC_PIDT_SHORTBSDINFO, PROC_PIDUNIQIDENTIFIERINFO on the process
5 * as well as on launchd to verify that PROC_PIDT_SHORTBSDINFO and PROC_PIDUNIQIDENTIFIERINFO are unpirivilege
6 * operations while PROC_PIDTBSDINFO and PROC_PIDTASKINFO are privelege ones.
9 #include <System/sys/proc_info.h>
21 bsdinfo_test(int pid
, int result
)
23 struct proc_bsdinfo bsdinfo
;
27 error
= proc_pidinfo(pid
, PROC_PIDTBSDINFO
, 0, &bsdinfo
, sizeof(bsdinfo
));
28 if ((error
> 0 && result
== TEST_PASS
) || (error
<= 0 && result
== TEST_FAIL
)) {
29 printf("[PASS]: Privilege test on pid = %d for PROC_PIDTBSDINFO passed\n", pid
);
32 printf("[FAIL]: Privilege test on pid = %d for PROC_PIDTBSDINFO failed\n", pid
);
39 taskinfo_test(int pid
, int result
)
41 struct proc_taskinfo taskinfo
;
45 error
= proc_pidinfo(pid
, PROC_PIDTASKINFO
, 0, &taskinfo
, sizeof(taskinfo
));
46 if ((error
> 0 && result
== TEST_PASS
) || (error
<= 0 && result
== TEST_FAIL
)) {
47 printf("[PASS]: Privilege test on pid = %d for PROC_PIDTASKINFO passed\n", pid
);
50 printf("[FAIL] Privilege test on pid = %d for PROC_PIDTASKINFO failed\n", pid
);
56 bsdshortinfo_test(int pid
, int result
)
58 struct proc_bsdshortinfo bsdshortinfo
;
62 error
= proc_pidinfo(pid
, PROC_PIDT_SHORTBSDINFO
, 0, &bsdshortinfo
, sizeof(bsdshortinfo
));
63 if ((error
> 0 && result
== TEST_PASS
) || (error
<= 0 && result
== TEST_FAIL
)) {
64 printf("[PASS]: Privilege test on pid = %d for PROC_PIDT_SHORTBSDINFO passed\n", pid
);
67 printf("[FAIL]: Privilege test on pid = %d for PROC_PIDT_SHORTBSDINFO failed\n", pid
);
74 piduniqid_test(int pid
, int result
)
76 struct proc_uniqidentifierinfo uniqidinfo
;
80 error
= proc_pidinfo(pid
, PROC_PIDUNIQIDENTIFIERINFO
, 0, &uniqidinfo
, sizeof(uniqidinfo
));
81 if ((error
> 0 && result
== TEST_PASS
) || (error
<= 0 && result
== TEST_FAIL
)) {
82 printf("[PASS]: Privilege test on pid = %d for PROC_PIDUNIQIDENTIFIERINFO passed\n", pid
);
85 printf("[FAIL]: Privilege test on pid = %d for PROC_PIDUNIQIDENTIFIERINFO failed\n", pid
);
94 int selfpid
, launchdpid
;
99 if (bsdinfo_test(selfpid
, TEST_PASS
))
101 if (bsdinfo_test(launchdpid
, TEST_FAIL
))
104 if (taskinfo_test(selfpid
, TEST_PASS
))
106 if (taskinfo_test(launchdpid
, TEST_FAIL
))
109 if (bsdshortinfo_test(selfpid
, TEST_PASS
))
111 if (bsdshortinfo_test(launchdpid
, TEST_PASS
))
114 if (piduniqid_test(selfpid
, TEST_PASS
))
116 if (piduniqid_test(launchdpid
, TEST_PASS
))
120 printf("Privilege test for libproc passed [PASS] \n");
124 printf("Privilege test for libproc failed [FAIL] \n");