def cache_has_ticket(self):
        res = False

        p = pipeopen("/usr/bin/klist -t")
        p.communicate()
        if p.returncode == 0:
            res = True

        return res
Example #2
0
    def join_activedirectory(self, id, enable=True):
        self.logger.debug('join_activedirectory()')

        ad_context = self.modules[DS_TYPE_ACTIVEDIRECTORY].context
        if not ad_context:
            return False

        os.environ['LOGNAME'] = 'root'
        p = pipeopen("/usr/local/bin/net -k ads join  '%s'" % ad_context.realm)
        out = p.communicate()
        if p.returncode != 0:
            self.logger.debug('join_activedirectory(): FAILED: %s', out)
            return False

        self.logger.debug('join_activedirectory(): SUCCESS')
        return True
    def get_principal_from_cache(self):
        principal = None

        p = pipeopen("klist")
        klist_out = p.communicate()
        if p.returncode != 0:
            return None

        klist_out = klist_out[0]
        lines = klist_out.splitlines()
        for line in lines:
            line = line.strip()
            if line.startswith(bytes("Principal", "UTF-8")):
                parts = line.split(bytes(":", "UTF-8"))
                if len(parts) > 1:
                    principal = parts[1].strip()

        return principal