|
|
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: "Itruecrypt.vxd"
292: };
293:
294: char szTmp[TC_MAX_PATH];
295: BOOL bOK = TRUE;
296: int i;
297:
298: if (bUninstall == TRUE)
299: bUninstallSupport = FALSE;
300:
301: for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
302: {
303: BOOL bResult, bSlash;
304: char szDir[TC_MAX_PATH];
305: int x;
306:
307: if (bUninstallSupport == FALSE && strstr (szFiles[i], "TrueCrypt Setup") != 0)
308: continue;
309:
310: if (*szFiles[i] == 'A')
311: strcpy (szDir, szDestDir);
312: else if (*szFiles[i] == 'S')
313: GetSystemDirectory (szDir, sizeof (szDir));
314: else if (*szFiles[i] == 'I')
315: {
316: GetSystemDirectory (szDir, sizeof (szDir));
317:
318: x = strlen (szDestDir);
319: if (szDestDir[x - 1] == '\\')
320: bSlash = TRUE;
321: else
322: bSlash = FALSE;
323:
324: if (bSlash == FALSE)
325: strcat (szDir, "\\");
326:
327: strcat (szDir, "IOSUBSYS");
328: }
329: else if (*szFiles[i] == 'D')
330: {
331: GetSystemDirectory (szDir, sizeof (szDir));
332:
333: x = strlen (szDestDir);
334: if (szDestDir[x - 1] == '\\')
335: bSlash = TRUE;
336: else
337: bSlash = FALSE;
338:
339: if (bSlash == FALSE)
340: strcat (szDir, "\\");
341:
342: strcat (szDir, "Drivers");
343: }
344: else if (*szFiles[i] == 'W')
345: GetWindowsDirectory (szDir, sizeof (szDir));
346:
347: x = strlen (szDestDir);
348: if (szDestDir[x - 1] == '\\')
349: bSlash = TRUE;
350: else
351: bSlash = FALSE;
352:
353: if (bSlash == FALSE)
354: strcat (szDir, "\\");
355:
356: if ((*szFiles[i] == 'D' || *szFiles[i] == 'S') && nCurrentOS != WIN_NT)
357: continue;
358:
359: if (*szFiles[i] == 'I' && nCurrentOS == WIN_NT)
360: continue;
361:
362: sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);
363:
364: if (bUninstall == FALSE)
365: CopyMessage (hwndDlg, szTmp);
366: else
367: RemoveMessage (hwndDlg, szTmp);
368:
369: if (bUninstall == FALSE)
370: {
371: bResult = CopyFile (szFiles[i] + 1, szTmp, FALSE);
372: if (!bResult)
373: {
374: char s[256];
375: sprintf (s, "Setup Files\\%s", szFiles[i] + 1);
376: bResult = CopyFile (s, szTmp, FALSE);
377: }
378: }
379: else
380: {
381: bResult = StatDeleteFile (szTmp);
382: }
383:
384: if (bResult == FALSE)
385: {
386: LPVOID lpMsgBuf;
387: DWORD dwError = GetLastError ();
388: char szTmp2[700];
389:
390: FormatMessage (
391: FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
392: NULL,
393: dwError,
394: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
395: (char *) &lpMsgBuf,
396: 0,
397: NULL
398: );
399:
400:
401: if (bUninstall == FALSE)
402: sprintf (szTmp2, "The installation of '%s' has failed. %s Do you want to continue with the Install?",
403: szTmp, lpMsgBuf);
404: else
405: sprintf (szTmp2, "The uninstallation of '%s' has failed. %s Do you want to continue with the Uninstall?",
406: szTmp, lpMsgBuf);
407:
408: LocalFree (lpMsgBuf);
409:
410: if (MessageBox (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
411: return FALSE;
412: }
413:
414: }
415:
416: return bOK;
417: }
418:
419: BOOL
420: DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType, BOOL bUninstallSupport)
421: {
422: char szDir[TC_MAX_PATH], *key;
423: HKEY hkey = 0;
424: BOOL bSlash, bOK = FALSE;
425: DWORD dw;
426: int x;
427:
428: strcpy (szDir, szDestDir);
429: x = strlen (szDestDir);
430: if (szDestDir[x - 1] == '\\')
431: bSlash = TRUE;
432: else
433: bSlash = FALSE;
434:
435: if (bSlash == FALSE)
436: strcat (szDir, "\\");
437:
438: if (nCurrentOS == WIN_NT)
439: {
440: /* 9/9/99 FIX This code should no longer be needed as we use
441: the "services" api to install the driver now, rather than
442: setting the registry by hand */
443:
444: /* Install device driver */
445: key = "SYSTEM\\CurrentControlSet\\Services\\truecrypt";
446: RegMessage (hwndDlg, key);
447: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
448: key,
449: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
450: goto error;
451:
452: dw = 1;
453: if (RegSetValueEx (hkey, "Type", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
454: goto error;
455:
456: dw = 1;
457: if (RegSetValueEx (hkey, "Start", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
458: goto error;
459:
460: dw = 1;
461: if (RegSetValueEx (hkey, "ErrorControl", 0, REG_DWORD, (BYTE *) & dw, 4) != ERROR_SUCCESS)
462: goto error;
463:
464: if (RegSetValueEx (hkey, "Group", 0, REG_SZ, (BYTE *) "Primary disk", 13) != ERROR_SUCCESS)
465: goto error;
466:
467: RegCloseKey (hkey);
468: hkey = 0;
469: }
470:
471: if (bInstallType == TRUE)
472: {
473: char szTmp[TC_MAX_PATH];
474:
475: key = "SOFTWARE\\Classes\\TrueCryptVolume";
476: RegMessage (hwndDlg, key);
477: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
478: key,
479: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
480: goto error;
481:
482: sprintf (szTmp, "TrueCrypt Volume", szDir);
483: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
484: goto error;
485:
486: RegCloseKey (hkey);
487: hkey = 0;
488:
489: key = "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon";
490: RegMessage (hwndDlg, key);
491: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
492: key,
493: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
494: goto error;
495:
496: sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
497: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
498: goto error;
499:
500: RegCloseKey (hkey);
501: hkey = 0;
502:
503: key = "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command";
504: RegMessage (hwndDlg, key);
505: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
506: key,
507: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
508: goto error;
509:
510: sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
511: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
512: goto error;
513:
514: RegCloseKey (hkey);
515: hkey = 0;
516:
517: key = "SOFTWARE\\Classes\\.tc";
518: RegMessage (hwndDlg, key);
519: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
520: key,
521: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
522: goto error;
523:
524: strcpy (szTmp, "TrueCryptVolume");
525: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
526: goto error;
527: }
528:
529:
530: if (bUninstallSupport == TRUE)
531: {
532: char szTmp[TC_MAX_PATH];
533:
534: key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
535: RegMessage (hwndDlg, key);
536: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
537: key,
538: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
539: goto error;
540:
541: GetWindowsDirectory (szDir, sizeof (szDir));
542:
543: x = strlen (szDir);
544: if (szDir[x - 1] == '\\')
545: bSlash = TRUE;
546: else
547: bSlash = FALSE;
548:
549: if (bSlash == FALSE)
550: strcat (szDir, "\\");
551:
552: sprintf (szTmp, "%sTrueCrypt Setup.exe /u", szDir);
553: if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
554: goto error;
555:
556: strcpy (szTmp, "TrueCrypt");
557: if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
558: goto error;
559: }
560:
561: bOK = TRUE;
562:
563: error:
564: if (hkey != 0)
565: RegCloseKey (hkey);
566:
567: if (bOK == FALSE)
568: {
569: handleWin32Error (hwndDlg);
570: MessageBox (hwndDlg, "The installation of the registry entries has failed", lpszTitle, MB_ICONHAND);
571: }
572:
573: return bOK;
574: }
575:
576: BOOL
577: DoRegUninstall (HWND hwndDlg)
578: {
579: BOOL bOK = FALSE;
580:
581: StatusMessage (hwndDlg, "%s", "Removing registry entries");
582:
583: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
584: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open\\command");
585: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell\\open");
586: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\Shell");
587: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume\\DefaultIcon");
588: RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\TrueCryptVolume");
589: RegDeleteKey (HKEY_CURRENT_USER, "SOFTWARE\\TrueCrypt");
590: if (RegDeleteKey (HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\.tc") != ERROR_SUCCESS)
591: goto error;
592:
593: bOK = TRUE;
594:
595: error:
596:
597: if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
598: && GetLastError ()!= ERROR_PATH_NOT_FOUND)
599: {
600: handleWin32Error (hwndDlg);
601: MessageBox (hwndDlg, "The uninstallation of the registry entries has failed", lpszTitle, MB_ICONHAND);
602: }
603: else
604: bOK = TRUE;
605:
606: return bOK;
607:
608: }
609:
610: BOOL
611: DoServiceUninstall (HWND hwndDlg, char *lpszService)
612: {
613: SC_HANDLE hManager, hService = NULL;
614: BOOL bOK = FALSE, bRet;
615: SERVICE_STATUS status;
616: char szTmp[128];
617: int x;
618:
619: if (nCurrentOS != WIN_NT)
620: return TRUE;
621: else
622: memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */
623:
624: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
625: if (hManager == NULL)
626: goto error;
627:
628: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
629: if (hService == NULL)
630: goto error;
631:
632: sprintf (szTmp, "stopping %s", lpszService);
633: ServiceMessage (hwndDlg, szTmp);
634:
635: #define WAIT_PERIOD 3
636:
637: for (x = 0; x < WAIT_PERIOD; x++)
638: {
639: bRet = QueryServiceStatus (hService, &status);
640: if (bRet != TRUE)
641: goto error;
642:
643: if (status.dwCurrentState != SERVICE_START_PENDING &&
644: status.dwCurrentState != SERVICE_STOP_PENDING &&
645: status.dwCurrentState != SERVICE_CONTINUE_PENDING)
646: break;
647:
648: Sleep (1000);
649: }
650:
651: if (status.dwCurrentState != SERVICE_STOPPED)
652: {
653: bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
654: if (bRet == FALSE)
655: goto try_delete;
656:
657: for (x = 0; x < WAIT_PERIOD; x++)
658: {
659: bRet = QueryServiceStatus (hService, &status);
660: if (bRet != TRUE)
661: goto error;
662:
663: if (status.dwCurrentState != SERVICE_START_PENDING &&
664: status.dwCurrentState != SERVICE_STOP_PENDING &&
665: status.dwCurrentState != SERVICE_CONTINUE_PENDING)
666: break;
667:
668: Sleep (1000);
669: }
670:
671: if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
672: goto error;
673: }
674:
675: try_delete:
676: sprintf (szTmp, "deleting %s", lpszService);
677: ServiceMessage (hwndDlg, szTmp);
678:
679: if (hService != NULL)
680: CloseServiceHandle (hService);
681:
682: if (hManager != NULL)
683: CloseServiceHandle (hManager);
684:
685: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
686: if (hManager == NULL)
687: goto error;
688:
689: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
690: if (hService == NULL)
691: goto error;
692:
693: bRet = DeleteService (hService);
694: if (bRet == FALSE)
695: goto error;
696:
697: bOK = TRUE;
698:
699: error:
700: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
701: {
702: handleWin32Error (hwndDlg);
703: MessageBox (hwndDlg, "The uninstallation of the device driver has failed", lpszTitle, MB_ICONHAND);
704: }
705: else
706: bOK = TRUE;
707:
708: if (hService != NULL)
709: CloseServiceHandle (hService);
710:
711: if (hManager != NULL)
712: CloseServiceHandle (hManager);
713:
714: return bOK;
715: }
716:
717: BOOL
718: DoDriverUnload (HWND hwndDlg)
719: {
720: BOOL bOK = TRUE;
721: int status;
722:
723: status = DriverAttach ();
724: if (status != 0)
725: {
726: if (status == ERR_OS_ERROR && GetLastError ()!= ERROR_FILE_NOT_FOUND)
727: {
728: handleWin32Error (hwndDlg);
729: AbortProcess (IDS_NODRIVER);
730: }
731:
732: if (status != ERR_OS_ERROR)
733: {
734: handleError (NULL, status);
735: AbortProcess (IDS_NODRIVER);
736: }
737: }
738:
739: if (hDriver != INVALID_HANDLE_VALUE)
740: {
741: DWORD dwError;
742: int x;
743:
744:
745: if (nCurrentOS == WIN_NT)
746: {
747: ServiceMessage (hwndDlg, "dismounting any mounted volumes");
748:
749: if (UnmountAllVolumes (hwndDlg, &dwError, &x) == FALSE)
750: {
751: bOK = FALSE;
752: MessageBox (hwndDlg, "Volumes are still mounted; all volumes must be dismounted before uninstallation can continue", lpszTitle, MB_ICONHAND);
753: }
754: }
755: else
756: {
757:
758: MOUNT_LIST_STRUCT driver;
759: DWORD dwResult;
760: BOOL bResult;
761:
762: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver,
763: sizeof (driver), &dwResult, NULL);
764:
765: if (bResult == TRUE)
766: {
767: if (driver.ulMountedDrives != 0)
768: {
769: bOK = FALSE;
770: MessageBox (hwndDlg, "Volumes are still mounted; all volumes must be dismounted before uninstallation can continue", lpszTitle, MB_ICONHAND);
771: }
772: }
773: else
774: {
775: bOK = FALSE;
776: handleWin32Error (hwndDlg);
777: }
778: }
779:
780: CloseHandle (hDriver);
781: hDriver = INVALID_HANDLE_VALUE;
782:
783: }
784:
785: return bOK;
786: }
787:
788: BOOL
789: DoServiceInstall (HWND hwndDlg)
790: {
791: BOOL bOK = FALSE;
792:
793: if (nCurrentOS != WIN_NT)
794: return TRUE;
795:
796: ServiceMessage (hwndDlg, "installing TrueCryptService");
797: ServiceMessage (hwndDlg, "starting TrueCryptService");
798:
799: if (CheckService ()== FALSE)
800: goto error;
801:
802: bOK = TRUE;
803:
804: error:
805: if (bOK == FALSE)
806: {
807: MessageBox ((HWND) hwndDlg, "The installation of the service has failed", lpszTitle, MB_ICONHAND);
808: }
809:
810: return bOK;
811: }
812:
813: BOOL
814: DoDriverInstall (HWND hwndDlg)
815: {
816: SC_HANDLE hManager, hService = NULL;
817: BOOL bOK = FALSE, bRet, bSlash;
818: char szDir[TC_MAX_PATH];
819: int x;
820:
821: if (nCurrentOS != WIN_NT)
822: return TRUE;
823:
824: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
825: if (hManager == NULL)
826: goto error;
827:
828: GetSystemDirectory (szDir, sizeof (szDir));
829:
830: x = strlen (szDir);
831: if (szDir[x - 1] == '\\')
832: bSlash = TRUE;
833: else
834: bSlash = FALSE;
835:
836: if (bSlash == FALSE)
837: strcat (szDir, "\\");
838:
839: strcat (szDir, "Drivers\\truecrypt.sys");
840:
841: ServiceMessage (hwndDlg, "installing TrueCrypt driver service");
842:
843: hService = CreateService (hManager, "truecrypt", "truecrypt",
844: SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
845: szDir, NULL, NULL, NULL, NULL, NULL
846: );
847: if (hService == NULL)
848: goto error;
849: else
850: CloseServiceHandle (hService);
851:
852: hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
853: if (hService == NULL)
854: goto error;
855:
856: ServiceMessage (hwndDlg, "starting TrueCrypt driver service");
857:
858: bRet = StartService (hService, 0, NULL);
859: if (bRet == FALSE)
860: goto error;
861:
862: bOK = TRUE;
863:
864: error:
865: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_ALREADY_RUNNING)
866: {
867: handleWin32Error (hwndDlg);
868: MessageBox (hwndDlg, "The installation of the device driver has failed", lpszTitle, MB_ICONHAND);
869: }
870: else
871: bOK = TRUE;
872:
873: if (hService != NULL)
874: CloseServiceHandle (hService);
875:
876: if (hManager != NULL)
877: CloseServiceHandle (hManager);
878:
879: return bOK;
880: }
881:
882: BOOL
883: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
884: {
885: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
886: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
887: BOOL bSlash, bOK = FALSE;
888: HRESULT hOle;
889: int x;
890: BOOL allUsers = FALSE;
891:
892: hOle = OleInitialize (NULL);
893:
894: // User start menu
895: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
896: x = strlen (szLinkDir);
897: if (szLinkDir[x - 1] == '\\')
898: bSlash = TRUE;
899: else
900: bSlash = FALSE;
901:
902: if (bSlash == FALSE)
903: strcat (szLinkDir, "\\");
904:
905: strcat (szLinkDir, "TrueCrypt");
906:
907: // Global start menu
908: if (nCurrentOS == WIN_NT)
909: {
910: struct _stat st;
911: char path[TC_MAX_PATH];
912:
913: SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
914: strcat (path, "\\TrueCrypt");
915:
916: if (_stat (path, &st) == 0)
917: {
918: strcpy (szLinkDir, path);
919: allUsers = TRUE;
920: }
921: }
922:
923: // Start menu entries
924: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
925: RemoveMessage (hwndDlg, szTmp2);
926: if (StatDeleteFile (szTmp2) == FALSE)
927: goto error;
928:
929: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
930: RemoveMessage (hwndDlg, szTmp2);
931: if (StatDeleteFile (szTmp2) == FALSE)
932: goto error;
933:
934: GetWindowsDirectory (szDir, sizeof (szDir));
935: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
936: RemoveMessage (hwndDlg, szTmp2);
937: if (StatDeleteFile (szTmp2) == FALSE)
938: goto error;
939:
940: // Start menu group
941: RemoveMessage ((HWND) hwndDlg, szLinkDir);
942: if (StatRemoveDirectory (szLinkDir) == FALSE)
943: {
944: handleWin32Error ((HWND) hwndDlg);
945: goto error;
946: }
947:
948: // Desktop icon
949:
950: if (allUsers)
951: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
952: else
953: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
954:
955: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
956:
957: RemoveMessage (hwndDlg, szTmp2);
958: if (StatDeleteFile (szTmp2) == FALSE)
959: goto error;
960:
961: bOK = TRUE;
962:
963: error:
964: OleUninitialize ();
965:
966: return bOK;
967: }
968:
969: BOOL
970: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
971: {
972: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
973: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
974: BOOL bSlash, bOK = FALSE;
975: HRESULT hOle;
976: int x;
977:
978: if (bProgGroup == FALSE && bDesktopIcon == FALSE)
979: return TRUE;
980:
981: hOle = OleInitialize (NULL);
982:
983: GetProgramPath (hwndDlg, szLinkDir);
984:
985: x = strlen (szLinkDir);
986: if (szLinkDir[x - 1] == '\\')
987: bSlash = TRUE;
988: else
989: bSlash = FALSE;
990:
991: if (bSlash == FALSE)
992: strcat (szLinkDir, "\\");
993:
994: strcat (szLinkDir, "TrueCrypt");
995:
996: strcpy (szDir, szDestDir);
997: x = strlen (szDestDir);
998: if (szDestDir[x - 1] == '\\')
999: bSlash = TRUE;
1000: else
1001: bSlash = FALSE;
1002:
1003: if (bSlash == FALSE)
1004: strcat (szDir, "\\");
1005:
1006: if (bProgGroup)
1007: {
1008: if (mkfulldir (szLinkDir, TRUE) != 0)
1009: {
1010: char szTmp[TC_MAX_PATH];
1011: int x;
1012:
1013: //sprintf (szTmp, "The program folder '%s' does not exist. Do you want to create this folder?", szLinkDir);
1014: //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
1015: //if (x == IDNO)
1016: //{
1017: // goto error;
1018: //}
1019:
1020: if (mkfulldir (szLinkDir, FALSE) != 0)
1021: {
1022: handleWin32Error (hwndDlg);
1023: sprintf (szTmp, "The folder '%s' could not be created", szLinkDir);
1024: MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1025: goto error;
1026: }
1027: }
1028:
1029: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1030: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1031:
1032: IconMessage (hwndDlg, szTmp2);
1033: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1034: goto error;
1035:
1036:
1037: sprintf (szTmp, "%s%s", szDir, "TrueCrypt User Guide.pdf");
1038: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
1039:
1040: IconMessage (hwndDlg, szTmp2);
1041: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1042: goto error;
1043:
1044: GetWindowsDirectory (szDir, sizeof (szDir));
1045: x = strlen (szDir);
1046: if (szDir[x - 1] == '\\')
1047: bSlash = TRUE;
1048: else
1049: bSlash = FALSE;
1050:
1051: if (bSlash == FALSE)
1052: strcat (szDir, "\\");
1053:
1054: sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
1055: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1056:
1057: IconMessage (hwndDlg, szTmp2);
1058: if (CreateLink (szTmp, "/u", szTmp2) != S_OK)
1059: goto error;
1060:
1061: }
1062:
1063: if (bDesktopIcon)
1064: {
1065: strcpy (szDir, szDestDir);
1066: x = strlen (szDestDir);
1067: if (szDestDir[x - 1] == '\\')
1068: bSlash = TRUE;
1069: else
1070: bSlash = FALSE;
1071:
1072: if (bSlash == FALSE)
1073: strcat (szDir, "\\");
1074:
1075: if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
1076: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
1077: else
1078: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
1079:
1080: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1081: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1082:
1083: IconMessage (hwndDlg, szTmp2);
1084:
1085: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1086: goto error;
1087: }
1088:
1089: bOK = TRUE;
1090:
1091: error:
1092: OleUninitialize ();
1093:
1094: return bOK;
1095: }
1096:
1097:
1098: void
1099: RebootPrompt (HWND hwndDlg, BOOL bOK)
1100: {
1101: if (bOK == TRUE)
1102: {
1103: SetWindowText (GetDlgItem ((HWND) hwndDlg, IDOK), "E&xit");
1104:
1105: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
1106:
1107: bDone = TRUE;
1108:
1109: if (nCurrentOS == WIN_NT)
1110: {
1111: if (bUninstall == FALSE)
1112: MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.", lpszTitle, MB_ICONINFORMATION);
1113: else
1114: MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.", lpszTitle, MB_ICONINFORMATION);
1115: }
1116: else
1117: {
1118: int x;
1119:
1120: if (bUninstall == FALSE)
1121: x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.\nTo use TrueCrypt your system must be restarted.", lpszTitle, MB_ICONINFORMATION);
1122: else
1123: x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.\nYour system must be restarted.", lpszTitle, MB_ICONINFORMATION);
1124: }
1125: }
1126: else
1127: {
1128: if (bUninstall == FALSE)
1129: MessageBox ((HWND) hwndDlg, "The installation has failed!", lpszTitle, MB_ICONHAND);
1130: else
1131: MessageBox ((HWND) hwndDlg, "The uninstall has failed!", lpszTitle, MB_ICONHAND);
1132: }
1133: }
1134:
1135: static void SetSystemRestorePoint (void *hwndDlg, BOOL finalize)
1136: {
1137: static RESTOREPOINTINFO RestPtInfo;
1138: static STATEMGRSTATUS SMgrStatus;
1139: static BOOL failed = FALSE;
1140: static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
1141:
1142: if (!SystemRestoreDll) return;
1143:
1144: _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
1145: if (_SRSetRestorePoint == 0)
1146: {
1147: FreeLibrary (SystemRestoreDll);
1148: SystemRestoreDll = 0;
1149: return;
1150: }
1151:
1152: if (!finalize)
1153: {
1154: StatusMessage (hwndDlg, "%s", "Creating system restore point");
1155:
1156: // Initialize the RESTOREPOINTINFO structure
1157: RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
1158:
1159: // Notify the system that changes are about to be made.
1160: // An application is to be installed.
1161: RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
1162:
1163: // Set RestPtInfo.llSequenceNumber.
1164: RestPtInfo.llSequenceNumber = 0;
1165:
1166: // String to be displayed by System Restore for this restore point.
1167: strcpy(RestPtInfo.szDescription, "TrueCrypt installation");
1168:
1169: // Notify the system that changes are to be made and that
1170: // the beginning of the restore point should be marked.
1171: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1172: {
1173: StatusMessage (hwndDlg, "%s", "Failed to create System Restore point!");
1174: failed = TRUE;
1175: }
1176:
1177: return;
1178: }
1179:
1180: if (failed) return;
1181:
1182: StatusMessage (hwndDlg, "%s", "Closing system restore point");
1183:
1184: // The application performs some installation operations here.
1185:
1186: // Re-initialize the RESTOREPOINTINFO structure to notify the
1187: // system that the operation is finished.
1188: RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
1189:
1190: // End the system change by returning the sequence number
1191: // received from the first call to SRSetRestorePoint.
1192: RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
1193:
1194: // Notify the system that the operation is done and that this
1195: // is the end of the restore point.
1196: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1197: {
1198: StatusMessage (hwndDlg, "%s", "Closing system restore point failed!");
1199: }
1200: else
1201: StatusMessage (hwndDlg, "%s", "System restore point created");
1202:
1203: }
1204:
1205: void
1206: DoUninstall (void *hwndDlg)
1207: {
1208: BOOL bOK = TRUE;
1209:
1210: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
1211:
1212: WaitCursor ();
1213:
1214: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
1215:
1216: if (DoDriverUnload (hwndDlg) == FALSE)
1217: {
1218: bOK = FALSE;
1219: }
1220: else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1221: {
1222: bOK = FALSE;
1223: }
1224: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1225: {
1226: bOK = FALSE;
1227: }
1228: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, FALSE) == FALSE)
1229: {
1230: bOK = FALSE;
1231: }
1232: else if (DoRegUninstall ((HWND) hwndDlg) == FALSE)
1233: {
1234: bOK = FALSE;
1235: }
1236: else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE)
1237: {
1238: bOK = FALSE;
1239: }
1240: else
1241: {
1242: RemoveMessage ((HWND) hwndDlg, dlg_file_name);
1243: if (StatRemoveDirectory (dlg_file_name) == FALSE)
1244: {
1245: handleWin32Error ((HWND) hwndDlg);
1246: bOK = FALSE;
1247: }
1248: }
1249:
1250: NormalCursor ();
1251:
1252: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1253:
1254: RebootPrompt (hwndDlg, bOK);
1255:
1256: }
1257:
1258: void
1259: DoInstall (void *hwndDlg)
1260: {
1261: BOOL bOK = TRUE;
1262:
1263: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
1264:
1265: WaitCursor ();
1266:
1267: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
1268:
1269: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
1270: SetSystemRestorePoint (hwndDlg, FALSE);
1271:
1272: if (DoDriverUnload (hwndDlg) == FALSE)
1273: {
1274: bOK = FALSE;
1275: }
1276: else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1277: {
1278: bOK = FALSE;
1279: }
1280: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1281: {
1282: bOK = FALSE;
1283: }
1284: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
1285: {
1286: bOK = FALSE;
1287: }
1288: else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name,
1289: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE)),
1290: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
1291: {
1292: bOK = FALSE;
1293: }
1294: else if (DoDriverInstall (hwndDlg) == FALSE)
1295: {
1296: bOK = FALSE;
1297: }
1298: else if (DoServiceInstall (hwndDlg) == FALSE)
1299: {
1300: bOK = FALSE;
1301: }
1302: else if (DoShortcutsInstall (hwndDlg, dlg_file_name,
1303: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)),
1304: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE)
1305: {
1306: bOK = FALSE;
1307: }
1308:
1309: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
1310: SetSystemRestorePoint (hwndDlg, TRUE);
1311:
1312: if (bOK)
1313: StatusMessage (hwndDlg, "%s", "Installation completed.");
1314:
1315: NormalCursor ();
1316:
1317: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1318:
1319: RebootPrompt (hwndDlg, bOK);
1320: }
1321:
1322: BOOL
1323: IsAdmin (void)
1324: {
1325: HANDLE hAccessToken;
1326: UCHAR InfoBuffer[1024];
1327: PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS) InfoBuffer;
1328: DWORD dwInfoBufferSize;
1329: PSID psidAdministrators;
1330: SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
1331: BOOL bSuccess;
1332: UINT x;
1333:
1334: if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, TRUE,
1335: &hAccessToken))
1336: {
1337: if (GetLastError ()!= ERROR_NO_TOKEN)
1338: return FALSE;
1339:
1340: /* Retry against process token if no thread token exists */
1341: if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY,
1342: &hAccessToken))
1343: return FALSE;
1344: }
1345:
1346: bSuccess = GetTokenInformation (hAccessToken, TokenGroups, InfoBuffer,
1347: 1024, &dwInfoBufferSize);
1348:
1349: CloseHandle (hAccessToken);
1350:
1351: if (!bSuccess)
1352: return FALSE;
1353:
1354: if (!AllocateAndInitializeSid (&siaNtAuthority, 2,
1355: SECURITY_BUILTIN_DOMAIN_RID,
1356: DOMAIN_ALIAS_RID_ADMINS,
1357: 0, 0, 0, 0, 0, 0,
1358: &psidAdministrators))
1359: return FALSE;
1360:
1361: /* Assume that we don't find the admin SID. */
1362: bSuccess = FALSE;
1363:
1364: for (x = 0; x < ptgGroups->GroupCount; x++)
1365: {
1366: if (EqualSid (psidAdministrators, ptgGroups->Groups[x].Sid))
1367: {
1368: bSuccess = TRUE;
1369: break;
1370: }
1371:
1372: }
1373:
1374: FreeSid (psidAdministrators);
1375: return bSuccess;
1376: }
1377:
1378: BOOL WINAPI
1379: InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1380: {
1381: WORD lw = LOWORD (wParam);
1382: if (lParam); /* remove warning */
1383:
1384: switch (msg)
1385: {
1386: case WM_INITDIALOG:
1387: SetDefaultUserFont (hwndDlg);
1388: InitDialog (hwndDlg);
1389:
1390: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), "C:\\Program Files\\TrueCrypt");
1391:
1392: if (bUninstall == FALSE)
1393: {
1394: SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) "By clicking 'Install', you accept the license agreement.");
1395:
1396: LoadLicense (hwndDlg);
1397: }
1398:
1399: SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0);
1400: if (nCurrentOS != WIN_NT)
1401: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_ALL_USERS), FALSE);
1402:
1403: SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0);
1404: SendMessage (GetDlgItem (hwndDlg, IDC_UNINSTALL), BM_SETCHECK, BST_CHECKED, 0);
1405: SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0);
1406: SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0);
1407:
1408: // System Restore
1409: SystemRestoreDll = LoadLibrary("srclient.dll");
1410:
1411: if (SystemRestoreDll != 0)
1412: SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0);
1413: else
1414: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
1415:
1416: SetWindowText (hwndDlg, lpszTitle);
1417: return 1;
1418:
1419: case WM_SYSCOMMAND:
1420: if (lw == IDC_ABOUT)
1421: {
1422: DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1423: return 1;
1424: }
1425: return 0;
1426:
1427: case WM_COMMAND:
1428: if (lw == IDOK)
1429: {
1430: char szDirname[TC_MAX_PATH];
1431:
1432: if (bDone == TRUE)
1433: {
1434: EndDialog (hwndDlg, IDOK);
1435: return 1;
1436: }
1437:
1438: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
1439:
1440: if (bUninstall == FALSE)
1441: {
1442: if (mkfulldir (szDirname, TRUE) != 0)
1443: {
1444: char szTmp[TC_MAX_PATH];
1445: int x;
1446:
1447: //sprintf (szTmp, "The directory '%s' does not exist. Do you want to create this directory?", szDirname);
1448: //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
1449: //if (x == IDNO)
1450: //{
1451: // SetFocus (GetDlgItem (hwndDlg, IDC_DESTINATION));
1452: // return 1;
1453: //}
1454:
1455: if (mkfulldir (szDirname, FALSE) != 0)
1456: {
1457: handleWin32Error (hwndDlg);
1458: sprintf (szTmp, "The directory '%s' could not be created", szDirname);
1459: MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1460: return 1;
1461: }
1462:
1463: }
1464: }
1465:
1466: strcpy (dlg_file_name, szDirname);
1467:
1468: if (bUninstall == FALSE)
1469: _beginthread (DoInstall, 16384, (void *) hwndDlg);
1470: else
1471: _beginthread (DoUninstall, 16384, (void *) hwndDlg);
1472:
1473: return 1;
1474: }
1475:
1476: if (lw == IDCANCEL)
1477: {
1478: EndDialog (hwndDlg, IDCANCEL);
1479: return 1;
1480: }
1481:
1482: if (lw == IDC_BROWSE)
1483: {
1484: char szDirname[TC_MAX_PATH];
1485:
1486: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
1487:
1488: if (BrowseFiles2 (hwndDlg, "Please select a folder", szDirname) == TRUE)
1489: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname);
1490:
1491: return 1;
1492: }
1493:
1494: if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE)
1495: {
1496: if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0)
1497: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
1498: else
1499: EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
1500: return 1;
1501: }
1502:
1503: return 0;
1504:
1505: case WM_CLOSE:
1506: EndDialog (hwndDlg, IDCANCEL);
1507: return 1;
1508: }
1509:
1510: return 0;
1511: }
1512:
1513:
1514: int WINAPI
1515: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
1516: int nCmdShow)
1517: {
1518: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
1519:
1520: lpszTitle = "TrueCrypt Setup";
1521:
1522: /* Call InitApp to initialize the common code */
1523: InitApp (hInstance);
1524:
1525: if (nCurrentOS == WIN_NT && IsAdmin ()!= TRUE)
1526: if (MessageBox (NULL, "To successfully install/uninstall TrueCrypt under Windows NT you must be running as an Administrator, "
1527: "do you still want to continue?", lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1528: return 0;
1529:
1530: if (lpszCommandLine[0] == '/' && (lpszCommandLine[1] == 'u' || lpszCommandLine[1] == 'U'))
1531: {
1532: bUninstall = TRUE;
1533: }
1534:
1535: if (bUninstall == FALSE)
1536: {
1537: /* Create the main dialog box */
1538: DialogBox (hInstance, MAKEINTRESOURCE (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc);
1539: }
1540: else
1541: {
1542: /* Create the main dialog box */
1543: DialogBox (hInstance, MAKEINTRESOURCE (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc);
1544: }
1545:
1546: /* Terminate */
1547: return 0;
1548: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.