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.

478 lines
15 KiB

  1. #ifndef _AUTODIAL_H_
  2. #define _AUTODIAL_H_
  3. #include <regstr.h>
  4. #include <inetreg.h>
  5. #include <windowsx.h>
  6. #include <rasdlg.h>
  7. // initialization for autodial
  8. void InitAutodialModule(BOOL fGlobalDataNeeded);
  9. void ExitAutodialModule(void);
  10. void ResetAutodialModule(void);
  11. void SetAutodialEnable(BOOL);
  12. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  13. // connection mutex name
  14. #define CONNECTION_MUTEX TEXT("WininetConnectionMutex")
  15. // proxy registry mutex name, used to serialze access to proxy settings
  16. #define PROXY_REG_MUTEX TEXT("WininetProxyRegistryMutex")
  17. // typedefs for function pointers for Internet wizard functions
  18. typedef VOID (WINAPI * INETPERFORMSECURITYCHECK) (HWND,LPBOOL);
  19. #define SMALLBUFLEN 48 // convenient size for small buffers
  20. // callback prototype
  21. extern "C"
  22. VOID
  23. InternetAutodialCallback(
  24. IN DWORD dwOpCode,
  25. IN LPCVOID lpParam
  26. );
  27. // opcode ordinals for dwOpCode parameter in hook
  28. #define WINSOCK_CALLBACK_CONNECT 1
  29. #define WINSOCK_CALLBACK_GETHOSTBYADDR 2
  30. #define WINSOCK_CALLBACK_GETHOSTBYNAME 3
  31. #define WINSOCK_CALLBACK_LISTEN 4
  32. #define WINSOCK_CALLBACK_RECVFROM 5
  33. #define WINSOCK_CALLBACK_SENDTO 6
  34. // maximum length of local host name
  35. #define MAX_LOCAL_HOST 255
  36. // max length of exported autodial handler function
  37. #define MAX_AUTODIAL_FCNNAME 48
  38. INT_PTR CALLBACK OnlineDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  39. LPARAM lParam);
  40. BOOL EnsureRasLoaded(void);
  41. INT_PTR CALLBACK GoOfflinePromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  42. INT_PTR CALLBACK ConnectDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  43. extern const CHAR szRegPathRemoteAccess[];
  44. extern const CHAR szRegPathInternetSettings[];
  45. extern const CHAR szRegValEnableAutodial[];
  46. extern const CHAR szRegValInternetEntry[];
  47. extern HANDLE g_hAutodialMutex;
  48. extern HANDLE g_hProxyRegMutex;
  49. extern BOOL g_fGetHostByNameNULLFails;
  50. //
  51. // Formerly dialmsg.h
  52. //
  53. #define WM_DIALMON_FIRST (WM_USER + 100)
  54. // message sent to dial monitor app window indicating that there has been
  55. // winsock activity and dial monitor should reset its idle timer
  56. #define WM_WINSOCK_ACTIVITY (WM_DIALMON_FIRST + 0)
  57. // message sent to dial monitor app window when user changes timeout through
  58. // UI, indicating that timeout value or status has changed
  59. #define WM_REFRESH_SETTINGS (WM_DIALMON_FIRST + 1)
  60. // message sent to dial monitor app window to set the name of the connectoid
  61. // to monitor and eventually disconnect. lParam should be an LPSTR that
  62. // points to the name of the connectoid.
  63. #define WM_SET_CONNECTOID_NAME (WM_DIALMON_FIRST + 2)
  64. // message sent to dial monitor app window when app exits
  65. #define WM_IEXPLORER_EXITING (WM_DIALMON_FIRST + 3)
  66. // yanked from ras.h becuase we include it as ver4.0 and this is ver4.1.
  67. #include <pshpack4.h>
  68. #define RASAUTODIALENTRYA struct tagRASAUTODIALENTRYA
  69. RASAUTODIALENTRYA
  70. {
  71. DWORD dwSize;
  72. DWORD dwFlags;
  73. DWORD dwDialingLocation;
  74. CHAR szEntry[ RAS_MaxEntryName + 1];
  75. };
  76. #define LPRASAUTODIALENTRYA RASAUTODIALENTRYA*
  77. #define RASCREDENTIALSW struct tagRASCREDENTIALSW
  78. RASCREDENTIALSW
  79. {
  80. DWORD dwSize;
  81. DWORD dwMask;
  82. WCHAR szUserName[ UNLEN + 1 ];
  83. WCHAR szPassword[ PWLEN + 1 ];
  84. WCHAR szDomain[ DNLEN + 1 ];
  85. };
  86. #define LPRASCREDENTIALSW RASCREDENTIALSW*
  87. #define RASCM_UserName 0x00000001
  88. #define RASCM_Password 0x00000002
  89. #define RASCM_Domain 0x00000004
  90. #include <poppack.h>
  91. // Types for ras functions
  92. typedef DWORD (WINAPI* _RASHANGUP) (HRASCONN);
  93. typedef DWORD (WINAPI* _RASDIALA) (LPRASDIALEXTENSIONS, LPSTR, LPRASDIALPARAMSA, DWORD, LPVOID, LPHRASCONN);
  94. typedef DWORD (WINAPI* _RASENUMENTRIESA) (LPSTR, LPSTR, LPRASENTRYNAMEA, LPDWORD, LPDWORD);
  95. typedef DWORD (WINAPI* _RASGETENTRYDIALPARAMSA) (LPCSTR, LPRASDIALPARAMSA, LPBOOL);
  96. typedef DWORD (WINAPI* _RASSETENTRYDIALPARAMSA) (LPCSTR, LPRASDIALPARAMSA, BOOL);
  97. typedef DWORD (WINAPI* _RASEDITPHONEBOOKENTRYA) (HWND, LPSTR, LPSTR);
  98. typedef DWORD (WINAPI* _RASCREATEPHONEBOOKENTRYA) (HWND, LPSTR);
  99. typedef DWORD (WINAPI* _RASGETERRORSTRINGA) (UINT, LPSTR, DWORD);
  100. typedef DWORD (WINAPI* _RASGETCONNECTSTATUSA) (HRASCONN, LPRASCONNSTATUSA);
  101. typedef DWORD (WINAPI* _RASENUMCONNECTIONSA) (LPRASCONNA, LPDWORD, LPDWORD);
  102. typedef DWORD (WINAPI* _RASGETENTRYPROPERTIESA) ( LPSTR, LPSTR, LPRASENTRYA, LPDWORD, LPBYTE, LPDWORD );
  103. typedef DWORD (WINAPI* _RASDIALDLGA) (LPSTR, LPSTR, LPSTR, LPRASDIALDLG);
  104. typedef DWORD (WINAPI* _RASDIALW) (LPRASDIALEXTENSIONS, LPWSTR, LPRASDIALPARAMSW, DWORD, LPVOID, LPHRASCONN);
  105. typedef DWORD (WINAPI* _RASENUMENTRIESW) (LPWSTR, LPWSTR, LPRASENTRYNAMEW, LPDWORD, LPDWORD);
  106. typedef DWORD (WINAPI* _RASGETENTRYDIALPARAMSW) (LPCWSTR, LPRASDIALPARAMSW, LPBOOL);
  107. typedef DWORD (WINAPI* _RASSETENTRYDIALPARAMSW) (LPCWSTR, LPRASDIALPARAMSW, BOOL);
  108. typedef DWORD (WINAPI* _RASEDITPHONEBOOKENTRYW) (HWND, LPWSTR, LPWSTR);
  109. typedef DWORD (WINAPI* _RASCREATEPHONEBOOKENTRYW) (HWND, LPWSTR);
  110. typedef DWORD (WINAPI* _RASGETERRORSTRINGW) (UINT, LPWSTR, DWORD);
  111. typedef DWORD (WINAPI* _RASGETCONNECTSTATUSW) (HRASCONN, LPRASCONNSTATUSW);
  112. typedef DWORD (WINAPI* _RASENUMCONNECTIONSW) (LPRASCONNW, LPDWORD, LPDWORD);
  113. typedef DWORD (WINAPI* _RASGETENTRYPROPERTIESW) ( LPWSTR, LPWSTR, LPRASENTRYW, LPDWORD, LPBYTE, LPDWORD );
  114. typedef DWORD (WINAPI* _RASDIALDLGW) (LPWSTR, LPWSTR, LPWSTR, LPRASDIALDLG);
  115. typedef DWORD (WINAPI* _RASGETAUTODIALADDRESSA) (LPCSTR, LPDWORD, LPRASAUTODIALENTRYA, LPDWORD, LPDWORD);
  116. typedef DWORD (WINAPI* _RASSETAUTODIALADDRESSA) (LPCSTR, DWORD, LPRASAUTODIALENTRYA, DWORD, DWORD);
  117. typedef DWORD (WINAPI* _RASGETCREDENTIALSW) (LPCWSTR, LPCWSTR, LPRASCREDENTIALSW);
  118. typedef DWORD (WINAPI* _RASSETCREDENTIALSW) (LPCWSTR, LPCWSTR, LPRASCREDENTIALSW, BOOL);
  119. typedef DWORD (WINAPI* _RASINTERNETDIAL) (HWND, LPSTR, DWORD, DWORD_PTR *, DWORD);
  120. typedef DWORD (WINAPI* _RASINTERNETHANGUP) (DWORD_PTR, DWORD);
  121. typedef DWORD (WINAPI* _RASINTERNETAUTODIAL) (DWORD, HWND);
  122. typedef DWORD (WINAPI* _RASINTERNETAUTODIALHANG) (DWORD);
  123. typedef DWORD (WINAPI* _RASINTERNETCONNSTATE) (LPDWORD, LPSTR, DWORD, DWORD);
  124. typedef DWORD (WINAPI* _RNAGETDEFAULTAUTODIAL) (LPSTR, DWORD, LPDWORD);
  125. typedef DWORD (WINAPI* _RNASETDEFAULTAUTODIAL) (LPSTR, DWORD);
  126. // Ras ansi prototypes
  127. DWORD _RasDialA(LPRASDIALEXTENSIONS, LPSTR, LPRASDIALPARAMSA, DWORD, LPVOID, LPHRASCONN);
  128. DWORD _RasEnumEntriesA(LPTSTR, LPSTR, LPRASENTRYNAMEA, LPDWORD, LPDWORD);
  129. DWORD _RasGetEntryDialParamsA(LPCSTR, LPRASDIALPARAMSA, LPBOOL);
  130. DWORD _RasSetEntryDialParamsA(LPCSTR, LPRASDIALPARAMSA, BOOL);
  131. DWORD _RasEditPhonebookEntryA(HWND, LPSTR, LPSTR);
  132. DWORD _RasCreatePhonebookEntryA(HWND, LPSTR);
  133. DWORD _RasGetErrorStringA(UINT, LPSTR, DWORD);
  134. DWORD _RasGetConnectStatusA(HRASCONN, LPRASCONNSTATUSA);
  135. DWORD _RasEnumConnectionsA(LPRASCONNA, LPDWORD, LPDWORD);
  136. DWORD _RasGetEntryPropertiesA(LPSTR, LPSTR, LPRASENTRYA, LPDWORD, LPBYTE, LPDWORD );
  137. // Ras wide prototypes
  138. DWORD _RasDialW(LPRASDIALEXTENSIONS, LPWSTR, LPRASDIALPARAMSW, DWORD, LPVOID, LPHRASCONN);
  139. DWORD _RasEnumEntriesW(LPWSTR, LPWSTR, LPRASENTRYNAMEW, LPDWORD, LPDWORD);
  140. DWORD _RasGetEntryDialParamsW(LPCWSTR, LPRASDIALPARAMSW, LPBOOL);
  141. DWORD _RasSetEntryDialParamsW(LPCWSTR, LPRASDIALPARAMSW, BOOL);
  142. DWORD _RasEditPhonebookEntryW(HWND, LPWSTR, LPWSTR);
  143. DWORD _RasCreatePhonebookEntryW(HWND, LPWSTR);
  144. DWORD _RasGetErrorStringW(UINT, LPWSTR, DWORD);
  145. DWORD _RasGetConnectStatusW(HRASCONN, LPRASCONNSTATUSW);
  146. DWORD _RasEnumConnectionsW(LPRASCONNW, LPDWORD, LPDWORD);
  147. DWORD _RasGetEntryPropertiesW(LPWSTR, LPWSTR, LPRASENTRYW, LPDWORD, LPBYTE, LPDWORD);
  148. DWORD _RasGetCredentialsW(LPCWSTR, LPCWSTR, LPRASCREDENTIALSW);
  149. DWORD _RasSetCredentialsW(LPCWSTR, LPCWSTR, LPRASCREDENTIALSW, BOOL);
  150. DWORD _RasHangUp(HRASCONN);
  151. // how many ras connections do we care about?
  152. #define MAX_CONNECTION 4
  153. #define CI_SAVE_PASSWORD 0x01
  154. #define CI_DIAL_UNATTENDED 0x02
  155. #define CI_AUTO_CONNECT 0x04
  156. #define CI_SHOW_OFFLINE 0x08
  157. #define CI_SHOW_DETAILS 0x10
  158. // Types of network coverage settable from the ui
  159. #define CO_INTERNET 1
  160. #define CO_INTRANET 2
  161. // definition to call RestartDialog in shell32
  162. typedef int (* _RESTARTDIALOG) (HWND, LPCTSTR, DWORD);
  163. // dialstate - passed to DialAndShowProgress
  164. typedef struct _dialstate {
  165. DWORD dwResult; // final result
  166. DWORD dwTry; // number of dial attempts
  167. DWORD dwTryCurrent; // current attempt
  168. DWORD dwWait; // time to wait between them
  169. DWORD dwWaitCurrent; // current time
  170. HRASCONN hConn; // ras connection
  171. UINT_PTR uTimerId; // timer for redial
  172. HANDLE hEvent; // event when dialing is complete
  173. DWORD dwFlags;
  174. RASDIALPARAMSW params;
  175. } DIALSTATE;
  176. BOOL
  177. GetRedialParameters(
  178. IN LPWSTR pszConn,
  179. OUT LPDWORD pdwDialAttempts,
  180. OUT LPDWORD pdwDialInterval
  181. );
  182. #define DEFAULT_DIAL_ATTEMPTS 10
  183. #define DEFAULT_DIAL_INTERVAL 5
  184. // When dealing with custom dial handler, it will inform us of disconnections.
  185. // We keep an internal state
  186. #define STATE_NONE 0
  187. #define STATE_CONNECTED 1
  188. #define STATE_DISCONNECTED 2
  189. // info relevant to a custom dial handler
  190. typedef struct _autodial {
  191. BOOL fConfigured;
  192. BOOL fEnabled;
  193. BOOL fHasEntry;
  194. BOOL fUnattended;
  195. BOOL fSecurity;
  196. BOOL fForceDial;
  197. WCHAR pszEntryName[RAS_MaxEntryName + 1];
  198. } AUTODIAL;
  199. typedef struct __cdhinfo {
  200. DWORD dwHandlerFlags;
  201. WCHAR pszDllName[MAX_PATH];
  202. WCHAR pszFcnName[MAX_PATH];
  203. BOOL fHasHandler;
  204. } CDHINFO;
  205. // dummy connection handle used to mean custom dial handler
  206. #define CDH_HCONN DWORD_PTR(-3)
  207. #define SAFE_RELEASE(a) \
  208. if(a) \
  209. { \
  210. a->Release(); \
  211. a = NULL; \
  212. }
  213. // List of properties supported by CDialEngine
  214. typedef enum {
  215. PropInvalid,
  216. PropUserName,
  217. PropPassword,
  218. PropDomain,
  219. PropSavePassword,
  220. PropPhoneNumber,
  221. PropRedialCount,
  222. PropRedialInterval,
  223. PropLastError,
  224. PropResolvedPhone
  225. } DIALPROP;
  226. typedef struct _PropMap {
  227. LPWSTR pwzProperty;
  228. DIALPROP Prop;
  229. } PROPMAP;
  230. //
  231. // Class definitions for default implementations
  232. //
  233. class CDialEngine : IDialEngine
  234. {
  235. private:
  236. ULONG m_cRef;
  237. IDialEventSink * m_pdes;
  238. RASDIALPARAMSW m_rdp;
  239. RASCREDENTIALSW m_rcred;
  240. RASCONNSTATE m_rcs;
  241. HRASCONN m_hConn;
  242. HWND m_hwnd;
  243. BOOL m_fPassword;
  244. BOOL m_fSavePassword;
  245. BOOL m_fCurrentlyDialing;
  246. BOOL m_fCancelled;
  247. UINT m_uRasMsg;
  248. DWORD m_dwTryCurrent;
  249. DWORD m_dwTryTotal;
  250. DWORD m_dwWaitCurrent;
  251. DWORD m_dwWaitTotal;
  252. DWORD m_dwError;
  253. UINT_PTR m_uTimerId;
  254. public:
  255. CDialEngine();
  256. ~CDialEngine();
  257. // IUnknown members
  258. STDMETHODIMP QueryInterface(REFIID riid, void **ppunk);
  259. STDMETHODIMP_(ULONG) AddRef();
  260. STDMETHODIMP_(ULONG) Release();
  261. // IDialEngine members
  262. STDMETHODIMP Initialize(LPCWSTR pwzConnectoid, IDialEventSink *pIDES);
  263. STDMETHODIMP GetProperty(LPCWSTR pwzProperty, LPWSTR pwzValue, DWORD dwBufSize);
  264. STDMETHODIMP SetProperty(LPCWSTR pwzProperty, LPCWSTR pwzValue);
  265. STDMETHODIMP Dial();
  266. STDMETHODIMP HangUp();
  267. STDMETHODIMP GetConnectedState(DWORD *pdwState);
  268. STDMETHODIMP GetConnectHandle(DWORD_PTR *pdwHandle);
  269. // other members
  270. VOID OnRasEvent(RASCONNSTATE rcs, DWORD dwError);
  271. VOID OnTimer();
  272. static LONG_PTR CALLBACK
  273. EngineWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  274. DWORD MapRCS(RASCONNSTATE rcs);
  275. VOID UpdateRasState();
  276. STDMETHODIMP StartConnection();
  277. STDMETHODIMP CleanConnection();
  278. VOID EndOfOperation();
  279. DIALPROP PropertyToOrdinal(LPCWSTR pwzProperty);
  280. BOOL ResolvePhoneNumber(LPWSTR pwzBuffer, DWORD dwLen);
  281. };
  282. class CDialUI : IDialEventSink
  283. {
  284. private:
  285. typedef enum tagSTATE
  286. {
  287. UISTATE_Interactive,
  288. UISTATE_Dialing,
  289. UISTATE_Unattended
  290. } UISTATE;
  291. ULONG m_cRef;
  292. IDialEngine * m_pEng;
  293. IDialBranding * m_pdb;
  294. HWND m_hwndParent;
  295. HWND m_hwnd; // dialog box
  296. DWORD m_dwError; // final dialing result
  297. DWORD m_dwFlags;
  298. UISTATE m_State;
  299. BOOL m_fOfflineSemantics;
  300. BOOL m_fSavePassword;
  301. BOOL m_fAutoConnect;
  302. BOOL m_fPasswordChanged;
  303. DIALSTATE * m_pDial;
  304. BOOL m_fCDH;
  305. BOOL m_fDialedCDH;
  306. CDHINFO m_cdh;
  307. public:
  308. CDialUI(HWND hwndParent);
  309. ~CDialUI();
  310. // IUnknown members
  311. STDMETHODIMP QueryInterface(REFIID riid, void **ppunk);
  312. STDMETHODIMP_(ULONG) AddRef();
  313. STDMETHODIMP_(ULONG) Release();
  314. // IDialEventSink members
  315. STDMETHODIMP OnEvent(DWORD dwEvent, DWORD dwStatus);
  316. // other members
  317. static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  318. VOID OnInitDialog();
  319. VOID OnConnect();
  320. VOID OnCancel();
  321. VOID OnSelChange();
  322. DWORD StartDial(DIALSTATE *pDial, DWORD dwFlags);
  323. VOID EnumerateConnectoids();
  324. VOID SaveProps();
  325. VOID GetProps();
  326. VOID FixUIComponents();
  327. BOOL DialedCDH(VOID)
  328. {
  329. return m_fDialedCDH;
  330. }
  331. };
  332. // CDH prototypes
  333. BOOL
  334. IsCDH(
  335. IN LPWSTR pszEntryName,
  336. IN CDHINFO *pcdh
  337. );
  338. BOOL
  339. CallCDH(
  340. IN HWND hwndParent,
  341. IN LPWSTR pszEntryName,
  342. IN CDHINFO *pcdh,
  343. IN DWORD dwOperation,
  344. OUT LPDWORD lpdwResult
  345. );
  346. BOOL
  347. IsAutodialEnabled(
  348. OUT BOOL *pfForceDial,
  349. IN AUTODIAL *pConfig
  350. );
  351. BOOL
  352. FixProxySettingsForCurrentConnection(
  353. IN BOOL fForceUpdate
  354. );
  355. VOID
  356. GetConnKeyA(
  357. IN LPSTR pszConn,
  358. IN LPSTR pszKey,
  359. IN int iLen
  360. );
  361. VOID
  362. GetConnKeyW(
  363. IN LPWSTR pszConn,
  364. IN LPWSTR pszKey,
  365. IN int iLen
  366. );
  367. BOOL
  368. InternetAutodialIfNotLocalHost(
  369. IN LPSTR OPTIONAL pszURL,
  370. IN LPSTR OPTIONAL pszHostName
  371. );
  372. BOOL
  373. DialIfWin2KCDH(
  374. LPWSTR pszEntry,
  375. HWND hwndParent,
  376. BOOL fHideParent,
  377. DWORD *lpdwResult,
  378. DWORD_PTR *lpdwConnection
  379. );
  380. BOOL
  381. InitCommCtrl(
  382. VOID
  383. );
  384. VOID
  385. ExitCommCtrl(
  386. VOID
  387. );
  388. DWORD
  389. GetAutodialMode(
  390. );
  391. DWORD
  392. SetAutodialMode(
  393. IN DWORD dwMode
  394. );
  395. DWORD
  396. GetAutodialConnection(
  397. CHAR *pszBuffer,
  398. DWORD dwBufferLength
  399. );
  400. DWORD
  401. SetAutodialConnection(
  402. CHAR *pszConnection
  403. );
  404. #endif // _AUTODIAL_H_