41 |
#include "wptCardEdit.h" |
#include "wptCardEdit.h" |
42 |
#include "wptCrypto.h" |
#include "wptCrypto.h" |
43 |
|
|
44 |
|
void remove_crit_file_attrs (const char *fname, int force); |
45 |
|
|
46 |
|
|
47 |
HINSTANCE glob_hinst; /* global instance for the dialogs */ |
HINSTANCE glob_hinst; /* global instance for the dialogs */ |
48 |
HWND glob_hwnd; /* global window handle for the dialogs */ |
HWND glob_hwnd; /* global window handle for the dialogs */ |
70 |
/* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */ |
/* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */ |
71 |
void |
void |
72 |
gpg_set_debug_mode (int val) |
gpg_set_debug_mode (int val) |
73 |
{ |
{ |
74 |
|
/* XXX: create the file in $user\$temp */ |
75 |
if (val) |
if (val) |
76 |
putenv ("GPGME_DEBUG=5:gpgme.dbg"); |
putenv ("GPGME_DEBUG=5:gpgme.dbg"); |
77 |
else |
else |
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
|
/* Return true if the GPG environment is useable. */ |
109 |
|
static bool |
110 |
|
gpg_prefs_ok (void) |
111 |
|
{ |
112 |
|
char *p; |
113 |
|
|
114 |
|
p = get_reg_entry_gpg4win ("gpg.exe"); |
115 |
|
if (!p || file_exist_check (p) != 0) { |
116 |
|
free_if_alloc (p); |
117 |
|
p = get_reg_entry_gpg ("gpgProgram"); |
118 |
|
if (!p || file_exist_check (p) != 0) { |
119 |
|
free_if_alloc (p); |
120 |
|
return false; |
121 |
|
} |
122 |
|
} |
123 |
|
free_if_alloc (p); |
124 |
|
p = get_reg_entry_gpg4win (NULL); |
125 |
|
if (!p || dir_exist_check (p) != 0) { |
126 |
|
free_if_alloc (p); |
127 |
|
p = get_reg_entry_gpg ("HomeDir"); |
128 |
|
if (!p || dir_exist_check (p) != 0) { |
129 |
|
free_if_alloc (p); |
130 |
|
return false; |
131 |
|
} |
132 |
|
} |
133 |
|
free_if_alloc (p); |
134 |
|
return true; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
/* Check gpg files if they are read-only and ask the user |
139 |
|
if this should be corrected. */ |
140 |
|
static void |
141 |
|
check_readonly_attr (const char *homedir) |
142 |
|
{ |
143 |
|
const char *files[] = {"pubring.gpg", "secring.gpg", "trustdb.gpg", NULL}; |
144 |
|
char *file; |
145 |
|
int i; |
146 |
|
|
147 |
|
for (i=0; files[i] != NULL; i++) { |
148 |
|
file = make_filename (homedir, files[i], NULL); |
149 |
|
remove_crit_file_attrs (file, 0); |
150 |
|
free_if_alloc (file); |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
/* Load the GPG environment. On the first start, some |
/* Load the GPG environment. On the first start, some |
156 |
checks are performed to find out in what state GPG is. |
checks are performed to find out in what state GPG is. |
157 |
Return value: 0 everything OK. |
Return value: 0 everything OK. |
172 |
return (1); |
return (1); |
173 |
} |
} |
174 |
free_if_alloc (p); |
free_if_alloc (p); |
175 |
p = multi_gnupg_path (0); |
|
176 |
|
p = get_reg_entry_gpg ("HomeDir"); |
177 |
|
if (!p || dir_exist_check (p) != 0) { |
178 |
|
free_if_alloc (p); |
179 |
|
p = multi_gnupg_path (0); |
180 |
|
} |
181 |
if (p && dir_exist_check (p)) { |
if (p && dir_exist_check (p)) { |
182 |
memset (&sec_attr, 0, sizeof (sec_attr)); |
memset (&sec_attr, 0, sizeof (sec_attr)); |
183 |
sec_attr.nLength = sizeof (sec_attr); |
sec_attr.nLength = sizeof (sec_attr); |
188 |
return (2); |
return (2); |
189 |
} |
} |
190 |
} |
} |
191 |
|
check_readonly_attr (p); |
192 |
pkr = make_filename (p, "pubring", "gpg"); |
pkr = make_filename (p, "pubring", "gpg"); |
193 |
free_if_alloc (p); |
free_if_alloc (p); |
194 |
if (!pkr) |
if (!pkr) |
369 |
reg_prefs.auto_backup = 0; |
reg_prefs.auto_backup = 0; |
370 |
reg_prefs.cache_time = 0; |
reg_prefs.cache_time = 0; |
371 |
reg_prefs.expert = 0; |
reg_prefs.expert = 0; |
|
reg_prefs.keylist_mode = 1; |
|
372 |
reg_prefs.kserv_conf = m_strdup ("keyserver.conf"); |
reg_prefs.kserv_conf = m_strdup ("keyserver.conf"); |
373 |
reg_prefs.no_zip_mmedia = 1; |
reg_prefs.no_zip_mmedia = 1; |
374 |
reg_prefs.use_tmpfiles = 1; |
reg_prefs.use_tmpfiles = 1; |
377 |
} |
} |
378 |
|
|
379 |
|
|
380 |
|
void |
381 |
|
set_default_keyserver (void) |
382 |
|
{ |
383 |
|
char *host = get_reg_entry_keyserver ("Default"); |
384 |
|
char *str_port = get_reg_entry_keyserver ("Default_Port"); |
385 |
|
WORD port = HKP_PORT; |
386 |
|
|
387 |
|
if (!host) |
388 |
|
keyserver_set_default (NULL, 0); |
389 |
|
else { |
390 |
|
if (str_port && *str_port) |
391 |
|
port = atoi (str_port); |
392 |
|
keyserver_set_default (host, port); |
393 |
|
} |
394 |
|
free_if_alloc (host); |
395 |
|
free_if_alloc (str_port); |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
/* Main entry point. */ |
/* Main entry point. */ |
400 |
int WINAPI |
int WINAPI |
401 |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
471 |
mobile = 1; |
mobile = 1; |
472 |
} |
} |
473 |
|
|
474 |
set_default_kserver (); |
set_default_keyserver (); |
475 |
load_gettext (winpt_inst_found); |
load_gettext (winpt_inst_found); |
476 |
|
|
477 |
if (!mobile) { |
if (!mobile) { |
489 |
reg_prefs.use_tmpfiles = 1; /* default */ |
reg_prefs.use_tmpfiles = 1; /* default */ |
490 |
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 */ |
491 |
get_reg_winpt_prefs (®_prefs); |
get_reg_winpt_prefs (®_prefs); |
|
if (!reg_prefs.no_hotkeys) |
|
|
hotkeys_modify (); |
|
492 |
gnupg_load_config (); |
gnupg_load_config (); |
493 |
} |
} |
494 |
|
|
503 |
winpt_strerror (rc)); |
winpt_strerror (rc)); |
504 |
s = get_fileopen_dlg (GetActiveWindow (), |
s = get_fileopen_dlg (GetActiveWindow (), |
505 |
_("Select GPG Public Keyring"), |
_("Select GPG Public Keyring"), |
506 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
"GPG Keyrings (*.gpg)\0*.gpg\0\0", |
507 |
NULL); |
NULL); |
508 |
if (s != NULL) { |
if (s != NULL) { |
509 |
size_t n; |
size_t n; |
662 |
} |
} |
663 |
|
|
664 |
if (first_start) { |
if (first_start) { |
|
struct first_start_s fs; |
|
665 |
struct genkey_s c; |
struct genkey_s c; |
666 |
|
int choice; |
667 |
HWND h; |
HWND h; |
668 |
start: |
start: |
669 |
h = GetDesktopWindow (); |
h = GetDesktopWindow (); |
670 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h, |
if (!gpg_prefs_ok ()) |
671 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h, |
672 |
gpgprefs_dlg_proc, 0); |
gpgprefs_dlg_proc, 0); |
673 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h, |
choice = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h, |
674 |
first_run_dlg_proc, (LPARAM)&fs); |
first_run_dlg_proc, 0); |
675 |
switch (fs.choice) { |
switch (choice) { |
676 |
case SETUP_KEYGEN: |
case SETUP_KEYGEN: |
677 |
c.interactive = 1; |
c.interactive = 1; |
678 |
c.first_start = 1; |
c.first_start = 1; |
690 |
} |
} |
691 |
break; |
break; |
692 |
|
|
693 |
case -1: /* Cancel/Abort. */ |
case 0: /* Cancel/Abort. */ |
694 |
|
default: |
695 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
696 |
free_gnupg_table (); |
free_gnupg_table (); |
697 |
return 0; |
return 0; |
698 |
} |
} |
699 |
update_keycache (hwnd); |
update_keycache (hwnd); |
700 |
check_crypto_engine (); |
if (!check_crypto_engine ()) { |
701 |
|
DestroyWindow (hwnd); |
702 |
|
free_gnupg_table (); |
703 |
|
return 0; |
704 |
|
} |
705 |
} |
} |
706 |
else { |
else { |
707 |
gpg_keycache_t c; |
gpg_keycache_t c, sec_c; |
708 |
update_keycache (hwnd); |
update_keycache (hwnd); |
709 |
c = keycache_get_ctx (1); |
c = keycache_get_ctx (1); |
710 |
if (!c || !gpg_keycache_get_size (c)) { |
if (!c || !gpg_keycache_get_size (c)) { |
726 |
return 0; |
return 0; |
727 |
} |
} |
728 |
} |
} |
729 |
if (check_default_key (c)) { |
sec_c = keycache_get_ctx (0); |
730 |
|
if (check_default_key (sec_c)) { |
731 |
char *p = get_gnupg_default_key (); |
char *p = get_gnupg_default_key (); |
732 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
733 |
_("Default key from the GPG options file could not be found.\n" |
_("Default key (from the GPG config file) could not be found.\n" |
734 |
"Please check your gpg.conf (options) to correct this:\n\n" |
"Please check your gpg.conf or set a new default key to correct it:\n\n" |
735 |
"%s: public key not found."), p? p : "[null]"); |
"%s: public key not found."), p? p : "[null]"); |
736 |
free_if_alloc (p); |
free_if_alloc (p); |
737 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |