File lio-utils-allow-clearing-discovery-auth.patch of Package lio-utils.216

From: Lee Duncan <lduncan@suse.com>
Subject: lio-utils: allow clearing discovery auth
References: bnc#893315

When setting a discovery auth atttribute to a NULL string,
we must actually write a NULL byte to reset that attribute.

Acked-by: Lee Duncan <lduncan@suse.com>
---
 lio-py/lio_node.py |   25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff -aurp lio-utils-4.1.orig/lio-py/lio_node.py lio-utils-4.1/lio-py/lio_node.py
--- lio-utils-4.1.orig/lio-py/lio_node.py	2014-08-26 14:59:01.535183056 -0700
+++ lio-utils-4.1/lio-py/lio_node.py	2014-08-26 18:26:35.674551572 -0700
@@ -694,6 +694,15 @@ def lio_target_set_chap_mutual_auth(opti
 	
 	return
 
+def write_to_file(fname, vstr):
+	if not os.path.isfile(fname):
+		return False
+	if not vstr:
+		vstr = "\0"
+	with open(fname, 'w', 0) as sysfile:
+		res = os.write(sysfile.fileno(), vstr)
+	return (res > 0)
+
 def lio_target_set_chap_discovery_auth(option, opt_str, value, parser):
 	user = str(value[0]);
 	password = str(value[1]);
@@ -702,14 +711,10 @@ def lio_target_set_chap_discovery_auth(o
         if not os.path.isdir(auth_dir):
                 lio_err("iSCSI Discovery Authentication directory " + auth_dir + " does not exist")
 
-        setuser_op = "echo -n " + user + " > " + auth_dir + "/userid"
-        ret = os.system(setuser_op)
-        if ret:
+	if not write_to_file(auth_dir + "/userid", user):
 		lio_err("Unable to set CHAP username for iSCSI  Discovery Authentication")
 
-        setpassword_op = "echo -n " + password + " > " + auth_dir + "/password"
-        ret = os.system(setpassword_op)
-        if ret:
+	if not write_to_file(auth_dir + "/password", password):
                 lio_err("Unable to set CHAP password for iSCSI Discovery Authentication")
         else:
                 lio_dbg("Successfully set CHAP authentication for iSCSI Discovery Authentication")
@@ -724,14 +729,10 @@ def lio_target_set_chap_mutual_discovery
 	if not os.path.isdir(auth_dir):
 		lio_err("iSCSI Discovery Authentication directory " + auth_dir + " does not exist")
 
-	setuser_op = "echo -n " + user_mutual + " > " + auth_dir + "/userid_mutual"
-	ret = os.system(setuser_op)
-	if ret:
+	if not write_to_file(auth_dir + "/userid_mutual", user_mutual):
 		lio_err("Unable to set mutual CHAP username for iSCSI Discovery Authentication")
 
-	setpassword_op = "echo -n " + password_mutual + " > " + auth_dir + "/password_mutual"
-	ret = os.system(setpassword_op)
-	if ret:
+	if not write_to_file(auth_dir + "/password_mutual", password_mutual):
 		lio_err("Unable to set mutual CHAP password for iSCSI Discovery Authentication")
 	else:
 		lio_dbg("Successfully set mutual CHAP authentication for iSCSI Discovery Authentication")

openSUSE Build Service is sponsored by