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.

modifyDn.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. """
  3. # Created on 2013.05.31
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2013 - 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. from ..protocol.rfc4511 import ModifyDNRequest, LDAPDN, RelativeLDAPDN, DeleteOldRDN, NewSuperior, ResultCode
  25. from ..operation.bind import referrals_to_list
  26. # ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
  27. # entry LDAPDN,
  28. # newrdn RelativeLDAPDN,
  29. # deleteoldrdn BOOLEAN,
  30. # newSuperior [0] LDAPDN OPTIONAL }
  31. def modify_dn_operation(dn,
  32. new_relative_dn,
  33. delete_old_rdn=True,
  34. new_superior=None):
  35. request = ModifyDNRequest()
  36. request['entry'] = LDAPDN(dn)
  37. request['newrdn'] = RelativeLDAPDN(new_relative_dn)
  38. request['deleteoldrdn'] = DeleteOldRDN(delete_old_rdn)
  39. if new_superior:
  40. request['newSuperior'] = NewSuperior(new_superior)
  41. return request
  42. def modify_dn_request_to_dict(request):
  43. return {'entry': str(request['entry']),
  44. 'newRdn': str(request['newrdn']),
  45. 'deleteOldRdn': bool(request['deleteoldrdn']),
  46. 'newSuperior': str(request['newSuperior']) if request['newSuperior'] is not None and request['newSuperior'].hasValue() else None}
  47. def modify_dn_response_to_dict(response):
  48. return {'result': int(response['resultCode']),
  49. 'description': ResultCode().getNamedValues().getName(response['resultCode']),
  50. 'dn': str(response['matchedDN']),
  51. 'referrals': referrals_to_list(response['referral']),
  52. 'message': str(response['diagnosticMessage'])}