当前位置: 首页>>代码示例>>Python>>正文


Python freenasldap.FreeNAS_ActiveDirectory类代码示例

本文整理汇总了Python中freenasUI.common.freenasldap.FreeNAS_ActiveDirectory的典型用法代码示例。如果您正苦于以下问题:Python FreeNAS_ActiveDirectory类的具体用法?Python FreeNAS_ActiveDirectory怎么用?Python FreeNAS_ActiveDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FreeNAS_ActiveDirectory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: directoryservice

 def directoryservice(self, name):
     """Temporary rapper to serialize DS connectors"""
     if name == 'AD':
         ds = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
         workgroups = []
         domains = ds.get_domains()
         for d in domains:
             if 'nETBIOSName' in d:
                 netbiosname = d['nETBIOSName']
                 workgroups.append(netbiosname)
         ds.workgroups = workgroups
     elif name == 'LDAP':
         ds = FreeNAS_LDAP(flags=FLAGS_DBINIT)
     else:
         raise ValueError('Unknown ds name {0}'.format(name))
     data = {}
     for i in (
         'netbiosname', 'keytab_file', 'keytab_principal', 'domainname',
         'use_default_domain', 'dchost', 'basedn', 'binddn', 'bindpw',
         'userdn', 'groupdn', 'ssl', 'certfile', 'id',
         'ad_idmap_backend', 'ds_type',
         'krb_realm', 'krbname', 'kpwdname',
         'krb_kdc', 'krb_admin_server', 'krb_kpasswd_server',
         'workgroups'
     ):
         if hasattr(ds, i):
             data[i] = getattr(ds, i)
     return data
开发者ID:binzyw,项目名称:freenas,代码行数:28,代码来源:notifier.py

示例2: _cache_keys_ActiveDirectory

def _cache_keys_ActiveDirectory(**kwargs):
    ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
    domains = ad.get_domains()
    for d in domains:
        workgroup = d['nETBIOSName']

        print "w: %s" % workgroup 

        ucache = FreeNAS_UserCache(dir=workgroup)
        if ucache: 
            for key in ucache.keys():
                print "u key: %s" % key

        gcache = FreeNAS_GroupCache(dir=workgroup)
        if gcache:
            for key in gcache.keys():
                print "g key: %s" % key

        ducache = FreeNAS_Directory_UserCache(dir=workgroup)
        if ducache:
            for key in ducache.keys():
                print "du key: %s" % key

        dgcache = FreeNAS_Directory_GroupCache(dir=workgroup)
        if dgcache:
            for key in dgcache.keys():
                print "dg key: %s" % key
开发者ID:PatriQ7,项目名称:freenas,代码行数:27,代码来源:cachetool.py

示例3: tryConnect

    def tryConnect(self, host, port):
        max_tries = 3
        connected = False
        sm_timeout = _fs().middlewared.plugins.service_monitor.socket_timeout
        host_list = []

        if self.name == 'activedirectory':

            for i in range(0, max_tries):
                # Make max_tries attempts to get SRV records from DNS
                host_list = FreeNAS_ActiveDirectory.get_ldap_servers(host)
                if host_list:
                    break
                else:
                    self.logger.debug(f'[ServiceMonitorThread] Attempt {i} to query SRV records failed')

            if not host_list:
                self.logger.debug(f'[ServiceMonitorThread] Query for SRV records for {host} failed')
                return False

            for h in host_list:
                port_is_listening = FreeNAS_ActiveDirectory.port_is_listening(str(h.target), h.port, errors=[], timeout=sm_timeout)
                if port_is_listening:
                    return True
                else:
                    self.logger.debug(f'[ServiceMonitorThread] Cannot connect: {h.target}:{h.port}')
                    connected = False

            return connected

        else:
            self.logger.debug(f'[ServiceMonitorThread] no monitoring has been written for {self.name}')
            return False
开发者ID:razzfazz,项目名称:freenas,代码行数:33,代码来源:service_monitor.py

示例4: _cache_rawdump_ActiveDirectory

def _cache_rawdump_ActiveDirectory(**kwargs):
    ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
    domains = ad.get_domains()
    for d in domains:
        workgroup = d['nETBIOSName']

        print "w: %s" % workgroup 

        ucache = FreeNAS_UserCache(dir=workgroup)
        if ucache:
            for key in ucache.keys():
                print "u: %s=%s" % (key, ucache[key])

        gcache = FreeNAS_GroupCache(dir=workgroup)
        if gcache:
            for key in gcache.keys():
                print "g: %s=%s" % (key, gcache[key])

        ducache = FreeNAS_Directory_UserCache(dir=workgroup)
        if ducache:
            for key in ducache.keys():
                print "du: %s=%s" % (key, ducache[key])

        dgcache = FreeNAS_Directory_GroupCache(dir=workgroup)
        if dgcache:
            for key in dgcache.keys():
                print "dg: %s=%s" % (key, dgcache[key])
开发者ID:PatriQ7,项目名称:freenas,代码行数:27,代码来源:cachetool.py

