mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
gdbus: actually return string length from hexdecode()
https://bugzilla.gnome.org/show_bug.cgi?id=794170
This commit is contained in:
parent
8e315bd8ae
commit
f7c0ff773e
@ -404,12 +404,16 @@ hexdecode (const gchar *str,
|
|||||||
g_string_append_c (s, value);
|
g_string_append_c (s, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*out_len = s->len;
|
||||||
ret = g_string_free (s, FALSE);
|
ret = g_string_free (s, FALSE);
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
|
{
|
||||||
|
*out_len = 0;
|
||||||
g_string_free (s, TRUE);
|
g_string_free (s, TRUE);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +262,7 @@ mechanism_client_initiate (GDBusAuthMechanism *mechanism,
|
|||||||
gsize *out_initial_response_len)
|
gsize *out_initial_response_len)
|
||||||
{
|
{
|
||||||
GDBusAuthMechanismAnon *m = G_DBUS_AUTH_MECHANISM_ANON (mechanism);
|
GDBusAuthMechanismAnon *m = G_DBUS_AUTH_MECHANISM_ANON (mechanism);
|
||||||
|
gchar *result;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM_ANON (mechanism), NULL);
|
g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM_ANON (mechanism), NULL);
|
||||||
g_return_val_if_fail (!m->priv->is_server && !m->priv->is_client, NULL);
|
g_return_val_if_fail (!m->priv->is_server && !m->priv->is_client, NULL);
|
||||||
@ -269,10 +270,11 @@ mechanism_client_initiate (GDBusAuthMechanism *mechanism,
|
|||||||
m->priv->is_client = TRUE;
|
m->priv->is_client = TRUE;
|
||||||
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
||||||
|
|
||||||
*out_initial_response_len = -1;
|
|
||||||
|
|
||||||
/* just return our library name and version */
|
/* just return our library name and version */
|
||||||
return g_strdup ("GDBus 0.1");
|
result = g_strdup ("GDBus 0.1");
|
||||||
|
*out_initial_response_len = strlen (result);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -178,6 +178,7 @@ mechanism_server_get_state (GDBusAuthMechanism *mechanism)
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
data_matches_credentials (const gchar *data,
|
data_matches_credentials (const gchar *data,
|
||||||
|
gsize data_len,
|
||||||
GCredentials *credentials)
|
GCredentials *credentials)
|
||||||
{
|
{
|
||||||
gboolean match;
|
gboolean match;
|
||||||
@ -187,7 +188,7 @@ data_matches_credentials (const gchar *data,
|
|||||||
if (credentials == NULL)
|
if (credentials == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (data == NULL || strlen (data) == 0)
|
if (data == NULL || data_len == 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
#if defined(G_OS_UNIX)
|
#if defined(G_OS_UNIX)
|
||||||
@ -227,7 +228,9 @@ mechanism_server_initiate (GDBusAuthMechanism *mechanism,
|
|||||||
|
|
||||||
if (initial_response != NULL)
|
if (initial_response != NULL)
|
||||||
{
|
{
|
||||||
if (data_matches_credentials (initial_response, _g_dbus_auth_mechanism_get_credentials (mechanism)))
|
if (data_matches_credentials (initial_response,
|
||||||
|
initial_response_len,
|
||||||
|
_g_dbus_auth_mechanism_get_credentials (mechanism)))
|
||||||
{
|
{
|
||||||
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
||||||
}
|
}
|
||||||
@ -253,7 +256,9 @@ mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
|
|||||||
g_return_if_fail (m->priv->is_server && !m->priv->is_client);
|
g_return_if_fail (m->priv->is_server && !m->priv->is_client);
|
||||||
g_return_if_fail (m->priv->state == G_DBUS_AUTH_MECHANISM_STATE_WAITING_FOR_DATA);
|
g_return_if_fail (m->priv->state == G_DBUS_AUTH_MECHANISM_STATE_WAITING_FOR_DATA);
|
||||||
|
|
||||||
if (data_matches_credentials (data, _g_dbus_auth_mechanism_get_credentials (mechanism)))
|
if (data_matches_credentials (data,
|
||||||
|
data_len,
|
||||||
|
_g_dbus_auth_mechanism_get_credentials (mechanism)))
|
||||||
{
|
{
|
||||||
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
||||||
}
|
}
|
||||||
@ -340,6 +345,7 @@ mechanism_client_initiate (GDBusAuthMechanism *mechanism,
|
|||||||
/* return the uid */
|
/* return the uid */
|
||||||
#if defined(G_OS_UNIX)
|
#if defined(G_OS_UNIX)
|
||||||
initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) g_credentials_get_unix_user (credentials, NULL));
|
initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) g_credentials_get_unix_user (credentials, NULL));
|
||||||
|
*out_initial_response_len = strlen (initial_response);
|
||||||
#elif defined(G_OS_WIN32)
|
#elif defined(G_OS_WIN32)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#warning Dont know how to send credentials on this OS. The EXTERNAL D-Bus authentication mechanism will not work.
|
#warning Dont know how to send credentials on this OS. The EXTERNAL D-Bus authentication mechanism will not work.
|
||||||
|
@ -949,7 +949,7 @@ mechanism_server_initiate (GDBusAuthMechanism *mechanism,
|
|||||||
m->priv->is_server = TRUE;
|
m->priv->is_server = TRUE;
|
||||||
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_REJECTED;
|
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_REJECTED;
|
||||||
|
|
||||||
if (initial_response != NULL && strlen (initial_response) > 0)
|
if (initial_response != NULL && initial_response_len > 0)
|
||||||
{
|
{
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
gint64 uid;
|
gint64 uid;
|
||||||
@ -1035,6 +1035,7 @@ mechanism_server_data_send (GDBusAuthMechanism *mechanism,
|
|||||||
g_return_val_if_fail (m->priv->state == G_DBUS_AUTH_MECHANISM_STATE_HAVE_DATA_TO_SEND, NULL);
|
g_return_val_if_fail (m->priv->state == G_DBUS_AUTH_MECHANISM_STATE_HAVE_DATA_TO_SEND, NULL);
|
||||||
|
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
*out_data_len = 0;
|
||||||
|
|
||||||
/* TODO: use GDBusAuthObserver here to get the cookie context to use? */
|
/* TODO: use GDBusAuthObserver here to get the cookie context to use? */
|
||||||
cookie_context = "org_gtk_gdbus_general";
|
cookie_context = "org_gtk_gdbus_general";
|
||||||
@ -1057,6 +1058,7 @@ mechanism_server_data_send (GDBusAuthMechanism *mechanism,
|
|||||||
cookie_context,
|
cookie_context,
|
||||||
cookie_id,
|
cookie_id,
|
||||||
m->priv->server_challenge);
|
m->priv->server_challenge);
|
||||||
|
*out_data_len = strlen (s);
|
||||||
|
|
||||||
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_WAITING_FOR_DATA;
|
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_WAITING_FOR_DATA;
|
||||||
|
|
||||||
@ -1120,8 +1122,10 @@ mechanism_client_initiate (GDBusAuthMechanism *mechanism,
|
|||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) getuid ());
|
initial_response = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) getuid ());
|
||||||
|
*out_initial_response_len = strlen (initial_response);
|
||||||
#elif defined (G_OS_WIN32)
|
#elif defined (G_OS_WIN32)
|
||||||
initial_response = _g_dbus_win32_get_user_sid ();
|
initial_response = _g_dbus_win32_get_user_sid ();
|
||||||
|
*out_initial_response_len = strlen (initial_response);
|
||||||
#else
|
#else
|
||||||
#error Please implement for your OS
|
#error Please implement for your OS
|
||||||
#endif
|
#endif
|
||||||
@ -1208,6 +1212,7 @@ mechanism_client_data_send (GDBusAuthMechanism *mechanism,
|
|||||||
|
|
||||||
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED;
|
||||||
|
|
||||||
|
*out_data_len = strlen (m->priv->to_send);
|
||||||
return g_strdup (m->priv->to_send);
|
return g_strdup (m->priv->to_send);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user