Add config validation, remove command, status filtering, and unlock method display

config check: validates UUID format, recognized methods, keyfile
consistency and existence. Reports all issues with alias context.

remove: deletes a device from config by alias. Inverse of add.

status: --mounted, --unlocked, --locked flags filter the device table.
Flags combine as OR.

mount/unlock: display which method succeeded and key slot used, e.g.
"(fido2, key slot 1)". cryptsetup Open now runs with -v and parses
"Key slot N unlocked" from stderr via io.MultiWriter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 10:22:52 -07:00
parent ce10c41466
commit e9247c720a
9 changed files with 245 additions and 27 deletions

View File

@@ -85,36 +85,43 @@ func runMount(cmd *cobra.Command, args []string) error {
return err
}
methodInfo := formatMethod(result)
if result.Privileged {
mnt, err := cryptsetup.Mount(result.Device.DevicePath, mp)
if err != nil {
return fmt.Errorf("mounting: %w", err)
}
fmt.Println(mnt)
fmt.Printf("%s %s\n", mnt, methodInfo)
return nil
}
if mp != "" {
fmt.Fprintf(os.Stderr, "warning: --mountpoint is ignored for udisks2 mounts (passphrase/keyfile path)\n")
}
return doMount(client, result.Device, "")
return doMountWithInfo(client, result.Device, "", methodInfo)
}
func doMount(client *udisks.Client, cleartext *udisks.BlockDevice, mp string) error {
return doMountWithInfo(client, cleartext, mp, "")
}
func doMountWithInfo(client *udisks.Client, cleartext *udisks.BlockDevice, mp, methodInfo string) error {
var mnt string
var err error
if mp != "" {
// udisks2 doesn't support custom mount points; use privileged mount.
mnt, err := cryptsetup.Mount(cleartext.DevicePath, mp)
if err != nil {
return fmt.Errorf("mounting: %w", err)
}
fmt.Println(mnt)
return nil
mnt, err = cryptsetup.Mount(cleartext.DevicePath, mp)
} else {
mnt, err = client.Mount(cleartext)
}
mnt, err := client.Mount(cleartext)
if err != nil {
return fmt.Errorf("mounting: %w", err)
}
fmt.Println(mnt)
if methodInfo != "" {
fmt.Printf("%s %s\n", mnt, methodInfo)
} else {
fmt.Println(mnt)
}
return nil
}