public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Richard Yao" <ryao@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/genkernel:ryao commit in: defaults/
Date: Mon,  5 Nov 2012 18:30:29 +0000 (UTC)	[thread overview]
Message-ID: <1351875962.3fa1bf680d90f5841d8830634ed13bbfd76271b7.ryao@gentoo> (raw)

commit:     3fa1bf680d90f5841d8830634ed13bbfd76271b7
Author:     Marek Sapota <marek <AT> sapota <DOT> org>
AuthorDate: Fri Nov  2 17:04:18 2012 +0000
Commit:     Richard Yao <ryao <AT> gentoo <DOT> org>
CommitDate: Fri Nov  2 17:06:02 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=3fa1bf68

Bug #378105: UUID/LABEL support for LUKS keydevs

LUKS keydevs now support mount by UUID/LABEL.

X-Gentoo-Bug: 378105
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=378105
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

---
 defaults/initrd.scripts |   83 ++++++++++++++++++++++++++---------------------
 1 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 53e1f97..7cb41b3 100755
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -282,6 +282,36 @@ findnfsmount() {
 	fi
 }
 
+find_real_device() {
+	local DEVICE="${1}"
+	case "${DEVICE}" in
+		UUID\=*|LABEL\=*)
+			local REAL_DEVICE=""
+			local retval=1
+
+			if [ "${retval}" -ne 0 ]; then
+				REAL_DEVICE=`findfs "${DEVICE}" 2>/dev/null`
+				retval=$?
+			fi
+
+			if [ "$retval" -ne 0 ]; then
+				REAL_DEVICE=`busybox findfs "${DEVICE}" 2>/dev/null`
+				retval=$?
+			fi
+
+			if [ "${retval}" -ne 0 ]; then
+				REAL_DEVICE=`blkid -o device -l -t "${DEVICE}"`
+				retval=$?
+			fi
+
+			if [ "${retval}" -eq 0 ] && [ -n "${REAL_DEVICE}" ]; then
+				DEVICE="${REAL_DEVICE}"
+			fi
+		;;
+	esac
+	echo -n "${DEVICE}"
+}
+
 check_loop() {
 	if [ "${LOOP}" = '' -o ! -e "${CDROOT_PATH}/${LOOP}" ]
 	then
@@ -811,32 +841,7 @@ openLUKS() {
 			prompt_user "LUKS_KEYDEV" "${LUKS_NAME} key device"
 			KEYDEV_ERROR=0
 		else
-			case "${LUKS_DEVICE}" in
-				UUID\=*|LABEL\=*)
-					local REAL_LUKS=""
-					local retval=1
-
-					if [ "${retval}" -ne 0 ]; then
-						REAL_LUKS=`findfs "${LUKS_DEVICE}" 2>/dev/null`
-						retval=$?
-					fi
-
-					if [ "$retval" -ne 0 ]; then
-						REAL_LUKS=`busybox findfs "${LUKS_DEVICE}" 2>/dev/null`
-						retval=$?
-					fi
-
-					if [ "${retval}" -ne 0 ]; then
-						REAL_LUKS=`blkid -o device -l -t "${LUKS_DEVICE}"`
-						retval=$?
-					fi
-
-					if [ "${retval}" -eq 0 ] && [ -n "${REAL_LUKS}" ]; then
-						good_msg "Detected device ${REAL_LUKS}"
-						LUKS_DEVICE="${REAL_LUKS}"
-					fi
-				;;
-			esac
+			LUKS_DEVICE=$(find_real_device "${LUKS_DEVICE}")
 
 			setup_md_device ${LUKS_DEVICE}
 			cryptsetup isLuks ${LUKS_DEVICE}
@@ -855,10 +860,12 @@ openLUKS() {
 
 				if [ -n "${LUKS_KEY}" ] 
 				then
+					local REAL_LUKS_KEYDEV="${LUKS_KEYDEV}"
 					if [ ! -e "${mntkey}${LUKS_KEY}" ] 
 					then
-						if [ -b "${LUKS_KEYDEV}" ]
-						then good_msg "Using key device ${LUKS_KEYDEV}." ${CRYPT_SILENT}
+						REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}")
+						if [ -b "${REAL_LUKS_KEYDEV}" ]
+						then good_msg "Using key device ${REAL_LUKS_KEYDEV}." ${CRYPT_SILENT}
 						else
 							good_msg "Please insert removable device ${LUKS_KEYDEV} for ${LUKS_NAME}" ${CRYPT_SILENT}
 							# abort after 10 secs
@@ -867,18 +874,20 @@ openLUKS() {
 							do 
 								count=$((count-1))
 								sleep 1
-								if [ -b "${LUKS_KEYDEV}" ]
+								REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}")
+								if [ -b "${REAL_LUKS_KEYDEV}" ]
 								then
-									good_msg "Removable device ${LUKS_KEYDEV} detected." ${CRYPT_SILENT}
+									good_msg "Removable device ${REAL_LUKS_KEYDEV} detected." ${CRYPT_SILENT}
 									break
 								fi
 							done
-							if [ ! -b "${LUKS_KEYDEV}" ]
+							if [ ! -b "${REAL_LUKS_KEYDEV}" ]
 							then
 								eval CRYPT_${TYPE}_KEY=${LUKS_KEY}
 								bootstrapKey ${TYPE}
 								eval LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"'
-								if [ ! -b "${LUKS_KEYDEV}" ]; then
+								REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}")
+								if [ ! -b "${REAL_LUKS_KEYDEV}" ]; then
 									KEYDEV_ERROR=1
 									bad_msg "Removable device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT}
 									continue
