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.

replicaInfo.py 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """
  2. """
  3. # Created on 2014.08.07
  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. from datetime import datetime
  25. from pyasn1.type.univ import Integer
  26. from ...core.exceptions import LDAPExtensionError
  27. from ...protocol.novell import LDAPDN, ReplicaInfoRequestValue
  28. from ..operation import ExtendedOperation
  29. from ...utils.asn1 import decoder
  30. from ...utils.dn import safe_dn
  31. class ReplicaInfo(ExtendedOperation):
  32. def config(self):
  33. self.request_name = '2.16.840.1.113719.1.27.100.17'
  34. self.response_name = '2.16.840.1.113719.1.27.100.18'
  35. # self.asn1_spec = ReplicaInfoResponseValue()
  36. self.request_value = ReplicaInfoRequestValue()
  37. self.response_attribute = 'partition_dn'
  38. def __init__(self, connection, server_dn, partition_dn, controls=None):
  39. if connection.check_names:
  40. if server_dn:
  41. server_dn = safe_dn(server_dn)
  42. if partition_dn:
  43. partition_dn = safe_dn(partition_dn)
  44. ExtendedOperation.__init__(self, connection, controls) # calls super __init__()
  45. self.request_value['server_dn'] = server_dn
  46. self.request_value['partition_dn'] = partition_dn
  47. def populate_result(self):
  48. substrate = self.decoded_response
  49. try:
  50. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  51. self.result['partition_id'] = int(decoded)
  52. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  53. self.result['replica_state'] = int(decoded)
  54. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  55. self.result['modification_time'] = datetime.utcfromtimestamp(int(decoded))
  56. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  57. self.result['purge_time'] = datetime.utcfromtimestamp(int(decoded))
  58. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  59. self.result['local_partition_id'] = int(decoded)
  60. decoded, substrate = decoder.decode(substrate, asn1Spec=LDAPDN())
  61. self.result['partition_dn'] = str(decoded)
  62. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  63. self.result['replica_type'] = int(decoded)
  64. decoded, substrate = decoder.decode(substrate, asn1Spec=Integer())
  65. self.result['flags'] = int(decoded)
  66. except Exception:
  67. raise LDAPExtensionError('unable to decode substrate')
  68. if substrate:
  69. raise LDAPExtensionError('unknown substrate remaining')