1 |
/* wptFileManager.cpp - File Manager routines |
/* wptFileManager.cpp - File Manager routines |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
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 |
*/ |
*/ |
|
/* TODO: |
|
|
* check_armor_type: we should check the whole file and not only the first line! |
|
|
*/ |
|
21 |
|
|
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
#include <config.h> |
47 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
48 |
#include "wptImport.h" |
#include "wptImport.h" |
49 |
#include "wptCrypto.h" |
#include "wptCrypto.h" |
50 |
|
#include "wptKeyManager.h" |
51 |
#include "openpgp.h" |
#include "openpgp.h" |
52 |
|
|
|
#define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT)) |
|
|
#define op_end() SetCursor (LoadCursor (NULL, IDC_ARROW)) |
|
53 |
|
|
54 |
void progress_cleanup (progress_filter_s *pfx); |
void progress_cleanup (progress_filter_s *pfx); |
55 |
BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, |
BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, |
58 |
gpgme_error_t sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf, |
gpgme_error_t sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf, |
59 |
int prev_was_bad, int fd); |
int prev_was_bad, int fd); |
60 |
|
|
|
/*-- wptFileVerifyDlg.cpp --*/ |
|
|
void file_verify_add_state (file_sig_ctx_t c); |
|
|
void file_verify_use_event (void); |
|
|
void file_verify_wait (void); |
|
61 |
|
|
62 |
static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
/* Symbolic column IDs. */ |
63 |
|
enum { |
64 |
|
FM_COL_STAT = 0, |
65 |
|
FM_COL_NAME = 1, |
66 |
|
FM_COL_OP = 2 |
67 |
|
}; |
68 |
|
|
69 |
|
static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
70 |
".mp3", ".wav", ".mid", ".wma", |
".mp3", ".wav", ".mid", ".wma", |
71 |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
72 |
|
|
112 |
|
|
113 |
/* Removes 'critical' attributes from the file @fname. |
/* Removes 'critical' attributes from the file @fname. |
114 |
If @force is 1, the user is not asked for permission. */ |
If @force is 1, the user is not asked for permission. */ |
115 |
static void |
void |
116 |
remove_crit_file_attrs (const char *fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
117 |
{ |
{ |
118 |
u32 fattr; |
DWORD fattr; |
119 |
int id = 0; |
int id = 0; |
120 |
|
|
121 |
if (file_exist_check (fname)) |
if (file_exist_check (fname)) |
225 |
|
|
226 |
/* Check the armor type of the file @fname and return |
/* Check the armor type of the file @fname and return |
227 |
a string representation of it. */ |
a string representation of it. */ |
228 |
static const char * |
static const char* |
229 |
fm_check_armor_type (const char *fname, int *r_type) |
fm_check_armor_type (const char *fname, int *r_type) |
230 |
{ |
{ |
231 |
FILE * fp; |
FILE *fp; |
232 |
char header[768], * p; |
char header[768], *p; |
233 |
|
|
234 |
if (r_type) |
if (r_type) |
235 |
*r_type = PGP_NONE; |
*r_type = PGP_NONE; |
272 |
|
|
273 |
/* Extract file type from @fname. If @r_type is valid, |
/* Extract file type from @fname. If @r_type is valid, |
274 |
it contains the PGP type on success. */ |
it contains the PGP type on success. */ |
275 |
static const char * |
static const char* |
276 |
fm_get_file_type (const char *fname, int *r_type) |
fm_get_file_type (const char *fname, int *r_type) |
277 |
{ |
{ |
278 |
gpg_iobuf_t inp; |
gpg_iobuf_t inp; |
279 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
280 |
PACKET *pkt; |
PACKET *pkt; |
281 |
const char *s = NULL; |
const char *s = NULL; |
282 |
|
size_t count = 0, compr = 0; |
283 |
int rc = 0; |
int rc = 0; |
284 |
|
|
285 |
if (r_type) |
if (r_type) |
337 |
s = "SECKEY"; rc = -2; |
s = "SECKEY"; rc = -2; |
338 |
if (r_type) *r_type = PGP_SECKEY; |
if (r_type) *r_type = PGP_SECKEY; |
339 |
break; |
break; |
340 |
|
|
341 |
|
case PKT_COMPRESSED: |
342 |
|
/* If we only find 1 packet and it is compressed, |
343 |
|
we assume a compress one-pass signature. */ |
344 |
|
if (count != 0) |
345 |
|
break; |
346 |
|
s = "SIGNED"; rc = -2; |
347 |
|
compr = 1; |
348 |
|
break; |
349 |
|
|
350 |
default: |
default: |
351 |
break; |
break; |
352 |
} |
} |
353 |
|
count++; |
354 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
355 |
gpg_init_packet (pkt); |
gpg_init_packet (pkt); |
356 |
if (rc == -2) |
if (rc == -2) |
362 |
s = fm_check_armor_type (fname, r_type); |
s = fm_check_armor_type (fname, r_type); |
363 |
if (!s) |
if (!s) |
364 |
s = "UNKNOWN"; |
s = "UNKNOWN"; |
365 |
if (!strcmp (s, "SIGNED") |
if (!strcmp (s, "SIGNED") && !compr |
366 |
&& strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) { |
&& strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) { |
367 |
if (r_type) *r_type = PGP_SIG; |
if (r_type) *r_type = PGP_SIG; |
368 |
s = "SIGNED-DETACH"; |
s = "SIGNED-DETACH"; |
371 |
} |
} |
372 |
|
|
373 |
|
|
374 |
|
/* Build the File Manager list view control. */ |
375 |
int |
int |
376 |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
377 |
{ |
{ |
378 |
int i, rc = 0; |
int i, rc = 0; |
379 |
listview_ctrl_t c; |
listview_ctrl_t c; |
380 |
struct listview_column_s col[] = |
struct listview_column_s col[] = { |
|
{ |
|
381 |
{0, 80, (char *)_("Status") }, |
{0, 80, (char *)_("Status") }, |
382 |
{1, 256, (char *)_("Name") }, |
{1, 256, (char *)_("Name") }, |
383 |
{2, 128, (char *)_("Operation") }, |
{2, 128, (char *)_("Operation") }, |
384 |
{0, 0, NULL } |
{0, 0, NULL} |
385 |
}; |
}; |
386 |
|
|
387 |
rc = listview_new( &c ); |
rc = listview_new (&c); |
388 |
if( rc ) |
if (rc) |
389 |
BUG( NULL ); |
BUG (NULL); |
390 |
c->ctrl = ctrl; |
c->ctrl = ctrl; |
391 |
for ( i = 0; col[i].width; i++ ) |
for (i = 0; col[i].width; i++) |
392 |
listview_add_column( c, &col[i] ); |
listview_add_column (c, &col[i]); |
393 |
listview_set_ext_style( c ); |
listview_set_ext_style (c); |
394 |
if( lv ) |
if (lv) |
395 |
*lv = c; |
*lv = c; |
396 |
return 0; |
return 0; |
397 |
} /* fm_build */ |
} |
398 |
|
|
399 |
|
|
400 |
|
/* Release the File Manager listview control. */ |
401 |
void |
void |
402 |
fm_delete( listview_ctrl_t lv ) |
fm_delete (listview_ctrl_t lv) |
403 |
{ |
{ |
404 |
if( lv ) { |
if (lv) { |
405 |
listview_release( lv ); |
listview_release(lv); |
406 |
} |
} |
407 |
} /* fm_delete */ |
} |
408 |
|
|
409 |
|
|
410 |
int |
int |
411 |
fm_state_new (fm_state_t * ctx) |
fm_state_new (fm_state_t * ctx) |
412 |
{ |
{ |
413 |
gpgme_error_t rc; |
gpgme_error_t rc; |
414 |
fm_state_s * c; |
fm_state_s *c; |
415 |
|
|
416 |
c = new fm_state_s; |
c = new fm_state_s; |
417 |
if (!c) |
if (!c) |
420 |
rc = gpgme_new (&c->ctx); |
rc = gpgme_new (&c->ctx); |
421 |
if (rc) |
if (rc) |
422 |
BUG (0); |
BUG (0); |
|
/* XXX rc = gpgme_recipients_new (&c->recp);*/ |
|
|
/* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */ |
|
423 |
*ctx = c; |
*ctx = c; |
424 |
return 0; |
return 0; |
425 |
} /* fm_state_new */ |
} |
426 |
|
|
427 |
|
|
428 |
/* Release the FM state handle @c. */ |
/* Release the FM state handle @c. */ |
431 |
{ |
{ |
432 |
if (!c) |
if (!c) |
433 |
return; |
return; |
|
if (c->recp) |
|
|
free (c->recp); |
|
434 |
if (c->ctx) { |
if (c->ctx) { |
435 |
gpgme_release (c->ctx); |
gpgme_release (c->ctx); |
436 |
c->ctx = NULL; |
c->ctx = NULL; |
437 |
} |
} |
438 |
|
safe_free (c->recp); |
439 |
free_if_alloc (c->opaque); |
free_if_alloc (c->opaque); |
440 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
441 |
delete c; c = NULL; |
delete c; |
442 |
} |
} |
443 |
|
|
444 |
|
|
445 |
static int |
static int |
446 |
fm_check_for_entry( listview_ctrl_t lv, const char *file ) |
fm_check_for_entry( listview_ctrl_t lv, const char *file ) |
447 |
{ |
{ |
456 |
} |
} |
457 |
|
|
458 |
return 0; |
return 0; |
459 |
} /* fm_check_for_entry */ |
} |
460 |
|
|
461 |
|
|
462 |
static int |
static int |
480 |
} |
} |
481 |
|
|
482 |
|
|
483 |
|
/* Add all files from the directory @path to the list view @lv. */ |
484 |
static int |
static int |
485 |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
486 |
{ |
{ |
527 |
if (rc == -1) |
if (rc == -1) |
528 |
break; /* XXX: fixme? */ |
break; /* XXX: fixme? */ |
529 |
} |
} |
530 |
|
DragFinish (dd_files); |
531 |
return rc; |
return rc; |
532 |
} |
} |
533 |
|
|
545 |
if (!type) |
if (!type) |
546 |
return WPTERR_FILE_OPEN; |
return WPTERR_FILE_OPEN; |
547 |
if (!strcmp (type, "UNKNOWN")) |
if (!strcmp (type, "UNKNOWN")) |
548 |
type = gnupg_check_file_ext (name, NULL); |
type = gnupg_check_file_ext (name, NULL); |
549 |
rc = listview_add_item (lv, ""); |
rc = listview_add_item (lv, ""); |
550 |
if (!rc) { |
if (!rc) { |
551 |
listview_add_sub_item (lv, 0, 0, type); |
listview_add_sub_item (lv, 0, 0, type); |
552 |
listview_add_sub_item (lv, 0, 1, name); |
listview_add_sub_item (lv, 0, 1, name); |
553 |
} |
} |
571 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
572 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
573 |
open.lpstrTitle = _("File Open"); |
open.lpstrTitle = _("File Open"); |
574 |
open.lpstrFilter = _("All Files (*.*)\0*.*\0\0"); |
open.lpstrFilter = "All Files (*.*)\0*.*\0\0"; |
575 |
open.hwndOwner = dlg; |
open.hwndOwner = dlg; |
576 |
open.lpstrFile = file; |
open.lpstrFile = file; |
577 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
599 |
else { |
else { |
600 |
char *p = make_filename (path, name, NULL); |
char *p = make_filename (path, name, NULL); |
601 |
rc = add_single_file (lv, p); |
rc = add_single_file (lv, p); |
602 |
free (p); |
safe_free (p); |
603 |
} |
} |
604 |
n++; |
n++; |
605 |
} |
} |
606 |
if (n == 1) /* single file selected. */ |
if (n == 1) /* single file selected. */ |
607 |
rc = add_single_file (lv, path); |
rc = add_single_file (lv, path); |
608 |
if (path) |
safe_free (path); |
|
free (path); |
|
609 |
return rc; |
return rc; |
610 |
} |
} |
611 |
|
|
612 |
|
|
613 |
int |
int |
614 |
fm_assume_onepass_sig (const char * fname) |
fm_assume_onepass_sig (const char * fname) |
615 |
{ |
{ |
|
gpgme_data_t dat; |
|
616 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
617 |
gpg_iobuf_t fp; |
gpg_iobuf_t fp; |
618 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
gpgme_data_t dat; |
619 |
|
PACKET *pkt; |
620 |
|
char tmpfile[MAX_PATH+1]; |
621 |
int check = 0; |
int check = 0; |
622 |
|
|
623 |
|
pkt = (PACKET *)calloc (1, sizeof *pkt); |
624 |
if (!fname) { |
if (!fname) { |
625 |
|
get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp"); |
626 |
gpg_data_new_from_clipboard (&dat, 0); |
gpg_data_new_from_clipboard (&dat, 0); |
627 |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
gpg_data_release_and_set_file (dat, tmpfile); |
628 |
|
|
629 |
fp = gpg_iobuf_open ("gpgme.tmp"); |
fp = gpg_iobuf_open (tmpfile); |
630 |
if (!fp) |
if (!fp) |
631 |
return 0; |
return 0; |
632 |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
639 |
&& pkt->pkttype == PKT_COMPRESSED) |
&& pkt->pkttype == PKT_COMPRESSED) |
640 |
check = 1; |
check = 1; |
641 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
|
safe_free (pkt); |
|
642 |
gpg_iobuf_close (fp); |
gpg_iobuf_close (fp); |
643 |
remove ("gpgme.tmp"); |
remove (tmpfile); |
644 |
} |
} |
645 |
/* XXX: implement it for real files */ |
/* XXX: implement it for real files */ |
646 |
|
safe_free (pkt); |
647 |
return check; |
return check; |
648 |
} |
} |
649 |
|
|
656 |
items = listview_count_items (lv, 0); |
items = listview_count_items (lv, 0); |
657 |
if (!items) |
if (!items) |
658 |
return -1; |
return -1; |
659 |
else if (items == 1) |
else if (items == 1) { |
|
{ |
|
660 |
listview_select_one (lv, 0); |
listview_select_one (lv, 0); |
661 |
return 0; |
return 0; |
662 |
} |
} |
663 |
else if (items > 1) |
else if (items > 1) { |
|
{ |
|
664 |
i = listview_get_curr_pos (lv); |
i = listview_get_curr_pos (lv); |
665 |
if (i == -1) |
if (i == -1) { |
666 |
{ |
msg_box (lv->ctrl, _("Please select a file."), |
667 |
msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
668 |
return -1; |
return -1; |
669 |
} |
} |
670 |
return i; |
return i; |
671 |
} |
} |
672 |
|
|
673 |
return -1; |
return -1; |
674 |
} /* fm_get_current_pos */ |
} |
675 |
|
|
676 |
|
|
677 |
static int |
static int |
678 |
fm_check_detached_sig( listview_ctrl_t lv, int pos ) |
fm_check_detached_sig (listview_ctrl_t lv, int pos) |
679 |
{ |
{ |
680 |
char type[128]; |
char type[128]; |
681 |
|
|
682 |
listview_get_item_text( lv, pos, 0, type, 127 ); |
listview_get_item_text (lv, pos, 0, type, sizeof (type)-1); |
683 |
return !strcmp( type, "SIGNED-DETACH" )? 1 : 0; |
return !strcmp (type, "SIGNED-DETACH")? 1 : 0; |
684 |
} /* fm_check_detached_sig */ |
} |
685 |
|
|
686 |
|
|
687 |
int |
int |
738 |
} |
} |
739 |
|
|
740 |
return rc; |
return rc; |
741 |
} /* fm_check_file_type */ |
} |
742 |
|
|
743 |
|
|
744 |
|
/* Set the file status of the given command @fm_cmd. |
745 |
|
@success is 0 on success. */ |
746 |
static void |
static void |
747 |
fm_set_status (listview_ctrl_t lv, int pos, int fm_cmd, int success, |
fm_set_status (listview_ctrl_t lv, int pos, int fm_cmd, |
748 |
const char * output) |
gpgme_sig_mode_t sigmode, int success, const char *output) |
749 |
{ |
{ |
750 |
char status[128], operat[128]; |
char status[128], operat[128]; |
751 |
int update = 1; |
int update = 1; |
752 |
const char *s; |
const char *s; |
753 |
|
|
754 |
if ( fm_cmd == FM_LIST ) |
if (fm_cmd == FM_LIST) |
755 |
return; |
return; |
756 |
success ? s = "SUCCESS" : s = "FAILED"; |
success ? s = "SUCCESS" : s = "FAILED"; |
757 |
strcpy( operat, s ); |
strcpy (operat, s); |
758 |
|
|
759 |
switch (fm_cmd) { |
switch (fm_cmd) { |
760 |
case FM_ENCRYPT: |
case FM_ENCRYPT: |
761 |
case FM_ENCRYPT_DIR: |
case FM_ENCRYPT_DIR: |
762 |
case FM_SIGNENCRYPT: strcpy( status, "ENCRYPTED" ); break; |
case FM_SIGNENCRYPT: strcpy (status, "ENCRYPTED"); break; |
763 |
case FM_DECRYPT: strcpy( status, "UNKNOWN" ); break; |
case FM_DECRYPT: strcpy (status, "UNKNOWN"); break; |
764 |
case FM_SIGN: strcpy( status, "SIGNED" ); break; |
case FM_SIGN: |
765 |
|
if (sigmode == GPGME_SIG_MODE_DETACH) |
766 |
|
strcpy (status, "SIGNED-DETACH"); |
767 |
|
else if (sigmode == GPGME_SIG_MODE_CLEAR) |
768 |
|
strcpy (status, "SIGNED-CLEAR"); |
769 |
|
else |
770 |
|
strcpy (status, "SIGNED"); |
771 |
|
break; |
772 |
case FM_VERIFY: update = 0; break; |
case FM_VERIFY: update = 0; break; |
773 |
case FM_SYMENC: strcpy( status, "SYMKEYENC" ); break; |
case FM_SYMENC: strcpy (status, "SYMKEYENC"); break; |
774 |
case FM_IMPORT: update = 0; break; |
case FM_IMPORT: update = 0; break; |
775 |
case FM_WIPE: strcpy( status, "WIPED" ); break; |
case FM_WIPE: strcpy (status, "WIPED"); break; |
776 |
default: strcpy( status, "UNKNOWN"); break; |
default: strcpy (status, "UNKNOWN"); break; |
777 |
} |
} |
778 |
|
|
779 |
if (success) { |
if (success && update) { |
780 |
if (update) { |
listview_add_sub_item (lv, pos, 0, status); |
781 |
listview_add_sub_item (lv, pos, 0, status); |
listview_add_sub_item (lv, pos, 1, output); |
|
listview_add_sub_item (lv, pos, 1, output); |
|
|
} |
|
782 |
} |
} |
783 |
listview_add_sub_item( lv, pos, 2, operat ); |
listview_add_sub_item( lv, pos, 2, operat ); |
784 |
} /* fm_set_status */ |
} |
785 |
|
|
786 |
|
|
787 |
int |
int |
809 |
if (!cnt) |
if (!cnt) |
810 |
return 0; |
return 0; |
811 |
n = -1; |
n = -1; |
812 |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
813 |
_("\"%s\" does not seems to be a text file.\n" |
_("\"%s\" does not seems to be a text file.\n" |
814 |
"Do you really want to clearsign it?"), name); |
"Do you really want to clearsign it?"), name); |
815 |
if (i == IDYES) |
if (i == IDYES) |
817 |
return n; |
return n; |
818 |
} |
} |
819 |
|
|
820 |
|
|
821 |
int |
int |
822 |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
823 |
{ |
{ |
869 |
case FM_SIGNENCRYPT: |
case FM_SIGNENCRYPT: |
870 |
if (fm_cmd == FM_SIGNENCRYPT) |
if (fm_cmd == FM_SIGNENCRYPT) |
871 |
ctx->req_signer = 1; |
ctx->req_signer = 1; |
872 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_ENCRYPT, ctx->dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_ENCRYPT, |
873 |
file_encrypt_dlg_proc, (LPARAM)ctx); |
ctx->dlg, file_encrypt_dlg_proc, (LPARAM)ctx); |
874 |
if (ctx->cancel == 1) { |
if (ctx->cancel == 1) { |
875 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
876 |
goto leave; |
goto leave; |
877 |
} |
} |
878 |
break; |
break; |
915 |
if (!confirm.yes) |
if (!confirm.yes) |
916 |
goto leave; |
goto leave; |
917 |
} |
} |
918 |
|
|
919 |
if (fm_cmd == FM_ENCRYPT_ZIP) |
if (fm_cmd == FM_ENCRYPT_ZIP) |
920 |
fm_encrypt_into_zip (ctx, lv); |
fm_encrypt_into_zip (ctx, lv); |
921 |
|
|
922 |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
923 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
924 |
continue; |
continue; |
925 |
listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 ); |
listview_get_item_text (lv, i, 1, fname, sizeof (fname) - 1); |
926 |
if( file_exist_check( fname ) && !is_directory( fname ) ) { |
if( file_exist_check (fname) && !is_directory (fname)) { |
927 |
log_box( _("File Manager"), MB_ERR, _("\"%s\" does not exist"), fname ); |
log_box (_("File Manager"), MB_ERR, |
928 |
|
_("\"%s\" does not exist"), fname); |
929 |
continue; |
continue; |
930 |
} |
} |
931 |
if( is_directory( fname ) ) |
if (is_directory (fname)) |
932 |
fm_cmd = FM_ENCRYPT_DIR; |
fm_cmd = FM_ENCRYPT_DIR; |
933 |
if( !fm_check_file_type( lv, i, fm_cmd ) ) |
if (!fm_check_file_type (lv, i, fm_cmd)) |
934 |
continue; |
continue; |
935 |
sig_detached = fm_check_detached_sig( lv, i ); |
sig_detached = fm_check_detached_sig (lv, i); |
936 |
switch (fm_cmd) { |
switch (fm_cmd) { |
937 |
case FM_LIST: rc = fm_list( fname, dlg ); break; |
case FM_LIST: rc = fm_list( fname, dlg ); break; |
938 |
case FM_WIPE: rc = fm_wipe( fname ); break; |
case FM_WIPE: rc = fm_wipe( fname ); break; |
941 |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
942 |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
943 |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
944 |
case FM_SYMENC: rc = fm_sym_encrypt( ctx, fname );break; |
case FM_SYMENC: rc = fm_sym_encrypt (ctx, fname); break; |
945 |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
946 |
case FM_IMPORT: |
case FM_IMPORT: |
947 |
free_if_alloc (ctx->opaque); |
free_if_alloc (ctx->opaque); |
948 |
ctx->opaque = m_strdup (fname); |
ctx->opaque = m_strdup (fname); |
949 |
if (!ctx->opaque) |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
950 |
BUG (0); |
file_import_dlg_proc, (LPARAM)ctx); |
|
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
|
|
file_import_dlg_proc, (LPARAM)ctx ); |
|
951 |
if (ctx->cancel == 1) |
if (ctx->cancel == 1) |
952 |
continue; |
continue; |
953 |
rc = fm_import (ctx, fname); |
rc = fm_import (ctx, fname); |
954 |
break; |
break; |
955 |
} |
} |
956 |
fm_set_status (lv, i, fm_cmd, !rc, ctx->output); |
if (ctx->cancel == 1) { |
957 |
|
ctx->cancel = 0; |
958 |
|
continue; |
959 |
|
} |
960 |
|
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
961 |
free_if_alloc (ctx->output); |
free_if_alloc (ctx->output); |
962 |
progress_cleanup (&pfx); |
progress_cleanup (&pfx); |
963 |
} |
} |
1027 |
free_if_alloc (*dst); |
free_if_alloc (*dst); |
1028 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1029 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (0); |
|
1030 |
if (dst) |
if (dst) |
1031 |
*dst = fm_quote_file (s); |
*dst = fm_quote_file (s); |
1032 |
return 0; |
return 0; |
1049 |
BUG (0); |
BUG (0); |
1050 |
strcpy (ext, file_get_extension (ctx, c->sigmode)); |
strcpy (ext, file_get_extension (ctx, c->sigmode)); |
1051 |
strcpy (c->output, name); |
strcpy (c->output, name); |
1052 |
strcat (c->output, ext); |
strcat (c->output, ext); |
1053 |
|
|
1054 |
if (!overwrite_file (c->output)) { |
if (!overwrite_file (c->output)) { |
1055 |
rc = ask_filename (c, _("Enter filename for encrypted file"), NULL); |
rc = ask_filename (c, _("Enter filename for encrypted file"), NULL); |
1057 |
goto leave; |
goto leave; |
1058 |
} |
} |
1059 |
|
|
1060 |
err = gpg_file_data_new (name, 1, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1061 |
if (err) |
if (err) |
1062 |
goto leave; |
goto leave; |
1063 |
err = gpg_file_data_new (c->output, 0, &out); |
remove_crit_file_attrs (c->output, 0); |
1064 |
|
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
1065 |
if (err) |
if (err) |
1066 |
goto leave; |
goto leave; |
1067 |
|
|
1072 |
} |
} |
1073 |
*/ |
*/ |
1074 |
|
|
1075 |
/* XXX |
/* XXX: disable compression for multi-media files. |
1076 |
no_compr = is_multi_media (name); |
no_compr = is_multi_media (name); |
1077 |
gpgme_control (ctx, GPGME_CTRL_NO_COMPR, no_compr); |
gpgme_control (ctx, GPGME_CTRL_NO_COMPR, no_compr); |
1078 |
*/ |
*/ |
1094 |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
1095 |
if (sigkey && sigkey->subkeys) { |
if (sigkey && sigkey->subkeys) { |
1096 |
keyid = m_strdup (sigkey->subkeys->keyid); |
keyid = m_strdup (sigkey->subkeys->keyid); |
|
if (!keyid) |
|
|
BUG (NULL); |
|
1097 |
} |
} |
1098 |
} |
} |
1099 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1153 |
char ext[5], * pass; |
char ext[5], * pass; |
1154 |
|
|
1155 |
pass = request_passphrase2 (_("Symmetric"), 0, &cancel); |
pass = request_passphrase2 (_("Symmetric"), 0, &cancel); |
1156 |
if (cancel) |
if (cancel) { |
1157 |
|
c->cancel = 1; |
1158 |
return 0; |
return 0; |
1159 |
|
} |
1160 |
|
|
1161 |
/* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/ |
/* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/ |
1162 |
c->output = new char[strlen (name) + 5 + 1]; |
c->output = new char[strlen (name) + 5 + 1]; |
1201 |
gpg_file_data_release (out); |
gpg_file_data_release (out); |
1202 |
sfree_if_alloc (pass); |
sfree_if_alloc (pass); |
1203 |
return rc; |
return rc; |
1204 |
} /* fm_sym_encrypt */ |
} |
1205 |
|
|
1206 |
|
|
1207 |
|
char* get_pka_status (gpgme_signature_t sig); |
1208 |
|
|
1209 |
|
|
1210 |
/* Show the human readable verify result from @sigres. */ |
/* Show the human readable verify result from @sigres. */ |
1214 |
gpgme_key_t key=NULL; |
gpgme_key_t key=NULL; |
1215 |
gpgme_signature_t sig=sigres->signatures; |
gpgme_signature_t sig=sigres->signatures; |
1216 |
const char *s, *keyid; |
const char *s, *keyid; |
1217 |
int sigok = 0; |
char *uid, *pka_info; |
|
int type; |
|
1218 |
char buf[384]; |
char buf[384]; |
1219 |
|
int sigok = 0; |
1220 |
|
|
1221 |
sig = sigres->signatures; |
sig = sigres->signatures; |
1222 |
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
1223 |
s = sigok? _("Good signature") : _("BAD signature"); |
s = sigok? _("Good signature") : _("BAD signature"); |
1224 |
type = sigok? MB_OK: MB_ICONWARNING|MB_OK; |
keyid = sig->fpr; |
|
keyid = sig->fpr; |
|
1225 |
if (!keyid) |
if (!keyid) |
1226 |
return; |
return; |
1227 |
|
pka_info = get_pka_status (sig); |
1228 |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24; |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24; |
1229 |
get_pubkey (sig->fpr, &key); |
get_pubkey (sig->fpr, &key); |
1230 |
_snprintf (buf, sizeof (buf)-1, "Signature made %s using %s key ID %s\n" |
|
1231 |
"%s from \"%s\"", |
if (key) |
1232 |
strtimestamp (sig->timestamp), get_key_pubalgo (sig->pubkey_algo), |
uid = utf8_to_native (key->uids->uid); |
1233 |
keyid, s, key? key->uids->uid : _("user ID not found")); |
else |
1234 |
msg_box (NULL, buf, _("Decrypt Verify"), type); |
uid = strdup (_("user ID not found")); |
1235 |
|
|
1236 |
|
_snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n" |
1237 |
|
"%s from \"%s\"\n%s"), |
1238 |
|
strtimestamp (sig->timestamp), |
1239 |
|
get_key_pubalgo (sig->pubkey_algo), |
1240 |
|
keyid, s, uid, pka_info? pka_info : ""); |
1241 |
|
msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK); |
1242 |
|
free_if_alloc (pka_info); |
1243 |
|
safe_free (uid); |
1244 |
} |
} |
1245 |
|
|
1246 |
|
|
1251 |
gpgme_recipient_t r; |
gpgme_recipient_t r; |
1252 |
gpgme_key_t key; |
gpgme_key_t key; |
1253 |
|
|
1254 |
for (r=rset; r; r = r->next) { |
for (r=rset; r; r = r->next) { |
1255 |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
1256 |
continue; |
continue; |
1257 |
else { |
else { |
1264 |
} |
} |
1265 |
|
|
1266 |
|
|
1267 |
|
/* If the decrypt result contains the original file name, |
1268 |
|
we use it instead of the artificial "output - .gpg" string. */ |
1269 |
|
static int |
1270 |
|
restore_original_name (const char *output, const char *file_name) |
1271 |
|
{ |
1272 |
|
char *dir; |
1273 |
|
char *orig; |
1274 |
|
int rc = 0; |
1275 |
|
|
1276 |
|
dir = strrchr (output, '\\'); |
1277 |
|
if (!dir) |
1278 |
|
orig = strdup (file_name); |
1279 |
|
else { |
1280 |
|
orig = (char*)calloc (1, strlen (file_name)+ 1 + |
1281 |
|
strlen (output)+1); |
1282 |
|
if (!orig) |
1283 |
|
BUG (0); |
1284 |
|
memcpy (orig, output, (dir-output)+1); |
1285 |
|
strcat (orig, file_name); |
1286 |
|
} |
1287 |
|
if (overwrite_file (orig)) { |
1288 |
|
DeleteFile (orig); |
1289 |
|
if (!MoveFile (output, orig)) |
1290 |
|
rc = -1; |
1291 |
|
} |
1292 |
|
safe_free (orig); |
1293 |
|
return rc; |
1294 |
|
} |
1295 |
|
|
1296 |
|
|
1297 |
/* Decrypt the file @name. */ |
/* Decrypt the file @name. */ |
1298 |
int |
int |
1299 |
fm_decrypt (fm_state_t c, const char *name) |
fm_decrypt (fm_state_t c, const char *name) |
1302 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1303 |
gpgme_decrypt_result_t res; |
gpgme_decrypt_result_t res; |
1304 |
gpgme_verify_result_t sigres; |
gpgme_verify_result_t sigres; |
1305 |
file_data_t in =NULL, out=NULL; |
file_data_t in = NULL, out = NULL; |
1306 |
int rc = 0; |
int rc = 0; |
1307 |
|
|
1308 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1309 |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT, |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT, |
1310 |
c->dlg, _("Decryption")); |
c->dlg, _("Decryption")); |
1311 |
c->init_cb = 1; |
c->init_cb = 1; |
1312 |
} |
} |
1313 |
|
|
1314 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (0); |
|
1315 |
if (is_openpgp_ext (c->output)) |
if (is_openpgp_ext (c->output)) |
1316 |
c->output[strlen (c->output)-4] = '\0'; |
c->output[strlen (c->output)-4] = '\0'; |
1317 |
else { |
else { |
1321 |
if (s) { |
if (s) { |
1322 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1323 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1324 |
} |
} |
1325 |
} |
} |
1326 |
|
|
1328 |
rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL); |
rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL); |
1329 |
if (rc) |
if (rc) |
1330 |
goto leave; |
goto leave; |
1331 |
} |
} |
|
|
|
|
remove_crit_file_attrs (c->output, 0); |
|
1332 |
|
|
1333 |
err = gpg_file_data_new (name, 1, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1334 |
if (err) |
if (err) |
1335 |
goto leave; |
goto leave; |
1336 |
err = gpg_file_data_new (c->output, 0, &out); |
remove_crit_file_attrs (c->output, 0); |
1337 |
|
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
1338 |
if (err) |
if (err) |
1339 |
goto leave; |
goto leave; |
1340 |
|
|
1354 |
char *p = get_key_userid (keyid+8); |
char *p = get_key_userid (keyid+8); |
1355 |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
1356 |
|
|
1357 |
log_box( _("Decryption"), MB_ERR, |
log_box (_("Decryption"), MB_ERR, |
1358 |
_("Encrypted with %s key, ID %s.%s\n" |
_("Encrypted with %s key, ID %s.%s\n" |
1359 |
"Decryption failed: secret key not available."), |
"Decryption failed: secret key not available."), |
1360 |
get_key_pubalgo (pkalgo), keyid+8, p); |
get_key_pubalgo (pkalgo), keyid+8, p); |
1368 |
goto leave; |
goto leave; |
1369 |
} |
} |
1370 |
if (file_exist_check (c->output)) { |
if (file_exist_check (c->output)) { |
1371 |
log_box ("Decrypt", MB_ERR, _("Decryption failed.\n%s: does not exist."), c->output); |
log_box ("Decrypt", MB_ERR, |
1372 |
|
_("Decryption failed.\n%s: does not exist."), c->output); |
1373 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1374 |
|
goto leave; |
1375 |
|
} |
1376 |
|
else if (res && res->file_name) { |
1377 |
|
char *file = strrchr (c->output, '\\'); |
1378 |
|
int id = log_box (_("Decrypt"), MB_QUEST_ASK, |
1379 |
|
_("The original file name is '%s'.\n\n" |
1380 |
|
"Do you want to use this instead of '%s'?"), |
1381 |
|
res->file_name, file? file+1 : c->output); |
1382 |
|
if (id == IDYES) { |
1383 |
|
/* before we can move the file, it needs to be closed first. */ |
1384 |
|
gpg_file_data_release (out); |
1385 |
|
out = NULL; |
1386 |
|
restore_original_name (c->output, res->file_name); |
1387 |
|
} |
1388 |
} |
} |
|
|
|
1389 |
sigres = gpgme_op_verify_result (ctx); |
sigres = gpgme_op_verify_result (ctx); |
1390 |
if (sigres && sigres->signatures) |
if (sigres && sigres->signatures) |
1391 |
show_verify_result (sigres); |
show_verify_result (sigres); |
1392 |
|
|
1393 |
leave: |
leave: |
1394 |
if (in) |
if (in) |
1395 |
gpg_file_data_release (in); |
gpg_file_data_release (in); |
1396 |
if (out) |
if (out) |
1397 |
gpg_file_data_release (out); |
gpg_file_data_release (out); |
1398 |
|
|
1399 |
return rc; |
return rc; |
1400 |
} |
} |
1401 |
|
|
1402 |
|
|
1403 |
int |
int |
1404 |
fm_sign (fm_state_t c, const char * name) |
fm_sign (fm_state_t c, const char * name) |
1405 |
{ |
{ |
|
int rc = 0; |
|
1406 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1407 |
gpgme_error_t err; |
gpgme_error_t err; |
1408 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1409 |
char ext[5]; |
char ext[5]; |
1410 |
|
int rc = 0; |
1411 |
|
|
1412 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1413 |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_SIGN, c->dlg, _("Signing") ); |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, |
1414 |
|
GPG_CMD_SIGN, c->dlg, _("Signing")); |
1415 |
c->init_cb = 1; |
c->init_cb = 1; |
1416 |
} |
} |
1417 |
|
|
1418 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1419 |
c->output = new char[strlen (name) + 5 + 1]; |
c->output = new char[strlen (name) + 5 + 1]; |
1420 |
if( !c->output) |
if (!c->output) |
1421 |
BUG( NULL ); |
BUG (NULL); |
1422 |
strcpy (ext, file_get_extension (ctx, c->sigmode)); |
strcpy (ext, file_get_extension (ctx, c->sigmode)); |
1423 |
strcpy (c->output, name); |
strcpy (c->output, name); |
1424 |
strcat (c->output, ext); |
strcat (c->output, ext); |
1428 |
if (rc) |
if (rc) |
1429 |
goto leave; |
goto leave; |
1430 |
} |
} |
1431 |
remove_crit_file_attrs (c->output, 0); |
|
1432 |
|
err = gpg_file_data_new (name, F_DATA_READ, &in); |
|
err = gpg_file_data_new (name, 1, &in); |
|
1433 |
if (err) |
if (err) |
1434 |
goto leave; |
goto leave; |
1435 |
err = gpg_file_data_new (c->output, 0, &out); |
remove_crit_file_attrs (c->output, 0); |
1436 |
|
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
1437 |
if (err) |
if (err) |
1438 |
goto leave; |
goto leave; |
1439 |
|
|
1440 |
op_begin (); |
op_begin (); |
1441 |
err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode); |
err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode); |
1442 |
op_end (); |
op_end (); |
1443 |
if( !c->cache_cb ) |
if (!c->cache_cb) |
1444 |
release_gpg_passphrase_cb (&c->pass_cb); |
release_gpg_passphrase_cb (&c->pass_cb); |
1445 |
if( c->pass_cb.cancel ) { |
if (c->pass_cb.cancel) { |
1446 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1447 |
goto leave; |
goto leave; |
1448 |
} |
} |
1449 |
if( err ) { |
if (err) { |
1450 |
msg_box( c->dlg, gpgme_strerror( err ), _("Sign"), MB_ERR ); |
msg_box (c->dlg, gpgme_strerror (err), _("Sign"), MB_ERR); |
1451 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1452 |
goto leave; |
goto leave; |
1453 |
} |
} |
1461 |
} |
} |
1462 |
|
|
1463 |
|
|
1464 |
static int |
static void |
1465 |
fm_add_sig_stat (file_sig_ctx_t log) |
fm_add_sig_stat (file_sig_ctx_t log) |
1466 |
{ |
{ |
1467 |
gpgme_key_t key; |
gpgme_key_t key; |
1481 |
log->use_uid = 1; |
log->use_uid = 1; |
1482 |
} |
} |
1483 |
file_verify_add_state (log); |
file_verify_add_state (log); |
|
return 0; |
|
1484 |
} |
} |
1485 |
|
|
1486 |
|
|
1487 |
|
/* Verify a detached signature from the clipboard. */ |
1488 |
static int |
static int |
1489 |
verify_pasted (listview_ctrl_t lv, fm_state_t ctx, const char * dat, |
verify_pasted (listview_ctrl_t lv, fm_state_t ctx, |
1490 |
int i, HWND dlg) |
const char *dat, int pos, HWND dlg) |
1491 |
{ |
{ |
1492 |
FILE * fp; |
FILE *fp; |
1493 |
char stat[32]; |
char stat[32]; |
1494 |
char file[256], * fname = NULL; |
char file[256], *fname = NULL; |
1495 |
int del_end=0; |
int del_end = 0; |
1496 |
|
|
1497 |
listview_get_item_text (lv, i, 0, stat, sizeof (stat)-1); |
listview_get_item_text (lv, pos, 0, stat, sizeof (stat)-1); |
1498 |
listview_get_item_text (lv, i, 1, file, sizeof (file)-1); |
listview_get_item_text (lv, pos, 1, file, sizeof (file)-1); |
1499 |
if (strcmp (stat, "UNKNOWN")) |
if (strcmp (stat, "UNKNOWN")) |
1500 |
return 0; |
return 0; |
1501 |
fname = make_filename (NULL, file, "asc"); |
fname = make_filename (NULL, file, "asc"); |
1504 |
if (fp == NULL) { |
if (fp == NULL) { |
1505 |
log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname); |
log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname); |
1506 |
free_if_alloc (fname); |
free_if_alloc (fname); |
1507 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1508 |
} |
} |
1509 |
fwrite (dat, 1, strlen (dat), fp); |
fwrite (dat, 1, strlen (dat), fp); |
1510 |
fclose (fp); |
fclose (fp); |
1511 |
del_end = 1; |
del_end = 1; |
1518 |
} |
} |
1519 |
|
|
1520 |
|
|
1521 |
|
/* Figure out if the clipboard contains a detached signature. */ |
1522 |
int |
int |
1523 |
fm_verify_pasted_detsig (listview_ctrl_t lv, HWND dlg) |
fm_verify_pasted_detsig (listview_ctrl_t lv, HWND dlg) |
1524 |
{ |
{ |
1536 |
/* XXX find a way to filter out bad signatures or just ignore all in |
/* XXX find a way to filter out bad signatures or just ignore all in |
1537 |
this case */ |
this case */ |
1538 |
fm_state_new (&ctx); |
fm_state_new (&ctx); |
1539 |
if ((i=listview_get_curr_pos (lv)) != -1) { |
i = listview_get_curr_pos (lv); |
1540 |
|
if (i= -1) { |
1541 |
verify_pasted (lv, ctx, dat, i, dlg); |
verify_pasted (lv, ctx, dat, i, dlg); |
1542 |
fnd = 1; |
fnd = 1; |
1543 |
} |
} |
1569 |
else |
else |
1570 |
title = _("Selected Output File"); |
title = _("Selected Output File"); |
1571 |
|
|
1572 |
if (strstr (name, ".sig") || strstr (name, ".asc") || strstr (name, ".gpg")) { |
if (stristr (name, ".sig") || |
1573 |
|
stristr (name, ".asc") || |
1574 |
|
stristr (name, ".gpg")) { |
1575 |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
1576 |
fname[strlen (fname) - 4] = '\0'; |
fname[strlen (fname) - 4] = '\0'; |
1577 |
if (file_exist_check (fname) == 0 && detached) |
if (file_exist_check (fname) == 0 && detached) |
1593 |
if (file) { |
if (file) { |
1594 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1595 |
c->output = m_strdup (file); |
c->output = m_strdup (file); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1596 |
} |
} |
1597 |
else { |
else { |
1598 |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
1601 |
if (detached) |
if (detached) |
1602 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
c->sigmode = GPGME_SIG_MODE_DETACH; |
1603 |
else { |
else { |
1604 |
if (strstr (name, ".asc")) |
if (stristr (name, ".asc")) |
1605 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
1606 |
else |
else |
1607 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
1623 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1624 |
int rc = 0; |
int rc = 0; |
1625 |
|
|
1626 |
if (strstr (name, ".sig")) |
if (stristr (name, ".sig")) |
1627 |
detached = 1; |
detached = 1; |
1628 |
|
|
1629 |
if (get_output_file (c, name, detached)) |
if (get_output_file (c, name, detached)) |
1631 |
|
|
1632 |
memset (&log, 0, sizeof (log)); |
memset (&log, 0, sizeof (log)); |
1633 |
log.file = m_strdup (name); |
log.file = m_strdup (name); |
|
if (!log.file) |
|
|
BUG (NULL); |
|
1634 |
file_verify_create_dlg (); |
file_verify_create_dlg (); |
1635 |
|
|
1636 |
err = gpg_file_data_new (name, 1, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1637 |
if (err) |
if (err) |
1638 |
goto leave; |
goto leave; |
1639 |
err = gpg_file_data_new (c->output, detached? 1 : 0, &out); |
err = gpg_file_data_new (c->output, |
1640 |
|
detached? F_DATA_READ : F_DATA_WRITE, &out); |
1641 |
if (err) |
if (err) |
1642 |
goto leave; |
goto leave; |
1643 |
|
|
1666 |
gpg_file_data_release (in); |
gpg_file_data_release (in); |
1667 |
if (out) |
if (out) |
1668 |
gpg_file_data_release (out); |
gpg_file_data_release (out); |
1669 |
if (log.file) |
free_if_alloc (log.file); |
|
delete []log.file; |
|
1670 |
return rc; |
return rc; |
1671 |
} |
} |
1672 |
|
|
1673 |
|
|
1674 |
|
/* Import the keys from the file @name. |
1675 |
|
Return value: 0 on success. */ |
1676 |
int |
int |
1677 |
fm_import (fm_state_t c, const char *name) |
fm_import (fm_state_t c, const char *name) |
1678 |
{ |
{ |
1684 |
|
|
1685 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1686 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1687 |
|
|
1688 |
err = gpg_file_data_new (name, 1, &keydata); |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
1689 |
if (err) |
if (err) |
1690 |
goto leave; |
goto leave; |
1691 |
|
|
1701 |
res = gpgme_op_import_result (ctx); |
res = gpgme_op_import_result (ctx); |
1702 |
print_import_status (res); |
print_import_status (res); |
1703 |
if (res->no_user_id > 0) { |
if (res->no_user_id > 0) { |
1704 |
msg_box (c->dlg, _("Key without a self signature was dectected!\n" |
msg_box (c->dlg, _("Key without a self signature was dectected!\n" |
1705 |
"(This key is NOT usable for encryption, etc)\n" |
"(This key is NOT usable for encryption, etc)\n" |
1706 |
"\n" |
"\n" |
1707 |
"Cannot import these key(s)!"), _("Import"), MB_INFO); |
"Cannot import these key(s)!"), _("Import"), MB_INFO); |
1711 |
if (keydata) |
if (keydata) |
1712 |
gpg_file_data_release (keydata); |
gpg_file_data_release (keydata); |
1713 |
return rc; |
return rc; |
1714 |
} /* fm_import */ |
} |
1715 |
|
|
1716 |
|
|
1717 |
/* Export the selected keys from the File Manager to a file. */ |
/* Export the selected keys from the File Manager to a file. */ |
1718 |
int |
int |
1719 |
fm_export (fm_state_t c) |
fm_export (fm_state_t c) |
1720 |
{ |
{ |
|
int rc = 0; |
|
1721 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1722 |
gpgme_error_t err; |
gpgme_error_t err; |
1723 |
gpgme_key_t *rset = c->recp; |
gpgme_key_t *rset = c->recp; |
1724 |
file_data_t keydata = NULL; |
file_data_t keydata = NULL; |
1725 |
const char *name; |
const char *name; |
1726 |
char *p = NULL, *patt = NULL; |
char *p = NULL, *patt = NULL; |
1727 |
|
int rc = 0; |
1728 |
|
|
1729 |
if (!rset || !rset[0]) { |
if (!rset || !rset[0]) { |
1730 |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
1732 |
goto leave; |
goto leave; |
1733 |
} |
} |
1734 |
|
|
1735 |
if (rset[1] == NULL) { /* count == 1*/ |
if (rset[1] == NULL) /* count == 1*/ |
1736 |
gpgme_key_t k = rset[0]; |
p = km_gen_export_filename (rset[0]->subkeys->keyid+8, 0); |
|
const char *s = k->uids->name; |
|
|
p = new char[strlen (s)+1+8]; |
|
|
if (!p) |
|
|
BUG (NULL); |
|
|
strcpy (p, s ); |
|
|
strcat (p, ".asc"); |
|
|
} |
|
1737 |
|
|
1738 |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
1739 |
NULL, p? p : NULL); |
NULL, p? p : NULL); |
|
|
|
1740 |
if (!name) |
if (!name) |
1741 |
name = "keys.gpg"; |
name = "keys.gpg"; |
1742 |
|
|
1743 |
patt = gpg_keylist_to_pattern (rset, c->n_recp); |
patt = gpg_keylist_to_pattern (rset, c->n_recp); |
1744 |
|
|
1745 |
err = gpg_file_data_new (name, 0, &keydata); |
err = gpg_file_data_new (name, F_DATA_WRITE, &keydata); |
1746 |
if (err) |
if (err) |
1747 |
goto leave; |
goto leave; |
1748 |
|
|
1759 |
leave: |
leave: |
1760 |
if (keydata) |
if (keydata) |
1761 |
gpg_file_data_release (keydata); |
gpg_file_data_release (keydata); |
1762 |
if (patt) |
safe_free (patt); |
|
free (patt); |
|
1763 |
free_if_alloc (p); |
free_if_alloc (p); |
|
|
|
1764 |
return rc; |
return rc; |
1765 |
} |
} |
1766 |
|
|
1816 |
|
|
1817 |
case PGP_SIG: |
case PGP_SIG: |
1818 |
case PGP_CLEARSIG: |
case PGP_CLEARSIG: |
|
file_verify_use_event (); |
|
1819 |
if (type == PGP_SIG) |
if (type == PGP_SIG) |
1820 |
detached = 1; |
detached = 1; |
1821 |
fm_verify (ctx, detached, fn); |
fm_verify (ctx, detached, fn); |
1822 |
file_verify_wait (); |
file_verify_wait (); |
1823 |
break; |
break; |
1824 |
|
|
1825 |
default: |
default: |
1826 |
break; |
break; |
1827 |
} |
} |
1834 |
} |
} |
1835 |
|
|
1836 |
|
|
1837 |
|
/* Extract the last folder name from @name. */ |
1838 |
const char* |
const char* |
1839 |
default_dirname (const char *name) |
default_dirname (const char *name) |
1840 |
{ |
{ |
1841 |
char * p = strrchr( name, '\\' ); |
char *p = strrchr (name, '\\'); |
1842 |
if( !p ) |
if (!p) |
1843 |
return NULL; |
return NULL; |
1844 |
return p+1; |
return p+1; |
1845 |
} /* default_dirname */ |
} |
1846 |
|
|
1847 |
|
|
1848 |
/* Store all selected files from @lv in a zip archive |
/* Store all selected files from @lv in a zip archive |
1852 |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
1853 |
{ |
{ |
1854 |
PK_FILE_LIST list=NULL; |
PK_FILE_LIST list=NULL; |
1855 |
const char *outfile; |
const char *outfile, *ext; |
1856 |
char *out_enc; |
char *out_enc; |
1857 |
int nitems = listview_count_items (lv, 0); |
int nitems; |
1858 |
int i, idx = -1; |
int i, idx = -1; |
1859 |
int rc; |
int rc; |
1860 |
|
|
1861 |
|
nitems = listview_count_items (lv, 0); |
1862 |
if (!nitems) { |
if (!nitems) { |
1863 |
msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"), |
msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"), |
1864 |
_("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
1865 |
return -1; |
return WPTERR_GENERAL; |
1866 |
} |
} |
1867 |
|
|
1868 |
outfile = get_filesave_dlg (NULL, _("Choose File Name for Output"), |
outfile = get_filesave_dlg (ctx->dlg, _("Choose File Name for Output"), |
1869 |
NULL, "encrypted_files.zip"); |
NULL, "Encrypted_Files.zip"); |
1870 |
if (!outfile) |
if (!outfile) |
1871 |
return -1; |
return WPTERR_GENERAL; |
1872 |
|
|
1873 |
for (i=0; i < nitems; i++) { |
for (i=0; i < nitems; i++) { |
1874 |
char name[300]; |
char name[300]; |
1888 |
if (rc) |
if (rc) |
1889 |
return rc; |
return rc; |
1890 |
|
|
1891 |
out_enc = make_filename (NULL, outfile, "gpg"); |
ext = file_get_extension (ctx->ctx, ctx->sigmode)+1; |
1892 |
fm_set_status (lv, idx, FM_ENCRYPT, 1, out_enc); |
out_enc = make_filename (NULL, outfile, ext); |
1893 |
|
fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc); |
1894 |
free_if_alloc (out_enc); |
free_if_alloc (out_enc); |
1895 |
|
|
1896 |
for (i=0; i < nitems; i++) { |
for (i=0; i < nitems; i++) { |
1902 |
|
|
1903 |
|
|
1904 |
int |
int |
1905 |
fm_encrypt_directory( fm_state_t c, const char * name ) |
fm_encrypt_directory (fm_state_t c, const char *name) |
1906 |
{ |
{ |
1907 |
PK_FILE_LIST list = NULL; |
PK_FILE_LIST list = NULL; |
1908 |
WIN32_FIND_DATA findbuf; |
WIN32_FIND_DATA findbuf; |
1911 |
char * patt = NULL, * p; |
char * patt = NULL, * p; |
1912 |
int rc = 0; |
int rc = 0; |
1913 |
|
|
1914 |
if( !is_directory( name ) ) |
if (!is_directory (name)) |
1915 |
return -1; |
return -1; |
1916 |
patt = new char[strlen( name ) + 4]; |
patt = new char[strlen (name) + 4]; |
1917 |
if( !patt ) |
if (!patt) |
1918 |
BUG( NULL ); |
BUG (NULL); |
1919 |
strcpy( patt, name ); |
strcpy (patt, name); |
1920 |
strcat( patt, "\\*" ); |
strcat (patt, "\\*"); |
1921 |
hd = FindFirstFile( patt, &findbuf ); |
hd = FindFirstFile (patt, &findbuf); |
1922 |
if( !hd ) { |
if (!hd) { |
1923 |
free_if_alloc( patt ); |
free_if_alloc (patt); |
1924 |
return -1; |
return WPTERR_GENERAL; |
1925 |
} |
} |
1926 |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
1927 |
p = make_filename( name, findbuf.cFileName, NULL ); |
p = make_filename( name, findbuf.cFileName, NULL ); |
1935 |
free_if_alloc( p ); |
free_if_alloc( p ); |
1936 |
} |
} |
1937 |
} |
} |
1938 |
s = get_filesave_dlg( c->dlg, _("Choose a Name for the Archive"), |
s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"), |
1939 |
NULL, default_dirname( name ) ); |
NULL, default_dirname (name)); |
1940 |
if( !s ) { |
if( !s ) { |
1941 |
msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR ); |
msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR ); |
1942 |
rc = -1; |
rc = -1; |
1955 |
pk_list_free( list ); |
pk_list_free( list ); |
1956 |
free_if_alloc( patt ); |
free_if_alloc( patt ); |
1957 |
return rc; |
return rc; |
1958 |
} /* fm_encrypt_directory */ |
} |
1959 |
|
|
1960 |
|
|
1961 |
static int CALLBACK |
static int CALLBACK |
1962 |
fm_cmp_cb( LPARAM first, LPARAM second, LPARAM sortby ) |
fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
1963 |
{ |
{ |
1964 |
const char * a = 0, * b = 0; |
const char *a = 0; |
1965 |
|
const char *b = 0; |
1966 |
|
|
1967 |
switch( (int)sortby ) { |
switch ((int)sortby) { |
1968 |
case FM_SORT_STAT: |
case FM_SORT_STAT: |
1969 |
break; |
break; |
1970 |
case FM_SORT_NAME: |
case FM_SORT_NAME: |
1972 |
case FM_SORT_OP: |
case FM_SORT_OP: |
1973 |
break; |
break; |
1974 |
} |
} |
1975 |
return stricmp( a, b ); |
return stricmp (a, b); |
1976 |
} /* fm_cmp_cb */ |
} |
1977 |
|
|
1978 |
|
|
1979 |
|
/* Sort the list items from @lv with the mode given by @sortby. */ |
1980 |
int |
int |
1981 |
fm_sort( listview_ctrl_t lv, int sortby ) |
fm_sort (listview_ctrl_t lv, int sortby) |
1982 |
{ |
{ |
1983 |
return listview_sort_items( lv, sortby, fm_cmp_cb ); |
return listview_sort_items (lv, sortby, fm_cmp_cb); |
1984 |
} /* fm_sort */ |
} |
1985 |
|
|
1986 |
|
|
1987 |
|
/* Start the 'print md' dialog. Pass over the listview control |
1988 |
|
@lv and the digest algo @mdalgo. */ |
1989 |
void |
void |
1990 |
fm_print_md( listview_ctrl_t lv, HWND dlg, int mdalgo ) |
fm_print_md (listview_ctrl_t lv, HWND dlg, int mdalgo) |
1991 |
{ |
{ |
1992 |
struct md_file_s mdctx; |
struct md_file_s mdctx; |
1993 |
|
|
1994 |
if( listview_count_items( lv, 0 ) == 0 ) |
if (listview_count_items (lv, 0) == 0) |
1995 |
return; |
return; |
1996 |
memset (&mdctx, 0, sizeof (mdctx)); |
memset (&mdctx, 0, sizeof (mdctx)); |
1997 |
mdctx.lv = lv; |
mdctx.lv = lv; |
1998 |
mdctx.mdalgo = mdalgo; |
mdctx.mdalgo = mdalgo; |
1999 |
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg, |
2000 |
mdsum_dlg_proc, (LPARAM)&mdctx ); |
mdsum_dlg_proc, (LPARAM)&mdctx); |
2001 |
} /* fm_print_md */ |
} |
2002 |
|
|
2003 |
|
|
2004 |
/* Send the selected file in @lv via MAPI to a mail recipient. */ |
/* Send the selected file in @lv via MAPI to a mail recipient. */ |