neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0021-Correctly-handle-non-unicode-iSCSI-initiator-names.patch

0b05ab
From 5f7dbb212b4d6da4f8f2609ae1415e8630d031cd Mon Sep 17 00:00:00 2001
0b05ab
From: Vojtech Trefny <vtrefny@redhat.com>
0b05ab
Date: Mon, 13 May 2019 12:49:52 +0200
0b05ab
Subject: [PATCH] Correctly handle non-unicode iSCSI initiator names
0b05ab
0b05ab
---
0b05ab
 blivet/iscsi.py |  4 +++-
0b05ab
 blivet/udev.py  | 20 +++++++++++---------
0b05ab
 2 files changed, 14 insertions(+), 10 deletions(-)
0b05ab
0b05ab
diff --git a/blivet/iscsi.py b/blivet/iscsi.py
0b05ab
index 74432505..f612cf15 100644
0b05ab
--- a/blivet/iscsi.py
0b05ab
+++ b/blivet/iscsi.py
0b05ab
@@ -206,7 +206,9 @@ def initiator(self):
0b05ab
         if self._initiator != "":
0b05ab
             return self._initiator
0b05ab
 
0b05ab
-        return self._call_initiator_method("GetInitiatorName")[0]
0b05ab
+        # udisks returns initiatorname as a NULL terminated bytearray
0b05ab
+        raw_initiator = bytes(self._call_initiator_method("GetInitiatorNameRaw")[0][:-1])
0b05ab
+        return raw_initiator.decode("utf-8", errors="replace")
0b05ab
 
0b05ab
     @initiator.setter
0b05ab
     @storaged_iscsi_required(critical=True, eval_mode=util.EvalMode.onetime)
0b05ab
diff --git a/blivet/udev.py b/blivet/udev.py
0b05ab
index 51b69b76..a70e3e08 100644
0b05ab
--- a/blivet/udev.py
0b05ab
+++ b/blivet/udev.py
0b05ab
@@ -836,24 +836,26 @@ def device_get_iscsi_nic(info):
0b05ab
 
0b05ab
 
0b05ab
 def device_get_iscsi_initiator(info):
0b05ab
-    initiator = None
0b05ab
+    initiator_name = None
0b05ab
     if device_is_partoff_iscsi(info):
0b05ab
         host = re.match(r'.*/(host\d+)', device_get_sysfs_path(info)).groups()[0]
0b05ab
         if host:
0b05ab
             initiator_file = "/sys/class/iscsi_host/%s/initiatorname" % host
0b05ab
             if os.access(initiator_file, os.R_OK):
0b05ab
-                initiator = open(initiator_file).read().strip()
0b05ab
+                initiator = open(initiator_file, "rb").read().strip()
0b05ab
+                initiator_name = initiator.decode("utf-8", errors="replace")
0b05ab
                 log.debug("found offload iscsi initiatorname %s in file %s",
0b05ab
-                          initiator, initiator_file)
0b05ab
-                if initiator.lstrip("(").rstrip(")").lower() == "null":
0b05ab
-                    initiator = None
0b05ab
-    if initiator is None:
0b05ab
+                          initiator_name, initiator_file)
0b05ab
+                if initiator_name.lstrip("(").rstrip(")").lower() == "null":
0b05ab
+                    initiator_name = None
0b05ab
+    if initiator_name is None:
0b05ab
         session = device_get_iscsi_session(info)
0b05ab
         if session:
0b05ab
             initiator = open("/sys/class/iscsi_session/%s/initiatorname" %
0b05ab
-                             session).read().strip()
0b05ab
-            log.debug("found iscsi initiatorname %s", initiator)
0b05ab
-    return initiator
0b05ab
+                             session, "rb").read().strip()
0b05ab
+            initiator_name = initiator.decode("utf-8", errors="replace")
0b05ab
+            log.debug("found iscsi initiatorname %s", initiator_name)
0b05ab
+    return initiator_name
0b05ab
 
0b05ab
 
0b05ab
 # fcoe disks have ID_PATH in the form of: