summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-22 03:14:42 +0200
committerLennart Poettering <lennart@poettering.net>2009-05-20 01:36:26 +0200
commit64c63db21ebdc81f4f830d0d9f1957259cff8f24 (patch)
treeaa394309ed789d9765e4be046ef07405d5296012
parent18f7259a439740d02f6cd727e32348b51191de14 (diff)
sysdeps-unix: introduce _dbus_socket_can_pass_unix_fd()
This function can be used to check if a socket can be used to pass file descriptors. On platforms that don't support this at all this is hardcoded to return FALSE.
-rw-r--r--dbus/dbus-sysdeps-unix.c32
-rw-r--r--dbus/dbus-sysdeps.h2
2 files changed, 34 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 5f94c6a5..74a95661 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -3462,4 +3462,36 @@ _dbus_get_is_errno_eagain_or_ewouldblock (void)
return errno == EAGAIN || errno == EWOULDBLOCK;
}
+/**
+ * Checks whether file descriptors may be passed via the socket
+ *
+ * @param fd the socket
+ * @return TRUE when fd passing over this socket is supported
+ *
+ */
+dbus_bool_t
+_dbus_socket_can_pass_unix_fd(int fd) {
+
+#ifdef SCM_RIGHTS
+ union {
+ struct sockaddr sa;
+ struct sockaddr_storage storage;
+ struct sockaddr_un un;
+ } sa_buf;
+
+ socklen_t sa_len = sizeof(sa_buf);
+
+ _DBUS_ZERO(sa_buf);
+
+ if (getsockname(fd, &sa_buf.sa, &sa_len) < 0)
+ return FALSE;
+
+ return sa_buf.sa.sa_family == AF_UNIX;
+
+#else
+ return FALSE;
+
+#endif
+}
+
/* tests in dbus-sysdeps-util.c */
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index b766f3f9..68fcdf61 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -192,6 +192,8 @@ dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid)
dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory,
DBusCredentials *credentials);
+dbus_bool_t _dbus_socket_can_pass_unix_fd(int fd);
+
/** Opaque type representing an atomically-modifiable integer
* that can be used from multiple threads.
*/