Commit d0a14469 authored by David Zeuthen's avatar David Zeuthen

Initial GDBus code-drop from GDBus-standalone repo

Things compile and the test-suite passes. Still need to hook up
gio.symbols and docs. There are still a bunch of TODOs left in the
sources that needs to be addressed.
Signed-off-by: default avatarDavid Zeuthen <davidz@redhat.com>
parent 81e98c39
......@@ -3496,6 +3496,16 @@ if test x$glib_win32_static_compilation = xyes; then
fi
])
# Check for libdbus1 - Optional - is only used in the GDBus test cases
#
PKG_CHECK_MODULES(DBUS1,
dbus-1,
[AC_DEFINE(HAVE_DBUS1, 1, [Define if dbus-1 is available]) have_dbus1=yes],
have_dbus1=no)
AC_SUBST(DBUS1_CFLAGS)
AC_SUBST(DBUS1_LIBS)
AM_CONDITIONAL(HAVE_DBUS1, [test "x$have_dbus1" = "xyes"])
AC_CONFIG_FILES([
glib-2.0.pc
glib-2.0-uninstalled.pc
......
......@@ -79,6 +79,48 @@ gio-marshal.c: gio-marshal.h gio-marshal.list
$(glib_genmarshal) --prefix=_gio_marshal $(srcdir)/gio-marshal.list --body --internal) > $@.tmp && \
mv $@.tmp $@
gdbus_headers = \
gdbusauthobserver.h \
gcredentials.h \
gunixcredentialsmessage.h \
gdbusutils.h \
gdbuserror.h \
gdbusaddress.h \
gdbusconnection.h \
gdbusmessage.h \
gdbusnameowning.h \
gdbusnamewatching.h \
gdbusproxywatching.h \
gdbusproxy.h \
gdbusintrospection.h \
gdbusmethodinvocation.h \
gdbusserver.h \
$(NULL)
gdbus_sources = \
gdbusutils.h gdbusutils.c \
gcredentials.h gcredentials.c \
gunixcredentialsmessage.h gunixcredentialsmessage.c \
gdbusaddress.h gdbusaddress.c \
gdbusauthobserver.h gdbusauthobserver.c \
gdbusauth.h gdbusauth.c \
gdbusauthmechanism.h gdbusauthmechanism.c \
gdbusauthmechanismanon.h gdbusauthmechanismanon.c \
gdbusauthmechanismexternal.h gdbusauthmechanismexternal.c \
gdbusauthmechanismsha1.h gdbusauthmechanismsha1.c \
gdbuserror.h gdbuserror.c \
gdbusconnection.h gdbusconnection.c \
gdbusmessage.h gdbusmessage.c \
gdbusnameowning.h gdbusnameowning.c \
gdbusnamewatching.h gdbusnamewatching.c \
gdbusproxywatching.h gdbusproxywatching.c \
gdbusproxy.h gdbusproxy.c \
gdbusprivate.h gdbusprivate.c \
gdbusintrospection.h gdbusintrospection.c \
gdbusmethodinvocation.h gdbusmethodinvocation.c \
gdbusserver.h gdbusserver.c \
$(NULL)
settings_headers = \
gsettingsbackend.h \
gsettings.h
......@@ -327,6 +369,7 @@ libgio_2_0_la_SOURCES = \
$(unix_sources) \
$(win32_sources) \
$(settings_sources) \
$(gdbus_sources) \
$(local_sources) \
$(marshal_sources) \
$(NULL)
......@@ -454,6 +497,7 @@ gio_headers = \
gzlibcompressor.h \
gzlibdecompressor.h \
$(settings_headers) \
$(gdbus_headers) \
$(NULL)
gioincludedir=$(includedir)/glib-2.0/gio/
......@@ -527,10 +571,22 @@ gsettings_LDADD = \
libgio-2.0.la
gsettings_SOURCES = gsettings-tool.c
schemadir = $(datadir)/glib-2.0/schemas
dist_schema_DATA = gschema.dtd
# ------------------------------------------------------------------------
# gdbus(1) tool
bin_PROGRAMS += gdbus
gdbus_SOURCES = gdbus-tool.c
gdbus_LDADD = libgio-2.0.la
completiondir = $(sysconfdir)/bash_completion.d
completion_SCRIPTS = gdbus-bash-completion.sh
EXTRA_DIST += $(completion_SCRIPTS)
# ------------------------------------------------------------------------
dist-hook: $(BUILT_EXTRA_DIST) ../build/win32/vs9/gio.vcproj
files='$(BUILT_EXTRA_DIST)'; \
for f in $$files; do \
......
/* GDBus - GLib D-Bus Library
*
* Copyright (C) 2008-2009 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#include "config.h"
#include <stdlib.h>
#include <glib/gi18n.h>
#include <gobject/gvaluecollector.h>
#include "gcredentials.h"
#include "gioerror.h"
#ifdef G_OS_UNIX
#include <sys/types.h>
#include <unistd.h>
#endif
/**
* SECTION:gcredentials
* @short_description: Credentials
* @include: gdbus/gdbus.h
*
* The #GCredentials type is used for storing information that can be
* used for identifying, authenticating and authorizing processes.
*
* Most UNIX and UNIX-like operating systems support a secure exchange
* of credentials over a Unix Domain Socket, see
* #GUnixCredentialsMessage, g_unix_connection_send_credentials() and
* g_unix_connection_receive_credentials() for details.
*/
struct _GCredentialsPrivate
{
gint64 unix_user;
gint64 unix_group;
gint64 unix_process;
gchar *windows_user;
};
G_DEFINE_TYPE (GCredentials, g_credentials, G_TYPE_OBJECT);
static void
g_credentials_finalize (GObject *object)
{
GCredentials *credentials = G_CREDENTIALS (object);
g_free (credentials->priv->windows_user);
if (G_OBJECT_CLASS (g_credentials_parent_class)->finalize != NULL)
G_OBJECT_CLASS (g_credentials_parent_class)->finalize (object);
}
static void
g_credentials_class_init (GCredentialsClass *klass)
{
GObjectClass *gobject_class;
g_type_class_add_private (klass, sizeof (GCredentialsPrivate));
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = g_credentials_finalize;
}
static void
g_credentials_init (GCredentials *credentials)
{
credentials->priv = G_TYPE_INSTANCE_GET_PRIVATE (credentials, G_TYPE_CREDENTIALS, GCredentialsPrivate);
credentials->priv->unix_user = -1;
credentials->priv->unix_group = -1;
credentials->priv->unix_process = -1;
credentials->priv->windows_user = NULL;
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_new:
*
* Creates a new empty credentials object.
*
* Returns: A #GCredentials. Free with g_object_unref().
*/
GCredentials *
g_credentials_new (void)
{
return g_object_new (G_TYPE_CREDENTIALS, NULL);
}
/* ---------------------------------------------------------------------------------------------------- */
#ifdef G_OS_UNIX
static GCredentials *
g_credentials_new_for_unix_process (void)
{
GCredentials *credentials;
credentials = g_credentials_new ();
credentials->priv->unix_user = getuid ();
credentials->priv->unix_group = getgid ();
credentials->priv->unix_process = getpid ();
return credentials;
}
#endif
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_new_for_process:
*
* Gets the credentials for the current process. Note that the exact
* set of credentials in the returned object vary according to
* platform.
*
* Returns: A #GCredentials. Free with g_object_unref().
*/
GCredentials *
g_credentials_new_for_process (void)
{
#ifdef G_OS_UNIX
return g_credentials_new_for_unix_process ();
#elif G_OS_WIN32
return g_credentials_new_for_win32_process ();
#else
#warning Please implement g_credentials_new_for_process() for your OS. For now g_credentials_new_for_process() will return empty credentials.
return g_credentials_new ();
#endif
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_new_for_string:
* @str: A string returned from g_credentials_to_string().
* @error: Return location for error.
*
* Constructs a #GCredentials instance from @str.
*
* Returns: A #GCredentials or %NULL if @error is set. The return
* object must be freed with g_object_unref().
*/
GCredentials *
g_credentials_new_for_string (const gchar *str,
GError **error)
{
GCredentials *credentials;
gchar **tokens;
guint n;
g_return_val_if_fail (str != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
tokens = NULL;
credentials = g_credentials_new ();
if (!g_str_has_prefix (str, "GCredentials:"))
goto fail;
tokens = g_strsplit (str + sizeof "GCredentials:" - 1, ",", 0);
for (n = 0; tokens[n] != NULL; n++)
{
const gchar *token = tokens[n];
if (g_str_has_prefix (token, "unix-user:"))
g_credentials_set_unix_user (credentials, atoi (token + sizeof ("unix-user:") - 1));
else if (g_str_has_prefix (token, "unix-group:"))
g_credentials_set_unix_group (credentials, atoi (token + sizeof ("unix-group:") - 1));
else if (g_str_has_prefix (token, "unix-process:"))
g_credentials_set_unix_process (credentials, atoi (token + sizeof ("unix-process:") - 1));
else if (g_str_has_prefix (token, "windows-user:"))
g_credentials_set_windows_user (credentials, token + sizeof ("windows-user:"));
else
goto fail;
}
g_strfreev (tokens);
return credentials;
fail:
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
_("The string `%s' is not a valid credentials string"),
str);
g_object_unref (credentials);
g_strfreev (tokens);
return NULL;
}
/**
* g_credentials_to_string:
* @credentials: A #GCredentials object.
*
* Serializes @credentials to a string that can be used with
* g_credentials_new_for_string().
*
* Returns: A string that should be freed with g_free().
*/
gchar *
g_credentials_to_string (GCredentials *credentials)
{
GString *ret;
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), NULL);
ret = g_string_new ("GCredentials:");
if (credentials->priv->unix_user != -1)
g_string_append_printf (ret, "unix-user=%" G_GINT64_FORMAT ",", credentials->priv->unix_user);
if (credentials->priv->unix_group != -1)
g_string_append_printf (ret, "unix-group=%" G_GINT64_FORMAT ",", credentials->priv->unix_group);
if (credentials->priv->unix_process != -1)
g_string_append_printf (ret, "unix-process=%" G_GINT64_FORMAT ",", credentials->priv->unix_process);
if (credentials->priv->windows_user != NULL)
g_string_append_printf (ret, "windows-user=%s,", credentials->priv->windows_user);
if (ret->str[ret->len - 1] == ',')
ret->str[ret->len - 1] = '\0';
return g_string_free (ret, FALSE);
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_has_unix_user:
* @credentials: A #GCredentials.
*
* Checks if @credentials has a UNIX user credential.
*
* Returns: %TRUE if @credentials has this type of credential, %FALSE otherwise.
*/
gboolean
g_credentials_has_unix_user (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), FALSE);
return credentials->priv->unix_user != -1;
}
/**
* g_credentials_get_unix_user:
* @credentials: A #GCredentials.
*
* Gets the UNIX user identifier from @credentials.
*
* Returns: The identifier or -1 if unset.
*/
gint64
g_credentials_get_unix_user (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), -1);
return credentials->priv->unix_user;
}
/**
* g_credentials_set_unix_user:
* @credentials: A #GCredentials.
* @user_id: A UNIX user identifier (typically type #uid_t) or -1 to unset it.
*
* Sets the UNIX user identifier.
*/
void
g_credentials_set_unix_user (GCredentials *credentials,
gint64 user_id)
{
g_return_if_fail (G_IS_CREDENTIALS (credentials));
credentials->priv->unix_user = user_id;
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_has_unix_group:
* @credentials: A #GCredentials.
*
* Checks if @credentials has a UNIX group credential.
*
* Returns: %TRUE if @credentials has this type of credential, %FALSE otherwise.
*/
gboolean
g_credentials_has_unix_group (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), FALSE);
return credentials->priv->unix_group != -1;
}
/**
* g_credentials_get_unix_group:
* @credentials: A #GCredentials.
*
* Gets the UNIX group identifier from @credentials.
*
* Returns: The identifier or -1 if unset.
*/
gint64
g_credentials_get_unix_group (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), -1);
return credentials->priv->unix_group;
}
/**
* g_credentials_set_unix_group:
* @credentials: A #GCredentials.
* @group_id: A UNIX group identifier (typically type #gid_t) or -1 to unset.
*
* Sets the UNIX group identifier.
*/
void
g_credentials_set_unix_group (GCredentials *credentials,
gint64 group_id)
{
g_return_if_fail (G_IS_CREDENTIALS (credentials));
credentials->priv->unix_group = group_id;
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_has_unix_process:
* @credentials: A #GCredentials.
*
* Checks if @credentials has a UNIX process credential.
*
* Returns: %TRUE if @credentials has this type of credential, %FALSE otherwise.
*/
gboolean
g_credentials_has_unix_process (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), FALSE);
return credentials->priv->unix_process != -1;
}
/**
* g_credentials_get_unix_process:
* @credentials: A #GCredentials.
*
* Gets the UNIX process identifier from @credentials.
*
* Returns: The identifier or -1 if unset.
*/
gint64
g_credentials_get_unix_process (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), -1);
return credentials->priv->unix_process;
}
/**
* g_credentials_set_unix_process:
* @credentials: A #GCredentials.
* @process_id: A UNIX process identifier (typically type #pid_t/#GPid) or -1 to unset.
*
* Sets the UNIX process identifier.
*/
void
g_credentials_set_unix_process (GCredentials *credentials,
gint64 process_id)
{
g_return_if_fail (G_IS_CREDENTIALS (credentials));
credentials->priv->unix_process = process_id;
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_credentials_has_windows_user:
* @credentials: A #GCredentials.
*
* Checks if @credentials has a Windows user SID (Security Identifier).
*
* Returns: %TRUE if @credentials has this type of credential, %FALSE otherwise.
*/
gboolean
g_credentials_has_windows_user (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), FALSE);
return credentials->priv->windows_user != NULL;
}
/**
* g_credentials_get_windows_user:
* @credentials: A #GCredentials.
*
* Gets the Windows User SID from @credentials.
*
* Returns: A string or %NULL if unset. Do not free, the string is owned by @credentials.
*/
const gchar *
g_credentials_get_windows_user (GCredentials *credentials)
{
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), NULL);
return credentials->priv->windows_user;
}
/**
* g_credentials_set_windows_user:
* @credentials: A #GCredentials.
* @user_sid: The Windows User SID or %NULL to unset.
*
* Sets the Windows User SID.
*/
void
g_credentials_set_windows_user (GCredentials *credentials,
const gchar *user_sid)
{
g_return_if_fail (G_IS_CREDENTIALS (credentials));
g_free (credentials->priv->windows_user);
credentials->priv->windows_user = g_strdup (user_sid);
}
/* ---------------------------------------------------------------------------------------------------- */
/* GDBus - GLib D-Bus Library
*
* Copyright (C) 2008-2009 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#ifndef __G_CREDENTIALS_H__
#define __G_CREDENTIALS_H__
#include <gio/giotypes.h>
G_BEGIN_DECLS
#define G_TYPE_CREDENTIALS (g_credentials_get_type ())
#define G_CREDENTIALS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_CREDENTIALS, GCredentials))
#define G_CREDENTIALS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_CREDENTIALS, GCredentialsClass))
#define G_CREDENTIALS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_CREDENTIALS, GCredentialsClass))
#define G_IS_CREDENTIALS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_CREDENTIALS))
#define G_IS_CREDENTIALS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_CREDENTIALS))
typedef struct _GCredentialsClass GCredentialsClass;
typedef struct _GCredentialsPrivate GCredentialsPrivate;
/**
* GCredentials:
*
* The #GCredentials structure contains only private data and
* should only be accessed using the provided API.
*/
struct _GCredentials
{
/*< private >*/
GObject parent_instance;
GCredentialsPrivate *priv;
};
/**
* GCredentialsClass:
*
* Class structure for #GCredentials.
*/
struct _GCredentialsClass
{
/*< private >*/
GObjectClass parent_class;
/* Padding for future expansion */
void (*_g_reserved1) (void);
void (*_g_reserved2) (void);
void (*_g_reserved3) (void);
void (*_g_reserved4) (void);
void (*_g_reserved5) (void);
void (*_g_reserved6) (void);
void (*_g_reserved7) (void);
void (*_g_reserved8) (void);
};
GType g_credentials_get_type (void) G_GNUC_CONST;
GCredentials *g_credentials_new (void);
GCredentials *g_credentials_new_for_process (void);
GCredentials *g_credentials_new_for_string (const gchar *str,
GError **error);
gchar *g_credentials_to_string (GCredentials *credentials);
gboolean g_credentials_has_unix_user (GCredentials *credentials);
gint64 g_credentials_get_unix_user (GCredentials *credentials);
void g_credentials_set_unix_user (GCredentials *credentials,
gint64 user_id);
gboolean g_credentials_has_unix_group (GCredentials *credentials);
gint64 g_credentials_get_unix_group (GCredentials *credentials);
void g_credentials_set_unix_group (GCredentials *credentials,
gint64 group_id);
gboolean g_credentials_has_unix_process (GCredentials *credentials);
gint64 g_credentials_get_unix_process (GCredentials *credentials);
void g_credentials_set_unix_process (GCredentials *credentials,
gint64 process_id);
gboolean g_credentials_has_windows_user (GCredentials *credentials);
const gchar *g_credentials_get_windows_user (GCredentials *credentials);
void g_credentials_set_windows_user (GCredentials *credentials,
const gchar *user_sid);
G_END_DECLS
#endif /* __G_DBUS_PROXY_H__ */
# Check for bash
[ -z "$BASH_VERSION" ] && return
####################################################################################################
__gdbus() {
local IFS=$'\n'
local cur=`_get_cword :`
local suggestions=$(gdbus complete "${COMP_LINE}" ${COMP_POINT})
COMPREPLY=($(compgen -W "$suggestions" -- "$cur"))
# Remove colon-word prefix from COMPREPLY items
case "$cur" in
*:*)
case "$COMP_WORDBREAKS" in
*:*)
local colon_word=${cur%${cur##*:}}
local i=${#COMPREPLY[*]}
while [ $((--i)) -ge 0 ]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
done
;;
esac
;;
esac
}
####################################################################################################
complete -o nospace -F __gdbus gdbus
This diff is collapsed.
This diff is collapsed.
/* GDBus - GLib D-Bus Library
*
* Copyright (C) 2008-2009 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#ifndef __G_DBUS_ADDRESS_H__
#define __G_DBUS_ADDRESS_H__
#include <gio/giotypes.h>
G_BEGIN_DECLS
gboolean g_dbus_is_address (const gchar *string);
gboolean g_dbus_is_supported_address (const gchar *string,
GError **error);
void g_dbus_address_get_stream (const gchar *address,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GIOStream *g_dbus_address_get_stream_finish (GAsyncResult *res,
gchar **out_guid,
GError **error);
GIOStream *g_dbus_address_get_stream_sync (const gchar *address,
gchar **out_guid,
GCancellable *cancellable,
GError **error);
gchar *g_dbus_address_get_for_bus_sync (GBusType bus_type,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* __G_DBUS_ADDRESS_H__ */
This diff is collapsed.
gio/gdbusauth.h 0 → 100644