示例#1
0
文件: kadmin.py 项目: nwhalen/nixauth
    def __init__(self, principal = None, auth_type = KRB_AUTH_CC, credentials = '', realm = None, server = None,
                 kadmin_type = 'kadmin'):
        if not kadmin_type in ('kadmin', 'kadmin.local'):
            raise KadminInvalidApplicationError(kadmin_type)

        self.kadmin_type = kadmin_type

        # kadmin.local will not run from anyone but root
        if kadmin_type == 'kadmin.local' and not nixcommon.runningAsRoot():
            raise KadminRootRequiredError('Use of kadmin.local requires root privileges.')

        try:
            self.app_paths = app_paths
        except NameError:
            raise nixexceptions.InvalidAppPathsError("'Kerberos' section not found in app paths file.")

        if principal:
            self.principal = principal
        if realm:
            self.realm = realm
        if server:
            self.server = server

        # Store authentication related variables
        self.auth_type = auth_type
        self.credentials_path = credentials

        # Init script check
        if not os.access(config['Locations']['init_script'], os.X_OK):
            raise nixexceptions.InvalidInitScript(config['Locations']['init_script'])
        else:
            self.init_script = config['Locations']['init_script']

        return
示例#2
0
    def run(self):
        """
        naSetup API call.  Runs all the appropriate methods in the class to set BIND and named up.

        :return: Modified naSetup configuration dictionary.

        """
        if not nixcommon.runningAsRoot():
            raise nixexceptions.RequiresRoot('BIND setup needs to be run as root!')

        nameServers = self.checkDomain()

        # Zone exists, figure out if we can join it
        if nameServers:
            self.detectDomainType(nameServers)

        # Zone DNE, set up a new one
        else:
            local_nameserver = bind.BIND()
            if not local_nameserver.isRunning():
                try:
                    local_nameserver.start()
                except bind.DaemonControlError:
                    raise BINDSetupError('Failed to start BIND nameserver, I can\'t recover from this error!')
            self.setHostName()
            self.createDomain()
            self.setupResolvConf()
            self.runOperationalTests()

        return self.my_na_setup_config_fragment
示例#3
0
    def test_rootReturnsTrue(self, getuid):
        """
        Tests to see if a uid value = 0 will return ``True``.

        :param getuid: Mocked version of the getuid method of the :module:`os` module to use in this test.

        """
        nixcommon.os.getuid = getuid
        assert nixcommon.runningAsRoot() == True
        assert nixcommon.os.getuid.called
示例#4
0
log = logging.getLogger('napkginstall')

# Set up the console driver
log.debug('Setting up console driver')
con = console.Console(quiet_mode, color=color_mode)

#-------------------------------------------------
# Init
#-------------------------------------------------
con.printBanner('nixAuth Automatic Package Installer', banner_color, banner_size)
if na_run_from:
    log.debug('naPkgInstall run from %s' %na_run_from)
    print 'Running from %s' %na_run_from

if not nixcommon.runningAsRoot():
    log.error('Exiting due to lack of root privileges')
    con.prints('This script must be run as root!  Exiting...')
    exit(-1)

# Find out which distro we're using and what version it's at then import it's config
distro_helper = None
try:
    log.debug('Loading the distro helper')
    distro_helper = distrodetermine.loadDistroHelper()
    con.printStatus('Distribution', '%s - %s (%s)' %(distro_helper.whoami, distro_helper.nickname,
                                                     distro_helper.version))
    log.info('Distro Info: %s - %s (%s)' %(distro_helper.whoami, distro_helper.nickname, distro_helper.version))
except distrodetermine.UnsupportedDistribution:
    error = 'I\'m sorry, this version of your distro is unsupported.  Please see the compatibility list at \
            http://www.nixauth.org/compatibility to find a distro that works with nixAuth.'