systemd/1048-cryptsetup-generator-refactor-add_crypttab_devices.patch
Jan Macku 1a2e4ff95c systemd-239-82.9
Resolves: RHEL-38859
2025-11-05 08:15:04 +01:00

111 lines
3.8 KiB
Diff

From d2cd65067fc614367a4efe460de5006ad3cfdb91 Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Thu, 30 May 2024 10:44:36 +0200
Subject: [PATCH] cryptsetup-generator: refactor add_crypttab_devices()
Move the processing of a crypttab entry to a separate function.
No functional changes, just refactoring.
(cherry picked from commit a07cb7d404582f9c0bfaedb9dd07f93848aa91c6)
Related: RHEL-38859
---
src/cryptsetup/cryptsetup-generator.c | 63 ++++++++++++++++-----------
1 file changed, 38 insertions(+), 25 deletions(-)
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 4117930925..50c2a5093a 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -525,10 +525,44 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
return 0;
}
+static int add_crypttab_device(const char *name, const char *device, const char *keyspec, const char *options) {
+ _cleanup_free_ char *keyfile = NULL, *keydev = NULL;
+ crypto_device *d = NULL;
+ char *uuid;
+ int r;
+
+ uuid = startswith(device, "UUID=");
+ if (!uuid)
+ uuid = path_startswith(device, "/dev/disk/by-uuid/");
+ if (!uuid)
+ uuid = startswith(name, "luks-");
+ if (uuid)
+ d = hashmap_get(arg_disks, uuid);
+
+ if (arg_whitelist && !d) {
+ log_info("Not creating device '%s' because it was not specified on the kernel command line.", name);
+ return 0;
+ }
+
+ r = split_keyspec(keyspec, &keyfile, &keydev);
+ if (r < 0)
+ return r;
+
+ r = create_disk(name, device, keyfile, keydev, (d && d->options) ? d->options : options);
+ if (r < 0)
+ return r;
+
+ if (d)
+ d->create = false;
+
+ return 0;
+}
+
static int add_crypttab_devices(void) {
struct stat st;
unsigned crypttab_line = 0;
_cleanup_fclose_ FILE *f = NULL;
+ int r;
if (!arg_read_crypttab)
return 0;
@@ -548,10 +582,9 @@ static int add_crypttab_devices(void) {
}
for (;;) {
- int r, k;
- char line[LINE_MAX], *l, *uuid;
- crypto_device *d = NULL;
- _cleanup_free_ char *name = NULL, *device = NULL, *keydev = NULL, *keyfile = NULL, *keyspec = NULL, *options = NULL;
+ char line[LINE_MAX], *l;
+ _cleanup_free_ char *name = NULL, *device = NULL, *keyspec = NULL, *options = NULL;
+ int k;
if (!fgets(line, sizeof(line), f))
break;
@@ -568,29 +601,9 @@ static int add_crypttab_devices(void) {
continue;
}
- uuid = startswith(device, "UUID=");
- if (!uuid)
- uuid = path_startswith(device, "/dev/disk/by-uuid/");
- if (!uuid)
- uuid = startswith(name, "luks-");
- if (uuid)
- d = hashmap_get(arg_disks, uuid);
-
- if (arg_whitelist && !d) {
- log_info("Not creating device '%s' because it was not specified on the kernel command line.", name);
- continue;
- }
-
- r = split_keyspec(keyspec, &keyfile, &keydev);
+ r = add_crypttab_device(name, device, keyspec, options);
if (r < 0)
return r;
-
- r = create_disk(name, device, keyfile, keydev, (d && d->options) ? d->options : options);
- if (r < 0)
- return r;
-
- if (d)
- d->create = false;
}
return 0;