Skip to content

Commit 479dab6

Browse files
committed
improve cryptsetup token resolution
Signed-off-by: Zen <[email protected]>
1 parent a2f1a66 commit 479dab6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/ugrd/crypto/cryptsetup.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '2.5.8'
2+
__version__ = '2.6.0'
33

44
from zenlib.util import contains
55

@@ -248,10 +248,8 @@ def get_crypt_dev(self) -> list[str]:
248248
' source_dev=$(blkid --match-token "$source_token" --output device)',
249249
' if [ -n "$source_dev" ]; then',
250250
' echo -n "$source_dev"',
251-
' return',
252251
' fi',
253-
'fi',
254-
'rd_fail "Failed to resolve device source for cryptsetup mount: $1"']
252+
'fi']
255253

256254

257255
def open_crypt_device(self, name: str, parameters: dict) -> list[str]:
@@ -284,8 +282,14 @@ def open_crypt_device(self, name: str, parameters: dict) -> list[str]:
284282
cryptsetup_command += ' --allow-discards'
285283
self.logger.warning("Using --allow-discards can be a security risk.")
286284

285+
# Resolve the device source using get_crypt_dev, if no source is returned, run rd_fail
286+
out += [f'crypt_dev="$(get_crypt_dev {name})"',
287+
'if [ -z "$crypt_dev" ]; then',
288+
f' rd_fail "Failed to resolve device source for cryptsetup mount: {name}"',
289+
'fi']
290+
287291
# Add the variable for the source device and mapped name
288-
cryptsetup_command += f' "$(get_crypt_dev {name})" {name}'
292+
cryptsetup_command += f' "$crypt_dev" {name}'
289293

290294
# Check if the device was successfully opened
291295
out += [f' if {cryptsetup_command}; then',

0 commit comments

Comments
 (0)