2013-09-26 17:14:40 +02:00

114 lines
2.8 KiB
Plaintext

$NetBSD: patch-ae,v 1.5 2008/12/26 20:05:56 hasso Exp $
--- src/ck-sysdeps-unix.c.orig 2008-11-27 05:10:25 +0200
+++ src/ck-sysdeps-unix.c 2008-11-27 05:09:59 +0200
@@ -35,6 +35,11 @@
#include <linux/kd.h>
#endif
+#ifdef __NetBSD__
+#include <dev/wscons/wsdisplay_usl_io.h>
+#include <sys/un.h>
+#endif
+
#ifdef HAVE_SYS_VT_H
#include <sys/vt.h>
#endif
@@ -53,6 +58,25 @@
#define ERROR -1
#endif
+#ifdef LOCAL_PEEREID
+static gboolean
+ck_nb_getpeeruucred(int socket_fd, pid_t *pid, uid_t *uid)
+{
+ struct unpcbid cred;
+ socklen_t len = sizeof(cred);
+
+ if (getsockopt(socket_fd, 0, LOCAL_PEEREID, &cred, &len) < 0)
+ return FALSE;
+
+ if (pid)
+ *pid = cred.unp_pid;
+ if (uid)
+ *uid = cred.unp_euid;
+
+ return TRUE;
+}
+#endif
+
/* Adapted from dbus-sysdeps-unix.c:_dbus_read_credentials_socket() */
gboolean
ck_get_socket_peer_credentials (int socket_fd,
@@ -99,7 +123,16 @@ ck_get_socket_peer_credentials (int
if (ucred != NULL) {
ucred_free (ucred);
}
-#else /* !SO_PEERCRED && !HAVE_GETPEERUCRED */
+#elif defined(LOCAL_PEEREID)
+ pid_t sockpid = -1, sockuid = -1;
+ if (ck_nb_getpeeruucred(socket_fd, &sockpid, &sockuid) == TRUE) {
+ pid_read = sockpid;
+ uid_read = sockuid;
+ ret = TRUE;
+ } else {
+ g_warning ("Failed to ck_nb_getpeeruucred() credentials\n");
+ }
+#else /* !SO_PEERCRED && !HAVE_GETPEERUCRED && !LOCAL_PEEREID*/
g_warning ("Socket credentials not supported on this OS\n");
#endif
@@ -126,17 +159,17 @@ ck_get_socket_peer_credentials (int
gboolean
ck_fd_is_a_console (int fd)
{
-#ifdef __linux__
+#if defined(__linux__) || defined(__NetBSD__)
struct vt_stat vts;
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__DragonFly__)
int vers;
#endif
int kb_ok;
errno = 0;
-#ifdef __linux__
+#if defined(__linux__) || defined(__NetBSD__)
kb_ok = (ioctl (fd, VT_GETSTATE, &vts) == 0);
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__DragonFly__)
kb_ok = (ioctl (fd, CONS_GETVERS, &vers) == 0);
#else
kb_ok = 1;
@@ -172,6 +205,15 @@ ck_get_a_console_fd (void)
fd = -1;
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+ /* On FreeBSD, try /dev/consolectl first as this will survive
+ * /etc/ttys initialization. */
+ fd = open_a_console ("/dev/consolectl");
+ if (fd >= 0) {
+ goto done;
+ }
+#endif
+
#ifdef __sun
/* On Solaris, first try Sun VT device. */
fd = open_a_console ("/dev/vt/active");
@@ -184,6 +226,14 @@ ck_get_a_console_fd (void)
}
#endif
+#ifdef __NetBSD__
+ /* On NetBSD, first try wsdisplay device. */
+ fd = open_a_console ("/dev/ttyE0");
+ if (fd >= 0) {
+ goto done;
+ }
+#endif
+
#ifdef _PATH_TTY
fd = open_a_console (_PATH_TTY);
if (fd >= 0) {