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 |
} |
} |
325 |
|
|
326 |
|
|
327 |
static int |
static int |
328 |
parse_version_nr (const char * buf, int *major, int *minor, int *patch) |
parse_version_nr (const char *buf, int *major, int *minor, int *patch) |
329 |
{ |
{ |
330 |
char tmp[8]; |
char tmp[8]; |
331 |
int i; |
int i; |
353 |
version given in @r_major.@r_minor.@r_patch. On success these |
version given in @r_major.@r_minor.@r_patch. On success these |
354 |
variables contain the GPG version which is installed. */ |
variables contain the GPG version which is installed. */ |
355 |
int |
int |
356 |
check_gnupg_engine (int *r_major, int *r_minor, int *r_patch) |
check_gnupg_engine (const char *need_gpg_ver, |
357 |
|
int *r_major, int *r_minor, int *r_patch) |
358 |
{ |
{ |
359 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
360 |
gpgme_engine_info_t inf; |
gpgme_engine_info_t inf; |
361 |
char *eng = NULL; |
char *eng = NULL; |
362 |
int major=0, minor=0, patch=0; |
int major=0, minor=0, patch=0; |
363 |
|
int need_major = 0, need_minor = 0, need_patch = 0; |
364 |
int rc = 1; |
int rc = 1; |
365 |
|
|
366 |
|
/* Convert the needed GPG version to the integer format. */ |
367 |
|
rc = parse_version_nr (need_gpg_ver, |
368 |
|
&need_major, &need_minor, &need_patch); |
369 |
|
if (rc) |
370 |
|
return rc; |
371 |
|
|
372 |
gpgme_new (&ctx); |
gpgme_new (&ctx); |
373 |
inf = gpgme_ctx_get_engine_info (ctx); |
inf = gpgme_ctx_get_engine_info (ctx); |
374 |
if (!inf) { |
if (!inf) { |
388 |
return rc; |
return rc; |
389 |
} |
} |
390 |
|
|
391 |
if (major > *r_major) |
if (major > need_major) |
392 |
rc = 0; |
rc = 0; |
393 |
else if (major == *r_major && minor > *r_minor) |
else if (major == need_major && minor > need_minor) |
394 |
rc = 0; |
rc = 0; |
395 |
else if (major == *r_major && minor == *r_minor && |
else if (major == need_major && minor == need_minor && |
396 |
patch >= *r_patch) |
patch >= need_patch) |
397 |
rc = 0; |
rc = 0; |
398 |
|
|
399 |
|
/* Return the current GPG version. */ |
400 |
*r_major = major; |
*r_major = major; |
401 |
*r_minor = minor; |
*r_minor = minor; |
402 |
*r_patch = patch; |
*r_patch = patch; |
432 |
} /* check_gnupg_cfgfile */ |
} /* check_gnupg_cfgfile */ |
433 |
|
|
434 |
|
|
435 |
/* |
/* Usually GPG creates the pubring.gpg, secring.gpg on |
436 |
* Check if both keyrings are located in the gnupg home directory. |
the first start, but to make sure they always exist |
437 |
*/ |
create them empty if needed. */ |
438 |
|
static void |
439 |
|
create_empty_keyring (int _pub) |
440 |
|
{ |
441 |
|
char *name; |
442 |
|
FILE *f; |
443 |
|
|
444 |
|
name = get_gnupg_keyring (_pub, 0); |
445 |
|
if (file_exist_check (name) != 0) { |
446 |
|
f = fopen (name, "ab"); |
447 |
|
if (f != NULL) |
448 |
|
fclose (f); |
449 |
|
} |
450 |
|
free_if_alloc (name); |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
|
/* Check if both keyrings are located in the gnupg home directory. */ |
455 |
int |
int |
456 |
gnupg_access_files (void) |
gnupg_access_files (void) |
457 |
{ |
{ |
460 |
int secrings = 0, pubrings = 0; |
int secrings = 0, pubrings = 0; |
461 |
char *optfile; |
char *optfile; |
462 |
|
|
463 |
|
create_empty_keyring (1); |
464 |
if (gnupg_access_keyring (1)) |
if (gnupg_access_keyring (1)) |
465 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
466 |
else |
else |
467 |
pubring_ok = 1; |
pubring_ok = 1; |
468 |
|
|
469 |
|
create_empty_keyring (0); |
470 |
if (gnupg_access_keyring (0)) |
if (gnupg_access_keyring (0)) |
471 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
472 |
else |
else |
495 |
rc = WPTERR_GPG_KEYRINGS; |
rc = WPTERR_GPG_KEYRINGS; |
496 |
} |
} |
497 |
return rc; |
return rc; |
498 |
} /* gnupg_access_files */ |
} |
499 |
|
|
500 |
|
|
501 |
static int |
static int |
508 |
if( s == NULL ) |
if( s == NULL ) |
509 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
510 |
optfile = make_filename (s, GPG_CONF, NULL); |
optfile = make_filename (s, GPG_CONF, NULL); |
511 |
fp = fopen( optfile, "wb" ); |
fp = fopen (optfile, "wb"); |
512 |
if( fp == NULL ) { |
if (fp == NULL) { |
513 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
514 |
goto fail; |
goto fail; |
515 |
} |
} |
516 |
fwrite( options_skel, 1, strlen( options_skel ), fp ); |
fwrite (options_skel, 1, strlen (options_skel), fp); |
517 |
fclose( fp ); |
fclose (fp); |
518 |
|
|
519 |
fail: |
fail: |
520 |
free_if_alloc( s ); |
free_if_alloc (s); |
521 |
free_if_alloc( optfile ); |
free_if_alloc (optfile); |
522 |
return 0; |
return 0; |
523 |
} /* create_gpg_options */ |
} /* create_gpg_options */ |
524 |
|
|