156 |
if (!path) |
if (!path) |
157 |
return NULL; |
return NULL; |
158 |
keyring = make_filename (path, pub? "pubring" : "secring", "gpg"); |
keyring = make_filename (path, pub? "pubring" : "secring", "gpg"); |
159 |
if (!strict && !file_exist_check (keyring)) { |
if (strict && !file_exist_check (keyring)) { |
160 |
|
free_if_alloc (path); |
161 |
|
return keyring; |
162 |
|
} |
163 |
|
else if (!strict) { |
164 |
free_if_alloc (path); |
free_if_alloc (path); |
165 |
return keyring; |
return keyring; |
166 |
} |
} |
423 |
} /* check_gnupg_cfgfile */ |
} /* check_gnupg_cfgfile */ |
424 |
|
|
425 |
|
|
426 |
/* |
/* Usually GPG creates the pubring.gpg, secring.gpg on |
427 |
* Check if both keyrings are located in the gnupg home directory. |
the first start, but to make sure they always exist |
428 |
*/ |
create them empty if needed. */ |
429 |
|
static void |
430 |
|
create_empty_keyring (int _pub) |
431 |
|
{ |
432 |
|
char *name; |
433 |
|
FILE *f; |
434 |
|
|
435 |
|
name = get_gnupg_keyring (_pub, 0); |
436 |
|
if (file_exist_check (name) != 0) { |
437 |
|
f = fopen (name, "ab"); |
438 |
|
if (f != NULL) |
439 |
|
fclose (f); |
440 |
|
} |
441 |
|
free_if_alloc (name); |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
/* Check if both keyrings are located in the gnupg home directory. */ |
446 |
int |
int |
447 |
gnupg_access_files (void) |
gnupg_access_files (void) |
448 |
{ |
{ |
451 |
int secrings = 0, pubrings = 0; |
int secrings = 0, pubrings = 0; |
452 |
char *optfile; |
char *optfile; |
453 |
|
|
454 |
|
create_empty_keyring (1); |
455 |
if (gnupg_access_keyring (1)) |
if (gnupg_access_keyring (1)) |
456 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
457 |
else |
else |
458 |
pubring_ok = 1; |
pubring_ok = 1; |
459 |
|
|
460 |
|
create_empty_keyring (0); |
461 |
if (gnupg_access_keyring (0)) |
if (gnupg_access_keyring (0)) |
462 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
463 |
else |
else |
486 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
487 |
} |
} |
488 |
return rc; |
return rc; |
489 |
} /* gnupg_access_files */ |
} |
490 |
|
|
491 |
|
|
492 |
static int |
static int |
499 |
if( s == NULL ) |
if( s == NULL ) |
500 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
501 |
optfile = make_filename (s, GPG_CONF, NULL); |
optfile = make_filename (s, GPG_CONF, NULL); |
502 |
fp = fopen( optfile, "wb" ); |
fp = fopen (optfile, "wb"); |
503 |
if( fp == NULL ) { |
if (fp == NULL) { |
504 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
505 |
goto fail; |
goto fail; |
506 |
} |
} |
507 |
fwrite( options_skel, 1, strlen( options_skel ), fp ); |
fwrite (options_skel, 1, strlen (options_skel), fp); |
508 |
fclose( fp ); |
fclose (fp); |
509 |
|
|
510 |
fail: |
fail: |
511 |
free_if_alloc( s ); |
free_if_alloc (s); |
512 |
free_if_alloc( optfile ); |
free_if_alloc (optfile); |
513 |
return 0; |
return 0; |
514 |
} /* create_gpg_options */ |
} /* create_gpg_options */ |
515 |
|
|