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.

366 lines
17 KiB

  1. // -----------------------------------------------------------------------------
  2. // A C C T M A N . H - Steven J. Bailey - 8/17/96
  3. // -----------------------------------------------------------------------------
  4. #ifndef __ACCTMAN_H
  5. #define __ACCTMAN_H
  6. // -----------------------------------------------------------------------------
  7. // Depends On...
  8. // -----------------------------------------------------------------------------
  9. #include "ipropobj.h"
  10. #include "imnact.h"
  11. #define ACCT_UNDEFINED ((ACCTTYPE)-1)
  12. #define ICC_FLAGS (ICC_WIN95_CLASSES|ICC_NATIVEFNTCTL_CLASS)
  13. class CAccountManager;
  14. extern const int NUM_ACCT_PROPS;
  15. extern const PROPINFO g_rgAcctPropSet[];
  16. // -----------------------------------------------------------------------------
  17. // CAccount
  18. // -----------------------------------------------------------------------------
  19. class CAccount : public IImnAccount
  20. {
  21. private:
  22. ULONG m_cRef;
  23. CAccountManager *m_pAcctMgr;
  24. BOOL m_fAccountExist;
  25. DWORD m_dwSrvTypes;
  26. ACCTTYPE m_AcctType;
  27. TCHAR m_szID[CCHMAX_ACCOUNT_NAME];
  28. TCHAR m_szName[CCHMAX_ACCOUNT_NAME];
  29. CPropertyContainer *m_pContainer;
  30. BOOL m_fNoModifyAccts;
  31. HKEY m_hkey;
  32. char m_szKey[MAX_PATH];
  33. HRESULT IDoWizard(HWND hwnd, CLSID *pclsid, DWORD dwFlags);
  34. public:
  35. DWORD m_dwDlgFlags;
  36. // -------------------------------------------------------------------------
  37. // Standard Object Stuff
  38. // -------------------------------------------------------------------------
  39. CAccount(ACCTTYPE AcctType);
  40. ~CAccount(void);
  41. // -------------------------------------------------------------------------
  42. // IUnknown Methods
  43. // -------------------------------------------------------------------------
  44. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  45. STDMETHODIMP_(ULONG) AddRef(void);
  46. STDMETHODIMP_(ULONG) Release(void);
  47. void SetAccountType(ACCTTYPE AcctType);
  48. HRESULT ValidProp(DWORD dwPropTag);
  49. // -------------------------------------------------------------------------
  50. // HrInit - initializes the container
  51. // -------------------------------------------------------------------------
  52. HRESULT Init(CAccountManager *pAcctMgr, CPropertySet *pPropertySet);
  53. // -------------------------------------------------------------------------
  54. // HrOpen - Read properties from the registry
  55. // -------------------------------------------------------------------------
  56. STDMETHODIMP Open(HKEY hkey, LPCSTR pszAcctKey, LPCSTR pszAccount);
  57. // -------------------------------------------------------------------------
  58. // Is this a new account or does it already exist?
  59. // -------------------------------------------------------------------------
  60. STDMETHODIMP Exist(VOID);
  61. // -------------------------------------------------------------------------
  62. // Make default account for support server types
  63. // -------------------------------------------------------------------------
  64. STDMETHODIMP SetAsDefault(VOID);
  65. // -------------------------------------------------------------------------
  66. // Delete this account
  67. // -------------------------------------------------------------------------
  68. STDMETHODIMP Delete(VOID);
  69. STDMETHODIMP GetAccountType(ACCTTYPE *pAcctType);
  70. STDMETHODIMP GetServerTypes(DWORD *pdwSrvTypes);
  71. // -------------------------------------------------------------------------
  72. // Save the container
  73. // -------------------------------------------------------------------------
  74. STDMETHODIMP SaveChanges();
  75. STDMETHODIMP SaveChanges(BOOL fSendMsg);
  76. // -------------------------------------------------------------------------
  77. // Write changes, without sending notifications message
  78. // -------------------------------------------------------------------------
  79. STDMETHODIMP WriteChanges();
  80. // -------------------------------------------------------------------------
  81. // IPropertyContainer Implementation (GetProperty)
  82. // -------------------------------------------------------------------------
  83. STDMETHODIMP GetProp(DWORD dwPropTag, LPBYTE pb, ULONG *pcb);
  84. STDMETHODIMP GetPropDw(DWORD dwPropTag, DWORD *pdw);
  85. STDMETHODIMP GetPropSz(DWORD dwPropTag, LPSTR psz, ULONG cchMax);
  86. STDMETHODIMP SetProp(DWORD dwPropTag, LPBYTE pb, ULONG cb);
  87. STDMETHODIMP SetPropDw(DWORD dwPropTag, DWORD dw);
  88. STDMETHODIMP SetPropSz(DWORD dwPropTag, LPSTR psz);
  89. STDMETHODIMP ShowProperties(HWND hwnd, DWORD dwFlags);
  90. STDMETHODIMP ValidateProperty(DWORD dwPropTag, BYTE *pb, ULONG cb);
  91. STDMETHODIMP DoWizard(HWND hwnd, DWORD dwFlags);
  92. STDMETHODIMP DoImportWizard(HWND hwnd, CLSID clsid, DWORD dwFlags);
  93. };
  94. // -----------------------------------------------------------------------------
  95. // ACCOUNT
  96. // -----------------------------------------------------------------------------
  97. typedef struct tagACCOUNT {
  98. TCHAR szID[CCHMAX_ACCOUNT_NAME];
  99. ACCTTYPE AcctType;
  100. DWORD dwSrvTypes;
  101. DWORD dwServerId; // for LDAP only
  102. IImnAccount *pAccountObject;
  103. } ACCOUNT, *LPACCOUNT;
  104. #define ENUM_FLAG_SORT_BY_NAME 0x0001
  105. #define ENUM_FLAG_RESOLVE_ONLY 0x0002
  106. #define ENUM_FLAG_SORT_BY_LDAP_ID 0x0004
  107. #define ENUM_FLAG_NO_IMAP 0x0008
  108. // -----------------------------------------------------------------------------
  109. // CEnumAccounts
  110. // -----------------------------------------------------------------------------
  111. class CEnumAccounts : public IImnEnumAccounts
  112. {
  113. private:
  114. ULONG m_cRef; // Reference Counting
  115. LPACCOUNT m_pAccounts; // Array of accounts and Account Objects
  116. ULONG m_cAccounts; // Number of accounts in m_pAccounts array
  117. LONG m_iAccount; // Index of current account (-1 if at beginning)
  118. DWORD m_dwSrvTypes; // Used for enumerating servers of a specific type
  119. DWORD m_dwFlags;
  120. private:
  121. VOID QSort(LONG left, LONG right);
  122. BOOL FEnumerateAccount(LPACCOUNT pAccount);
  123. public:
  124. // -------------------------------------------------------------------------
  125. // Standard Object Stuff
  126. // -------------------------------------------------------------------------
  127. CEnumAccounts(DWORD dwSrvTypes, DWORD dwFlags);
  128. ~CEnumAccounts();
  129. // -------------------------------------------------------------------------
  130. // IUnknown Methods
  131. // -------------------------------------------------------------------------
  132. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  133. STDMETHODIMP_(ULONG) AddRef(void);
  134. STDMETHODIMP_(ULONG) Release(void);
  135. // -------------------------------------------------------------------------
  136. // Init - Initialize the enumerator, i.e. duplicate the Accounts array
  137. // -------------------------------------------------------------------------
  138. HRESULT Init(LPACCOUNT pAccounts, ULONG cAccounts);
  139. // -------------------------------------------------------------------------
  140. // GetCount - Get the number of items that the enumerator will process
  141. // -------------------------------------------------------------------------
  142. STDMETHODIMP GetCount(ULONG *pcItems);
  143. // -------------------------------------------------------------------------
  144. // SortByAccountName - sorts the enumerated accounts by name
  145. // -------------------------------------------------------------------------
  146. STDMETHODIMP SortByAccountName(void);
  147. // -------------------------------------------------------------------------
  148. // GetNext - Get the first or next enumerated account
  149. // Returns hrEnumFinished (*ppAccount = NULL) when no more accounts to enumerate
  150. // -------------------------------------------------------------------------
  151. STDMETHODIMP GetNext(IImnAccount **ppAccount);
  152. // -------------------------------------------------------------------------
  153. // Reset - This is like rewinding the enumerator
  154. // -------------------------------------------------------------------------
  155. STDMETHODIMP Reset(void);
  156. };
  157. // -----------------------------------------------------------------------------
  158. // ACCTINFO - Account Inforation
  159. // -----------------------------------------------------------------------------
  160. typedef struct tagACCTINFO {
  161. TCHAR szDefaultID[CCHMAX_ACCOUNT_NAME];
  162. BOOL fDefaultKnown;
  163. DWORD cAccounts;
  164. LPTSTR pszDefRegValue;
  165. LPTSTR pszFirstAccount;
  166. } ACCTINFO;
  167. #define ADVISE_BLOCK_SIZE (16)
  168. #define ADVISE_COOKIE ((WORD)0xAD5E)
  169. // Advise connections will be generated by masking in this cookie with the
  170. // index into the CAccountManager array where the advise is stored.
  171. #define MAX_INDEX (INT)(0xFFFF)
  172. #define INDEX_FROM_CONNECTION(conn) (INT)(LOWORD(conn))
  173. #define CONNECTION_FROM_INDEX(indx) (MAKELONG(LOWORD(indx), ADVISE_COOKIE))
  174. #define IS_VALID_CONNECTION(conn) (ADVISE_COOKIE == HIWORD(conn))
  175. #define IS_VALID_INDEX(indx) (((indx)>=0)&&((indx)<=MAX_INDEX))
  176. // -----------------------------------------------------------------------------
  177. // CAccountManager
  178. // -----------------------------------------------------------------------------
  179. class CAccountManager : public IImnAccountManager2
  180. {
  181. private:
  182. ULONG m_cRef; // Reference Counting
  183. LPACCOUNT m_pAccounts; // Array of accounts and Account Objects
  184. ULONG m_cAccounts; // Number of accounts in m_pAccounts array
  185. CPropertySet *m_pAcctPropSet; // Base account property set used to create CAccount
  186. BOOL m_fInit; // Has the object been successfully initialized
  187. UINT m_uMsgNotify; // Account Manager global notification message (0 means not processing)
  188. ACCTINFO m_rgAccountInfo[ACCT_LAST]; // Array of known account informtaion
  189. CRITICAL_SECTION m_cs; // Thread Safety
  190. IImnAdviseAccount **m_ppAdviseAccounts; // Client Account Advise Handlers
  191. INT m_cAdvisesAllocated;
  192. BOOL m_fNoModifyAccts;
  193. BOOL m_fInitCalled; // Avoid duplicate initialization
  194. BOOL m_fOutlook;
  195. HKEY m_hkey;
  196. char m_szRegRoot[MAX_PATH];
  197. char m_szRegAccts[MAX_PATH];
  198. HRESULT IInit(IImnAdviseMigrateServer *pMigrateServerAdvise, HKEY hkey, LPCSTR pszSubKey, DWORD dwFlags);
  199. // -------------------------------------------------------------------------
  200. // Reloads accounts (m_pAccounts) array from the registry
  201. // -------------------------------------------------------------------------
  202. HRESULT LoadAccounts(VOID);
  203. // -------------------------------------------------------------------------
  204. // Loading Default Account Information
  205. // -------------------------------------------------------------------------
  206. VOID GetDefaultAccounts(VOID);
  207. public:
  208. // -------------------------------------------------------------------------
  209. // Standard Object Stuff
  210. // -------------------------------------------------------------------------
  211. CAccountManager();
  212. ~CAccountManager();
  213. // -------------------------------------------------------------------------
  214. // IUnknown Methods
  215. // -------------------------------------------------------------------------
  216. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  217. STDMETHODIMP_(ULONG) AddRef(void);
  218. STDMETHODIMP_(ULONG) Release(void);
  219. // -------------------------------------------------------------------------
  220. // Initialization of this object (only call it once)
  221. // -------------------------------------------------------------------------
  222. STDMETHODIMP Init(IImnAdviseMigrateServer *pAdviseMigrateServer);
  223. STDMETHODIMP InitEx(IImnAdviseMigrateServer *pAdviseMigrateServer, DWORD dwFlags);
  224. STDMETHODIMP InitUser(IImnAdviseMigrateServer *pAdviseMigrateServer, REFGUID rguidID, DWORD dwFlags);
  225. // -------------------------------------------------------------------------
  226. // FProcessNotification - returns TRUE if window message was
  227. // processed as a notification
  228. // -------------------------------------------------------------------------
  229. STDMETHODIMP ProcessNotification(UINT uMsg, WPARAM wParam, LPARAM lParam);
  230. VOID Advise(DWORD dwAction, ACTX* pactx);
  231. // -------------------------------------------------------------------------
  232. // Creating Account Objects
  233. // -------------------------------------------------------------------------
  234. STDMETHODIMP CreateAccountObject(ACCTTYPE AcctType, IImnAccount **ppAccount);
  235. HRESULT ICreateAccountObject(ACCTTYPE AcctType, IImnAccount **ppAccount);
  236. HRESULT DeleteAccount(LPSTR pszID, LPSTR pszName, ACCTTYPE AcctType, DWORD dwSrvTypes);
  237. // -------------------------------------------------------------------------
  238. // Enumerators - Always returns connected accounts first
  239. // -------------------------------------------------------------------------
  240. STDMETHODIMP Enumerate(DWORD dwSrvTypes, IImnEnumAccounts **ppEnumAccounts);
  241. HRESULT IEnumerate(DWORD dwSrvTypes, DWORD dwFlags, IImnEnumAccounts **ppEnumAccounts);
  242. // -------------------------------------------------------------------------
  243. // GetServerCount
  244. // -------------------------------------------------------------------------
  245. STDMETHODIMP GetAccountCount(ACCTTYPE AcctType, ULONG *pcServers);
  246. // -------------------------------------------------------------------------
  247. // FindAccount - used to find accounts by unique properties
  248. // -------------------------------------------------------------------------
  249. STDMETHODIMP FindAccount(DWORD dwPropTag, LPCTSTR pszSearchData, IImnAccount **ppAccount);
  250. // -------------------------------------------------------------------------
  251. // GetDefaultAccount - Opens the default account for the account type
  252. // -------------------------------------------------------------------------
  253. STDMETHODIMP GetDefaultAccount(ACCTTYPE AcctType, IImnAccount **ppAccount);
  254. STDMETHODIMP GetDefaultAccountName(ACCTTYPE AcctType, LPTSTR pszAccount, ULONG cchMax);
  255. HRESULT SetDefaultAccount(ACCTTYPE AcctType, LPSTR pszID, BOOL fNotify);
  256. STDMETHODIMP GetIncompleteAccount(ACCTTYPE AcctType, LPSTR pszAccountId, ULONG cchMax);
  257. STDMETHODIMP SetIncompleteAccount(ACCTTYPE AcctType, LPCSTR pszAccountId);
  258. // I wrote this function because I support accounts without an SMTP server. This
  259. // functions verifies that the default Send account truly contains an SMTP server,
  260. // and if it doesn't, resets the default Send Account to an account that does have
  261. // an SMTP server.
  262. STDMETHODIMP ValidateDefaultSendAccount(VOID);
  263. STDMETHODIMP AccountListDialog(HWND hwnd, ACCTLISTINFO *pinfo);
  264. STDMETHODIMP Advise(IImnAdviseAccount *pAdviseAccount, DWORD* pdwConnection);
  265. STDMETHODIMP Unadvise(DWORD dwConnection);
  266. STDMETHODIMP GetUniqueAccountName(LPTSTR szName, UINT cch);
  267. void UpgradeAccountProps(void);
  268. HRESULT GetNextLDAPServerID(DWORD dwSet, DWORD *pdwId);
  269. HRESULT GetNextAccountID(TCHAR *szID, int cch);
  270. HRESULT UniqueAccountName(char *szName, char *szID);
  271. inline LPCSTR GetAcctRegKey(void) {return(m_szRegAccts);};
  272. inline HKEY GetAcctHKey(void) {return(m_hkey);};
  273. inline BOOL FNoModifyAccts(void) {return(m_fNoModifyAccts);}
  274. inline BOOL FOutlook(void) {return(m_fOutlook);}
  275. };
  276. #define CCH_USERNAME_MAX_LENGTH 63
  277. typedef struct tagOEUSERINFO {
  278. DWORD dwUserId;
  279. TCHAR szUsername[CCH_USERNAME_MAX_LENGTH+1];
  280. } OEUSERINFO;
  281. // -----------------------------------------------------------------------------
  282. // AcctUtil Prototypes
  283. // -----------------------------------------------------------------------------
  284. HRESULT AcctUtil_ValidAccountName(LPTSTR pszAccount);
  285. VOID AcctUtil_FreeAccounts(LPACCOUNT *ppAccounts, ULONG *pcAccounts);
  286. HRESULT AcctUtil_HrSetAsDefault(IImnAccount *pAccount, LPCTSTR pszRegRoot);
  287. BOOL AcctUtil_IsHTTPMailEnabled(void);
  288. BOOL AcctUtil_HideHotmail();
  289. #endif // __ACCTMAN_H