Merge branch 'master' of ssh://git.fedorahosted.org/git/fedora-infrastructure

This commit is contained in:
Ricky Zhou (周家杰) 2008-03-06 22:32:19 -05:00
commit ea0b7949b8

View file

@ -22,12 +22,13 @@
import sys import sys
import logging import logging
import syslog
import os import os
import tempfile import tempfile
from fedora.tg.client import BaseClient, AuthError, ServerError from fedora.tg.client import BaseClient, AuthError, ServerError
from optparse import OptionParser from optparse import OptionParser
from shutil import move, rmtree from shutil import move, rmtree, copytree
from rhpl.translate import _ from rhpl.translate import _
import ConfigParser import ConfigParser
@ -59,6 +60,12 @@ parser.add_option('--noshadow',
default = False, default = False,
action = 'store_true', action = 'store_true',
help = _('Do not sync shadow information')) help = _('Do not sync shadow information'))
parser.add_option('--nohome',
dest = 'no_home_dirs',
default = False,
action = 'store_true',
help = _('Do not create home dirs'))
parser.add_option('-s', '--server', parser.add_option('-s', '--server',
dest = 'FAS_URL', dest = 'FAS_URL',
default = None, default = None,
@ -77,6 +84,8 @@ parser.add_option('-d', '--disable',
(opts, args) = parser.parse_args() (opts, args) = parser.parse_args()
log = logging.getLogger('fas')
try: try:
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
if os.path.exists(opts.CONFIG_FILE): if os.path.exists(opts.CONFIG_FILE):
@ -93,6 +102,11 @@ except ConfigParser.MissingSectionHeaderError, e:
FAS_URL = config.get('global', 'url') FAS_URL = config.get('global', 'url')
def _chown(arg, dir_name, files):
os.chown(dir_name, arg[0], arg[1])
for file in files:
os.chown(os.path.join(dir_name, file), arg[0], arg[1])
class MakeShellAccounts(BaseClient): class MakeShellAccounts(BaseClient):
temp = None temp = None
groups = None groups = None
@ -112,9 +126,6 @@ class MakeShellAccounts(BaseClient):
config.get('host', 'ssh_restricted_groups').split(',') config.get('host', 'ssh_restricted_groups').split(',')
try: try:
for group in valid_groups: for group in valid_groups:
print group
print self.group_mapping[group]
print username
if username in self.group_mapping[group]: if username in self.group_mapping[group]:
return True return True
except KeyError: except KeyError:
@ -156,7 +167,7 @@ class MakeShellAccounts(BaseClient):
i = i + 1 i = i + 1
passwd_file.close() passwd_file.close()
shadow_file.close() shadow_file.close()
def valid_user_group(self, person_id): def valid_user_group(self, person_id):
''' Determine if person is valid on this machine as defined in the ''' Determine if person is valid on this machine as defined in the
config file. I worry that this is going to be horribly inefficient config file. I worry that this is going to be horribly inefficient
@ -247,6 +258,18 @@ class MakeShellAccounts(BaseClient):
move(self.temp + '/group.db', '/var/db/group.db') move(self.temp + '/group.db', '/var/db/group.db')
except IOError, e: except IOError, e:
print "ERROR: Could not write group db - %s" % e print "ERROR: Could not write group db - %s" % e
def create_homedirs(self):
''' Create homedirs and home base dir if they do not exist '''
home_base = config.get('users', 'home')
if not os.path.exists(home_base):
os.makedirs(home_base, mode=0755)
for person in self.people:
home_dir = os.path.join(home_base, person['username'])
if not os.path.exists(home_dir) and self.valid_user(person['username']):
syslog.syslog('Creating homedir for %s' % person['username'])
copytree('/etc/skel/', home_dir)
os.path.walk(home_dir, _chown, [person['id'], person['id']])
def enable(): def enable():
temp = tempfile.mkdtemp('-tmp', 'fas-', config.get('global', 'temp')) temp = tempfile.mkdtemp('-tmp', 'fas-', config.get('global', 'temp'))
@ -309,6 +332,8 @@ if __name__ == '__main__':
fas.install_passwd_db() fas.install_passwd_db()
if not opts.no_shadow: if not opts.no_shadow:
fas.install_shadow_db() fas.install_shadow_db()
if not opts.no_home_dirs:
fas.create_homedirs()
fas.rm_tempdir() fas.rm_tempdir()
if not (opts.install or opts.enable or opts.disable): if not (opts.install or opts.enable or opts.disable):
parser.print_help() parser.print_help()