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.

190 lines
5.3 KiB

  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. //strsafe apis
  20. //
  21. #define STRSAFE_NO_DEPRECATE
  22. #include <strsafe.h>
  23. #ifndef __T2__
  24. #define __T2__
  25. VOID * Add2Ptr(VOID *pv, ULONG cb);
  26. //
  27. // indicates add denied ace
  28. #define GENERIC_NONE 0
  29. //
  30. // mask for command line options
  31. #define OPTION_REPLACE 0x00000001
  32. #define OPTION_REVOKE 0x00000002
  33. #define OPTION_DENY 0x00000004
  34. #define OPTION_GRANT 0x00000008
  35. #define OPTION_TREE 0x00000010
  36. #define OPTION_CONTINUE_ON_ERROR 0x00000020
  37. // command modes
  38. typedef enum
  39. {
  40. MODE_DISPLAY ,
  41. MODE_REPLACE ,
  42. MODE_MODIFY ,
  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. void __cdecl cprintf(LPCTSTR pszFormat, ...);
  64. void __cdecl fcprintf(FILE *pOut, LPCTSTR pszFormat, ...);
  65. void vfcprintf(FILE *pOut, LPCTSTR pszFormat, va_list argList);
  66. #define DEBUG_DISPLAY_SIDS 0x00000001
  67. #define DEBUG_DISPLAY_MASK 0x00000002
  68. #define DEBUG_LAST_ERROR 0x00000004
  69. #define DEBUG_ERRORS 0x00000008
  70. #define DEBUG_VERBOSE 0x00000010
  71. #define DEBUG_VERBOSER 0x00000020
  72. #define DEBUG_ENUMERATE_STAT 0x00000040
  73. #define DEBUG_ENUMERATE_FAIL 0x00000080
  74. #define DEBUG_ENUMERATE_RETURNS 0x00000100
  75. #define DEBUG_ENUMERATE_EXTRA 0x00000200
  76. #define DEBUG_SIZE_ALLOCATIONS 0x00000400
  77. #define DEBUG_ENUMERATE 0x00000800
  78. #define DISPLAY(a) if ((Debug & DEBUG_DISPLAY_MASK) || (Debug & DEBUG_DISPLAY_SIDS)) {fprintf a;}
  79. #define DISPLAYW(a) if ((Debug & DEBUG_DISPLAY_MASK) || (Debug & DEBUG_DISPLAY_SIDS)) {fcprintf a;}
  80. #define DISPLAY_MASK(a) if (Debug & DEBUG_DISPLAY_MASK) {fprintf a;}
  81. #define DISPLAY_MASKW(a) if (Debug & DEBUG_DISPLAY_MASK) {fcprintf a;}
  82. #define DISPLAY_SIDS(a) if (Debug & DEBUG_DISPLAY_SIDS) {fprintf a;}
  83. #define DISPLAY_SIDSW(a) if (Debug & DEBUG_DISPLAY_SIDS) {fcprintf a;}
  84. #define VERBOSE(a) if (Debug & DEBUG_VERBOSE) {fprintf a;}
  85. #define VERBOSEW(a) if (Debug & DEBUG_VERBOSER) {fcprintf a;}
  86. #define VERBOSER(a) if (Debug & DEBUG_VERBOSER) {fprintf a;}
  87. #define VERBOSERW(a) if (Debug & DEBUG_VERBOSER) {fcprintf a;}
  88. #define ERRORS(a) if (Debug & DEBUG_ERRORS) {fprintf a;}
  89. #define ERRORSW(a) if (Debug & DEBUG_ERRORS) {fcprintf a;}
  90. #define LAST_ERROR(a) if (Debug & DEBUG_LAST_ERROR) {fprintf a;}
  91. #define ENUMERATE_STAT(a) if (Debug & DEBUG_ENUMERATE_STAT) {fprintf a;}
  92. #define ENUMERATE_FAIL(a) if (Debug & DEBUG_ENUMERATE_FAIL) {fprintf a;}
  93. #define ENUMERATE_RETURNS(a) if (Debug & DEBUG_ENUMERATE_RETURNS) {fprintf a;}
  94. #define ENUMERATE_EXTRA(a) if (Debug & DEBUG_ENUMERATE_EXTRA) {fprintf a;}
  95. #define SIZE(a) if (Debug & DEBUG_SIZE_ALLOCATIONS) {fprintf a;}
  96. #else
  97. #define DISPLAY(a)
  98. #define DISPLAYW(a)
  99. #define DISPLAY_MASK(a)
  100. #define DISPLAY_MASKW(a)
  101. #define DISPLAY_SIDS(a)
  102. #define DISPLAY_SIDSW(a)
  103. #define VERBOSE(a)
  104. #define VERBOSEW(a)
  105. #define VERBOSER(a)
  106. #define VERBOSERW(a)
  107. #define ERRORS(a)
  108. #define ERRORSW(a)
  109. #define LAST_ERROR(a)
  110. #define ENUMERATE_STAT(a)
  111. #define ENUMERATE_FAIL(a)
  112. #define ENUMERATE_RETURNS(a)
  113. #define ENUMERATE_EXTRA(a)
  114. #define SIZE(a)
  115. #endif
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Class: FastAllocator
  119. //
  120. // Synopsis: takes in a buffer, buffer size, and needed size, and either
  121. // uses the buffer, or allocates a new one for the size
  122. // and of course destroys it in the dtor
  123. //
  124. //--------------------------------------------------------------------------
  125. class FastAllocator
  126. {
  127. public:
  128. inline FastAllocator(VOID *buf, LONG bufsize);
  129. inline ~FastAllocator();
  130. inline VOID *GetBuf(LONG neededsize);
  131. private:
  132. VOID *_statbuf;
  133. VOID *_allocatedbuf;
  134. LONG _statbufsize;
  135. BOOL _allocated;
  136. };
  137. FastAllocator::FastAllocator(VOID *buf, LONG bufsize)
  138. :_statbuf(buf),
  139. _statbufsize(bufsize),
  140. _allocated(FALSE)
  141. {
  142. }
  143. FastAllocator::~FastAllocator()
  144. {
  145. if (_allocated)
  146. delete _allocatedbuf;
  147. }
  148. VOID *FastAllocator::GetBuf(LONG neededsize)
  149. {
  150. if (neededsize > _statbufsize)
  151. {
  152. _allocatedbuf = (VOID *)new BYTE[neededsize];
  153. if (_allocatedbuf)
  154. _allocated = TRUE;
  155. } else
  156. {
  157. _allocatedbuf = _statbuf;
  158. }
  159. return(_allocatedbuf);
  160. }
  161. #endif // __T2__