From 7cafd0e183904f17f15c9b1ab7b76eeae0ef7282 Mon Sep 17 00:00:00 2001 From: OBATA Akio Date: Sat, 19 Sep 2015 18:09:05 +0900 Subject: [PATCH] Add support for NetBSD --- configure.ac | 19 ++++++++++-- src/polkit/polkitunixprocess.c | 36 ++++++++++++++++++---- .../polkitbackendinteractiveauthority.c | 2 +- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 85f26b9..2f9edad 100644 --- a/configure.ac +++ b/configure.ac @@ -421,7 +421,7 @@ fi AC_SUBST(PAM_MODULE_DIR) -AC_ARG_WITH(os-type, [ --with-os-type= distribution or OS (redhat/suse/gentoo/pardus/solaris)]) +AC_ARG_WITH(os-type, [ --with-os-type= distribution or OS (redhat/suse/gentoo/pardus/solaris/netbsd)]) #### Check our operating system (distro-tweaks required) if test "z$with_os_type" = "z"; then @@ -450,8 +450,17 @@ if test x$with_os_type = x; then with_os_type=solaris elif test x$operating_system = xfreebsd ; then with_os_type=freebsd + elif test x$operating_system = xnetbsd ; then + with_os_type=netbsd else - with_os_type=unknown + case "$host_os" in + *netbsd*) + with_os_type=netbsd + ;; + *) + with_os_type=unknown + :: + esac fi fi @@ -463,6 +472,7 @@ AM_CONDITIONAL(OS_TYPE_GENTOO, test x$with_os_type = xgentoo, [Running on Gentoo AM_CONDITIONAL(OS_TYPE_PARDUS, test x$with_os_type = xpardus, [Running on Pardus OS'es]) AM_CONDITIONAL(OS_TYPE_SOLARIS, test x$with_os_type = xsolaris, [Running os Solaris OS'es]) AM_CONDITIONAL(OS_TYPE_FREEBSD, test x$with_os_type = xfreebsd, [Running on FreeBSD OS'es]) +AM_CONDITIONAL(OS_TYPE_NETBSD, test x$with_os_type = xnetbsd, [Running on NetBSD OS'es]) AC_ARG_WITH(pam-include, [ --with-pam-include= pam file to include]) @@ -482,7 +492,7 @@ elif test x$with_os_type = xsuse -o x$with_os_type = xsolaris ; then PAM_FILE_INCLUDE_ACCOUNT=common-account PAM_FILE_INCLUDE_PASSWORD=common-password PAM_FILE_INCLUDE_SESSION=common-session -elif test x$with_os_type = xfreebsd ; then +elif test x$with_os_type = xfreebsd -o x$with_os_type = xnetbsd; then PAM_FILE_INCLUDE_AUTH=system PAM_FILE_INCLUDE_ACCOUNT=system PAM_FILE_INCLUDE_PASSWORD=system @@ -515,6 +525,9 @@ case "$host_os" in *freebsd*) AC_DEFINE([HAVE_FREEBSD], 1, [Is this a FreeBSD system?]) ;; + *netbsd*) + AC_DEFINE([HAVE_NETBSD], 1, [Is this an NetBSD system?]) + ;; *openbsd*) AC_DEFINE([HAVE_OPENBSD], 1, [Is this an OpenBSD system?]) ;; diff --git a/src/polkit/polkitunixprocess.c b/src/polkit/polkitunixprocess.c index 61790b0..d4ebf50 100644 --- a/src/polkit/polkitunixprocess.c +++ b/src/polkit/polkitunixprocess.c @@ -29,6 +29,10 @@ #include #include #endif +#ifdef HAVE_NETBSD +#include +#include +#endif #ifdef HAVE_OPENBSD #include #endif @@ -89,8 +93,13 @@ static guint64 get_start_time_for_pid (gint pid, static gint _polkit_unix_process_get_owner (PolkitUnixProcess *process, GError **error); -#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) -static gboolean get_kinfo_proc (gint pid, struct kinfo_proc *p); +#if defined(HAVE_FREEBSD) || defined(HAVE_NETBSD) || defined(HAVE_OPENBSD) +static gboolean get_kinfo_proc (gint pid, +#if defined(HAVE_NETBSD) + struct kinfo_proc2 *p); +#else + struct kinfo_proc *p); +#endif #endif G_DEFINE_TYPE_WITH_CODE (PolkitUnixProcess, polkit_unix_process, G_TYPE_OBJECT, @@ -557,9 +566,14 @@ get_kinfo_proc (pid_t pid, struct kinfo_proc *p) } #endif -#ifdef HAVE_OPENBSD +#if defined(HAVE_NETBSD) || defined(HAVE_OPENBSD) static gboolean -get_kinfo_proc (gint pid, struct kinfo_proc *p) +get_kinfo_proc (gint pid, +#ifdef HAVE_NETBSD + struct kinfo_proc2 *p) +#else + struct kinfo_proc *p) +#endif { int name[6]; u_int namelen; @@ -568,7 +582,11 @@ get_kinfo_proc (gint pid, struct kinfo_proc *p) sz = sizeof(*p); namelen = 0; name[namelen++] = CTL_KERN; +#ifdef HAVE_NETBSD + name[namelen++] = KERN_PROC2; +#else name[namelen++] = KERN_PROC; +#endif name[namelen++] = KERN_PROC_PID; name[namelen++] = pid; name[namelen++] = sz; @@ -586,7 +604,7 @@ get_start_time_for_pid (pid_t pid, GError **error) { guint64 start_time; -#if !defined(HAVE_FREEBSD) && !defined(HAVE_OPENBSD) +#if !defined(HAVE_FREEBSD) && !defined(HAVE_NETBSD) && !defined(HAVE_OPENBSD) gchar *filename; gchar *contents; size_t length; @@ -659,7 +677,11 @@ get_start_time_for_pid (pid_t pid, g_free (filename); g_free (contents); #else +#ifdef HAVE_NETBSD + struct kinfo_proc2 p; +#else struct kinfo_proc p; +#endif start_time = 0; @@ -695,6 +717,8 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, gchar **lines; #if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) struct kinfo_proc p; +#elif defined(HAVE_NETBSD) + struct kinfo_proc2 p; #else gchar filename[64]; guint n; @@ -707,7 +731,7 @@ _polkit_unix_process_get_owner (PolkitUnixProcess *process, lines = NULL; contents = NULL; -#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD) +#if defined(HAVE_FREEBSD) || defined(HAVE_NETBSD) || defined(HAVE_OPENBSD) if (get_kinfo_proc (process->pid, &p) == 0) { g_set_error (error, diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c index 0be60c7..967b764 100644 --- a/src/polkitbackend/polkitbackendinteractiveauthority.c +++ b/src/polkitbackend/polkitbackendinteractiveauthority.c @@ -2240,7 +2240,7 @@ get_users_in_net_group (PolkitIdentity *group, for (;;) { -#if defined HAVE_OPENBSD +#if defined(HAVE_NETBSD) || defined(HAVE_OPENBSD) const char *hostname, *username, *domainname; #else char *hostname, *username, *domainname; -- 2.5.2