mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-25 08:36:52 +02:00
gcredentials: Consistently use #ifdef for G_CREDENTIALS_* defines
The alternative is to `#define` all the `G_CREDENTIALS_*` defines to zero in each platform’s definition block, which would result in a combinatorial explosion of `#define`s (or loads of `#undef`s). Stick to the convention for GLib and consistently define them to 1 or leave them undefined. This helps with `-Wundef` support. Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
32f68bef2e
commit
fdba77e584
@ -82,20 +82,20 @@ struct _GCredentials
|
||||
/*< private >*/
|
||||
GObject parent_instance;
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
struct ucred native;
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
struct xucred native;
|
||||
pid_t pid;
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
struct cmsgcred native;
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
struct unpcbid native;
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
struct sockpeercred native;
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
ucred_t *native;
|
||||
#elif G_CREDENTIALS_USE_WIN32_PID
|
||||
#elif defined(G_CREDENTIALS_USE_WIN32_PID)
|
||||
DWORD native;
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
@ -125,7 +125,7 @@ G_DEFINE_TYPE (GCredentials, g_credentials, G_TYPE_OBJECT)
|
||||
static void
|
||||
g_credentials_finalize (GObject *object)
|
||||
{
|
||||
#if G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
GCredentials *credentials = G_CREDENTIALS (object);
|
||||
|
||||
ucred_free (credentials->native);
|
||||
@ -148,11 +148,11 @@ g_credentials_class_init (GCredentialsClass *klass)
|
||||
static void
|
||||
g_credentials_init (GCredentials *credentials)
|
||||
{
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
credentials->native.pid = getpid ();
|
||||
credentials->native.uid = geteuid ();
|
||||
credentials->native.gid = getegid ();
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
gsize i;
|
||||
|
||||
credentials->native.cr_version = XUCRED_VERSION;
|
||||
@ -170,22 +170,22 @@ g_credentials_init (GCredentials *credentials)
|
||||
credentials->native.cr_groups[i] = -1;
|
||||
|
||||
credentials->pid = -1;
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
memset (&credentials->native, 0, sizeof (struct cmsgcred));
|
||||
credentials->native.cmcred_pid = getpid ();
|
||||
credentials->native.cmcred_euid = geteuid ();
|
||||
credentials->native.cmcred_gid = getegid ();
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
credentials->native.unp_pid = getpid ();
|
||||
credentials->native.unp_euid = geteuid ();
|
||||
credentials->native.unp_egid = getegid ();
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
credentials->native.pid = getpid ();
|
||||
credentials->native.uid = geteuid ();
|
||||
credentials->native.gid = getegid ();
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
credentials->native = ucred_get (P_MYID);
|
||||
#elif G_CREDENTIALS_USE_WIN32_PID
|
||||
#elif defined(G_CREDENTIALS_USE_WIN32_PID)
|
||||
credentials->native = GetCurrentProcessId ();
|
||||
#endif
|
||||
}
|
||||
@ -226,14 +226,14 @@ gchar *
|
||||
g_credentials_to_string (GCredentials *credentials)
|
||||
{
|
||||
GString *ret;
|
||||
#if G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#if defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
glib_typeof (credentials->native.cr_ngroups) i;
|
||||
#endif
|
||||
|
||||
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), NULL);
|
||||
|
||||
ret = g_string_new ("GCredentials:");
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
g_string_append (ret, "linux-ucred:");
|
||||
if (credentials->native.pid != (pid_t) -1)
|
||||
g_string_append_printf (ret, "pid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.pid);
|
||||
@ -243,7 +243,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
g_string_append_printf (ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.gid);
|
||||
if (ret->str[ret->len - 1] == ',')
|
||||
ret->str[ret->len - 1] = '\0';
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
g_string_append (ret, "apple-xucred:");
|
||||
g_string_append_printf (ret, "version=%u,", credentials->native.cr_version);
|
||||
if (credentials->native.cr_uid != (uid_t) -1)
|
||||
@ -252,7 +252,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
g_string_append_printf (ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.cr_groups[i]);
|
||||
if (ret->str[ret->len - 1] == ',')
|
||||
ret->str[ret->len - 1] = '\0';
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
g_string_append (ret, "freebsd-cmsgcred:");
|
||||
if (credentials->native.cmcred_pid != (pid_t) -1)
|
||||
g_string_append_printf (ret, "pid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.cmcred_pid);
|
||||
@ -260,7 +260,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
g_string_append_printf (ret, "uid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.cmcred_euid);
|
||||
if (credentials->native.cmcred_gid != (gid_t) -1)
|
||||
g_string_append_printf (ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.cmcred_gid);
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
g_string_append (ret, "netbsd-unpcbid:");
|
||||
if (credentials->native.unp_pid != (pid_t) -1)
|
||||
g_string_append_printf (ret, "pid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.unp_pid);
|
||||
@ -269,7 +269,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
if (credentials->native.unp_egid != (gid_t) -1)
|
||||
g_string_append_printf (ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.unp_egid);
|
||||
ret->str[ret->len - 1] = '\0';
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
g_string_append (ret, "openbsd-sockpeercred:");
|
||||
if (credentials->native.pid != (pid_t) -1)
|
||||
g_string_append_printf (ret, "pid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.pid);
|
||||
@ -279,7 +279,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
g_string_append_printf (ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->native.gid);
|
||||
if (ret->str[ret->len - 1] == ',')
|
||||
ret->str[ret->len - 1] = '\0';
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
g_string_append (ret, "solaris-ucred:");
|
||||
{
|
||||
id_t id;
|
||||
@ -292,7 +292,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
if (ret->str[ret->len - 1] == ',')
|
||||
ret->str[ret->len - 1] = '\0';
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_WIN32_PID
|
||||
#elif defined(G_CREDENTIALS_USE_WIN32_PID)
|
||||
g_string_append_printf (ret, "win32-pid:pid=%lu", credentials->native);
|
||||
#else
|
||||
g_string_append (ret, "unknown");
|
||||
@ -303,7 +303,7 @@ g_credentials_to_string (GCredentials *credentials)
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
/*
|
||||
* Check whether @native contains invalid data. If getsockopt SO_PEERCRED
|
||||
* is used on a TCP socket, it succeeds but yields a credentials structure
|
||||
@ -360,24 +360,24 @@ g_credentials_is_same_user (GCredentials *credentials,
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
ret = FALSE;
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
if (linux_ucred_check_valid (&credentials->native, NULL)
|
||||
&& credentials->native.uid == other_credentials->native.uid)
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
if (credentials->native.cr_version == other_credentials->native.cr_version &&
|
||||
credentials->native.cr_uid == other_credentials->native.cr_uid)
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
if (credentials->native.cmcred_euid == other_credentials->native.cmcred_euid)
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
if (credentials->native.unp_euid == other_credentials->native.unp_euid)
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
if (credentials->native.uid == other_credentials->native.uid)
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
if (ucred_geteuid (credentials->native) == ucred_geteuid (other_credentials->native))
|
||||
ret = TRUE;
|
||||
#else
|
||||
@ -396,11 +396,11 @@ credentials_native_type_check (GCredentialsType requested_type,
|
||||
{
|
||||
GEnumClass *enum_class;
|
||||
GEnumValue *requested;
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
GEnumValue *supported;
|
||||
#endif
|
||||
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
if (requested_type == G_CREDENTIALS_NATIVE_TYPE)
|
||||
return TRUE;
|
||||
#endif
|
||||
@ -408,7 +408,7 @@ credentials_native_type_check (GCredentialsType requested_type,
|
||||
enum_class = g_type_class_ref (g_credentials_type_get_type ());
|
||||
requested = g_enum_get_value (enum_class, requested_type);
|
||||
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
supported = g_enum_get_value (enum_class, G_CREDENTIALS_NATIVE_TYPE);
|
||||
g_assert (supported);
|
||||
g_warning ("g_credentials_%s_native: Trying to %s credentials of type %s "
|
||||
@ -455,9 +455,9 @@ g_credentials_get_native (GCredentials *credentials,
|
||||
if (!credentials_native_type_check (native_type, "get"))
|
||||
return NULL;
|
||||
|
||||
#if G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
return credentials->native;
|
||||
#elif G_CREDENTIALS_SUPPORTED
|
||||
#elif defined(G_CREDENTIALS_SUPPORTED)
|
||||
return &credentials->native;
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
@ -487,9 +487,9 @@ g_credentials_set_native (GCredentials *credentials,
|
||||
if (!credentials_native_type_check (native_type, "set"))
|
||||
return;
|
||||
|
||||
#if G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
memcpy (credentials->native, native, ucred_size ());
|
||||
#elif G_CREDENTIALS_SUPPORTED
|
||||
#elif defined(G_CREDENTIALS_SUPPORTED)
|
||||
memcpy (&credentials->native, native, sizeof (credentials->native));
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
@ -524,12 +524,12 @@ g_credentials_get_unix_user (GCredentials *credentials,
|
||||
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), -1);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
if (linux_ucred_check_valid (&credentials->native, error))
|
||||
ret = credentials->native.uid;
|
||||
else
|
||||
ret = -1;
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
if (credentials->native.cr_version == XUCRED_VERSION)
|
||||
{
|
||||
ret = credentials->native.cr_uid;
|
||||
@ -544,13 +544,13 @@ g_credentials_get_unix_user (GCredentials *credentials,
|
||||
XUCRED_VERSION);
|
||||
ret = -1;
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
ret = credentials->native.cmcred_euid;
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
ret = credentials->native.unp_euid;
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
ret = credentials->native.uid;
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
ret = ucred_geteuid (credentials->native);
|
||||
#else
|
||||
ret = -1;
|
||||
@ -588,24 +588,24 @@ g_credentials_get_unix_pid (GCredentials *credentials,
|
||||
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), -1);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
if (linux_ucred_check_valid (&credentials->native, error))
|
||||
ret = credentials->native.pid;
|
||||
else
|
||||
ret = -1;
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
ret = credentials->native.cmcred_pid;
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
ret = credentials->native.unp_pid;
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
ret = credentials->native.pid;
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
ret = ucred_getpid (credentials->native);
|
||||
#elif G_CREDENTIALS_USE_WIN32_PID
|
||||
#elif defined(G_CREDENTIALS_USE_WIN32_PID)
|
||||
ret = credentials->native;
|
||||
#else
|
||||
|
||||
#if G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#if defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
ret = credentials->pid;
|
||||
#else
|
||||
ret = -1;
|
||||
@ -650,22 +650,22 @@ g_credentials_set_unix_user (GCredentials *credentials,
|
||||
g_return_val_if_fail (uid != (uid_t) -1, FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
credentials->native.uid = uid;
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
credentials->native.cr_uid = uid;
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
credentials->native.cmcred_euid = uid;
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
credentials->native.unp_euid = uid;
|
||||
ret = TRUE;
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
credentials->native.uid = uid;
|
||||
ret = TRUE;
|
||||
#elif !G_CREDENTIALS_SPOOFING_SUPPORTED
|
||||
#elif !defined(G_CREDENTIALS_SPOOFING_SUPPORTED)
|
||||
g_set_error_literal (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_PERMISSION_DENIED,
|
||||
|
@ -169,7 +169,6 @@
|
||||
#undef G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
|
||||
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
|
||||
#define G_CREDENTIALS_HAS_PID 0
|
||||
|
||||
void _g_credentials_set_local_peerid (GCredentials *credentials,
|
||||
pid_t pid);
|
||||
|
@ -6301,7 +6301,7 @@ g_socket_get_credentials (GSocket *socket,
|
||||
|
||||
ret = NULL;
|
||||
|
||||
#if G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED)
|
||||
|
||||
#ifdef SO_PEERCRED
|
||||
{
|
||||
@ -6320,7 +6320,7 @@ g_socket_get_credentials (GSocket *socket,
|
||||
native_creds_buf);
|
||||
}
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
{
|
||||
struct xucred cred;
|
||||
socklen_t optlen = sizeof (cred);
|
||||
@ -6377,7 +6377,7 @@ g_socket_get_credentials (GSocket *socket,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
{
|
||||
struct unpcbid cred;
|
||||
socklen_t optlen = sizeof (cred);
|
||||
@ -6394,7 +6394,7 @@ g_socket_get_credentials (GSocket *socket,
|
||||
&cred);
|
||||
}
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
{
|
||||
ucred_t *ucred = NULL;
|
||||
|
||||
@ -6407,7 +6407,7 @@ g_socket_get_credentials (GSocket *socket,
|
||||
ucred_free (ucred);
|
||||
}
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_WIN32_PID
|
||||
#elif defined(G_CREDENTIALS_USE_WIN32_PID)
|
||||
{
|
||||
DWORD peerid, drc;
|
||||
|
||||
|
@ -75,7 +75,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GUnixCredentialsMessage, g_unix_credentials_message,
|
||||
static gsize
|
||||
g_unix_credentials_message_get_size (GSocketControlMessage *message)
|
||||
{
|
||||
#if G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED)
|
||||
return G_CREDENTIALS_NATIVE_SIZE;
|
||||
#else
|
||||
return 0;
|
||||
@ -85,7 +85,7 @@ g_unix_credentials_message_get_size (GSocketControlMessage *message)
|
||||
static int
|
||||
g_unix_credentials_message_get_level (GSocketControlMessage *message)
|
||||
{
|
||||
#if G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED)
|
||||
return SOL_SOCKET;
|
||||
#else
|
||||
return 0;
|
||||
@ -95,15 +95,15 @@ g_unix_credentials_message_get_level (GSocketControlMessage *message)
|
||||
static int
|
||||
g_unix_credentials_message_get_msg_type (GSocketControlMessage *message)
|
||||
{
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
return SCM_CREDENTIALS;
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
return SCM_CREDS;
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
return SCM_CREDS;
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
return SCM_UCRED;
|
||||
#elif G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#elif defined(G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED)
|
||||
#error "G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED is set but there is no msg_type defined for this platform"
|
||||
#else
|
||||
/* includes G_CREDENTIALS_USE_APPLE_XUCRED */
|
||||
@ -117,7 +117,7 @@ g_unix_credentials_message_deserialize (gint level,
|
||||
gsize size,
|
||||
gpointer data)
|
||||
{
|
||||
#if G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED)
|
||||
GSocketControlMessage *message;
|
||||
GCredentials *credentials;
|
||||
|
||||
@ -157,7 +157,7 @@ static void
|
||||
g_unix_credentials_message_serialize (GSocketControlMessage *_message,
|
||||
gpointer data)
|
||||
{
|
||||
#if G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED)
|
||||
GUnixCredentialsMessage *message = G_UNIX_CREDENTIALS_MESSAGE (_message);
|
||||
|
||||
memcpy (data,
|
||||
@ -289,7 +289,7 @@ g_unix_credentials_message_class_init (GUnixCredentialsMessageClass *class)
|
||||
gboolean
|
||||
g_unix_credentials_message_is_supported (void)
|
||||
{
|
||||
#if G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED)
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
|
@ -55,7 +55,7 @@ test_basic (void)
|
||||
GCredentials *creds = g_credentials_new ();
|
||||
GCredentials *other = g_credentials_new ();
|
||||
gpointer bad_native_creds;
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
GError *error = NULL;
|
||||
gboolean set;
|
||||
pid_t not_me;
|
||||
@ -66,7 +66,7 @@ test_basic (void)
|
||||
g_assert (creds != NULL);
|
||||
g_assert (other != NULL);
|
||||
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
g_assert (g_credentials_is_same_user (creds, other, &error));
|
||||
g_assert_no_error (error);
|
||||
|
||||
@ -79,7 +79,7 @@ test_basic (void)
|
||||
geteuid ());
|
||||
g_assert_no_error (error);
|
||||
|
||||
#if G_CREDENTIALS_HAS_PID
|
||||
#if defined(G_CREDENTIALS_HAS_PID)
|
||||
g_assert_cmpint (g_credentials_get_unix_pid (creds, &error), ==,
|
||||
getpid ());
|
||||
g_assert_no_error (error);
|
||||
@ -90,7 +90,7 @@ test_basic (void)
|
||||
#endif
|
||||
|
||||
set = g_credentials_set_unix_user (other, not_me, &error);
|
||||
#if G_CREDENTIALS_SPOOFING_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SPOOFING_SUPPORTED)
|
||||
g_assert_no_error (error);
|
||||
g_assert (set);
|
||||
|
||||
@ -115,7 +115,7 @@ test_basic (void)
|
||||
g_test_message ("%s", stringified);
|
||||
g_free (stringified);
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
{
|
||||
struct ucred *native = g_credentials_get_native (creds,
|
||||
G_CREDENTIALS_TYPE_LINUX_UCRED);
|
||||
@ -123,7 +123,7 @@ test_basic (void)
|
||||
g_assert_cmpuint (native->uid, ==, geteuid ());
|
||||
g_assert_cmpuint (native->pid, ==, getpid ());
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_APPLE_XUCRED
|
||||
#elif defined(G_CREDENTIALS_USE_APPLE_XUCRED)
|
||||
{
|
||||
struct xucred *native = g_credentials_get_native (creds,
|
||||
G_CREDENTIALS_TYPE_APPLE_XUCRED);
|
||||
@ -131,7 +131,7 @@ test_basic (void)
|
||||
g_assert_cmpuint (native->cr_version, ==, XUCRED_VERSION);
|
||||
g_assert_cmpuint (native->cr_uid, ==, geteuid ());
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_FREEBSD_CMSGCRED
|
||||
#elif defined(G_CREDENTIALS_USE_FREEBSD_CMSGCRED)
|
||||
{
|
||||
struct cmsgcred *native = g_credentials_get_native (creds,
|
||||
G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED);
|
||||
@ -139,7 +139,7 @@ test_basic (void)
|
||||
g_assert_cmpuint (native->cmcred_euid, ==, geteuid ());
|
||||
g_assert_cmpuint (native->cmcred_pid, ==, getpid ());
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_NETBSD_UNPCBID
|
||||
#elif defined(G_CREDENTIALS_USE_NETBSD_UNPCBID)
|
||||
{
|
||||
struct unpcbid *native = g_credentials_get_native (creds,
|
||||
G_CREDENTIALS_TYPE_NETBSD_UNPCBID);
|
||||
@ -147,7 +147,7 @@ test_basic (void)
|
||||
g_assert_cmpuint (native->unp_euid, ==, geteuid ());
|
||||
g_assert_cmpuint (native->unp_pid, ==, getpid ());
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
|
||||
#elif defined(G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED)
|
||||
{
|
||||
struct sockpeercred *native = g_credentials_get_native (creds,
|
||||
G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED);
|
||||
@ -155,7 +155,7 @@ test_basic (void)
|
||||
g_assert_cmpuint (native->uid, ==, geteuid ());
|
||||
g_assert_cmpuint (native->pid, ==, getpid ());
|
||||
}
|
||||
#elif G_CREDENTIALS_USE_SOLARIS_UCRED
|
||||
#elif defined(G_CREDENTIALS_USE_SOLARIS_UCRED)
|
||||
{
|
||||
ucred_t *native = g_credentials_get_native (creds,
|
||||
G_CREDENTIALS_TYPE_SOLARIS_UCRED);
|
||||
@ -168,7 +168,7 @@ test_basic (void)
|
||||
#endif
|
||||
|
||||
|
||||
#if G_CREDENTIALS_USE_LINUX_UCRED
|
||||
#if defined(G_CREDENTIALS_USE_LINUX_UCRED)
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||
"*g_credentials_get_native: Trying to get*"
|
||||
"G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED "
|
||||
|
@ -404,7 +404,7 @@ on_new_connection (GDBusServer *server,
|
||||
|
||||
g_ptr_array_add (data->current_connections, g_object_ref (connection));
|
||||
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
{
|
||||
GCredentials *credentials;
|
||||
|
||||
@ -420,7 +420,7 @@ on_new_connection (GDBusServer *server,
|
||||
#else
|
||||
g_assert_cmpuint (g_credentials_get_unix_user (credentials, NULL), ==,
|
||||
getuid ());
|
||||
#if G_CREDENTIALS_HAS_PID
|
||||
#if defined(G_CREDENTIALS_HAS_PID)
|
||||
g_assert_cmpint (g_credentials_get_unix_pid (credentials, &error), ==,
|
||||
getpid ());
|
||||
g_assert_no_error (error);
|
||||
@ -1026,7 +1026,7 @@ do_test_peer (void)
|
||||
error = NULL;
|
||||
credentials = g_socket_get_credentials (socket, &error);
|
||||
|
||||
#if G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED)
|
||||
g_assert_no_error (error);
|
||||
g_assert (G_IS_CREDENTIALS (credentials));
|
||||
|
||||
@ -1039,7 +1039,7 @@ do_test_peer (void)
|
||||
#else
|
||||
g_assert_cmpuint (g_credentials_get_unix_user (credentials, NULL), ==,
|
||||
getuid ());
|
||||
#if G_CREDENTIALS_HAS_PID
|
||||
#if defined(G_CREDENTIALS_HAS_PID)
|
||||
g_assert_cmpint (g_credentials_get_unix_pid (credentials, &error), ==,
|
||||
getpid ());
|
||||
g_assert_no_error (error);
|
||||
|
@ -2012,7 +2012,7 @@ test_nosigpipe (void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
static gpointer client_setup_thread (gpointer user_data);
|
||||
|
||||
static void
|
||||
@ -2604,7 +2604,7 @@ main (int argc,
|
||||
#ifdef SO_NOSIGPIPE
|
||||
g_test_add_func ("/socket/nosigpipe", test_nosigpipe);
|
||||
#endif
|
||||
#if G_CREDENTIALS_SUPPORTED
|
||||
#if defined(G_CREDENTIALS_SUPPORTED)
|
||||
g_test_add_func ("/socket/credentials/tcp_client", test_credentials_tcp_client);
|
||||
g_test_add_func ("/socket/credentials/tcp_server", test_credentials_tcp_server);
|
||||
g_test_add_func ("/socket/credentials/unix_socketpair", test_credentials_unix_socketpair);
|
||||
|
Loading…
x
Reference in New Issue
Block a user