1 |
/* WinPT.cpp - Windows Privacy Tray (WinPT) |
/* WinPT.cpp - Windows Privacy Tray (WinPT) |
2 |
* Copyright (C) 2000-2009 Timo Schulz |
* Copyright (C) 2000-2009, 2012 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
315 |
static bool |
static bool |
316 |
check_for_empty_keyrings (bool pub_only) |
check_for_empty_keyrings (bool pub_only) |
317 |
{ |
{ |
318 |
char *p; |
int n = 0; |
319 |
int n; |
char *p = get_gnupg_keyring (1, 0); |
|
|
|
|
n=0; |
|
|
p = get_gnupg_keyring (1, 0); |
|
320 |
if (file_exist_check (p) == 0 && get_file_size (p) == 0) |
if (file_exist_check (p) == 0 && get_file_size (p) == 0) |
321 |
n++; |
n++; |
322 |
free_if_alloc (p); |
free_if_alloc (p); |
326 |
if (file_exist_check (p) == 0 && get_file_size (p) == 0) |
if (file_exist_check (p) == 0 && get_file_size (p) == 0) |
327 |
n++; |
n++; |
328 |
free_if_alloc (p); |
free_if_alloc (p); |
329 |
return n==2? true : false; |
return n == 2? true : false; |
330 |
} |
} |
331 |
|
|
332 |
|
|
341 |
GetTempPath (DIM (temp) - 1, temp); |
GetTempPath (DIM (temp) - 1, temp); |
342 |
_snprintf (output, DIM (output)-1, |
_snprintf (output, DIM (output)-1, |
343 |
"The GPGME output file is %sgpgme.dbg\n" |
"The GPGME output file is %sgpgme.dbg\n" |
344 |
"The WinPT output file is %swinpt.log\n", temp, temp); |
"The WinPT output file is %swinpt-%08lx.log\n", temp, temp, GetCurrentProcessId()); |
345 |
MessageBox (NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO); |
MessageBox (NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO); |
346 |
} |
} |
347 |
|
|
351 |
static int |
static int |
352 |
count_insecure_elgkeys (void) |
count_insecure_elgkeys (void) |
353 |
{ |
{ |
|
gpg_keycache_t pc; |
|
354 |
gpgme_key_t key; |
gpgme_key_t key; |
355 |
|
|
356 |
int n = 0; |
int n = 0; |
357 |
pc = keycache_get_ctx (1); |
gpg_keycache_t pc = keycache_get_ctx (1); |
358 |
while (!gpg_keycache_next_key (pc, 0, &key)) { |
while (!gpg_keycache_next_key (pc, 0, &key)) { |
359 |
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) |
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) |
360 |
n++; |
n++; |
408 |
|
|
409 |
glob_hinst = hinst; |
glob_hinst = hinst; |
410 |
|
|
411 |
|
/* Check as early as possible for debug flags and activate |
412 |
|
the debug mode if requested */ |
413 |
|
if (cmdline && (stristr (cmdline, "--enable-debug") || |
414 |
|
stristr (cmdline, "--debug"))) { |
415 |
|
//gpg_set_debug_mode (1); |
416 |
|
winpt_debug_msg (); |
417 |
|
debug = 1; |
418 |
|
} |
419 |
|
|
420 |
/* Allow to shutdown the process, for instance by an installer */ |
/* Allow to shutdown the process, for instance by an installer */ |
421 |
if (cmdline && stristr (cmdline, "--stop")) { |
if (cmdline && stristr (cmdline, "--stop")) { |
422 |
hwnd = FindWindow ("WinPT", "WinPT"); |
hwnd = FindWindow ("WinPT", "WinPT"); |
423 |
if (hwnd != NULL) { |
if (hwnd != NULL) { |
424 |
log_debug("shutdown an existing WinPT process"); |
log_debug ("shutdown an existing WinPT process"); |
425 |
PostMessage (hwnd, WM_DESTROY, 0, 0); |
PostMessage (hwnd, WM_DESTROY, 0, 0); |
426 |
} |
} |
427 |
return 0; |
return 0; |
428 |
} |
} |
429 |
|
|
430 |
/* KLUDGE: test if the hooking is causing problems with some AV programs */ |
/* KLUDGE: test if the hooking is causing problems with some AV programs */ |
431 |
if (cmdline && stristr (cmdline, "--disable-hook")) |
if (cmdline && stristr (cmdline, "--disable-hook")) { |
432 |
|
log_debug ("disable current window hooks"); |
433 |
disable_hook = 1; |
disable_hook = 1; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
log_debug("check PTD and GPGME version"); |
log_debug("check PTD and GPGME version"); |
438 |
get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]); |
get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]); |
454 |
} |
} |
455 |
|
|
456 |
CreateMutex (NULL, TRUE, PGM_NAME); |
CreateMutex (NULL, TRUE, PGM_NAME); |
457 |
if (GetLastError () == ERROR_ALREADY_EXISTS) |
if (GetLastError () == ERROR_ALREADY_EXISTS) { |
458 |
|
log_debug ("Found running WinPT instance"); |
459 |
winpt_inst_found = 1; |
winpt_inst_found = 1; |
460 |
|
} |
461 |
|
|
462 |
gettext_set_user_domain (); |
gettext_set_user_domain (); |
463 |
|
|
477 |
} |
} |
478 |
|
|
479 |
if (is_gpg4win_installed ()) { |
if (is_gpg4win_installed ()) { |
480 |
log_debug("gpg4win: load gpg environment"); |
log_debug ("gpg4win: load gpg environment"); |
481 |
load_gpg_env (); /* TODO: check return code. */ |
load_gpg_env (); /* TODO: check return code. */ |
482 |
} |
} |
483 |
|
|
538 |
return 0; |
return 0; |
539 |
} |
} |
540 |
} |
} |
541 |
if (check_for_empty_keyrings (false)) |
if (check_for_empty_keyrings (false)) { |
542 |
|
log_debug ("found empty keyrings, assume first start"); |
543 |
first_start = 1; |
first_start = 1; |
544 |
|
} |
545 |
|
|
546 |
if (!first_start) { |
if (!first_start) { |
547 |
rc = gpg_check_permissions (1); |
rc = gpg_check_permissions (1); |
554 |
init_gnupg_table (); |
init_gnupg_table (); |
555 |
|
|
556 |
if (fm_parse_command_line (cmdline) > 0) { |
if (fm_parse_command_line (cmdline) > 0) { |
557 |
|
log_debug ("processed arguments with File Manager, exiting..."); |
558 |
free_gnupg_table (); |
free_gnupg_table (); |
559 |
return 0; |
return 0; |
560 |
} |
} |
587 |
free_gnupg_table (); |
free_gnupg_table (); |
588 |
return 0; |
return 0; |
589 |
} |
} |
590 |
|
|
|
if (cmdline && (stristr (cmdline, "--enable-debug") || |
|
|
stristr (cmdline, "--debug"))) { |
|
|
gpg_set_debug_mode (1); |
|
|
winpt_debug_msg (); |
|
|
debug = 1; |
|
|
} |
|
|
|
|
591 |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
592 |
rc = RegisterClass (&wc); |
rc = RegisterClass (&wc); |
593 |
if (rc == FALSE) { |
if (rc == FALSE) { |