[glib/wip/smcv/apple-xucred: 3/4] GCredentials: Add the concept of credentials that lack the process ID



commit c3e0fd10f368c355c10818ff108cd45e57d54b2e
Author: Simon McVittie <smcv collabora com>
Date:   Sun Mar 15 18:10:53 2020 +0000

    GCredentials: Add the concept of credentials that lack the process ID
    
    struct xucred on macOS doesn't have the process ID, only the user ID
    and groups.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 gio/gcredentialsprivate.h | 12 ++++++++++++
 gio/tests/credentials.c   |  3 +++
 gio/tests/gdbus-peer.c    |  4 ++++
 3 files changed, 19 insertions(+)
---
diff --git a/gio/gcredentialsprivate.h b/gio/gcredentialsprivate.h
index e9ec09b9f..6d7284bc7 100644
--- a/gio/gcredentialsprivate.h
+++ b/gio/gcredentialsprivate.h
@@ -93,6 +93,13 @@
  */
 #undef G_CREDENTIALS_PREFER_MESSAGE_PASSING
 
+/*
+ * G_CREDENTIALS_HAS_PID:
+ *
+ * Defined to 1 if the %G_CREDENTIALS_NATIVE_TYPE contains the process ID.
+ */
+#undef G_CREDENTIALS_HAS_PID
+
 #ifdef __linux__
 #define G_CREDENTIALS_SUPPORTED 1
 #define G_CREDENTIALS_USE_LINUX_UCRED 1
@@ -101,6 +108,7 @@
 #define G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
 #define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
 #define G_CREDENTIALS_SPOOFING_SUPPORTED 1
+#define G_CREDENTIALS_HAS_PID 1
 
 #elif defined(__FreeBSD__)                                  || \
       defined(__FreeBSD_kernel__) /* Debian GNU/kFreeBSD */ || \
@@ -118,6 +126,7 @@
  * SCM_CREDS, and if we implement getpeereid() in future, we should
  * do the same. */
 #define G_CREDENTIALS_PREFER_MESSAGE_PASSING 1
+#define G_CREDENTIALS_HAS_PID 1
 
 #elif defined(__NetBSD__)
 #define G_CREDENTIALS_SUPPORTED 1
@@ -126,6 +135,7 @@
 #define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct unpcbid))
 /* #undef G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED */
 #define G_CREDENTIALS_SPOOFING_SUPPORTED 1
+#define G_CREDENTIALS_HAS_PID 1
 
 #elif defined(__OpenBSD__)
 #define G_CREDENTIALS_SUPPORTED 1
@@ -134,6 +144,7 @@
 #define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct sockpeercred))
 #define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
 #define G_CREDENTIALS_SPOOFING_SUPPORTED 1
+#define G_CREDENTIALS_HAS_PID 1
 
 #elif defined(__sun__) || defined(__illumos__) || defined (__OpenSolaris_kernel__)
 #include <ucred.h>
@@ -143,6 +154,7 @@
 #define G_CREDENTIALS_NATIVE_SIZE (ucred_size ())
 #define G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
 #define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
+#define G_CREDENTIALS_HAS_PID 1
 
 #endif
 
diff --git a/gio/tests/credentials.c b/gio/tests/credentials.c
index 6d7609964..2f4eff927 100644
--- a/gio/tests/credentials.c
+++ b/gio/tests/credentials.c
@@ -54,9 +54,12 @@ test_basic (void)
   g_assert_cmpuint (g_credentials_get_unix_user (creds, &error), ==,
       geteuid ());
   g_assert_no_error (error);
+
+#if G_CREDENTIALS_HAS_PID
   g_assert_cmpuint (g_credentials_get_unix_pid (creds, &error), ==,
       getpid ());
   g_assert_no_error (error);
+#endif
 
   set = g_credentials_set_unix_user (other, not_me, &error);
 #if G_CREDENTIALS_SPOOFING_SUPPORTED
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index d01bc9a7a..0a6c15b0a 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -362,8 +362,10 @@ on_new_connection (GDBusServer *server,
       g_assert (credentials != NULL);
       g_assert_cmpuint (g_credentials_get_unix_user (credentials, NULL), ==,
                         getuid ());
+#if G_CREDENTIALS_HAS_PID
       g_assert_cmpuint (g_credentials_get_unix_pid (credentials, NULL), ==,
                         getpid ());
+#endif
     }
 #endif
 
@@ -922,8 +924,10 @@ do_test_peer (void)
 
     g_assert_cmpuint (g_credentials_get_unix_user (credentials, NULL), ==,
                       getuid ());
+#if G_CREDENTIALS_HAS_PID
     g_assert_cmpuint (g_credentials_get_unix_pid (credentials, NULL), ==,
                       getpid ());
+#endif
     g_object_unref (credentials);
 #else
     g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]