[PATCH] Add an "sshpw" command for changing the passwords in anaconda's env.

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

 



This allows the user to change the passwords for anaconda's "ssh"
environment.
---
 pykickstart/commands/__init__.py |    2 +-
 pykickstart/commands/sshpw.py    |  104 ++++++++++++++++++++++++++++++++++++++
 pykickstart/handlers/control.py  |    2 +
 tests/commands/sshpw.py          |   57 +++++++++++++++++++++
 4 files changed, 164 insertions(+), 1 deletions(-)
 create mode 100644 pykickstart/commands/sshpw.py
 create mode 100644 tests/commands/sshpw.py

diff --git a/pykickstart/commands/__init__.py b/pykickstart/commands/__init__.py
index 0952bf8..da48ff5 100644
--- a/pykickstart/commands/__init__.py
+++ b/pykickstart/commands/__init__.py
@@ -22,5 +22,5 @@ import deviceprobe, displaymode, dmraid, driverdisk, fcoe, firewall, firstboot
 import group, ignoredisk, interactive, iscsi, iscsiname, key, keyboard, lang
 import langsupport, lilocheck, logging, logvol, mediacheck, method, monitor
 import mouse, multipath, network, partition, raid, reboot, repo, rescue, rootpw
-import selinux, services, skipx, timezone, updates, upgrade, user, vnc
+import selinux, services, skipx, sshpw, timezone, updates, upgrade, user, vnc
 import volgroup, xconfig, zerombr, zfcp
