Skip to contentSkip to conversation

.gitignore: cleanup (prefix paths with /, remove unnecessary)

PATCH New Amadeusz Żołnowski 1 participant 5 messages May 5, 2011 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 .gitignore: cleanup (prefix paths with /, remove unnecessary)

*~ should be globally ignored anyway. Paths were prefix with / to be strict.

---
 .gitignore |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
.gitignore +6 -7
index a689a3e..6bcb943 100644
@@ -1,8 +1,7 @@
+/dracut.8
+/dracut-catimages.8
+/dracut.conf.5
+/dracut-gencmdline.8
+/dracut.kernel.7
+/modules.d/99base/switch_root
 test*.img
-modules.d/99base/switch_root
-*~
-dracut.kernel.7
-dracut.conf.5
-dracut.8
-dracut-catimages.8
-dracut-gencmdline.8
Signature · 1 line
1.7.5.rc3

A message that is not in the archive (sent off-list or not yet received): 1304595261-11077-1-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org

#2 lore raw

PATCH 2/5 .gitignore: ignore dracut.html, dracut.conf.d/*.conf files, test.log

---
 .gitignore |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
.gitignore +3 -0
index 6bcb943..3d02102 100644
@@ -1,7 +1,10 @@
 /dracut.8
 /dracut-catimages.8
 /dracut.conf.5
+/dracut.conf.d/*.conf
 /dracut-gencmdline.8
+/dracut.html
 /dracut.kernel.7
 /modules.d/99base/switch_root
+/test/*/test.log
 test*.img
Signature · 1 line
1.7.5.rc3

A message that is not in the archive (sent off-list or not yet received): 1304595261-11077-2-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org

#4 lore raw

PATCH 3/5 crypt-lib.sh: 'command -v' preferred over 'type'

---
 modules.d/90crypt/crypt-lib.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
modules.d/90crypt/crypt-lib.sh +1 -1
index 26f9950..f423289 100644
@@ -2,7 +2,7 @@
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
 
-type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+command -v getarg >/dev/null || . /lib/dracut-lib.sh
 
 # Try to mount specified device (by path, by UUID or by label) and check
 # the path with 'test'.
Signature · 1 line
1.7.5.rc3

A message that is not in the archive (sent off-list or not yet received): 1304595261-11077-3-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org

#6 lore raw

PATCH 4/5 crypt: functions for ask-for-password and reading key

Asking for password and reading key parts are moved to separate functions in crypt-lib.sh: ask_for_password and readkey.

---
 modules.d/90crypt/crypt-lib.sh     |  102 ++++++++++++++++++++++++++++++++++++
 modules.d/90crypt/cryptroot-ask.sh |   42 ++++-----------
 2 files changed, 113 insertions(+), 31 deletions(-)
modules.d/90crypt/crypt-lib.sh +102 -0
index f423289..4bcd468 100644
@@ -4,6 +4,78 @@
 
 command -v getarg >/dev/null || . /lib/dracut-lib.sh
 
+# ask_for_password
+#
+# Wraps around plymouth ask-for-password and adds fallback to tty password ask
+# if plymouth is not present.
+#
+# --cmd command
+#   Command to execute. Required.
+# --prompt prompt
+#   Password prompt. Note that function already adds ':' at the end.
+#   Recommended.
+# --tries n
+#   How many times repeat command on its failure.  Default is 3.
+# --ply-[cmd|prompt|tries]
+#   Command/prompt/tries specific for plymouth password ask only.
+# --tty-[cmd|prompt|tries]
+#   Command/prompt/tries specific for tty password ask only.
+# --tty-echo-off
+#   Turn off input echo before tty command is executed and turn on after.
+#   It's useful when password is read from stdin.
+ask_for_password() {
+    local cmd; local prompt; local tries=3
+    local ply_cmd; local ply_prompt; local ply_tries=3
+    local tty_cmd; local tty_prompt; local tty_tries=3
+    local ret
+
+    while [ $# -gt 0 ]; do
+        case "$1" in
+            --cmd) ply_cmd="$2"; tty_cmd="$2" shift;;
+            --ply-cmd) ply_cmd="$2"; shift;;
+            --tty-cmd) tty_cmd="$2"; shift;;
+            --prompt) ply_prompt="$2"; tty_prompt="$2" shift;;
+            --ply-prompt) ply_prompt="$2"; shift;;
+            --tty-prompt) tty_prompt="$2"; shift;;
+            --tries) ply_tries="$2"; tty_tries="$2"; shift;;
+            --ply-tries) ply_tries="$2"; shift;;
+            --tty-tries) tty_tries="$2"; shift;;
+            --tty-echo-off) tty_echo_off=yes;;
+        esac
+        shift
+    done
+
+    { flock -s 9;
+        # Prompt for password with plymouth, if installed and running.
+        if [ -x /bin/plymouth ] && /bin/plymouth --has-active-vt; then
+            /bin/plymouth ask-for-password \
+                --prompt "$ply_prompt" --number-of-tries=$ply_tries \
+                --command="$ply_cmd"
+            ret=$?
+        else
+            if [ "$tty_echo_off" = yes ]; then
+                stty_orig="$(stty -g)"
+                stty -echo
+            fi
+
+            local i=1
+            while [ $i -le $tty_tries ]; do
+                [ -n "$tty_prompt" ] && \
+                    printf "$tty_prompt [$i/$tty_tries]:" >&2
+                eval "$tty_cmd" && ret=0 && break
+                ret=$?
+                i=$(($i+1))
+                [ -n "$tty_prompt" ] && printf '\n' >&2
+            done
+
+            [ "$tty_echo_off" = yes ] && stty $stty_orig
+        fi
+    } 9>/.console.lock
+
+    [ $ret -ne 0 ] && echo "Wrong password" >&2
+    return $ret
+}
+
 # Try to mount specified device (by path, by UUID or by label) and check
 # the path with 'test'.
 #