@@ -890,27 +899,27 @@ openLUKS() {
 						# At this point a device was recognized, now let's see if the key is there
 						[ ! -d "$mntkey" ] && mkdir -p ${mntkey} 2>/dev/null >/dev/null
 
-						mount -n -o ro ${LUKS_KEYDEV} ${mntkey} >/dev/null 2>/dev/null
+						mount -n -o ro ${REAL_LUKS_KEYDEV} ${mntkey} >/dev/null 2>/dev/null
 						if [ "$?" != '0' ]
 						then
 							KEYDEV_ERROR=1
-							bad_msg "Mounting of device ${LUKS_KEYDEV} failed." ${CRYPT_SILENT}
+							bad_msg "Mounting of device ${REAL_LUKS_KEYDEV} failed." ${CRYPT_SILENT}
 							continue
 						else
-							good_msg "Removable device ${LUKS_KEYDEV} mounted." ${CRYPT_SILENT}
+							good_msg "Removable device ${REAL_LUKS_KEYDEV} mounted." ${CRYPT_SILENT}
 							sleep 2
 							# keyfile exists?
 							if [ ! -e "${mntkey}${LUKS_KEY}" ]; then
 								umount -n ${mntkey} 2>/dev/null >/dev/null
 								KEY_ERROR=1
 								KEYDEV_ERROR=1
-								bad_msg "Key {LUKS_KEY} on device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT}
+								bad_msg "Key {LUKS_KEY} on device ${REAL_LUKS_KEYDEV} not found." ${CRYPT_SILENT}
 								continue
 							fi
 						fi
 					fi
 					# At this point a candidate key exists (either mounted before or not)
-					good_msg "${LUKS_KEY} on device ${LUKS_KEYDEV} found" ${CRYPT_SILENT}
+					good_msg "${LUKS_KEY} on device ${REAL_LUKS_KEYDEV} found" ${CRYPT_SILENT}
 					if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ] && [ -e /sbin/gpg ] ; then
 						[ -e /dev/tty ] && mv /dev/tty /dev/tty.org
 						mknod /dev/tty c 5 1


             reply	other threads:[~2012-11-05 18:32 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05 18:30 Richard Yao [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-11-11 17:04 [gentoo-commits] proj/genkernel:master commit in: defaults/ Richard Yao
2012-11-11 17:32 ` [gentoo-commits] proj/genkernel:ryao " Richard Yao
2012-11-22 22:20 [gentoo-commits] proj/genkernel:master " Richard Yao
2013-01-01 16:53 ` [gentoo-commits] proj/genkernel:ryao " Richard Yao
2012-11-22 22:20 Richard Yao
2013-01-01 16:53 Richard Yao
2013-06-03 23:35 Richard Yao
2013-06-03 23:35 Richard Yao
2013-06-03 23:35 Richard Yao
2013-06-03 23:35 Richard Yao
2013-06-03 23:35 Richard Yao
2013-06-03 23:35 Richard Yao
2013-06-03 23:49 Richard Yao
2013-06-06  3:36 Richard Yao
2013-06-09  6:43 Richard Yao
2013-06-09  7:45 Richard Yao
2013-06-09  8:32 Richard Yao
2013-06-09  9:44 Richard Yao
2013-06-09  9:44 Richard Yao
2013-06-09  9:46 Richard Yao
2013-06-09  9:49 Richard Yao
2013-06-09  9:49 Richard Yao
2013-06-09  9:53 Richard Yao
2013-06-09  9:58 Richard Yao
2013-06-09  9:58 Richard Yao
2013-06-09  9:58 Richard Yao
2013-06-09 10:02 Richard Yao
2013-06-09 10:05 Richard Yao
2013-06-09 10:28 Richard Yao
2013-06-09 11:43 Richard Yao
2013-06-09 11:47 Richard Yao
2013-06-09 11:51 Richard Yao
2013-06-09 11:56 Richard Yao
2013-06-09 12:11 Richard Yao
2013-06-09 12:29 Richard Yao
2013-06-09 13:15 Richard Yao
2013-06-09 13:15 Richard Yao
2013-06-09 13:17 Richard Yao
2013-06-09 13:17 Richard Yao
2013-06-09 13:17 Richard Yao
2013-06-09 13:17 Richard Yao
2013-06-09 13:21 Richard Yao
2013-06-09 13:33 Richard Yao
2013-06-09 13:33 Richard Yao
2013-06-09 13:33 Richard Yao
2013-06-09 13:33 Richard Yao
2013-06-09 13:33 Richard Yao
2013-06-09 13:33 Richard Yao
2013-06-09 13:36 Richard Yao
2013-06-09 13:36 Richard Yao
2013-06-09 13:37 Richard Yao
2013-06-09 13:37 Richard Yao
2013-06-09 13:37 Richard Yao
2013-06-09 13:40 Richard Yao
2013-06-09 13:40 Richard Yao
2013-06-09 13:40 Richard Yao
2013-06-09 13:40 Richard Yao
2013-06-09 13:40 Richard Yao
2013-06-09 13:40 Richard Yao
2013-06-09 13:48 [gentoo-commits] proj/genkernel:master " Richard Yao
2013-06-09 13:57 ` [gentoo-commits] proj/genkernel:ryao " Richard Yao
2013-06-09 13:57 [gentoo-commits] proj/genkernel:master " Richard Yao
2013-06-09 13:57 ` [gentoo-commits] proj/genkernel:ryao " Richard Yao
2013-06-09 13:57 [gentoo-commits] proj/genkernel:master " Richard Yao
2013-06-09 13:57 ` [gentoo-commits] proj/genkernel:ryao " Richard Yao
2013-06-09 13:57 Richard Yao
2013-06-09 13:57 Richard Yao
2013-06-09 13:57 Richard Yao
2013-06-09 13:57 Richard Yao
2013-06-09 13:57 Richard Yao
2013-06-09 13:57 Richard Yao
2013-10-02 12:43 Richard Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351875962.3fa1bf680d90f5841d8830634ed13bbfd76271b7.ryao@gentoo \
    --to=ryao@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox