def clean(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") ssl = cdata.get("ldap_ssl") certfile = None if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] if not certificate: raise forms.ValidationError( "SSL/TLS specified without certificate") else: certfile = get_certificateauthority_path(certificate) port = 389 if ssl == "on": port = 636 if hostname: parts = hostname.split(':') hostname = parts[0] if len(parts) > 1: port = int(parts[1]) if cdata.get("ldap_enable") is False: return cdata # self.check_for_samba_schema() try: FreeNAS_LDAP.validate_credentials(hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, port=port, certfile=certfile, ssl=ssl) 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: error = str(e) raise forms.ValidationError("{0}".format(error)) except Exception as e: log.debug("LDAPError: type = %s", type(e)) raise forms.ValidationError("{0}".format(str(e))) return cdata
def clean(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") ssl = cdata.get("ldap_ssl") certfile = None if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] if not certificate: raise forms.ValidationError( "SSL/TLS specified without certificate") else: certfile = get_certificateauthority_path(certificate) port = 389 if ssl == "on": port = 636 if hostname: parts = hostname.split(':') hostname = parts[0] if len(parts) > 1: port = int(parts[1]) # self.check_for_samba_schema() try: FreeNAS_LDAP.validate_credentials(hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, port=port, certfile=certfile, ssl=ssl) 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))) return cdata
def clean_ldap_bindpw(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") ssl = cdata.get("ldap_ssl") port = 389 if ssl == "on": port = 636 if hostname: parts = hostname.split(':') hostname = parts[0] if len(parts) > 1: port = int(parts[1]) certfile = None if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] certfile = get_certificateauthority_path(certificate) try: FreeNAS_LDAP.validate_credentials( hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, port=port, certfile=certfile, ssl=ssl ) 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))) return bindpw
def clean_bindpw(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") errors = [] certfile = None ssl = cdata.get("ldap_ssl") if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] certfile = get_certificateauthority_path(certificate) ret = FreeNAS_LDAP.validate_credentials( hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, certfile=certfile, ssl=ssl, errors=errors) if ret is False: raise forms.ValidationError("%s." % errors[0])
def clean_bindpw(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") errors = [] certfile = None ssl = cdata.get("ldap_ssl") if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] certfile = get_certificateauthority_path(certificate) ret = FreeNAS_LDAP.validate_credentials(hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, certfile=certfile, ssl=ssl, errors=errors) if ret is False: raise forms.ValidationError("%s." % errors[0])
def clean_ldap_bindpw(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") ssl = cdata.get("ldap_ssl") port = 389 if ssl == "on": port = 636 if hostname: parts = hostname.split(':') hostname = parts[0] if len(parts) > 1: port = int(parts[1]) errors = [] certfile = None if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] certfile = get_certificateauthority_path(certificate) ret = FreeNAS_LDAP.validate_credentials( hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, port=port, certfile=certfile, ssl=ssl, errors=errors ) if ret is False: raise forms.ValidationError("%s." % errors[0]) return bindpw
def clean_bindpw(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") hostname = cdata.get("ldap_hostname") errors = [] ret = FreeNAS_LDAP.validate_credentials( hostname, binddn=binddn, bindpw=bindpw, errors=errors ) if ret is False: raise forms.ValidationError("%s." % errors[0])
def clean_bindpw(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") hostname = cdata.get("ldap_hostname") errors = [] ret = FreeNAS_LDAP.validate_credentials(hostname, binddn=binddn, bindpw=bindpw, errors=errors) if ret is False: raise forms.ValidationError("%s." % errors[0])
def clean(self): cdata = self.cleaned_data if not cdata.get("ldap_bindpw"): cdata["ldap_bindpw"] = self.instance.ldap_bindpw binddn = cdata.get("ldap_binddn") bindpw = cdata.get("ldap_bindpw") basedn = cdata.get("ldap_basedn") hostname = cdata.get("ldap_hostname") ssl = cdata.get("ldap_ssl") certfile = None if ssl in ('start_tls', 'on'): certificate = cdata["ldap_certificate"] if not certificate: raise forms.ValidationError( "SSL/TLS specified without certificate") else: certfile = get_certificateauthority_path(certificate) port = 389 if ssl == "on": port = 636 if hostname: parts = hostname.split(':') hostname = parts[0] if len(parts) > 1: port = int(parts[1]) if cdata.get("ldap_enable") is False: return cdata # self.check_for_samba_schema() try: FreeNAS_LDAP.validate_credentials( hostname, binddn=binddn, bindpw=bindpw, basedn=basedn, port=port, certfile=certfile, ssl=ssl ) 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: error = str(e) raise forms.ValidationError("{0}".format(error)) except Exception as e: log.debug("LDAPError: type = %s", type(e)) raise forms.ValidationError("{0}".format(str(e))) return cdata