1 |
/* wptKeyEditOwnertrustDlg.cpp - Key onwertrust dialog |
2 |
* Copyright (C) 2003 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
20 |
|
21 |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
23 |
#endif |
24 |
|
25 |
#include <windows.h> |
26 |
#include <windows.h> |
27 |
#include <stdio.h> |
28 |
#include "../resource.h" |
29 |
#include "wptTypes.h" |
30 |
#include "wptW32API.h" |
31 |
#include "wptVersion.h" |
32 |
#include "wptNLS.h" |
33 |
#include "wptErrors.h" |
34 |
|
35 |
static const char * algos[] = { |
36 |
"TWOFISH", |
37 |
"AES256", |
38 |
"AES192", |
39 |
"AES", |
40 |
"BLOWFISH", |
41 |
"CAST5", |
42 |
"3DES", |
43 |
"MD5", |
44 |
"SHA1", |
45 |
"ZIP", |
46 |
"ZLIB", |
47 |
NULL |
48 |
}; |
49 |
|
50 |
#define MDC_FEATURE 0x01 |
51 |
#define KSNO_FLAG 0x02 |
52 |
|
53 |
|
54 |
struct prefs_cb_s { |
55 |
char * p; |
56 |
int flags; |
57 |
}; |
58 |
|
59 |
static void |
60 |
load_listbox (HWND dlg) |
61 |
{ |
62 |
HWND lb = GetDlgItem (dlg, IDC_SETPREF_PREFLIST); |
63 |
const char * s; |
64 |
int i; |
65 |
|
66 |
for (i=0; (s=algos[i]); i++) |
67 |
listbox_add_string (lb, s); |
68 |
} |
69 |
|
70 |
|
71 |
static int |
72 |
copy_listbox_entry (HWND dlg) |
73 |
{ |
74 |
int idx=0, ctlid=0, rctlid=0; |
75 |
char buf[256]; |
76 |
|
77 |
if (listbox_get_cursel (GetDlgItem (dlg, IDC_SETPREF_PREFLIST)) != LB_ERR) { |
78 |
ctlid = IDC_SETPREF_PREFLIST; |
79 |
rctlid = IDC_SETPREF_LIST; |
80 |
} |
81 |
else { |
82 |
ctlid = IDC_SETPREF_LIST; |
83 |
rctlid = IDC_SETPREF_PREFLIST; |
84 |
} |
85 |
idx = listbox_get_cursel (GetDlgItem (dlg, ctlid)); |
86 |
if (idx == LB_ERR) |
87 |
return -1; |
88 |
SendDlgItemMessage (dlg, ctlid, LB_GETTEXT, (WPARAM)idx, (LPARAM)buf); |
89 |
SendDlgItemMessage (dlg, ctlid, LB_DELETESTRING, (WPARAM)idx, 0); |
90 |
SendDlgItemMessage (dlg, rctlid, LB_ADDSTRING, 0, (LPARAM)(const char *)buf); |
91 |
return 0; |
92 |
} |
93 |
|
94 |
|
95 |
static int |
96 |
return_pref_flags (HWND dlg) |
97 |
{ |
98 |
int flags=0; |
99 |
|
100 |
if (IsDlgButtonChecked (dlg, IDC_SETPREF_MDC)) |
101 |
flags |= MDC_FEATURE; |
102 |
if (IsDlgButtonChecked (dlg, IDC_SETPREF_KSNO)) |
103 |
flags |= KSNO_FLAG; |
104 |
return flags; |
105 |
} |
106 |
|
107 |
|
108 |
static char * |
109 |
mk_prefs_from_list (HWND dlg, int flags) |
110 |
{ |
111 |
int i, nlist, n=0; |
112 |
char * p, buf[32]; |
113 |
|
114 |
nlist = SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETCOUNT, 0, 0); |
115 |
if (!nlist) { |
116 |
msg_box (dlg, _("There are no preferences in the list."), |
117 |
_("Key Preferences"), MB_ERR); |
118 |
return NULL; |
119 |
} |
120 |
for (i=0; i < nlist; i++) |
121 |
n += SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETTEXTLEN, i, 0); |
122 |
if (flags & MDC_FEATURE) |
123 |
n += 4; |
124 |
if (flags & KSNO_FLAG) |
125 |
n += 10; |
126 |
p = new char[n+2*nlist+1]; |
127 |
if (!p) |
128 |
BUG (NULL); |
129 |
memset (p, 0, n+2*nlist+1); |
130 |
for (i=0; i < nlist; i++) { |
131 |
SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETTEXT, i, (LPARAM)(char *)buf); |
132 |
strcat (p, buf); |
133 |
strcat (p, " "); |
134 |
} |
135 |
if (flags & MDC_FEATURE) |
136 |
strcat (p, "MDC"); |
137 |
if (flags & KSNO_FLAG) { |
138 |
strcat (p, " "); |
139 |
strcat (p, "NO-MODIFY"); |
140 |
} |
141 |
return p; |
142 |
} |
143 |
|
144 |
|
145 |
BOOL CALLBACK |
146 |
keyedit_setpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
147 |
{ |
148 |
static struct prefs_cb_s * cb; |
149 |
|
150 |
switch (msg) { |
151 |
case WM_INITDIALOG: |
152 |
cb = (struct prefs_cb_s *)lparam; |
153 |
if (!cb) |
154 |
BUG (NULL); |
155 |
load_listbox (dlg); |
156 |
CheckDlgButton (dlg, IDC_SETPREF_MDC, BST_CHECKED); |
157 |
center_window (dlg, NULL); |
158 |
SetForegroundWindow (dlg); |
159 |
break; |
160 |
|
161 |
case WM_COMMAND: |
162 |
switch (LOWORD (wparam)) { |
163 |
case IDOK: |
164 |
cb->flags = return_pref_flags (dlg); |
165 |
cb->p = mk_prefs_from_list (dlg, cb->flags); |
166 |
if (!cb->p) |
167 |
return FALSE; |
168 |
EndDialog (dlg, TRUE); |
169 |
break; |
170 |
|
171 |
case IDCANCEL: |
172 |
EndDialog (dlg, FALSE); |
173 |
break; |
174 |
|
175 |
case IDC_SETPREF_UPDATE: |
176 |
copy_listbox_entry (dlg); |
177 |
break; |
178 |
} |
179 |
break; |
180 |
} |
181 |
|
182 |
return FALSE; |
183 |
} |
184 |
|
185 |
|
186 |
void |
187 |
get_userid_preflist (char ** r_prefs, int * r_flags) |
188 |
{ |
189 |
struct prefs_cb_s cb; |
190 |
|
191 |
memset (&cb, 0, sizeof cb); |
192 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SETPREF, |
193 |
GetDesktopWindow (), keyedit_setpref_dlg_proc, (LPARAM)&cb); |
194 |
*r_prefs = cb.p; |
195 |
*r_flags = cb.flags; |
196 |
} |
197 |
|