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.

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