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, |
56 |
WPARAM wparam, LPARAM lparam); |
WPARAM wparam, LPARAM lparam); |
57 |
char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n); |
char* gpg_keylist_to_pattern (gpgme_key_t *rset, size_t 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 |
|
|
|
/*-- wptFileVerifyDlg.cpp --*/ |
|
|
void file_verify_add_state (file_sig_ctx_t c); |
|
|
void file_verify_use_event (void); |
|
|
void file_verify_wait (void); |
|
62 |
|
|
63 |
static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
64 |
".mp3", ".wav", ".mid", ".wma", |
".mp3", ".wav", ".mid", ".wma", |
65 |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
66 |
|
|
67 |
|
|
68 |
|
/* Add a new file to the model @fm. */ |
69 |
|
static void |
70 |
|
fm_model_add_file (fm_model_t *fm, fm_model_t file) |
71 |
|
{ |
72 |
|
fm_model_t m; |
73 |
|
|
74 |
|
if (!*fm) { |
75 |
|
*fm = file; |
76 |
|
return; |
77 |
|
} |
78 |
|
for (m = *fm; m->next; m = m->next) |
79 |
|
; |
80 |
|
m->next = file; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
/* Search for a file model based on the name @name. */ |
85 |
|
static fm_model_t |
86 |
|
fm_model_find_file (fm_model_t fm, const char *name) |
87 |
|
{ |
88 |
|
fm_model_t m; |
89 |
|
|
90 |
|
for (m=fm; m; m=m->next) { |
91 |
|
if (!stricmp (m->name, name)) |
92 |
|
return m; |
93 |
|
} |
94 |
|
return NULL; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
/* Check if the drive given by @fname is a floppy disc. |
/* Check if the drive given by @fname is a floppy disc. |
99 |
Return value: -1 for success. */ |
Return value: -1 for success. */ |
100 |
static int |
static int |
101 |
is_floppy_disc (const char *fname) |
is_floppy_disc (const char *fname) |
102 |
{ |
{ |
103 |
char drv[32] = {0}; |
char drv[32] = {0}; |
104 |
int max = sizeof (drv)-1; |
int max = DIM (drv)-1; |
105 |
int i=0; |
int i=0; |
106 |
|
|
107 |
if (!strstr (fname, ":\\")) |
if (!strstr (fname, ":\\")) |
139 |
void |
void |
140 |
remove_crit_file_attrs (const char *fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
141 |
{ |
{ |
142 |
u32 fattr; |
DWORD fattr; |
143 |
int id = 0; |
int id = 0; |
144 |
|
|
145 |
if (file_exist_check (fname)) |
if (file_exist_check (fname)) |
168 |
} |
} |
169 |
|
|
170 |
|
|
171 |
/* Return -1 if the given name @name is a valid PGP extension. */ |
/* Return -1 if the given name @name is a valid GPG extension. */ |
172 |
static int |
int |
173 |
is_openpgp_ext (const char *name) |
is_openpgp_ext (const char *name) |
174 |
{ |
{ |
175 |
if (stristr (name, ".gpg") || stristr (name, ".asc") |
if (stristr (name, ".gpg") || |
176 |
|| stristr (name, ".sig") || stristr (name, ".pgp")) |
stristr (name, ".asc") || |
177 |
|
stristr (name, ".sig") || |
178 |
|
stristr (name, ".pgp")) |
179 |
return -1; |
return -1; |
180 |
return 0; |
return 0; |
181 |
} |
} |
190 |
int ans=0; |
int ans=0; |
191 |
|
|
192 |
i = get_reg_winpt_single (CFG_NOZIP_MMEDIA); |
i = get_reg_winpt_single (CFG_NOZIP_MMEDIA); |
193 |
if (i == -1) |
if (i == -1) { |
|
{ |
|
194 |
ans = msg_box (NULL, _("Multi-Media files are already compressed, GPG would compress\n" |
ans = msg_box (NULL, _("Multi-Media files are already compressed, GPG would compress\n" |
195 |
"them anyway and this costs a lot of time.\n" |
"them anyway and this takes a lot of time.\n" |
196 |
"It is possible to disable compression for these files.\n" |
"It is possible to disable compression for these files.\n" |
197 |
"Do you want to disable it?"), |
"Do you want to disable it?"), |
198 |
_("File Manager"), MB_YESNO|MB_INFO); |
_("File Manager"), MB_YESNO|MB_INFO); |
225 |
return ".asc"; |
return ".asc"; |
226 |
if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH) |
if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH) |
227 |
return ".sig"; |
return ".sig"; |
228 |
return ".gpg"; |
return reg_prefs.default_ext == 1? ".pgp" : ".gpg"; |
229 |
} |
} |
230 |
|
|
231 |
|
|
250 |
|
|
251 |
/* Check the armor type of the file @fname and return |
/* Check the armor type of the file @fname and return |
252 |
a string representation of it. */ |
a string representation of it. */ |
253 |
static const char * |
static const char* |
254 |
fm_check_armor_type (const char *fname, int *r_type) |
fm_check_armor_type (const char *fname, int *r_type) |
255 |
{ |
{ |
256 |
FILE * fp; |
FILE *fp; |
257 |
char header[768], * p; |
char header[512], *p; |
258 |
|
|
259 |
if (r_type) |
if (r_type) |
260 |
*r_type = PGP_NONE; |
*r_type = PGP_NONE; |
261 |
fp = fopen (fname, "rb"); |
fp = fopen (fname, "rb"); |
262 |
if (!fp) |
if (!fp) |
263 |
return "UNKNOWN"; |
return "UNKNOWN"; |
264 |
p = fgets (header, sizeof (header) - 1, fp); |
p = fgets (header, DIM (header) - 1, fp); |
265 |
fclose (fp); |
fclose (fp); |
266 |
if (!p) |
if (!p) |
267 |
return "UNKNOWN"; |
return "UNKNOWN"; |
268 |
|
|
269 |
if (strncmp (header, "-----", 5)) |
if (strncmp (header, "-----", 5)) |
270 |
goto leave; |
goto leave; |
271 |
if (strstr( header, "BEGIN PGP PUBLIC KEY" )) { |
if (strstr (header, "BEGIN PGP PUBLIC KEY" )) { |
272 |
if (r_type) *r_type = PGP_PUBKEY; |
if (r_type) *r_type = PGP_PUBKEY; |
273 |
return "PUBKEY"; |
return "PUBKEY"; |
274 |
} |
} |
314 |
return NULL; |
return NULL; |
315 |
} |
} |
316 |
|
|
317 |
|
/* to avoid lengthy operations on floppy disks, we use a quick check. */ |
318 |
if (is_floppy_disc (fname)) |
if (is_floppy_disc (fname)) |
319 |
return fm_check_armor_type (fname, r_type); |
return fm_check_armor_type (fname, r_type); |
320 |
|
|
339 |
if (!pkt) |
if (!pkt) |
340 |
BUG (NULL); |
BUG (NULL); |
341 |
gpg_init_packet (pkt); |
gpg_init_packet (pkt); |
342 |
|
/* XXX: for larger files, we could just look for the first ~3 packets |
343 |
|
and stop if we found a packet which were sufficient to idenitfy |
344 |
|
the file contents. */ |
345 |
while (!(rc = gpg_parse_packet (inp, pkt))) { |
while (!(rc = gpg_parse_packet (inp, pkt))) { |
346 |
switch (pkt->pkttype) { |
switch (pkt->pkttype) { |
347 |
case PKT_PUBKEY_ENC: |
case PKT_PUBKEY_ENC: |
348 |
s = "ENCRYPTED";rc = -2; |
s = "ENCRYPTED";rc = -2; |
349 |
if (r_type) *r_type = PGP_MESSAGE; |
if (r_type) *r_type = PGP_MESSAGE; |
350 |
break; |
break; |
351 |
|
|
352 |
case PKT_SYMKEY_ENC: |
case PKT_SYMKEY_ENC: |
353 |
case PKT_ENCRYPTED: |
case PKT_ENCRYPTED: |
354 |
s = "SYMKEYENC";rc = -2; |
s = "SYMKEYENC";rc = -2; |
355 |
if (r_type) *r_type = PGP_MESSAGE; |
if (r_type) *r_type = PGP_MESSAGE; |
356 |
break; |
break; |
357 |
|
|
358 |
case PKT_SIGNATURE: |
case PKT_SIGNATURE: |
359 |
case PKT_ONEPASS_SIG: |
case PKT_ONEPASS_SIG: |
360 |
s = "SIGNED"; rc = -2; |
s = "SIGNED"; rc = -2; |
361 |
if (r_type) *r_type = PGP_SIG; |
if (r_type) *r_type = PGP_SIG; |
362 |
break; |
break; |
363 |
|
|
364 |
case PKT_PUBLIC_KEY: |
case PKT_PUBLIC_KEY: |
365 |
s = "PUBKEY"; rc = -2; |
s = "PUBKEY"; rc = -2; |
366 |
if (r_type) *r_type = PGP_PUBKEY; |
if (r_type) *r_type = PGP_PUBKEY; |
367 |
break; |
break; |
368 |
|
|
369 |
case PKT_SECRET_KEY: |
case PKT_SECRET_KEY: |
370 |
s = "SECKEY"; rc = -2; |
s = "SECKEY"; rc = -2; |
371 |
if (r_type) *r_type = PGP_SECKEY; |
if (r_type) *r_type = PGP_SECKEY; |
373 |
|
|
374 |
case PKT_COMPRESSED: |
case PKT_COMPRESSED: |
375 |
/* If we only find 1 packet and it is compressed, |
/* If we only find 1 packet and it is compressed, |
376 |
we assume a compress one-pass signature. */ |
we assume a compressed one-pass signature. */ |
377 |
if (count != 0) |
if (count != 0) |
378 |
break; |
break; |
379 |
s = "SIGNED"; rc = -2; |
s = "SIGNED"; rc = -2; |
380 |
compr = 1; |
compr = 1; |
381 |
break; |
break; |
382 |
|
|
396 |
if (!s) |
if (!s) |
397 |
s = "UNKNOWN"; |
s = "UNKNOWN"; |
398 |
if (!strcmp (s, "SIGNED") && !compr |
if (!strcmp (s, "SIGNED") && !compr |
399 |
&& strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) { |
&& strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR")) { |
400 |
if (r_type) *r_type = PGP_SIG; |
if (r_type) *r_type = PGP_SIG; |
401 |
s = "SIGNED-DETACH"; |
s = "SIGNED-DETACH"; |
402 |
} |
} |
404 |
} |
} |
405 |
|
|
406 |
|
|
407 |
/* Build the File Manager list view control. */ |
/* Build the File Manager dialog context. */ |
408 |
int |
void |
409 |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
fm_build (fm_info_t *r_fm, HWND ctrl) |
410 |
{ |
{ |
411 |
int i, rc = 0; |
|
412 |
listview_ctrl_t c; |
fm_info_t fm; |
413 |
struct listview_column_s col[] = { |
struct listview_column_s col[] = { |
414 |
{0, 80, (char *)_("Status") }, |
{0, 80, (char *)_("Status") }, |
415 |
{1, 256, (char *)_("Name") }, |
{1, 256, (char *)_("Name") }, |
416 |
{2, 128, (char *)_("Operation") }, |
{2, 128, (char *)_("Operation") }, |
417 |
{0, 0, NULL } |
{0, 0, NULL} |
418 |
}; |
}; |
419 |
|
int i; |
420 |
rc = listview_new (&c); |
|
421 |
if (rc) |
fm = new fm_info_s; |
422 |
BUG (NULL); |
memset (fm, 0, sizeof *fm); |
423 |
c->ctrl = ctrl; |
listview_new (&fm->lv, ctrl); |
424 |
for (i = 0; col[i].width; i++) |
for (i = 0; col[i].width; i++) |
425 |
listview_add_column (c, &col[i]); |
listview_add_column (fm->lv, &col[i]); |
426 |
listview_set_ext_style (c); |
listview_set_ext_style (fm->lv); |
427 |
if (lv) |
fm->model = NULL; /*init*/ |
428 |
*lv = c; |
*r_fm = fm; |
|
return 0; |
|
429 |
} |
} |
430 |
|
|
431 |
|
|
432 |
/* Release the File Manager listview control. */ |
/* Release the file model in @mod. */ |
433 |
void |
static void |
434 |
fm_delete (listview_ctrl_t lv) |
fm_model_release (fm_model_t mod) |
435 |
{ |
{ |
436 |
if (lv) { |
fm_model_t m; |
437 |
listview_release(lv); |
|
438 |
|
while (mod) { |
439 |
|
m = mod->next; |
440 |
|
free_if_alloc (mod->name); |
441 |
|
free_if_alloc (mod->op); |
442 |
|
free_if_alloc (mod->status); |
443 |
|
free_if_alloc (mod); |
444 |
|
mod = m; |
445 |
} |
} |
446 |
} |
} |
447 |
|
|
448 |
|
|
449 |
|
/* Reset the File Manager info context @fm. */ |
450 |
|
void |
451 |
|
fm_reset (fm_info_t fm) |
452 |
|
{ |
453 |
|
listview_del_all_items (fm->lv); |
454 |
|
fm_model_release (fm->model); |
455 |
|
fm->model = NULL; |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
|
/* Release the File Manager dialog context @fm. */ |
460 |
|
void |
461 |
|
fm_delete (fm_info_t fm) |
462 |
|
{ |
463 |
|
if (!fm) |
464 |
|
return; |
465 |
|
if (fm->menu) |
466 |
|
DestroyMenu (fm->menu); |
467 |
|
listview_release (fm->lv); |
468 |
|
fm_model_release (fm->model); |
469 |
|
free_if_alloc (fm); |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
int |
int |
474 |
fm_state_new (fm_state_t * ctx) |
fm_state_new (fm_state_t * ctx) |
475 |
{ |
{ |
476 |
gpgme_error_t rc; |
fm_state_s *c; |
|
fm_state_s * c; |
|
477 |
|
|
478 |
c = new fm_state_s; |
c = new fm_state_s; |
479 |
if (!c) |
if (!c) |
480 |
BUG (0); |
BUG (0); |
481 |
memset (c, 0, sizeof *c); |
memset (c, 0, sizeof *c); |
482 |
rc = gpgme_new (&c->ctx); |
if (gpgme_new (&c->ctx)) |
|
if (rc) |
|
483 |
BUG (0); |
BUG (0); |
|
/* XXX rc = gpgme_recipients_new (&c->recp);*/ |
|
|
/* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */ |
|
484 |
*ctx = c; |
*ctx = c; |
485 |
return 0; |
return 0; |
486 |
} /* fm_state_new */ |
} |
487 |
|
|
488 |
|
|
489 |
/* Release the FM state handle @c. */ |
/* Release the FM state handle @c. */ |
499 |
safe_free (c->recp); |
safe_free (c->recp); |
500 |
free_if_alloc (c->opaque); |
free_if_alloc (c->opaque); |
501 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
502 |
delete c; c = NULL; |
delete c; |
503 |
} |
} |
504 |
|
|
505 |
|
|
506 |
|
/* Check if file @file is already in the list view. */ |
507 |
static int |
static int |
508 |
fm_check_for_entry( listview_ctrl_t lv, const char *file ) |
fm_check_for_entry (listview_ctrl_t lv, const char *file) |
509 |
{ |
{ |
510 |
char name[512]; |
char name[MAX_PATH+128]; |
511 |
int i; |
int i; |
512 |
|
|
513 |
memset (name, 0, sizeof (name)); |
memset (name, 0, sizeof (name)); |
514 |
for (i = 0; i < listview_count_items( lv, 0 ); i++) { |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
515 |
listview_get_item_text( lv, i, 1, name, sizeof (name) - 1 ); |
listview_get_item_text (lv, i, FM_COL_NAME, name, DIM (name) - 1); |
516 |
if( !strcmp( name, file ) ) |
if (!stricmp (name, file)) |
517 |
return 1; /* found */ |
return 1; /* found */ |
518 |
} |
} |
519 |
|
|
520 |
return 0; |
return 0; |
521 |
} /* fm_check_for_entry */ |
} |
522 |
|
|
523 |
|
|
524 |
static int |
static int |
525 |
fm_set_ftype (listview_ctrl_t lv, const char *name) |
fm_set_ftype (listview_ctrl_t lv, fm_model_t *fm, const char *name) |
526 |
{ |
{ |
527 |
|
fm_model_t m; |
528 |
const char *type; |
const char *type; |
529 |
int rc; |
int rc; |
530 |
|
|
531 |
rc = fm_check_for_entry (lv, name); |
rc = fm_check_for_entry (lv, name); |
532 |
if (rc) |
if (rc) |
533 |
return 0; |
return 0; /* already present. */ |
534 |
|
m = new fm_model_s; |
535 |
|
memset (m, 0, sizeof *m); |
536 |
type = fm_get_file_type (name, NULL); |
type = fm_get_file_type (name, NULL); |
537 |
if (!type || !strcmp (type, "UNKNOWN")) |
if (!type || !strcmp (type, "UNKNOWN")) |
538 |
type = gnupg_check_file_ext (name, NULL); |
type = gnupg_check_file_ext (name, NULL); |
539 |
rc = listview_add_item (lv, " "); |
listview_add_item2 (lv, " ", (void*)m); |
540 |
if (rc) |
listview_add_sub_item (lv, 0, FM_COL_STAT, type); |
541 |
return -1; |
listview_add_sub_item (lv, 0, FM_COL_NAME, name); |
542 |
listview_add_sub_item (lv, 0, 0, type); |
m->name = m_strdup (name); |
543 |
listview_add_sub_item (lv, 0, 1, name); |
m->status = m_strdup (type); |
544 |
|
m->op = NULL; |
545 |
|
fm_model_add_file (fm, m); |
546 |
return 0; |
return 0; |
547 |
} |
} |
548 |
|
|
549 |
|
|
550 |
|
/* Add all files from the directory @path to the list view @lv. */ |
551 |
static int |
static int |
552 |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
fm_add_dir_files (listview_ctrl_t lv, fm_model_t *fm, char *path) |
553 |
{ |
{ |
554 |
struct _finddata_t fd; |
WIN32_FIND_DATA fd; |
555 |
char * p; |
HANDLE hd; |
556 |
long hd; |
char *p; |
557 |
|
|
558 |
strcat (path, "\\*"); |
strcat (path, "\\*"); |
559 |
hd = _findfirst (path, &fd); |
hd = FindFirstFile (path, &fd); |
560 |
|
if (hd == INVALID_HANDLE_VALUE) |
561 |
|
return -1; |
562 |
do { |
do { |
563 |
p = new char [(strlen (path) + strlen (fd.name))+1]; |
if (fd.cFileName[0] == '.' && strlen (fd.cFileName) < 3) |
564 |
|
continue; |
565 |
|
p = new char [strlen (path) + strlen (fd.cFileName)+1]; |
566 |
if (!p) |
if (!p) |
567 |
BUG (0); |
BUG (0); |
568 |
memcpy (p, path, strlen (path)-1); |
memcpy (p, path, strlen (path)-1); |
569 |
p[strlen (path)-1] = 0; |
p[strlen (path)-1] = 0; |
570 |
strcat (p, fd.name); |
strcat (p, fd.cFileName); |
571 |
if (!is_directory (p)) |
if (!is_directory (p)) |
572 |
fm_set_ftype (lv, p); |
fm_set_ftype (lv, fm, p); |
573 |
free_if_alloc (p); |
free_if_alloc (p); |
574 |
} while (_findnext (hd, &fd) == 0); |
} while (FindNextFile (hd, &fd)); |
575 |
_findclose (hd); |
FindClose (hd); |
576 |
return 0; |
return 0; |
577 |
} |
} |
578 |
|
|
580 |
/* Add the drag & drop files from @dd_files to the |
/* Add the drag & drop files from @dd_files to the |
581 |
list view control @lv. */ |
list view control @lv. */ |
582 |
int |
int |
583 |
fm_add_dropped_files (listview_ctrl_t lv, HDROP dd_files) |
fm_add_dropped_files (fm_info_t fm, HDROP dd_files) |
584 |
{ |
{ |
585 |
char name[384+4]; |
char name[MAX_PATH+32+4]; |
|
int nfiles; |
|
586 |
int rc = 0; |
int rc = 0; |
587 |
int i; |
UINT i; |
588 |
|
|
589 |
memset (name, 0, sizeof (name)); |
for (i = 0; i < DragQueryFile (dd_files, 0xFFFFFFFF, NULL, 0); i++) { |
590 |
nfiles = DragQueryFile (dd_files, 0xFFFFFFFF, NULL, 0); |
memset (name, 0, sizeof (name)); |
591 |
for (i = 0; i < nfiles; i++) { |
DragQueryFile (dd_files, i, name, DIM (name) -1); |
|
DragQueryFile (dd_files, i, name, sizeof (name) -1); |
|
592 |
if (is_directory (name)) |
if (is_directory (name)) |
593 |
rc = fm_add_dir_files (lv, name); |
rc = fm_add_dir_files (fm->lv, &fm->model, name); |
594 |
else |
else |
595 |
rc = fm_set_ftype (lv, name); |
rc = fm_set_ftype (fm->lv, &fm->model, name); |
596 |
if (rc == -1) |
if (rc == -1) |
597 |
break; /* XXX: fixme? */ |
break; /* XXX: fixme? */ |
598 |
} |
} |
605 |
figure out the type of it. |
figure out the type of it. |
606 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
607 |
static int |
static int |
608 |
add_single_file (listview_ctrl_t lv, const char *name) |
add_single_file (listview_ctrl_t lv, fm_model_t *fm, const char *name) |
609 |
{ |
{ |
610 |
|
fm_model_t m; |
611 |
const char *type; |
const char *type; |
612 |
int rc = 0; |
int rc; |
613 |
|
|
614 |
type = fm_get_file_type (name, NULL); |
type = fm_get_file_type (name, NULL); |
615 |
if (!type) |
if (!type) |
616 |
return WPTERR_FILE_OPEN; |
return WPTERR_FILE_OPEN; |
617 |
|
m = new fm_model_s; |
618 |
|
memset (m, 0, sizeof *m); |
619 |
if (!strcmp (type, "UNKNOWN")) |
if (!strcmp (type, "UNKNOWN")) |
620 |
type = gnupg_check_file_ext (name, NULL); |
type = gnupg_check_file_ext (name, NULL); |
621 |
rc = listview_add_item (lv, ""); |
rc = listview_add_item2 (lv, "", (void*)m); |
622 |
if (!rc) { |
if (!rc) { |
623 |
listview_add_sub_item (lv, 0, 0, type); |
listview_add_sub_item (lv, 0, FM_COL_STAT, type); |
624 |
listview_add_sub_item (lv, 0, 1, name); |
listview_add_sub_item (lv, 0, FM_COL_NAME, name); |
625 |
} |
} |
626 |
|
m->status = m_strdup (type); |
627 |
|
m->name = m_strdup (name); |
628 |
|
m->op = NULL; |
629 |
|
fm_model_add_file (fm, m); |
630 |
return rc; |
return rc; |
631 |
} |
} |
632 |
|
|
634 |
/* Use the common Open-File-Dialog to allow the user to |
/* Use the common Open-File-Dialog to allow the user to |
635 |
add one ore more selected files to the listview @lv. */ |
add one ore more selected files to the listview @lv. */ |
636 |
int |
int |
637 |
fm_add_opened_files (listview_ctrl_t lv, HWND dlg) |
fm_add_opened_files (fm_info_t fm, HWND dlg) |
638 |
{ |
{ |
639 |
OPENFILENAME open; |
OPENFILENAME open; |
640 |
char file[512], name[MAX_PATH+1]; |
char file[512], name[MAX_PATH+1]; |
650 |
open.lpstrFilter = "All Files (*.*)\0*.*\0\0"; |
open.lpstrFilter = "All Files (*.*)\0*.*\0\0"; |
651 |
open.hwndOwner = dlg; |
open.hwndOwner = dlg; |
652 |
open.lpstrFile = file; |
open.lpstrFile = file; |
653 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = DIM (file) - 1; |
654 |
open.Flags = OFN_ALLOWMULTISELECT|OFN_EXPLORER ; |
open.Flags = OFN_ALLOWMULTISELECT|OFN_EXPLORER ; |
655 |
|
|
656 |
memset (file, 0, sizeof file); |
memset (file, 0, sizeof file); |
657 |
if (!GetOpenFileName (&open)) |
if (!GetOpenFileName (&open)) |
658 |
return 0; |
return 0; |
659 |
|
|
660 |
|
/* It is possible that multiple files are returned |
661 |
|
and then they are separated by \0 chars. */ |
662 |
s = file; |
s = file; |
663 |
len = sizeof (file)-1; |
len = DIM (file)-1; |
664 |
for (;;) { |
for (;;) { |
665 |
if (len < 2 || (*s == '\0' && *(s+1) == '\0')) |
if (len < 2 || (*s == '\0' && *(s+1) == '\0')) |
666 |
break; |
break; |
673 |
name[i] = *s++; |
name[i] = *s++; |
674 |
} |
} |
675 |
if (n == 0) |
if (n == 0) |
676 |
path = strdup (name); |
path = m_strdup (name); |
677 |
else { |
else { |
678 |
char *p = make_filename (path, name, NULL); |
char *p = make_filename (path, name, NULL); |
679 |
rc = add_single_file (lv, p); |
rc = add_single_file (fm->lv, &fm->model, p); |
680 |
free (p); |
free_if_alloc (p); |
681 |
} |
} |
682 |
n++; |
n++; |
683 |
} |
} |
684 |
if (n == 1) /* single file selected. */ |
if (n == 1) /* single file selected. */ |
685 |
rc = add_single_file (lv, path); |
rc = add_single_file (fm->lv, &fm->model, path); |
686 |
if (path) |
free_if_alloc (path); |
|
free (path); |
|
687 |
return rc; |
return rc; |
688 |
} |
} |
689 |
|
|
690 |
|
|
691 |
int |
int |
692 |
fm_assume_onepass_sig (const char * fname) |
fm_assume_onepass_sig (const char *fname) |
693 |
{ |
{ |
|
gpgme_data_t dat; |
|
694 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
695 |
gpg_iobuf_t fp; |
gpg_iobuf_t fp; |
696 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
gpgme_data_t dat; |
697 |
|
PACKET *pkt; |
698 |
|
char tmpfile[MAX_PATH+1]; |
699 |
int check = 0; |
int check = 0; |
700 |
|
|
701 |
|
pkt = (PACKET *)calloc (1, sizeof *pkt); |
702 |
if (!fname) { |
if (!fname) { |
703 |
|
get_temp_name (tmpfile, DIM (tmpfile)-1, "gpgme.tmp"); |
704 |
gpg_data_new_from_clipboard (&dat, 0); |
gpg_data_new_from_clipboard (&dat, 0); |
705 |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
gpg_data_release_and_set_file (dat, tmpfile); |
706 |
|
|
707 |
fp = gpg_iobuf_open ("gpgme.tmp"); |
fp = gpg_iobuf_open (tmpfile); |
708 |
if (!fp) |
if (!fp) |
709 |
return 0; |
return 0; |
710 |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
gpg_iobuf_ioctl (fp, 3, 1, NULL); /* disable cache. */ |
711 |
if (gpg_use_armor_filter(fp)) { |
if (gpg_use_armor_filter(fp)) { |
712 |
memset (&afx, 0, sizeof (afx)); |
memset (&afx, 0, sizeof (afx)); |
713 |
gpg_iobuf_push_filter (fp, gpg_armor_filter, &afx); |
gpg_iobuf_push_filter (fp, gpg_armor_filter, &afx); |
717 |
&& pkt->pkttype == PKT_COMPRESSED) |
&& pkt->pkttype == PKT_COMPRESSED) |
718 |
check = 1; |
check = 1; |
719 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
|
safe_free (pkt); |
|
720 |
gpg_iobuf_close (fp); |
gpg_iobuf_close (fp); |
721 |
remove ("gpgme.tmp"); |
DeleteFile (tmpfile); |
722 |
} |
} |
723 |
/* XXX: implement it for real files */ |
/* XXX: implement it for real files */ |
724 |
|
safe_free (pkt); |
725 |
return check; |
return check; |
726 |
} |
} |
727 |
|
|
729 |
int |
int |
730 |
fm_get_current_pos (listview_ctrl_t lv) |
fm_get_current_pos (listview_ctrl_t lv) |
731 |
{ |
{ |
732 |
int i = 0, items; |
int i = 0; |
733 |
|
int items; |
734 |
|
|
735 |
items = listview_count_items (lv, 0); |
items = listview_count_items (lv, 0); |
736 |
if (!items) |
if (!items) |
737 |
return -1; |
return -1; |
738 |
else if (items == 1) |
else if (items == 1) { |
|
{ |
|
739 |
listview_select_one (lv, 0); |
listview_select_one (lv, 0); |
740 |
return 0; |
return 0; |
741 |
} |
} |
742 |
else if (items > 1) |
else if (items > 1) { |
|
{ |
|
743 |
i = listview_get_curr_pos (lv); |
i = listview_get_curr_pos (lv); |
744 |
if (i == -1) |
if (i == -1) { |
745 |
{ |
msg_box (lv->ctrl, _("Please select a file."), |
746 |
msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
747 |
return -1; |
return -1; |
748 |
} |
} |
749 |
return i; |
return i; |
750 |
} |
} |
751 |
|
|
752 |
return -1; |
return -1; |
753 |
} /* fm_get_current_pos */ |
} |
754 |
|
|
755 |
|
|
756 |
static int |
static int |
757 |
fm_check_detached_sig( listview_ctrl_t lv, int pos ) |
fm_check_detached_sig (listview_ctrl_t lv, int pos) |
758 |
{ |
{ |
759 |
char type[128]; |
char type[64]; |
760 |
|
|
761 |
listview_get_item_text( lv, pos, 0, type, 127 ); |
listview_get_item_text (lv, pos, 0, type, DIM (type)-1); |
762 |
return !strcmp( type, "SIGNED-DETACH" )? 1 : 0; |
return !strcmp (type, "SIGNED-DETACH")? 1 : 0; |
763 |
} /* fm_check_detached_sig */ |
} |
764 |
|
|
765 |
|
|
766 |
|
/* Check if the given file on position @pos is useful for |
767 |
|
command @fmd_cmd. For example sign can be used for all files |
768 |
|
which are not already signed. */ |
769 |
int |
int |
770 |
fm_check_file_type (listview_ctrl_t lv, int pos, int fm_cmd) |
fm_check_file_type (listview_ctrl_t lv, int pos, int fm_cmd) |
771 |
{ |
{ |
772 |
char status[128]; |
char status[64]; |
773 |
int rc = 0; |
int rc = 0; |
774 |
|
|
775 |
listview_get_item_text (lv, pos, 0, status, sizeof (status) - 1); |
listview_get_item_text (lv, pos, 0, status, DIM (status) - 1); |
776 |
|
|
777 |
switch (fm_cmd) { |
switch (fm_cmd) { |
778 |
case FM_ENCRYPT: |
case FM_ENCRYPT: |
784 |
break; |
break; |
785 |
|
|
786 |
case FM_DECRYPT: |
case FM_DECRYPT: |
787 |
if (!strcmp (status, "DATA") |
if (!strcmp (status, "DATA") || |
788 |
|| !strcmp (status, "ENCRYPTED") |
!strcmp (status, "ENCRYPTED") || |
789 |
|| !strcmp (status, "SYMKEYENC") |
!strcmp (status, "SYMKEYENC") || |
790 |
|| !strcmp (status, "ARMORED")) |
!strcmp (status, "ARMORED")) |
791 |
rc = 1; |
rc = 1; |
792 |
break; |
break; |
793 |
|
|
794 |
case FM_SIGN: |
case FM_SIGN: |
795 |
if( strncmp( status, "SIGNED", 6 ) ) |
if (strncmp( status, "SIGNED", 6)) |
796 |
rc = 1; |
rc = 1; |
797 |
break; |
break; |
798 |
|
|
799 |
case FM_VERIFY: |
case FM_VERIFY: |
800 |
if( !strncmp( status, "SIGNED", 6 ) |
if(!strncmp (status, "SIGNED", 6) || |
801 |
|| !strcmp( status, "COMPRESSED" ) ) |
!strcmp (status, "COMPRESSED")) |
802 |
rc = 1; |
rc = 1; |
803 |
break; |
break; |
804 |
|
|
805 |
case FM_SYMENC: |
case FM_SYMENC: |
806 |
if( strcmp( status, "SYMKEYENC" ) ) |
if (strcmp (status, "SYMKEYENC")) |
807 |
rc = 1; |
rc = 1; |
808 |
break; |
break; |
809 |
|
|
810 |
case FM_IMPORT: |
case FM_IMPORT: |
811 |
if( !strcmp( status, "PUBKEY" ) |
if (!strcmp (status, "PUBKEY") || |
812 |
|| !strcmp( status, "SECKEY" ) ) |
!strcmp (status, "SECKEY")) |
813 |
rc = 1; |
rc = 1; |
814 |
break; |
break; |
815 |
|
|
820 |
} |
} |
821 |
|
|
822 |
return rc; |
return rc; |
823 |
} /* fm_check_file_type */ |
} |
824 |
|
|
825 |
|
|
826 |
/* Set the file status of the given command @fm_cmd. |
/* Set the file status of the given command @fm_cmd. |
841 |
switch (fm_cmd) { |
switch (fm_cmd) { |
842 |
case FM_ENCRYPT: |
case FM_ENCRYPT: |
843 |
case FM_ENCRYPT_DIR: |
case FM_ENCRYPT_DIR: |
844 |
case FM_SIGNENCRYPT: strcpy (status, "ENCRYPTED"); break; |
case FM_SIGNENCRYPT: |
845 |
case FM_DECRYPT: strcpy (status, "UNKNOWN"); break; |
strcpy (status, "ENCRYPTED"); |
846 |
|
break; |
847 |
|
|
848 |
|
case FM_DECRYPT: |
849 |
|
strcpy (status, "UNKNOWN"); |
850 |
|
break; |
851 |
|
|
852 |
case FM_SIGN: |
case FM_SIGN: |
853 |
if (sigmode == GPGME_SIG_MODE_DETACH) |
if (sigmode == GPGME_SIG_MODE_DETACH) |
854 |
strcpy (status, "SIGNED-DETACH"); |
strcpy (status, "SIGNED-DETACH"); |
857 |
else |
else |
858 |
strcpy (status, "SIGNED"); |
strcpy (status, "SIGNED"); |
859 |
break; |
break; |
860 |
case FM_VERIFY: update = 0; break; |
case FM_VERIFY: |
861 |
case FM_SYMENC: strcpy (status, "SYMKEYENC"); break; |
update = 0; |
862 |
case FM_IMPORT: update = 0; break; |
break; |
863 |
case FM_WIPE: strcpy (status, "WIPED"); break; |
|
864 |
default: strcpy (status, "UNKNOWN"); break; |
case FM_SYMENC: |
865 |
|
strcpy (status, "SYMKEYENC"); |
866 |
|
break; |
867 |
|
|
868 |
|
case FM_IMPORT: |
869 |
|
update = 0; |
870 |
|
break; |
871 |
|
|
872 |
|
case FM_WIPE: |
873 |
|
strcpy (status, "WIPED"); |
874 |
|
break; |
875 |
|
|
876 |
|
default: |
877 |
|
strcpy (status, "UNKNOWN"); |
878 |
|
break; |
879 |
} |
} |
880 |
|
|
881 |
if (success && update) { |
if (success && update) { |
882 |
listview_add_sub_item (lv, pos, 0, status); |
listview_add_sub_item (lv, pos, FM_COL_STAT, status); |
883 |
listview_add_sub_item (lv, pos, 1, output); |
listview_add_sub_item (lv, pos, FM_COL_NAME, output); |
884 |
} |
} |
885 |
listview_add_sub_item( lv, pos, 2, operat ); |
listview_add_sub_item (lv, pos, FM_COL_OP, operat); |
886 |
} |
} |
887 |
|
|
888 |
|
|
890 |
fm_clearsign_8bit (listview_ctrl_t lv, fm_state_s *ctx) |
fm_clearsign_8bit (listview_ctrl_t lv, fm_state_s *ctx) |
891 |
{ |
{ |
892 |
FILE *f; |
FILE *f; |
893 |
byte buf[32]; |
BYTE buf[32]; |
894 |
char name[256]; |
char name[MAX_PATH+1]; |
895 |
int i, n, cnt=0; |
int i, n, cnt=0; |
896 |
|
|
897 |
if (ctx->sigmode != GPGME_SIG_MODE_CLEAR) |
if (ctx->sigmode != GPGME_SIG_MODE_CLEAR) |
898 |
return 0; |
return 0; |
899 |
listview_get_item_text (lv, -1, 1, name, sizeof (name)-1); |
listview_get_item_text (lv, -1, FM_COL_NAME, name, DIM (name)-1); |
900 |
if (stristr (name, ".TXT")) |
if (stristr (name, ".txt")) |
901 |
return 0; |
return 0; |
902 |
f = fopen (name, "rb"); |
f = fopen (name, "rb"); |
903 |
if (!f) |
if (!f) |
904 |
return -1; /* should never happen */ |
return -1; /* should never happen */ |
905 |
n = fread (buf, 1, 32, f); |
n = fread (buf, 1, 32, f); |
906 |
|
fclose (f); |
907 |
for (i = 0; i < n; i++) { |
for (i = 0; i < n; i++) { |
908 |
if (buf[i] == 0x00 || buf[i] > 170) |
if (buf[i] == 0x00 || buf[i] > 170) |
909 |
cnt++; |
cnt++; |
910 |
} |
} |
|
fclose (f); |
|
911 |
if (!cnt) |
if (!cnt) |
912 |
return 0; |
return 0; |
913 |
n = -1; |
n = -1; |
914 |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
915 |
_("\"%s\" does not seems to be a text file.\n" |
_("\"%s\" does not seems to be a text file.\n" |
916 |
"Do you really want to clearsign it?"), name); |
"Do you really want to clearsign it?"), name); |
917 |
if (i == IDYES) |
if (i == IDYES) |
919 |
return n; |
return n; |
920 |
} |
} |
921 |
|
|
922 |
|
|
923 |
int |
int |
924 |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
925 |
{ |
{ |
928 |
fm_state_s * ctx; |
fm_state_s * ctx; |
929 |
int fm_cmd, sig_detached = 0; |
int fm_cmd, sig_detached = 0; |
930 |
int rc = 0, i, n, ndel = 0; |
int rc = 0, i, n, ndel = 0; |
931 |
char fname[512], status[128]; |
char fname[2*MAX_PATH+1], status[128]; |
932 |
|
|
933 |
switch (cmd) { |
switch (cmd) { |
934 |
case ID_FILEMISC_ENCRYPT: fm_cmd = FM_ENCRYPT; break; |
case ID_FILEMISC_ENCRYPT: fm_cmd = FM_ENCRYPT; break; |
994 |
break; |
break; |
995 |
} |
} |
996 |
|
|
997 |
for( i = 0, n = 0; i < listview_count_items( lv, 0 ); i++ ) { |
for( i = 0, n = 0; i < listview_count_items (lv, 0); i++ ) { |
998 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
999 |
continue; |
continue; |
1000 |
listview_get_item_text( lv, i, 0, status, sizeof (status) -1 ); |
listview_get_item_text (lv, i, FM_COL_STAT, status, DIM (status) -1); |
1001 |
if (!strcmp( status, "ENCRYPTED" ) && fm_cmd == FM_DECRYPT) |
if (!strcmp( status, "ENCRYPTED") && fm_cmd == FM_DECRYPT) |
1002 |
n++; |
n++; |
1003 |
if (!strcmp( status, "UNKNOWN" ) && fm_cmd == FM_SIGN) |
if (!strcmp( status, "UNKNOWN") && fm_cmd == FM_SIGN) |
1004 |
n++; |
n++; |
1005 |
if (fm_cmd == FM_WIPE) |
if (fm_cmd == FM_WIPE) |
1006 |
ndel++; |
ndel++; |
1022 |
fm_encrypt_into_zip (ctx, lv); |
fm_encrypt_into_zip (ctx, lv); |
1023 |
|
|
1024 |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
1025 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
1026 |
continue; |
continue; |
1027 |
listview_get_item_text(lv, i, 1, fname, sizeof (fname) - 1); |
listview_get_item_text (lv, i, FM_COL_NAME, fname, DIM (fname) - 1); |
1028 |
if( file_exist_check (fname) && !is_directory (fname)) { |
if( file_exist_check (fname) && !is_directory (fname)) { |
1029 |
log_box (_("File Manager"), MB_ERR, |
log_box (_("File Manager"), MB_ERR, |
1030 |
_("\"%s\" does not exist"), fname); |
_("\"%s\" does not exist"), fname); |
1043 |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
1044 |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
1045 |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
1046 |
case FM_SYMENC: rc = fm_sym_encrypt( ctx, fname );break; |
case FM_SYMENC: rc = fm_sym_encrypt (ctx, fname); break; |
1047 |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
1048 |
case FM_IMPORT: |
case FM_IMPORT: |
1049 |
free_if_alloc (ctx->opaque); |
free_if_alloc (ctx->opaque); |
1050 |
ctx->opaque = m_strdup (fname); |
ctx->opaque = m_strdup (fname); |
1051 |
if (!ctx->opaque) |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
1052 |
BUG (0); |
file_import_dlg_proc, (LPARAM)ctx); |
|
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
|
|
file_import_dlg_proc, (LPARAM)ctx ); |
|
1053 |
if (ctx->cancel == 1) |
if (ctx->cancel == 1) |
1054 |
continue; |
continue; |
1055 |
rc = fm_import (ctx, fname); |
rc = fm_import (ctx, fname); |
1056 |
break; |
break; |
1057 |
} |
} |
1058 |
|
if (ctx->cancel == 1) { |
1059 |
|
ctx->cancel = 0; |
1060 |
|
continue; |
1061 |
|
} |
1062 |
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
1063 |
free_if_alloc (ctx->output); |
free_if_alloc (ctx->output); |
1064 |
progress_cleanup (&pfx); |
progress_cleanup (&pfx); |
1076 |
/* remove wipe files from the list */ |
/* remove wipe files from the list */ |
1077 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
1078 |
while (n--) { |
while (n--) { |
1079 |
listview_get_item_text (lv, n, 0, status, sizeof (status) - 1); |
listview_get_item_text (lv, n, FM_COL_STAT, status, DIM (status) - 1); |
1080 |
if (!strcmp (status, "WIPED")) |
if (!strcmp (status, "WIPED")) |
1081 |
listview_del_item (lv, n); |
listview_del_item (lv, n); |
1082 |
} |
} |
1086 |
fm_state_release (ctx); |
fm_state_release (ctx); |
1087 |
progress_cleanup (&pfx); |
progress_cleanup (&pfx); |
1088 |
return rc; |
return rc; |
1089 |
} /* fm_parse_files */ |
} |
1090 |
|
|
1091 |
|
|
1092 |
/* Wipe the given file @name with the delete mode |
/* Wipe the given file @name with the delete mode |
1119 |
static int |
static int |
1120 |
ask_filename (fm_state_t c, const char *msg, char **dst) |
ask_filename (fm_state_t c, const char *msg, char **dst) |
1121 |
{ |
{ |
1122 |
const char * s; |
const char *s; |
1123 |
|
|
1124 |
s = get_filesave_dlg (c->dlg, msg, NULL, NULL); |
s = get_filesave_dlg (c->dlg, msg, NULL, NULL); |
1125 |
if (!s) |
if (!s) |
1129 |
free_if_alloc (*dst); |
free_if_alloc (*dst); |
1130 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1131 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (0); |
|
1132 |
if (dst) |
if (dst) |
1133 |
*dst = fm_quote_file (s); |
*dst = fm_quote_file (s); |
1134 |
return 0; |
return 0; |
1143 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1144 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1145 |
char *keyid = NULL, ext[5]; |
char *keyid = NULL, ext[5]; |
|
/*int no_compr = 0;*/ |
|
1146 |
int rc = 0; |
int rc = 0; |
1147 |
|
|
1148 |
c->output = new char[strlen (name) + 5 + 1]; |
c->output = new char[strlen (name) + 5 + 1]; |
1153 |
strcat (c->output, ext); |
strcat (c->output, ext); |
1154 |
|
|
1155 |
if (!overwrite_file (c->output)) { |
if (!overwrite_file (c->output)) { |
1156 |
rc = ask_filename (c, _("Enter filename for encrypted file"), NULL); |
rc = ask_filename (c, _("Enter Filename for Encrypted File"), NULL); |
1157 |
if (rc) |
if (rc) |
1158 |
goto leave; |
goto leave; |
1159 |
} |
} |
1167 |
goto leave; |
goto leave; |
1168 |
|
|
1169 |
/* |
/* |
1170 |
|
int no_compr = 0; |
1171 |
if (c->prog_cb) { |
if (c->prog_cb) { |
1172 |
c->prog_cb->what = name; |
c->prog_cb->what = name; |
1173 |
gpg_file_data_set_cb (in, c->prog_cb); |
gpg_file_data_set_cb (in, c->prog_cb); |
1196 |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
1197 |
if (sigkey && sigkey->subkeys) { |
if (sigkey && sigkey->subkeys) { |
1198 |
keyid = m_strdup (sigkey->subkeys->keyid); |
keyid = m_strdup (sigkey->subkeys->keyid); |
|
if (!keyid) |
|
|
BUG (NULL); |
|
1199 |
} |
} |
1200 |
} |
} |
1201 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1252 |
gpgme_error_t err; |
gpgme_error_t err; |
1253 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1254 |
int rc = 0, cancel = 0; |
int rc = 0, cancel = 0; |
1255 |
char ext[5], * pass; |
char ext[5], *pass; |
1256 |
|
|
1257 |
pass = request_passphrase2 (_("Symmetric"), 0, &cancel); |
pass = request_passphrase2 (_("Symmetric Encryption"), 0, &cancel); |
1258 |
if (cancel) |
if (cancel) { |
1259 |
|
c->cancel = 1; |
1260 |
return 0; |
return 0; |
1261 |
|
} |
1262 |
|
|
1263 |
/* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/ |
/* XXX: a convenient feature could be to select the preferred |
1264 |
|
symmetric algorithm. */ |
1265 |
c->output = new char[strlen (name) + 5 + 1]; |
c->output = new char[strlen (name) + 5 + 1]; |
1266 |
if (!c->output) |
if (!c->output) |
1267 |
BUG (0); |
BUG (0); |
1274 |
goto leave; |
goto leave; |
1275 |
} |
} |
1276 |
|
|
1277 |
gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass); |
gpgme_set_passphrase_cb (ctx, sym_passphrase_cb, pass); |
|
|
|
1278 |
err = gpg_file_data_new (name, 1, &in); |
err = gpg_file_data_new (name, 1, &in); |
1279 |
if (err) |
if (err) |
1280 |
goto leave; |
goto leave; |
1306 |
} |
} |
1307 |
|
|
1308 |
|
|
|
/* 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); |
|
|
} |
|
|
|
|
|
|
|
1309 |
/* Check the recipients if we have at least one secret key. */ |
/* Check the recipients if we have at least one secret key. */ |
1310 |
bool |
bool |
1311 |
secret_key_available (gpgme_recipient_t rset) |
is_seckey_available (gpgme_recipient_t rset) |
1312 |
{ |
{ |
1313 |
gpgme_recipient_t r; |
gpgme_recipient_t r; |
1314 |
gpgme_key_t key; |
winpt_key_s key; |
1315 |
|
|
1316 |
for (r=rset; r; r = r->next) { |
for (r=rset; r; r = r->next) { |
1317 |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
1318 |
continue; |
continue; |
1319 |
else { |
else { |
1320 |
|
memset (&key, 0, sizeof (key)); |
1321 |
/* extra check to make sure the key is available right now. */ |
/* extra check to make sure the key is available right now. */ |
1322 |
if (!get_seckey (r->keyid, &key)) |
if (!winpt_get_seckey (r->keyid, &key)) { |
1323 |
|
winpt_release_pubkey (&key); |
1324 |
return true; |
return true; |
1325 |
|
} |
1326 |
|
winpt_release_pubkey (&key); |
1327 |
} |
} |
1328 |
} |
} |
1329 |
return false; |
return false; |
1330 |
} |
} |
1331 |
|
|
1332 |
|
|
1333 |
|
/* If the decrypt result contains the original file name, |
1334 |
|
we use it instead of the artificial "output - .gpg" string. */ |
1335 |
|
static int |
1336 |
|
restore_original_name (const char *output, const char *file_name) |
1337 |
|
{ |
1338 |
|
char *dir; |
1339 |
|
char *orig; |
1340 |
|
int rc = 0; |
1341 |
|
|
1342 |
|
dir = strrchr (output, '\\'); |
1343 |
|
if (!dir) |
1344 |
|
orig = strdup (file_name); |
1345 |
|
else { |
1346 |
|
orig = (char*)calloc (1, strlen (file_name)+ 1 + |
1347 |
|
strlen (output)+1); |
1348 |
|
if (!orig) |
1349 |
|
BUG (0); |
1350 |
|
memcpy (orig, output, (dir-output)+1); |
1351 |
|
strcat (orig, file_name); |
1352 |
|
} |
1353 |
|
/* XXX: we need to find out if the string needs to be utf8 decoded. */ |
1354 |
|
if (overwrite_file (orig)) { |
1355 |
|
DeleteFile (orig); |
1356 |
|
if (!MoveFile (output, orig)) |
1357 |
|
rc = -1; |
1358 |
|
} |
1359 |
|
safe_free (orig); |
1360 |
|
return rc; |
1361 |
|
} |
1362 |
|
|
1363 |
|
|
1364 |
/* Decrypt the file @name. */ |
/* Decrypt the file @name. */ |
1365 |
int |
int |
1366 |
fm_decrypt (fm_state_t c, const char *name) |
fm_decrypt (fm_state_t c, const char *name) |
1369 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1370 |
gpgme_decrypt_result_t res; |
gpgme_decrypt_result_t res; |
1371 |
gpgme_verify_result_t sigres; |
gpgme_verify_result_t sigres; |
1372 |
file_data_t in =NULL, out=NULL; |
file_data_t in = NULL, out = NULL; |
1373 |
int rc = 0; |
int rc = 0; |
1374 |
|
|
1375 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1379 |
} |
} |
1380 |
|
|
1381 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (0); |
|
1382 |
if (is_openpgp_ext (c->output)) |
if (is_openpgp_ext (c->output)) |
1383 |
c->output[strlen (c->output)-4] = '\0'; |
c->output[strlen (c->output)-4] = '\0'; |
1384 |
else { |
else { |
1388 |
if (s) { |
if (s) { |
1389 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1390 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1391 |
} |
} |
1392 |
} |
} |
1393 |
|
|
1394 |
if (overwrite_file (c->output) == 0) { |
if (overwrite_file (c->output) == 0) { |
1395 |
rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL); |
rc = ask_filename (c, _("Enter Filename for Plaintext File"), NULL); |
1396 |
if (rc) |
if (rc) |
1397 |
goto leave; |
goto leave; |
1398 |
} |
} |
1399 |
|
|
1400 |
|
/* we fetch all recipients here to make sure they list is complete. */ |
1401 |
|
release_gpg_recipients (&c->pass_cb.recipients); |
1402 |
|
gpg_get_recipients (name, &c->pass_cb.recipients); |
1403 |
|
|
1404 |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1405 |
if (err) |
if (err) |
1406 |
goto leave; |
goto leave; |
1408 |
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
1409 |
if (err) |
if (err) |
1410 |
goto leave; |
goto leave; |
1411 |
|
|
1412 |
op_begin (); |
op_begin (); |
1413 |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
1414 |
op_end (); |
op_end (); |
1420 |
} |
} |
1421 |
|
|
1422 |
res = gpgme_op_decrypt_result (ctx); |
res = gpgme_op_decrypt_result (ctx); |
1423 |
if (res && res->recipients && !secret_key_available (res->recipients)) { |
if (res && res->recipients && !is_seckey_available (res->recipients)) { |
1424 |
const char *keyid = res->recipients->keyid; |
const char *keyid = get_keyid_from_fpr (res->recipients->keyid); |
1425 |
char *p = get_key_userid (keyid+8); |
char *p = get_key_userid (keyid); |
1426 |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
1427 |
|
|
1428 |
log_box( _("Decryption"), MB_ERR, |
log_box (_("Decryption"), MB_ERR, |
1429 |
_("Encrypted with %s key, ID %s.%s\n" |
_("Encrypted with %s key, ID 0x%s.%s\n" |
1430 |
"Decryption failed: secret key not available."), |
"Decryption failed: secret key not available."), |
1431 |
get_key_pubalgo (pkalgo), keyid+8, p); |
get_key_pubalgo (pkalgo), keyid, p); |
1432 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1433 |
free_if_alloc (p); |
free_if_alloc (p); |
1434 |
goto leave; |
goto leave; |
1442 |
log_box ("Decrypt", MB_ERR, |
log_box ("Decrypt", MB_ERR, |
1443 |
_("Decryption failed.\n%s: does not exist."), c->output); |
_("Decryption failed.\n%s: does not exist."), c->output); |
1444 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1445 |
|
goto leave; |
1446 |
|
} |
1447 |
|
else if (res && res->file_name) { |
1448 |
|
char *file; |
1449 |
|
int id = IDNO; |
1450 |
|
|
1451 |
|
file = strrchr (c->output, '\\'); |
1452 |
|
if (!file) |
1453 |
|
file = c->output; |
1454 |
|
else |
1455 |
|
file++; |
1456 |
|
if (strcmp (res->file_name, file)) |
1457 |
|
id = log_box (_("Decrypt"), MB_QUEST_ASK, |
1458 |
|
_("The original file name is '%s'.\n\n" |
1459 |
|
"Do you want to use this instead of '%s'?"), |
1460 |
|
res->file_name, file); |
1461 |
|
if (id == IDYES) { |
1462 |
|
/* before we can move the file, it needs to be closed first. */ |
1463 |
|
gpg_file_data_release (out); |
1464 |
|
out = NULL; |
1465 |
|
restore_original_name (c->output, res->file_name); |
1466 |
|
} |
1467 |
} |
} |
|
|
|
1468 |
sigres = gpgme_op_verify_result (ctx); |
sigres = gpgme_op_verify_result (ctx); |
1469 |
if (sigres && sigres->signatures) |
if (sigres && sigres->signatures) |
1470 |
show_verify_result (sigres); |
verify_show_signature_state (sigres->signatures); |
1471 |
|
|
1472 |
leave: |
leave: |
1473 |
if (in) |
if (in) |
1503 |
strcat (c->output, ext); |
strcat (c->output, ext); |
1504 |
|
|
1505 |
if (!overwrite_file (c->output)) { |
if (!overwrite_file (c->output)) { |
1506 |
rc = ask_filename (c, _("Enter filename for signed file"), NULL); |
rc = ask_filename (c, _("Enter Filename for Signed File"), NULL); |
1507 |
if (rc) |
if (rc) |
1508 |
goto leave; |
goto leave; |
1509 |
} |
} |
1543 |
static void |
static void |
1544 |
fm_add_sig_stat (file_sig_ctx_t log) |
fm_add_sig_stat (file_sig_ctx_t log) |
1545 |
{ |
{ |
1546 |
gpgme_key_t key; |
struct winpt_key_s key; |
1547 |
const char *kid; |
const char *kid; |
1548 |
|
|
1549 |
kid = log->sig->fpr; |
memset (&key, 0, sizeof (key)); |
1550 |
if (!kid) |
kid = get_keyid_from_fpr (log->sig->fpr); |
1551 |
BUG (NULL); |
log->use_uid = 0; |
1552 |
if (strlen (kid) == 40) |
if (!winpt_get_pubkey (kid, &key)) { |
1553 |
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; |
|
1554 |
log->use_uid = 1; |
log->use_uid = 1; |
1555 |
} |
} |
1556 |
file_verify_add_state (log); |
file_verify_add_state (log); |
1557 |
|
winpt_release_pubkey (&key); |
1558 |
} |
} |
1559 |
|
|
1560 |
|
|
1568 |
char file[256], *fname = NULL; |
char file[256], *fname = NULL; |
1569 |
int del_end = 0; |
int del_end = 0; |
1570 |
|
|
1571 |
listview_get_item_text (lv, pos, 0, stat, sizeof (stat)-1); |
listview_get_item_text (lv, pos, FM_COL_STAT, stat, DIM (stat)-1); |
1572 |
listview_get_item_text (lv, pos, 1, file, sizeof (file)-1); |
listview_get_item_text (lv, pos, FM_COL_NAME, file, DIM (file)-1); |
1573 |
if (strcmp (stat, "UNKNOWN")) |
if (strcmp (stat, "UNKNOWN")) |
1574 |
return 0; |
return 0; |
1575 |
fname = make_filename (NULL, file, "asc"); |
fname = make_filename (NULL, file, "asc"); |
1576 |
if (file_exist_check (fname) != 0) { |
if (file_exist_check (fname) != 0) { |
1577 |
fp = fopen (fname, "wb"); |
fp = fopen (fname, "wb"); |
1578 |
if (fp == NULL) { |
if (fp == NULL) { |
1579 |
log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname); |
log_box (_("File Manager"), MB_ERR, "Could not create '%s'", fname); |
1580 |
free_if_alloc (fname); |
free_if_alloc (fname); |
1581 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1582 |
} |
} |
1586 |
} |
} |
1587 |
fm_verify (ctx, 1, fname); |
fm_verify (ctx, 1, fname); |
1588 |
if (del_end) |
if (del_end) |
1589 |
remove (fname); |
DeleteFile (fname); |
1590 |
free_if_alloc (fname); |
free_if_alloc (fname); |
1591 |
return 0; |
return 0; |
1592 |
} |
} |
1611 |
this case */ |
this case */ |
1612 |
fm_state_new (&ctx); |
fm_state_new (&ctx); |
1613 |
i = listview_get_curr_pos (lv); |
i = listview_get_curr_pos (lv); |
1614 |
if (i= -1) { |
if (i == -1) { |
1615 |
verify_pasted (lv, ctx, dat, i, dlg); |
verify_pasted (lv, ctx, dat, i, dlg); |
1616 |
fnd = 1; |
fnd = 1; |
1617 |
} |
} |
1643 |
else |
else |
1644 |
title = _("Selected Output File"); |
title = _("Selected Output File"); |
1645 |
|
|
1646 |
if (strstr (name, ".sig") |
if (is_openpgp_ext (name)) { |
1647 |
|| strstr (name, ".asc") |
_snprintf (fname, DIM (fname) - 1, "%s", name); |
|
|| strstr (name, ".gpg")) { |
|
|
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
|
1648 |
fname[strlen (fname) - 4] = '\0'; |
fname[strlen (fname) - 4] = '\0'; |
1649 |
if (file_exist_check (fname) == 0 && detached) |
if (file_exist_check (fname) == 0 && detached) |
1650 |
file = fname; |
file = fname; |
1665 |
if (file) { |
if (file) { |
1666 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1667 |
c->output = m_strdup (file); |
c->output = m_strdup (file); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1668 |
} |
} |
1669 |
else { |
else { |
1670 |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
1673 |
if (detached) |
if (detached) |
1674 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
c->sigmode = GPGME_SIG_MODE_DETACH; |
1675 |
else { |
else { |
1676 |
if (strstr (name, ".asc")) |
if (stristr (name, ".asc")) |
1677 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
1678 |
else |
else |
1679 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
1695 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1696 |
int rc = 0; |
int rc = 0; |
1697 |
|
|
1698 |
if (strstr (name, ".sig")) |
if (stristr (name, ".sig")) |
1699 |
detached = 1; |
detached = 1; |
1700 |
|
|
1701 |
if (get_output_file (c, name, detached)) |
if (get_output_file (c, name, detached)) |
1703 |
|
|
1704 |
memset (&log, 0, sizeof (log)); |
memset (&log, 0, sizeof (log)); |
1705 |
log.file = m_strdup (name); |
log.file = m_strdup (name); |
|
if (!log.file) |
|
|
BUG (NULL); |
|
1706 |
file_verify_create_dlg (); |
file_verify_create_dlg (); |
1707 |
|
|
1708 |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1726 |
} |
} |
1727 |
|
|
1728 |
res = gpgme_op_verify_result (ctx); |
res = gpgme_op_verify_result (ctx); |
1729 |
|
if (!res) |
1730 |
|
goto leave; |
1731 |
for (s=res->signatures; s; s=s->next) { |
for (s=res->signatures; s; s=s->next) { |
1732 |
log.sig = s; |
log.sig = s; |
1733 |
fm_add_sig_stat (&log); |
fm_add_sig_stat (&log); |
1758 |
|
|
1759 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1760 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1761 |
|
|
1762 |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
1763 |
if (err) |
if (err) |
1791 |
/* Export the selected keys from the File Manager to a file. */ |
/* Export the selected keys from the File Manager to a file. */ |
1792 |
int |
int |
1793 |
fm_export (fm_state_t c) |
fm_export (fm_state_t c) |
1794 |
{ |
{ |
|
int rc = 0; |
|
1795 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1796 |
gpgme_error_t err; |
gpgme_error_t err; |
1797 |
gpgme_key_t *rset = c->recp; |
gpgme_key_t *rset = c->recp; |
1798 |
file_data_t keydata = NULL; |
file_data_t keydata = NULL; |
1799 |
const char *name; |
const char *name; |
1800 |
char *p = NULL, *patt = NULL; |
char *p = NULL, *patt = NULL; |
1801 |
|
int rc = 0; |
1802 |
|
|
1803 |
if (!rset || !rset[0]) { |
if (!rset || !rset[0]) { |
1804 |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
msg_box (c->dlg, _("No key was selected for export."), |
1805 |
|
_("Export"), MB_ERR); |
1806 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1807 |
goto leave; |
goto leave; |
1808 |
} |
} |
1813 |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
1814 |
NULL, p? p : NULL); |
NULL, p? p : NULL); |
1815 |
if (!name) |
if (!name) |
1816 |
name = "keys.gpg"; |
name = reg_prefs.default_ext? "keys.pgp" : "keys.gpg"; |
1817 |
|
|
1818 |
patt = gpg_keylist_to_pattern (rset, c->n_recp); |
patt = gpg_keylist_to_pattern (rset, c->n_recp); |
1819 |
|
|
1834 |
leave: |
leave: |
1835 |
if (keydata) |
if (keydata) |
1836 |
gpg_file_data_release (keydata); |
gpg_file_data_release (keydata); |
1837 |
if (patt) |
safe_free (patt); |
|
free (patt); |
|
1838 |
free_if_alloc (p); |
free_if_alloc (p); |
1839 |
return rc; |
return rc; |
1840 |
} |
} |
1891 |
|
|
1892 |
case PGP_SIG: |
case PGP_SIG: |
1893 |
case PGP_CLEARSIG: |
case PGP_CLEARSIG: |
|
file_verify_use_event (); |
|
1894 |
if (type == PGP_SIG) |
if (type == PGP_SIG) |
1895 |
detached = 1; |
detached = 1; |
1896 |
fm_verify (ctx, detached, fn); |
fm_verify (ctx, detached, fn); |
1927 |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
1928 |
{ |
{ |
1929 |
PK_FILE_LIST list=NULL; |
PK_FILE_LIST list=NULL; |
1930 |
const char *outfile; |
const char *outfile, *ext; |
1931 |
char *out_enc; |
char *out_enc; |
1932 |
int nitems = listview_count_items (lv, 0); |
int nitems; |
1933 |
int i, idx = -1; |
int i, idx = -1; |
1934 |
int rc; |
int rc; |
1935 |
|
|
1936 |
|
nitems = listview_count_items (lv, 0); |
1937 |
if (!nitems) { |
if (!nitems) { |
1938 |
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"), |
1939 |
_("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
1946 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
1947 |
|
|
1948 |
for (i=0; i < nitems; i++) { |
for (i=0; i < nitems; i++) { |
1949 |
char name[300]; |
char name[MAX_PATH+32]; |
1950 |
|
|
1951 |
if (!listview_get_item_state (lv, i)) |
if (!listview_get_item_state (lv, i)) |
1952 |
continue; |
continue; |
1953 |
if (idx == -1) |
if (idx == -1) |
1954 |
idx = i; |
idx = i; |
1955 |
listview_get_item_text (lv, i, 1, name, sizeof (name)-1); |
listview_get_item_text (lv, i, 1, name, DIM (name)-1); |
1956 |
pk_list_add (&list, name); |
pk_list_add (&list, name); |
1957 |
} |
} |
1958 |
|
|
1964 |
if (rc) |
if (rc) |
1965 |
return rc; |
return rc; |
1966 |
|
|
1967 |
out_enc = make_filename (NULL, outfile, "gpg"); |
ext = file_get_extension (ctx->ctx, ctx->sigmode)+1; |
1968 |
|
out_enc = make_filename (NULL, outfile, ext); |
1969 |
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); |
1970 |
free_if_alloc (out_enc); |
free_if_alloc (out_enc); |
1971 |
|
|
1972 |
for (i=0; i < nitems; i++) { |
for (i=nitems; i > -1; i--) { |
1973 |
if (i != idx && listview_get_item_state (lv, i)) |
if (i != idx && listview_get_item_state (lv, i)) |
1974 |
listview_del_item (lv, i); |
listview_del_item (lv, i); |
1975 |
} |
} |
1979 |
|
|
1980 |
int |
int |
1981 |
fm_encrypt_directory (fm_state_t c, const char *name) |
fm_encrypt_directory (fm_state_t c, const char *name) |
1982 |
{ |
{ |
|
PK_FILE_LIST list = NULL; |
|
1983 |
WIN32_FIND_DATA findbuf; |
WIN32_FIND_DATA findbuf; |
1984 |
HANDLE hd; |
HANDLE hd; |
1985 |
const char * s; |
PK_FILE_LIST list = NULL; |
1986 |
char * patt = NULL, * p; |
const char *s; |
1987 |
|
char *patt = NULL, *p; |
1988 |
int rc = 0; |
int rc = 0; |
1989 |
|
|
1990 |
if (!is_directory (name)) |
if (!is_directory (name)) |
1999 |
free_if_alloc (patt); |
free_if_alloc (patt); |
2000 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
2001 |
} |
} |
2002 |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
if (strcmp (findbuf.cFileName, ".") && strcmp (findbuf.cFileName, "..")) { |
2003 |
p = make_filename( name, findbuf.cFileName, NULL ); |
p = make_filename (name, findbuf.cFileName, NULL); |
2004 |
pk_list_add( &list, p ); |
pk_list_add (&list, p); |
2005 |
free_if_alloc( p ); |
free_if_alloc (p); |
2006 |
} |
} |
2007 |
while( FindNextFile( hd, &findbuf ) ) { |
/* XXX: support to scan sub directories also. */ |
2008 |
if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) { |
while (FindNextFile (hd, &findbuf)) { |
2009 |
p = make_filename( name, findbuf.cFileName, NULL ); |
if (strcmp (findbuf.cFileName, ".") && strcmp (findbuf.cFileName, "..")) { |
2010 |
pk_list_add( &list, p ); |
p = make_filename (name, findbuf.cFileName, NULL); |
2011 |
free_if_alloc( p ); |
pk_list_add (&list, p); |
2012 |
|
free_if_alloc (p); |
2013 |
} |
} |
2014 |
} |
} |
2015 |
s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"), |
s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"), |
2016 |
NULL, default_dirname (name)); |
NULL, default_dirname (name)); |
2017 |
if( !s ) { |
if (!s) { |
2018 |
msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR ); |
msg_box (c->dlg, _("Invalid archive name. Exit."), |
2019 |
|
_("Encrypt Directory"), MB_ERR); |
2020 |
rc = -1; |
rc = -1; |
2021 |
goto leave; |
goto leave; |
2022 |
} |
} |
2023 |
|
|
2024 |
rc = pk_archiv_create( list, s ); |
rc = pk_archiv_create (list, s); |
2025 |
if( rc ) |
if (rc) |
2026 |
msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR ); |
msg_box (c->dlg, _("Could not create zip archive."), |
2027 |
|
_("Encrypt Directory"), MB_ERR); |
2028 |
else { |
else { |
2029 |
fm_encrypt( c, s, 0 ); |
fm_encrypt (c, s, 0); |
2030 |
remove( s ); |
DeleteFile (s); |
2031 |
} |
} |
2032 |
leave: |
leave: |
2033 |
FindClose (hd); |
FindClose (hd); |
2034 |
pk_list_free( list ); |
pk_list_free (list); |
2035 |
free_if_alloc( patt ); |
free_if_alloc (patt); |
2036 |
return rc; |
return rc; |
2037 |
} |
} |
2038 |
|
|
2040 |
static int CALLBACK |
static int CALLBACK |
2041 |
fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) |
2042 |
{ |
{ |
2043 |
const char *a = 0; |
fm_model_t a, b; |
2044 |
const char *b = 0; |
int cmpres = 0; |
2045 |
|
|
2046 |
|
a = (fm_model_t)first; |
2047 |
|
b = (fm_model_t)second; |
2048 |
|
if (!a || !b) |
2049 |
|
return 0; |
2050 |
|
|
2051 |
switch( (int)sortby ) { |
switch ((int)sortby) { |
2052 |
case FM_SORT_STAT: |
case FM_COL_STAT: |
2053 |
|
cmpres = stricmp (a->status, b->status); |
2054 |
break; |
break; |
2055 |
case FM_SORT_NAME: |
|
2056 |
|
case FM_COL_NAME: |
2057 |
|
cmpres = stricmp (a->name, b->name); |
2058 |
break; |
break; |
2059 |
case FM_SORT_OP: |
|
2060 |
|
case FM_COL_OP: |
2061 |
|
if (a->op && b->op) |
2062 |
|
cmpres = stricmp (a->op, b->op); |
2063 |
break; |
break; |
2064 |
} |
} |
2065 |
return stricmp (a, b); |
return cmpres; |
2066 |
} |
} |
2067 |
|
|
2068 |
|
|
2069 |
/* Sort the list items from @lv with the mode given by @sortby. */ |
/* Sort the list items from @lv with the mode given by @sortby. */ |
2070 |
int |
int |
2071 |
fm_sort (listview_ctrl_t lv, int sortby) |
fm_sort (listview_ctrl_t lv, int sortby) |
2072 |
{ |
{ |
2073 |
return listview_sort_items( lv, sortby, fm_cmp_cb ); |
return ListView_SortItems (lv->ctrl, fm_cmp_cb, (LPARAM)sortby); |
2074 |
} |
} |
2075 |
|
|
2076 |
|
|
2095 |
int |
int |
2096 |
fm_send_file (listview_ctrl_t lv) |
fm_send_file (listview_ctrl_t lv) |
2097 |
{ |
{ |
2098 |
char buf[128]; |
char name[MAX_PATH+1]; |
2099 |
int rc; |
int rc; |
2100 |
|
|
2101 |
rc = listview_get_item_text (lv, -1, 1, buf, sizeof (buf)-1); |
rc = listview_get_item_text (lv, -1, FM_COL_NAME, name, DIM (name)-1); |
2102 |
if (rc != -1) |
if (rc != -1) |
2103 |
mapi_send_ascfile (buf); |
mapi_send_ascfile (name); |
2104 |
return 0; |
return 0; |
2105 |
} |
} |