/[winpt]/trunk/Src/wptFileManager.cpp
ViewVC logotype

Diff of /trunk/Src/wptFileManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 88 by twoaday, Mon Nov 21 12:06:59 2005 UTC revision 172 by twoaday, Mon Jan 30 13:47:35 2006 UTC
# Line 21  Line 21 
21  /* TODO:  /* TODO:
22   *    check_armor_type: we should check the whole file and not only the first line!   *    check_armor_type: we should check the whole file and not only the first line!
23   */   */
24    
25  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
26  #include <config.h>  #include <config.h>
27  #endif  #endif
# Line 49  Line 50 
50  #include "wptRegistry.h"  #include "wptRegistry.h"
51  #include "wptImport.h"  #include "wptImport.h"
52  #include "wptCrypto.h"  #include "wptCrypto.h"
53    #include "wptKeyManager.h"
54  #include "openpgp.h"  #include "openpgp.h"
55    
56  #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))  #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))
# Line 112  overwrite_file (const char *fname) Line 114  overwrite_file (const char *fname)
114    
115  /* Removes 'critical' attributes from the file @fname.  /* Removes 'critical' attributes from the file @fname.
116     If @force is 1, the user is not asked for permission. */     If @force is 1, the user is not asked for permission. */
117  static void  void
118  remove_crit_file_attrs (const char *fname, int force)  remove_crit_file_attrs (const char *fname, int force)
119  {  {
120      u32 fattr;      u32 fattr;
# Line 272  leave: Line 274  leave:
274    
275  /* Extract file type from @fname. If @r_type is valid,  /* Extract file type from @fname. If @r_type is valid,
276     it contains the PGP type on success. */     it contains the PGP type on success. */
277  static const char *  static const char*
278  fm_get_file_type (const char *fname, int *r_type)  fm_get_file_type (const char *fname, int *r_type)
279  {          {        
280      gpg_iobuf_t inp;      gpg_iobuf_t inp;
281      armor_filter_context_t afx;      armor_filter_context_t afx;
282      PACKET *pkt;      PACKET *pkt;
283      const char *s = NULL;      const char *s = NULL;
284        size_t count = 0, compr = 0;
285      int rc = 0;      int rc = 0;
286    
     /* XXX: if the text was created with gpg --sign and armored  
             there is no way to differ between an encrypted text  
             and a one-pass signature. */  
287      if (r_type)      if (r_type)
288          *r_type = PGP_NONE;          *r_type = PGP_NONE;
289      if (!fname) {      if (!fname) {
# Line 340  fm_get_file_type (const char *fname, int Line 340  fm_get_file_type (const char *fname, int
340              if (r_type) *r_type = PGP_SECKEY;              if (r_type) *r_type = PGP_SECKEY;
341              break;              break;
342    
343            case PKT_COMPRESSED:
344                /* If we only find 1 packet and it is compressed,
345                   we assume a compress one-pass signature. */
346                if (count != 0)
347                    break;
348                s = "SIGNED";   rc = -2;
349                compr = 1;
350                break;
351    
352          default:          default:
353              break;              break;
354          }          }
355            count++;
356          gpg_free_packet (pkt);          gpg_free_packet (pkt);
357          gpg_init_packet (pkt);          gpg_init_packet (pkt);
358          if (rc == -2)          if (rc == -2)
# Line 354  fm_get_file_type (const char *fname, int Line 364  fm_get_file_type (const char *fname, int
364          s = fm_check_armor_type (fname, r_type);          s = fm_check_armor_type (fname, r_type);
365      if (!s)      if (!s)
366          s = "UNKNOWN";          s = "UNKNOWN";
367      if (!strcmp (s, "SIGNED")      if (!strcmp (s, "SIGNED") && !compr
368          && strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) {          && strcmp (fm_check_armor_type (fname, r_type), "SIGNED-CLEAR ")) {
369          if (r_type) *r_type = PGP_SIG;          if (r_type) *r_type = PGP_SIG;
370          s = "SIGNED-DETACH";          s = "SIGNED-DETACH";
# Line 363  fm_get_file_type (const char *fname, int Line 373  fm_get_file_type (const char *fname, int
373  }  }
374    
375    
376    /* Build the File Manager list view control. */
377  int  int
378  fm_build (listview_ctrl_t *lv, HWND ctrl)  fm_build (listview_ctrl_t *lv, HWND ctrl)
379  {  {
380      int i, rc = 0;      int i, rc = 0;
381      listview_ctrl_t c;      listview_ctrl_t c;
382      struct listview_column_s col[] =      struct listview_column_s col[] = {
     {  
383          {0,  80, (char *)_("Status") },          {0,  80, (char *)_("Status") },
384          {1, 256, (char *)_("Name") },          {1, 256, (char *)_("Name") },
385          {2, 128, (char *)_("Operation") },          {2, 128, (char *)_("Operation") },
386          {0,   0, NULL }          {0,   0, NULL }
387      };      };
388                    
389      rc = listview_new( &c );      rc = listview_new (&c);
390      if( rc )      if (rc)
391          BUG( NULL );          BUG (NULL);
392      c->ctrl = ctrl;      c->ctrl = ctrl;
393      for ( i = 0; col[i].width; i++ )      for (i = 0; col[i].width; i++)
394          listview_add_column( c, &col[i] );          listview_add_column (c, &col[i]);
395      listview_set_ext_style( c );      listview_set_ext_style (c);
396      if( lv )      if (lv)
397          *lv = c;          *lv = c;
398      return 0;      return 0;
399  } /* fm_build */  }
400    
401    
402    /* Release the File Manager listview control. */
403  void  void
404  fm_delete( listview_ctrl_t lv )  fm_delete (listview_ctrl_t lv)
405  {  {
406      if( lv ) {      if (lv) {
407          listview_release( lv );          listview_release(lv);  
408      }      }
409  } /* fm_delete */  }
410    
411    
412  int  int
# Line 424  fm_state_release (fm_state_t c) Line 435  fm_state_release (fm_state_t c)
435  {  {
436      if (!c)      if (!c)
437          return;          return;
     if (c->recp)  
         free (c->recp);  
438      if (c->ctx) {      if (c->ctx) {
439          gpgme_release (c->ctx);          gpgme_release (c->ctx);
440          c->ctx = NULL;            c->ctx = NULL;  
441      }      }
442        safe_free (c->recp);
443      free_if_alloc (c->opaque);      free_if_alloc (c->opaque);
444      free_if_alloc (c->output);      free_if_alloc (c->output);
445      delete c; c = NULL;          delete c; c = NULL;    
# Line 519  fm_add_dropped_files (listview_ctrl_t lv Line 529  fm_add_dropped_files (listview_ctrl_t lv
529          if (rc == -1)          if (rc == -1)
530              break; /* XXX: fixme? */              break; /* XXX: fixme? */
531      }      }
532        DragFinish (dd_files);
533      return rc;      return rc;
534  }  }
535    
# Line 562  fm_add_opened_files (listview_ctrl_t lv, Line 573  fm_add_opened_files (listview_ctrl_t lv,
573      open.lStructSize = sizeof (OPENFILENAME);      open.lStructSize = sizeof (OPENFILENAME);
574      open.hInstance = glob_hinst;      open.hInstance = glob_hinst;
575      open.lpstrTitle = _("File Open");      open.lpstrTitle = _("File Open");
576      open.lpstrFilter = _("All Files (*.*)\0*.*\0\0");      open.lpstrFilter = "All Files (*.*)\0*.*\0\0";
577      open.hwndOwner = dlg;      open.hwndOwner = dlg;
578      open.lpstrFile = file;      open.lpstrFile = file;
579      open.nMaxFile = sizeof (file) - 1;      open.nMaxFile = sizeof (file) - 1;
# Line 755  fm_set_status (listview_ctrl_t lv, int p Line 766  fm_set_status (listview_ctrl_t lv, int p
766      case FM_SIGN:      case FM_SIGN:
767          if (sigmode == GPGME_SIG_MODE_DETACH)          if (sigmode == GPGME_SIG_MODE_DETACH)
768              strcpy (status, "SIGNED-DETACH");              strcpy (status, "SIGNED-DETACH");
769            else if (sigmode == GPGME_SIG_MODE_CLEAR)
770                strcpy (status, "SIGNED-CLEAR");
771          else          else
772              strcpy (status, "SIGNED");              strcpy (status, "SIGNED");
773          break;          break;
# Line 765  fm_set_status (listview_ctrl_t lv, int p Line 778  fm_set_status (listview_ctrl_t lv, int p
778      default:             strcpy (status, "UNKNOWN");    break;      default:             strcpy (status, "UNKNOWN");    break;
779      }      }
780    
781      if (success) {      if (success && update) {
782          if (update) {          listview_add_sub_item (lv, pos, 0, status);
783              listview_add_sub_item (lv, pos, 0, status);          listview_add_sub_item (lv, pos, 1, output);
             listview_add_sub_item (lv, pos, 1, output);  
         }  
784      }      }
785      listview_add_sub_item( lv, pos, 2, operat );      listview_add_sub_item( lv, pos, 2, operat );
786  }  }
# Line 859  fm_parse_files (listview_ctrl_t lv, HWND Line 870  fm_parse_files (listview_ctrl_t lv, HWND
870      case FM_SIGNENCRYPT:      case FM_SIGNENCRYPT:
871          if (fm_cmd == FM_SIGNENCRYPT)          if (fm_cmd == FM_SIGNENCRYPT)
872              ctx->req_signer = 1;              ctx->req_signer = 1;
873          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_ENCRYPT, ctx->dlg,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_ENCRYPT,
874                          file_encrypt_dlg_proc, (LPARAM)ctx);                          ctx->dlg, file_encrypt_dlg_proc, (LPARAM)ctx);
875          if (ctx->cancel == 1) {          if (ctx->cancel == 1) {
876              rc = WPTERR_GENERAL;              rc = WPTERR_GENERAL;
877              goto leave;              goto leave;
878          }          }
879          break;          break;
# Line 905  fm_parse_files (listview_ctrl_t lv, HWND Line 916  fm_parse_files (listview_ctrl_t lv, HWND
916          if (!confirm.yes)          if (!confirm.yes)
917              goto leave;              goto leave;
918      }      }
919        
920      if (fm_cmd == FM_ENCRYPT_ZIP)      if (fm_cmd == FM_ENCRYPT_ZIP)
921          fm_encrypt_into_zip (ctx, lv);          fm_encrypt_into_zip (ctx, lv);
922    
923      for (i = 0; i < listview_count_items (lv, 0); i++) {      for (i = 0; i < listview_count_items (lv, 0); i++) {
924          if( !listview_get_item_state( lv, i ) )          if( !listview_get_item_state( lv, i ) )
925              continue;              continue;
926          listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 );          listview_get_item_text(lv, i, 1, fname, sizeof (fname) - 1);
927          if( file_exist_check( fname ) && !is_directory( fname ) ) {          if( file_exist_check (fname) && !is_directory (fname)) {
928              log_box( _("File Manager"), MB_ERR, _("\"%s\" does not exist"), fname );              log_box (_("File Manager"), MB_ERR,
929                         _("\"%s\" does not exist"), fname);
930              continue;              continue;
931          }          }
932          if( is_directory( fname ) )          if (is_directory (fname))
933              fm_cmd = FM_ENCRYPT_DIR;                      fm_cmd = FM_ENCRYPT_DIR;        
934          if( !fm_check_file_type( lv, i, fm_cmd ) )          if (!fm_check_file_type (lv, i, fm_cmd))
935              continue;              continue;
936          sig_detached = fm_check_detached_sig( lv, i );          sig_detached = fm_check_detached_sig (lv, i);
937          switch (fm_cmd) {          switch (fm_cmd) {
938          case FM_LIST:        rc = fm_list( fname, dlg );       break;          case FM_LIST:        rc = fm_list( fname, dlg );       break;
939          case FM_WIPE:        rc = fm_wipe( fname );            break;          case FM_WIPE:        rc = fm_wipe( fname );            break;
# Line 1038  fm_encrypt (fm_state_t c, const char *na Line 1050  fm_encrypt (fm_state_t c, const char *na
1050          BUG (0);          BUG (0);
1051      strcpy (ext, file_get_extension (ctx, c->sigmode));      strcpy (ext, file_get_extension (ctx, c->sigmode));
1052      strcpy (c->output, name);      strcpy (c->output, name);
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);
# Line 1046  fm_encrypt (fm_state_t c, const char *na Line 1058  fm_encrypt (fm_state_t c, const char *na
1058              goto leave;              goto leave;
1059      }      }
1060    
1061      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1062      if (err)      if (err)
1063          goto leave;          goto leave;
1064      err = gpg_file_data_new (c->output, 0, &out);      remove_crit_file_attrs (c->output, 0);
1065        err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1066      if (err)      if (err)
1067          goto leave;          goto leave;
1068    
# Line 1060  fm_encrypt (fm_state_t c, const char *na Line 1073  fm_encrypt (fm_state_t c, const char *na
1073      }      }
1074      */      */
1075            
1076      /* XXX      /* XXX: disable compression for multi-media files.
1077      no_compr = is_multi_media (name);      no_compr = is_multi_media (name);
1078      gpgme_control (ctx, GPGME_CTRL_NO_COMPR, no_compr);      gpgme_control (ctx, GPGME_CTRL_NO_COMPR, no_compr);
1079      */      */
# Line 1189  leave: Line 1202  leave:
1202          gpg_file_data_release (out);          gpg_file_data_release (out);
1203      sfree_if_alloc (pass);      sfree_if_alloc (pass);
1204      return rc;      return rc;
1205  } /* fm_sym_encrypt */  }
1206    
1207    
1208  /* Show the human readable verify result from @sigres. */  /* Show the human readable verify result from @sigres. */
# Line 1207  show_verify_result (gpgme_verify_result_ Line 1220  show_verify_result (gpgme_verify_result_
1220      sigok = sig->summary & GPGME_SIGSUM_GREEN;      sigok = sig->summary & GPGME_SIGSUM_GREEN;
1221      s = sigok? _("Good signature") : _("BAD signature");      s = sigok? _("Good signature") : _("BAD signature");
1222      type = sigok? MB_OK: MB_ICONWARNING|MB_OK;      type = sigok? MB_OK: MB_ICONWARNING|MB_OK;
1223      keyid = sig->fpr;        keyid = sig->fpr;
1224      if (!keyid)      if (!keyid)
1225          return;          return;
1226    
1227      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;
1228      get_pubkey (sig->fpr, &key);      get_pubkey (sig->fpr, &key);
1229      _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"
1230                                      "%s from \"%s\"",                                      "%s from \"%s\""),
1231                  strtimestamp (sig->timestamp), get_key_pubalgo (sig->pubkey_algo),                  strtimestamp (sig->timestamp),
1232                    get_key_pubalgo (sig->pubkey_algo),
1233                  keyid, s, key? key->uids->uid : _("user ID not found"));                  keyid, s, key? key->uids->uid : _("user ID not found"));
1234      msg_box (NULL, buf, _("Decrypt Verify"), type);      msg_box (NULL, buf, _("Decrypt Verify"), type);
1235  }  }
# Line 1228  secret_key_available (gpgme_recipient_t Line 1242  secret_key_available (gpgme_recipient_t
1242      gpgme_recipient_t r;      gpgme_recipient_t r;
1243      gpgme_key_t key;      gpgme_key_t key;
1244    
1245      for (r=rset; r; r = r->next) {            for (r=rset; r; r = r->next) {
1246          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)
1247              continue;              continue;
1248          else {          else {
# Line 1253  fm_decrypt (fm_state_t c, const char *na Line 1267  fm_decrypt (fm_state_t c, const char *na
1267      int rc = 0;      int rc = 0;
1268            
1269      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
1270          set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT,          set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT,
1271                                 c->dlg, _("Decryption"));                                 c->dlg, _("Decryption"));
1272          c->init_cb = 1;          c->init_cb = 1;
1273      }          }
1274            
1275      c->output = m_strdup (name);      c->output = m_strdup (name);
1276      if (!c->output)      if (!c->output)
# Line 1279  fm_decrypt (fm_state_t c, const char *na Line 1293  fm_decrypt (fm_state_t c, const char *na
1293          rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL);          rc = ask_filename (c, _("Please enter filename for plaintext file"), NULL);
1294          if (rc)          if (rc)
1295              goto leave;              goto leave;
1296      }          }
   
     remove_crit_file_attrs (c->output, 0);  
