summaryrefslogtreecommitdiffstats
path: root/utils/handle-sshpw
blob: 4b14208fc04a417fb4126293546be652d5d424e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/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 = '/run/install/ks.cfg'

# 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"])