| 1 |
#!/bin/bash -e |
| 2 |
# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: |
| 3 |
# |
| 4 |
# Copyright (c) 2017-2019 Red Hat, Inc. |
| 5 |
# Author: Javier Martinez Canillas <[email protected]> |
| 6 |
# Author: Sergio Correia <[email protected]> - LUKS2 support. |
| 7 |
# |
| 8 |
# This program is free software: you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation, either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
# |
| 21 |
|
| 22 |
. clevis-luks-common-functions |
| 23 |
|
| 24 |
SUMMARY="Lists pins bound to a LUKSv1 or LUKSv2 device" |
| 25 |
|
| 26 |
function usage() { |
| 27 |
echo >&2 |
| 28 |
echo "Usage: clevis luks list -d DEV [-s SLT] [-p]" >&2 |
| 29 |
echo >&2 |
| 30 |
echo "$SUMMARY": >&2 |
| 31 |
echo >&2 |
| 32 |
echo " -d DEV The LUKS device to list bound pins" >&2 |
| 33 |
echo >&2 |
| 34 |
echo " -s SLOT The slot number to list" >&2 |
| 35 |
echo >&2 |
| 36 |
echo " -p Print only a sorted space-separated list of used pins bound to the specified device" >&2 |
| 37 |
echo >&2 |
| 38 |
exit 1 |
| 39 |
} |
| 40 |
|
| 41 |
if [ ${#} -eq 1 ] && [ "${1}" = "--summary" ]; then |
| 42 |
echo "${SUMMARY}" |
| 43 |
exit 0 |
| 44 |
fi |
| 45 |
|
| 46 |
luks_function=clevis_luks_read_pins_from_slot |
| 47 |
while getopts ":d:s:p" o; do |
| 48 |
case "$o" in |
| 49 |
d) DEV=${OPTARG};; |
| 50 |
s) SLT=${OPTARG};; |
| 51 |
p) luks_function=clevis_luks_read_used_pins_from_slot;; |
| 52 |
*) usage;; |
| 53 |
esac |
| 54 |
done |
| 55 |
|
| 56 |
if [ -z "${DEV}" ]; then |
| 57 |
echo "Did not specify a device!" >&2 |
| 58 |
usage |
| 59 |
fi |
| 60 |
|
| 61 |
if cryptsetup isLuks --type luks1 "${DEV}"; then |
| 62 |
if ! luksmeta test -d "${DEV}" 2>/dev/null; then |
| 63 |
echo "The ${DEV} device is not valid!" >&2 |
| 64 |
exit 1 |
| 65 |
fi |
| 66 |
fi |
| 67 |
|
| 68 |
if [ -n "${SLT}" ]; then |
| 69 |
$luks_function "${DEV}" "${SLT}" |
| 70 |
else |
| 71 |
if ! used_slots=$(clevis_luks_used_slots "${DEV}"); then |
| 72 |
echo "No used slots detected for device ${DEV}!" >&2 |
| 73 |
exit 1 |
| 74 |
fi |
| 75 |
|
| 76 |
for s in ${used_slots}; do |
| 77 |
if ! $luks_function "${DEV}" "${s}"; then |
| 78 |
continue |
| 79 |
fi |
| 80 |
done |
| 81 |
fi |