Ejemplo n.º 1
0
def check_join(logger, responsible):
    """
    'net ads testjoin' should be sufficient in most cases.
    'net rpc testjoin' is a fallback to 'net ads testjoin'
    """
    responsible.feedback(tr("Checking that the group mappings exist."))
    if not exists("/var/lib/samba/winbindd_idmap.tdb"):
        raise NuauthException(NO_MAPPING_EXISTS, "The group mappings don't exist")
    try:
        cmd = ('/usr/bin/net', 'ads', 'testjoin')
        runCommandAndCheck(logger, cmd)
    except RunCommandError:
        pass # another test
    else:
        responsible.feedback(tr("The junction to the Active Directory domain is functional"))
        return # ok

    try:
        cmd = ('/usr/bin/net', 'rpc', 'testjoin')
        runCommandAndCheck(logger, cmd)
    except RunCommandError:
        if responsible is not None:
            responsible.feedback(
                tr("No junction to an Active Directory domain.")
            )
        raise NuauthException(NUAUTH_INVALID_CONF,
            "Domain not available")
    responsible.feedback(tr("The junction to the Active Directory domain is functional"))
Ejemplo n.º 2
0
 def createFingerprint(self):
     """
     create fingerprint if needed
     """
     if not exists(self.FINGERPRINT_CREATED):
         self.info('Generate new authentication key')
         runCommandAndCheck(self, [self.CREATE_FINGERPRINT])
         open(self.FINGERPRINT_CREATED, 'a').close() # touch
Ejemplo n.º 3
0
    def service_rebootSystem(self, context):
        """
        Reboot the system
        """
        if context.isComponentContext:
            runCommandAndCheck(self, '/sbin/reboot')
            return

        defer = self.core.callService(context, 'session', 'destroy')
        defer.addCallback(lambda unused: runCommandAndCheck(self, '/sbin/reboot'))
Ejemplo n.º 4
0
 def _update_sysctl_nf_conntrack_max(self, model):
     nf_conntrack_max = _NF_CONNTRACK_MAX.get(model, 0)
     if nf_conntrack_max > 0:
         self.generate_configfile({"nf_conntrack_max": nf_conntrack_max},
                                  ("/etc/sysctl.d/nf_conntrack_max.conf",))
         try:
             runCommandAndCheck(self, ["sysctl", "-w",
                                       "net.netfilter.nf_conntrack_max=%d"
                                       % nf_conntrack_max])
         except Exception:
             self.critical(
                 "Error while setting the maximum number of simultaneous connexions.")
Ejemplo n.º 5
0
def test_system_group(logger, groupname):
    cmd = (GETENT_BIN, "group", groupname)
    try:
        runCommandAndCheck(logger, cmd)
    except RunCommandError, err:
        if isinstance(err.status, (str, unicode)):
            status = int(err.status)
        else:
            status = err.status
        if status == 2:
            raise NoSuchGroup(groupname)
        else:
            raise GetentError(groupname)
Ejemplo n.º 6
0
def test_system_user(logger, username):
    cmd = (GETENT_BIN, "passwd", username)
    try:
        runCommandAndCheck(logger, cmd)
    except RunCommandError, err:
        if isinstance(err.status, (str, unicode)):
            status = int(err.status)
        else:
            status = err.status
        if status == 2:
            raise NoSuchUser(username)
        else:
            raise GetentError(username)
Ejemplo n.º 7
0
def net_ads_keytab_command(logger, user, password, keytab_command):
    login_string = '%'.join((user, password))
    command = "net ads -U".split()
    #slow construction, but handles spaces in login/password nicely
    command.append(login_string)
    command.append('keytab')
    command += keytab_command.split()

    command_log = "net ads -U ***user***  ***pass*** keytab %s" % keytab_command

    runCommandAndCheck(
        logger,
        command,
        env={},
        cmdstr=command_log
    )
Ejemplo n.º 8
0
 def _update_default_mpt_statusd(self, model):
     if model.startswith("E4"):  # Enable then start.
         run_mpt_statusd = "yes"
         self.generate_configfile({"run_mpt_statusd": run_mpt_statusd},
                                  ("/etc/default/mpt-statusd",))
         try:
             runCommandAndCheck(self, ["/etc/init.d/mpt-statusd", "start"])
         except Exception:
             self.critical(
                 "Error while starting the RAID status monitor.")
     else:  # Stop then disable.
         run_mpt_statusd = "no"
         try:
             runCommandAndCheck(self, ["/etc/init.d/mpt-statusd", "stop"])
         except Exception:
             self.error(
                 "Error while stopping the RAID status monitor.")
         self.generate_configfile({"run_mpt_statusd": run_mpt_statusd},
                                  ("/etc/default/mpt-statusd",))
Ejemplo n.º 9
0
def net_ads_testjoin(logger):
    try:
        process, stdout = runCommandAndCheck(
            logger,
            _TESTJOIN_COMMAND,
            env={},
            timeout=10
        )

    except RunCommandError:
        return False

    for line in stdout:
        if line.strip() == _OK_JOIN_MSG:
            return True

    return False
Ejemplo n.º 10
0
def ad_info(logger):
    data = {}

    try:
        process, stdout = runCommandAndCheck(
            logger,
            _INFO_COMMAND,
            env={},
            timeout=10
        )

    except RunCommandError:
        return data

    for line in stdout:
        split_value = line.split(":", 1)
        if len(split_value) == 2:
            key, value = split_value
            data[key] = value.strip()

    return data
Ejemplo n.º 11
0
 def service_haltSystem(self, context):
     """
     destroy current session and halt the system
     """
     defer = self.core.callService(context, 'session', 'destroy')
     defer.addCallback(lambda unused: runCommandAndCheck(self, '/sbin/halt'))