Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:17 Der 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!) ;)
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:18 #1
Er det muligt at finde de oplysninger via VBA?
Avatar billede terry Ekspert
29. oktober 2002 - 10:20 #2
Yes I would think so, but you MAY need to be admin!
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:23 #3
That's ok, cause I AM the admin!
Avatar billede terry Ekspert
29. oktober 2002 - 10:28 #4
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
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:29 #5
Giving it a shot, DON'T tell me you just came up with that kinda code in under 8 mins!!! ;)
Avatar billede terry Ekspert
29. oktober 2002 - 10:35 #6
of course :o)
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:35 #7
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....
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:39 #8
But......I guess I just have to sorta "fill in the missing code", right? ;(
Avatar billede terry Ekspert
29. oktober 2002 - 10:42 #9
I'll see what I can find.
Avatar billede terry Ekspert
29. oktober 2002 - 10:47 #10
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 10:48 #11
Taking a look...
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 11:05 #12
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..... :(
Avatar billede terry Ekspert
29. oktober 2002 - 11:18 #13
thats because it is an MDE file (no code) :o(
Which version (access) did you download?
Avatar billede dougheffernan Nybegynder
29. oktober 2002 - 11:24 #14
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........
Avatar billede terry Ekspert
29. oktober 2002 - 11:28 #15
I'll download it myslef and see what it does give!
Avatar billede terry Ekspert
29. oktober 2002 - 13:10 #16
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
Avatar billede terry Ekspert
29. oktober 2002 - 18:02 #17
Avatar billede terry Ekspert
29. oktober 2002 - 18:05 #18
IF you cant find what you want here, then it doesnt exist!
Avatar billede terry Ekspert
29. oktober 2002 - 18:12 #19
this is maybe easier for you

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

I have removed the other
Avatar billede dougheffernan Nybegynder
30. oktober 2002 - 09:30 #20
Thanks you very much, terry, there's enough for me to work with.
Avatar billede terry Ekspert
30. oktober 2002 - 09:35 #21
:o)
og tak
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester