home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / Exchange / Security / Security.bas next >
Encoding:
BASIC Source File  |  1999-03-12  |  2.9 KB  |  106 lines

  1. Attribute VB_Name = "Security"
  2. Public Const RIGHT_DS_ADD_CHILD = &H1
  3. Public Const RIGHT_DS_MODIFY_USER_ATT = &H2
  4. Public Const RIGHT_DS_MODIFY_ADMIN_ATT = &H4
  5. Public Const RIGHT_DS_DELETE = &H10000
  6. Public Const RIGHT_MAIL_SEND_AS = &H8
  7. Public Const RIGHT_MAIL_RECEIVE_AS = &H10
  8. Public Const RIGHT_MAIL_ADMIN_AS = &H20
  9. Public Const RIGHT_DS_REPLICATION = &H40
  10. Public Const RIGHT_DS_MODIFY_SEC_ATT = &H80
  11. Public Const RIGHT_DS_SEARCH = &H100
  12.  
  13.  
  14. Sub Main()
  15.  
  16.  
  17. 'Sample reading and modifying Exchange Security Descriptor Attribute in Exchange 5.5/ADSI 2.5:
  18.  
  19. Dim propVal As IADsPropertyValue2
  20. Dim sd As IADsSecurityDescriptor
  21. Dim dacl As IADsAccessControlList
  22. Dim ace As IADsAccessControlEntry
  23. Dim o As IADs
  24. Dim srv
  25.  
  26. srv = "andyhar04"
  27. mailbox = "cn=andyhar"
  28. Site = "ou=Redmond"
  29. Org = "o=Microsoft"
  30.  
  31.  
  32. '--- Binding------
  33. ADsPath = "LDAP://" & srv & "/" & mailbox & ",cn=Recipients," & Site & "," & Org
  34. Set o = GetObject(ADsPath)
  35.  
  36.  
  37.  
  38. '-- Get NT Security Descriptor as a raw binary security descriptor
  39. o.GetInfoEx Array("NT-Security-Descriptor;binary"), 0
  40. v = o.Get("NT-Security-Descriptor")
  41.  
  42. '--- Convert from Raw Security Descriptor to IADsSecurityDescriptor
  43. Set propVal = CreateObject("PropertyValue")
  44. propVal.PutObjectProperty ADSTYPE_OCTET_STRING, v
  45. Set sd = propVal.GetObjectProperty(ADSTYPE_NT_SECURITY_DESCRIPTOR)
  46.  
  47. '--- Enumerate ACE in DACL
  48. Set dacl = sd.DiscretionaryAcl
  49.  
  50. For Each ace In dacl
  51.  
  52.    '--- TRUSTEE----
  53.    perm = ace.Trustee
  54.    
  55.    '----ACE TYPE-----
  56.    If (ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED) Then
  57.       perm = perm & " is allowed to "
  58.    ElseIf (ace.Type = ADS_ACETYPE_ACCESS_DENIED) Then
  59.       perm = perm & " is denied to:"
  60.    End If
  61.    
  62.    '--- ACE MASK ------
  63.    If (ace.AccessMask And RIGHT_MAIL_SEND_AS) Then
  64.       perm = perm & " -send mail"
  65.    End If
  66.    
  67.    If (ace.AccessMask And RIGHT_MAIL_RECEIVE_AS) Then
  68.        perm = perm & " -receive mail as"
  69.    End If
  70.    
  71.    If (ace.AccessMask And RIGHT_DS_MODIFY_USER_ATT) Then
  72.        perm = perm & " -modify user attributes"
  73.    End If
  74.    
  75.    If (ace.AccessMask And RIGHT_DS_MODIFY_ADMIN_ATT) Then
  76.        perm = perm & " -modify admin attributes"
  77.    End If
  78.    
  79.    If (ace.AccessMask & RIGHT_DS_DELETE) Then
  80.      perm = perm & " -delete this object"
  81.    End If
  82.    
  83.    Debug.Print perm
  84.    
  85. Next
  86.  
  87. '---- You can also add a new ace, and add it to DACL
  88. Set ace = CreateObject("AccessControlEntry")
  89. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED  ' Allow permission
  90. ace.AccessMask = RIGHT_MAIL_SEND_AS Or RIGHT_DS_MODIFY_USER_ATT Or RIGHT_DS_MODIFY_ADMIN_ATT Or RIGHT_DS_DELETE
  91. ace.Trustee = "NTDEV\Administrator"
  92. dacl.AddAce ace
  93. sd.DiscretionaryAcl = dacl
  94.  
  95. '--- Now you have to convert back to the Raw Security Descriptor
  96. propVal.PutObjectProperty ADSTYPE_NT_SECURITY_DESCRIPTOR, sd
  97. v = propVal.GetObjectProperty(ADSTYPE_OCTET_STRING)
  98.  
  99. '-- Commit to the Directory
  100. o.Put "NT-Security-Descriptor;binary", v
  101. o.SetInfo
  102.  
  103.  
  104.  
  105. End Sub
  106.