daandemeyer / rpms / systemd

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