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.

289 lines
12 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. IWamAdmin2* pIWamAdm2; //interface pointer to Wam Admin
  124. METADATA_HANDLE m_hmd; //metabase handle that micht be reused for sequence of commands
  125. CString m_strNodePath; //related to m_hmd - if h_hmd!=NULL it points to m_strNodePath
  126. DWORD m_dwPermissionOfhmd; //related to m_hmd
  127. PBYTE pbDataBuffer; //buffer to get data from METABASE (used for METADATA_RECORD)
  128. WORD wDataBufferSize; //size of the above buffer
  129. protected:
  130. BOOL fPrint ; //print Error messages
  131. HRESULT hresError; //store the last HRESULT of calling interface IMSAdminBase interface function
  132. // this is used to store some other error as is OUT_OF_MEMORY or INVALID_PARAMETER
  133. //with wIndex it is possible to open more than one METADATA object, opening multiple object is not available outside the class
  134. void OpenObject(WORD wIndex, LPCSTR lpszService,WORD wInstance, LPCSTR lpszPath, DWORD dwPermission=METADATA_PERMISSION_WRITE+METADATA_PERMISSION_READ, BOOL fCreate=TRUE);
  135. void CloseObject(WORD wIndex);
  136. METADATA_HANDLE OpenObjectTo_hmd(CAdmNode & a_AdmNode,
  137. DWORD dwPermission=METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
  138. BOOL fCreate=FALSE);
  139. void CloseObject_hmd(void);
  140. public:
  141. CAdmUtil(const CString & strComputer=CString(""));
  142. ~CAdmUtil();
  143. #ifdef UNICODE
  144. IMSAdminBase * GetpcAdmCom(void) {return pcAdmCom;};
  145. #else
  146. IMSAdminBase * GetpcAdmCom(void) {return (pcAdmCom==0)?0:pcAdmCom->m_pcAdmCom;};
  147. #endif
  148. //connect to computer, call class factory for IMSAdminBase
  149. void Open(const CString & strComputer);
  150. //close connection to computer, throw away IMSAdminBase
  151. void Close(void);
  152. //OPEN , CLOSE, CREATE, DELETE, COPY METAOBJECT
  153. METADATA_HANDLE OpenObject(CAdmNode & a_AdmNode,
  154. DWORD dwPermission=METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
  155. BOOL fCreate=FALSE);
  156. void CloseObject(METADATA_HANDLE hmd);
  157. void CreateObject(CAdmNode & a_AdmNode);
  158. void DeleteObject(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  159. void DeleteObject(METADATA_HANDLE a_hmd, CString& a_strNodeNameToDelete);
  160. void CopyObject(CAdmNode& a_AdmNode, CAdmNode& a_AdmNodeDst);
  161. void RenameObject(CAdmNode& a_AdmNode, CAdmNode& a_AdmNodeDst);
  162. void GetProperty(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  163. void SetProperty(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  164. void SetProperty(PMETADATA_RECORD a_pmdrData, METADATA_HANDLE a_hmd);
  165. void DeleteProperty(CAdmNode& a_AdmNode, CAdmProp& a_AdmProp);
  166. void DeleteProperty(PMETADATA_RECORD a_pmdrData, METADATA_HANDLE a_hmd);
  167. //ENUMERATE
  168. void EnumPropertiesAndPrint(CAdmNode& a_AdmNode,
  169. CAdmProp a_AdmProp,
  170. BYTE bRecurLevel, // =0
  171. METADATA_HANDLE a_hmd, // =0
  172. CString & a_strRelPath); // = CString("")
  173. void EnumAndPrint(CAdmNode& a_AdmNode,
  174. CAdmProp& a_AdmProp,
  175. BOOL a_fRecursive, // =FALSE
  176. BYTE a_bRecurLevel, // =0
  177. METADATA_HANDLE a_hmd, // =0
  178. CString& a_strRelPath); // CString("")
  179. //SAVE METABASE DATA
  180. void SaveData(void);
  181. //FUNCTION TO RUN CHOSEN METABASE COMMAND WITH GIVEN PARAMATERS
  182. void Run(CString& strCommand, //command to run
  183. CAdmNode& a_AdmNode, //PATH TO METABASE OBJECT
  184. CAdmProp& a_AdmProp, //METADATA object
  185. CAdmNode& a_AdmDstNode, //=CAdmNode(""), //DESTINATION PATH (as used for COPY)
  186. LPCTSTR *a_lplpszPropValue=0, //VALUES TO BE STORED (for SET command)
  187. DWORD *a_lpdwPropValueLength=0, //LENGTH OF VALUES TO BE STORED (for SET command)
  188. WORD wPropValueCount=0); //NUMBER OF VALUES TO BE STORED
  189. //virtual functions for Error and regular messages to be printed.
  190. // these can be redefined in order to fit custom needs
  191. virtual void Error(const _TCHAR * format,...);
  192. virtual void Print(const _TCHAR * format,...);
  193. //Disable and enable to print error or regular messages
  194. void EnablePrint(void) {fPrint=TRUE;};
  195. void DisablePrint(void) {fPrint=FALSE;};
  196. HRESULT QueryLastHresError(void) {return hresError;};
  197. void SetLastHresError(HRESULT hr) {hresError=hr;};
  198. //defined in vptool
  199. void OpenWamAdm(const CString & strComputer);
  200. void CloseWamAdm(void);
  201. void AppCreateInProc(const _TCHAR* szPath,const CString & strComputer);
  202. void AppCreateOutPool(const _TCHAR* szPath,const CString & strComputer);
  203. void AppCreateOutProc(const _TCHAR* szPath,const CString & strComputer);
  204. void AppDelete(const _TCHAR* szPath,const CString & strComputer);
  205. void AppRename(CAdmNode& a_AdmNode, CAdmNode& a_AdmDstNode, const CString & strComputer);
  206. void AppUnLoad(const _TCHAR* szPath,const CString & strComputer);
  207. void AppGetStatus(const _TCHAR* szPath,const CString & strComputer);
  208. };
  209. //runs administration command based on given parameters
  210. LPTSTR ConvertHresToString(HRESULT hRes);
  211. DWORD ConvertHresToDword(HRESULT hRes);
  212. LPTSTR ConvertReturnCodeToString(DWORD ReturnCode);
  213. CString FindCommonPath(CString a_strPath1,CString a_strPath2);
  214. #define M_LOCAL_MACHINE "/LM/"
  215. #endif