Commit 3dfd7aa7 authored by Stef Walter's avatar Stef Walter Committed by nobody
Browse files

Initial module setup. Implement GSecretData

parents
*~
*.o
*.la
*.lo
.deps
.cproject
.libs
.project
aclocal.m4
autom4te.cache
compile
configure
config.*
depcomp
install-sh
INSTALL
libtool
ltmain.sh
m4
Makefile
Makefile.in
Makefile.in.in
missing
stamp*
/po/POTFILES
Stef Walter <stefw@collabora.co.uk>
This diff is collapsed.
=== ChangeLog discontinued ===
gsecret relies on commit messages to provide change history. Please
write commit messages in the following format:
=== begin example commit ===
Short explanation of the commit
Longer explanation explaining exactly what's changed, whether any
external or private interfaces changed, what bugs were fixed (with bug
tracker reference if applicable) and so forth. Be concise but not too
brief.
=== end example commit ===
- Always add a brief description of the commit to the _first_ line of
the commit and terminate by two newlines. This may be the title of
a fixed bug, copied from Bugzilla.
- First line (the brief description) must only be one sentence and
should start with a capital letter unless it starts with a
lowercase symbol or identifier. Don't use a trailing full stop,
and don't exceed 72 characters.
- The main description (the body) is normal prose and should use
normal punctuation and capital letters where appropriate.
- When committing code on behalf of others use the --author option,
e.g. git commit -a --author "Joe Coder <joe@coder.org>" and
--signoff.
## Process this file with automake to produce Makefile.in
include $(top_srcdir)/Makefile.decl
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS = po egg library
2.27.90
=======
* Fixed configure script to actually error out if installed glib
version is too old (Emilio Pozuelo Monfort)
* gnutls: updated GTlsClientConnectionGnutls for :accepted-cas type
change (Stef Walter)
* gnutls: fixed an uninitialized variable (Dan Winship)
2.27.5
======
* gnutls: finish implementing GTlsRehandshakeMode, which was present
but non-functional in 2.27.4
* gnutls: updates for glib TLS API changes
* gnutls: fix some async bugs that caused the main loop to spin
* gnutls: implement a client-side session cache, to speed up
handshakes
* Compile with gcc warnings by default
2.27.4
======
* GNUTLS-based implementation of GTlsBackend
2.26.0
======
* No changes, just a version bump
2.25.0
======
* Initial release, with libproxy-based GProxyResolver
GObject based library for accessing the Secret Service API.
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
PROJECT=gsecret
TEST_TYPE=-f
FILE=library/gsecret-data.c
DIE=0
have_libtool=false
if libtoolize --version < /dev/null > /dev/null 2>&1 ; then
libtool_version=`libtoolize --version |
head -1 |
sed -e 's/^\(.*\)([^)]*)\(.*\)$/\1\2/g' \
-e 's/^[^0-9]*\([0-9.][0-9.]*\).*/\1/'`
case $libtool_version in
2.2*)
have_libtool=true
;;
2.4*)
have_libtool=true
;;
esac
fi
if $have_libtool ; then : ; else
echo
echo "You must have libtool >= 2.2 installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/"
DIE=1
fi
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/"
DIE=1
}
if automake-1.11 --version < /dev/null > /dev/null 2>&1 ; then
AUTOMAKE=automake-1.11
ACLOCAL=aclocal-1.11
else if automake-1.10 --version < /dev/null > /dev/null 2>&1 ; then
AUTOMAKE=automake-1.10
ACLOCAL=aclocal-1.10
else
echo
echo "You must have automake 1.10.x or 1.11.x installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/"
DIE=1
fi
fi
if test "$DIE" -eq 1; then
exit 1
fi
test $TEST_TYPE $FILE || {
echo "You must run this script in the top-level $PROJECT directory"
exit 1
}
# NOCONFIGURE is used by gnome-common; support both
if ! test -z "$AUTOGEN_SUBDIR_MODE"; then
NOCONFIGURE=1
fi
if test -z "$NOCONFIGURE"; then
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
fi
rm -rf autom4te.cache
# README and INSTALL are required by automake, but may be deleted by clean
# up rules. to get automake to work, simply touch these here, they will be
# regenerated from their corresponding *.in files by ./configure anyway.
touch README INSTALL
$ACLOCAL $ACLOCAL_FLAGS || exit $?
libtoolize --force || exit $?
intltoolize --force --copy || exit $?
autoheader || exit $?
$AUTOMAKE --add-missing || exit $?
autoconf || exit $?
cd $ORIGDIR || exit $?
if test -z "$NOCONFIGURE"; then
$srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
echo
echo "Now type 'make' to compile $PROJECT."
fi
AC_PREREQ(2.65)
AC_CONFIG_MACRO_DIR([m4])
AC_INIT([gsecret],[0.1],[http://bugzilla.gnome.org/enter_bug.cgi?product=gsecret])
AC_CONFIG_SRCDIR([library/gsecret-data.c])
AC_CONFIG_HEADERS([config.h])
dnl Other initialization
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE([enable])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],)
LT_INIT
dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AM_PROG_CC_C_O
dnl Checks for libraries.
dnl ****************************
dnl *** Checks for intltool
IT_PROG_INTLTOOL([0.35.0])
GETTEXT_PACKAGE=gsecret
AC_SUBST([GETTEXT_PACKAGE])
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[The gettext domain name])
AM_GLIB_GNU_GETTEXT
dnl *****************************
dnl *** Check GLib
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16.0 gio-2.0 >= 2.16.0 gthread-2.0 >= 2.16.0)
LIBS="$LIBS $GLIB_LIBS"
CFLAGS="$CFLAGS $GLIB_CFLAGS"
AC_CHECK_FUNCS(mlock)
dnl *************************************
dnl *** Warnings to show if using GCC ***
dnl *************************************
AC_ARG_ENABLE(more-warnings,
AS_HELP_STRING([--disable-more-warnings], [Inhibit compiler warnings]),
set_more_warnings=no)
if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
CFLAGS="$CFLAGS \
-Wall -Wstrict-prototypes -Wmissing-declarations \
-Wmissing-prototypes -Wnested-externs -Wpointer-arith \
-Wdeclaration-after-statement -Wformat=2 -Winit-self \
-Waggregate-return -Wmissing-format-attribute"
for option in -Wmissing-include-dirs -Wundef; do
SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $option"
AC_MSG_CHECKING([whether gcc understands $option])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
[has_option=yes],
[has_option=no])
AC_MSG_RESULT($has_option)
if test $has_option = no; then
CFLAGS="$SAVE_CFLAGS"
fi
done
fi
dnl *****************************
dnl *** done ***
dnl *****************************
AC_CONFIG_FILES([Makefile
egg/Makefile
po/Makefile.in
po/Makefile
library/Makefile
])
AC_OUTPUT
noinst_LTLIBRARIES = \
libegg.la
INCLUDES = \
-I$(top_srcdir)
libegg_la_SOURCES = \
egg-secure-memory.c egg-secure-memory.h \
$(BUILT_SOURCES)
This diff is collapsed.
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* egg-secure-memory.h - library for allocating memory that is non-pageable
Copyright (C) 2007 Stefan Walter
The Gnome Keyring Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Keyring 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Stef Walter <stef@memberwebs.com>
*/
#ifndef EGG_SECURE_MEMORY_H
#define EGG_SECURE_MEMORY_H
#include <stdlib.h>
/* -------------------------------------------------------------------
* Low Level Secure Memory
*
* IMPORTANT: This is pure vanila standard C, no glib. We need this
* because certain consumers of this protocol need to be built
* without linking in any special libraries. ie: the PKCS#11 module.
*
* Thread locking
*
* In order to use these functions in a module the following functions
* must be defined somewhere, and provide appropriate locking for
* secure memory between threads:
*/
extern void egg_memory_lock (void);
extern void egg_memory_unlock (void);
/*
* Allocation Fallbacks
*
* If we cannot allocate secure memory, then this function
* (defined elsewhere) will be called which has a chance to
* allocate other memory abort or do whatever.
*
* Same call semantics as realloc with regard to NULL and zeros
*/
extern void* egg_memory_fallback (void *p, size_t length);
#define EGG_SECURE_GLIB_DEFINITIONS() \
static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT; \
void egg_memory_lock (void) \
{ g_static_mutex_lock (&memory_mutex); } \
void egg_memory_unlock (void) \
{ g_static_mutex_unlock (&memory_mutex); } \
void* egg_memory_fallback (void *p, size_t sz) \
{ return g_realloc (p, sz); } \
/*
* Main functionality
*
* Allocations return NULL on failure.
*/
#define GKR_SECURE_USE_FALLBACK 0x0001
void* egg_secure_alloc (size_t length);
void* egg_secure_alloc_full (size_t length, int flags);
void* egg_secure_realloc (void *p, size_t length);
void* egg_secure_realloc_full (void *p, size_t length, int fallback);
void egg_secure_free (void* p);
void egg_secure_free_full (void* p, int fallback);
void egg_secure_clear (void *p, size_t length);
int egg_secure_check (const void* p);
void egg_secure_validate (void);
void egg_secure_dump_blocks (void);
char* egg_secure_strdup (const char *str);
void egg_secure_strclear (char *str);
void egg_secure_strfree (char *str);
#endif /* EGG_SECURE_MEMORY_H */
include $(top_srcdir)/Makefile.decl
NULL =
module_flags = \
-export_dynamic \
-avoid-version \
-module \
-no-undefined \
-export-symbols-regex '^gsecret_'
lib_LTLIBRARIES = libgsecret.la
libgsecret_la_SOURCES = \
gsecret-data.h gsecret-data.c
libgsecret_la_LIBADD = \
$(top_builddir)/egg/libegg.la \
$(LIBS)
\ No newline at end of file
/* GSecret - GLib wrapper for Secret Service
*
* Copyright 2011 Collabora Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the licence or (at
* your option) any later version.
*
* See the included COPYING file for more information.
*/
#include "config.h"
#include "gsecret-data.h"
#include "egg/egg-secure-memory.h"
#include <string.h>
struct _GSecretData {
gint refs;
gpointer secret;
gsize length;
GDestroyNotify destroy;
gchar *content_type;
};
GType
gsecret_data_get_type (void)
{
static gsize initialized = 0;
static GType type = 0;
if (g_once_init_enter (&initialized)) {
type = g_boxed_type_register_static ("GSecretData",
(GBoxedCopyFunc)gsecret_data_ref,
(GBoxedFreeFunc)gsecret_data_unref);
g_once_init_leave (&initialized, 1);
}
return type;
}
GSecretData*
gsecret_data_new (const gchar *secret, gssize length, const gchar *content_type)
{
gchar *copy;
g_return_val_if_fail (!secret && length, NULL);
g_return_val_if_fail (content_type, NULL);
if (length < 0)
length = strlen (secret);
copy = egg_secure_alloc (length + 1);
memcpy (copy, secret, length);
copy[length] = 0;
return gsecret_data_new_full (copy, length, content_type, egg_secure_free);
}
GSecretData*
gsecret_data_new_full (gchar *secret, gssize length,
const gchar *content_type, GDestroyNotify destroy)
{
GSecretData *data;
g_return_val_if_fail (!secret && length, NULL);
g_return_val_if_fail (content_type, NULL);
if (length < 0)
length = strlen (secret);
data = g_slice_new0 (GSecretData);
data->content_type = strdup (content_type);
data->destroy = destroy;
data->length = length;
data->secret = secret;
return data;
}
const gchar*
gsecret_data_get (GSecretData *data, gsize *length)
{
g_return_val_if_fail (data, NULL);
if (length)
*length = data->length;
return data->secret;
}
const gchar*
gsecret_data_get_content_type (GSecretData *data)
{
g_return_val_if_fail (data, NULL);
return data->content_type;
}
GSecretData*
gsecret_data_ref (GSecretData *data)
{
g_return_val_if_fail (data, NULL);
g_atomic_int_inc (&data->refs);
return data;
}
void
gsecret_data_unref (GSecretData *data)
{
g_return_if_fail (data);
if (g_atomic_int_dec_and_test (&data->refs)) {
g_free (data->content_type);
if (data->destroy)
(data->destroy) (data->secret);
g_slice_free (GSecretData, data);
}
}
/* GSecret - GLib wrapper for Secret Service
*
* Copyright 2011 Collabora Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the licence or (at
* your option) any later version.
*
* See the included COPYING file for more information.
*/
#ifndef __GSECRET_DATA_H__
#define __GSECRET_DATA_H__
#include <gio/gio.h>
G_BEGIN_DECLS
#define GSECRET_TYPE_DATA (gsecret_service_get_type ())
typedef struct _GSecretData GSecretData;
GType gsecret_data_get_type (void) G_GNUC_CONST;
GSecretData* gsecret_data_new (const gchar *secret,
gssize length,
const gchar *content_type);
GSecretData* gsecret_data_new_full (gchar *secret,
gssize length,
const gchar *content_type,
GDestroyNotify destroy);
const gchar* gsecret_data_get (GSecretData *data,
gsize *length);
const gchar* gsecret_data_get_content_type (GSecretData *data);
GSecretData* gsecret_data_ref (GSecretData *data);
void gsecret_data_unref (GSecretData *data);
G_END_DECLS
#endif /* __G_SERVICE_H___ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment