1 |
werner |
36 |
/* 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 <stdio.h> |
27 |
werner |
47 |
#include "resource.h" |
28 |
werner |
36 |
#include "wptTypes.h" |
29 |
|
|
#include "wptW32API.h" |
30 |
|
|
#include "wptVersion.h" |
31 |
|
|
#include "wptNLS.h" |
32 |
|
|
#include "wptErrors.h" |
33 |
|
|
|
34 |
|
|
static const char * algos[] = { |
35 |
|
|
"TWOFISH", |
36 |
|
|
"AES256", |
37 |
|
|
"AES192", |
38 |
|
|
"AES", |
39 |
|
|
"BLOWFISH", |
40 |
|
|
"CAST5", |
41 |
|
|
"3DES", |
42 |
|
|
"MD5", |
43 |
|
|
"SHA1", |
44 |
|
|
"ZIP", |
45 |
|
|
"ZLIB", |
46 |
|
|
NULL |
47 |
|
|
}; |
48 |
|
|
|
49 |
|
|
#define MDC_FEATURE 0x01 |
50 |
|
|
#define KSNO_FLAG 0x02 |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
struct prefs_cb_s { |
54 |
|
|
char * p; |
55 |
|
|
int flags; |
56 |
|
|
}; |
57 |
|
|
|
58 |
|
|
static void |
59 |
|
|
load_listbox (HWND dlg) |
60 |
|
|
{ |
61 |
|
|
HWND lb = GetDlgItem (dlg, IDC_SETPREF_PREFLIST); |
62 |
|
|
const char * s; |
63 |
|
|
int i; |
64 |
|
|
|
65 |
|
|
for (i=0; (s=algos[i]); i++) |
66 |
|
|
listbox_add_string (lb, s); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
|
70 |
|
|
static int |
71 |
|
|
copy_listbox_entry (HWND dlg) |
72 |
|
|
{ |
73 |
|
|
int idx=0, ctlid=0, rctlid=0; |
74 |
|
|
char buf[256]; |
75 |
|
|
|
76 |
|
|
if (listbox_get_cursel (GetDlgItem (dlg, IDC_SETPREF_PREFLIST)) != LB_ERR) { |
77 |
|
|
ctlid = IDC_SETPREF_PREFLIST; |
78 |
|
|
rctlid = IDC_SETPREF_LIST; |
79 |
|
|
} |
80 |
|
|
else { |
81 |
|
|
ctlid = IDC_SETPREF_LIST; |
82 |
|
|
rctlid = IDC_SETPREF_PREFLIST; |
83 |
|
|
} |
84 |
|
|
idx = listbox_get_cursel (GetDlgItem (dlg, ctlid)); |
85 |
|
|
if (idx == LB_ERR) |
86 |
|
|
return -1; |
87 |
|
|
SendDlgItemMessage (dlg, ctlid, LB_GETTEXT, (WPARAM)idx, (LPARAM)buf); |
88 |
|
|
SendDlgItemMessage (dlg, ctlid, LB_DELETESTRING, (WPARAM)idx, 0); |
89 |
|
|
SendDlgItemMessage (dlg, rctlid, LB_ADDSTRING, 0, (LPARAM)(const char *)buf); |
90 |
|
|
return 0; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
static int |
95 |
|
|
return_pref_flags (HWND dlg) |
96 |
|
|
{ |
97 |
|
|
int flags=0; |
98 |
|
|
|
99 |
|
|
if (IsDlgButtonChecked (dlg, IDC_SETPREF_MDC)) |
100 |
|
|
flags |= MDC_FEATURE; |
101 |
|
|
if (IsDlgButtonChecked (dlg, IDC_SETPREF_KSNO)) |
102 |
|
|
flags |= KSNO_FLAG; |
103 |
|
|
return flags; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
|
|
static char * |
108 |
|
|
mk_prefs_from_list (HWND dlg, int flags) |
109 |
|
|
{ |
110 |
|
|
int i, nlist, n=0; |
111 |
|
|
char * p, buf[32]; |
112 |
|
|
|
113 |
|
|
nlist = SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETCOUNT, 0, 0); |
114 |
|
|
if (!nlist) { |
115 |
|
|
msg_box (dlg, _("There are no preferences in the list."), |
116 |
|
|
_("Key Preferences"), MB_ERR); |
117 |
|
|
return NULL; |
118 |
|
|
} |
119 |
|
|
for (i=0; i < nlist; i++) |
120 |
|
|
n += SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETTEXTLEN, i, 0); |
121 |
|
|
if (flags & MDC_FEATURE) |
122 |
|
|
n += 4; |
123 |
|
|
if (flags & KSNO_FLAG) |
124 |
|
|
n += 10; |
125 |
|
|
p = new char[n+2*nlist+1]; |
126 |
|
|
if (!p) |
127 |
|
|
BUG (NULL); |
128 |
|
|
memset (p, 0, n+2*nlist+1); |
129 |
|
|
for (i=0; i < nlist; i++) { |
130 |
|
|
SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETTEXT, i, (LPARAM)(char *)buf); |
131 |
|
|
strcat (p, buf); |
132 |
|
|
strcat (p, " "); |
133 |
|
|
} |
134 |
|
|
if (flags & MDC_FEATURE) |
135 |
|
|
strcat (p, "MDC"); |
136 |
|
|
if (flags & KSNO_FLAG) { |
137 |
|
|
strcat (p, " "); |
138 |
|
|
strcat (p, "NO-MODIFY"); |
139 |
|
|
} |
140 |
|
|
return p; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
|
144 |
|
|
BOOL CALLBACK |
145 |
|
|
keyedit_setpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
146 |
|
|
{ |
147 |
|
|
static struct prefs_cb_s * cb; |
148 |
|
|
|
149 |
|
|
switch (msg) { |
150 |
|
|
case WM_INITDIALOG: |
151 |
|
|
cb = (struct prefs_cb_s *)lparam; |
152 |
|
|
if (!cb) |
153 |
|
|
BUG (NULL); |
154 |
|
|
load_listbox (dlg); |
155 |
|
|
CheckDlgButton (dlg, IDC_SETPREF_MDC, BST_CHECKED); |
156 |
|
|
center_window (dlg, NULL); |
157 |
|
|
SetForegroundWindow (dlg); |
158 |
|
|
break; |
159 |
|
|
|
160 |
|
|
case WM_COMMAND: |
161 |
|
|
switch (LOWORD (wparam)) { |
162 |
|
|
case IDOK: |
163 |
|
|
cb->flags = return_pref_flags (dlg); |
164 |
|
|
cb->p = mk_prefs_from_list (dlg, cb->flags); |
165 |
|
|
if (!cb->p) |
166 |
|
|
return FALSE; |
167 |
|
|
EndDialog (dlg, TRUE); |
168 |
|
|
break; |
169 |
|
|
|
170 |
|
|
case IDCANCEL: |
171 |
|
|
EndDialog (dlg, FALSE); |
172 |
|
|
break; |
173 |
|
|
|
174 |
|
|
case IDC_SETPREF_UPDATE: |
175 |
|
|
copy_listbox_entry (dlg); |
176 |
|
|
break; |
177 |
|
|
} |
178 |
|
|
break; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
return FALSE; |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
void |
186 |
|
|
get_userid_preflist (char ** r_prefs, int * r_flags) |
187 |
|
|
{ |
188 |
|
|
struct prefs_cb_s cb; |
189 |
|
|
|
190 |
|
|
memset (&cb, 0, sizeof cb); |
191 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SETPREF, |
192 |
|
|
GetDesktopWindow (), keyedit_setpref_dlg_proc, (LPARAM)&cb); |
193 |
|
|
*r_prefs = cb.p; |
194 |
|
|
*r_flags = cb.flags; |
195 |
|
|
} |
196 |
|
|
|