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.

591 lines
16 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. metasub.hxx
  5. Abstract:
  6. IIS MetaBase declarations for subroutines.
  7. Author:
  8. Michael W. Thomas 32-May-96
  9. Revision History:
  10. --*/
  11. #ifndef _metasub_
  12. #define _metasub_
  13. #define WSZSCHEMA_KEY_NAME1 L"SCHEMA"
  14. #define WSZSCHEMA_KEY_LENGTH1 (sizeof(WSZSCHEMA_KEY_NAME1)/sizeof(WCHAR))-1
  15. #define WSZSCHEMA_KEY_NAME2 L"/SCHEMA"
  16. #define WSZSCHEMA_KEY_LENGTH2 (sizeof(WSZSCHEMA_KEY_NAME2)/sizeof(WCHAR))-1
  17. #define WSZSCHEMA_KEY_NAME3 L"\\SCHEMA"
  18. #define WSZSCHEMA_KEY_LENGTH3 (sizeof(WSZSCHEMA_KEY_NAME3)/sizeof(WCHAR))-1
  19. #define SZSCHEMA_KEY_NAME1 "SCHEMA"
  20. #define SZSCHEMA_KEY_LENGTH1 (sizeof(SZSCHEMA_KEY_NAME1)/sizeof(CHAR))-1
  21. #define SZSCHEMA_KEY_NAME2 "/SCHEMA"
  22. #define SZSCHEMA_KEY_LENGTH2 (sizeof(SZSCHEMA_KEY_NAME2)/sizeof(CHAR))-1
  23. #define SZSCHEMA_KEY_NAME3 "\\SCHEMA"
  24. #define SZSCHEMA_KEY_LENGTH3 (sizeof(SZSCHEMA_KEY_NAME3)/sizeof(CHAR))-1
  25. inline void INCREMENT_SCHEMA_CHANGE_NUMBER(
  26. METADATA_HANDLE handle,
  27. CMDHandle* object,
  28. LPSTR path,
  29. BOOL bUnicode)
  30. {
  31. if((handle) != METADATA_MASTER_ROOT_HANDLE)
  32. {
  33. if(NULL != object)
  34. {
  35. if((object)->IsSchemaHandle())
  36. g_dwSchemaChangeNumber ++;
  37. }
  38. }
  39. else if((NULL != path) && (0 != *path))
  40. {
  41. if(bUnicode)
  42. {
  43. if((0 == _wcsnicmp((LPWSTR)(path), WSZSCHEMA_KEY_NAME1, WSZSCHEMA_KEY_LENGTH1)) ||
  44. (0 == _wcsnicmp((LPWSTR)(path), WSZSCHEMA_KEY_NAME2, WSZSCHEMA_KEY_LENGTH2)) ||
  45. (0 == _wcsnicmp((LPWSTR)(path), WSZSCHEMA_KEY_NAME3, WSZSCHEMA_KEY_LENGTH3))
  46. )
  47. g_dwSchemaChangeNumber ++;
  48. }
  49. else
  50. {
  51. if((0 == _strnicmp((LPSTR)(path), SZSCHEMA_KEY_NAME1, SZSCHEMA_KEY_LENGTH1)) ||
  52. (0 == _strnicmp((LPSTR)(path), SZSCHEMA_KEY_NAME2, SZSCHEMA_KEY_LENGTH2)) ||
  53. (0 == _strnicmp((LPSTR)(path), SZSCHEMA_KEY_NAME3, SZSCHEMA_KEY_LENGTH3))
  54. )
  55. g_dwSchemaChangeNumber ++;
  56. }
  57. }
  58. }
  59. HRESULT
  60. ConstructHistoryFileName(LPWSTR* o_wszHistoryFile,
  61. LPWSTR i_wszHistroyFileDir,
  62. ULONG i_cchHistoryFileDir,
  63. LPWSTR i_wszFileNameWithoutPathWithoutExtension,
  64. ULONG i_cchFileNameWithoutPathWithoutExtension,
  65. LPWSTR i_wszFileNameExtension,
  66. ULONG i_cchFileNameExtension,
  67. DWORD i_dwMajorVersion,
  68. DWORD i_dwMinorVersion);
  69. HRESULT
  70. ParseVersionNumber(IN LPWSTR i_wszFileName,
  71. IN OUT DWORD* io_pdwMinor,
  72. IN OUT DWORD* io_pdwMajor);
  73. HRESULT
  74. ParseVersionNumber(LPWSTR i_wszFileName,
  75. ULONG i_cchFileNameUntilFirstUnderscore,
  76. ULONG* o_ulVersionMinor,
  77. ULONG* o_ulVersionMajor);
  78. HRESULT
  79. ConstructHistoryFileNameWithoutMinorVersion(LPWSTR* o_wszHistoryFileNameWithoutMinorVersion,
  80. ULONG* o_iStartMinorVersion,
  81. LPWSTR i_wszHistroyFileSearchString,
  82. ULONG i_cchHistoryFileSearchString,
  83. LPWSTR i_wszFileNameExtension,
  84. ULONG i_cchFileNameExtension,
  85. ULONG i_ulMajorVersion);
  86. HRESULT
  87. SetSecurityOnFile(LPWSTR i_wszFileSrc,
  88. LPWSTR i_wszFileDest);
  89. HRESULT GetObjectFromPath(
  90. OUT CMDBaseObject *&rpboReturn,
  91. IN METADATA_HANDLE hHandle,
  92. IN DWORD dwPermissionNeeded,
  93. IN OUT LPTSTR &strPath,
  94. IN BOOL bUnicode = FALSE);
  95. HRESULT GetObjectFromPathWithHandle(
  96. OUT CMDBaseObject *&rpboReturn,
  97. IN METADATA_HANDLE hHandle,
  98. IN CMDHandle *hHandleObject,
  99. IN DWORD dwPermissionNeeded,
  100. IN OUT LPTSTR &strPath,
  101. IN BOOL bUnicode = FALSE);
  102. HRESULT AddObjectToDataBase(
  103. IN METADATA_HANDLE hHandle,
  104. IN CMDHandle *hHandleObject,
  105. IN LPTSTR strPath,
  106. IN BOOL bUnicode = FALSE);
  107. HRESULT RemoveObjectFromDataBase(IN METADATA_HANDLE hHandle,
  108. IN CMDHandle *hHandleObject,
  109. IN LPTSTR strPath,
  110. IN BOOL bUnicode = FALSE);
  111. CMDHandle *GetHandleObject(
  112. IN METADATA_HANDLE MetaDataHandle);
  113. BOOL
  114. PermissionsAvailable(
  115. IN CMDBaseObject *pboTest,
  116. IN DWORD dwRequestedPermissions,
  117. IN DWORD dwReadThreshhold
  118. );
  119. HRESULT
  120. AddHandle(
  121. CMDBaseObject *pboAssociated,
  122. DWORD dwRequestedPermissions,
  123. METADATA_HANDLE &rmhNew,
  124. BOOLEAN SchemaHandle
  125. );
  126. CMDHandle *
  127. RemoveHandleObject(
  128. IN METADATA_HANDLE hHandle
  129. );
  130. VOID
  131. AddPermissions(
  132. IN CMDBaseObject *pboAffected,
  133. IN DWORD dwRequestedPermissions
  134. );
  135. VOID RemovePermissions(
  136. IN CMDBaseObject *pboAffected,
  137. IN DWORD dwRemovePermissions
  138. );
  139. HRESULT
  140. SaveAllData(
  141. IN BOOL bSetSaveDisallowed,
  142. IN IIS_CRYPTO_STORAGE *pCryptoStorage,
  143. IN PIIS_CRYPTO_BLOB pSessionKeyBlob,
  144. IN LPWSTR pwszBackupLocation = NULL,
  145. IN LPWSTR pwszSchemaLocation = NULL,
  146. IN METADATA_HANDLE hHandle = METADATA_MASTER_ROOT_HANDLE,
  147. IN BOOL bHaveReadSaveSemaphore = FALSE,
  148. IN BOOL bTerminating = FALSE
  149. );
  150. HRESULT
  151. SaveSomeData(
  152. IN BOOL i_bSaveInherited,
  153. IN BOOL i_bSaveNodeOnly,
  154. IN BOOL i_bOverwriteFile,
  155. IN IIS_CRYPTO_STORAGE* i_pCryptoStorage,
  156. IN PIIS_CRYPTO_BLOB i_pSessionKeyBlob,
  157. IN LPCWSTR i_wszBackupLocation,
  158. IN METADATA_HANDLE i_hHandle,
  159. IN LPCWSTR i_wszSourcePath = NULL,
  160. IN BOOL i_bHaveReadSaveSemaphore = FALSE
  161. );
  162. HRESULT
  163. SaveTree(
  164. IN HANDLE hFileHandle,
  165. IN CMDBaseObject *pboRoot,
  166. IN PBYTE pbLineBuf,
  167. IN BUFFER *pbufParentPath,
  168. IN DWORD dwWriteBufSize,
  169. IN PBYTE pbWriteBuf,
  170. IN OUT PBYTE &pbrNextPtr,
  171. IN IIS_CRYPTO_STORAGE *pCryptoStorage
  172. );
  173. HRESULT
  174. SaveMasterRoot(HANDLE hFileHandle,
  175. PBYTE pbLineBuf,
  176. DWORD dwWriteBufSize,
  177. PBYTE pbWriteBuf,
  178. PBYTE &pbrNextPtr,
  179. IIS_CRYPTO_STORAGE *pCryptoStorage
  180. );
  181. DWORD
  182. MDTypeToRegType(
  183. DWORD dwMDType);
  184. HRESULT
  185. SaveDataObject(HANDLE hFileHandle,
  186. CMDBaseData *pbdSave,
  187. PBYTE pbLineBuf,
  188. DWORD dwWriteBufSize,
  189. PBYTE pbWriteBuf,
  190. PBYTE &pbrNextPtr,
  191. IIS_CRYPTO_STORAGE *pCryptoStorage
  192. );
  193. HRESULT
  194. ReadSomeDataFromXML(
  195. IN LPSTR i_pszPasswd,
  196. IN LPWSTR i_wszFileName,
  197. IN LPWSTR i_wszSourcePath,
  198. IN LPCWSTR i_wszKeyType,
  199. IN DWORD i_dwMDFlags,
  200. IN BOOL i_bHaveReadSaveSemaphore,
  201. OUT CMDBaseObject **o_ppboNew
  202. );
  203. HRESULT
  204. ReadAllData(LPSTR pszPasswd,
  205. LPSTR pszBackupLocation,
  206. LPSTR pszSchemaLocation,
  207. BOOL bHaveReadSaveSemaphore = FALSE
  208. );
  209. //
  210. // Next two routines used by EnumBackups and EnumHistory, respectively, to
  211. // validate enumerated files.
  212. //
  213. BOOL
  214. CheckDigits(LPTSTR pszString);
  215. HRESULT
  216. GetMostRecentHistoryFile(
  217. LPCWSTR i_wszPattern,
  218. DWORD* io_pdwMajor,
  219. DWORD* io_pdwMinor);
  220. HRESULT
  221. EnumFiles(IN LPWSTR i_wszPattern,
  222. IN DWORD i_dwMDEnumIndex,
  223. OUT DWORD *o_pdwMajor,
  224. OUT DWORD *o_pdwMinor,
  225. OUT PFILETIME o_pftMDBackupTime);
  226. HRESULT
  227. CopyMetaObject(
  228. IN METADATA_HANDLE hMDSourceHandle,
  229. IN unsigned char *pszMDSourcePath,
  230. BOOL bUseSourceHandle,
  231. CMDBaseObject* pboSource,
  232. IN METADATA_HANDLE hMDDestHandle,
  233. IN unsigned char *pszMDDestPath,
  234. IN BOOL bMDOverwriteFlag,
  235. IN BOOL bMDCopyFlag,
  236. IN BOOL bUnicode);
  237. HRESULT
  238. ReadMetaObject(
  239. IN CMDBaseObject *&cboRead,
  240. IN BUFFER *pbufLine,
  241. IN DWORD dwLineLen,
  242. IN IIS_CRYPTO_STORAGE * pCryptoStorage,
  243. IN BOOL bUnicode);
  244. HRESULT
  245. ReadDataObject(
  246. IN CMDBaseObject *cboAssociated,
  247. IN BUFFER *pbufLine,
  248. IN DWORD dwLineLen,
  249. IN IIS_CRYPTO_STORAGE * pCryptoStorage,
  250. IN BOOL bUnicode
  251. );
  252. HRESULT
  253. ReadDataObject(
  254. IN CMDBaseObject* cboAssociated,
  255. LPVOID* a_pv,
  256. ULONG* a_Size,
  257. IN IIS_CRYPTO_STORAGE* pCryptoStorage,
  258. IN BOOL bUnicode);
  259. HRESULT
  260. FlushWriteBuf(HANDLE hWriteFileHandle,
  261. PBYTE pbWriteBuf,
  262. PBYTE &pbrNextPtr);
  263. HRESULT
  264. WriteLine(HANDLE hWriteFileHandle,
  265. DWORD dwWriteBufSize,
  266. PBYTE pbWriteBuf,
  267. PBYTE pbLineBuf,
  268. PBYTE &pbNextPtr,
  269. DWORD dwLineLen,
  270. BOOL bTerminate);
  271. PBYTE
  272. FindEndOfData(PBYTE pbNextPtr,
  273. PBYTE pbEndReadData,
  274. BOOL bEscapePending);
  275. DWORD
  276. GetLineFromBuffer(PBYTE &pbrNextPtr,
  277. PBYTE &pbrEndReadData,
  278. BUFFER *pbufLine,
  279. DWORD &dwrLineLen,
  280. BOOL &brEscapePending);
  281. HRESULT
  282. GetNextLine(
  283. IN HANDLE hReadFileHandle,
  284. IN OUT PBYTE &pbrEndReadData,
  285. IN BUFFER *pbufRead,
  286. IN OUT BUFFER *pbufLine,
  287. IN OUT DWORD &dwrLineLen,
  288. IN OUT PBYTE &pbrNextPtr);
  289. DWORD
  290. GetLineID(
  291. IN OUT LPTSTR &strCurPtr);
  292. HRESULT
  293. GetWarning(
  294. IN HRESULT hresWarningCode);
  295. HRESULT
  296. InitWorker(BOOL bHaveReadSaveSemaphore,
  297. LPSTR pszPasswd,
  298. LPSTR pszBackupLocation,
  299. LPSTR pszSchemaLocation);
  300. HRESULT
  301. TerminateWorker1(
  302. IN BOOL bHaveReadSaveSemaphore
  303. );
  304. VOID
  305. TerminateWorker();
  306. VOID
  307. InitializeGlobalsToNull();
  308. HRESULT
  309. SetStorageSecurityDescriptor();
  310. VOID
  311. ReleaseStorageSecurityDescriptor();
  312. HRESULT
  313. ExtractNameFromPath(
  314. IN OUT LPSTR &strPath,
  315. OUT LPSTR strNameBuffer,
  316. IN BOOL bUnicode = FALSE);
  317. HRESULT
  318. ExtractNameFromPath(
  319. IN OUT LPWSTR *pstrPath,
  320. OUT LPWSTR strNameBuffer);
  321. HRESULT
  322. RemoveLastPartOfPath(
  323. IN OUT LPWSTR i_wszPath,
  324. IN int i_iLen);
  325. BOOL
  326. ValidateData(IN PMETADATA_RECORD pmdrData,
  327. IN BOOL bUnicode = FALSE);
  328. BOOL
  329. DataMatch(IN CMDBaseObject *pbdExisting,
  330. IN PMETADATA_RECORD pmdrData,
  331. OUT PBOOL pbError,
  332. IN BOOL bUnicode = FALSE);
  333. VOID
  334. DeleteDataObject(
  335. IN CMDBaseData *pbdDelete);
  336. VOID
  337. DeleteAllRemainingDataObjects();
  338. CMDBaseData *
  339. MakeDataObject(IN PMETADATA_RECORD pmdrMDData,
  340. IN BOOL bUnicode = FALSE);
  341. BOOL
  342. ValidateBackupLocation(LPSTR pszBackupLocation,
  343. BOOL bUnicode);
  344. DWORD
  345. GetBackupNameLen(LPSTR pszBackupName);
  346. DWORD
  347. GetBackupNameLen(LPWSTR pszBackupName);
  348. HRESULT
  349. GetHighestVersion(IN OUT STRAU *pstrauBackupLocation,
  350. OUT DWORD *pdwVersion);
  351. HRESULT CreateBackupFileName(IN LPSTR pszMDBackupLocation,
  352. IN DWORD dwMDVersion,
  353. IN BOOL bUnicode,
  354. IN OUT STRAU *pstrauBackupLocation,
  355. IN OUT STRAU *pstrauSchemaLocation);
  356. HRESULT SetBackupPath(LPSTR pszBackupPath);
  357. HRESULT
  358. SetGlobalDataFileValues(LPTSTR pszFileName);
  359. HRESULT
  360. SetUnicodeGlobalDataFileValues();
  361. void
  362. InitializeUnicodeGlobalDataFileValues();
  363. void
  364. UnInitializeUnicodeGlobalDataFileValues();
  365. HRESULT
  366. InitSessionKey(ISimpleTableRead2* pSITProperty,
  367. IIS_CRYPTO_STORAGE** ppStorage,
  368. LPSTR pszPasswd);
  369. HRESULT
  370. SetDataFile();
  371. DWORD
  372. GetObjectPath(CMDBaseObject *pboObject,
  373. BUFFER *pbufPath,
  374. DWORD &rdwStringLen,
  375. CMDBaseObject *pboTopObject,
  376. IN BOOL bUnicode = FALSE);
  377. HRESULT
  378. MakeInsertPathData(STRAU *pstrauData,
  379. LPTSTR pszPath,
  380. LPTSTR pszData,
  381. DWORD *pdwDataLen,
  382. IN BOOL bUnicode = FALSE);
  383. HRESULT
  384. InsertPathIntoData(BUFFER *pbufNewData,
  385. STRAU *pstrData,
  386. PBYTE *ppbNewData,
  387. DWORD *pdwNewDataLen,
  388. CMDBaseData *pbdRetrieve,
  389. METADATA_HANDLE hHandle,
  390. CMDBaseObject *pboDataMetaObject,
  391. IN BOOL bUnicode = FALSE);
  392. HRESULT
  393. ReplaceMasterRoot(
  394. CMDBaseObject* i_pboNew,
  395. CMDHandle* i_phoRootHandle);
  396. HRESULT
  397. MakeTreeCopyWithPath(CMDBaseObject *pboSource,
  398. CMDBaseObject *&rpboNew,
  399. LPSTR pszPath,
  400. IN BOOL bUnicode = FALSE);
  401. HRESULT
  402. MakeTreeCopy(CMDBaseObject *pboSource,
  403. CMDBaseObject *&pboNew,
  404. LPSTR pszName = NULL,
  405. IN BOOL bUnicode = FALSE);
  406. void
  407. AddNewChangeData(CMDHandle *phoDestParentHandle,
  408. CMDBaseObject *pboNew);
  409. HRESULT
  410. CopyTree(CMDHandle *phoDestParentHandle,
  411. CMDBaseObject *pboDest,
  412. CMDBaseObject *pboSource,
  413. BOOL &rbChanged);
  414. void
  415. CheckForNewMetabaseVersion();
  416. HRESULT
  417. CheckForSetup();
  418. BOOL
  419. CheckVersionNumber();
  420. VOID
  421. SkipPathDelimeter(IN OUT LPSTR &rpszPath,
  422. IN BOOL bUnicode = FALSE);
  423. BOOL
  424. IsStringTerminator(IN LPTSTR pszString,
  425. IN BOOL bUnicode = FALSE);
  426. #define IsSecureMetadata(id,att) \
  427. (((DWORD)(att) & METADATA_SECURE) != 0)
  428. HRESULT
  429. InitStorageAndSessionKey(
  430. IN IIS_CRYPTO_STORAGE *pCryptoStorage,
  431. OUT PIIS_CRYPTO_BLOB *ppSessionKeyBlob
  432. );
  433. HRESULT
  434. InitStorageAndSessionKey2(
  435. IN LPSTR pszPasswd,
  436. IN IIS_CRYPTO_STORAGE *pCryptoStorage,
  437. OUT PIIS_CRYPTO_BLOB *ppSessionKeyBlob
  438. );
  439. HRESULT
  440. GetLastHResult();
  441. HRESULT
  442. BackupCertificates (LPCWSTR backupName,PCHAR lpszToPath,PCHAR lpszFromPath);
  443. HRESULT
  444. RestoreCertificates (LPCWSTR backupName,PCHAR lpszFromPath,PCHAR lpszToPath);
  445. HRESULT
  446. LogEvent(ICatalogErrorLogger2* pLogger,
  447. DWORD dwError,
  448. DWORD dwErrorType,
  449. DWORD dwErrorCategory,
  450. DWORD dwHr,
  451. WCHAR* pString1 = NULL,
  452. WCHAR* pString2 = NULL,
  453. WCHAR* pString3 = NULL,
  454. WCHAR* pString4 = NULL,
  455. WCHAR* pString5 = NULL);
  456. DWORD
  457. GetMetabaseType(DWORD i_dwType,
  458. DWORD i_dwMetaFlags);
  459. HRESULT
  460. ReAllocateFileData(ULONG i_iFileData,
  461. METABASE_FILE_DATA** io_aFileData,
  462. ULONG* io_pcFileData,
  463. BOOL* io_pbReAlloced);
  464. void
  465. ResetFileAttributesIfNeeded(LPTSTR pszFile,
  466. BOOL bUnicode);
  467. HRESULT
  468. GetGlobalValue(ISimpleTableRead2* pISTProperty,
  469. LPCWSTR wszName,
  470. ULONG* pcbSize,
  471. LPVOID* ppVoid);
  472. HRESULT
  473. CompileIntoBinFromSchemaFile(IMetabaseSchemaCompiler* i_pCompiler,
  474. LPCWSTR i_wszSchemaFileName);
  475. HRESULT
  476. CompileIntoBin(IMetabaseSchemaCompiler* i_pCompiler,
  477. LPCWSTR i_wszSchemaExtensionFileName,
  478. LPCWSTR i_wszSchemaFileName);
  479. int
  480. _cdecl MyCompareFileData(const void *a,
  481. const void *b);
  482. #endif