diff options
author | Jussi Laako <jussi.laako@linux.intel.com> | 2014-03-10 16:44:09 +0200 |
---|---|---|
committer | Jussi Laako <jussi.laako@linux.intel.com> | 2014-03-10 16:44:09 +0200 |
commit | b539cb740dad93950d9d89ec321c1b9622ccdab5 (patch) | |
tree | 1daa996bd516f68c458367be96c4188b6effbda0 /src/common | |
parent | 1fd618eee96db111f3eea0806eccb8cf2ad91106 (diff) | |
download | gsignond-b539cb740dad93950d9d89ec321c1b9622ccdab5.tar.gz gsignond-b539cb740dad93950d9d89ec321c1b9622ccdab5.tar.bz2 gsignond-b539cb740dad93950d9d89ec321c1b9622ccdab5.zip |
Update to upstream 1.0.1
Change-Id: Ibda71ee45e57dd921e49d36ffb57c3b23e972179
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Makefile.am | 6 | ||||
-rw-r--r-- | src/common/Makefile.in | 59 | ||||
-rw-r--r-- | src/common/db/Makefile.in | 27 | ||||
-rw-r--r-- | src/common/db/gsignond-secret-storage.c | 13 | ||||
-rw-r--r-- | src/common/gsignond-access-control-manager.c | 32 | ||||
-rw-r--r-- | src/common/gsignond-config.c | 195 | ||||
-rw-r--r-- | src/common/gsignond-dictionary.c | 76 | ||||
-rw-r--r-- | src/common/gsignond-identity-info-internal.h | 49 | ||||
-rw-r--r-- | src/common/gsignond-identity-info.c | 762 | ||||
-rw-r--r-- | src/common/gsignond-identity-info.h | 33 | ||||
-rw-r--r-- | src/common/gsignond-plugin-interface.c | 4 | ||||
-rw-r--r-- | src/common/gsignond-plugin-loader.c | 83 | ||||
-rw-r--r-- | src/common/gsignond-plugin-loader.h | 47 | ||||
-rw-r--r-- | src/common/gsignond-session-data.c | 33 | ||||
-rw-r--r-- | src/common/gsignond-storage-manager.c | 25 | ||||
-rw-r--r-- | src/common/gsignond-utils.c | 181 |
16 files changed, 923 insertions, 702 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am index b89d47e..baf7098 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -32,9 +32,7 @@ libgsignond_common_la_CPPFLAGS = \ -I$(top_srcdir)/include \ -I. \ $(GSIGNOND_CFLAGS) \ - -DGSIGNOND_PLUGINS_DIR='"$(pluginsdir)"' \ - -DGSIGNOND_EXTENSIONS_DIR='"$(extensionsdir)"' \ - -DGSIGNOND_BIN_DIR='"$(bindir)"' \ + -DGSIGNOND_GPLUGINS_DIR='"$(gpluginsdir)"' \ -DGSIGNOND_SYSCONF_DIR='"$(sysconfdir)"' \ $(NULL) @@ -62,8 +60,6 @@ libgsignond_common_la_SOURCES = \ gsignond-dictionary.c \ gsignond-session-data.c \ gsignond-signonui-data.c \ - gsignond-plugin-loader.h \ - gsignond-plugin-loader.c \ gsignond-utils.c \ gsignond-pipe-stream.h \ gsignond-pipe-stream.c \ diff --git a/src/common/Makefile.in b/src/common/Makefile.in index ddf1481..d26d2c7 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11.6 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -16,23 +16,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -112,7 +95,6 @@ am_libgsignond_common_la_OBJECTS = \ libgsignond_common_la-gsignond-dictionary.lo \ libgsignond_common_la-gsignond-session-data.lo \ libgsignond_common_la-gsignond-signonui-data.lo \ - libgsignond_common_la-gsignond-plugin-loader.lo \ libgsignond_common_la-gsignond-utils.lo \ libgsignond_common_la-gsignond-pipe-stream.lo \ libgsignond_common_la-gsignond-disposable.lo $(am__objects_2) \ @@ -160,11 +142,6 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ install-pdf-recursive install-ps-recursive install-recursive \ installcheck-recursive installdirs-recursive pdf-recursive \ ps-recursive uninstall-recursive -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ @@ -207,6 +184,7 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BASE_STORAGE_DIR = @BASE_STORAGE_DIR@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -233,6 +211,7 @@ GREP = @GREP@ GSIGNOND_CFLAGS = @GSIGNOND_CFLAGS@ GSIGNOND_LIBS = @GSIGNOND_LIBS@ GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ GTKDOC_MKPDF = @GTKDOC_MKPDF@ @@ -245,6 +224,7 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KEYCHAIN_SYSCTX = @KEYCHAIN_SYSCTX@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBECRYPTFS_CFLAGS = @LIBECRYPTFS_CFLAGS@ @@ -338,7 +318,8 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ extensionsdir = $(pkglibdir)/extensions -pluginsdir = $(pkglibdir)/plugins +pluginloadersdir = $(pkglibdir)/pluginloaders +gpluginsdir = $(pkglibdir)/gplugins SUBDIRS = db NULL = lib_LTLIBRARIES = libgsignond-common.la @@ -354,9 +335,7 @@ libgsignond_common_la_CPPFLAGS = \ -I$(top_srcdir)/include \ -I. \ $(GSIGNOND_CFLAGS) \ - -DGSIGNOND_PLUGINS_DIR='"$(pluginsdir)"' \ - -DGSIGNOND_EXTENSIONS_DIR='"$(extensionsdir)"' \ - -DGSIGNOND_BIN_DIR='"$(bindir)"' \ + -DGSIGNOND_GPLUGINS_DIR='"$(gpluginsdir)"' \ -DGSIGNOND_SYSCONF_DIR='"$(sysconfdir)"' \ $(NULL) @@ -384,8 +363,6 @@ libgsignond_common_la_SOURCES = \ gsignond-dictionary.c \ gsignond-session-data.c \ gsignond-signonui-data.c \ - gsignond-plugin-loader.h \ - gsignond-plugin-loader.c \ gsignond-utils.c \ gsignond-pipe-stream.h \ gsignond-pipe-stream.c \ @@ -442,6 +419,7 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps) $(am__aclocal_m4_deps): install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ list2=; for p in $$list; do \ if test -f $$p; then \ @@ -449,8 +427,6 @@ install-libLTLIBRARIES: $(lib_LTLIBRARIES) else :; fi; \ done; \ test -z "$$list2" || { \ - echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ } @@ -492,7 +468,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-pipe-stream.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-plugin-enum-types.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-plugin-interface.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-plugin-loader.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-security-context.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-session-data.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgsignond_common_la-gsignond-signonui-data.Plo@am__quote@ @@ -607,13 +582,6 @@ libgsignond_common_la-gsignond-signonui-data.lo: gsignond-signonui-data.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgsignond_common_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libgsignond_common_la-gsignond-signonui-data.lo `test -f 'gsignond-signonui-data.c' || echo '$(srcdir)/'`gsignond-signonui-data.c -libgsignond_common_la-gsignond-plugin-loader.lo: gsignond-plugin-loader.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgsignond_common_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libgsignond_common_la-gsignond-plugin-loader.lo -MD -MP -MF $(DEPDIR)/libgsignond_common_la-gsignond-plugin-loader.Tpo -c -o libgsignond_common_la-gsignond-plugin-loader.lo `test -f 'gsignond-plugin-loader.c' || echo '$(srcdir)/'`gsignond-plugin-loader.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgsignond_common_la-gsignond-plugin-loader.Tpo $(DEPDIR)/libgsignond_common_la-gsignond-plugin-loader.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gsignond-plugin-loader.c' object='libgsignond_common_la-gsignond-plugin-loader.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgsignond_common_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libgsignond_common_la-gsignond-plugin-loader.lo `test -f 'gsignond-plugin-loader.c' || echo '$(srcdir)/'`gsignond-plugin-loader.c - libgsignond_common_la-gsignond-utils.lo: gsignond-utils.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgsignond_common_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libgsignond_common_la-gsignond-utils.lo -MD -MP -MF $(DEPDIR)/libgsignond_common_la-gsignond-utils.Tpo -c -o libgsignond_common_la-gsignond-utils.lo `test -f 'gsignond-utils.c' || echo '$(srcdir)/'`gsignond-utils.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgsignond_common_la-gsignond-utils.Tpo $(DEPDIR)/libgsignond_common_la-gsignond-utils.Plo @@ -815,10 +783,13 @@ distdir: $(DISTFILES) done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ - $(am__make_dryrun) \ - || test -d "$(distdir)/$$subdir" \ - || $(MKDIR_P) "$(distdir)/$$subdir" \ - || exit 1; \ + test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ diff --git a/src/common/db/Makefile.in b/src/common/db/Makefile.in index 6faf597..8aa00fa 100644 --- a/src/common/db/Makefile.in +++ b/src/common/db/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11.6 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -16,23 +16,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -107,11 +90,6 @@ am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(libgsignond_common_db_la_SOURCES) DIST_SOURCES = $(libgsignond_common_db_la_SOURCES) -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -123,6 +101,7 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BASE_STORAGE_DIR = @BASE_STORAGE_DIR@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -149,6 +128,7 @@ GREP = @GREP@ GSIGNOND_CFLAGS = @GSIGNOND_CFLAGS@ GSIGNOND_LIBS = @GSIGNOND_LIBS@ GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ GTKDOC_MKPDF = @GTKDOC_MKPDF@ @@ -161,6 +141,7 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KEYCHAIN_SYSCTX = @KEYCHAIN_SYSCTX@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBECRYPTFS_CFLAGS = @LIBECRYPTFS_CFLAGS@ diff --git a/src/common/db/gsignond-secret-storage.c b/src/common/db/gsignond-secret-storage.c index 97e021d..42a8f57 100644 --- a/src/common/db/gsignond-secret-storage.c +++ b/src/common/db/gsignond-secret-storage.c @@ -29,6 +29,8 @@ #include "gsignond/gsignond-log.h" #include "gsignond/gsignond-secret-storage.h" +#define GSIGNOND_SECRET_DB_FILENAME "secret.db" + /** * SECTION:gsignond-secret-storage * @short_description: provides access to the database that stores user credentials and identity/method cache @@ -129,7 +131,6 @@ static gboolean _open_db (GSignondSecretStorage *self) { const gchar *dir = NULL; - const gchar *filename = NULL; gchar *db_filename = NULL; gboolean ret = FALSE; @@ -142,13 +143,7 @@ _open_db (GSignondSecretStorage *self) ERR ("No directory specified in config object for secret db..."); return FALSE; } - filename = gsignond_config_get_string (self->config, - GSIGNOND_CONFIG_DB_SECRET_DB_FILENAME); - if (!filename) { - ERR ("Database filename not specified"); - return FALSE; - } - db_filename = g_build_filename (dir, filename, NULL); + db_filename = g_build_filename (dir, GSIGNOND_SECRET_DB_FILENAME, NULL); if (!db_filename) { ERR ("Invalid db filename..."); return FALSE; @@ -376,7 +371,7 @@ gsignond_secret_storage_init (GSignondSecretStorage *self) * * Opens (and initializes) the database. The implementation should take * care of creating the DB, if it doesn't exist, and it should use - * #GSIGNOND_CONFIG_GENERAL_SECURE_DIR and #GSIGNOND_CONFIG_DB_SECRET_DB_FILENAME + * #GSIGNOND_CONFIG_GENERAL_SECURE_DIR * to determine database location in the filesystem. * * The default implementation is using SQLite for the storage. diff --git a/src/common/gsignond-access-control-manager.c b/src/common/gsignond-access-control-manager.c index ef5d8f8..b583151 100644 --- a/src/common/gsignond-access-control-manager.c +++ b/src/common/gsignond-access-control-manager.c @@ -277,18 +277,26 @@ _acl_is_valid (GSignondAccessControlManager *self, GSignondSecurityContext * _security_context_of_keychain (GSignondAccessControlManager *self) { - const gchar *keychain_sysctx = NULL; + g_return_val_if_fail (self != NULL, NULL); - (void) self; + const gchar *keychain_sysctx; -# if defined(ENABLE_DEBUG) - keychain_sysctx = g_getenv ("SSO_KEYCHAIN_SYSCTX"); -# elif defined(KEYCHAIN_SYSCTX) - keychain_sysctx = KEYCHAIN_SYSCTX; -# endif + keychain_sysctx = gsignond_config_get_string ( + self->config, + GSIGNOND_CONFIG_GENERAL_KEYCHAIN_SYSCTX); if (!keychain_sysctx) +# ifdef KEYCHAIN_SYSCTX + keychain_sysctx = KEYCHAIN_SYSCTX; +# else keychain_sysctx = ""; - return gsignond_security_context_new_from_values (keychain_sysctx, ""); +# endif +# ifdef ENABLE_DEBUG + const gchar *keychain_env = g_getenv ("SSO_KEYCHAIN_SYSCTX"); + if (keychain_env) + keychain_sysctx = keychain_env; +# endif + + return gsignond_security_context_new_from_values (keychain_sysctx, NULL); } /** @@ -444,7 +452,13 @@ gsignond_access_control_manager_acl_is_valid ( * has a special management access to all stored identities and is able to * perform deletion of all identities from storage. * - * The default implementation returns an empty context. If gSSO was compiled + * The default implementation returns a context either set in #GSignondConfig, + * or if not set, a value specified through a configure --enable-keychain + * option (see + * <link linkend="gsignond-building">Building gsignond</link>), or if that is not + * set either then an empty string "" is returned. + * + * If gSSO was compiled * with --enable-debug and SSO_KEYCHAIN_SYSCTX environment variable is set, then * the value of that variable is used to set the returned system context instead. * diff --git a/src/common/gsignond-config.c b/src/common/gsignond-config.c index 855777d..c40e160 100644 --- a/src/common/gsignond-config.c +++ b/src/common/gsignond-config.c @@ -3,7 +3,7 @@ /* * This file is part of gsignond * - * Copyright (C) 2012 Intel Corporation. + * Copyright (C) 2012-2013 Intel Corporation. * * Contact: Jussi Laako <jussi.laako@linux.intel.com> * Amarnath Valluri <amarnath.valluri@linux.intel.com> @@ -32,7 +32,6 @@ #include "gsignond/gsignond-config.h" #include "gsignond/gsignond-config-general.h" -#include "gsignond/gsignond-config-db.h" #include "gsignond/gsignond-config-dbus.h" #include "gsignond/gsignond-log.h" #include "gsignond/gsignond-dictionary.h" @@ -45,32 +44,28 @@ * #GSignondConfig holds configuration information as a set of keys and values * (integer or strings). The key names are defined in * <link linkend="gsignond-General-configuration">general config keys</link>, - * <link linkend="gsignond-Database-configuration">database config keys</link>, and - * <link linkend="gsignond-DBus-configuration">DBus config keys</link>. + * and <link linkend="gsignond-DBus-configuration">DBus config keys</link>. * - * The configuration is discovered from these sources, in decreasing order of - * priority: - * - environment variables, if gSSO has been compiled with --enable-debug switch. - * See the specific keys documentation for the variable names. - * - gSSO configuration file. See below for where the file is searched for. - * - default values. See the documentation for specific keys for those. + * The configuration is retrieved from the gSSO configuration file. See below + * for where the file is searched for. * * <refsect1><title>Where the configuration file is searched for</title></refsect1> * * If gSSO has been compiled with --enable-debug, then these locations are used, * in decreasing order of priority: * - GSIGNOND_CONFIG environment variable - * - g_get_user_config_dir() + "gsignond/gsignond.conf" - * - each of g_get_system_config_dirs() + "gsignond/gsignond.conf" + * - g_get_user_config_dir() + "gsignond.conf" + * - path specified in --sysconfdir configure option ($(sysconfdir)) + * - each of g_get_system_config_dirs() + "gsignond.conf" * * Otherwise, the config file location is determined at compilation time as - * $(sysconfdir) + "gsignond/gsignond.conf" + * $(sysconfdir) + "gsignond.conf" * * <refsect1><title>Example configuration file</title></refsect1> * * See example configuration file here: - * <ulink url="http://code.google.com/p/accounts-sso/source/browse/gsignond.conf?repo=gsignond"> - * http://code.google.com/p/accounts-sso/source/browse/gsignond.conf?repo=gsignond</ulink> + * <ulink url="http://code.google.com/p/accounts-sso/source/browse/gsignond.conf.in?repo=gsignond"> + * http://code.google.com/p/accounts-sso/source/browse/gsignond.conf.in?repo=gsignond</ulink> */ /** @@ -85,9 +80,6 @@ */ -#define GSIGNOND_DB_METADATA_DEFAULT_DB_FILENAME "metadata.db" -#define GSIGNOND_DB_SECRET_DEFAULT_DB_FILENAME "secret.db" - struct _GSignondConfigPrivate { gchar *config_file_path; @@ -98,23 +90,24 @@ struct _GSignondConfigPrivate G_DEFINE_TYPE (GSignondConfig, gsignond_config, G_TYPE_OBJECT); - -static void -_set_storage_path (GSignondConfig *self, const gchar *value) +static gchar * +_check_config_file (const gchar *path) { - gchar *storage_path = g_build_filename (value, - "gsignond.general", - NULL); - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_STORAGE_PATH, - storage_path); - g_free (storage_path); + gchar *fn; + + fn = g_build_filename (path, + "gsignond.conf", + NULL); + DBG ("check config at %s", fn); + if (g_access (fn, R_OK) == 0) + return fn; + g_free (fn); + return NULL; } static gboolean _load_config (GSignondConfig *self) { - gchar *def_config; GError *err = NULL; gchar **groups = NULL; gsize n_groups = 0; @@ -125,41 +118,37 @@ _load_config (GSignondConfig *self) const gchar * const *sysconfdirs; if (!self->priv->config_file_path) { - def_config = g_strdup (g_getenv ("GSIGNOND_CONFIG")); - if (!def_config) - def_config = g_build_filename (g_get_user_config_dir(), - "gsignond/gsignond.conf", - NULL); - if (g_access (def_config, R_OK) == 0) { - self->priv->config_file_path = def_config; - } else { - g_free (def_config); - sysconfdirs = g_get_system_config_dirs (); - while (*sysconfdirs != NULL) { - def_config = g_build_filename (*sysconfdirs, - "gsignond/gsignond.conf", - NULL); - if (g_access (def_config, R_OK) == 0) { - self->priv->config_file_path = def_config; - break; - } - g_free (def_config); - sysconfdirs++; + const gchar *cfg_env = g_getenv ("GSIGNOND_CONFIG"); + if (cfg_env) + self->priv->config_file_path = _check_config_file (cfg_env); + } + if (!self->priv->config_file_path) { + gchar *user_cfg = g_strdup_printf ("%s/%s", + g_get_user_config_dir (), + "gsignond"); + self->priv->config_file_path = _check_config_file (user_cfg); + g_free (user_cfg); + } + if (!self->priv->config_file_path) { + self->priv->config_file_path = + _check_config_file (GSIGNOND_SYSCONF_DIR); + } + if (!self->priv->config_file_path) { + sysconfdirs = g_get_system_config_dirs (); + while (*sysconfdirs != NULL) { + gchar *sys_cfg = _check_config_file (*sysconfdirs); + if (sys_cfg) { + self->priv->config_file_path = sys_cfg; + break; } + sysconfdirs++; } } # else /* ENABLE_DEBUG */ # ifndef GSIGNOND_SYSCONF_DIR # error "System configuration directory not defined!" # endif - def_config = g_build_filename (GSIGNOND_SYSCONF_DIR, - "gsignond/gsignond.conf", - NULL); - if (g_access (def_config, R_OK) == 0) { - self->priv->config_file_path = def_config; - } else { - g_free (def_config); - } + self->priv->config_file_path = _check_config_file (GSIGNOND_SYSCONF_DIR); # endif /* ENABLE_DEBUG */ if (self->priv->config_file_path) { @@ -203,12 +192,7 @@ _load_config (GSignondConfig *self) } INFO ("found config : '%s/%s' - '%s'", groups[i], keys[j], value); - - /* construct a full storage path for wipe safety */ - if (g_strcmp0 (key, GSIGNOND_CONFIG_GENERAL_STORAGE_PATH) == 0) - _set_storage_path (self, value); - else - gsignond_config_set_string (self, key, value); + gsignond_config_set_string (self, key, value); g_free (key); g_free (value); @@ -224,67 +208,6 @@ _load_config (GSignondConfig *self) return TRUE; } -#ifdef ENABLE_DEBUG -static void -_load_environment (GSignondConfig *self) -{ - const gchar *e_val = 0; - guint timeout = 0; - - e_val = g_getenv ("SSO_DAEMON_TIMEOUT"); - if (e_val && (timeout = atoi(e_val))) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_DBUS_DAEMON_TIMEOUT, - e_val); - - e_val = g_getenv ("SSO_IDENTITY_TIMEOUT"); - if (e_val && (timeout = atoi(e_val))) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_DBUS_IDENTITY_TIMEOUT, - e_val); - - e_val = g_getenv ("SSO_AUTH_SESSION_TIMEOUT"); - if (e_val && (timeout = atoi(e_val))) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_DBUS_AUTH_SESSION_TIMEOUT, - e_val); - - e_val = g_getenv ("SSO_PLUGIN_TIMEOUT"); - if (e_val && (timeout = atoi(e_val))) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_PLUGIN_TIMEOUT, - e_val); - - e_val = g_getenv ("SSO_PLUGINS_DIR"); - if (e_val) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_PLUGINS_DIR, - e_val); - - e_val = g_getenv ("SSO_EXTENSIONS_DIR"); - if (e_val) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_EXTENSIONS_DIR, - e_val); - - e_val = g_getenv ("SSO_BIN_DIR"); - if (e_val) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_BIN_DIR, - e_val); - - e_val = g_getenv ("SSO_EXTENSION"); - if (e_val) - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_EXTENSION, - e_val); - - e_val = g_getenv ("SSO_STORAGE_PATH"); - if (e_val) - _set_storage_path (self, e_val); -} -#endif /* ENABLE_DEBUG */ - /** * gsignond_config_get_integer: * @self: an instance of #GSignondConfig @@ -408,32 +331,8 @@ gsignond_config_init (GSignondConfig *self) self->priv->config_file_path = NULL; self->priv->config_table = gsignond_dictionary_new(); - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_PLUGINS_DIR, - (GSIGNOND_PLUGINS_DIR)); - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_EXTENSIONS_DIR, - (GSIGNOND_EXTENSIONS_DIR)); - gsignond_config_set_string (self, - (GSIGNOND_CONFIG_GENERAL_BIN_DIR), - (GSIGNOND_BIN_DIR)); - - gsignond_config_set_string (self, - GSIGNOND_CONFIG_GENERAL_STORAGE_PATH, - "/var/db"); - - gsignond_config_set_string (self, - GSIGNOND_CONFIG_DB_SECRET_DB_FILENAME, - GSIGNOND_DB_SECRET_DEFAULT_DB_FILENAME); - gsignond_config_set_string (self, - GSIGNOND_CONFIG_DB_METADATA_DB_FILENAME, - GSIGNOND_DB_METADATA_DEFAULT_DB_FILENAME); - if (!_load_config (self)) WARN ("load configuration failed, using default settings"); -# ifdef ENABLE_DEBUG - _load_environment (self); -# endif } static void diff --git a/src/common/gsignond-dictionary.c b/src/common/gsignond-dictionary.c index 8ec88c3..40d68d4 100644 --- a/src/common/gsignond-dictionary.c +++ b/src/common/gsignond-dictionary.c @@ -85,6 +85,39 @@ gsignond_dictionary_new_from_variant (GVariant *variant) } /** + * gsignond_dictionary_to_variant_builder: + * @dict: instance of #GSignondDictionary + * + * Converts the #GSignondDictionary to a #GVariantBuilder of type + * G_VARIANT_TYPE_VARDICT. + * + * Caller should use g_variant_builder_unref() on the return value when it is + * no longer needed. + * + * Returns: (transfer full): #GVariantBuilder if successful, NULL otherwise. + */ +GVariantBuilder * +gsignond_dictionary_to_variant_builder (GSignondDictionary *dict) +{ + GVariantBuilder *builder; + GHashTableIter iter; + const gchar *key = NULL; + GVariant *value = NULL; + + g_return_val_if_fail (dict != NULL, NULL); + + builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT); + + g_hash_table_iter_init (&iter, dict); + while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value)) + { + g_variant_builder_add (builder, "{sv}", key, value); + } + + return builder; +} + +/** * gsignond_dictionary_to_variant: * @dict: instance of #GSignondDictionary * @@ -96,25 +129,18 @@ gsignond_dictionary_new_from_variant (GVariant *variant) GVariant * gsignond_dictionary_to_variant (GSignondDictionary *dict) { - GVariantBuilder builder; - GHashTableIter iter; + GVariantBuilder *builder = NULL; GVariant *vdict = NULL; - const gchar *key = NULL; - GVariant *value = NULL; g_return_val_if_fail (dict != NULL, NULL); - g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - g_hash_table_iter_init (&iter, dict); - while (g_hash_table_iter_next (&iter, - (gpointer)&key, - (gpointer)&value)) - { - g_variant_builder_add (&builder, "{sv}", - key, - value); - } - vdict = g_variant_builder_end (&builder); + builder = gsignond_dictionary_to_variant_builder (dict); + if (!builder) return NULL; + + vdict = g_variant_builder_end (builder); + + g_variant_builder_unref (builder); + return vdict; } @@ -515,3 +541,23 @@ gsignond_dictionary_copy (GSignondDictionary *other) return dict; } + +/** + * gsignond_dictionary_contains: + * @dict: instance of #GSignondDictionary + * @key: (transfer none): key to check + * + * Checks if the @dict contains @key. + * + * Returns: TRUE if found, FALSE otherwise. + */ +gboolean +gsignond_dictionary_contains (GSignondDictionary *dict, + const gchar *key) +{ + g_return_val_if_fail (dict != NULL, FALSE); + g_return_val_if_fail (key != NULL, FALSE); + + return g_hash_table_contains (dict, key); +} + diff --git a/src/common/gsignond-identity-info-internal.h b/src/common/gsignond-identity-info-internal.h index 60ce7a1..92af966 100644 --- a/src/common/gsignond-identity-info-internal.h +++ b/src/common/gsignond-identity-info-internal.h @@ -50,6 +50,55 @@ G_BEGIN_DECLS #define GSIGNOND_IDENTITY_INFO_VALIDATED "Validated" #define GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET "UserNameSecret" +#define GSIGNOND_IDENTITY_INFO_EDIT_FLAGS "EditFlags" + +typedef enum { + IDENTITY_INFO_PROP_NONE = 0x0000, + + /* Secret fields */ + IDENTITY_INFO_PROP_USERNAME = 0x0001, + IDENTITY_INFO_PROP_SECRET = 0x0002, + + IDENTITY_INFO_PROP_ID = 0x0004, + IDENTITY_INFO_PROP_TYPE = 0x0008, + IDENTITY_INFO_PROP_CAPTION = 0x0010, + IDENTITY_INFO_PROP_STORE_SECRET = 0x0020, + IDENTITY_INFO_PROP_USERNAME_IS_SECRET = 0x0040, + IDENTITY_INFO_PROP_OWNER = 0x0080, + IDENTITY_INFO_PROP_ACL = 0x0100, + IDENTITY_INFO_PROP_METHODS = 0x0200, + IDENTITY_INFO_PROP_REALMS = 0x0400, + IDENTITY_INFO_PROP_REF_COUNT = 0x0800, + IDENTITY_INFO_PROP_VALIDATED = 0x1000, + + IDENTITY_INFO_PROP_MAX = 0x2000, + IDENTITY_INFO_PROP_ALL = 0x1ffff + +} GSignondIdentityInfoPropFlags; + +GSignondIdentityInfoPropFlags +gsignond_identity_info_get_edit_flags (GSignondIdentityInfo *info); + +gboolean +gsignond_identity_info_set_edit_flags (GSignondIdentityInfo *info, + GSignondIdentityInfoPropFlags flags); + +gboolean +gsignond_identity_info_reset_edit_flags (GSignondIdentityInfo *info, + GSignondIdentityInfoPropFlags flags); + +gboolean +gsignond_identity_info_unset_edit_flags (GSignondIdentityInfo *info, + GSignondIdentityInfoPropFlags flags); + +GSignondIdentityInfoPropFlags +gsignond_identity_info_selective_copy (GSignondIdentityInfo *dest, + const GSignondIdentityInfo *src, + GSignondIdentityInfoPropFlags flags); + +void +gsignond_identity_info_remove_owner (GSignondIdentityInfo *info); + G_END_DECLS #endif /* __GSIGNOND_IDENTITY_INFO_INTERNAL_H__ */ diff --git a/src/common/gsignond-identity-info.c b/src/common/gsignond-identity-info.c index 02af6c3..a27aadb 100644 --- a/src/common/gsignond-identity-info.c +++ b/src/common/gsignond-identity-info.c @@ -25,7 +25,21 @@ #include "gsignond-identity-info.h" #include "gsignond-identity-info-internal.h" +#include "gsignond/gsignond-utils.h" +G_DEFINE_BOXED_TYPE(GSignondIdentityInfo, + gsignond_identity_info, + gsignond_identity_info_ref, + gsignond_identity_info_unref) + +struct _GSignondIdentityInfo +{ + volatile gint ref_count; + gchar *username; + gchar *secret; + GSignondIdentityInfoPropFlags edit_flags; + GSignondDictionary *map; +}; static gboolean _gsignond_identity_info_seq_cmp ( @@ -69,96 +83,6 @@ _gsignond_identity_info_seq_cmp ( return equal; } -static gint -_compare_strings ( - const gchar* a, - const gchar* b, - gpointer data) -{ - (void)data; - return g_strcmp0 (a,b); -} - -static GVariant * -_gsignond_identity_info_sequence_to_variant (GSequence *seq) - -{ - GSequenceIter * iter = NULL; - GVariant *var = NULL; - GVariantBuilder builder; - - if (!seq) return NULL; - - g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY); - iter = g_sequence_get_begin_iter (seq); - while (!g_sequence_iter_is_end (iter)) { - const gchar * d = g_sequence_get (iter); - g_variant_builder_add (&builder, "s", d); - iter = g_sequence_iter_next (iter); - } - var = g_variant_builder_end (&builder); - return var; -} - -static GSequence * -_gsignond_identity_info_variant_to_sequence (GVariant *var) - -{ - GVariantIter iter; - GSequence *seq = NULL; - gchar *item = NULL; - - if (!var) return NULL; - - seq = g_sequence_new ((GDestroyNotify)g_free); - g_variant_iter_init (&iter, var); - while (g_variant_iter_next (&iter, "s", &item)) { - g_sequence_insert_sorted (seq, - item, - (GCompareDataFunc) _compare_strings, - NULL); - } - return seq; -} - -static gchar ** -_gsignond_identity_info_sequence_to_array (GSequence *seq) -{ - gchar **items, **temp; - GSequenceIter *iter; - - if (!seq) return NULL; - - items = g_malloc0 ((g_sequence_get_length (seq) + 1) * sizeof (gchar *)); - temp = items; - for (iter = g_sequence_get_begin_iter (seq); - iter != g_sequence_get_end_iter (seq); - iter = g_sequence_iter_next (iter)) { - *temp = g_sequence_get (iter); - temp++; - } - return items; -} - -static GSequence * -_gsignond_identity_info_array_to_sequence (gchar **items) - -{ - GSequence *seq = NULL; - - if (!items) return NULL; - - seq = g_sequence_new ((GDestroyNotify) g_free); - while (*items) { - g_sequence_insert_sorted (seq, - *items, - (GCompareDataFunc) _compare_strings, - NULL); - items++; - } - return seq; -} - static gboolean _gsignond_identity_info_sec_context_list_cmp ( GSignondSecurityContextList *one, @@ -226,6 +150,114 @@ _gsignond_identity_info_methods_cmp ( return equal; } +GSignondIdentityInfoPropFlags +gsignond_identity_info_get_edit_flags ( + GSignondIdentityInfo *info) +{ + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO(info), + IDENTITY_INFO_PROP_NONE); + + return info->edit_flags; +} + +gboolean +gsignond_identity_info_set_edit_flags ( + GSignondIdentityInfo *info, + GSignondIdentityInfoPropFlags flag) +{ + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO(info), FALSE); + + info->edit_flags |= flag; + + return TRUE; +} + +gboolean +gsignond_identity_info_reset_edit_flags ( + GSignondIdentityInfo *info, + GSignondIdentityInfoPropFlags flags) +{ + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO(info), FALSE); + + info->edit_flags = flags; + + return TRUE; +} + +gboolean +gsignond_identity_info_unset_edit_flags ( + GSignondIdentityInfo *info, + GSignondIdentityInfoPropFlags unset_flags) +{ + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO(info), FALSE); + + info->edit_flags &= ~unset_flags; + + return TRUE; +} + +GSignondIdentityInfoPropFlags +gsignond_identity_info_selective_copy (GSignondIdentityInfo *dest, + const GSignondIdentityInfo *src, + GSignondIdentityInfoPropFlags flags) +{ + GSignondIdentityInfoPropFlags tmp_flag; + guint i; + g_return_val_if_fail (src, IDENTITY_INFO_PROP_NONE); + g_return_val_if_fail (dest, IDENTITY_INFO_PROP_NONE); + g_return_val_if_fail (flags != IDENTITY_INFO_PROP_NONE, flags); + + /* This table should match to GSignondIdentityInfoPropFlags order */ + const gchar *keys[] = { + GSIGNOND_IDENTITY_INFO_ID, + GSIGNOND_IDENTITY_INFO_TYPE, + GSIGNOND_IDENTITY_INFO_CAPTION, + GSIGNOND_IDENTITY_INFO_STORESECRET, + GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET, + GSIGNOND_IDENTITY_INFO_OWNER, + GSIGNOND_IDENTITY_INFO_ACL, + GSIGNOND_IDENTITY_INFO_AUTHMETHODS, + GSIGNOND_IDENTITY_INFO_REALMS, + GSIGNOND_IDENTITY_INFO_REFCOUNT, + GSIGNOND_IDENTITY_INFO_VALIDATED + }; + + for (i= 0, tmp_flag = IDENTITY_INFO_PROP_ID; + tmp_flag < IDENTITY_INFO_PROP_MAX; + tmp_flag <<= 1, i++) { + if ((flags & tmp_flag) && + gsignond_dictionary_contains (src->map, keys[i])) { + gsignond_dictionary_set (dest->map, keys[i], + g_variant_ref (gsignond_dictionary_get (src->map, keys[i]))); + } + else { + flags &= ~tmp_flag; + } + } + + if (flags & IDENTITY_INFO_PROP_USERNAME) { + g_free (dest->username); + dest->username = g_strdup (src->username); + } + + if (flags & IDENTITY_INFO_PROP_SECRET) { + g_free (dest->secret); + dest->secret = g_strdup (src->secret); + } + + dest->edit_flags |= flags; + + return flags; +} + +void +gsignond_identity_info_remove_owner (GSignondIdentityInfo *info) +{ + g_return_if_fail (info && GSIGNOND_IS_IDENTITY_INFO(info)); + + gsignond_dictionary_remove (info->map, GSIGNOND_IDENTITY_INFO_OWNER); +} + /** * gsignond_identity_info_new: * @@ -237,10 +269,86 @@ _gsignond_identity_info_methods_cmp ( GSignondIdentityInfo * gsignond_identity_info_new (void) { - GSignondIdentityInfo *info; + return gsignond_identity_info_new_from_variant (NULL); +} + +/** + * gsignond_identity_info_new_from_variant: + * + * Creates new instance of GSignondIdentityInfo. + * + * Returns: (transfer full) #GSignondIdentityInfo object if successful, + * NULL otherwise. + */ +GSignondIdentityInfo * +gsignond_identity_info_new_from_variant (GVariant *variant_map) +{ + gboolean uname_is_secret = FALSE; + GSignondIdentityInfo *info = g_slice_new0 (GSignondIdentityInfo); + if (!info) return NULL; + + info->ref_count = 1; + info->edit_flags = IDENTITY_INFO_PROP_NONE; + info->username = info->secret = NULL; + + if (!variant_map) { + info->map = gsignond_dictionary_new (); + + gsignond_dictionary_set (info->map, GSIGNOND_IDENTITY_INFO_ID, + g_variant_new_uint32 (GSIGNOND_IDENTITY_INFO_NEW_IDENTITY)); - info = gsignond_dictionary_new (); - gsignond_identity_info_set_id (info, GSIGNOND_IDENTITY_INFO_NEW_IDENTITY); + return info; + } + + info->map = gsignond_dictionary_new_from_variant (variant_map); + if (!info->map) return info; + + /* update edit flags */ + if (gsignond_dictionary_contains (info->map, GSIGNOND_IDENTITY_INFO_ID)) + info->edit_flags |= IDENTITY_INFO_PROP_ID; + if (gsignond_dictionary_contains (info->map, GSIGNOND_IDENTITY_INFO_TYPE)) + info->edit_flags |= IDENTITY_INFO_PROP_TYPE; + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET)) { + info->edit_flags |= IDENTITY_INFO_PROP_USERNAME_IS_SECRET; + gsignond_dictionary_get_boolean (info->map, + GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET, &uname_is_secret); + } + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_USERNAME)) { + info->edit_flags |= IDENTITY_INFO_PROP_USERNAME; + info->username = g_strdup (gsignond_dictionary_get_string (info->map, + GSIGNOND_IDENTITY_INFO_USERNAME)); + gsignond_dictionary_remove (info->map, GSIGNOND_IDENTITY_INFO_USERNAME); + } + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_SECRET)) { + info->edit_flags |= IDENTITY_INFO_PROP_SECRET; + info->secret = g_strdup (gsignond_dictionary_get_string (info->map, + GSIGNOND_IDENTITY_INFO_SECRET)); + gsignond_dictionary_remove (info->map, GSIGNOND_IDENTITY_INFO_SECRET); + } + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_STORESECRET)) + info->edit_flags |= IDENTITY_INFO_PROP_STORE_SECRET; + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_CAPTION)) + info->edit_flags |= IDENTITY_INFO_PROP_CAPTION; + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_AUTHMETHODS)) + info->edit_flags |= IDENTITY_INFO_PROP_METHODS; + if (gsignond_dictionary_contains (info->map, GSIGNOND_IDENTITY_INFO_REALMS)) + info->edit_flags |= IDENTITY_INFO_PROP_REALMS; + if (gsignond_dictionary_contains (info->map, GSIGNOND_IDENTITY_INFO_ACL)) + info->edit_flags |= IDENTITY_INFO_PROP_ACL; + if (gsignond_dictionary_contains (info->map, GSIGNOND_IDENTITY_INFO_OWNER)) + info->edit_flags |= IDENTITY_INFO_PROP_OWNER; + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_REFCOUNT)) + info->edit_flags |= IDENTITY_INFO_PROP_REF_COUNT; + if (gsignond_dictionary_contains (info->map, + GSIGNOND_IDENTITY_INFO_VALIDATED)) + info->edit_flags |= IDENTITY_INFO_PROP_VALIDATED; return info; } @@ -256,10 +364,19 @@ gsignond_identity_info_new (void) GSignondIdentityInfo * gsignond_identity_info_copy (GSignondIdentityInfo *info) { - if (!info) - return NULL; + GSignondIdentityInfo *new_info = NULL; + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); + + new_info = g_slice_new0 (GSignondIdentityInfo); + if (!new_info) return NULL; + + new_info->ref_count = 1; + new_info->edit_flags = info->edit_flags; + new_info->username = g_strdup (info->username); + new_info->secret = g_strdup (info->secret); + new_info->map = gsignond_dictionary_copy (info->map); - return gsignond_dictionary_copy (info); + return new_info; } /** @@ -267,13 +384,17 @@ gsignond_identity_info_copy (GSignondIdentityInfo *info) * @info: instance of #GSignondIdentityInfo * * Increment reference count of the info structure. + * + * Returns: (transfer none) returns the same copy of the info. */ -void +GSignondIdentityInfo * gsignond_identity_info_ref (GSignondIdentityInfo *info) { - g_return_if_fail (info != NULL); + g_return_val_if_fail (info != NULL, info); - gsignond_dictionary_ref (info); + g_atomic_int_inc (&info->ref_count); + + return info; } /** @@ -285,10 +406,14 @@ gsignond_identity_info_ref (GSignondIdentityInfo *info) void gsignond_identity_info_unref (GSignondIdentityInfo *info) { - if (!info) - return; + g_return_if_fail (info != NULL); - gsignond_dictionary_unref (info); + if (g_atomic_int_dec_and_test (&info->ref_count)) { + gsignond_dictionary_unref (info->map); + g_free(info->username); + g_free(info->secret); + g_slice_free (GSignondIdentityInfo, info); + } } /** @@ -302,14 +427,14 @@ gsignond_identity_info_unref (GSignondIdentityInfo *info) guint32 gsignond_identity_info_get_id (GSignondIdentityInfo *info) { - g_assert (info != NULL); - - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_ID); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), + GSIGNOND_IDENTITY_INFO_NEW_IDENTITY); - g_return_val_if_fail (var != NULL, -1); + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_ID); - return g_variant_get_uint32 (var); + return var ? g_variant_get_uint32 (var) + : GSIGNOND_IDENTITY_INFO_NEW_IDENTITY; } /** @@ -327,12 +452,17 @@ gsignond_identity_info_set_id ( GSignondIdentityInfo *info, guint32 id) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); + + if (gsignond_identity_info_get_id (info) == id) + return TRUE; return gsignond_dictionary_set ( - info, + info->map, GSIGNOND_IDENTITY_INFO_ID, - g_variant_new_uint32 (id)); + g_variant_new_uint32 (id)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_ID); } /** @@ -346,7 +476,7 @@ gsignond_identity_info_set_id ( gboolean gsignond_identity_info_get_is_identity_new (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); return GSIGNOND_IDENTITY_INFO_NEW_IDENTITY == gsignond_identity_info_get_id (info); @@ -364,8 +494,8 @@ gboolean gsignond_identity_info_set_identity_new ( GSignondIdentityInfo *info) { - g_assert (info != NULL); - + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); + return gsignond_identity_info_set_id ( info, GSIGNOND_IDENTITY_INFO_NEW_IDENTITY); @@ -382,14 +512,9 @@ gsignond_identity_info_set_identity_new ( const gchar * gsignond_identity_info_get_username (GSignondIdentityInfo *info) { - g_assert (info != NULL); - - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_USERNAME); - if (var != NULL) { - return g_variant_get_string (var, NULL); - } - return NULL; + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); + + return (const gchar *)info->username; } /** @@ -407,30 +532,16 @@ gsignond_identity_info_set_username ( GSignondIdentityInfo *info, const gchar *username) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - if (!username) { - return gsignond_dictionary_remove (info, - GSIGNOND_IDENTITY_INFO_USERNAME); - } - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_USERNAME, - g_variant_new_string (username)); -} + const gchar *current_name = gsignond_identity_info_get_username(info); + if (g_strcmp0 (username, current_name) == 0) return TRUE; -/** - * gsignond_identity_info_remove_username: - * @info: instance of #GSignondIdentityInfo - * - * Removes username from the info. - */ -void -gsignond_identity_info_remove_username (GSignondIdentityInfo *info) -{ - g_assert (info != NULL); - - gsignond_dictionary_remove (info, GSIGNOND_IDENTITY_INFO_USERNAME); + g_free (info->username); + info->username = g_strdup (username); + + return gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_USERNAME); } /** @@ -444,15 +555,11 @@ gsignond_identity_info_remove_username (GSignondIdentityInfo *info) gboolean gsignond_identity_info_get_is_username_secret (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, + GVariant *var = gsignond_dictionary_get (info->map, GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET); - if (var != NULL) { - return g_variant_get_boolean (var); - } - return FALSE; + return var ? g_variant_get_boolean (var) : FALSE; } /** @@ -470,12 +577,19 @@ gsignond_identity_info_set_username_secret ( GSignondIdentityInfo *info, gboolean username_secret) { - g_assert (info != NULL); + gboolean res = FALSE; + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - return gsignond_dictionary_set ( - info, + if (gsignond_identity_info_get_is_username_secret(info) == username_secret) + return TRUE; + + res = gsignond_dictionary_set (info->map, GSIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET, - g_variant_new_boolean(username_secret)); + g_variant_new_boolean(username_secret)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_USERNAME_IS_SECRET); + + return res; } /** @@ -489,14 +603,9 @@ gsignond_identity_info_set_username_secret ( const gchar * gsignond_identity_info_get_secret (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_SECRET); - if (var != NULL) { - return g_variant_get_string (var, NULL); - } - return NULL; + return info->secret; } /** @@ -514,30 +623,19 @@ gsignond_identity_info_set_secret ( GSignondIdentityInfo *info, const gchar *secret) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - if (!secret) { - return gsignond_dictionary_remove (info, - GSIGNOND_IDENTITY_INFO_SECRET); - } - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_SECRET, - g_variant_new_string (secret)); -} + const gchar *current_secret = + gsignond_identity_info_get_secret (info); -/** - * gsignond_identity_info_remove_secret: - * @info: instance of #GSignondIdentityInfo - * - * Removes secret from the info. - */ -void -gsignond_identity_info_remove_secret (GSignondIdentityInfo *info) -{ - g_assert (info != NULL); + if (g_strcmp0 (current_secret, secret) == 0) return TRUE; + + if (info->secret) g_free (info->secret); + + info->secret = g_strdup (secret); - gsignond_dictionary_remove (info, GSIGNOND_IDENTITY_INFO_SECRET); + return gsignond_identity_info_set_edit_flags ( + info, IDENTITY_INFO_PROP_SECRET); } /** @@ -551,14 +649,11 @@ gsignond_identity_info_remove_secret (GSignondIdentityInfo *info) gboolean gsignond_identity_info_get_store_secret (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_STORESECRET); - if (var != NULL) { - return g_variant_get_boolean (var); - } - return FALSE; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_STORESECRET); + return var ? g_variant_get_boolean (var) : FALSE; } /** @@ -576,12 +671,16 @@ gsignond_identity_info_set_store_secret ( GSignondIdentityInfo *info, gboolean store_secret) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_STORESECRET, - g_variant_new_boolean(store_secret)); + if (gsignond_identity_info_get_store_secret (info) == store_secret) + return TRUE; + + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_STORESECRET, + g_variant_new_boolean(store_secret)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_STORE_SECRET); } /** @@ -595,14 +694,11 @@ gsignond_identity_info_set_store_secret ( const gchar * gsignond_identity_info_get_caption (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_CAPTION); - if (var != NULL) { - return g_variant_get_string (var, NULL); - } - return NULL; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_CAPTION); + return var ? g_variant_get_string (var, NULL) : NULL; } /** @@ -620,16 +716,24 @@ gsignond_identity_info_set_caption ( GSignondIdentityInfo *info, const gchar *caption) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); + const gchar *current_caption = + gsignond_identity_info_get_caption (info); + + if (g_strcmp0 (current_caption, caption) == 0) + return TRUE; if (!caption) { - return gsignond_dictionary_remove (info, - GSIGNOND_IDENTITY_INFO_CAPTION); + return gsignond_dictionary_remove (info->map, + GSIGNOND_IDENTITY_INFO_CAPTION) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_CAPTION); } - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_CAPTION, - g_variant_new_string (caption)); + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_CAPTION, + g_variant_new_string (caption)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_CAPTION); } /** @@ -644,14 +748,11 @@ gsignond_identity_info_set_caption ( GSequence * gsignond_identity_info_get_realms (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_REALMS); - if (var != NULL) { - return _gsignond_identity_info_variant_to_sequence (var); - } - return NULL; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_REALMS); + return var ? gsignond_variant_to_sequence (var) : NULL; } /** @@ -669,13 +770,24 @@ gsignond_identity_info_set_realms ( GSignondIdentityInfo *info, GSequence *realms) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); g_return_val_if_fail (realms != NULL, FALSE); - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_REALMS, - _gsignond_identity_info_sequence_to_variant (realms)); + GVariant *current_realms = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_REALMS); + GVariant *var_realms = gsignond_sequence_to_variant (realms); + + if (current_realms != NULL && + g_variant_equal (current_realms, var_realms) == TRUE) { + g_variant_unref (var_realms); + return TRUE; + } + + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_REALMS, + var_realms) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_REALMS); } /** @@ -691,11 +803,11 @@ gsignond_identity_info_set_realms ( GHashTable * gsignond_identity_info_get_methods (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); - GVariant *var = NULL; GHashTable *methods = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_AUTHMETHODS); + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_AUTHMETHODS); if (var != NULL) { GVariantIter iter; gchar *vmethod; @@ -710,10 +822,9 @@ gsignond_identity_info_get_methods (GSignondIdentityInfo *info) g_variant_iter_init (&iter, var); while (g_variant_iter_next (&iter, "{s^as}", &vmethod, &vmechanisms)) { - /* ownership of all content is transferred */ - seq = _gsignond_identity_info_array_to_sequence (vmechanisms); + /* ownership is transferred */ + seq = gsignond_array_to_sequence (vmechanisms); g_hash_table_insert (methods, vmethod, seq); - g_free (vmechanisms); } } return methods; @@ -735,10 +846,11 @@ gsignond_identity_info_set_methods ( GSignondIdentityInfo *info, GHashTable *methods) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); gchar **items = NULL; GVariantBuilder builder; + GVariant *current_mehtods, *var_methods; GHashTableIter iter; const gchar *method; @@ -753,14 +865,26 @@ gsignond_identity_info_set_methods ( (gpointer)&method, (gpointer)&mechanisms)) { - items = _gsignond_identity_info_sequence_to_array (mechanisms); + items = gsignond_sequence_to_array (mechanisms); g_variant_builder_add (&builder, "{s^as}", method, items); g_free (items); } - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_AUTHMETHODS, - g_variant_builder_end (&builder)); + + var_methods = g_variant_builder_end (&builder); + current_mehtods = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_AUTHMETHODS); + + if (current_mehtods != NULL && + g_variant_equal (current_mehtods, var_methods) == TRUE) { + g_variant_unref (var_methods); + return TRUE; + } + + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_AUTHMETHODS, + var_methods) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_METHODS); } /** @@ -780,14 +904,15 @@ gsignond_identity_info_get_mechanisms ( GSignondIdentityInfo *info, const gchar *method) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); GVariant *var = NULL; GSequence *mechanisms = NULL; g_return_val_if_fail (method != NULL, NULL); - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_AUTHMETHODS); + var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_AUTHMETHODS); if (var != NULL) { GVariantIter iter; gchar *vmethod; @@ -796,12 +921,10 @@ gsignond_identity_info_get_mechanisms ( g_variant_iter_init (&iter, var); while (g_variant_iter_next (&iter, "{s^as}", &vmethod, &vmechanisms)) { - /* ownership of content is transferred */ + /* ownership is transferred */ if (vmethod != NULL && g_strcmp0 (vmethod, method) == 0) { - mechanisms = _gsignond_identity_info_array_to_sequence ( - vmechanisms); + mechanisms = gsignond_array_to_sequence (vmechanisms); g_free (vmethod); - g_free (vmechanisms); break; } g_free (vmethod); vmethod = NULL; @@ -824,7 +947,7 @@ gsignond_identity_info_remove_method ( GSignondIdentityInfo *info, const gchar *method) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); GHashTable *methods = NULL; gboolean ret = FALSE; @@ -852,14 +975,11 @@ gsignond_identity_info_remove_method ( GSignondSecurityContextList * gsignond_identity_info_get_access_control_list (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_ACL); - if (var != NULL) { - return gsignond_security_context_list_from_variant (var); - } - return NULL; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_ACL); + return var ? gsignond_security_context_list_from_variant (var) : NULL; } /** @@ -877,13 +997,26 @@ gsignond_identity_info_set_access_control_list ( GSignondIdentityInfo *info, const GSignondSecurityContextList *acl) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); + + GVariant *current_acl = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_ACL); + GVariant *var_acl = NULL; + + if (!current_acl && !acl) return TRUE; + + var_acl = gsignond_security_context_list_to_variant (acl); + if (current_acl != NULL && + g_variant_equal (current_acl, var_acl) == TRUE) { + g_variant_unref (var_acl); + return TRUE; + } g_return_val_if_fail (acl != NULL, FALSE); - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_ACL, - gsignond_security_context_list_to_variant (acl)); + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_ACL, var_acl) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_ACL); } /** @@ -899,21 +1032,18 @@ gsignond_identity_info_set_access_control_list ( GSignondSecurityContext * gsignond_identity_info_get_owner (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_OWNER); - if (var != NULL) { - return gsignond_security_context_from_variant (var); - } - return NULL; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_OWNER); + return var ? gsignond_security_context_from_variant (var) : NULL; } /** * gsignond_identity_info_set_owner: * @info: instance of #GSignondIdentityInfo * - * @owners: (transfer none): owner to be set + * @owner: (transfer none): owner to be set * * Sets the owner of the info. * @@ -922,15 +1052,23 @@ gsignond_identity_info_get_owner (GSignondIdentityInfo *info) gboolean gsignond_identity_info_set_owner ( GSignondIdentityInfo *info, - const GSignondSecurityContext *owners) + const GSignondSecurityContext *owner) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - g_return_val_if_fail (owners != NULL, FALSE); - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_OWNER, - gsignond_security_context_to_variant (owners)); + g_return_val_if_fail (owner != NULL, FALSE); + GSignondSecurityContext *current_owner = + gsignond_identity_info_get_owner (info); + + if (current_owner != NULL && + gsignond_security_context_compare (current_owner, owner) == 0) + return TRUE; + + return (gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_OWNER, + gsignond_security_context_to_variant (owner)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_OWNER)); } /** @@ -944,14 +1082,11 @@ gsignond_identity_info_set_owner ( gboolean gsignond_identity_info_get_validated (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_VALIDATED); - if (var != NULL) { - return g_variant_get_boolean (var); - } - return FALSE; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_VALIDATED); + return var ? g_variant_get_boolean (var) : FALSE; } /** @@ -969,12 +1104,16 @@ gsignond_identity_info_set_validated ( GSignondIdentityInfo *info, gboolean validated) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_VALIDATED, - g_variant_new_boolean (validated)); + if (gsignond_identity_info_get_validated (info) == validated) + return TRUE; + + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_VALIDATED, + g_variant_new_boolean (validated)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_VALIDATED); } /** @@ -988,14 +1127,11 @@ gsignond_identity_info_set_validated ( guint32 gsignond_identity_info_get_identity_type (GSignondIdentityInfo *info) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), 0); - GVariant *var = NULL; - var = gsignond_dictionary_get (info, GSIGNOND_IDENTITY_INFO_TYPE); - if (var != NULL) { - return g_variant_get_int32 (var); - } - return -1; + GVariant *var = gsignond_dictionary_get (info->map, + GSIGNOND_IDENTITY_INFO_TYPE); + return var ? g_variant_get_int32 (var) : 0; } /** @@ -1013,12 +1149,16 @@ gsignond_identity_info_set_identity_type ( GSignondIdentityInfo *info, guint32 type) { - g_assert (info != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); - return gsignond_dictionary_set ( - info, - GSIGNOND_IDENTITY_INFO_TYPE, - g_variant_new_int32 (type)); + if (gsignond_identity_info_get_identity_type (info) == type) + return TRUE; + + return gsignond_dictionary_set (info->map, + GSIGNOND_IDENTITY_INFO_TYPE, + g_variant_new_int32 (type)) && + gsignond_identity_info_set_edit_flags (info, + IDENTITY_INFO_PROP_TYPE); } /** @@ -1036,7 +1176,8 @@ gsignond_identity_info_compare ( GSignondIdentityInfo *info, GSignondIdentityInfo *other) { - g_assert (info != NULL && other != NULL); + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), FALSE); + g_return_val_if_fail (other && GSIGNOND_IS_IDENTITY_INFO (other), FALSE); GSequence *info_realms = NULL, *other_realms = NULL; GHashTable *info_methods = NULL, *other_methods = NULL; @@ -1132,10 +1273,45 @@ gsignond_identity_info_compare ( return TRUE; } +/** + * gsignond_identity_info_to_variant: + * @info: instance of #GSignondIdentityInfo + * + * Converts the #GSignondIndentityInfo to a #GVariant. + * + * Returns: (transfer full): #GVariant object if successful, NULL otherwise. + */ +GVariant * +gsignond_identity_info_to_variant (GSignondIdentityInfo *info) +{ + gboolean username_is_secret ; + + g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL); + + username_is_secret = gsignond_identity_info_get_is_username_secret (info); + + if (username_is_secret) + return gsignond_dictionary_to_variant (info->map); + else { + GVariant *vdict = NULL; + GVariantBuilder *builder = + gsignond_dictionary_to_variant_builder (info->map); + if (!builder) return NULL; + + g_variant_builder_add (builder, "{sv}", GSIGNOND_IDENTITY_INFO_USERNAME, + g_variant_new_string (info->username ? info->username : "")); + + vdict = g_variant_builder_end (builder); + + g_variant_builder_unref (builder); + + return vdict; + } +} + void gsignond_identity_info_list_free (GSignondIdentityInfoList *list) { g_return_if_fail (list != NULL); g_list_free_full (list, (GDestroyNotify)gsignond_identity_info_unref); } - diff --git a/src/common/gsignond-identity-info.h b/src/common/gsignond-identity-info.h index be6d318..d882e16 100644 --- a/src/common/gsignond-identity-info.h +++ b/src/common/gsignond-identity-info.h @@ -33,24 +33,34 @@ G_BEGIN_DECLS -#define GSIGNOND_TYPE_IDENTITY_INFO (GSIGNOND_TYPE_DICTIONARY) - -#define GSIGNOND_IDENTITY_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ +#define GSIGNOND_TYPE_IDENTITY_INFO (gsignond_identity_info_get_type()) +#define GSIGNOND_IDENTITY_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ GSIGNOND_TYPE_IDENTITY_INFO, \ GSignondIdentityInfo)) -#define GSIGNOND_IS_IDENTITY_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ - GSIGNOND_TYPE_IDENTITY_INFO)) +/*#define GSIGNOND_IS_IDENTITY_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ + GSIGNOND_TYPE_IDENTITY_INFO))*/ + +#define GSIGNOND_IS_IDENTITY_INFO(obj) (obj) -typedef GSignondDictionary GSignondIdentityInfo; +typedef struct _GSignondIdentityInfo GSignondIdentityInfo; typedef GList GSignondIdentityInfoList; +GType gsignond_identity_info_get_type (void) G_GNUC_CONST; + + GSignondIdentityInfo * gsignond_identity_info_new (void); GSignondIdentityInfo * +gsignond_identity_info_new_from_variant (GVariant *variatn_mp); + +GVariant * +gsignond_identity_info_to_variant (GSignondIdentityInfo *info); + +GSignondIdentityInfo * gsignond_identity_info_copy (GSignondIdentityInfo *info); -void +GSignondIdentityInfo * gsignond_identity_info_ref (GSignondIdentityInfo *info); void @@ -78,9 +88,6 @@ gsignond_identity_info_set_username ( GSignondIdentityInfo *info, const gchar *username); -void -gsignond_identity_info_remove_username (GSignondIdentityInfo *info); - gboolean gsignond_identity_info_get_is_username_secret (GSignondIdentityInfo *info); @@ -97,9 +104,6 @@ gsignond_identity_info_set_secret ( GSignondIdentityInfo *info, const gchar *secret); -void -gsignond_identity_info_remove_secret (GSignondIdentityInfo *info); - gboolean gsignond_identity_info_get_store_secret (GSignondIdentityInfo *info); @@ -179,6 +183,9 @@ gsignond_identity_info_compare ( GSignondIdentityInfo *info, GSignondIdentityInfo *other); +GVariant * +gsignond_identity_info_to_variant (GSignondIdentityInfo *info); + void gsignond_identity_info_list_free (GSignondIdentityInfoList *list); diff --git a/src/common/gsignond-plugin-interface.c b/src/common/gsignond-plugin-interface.c index be98631..a0db247 100644 --- a/src/common/gsignond-plugin-interface.c +++ b/src/common/gsignond-plugin-interface.c @@ -29,10 +29,10 @@ /** * SECTION:gsignond-plugin-interface - * @short_description: an interface for implementing authentication plugins + * @short_description: an interface for implementing GLib-based authentication plugins * @include: gsignond/gsignond-plugin-interface.h * - * #GSignondPlugin is an interface for implementing authentication plugins. + * #GSignondPlugin is an interface for implementing GLib-based authentication plugins. * * When creating a plugin, write the #GObject boilerplate code as usual, but * diff --git a/src/common/gsignond-plugin-loader.c b/src/common/gsignond-plugin-loader.c deleted file mode 100644 index 99dd5bd..0000000 --- a/src/common/gsignond-plugin-loader.c +++ /dev/null @@ -1,83 +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 gsignond - * - * Copyright (C) 2012 Intel Corporation. - * - * Contact: Alexander Kanavin <alex.kanavin@gmail.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - - -#include <gmodule.h> - -#include "gsignond/gsignond-log.h" -#include "gsignond-plugin-loader.h" - -GSignondPlugin* -gsignond_load_plugin( - GSignondConfig* config, - gchar* plugin_type) -{ - gchar* plugin_filename = g_module_build_path ( - gsignond_config_get_string (config, - GSIGNOND_CONFIG_GENERAL_PLUGINS_DIR), plugin_type); - GSignondPlugin *plugin = gsignond_load_plugin_with_filename (plugin_type, - plugin_filename); - g_free(plugin_filename); - return plugin; -} - -GSignondPlugin* -gsignond_load_plugin_with_filename( - gchar *plugin_type, - gchar *plugin_filename) -{ - DBG("Loading plugin %s", plugin_filename); - GModule* plugin_module = g_module_open (plugin_filename, - G_MODULE_BIND_LOCAL); - if (plugin_module == NULL) { - DBG("Plugin couldn't be opened: %s", g_module_error()); - return NULL; - } - - gchar* plugin_get_type = g_strdup_printf("gsignond_%s_plugin_get_type", - plugin_type); - gpointer p; - - DBG("Resolving symbol %s", plugin_get_type); - gboolean symfound = g_module_symbol (plugin_module, - plugin_get_type, &p); - g_free(plugin_get_type); - if (!symfound) { - DBG("Symbol couldn't be resolved"); - g_module_close (plugin_module); - return NULL; - } - - DBG("Creating plugin object"); - GType (*plugin_get_type_f)(void) = p; - GSignondPlugin* plugin = g_object_new(plugin_get_type_f(), NULL); - if (plugin == NULL) { - DBG("Plugin couldn't be created"); - g_module_close (plugin_module); - return NULL; - } - g_module_make_resident (plugin_module); - return plugin; -} diff --git a/src/common/gsignond-plugin-loader.h b/src/common/gsignond-plugin-loader.h deleted file mode 100644 index 0c1e727..0000000 --- a/src/common/gsignond-plugin-loader.h +++ /dev/null @@ -1,47 +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 gsignond - * - * Copyright (C) 2012 Intel Corporation. - * - * Contact: Alexander Kanavin <alex.kanavin@gmail.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef _GSIGNOND_PLUGIN_LOADER_H_ -#define _GSIGNOND_PLUGIN_LOADER_H_ - -#include <gsignond/gsignond-plugin-interface.h> -#include <gsignond/gsignond-config.h> - -G_BEGIN_DECLS - -GSignondPlugin* -gsignond_load_plugin( - GSignondConfig* config, - gchar* plugin_type); - -GSignondPlugin* -gsignond_load_plugin_with_filename( - gchar *plugin_type, - gchar *plugin_filename); - -G_END_DECLS - -#endif /* _GSIGNOND_PLUGIN_LOADER_H_ */ - diff --git a/src/common/gsignond-session-data.c b/src/common/gsignond-session-data.c index a8583f3..6e0b49f 100644 --- a/src/common/gsignond-session-data.c +++ b/src/common/gsignond-session-data.c @@ -23,7 +23,8 @@ * 02110-1301 USA */ -#include <gsignond/gsignond-session-data.h> +#include "gsignond/gsignond-session-data.h" +#include "gsignond/gsignond-utils.h" /** @@ -132,6 +133,36 @@ gsignond_session_data_get_realm (GSignondSessionData *data) } /** + * gsignond_session_data_set_allowed_realms: + * @data: a #GSignondDictionary structure + * @realms: a #GSequence if allowed realms + * + * A setter for a list of realms allowed for the identity use. + */ +void +gsignond_session_data_set_allowed_realms (GSignondSessionData *data, + GSequence *realms) +{ + gsignond_dictionary_set (data, "AllowedRealms", + gsignond_sequence_to_variant (realms)); +} + +/** + * gsignond_session_data_get_allowed_realms: + * @data: a #GSignondDictionary structure + * + * A getter for a list of realms allowed for the identity use. + * + * Returns: (transfer full): #GSequence of allowed realms + */ +GSequence * +gsignond_session_data_get_allowed_realms (GSignondSessionData *data) +{ + return gsignond_variant_to_sequence (gsignond_dictionary_get (data, + "AllowedRealms")); +} + +/** * gsignond_session_data_set_realm: * @data: a #GSignondDictionary structure * @realm: a realm to set diff --git a/src/common/gsignond-storage-manager.c b/src/common/gsignond-storage-manager.c index 7df6c27..7483527 100644 --- a/src/common/gsignond-storage-manager.c +++ b/src/common/gsignond-storage-manager.c @@ -28,6 +28,8 @@ #include <glib/gstdio.h> +#include "config.h" + #include "gsignond/gsignond-log.h" #include "gsignond/gsignond-storage-manager.h" #include "gsignond/gsignond-utils.h" @@ -81,14 +83,16 @@ _set_config (GSignondStorageManager *self, GSignondConfig *config) const gchar *storage_path = gsignond_config_get_string ( self->config, GSIGNOND_CONFIG_GENERAL_STORAGE_PATH); - if (storage_path) - self->location = g_build_filename (storage_path, - user_dir, - NULL); - else - self->location = g_build_filename ("/var/db", - user_dir, - NULL); + if (!storage_path) { + storage_path = BASE_STORAGE_DIR; + DBG ("storage path not configured, using default location"); + } +# ifdef ENABLE_DEBUG + const gchar *env_val = g_getenv("SSO_STORAGE_PATH"); + if (env_val) + storage_path = env_val; +# endif + self->location = g_build_filename (storage_path, user_dir, NULL); g_free (user_dir); DBG ("secure dir %s", self->location); } @@ -285,7 +289,7 @@ gsignond_storage_manager_init (GSignondStorageManager *self) * @self: object instance. * * Initialize encryption storage. This means making sure that the - * necessary directories exist and are accessible. + * necessary directories under #GSIGNOND_CONFIG_GENERAL_STORAGE_PATH exist and are accessible. * * Returns: success? */ @@ -332,7 +336,8 @@ gsignond_storage_manager_storage_is_initialized (GSignondStorageManager *self) * @self: object instance. * * Mounts an encrypted storage and returns the filesystem path of the storage - * mount point. This path will be used to access the secret database via + * mount point. This path will be set in #GSignondConfig as + * #GSIGNOND_CONFIG_GENERAL_SECURE_DIR and used to access the secret database via * #GSignondSecretStorage. * * The default implemenation does nothing, and immediately returns the path for the diff --git a/src/common/gsignond-utils.c b/src/common/gsignond-utils.c index df84032..83466fd 100644 --- a/src/common/gsignond-utils.c +++ b/src/common/gsignond-utils.c @@ -264,3 +264,184 @@ nonce_exit: return nonce; } +static gint +_compare_strings ( + const gchar* a, + const gchar* b, + gpointer data) +{ + (void)data; + return g_strcmp0 (a,b); +} + +/** + * gsignond_sequence_to_variant: + * @seq: Sequence of strings to convert + * + * Convert a string sequence to a variant. + * + * Returns: (transfer full): #GVariant of type "as". + */ +GVariant * +gsignond_sequence_to_variant (GSequence *seq) +{ + GSequenceIter * iter = NULL; + GVariant *var = NULL; + GVariantBuilder builder; + + if (!seq) return NULL; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY); + iter = g_sequence_get_begin_iter (seq); + while (!g_sequence_iter_is_end (iter)) { + const gchar * d = g_sequence_get (iter); + g_variant_builder_add (&builder, "s", d); + iter = g_sequence_iter_next (iter); + } + var = g_variant_builder_end (&builder); + return var; +} + +/** + * gsignond_variant_to_sequence: + * @var: Variant of "as" to convert + * + * Convert variant containing string array to sequence. + * + * Returns: (transfer full): #GSequence of strings + */ +GSequence * +gsignond_variant_to_sequence (GVariant *var) +{ + GVariantIter iter; + GSequence *seq = NULL; + gchar *item = NULL; + + if (!var) return NULL; + + seq = g_sequence_new ((GDestroyNotify)g_free); + g_variant_iter_init (&iter, var); + while (g_variant_iter_next (&iter, "s", &item)) { + g_sequence_insert_sorted (seq, + item, + (GCompareDataFunc) _compare_strings, + NULL); + } + return seq; +} + +/** + * gsignond_sequence_to_array: + * @seq: Sequence of strings to convert + * + * Convert sequence of strings to null-terminated string array. + * + * Returns: (transfer full): Null-terminated array of strings + */ +gchar ** +gsignond_sequence_to_array (GSequence *seq) +{ + gchar **items, **temp; + GSequenceIter *iter; + + if (!seq) return NULL; + + items = g_malloc0 ((g_sequence_get_length (seq) + 1) * sizeof (gchar *)); + temp = items; + for (iter = g_sequence_get_begin_iter (seq); + iter != g_sequence_get_end_iter (seq); + iter = g_sequence_iter_next (iter)) { + *temp = g_sequence_get (iter); + temp++; + } + return items; +} + +/** + * gsignond_array_to_sequence: + * @items: (transfer full): Null-terminated array of strings to convert + * + * Convert null-terminated array of strings to a sequence. + * + * Returns: (transfer full): #GSequence of strings + */ +GSequence * +gsignond_array_to_sequence (gchar **items) +{ + gchar **item_iter = items; + GSequence *seq = NULL; + + if (!items) return NULL; + + seq = g_sequence_new ((GDestroyNotify) g_free); + while (*item_iter) { + g_sequence_insert_sorted (seq, + *item_iter, + (GCompareDataFunc) _compare_strings, + NULL); + item_iter++; + } + g_free (items); + return seq; +} + +/** + * gsignond_copy_array_to_sequence: + * @items: Null-terminated array of strings to copy + * + * Copy null-terminated array of strings to a sequence. + * + * Returns: (transfer full): #GSequence of strings + */ +GSequence * +gsignond_copy_array_to_sequence (const gchar **items) +{ + GSequence *seq = NULL; + + if (!items) return NULL; + + seq = g_sequence_new ((GDestroyNotify) g_free); + while (*items) { + g_sequence_insert_sorted (seq, + g_strdup (*items), + (GCompareDataFunc) _compare_strings, + NULL); + items++; + } + return seq; +} + +/** + * gsignond_is_host_in_domain: + * @domain: a domain name + * @host: a host name + * + * Checks if @host belongs to @domain. + * + * Returns: the result + */ +gboolean +gsignond_is_host_in_domain(const gchar *host, const gchar *domain) +{ + gchar** domain_parts = g_strsplit(domain, ".", 0); + gchar** host_parts = g_strsplit(host, ".", 0); + gchar** truncated_host_parts = host_parts; + + guint domain_parts_n = g_strv_length(domain_parts); + guint host_parts_n = g_strv_length(host_parts); + + gint extra_host_parts_n = host_parts_n - domain_parts_n; + + while (extra_host_parts_n > 0) { + truncated_host_parts++; + extra_host_parts_n--; + } + gchar* truncated_host = g_strjoinv(".", truncated_host_parts); + gint result = g_strcmp0(domain, truncated_host); + + g_free(truncated_host); + g_strfreev(host_parts); + g_strfreev(domain_parts); + + return result == 0 ? TRUE : FALSE; +}
\ No newline at end of file |