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.

microsoft.py 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. """
  2. """
  3. # Created on 2015.03.27
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2015 - 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. import ctypes
  25. from pyasn1.type.namedtype import NamedTypes, NamedType
  26. from pyasn1.type.tag import Tag, tagClassApplication, tagFormatConstructed
  27. from pyasn1.type.univ import Sequence, OctetString, Integer
  28. from .rfc4511 import ResultCode, LDAPString
  29. from .controls import build_control
  30. class SicilyBindResponse(Sequence):
  31. # SicilyBindResponse ::= [APPLICATION 1] SEQUENCE {
  32. #
  33. # resultCode ENUMERATED {
  34. # success (0),
  35. # protocolError (2),
  36. # adminLimitExceeded (11),
  37. # inappropriateAuthentication (48),
  38. # invalidCredentials (49),
  39. # busy (51),
  40. # unavailable (52),
  41. # unwillingToPerform (53),
  42. # other (80) },
  43. #
  44. # serverCreds OCTET STRING,
  45. # errorMessage LDAPString }
  46. # BindResponse ::= [APPLICATION 1] SEQUENCE {
  47. # COMPONENTS OF LDAPResult,
  48. # serverSaslCreds [7] OCTET STRING OPTIONAL }
  49. tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassApplication, tagFormatConstructed, 1))
  50. componentType = NamedTypes(NamedType('resultCode', ResultCode()),
  51. NamedType('serverCreds', OctetString()),
  52. NamedType('errorMessage', LDAPString())
  53. )
  54. class DirSyncControlRequestValue(Sequence):
  55. # DirSyncRequestValue ::= SEQUENCE {
  56. # Flags integer
  57. # MaxBytes integer
  58. # Cookie OCTET STRING }
  59. componentType = NamedTypes(NamedType('Flags', Integer()),
  60. NamedType('MaxBytes', Integer()),
  61. NamedType('Cookie', OctetString())
  62. )
  63. class DirSyncControlResponseValue(Sequence):
  64. # DirSyncResponseValue ::= SEQUENCE {
  65. # MoreResults INTEGER
  66. # unused INTEGER
  67. # CookieServer OCTET STRING
  68. # }
  69. componentType = NamedTypes(NamedType('MoreResults', Integer()),
  70. NamedType('unused', Integer()),
  71. NamedType('CookieServer', OctetString())
  72. )
  73. class SdFlags(Sequence):
  74. # SDFlagsRequestValue ::= SEQUENCE {
  75. # Flags INTEGER
  76. # }
  77. componentType = NamedTypes(NamedType('Flags', Integer())
  78. )
  79. class ExtendedDN(Sequence):
  80. # A flag value 0 specifies that the GUID and SID values be returned in hexadecimal string
  81. # A flag value of 1 will return the GUID and SID values in standard string format
  82. componentType = NamedTypes(NamedType('option', Integer())
  83. )
  84. def dir_sync_control(criticality, object_security, ancestors_first, public_data_only, incremental_values, max_length, cookie):
  85. control_value = DirSyncControlRequestValue()
  86. flags = 0x0
  87. if object_security:
  88. flags |= 0x00000001
  89. if ancestors_first:
  90. flags |= 0x00000800
  91. if public_data_only:
  92. flags |= 0x00002000
  93. if incremental_values:
  94. flags |= 0x80000000
  95. # converts flags to signed 32 bit (AD expects a 4 bytes long unsigned integer, but ASN.1 Integer type is signed
  96. # so the BER encoder gives back a 5 bytes long signed integer
  97. flags = ctypes.c_long(flags & 0xFFFFFFFF).value
  98. control_value.setComponentByName('Flags', flags)
  99. control_value.setComponentByName('MaxBytes', max_length)
  100. if cookie:
  101. control_value.setComponentByName('Cookie', cookie)
  102. else:
  103. control_value.setComponentByName('Cookie', OctetString(''))
  104. return build_control('1.2.840.113556.1.4.841', criticality, control_value)
  105. def extended_dn_control(criticality=False, hex_format=False):
  106. control_value = ExtendedDN()
  107. control_value.setComponentByName('option', Integer(not hex_format))
  108. return build_control('1.2.840.113556.1.4.529', criticality, control_value)
  109. def show_deleted_control(criticality=False):
  110. return build_control('1.2.840.113556.1.4.417', criticality, value=None)
  111. def security_descriptor_control(criticality=False, sdflags=0x0F):
  112. sdcontrol = SdFlags()
  113. sdcontrol.setComponentByName('Flags', sdflags)
  114. return [build_control('1.2.840.113556.1.4.801', criticality, sdcontrol)]