Source code of Windows XP (NT5)
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.

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