listacl.cpp

Go to the documentation of this file.
00001 /*++
00002 
00003 DCOM Permission Configuration Sample
00004 Copyright (c) 1996, Microsoft Corporation. All rights reserved.
00005 
00006 Module Name:
00007 
00008     listacl.cpp
00009 
00010 Abstract:
00011 
00012     Code to list ACL information
00013 
00014 Author:
00015 
00016     Michael Nelson
00017 
00018 Environment:
00019 
00020     Windows NT
00021 
00022 --*/
00023 
00024 #include <windows.h>
00025 #include <stdio.h>
00026 #include <conio.h>
00027 #include <tchar.h>
00028 #include "ntsecapi.h"
00029 #include "dcomperm.h"
00030 
00031 void
00032 ListACL (
00033     PACL Acl
00034     )
00035 {
00036     ACL_SIZE_INFORMATION     aclSizeInfo;
00037     ACL_REVISION_INFORMATION aclRevInfo;
00038     ULONG                    i = 0;
00039     LPVOID                   ace = NIL;
00040     ACE_HEADER               *aceHeader = NIL;
00041     ACCESS_ALLOWED_ACE       *paaace = NIL;
00042     ACCESS_DENIED_ACE        *padace = NIL;
00043     TCHAR                    domainName [256];
00044     TCHAR                    userName [256];
00045     DWORD                    nameLength = 0;
00046     SID_NAME_USE             snu;
00047 
00048     if (!GetAclInformation (Acl,
00049                             &aclSizeInfo,
00050                             sizeof (ACL_SIZE_INFORMATION),
00051                             AclSizeInformation))
00052     {
00053         _tprintf (TEXT("Could not get AclSizeInformation"));
00054         return;
00055     }
00056 
00057     if (!GetAclInformation (Acl,
00058                             &aclRevInfo,
00059                             sizeof (ACL_REVISION_INFORMATION),
00060                             AclRevisionInformation))
00061     {
00062         _tprintf (TEXT("Could not get AclRevisionInformation"));
00063         return;
00064     }
00065 
00066     for (i = 0; i < aclSizeInfo.AceCount; i++)
00067     {
00068         if (!GetAce (Acl, i, &ace))
00069             return;
00070 
00071         aceHeader = (ACE_HEADER *) ace;
00072 
00073         if (aceHeader->AceType == ACCESS_ALLOWED_ACE_TYPE)
00074         {
00075             paaace = (ACCESS_ALLOWED_ACE *) ace;
00076             nameLength = 255;
00077             LookupAccountSid (NULL,
00078                               &paaace->SidStart,
00079                               userName,
00080                               &nameLength,
00081                               domainName,
00082                               &nameLength,
00083                               &snu);
00084 
00085             _tprintf (TEXT("Access permitted to %s\\%s.\n"), domainName, userName);
00086         } else
00087         if (aceHeader->AceType == ACCESS_DENIED_ACE_TYPE)
00088         {
00089             padace = (ACCESS_DENIED_ACE *) ace;
00090             nameLength = 255;
00091             LookupAccountSid (NULL,
00092                               &padace->SidStart,
00093                               userName,
00094                               &nameLength,
00095                               domainName,
00096                               &nameLength,
00097                               &snu);
00098 
00099             _tprintf (TEXT("Access denied to %s\\%s.\n"), domainName, userName);
00100 
00101         }
00102    }
00103 }
00104 

Generated on Fri Nov 28 04:28:49 2008 for HOOPLE Libraries by  doxygen 1.5.1