Package pyanaconda :: Module sshd
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.sshd

 1  # sshd.py 
 2  # Configuring the sshd daemon from Anaconda. 
 3  # 
 4  # Copyright (C) 2009  Red Hat, Inc. 
 5  # 
 6  # This copyrighted material is made available to anyone wishing to use, 
 7  # modify, copy, or redistribute it subject to the terms and conditions of 
 8  # the GNU General Public License v.2, or (at your option) any later version. 
 9  # This program is distributed in the hope that it will be useful, but WITHOUT 
10  # ANY WARRANTY expressed or implied, including the implied warranties of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
12  # Public License for more details.  You should have received a copy of the 
13  # GNU General Public License along with this program; if not, write to the 
14  # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
15  # 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the 
16  # source code or documentation are not subject to the GNU General Public 
17  # License and may only be used or replicated with the express permission of 
18  # Red Hat, Inc. 
19  # 
20   
21   
22  import logging 
23  import os, sys 
24  log = logging.getLogger("anaconda") 
25   
26  import iutil 
27  import users 
28  from flags import flags 
29  from constants import ROOT_PATH 
30   
31 -def createSshKey(algorithm, keyfile):
32 path = '/etc/ssh/%s' % (keyfile,) 33 argv = ['-q','-t',algorithm,'-f',path,'-C','','-N',''] 34 if os.access(path, os.R_OK): 35 return 36 log.debug("running \"%s\"" % (" ".join(['ssh-keygen']+argv),)) 37 38 so = "/tmp/ssh-keygen-%s-stdout.log" % (algorithm,) 39 se = "/tmp/ssh-keygen-%s-stderr.log" % (algorithm,) 40 iutil.execWithRedirect('ssh-keygen', argv, stdout=so, stderr=se)
41
42 -def doSshd(anaconda):
43 if flags.sshd: 44 # we need to have a libuser.conf that points to the installer root for 45 # sshpw, but after that we start sshd, we need one that points to the 46 # install target. 47 luserConf = users.createLuserConf(instPath="") 48 handleSshPw(anaconda) 49 startSsh() 50 del(os.environ["LIBUSER_CONF"]) 51 else: 52 log.info("sshd: not enabled, skipping.") 53 54 users.createLuserConf(ROOT_PATH)
55
56 -def handleSshPw(anaconda):
57 if not anaconda.ksdata: 58 return 59 60 u = users.Users(anaconda) 61 62 userdata = anaconda.ksdata.sshpw.dataList() 63 for ud in userdata: 64 if u.checkUserExists(ud.username, root="/"): 65 u.setUserPassword(username=ud.username, password=ud.password, 66 isCrypted=ud.isCrypted, lock=ud.lock) 67 else: 68 kwargs = ud.__dict__ 69 kwargs.update({"root": "/", "mkmailspool": False}) 70 u.createUser(ud.username, **kwargs) 71 72 del u
73
74 -def startSsh():
75 if iutil.isS390(): 76 return 77 78 if not iutil.fork_orphan(): 79 os.open("/var/log/lastlog", os.O_RDWR | os.O_CREAT, 0644) 80 ssh_keys = { 81 'rsa1':'ssh_host_key', 82 'rsa':'ssh_host_rsa_key', 83 'dsa':'ssh_host_dsa_key', 84 } 85 for (algorithm, keyfile) in ssh_keys.items(): 86 createSshKey(algorithm, keyfile) 87 sshd = iutil.find_program_in_path("sshd") 88 args = [sshd, "-f", "/etc/ssh/sshd_config.anaconda"] 89 os.execv(sshd, args) 90 sys.exit(1)
91