1297    
1298      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1299      if (err)      if (err)
1300          goto leave;          goto leave;
1301      err = gpg_file_data_new (c->output, 0, &out);      remove_crit_file_attrs (c->output, 0);
1302        err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1303      if (err)      if (err)
1304          goto leave;          goto leave;
1305    
# Line 1320  fm_decrypt (fm_state_t c, const char *na Line 1333  fm_decrypt (fm_state_t c, const char *na
1333          goto leave;          goto leave;
1334      }      }
1335      if (file_exist_check (c->output)) {      if (file_exist_check (c->output)) {
1336          log_box ("Decrypt", MB_ERR, _("Decryption failed.\n%s: does not exist."), c->output);          log_box ("Decrypt", MB_ERR,
1337                     _("Decryption failed.\n%s: does not exist."), c->output);
1338          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1339      }      }
1340            
# Line 1333  leave: Line 1347  leave:
1347          gpg_file_data_release (in);          gpg_file_data_release (in);
1348      if (out)      if (out)
1349          gpg_file_data_release (out);          gpg_file_data_release (out);
1350    
1351      return rc;      return rc;
1352  }  }
1353    
1354    
1355  int  int
1356  fm_sign (fm_state_t c, const char * name)  fm_sign (fm_state_t c, const char * name)
1357  {        {
     int rc = 0;  
1358      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1359      gpgme_error_t err;      gpgme_error_t err;
1360      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1361      char ext[5];      char ext[5];
1362        int rc = 0;
1363    
1364      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
1365          set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_SIGN, c->dlg, _("Signing") );          set_gpg_passphrase_cb (&c->pass_cb, c->ctx,
1366                                   GPG_CMD_SIGN, c->dlg, _("Signing"));
1367          c->init_cb = 1;          c->init_cb = 1;
1368      }      }
1369            
1370      free_if_alloc (c->output);      free_if_alloc (c->output);
1371      c->output = new char[strlen (name) + 5 + 1];      c->output = new char[strlen (name) + 5 + 1];
1372      if( !c->output)      if (!c->output)
1373          BUG( NULL );          BUG (NULL);
1374      strcpy (ext, file_get_extension (ctx, c->sigmode));      strcpy (ext, file_get_extension (ctx, c->sigmode));
1375      strcpy (c->output, name);      strcpy (c->output, name);
1376      strcat (c->output, ext);      strcat (c->output, ext);
# Line 1364  fm_sign (fm_state_t c, const char * name Line 1380  fm_sign (fm_state_t c, const char * name
1380          if (rc)          if (rc)
1381              goto leave;              goto leave;
1382      }      }
1383      remove_crit_file_attrs (c->output, 0);      
1384        err = gpg_file_data_new (name, F_DATA_READ, &in);
     err = gpg_file_data_new (name, 1, &in);  
