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.

304 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1999.
  5. //
  6. // File: UserOM.h
  7. //
  8. // Contents: shell user object model (interface implemtation for ILogonEnumUsers, ILogonUser)
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef _USEROM_H_
  12. #define _USEROM_H_
  13. #include "priv.h"
  14. #include "CIDispatchHelper.h"
  15. #include "UIHostIPC.h"
  16. #include "CInteractiveLogon.h"
  17. HRESULT _IsGuestAccessMode(void);
  18. const TCHAR CDECL c_szRegRoot[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Hints");
  19. const TCHAR CDECL c_szPictureSrcVal[] = TEXT("PictureSource");
  20. // prototypes for class factory functions
  21. STDAPI CLogonEnumUsers_Create(REFIID riid, void** ppvObj);
  22. STDAPI CLocalMachine_Create(REFIID riid, void** ppvObj);
  23. STDAPI CLogonStatusHost_Create(REFIID riid, void** ppvObj);
  24. STDAPI CLogonUser_Create(REFIID riid, void** ppvObj);
  25. class CLogonEnumUsers : public CIDispatchHelper,
  26. public IEnumVARIANT,
  27. public ILogonEnumUsers
  28. {
  29. public:
  30. // *** IUnknown methods ***
  31. virtual STDMETHODIMP_(ULONG) AddRef(void);
  32. virtual STDMETHODIMP_(ULONG) Release(void);
  33. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  34. // *** IDispatch methods ***
  35. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
  36. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  37. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid);
  38. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  39. // *** IEnumVARIANT methods ***
  40. virtual STDMETHODIMP Next(ULONG cUsers, VARIANT* rgvar, ULONG* pcUsersFetched);
  41. virtual STDMETHODIMP Skip(ULONG cUsers);
  42. virtual STDMETHODIMP Reset();
  43. virtual STDMETHODIMP Clone(IEnumVARIANT** ppenum);
  44. // *** ILogonEnumUsers ***
  45. virtual STDMETHODIMP get_Domain(BSTR* pbstr);
  46. virtual STDMETHODIMP put_Domain(BSTR bstr);
  47. virtual STDMETHODIMP get_EnumFlags(ILUEORDER* porder);
  48. virtual STDMETHODIMP put_EnumFlags(ILUEORDER order);
  49. virtual STDMETHODIMP get_length(UINT* pcUsers);
  50. virtual STDMETHODIMP get_currentUser(ILogonUser** ppLogonUserInfo);
  51. virtual STDMETHODIMP item(VARIANT varUserId, ILogonUser** ppLogonUserInfo);
  52. virtual STDMETHODIMP _NewEnum(IUnknown** ppunk);
  53. virtual STDMETHODIMP create(BSTR bstrLoginName, ILogonUser **ppLogonUser);
  54. virtual STDMETHODIMP remove(VARIANT varUserId, VARIANT varBackupPath, VARIANT_BOOL *pbSuccess);
  55. public:
  56. // friend functions
  57. friend HRESULT CLogonEnumUsers_Create(REFIID riid, void** ppvObj);
  58. private:
  59. // private member variables
  60. int _cRef;
  61. TCHAR _szDomain[256]; // name of the domain we are enumerating users on
  62. ILUEORDER _enumorder; // order in which to enumerate users
  63. HDPA _hdpaUsers; // dpa holding the list of enumerated users
  64. // private member functions
  65. HRESULT _EnumerateUsers();
  66. HRESULT _GetUserByIndex(LONG lUserID, ILogonUser** ppLogonUserInfo);
  67. HRESULT _GetUserByName(BSTR bstrUserName, ILogonUser** ppLogonUserInfo);
  68. void _DestroyHDPAUsers();
  69. CLogonEnumUsers();
  70. ~CLogonEnumUsers();
  71. };
  72. class CLogonUser : public CIDispatchHelper,
  73. public ILogonUser
  74. {
  75. public:
  76. static HRESULT Create(LPCTSTR pszLoginName, LPCTSTR pszFullName, LPCTSTR pszDomain, REFIID riid, LPVOID* ppv);
  77. // *** IUnknown methods ***
  78. virtual STDMETHODIMP_(ULONG) AddRef(void);
  79. virtual STDMETHODIMP_(ULONG) Release(void);
  80. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  81. // *** IDispatch methods ***
  82. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
  83. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  84. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid);
  85. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  86. // *** ILogonUser ***
  87. virtual STDMETHODIMP get_setting(BSTR bstrName, VARIANT* pvarVal);
  88. virtual STDMETHODIMP put_setting(BSTR bstrName, VARIANT varVal);
  89. virtual STDMETHODIMP get_isLoggedOn(VARIANT_BOOL* pbLoggedIn);
  90. virtual STDMETHODIMP get_passwordRequired(VARIANT_BOOL* pbPasswordRequired);
  91. virtual STDMETHODIMP get_interactiveLogonAllowed(VARIANT_BOOL *pbInteractiveLogonAllowed);
  92. virtual STDMETHODIMP get_isProfilePrivate(VARIANT_BOOL* pbPrivate);
  93. virtual STDMETHODIMP get_isPasswordResetAvailable(VARIANT_BOOL* pbResetAvailable);
  94. virtual STDMETHODIMP logon(BSTR pstrPassword, VARIANT_BOOL* pbRet);
  95. virtual STDMETHODIMP logoff(VARIANT_BOOL* pbRet);
  96. virtual STDMETHODIMP changePassword(VARIANT varNewPassword, VARIANT varOldPassword, VARIANT_BOOL* pbRet);
  97. virtual STDMETHODIMP makeProfilePrivate(VARIANT_BOOL bPrivate);
  98. virtual STDMETHODIMP getMailAccountInfo(UINT uiAccountIndex, VARIANT *pvarAccountName, UINT *pcUnreadMessages);
  99. private:
  100. // private member variables
  101. int _cRef;
  102. TCHAR _szLoginName[UNLEN + sizeof('\0')];
  103. TCHAR _szDomain[DNLEN + sizeof('\0')];
  104. BSTR _strDisplayName;
  105. TCHAR _szPicture[MAX_PATH+7]; // +7 for "file://" prefix
  106. BSTR _strPictureSource;
  107. BSTR _strHint;
  108. BSTR _strDescription;
  109. BOOL _bPasswordRequired;
  110. int _iPrivilegeLevel;
  111. LPTSTR _pszSID;
  112. // private member functions
  113. CLogonUser(LPCTSTR pszLoginName, LPCTSTR pszFullName, LPCTSTR pszDomain);
  114. ~CLogonUser();
  115. HRESULT _InitPicture();
  116. HRESULT _SetPicture(LPCTSTR pszNewPicturePath);
  117. DWORD _OpenUserHintKey(REGSAM sam, HKEY *phkey);
  118. HRESULT _UserSettingAccessor(BSTR bstrName, VARIANT *pvarVal, BOOL bPut);
  119. // DisplayName
  120. HRESULT _GetDisplayName(VARIANT* pvar);
  121. HRESULT _PutDisplayName(VARIANT var);
  122. // LoginName
  123. HRESULT _GetLoginName(VARIANT* pvar);
  124. HRESULT _PutLoginName(VARIANT var);
  125. // Domain
  126. HRESULT _GetDomain(VARIANT* pvar);
  127. // Picture
  128. HRESULT _GetPicture(VARIANT* pvar);
  129. HRESULT _PutPicture(VARIANT var);
  130. HRESULT _GetPictureSource(VARIANT* pvar);
  131. // Description
  132. HRESULT _GetDescription(VARIANT* pvar);
  133. HRESULT _PutDescription(VARIANT var);
  134. // Hint
  135. HRESULT _GetHint(VARIANT* pvar);
  136. HRESULT _PutHint(VARIANT var);
  137. // AccountType
  138. HRESULT _GetAccountType(VARIANT* pvar);
  139. HRESULT _PutAccountType(VARIANT var);
  140. // SID
  141. HRESULT _LookupUserSid();
  142. HRESULT _GetSID(VARIANT* pvar);
  143. //
  144. DWORD _GetExpiryDays (HKEY hKeyCurrentUser);
  145. HRESULT _GetUnreadMail(VARIANT* pvar);
  146. };
  147. class CLocalMachine : public CIDispatchHelper,
  148. public ILocalMachine
  149. {
  150. public:
  151. // *** IUnknown methods ***
  152. virtual STDMETHODIMP_(ULONG) AddRef(void);
  153. virtual STDMETHODIMP_(ULONG) Release(void);
  154. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  155. // *** IDispatch methods ***
  156. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
  157. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  158. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid);
  159. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  160. // *** ILocalMachine ***
  161. virtual STDMETHODIMP get_MachineName(VARIANT* pvar);
  162. virtual STDMETHODIMP get_isGuestEnabled(ILM_GUEST_FLAGS flags, VARIANT_BOOL* pbEnabled);
  163. virtual STDMETHODIMP get_isFriendlyUIEnabled(VARIANT_BOOL* pbEnabled);
  164. virtual STDMETHODIMP put_isFriendlyUIEnabled(VARIANT_BOOL bEnabled);
  165. virtual STDMETHODIMP get_isMultipleUsersEnabled(VARIANT_BOOL* pbEnabled);
  166. virtual STDMETHODIMP put_isMultipleUsersEnabled(VARIANT_BOOL bEnabled);
  167. virtual STDMETHODIMP get_isRemoteConnectionsEnabled(VARIANT_BOOL* pbEnabled);
  168. virtual STDMETHODIMP put_isRemoteConnectionsEnabled(VARIANT_BOOL bEnabled);
  169. virtual STDMETHODIMP get_AccountName(VARIANT varAccount, VARIANT* pvar);
  170. virtual STDMETHODIMP get_isUndockEnabled(VARIANT_BOOL* pbEnabled);
  171. virtual STDMETHODIMP get_isShutdownAllowed(VARIANT_BOOL* pbShutdownAllowed);
  172. virtual STDMETHODIMP get_isGuestAccessMode(VARIANT_BOOL* pbForceGuest);
  173. virtual STDMETHODIMP get_isOfflineFilesEnabled(VARIANT_BOOL *pbEnabled);
  174. virtual STDMETHODIMP TurnOffComputer(void);
  175. virtual STDMETHODIMP SignalUIHostFailure(void);
  176. virtual STDMETHODIMP AllowExternalCredentials(void);
  177. virtual STDMETHODIMP RequestExternalCredentials(void);
  178. virtual STDMETHODIMP LogonWithExternalCredentials(BSTR pstrUsername, BSTR pstrDomain, BSTR pstrPassword, VARIANT_BOOL* pbRet);
  179. virtual STDMETHODIMP InitiateInteractiveLogon(BSTR pstrUsername, BSTR pstrDomain, BSTR pstrPassword, DWORD dwTimeout, VARIANT_BOOL* pbRet);
  180. virtual STDMETHODIMP UndockComputer(void);
  181. virtual STDMETHODIMP EnableGuest(ILM_GUEST_FLAGS flags);
  182. virtual STDMETHODIMP DisableGuest(ILM_GUEST_FLAGS flags);
  183. public:
  184. // friend Functions
  185. friend HRESULT CLocalMachine_Create(REFIID riid, LPVOID* ppv);
  186. private:
  187. // private member variables
  188. int _cRef;
  189. private:
  190. // private member functions
  191. CLocalMachine(void);
  192. ~CLocalMachine();
  193. static void RefreshStartMenu(void);
  194. };
  195. class CLogonStatusHost : public CIDispatchHelper,
  196. public ILogonStatusHost
  197. {
  198. public:
  199. // *** IUnknown methods ***
  200. virtual STDMETHODIMP_(ULONG) AddRef(void);
  201. virtual STDMETHODIMP_(ULONG) Release(void);
  202. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  203. // *** IDispatch methods ***
  204. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
  205. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  206. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid);
  207. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  208. // *** ILogonStatusHost ***
  209. virtual STDMETHODIMP Initialize(HINSTANCE hInstance, HWND hwndHost);
  210. virtual STDMETHODIMP WindowProcedureHelper(HWND hwnd, UINT uMsg, VARIANT wParam, VARIANT lParam);
  211. virtual STDMETHODIMP UnInitialize(void);
  212. public:
  213. // friend Functions
  214. friend HRESULT CLogonStatusHost_Create(REFIID riid, LPVOID* ppv);
  215. private:
  216. // implementation helpers
  217. LRESULT Handle_WM_UISERVICEREQUEST (WPARAM wParam, LPARAM lParam);
  218. LRESULT Handle_WM_WTSSESSION_CHANGE (WPARAM wParam, LPARAM lParam);
  219. static LRESULT CALLBACK StatusWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  220. // terminal service wait helpers
  221. bool IsTermServiceDisabled (void);
  222. void StartWaitForTermService (void);
  223. void EndWaitForTermService (void);
  224. void WaitForTermService (void);
  225. static DWORD WINAPI CB_WaitForTermService (void *pParameter);
  226. // parent process wait helpers
  227. void StartWaitForParentProcess (void);
  228. void EndWaitForParentProcess (void);
  229. void WaitForParentProcess (void);
  230. static DWORD WINAPI CB_WaitForParentProcess (void *pParameter);
  231. // thread helper
  232. static void CALLBACK CB_WakeupThreadAPC (ULONG_PTR dwParam);
  233. private:
  234. // private member variables
  235. int _cRef;
  236. HINSTANCE _hInstance;
  237. HWND _hwnd;
  238. HWND _hwndHost;
  239. ATOM _atom;
  240. BOOL _fRegisteredNotification;
  241. HANDLE _hThreadWaitForTermService;
  242. HANDLE _hThreadWaitForParentProcess;
  243. HANDLE _hProcessParent;
  244. CInteractiveLogon _interactiveLogon;
  245. static const WCHAR s_szTermSrvReadyEventName[];
  246. public:
  247. // private member functions
  248. CLogonStatusHost(void);
  249. ~CLogonStatusHost();
  250. };
  251. #endif // _USEROM_H_