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.

271 lines
9.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  4. //
  5. // File: idq.hxx
  6. //
  7. // Contents: Parser for an IDQ file
  8. //
  9. // History: 96/Jan/3 DwightKr Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #pragma once
  13. #if !defined( LONGSIG )
  14. #define LONGSIG(c1, c2, c3, c4) \
  15. (((ULONG) (BYTE) (c1)) | \
  16. (((ULONG) (BYTE) (c2)) << 8) | \
  17. (((ULONG) (BYTE) (c3)) << 16) | \
  18. (((ULONG) (BYTE) (c4)) << 24))
  19. #endif // LONGSIG
  20. class CVariable;
  21. class CVariableSet;
  22. class COutputFormat;
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Function: ISAPI_IDQHash, inline
  26. //
  27. // Arguments: [wcsName] -- name to be hashed
  28. //
  29. // Returns: ULONG - hashed value for wcsName
  30. //
  31. //----------------------------------------------------------------------------
  32. inline ULONG ISAPI_IDQHash( WCHAR const * wcsName )
  33. {
  34. ULONG ulHash = 0;
  35. ULONG cwcName;
  36. for ( cwcName=0; wcsName[cwcName] != 0; cwcName++ )
  37. {
  38. ulHash <<= 1;
  39. ulHash += wcsName[cwcName];
  40. }
  41. ulHash += cwcName;
  42. return ulHash;
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Class: CIDQFile
  47. //
  48. // Purpose: Scans and parses an IDQ file.
  49. //
  50. // History: 96/Jan/23 DwightKr Created
  51. //
  52. //----------------------------------------------------------------------------
  53. class CIDQFile
  54. {
  55. public:
  56. CIDQFile( WCHAR const * wcsFileName,
  57. UINT codePage,
  58. CSecurityIdentity const & securityIdentity );
  59. ~CIDQFile();
  60. void ParseFile();
  61. WCHAR const * GetIDQFileName() const { return _wcsIDQFileName; }
  62. WCHAR const * GetRestriction() const { return _wcsRestriction; }
  63. WCHAR const * GetDialect() const { return _wcsDialect; }
  64. WCHAR const * GetScope() const { return _wcsScope; }
  65. WCHAR const * GetSort() const { return _wcsSort; }
  66. WCHAR const * GetCiFlags() const { return _wcsCiFlags; }
  67. WCHAR const * GetForceUseCI() const { return _wcsForceUseCi; }
  68. WCHAR const * GetDeferTrimming() const { return _wcsDeferTrimming; }
  69. WCHAR const * GetHTXFileName() const { return _wcsHTXFileName; }
  70. WCHAR const * GetCatalog() const { return _wcsCatalog; }
  71. WCHAR const * GetColumns() const { return _wcsColumns; }
  72. WCHAR const * GetLocale() const { return _wcsLocale; }
  73. WCHAR const * GetCanonicalOutput() const { return _wcsCanonicalOutput; }
  74. WCHAR const * GetDontTimeout() const { return _wcsDontTimeout; }
  75. WCHAR const * GetMaxRecordsInResultSet() const { return _wcsMaxRecordsInResultSet; }
  76. WCHAR const * GetMaxRecordsPerPage() const { return _wcsMaxRecordsPerPage; }
  77. WCHAR const * GetFirstRowsInResultSet() const { return _wcsFirstRowsInResultSet; }
  78. IColumnMapper * GetColumnMapper() const { return _xList.GetPointer(); }
  79. BOOL IsCachedDataValid();
  80. inline BOOL CheckSecurity( CSecurityIdentity const & securityIdentity ) const;
  81. void SetSecurityToken( CSecurityIdentity const & securityIdentity )
  82. {
  83. _securityIdentity.SetSecurityToken( securityIdentity );
  84. }
  85. void GetVectorFormatting( COutputFormat & outputFormat );
  86. CDbColumns * ParseColumns( WCHAR const * wcsColumns,
  87. CVariableSet & variableSet,
  88. CDynArray<WCHAR> & awcsColumns );
  89. ULONG GetReplaceableParameterCount() const { return _cReplaceableParameters; }
  90. void LokAddRef() { InterlockedIncrement(&_refCount); }
  91. void Release()
  92. {
  93. InterlockedDecrement(&_refCount);
  94. Win4Assert( _refCount >= 0 );
  95. }
  96. LONG LokGetRefCount() { return _refCount; }
  97. ULONG ParseFlags( WCHAR const * wcsCiFlags );
  98. BOOL ParseForceUseCI( WCHAR const * wcsForceUseCi );
  99. BOOL ParseDeferTrimming( WCHAR const * wcsDeferTrimming );
  100. BOOL IsCanonicalOutput() const;
  101. BOOL IsDontTimeout() const;
  102. UINT GetCodePage() const { return _codePage; }
  103. private:
  104. void ParseOneLine( CQueryScanner & scan, unsigned iLine );
  105. void GetStringValue( CQueryScanner & scan,
  106. unsigned iLine,
  107. WCHAR ** pwcsStringValue,
  108. BOOL fParseQuotes = TRUE );
  109. WCHAR * _wcsRestriction; // The query restriction
  110. WCHAR * _wcsDialect; // The tripolish version (1/2)
  111. WCHAR * _wcsScope; // The query scope
  112. WCHAR * _wcsColumns; // Output columns
  113. WCHAR * _wcsLocale; // Locale specified in IDQ file
  114. WCHAR * _wcsSort; // Sort order
  115. WCHAR * _wcsHTXFileName; // The name of the template file
  116. WCHAR * _wcsMaxRecordsInResultSet; // Max # recs to get from qry
  117. WCHAR * _wcsMaxRecordsPerPage; // Number of records per page
  118. WCHAR * _wcsFirstRowsInResultSet;
  119. WCHAR * _wcsCatalog; // Location of the catalog
  120. WCHAR * _wcsCiFlags; // Flags
  121. WCHAR * _wcsForceUseCi; // Force use of CI for all queries
  122. WCHAR * _wcsDeferTrimming; // Defer result trimming
  123. WCHAR * _wcsCanonicalOutput; // Canonical output
  124. WCHAR * _wcsDontTimeout; // Don't timeout value
  125. WCHAR * _wcsBoolVectorPrefix; // Prefix for vectors of bools
  126. WCHAR * _wcsBoolVectorSeparator; // Separator for vectors of bools
  127. WCHAR * _wcsBoolVectorSuffix; // Suffix for vectors or bools
  128. WCHAR * _wcsCurrencyVectorPrefix; // Prefix for vectors of currency
  129. WCHAR * _wcsCurrencyVectorSeparator;// Separator for vectors of currency
  130. WCHAR * _wcsCurrencyVectorSuffix; // Suffix for vectors or currency
  131. WCHAR * _wcsDateVectorPrefix; // Prefix for vectors of date
  132. WCHAR * _wcsDateVectorSeparator; // Separator for vectors of date
  133. WCHAR * _wcsDateVectorSuffix; // Suffix for vectors for date
  134. WCHAR * _wcsNumberVectorPrefix; // Prefix for vectors of numbers
  135. WCHAR * _wcsNumberVectorSeparator;// Separator for vectors of numbers
  136. WCHAR * _wcsNumberVectorSuffix; // Suffix for vectors or numbers
  137. WCHAR * _wcsStringVectorPrefix; // Prefix for vectors of strings
  138. WCHAR * _wcsStringVectorSeparator;// Separator for vectors of string
  139. WCHAR * _wcsStringVectorSuffix; // Suffix for vectors or strings
  140. ULONG _cReplaceableParameters; // # of replaceable parameters
  141. FILETIME _ftIDQLastWriteTime; // Last write time of IDQ file
  142. LONG _refCount; // Refcount for this file
  143. XInterface<CLocalGlobalPropertyList> _xList; // Parsed property list
  144. WCHAR _wcsIDQFileName[MAX_PATH]; // The IDQ file name
  145. UINT _codePage; // code page to parse file
  146. CSecurityIdentity _securityIdentity; // Security ID used to open file
  147. };
  148. //+---------------------------------------------------------------------------
  149. //
  150. // Function: GetLastWriteTime
  151. //
  152. // Purpose: Gets the last change time of the file specified
  153. //
  154. // Arguments: [wcsFileName] - name of file to get last write time of
  155. // [ft] - returns the last write time of the file
  156. //
  157. // History: 96/Jan/23 DwightKr Created
  158. //
  159. //----------------------------------------------------------------------------
  160. SCODE GetLastWriteTime( WCHAR const * wcsFileName, FILETIME & ft );
  161. //+---------------------------------------------------------------------------
  162. //
  163. // Class: CIDQFileList
  164. //
  165. // Purpose: List of parsed and cached IDQ files
  166. //
  167. // History: 96/Mar/27 DwightKr Created
  168. //
  169. //----------------------------------------------------------------------------
  170. class CIDQFileList
  171. {
  172. public:
  173. CIDQFileList()
  174. : _ulSignature( LONGSIG( 'i', 'd', 'q', 'l' ) )
  175. {
  176. END_CONSTRUCTION(CIDQFileList);
  177. }
  178. ~CIDQFileList();
  179. CIDQFile * Find( WCHAR const * wcsFileName,
  180. UINT codePage,
  181. CSecurityIdentity const & securityIdentity );
  182. void Release( CIDQFile & idqFile );
  183. void DeleteZombies();
  184. private:
  185. ULONG _ulSignature; // Signature of start of privates
  186. CMutexSem _mutex; // To serialize access to list
  187. CDynArrayInPlace<CIDQFile *> _aIDQFile; // parsed IDQ files
  188. };
  189. //+---------------------------------------------------------------------------
  190. //
  191. // Method: CIDQFile::CheckSecurity
  192. //
  193. // Purpose: Compare user id with one used to load IDQ file
  194. //
  195. // Arguments: [securityIdentity] - Check against this
  196. //
  197. // Returns: TRUE if check passes
  198. //
  199. // History: 26-Oct-1996 KyleP Created
  200. //
  201. //----------------------------------------------------------------------------
  202. inline BOOL CIDQFile::CheckSecurity( CSecurityIdentity const & securityIdentity ) const
  203. {
  204. return _securityIdentity.IsEqual( securityIdentity );
  205. }
  206. //+---------------------------------------------------------------------------
  207. //
  208. // Function: IsNetPath
  209. //
  210. // Purpose: Determines if a physical path is a UNC
  211. //
  212. // Arguments: [pwszPath] -- The path to check
  213. //
  214. // Returns: TRUE if the path is a UNC, FALSE otherwise
  215. //
  216. // History: 26-Aug-1997 dlee Coped from impersonation code
  217. //
  218. //----------------------------------------------------------------------------
  219. inline BOOL IsNetPath( WCHAR const * pwszPath )
  220. {
  221. return L'\\' == pwszPath[0] && L'\\' == pwszPath[1];
  222. }