1385      if (err)      if (err)
1386          goto leave;          goto leave;
1387      err = gpg_file_data_new (c->output, 0, &out);      remove_crit_file_attrs (c->output, 0);
1388        err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1389      if (err)      if (err)
1390          goto leave;          goto leave;
1391    
1392      op_begin ();      op_begin ();
1393      err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode);      err = gpgme_op_sign (ctx, in->dat, out->dat, c->sigmode);
1394      op_end ();      op_end ();
1395      if( !c->cache_cb )      if (!c->cache_cb)
1396          release_gpg_passphrase_cb (&c->pass_cb);          release_gpg_passphrase_cb (&c->pass_cb);
1397      if( c->pass_cb.cancel ) {      if (c->pass_cb.cancel) {
1398          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1399          goto leave;          goto leave;
1400      }      }
1401      if( err ) {      if (err) {
1402          msg_box( c->dlg, gpgme_strerror( err ), _("Sign"), MB_ERR );          msg_box (c->dlg, gpgme_strerror (err), _("Sign"), MB_ERR);
1403          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1404          goto leave;              goto leave;    
1405      }      }
# Line 1397  leave: Line 1413  leave:
1413  }  }
1414    
1415    
1416  static int  static void
1417  fm_add_sig_stat (file_sig_ctx_t log)  fm_add_sig_stat (file_sig_ctx_t log)
1418  {  {
1419      gpgme_key_t key;          gpgme_key_t key;    
# Line 1417  fm_add_sig_stat (file_sig_ctx_t log) Line 1433  fm_add_sig_stat (file_sig_ctx_t log)
1433          log->use_uid = 1;          log->use_uid = 1;
1434      }      }
1435      file_verify_add_state (log);      file_verify_add_state (log);
     return 0;  
