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> |
50 |
#include "wptKeyManager.h" |
#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, |
57 |
char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n); |
char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n); |
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 |
|
void verify_show_signature_state (gpgme_signature_t sig); |
61 |
|
|
62 |
|
|
63 |
/*-- wptFileVerifyDlg.cpp --*/ |
/* Symbolic column IDs. */ |
64 |
void file_verify_add_state (file_sig_ctx_t c); |
enum { |
65 |
void file_verify_use_event (void); |
FM_COL_STAT = 0, |
66 |
void file_verify_wait (void); |
FM_COL_NAME = 1, |
67 |
|
FM_COL_OP = 2 |
68 |
|
}; |
69 |
|
|
70 |
static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
71 |
".mp3", ".wav", ".mid", ".wma", |
".mp3", ".wav", ".mid", ".wma", |
72 |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
73 |
|
|
116 |
void |
void |
117 |
remove_crit_file_attrs (const char *fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
118 |
{ |
{ |
119 |
u32 fattr; |
DWORD fattr; |
120 |
int id = 0; |
int id = 0; |
121 |
|
|
122 |
if (file_exist_check (fname)) |
if (file_exist_check (fname)) |
145 |
} |
} |
146 |
|
|
147 |
|
|
148 |
/* Return -1 if the given name @name is a valid PGP extension. */ |
/* Return -1 if the given name @name is a valid GPG extension. */ |
149 |
static int |
int |
150 |
is_openpgp_ext (const char *name) |
is_openpgp_ext (const char *name) |
151 |
{ |
{ |
152 |
if (stristr (name, ".gpg") || stristr (name, ".asc") |
if (stristr (name, ".gpg") || |
153 |
|| stristr (name, ".sig") || stristr (name, ".pgp")) |
stristr (name, ".asc") || |
154 |
|
stristr (name, ".sig") || |
155 |
|
stristr (name, ".pgp")) |
156 |
return -1; |
return -1; |
157 |
return 0; |
return 0; |
158 |
} |
} |
203 |
return ".asc"; |
return ".asc"; |
204 |
if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH) |
if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH) |
205 |
return ".sig"; |
return ".sig"; |
206 |
return ".gpg"; |
return reg_prefs.default_ext == 1? ".pgp" : ".gpg"; |
207 |
} |
} |
208 |
|
|
209 |
|
|
228 |
|
|
229 |
/* Check the armor type of the file @fname and return |
/* Check the armor type of the file @fname and return |
230 |
a string representation of it. */ |
a string representation of it. */ |
231 |
static const char * |
static const char* |
232 |
fm_check_armor_type (const char *fname, int *r_type) |
fm_check_armor_type (const char *fname, int *r_type) |
233 |
{ |
{ |
234 |
FILE * fp; |
FILE *fp; |
235 |
char header[768], * p; |
char header[768], *p; |
236 |
|
|
237 |
if (r_type) |
if (r_type) |
238 |
*r_type = PGP_NONE; |
*r_type = PGP_NONE; |
378 |
int |
int |
379 |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
380 |
{ |
{ |
381 |
int i, rc = 0; |
int i; |
382 |
listview_ctrl_t c; |
listview_ctrl_t c; |
383 |
struct listview_column_s col[] = { |
struct listview_column_s col[] = { |
384 |
{0, 80, (char *)_("Status") }, |
{0, 80, (char *)_("Status") }, |
385 |
{1, 256, (char *)_("Name") }, |
{1, 256, (char *)_("Name") }, |
386 |
{2, 128, (char *)_("Operation") }, |
{2, 128, (char *)_("Operation") }, |
387 |
{0, 0, NULL } |
{0, 0, NULL} |
388 |
}; |
}; |
389 |
|
|
390 |
rc = listview_new (&c); |
listview_new (&c, ctrl); |
|
if (rc) |
|
|
BUG (NULL); |
|
|
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); |
410 |
int |
int |
411 |
fm_state_new (fm_state_t * ctx) |
fm_state_new (fm_state_t * ctx) |
412 |
{ |
{ |
413 |
gpgme_error_t rc; |
fm_state_s *c; |
|
fm_state_s * c; |
|
414 |
|
|
415 |
c = new fm_state_s; |
c = new fm_state_s; |
416 |
if (!c) |
if (!c) |
417 |
BUG (0); |
BUG (0); |
418 |
memset (c, 0, sizeof *c); |
memset (c, 0, sizeof *c); |
419 |
rc = gpgme_new (&c->ctx); |
if (gpgme_new (&c->ctx)) |
|
if (rc) |
|
420 |
BUG (0); |
BUG (0); |
|
/* XXX rc = gpgme_recipients_new (&c->recp);*/ |
|
|
/* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */ |
|
421 |
*ctx = c; |
*ctx = c; |
422 |
return 0; |
return 0; |
423 |
} /* fm_state_new */ |
} |
424 |
|
|
425 |
|
|
426 |
/* Release the FM state handle @c. */ |
/* Release the FM state handle @c. */ |
436 |
safe_free (c->recp); |
safe_free (c->recp); |
437 |
free_if_alloc (c->opaque); |
free_if_alloc (c->opaque); |
438 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
439 |
delete c; c = NULL; |
delete c; |
440 |
} |
} |
441 |
|
|
442 |
|
|
443 |
|
/* Check if file @file is already in the list (view). */ |
444 |
static int |
static int |
445 |
fm_check_for_entry( listview_ctrl_t lv, const char *file ) |
fm_check_for_entry (listview_ctrl_t lv, const char *file) |
446 |
{ |
{ |
447 |
char name[512]; |
char name[512]; |
448 |
int i; |
int i; |
449 |
|
|
450 |
memset (name, 0, sizeof (name)); |
memset (name, 0, sizeof (name)); |
451 |
for (i = 0; i < listview_count_items( lv, 0 ); i++) { |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
452 |
listview_get_item_text( lv, i, 1, name, sizeof (name) - 1 ); |
listview_get_item_text (lv, i, FM_COL_NAME, name, sizeof (name) - 1); |
453 |
if( !strcmp( name, file ) ) |
if (!strcmp( name, file)) |
454 |
return 1; /* found */ |
return 1; /* found */ |
455 |
} |
} |
456 |
|
|
457 |
return 0; |
return 0; |
458 |
} /* fm_check_for_entry */ |
} |
459 |
|
|
460 |
|
|
461 |
static int |
static int |
473 |
rc = listview_add_item (lv, " "); |
rc = listview_add_item (lv, " "); |
474 |
if (rc) |
if (rc) |
475 |
return -1; |
return -1; |
476 |
listview_add_sub_item (lv, 0, 0, type); |
listview_add_sub_item (lv, 0, FM_COL_STAT, type); |
477 |
listview_add_sub_item (lv, 0, 1, name); |
listview_add_sub_item (lv, 0, FM_COL_NAME, name); |
478 |
return 0; |
return 0; |
479 |
} |
} |
480 |
|
|
481 |
|
|
482 |
|
/* Add all files from the directory @path to the list view @lv. */ |
483 |
static int |
static int |
484 |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
485 |
{ |
{ |
486 |
struct _finddata_t fd; |
struct _finddata_t fd; |
487 |
char * p; |
char *p; |
488 |
long hd; |
long hd; |
489 |
|
|
490 |
strcat (path, "\\*"); |
strcat (path, "\\*"); |
491 |
hd = _findfirst (path, &fd); |
hd = _findfirst (path, &fd); |
492 |
do { |
do { |
493 |
p = new char [(strlen (path) + strlen (fd.name))+1]; |
p = new char [strlen (path) + strlen (fd.name)+1]; |
494 |
if (!p) |
if (!p) |
495 |
BUG (0); |
BUG (0); |
496 |
memcpy (p, path, strlen (path)-1); |
memcpy (p, path, strlen (path)-1); |
544 |
if (!type) |
if (!type) |
545 |
return WPTERR_FILE_OPEN; |
return WPTERR_FILE_OPEN; |
546 |
if (!strcmp (type, "UNKNOWN")) |
if (!strcmp (type, "UNKNOWN")) |
547 |
type = gnupg_check_file_ext (name, NULL); |
type = gnupg_check_file_ext (name, NULL); |
548 |
rc = listview_add_item (lv, ""); |
rc = listview_add_item (lv, ""); |
549 |
if (!rc) { |
if (!rc) { |
550 |
listview_add_sub_item (lv, 0, 0, type); |
listview_add_sub_item (lv, 0, FM_COL_STAT, type); |
551 |
listview_add_sub_item (lv, 0, 1, name); |
listview_add_sub_item (lv, 0, FM_COL_NAME, name); |
552 |
} |
} |
553 |
return rc; |
return rc; |
554 |
} |
} |
580 |
if (!GetOpenFileName (&open)) |
if (!GetOpenFileName (&open)) |
581 |
return 0; |
return 0; |
582 |
|
|
583 |
|
/* It is possible that multiple files are returned |
584 |
|
and then they are separated by \0 chars. */ |
585 |
s = file; |
s = file; |
586 |
len = sizeof (file)-1; |
len = sizeof (file)-1; |
587 |
for (;;) { |
for (;;) { |
596 |
name[i] = *s++; |
name[i] = *s++; |
597 |
} |
} |
598 |
if (n == 0) |
if (n == 0) |
599 |
path = strdup (name); |
path = m_strdup (name); |
600 |
else { |
else { |
601 |
char *p = make_filename (path, name, NULL); |
char *p = make_filename (path, name, NULL); |
602 |
rc = add_single_file (lv, p); |
rc = add_single_file (lv, p); |
603 |
free (p); |
free_if_alloc (p); |
604 |
} |
} |
605 |
n++; |
n++; |
606 |
} |
} |
607 |
if (n == 1) /* single file selected. */ |
if (n == 1) /* single file selected. */ |
608 |
rc = add_single_file (lv, path); |
rc = add_single_file (lv, path); |
609 |
if (path) |
free_if_alloc (path); |
|
free (path); |
|
610 |
return rc; |
return rc; |
611 |
} |
} |
612 |
|
|
613 |
|
|
614 |
int |
int |
615 |
fm_assume_onepass_sig (const char * fname) |
fm_assume_onepass_sig (const char *fname) |
616 |
{ |
{ |
|
gpgme_data_t dat; |
|
617 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
618 |
gpg_iobuf_t fp; |
gpg_iobuf_t fp; |
619 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
gpgme_data_t dat; |
620 |
|
PACKET *pkt; |
621 |
|
char tmpfile[MAX_PATH+1]; |
622 |
int check = 0; |
int check = 0; |
623 |
|
|
624 |
|
pkt = (PACKET *)calloc (1, sizeof *pkt); |
625 |
if (!fname) { |
if (!fname) { |
626 |
|
get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp"); |
627 |
gpg_data_new_from_clipboard (&dat, 0); |
gpg_data_new_from_clipboard (&dat, 0); |
628 |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
gpg_data_release_and_set_file (dat, tmpfile); |
629 |
|
|
630 |
fp = gpg_iobuf_open ("gpgme.tmp"); |
fp = gpg_iobuf_open (tmpfile); |
631 |
if (!fp) |
if (!fp) |
632 |
return 0; |
return 0; |
633 |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
640 |
&& pkt->pkttype == PKT_COMPRESSED) |
&& pkt->pkttype == PKT_COMPRESSED) |
641 |
check = 1; |
check = 1; |
642 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
|
safe_free (pkt); |
|
643 |
gpg_iobuf_close (fp); |
gpg_iobuf_close (fp); |
644 |
remove ("gpgme.tmp"); |
DeleteFile (tmpfile); |
645 |
} |
} |
646 |
/* XXX: implement it for real files */ |
/* XXX: implement it for real files */ |
647 |
|
safe_free (pkt); |
648 |
return check; |
return check; |
649 |
} |
} |
650 |
|
|
657 |
items = listview_count_items (lv, 0); |
items = listview_count_items (lv, 0); |
658 |
if (!items) |
if (!items) |
659 |
return -1; |
return -1; |
660 |
else if (items == 1) |
else if (items == 1) { |
|
{ |
|
661 |
listview_select_one (lv, 0); |
listview_select_one (lv, 0); |
662 |
return 0; |
return 0; |
663 |
} |
} |
664 |
else if (items > 1) |
else if (items > 1) { |
|
{ |
|
665 |
i = listview_get_curr_pos (lv); |
i = listview_get_curr_pos (lv); |
666 |
if (i == -1) |
if (i == -1) { |
667 |
{ |
msg_box (lv->ctrl, _("Please select a file."), |
668 |
msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
669 |
return -1; |
return -1; |
670 |
} |
} |
671 |
return i; |
return i; |
672 |
} |
} |
673 |
|
|
674 |
return -1; |
return -1; |
675 |
} /* fm_get_current_pos */ |
} |
676 |
|
|
677 |
|
|
678 |
static int |
static int |
679 |
fm_check_detached_sig( listview_ctrl_t lv, int pos ) |
fm_check_detached_sig (listview_ctrl_t lv, int pos) |
680 |
{ |
{ |
681 |
char type[128]; |
char type[128]; |
682 |
|
|
683 |
listview_get_item_text( lv, pos, 0, type, 127 ); |
listview_get_item_text (lv, pos, 0, type, sizeof (type)-1); |
684 |
return !strcmp( type, "SIGNED-DETACH" )? 1 : 0; |
return !strcmp (type, "SIGNED-DETACH")? 1 : 0; |
685 |
} /* fm_check_detached_sig */ |
} |
686 |
|
|
687 |
|
|
688 |
int |
int |
703 |
break; |
break; |
704 |
|
|
705 |
case FM_DECRYPT: |
case FM_DECRYPT: |
706 |
if (!strcmp (status, "DATA") |
if (!strcmp (status, "DATA") || |
707 |
|| !strcmp (status, "ENCRYPTED") |
!strcmp (status, "ENCRYPTED") || |
708 |
|| !strcmp (status, "SYMKEYENC") |
!strcmp (status, "SYMKEYENC") || |
709 |
|| !strcmp (status, "ARMORED")) |
!strcmp (status, "ARMORED")) |
710 |
rc = 1; |
rc = 1; |
711 |
break; |
break; |
712 |
|
|
739 |
} |
} |
740 |
|
|
741 |
return rc; |
return rc; |
742 |
} /* fm_check_file_type */ |
} |
743 |
|
|
744 |
|
|
745 |
/* Set the file status of the given command @fm_cmd. |
/* Set the file status of the given command @fm_cmd. |
789 |
fm_clearsign_8bit (listview_ctrl_t lv, fm_state_s *ctx) |
fm_clearsign_8bit (listview_ctrl_t lv, fm_state_s *ctx) |
790 |
{ |
{ |
791 |
FILE *f; |
FILE *f; |
792 |
byte buf[32]; |
BYTE buf[32]; |
793 |
char name[256]; |
char name[256]; |
794 |
int i, n, cnt=0; |
int i, n, cnt=0; |
795 |
|
|
796 |
if (ctx->sigmode != GPGME_SIG_MODE_CLEAR) |
if (ctx->sigmode != GPGME_SIG_MODE_CLEAR) |
797 |
return 0; |
return 0; |
798 |
listview_get_item_text (lv, -1, 1, name, sizeof (name)-1); |
listview_get_item_text (lv, -1, FM_COL_NAME, name, sizeof (name)-1); |
799 |
if (stristr (name, ".TXT")) |
if (stristr (name, ".TXT")) |
800 |
return 0; |
return 0; |
801 |
f = fopen (name, "rb"); |
f = fopen (name, "rb"); |
802 |
if (!f) |
if (!f) |
803 |
return -1; /* should never happen */ |
return -1; /* should never happen */ |
804 |
n = fread (buf, 1, 32, f); |
n = fread (buf, 1, 32, f); |
805 |
|
fclose (f); |
806 |
for (i = 0; i < n; i++) { |
for (i = 0; i < n; i++) { |
807 |
if (buf[i] == 0x00 || buf[i] > 170) |
if (buf[i] == 0x00 || buf[i] > 170) |
808 |
cnt++; |
cnt++; |
809 |
} |
} |
|
fclose (f); |
|
810 |
if (!cnt) |
if (!cnt) |
811 |
return 0; |
return 0; |
812 |
n = -1; |
n = -1; |
813 |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
814 |
_("\"%s\" does not seems to be a text file.\n" |
_("\"%s\" does not seems to be a text file.\n" |
815 |
"Do you really want to clearsign it?"), name); |
"Do you really want to clearsign it?"), name); |
816 |
if (i == IDYES) |
if (i == IDYES) |
818 |
return n; |
return n; |
819 |
} |
} |
820 |
|
|
821 |
|
|
822 |
int |
int |
823 |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
824 |
{ |
{ |
921 |
fm_encrypt_into_zip (ctx, lv); |
fm_encrypt_into_zip (ctx, lv); |
922 |
|
|
923 |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
924 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
925 |
continue; |
continue; |
926 |
listview_get_item_text(lv, i, 1, fname, sizeof (fname) - 1); |
listview_get_item_text (lv, i, 1, fname, sizeof (fname) - 1); |
927 |
if( file_exist_check (fname) && !is_directory (fname)) { |
if( file_exist_check (fname) && !is_directory (fname)) { |
928 |
log_box (_("File Manager"), MB_ERR, |
log_box (_("File Manager"), MB_ERR, |
929 |
_("\"%s\" does not exist"), fname); |
_("\"%s\" does not exist"), fname); |
942 |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
943 |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
944 |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
945 |
case FM_SYMENC: rc = fm_sym_encrypt( ctx, fname );break; |
case FM_SYMENC: rc = fm_sym_encrypt (ctx, fname); break; |
946 |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
947 |
case FM_IMPORT: |
case FM_IMPORT: |
948 |
free_if_alloc (ctx->opaque); |
free_if_alloc (ctx->opaque); |
949 |
ctx->opaque = m_strdup (fname); |
ctx->opaque = m_strdup (fname); |
950 |
if (!ctx->opaque) |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
951 |
BUG (0); |
file_import_dlg_proc, (LPARAM)ctx); |
|
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
|
|
file_import_dlg_proc, (LPARAM)ctx ); |
|
952 |
if (ctx->cancel == 1) |
if (ctx->cancel == 1) |
953 |
continue; |
continue; |
954 |
rc = fm_import (ctx, fname); |
rc = fm_import (ctx, fname); |
955 |
break; |
break; |
956 |
} |
} |
957 |
|
if (ctx->cancel == 1) { |
958 |
|
ctx->cancel = 0; |
959 |
|
continue; |
960 |
|
} |
961 |
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
962 |
free_if_alloc (ctx->output); |
free_if_alloc (ctx->output); |
963 |
progress_cleanup (&pfx); |
progress_cleanup (&pfx); |
1018 |
static int |
static int |
1019 |
ask_filename (fm_state_t c, const char *msg, char **dst) |
ask_filename (fm_state_t c, const char *msg, char **dst) |
1020 |
{ |
{ |
1021 |
const char * s; |
const char *s; |
1022 |
|
|
1023 |
s = get_filesave_dlg (c->dlg, msg, NULL, NULL); |
s = get_filesave_dlg (c->dlg, msg, NULL, NULL); |
1024 |
if (!s) |
if (!s) |
1028 |
free_if_alloc (*dst); |
free_if_alloc (*dst); |
1029 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1030 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (0); |
|
1031 |
if (dst) |
if (dst) |
1032 |
*dst = fm_quote_file (s); |
*dst = fm_quote_file (s); |
1033 |
return 0; |
return 0; |
1053 |
strcat (c->output, ext); |
strcat (c->output, ext); |
1054 |
|
|
1055 |
if (!overwrite_file (c->output)) { |
if (!overwrite_file (c->output)) { |
1056 |
rc = ask_filename (c, _("Enter filename for encrypted file"), NULL); |
rc = ask_filename (c, _("Enter Filename for Encrypted File"), NULL); |
1057 |
if (rc) |
if (rc) |
1058 |
goto leave; |
goto leave; |
1059 |
} |
} |
1095 |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
1096 |
if (sigkey && sigkey->subkeys) { |
if (sigkey && sigkey->subkeys) { |
1097 |
keyid = m_strdup (sigkey->subkeys->keyid); |
keyid = m_strdup (sigkey->subkeys->keyid); |
|
if (!keyid) |
|
|
BUG (NULL); |
|
1098 |
} |
} |
1099 |
} |
} |
1100 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1151 |
gpgme_error_t err; |
gpgme_error_t err; |
1152 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1153 |
int rc = 0, cancel = 0; |
int rc = 0, cancel = 0; |
1154 |
char ext[5], * pass; |
char ext[5], *pass; |
1155 |
|
|
1156 |
pass = request_passphrase2 (_("Symmetric"), 0, &cancel); |
pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel); |
1157 |
if (cancel) |
if (cancel) { |
1158 |
|
c->cancel = 1; |
1159 |
return 0; |
return 0; |
1160 |
|
} |
1161 |
|
|
1162 |
/* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/ |
/* XXX: a convenient feature could be to select the preferred |
1163 |
|
symmetric algorithm. */ |
1164 |
c->output = new char[strlen (name) + 5 + 1]; |
c->output = new char[strlen (name) + 5 + 1]; |
1165 |
if (!c->output) |
if (!c->output) |
1166 |
BUG (0); |
BUG (0); |
1173 |
goto leave; |
goto leave; |
1174 |
} |
} |
1175 |
|
|
1176 |
gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass); |
gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass); |
|
|
|
1177 |
err = gpg_file_data_new (name, 1, &in); |
err = gpg_file_data_new (name, 1, &in); |
1178 |
if (err) |
if (err) |
1179 |
goto leave; |
goto leave; |
1205 |
} |
} |
1206 |
|
|
1207 |
|
|
|
/* Show the human readable verify result from @sigres. */ |
|
|
static void |
|
|
show_verify_result (gpgme_verify_result_t sigres) |
|
|
{ |
|
|
gpgme_key_t key=NULL; |
|
|
gpgme_signature_t sig=sigres->signatures; |
|
|
const char *s, *keyid; |
|
|
int sigok = 0; |
|
|
int type; |
|
|
char buf[384]; |
|
|
|
|
|
sig = sigres->signatures; |
|
|
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
|
|
s = sigok? _("Good signature") : _("BAD signature"); |
|
|
type = sigok? MB_OK: MB_ICONWARNING|MB_OK; |
|
|
keyid = sig->fpr; |
|
|
if (!keyid) |
|
|
return; |
|
|
|
|
|
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24; |
|
|
get_pubkey (sig->fpr, &key); |
|
|
_snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n" |
|
|
"%s from \"%s\""), |
|
|
strtimestamp (sig->timestamp), |
|
|
get_key_pubalgo (sig->pubkey_algo), |
|
|
keyid, s, key? key->uids->uid : _("user ID not found")); |
|
|
msg_box (NULL, buf, _("Decrypt Verify"), type); |
|
|
} |
|
|
|
|
|
|
|
1208 |
/* Check the recipients if we have at least one secret key. */ |
/* Check the recipients if we have at least one secret key. */ |
1209 |
bool |
bool |
1210 |
secret_key_available (gpgme_recipient_t rset) |
is_seckey_available (gpgme_recipient_t rset) |
1211 |
{ |
{ |
1212 |
gpgme_recipient_t r; |
gpgme_recipient_t r; |
1213 |
gpgme_key_t key; |
winpt_key_s key; |
1214 |
|
|
1215 |
for (r=rset; r; r = r->next) { |
for (r=rset; r; r = r->next) { |
1216 |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
1217 |
continue; |
continue; |
1218 |
else { |
else { |
1219 |
|
memset (&key, 0, sizeof (key)); |
1220 |
/* extra check to make sure the key is available right now. */ |
/* extra check to make sure the key is available right now. */ |
1221 |
if (!get_seckey (r->keyid, &key)) |
if (!winpt_get_seckey (r->keyid, &key)) { |
1222 |
|
winpt_release_pubkey (&key); |
1223 |
return true; |
return true; |
1224 |
|
} |
1225 |
|
winpt_release_pubkey (&key); |
1226 |
} |
} |
1227 |
} |
} |
1228 |
return false; |
return false; |
1229 |
} |
} |
1230 |
|
|
1231 |
|
|
1232 |
|
/* If the decrypt result contains the original file name, |
1233 |
|
we use it instead of the artificial "output - .gpg" string. */ |
1234 |
|
static int |
1235 |
|
restore_original_name (const char *output, const char *file_name) |
1236 |
|
{ |
1237 |
|
char *dir; |
1238 |
|
char *orig; |
1239 |
|
int rc = 0; |
1240 |
|
|
1241 |
|
dir = strrchr (output, '\\'); |
1242 |
|
if (!dir) |
1243 |
|
orig = strdup (file_name); |
1244 |
|
else { |
1245 |
|
orig = (char*)calloc (1, strlen (file_name)+ 1 + |
1246 |
|
strlen (output)+1); |
1247 |
|
if (!orig) |
1248 |
|
BUG (0); |
1249 |
|
memcpy (orig, output, (dir-output)+1); |
1250 |
|
strcat (orig, file_name); |
1251 |
|
} |
1252 |
|
/* XXX: we need to find out if the string needs to be utf8 decoded. */ |
1253 |
|
if (overwrite_file (orig)) { |
1254 |
|
DeleteFile (orig); |
1255 |
|
if (!MoveFile (output, orig)) |
1256 |
|
rc = -1; |
1257 |
|
} |
1258 |
|
safe_free (orig); |
1259 |
|
return rc; |
1260 |
|
} |
1261 |
|
|
1262 |
|
|
1263 |
/* Decrypt the file @name. */ |
/* Decrypt the file @name. */ |
1264 |
int |
int |
1265 |
fm_decrypt (fm_state_t c, const char *name) |
fm_decrypt (fm_state_t c, const char *name) |
1268 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1269 |
gpgme_decrypt_result_t res; |
gpgme_decrypt_result_t res; |
1270 |
gpgme_verify_result_t sigres; |
gpgme_verify_result_t sigres; |
1271 |
file_data_t in =NULL, out=NULL; |
file_data_t in = NULL, out = NULL; |
1272 |
int rc = 0; |
int rc = 0; |
1273 |
|
|
1274 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1278 |
} |
} |
1279 |
|
|
1280 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (0); |
|
1281 |
if (is_openpgp_ext (c->output)) |
if (is_openpgp_ext (c->output)) |
1282 |
c->output[strlen (c->output)-4] = '\0'; |
c->output[strlen (c->output)-4] = '\0'; |
1283 |
else { |
else { |
1287 |
if (s) { |
if (s) { |
1288 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1289 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1290 |
} |
} |
1291 |
} |
} |
1292 |
|
|
1293 |
if (overwrite_file (c->output) == 0) { |
if (overwrite_file (c->output) == 0) { |
1294 |
rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL); |
rc = ask_filename (c, _("Enter Filename for Plaintext File"), NULL); |
1295 |
if (rc) |
if (rc) |
1296 |
goto leave; |
goto leave; |
1297 |
} |
} |
1298 |
|
|
1299 |
|
/* we fetch all recipients here to make sure they list is complete. */ |
1300 |
|
release_gpg_recipients (&c->pass_cb.recipients); |
1301 |
|
gpg_get_recipients (name, &c->pass_cb.recipients); |
1302 |
|
|
1303 |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1304 |
if (err) |
if (err) |
1305 |
goto leave; |
goto leave; |
1307 |
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
1308 |
if (err) |
if (err) |
1309 |
goto leave; |
goto leave; |
1310 |
|
|
1311 |
op_begin (); |
op_begin (); |
1312 |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
1313 |
op_end (); |
op_end (); |
1319 |
} |
} |
1320 |
|
|
1321 |
res = gpgme_op_decrypt_result (ctx); |
res = gpgme_op_decrypt_result (ctx); |
1322 |
if (res && res->recipients && !secret_key_available (res->recipients)) { |
if (res && res->recipients && !is_seckey_available (res->recipients)) { |
1323 |
const char *keyid = res->recipients->keyid; |
const char *keyid = res->recipients->keyid; |
1324 |
char *p = get_key_userid (keyid+8); |
char *p = get_key_userid (keyid+8); |
1325 |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
1326 |
|
|
1327 |
log_box( _("Decryption"), MB_ERR, |
log_box (_("Decryption"), MB_ERR, |
1328 |
_("Encrypted with %s key, ID %s.%s\n" |
_("Encrypted with %s key, ID %s.%s\n" |
1329 |
"Decryption failed: secret key not available."), |
"Decryption failed: secret key not available."), |
1330 |
get_key_pubalgo (pkalgo), keyid+8, p); |
get_key_pubalgo (pkalgo), keyid+8, p); |
1341 |
log_box ("Decrypt", MB_ERR, |
log_box ("Decrypt", MB_ERR, |
1342 |
_("Decryption failed.\n%s: does not exist."), c->output); |
_("Decryption failed.\n%s: does not exist."), c->output); |
1343 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1344 |
|
goto leave; |
1345 |
|
} |
1346 |
|
else if (res && res->file_name) { |
1347 |
|
char *file; |
1348 |
|
int id = IDNO; |
1349 |
|
|
1350 |
|
file = strrchr (c->output, '\\'); |
1351 |
|
if (!file) |
1352 |
|
file = c->output; |
1353 |
|
else |
1354 |
|
file++; |
1355 |
|
if (strcmp (res->file_name, file)) |
1356 |
|
id = log_box (_("Decrypt"), MB_QUEST_ASK, |
1357 |
|
_("The original file name is '%s'.\n\n" |
1358 |
|
"Do you want to use this instead of '%s'?"), |
1359 |
|
res->file_name, file); |
1360 |
|
if (id == IDYES) { |
1361 |
|
/* before we can move the file, it needs to be closed first. */ |
1362 |
|
gpg_file_data_release (out); |
1363 |
|
out = NULL; |
1364 |
|
restore_original_name (c->output, res->file_name); |
1365 |
|
} |
1366 |
} |
} |
|
|
|
1367 |
sigres = gpgme_op_verify_result (ctx); |
sigres = gpgme_op_verify_result (ctx); |
1368 |
if (sigres && sigres->signatures) |
if (sigres && sigres->signatures) |
1369 |
show_verify_result (sigres); |
verify_show_signature_state (sigres->signatures); |
1370 |
|
|
1371 |
leave: |
leave: |
1372 |
if (in) |
if (in) |
1402 |
strcat (c->output, ext); |
strcat (c->output, ext); |
1403 |
|
|
1404 |
if (!overwrite_file (c->output)) { |
if (!overwrite_file (c->output)) { |
1405 |
rc = ask_filename (c, _("Enter filename for signed file"), NULL); |
rc = ask_filename (c, _("Enter Filename for Signed File"), NULL); |
1406 |
if (rc) |
if (rc) |
1407 |
goto leave; |
goto leave; |
1408 |
} |
} |
1442 |
static void |
static void |
1443 |
fm_add_sig_stat (file_sig_ctx_t log) |
fm_add_sig_stat (file_sig_ctx_t log) |
1444 |
{ |
{ |
1445 |
gpgme_key_t key; |
struct winpt_key_s key; |
1446 |
const char *kid; |
const char *kid; |
1447 |
|
|
1448 |
kid = log->sig->fpr; |
memset (&key, 0, sizeof (key)); |
1449 |
if (!kid) |
kid = get_keyid_from_fpr (log->sig->fpr); |
1450 |
BUG (NULL); |
log->use_uid = 0; |
1451 |
if (strlen (kid) == 40) |
if (!winpt_get_pubkey (kid, &key)) { |
1452 |
kid += 32; |
log->user_id = key.ext->uids->uid; |
|
else if (strlen (kid) == 32) |
|
|
kid += 24; |
|
|
if (get_pubkey (kid, &key)) |
|
|
log->use_uid = 0; |
|
|
else { |
|
|
log->user_id = key->uids->uid; |
|
1453 |
log->use_uid = 1; |
log->use_uid = 1; |
1454 |
} |
} |
1455 |
|
winpt_release_pubkey (&key); |
1456 |
file_verify_add_state (log); |
file_verify_add_state (log); |
1457 |
} |
} |
1458 |
|
|
1467 |
char file[256], *fname = NULL; |
char file[256], *fname = NULL; |
1468 |
int del_end = 0; |
int del_end = 0; |
1469 |
|
|
1470 |
listview_get_item_text (lv, pos, 0, stat, sizeof (stat)-1); |
listview_get_item_text (lv, pos, FM_COL_STAT, stat, sizeof (stat)-1); |
1471 |
listview_get_item_text (lv, pos, 1, file, sizeof (file)-1); |
listview_get_item_text (lv, pos, FM_COL_NAME, file, sizeof (file)-1); |
1472 |
if (strcmp (stat, "UNKNOWN")) |
if (strcmp (stat, "UNKNOWN")) |
1473 |
return 0; |
return 0; |
1474 |
fname = make_filename (NULL, file, "asc"); |
fname = make_filename (NULL, file, "asc"); |
1475 |
if (file_exist_check (fname) != 0) { |
if (file_exist_check (fname) != 0) { |
1476 |
fp = fopen (fname, "wb"); |
fp = fopen (fname, "wb"); |
1477 |
if (fp == NULL) { |
if (fp == NULL) { |
1478 |
log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname); |
log_box (_("File Manager"), MB_ERR, "Could not create '%s'", fname); |
1479 |
free_if_alloc (fname); |
free_if_alloc (fname); |
1480 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1481 |
} |
} |
1485 |
} |
} |
1486 |
fm_verify (ctx, 1, fname); |
fm_verify (ctx, 1, fname); |
1487 |
if (del_end) |
if (del_end) |
1488 |
remove (fname); |
DeleteFile (fname); |
1489 |
free_if_alloc (fname); |
free_if_alloc (fname); |
1490 |
return 0; |
return 0; |
1491 |
} |
} |
1542 |
else |
else |
1543 |
title = _("Selected Output File"); |
title = _("Selected Output File"); |
1544 |
|
|
1545 |
if (strstr (name, ".sig") |
if (is_openpgp_ext (name)) { |
|
|| strstr (name, ".asc") |
|
|
|| strstr (name, ".gpg")) { |
|
1546 |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
1547 |
fname[strlen (fname) - 4] = '\0'; |
fname[strlen (fname) - 4] = '\0'; |
1548 |
if (file_exist_check (fname) == 0 && detached) |
if (file_exist_check (fname) == 0 && detached) |
1564 |
if (file) { |
if (file) { |
1565 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1566 |
c->output = m_strdup (file); |
c->output = m_strdup (file); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1567 |
} |
} |
1568 |
else { |
else { |
1569 |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
1572 |
if (detached) |
if (detached) |
1573 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
c->sigmode = GPGME_SIG_MODE_DETACH; |
1574 |
else { |
else { |
1575 |
if (strstr (name, ".asc")) |
if (stristr (name, ".asc")) |
1576 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
1577 |
else |
else |
1578 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
1594 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1595 |
int rc = 0; |
int rc = 0; |
1596 |
|
|
1597 |
if (strstr (name, ".sig")) |
if (stristr (name, ".sig")) |
1598 |
detached = 1; |
detached = 1; |
1599 |
|
|
1600 |
if (get_output_file (c, name, detached)) |
if (get_output_file (c, name, detached)) |
1602 |
|
|
1603 |
memset (&log, 0, sizeof (log)); |
memset (&log, 0, sizeof (log)); |
1604 |
log.file = m_strdup (name); |
log.file = m_strdup (name); |
|
if (!log.file) |
|
|
BUG (NULL); |
|
1605 |
file_verify_create_dlg (); |
file_verify_create_dlg (); |
1606 |
|
|
1607 |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1655 |
|
|
1656 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1657 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1658 |
|
|
1659 |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
1660 |
if (err) |
if (err) |
1688 |
/* Export the selected keys from the File Manager to a file. */ |
/* Export the selected keys from the File Manager to a file. */ |
1689 |
int |
int |
1690 |
fm_export (fm_state_t c) |
fm_export (fm_state_t c) |
1691 |
{ |
{ |
|
int rc = 0; |
|
1692 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1693 |
gpgme_error_t err; |
gpgme_error_t err; |
1694 |
gpgme_key_t *rset = c->recp; |
gpgme_key_t *rset = c->recp; |
1695 |
file_data_t keydata = NULL; |
file_data_t keydata = NULL; |
1696 |
const char *name; |
const char *name; |
1697 |
char *p = NULL, *patt = NULL; |
char *p = NULL, *patt = NULL; |
1698 |
|
int rc = 0; |
1699 |
|
|
1700 |
if (!rset || !rset[0]) { |
if (!rset || !rset[0]) { |
1701 |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
msg_box (c->dlg, _("No key was selected for export."), |
1702 |
|
_("Export"), MB_ERR); |
1703 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1704 |
goto leave; |
goto leave; |
1705 |
} |
} |
1710 |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
1711 |
NULL, p? p : NULL); |
NULL, p? p : NULL); |
1712 |
if (!name) |
if (!name) |
1713 |
name = "keys.gpg"; |
name = reg_prefs.default_ext? "keys.pgp" : "keys.gpg"; |
1714 |
|
|
1715 |
patt = gpg_keylist_to_pattern (rset, c->n_recp); |
patt = gpg_keylist_to_pattern (rset, c->n_recp); |
1716 |
|
|
1731 |
leave: |
leave: |
1732 |
if (keydata) |
if (keydata) |
1733 |
gpg_file_data_release (keydata); |
gpg_file_data_release (keydata); |
1734 |
if (patt) |
safe_free (patt); |
|
free (patt); |
|
1735 |
free_if_alloc (p); |
free_if_alloc (p); |
1736 |
return rc; |
return rc; |
1737 |
} |
} |
1788 |
|
|
1789 |
case PGP_SIG: |
case PGP_SIG: |
1790 |
case PGP_CLEARSIG: |
case PGP_CLEARSIG: |
|
file_verify_use_event (); |
|
1791 |
if (type == PGP_SIG) |
if (type == PGP_SIG) |
1792 |
detached = 1; |
detached = 1; |
1793 |
fm_verify (ctx, detached, fn); |
fm_verify (ctx, detached, fn); |
1824 |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
1825 |
{ |
{ |
1826 |
PK_FILE_LIST list=NULL; |
PK_FILE_LIST list=NULL; |
1827 |
const char *outfile; |
const char *outfile, *ext; |
1828 |
char *out_enc; |
char *out_enc; |
1829 |
int nitems = listview_count_items (lv, 0); |
int nitems; |
1830 |
int i, idx = -1; |
int i, idx = -1; |
1831 |
int rc; |
int rc; |
1832 |
|
|
1833 |
|
nitems = listview_count_items (lv, 0); |
1834 |
if (!nitems) { |
if (!nitems) { |
1835 |
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"), |
1836 |
_("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
1860 |
if (rc) |
if (rc) |
1861 |
return rc; |
return rc; |
1862 |
|
|
1863 |
out_enc = make_filename (NULL, outfile, "gpg"); |
ext = file_get_extension (ctx->ctx, ctx->sigmode)+1; |
1864 |
|
out_enc = make_filename (NULL, outfile, ext); |
1865 |
fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc); |
fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc); |
1866 |
free_if_alloc (out_enc); |
free_if_alloc (out_enc); |
1867 |
|
|
1879 |
PK_FILE_LIST list = NULL; |
PK_FILE_LIST list = NULL; |
1880 |
WIN32_FIND_DATA findbuf; |
WIN32_FIND_DATA findbuf; |
1881 |
HANDLE hd; |
HANDLE hd; |
1882 |
const char * s; |
const char *s; |
1883 |
char * patt = NULL, * p; |
char *patt = NULL, *p; |
1884 |
int rc = 0; |
int rc = 0; |
1885 |
|
|
1886 |
if (!is_directory (name)) |
if (!is_directory (name)) |
1895 |
free_if_alloc (patt); |
free_if_alloc (patt); |
1896 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1897 |
} |
} |
1898 |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
if (strcmp (findbuf.cFileName, ".") && strcmp (findbuf.cFileName, "..")) { |
1899 |
p = make_filename( name, findbuf.cFileName, NULL ); |
p = make_filename (name, findbuf.cFileName, NULL); |
1900 |
pk_list_add( &list, p ); |
pk_list_add (&list, p); |
1901 |
free_if_alloc( p ); |
free_if_alloc (p); |
1902 |
} |
} |
1903 |
while( FindNextFile( hd, &findbuf ) ) { |
while( FindNextFile( hd, &findbuf ) ) { |
1904 |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
1910 |
s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"), |
s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"), |
1911 |
NULL, default_dirname (name)); |
NULL, default_dirname (name)); |
1912 |
if( !s ) { |
if( !s ) { |
1913 |
msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR ); |
msg_box (c->dlg, _("Invalid archive name. Exit."), |
1914 |
|
_("Encrypt Directory"), MB_ERR); |
1915 |
rc = -1; |
rc = -1; |
1916 |
goto leave; |
goto leave; |
1917 |
} |
} |
1918 |
|
|
1919 |
rc = pk_archiv_create( list, s ); |
rc = pk_archiv_create (list, s); |
1920 |
if( rc ) |
if( rc ) |
1921 |
msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR ); |
msg_box (c->dlg, _("Could not create zip archive."), |
1922 |
|
_("Encrypt Directory"), MB_ERR); |
1923 |
else { |
else { |
1924 |
fm_encrypt( c, s, 0 ); |
fm_encrypt (c, s, 0); |
1925 |
remove( s ); |
DeleteFile (s); |
1926 |
} |
} |
1927 |
leave: |
leave: |
1928 |
FindClose (hd); |
FindClose (hd); |
1929 |
pk_list_free( list ); |
pk_list_free (list); |
1930 |
free_if_alloc( patt ); |
free_if_alloc (patt); |
1931 |
return rc; |
return rc; |
1932 |
} |
} |
1933 |
|
|
1935 |
static int CALLBACK |
static int CALLBACK |
1936 |
fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
1937 |
{ |
{ |
1938 |
const char *a = 0; |
const char *a = ""; |
1939 |
const char *b = 0; |
const char *b = ""; |
1940 |
|
|
1941 |
switch( (int)sortby ) { |
switch ((int)sortby) { |
1942 |
case FM_SORT_STAT: |
case FM_SORT_STAT: |
1943 |
break; |
break; |
1944 |
case FM_SORT_NAME: |
case FM_SORT_NAME: |
1954 |
int |
int |
1955 |
fm_sort (listview_ctrl_t lv, int sortby) |
fm_sort (listview_ctrl_t lv, int sortby) |
1956 |
{ |
{ |
1957 |
return listview_sort_items( lv, sortby, fm_cmp_cb ); |
return listview_sort_items (lv, sortby, fm_cmp_cb); |
1958 |
} |
} |
1959 |
|
|
1960 |
|
|