[PATCH] Two new options for the rootpw command

Vratislav Podzimek vpodzime at redhat.com
Wed May 15 12:29:21 UTC 2013


These are needed for specifying what should be the policy on changing the
password from kickstart in the UI.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pykickstart/commands/rootpw.py  | 63 ++++++++++++++++++++++++++++++++++++++++-
 pykickstart/handlers/control.py |  4 +--
 tests/commands/rootpw.py        | 31 ++++++++++++++++++++
 3 files changed, 95 insertions(+), 3 deletions(-)

diff --git a/pykickstart/commands/rootpw.py b/pykickstart/commands/rootpw.py
index 494c7f4..88f8b97 100644
--- a/pykickstart/commands/rootpw.py
+++ b/pykickstart/commands/rootpw.py
@@ -1,7 +1,7 @@
 #
 # Chris Lumens <clumens at redhat.com>
 #
-# Copyright 2005, 2006, 2007 Red Hat, Inc.
+# Copyright 2005-2013 Red Hat, Inc.
 #
 # This copyrighted material is made available to anyone wishing to use, modify,
 # copy, or redistribute it subject to the terms and conditions of the GNU
@@ -115,3 +115,64 @@ class F18_RootPw(F8_RootPw):
             self.password = extra[0]
 
         return self
+
+class F19_RootPw(F18_RootPw):
+    def __init__(self, *args, **kwargs):
+        F18_RootPw.__init__(self, *args, **kwargs)
+        self.frozen = kwargs.get("frozen", False)
+        self.allow_changes = kwargs.get("allow_changes", False)
+
+    def _getParser(self):
+        op = F18_RootPw._getParser(self)
+        op.add_option("--frozen", dest="frozen", action="store_true", default=False)
+        op.add_option("--allow-changes", dest="allow_changes", action="store_true", default=False)
+
+        return op
+
+    def _getArgsAsStr(self):
+        retval = ""
+
+        if self.lock:
+            retval += " --lock"
+
+        if self.frozen:
+            retval += " --frozen"
+
+        if self.allow_changes:
+            retval += " --allow-changes"
+
+        if self.password:
+            if self.isCrypted:
+                retval += " --iscrypted"
+            else:
+                retval += " --plaintext"
+
+        return retval
+
+    def parse(self, args):
+        F18_RootPw.parse(self, args)
+
+        if self.frozen and not self.password:
+            # password must be given when --frozen (i.e. no more changes) is used
+            raise KickstarParseError(formatErrorMsg(self.lineno,
+                                                     msg=_("A password must be given if "
+                                                           "the '--frozen' is used")))
+
+        if self.frozen and self.allow_changes:
+            # cannot be used both at the same time
+            raise KickstartParseError(formatErrorMsg(self.lineno,
+                                                     msg=_("Cannot use '--frozen' and "
+                                                           "'--allow-changes' in the same time")))
+
+        return self
+
+    def __str__(self):
+        retval  = "# Root password\n"
+        retval += "rootpw%s" % self._getArgsAsStr()
+
+        if self.password:
+            retval += " %s\n" % self.password
+        else:
+            retval += "\n"
+
+        return retval
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index de71643..dfc2cdd 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -987,7 +987,7 @@ commandMap = {
         "reboot": reboot.F18_Reboot,
         "repo": repo.F15_Repo,
         "rescue": rescue.F10_Rescue,
-        "rootpw": rootpw.F18_RootPw,
+        "rootpw": rootpw.F19_RootPw,
         "selinux": selinux.FC3_SELinux,
         "services": services.FC6_Services,
         "shutdown": reboot.F18_Reboot,
@@ -1268,7 +1268,7 @@ commandMap = {
         "reboot": reboot.FC6_Reboot,
         "repo": repo.F15_Repo,
         "rescue": rescue.F10_Rescue,
-        "rootpw": rootpw.F18_RootPw,
+        "rootpw": rootpw.F19_RootPw,
         "selinux": selinux.FC3_SELinux,
         "services": services.FC6_Services,
         "shutdown": reboot.FC6_Reboot,
diff --git a/tests/commands/rootpw.py b/tests/commands/rootpw.py
index 8498eb4..2a9b751 100644
--- a/tests/commands/rootpw.py
+++ b/tests/commands/rootpw.py
@@ -65,5 +65,36 @@ class F18_TestCase(F8_TestCase):
 
         self.assert_parse("rootpw --lock", "rootpw --lock\n")
 
+class F19_TestCase(F18_TestCase):
+    def runTest(self):
+        # pass
+        self.assert_parse("rootpw --iscrypted secrethandshake", "rootpw --iscrypted secrethandshake\n")
+        self.assert_parse("rootpw --lock secrethandshake", "rootpw --lock --plaintext secrethandshake\n")
+        self.assert_parse("rootpw --plaintext secrethandshake", "rootpw --plaintext secrethandshake\n")
+        self.assert_parse("rootpw --plaintext --iscrypted secrethandshake", "rootpw --iscrypted secrethandshake\n")
+        self.assert_parse("rootpw --iscrypted --plaintext secrethandshake\n", "rootpw --plaintext secrethandshake\n")
+        self.assert_parse("rootpw --lock --plaintext secrethandshake", "rootpw --lock --plaintext secrethandshake\n")
+        self.assert_parse("rootpw --iscrypted --lock secrethandshake", "rootpw --lock --iscrypted secrethandshake\n")
+        self.assert_parse("rootpw --lock --iscrypted --plaintext secrethandshake", "rootpw --lock --plaintext secrethandshake\n")
+        self.assert_parse("rootpw --lock --plaintext --iscrypted secrethandshake", "rootpw --lock --iscrypted secrethandshake\n")
+        self.assert_parse("rootpw --plaintext --iscrypted --lock secrethandshake", "rootpw --lock --iscrypted secrethandshake\n")
+        self.assert_parse("rootpw --iscrypted --plaintext --lock secrethandshake", "rootpw --lock --plaintext secrethandshake\n")
+        self.assert_parse("rootpw --lock", "rootpw --lock\n")
+
+        # fail
+        self.assert_parse_error("rootpw", KickstartValueError)
+        self.assert_parse_error("rootpw --iscrypted=OMGSEKRITZ", KickstartParseError)
+        self.assert_parse_error("rootpw --iscrypted", KickstartValueError)
+        self.assert_parse_error("rootpw --plaintext=ISEEENGLAND secrethandshake", KickstartParseError)
+        self.assert_parse_error("rootpw --lock=NOKEYSFORYOU secrethandshake", KickstartParseError)
+        self.assert_parse_error("rootpw --plaintext", KickstartValueError)
+
+        # test parsing of the new options
+        self.assert_parse("rootpw --frozen password", "rootpw --frozen --plaintext password\n")
+        self.assert_parse("rootpw --allow-changes password", "rootpw --allow-changes --plaintext password\n")
+
+        # cannot be used both in the same time
+        self.assert_parse_error("rootpw --frozen --allow-changes password", KickstartParseError)
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.7.11.7



More information about the anaconda-patches mailing list