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.

255 lines
9.3 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. GETMAC.H
  5. Abstract:
  6. Contains function prototypes and macros.
  7. Author:
  8. Vasundhara .G
  9. Revision History:
  10. Vasundhara .G 26-sep-2k : Created It.
  11. Vasundhara .G 31-oct-2k : Modified.
  12. Added macros and some #defines.
  13. --*/
  14. #ifndef __GETMAC_H
  15. #define __GETMAC_H
  16. // constants / defines / enumerations
  17. #define MAX_STRING 256
  18. #define MAX_OPTIONS 7
  19. #define MAX_COLUMNS 5
  20. #define USAGE_END 37
  21. //Command line parser index
  22. #define CMD_PARSE_SERVER 0
  23. #define CMD_PARSE_USER 1
  24. #define CMD_PARSE_PWD 2
  25. #define CMD_PARSE_FMT 3
  26. #define CMD_PARSE_USG 4
  27. #define CMD_PARSE_HRD 5
  28. #define CMD_PARSE_VER 6
  29. //show results index
  30. #define SH_RES_HOST 0
  31. #define SH_RES_CON 1
  32. #define SH_RES_TYPE 2
  33. #define SH_RES_MAC 3
  34. #define SH_RES_TRAN 4
  35. //wmi registry key value
  36. #define WMI_HKEY_CLASSES_ROOT 2147483648
  37. #define WMI_HKEY_CURRENT_USER 2147483649
  38. #define WMI_HKEY_LOCAL_MACHINE 2147483650
  39. #define WMI_HKEY_USERS 2147483651
  40. #define WMI_HKEY_CURRENT_CONFIG 2147482652
  41. // Error constants
  42. #define ERROR_USER_WITH_NOSERVER GetResString( IDS_USER_NMACHINE )
  43. #define ERROR_SERVER_WITH_NOPASSWORD GetResString( IDS_SERVER_NPASSWORD )
  44. #define ERROR_NULL_SERVER GetResString( IDS_NULL_SERVER )
  45. #define ERROR_NULL_USER GetResString( IDS_NULL_USER )
  46. #define ERROR_INVALID_HEADER_OPTION GetResString( IDS_INVALID_OPTIONS )
  47. #define ERROR_TYPE_REQUEST GetResString( IDS_TYPE_REQUEST )
  48. #define ERROR_STRING GetResString( IDS_ERROR_STRING )
  49. #define ERROR_VERSION_MISMATCH GetResString( IDS_ERROR_VERSION_MISMATCH )
  50. #define ERROR_NOT_RESPONDING GetResString( IDS_NOT_RESPONDING )
  51. #define ERROR_NO_MACHINE GetResString( IDS_NO_MACHINE )
  52. #define ERROR_INVALID_MACHINE GetResString( IDS_INVALID_MACHINE )
  53. #define ERROR_WKST_NOT_FOUND GetResString( IDS_WKST_NOT_FOUND )
  54. //warning message
  55. #define IGNORE_LOCALCREDENTIALS GetResString( IDS_IGNORE_LOCALCREDENTIALS )
  56. #define WARNING_STRING GetResString( IDS_WARNING_STRING )
  57. //info message
  58. #define NO_NETWORK_ADAPTERS GetResString( IDS_NO_NETWORK_ADAPTERS )
  59. #define NO_NETWOK_PROTOCOLS GetResString( IDS_NO_NETWOK_PROTOCOLS )
  60. //show results column length
  61. #define HOST_NAME_WIDTH AsLong(GetResString( IDS_HOST_NAME_WIDTH ),10 )
  62. #define CONN_NAME_WIDTH AsLong(GetResString( IDS_CONN_NAME_WIDTH ),10 )
  63. #define ADAPT_TYPE_WIDTH AsLong(GetResString( IDS_ADAPT_TYPE_WIDTH ),10 )
  64. #define MAC_ADDR_WIDTH AsLong(GetResString( IDS_MAC_ADDR_WIDTH ),10 )
  65. #define TRANS_NAME_WIDTH AsLong(GetResString( IDS_TRANS_NAME_WIDTH ),10 )
  66. //output headers strings
  67. #define RES_HOST_NAME GetResString( RES_HOST )
  68. #define RES_CONNECTION_NAME GetResString( RES_CONNECTION )
  69. #define RES_ADAPTER_TYPE GetResString( RES_ADAPTER )
  70. #define RES_MAC_ADDRESS GetResString( RES_ADDRESS )
  71. #define RES_TRANS_NAME GetResString( RES_TRANSNAME )
  72. //general
  73. #define NOT_AVAILABLE GetResString( IDS_NOT_AVAILABLE )
  74. #define DISABLED GetResString( IDS_DISABLED )
  75. #define HYPHEN_STRING GetResString( IDS_HYPHEN_STRING )
  76. #define COLON_STRING GetResString( IDS_COLON_STRING )
  77. #define NEW_LINE GetResString( IDS_NEW_LINE )
  78. #define FORMAT_TYPES GetResString( IDS_FORMAT_TYPES )
  79. //registry key names
  80. #define DEFAULT_ADDRESS _T( "000000000000" )
  81. #define CONNECTION_KEYPATH _T( "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" )
  82. #define TRANSPORT_KEYPATH _T( "SYSTEM\\CurrentControlSet\\Services\\" )
  83. #define LINKAGE _T( "\\Linkage" )
  84. #define ROUTE _T( "route" )
  85. #define EXPORT _T( "Export" )
  86. #define CONNECTION_STRING _T( "\\Connection" )
  87. #define REG_NAME _T( "name" )
  88. #define NETBIOS _T( "NetBIOS" )
  89. //command line options
  90. #define CMDOPTION_SERVER _T( "s" )
  91. #define CMDOPTION_USER _T( "u" )
  92. #define CMDOPTION_PASSWORD _T( "p" )
  93. #define CMDOPTION_FORMAT _T( "fo" )
  94. #define CMDOPTION_USAGE _T( "?" )
  95. #define CMDOPTION_HEADER _T( "nh" )
  96. #define CMDOPTION_VERBOSE _T( "v" )
  97. #define TOKEN_BACKSLASH2 _T( "\\\\" )
  98. #define TOKEN_BACKSLASH3 _T( "\\\\\\" )
  99. //wmi classes and property names
  100. #define HYPHEN_CHAR L'-'
  101. #define COLON_CHAR L':'
  102. #define BACK_SLASHS L"\\\\"
  103. #define BACK_SLASH L"\\"
  104. #define NETCONNECTION_STATUS L"NetConnectionStatus"
  105. #define ADAPTER_MACADDR L"MACAddress"
  106. #define NETCONNECTION_ID L"NetConnectionID"
  107. #define DEVICE_ID L"DeviceID"
  108. #define NAME L"Name"
  109. #define HOST_NAME L"SystemName"
  110. #define SETTING_ID L"SettingID"
  111. #define NETWORK_ADAPTER_CLASS L"Win32_NetworkAdapter"
  112. #define NETWORK_ADAPTER_CONFIG_CLASS L"Win32_NetworkAdapterConfiguration"
  113. #define NETWORK_PROTOCOL L"Win32_NetworkProtocol"
  114. #define CLASS_CIMV2_Win32_OperatingSystem L"Win32_OperatingSystem"
  115. #define QUERY_LANGUAGE L"WQL"
  116. #define ASSOCIATOR_QUERY _T( "ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=\"" )
  117. #define ASSOCIATOR_QUERY1 _T( "\"} WHERE ResultClass=Win32_NetworkAdapterConfiguration" )
  118. #define SUCCESS 0
  119. #define FAILURE 1
  120. #define WMI_NAMESPACE_CIMV2 L"root\\cimv2"
  121. #define WMI_NAMESPACE_DEFAULT L"root\\default"
  122. #define WMI_CLAUSE_AND L"AND"
  123. #define WMI_CLAUSE_OR L"OR"
  124. #define WMI_CLAUSE_WHERE L"WHERE"
  125. #define WMI_REGISTRY L"StdRegProv"
  126. #define WMI_REGISTRY_M_STRINGVALUE L"GetStringValue"
  127. #define WMI_REGISTRY_M_MSTRINGVALUE L"GetMultiStringValue"
  128. #define WMI_REGISTRY_IN_HDEFKEY L"hDefKey"
  129. #define WMI_REGISTRY_IN_SUBKEY L"sSubKeyName"
  130. #define WMI_REGISTRY_IN_VALUENAME L"sValueName"
  131. #define WMI_REGISTRY_OUT_VALUE L"sValue"
  132. #define WMI_REGISTRY_OUT_RETURNVALUE L"ReturnValue"
  133. #define CAPTION L"Caption"
  134. #define SAFERELEASE( pIObj ) \
  135. if ( NULL != pIObj ) \
  136. { \
  137. pIObj->Release(); \
  138. pIObj = NULL; \
  139. }
  140. #define SAFEBSTRRELEASE( pIObj ) \
  141. if ( NULL != pIObj ) \
  142. { \
  143. SysFreeString( pIObj ); \
  144. pIObj = NULL; \
  145. }
  146. #define ONFAILTHROWERROR(hResult) \
  147. if (FAILED(hResult)) \
  148. { \
  149. _com_issue_error(hResult); \
  150. }
  151. #define SAFE_RELEASE( interfacepointer ) \
  152. if ( (interfacepointer) != NULL ) \
  153. { \
  154. (interfacepointer)->Release(); \
  155. (interfacepointer) = NULL; \
  156. } \
  157. 1
  158. #define SAFE_EXECUTE( statement ) \
  159. hRes = statement; \
  160. if ( FAILED( hRes ) ) \
  161. { \
  162. _com_issue_error( hRes ); \
  163. } \
  164. 1
  165. //function prototype
  166. BOOL
  167. ConnectWmi(
  168. IN IWbemLocator *pLocator,
  169. OUT IWbemServices **ppServices,
  170. IN LPCWSTR pwszServer,
  171. OUT LPCWSTR pwszUser,
  172. OUT LPCWSTR pwszPassword,
  173. OUT COAUTHIDENTITY **ppAuthIdentity,
  174. IN BOOL bCheckWithNullPwd = FALSE,
  175. IN LPCWSTR pwszNamespace = WMI_NAMESPACE_CIMV2,
  176. OUT HRESULT *phRes = NULL,
  177. OUT BOOL *pbLocalSystem = NULL
  178. );
  179. BOOL
  180. ConnectWmiEx(
  181. IN IWbemLocator *pLocator,
  182. OUT IWbemServices **ppServices,
  183. IN LPCWSTR pwszServer,
  184. OUT CHString &strUserName,
  185. OUT CHString &strPassword,
  186. OUT COAUTHIDENTITY **ppAuthIdentity,
  187. IN BOOL bNeedPassword = FALSE,
  188. IN LPCWSTR pszNamespace = WMI_NAMESPACE_CIMV2,
  189. OUT BOOL *pbLocalSystem = NULL
  190. );
  191. BOOL
  192. IsValidServerEx(
  193. IN LPCWSTR pwszServer,
  194. OUT BOOL &bLocalSystem
  195. );
  196. HRESULT
  197. SetInterfaceSecurity(
  198. IN IUnknown *pInterface,
  199. IN COAUTHIDENTITY *pAuthIdentity
  200. );
  201. VOID
  202. WINAPI WbemFreeAuthIdentity(
  203. IN COAUTHIDENTITY **ppAuthIdentity
  204. );
  205. VOID
  206. WMISaveError(
  207. IN HRESULT hResError
  208. );
  209. DWORD
  210. GetTargetVersionEx(
  211. IN IWbemServices* pWbemServices,
  212. IN COAUTHIDENTITY* pAuthIdentity
  213. );
  214. // inline functions
  215. inline VOID WMISaveError( _com_error &e )
  216. {
  217. WMISaveError( e.Error() );
  218. }
  219. #endif // __GETMAC_H