home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / winnt / cacls / t2.hxx < prev   
Text File  |  1995-03-13  |  5KB  |  169 lines

  1. //+-------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1995, Microsoft Corporation.
  4. //
  5. //  File:        t2.hxx
  6. //
  7. //  Contents:    general include things for the Control ACLS program
  8. //
  9. //  Classes:     none
  10. //
  11. //  History:     Dec-93        Created         DaveMont
  12. //
  13. //--------------------------------------------------------------------
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <windows.h>
  17. #include <wchar.h>
  18.  
  19. #ifndef __T2__
  20. #define __T2__
  21.  
  22. VOID * Add2Ptr(VOID *pv, ULONG cb);
  23.  
  24. //
  25. // indicates add denied ace
  26.  
  27. #define GENERIC_NONE 0
  28.  
  29. //
  30. // mask for command line options
  31.  
  32. #define OPTION_REPLACE           0x00000001
  33. #define OPTION_REVOKE            0x00000002
  34. #define OPTION_DENY              0x00000004
  35. #define OPTION_GRANT             0x00000008
  36. #define OPTION_TREE              0x00000010
  37. #define OPTION_CONTINUE_ON_ERROR 0x00000020
  38.  
  39. // command modes
  40.  
  41. typedef enum
  42. {
  43.     MODE_DISPLAY            ,
  44.     MODE_REPLACE            ,
  45.     MODE_MODIFY             ,
  46.     MODE_DEBUG_ENUMERATE
  47. } MODE;
  48.  
  49. // input arg modes, used in GetCmdArgs, and as index for start/end arg
  50. // counters, The order of the first 4 of these must match the order of the
  51. // command line option masks (above)
  52.  
  53. typedef enum
  54. {
  55.     ARG_MODE_INDEX_REPLACE = 0,
  56.     ARG_MODE_INDEX_REVOKE,
  57.     ARG_MODE_INDEX_DENY,
  58.     ARG_MODE_INDEX_GRANT,
  59.     ARG_MODE_INDEX_DEBUG,
  60.     ARG_MODE_INDEX_EXTENDED,
  61.     ARG_MODE_INDEX_NEED_OPTION
  62. } ARG_MODE_INDEX;
  63.  
  64. #define MAX_OPTIONS ARG_MODE_INDEX_GRANT + 1
  65.  
  66. // max permissions per command line
  67.  
  68. #define CMAXACES 64
  69.  
  70. #if DBG
  71.  
  72. // debug options:
  73.  
  74. #define DEBUG_DISPLAY_SIDS      0x00000001
  75. #define DEBUG_DISPLAY_MASK      0x00000002
  76. #define DEBUG_LAST_ERROR        0x00000004
  77. #define DEBUG_ERRORS            0x00000008
  78. #define DEBUG_VERBOSE           0x00000010
  79. #define DEBUG_VERBOSER          0x00000020
  80. #define DEBUG_ENUMERATE_STAT    0x00000040
  81. #define DEBUG_ENUMERATE_FAIL    0x00000080
  82. #define DEBUG_ENUMERATE_RETURNS 0x00000100
  83. #define DEBUG_ENUMERATE_EXTRA   0x00000200
  84. #define DEBUG_SIZE_ALLOCATIONS  0x00000400
  85. #define DEBUG_ENUMERATE         0x00000800
  86.  
  87. #define DISPLAY(a) if ((Debug & DEBUG_DISPLAY_MASK) || (Debug & DEBUG_DISPLAY_SIDS))  {fprintf a;}
  88. #define DISPLAY_MASK(a) if (Debug & DEBUG_DISPLAY_MASK)  {fprintf a;}
  89. #define DISPLAY_SIDS(a) if (Debug & DEBUG_DISPLAY_SIDS)  {fprintf a;}
  90. #define VERBOSE(a) if (Debug & DEBUG_VERBOSE)  {fprintf a;}
  91. #define VERBOSER(a) if (Debug & DEBUG_VERBOSER) {fprintf a;}
  92. #define ERRORS(a) if (Debug & DEBUG_ERRORS)  {fprintf a;}
  93. #define LAST_ERROR(a) if (Debug & DEBUG_LAST_ERROR)  {fprintf a;}
  94. #define ENUMERATE_STAT(a) if (Debug & DEBUG_ENUMERATE_STAT)  {fprintf a;}
  95. #define ENUMERATE_FAIL(a) if (Debug & DEBUG_ENUMERATE_FAIL)  {fprintf a;}
  96. #define ENUMERATE_RETURNS(a) if (Debug & DEBUG_ENUMERATE_RETURNS)  {fprintf a;}
  97. #define ENUMERATE_EXTRA(a) if (Debug & DEBUG_ENUMERATE_EXTRA)  {fprintf a;}
  98. #define SIZE(a) if (Debug & DEBUG_SIZE_ALLOCATIONS)  {fprintf a;}
  99.  
  100. #else
  101. #define DISPLAY(a)
  102. #define DISPLAY_MASK(a)
  103. #define DISPLAY_SIDS(a)
  104. #define VERBOSE(a)
  105. #define VERBOSER(a)
  106. #define ERRORS(a)
  107. #define LAST_ERROR(a)
  108. #define ENUMERATE_STAT(a)
  109. #define ENUMERATE_FAIL(a)
  110. #define ENUMERATE_RETURNS(a)
  111. #define ENUMERATE_EXTRA(a)
  112. #define SIZE(a)
  113. #endif
  114. //+-------------------------------------------------------------------------
  115. //
  116. //  Class:     FastAllocator
  117. //
  118. //  Synopsis:  takes in a buffer, buffer size, and needed size, and either
  119. //             uses the buffer, or allocates a new one for the size
  120. //             and of course destroys it in the dtor
  121. //
  122. //--------------------------------------------------------------------------
  123. class FastAllocator
  124. {
  125. public:
  126.  
  127.     inline FastAllocator(VOID *buf, LONG bufsize);
  128.     inline ~FastAllocator();
  129.  
  130.     inline VOID *GetBuf(LONG neededsize);
  131.  
  132. private:
  133.  
  134.     VOID *_statbuf;
  135.     VOID *_allocatedbuf;
  136.     LONG  _statbufsize;
  137.     BOOL  _allocated;
  138. };
  139.  
  140. FastAllocator::FastAllocator(VOID *buf, LONG bufsize)
  141.     :_statbuf(buf),
  142.      _statbufsize(bufsize),
  143.      _allocated(FALSE)
  144. {
  145. }
  146.  
  147. FastAllocator::~FastAllocator()
  148. {
  149.     if (_allocated)
  150.         delete _allocatedbuf;
  151. }
  152.  
  153. VOID *FastAllocator::GetBuf(LONG neededsize)
  154. {
  155.     if (neededsize > _statbufsize)
  156.     {
  157.        _allocatedbuf = (VOID *)new BYTE[neededsize];
  158.        if (_allocatedbuf)
  159.            _allocated = TRUE;
  160.     } else
  161.     {
  162.         _allocatedbuf = _statbuf;
  163.     }
  164.     return(_allocatedbuf);
  165. }
  166.  
  167. #endif // __T2__
  168.  
  169.