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.

260 lines
6.3 KiB

  1. /*++
  2. Module Name:
  3. DfsRep.cpp
  4. Abstract:
  5. This COM Class provides method to get information of Dfs replica.
  6. --*/
  7. #include "stdafx.h"
  8. #include "DfsCore.h"
  9. #include "DfsRep.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CDfsReplica
  12. CDfsReplica::CDfsReplica()
  13. {
  14. dfsDebugOut((_T("CDfsReplica::CDfsReplica this=%p\n"), this));
  15. }
  16. CDfsReplica::~CDfsReplica()
  17. {
  18. dfsDebugOut((_T("CDfsReplica::~CDfsReplica this=%p\n"), this));
  19. }
  20. /////////////////////////////////////////////////////////////////////////////
  21. // get_State
  22. STDMETHODIMP CDfsReplica :: get_State
  23. (
  24. long* pVal
  25. )
  26. {
  27. if (!pVal)
  28. return E_INVALIDARG;
  29. *pVal = m_lDfsReferralState;
  30. return S_OK;
  31. }
  32. /////////////////////////////////////////////////////////////////////////////
  33. // put_State
  34. STDMETHODIMP CDfsReplica :: put_State
  35. (
  36. long newVal
  37. )
  38. {
  39. DFS_INFO_101 DfsInfoLevel101 = {0};
  40. if (DFS_REFERRAL_STATE_OFFLINE == newVal)
  41. DfsInfoLevel101.State = DFS_STORAGE_STATE_OFFLINE;
  42. else if (DFS_REFERRAL_STATE_ONLINE == newVal)
  43. DfsInfoLevel101.State = DFS_STORAGE_STATE_ONLINE;
  44. else
  45. return E_INVALIDARG;
  46. NET_API_STATUS nstatRetVal = NetDfsSetInfo (
  47. m_bstrEntryPath,
  48. m_bstrStorageServerName,
  49. m_bstrStorageShareName,
  50. 101,
  51. (LPBYTE) &DfsInfoLevel101
  52. );
  53. dfsDebugOut((_T("NetDfsSetInfo entry=%s, server=%s, share=%s, level 101 for State, nRet=%d\n"),
  54. m_bstrEntryPath, m_bstrStorageServerName, m_bstrStorageShareName, nstatRetVal));
  55. if (NERR_Success == nstatRetVal)
  56. m_lDfsReferralState = newVal;
  57. return HRESULT_FROM_WIN32 (nstatRetVal);
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. // get_StorageServerName
  61. STDMETHODIMP CDfsReplica :: get_StorageServerName
  62. (
  63. BSTR* pVal
  64. )
  65. {
  66. if (!pVal)
  67. return E_INVALIDARG;
  68. *pVal = m_bstrStorageServerName.Copy ();
  69. if (!*pVal)
  70. return E_OUTOFMEMORY;
  71. return S_OK;
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // get_StorageShareName
  75. STDMETHODIMP CDfsReplica :: get_StorageShareName
  76. (
  77. BSTR* pVal
  78. )
  79. {
  80. if (!pVal)
  81. return E_INVALIDARG;
  82. *pVal = m_bstrStorageShareName.Copy ();
  83. if (!*pVal)
  84. return E_OUTOFMEMORY;
  85. return S_OK;
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // Initialize
  89. STDMETHODIMP CDfsReplica :: Initialize
  90. (
  91. BSTR i_szEntryPath,
  92. BSTR i_szStorageServerName,
  93. BSTR i_szStorageShareName,
  94. long i_lDfsStorageState
  95. )
  96. {
  97. /*++
  98. Routine Description:
  99. Initializes the DfsReplica object. Should be called after CoCreateInstance.
  100. If initialisation fails all properties will be NULL.
  101. Arguments:
  102. i_szEntryPath - The entry path to the Replica.
  103. i_szStorageServerName - The name of the server which hosts the share the replica exists on.
  104. i_szStorageShareName - The name of the share.
  105. --*/
  106. if (!i_szEntryPath || !i_szStorageServerName || !i_szStorageShareName)
  107. return E_INVALIDARG;
  108. _FreeMemberVariables ();
  109. HRESULT hr = S_OK;
  110. do {
  111. m_bstrEntryPath = i_szEntryPath;
  112. BREAK_OUTOFMEMORY_IF_NULL((BSTR)m_bstrEntryPath, &hr);
  113. m_bstrStorageServerName = i_szStorageServerName;
  114. BREAK_OUTOFMEMORY_IF_NULL((BSTR)m_bstrStorageServerName, &hr);
  115. m_bstrStorageShareName = i_szStorageShareName;
  116. BREAK_OUTOFMEMORY_IF_NULL((BSTR)m_bstrStorageShareName, &hr);
  117. if (DFS_STORAGE_STATE_ONLINE == i_lDfsStorageState)
  118. {
  119. m_lDfsReferralState = DFS_REFERRAL_STATE_ONLINE;
  120. } else if (DFS_STORAGE_STATE_OFFLINE == i_lDfsStorageState)
  121. {
  122. m_lDfsReferralState = DFS_REFERRAL_STATE_OFFLINE;
  123. } else
  124. {
  125. hr = E_INVALIDARG;
  126. break;
  127. }
  128. } while (0);
  129. if (FAILED(hr))
  130. _FreeMemberVariables ();
  131. return hr;
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // get_EntryPath
  135. STDMETHODIMP CDfsReplica :: get_EntryPath
  136. (
  137. BSTR* pVal
  138. )
  139. {
  140. if (!pVal)
  141. return E_INVALIDARG;
  142. *pVal = m_bstrEntryPath.Copy ();
  143. if (!*pVal)
  144. return E_OUTOFMEMORY;
  145. return S_OK;
  146. }
  147. /////////////////////////////////////////////////////////////////////////////
  148. // FindTarget
  149. STDMETHODIMP CDfsReplica::FindTarget
  150. (
  151. )
  152. {
  153. PDFS_INFO_3 pDfsInfo = NULL;
  154. NET_API_STATUS nstatRetVal = NetDfsGetInfo (
  155. m_bstrEntryPath,
  156. m_bstrStorageServerName,
  157. m_bstrStorageShareName,
  158. 3,
  159. (LPBYTE*)&pDfsInfo
  160. );
  161. dfsDebugOut((_T("NetDfsGetInfo entry=%s, server=%s, share=%s, level 3 for FindTarget, nRet=%d\n"),
  162. m_bstrEntryPath, m_bstrStorageServerName, m_bstrStorageShareName, nstatRetVal));
  163. if (nstatRetVal != NERR_Success)
  164. {
  165. if (nstatRetVal == NERR_DfsNoSuchVolume)
  166. return S_FALSE;
  167. else
  168. return HRESULT_FROM_WIN32(nstatRetVal);
  169. }
  170. BOOL bFound = FALSE;
  171. LPDFS_STORAGE_INFO pStorageInfo = pDfsInfo->Storage;
  172. for (UINT i=0; i < pDfsInfo->NumberOfStorages; i++, pStorageInfo++)
  173. {
  174. if ( !lstrcmpi(pStorageInfo->ServerName, m_bstrStorageServerName) &&
  175. !lstrcmpi(pStorageInfo->ShareName, m_bstrStorageShareName) )
  176. {
  177. bFound = TRUE;
  178. break;
  179. }
  180. }
  181. NetApiBufferFree(pDfsInfo);
  182. return (bFound ? S_OK : S_FALSE);
  183. }
  184. /////////////////////////////////////////////////////////////////////////////
  185. // _FreeMemberVariables
  186. void CDfsReplica :: _FreeMemberVariables ()
  187. {
  188. m_bstrEntryPath.Empty();
  189. m_bstrStorageServerName.Empty();
  190. m_bstrStorageShareName.Empty();
  191. m_lDfsReferralState = DFS_REFERRAL_STATE_OFFLINE;
  192. }