29. oktober 2002 - 10:17Der er
20 kommentarer og 1 løsning
Udskrive tilladelser
Er det muligt (hvis ja, hvordan?) at udskrive noget a la de informationer man ser ved at klikke på Funktioner -> Sikkerhed -> Bruger- og Gruppetilladelser? Altså en form for "sikkerheds-matrix" over alle objekter i databasen. (nej, det er IKKE ok at tage et screendump for hver bruger/gruppe!) ;)
List Users in the system: Function faq_ListUsersInSystem () Dim ws As WorkSpace Dim i As Integer
Set ws = DBEngine.Workspaces(0) For i = 0 To ws.Users.count - 1 Debug.Print ws.Users(i).Name Next i End Function
List Groups in System: Function faq_ListGroupsInSystem () Dim ws As WorkSpace Dim i As Integer
Set ws = DBEngine.Workspaces(0) For i = 0 To ws.Groups.count - 1 Debug.Print ws.Groups(i).Name Next i End Function
List Members of Group: Function faq_ListUsersOfGroup (strGroupName As String) Dim ws As WorkSpace Dim grp As Group Dim i As Integer
Set ws = DBEngine.Workspaces(0) Set grp = ws.Groups(strGroupName) For i = 0 To grp.Users.count - 1 Debug.Print grp.Users(i).Name Next i End Function
List Groups User is a member of: Function faq_ListGroupsOfUser (strUserName As String) Dim ws As WorkSpace Dim usr As User Dim i As Integer
Set ws = DBEngine.Workspaces(0) Set usr = ws.Users(strUserName) For i = 0 To usr.Groups.count - 1 Debug.Print usr.Groups(i).Name Next i End Function
Determine if a User is in a given Group: Function faq_IsUserInGroup (strGroup As String, strUser as String) As Integer ' Returns True if user is in group, False otherwise ' This only works if you're a member of the Admins group. Dim ws As WorkSpace Dim grp As Group Dim strUserName as string
Set ws = DBEngine.Workspaces(0) Set grp = ws.Groups(strGroup) On Error Resume Next strUserName = ws.groups(strGroup).users(strUser).Name faq_IsUserInGroup = (Err = 0) End Function
Just one problem, this lists the users and which groups they belong to, NOT which rights they have to access/modify/delete all the different objects, such as tables, forms, reports and so on....
Well, it does contain some of the functionality, but no matter which form I open, I get an error and I can't get "behind" the form, to edit/see what's beneath..... :(
I downloaded the Access 2000 version, but "forgot" to RTFM!!! :( Well, now that it's up and running, I still have to say that it doesn't provide me with a report on user-rights on all objects........
No I can see that it doesnt give you a report. You are going to have to program this yourself! I have something which may be of use but you will have to wait until this evening. If I find something else I will get back
Sub ShowPermissionsAsText(strDbPath As String) ' This procedure prints the names of the constants representing the permissions ' for each user and group for all objects in the database. It calls ' the DecodePerms procedure, which returns a string containing the ' name of each constant. ' ' Arguments: ' strDbPath: The path to the database.
Dim wrk As Workspace, dbs As Database Dim usr As User, grp As Group Dim ctr As Container, doc As Document Dim intType As Integer
On Error Resume Next Set wrk = DBEngine.Workspaces(0) Set dbs = OpenDatabase(strDbPath)
For Each usr In wrk.Users Debug.Print "User: " & usr.Name Debug.Print "----------------------" For Each ctr In dbs.Containers Debug.Print " Container: " & ctr.Name Select Case ctr.Name Case "Tables": intType = 1 Case "Databases": intType = 2 Case Else: intType = -1 End Select For Each doc In ctr.Documents doc.UserName = usr.Name Debug.Print " Document: " & doc.Name Debug.Print " Permissions: " & _ DecodePerms(intType, doc.Permissions) Next doc Next ctr Next usr
For Each grp In wrk.Groups Debug.Print "Group: " & grp.Name Debug.Print "----------------------" For Each ctr In dbs.Containers Debug.Print " Container: " & ctr.Name Select Case ctr.Name Case "Tables": intType = 1 Case "Databases": intType = 2 Case Else: intType = -1 End Select For Each doc In ctr.Documents doc.UserName = grp.Name Debug.Print " Document: " & doc.Name Debug.Print " Permissions: " & _ DecodePerms(intType, doc.Permissions) Next doc Next ctr Next grp End Sub
' Section 4: Using DAO to Program Security Function DecodePerms(intType As Integer, lngPerms As Long) As String ' This procedure returns a string containing the names of all of ' the permissions for a particular user or group on a particular document. ' ' Arguments: ' intType: The integer value representing the type of container that contains ' the document. ' lngPerms: A long value indicating the setting of the Permissions property ' for a particular document and a particular user or group. ' ' Returns: ' A string that includes the names of the constants ' representing the permissions that a user or group has on a particular document.
Dim strPerms As String
' Decode the common permissions. If (lngPerms And dbSecNoAccess) = dbSecNoAccess Then _ strPerms = AddString(strPerms, "dbSecNoAccess")
If (lngPerms And dbSecFullAccess) = dbSecFullAccess Then _ strPerms = AddString(strPerms, "dbSecFullAccess")
If (lngPerms And dbSecDelete) = dbSecDelete Then _ strPerms = AddString(strPerms, "dbSecDelete")
If (lngPerms And dbSecReadSec) = dbSecReadSec Then _ strPerms = AddString(strPerms, "dbSecReadSec")
If (lngPerms And dbSecWriteSec) = dbSecWriteSec Then _ strPerms = AddString(strPerms, "dbSecWriteSec")
If (lngPerms And dbSecWriteOwner) = dbSecWriteOwner Then _ strPerms = AddString(strPerms, "dbSecWriteOwner")
' Decode specific permissions. Select Case intType Case 1 ' Object is table or query. If (lngPerms And dbSecReadDef) = dbSecReadDef Then _ strPerms = AddString(strPerms, "dbSecReadDef")
If (lngPerms And dbSecWriteDef) = dbSecWriteDef Then _ strPerms = AddString(strPerms, "dbSecWriteDef")
If (lngPerms And dbSecRetrieveData) = dbSecRetrieveData Then _ strPerms = AddString(strPerms, "dbSecRetrieveData")
If (lngPerms And dbSecInsertData) = dbSecInsertData Then _ strPerms = AddString(strPerms, "dbSecInsertData")
If (lngPerms And dbSecReplaceData) = dbSecReplaceData Then _ strPerms = AddString(strPerms, "dbSecReplaceData")
If (lngPerms And dbSecDeleteData) = dbSecDeleteData Then _ strPerms = AddString(strPerms, "dbSecDeleteData")
Case 2 ' Object is database. If (lngPerms And dbSecDBOpen) = dbSecDBOpen Then _ strPerms = AddString(strPerms, "dbSecDBOpen")
If (lngPerms And dbSecDBExclusive) = dbSecDBExclusive Then _ strPerms = AddString(strPerms, "dbSecDBExclusive")
If (lngPerms And dbSecDBAdmin) = dbSecDBAdmin Then _ strPerms = AddString(strPerms, "dbSecDBAdmin")
Case 3 ' Object is container. If (lngPerms And dbSecWriteOwner) = dbSecWriteOwner Then _ strPerms = AddString(strPerms, "dbSecWriteOwner")
If (lngPerms And dbSecCreate) = dbSecCreate Then _ strPerms = AddString(strPerms, "dbSecCreate")
Case Else ' Unknown object, pass the permissions back. strPerms = CStr(lngPerms) End Select
DecodePerms = strPerms End Function
' Section 4: Using DAO to Program Security Function AddString(strCurrent As String, strIn As String) As String ' This procedure adds the name of a permissions constant to the ' string containing the other constants for a particular user or group ' on a particular document object. ' ' Arguments: ' strCurrent: A string that contains all of ' the permissions constants decoded for an object so far. ' strIn: A string that contains the name of a permissions constant. ' ' Returns: ' A string that includes the previously decoded ' permissions, plus the new constant name that has been concatenated into ' the string.
Dim strPerms As String
' If no permissions have been decoded, return string containing ' the permission passed in. If strCurrent = "" Then strPerms = strIn ' Otherwise concatenate new permission into existing string. Else strPerms = strCurrent & "," & strIn End If AddString = strPerms End Function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.