chiark / gitweb /
automount: print mount point in debug message
[elogind.git] / src / cryptsetup / cryptsetup.c
index 6d4e965fe11be56eface30edb832816962058e69..cc30e50003da8bbf95a711f736c9d75d87d1c0c9 100644 (file)
 static const char *opt_type = NULL; /* LUKS1 or PLAIN */
 static char *opt_cipher = NULL;
 static unsigned opt_key_size = 0;
+static unsigned opt_keyfile_offset = 0;
 static char *opt_hash = NULL;
 static unsigned opt_tries = 0;
 static bool opt_readonly = false;
 static bool opt_verify = false;
+static bool opt_discards = false;
 static usec_t opt_timeout = DEFAULT_TIMEOUT_USEC;
 
 /* Options Debian's crypttab knows we don't:
@@ -78,6 +80,13 @@ static int parse_one_option(const char *option) {
                         return 0;
                 }
 
+        } else if (startswith(option, "keyfile-offset=")) {
+
+                if (safe_atou(option+15, &opt_keyfile_offset) < 0) {
+                        log_error("keyfile-offset= parse failure, ignoring.");
+                        return 0;
+                }
+
         } else if (startswith(option, "hash=")) {
                 char *t;
 
@@ -98,6 +107,8 @@ static int parse_one_option(const char *option) {
                 opt_readonly = true;
         else if (streq(option, "verify"))
                 opt_verify = true;
+        else if (streq(option, "allow-discards"))
+                opt_discards = true;
         else if (streq(option, "luks"))
                 opt_type = CRYPT_LUKS1;
         else if (streq(option, "plain") ||
@@ -314,6 +325,9 @@ int main(int argc, char *argv[]) {
                 if (opt_readonly)
                         flags |= CRYPT_ACTIVATE_READONLY;
 
+                if (opt_discards)
+                        flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
+
                 if (opt_timeout > 0)
                         until = now(CLOCK_MONOTONIC) + opt_timeout;
                 else
@@ -329,7 +343,7 @@ int main(int argc, char *argv[]) {
                         l = strcspn(opt_cipher, "-");
 
                         if (!(truncated_cipher = strndup(opt_cipher, l))) {
-                                log_error("Out of memory");
+                                log_oom();
                                 goto finish;
                         }
 
@@ -351,7 +365,7 @@ int main(int argc, char *argv[]) {
                                 char **p;
 
                                 if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) {
-                                        log_error("Out of memory");
+                                        log_oom();
                                         goto finish;
                                 }
 
@@ -369,7 +383,7 @@ int main(int argc, char *argv[]) {
                                         assert(strv_length(passwords) == 1);
 
                                         if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0) {
-                                                log_error("Out of memory");
+                                                log_oom();
                                                 goto finish;
                                         }
 
@@ -402,7 +416,7 @@ int main(int argc, char *argv[]) {
 
                                         /* Pad password if necessary */
                                         if (!(c = new(char, opt_key_size))) {
-                                                log_error("Out of memory.");
+                                                log_oom();
                                                 goto finish;
                                         }
 
@@ -456,7 +470,8 @@ int main(int argc, char *argv[]) {
                                  argv[3]);
 
                         if (key_file)
-                                k = crypt_activate_by_keyfile(cd, argv[2], CRYPT_ANY_SLOT, key_file, keyfile_size, flags);
+                                k = crypt_activate_by_keyfile_offset(cd, argv[2], CRYPT_ANY_SLOT, key_file, keyfile_size,
+                                            opt_keyfile_offset, flags);
                         else {
                                 char **p;