--- /dev/null
+/* 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) 2013 Intel Corporation.
+ *
+ * Contact: Jussi Laako <jussi.laako@linux.intel.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_UTILS_H_
+#define _GSIGNOND_UTILS_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean
+gsignond_wipe_file (const gchar *);
+
+gboolean
+gsignond_wipe_directory (const gchar *);
+
+G_END_DECLS
+
+#endif /* _SGINOND_UTILS_H_ */
+
gsignond-session-data.c \
gsignond-signonui-data.c \
gsignond-plugin-loader.c \
+ gsignond-utils.c \
$(BUILT_SOURCES) \
$(NULL)
#include <glib/gstdio.h>
#include "gsignond/gsignond-storage-manager.h"
+#include "gsignond/gsignond-utils.h"
#define GSIGNOND_STORAGE_MANAGER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
static gboolean
_delete_storage (GSignondStorageManager *self)
{
- const gchar *filename;
- GDir *storage_dir;
-
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (self->location, FALSE);
- storage_dir = g_dir_open (self->location, 0, NULL);
- if (!storage_dir)
- return FALSE;
- while ((filename = g_dir_read_name (storage_dir)) != NULL) {
- g_remove (filename);
- }
- g_dir_close (storage_dir);
- if (g_rmdir (self->location))
- return FALSE;
-
- return TRUE;
+ return gsignond_wipe_directory (self->location);
}
static gboolean
--- /dev/null
+/* 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) 2013 Intel Corporation.
+ *
+ * Contact: Jussi Laako <jussi.laako@linux.intel.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 <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include "gsignond/gsignond-utils.h"
+
+
+static size_t pagesize = 0;
+
+
+gboolean
+gsignond_wipe_file (const gchar *filename)
+{
+ gboolean retval = FALSE;
+ int rngfd;
+ int wipefd;
+ size_t sizeleft;
+ size_t writesize;
+ ssize_t sizewritten;
+ struct stat filestat;
+ guint8 *wipebuf;
+
+ if (!pagesize) {
+ long confval = sysconf (_SC_PAGE_SIZE);
+ if (confval <= 0)
+ return FALSE;
+ pagesize = (size_t) confval;
+ }
+
+ rngfd = open ("/dev/urandom", O_RDONLY);
+ if (rngfd < 0)
+ return FALSE;
+
+ wipefd = open (filename, O_WRONLY | O_SYNC);
+ if (rngfd < 0)
+ goto _rng_exit;
+ wipebuf = g_malloc (pagesize);
+ if (fstat (wipefd, &filestat))
+ goto _wipe_exit;
+
+ /* write all 1's */
+ sizeleft = filestat.st_size;
+ memset (wipebuf, 0xff, pagesize);
+ while (sizeleft) {
+ writesize = (sizeleft < pagesize) ? sizeleft : pagesize;
+ sizewritten = write (wipefd, wipebuf, writesize);
+ if (sizewritten != (ssize_t) writesize)
+ goto _wipe_exit;
+ sizeleft -= sizewritten;
+ }
+
+ if (lseek (wipefd, 0, SEEK_SET) == (off_t) -1)
+ goto _wipe_exit;
+
+ /* write all 0's */
+ sizeleft = filestat.st_size;
+ memset (wipebuf, 0x00, pagesize);
+ while (sizeleft) {
+ writesize = (sizeleft < pagesize) ? sizeleft : pagesize;
+ sizewritten = write (wipefd, wipebuf, writesize);
+ if (sizewritten != (ssize_t) writesize)
+ goto _wipe_exit;
+ sizeleft -= sizewritten;
+ }
+
+ if (lseek (wipefd, 0, SEEK_SET) == (off_t) -1)
+ goto _wipe_exit;
+
+ /* write random */
+ sizeleft = filestat.st_size;
+ while (sizeleft) {
+ writesize = (sizeleft < pagesize) ? sizeleft : pagesize;
+ if (read (rngfd, wipebuf, writesize) != (ssize_t) writesize)
+ goto _wipe_exit;
+ sizewritten = write (wipefd, wipebuf, writesize);
+ if (sizewritten != (ssize_t) writesize)
+ goto _wipe_exit;
+ sizeleft -= sizewritten;
+ }
+
+ /* don't leave traces of last pattern to the memory */
+ memset (wipebuf, 0x00, pagesize);
+
+ /* remove the file and set return value on success */
+ if (unlink (filename) == 0)
+ retval = TRUE;
+
+_wipe_exit:
+ g_free (wipebuf);
+ close (wipefd);
+_rng_exit:
+ close (rngfd);
+ return retval;
+}
+
+
+gboolean
+gsignond_wipe_directory (const gchar *dirname)
+{
+ gboolean retval = FALSE;
+ gboolean wiperes;
+ const gchar *filename;
+ gchar *filepath;
+ GDir *dirctx;
+
+ dirctx = g_dir_open (dirname, 0, NULL);
+ if (!dirctx)
+ return FALSE;
+ while ((filename = g_dir_read_name (dirctx))) {
+ filepath = g_build_filename (dirname, filename, NULL);
+ wiperes = gsignond_wipe_file (filepath);
+ g_free (filepath);
+ if (!wiperes)
+ goto _dir_exit;
+ }
+ retval = TRUE;
+
+_dir_exit:
+ g_dir_close (dirctx);
+ return retval;
+}
+
g_object_unref (adapter);
return NULL;
}
- DBG("(+) started auth service '%p' at path '%s' on conneciton '%p'", adapter, GSIGNOND_DAEMON_OBJECTPATH, bus_connection);
+ DBG("(+) started auth service '%p' at path '%s' on connection '%p'", adapter, GSIGNOND_DAEMON_OBJECTPATH, bus_connection);
timeout = gsignond_daemon_get_timeout (adapter->priv->auth_service);
if (timeout) {
GType gsignond_dbus_auth_service_adapter_get_type (void) G_GNUC_CONST;
GSignondDbusAuthServiceAdapter *
-gsignond_dbus_auth_service_adapter_new_with_connection (GDBusConnection *conneciton,
+gsignond_dbus_auth_service_adapter_new_with_connection (GDBusConnection *connection,
GSignondDaemon *daemon);
#ifndef USE_P2P
#include "tizen-storage-manager.h"
#include "gsignond/gsignond-log.h"
+#include "gsignond/gsignond-utils.h"
#define EXTENSION_TIZEN_STORAGE_MANAGER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
}
static gboolean
-_delete_storage (GSignondStorageManager *parent)
-{
- ExtensionTizenStorageManager *self =
- EXTENSION_TIZEN_STORAGE_MANAGER (parent);
- ExtensionTizenStorageManagerPrivate *priv = self->priv;
-
- g_return_val_if_fail (priv->cdir, FALSE);
-
- gboolean retval = FALSE;
- const gchar *filename;
- GDir *storage_dir;
-
- storage_dir = g_dir_open (priv->cdir, 0, NULL);
- if (!storage_dir)
- goto _delete_exit;
- while ((filename = g_dir_read_name (storage_dir)) != NULL) {
- DBG ("remove file %s", filename);
- g_remove (filename);
- }
- g_dir_close (storage_dir);
- DBG ("remove directory %s", priv->cdir);
- if (g_rmdir (priv->cdir))
- goto _delete_exit;
- DBG ("remove directory %s", parent->location);
- if (g_rmdir (parent->location))
- goto _delete_exit;
-
- retval = TRUE;
-
-_delete_exit:
- return retval;
-}
-
-static gboolean
_storage_is_initialized (GSignondStorageManager *parent)
{
ExtensionTizenStorageManager *self =
return retval;
}
+static gboolean
+_delete_storage (GSignondStorageManager *parent)
+{
+ ExtensionTizenStorageManager *self =
+ EXTENSION_TIZEN_STORAGE_MANAGER (parent);
+ ExtensionTizenStorageManagerPrivate *priv = self->priv;
+
+ g_return_val_if_fail (priv->cdir, FALSE);
+ g_return_val_if_fail (!_filesystem_is_mounted(parent), FALSE);
+
+ return (gsignond_wipe_directory (priv->cdir) &&
+ gsignond_wipe_directory (parent->location));
+}
+
static void
extension_tizen_storage_manager_class_init (
ExtensionTizenStorageManagerClass *klass)