~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to debian/initramfs/script

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2008-08-22 11:57:17 UTC
  • mfrom: (8.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080822115717-v8wfa8pxwlfvyje0
Tags: 2.13.1-4
* patches/losetup_add_option_f.dpatch: 
  - Added to support "find next free loop" in losetup.
    (closes: #495682)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
#
 
4
# Standard initramfs preamble
 
5
#
 
6
prereqs()
 
7
{
 
8
    echo ""
 
9
}
 
10
 
 
11
case $1 in
 
12
prereqs)
 
13
        prereqs
 
14
        exit 0
 
15
        ;;
 
16
esac
 
17
 
 
18
#
 
19
# Helper functions
 
20
#
 
21
cipher_modname() {
 
22
    # When changing this, don't forget to update the copy in
 
23
    # initramfs-tools-hook, as well as the list of all known cipher
 
24
    # modules in the iterate_cipher_module call near the end of
 
25
    # initramfs-tools-hook.
 
26
    case "$1" in
 
27
        NONE|XOR|AES*)
 
28
            ;;
 
29
        twofish*)
 
30
            echo loop_twofish
 
31
            ;;
 
32
        blowfish*)
 
33
            echo loop_blowfish
 
34
            ;;
 
35
        serpent*)
 
36
            echo loop_serpent
 
37
            ;;
 
38
        mars*|rc6*|tripleDES)
 
39
            echo "WARNING| (loop-aes) Don't know how to handle encryption type $1" 1>&2
 
40
            ;;
 
41
        *)
 
42
            echo "WARNING| (loop-aes) Unknown encryption type $1" 1>&2
 
43
            ;;
 
44
    esac
 
45
}
 
46
 
 
47
get_options()
 
48
{
 
49
    # Do we have any settings from the /conf/conf.d/loopaesroot file?
 
50
    [ -r /conf/conf.d/loopaesroot ] && . /conf/conf.d/loopaesroot
 
51
    loopaes_opts="${LOOPAESOPTS}"
 
52
 
 
53
    # Does the kernel boot command line override them?
 
54
    for x in $(cat /proc/cmdline); do
 
55
        case $x in
 
56
            loopaesopts=*)
 
57
                loopaes_opts=${x#loopaesopts=}
 
58
                ;;
 
59
        esac
 
60
    done
 
61
 
 
62
    # Sanity check
 
63
    if [ -z "${loopaes_opts}" ]; then
 
64
        # Apparently the root partition isn't encrypted
 
65
        exit 0
 
66
    fi
 
67
 
 
68
    # If you change this, keep the version in initramfs-tools-script
 
69
    # in sync.
 
70
    local opt module
 
71
    local IFS=", "
 
72
    for opt in $loopaes_opts; do
 
73
        case $opt in
 
74
            encryption=*)
 
75
                module="$(cipher_modname "${opt#encryption=}")"
 
76
                if [ -n "$module" ]; then
 
77
                    rootencryption="${rootencryption}${rootencryption:+:}${module}"
 
78
                fi
 
79
                losetup_opts="${losetup_opts} -e ${opt#encryption=}"
 
80
                ;;
 
81
            offset=*)
 
82
                losetup_opts="${losetup_opts} -o ${opt#offset=}"
 
83
                ;;
 
84
            sizelimit=*)
 
85
                losetup_opts="${losetup_opts} -s ${opt#sizelimit=}"
 
86
                ;;
 
87
            pseed=*)
 
88
                losetup_opts="${losetup_opts} -S ${opt#pseed=}"
 
89
                ;;
 
90
            phash=*)
 
91
                losetup_opts="${losetup_opts} -H ${opt#phash=}"
 
92
                ;;
 
93
            loinit=*)
 
94
                losetup_opts="${losetup_opts} -I ${opt#loinit=}"
 
95
                ;;
 
96
            itercountk=*)
 
97
                losetup_opts="${losetup_opts} -C ${opt#itercountk=}"
 
98
                ;;
 
99
            gpgkey=*)
 
100
                losetup_opts="${losetup_opts} -K ${opt#gpgkey=}"
 
101
                ;;
 
102
            gpghome=*)
 
103
                rootgpghome=${opt#gpghome=}
 
104
                ;;
 
105
            loop=*)
 
106
                rootloop=${opt#loop=}
 
107
                ;;
 
108
            *)
 
109
                # Presumably a non-supported or filesystem option
 
110
                ;;
 
111
        esac
 
112
    done
 
113
}
 
114
 
 
115
#
 
116
# Begin real processing
 
117
#
 
118
 
 
119
# Define crypto variables
 
120
get_options
 
121
 
 
122
# Sanity check
 
123
if [ -z "${rootloop}" ]; then
 
124
    echo "root on loop enabled, but no loop device given"
 
125
    exit 1
 
126
fi
 
127
 
 
128
if [ -z "${rootgpghome}" ]; then
 
129
    rootgpghome=/.gnupg
 
130
fi
 
131
losetup_opts="${losetup_opts} -G ${rootgpghome}"
 
132
 
 
133
modprobe -q loop
 
134
for mod in "$rootencryption"; do
 
135
    modprobe -q "$mod"
 
136
done
 
137
 
 
138
while ! [ -b "${rootloop}" ]; do
 
139
      sleep 1
 
140
done
 
141
 
 
142
# Use /sbin/losetup to make sure that we get the loopaes modified one,
 
143
# not the busybox one.
 
144
while ! /sbin/losetup ${losetup_opts} "${rootloop}" "$ROOT"; do
 
145
        sleep 1
 
146
done
 
147
 
 
148
# init can now pick up new FSTYPE, FSSIZE and ROOT
 
149
echo "ROOT=\"${rootloop}\"" >> /conf/param.conf
 
150
exit 0
 
151