]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: add helper for mangling "none" option strings
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Mar 2022 08:48:37 +0000 (10:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Mar 2022 09:24:01 +0000 (11:24 +0200)
let's unify some code here, and let's do so in cryptsetup-util.h so that
we can later reuse this in integritysetup/veritysetup

src/cryptsetup/cryptsetup.c
src/shared/cryptsetup-util.h

index 9db3f6f098be602ed02fe3a99c6e15d656846b09..137e7ee95d93f6de77f5de6b10cd1d2360be90fe 100644 (file)
@@ -1750,8 +1750,8 @@ static int run(int argc, char *argv[]) {
 
                 volume = argv[2];
                 source = argv[3];
-                key_file = argc >= 5 && !STR_IN_SET(argv[4], "", "-", "none") ? argv[4] : NULL;
-                options = argc >= 6 && !STR_IN_SET(argv[5], "", "-", "none") ? argv[5] : NULL;
+                key_file = mangle_none(argc >= 5 ? argv[4] : NULL);
+                options = mangle_none(argc >= 6 ? argv[5] : NULL);
 
                 if (!filename_is_valid(volume))
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Volume name '%s' is not valid.", volume);
index ff44af84410c4715346c9f4d84ab9497b30274a3..2a17820d63976decebd9a5de1a22d7aecbb08520 100644 (file)
@@ -86,3 +86,8 @@ static inline void sym_crypt_free(struct crypt_device* cd) {}
 static inline void sym_crypt_freep(struct crypt_device** cd) {}
 
 #endif
+
+static inline const char *mangle_none(const char *s) {
+        /* A helper that turns cryptsetup/integritysetup/veritysetup "options" strings into NULL if they are effectively empty */
+        return isempty(s) || STR_IN_SET(s, "-", "none") ? NULL : s;
+}