@@ -118,3 +190,33 @@ getkey() {
 
     return 1
 }
+
+# readkey keypath keydev device
+#
+# Mounts <keydev>, reads key from file <keypath>, optionally processes it (e.g.
+# if encrypted with GPG) and prints to standard output which is supposed to be
+# read by cryptsetup.  <device> is just passed to helper function for
+# informational purpose.
+readkey() {
+    local keypath="$1"
+    local keydev="$2"
+    local device="$3"
+
+    local mntp=$(mkuniqdir /mnt keydev)
+    mount -r "$keydev" "$mntp" || die 'Mounting rem. dev. failed!'
+
+    case "${keypath##*.}" in
+        gpg)
+            if [ -f /lib/dracut-crypt-gpg-lib.sh ]; then
+                . /lib/dracut-crypt-gpg-lib.sh
+                gpg_decrypt "$mntp" "$keypath" "$keydev" "$device"
+            else
+                die "No GPG support to decrypt '$keypath' on '$keydev'."
+            fi
+            ;;
+        *) cat "$mntp/$keypath" ;;
+    esac 
+
+    umount "$mntp"
+    rmdir "$mntp"
+}
modules.d/90crypt/cryptroot-ask.sh +11 -31

49 lines not on this page · raw message

Signature · 1 line
1.7.5.rc3

A message that is not in the archive (sent off-list or not yet received): 1304595261-11077-4-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org

#8 lore raw

PATCH 5/5 new module - 91crypt-gpg

It's an extension to 90crypt module. Adds support for GPG-encrypted keys (symmetrically, of course). Module is optional.

---
 modules.d/91crypt-gpg/crypt-gpg-lib.sh |   33 ++++++++++++++++++++++++++++++++
 modules.d/91crypt-gpg/module-setup.sh  |   19 ++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
 create mode 100644 modules.d/91crypt-gpg/crypt-gpg-lib.sh
 create mode 100755 modules.d/91crypt-gpg/module-setup.sh
modules.d/91crypt-gpg/crypt-gpg-lib.sh new file +33 -0
new file mode 100644
index 0000000..f934cae
@@ -0,0 +1,33 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=4 sw=4 sts=0 et filetype=sh
+
+command -v ask_for_password >/dev/null || . /lib/dracut-crypt-lib.sh
+
+# gpg_decrypt mnt_point keypath keydev device
+#
+# Decrypts encrypted symmetrically key to standard output.
+#
+# mnt_point - mount point where <keydev> is already mounted
+# keypath - GPG encrypted key path relative to <mnt_point>
+# keydev - device on which key resides; only to display in prompt
+# device - device to be opened by cryptsetup; only to display in prompt
+gpg_decrypt() {
+    local mntp="$1"
+    local keypath="$2"
+    local keydev="$3"
+    local device="$4"
+
+    local gpghome=/tmp/gnupg
+    local opts="--homedir $gpghome --no-mdc-warning --skip-verify --quiet"
+    opts="$opts --logger-file /dev/null --batch --no-tty --passphrase-fd 0"
+
+    mkdir -m 0700 -p "$gpghome"
+
+    ask_for_password \
+        --cmd "gpg $opts --decrypt $mntp/$keypath" \
+        --prompt "Password ($keypath on $keydev for $device)" \
+        --tries 3 --tty-echo-off
+
+    rm -rf -- "$gpghome"
+}
modules.d/91crypt-gpg/module-setup.sh new file +19 -0
new file mode 100755
index 0000000..3adb3a6
@@ -0,0 +1,19 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+# GPG support is optional
+check() {
+    type -P gpg >/dev/null || return 1
+
+    return 255
+}
+
+depends() {
+    echo crypt
+}
+
+install() {
+    dracut_install gpg
+    inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
+}
Signature · 1 line
1.7.5.rc3