[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Fedora-livecd-list] [Patch] setting root password



Jeroen van Meeuwen wrote:
> This is an attempt to fix being able to set the root password from
> kickstart.
> 

My bad, I used kshandler.rootpw.rootpw instead of kshandler.rootpw.password.

Kind regards,

Jeroen van Meeuwen
-kanarip
--- livecd/creator/livecd-creator.orig	2007-04-10 23:53:59.000000000 +0200
+++ livecd/creator/livecd-creator	2007-04-16 14:21:52.000000000 +0200
@@ -522,9 +522,22 @@
                 args.append("--selinux=disabled")
             subprocess.call(args, preexec_fn=self.run_in_root)
 
-        # FIXME: we should allow the setting of the root pass
-        if os.path.exists("%s/usr/bin/passwd" %(instroot,)):
-            subprocess.call(["/usr/bin/passwd", "-d", "root"], preexec_fn=self.run_in_root)
+        # Set the root password
+        if not self.ksparser.handler.rootpw.isCrypted:
+            p1 = subprocess.Popen(["/bin/echo", self.ksparser.handler.rootpw.password], stdout=PIPE, preexec_fn=self.run_in_root)
+            p2 = subprocess.Popen(["/usr/bin/passwd", "--stdin", "root"], stdin=p1.stdout, stdout=PIPE, preexec_fn=self.run_in_root)
+            output = p2.communicate()[0]
+        else:
+            if os.path.exists("%s/etc/shadow" %(instroot,), "rw+"):
+                f = open("%s/etc/shadow" % (instroot,))
+            else:
+                f = open("%s/etc/passwd" % (instroot,))
+            
+            buf = f.read()
+            buf = buf.replace("root:!!:","root:%s:" % (self.ksparser.handler.rootpw.password,))
+            f.seek(0)
+            f.write(buf)
+            f.close()
 
         # enable/disable services appropriately
         if os.path.exists("%s/sbin/chkconfig" %(instroot,)):

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]