示例5: _cache_count_ActiveDirectory

def _cache_count_ActiveDirectory(**kwargs):
    ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
    domains = ad.get_domains()
    for d in domains:
        workgroup = d['nETBIOSName']

        print "w:  %s" % workgroup
        print "u:  %ld" % _cachelen(FreeNAS_UserCache(dir=workgroup))
        print "g:  %ld" % _cachelen(FreeNAS_GroupCache(dir=workgroup))
        print "du: %ld" % _cachelen(FreeNAS_Directory_UserCache(dir=workgroup))
        print "dg: %ld" % _cachelen(FreeNAS_Directory_GroupCache(dir=workgroup))
        print "\n"
开发者ID:PatriQ7,项目名称:freenas,代码行数:12,代码来源:cachetool.py

示例6: ActiveDirectory

class ActiveDirectory(TestObject):
    def __init__(self, handler=None):
        super(self.__class__, self).__init__(handler)
        self._name = "ActiveDirectory"
        self.freenas_ad = None

    def Enabled(self):
        return activedirectory_enabled()

    def Test(self):
        try:
            self.freenas_ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
            if self.freenas_ad.connected():
                return self._handler.Pass("ActiveDirectory")
            else:
                return self._handler.Fail("ActiveDirectory", "Unable to login to the Domain Controller.")
        except LDAPError as e:
            # LDAPError is dumb, it returns a list with one element for goodness knows what reason
            e = e[0]
            error = "" 
            if 'desc' in e:
                error = e['desc']
                if 'info' in e:
                    error = "{0}, {1}".format(error, e['info'])
            else:
                # LDAPError may have desc and info or just info so making a case that handles just info
                if 'info' in e:
                    error = e['info']
                else:
                    error = str(e)
            return self._handler.Fail("ActiveDirectory", error)
        except Exception as e:
            return self._handler.Fail("ActiveDirectory", str(e))
开发者ID:toastcomputer,项目名称:freenas,代码行数:33,代码来源:ActiveDirectory.py

示例7: clean_ad_gcname

    def clean_ad_gcname(self):
        ad_gcname = self.cleaned_data.get('ad_gcname')
        ad_gcport = self.get_gcport()

        if not ad_gcname:
            return None

        parts = ad_gcname.split(':')
        ad_gcname = parts[0]

        errors = []
        try:
            ret = FreeNAS_ActiveDirectory.port_is_listening(
                host=ad_gcname, port=ad_gcport, errors=errors
            )

            if ret is False:
                raise Exception(
                    'Invalid Host/Port: %s' % errors[0]
                )

        except Exception as e:
            raise forms.ValidationError('%s.' % e)

        return self.cleaned_data.get('ad_gcname')
开发者ID:binzyw,项目名称:freenas,代码行数:25,代码来源:forms.py

示例8: clean_ad_gcname

    def clean_ad_gcname(self):
        ad_gcname = self.cleaned_data.get('ad_gcname')
        ad_gcport = 3268

        ad_ssl = self.cleaned_data.get('ad_ssl')
        if ad_ssl == 'on':
            ad_gcport = 3269

        if not ad_gcname:
            return None

        parts = ad_gcname.split(':')
        ad_gcname = parts[0]
        if len(parts) > 1 and parts[1].isdigit():
            ad_gcport = long(parts[1])

        errors = []
        try:
            ret = FreeNAS_ActiveDirectory.port_is_listening(
                host=ad_gcname, port=ad_gcport, errors=errors)

            if ret is False:
                raise Exception('Invalid Host/Port: %s' % errors[0])

        except Exception as e:
            raise forms.ValidationError('%s.' % e)

        return self.cleaned_data.get('ad_gcname')
开发者ID:vanloswang,项目名称:freenas,代码行数:28,代码来源:forms.py

示例9: Test

    def Test(self):
        try:
            self.freenas_ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
            if self.freenas_ad.connected():
                return self._handler.Pass("ActiveDirectory")
            else:
                return self._handler.Fail("ActiveDirectory", "Unable to login to the Domain Controller.")
        except LDAPError as e:
            # LDAPError is dumb, it returns a list with one element for goodness knows what reason
            e = e[0]
            error = []
            desc = e.get('desc')
            info = e.get('info')
            if desc:
                error.append(desc)
            if info:
                error.append(info)

            if error:
                error = ', '.join(error)
            else:
                error = str(e)

            return self._handler.Fail("ActiveDirectory", error)
        except Exception as e:
            return self._handler.Fail("ActiveDirectory", str(e))
开发者ID:GitVendor,项目名称:freenas,代码行数:26,代码来源:ActiveDirectory.py

示例10: Test

 def Test(self):
     try:
         self.freenas_ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
         if self.freenas_ad.connected():
             return self._handler.Pass("ActiveDirectory")
         else:
             return self._handler.Fail("ActiveDirectory", "Unable to login to the Domain Controller.")
     except Exception as e:
         return self._handler.Fail("ActiveDirectory", str(e))
