From: Jussi Laako Date: Fri, 31 May 2013 10:34:47 +0000 (+0300) Subject: Rename the project X-Git-Tag: upstream/2.4.0^2~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=61db6d534016b27802593c534266bc402c0f9639;p=platform%2Fupstream%2Flibgsignon-glib.git Rename the project --- diff --git a/Makefile.am b/Makefile.am index 3d7030e..624be76 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 DISTCHECK_CONFIGURE_FLAGS = \ --enable-gtk-doc \ --enable-introspection=yes -SUBDIRS = libsignon-glib docs +SUBDIRS = libgsignon-glib docs if ENABLE_PYTHON SUBDIRS += pygobject @@ -13,11 +13,11 @@ SUBDIRS += tests endif pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_in_files = libsignon-glib.pc.in +pkgconfig_in_files = libgsignon-glib.pc.in pkgconfig_DATA = $(pkgconfig_in_files:.pc.in=.pc) dist_noinst_DATA = \ - $(libsignondoc_DATA) \ + $(libgsignondoc_DATA) \ m4/introspection.m4 dist-hook: git-changelog-hook diff --git a/NEWS b/NEWS index be44a40..d3a2150 100644 --- a/NEWS +++ b/NEWS @@ -1,66 +1,2 @@ -libsignon-glib NEWS +libgsignon-glib NEWS -Version 1.9 ------------ - -* Invoke the callback when errors occur -* Add NOCONFIGURE logic to autogen.sh -* Fix the check for pyoverridesdir for python3 -* Fix a memory leak - -Version 1.8 ------------ - -* Add signon_auth_session_process_async - http://code.google.com/p/accounts-sso/issues/detail?id=115 -* Fix all memory leaks detected by valgrind -* Set ID before invoking the client callback - http://code.google.com/p/accounts-sso/issues/detail?id=132 -* Make tests optional at configure time - http://code.google.com/p/accounts-sso/issues/detail?id=124 -* Documentation and build system improvements - -Version 1.7 ------------ - -* Support GValues of type GVariant - http://code.google.com/p/accounts-sso/issues/detail?id=121 - -Version 1.6 ------------ - -* Be Python 3 compatible - -Version 1.5 ------------ - -* Add workaround for missing GStrv support in PyGObject -* Port from dbus-glib to GDBus - -Version 1.4 ------------ - -* Update licence is tests - -Version 1.3 ------------ - -* AuthSession: let the callback unreference "self" - http://code.google.com/p/accounts-sso/issues/detail?id=121 -* Several improvements to tests -* Distribute Vala bindings -* Add Requires.private to pkg-config files - -Version 1.2 ------------ - -* Depend on latest signond -* Remove support for old D-Bus API -* Improve creation of GError instances -* Use dbus-test-runner for running tests if available -* Support new signond D-Bus API -* Several API reference documentation improvements -* Add GObject-Introspection for bindings -* Add GType information to enums -* Tidy public includes -* Define SignonIdentityInfo as a new boxed type diff --git a/README b/README index 57c5115..9640419 100644 --- a/README +++ b/README @@ -20,4 +20,4 @@ The library is licensed under the GNU LGPL version 2.1. Resources --------- -http://code.google.com/p/accounts-sso/sources/list?repo=libsignon-glib +http://code.google.com/p/accounts-sso/sources/list?repo=libgsignon-glib diff --git a/autogen.sh b/autogen.sh index ffe17e2..dc03e16 100755 --- a/autogen.sh +++ b/autogen.sh @@ -3,9 +3,9 @@ srcdir=`dirname $0` test -z "$srcdir" && srcdir=. -(test -f $srcdir/libsignon-glib.pc.in ) || { +(test -f $srcdir/libgsignon-glib.pc.in ) || { echo -n "Error: Directory "\`$srcdir\`" does not look like the " - echo "top-level libsignon-glib directory." + echo "top-level libgsignon-glib directory." exit 1 } diff --git a/configure.ac b/configure.ac index 1cab042..43fe45c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,14 +1,14 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.64]) -AC_INIT([libsignon-glib], - [1.9], +AC_INIT([libgsignon-glib], + [2.0], [http://code.google.com/p/accounts-sso/issues/entry], - [libsignon-glib], + [libgsignon-glib], [http://code.google.com/p/accounts-sso/]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_SRCDIR([libsignon-glib.pc.in]) +AC_CONFIG_SRCDIR([libgsignon-glib.pc.in]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([1.11 check-news nostdinc silent-rules subdir-objects -Wno-portability]) @@ -128,8 +128,8 @@ AM_CONDITIONAL([ENABLE_PYTHON], [test "x$have_python" = "xyes"]) AC_CONFIG_FILES([ Makefile - libsignon-glib/Makefile - libsignon-glib.pc + libgsignon-glib/Makefile + libgsignon-glib.pc docs/Makefile docs/reference/Makefile docs/reference/version.xml diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index ee9ca13..3deeb7e 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -9,7 +9,7 @@ AUTOMAKE_OPTIONS = 1.6 # of using the various options. # The name of the module, e.g. 'glib'. -DOC_MODULE=libsignon-glib +DOC_MODULE=libgsignon-glib # The top-level SGML file. You can change this if you want to. DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml @@ -18,7 +18,7 @@ DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml # gtk-doc will search all .c & .h files beneath here for inline comments # documenting the functions and macros. # e.g. DOC_SOURCE_DIR=../../../gtk -DOC_SOURCE_DIR=$(top_srcdir)/libsignon-glib +DOC_SOURCE_DIR=$(top_srcdir)/libgsignon-glib # Extra options to pass to gtkdoc-scangobj. Not normally needed. SCANGOBJ_OPTIONS= @@ -29,7 +29,7 @@ SCAN_OPTIONS=--rebuild-types --deprecated-guards="SIGNON_DISABLE_DEPRECATED" # Extra options to supply to gtkdoc-mkdb. # e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml -MKDB_OPTIONS=--source-dir=$(top_srcdir)/libsignon-glib --sgml-mode --output-format=xml --name-space=signon +MKDB_OPTIONS=--source-dir=$(top_srcdir)/libgsignon-glib --sgml-mode --output-format=xml --name-space=signon # Extra options to supply to gtkdoc-fixref. Not normally needed. # e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html @@ -38,8 +38,8 @@ FIXXREF_OPTIONS= # Used for dependencies. The docs will be rebuilt if any of these change. # e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h # e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c -HFILE_GLOB=$(top_srcdir)/libsignon-glib/signon-*.h -CFILE_GLOB=$(top_srcdir)/libsignon-glib/signon-*.c +HFILE_GLOB=$(top_srcdir)/libgsignon-glib/signon-*.h +CFILE_GLOB=$(top_srcdir)/libgsignon-glib/signon-*.c # Header files to ignore when scanning. # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h @@ -71,7 +71,7 @@ content_files= # e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) # e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) AM_CPPFLAGS=$(DEPS_CFLAGS) -GTKDOC_LIBS=$(top_builddir)/libsignon-glib/libsignon-glib.la $(DEPS_LIBS) +GTKDOC_LIBS=$(top_builddir)/libgsignon-glib/libgsignon-glib.la $(DEPS_LIBS) # This includes the standard gtk-doc make rules, copied by gtkdocize. include $(top_srcdir)/gtk-doc.make diff --git a/docs/reference/libsignon-glib-docs.xml b/docs/reference/libsignon-glib-docs.xml index ae0c471..fb8bc6f 100644 --- a/docs/reference/libsignon-glib-docs.xml +++ b/docs/reference/libsignon-glib-docs.xml @@ -6,27 +6,27 @@ - libsignon-glib Reference Manual + libgsignon-glib Reference Manual - This document is for libsignon-glib, version &version;. The latest + This document is for libgsignon-glib, version &version;. The latest version of this documentation can be built from the source code at - https://code.google.com/p/accounts-sso/source/checkout?repo=libsignon-glib. + https://code.google.com/p/accounts-sso/source/checkout?repo=libgsignon-glib. - - libsignon-glib Overview + + libgsignon-glib Overview - libsignon-glib provides authorization and authentication management for + libgsignon-glib provides authorization and authentication management for GLib applications. - - libsignon-glib Objects + + libgsignon-glib Objects Object Hierarchy @@ -48,14 +48,14 @@ The signond D-Bus APIs are unstable, subject to change and should not be - used by client applications, which should use libsignon-glib or - libsignon-qt instead. + used by client applications, which should use libgsignon-glib or + libgsignon-qt instead. - - - + + + diff --git a/libgsignon-glib.pc.in b/libgsignon-glib.pc.in new file mode 100644 index 0000000..14434f2 --- /dev/null +++ b/libgsignon-glib.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ +pluginlibdir=@pluginlibdir@ + +Name: libgsignon-glib +Description: A low-level library for managing account credentials. +Version: @VERSION@ +Requires: gsignond glib-2.0 gobject-2.0 gio-unix-2.0 +Libs: -L${libdir} -lgsignon-glib +Cflags: -I${includedir} diff --git a/libgsignon-glib/.gitignore b/libgsignon-glib/.gitignore new file mode 100644 index 0000000..02bc592 --- /dev/null +++ b/libgsignon-glib/.gitignore @@ -0,0 +1,3 @@ +*-glib-gen.h +*-enum-types.[ch] +signon-errors-enum.c diff --git a/libgsignon-glib/Makefile.am b/libgsignon-glib/Makefile.am new file mode 100644 index 0000000..49b724f --- /dev/null +++ b/libgsignon-glib/Makefile.am @@ -0,0 +1,213 @@ +lib_LTLIBRARIES = \ + libgsignon-glib.la + +libgsignon_glib_la_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(srcdir) \ + -I$(top_builddir) \ + -I$(builddir) \ + $(DEPS_CFLAGS) \ + -Wall -Werror +libgsignon_glib_la_LIBADD = $(DEPS_LIBS) +libgsignon_glib_la_LDFLAGS = \ + -version-info 1:0:0 \ + -export-symbols-regex '^signon_' + +nodist_libgsignon_glib_la_SOURCES = \ + signon-marshal.c \ + signon-marshal.h \ + signon-enum-types.h \ + signon-enum-types.c \ + signon-errors-enum.c \ + sso-auth-service-gen.c \ + sso-auth-service-gen.h \ + sso-auth-session-gen.c \ + sso-auth-session-gen.h \ + sso-identity-gen.c \ + sso-identity-gen.h \ + stamp-signon-enum-types.h + +BUILT_SOURCES = \ + $(nodist_libgsignon_glib_la_SOURCES) \ + signon-errors-map.c + +CLEANFILES = \ + $(BUILT_SOURCES) \ + sso-auth-service-gen-doc-com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml \ + sso-auth-session-gen-doc-com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml \ + sso-identity-gen-doc-com.google.code.AccountsSSO.gSingleSignOn.Identity.xml + +libgsignon_glib_la_SOURCES = \ + signon-auth-service.h \ + signon-identity-info.h \ + signon-identity.h \ + signon-dbus-queue.h \ + signon-auth-session.h \ + signon-internals.h \ + signon-auth-service.c \ + signon-identity-info.c \ + signon-identity.c \ + signon-dbus-queue.c \ + signon-auth-session.c \ + signon-errors.h \ + signon-errors.c \ + signon-utils.h \ + signon-utils.c \ + signon-types.h \ + signon-security-context.h \ + signon-security-context.c \ + sso-auth-service.c \ + sso-auth-service.h + +libgsignon_glib_includedir = $(includedir)/libgsignon-glib +libgsignon_glib_include_HEADERS = \ + signon-auth-service.h \ + signon-auth-session.h \ + signon-identity-info.h \ + signon-identity.h \ + signon-security-context.h \ + signon-errors.h \ + signon-enum-types.h \ + signon-glib.h \ + signon-types.h \ + $(signon_headers) + +# Headers with enums to be parsed with glib-mkenums; +# signon-errors.h is handled separately +libgsignon_glib_headers_with_enums = \ + signon-auth-session.h \ + signon-identity-info.h + +# This should come from `pkg-config --variable=interfaces_dir dbus-1` +# default is /usr/share/dbus-1/interfaces +DBUS_INTERFACES_DIR = interfaces + +sso-auth-service-gen.h sso-auth-service-gen.c: $(DBUS_INTERFACES_DIR)/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml + $(AM_V_GEN)gdbus-codegen \ + --generate-c-code sso-auth-service-gen \ + --generate-docbook sso-auth-service-gen-doc \ + --annotate "com.google.code.AccountsSSO.gSingleSignOn.AuthService" org.gtk.GDBus.C.Name SsoAuthService \ + $< + +sso-auth-session-gen.h sso-auth-session-gen.c: $(DBUS_INTERFACES_DIR)/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml + $(AM_V_GEN)gdbus-codegen \ + --generate-c-code sso-auth-session-gen \ + --generate-docbook sso-auth-session-gen-doc \ + --annotate "com.google.code.AccountsSSO.gSingleSignOn.AuthSession" org.gtk.GDBus.C.Name SsoAuthSession \ + $< + +sso-identity-gen.h sso-identity-gen.c: $(DBUS_INTERFACES_DIR)/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml + $(AM_V_GEN)gdbus-codegen \ + --generate-c-code sso-identity-gen \ + --generate-docbook sso-identity-gen-doc \ + --annotate "com.google.code.AccountsSSO.gSingleSignOn.Identity" org.gtk.GDBus.C.Name SsoIdentity \ + $< + +signon-marshal.h: signon-marshal.list Makefile + $(AM_V_GEN)glib-genmarshal --header --prefix=_signon_marshal $< > $@ + +signon-marshal.c: signon-marshal.list Makefile + $(AM_V_GEN)glib-genmarshal --body --prefix=_signon_marshal $< > $@ + +signon-enum-types.h: stamp-signon-enum-types.h + $(AM_V_at)true + +stamp-signon-enum-types.h: Makefile \ + $(libgsignon_glib_headers_with_enums) signon-errors.h + $(AM_V_GEN)( cd $(srcdir) && glib-mkenums \ + --fhead "#ifndef __SIGNON_ENUM_TYPES_H__\n#define __SIGNON_ENUM_TYPES_H__\n#include \n\nG_BEGIN_DECLS\n" \ + --fprod "/* enumerations from \"@filename@\" */\n" \ + --vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define SIGNON_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ + --ftail "G_END_DECLS\n\n#endif /* __SIGNON_ENUM_TYPES_H__ */" \ + $(libgsignon_glib_headers_with_enums) signon-errors.h ) >> xgen-geth \ + && (cmp -s xgen-geth signon-enum-types.h || cp xgen-geth signon-enum-types.h ) \ + && rm -f xgen-geth \ + && echo timestamp > $(@F) + +signon-enum-types.c: Makefile $(libgsignon_glib_headers_with_enums) + $(AM_V_GEN)( cd $(srcdir) && glib-mkenums \ + --fhead "#include \"signon-enum-types.h\"\n" \ + --fhead "#include \"signon-identity-info.h\"\n" \ + --fhead "#include \"signon-auth-session.h\"\n" \ + --fhead "#define g_intern_static_string(s) (s)\n" \ + --fprod "\n/* enumerations from \"@filename@\" */" \ + --ftail "\n#define __SIGNON_ENUM_TYPES_C__\n" \ + --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ + --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \ + --vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (g_intern_static_string (\"@EnumName@\"), values);\n }\n return etype;\n}\n" \ + $(libgsignon_glib_headers_with_enums) ) > xgen-getc \ + && cp xgen-getc signon-enum-types.c \ + && rm -f xgen-getc + +signon-errors-enum.c: Makefile signon-errors.h + $(AM_V_GEN)( cd $(srcdir) && glib-mkenums \ + --fhead "#include \"signon-enum-types.h\"\n#include \"signon-errors.h\"\n#include \"signon-internals.h\"\n#define g_intern_static_string(s) (s)\n" \ + --fprod "\n/* enumerations from \"@filename@\" */" \ + --ftail "\n#define __SIGNON_ENUM_TYPES_C__\n" \ + --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ + --vprod " { @VALUENAME@, SED@VALUENAME@, \"@valuenick@\" }," \ + --vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (g_intern_static_string (\"@EnumName@\"), values);\n }\n return etype;\n}\n" \ + signon-errors.h ) | \ + $(SED) -e 's/SEDSIGNON_ERROR_\([^,]*\)/SIGNOND_\1_ERR_NAME/' \ + > xgen-getc \ + && cp xgen-getc signon-errors-enum.c \ + && rm -f xgen-getc + +signon-errors-map.c: Makefile signon-errors.h + $(AM_V_GEN)( cd $(srcdir) && \ + echo "static const GDBusErrorEntry signon_error_entries[] = {" && \ + grep "^ *SIGNON_ERROR_" signon-errors.h | \ + $(SED) -e 's/SIGNON_ERROR_\([A-Z_0-9]*\).*/{ SIGNON_ERROR_\1, SIGNOND_\1_ERR_NAME },/' && \ + echo -e "};\n" ) > signon-errors-map.c + +dist_noinst_DATA = \ + signon-marshal.list \ + stamp-signon-enum-types.h + +-include $(INTROSPECTION_MAKEFILE) +INTROSPECTION_GIRS = +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) +INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) + +if HAVE_INTROSPECTION +introspection_sources = \ + signon-auth-service.c \ + signon-auth-service.h \ + signon-auth-session.c \ + signon-auth-session.h \ + signon-enum-types.h \ + signon-enum-types.c \ + signon-errors.c \ + signon-errors.h \ + signon-identity-info.c \ + signon-identity-info.h \ + signon-identity.c \ + signon-identity.h + +Signon-1.0.gir: libgsignon-glib.la +Signon_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0 +Signon_1_0_gir_SCANNERFLAGS = \ + --identifier-prefix=Signon \ + --symbol-prefix=signon \ + --c-include="libgsignon-glib/signon-glib.h" \ + --warn-all +Signon_1_0_gir_CFLAGS = \ + -I$(top_srcdir) \ + $(DEPS_CFLAGS) +Signon_1_0_gir_LIBS = libgsignon-glib.la +Signon_1_0_gir_FILES = $(introspection_sources) +INTROSPECTION_GIRS += Signon-1.0.gir + +girdir = $(datadir)/gir-1.0 +gir_DATA = $(INTROSPECTION_GIRS) + +typelibdir = $(libdir)/girepository-1.0 +typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) + +CLEANFILES += $(gir_DATA) $(typelib_DATA) +endif + +# Vala bindings +vapidir = $(datadir)/vala/vapi +dist_vapi_DATA = \ + signon.vapi diff --git a/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml b/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml new file mode 100644 index 0000000..9fc893c --- /dev/null +++ b/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml b/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml new file mode 100644 index 0000000..7047757 --- /dev/null +++ b/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml b/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml new file mode 100644 index 0000000..8e265de --- /dev/null +++ b/libgsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libgsignon-glib/signon-auth-service.c b/libgsignon-glib/signon-auth-service.c new file mode 100644 index 0000000..5da7ca8 --- /dev/null +++ b/libgsignon-glib/signon-auth-service.c @@ -0,0 +1,369 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +/** + * SECTION:signon-auth-service + * @title: SignonAuthService + * @short_description: The authorization service object + * + * The #SignonAuthService is the main object in this library. + */ + +#include "signon-auth-service.h" +#include "signon-errors.h" +#include "signon-internals.h" +#include "sso-auth-service.h" +#include +#include + +G_DEFINE_TYPE (SignonAuthService, signon_auth_service, G_TYPE_OBJECT); + +struct _SignonAuthServicePrivate +{ + SsoAuthService *proxy; + GCancellable *cancellable; +}; + +typedef struct _MethodCbData +{ + SignonAuthService *service; + SignonQueryMethodsCb cb; + gpointer userdata; +} MethodCbData; + +typedef struct _MechanismCbData +{ + SignonAuthService *service; + SignonQueryMechanismCb cb; + gpointer userdata; + gchar *method; +} MechanismCbData; + +typedef struct _IdentityCbData +{ + SignonAuthService *service; + SignonQueryIdentitiesCb cb; + gpointer userdata; +} IdentityCbData; + +#define SIGNON_AUTH_SERVICE_PRIV(obj) (SIGNON_AUTH_SERVICE(obj)->priv) + +static void +signon_auth_service_init (SignonAuthService *auth_service) +{ + SignonAuthServicePrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (auth_service, SIGNON_TYPE_AUTH_SERVICE, + SignonAuthServicePrivate); + auth_service->priv = priv; + + /* Create the proxy */ + priv->cancellable = g_cancellable_new (); + priv->proxy = sso_auth_service_get_instance (); +} + +static void +signon_auth_service_dispose (GObject *object) +{ + SignonAuthService *auth_service = SIGNON_AUTH_SERVICE (object); + SignonAuthServicePrivate *priv = auth_service->priv; + + if (priv->cancellable) + { + g_cancellable_cancel (priv->cancellable); + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + } + + if (priv->proxy) + { + g_object_unref (priv->proxy); + priv->proxy = NULL; + } + + G_OBJECT_CLASS (signon_auth_service_parent_class)->dispose (object); +} + +static void +signon_auth_service_finalize (GObject *object) +{ + G_OBJECT_CLASS (signon_auth_service_parent_class)->finalize (object); +} + +static void +signon_auth_service_class_init (SignonAuthServiceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (SignonAuthServicePrivate)); + + object_class->dispose = signon_auth_service_dispose; + object_class->finalize = signon_auth_service_finalize; +} + +/** + * signon_auth_service_new: + * + * Create a new #SignonAuthService. + * + * Returns: an instance of an #SignonAuthService. + */ +SignonAuthService * +signon_auth_service_new () +{ + return g_object_new (SIGNON_TYPE_AUTH_SERVICE, NULL); +} + +static void +auth_query_methods_cb (GObject *object, GAsyncResult *res, + gpointer user_data) +{ + SsoAuthService *proxy = SSO_AUTH_SERVICE (object); + MethodCbData *data = (MethodCbData*)user_data; + gchar **value = NULL; + GError *error = NULL; + + g_return_if_fail (data != NULL); + + sso_auth_service_call_query_methods_finish (proxy, &value, + res, &error); + (data->cb) + (data->service, value, error, data->userdata); + + g_clear_error (&error); + g_slice_free (MethodCbData, data); +} + +static void +auth_query_mechanisms_cb (GObject *object, GAsyncResult *res, + gpointer user_data) +{ + SsoAuthService *proxy = SSO_AUTH_SERVICE (object); + MechanismCbData *data = (MechanismCbData*) user_data; + gchar **value = NULL; + GError *error = NULL; + + g_return_if_fail (data != NULL); + + sso_auth_service_call_query_mechanisms_finish (proxy, &value, + res, &error); + (data->cb) + (data->service, data->method, value, error, data->userdata); + + if (error) + g_error_free (error); + g_free (data->method); + g_slice_free (MechanismCbData, data); +} + +/** + * SignonQueryMethodsCb: + * @auth_service: the #SignonAuthService. + * @methods: (transfer full) (type GStrv): list of available methods. + * @error: a #GError if an error occurred, %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_auth_service_query_methods(). + */ + +/** + * signon_auth_service_query_methods: + * @auth_service: the #SignonAuthService. + * @cb: (scope async): callback to be invoked. + * @user_data: user data. + * + * Lists all the available methods. + */ +void +signon_auth_service_query_methods (SignonAuthService *auth_service, + SignonQueryMethodsCb cb, + gpointer user_data) +{ + SignonAuthServicePrivate *priv; + + g_return_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service)); + g_return_if_fail (cb != NULL); + priv = SIGNON_AUTH_SERVICE_PRIV (auth_service); + + MethodCbData *cb_data; + cb_data = g_slice_new (MethodCbData); + cb_data->service = auth_service; + cb_data->cb = cb; + cb_data->userdata = user_data; + + sso_auth_service_call_query_methods (priv->proxy, + priv->cancellable, + auth_query_methods_cb, + cb_data); +} + +/** + * SignonQueryMechanismCb: + * @auth_service: the #SignonAuthService. + * @method: the authentication method being inspected. + * @mechanisms: (transfer full) (type GStrv): list of available mechanisms. + * @error: a #GError if an error occurred, %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_auth_service_query_mechanisms(). + */ + +/** + * signon_auth_service_query_mechanisms: + * @auth_service: the #SignonAuthService. + * @method: the name of the method whose mechanisms must be + * retrieved. + * @cb: (scope async): callback to be invoked. + * @user_data: user data. + * + * Lists all the available mechanisms. + */ +void +signon_auth_service_query_mechanisms (SignonAuthService *auth_service, + const gchar *method, + SignonQueryMechanismCb cb, + gpointer user_data) +{ + SignonAuthServicePrivate *priv; + + g_return_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service)); + g_return_if_fail (cb != NULL); + priv = SIGNON_AUTH_SERVICE_PRIV (auth_service); + + MechanismCbData *cb_data; + cb_data = g_slice_new (MechanismCbData); + cb_data->service = auth_service; + cb_data->cb = cb; + cb_data->userdata = user_data; + cb_data->method = g_strdup (method); + + sso_auth_service_call_query_mechanisms (priv->proxy, + method, + priv->cancellable, + auth_query_mechanisms_cb, + cb_data); +} + +static void +auth_query_identities_cb (GObject *object, GAsyncResult *res, + gpointer user_data) +{ + SsoAuthService *proxy = SSO_AUTH_SERVICE (object); + IdentityCbData *data = (IdentityCbData *) user_data; + GVariant *value = NULL; + GError *error = NULL; + GVariantIter iter; + GVariant *identity_var; + SignonIdentityList *identity_list = NULL; + + g_return_if_fail (data != NULL); + + sso_auth_service_call_query_identities_finish (proxy, + &value, + res, + &error); + + if (value && !error) + { + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "@a{sv}", &identity_var)) + { + identity_list = + g_list_append (identity_list, + signon_identity_info_new_from_variant (identity_var)); + g_variant_unref (identity_var); + } + } + (data->cb) + (data->service, identity_list, error, data->userdata); + + if (error) + g_error_free (error); + g_slice_free (IdentityCbData, data); +} + +/** + * SignonQueryIdentitiesCb: + * @auth_service: the #SignonAuthService. + * @identities: (transfer full): #GList based list of #SignonIdentityInfo. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_auth_service_query_identities(). + */ + +/** + * signon_auth_service_query_identities: + * @auth_service: the #SignonAuthService. + * @filter: filter variant dictionary based on #GHashTable. + * @application_context: application security context, can be %NULL. + * @cb: (scope async): callback to be invoked. + * @user_data: user data. + */ +void +signon_auth_service_query_identities (SignonAuthService *auth_service, + SignonIdentityFilter *filter, + const gchar *application_context, + SignonQueryIdentitiesCb cb, + gpointer user_data) +{ + SignonAuthServicePrivate *priv; + GVariantBuilder builder; + GHashTableIter iter; + const gchar *key; + GVariant *value; + GVariant *filter_var; + + g_return_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service)); + g_return_if_fail (cb != NULL); + priv = SIGNON_AUTH_SERVICE_PRIV (auth_service); + + IdentityCbData *cb_data; + cb_data = g_slice_new (IdentityCbData); + cb_data->service = auth_service; + cb_data->cb = cb; + cb_data->userdata = user_data; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + if (filter) + { + g_hash_table_iter_init (&iter, filter); + while (g_hash_table_iter_next (&iter, + (gpointer) &key, + (gpointer) &value)) + g_variant_builder_add (&builder, "{sv}", key, value); + } + filter_var = g_variant_builder_end (&builder); + + if (!application_context) + application_context = ""; + + sso_auth_service_call_query_identities (priv->proxy, + filter_var, + application_context, + priv->cancellable, + auth_query_identities_cb, + cb_data); +} + diff --git a/libgsignon-glib/signon-auth-service.h b/libgsignon-glib/signon-auth-service.h new file mode 100644 index 0000000..9240dc8 --- /dev/null +++ b/libgsignon-glib/signon-auth-service.h @@ -0,0 +1,104 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _SIGNON_AUTH_SERVICE_H_ +#define _SIGNON_AUTH_SERVICE_H_ + +#include + +G_BEGIN_DECLS + +#define SIGNON_TYPE_AUTH_SERVICE (signon_auth_service_get_type ()) +#define SIGNON_AUTH_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIGNON_TYPE_AUTH_SERVICE, SignonAuthService)) +#define SIGNON_AUTH_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIGNON_TYPE_AUTH_SERVICE, SignonAuthServiceClass)) +#define SIGNON_IS_AUTH_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIGNON_TYPE_AUTH_SERVICE)) +#define SIGNON_IS_AUTH_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_AUTH_SERVICE)) +#define SIGNON_AUTH_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_AUTH_SERVICE, SignonAuthServiceClass)) + +typedef struct _SignonAuthServiceClass SignonAuthServiceClass; +typedef struct _SignonAuthServicePrivate SignonAuthServicePrivate; +typedef struct _SignonAuthService SignonAuthService; + +/** + * SignonAuthServiceClass: + * + * Opaque struct. Use the accessor functions below. + */ +struct _SignonAuthServiceClass +{ + GObjectClass parent_class; +}; + +/** + * SignonAuthService: + * + * Opaque struct. Use the accessor functions below. + */ +struct _SignonAuthService +{ + GObject parent_instance; + SignonAuthServicePrivate *priv; +}; + +GType signon_auth_service_get_type (void) G_GNUC_CONST; + +typedef void (*SignonQueryMethodsCb) (SignonAuthService *auth_service, + gchar **methods, + const GError *error, + gpointer user_data); + +typedef void (*SignonQueryMechanismCb) (SignonAuthService *auth_service, + const gchar *method, + gchar **mechanisms, + const GError *error, + gpointer user_data); + +typedef GList SignonIdentityList; +typedef GHashTable SignonIdentityFilter; + +typedef void (*SignonQueryIdentitiesCb) (SignonAuthService *auth_service, + SignonIdentityList *identities, + const GError *error, + gpointer user_data); + +SignonAuthService *signon_auth_service_new (); + +void signon_auth_service_query_methods (SignonAuthService *auth_service, + SignonQueryMethodsCb cb, + gpointer user_data); + +void signon_auth_service_query_mechanisms (SignonAuthService *auth_service, + const gchar *method, + SignonQueryMechanismCb cb, + gpointer user_data); + +void signon_auth_service_query_identities (SignonAuthService *auth_service, + SignonIdentityFilter *filter, + const gchar *application_context, + SignonQueryIdentitiesCb cb, + gpointer user_data); + +G_END_DECLS + +#endif /* _SIGNON_AUTH_SERVICE_H_ */ diff --git a/libgsignon-glib/signon-auth-session.c b/libgsignon-glib/signon-auth-session.c new file mode 100644 index 0000000..230b513 --- /dev/null +++ b/libgsignon-glib/signon-auth-session.c @@ -0,0 +1,917 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +/** + * SECTION:signon-auth-session + * @title: SignonAuthSession + * @short_description: Authentication session handler. + * + * The #SignonAuthSession object is responsible for handling the client + * authentication. #SignonAuthSession objects can be created from existing + * identities (via signon_identity_create_session() or by passing a non-zero ID + * to signon_auth_session_new()), in which case the authentication data such as + * username and password will be implicitly taken from the identity, or they + * can be created with no existing identity bound to them, in which case all + * the authentication data must be filled in by the client when + * signon_auth_session_process() is called. + */ + +#include "signon-internals.h" +#include "signon-auth-session.h" +#include "signon-dbus-queue.h" +#include "signon-errors.h" +#include "signon-marshal.h" +#include "signon-utils.h" +#include "signon-identity.h" +#include "sso-auth-service.h" +#include "sso-auth-session-gen.h" + + +G_DEFINE_TYPE (SignonAuthSession, signon_auth_session, G_TYPE_OBJECT); + +enum +{ + PROP_0, + PROP_IDENTITY, + PROP_APPCTX +}; + +/* Signals */ +enum +{ + STATE_CHANGED, + LAST_SIGNAL +}; + +static guint auth_session_signals[LAST_SIGNAL] = { 0 }; +static const gchar auth_session_process_pending_message[] = + "The request is added to queue."; +static const gchar data_key_process[] = "signon-process"; + +struct _SignonAuthSessionPrivate +{ + SsoAuthSession *proxy; + SignonIdentity *identity; + GCancellable *cancellable; + + guint id; + gchar *method_name; + + gboolean registering; + gboolean busy; + gboolean canceled; + gboolean dispose_has_run; + + guint signal_state_changed; + guint signal_unregistered; +}; + +typedef struct _AuthSessionQueryAvailableMechanismsData +{ + gchar **wanted_mechanisms; + gpointer cb_data; +} AuthSessionQueryAvailableMechanismsData; + +typedef struct _AuthSessionProcessData +{ + GVariant *session_data; + gchar *mechanism; + GCancellable *cancellable; +} AuthSessionProcessData; + +typedef struct _AuthSessionQueryAvailableMechanismsCbData +{ + SignonAuthSession *self; + SignonAuthSessionQueryAvailableMechanismsCb cb; + gpointer user_data; +} AuthSessionQueryAvailableMechanismsCbData; + +typedef struct _AuthSessionProcessCbData +{ + SignonAuthSessionProcessCb cb; + gpointer user_data; +} AuthSessionProcessCbData; + +#define SIGNON_AUTH_SESSION_PRIV(obj) (SIGNON_AUTH_SESSION(obj)->priv) +#define SIGNON_AUTH_SESSION_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionPrivate)) + + +static void auth_session_state_changed_cb (GDBusProxy *proxy, gint state, gchar *message, gpointer user_data); +static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, gpointer user_data); + +static gboolean auth_session_priv_init (SignonAuthSession *self, const gchar *method_name, GError **err); + +static void auth_session_query_available_mechanisms_ready_cb (gpointer object, const GError *error, gpointer user_data); +static void auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data); + +static void auth_session_check_remote_object(SignonAuthSession *self); + +static void +auth_session_process_data_free (AuthSessionProcessData *process_data) +{ + g_free (process_data->mechanism); + g_variant_unref (process_data->session_data); + g_slice_free (AuthSessionProcessData, process_data); +} + +static void +auth_session_process_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SignonAuthSession *self; + SsoAuthSession *proxy = SSO_AUTH_SESSION (object); + GSimpleAsyncResult *res_process = (GSimpleAsyncResult *)userdata; + GVariant *reply; + GError *error = NULL; + + g_return_if_fail (res_process != NULL); + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + sso_auth_session_call_process_finish (proxy, &reply, res, &error); + + self = SIGNON_AUTH_SESSION (g_async_result_get_source_object ( + (GAsyncResult *)res_process)); + self->priv->busy = FALSE; + + if (G_LIKELY (error == NULL)) + { + g_simple_async_result_set_op_res_gpointer (res_process, reply, + (GDestroyNotify) + g_variant_unref); + } + else + { + g_simple_async_result_take_error (res_process, error); + } + + /* We use the idle variant in order to avoid the following critical + * message: + * g_main_context_pop_thread_default: assertion `g_queue_peek_head (stack) == context' failed + */ + g_simple_async_result_complete_in_idle (res_process); + g_object_unref (res_process); + g_object_unref (self); +} + +static void +auth_session_process_ready_cb (gpointer object, const GError *error, gpointer user_data) +{ + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + SignonAuthSessionPrivate *priv; + GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); + AuthSessionProcessData *process_data; + + g_return_if_fail (self != NULL); + priv = self->priv; + + if (error != NULL) + { + DEBUG ("AuthSessionError: %s", error->message); + g_simple_async_result_set_from_error (res, error); + g_simple_async_result_complete (res); + g_object_unref (res); + return; + } + + if (priv->canceled) + { + priv->busy = FALSE; + priv->canceled = FALSE; + g_simple_async_result_set_error (res, + signon_error_quark (), + SIGNON_ERROR_SESSION_CANCELED, + "Authentication session was canceled"); + g_simple_async_result_complete (res); + g_object_unref (res); + return; + } + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + process_data = g_object_get_data ((GObject *)res, data_key_process); + g_return_if_fail (process_data != NULL); + + sso_auth_session_call_process (priv->proxy, + process_data->session_data, + process_data->mechanism, + process_data->cancellable, + auth_session_process_reply, + res); +} + +static void +process_async_cb_wrapper (GObject *object, GAsyncResult *res, + gpointer user_data) +{ + AuthSessionProcessCbData *cb_data = user_data; + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + GVariant *v_reply; + GHashTable *reply = NULL; + GError *error = NULL; + gboolean cancelled; + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + v_reply = signon_auth_session_process_finish (self, res, &error); + + cancelled = error != NULL && + error->domain == G_IO_ERROR && + error->code == G_IO_ERROR_CANCELLED; + + /* Do not invoke the callback if the operation was cancelled */ + if (cb_data->cb != NULL && !cancelled) + { + if (v_reply != NULL) + reply = signon_hash_table_from_variant (v_reply); + + cb_data->cb (self, reply, error, cb_data->user_data); + } + g_variant_unref (v_reply); + + g_slice_free (AuthSessionProcessCbData, cb_data); + g_clear_error (&error); +} + +static GQuark +auth_session_object_quark () +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string ("auth_session_object_quark"); + + return quark; +} + +static void +signon_auth_session_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + + switch (property_id) + { + case PROP_IDENTITY: + self->priv->identity = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +signon_auth_session_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + + switch (property_id) + { + case PROP_IDENTITY: + g_value_set_object (value, self->priv->identity); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +signon_auth_session_init (SignonAuthSession *self) +{ + self->priv = SIGNON_AUTH_SESSION_GET_PRIV (self); + self->priv->cancellable = g_cancellable_new (); +} + +static void +signon_auth_session_dispose (GObject *object) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + if (priv->dispose_has_run) + return; + + if (priv->cancellable) + { + g_cancellable_cancel (priv->cancellable); + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + } + + if (priv->proxy) + { + g_signal_handler_disconnect (priv->proxy, priv->signal_state_changed); + g_signal_handler_disconnect (priv->proxy, priv->signal_unregistered); + g_object_unref (priv->proxy); + + priv->proxy = NULL; + } + + G_OBJECT_CLASS (signon_auth_session_parent_class)->dispose (object); + + priv->dispose_has_run = TRUE; +} + +static void +signon_auth_session_finalize (GObject *object) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION(object)); + + SignonAuthSession *self = SIGNON_AUTH_SESSION(object); + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + g_free (priv->method_name); + g_object_unref (priv->identity); + + G_OBJECT_CLASS (signon_auth_session_parent_class)->finalize (object); +} + +static void +signon_auth_session_class_init (SignonAuthSessionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + object_class->set_property = signon_auth_session_set_property; + object_class->get_property = signon_auth_session_get_property; + + pspec = g_param_spec_object ("identity", + "Identity Object", + "Identity Object construct parameter", + SIGNON_TYPE_IDENTITY, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, + PROP_IDENTITY, + pspec); + + g_type_class_add_private (object_class, sizeof (SignonAuthSessionPrivate)); + + /** + * SignonAuthSession::state-changed: + * @auth_session: the #SignonAuthSession + * @state: the current state of the #SignonAuthSession + * @message: the message associated with the state change + * + * Emitted when the state of the #SignonAuthSession changes. + */ + auth_session_signals[STATE_CHANGED] = + g_signal_new ("state-changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + 0, + NULL, + NULL, + _signon_marshal_VOID__INT_STRING, + G_TYPE_NONE, 2, + G_TYPE_INT, + G_TYPE_STRING); + + object_class->dispose = signon_auth_session_dispose; + object_class->finalize = signon_auth_session_finalize; +} + +/** + * signon_auth_session_new: + * @parent: #SignonIdentity parent object. + * @method_name: the name of the authentication method to be used. + * @err: a pointer to a location which will contain the error, in case this + * function fails. + * + * Creates a new #SignonAuthSession, which can be used to authenticate using + * the specified method. + * + * Returns: a new #SignonAuthSession. + */ +SignonAuthSession * +signon_auth_session_new (GObject *parent, + const gchar *method_name, + GError **err) +{ + if (!SIGNON_IS_IDENTITY(parent)) + { + g_set_error (err, + signon_error_quark(), + SIGNON_ERROR_UNKNOWN, + "Parent object is wrong type"); + return NULL; + } + SignonIdentity *identity = SIGNON_IDENTITY(parent); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + SignonAuthSession *self = SIGNON_AUTH_SESSION(g_object_new ( + SIGNON_TYPE_AUTH_SESSION, + "identity", identity, + NULL)); + g_return_val_if_fail (self != NULL, NULL); + + if (!auth_session_priv_init(self, method_name, err)) + { + if (*err) + g_warning ("%s returned error: %s", G_STRFUNC, (*err)->message); + + g_object_unref (self); + return NULL; + } + + return self; +} + +/** + * signon_auth_session_get_method: + * @self: the #SignonAuthSession. + * + * Get the current authentication method. + * + * Returns: the authentication method being used, or %NULL on failure. + */ +const gchar * +signon_auth_session_get_method (SignonAuthSession *self) +{ + g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), NULL); + SignonAuthSessionPrivate *priv = self->priv; + + g_return_val_if_fail (priv != NULL, NULL); + + return priv->method_name; +} + +/** + * SignonAuthSessionQueryAvailableMechanismsCb: + * @self: the #SignonAuthSession. + * @mechanisms: (transfer full) (type GStrv): list of available mechanisms. + * @error: a #GError if an error occurred, %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_auth_session_query_available_mechanisms(). + */ + +/** + * signon_auth_session_query_available_mechanisms: + * @self: the #SignonAuthSession. + * @wanted_mechanisms: a %NULL-terminated list of mechanisms supported by the client. + * @cb: (scope async): a callback which will be called with the result. + * @user_data: user data to be passed to the callback. + * + * Queries the mechanisms available for this authentication session. the result + * will be the intersection between @wanted_mechanisms and the mechanisms + * supported by the authentication plugin. + */ +void +signon_auth_session_query_available_mechanisms (SignonAuthSession *self, + const gchar **wanted_mechanisms, + SignonAuthSessionQueryAvailableMechanismsCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); + SignonAuthSessionPrivate* priv = self->priv; + + g_return_if_fail (priv != NULL); + + AuthSessionQueryAvailableMechanismsCbData *cb_data = g_slice_new0 (AuthSessionQueryAvailableMechanismsCbData); + cb_data->self = self; + cb_data->cb = cb; + cb_data->user_data = user_data; + + AuthSessionQueryAvailableMechanismsData *operation_data = g_slice_new0 (AuthSessionQueryAvailableMechanismsData); + operation_data->wanted_mechanisms = g_strdupv ((gchar **)wanted_mechanisms); + operation_data->cb_data = cb_data; + + auth_session_check_remote_object(self); + _signon_object_call_when_ready (self, + auth_session_object_quark(), + auth_session_query_available_mechanisms_ready_cb, + operation_data); +} + +/** + * SignonAuthSessionProcessCb: + * @self: the #SignonAuthSession. + * @session_data: (transfer full) (element-type utf8 GValue): a dictionary with + * the response. + * @error: a #GError if an error occurred, %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * This callback is invoked when the authentication plugin delivers the result + * of the signon_auth_session_process() operation. + */ + +/** + * signon_auth_session_process: + * @self: the #SignonAuthSession. + * @session_data: (transfer none) (element-type utf8 GValue): a dictionary of parameters. + * @mechanism: the authentication mechanism to be used. + * @cb: (scope async): a callback which will be called with the result. + * @user_data: user data to be passed to the callback. + * + * Performs one step of the authentication process. If the #SignonAuthSession + * object is bound to an existing identity, the identity properties such as + * username and password will be also passed to the authentication plugin, so + * there's no need to fill them into @session_data. + * @session_data can be used to add additional authentication parameters to the + * session, or to override the parameters otherwise taken from the identity. + * + * Deprecated: 1.8: Use signon_auth_session_process_async() instead. + */ +void +signon_auth_session_process (SignonAuthSession *self, + const GHashTable *session_data, + const gchar* mechanism, + SignonAuthSessionProcessCb cb, + gpointer user_data) +{ + GVariant *v_session_data; + + g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + AuthSessionProcessCbData *cb_data = g_slice_new0 (AuthSessionProcessCbData); + cb_data->cb = cb; + cb_data->user_data = user_data; + + v_session_data = signon_hash_table_to_variant (session_data); + + signon_auth_session_process_async (self, v_session_data, mechanism, NULL, + process_async_cb_wrapper, cb_data); +} + +/** + * signon_auth_session_process_async: + * @self: the #SignonAuthSession. + * @session_data: (transfer floating): a dictionary of parameters. + * @mechanism: the authentication mechanism to be used. + * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore. + * @callback: (scope async): a callback which will be called when the + * authentication reply is available. + * @user_data: user data to be passed to the callback. + * + * Performs one step of the authentication process. If the #SignonAuthSession + * object is bound to an existing identity, the identity properties such as + * username and password will be also passed to the authentication plugin, so + * there's no need to fill them into @session_data. + * @session_data can be used to add additional authentication parameters to the + * session, or to override the parameters otherwise taken from the identity. + * + * Since: 1.8 + */ +void +signon_auth_session_process_async (SignonAuthSession *self, + GVariant *session_data, + const gchar *mechanism, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + SignonAuthSessionPrivate *priv; + AuthSessionProcessData *process_data; + GSimpleAsyncResult *res; + + g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); + priv = self->priv; + + g_return_if_fail (session_data != NULL); + + res = g_simple_async_result_new ((GObject *)self, callback, user_data, + signon_auth_session_process_async); + g_simple_async_result_set_check_cancellable (res, cancellable); + + process_data = g_slice_new0 (AuthSessionProcessData); + process_data->session_data = g_variant_ref_sink (session_data); + process_data->mechanism = g_strdup (mechanism); + process_data->cancellable = cancellable; + g_object_set_data_full ((GObject *)res, data_key_process, process_data, + (GDestroyNotify)auth_session_process_data_free); + + priv->busy = TRUE; + + auth_session_check_remote_object(self); + _signon_object_call_when_ready (self, + auth_session_object_quark(), + auth_session_process_ready_cb, + res); +} + +/** + * signon_auth_session_process_finish: + * @self: the #SignonAuthSession. + * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to + * signon_auth_session_process_async(). + * @error: return location for error, or %NULL. + * + * Collect the result of the signon_auth_session_process_async() operation. + * + * Returns: a #GVariant of type %G_VARIANT_TYPE_VARDICT containing the + * authentication reply. + * + * Since: 1.8 + */ +GVariant * +signon_auth_session_process_finish (SignonAuthSession *self, GAsyncResult *res, + GError **error) +{ + GSimpleAsyncResult *async_result; + GVariant *reply; + + g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), NULL); + + async_result = (GSimpleAsyncResult *)res; + if (g_simple_async_result_propagate_error (async_result, error)) + return NULL; + + reply = g_simple_async_result_get_op_res_gpointer (async_result); + return g_variant_ref (reply); +} + +/** + * signon_auth_session_cancel: + * @self: the #SignonAuthSession. + * + * Cancel the authentication session. + */ +void +signon_auth_session_cancel (SignonAuthSession *self) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); + SignonAuthSessionPrivate *priv = self->priv; + + g_return_if_fail (priv != NULL); + + auth_session_check_remote_object(self); + + if (!priv->busy) + return; + + priv->canceled = TRUE; + _signon_object_call_when_ready (self, + auth_session_object_quark(), + auth_session_cancel_ready_cb, + NULL); +} + +static void +auth_session_state_changed_cb (GDBusProxy *proxy, + gint state, + gchar *message, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (user_data)); + SignonAuthSession *self = SIGNON_AUTH_SESSION (user_data); + + g_signal_emit ((GObject *)self, + auth_session_signals[STATE_CHANGED], + 0, + state, + message); +} + +static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (user_data)); + SignonAuthSession *self = SIGNON_AUTH_SESSION (user_data); + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + DEBUG ("remote object unregistered"); + + if (priv->proxy) + { + g_object_unref (priv->proxy); + priv->proxy = NULL; + } + + /* + * as remote object is destroyed only + * when the session core is destroyed, + * so there should not be any processes + * running + * */ + priv->busy = FALSE; + priv->canceled = FALSE; + _signon_object_not_ready(self); +} + +static gboolean +auth_session_priv_init (SignonAuthSession *self, + const gchar *method_name, GError **err) +{ + g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), FALSE); + SignonAuthSessionPrivate *priv = SIGNON_AUTH_SESSION_PRIV (self); + g_return_val_if_fail (priv, FALSE); + + priv->method_name = g_strdup (method_name); + + priv->registering = FALSE; + priv->busy = FALSE; + priv->canceled = FALSE; + return TRUE; +} + +static void +auth_session_query_mechanisms_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SsoAuthSession *proxy = SSO_AUTH_SESSION (object); + gchar **mechanisms = NULL; + GError *error = NULL; + AuthSessionQueryAvailableMechanismsCbData *cb_data = + (AuthSessionQueryAvailableMechanismsCbData *)userdata; + g_return_if_fail (cb_data != NULL); + + sso_auth_session_call_query_available_mechanisms_finish (proxy, + &mechanisms, + res, + &error); + if (SIGNON_IS_NOT_CANCELLED (error)) + { + (cb_data->cb) (cb_data->self, mechanisms, error, cb_data->user_data); + } + + g_clear_error (&error); + g_slice_free (AuthSessionQueryAvailableMechanismsCbData, cb_data); +} + +static void +auth_session_query_available_mechanisms_ready_cb (gpointer object, const GError *error, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + AuthSessionQueryAvailableMechanismsData *operation_data = + (AuthSessionQueryAvailableMechanismsData *)user_data; + g_return_if_fail (operation_data != NULL); + + AuthSessionQueryAvailableMechanismsCbData *cb_data = operation_data->cb_data; + g_return_if_fail (cb_data != NULL); + + if (error) + { + (cb_data->cb) + (self, NULL, error, cb_data->user_data); + + g_slice_free (AuthSessionQueryAvailableMechanismsCbData, cb_data); + } + else + { + g_return_if_fail (priv->proxy != NULL); + sso_auth_session_call_query_available_mechanisms ( + priv->proxy, + (const char **)operation_data->wanted_mechanisms, + priv->cancellable, + auth_session_query_mechanisms_reply, + cb_data); + + g_signal_emit (self, + auth_session_signals[STATE_CHANGED], + 0, + SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, + auth_session_process_pending_message); + } + + g_strfreev (operation_data->wanted_mechanisms); + g_slice_free (AuthSessionQueryAvailableMechanismsData, operation_data); +} + +static void +auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); + g_return_if_fail (user_data == NULL); + + SignonAuthSession *self = SIGNON_AUTH_SESSION (object); + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + if (error) + { + //TODO: in general this function does not return any values, + // that is why I think it should not emit anything for this particular case + DEBUG("error during initialization"); + } + else if (priv->proxy && priv->busy) + sso_auth_session_call_cancel_sync (priv->proxy, + priv->cancellable, + NULL); + + priv->busy = FALSE; + priv->canceled = FALSE; +} + +static void +signon_auth_session_complete (SignonAuthSession *self, + GError *error, + GDBusConnection *connection, + const gchar *bus_name, + const gchar *object_path) +{ + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + priv->registering = FALSE; + if (!g_strcmp0(object_path, "") || error) + { + if (error) + DEBUG ("Error message is %s", error->message); + else + error = g_error_new (signon_error_quark(), + SIGNON_ERROR_RUNTIME, + "Cannot create remote AuthSession object"); + } + else + { + GError *proxy_error = NULL; + + priv->proxy = + sso_auth_session_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + bus_name, + object_path, + priv->cancellable, + &proxy_error); + if (G_UNLIKELY (proxy_error != NULL)) + { + g_warning ("Failed to initialize AuthSession proxy: %s", + proxy_error->message); + g_clear_error (&proxy_error); + } + + g_dbus_proxy_set_default_timeout ((GDBusProxy *)priv->proxy, + G_MAXINT); + + priv->signal_state_changed = + g_signal_connect (priv->proxy, + "state-changed", + G_CALLBACK (auth_session_state_changed_cb), + self); + + priv->signal_unregistered = + g_signal_connect (priv->proxy, + "unregistered", + G_CALLBACK (auth_session_remote_object_destroyed_cb), + self); + } + + DEBUG ("Object path received: %s", object_path); + _signon_object_ready (self, auth_session_object_quark (), error); +} + +static void +auth_session_check_remote_object(SignonAuthSession *self) +{ + g_return_if_fail (self != NULL); + SignonAuthSessionPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + if (priv->proxy != NULL) + return; + + g_return_if_fail (priv->identity != NULL); + + if (!priv->registering) + { + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + priv->registering = TRUE; + signon_identity_get_auth_session (priv->identity, + self, + priv->method_name, + signon_auth_session_complete); + + } +} + diff --git a/libgsignon-glib/signon-auth-session.h b/libgsignon-glib/signon-auth-session.h new file mode 100644 index 0000000..d56a253 --- /dev/null +++ b/libgsignon-glib/signon-auth-session.h @@ -0,0 +1,194 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef SIGNONAUTHSESSION_H_ +#define SIGNONAUTHSESSION_H_ + +#include +#include +#include + +G_BEGIN_DECLS + +/* + * Useful session data keys + */ +/** + * SIGNON_SESSION_DATA_USERNAME: + * + * Username. + */ +#define SIGNON_SESSION_DATA_USERNAME "UserName" +/** + * SIGNON_SESSION_DATA_SECRET: + * + * Secret. + */ +#define SIGNON_SESSION_DATA_SECRET "Secret" +/** + * SIGNON_SESSION_DATA_REALM: + * + * Realm. + */ +#define SIGNON_SESSION_DATA_REALM "Realm" +/** + * SIGNON_SESSION_DATA_PROXY: + * + * Proxy. + */ +#define SIGNON_SESSION_DATA_PROXY "NetworkProxy" + +/** + * SignonSessionDataUiPolicy: + * @SIGNON_POLICY_DEFAULT: The plugin can decide when to show UI. + * @SIGNON_POLICY_REQUEST_PASSWORD: Force the user to enter the password. + * @SIGNON_POLICY_NO_USER_INTERACTION: No UI elements will be shown to the user. + * @SIGNON_POLICY_VALIDATION: UI elements can be shown to the user only when + * CAPTCHA-like security measures are required. + * + * Policy for the signon process, passed to the UI plugin. + */ +typedef enum { + SIGNON_POLICY_DEFAULT = 0, + SIGNON_POLICY_REQUEST_PASSWORD, + SIGNON_POLICY_NO_USER_INTERACTION, + SIGNON_POLICY_VALIDATION, +} SignonSessionDataUiPolicy; +/** + * SIGNON_SESSION_DATA_UI_POLICY: + * @see_also: #SignonSessionDataUiPolicy + * + * Policy for the signon process. + */ +#define SIGNON_SESSION_DATA_UI_POLICY "UiPolicy" +/** + * SIGNON_SESSION_DATA_CAPTION: + * + * Caption for the UI dialog. + */ +#define SIGNON_SESSION_DATA_CAPTION "Caption" +/** + * SIGNON_SESSION_DATA_TIMEOUT: + * + * Network timeout, in milliseconds (uint32). + */ +#define SIGNON_SESSION_DATA_TIMEOUT "NetworkTimeout" +/** + * SIGNON_SESSION_DATA_WINDOW_ID: + * + * Platform-specific window id (for dialog transiency) - uint32. + */ +#define SIGNON_SESSION_DATA_WINDOW_ID "WindowId" +/** + * SIGNON_SESSION_DATA_RENEW_TOKEN: + * + * Requests the signon plugin to obtain a new token (boolean). + */ +#define SIGNON_SESSION_DATA_RENEW_TOKEN "RenewToken" + + +#define SIGNON_TYPE_AUTH_SESSION (signon_auth_session_get_type ()) +#define SIGNON_AUTH_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSession)) +#define SIGNON_AUTH_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionClass)) +#define SIGNON_IS_AUTH_SESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIGNON_TYPE_AUTH_SESSION)) +#define SIGNON_IS_AUTH_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_AUTH_SESSION)) +#define SIGNON_AUTH_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionClass)) + +typedef struct _SignonAuthSession SignonAuthSession; +typedef struct _SignonAuthSessionPrivate SignonAuthSessionPrivate; +typedef struct _SignonAuthSessionClass SignonAuthSessionClass; + +/** + * SignonAuthSession: + * + * Opaque struct. Use the accessor functions below. + */ +struct _SignonAuthSession { + GObject parent; + + SignonAuthSessionPrivate *priv; +}; + +/** + * SignonAuthSessionClass: + * + * Opaque struct. Use the accessor functions below. + */ +struct _SignonAuthSessionClass { + GObjectClass parent; +}; + +GType signon_auth_session_get_type (void) G_GNUC_CONST; + +SignonAuthSession *signon_auth_session_new(GObject *parent, + const gchar *method_name, + GError **err); + +const gchar *signon_auth_session_get_method (SignonAuthSession *self); + +typedef void (*SignonAuthSessionQueryAvailableMechanismsCb) ( + SignonAuthSession* self, + gchar **mechanisms, + const GError *error, + gpointer user_data); + +G_GNUC_DEPRECATED +typedef SignonAuthSessionQueryAvailableMechanismsCb + SignonAuthSessionQueryAvailableMethodsCb; + +void signon_auth_session_query_available_mechanisms(SignonAuthSession *self, + const gchar **wanted_mechanisms, + SignonAuthSessionQueryAvailableMechanismsCb cb, + gpointer user_data); + +#ifndef SIGNON_DISABLE_DEPRECATED +typedef void (*SignonAuthSessionProcessCb) (SignonAuthSession *self, + GHashTable *session_data, + const GError *error, + gpointer user_data); +SIGNON_DEPRECATED_FOR(signon_auth_session_process_async) +void signon_auth_session_process(SignonAuthSession *self, + const GHashTable *session_data, + const gchar *mechanism, + SignonAuthSessionProcessCb cb, + gpointer user_data); +#endif +void signon_auth_session_process_async (SignonAuthSession *self, + GVariant *session_data, + const gchar *mechanism, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GVariant *signon_auth_session_process_finish (SignonAuthSession *self, + GAsyncResult *res, + GError **error); + +void signon_auth_session_cancel(SignonAuthSession *self); + +G_END_DECLS + +#endif //SIGNONAUTHSESSIONIMPL_H_ diff --git a/libgsignon-glib/signon-dbus-queue.c b/libgsignon-glib/signon-dbus-queue.c new file mode 100644 index 0000000..aa0fb19 --- /dev/null +++ b/libgsignon-glib/signon-dbus-queue.c @@ -0,0 +1,169 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "signon-dbus-queue.h" + +typedef struct { + SignonReadyCb callback; + gpointer user_data; +} SignonReadyCbData; + +typedef struct { + gpointer self; + GSList *callbacks; +} SignonReadyData; + +static GQuark +_signon_object_ready_quark() +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string ("signon_object_ready_quark"); + + return quark; +} + +static GQuark +_signon_object_error_quark() +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string ("signon_object_error_quark"); + + return quark; +} + +static void +signon_object_invoke_ready_callbacks (SignonReadyData *rd, const GError *error) +{ + GSList *list; + + for (list = rd->callbacks; list != NULL; list = list->next) + { + SignonReadyCbData *cb = list->data; + + cb->callback (rd->self, error, cb->user_data); + g_slice_free (SignonReadyCbData, cb); + } + g_slist_free (rd->callbacks); +} + +static void +signon_ready_data_free (SignonReadyData *rd) +{ + if (rd->self) + { + //TODO: Signon error codes need be presented instead of 555 and 666 + GError error = { 555, 666, "Object disposed" }; + signon_object_invoke_ready_callbacks (rd, &error); + } + g_slice_free (SignonReadyData, rd); +} + +void +_signon_object_call_when_ready (gpointer object, GQuark quark, SignonReadyCb callback, + gpointer user_data) +{ + SignonReadyData *rd; + SignonReadyCbData *cb; + + g_return_if_fail (G_IS_OBJECT (object)); + g_return_if_fail (quark != 0); + g_return_if_fail (callback != NULL); + + if (GPOINTER_TO_INT (g_object_get_qdata((GObject *)object, + _signon_object_ready_quark())) == TRUE) + { + //TODO: specify the last error in object initialization + GError * err = g_object_get_qdata((GObject *)object, + _signon_object_error_quark()); + return (*callback)(object, err, user_data); + } + + cb = g_slice_new (SignonReadyCbData); + cb->callback = callback; + cb->user_data = user_data; + + rd = g_object_get_qdata ((GObject *)object, quark); + if (!rd) + { + rd = g_slice_new (SignonReadyData); + rd->self = object; + rd->callbacks = NULL; + g_object_set_qdata_full ((GObject *)object, quark, rd, + (GDestroyNotify)signon_ready_data_free); + } + + rd->callbacks = g_slist_append (rd->callbacks, cb); +} + +void +_signon_object_ready (gpointer object, GQuark quark, const GError *error) +{ + SignonReadyData *rd; + + g_object_set_qdata((GObject *)object, _signon_object_ready_quark(), GINT_TO_POINTER(TRUE)); + + if(error) + g_object_set_qdata_full ((GObject *)object, _signon_object_error_quark(), + g_error_copy(error), + (GDestroyNotify)g_error_free); + + /* steal the qdata so the callbacks won't be invoked again, even if the + * object becomes ready or is finalized while still invoking them */ + + rd = g_object_steal_qdata ((GObject *)object, quark); + if (!rd) return; + + g_object_ref (object); + + signon_object_invoke_ready_callbacks (rd, error); + rd->self = NULL; /* so the callbacks won't be invoked again */ + signon_ready_data_free (rd); + + g_object_unref (object); + + //TODO: set some sort of ready information +} + +void +_signon_object_not_ready (gpointer object) +{ + g_object_set_qdata ((GObject *)object, + _signon_object_ready_quark(), + GINT_TO_POINTER(FALSE)); + + g_object_set_qdata ((GObject *)object, + _signon_object_error_quark(), + NULL); +} + +const GError * +_signon_object_last_error (gpointer object) +{ + return g_object_get_qdata((GObject *)object, + _signon_object_error_quark()); +} diff --git a/libgsignon-glib/signon-dbus-queue.h b/libgsignon-glib/signon-dbus-queue.h new file mode 100644 index 0000000..6308a7c --- /dev/null +++ b/libgsignon-glib/signon-dbus-queue.h @@ -0,0 +1,45 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef SIGNONDBUSQUEUEDDATA_H +#define SIGNONDBUSQUEUEDDATA_H + +#include +#include + +G_BEGIN_DECLS + +typedef void (*SignonReadyCb) (gpointer object, const GError *error, + gpointer user_data); + +void _signon_object_call_when_ready (gpointer object, GQuark quark, + SignonReadyCb callback, gpointer user_data); + +void _signon_object_ready (gpointer object, GQuark quark, const GError *error); +void _signon_object_not_ready (gpointer object); + +const GError *_signon_object_last_error (gpointer object); + +G_END_DECLS +#endif /* SIGNONDBUSQUEUEDDATA_H */ diff --git a/libgsignon-glib/signon-errors.c b/libgsignon-glib/signon-errors.c new file mode 100644 index 0000000..1ffb301 --- /dev/null +++ b/libgsignon-glib/signon-errors.c @@ -0,0 +1,53 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * Copyright (C) 2012 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "signon-errors.h" +#include "signon-enum-types.h" +#include "signon-internals.h" +#include + +/** + * SECTION:signon-errors + * @title: SignonError + * @short_description: Possible errors from Signon. + * + * An enumeration of errors that are possible from Signon. + */ +#define SIGNON_ERROR_PREFIX SIGNOND_SERVICE_PREFIX ".Error" + +#include "signon-errors-map.c" + +GQuark signon_error_quark (void) +{ + static volatile gsize quark = 0; + + g_dbus_error_register_error_domain ("gsignond", + &quark, + signon_error_entries, + G_N_ELEMENTS (signon_error_entries)); + return (GQuark) quark; +} diff --git a/libgsignon-glib/signon-errors.h b/libgsignon-glib/signon-errors.h new file mode 100644 index 0000000..4683e51 --- /dev/null +++ b/libgsignon-glib/signon-errors.h @@ -0,0 +1,129 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef __LIBSIGNON_ERRORS_H__ +#define __LIBSIGNON_ERRORS_H__ + +#include +#include +#include "signon-enum-types.h" + +#define SIGNON_ERROR (signon_error_quark()) + +/** + * SignonError: + * @SIGNON_ERROR_UNKNOWN: Catch-all for errors not distinguished by another code. + * @SIGNON_ERROR_INTERNAL_SERVER: Signon daemon internal error. + * @SIGNON_ERROR_INTERNAL_COMMUNICATION: Error communicating with Sigon daemon. + * @SIGNON_ERROR_PERMISSION_DENIED: The operation cannot be performed due to + * insufficient client permissions. + * @SIGNON_ERROR_METHOD_NOT_KNOWN: The method with this name was not found. + * @SIGNON_ERROR_SERVICE_NOT_AVAILABLE: The service is temporarily unavailable. + * @SIGNON_ERROR_INVALID_QUERY: Parameters for the query are invalid. + * @SIGNON_ERROR_METHOD_NOT_AVAILABLE: The requested method is not available. + * @SIGNON_ERROR_IDENTITY_NOT_FOUND: The identity mathching the #SignonIdentity + * was not found on the service. + * @SIGNON_ERROR_STORE_FAILED: Storing credentials failed. + * @SIGNON_ERROR_REMOVE_FAILED: Removing credentials failed. + * @SIGNON_ERROR_SIGNOUT_FAILED: Signing out failed. + * @SIGNON_ERROR_IDENTITY_OPERATION_CANCELED: Identity operation was canceled + * by the user. + * @SIGNON_ERROR_CREDENTIALS_NOT_AVAILABLE: Query failed. + * @SIGNON_ERROR_REFERENCE_NOT_FOUND: Trying to remove non-existent reference. + * @SIGNON_ERROR_MECHANISM_NOT_AVAILABLE: The requested mechanism in not + * available. + * @SIGNON_ERROR_MISSING_DATA: The #SessionData does not contain the necessary + * information. + * @SIGNON_ERROR_INVALID_CREDENTIALS: The supplied credentials are invalid for + * the mechanism implementation. + * @SIGNON_ERROR_NOT_AUTHORIZED: Authorization failed. + * @SIGNON_ERROR_WRONG_STATE: An operation method has been called in an + * incorrect state. + * @SIGNON_ERROR_OPERATION_NOT_SUPPORTED: The operation is not supported by the + * mechanism implementation. + * @SIGNON_ERROR_NO_CONNECTION: No network connection. + * @SIGNON_ERROR_NETWORK: Network connection failed. + * @SIGNON_ERROR_SSL: SSL connection failed. + * @SIGNON_ERROR_RUNTIME: Casting #SessionData into subclass failed. + * @SIGNON_ERROR_SESSION_CANCELED: Challenge was canceled. + * @SIGNON_ERROR_TIMED_OUT: Challenge timed out. + * @SIGNON_ERROR_USER_INTERACTION: User interaction dialog failed. + * @SIGNON_ERROR_OPERATION_FAILED: Temporary failure in authentication. + * @SIGNON_ERROR_ENCRYPTION_FAILED: @deprecated: Failure during data + * encryption/decryption. + * @SIGNON_ERROR_TOS_NOT_ACCEPTED: User declined Terms of Service. + * @SIGNON_ERROR_FORGOT_PASSWORD: User requested password reset sequence. + * @SIGNON_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED: Method or mechanism not + * allowed for this identity. + * @SIGNON_ERROR_INCORRECT_DATE: Date/time incorrect on device. + * @SIGNON_ERROR_USER_ERROR: Placeholder to rearrange enumeration - userspace + * specific. + * + * Possible Signon errors. + */ +typedef enum { + SIGNON_ERROR_UNKNOWN = 1, + SIGNON_ERROR_INTERNAL_SERVER = 2, + SIGNON_ERROR_INTERNAL_COMMUNICATION = 3, + SIGNON_ERROR_PERMISSION_DENIED = 4, + + SIGNON_ERROR_METHOD_NOT_KNOWN = 101, + SIGNON_ERROR_SERVICE_NOT_AVAILABLE, + SIGNON_ERROR_INVALID_QUERY, + + SIGNON_ERROR_METHOD_NOT_AVAILABLE = 201, + SIGNON_ERROR_IDENTITY_NOT_FOUND, + SIGNON_ERROR_STORE_FAILED, + SIGNON_ERROR_REMOVE_FAILED, + SIGNON_ERROR_SIGNOUT_FAILED, + SIGNON_ERROR_IDENTITY_OPERATION_CANCELED, + SIGNON_ERROR_CREDENTIALS_NOT_AVAILABLE, + SIGNON_ERROR_REFERENCE_NOT_FOUND, + + SIGNON_ERROR_MECHANISM_NOT_AVAILABLE = 301, + SIGNON_ERROR_MISSING_DATA, + SIGNON_ERROR_INVALID_CREDENTIALS, + SIGNON_ERROR_NOT_AUTHORIZED, + SIGNON_ERROR_WRONG_STATE, + SIGNON_ERROR_OPERATION_NOT_SUPPORTED, + SIGNON_ERROR_NO_CONNECTION, + SIGNON_ERROR_NETWORK, + SIGNON_ERROR_SSL, + SIGNON_ERROR_RUNTIME, + SIGNON_ERROR_SESSION_CANCELED, + SIGNON_ERROR_TIMED_OUT, + SIGNON_ERROR_USER_INTERACTION, + SIGNON_ERROR_OPERATION_FAILED, + SIGNON_ERROR_ENCRYPTION_FAILED, + SIGNON_ERROR_TOS_NOT_ACCEPTED, + SIGNON_ERROR_FORGOT_PASSWORD, + SIGNON_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED, + SIGNON_ERROR_INCORRECT_DATE, + SIGNON_ERROR_USER_ERROR = 400 +} SignonError; + +GQuark signon_error_quark (void); + + +#endif diff --git a/libgsignon-glib/signon-glib.h b/libgsignon-glib/signon-glib.h new file mode 100644 index 0000000..971cdfa --- /dev/null +++ b/libgsignon-glib/signon-glib.h @@ -0,0 +1,35 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2011 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef SIGNON_GLIB_H +#define SIGNON_GLIB_H + +#include +#include +#include +#include +#include +#include + +#endif /* SIGNON_GLIB_H */ diff --git a/libgsignon-glib/signon-identity-info.c b/libgsignon-glib/signon-identity-info.c new file mode 100644 index 0000000..666fdc5 --- /dev/null +++ b/libgsignon-glib/signon-identity-info.c @@ -0,0 +1,680 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2011-2012 Canonical Ltd. + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +/** + * SECTION:signon-identity-info + * @title: SignonIdentityInfo + * @short_description: Extra data for a #SignonIdentity. + * + * Extra data retreived from a #SignonIdentity. + */ + +#include "signon-identity-info.h" + +#include "signon-internals.h" +#include "signon-utils.h" + +G_DEFINE_BOXED_TYPE (SignonIdentityInfo, signon_identity_info, + (GBoxedCopyFunc)signon_identity_info_copy, + (GBoxedFreeFunc)signon_identity_info_free); + + +static GVariant * +signon_variant_new_string (const gchar *string) +{ + return g_variant_new_string (string != NULL ? string : ""); +} + +static const gchar *identity_info_get_secret (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + + return info->secret; +} + +static void identity_info_set_id (SignonIdentityInfo *info, gint id) +{ + g_return_if_fail (info != NULL); + g_return_if_fail (id >= 0); + + info->id = id; +} + +static void identity_methods_copy (gpointer key, gpointer value, gpointer user_data) +{ + signon_identity_info_set_method ((SignonIdentityInfo *)user_data, + (const gchar *)key, + (const gchar* const *)value); +} + +/** + * signon_identity_info_set_methods: + * @info: the #SignonIdentityInfo. + * @methods: (transfer none) (element-type utf8 GStrv): methods. + * + * Set allowed methods. + * Mechanisms are method-specific functions. + */ +void signon_identity_info_set_methods (SignonIdentityInfo *info, + const GHashTable *methods) +{ + g_return_if_fail (info != NULL); + g_return_if_fail (methods != NULL); + + DEBUG("%s", G_STRFUNC); + + if (info->methods) + g_hash_table_remove_all (info->methods); + else + info->methods = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify)g_strfreev); + + g_hash_table_foreach ((GHashTable *)methods, identity_methods_copy, info); +} + +SignonIdentityInfo * +signon_identity_info_new_from_variant (GVariant *variant) +{ + GVariant *method_map; + GVariant *owner; + GVariant *acl; + + if (!variant) + return NULL; + + SignonIdentityInfo *info = signon_identity_info_new (); + + DEBUG("%s: ", G_STRFUNC); + + g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_ID, + "u", + &info->id); + + g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_USERNAME, + "s", + &info->username); + + if (g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_SECRET, + "s", + &info->secret)) + { + g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_STORESECRET, + "b", + &info->store_secret); + } + + g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_CAPTION, + "s", + &info->caption); + + g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_REALMS, + "^as", + &info->realms); + + /* get the methods */ + if (g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_AUTHMETHODS, + "@a{sas}", + &method_map)) + { + GVariantIter iter; + gchar *method; + gchar **mechanisms; + + g_variant_iter_init (&iter, method_map); + while (g_variant_iter_next (&iter, "{s^as}", &method, &mechanisms)) + { + g_hash_table_insert (info->methods, method, mechanisms); + } + g_variant_unref (method_map); + } + + if (g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_OWNER, + "@(ss)", + &owner)) + { + info->owner = signon_security_context_deconstruct_variant (owner); + g_variant_unref (owner); + } + + if (g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_ACL, + "@a(ss)", + &acl)) + { + info->access_control_list = + signon_security_context_list_deconstruct_variant (acl); + g_variant_unref (acl); + } + + g_variant_lookup (variant, + SIGNOND_IDENTITY_INFO_TYPE, + "u", + &info->type); + + return info; +} + +GVariant * +signon_identity_info_to_variant (const SignonIdentityInfo *self) +{ + GVariantBuilder builder; + GVariantBuilder method_builder; + GVariant *method_map; + GHashTableIter iter; + const gchar *method; + const gchar **mechanisms; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_ID, + g_variant_new_uint32 (self->id)); + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_USERNAME, + signon_variant_new_string (self->username)); + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_SECRET, + signon_variant_new_string (self->secret)); + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_CAPTION, + signon_variant_new_string (self->caption)); + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_STORESECRET, + g_variant_new_boolean (self->store_secret)); + + g_variant_builder_init (&method_builder, + (const GVariantType *)"a{sas}"); + g_hash_table_iter_init (&iter, self->methods); + while (g_hash_table_iter_next (&iter, + (gpointer)&method, + (gpointer)&mechanisms)) + { + g_variant_builder_add (&method_builder, "{s^as}", + method, + mechanisms); + } + method_map = g_variant_builder_end (&method_builder); + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_AUTHMETHODS, + method_map); + + if (self->realms != NULL) + { + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_REALMS, + g_variant_new_strv ((const gchar * const *) + self->realms, + -1)); + } + + if (self->owner != NULL) + { + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_OWNER, + signon_security_context_build_variant ( + self->owner)); + } + + if (self->access_control_list != NULL) + { + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_ACL, + signon_security_context_list_build_variant ( + self->access_control_list)); + } + + g_variant_builder_add (&builder, "{sv}", + SIGNOND_IDENTITY_INFO_TYPE, + g_variant_new_int32 (self->type)); + + return g_variant_builder_end (&builder); +} + +/* + * Public methods: + */ + +/** + * signon_identity_info_new: + * + * Creates a new #SignonIdentityInfo item. + * + * Returns: a new #SignonIdentityInfo item. + */ +SignonIdentityInfo *signon_identity_info_new () +{ + SignonIdentityInfo *info = g_slice_new0 (SignonIdentityInfo); + info->methods = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify)g_strfreev); + info->store_secret = FALSE; + + return info; +} + +/** + * signon_identity_info_free: + * @info: the #SignonIdentityInfo. + * + * Destroys the given #SignonIdentityInfo item. + */ +void signon_identity_info_free (SignonIdentityInfo *info) +{ + if (info == NULL) return; + + g_free (info->username); + g_free (info->secret); + g_free (info->caption); + + g_hash_table_destroy (info->methods); + + g_strfreev (info->realms); + signon_security_context_free (info->owner); + signon_security_context_list_free (info->access_control_list); + + g_slice_free (SignonIdentityInfo, info); +} + +/** + * signon_identity_info_copy: + * @other: the #SignonIdentityInfo. + * + * Get a newly-allocated copy of @info. + * + * Returns: a copy of the given #SignonIdentityInfo, or %NULL on failure. + */ +SignonIdentityInfo *signon_identity_info_copy (const SignonIdentityInfo *other) +{ + g_return_val_if_fail (other != NULL, NULL); + SignonIdentityInfo *info = signon_identity_info_new (); + + identity_info_set_id (info, signon_identity_info_get_id (other)); + + signon_identity_info_set_username (info, + signon_identity_info_get_username (other)); + + signon_identity_info_set_secret (info, identity_info_get_secret(other), + signon_identity_info_get_storing_secret (other)); + + signon_identity_info_set_caption (info, + signon_identity_info_get_caption(other)); + + signon_identity_info_set_methods (info, + signon_identity_info_get_methods (other)); + + signon_identity_info_set_realms (info, + signon_identity_info_get_realms (other)); + + signon_identity_info_set_owner (info, + signon_identity_info_get_owner (other)); + + signon_identity_info_set_access_control_list (info, + signon_identity_info_get_access_control_list (other)); + + signon_identity_info_set_identity_type (info, + signon_identity_info_get_identity_type (other)); + + return info; +} + +/** + * signon_identity_info_get_id: + * @info: the #SignonIdentityInfo. + * + * Get the numeric ID of @info. + * + * Returns: the numeric ID of the identity. + */ +gint signon_identity_info_get_id (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, -1); + return info->id; +} + +/** + * signon_identity_info_get_username: + * @info: the #SignonIdentityInfo. + * + * Get the username of @info. + * + * Returns: the username, or %NULL. + */ +const gchar *signon_identity_info_get_username (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + return info->username; +} + +/** + * signon_identity_info_get_storing_secret: + * @info: the #SignonIdentityInfo. + * + * Get whether the secret of @info should be stored. + * + * Returns: %TRUE if Signon must store the secret, %FALSE otherwise. + */ +gboolean signon_identity_info_get_storing_secret (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, FALSE); + return info->store_secret; +} + +/** + * signon_identity_info_get_caption: + * @info: the #SignonIdentityInfo. + * + * Get the display name of @info. + * + * Returns: the display name for the identity. + */ +const gchar *signon_identity_info_get_caption (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + return info->caption; +} + +/** + * signon_identity_info_get_methods: + * @info: the #SignonIdentityInfo. + * + * Get a hash table of the methods and mechanisms of @info. + * + * Returns: (transfer none) (element-type utf8 GStrv): the table of allowed + * methods and mechanisms. + */ +const GHashTable *signon_identity_info_get_methods (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + return info->methods; +} + +/** + * signon_identity_info_get_realms: + * @info: the #SignonIdentityInfo. + * + * Get an array of the realms of @info. + * + * Returns: (transfer none): a %NULL terminated array of realms. + */ +const gchar* const *signon_identity_info_get_realms (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + return (const gchar* const *)info->realms; +} + +/** + * signon_identity_info_get_owner: + * @info: the #SignonIdentityInfo. + * + * Get owner security context of @info. + * + * Returns: (transfer none): a security context. + */ +const SignonSecurityContext *signon_identity_info_get_owner (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + return info->owner; +} + +/** + * signon_identity_info_get_access_control_list: + * @info: the #SignonIdentityInfo. + * + * Get an array of ACL statements of the identity. + * + * Returns: (transfer none): a list of ACL security contexts. + */ +const SignonSecurityContextList *signon_identity_info_get_access_control_list (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, NULL); + return info->access_control_list; +} + +/** + * signon_identity_info_get_identity_type: + * @info: the #SignonIdentityInfo. + * + * Get the type of the identity. + * + * Returns: the type of the identity. + */ +SignonIdentityType signon_identity_info_get_identity_type (const SignonIdentityInfo *info) +{ + g_return_val_if_fail (info != NULL, -1); + return (SignonIdentityType)info->type; +} + +/** + * signon_identity_info_set_username: + * @info: the #SignonIdentityInfo. + * @username: the username. + * + * Sets the username for the identity. + */ +void signon_identity_info_set_username (SignonIdentityInfo *info, const gchar *username) +{ + g_return_if_fail (info != NULL); + + if (info->username) g_free (info->username); + + info->username = g_strdup (username); +} + +/** + * signon_identity_info_set_secret: + * @info: the #SignonIdentityInfo. + * @secret: the secret. + * @store_secret: whether signond should store the secret in its DB. + * + * Sets the secret (password) for the identity, and whether the signon daemon + * should remember it. + */ +void signon_identity_info_set_secret (SignonIdentityInfo *info, const gchar *secret, + gboolean store_secret) +{ + g_return_if_fail (info != NULL); + + if (info->secret) g_free (info->secret); + + info->secret = g_strdup (secret); + info->store_secret = store_secret; +} + +/** + * signon_identity_info_set_caption: + * @info: the #SignonIdentityInfo. + * @caption: the caption. + * + * Sets the caption (display name) for the identity. + */ +void signon_identity_info_set_caption (SignonIdentityInfo *info, const gchar *caption) +{ + g_return_if_fail (info != NULL); + + if (info->caption) g_free (info->caption); + + info->caption = g_strdup (caption); +} + +/** + * signon_identity_info_set_method: + * @info: the #SignonIdentityInfo. + * @method: an authentication method. + * @mechanisms: a %NULL-termianted list of mechanisms. + * + * Adds a method to the list of allowed methods. + * Mechanisms are method-specific functions. + */ +void signon_identity_info_set_method (SignonIdentityInfo *info, const gchar *method, + const gchar* const *mechanisms) +{ + g_return_if_fail (info != NULL); + + g_return_if_fail (info->methods != NULL); + g_return_if_fail (method != NULL); + g_return_if_fail (mechanisms != NULL); + + g_hash_table_replace (info->methods, + g_strdup(method), g_strdupv((gchar **)mechanisms)); +} + +/** + * signon_identity_info_remove_method: + * @info: the #SignonIdentityInfo. + * @method: an authentication method. + * + * Remove @method from the list of allowed authentication methods. If all + * methods are removed, then all methods are allowed. + */ +void signon_identity_info_remove_method (SignonIdentityInfo *info, const gchar *method) +{ + g_return_if_fail (info != NULL); + g_return_if_fail (info->methods != NULL); + + g_hash_table_remove (info->methods, method); +} + +/** + * signon_identity_info_set_realms: + * @info: the #SignonIdentityInfo. + * @realms: a %NULL-terminated list of realms. + * + * Specify what realms this identity can be used in. + */ +void signon_identity_info_set_realms (SignonIdentityInfo *info, + const gchar* const *realms) +{ + g_return_if_fail (info != NULL); + + if (info->realms) g_strfreev (info->realms); + + info->realms = g_strdupv ((gchar **)realms); +} + +/** + * signon_identity_info_set_owner: + * @info: the #SignonIdentityInfo. + * @owner: (transfer none) a security context of owner. + * + * Specify owner security context. + */ +void signon_identity_info_set_owner (SignonIdentityInfo *info, + const SignonSecurityContext *owner) +{ + g_return_if_fail (info != NULL); + + if (info->owner) signon_security_context_free (info->owner); + + info->owner = signon_security_context_copy (owner); +} + +/** + * signon_identity_info_set_owner_from_values: + * @info: the #SignonIdentityInfo. + * @system_context: owner's system context. + * @application_context: owner's application context. + * + * Specify owner security context. + */ +void signon_identity_info_set_owner_from_values ( + SignonIdentityInfo *info, + const gchar *system_context, + const gchar *application_context) +{ + g_return_if_fail (info != NULL && + system_context != NULL && + application_context != NULL); + + if (info->owner) signon_security_context_free (info->owner); + + info->owner = signon_security_context_new_from_values(system_context, + application_context); +} + +/** + * signon_identity_info_set_access_control_list: + * @info: the #SignonIdentityInfo. + * @access_control_list: (transfer none) a list of ACL security contexts. + * + * Specifies the ACL for this identity. The actual meaning of the ACL depends + * on the security framework used by signond. Ownership of the list is trans + */ +void signon_identity_info_set_access_control_list (SignonIdentityInfo *info, + const SignonSecurityContextList *access_control_list) +{ + g_return_if_fail (info != NULL); + + if (info->access_control_list) + signon_security_context_list_free (info->access_control_list); + + info->access_control_list = + signon_security_context_list_copy (access_control_list); +} + +/** + * signon_identity_info_access_control_list_append: + * @info: the #SignonIdentityInfo. + * @security_context: (transfer full) a security context to be appended. + * + * Appends a new #SignonSecurityContext item to the access control list. + */ +void signon_identity_info_access_control_list_append ( + SignonIdentityInfo *info, + SignonSecurityContext *security_context) +{ + g_return_if_fail (info != NULL); + g_return_if_fail (security_context != NULL); + + info->access_control_list = g_list_append (info->access_control_list, + security_context); +} + +/** + * signon_identity_info_set_identity_type: + * @info: the #SignonIdentityInfo. + * @type: the type of the identity. + * + * Specifies the type of this identity. + */ +void signon_identity_info_set_identity_type (SignonIdentityInfo *info, + SignonIdentityType type) +{ + g_return_if_fail (info != NULL); + info->type = (gint)type; +} diff --git a/libgsignon-glib/signon-identity-info.h b/libgsignon-glib/signon-identity-info.h new file mode 100644 index 0000000..fe139b3 --- /dev/null +++ b/libgsignon-glib/signon-identity-info.h @@ -0,0 +1,112 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2011 Canonical Ltd. + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _SIGNON_IDENTITY_INFO_H_ +#define _SIGNON_IDENTITY_INFO_H_ + +#include + +#include "signon-security-context.h" + +G_BEGIN_DECLS + +/** + * SignonIdentityInfo: + * + * Opaque struct. Use the accessor functions below. + */ +typedef struct _SignonIdentityInfo SignonIdentityInfo; + +/** + * SignonIdentityType: + * @SIGNON_IDENTITY_TYPE_OTHER: an identity that is not an app, web or network + * @SIGNON_IDENTITY_TYPE_APP: an application identity + * @SIGNON_IDENTITY_TYPE_WEB: a web identity + * @SIGNON_IDENTITY_TYPE_NETWORK: a network server identity + * + * Types used in #SignonIdentityInfo. + */ +typedef enum { + SIGNON_IDENTITY_TYPE_OTHER = 0, + SIGNON_IDENTITY_TYPE_APP = 1 << 0, + SIGNON_IDENTITY_TYPE_WEB = 1 << 1, + SIGNON_IDENTITY_TYPE_NETWORK = 1 << 2 +} SignonIdentityType; + +GType signon_identity_info_get_type (void) G_GNUC_CONST; + +SignonIdentityInfo *signon_identity_info_new (); +void signon_identity_info_free (SignonIdentityInfo *info); + +SignonIdentityInfo *signon_identity_info_copy (const SignonIdentityInfo *other); + +gint signon_identity_info_get_id (const SignonIdentityInfo *info); +const gchar *signon_identity_info_get_username (const SignonIdentityInfo *info); +gboolean signon_identity_info_get_storing_secret ( + const SignonIdentityInfo *info); +const gchar *signon_identity_info_get_caption (const SignonIdentityInfo *info); +const GHashTable *signon_identity_info_get_methods ( + const SignonIdentityInfo *info); +const gchar* const *signon_identity_info_get_realms ( + const SignonIdentityInfo *info); +const SignonSecurityContext *signon_identity_info_get_owner ( + const SignonIdentityInfo *info); +const SignonSecurityContextList *signon_identity_info_get_access_control_list ( + const SignonIdentityInfo *info); +SignonIdentityType signon_identity_info_get_identity_type ( + const SignonIdentityInfo *info); + +void signon_identity_info_set_username (SignonIdentityInfo *info, const gchar *username); +void signon_identity_info_set_secret (SignonIdentityInfo *info, + const gchar *secret, + gboolean store_secret); +void signon_identity_info_set_caption (SignonIdentityInfo *info, + const gchar *caption); +void signon_identity_info_set_methods (SignonIdentityInfo *info, + const GHashTable *methods); +void signon_identity_info_set_method (SignonIdentityInfo *info, + const gchar *method, + const gchar* const *mechanisms); +void signon_identity_info_remove_method (SignonIdentityInfo *info, + const gchar *method); +void signon_identity_info_set_realms (SignonIdentityInfo *info, + const gchar* const *realms); +void signon_identity_info_set_owner (SignonIdentityInfo *info, + const SignonSecurityContext *owner); +void signon_identity_info_set_owner_from_values (SignonIdentityInfo *info, + const gchar *system_context, + const gchar *application_context); +void signon_identity_info_set_access_control_list (SignonIdentityInfo *info, + const SignonSecurityContextList *access_control_list); +void signon_identity_info_access_control_list_append (SignonIdentityInfo *info, + SignonSecurityContext *security_context); +void signon_identity_info_set_identity_type (SignonIdentityInfo *info, + SignonIdentityType type); + +G_END_DECLS + +#endif /* _SIGNON_IDENTITY_INFO_H_ */ diff --git a/libgsignon-glib/signon-identity.c b/libgsignon-glib/signon-identity.c new file mode 100644 index 0000000..ade93c2 --- /dev/null +++ b/libgsignon-glib/signon-identity.c @@ -0,0 +1,1644 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +/** + * SECTION:signon-identity + * @title: SignonIdentity + * @short_description: Client side presentation of a credential. + * + * The #SignonIdentity represents a database entry for a single identity. + */ + +#include "signon-identity.h" +#include "signon-auth-session.h" +#include "signon-internals.h" +#include "signon-dbus-queue.h" +#include "signon-utils.h" +#include "signon-errors.h" +#include "sso-auth-service.h" +#include "sso-identity-gen.h" + +G_DEFINE_TYPE (SignonIdentity, signon_identity, G_TYPE_OBJECT); + +enum +{ + PROP_0, + PROP_ID, + PROP_APPCTX +}; + +typedef enum { + NOT_REGISTERED, + PENDING_REGISTRATION, + REGISTERED, +} IdentityRegistrationState; + +typedef enum { + DATA_UPDATED = 0, + IDENTITY_REMOVED, + IDENTITY_SIGNED_OUT +} RemoteIdentityState; + +struct _SignonIdentityPrivate +{ + SsoIdentity *proxy; + SsoAuthService *auth_service_proxy; + GCancellable *cancellable; + + SignonIdentityInfo *identity_info; + + GSList *sessions; + IdentityRegistrationState registration_state; + + gboolean removed; + gboolean signed_out; + gboolean updated; + + guint id; + gchar *app_ctx; + + guint signal_info_updated; + guint signal_unregistered; +}; + +enum { + SIGNEDOUT_SIGNAL, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +#define SIGNON_IDENTITY_PRIV(obj) (SIGNON_IDENTITY(obj)->priv) + +typedef struct _IdentityStoreCredentialsCbData +{ + SignonIdentity *self; + SignonIdentityStoreCredentialsCb cb; + gpointer user_data; +} IdentityStoreCredentialsCbData; + +typedef struct _IdentityStoreCredentialsData +{ + GVariant *info_variant; + gpointer cb_data; +} IdentityStoreCredentialsData; + +typedef enum { + SIGNON_VERIFY_USER, + SIGNON_VERIFY_SECRET, + SIGNON_INFO, + SIGNON_REMOVE, + SIGNON_SIGNOUT +} IdentityOperation; + +typedef struct _IdentitySessionCbData +{ + SignonIdentity *self; + SignonAuthSession *session; + SignonIdentitySessionReadyCb cb; +} IdentitySessionCbData; + +typedef struct _IdentitySessionData +{ + const gchar *method; + gpointer cb_data; +} IdentitySessionData; + +typedef struct _IdentityVerifyCbData +{ + SignonIdentity *self; + SignonIdentityVerifyCb cb; + gpointer user_data; +} IdentityVerifyCbData; + +typedef struct _IdentityVerifyData +{ + gchar *data_to_send; + GHashTable *params; + IdentityOperation operation; + gpointer cb_data; +} IdentityVerifyData; + +typedef struct _IdentityInfoCbData +{ + SignonIdentity *self; + SignonIdentityInfoCb cb; + gpointer user_data; +} IdentityInfoCbData; + +typedef struct _IdentityVoidCbData +{ + SignonIdentity *self; + SignonIdentityVoidCb cb; + gpointer user_data; +} IdentityVoidCbData; + +typedef struct _IdentityVoidData +{ + IdentityOperation operation; + gpointer cb_data; +} IdentityVoidData; + +static void identity_check_remote_registration (SignonIdentity *self); +static void identity_store_credentials_ready_cb (gpointer object, const GError *error, gpointer user_data); +static void identity_store_credentials_reply (GObject *object, + GAsyncResult *res, + gpointer userdata); +static void identity_verify_data (SignonIdentity *self, const gchar *data_to_send, gint operation, + SignonIdentityVerifyCb cb, gpointer user_data); +static void identity_verify_ready_cb (gpointer object, const GError *error, gpointer user_data); + +static void identity_remove_ready_cb (gpointer object, const GError *error, gpointer user_data); +static void identity_signout_ready_cb (gpointer object, const GError *error, gpointer user_data); +static void identity_info_ready_cb (gpointer object, const GError *error, gpointer user_data); + +static void identity_process_signout (SignonIdentity *self); +static void identity_process_updated (SignonIdentity *self); +static void identity_process_removed (SignonIdentity *self); +static void identity_get_auth_session_reply (GObject *object, + GAsyncResult *res, + gpointer userdata); +static void identity_session_ready_cb (gpointer object, const GError *error, + gpointer user_data); +static void identity_session_object_destroyed_cb (gpointer data, + GObject *where_the_session_was); + +static GQuark +identity_object_quark () +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string ("identity_object_quark"); + + return quark; +} + +static void +signon_identity_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + SignonIdentity *self = SIGNON_IDENTITY (object); + + switch (property_id) + { + case PROP_ID: + self->priv->id = g_value_get_uint (value); + break; + case PROP_APPCTX: + g_free (self->priv->app_ctx); + self->priv->app_ctx = g_strdup (g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +signon_identity_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + SignonIdentity *self = SIGNON_IDENTITY (object); + + switch (property_id) + { + case PROP_ID: + g_value_set_uint (value, self->priv->id); + break; + case PROP_APPCTX: + g_value_set_string (value, self->priv->app_ctx); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +signon_identity_init (SignonIdentity *identity) +{ + SignonIdentityPrivate *priv; + + identity->priv = G_TYPE_INSTANCE_GET_PRIVATE (identity, + SIGNON_TYPE_IDENTITY, + SignonIdentityPrivate); + + priv = identity->priv; + priv->proxy = NULL; + priv->auth_service_proxy = sso_auth_service_get_instance(); + priv->cancellable = g_cancellable_new (); + priv->registration_state = NOT_REGISTERED; + + priv->removed = FALSE; + priv->signed_out = FALSE; + priv->updated = FALSE; + + priv->app_ctx = NULL; +} + +static void +signon_identity_dispose (GObject *object) +{ + SignonIdentity *identity = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = identity->priv; + + if (priv->cancellable) + { + g_cancellable_cancel (priv->cancellable); + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + } + + if (priv->identity_info) + { + signon_identity_info_free (priv->identity_info); + priv->identity_info = NULL; + } + + g_clear_object (&priv->auth_service_proxy); + + if (priv->proxy) + { + g_signal_handler_disconnect (priv->proxy, priv->signal_info_updated); + g_signal_handler_disconnect (priv->proxy, priv->signal_unregistered); + g_object_unref (priv->proxy); + priv->proxy = NULL; + } + + if (priv->sessions) + g_critical ("SignonIdentity: the list of AuthSessions MUST be empty"); + + G_OBJECT_CLASS (signon_identity_parent_class)->dispose (object); +} + +static void +signon_identity_finalize (GObject *object) +{ + SignonIdentity *identity = SIGNON_IDENTITY (object); + if (identity->priv->app_ctx) + { + g_free(identity->priv->app_ctx); + identity->priv->app_ctx = NULL; + } + + G_OBJECT_CLASS (signon_identity_parent_class)->finalize (object); +} + +static void +signon_identity_class_init (SignonIdentityClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + object_class->set_property = signon_identity_set_property; + object_class->get_property = signon_identity_get_property; + + pspec = g_param_spec_uint ("id", + "Identity ID", + "Set/Get Identity ID", + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE); + g_object_class_install_property (object_class, + PROP_ID, + pspec); + + pspec = g_param_spec_string ("app_ctx", + "Application Context", + "Set/Get Application Security Context", + "", + G_PARAM_READWRITE); + g_object_class_install_property (object_class, + PROP_APPCTX, + pspec); + + g_type_class_add_private (object_class, sizeof (SignonIdentityPrivate)); + + /** + * SignonIdentity::signout: + * + * Emitted when the identity was signed out. + */ + signals[SIGNEDOUT_SIGNAL] = g_signal_new("signout", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, + 0 /* class closure */, + NULL /* accumulator */, + NULL /* accu_data */, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE /* return_type */, + 0); + + object_class->dispose = signon_identity_dispose; + object_class->finalize = signon_identity_finalize; +} + +static void +identity_state_changed_cb (GDBusProxy *proxy, + gint state, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (user_data)); + SignonIdentity *self = SIGNON_IDENTITY (user_data); + + switch (state) { + case DATA_UPDATED: + DEBUG ("State changed to DATA_UPDATED"); + identity_process_updated (self); + break; + case IDENTITY_REMOVED: + DEBUG ("State changed to IDENTITY_REMOVED"); + identity_process_removed (self); + break; + case IDENTITY_SIGNED_OUT: + DEBUG ("State changed to IDENTITY_SIGNED_OUT"); + identity_process_signout (self); + break; + default: + g_critical ("wrong state value obtained from signon daemon"); + }; +} + +static void +identity_remote_object_destroyed_cb(GDBusProxy *proxy, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (user_data)); + SignonIdentity *self = SIGNON_IDENTITY (user_data); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + if (priv->proxy) + { + g_object_unref (priv->proxy); + priv->proxy = NULL; + } + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + _signon_object_not_ready(self); + + priv->registration_state = NOT_REGISTERED; + + signon_identity_info_free (priv->identity_info); + priv->identity_info = NULL; + + priv->removed = FALSE; + priv->signed_out = FALSE; + priv->updated = FALSE; +} + +static void +identity_registered (SignonIdentity *identity, + char *object_path, GVariant *identity_data, + GError *error) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (identity)); + + SignonIdentityPrivate *priv; + priv = identity->priv; + + g_return_if_fail (priv != NULL); + + if (!error) + { + GDBusConnection *connection; + GDBusProxy *auth_service_proxy; + const gchar *bus_name; + GError *proxy_error = NULL; + + DEBUG("%s: %s", G_STRFUNC, object_path); + /* + * TODO: as Aurel will finalize the code polishing so we will + * need to implement the refresh of the proxy to SignonIdentity + * */ + g_return_if_fail (priv->proxy == NULL); + + auth_service_proxy = (GDBusProxy *)priv->auth_service_proxy; + connection = g_dbus_proxy_get_connection (auth_service_proxy); + bus_name = g_dbus_proxy_get_name (auth_service_proxy); + + priv->proxy = + sso_identity_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + bus_name, + object_path, + priv->cancellable, + &proxy_error); + if (G_UNLIKELY (proxy_error != NULL)) + { + g_warning ("Failed to initialize Identity proxy: %s", + proxy_error->message); + g_clear_error (&proxy_error); + } + + priv->signal_info_updated = + g_signal_connect (priv->proxy, + "info-updated", + G_CALLBACK (identity_state_changed_cb), + identity); + + priv->signal_unregistered = + g_signal_connect (priv->proxy, + "unregistered", + G_CALLBACK (identity_remote_object_destroyed_cb), + identity); + + if (identity_data) + { + DEBUG("%s: ", G_STRFUNC); + priv->identity_info = + signon_identity_info_new_from_variant (identity_data); + g_variant_unref (identity_data); + } + + priv->updated = TRUE; + } + else + g_warning ("%s: %s", G_STRFUNC, error->message); + + /* + * execute queued operations or emit errors on each of them + * */ + priv->registration_state = REGISTERED; + + /* + * TODO: if we will add a new state for identity: "INVALID" + * consider emission of another error, like "invalid" + * */ + _signon_object_ready (identity, identity_object_quark (), error); + + /* + * as the registration failed we do not + * request for new registration, but emit + * same error again and again + * */ +} + +/** + * signon_identity_get_last_error: + * @identity: the #SignonIdentity. + * + * Get the most recent error that occurred on @identity. + * + * Returns: a #GError containing the most recent error, or %NULL on failure. + */ +const GError * +signon_identity_get_last_error (SignonIdentity *identity) +{ + g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL); + return _signon_object_last_error(identity); +} + +static void +identity_new_cb (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SignonIdentity *identity = (SignonIdentity*)userdata; + SsoAuthService *proxy = SSO_AUTH_SERVICE (object); + gchar *object_path = NULL; + GError *error = NULL; + + g_return_if_fail (identity != NULL); + DEBUG ("%s", G_STRFUNC); + + sso_auth_service_call_register_new_identity_finish (proxy, + &object_path, + res, + &error); + if (SIGNON_IS_NOT_CANCELLED (error)) + { + identity_registered (identity, object_path, NULL, error); + } + if (object_path) g_free (object_path); + g_clear_error (&error); +} + +static void +identity_new_from_db_cb (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SignonIdentity *identity = (SignonIdentity*)userdata; + SsoAuthService *proxy = SSO_AUTH_SERVICE (object); + gchar *object_path = NULL; + GVariant *identity_data; + GError *error = NULL; + + g_return_if_fail (identity != NULL); + DEBUG ("%s", G_STRFUNC); + + sso_auth_service_call_get_identity_finish (proxy, + &object_path, + &identity_data, + res, + &error); + if (SIGNON_IS_NOT_CANCELLED (error)) + { + identity_registered (identity, object_path, identity_data, error); + } + if (object_path) g_free (object_path); + g_clear_error (&error); +} + +static void +identity_check_remote_registration (SignonIdentity *self) +{ + g_return_if_fail (self != NULL); + SignonIdentityPrivate *priv = self->priv; + + g_return_if_fail (priv != NULL); + + if (priv->registration_state != NOT_REGISTERED) + return; + + if (priv->id != 0) + sso_auth_service_call_get_identity (priv->auth_service_proxy, + priv->id, + priv->app_ctx, + priv->cancellable, + identity_new_from_db_cb, + self); + else + sso_auth_service_call_register_new_identity (priv->auth_service_proxy, + priv->app_ctx, + priv->cancellable, + identity_new_cb, + self); + + priv->registration_state = PENDING_REGISTRATION; +} + +/** + * signon_identity_new_from_db: + * @id: identity ID. + * @application_context: application security context, can be %NULL. + * + * Construct an identity object associated with an existing identity + * record. + * + * Returns: an instance of a #SignonIdentity. + */ +SignonIdentity* +signon_identity_new_from_db (guint32 id, const gchar *application_context) +{ + SignonIdentity *identity; + DEBUG ("%s %d: %d\n", G_STRFUNC, __LINE__, id); + if (id == 0) + return NULL; + + identity = g_object_new (SIGNON_TYPE_IDENTITY, + "id", id, + "app_ctx", application_context, + NULL); + g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL); + g_return_val_if_fail (identity->priv != NULL, NULL); + + identity->priv->id = id; + identity->priv->app_ctx = (application_context) ? + g_strdup (application_context) : g_strdup (""); + identity_check_remote_registration (identity); + + return identity; +} + +/** + * signon_identity_new: + * @application_context: application security context, can be %NULL. + * + * Construct new, empty, identity object. + * + * Returns: an instance of an #SignonIdentity. + */ +SignonIdentity* +signon_identity_new (const gchar *application_context) +{ + DEBUG ("%s %d", G_STRFUNC, __LINE__); + SignonIdentity *identity = g_object_new ( + SIGNON_TYPE_IDENTITY, + "app_ctx", application_context, + NULL); + g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL); + g_return_val_if_fail (identity->priv != NULL, NULL); + + identity->priv->app_ctx = (application_context) ? + g_strdup (application_context) : g_strdup (""); + identity_check_remote_registration (identity); + + return identity; +} + +/** + * signon_identity_create_session: + * @self: the #SignonIdentity. + * @method: method. + * @error: pointer to a location which will receive the error, if any. + * + * Creates an authentication session for this identity. + * + * Returns: (transfer full): a new #SignonAuthSession. + */ +SignonAuthSession * +signon_identity_create_session(SignonIdentity *self, + const gchar *method, + GError **error) +{ + g_return_val_if_fail (SIGNON_IS_IDENTITY (self), NULL); + + SignonIdentityPrivate *priv = self->priv; + g_return_val_if_fail (priv != NULL, NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + if (method == NULL) + { + DEBUG ("NULL method as input. Aborting."); + g_set_error(error, + signon_error_quark(), + SIGNON_ERROR_UNKNOWN, + "NULL input method."); + return NULL; + } + + GSList *list = priv->sessions; + while (list) + { + SignonAuthSession *session = SIGNON_AUTH_SESSION (priv->sessions->data); + const gchar *sessionMethod = signon_auth_session_get_method (session); + if (g_strcmp0(sessionMethod, method) == 0) + { + DEBUG ("Auth Session with method `%s` already created.", method); + g_set_error (error, + signon_error_quark(), + SIGNON_ERROR_METHOD_NOT_AVAILABLE, + "Authentication session for this method already requested."); + return NULL; + } + + list = list->next; + } + + SignonAuthSession *session = signon_auth_session_new (G_OBJECT(self), + method, + error); + if (session) + { + DEBUG ("%s %d - success", G_STRFUNC, __LINE__); + priv->sessions = g_slist_append(priv->sessions, session); + g_object_weak_ref (G_OBJECT(session), + identity_session_object_destroyed_cb, + self); + /* + * if you want to delete the identity + * you MUST delete all authsessions + * first + * */ + g_object_ref (self); + priv->signed_out = FALSE; + } + + return session; +} + +/** + * signon_identity_store_credentials_with_info: + * @self: the #SignonIdentity. + * @info: the #SignonIdentityInfo data to store. + * @cb: (scope async): callback. + * @user_data: user_data. + * + * Stores the data from @info into the identity. + */ +void +signon_identity_store_credentials_with_info(SignonIdentity *self, + const SignonIdentityInfo *info, + SignonIdentityStoreCredentialsCb cb, + gpointer user_data) +{ + IdentityStoreCredentialsCbData *cb_data; + IdentityStoreCredentialsData *operation_data; + + DEBUG (); + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + g_return_if_fail (info != NULL); + + SignonIdentityPrivate *priv = self->priv; + if (priv->identity_info) + signon_identity_info_free (priv->identity_info); + priv->identity_info = signon_identity_info_copy (info); + + cb_data = g_slice_new0 (IdentityStoreCredentialsCbData); + cb_data->self = self; + cb_data->cb = cb; + cb_data->user_data = user_data; + + operation_data = g_slice_new0 (IdentityStoreCredentialsData); + operation_data->info_variant = signon_identity_info_to_variant (info); + operation_data->cb_data = cb_data; + + identity_check_remote_registration (self); + _signon_object_call_when_ready (self, + identity_object_quark(), + identity_store_credentials_ready_cb, + operation_data); +} + +/** + * signon_identity_store_credentials_with_args: + * @self: the #SignonIdentity. + * @username: username. + * @secret: secret. + * @store_secret: whether signond should store the password. + * @methods: (transfer none) (element-type utf8 GStrv): methods. + * @caption: caption. + * @realms: realms. + * @access_control_list: access control list. + * @type: the type of the identity. + * @cb: (scope async): callback. + * @user_data: user_data. + * + * Stores the given data into the identity. + */ +void signon_identity_store_credentials_with_args(SignonIdentity *self, + const gchar *username, + const gchar *secret, + const gboolean store_secret, + const GHashTable *methods, + const gchar *caption, + const gchar* const *realms, + const SignonSecurityContext *owner, + const SignonSecurityContextList *access_control_list, + SignonIdentityType type, + SignonIdentityStoreCredentialsCb cb, + gpointer user_data) +{ + SignonIdentityInfo *info; + + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + info = signon_identity_info_new (); + signon_identity_info_set_username (info, username); + signon_identity_info_set_secret (info, secret, store_secret); + signon_identity_info_set_methods (info, methods); + signon_identity_info_set_caption (info, caption); + signon_identity_info_set_realms (info, realms); + if (owner) + { + signon_identity_info_set_owner (info, owner); + } + if (access_control_list) + { + signon_identity_info_set_access_control_list (info, + access_control_list); + } + signon_identity_info_set_identity_type (info, type); + + signon_identity_store_credentials_with_info (self, info, cb, user_data); + signon_identity_info_free (info); +} + +static void +identity_store_credentials_ready_cb (gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (object)); + + SignonIdentity *self = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + IdentityStoreCredentialsData *operation_data = + (IdentityStoreCredentialsData *)user_data; + g_return_if_fail (operation_data != NULL); + + IdentityStoreCredentialsCbData *cb_data = operation_data->cb_data; + g_return_if_fail (cb_data != NULL); + + if (error) + { + DEBUG ("IdentityError: %s", error->message); + + if (cb_data->cb) + { + (cb_data->cb) (self, 0, error, cb_data->user_data); + } + + g_slice_free (IdentityStoreCredentialsCbData, cb_data); + } + else + { + g_return_if_fail (priv->proxy != NULL); + + sso_identity_call_store (priv->proxy, + operation_data->info_variant, + priv->cancellable, + identity_store_credentials_reply, + cb_data); + } + + g_slice_free (IdentityStoreCredentialsData, operation_data); +} + +static void +identity_store_credentials_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + IdentityStoreCredentialsCbData *cb_data = (IdentityStoreCredentialsCbData *)userdata; + SsoIdentity *proxy = SSO_IDENTITY (object); + guint id; + GError *error = NULL; + + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->self != NULL); + g_return_if_fail (cb_data->self->priv != NULL); + + SignonIdentityPrivate *priv = cb_data->self->priv; + + sso_identity_call_store_finish (proxy, &id, res, &error); + + if (error == NULL) + { + g_return_if_fail (priv->identity_info == NULL); + + g_object_set (cb_data->self, "id", id, NULL); + cb_data->self->priv->id = id; + + /* + * if the previous state was REMOVED + * then we need to reset it + * */ + priv->removed = FALSE; + } + + if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) + { + (cb_data->cb) (cb_data->self, id, error, cb_data->user_data); + } + + g_clear_error(&error); + g_slice_free (IdentityStoreCredentialsCbData, cb_data); +} + +static void +identity_verify_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SsoIdentity *proxy = SSO_IDENTITY (object); + gboolean valid; + GError *error = NULL; + IdentityVerifyCbData *cb_data = (IdentityVerifyCbData *)userdata; + + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->self != NULL); + + sso_identity_call_verify_secret_finish (proxy, &valid, res, &error); + + if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) + { + (cb_data->cb) (cb_data->self, valid, error, cb_data->user_data); + } + + g_clear_error(&error); + g_slice_free (IdentityVerifyCbData, cb_data); +} + +static void +identity_verify_ready_cb (gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (object)); + + SignonIdentity *self = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + IdentityVerifyData *operation_data = + (IdentityVerifyData *)user_data; + g_return_if_fail (operation_data != NULL); + + IdentityVerifyCbData *cb_data = operation_data->cb_data; + g_return_if_fail (cb_data != NULL); + + if (priv->removed == TRUE) + { + GError *new_error = g_error_new (signon_error_quark(), + SIGNON_ERROR_IDENTITY_NOT_FOUND, + "Already removed from database."); + + if (cb_data->cb) + { + (cb_data->cb) (self, FALSE, new_error, cb_data->user_data); + } + + g_error_free (new_error); + g_slice_free (IdentityVerifyCbData, cb_data); + } + else if (error) + { + DEBUG ("IdentityError: %s", error->message); + + if (cb_data->cb) + { + (cb_data->cb) (self, FALSE, error, cb_data->user_data); + } + + g_slice_free (IdentityVerifyCbData, cb_data); + } + else + { + DEBUG ("%s %d", G_STRFUNC, __LINE__); + g_return_if_fail (priv->proxy != NULL); + + switch (operation_data->operation) { + case SIGNON_VERIFY_SECRET: + sso_identity_call_verify_secret (priv->proxy, + operation_data->data_to_send, + priv->cancellable, + identity_verify_reply, + cb_data); + break; + default: g_critical ("Wrong operation code"); + }; + } + g_free (operation_data->params); + g_free (operation_data->data_to_send); + g_slice_free (IdentityVerifyData, operation_data); +} + +static void +identity_verify_data(SignonIdentity *self, + const gchar *data_to_send, + gint operation, + SignonIdentityVerifyCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + IdentityVerifyCbData *cb_data = g_slice_new0 (IdentityVerifyCbData); + cb_data->self = self; + cb_data->cb = cb; + cb_data->user_data = user_data; + + IdentityVerifyData *operation_data = g_slice_new0 (IdentityVerifyData); + + operation_data->params = NULL; + operation_data->data_to_send = g_strdup (data_to_send); + operation_data->operation = operation; + operation_data->cb_data = cb_data; + + identity_check_remote_registration (self); + _signon_object_call_when_ready (self, + identity_object_quark(), + identity_verify_ready_cb, + operation_data); +} + +/** + * signon_identity_verify_secret: + * @self: the #SignonIdentity. + * @secret: the secret (password) to be verified. + * @cb: (scope async): callback. + * @user_data: user_data. + * + * Verifies the given secret. + */ +void signon_identity_verify_secret(SignonIdentity *self, + const gchar *secret, + SignonIdentityVerifyCb cb, + gpointer user_data) +{ + identity_verify_data (self, + secret, + SIGNON_VERIFY_SECRET, + cb, + user_data); +} + +static void +identity_process_updated (SignonIdentity *self) +{ + DEBUG ("%d %s", __LINE__, __func__); + + g_return_if_fail (self != NULL); + g_return_if_fail (self->priv != NULL); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv->proxy != NULL); + + signon_identity_info_free (priv->identity_info); + priv->identity_info = NULL; + priv->updated = FALSE; + + DEBUG ("%s info freed, to be updated", __func__); +} + +static void +identity_process_removed (SignonIdentity *self) +{ + g_return_if_fail (self != NULL); + g_return_if_fail (self->priv != NULL); + + DEBUG ("%d %s", __LINE__, __func__); + + SignonIdentityPrivate *priv = self->priv; + + if (priv->removed == TRUE) + return; + + priv->removed = TRUE; + signon_identity_info_free (priv->identity_info); + priv->identity_info = NULL; + + g_object_set (self, "id", 0, NULL); + priv->id = 0; +} + +static void +identity_process_signout(SignonIdentity *self) +{ + g_return_if_fail (self != NULL); + g_return_if_fail (self->priv != NULL); + + DEBUG ("%d %s", __LINE__, __func__); + SignonIdentityPrivate *priv = self->priv; + + if (priv->signed_out == TRUE) + return; + + GSList *llink = priv->sessions; + while (llink) + { + GSList *next = llink->next; + g_object_unref (G_OBJECT(llink->data)); + llink = next; + } + + priv->signed_out = TRUE; + g_signal_emit(G_OBJECT(self), signals[SIGNEDOUT_SIGNAL], 0); +} + +/* + * TODO: fix the implementation + * of signond: it returns result = TRUE + * in ANY CASE + * */ +static void +identity_signout_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SsoIdentity *proxy = SSO_IDENTITY (object); + gboolean result; + GError *error = NULL; + IdentityVoidCbData *cb_data = (IdentityVoidCbData *)userdata; + + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->self != NULL); + g_return_if_fail (cb_data->self->priv != NULL); + + sso_identity_call_sign_out_finish (proxy, &result, res, &error); + + if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) + { + (cb_data->cb) (cb_data->self, error, cb_data->user_data); + } + + g_clear_error(&error); + g_slice_free (IdentityVoidCbData, cb_data); +} + +static void +identity_removed_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SsoIdentity *proxy = SSO_IDENTITY (object); + GError *error = NULL; + IdentityVoidCbData *cb_data = (IdentityVoidCbData *)userdata; + + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->self != NULL); + g_return_if_fail (cb_data->self->priv != NULL); + + sso_identity_call_remove_finish (proxy, res, &error); + + if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) + { + (cb_data->cb) (cb_data->self, error, cb_data->user_data); + } + + g_clear_error(&error); + g_slice_free (IdentityVoidCbData, cb_data); +} + +static void +identity_info_reply(GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SsoIdentity *proxy = SSO_IDENTITY (object); + GVariant *identity_data = NULL; + DEBUG ("%d %s", __LINE__, __func__); + + GError *error = NULL; + IdentityInfoCbData *cb_data = (IdentityInfoCbData *)userdata; + + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->self != NULL); + g_return_if_fail (cb_data->self->priv != NULL); + + SignonIdentityPrivate *priv = cb_data->self->priv; + + sso_identity_call_get_info_finish (proxy, &identity_data, res, &error); + + if (identity_data != NULL) + { + priv->identity_info = + signon_identity_info_new_from_variant (identity_data); + g_variant_unref (identity_data); + } + + if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) + { + (cb_data->cb) (cb_data->self, priv->identity_info, error, cb_data->user_data); + } + + g_clear_error(&error); + g_slice_free (IdentityInfoCbData, cb_data); + + priv->updated = TRUE; +} + +static void +identity_info_ready_cb(gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (object)); + + SignonIdentity *self = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + IdentityVoidData *operation_data = + (IdentityVoidData *)user_data; + g_return_if_fail (operation_data != NULL); + + IdentityInfoCbData *cb_data = operation_data->cb_data; + g_return_if_fail (cb_data != NULL); + + if (priv->removed == TRUE) + { + DEBUG ("%s identity removed", G_STRFUNC); + + GError *new_error = g_error_new (signon_error_quark(), + SIGNON_ERROR_IDENTITY_NOT_FOUND, + "Already removed from database."); + if (cb_data->cb) + (cb_data->cb) (self, NULL, new_error, cb_data->user_data); + + g_error_free (new_error); + } + else if (error || priv->id == 0) + { + DEBUG ("%s identity is new", G_STRFUNC); + + if (error) + DEBUG ("IdentityError: %s", error->message); + else + DEBUG ("Identity is not stored and has no info yet"); + + if (cb_data->cb) + (cb_data->cb) (self, NULL, error, cb_data->user_data); + } + else if (priv->updated == FALSE) + { + DEBUG ("%s identity needs update, call daemon", G_STRFUNC); + + g_return_if_fail (priv->proxy != NULL); + sso_identity_call_get_info (priv->proxy, + priv->cancellable, + identity_info_reply, + cb_data); + goto free_op_data; + } + else + { + DEBUG ("%s pass existing one", G_STRFUNC); + + if (cb_data->cb) + (cb_data->cb) (self, priv->identity_info, error, cb_data->user_data); + } + + g_slice_free (IdentityInfoCbData, cb_data); + +free_op_data: + g_slice_free (IdentityVoidData, operation_data); +} + +static void +identity_signout_ready_cb(gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (object)); + + SignonIdentity *self = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + IdentityVoidCbData *cb_data = (IdentityVoidCbData *)user_data; + + g_return_if_fail (cb_data != NULL); + + if (priv->removed == TRUE) + { + GError *new_error = g_error_new (signon_error_quark(), + SIGNON_ERROR_IDENTITY_NOT_FOUND, + "Already removed from database."); + if (cb_data->cb) + { + (cb_data->cb) (self, new_error, cb_data->user_data); + } + + g_error_free (new_error); + g_slice_free (IdentityVoidCbData, cb_data); + } + else if (error) + { + DEBUG ("IdentityError: %s", error->message); + if (cb_data->cb) + { + (cb_data->cb) (self, error, cb_data->user_data); + } + + g_slice_free (IdentityVoidCbData, cb_data); + } + else + { + g_return_if_fail (priv->proxy != NULL); + sso_identity_call_sign_out (priv->proxy, + priv->cancellable, + identity_signout_reply, + cb_data); + } +} + +static void +identity_remove_ready_cb(gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (object)); + + SignonIdentity *self = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + IdentityVoidCbData *cb_data = (IdentityVoidCbData *)user_data; + g_return_if_fail (cb_data != NULL); + + if (priv->removed == TRUE) + { + GError *new_error = g_error_new (signon_error_quark(), + SIGNON_ERROR_IDENTITY_NOT_FOUND, + "Already removed from database."); + if (cb_data->cb) + { + (cb_data->cb) (self, new_error, cb_data->user_data); + } + + g_error_free (new_error); + g_slice_free (IdentityVoidCbData, cb_data); + } + else if (error) + { + DEBUG ("IdentityError: %s", error->message); + if (cb_data->cb) + { + (cb_data->cb) (self, error, cb_data->user_data); + } + + g_slice_free (IdentityVoidCbData, cb_data); + } + else + { + g_return_if_fail (priv->proxy != NULL); + sso_identity_call_remove (priv->proxy, + priv->cancellable, + identity_removed_reply, + cb_data); + } +} + +void static +identity_void_operation(SignonIdentity *self, + gint operation, + gpointer cb_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + IdentityVoidData *operation_data = g_slice_new0 (IdentityVoidData); + operation_data->cb_data = cb_data; + _signon_object_call_when_ready (self, + identity_object_quark(), + identity_info_ready_cb, + operation_data); +} + +/** + * signon_identity_remove: + * @self: the #SignonIdentity. + * @cb: (scope async): callback to be called when the operation has completed. + * @user_data: user_data to pass to the callback. + * + * Removes the corresponding credentials record from the database. + */ +void signon_identity_remove(SignonIdentity *self, + SignonIdentityRemovedCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + IdentityVoidCbData *cb_data = g_slice_new0 (IdentityVoidCbData); + cb_data->self = self; + cb_data->cb = (SignonIdentityVoidCb)cb; + cb_data->user_data = user_data; + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + identity_check_remote_registration (self); + _signon_object_call_when_ready (self, + identity_object_quark(), + identity_remove_ready_cb, + cb_data); +} + +/** + * signon_identity_signout: + * @self: the #SignonIdentity. + * @cb: (scope async): callback. + * @user_data: user_data. + * + * Asks signond to close all authentication sessions for this + * identity, and to remove any stored secrets associated with it (password and + * authentication tokens). + */ +void signon_identity_signout(SignonIdentity *self, + SignonIdentitySignedOutCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + IdentityVoidCbData *cb_data = g_slice_new0 (IdentityVoidCbData); + cb_data->self = self; + cb_data->cb = (SignonIdentityVoidCb)cb; + cb_data->user_data = user_data; + + identity_check_remote_registration (self); + _signon_object_call_when_ready (self, + identity_object_quark(), + identity_signout_ready_cb, + cb_data); +} + +/** + * signon_identity_add_reference: + * @self: the #SignonIdentity. + * @reference: reference to be added + * @cb: callback + * @user_data: user_data. + * + * Adds named reference to identity + */ +void signon_identity_add_reference(SignonIdentity *self, + const gchar *reference, + SignonIdentityReferenceAddedCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + //TODO implement + + if (cb) + (cb) (self, NULL, user_data); +} + +/** + * signon_identity_remove_reference: + * @self: the #SignonIdentity. + * @reference: reference to be removed + * @cb: callback + * @user_data: user_data. + * + * Removes named reference from identity + */ +void signon_identity_remove_reference(SignonIdentity *self, + const gchar *reference, + SignonIdentityReferenceRemovedCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + //TODO implement + + if (cb) + (cb) (self, NULL, user_data); +} + +/** + * signon_identity_query_info: + * @self: the #SignonIdentity. + * @cb: (scope async): callback. + * @user_data: user_data. + * + * Fetches the #SignonIdentityInfo data associated with this + * identity. + */ +void signon_identity_query_info(SignonIdentity *self, + SignonIdentityInfoCb cb, + gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + IdentityInfoCbData *cb_data = g_slice_new0 (IdentityInfoCbData); + cb_data->self = self; + cb_data->cb = cb; + cb_data->user_data = user_data; + + identity_check_remote_registration (self); + identity_void_operation(self, + SIGNON_INFO, + cb_data); +} + +static void +identity_get_auth_session_reply (GObject *object, GAsyncResult *res, + gpointer userdata) +{ + SsoIdentity *proxy = SSO_IDENTITY (object); + gchar *object_path = NULL; + GError *error = NULL; + + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + sso_identity_call_get_auth_session_finish (proxy, + &object_path, + res, + &error); + + IdentitySessionCbData *cb_data = (IdentitySessionCbData *) userdata; + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->cb != NULL); + + if (SIGNON_IS_NOT_CANCELLED (error)) + { + (cb_data->cb) (cb_data->session, + error, + g_dbus_proxy_get_connection ((GDBusProxy *)proxy), + g_dbus_proxy_get_name ((GDBusProxy *)proxy), + object_path); + } + g_slice_free (IdentitySessionCbData, cb_data); + if (object_path) g_free (object_path); + g_clear_error (&error); +} + +static void +identity_session_ready_cb(gpointer object, const GError *error, gpointer user_data) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (object)); + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + SignonIdentity *self = SIGNON_IDENTITY (object); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + IdentitySessionData *operation_data = (IdentitySessionData *) user_data; + g_return_if_fail (operation_data != NULL); + + IdentitySessionCbData *cb_data = operation_data->cb_data; + g_return_if_fail (cb_data != NULL); + g_return_if_fail (cb_data->cb != NULL); + + if (error) + { + (cb_data->cb) (cb_data->session, (GError *)error, NULL, NULL, NULL); + } + else if (priv->removed == TRUE) + { + GError *new_error = g_error_new (signon_error_quark(), + SIGNON_ERROR_IDENTITY_NOT_FOUND, + "Already removed from database."); + (cb_data->cb) (cb_data->session, new_error, NULL, NULL, NULL); + g_error_free (new_error); + } + else + { + g_return_if_fail (priv->proxy != NULL); + + sso_identity_call_get_auth_session ( + priv->proxy, + operation_data->method, + priv->cancellable, + identity_get_auth_session_reply, + cb_data); + } + + g_slice_free (IdentitySessionData, operation_data); +} + +static void +identity_session_object_destroyed_cb(gpointer data, + GObject *where_the_session_was) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (data)); + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + SignonIdentity *self = SIGNON_IDENTITY (data); + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + priv->sessions = g_slist_remove(priv->sessions, (gpointer)where_the_session_was); + g_object_unref (self); +} + +void signon_identity_get_auth_session (SignonIdentity *self, + SignonAuthSession *session, + const gchar *method, + SignonIdentitySessionReadyCb cb) +{ + g_return_if_fail (SIGNON_IS_IDENTITY (self)); + DEBUG ("%s %d", G_STRFUNC, __LINE__); + + SignonIdentityPrivate *priv = self->priv; + g_return_if_fail (priv != NULL); + + IdentitySessionCbData *cb_data = g_slice_new0 (IdentitySessionCbData); + cb_data->self = self; + cb_data->session = session; + cb_data->cb = cb; + + IdentitySessionData *operation_data = g_slice_new0 (IdentitySessionData); + operation_data->method = method; + operation_data->cb_data = cb_data; + + identity_check_remote_registration (self); + _signon_object_call_when_ready (self, + identity_object_quark(), + identity_session_ready_cb, + operation_data); +} + diff --git a/libgsignon-glib/signon-identity.h b/libgsignon-glib/signon-identity.h new file mode 100644 index 0000000..14c4ff1 --- /dev/null +++ b/libgsignon-glib/signon-identity.h @@ -0,0 +1,218 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _SIGNON_IDENTITY_H_ +#define _SIGNON_IDENTITY_H_ + +#include +#include +#include + +G_BEGIN_DECLS + +#define SIGNON_TYPE_IDENTITY (signon_identity_get_type ()) +#define SIGNON_IDENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIGNON_TYPE_IDENTITY, SignonIdentity)) +#define SIGNON_IDENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIGNON_TYPE_IDENTITY, SignonIdentityClass)) +#define SIGNON_IS_IDENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIGNON_TYPE_IDENTITY)) +#define SIGNON_IS_IDENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_IDENTITY)) +#define SIGNON_IDENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_IDENTITY, SignonIdentityClass)) + +typedef struct _SignonIdentityClass SignonIdentityClass; +typedef struct _SignonIdentityPrivate SignonIdentityPrivate; +typedef struct _SignonIdentity SignonIdentity; + +/** + * SignonIdentityClass: + * + * Opaque struct. Use the accessor functions below. + */ +struct _SignonIdentityClass +{ + GObjectClass parent_class; +}; + +/** + * SignonIdentity: + * + * Opaque struct. Use the accessor functions below. + */ +struct _SignonIdentity +{ + GObject parent_instance; + SignonIdentityPrivate *priv; +}; + +/** + * SignonIdentityVoidCb: + * @self: the #SignonIdentity. + * @error: a #GError if an error occurred, or %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Generic callback to be passed to several #SignonIdentity methods. + */ +typedef void (*SignonIdentityVoidCb) (SignonIdentity *self, + const GError *error, + gpointer user_data); + +/** + * SignonIdentityRemovedCb: + * + * Callback to be passed to signon_identity_remove(). + */ +typedef SignonIdentityVoidCb SignonIdentityRemovedCb; +/** + * SignonIdentitySignedOutCb: + * + * Callback to be passed to signon_identity_signout(). + */ +typedef SignonIdentityVoidCb SignonIdentitySignedOutCb; +/** + * SignonIdentityReferenceAddedCb: + * + * Callback to be passed to signon_identity_add_reference(). + */ +typedef SignonIdentityVoidCb SignonIdentityReferenceAddedCb; +/** + * SignonIdentityReferenceRemovedCb: + * + * Callback to be passed to signon_identity_remove_reference(). + */ +typedef SignonIdentityVoidCb SignonIdentityReferenceRemovedCb; + +GType signon_identity_get_type (void) G_GNUC_CONST; + +SignonIdentity *signon_identity_new_from_db (guint32 id, + const gchar *application_context); +SignonIdentity *signon_identity_new (const gchar *application_context); + +const GError *signon_identity_get_last_error (SignonIdentity *identity); + +SignonAuthSession *signon_identity_create_session(SignonIdentity *self, + const gchar *method, + GError **error); + +/** + * SignonIdentityStoreCredentialsCb: + * @self: the #SignonIdentity. + * @id: the numeric ID of the identity in the database. + * @error: a #GError if an error occurred, or %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_identity_store_credentials_with_args() or + * signon_identity_store_credentials_with_info(). + */ +typedef void (*SignonIdentityStoreCredentialsCb) (SignonIdentity *self, + guint32 id, + const GError *error, + gpointer user_data); + +void signon_identity_store_credentials_with_info(SignonIdentity *self, + const SignonIdentityInfo *info, + SignonIdentityStoreCredentialsCb cb, + gpointer user_data); + +void signon_identity_store_credentials_with_args(SignonIdentity *self, + const gchar *username, + const gchar *secret, + const gboolean store_secret, + const GHashTable *methods, + const gchar *caption, + const gchar* const *realms, + const SignonSecurityContext *owner, + const SignonSecurityContextList *access_control_list, + SignonIdentityType type, + SignonIdentityStoreCredentialsCb cb, + gpointer user_data); + +/** + * SignonIdentityVerifyCb: + * @self: the #SignonIdentity. + * @valid: whether the secret is valid. + * @error: a #GError if an error occurred, or %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_identity_verify_secret(). + */ +typedef void (*SignonIdentityVerifyCb) (SignonIdentity *self, + gboolean valid, + const GError *error, + gpointer user_data); + +void signon_identity_verify_secret(SignonIdentity *self, + const gchar *secret, + SignonIdentityVerifyCb cb, + gpointer user_data); + +/** + * SignonIdentityInfoCb: + * @self: the #SignonIdentity. + * @info: the #SignonIdentityInfo for @self. + * @error: a #GError if an error occurred, or %NULL otherwise. + * @user_data: the user data that was passed when installing this callback. + * + * Callback to be passed to signon_identity_query_info(). + */ +typedef void (*SignonIdentityInfoCb) (SignonIdentity *self, + const SignonIdentityInfo *info, + const GError *error, + gpointer user_data); + +void signon_identity_query_info(SignonIdentity *self, + SignonIdentityInfoCb cb, + gpointer user_data); + +void signon_identity_remove(SignonIdentity *self, + SignonIdentityRemovedCb cb, + gpointer user_data); + +void signon_identity_signout(SignonIdentity *self, + SignonIdentitySignedOutCb cb, + gpointer user_data); + +void signon_identity_add_reference(SignonIdentity *self, + const gchar *reference, + SignonIdentityReferenceAddedCb cb, + gpointer user_data); + +void signon_identity_remove_reference(SignonIdentity *self, + const gchar *reference, + SignonIdentityReferenceRemovedCb cb, + gpointer user_data); + +typedef void (*SignonIdentitySessionReadyCb) (SignonAuthSession *self, + GError *error, + GDBusConnection *connection, + const gchar *bus_name, + const gchar *object_path); +void signon_identity_get_auth_session(SignonIdentity *self, + SignonAuthSession *session, + const gchar *method, + SignonIdentitySessionReadyCb cb); + + +G_END_DECLS + +#endif /* _SIGNON_IDENTITY_H_ */ diff --git a/libgsignon-glib/signon-internals.h b/libgsignon-glib/signon-internals.h new file mode 100644 index 0000000..37ab066 --- /dev/null +++ b/libgsignon-glib/signon-internals.h @@ -0,0 +1,180 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * Copyright (C) 2012 Intel Corporation. + * + * Contact: Alberto Mardegan + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _SIGNONINTERNALS_H_ +#define _SIGNONINTERNALS_H_ + +#include "signon-security-context.h" + +#ifndef SIGNON_TRACE +#define SIGNON_TRACE +#endif + +#ifdef SIGNON_TRACE + #define DEBUG(format...) g_debug (G_STRLOC ": " format) +#else + #define DEBUG(...) do {} while (0) +#endif + +/* + * Common DBUS definitions + * */ +#define SIGNOND_SERVICE_PREFIX "com.google.code.AccountsSSO.gSingleSignOn" +#define SIGNOND_SERVICE SIGNOND_SERVICE_PREFIX + +#define SIGNOND_DAEMON_OBJECTPATH "/com/google/code/AccountsSSO/gSingleSignOn" +#define SIGNOND_DAEMON_INTERFACE SIGNOND_SERVICE_PREFIX ".AuthService" +#define SIGNOND_IDENTITY_INTERFACE SIGNOND_SERVICE_PREFIX ".Identity" +#define SIGNOND_AUTH_SESSION_INTERFACE SIGNOND_SERVICE_PREFIX ".AuthSession" + +#define SIGNOND_ERR_PREFIX SIGNOND_SERVICE_PREFIX ".Error." + +/* + * Common server/client identity info strings + * */ +#define SIGNOND_IDENTITY_INFO_ID "Id" +#define SIGNOND_IDENTITY_INFO_USERNAME "UserName" +#define SIGNOND_IDENTITY_INFO_SECRET "Secret" +#define SIGNOND_IDENTITY_INFO_STORESECRET "StoreSecret" +#define SIGNOND_IDENTITY_INFO_CAPTION "Caption" +#define SIGNOND_IDENTITY_INFO_REALMS "Realms" +#define SIGNOND_IDENTITY_INFO_AUTHMETHODS "AuthMethods" +#define SIGNOND_IDENTITY_INFO_OWNER "Owner" +#define SIGNOND_IDENTITY_INFO_ACL "ACL" +#define SIGNOND_IDENTITY_INFO_TYPE "Type" +#define SIGNOND_IDENTITY_INFO_REFCOUNT "RefCount" +#define SIGNOND_IDENTITY_INFO_VALIDATED "Validated" +#define SIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET "UserNameSecret" + +/* + * Common server/client sides error names and messages + * */ +#define SIGNOND_UNKNOWN_ERR_NAME SIGNOND_ERR_PREFIX "Unknown" +#define SIGNOND_INTERNAL_SERVER_ERR_NAME SIGNOND_ERR_PREFIX "InternalServer" +#define SIGNOND_INTERNAL_COMMUNICATION_ERR_NAME \ + SIGNOND_ERR_PREFIX "InternalCommunication" +#define SIGNOND_PERMISSION_DENIED_ERR_NAME \ + SIGNOND_ERR_PREFIX "PermissionDenied" +#define SIGNOND_METHOD_OR_MECHANISM_NOT_ALLOWED_ERR_NAME \ + SIGNOND_ERR_PREFIX "MethodOrMechanismNotAllowed" +#define SIGNOND_ENCRYPTION_FAILED_ERR_NAME \ + SIGNOND_ERR_PREFIX "EncryptionFailed" +#define SIGNOND_METHOD_NOT_KNOWN_ERR_NAME SIGNOND_ERR_PREFIX "MethodNotKnown" +#define SIGNOND_SERVICE_NOT_AVAILABLE_ERR_NAME \ + SIGNOND_ERR_PREFIX "ServiceNotAvailable" +#define SIGNOND_INVALID_QUERY_ERR_NAME SIGNOND_ERR_PREFIX "InvalidQuery" +#define SIGNOND_METHOD_NOT_AVAILABLE_ERR_NAME \ + SIGNOND_ERR_PREFIX "MethodNotAvailable" +#define SIGNOND_IDENTITY_NOT_FOUND_ERR_NAME \ + SIGNOND_ERR_PREFIX "IdentityNotFound" +#define SIGNOND_STORE_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "StoreFailed" +#define SIGNOND_REMOVE_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "RemoveFailed" +#define SIGNOND_SIGNOUT_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "SignOutFailed" +#define SIGNOND_IDENTITY_OPERATION_CANCELED_ERR_NAME \ + SIGNOND_ERR_PREFIX "IdentityOperationCanceled" +#define SIGNOND_CREDENTIALS_NOT_AVAILABLE_ERR_NAME \ + SIGNOND_ERR_PREFIX "CredentialsNotAvailable" +#define SIGNOND_REFERENCE_NOT_FOUND_ERR_NAME \ + SIGNOND_ERR_PREFIX "ReferenceNotFound" +#define SIGNOND_MECHANISM_NOT_AVAILABLE_ERR_NAME \ + SIGNOND_ERR_PREFIX "MechanismNotAvailable" +#define SIGNOND_MISSING_DATA_ERR_NAME SIGNOND_ERR_PREFIX "MissingData" +#define SIGNOND_INVALID_CREDENTIALS_ERR_NAME \ + SIGNOND_ERR_PREFIX "InvalidCredentials" +#define SIGNOND_NOT_AUTHORIZED_ERR_NAME SIGNOND_ERR_PREFIX "NotAuthorized" +#define SIGNOND_WRONG_STATE_ERR_NAME SIGNOND_ERR_PREFIX "WrongState" +#define SIGNOND_OPERATION_NOT_SUPPORTED_ERR_NAME \ + SIGNOND_ERR_PREFIX "OperationNotSupported" +#define SIGNOND_NO_CONNECTION_ERR_NAME SIGNOND_ERR_PREFIX "NoConnection" +#define SIGNOND_NETWORK_ERR_NAME SIGNOND_ERR_PREFIX "Network" +#define SIGNOND_SSL_ERR_NAME SIGNOND_ERR_PREFIX "Ssl" +#define SIGNOND_RUNTIME_ERR_NAME SIGNOND_ERR_PREFIX "Runtime" +#define SIGNOND_SESSION_CANCELED_ERR_NAME SIGNOND_ERR_PREFIX "SessionCanceled" +#define SIGNOND_TIMED_OUT_ERR_NAME SIGNOND_ERR_PREFIX "TimedOut" +#define SIGNOND_USER_INTERACTION_ERR_NAME SIGNOND_ERR_PREFIX "UserInteraction" +#define SIGNOND_OPERATION_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "OperationFailed" +#define SIGNOND_TOS_NOT_ACCEPTED_ERR_NAME SIGNOND_ERR_PREFIX "TOSNotAccepted" +#define SIGNOND_FORGOT_PASSWORD_ERR_NAME SIGNOND_ERR_PREFIX "ForgotPassword" +#define SIGNOND_INCORRECT_DATE_ERR_NAME SIGNOND_ERR_PREFIX "IncorrectDate" +#define SIGNOND_USER_ERROR_ERR_NAME SIGNOND_ERR_PREFIX "User" + + +#include "signon-identity-info.h" + +G_BEGIN_DECLS + +enum SignonAuthSessionState { + SIGNON_AUTH_SESSION_STATE_NOT_STARTED = 0, /**< No message. */ + SIGNON_AUTH_SESSION_STATE_RESOLVING_HOST, /**< Resolving remote server + host name. */ + SIGNON_AUTH_SESSION_STATE_CONNECTING, /**< Connecting to remote + server. */ + SIGNON_AUTH_SESSION_STATE_SENDING_DATA, /**< Sending data to remote + server. */ + SIGNON_AUTH_SESSION_STATE_WAITING_REPLY, /**< Waiting reply from remote + server. */ + SIGNON_AUTH_SESSION_STATE_USER_PENDING, /**< Waiting response from + user. */ + SIGNON_AUTH_SESSION_STATE_UI_REFRESHING, /**< Refreshing ui request. */ + SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, /**< Waiting another process + to start. */ + SIGNON_AUTH_SESSION_STATE_STARTED, /**< Authentication session is + started. */ + SIGNON_AUTH_SESSION_STATE_PROCESS_CANCELING, /**< Canceling.current + process. */ + SIGNON_AUTH_SESSION_STATE_PROCESS_DONE, /**< Authentication + completed. */ + SIGNON_AUTH_SESSION_STATE_CUSTOM, /**< Custom message. */ + SIGNON_AUTH_SESSION_STATE_LAST +}; + +struct _SignonIdentityInfo +{ + gint id; + gchar *username; + gchar *secret; + gchar *caption; + gboolean store_secret; + GHashTable *methods; + gchar **realms; + SignonSecurityContext *owner; + SignonSecurityContextList *access_control_list; + gint type; +}; + +G_GNUC_INTERNAL +SignonIdentityInfo * +signon_identity_info_new_from_variant (GVariant *variant); + +G_GNUC_INTERNAL +GVariant * +signon_identity_info_to_variant (const SignonIdentityInfo *self); + +G_END_DECLS + +#endif + diff --git a/libgsignon-glib/signon-marshal.list b/libgsignon-glib/signon-marshal.list new file mode 100644 index 0000000..70ef299 --- /dev/null +++ b/libgsignon-glib/signon-marshal.list @@ -0,0 +1,2 @@ +VOID:INT,STRING + diff --git a/libgsignon-glib/signon-security-context.c b/libgsignon-glib/signon-security-context.c new file mode 100644 index 0000000..737db18 --- /dev/null +++ b/libgsignon-glib/signon-security-context.c @@ -0,0 +1,325 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2012-2013 Intel Corporation. + * + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "signon-security-context.h" + +static void +_security_context_free (gpointer ptr) +{ + SignonSecurityContext *ctx = (SignonSecurityContext *) ptr; + + signon_security_context_free (ctx); +} + +/** + * signon_security_context_new: + * + * Allocates a new security context item. + * + * Returns: (transfer full) allocated #SignonSecurityContext. + */ +SignonSecurityContext * +signon_security_context_new () +{ + SignonSecurityContext *ctx; + + ctx = g_slice_new0 (SignonSecurityContext); + ctx->sys_ctx = g_strdup (""); + ctx->app_ctx = g_strdup (""); + + return ctx; +} + +/** + * signon_security_context_new_from_vaues: + * @system_context: system security context (such as SMACK/MSSF label/token). + * @application_context: application security context (such as a script name). + * + * Allocates and initializes a new security context item. + * + * Returns: (transfer full) allocated #SignonSecurityContext. + */ +SignonSecurityContext * +signon_security_context_new_from_values (const gchar *system_context, + const gchar *application_context) +{ + SignonSecurityContext *ctx; + + g_return_val_if_fail (system_context != NULL, NULL); + + ctx = g_slice_new0 (SignonSecurityContext); + ctx->sys_ctx = g_strdup (system_context); + if (application_context) + ctx->app_ctx = g_strdup (application_context); + else + ctx->app_ctx = g_strdup (""); + + return ctx; +} + +/** + * signon_security_context_copy: + * @src_ctx: source security context to copy. + * + * Copy a security context item. + * + * Returns: (transfer full) a copy of the #SignonSecurityContex item. + */ +SignonSecurityContext * +signon_security_context_copy (const SignonSecurityContext *src_ctx) +{ + if (!src_ctx) + return NULL; + + return signon_security_context_new_from_values (src_ctx->sys_ctx, + src_ctx->app_ctx); +} + +/** + * signon_security_context_free: + * @ctx: #SignonSecurityContext to be freed. + * + * Frees a security context item. + */ +void +signon_security_context_free (SignonSecurityContext *ctx) +{ + if (ctx == NULL) return; + + g_free (ctx->sys_ctx); + g_free (ctx->app_ctx); + g_slice_free (SignonSecurityContext, ctx); +} + +/** + * signon_security_context_set_system_context: + * @ctx: #SignonSecurityContext item. + * @system_context: system security context. + * + * Sets the system context part (such as SMACK label or MSSF token) of the + * #SignonSecurityContext. + */ +void +signon_security_context_set_system_context (SignonSecurityContext *ctx, + const gchar *system_context) +{ + g_return_if_fail (ctx != NULL); + + g_free (ctx->sys_ctx); + ctx->sys_ctx = g_strdup (system_context); +} + +/** + * signon_security_context_get_system_context: + * @ctx: #SignonSecurityContext item. + * + * Get the system context part (such as SMACK label or MSSF token) of the + * #SignonSecurityContext. + * + * Returns: (transfer none) system context. + */ +const gchar * +signon_security_context_get_system_context (const SignonSecurityContext *ctx) +{ + g_return_val_if_fail (ctx != NULL, NULL); + + return ctx->sys_ctx; +} + +/** + * signon_security_context_set_application_context: + * @ctx: #SignonSecurityContext item. + * @application_context: application security context. + * + * Sets the application context part (such as a script name or a web page) of + * the #SignonSecurityContext. + */ +void +signon_security_context_set_application_context (SignonSecurityContext *ctx, + const gchar *application_context) +{ + g_return_if_fail (ctx != NULL); + + g_free (ctx->app_ctx); + ctx->app_ctx = g_strdup (application_context); +} + +/** + * signon_security_context_get_application_context: + * @ctx: #SignonSecurityContext item. + * + * Get the application context part (such as script name or a web page) of + * the #SignonSecurityContext. + * + * Returns: (transfer none) application context. + */ +const gchar * +signon_security_context_get_application_context ( + const SignonSecurityContext *ctx) +{ + g_return_val_if_fail (ctx != NULL, NULL); + + return ctx->app_ctx; +} + +/** + * signon_security_conetxt_build_variant: + * @ctx: #SignonSecurityContext item. + * + * Build a GVariant of type "(ss)" from a #SignonSecurityContext item. + * + * Returns: (transfer full) GVariant construct of a #SignonSecurityContext. + */ +GVariant * +signon_security_context_build_variant (const SignonSecurityContext *ctx) +{ + GVariant *variant; + + g_return_val_if_fail (ctx != NULL, NULL); + + variant = g_variant_new ("(ss)", + ctx->sys_ctx ? ctx->sys_ctx : "", + ctx->app_ctx ? ctx->app_ctx : ""); + + return variant; +} + +/** + * signon_security_context_deconstruct_variant: + * @variant: GVariant item with a #SignonSecurityContext construct. + * + * Builds a #SignonSecurityContext item from a GVariant of type "(ss)". + * + * Returns: (transfer full) #SignonSecurityContext item. + */ +SignonSecurityContext * +signon_security_context_deconstruct_variant (GVariant *variant) +{ + gchar *sys_ctx = NULL; + gchar *app_ctx = NULL; + SignonSecurityContext *ctx; + + g_return_val_if_fail (variant != NULL, NULL); + + g_variant_get (variant, "(ss)", &sys_ctx, &app_ctx); + ctx = signon_security_context_new_from_values (sys_ctx, app_ctx); + g_free (sys_ctx); + g_free (app_ctx); + return ctx; +} + +/** + * signon_security_context_list_build_variant: + * @list: #SignonSecurityContextList item. + * + * Builds a GVariant of type "a(ss)" from a GList of #SignonSecurityContext + * items. + * + * Returns: (transfer full) GVariant construct of a #SignonSecurityContextList. + */ +GVariant * +signon_security_context_list_build_variant ( + const SignonSecurityContextList *list) +{ + GVariantBuilder builder; + GVariant *variant; + SignonSecurityContext *ctx; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + for ( ; list != NULL; list = g_list_next (list)) + { + ctx = (SignonSecurityContext *) list->data; + g_variant_builder_add_value (&builder, + signon_security_context_build_variant (ctx)); + } + variant = g_variant_builder_end (&builder); + + return variant; +} + +/** + * signon_security_context_list_deconstruct_variant: + * @variant: GVariant item with a list of security context tuples. + * + * Builds a GList of #SignonSecurityContext items from a GVariant of type + * "a(ss)". + * + * Returns: (transfer full) #SignonSecurityContextList item. + */ +SignonSecurityContextList * +signon_security_context_list_deconstruct_variant (GVariant *variant) +{ + SignonSecurityContextList *list = NULL; + GVariantIter iter; + GVariant *value; + + g_return_val_if_fail (variant != NULL, NULL); + + g_variant_iter_init (&iter, variant); + while ((value = g_variant_iter_next_value (&iter))) + { + list = g_list_append ( + list, signon_security_context_deconstruct_variant (value)); + g_variant_unref (value); + } + + return list; +} + +/** + * signon_security_context_list_copy: + * @src_list: source #SignonSecurityContextList. + * + * Copies a GList of #SignonSecurityContext items. + * + * Returns: (transfer full) #SignonSecurityContextList item. + */ +SignonSecurityContextList * +signon_security_context_list_copy (const SignonSecurityContextList *src_list) +{ + SignonSecurityContext *ctx; + SignonSecurityContextList *dst_list = NULL; + + for ( ; src_list != NULL; src_list = g_list_next (src_list)) + { + ctx = (SignonSecurityContext *) src_list->data; + dst_list = g_list_append ( + dst_list, signon_security_context_copy (ctx)); + } + + return dst_list; +} + +/** + * signon_security_context_list_free: + * @seclist: (transfer full) #SignonSecurityContextList item. + * + * Frees all items and the GList of #SignonSecurityContext. + */ +void +signon_security_context_list_free (SignonSecurityContextList *seclist) +{ + g_list_free_full (seclist, _security_context_free); +} + diff --git a/libgsignon-glib/signon-security-context.h b/libgsignon-glib/signon-security-context.h new file mode 100644 index 0000000..a91cd7b --- /dev/null +++ b/libgsignon-glib/signon-security-context.h @@ -0,0 +1,85 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2012 Intel Corporation. + * + * Contact: Jussi Laako + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _SIGNON_SECURITY_CONTEXT_H_ +#define _SIGNON_SECURITY_CONTEXT_H_ + +#include + +G_BEGIN_DECLS + +/** + * Security context descriptor. + * + * Practically a string tuple. + * + * @sys_ctx: system context, such as SMACK-label, MSSF token or just a + * binary path. + * @app_ctx: application context, such as a script or a web page. + */ +typedef struct _SignonSecurityContext +{ + gchar *sys_ctx; + gchar *app_ctx; +} SignonSecurityContext; + +/** + * GList of #SignonSecurityContext items. + */ +typedef GList SignonSecurityContextList; + +SignonSecurityContext * signon_security_context_new (); +SignonSecurityContext * signon_security_context_new_from_values ( + const gchar *system_context, + const gchar *application_context); +void signon_security_context_free (SignonSecurityContext *ctx); +SignonSecurityContext * signon_security_context_copy ( + const SignonSecurityContext *src_ctx); +void signon_security_context_set_system_context (SignonSecurityContext *ctx, + const gchar *system_context); +const gchar * signon_security_context_get_system_context ( + const SignonSecurityContext *ctx); +void signon_security_context_set_application_context ( + SignonSecurityContext *ctx, + const gchar *application_context); +const gchar * signon_security_context_get_application_context ( + const SignonSecurityContext *ctx); +GVariant * signon_security_context_build_variant ( + const SignonSecurityContext *ctx); +SignonSecurityContext * signon_security_context_deconstruct_variant ( + GVariant *variant); + +GVariant * signon_security_context_list_build_variant ( + const SignonSecurityContextList *list); +SignonSecurityContextList * signon_security_context_list_deconstruct_variant ( + GVariant *variant); + +SignonSecurityContextList * signon_security_context_list_copy ( + const SignonSecurityContextList *src_list); +void signon_security_context_list_free (SignonSecurityContextList *seclist); + +G_END_DECLS + +#endif /* _SIGNON_SECURITY_CONTEXT_H_ */ + diff --git a/libgsignon-glib/signon-types.h b/libgsignon-glib/signon-types.h new file mode 100644 index 0000000..cc2de90 --- /dev/null +++ b/libgsignon-glib/signon-types.h @@ -0,0 +1,42 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2012 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef SIGNON_TYPES_H +#define SIGNON_TYPES_H + +#include + +G_BEGIN_DECLS + +#ifdef SIGNON_DISABLE_DEPRECATION_WARNINGS +#define SIGNON_DEPRECATED +#define SIGNON_DEPRECATED_FOR(x) +#else +#define SIGNON_DEPRECATED G_DEPRECATED +#define SIGNON_DEPRECATED_FOR(x) G_DEPRECATED_FOR(x) +#endif + +G_END_DECLS + +#endif /* SIGNON_TYPES_H */ diff --git a/libgsignon-glib/signon-utils.c b/libgsignon-glib/signon-utils.c new file mode 100644 index 0000000..fff3a4d --- /dev/null +++ b/libgsignon-glib/signon-utils.c @@ -0,0 +1,122 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "signon-utils.h" +#include + +static const GVariantType * +signon_gtype_to_variant_type (GType type) +{ + switch (type) + { + case G_TYPE_STRING: return G_VARIANT_TYPE_STRING; + case G_TYPE_BOOLEAN: return G_VARIANT_TYPE_BOOLEAN; + case G_TYPE_UCHAR: return G_VARIANT_TYPE_BYTE; + case G_TYPE_INT: return G_VARIANT_TYPE_INT32; + case G_TYPE_UINT: return G_VARIANT_TYPE_UINT32; + case G_TYPE_INT64: return G_VARIANT_TYPE_INT64; + case G_TYPE_UINT64: return G_VARIANT_TYPE_UINT64; + case G_TYPE_DOUBLE: return G_VARIANT_TYPE_DOUBLE; + default: + if (type == G_TYPE_STRV) return G_VARIANT_TYPE_STRING_ARRAY; + + g_critical ("Unsupported type %s", g_type_name (type)); + return NULL; + } +} + +GValue * +signon_gvalue_new (GType type) +{ + GValue *value = g_slice_new0 (GValue); + g_value_init (value, type); + return value; +} + +void signon_gvalue_free (gpointer val) +{ + g_return_if_fail (G_IS_VALUE(val)); + + GValue *value = (GValue*)val; + g_value_unset (value); + g_slice_free (GValue, value); +} + +GHashTable *signon_hash_table_from_variant (GVariant *variant) +{ + GHashTable *hash_table; + GVariantIter iter; + GVariant *value; + gchar *key; + + if (variant == NULL) return NULL; + + hash_table = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + signon_gvalue_free); + g_variant_iter_init (&iter, variant); + while (g_variant_iter_next (&iter, "{sv}", &key, &value)) + { + GValue *val = g_slice_new0 (GValue); + g_dbus_gvariant_to_gvalue (value, val); + g_variant_unref (value); + + g_hash_table_insert (hash_table, key, val); + } + return hash_table; +} + +GVariant *signon_hash_table_to_variant (const GHashTable *hash_table) +{ + GVariantBuilder builder; + GHashTableIter iter; + const gchar *key; + const GValue *value; + + if (hash_table == NULL) return NULL; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + g_hash_table_iter_init (&iter, (GHashTable *)hash_table); + while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value)) + { + GVariant *val; + + if (G_VALUE_TYPE (value) == G_TYPE_VARIANT) + { + val = g_value_get_variant (value); + g_variant_builder_add (&builder, "{sv}", key, val); + } + else + { + const GVariantType *type; + type = signon_gtype_to_variant_type (G_VALUE_TYPE (value)); + val = g_dbus_gvalue_to_gvariant (value, type); + g_variant_builder_add (&builder, "{sv}", key, val); + g_variant_unref (val); + } + } + return g_variant_builder_end (&builder); +} diff --git a/libgsignon-glib/signon-utils.h b/libgsignon-glib/signon-utils.h new file mode 100644 index 0000000..9a81e8b --- /dev/null +++ b/libgsignon-glib/signon-utils.h @@ -0,0 +1,45 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2009-2010 Nokia Corporation. + * Copyright (C) 2012 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef _SIGNON_UTILS_H_ +#define _SIGNON_UTILS_H_ + +#include + +#define SIGNON_IS_NOT_CANCELLED(error) \ + (error == NULL || \ + error->domain != G_IO_ERROR || \ + error->code != G_IO_ERROR_CANCELLED) + +G_GNUC_INTERNAL +GValue *signon_gvalue_new (GType type); +G_GNUC_INTERNAL +void signon_gvalue_free (gpointer val); + +G_GNUC_INTERNAL +GHashTable *signon_hash_table_from_variant (GVariant *variant); +G_GNUC_INTERNAL +GVariant *signon_hash_table_to_variant (const GHashTable *hash_table); + +#endif //_SIGNON_UTILS_H_ diff --git a/libgsignon-glib/signon.vapi b/libgsignon-glib/signon.vapi new file mode 100644 index 0000000..0f8bf39 --- /dev/null +++ b/libgsignon-glib/signon.vapi @@ -0,0 +1,166 @@ +/* signon.vapi generated by vapigen, do not modify. */ + +[CCode (cprefix = "Signon", gir_namespace = "Signon", gir_version = "1.0", lower_case_cprefix = "signon_")] +namespace Signon { + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", type_id = "signon_auth_service_get_type ()")] + public class AuthService : GLib.Object { + [CCode (has_construct_function = false)] + public AuthService (); + public void query_mechanisms (string method, Signon.QueryMechanismCb cb); + public void query_methods (Signon.QueryMethodsCb cb); + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", type_id = "signon_auth_session_get_type ()")] + public class AuthSession : GLib.Object { + [CCode (has_construct_function = false)] + public AuthSession (uint id, string method_name) throws GLib.Error; + public void cancel (); + public unowned string get_method (); + public void process (GLib.HashTable session_data, string mechanism, Signon.AuthSessionProcessCb cb); + public void query_available_mechanisms (string wanted_mechanisms, Signon.AuthSessionQueryAvailableMechanismsCb cb); + public signal void state_changed (int object, string p0); + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", type_id = "signon_identity_get_type ()")] + public class Identity : GLib.Object { + [CCode (has_construct_function = false)] + public Identity (); + public void add_reference (string reference, Signon.IdentityReferenceAddedCb cb, void* user_data); + public Signon.AuthSession create_session (string method) throws GLib.Error; + [CCode (has_construct_function = false)] + public Identity.from_db (uint32 id); + public unowned GLib.Error get_last_error (); + public void query_info (Signon.IdentityInfoCb cb); + public void remove (Signon.IdentityRemovedCb cb, void* user_data); + public void remove_reference (string reference, Signon.IdentityReferenceRemovedCb cb, void* user_data); + public void store_credentials_with_args (string username, string secret, bool store_secret, GLib.HashTable methods, string caption, string realms, string access_control_list, Signon.IdentityType type, Signon.IdentityStoreCredentialsCb cb); + public void store_credentials_with_info (Signon.IdentityInfo info, Signon.IdentityStoreCredentialsCb cb); + public void verify_secret (string secret, Signon.IdentityVerifyCb cb); + [NoAccessorMethod] + public uint id { get; set; } + [HasEmitter] + public signal void signout (); + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "signon_identity_info_get_type ()")] + [Compact] + public class IdentityInfo { + [CCode (has_construct_function = false)] + public IdentityInfo (); + public Signon.IdentityInfo copy (); + public void free (); + [CCode (array_length = false, array_null_terminated = true)] + public unowned string[] get_access_control_list (); + public unowned string get_caption (); + public int get_id (); + public Signon.IdentityType get_identity_type (); + public unowned GLib.HashTable get_methods (); + [CCode (array_length = false, array_null_terminated = true)] + public unowned string[] get_realms (); + public bool get_storing_secret (); + public unowned string get_username (); + public void remove_method (string method); + public void set_access_control_list (string access_control_list); + public void set_caption (string caption); + public void set_identity_type (Signon.IdentityType type); + public void set_method (string method, string mechanisms); + public void set_realms (string realms); + public void set_secret (string secret, bool store_secret); + public void set_username (string username); + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cprefix = "SIGNON_IDENTITY_TYPE_")] + [Flags] + public enum IdentityType { + OTHER, + APP, + WEB, + NETWORK + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cprefix = "SIGNON_POLICY_")] + public enum SessionDataUiPolicy { + DEFAULT, + REQUEST_PASSWORD, + NO_USER_INTERACTION, + VALIDATION + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cprefix = "SIGNON_ERROR_")] + public errordomain Error { + UNKNOWN, + INTERNAL_SERVER, + INTERNAL_COMMUNICATION, + PERMISSION_DENIED, + METHOD_NOT_KNOWN, + SERVICE_NOT_AVAILABLE, + INVALID_QUERY, + METHOD_NOT_AVAILABLE, + IDENTITY_NOT_FOUND, + STORE_FAILED, + REMOVE_FAILED, + SIGNOUT_FAILED, + IDENTITY_OPERATION_CANCELED, + CREDENTIALS_NOT_AVAILABLE, + REFERENCE_NOT_FOUND, + MECHANISM_NOT_AVAILABLE, + MISSING_DATA, + INVALID_CREDENTIALS, + NOT_AUTHORIZED, + WRONG_STATE, + OPERATION_NOT_SUPPORTED, + NO_CONNECTION, + NETWORK, + SSL, + RUNTIME, + SESSION_CANCELED, + TIMED_OUT, + USER_INTERACTION, + OPERATION_FAILED, + ENCRYPTION_FAILED, + TOS_NOT_ACCEPTED, + FORGOT_PASSWORD, + METHOD_OR_MECHANISM_NOT_ALLOWED, + INCORRECT_DATE, + USER_ERROR; + public static GLib.Quark quark (); + } + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void AuthSessionProcessCb (Signon.AuthSession self, owned GLib.HashTable session_data, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void AuthSessionQueryAvailableMechanismsCb (Signon.AuthSession self, [CCode (array_length = false, array_null_terminated = true)] owned string[] mechanisms, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void AuthSessionQueryAvailableMethodsCb (Signon.AuthSession self, [CCode (array_length = false, array_null_terminated = true)] owned string[] mechanisms, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void IdentityInfoCb (Signon.Identity self, Signon.IdentityInfo info, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 2.9)] + public delegate void IdentityReferenceAddedCb (Signon.Identity self, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 2.9)] + public delegate void IdentityReferenceRemovedCb (Signon.Identity self, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 2.9)] + public delegate void IdentityRemovedCb (Signon.Identity self, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 2.9)] + public delegate void IdentitySignedOutCb (Signon.Identity self, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void IdentityStoreCredentialsCb (Signon.Identity self, uint32 id, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void IdentityVerifyCb (Signon.Identity self, bool valid, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 2.9)] + public delegate void IdentityVoidCb (Signon.Identity self, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 4.9)] + public delegate void QueryMechanismCb (Signon.AuthService auth_service, string method, [CCode (array_length = false, array_null_terminated = true)] owned string[] mechanisms, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", instance_pos = 3.9)] + public delegate void QueryMethodsCb (Signon.AuthService auth_service, [CCode (array_length = false, array_null_terminated = true)] owned string[] methods, GLib.Error error); + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_CAPTION")] + public const string SESSION_DATA_CAPTION; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_PROXY")] + public const string SESSION_DATA_PROXY; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_REALM")] + public const string SESSION_DATA_REALM; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_RENEW_TOKEN")] + public const string SESSION_DATA_RENEW_TOKEN; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_SECRET")] + public const string SESSION_DATA_SECRET; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_TIMEOUT")] + public const string SESSION_DATA_TIMEOUT; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_UI_POLICY")] + public const string SESSION_DATA_UI_POLICY; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_USERNAME")] + public const string SESSION_DATA_USERNAME; + [CCode (cheader_filename = "libgsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_WINDOW_ID")] + public const string SESSION_DATA_WINDOW_ID; +} diff --git a/libgsignon-glib/sso-auth-service.c b/libgsignon-glib/sso-auth-service.c new file mode 100644 index 0000000..eccdf56 --- /dev/null +++ b/libgsignon-glib/sso-auth-service.c @@ -0,0 +1,143 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2012 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include "signon-errors.h" +#include "signon-internals.h" +#include "sso-auth-service.h" + +static GHashTable *thread_objects = NULL; +static GMutex map_mutex; + +static SsoAuthService * +get_singleton () +{ + SsoAuthService *object = NULL; + + g_mutex_lock (&map_mutex); + + if (thread_objects != NULL) + { + GWeakRef *ref; + ref = g_hash_table_lookup (thread_objects, g_thread_self ()); + if (ref != NULL) + { + object = g_weak_ref_get (ref); + } + } + + g_mutex_unlock (&map_mutex); + return object; +} + +static void +g_thread_ref_free (GWeakRef *data) +{ + g_slice_free (GWeakRef, data); +} + +static void +set_singleton (SsoAuthService *object) +{ + g_return_if_fail (IS_SSO_AUTH_SERVICE (object)); + + g_mutex_lock (&map_mutex); + + if (thread_objects == NULL) + { + thread_objects = g_hash_table_new_full (g_direct_hash, g_direct_equal, + NULL, (GDestroyNotify)g_thread_ref_free); + } + + if (object != NULL) + { + GWeakRef *ref = g_slice_new (GWeakRef); + g_weak_ref_init (ref, object); + g_hash_table_insert (thread_objects, g_thread_self (), ref); + } + + g_mutex_unlock (&map_mutex); +} + +static void +_on_auth_service_destroyed (gpointer data, GObject *obj) +{ + (void)data; + (void)obj; + g_mutex_lock (&map_mutex); + if (thread_objects) + { + g_hash_table_unref (thread_objects); + thread_objects = NULL; + } + g_mutex_unlock (&map_mutex); +} + + +SsoAuthService * +sso_auth_service_get_instance () +{ + SsoAuthService *sso_auth_service = NULL; + GDBusConnection *connection = NULL; + GError *error = NULL; + + sso_auth_service = get_singleton (); + if (sso_auth_service != NULL) return sso_auth_service; + +#ifdef USE_P2P + connection = g_dbus_connection_new_for_address_sync (SIGNOND_BUS_ADDRESS, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, + NULL, + NULL, + &error); +#else + connection = g_bus_get_sync (SIGNOND_BUS_TYPE, NULL, &error); +#endif + /* Create the object */ + sso_auth_service = + sso_auth_service_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, +#ifdef USE_P2P + NULL, +#else + SIGNOND_SERVICE, +#endif + SIGNOND_DAEMON_OBJECTPATH, + NULL, + &error); + g_object_weak_ref (G_OBJECT (sso_auth_service), _on_auth_service_destroyed, sso_auth_service); + if (G_LIKELY (error == NULL)) { + set_singleton (sso_auth_service); + } + else + { + g_warning ("Couldn't activate signond: %s", error->message); + g_clear_error (&error); + } + + /* While at it, register the error mapping with GDBus */ + signon_error_quark (); + + return sso_auth_service; +} diff --git a/libgsignon-glib/sso-auth-service.h b/libgsignon-glib/sso-auth-service.h new file mode 100644 index 0000000..1c4ab7c --- /dev/null +++ b/libgsignon-glib/sso-auth-service.h @@ -0,0 +1,37 @@ +/* vi: set et sw=4 ts=4 cino=t0,(0: */ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of libgsignon-glib + * + * Copyright (C) 2012 Canonical Ltd. + * + * Contact: Alberto Mardegan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef _SSO_AUTH_SERVICE_H_ +#define _SSO_AUTH_SERVICE_H_ + +#include "sso-auth-service-gen.h" + +G_BEGIN_DECLS + +G_GNUC_INTERNAL +SsoAuthService *sso_auth_service_get_instance (); + +G_END_DECLS + +#endif /* _SSO_AUTH_SERVICE_H_ */ diff --git a/libsignon-glib.pc.in b/libsignon-glib.pc.in deleted file mode 100644 index 0c1e247..0000000 --- a/libsignon-glib.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ -pluginlibdir=@pluginlibdir@ - -Name: libsignon-glib -Description: A low-level library for managing account credentials. -Version: @VERSION@ -Requires: signond glib-2.0 gobject-2.0 gio-unix-2.0 -Libs: -L${libdir} -lsignon-glib -Cflags: -I${includedir} diff --git a/libsignon-glib/.gitignore b/libsignon-glib/.gitignore deleted file mode 100644 index 02bc592..0000000 --- a/libsignon-glib/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*-glib-gen.h -*-enum-types.[ch] -signon-errors-enum.c diff --git a/libsignon-glib/Makefile.am b/libsignon-glib/Makefile.am deleted file mode 100644 index 3aeeba8..0000000 --- a/libsignon-glib/Makefile.am +++ /dev/null @@ -1,213 +0,0 @@ -lib_LTLIBRARIES = \ - libsignon-glib.la - -libsignon_glib_la_CPPFLAGS = \ - -I$(top_srcdir) \ - -I$(srcdir) \ - -I$(top_builddir) \ - -I$(builddir) \ - $(DEPS_CFLAGS) \ - -Wall -Werror -libsignon_glib_la_LIBADD = $(DEPS_LIBS) -libsignon_glib_la_LDFLAGS = \ - -version-info 1:0:0 \ - -export-symbols-regex '^signon_' - -nodist_libsignon_glib_la_SOURCES = \ - signon-marshal.c \ - signon-marshal.h \ - signon-enum-types.h \ - signon-enum-types.c \ - signon-errors-enum.c \ - sso-auth-service-gen.c \ - sso-auth-service-gen.h \ - sso-auth-session-gen.c \ - sso-auth-session-gen.h \ - sso-identity-gen.c \ - sso-identity-gen.h \ - stamp-signon-enum-types.h - -BUILT_SOURCES = \ - $(nodist_libsignon_glib_la_SOURCES) \ - signon-errors-map.c - -CLEANFILES = \ - $(BUILT_SOURCES) \ - sso-auth-service-gen-doc-com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml \ - sso-auth-session-gen-doc-com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml \ - sso-identity-gen-doc-com.google.code.AccountsSSO.gSingleSignOn.Identity.xml - -libsignon_glib_la_SOURCES = \ - signon-auth-service.h \ - signon-identity-info.h \ - signon-identity.h \ - signon-dbus-queue.h \ - signon-auth-session.h \ - signon-internals.h \ - signon-auth-service.c \ - signon-identity-info.c \ - signon-identity.c \ - signon-dbus-queue.c \ - signon-auth-session.c \ - signon-errors.h \ - signon-errors.c \ - signon-utils.h \ - signon-utils.c \ - signon-types.h \ - signon-security-context.h \ - signon-security-context.c \ - sso-auth-service.c \ - sso-auth-service.h - -libsignon_glib_includedir = $(includedir)/libsignon-glib -libsignon_glib_include_HEADERS = \ - signon-auth-service.h \ - signon-auth-session.h \ - signon-identity-info.h \ - signon-identity.h \ - signon-security-context.h \ - signon-errors.h \ - signon-enum-types.h \ - signon-glib.h \ - signon-types.h \ - $(signon_headers) - -# Headers with enums to be parsed with glib-mkenums; -# signon-errors.h is handled separately -libsignon_glib_headers_with_enums = \ - signon-auth-session.h \ - signon-identity-info.h - -# This should come from `pkg-config --variable=interfaces_dir dbus-1` -# default is /usr/share/dbus-1/interfaces -DBUS_INTERFACES_DIR = interfaces - -sso-auth-service-gen.h sso-auth-service-gen.c: $(DBUS_INTERFACES_DIR)/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml - $(AM_V_GEN)gdbus-codegen \ - --generate-c-code sso-auth-service-gen \ - --generate-docbook sso-auth-service-gen-doc \ - --annotate "com.google.code.AccountsSSO.gSingleSignOn.AuthService" org.gtk.GDBus.C.Name SsoAuthService \ - $< - -sso-auth-session-gen.h sso-auth-session-gen.c: $(DBUS_INTERFACES_DIR)/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml - $(AM_V_GEN)gdbus-codegen \ - --generate-c-code sso-auth-session-gen \ - --generate-docbook sso-auth-session-gen-doc \ - --annotate "com.google.code.AccountsSSO.gSingleSignOn.AuthSession" org.gtk.GDBus.C.Name SsoAuthSession \ - $< - -sso-identity-gen.h sso-identity-gen.c: $(DBUS_INTERFACES_DIR)/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml - $(AM_V_GEN)gdbus-codegen \ - --generate-c-code sso-identity-gen \ - --generate-docbook sso-identity-gen-doc \ - --annotate "com.google.code.AccountsSSO.gSingleSignOn.Identity" org.gtk.GDBus.C.Name SsoIdentity \ - $< - -signon-marshal.h: signon-marshal.list Makefile - $(AM_V_GEN)glib-genmarshal --header --prefix=_signon_marshal $< > $@ - -signon-marshal.c: signon-marshal.list Makefile - $(AM_V_GEN)glib-genmarshal --body --prefix=_signon_marshal $< > $@ - -signon-enum-types.h: stamp-signon-enum-types.h - $(AM_V_at)true - -stamp-signon-enum-types.h: Makefile \ - $(libsignon_glib_headers_with_enums) signon-errors.h - $(AM_V_GEN)( cd $(srcdir) && glib-mkenums \ - --fhead "#ifndef __SIGNON_ENUM_TYPES_H__\n#define __SIGNON_ENUM_TYPES_H__\n#include \n\nG_BEGIN_DECLS\n" \ - --fprod "/* enumerations from \"@filename@\" */\n" \ - --vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define SIGNON_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ - --ftail "G_END_DECLS\n\n#endif /* __SIGNON_ENUM_TYPES_H__ */" \ - $(libsignon_glib_headers_with_enums) signon-errors.h ) >> xgen-geth \ - && (cmp -s xgen-geth signon-enum-types.h || cp xgen-geth signon-enum-types.h ) \ - && rm -f xgen-geth \ - && echo timestamp > $(@F) - -signon-enum-types.c: Makefile $(libsignon_glib_headers_with_enums) - $(AM_V_GEN)( cd $(srcdir) && glib-mkenums \ - --fhead "#include \"signon-enum-types.h\"\n" \ - --fhead "#include \"signon-identity-info.h\"\n" \ - --fhead "#include \"signon-auth-session.h\"\n" \ - --fhead "#define g_intern_static_string(s) (s)\n" \ - --fprod "\n/* enumerations from \"@filename@\" */" \ - --ftail "\n#define __SIGNON_ENUM_TYPES_C__\n" \ - --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ - --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \ - --vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (g_intern_static_string (\"@EnumName@\"), values);\n }\n return etype;\n}\n" \ - $(libsignon_glib_headers_with_enums) ) > xgen-getc \ - && cp xgen-getc signon-enum-types.c \ - && rm -f xgen-getc - -signon-errors-enum.c: Makefile signon-errors.h - $(AM_V_GEN)( cd $(srcdir) && glib-mkenums \ - --fhead "#include \"signon-enum-types.h\"\n#include \"signon-errors.h\"\n#include \"signon-internals.h\"\n#define g_intern_static_string(s) (s)\n" \ - --fprod "\n/* enumerations from \"@filename@\" */" \ - --ftail "\n#define __SIGNON_ENUM_TYPES_C__\n" \ - --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ - --vprod " { @VALUENAME@, SED@VALUENAME@, \"@valuenick@\" }," \ - --vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (g_intern_static_string (\"@EnumName@\"), values);\n }\n return etype;\n}\n" \ - signon-errors.h ) | \ - $(SED) -e 's/SEDSIGNON_ERROR_\([^,]*\)/SIGNOND_\1_ERR_NAME/' \ - > xgen-getc \ - && cp xgen-getc signon-errors-enum.c \ - && rm -f xgen-getc - -signon-errors-map.c: Makefile signon-errors.h - $(AM_V_GEN)( cd $(srcdir) && \ - echo "static const GDBusErrorEntry signon_error_entries[] = {" && \ - grep "^ *SIGNON_ERROR_" signon-errors.h | \ - $(SED) -e 's/SIGNON_ERROR_\([A-Z_0-9]*\).*/{ SIGNON_ERROR_\1, SIGNOND_\1_ERR_NAME },/' && \ - echo -e "};\n" ) > signon-errors-map.c - -dist_noinst_DATA = \ - signon-marshal.list \ - stamp-signon-enum-types.h - --include $(INTROSPECTION_MAKEFILE) -INTROSPECTION_GIRS = -INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) -INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) - -if HAVE_INTROSPECTION -introspection_sources = \ - signon-auth-service.c \ - signon-auth-service.h \ - signon-auth-session.c \ - signon-auth-session.h \ - signon-enum-types.h \ - signon-enum-types.c \ - signon-errors.c \ - signon-errors.h \ - signon-identity-info.c \ - signon-identity-info.h \ - signon-identity.c \ - signon-identity.h - -Signon-1.0.gir: libsignon-glib.la -Signon_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0 -Signon_1_0_gir_SCANNERFLAGS = \ - --identifier-prefix=Signon \ - --symbol-prefix=signon \ - --c-include="libsignon-glib/signon-glib.h" \ - --warn-all -Signon_1_0_gir_CFLAGS = \ - -I$(top_srcdir) \ - $(DEPS_CFLAGS) -Signon_1_0_gir_LIBS = libsignon-glib.la -Signon_1_0_gir_FILES = $(introspection_sources) -INTROSPECTION_GIRS += Signon-1.0.gir - -girdir = $(datadir)/gir-1.0 -gir_DATA = $(INTROSPECTION_GIRS) - -typelibdir = $(libdir)/girepository-1.0 -typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) - -CLEANFILES += $(gir_DATA) $(typelib_DATA) -endif - -# Vala bindings -vapidir = $(datadir)/vala/vapi -dist_vapi_DATA = \ - signon.vapi diff --git a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml b/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml deleted file mode 100644 index 9fc893c..0000000 --- a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml b/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml deleted file mode 100644 index 7047757..0000000 --- a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthSession.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml b/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml deleted file mode 100644 index 8e265de..0000000 --- a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.Identity.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libsignon-glib/signon-auth-service.c b/libsignon-glib/signon-auth-service.c deleted file mode 100644 index bfa171d..0000000 --- a/libsignon-glib/signon-auth-service.c +++ /dev/null @@ -1,369 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -/** - * SECTION:signon-auth-service - * @title: SignonAuthService - * @short_description: The authorization service object - * - * The #SignonAuthService is the main object in this library. - */ - -#include "signon-auth-service.h" -#include "signon-errors.h" -#include "signon-internals.h" -#include "sso-auth-service.h" -#include -#include - -G_DEFINE_TYPE (SignonAuthService, signon_auth_service, G_TYPE_OBJECT); - -struct _SignonAuthServicePrivate -{ - SsoAuthService *proxy; - GCancellable *cancellable; -}; - -typedef struct _MethodCbData -{ - SignonAuthService *service; - SignonQueryMethodsCb cb; - gpointer userdata; -} MethodCbData; - -typedef struct _MechanismCbData -{ - SignonAuthService *service; - SignonQueryMechanismCb cb; - gpointer userdata; - gchar *method; -} MechanismCbData; - -typedef struct _IdentityCbData -{ - SignonAuthService *service; - SignonQueryIdentitiesCb cb; - gpointer userdata; -} IdentityCbData; - -#define SIGNON_AUTH_SERVICE_PRIV(obj) (SIGNON_AUTH_SERVICE(obj)->priv) - -static void -signon_auth_service_init (SignonAuthService *auth_service) -{ - SignonAuthServicePrivate *priv; - - priv = G_TYPE_INSTANCE_GET_PRIVATE (auth_service, SIGNON_TYPE_AUTH_SERVICE, - SignonAuthServicePrivate); - auth_service->priv = priv; - - /* Create the proxy */ - priv->cancellable = g_cancellable_new (); - priv->proxy = sso_auth_service_get_instance (); -} - -static void -signon_auth_service_dispose (GObject *object) -{ - SignonAuthService *auth_service = SIGNON_AUTH_SERVICE (object); - SignonAuthServicePrivate *priv = auth_service->priv; - - if (priv->cancellable) - { - g_cancellable_cancel (priv->cancellable); - g_object_unref (priv->cancellable); - priv->cancellable = NULL; - } - - if (priv->proxy) - { - g_object_unref (priv->proxy); - priv->proxy = NULL; - } - - G_OBJECT_CLASS (signon_auth_service_parent_class)->dispose (object); -} - -static void -signon_auth_service_finalize (GObject *object) -{ - G_OBJECT_CLASS (signon_auth_service_parent_class)->finalize (object); -} - -static void -signon_auth_service_class_init (SignonAuthServiceClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (object_class, sizeof (SignonAuthServicePrivate)); - - object_class->dispose = signon_auth_service_dispose; - object_class->finalize = signon_auth_service_finalize; -} - -/** - * signon_auth_service_new: - * - * Create a new #SignonAuthService. - * - * Returns: an instance of an #SignonAuthService. - */ -SignonAuthService * -signon_auth_service_new () -{ - return g_object_new (SIGNON_TYPE_AUTH_SERVICE, NULL); -} - -static void -auth_query_methods_cb (GObject *object, GAsyncResult *res, - gpointer user_data) -{ - SsoAuthService *proxy = SSO_AUTH_SERVICE (object); - MethodCbData *data = (MethodCbData*)user_data; - gchar **value = NULL; - GError *error = NULL; - - g_return_if_fail (data != NULL); - - sso_auth_service_call_query_methods_finish (proxy, &value, - res, &error); - (data->cb) - (data->service, value, error, data->userdata); - - g_clear_error (&error); - g_slice_free (MethodCbData, data); -} - -static void -auth_query_mechanisms_cb (GObject *object, GAsyncResult *res, - gpointer user_data) -{ - SsoAuthService *proxy = SSO_AUTH_SERVICE (object); - MechanismCbData *data = (MechanismCbData*) user_data; - gchar **value = NULL; - GError *error = NULL; - - g_return_if_fail (data != NULL); - - sso_auth_service_call_query_mechanisms_finish (proxy, &value, - res, &error); - (data->cb) - (data->service, data->method, value, error, data->userdata); - - if (error) - g_error_free (error); - g_free (data->method); - g_slice_free (MechanismCbData, data); -} - -/** - * SignonQueryMethodsCb: - * @auth_service: the #SignonAuthService. - * @methods: (transfer full) (type GStrv): list of available methods. - * @error: a #GError if an error occurred, %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_auth_service_query_methods(). - */ - -/** - * signon_auth_service_query_methods: - * @auth_service: the #SignonAuthService. - * @cb: (scope async): callback to be invoked. - * @user_data: user data. - * - * Lists all the available methods. - */ -void -signon_auth_service_query_methods (SignonAuthService *auth_service, - SignonQueryMethodsCb cb, - gpointer user_data) -{ - SignonAuthServicePrivate *priv; - - g_return_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service)); - g_return_if_fail (cb != NULL); - priv = SIGNON_AUTH_SERVICE_PRIV (auth_service); - - MethodCbData *cb_data; - cb_data = g_slice_new (MethodCbData); - cb_data->service = auth_service; - cb_data->cb = cb; - cb_data->userdata = user_data; - - sso_auth_service_call_query_methods (priv->proxy, - priv->cancellable, - auth_query_methods_cb, - cb_data); -} - -/** - * SignonQueryMechanismCb: - * @auth_service: the #SignonAuthService. - * @method: the authentication method being inspected. - * @mechanisms: (transfer full) (type GStrv): list of available mechanisms. - * @error: a #GError if an error occurred, %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_auth_service_query_mechanisms(). - */ - -/** - * signon_auth_service_query_mechanisms: - * @auth_service: the #SignonAuthService. - * @method: the name of the method whose mechanisms must be - * retrieved. - * @cb: (scope async): callback to be invoked. - * @user_data: user data. - * - * Lists all the available mechanisms. - */ -void -signon_auth_service_query_mechanisms (SignonAuthService *auth_service, - const gchar *method, - SignonQueryMechanismCb cb, - gpointer user_data) -{ - SignonAuthServicePrivate *priv; - - g_return_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service)); - g_return_if_fail (cb != NULL); - priv = SIGNON_AUTH_SERVICE_PRIV (auth_service); - - MechanismCbData *cb_data; - cb_data = g_slice_new (MechanismCbData); - cb_data->service = auth_service; - cb_data->cb = cb; - cb_data->userdata = user_data; - cb_data->method = g_strdup (method); - - sso_auth_service_call_query_mechanisms (priv->proxy, - method, - priv->cancellable, - auth_query_mechanisms_cb, - cb_data); -} - -static void -auth_query_identities_cb (GObject *object, GAsyncResult *res, - gpointer user_data) -{ - SsoAuthService *proxy = SSO_AUTH_SERVICE (object); - IdentityCbData *data = (IdentityCbData *) user_data; - GVariant *value = NULL; - GError *error = NULL; - GVariantIter iter; - GVariant *identity_var; - SignonIdentityList *identity_list = NULL; - - g_return_if_fail (data != NULL); - - sso_auth_service_call_query_identities_finish (proxy, - &value, - res, - &error); - - if (value && !error) - { - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "@a{sv}", &identity_var)) - { - identity_list = - g_list_append (identity_list, - signon_identity_info_new_from_variant (identity_var)); - g_variant_unref (identity_var); - } - } - (data->cb) - (data->service, identity_list, error, data->userdata); - - if (error) - g_error_free (error); - g_slice_free (IdentityCbData, data); -} - -/** - * SignonQueryIdentitiesCb: - * @auth_service: the #SignonAuthService. - * @identities: (transfer full): #GList based list of #SignonIdentityInfo. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_auth_service_query_identities(). - */ - -/** - * signon_auth_service_query_identities: - * @auth_service: the #SignonAuthService. - * @filter: filter variant dictionary based on #GHashTable. - * @application_context: application security context, can be %NULL. - * @cb: (scope async): callback to be invoked. - * @user_data: user data. - */ -void -signon_auth_service_query_identities (SignonAuthService *auth_service, - SignonIdentityFilter *filter, - const gchar *application_context, - SignonQueryIdentitiesCb cb, - gpointer user_data) -{ - SignonAuthServicePrivate *priv; - GVariantBuilder builder; - GHashTableIter iter; - const gchar *key; - GVariant *value; - GVariant *filter_var; - - g_return_if_fail (SIGNON_IS_AUTH_SERVICE (auth_service)); - g_return_if_fail (cb != NULL); - priv = SIGNON_AUTH_SERVICE_PRIV (auth_service); - - IdentityCbData *cb_data; - cb_data = g_slice_new (IdentityCbData); - cb_data->service = auth_service; - cb_data->cb = cb; - cb_data->userdata = user_data; - - g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - if (filter) - { - g_hash_table_iter_init (&iter, filter); - while (g_hash_table_iter_next (&iter, - (gpointer) &key, - (gpointer) &value)) - g_variant_builder_add (&builder, "{sv}", key, value); - } - filter_var = g_variant_builder_end (&builder); - - if (!application_context) - application_context = ""; - - sso_auth_service_call_query_identities (priv->proxy, - filter_var, - application_context, - priv->cancellable, - auth_query_identities_cb, - cb_data); -} - diff --git a/libsignon-glib/signon-auth-service.h b/libsignon-glib/signon-auth-service.h deleted file mode 100644 index 8c68aad..0000000 --- a/libsignon-glib/signon-auth-service.h +++ /dev/null @@ -1,104 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _SIGNON_AUTH_SERVICE_H_ -#define _SIGNON_AUTH_SERVICE_H_ - -#include - -G_BEGIN_DECLS - -#define SIGNON_TYPE_AUTH_SERVICE (signon_auth_service_get_type ()) -#define SIGNON_AUTH_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIGNON_TYPE_AUTH_SERVICE, SignonAuthService)) -#define SIGNON_AUTH_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIGNON_TYPE_AUTH_SERVICE, SignonAuthServiceClass)) -#define SIGNON_IS_AUTH_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIGNON_TYPE_AUTH_SERVICE)) -#define SIGNON_IS_AUTH_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_AUTH_SERVICE)) -#define SIGNON_AUTH_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_AUTH_SERVICE, SignonAuthServiceClass)) - -typedef struct _SignonAuthServiceClass SignonAuthServiceClass; -typedef struct _SignonAuthServicePrivate SignonAuthServicePrivate; -typedef struct _SignonAuthService SignonAuthService; - -/** - * SignonAuthServiceClass: - * - * Opaque struct. Use the accessor functions below. - */ -struct _SignonAuthServiceClass -{ - GObjectClass parent_class; -}; - -/** - * SignonAuthService: - * - * Opaque struct. Use the accessor functions below. - */ -struct _SignonAuthService -{ - GObject parent_instance; - SignonAuthServicePrivate *priv; -}; - -GType signon_auth_service_get_type (void) G_GNUC_CONST; - -typedef void (*SignonQueryMethodsCb) (SignonAuthService *auth_service, - gchar **methods, - const GError *error, - gpointer user_data); - -typedef void (*SignonQueryMechanismCb) (SignonAuthService *auth_service, - const gchar *method, - gchar **mechanisms, - const GError *error, - gpointer user_data); - -typedef GList SignonIdentityList; -typedef GHashTable SignonIdentityFilter; - -typedef void (*SignonQueryIdentitiesCb) (SignonAuthService *auth_service, - SignonIdentityList *identities, - const GError *error, - gpointer user_data); - -SignonAuthService *signon_auth_service_new (); - -void signon_auth_service_query_methods (SignonAuthService *auth_service, - SignonQueryMethodsCb cb, - gpointer user_data); - -void signon_auth_service_query_mechanisms (SignonAuthService *auth_service, - const gchar *method, - SignonQueryMechanismCb cb, - gpointer user_data); - -void signon_auth_service_query_identities (SignonAuthService *auth_service, - SignonIdentityFilter *filter, - const gchar *application_context, - SignonQueryIdentitiesCb cb, - gpointer user_data); - -G_END_DECLS - -#endif /* _SIGNON_AUTH_SERVICE_H_ */ diff --git a/libsignon-glib/signon-auth-session.c b/libsignon-glib/signon-auth-session.c deleted file mode 100644 index 83f4407..0000000 --- a/libsignon-glib/signon-auth-session.c +++ /dev/null @@ -1,917 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -/** - * SECTION:signon-auth-session - * @title: SignonAuthSession - * @short_description: Authentication session handler. - * - * The #SignonAuthSession object is responsible for handling the client - * authentication. #SignonAuthSession objects can be created from existing - * identities (via signon_identity_create_session() or by passing a non-zero ID - * to signon_auth_session_new()), in which case the authentication data such as - * username and password will be implicitly taken from the identity, or they - * can be created with no existing identity bound to them, in which case all - * the authentication data must be filled in by the client when - * signon_auth_session_process() is called. - */ - -#include "signon-internals.h" -#include "signon-auth-session.h" -#include "signon-dbus-queue.h" -#include "signon-errors.h" -#include "signon-marshal.h" -#include "signon-utils.h" -#include "signon-identity.h" -#include "sso-auth-service.h" -#include "sso-auth-session-gen.h" - - -G_DEFINE_TYPE (SignonAuthSession, signon_auth_session, G_TYPE_OBJECT); - -enum -{ - PROP_0, - PROP_IDENTITY, - PROP_APPCTX -}; - -/* Signals */ -enum -{ - STATE_CHANGED, - LAST_SIGNAL -}; - -static guint auth_session_signals[LAST_SIGNAL] = { 0 }; -static const gchar auth_session_process_pending_message[] = - "The request is added to queue."; -static const gchar data_key_process[] = "signon-process"; - -struct _SignonAuthSessionPrivate -{ - SsoAuthSession *proxy; - SignonIdentity *identity; - GCancellable *cancellable; - - guint id; - gchar *method_name; - - gboolean registering; - gboolean busy; - gboolean canceled; - gboolean dispose_has_run; - - guint signal_state_changed; - guint signal_unregistered; -}; - -typedef struct _AuthSessionQueryAvailableMechanismsData -{ - gchar **wanted_mechanisms; - gpointer cb_data; -} AuthSessionQueryAvailableMechanismsData; - -typedef struct _AuthSessionProcessData -{ - GVariant *session_data; - gchar *mechanism; - GCancellable *cancellable; -} AuthSessionProcessData; - -typedef struct _AuthSessionQueryAvailableMechanismsCbData -{ - SignonAuthSession *self; - SignonAuthSessionQueryAvailableMechanismsCb cb; - gpointer user_data; -} AuthSessionQueryAvailableMechanismsCbData; - -typedef struct _AuthSessionProcessCbData -{ - SignonAuthSessionProcessCb cb; - gpointer user_data; -} AuthSessionProcessCbData; - -#define SIGNON_AUTH_SESSION_PRIV(obj) (SIGNON_AUTH_SESSION(obj)->priv) -#define SIGNON_AUTH_SESSION_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionPrivate)) - - -static void auth_session_state_changed_cb (GDBusProxy *proxy, gint state, gchar *message, gpointer user_data); -static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, gpointer user_data); - -static gboolean auth_session_priv_init (SignonAuthSession *self, const gchar *method_name, GError **err); - -static void auth_session_query_available_mechanisms_ready_cb (gpointer object, const GError *error, gpointer user_data); -static void auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data); - -static void auth_session_check_remote_object(SignonAuthSession *self); - -static void -auth_session_process_data_free (AuthSessionProcessData *process_data) -{ - g_free (process_data->mechanism); - g_variant_unref (process_data->session_data); - g_slice_free (AuthSessionProcessData, process_data); -} - -static void -auth_session_process_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SignonAuthSession *self; - SsoAuthSession *proxy = SSO_AUTH_SESSION (object); - GSimpleAsyncResult *res_process = (GSimpleAsyncResult *)userdata; - GVariant *reply; - GError *error = NULL; - - g_return_if_fail (res_process != NULL); - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - sso_auth_session_call_process_finish (proxy, &reply, res, &error); - - self = SIGNON_AUTH_SESSION (g_async_result_get_source_object ( - (GAsyncResult *)res_process)); - self->priv->busy = FALSE; - - if (G_LIKELY (error == NULL)) - { - g_simple_async_result_set_op_res_gpointer (res_process, reply, - (GDestroyNotify) - g_variant_unref); - } - else - { - g_simple_async_result_take_error (res_process, error); - } - - /* We use the idle variant in order to avoid the following critical - * message: - * g_main_context_pop_thread_default: assertion `g_queue_peek_head (stack) == context' failed - */ - g_simple_async_result_complete_in_idle (res_process); - g_object_unref (res_process); - g_object_unref (self); -} - -static void -auth_session_process_ready_cb (gpointer object, const GError *error, gpointer user_data) -{ - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - SignonAuthSessionPrivate *priv; - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); - AuthSessionProcessData *process_data; - - g_return_if_fail (self != NULL); - priv = self->priv; - - if (error != NULL) - { - DEBUG ("AuthSessionError: %s", error->message); - g_simple_async_result_set_from_error (res, error); - g_simple_async_result_complete (res); - g_object_unref (res); - return; - } - - if (priv->canceled) - { - priv->busy = FALSE; - priv->canceled = FALSE; - g_simple_async_result_set_error (res, - signon_error_quark (), - SIGNON_ERROR_SESSION_CANCELED, - "Authentication session was canceled"); - g_simple_async_result_complete (res); - g_object_unref (res); - return; - } - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - process_data = g_object_get_data ((GObject *)res, data_key_process); - g_return_if_fail (process_data != NULL); - - sso_auth_session_call_process (priv->proxy, - process_data->session_data, - process_data->mechanism, - process_data->cancellable, - auth_session_process_reply, - res); -} - -static void -process_async_cb_wrapper (GObject *object, GAsyncResult *res, - gpointer user_data) -{ - AuthSessionProcessCbData *cb_data = user_data; - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - GVariant *v_reply; - GHashTable *reply = NULL; - GError *error = NULL; - gboolean cancelled; - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - v_reply = signon_auth_session_process_finish (self, res, &error); - - cancelled = error != NULL && - error->domain == G_IO_ERROR && - error->code == G_IO_ERROR_CANCELLED; - - /* Do not invoke the callback if the operation was cancelled */ - if (cb_data->cb != NULL && !cancelled) - { - if (v_reply != NULL) - reply = signon_hash_table_from_variant (v_reply); - - cb_data->cb (self, reply, error, cb_data->user_data); - } - g_variant_unref (v_reply); - - g_slice_free (AuthSessionProcessCbData, cb_data); - g_clear_error (&error); -} - -static GQuark -auth_session_object_quark () -{ - static GQuark quark = 0; - - if (!quark) - quark = g_quark_from_static_string ("auth_session_object_quark"); - - return quark; -} - -static void -signon_auth_session_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - - switch (property_id) - { - case PROP_IDENTITY: - self->priv->identity = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -signon_auth_session_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - - switch (property_id) - { - case PROP_IDENTITY: - g_value_set_object (value, self->priv->identity); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -signon_auth_session_init (SignonAuthSession *self) -{ - self->priv = SIGNON_AUTH_SESSION_GET_PRIV (self); - self->priv->cancellable = g_cancellable_new (); -} - -static void -signon_auth_session_dispose (GObject *object) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - if (priv->dispose_has_run) - return; - - if (priv->cancellable) - { - g_cancellable_cancel (priv->cancellable); - g_object_unref (priv->cancellable); - priv->cancellable = NULL; - } - - if (priv->proxy) - { - g_signal_handler_disconnect (priv->proxy, priv->signal_state_changed); - g_signal_handler_disconnect (priv->proxy, priv->signal_unregistered); - g_object_unref (priv->proxy); - - priv->proxy = NULL; - } - - G_OBJECT_CLASS (signon_auth_session_parent_class)->dispose (object); - - priv->dispose_has_run = TRUE; -} - -static void -signon_auth_session_finalize (GObject *object) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION(object)); - - SignonAuthSession *self = SIGNON_AUTH_SESSION(object); - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - g_free (priv->method_name); - g_object_unref (priv->identity); - - G_OBJECT_CLASS (signon_auth_session_parent_class)->finalize (object); -} - -static void -signon_auth_session_class_init (SignonAuthSessionClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - object_class->set_property = signon_auth_session_set_property; - object_class->get_property = signon_auth_session_get_property; - - pspec = g_param_spec_object ("identity", - "Identity Object", - "Identity Object construct parameter", - SIGNON_TYPE_IDENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, - PROP_IDENTITY, - pspec); - - g_type_class_add_private (object_class, sizeof (SignonAuthSessionPrivate)); - - /** - * SignonAuthSession::state-changed: - * @auth_session: the #SignonAuthSession - * @state: the current state of the #SignonAuthSession - * @message: the message associated with the state change - * - * Emitted when the state of the #SignonAuthSession changes. - */ - auth_session_signals[STATE_CHANGED] = - g_signal_new ("state-changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - 0, - NULL, - NULL, - _signon_marshal_VOID__INT_STRING, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_STRING); - - object_class->dispose = signon_auth_session_dispose; - object_class->finalize = signon_auth_session_finalize; -} - -/** - * signon_auth_session_new: - * @parent: #SignonIdentity parent object. - * @method_name: the name of the authentication method to be used. - * @err: a pointer to a location which will contain the error, in case this - * function fails. - * - * Creates a new #SignonAuthSession, which can be used to authenticate using - * the specified method. - * - * Returns: a new #SignonAuthSession. - */ -SignonAuthSession * -signon_auth_session_new (GObject *parent, - const gchar *method_name, - GError **err) -{ - if (!SIGNON_IS_IDENTITY(parent)) - { - g_set_error (err, - signon_error_quark(), - SIGNON_ERROR_UNKNOWN, - "Parent object is wrong type"); - return NULL; - } - SignonIdentity *identity = SIGNON_IDENTITY(parent); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - SignonAuthSession *self = SIGNON_AUTH_SESSION(g_object_new ( - SIGNON_TYPE_AUTH_SESSION, - "identity", identity, - NULL)); - g_return_val_if_fail (self != NULL, NULL); - - if (!auth_session_priv_init(self, method_name, err)) - { - if (*err) - g_warning ("%s returned error: %s", G_STRFUNC, (*err)->message); - - g_object_unref (self); - return NULL; - } - - return self; -} - -/** - * signon_auth_session_get_method: - * @self: the #SignonAuthSession. - * - * Get the current authentication method. - * - * Returns: the authentication method being used, or %NULL on failure. - */ -const gchar * -signon_auth_session_get_method (SignonAuthSession *self) -{ - g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), NULL); - SignonAuthSessionPrivate *priv = self->priv; - - g_return_val_if_fail (priv != NULL, NULL); - - return priv->method_name; -} - -/** - * SignonAuthSessionQueryAvailableMechanismsCb: - * @self: the #SignonAuthSession. - * @mechanisms: (transfer full) (type GStrv): list of available mechanisms. - * @error: a #GError if an error occurred, %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_auth_session_query_available_mechanisms(). - */ - -/** - * signon_auth_session_query_available_mechanisms: - * @self: the #SignonAuthSession. - * @wanted_mechanisms: a %NULL-terminated list of mechanisms supported by the client. - * @cb: (scope async): a callback which will be called with the result. - * @user_data: user data to be passed to the callback. - * - * Queries the mechanisms available for this authentication session. the result - * will be the intersection between @wanted_mechanisms and the mechanisms - * supported by the authentication plugin. - */ -void -signon_auth_session_query_available_mechanisms (SignonAuthSession *self, - const gchar **wanted_mechanisms, - SignonAuthSessionQueryAvailableMechanismsCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); - SignonAuthSessionPrivate* priv = self->priv; - - g_return_if_fail (priv != NULL); - - AuthSessionQueryAvailableMechanismsCbData *cb_data = g_slice_new0 (AuthSessionQueryAvailableMechanismsCbData); - cb_data->self = self; - cb_data->cb = cb; - cb_data->user_data = user_data; - - AuthSessionQueryAvailableMechanismsData *operation_data = g_slice_new0 (AuthSessionQueryAvailableMechanismsData); - operation_data->wanted_mechanisms = g_strdupv ((gchar **)wanted_mechanisms); - operation_data->cb_data = cb_data; - - auth_session_check_remote_object(self); - _signon_object_call_when_ready (self, - auth_session_object_quark(), - auth_session_query_available_mechanisms_ready_cb, - operation_data); -} - -/** - * SignonAuthSessionProcessCb: - * @self: the #SignonAuthSession. - * @session_data: (transfer full) (element-type utf8 GValue): a dictionary with - * the response. - * @error: a #GError if an error occurred, %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * This callback is invoked when the authentication plugin delivers the result - * of the signon_auth_session_process() operation. - */ - -/** - * signon_auth_session_process: - * @self: the #SignonAuthSession. - * @session_data: (transfer none) (element-type utf8 GValue): a dictionary of parameters. - * @mechanism: the authentication mechanism to be used. - * @cb: (scope async): a callback which will be called with the result. - * @user_data: user data to be passed to the callback. - * - * Performs one step of the authentication process. If the #SignonAuthSession - * object is bound to an existing identity, the identity properties such as - * username and password will be also passed to the authentication plugin, so - * there's no need to fill them into @session_data. - * @session_data can be used to add additional authentication parameters to the - * session, or to override the parameters otherwise taken from the identity. - * - * Deprecated: 1.8: Use signon_auth_session_process_async() instead. - */ -void -signon_auth_session_process (SignonAuthSession *self, - const GHashTable *session_data, - const gchar* mechanism, - SignonAuthSessionProcessCb cb, - gpointer user_data) -{ - GVariant *v_session_data; - - g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - AuthSessionProcessCbData *cb_data = g_slice_new0 (AuthSessionProcessCbData); - cb_data->cb = cb; - cb_data->user_data = user_data; - - v_session_data = signon_hash_table_to_variant (session_data); - - signon_auth_session_process_async (self, v_session_data, mechanism, NULL, - process_async_cb_wrapper, cb_data); -} - -/** - * signon_auth_session_process_async: - * @self: the #SignonAuthSession. - * @session_data: (transfer floating): a dictionary of parameters. - * @mechanism: the authentication mechanism to be used. - * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore. - * @callback: (scope async): a callback which will be called when the - * authentication reply is available. - * @user_data: user data to be passed to the callback. - * - * Performs one step of the authentication process. If the #SignonAuthSession - * object is bound to an existing identity, the identity properties such as - * username and password will be also passed to the authentication plugin, so - * there's no need to fill them into @session_data. - * @session_data can be used to add additional authentication parameters to the - * session, or to override the parameters otherwise taken from the identity. - * - * Since: 1.8 - */ -void -signon_auth_session_process_async (SignonAuthSession *self, - GVariant *session_data, - const gchar *mechanism, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SignonAuthSessionPrivate *priv; - AuthSessionProcessData *process_data; - GSimpleAsyncResult *res; - - g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); - priv = self->priv; - - g_return_if_fail (session_data != NULL); - - res = g_simple_async_result_new ((GObject *)self, callback, user_data, - signon_auth_session_process_async); - g_simple_async_result_set_check_cancellable (res, cancellable); - - process_data = g_slice_new0 (AuthSessionProcessData); - process_data->session_data = g_variant_ref_sink (session_data); - process_data->mechanism = g_strdup (mechanism); - process_data->cancellable = cancellable; - g_object_set_data_full ((GObject *)res, data_key_process, process_data, - (GDestroyNotify)auth_session_process_data_free); - - priv->busy = TRUE; - - auth_session_check_remote_object(self); - _signon_object_call_when_ready (self, - auth_session_object_quark(), - auth_session_process_ready_cb, - res); -} - -/** - * signon_auth_session_process_finish: - * @self: the #SignonAuthSession. - * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to - * signon_auth_session_process_async(). - * @error: return location for error, or %NULL. - * - * Collect the result of the signon_auth_session_process_async() operation. - * - * Returns: a #GVariant of type %G_VARIANT_TYPE_VARDICT containing the - * authentication reply. - * - * Since: 1.8 - */ -GVariant * -signon_auth_session_process_finish (SignonAuthSession *self, GAsyncResult *res, - GError **error) -{ - GSimpleAsyncResult *async_result; - GVariant *reply; - - g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), NULL); - - async_result = (GSimpleAsyncResult *)res; - if (g_simple_async_result_propagate_error (async_result, error)) - return NULL; - - reply = g_simple_async_result_get_op_res_gpointer (async_result); - return g_variant_ref (reply); -} - -/** - * signon_auth_session_cancel: - * @self: the #SignonAuthSession. - * - * Cancel the authentication session. - */ -void -signon_auth_session_cancel (SignonAuthSession *self) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); - SignonAuthSessionPrivate *priv = self->priv; - - g_return_if_fail (priv != NULL); - - auth_session_check_remote_object(self); - - if (!priv->busy) - return; - - priv->canceled = TRUE; - _signon_object_call_when_ready (self, - auth_session_object_quark(), - auth_session_cancel_ready_cb, - NULL); -} - -static void -auth_session_state_changed_cb (GDBusProxy *proxy, - gint state, - gchar *message, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (user_data)); - SignonAuthSession *self = SIGNON_AUTH_SESSION (user_data); - - g_signal_emit ((GObject *)self, - auth_session_signals[STATE_CHANGED], - 0, - state, - message); -} - -static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (user_data)); - SignonAuthSession *self = SIGNON_AUTH_SESSION (user_data); - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - DEBUG ("remote object unregistered"); - - if (priv->proxy) - { - g_object_unref (priv->proxy); - priv->proxy = NULL; - } - - /* - * as remote object is destroyed only - * when the session core is destroyed, - * so there should not be any processes - * running - * */ - priv->busy = FALSE; - priv->canceled = FALSE; - _signon_object_not_ready(self); -} - -static gboolean -auth_session_priv_init (SignonAuthSession *self, - const gchar *method_name, GError **err) -{ - g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), FALSE); - SignonAuthSessionPrivate *priv = SIGNON_AUTH_SESSION_PRIV (self); - g_return_val_if_fail (priv, FALSE); - - priv->method_name = g_strdup (method_name); - - priv->registering = FALSE; - priv->busy = FALSE; - priv->canceled = FALSE; - return TRUE; -} - -static void -auth_session_query_mechanisms_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SsoAuthSession *proxy = SSO_AUTH_SESSION (object); - gchar **mechanisms = NULL; - GError *error = NULL; - AuthSessionQueryAvailableMechanismsCbData *cb_data = - (AuthSessionQueryAvailableMechanismsCbData *)userdata; - g_return_if_fail (cb_data != NULL); - - sso_auth_session_call_query_available_mechanisms_finish (proxy, - &mechanisms, - res, - &error); - if (SIGNON_IS_NOT_CANCELLED (error)) - { - (cb_data->cb) (cb_data->self, mechanisms, error, cb_data->user_data); - } - - g_clear_error (&error); - g_slice_free (AuthSessionQueryAvailableMechanismsCbData, cb_data); -} - -static void -auth_session_query_available_mechanisms_ready_cb (gpointer object, const GError *error, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - AuthSessionQueryAvailableMechanismsData *operation_data = - (AuthSessionQueryAvailableMechanismsData *)user_data; - g_return_if_fail (operation_data != NULL); - - AuthSessionQueryAvailableMechanismsCbData *cb_data = operation_data->cb_data; - g_return_if_fail (cb_data != NULL); - - if (error) - { - (cb_data->cb) - (self, NULL, error, cb_data->user_data); - - g_slice_free (AuthSessionQueryAvailableMechanismsCbData, cb_data); - } - else - { - g_return_if_fail (priv->proxy != NULL); - sso_auth_session_call_query_available_mechanisms ( - priv->proxy, - (const char **)operation_data->wanted_mechanisms, - priv->cancellable, - auth_session_query_mechanisms_reply, - cb_data); - - g_signal_emit (self, - auth_session_signals[STATE_CHANGED], - 0, - SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, - auth_session_process_pending_message); - } - - g_strfreev (operation_data->wanted_mechanisms); - g_slice_free (AuthSessionQueryAvailableMechanismsData, operation_data); -} - -static void -auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); - g_return_if_fail (user_data == NULL); - - SignonAuthSession *self = SIGNON_AUTH_SESSION (object); - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - if (error) - { - //TODO: in general this function does not return any values, - // that is why I think it should not emit anything for this particular case - DEBUG("error during initialization"); - } - else if (priv->proxy && priv->busy) - sso_auth_session_call_cancel_sync (priv->proxy, - priv->cancellable, - NULL); - - priv->busy = FALSE; - priv->canceled = FALSE; -} - -static void -signon_auth_session_complete (SignonAuthSession *self, - GError *error, - GDBusConnection *connection, - const gchar *bus_name, - const gchar *object_path) -{ - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - priv->registering = FALSE; - if (!g_strcmp0(object_path, "") || error) - { - if (error) - DEBUG ("Error message is %s", error->message); - else - error = g_error_new (signon_error_quark(), - SIGNON_ERROR_RUNTIME, - "Cannot create remote AuthSession object"); - } - else - { - GError *proxy_error = NULL; - - priv->proxy = - sso_auth_session_proxy_new_sync (connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - bus_name, - object_path, - priv->cancellable, - &proxy_error); - if (G_UNLIKELY (proxy_error != NULL)) - { - g_warning ("Failed to initialize AuthSession proxy: %s", - proxy_error->message); - g_clear_error (&proxy_error); - } - - g_dbus_proxy_set_default_timeout ((GDBusProxy *)priv->proxy, - G_MAXINT); - - priv->signal_state_changed = - g_signal_connect (priv->proxy, - "state-changed", - G_CALLBACK (auth_session_state_changed_cb), - self); - - priv->signal_unregistered = - g_signal_connect (priv->proxy, - "unregistered", - G_CALLBACK (auth_session_remote_object_destroyed_cb), - self); - } - - DEBUG ("Object path received: %s", object_path); - _signon_object_ready (self, auth_session_object_quark (), error); -} - -static void -auth_session_check_remote_object(SignonAuthSession *self) -{ - g_return_if_fail (self != NULL); - SignonAuthSessionPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - if (priv->proxy != NULL) - return; - - g_return_if_fail (priv->identity != NULL); - - if (!priv->registering) - { - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - priv->registering = TRUE; - signon_identity_get_auth_session (priv->identity, - self, - priv->method_name, - signon_auth_session_complete); - - } -} - diff --git a/libsignon-glib/signon-auth-session.h b/libsignon-glib/signon-auth-session.h deleted file mode 100644 index 66bca20..0000000 --- a/libsignon-glib/signon-auth-session.h +++ /dev/null @@ -1,194 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef SIGNONAUTHSESSION_H_ -#define SIGNONAUTHSESSION_H_ - -#include -#include -#include - -G_BEGIN_DECLS - -/* - * Useful session data keys - */ -/** - * SIGNON_SESSION_DATA_USERNAME: - * - * Username. - */ -#define SIGNON_SESSION_DATA_USERNAME "UserName" -/** - * SIGNON_SESSION_DATA_SECRET: - * - * Secret. - */ -#define SIGNON_SESSION_DATA_SECRET "Secret" -/** - * SIGNON_SESSION_DATA_REALM: - * - * Realm. - */ -#define SIGNON_SESSION_DATA_REALM "Realm" -/** - * SIGNON_SESSION_DATA_PROXY: - * - * Proxy. - */ -#define SIGNON_SESSION_DATA_PROXY "NetworkProxy" - -/** - * SignonSessionDataUiPolicy: - * @SIGNON_POLICY_DEFAULT: The plugin can decide when to show UI. - * @SIGNON_POLICY_REQUEST_PASSWORD: Force the user to enter the password. - * @SIGNON_POLICY_NO_USER_INTERACTION: No UI elements will be shown to the user. - * @SIGNON_POLICY_VALIDATION: UI elements can be shown to the user only when - * CAPTCHA-like security measures are required. - * - * Policy for the signon process, passed to the UI plugin. - */ -typedef enum { - SIGNON_POLICY_DEFAULT = 0, - SIGNON_POLICY_REQUEST_PASSWORD, - SIGNON_POLICY_NO_USER_INTERACTION, - SIGNON_POLICY_VALIDATION, -} SignonSessionDataUiPolicy; -/** - * SIGNON_SESSION_DATA_UI_POLICY: - * @see_also: #SignonSessionDataUiPolicy - * - * Policy for the signon process. - */ -#define SIGNON_SESSION_DATA_UI_POLICY "UiPolicy" -/** - * SIGNON_SESSION_DATA_CAPTION: - * - * Caption for the UI dialog. - */ -#define SIGNON_SESSION_DATA_CAPTION "Caption" -/** - * SIGNON_SESSION_DATA_TIMEOUT: - * - * Network timeout, in milliseconds (uint32). - */ -#define SIGNON_SESSION_DATA_TIMEOUT "NetworkTimeout" -/** - * SIGNON_SESSION_DATA_WINDOW_ID: - * - * Platform-specific window id (for dialog transiency) - uint32. - */ -#define SIGNON_SESSION_DATA_WINDOW_ID "WindowId" -/** - * SIGNON_SESSION_DATA_RENEW_TOKEN: - * - * Requests the signon plugin to obtain a new token (boolean). - */ -#define SIGNON_SESSION_DATA_RENEW_TOKEN "RenewToken" - - -#define SIGNON_TYPE_AUTH_SESSION (signon_auth_session_get_type ()) -#define SIGNON_AUTH_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSession)) -#define SIGNON_AUTH_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionClass)) -#define SIGNON_IS_AUTH_SESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIGNON_TYPE_AUTH_SESSION)) -#define SIGNON_IS_AUTH_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_AUTH_SESSION)) -#define SIGNON_AUTH_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_AUTH_SESSION, SignonAuthSessionClass)) - -typedef struct _SignonAuthSession SignonAuthSession; -typedef struct _SignonAuthSessionPrivate SignonAuthSessionPrivate; -typedef struct _SignonAuthSessionClass SignonAuthSessionClass; - -/** - * SignonAuthSession: - * - * Opaque struct. Use the accessor functions below. - */ -struct _SignonAuthSession { - GObject parent; - - SignonAuthSessionPrivate *priv; -}; - -/** - * SignonAuthSessionClass: - * - * Opaque struct. Use the accessor functions below. - */ -struct _SignonAuthSessionClass { - GObjectClass parent; -}; - -GType signon_auth_session_get_type (void) G_GNUC_CONST; - -SignonAuthSession *signon_auth_session_new(GObject *parent, - const gchar *method_name, - GError **err); - -const gchar *signon_auth_session_get_method (SignonAuthSession *self); - -typedef void (*SignonAuthSessionQueryAvailableMechanismsCb) ( - SignonAuthSession* self, - gchar **mechanisms, - const GError *error, - gpointer user_data); - -G_GNUC_DEPRECATED -typedef SignonAuthSessionQueryAvailableMechanismsCb - SignonAuthSessionQueryAvailableMethodsCb; - -void signon_auth_session_query_available_mechanisms(SignonAuthSession *self, - const gchar **wanted_mechanisms, - SignonAuthSessionQueryAvailableMechanismsCb cb, - gpointer user_data); - -#ifndef SIGNON_DISABLE_DEPRECATED -typedef void (*SignonAuthSessionProcessCb) (SignonAuthSession *self, - GHashTable *session_data, - const GError *error, - gpointer user_data); -SIGNON_DEPRECATED_FOR(signon_auth_session_process_async) -void signon_auth_session_process(SignonAuthSession *self, - const GHashTable *session_data, - const gchar *mechanism, - SignonAuthSessionProcessCb cb, - gpointer user_data); -#endif -void signon_auth_session_process_async (SignonAuthSession *self, - GVariant *session_data, - const gchar *mechanism, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GVariant *signon_auth_session_process_finish (SignonAuthSession *self, - GAsyncResult *res, - GError **error); - -void signon_auth_session_cancel(SignonAuthSession *self); - -G_END_DECLS - -#endif //SIGNONAUTHSESSIONIMPL_H_ diff --git a/libsignon-glib/signon-dbus-queue.c b/libsignon-glib/signon-dbus-queue.c deleted file mode 100644 index f70714d..0000000 --- a/libsignon-glib/signon-dbus-queue.c +++ /dev/null @@ -1,169 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "signon-dbus-queue.h" - -typedef struct { - SignonReadyCb callback; - gpointer user_data; -} SignonReadyCbData; - -typedef struct { - gpointer self; - GSList *callbacks; -} SignonReadyData; - -static GQuark -_signon_object_ready_quark() -{ - static GQuark quark = 0; - - if (!quark) - quark = g_quark_from_static_string ("signon_object_ready_quark"); - - return quark; -} - -static GQuark -_signon_object_error_quark() -{ - static GQuark quark = 0; - - if (!quark) - quark = g_quark_from_static_string ("signon_object_error_quark"); - - return quark; -} - -static void -signon_object_invoke_ready_callbacks (SignonReadyData *rd, const GError *error) -{ - GSList *list; - - for (list = rd->callbacks; list != NULL; list = list->next) - { - SignonReadyCbData *cb = list->data; - - cb->callback (rd->self, error, cb->user_data); - g_slice_free (SignonReadyCbData, cb); - } - g_slist_free (rd->callbacks); -} - -static void -signon_ready_data_free (SignonReadyData *rd) -{ - if (rd->self) - { - //TODO: Signon error codes need be presented instead of 555 and 666 - GError error = { 555, 666, "Object disposed" }; - signon_object_invoke_ready_callbacks (rd, &error); - } - g_slice_free (SignonReadyData, rd); -} - -void -_signon_object_call_when_ready (gpointer object, GQuark quark, SignonReadyCb callback, - gpointer user_data) -{ - SignonReadyData *rd; - SignonReadyCbData *cb; - - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (quark != 0); - g_return_if_fail (callback != NULL); - - if (GPOINTER_TO_INT (g_object_get_qdata((GObject *)object, - _signon_object_ready_quark())) == TRUE) - { - //TODO: specify the last error in object initialization - GError * err = g_object_get_qdata((GObject *)object, - _signon_object_error_quark()); - return (*callback)(object, err, user_data); - } - - cb = g_slice_new (SignonReadyCbData); - cb->callback = callback; - cb->user_data = user_data; - - rd = g_object_get_qdata ((GObject *)object, quark); - if (!rd) - { - rd = g_slice_new (SignonReadyData); - rd->self = object; - rd->callbacks = NULL; - g_object_set_qdata_full ((GObject *)object, quark, rd, - (GDestroyNotify)signon_ready_data_free); - } - - rd->callbacks = g_slist_append (rd->callbacks, cb); -} - -void -_signon_object_ready (gpointer object, GQuark quark, const GError *error) -{ - SignonReadyData *rd; - - g_object_set_qdata((GObject *)object, _signon_object_ready_quark(), GINT_TO_POINTER(TRUE)); - - if(error) - g_object_set_qdata_full ((GObject *)object, _signon_object_error_quark(), - g_error_copy(error), - (GDestroyNotify)g_error_free); - - /* steal the qdata so the callbacks won't be invoked again, even if the - * object becomes ready or is finalized while still invoking them */ - - rd = g_object_steal_qdata ((GObject *)object, quark); - if (!rd) return; - - g_object_ref (object); - - signon_object_invoke_ready_callbacks (rd, error); - rd->self = NULL; /* so the callbacks won't be invoked again */ - signon_ready_data_free (rd); - - g_object_unref (object); - - //TODO: set some sort of ready information -} - -void -_signon_object_not_ready (gpointer object) -{ - g_object_set_qdata ((GObject *)object, - _signon_object_ready_quark(), - GINT_TO_POINTER(FALSE)); - - g_object_set_qdata ((GObject *)object, - _signon_object_error_quark(), - NULL); -} - -const GError * -_signon_object_last_error (gpointer object) -{ - return g_object_get_qdata((GObject *)object, - _signon_object_error_quark()); -} diff --git a/libsignon-glib/signon-dbus-queue.h b/libsignon-glib/signon-dbus-queue.h deleted file mode 100644 index 62b0ddf..0000000 --- a/libsignon-glib/signon-dbus-queue.h +++ /dev/null @@ -1,45 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef SIGNONDBUSQUEUEDDATA_H -#define SIGNONDBUSQUEUEDDATA_H - -#include -#include - -G_BEGIN_DECLS - -typedef void (*SignonReadyCb) (gpointer object, const GError *error, - gpointer user_data); - -void _signon_object_call_when_ready (gpointer object, GQuark quark, - SignonReadyCb callback, gpointer user_data); - -void _signon_object_ready (gpointer object, GQuark quark, const GError *error); -void _signon_object_not_ready (gpointer object); - -const GError *_signon_object_last_error (gpointer object); - -G_END_DECLS -#endif /* SIGNONDBUSQUEUEDDATA_H */ diff --git a/libsignon-glib/signon-errors.c b/libsignon-glib/signon-errors.c deleted file mode 100644 index f66e66f..0000000 --- a/libsignon-glib/signon-errors.c +++ /dev/null @@ -1,53 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * Copyright (C) 2012 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "signon-errors.h" -#include "signon-enum-types.h" -#include "signon-internals.h" -#include - -/** - * SECTION:signon-errors - * @title: SignonError - * @short_description: Possible errors from Signon. - * - * An enumeration of errors that are possible from Signon. - */ -#define SIGNON_ERROR_PREFIX SIGNOND_SERVICE_PREFIX ".Error" - -#include "signon-errors-map.c" - -GQuark signon_error_quark (void) -{ - static volatile gsize quark = 0; - - g_dbus_error_register_error_domain ("gsignond", - &quark, - signon_error_entries, - G_N_ELEMENTS (signon_error_entries)); - return (GQuark) quark; -} diff --git a/libsignon-glib/signon-errors.h b/libsignon-glib/signon-errors.h deleted file mode 100644 index 2d0ff07..0000000 --- a/libsignon-glib/signon-errors.h +++ /dev/null @@ -1,129 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef __LIBSIGNON_ERRORS_H__ -#define __LIBSIGNON_ERRORS_H__ - -#include -#include -#include "signon-enum-types.h" - -#define SIGNON_ERROR (signon_error_quark()) - -/** - * SignonError: - * @SIGNON_ERROR_UNKNOWN: Catch-all for errors not distinguished by another code. - * @SIGNON_ERROR_INTERNAL_SERVER: Signon daemon internal error. - * @SIGNON_ERROR_INTERNAL_COMMUNICATION: Error communicating with Sigon daemon. - * @SIGNON_ERROR_PERMISSION_DENIED: The operation cannot be performed due to - * insufficient client permissions. - * @SIGNON_ERROR_METHOD_NOT_KNOWN: The method with this name was not found. - * @SIGNON_ERROR_SERVICE_NOT_AVAILABLE: The service is temporarily unavailable. - * @SIGNON_ERROR_INVALID_QUERY: Parameters for the query are invalid. - * @SIGNON_ERROR_METHOD_NOT_AVAILABLE: The requested method is not available. - * @SIGNON_ERROR_IDENTITY_NOT_FOUND: The identity mathching the #SignonIdentity - * was not found on the service. - * @SIGNON_ERROR_STORE_FAILED: Storing credentials failed. - * @SIGNON_ERROR_REMOVE_FAILED: Removing credentials failed. - * @SIGNON_ERROR_SIGNOUT_FAILED: Signing out failed. - * @SIGNON_ERROR_IDENTITY_OPERATION_CANCELED: Identity operation was canceled - * by the user. - * @SIGNON_ERROR_CREDENTIALS_NOT_AVAILABLE: Query failed. - * @SIGNON_ERROR_REFERENCE_NOT_FOUND: Trying to remove non-existent reference. - * @SIGNON_ERROR_MECHANISM_NOT_AVAILABLE: The requested mechanism in not - * available. - * @SIGNON_ERROR_MISSING_DATA: The #SessionData does not contain the necessary - * information. - * @SIGNON_ERROR_INVALID_CREDENTIALS: The supplied credentials are invalid for - * the mechanism implementation. - * @SIGNON_ERROR_NOT_AUTHORIZED: Authorization failed. - * @SIGNON_ERROR_WRONG_STATE: An operation method has been called in an - * incorrect state. - * @SIGNON_ERROR_OPERATION_NOT_SUPPORTED: The operation is not supported by the - * mechanism implementation. - * @SIGNON_ERROR_NO_CONNECTION: No network connection. - * @SIGNON_ERROR_NETWORK: Network connection failed. - * @SIGNON_ERROR_SSL: SSL connection failed. - * @SIGNON_ERROR_RUNTIME: Casting #SessionData into subclass failed. - * @SIGNON_ERROR_SESSION_CANCELED: Challenge was canceled. - * @SIGNON_ERROR_TIMED_OUT: Challenge timed out. - * @SIGNON_ERROR_USER_INTERACTION: User interaction dialog failed. - * @SIGNON_ERROR_OPERATION_FAILED: Temporary failure in authentication. - * @SIGNON_ERROR_ENCRYPTION_FAILED: @deprecated: Failure during data - * encryption/decryption. - * @SIGNON_ERROR_TOS_NOT_ACCEPTED: User declined Terms of Service. - * @SIGNON_ERROR_FORGOT_PASSWORD: User requested password reset sequence. - * @SIGNON_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED: Method or mechanism not - * allowed for this identity. - * @SIGNON_ERROR_INCORRECT_DATE: Date/time incorrect on device. - * @SIGNON_ERROR_USER_ERROR: Placeholder to rearrange enumeration - userspace - * specific. - * - * Possible Signon errors. - */ -typedef enum { - SIGNON_ERROR_UNKNOWN = 1, - SIGNON_ERROR_INTERNAL_SERVER = 2, - SIGNON_ERROR_INTERNAL_COMMUNICATION = 3, - SIGNON_ERROR_PERMISSION_DENIED = 4, - - SIGNON_ERROR_METHOD_NOT_KNOWN = 101, - SIGNON_ERROR_SERVICE_NOT_AVAILABLE, - SIGNON_ERROR_INVALID_QUERY, - - SIGNON_ERROR_METHOD_NOT_AVAILABLE = 201, - SIGNON_ERROR_IDENTITY_NOT_FOUND, - SIGNON_ERROR_STORE_FAILED, - SIGNON_ERROR_REMOVE_FAILED, - SIGNON_ERROR_SIGNOUT_FAILED, - SIGNON_ERROR_IDENTITY_OPERATION_CANCELED, - SIGNON_ERROR_CREDENTIALS_NOT_AVAILABLE, - SIGNON_ERROR_REFERENCE_NOT_FOUND, - - SIGNON_ERROR_MECHANISM_NOT_AVAILABLE = 301, - SIGNON_ERROR_MISSING_DATA, - SIGNON_ERROR_INVALID_CREDENTIALS, - SIGNON_ERROR_NOT_AUTHORIZED, - SIGNON_ERROR_WRONG_STATE, - SIGNON_ERROR_OPERATION_NOT_SUPPORTED, - SIGNON_ERROR_NO_CONNECTION, - SIGNON_ERROR_NETWORK, - SIGNON_ERROR_SSL, - SIGNON_ERROR_RUNTIME, - SIGNON_ERROR_SESSION_CANCELED, - SIGNON_ERROR_TIMED_OUT, - SIGNON_ERROR_USER_INTERACTION, - SIGNON_ERROR_OPERATION_FAILED, - SIGNON_ERROR_ENCRYPTION_FAILED, - SIGNON_ERROR_TOS_NOT_ACCEPTED, - SIGNON_ERROR_FORGOT_PASSWORD, - SIGNON_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED, - SIGNON_ERROR_INCORRECT_DATE, - SIGNON_ERROR_USER_ERROR = 400 -} SignonError; - -GQuark signon_error_quark (void); - - -#endif diff --git a/libsignon-glib/signon-glib.h b/libsignon-glib/signon-glib.h deleted file mode 100644 index 02b84bc..0000000 --- a/libsignon-glib/signon-glib.h +++ /dev/null @@ -1,35 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2011 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef SIGNON_GLIB_H -#define SIGNON_GLIB_H - -#include -#include -#include -#include -#include -#include - -#endif /* SIGNON_GLIB_H */ diff --git a/libsignon-glib/signon-identity-info.c b/libsignon-glib/signon-identity-info.c deleted file mode 100644 index 905b6cc..0000000 --- a/libsignon-glib/signon-identity-info.c +++ /dev/null @@ -1,680 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2011-2012 Canonical Ltd. - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -/** - * SECTION:signon-identity-info - * @title: SignonIdentityInfo - * @short_description: Extra data for a #SignonIdentity. - * - * Extra data retreived from a #SignonIdentity. - */ - -#include "signon-identity-info.h" - -#include "signon-internals.h" -#include "signon-utils.h" - -G_DEFINE_BOXED_TYPE (SignonIdentityInfo, signon_identity_info, - (GBoxedCopyFunc)signon_identity_info_copy, - (GBoxedFreeFunc)signon_identity_info_free); - - -static GVariant * -signon_variant_new_string (const gchar *string) -{ - return g_variant_new_string (string != NULL ? string : ""); -} - -static const gchar *identity_info_get_secret (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - - return info->secret; -} - -static void identity_info_set_id (SignonIdentityInfo *info, gint id) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (id >= 0); - - info->id = id; -} - -static void identity_methods_copy (gpointer key, gpointer value, gpointer user_data) -{ - signon_identity_info_set_method ((SignonIdentityInfo *)user_data, - (const gchar *)key, - (const gchar* const *)value); -} - -/** - * signon_identity_info_set_methods: - * @info: the #SignonIdentityInfo. - * @methods: (transfer none) (element-type utf8 GStrv): methods. - * - * Set allowed methods. - * Mechanisms are method-specific functions. - */ -void signon_identity_info_set_methods (SignonIdentityInfo *info, - const GHashTable *methods) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (methods != NULL); - - DEBUG("%s", G_STRFUNC); - - if (info->methods) - g_hash_table_remove_all (info->methods); - else - info->methods = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify)g_strfreev); - - g_hash_table_foreach ((GHashTable *)methods, identity_methods_copy, info); -} - -SignonIdentityInfo * -signon_identity_info_new_from_variant (GVariant *variant) -{ - GVariant *method_map; - GVariant *owner; - GVariant *acl; - - if (!variant) - return NULL; - - SignonIdentityInfo *info = signon_identity_info_new (); - - DEBUG("%s: ", G_STRFUNC); - - g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_ID, - "u", - &info->id); - - g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_USERNAME, - "s", - &info->username); - - if (g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_SECRET, - "s", - &info->secret)) - { - g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_STORESECRET, - "b", - &info->store_secret); - } - - g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_CAPTION, - "s", - &info->caption); - - g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_REALMS, - "^as", - &info->realms); - - /* get the methods */ - if (g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_AUTHMETHODS, - "@a{sas}", - &method_map)) - { - GVariantIter iter; - gchar *method; - gchar **mechanisms; - - g_variant_iter_init (&iter, method_map); - while (g_variant_iter_next (&iter, "{s^as}", &method, &mechanisms)) - { - g_hash_table_insert (info->methods, method, mechanisms); - } - g_variant_unref (method_map); - } - - if (g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_OWNER, - "@(ss)", - &owner)) - { - info->owner = signon_security_context_deconstruct_variant (owner); - g_variant_unref (owner); - } - - if (g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_ACL, - "@a(ss)", - &acl)) - { - info->access_control_list = - signon_security_context_list_deconstruct_variant (acl); - g_variant_unref (acl); - } - - g_variant_lookup (variant, - SIGNOND_IDENTITY_INFO_TYPE, - "u", - &info->type); - - return info; -} - -GVariant * -signon_identity_info_to_variant (const SignonIdentityInfo *self) -{ - GVariantBuilder builder; - GVariantBuilder method_builder; - GVariant *method_map; - GHashTableIter iter; - const gchar *method; - const gchar **mechanisms; - - g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_ID, - g_variant_new_uint32 (self->id)); - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_USERNAME, - signon_variant_new_string (self->username)); - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_SECRET, - signon_variant_new_string (self->secret)); - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_CAPTION, - signon_variant_new_string (self->caption)); - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_STORESECRET, - g_variant_new_boolean (self->store_secret)); - - g_variant_builder_init (&method_builder, - (const GVariantType *)"a{sas}"); - g_hash_table_iter_init (&iter, self->methods); - while (g_hash_table_iter_next (&iter, - (gpointer)&method, - (gpointer)&mechanisms)) - { - g_variant_builder_add (&method_builder, "{s^as}", - method, - mechanisms); - } - method_map = g_variant_builder_end (&method_builder); - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_AUTHMETHODS, - method_map); - - if (self->realms != NULL) - { - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_REALMS, - g_variant_new_strv ((const gchar * const *) - self->realms, - -1)); - } - - if (self->owner != NULL) - { - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_OWNER, - signon_security_context_build_variant ( - self->owner)); - } - - if (self->access_control_list != NULL) - { - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_ACL, - signon_security_context_list_build_variant ( - self->access_control_list)); - } - - g_variant_builder_add (&builder, "{sv}", - SIGNOND_IDENTITY_INFO_TYPE, - g_variant_new_int32 (self->type)); - - return g_variant_builder_end (&builder); -} - -/* - * Public methods: - */ - -/** - * signon_identity_info_new: - * - * Creates a new #SignonIdentityInfo item. - * - * Returns: a new #SignonIdentityInfo item. - */ -SignonIdentityInfo *signon_identity_info_new () -{ - SignonIdentityInfo *info = g_slice_new0 (SignonIdentityInfo); - info->methods = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify)g_strfreev); - info->store_secret = FALSE; - - return info; -} - -/** - * signon_identity_info_free: - * @info: the #SignonIdentityInfo. - * - * Destroys the given #SignonIdentityInfo item. - */ -void signon_identity_info_free (SignonIdentityInfo *info) -{ - if (info == NULL) return; - - g_free (info->username); - g_free (info->secret); - g_free (info->caption); - - g_hash_table_destroy (info->methods); - - g_strfreev (info->realms); - signon_security_context_free (info->owner); - signon_security_context_list_free (info->access_control_list); - - g_slice_free (SignonIdentityInfo, info); -} - -/** - * signon_identity_info_copy: - * @other: the #SignonIdentityInfo. - * - * Get a newly-allocated copy of @info. - * - * Returns: a copy of the given #SignonIdentityInfo, or %NULL on failure. - */ -SignonIdentityInfo *signon_identity_info_copy (const SignonIdentityInfo *other) -{ - g_return_val_if_fail (other != NULL, NULL); - SignonIdentityInfo *info = signon_identity_info_new (); - - identity_info_set_id (info, signon_identity_info_get_id (other)); - - signon_identity_info_set_username (info, - signon_identity_info_get_username (other)); - - signon_identity_info_set_secret (info, identity_info_get_secret(other), - signon_identity_info_get_storing_secret (other)); - - signon_identity_info_set_caption (info, - signon_identity_info_get_caption(other)); - - signon_identity_info_set_methods (info, - signon_identity_info_get_methods (other)); - - signon_identity_info_set_realms (info, - signon_identity_info_get_realms (other)); - - signon_identity_info_set_owner (info, - signon_identity_info_get_owner (other)); - - signon_identity_info_set_access_control_list (info, - signon_identity_info_get_access_control_list (other)); - - signon_identity_info_set_identity_type (info, - signon_identity_info_get_identity_type (other)); - - return info; -} - -/** - * signon_identity_info_get_id: - * @info: the #SignonIdentityInfo. - * - * Get the numeric ID of @info. - * - * Returns: the numeric ID of the identity. - */ -gint signon_identity_info_get_id (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, -1); - return info->id; -} - -/** - * signon_identity_info_get_username: - * @info: the #SignonIdentityInfo. - * - * Get the username of @info. - * - * Returns: the username, or %NULL. - */ -const gchar *signon_identity_info_get_username (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - return info->username; -} - -/** - * signon_identity_info_get_storing_secret: - * @info: the #SignonIdentityInfo. - * - * Get whether the secret of @info should be stored. - * - * Returns: %TRUE if Signon must store the secret, %FALSE otherwise. - */ -gboolean signon_identity_info_get_storing_secret (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, FALSE); - return info->store_secret; -} - -/** - * signon_identity_info_get_caption: - * @info: the #SignonIdentityInfo. - * - * Get the display name of @info. - * - * Returns: the display name for the identity. - */ -const gchar *signon_identity_info_get_caption (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - return info->caption; -} - -/** - * signon_identity_info_get_methods: - * @info: the #SignonIdentityInfo. - * - * Get a hash table of the methods and mechanisms of @info. - * - * Returns: (transfer none) (element-type utf8 GStrv): the table of allowed - * methods and mechanisms. - */ -const GHashTable *signon_identity_info_get_methods (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - return info->methods; -} - -/** - * signon_identity_info_get_realms: - * @info: the #SignonIdentityInfo. - * - * Get an array of the realms of @info. - * - * Returns: (transfer none): a %NULL terminated array of realms. - */ -const gchar* const *signon_identity_info_get_realms (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - return (const gchar* const *)info->realms; -} - -/** - * signon_identity_info_get_owner: - * @info: the #SignonIdentityInfo. - * - * Get owner security context of @info. - * - * Returns: (transfer none): a security context. - */ -const SignonSecurityContext *signon_identity_info_get_owner (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - return info->owner; -} - -/** - * signon_identity_info_get_access_control_list: - * @info: the #SignonIdentityInfo. - * - * Get an array of ACL statements of the identity. - * - * Returns: (transfer none): a list of ACL security contexts. - */ -const SignonSecurityContextList *signon_identity_info_get_access_control_list (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, NULL); - return info->access_control_list; -} - -/** - * signon_identity_info_get_identity_type: - * @info: the #SignonIdentityInfo. - * - * Get the type of the identity. - * - * Returns: the type of the identity. - */ -SignonIdentityType signon_identity_info_get_identity_type (const SignonIdentityInfo *info) -{ - g_return_val_if_fail (info != NULL, -1); - return (SignonIdentityType)info->type; -} - -/** - * signon_identity_info_set_username: - * @info: the #SignonIdentityInfo. - * @username: the username. - * - * Sets the username for the identity. - */ -void signon_identity_info_set_username (SignonIdentityInfo *info, const gchar *username) -{ - g_return_if_fail (info != NULL); - - if (info->username) g_free (info->username); - - info->username = g_strdup (username); -} - -/** - * signon_identity_info_set_secret: - * @info: the #SignonIdentityInfo. - * @secret: the secret. - * @store_secret: whether signond should store the secret in its DB. - * - * Sets the secret (password) for the identity, and whether the signon daemon - * should remember it. - */ -void signon_identity_info_set_secret (SignonIdentityInfo *info, const gchar *secret, - gboolean store_secret) -{ - g_return_if_fail (info != NULL); - - if (info->secret) g_free (info->secret); - - info->secret = g_strdup (secret); - info->store_secret = store_secret; -} - -/** - * signon_identity_info_set_caption: - * @info: the #SignonIdentityInfo. - * @caption: the caption. - * - * Sets the caption (display name) for the identity. - */ -void signon_identity_info_set_caption (SignonIdentityInfo *info, const gchar *caption) -{ - g_return_if_fail (info != NULL); - - if (info->caption) g_free (info->caption); - - info->caption = g_strdup (caption); -} - -/** - * signon_identity_info_set_method: - * @info: the #SignonIdentityInfo. - * @method: an authentication method. - * @mechanisms: a %NULL-termianted list of mechanisms. - * - * Adds a method to the list of allowed methods. - * Mechanisms are method-specific functions. - */ -void signon_identity_info_set_method (SignonIdentityInfo *info, const gchar *method, - const gchar* const *mechanisms) -{ - g_return_if_fail (info != NULL); - - g_return_if_fail (info->methods != NULL); - g_return_if_fail (method != NULL); - g_return_if_fail (mechanisms != NULL); - - g_hash_table_replace (info->methods, - g_strdup(method), g_strdupv((gchar **)mechanisms)); -} - -/** - * signon_identity_info_remove_method: - * @info: the #SignonIdentityInfo. - * @method: an authentication method. - * - * Remove @method from the list of allowed authentication methods. If all - * methods are removed, then all methods are allowed. - */ -void signon_identity_info_remove_method (SignonIdentityInfo *info, const gchar *method) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (info->methods != NULL); - - g_hash_table_remove (info->methods, method); -} - -/** - * signon_identity_info_set_realms: - * @info: the #SignonIdentityInfo. - * @realms: a %NULL-terminated list of realms. - * - * Specify what realms this identity can be used in. - */ -void signon_identity_info_set_realms (SignonIdentityInfo *info, - const gchar* const *realms) -{ - g_return_if_fail (info != NULL); - - if (info->realms) g_strfreev (info->realms); - - info->realms = g_strdupv ((gchar **)realms); -} - -/** - * signon_identity_info_set_owner: - * @info: the #SignonIdentityInfo. - * @owner: (transfer none) a security context of owner. - * - * Specify owner security context. - */ -void signon_identity_info_set_owner (SignonIdentityInfo *info, - const SignonSecurityContext *owner) -{ - g_return_if_fail (info != NULL); - - if (info->owner) signon_security_context_free (info->owner); - - info->owner = signon_security_context_copy (owner); -} - -/** - * signon_identity_info_set_owner_from_values: - * @info: the #SignonIdentityInfo. - * @system_context: owner's system context. - * @application_context: owner's application context. - * - * Specify owner security context. - */ -void signon_identity_info_set_owner_from_values ( - SignonIdentityInfo *info, - const gchar *system_context, - const gchar *application_context) -{ - g_return_if_fail (info != NULL && - system_context != NULL && - application_context != NULL); - - if (info->owner) signon_security_context_free (info->owner); - - info->owner = signon_security_context_new_from_values(system_context, - application_context); -} - -/** - * signon_identity_info_set_access_control_list: - * @info: the #SignonIdentityInfo. - * @access_control_list: (transfer none) a list of ACL security contexts. - * - * Specifies the ACL for this identity. The actual meaning of the ACL depends - * on the security framework used by signond. Ownership of the list is trans - */ -void signon_identity_info_set_access_control_list (SignonIdentityInfo *info, - const SignonSecurityContextList *access_control_list) -{ - g_return_if_fail (info != NULL); - - if (info->access_control_list) - signon_security_context_list_free (info->access_control_list); - - info->access_control_list = - signon_security_context_list_copy (access_control_list); -} - -/** - * signon_identity_info_access_control_list_append: - * @info: the #SignonIdentityInfo. - * @security_context: (transfer full) a security context to be appended. - * - * Appends a new #SignonSecurityContext item to the access control list. - */ -void signon_identity_info_access_control_list_append ( - SignonIdentityInfo *info, - SignonSecurityContext *security_context) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (security_context != NULL); - - info->access_control_list = g_list_append (info->access_control_list, - security_context); -} - -/** - * signon_identity_info_set_identity_type: - * @info: the #SignonIdentityInfo. - * @type: the type of the identity. - * - * Specifies the type of this identity. - */ -void signon_identity_info_set_identity_type (SignonIdentityInfo *info, - SignonIdentityType type) -{ - g_return_if_fail (info != NULL); - info->type = (gint)type; -} diff --git a/libsignon-glib/signon-identity-info.h b/libsignon-glib/signon-identity-info.h deleted file mode 100644 index f585fac..0000000 --- a/libsignon-glib/signon-identity-info.h +++ /dev/null @@ -1,112 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2011 Canonical Ltd. - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _SIGNON_IDENTITY_INFO_H_ -#define _SIGNON_IDENTITY_INFO_H_ - -#include - -#include "signon-security-context.h" - -G_BEGIN_DECLS - -/** - * SignonIdentityInfo: - * - * Opaque struct. Use the accessor functions below. - */ -typedef struct _SignonIdentityInfo SignonIdentityInfo; - -/** - * SignonIdentityType: - * @SIGNON_IDENTITY_TYPE_OTHER: an identity that is not an app, web or network - * @SIGNON_IDENTITY_TYPE_APP: an application identity - * @SIGNON_IDENTITY_TYPE_WEB: a web identity - * @SIGNON_IDENTITY_TYPE_NETWORK: a network server identity - * - * Types used in #SignonIdentityInfo. - */ -typedef enum { - SIGNON_IDENTITY_TYPE_OTHER = 0, - SIGNON_IDENTITY_TYPE_APP = 1 << 0, - SIGNON_IDENTITY_TYPE_WEB = 1 << 1, - SIGNON_IDENTITY_TYPE_NETWORK = 1 << 2 -} SignonIdentityType; - -GType signon_identity_info_get_type (void) G_GNUC_CONST; - -SignonIdentityInfo *signon_identity_info_new (); -void signon_identity_info_free (SignonIdentityInfo *info); - -SignonIdentityInfo *signon_identity_info_copy (const SignonIdentityInfo *other); - -gint signon_identity_info_get_id (const SignonIdentityInfo *info); -const gchar *signon_identity_info_get_username (const SignonIdentityInfo *info); -gboolean signon_identity_info_get_storing_secret ( - const SignonIdentityInfo *info); -const gchar *signon_identity_info_get_caption (const SignonIdentityInfo *info); -const GHashTable *signon_identity_info_get_methods ( - const SignonIdentityInfo *info); -const gchar* const *signon_identity_info_get_realms ( - const SignonIdentityInfo *info); -const SignonSecurityContext *signon_identity_info_get_owner ( - const SignonIdentityInfo *info); -const SignonSecurityContextList *signon_identity_info_get_access_control_list ( - const SignonIdentityInfo *info); -SignonIdentityType signon_identity_info_get_identity_type ( - const SignonIdentityInfo *info); - -void signon_identity_info_set_username (SignonIdentityInfo *info, const gchar *username); -void signon_identity_info_set_secret (SignonIdentityInfo *info, - const gchar *secret, - gboolean store_secret); -void signon_identity_info_set_caption (SignonIdentityInfo *info, - const gchar *caption); -void signon_identity_info_set_methods (SignonIdentityInfo *info, - const GHashTable *methods); -void signon_identity_info_set_method (SignonIdentityInfo *info, - const gchar *method, - const gchar* const *mechanisms); -void signon_identity_info_remove_method (SignonIdentityInfo *info, - const gchar *method); -void signon_identity_info_set_realms (SignonIdentityInfo *info, - const gchar* const *realms); -void signon_identity_info_set_owner (SignonIdentityInfo *info, - const SignonSecurityContext *owner); -void signon_identity_info_set_owner_from_values (SignonIdentityInfo *info, - const gchar *system_context, - const gchar *application_context); -void signon_identity_info_set_access_control_list (SignonIdentityInfo *info, - const SignonSecurityContextList *access_control_list); -void signon_identity_info_access_control_list_append (SignonIdentityInfo *info, - SignonSecurityContext *security_context); -void signon_identity_info_set_identity_type (SignonIdentityInfo *info, - SignonIdentityType type); - -G_END_DECLS - -#endif /* _SIGNON_IDENTITY_INFO_H_ */ diff --git a/libsignon-glib/signon-identity.c b/libsignon-glib/signon-identity.c deleted file mode 100644 index 808d369..0000000 --- a/libsignon-glib/signon-identity.c +++ /dev/null @@ -1,1644 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -/** - * SECTION:signon-identity - * @title: SignonIdentity - * @short_description: Client side presentation of a credential. - * - * The #SignonIdentity represents a database entry for a single identity. - */ - -#include "signon-identity.h" -#include "signon-auth-session.h" -#include "signon-internals.h" -#include "signon-dbus-queue.h" -#include "signon-utils.h" -#include "signon-errors.h" -#include "sso-auth-service.h" -#include "sso-identity-gen.h" - -G_DEFINE_TYPE (SignonIdentity, signon_identity, G_TYPE_OBJECT); - -enum -{ - PROP_0, - PROP_ID, - PROP_APPCTX -}; - -typedef enum { - NOT_REGISTERED, - PENDING_REGISTRATION, - REGISTERED, -} IdentityRegistrationState; - -typedef enum { - DATA_UPDATED = 0, - IDENTITY_REMOVED, - IDENTITY_SIGNED_OUT -} RemoteIdentityState; - -struct _SignonIdentityPrivate -{ - SsoIdentity *proxy; - SsoAuthService *auth_service_proxy; - GCancellable *cancellable; - - SignonIdentityInfo *identity_info; - - GSList *sessions; - IdentityRegistrationState registration_state; - - gboolean removed; - gboolean signed_out; - gboolean updated; - - guint id; - gchar *app_ctx; - - guint signal_info_updated; - guint signal_unregistered; -}; - -enum { - SIGNEDOUT_SIGNAL, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -#define SIGNON_IDENTITY_PRIV(obj) (SIGNON_IDENTITY(obj)->priv) - -typedef struct _IdentityStoreCredentialsCbData -{ - SignonIdentity *self; - SignonIdentityStoreCredentialsCb cb; - gpointer user_data; -} IdentityStoreCredentialsCbData; - -typedef struct _IdentityStoreCredentialsData -{ - GVariant *info_variant; - gpointer cb_data; -} IdentityStoreCredentialsData; - -typedef enum { - SIGNON_VERIFY_USER, - SIGNON_VERIFY_SECRET, - SIGNON_INFO, - SIGNON_REMOVE, - SIGNON_SIGNOUT -} IdentityOperation; - -typedef struct _IdentitySessionCbData -{ - SignonIdentity *self; - SignonAuthSession *session; - SignonIdentitySessionReadyCb cb; -} IdentitySessionCbData; - -typedef struct _IdentitySessionData -{ - const gchar *method; - gpointer cb_data; -} IdentitySessionData; - -typedef struct _IdentityVerifyCbData -{ - SignonIdentity *self; - SignonIdentityVerifyCb cb; - gpointer user_data; -} IdentityVerifyCbData; - -typedef struct _IdentityVerifyData -{ - gchar *data_to_send; - GHashTable *params; - IdentityOperation operation; - gpointer cb_data; -} IdentityVerifyData; - -typedef struct _IdentityInfoCbData -{ - SignonIdentity *self; - SignonIdentityInfoCb cb; - gpointer user_data; -} IdentityInfoCbData; - -typedef struct _IdentityVoidCbData -{ - SignonIdentity *self; - SignonIdentityVoidCb cb; - gpointer user_data; -} IdentityVoidCbData; - -typedef struct _IdentityVoidData -{ - IdentityOperation operation; - gpointer cb_data; -} IdentityVoidData; - -static void identity_check_remote_registration (SignonIdentity *self); -static void identity_store_credentials_ready_cb (gpointer object, const GError *error, gpointer user_data); -static void identity_store_credentials_reply (GObject *object, - GAsyncResult *res, - gpointer userdata); -static void identity_verify_data (SignonIdentity *self, const gchar *data_to_send, gint operation, - SignonIdentityVerifyCb cb, gpointer user_data); -static void identity_verify_ready_cb (gpointer object, const GError *error, gpointer user_data); - -static void identity_remove_ready_cb (gpointer object, const GError *error, gpointer user_data); -static void identity_signout_ready_cb (gpointer object, const GError *error, gpointer user_data); -static void identity_info_ready_cb (gpointer object, const GError *error, gpointer user_data); - -static void identity_process_signout (SignonIdentity *self); -static void identity_process_updated (SignonIdentity *self); -static void identity_process_removed (SignonIdentity *self); -static void identity_get_auth_session_reply (GObject *object, - GAsyncResult *res, - gpointer userdata); -static void identity_session_ready_cb (gpointer object, const GError *error, - gpointer user_data); -static void identity_session_object_destroyed_cb (gpointer data, - GObject *where_the_session_was); - -static GQuark -identity_object_quark () -{ - static GQuark quark = 0; - - if (!quark) - quark = g_quark_from_static_string ("identity_object_quark"); - - return quark; -} - -static void -signon_identity_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - SignonIdentity *self = SIGNON_IDENTITY (object); - - switch (property_id) - { - case PROP_ID: - self->priv->id = g_value_get_uint (value); - break; - case PROP_APPCTX: - g_free (self->priv->app_ctx); - self->priv->app_ctx = g_strdup (g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -signon_identity_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - SignonIdentity *self = SIGNON_IDENTITY (object); - - switch (property_id) - { - case PROP_ID: - g_value_set_uint (value, self->priv->id); - break; - case PROP_APPCTX: - g_value_set_string (value, self->priv->app_ctx); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -signon_identity_init (SignonIdentity *identity) -{ - SignonIdentityPrivate *priv; - - identity->priv = G_TYPE_INSTANCE_GET_PRIVATE (identity, - SIGNON_TYPE_IDENTITY, - SignonIdentityPrivate); - - priv = identity->priv; - priv->proxy = NULL; - priv->auth_service_proxy = sso_auth_service_get_instance(); - priv->cancellable = g_cancellable_new (); - priv->registration_state = NOT_REGISTERED; - - priv->removed = FALSE; - priv->signed_out = FALSE; - priv->updated = FALSE; - - priv->app_ctx = NULL; -} - -static void -signon_identity_dispose (GObject *object) -{ - SignonIdentity *identity = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = identity->priv; - - if (priv->cancellable) - { - g_cancellable_cancel (priv->cancellable); - g_object_unref (priv->cancellable); - priv->cancellable = NULL; - } - - if (priv->identity_info) - { - signon_identity_info_free (priv->identity_info); - priv->identity_info = NULL; - } - - g_clear_object (&priv->auth_service_proxy); - - if (priv->proxy) - { - g_signal_handler_disconnect (priv->proxy, priv->signal_info_updated); - g_signal_handler_disconnect (priv->proxy, priv->signal_unregistered); - g_object_unref (priv->proxy); - priv->proxy = NULL; - } - - if (priv->sessions) - g_critical ("SignonIdentity: the list of AuthSessions MUST be empty"); - - G_OBJECT_CLASS (signon_identity_parent_class)->dispose (object); -} - -static void -signon_identity_finalize (GObject *object) -{ - SignonIdentity *identity = SIGNON_IDENTITY (object); - if (identity->priv->app_ctx) - { - g_free(identity->priv->app_ctx); - identity->priv->app_ctx = NULL; - } - - G_OBJECT_CLASS (signon_identity_parent_class)->finalize (object); -} - -static void -signon_identity_class_init (SignonIdentityClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - object_class->set_property = signon_identity_set_property; - object_class->get_property = signon_identity_get_property; - - pspec = g_param_spec_uint ("id", - "Identity ID", - "Set/Get Identity ID", - 0, - G_MAXUINT, - 0, - G_PARAM_READWRITE); - g_object_class_install_property (object_class, - PROP_ID, - pspec); - - pspec = g_param_spec_string ("app_ctx", - "Application Context", - "Set/Get Application Security Context", - "", - G_PARAM_READWRITE); - g_object_class_install_property (object_class, - PROP_APPCTX, - pspec); - - g_type_class_add_private (object_class, sizeof (SignonIdentityPrivate)); - - /** - * SignonIdentity::signout: - * - * Emitted when the identity was signed out. - */ - signals[SIGNEDOUT_SIGNAL] = g_signal_new("signout", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0 /* class closure */, - NULL /* accumulator */, - NULL /* accu_data */, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE /* return_type */, - 0); - - object_class->dispose = signon_identity_dispose; - object_class->finalize = signon_identity_finalize; -} - -static void -identity_state_changed_cb (GDBusProxy *proxy, - gint state, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (user_data)); - SignonIdentity *self = SIGNON_IDENTITY (user_data); - - switch (state) { - case DATA_UPDATED: - DEBUG ("State changed to DATA_UPDATED"); - identity_process_updated (self); - break; - case IDENTITY_REMOVED: - DEBUG ("State changed to IDENTITY_REMOVED"); - identity_process_removed (self); - break; - case IDENTITY_SIGNED_OUT: - DEBUG ("State changed to IDENTITY_SIGNED_OUT"); - identity_process_signout (self); - break; - default: - g_critical ("wrong state value obtained from signon daemon"); - }; -} - -static void -identity_remote_object_destroyed_cb(GDBusProxy *proxy, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (user_data)); - SignonIdentity *self = SIGNON_IDENTITY (user_data); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - if (priv->proxy) - { - g_object_unref (priv->proxy); - priv->proxy = NULL; - } - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - _signon_object_not_ready(self); - - priv->registration_state = NOT_REGISTERED; - - signon_identity_info_free (priv->identity_info); - priv->identity_info = NULL; - - priv->removed = FALSE; - priv->signed_out = FALSE; - priv->updated = FALSE; -} - -static void -identity_registered (SignonIdentity *identity, - char *object_path, GVariant *identity_data, - GError *error) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (identity)); - - SignonIdentityPrivate *priv; - priv = identity->priv; - - g_return_if_fail (priv != NULL); - - if (!error) - { - GDBusConnection *connection; - GDBusProxy *auth_service_proxy; - const gchar *bus_name; - GError *proxy_error = NULL; - - DEBUG("%s: %s", G_STRFUNC, object_path); - /* - * TODO: as Aurel will finalize the code polishing so we will - * need to implement the refresh of the proxy to SignonIdentity - * */ - g_return_if_fail (priv->proxy == NULL); - - auth_service_proxy = (GDBusProxy *)priv->auth_service_proxy; - connection = g_dbus_proxy_get_connection (auth_service_proxy); - bus_name = g_dbus_proxy_get_name (auth_service_proxy); - - priv->proxy = - sso_identity_proxy_new_sync (connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - bus_name, - object_path, - priv->cancellable, - &proxy_error); - if (G_UNLIKELY (proxy_error != NULL)) - { - g_warning ("Failed to initialize Identity proxy: %s", - proxy_error->message); - g_clear_error (&proxy_error); - } - - priv->signal_info_updated = - g_signal_connect (priv->proxy, - "info-updated", - G_CALLBACK (identity_state_changed_cb), - identity); - - priv->signal_unregistered = - g_signal_connect (priv->proxy, - "unregistered", - G_CALLBACK (identity_remote_object_destroyed_cb), - identity); - - if (identity_data) - { - DEBUG("%s: ", G_STRFUNC); - priv->identity_info = - signon_identity_info_new_from_variant (identity_data); - g_variant_unref (identity_data); - } - - priv->updated = TRUE; - } - else - g_warning ("%s: %s", G_STRFUNC, error->message); - - /* - * execute queued operations or emit errors on each of them - * */ - priv->registration_state = REGISTERED; - - /* - * TODO: if we will add a new state for identity: "INVALID" - * consider emission of another error, like "invalid" - * */ - _signon_object_ready (identity, identity_object_quark (), error); - - /* - * as the registration failed we do not - * request for new registration, but emit - * same error again and again - * */ -} - -/** - * signon_identity_get_last_error: - * @identity: the #SignonIdentity. - * - * Get the most recent error that occurred on @identity. - * - * Returns: a #GError containing the most recent error, or %NULL on failure. - */ -const GError * -signon_identity_get_last_error (SignonIdentity *identity) -{ - g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL); - return _signon_object_last_error(identity); -} - -static void -identity_new_cb (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SignonIdentity *identity = (SignonIdentity*)userdata; - SsoAuthService *proxy = SSO_AUTH_SERVICE (object); - gchar *object_path = NULL; - GError *error = NULL; - - g_return_if_fail (identity != NULL); - DEBUG ("%s", G_STRFUNC); - - sso_auth_service_call_register_new_identity_finish (proxy, - &object_path, - res, - &error); - if (SIGNON_IS_NOT_CANCELLED (error)) - { - identity_registered (identity, object_path, NULL, error); - } - if (object_path) g_free (object_path); - g_clear_error (&error); -} - -static void -identity_new_from_db_cb (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SignonIdentity *identity = (SignonIdentity*)userdata; - SsoAuthService *proxy = SSO_AUTH_SERVICE (object); - gchar *object_path = NULL; - GVariant *identity_data; - GError *error = NULL; - - g_return_if_fail (identity != NULL); - DEBUG ("%s", G_STRFUNC); - - sso_auth_service_call_get_identity_finish (proxy, - &object_path, - &identity_data, - res, - &error); - if (SIGNON_IS_NOT_CANCELLED (error)) - { - identity_registered (identity, object_path, identity_data, error); - } - if (object_path) g_free (object_path); - g_clear_error (&error); -} - -static void -identity_check_remote_registration (SignonIdentity *self) -{ - g_return_if_fail (self != NULL); - SignonIdentityPrivate *priv = self->priv; - - g_return_if_fail (priv != NULL); - - if (priv->registration_state != NOT_REGISTERED) - return; - - if (priv->id != 0) - sso_auth_service_call_get_identity (priv->auth_service_proxy, - priv->id, - priv->app_ctx, - priv->cancellable, - identity_new_from_db_cb, - self); - else - sso_auth_service_call_register_new_identity (priv->auth_service_proxy, - priv->app_ctx, - priv->cancellable, - identity_new_cb, - self); - - priv->registration_state = PENDING_REGISTRATION; -} - -/** - * signon_identity_new_from_db: - * @id: identity ID. - * @application_context: application security context, can be %NULL. - * - * Construct an identity object associated with an existing identity - * record. - * - * Returns: an instance of a #SignonIdentity. - */ -SignonIdentity* -signon_identity_new_from_db (guint32 id, const gchar *application_context) -{ - SignonIdentity *identity; - DEBUG ("%s %d: %d\n", G_STRFUNC, __LINE__, id); - if (id == 0) - return NULL; - - identity = g_object_new (SIGNON_TYPE_IDENTITY, - "id", id, - "app_ctx", application_context, - NULL); - g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL); - g_return_val_if_fail (identity->priv != NULL, NULL); - - identity->priv->id = id; - identity->priv->app_ctx = (application_context) ? - g_strdup (application_context) : g_strdup (""); - identity_check_remote_registration (identity); - - return identity; -} - -/** - * signon_identity_new: - * @application_context: application security context, can be %NULL. - * - * Construct new, empty, identity object. - * - * Returns: an instance of an #SignonIdentity. - */ -SignonIdentity* -signon_identity_new (const gchar *application_context) -{ - DEBUG ("%s %d", G_STRFUNC, __LINE__); - SignonIdentity *identity = g_object_new ( - SIGNON_TYPE_IDENTITY, - "app_ctx", application_context, - NULL); - g_return_val_if_fail (SIGNON_IS_IDENTITY (identity), NULL); - g_return_val_if_fail (identity->priv != NULL, NULL); - - identity->priv->app_ctx = (application_context) ? - g_strdup (application_context) : g_strdup (""); - identity_check_remote_registration (identity); - - return identity; -} - -/** - * signon_identity_create_session: - * @self: the #SignonIdentity. - * @method: method. - * @error: pointer to a location which will receive the error, if any. - * - * Creates an authentication session for this identity. - * - * Returns: (transfer full): a new #SignonAuthSession. - */ -SignonAuthSession * -signon_identity_create_session(SignonIdentity *self, - const gchar *method, - GError **error) -{ - g_return_val_if_fail (SIGNON_IS_IDENTITY (self), NULL); - - SignonIdentityPrivate *priv = self->priv; - g_return_val_if_fail (priv != NULL, NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - if (method == NULL) - { - DEBUG ("NULL method as input. Aborting."); - g_set_error(error, - signon_error_quark(), - SIGNON_ERROR_UNKNOWN, - "NULL input method."); - return NULL; - } - - GSList *list = priv->sessions; - while (list) - { - SignonAuthSession *session = SIGNON_AUTH_SESSION (priv->sessions->data); - const gchar *sessionMethod = signon_auth_session_get_method (session); - if (g_strcmp0(sessionMethod, method) == 0) - { - DEBUG ("Auth Session with method `%s` already created.", method); - g_set_error (error, - signon_error_quark(), - SIGNON_ERROR_METHOD_NOT_AVAILABLE, - "Authentication session for this method already requested."); - return NULL; - } - - list = list->next; - } - - SignonAuthSession *session = signon_auth_session_new (G_OBJECT(self), - method, - error); - if (session) - { - DEBUG ("%s %d - success", G_STRFUNC, __LINE__); - priv->sessions = g_slist_append(priv->sessions, session); - g_object_weak_ref (G_OBJECT(session), - identity_session_object_destroyed_cb, - self); - /* - * if you want to delete the identity - * you MUST delete all authsessions - * first - * */ - g_object_ref (self); - priv->signed_out = FALSE; - } - - return session; -} - -/** - * signon_identity_store_credentials_with_info: - * @self: the #SignonIdentity. - * @info: the #SignonIdentityInfo data to store. - * @cb: (scope async): callback. - * @user_data: user_data. - * - * Stores the data from @info into the identity. - */ -void -signon_identity_store_credentials_with_info(SignonIdentity *self, - const SignonIdentityInfo *info, - SignonIdentityStoreCredentialsCb cb, - gpointer user_data) -{ - IdentityStoreCredentialsCbData *cb_data; - IdentityStoreCredentialsData *operation_data; - - DEBUG (); - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - g_return_if_fail (info != NULL); - - SignonIdentityPrivate *priv = self->priv; - if (priv->identity_info) - signon_identity_info_free (priv->identity_info); - priv->identity_info = signon_identity_info_copy (info); - - cb_data = g_slice_new0 (IdentityStoreCredentialsCbData); - cb_data->self = self; - cb_data->cb = cb; - cb_data->user_data = user_data; - - operation_data = g_slice_new0 (IdentityStoreCredentialsData); - operation_data->info_variant = signon_identity_info_to_variant (info); - operation_data->cb_data = cb_data; - - identity_check_remote_registration (self); - _signon_object_call_when_ready (self, - identity_object_quark(), - identity_store_credentials_ready_cb, - operation_data); -} - -/** - * signon_identity_store_credentials_with_args: - * @self: the #SignonIdentity. - * @username: username. - * @secret: secret. - * @store_secret: whether signond should store the password. - * @methods: (transfer none) (element-type utf8 GStrv): methods. - * @caption: caption. - * @realms: realms. - * @access_control_list: access control list. - * @type: the type of the identity. - * @cb: (scope async): callback. - * @user_data: user_data. - * - * Stores the given data into the identity. - */ -void signon_identity_store_credentials_with_args(SignonIdentity *self, - const gchar *username, - const gchar *secret, - const gboolean store_secret, - const GHashTable *methods, - const gchar *caption, - const gchar* const *realms, - const SignonSecurityContext *owner, - const SignonSecurityContextList *access_control_list, - SignonIdentityType type, - SignonIdentityStoreCredentialsCb cb, - gpointer user_data) -{ - SignonIdentityInfo *info; - - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - info = signon_identity_info_new (); - signon_identity_info_set_username (info, username); - signon_identity_info_set_secret (info, secret, store_secret); - signon_identity_info_set_methods (info, methods); - signon_identity_info_set_caption (info, caption); - signon_identity_info_set_realms (info, realms); - if (owner) - { - signon_identity_info_set_owner (info, owner); - } - if (access_control_list) - { - signon_identity_info_set_access_control_list (info, - access_control_list); - } - signon_identity_info_set_identity_type (info, type); - - signon_identity_store_credentials_with_info (self, info, cb, user_data); - signon_identity_info_free (info); -} - -static void -identity_store_credentials_ready_cb (gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (object)); - - SignonIdentity *self = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - IdentityStoreCredentialsData *operation_data = - (IdentityStoreCredentialsData *)user_data; - g_return_if_fail (operation_data != NULL); - - IdentityStoreCredentialsCbData *cb_data = operation_data->cb_data; - g_return_if_fail (cb_data != NULL); - - if (error) - { - DEBUG ("IdentityError: %s", error->message); - - if (cb_data->cb) - { - (cb_data->cb) (self, 0, error, cb_data->user_data); - } - - g_slice_free (IdentityStoreCredentialsCbData, cb_data); - } - else - { - g_return_if_fail (priv->proxy != NULL); - - sso_identity_call_store (priv->proxy, - operation_data->info_variant, - priv->cancellable, - identity_store_credentials_reply, - cb_data); - } - - g_slice_free (IdentityStoreCredentialsData, operation_data); -} - -static void -identity_store_credentials_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - IdentityStoreCredentialsCbData *cb_data = (IdentityStoreCredentialsCbData *)userdata; - SsoIdentity *proxy = SSO_IDENTITY (object); - guint id; - GError *error = NULL; - - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->self != NULL); - g_return_if_fail (cb_data->self->priv != NULL); - - SignonIdentityPrivate *priv = cb_data->self->priv; - - sso_identity_call_store_finish (proxy, &id, res, &error); - - if (error == NULL) - { - g_return_if_fail (priv->identity_info == NULL); - - g_object_set (cb_data->self, "id", id, NULL); - cb_data->self->priv->id = id; - - /* - * if the previous state was REMOVED - * then we need to reset it - * */ - priv->removed = FALSE; - } - - if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) - { - (cb_data->cb) (cb_data->self, id, error, cb_data->user_data); - } - - g_clear_error(&error); - g_slice_free (IdentityStoreCredentialsCbData, cb_data); -} - -static void -identity_verify_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SsoIdentity *proxy = SSO_IDENTITY (object); - gboolean valid; - GError *error = NULL; - IdentityVerifyCbData *cb_data = (IdentityVerifyCbData *)userdata; - - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->self != NULL); - - sso_identity_call_verify_secret_finish (proxy, &valid, res, &error); - - if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) - { - (cb_data->cb) (cb_data->self, valid, error, cb_data->user_data); - } - - g_clear_error(&error); - g_slice_free (IdentityVerifyCbData, cb_data); -} - -static void -identity_verify_ready_cb (gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (object)); - - SignonIdentity *self = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - IdentityVerifyData *operation_data = - (IdentityVerifyData *)user_data; - g_return_if_fail (operation_data != NULL); - - IdentityVerifyCbData *cb_data = operation_data->cb_data; - g_return_if_fail (cb_data != NULL); - - if (priv->removed == TRUE) - { - GError *new_error = g_error_new (signon_error_quark(), - SIGNON_ERROR_IDENTITY_NOT_FOUND, - "Already removed from database."); - - if (cb_data->cb) - { - (cb_data->cb) (self, FALSE, new_error, cb_data->user_data); - } - - g_error_free (new_error); - g_slice_free (IdentityVerifyCbData, cb_data); - } - else if (error) - { - DEBUG ("IdentityError: %s", error->message); - - if (cb_data->cb) - { - (cb_data->cb) (self, FALSE, error, cb_data->user_data); - } - - g_slice_free (IdentityVerifyCbData, cb_data); - } - else - { - DEBUG ("%s %d", G_STRFUNC, __LINE__); - g_return_if_fail (priv->proxy != NULL); - - switch (operation_data->operation) { - case SIGNON_VERIFY_SECRET: - sso_identity_call_verify_secret (priv->proxy, - operation_data->data_to_send, - priv->cancellable, - identity_verify_reply, - cb_data); - break; - default: g_critical ("Wrong operation code"); - }; - } - g_free (operation_data->params); - g_free (operation_data->data_to_send); - g_slice_free (IdentityVerifyData, operation_data); -} - -static void -identity_verify_data(SignonIdentity *self, - const gchar *data_to_send, - gint operation, - SignonIdentityVerifyCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - IdentityVerifyCbData *cb_data = g_slice_new0 (IdentityVerifyCbData); - cb_data->self = self; - cb_data->cb = cb; - cb_data->user_data = user_data; - - IdentityVerifyData *operation_data = g_slice_new0 (IdentityVerifyData); - - operation_data->params = NULL; - operation_data->data_to_send = g_strdup (data_to_send); - operation_data->operation = operation; - operation_data->cb_data = cb_data; - - identity_check_remote_registration (self); - _signon_object_call_when_ready (self, - identity_object_quark(), - identity_verify_ready_cb, - operation_data); -} - -/** - * signon_identity_verify_secret: - * @self: the #SignonIdentity. - * @secret: the secret (password) to be verified. - * @cb: (scope async): callback. - * @user_data: user_data. - * - * Verifies the given secret. - */ -void signon_identity_verify_secret(SignonIdentity *self, - const gchar *secret, - SignonIdentityVerifyCb cb, - gpointer user_data) -{ - identity_verify_data (self, - secret, - SIGNON_VERIFY_SECRET, - cb, - user_data); -} - -static void -identity_process_updated (SignonIdentity *self) -{ - DEBUG ("%d %s", __LINE__, __func__); - - g_return_if_fail (self != NULL); - g_return_if_fail (self->priv != NULL); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv->proxy != NULL); - - signon_identity_info_free (priv->identity_info); - priv->identity_info = NULL; - priv->updated = FALSE; - - DEBUG ("%s info freed, to be updated", __func__); -} - -static void -identity_process_removed (SignonIdentity *self) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (self->priv != NULL); - - DEBUG ("%d %s", __LINE__, __func__); - - SignonIdentityPrivate *priv = self->priv; - - if (priv->removed == TRUE) - return; - - priv->removed = TRUE; - signon_identity_info_free (priv->identity_info); - priv->identity_info = NULL; - - g_object_set (self, "id", 0, NULL); - priv->id = 0; -} - -static void -identity_process_signout(SignonIdentity *self) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (self->priv != NULL); - - DEBUG ("%d %s", __LINE__, __func__); - SignonIdentityPrivate *priv = self->priv; - - if (priv->signed_out == TRUE) - return; - - GSList *llink = priv->sessions; - while (llink) - { - GSList *next = llink->next; - g_object_unref (G_OBJECT(llink->data)); - llink = next; - } - - priv->signed_out = TRUE; - g_signal_emit(G_OBJECT(self), signals[SIGNEDOUT_SIGNAL], 0); -} - -/* - * TODO: fix the implementation - * of signond: it returns result = TRUE - * in ANY CASE - * */ -static void -identity_signout_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SsoIdentity *proxy = SSO_IDENTITY (object); - gboolean result; - GError *error = NULL; - IdentityVoidCbData *cb_data = (IdentityVoidCbData *)userdata; - - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->self != NULL); - g_return_if_fail (cb_data->self->priv != NULL); - - sso_identity_call_sign_out_finish (proxy, &result, res, &error); - - if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) - { - (cb_data->cb) (cb_data->self, error, cb_data->user_data); - } - - g_clear_error(&error); - g_slice_free (IdentityVoidCbData, cb_data); -} - -static void -identity_removed_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SsoIdentity *proxy = SSO_IDENTITY (object); - GError *error = NULL; - IdentityVoidCbData *cb_data = (IdentityVoidCbData *)userdata; - - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->self != NULL); - g_return_if_fail (cb_data->self->priv != NULL); - - sso_identity_call_remove_finish (proxy, res, &error); - - if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) - { - (cb_data->cb) (cb_data->self, error, cb_data->user_data); - } - - g_clear_error(&error); - g_slice_free (IdentityVoidCbData, cb_data); -} - -static void -identity_info_reply(GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SsoIdentity *proxy = SSO_IDENTITY (object); - GVariant *identity_data = NULL; - DEBUG ("%d %s", __LINE__, __func__); - - GError *error = NULL; - IdentityInfoCbData *cb_data = (IdentityInfoCbData *)userdata; - - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->self != NULL); - g_return_if_fail (cb_data->self->priv != NULL); - - SignonIdentityPrivate *priv = cb_data->self->priv; - - sso_identity_call_get_info_finish (proxy, &identity_data, res, &error); - - if (identity_data != NULL) - { - priv->identity_info = - signon_identity_info_new_from_variant (identity_data); - g_variant_unref (identity_data); - } - - if (SIGNON_IS_NOT_CANCELLED (error) && cb_data->cb) - { - (cb_data->cb) (cb_data->self, priv->identity_info, error, cb_data->user_data); - } - - g_clear_error(&error); - g_slice_free (IdentityInfoCbData, cb_data); - - priv->updated = TRUE; -} - -static void -identity_info_ready_cb(gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (object)); - - SignonIdentity *self = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - IdentityVoidData *operation_data = - (IdentityVoidData *)user_data; - g_return_if_fail (operation_data != NULL); - - IdentityInfoCbData *cb_data = operation_data->cb_data; - g_return_if_fail (cb_data != NULL); - - if (priv->removed == TRUE) - { - DEBUG ("%s identity removed", G_STRFUNC); - - GError *new_error = g_error_new (signon_error_quark(), - SIGNON_ERROR_IDENTITY_NOT_FOUND, - "Already removed from database."); - if (cb_data->cb) - (cb_data->cb) (self, NULL, new_error, cb_data->user_data); - - g_error_free (new_error); - } - else if (error || priv->id == 0) - { - DEBUG ("%s identity is new", G_STRFUNC); - - if (error) - DEBUG ("IdentityError: %s", error->message); - else - DEBUG ("Identity is not stored and has no info yet"); - - if (cb_data->cb) - (cb_data->cb) (self, NULL, error, cb_data->user_data); - } - else if (priv->updated == FALSE) - { - DEBUG ("%s identity needs update, call daemon", G_STRFUNC); - - g_return_if_fail (priv->proxy != NULL); - sso_identity_call_get_info (priv->proxy, - priv->cancellable, - identity_info_reply, - cb_data); - goto free_op_data; - } - else - { - DEBUG ("%s pass existing one", G_STRFUNC); - - if (cb_data->cb) - (cb_data->cb) (self, priv->identity_info, error, cb_data->user_data); - } - - g_slice_free (IdentityInfoCbData, cb_data); - -free_op_data: - g_slice_free (IdentityVoidData, operation_data); -} - -static void -identity_signout_ready_cb(gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (object)); - - SignonIdentity *self = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - IdentityVoidCbData *cb_data = (IdentityVoidCbData *)user_data; - - g_return_if_fail (cb_data != NULL); - - if (priv->removed == TRUE) - { - GError *new_error = g_error_new (signon_error_quark(), - SIGNON_ERROR_IDENTITY_NOT_FOUND, - "Already removed from database."); - if (cb_data->cb) - { - (cb_data->cb) (self, new_error, cb_data->user_data); - } - - g_error_free (new_error); - g_slice_free (IdentityVoidCbData, cb_data); - } - else if (error) - { - DEBUG ("IdentityError: %s", error->message); - if (cb_data->cb) - { - (cb_data->cb) (self, error, cb_data->user_data); - } - - g_slice_free (IdentityVoidCbData, cb_data); - } - else - { - g_return_if_fail (priv->proxy != NULL); - sso_identity_call_sign_out (priv->proxy, - priv->cancellable, - identity_signout_reply, - cb_data); - } -} - -static void -identity_remove_ready_cb(gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (object)); - - SignonIdentity *self = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - IdentityVoidCbData *cb_data = (IdentityVoidCbData *)user_data; - g_return_if_fail (cb_data != NULL); - - if (priv->removed == TRUE) - { - GError *new_error = g_error_new (signon_error_quark(), - SIGNON_ERROR_IDENTITY_NOT_FOUND, - "Already removed from database."); - if (cb_data->cb) - { - (cb_data->cb) (self, new_error, cb_data->user_data); - } - - g_error_free (new_error); - g_slice_free (IdentityVoidCbData, cb_data); - } - else if (error) - { - DEBUG ("IdentityError: %s", error->message); - if (cb_data->cb) - { - (cb_data->cb) (self, error, cb_data->user_data); - } - - g_slice_free (IdentityVoidCbData, cb_data); - } - else - { - g_return_if_fail (priv->proxy != NULL); - sso_identity_call_remove (priv->proxy, - priv->cancellable, - identity_removed_reply, - cb_data); - } -} - -void static -identity_void_operation(SignonIdentity *self, - gint operation, - gpointer cb_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - IdentityVoidData *operation_data = g_slice_new0 (IdentityVoidData); - operation_data->cb_data = cb_data; - _signon_object_call_when_ready (self, - identity_object_quark(), - identity_info_ready_cb, - operation_data); -} - -/** - * signon_identity_remove: - * @self: the #SignonIdentity. - * @cb: (scope async): callback to be called when the operation has completed. - * @user_data: user_data to pass to the callback. - * - * Removes the corresponding credentials record from the database. - */ -void signon_identity_remove(SignonIdentity *self, - SignonIdentityRemovedCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - IdentityVoidCbData *cb_data = g_slice_new0 (IdentityVoidCbData); - cb_data->self = self; - cb_data->cb = (SignonIdentityVoidCb)cb; - cb_data->user_data = user_data; - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - identity_check_remote_registration (self); - _signon_object_call_when_ready (self, - identity_object_quark(), - identity_remove_ready_cb, - cb_data); -} - -/** - * signon_identity_signout: - * @self: the #SignonIdentity. - * @cb: (scope async): callback. - * @user_data: user_data. - * - * Asks signond to close all authentication sessions for this - * identity, and to remove any stored secrets associated with it (password and - * authentication tokens). - */ -void signon_identity_signout(SignonIdentity *self, - SignonIdentitySignedOutCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - IdentityVoidCbData *cb_data = g_slice_new0 (IdentityVoidCbData); - cb_data->self = self; - cb_data->cb = (SignonIdentityVoidCb)cb; - cb_data->user_data = user_data; - - identity_check_remote_registration (self); - _signon_object_call_when_ready (self, - identity_object_quark(), - identity_signout_ready_cb, - cb_data); -} - -/** - * signon_identity_add_reference: - * @self: the #SignonIdentity. - * @reference: reference to be added - * @cb: callback - * @user_data: user_data. - * - * Adds named reference to identity - */ -void signon_identity_add_reference(SignonIdentity *self, - const gchar *reference, - SignonIdentityReferenceAddedCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - //TODO implement - - if (cb) - (cb) (self, NULL, user_data); -} - -/** - * signon_identity_remove_reference: - * @self: the #SignonIdentity. - * @reference: reference to be removed - * @cb: callback - * @user_data: user_data. - * - * Removes named reference from identity - */ -void signon_identity_remove_reference(SignonIdentity *self, - const gchar *reference, - SignonIdentityReferenceRemovedCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - //TODO implement - - if (cb) - (cb) (self, NULL, user_data); -} - -/** - * signon_identity_query_info: - * @self: the #SignonIdentity. - * @cb: (scope async): callback. - * @user_data: user_data. - * - * Fetches the #SignonIdentityInfo data associated with this - * identity. - */ -void signon_identity_query_info(SignonIdentity *self, - SignonIdentityInfoCb cb, - gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - IdentityInfoCbData *cb_data = g_slice_new0 (IdentityInfoCbData); - cb_data->self = self; - cb_data->cb = cb; - cb_data->user_data = user_data; - - identity_check_remote_registration (self); - identity_void_operation(self, - SIGNON_INFO, - cb_data); -} - -static void -identity_get_auth_session_reply (GObject *object, GAsyncResult *res, - gpointer userdata) -{ - SsoIdentity *proxy = SSO_IDENTITY (object); - gchar *object_path = NULL; - GError *error = NULL; - - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - sso_identity_call_get_auth_session_finish (proxy, - &object_path, - res, - &error); - - IdentitySessionCbData *cb_data = (IdentitySessionCbData *) userdata; - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->cb != NULL); - - if (SIGNON_IS_NOT_CANCELLED (error)) - { - (cb_data->cb) (cb_data->session, - error, - g_dbus_proxy_get_connection ((GDBusProxy *)proxy), - g_dbus_proxy_get_name ((GDBusProxy *)proxy), - object_path); - } - g_slice_free (IdentitySessionCbData, cb_data); - if (object_path) g_free (object_path); - g_clear_error (&error); -} - -static void -identity_session_ready_cb(gpointer object, const GError *error, gpointer user_data) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (object)); - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - SignonIdentity *self = SIGNON_IDENTITY (object); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - IdentitySessionData *operation_data = (IdentitySessionData *) user_data; - g_return_if_fail (operation_data != NULL); - - IdentitySessionCbData *cb_data = operation_data->cb_data; - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->cb != NULL); - - if (error) - { - (cb_data->cb) (cb_data->session, (GError *)error, NULL, NULL, NULL); - } - else if (priv->removed == TRUE) - { - GError *new_error = g_error_new (signon_error_quark(), - SIGNON_ERROR_IDENTITY_NOT_FOUND, - "Already removed from database."); - (cb_data->cb) (cb_data->session, new_error, NULL, NULL, NULL); - g_error_free (new_error); - } - else - { - g_return_if_fail (priv->proxy != NULL); - - sso_identity_call_get_auth_session ( - priv->proxy, - operation_data->method, - priv->cancellable, - identity_get_auth_session_reply, - cb_data); - } - - g_slice_free (IdentitySessionData, operation_data); -} - -static void -identity_session_object_destroyed_cb(gpointer data, - GObject *where_the_session_was) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (data)); - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - SignonIdentity *self = SIGNON_IDENTITY (data); - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - priv->sessions = g_slist_remove(priv->sessions, (gpointer)where_the_session_was); - g_object_unref (self); -} - -void signon_identity_get_auth_session (SignonIdentity *self, - SignonAuthSession *session, - const gchar *method, - SignonIdentitySessionReadyCb cb) -{ - g_return_if_fail (SIGNON_IS_IDENTITY (self)); - DEBUG ("%s %d", G_STRFUNC, __LINE__); - - SignonIdentityPrivate *priv = self->priv; - g_return_if_fail (priv != NULL); - - IdentitySessionCbData *cb_data = g_slice_new0 (IdentitySessionCbData); - cb_data->self = self; - cb_data->session = session; - cb_data->cb = cb; - - IdentitySessionData *operation_data = g_slice_new0 (IdentitySessionData); - operation_data->method = method; - operation_data->cb_data = cb_data; - - identity_check_remote_registration (self); - _signon_object_call_when_ready (self, - identity_object_quark(), - identity_session_ready_cb, - operation_data); -} - diff --git a/libsignon-glib/signon-identity.h b/libsignon-glib/signon-identity.h deleted file mode 100644 index 507644f..0000000 --- a/libsignon-glib/signon-identity.h +++ /dev/null @@ -1,218 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _SIGNON_IDENTITY_H_ -#define _SIGNON_IDENTITY_H_ - -#include -#include -#include - -G_BEGIN_DECLS - -#define SIGNON_TYPE_IDENTITY (signon_identity_get_type ()) -#define SIGNON_IDENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIGNON_TYPE_IDENTITY, SignonIdentity)) -#define SIGNON_IDENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIGNON_TYPE_IDENTITY, SignonIdentityClass)) -#define SIGNON_IS_IDENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIGNON_TYPE_IDENTITY)) -#define SIGNON_IS_IDENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIGNON_TYPE_IDENTITY)) -#define SIGNON_IDENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIGNON_TYPE_IDENTITY, SignonIdentityClass)) - -typedef struct _SignonIdentityClass SignonIdentityClass; -typedef struct _SignonIdentityPrivate SignonIdentityPrivate; -typedef struct _SignonIdentity SignonIdentity; - -/** - * SignonIdentityClass: - * - * Opaque struct. Use the accessor functions below. - */ -struct _SignonIdentityClass -{ - GObjectClass parent_class; -}; - -/** - * SignonIdentity: - * - * Opaque struct. Use the accessor functions below. - */ -struct _SignonIdentity -{ - GObject parent_instance; - SignonIdentityPrivate *priv; -}; - -/** - * SignonIdentityVoidCb: - * @self: the #SignonIdentity. - * @error: a #GError if an error occurred, or %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Generic callback to be passed to several #SignonIdentity methods. - */ -typedef void (*SignonIdentityVoidCb) (SignonIdentity *self, - const GError *error, - gpointer user_data); - -/** - * SignonIdentityRemovedCb: - * - * Callback to be passed to signon_identity_remove(). - */ -typedef SignonIdentityVoidCb SignonIdentityRemovedCb; -/** - * SignonIdentitySignedOutCb: - * - * Callback to be passed to signon_identity_signout(). - */ -typedef SignonIdentityVoidCb SignonIdentitySignedOutCb; -/** - * SignonIdentityReferenceAddedCb: - * - * Callback to be passed to signon_identity_add_reference(). - */ -typedef SignonIdentityVoidCb SignonIdentityReferenceAddedCb; -/** - * SignonIdentityReferenceRemovedCb: - * - * Callback to be passed to signon_identity_remove_reference(). - */ -typedef SignonIdentityVoidCb SignonIdentityReferenceRemovedCb; - -GType signon_identity_get_type (void) G_GNUC_CONST; - -SignonIdentity *signon_identity_new_from_db (guint32 id, - const gchar *application_context); -SignonIdentity *signon_identity_new (const gchar *application_context); - -const GError *signon_identity_get_last_error (SignonIdentity *identity); - -SignonAuthSession *signon_identity_create_session(SignonIdentity *self, - const gchar *method, - GError **error); - -/** - * SignonIdentityStoreCredentialsCb: - * @self: the #SignonIdentity. - * @id: the numeric ID of the identity in the database. - * @error: a #GError if an error occurred, or %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_identity_store_credentials_with_args() or - * signon_identity_store_credentials_with_info(). - */ -typedef void (*SignonIdentityStoreCredentialsCb) (SignonIdentity *self, - guint32 id, - const GError *error, - gpointer user_data); - -void signon_identity_store_credentials_with_info(SignonIdentity *self, - const SignonIdentityInfo *info, - SignonIdentityStoreCredentialsCb cb, - gpointer user_data); - -void signon_identity_store_credentials_with_args(SignonIdentity *self, - const gchar *username, - const gchar *secret, - const gboolean store_secret, - const GHashTable *methods, - const gchar *caption, - const gchar* const *realms, - const SignonSecurityContext *owner, - const SignonSecurityContextList *access_control_list, - SignonIdentityType type, - SignonIdentityStoreCredentialsCb cb, - gpointer user_data); - -/** - * SignonIdentityVerifyCb: - * @self: the #SignonIdentity. - * @valid: whether the secret is valid. - * @error: a #GError if an error occurred, or %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_identity_verify_secret(). - */ -typedef void (*SignonIdentityVerifyCb) (SignonIdentity *self, - gboolean valid, - const GError *error, - gpointer user_data); - -void signon_identity_verify_secret(SignonIdentity *self, - const gchar *secret, - SignonIdentityVerifyCb cb, - gpointer user_data); - -/** - * SignonIdentityInfoCb: - * @self: the #SignonIdentity. - * @info: the #SignonIdentityInfo for @self. - * @error: a #GError if an error occurred, or %NULL otherwise. - * @user_data: the user data that was passed when installing this callback. - * - * Callback to be passed to signon_identity_query_info(). - */ -typedef void (*SignonIdentityInfoCb) (SignonIdentity *self, - const SignonIdentityInfo *info, - const GError *error, - gpointer user_data); - -void signon_identity_query_info(SignonIdentity *self, - SignonIdentityInfoCb cb, - gpointer user_data); - -void signon_identity_remove(SignonIdentity *self, - SignonIdentityRemovedCb cb, - gpointer user_data); - -void signon_identity_signout(SignonIdentity *self, - SignonIdentitySignedOutCb cb, - gpointer user_data); - -void signon_identity_add_reference(SignonIdentity *self, - const gchar *reference, - SignonIdentityReferenceAddedCb cb, - gpointer user_data); - -void signon_identity_remove_reference(SignonIdentity *self, - const gchar *reference, - SignonIdentityReferenceRemovedCb cb, - gpointer user_data); - -typedef void (*SignonIdentitySessionReadyCb) (SignonAuthSession *self, - GError *error, - GDBusConnection *connection, - const gchar *bus_name, - const gchar *object_path); -void signon_identity_get_auth_session(SignonIdentity *self, - SignonAuthSession *session, - const gchar *method, - SignonIdentitySessionReadyCb cb); - - -G_END_DECLS - -#endif /* _SIGNON_IDENTITY_H_ */ diff --git a/libsignon-glib/signon-internals.h b/libsignon-glib/signon-internals.h deleted file mode 100644 index 3201870..0000000 --- a/libsignon-glib/signon-internals.h +++ /dev/null @@ -1,180 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * Copyright (C) 2012 Intel Corporation. - * - * Contact: Alberto Mardegan - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _SIGNONINTERNALS_H_ -#define _SIGNONINTERNALS_H_ - -#include "signon-security-context.h" - -#ifndef SIGNON_TRACE -#define SIGNON_TRACE -#endif - -#ifdef SIGNON_TRACE - #define DEBUG(format...) g_debug (G_STRLOC ": " format) -#else - #define DEBUG(...) do {} while (0) -#endif - -/* - * Common DBUS definitions - * */ -#define SIGNOND_SERVICE_PREFIX "com.google.code.AccountsSSO.gSingleSignOn" -#define SIGNOND_SERVICE SIGNOND_SERVICE_PREFIX - -#define SIGNOND_DAEMON_OBJECTPATH "/com/google/code/AccountsSSO/gSingleSignOn" -#define SIGNOND_DAEMON_INTERFACE SIGNOND_SERVICE_PREFIX ".AuthService" -#define SIGNOND_IDENTITY_INTERFACE SIGNOND_SERVICE_PREFIX ".Identity" -#define SIGNOND_AUTH_SESSION_INTERFACE SIGNOND_SERVICE_PREFIX ".AuthSession" - -#define SIGNOND_ERR_PREFIX SIGNOND_SERVICE_PREFIX ".Error." - -/* - * Common server/client identity info strings - * */ -#define SIGNOND_IDENTITY_INFO_ID "Id" -#define SIGNOND_IDENTITY_INFO_USERNAME "UserName" -#define SIGNOND_IDENTITY_INFO_SECRET "Secret" -#define SIGNOND_IDENTITY_INFO_STORESECRET "StoreSecret" -#define SIGNOND_IDENTITY_INFO_CAPTION "Caption" -#define SIGNOND_IDENTITY_INFO_REALMS "Realms" -#define SIGNOND_IDENTITY_INFO_AUTHMETHODS "AuthMethods" -#define SIGNOND_IDENTITY_INFO_OWNER "Owner" -#define SIGNOND_IDENTITY_INFO_ACL "ACL" -#define SIGNOND_IDENTITY_INFO_TYPE "Type" -#define SIGNOND_IDENTITY_INFO_REFCOUNT "RefCount" -#define SIGNOND_IDENTITY_INFO_VALIDATED "Validated" -#define SIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET "UserNameSecret" - -/* - * Common server/client sides error names and messages - * */ -#define SIGNOND_UNKNOWN_ERR_NAME SIGNOND_ERR_PREFIX "Unknown" -#define SIGNOND_INTERNAL_SERVER_ERR_NAME SIGNOND_ERR_PREFIX "InternalServer" -#define SIGNOND_INTERNAL_COMMUNICATION_ERR_NAME \ - SIGNOND_ERR_PREFIX "InternalCommunication" -#define SIGNOND_PERMISSION_DENIED_ERR_NAME \ - SIGNOND_ERR_PREFIX "PermissionDenied" -#define SIGNOND_METHOD_OR_MECHANISM_NOT_ALLOWED_ERR_NAME \ - SIGNOND_ERR_PREFIX "MethodOrMechanismNotAllowed" -#define SIGNOND_ENCRYPTION_FAILED_ERR_NAME \ - SIGNOND_ERR_PREFIX "EncryptionFailed" -#define SIGNOND_METHOD_NOT_KNOWN_ERR_NAME SIGNOND_ERR_PREFIX "MethodNotKnown" -#define SIGNOND_SERVICE_NOT_AVAILABLE_ERR_NAME \ - SIGNOND_ERR_PREFIX "ServiceNotAvailable" -#define SIGNOND_INVALID_QUERY_ERR_NAME SIGNOND_ERR_PREFIX "InvalidQuery" -#define SIGNOND_METHOD_NOT_AVAILABLE_ERR_NAME \ - SIGNOND_ERR_PREFIX "MethodNotAvailable" -#define SIGNOND_IDENTITY_NOT_FOUND_ERR_NAME \ - SIGNOND_ERR_PREFIX "IdentityNotFound" -#define SIGNOND_STORE_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "StoreFailed" -#define SIGNOND_REMOVE_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "RemoveFailed" -#define SIGNOND_SIGNOUT_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "SignOutFailed" -#define SIGNOND_IDENTITY_OPERATION_CANCELED_ERR_NAME \ - SIGNOND_ERR_PREFIX "IdentityOperationCanceled" -#define SIGNOND_CREDENTIALS_NOT_AVAILABLE_ERR_NAME \ - SIGNOND_ERR_PREFIX "CredentialsNotAvailable" -#define SIGNOND_REFERENCE_NOT_FOUND_ERR_NAME \ - SIGNOND_ERR_PREFIX "ReferenceNotFound" -#define SIGNOND_MECHANISM_NOT_AVAILABLE_ERR_NAME \ - SIGNOND_ERR_PREFIX "MechanismNotAvailable" -#define SIGNOND_MISSING_DATA_ERR_NAME SIGNOND_ERR_PREFIX "MissingData" -#define SIGNOND_INVALID_CREDENTIALS_ERR_NAME \ - SIGNOND_ERR_PREFIX "InvalidCredentials" -#define SIGNOND_NOT_AUTHORIZED_ERR_NAME SIGNOND_ERR_PREFIX "NotAuthorized" -#define SIGNOND_WRONG_STATE_ERR_NAME SIGNOND_ERR_PREFIX "WrongState" -#define SIGNOND_OPERATION_NOT_SUPPORTED_ERR_NAME \ - SIGNOND_ERR_PREFIX "OperationNotSupported" -#define SIGNOND_NO_CONNECTION_ERR_NAME SIGNOND_ERR_PREFIX "NoConnection" -#define SIGNOND_NETWORK_ERR_NAME SIGNOND_ERR_PREFIX "Network" -#define SIGNOND_SSL_ERR_NAME SIGNOND_ERR_PREFIX "Ssl" -#define SIGNOND_RUNTIME_ERR_NAME SIGNOND_ERR_PREFIX "Runtime" -#define SIGNOND_SESSION_CANCELED_ERR_NAME SIGNOND_ERR_PREFIX "SessionCanceled" -#define SIGNOND_TIMED_OUT_ERR_NAME SIGNOND_ERR_PREFIX "TimedOut" -#define SIGNOND_USER_INTERACTION_ERR_NAME SIGNOND_ERR_PREFIX "UserInteraction" -#define SIGNOND_OPERATION_FAILED_ERR_NAME SIGNOND_ERR_PREFIX "OperationFailed" -#define SIGNOND_TOS_NOT_ACCEPTED_ERR_NAME SIGNOND_ERR_PREFIX "TOSNotAccepted" -#define SIGNOND_FORGOT_PASSWORD_ERR_NAME SIGNOND_ERR_PREFIX "ForgotPassword" -#define SIGNOND_INCORRECT_DATE_ERR_NAME SIGNOND_ERR_PREFIX "IncorrectDate" -#define SIGNOND_USER_ERROR_ERR_NAME SIGNOND_ERR_PREFIX "User" - - -#include "signon-identity-info.h" - -G_BEGIN_DECLS - -enum SignonAuthSessionState { - SIGNON_AUTH_SESSION_STATE_NOT_STARTED = 0, /**< No message. */ - SIGNON_AUTH_SESSION_STATE_RESOLVING_HOST, /**< Resolving remote server - host name. */ - SIGNON_AUTH_SESSION_STATE_CONNECTING, /**< Connecting to remote - server. */ - SIGNON_AUTH_SESSION_STATE_SENDING_DATA, /**< Sending data to remote - server. */ - SIGNON_AUTH_SESSION_STATE_WAITING_REPLY, /**< Waiting reply from remote - server. */ - SIGNON_AUTH_SESSION_STATE_USER_PENDING, /**< Waiting response from - user. */ - SIGNON_AUTH_SESSION_STATE_UI_REFRESHING, /**< Refreshing ui request. */ - SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, /**< Waiting another process - to start. */ - SIGNON_AUTH_SESSION_STATE_STARTED, /**< Authentication session is - started. */ - SIGNON_AUTH_SESSION_STATE_PROCESS_CANCELING, /**< Canceling.current - process. */ - SIGNON_AUTH_SESSION_STATE_PROCESS_DONE, /**< Authentication - completed. */ - SIGNON_AUTH_SESSION_STATE_CUSTOM, /**< Custom message. */ - SIGNON_AUTH_SESSION_STATE_LAST -}; - -struct _SignonIdentityInfo -{ - gint id; - gchar *username; - gchar *secret; - gchar *caption; - gboolean store_secret; - GHashTable *methods; - gchar **realms; - SignonSecurityContext *owner; - SignonSecurityContextList *access_control_list; - gint type; -}; - -G_GNUC_INTERNAL -SignonIdentityInfo * -signon_identity_info_new_from_variant (GVariant *variant); - -G_GNUC_INTERNAL -GVariant * -signon_identity_info_to_variant (const SignonIdentityInfo *self); - -G_END_DECLS - -#endif - diff --git a/libsignon-glib/signon-marshal.list b/libsignon-glib/signon-marshal.list deleted file mode 100644 index 70ef299..0000000 --- a/libsignon-glib/signon-marshal.list +++ /dev/null @@ -1,2 +0,0 @@ -VOID:INT,STRING - diff --git a/libsignon-glib/signon-security-context.c b/libsignon-glib/signon-security-context.c deleted file mode 100644 index 8985ed4..0000000 --- a/libsignon-glib/signon-security-context.c +++ /dev/null @@ -1,325 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2012-2013 Intel Corporation. - * - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "signon-security-context.h" - -static void -_security_context_free (gpointer ptr) -{ - SignonSecurityContext *ctx = (SignonSecurityContext *) ptr; - - signon_security_context_free (ctx); -} - -/** - * signon_security_context_new: - * - * Allocates a new security context item. - * - * Returns: (transfer full) allocated #SignonSecurityContext. - */ -SignonSecurityContext * -signon_security_context_new () -{ - SignonSecurityContext *ctx; - - ctx = g_slice_new0 (SignonSecurityContext); - ctx->sys_ctx = g_strdup (""); - ctx->app_ctx = g_strdup (""); - - return ctx; -} - -/** - * signon_security_context_new_from_vaues: - * @system_context: system security context (such as SMACK/MSSF label/token). - * @application_context: application security context (such as a script name). - * - * Allocates and initializes a new security context item. - * - * Returns: (transfer full) allocated #SignonSecurityContext. - */ -SignonSecurityContext * -signon_security_context_new_from_values (const gchar *system_context, - const gchar *application_context) -{ - SignonSecurityContext *ctx; - - g_return_val_if_fail (system_context != NULL, NULL); - - ctx = g_slice_new0 (SignonSecurityContext); - ctx->sys_ctx = g_strdup (system_context); - if (application_context) - ctx->app_ctx = g_strdup (application_context); - else - ctx->app_ctx = g_strdup (""); - - return ctx; -} - -/** - * signon_security_context_copy: - * @src_ctx: source security context to copy. - * - * Copy a security context item. - * - * Returns: (transfer full) a copy of the #SignonSecurityContex item. - */ -SignonSecurityContext * -signon_security_context_copy (const SignonSecurityContext *src_ctx) -{ - if (!src_ctx) - return NULL; - - return signon_security_context_new_from_values (src_ctx->sys_ctx, - src_ctx->app_ctx); -} - -/** - * signon_security_context_free: - * @ctx: #SignonSecurityContext to be freed. - * - * Frees a security context item. - */ -void -signon_security_context_free (SignonSecurityContext *ctx) -{ - if (ctx == NULL) return; - - g_free (ctx->sys_ctx); - g_free (ctx->app_ctx); - g_slice_free (SignonSecurityContext, ctx); -} - -/** - * signon_security_context_set_system_context: - * @ctx: #SignonSecurityContext item. - * @system_context: system security context. - * - * Sets the system context part (such as SMACK label or MSSF token) of the - * #SignonSecurityContext. - */ -void -signon_security_context_set_system_context (SignonSecurityContext *ctx, - const gchar *system_context) -{ - g_return_if_fail (ctx != NULL); - - g_free (ctx->sys_ctx); - ctx->sys_ctx = g_strdup (system_context); -} - -/** - * signon_security_context_get_system_context: - * @ctx: #SignonSecurityContext item. - * - * Get the system context part (such as SMACK label or MSSF token) of the - * #SignonSecurityContext. - * - * Returns: (transfer none) system context. - */ -const gchar * -signon_security_context_get_system_context (const SignonSecurityContext *ctx) -{ - g_return_val_if_fail (ctx != NULL, NULL); - - return ctx->sys_ctx; -} - -/** - * signon_security_context_set_application_context: - * @ctx: #SignonSecurityContext item. - * @application_context: application security context. - * - * Sets the application context part (such as a script name or a web page) of - * the #SignonSecurityContext. - */ -void -signon_security_context_set_application_context (SignonSecurityContext *ctx, - const gchar *application_context) -{ - g_return_if_fail (ctx != NULL); - - g_free (ctx->app_ctx); - ctx->app_ctx = g_strdup (application_context); -} - -/** - * signon_security_context_get_application_context: - * @ctx: #SignonSecurityContext item. - * - * Get the application context part (such as script name or a web page) of - * the #SignonSecurityContext. - * - * Returns: (transfer none) application context. - */ -const gchar * -signon_security_context_get_application_context ( - const SignonSecurityContext *ctx) -{ - g_return_val_if_fail (ctx != NULL, NULL); - - return ctx->app_ctx; -} - -/** - * signon_security_conetxt_build_variant: - * @ctx: #SignonSecurityContext item. - * - * Build a GVariant of type "(ss)" from a #SignonSecurityContext item. - * - * Returns: (transfer full) GVariant construct of a #SignonSecurityContext. - */ -GVariant * -signon_security_context_build_variant (const SignonSecurityContext *ctx) -{ - GVariant *variant; - - g_return_val_if_fail (ctx != NULL, NULL); - - variant = g_variant_new ("(ss)", - ctx->sys_ctx ? ctx->sys_ctx : "", - ctx->app_ctx ? ctx->app_ctx : ""); - - return variant; -} - -/** - * signon_security_context_deconstruct_variant: - * @variant: GVariant item with a #SignonSecurityContext construct. - * - * Builds a #SignonSecurityContext item from a GVariant of type "(ss)". - * - * Returns: (transfer full) #SignonSecurityContext item. - */ -SignonSecurityContext * -signon_security_context_deconstruct_variant (GVariant *variant) -{ - gchar *sys_ctx = NULL; - gchar *app_ctx = NULL; - SignonSecurityContext *ctx; - - g_return_val_if_fail (variant != NULL, NULL); - - g_variant_get (variant, "(ss)", &sys_ctx, &app_ctx); - ctx = signon_security_context_new_from_values (sys_ctx, app_ctx); - g_free (sys_ctx); - g_free (app_ctx); - return ctx; -} - -/** - * signon_security_context_list_build_variant: - * @list: #SignonSecurityContextList item. - * - * Builds a GVariant of type "a(ss)" from a GList of #SignonSecurityContext - * items. - * - * Returns: (transfer full) GVariant construct of a #SignonSecurityContextList. - */ -GVariant * -signon_security_context_list_build_variant ( - const SignonSecurityContextList *list) -{ - GVariantBuilder builder; - GVariant *variant; - SignonSecurityContext *ctx; - - g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); - for ( ; list != NULL; list = g_list_next (list)) - { - ctx = (SignonSecurityContext *) list->data; - g_variant_builder_add_value (&builder, - signon_security_context_build_variant (ctx)); - } - variant = g_variant_builder_end (&builder); - - return variant; -} - -/** - * signon_security_context_list_deconstruct_variant: - * @variant: GVariant item with a list of security context tuples. - * - * Builds a GList of #SignonSecurityContext items from a GVariant of type - * "a(ss)". - * - * Returns: (transfer full) #SignonSecurityContextList item. - */ -SignonSecurityContextList * -signon_security_context_list_deconstruct_variant (GVariant *variant) -{ - SignonSecurityContextList *list = NULL; - GVariantIter iter; - GVariant *value; - - g_return_val_if_fail (variant != NULL, NULL); - - g_variant_iter_init (&iter, variant); - while ((value = g_variant_iter_next_value (&iter))) - { - list = g_list_append ( - list, signon_security_context_deconstruct_variant (value)); - g_variant_unref (value); - } - - return list; -} - -/** - * signon_security_context_list_copy: - * @src_list: source #SignonSecurityContextList. - * - * Copies a GList of #SignonSecurityContext items. - * - * Returns: (transfer full) #SignonSecurityContextList item. - */ -SignonSecurityContextList * -signon_security_context_list_copy (const SignonSecurityContextList *src_list) -{ - SignonSecurityContext *ctx; - SignonSecurityContextList *dst_list = NULL; - - for ( ; src_list != NULL; src_list = g_list_next (src_list)) - { - ctx = (SignonSecurityContext *) src_list->data; - dst_list = g_list_append ( - dst_list, signon_security_context_copy (ctx)); - } - - return dst_list; -} - -/** - * signon_security_context_list_free: - * @seclist: (transfer full) #SignonSecurityContextList item. - * - * Frees all items and the GList of #SignonSecurityContext. - */ -void -signon_security_context_list_free (SignonSecurityContextList *seclist) -{ - g_list_free_full (seclist, _security_context_free); -} - diff --git a/libsignon-glib/signon-security-context.h b/libsignon-glib/signon-security-context.h deleted file mode 100644 index 9c4662a..0000000 --- a/libsignon-glib/signon-security-context.h +++ /dev/null @@ -1,85 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2012 Intel Corporation. - * - * Contact: Jussi Laako - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _SIGNON_SECURITY_CONTEXT_H_ -#define _SIGNON_SECURITY_CONTEXT_H_ - -#include - -G_BEGIN_DECLS - -/** - * Security context descriptor. - * - * Practically a string tuple. - * - * @sys_ctx: system context, such as SMACK-label, MSSF token or just a - * binary path. - * @app_ctx: application context, such as a script or a web page. - */ -typedef struct _SignonSecurityContext -{ - gchar *sys_ctx; - gchar *app_ctx; -} SignonSecurityContext; - -/** - * GList of #SignonSecurityContext items. - */ -typedef GList SignonSecurityContextList; - -SignonSecurityContext * signon_security_context_new (); -SignonSecurityContext * signon_security_context_new_from_values ( - const gchar *system_context, - const gchar *application_context); -void signon_security_context_free (SignonSecurityContext *ctx); -SignonSecurityContext * signon_security_context_copy ( - const SignonSecurityContext *src_ctx); -void signon_security_context_set_system_context (SignonSecurityContext *ctx, - const gchar *system_context); -const gchar * signon_security_context_get_system_context ( - const SignonSecurityContext *ctx); -void signon_security_context_set_application_context ( - SignonSecurityContext *ctx, - const gchar *application_context); -const gchar * signon_security_context_get_application_context ( - const SignonSecurityContext *ctx); -GVariant * signon_security_context_build_variant ( - const SignonSecurityContext *ctx); -SignonSecurityContext * signon_security_context_deconstruct_variant ( - GVariant *variant); - -GVariant * signon_security_context_list_build_variant ( - const SignonSecurityContextList *list); -SignonSecurityContextList * signon_security_context_list_deconstruct_variant ( - GVariant *variant); - -SignonSecurityContextList * signon_security_context_list_copy ( - const SignonSecurityContextList *src_list); -void signon_security_context_list_free (SignonSecurityContextList *seclist); - -G_END_DECLS - -#endif /* _SIGNON_SECURITY_CONTEXT_H_ */ - diff --git a/libsignon-glib/signon-types.h b/libsignon-glib/signon-types.h deleted file mode 100644 index 7318baf..0000000 --- a/libsignon-glib/signon-types.h +++ /dev/null @@ -1,42 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2012 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef SIGNON_TYPES_H -#define SIGNON_TYPES_H - -#include - -G_BEGIN_DECLS - -#ifdef SIGNON_DISABLE_DEPRECATION_WARNINGS -#define SIGNON_DEPRECATED -#define SIGNON_DEPRECATED_FOR(x) -#else -#define SIGNON_DEPRECATED G_DEPRECATED -#define SIGNON_DEPRECATED_FOR(x) G_DEPRECATED_FOR(x) -#endif - -G_END_DECLS - -#endif /* SIGNON_TYPES_H */ diff --git a/libsignon-glib/signon-utils.c b/libsignon-glib/signon-utils.c deleted file mode 100644 index a57ea0a..0000000 --- a/libsignon-glib/signon-utils.c +++ /dev/null @@ -1,122 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include "signon-utils.h" -#include - -static const GVariantType * -signon_gtype_to_variant_type (GType type) -{ - switch (type) - { - case G_TYPE_STRING: return G_VARIANT_TYPE_STRING; - case G_TYPE_BOOLEAN: return G_VARIANT_TYPE_BOOLEAN; - case G_TYPE_UCHAR: return G_VARIANT_TYPE_BYTE; - case G_TYPE_INT: return G_VARIANT_TYPE_INT32; - case G_TYPE_UINT: return G_VARIANT_TYPE_UINT32; - case G_TYPE_INT64: return G_VARIANT_TYPE_INT64; - case G_TYPE_UINT64: return G_VARIANT_TYPE_UINT64; - case G_TYPE_DOUBLE: return G_VARIANT_TYPE_DOUBLE; - default: - if (type == G_TYPE_STRV) return G_VARIANT_TYPE_STRING_ARRAY; - - g_critical ("Unsupported type %s", g_type_name (type)); - return NULL; - } -} - -GValue * -signon_gvalue_new (GType type) -{ - GValue *value = g_slice_new0 (GValue); - g_value_init (value, type); - return value; -} - -void signon_gvalue_free (gpointer val) -{ - g_return_if_fail (G_IS_VALUE(val)); - - GValue *value = (GValue*)val; - g_value_unset (value); - g_slice_free (GValue, value); -} - -GHashTable *signon_hash_table_from_variant (GVariant *variant) -{ - GHashTable *hash_table; - GVariantIter iter; - GVariant *value; - gchar *key; - - if (variant == NULL) return NULL; - - hash_table = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - signon_gvalue_free); - g_variant_iter_init (&iter, variant); - while (g_variant_iter_next (&iter, "{sv}", &key, &value)) - { - GValue *val = g_slice_new0 (GValue); - g_dbus_gvariant_to_gvalue (value, val); - g_variant_unref (value); - - g_hash_table_insert (hash_table, key, val); - } - return hash_table; -} - -GVariant *signon_hash_table_to_variant (const GHashTable *hash_table) -{ - GVariantBuilder builder; - GHashTableIter iter; - const gchar *key; - const GValue *value; - - if (hash_table == NULL) return NULL; - - g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - - g_hash_table_iter_init (&iter, (GHashTable *)hash_table); - while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value)) - { - GVariant *val; - - if (G_VALUE_TYPE (value) == G_TYPE_VARIANT) - { - val = g_value_get_variant (value); - g_variant_builder_add (&builder, "{sv}", key, val); - } - else - { - const GVariantType *type; - type = signon_gtype_to_variant_type (G_VALUE_TYPE (value)); - val = g_dbus_gvalue_to_gvariant (value, type); - g_variant_builder_add (&builder, "{sv}", key, val); - g_variant_unref (val); - } - } - return g_variant_builder_end (&builder); -} diff --git a/libsignon-glib/signon-utils.h b/libsignon-glib/signon-utils.h deleted file mode 100644 index 32a404b..0000000 --- a/libsignon-glib/signon-utils.h +++ /dev/null @@ -1,45 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2009-2010 Nokia Corporation. - * Copyright (C) 2012 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef _SIGNON_UTILS_H_ -#define _SIGNON_UTILS_H_ - -#include - -#define SIGNON_IS_NOT_CANCELLED(error) \ - (error == NULL || \ - error->domain != G_IO_ERROR || \ - error->code != G_IO_ERROR_CANCELLED) - -G_GNUC_INTERNAL -GValue *signon_gvalue_new (GType type); -G_GNUC_INTERNAL -void signon_gvalue_free (gpointer val); - -G_GNUC_INTERNAL -GHashTable *signon_hash_table_from_variant (GVariant *variant); -G_GNUC_INTERNAL -GVariant *signon_hash_table_to_variant (const GHashTable *hash_table); - -#endif //_SIGNON_UTILS_H_ diff --git a/libsignon-glib/signon.vapi b/libsignon-glib/signon.vapi deleted file mode 100644 index fb1c23e..0000000 --- a/libsignon-glib/signon.vapi +++ /dev/null @@ -1,166 +0,0 @@ -/* signon.vapi generated by vapigen, do not modify. */ - -[CCode (cprefix = "Signon", gir_namespace = "Signon", gir_version = "1.0", lower_case_cprefix = "signon_")] -namespace Signon { - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", type_id = "signon_auth_service_get_type ()")] - public class AuthService : GLib.Object { - [CCode (has_construct_function = false)] - public AuthService (); - public void query_mechanisms (string method, Signon.QueryMechanismCb cb); - public void query_methods (Signon.QueryMethodsCb cb); - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", type_id = "signon_auth_session_get_type ()")] - public class AuthSession : GLib.Object { - [CCode (has_construct_function = false)] - public AuthSession (uint id, string method_name) throws GLib.Error; - public void cancel (); - public unowned string get_method (); - public void process (GLib.HashTable session_data, string mechanism, Signon.AuthSessionProcessCb cb); - public void query_available_mechanisms (string wanted_mechanisms, Signon.AuthSessionQueryAvailableMechanismsCb cb); - public signal void state_changed (int object, string p0); - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", type_id = "signon_identity_get_type ()")] - public class Identity : GLib.Object { - [CCode (has_construct_function = false)] - public Identity (); - public void add_reference (string reference, Signon.IdentityReferenceAddedCb cb, void* user_data); - public Signon.AuthSession create_session (string method) throws GLib.Error; - [CCode (has_construct_function = false)] - public Identity.from_db (uint32 id); - public unowned GLib.Error get_last_error (); - public void query_info (Signon.IdentityInfoCb cb); - public void remove (Signon.IdentityRemovedCb cb, void* user_data); - public void remove_reference (string reference, Signon.IdentityReferenceRemovedCb cb, void* user_data); - public void store_credentials_with_args (string username, string secret, bool store_secret, GLib.HashTable methods, string caption, string realms, string access_control_list, Signon.IdentityType type, Signon.IdentityStoreCredentialsCb cb); - public void store_credentials_with_info (Signon.IdentityInfo info, Signon.IdentityStoreCredentialsCb cb); - public void verify_secret (string secret, Signon.IdentityVerifyCb cb); - [NoAccessorMethod] - public uint id { get; set; } - [HasEmitter] - public signal void signout (); - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "signon_identity_info_get_type ()")] - [Compact] - public class IdentityInfo { - [CCode (has_construct_function = false)] - public IdentityInfo (); - public Signon.IdentityInfo copy (); - public void free (); - [CCode (array_length = false, array_null_terminated = true)] - public unowned string[] get_access_control_list (); - public unowned string get_caption (); - public int get_id (); - public Signon.IdentityType get_identity_type (); - public unowned GLib.HashTable get_methods (); - [CCode (array_length = false, array_null_terminated = true)] - public unowned string[] get_realms (); - public bool get_storing_secret (); - public unowned string get_username (); - public void remove_method (string method); - public void set_access_control_list (string access_control_list); - public void set_caption (string caption); - public void set_identity_type (Signon.IdentityType type); - public void set_method (string method, string mechanisms); - public void set_realms (string realms); - public void set_secret (string secret, bool store_secret); - public void set_username (string username); - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cprefix = "SIGNON_IDENTITY_TYPE_")] - [Flags] - public enum IdentityType { - OTHER, - APP, - WEB, - NETWORK - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cprefix = "SIGNON_POLICY_")] - public enum SessionDataUiPolicy { - DEFAULT, - REQUEST_PASSWORD, - NO_USER_INTERACTION, - VALIDATION - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cprefix = "SIGNON_ERROR_")] - public errordomain Error { - UNKNOWN, - INTERNAL_SERVER, - INTERNAL_COMMUNICATION, - PERMISSION_DENIED, - METHOD_NOT_KNOWN, - SERVICE_NOT_AVAILABLE, - INVALID_QUERY, - METHOD_NOT_AVAILABLE, - IDENTITY_NOT_FOUND, - STORE_FAILED, - REMOVE_FAILED, - SIGNOUT_FAILED, - IDENTITY_OPERATION_CANCELED, - CREDENTIALS_NOT_AVAILABLE, - REFERENCE_NOT_FOUND, - MECHANISM_NOT_AVAILABLE, - MISSING_DATA, - INVALID_CREDENTIALS, - NOT_AUTHORIZED, - WRONG_STATE, - OPERATION_NOT_SUPPORTED, - NO_CONNECTION, - NETWORK, - SSL, - RUNTIME, - SESSION_CANCELED, - TIMED_OUT, - USER_INTERACTION, - OPERATION_FAILED, - ENCRYPTION_FAILED, - TOS_NOT_ACCEPTED, - FORGOT_PASSWORD, - METHOD_OR_MECHANISM_NOT_ALLOWED, - INCORRECT_DATE, - USER_ERROR; - public static GLib.Quark quark (); - } - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void AuthSessionProcessCb (Signon.AuthSession self, owned GLib.HashTable session_data, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void AuthSessionQueryAvailableMechanismsCb (Signon.AuthSession self, [CCode (array_length = false, array_null_terminated = true)] owned string[] mechanisms, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void AuthSessionQueryAvailableMethodsCb (Signon.AuthSession self, [CCode (array_length = false, array_null_terminated = true)] owned string[] mechanisms, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void IdentityInfoCb (Signon.Identity self, Signon.IdentityInfo info, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 2.9)] - public delegate void IdentityReferenceAddedCb (Signon.Identity self, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 2.9)] - public delegate void IdentityReferenceRemovedCb (Signon.Identity self, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 2.9)] - public delegate void IdentityRemovedCb (Signon.Identity self, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 2.9)] - public delegate void IdentitySignedOutCb (Signon.Identity self, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void IdentityStoreCredentialsCb (Signon.Identity self, uint32 id, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void IdentityVerifyCb (Signon.Identity self, bool valid, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 2.9)] - public delegate void IdentityVoidCb (Signon.Identity self, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 4.9)] - public delegate void QueryMechanismCb (Signon.AuthService auth_service, string method, [CCode (array_length = false, array_null_terminated = true)] owned string[] mechanisms, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", instance_pos = 3.9)] - public delegate void QueryMethodsCb (Signon.AuthService auth_service, [CCode (array_length = false, array_null_terminated = true)] owned string[] methods, GLib.Error error); - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_CAPTION")] - public const string SESSION_DATA_CAPTION; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_PROXY")] - public const string SESSION_DATA_PROXY; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_REALM")] - public const string SESSION_DATA_REALM; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_RENEW_TOKEN")] - public const string SESSION_DATA_RENEW_TOKEN; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_SECRET")] - public const string SESSION_DATA_SECRET; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_TIMEOUT")] - public const string SESSION_DATA_TIMEOUT; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_UI_POLICY")] - public const string SESSION_DATA_UI_POLICY; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_USERNAME")] - public const string SESSION_DATA_USERNAME; - [CCode (cheader_filename = "libsignon-glib/signon-glib.h", cname = "SIGNON_SESSION_DATA_WINDOW_ID")] - public const string SESSION_DATA_WINDOW_ID; -} diff --git a/libsignon-glib/sso-auth-service.c b/libsignon-glib/sso-auth-service.c deleted file mode 100644 index e5c51f3..0000000 --- a/libsignon-glib/sso-auth-service.c +++ /dev/null @@ -1,143 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2012 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include -#include "signon-errors.h" -#include "signon-internals.h" -#include "sso-auth-service.h" - -static GHashTable *thread_objects = NULL; -static GMutex map_mutex; - -static SsoAuthService * -get_singleton () -{ - SsoAuthService *object = NULL; - - g_mutex_lock (&map_mutex); - - if (thread_objects != NULL) - { - GWeakRef *ref; - ref = g_hash_table_lookup (thread_objects, g_thread_self ()); - if (ref != NULL) - { - object = g_weak_ref_get (ref); - } - } - - g_mutex_unlock (&map_mutex); - return object; -} - -static void -g_thread_ref_free (GWeakRef *data) -{ - g_slice_free (GWeakRef, data); -} - -static void -set_singleton (SsoAuthService *object) -{ - g_return_if_fail (IS_SSO_AUTH_SERVICE (object)); - - g_mutex_lock (&map_mutex); - - if (thread_objects == NULL) - { - thread_objects = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify)g_thread_ref_free); - } - - if (object != NULL) - { - GWeakRef *ref = g_slice_new (GWeakRef); - g_weak_ref_init (ref, object); - g_hash_table_insert (thread_objects, g_thread_self (), ref); - } - - g_mutex_unlock (&map_mutex); -} - -static void -_on_auth_service_destroyed (gpointer data, GObject *obj) -{ - (void)data; - (void)obj; - g_mutex_lock (&map_mutex); - if (thread_objects) - { - g_hash_table_unref (thread_objects); - thread_objects = NULL; - } - g_mutex_unlock (&map_mutex); -} - - -SsoAuthService * -sso_auth_service_get_instance () -{ - SsoAuthService *sso_auth_service = NULL; - GDBusConnection *connection = NULL; - GError *error = NULL; - - sso_auth_service = get_singleton (); - if (sso_auth_service != NULL) return sso_auth_service; - -#ifdef USE_P2P - connection = g_dbus_connection_new_for_address_sync (SIGNOND_BUS_ADDRESS, - G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, - NULL, - NULL, - &error); -#else - connection = g_bus_get_sync (SIGNOND_BUS_TYPE, NULL, &error); -#endif - /* Create the object */ - sso_auth_service = - sso_auth_service_proxy_new_sync (connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, -#ifdef USE_P2P - NULL, -#else - SIGNOND_SERVICE, -#endif - SIGNOND_DAEMON_OBJECTPATH, - NULL, - &error); - g_object_weak_ref (G_OBJECT (sso_auth_service), _on_auth_service_destroyed, sso_auth_service); - if (G_LIKELY (error == NULL)) { - set_singleton (sso_auth_service); - } - else - { - g_warning ("Couldn't activate signond: %s", error->message); - g_clear_error (&error); - } - - /* While at it, register the error mapping with GDBus */ - signon_error_quark (); - - return sso_auth_service; -} diff --git a/libsignon-glib/sso-auth-service.h b/libsignon-glib/sso-auth-service.h deleted file mode 100644 index 69f83d5..0000000 --- a/libsignon-glib/sso-auth-service.h +++ /dev/null @@ -1,37 +0,0 @@ -/* vi: set et sw=4 ts=4 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of libsignon-glib - * - * Copyright (C) 2012 Canonical Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _SSO_AUTH_SERVICE_H_ -#define _SSO_AUTH_SERVICE_H_ - -#include "sso-auth-service-gen.h" - -G_BEGIN_DECLS - -G_GNUC_INTERNAL -SsoAuthService *sso_auth_service_get_instance (); - -G_END_DECLS - -#endif /* _SSO_AUTH_SERVICE_H_ */ diff --git a/packaging/libgsignon-glib.spec b/packaging/libgsignon-glib.spec new file mode 100644 index 0000000..d9395b1 --- /dev/null +++ b/packaging/libgsignon-glib.spec @@ -0,0 +1,70 @@ +Name: libgsignon-glib +Summary: GLib API for the SSO framework +Version: 2.0.0 +Release: 1 +Group: System/Libraries +License: LGPL +Source: %{name}-%{version}.tar.bz2 +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: pkgconfig(gtk-doc) +BuildRequires: pkgconfig(check) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gobject-2.0) +BuildRequires: pkgconfig(gio-2.0) + +%description +%{summary}. + + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +%{summary}. + + +%prep +%setup -q -n %{name}-%{version} +gtkdocize +autoreconf -f -i + + +%build +%configure --enable-gtk-doc --enable-gtk-doc-html --enable-python +make #%{?_smp_mflags} + + +%install +rm -rf %{buildroot} +%make_install + + +%post -p /sbin/ldconfig + + +%postun -p /sbin/ldconfig + + +%files +%defattr(-,root,root,-) +%doc AUTHORS COPYING ChangeLog INSTALL NEWS README +%{_libdir}/%{name}.so.* + + +%files devel +%defattr(-,root,root,-) +%{_includedir}/%{name}/*.h +%{_libdir}/%{name}.so +%{_libdir}/%{name}.la +%{_libdir}/pkgconfig/%{name}.pc +%{_datadir}/vala/vapi/signon.vapi +%{_datadir}/gtk-doc/html/%{name}/* + + +%changelog +* Fri May 31 2013 Jussi Laako - 2.0 +- Initial version of the renamed fork + diff --git a/packaging/libsignon-glib.spec b/packaging/libsignon-glib.spec deleted file mode 100644 index dffdf00..0000000 --- a/packaging/libsignon-glib.spec +++ /dev/null @@ -1,78 +0,0 @@ -Name: libsignon-glib -Summary: GLib API for the SSO framework -Version: 1.9.0 -Release: 4 -Group: System/Libraries -License: LGPL -Source: %{name}-%{version}.tar.bz2 -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig -BuildRequires: pkgconfig(gtk-doc) -BuildRequires: pkgconfig(check) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(gobject-2.0) -BuildRequires: pkgconfig(gio-2.0) - -%description -%{summary}. - - -%package devel -Summary: Development files for %{name} -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -%{summary}. - - -%prep -%setup -q -n %{name}-%{version} -gtkdocize -autoreconf -f -i - - -%build -%configure --enable-gtk-doc --enable-gtk-doc-html --enable-python -make #%{?_smp_mflags} - - -%install -rm -rf %{buildroot} -%make_install - - -%post -p /sbin/ldconfig - - -%postun -p /sbin/ldconfig - - -%files -%defattr(-,root,root,-) -%doc AUTHORS COPYING ChangeLog INSTALL NEWS README -%{_libdir}/%{name}.so.* - - -%files devel -%defattr(-,root,root,-) -%{_includedir}/%{name}/*.h -%{_libdir}/%{name}.so -%{_libdir}/%{name}.la -%{_libdir}/pkgconfig/%{name}.pc -%{_datadir}/vala/vapi/signon.vapi -%{_datadir}/gtk-doc/html/%{name}/* - - -%changelog -* Mon Feb 11 2013 Jussi Laako - 1.9 -- Update to latest intel branch version - -* Thu Feb 07 2013 Jussi Laako - 1.7 -- Update to latest intel branch version - -* Tue Mar 27 2012 Jussi Laako - 1.1 -- Update to latest upstream version - -* Wed Aug 03 2011 Jussi Laako - 1.0 -- Update to latest upstream version diff --git a/tests/Makefile.am b/tests/Makefile.am index 9e5765c..c9a471a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,4 +25,4 @@ signon_glib_testsuite_CPPFLAGS = \ signon_glib_testsuite_LDADD = \ $(CHECK_LIBS) \ $(DEPS_LIBS) \ - $(top_builddir)/libsignon-glib/libsignon-glib.la + $(top_builddir)/libgsignon-glib/libgsignon-glib.la diff --git a/tests/check_signon.c b/tests/check_signon.c index dc11236..57b692c 100644 --- a/tests/check_signon.c +++ b/tests/check_signon.c @@ -1,6 +1,6 @@ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * This file is part of libsignon-glib + * This file is part of libgsignon-glib * * Copyright (C) 2009-2011 Nokia Corporation. * Copyright (C) 2011-2012 Canonical Ltd. @@ -31,11 +31,11 @@ #define SIGNON_DISABLE_DEPRECATION_WARNINGS -#include "libsignon-glib/signon-internals.h" -#include "libsignon-glib/signon-auth-service.h" -#include "libsignon-glib/signon-auth-session.h" -#include "libsignon-glib/signon-identity.h" -#include "libsignon-glib/signon-errors.h" +#include "libgsignon-glib/signon-internals.h" +#include "libgsignon-glib/signon-auth-service.h" +#include "libgsignon-glib/signon-auth-session.h" +#include "libgsignon-glib/signon-identity.h" +#include "libgsignon-glib/signon-errors.h" #include #include diff --git a/tests/tests.xml b/tests/tests.xml index 2ba8b91..0eaaf34 100644 --- a/tests/tests.xml +++ b/tests/tests.xml @@ -1,7 +1,7 @@ - - - + + + /usr/bin/signon-glib-test.sh true