67 |
strcat (buf, "\\gnupg"); |
strcat (buf, "\\gnupg"); |
68 |
if (access (buf, 00)) |
if (access (buf, 00)) |
69 |
return NULL; |
return NULL; |
70 |
return buf; |
return m_strdup (buf); |
71 |
} |
} |
72 |
|
|
73 |
/* |
/* |
77 |
char* |
char* |
78 |
get_gnupg_path (void) |
get_gnupg_path (void) |
79 |
{ |
{ |
80 |
char *p = NULL, *path = NULL; |
char *p = NULL, *path = NULL; |
81 |
|
|
82 |
p = get_reg_entry_gpg ("HomeDir"); |
p = get_reg_entry_gpg ("HomeDir"); |
83 |
if (p) { |
if (p) { |
85 |
free_if_alloc (p); |
free_if_alloc (p); |
86 |
return path; |
return path; |
87 |
} |
} |
88 |
else { |
else |
89 |
p = multi_gnupg_path (); |
return multi_gnupg_path (); |
|
if (p) |
|
|
return m_strdup (p); |
|
|
} |
|
90 |
return m_strdup ("c:\\gnupg"); |
return m_strdup ("c:\\gnupg"); |
91 |
} /* get_gnupg_path */ |
} /* get_gnupg_path */ |
92 |
|
|
161 |
* appended string 'gpg.exe' is used. |
* appended string 'gpg.exe' is used. |
162 |
*/ |
*/ |
163 |
char* |
char* |
164 |
get_gnupg_prog( void ) |
get_gnupg_prog (void) |
165 |
{ |
{ |
166 |
char *p, *path, *pgm = NULL; |
char *p, *path, *pgm = NULL; |
167 |
size_t nlen = 0; |
size_t nlen = 0; |
193 |
if (!sec) |
if (!sec) |
194 |
BUG (0); |
BUG (0); |
195 |
gpgme_keycache_rewind (sec); |
gpgme_keycache_rewind (sec); |
196 |
while (!gpgme_keycache_next_key (sec, 1, &key)) |
while (!gpgme_keycache_next_key (sec, 1, &key)) { |
197 |
{ |
if (key_is_useable (key)) { |
198 |
if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_USABLE, NULL, 0)) |
s = key->subkeys->keyid; |
|
{ |
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0); |
|
199 |
if (s) |
if (s) |
200 |
keyid = m_strdup (s+8); |
keyid = m_strdup (s+8); |
201 |
break; |
break; |
202 |
} |
} |
203 |
} |
} |
204 |
if (!keyid) |
if (!keyid) { |
|
{ |
|
205 |
*ret_no_useable = 1; |
*ret_no_useable = 1; |
206 |
msg_box( NULL, _("No useable secret key found."), _("GPG Error"), MB_ERR); |
msg_box( NULL, _("No useable secret key found."), _("GPG Error"), MB_ERR); |
207 |
} |
} |
299 |
int |
int |
300 |
check_gnupg_engine (int * r_major, int * r_minor, int * r_patch) |
check_gnupg_engine (int * r_major, int * r_minor, int * r_patch) |
301 |
{ |
{ |
302 |
gpgme_error_t err; |
gpgme_ctx_t ctx; |
303 |
|
gpgme_engine_info_t inf; |
304 |
char * eng = NULL; |
char * eng = NULL; |
305 |
int major=0, minor=0, patch=0; |
int major=0, minor=0, patch=0; |
306 |
int rc; |
int rc; |
307 |
|
|
308 |
err = gpgme_op_version( &eng ); |
gpgme_new (&ctx); |
309 |
if( err ) |
inf = gpgme_ctx_get_engine_info (ctx); |
310 |
|
if (!inf) { |
311 |
|
gpgme_release (ctx); |
312 |
return -1; |
return -1; |
313 |
|
} |
314 |
if( strstr( eng, "IDEA" ) ) |
if( strstr( eng, "IDEA" ) ) |
315 |
idea_available = 1; |
idea_available = 1; |
316 |
rc = parse_version_nr( eng, &major, &minor, &patch ); |
rc = parse_version_nr( inf->version, &major, &minor, &patch ); |
317 |
free( eng ); eng = NULL; |
if( rc ) { |
318 |
if( rc ) |
gpgme_release (ctx); |
319 |
return rc; |
return rc; |
320 |
|
} |
321 |
if( major < *r_major |
if( major < *r_major |
322 |
|| minor < *r_minor) |
|| minor < *r_minor) |
323 |
rc = 1; |
rc = 1; |
437 |
* Return the contents of the options file as a char buf. |
* Return the contents of the options file as a char buf. |
438 |
*/ |
*/ |
439 |
char * |
char * |
440 |
get_gnupg_config( void ) |
get_gnupg_config (void) |
441 |
{ |
{ |
442 |
FILE * fp; |
FILE * fp; |
443 |
char * p = NULL, * optfile = NULL; |
char * p = NULL, * optfile = NULL; |
444 |
int fsize, rc = 0; |
int fsize, rc = 0; |
445 |
|
|
446 |
optfile = get_gnupg_cfgfile( ); |
optfile = get_gnupg_cfgfile (); |
447 |
if( optfile == NULL ) |
if( optfile == NULL ) |
448 |
return NULL; |
return NULL; |
449 |
fsize = get_file_size( optfile ); |
fsize = get_file_size( optfile ); |
902 |
|
|
903 |
|
|
904 |
void |
void |
905 |
gnupg_backup_options (int keep) |
gnupg_backup_options (void) |
906 |
{ |
{ |
907 |
char *optfile = NULL; |
char *cfgfile = NULL; |
908 |
char bak[1024]; |
char bak[512]; |
909 |
|
|
910 |
optfile = get_gnupg_cfgfile (); |
cfgfile = get_gnupg_cfgfile (); |
911 |
if (optfile == NULL) |
if (cfgfile == NULL) |
912 |
return; |
return; |
913 |
if (keep) |
_snprintf (bak, DIM (bak)-1, "%s.bak", cfgfile); |
914 |
_snprintf (bak, DIM (bak)-1, "%s.old", optfile); |
CopyFile (cfgfile, bak, FALSE); |
915 |
else |
free_if_alloc (cfgfile); |
|
_snprintf (bak, DIM (bak)-1, "%s.O", optfile); |
|
|
CopyFile (optfile, bak, keep); |
|
|
free_if_alloc (optfile); |
|
916 |
} /* gnupg_backup_options */ |
} /* gnupg_backup_options */ |
917 |
|
|
918 |
|
|
977 |
} |
} |
978 |
|
|
979 |
|
|
980 |
|
static char* |
981 |
|
get_backup_name (const char *templ) |
982 |
|
{ |
983 |
|
struct tm *tm; |
984 |
|
char *p; |
985 |
|
|
986 |
|
time_t t = time (NULL); |
987 |
|
tm = localtime (&t); |
988 |
|
p = new char [strlen (templ) + 8 + 1]; |
989 |
|
if (!p) |
990 |
|
BUG (0); |
991 |
|
sprintf (p, "%s-%d", templ, tm->tm_wday % 3); |
992 |
|
return p; |
993 |
|
} |
994 |
|
|
995 |
|
|
996 |
void |
void |
997 |
gnupg_backup_keyrings (void) |
gnupg_backup_keyrings (void) |
998 |
{ |
{ |
999 |
char * srcpath = NULL, * dstpath = NULL; |
char *srcpath = NULL, *dstpath = NULL; |
1000 |
|
char *name=NULL; |
1001 |
int rc, bakmode=0; |
int rc, bakmode=0; |
1002 |
|
|
1003 |
if (!reg_prefs.auto_backup) |
if (!reg_prefs.auto_backup) |
1005 |
bakmode = reg_prefs.backup.mode; |
bakmode = reg_prefs.backup.mode; |
1006 |
srcpath = get_gnupg_path (); |
srcpath = get_gnupg_path (); |
1007 |
check_keyring (&srcpath); |
check_keyring (&srcpath); |
1008 |
if (bakmode == 1) |
if (bakmode == 1) { |
|
{ |
|
1009 |
dstpath = get_gnupg_path (); |
dstpath = get_gnupg_path (); |
1010 |
check_keyring (&dstpath); |
check_keyring (&dstpath); |
1011 |
} |
} |
1012 |
else if (bakmode == 2) |
else if (bakmode == 2) { |
|
{ |
|
1013 |
char * tmpfile; |
char * tmpfile; |
1014 |
FILE * fp; |
FILE * fp; |
1015 |
|
|
1021 |
if (!fp) |
if (!fp) |
1022 |
rc = log_box (_("Backup"), MB_WARN|MB_RETRYCANCEL, _("The backup drive '%s' does not seems to accessable.\n" |
rc = log_box (_("Backup"), MB_WARN|MB_RETRYCANCEL, _("The backup drive '%s' does not seems to accessable.\n" |
1023 |
"Please insert/check the drive to continue."), dstpath); |
"Please insert/check the drive to continue."), dstpath); |
1024 |
else |
else { |
|
{ |
|
1025 |
rc = 0; |
rc = 0; |
1026 |
fclose (fp); |
fclose (fp); |
1027 |
unlink (tmpfile); |
unlink (tmpfile); |
1030 |
if (!fp || rc == IDCANCEL) |
if (!fp || rc == IDCANCEL) |
1031 |
return; |
return; |
1032 |
} |
} |
1033 |
else |
else { |
|
{ |
|
1034 |
log_box (_("Backup"), MB_ERR, _("Invalid backup mode %d"), bakmode); |
log_box (_("Backup"), MB_ERR, _("Invalid backup mode %d"), bakmode); |
1035 |
return; |
return; |
1036 |
} |
} |
1037 |
rc = backup_one_file (srcpath, "pubring", dstpath, "pubring-bak"); |
name = get_backup_name ("pubring-bak"); |
1038 |
|
rc = backup_one_file (srcpath, "pubring", dstpath, name); |
1039 |
if (!rc) |
if (!rc) |
1040 |
rc = backup_one_file (srcpath, "secring", dstpath, "secring-bak"); |
rc = backup_one_file (srcpath, "secring", dstpath, "secring-bak"); |
1041 |
|
free_if_alloc (name); |
1042 |
free_if_alloc (srcpath); |
free_if_alloc (srcpath); |
1043 |
free_if_alloc (dstpath); |
free_if_alloc (dstpath); |
1044 |
} /* gnupg_backup_keyrings */ |
} /* gnupg_backup_keyrings */ |