2017-06-23 20:25:12 +02:00
|
|
|
$NetBSD: patch-bf,v 1.6 2017/06/23 18:25:12 kamil Exp $
|
2008-08-31 08:36:47 +02:00
|
|
|
|
2017-06-23 20:25:12 +02:00
|
|
|
--- lib/procMgr/procMgrPosix.c.orig 2017-02-11 10:06:31.000000000 +0000
|
2008-08-31 08:36:47 +02:00
|
|
|
+++ lib/procMgr/procMgrPosix.c
|
2016-10-09 05:41:56 +02:00
|
|
|
@@ -27,7 +27,7 @@
|
2008-08-31 08:36:47 +02:00
|
|
|
// pull in setresuid()/setresgid() if possible
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <unistd.h>
|
|
|
|
-#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__)
|
|
|
|
+#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) && !defined(__NetBSD__)
|
|
|
|
#include <asm/param.h>
|
2016-10-09 05:41:56 +02:00
|
|
|
#endif
|
|
|
|
#if !defined(sun) && !defined(__APPLE__)
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -47,13 +47,15 @@
|
2016-10-09 05:41:56 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
-#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H)
|
|
|
|
+#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H) || defined(__NetBSD__)
|
|
|
|
// sys/param.h is required on FreeBSD before sys/user.h
|
|
|
|
# include <sys/param.h>
|
|
|
|
// Pull in PAGE_SIZE/PAGE_SHIFT defines ahead of vm_basic_defs.h
|
2017-06-23 20:25:12 +02:00
|
|
|
+#if defined(__FreeBSD__) || defined(__DragonFly__)
|
2016-10-09 05:41:56 +02:00
|
|
|
# include <sys/user.h>
|
|
|
|
#endif
|
|
|
|
-#if defined (__FreeBSD__)
|
2017-06-23 20:25:12 +02:00
|
|
|
+#endif
|
2016-10-09 05:41:56 +02:00
|
|
|
+#if defined (__FreeBSD__) || defined(__NetBSD__)
|
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <paths.h>
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -136,7 +138,7 @@ Bool ProcMgr_PromoteEffectiveToReal(void
|
2016-12-23 05:11:03 +01:00
|
|
|
#ifdef sun
|
|
|
|
#define BASH_PATH "/usr/bin/bash"
|
|
|
|
#else
|
|
|
|
-#define BASH_PATH "/bin/bash"
|
|
|
|
+#define BASH_PATH "@PREFIX@/bin/bash"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -607,7 +609,7 @@ abort:
|
2016-10-09 05:41:56 +02:00
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
-#if defined(__FreeBSD__)
|
|
|
|
+#if defined(__FreeBSD__) || defined(__NetBSD__)
|
|
|
|
ProcMgrProcInfoArray *
|
2008-08-31 08:36:47 +02:00
|
|
|
ProcMgr_ListProcesses(void)
|
|
|
|
{
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -615,7 +617,11 @@ ProcMgr_ListProcesses(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
ProcMgrProcInfo procInfo;
|
|
|
|
Bool failed = TRUE;
|
|
|
|
static kvm_t *kd;
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ struct kinfo_proc2 *kp;
|
|
|
|
+#else
|
|
|
|
struct kinfo_proc *kp;
|
|
|
|
+#endif
|
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
|
|
|
int i;
|
|
|
|
int nentries=-1;
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -638,7 +644,12 @@ ProcMgr_ListProcesses(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
/*
|
|
|
|
* Get the list of process info structs
|
|
|
|
*/
|
|
|
|
+#if defined(__NetBSD__)
|
2016-10-13 23:48:26 +02:00
|
|
|
+ int elemsize = sizeof(struct kinfo_proc2);
|
2016-10-12 15:57:13 +02:00
|
|
|
+ kp = kvm_getproc2(kd, KERN_PROC_ALL, flag, elemsize, &nentries);
|
2016-10-09 05:41:56 +02:00
|
|
|
+#else
|
|
|
|
kp = kvm_getprocs(kd, KERN_PROC_PROC, flag, &nentries);
|
|
|
|
+#endif
|
|
|
|
if (kp == NULL || nentries <= 0) {
|
|
|
|
Warning("%s: failed to get proc infos with error: %s\n",
|
|
|
|
__FUNCTION__, kvm_geterr(kd));
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -666,14 +677,26 @@ ProcMgr_ListProcesses(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
/*
|
|
|
|
* Store the pid of the process.
|
|
|
|
*/
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ procInfo.procId = kp->p_pid;
|
|
|
|
+#else
|
|
|
|
procInfo.procId = kp->ki_pid;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the owner of the process.
|
|
|
|
*/
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ pwd = getpwuid(kp->p_uid);
|
|
|
|
+#else
|
|
|
|
pwd = getpwuid(kp->ki_uid);
|
|
|
|
+#endif
|
|
|
|
procInfo.procOwner = (NULL == pwd)
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ ? Str_SafeAsprintf(NULL, "%d", (int) kp->p_uid)
|
|
|
|
+#else
|
|
|
|
? Str_SafeAsprintf(NULL, "%d", (int) kp->ki_uid)
|
|
|
|
+#endif
|
|
|
|
: Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT);
|
|
|
|
|
|
|
|
/*
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -681,15 +704,24 @@ ProcMgr_ListProcesses(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
* maximum allowed size, then we can save it right now. Else we shall
|
|
|
|
* need to try and parse it from the entire command line.
|
|
|
|
*/
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ if (strlen(kp->p_comm) + 1 < sizeof kp->p_comm) {
|
|
|
|
+ procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT);
|
|
|
|
+#else
|
|
|
|
if (strlen(kp->ki_comm) + 1 < sizeof kp->ki_comm) {
|
|
|
|
procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT);
|
|
|
|
+#endif
|
|
|
|
cmdNameLookup = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the command line string of the process.
|
|
|
|
*/
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ cmdLineTemp = kvm_getargv2(kd, kp, 0);
|
|
|
|
+#else
|
|
|
|
cmdLineTemp = kvm_getargv(kd, kp, 0);
|
|
|
|
+#endif
|
|
|
|
if (cmdLineTemp != NULL) {
|
|
|
|
/*
|
|
|
|
* Flatten the argument list to get cmd & all params.
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -745,9 +777,15 @@ ProcMgr_ListProcesses(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
procInfo.procCmdLine = DynBuf_Detach(&dbuf);
|
|
|
|
DynBuf_Destroy(&dbuf);
|
|
|
|
} else {
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ procInfo.procCmdLine = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT);
|
|
|
|
+ if (cmdNameLookup) {
|
|
|
|
+ procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT);
|
|
|
|
+#else
|
|
|
|
procInfo.procCmdLine = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT);
|
|
|
|
if (cmdNameLookup) {
|
|
|
|
procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT);
|
|
|
|
+#endif
|
|
|
|
cmdNameLookup = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -755,7 +793,11 @@ ProcMgr_ListProcesses(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
/*
|
|
|
|
* Store the start time of the process
|
|
|
|
*/
|
|
|
|
+#if defined(__NetBSD__)
|
|
|
|
+ procInfo.procStartTime = kp->p_rtime_sec;
|
|
|
|
+#else
|
|
|
|
procInfo.procStartTime = kp->ki_start.tv_sec;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the process info pointer into a list buffer.
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -785,7 +827,7 @@ abort:
|
2008-08-31 08:36:47 +02:00
|
|
|
|
|
|
|
return procList;
|
|
|
|
}
|
2016-10-09 05:41:56 +02:00
|
|
|
-#endif // defined(__FreeBSD__)
|
|
|
|
+#endif // defined(__NetBSD__)
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -2022,7 +2064,7 @@ ProcMgr_Free(ProcMgr_AsyncProc *asyncPro
|
2016-10-09 05:41:56 +02:00
|
|
|
free(asyncProc);
|
|
|
|
}
|
|
|
|
|
|
|
|
-#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__)
|
|
|
|
+#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)
|
|
|
|
|
|
|
|
/*
|
|
|
|
*----------------------------------------------------------------------
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -2104,7 +2146,7 @@ ProcMgr_ImpersonateUserStart(const char
|
2016-10-09 05:41:56 +02:00
|
|
|
// first change group
|
|
|
|
#if defined(USERWORLD)
|
|
|
|
ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid);
|
|
|
|
-#elif defined(__APPLE__)
|
|
|
|
+#elif defined(__APPLE__) || defined(__NetBSD__)
|
2016-12-23 05:11:03 +01:00
|
|
|
ret = setegid(ppw->pw_gid);
|
2016-10-09 05:41:56 +02:00
|
|
|
#else
|
|
|
|
ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid);
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -2123,7 +2165,7 @@ ProcMgr_ImpersonateUserStart(const char
|
2016-10-09 05:41:56 +02:00
|
|
|
// now user
|
|
|
|
#if defined(USERWORLD)
|
|
|
|
ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid);
|
|
|
|
-#elif defined(__APPLE__)
|
|
|
|
+#elif defined(__APPLE__) || defined(__NetBSD__)
|
2016-12-23 05:11:03 +01:00
|
|
|
ret = seteuid(ppw->pw_uid);
|
2016-10-09 05:41:56 +02:00
|
|
|
#else
|
|
|
|
ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -2185,7 +2227,7 @@ ProcMgr_ImpersonateUserStop(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
// first change back user
|
|
|
|
#if defined(USERWORLD)
|
|
|
|
ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid);
|
|
|
|
-#elif defined(__APPLE__)
|
|
|
|
+#elif defined(__APPLE__) || defined(__NetBSD__)
|
2016-12-23 05:11:03 +01:00
|
|
|
ret = seteuid(ppw->pw_uid);
|
2016-10-09 05:41:56 +02:00
|
|
|
#else
|
|
|
|
ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
|
2017-06-23 20:25:12 +02:00
|
|
|
@@ -2198,7 +2240,7 @@ ProcMgr_ImpersonateUserStop(void)
|
2016-10-09 05:41:56 +02:00
|
|
|
// now group
|
|
|
|
#if defined(USERWORLD)
|
|
|
|
ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid);
|
|
|
|
-#elif defined(__APPLE__)
|
|
|
|
+#elif defined(__APPLE__) || defined(__NetBSD__)
|
2016-12-23 05:11:03 +01:00
|
|
|
ret = setegid(ppw->pw_gid);
|
2016-10-09 05:41:56 +02:00
|
|
|
#else
|
|
|
|
ret = setresgid(ppw->pw_gid, ppw->pw_gid, ppw->pw_gid);
|