Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plain.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. """
  3. # Created on 2014.01.04
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2014 - 2018 Giovanni Cannata
  8. #
  9. # This file is part of ldap3.
  10. #
  11. # ldap3 is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU Lesser General Public License as published
  13. # by the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # ldap3 is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Lesser General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Lesser General Public License
  22. # along with ldap3 in the COPYING and COPYING.LESSER files.
  23. # If not, see <http://www.gnu.org/licenses/>.
  24. # payload for PLAIN mechanism
  25. # message = [authzid] UTF8NUL authcid UTF8NUL passwd
  26. # authcid = 1*SAFE ; MUST accept up to 255 octets
  27. # authzid = 1*SAFE ; MUST accept up to 255 octets
  28. # passwd = 1*SAFE ; MUST accept up to 255 octets
  29. # UTF8NUL = %x00 ; UTF-8 encoded NUL character
  30. #
  31. # SAFE = UTF1 / UTF2 / UTF3 / UTF4
  32. # ;; any UTF-8 encoded Unicode character except NUL
  33. #
  34. # UTF1 = %x01-7F ;; except NUL
  35. # UTF2 = %xC2-DF UTF0
  36. # UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC 2(UTF0) /
  37. # %xED %x80-9F UTF0 / %xEE-EF 2(UTF0)
  38. # UTF4 = %xF0 %x90-BF 2(UTF0) / %xF1-F3 3(UTF0) /
  39. # %xF4 %x80-8F 2(UTF0)
  40. # UTF0 = %x80-BF
  41. from ...protocol.sasl.sasl import send_sasl_negotiation
  42. from .sasl import sasl_prep
  43. from ...utils.conv import to_raw, to_unicode
  44. def sasl_plain(connection, controls):
  45. authzid = connection.sasl_credentials[0]
  46. authcid = connection.sasl_credentials[1]
  47. passwd = connection.sasl_credentials[2]
  48. payload = b''
  49. if authzid:
  50. payload += to_raw(sasl_prep(to_unicode(authzid)))
  51. payload += b'\0'
  52. if authcid:
  53. payload += to_raw(sasl_prep(to_unicode(authcid)))
  54. payload += b'\0'
  55. if passwd:
  56. payload += to_raw(sasl_prep(to_unicode(passwd)))
  57. result = send_sasl_negotiation(connection, controls, payload)
  58. return result