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.

327 lines
9.5 KiB

  1. //#define DBCS
  2. #ifndef WIN32_LEAN_AND_MEAN
  3. #define WIN32_LEAN_AND_MEAN
  4. #endif
  5. #include <windows.h>
  6. #include <regstr.h>
  7. #define WIN31
  8. #include "pwlapi.h"
  9. #include <string.h>
  10. #include <netlib.h>
  11. #ifdef DEBUG
  12. #define SAVE_DEBUG
  13. #undef DEBUG
  14. #endif
  15. #include <npstring.h>
  16. #include <npdefs.h>
  17. #define _COMCTL32_ // We delay-load Comctl32
  18. #include <prsht.h>
  19. #ifdef SAVE_DEBUG
  20. #define DEBUG
  21. #endif
  22. #include <ole2.h>
  23. #include "msluguid.h"
  24. #include "msluapi.h"
  25. void Netlib_EnterCriticalSection(void);
  26. void Netlib_LeaveCriticalSection(void);
  27. #ifdef DEBUG
  28. extern BOOL g_fCritical;
  29. #endif
  30. #define ENTERCRITICAL Netlib_EnterCriticalSection();
  31. #define LEAVECRITICAL Netlib_LeaveCriticalSection();
  32. #define ASSERTCRITICAL ASSERT(g_fCritical);
  33. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  34. extern "C" {
  35. HRESULT VerifySupervisorPassword(LPCSTR pszPassword);
  36. HRESULT ChangeSupervisorPassword(LPCSTR pszOldPassword, LPCSTR pszNewPassword);
  37. };
  38. const UINT cchMaxUsername = 128;
  39. extern UINT g_cRefThisDll;
  40. extern UINT g_cLocks;
  41. extern void LockThisDLL(BOOL fLock);
  42. extern void RefThisDLL(BOOL fRef);
  43. extern void UnloadShellEntrypoint(void);
  44. extern void CleanupWinINet(void);
  45. UINT NPSCopyNLS (NLS_STR FAR *pnlsSourceString, LPVOID lpDestBuffer, LPDWORD lpBufferSize);
  46. extern APIERR MakeSupervisor(HPWL hPWL, LPCSTR pszSupervisorPassword);
  47. HRESULT GetSystemCurrentUser(NLS_STR *pnlsCurrentUser);
  48. HRESULT GetUserPasswordCache(LPCSTR pszUsername, LPCSTR pszPassword, LPHANDLE phOut, BOOL fCreate);
  49. typedef void (*PFNSELNOTIFY)(HWND hwndLB, int iSel);
  50. HRESULT FillUserList(HWND hwndLB, IUserDatabase *pDB, LPCSTR pszDefaultSelection,
  51. BOOL fIncludeGuest, PFNSELNOTIFY pfnSelNotify);
  52. void DestroyUserList(HWND hwndLB);
  53. void AddPage(LPPROPSHEETHEADER ppsh, UINT id, DLGPROC pfn, LPVOID pwd);
  54. void InitWizDataPtr(HWND hDlg, LPARAM lParam);
  55. void InsertControlText(HWND hDlg, UINT idCtrl, const NLS_STR *pnlsInsert);
  56. HRESULT GetControlText(HWND hDlg, UINT idCtrl, NLS_STR *pnls);
  57. HRESULT DoAddUserWizard(HWND hwndParent, IUserDatabase *pDB,
  58. BOOL fPickUserPage, IUser *pUserToClone);
  59. BOOL InstallLogonDialog(void);
  60. void DeinstallLogonDialog(void);
  61. HRESULT DoUserDialog(HWND hwndOwner, DWORD dwFlags, IUser **ppOut);
  62. void CacheLogonCredentials(LPCSTR pszUsername, LPCSTR pszPassword);
  63. void ReportUserError(HWND hwndOwner, HRESULT hres);
  64. void SetErrorFocus(HWND hDlg, UINT idCtrl, BOOL fClear = TRUE);
  65. class CLUClassFactory : public IClassFactory
  66. {
  67. public:
  68. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  69. STDMETHODIMP_(ULONG) AddRef(void);
  70. STDMETHODIMP_(ULONG) Release(void);
  71. STDMETHODIMP CreateInstance(
  72. /* [unique][in] */ IUnknown __RPC_FAR *pUnkOuter,
  73. /* [in] */ REFIID riid,
  74. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
  75. STDMETHODIMP LockServer(
  76. /* [in] */ BOOL fLock);
  77. };
  78. HRESULT CreateUserDatabase(REFIID riid, void **ppOut);
  79. class CLUUser;
  80. class BUFFER;
  81. class CLUDatabase : public IUserDatabase
  82. {
  83. //friend class CLUClassFactory;
  84. friend HRESULT CreateUserDatabase(REFIID riid, void **ppOut);
  85. private:
  86. ULONG m_cRef;
  87. CLUUser *m_CurrentUser;
  88. CLUDatabase();
  89. ~CLUDatabase();
  90. STDMETHODIMP CreateUser(LPCSTR pszName, IUser *pCloneFrom,
  91. BOOL fFixInstallStubs, IUserProfileInit *pInit);
  92. public:
  93. // *** IUnknown methods ***
  94. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  95. STDMETHODIMP_(ULONG) AddRef(void);
  96. STDMETHODIMP_(ULONG) Release(void);
  97. STDMETHODIMP Install(LPCSTR pszSupervisorName, LPCSTR pszSupervisorPassword,
  98. LPCSTR pszRatingsPassword, IUserProfileInit *pInit);
  99. STDMETHODIMP AddUser(LPCSTR pszName, IUser *pSourceUser,
  100. IUserProfileInit *pInit, IUser **ppOut);
  101. STDMETHODIMP GetUser(LPCSTR pszName, IUser **ppOut);
  102. STDMETHODIMP GetSpecialUser(DWORD nSpecialUserCode, IUser **ppOut);
  103. STDMETHODIMP GetCurrentUser(IUser **ppOut);
  104. STDMETHODIMP SetCurrentUser(IUser *pUser);
  105. STDMETHODIMP DeleteUser(LPCSTR pszName);
  106. STDMETHODIMP RenameUser(LPCSTR pszOldName, LPCSTR pszNewName);
  107. STDMETHODIMP EnumUsers(IEnumUnknown **ppOut);
  108. STDMETHODIMP Authenticate(HWND hwndOwner, DWORD dwFlags,
  109. LPCSTR pszName, LPCSTR pszPassword,
  110. IUser **ppOut);
  111. STDMETHODIMP InstallComponent(REFCLSID clsidComponent, LPCSTR pszName,
  112. DWORD dwFlags);
  113. STDMETHODIMP RemoveComponent(REFCLSID clsidComponent, LPCSTR pszName);
  114. STDMETHODIMP InstallWizard(HWND hwndParent);
  115. STDMETHODIMP AddUserWizard(HWND hwndParent);
  116. STDMETHODIMP UserCPL(HWND hwndParent);
  117. };
  118. class CLUUser : public IUser
  119. {
  120. friend class CLUDatabase;
  121. friend class CLUEnum;
  122. private:
  123. NLS_STR m_nlsUsername;
  124. NLS_STR m_nlsDir;
  125. NLS_STR m_nlsPassword;
  126. BOOL m_fAuthenticated;
  127. BOOL m_fTempSupervisor;
  128. HKEY m_hkeyDB;
  129. HKEY m_hkeyUser;
  130. BOOL m_fUserExists;
  131. BOOL m_fAppearsSupervisor;
  132. BOOL m_fLoadedProfile;
  133. ULONG m_cRef;
  134. CLUDatabase *m_pDB;
  135. CLUUser(CLUDatabase *m_pDB);
  136. ~CLUUser();
  137. HRESULT Init(LPCSTR pszUsername);
  138. BOOL Exists() { return m_fUserExists; }
  139. HRESULT GetSupervisorPassword(BUFFER *pbufPCE);
  140. BOOL IsSystemCurrentUser(void);
  141. public:
  142. // *** IUnknown methods ***
  143. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  144. STDMETHODIMP_(ULONG) AddRef(void);
  145. STDMETHODIMP_(ULONG) Release(void);
  146. STDMETHODIMP GetName(LPSTR pbBuffer, LPDWORD pcbBuffer);
  147. STDMETHODIMP GetProfileDirectory(LPSTR pbBuffer, LPDWORD pcbBuffer);
  148. STDMETHODIMP IsSupervisor(void);
  149. STDMETHODIMP SetSupervisorPrivilege(BOOL fMakeSupervisor, LPCSTR pszSupervisorPassword);
  150. STDMETHODIMP MakeTempSupervisor(BOOL fMakeSupervisor, LPCSTR pszSupervisorPassword);
  151. STDMETHODIMP AppearsSupervisor(void);
  152. STDMETHODIMP Authenticate(LPCSTR pszPassword);
  153. STDMETHODIMP ChangePassword(LPCSTR pszOldPassword, LPCSTR pszNewPassword);
  154. STDMETHODIMP GetPasswordCache(LPCSTR pszPassword, LPHANDLE phOut);
  155. STDMETHODIMP LoadProfile(HKEY *phkeyUser);
  156. STDMETHODIMP UnloadProfile(HKEY hkeyUser);
  157. STDMETHODIMP GetComponentSettings(REFCLSID clsidComponent,
  158. LPCSTR pszName, IUnknown **ppOut,
  159. DWORD fdwAccess);
  160. STDMETHODIMP EnumerateComponentSettings(IEnumUnknown **ppOut,
  161. DWORD fdwAccess);
  162. };
  163. class CLUEnum : public IEnumUnknown
  164. {
  165. friend class CLUDatabase;
  166. private:
  167. ULONG m_cRef;
  168. HKEY m_hkeyDB;
  169. LPSTR *m_papszNames;
  170. UINT m_cNames;
  171. UINT m_cAlloc;
  172. UINT m_iCurrent;
  173. CLUDatabase *m_pDB;
  174. CLUEnum(CLUDatabase *m_pDB);
  175. ~CLUEnum();
  176. HRESULT Init(void);
  177. void Cleanup(void);
  178. public:
  179. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  180. STDMETHODIMP_(ULONG) AddRef(void);
  181. STDMETHODIMP_(ULONG) Release(void);
  182. STDMETHODIMP Next(ULONG celt, IUnknown __RPC_FAR *__RPC_FAR *rgelt,
  183. ULONG __RPC_FAR *pceltFetched);
  184. STDMETHODIMP Skip(ULONG celt);
  185. STDMETHODIMP Reset(void);
  186. STDMETHODIMP Clone(IEnumUnknown __RPC_FAR *__RPC_FAR *ppenum);
  187. };
  188. #ifdef USER_SETTINGS_IMPLEMENTED
  189. class CUserSettings : public IUserSettings
  190. {
  191. private:
  192. ULONG m_cRef;
  193. CLSID m_clsid;
  194. NLS_STR m_nlsName;
  195. HKEY m_hkey;
  196. CUserSettings();
  197. ~CUserSettings();
  198. public:
  199. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  200. STDMETHODIMP_(ULONG) AddRef(void);
  201. STDMETHODIMP_(ULONG) Release(void);
  202. STDMETHODIMP GetCLSID(CLSID *pclsidOut);
  203. STDMETHODIMP GetName(LPSTR pbBuffer, LPDWORD pcbBuffer);
  204. STDMETHODIMP GetDisplayName(LPSTR pbBuffer, LPDWORD pcbBuffer);
  205. STDMETHODIMP QueryKey(HKEY *phkeyOut);
  206. };
  207. #endif
  208. class CWizData : public IUserProfileInit
  209. {
  210. public:
  211. HRESULT m_hresRatings; /* result of VerifySupervisorPassword("") */
  212. BOOL m_fGoMultiWizard; /* TRUE if this is the big go-multiuser wizard */
  213. NLS_STR m_nlsSupervisorPassword;
  214. NLS_STR m_nlsUsername;
  215. NLS_STR m_nlsUserPassword;
  216. IUserDatabase *m_pDB;
  217. IUser *m_pUserToClone;
  218. int m_idPrevPage; /* ID of page before Finish */
  219. UINT m_cRef;
  220. DWORD m_fdwOriginalPerUserFolders;
  221. DWORD m_fdwNewPerUserFolders;
  222. DWORD m_fdwCloneFromDefault;
  223. BOOL m_fCreatingProfile;
  224. IUser *m_pNewUser;
  225. BOOL m_fChannelHack;
  226. CWizData();
  227. ~CWizData();
  228. // *** IUnknown methods ***
  229. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  230. STDMETHODIMP_(ULONG) AddRef(void);
  231. STDMETHODIMP_(ULONG) Release(void);
  232. STDMETHODIMP PreInitProfile(HKEY hkeyUser, LPCSTR pszProfileDir);
  233. STDMETHODIMP PostInitProfile(HKEY hkeyUser, LPCSTR pszProfileDir);
  234. };
  235. void InitFolderCheckboxes(HWND hDlg, CWizData *pwd);
  236. void FinishChooseFolders(HWND hDlg, CWizData *pwd);
  237. BOOL ProfileUIRestricted(void);
  238. void ReportRestrictionError(HWND hwndOwner);
  239. typedef HRESULT (*PFNPROGRESS)(LPARAM lParam);
  240. HRESULT CallWithinProgressDialog(HWND hwndOwner, UINT idResource, PFNPROGRESS pfn,
  241. LPARAM lParam);
  242. HRESULT IsCurrentUserSupervisor(IUserDatabase *pDB);
  243. /* NOTE: Keep the following flags in the same order as the corresponding
  244. * entries in the folder descriptor table in msluwiz.cpp.
  245. */
  246. const DWORD FOLDER_DESKTOP = 0x00000001;
  247. const DWORD FOLDER_NETHOOD = 0x00000002;
  248. const DWORD FOLDER_RECENT = 0x00000004;
  249. const DWORD FOLDER_STARTMENU = 0x00000008;
  250. const DWORD FOLDER_PROGRAMS = 0x00000010;
  251. const DWORD FOLDER_STARTUP = 0x00000020;
  252. const DWORD FOLDER_FAVORITES = 0x00000040;
  253. const DWORD FOLDER_CACHE = 0x00000080;
  254. const DWORD FOLDER_MYDOCS = 0x00000100;