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.

112 lines
3.4 KiB

  1. #include "shellprv.h"
  2. #include "util.h"
  3. #include "datautil.h"
  4. #include "idlcomm.h"
  5. #include "stgutil.h"
  6. #include "ole2dup.h"
  7. STDAPI StgCopyFileToStream(LPCTSTR pszSrc, IStream *pStream)
  8. {
  9. IStream *pStreamSrc;
  10. DWORD grfModeSrc = STGM_READ | STGM_DIRECT | STGM_SHARE_DENY_WRITE;
  11. HRESULT hr = SHCreateStreamOnFileEx(pszSrc, grfModeSrc, 0, FALSE, NULL, &pStreamSrc);
  12. if (SUCCEEDED(hr))
  13. {
  14. ULARGE_INTEGER ulMax = {-1, -1};
  15. hr = pStreamSrc->CopyTo(pStream, ulMax, NULL, NULL);
  16. pStreamSrc->Release();
  17. }
  18. if (SUCCEEDED(hr))
  19. {
  20. hr = pStream->Commit(STGC_DEFAULT);
  21. }
  22. return hr;
  23. }
  24. STDAPI StgBindToObject(LPCITEMIDLIST pidl, DWORD grfMode, REFIID riid, void **ppv)
  25. {
  26. IBindCtx *pbc;
  27. HRESULT hr = BindCtx_CreateWithMode(grfMode, &pbc);
  28. if (SUCCEEDED(hr))
  29. {
  30. hr = SHBindToObjectEx(NULL, pidl, pbc, riid, ppv);
  31. pbc->Release();
  32. }
  33. return hr;
  34. }
  35. typedef HRESULT (WINAPI * PSTGOPENSTORAGEONHANDLE)(HANDLE,DWORD,void*,void*,REFIID,void**);
  36. STDAPI SHStgOpenStorageOnHandle(HANDLE h, DWORD grfMode, void *res1, void *res2, REFIID riid, void **ppv)
  37. {
  38. static PSTGOPENSTORAGEONHANDLE pfn = NULL;
  39. if (pfn == NULL)
  40. {
  41. HMODULE hmodOle32 = LoadLibraryA("ole32.dll");
  42. if (hmodOle32)
  43. {
  44. pfn = (PSTGOPENSTORAGEONHANDLE)GetProcAddress(hmodOle32, "StgOpenStorageOnHandle");
  45. }
  46. }
  47. if (pfn)
  48. {
  49. return pfn(h, grfMode, res1, res2, riid, ppv);
  50. }
  51. else
  52. {
  53. return E_OUTOFMEMORY;
  54. }
  55. }
  56. STDAPI StgOpenStorageOnFolder(LPCTSTR pszFolder, DWORD grfFlags, REFIID riid, void **ppv)
  57. {
  58. *ppv = NULL;
  59. DWORD dwDesiredAccess, dwShareMode, dwCreationDisposition;
  60. HRESULT hr = ModeToCreateFileFlags(grfFlags, FALSE, &dwDesiredAccess, &dwShareMode, &dwCreationDisposition);
  61. if (SUCCEEDED(hr))
  62. {
  63. // For IPropertySetStorage, we don't want to unnecessarily tie up access to the folder, if all
  64. // we're doing is dealing with property sets. The implementation of IPropertySetStorage for
  65. // NTFS files is defined so that the sharing/access only applies to the property set stream, not
  66. // it's other streams. So it makes sense to do a CreateFile on a folder with full sharing, while perhaps specifying
  67. // STGM_SHARE_EXCLUSIVE for the property set storage.
  68. if (riid == IID_IPropertySetStorage)
  69. dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
  70. // FILE_FLAG_BACKUP_SEMANTICS to get a handle on the folder
  71. HANDLE h = CreateFile(pszFolder, dwDesiredAccess, dwShareMode, NULL,
  72. dwCreationDisposition, FILE_FLAG_BACKUP_SEMANTICS, INVALID_HANDLE_VALUE);
  73. if (INVALID_HANDLE_VALUE != h)
  74. {
  75. hr = SHStgOpenStorageOnHandle(h, grfFlags, NULL, NULL, riid, ppv);
  76. CloseHandle(h);
  77. }
  78. else
  79. {
  80. hr = HRESULT_FROM_WIN32(GetLastError());
  81. }
  82. }
  83. return hr;
  84. }
  85. // various helper classes removed for security push -- if it gets RI'd back into Lab06 somehow
  86. // and they're needed, just put em back.
  87. // this includes a wrapper for docfile IStorages to make them play nice and a shortcut-storage
  88. // which dereferences links on the fly.
  89. //
  90. // gpease 05-MAR-2003
  91. // If you do put them back, make sure the Release implementation is correct!
  92. //