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.

330 lines
11 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows NT Directory Service Property Pages
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1999
  7. //
  8. // File: dscmn.h
  9. //
  10. // Contents: Methods exported from DSPROP.DLL for use in DSADMIN.DLL
  11. //
  12. // History: 19-February-98 JonN created
  13. //
  14. //-----------------------------------------------------------------------------
  15. #ifndef _DSCMN_H_
  16. #define _DSCMN_H_
  17. #include <ADsOpenFlags.h> // GetADsOpenObjectFlags
  18. //
  19. // Illegal characters that cannot be used in the UPN or SAM Account name
  20. //
  21. #define INVALID_ACCOUNT_NAME_CHARS L"\"/\\[]:|<>+=;,?,*"
  22. #define INVALID_ACCOUNT_NAME_CHARS_WITH_AT L"\"/\\[]:|<>+=;,?,*@"
  23. // This GUID is copied from ds\setup\schema.ini
  24. #define SZ_GUID_CONTROL_UserChangePassword L"ab721a53-1e2f-11d0-9819-00aa0040529b"
  25. extern const GUID GUID_CONTROL_UserChangePassword;
  26. /* add this to your source:
  27. const GUID GUID_CONTROL_UserChangePassword =
  28. { 0xab721a53, 0x1e2f, 0x11d0, { 0x98, 0x19, 0x00, 0xaa, 0x00, 0x40, 0x52, 0x9b}};
  29. */
  30. HRESULT DSPROP_PickComputer(
  31. IN HWND hwndParent,
  32. IN LPCWSTR lpcwszRootPath, // only the server name is used
  33. OUT BSTR* pbstrADsPath );
  34. HRESULT DSPROP_PickNTDSDSA(
  35. IN HWND hwndParent,
  36. IN LPCWSTR lpcwszRootPath,
  37. OUT BSTR* pbstrADsPath );
  38. HRESULT DSPROP_DSQuery(
  39. IN HWND hwndParent,
  40. IN LPCWSTR lpcwszRootPath,
  41. IN CLSID* pclsidDefaultForm,
  42. OUT BSTR* pbstrADsPath );
  43. HRESULT DSPROP_IsFrsObject( IN LPWSTR pszClassName, OUT bool* pfIsFrsObject );
  44. HRESULT DSPROP_RemoveX500LeafElements(
  45. IN unsigned int nElements,
  46. IN OUT BSTR* pbstrADsPath );
  47. HRESULT DSPROP_TweakADsPath(
  48. IN LPCWSTR lpcwszInitialADsPath,
  49. IN int iTargetLevelsUp,
  50. IN PWCHAR* ppwszTargetLevelsBack,
  51. OUT BSTR* pbstrResultDN
  52. );
  53. HRESULT DSPROP_RetrieveRDN(
  54. IN LPCWSTR lpwszDN,
  55. OUT BSTR* pbstrRDN
  56. );
  57. //HRESULT DSPROP_GetGCSearch(
  58. // IN REFIID iid,
  59. // OUT void** ppvObject
  60. // );
  61. HRESULT DSPROP_GetGCSearchOnDomain(
  62. PWSTR pwzDomainDnsName,
  63. IN REFIID iid,
  64. OUT void** ppvObject
  65. );
  66. typedef enum {
  67. GET_OBJ_CAN_NAME,
  68. GET_OBJ_CAN_NAME_EX,
  69. GET_OBJ_1779_DN,
  70. GET_OBJ_NT4_NAME,
  71. GET_DNS_DOMAIN_NAME,
  72. GET_NT4_DOMAIN_NAME,
  73. GET_FQDN_DOMAIN_NAME,
  74. GET_OBJ_UPN
  75. } CRACK_NAME_OPR;
  76. HRESULT CrackName(PWSTR pwzNameIn, PWSTR * ppwzDnsName,
  77. CRACK_NAME_OPR Opr, HWND hWnd = NULL);
  78. void MsgBox(UINT MsgID, HWND hWnd);
  79. void MsgBox2(UINT MsgID, UINT InsertID, HWND hWnd);
  80. //
  81. // Error reporting. Note, use MsgBoxX (see above) for non-error messages.
  82. //
  83. void ErrMsg(UINT MsgID, HWND hWnd = NULL);
  84. void ErrMsgParam(UINT MsgID, LPARAM param, HWND hWnd = NULL);
  85. BOOL CheckADsError(HRESULT * phr, BOOL fIgnoreAttrNotFound, PSTR file,
  86. int line, HWND hwnd = NULL);
  87. #define CHECK_ADS_HR(phr, hwnd) CheckADsError(phr, FALSE, __FILE__, __LINE__, hwnd)
  88. #define CHECK_ADS_HR_IGNORE_UNFOUND_ATTR(phr, hwnd) \
  89. CheckADsError(phr, TRUE, __FILE__, __LINE__, hwnd)
  90. void ReportError(HRESULT hr, int nStr, HWND hWnd = NULL);
  91. #if defined(DSADMIN)
  92. //+----------------------------------------------------------------------------
  93. //
  94. // Function: SuperMsgBox
  95. //
  96. // Synopsis: Displays a message obtained from a string resource with
  97. // the parameters expanded. The error param, dwErr, if
  98. // non-zero, is converted to a string and becomes the first
  99. // replaceable param.
  100. //
  101. // This function includes the functionality of ReportErrorEx in
  102. // dsadmin\util.cpp *except* it does not have SpecialMessageBox.
  103. // It also can replace ReportMessageEx by setting dwErr to zero.
  104. //
  105. // Note: this function is UNICODE-only.
  106. //
  107. //-----------------------------------------------------------------------------
  108. int SuperMsgBox(
  109. HWND hWnd, // owning window.
  110. int nMessageId, // string resource ID of message. Must have replacable params to match nArguments.
  111. int nTitleId, // string resource ID of the title. If zero, uses IDS_MSG_TITLE.
  112. UINT ufStyle, // MessageBox flags.
  113. DWORD dwErr, // Error code, or zero if not needed.
  114. PVOID * rgpvArgs, // array of pointers/values for substitution in the nMessageId string.
  115. int nArguments, // count of pointers in string array.
  116. BOOL fTryADSiErrors,// If the failure is the result of an ADSI call, see if an ADSI extended error.
  117. PSTR szFile, // use the __FILE__ macro. ignored in retail build.
  118. int nLine // use the __LINE__ macro. ignored in retail build.
  119. );
  120. #endif //defined(DSADMIN)
  121. HRESULT
  122. ModifyNetWareUserPassword(
  123. IN IADsUser* pADsUser,
  124. IN PCWSTR pwzADsPath,
  125. IN PCWSTR pwzNewPassword
  126. );
  127. BOOL CheckGroupUpdate(HRESULT hr, HWND hPage = NULL, BOOL fAdd = TRUE, PWSTR pwzDN = NULL);
  128. #ifndef dspAssert
  129. #define dspAssert ASSERT
  130. #endif
  131. // smartpointer for PADS_ATTR_INFO
  132. class Smart_PADS_ATTR_INFO
  133. {
  134. private:
  135. PADS_ATTR_INFO m_pAttrs;
  136. public:
  137. Smart_PADS_ATTR_INFO::Smart_PADS_ATTR_INFO() : m_pAttrs(NULL) {}
  138. Smart_PADS_ATTR_INFO::~Smart_PADS_ATTR_INFO() { Empty(); }
  139. operator PADS_ATTR_INFO() const { return m_pAttrs; }
  140. PADS_ATTR_INFO* operator&() { return &m_pAttrs; }
  141. PADS_ATTR_INFO operator->() {dspAssert(m_pAttrs); return m_pAttrs;}
  142. void Empty()
  143. {
  144. if (NULL != m_pAttrs)
  145. {
  146. FreeADsMem( m_pAttrs );
  147. m_pAttrs = NULL;
  148. }
  149. }
  150. };
  151. // smartpointer for DsBind handle
  152. void Smart_DsHandle__Empty( HANDLE* phDs );
  153. class Smart_DsHandle
  154. {
  155. private:
  156. HANDLE m_hDs;
  157. public:
  158. Smart_DsHandle::Smart_DsHandle() : m_hDs(NULL) {}
  159. Smart_DsHandle::~Smart_DsHandle() { Empty(); }
  160. operator HANDLE() const { return m_hDs; }
  161. HANDLE* operator&() { return &m_hDs; }
  162. void Empty() { Smart_DsHandle__Empty( &m_hDs ); }
  163. };
  164. class DSPROP_BSTR_BLOCK;
  165. bool DSPROP_BSTR_BLOCK__SetCount( DSPROP_BSTR_BLOCK& block, int cItems );
  166. BSTR& DSPROP_BSTR_BLOCK__Reference( DSPROP_BSTR_BLOCK& block, int iItem );
  167. class DSPROP_BSTR_BLOCK
  168. {
  169. public:
  170. DSPROP_BSTR_BLOCK()
  171. : m_cItems( 0 )
  172. , m_abstrItems( NULL ) {}
  173. ~DSPROP_BSTR_BLOCK() { Empty(); }
  174. int QueryCount() const { return m_cItems; }
  175. const BSTR operator[](int iItem) const
  176. { return DSPROP_BSTR_BLOCK__Reference(
  177. const_cast<DSPROP_BSTR_BLOCK&>(*this), iItem ); }
  178. operator const BSTR*() const { return m_abstrItems; }
  179. operator LPWSTR*() const { return (LPWSTR*)m_abstrItems; }
  180. bool SetCount( int cItems )
  181. { return DSPROP_BSTR_BLOCK__SetCount( *this, cItems ); }
  182. bool Set( BSTR cbstrItem, int iItem )
  183. {
  184. return (NULL != (
  185. DSPROP_BSTR_BLOCK__Reference( *this, iItem ) =
  186. ::SysAllocString(cbstrItem) ) );
  187. }
  188. void Empty() { (void) SetCount(0); }
  189. private:
  190. int m_cItems;
  191. BSTR* m_abstrItems;
  192. friend bool DSPROP_BSTR_BLOCK__SetCount( DSPROP_BSTR_BLOCK& block, int cItems );
  193. friend BSTR& DSPROP_BSTR_BLOCK__Reference( DSPROP_BSTR_BLOCK& block, int iItem );
  194. };
  195. HRESULT DSPROP_ShallowSearch(
  196. IN OUT DSPROP_BSTR_BLOCK* pbstrBlock,
  197. IN LPCTSTR lpcwszADsPathDirectory,
  198. IN LPCTSTR lpcwszTargetDesiredClass,
  199. IN PADS_ATTR_INFO pAttrInfoExclusions = NULL
  200. );
  201. // The following functions support duelling listbox capability
  202. HRESULT DSPROP_Duelling_Populate(
  203. IN HWND hwndListbox,
  204. IN const DSPROP_BSTR_BLOCK& bstrblock
  205. );
  206. void DSPROP_Duelling_UpdateButtons(
  207. HWND hwndDlg,
  208. int nAnyCtrlid
  209. );
  210. void DSPROP_Duelling_ButtonClick(
  211. HWND hwndDlg,
  212. int nButtonCtrlid
  213. );
  214. void DSPROP_Duelling_ClearListbox(
  215. HWND hwndListbox
  216. );
  217. // JonN 4/8/99: add code to enable horizontal scrolling where appropriate
  218. HRESULT DSPROP_HScrollStringListbox(
  219. HWND hwndListbox
  220. );
  221. DWORD DSPROP_CreateHomeDirectory(IN PSID pUserSid, IN LPCWSTR lpszPathName);
  222. BOOL DSPROP_IsValidUNCPath(LPCWSTR lpszPath);
  223. void DSPROP_DomainVersionDlg(PCWSTR pwzDomainPath, PCWSTR pwzDomainDnsName,
  224. HWND hWndParent);
  225. void DSPROP_ForestVersionDlg(PCWSTR pwzConfigPath, PCWSTR pwzPartitionsPath,
  226. PCWSTR pwzSchemaPath, PCWSTR pwzRootDnsName,
  227. HWND hWndParent);
  228. //
  229. // This is a wrapper for ADsOpenObject. It gives DSAdmin a single point to change
  230. // global flags that are passed to ADsOpenObject without have to search and replace
  231. // all occurrences in the code
  232. //
  233. inline
  234. HRESULT DSAdminOpenObject(PCWSTR pszPath,
  235. REFIID refIID,
  236. PVOID* ppObject,
  237. BOOL bServer = FALSE)
  238. {
  239. HRESULT hr = S_OK;
  240. DWORD dwFlags = ADS_SECURE_AUTHENTICATION;
  241. if (bServer)
  242. {
  243. //
  244. // If we know we are connecting to a specific server and not domain in general
  245. // then pass the ADS_SERVER_BIND flag to save ADSI the trouble of figuring it out
  246. //
  247. dwFlags |= ADS_SERVER_BIND;
  248. }
  249. //
  250. // Get the security flags for ADsOpenObject using the published inline function
  251. // so that we can turn off signing/sealing/etc. based on regkeys.
  252. // For performance reasons we only want to read the regkey once.
  253. //
  254. static DWORD retrievedFlags = GetADsOpenObjectFlags();
  255. dwFlags |= retrievedFlags;
  256. hr = ADsOpenObject((LPWSTR)pszPath, NULL, NULL, dwFlags, refIID, ppObject);
  257. return hr;
  258. }
  259. //+---------------------------------------------------------------------------
  260. //
  261. // Function: GetDsObjectSD
  262. // Synopsis: Reads the security descriptor from the specied DS object
  263. // It only reads the DACL portion of the security descriptor
  264. //
  265. // Arguments: [IN pszObjectPath] -- LDAP Path of ds object
  266. // [ppDACL] --pointer to dacl in ppSD is returned here
  267. // [OUT ppSD] -- Security descriptor returned here.
  268. // calling API must free this by calling LocalFree
  269. //
  270. // Notes: The returned security descriptor must be freed with LocalFree
  271. //
  272. //----------------------------------------------------------------------------
  273. HRESULT GetDsObjectSD(LPCWSTR pszObjectPath,
  274. PACL* ppDACL,
  275. PSECURITY_DESCRIPTOR* ppSecurityDescriptor);
  276. //+---------------------------------------------------------------------------
  277. //
  278. // Function: SetDsObjectDacl
  279. // Synopsis: Writes the specified DACL to the specified DS object
  280. //
  281. // Arguments: [IN pszObjectPath] -- LDAP Path of ds object
  282. // [pDACL] -- pointer to dacl to be set
  283. //
  284. // Notes:
  285. //
  286. //----------------------------------------------------------------------------
  287. HRESULT SetDsObjectDacl(LPCWSTR pszObjectPath,
  288. PACL pDACL);
  289. #endif // _DSCMN_H_