2016-04-10 04:00:00 +00:00
|
|
|
#!/usr/bin/python3
|
2013-01-23 17:28:19 +00:00
|
|
|
#
|
|
|
|
# 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
|
2014-04-07 12:38:09 +00:00
|
|
|
from pykickstart.parser import KickstartParser
|
2013-01-23 17:28:19 +00:00
|
|
|
from pykickstart.version import makeVersion
|
2015-05-30 11:20:59 +00:00
|
|
|
from pykickstart.sections import NullSection
|
2013-01-23 17:28:19 +00:00
|
|
|
import pyanaconda.users as users
|
|
|
|
|
|
|
|
ksfile = '/run/install/ks.cfg'
|
|
|
|
|
|
|
|
# see if we have a file to work with
|
|
|
|
if not os.path.exists(ksfile):
|
|
|
|
sys.exit()
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
handler = makeVersion()
|
|
|
|
ksparser = KickstartParser(handler, missingIncludeIsFatal=False)
|
|
|
|
ksparser.registerSection(NullSection(handler, sectionOpen="%addon"))
|
|
|
|
ksparser.registerSection(NullSection(handler, sectionOpen="%anaconda"))
|
2013-01-23 17:28:19 +00:00
|
|
|
ksparser.readKickstart(ksfile)
|
|
|
|
|
|
|
|
u = users.Users()
|
|
|
|
|
|
|
|
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__
|
2016-04-10 04:00:00 +00:00
|
|
|
kwargs.update({"root": "/"})
|
2013-01-23 17:28:19 +00:00
|
|
|
u.createUser(ud.username, **kwargs)
|