/mandos/trunk

To get this branch, use:
bzr branch http://term.recompile.se/loggerhead/mandos/trunk
1127 by Teddy Hogeborn
Add dracut(8) support
1
#!/bin/sh
2
#
3
# This file should be present in the root file system directory
4
# /usr/lib/dracut/modules.d/90mandos.  When dracut creates the
5
# initramfs image, dracut will run the "module-setup.sh" file in the
6
# same directory, which (when *not* using the "systemd" dracut module)
7
# will copy this file ("cmdline-mandos.sh") into the initramfs as
8
# "/lib/dracut/hooks/cmdline/20-cmdline-mandos.sh".
9
# 
10
# Despite the above #!/bin/sh line and the executable flag, this file
11
# is not executed; this file is sourced by the /init script in the
12
# initramfs image created by dracut.
13
14
if getargbool 1 mandos && [ -e /lib/dracut-crypt-lib.sh ]; then
1326 by Teddy Hogeborn
Fix kernel command line option "mandos=connect:<ip>:<port>" with dracut
15
    if mandos=$(getarg mandos); then
16
	case "$mandos" in
17
	    connect:*) mandos_connect="${mandos#connect:}" ;;
18
	esac
19
	if [ -n "$mandos_connect" ]; then
20
	    printf -- '\n--options-for=mandos-client:--connect=%s\n' "$mandos_connect" >> /etc/mandos/plugin-runner.conf
21
	fi
22
    fi
23
1127 by Teddy Hogeborn
Add dracut(8) support
24
    cat >> /lib/dracut-crypt-lib.sh <<- "EOF"
25
	ask_for_password(){
26
	    local cmd; local prompt; local tries=3
27
	    local ply_cmd; local ply_prompt; local ply_tries=3
28
	    local tty_cmd; local tty_prompt; local tty_tries=3
29
	    local ret
30
	
31
	    while [ $# -gt 0 ]; do
32
		case "$1" in
33
		    --cmd) ply_cmd="$2"; tty_cmd="$2"; shift;;
34
		    --ply-cmd) ply_cmd="$2"; shift;;
35
		    --tty-cmd) tty_cmd="$2"; shift;;
36
		    --prompt) ply_prompt="$2"; tty_prompt="$2"; shift;;
37
		    --ply-prompt) ply_prompt="$2"; shift;;
38
		    --tty-prompt) tty_prompt="$2"; shift;;
39
		    --tries) ply_tries="$2"; tty_tries="$2"; shift;;
40
		    --ply-tries) ply_tries="$2"; shift;;
41
		    --tty-tries) tty_tries="$2"; shift;;
42
		    --tty-echo-off) tty_echo_off=yes;;
43
		    -*) :;;
44
		esac
45
		shift
46
	    done
47
	    if [ -z "$ply_cmd" ]; then
48
		ply_cmd="$tty_cmd"
49
	    fi
50
	    # Extract device and luksname from $ply_cmd
51
	    set -- $ply_cmd
52
	    shift
53
	    for arg in "$@"; do
54
		case "$arg" in
55
		    -*) :;;
56
		    *)
57
			if [ -z "$device" ]; then
58
			    device="$arg"
59
			else
60
			    luksname="$arg"
61
			    break
62
			fi
63
			;;
64
		esac
65
	    done
66
	    { flock -s 9;
67
	      if [ -z "$ply_prompt" ]; then
68
		  if [ -z "$tty_prompt" ]; then
69
		      CRYPTTAB_SOURCE="$device" cryptsource="$device" CRYPTTAB_NAME="$luksname" crypttarget="$luksname" /lib/mandos/plugin-runner --config-file=/etc/mandos/plugin-runner.conf | $ply_cmd
70
		  else
71
		      CRYPTTAB_SOURCE="$device" cryptsource="$device" CRYPTTAB_NAME="$luksname" crypttarget="$luksname" /lib/mandos/plugin-runner --options-for=password-prompt:--prompt="${tty_prompt}" --config-file=/etc/mandos/plugin-runner.conf | $ply_cmd
72
		  fi
73
	      else
74
		  if [ -z "$tty_prompt" ]; then
75
		      CRYPTTAB_SOURCE="$device" cryptsource="$device" CRYPTTAB_NAME="$luksname" crypttarget="$luksname" /lib/mandos/plugin-runner --options-for=plymouth:--prompt="${ply_prompt}" --config-file=/etc/mandos/plugin-runner.conf | $ply_cmd
76
		  else
77
		      CRYPTTAB_SOURCE="$device" cryptsource="$device" CRYPTTAB_NAME="$luksname" crypttarget="$luksname" /lib/mandos/plugin-runner --options-for=password-prompt:--prompt="${tty_prompt}" --options-for=plymouth:--prompt="${ply_prompt}" --config-file=/etc/mandos/plugin-runner.conf | $ply_cmd
78
		  fi
79
	      fi
80
	    } 9>/.console_lock
81
	}
82
	EOF
83
fi