daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
ecbff1
From 1e02c945fbf54f2b9179ab84794a05cffb3efd98 Mon Sep 17 00:00:00 2001
ecbff1
From: Michal Sekletar <msekleta@redhat.com>
ecbff1
Date: Tue, 12 Dec 2017 20:00:31 +0100
ecbff1
Subject: [PATCH] cryptsetup: use more descriptive name for the variable and
ecbff1
 drop redundant function
ecbff1
ecbff1
Let's rename escaped_name to disk_path since this is an actual content
ecbff1
that pointer refers to. It is either path to encrypted block device
ecbff1
or path to encrypted image file.
ecbff1
ecbff1
Also drop redundant function disk_major_minor(). src is always set, and
ecbff1
it always points to either encrypted block device path (or symlink to
ecbff1
such device) or to encrypted image. In case it is set to device path
ecbff1
there is no need to reset it to /dev/block/major:minor symlink since
ecbff1
those paths are equivalent.
ecbff1
ecbff1
(cherry-picked from commit ea7e7c1e9c3b579ee94a11a192f1013ee4cb829e)
ecbff1
ecbff1
Related: #1511043
ecbff1
---
de8967
 src/cryptsetup/cryptsetup.c | 41 ++++++++-----------------------------
ecbff1
 1 file changed, 8 insertions(+), 33 deletions(-)
ecbff1
ecbff1
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
ecbff1
index c57d2b294..69a015614 100644
ecbff1
--- a/src/cryptsetup/cryptsetup.c
ecbff1
+++ b/src/cryptsetup/cryptsetup.c
ecbff1
@@ -217,23 +217,6 @@ static void log_glue(int level, const char *msg, void *usrptr) {
ecbff1
         log_debug("%s", msg);
ecbff1
 }
ecbff1
 
ecbff1
-static int disk_major_minor(const char *path, char **ret) {
ecbff1
-        struct stat st;
ecbff1
-
ecbff1
-        assert(path);
ecbff1
-
ecbff1
-        if (stat(path, &st) < 0)
ecbff1
-                return -errno;
ecbff1
-
ecbff1
-        if (!S_ISBLK(st.st_mode))
ecbff1
-                return -EINVAL;
ecbff1
-
ecbff1
-        if (asprintf(ret, "/dev/block/%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0)
ecbff1
-                return -errno;
ecbff1
-
ecbff1
-        return 0;
ecbff1
-}
ecbff1
-
ecbff1
 static char* disk_description(const char *path) {
ecbff1
 
ecbff1
         static const char name_fields[] =
ecbff1
@@ -299,11 +282,11 @@ static int get_password(const char *vol, const char *src, usec_t until, bool acc
ecbff1
         int r = 0;
ecbff1
         char **p;
ecbff1
         _cleanup_free_ char *text = NULL;
ecbff1
-        _cleanup_free_ char *escaped_name = NULL;
ecbff1
+        _cleanup_free_ char *disk_path = NULL;
ecbff1
         char *id;
ecbff1
         const char *name = NULL;
ecbff1
         _cleanup_free_ char *description = NULL, *name_buffer = NULL,
ecbff1
-                *mount_point = NULL, *maj_min = NULL;
ecbff1
+                *mount_point = NULL;
ecbff1
 
ecbff1
         assert(vol);
ecbff1
         assert(src);
ecbff1
@@ -312,6 +295,10 @@ static int get_password(const char *vol, const char *src, usec_t until, bool acc
ecbff1
         description = disk_description(src);
ecbff1
         mount_point = disk_mount_point(vol);
ecbff1
 
ecbff1
+        disk_path = cescape(src);
ecbff1
+        if (!disk_path)
ecbff1
+                return log_oom();
ecbff1
+
ecbff1
         if (description && streq(vol, description)) {
ecbff1
                 /* If the description string is simply the
ecbff1
                  * volume name, then let's not show this
ecbff1
@@ -335,19 +322,7 @@ static int get_password(const char *vol, const char *src, usec_t until, bool acc
ecbff1
         if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0)
ecbff1
                 return log_oom();
ecbff1
 
ecbff1
-        if (src)
ecbff1
-                (void) disk_major_minor(src, &maj_min);
ecbff1
-
ecbff1
-        if (maj_min) {
ecbff1
-                escaped_name = maj_min;
ecbff1
-                maj_min = NULL;
ecbff1
-        } else
ecbff1
-                escaped_name = cescape(src);
ecbff1
-
ecbff1
-        if (!escaped_name)
ecbff1
-                return log_oom();
ecbff1
-
ecbff1
-        id = strjoina("cryptsetup:", escaped_name);
ecbff1
+        id = strjoina("cryptsetup:", disk_path);
ecbff1
 
ecbff1
         r = ask_password_auto(text, "drive-harddisk", id, until, accept_cached, passwords);
ecbff1
         if (r < 0)
ecbff1
@@ -361,7 +336,7 @@ static int get_password(const char *vol, const char *src, usec_t until, bool acc
ecbff1
                 if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0)
ecbff1
                         return log_oom();
ecbff1
 
ecbff1
-                id = strjoina("cryptsetup-verification:", escaped_name);
ecbff1
+                id = strjoina("cryptsetup-verification:", disk_path);
ecbff1
 
ecbff1
                 r = ask_password_auto(text, "drive-harddisk", id, until, false, &passwords2);
ecbff1
                 if (r < 0)