hal/tools Makefile.am, 1.17, 1.18 hal-luks-remove.in, NONE, 1.1 hal-luks-setup.in, 1.1, 1.2 hal_set_property.c, 1.9, 1.10

David Zeuthen david at freedesktop.org
Wed Jul 27 17:55:11 PDT 2005


Update of /cvs/hal/hal/tools
In directory gabe:/tmp/cvs-serv13571/tools

Modified Files:
	Makefile.am hal-luks-setup.in hal_set_property.c 
Added Files:
	hal-luks-remove.in 
Log Message:
2005-07-27  David Zeuthen  <davidz at redhat.com>

        * tools/hal-luks-remove.in: Unmount the cleartext volume, if mounted,
        before tearing down the dm-crypt mapping

        * hald/linux2/blockdev.c (hotplug_event_begin_remove_blockdev):
        Actually read the is_partition from the device since e.g.
        /sys/block/dm-0 probably is a partition

2005-07-26  W. Michael Petullo  <mike at flyn.org>

        * tools/hal_set_property.c: Add --strlist-pre, --strlist-post
        and --strlist-rem options to hal-set-property

        * tools/hal-luks-setup.in: Use --strlist-pre to add hal-luks-remove to
        a LUKS device's info.callouts.remove.

        * tools/hal-luks-remove.in: New script to tear down dm-crypt
        device.



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/tools/Makefile.am,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- Makefile.am	20 Jul 2005 23:43:19 -0000	1.17
+++ Makefile.am	28 Jul 2005 00:55:09 -0000	1.18
@@ -43,7 +43,7 @@
 endif
 ## FSTAB_SYNC_ENABLED end
 
-sbin_SCRIPTS = hal-luks-setup
+sbin_SCRIPTS = hal-luks-setup hal-luks-remove
 
 EXTRA_DIST=$(man_MANS) $(MAN_IN_FILES) gen-libgphoto-hal-fdi
 

--- NEW FILE: hal-luks-remove.in ---
#!/bin/bash

#   FILE: hal-luks-remove -- HAL method wrapper for cryptsetup remove
# AUTHOR: W. Michael Petullo <mike at flyn.org>
#   DATE: 25 July 2005
# 
# Copyright (C) 2005 W. Michael Petullo <mike at flyn.org>
# All rights reserved.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program 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 General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

CRYPTSETUP=/sbin/cryptsetup

HAL_FIND_BY_PROPERTY=@BINDIR@/hal-find-by-property
HAL_GET_PROPERTY=@BINDIR@/hal-get-property

