|
|
1.1 root 1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org
2: This product uses components written by Paul Le Roux <[email protected]> */
3:
4: #include "TCdefs.h"
5: #include <SrRestorePtApi.h>
6:
7: #define MAX_PASSWORD
8:
9: #include "apidrvr.h"
10: #include "dlgcode.h"
11: #include "dismount.h"
12: #include "../common/resource.h"
13:
14: #include "resource.h"
15:
16: #include "dir.h"
17: #include "setup.h"
18:
19: #include <sys\types.h>
20: #include <sys\stat.h>
21:
22: #pragma warning( disable : 4201 )
23: #pragma warning( disable : 4115 )
24:
25: #include <shlobj.h>
26:
27: #pragma warning( default : 4201 )
28: #pragma warning( default : 4115 )
29:
30: char dlg_file_name[TC_MAX_PATH];
31: BOOL bUninstall = FALSE;
32: BOOL bDone = FALSE;
33:
34: HMODULE SystemRestoreDll = 0;
35:
36: BOOL
37: StatDeleteFile (char *lpszFile)
38: {
39: struct __stat64 st;
40:
41: if (_stat64 (lpszFile, &st) == 0)
42: return DeleteFile (lpszFile);
43: else
44: return TRUE;
45: }
46:
47: BOOL
48: StatRemoveDirectory (char *lpszDir)
49: {
50: struct __stat64 st;
51:
52: if (_stat64 (lpszDir, &st) == 0)
53: return RemoveDirectory (lpszDir);
54: else
55: return TRUE;
56: }
57:
58: HRESULT
59: CreateLink (char *lpszPathObj, char *lpszArguments,
60: char *lpszPathLink)
61: {
62: HRESULT hres;
63: IShellLink *psl;
64:
65: /* Get a pointer to the IShellLink interface. */
66: hres = CoCreateInstance (&CLSID_ShellLink, NULL,
67: CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
68: if (SUCCEEDED (hres))
69: {
70: IPersistFile *ppf;
71:
72: /* Set the path to the shortcut target, and add the
73: description. */
74: psl->lpVtbl->SetPath (psl, lpszPathObj);
75: psl->lpVtbl->SetArguments (psl, lpszArguments);
76:
77: /* Query IShellLink for the IPersistFile interface for saving
78: the shortcut in persistent storage. */
79: hres = psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
80: &ppf);
81:
82: if (SUCCEEDED (hres))
83: {
84: WORD wsz[TC_MAX_PATH];
85:
86: /* Ensure that the string is ANSI. */
87: MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1,
88: wsz, TC_MAX_PATH);
89:
90: /* Save the link by calling IPersistFile::Save. */
91: hres = ppf->lpVtbl->Save (ppf, wsz, TRUE);
92: ppf->lpVtbl->Release (ppf);
93: }
94: psl->lpVtbl->Release (psl);
95: }
96: return hres;
97: }
98:
99: void
100: GetProgramPath (HWND hwndDlg, char *path)
101: {
102: ITEMIDLIST *i;
103: HRESULT res;
104:
105: if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
106: res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
107: else
108: res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
109:
110: SHGetPathFromIDList (i, path);
111: }
112:
113:
114: void
115: StatusMessage (HWND hwndDlg, char *head, char *txt)
116: {
117: char szTmp[TC_MAX_PATH];
118: sprintf (szTmp, head, txt);
119: SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) szTmp);
120:
121: SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX,
122: SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0);
123: }
124:
125: void
126: RegMessage (HWND hwndDlg, char *txt)
127: {
128: StatusMessage (hwndDlg, "Adding registry entry %s", txt);
129: }
130:
131: void
132: CopyMessage (HWND hwndDlg, char *txt)
133: {
134: StatusMessage (hwndDlg, "Copying %s", txt);
135: }
136:
137: void
138: RemoveMessage (HWND hwndDlg, char *txt)
139: {
140: StatusMessage (hwndDlg, "Removing %s", txt);
141: }
142:
143: void
144: ServiceMessage (HWND hwndDlg, char *txt)
145: {
146: StatusMessage (hwndDlg, "Service %s", txt);
147: }
148:
149: void
150: IconMessage (HWND hwndDlg, char *txt)
151: {
152: StatusMessage (hwndDlg, "Adding icon %s", txt);
153: }
154:
155: int CALLBACK
156: BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData)
157: {
158: switch(uMsg) {
159: case BFFM_INITIALIZED:
160: {
161: /* WParam is TRUE since we are passing a path.
162: It would be FALSE if we were passing a pidl. */
163: SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData);
164: break;
165: }
166:
167: case BFFM_SELCHANGED:
168: {
169: char szDir[TC_MAX_PATH];
170:
171: /* Set the status window to the currently selected path. */
172: if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
173: {
174: SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
175: }
176: break;
177: }
178:
179: default:
180: break;
181: }
182:
183: return 0;
184: }
185:
186: BOOL
187: BrowseFiles2 (HWND hwndDlg, char* lpszTitle, char* lpszFileName)
188: {
189: BROWSEINFO bi;
190: LPITEMIDLIST pidl;
191: LPMALLOC pMalloc;
192: BOOL bOK = FALSE;
193:
194: if (SUCCEEDED(SHGetMalloc(&pMalloc)))
195: {
196: ZeroMemory(&bi,sizeof(bi));
197: bi.hwndOwner = hwndDlg;
198: bi.pszDisplayName = 0;
199: bi.lpszTitle = lpszTitle;
200: bi.pidlRoot = 0;
201: bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT /*| BIF_EDITBOX*/;
202: bi.lpfn = BrowseCallbackProc;
203: bi.lParam = (LPARAM)lpszFileName;
204:
205: pidl = SHBrowseForFolder(&bi);
206: if (pidl!=NULL)
207: {
208: if (SHGetPathFromIDList(pidl,lpszFileName)==TRUE)
209: {
210: bOK = TRUE;
211: }
212:
213: pMalloc->lpVtbl->Free(pMalloc,pidl);
214: pMalloc->lpVtbl->Release(pMalloc);
215: }
216: }
217:
218: return bOK;
219: }
220:
221:
222: void
223: LoadLicense (HWND hwndDlg)
224: {
225: FILE *fp;
226:
227: fp = fopen ("Setup Files\\license.txt", "rb");
228:
229: if (fp == NULL)
230: return;
231: else
232: {
233: long x;
234:
235: fseek (fp, 0, SEEK_END);
236: x = ftell (fp);
237: rewind (fp);
238:
239: if (x > 0)
240: {
241: char *tmp = malloc (x + 1);
242: long z;
243:
244: if (tmp == NULL)
245: goto exit;
246: z = (long) fread (tmp, 1, x, fp);
247: if (z != x)
248: {
249: free (tmp);
250: goto exit;
251: }
252: else
253: {
254: int i;
255: tmp[x] = 0;
256:
257: //// Remove single CRLFs
258: //for (i = 0; i < x - 3; i++)
259: //{
260: // if (tmp[i] == 0xd && tmp[i+2] == 0xd)
261: // i += 4;
262:
263: // if (tmp[i] == 0xd && tmp[i+2] != 0xd)
264: // {
265: // tmp[i] = tmp[i+1] = ' ';
266: // }
267: //}
268:
269: SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE), WM_SETFONT, (WPARAM) hFixedFont, (LPARAM) 0);
270: SetWindowText (GetDlgItem (hwndDlg, IDC_LICENSE), tmp);
271:
272: free (tmp);
273: }
274: }
275: }
276:
277: exit:
278: fclose (fp);
279: }
280:
281: BOOL
282: DoFilesInstall (HWND hwndDlg, char *szDestDir, BOOL bUninstallSupport)
283: {
284:
285:
286: char *szFiles[]=
287: {
288: "ATrueCrypt.exe", "ATrueCrypt Format.exe",
289: "Alicense.txt", "ATrueCrypt User Guide.pdf",
290: "WTrueCrypt Setup.exe", "STrueCryptService.exe", "Dtruecrypt.sys",
291: };
292:
293: char szTmp[TC_MAX_PATH];
294: BOOL bOK = TRUE;
295: int i;
296:
297: if (bUninstall == TRUE)
298: bUninstallSupport = FALSE;
299:
300: for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
301: {
302: BOOL bResult, bSlash;
303: char szDir[TC_MAX_PATH];
304: int x;
305:
306: if (bUninstallSupport == FALSE && strstr (szFiles[i], "TrueCrypt Setup") != 0)
307: continue;
308:
309: if (*szFiles[i] == 'A')
310: strcpy (szDir, szDestDir);
311: else if (*szFiles[i] == 'S')
312: GetSystemDirectory (szDir, sizeof (szDir));
313: else if (*szFiles[i] == 'I')
314: {
315: GetSystemDirectory (szDir, sizeof (szDir));
316:
317: x = strlen (szDestDir);
318: if (szDestDir[x - 1] == '\\')
319: bSlash = TRUE;
320: else
321: bSlash = FALSE;
322:
323: if (bSlash == FALSE)
324: strcat (szDir, "\\");
325:
326: strcat (szDir, "IOSUBSYS");
327: }
328: else if (*szFiles[i] == 'D')
329: {
330: GetSystemDirectory (szDir, sizeof (szDir));
331:
332: x = strlen (szDestDir);
333: if (szDestDir[x - 1] == '\\')
334: bSlash = TRUE;
335: else
336: bSlash = FALSE;
337:
338: if (bSlash == FALSE)
339: strcat (szDir, "\\");
340:
341: strcat (szDir, "Drivers");
342: }
343: else if (*szFiles[i] == 'W')
344: GetWindowsDirectory (szDir, sizeof (szDir));
345:
346: x = strlen (szDestDir);
347: if (szDestDir[x - 1] == '\\')
348: bSlash = TRUE;
349: else
350: bSlash = FALSE;
351:
352: if (bSlash == FALSE)
353: strcat (szDir, "\\");
354:
355: if ((*szFiles[i] == 'D' || *szFiles[i] == 'S') && nCurrentOS != WIN_NT)
356: continue;
357:
358: if (*szFiles[i] == 'I' && nCurrentOS == WIN_NT)
359: continue;
360:
361: sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);
362:
363: if (bUninstall == FALSE)
364: CopyMessage (hwndDlg, szTmp);
365: else
366: RemoveMessage (hwndDlg, szTmp);
367:
368: if (bUninstall == FALSE)
369: {
370: bResult = CopyFile (szFiles[i] + 1, szTmp, FALSE);
371: if (!bResult)
372: {
373: char s[256];
374: sprintf (s, "Setup Files\\%s", szFiles[i] + 1);
375: bResult = CopyFile (s, szTmp, FALSE);
376: }
377: }
378: else
379: {
380: bResult = StatDeleteFile (szTmp);
381: }
382:
383: if (bResult == FALSE)
384: {
385: LPVOID lpMsgBuf;
386: DWORD dwError = GetLastError ();
387: char szTmp2[700];
388:
389: FormatMessage (
390: FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
391: NULL,
392: dwError,
393: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
394: (char *) &lpMsgBuf,
395: 0,
396: NULL
397: );
398:
399:
400: if (bUninstall == FALSE)
401: sprintf (szTmp2, "The installation of '%s' has failed. %s Do you want to continue with the Install?",
402: szTmp, lpMsgBuf);
403: else
404: sprintf (szTmp2, "The uninstallation of '%s' has failed. %s Do you want to continue with the Uninstall?",
405: szTmp, lpMsgBuf);
406:
407: LocalFree (lpMsgBuf);
408:
409: if (MessageBox (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
410: return FALSE;
411: }
412:
413: }
414:
415: return bOK;
416: }
417:
418: BOOL
419: DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType, BOOL bUninstallSupport)
420: {
421: char szDir[TC_MAX_PATH], *key;
422: HKEY hkey = 0;
423: BOOL bSlash, bOK = FALSE;
424: DWORD dw;
425: int x;
426:
427: strcpy (szDir, szDestDir);
428: x = strlen (szDestDir);
429: if (szDestDir[x - 1] == '\\')
430: bSlash = TRUE;
431: else
432: bSlash = FALSE;
433:
434: if (bSlash == FALSE)
435: strcat (szDir, "\\");
436:
437: if (nCurrentOS == WIN_NT)
438: {
439: /* 9/9/99 FIX This code should no longer be needed as we use
440: the "services" api to install the driver now, rather than
441: setting the registry by hand */
442:
443: /* Install device driver */
444: key = "SYSTEM\\CurrentControlSet\\Services\\truecrypt";
445: RegMessage (hwndDlg, key);
446: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
447: key,
448: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
449: goto error;
450:
451: dw = 1;
452: if (RegSetValueEx (hkey, "Type", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
453: goto error;
454:
455: dw = 1;
456: if (RegSetValueEx (hkey, "Start", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
457: goto error;
458:
459: dw = 1;
460: if (RegSetValueEx (hkey, "ErrorControl", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
461: goto error;
462:
463: if (RegSetValueEx (hkey, "Group", 0, REG_SZ, (BYTE *) "Primary disk", 13) != ERROR_SUCCESS)
464: goto error;
465:
466: RegCloseKey (hkey);
467: hkey = 0;
468: }
469:
470: if (bInstallType == TRUE)
471: {
472: char szTmp[TC_MAX_PATH];
473:
474: key = "SOFTWARE\\Classes\\TrueCryptVolume";
475: RegMessage (hwndDlg, key);
476: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
477: key,
478: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
479: goto error;
480:
481: sprintf (szTmp, "TrueCrypt Volume", szDir);
482: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
483: goto error;
484:
485: RegCloseKey (hkey);
486: hkey = 0;
487:
488: key = "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon";
489: RegMessage (hwndDlg, key);
490: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
491: key,
492: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
493: goto error;
494:
495: sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
496: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
497: goto error;
498:
499: RegCloseKey (hkey);
500: hkey = 0;
501:
502: key = "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command";
503: RegMessage (hwndDlg, key);
504: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
505: key,
506: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
507: goto error;
508:
509: sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
510: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
511: goto error;
512:
513: RegCloseKey (hkey);
514: hkey = 0;
515:
516: key = "SOFTWARE\\Classes\\.tc";
517: RegMessage (hwndDlg, key);
518: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
519: key,
520: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
521: goto error;
522:
523: strcpy (szTmp, "TrueCryptVolume");
524: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
525: goto error;
526: }
527:
528:
529: if (bUninstallSupport == TRUE)
530: {
531: char szTmp[TC_MAX_PATH];
532:
533: key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
534: RegMessage (hwndDlg, key);
535: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
536: key,
537: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
538: goto error;
539:
540: GetWindowsDirectory (szDir, sizeof (szDir));
541:
542: x = strlen (szDir);
543: if (szDir[x - 1] == '\\')
544: bSlash = TRUE;
545: else
546: bSlash = FALSE;
547:
548: if (bSlash == FALSE)
549: strcat (szDir, "\\");
550:
551: sprintf (szTmp, "%sTrueCrypt Setup.exe /u", szDir);
552: if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
553: goto error;
554:
555: strcpy (szTmp, "TrueCrypt");
556: if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
557: goto error;
558: }
559:
560: bOK = TRUE;
561:
562: error:
563: if (hkey != 0)
564: RegCloseKey (hkey);
565:
566: if (bOK == FALSE)
567: {
568: handleWin32Error (hwndDlg);
569: MessageBox (hwndDlg, "The installation of the registry entries has failed", lpszTitle, MB_ICONHAND);
570: }
571:
572: return bOK;
573: }
574:
575: BOOL
576: DoRegUninstall (HWND hwndDlg)
577: {
578: BOOL bOK = FALSE;
579:
580: StatusMessage (hwndDlg, "%s", "Removing registry entries");
581:
582: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
583: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command");
584: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open");
585: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell");
586: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon");
587: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume");
588: RegDeleteKey (HKEY_CURRENT_USER, "SOFTWARE\\TrueCrypt");
589: if (RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\.tc") != ERROR_SUCCESS)
590: goto error;
591:
592: bOK = TRUE;
593:
594: error:
595:
596: if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
597: && GetLastError ()!= ERROR_PATH_NOT_FOUND)
598: {
599: handleWin32Error (hwndDlg);
600: MessageBox (hwndDlg, "The uninstallation of the registry entries has failed", lpszTitle, MB_ICONHAND);
601: }
602: else
603: bOK = TRUE;
604:
605: return bOK;
606:
607: }
608:
609: BOOL
610: DoServiceUninstall (HWND hwndDlg, char *lpszService)
611: {
612: SC_HANDLE hManager, hService = NULL;
613: BOOL bOK = FALSE, bRet;
614: SERVICE_STATUS status;
615: char szTmp[128];
616: int x;
617:
618: if (nCurrentOS != WIN_NT)
619: return TRUE;
620: else
621: memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */
622:
623: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
624: if (hManager == NULL)
625: goto error;
626:
627: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
628: if (hService == NULL)
629: goto error;
630:
631: sprintf (szTmp, "stopping %s", lpszService);
632: ServiceMessage (hwndDlg, szTmp);
633:
634: #define WAIT_PERIOD 3
635:
636: for (x = 0; x < WAIT_PERIOD; x++)
637: {
638: bRet = QueryServiceStatus (hService, &status);
639: if (bRet != TRUE)
640: goto error;
641:
642: if (status.dwCurrentState != SERVICE_START_PENDING &&
643: status.dwCurrentState != SERVICE_STOP_PENDING &&
644: status.dwCurrentState != SERVICE_CONTINUE_PENDING)
645: break;
646:
647: Sleep (1000);
648: }
649:
650: if (status.dwCurrentState != SERVICE_STOPPED)
651: {
652: bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
653: if (bRet == FALSE)
654: goto try_delete;
655:
656: for (x = 0; x < WAIT_PERIOD; x++)
657: {
658: bRet = QueryServiceStatus (hService, &status);
659: if (bRet != TRUE)
660: goto error;
661:
662: if (status.dwCurrentState != SERVICE_START_PENDING &&
663: status.dwCurrentState != SERVICE_STOP_PENDING &&
664: status.dwCurrentState != SERVICE_CONTINUE_PENDING)
665: break;
666:
667: Sleep (1000);
668: }
669:
670: if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
671: goto error;
672: }
673:
674: try_delete:
675: sprintf (szTmp, "deleting %s", lpszService);
676: ServiceMessage (hwndDlg, szTmp);
677:
678: if (hService != NULL)
679: CloseServiceHandle (hService);
680:
681: if (hManager != NULL)
682: CloseServiceHandle (hManager);
683:
684: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
685: if (hManager == NULL)
686: goto error;
687:
688: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
689: if (hService == NULL)
690: goto error;
691:
692: bRet = DeleteService (hService);
693: if (bRet == FALSE)
694: goto error;
695:
696: bOK = TRUE;
697:
698: error:
699: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
700: {
701: handleWin32Error (hwndDlg);
702: MessageBox (hwndDlg, "The uninstallation of the device driver has failed", lpszTitle, MB_ICONHAND);
703: }
704: else
705: bOK = TRUE;
706:
707: if (hService != NULL)
708: CloseServiceHandle (hService);
709:
710: if (hManager != NULL)
711: CloseServiceHandle (hManager);
712:
713: return bOK;
714: }
715:
716: BOOL
717: DoDriverUnload (HWND hwndDlg)
718: {
719: BOOL bOK = TRUE;
720: int status;
721:
722: status = DriverAttach ();
723: if (status != 0)
724: {
725: if (status == ERR_OS_ERROR && GetLastError ()!= ERROR_FILE_NOT_FOUND)
726: {
727: handleWin32Error (hwndDlg);
728: AbortProcess (IDS_NODRIVER);
729: }
730:
731: if (status != ERR_OS_ERROR)
732: {
733: handleError (NULL, status);
734: AbortProcess (IDS_NODRIVER);
735: }
736: }
737:
738: if (hDriver != INVALID_HANDLE_VALUE)
739: {
740: DWORD dwError;
741: int x;
742:
743:
744: if (nCurrentOS == WIN_NT)
745: {
746: ServiceMessage (hwndDlg, "dismounting any mounted volumes");
747:
748: if (UnmountAllVolumes (hwndDlg, &dwError, &x) == FALSE)
749: {
750: bOK = FALSE;
751: MessageBox (hwndDlg, "Volumes are still mounted; all volumes must be dismounted before uninstallation can continue", lpszTitle, MB_ICONHAND);
752: }
753: }
754: else
755: {
756:
757: MOUNT_LIST_STRUCT driver;
758: DWORD dwResult;
759: BOOL bResult;
760:
761: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver,
762: sizeof (driver), &dwResult, NULL);
763:
764: if (bResult == TRUE)
765: {
766: if (driver.ulMountedDrives != 0)
767: {
768: bOK = FALSE;
769: MessageBox (hwndDlg, "Volumes are still mounted; all volumes must be dismounted before uninstallation can continue", lpszTitle, MB_ICONHAND);
770: }
771: }
772: else
773: {
774: bOK = FALSE;
775: handleWin32Error (hwndDlg);
776: }
777: }
778:
779: CloseHandle (hDriver);
780: hDriver = INVALID_HANDLE_VALUE;
781:
782: }
783:
784: return bOK;
785: }
786:
787: BOOL
788: DoServiceInstall (HWND hwndDlg)
789: {
790: BOOL bOK = FALSE;
791:
792: if (nCurrentOS != WIN_NT)
793: return TRUE;
794:
795: ServiceMessage (hwndDlg, "installing TrueCryptService");
796: ServiceMessage (hwndDlg, "starting TrueCryptService");
797:
798: if (CheckService ()== FALSE)
799: goto error;
800:
801: bOK = TRUE;
802:
803: error:
804: if (bOK == FALSE)
805: {
806: MessageBox ((HWND) hwndDlg, "The installation of the service has failed", lpszTitle, MB_ICONHAND);
807: }
808:
809: return bOK;
810: }
811:
812: BOOL
813: DoDriverInstall (HWND hwndDlg)
814: {
815: SC_HANDLE hManager, hService = NULL;
816: BOOL bOK = FALSE, bRet, bSlash;
817: char szDir[TC_MAX_PATH];
818: int x;
819:
820: if (nCurrentOS != WIN_NT)
821: return TRUE;
822:
823: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
824: if (hManager == NULL)
825: goto error;
826:
827: GetSystemDirectory (szDir, sizeof (szDir));
828:
829: x = strlen (szDir);
830: if (szDir[x - 1] == '\\')
831: bSlash = TRUE;
832: else
833: bSlash = FALSE;
834:
835: if (bSlash == FALSE)
836: strcat (szDir, "\\");
837:
838: strcat (szDir, "Drivers\\truecrypt.sys");
839:
840: ServiceMessage (hwndDlg, "installing TrueCrypt driver service");
841:
842: hService = CreateService (hManager, "truecrypt", "truecrypt",
843: SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
844: szDir, NULL, NULL, NULL, NULL, NULL
845: );
846: if (hService == NULL)
847: goto error;
848: else
849: CloseServiceHandle (hService);
850:
851: hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
852: if (hService == NULL)
853: goto error;
854:
855: ServiceMessage (hwndDlg, "starting TrueCrypt driver service");
856:
857: bRet = StartService (hService, 0, NULL);
858: if (bRet == FALSE)
859: goto error;
860:
861: bOK = TRUE;
862:
863: error:
864: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_ALREADY_RUNNING)
865: {
866: handleWin32Error (hwndDlg);
867: MessageBox (hwndDlg, "The installation of the device driver has failed", lpszTitle, MB_ICONHAND);
868: }
869: else
870: bOK = TRUE;
871:
872: if (hService != NULL)
873: CloseServiceHandle (hService);
874:
875: if (hManager != NULL)
876: CloseServiceHandle (hManager);
877:
878: return bOK;
879: }
880:
881: BOOL
882: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
883: {
884: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
885: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
886: BOOL bSlash, bOK = FALSE;
887: HRESULT hOle;
888: int x;
889: BOOL allUsers = FALSE;
890:
891: hOle = OleInitialize (NULL);
892:
893: // User start menu
894: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
895: x = strlen (szLinkDir);
896: if (szLinkDir[x - 1] == '\\')
897: bSlash = TRUE;
898: else
899: bSlash = FALSE;
900:
901: if (bSlash == FALSE)
902: strcat (szLinkDir, "\\");
903:
904: strcat (szLinkDir, "TrueCrypt");
905:
906: // Global start menu
907: if (nCurrentOS == WIN_NT)
908: {
909: struct _stat st;
910: char path[TC_MAX_PATH];
911:
912: SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
913: strcat (path, "\\TrueCrypt");
914:
915: if (_stat (path, &st) == 0)
916: {
917: strcpy (szLinkDir, path);
918: allUsers = TRUE;
919: }
920: }
921:
922: // Start menu entries
923: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
924: RemoveMessage (hwndDlg, szTmp2);
925: if (StatDeleteFile (szTmp2) == FALSE)
926: goto error;
927:
928: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
929: RemoveMessage (hwndDlg, szTmp2);
930: if (StatDeleteFile (szTmp2) == FALSE)
931: goto error;
932:
933: GetWindowsDirectory (szDir, sizeof (szDir));
934: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
935: RemoveMessage (hwndDlg, szTmp2);
936: if (StatDeleteFile (szTmp2) == FALSE)
937: goto error;
938:
939: // Start menu group
940: RemoveMessage ((HWND) hwndDlg, szLinkDir);
941: if (StatRemoveDirectory (szLinkDir) == FALSE)
942: {
943: handleWin32Error ((HWND) hwndDlg);
944: goto error;
945: }
946:
947: // Desktop icon
948:
949: if (allUsers)
950: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
951: else
952: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
953:
954: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
955:
956: RemoveMessage (hwndDlg, szTmp2);
957: if (StatDeleteFile (szTmp2) == FALSE)
958: goto error;
959:
960: bOK = TRUE;
961:
962: error:
963: OleUninitialize ();
964:
965: return bOK;
966: }
967:
968: BOOL
969: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
970: {
971: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
972: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
973: BOOL bSlash, bOK = FALSE;
974: HRESULT hOle;
975: int x;
976:
977: if (bProgGroup == FALSE && bDesktopIcon == FALSE)
978: return TRUE;
979:
980: hOle = OleInitialize (NULL);
981:
982: GetProgramPath (hwndDlg, szLinkDir);
983:
984: x = strlen (szLinkDir);
985: if (szLinkDir[x - 1] == '\\')
986: bSlash = TRUE;
987: else
988: bSlash = FALSE;
989:
990: if (bSlash == FALSE)
991: strcat (szLinkDir, "\\");
992:
993: strcat (szLinkDir, "TrueCrypt");
994:
995: strcpy (szDir, szDestDir);
996: x = strlen (szDestDir);
997: if (szDestDir[x - 1] == '\\')
998: bSlash = TRUE;
999: else
1000: bSlash = FALSE;
1001:
1002: if (bSlash == FALSE)
1003: strcat (szDir, "\\");
1004:
1005: if (bProgGroup)
1006: {
1007: if (mkfulldir (szLinkDir, TRUE) != 0)
1008: {
1009: char szTmp[TC_MAX_PATH];
1010: int x;
1011:
1012: //sprintf (szTmp, "The program folder '%s' does not exist. Do you want to create this folder?", szLinkDir);
1013: //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
1014: //if (x == IDNO)
1015: //{
1016: // goto error;
1017: //}
1018:
1019: if (mkfulldir (szLinkDir, FALSE) != 0)
1020: {
1021: handleWin32Error (hwndDlg);
1022: sprintf (szTmp, "The folder '%s' could not be created", szLinkDir);
1023: MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1024: goto error;
1025: }
1026: }
1027:
1028: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1029: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1030:
1031: IconMessage (hwndDlg, szTmp2);
1032: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1033: goto error;
1034:
1035:
1036: sprintf (szTmp, "%s%s", szDir, "TrueCrypt User Guide.pdf");
1037: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
1038:
1039: IconMessage (hwndDlg, szTmp2);
1040: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1041: goto error;
1042:
1043: GetWindowsDirectory (szDir, sizeof (szDir));
1044: x = strlen (szDir);
1045: if (szDir[x - 1] == '\\')
1046: bSlash = TRUE;
1047: else
1048: bSlash = FALSE;
1049:
1050: if (bSlash == FALSE)
1051: strcat (szDir, "\\");
1052:
1053: sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
1054: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1055:
1056: IconMessage (hwndDlg, szTmp2);
1057: if (CreateLink (szTmp, "/u", szTmp2) != S_OK)
1058: goto error;
1059:
1060: }
1061:
1062: if (bDesktopIcon)
1063: {
1064: strcpy (szDir, szDestDir);
1065: x = strlen (szDestDir);
1066: if (szDestDir[x - 1] == '\\')
1067: bSlash = TRUE;
1068: else
1069: bSlash = FALSE;
1070:
1071: if (bSlash == FALSE)
1072: strcat (szDir, "\\");
1073:
1074: if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
1075: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
1076: else
1077: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
1078:
1079: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1080: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1081:
1082: IconMessage (hwndDlg, szTmp2);
1083:
1084: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1085: goto error;
1086: }
1087:
1088: bOK = TRUE;
1089:
1090: error:
1091: OleUninitialize ();
1092:
1093: return bOK;
1094: }
1095:
1096:
1097: void
1098: RebootPrompt (HWND hwndDlg, BOOL bOK)
1099: {
1100: if (bOK == TRUE)
1101: {
1102: SetWindowText (GetDlgItem ((HWND) hwndDlg, IDOK), "E&xit");
1103:
1104: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
1105:
1106: bDone = TRUE;
1107:
1108: if (nCurrentOS == WIN_NT)
1109: {
1110: if (bUninstall == FALSE)
1111: MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.", lpszTitle, MB_ICONINFORMATION);
1112: else
1113: MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.", lpszTitle, MB_ICONINFORMATION);
1114: }
1115: else
1116: {
1117: int x;
1118:
1119: if (bUninstall == FALSE)
1120: x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.\nTo use TrueCrypt your system must be restarted.", lpszTitle, MB_ICONINFORMATION);
1121: else
1122: x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.\nYour system must be restarted.", lpszTitle, MB_ICONINFORMATION);
1123: }
1124: }
1125: else
1126: {
1127: if (bUninstall == FALSE)
1128: MessageBox ((HWND) hwndDlg, "The installation has failed!", lpszTitle, MB_ICONHAND);
1129: else
1130: MessageBox ((HWND) hwndDlg, "The uninstall has failed!", lpszTitle, MB_ICONHAND);
1131: }
1132: }
1133:
1134: static void SetSystemRestorePoint (void *hwndDlg, BOOL finalize)
1135: {
1136: static RESTOREPOINTINFO RestPtInfo;
1137: static STATEMGRSTATUS SMgrStatus;
1138: static BOOL failed = FALSE;
1139: static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
1140:
1141: if (!SystemRestoreDll) return;
1142:
1143: _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
1144: if (_SRSetRestorePoint == 0)
1145: {
1146: FreeLibrary (SystemRestoreDll);
1147: SystemRestoreDll = 0;
1148: return;
1149: }
1150:
1151: if (!finalize)
1152: {
1153: StatusMessage (hwndDlg, "%s", "Creating system restore point");
1154:
1155: // Initialize the RESTOREPOINTINFO structure
1156: RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
1157:
1158: // Notify the system that changes are about to be made.
1159: // An application is to be installed.
1160: RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
1161:
1162: // Set RestPtInfo.llSequenceNumber.
1163: RestPtInfo.llSequenceNumber = 0;
1164:
1165: // String to be displayed by System Restore for this restore point.
1166: strcpy(RestPtInfo.szDescription, "TrueCrypt installation");
1167:
1168: // Notify the system that changes are to be made and that
1169: // the beginning of the restore point should be marked.
1170: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1171: {
1172: StatusMessage (hwndDlg, "%s", "Failed to create System Restore point!");
1173: failed = TRUE;
1174: }
1175:
1176: return;
1177: }
1178:
1179: if (failed) return;
1180:
1181: StatusMessage (hwndDlg, "%s", "Closing system restore point");
1182:
1183: // The application performs some installation operations here.
1184:
1185: // Re-initialize the RESTOREPOINTINFO structure to notify the
1186: // system that the operation is finished.
1187: RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
1188:
1189: // End the system change by returning the sequence number
1190: // received from the first call to SRSetRestorePoint.
1191: RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
1192:
1193: // Notify the system that the operation is done and that this
1194: // is the end of the restore point.
1195: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1196: {
1197: StatusMessage (hwndDlg, "%s", "Closing system restore point failed!");
1198: }
1199: else
1200: StatusMessage (hwndDlg, "%s", "System restore point created");
1201:
1202: }
1203:
1204: void
1205: DoUninstall (void *hwndDlg)
1206: {
1207: BOOL bOK = TRUE;
1208:
1209: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
1210:
1211: WaitCursor ();
1212:
1213: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
1214:
1215: if (DoDriverUnload (hwndDlg) == FALSE)
1216: {
1217: bOK = FALSE;
1218: }
1219: else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1220: {
1221: bOK = FALSE;
1222: }
1223: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1224: {
1225: bOK = FALSE;
1226: }
1227: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, FALSE) == FALSE)
1228: {
1229: bOK = FALSE;
1230: }
1231: else if (DoRegUninstall ((HWND) hwndDlg) == FALSE)
1232: {
1233: bOK = FALSE;
1234: }
1235: else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE)
1236: {
1237: bOK = FALSE;
1238: }
1239: else
1240: {
1241: RemoveMessage ((HWND) hwndDlg, dlg_file_name);
1242: if (StatRemoveDirectory (dlg_file_name) == FALSE)
1243: {
1244: handleWin32Error ((HWND) hwndDlg);
1245: bOK = FALSE;
1246: }
1247: }
1248:
1249: NormalCursor ();
1250:
1251: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1252:
1253: RebootPrompt (hwndDlg, bOK);
1254:
1255: }
1256:
1257: void
1258: DoInstall (void *hwndDlg)
1259: {
1260: BOOL bOK = TRUE;
1261:
1262: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
1263:
1264: WaitCursor ();
1265:
1266: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
1267:
1268: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
1269: SetSystemRestorePoint (hwndDlg, FALSE);
1270:
1271: if (DoDriverUnload (hwndDlg) == FALSE)
1272: {
1273: bOK = FALSE;
1274: }
1275: else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1276: {
1277: bOK = FALSE;
1278: }
1279: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1280: {
1281: bOK = FALSE;
1282: }
1283: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
1284: {
1285: bOK = FALSE;
1286: }
1287: else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name,
1288: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE)),
1289: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
1290: {
1291: bOK = FALSE;
1292: }
1293: else if (DoDriverInstall (hwndDlg) == FALSE)
1294: {
1295: bOK = FALSE;
1296: }
1297: else if (DoServiceInstall (hwndDlg) == FALSE)
1298: {
1299: bOK = FALSE;
1300: }
1301: else if (DoShortcutsInstall (hwndDlg, dlg_file_name,
1302: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)),
1303: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE)
1304: {
1305: bOK = FALSE;
1306: }
1307:
1308: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
1309: SetSystemRestorePoint (hwndDlg, TRUE);
1310:
1311: if (bOK)
1312: StatusMessage (hwndDlg, "%s", "Installation completed.");
1313:
1314: NormalCursor ();
1315:
1316: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1317:
1318: RebootPrompt (hwndDlg, bOK);
1319: }
1320:
1321: BOOL
1322: IsAdmin (void)
1323: {
1324: HANDLE hAccessToken;
1325: UCHAR InfoBuffer[1024];
1326: PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS) InfoBuffer;
1327: DWORD dwInfoBufferSize;
1328: PSID psidAdministrators;
1329: SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
1330: BOOL bSuccess;
1331: UINT x;
1332:
1333: if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, TRUE,
1334: &hAccessToken))
1335: {
1336: if (GetLastError ()!= ERROR_NO_TOKEN)
1337: return FALSE;
1338:
1339: /* Retry against process token if no thread token exists */
1340: if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY,
1341: &hAccessToken))
1342: return FALSE;
1343: }
1344:
1345: bSuccess = GetTokenInformation (hAccessToken, TokenGroups, InfoBuffer,
1346: 1024, &dwInfoBufferSize);
1347:
1348: CloseHandle (hAccessToken);
1349:
1350: if (!bSuccess)
1351: return FALSE;
1352:
1353: if (!AllocateAndInitializeSid (&siaNtAuthority, 2,
1354: SECURITY_BUILTIN_DOMAIN_RID,
1355: DOMAIN_ALIAS_RID_ADMINS,
1356: 0, 0, 0, 0, 0, 0,
1357: &psidAdministrators))
1358: return FALSE;
1359:
1360: /* Assume that we don't find the admin SID. */
1361: bSuccess = FALSE;
1362:
1363: for (x = 0; x < ptgGroups->GroupCount; x++)
1364: {
1365: if (EqualSid (psidAdministrators, ptgGroups->Groups[x].Sid))
1366: {
1367: bSuccess = TRUE;
1368: break;
1369: }
1370:
1371: }
1372:
1373: FreeSid (psidAdministrators);
1374: return bSuccess;
1375: }
1376:
1377: BOOL WINAPI
1378: InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1379: {
1380: WORD lw = LOWORD (wParam);
1381: if (lParam); /* remove warning */
1382:
1383: switch (msg)
1384: {
1385: case WM_INITDIALOG:
1386: SetDefaultUserFont (hwndDlg);
1387: InitDialog (hwndDlg);
1388:
1389: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), "C:\\Program Files\\TrueCrypt");
1390:
1391: if (bUninstall == FALSE)
1392: {
1393: SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) "By clicking 'Install', you accept the license agreement.");
1394:
1395: LoadLicense (hwndDlg);
1396: }
1397:
1398: SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0);
1399: if (nCurrentOS != WIN_NT)
1400: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_ALL_USERS), FALSE);
1401:
1402: SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0);
1403: SendMessage (GetDlgItem (hwndDlg, IDC_UNINSTALL), BM_SETCHECK, BST_CHECKED, 0);
1404: SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0);
1405: SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0);
1406:
1407: // System Restore
1408: SystemRestoreDll = LoadLibrary("srclient.dll");
1409:
1410: if (SystemRestoreDll != 0)
1411: SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0);
1412: else
1413: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
1414:
1415: SetWindowText (hwndDlg, lpszTitle);
1416: return 1;
1417:
1418: case WM_SYSCOMMAND:
1419: if (lw == IDC_ABOUT)
1420: {
1421: DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1422: return 1;
1423: }
1424: return 0;
1425:
1426: case WM_COMMAND:
1427: if (lw == IDOK)
1428: {
1429: char szDirname[TC_MAX_PATH];
1430:
1431: if (bDone == TRUE)
1432: {
1433: EndDialog (hwndDlg, IDOK);
1434: return 1;
1435: }
1436:
1437: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
1438:
1439: if (bUninstall == FALSE)
1440: {
1441: if (mkfulldir (szDirname, TRUE) != 0)
1442: {
1443: char szTmp[TC_MAX_PATH];
1444: int x;
1445:
1446: //sprintf (szTmp, "The directory '%s' does not exist. Do you want to create this directory?", szDirname);
1447: //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
1448: //if (x == IDNO)
1449: //{
1450: // SetFocus (GetDlgItem (hwndDlg, IDC_DESTINATION));
1451: // return 1;
1452: //}
1453:
1454: if (mkfulldir (szDirname, FALSE) != 0)
1455: {
1456: handleWin32Error (hwndDlg);
1457: sprintf (szTmp, "The directory '%s' could not be created", szDirname);
1458: MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1459: return 1;
1460: }
1461:
1462: }
1463: }
1464:
1465: strcpy (dlg_file_name, szDirname);
1466:
1467: if (bUninstall == FALSE)
1468: _beginthread (DoInstall, 16384, (void *) hwndDlg);
1469: else
1470: _beginthread (DoUninstall, 16384, (void *) hwndDlg);
1471:
1472: return 1;
1473: }
1474:
1475: if (lw == IDCANCEL)
1476: {
1477: EndDialog (hwndDlg, IDCANCEL);
1478: return 1;
1479: }
1480:
1481: if (lw == IDC_BROWSE)
1482: {
1483: char szDirname[TC_MAX_PATH];
1484:
1485: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
1486:
1487: if (BrowseFiles2 (hwndDlg, "Please select a folder", szDirname) == TRUE)
1488: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname);
1489:
1490: return 1;
1491: }
1492:
1493: if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE)
1494: {
1495: if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0)
1496: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
1497: else
1498: EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
1499: return 1;
1500: }
1501:
1502: return 0;
1503:
1504: case WM_CLOSE:
1505: EndDialog (hwndDlg, IDCANCEL);
1506: return 1;
1507: }
1508:
1509: return 0;
1510: }
1511:
1512:
1513: int WINAPI
1514: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
1515: int nCmdShow)
1516: {
1517: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
1518:
1519: lpszTitle = "TrueCrypt Setup";
1520:
1521: /* Call InitApp to initialize the common code */
1522: InitApp (hInstance);
1523:
1.1.1.2 ! root 1524: if (CurrentOSMajor < 5)
! 1525: {
! 1526: MessageBox (NULL, "TrueCrypt requires at least Windows 2000 to run.", lpszTitle, MB_ICONSTOP);
! 1527: return 0;
! 1528: }
! 1529:
1.1 root 1530: if (nCurrentOS == WIN_NT && IsAdmin ()!= TRUE)
1531: if (MessageBox (NULL, "To successfully install/uninstall TrueCrypt under Windows NT you must be running as an Administrator, "
1532: "do you still want to continue?", lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1533: return 0;
1534:
1535: if (lpszCommandLine[0] == '/' && (lpszCommandLine[1] == 'u' || lpszCommandLine[1] == 'U'))
1536: {
1537: bUninstall = TRUE;
1538: }
1539:
1540: if (bUninstall == FALSE)
1541: {
1542: /* Create the main dialog box */
1543: DialogBox (hInstance, MAKEINTRESOURCE (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc);
1544: }
1545: else
1546: {
1547: /* Create the main dialog box */
1548: DialogBox (hInstance, MAKEINTRESOURCE (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc);
1549: }
1550:
1551: /* Terminate */
1552: return 0;
1553: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.