def clean(self): cdata = self.cleaned_data site = cdata.get("ad_site") ssl = cdata.get("ad_ssl") certificate = cdata["ad_certificate"] if certificate: certificate = certificate.get_certificate_path() 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 = "%s@%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)
def clean(self): cdata = self.cleaned_data domain = cdata.get("ad_domainname") bindname = cdata.get("ad_bindname") binddn = "%s@%s" % (bindname, domain) bindpw = cdata.get("ad_bindpw") site = cdata.get("ad_site") netbiosname = cdata.get("ad_netbiosname_a") 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 cdata.get("ad_bindpw"): bindpw = self.instance.ad_bindpw cdata['ad_bindpw'] = bindpw if not ad_kerberos_principal: if not bindname: raise forms.ValidationError("No domain account name specified") if not bindpw: raise forms.ValidationError( "No domain account password specified") 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
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 = "%s@%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
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 = "%s@%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)
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 = "%s@%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
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 = "%s@%s" % (bindname, domain) ret = FreeNAS_ActiveDirectory.validate_credentials( domain, binddn=binddn, bindpw=bindpw ) if ret == False: raise forms.ValidationError( _("Incorrect password.") ) return cdata
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 = "%s@%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)
def clean(self): cdata = self.cleaned_data domain = cdata.get("ad_domainname") bindname = cdata.get("ad_bindname") binddn = "%s@%s" % (bindname, domain) bindpw = cdata.get("ad_bindpw") site = cdata.get("ad_site") netbiosname = cdata.get("ad_netbiosname_a") 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 cdata.get("ad_bindpw"): bindpw = self.instance.ad_bindpw cdata['ad_bindpw'] = bindpw if cdata.get("ad_enable") is False: return cdata if not ad_kerberos_principal: if not bindname: raise forms.ValidationError("No domain account name specified") if not bindpw: raise forms.ValidationError("No domain account password specified") try: FreeNAS_ActiveDirectory.validate_credentials( domain, site=site, ssl=ssl, certfile=certificate, binddn=binddn, bindpw=bindpw ) 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) raise forms.ValidationError("{0}".format(error)) except Exception as e: raise forms.ValidationError('{0}.'.format(str(e))) args['binddn'] = binddn args['bindpw'] = bindpw else: args['keytab_principal'] = ad_kerberos_principal.principal_name args['keytab_file'] = '/etc/krb5.keytab' try: workgroup = FreeNAS_ActiveDirectory.get_workgroup_name(**args) except Exception as e: raise forms.ValidationError(e) if workgroup: if compare_netbios_names(netbiosname, workgroup, None): raise forms.ValidationError(_( "The NetBIOS name cannot be the same as the workgroup name!" )) if netbiosname_b: if compare_netbios_names(netbiosname_b, workgroup, None): raise forms.ValidationError(_( "The NetBIOS name cannot be the same as the workgroup " "name!" )) else: log.warn("Unable to determine workgroup name") if ssl in ("off", None): return cdata if not certificate: raise forms.ValidationError( "SSL/TLS specified without certificate") return cdata
def clean(self): cdata = self.cleaned_data domain = cdata.get("ad_domainname") bindname = cdata.get("ad_bindname") binddn = "%s@%s" % (bindname, domain) bindpw = cdata.get("ad_bindpw") site = cdata.get("ad_site") netbiosname = cdata.get("ad_netbiosname_a") 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 cdata.get("ad_bindpw"): bindpw = self.instance.ad_bindpw cdata['ad_bindpw'] = bindpw if cdata.get("ad_enable") is False: return cdata if not ad_kerberos_principal: if not bindname: raise forms.ValidationError("No domain account name specified") if not bindpw: raise forms.ValidationError( "No domain account password specified") try: FreeNAS_ActiveDirectory.validate_credentials( domain, site=site, ssl=ssl, certfile=certificate, binddn=binddn, bindpw=bindpw) 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) raise forms.ValidationError("{0}".format(error)) except Exception as e: raise forms.ValidationError('{0}.'.format(str(e))) args['binddn'] = binddn args['bindpw'] = bindpw else: args['keytab_principal'] = ad_kerberos_principal.principal_name args['keytab_file'] = '/etc/krb5.keytab' try: workgroup = FreeNAS_ActiveDirectory.get_workgroup_name(**args) except Exception as e: raise forms.ValidationError(e) if workgroup: if compare_netbios_names(netbiosname, workgroup, None): raise forms.ValidationError( _("The NetBIOS name cannot be the same as the workgroup name!" )) if netbiosname_b: if compare_netbios_names(netbiosname_b, workgroup, None): raise forms.ValidationError( _("The NetBIOS name cannot be the same as the workgroup " "name!")) else: log.warn("Unable to determine workgroup name") if ssl in ("off", None): return cdata if not certificate: raise forms.ValidationError( "SSL/TLS specified without certificate") return cdata
def clean(self): cdata = self.cleaned_data domain = cdata.get("ad_domainname") bindname = cdata.get("ad_bindname") binddn = "%s@%s" % (bindname, domain) bindpw = cdata.get("ad_bindpw") site = cdata.get("ad_site") netbiosname = cdata.get("ad_netbiosname_a") 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: with client as c: certificate = c.call('certificateauthority.query', [['id', '=', certificate.id]], {'get': True}) certificate = certificate['certificate_path'] args = { 'domain': domain, 'site': site, 'ssl': ssl, 'certfile': certificate } if not cdata.get("ad_bindpw"): bindpw = self.instance.ad_bindpw cdata['ad_bindpw'] = bindpw if cdata.get("ad_enable") is False: return cdata if not ad_kerberos_principal: if not bindname: raise forms.ValidationError("No domain account name specified") if not bindpw: raise forms.ValidationError( "No domain account password specified") try: FreeNAS_ActiveDirectory.validate_credentials( domain, site=site, ssl=ssl, certfile=certificate, binddn=binddn, bindpw=bindpw) except LDAPError as e: log.debug("LDAPError: type = %s", type(e)) error = [] try: error.append(e.args[0]['info']) error.append(e.args[0]['desc']) error = ', '.join(error) except Exception as e: error = str(e) raise forms.ValidationError("{0}".format(error)) except Exception as e: log.debug("Exception: type = %s", type(e)) raise forms.ValidationError('{0}.'.format(str(e))) args['binddn'] = binddn args['bindpw'] = bindpw else: args['keytab_principal'] = ad_kerberos_principal.principal_name args['keytab_file'] = '/etc/krb5.keytab' try: workgroup = FreeNAS_ActiveDirectory.get_workgroup_name(**args) except Exception as e: raise forms.ValidationError(e) if workgroup: if compare_netbios_names(netbiosname, workgroup, None): raise forms.ValidationError( _("The NetBIOS name cannot be the same as the workgroup name!" )) if netbiosname_b: if compare_netbios_names(netbiosname_b, workgroup, None): raise forms.ValidationError( _("The NetBIOS name cannot be the same as the workgroup " "name!")) else: log.warn("Unable to determine workgroup name") if ssl in ("off", None): return cdata if not certificate: raise forms.ValidationError( "SSL/TLS specified without certificate") return cdata