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.

532 lines
13 KiB

  1. /****
  2. SchmUtil.h
  3. Various common utility routines for the Schema Editor Snap-In.
  4. ****/
  5. #include "cache.h"
  6. #include "cookie.h"
  7. #include "select.h"
  8. #ifndef __SCHMUTIL_H_INCLUDED__
  9. #define __SCHMUTIL_H_INCLUDED__
  10. //
  11. // uncomment to enable the negative numbers support
  12. //
  13. #define ENABLE_NEGATIVE_INT
  14. // Returns the full pathname of the .hlp file for this snapin
  15. CString
  16. GetHelpFilename();
  17. //
  18. // The global list of class scope cookies.
  19. //
  20. class CCookieListEntry {
  21. public:
  22. CCookieListEntry() :
  23. pCookie( NULL ),
  24. pNext( this ),
  25. pBack( this ) { ; }
  26. ~CCookieListEntry() { ; }
  27. Cookie *pCookie;
  28. HSCOPEITEM hScopeItem;
  29. CCookieListEntry *pNext;
  30. CCookieListEntry *pBack;
  31. };
  32. class CCookieList
  33. {
  34. public:
  35. CCookieList() :
  36. pHead( NULL ),
  37. pParentCookie( NULL ) { ; }
  38. ~CCookieList() { DeleteAll(); }
  39. VOID AddCookie( Cookie *pCookie,
  40. HSCOPEITEM hScope );
  41. VOID InsertSortedDisplay( ComponentData *pScopeControl,
  42. SchemaObject *pNewClass );
  43. bool DeleteCookie(Cookie* pCookie);
  44. void
  45. DeleteAll();
  46. //
  47. // Data members.
  48. //
  49. Cookie *pParentCookie;
  50. HSCOPEITEM hParentScopeItem;
  51. CCookieListEntry *pHead;
  52. //
  53. // We provide no functions to walk this list. The
  54. // user of this list has to walk it manually.
  55. //
  56. };
  57. //
  58. // Some schema magic numbers.
  59. //
  60. #define CLASS_TYPE_88 0
  61. #define CLASS_TYPE_STRUCTURAL 1
  62. #define CLASS_TYPE_ABSTRACT 2
  63. #define CLASS_TYPE_AUXILIARY 3
  64. #define ATTRIBUTE_OPTIONAL 1
  65. #define ATTRIBUTE_MANDATORY 2
  66. //
  67. // Global DS class and attribute strings.
  68. //
  69. extern LPWSTR g_DisplayName;
  70. extern LPWSTR g_ClassFilter;
  71. extern LPWSTR g_AttributeFilter;
  72. extern LPWSTR g_Description;
  73. extern LPWSTR g_MayContain;
  74. extern LPWSTR g_MustContain;
  75. extern LPWSTR g_SystemMayContain;
  76. extern LPWSTR g_SystemMustContain;
  77. extern LPWSTR g_AuxiliaryClass;
  78. extern LPWSTR g_SystemAuxiliaryClass;
  79. extern LPWSTR g_SubclassOf;
  80. extern LPWSTR g_ObjectClassCategory;
  81. extern LPWSTR g_ObjectClass;
  82. extern LPWSTR g_CN;
  83. extern LPWSTR g_ClassSearchRequest;
  84. extern LPWSTR g_AttribSearchRequest;
  85. extern LPWSTR g_omSyntax;
  86. extern LPWSTR g_AttributeSyntax;
  87. extern LPWSTR g_omObjectClass;
  88. extern LPWSTR g_SystemOnly;
  89. extern LPWSTR g_Superiors;
  90. extern LPWSTR g_SystemSuperiors;
  91. extern LPWSTR g_GlobalClassID;
  92. extern LPWSTR g_GlobalAttributeID;
  93. extern LPWSTR g_RangeUpper;
  94. extern LPWSTR g_RangeLower;
  95. extern LPWSTR g_ShowInAdvViewOnly;
  96. extern LPWSTR g_IsSingleValued;
  97. extern LPWSTR g_IndexFlag;
  98. extern LPWSTR g_UpdateSchema;
  99. extern LPWSTR g_isDefunct;
  100. extern LPWSTR g_GCReplicated;
  101. extern LPWSTR g_DefaultAcl;
  102. extern LPWSTR g_DefaultCategory;
  103. extern LPWSTR g_systemFlags;
  104. extern LPWSTR g_fsmoRoleOwner;
  105. extern LPWSTR g_allowedChildClassesEffective;
  106. extern LPWSTR g_allowedAttributesEffective;
  107. //
  108. // *******************************************************************
  109. // These are loaded from the resources as they need to be localizable.
  110. // *******************************************************************
  111. //
  112. //
  113. // Global strings for our static nodes.
  114. //
  115. extern CString g_strSchmMgmt;
  116. extern CString g_strClasses;
  117. extern CString g_strAttributes;
  118. //
  119. // Strings for various object types.
  120. //
  121. extern CString g_88Class;
  122. extern CString g_StructuralClass;
  123. extern CString g_AuxClass;
  124. extern CString g_AbstractClass;
  125. extern CString g_MandatoryAttribute;
  126. extern CString g_OptionalAttribute;
  127. extern CString g_Yes;
  128. extern CString g_No;
  129. extern CString g_Unknown;
  130. extern CString g_Defunct;
  131. extern CString g_Active;
  132. //
  133. // Message strings.
  134. //
  135. extern CString g_NoDescription;
  136. extern CString g_NoName;
  137. extern CString g_MsgBoxErr;
  138. extern CString g_MsgBoxWarn;
  139. extern CString g_SysClassString;
  140. extern CString g_SysAttrString;
  141. //
  142. // Utility function declarations.
  143. //
  144. void
  145. LoadGlobalCookieStrings(
  146. );
  147. VOID
  148. DebugTrace(
  149. LPWSTR Format,
  150. ...
  151. );
  152. INT
  153. DoErrMsgBox(
  154. HWND hwndParent,
  155. BOOL fError,
  156. UINT wIdString
  157. );
  158. INT
  159. DoErrMsgBox(
  160. HWND hwndParent,
  161. BOOL fError,
  162. PCWSTR pszError
  163. );
  164. VOID
  165. DoExtErrMsgBox(
  166. VOID
  167. );
  168. // INVALID_POINTER is returned by CListBox::GetItemDataPtr() in case of an error.
  169. extern const VOID * INVALID_POINTER;
  170. // add items from the VT_ARRAY|VT_BSTR variant to the listbox
  171. HRESULT
  172. InsertEditItems(
  173. HWND hwnd,
  174. VARIANT *AdsResult
  175. );
  176. // as above but takes a CListBox&
  177. inline HRESULT
  178. InsertVariantEditItems(
  179. CListBox& refListBox,
  180. VARIANT *AdsResult
  181. )
  182. {
  183. return InsertEditItems( refListBox.m_hWnd, AdsResult );
  184. }
  185. // add items from stringlist to the listbox
  186. HRESULT
  187. InsertEditItems(
  188. CListBox& refListBox,
  189. CStringList& refstringlist
  190. );
  191. // Add items from the listbox to the stringlist, skipping those
  192. // from the exclusion stringlist if one is present
  193. HRESULT
  194. RetrieveEditItemsWithExclusions(
  195. CListBox& refListBox,
  196. CStringList& refstringlist,
  197. CStringList* pstringlistExclusions = NULL
  198. );
  199. // Helper function for octet string comparisson
  200. BOOL
  201. IsEqual( ADS_OCTET_STRING * ostr1, ADS_OCTET_STRING * ostr2 );
  202. UINT
  203. GetSyntaxOrdinal(
  204. PCTSTR attributeSyntax, UINT omSyntax, ADS_OCTET_STRING * omObjectClass
  205. );
  206. // add items from the VT_ARRAY|VT_BSTR variant to the stringlist
  207. HRESULT
  208. VariantToStringList(
  209. VARIANT& refvar,
  210. CStringList& refstringlist
  211. );
  212. // Creates a new VT_ARRAY|VT_BSTR variant from the stringlist
  213. HRESULT
  214. StringListToVariant(
  215. VARIANT& refvar,
  216. CStringList& refstringlist
  217. );
  218. HRESULT
  219. StringListToColumnList(
  220. ComponentData* pScopeControl,
  221. CStringList& refstringlist,
  222. ListEntry **ppNewList
  223. );
  224. //
  225. // The menu command ids.
  226. //
  227. enum MENU_COMMAND
  228. {
  229. CLASSES_CREATE_CLASS = 0,
  230. ATTRIBUTES_CREATE_ATTRIBUTE,
  231. SCHEMA_RETARGET,
  232. SCHEMA_EDIT_FSMO,
  233. SCHEMA_REFRESH,
  234. SCHEMA_SECURITY,
  235. NEW_CLASS,
  236. NEW_ATTRIBUTE,
  237. MENU_LAST_COMMAND
  238. };
  239. //
  240. // The menu strings.
  241. //
  242. extern CString g_MenuStrings[MENU_LAST_COMMAND];
  243. extern CString g_StatusStrings[MENU_LAST_COMMAND];
  244. //
  245. // Schema Object Syntax Descriptor class
  246. //
  247. class CSyntaxDescriptor
  248. {
  249. public:
  250. CSyntaxDescriptor( UINT nResourceID,
  251. BOOL fIsSigned, // Should the range be signed or unsigned number?
  252. BOOL fIsANRCapable,
  253. PCTSTR pszAttributeSyntax,
  254. UINT nOmSyntax,
  255. DWORD dwOmObjectClass,
  256. LPBYTE pOmObjectClass ) :
  257. m_nResourceID(nResourceID),
  258. m_fIsSigned(fIsSigned),
  259. m_fIsANRCapable(fIsANRCapable),
  260. m_pszAttributeSyntax(pszAttributeSyntax),
  261. m_nOmSyntax(nOmSyntax)
  262. {
  263. ASSERT( nResourceID );
  264. ASSERT( (!pszAttributeSyntax && !nOmSyntax) || // either both are given
  265. (pszAttributeSyntax && nOmSyntax) ); // or both are 0
  266. ASSERT( (!dwOmObjectClass && !pOmObjectClass) || // either both are given
  267. (dwOmObjectClass && pOmObjectClass) ); // or both are 0
  268. m_octstrOmObjectClass.dwLength = dwOmObjectClass;
  269. m_octstrOmObjectClass.lpValue = pOmObjectClass;
  270. };
  271. UINT m_nResourceID;
  272. BOOL m_fIsSigned;
  273. BOOL m_fIsANRCapable;
  274. PCTSTR m_pszAttributeSyntax;
  275. UINT m_nOmSyntax;
  276. ADS_OCTET_STRING m_octstrOmObjectClass;
  277. CString m_strSyntaxName;
  278. };
  279. extern CSyntaxDescriptor g_Syntax[];
  280. extern const UINT SCHEMA_SYNTAX_UNKNOWN;
  281. extern const LPWSTR g_UINT32_FORMAT;
  282. extern const LPWSTR g_INT32_FORMAT;
  283. //
  284. // ADS Provider Specific Extended Error
  285. //
  286. const HRESULT ADS_EXTENDED_ERROR = HRESULT_FROM_WIN32(ERROR_EXTENDED_ERROR);
  287. CString
  288. GetErrorMessage( HRESULT hr, BOOL fTryADSIExtError = FALSE );
  289. HRESULT
  290. GetLastADsError( HRESULT hr, CString& refErrorMsg, CString& refName );
  291. //
  292. // string to dword conversion utils, verification, etc.
  293. //
  294. const DWORD cchMinMaxRange = 11; // the largest numbers possible in the Range settings
  295. const DWORD cchMaxOID = 1024;
  296. const BOOL GETSAFEINT_ALLOW_CANCEL = TRUE;
  297. const HRESULT S_VALUE_MODIFIED = S_FALSE;
  298. const WCHAR g_chSpace = TEXT(' ');
  299. const WCHAR g_chNegativeSign = TEXT('-');
  300. const WCHAR g_chPeriod = TEXT('.');
  301. void DDXV_VerifyAttribRange( CDataExchange *pDX, BOOL fIsSigned,
  302. UINT idcLower, CString & strLower,
  303. UINT idcUpper, CString & strUpper );
  304. INT64 DDXV_SigUnsigINT32Value( CDataExchange *pDX, BOOL fIsSigned,
  305. UINT idc, CString & str );
  306. HRESULT GetSafeSignedDWORDFromString( CWnd * pwndParent, DWORD & lDst, CString & strSrc,
  307. BOOL fIsSigned, BOOL fAllowCancel = FALSE);
  308. HRESULT GetSafeINT32FromString( CWnd * pwndParent, INT64 & llDst, CString & strSrc,
  309. BOOL fIsSigned, BOOL fAllowCancel);
  310. BOOL IsValidNumber32( INT64 & llVal, BOOL fIsSigned );
  311. BOOL IsValidNumberString( CString & str );
  312. inline BOOL IsCharNumeric( WCHAR ch )
  313. {
  314. return IsCharAlphaNumeric( ch ) && !IsCharAlpha( ch );
  315. }
  316. /////////////////////////////////////////////////////////////////////////////
  317. // CParsedEdit is a specialized CEdit control that only allows characters
  318. // of the number type ( signed/unsigned can be set dynamically )
  319. // originally from the MFC samples
  320. class CParsedEdit : public CEdit
  321. {
  322. public:
  323. enum EditType
  324. {
  325. EDIT_TYPE_INVALID = 0, // should never be used, must be the first type
  326. EDIT_TYPE_GENERIC,
  327. EDIT_TYPE_INT32,
  328. EDIT_TYPE_UINT32,
  329. EDIT_TYPE_OID,
  330. EDIT_TYPE_LAST // should never be used, must be the last type
  331. };
  332. private:
  333. EditType m_editType;
  334. public:
  335. // Construction
  336. CParsedEdit( EditType et ) { SetEditType( et ); }
  337. // subclassed construction
  338. BOOL SubclassEdit( UINT nID,
  339. CWnd* pParent,
  340. int cchMaxTextSize ); // 0 == unlimited
  341. // Edit box type
  342. protected:
  343. static BOOL IsNumericType( EditType et ) { return EDIT_TYPE_INT32 == et || EDIT_TYPE_UINT32 == et; }
  344. static BOOL IsValidEditType( EditType et ) { return EDIT_TYPE_INVALID < et && et < EDIT_TYPE_LAST; }
  345. BOOL IsInitialized() const { return IsValidEditType( m_editType ); }
  346. // can the current type be changed to et?
  347. BOOL IsCompatibleType( EditType et ) { ASSERT( IsValidEditType( et ) );
  348. return !IsInitialized() || // everything is ok
  349. et == GetEditType() || // no change
  350. ( IsNumericType(GetEditType()) && // allow sign/unsign
  351. IsNumericType(et)) ; } // switch
  352. void SetEditType( EditType et ) { ASSERT( IsValidEditType(et) );
  353. ASSERT( IsCompatibleType(et) );
  354. m_editType = et; }
  355. public:
  356. EditType GetEditType() const { ASSERT( IsInitialized() ); // initialized?
  357. return m_editType; }
  358. // IsSigned access functions
  359. BOOL FIsSigned() const { ASSERT( IsNumericType(GetEditType()) );
  360. return EDIT_TYPE_INT32 == GetEditType(); }
  361. void SetSigned( BOOL fIsSigned ) { ASSERT( IsInitialized() );
  362. SetEditType( fIsSigned ? EDIT_TYPE_INT32 : EDIT_TYPE_UINT32 ); }
  363. // Implementation
  364. protected:
  365. //{{AFX_MSG(CParsedEdit)
  366. afx_msg void OnChar(UINT, UINT, UINT); // for character validation
  367. //}}AFX_MSG
  368. DECLARE_MESSAGE_MAP()
  369. };
  370. ///////////////////////////////////////////////////////////////////////////////
  371. // Search a list of PCTSTR for a strValue, returns TRUE if found
  372. // rgszList[] last element must be NULL
  373. //
  374. // puIndex - optional pointer, will be set to the position of the value if found.
  375. //
  376. BOOL IsInList( PCTSTR rgszList[], const CString & strValue, UINT * puIndex = NULL );
  377. //
  378. // Determine if the object pointed to by pIADsObject is category 1 object.
  379. //
  380. HRESULT IsCategory1Object( IADs *pIADsObject, BOOL & fIsCategory1 );
  381. //
  382. // Determine if the object pointed to by pIADsObject is a constructed object.
  383. //
  384. HRESULT IsConstructedObject( IADs *pIADsObject, BOOL & fIsConstructed );
  385. //
  386. // Read object's System Attribute
  387. //
  388. HRESULT GetSystemAttributes( IADs *pIADsObject, LONG &fSysAttribs );
  389. //
  390. //
  391. //
  392. class CDialogControlsInfo
  393. {
  394. public:
  395. UINT m_nID;
  396. LPCTSTR m_pszAttributeName;
  397. BOOL m_fIsEditBox;
  398. };
  399. HRESULT DissableReadOnlyAttributes( CWnd * pwnd, IADs *pIADsObject, const CDialogControlsInfo * pCtrls, UINT cCtrls );
  400. HRESULT GetStringListElement( IADs *pIADsObject, LPWSTR *lppPathNames, CStringList &strlist );
  401. //
  402. // Validate an OID string format
  403. //
  404. bool OIDHasValidFormat (PCWSTR pszOidValue, int& rErrorTypeStrID);
  405. HRESULT DeleteObject( const CString& path, Cookie* pcookie, PCWSTR pszClass);
  406. #endif