Copy ACLs Between DBs

This DB allows for copying the ACL from one database to another, including all roles and role assignments for entries. This code prompts for the name of a local database for both saource and destination.

It can easily be modified to remove any entries in the Destination DB that doesn't appear in the Source, as well as changing it to run on servers etc.


Option Declare

Sub Initialize
'This Agent will refresh the design on all specified databases and verify the ACL is configured correctly.
Dim SrcDB As NotesDatabase
Dim DestDB As NotesDatabase
Dim SrcDBName As String
Dim DestDBName As String
Dim Done As Variant

'Perform Update
Done = False
While Not Done
SrcDBName = Inputbox("Enter the Source DB path and filename", "Source DB")
If SrcDBName = "" Then Done = True
If Not(Done) Then
DestDBName = Inputbox("Enter Destination DB Path and filename","Destination DB")
If DestDBName = "" Then Done = True
If Not(Done) Then
Set SrcDB = New NotesDatabase("",SrcDBName)
Set DestDB = New NotesDatabase("",DestDBName)
If SrcDB.Title = "" Or DestDB.Title = "" Then
Messagebox "Could not get one of the DBs"
Else
Call ConfirmACL(SrcDB,DestDB)
End If
End If
End If
Wend

End Sub
Sub ConfirmACL(SrcDB As NotesDatabase, DestDB As NotesDatabase)
Dim SrcACL As NotesACL
Dim DestACL As NotesACL
Dim Entry As NotesACLEntry
Dim NEntry As NotesACLEntry
Dim Roles As Variant
Dim TRoles As Variant
Dim Found As Variant
Dim I, J As Integer

Set SrcACL = SrcDB.ACL
Set DestACL = DestDB.ACL

Call SyncACLRoles(SrcACL,DestACL)

Set Entry = SrcACL.GetFirstEntry
While Not(Entry Is Nothing)
Set NEntry = DestACL.CreateACLEntry(Entry.Name, Entry.Level)
NEntry.CanCreateDocuments = Entry.CanCreateDocuments
NEntry.CanCreatePersonalAgent = Entry.CanCreatePersonalAgent
NEntry.CanCreatePersonalFolder = Entry.CanCreatePersonalFolder
NEntry.CanDeleteDocuments = Entry.CanDeleteDocuments
NEntry.IsPublicReader = Entry.IsPublicReader
NEntry.IsPublicWriter = Entry.IsPublicWriter
Call SyncEntryRoles(NEntry, Entry, DestACL)

Set Entry = SrcACL.GetNextEntry(Entry)
Wend

Call DestACL.Save

End Sub
Sub SyncACLRoles(SrcACL As NotesACL, DestACL As NotesACL)
Dim Roles As Variant
Dim TRoles As Variant
Dim Found As Variant
Dim i, j As Integer

Roles = DestACL.Roles
TRoles = SrcACL.Roles

For i = 0 To Ubound(TRoles)
If TRoles(i) <> "" Then
Found = False
For j = 0 To Ubound(Roles)
If Roles(j) <> "" Then
If TRoles(i) = Roles(j) Then
found = True
Exit For
End If
End If
Next j
If Not(Found) Then
Call DestACL.AddRole(Mid(TRoles(i),2,Len(TRoles(i))-2))
End If
End If
Next i

Call DestACL.Save

End Sub
Sub SyncEntryRoles(NEntry As NotesACLEntry, Entry As NotesACLEntry, ACL As NotesACL)
Dim ACLRoles As Variant
Dim TRoles As Variant
Dim i, j As Integer

ACLRoles = ACL.Roles
TRoles = Entry.Roles

For i = 0 To Ubound(ACLRoles)
If ACLRoles(i) <> "" Then
For j = 0 To Ubound(TRoles)
If TRoles(j) <> "" Then
If ACLRoles(i) = TRoles(j) Then
Call
NEntry.EnableRole(Mid(ACLRoles(i),2,Len(ACLRoles(i))-2))
Exit For
Else
Call
NEntry.DisableRole(Mid(ACLRoles(i),2,Len(ACLRoles(i))-2))
End If
End

This was first published in November 2000
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close