diff --git a/pykickstart/commands/sshpw.py b/pykickstart/commands/sshpw.py
new file mode 100644
index 0000000..9d48e22
--- /dev/null
+++ b/pykickstart/commands/sshpw.py
@@ -0,0 +1,104 @@
+#
+# Peter Jones <pjones@xxxxxxxxxx>
+#
+# Copyright 2009 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
+# General Public License v.2.  This program is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
+# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
+# trademarks that are incorporated in the source code or documentation are not
+# subject to the GNU General Public License and may only be used or replicated
+# with the express permission of Red Hat, Inc. 
+#
+from pykickstart.base import *
+from pykickstart.errors import *
+from pykickstart.options import *
+
+import gettext
+_ = lambda x: gettext.ldgettext("pykickstart", x)
+
+class F13_SshPwData(BaseData):
+    removedKeywords = BaseData.removedKeywords
+    removedAttrs = BaseData.removedAttrs
+
+    def __init__(self, *args, **kwargs):
+        BaseData.__init__(self, *args, **kwargs)
+        self.username = kwargs.get("username", None)
+        self.isCrypted = kwargs.get("isCrypted", False)
+        self.password = kwargs.get("password", "")
+        self.lock = kwargs.get("lock", False)
+
+    def __eq__(self, y):
+        return self.username == y.username
+
+    def __str__(self):
+        retval = BaseData.__str__(self)
+
+        retval += "sshpw"
+        retval += self._getArgsAsStr() + '\n'
+
+        return retval
+
+    def _getArgsAsStr(self):
+        retval = ""
+
+        retval += " --username=%s" % self.username
+        if self.lock:
+            retval += " --lock"
+        if self.isCrypted:
+            retval += " --iscrypted"
+        else:
+            retval += " --plaintext"
+
+        retval += " %s" % self.password
+        return retval
+
+class F13_SshPw(KickstartCommand):
+    removedKeywords = KickstartCommand.removedKeywords
+    removedAttrs = KickstartCommand.removedAttrs
+
+    def __init__(self, writePriority=0, *args, **kwargs):
+        KickstartCommand.__init__(self, writePriority, *args, **kwargs)
+        self.op = self._getParser()
+
+        self.sshUserList = kwargs.get("sshUserList", [])
+
+    def __str__(self):
+        retval = ""
+        for user in self.sshUserList:
+            retval += user.__str__()
+
+        return retval
+
+    def _getParser(self):
+        op = KSOptionParser()
+        op.add_option("--username", dest="username", required=True)
+        op.add_option("--iscrypted", dest="isCrypted", action="store_true",
+                      default=False)
+        op.add_option("--plaintext", dest="isCrypted", action="store_false")
+        op.add_option("--lock", dest="lock", action="store_true", default=False)
+        return op
+
+    def parse(self, args):
+        ud = self.handler.SshPwData()
+        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
+        self._setToObj(self.op, opts, ud)
+
+        if len(extra) != 1:
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("A single argument is expected for the %s command") % "sshpw")
+        ud.password = extra[0]
+
+        if ud in self.dataList():
+            warnings.warn(_("An ssh user with the name %s has already been defined.") % ud.name)
+
+        return ud
+
+    def dataList(self):
+        return self.sshUserList
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index e6f62c0..9d15cfd 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -636,6 +636,7 @@ commandMap = {
         "services": services.FC6_Services,
         "shutdown": reboot.FC6_Reboot,
         "skipx": skipx.FC3_SkipX,
+        "sshpw": sshpw.F13_SshPw,
         "text": displaymode.FC3_DisplayMode,
         "timezone": timezone.FC6_Timezone,
         "updates": updates.F7_Updates,
@@ -961,6 +962,7 @@ dataMap = {
         "PartData": partition.F12_PartData,
         "RaidData": raid.F12_RaidData,
         "RepoData": repo.F13_RepoData,
+        "SshPwData": sshpw.F13_SshPwData,
         "UserData": user.F12_UserData,
         "VolGroupData": volgroup.FC3_VolGroupData,
         "ZFCPData": zfcp.F12_ZFCPData,
diff --git a/tests/commands/sshpw.py b/tests/commands/sshpw.py
new file mode 100644
index 0000000..2187c74
--- /dev/null
+++ b/tests/commands/sshpw.py
@@ -0,0 +1,57 @@
+#
+# Peter Jones <pjones@xxxxxxxxxx>
+#
+# Copyright 2009 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
+# General Public License v.2.  This program is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
+# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
+# trademarks that are incorporated in the source code or documentation are not
+# subject to the GNU General Public License and may only be used or replicated
+# with the express permission of Red Hat, Inc. 
+#
+import unittest, shlex
+import warnings
+from tests.baseclass import *
+
+from pykickstart.errors import *
+from pykickstart.commands.sshpw import *
+
+class F13_TestCase(CommandTest):
+    def runTest(self):
+        # pass
+        self.assert_parse("sshpw --username=someguy --iscrypted secrethandshake", "sshpw --username=someguy --iscrypted secrethandshake\n")
+
+        # fail
+        self.assert_parse_error("sshpw", KickstartValueError)
+        self.assert_parse_error("sshpw --username=someguy", KickstartValueError)
+        self.assert_parse_error("sshpw --username=someguy --iscrypted=OMGSEKRITZ", KickstartParseError)
+        self.assert_parse_error("sshpw --username=someguy --iscrypted", KickstartValueError)
+
+        # pass
+        self.assert_parse("sshpw --username=someguy --lock secrethandshake", "sshpw --username=someguy --lock --plaintext secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --plaintext secrethandshake", "sshpw --username=someguy --plaintext secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --plaintext --iscrypted secrethandshake", "sshpw --username=someguy --iscrypted secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --iscrypted --plaintext secrethandshake\n", "sshpw --username=someguy --plaintext secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --lock --plaintext secrethandshake", "sshpw --username=someguy --lock --plaintext secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --iscrypted --lock secrethandshake", "sshpw --username=someguy --lock --iscrypted secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --lock --iscrypted --plaintext secrethandshake", "sshpw --username=someguy --lock --plaintext secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --lock --plaintext --iscrypted secrethandshake", "sshpw --username=someguy --lock --iscrypted secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --plaintext --iscrypted --lock secrethandshake", "sshpw --username=someguy --lock --iscrypted secrethandshake\n")
+        self.assert_parse("sshpw --username=someguy --iscrypted --plaintext --lock secrethandshake", "sshpw --username=someguy --lock --plaintext secrethandshake\n")
+
+        # fail
+        self.assert_parse_error("sshpw --username=someguy --plaintext=ISEEENGLAND secrethandshake", KickstartParseError)
+        self.assert_parse_error("sshpw --username=someguy --lock=NOKEYSFORYOU secrethandshake", KickstartParseError)
+        self.assert_parse_error("sshpw --username=someguy --plaintext", KickstartValueError)
+        self.assert_parse_error("sshpw --username=someguy --lock", KickstartValueError)
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.6.5.rc2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux