22 |
#endif |
#endif |
23 |
|
|
24 |
#include <windows.h> |
#include <windows.h> |
|
#include <shlobj.h> |
|
25 |
#include <string.h> |
#include <string.h> |
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
#include <shlobj.h> |
#include <shlobj.h> |
39 |
#include "wptW32API.h" |
#include "wptW32API.h" |
40 |
#include "wptCrypto.h" |
#include "wptCrypto.h" |
41 |
|
|
42 |
#define GPG_CONF "gpg.conf" |
#define GPG_CONF "gpg.conf" |
43 |
|
#define GPG_REG_EXE "gpgProgram" /* registry name for the binary. */ |
44 |
|
#define GPG_REG_HOME "HomeDir" /* registry name of the home dir. */ |
45 |
|
|
46 |
struct gpg_watcher_s { |
struct gpg_watcher_s { |
47 |
FILETIME last_access; |
FILETIME last_access; |
62 |
|
|
63 |
|
|
64 |
/* Return the application data folder of the current user. */ |
/* Return the application data folder of the current user. */ |
65 |
static char* |
char* |
66 |
multi_gnupg_path (void) |
multi_gnupg_path (int strict) |
67 |
{ |
{ |
68 |
static char buf[256+64]; |
static char buf[256+64]; |
69 |
BOOL ec; |
BOOL ec; |
72 |
memset (buf, 0, sizeof (buf)); |
memset (buf, 0, sizeof (buf)); |
73 |
/* XXX: ec should be NOERROR (MSDN) but NOERROR is defined as '0' !? */ |
/* XXX: ec should be NOERROR (MSDN) but NOERROR is defined as '0' !? */ |
74 |
ec = SHGetSpecialFolderPath (HWND_DESKTOP, buf, CSIDL_APPDATA, TRUE); |
ec = SHGetSpecialFolderPath (HWND_DESKTOP, buf, CSIDL_APPDATA, TRUE); |
75 |
if (ec != 1) |
if (ec != 1) { |
76 |
|
log_debug ("multi_gnupg_path: SHGetSpecialFolderPath() failed\r\n", |
77 |
|
(int)GetLastError ()); |
78 |
return NULL; |
return NULL; |
79 |
|
} |
80 |
strcat (buf, "\\gnupg"); |
strcat (buf, "\\gnupg"); |
81 |
if (access (buf, 00)) |
if (strict && access (buf, 00)) |
82 |
return NULL; |
return NULL; |
83 |
return m_strdup (buf); |
return m_strdup (buf); |
84 |
} |
} |
85 |
|
|
86 |
|
|
87 |
/* Return the full path of the GnuPG application. First the registry is scanned |
/* Return the full path to the GPG home directory. First the 'HomeDir' entry |
88 |
for the entry 'HomeDir'. If it wasn't set, the default dir C:\GNUPG is used. |
from the registry is used. Then the default $APPDATA\gnupg path. */ |
|
*/ |
|
89 |
char* |
char* |
90 |
get_gnupg_path (void) |
get_gnupg_path (void) |
91 |
{ |
{ |
92 |
char *p = NULL, *path = NULL; |
char *path; |
93 |
|
|
94 |
p = get_reg_entry_gpg ("HomeDir"); |
path = get_reg_entry_gpg (GPG_REG_HOME); |
95 |
if (p) { |
if (path) { |
96 |
path = m_strdup (p); |
if (dir_exist_check (path) == 0) |
97 |
free_if_alloc (p); |
return path; |
98 |
return path; |
free_if_alloc (path); |
99 |
} |
} |
100 |
else |
path = multi_gnupg_path (1); |
101 |
return multi_gnupg_path (); |
return path; |
|
return m_strdup ("c:\\gnupg"); |
|
102 |
} |
} |
103 |
|
|
104 |
|
|
107 |
char* |
char* |
108 |
get_gnupg_cfgfile (void) |
get_gnupg_cfgfile (void) |
109 |
{ |
{ |
110 |
char *p = NULL, *optfile = NULL, *path = NULL; |
char *p = NULL; |
111 |
|
char *optfile = NULL; |
112 |
|
char *path = NULL; |
113 |
size_t nlen = 0; |
size_t nlen = 0; |
114 |
|
|
115 |
path = get_gnupg_path (); |
path = get_gnupg_path (); |
182 |
char *p; |
char *p; |
183 |
char *pgm = NULL; |
char *pgm = NULL; |
184 |
|
|
185 |
p = get_reg_entry_gpg ("gpgProgram"); |
p = get_reg_entry_gpg (GPG_REG_EXE); |
186 |
if (!p) { |
if (!p) { |
187 |
char *path = get_gnupg_path (); |
char *path = get_gnupg_path (); |
188 |
if (!path) |
if (!path) |
204 |
static char * |
static char * |
205 |
default_key_from_cache (int *ret_no_useable) |
default_key_from_cache (int *ret_no_useable) |
206 |
{ |
{ |
207 |
const char * s; |
const char *s; |
208 |
char * keyid = NULL; |
char *keyid = NULL; |
209 |
gpgme_key_t key; |
gpgme_key_t key; |
210 |
gpg_keycache_t sec = keycache_get_ctx (0); |
gpg_keycache_t sec = keycache_get_ctx (0); |
211 |
|
|
265 |
return default_key_from_cache (&no_usable); |
return default_key_from_cache (&no_usable); |
266 |
rc = parse_gpg_options (optfile, &opt); |
rc = parse_gpg_options (optfile, &opt); |
267 |
if (rc) { |
if (rc) { |
268 |
free_if_alloc( optfile ); |
free_if_alloc (optfile); |
269 |
return default_key_from_cache( &no_usable ); |
return default_key_from_cache (&no_usable); |
270 |
} |
} |
271 |
e = find_option( opt, "default-key" ); |
e = find_option( opt, "default-key" ); |
272 |
if ( e ) |
if ( e ) |
290 |
} /* get_gnupg_default_key */ |
} /* get_gnupg_default_key */ |
291 |
|
|
292 |
|
|
293 |
|
/* Check if GPG4WIN is available and if so, use the |
294 |
|
install path to figure out where the gpg.exe is. */ |
295 |
|
char* |
296 |
|
check_for_gpg4win (void) |
297 |
|
{ |
298 |
|
return get_reg_entry_gpg4win ("gpg.exe"); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
/* Check if the gpg application (exe file) is available. */ |
/* Check if the gpg application (exe file) is available. */ |
303 |
int |
int |
304 |
check_gnupg_prog (void) |
check_gnupg_prog (void) |
305 |
{ |
{ |
306 |
char *pgm = NULL; |
char *gpgexe = NULL; |
307 |
int rc = 0; |
int rc = 0; |
308 |
|
|
309 |
pgm = get_gnupg_prog (); |
gpgexe = get_gnupg_prog (); |
310 |
if (!pgm) |
if (!gpgexe || file_exist_check (gpgexe)) { |
311 |
rc = WPTERR_GPG_EXEFILE; |
free_if_alloc (gpgexe); |
312 |
if (file_exist_check (pgm)) |
gpgexe = check_for_gpg4win (); |
313 |
rc = WPTERR_GPG_EXEFILE; |
if (!gpgexe || file_exist_check (gpgexe)) |
314 |
free_if_alloc (pgm); |
rc = WPTERR_GPG_EXEFILE; |
315 |
|
else |
316 |
|
set_reg_entry_gpg (GPG_REG_EXE, gpgexe); |
317 |
|
} |
318 |
|
free_if_alloc (gpgexe); |
319 |
return rc; |
return rc; |
320 |
} |
} |
321 |
|
|
337 |
tmp[i] = 0; buf++; |
tmp[i] = 0; buf++; |
338 |
*minor = atol (tmp); |
*minor = atol (tmp); |
339 |
i=0; |
i=0; |
340 |
while (buf && isdigit( *buf ) && i < 8) |
while (buf && isdigit (*buf) && i < 8) |
341 |
tmp[i++] = *buf++; |
tmp[i++] = *buf++; |
342 |
tmp[i] = 0; |
tmp[i] = 0; |
343 |
*patch = atol (tmp); |
*patch = atol (tmp); |
353 |
{ |
{ |
354 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
355 |
gpgme_engine_info_t inf; |
gpgme_engine_info_t inf; |
356 |
char * eng = NULL; |
char *eng = NULL; |
357 |
int major=0, minor=0, patch=0; |
int major=0, minor=0, patch=0; |
358 |
int rc; |
int rc = 1; |
359 |
|
|
360 |
gpgme_new (&ctx); |
gpgme_new (&ctx); |
361 |
inf = gpgme_ctx_get_engine_info (ctx); |
inf = gpgme_ctx_get_engine_info (ctx); |
363 |
gpgme_release (ctx); |
gpgme_release (ctx); |
364 |
return -1; |
return -1; |
365 |
} |
} |
366 |
|
|
367 |
/* We need to exec GPG again to find out if IDEA is available. */ |
/* We need to exec GPG again to find out if IDEA is available. */ |
368 |
if (gpg_get_version (&eng)) |
if (gpg_get_version (&eng)) |
369 |
return -1; |
return -1; |
370 |
if (strstr (eng, "IDEA")) |
if (strstr (eng, "IDEA")) |
371 |
idea_available = 1; |
idea_available = 1; |
372 |
free (eng); |
free (eng); |
373 |
rc = parse_version_nr( inf->version, &major, &minor, &patch ); |
rc = parse_version_nr (inf->version, &major, &minor, &patch); |
374 |
if( rc ) { |
if (rc) { |
375 |
gpgme_release (ctx); |
gpgme_release (ctx); |
376 |
return rc; |
return rc; |
377 |
} |
} |
378 |
|
|
379 |
/* FIXME: This check is wrong! */ |
if (major > *r_major) |
|
if (major < *r_major || minor < *r_minor) |
|
|
rc = 1; |
|
|
else { |
|
|
if (patch < *r_patch) |
|
|
rc = 1; |
|
380 |
rc = 0; |
rc = 0; |
381 |
} |
else if (major == *r_major && minor > *r_minor) |
382 |
|
rc = 0; |
383 |
|
else if (major == *r_major && minor == *r_minor && |
384 |
|
patch >= *r_patch) |
385 |
|
rc = 0; |
386 |
|
|
387 |
*r_major = major; |
*r_major = major; |
388 |
*r_minor = minor; |
*r_minor = minor; |
389 |
*r_patch = patch; |
*r_patch = patch; |
439 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
440 |
else |
else |
441 |
secring_ok = 1; |
secring_ok = 1; |
442 |
|
|
443 |
if (!pubring_ok || !secring_ok) { |
if (!pubring_ok || !secring_ok) { |
444 |
optfile = get_gnupg_cfgfile (); |
optfile = get_gnupg_cfgfile (); |
445 |
if (!optfile) |
if (!optfile) |
446 |
return WPTERR_GPG_KEYRINGS; |
return WPTERR_GPG_KEYRINGS; |
447 |
rc = file_exist_check (optfile); |
rc = file_exist_check (optfile); |
448 |
if (!rc && get_file_size(optfile) > 0) { |
if (!rc && get_file_size (optfile) > 0) { |
449 |
rc = check_gnupg_cfgfile (optfile, &secrings, &pubrings); |
rc = check_gnupg_cfgfile (optfile, &secrings, &pubrings); |
450 |
if (!rc && secrings && pubrings) { |
if (!rc && secrings && pubrings) { |
451 |
free_if_alloc (optfile); |
free_if_alloc (optfile); |
472 |
FILE *fp; |
FILE *fp; |
473 |
char *s, *optfile; |
char *s, *optfile; |
474 |
|
|
475 |
s = get_gnupg_path( ); |
s = get_gnupg_path (); |
476 |
if( s == NULL ) |
if( s == NULL ) |
477 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
478 |
optfile = make_filename( s, GPG_CONF, NULL ); |
optfile = make_filename (s, GPG_CONF, NULL); |
479 |
fp = fopen( optfile, "wb" ); |
fp = fopen( optfile, "wb" ); |
480 |
if( fp == NULL ) { |
if( fp == NULL ) { |
481 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
666 |
if (ctx->last_access.dwHighDateTime != ctx->access.dwHighDateTime && |
if (ctx->last_access.dwHighDateTime != ctx->access.dwHighDateTime && |
667 |
ctx->last_access.dwLowDateTime != ctx->access.dwLowDateTime) |
ctx->last_access.dwLowDateTime != ctx->access.dwLowDateTime) |
668 |
ctx->modified = 1; |
ctx->modified = 1; |
669 |
|
|
670 |
|
/* XXX: find a better way. without it, winpt --keymanager loads |
671 |
|
the key cache twice. */ |
672 |
|
if (ctx->last_access.dwLowDateTime == 0) |
673 |
|
ctx->modified = 0; |
674 |
|
|
675 |
ctx->last_access.dwLowDateTime = ctx->access.dwLowDateTime; |
ctx->last_access.dwLowDateTime = ctx->access.dwLowDateTime; |
676 |
ctx->last_access.dwHighDateTime = ctx->access.dwHighDateTime; |
ctx->last_access.dwHighDateTime = ctx->access.dwHighDateTime; |
777 |
|
|
778 |
/* XXX: does not work with write-protected floppies */ |
/* XXX: does not work with write-protected floppies */ |
779 |
static int |
static int |
780 |
my_access (const char * fname) |
my_access (const char *fname) |
781 |
{ |
{ |
782 |
HANDLE hd; |
HANDLE hd; |
783 |
hd = CreateFile (fname, GENERIC_WRITE, FILE_SHARE_WRITE, |
hd = CreateFile (fname, GENERIC_WRITE, FILE_SHARE_WRITE, |
789 |
} |
} |
790 |
|
|
791 |
|
|
792 |
|
/* Check the file permissions of the public keyring. |
793 |
|
If @showmsg is 1 output a message in case of errors. |
794 |
|
Return value: 1 if read-only attribute |
795 |
|
2 if file is opened by another process exclusively. */ |
796 |
int |
int |
797 |
gpg_check_permissions (int showmsg) |
gpg_check_permissions (int showmsg) |
798 |
{ |
{ |
799 |
char * p, * name = NULL; |
char *p = NULL; |
800 |
|
char *name = NULL; |
801 |
int failed = 0, ans=0, attrs=0; |
int failed = 0, ans=0, attrs=0; |
802 |
|
|
803 |
p = get_gnupg_path (); |
p = get_gnupg_path (); |
804 |
check_keyring (&p); |
if (check_keyring (&p) && p) { |
|
if (p) { |
|
805 |
name = make_filename (p, "pubring", "gpg"); |
name = make_filename (p, "pubring", "gpg"); |
|
free_if_alloc (p); |
|
806 |
if ((attrs=GetFileAttributes (name)) & FILE_ATTRIBUTE_READONLY) { |
if ((attrs=GetFileAttributes (name)) & FILE_ATTRIBUTE_READONLY) { |
807 |
ans = msg_box (NULL, |
ans = msg_box (NULL, |
808 |
_("The selected keyring has the read-only file\n" |
_("The selected keyring has the read-only file\n" |
818 |
} |
} |
819 |
} |
} |
820 |
else if (ans == IDNO) { |
else if (ans == IDNO) { |
821 |
/* |
/* All commands with write access will be disabled. */ |
|
msg_box (NULL, _("All commands with write access to the keyring\n" |
|
|
"will be disabled."), _("GPG Information"), MB_INFO); |
|
|
*/ |
|
822 |
failed = 1; |
failed = 1; |
823 |
} |
} |
824 |
} |
} |
834 |
failed = 2; |
failed = 2; |
835 |
} |
} |
836 |
} |
} |
837 |
|
free_if_alloc (p); |
838 |
free_if_alloc (name); |
free_if_alloc (name); |
839 |
return failed; |
return failed; |
840 |
} /* gpg_check_permissions */ |
} |
841 |
|
|
842 |
|
|
843 |
/* Check the GPG home dir. If all methods failed, try to |
/* Check the GPG home dir. First try to read the 'HomeDir' registry entry, |
844 |
create the default folder. */ |
then check for $APPDATA\gnupg. Create the dir if it does not exists. */ |
845 |
static int |
int |
846 |
check_homedir (void) |
gnupg_check_homedir (void) |
847 |
{ |
{ |
848 |
char *homedir = NULL; |
char *homedir = NULL; |
849 |
int yes = 0; |
int val = 0; |
850 |
|
int rc = 0; |
851 |
|
|
852 |
homedir = get_reg_entry_gpg ("HomeDir"); |
homedir = get_reg_entry_gpg (GPG_REG_HOME); |
|
if (!homedir) |
|
|
homedir = multi_gnupg_path (); |
|
853 |
if (!homedir) |
if (!homedir) |
854 |
homedir = m_strdup ("c:\\gnupg"); |
homedir = multi_gnupg_path (0); |
855 |
if (homedir) { |
if (homedir) { |
856 |
if (GetFileAttributes (homedir) == 0xFFFFFFFF) { |
if (GetFileAttributes (homedir) == 0xFFFFFFFF) { |
857 |
yes = log_box (_("Preferences"), MB_YESNO, |
val = log_box (_("Preferences"), MB_YESNO, |
858 |
_("%s does not exit.\n" |
_("%s does not exit.\n" |
859 |
"Do you want to create this directory?"), homedir); |
"Do you want to create this directory?"), homedir); |
860 |
if (yes == IDYES) { |
if (val == IDYES) { |
861 |
BOOL ec = CreateDirectory (homedir, NULL); |
if (!CreateDirectory (homedir, NULL)) |
862 |
free_if_alloc (homedir); |
rc = WPTERR_DIR_CREAT; |
|
if (ec == FALSE) |
|
|
return WPTERR_DIR_CREAT; |
|
|
return 0; |
|
863 |
} |
} |
864 |
return WPTERR_DIR_OPEN; |
else |
865 |
} |
rc = WPTERR_DIR_OPEN; |
|
free_if_alloc (homedir); |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
gnupg_check_homedir (void) |
|
|
{ |
|
|
char *homedir = NULL; |
|
|
char *prog = NULL; |
|
|
int rc = 0; |
|
|
|
|
|
rc = check_homedir (); |
|
|
if (rc) |
|
|
return rc; |
|
|
if ((homedir = get_reg_entry_gpg ("HomeDir")) && |
|
|
!(prog = get_reg_entry_gpg ("gpgProgram" ))) { |
|
|
prog = make_filename (homedir, "gpg", "exe"); |
|
|
if (file_exist_check (prog) == 0) { |
|
|
rc = set_reg_entry_gpg ("gpgProgram", prog); |
|
|
if (rc) |
|
|
goto fail; |
|
866 |
} |
} |
867 |
free_if_alloc (homedir); |
free_if_alloc (homedir); |
|
free_if_alloc (prog); |
|
|
return rc; |
|
868 |
} |
} |
|
if ((prog = get_reg_entry_gpg ("gpgProgram")) |
|
|
&& file_exist_check (prog)) { |
|
|
free_if_alloc (prog); |
|
|
homedir = get_reg_entry_gpg ("HomeDir"); |
|
|
if (!homedir) { |
|
|
rc = WPTERR_GENERAL; |
|
|
goto fail; |
|
|
} |
|
|
prog = make_filename (homedir, "gpg", "exe"); |
|
|
if (file_exist_check (prog) == 0) { |
|
|
rc = set_reg_entry_gpg ("gpgProgram", prog); |
|
|
if (rc) |
|
|
goto fail; |
|
|
free_if_alloc (prog); |
|
|
return rc; |
|
|
} |
|
|
} |
|
|
|
|
|
/* Change the return code if homedir doesn't exist or if the program |
|
|
doesn't exist. Note that exist_checks return 0 to suggest existance. */ |
|
|
if ((!homedir || dir_exist_check (homedir))) |
|
|
rc = WPTERR_GENERAL; |
|
|
|
|
|
fail: |
|
|
free_if_alloc (homedir); |
|
|
free_if_alloc (prog); |
|
869 |
return rc; |
return rc; |
870 |
} /* gnupg_check_homedir */ |
} |
871 |
|
|
872 |
|
|
873 |
int |
int |
883 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
884 |
hwnd = GetDesktopWindow (); |
hwnd = GetDesktopWindow (); |
885 |
|
|
886 |
pring = get_filename_dlg (hwnd, FILE_OPEN, _("Please choose your public keyring"), |
pring = get_fileopen_dlg (hwnd, _("Please choose your public keyring"), |
887 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"),NULL); |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"),NULL); |
888 |
if (!pring) { |
if (!pring) { |
889 |
msg_box (hwnd, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR); |
msg_box (hwnd, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR); |
903 |
} |
} |
904 |
free_if_alloc (file); |
free_if_alloc (file); |
905 |
|
|
906 |
sring = get_filename_dlg (hwnd, FILE_OPEN, _("Please choose your secret keyring"), |
sring = get_fileopen_dlg (hwnd, _("Please choose your secret keyring"), |
907 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), NULL); |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), NULL); |
908 |
if (!sring) { |
if (!sring) { |
909 |
msg_box( NULL, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR ); |
msg_box( NULL, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR ); |
927 |
} /* gnupg_import_keyrings */ |
} /* gnupg_import_keyrings */ |
928 |
|
|
929 |
|
|
930 |
|
/* Backup the gpg.conf file. */ |
931 |
void |
void |
932 |
gnupg_backup_options (void) |
gnupg_backup_options (void) |
933 |
{ |
{ |
935 |
char bak[512]; |
char bak[512]; |
936 |
|
|
937 |
cfgfile = get_gnupg_cfgfile (); |
cfgfile = get_gnupg_cfgfile (); |
938 |
if (cfgfile == NULL) |
if (!cfgfile) |
939 |
return; |
return; |
940 |
_snprintf (bak, DIM (bak)-1, "%s.bak", cfgfile); |
_snprintf (bak, DIM (bak)-1, "%s.bak", cfgfile); |
941 |
CopyFile (cfgfile, bak, FALSE); |
CopyFile (cfgfile, bak, FALSE); |
942 |
free_if_alloc (cfgfile); |
free_if_alloc (cfgfile); |
943 |
} /* gnupg_backup_options */ |
} |
|
|
|
944 |
|
|
945 |
|
|
946 |
static int |
static int |
968 |
} /* backup_one_file */ |
} /* backup_one_file */ |
969 |
|
|
970 |
|
|
971 |
|
/* Figure out first public keyring which is not empty. |
972 |
|
Return value: 1 on success. */ |
973 |
static int |
static int |
974 |
check_keyring (char ** r_path) |
check_keyring (char **r_path) |
975 |
{ |
{ |
976 |
char * p; |
char *p; |
977 |
char * opt, * name; |
char *opt; |
978 |
|
char *name; |
979 |
|
|
980 |
if (!*r_path) |
if (!*r_path) |
981 |
return 0; |
return 0; |
982 |
p = make_filename (*r_path, "pubring", "gpg"); |
p = make_filename (*r_path, "pubring", "gpg"); |
983 |
if (!p || get_file_size (p) > 0) |
if (!p || get_file_size (p) <= 0) |
984 |
return 0; |
return 0; |
985 |
|
|
986 |
opt = get_gnupg_cfgfile (); |
opt = get_gnupg_cfgfile (); |
992 |
if (!name) |
if (!name) |
993 |
return 0; |
return 0; |
994 |
p = strrchr (name, '\\'); |
p = strrchr (name, '\\'); |
995 |
if (!p) |
if (!p) { |
|
{ |
|
996 |
free_if_alloc (name); |
free_if_alloc (name); |
997 |
return 0; |
return 0; |
998 |
} |
} |
1005 |
} |
} |
1006 |
|
|
1007 |
|
|
1008 |
|
/* Return a temp name based on the day of the week. */ |
1009 |
static char* |
static char* |
1010 |
get_backup_name (const char *templ) |
get_backup_name (const char *templ) |
1011 |
{ |
{ |
1012 |
struct tm *tm; |
struct tm *tm; |
1013 |
char *p; |
char *p; |
1014 |
|
time_t t; |
1015 |
|
|
1016 |
time_t t = time (NULL); |
t = time (NULL); |
1017 |
tm = localtime (&t); |
tm = localtime (&t); |
1018 |
p = new char [strlen (templ) + 8 + 1]; |
p = new char [strlen (templ) + 8 + 1]; |
1019 |
if (!p) |
if (!p) |
1023 |
} |
} |
1024 |
|
|
1025 |
|
|
1026 |
|
/* Make backups of all keyrings. The public key ring is |
1027 |
|
rotated like this pubring-%d.gpg. */ |
1028 |
void |
void |
1029 |
gnupg_backup_keyrings (void) |
gnupg_backup_keyrings (void) |
1030 |
{ |
{ |
1035 |
if (!reg_prefs.auto_backup) |
if (!reg_prefs.auto_backup) |
1036 |
return; |
return; |
1037 |
bakmode = reg_prefs.backup.mode; |
bakmode = reg_prefs.backup.mode; |
1038 |
srcpath = get_gnupg_path (); |
srcpath = get_gnupg_path (); |
1039 |
check_keyring (&srcpath); |
check_keyring (&srcpath); |
1040 |
if (bakmode == 1) { |
if (bakmode == 1) { |
1041 |
dstpath = get_gnupg_path (); |
dstpath = multi_gnupg_path (1); |
1042 |
check_keyring (&dstpath); |
check_keyring (&dstpath); |
1043 |
} |
} |
1044 |
else if (bakmode == 2) { |
else if (bakmode == 2) { |
1045 |
char * tmpfile; |
char *tmpfile; |
1046 |
FILE * fp; |
FILE *fp; |
1047 |
|
|
1048 |
dstpath = m_strdup (reg_prefs.backup.path); |
dstpath = m_strdup (reg_prefs.backup.path); |
1049 |
if (!dstpath) |
if (!dstpath) |
1057 |
else { |
else { |
1058 |
rc = 0; |
rc = 0; |
1059 |
fclose (fp); |
fclose (fp); |
1060 |
unlink (tmpfile); |
remove (tmpfile); |
1061 |
} |
} |
1062 |
free_if_alloc (tmpfile); |
free_if_alloc (tmpfile); |
1063 |
if (!fp || rc == IDCANCEL) |
if (!fp || rc == IDCANCEL) |
1074 |
free_if_alloc (name); |
free_if_alloc (name); |
1075 |
free_if_alloc (srcpath); |
free_if_alloc (srcpath); |
1076 |
free_if_alloc (dstpath); |
free_if_alloc (dstpath); |
1077 |
} /* gnupg_backup_keyrings */ |
} |
1078 |
|
|
1079 |
|
|
1080 |
/* Display GPG error from file if possible. */ |
/* Display GPG error from file if possible. */ |
1092 |
return; |
return; |
1093 |
fp = fopen( tmpath, "rb" ); |
fp = fopen( tmpath, "rb" ); |
1094 |
if (!fp) { |
if (!fp) { |
1095 |
msg_box( NULL, _("No GPG error description available."), _("GPG Error"), MB_INFO ); |
msg_box (NULL, _("No GPG error description available."), |
1096 |
|
_("GPG Error"), MB_INFO); |
1097 |
return; |
return; |
1098 |
} |
} |
1099 |
errstr = new char[size+1]; |
errstr = new char[size+1]; |