开发者ID:elovelan,项目名称:freenas,代码行数:9,代码来源:ActiveDirectory.py

示例11: clean

    def clean(self):
        cdata = self.cleaned_data
        domain = cdata.get("ad_domainname")
        bindname = cdata.get("ad_bindname")
        bindpw = cdata.get("ad_bindpw")
        site = cdata.get("ad_site")
        netbiosname = cdata.get("ad_netbiosname")
        netbiosname_b = cdata.get("ad_netbiosname_b")
        ssl = cdata.get("ad_ssl")
        certificate = cdata["ad_certificate"]
        ad_kerberos_principal = cdata["ad_kerberos_principal"]
        workgroup = None

        if certificate:
            certificate = certificate.get_certificate_path()

        args = {
            'domain': domain,
            'site': site,
            'ssl': ssl,
            'certfile': certificate
        }

        if not ad_kerberos_principal:
            if not cdata.get("ad_bindpw"):
                cdata['ad_bindpw'] = self.instance.ad_bindpw

            if not bindname:
                raise forms.ValidationError("No domain account name specified")
            if not bindpw:
                raise forms.ValidationError(
                    "No domain account password specified")

            binddn = "%[email protected]%s" % (bindname, domain)
            errors = []

            try:
                ret = FreeNAS_ActiveDirectory.validate_credentials(
                    domain,
                    site=site,
                    ssl=ssl,
                    certfile=certificate,
                    binddn=binddn,
                    bindpw=bindpw,
                    errors=errors)
                if ret is False:
                    raise forms.ValidationError("%s." % errors[0])
            except FreeNAS_ActiveDirectory_Exception, e:
                raise forms.ValidationError('%s.' % e)

            args['binddn'] = binddn
            args['bindpw'] = bindpw
开发者ID:vanloswang,项目名称:freenas,代码行数:52,代码来源:forms.py

示例12: ActiveDirectory

class ActiveDirectory(TestObject):
    def __init__(self, handler=None):
        super(self.__class__, self).__init__(handler)
        self._name = "ActiveDirectory"
        self.freenas_ad = None

    def Enabled(self):
        return activedirectory_enabled()

    def Test(self):
        try:
            self.freenas_ad = FreeNAS_ActiveDirectory(flags=FLAGS_DBINIT)
            if self.freenas_ad.connected():
                return self._handler.Pass("ActiveDirectory")
            else:
                return self._handler.Fail("ActiveDirectory", "Unable to login to the Domain Controller.")
        except Exception as e:
            return self._handler.Fail("ActiveDirectory", str(e))
开发者ID:elovelan,项目名称:freenas,代码行数:18,代码来源:ActiveDirectory.py

示例13: clean

    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ad_bindpw"):
            cdata['ad_bindpw'] = self.instance.ad_bindpw

        if self.instance.ad_use_keytab is False:
            bindname = cdata.get("ad_bindname")
            bindpw = cdata.get("ad_bindpw")
            domain = cdata.get("ad_domainname")
            binddn = "%[email protected]%s" % (bindname, domain)
            errors = []

            ret = FreeNAS_ActiveDirectory.validate_credentials(
                domain, binddn=binddn, bindpw=bindpw, errors=errors
            )
            if ret is False:
                raise forms.ValidationError("%s." % errors[0])

        return cdata
开发者ID:dlrik,项目名称:freenas,代码行数:19,代码来源:forms.py

示例14: clean

    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ad_bindpw"):
            cdata['ad_bindpw'] = self.instance.ad_bindpw

        if not self.instance.ad_kerberos_keytab:
            bindname = cdata.get("ad_bindname")
            bindpw = cdata.get("ad_bindpw")
            domain = cdata.get("ad_domainname")
            binddn = "%[email protected]%s" % (bindname, domain)
            errors = []

            try:
                ret = FreeNAS_ActiveDirectory.validate_credentials(
                    domain, binddn=binddn, bindpw=bindpw, errors=errors
                )
                if ret is False:
                    raise forms.ValidationError("%s." % errors[0])
            except FreeNAS_ActiveDirectory_Exception, e:
                raise forms.ValidationError('%s.' % e)
开发者ID:anilh889,项目名称:freenas,代码行数:20,代码来源:forms.py

示例15: clean

    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ad_bindpw"):
            cdata['ad_bindpw'] = self.instance.ad_bindpw

        if self.instance.ad_use_keytab == False:
            bindname = cdata.get("ad_bindname")
            bindpw = cdata.get("ad_bindpw")
            domain = cdata.get("ad_domainname")
            binddn = "%[email protected]%s" % (bindname, domain)

            ret = FreeNAS_ActiveDirectory.validate_credentials(
                domain, binddn=binddn, bindpw=bindpw
            )
            if ret == False:
                raise forms.ValidationError(
                    _("Incorrect password.")
                )

        return cdata
开发者ID:PatriQ7,项目名称:freenas,代码行数:20,代码来源:forms.py


注:本文中的freenasUI.common.freenasldap.FreeNAS_ActiveDirectory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。