[node-patches] Change in ovirt-node[master]: password: Replace setpassUser and update the persist/unpersi...

dougsland at redhat.com dougsland at redhat.com
Fri Nov 6 22:05:43 UTC 2015


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: password: Replace setpassUser and update the persist/unpersist calls
......................................................................

password: Replace setpassUser and update the persist/unpersist calls

Workaround for admin.setpassUser not working properly
with persist command during upgrades/reinstall or downgrade.
Additionally, updated the persist/unpersist calls for the new module Config.

Change-Id: Ie8a1b3fe1343e6820e83e2a9db8ff6715d959336
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1263648
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M src/ovirtnode/password.py
1 file changed, 24 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/16/48216/1

diff --git a/src/ovirtnode/password.py b/src/ovirtnode/password.py
index 53614bb..3cf7d00 100755
--- a/src/ovirtnode/password.py
+++ b/src/ovirtnode/password.py
@@ -24,6 +24,7 @@
 import string
 import augeas
 
+from ovirt.node.utils.fs import Config
 
 def cryptPassword(password):
     saltlen = 2
@@ -39,15 +40,33 @@
     admin = libuser.admin()
     root = admin.lookupUserByName(user)
     passwd = cryptPassword(password)
+
     try:
-        _functions.unmount_config("/etc/shadow")
-        _functions.unmount_config("/etc/passwd")
-        admin.setpassUser(root, passwd, "is_crypted")
+        Config().unpersist("/etc/passwd")
+
+        # Workaround for admin.setpassUser not working properly
+        # with persist command during upgrades/reinstall or downgrade
+        # See more: BZ#1263648
+        #
+        with open("/etc/shadow", "r") as f:
+            shw = f.readlines()
+
+        with open("/etc/shadow", "w") as f:
+            for line in shw:
+                if line.split(":")[0] == "admin":
+                    entry = line.split(":")
+                    entry[1] = "{0}".format(passwd)
+                    f.write(':'.join(entry))
+                    continue
+                f.write(line)
+
+        # Ends workaround
+        # admin.setpassUser(root, passwd, "is_crypted")
     except:
         raise
     finally:
-        _functions.ovirt_store_config("/etc/shadow")
-        _functions.ovirt_store_config("/etc/passwd")
+        Config().persist("/etc/shadow")
+
     return True
 
 


-- 
To view, visit https://gerrit.ovirt.org/48216
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie8a1b3fe1343e6820e83e2a9db8ff6715d959336
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list