1 |
/* WinPT.cpp - Windows Privacy Tray (WinPT) |
/* WinPT.cpp - Windows Privacy Tray (WinPT) |
2 |
* Copyright (C) 2000-2006 Timo Schulz |
* Copyright (C) 2000-2007 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
40 |
|
|
41 |
void remove_crit_file_attrs (const char *fname, int force); |
void remove_crit_file_attrs (const char *fname, int force); |
42 |
BOOL user_is_admin (void); |
BOOL user_is_admin (void); |
43 |
extern "C" int pcsc_available (void); |
int pcsc_available (void); |
44 |
|
|
45 |
/* Global variables. */ |
/* Global variables. */ |
46 |
HINSTANCE glob_hinst; /* global instance for the dialogs */ |
HINSTANCE glob_hinst; /* global instance for the dialogs */ |
58 |
update_keycache (HWND hwnd) |
update_keycache (HWND hwnd) |
59 |
{ |
{ |
60 |
int err; |
int err; |
61 |
|
refresh_cache_s rcs; |
62 |
|
|
63 |
refresh_cache_s rcs = {0}; |
/* no need to rebuild the sig cache each time. */ |
64 |
rcs.kr_reload = 0; |
memset (&rcs, 0, sizeof (rcs)); |
65 |
rcs.kr_update = 1; |
rcs.kring_update = 1; |
|
rcs.tr_update = 1; |
|
66 |
err = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd, |
err = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd, |
67 |
keycache_dlg_proc, (LPARAM)&rcs); |
keycache_dlg_proc, (LPARAM)&rcs); |
68 |
if (err) { |
if (err) { |
103 |
/* Return the name of the gettext language file. */ |
/* Return the name of the gettext language file. */ |
104 |
nls = get_reg_entry_mo (); |
nls = get_reg_entry_mo (); |
105 |
if (nls != NULL) { |
if (nls != NULL) { |
106 |
set_gettext_file ("winpt", nls); |
gettext_set_file ("winpt", nls); |
107 |
free_if_alloc (nls); |
free_if_alloc (nls); |
108 |
} |
} |
109 |
} |
} |
208 |
/* check if the default key from the gpg.conf file is available in the |
/* check if the default key from the gpg.conf file is available in the |
209 |
keyring. if not, bail out because encryption won't work properly then. */ |
keyring. if not, bail out because encryption won't work properly then. */ |
210 |
static int |
static int |
211 |
check_default_key (gpg_keycache_t kc) |
check_default_key (void) |
212 |
{ |
{ |
213 |
gpgme_key_t key; |
gpgme_key_t key; |
214 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
215 |
|
gpg_keycache_t kc; |
216 |
char *defkey; |
char *defkey; |
217 |
|
|
218 |
|
kc = keycache_get_ctx (0); |
219 |
defkey = get_gnupg_default_key (); |
defkey = get_gnupg_default_key (); |
220 |
if (defkey) |
if (defkey) { |
221 |
err = gpg_keycache_find_key (kc, defkey, 0, &key); |
err = gpg_keycache_find_key (kc, defkey, 0, &key); |
222 |
else |
if (err) { |
223 |
|
free_if_alloc (defkey); |
224 |
|
return -1; |
225 |
|
} |
226 |
|
} |
227 |
|
else { |
228 |
|
/* Actually this is just a warning but we still continue. */ |
229 |
msg_box (NULL, _("No useable secret key found."), |
msg_box (NULL, _("No useable secret key found."), |
230 |
_("WinPT Warning"), MB_WARN); |
_("WinPT Warning"), MB_WARN); |
231 |
|
free_if_alloc (defkey); |
232 |
|
return 0; |
233 |
|
} |
234 |
|
|
235 |
|
/* Because the secret key listing has no information |
236 |
|
about the validity/status, we need to check the public key. */ |
237 |
|
kc = keycache_get_ctx (1); |
238 |
|
if (!gpg_keycache_find_key (kc, defkey, 0, &key) && |
239 |
|
(key->revoked || key->expired)) { |
240 |
|
msg_box (NULL, _("Default secret key is unuseable"), |
241 |
|
_("WinPT Warning"), MB_ERR); |
242 |
|
free_if_alloc (defkey); |
243 |
|
return -1; |
244 |
|
} |
245 |
free_if_alloc (defkey); |
free_if_alloc (defkey); |
246 |
return err? -1 : 0; |
return 0; |
247 |
} |
} |
248 |
|
|
249 |
|
|
250 |
/* Return the WinPT program file name (with full pathname). */ |
/* Return the WinPT program file name (with full pathname). */ |
251 |
static const char* |
static const char* |
252 |
get_prog_part (const char * fname, int use_cwd) |
get_prog_part (const char *fname, int use_cwd) |
253 |
{ |
{ |
254 |
static char program[2*MAX_PATH+1]; |
static char program[2*MAX_PATH+1]; |
255 |
char currdir[MAX_PATH+1]; |
char currdir[MAX_PATH+1]; |
256 |
char *cmd = NULL; |
char *cmd; |
257 |
int j; |
int j; |
258 |
|
|
259 |
memset (currdir, 0, DIM (currdir)); |
memset (currdir, 0, DIM (currdir)); |
296 |
} |
} |
297 |
else if (rc) { |
else if (rc) { |
298 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
299 |
_("Sorry, you need a newer GPG version.\n" |
_("A newer GPG version is needed.\n" |
300 |
"GPG version %d.%d.%d required GPG version "NEED_GPG_VERSION), |
"Current GPG version %d.%d.%d, required "NEED_GPG_VERSION), |
301 |
ma, mi, pa); |
ma, mi, pa); |
302 |
return false; |
return false; |
303 |
} |
} |
524 |
return 0; |
return 0; |
525 |
} |
} |
526 |
|
|
527 |
#ifdef _DEBUG |
#ifdef _DEBUG |
528 |
gpg_set_debug_mode (1); |
gpg_set_debug_mode (1); |
529 |
debug = 1; |
debug = 1; |
530 |
#endif |
#endif |
531 |
|
|
532 |
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]); |
533 |
ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1], |
ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1], |
571 |
memset (®_prefs, 0, sizeof (reg_prefs)); |
memset (®_prefs, 0, sizeof (reg_prefs)); |
572 |
get_reg_winpt_prefs (®_prefs); |
get_reg_winpt_prefs (®_prefs); |
573 |
reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */ |
reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */ |
574 |
gnupg_load_config (); |
if (gnupg_load_config () == -2) |
575 |
|
msg_box (NULL, _("The gpg.conf file contains the 'textmode' option\n" |
576 |
|
"which leads to broken binary output during decryption.\n" |
577 |
|
"If this is on purpose, just continue otherwise the option should be disabled."), |
578 |
|
_("WinPT Error"), MB_ERR); |
579 |
} |
} |
580 |
|
|
581 |
if (is_gpg4win_installed ()) |
if (is_gpg4win_installed ()) |
687 |
return 0; |
return 0; |
688 |
} |
} |
689 |
|
|
690 |
#ifndef WINPT_MOBILE |
#ifndef WINPT_MOBILE |
691 |
if (cmdline && (stristr (cmdline, "--enable-debug") || |
if (cmdline && (stristr (cmdline, "--enable-debug") || |
692 |
stristr (cmdline, "--debug"))) { |
stristr (cmdline, "--debug"))) { |
693 |
gpg_set_debug_mode (1); |
gpg_set_debug_mode (1); |
694 |
winpt_debug_msg (); |
winpt_debug_msg (); |
695 |
debug = 1; |
debug = 1; |
696 |
} |
} |
697 |
#endif |
#endif |
698 |
|
|
699 |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
700 |
rc = RegisterClass (&wc); |
rc = RegisterClass (&wc); |
791 |
} |
} |
792 |
} |
} |
793 |
else { |
else { |
794 |
gpg_keycache_t c, sec_c; |
gpg_keycache_t c; |
795 |
if (update_keycache (hwnd)) { |
if (update_keycache (hwnd)) { |
796 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
797 |
free_gnupg_table (); |
free_gnupg_table (); |
818 |
keycache_release (1); |
keycache_release (1); |
819 |
return 0; |
return 0; |
820 |
} |
} |
821 |
} |
} |
822 |
sec_c = keycache_get_ctx (0); |
if (check_default_key ()) { |
|
if (check_default_key (sec_c)) { |
|
823 |
char *p = get_gnupg_default_key (); |
char *p = get_gnupg_default_key (); |
824 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
825 |
_("Default key (from the GPG config file) could not be found.\n" |
_("Default key (from the GPG config file) could not be found or is unuseable.\n" |
826 |
"Please check your gpg.conf or set a new default key to correct it:\n\n" |
"The default key will be resetted and can be set later in the Key Manager again.\n\n" |
827 |
"%s: public key not found."), p? p : "[null]"); |
"%s: secret key not found."), p? p : "?"); |
828 |
set_gnupg_default_key (NULL); |
set_gnupg_default_key (NULL); |
829 |
|
free_if_alloc (p); |
830 |
} |
} |
831 |
if (count_insecure_elgkeys ()) |
if (count_insecure_elgkeys ()) |
832 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_ELGWARN, glob_hwnd, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_ELGWARN, glob_hwnd, |