127 |
if (defkey) |
if (defkey) |
128 |
err = gpg_keycache_find_key (kc, defkey, 0, &key); |
err = gpg_keycache_find_key (kc, defkey, 0, &key); |
129 |
else |
else |
130 |
msg_box (NULL, _("No useable secret key found."), _("WinPT Error"), MB_ERR); |
msg_box (NULL, _("No useable secret key found."), |
131 |
|
_("WinPT Error"), MB_ERR); |
132 |
free_if_alloc (defkey); |
free_if_alloc (defkey); |
133 |
return err? -1 : 0; |
return err? -1 : 0; |
134 |
} |
} |
135 |
|
|
136 |
|
|
137 |
/* Return the WinPT program file name (with full pathname). */ |
/* Return the WinPT program file name (with full pathname). */ |
138 |
static const char * |
static const char* |
139 |
get_prog_part (const char * fname, int use_cwd) |
get_prog_part (const char * fname, int use_cwd) |
140 |
{ |
{ |
141 |
static char program[512]; |
static char program[512]; |
189 |
return rc; |
return rc; |
190 |
} |
} |
191 |
/* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */ |
/* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */ |
192 |
if (ma > 1 || pa >= 3) |
if (ma > 1 || pa >= 3) |
193 |
scard_support = 1; |
scard_support = 1; |
194 |
|
|
195 |
gpgver[0] = ma; |
gpgver[0] = ma; |
204 |
static int |
static int |
205 |
load_keyserver_conf (int quiet) |
load_keyserver_conf (int quiet) |
206 |
{ |
{ |
207 |
const char * t; |
const char *t; |
208 |
int rc; |
int rc; |
209 |
|
|
210 |
if (reg_prefs.kserv_conf) |
if (reg_prefs.kserv_conf) |
237 |
reg_prefs.use_viewer = 0; /* XXX */ |
reg_prefs.use_viewer = 0; /* XXX */ |
238 |
} |
} |
239 |
|
|
|
char* multi_gnupg_path (void); |
|
|
|
|
|
const char * fm_get_file_type (const char *fname, int *r_type); |
|
240 |
|
|
241 |
/* Main entry point. */ |
/* Main entry point. */ |
242 |
int WINAPI |
int WINAPI |
244 |
{ |
{ |
245 |
WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME}; |
WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME}; |
246 |
HACCEL accel_tab; |
HACCEL accel_tab; |
247 |
int rc, ec, created = 0, nfiles = 0; |
MSG msg; |
248 |
|
HWND hwnd = NULL; |
249 |
|
WORD ver[3], ptdver[4]; |
250 |
|
int rc, ec, created = 0; |
251 |
int first_start = 0, start_gpgprefs = 0; |
int first_start = 0, start_gpgprefs = 0; |
252 |
int winpt_inst_found = 0; |
int winpt_inst_found = 0; |
253 |
|
int start_manager = 0; |
254 |
const char *s; |
const char *s; |
|
MSG msg; |
|
|
HWND hwnd = NULL; |
|
255 |
|
|
256 |
glob_hinst = hinst; |
glob_hinst = hinst; |
|
|
|
257 |
if (cmdline && stristr (cmdline, "--stop")) { |
if (cmdline && stristr (cmdline, "--stop")) { |
258 |
hwnd = FindWindow ("WinPT", "WinPT"); |
hwnd = FindWindow ("WinPT", "WinPT"); |
259 |
if (hwnd != NULL) |
if (hwnd != NULL) |
260 |
PostMessage (hwnd, WM_DESTROY, 0, 0); |
PostMessage (hwnd, WM_DESTROY, 0, 0); |
261 |
return 0; |
return 0; |
262 |
} |
} |
263 |
|
|
264 |
#ifdef _DEBUG |
/* |
265 |
|
OSVERSIONINFO osinf; |
266 |
|
memset (&osinf, 0, sizeof (osinf)); |
267 |
|
if (GetVersionEx (&osinf) && |
268 |
|
osinf.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && |
269 |
|
osinf.dwMinorVersion == 0) { |
270 |
|
msg_box (NULL, "WinPT propably does not work on Windows 95 without restrictions", |
271 |
|
"WinPT Warning", MB_INFO); |
272 |
|
} |
273 |
|
*/ |
274 |
|
|
275 |
|
#ifdef _DEBUG |
276 |
gpg_set_debug_mode (1); |
gpg_set_debug_mode (1); |
277 |
debug = 1; |
debug = 1; |
278 |
#endif |
#endif |
279 |
|
|
280 |
|
get_file_version ("WinPT.exe", &ver[0], &ver[1], &ver[2], &ver[3]); |
281 |
|
get_file_version ("PTD.dll", &ptdver[0], &ptdver[1], |
282 |
|
&ptdver[2], &ptdver[3]); |
283 |
|
/* XXX |
284 |
|
if (ptdver[0] != ver[0] || ptdver[1] != ver[1]|| ptdver[2] != ver[2]) { |
285 |
|
log_box (_("WinPT Error"), MB_ERR, |
286 |
|
_("The PTD.dll file has a different version than WinPT.exe\n" |
287 |
|
"Please update the PTD.dll to version %d.%d.%d"), |
288 |
|
ver[0], ver[1], ver[2]); |
289 |
|
return 0; |
290 |
|
} |
291 |
|
*/ |
292 |
if (gpg_md_selftest ()) { |
if (gpg_md_selftest ()) { |
293 |
msg_box (NULL, _("Cryptographic selftest failed."), |
msg_box (NULL, _("Cryptographic selftest failed."), |
294 |
_("WinPT Error"), MB_ERR); |
_("WinPT Error"), MB_ERR); |
312 |
mobile = 1; |
mobile = 1; |
313 |
} |
} |
314 |
|
|
|
load_gettext (winpt_inst_found); |
|
315 |
set_default_kserver (); |
set_default_kserver (); |
316 |
|
load_gettext (winpt_inst_found); |
317 |
|
|
318 |
if (!mobile) { |
if (!mobile) { |
319 |
regist_inst_gnupg (1); |
regist_inst_gnupg (1); |
342 |
"Please check the GPG registry settings:\n%s."), |
"Please check the GPG registry settings:\n%s."), |
343 |
winpt_strerror (rc)); |
winpt_strerror (rc)); |
344 |
s = get_fileopen_dlg (GetActiveWindow (), |
s = get_fileopen_dlg (GetActiveWindow (), |
345 |
_("Select GPG Public Keyring"), |
_("Select GPG Public Keyring"), |
346 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
347 |
NULL); |
NULL); |
348 |
if (s != NULL) { |
if (s != NULL) { |
349 |
size_t n; |
size_t n; |
350 |
char * p = strrchr (s, '\\'); |
char *p = strrchr (s, '\\'); |
351 |
if (!p) |
if (!p) |
352 |
BUG (0); |
BUG (0); |
353 |
n = p - s; |
n = p - s; |
354 |
if (n) { |
if (n) { |
355 |
char * file = new char[n+1]; |
char *file = new char[n+1]; |
356 |
if (!file) |
if (!file) |
357 |
BUG (NULL); |
BUG (NULL); |
358 |
memset (file, 0, n); |
memset (file, 0, n); |
377 |
"correct this problem?"), _("WinPT Error"), |
"correct this problem?"), _("WinPT Error"), |
378 |
MB_INFO|MB_YESNO) == IDYES) |
MB_INFO|MB_YESNO) == IDYES) |
379 |
start_gpgprefs = 1; |
start_gpgprefs = 1; |
380 |
else |
else { |
|
{ |
|
381 |
msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR); |
msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR); |
382 |
return 0; |
return 0; |
383 |
} |
} |
407 |
else if (rc) |
else if (rc) |
408 |
return 0; |
return 0; |
409 |
} |
} |
410 |
|
|
411 |
init_gnupg_table (); |
init_gnupg_table (); |
412 |
|
|
413 |
nfiles = fm_parse_command_line (cmdline); |
if (fm_parse_command_line (cmdline) > 0) { |
|
if (nfiles > 0) { |
|
414 |
free_gnupg_table (); |
free_gnupg_table (); |
415 |
return 0; |
return 0; |
416 |
} |
} |
431 |
to open the key manager. Otherwise start a new instance. |
to open the key manager. Otherwise start a new instance. |
432 |
*/ |
*/ |
433 |
HWND tray = FindWindow ("WinPT", "WinPT"); |
HWND tray = FindWindow ("WinPT", "WinPT"); |
434 |
|
if (stristr (cmdline, "keymanager")) |
435 |
|
start_manager = ID_WINPT_KEY; |
436 |
|
else |
437 |
|
start_manager = ID_WINPT_CARD; |
438 |
if (tray != NULL) { |
if (tray != NULL) { |
439 |
PostMessage (tray, WM_COMMAND, ID_WINPT_KEY, 0); |
PostMessage (tray, WM_COMMAND, start_manager, 0); |
440 |
free_gnupg_table (); |
free_gnupg_table (); |
441 |
return 0; |
return 0; |
442 |
} |
} |
|
update_keycache (GetDesktopWindow ()); |
|
|
if (stristr (cmdline, "keymanager")) |
|
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
|
|
GetDesktopWindow(), keymanager_dlg_proc, 0, |
|
|
_("Key Manager"), IDS_WINPT_KEYMISC); |
|
|
else { |
|
|
gpg_card_t crd = gpg_card_load (); |
|
|
if (crd) |
|
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT, |
|
|
GetDesktopWindow(), card_edit_dlg_proc, |
|
|
(LPARAM)crd, _("Card Manager"), |
|
|
IDS_WINPT_CARD_EDIT); |
|
|
gpg_card_release (crd); |
|
|
} |
|
|
/* |
|
|
keycache_release (0); |
|
|
free_gnupg_table (); |
|
|
return 0; |
|
|
*/ |
|
443 |
} |
} |
444 |
|
|
445 |
/* If we found another WinPT instance, just quit to avoid it |
/* If we found another WinPT instance, just quit to avoid it |
451 |
} |
} |
452 |
|
|
453 |
if (cmdline) { |
if (cmdline) { |
454 |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
if (stristr (cmdline, "--enable-debug") || |
455 |
|
stristr (cmdline, "--debug")) { |
456 |
gpg_set_debug_mode (1); |
gpg_set_debug_mode (1); |
457 |
winpt_debug_msg (); |
winpt_debug_msg (); |
458 |
debug = 1; |
debug = 1; |
495 |
|
|
496 |
if (start_gpgprefs) { |
if (start_gpgprefs) { |
497 |
char *ring; |
char *ring; |
|
|
|
498 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
499 |
gpgprefs_dlg_proc, 0); |
gpgprefs_dlg_proc, 0); |
500 |
ring = get_gnupg_keyring (0, !NO_STRICT); |
ring = get_gnupg_keyring (0, !NO_STRICT); |
563 |
} |
} |
564 |
} |
} |
565 |
if (check_default_key (c)) { |
if (check_default_key (c)) { |
566 |
char * p = get_gnupg_default_key (); |
char *p = get_gnupg_default_key (); |
567 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
568 |
_("Default key from the GPG options file could not be found.\n" |
_("Default key from the GPG options file could not be found.\n" |
569 |
"Please check your gpg.conf (options) to correct this:\n\n" |
"Please check your gpg.conf (options) to correct this:\n\n" |
578 |
elgamal_warn_dlg_proc, 0); |
elgamal_warn_dlg_proc, 0); |
579 |
} |
} |
580 |
|
|
581 |
|
if (start_manager) |
582 |
|
PostMessage (hwnd, WM_COMMAND, start_manager, 0); |
583 |
|
|
584 |
accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR); |
accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR); |
585 |
keyring_check_last_access (); /* init */ |
keyring_check_last_access (); /* init */ |
586 |
while (GetMessage (&msg, hwnd, 0, 0)) { |
while (GetMessage (&msg, hwnd, 0, 0)) { |