anitazha / rpms / systemd

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