40 |
#include "wptW32API.h" |
#include "wptW32API.h" |
41 |
#include "wptVersion.h" |
#include "wptVersion.h" |
42 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
43 |
#include "wptGPGZIP.h" |
#include "wptZIP.h" |
44 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
45 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
46 |
#include "wptImport.h" |
#include "wptImport.h" |
47 |
|
|
48 |
#include "openpgp.h" |
#include "openpgp.h" |
49 |
|
|
50 |
void progress_cleanup (progress_filter_s *pfx); |
#define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT)) |
51 |
|
#define op_end() SetCursor (LoadCursor (NULL, IDC_ARROW)) |
52 |
|
|
53 |
|
void progress_cleanup (progress_filter_s *pfx); |
54 |
|
BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, |
55 |
|
WPARAM wparam, LPARAM lparam); |
56 |
char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n); |
char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n); |
57 |
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, |
58 |
int prev_was_bad, int fd); |
int prev_was_bad, int fd); |
59 |
|
|
60 |
/*-- wptFileVerifyDlg.cpp --*/ |
/*-- wptFileVerifyDlg.cpp --*/ |
61 |
int file_verify_add_state (file_sig_ctx_t c); |
void file_verify_add_state (file_sig_ctx_t c); |
62 |
void file_verify_use_event (void); |
void file_verify_use_event (void); |
63 |
void file_verify_wait (void); |
void file_verify_wait (void); |
64 |
|
|
67 |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
68 |
|
|
69 |
|
|
70 |
char * |
/* Check if the drive given by @fname is a floppy disc. |
71 |
fm_quote_file (const char * name) |
Return value: 1 for success. */ |
72 |
|
static int |
73 |
|
is_floppy_disc (const char * fname) |
74 |
{ |
{ |
75 |
char * p; |
char drv[32] = {0}; |
76 |
size_t len = strlen (name) + 8; |
int i=0; |
77 |
|
|
78 |
if (*name == '"') |
if (!strstr (fname, ":\\")) |
79 |
return m_strdup (name); /* avoid double quotes */ |
return 0; |
|
p = new char[len + 1]; |
|
|
if (!p) |
|
|
BUG (0); |
|
|
_snprintf (p, len, "\"%s\"", name); |
|
80 |
|
|
81 |
return p; |
while (fname && *fname && *fname != '\\') |
82 |
} /* fm_quote_file */ |
drv[i++] = *fname++; |
83 |
|
drv[i++] = '\\'; |
84 |
|
drv[i++] = '\0'; |
85 |
|
i = GetDriveType (drv); |
86 |
|
if (i == DRIVE_REMOVABLE) |
87 |
|
return -1; |
88 |
|
return 0; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
/* Ask the user to overwrite file @fname. |
93 |
|
Return value: 0 for cancel. */ |
94 |
int |
int |
95 |
overwrite_file (const char * fname) |
overwrite_file (const char *fname) |
96 |
{ |
{ |
97 |
int id; |
int id; |
98 |
|
|
102 |
_("\"%s\" already exists.\n" |
_("\"%s\" already exists.\n" |
103 |
"Replace existing file?"), fname); |
"Replace existing file?"), fname); |
104 |
return id == IDNO ? 0 : -1; |
return id == IDNO ? 0 : -1; |
105 |
} /* overwrite_file */ |
} |
106 |
|
|
107 |
|
|
108 |
|
/* Removes 'critical' attributes from the file @fname. |
109 |
|
If @force is 1, the user is not asked for permission. */ |
110 |
static void |
static void |
111 |
remove_crit_file_attrs (const char * fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
112 |
{ |
{ |
113 |
u32 f_attr; |
u32 f_attr; |
114 |
int id; |
int id; |
126 |
if (id == IDYES) |
if (id == IDYES) |
127 |
SetFileAttributes (fname, FILE_ATTRIBUTE_NORMAL); |
SetFileAttributes (fname, FILE_ATTRIBUTE_NORMAL); |
128 |
} |
} |
129 |
} /* remove_crit_file_attrs */ |
} |
130 |
|
|
131 |
|
|
132 |
static int inline |
static int inline |
133 |
is_directory (const char * fname) |
is_directory (const char *fname) |
134 |
{ |
{ |
135 |
return GetFileAttributes (fname) & FILE_ATTRIBUTE_DIRECTORY? 1 : 0; |
return GetFileAttributes (fname) & FILE_ATTRIBUTE_DIRECTORY? 1 : 0; |
136 |
} /* is_directory */ |
} |
137 |
|
|
138 |
|
|
139 |
static int inline |
static int inline |
140 |
is_openpgp_ext (const char * name) |
is_openpgp_ext (const char *name) |
141 |
{ |
{ |
142 |
if (strstr (name, ".gpg") || strstr (name, ".asc") |
if (strstr (name, ".gpg") || strstr (name, ".asc") |
143 |
|| strstr (name, ".sig") || strstr (name, ".pgp")) |
|| strstr (name, ".sig") || strstr (name, ".pgp")) |
191 |
if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH) |
if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH) |
192 |
return ".sig"; |
return ".sig"; |
193 |
return ".gpg"; |
return ".gpg"; |
194 |
} /* file_get_extension */ |
} |
195 |
|
|
196 |
|
|
197 |
|
char* |
198 |
|
fm_quote_file (const char * name) |
199 |
|
{ |
200 |
|
char * p; |
201 |
|
size_t len = strlen (name) + 8; |
202 |
|
|
203 |
|
if (*name == '"') |
204 |
|
return m_strdup (name); /* avoid double quotes */ |
205 |
|
p = new char[len + 1]; |
206 |
|
if (!p) |
207 |
|
BUG (0); |
208 |
|
_snprintf (p, len, "\"%s\"", name); |
209 |
|
|
210 |
|
return p; |
211 |
|
} /* fm_quote_file */ |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
/* Check the armor type of the file @fname and return |
216 |
|
a string representation of it. */ |
217 |
|
static const char * |
218 |
|
fm_check_armor_type (const char *fname, int *r_type) |
219 |
|
{ |
220 |
|
FILE * fp; |
221 |
|
char header[768], * p; |
222 |
|
|
223 |
|
if (r_type) |
224 |
|
*r_type = PGP_NONE; |
225 |
|
fp = fopen (fname, "rb"); |
226 |
|
if (!fp) |
227 |
|
return "UNKNOWN"; |
228 |
|
p = fgets (header, sizeof (header) - 1, fp); |
229 |
|
fclose (fp); |
230 |
|
if (!p) |
231 |
|
return "UNKNOWN"; |
232 |
|
|
233 |
|
if (strncmp (header, "-----", 5)) |
234 |
|
goto leave; |
235 |
|
if (strstr( header, "BEGIN PGP PUBLIC KEY" )) { |
236 |
|
if (r_type) *r_type = PGP_PUBKEY; |
237 |
|
return "PUBKEY"; |
238 |
|
} |
239 |
|
else if (strstr (header, "BEGIN PGP PRIVATE KEY") || |
240 |
|
strstr (header, "BEGIN PGP SECRET KEY")) { |
241 |
|
if (r_type) *r_type = PGP_SECKEY; |
242 |
|
return "SECKEY"; |
243 |
|
} |
244 |
|
else if (strstr (header, "BEGIN PGP MESSAGE")) { |
245 |
|
if (r_type) *r_type = PGP_MESSAGE; |
246 |
|
return "ENCRYPTED"; |
247 |
|
} |
248 |
|
else if (strstr( header, "BEGIN PGP SIGNED MESSAGE")) { |
249 |
|
if (r_type) *r_type = PGP_CLEARSIG; |
250 |
|
return "SIGNED-CLEAR"; |
251 |
|
} |
252 |
|
else if (strstr(header, "BEGIN PGP SIGNATURE")) { |
253 |
|
if (r_type) *r_type = PGP_SIG; |
254 |
|
return "SIGNED-DETACH"; |
255 |
|
} |
256 |
|
|
257 |
|
leave: |
258 |
|
return "UNKNOWN"; |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
/* Extract file type from @fname. If @r_type is valid, |
263 |
|
it contains the PGP type on success. */ |
264 |
|
static const char * |
265 |
|
fm_get_file_type (const char *fname, int *r_type) |
266 |
|
{ |
267 |
|
gpg_iobuf_t inp; |
268 |
|
armor_filter_context_t afx; |
269 |
|
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
270 |
|
int i = 0, rc = 0; |
271 |
|
const char *s = NULL; |
272 |
|
|
273 |
|
if (r_type) |
274 |
|
*r_type = PGP_NONE; |
275 |
|
if (!fname) { |
276 |
|
safe_free (pkt); |
277 |
|
return NULL; |
278 |
|
} |
279 |
|
|
280 |
|
if (is_floppy_disc (fname)) |
281 |
|
return fm_check_armor_type (fname, r_type); |
282 |
|
|
283 |
|
inp = gpg_iobuf_open (fname); |
284 |
|
if (!inp) { |
285 |
|
const char *s = winpt_strerror (WPTERR_FILE_OPEN); |
286 |
|
log_box( _("File Manager"), MB_ERR, "\"%s\": %s", fname, s ); |
287 |
|
safe_free( pkt ); |
288 |
|
return NULL; |
289 |
|
} |
290 |
|
gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */ |
291 |
|
if (gpg_iobuf_get_filelength (inp) > 32000000 /* 32MB */ |
292 |
|
&& !is_openpgp_ext (fname)) { |
293 |
|
gpg_iobuf_close (inp); |
294 |
|
return "UNKNOWN"; |
295 |
|
} |
296 |
|
|
297 |
|
if (gpg_use_armor_filter(inp)) { |
298 |
|
memset (&afx, 0, sizeof (afx)); |
299 |
|
gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx); |
300 |
|
} |
301 |
|
|
302 |
|
gpg_init_packet (pkt); |
303 |
|
while (!(rc = gpg_parse_packet (inp, pkt))) { |
304 |
|
switch (pkt->pkttype) { |
305 |
|
case PKT_PUBKEY_ENC: |
306 |
|
s = "ENCRYPTED";rc = -2; |
307 |
|
if (r_type) *r_type = PGP_MESSAGE; |
308 |
|
break; |
309 |
|
case PKT_SYMKEY_ENC: |
310 |
|
case PKT_ENCRYPTED: |
311 |
|
s = "SYMKEYENC";rc = -2; |
312 |
|
if (r_type) *r_type = PGP_MESSAGE; |
313 |
|
break; |
314 |
|
case PKT_SIGNATURE: |
315 |
|
case PKT_ONEPASS_SIG: |
316 |
|
s = "SIGNED"; rc = -2; |
317 |
|
if (r_type) *r_type = PGP_SIG; |
318 |
|
break; |
319 |
|
case PKT_PUBLIC_KEY: |
320 |
|
s = "PUBKEY"; rc = -2; |
321 |
|
if (r_type) *r_type = PGP_PUBKEY; |
322 |
|
break; |
323 |
|
case PKT_SECRET_KEY: |
324 |
|
s = "SECKEY"; rc = -2; |
325 |
|
if (r_type) *r_type = PGP_SECKEY; |
326 |
|
break; |
327 |
|
} |
328 |
|
gpg_free_packet (pkt); |
329 |
|
gpg_init_packet (pkt); |
330 |
|
if (rc == -2) |
331 |
|
break; /* found */ |
332 |
|
} |
333 |
|
safe_free (pkt); |
334 |
|
gpg_iobuf_close (inp); |
335 |
|
if (!s) |
336 |
|
s = fm_check_armor_type (fname, r_type); |
337 |
|
if (!s) |
338 |
|
s = "UNKNOWN"; |
339 |
|
if (!strcmp (s, "SIGNED") |
340 |
|
&& strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) { |
341 |
|
if (r_type) *r_type = PGP_SIG; |
342 |
|
s = "SIGNED-DETACH"; |
343 |
|
} |
344 |
|
return s; |
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
int |
int |
349 |
fm_build( listview_ctrl_t *lv, HWND ctrl ) |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
350 |
{ |
{ |
351 |
int i, rc = 0; |
int i, rc = 0; |
352 |
listview_ctrl_t c; |
listview_ctrl_t c; |
436 |
|
|
437 |
|
|
438 |
static int |
static int |
439 |
fm_set_ftype (listview_ctrl_t lv, const char * name) |
fm_set_ftype (listview_ctrl_t lv, const char *name) |
440 |
{ |
{ |
441 |
const char *type; |
const char *type; |
442 |
int rc; |
int rc; |
444 |
rc = fm_check_for_entry (lv, name); |
rc = fm_check_for_entry (lv, name); |
445 |
if (rc) |
if (rc) |
446 |
return 0; |
return 0; |
447 |
type = fm_get_file_type (name); |
type = fm_get_file_type (name, NULL); |
448 |
if (!type || !strcmp (type, "UNKNOWN")) |
if (!type || !strcmp (type, "UNKNOWN")) |
449 |
type = gnupg_check_file_ext (name); |
type = gnupg_check_file_ext (name, NULL); |
450 |
rc = listview_add_item (lv, " "); |
rc = listview_add_item (lv, " "); |
451 |
if (rc) |
if (rc) |
452 |
return -1; |
return -1; |
510 |
{ |
{ |
511 |
OPENFILENAME open; |
OPENFILENAME open; |
512 |
const char *type; |
const char *type; |
513 |
char file[1024] = ""; |
char file[512] = ""; |
514 |
int rc; |
int rc; |
515 |
|
|
516 |
memset( &open, 0, sizeof (open) ); |
/* XXX: support to add multiple files. */ |
517 |
|
memset (&open, 0, sizeof (open)); |
518 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
519 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
520 |
open.lpstrTitle = _("File Open"); |
open.lpstrTitle = _("File Open"); |
525 |
open.Flags = 0; |
open.Flags = 0; |
526 |
|
|
527 |
if (GetOpenFileName (&open)) { |
if (GetOpenFileName (&open)) { |
528 |
type = fm_get_file_type (open.lpstrFile); |
type = fm_get_file_type (open.lpstrFile, NULL); |
529 |
if (!type) |
if (!type) |
530 |
return WPTERR_FILE_OPEN; |
return WPTERR_FILE_OPEN; |
531 |
if (!strcmp (type, "UNKNOWN")) |
if (!strcmp (type, "UNKNOWN")) |
532 |
type = gnupg_check_file_ext (open.lpstrFile); |
type = gnupg_check_file_ext (open.lpstrFile, NULL); |
533 |
rc = listview_add_item (lv, ""); |
rc = listview_add_item (lv, ""); |
534 |
if( !rc ) { |
if (!rc) { |
535 |
listview_add_sub_item (lv, 0, 0, type); |
listview_add_sub_item (lv, 0, 0, type); |
536 |
listview_add_sub_item (lv, 0, 1, open.lpstrFile); |
listview_add_sub_item (lv, 0, 1, open.lpstrFile); |
537 |
} |
} |
541 |
} |
} |
542 |
|
|
543 |
|
|
|
/* Check the armor type of the file @fname and return |
|
|
a string representation of it. */ |
|
|
static const char * |
|
|
fm_check_armor_type (const char *fname) |
|
|
{ |
|
|
FILE * fp; |
|
|
char header[768], * p; |
|
|
|
|
|
fp = fopen (fname, "rb"); |
|
|
if (!fp) |
|
|
return "UNKNOWN"; |
|
|
p = fgets (header, sizeof (header) - 1, fp); |
|
|
fclose (fp); |
|
|
if (!p) |
|
|
return "UNKNOWN"; |
|
|
|
|
|
if( strncmp( header, "-----", 5 ) ) |
|
|
goto leave; |
|
|
if( strstr( header, "BEGIN PGP PUBLIC KEY" ) ) |
|
|
return "PUBKEY"; |
|
|
else if( strstr( header, "BEGIN PGP PRIVATE KEY" ) ) |
|
|
return "SECKEY"; |
|
|
else if( strstr( header, "BEGIN PGP SECRET KEY" ) ) |
|
|
return "SECKEY"; |
|
|
else if( strstr( header, "BEGIN PGP MESSAGE" ) ) |
|
|
return "ENCRYPTED"; |
|
|
else if( strstr( header, "BEGIN PGP SIGNED MESSAGE" ) ) |
|
|
return "SIGNED-CLEAR"; |
|
|
else if( strstr(header, "BEGIN PGP SIGNATURE" ) ) |
|
|
return "SIGNED-DETACH"; |
|
|
|
|
|
leave: |
|
|
return "UNKNOWN"; |
|
|
} |
|
|
|
|
|
|
|
544 |
int |
int |
545 |
fm_assume_onepass_sig (const char * fname) |
fm_assume_onepass_sig (const char * fname) |
546 |
{ |
{ |
550 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
551 |
int check = 0; |
int check = 0; |
552 |
|
|
553 |
if (!fname) |
if (!fname) { |
|
{ |
|
554 |
gpg_data_new_from_clipboard (&dat, 0); |
gpg_data_new_from_clipboard (&dat, 0); |
555 |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
556 |
|
|
558 |
if (!fp) |
if (!fp) |
559 |
return 0; |
return 0; |
560 |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
561 |
if (gpg_use_armor_filter(fp)) |
if (gpg_use_armor_filter(fp)) { |
|
{ |
|
562 |
memset (&afx, 0, sizeof (afx)); |
memset (&afx, 0, sizeof (afx)); |
563 |
gpg_iobuf_push_filter (fp, gpg_armor_filter, &afx); |
gpg_iobuf_push_filter (fp, gpg_armor_filter, &afx); |
564 |
} |
} |
576 |
} |
} |
577 |
|
|
578 |
|
|
|
static int |
|
|
is_floppy_disc (const char * fname) |
|
|
{ |
|
|
char drv[32] = {0}; |
|
|
int i=0; |
|
|
|
|
|
if (!strstr (fname, ":\\")) |
|
|
return 0; |
|
|
|
|
|
while (fname && *fname && *fname != '\\') |
|
|
drv[i++] = *fname++; |
|
|
drv[i++] = '\\'; |
|
|
drv[i++] = '\0'; |
|
|
i = GetDriveType (drv); |
|
|
if (i == DRIVE_REMOVABLE) |
|
|
return -1; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
const char * |
|
|
fm_get_file_type (const char * fname) |
|
|
{ |
|
|
gpg_iobuf_t inp; |
|
|
armor_filter_context_t afx; |
|
|
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
|
|
int i = 0, rc = 0; |
|
|
const char * s = NULL; |
|
|
|
|
|
if (!fname) { |
|
|
safe_free (pkt); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
if (is_floppy_disc (fname)) |
|
|
return fm_check_armor_type (fname); |
|
|
|
|
|
inp = gpg_iobuf_open (fname); |
|
|
if (!inp) { |
|
|
const char *s = winpt_strerror (WPTERR_FILE_OPEN); |
|
|
log_box( _("File Manager"), MB_ERR, "\"%s\": %s", fname, s ); |
|
|
safe_free( pkt ); |
|
|
return NULL; |
|
|
} |
|
|
gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */ |
|
|
if (gpg_iobuf_get_filelength (inp) > 32000000 /* 32MB */ |
|
|
&& !is_openpgp_ext (fname)) { |
|
|
gpg_iobuf_close (inp); |
|
|
return "UNKNOWN"; |
|
|
} |
|
|
|
|
|
if (gpg_use_armor_filter(inp)) { |
|
|
memset (&afx, 0, sizeof (afx)); |
|
|
gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx); |
|
|
} |
|
|
|
|
|
gpg_init_packet (pkt); |
|
|
while (!(rc = gpg_parse_packet (inp, pkt))) { |
|
|
switch (pkt->pkttype) { |
|
|
case PKT_PUBKEY_ENC: s = "ENCRYPTED";rc = -2; break; |
|
|
case PKT_SYMKEY_ENC: |
|
|
case PKT_ENCRYPTED: s = "SYMKEYENC";rc = -2; break; |
|
|
case PKT_SIGNATURE: |
|
|
case PKT_ONEPASS_SIG: s = "SIGNED"; rc = -2; break; |
|
|
case PKT_PUBLIC_KEY: s = "PUBKEY"; rc = -2; break; |
|
|
case PKT_SECRET_KEY: s = "SECKEY"; rc = -2; break; |
|
|
} |
|
|
gpg_free_packet (pkt); |
|
|
gpg_init_packet (pkt); |
|
|
if (rc == -2) |
|
|
break; /* found */ |
|
|
} |
|
|
safe_free (pkt); |
|
|
gpg_iobuf_close (inp); |
|
|
if (!s) |
|
|
s = fm_check_armor_type (fname); |
|
|
if (!s) |
|
|
s = "UNKNOWN"; |
|
|
if (!strcmp( s, "SIGNED") |
|
|
&& strcmp (fm_check_armor_type (fname), "SIGNED-CLEAR ")) |
|
|
s = "SIGNED-DETACH"; |
|
|
return s; |
|
|
} /* fm_get_file_type */ |
|
|
|
|
|
|
|
579 |
int |
int |
580 |
fm_get_current_pos (listview_ctrl_t lv) |
fm_get_current_pos (listview_ctrl_t lv) |
581 |
{ |
{ |
1018 |
c->dlg, _("Signing")); |
c->dlg, _("Signing")); |
1019 |
c->init_cb = 1; |
c->init_cb = 1; |
1020 |
} |
} |
1021 |
|
op_begin (); |
1022 |
err = gpgme_op_encrypt_sign (ctx, c->recp, GPGME_ENCRYPT_ALWAYS_TRUST, |
err = gpgme_op_encrypt_sign (ctx, c->recp, GPGME_ENCRYPT_ALWAYS_TRUST, |
1023 |
in->dat, out->dat); |
in->dat, out->dat); |
1024 |
|
op_end (); |
1025 |
if (!c->cache_cb) |
if (!c->cache_cb) |
1026 |
release_gpg_passphrase_cb (&c->pass_cb); |
release_gpg_passphrase_cb (&c->pass_cb); |
1027 |
if (c->pass_cb.cancel) { |
if (c->pass_cb.cancel) { |
1037 |
} |
} |
1038 |
} |
} |
1039 |
else { |
else { |
1040 |
|
op_begin (); |
1041 |
err = gpgme_op_encrypt (ctx, c->recp, GPGME_ENCRYPT_ALWAYS_TRUST, |
err = gpgme_op_encrypt (ctx, c->recp, GPGME_ENCRYPT_ALWAYS_TRUST, |
1042 |
in->dat, out->dat); |
in->dat, out->dat); |
1043 |
|
op_end (); |
1044 |
if (err) { |
if (err) { |
1045 |
msg_box (c->dlg, gpgme_strerror (err), _("Encrypt"), MB_ERR); |
msg_box (c->dlg, gpgme_strerror (err), _("Encrypt"), MB_ERR); |
1046 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1096 |
if (err) |
if (err) |
1097 |
goto leave; |
goto leave; |
1098 |
|
|
1099 |
err = gpgme_op_encrypt (ctx, NULL, GPGME_ENCRYPT_ALWAYS_TRUST, in->dat, out->dat); |
op_begin (); |
1100 |
|
err = gpgme_op_encrypt (ctx, NULL, GPGME_ENCRYPT_ALWAYS_TRUST, |
1101 |
|
in->dat, out->dat); |
1102 |
|
op_end (); |
1103 |
if (err) { |
if (err) { |
1104 |
msg_box (c->dlg, gpgme_strerror (err), _("Symmetric"), MB_ERR); |
msg_box (c->dlg, gpgme_strerror (err), _("Symmetric"), MB_ERR); |
1105 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1218 |
if (err) |
if (err) |
1219 |
goto leave; |
goto leave; |
1220 |
|
|
1221 |
|
op_begin (); |
1222 |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
1223 |
|
op_end (); |
1224 |
if (!c->cache_cb) |
if (!c->cache_cb) |
1225 |
release_gpg_passphrase_cb (&c->pass_cb); |
release_gpg_passphrase_cb (&c->pass_cb); |
1226 |
if (c->pass_cb.cancel) { |
if (c->pass_cb.cancel) { |
1302 |
if (err) |
if (err) |
1303 |
goto leave; |
goto leave; |
1304 |
|
|
1305 |
|
op_begin (); |
1306 |
err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode); |
err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode); |
1307 |
|
op_end (); |
1308 |
if( !c->cache_cb ) |
if( !c->cache_cb ) |
1309 |
release_gpg_passphrase_cb (&c->pass_cb); |
release_gpg_passphrase_cb (&c->pass_cb); |
1310 |
if( c->pass_cb.cancel ) { |
if( c->pass_cb.cancel ) { |
1506 |
if (err) |
if (err) |
1507 |
goto leave; |
goto leave; |
1508 |
|
|
1509 |
|
op_begin (); |
1510 |
if (c->sigmode == GPGME_SIG_MODE_DETACH) |
if (c->sigmode == GPGME_SIG_MODE_DETACH) |
1511 |
err = gpgme_op_verify (ctx, in->dat, out->dat, NULL); |
err = gpgme_op_verify (ctx, in->dat, out->dat, NULL); |
1512 |
else |
else |
1513 |
err = gpgme_op_verify (ctx, in->dat, in->dat, out->dat); |
err = gpgme_op_verify (ctx, in->dat, in->dat, out->dat); |
1514 |
|
op_end (); |
1515 |
if (err) { |
if (err) { |
1516 |
msg_box (c->dlg, gpgme_strerror (err), _("Verify"), MB_ERR); |
msg_box (c->dlg, gpgme_strerror (err), _("Verify"), MB_ERR); |
1517 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1555 |
if (err) |
if (err) |
1556 |
goto leave; |
goto leave; |
1557 |
|
|
1558 |
|
op_begin (); |
1559 |
err = gpgme_op_import (ctx, keydata->dat); |
err = gpgme_op_import (ctx, keydata->dat); |
1560 |
|
op_end (); |
1561 |
if (err) { |
if (err) { |
1562 |
msg_box (c->dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
msg_box (c->dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
1563 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1620 |
if (err) |
if (err) |
1621 |
goto leave; |
goto leave; |
1622 |
|
|
1623 |
|
op_begin (); |
1624 |
err = gpgme_op_export (ctx, patt, 0, keydata->dat); |
err = gpgme_op_export (ctx, patt, 0, keydata->dat); |
1625 |
|
op_end (); |
1626 |
if (err) { |
if (err) { |
1627 |
msg_box (c->dlg, gpgme_strerror (err), _("Export"), MB_ERR); |
msg_box (c->dlg, gpgme_strerror (err), _("Export"), MB_ERR); |
1628 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1641 |
} |
} |
1642 |
|
|
1643 |
|
|
1644 |
|
/* Parse the command line and process the given file. */ |
1645 |
int |
int |
1646 |
fm_parse_command_line (char *cmdl) |
fm_parse_command_line (char *cmdl) |
1647 |
{ |
{ |
1649 |
const char *s; |
const char *s; |
1650 |
char *p, *fn = NULL; |
char *p, *fn = NULL; |
1651 |
int count = 0, detached = 0; |
int count = 0, detached = 0; |
1652 |
|
int type; |
1653 |
|
|
1654 |
if( !cmdl || !*cmdl ) |
if (!cmdl || !*cmdl) |
1655 |
return 0; |
return 0; |
1656 |
|
|
1657 |
fm_state_new( &ctx ); |
fm_state_new (&ctx); |
1658 |
ctx->dlg = GetActiveWindow( ); |
ctx->dlg = GetActiveWindow (); |
1659 |
ctx->cache_cb = 1; |
ctx->cache_cb = 1; |
1660 |
|
|
1661 |
p = cmdl; |
p = cmdl; |
1662 |
if( p && *p > 32 && !stristr( p, "winpt.exe" ) |
if (p && *p > 32 && !stristr (p, "winpt.exe") |
1663 |
&& !strstr( p, "--" ) ) { |
&& !strstr (p, "--" )) { |
1664 |
count++; |
count++; |
1665 |
if (*p == '"') { /* need to remove quotes */ |
if (*p == '"') { /* need to remove quotes */ |
1666 |
fn = new char[strlen( p )]; |
fn = new char[strlen (p)]; |
1667 |
if (!fn) |
if (!fn) |
1668 |
BUG( NULL ); |
BUG (NULL); |
1669 |
memcpy( fn, p+1, strlen( p ) - 2 ); |
memcpy (fn, p+1, strlen (p) - 2); |
1670 |
fn[strlen( p ) -2] = '\0'; |
fn[strlen (p) -2] = '\0'; |
1671 |
} |
} |
1672 |
else |
else |
1673 |
fn = m_strdup (p); |
fn = m_strdup (p); |
1674 |
s = fm_get_file_type (fn); |
s = fm_get_file_type (fn, &type); |
1675 |
if (!s || !strcmp (s, "UNKNOWN")) |
if (!s || !strcmp (s, "UNKNOWN")) |
1676 |
s = gnupg_check_file_ext (fn); |
s = gnupg_check_file_ext (fn, &type); |
1677 |
if (*s == 'U') { |
if (type == PGP_NONE) { |
1678 |
log_box( _("File Manager"), MB_ERR, _("%s: no valid OpenPGP data found."), p ); |
log_box (_("File Manager"), MB_ERR, |
1679 |
|
_("%s: no valid OpenPGP data found."), p); |
1680 |
|
free_if_alloc (fn); |
1681 |
return count; |
return count; |
1682 |
} |
} |
1683 |
|
switch (type) { |
1684 |
switch( *s ) { |
case PGP_MESSAGE: |
1685 |
case 'E': fm_decrypt (ctx, fn); break; |
fm_decrypt (ctx, fn); |
1686 |
case 'P': fm_import (ctx, fn); break; |
break; |
1687 |
case 'S': |
|
1688 |
if (s[1] == 'Y') { |
case PGP_PUBKEY: |
1689 |
fm_decrypt (ctx, fn); |
case PGP_SECKEY: |
1690 |
break; |
fm_import (ctx, fn); |
1691 |
} |
break; |
1692 |
|
|
1693 |
|
case PGP_SIG: |
1694 |
|
case PGP_CLEARSIG: |
1695 |
file_verify_use_event (); |
file_verify_use_event (); |
1696 |
if (s[1] == 'I') { |
if (type == PGP_SIG) |
1697 |
if (strlen (s) == 13 && s[7] == 'D') |
detached = 1; |
1698 |
detached = 1; |
fm_verify (ctx, detached, fn); |
1699 |
fm_verify( ctx, detached, fn ); |
file_verify_wait (); |
|
} |
|
|
file_verify_wait( ); |
|
1700 |
break; |
break; |
1701 |
} |
} |
1702 |
} |
} |
1703 |
|
|
1704 |
memset( &ctx->pass_cb, 0, sizeof (ctx->pass_cb) ); |
wipememory (&ctx->pass_cb, sizeof (ctx->pass_cb)); |
1705 |
safe_free( fn ); |
free_if_alloc (fn); |
1706 |
fm_state_release( ctx ); |
fm_state_release (ctx); |
1707 |
return count; |
return count; |
1708 |
} /* fm_parse_command_line */ |
} |
1709 |
|
|
1710 |
|
|
1711 |
const char * |
const char* |
1712 |
default_dirname( const char * name ) |
default_dirname (const char *name) |
1713 |
{ |
{ |
1714 |
char * p = strrchr( name, '\\' ); |
char * p = strrchr( name, '\\' ); |
1715 |
if( !p ) |
if( !p ) |
1768 |
unlink( s ); |
unlink( s ); |
1769 |
} |
} |
1770 |
leave: |
leave: |
1771 |
|
FindClose (hd); |
1772 |
pk_list_free( list ); |
pk_list_free( list ); |
1773 |
free_if_alloc( patt ); |
free_if_alloc( patt ); |
1774 |
return rc; |
return rc; |
1806 |
|
|
1807 |
if( listview_count_items( lv, 0 ) == 0 ) |
if( listview_count_items( lv, 0 ) == 0 ) |
1808 |
return; |
return; |
1809 |
memset( &mdctx, 0, sizeof (mdctx) ); |
memset (&mdctx, 0, sizeof (mdctx)); |
1810 |
mdctx.lv = lv; |
mdctx.lv = lv; |
1811 |
mdctx.mdalgo = mdalgo; |
mdctx.mdalgo = mdalgo; |
1812 |
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg, |
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg, |