tags 502598 patch
thanks

Hi again,

I hacked a timeout option, patch is attached.
passdev now accepts either dev:path or dev:path:timeout as argument and
will quit when the timeout is reached. Additionally one should set
tries=1 in the crypttab, as it does not make sense to try a keyfile 3
times.

Regards
Evgeni

diff -u cryptsetup-1.0.6/debian/passdev.c cryptsetup-1.0.6/debian/passdev.c
--- cryptsetup-1.0.6/debian/passdev.c
+++ cryptsetup-1.0.6/debian/passdev.c
@@ -118,6 +118,9 @@
 	size_t towrite;
 	size_t byteswritten;
 	ssize_t bytes;
+	char *to;
+	int timeout;
+	bool do_timeout = false;
 
 	/* We only take one argument */
 	if (argc != 2) {
@@ -130,7 +133,7 @@
 	if (debugval && atoi(debugval) > 0)
 		do_debug = true;
 
-	/* Split string into device and path */
+	/* Split string into device and path (and timeout) */
 	devpath = argv[1];
 	filepath = strchr(devpath, ':');
 	if (!filepath || !(*filepath) || !(*(filepath + 1))) {
@@ -139,13 +142,29 @@
 	}
 	*filepath = '\0';
 	filepath++;
+	to = strchr(filepath, ':');
+	if (to && (*to) && (*(to + 1))) {
+		*to = '\0';
+		to++;
+		timeout = atoi(to);
+		if (timeout > 0)
+			do_timeout = true;
+	}
 	debug("Path is %p and filepath is %p\n", devpath, filepath);
+	if (do_timeout)
+		debug("Timeout is %i\n",timeout);
 
 	/* Wait until device is available */
 	if (access(devpath, F_OK)) {
 		debug("Waiting for %s\n", devpath);
-		while(access(devpath, F_OK))
+		while(access(devpath, F_OK)) {
 			sleep(1);
+			if (do_timeout) {
+				if (timeout <= 0)
+					break;
+				timeout--;
+			}
+		}
 	}
 
 	/* Make sure device is a blockdev */
diff -u cryptsetup-1.0.6/debian/README.initramfs cryptsetup-1.0.6/debian/README.initramfs
--- cryptsetup-1.0.6/debian/README.initramfs
+++ cryptsetup-1.0.6/debian/README.initramfs
@@ -184,8 +184,8 @@
 passdev keyscript. It will wait for the device to appear, mount it read-only,
 read the key and then unmount the device.
 
-The "key" part of /etc/crypttab will be interpreted as <device>:<path>, it is
-strongly recommended that you use one of the persistent device names from
+The "key" part of /etc/crypttab will be interpreted as <device>:<path>[:<timeout>],
+it is strongly recommended that you use one of the persistent device names from
 /dev/disk/*, e.g. /dev/disk/by-label/myusbkey.
 
 This is an example of a suitable line in cryptsetup:
@@ -197,2 +197,4 @@
 
+The timeout option has to be in seconds.
+
 -- David Härdeman <[EMAIL PROTECTED]>
diff -u cryptsetup-1.0.6/debian/changelog cryptsetup-1.0.6/debian/changelog
--- cryptsetup-1.0.6/debian/changelog
+++ cryptsetup-1.0.6/debian/changelog
@@ -1,3 +1,10 @@
+cryptsetup (2:1.0.6-6.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Make passdev accept a timeout option. (Closes: #502598)
+
+ -- Evgeni Golov <[EMAIL PROTECTED]>  Sat, 18 Oct 2008 10:55:10 +0200
+
 cryptsetup (2:1.0.6-6) unstable; urgency=high
 
   * Don't cat keyfile into pipe for do_noluks(). cryptsetup handles

Attachment: pgpHJ0RmhMfgz.pgp
Description: PGP signature

Reply via email to