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.

323 lines
8.7 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: sdoserverinfo.cpp
  4. //
  5. // Synopsis: Implementation of CSdoServerInfo class methods
  6. //
  7. //
  8. // History: 06/04/98 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "sdoserverinfo.h"
  16. #include <activeds.h>
  17. #include <security.h>
  18. const DWORD MAX_DOMAINNAME_LENGTH = 1024;
  19. //++--------------------------------------------------------------
  20. //
  21. // Function: CSdoServerInfo
  22. //
  23. // Synopsis: This is CSdoServerInfo Class constructor
  24. //
  25. // Arguments: NONE
  26. //
  27. // Returns: NONE
  28. //
  29. // History: MKarki Created 06/04/98
  30. //
  31. //----------------------------------------------------------------
  32. CSdoServerInfo::CSdoServerInfo()
  33. :m_bIsNT5 (false)
  34. {
  35. DWORD dwSize = sizeof (OSVERSIONINFO);
  36. OSVERSIONINFO VersionInfo;
  37. ZeroMemory (&VersionInfo, dwSize);
  38. VersionInfo.dwOSVersionInfoSize = dwSize;
  39. //
  40. // find out which system type this is
  41. //
  42. m_bIsNT5 =
  43. (GetVersionEx (&VersionInfo) && (5 == VersionInfo.dwMajorVersion));
  44. } // end of CSdoServerInfo class constructor
  45. //++--------------------------------------------------------------
  46. //
  47. // Function: ~CSdoServerInfo
  48. //
  49. // Synopsis: This is CSdoSeverInfo class destructor
  50. //
  51. // Arguments: NONE
  52. //
  53. // Returns: NONE
  54. //
  55. //
  56. // History: MKarki Created 2/10/98
  57. //
  58. //----------------------------------------------------------------
  59. CSdoServerInfo ::~CSdoServerInfo()
  60. {
  61. } // end of CSdoServerInfo class destructor
  62. //++--------------------------------------------------------------
  63. //
  64. // Function: GetOSInfo
  65. //
  66. // Synopsis: This is GetOSInfo method of the
  67. // ISdoServerInfo COM Interface.
  68. //
  69. // Arguments:
  70. // [in] BSTR - Computer Name
  71. // [out] PIASOSTYPE
  72. //
  73. // Returns: HRESULT - status
  74. //
  75. //
  76. // History: MKarki Created 06/09/98
  77. //
  78. //----------------------------------------------------------------
  79. HRESULT
  80. CSdoServerInfo::GetOSInfo (
  81. /*[in]*/ BSTR bstrServerName,
  82. /*[out]*/ PIASOSTYPE pOSType
  83. )
  84. {
  85. WCHAR szComputerName [MAX_COMPUTERNAME_LENGTH +1];
  86. DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH +1;
  87. DWORD dwErrorCode = ERROR_SUCCESS;
  88. _ASSERT(NULL != pOSType);
  89. if (NULL == pOSType)
  90. {
  91. IASTracePrintf(
  92. "Error in Server Information SDO - GetOSInfo()"
  93. " - invalid argument passed in"
  94. );
  95. return E_INVALIDARG;
  96. }
  97. //
  98. // check if the user wants to get Info about local machine
  99. //
  100. if ( NULL == bstrServerName )
  101. {
  102. if ( FALSE == ::GetComputerName (szComputerName, &dwBufferSize))
  103. {
  104. dwErrorCode = GetLastError ();
  105. IASTracePrintf(
  106. "Error in Server Information SDO - GetOSInfo()"
  107. "GetComputerName() failed with error: %d",
  108. dwErrorCode
  109. );
  110. return (HRESULT_FROM_WIN32 (dwErrorCode));
  111. }
  112. else
  113. {
  114. bstrServerName = szComputerName;
  115. }
  116. }
  117. // call the IASSDO.DLL specific method to return the
  118. // required information
  119. //
  120. return (::SdoGetOSInfo (bstrServerName, pOSType));
  121. } // end of CSdoServerInfo::GetOSInfo method
  122. //++--------------------------------------------------------------
  123. //
  124. // Function: GetDomainInfo
  125. //
  126. // Synopsis: This is the ISdoServerInfo Interface method.
  127. //
  128. // Arguments:
  129. // [in] OBJECTTYPE
  130. // [in] BSTR - Object Id
  131. // [out] PDOMAINTYPE
  132. //
  133. // Returns: HRESULT - status
  134. //
  135. //
  136. // History: MKarki Created 06/09/98
  137. //
  138. //----------------------------------------------------------------
  139. HRESULT
  140. CSdoServerInfo::GetDomainInfo (
  141. /*[in]*/ OBJECTTYPE ObjectType,
  142. /*[in]*/ BSTR bstrObjectId,
  143. /*[out]*/ PIASDOMAINTYPE pDomainType
  144. )
  145. {
  146. HRESULT hr = S_OK;
  147. WCHAR szDomainName[MAX_DOMAINNAME_LENGTH +1];
  148. WCHAR szComputerName [MAX_COMPUTERNAME_LENGTH +1];
  149. DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH +1;
  150. _ASSERT (NULL != pDomainType);
  151. if (NULL == pDomainType)
  152. {
  153. IASTracePrintf(
  154. "Error in Server Information SDO - GetDomainInfo()"
  155. " - invalid argument passed in (PIASDOMAINTYPE==NULL)"
  156. );
  157. return (E_INVALIDARG);
  158. }
  159. // for now we are not supporting this API if this is not
  160. // a NT 5 machine
  161. //
  162. if ( false == m_bIsNT5 )
  163. {
  164. IASTracePrintf(
  165. "Error in Server Information SDO - GetDomainInfo()"
  166. " - Not an NT 5 machine..."
  167. );
  168. return (E_NOTIMPL);
  169. }
  170. switch (ObjectType)
  171. {
  172. case OBJECT_TYPE_COMPUTER:
  173. //
  174. // check if the user wants to get Info about local machine
  175. //
  176. if ( NULL == bstrObjectId)
  177. {
  178. if ( FALSE == ::GetComputerName (szComputerName, &dwBufferSize))
  179. {
  180. DWORD dwErrorCode = GetLastError ();
  181. IASTracePrintf(
  182. "Error in Server Information SDO - GetDomainInfo()"
  183. "GetComputerName() failed with error: %d",
  184. dwErrorCode
  185. );
  186. hr = HRESULT_FROM_WIN32 (dwErrorCode);
  187. break;
  188. }
  189. else
  190. {
  191. bstrObjectId = szComputerName;
  192. }
  193. }
  194. //
  195. // call the API to get the appropriate info
  196. //
  197. hr = ::SdoGetDomainInfo (
  198. bstrObjectId,
  199. NULL,
  200. pDomainType
  201. );
  202. if (FAILED (hr))
  203. {
  204. IASTracePrintf(
  205. "Error in Server Information SDO"
  206. " - GetDomainInfo() - SetDomainInfo() failed:%x",
  207. hr
  208. );
  209. break;
  210. }
  211. break;
  212. case OBJECT_TYPE_USER:
  213. //
  214. // get the domain name from the ADsPath
  215. //
  216. hr = GetDomainFromADsPath (bstrObjectId, szDomainName);
  217. if (FAILED (hr))
  218. {
  219. IASTracePrintf(
  220. "Error in Server Information SDO GetDomainInfo()"
  221. " - GetDomainFromADsPath() failed with error:%x",
  222. hr
  223. );
  224. break;
  225. }
  226. //
  227. //
  228. // call the API to get the appropriate info
  229. //
  230. hr = ::SdoGetDomainInfo (
  231. NULL,
  232. szDomainName,
  233. pDomainType
  234. );
  235. if (FAILED (hr))
  236. {
  237. IASTracePrintf(
  238. "Error in Server Information SDO - GetDomainInfo()"
  239. " - SdoGetDomainInfo() failed with error:%x",
  240. hr
  241. );
  242. break;
  243. }
  244. break;
  245. default:
  246. IASTracePrintf(
  247. "Error in Server Information SDO - GetDomainInfo()"
  248. " - Invalid object type:%d",
  249. ObjectType
  250. );
  251. hr = E_INVALIDARG;
  252. break;
  253. }
  254. return (hr);
  255. } // end of CSdoServerInfo::GetDomainInfo method
  256. //++--------------------------------------------------------------
  257. //
  258. // Function: GetDomainFromADsPath
  259. //
  260. // Synopsis: This is the CSdoServerInfo class private method.
  261. // used to convert a ADsPath to a Domain Name
  262. //
  263. // Arguments:
  264. // [in] LPCWSTR - ADsPath
  265. // [out] PWSTR - Domain Name
  266. //
  267. // Returns: HRESULT - status
  268. //
  269. //
  270. // History: MKarki Created 06/09/98
  271. //
  272. //----------------------------------------------------------------
  273. HRESULT
  274. CSdoServerInfo::GetDomainFromADsPath (
  275. /*[in]*/ LPCWSTR pObjectId,
  276. /*[out]*/ LPWSTR pszDomainName
  277. )
  278. {
  279. _ASSERT ((NULL != pObjectId) && (NULL != pszDomainName));
  280. // copy the name to the buffer to be returned
  281. //
  282. wcscpy (pszDomainName, pObjectId);
  283. PWCHAR pTemp = wcschr (pszDomainName, L'/');
  284. if (NULL != pTemp)
  285. {
  286. //
  287. // we only need the domain name part of the ADsPath
  288. //
  289. *pTemp = L'\0';
  290. }
  291. return (S_OK);
  292. } // end of CSdoServerInfo::GetDomainFromADsPath method