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.

272 lines
7.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. xbf.hxx
  5. Abstract:
  6. Helper classes used to handle IIS client cert wildcard mapping
  7. see iis\svcs\iismap\iiscmr.cxx for implementation
  8. Author:
  9. Philippe Choquier (phillich) 17-oct-1996
  10. --*/
  11. #if !defined( _IISXBF_HXX )
  12. #define _IISXBF_HXX
  13. #ifndef IISMAP_DLLEXP
  14. # ifdef DLL_IMPLEMENTATION
  15. # define IISMAP_DLLEXP __declspec(IISMAP_DLLEXPort)
  16. # ifdef IMPLEMENTATION_EXPORT
  17. # define IRTL_EXPIMP
  18. # else
  19. # undef IRTL_EXPIMP
  20. # endif
  21. # else // !DLL_IMPLEMENTATION
  22. # define IISMAP_DLLEXP __declspec(dllimport)
  23. # define IRTL_EXPIMP extern
  24. # endif // !DLL_IMPLEMENTATION
  25. #endif // !IISMAP_DLLEXP
  26. //
  27. // Extensible buffer class
  28. //
  29. // Use GetBuff() & GetUsed() to retrieve buffer ptr & length
  30. //
  31. class CStoreXBF
  32. {
  33. public:
  34. IISMAP_DLLEXP CStoreXBF( UINT cG = sizeof(DWORD) ) { m_pBuff = NULL; m_cAllocBuff = 0; m_cUsedBuff = 0; m_cGrain = cG; }
  35. IISMAP_DLLEXP ~CStoreXBF() { Reset(); }
  36. IISMAP_DLLEXP VOID Reset()
  37. {
  38. if ( m_pBuff )
  39. {
  40. LocalFree( m_pBuff );
  41. m_pBuff = NULL;
  42. m_cAllocBuff = 0;
  43. m_cUsedBuff = 0;
  44. }
  45. }
  46. IISMAP_DLLEXP VOID Clear()
  47. {
  48. m_cUsedBuff = 0;
  49. }
  50. IISMAP_DLLEXP BOOL DecreaseUse( DWORD dwD )
  51. {
  52. if ( dwD <= m_cUsedBuff )
  53. {
  54. m_cUsedBuff -= dwD;
  55. return TRUE;
  56. }
  57. return FALSE;
  58. }
  59. IISMAP_DLLEXP BOOL Append( LPSTR pszB )
  60. {
  61. return Append( (LPBYTE)pszB, (DWORD)strlen(pszB) );
  62. }
  63. IISMAP_DLLEXP BOOL AppendZ( LPSTR pszB )
  64. {
  65. return Append( (LPBYTE)pszB, (DWORD)strlen(pszB)+1 );
  66. }
  67. IISMAP_DLLEXP BOOL Append( DWORD dwB )
  68. {
  69. return Append( (LPBYTE)&dwB, (DWORD)sizeof(DWORD) );
  70. }
  71. IISMAP_DLLEXP BOOL Append( LPBYTE pB, DWORD cB )
  72. {
  73. DWORD dwNeed = m_cUsedBuff + cB;
  74. if ( Need( dwNeed ) )
  75. {
  76. memcpy( m_pBuff + m_cUsedBuff, pB, cB );
  77. m_cUsedBuff += cB;
  78. return TRUE;
  79. }
  80. return FALSE;
  81. }
  82. IISMAP_DLLEXP BOOL Need( DWORD dwNeed );
  83. //
  84. // Get ptr to buffer
  85. //
  86. IISMAP_DLLEXP LPBYTE GetBuff() { return m_pBuff; }
  87. //
  88. // Get count of bytes in buffer
  89. //
  90. IISMAP_DLLEXP DWORD GetUsed() { return m_cUsedBuff; }
  91. IISMAP_DLLEXP BOOL Save( HANDLE hFile );
  92. IISMAP_DLLEXP BOOL Load( HANDLE hFile );
  93. private:
  94. LPBYTE m_pBuff;
  95. DWORD m_cAllocBuff;
  96. DWORD m_cGrain;
  97. DWORD m_cUsedBuff;
  98. } ;
  99. //
  100. // extensible array of DWORDS
  101. // Added to make win64 stuff work
  102. //
  103. class CPtrDwordXBF : public CStoreXBF
  104. {
  105. public:
  106. IISMAP_DLLEXP CPtrDwordXBF() : CStoreXBF( sizeof(DWORD) ) {}
  107. IISMAP_DLLEXP DWORD GetNbPtr() { return GetUsed()/sizeof(DWORD); }
  108. IISMAP_DLLEXP DWORD AddPtr(DWORD dwEntry);
  109. IISMAP_DLLEXP DWORD InsertPtr(DWORD iBefore, DWORD dwEntry);
  110. IISMAP_DLLEXP LPDWORD GetPtr( DWORD i ) { return ( (LPDWORD*) GetBuff())[i]; }
  111. IISMAP_DLLEXP BOOL SetPtr( DWORD i, DWORD pV ) { ((LPDWORD)GetBuff())[i] = pV; return TRUE; }
  112. IISMAP_DLLEXP BOOL DeletePtr( DWORD i );
  113. IISMAP_DLLEXP BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  114. IISMAP_DLLEXP BOOL Serialize( CStoreXBF* pX );
  115. } ;
  116. //
  117. // extensible array of LPVOID
  118. //
  119. class CPtrXBF : public CStoreXBF
  120. {
  121. public:
  122. IISMAP_DLLEXP CPtrXBF() : CStoreXBF( sizeof(LPVOID) ) {}
  123. IISMAP_DLLEXP DWORD GetNbPtr() { return GetUsed()/sizeof(LPVOID); }
  124. IISMAP_DLLEXP DWORD AddPtr( LPVOID pV);
  125. IISMAP_DLLEXP DWORD InsertPtr( DWORD iBefore, LPVOID pV );
  126. IISMAP_DLLEXP LPVOID GetPtr( DWORD i ) { return ((LPVOID*)GetBuff())[i]; }
  127. IISMAP_DLLEXP LPVOID GetPtrAddr( DWORD i ) { return ((LPVOID*)GetBuff())+i; }
  128. IISMAP_DLLEXP BOOL SetPtr( DWORD i, LPVOID pV ) { ((LPVOID*)GetBuff())[i] = pV; return TRUE; }
  129. IISMAP_DLLEXP BOOL DeletePtr( DWORD i );
  130. IISMAP_DLLEXP BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  131. IISMAP_DLLEXP BOOL Serialize( CStoreXBF* pX );
  132. } ;
  133. //
  134. // string storage class
  135. //
  136. class CAllocString {
  137. public:
  138. IISMAP_DLLEXP CAllocString() { m_pStr = NULL; }
  139. IISMAP_DLLEXP ~CAllocString() { Reset(); }
  140. IISMAP_DLLEXP VOID Reset() { if ( m_pStr != NULL ) {LocalFree( m_pStr ); m_pStr = NULL;} }
  141. IISMAP_DLLEXP BOOL Set( LPSTR pS );
  142. IISMAP_DLLEXP BOOL Append( LPSTR pS );
  143. IISMAP_DLLEXP BOOL Unserialize( LPBYTE* ppb, LPDWORD pc );
  144. IISMAP_DLLEXP BOOL Serialize( CStoreXBF* pX );
  145. IISMAP_DLLEXP LPSTR Get() { return m_pStr; }
  146. private:
  147. LPSTR m_pStr;
  148. } ;
  149. //
  150. // binary object, contains ptr & size
  151. //
  152. class CBlob {
  153. public:
  154. IISMAP_DLLEXP CBlob() { m_pStr = NULL; m_cStr = 0; }
  155. IISMAP_DLLEXP ~CBlob() { Reset(); }
  156. IISMAP_DLLEXP VOID Reset() { if ( m_pStr != NULL ) {LocalFree( m_pStr ); m_pStr = NULL; m_cStr = 0;} }
  157. IISMAP_DLLEXP BOOL Set( LPBYTE pStr, DWORD cStr );
  158. IISMAP_DLLEXP BOOL InitSet( LPBYTE pStr, DWORD cStr );
  159. IISMAP_DLLEXP LPBYTE Get( LPDWORD pc ) { *pc = m_cStr; return m_pStr; }
  160. IISMAP_DLLEXP BOOL Unserialize( LPBYTE* ppB, LPDWORD pC );
  161. IISMAP_DLLEXP BOOL Serialize( CStoreXBF* pX );
  162. private:
  163. LPBYTE m_pStr;
  164. DWORD m_cStr;
  165. } ;
  166. //
  167. // extensible array of strings
  168. //
  169. class CStrPtrXBF : public CPtrXBF {
  170. public:
  171. IISMAP_DLLEXP ~CStrPtrXBF();
  172. IISMAP_DLLEXP DWORD AddEntry( LPSTR pS );
  173. IISMAP_DLLEXP DWORD InsertEntry( DWORD iBefore, LPSTR pS );
  174. IISMAP_DLLEXP DWORD GetNbEntry() { return GetNbPtr(); }
  175. IISMAP_DLLEXP LPSTR GetEntry( DWORD i ) { return ((CAllocString*)GetPtrAddr(i))->Get(); }
  176. IISMAP_DLLEXP BOOL SetEntry( DWORD i, LPSTR pS ) { return ((CAllocString*)GetPtrAddr(i))->Set( pS ); }
  177. IISMAP_DLLEXP BOOL DeleteEntry( DWORD i );
  178. IISMAP_DLLEXP BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  179. IISMAP_DLLEXP BOOL Serialize( CStoreXBF* pX );
  180. } ;
  181. //
  182. // extensible array of binary object
  183. // ptr & size are stored for each entry
  184. //
  185. class CBlobXBF : public CStoreXBF {
  186. public:
  187. IISMAP_DLLEXP CBlobXBF() : CStoreXBF( sizeof(CBlob) ) {}
  188. IISMAP_DLLEXP ~CBlobXBF();
  189. IISMAP_DLLEXP VOID Reset();
  190. IISMAP_DLLEXP DWORD AddEntry( LPBYTE pS, DWORD cS );
  191. IISMAP_DLLEXP DWORD InsertEntry( DWORD iBefore, LPSTR pS, DWORD cS );
  192. IISMAP_DLLEXP DWORD GetNbEntry() { return GetUsed()/sizeof(CBlob); }
  193. IISMAP_DLLEXP CBlob* GetBlob( DWORD i )
  194. { return (CBlob*)(GetBuff()+i*sizeof(CBlob)); }
  195. IISMAP_DLLEXP BOOL GetEntry( DWORD i, LPBYTE* ppB, LPDWORD pcB )
  196. {
  197. if ( i < (GetUsed()/sizeof(CBlob)) )
  198. {
  199. *ppB = GetBlob(i)->Get( pcB );
  200. return TRUE;
  201. }
  202. return FALSE;
  203. }
  204. IISMAP_DLLEXP BOOL SetEntry( DWORD i, LPBYTE pS, DWORD cS )
  205. { return GetBlob(i)->Set( pS, cS ); }
  206. IISMAP_DLLEXP BOOL DeleteEntry( DWORD i );
  207. IISMAP_DLLEXP BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  208. IISMAP_DLLEXP BOOL Serialize( CStoreXBF* pX );
  209. } ;
  210. BOOL
  211. Unserialize(
  212. LPBYTE* ppB,
  213. LPDWORD pC,
  214. LPDWORD pU
  215. );
  216. BOOL
  217. Unserialize(
  218. LPBYTE* ppB,
  219. LPDWORD pC,
  220. LPBOOL pU
  221. );
  222. BOOL
  223. Serialize(
  224. CStoreXBF* pX,
  225. DWORD dw
  226. );
  227. BOOL
  228. Serialize(
  229. CStoreXBF* pX,
  230. BOOL f
  231. );
  232. #endif