Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.6 KiB

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