# make sure that the cleartext volume is unmounted
CLEARTEXT_VOLUME_UDI=`$HAL_FIND_BY_PROPERTY --key volume.crypto_luks.clear.backing_volume --string $HAL_PROP_INFO_UDI`
RET=$?
if [ x$RET = x0 ]; then
  MOUNT_POINT=`$HAL_GET_PROPERTY --udi $CLEARTEXT_VOLUME_UDI --key volume.mount_point`
  if [ ! x${#MOUNT_POINT} = x0 ]; then
    /bin/umount -l $MOUNT_POINT
  fi
fi

if [ ! -f $CRYPTSETUP ]; then
	echo Error removing $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
	exit 1
fi

if [ -z $HAL_PROP_VOLUME_UUID ]; then
	echo Error determining UUID of $HAL_PROP_BLOCK_DEVICE >&2
	exit 1
fi

if ! $CRYPTSETUP remove luks_crypto_$HAL_PROP_VOLUME_UUID 2> /dev/null; then
	echo Error removing luks_crypto_$HAL_PROP_VOLUME_UUID >&2
	exit 1
fi

exit 0

Index: hal-luks-setup.in
===================================================================
RCS file: /cvs/hal/hal/tools/hal-luks-setup.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hal-luks-setup.in	20 Jul 2005 23:43:19 -0000	1.1
+++ hal-luks-setup.in	28 Jul 2005 00:55:09 -0000	1.2
@@ -23,16 +23,25 @@
 
 read password
 
-if [ ! -f @SBINDIR@/luks-setup ]; then
+LUKSSETUP=@SBINDIR@/luks-setup
+HALSETPROPERTY=@BINDIR@/hal-set-property
+
+if [ ! -f $LUKSSETUP ]; then
 	echo org.freedesktop.Hal.Device.Volume.Crypto.SetupError >&2
-	echo Error setting up $HAL_PROP_BLOCK_DEVICE - @SBINDIR@/luks-setup not found >&2
+	echo Error setting up $HAL_PROP_BLOCK_DEVICE - $LUKSSETUP not found >&2
 	exit 1
 fi
 
-if ! echo $password | @SBINDIR@/luks-setup $HAL_PROP_BLOCK_DEVICE 2> /dev/null; then
-	echo org.freedesktop.Hal.Device.Volume.Cryptoe.SetupError >&2
+if ! echo $password | $LUKSSETUP $HAL_PROP_BLOCK_DEVICE 2> /dev/null; then
+	echo org.freedesktop.Hal.Device.Volume.Crypto.SetupError >&2
 	echo Error setting up $HAL_PROP_BLOCK_DEVICE - bad password? >&2
 	exit 1
 fi
 
+if ! $HALSETPROPERTY --udi="$HAL_PROP_INFO_UDI" --key="info.callouts.remove" --strlist-pre="hal-luks-remove" 2> /dev/null; then
+	echo org.freedesktop.Hal.Device.Volume.Crypto.SetupError >&2
+	echo Error setting info.callouts.remove >&2
+	exit 1
+fi
+
 exit 0

Index: hal_set_property.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal_set_property.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- hal_set_property.c	14 Feb 2005 18:20:05 -0000	1.9
+++ hal_set_property.c	28 Jul 2005 00:55:09 -0000	1.10
@@ -38,6 +38,18 @@
 
 static LibHalContext *hal_ctx;
 
+enum property_op {
+	PROP_INT,
+	PROP_UINT64,
+	PROP_STRING,
+	PROP_DOUBLE,
+	PROP_BOOL,
+	PROP_STRLIST_PRE,
+	PROP_STRLIST_POST,
+	PROP_STRLIST_REM,
+	PROP_INVALID
+};
+
 /**
  * @defgroup HalSetProperty  Set HAL device property
  * @ingroup HalMisc
@@ -59,7 +71,9 @@
  "\n"
  "usage : hal-set-property --udi <udi> --key <key>\n"
  "           (--int <value> | --string <value> | --bool <value> |\n"
- "            --double <value> | --remove) [--help] [--version]\n");
+ "            --strlist-pre <value> | --strlist-post <value> |\n"
+ "            --strlist-rem <value> | --double <value> | --remove)\n"
+ "           [--help] [--version]\n");
 	fprintf (stderr,
  "\n" "        --udi            Unique Device Id\n"
  "        --key            Key of the property to set\n"
@@ -70,6 +84,9 @@
  "        --string         Set value to a string\n"
  "        --double         Set value to a floating point number\n"
  "        --bool           Set value to a boolean, ie. true or false\n"
+ "        --strlist-pre    Prepend a string to a list\n"
+ "        --strlist-post   Append a string to a list\n"
+ "        --strlist-rem    Remove a string from a list\n"
  "        --remove         Indicates that the property should be removed\n"
  "        --verbose        Be verbose\n"
  "        --version        Show version and exit\n"
@@ -100,7 +117,7 @@
 	dbus_bool_t bool_value = TRUE;
 	dbus_bool_t remove = FALSE;
 	dbus_bool_t is_version = FALSE;
-	int type = DBUS_TYPE_INVALID;
+	int type = PROP_INVALID;
 	DBusError error;
 
 	if (argc <= 1) {
@@ -120,6 +137,9 @@
 			{"string", 1, NULL, 0},
 			{"double", 1, NULL, 0},
 			{"bool", 1, NULL, 0},
+			{"strlist-pre", 1, NULL, 0},
+			{"strlist-post", 1, NULL, 0},
+			{"strlist-rem", 1, NULL, 0},
 			{"remove", 0, NULL, 0},
 			{"version", 0, NULL, 0},
 			{"help", 0, NULL, 0},
@@ -142,16 +162,16 @@
 				key = strdup (optarg);
 			} else if (strcmp (opt, "string") == 0) {
 				str_value = strdup (optarg);
-				type = DBUS_TYPE_STRING;
+				type = PROP_STRING;
 			} else if (strcmp (opt, "int") == 0) {
 				int_value = strtol (optarg, NULL, 0);
-				type = DBUS_TYPE_INT32;
+				type = PROP_INT;
 			} else if (strcmp (opt, "uint64") == 0) {
 				uint64_value = strtoull (optarg, NULL, 0);
-				type = DBUS_TYPE_UINT64;
+				type = PROP_UINT64;
 			} else if (strcmp (opt, "double") == 0) {
 				double_value = (double) atof (optarg);
-				type = DBUS_TYPE_DOUBLE;
+				type = PROP_DOUBLE;
 			} else if (strcmp (opt, "bool") == 0) {
 				if (strcmp (optarg, "true") == 0)
 					bool_value = TRUE;
@@ -161,7 +181,16 @@
 					usage (argc, argv);
 					return 1;
 				}
-				type = DBUS_TYPE_BOOLEAN;
+				type = PROP_BOOL;
+			} else if (strcmp (opt, "strlist-pre") == 0) {
+				str_value = strdup (optarg);
+				type = PROP_STRLIST_PRE;
+			} else if (strcmp (opt, "strlist-post") == 0) {
+				str_value = strdup (optarg);
+				type = PROP_STRLIST_POST;
+			} else if (strcmp (opt, "strlist-rem") == 0) {
+				str_value = strdup (optarg);
+				type = PROP_STRLIST_REM;
 			} else if (strcmp (opt, "remove") == 0) {
 				remove = TRUE;
 			} else if (strcmp (opt, "udi") == 0) {
@@ -184,7 +213,7 @@
 	}
 
 	/* must have at least one, but not neither or both */
-	if ((remove && type != DBUS_TYPE_INVALID) || ((!remove) && type == DBUS_TYPE_INVALID)) {
+	if ((remove && type != PROP_INVALID) || ((!remove) && type == PROP_INVALID)) {
 		usage (argc, argv);
 		return 1;
 	}
@@ -213,21 +242,30 @@
 		}
 	} else {
 		switch (type) {
-		case DBUS_TYPE_STRING:
+		case PROP_STRING:
 			rc = libhal_device_set_property_string (hal_ctx, udi, key, str_value, &error);
 			break;
-		case DBUS_TYPE_INT32:
+		case PROP_INT:
 			rc = libhal_device_set_property_int (hal_ctx, udi, key, int_value, &error);
 			break;
-		case DBUS_TYPE_UINT64:
+		case PROP_UINT64:
 			rc = libhal_device_set_property_uint64 (hal_ctx, udi, key, uint64_value, &error);
 			break;
-		case DBUS_TYPE_DOUBLE:
+		case PROP_DOUBLE:
 			rc = libhal_device_set_property_double (hal_ctx, udi, key, double_value, &error);
 			break;
-		case DBUS_TYPE_BOOLEAN:
+		case PROP_BOOL:
 			rc = libhal_device_set_property_bool (hal_ctx, udi, key, bool_value, &error);
 			break;
+		case PROP_STRLIST_PRE:
+			rc = libhal_device_property_strlist_prepend (hal_ctx, udi, key, str_value, &error);
+			break;
+		case PROP_STRLIST_POST:
+			rc = libhal_device_property_strlist_append (hal_ctx, udi, key, str_value, &error);
+			break;
+		case PROP_STRLIST_REM:
+			rc = libhal_device_property_strlist_remove (hal_ctx, udi, key, str_value, &error);
+			break;
 		}
 		if (!rc) {
 			fprintf (stderr, "error: libhal_device_set_property: %s: %s\n", error.name, error.message);




More information about the hal-commit mailing list