1436  }  }
1437    
1438    
1439    /* Verify a detached signature from the clipboard. */  
1440  static int  static int
1441  verify_pasted (listview_ctrl_t lv, fm_state_t ctx, const char * dat,  verify_pasted (listview_ctrl_t lv, fm_state_t ctx,
1442                 int i, HWND dlg)                 const char *dat, int pos, HWND dlg)
1443  {  {
1444      FILE * fp;      FILE *fp;
1445      char stat[32];      char stat[32];
1446      char file[256], * fname = NULL;      char file[256], *fname = NULL;
1447      int del_end=0;      int del_end = 0;
1448    
1449      listview_get_item_text (lv, i, 0, stat, sizeof (stat)-1);      listview_get_item_text (lv, pos, 0, stat, sizeof (stat)-1);
1450      listview_get_item_text (lv, i, 1, file, sizeof (file)-1);      listview_get_item_text (lv, pos, 1, file, sizeof (file)-1);
1451      if (strcmp (stat, "UNKNOWN"))      if (strcmp (stat, "UNKNOWN"))
1452          return 0;          return 0;
1453      fname = make_filename (NULL, file, "asc");      fname = make_filename (NULL, file, "asc");
# Line 1440  verify_pasted (listview_ctrl_t lv, fm_st Line 1456  verify_pasted (listview_ctrl_t lv, fm_st
1456          if (fp == NULL) {          if (fp == NULL) {
1457              log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname);              log_box (_("File Manager"), MB_ERR, "could not create '%s'", fname);
1458              free_if_alloc (fname);              free_if_alloc (fname);
1459              return WPTERR_GENERAL;                    return WPTERR_GENERAL;
1460          }                }
1461          fwrite (dat, 1, strlen (dat), fp);          fwrite (dat, 1, strlen (dat), fp);
1462          fclose (fp);          fclose (fp);
1463          del_end = 1;          del_end = 1;
# Line 1454  verify_pasted (listview_ctrl_t lv, fm_st Line 1470  verify_pasted (listview_ctrl_t lv, fm_st
1470  }  }
1471    
1472    
1473    /* Figure out if the clipboard contains a detached signature. */
1474  int  int
1475  fm_verify_pasted_detsig (listview_ctrl_t lv, HWND dlg)  fm_verify_pasted_detsig (listview_ctrl_t lv, HWND dlg)
1476  {  {
# Line 1471  fm_verify_pasted_detsig (listview_ctrl_t Line 1488  fm_verify_pasted_detsig (listview_ctrl_t
1488      /* XXX find a way to filter out bad signatures or just ignore all in      /* XXX find a way to filter out bad signatures or just ignore all in
1489             this case */             this case */
1490      fm_state_new (&ctx);      fm_state_new (&ctx);
1491      if ((i=listview_get_curr_pos (lv)) != -1) {      i = listview_get_curr_pos (lv);
1492        if (i= -1) {
1493          verify_pasted (lv, ctx, dat, i, dlg);          verify_pasted (lv, ctx, dat, i, dlg);
1494          fnd = 1;          fnd = 1;
1495      }      }
# Line 1503  get_output_file (fm_state_t c, const cha Line 1521  get_output_file (fm_state_t c, const cha
1521      else      else
1522          title = _("Selected Output File");          title = _("Selected Output File");
1523    
1524      if (strstr (name, ".sig") || strstr (name, ".asc") || strstr (name, ".gpg")) {      if (strstr (name, ".sig")
1525            || strstr (name, ".asc")
1526            || strstr (name, ".gpg")) {
1527          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1528          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1529          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1569  fm_verify (fm_state_t c, int detached, c Line 1589  fm_verify (fm_state_t c, int detached, c
1589          BUG (NULL);          BUG (NULL);
1590      file_verify_create_dlg ();      file_verify_create_dlg ();
1591    
1592      err = gpg_file_data_new (name, 1, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1593      if (err)      if (err)
1594          goto leave;          goto leave;
1595      err = gpg_file_data_new (c->output, detached? 1 : 0, &out);      err = gpg_file_data_new (c->output,
1596                                 detached? F_DATA_READ : F_DATA_WRITE, &out);
1597      if (err)      if (err)
1598          goto leave;          goto leave;
1599    
# Line 1601  leave: Line 1622  leave:
1622          gpg_file_data_release (in);          gpg_file_data_release (in);
1623      if (out)      if (out)
1624          gpg_file_data_release (out);          gpg_file_data_release (out);
1625      if (log.file)      free_if_alloc (log.file);
         delete []log.file;  
1626      return rc;      return rc;
1627  }  }
1628    
1629    
1630    /* Import the keys from the file @name.
1631       Return value: 0 on success. */
1632  int  int
1633  fm_import (fm_state_t c, const char *name)  fm_import (fm_state_t c, const char *name)
1634  {  {
# Line 1621  fm_import (fm_state_t c, const char *nam Line 1643  fm_import (fm_state_t c, const char *nam
1643      if (!c->output)      if (!c->output)
1644          BUG (NULL);          BUG (NULL);
1645    
1646      err = gpg_file_data_new (name, 1, &keydata);      err = gpg_file_data_new (name, F_DATA_READ, &keydata);
1647      if (err)      if (err)
1648          goto leave;          goto leave;
1649    
# Line 1637  fm_import (fm_state_t c, const char *nam Line 1659  fm_import (fm_state_t c, const char *nam
1659      res = gpgme_op_import_result (ctx);      res = gpgme_op_import_result (ctx);
1660      print_import_status (res);      print_import_status (res);
1661      if (res->no_user_id > 0) {      if (res->no_user_id > 0) {
1662          msg_box (c->dlg, _("Key without a self signature was dectected!\n"                msg_box (c->dlg, _("Key without a self signature was dectected!\n"
1663                             "(This key is NOT usable for encryption, etc)\n"                             "(This key is NOT usable for encryption, etc)\n"
1664                             "\n"                             "\n"
1665                             "Cannot import these key(s)!"), _("Import"), MB_INFO);                             "Cannot import these key(s)!"), _("Import"), MB_INFO);
# Line 1647  leave: Line 1669  leave:
1669      if (keydata)      if (keydata)
1670          gpg_file_data_release (keydata);          gpg_file_data_release (keydata);
1671      return rc;      return rc;
1672  } /* fm_import */  }
1673    
1674    
1675  /* Export the selected keys from the File Manager to a file. */  /* Export the selected keys from the File Manager to a file. */
# Line 1659  fm_export (fm_state_t c) Line 1681  fm_export (fm_state_t c)
1681      gpgme_error_t err;      gpgme_error_t err;
1682      gpgme_key_t *rset = c->recp;      gpgme_key_t *rset = c->recp;
1683      file_data_t keydata = NULL;      file_data_t keydata = NULL;
1684      const char *name, *s = NULL;      const char *name;
1685      char *p = NULL, *patt = NULL;      char *p = NULL, *patt = NULL;
1686    
1687      if (!rset || !rset[0]) {      if (!rset || !rset[0]) {
# Line 1668  fm_export (fm_state_t c) Line 1690  fm_export (fm_state_t c)
1690          goto leave;          goto leave;
1691      }      }
1692    
1693      if (rset[1] == NULL) { /* count == 1*/      if (rset[1] == NULL) /* count == 1*/
1694          gpgme_key_t k = rset[0];          p = km_gen_export_filename (rset[0]->subkeys->keyid+8, 0);
         const char *s = k->uids->name;  
         p = new char[strlen (s)+1+8];  
         if (!p)  
             BUG (NULL);  
         strcpy (p, s );  
         strcat (p, ".asc");  
     }  
1695    
1696      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),
1697                               NULL, p? p : NULL);                               NULL, p? p : NULL);
                               
1698      if (!name)      if (!name)
1699          name = "keys.gpg";          name = "keys.gpg";
1700    
1701      patt = gpg_keylist_to_pattern (rset, c->n_recp);      patt = gpg_keylist_to_pattern (rset, c->n_recp);
1702    
1703      err = gpg_file_data_new (name, 0, &keydata);      err = gpg_file_data_new (name, F_DATA_WRITE, &keydata);
1704      if (err)      if (err)
1705          goto leave;          goto leave;
1706    
# Line 1706  leave: Line 1720  leave:
1720      if (patt)      if (patt)
1721          free (patt);          free (patt);
1722      free_if_alloc (p);      free_if_alloc (p);
           
1723      return rc;      return rc;
1724  }  }
1725    
# Line 1781  fm_parse_command_line (char *cmdl) Line 1794  fm_parse_command_line (char *cmdl)
1794  }  }
1795    
1796    
1797    /* Extract the last folder name from @name. */
1798  const char*  const char*
1799  default_dirname (const char *name)  default_dirname (const char *name)
1800  {  {
1801      char * p = strrchr( name, '\\' );      char *p = strrchr (name, '\\');
1802      if( !p )      if (!p)
1803          return NULL;          return NULL;
1804      return p+1;      return p+1;
1805  } /* default_dirname */  }
1806    
1807    
1808  /* Store all selected files from @lv in a zip archive  /* Store all selected files from @lv in a zip archive
# Line 1807  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1821  fm_encrypt_into_zip (fm_state_t ctx, lis
1821      if (!nitems) {      if (!nitems) {
1822          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"),
1823                   _("File Manager"), MB_ERR);                   _("File Manager"), MB_ERR);
1824          return -1;          return WPTERR_GENERAL;
1825      }      }
1826    
1827      outfile = get_filesave_dlg (NULL, _("Choose File Name for Output"),      outfile = get_filesave_dlg (ctx->dlg, _("Choose File Name for Output"),
1828                                  NULL, "encrypted_files.zip");                                  NULL, "Encrypted_Files.zip");
1829      if (!outfile)      if (!outfile)
1830          return -1;          return WPTERR_GENERAL;
1831    
1832      for (i=0; i < nitems; i++) {      for (i=0; i < nitems; i++) {
1833          char name[300];          char name[300];
# Line 1846  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1860  fm_encrypt_into_zip (fm_state_t ctx, lis
1860    
1861    
1862  int  int
1863  fm_encrypt_directory( fm_state_t c, const char * name )  fm_encrypt_directory (fm_state_t c, const char *name)
1864  {  {
1865      PK_FILE_LIST list = NULL;      PK_FILE_LIST list = NULL;
1866      WIN32_FIND_DATA findbuf;      WIN32_FIND_DATA findbuf;
# Line 1855  fm_encrypt_directory( fm_state_t c, cons Line 1869  fm_encrypt_directory( fm_state_t c, cons
1869      char * patt = NULL, * p;      char * patt = NULL, * p;
1870      int rc = 0;      int rc = 0;
1871            
1872      if( !is_directory( name ) )          if (!is_directory (name))
1873          return -1;          return -1;
1874      patt = new char[strlen( name ) + 4];      patt = new char[strlen (name) + 4];
1875      if( !patt )      if (!patt)
1876          BUG( NULL );          BUG (NULL);
1877      strcpy( patt, name );      strcpy (patt, name);
1878      strcat( patt, "\\*" );      strcat (patt, "\\*");
1879      hd = FindFirstFile( patt, &findbuf );          hd = FindFirstFile (patt, &findbuf);
1880      if( !hd ) {      if (!hd) {
1881          free_if_alloc( patt );            free_if_alloc (patt);
1882          return -1;                return WPTERR_GENERAL;
1883      }      }
1884      if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {      if( strcmp( findbuf.cFileName, "." ) && strcmp( findbuf.cFileName, ".." ) ) {
1885          p = make_filename( name, findbuf.cFileName, NULL );          p = make_filename( name, findbuf.cFileName, NULL );
# Line 1879  fm_encrypt_directory( fm_state_t c, cons Line 1893  fm_encrypt_directory( fm_state_t c, cons
1893              free_if_alloc( p );              free_if_alloc( p );
1894          }          }
1895      }      }
1896      s = get_filesave_dlg( c->dlg, _("Choose a Name for the Archive"),      s = get_filesave_dlg (c->dlg, _("Choose a Name for the Archive"),
1897                            NULL, default_dirname( name ) );                            NULL, default_dirname (name));
1898      if( !s ) {      if( !s ) {
1899          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );
1900          rc = -1;          rc = -1;
# Line 1899  leave: Line 1913  leave:
1913      pk_list_free( list );      pk_list_free( list );
1914      free_if_alloc( patt );      free_if_alloc( patt );
1915      return rc;      return rc;
1916  } /* fm_encrypt_directory */  }
1917    
1918    
1919  static int CALLBACK  static int CALLBACK
1920  fm_cmp_cb( LPARAM first, LPARAM second, LPARAM sortby )  fm_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
1921  {  {
1922      const char * a = 0, * b = 0;      const char *a = 0;
1923        const char *b = 0;
1924    
1925      switch( (int)sortby ) {      switch( (int)sortby ) {
1926      case FM_SORT_STAT:      case FM_SORT_STAT:
# Line 1915  fm_cmp_cb( LPARAM first, LPARAM second, Line 1930  fm_cmp_cb( LPARAM first, LPARAM second,
1930      case FM_SORT_OP:      case FM_SORT_OP:
1931          break;          break;
1932      }      }
1933      return stricmp( a, b );      return stricmp (a, b);
1934  } /* fm_cmp_cb */  }
1935                    
1936    
1937    /* Sort the list items from @lv with the mode given by @sortby. */
1938  int  int
1939  fm_sort( listview_ctrl_t lv, int sortby )  fm_sort (listview_ctrl_t lv, int sortby)
1940  {  {
1941      return listview_sort_items( lv, sortby, fm_cmp_cb );      return listview_sort_items( lv, sortby, fm_cmp_cb );
1942  } /* fm_sort */  }
1943    
1944    
1945    /* Start the 'print md' dialog. Pass over the listview control
1946       @lv and the digest algo @mdalgo. */
1947  void  void
1948  fm_print_md( listview_ctrl_t lv, HWND dlg, int mdalgo )  fm_print_md (listview_ctrl_t lv, HWND dlg, int mdalgo)
1949  {  {
1950      struct md_file_s mdctx;      struct md_file_s mdctx;
1951    
1952      if( listview_count_items( lv, 0 ) == 0 )      if (listview_count_items (lv, 0) == 0)
1953          return;          return;
1954      memset (&mdctx, 0, sizeof (mdctx));      memset (&mdctx, 0, sizeof (mdctx));
1955      mdctx.lv = lv;      mdctx.lv = lv;
1956      mdctx.mdalgo = mdalgo;      mdctx.mdalgo = mdalgo;
1957      DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_MDSUM, dlg,
1958                      mdsum_dlg_proc, (LPARAM)&mdctx );                      mdsum_dlg_proc, (LPARAM)&mdctx);
1959  } /* fm_print_md */  }
1960    
1961    
1962  /* Send the selected file in @lv via MAPI to a mail recipient. */  /* Send the selected file in @lv via MAPI to a mail recipient. */

Legend:
Removed from v.88  
changed lines
  Added in v.172

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26