gumd post user deletion hooks added 19/29619/2
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Tue, 28 Oct 2014 08:57:58 +0000 (10:57 +0200)
committerAmarnath Valluri <amarnath.valluri@linux.intel.com>
Fri, 31 Oct 2014 03:48:57 +0000 (05:48 +0200)
This commit allows cleaning up the database when user gets deleted.

Change-Id: If488d7b6ca1b20180a12d0360d68a285c0ec0471
Signed-off-by: Amarnath Valluri <amarnath.valluri@linux.intel.com>
packaging/gsignond-cleandb [new file with mode: 0755]
packaging/gsignond.spec

diff --git a/packaging/gsignond-cleandb b/packaging/gsignond-cleandb
new file mode 100755 (executable)
index 0000000..fe4fc2c
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# gsignond-cleandb
+#
+# This script is executed by 'gumd-daemon' on post delete of a user
+# gsignond-cleandb <<username>> <<uid>> <<gid>> <<homeddir>>
+#
+# NOTE: currently we do not support cleaningup the database that was set via
+#       build configuration, i.e, ./configure --enable-storagedir=<<path>>.
+#       In this case we need to manually set the $DB_BASE_PATH.
+#
+LOG_FILE=/tmp/gsignond-cleandb.log
+CONF_FILE_PATH='/etc/gsignond.conf'
+DB_BASE_PATH='/var/db'
+DB_PATH=""
+
+LOG() {
+  echo $* >> $LOG_FILE;
+}
+
+touch $LOG_FILE
+LOG `date`
+
+if [ $# -le 1 ]; then
+  LOG "Error: invalid arguments passed";
+  exit 1;
+fi
+
+LOG "Cleaning database for user $1"
+
+# Consider configured storage path if any
+if [ -f $CONF_FILE_PATH ]; then
+  storage_path=`sed -e 's/^[ \t]*//' < $CONF_FILE_PATH | grep "^StoragePath"`
+  if [ `expr length "$storage_path"` -gt 0 ]; then
+    storage_path=`echo $storage_path | cut -f2 -d'=' | tr -d ' '`
+  fi
+
+  LOG "Storage path found from conf file: $storage_path"
+  if [ `expr length $storage_path"` -gt 0 ]; then
+    DB_BASE_PATH=$storage_path
+  fi
+fi
+
+DB_PATH="$DB_BASE_PATH/gsignond.$1"
+LOG "Cleaning : $DB_PATH ..."
+
+if [ -d "$DB_PATH" ]; then
+  rm -rf "$DB_PATH" 2>> $LOG_FILE
+  exit $?
+fi
+
+LOG "Done"
+LOG "======================"
+
+exit 0
+
index f8dc13f..7aa4397 100644 (file)
@@ -13,9 +13,10 @@ License: LGPL-2.1+ and GPL-2.0+
 Source: %{name}-%{version}.tar.gz
 URL: https://01.org/gsso
 Source1001: %{name}.manifest
+Source1002: gsignond-cleandb
 Provides: gsignon
 %if %{dbus_type} != "p2p"
-Requires: dbus-1
+BuildRequires: dbus-1
 %endif
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
@@ -51,8 +52,10 @@ Requires:   %{name} = %{version}-%{release}
 %prep
 %setup -q -n %{name}-%{version}
 cp %{SOURCE1001} .
+cp %{SOURCE1002} .
 
 %build
+autoreconf -ivf
 %if %{debug_build} == 1
 %configure --enable-dbus-type=%{dbus_type} --enable-debug
 %else
@@ -68,6 +71,8 @@ install -m 755 -d %{buildroot}%{_unitdir_user}
 install -m 644 data/gsignond.service %{buildroot}%{_unitdir_user}/
 install -m 755 -d %{buildroot}%{_unitdir_user}/weston.target.wants
 ln -sf ../gsignond.service %{buildroot}%{_unitdir_user}/weston.target.wants/gsignond.service
+install -m 755 -d %{buildroot}%{_sysconfdir}/gumd/userdel.d/
+install -m 755 gsignond-cleandb %{buildroot}%{_sysconfdir}/gumd/userdel.d/
 
 %post
 /sbin/ldconfig
@@ -91,6 +96,7 @@ getent group gsignond > /dev/null || /usr/sbin/groupadd -r gsignond
 %{_unitdir_user}/gsignond.service
 %{_unitdir_user}/weston.target.wants/gsignond.service
 %config(noreplace) %{_sysconfdir}/gsignond.conf
+%{_sysconfdir}/gumd/userdel.d/
 
 %files devel
 %defattr(-,root,root,-)