summaryrefslogtreecommitdiffstats
path: root/utils/handle-sshpw
diff options
context:
space:
mode:
authorJesse Keating <jkeating@redhat.com>2012-06-07 22:09:26 -0700
committerJesse Keating <jkeating@redhat.com>2012-06-08 10:06:49 -0700
commit6a5deaff7cd9710f9267f48001d4331958bacd45 (patch)
tree35b6f89f061aa98f1eb395a9c3653f2a84f25d0b /utils/handle-sshpw
parentfcb1049bffe200acebac3372d8af7fc60926c892 (diff)
downloadanaconda-6a5deaff7cd9710f9267f48001d4331958bacd45.tar.gz
anaconda-6a5deaff7cd9710f9267f48001d4331958bacd45.tar.xz
anaconda-6a5deaff7cd9710f9267f48001d4331958bacd45.zip
Move sshpw handling out of Anaconda
This creates an ExecStartPre on the anaconda-sshd.service that will check for a kickstart entry for sshpw. It will add/modify users accordingly prior to launching the sshd service. Since now sshpw and sshd bring up happens outside of and before anaconda starts, we can remove sshd.py and any reference to it.
Diffstat (limited to 'utils/handle-sshpw')
-rwxr-xr-xutils/handle-sshpw57
1 files changed, 57 insertions, 0 deletions
diff --git a/utils/handle-sshpw b/utils/handle-sshpw
new file mode 100755
index 000000000..a7acb5dbd
--- /dev/null
+++ b/utils/handle-sshpw
@@ -0,0 +1,57 @@
+#!/bin/python
+#
+# handle-sshpw: Code processing sshpw lines in kickstart files for the
+# install environment.
+#
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty 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, see <http://www.gnu.org/licenses/>.
+#
+# Author(s): Jesse Keating <jkeating@redhat.com>
+#
+# Some of this code comes from the old pyanaconda/sshd.py
+#
+import os
+import sys
+from pykickstart.parser import *
+from pykickstart.version import makeVersion
+import pyanaconda.users as users
+
+ksfile = '/ks.cfg.done'
+
+# see if we have a file to work with
+if not os.path.exists(ksfile):
+ sys.exit()
+
+ksparser = KickstartParser(makeVersion())
+ksparser.readKickstart(ksfile)
+
+# we need to have a libuser.conf that points to the installer root for
+# sshpw, but after that we start sshd, we need one that points to the
+# install target.
+luserConf = users.createLuserConf(instPath="")
+# Pass a fake anaconda object in because it won't be needed
+u = users.Users(None)
+
+userdata = ksparser.handler.sshpw.dataList()
+for ud in userdata:
+ if u.checkUserExists(ud.username, root="/"):
+ u.setUserPassword(username=ud.username, password=ud.password,
+ isCrypted=ud.isCrypted, lock=ud.lock)
+ else:
+ kwargs = ud.__dict__
+ kwargs.update({"root": "/", "mkmailspool": False})
+ u.createUser(ud.username, **kwargs)
+
+del(os.environ["LIBUSER_CONF"])