functions 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. if [ "${0#/usr/share/initramfs-tools/hooks/}" != "$0" ] ||
  2. [ "${0#/etc/initramfs-tools/hooks/}" != "$0" ]; then
  3. # called from an initramfs-tools hook script
  4. TABFILE="$DESTDIR/cryptroot/crypttab"
  5. elif [ "${0#/scripts/}" != "$0" ]; then
  6. # called at initramfs stage from a boot script
  7. TABFILE="/cryptroot/crypttab"
  8. else
  9. TABFILE="${TABFILE-/etc/crypttab}"
  10. fi
  11. export DM_DEFAULT_NAME_MANGLING_MODE=hex # for dmsetup(8)
  12. # Logging helpers. Send the argument list to plymouth(1), or fold it
  13. # and print it to the standard error.
  14. cryptsetup_message() {
  15. local IFS=' '
  16. if [ "${0#/scripts/}" != "$0" ] && [ -x /bin/plymouth ] && plymouth --ping; then
  17. plymouth message --text="cryptsetup: $*"
  18. elif [ ${#*} -lt 70 ]; then
  19. echo "cryptsetup: $*" >&2
  20. else
  21. # use busybox's fold(1) and sed(1) at initramfs stage
  22. echo "cryptsetup: $*" | fold -s | sed '1! s/^/ /' >&2
  23. fi
  24. return 0
  25. }
  26. # crypttab_parse_options([--export], [--quiet], [--missing-path={ignore|warn|fail}])
  27. # Parse $_CRYPTTAB_OPTIONS, a comma-separated option string from the
  28. # crypttab(5) 4th column, and sets corresponding variables
  29. # CRYPTTAB_OPTION_<option>=<value> (which are added to the environment
  30. # if --export is set). If --path-exists isn't set to "ignore" (the
  31. # default), then options taking a file name, such as header=<path>,
  32. # need to point to an existing path, otherwise a warning is printed;
  33. # and an error is raised if the value is set to "fail".
  34. # For error and warning messages, CRYPTTAB_NAME, (resp. CRYPTTAB_KEY)
  35. # should be set to the (unmangled) mapped device name (resp. key
  36. # file).
  37. # Return 1 on parsing error, 0 otherwise (incl. if unknown options
  38. # were encountered).
  39. crypttab_parse_options() {
  40. local quiet="n" export="n" missing_path="ignore"
  41. while [ $# -gt 0 ]; do
  42. case "$1" in
  43. --quiet) quiet="y";;
  44. --export) export="y";;
  45. --missing-path=*) missing_path="${1#--missing-path=}";;
  46. *) cryptsetup_message "WARNING: crypttab_parse_options(): unknown option $1"
  47. esac
  48. shift
  49. done
  50. local IFS=',' x OPTION VALUE
  51. unset -v CRYPTTAB_OPTION_cipher \
  52. CRYPTTAB_OPTION_size \
  53. CRYPTTAB_OPTION_sector_size \
  54. CRYPTTAB_OPTION_hash \
  55. CRYPTTAB_OPTION_offset \
  56. CRYPTTAB_OPTION_skip \
  57. CRYPTTAB_OPTION_verify \
  58. CRYPTTAB_OPTION_readonly \
  59. CRYPTTAB_OPTION_discard \
  60. CRYPTTAB_OPTION_plain \
  61. CRYPTTAB_OPTION_luks \
  62. CRYPTTAB_OPTION_tcrypt \
  63. CRYPTTAB_OPTION_veracrypt \
  64. CRYPTTAB_OPTION_swap \
  65. CRYPTTAB_OPTION_tmp \
  66. CRYPTTAB_OPTION_check \
  67. CRYPTTAB_OPTION_checkargs \
  68. CRYPTTAB_OPTION_tries \
  69. CRYPTTAB_OPTION_initramfs \
  70. CRYPTTAB_OPTION_noearly \
  71. CRYPTTAB_OPTION_noauto \
  72. CRYPTTAB_OPTION_loud \
  73. CRYPTTAB_OPTION_quiet \
  74. CRYPTTAB_OPTION_keyscript \
  75. CRYPTTAB_OPTION_keyslot \
  76. CRYPTTAB_OPTION_header \
  77. CRYPTTAB_OPTION_tcrypthidden
  78. # use $_CRYPTTAB_OPTIONS not $CRYPTTAB_OPTIONS as options values may
  79. # contain '\054' which is decoded to ',' in the latter
  80. for x in $_CRYPTTAB_OPTIONS; do
  81. OPTION="${x%%=*}"
  82. VALUE="${x#*=}"
  83. if [ "$x" = "$OPTION" ]; then
  84. unset -v VALUE
  85. else
  86. VALUE="$(printf '%b' "$VALUE")"
  87. fi
  88. if ! crypttab_validate_option; then
  89. if [ "$quiet" = "n" ]; then
  90. cryptsetup_message "ERROR: $CRYPTTAB_NAME: invalid value for '${x%%=*}' option, skipping"
  91. fi
  92. return 1
  93. elif [ -z "${OPTION+x}" ]; then
  94. continue
  95. fi
  96. if [ "$export" = "y" ]; then
  97. export "CRYPTTAB_OPTION_$OPTION"="${VALUE-yes}"
  98. else
  99. eval "CRYPTTAB_OPTION_$OPTION"='${VALUE-yes}'
  100. fi
  101. done
  102. IFS=" "
  103. if [ "$quiet" = "n" ] &&
  104. [ -z "${CRYPTTAB_OPTION_luks+x}" ] && [ -n "${CRYPTTAB_OPTION_header+x}" ]; then
  105. cryptsetup_message "WARNING: Option 'luks' missing in crypttab for target $CRYPTTAB_NAME." \
  106. "Headers are only supported for LUKS devices."
  107. fi
  108. if [ -z "${CRYPTTAB_OPTION_luks+x}" ] && [ -z "${CRYPTTAB_OPTION_tcrypt+x}" ]; then
  109. # the compiled-in default for these are subject to change
  110. options='cipher size'
  111. if [ -n "${CRYPTTAB_OPTION_keyscript+x}" ] || [ "$CRYPTTAB_KEY" = "none" ]; then
  112. options="$options hash" # --hash is being ignored in plain mode with keyfile specified
  113. fi
  114. for o in $options; do
  115. if [ "$quiet" = "n" ] && eval [ -z "\${CRYPTTAB_OPTION_$o+x}" ]; then
  116. cryptsetup_message "WARNING: Option '$o' missing in crypttab for plain dm-crypt" \
  117. "mapping $CRYPTTAB_NAME. Please read /usr/share/doc/cryptsetup-initramfs/README.initramfs.gz and" \
  118. "add the correct '$o' option to your crypttab(5)."
  119. fi
  120. done
  121. fi
  122. }
  123. # crypttab_validate_option()
  124. # Validate $OPTION=$VALUE (or flag $OPTION if VALUE is unset). return
  125. # 1 on error, unsets OPTION for unknown or useless options.
  126. crypttab_validate_option() {
  127. # option aliases
  128. case "$OPTION" in
  129. read-only) OPTION="readonly";;
  130. key-slot) OPTION="keyslot";;
  131. tcrypt-hidden) OPTION="tcrypthidden";;
  132. tcrypt-veracrypt) OPTION="veracrypt";;
  133. esac
  134. # sanitize the option name so CRYPTTAB_OPTION_$OPTION is a valid variable name
  135. local o="$OPTION"
  136. case "$o" in
  137. keyfile-offset) OPTION="keyfile_offset";;
  138. keyfile-size) OPTION="keyfile_size";;
  139. sector-size) OPTION="sector_size";;
  140. esac
  141. case "$o" in
  142. # value must be a non-empty string
  143. cipher|hash)
  144. [ -n "${VALUE:+x}" ] || return 1
  145. ;;
  146. # value must be a non-empty string, and an existing path if --missing-path is set
  147. header)
  148. [ -n "${VALUE:+x}" ] || return 1
  149. if [ "$missing_path" != "ignore" ]; then
  150. if [ ! -e "$VALUE" ]; then
  151. cryptsetup_message "WARNING: $CRYPTTAB_NAME: $VALUE does not exist";
  152. [ "$missing_path" = "warn" ] || return 1
  153. fi
  154. fi
  155. ;;
  156. # numeric options >0
  157. size|keyfile-size|sector-size)
  158. if ! printf '%s' "${VALUE-}" | grep -Exq "0*[1-9][0-9]*"; then
  159. return 1
  160. fi
  161. ;;
  162. # numeric options >=0
  163. offset|skip|tries|keyslot|keyfile-offset)
  164. if ! printf '%s' "${VALUE-}" | grep -Exq "[0-9]+"; then
  165. return 1
  166. fi
  167. ;;
  168. tmp)
  169. if [ -z "${VALUE+x}" ]; then
  170. VALUE="ext4" # 'tmp flag'
  171. elif [ -z "$VALUE" ]; then
  172. return 1
  173. fi
  174. ;;
  175. check)
  176. if [ -z "${VALUE+x}" ]; then
  177. if [ -n "${CRYPTDISKS_CHECK-}" ]; then
  178. VALUE="$CRYPTDISKS_CHECK"
  179. else
  180. unset -v OPTION
  181. return 0
  182. fi
  183. fi
  184. if [ -x "/lib/cryptsetup/checks/$VALUE" ] && [ -f "/lib/cryptsetup/checks/$VALUE" ]; then
  185. VALUE="/lib/cryptsetup/checks/$VALUE"
  186. elif [ ! -x "$VALUE" ] || [ ! -f "$VALUE" ]; then
  187. return 1
  188. fi
  189. ;;
  190. checkargs)
  191. [ -n "${VALUE+x}" ] || return 1 # must have a value (possibly empty)
  192. ;;
  193. keyscript)
  194. [ -n "${VALUE:+x}" ] || return 1 # must have a value
  195. if [ "${VALUE#/}" = "$VALUE" ]; then
  196. VALUE="/lib/cryptsetup/scripts/$VALUE"
  197. fi
  198. if [ ! -x "$VALUE" ] || [ ! -f "$VALUE" ]; then
  199. return 1
  200. fi
  201. ;;
  202. # and now the flags
  203. verify) ;;
  204. loud) ;;
  205. quiet) ;;
  206. initramfs) ;;
  207. noearly) ;;
  208. noauto) ;;
  209. readonly) ;;
  210. discard) ;;
  211. plain) ;;
  212. luks) ;;
  213. swap) ;;
  214. tcrypt) ;;
  215. veracrypt) ;;
  216. tcrypthidden) ;;
  217. *)
  218. if [ "${quiet:-n}" = "n" ]; then
  219. cryptsetup_message "WARNING: $CRYPTTAB_NAME: ignoring unknown option '$o'";
  220. fi
  221. unset -v OPTION
  222. ;;
  223. esac
  224. }
  225. # crypttab_resolve_source()
  226. # Resolve the CRYPTTAB_SOURCE variable, containing value of the second
  227. # field of a crypttab(5)-like file.
  228. # On error (non-existing source), CRYPTTAB_SOURCE is not changed and 1
  229. # is returned.
  230. crypttab_resolve_source() {
  231. # return immediately if source is a regular file
  232. [ ! -f "$CRYPTTAB_SOURCE" ] || return 0
  233. # otherwise resolve the block device specification
  234. local dev="$CRYPTTAB_SOURCE"
  235. dev="$(resolve_device_spec "$dev")" && CRYPTTAB_SOURCE="$dev" || return 1
  236. }
  237. # run_keyscript($keyscriptarg, $tried_count)
  238. # exec()'ute `$CRYPTTAB_OPTION_keyscript $keyscriptarg`.
  239. # If $CRYPTTAB_OPTION_keyscript is unset or null and $keyscriptarg is
  240. # "none" (meaning the passphrase is to be read interactively from the
  241. # console), use `/lib/cryptsetup/askpass` as keyscript with a suitable
  242. # prompt message.
  243. # Since the shell process is replaced with the $CRYPTTAB_OPTION_keyscript
  244. # program, run_keyscript() must be used on the left-hand side of a
  245. # pipe, or similar.
  246. run_keyscript() {
  247. local keyscriptarg="$1" CRYPTTAB_TRIED="$2" keyscript;
  248. export CRYPTTAB_NAME CRYPTTAB_SOURCE CRYPTTAB_OPTIONS
  249. export CRYPTTAB_TRIED
  250. if [ -n "${CRYPTTAB_OPTION_keyscript+x}" ] && \
  251. [ "$CRYPTTAB_OPTION_keyscript" != "/lib/cryptsetup/askpass" ]; then
  252. # 'keyscript' option is present: export its argument as
  253. # $CRYPTTAB_KEY
  254. export CRYPTTAB_KEY="$keyscriptarg"
  255. keyscript="$CRYPTTAB_OPTION_keyscript"
  256. elif [ "$keyscriptarg" = none ]; then
  257. # don't export the prompt message as CRYPTTAB_KEY
  258. keyscript="/lib/cryptsetup/askpass"
  259. keyscriptarg="Please unlock disk $CRYPTTAB_NAME: "
  260. fi
  261. exec "$keyscript" "$keyscriptarg"
  262. }
  263. # get_crypt_type()
  264. # Set CRYPTTAB_TYPE to the mapping type, depending on its
  265. # $CRYPTTAB_OPTION_<option> values
  266. get_crypt_type() {
  267. if [ "${CRYPTTAB_OPTION_tcrypt-}" = "yes" ]; then
  268. CRYPTTAB_TYPE="tcrypt"
  269. elif [ "${CRYPTTAB_OPTION_plain-}" = "yes" ]; then
  270. CRYPTTAB_TYPE="plain"
  271. elif [ "${CRYPTTAB_OPTION_luks-}" = "yes" ] ||
  272. /sbin/cryptsetup isLuks -- "${CRYPTTAB_OPTION_header-$CRYPTTAB_SOURCE}"; then
  273. CRYPTTAB_TYPE="luks"
  274. else
  275. # assume plain dm-crypt device by default
  276. CRYPTTAB_TYPE="plain"
  277. fi
  278. }
  279. # unlock_mapping([$keyfile])
  280. # Run cryptsetup(8) with suitable options and arguments to unlock
  281. # $CRYPTTAB_SOURCE and setup dm-crypt managed device-mapper mapping
  282. # $CRYPTTAB_NAME.
  283. unlock_mapping() {
  284. local keyfile="${1:--}"
  285. if [ "$CRYPTTAB_TYPE" = "luks" ] || [ "$CRYPTTAB_TYPE" = "tcrypt" ]; then
  286. # ignored for LUKS and TCRYPT devices
  287. unset -v CRYPTTAB_OPTION_cipher \
  288. CRYPTTAB_OPTION_size \
  289. CRYPTTAB_OPTION_hash \
  290. CRYPTTAB_OPTION_offset \
  291. CRYPTTAB_OPTION_skip
  292. fi
  293. if [ "$CRYPTTAB_TYPE" = "plain" ] || [ "$CRYPTTAB_TYPE" = "tcrypt" ]; then
  294. unset -v CRYPTTAB_OPTION_keyfile_size
  295. fi
  296. if [ "$CRYPTTAB_TYPE" = "tcrypt" ]; then
  297. # ignored for TCRYPT devices
  298. unset -v CRYPTTAB_OPTION_keyfile_offset
  299. else
  300. # ignored for non-TCRYPT devices
  301. unset -v CRYPTTAB_OPTION_veracrypt CRYPTTAB_OPTION_tcrypthidden
  302. fi
  303. if [ "$CRYPTTAB_TYPE" != "luks" ]; then
  304. # ignored for non-LUKS devices
  305. unset -v CRYPTTAB_OPTION_keyslot
  306. fi
  307. /sbin/cryptsetup -T1 \
  308. ${CRYPTTAB_OPTION_header:+--header="$CRYPTTAB_OPTION_header"} \
  309. ${CRYPTTAB_OPTION_cipher:+--cipher="$CRYPTTAB_OPTION_cipher"} \
  310. ${CRYPTTAB_OPTION_size:+--key-size="$CRYPTTAB_OPTION_size"} \
  311. ${CRYPTTAB_OPTION_sector_size:+--sector-size="$CRYPTTAB_OPTION_sector_size"} \
  312. ${CRYPTTAB_OPTION_hash:+--hash="$CRYPTTAB_OPTION_hash"} \
  313. ${CRYPTTAB_OPTION_offset:+--offset="$CRYPTTAB_OPTION_offset"} \
  314. ${CRYPTTAB_OPTION_skip:+--skip="$CRYPTTAB_OPTION_skip"} \
  315. ${CRYPTTAB_OPTION_verify:+--verify-passphrase} \
  316. ${CRYPTTAB_OPTION_readonly:+--readonly} \
  317. ${CRYPTTAB_OPTION_discard:+--allow-discards} \
  318. ${CRYPTTAB_OPTION_veracrypt:+--veracrypt} \
  319. ${CRYPTTAB_OPTION_keyslot:+--key-slot="$CRYPTTAB_OPTION_keyslot"} \
  320. ${CRYPTTAB_OPTION_tcrypthidden:+--tcrypt-hidden} \
  321. ${CRYPTTAB_OPTION_keyfile_size:+--keyfile-size="$CRYPTTAB_OPTION_keyfile_size"} \
  322. ${CRYPTTAB_OPTION_keyfile_offset:+--keyfile-offset="$CRYPTTAB_OPTION_keyfile_offset"} \
  323. --type="$CRYPTTAB_TYPE" --key-file="$keyfile" \
  324. open -- "$CRYPTTAB_SOURCE" "$CRYPTTAB_NAME"
  325. }
  326. # crypttab_key_check()
  327. # Sanity checks for keyfile $CRYPTTAB_KEY. CRYPTTAB_NAME and
  328. # CRYPTTAB_OPTION_<option> must be set appropriately.
  329. crypttab_key_check() {
  330. if [ ! -f "$CRYPTTAB_KEY" ] && [ ! -b "$CRYPTTAB_KEY" ] && [ ! -c "$CRYPTTAB_KEY" ] ; then
  331. cryptsetup_message "WARNING: $CRYPTTAB_NAME: keyfile '$CRYPTTAB_KEY' not found"
  332. return 0
  333. fi
  334. if [ "$CRYPTTAB_KEY" = "/dev/random" ] || [ "$CRYPTTAB_KEY" = "/dev/urandom" ]; then
  335. if [ -n "${CRYPTTAB_OPTION_luks+x}" ] || [ -n "${CRYPTTAB_OPTION_tcrypt+x}" ]; then
  336. cryptsetup_message "WARNING: $CRYPTTAB_NAME: has random data as key"
  337. return 1
  338. else
  339. return 0
  340. fi
  341. fi
  342. local mode="$(stat -L -c"%04a" -- "$CRYPTTAB_KEY")"
  343. if [ $(stat -L -c"%u" -- "$CRYPTTAB_KEY") -ne 0 ] || [ "${mode%00}" = "$mode" ]; then
  344. cryptsetup_message "WARNING: $CRYPTTAB_NAME: key file $CRYPTTAB_KEY has" \
  345. "insecure ownership, see /usr/share/doc/cryptsetup/README.Debian.gz."
  346. fi
  347. }
  348. # resolve_device_spec($spec)
  349. # Resolve LABEL=<label>, UUID=<uuid>, PARTUUID=<partuuid> and
  350. # PARTLABEL=<partlabel> to a block special device. If $spec is
  351. # already a (link to a block special device) then it is echoed as is.
  352. # Return 1 if $spec doesn't correspond to a block special device.
  353. resolve_device_spec() {
  354. local spec="$1"
  355. case "$spec" in
  356. UUID=*|LABEL=*|PARTUUID=*|PARTLABEL=*)
  357. # don't use /dev/disk/by-label/... to avoid gessing udev mangling
  358. spec="$(blkid -l -t "$spec" -o device)" || spec=
  359. ;;
  360. esac
  361. [ -b "$spec" ] && printf '%s\n' "$spec" || return 1
  362. }
  363. # dm_blkdevname($name)
  364. # Print the mapped device name, or return 1 if the the device doesn't exist.
  365. dm_blkdevname() {
  366. local name="$1" dev
  367. # /dev/mapper/$name isn't reliable due to udev mangling
  368. if dev="$(dmsetup info -c --noheadings -o blkdevname -- "$name" 2>/dev/null)" &&
  369. [ -n "$dev" ] && [ -b "/dev/$dev" ]; then
  370. echo "/dev/$dev"
  371. return 0
  372. else
  373. return 1
  374. fi
  375. }
  376. # crypttab_find_entry([--quiet], $target)
  377. # Search in the crypttab(5) for the given $target, and sets the
  378. # variables CRYPTTAB_NAME, CRYPTTAB_SOURCE, CRYPTTAB_KEY and
  379. # CRYPTTAB_OPTIONS accordingly. (In addition _CRYPTTAB_NAME,
  380. # _CRYPTTAB_SOURCE, _CRYPTTAB_KEY and _CRYPTTAB_OPTIONS are set to the
  381. # unmangled values before decoding the escape sequence.) If there are
  382. # duplicates then only the first match is considered.
  383. # Return 0 if a match is found, and 1 otherwise.
  384. crypttab_find_entry() {
  385. local target="$1" quiet="n" IFS
  386. if [ "$target" = "--quiet" ] && [ $# -eq 2 ]; then
  387. quiet="y"
  388. target="$2"
  389. fi
  390. if [ -f "$TABFILE" ]; then
  391. while IFS=" " read -r _CRYPTTAB_NAME _CRYPTTAB_SOURCE _CRYPTTAB_KEY _CRYPTTAB_OPTIONS; do
  392. if [ "${_CRYPTTAB_NAME#\#}" != "$_CRYPTTAB_NAME" ] || [ -z "$_CRYPTTAB_NAME" ]; then
  393. # ignore comments and empty lines
  394. continue
  395. fi
  396. # unmangle names
  397. CRYPTTAB_NAME="$(printf '%b' "$_CRYPTTAB_NAME")"
  398. if [ -z "$_CRYPTTAB_SOURCE" ] || [ -z "$_CRYPTTAB_KEY" ] || [ -z "$_CRYPTTAB_OPTIONS" ]; then
  399. cryptsetup_message "WARNING: '$CRYPTTAB_NAME' is missing some arguments, see crypttab(5)"
  400. continue
  401. elif [ "$CRYPTTAB_NAME" = "$target" ]; then
  402. CRYPTTAB_SOURCE="$( printf '%b' "$_CRYPTTAB_SOURCE" )"
  403. CRYPTTAB_KEY="$( printf '%b' "$_CRYPTTAB_KEY" )"
  404. CRYPTTAB_OPTIONS="$(printf '%b' "$_CRYPTTAB_OPTIONS")"
  405. return 0
  406. fi
  407. done <"$TABFILE"
  408. fi
  409. if [ "$quiet" = "n" ]; then
  410. cryptsetup_message "WARNING: target '$target' not found in $TABFILE"
  411. fi
  412. return 1
  413. }
  414. # crypttab_foreach_entry($callback)
  415. # Iterate through the crypttab(5) and run the given $callback for each
  416. # entry found. Variables CRYPTTAB_NAME, CRYPTTAB_SOURCE, CRYPTTAB_KEY
  417. # and CRYPTTAB_OPTIONS are set accordingly and available to the
  418. # $callback. (In addition _CRYPTTAB_NAME, _CRYPTTAB_SOURCE,
  419. # _CRYPTTAB_KEY and _CRYPTTAB_OPTIONS are set to the unmangled values
  420. # before decoding the escape sequence.)
  421. # Return 0 if a match is found, and 1 otherwise.
  422. crypttab_foreach_entry() {
  423. local callback="$1" IFS
  424. local _CRYPTTAB_NAME _CRYPTTAB_SOURCE _CRYPTTAB_KEY _CRYPTTAB_OPTIONS \
  425. CRYPTTAB_NAME CRYPTTAB_SOURCE CRYPTTAB_KEY CRYPTTAB_OPTIONS
  426. [ -f "$TABFILE" ] || return
  427. while IFS=" " read -r _CRYPTTAB_NAME _CRYPTTAB_SOURCE _CRYPTTAB_KEY _CRYPTTAB_OPTIONS <&9; do
  428. if [ "${_CRYPTTAB_NAME#\#}" != "$_CRYPTTAB_NAME" ] || [ -z "$_CRYPTTAB_NAME" ]; then
  429. # ignore comments and empty lines
  430. continue
  431. fi
  432. # unmangle names
  433. CRYPTTAB_NAME="$( printf '%b' "$_CRYPTTAB_NAME" )"
  434. CRYPTTAB_SOURCE="$( printf '%b' "$_CRYPTTAB_SOURCE" )"
  435. CRYPTTAB_KEY="$( printf '%b' "$_CRYPTTAB_KEY" )"
  436. CRYPTTAB_OPTIONS="$(printf '%b' "$_CRYPTTAB_OPTIONS")"
  437. if [ -z "$CRYPTTAB_SOURCE" ] || [ -z "$CRYPTTAB_KEY" ] || [ -z "$CRYPTTAB_OPTIONS" ]; then
  438. cryptsetup_message "WARNING: '$CRYPTTAB_NAME' is missing some arguments, see crypttab(5)"
  439. continue
  440. fi
  441. "$callback" 9<&-
  442. done 9<"$TABFILE"
  443. }
  444. # vim: set filetype=sh :