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.

188 lines
6.2 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include <docobj.h>
  4. #include <advpub.h>
  5. #include <initguid.h>
  6. #include "msident.h"
  7. #include "factory.h"
  8. #include "multiutl.h"
  9. #include <ocidl.h>
  10. #include <shlwapi.h>
  11. #include <shlwapip.h>
  12. #include <shfusion.h>
  13. #ifndef ASSERT
  14. #ifdef DEBUG
  15. #define ASSERT Assert
  16. #else
  17. #define ASSERT(x)
  18. #endif
  19. #endif
  20. #define IDENTITY_PASSWORDS
  21. #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
  22. extern ULONG g_cLock, g_cObj;
  23. extern HANDLE g_hMutex;
  24. extern GUID g_uidOldUserId;
  25. extern GUID g_uidNewUserId;
  26. extern BOOL g_fNotifyComplete;
  27. inline ULONG DllLock() { return ++g_cLock; }
  28. inline ULONG DllUnlock() { return --g_cLock; }
  29. inline ULONG DllGetLock() { return g_cLock; }
  30. inline ULONG DllAddRef() { return ++g_cObj; }
  31. inline ULONG DllRelease() { return --g_cObj; }
  32. inline ULONG DllGetRef() { return g_cObj; }
  33. extern UINT WM_IDENTITY_CHANGED;
  34. extern UINT WM_QUERY_IDENTITY_CHANGE;
  35. extern UINT WM_IDENTITY_INFO_CHANGED;
  36. #define CCH_USERPASSWORD_MAX_LENGTH 16
  37. #define CCH_USERNAME_MAX_LENGTH CCH_IDENTITY_NAME_MAX_LENGTH
  38. //
  39. // CUserIdentity object
  40. //
  41. class CUserIdentity : public IUserIdentity2
  42. {
  43. protected:
  44. ULONG m_cRef;
  45. GUID m_uidCookie;
  46. BOOL m_fSaved;
  47. BOOL m_fUsePassword;
  48. TCHAR m_szUsername[CCH_USERNAME_MAX_LENGTH];
  49. TCHAR m_szPassword[CCH_USERPASSWORD_MAX_LENGTH];
  50. public:
  51. CUserIdentity();
  52. ~CUserIdentity();
  53. // IUnknown members
  54. STDMETHODIMP QueryInterface(REFIID, void **);
  55. STDMETHODIMP_(ULONG) AddRef(void);
  56. STDMETHODIMP_(ULONG) Release(void);
  57. // IUserIdentity members
  58. STDMETHODIMP GetCookie(GUID *puidCookie);
  59. STDMETHODIMP OpenIdentityRegKey(DWORD dwDesiredAccess, HKEY *phKey);
  60. STDMETHODIMP GetIdentityFolder(DWORD dwFlags, WCHAR *pszPath, ULONG ulBuffSize);
  61. STDMETHODIMP GetName(WCHAR *pszName, ULONG ulBuffSize);
  62. // IUserIdentity2 members
  63. STDMETHODIMP GetOrdinal(DWORD* pdwOrdinal);
  64. STDMETHODIMP SetName(WCHAR *pszName);
  65. STDMETHODIMP ChangePassword(WCHAR *szOldPass, WCHAR *szNewPass);
  66. // Other members
  67. STDMETHODIMP SetPassword(WCHAR *pszPassword);
  68. STDMETHODIMP InitFromUsername(TCHAR *pszUsername);
  69. STDMETHODIMP InitFromCookie(GUID *uidCookie);
  70. private:
  71. STDMETHODIMP _SaveUser();
  72. };
  73. //
  74. // CEnumUserIdentity object
  75. //
  76. class CEnumUserIdentity : public IEnumUserIdentity
  77. {
  78. protected:
  79. ULONG m_cRef;
  80. DWORD m_dwCurrentUser; // Maintain current index into the reg list
  81. DWORD m_cCountUsers; // number of accounts in the registry
  82. GUID *m_rguidUsers;
  83. BOOL m_fInited;
  84. public:
  85. CEnumUserIdentity();
  86. ~CEnumUserIdentity();
  87. // IUnknown members
  88. STDMETHODIMP QueryInterface(REFIID, void **);
  89. STDMETHODIMP_(ULONG) AddRef(void);
  90. STDMETHODIMP_(ULONG) Release(void);
  91. // IEnumUserIdentity members
  92. STDMETHODIMP Next(ULONG celt, IUnknown **rgelt, ULONG *pceltFetched);
  93. STDMETHODIMP Skip(ULONG celt);
  94. STDMETHODIMP Reset(void);
  95. STDMETHODIMP Clone(IEnumUserIdentity **ppenum);
  96. STDMETHODIMP GetCount(ULONG *pnCount);
  97. private:
  98. // Other methods
  99. STDMETHODIMP _Init();
  100. STDMETHODIMP _Init(DWORD dwCurrentUser, DWORD dwCountUsers, GUID *prguidUserCookies);
  101. STDMETHODIMP _Cleanup();
  102. };
  103. //
  104. // CUserIdentityManager object
  105. //
  106. class CUserIdentityManager :
  107. public IUserIdentityManager,
  108. public IConnectionPoint,
  109. public IPrivateIdentityManager,
  110. public IPrivateIdentityManager2
  111. {
  112. protected:
  113. ULONG m_cRef;
  114. CRITICAL_SECTION m_rCritSect;
  115. CNotifierList *m_pAdviseRegistry;
  116. BOOL m_fWndRegistered;
  117. HWND m_hwnd;
  118. public:
  119. CUserIdentityManager();
  120. ~CUserIdentityManager();
  121. // IUnknown members
  122. STDMETHODIMP QueryInterface(REFIID, void **);
  123. STDMETHODIMP_(ULONG) AddRef(void);
  124. STDMETHODIMP_(ULONG) Release(void);
  125. // IUserIdentityManager members
  126. STDMETHODIMP EnumIdentities(IEnumUserIdentity **ppEnumUserIdentity);
  127. STDMETHODIMP ManageIdentities(HWND hwndParent, DWORD dwFlags);
  128. STDMETHODIMP Logon(HWND hwndParent, DWORD dwFlags, IUserIdentity **ppUserIdentity);
  129. STDMETHODIMP Logoff(HWND hwndParent);
  130. STDMETHODIMP GetIdentityByCookie(GUID *uidCookie, IUserIdentity **ppUserIdentity);
  131. // IConnectionPoint functions
  132. STDMETHODIMP GetConnectionInterface(IID *pIID);
  133. STDMETHODIMP GetConnectionPointContainer(IConnectionPointContainer **ppCPC);
  134. STDMETHODIMP Advise(IUnknown *pUnkSink, DWORD *pdwCookie);
  135. STDMETHODIMP Unadvise(DWORD dwCookie);
  136. STDMETHODIMP EnumConnections(IEnumConnections **ppEnum);
  137. // IPrivateIdentityManager functions
  138. STDMETHODIMP CreateIdentity(WCHAR *pszName, IUserIdentity **ppIdentity);
  139. STDMETHODIMP ConfirmPassword(GUID *uidCookie, WCHAR *pszPassword);
  140. // IPrivateIdentityManager2 functions
  141. STDMETHODIMP CreateIdentity2(WCHAR *pszName, WCHAR *pszPassword, IUserIdentity **ppIdentity);
  142. STDMETHODIMP DestroyIdentity(GUID *uidCookie);
  143. STDMETHODIMP LogonAs(WCHAR *pszName, WCHAR *pszPassword, IUserIdentity **ppIdentity);
  144. STDMETHODIMP SetDefaultIdentity(GUID *uidCookie);
  145. STDMETHODIMP GetDefaultIdentity(GUID *uidCookie);
  146. // Other methods
  147. STDMETHODIMP QuerySwitchIdentities();
  148. STDMETHODIMP NotifySwitchIdentities();
  149. static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  150. static STDMETHODIMP ClearChangingIdentities();
  151. private:
  152. STDMETHODIMP _NotifyIdentitiesSwitched();
  153. STDMETHODIMP _QueryProcessesCanSwitch();
  154. STDMETHODIMP _CreateWindowClass();
  155. STDMETHODIMP _SwitchToUser(GUID *puidFromUser, GUID *puidToUser);
  156. STDMETHODIMP _PersistChangingIdentities();
  157. STDMETHODIMP _LoadChangingIdentities();
  158. };