149 |
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 |
} |
} |
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 |
|
|
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 |
|
|
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); |
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 |
safe_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 |
safe_free (path); |
free_if_alloc (path); |
610 |
return rc; |
return rc; |
611 |
} |
} |
612 |
|
|
641 |
check = 1; |
check = 1; |
642 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
643 |
gpg_iobuf_close (fp); |
gpg_iobuf_close (fp); |
644 |
remove (tmpfile); |
DeleteFile (tmpfile); |
645 |
} |
} |
646 |
/* XXX: implement it for real files */ |
/* XXX: implement it for real files */ |
647 |
safe_free (pkt); |
safe_free (pkt); |
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 |
|
|
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; |
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) |
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 |
} |
} |
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; |
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; |
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 |
} |
} |
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 |
} |
} |
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 (stristr (name, ".sig") || |
if (is_openpgp_ext (name)) { |
|
stristr (name, ".asc") || |
|
|
stristr (name, ".gpg") || |
|
|
stristr (name, ".pgp")) { |
|
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) |
1698 |
int rc = 0; |
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 |
} |
} |
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: |