18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
#include <config.h> |
24 |
#endif |
#endif |
130 |
} |
} |
131 |
|
|
132 |
|
|
133 |
|
/* Check if the key has a good status. |
134 |
|
Return value: 0 on success. */ |
135 |
int |
int |
136 |
km_check_key_status (listview_ctrl_t lv, int pos) |
km_check_key_status (listview_ctrl_t lv, int pos) |
137 |
{ |
{ |
149 |
} |
} |
150 |
|
|
151 |
return 0; |
return 0; |
152 |
} /* km_check_key_status */ |
} |
153 |
|
|
154 |
|
|
155 |
|
/* Return all key flags ORed. */ |
156 |
int |
int |
157 |
km_get_key_status (listview_ctrl_t lv, int pos) |
km_get_key_status (listview_ctrl_t lv, int pos) |
158 |
{ |
{ |
172 |
if (key->disabled) |
if (key->disabled) |
173 |
flags |= KM_FLAG_DISABLED; |
flags |= KM_FLAG_DISABLED; |
174 |
return flags; |
return flags; |
175 |
} /* km_get_key_status */ |
} |
176 |
|
|
177 |
|
|
178 |
/* Interface to enable or disable a key (@enable = 1 then enable). |
/* Interface to enable or disable a key (@enable = 1 then enable). |
191 |
BUG (NULL); |
BUG (NULL); |
192 |
|
|
193 |
err = enable? ke->enable () : ke->disable (); |
err = enable? ke->enable () : ke->disable (); |
194 |
if (!err) { |
if (!err) |
195 |
show_msg (dlg, 1500, _("Key status changed.")); |
show_msg (dlg, 1500, _("Key status changed.")); |
|
keycache_set_reload (1); /* XXX: set update flag */ |
|
|
} |
|
196 |
else |
else |
197 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
198 |
delete ke; |
delete ke; |
272 |
|
|
273 |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
274 |
if (!n) { |
if (!n) { |
275 |
msg_box (dlg, _("No key was selected for export."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No key was selected for export."), |
276 |
rc = WPTERR_GENERAL; |
_("Key Manager"), MB_ERR); |
277 |
|
rc = WPTERR_GENERAL; |
278 |
goto leave; |
goto leave; |
279 |
} |
} |
280 |
|
|
294 |
leave: |
leave: |
295 |
free (rset); |
free (rset); |
296 |
return rc; |
return rc; |
297 |
} /* km_clip_export */ |
} |
298 |
|
|
299 |
|
|
300 |
/* Export the selected secret key from @lv into @fname. |
/* Export the selected secret key from @lv into @fname. |
359 |
/*gpgme_set_comment (ctx, "Generated by WinPT "PGM_VERSION);*/ |
/*gpgme_set_comment (ctx, "Generated by WinPT "PGM_VERSION);*/ |
360 |
patt = gpg_keylist_to_pattern (rset, n); |
patt = gpg_keylist_to_pattern (rset, n); |
361 |
|
|
362 |
err = gpgme_op_export( ctx, patt, 0, keydata); |
err = gpgme_op_export (ctx, patt, 0, keydata); |
363 |
if( err ) { |
if( err ) { |
364 |
msg_box( dlg, gpgme_strerror( err ), _("Key Manager"), MB_ERR ); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
365 |
goto leave; |
goto leave; |
366 |
} |
} |
367 |
|
|
368 |
log_box( _("Key Manager"), MB_OK, |
log_box (_("Key Manager"), MB_OK, |
369 |
_("Key(s) successfully saved in '%s'."), fname ); |
_("Key(s) successfully saved in '%s'."), fname); |
370 |
|
|
371 |
leave: |
leave: |
372 |
err = gpg_data_release_and_set_file( keydata, fname ); |
err = gpg_data_release_and_set_file (keydata, fname); |
373 |
if (err) |
if (err) |
374 |
log_box (_("Key Manager"), MB_OK, |
log_box (_("Key Manager"), MB_OK, |
375 |
_("Could not save data to '%s'."), fname); |
_("Could not save data to '%s'."), fname); |
376 |
gpgme_release (ctx); |
gpgme_release (ctx); |
377 |
free (patt); |
free (patt); |
378 |
return (int)err; |
return (int)err; |
379 |
} /* km_file_export */ |
} |
380 |
|
|
381 |
|
|
382 |
|
/* Read a dash escaped key from the clipboard |
383 |
|
unescape it and write it back. */ |
384 |
static int |
static int |
385 |
extract_dash_escaped_key (void) |
extract_dash_escaped_key (void) |
386 |
{ |
{ |
389 |
|
|
390 |
err = gpg_data_new_from_clipboard (&inp, 0); |
err = gpg_data_new_from_clipboard (&inp, 0); |
391 |
if (err) { |
if (err) { |
392 |
msg_box (NULL, gpgme_strerror( err ), _("Key Manager"), MB_ERR); |
msg_box (NULL, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
393 |
return -1; |
return -1; |
394 |
} |
} |
395 |
gpg_data_extract_plaintext (inp, &plain); |
gpg_data_extract_plaintext (inp, &plain); |
397 |
gpgme_data_release (inp); |
gpgme_data_release (inp); |
398 |
|
|
399 |
return 0; |
return 0; |
400 |
} /* extract_dash_escaped_key */ |
} |
401 |
|
|
402 |
|
|
403 |
/* Import keys from the clipboard. */ |
/* Import keys from the clipboard. */ |
410 |
int has_data = 0; |
int has_data = 0; |
411 |
|
|
412 |
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
413 |
msg_box( dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), _("Key Manager"), MB_ERR); |
msg_box (dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), |
414 |
|
_("Key Manager"), MB_ERR); |
415 |
return WPTERR_CLIP_ISEMPTY; |
return WPTERR_CLIP_ISEMPTY; |
416 |
} |
} |
417 |
err = gpg_clip_is_secured (&pgptype, &has_data); |
err = gpg_clip_is_secured (&pgptype, &has_data); |
418 |
if (err) |
if (err) |
419 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
420 |
if (!has_data) { |
if (!has_data) { |
421 |
msg_box (dlg, _("No valid OpenPGP data found."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No valid OpenPGP data found."), |
422 |
|
_("Key Manager"), MB_ERR); |
423 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
424 |
} |
} |
425 |
if (!(pgptype & PGP_PUBKEY) && !(pgptype & PGP_SECKEY)) { |
if (!(pgptype & PGP_PUBKEY) && !(pgptype & PGP_SECKEY)) { |
426 |
msg_box (dlg, _("No valid OpenPGP keys found."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("No valid OpenPGP keys found."), |
427 |
|
_("Key Manager"), MB_ERR); |
428 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
429 |
} |
} |
430 |
if (pgptype & PGP_DASH_ESCAPED) { |
if (pgptype & PGP_DASH_ESCAPED) { |
469 |
fp = fopen (p, "wb"); |
fp = fopen (p, "wb"); |
470 |
if (!fp) { |
if (!fp) { |
471 |
free_if_alloc (p); |
free_if_alloc (p); |
472 |
log_box (_("Key Import HTTP"), MB_ERR, "%s: %s", p, winpt_strerror (WPTERR_FILE_CREAT)); |
log_box (_("Key Import HTTP"), MB_ERR, "%s: %s", p, |
473 |
|
winpt_strerror (WPTERR_FILE_CREAT)); |
474 |
return WPTERR_FILE_CREAT; |
return WPTERR_FILE_CREAT; |
475 |
} |
} |
476 |
|
|
580 |
|
|
581 |
if (listview_get_curr_pos (lv) == -1) { |
if (listview_get_curr_pos (lv) == -1) { |
582 |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
583 |
return WPTERR_GENERAL; |
return -1; |
584 |
} |
} |
585 |
|
|
586 |
if (listview_count_items (lv, 1) > 8) { |
if (listview_count_items (lv, 1) > 8) { |
598 |
rset = (gpgme_key_t *)calloc (n+1, sizeof (gpgme_key_t)); |
rset = (gpgme_key_t *)calloc (n+1, sizeof (gpgme_key_t)); |
599 |
if (!rset) |
if (!rset) |
600 |
BUG (NULL); |
BUG (NULL); |
601 |
for( i = 0; i < n; i++ ) { |
for (i = 0; i < n; i++) { |
602 |
if( listview_get_item_state( lv, i ) ) { |
if( listview_get_item_state(lv, i)) { |
603 |
listview_get_item_text( lv, i, 0, uid, sizeof uid - 1 ); |
listview_get_item_text (lv, i, 0, uid, sizeof uid - 1); |
604 |
listview_get_item_text( lv, i, 1, keyid, sizeof keyid - 1 ); |
listview_get_item_text (lv, i, 1, keyid, sizeof keyid - 1); |
605 |
listview_get_item_text( lv, i, 3, keylen, sizeof keylen - 1 ); |
listview_get_item_text (lv, i, 3, keylen, sizeof keylen - 1); |
606 |
listview_get_item_text( lv, i, 7, date, sizeof date - 1 ); |
listview_get_item_text (lv, i, 7, date, sizeof date - 1); |
607 |
seckey_type = km_check_for_seckey (lv, i, NULL); |
seckey_type = km_check_for_seckey (lv, i, NULL); |
608 |
if (confirm && !seckey_type) { |
if (confirm && !seckey_type) { |
609 |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
617 |
with_seckey = 0; |
with_seckey = 0; |
618 |
} |
} |
619 |
else if (confirm) { |
else if (confirm) { |
620 |
rc = log_box( _("Key Manager"), MB_YESNO|MB_ICONWARNING, |
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
621 |
_("Do you really want to delete this KEY PAIR?\n\n" |
_("Do you really want to delete this KEY PAIR?\n\n" |
622 |
"Please remember that you are not able to decrypt\n" |
"Please remember that you are not able to decrypt\n" |
623 |
"messages you stored with this key any longer.\n" |
"messages you stored with this key any longer.\n" |
624 |
"\n" |
"\n" |
625 |
"pub/sec %s %s %s\n" |
"pub/sec %s %s %s\n" |
626 |
" \"%s\""), keylen, keyid, date, uid ); |
" \"%s\""), keylen, keyid, date, uid); |
627 |
if( rc == IDYES ) { |
if( rc == IDYES ) { |
628 |
if (seckey_type == 2) |
if (seckey_type == 2) |
629 |
msg_box( dlg, _("The actual secret key is stored on a smartcard.\n" |
msg_box (dlg, _("The actual secret key is stored on a smartcard.\n" |
630 |
"Only the public key and the secret key \n" |
"Only the public key and the secret key \n" |
631 |
"placeholder will be deleted.\n"), _("Key Manager"), MB_OK ); |
"placeholder will be deleted.\n"), |
632 |
|
_("Key Manager"), MB_OK); |
633 |
get_pubkey (keyid, &k); |
get_pubkey (keyid, &k); |
634 |
rset[k_pos++] = k; |
rset[k_pos++] = k; |
635 |
} |
} |
660 |
n--; |
n--; |
661 |
} |
} |
662 |
if (n == 0) |
if (n == 0) |
663 |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
664 |
gpgme_release (ctx); |
gpgme_release (ctx); |
665 |
listview_del_items (lv); |
listview_del_items (lv); |
666 |
delete_keys_from_cache (rset, k_pos); |
delete_keys_from_cache (rset, k_pos); |
670 |
} |
} |
671 |
|
|
672 |
|
|
673 |
|
/* Send the select key in @lv to the keyserver @host:@port. */ |
674 |
int |
int |
675 |
km_send_to_keyserver (listview_ctrl_t lv, HWND dlg, const char * host, u16 port) |
km_send_to_keyserver (listview_ctrl_t lv, HWND dlg, const char *host, u16 port) |
676 |
{ |
{ |
677 |
char keyid[32]; |
char keyid[32]; |
678 |
const char *t; |
const char *t; |
679 |
int id; |
int id; |
680 |
|
|
681 |
id = listview_get_curr_pos( lv ); |
id = listview_get_curr_pos (lv); |
682 |
if( id == -1 ) { |
if (id == -1) { |
683 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
684 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
685 |
} |
} |
686 |
|
|
687 |
listview_get_item_text( lv, id, 1, keyid, sizeof keyid - 1 ); |
listview_get_item_text (lv, id, 1, keyid, sizeof keyid - 1); |
688 |
id = log_box (_("Key Manager"), MB_YESNO, |
id = log_box (_("Key Manager"), MB_YESNO, |
689 |
_("Do you really want to send '%s' to keyserver %s?"), |
_("Do you really want to send '%s' to keyserver %s?"), |
690 |
keyid, host); |
keyid, host); |
696 |
} |
} |
697 |
|
|
698 |
return 0; |
return 0; |
699 |
} /* km_send_to_keyserver */ |
} |
700 |
|
|
701 |
|
|
702 |
/* Send the selected key in @lv via MAPI to a mail recipient. */ |
/* Send the selected key in @lv via MAPI to a mail recipient. */ |
707 |
gpgme_ctx_t ctx=NULL; |
gpgme_ctx_t ctx=NULL; |
708 |
gpgme_data_t out; |
gpgme_data_t out; |
709 |
gpgme_error_t rc; |
gpgme_error_t rc; |
710 |
const char *s; |
char keyid[32], tmp[128]; |
711 |
char keyid[32], tmp[192+256]; |
char *fname; |
712 |
int pos; |
int pos; |
713 |
|
|
714 |
if (listview_count_items (lv, 1 ) > 1) { |
if (listview_count_items (lv, 1) > 1) { |
715 |
msg_box (dlg, _("Please only select one key."), |
msg_box (dlg, _("Please only select one key."), |
716 |
_("Key Manager"), MB_INFO|MB_OK); |
_("Key Manager"), MB_INFO|MB_OK); |
717 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
721 |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
722 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
723 |
} |
} |
724 |
listview_get_item_text(lv, pos, 1, keyid, sizeof keyid-1); |
listview_get_item_text(lv, pos, 1, keyid, sizeof (keyid)-1); |
725 |
if (get_pubkey (keyid, &key)) |
if (get_pubkey (keyid, &key)) |
726 |
BUG (NULL); |
BUG (NULL); |
727 |
s = key->uids->name; |
|
728 |
GetTempPath (sizeof tmp-1, tmp); |
GetTempPath (sizeof (tmp)-1, tmp); |
729 |
strncat (tmp, s, sizeof tmp-200); |
if (tmp[strlen (tmp)-1] == '\\') |
730 |
strncat (tmp, ".asc", sizeof tmp-200); |
tmp[strlen (tmp)-1] = 0; |
731 |
|
fname = make_filename (tmp, key->uids->name, "asc"); |
732 |
|
for (pos=0; pos < (int)strlen (fname); pos++) { |
733 |
|
if (fname[pos] == ' ') |
734 |
|
fname[pos] = '_'; |
735 |
|
} |
736 |
|
|
737 |
rc = gpgme_new (&ctx); |
rc = gpgme_new (&ctx); |
738 |
if (rc) |
if (rc) |
746 |
if (rc) |
if (rc) |
747 |
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
748 |
else |
else |
749 |
mapi_send_pubkey (keyid, tmp); |
mapi_send_pubkey (keyid, fname); |
750 |
|
|
751 |
gpg_data_release_and_set_file (out, tmp); |
gpg_data_release_and_set_file (out, fname); |
752 |
gpgme_release (ctx); |
gpgme_release (ctx); |
753 |
|
free_if_alloc (fname); |
754 |
return rc; |
return rc; |
755 |
} |
} |
756 |
|
|
766 |
idx = pos; |
idx = pos; |
767 |
else |
else |
768 |
idx = listview_get_curr_pos (lv); |
idx = listview_get_curr_pos (lv); |
769 |
if (idx != -1) |
if (idx != -1) { |
770 |
{ |
listview_get_item_text (lv, idx, 1, keyid, sizeof (keyid) - 1); |
|
listview_get_item_text (lv, idx, 1, keyid, sizeof keyid - 1); |
|
771 |
t = keyid; |
t = keyid; |
772 |
if (!strncmp (keyid, "0x", 2)) |
if (!strncmp (keyid, "0x", 2)) |
773 |
t += 2; |
t += 2; |
774 |
hkp_recv_key (dlg, default_keyserver, default_keyserver_port, t, 0, KM_KS_REFRESH); |
hkp_recv_key (dlg, default_keyserver, default_keyserver_port, |
775 |
|
t, 0, KM_KS_REFRESH); |
776 |
} |
} |
777 |
} |
} |
778 |
|
|
779 |
|
|
780 |
|
/* Refresh all keys from the default keyserver. */ |
781 |
void |
void |
782 |
km_refresh_from_keyserver (listview_ctrl_t lv, HWND dlg) |
km_refresh_from_keyserver (listview_ctrl_t lv, HWND dlg) |
783 |
{ |
{ |
791 |
} |
} |
792 |
idx = listview_count_items (lv, 0); |
idx = listview_count_items (lv, 0); |
793 |
if (listview_count_items (lv, 1) == idx) { |
if (listview_count_items (lv, 1) == idx) { |
794 |
id = msg_box (dlg, _("Do you really want to refresh all keys in the keyring?"), _("Key Manager"), MB_YESNO); |
id = msg_box (dlg, _("Do you really want to refresh all keys in the keyring?"), |
795 |
|
_("Key Manager"), MB_YESNO); |
796 |
if (id == IDNO) |
if (id == IDNO) |
797 |
return; |
return; |
798 |
for (i = 0; i < idx; i++) |
for (i = 0; i < idx; i++) |
806 |
km_refresh_one_key (lv, dlg, i); |
km_refresh_one_key (lv, dlg, i); |
807 |
} |
} |
808 |
} |
} |
809 |
} /* km_refresh_from_keyserver */ |
} |
810 |
|
|
811 |
|
|
812 |
void |
void |
816 |
|
|
817 |
key_get_clip_info (uid, buf, 255); |
key_get_clip_info (uid, buf, 255); |
818 |
set_clip_text (NULL, buf, strlen (buf)); |
set_clip_text (NULL, buf, strlen (buf)); |
819 |
} /* km_set_clip_info */ |
} |
820 |
|
|
821 |
|
|
822 |
|
|
862 |
|
|
863 |
/* Count all keys and show from @lv results in the status bar @sb. */ |
/* Count all keys and show from @lv results in the status bar @sb. */ |
864 |
void |
void |
865 |
km_complete_status_bar (HWND sb, listview_ctrl_t lv) |
km_update_status_bar (HWND sb, listview_ctrl_t lv) |
866 |
{ |
{ |
867 |
char txt_sec[128], txt_pub[128]; |
char txt_sec[128], txt_pub[128]; |
868 |
int nkeys = 0, nsec = 0, i; |
int nkeys = 0, nsec = 0; |
869 |
|
int i; |
870 |
|
|
871 |
nkeys = listview_count_items (lv, 0); |
nkeys = listview_count_items (lv, 0); |
872 |
for (i = 0; i < nkeys; i++) { |
for (i = 0; i < nkeys; i++) { |
931 |
} |
} |
932 |
free_if_alloc (name); |
free_if_alloc (name); |
933 |
} |
} |
|
|
|
|
|
|
|
|
|
|
void |
|
|
km_dump_key (gpgme_key_t key) |
|
|
{ |
|
|
#if _DEBUG |
|
|
log_box ("DEBUG", MB_OK, |
|
|
"%d %d %s %d\n%s", key->subkeys->length, |
|
|
key->subkeys->pubkey_algo, |
|
|
key->subkeys->keyid, |
|
|
key->subkeys->timestamp, |
|
|
key->uids->uid); |
|
|
#endif |
|
|
} |
|
|
|
|
|
#if 0 |
|
|
gpg_optfile_t |
|
|
km_groupdb_open (void) |
|
|
{ |
|
|
gpg_optfile_t opt; |
|
|
char * optfile; |
|
|
int err = 0; |
|
|
|
|
|
optfile = get_gnupg_cfgfile(); |
|
|
if( !optfile ) |
|
|
BUG( NULL ); |
|
|
if( parse_gpg_options( optfile, &opt ) ) |
|
|
err = 1; |
|
|
free_if_alloc( optfile ); |
|
|
return err? NULL : opt; |
|
|
} /* km_groupdb_open */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groupdb_expand_recipients( const char *name, gpgme_recipients_t rset ) |
|
|
{ |
|
|
gpg_keycache_t kc; |
|
|
gpgme_key_t pk; |
|
|
gpg_optfile_t opt; |
|
|
gpg_group_t grp; |
|
|
gpg_member_t mbr; |
|
|
int no_trust = 0, n; |
|
|
|
|
|
kc = keycache_get_ctx( 1 ); |
|
|
if( !kc ) |
|
|
BUG( NULL ); |
|
|
|
|
|
opt = km_groupdb_open( ); |
|
|
if( !opt ) |
|
|
return WPTERR_FILE_OPEN; |
|
|
|
|
|
grp = find_group( opt, name ); |
|
|
if( !grp ) |
|
|
return WPTERR_GENERAL; |
|
|
|
|
|
/* we are paranoid and check that all group members exist in the |
|
|
key cache. there is no need that it is really the real key, but |
|
|
an entry should be available. the rest is up to GPG. */ |
|
|
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
|
|
if( gpgme_keycache_find_key( kc, mbr->name, 0, &pk ) ) |
|
|
BUG( NULL ); |
|
|
n = count_userids (pk); |
|
|
while( n-- ) { |
|
|
gpgme_user_id_t u = get_nth_userid (pk, n); |
|
|
const char * s = u->uid; |
|
|
if( s && stristr( s, mbr->name ) |
|
|
&& u->validity < 3 ) |
|
|
no_trust++; |
|
|
} |
|
|
} |
|
|
|
|
|
gpgme_recipients_add_name( rset, name ); |
|
|
release_gpg_options( opt ); |
|
|
|
|
|
return no_trust; |
|
|
} /* km_groupdb_expand_recipients */ |
|
|
|
|
|
|
|
|
static HTREEITEM |
|
|
km_tv_insert_item( HWND tree, HTREEITEM parent, const char *text ) |
|
|
{ |
|
|
TVINSERTSTRUCT tvis; |
|
|
HTREEITEM node; |
|
|
|
|
|
memset( &tvis, 0, sizeof tvis ); |
|
|
tvis.hParent = parent; |
|
|
tvis.hInsertAfter = TVI_LAST; |
|
|
tvis.item.mask = TVIF_TEXT; |
|
|
tvis.item.pszText = (char *)text; |
|
|
node = TreeView_InsertItem( tree, &tvis ); |
|
|
return node; |
|
|
} /* km_tv_insert_item */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_new( km_group_t *r_gc, HWND ctrl ) |
|
|
{ |
|
|
km_group_t gc; |
|
|
|
|
|
gc = new km_group_s; |
|
|
if (!gc) |
|
|
BUG (NULL); |
|
|
gc->tree = ctrl; |
|
|
gc->gh = km_groupdb_open (); |
|
|
*r_gc = gc; |
|
|
return 0; |
|
|
} /* km_groups_new */ |
|
|
|
|
|
|
|
|
void |
|
|
km_groups_sync( km_group_t gc ) |
|
|
{ |
|
|
char * optfile; |
|
|
|
|
|
optfile = get_gnupg_cfgfile (); |
|
|
if( !optfile ) |
|
|
BUG( NULL ); |
|
|
commit_gpg_options( optfile, gc->gh ); |
|
|
free_if_alloc( optfile ); |
|
|
gc->need_sync = 0; |
|
|
} /* km_groups_sync */ |
|
|
|
|
|
|
|
|
void |
|
|
km_groups_release (km_group_t gc) |
|
|
{ |
|
|
if( gc ) { |
|
|
/* xxx: this reset the default key (sync=1) */ |
|
|
gc->need_sync=0; |
|
|
if (gc->need_sync) |
|
|
km_groups_sync (gc); |
|
|
if (gc->gh) |
|
|
release_gpg_options( gc->gh ); |
|
|
gc->gh = NULL; |
|
|
gc->tree = NULL; |
|
|
delete gc; |
|
|
} |
|
|
} /* km_groups_release */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_load( km_group_t gc ) |
|
|
{ |
|
|
HTREEITEM n; |
|
|
gpg_group_t grp, g; |
|
|
gpg_member_t mbr; |
|
|
u32 gid = 0; |
|
|
|
|
|
if( !gc->gh ) |
|
|
return 0; |
|
|
grp = gc->gh->grp; |
|
|
if( !grp ) |
|
|
return 0; /* no groups */ |
|
|
|
|
|
for( g = grp; g; g = g->next ) { |
|
|
n = km_tv_insert_item( gc->tree, NULL, g->name ); |
|
|
for( mbr = g->list; mbr; mbr = mbr->next ) { |
|
|
if( mbr->used && mbr->name ) |
|
|
km_tv_insert_item( gc->tree, n, mbr->name ); |
|
|
} |
|
|
} |
|
|
DragAcceptFiles( gc->tree, TRUE ); |
|
|
gc->need_sync = 0; |
|
|
return 0; |
|
|
} /* km_groups_load */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_add( km_group_t gc, listview_ctrl_t lv, int km_index ) |
|
|
{ |
|
|
TVITEM tvi; |
|
|
char uid[128], valid[64], text[128]; |
|
|
int i_valid; |
|
|
|
|
|
memset( &tvi, 0, sizeof tvi ); |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
|
|
tvi.pszText = text; |
|
|
tvi.cchTextMax = sizeof text -1; |
|
|
tvi.mask = TVIF_TEXT; |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
|
|
|
|
|
|
|
|
listview_get_item_text( lv, km_index, 0, uid, sizeof uid -1 ); |
|
|
listview_get_item_text( lv, km_index, 5, valid, sizeof valid -1 ); |
|
|
|
|
|
if( strstr( valid, "Ultimate" ) ) |
|
|
i_valid = 5; |
|
|
else if( !strstr( valid, "Full" ) ) |
|
|
i_valid = 4; |
|
|
else if( !strstr( valid, "Marginal" ) ) |
|
|
i_valid = 3; |
|
|
else |
|
|
i_valid = 0; |
|
|
|
|
|
/* we can't add the full name. one way would be to use the first |
|
|
text until a space appears. |
|
|
group_add_entry(&gc->gh, gid, i_valid, uid); |
|
|
treeview_add_item(gc->tree, tvi.hItem, uid); |
|
|
*/ |
|
|
gc->need_sync = 1; |
|
|
|
|
|
return 0; |
|
|
} /* km_groups_add */ |
|
|
|
|
|
|
|
|
static int |
|
|
km_groups_del_main( km_group_t gc ) |
|
|
{ |
|
|
TVITEM tvi; |
|
|
char text[128]; |
|
|
int id; |
|
|
|
|
|
memset( &tvi, 0, sizeof tvi ); |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
|
|
tvi.pszText = text; |
|
|
tvi.cchTextMax = sizeof text -1; |
|
|
tvi.mask = TVIF_TEXT; |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
|
|
|
|
|
id = log_box( _("Key Manager"), MB_INFO_ASK, |
|
|
_("Do you really want to delete this group?\n\n%s"), text); |
|
|
if( id == IDNO ) |
|
|
return 0; |
|
|
delete_group( gc->gh, text ); |
|
|
TreeView_DeleteItem( gc->tree, &tvi ); |
|
|
gc->need_sync = 1; |
|
|
|
|
|
return 0; |
|
|
} /* km_groups_del */ |
|
|
|
|
|
|
|
|
static int |
|
|
km_groups_del_entry( km_group_t gc ) |
|
|
{ |
|
|
TVITEM tvi; |
|
|
HTREEITEM root; |
|
|
int id; |
|
|
char text[128], info[256]; |
|
|
gpg_group_t grp = NULL; |
|
|
|
|
|
memset( &tvi, 0, sizeof tvi ); |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
|
|
tvi.pszText = text; |
|
|
tvi.cchTextMax = sizeof text-1; |
|
|
tvi.mask = TVIF_TEXT; |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
|
|
|
|
|
_snprintf( info, sizeof info -1, |
|
|
_("Do you really want to delete this entry?\n\n%s"), text ); |
|
|
|
|
|
id = msg_box( gc->tree, info, _("Key Manager"), MB_INFO_ASK ); |
|
|
if( id == IDNO ) |
|
|
return 0; |
|
|
|
|
|
root = TreeView_GetParent( gc->tree, tvi.hItem ); |
|
|
if( root ) { |
|
|
} |
|
|
|
|
|
delete_member( gc->gh, /*fixme*/NULL, text ); |
|
|
TreeView_DeleteItem( gc->tree, &tvi ); |
|
|
gc->need_sync = 1; |
|
|
return 0; |
|
|
} /* km_groups_del_entry */ |
|
|
|
|
|
|
|
|
int |
|
|
km_groups_del( km_group_t gc ) |
|
|
{ |
|
|
if ( TreeView_GetParent( gc->tree, TreeView_GetSelection( gc->tree ) ) ) |
|
|
return km_groups_del_entry( gc ); |
|
|
else |
|
|
return km_groups_del_main( gc ); |
|
|
} /* km_groups_del */ |
|
|
#endif |
|