Source code of Windows XP (NT5)
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.

251 lines
8.0 KiB

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