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> |
599 |
else { |
else { |
600 |
char *p = make_filename (path, name, NULL); |
char *p = make_filename (path, name, NULL); |
601 |
rc = add_single_file (lv, p); |
rc = add_single_file (lv, p); |
602 |
free (p); |
safe_free (p); |
603 |
} |
} |
604 |
n++; |
n++; |
605 |
} |
} |
606 |
if (n == 1) /* single file selected. */ |
if (n == 1) /* single file selected. */ |
607 |
rc = add_single_file (lv, path); |
rc = add_single_file (lv, path); |
608 |
if (path) |
safe_free (path); |
|
free (path); |
|
609 |
return rc; |
return rc; |
610 |
} |
} |
611 |
|
|
612 |
|
|
613 |
int |
int |
614 |
fm_assume_onepass_sig (const char * fname) |
fm_assume_onepass_sig (const char * fname) |
615 |
{ |
{ |
|
gpgme_data_t dat; |
|
616 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
617 |
gpg_iobuf_t fp; |
gpg_iobuf_t fp; |
618 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
gpgme_data_t dat; |
619 |
|
PACKET *pkt; |
620 |
|
char tmpfile[MAX_PATH+1]; |
621 |
int check = 0; |
int check = 0; |
622 |
|
|
623 |
|
pkt = (PACKET *)calloc (1, sizeof *pkt); |
624 |
if (!fname) { |
if (!fname) { |
625 |
|
get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp"); |
626 |
gpg_data_new_from_clipboard (&dat, 0); |
gpg_data_new_from_clipboard (&dat, 0); |
627 |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
gpg_data_release_and_set_file (dat, tmpfile); |
628 |
|
|
629 |
fp = gpg_iobuf_open ("gpgme.tmp"); |
fp = gpg_iobuf_open (tmpfile); |
630 |
if (!fp) |
if (!fp) |
631 |
return 0; |
return 0; |
632 |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
639 |
&& pkt->pkttype == PKT_COMPRESSED) |
&& pkt->pkttype == PKT_COMPRESSED) |
640 |
check = 1; |
check = 1; |
641 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
|
safe_free (pkt); |
|
642 |
gpg_iobuf_close (fp); |
gpg_iobuf_close (fp); |
643 |
remove ("gpgme.tmp"); |
remove (tmpfile); |
644 |
} |
} |
645 |
/* XXX: implement it for real files */ |
/* XXX: implement it for real files */ |
646 |
|
safe_free (pkt); |
647 |
return check; |
return check; |
648 |
} |
} |
649 |
|
|
656 |
items = listview_count_items (lv, 0); |
items = listview_count_items (lv, 0); |
657 |
if (!items) |
if (!items) |
658 |
return -1; |
return -1; |
659 |
else if (items == 1) |
else if (items == 1) { |
|
{ |
|
660 |
listview_select_one (lv, 0); |
listview_select_one (lv, 0); |
661 |
return 0; |
return 0; |
662 |
} |
} |
663 |
else if (items > 1) |
else if (items > 1) { |
|
{ |
|
664 |
i = listview_get_curr_pos (lv); |
i = listview_get_curr_pos (lv); |
665 |
if (i == -1) |
if (i == -1) { |
666 |
{ |
msg_box (lv->ctrl, _("Please select a file."), |
667 |
msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
668 |
return -1; |
return -1; |
669 |
} |
} |
670 |
return i; |
return i; |
671 |
} |
} |
672 |
|
|
673 |
return -1; |
return -1; |
674 |
} /* fm_get_current_pos */ |
} |
675 |
|
|
676 |
|
|
677 |
static int |
static int |
678 |
fm_check_detached_sig( listview_ctrl_t lv, int pos ) |
fm_check_detached_sig (listview_ctrl_t lv, int pos) |
679 |
{ |
{ |
680 |
char type[128]; |
char type[128]; |
681 |
|
|
682 |
listview_get_item_text( lv, pos, 0, type, 127 ); |
listview_get_item_text (lv, pos, 0, type, sizeof (type)-1); |
683 |
return !strcmp( type, "SIGNED-DETACH" )? 1 : 0; |
return !strcmp (type, "SIGNED-DETACH")? 1 : 0; |
684 |
} /* fm_check_detached_sig */ |
} |
685 |
|
|
686 |
|
|
687 |
int |
int |
738 |
} |
} |
739 |
|
|
740 |
return rc; |
return rc; |
741 |
} /* fm_check_file_type */ |
} |
742 |
|
|
743 |
|
|
744 |
/* Set the file status of the given command @fm_cmd. |
/* Set the file status of the given command @fm_cmd. |
809 |
if (!cnt) |
if (!cnt) |
810 |
return 0; |
return 0; |
811 |
n = -1; |
n = -1; |
812 |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
813 |
_("\"%s\" does not seems to be a text file.\n" |
_("\"%s\" does not seems to be a text file.\n" |
814 |
"Do you really want to clearsign it?"), name); |
"Do you really want to clearsign it?"), name); |
815 |
if (i == IDYES) |
if (i == IDYES) |
817 |
return n; |
return n; |
818 |
} |
} |
819 |
|
|
820 |
|
|
821 |
int |
int |
822 |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
823 |
{ |
{ |
1211 |
gpgme_key_t key=NULL; |
gpgme_key_t key=NULL; |
1212 |
gpgme_signature_t sig=sigres->signatures; |
gpgme_signature_t sig=sigres->signatures; |
1213 |
const char *s, *keyid; |
const char *s, *keyid; |
1214 |
int sigok = 0; |
char *uid; |
|
int type; |
|
1215 |
char buf[384]; |
char buf[384]; |
1216 |
|
int sigok = 0; |
1217 |
|
|
1218 |
sig = sigres->signatures; |
sig = sigres->signatures; |
1219 |
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
1220 |
s = sigok? _("Good signature") : _("BAD signature"); |
s = sigok? _("Good signature") : _("BAD signature"); |
|
type = sigok? MB_OK: MB_ICONWARNING|MB_OK; |
|
1221 |
keyid = sig->fpr; |
keyid = sig->fpr; |
1222 |
if (!keyid) |
if (!keyid) |
1223 |
return; |
return; |
1224 |
|
|
1225 |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24; |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24; |
1226 |
get_pubkey (sig->fpr, &key); |
get_pubkey (sig->fpr, &key); |
1227 |
|
|
1228 |
|
if (key) |
1229 |
|
uid = utf8_to_native (key->uids->uid); |
1230 |
|
else |
1231 |
|
uid = strdup (_("user ID not found")); |
1232 |
|
|
1233 |
_snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n" |
_snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n" |
1234 |
"%s from \"%s\""), |
"%s from \"%s\""), |
1235 |
strtimestamp (sig->timestamp), |
strtimestamp (sig->timestamp), |
1236 |
get_key_pubalgo (sig->pubkey_algo), |
get_key_pubalgo (sig->pubkey_algo), |
1237 |
keyid, s, key? key->uids->uid : _("user ID not found")); |
keyid, s, uid); |
1238 |
msg_box (NULL, buf, _("Decrypt Verify"), type); |
msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK); |
1239 |
|
safe_free (uid); |
1240 |
} |
} |
1241 |
|
|
1242 |
|
|
1263 |
/* If the decrypt result contains the original file name, |
/* If the decrypt result contains the original file name, |
1264 |
we use it instead of the artificial "output - .gpg" string. */ |
we use it instead of the artificial "output - .gpg" string. */ |
1265 |
static int |
static int |
1266 |
restore_original_name (const char *output, const char *plaintext_filename) |
restore_original_name (const char *output, const char *file_name) |
1267 |
{ |
{ |
1268 |
char *dir; |
char *dir; |
1269 |
char *orig; |
char *orig; |
1271 |
|
|
1272 |
dir = strrchr (output, '\\'); |
dir = strrchr (output, '\\'); |
1273 |
if (!dir) |
if (!dir) |
1274 |
orig = strdup (plaintext_filename); |
orig = strdup (file_name); |
1275 |
else { |
else { |
1276 |
orig = (char*)calloc (1, strlen (plaintext_filename)+ 1 + |
orig = (char*)calloc (1, strlen (file_name)+ 1 + |
1277 |
strlen (output)+1); |
strlen (output)+1); |
1278 |
if (!orig) |
if (!orig) |
1279 |
BUG (0); |
BUG (0); |
1280 |
memcpy (orig, output, (dir-output)+1); |
memcpy (orig, output, (dir-output)+1); |
1281 |
strcat (orig, plaintext_filename); |
strcat (orig, file_name); |
1282 |
} |
} |
1283 |
if (overwrite_file (orig)) { |
if (overwrite_file (orig)) { |
1284 |
DeleteFile (orig); |
DeleteFile (orig); |
1565 |
else |
else |
1566 |
title = _("Selected Output File"); |
title = _("Selected Output File"); |
1567 |
|
|
1568 |
if (strstr (name, ".sig") |
if (stristr (name, ".sig") || |
1569 |
|| strstr (name, ".asc") |
stristr (name, ".asc") || |
1570 |
|| strstr (name, ".gpg")) { |
stristr (name, ".gpg")) { |
1571 |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
1572 |
fname[strlen (fname) - 4] = '\0'; |
fname[strlen (fname) - 4] = '\0'; |
1573 |
if (file_exist_check (fname) == 0 && detached) |
if (file_exist_check (fname) == 0 && detached) |
1597 |
if (detached) |
if (detached) |
1598 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
c->sigmode = GPGME_SIG_MODE_DETACH; |
1599 |
else { |
else { |
1600 |
if (strstr (name, ".asc")) |
if (stristr (name, ".asc")) |
1601 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
1602 |
else |
else |
1603 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
1619 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1620 |
int rc = 0; |
int rc = 0; |
1621 |
|
|
1622 |
if (strstr (name, ".sig")) |
if (stristr (name, ".sig")) |
1623 |
detached = 1; |
detached = 1; |
1624 |
|
|
1625 |
if (get_output_file (c, name, detached)) |
if (get_output_file (c, name, detached)) |
1713 |
/* Export the selected keys from the File Manager to a file. */ |
/* Export the selected keys from the File Manager to a file. */ |
1714 |
int |
int |
1715 |
fm_export (fm_state_t c) |
fm_export (fm_state_t c) |
1716 |
{ |
{ |
|
int rc = 0; |
|
1717 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1718 |
gpgme_error_t err; |
gpgme_error_t err; |
1719 |
gpgme_key_t *rset = c->recp; |
gpgme_key_t *rset = c->recp; |
1720 |
file_data_t keydata = NULL; |
file_data_t keydata = NULL; |
1721 |
const char *name; |
const char *name; |
1722 |
char *p = NULL, *patt = NULL; |
char *p = NULL, *patt = NULL; |
1723 |
|
int rc = 0; |
1724 |
|
|
1725 |
if (!rset || !rset[0]) { |
if (!rset || !rset[0]) { |
1726 |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
1755 |
leave: |
leave: |
1756 |
if (keydata) |
if (keydata) |
1757 |
gpg_file_data_release (keydata); |
gpg_file_data_release (keydata); |
1758 |
if (patt) |
safe_free (patt); |
|
free (patt); |
|
1759 |
free_if_alloc (p); |
free_if_alloc (p); |
1760 |
return rc; |
return rc; |
1761 |
} |
} |
1848 |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
1849 |
{ |
{ |
1850 |
PK_FILE_LIST list=NULL; |
PK_FILE_LIST list=NULL; |
1851 |
const char *outfile; |
const char *outfile, *ext; |
1852 |
char *out_enc; |
char *out_enc; |
1853 |
int nitems = listview_count_items (lv, 0); |
int nitems; |
1854 |
int i, idx = -1; |
int i, idx = -1; |
1855 |
int rc; |
int rc; |
1856 |
|
|
1857 |
|
nitems = listview_count_items (lv, 0); |
1858 |
if (!nitems) { |
if (!nitems) { |
1859 |
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"), |
1860 |
_("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
1884 |
if (rc) |
if (rc) |
1885 |
return rc; |
return rc; |
1886 |
|
|
1887 |
out_enc = make_filename (NULL, outfile, "gpg"); |
ext = file_get_extension (ctx->ctx, ctx->sigmode)+1; |
1888 |
|
out_enc = make_filename (NULL, outfile, ext); |
1889 |
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); |
1890 |
free_if_alloc (out_enc); |
free_if_alloc (out_enc); |
1891 |
|
|
1960 |
const char *a = 0; |
const char *a = 0; |
1961 |
const char *b = 0; |
const char *b = 0; |
1962 |
|
|
1963 |
switch( (int)sortby ) { |
switch ((int)sortby) { |
1964 |
case FM_SORT_STAT: |
case FM_SORT_STAT: |
1965 |
break; |
break; |
1966 |
case FM_SORT_NAME: |
case FM_SORT_NAME: |
1976 |
int |
int |
1977 |
fm_sort (listview_ctrl_t lv, int sortby) |
fm_sort (listview_ctrl_t lv, int sortby) |
1978 |
{ |
{ |
1979 |
return listview_sort_items( lv, sortby, fm_cmp_cb ); |
return listview_sort_items (lv, sortby, fm_cmp_cb); |
1980 |
} |
} |
1981 |
|
|
1982 |
|
|