File lio-utils-fix-empty-attribute-string-writes of Package lio-utils.216

From: Lee Duncan <lduncan@suse.com>
Date: Wed Mar  4 10:42:09 PST 2015
Subject: [lio-utils] fix empty attribute string writes

Writing an empty string to a sysfs attribute does not work,
as 'echo -n "" >/sys/some/path/to/attribute" fails, as it
gets optimized to a NOOP.

This patch converts user input of an empty string to the
4-leter string "NULL", which is how sysfs actually detects
empty string values for targets.
--- 
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	2015-02-26 15:23:33.472000000 -0800
+++ lio-utils-4.1/lio-py/lio_node.py	2015-03-04 10:39:22.024000000 -0800
@@ -652,14 +652,10 @@ def lio_target_set_chap_auth(option, opt
 	if not os.path.isdir(auth_dir):
 		lio_err("iSCSI Initiator ACL " + initiator_iqn + " does not exist for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
-	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 Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
-	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 Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
 		lio_dbg("Successfully set CHAP authentication for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
@@ -680,14 +676,10 @@ def lio_target_set_chap_mutual_auth(opti
 	if not os.path.isdir(auth_dir):
 		lio_err("iSCSI Initiator ACL " + initiator_iqn + " does not exist for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
-	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 Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
-	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 Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
 		lio_dbg("Successfully set mutual CHAP authentication for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
@@ -698,7 +690,7 @@ def write_to_file(fname, vstr):
 	if not os.path.isfile(fname):
 		return False
 	if not vstr:
-		vstr = "\0"
+		vstr = "NULL"
 	with open(fname, 'w', 0) as sysfile:
 		res = os.write(sysfile.fileno(), vstr)
 	return (res > 0)
openSUSE Build Service is sponsored by