| 6 |
details. |
details. |
| 7 |
|
|
| 8 |
OpenPGP key database |
OpenPGP key database |
| 9 |
$Id: pgpdb.c,v 1.8 2002/08/25 13:27:40 weaselp Exp $ */ |
$Id: pgpdb.c,v 1.9 2002/08/26 19:17:31 weaselp Exp $ */ |
| 10 |
|
|
| 11 |
|
|
| 12 |
#include "mix3.h" |
#include "mix3.h" |
| 43 |
} |
} |
| 44 |
while (!bufleft(line, begin_pgp)) ; |
while (!bufleft(line, begin_pgp)) ; |
| 45 |
buf_clear(tmp); |
buf_clear(tmp); |
| 46 |
buf_appends(tmp, begin_pgp); |
buf_cat(tmp, line); |
| 47 |
buf_appends(tmp, "\n"); |
buf_appends(tmp, "\n"); |
| 48 |
buf_cat(tmp, armored); |
do { |
| 49 |
|
if (buf_getline(armored, line) == -1) { |
| 50 |
|
goto end_greedy_dearmor; |
| 51 |
|
} |
| 52 |
|
buf_cat(tmp, line); |
| 53 |
|
buf_appends(tmp, "\n"); |
| 54 |
|
} while (!bufleft(line, end_pgp)) ; |
| 55 |
|
|
| 56 |
if (pgp_dearmor(tmp, tmp) == 0) { |
if (pgp_dearmor(tmp, tmp) == 0) { |
| 57 |
err = ARMORED; |
err = ARMORED; |
| 61 |
end_greedy_dearmor: |
end_greedy_dearmor: |
| 62 |
buf_free(line); |
buf_free(line); |
| 63 |
buf_free(tmp); |
buf_free(tmp); |
| 64 |
|
|
| 65 |
} |
} |
| 66 |
buf_free(armored); |
buf_free(armored); |
| 67 |
return (err); |
return (err); |
| 317 |
int pgp_keymgt(int force) |
int pgp_keymgt(int force) |
| 318 |
{ |
{ |
| 319 |
FILE *f = NULL; |
FILE *f = NULL; |
| 320 |
BUFFER *key, *userid, *out, *outkey, *outtxt, *pass; |
BUFFER *key, *keybak, *userid, *out, *outkey, *outtxt, *pass, *secout; |
| 321 |
KEYRING *keys; |
KEYRING *keys; |
| 322 |
int err = 0, type = 0; |
int err = 0, type = 0; |
| 323 |
|
LOCK *seclock; |
| 324 |
|
|
| 325 |
key = buf_new(); |
key = buf_new(); |
| 326 |
out = buf_new(); |
out = buf_new(); |
| 327 |
|
keybak = buf_new(); |
| 328 |
|
secout = buf_new(); |
| 329 |
|
|
| 330 |
userid = buf_new(); |
userid = buf_new(); |
| 331 |
buf_sets(userid, REMAILERNAME); |
buf_sets(userid, REMAILERNAME); |
| 365 |
if (keys == NULL) |
if (keys == NULL) |
| 366 |
goto end; |
goto end; |
| 367 |
while (pgpdb_getnext(keys, key, NULL, userid) != -1) { |
while (pgpdb_getnext(keys, key, NULL, userid) != -1) { |
| 368 |
|
buf_clear(outtxt); |
| 369 |
buf_clear(outkey); |
buf_clear(outkey); |
| 370 |
|
buf_clear(keybak); |
| 371 |
|
buf_cat(keybak, key); |
| 372 |
|
if (pgp_makeseckey(key, outtxt, pass, |
| 373 |
|
type == 0 ? PGP_ES_RSA : PGP_S_DSA) == 0) { |
| 374 |
|
err = 0; |
| 375 |
|
buf_appends(secout, "Type Bits/KeyID Date User ID\n"); |
| 376 |
|
buf_cat(secout, outtxt); |
| 377 |
|
buf_nl(secout); |
| 378 |
|
pgp_armor(key, PGP_ARMOR_SECKEY); |
| 379 |
|
buf_cat(secout, key); |
| 380 |
|
buf_nl(secout); |
| 381 |
|
} |
| 382 |
buf_clear(outtxt); |
buf_clear(outtxt); |
| 383 |
if (pgp_makepubkey(key, outtxt, outkey, pass, |
if (pgp_makepubkey(keybak, outtxt, outkey, pass, |
| 384 |
type == 0 ? PGP_ES_RSA : PGP_S_DSA) == 0) { |
type == 0 ? PGP_ES_RSA : PGP_S_DSA) == 0) { |
| 385 |
err = 0; |
err = 0; |
| 386 |
buf_appends(out, "Type Bits/KeyID Date User ID\n"); |
buf_appends(out, "Type Bits/KeyID Date User ID\n"); |
| 387 |
buf_cat(out, outtxt); |
buf_cat(out, outtxt); |
|
pgp_armor(outkey, PGP_ARMOR_KEY); |
|
| 388 |
buf_nl(out); |
buf_nl(out); |
| 389 |
|
pgp_armor(outkey, PGP_ARMOR_KEY); |
| 390 |
buf_cat(out, outkey); |
buf_cat(out, outkey); |
| 391 |
buf_nl(out); |
buf_nl(out); |
| 392 |
} |
} |
| 394 |
pgpdb_close(keys); |
pgpdb_close(keys); |
| 395 |
} |
} |
| 396 |
|
|
| 397 |
|
seclock = lockfile(PGPREMSECRING); |
| 398 |
|
if (err == 0 && (f = mix_openfile(PGPREMSECRING, "w")) != NULL) { |
| 399 |
|
buf_write(secout, f); |
| 400 |
|
fclose(f); |
| 401 |
|
} else |
| 402 |
|
err = -1; |
| 403 |
|
unlockfile(seclock); |
| 404 |
if (err == 0 && (f = mix_openfile(PGPKEY, "w")) != NULL) { |
if (err == 0 && (f = mix_openfile(PGPKEY, "w")) != NULL) { |
| 405 |
buf_write(out, f); |
buf_write(out, f); |
| 406 |
fclose(f); |
fclose(f); |
| 407 |
} else |
} else |
| 408 |
err = -1; |
err = -1; |
| 409 |
end: |
end: |
| 410 |
buf_free(key); |
buf_free(key); |
| 411 |
|
buf_free(keybak); |
| 412 |
buf_free(out); |
buf_free(out); |
| 413 |
buf_free(userid); |
buf_free(userid); |
| 414 |
buf_free(pass); |
buf_free(pass); |
| 415 |
buf_free(outtxt); |
buf_free(outtxt); |
| 416 |
buf_free(outkey); |
buf_free(outkey); |
| 417 |
|
buf_free(secout); |
| 418 |
return (err); |
return (err); |
| 419 |
} |
} |
| 420 |
|
|