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.

287 lines
11 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. admutil.cpp
  5. Abstract:
  6. IMSAdminBase interface WRAPPER functions definition
  7. Environment:
  8. Win32 User Mode
  9. Author:
  10. jaroslad (jan 1997)
  11. --*/
  12. #if !defined (ADMUTIL_H)
  13. #define ADMUTIL_H
  14. #include <afx.h>
  15. #ifdef UNICODE
  16. #include <iadmw.h>
  17. #else
  18. #include "ansimeta.h"
  19. #endif
  20. #include <iwamreg.h>
  21. class CAdmUtil;
  22. //************************************************************************
  23. //CAdmNode DEFINITION
  24. //- store all the complex information about accessing MetaObject or MetaData
  25. class CAdmNode
  26. {
  27. CString strComputer; //computer to access
  28. CString strService;
  29. CString strInstance;
  30. CString strIPath; //path relative to instance
  31. //(/LM/{strService}/{strInstance}/{strIPath} gives the full path to MEtaObject
  32. CString strProperty; // name of the MetaData within given Path
  33. static INT GetSlashIndex(const CString& strPath, INT iSeqNumber);
  34. static INT GetCountOfSlashes(const CString& strPath);
  35. static CString GetPartOfPath(const CString& strPath, INT iStart, INT iEnd=-1);
  36. public:
  37. CAdmNode(const CString& a_strPath=CString("")) {SetPath(a_strPath);};
  38. void SetPath(CString a_strPath);
  39. //magic functions to provide various kinds of paths within metabase
  40. CString GetLMRootPath(void);
  41. CString GetLMServicePath(void);
  42. CString GetLMInstancePath(void);
  43. CString GetLMNodePath(void);
  44. CString GetServicePath(void);
  45. CString GetInstancePath(void);
  46. CString GetNodePath(void);
  47. CString GetRelPathFromService(void);
  48. CString GetRelPathFromInstance(void);
  49. CString GetParentNodePath(void);
  50. CString GetCurrentNodeName(void);
  51. //access to METADATA_RECORD items
  52. CString GetComputer(void) {return strComputer;};
  53. CString GetService(void) {return strService;};
  54. CString GetInstance(void) {return strInstance;};
  55. CString GetIPath(void) {return strIPath;};
  56. CString GetProperty(void) {return strProperty;};
  57. //setting the METADATA_RECORD items
  58. void SetComputer(const CString& a_strComputer) {strComputer=a_strComputer;};
  59. void SetService(const CString& a_strService) {strService=a_strService;};
  60. void SetInstance(const CString& a_strInstance) {strInstance=a_strInstance;};
  61. void SetIPath(const CString& a_strIPath) {strIPath=a_strIPath;};
  62. void SetProperty(const CString& a_strProperty) {strProperty=a_strProperty;};
  63. friend CAdmUtil;
  64. };
  65. //************************************************************************
  66. //CAdmProp DEFINITION
  67. //
  68. // -convenience wrapper for METADATA_RECORD
  69. class CAdmProp
  70. {
  71. enum {USERTYPESET=0x01,DATATYPESET=0x02,ATTRIBSET=0x04}; //value indicates that the variable was not set
  72. //0 cannot be used, because that is valid value
  73. METADATA_RECORD mdr;
  74. DWORD dwFlags;
  75. public:
  76. CAdmProp(){dwFlags=0;mdr.dwMDIdentifier=0; mdr.dwMDAttributes=0; mdr.dwMDUserType=0;
  77. mdr.dwMDDataType=0;mdr.pbMDData=0; mdr.dwMDDataLen=0;};
  78. CAdmProp(METADATA_RECORD &a_mdr);
  79. CAdmProp(const CString &a_strProperty);
  80. void SetIdentifier(DWORD a_dwIdentif) {mdr.dwMDIdentifier=a_dwIdentif;};
  81. void SetAttrib(DWORD a_dwAttrib) {mdr.dwMDAttributes=a_dwAttrib;dwFlags|=ATTRIBSET;};
  82. void SetUserType(DWORD a_dwUserType) {mdr.dwMDUserType=a_dwUserType;dwFlags|=USERTYPESET;};
  83. void SetDataType(DWORD a_dwDataType) {mdr.dwMDDataType=a_dwDataType;dwFlags|=DATATYPESET;};
  84. BOOL IsSetAttrib(void)
  85. { return (((dwFlags&ATTRIBSET)!=0)?TRUE:FALSE); };
  86. BOOL IsSetUserType(void)
  87. {return (((dwFlags&USERTYPESET)!=0)?TRUE:FALSE); };
  88. BOOL IsSetDataType(void)
  89. {return (((dwFlags&DATATYPESET)!=0)?TRUE:FALSE); };
  90. DWORD GetAttrib(void) {return mdr.dwMDAttributes;};
  91. DWORD GetDataType(void) {return mdr.dwMDDataType;};
  92. DWORD GetUserType(void) {return mdr.dwMDUserType;};
  93. DWORD GetIdentifier(void) {return mdr.dwMDIdentifier;};
  94. PBYTE GetMDData(void) {return mdr.pbMDData;};
  95. DWORD GetMDDataLen(void) {return mdr.dwMDDataLen;};
  96. void SetValue(DWORD a_dwValue);
  97. void SetValue(CString a_strValue);
  98. void SetValue(LPCTSTR *a_lplpszValue, DWORD a_dwValueCount); //for multisz
  99. void SetValue(LPBYTE pbValue, DWORD dwValueLength ); //for binary
  100. BOOL SetValueByDataType(LPCTSTR *a_lplpszPropValue,DWORD* a_lpdwPropValueLength,WORD a_wPropValueCount);
  101. void PrintProperty(void);
  102. virtual void Print(const _TCHAR *format,...);
  103. friend CAdmUtil;
  104. };
  105. //************************************************************************
  106. //CAdmUtil DEFINITION
  107. //
  108. //-convenience wrapper for calling IMSAdminBase interface functions
  109. //defined in admutil.cpp
  110. extern DWORD g_dwTIMEOUT_VALUE;
  111. extern DWORD g_dwDELAY_AFTER_OPEN_VALUE;
  112. class CAdmUtil
  113. {
  114. static enum {
  115. DEFAULTBufferSize=4
  116. };
  117. #ifdef UNICODE
  118. IMSAdminBase * pcAdmCom; //interface pointer to Metabase Admin
  119. #else
  120. ANSI_smallIMSAdminBase * pcAdmCom; //interface pointer to Metabase Admin Ansi Wrapper
  121. #endif
  122. IWamAdmin* pIWamAdm; //interface pointer to Wam Admin
  123. METADATA_HANDLE m_hmd; //metabase handle that micht be reused for sequence of commands
  124. CString m_strNodePath; //related to m_hmd - if h_hmd!=NULL it points to m_strNodePath
  125. DWORD m_dwPermissionOfhmd; //related to m_hmd
  126. PBYTE pbDataBuffer; //buffer to get data from METABASE (used for METADATA_RECORD)
  127. WORD wDataBufferSize; //size of the above buffer
  128. protected:
  129. BOOL fPrint ; //print Error messages
  130. HRESULT hresError; //store the last HRESULT of calling interface IMSAdminBase interface function
  131. // this is used to store some other error as is OUT_OF_MEMORY or INVALID_PARAMETER
  132. //with wIndex it is possible to open more than one METADATA object, opening multiple object is not available outside the class
  133. void OpenObject(WORD wIndex, LPCSTR lpszService,WORD wInstance, LPCSTR lpszPath, DWORD dwPermission=METADATA_PERMISSION_WRITE+METADATA_PERMISSION_READ, BOOL fCreate=TRUE);
  134. void CloseObject(WORD wIndex);
  135. METADATA_HANDLE OpenObjectTo_hmd(CAdmNode & a_AdmNode,
  136. DWORD dwPermission=METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
  137. BOOL fCreate=FALSE);
  138. void CloseObject_hmd(void);
  139. public:
  140. CAdmUtil(const CString & strComputer=CString(""));
  141. ~CAdmUtil();
  142. #ifdef UNICODE
  143. IMSAdminBase * GetpcAdmCom(void) {return pcAdmCom;};
  144. #else
  145. IMSAdminBase * GetpcAdmCom(void) {return (pcAdmCom==0)?0:pcAdmCom->m_pcAdmCom;};
  146. #endif
  147. //connect to computer, call class factory for IMSAdminBase
  148. void Open(const CString & strComputer);
  149. //close connection to computer, throw away IMSAdminBase
  150. void Close(void);
  151. //OPEN , CLOSE, CREATE, DELETE, COPY METAOBJECT
  152. METADATA_HANDLE OpenObject(CAdmNode & a_AdmNode,
  153. DWORD dwPermission=METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
  154. BOOL fCreate=FALSE);
  155. void CloseObject(METADATA_HANDLE hmd);
  156. void CreateObject(CAdmNode & a_AdmNode);
  157. void DeleteObject(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  158. void DeleteObject(METADATA_HANDLE a_hmd, CString& a_strNodeNameToDelete);
  159. void CopyObject(CAdmNode& a_AdmNode, CAdmNode& a_AdmNodeDst);
  160. void RenameObject(CAdmNode& a_AdmNode, CAdmNode& a_AdmNodeDst);
  161. void GetProperty(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  162. void SetProperty(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  163. void SetProperty(PMETADATA_RECORD a_pmdrData, METADATA_HANDLE a_hmd);
  164. void DeleteProperty(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  165. void DeleteProperty(PMETADATA_RECORD a_pmdrData, METADATA_HANDLE a_hmd);
  166. //ENUMERATE
  167. void EnumPropertiesAndPrint(CAdmNode& a_AdmNode,
  168. CAdmProp a_AdmProp,
  169. BYTE bRecurLevel=0,
  170. METADATA_HANDLE a_hmd=0,
  171. CString & a_strRelPath=CString(""));
  172. void EnumAndPrint(CAdmNode& a_AdmNode,
  173. CAdmProp& a_AdmProp,
  174. BOOL a_fRecursive=FALSE,
  175. BYTE a_bRecurLevel=0,
  176. METADATA_HANDLE a_hmd=0,
  177. CString& a_strRelPath=CString(""));
  178. //SAVE METABASE DATA
  179. void SaveData(void);
  180. //FUNCTION TO RUN CHOSEN METABASE COMMAND WITH GIVEN PARAMATERS
  181. void Run(CString& strCommand, //command to run
  182. CAdmNode& a_AdmNode, //PATH TO METABASE OBJECT
  183. CAdmProp& a_AdmProp, //METADATA object
  184. CAdmNode& a_AdmDstNode=CAdmNode(""), //DESTINATION PATH (as used for COPY)
  185. LPCTSTR *a_lplpszPropValue=0, //VALUES TO BE STORED (for SET command)
  186. DWORD *a_lpdwPropValueLength=0, //LENGTH OF VALUES TO BE STORED (for SET command)
  187. WORD wPropValueCount=0); //NUMBER OF VALUES TO BE STORED
  188. //virtual functions for Error and regular messages to be printed.
  189. // these can be redefined in order to fit custom needs
  190. virtual void Error(const _TCHAR * format,...);
  191. virtual void Print(const _TCHAR * format,...);
  192. //Disable and enable to print error or regular messages
  193. void EnablePrint(void) {fPrint=TRUE;};
  194. void DisablePrint(void) {fPrint=FALSE;};
  195. HRESULT QueryLastHresError(void) {return hresError;};
  196. void SetLastHresError(HRESULT hr) {hresError=hr;};
  197. //defined in vptool
  198. void OpenWamAdm(const CString & strComputer);
  199. void CloseWamAdm(void);
  200. void AppCreateInProc(const _TCHAR* szPath,const CString & strComputer);
  201. void AppCreateOutProc(const _TCHAR* szPath,const CString & strComputer);
  202. void AppDelete(const _TCHAR* szPath,const CString & strComputer);
  203. void AppRename(CAdmNode& a_AdmNode, CAdmNode& a_AdmDstNode, const CString & strComputer);
  204. void AppUnLoad(const _TCHAR* szPath,const CString & strComputer);
  205. void AppGetStatus(const _TCHAR* szPath,const CString & strComputer);
  206. };
  207. //runs administration command based on given parameters
  208. LPTSTR ConvertHresToString(HRESULT hRes);
  209. DWORD ConvertHresToDword(HRESULT hRes);
  210. LPTSTR ConvertReturnCodeToString(DWORD ReturnCode);
  211. CString FindCommonPath(CString a_strPath1,CString a_strPath2);
  212. #define M_LOCAL_MACHINE "/LM/"
  213. #endif