diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-11-18 23:34:42 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-11-18 23:34:42 +0100 |
commit | b1a2da0a7917fed1fbbc51ef7562b4db92c715f6 (patch) | |
tree | 60a74f09e8bd547c584bcee5e283ba47437f9c30 /src | |
parent | 24a3597372849741193570d70bf0deff3ab1ef99 (diff) |
cryptsetup: show udev device name when asking for password
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptsetup.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/cryptsetup.c b/src/cryptsetup.c index ee15802365..48b2c9ce1b 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -24,6 +24,7 @@ #include <sys/mman.h> #include <libcryptsetup.h> +#include <libudev.h> #include "log.h" #include "util.h" @@ -140,11 +141,47 @@ static void log_glue(int level, const char *msg, void *usrptr) { log_debug("%s", msg); } +static char *disk_description(const char *path) { + struct udev *udev = NULL; + struct udev_device *device = NULL; + struct stat st; + char *description = NULL; + const char *model; + + assert(path); + + if (stat(path, &st) < 0) + return NULL; + + if (!S_ISBLK(st.st_mode)) + return NULL; + + if (!(udev = udev_new())) + return NULL; + + if (!(device = udev_device_new_from_devnum(udev, 'b', st.st_rdev))) + goto finish; + + if ((model = udev_device_get_property_value(device, "ID_MODEL_FROM_DATABASE")) || + (model = udev_device_get_property_value(device, "ID_MODEL"))) + description = strdup(model); + +finish: + if (device) + udev_device_unref(device); + + if (udev) + udev_unref(udev); + + return description; +} + int main(int argc, char *argv[]) { int r = EXIT_FAILURE; struct crypt_device *cd = NULL; char *password = NULL, *truncated_cipher = NULL; - const char *cipher = NULL, *cipher_mode = NULL, *hash = NULL; + const char *cipher = NULL, *cipher_mode = NULL, *hash = NULL, *name = NULL; + char *description = NULL; if (argc < 3) { log_error("This program requires at least two arguments."); @@ -185,6 +222,9 @@ int main(int argc, char *argv[]) { /* A delicious drop of snake oil */ mlockall(MCL_FUTURE); + description = disk_description(argv[3]); + name = description ? description : argv[2]; + if ((k = crypt_init(&cd, argv[3]))) { log_error("crypt_init() failed: %s", strerror(-k)); goto finish; @@ -382,5 +422,7 @@ finish: free(password); + free(description); + return r; } |