1 // SoftEther VPN Source Code - Developer Edition Master Branch
2 // Cedar Communication Module
3 
4 
5 // SWInner.h
6 // Header of SW.c (for internal use)
7 
8 #ifndef	SW_INNER_H
9 #define	SW_INNER_H
10 
11 #include "WinUi.h"
12 
13 // Component string
14 #define	SW_NAME_VPNSERVER			"vpnserver"
15 #define	SW_LONG_VPNSERVER			_UU("SW_LONG_VPNSERVER")
16 
17 #define	SW_NAME_VPNCLIENT			"vpnclient"
18 #define	SW_LONG_VPNCLIENT			_UU("SW_LONG_VPNCLIENT")
19 
20 #define	SW_NAME_VPNBRIDGE			"vpnbridge"
21 #define	SW_LONG_VPNBRIDGE			_UU("SW_LONG_VPNBRIDGE")
22 
23 #define	SW_NAME_VPNSMGR				"vpnsmgr"
24 #define	SW_LONG_VPNSMGR				_UU("SW_LONG_VPNSMGR")
25 
26 #define	SW_NAME_VPNCMGR				"vpncmgr"
27 #define	SW_LONG_VPNCMGR				_UU("SW_LONG_VPNCMGR")
28 
29 #define	SW_VPN_CLIENT_UIHELPER_REGVALUE	GC_SW_UIHELPER_REGVALUE
30 
31 #define	SW_VPN_CLIENT_EXT_REGKEY	"SOFTWARE\\Classes\\.vpn"
32 #define	SW_VPN_CLIENT_EXT_REGVALUE	"vpnfile"
33 #define	SW_VPN_CLIENT_EXT_REGKEY_SUB1	"SOFTWARE\\Classes\\.vpn\\vpnfile"
34 #define	SW_VPN_CLIENT_EXT_REGKEY_SUB2	"SOFTWARE\\Classes\\.vpn\\vpnfile\\ShellNew"
35 
36 #define	SW_VPN_CLIENT_VPNFILE_REGKEY	"SOFTWARE\\Classes\\vpnfile"
37 #define	SW_VPN_CLIENT_VPNFILE_REGVALUE	"VPN Client Connection Setting File"
38 #define	SW_VPN_CLIENT_VPNFILE_ICON_REGKEY	"SOFTWARE\\Classes\\vpnfile\\DefaultIcon"
39 #define	SW_VPN_CLIENT_VPNFILE_SHELLOPEN_CMD_REGKEY	"SOFTWARE\\Classes\\vpnfile\\shell\\open\\command"
40 #define	SW_VPN_CLIENT_VPNFILE_SHELLOPEN_CMD_REGKEY_SUB1	"SOFTWARE\\Classes\\vpnfile\\shell\\open"
41 #define	SW_VPN_CLIENT_VPNFILE_SHELLOPEN_CMD_REGKEY_SUB2	"SOFTWARE\\Classes\\vpnfile\\shell"
42 
43 #define	SW_REG_KEY_EULA					"Software\\" GC_REG_COMPANY_NAME "\\Setup Wizard Settings\\Eula"
44 
45 
46 // Component ID
47 #define	SW_CMP_VPN_SERVER			1	// VPN Server
48 #define	SW_CMP_VPN_CLIENT			2	// VPN Client
49 #define	SW_CMP_VPN_BRIDGE			3	// VPN Bridge
50 #define	SW_CMP_VPN_SMGR				4	// VPN Server Manager (Tools Only)
51 #define	SW_CMP_VPN_CMGR				5	// VPN Client Manager (Tools Only)
52 
53 // Exit code
54 #define	SW_EXIT_CODE_USER_CANCEL			1000000001		// Cancel by the user
55 #define	SW_EXIT_CODE_INTERNAL_ERROR			1000000002		// Internal error
56 
57 // Special messages to be used in the setup wizard
58 #define	WM_SW_BASE						(WM_APP + 251)
59 #define	WM_SW_INTERACT_UI				(WM_SW_BASE + 0)	// UI processing
60 #define	WM_SW_EXIT						(WM_SW_BASE + 1)	// Close
61 
62 // Automatic connection setting file
63 #define	SW_AUTO_CONNECT_ACCOUNT_FILE_NAME	"auto_connect.vpn"
64 #define	SW_AUTO_CONNECT_ACCOUNT_FILE_NAME_W	L"auto_connect.vpn"
65 
66 // Installer cache file to be stored in the VPN Client installation folder
67 #define	SW_SFX_CACHE_FILENAME				L"installer.cache"
68 
69 // Flag file
70 #define	SW_FLAG_EASY_MODE					"easy_mode.flag"
71 #define	SW_FLAG_EASY_MODE_2					"@easy_mode.flag"
72 
73 // Multiple-starts prevention name
74 #define	SW_SINGLE_INSTANCE_NAME				"SoftEther_VPN_Setup_Wizard"
75 
76 // Time to wait for the VPN Client service startup
77 #define	SW_VPNCLIENT_SERVICE_WAIT_READY_TIMEOUT		(30 * 1000)
78 
79 // UI interaction
80 typedef struct SW_UI
81 {
82 	UINT Type;							// Type
83 	wchar_t *Message;					// Message string
84 	UINT Param;							// Parameters
85 	UINT RetCode;						// Return value
86 } SW_UI;
87 
88 // Type of UI interaction
89 #define	SW_UI_TYPE_PRINT				0	// Display the message
90 #define	SW_UI_TYPE_MSGBOX				1	// Show a message box
91 #define	SW_UI_TYPE_FINISH				2	// Completion
92 #define	SW_UI_TYPE_ERROR				3	// Error
93 
94 // Resource type of the file stored in the setup.exe
95 #define	SW_SFX_RESOURCE_TYPE			"DATAFILE"
96 
97 // Code of old MSI
98 typedef struct SW_OLD_MSI
99 {
100 	char *ProductCode;						// Product code
101 	char *ComponentCode;					// Component code
102 } SW_OLD_MSI;
103 
104 // Component
105 typedef struct SW_COMPONENT
106 {
107 	UINT Id;							// ID
108 	bool Detected;						// Whether it has been detected as an installation source
109 	LIST *NeedFiles;					// Necessary files
110 	char *Name;							// Internal name
111 	char *SvcName;						// Service name
112 	wchar_t *Title;						// Display name
113 	wchar_t *Description;				// Detail
114 	wchar_t *DefaultDirName;			// Installation directory name of the default
115 	wchar_t *LongName;					// Long name
116 	UINT Icon;							// Icon
117 	UINT IconExeIndex;					// The index number of the icon within the Setup.exe
118 	bool SystemModeOnly;				// Only system mode
119 	bool InstallService;				// Installation of service
120 	wchar_t *SvcFileName;				// Service file name
121 	wchar_t *StartExeName;				// Start EXE file name
122 	wchar_t *StartDescription;			// Description of the running software
123 	SW_OLD_MSI *OldMsiList;				// Old MSI Product List
124 	UINT NumOldMsi;						// The number of old MSI Product List
125 	bool CopyVGDat;						// Copy of the VPN Gate DAT file
126 } SW_COMPONENT;
127 
128 // File copy task
129 typedef struct SW_TASK_COPY
130 {
131 	wchar_t SrcFileName[MAX_SIZE];		// Original file name
132 	wchar_t DstFileName[MAX_SIZE];		// Destination file name
133 	wchar_t SrcDir[MAX_SIZE];			// Source directory
134 	wchar_t DstDir[MAX_SIZE];			// Destination directory
135 	bool Overwrite;						// Override flag
136 	bool SetupFile;						// Setup file flag
137 } SW_TASK_COPY;
138 
139 // Link creation task
140 typedef struct SW_TASK_LINK
141 {
142 	wchar_t TargetDir[MAX_SIZE];		// Target directory
143 	wchar_t TargetExe[MAX_SIZE];		// Target EXE file name
144 	wchar_t TargetArg[MAX_SIZE];		// Arguments to pass to the target
145 	wchar_t IconExe[MAX_SIZE];			// Icon EXE file name
146 	UINT IconIndex;						// Icon Index number
147 	wchar_t DestDir[MAX_SIZE];			// Directory name to be created
148 	wchar_t DestName[MAX_SIZE];			// File name to be created
149 	wchar_t DestDescription[MAX_SIZE];	// Description string
150 	bool NoDeleteDir;					// Do not delete the directory on uninstall
151 } SW_TASK_LINK;
152 
153 // Setup Tasks
154 typedef struct SW_TASK
155 {
156 	LIST *CopyTasks;					// File copy task
157 	LIST *SetSecurityPaths;				// List of paths to set the security
158 	LIST *LinkTasks;					// Link creation task
159 } SW_TASK;
160 
161 // Setup log
162 typedef struct SW_LOG
163 {
164 	UINT Type;							// Type of log
165 	wchar_t Path[MAX_PATH];				// Path
166 } SW_LOG;
167 
168 // Type of setup log
169 #define	SW_LOG_TYPE_FILE				1	// File
170 #define	SW_LOG_TYPE_DIR					2	// Directory
171 #define	SW_LOG_TYPE_REGISTRY			3	// Registry
172 #define	SW_LOG_TYPE_LNK					4	// Shortcut file
173 #define	SW_LOG_TYPE_LNK_DIR				5	// Shortcut directory
174 #define	SW_LOG_TYPE_SVC					6	// Service
175 
176 // Setup log files
177 typedef struct SW_LOGFILE
178 {
179 	LIST *LogList;							// List of log
180 	bool IsSystemMode;						// Whether the system mode
181 	UINT Build;								// Build Number
182 	SW_COMPONENT *Component;				// Component
183 } SW_LOGFILE;
184 
185 // SFX file
186 typedef struct SW_SFX_FILE
187 {
188 	char InnerFileName[MAX_PATH];				// Internal file name
189 	wchar_t DiskFileName[MAX_PATH];				// File name of the disk
190 } SW_SFX_FILE;
191 
192 // SW instance
193 typedef struct SW
194 {
195 	LIST *ComponentList;				// List of components
196 	wchar_t InstallSrc[MAX_SIZE];		// Source directory
197 	bool IsSystemMode;					// Whether the system mode
198 	bool UninstallMode;					// Uninstall mode
199 	UINT ExitCode;						// Exit code
200 	void *ReExecProcessHandle;			// Child process handle of a result of the re-run itself
201 	bool IsReExecForUac;				// Whether the process was re-run for UAC handling
202 	SW_COMPONENT *CurrentComponent;		// Component that is currently selected
203 	bool EulaAgreed;					// Whether the user accepted the license agreement
204 	bool DoubleClickBlocker;			// Double-click blocker
205 	bool LanguageMode;					// Language setting mode
206 	UINT LangId;						// Language ID in the language setting mode
207 	bool SetLangAndReboot;				// Prompt to restart after making the language setting
208 	bool LangNow;						// Start the language setting process right now
209 	bool EasyMode;						// Simple installer creation mode
210 	bool WebMode;						// Web installer creation mode
211 	bool OnlyAutoSettingMode;			// Apply only mode of connection settings of VPN Client
212 
213 	INSTANCE *Single;					// Multiple-starts check
214 	wchar_t DefaultInstallDir_System[MAX_PATH];		// Default system installation directory
215 	wchar_t DefaultInstallDir_User[MAX_PATH];		// Default user installation directory
216 	bool IsAvailableSystemMode;			// Whether the system mode is selectable
217 	bool IsAvailableUserMode;			// Whether the user mode is selectable
218 	bool ShowWarningForUserMode;		// Whether to display a warning for the user-mode
219 	wchar_t InstallDir[MAX_PATH];		// Destination directory
220 	THREAD *PerformThread;				// Set up processing thread
221 	bool Run;							// Whether to start the tool after Setup finishes
222 	SW_LOGFILE *LogFile;				// Log file
223 	bool MsiRebootRequired;				// Need to be re-started as a result of MSI
224 	bool LangNotChanged;				// Language has not changed
225 	wchar_t FinishMsg[MAX_SIZE * 2];	// Completion message
226 	wchar_t Easy_SettingFile[MAX_PATH];	// Connection settings file name of the Simple installer creation kit:
227 	wchar_t Easy_OutFile[MAX_PATH];		// Destination file name of the simple installer creation kit
228 	bool Easy_EraseSensitive;			// Simple installer creation kit: Delete the confidential information
229 	bool Easy_EasyMode;					// Simple installer creation kit: simple mode
230 	wchar_t Web_SettingFile[MAX_PATH];	// Connection setting file name for the Web installer creation Kit
231 	wchar_t Web_OutFile[MAX_PATH];		// Destination file name of the Web installer creation Kit
232 	bool Web_EraseSensitive;			// Web installer creation Kit: removing confidential information
233 	bool Web_EasyMode;					// Web installer creation kit: simple mode
234 	wchar_t vpncmgr_path[MAX_PATH];		// Path of vpncmgr.exe
235 	wchar_t auto_setting_path[MAX_PATH];	// Path of automatic connection setting
236 	bool HideStartCommand;				// Not to show the option to start the program on installation complete screen
237 	char SfxMode[MAX_SIZE];				// SFX generation mode
238 	wchar_t SfxOut[MAX_PATH];			// SFX destination
239 	wchar_t CallerSfxPath[MAX_PATH];	// Calling SFX path
240 	bool IsEasyInstaller;				// Whether the calling SFX was built by the simple installer creation kit
241 	bool IsWebInstaller;				// Whether Web installer
242 	bool DisableAutoImport;				// Not to use the automatic import process
243 	bool SuInstMode;					// SuInst mode
244 	UINT CurrentEulaHash;				// Hash of the license agreement
245 } SW;
246 
247 
248 // Function prototype
249 SW *NewSw();
250 UINT FreeSw(SW *sw);
251 
252 void SwDefineComponents(SW *sw);
253 SW_COMPONENT *SwNewComponent(char *name, char *svc_name, UINT id, UINT icon, UINT icon_index, wchar_t *svc_filename,
254 							 wchar_t *long_name, bool system_mode_only, UINT num_files, char *files[],
255 							 wchar_t *start_exe_name, wchar_t *start_description,
256 							 SW_OLD_MSI *old_msis, UINT num_old_msis);
257 void SwFreeComponent(SW_COMPONENT *c);
258 void SwDetectComponents(SW *sw);
259 bool SwIsComponentDetected(SW *sw, SW_COMPONENT *c);
260 void SwParseCommandLine(SW *sw);
261 SW_COMPONENT *SwFindComponent(SW *sw, char *name);
262 
263 void SwInitDefaultInstallDir(SW *sw);
264 void SwUiMain(SW *sw);
265 bool SwCheckNewDirName(wchar_t *name);
266 wchar_t *SwGetOldMsiInstalledDir(SW_COMPONENT *c);
267 bool SwUninstallOldMsiInstalled(HWND hWnd, WIZARD_PAGE *wp, SW_COMPONENT *c, bool *reboot_required);
268 
269 bool SwReExecMyself(SW *sw, wchar_t *additional_params, bool as_admin);
270 
271 SW_TASK *SwNewTask();
272 void SwFreeTask(SW_TASK *t);
273 SW_TASK_COPY *SwNewCopyTask(wchar_t *srcfilename, wchar_t *dstfilename, wchar_t *srcdir, wchar_t *dstdir, bool overwrite, bool setup_file);
274 void SwFreeCopyTask(SW_TASK_COPY *ct);
275 void SwDefineTasks(SW *sw, SW_TASK *t, SW_COMPONENT *c);
276 SW_TASK_LINK *SwNewLinkTask(wchar_t *target_dir, wchar_t *target_exe, wchar_t *target_arg,
277 							wchar_t *icon_exe, UINT icon_index,
278 							wchar_t *dest_dir, wchar_t *dest_name, wchar_t *dest_desc,
279 							bool no_delete_dir);
280 void SwFreeLinkTask(SW_TASK_LINK *lt);
281 
282 void SwAddLog(SW *sw, SW_LOGFILE *logfile, UINT type, wchar_t *path);
283 void SwAddLogA(SW *sw, SW_LOGFILE *logfile, UINT type, char *path);
284 bool SwSaveLogFile(SW *sw, wchar_t *dst_name, SW_LOGFILE *logfile);
285 SW_LOGFILE *SwLoadLogFile(SW *sw, wchar_t *filename);
286 SW_LOGFILE *SwNewLogFile();
287 void SwFreeLogFile(SW_LOGFILE *logfile);
288 
289 void SwInstallShortcuts(SW *sw, WIZARD_PAGE *wp, SW_COMPONENT *c, SW_TASK *t);
290 void SwDeleteShortcuts(SW_LOGFILE *logfile);
291 
292 bool SwEnterSingle(SW *sw);
293 void SwLeaveSingle(SW *sw);
294 
295 UINT SwWelcomeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
296 UINT SwModeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
297 UINT SwNotAdminDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
298 UINT SwComponents(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
299 void SwComponentsInit(HWND hWnd, SW *sw);
300 void SwComponentsUpdate(HWND hWnd, SW *sw, WIZARD *wizard, WIZARD_PAGE *wizard_page);
301 UINT SwEula(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
302 void SwEulaUpdate(HWND hWnd, SW *sw, WIZARD *wizard, WIZARD_PAGE *wizard_page);
303 UINT SwDir(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
304 void SwDirUpdate(HWND hWnd, SW *sw, WIZARD_PAGE *wizard_page);
305 UINT SwReady(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
306 UINT SwPerform(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
307 void SwPerformInit(HWND hWnd, SW *sw, WIZARD_PAGE *wp);
308 void SwPerformThread(THREAD *thread, void *param);
309 void SwPerformPrint(WIZARD_PAGE *wp, wchar_t *str);
310 UINT SwPerformMsgBox(WIZARD_PAGE *wp, UINT flags, wchar_t *msg);
311 UINT SwInteractUi(WIZARD_PAGE *wp, SW_UI *ui);
312 void SwInteractUiCalled(HWND hWnd, SW *sw, WIZARD_PAGE *wp, SW_UI *ui);
313 bool SwInstallMain(SW *sw, WIZARD_PAGE *wp, SW_COMPONENT *c);
314 UINT SwError(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
315 UINT SwFinish(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
316 UINT SwUninst1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
317 bool SwUninstallMain(SW *sw, WIZARD_PAGE *wp, SW_COMPONENT *c);
318 UINT SwLang1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
319 void SwLang1Init(HWND hWnd, SW *sw);
320 UINT SwGetLangIcon(char *name);
321 void SwLang1Update(HWND hWnd, SW *sw, WIZARD *wizard, WIZARD_PAGE *wizard_page);
322 UINT SwEasy1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
323 UINT SwEasy2(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
324 void SwEasy2Update(HWND hWnd, SW *sw, WIZARD *wizard, WIZARD_PAGE *wizard_page);
325 bool SwEasyMain(SW *sw, WIZARD_PAGE *wp);
326 UINT SwWeb1(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
327 UINT SwWeb2(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, WIZARD *wizard, WIZARD_PAGE *wizard_page, void *param);
328 void SwWeb2Update(HWND hWnd, SW *sw, WIZARD *wizard, WIZARD_PAGE *wizard_page);
329 bool SwWebMain(SW *sw, WIZARD_PAGE *wp);
330 
331 
332 void SwGenerateDefaultSfxFileName(wchar_t *name, UINT size);
333 void SwGenerateDefaultZipFileName(wchar_t *name, UINT size);
334 
335 bool CALLBACK SwEnumResourceNamesProc(HMODULE hModule, const char *type, char *name, LONG_PTR lParam);
336 
337 UINT SwSfxModeMain();
338 bool CALLBACK SfxModeMainDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
339 bool SwSfxExtractProcess(HWND hWnd, bool *hide_error_msg);
340 bool SwSfxExtractFile(HWND hWnd, void *data, UINT size, wchar_t *dst, bool compressed);
341 SW_SFX_FILE *SwNewSfxFile(char *inner_file_name, wchar_t *disk_file_name);
342 bool SwSfxCopyVgFiles(HWND hWnd, wchar_t *src, wchar_t *dst);
343 
344 #endif	// SW_INNER_H
345 
346 
347