home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / dcom / dcomperm / listacl.cpp < prev    next >
C/C++ Source or Header  |  1996-07-19  |  3KB  |  104 lines

  1. /*++
  2.  
  3. DCOM Permission Configuration Sample
  4. Copyright (c) 1996, Microsoft Corporation. All rights reserved.
  5.  
  6. Module Name:
  7.  
  8.     listacl.cpp
  9.  
  10. Abstract:
  11.  
  12.     Code to list ACL information
  13.  
  14. Author:
  15.  
  16.     Michael Nelson
  17.  
  18. Environment:
  19.  
  20.     Windows NT
  21.  
  22. --*/
  23.  
  24. #include <windows.h>
  25. #include <stdio.h>
  26. #include <conio.h>
  27. #include <tchar.h>
  28. #include "ntsecapi.h"
  29. #include "dcomperm.h"
  30.  
  31. void
  32. ListACL (
  33.     PACL Acl
  34.     )
  35. {
  36.     ACL_SIZE_INFORMATION     aclSizeInfo;
  37.     ACL_REVISION_INFORMATION aclRevInfo;
  38.     ULONG                    i;
  39.     LPVOID                   ace;
  40.     ACE_HEADER               *aceHeader;
  41.     ACCESS_ALLOWED_ACE       *paaace;
  42.     ACCESS_DENIED_ACE        *padace;
  43.     TCHAR                    domainName [256];
  44.     TCHAR                    userName [256];
  45.     DWORD                    nameLength;
  46.     SID_NAME_USE             snu;
  47.  
  48.     if (!GetAclInformation (Acl,
  49.                             &aclSizeInfo,
  50.                             sizeof (ACL_SIZE_INFORMATION),
  51.                             AclSizeInformation))
  52.     {
  53.         _tprintf (TEXT("Could not get AclSizeInformation"));
  54.         return;
  55.     }
  56.  
  57.     if (!GetAclInformation (Acl,
  58.                             &aclRevInfo,
  59.                             sizeof (ACL_REVISION_INFORMATION),
  60.                             AclRevisionInformation))
  61.     {
  62.         _tprintf (TEXT("Could not get AclRevisionInformation"));
  63.         return;
  64.     }
  65.  
  66.     for (i = 0; i < aclSizeInfo.AceCount; i++)
  67.     {
  68.         if (!GetAce (Acl, i, &ace))
  69.             return;
  70.  
  71.         aceHeader = (ACE_HEADER *) ace;
  72.  
  73.         if (aceHeader->AceType == ACCESS_ALLOWED_ACE_TYPE)
  74.         {
  75.             paaace = (ACCESS_ALLOWED_ACE *) ace;
  76.             nameLength = 255;
  77.             LookupAccountSid (NULL,
  78.                               &paaace->SidStart,
  79.                               userName,
  80.                               &nameLength,
  81.                               domainName,
  82.                               &nameLength,
  83.                               &snu);
  84.  
  85.             _tprintf (TEXT("Access permitted to %s\\%s.\n"), domainName, userName);
  86.         } else
  87.         if (aceHeader->AceType == ACCESS_DENIED_ACE_TYPE)
  88.         {
  89.             padace = (ACCESS_DENIED_ACE *) ace;
  90.             nameLength = 255;
  91.             LookupAccountSid (NULL,
  92.                               &padace->SidStart,
  93.                               userName,
  94.                               &nameLength,
  95.                               domainName,
  96.                               &nameLength,
  97.                               &snu);
  98.  
  99.             _tprintf (TEXT("Access denied to %s\\%s.\n"), domainName, userName);
  100.  
  101.         }
  102.    }
  103. }
  104.