/[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 48 by werner, Mon Oct 31 21:14:11 2005 UTC revision 88 by twoaday, Mon Nov 21 12:06:59 2005 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  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
25  #include <config.h>  #include <config.h>
26  #endif  #endif
27    
28  #include <sys/types.h>  #include <sys/types.h>
 #include <sys/types.h>  
29  #include <windows.h>  #include <windows.h>
30  #include <commdlg.h>  #include <commdlg.h>
31  #include <io.h>  #include <io.h>
# Line 51  Line 49 
49  #include "wptRegistry.h"  #include "wptRegistry.h"
50  #include "wptImport.h"  #include "wptImport.h"
51  #include "wptCrypto.h"  #include "wptCrypto.h"
   
52  #include "openpgp.h"  #include "openpgp.h"
53    
54  #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))  #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))
# Line 282  fm_get_file_type (const char *fname, int Line 279  fm_get_file_type (const char *fname, int
279      armor_filter_context_t afx;      armor_filter_context_t afx;
280      PACKET *pkt;      PACKET *pkt;
281      const char *s = NULL;      const char *s = NULL;
282      int i = 0, rc = 0;      int rc = 0;
283    
284        /* XXX: if the text was created with gpg --sign and armored
285                there is no way to differ between an encrypted text
286                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 296  fm_get_file_type (const char *fname, int Line 296  fm_get_file_type (const char *fname, int
296    
297      inp = gpg_iobuf_open (fname);      inp = gpg_iobuf_open (fname);
298      if (!inp) {      if (!inp) {
299          const char *s = winpt_strerror (WPTERR_FILE_OPEN);          const char *err = winpt_strerror (WPTERR_FILE_OPEN);
300          log_box (_("File Manager"), MB_ERR, "\"%s\": %s", fname, s);          log_box (_("File Manager"), MB_ERR, "\"%s\": %s", fname, err);
301          return NULL;          return NULL;
302      }      }
303      gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */      gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */
# Line 339  fm_get_file_type (const char *fname, int Line 339  fm_get_file_type (const char *fname, int
339              s = "SECKEY";   rc = -2;              s = "SECKEY";   rc = -2;
340              if (r_type) *r_type = PGP_SECKEY;              if (r_type) *r_type = PGP_SECKEY;
341              break;              break;
342    
343            default:
344                break;
345          }          }
346          gpg_free_packet (pkt);          gpg_free_packet (pkt);
347          gpg_init_packet (pkt);          gpg_init_packet (pkt);
# Line 501  int Line 504  int
504  fm_add_dropped_files (listview_ctrl_t lv, HDROP dd_files)  fm_add_dropped_files (listview_ctrl_t lv, HDROP dd_files)
505  {  {
506      char name[384+4];      char name[384+4];
507      int nfiles, rc, i;      int nfiles;
508        int rc = 0;
509        int i;
510            
511      memset (name, 0, sizeof (name));      memset (name, 0, sizeof (name));
512      nfiles = DragQueryFile (dd_files, 0xFFFFFFFF, NULL, 0);      nfiles = DragQueryFile (dd_files, 0xFFFFFFFF, NULL, 0);
# Line 625  fm_assume_onepass_sig (const char * fnam Line 630  fm_assume_onepass_sig (const char * fnam
630          gpg_free_packet (pkt);          gpg_free_packet (pkt);
631          safe_free (pkt);          safe_free (pkt);
632          gpg_iobuf_close (fp);          gpg_iobuf_close (fp);
633          unlink ("gpgme.tmp");          remove ("gpgme.tmp");
634      }      }
635      /* XXX: implement it for real files */      /* XXX: implement it for real files */
636      return check;      return check;
# Line 727  fm_check_file_type (listview_ctrl_t lv, Line 732  fm_check_file_type (listview_ctrl_t lv,
732  } /* fm_check_file_type */  } /* fm_check_file_type */
733    
734    
735    /* Set the file status of the given command @fm_cmd.
736       @success is 0 on success. */
737  static void  static void
738  fm_set_status (listview_ctrl_t lv, int pos, int fm_cmd, int success,  fm_set_status (listview_ctrl_t lv, int pos, int fm_cmd,
739                 const char * output)                 gpgme_sig_mode_t sigmode, int success, const char *output)
740  {  {
741      char status[128], operat[128];      char status[128], operat[128];
742      int update = 1;      int update = 1;
743      const char *s;      const char *s;
744    
745      if ( fm_cmd == FM_LIST )      if (fm_cmd == FM_LIST)
746          return;          return;
747      success ? s = "SUCCESS" : s = "FAILED";      success ? s = "SUCCESS" : s = "FAILED";
748      strcpy( operat, s );      strcpy (operat, s);
749    
750      switch (fm_cmd) {      switch (fm_cmd) {
751      case FM_ENCRYPT:      case FM_ENCRYPT:
752      case FM_ENCRYPT_DIR:      case FM_ENCRYPT_DIR:
753      case FM_SIGNENCRYPT: strcpy( status, "ENCRYPTED" ); break;      case FM_SIGNENCRYPT: strcpy (status, "ENCRYPTED"); break;
754      case FM_DECRYPT:     strcpy( status, "UNKNOWN" );   break;      case FM_DECRYPT:     strcpy (status, "UNKNOWN");   break;
755      case FM_SIGN:        strcpy( status, "SIGNED" );    break;      case FM_SIGN:
756            if (sigmode == GPGME_SIG_MODE_DETACH)
757                strcpy (status, "SIGNED-DETACH");
758            else
759                strcpy (status, "SIGNED");
760            break;
761      case FM_VERIFY:      update = 0;                    break;      case FM_VERIFY:      update = 0;                    break;
762      case FM_SYMENC:      strcpy( status, "SYMKEYENC" ); break;      case FM_SYMENC:      strcpy (status, "SYMKEYENC"); break;
763      case FM_IMPORT:      update = 0;                    break;      case FM_IMPORT:      update = 0;                    break;
764      case FM_WIPE:        strcpy( status, "WIPED" );     break;      case FM_WIPE:        strcpy (status, "WIPED");     break;
765      default:             strcpy( status, "UNKNOWN");    break;      default:             strcpy (status, "UNKNOWN");    break;
766      }      }
767    
768      if (success) {      if (success) {
# Line 760  fm_set_status (listview_ctrl_t lv, int p Line 772  fm_set_status (listview_ctrl_t lv, int p
772          }          }
773      }      }
774      listview_add_sub_item( lv, pos, 2, operat );      listview_add_sub_item( lv, pos, 2, operat );
775  } /* fm_set_status */  }
776    
777    
778  int  int
# Line 808  fm_parse_files (listview_ctrl_t lv, HWND Line 820  fm_parse_files (listview_ctrl_t lv, HWND
820            
821      switch (cmd) {      switch (cmd) {
822      case ID_FILEMISC_ENCRYPT: fm_cmd = FM_ENCRYPT; break;      case ID_FILEMISC_ENCRYPT: fm_cmd = FM_ENCRYPT; break;
823        case ID_FILEMISC_ENCRYPT_ZIP:fm_cmd = FM_ENCRYPT_ZIP; break;
824      case ID_FILEMISC_DECRYPT: fm_cmd = FM_DECRYPT; break;      case ID_FILEMISC_DECRYPT: fm_cmd = FM_DECRYPT; break;
825      case ID_FILEMISC_SYMENC:  fm_cmd = FM_SYMENC;  break;      case ID_FILEMISC_SYMENC:  fm_cmd = FM_SYMENC;  break;
826      case ID_FILEMISC_SIGN:    fm_cmd = FM_SIGN;    break;          case ID_FILEMISC_SIGN:    fm_cmd = FM_SIGN;    break;    
# Line 820  fm_parse_files (listview_ctrl_t lv, HWND Line 833  fm_parse_files (listview_ctrl_t lv, HWND
833      }      }
834            
835      if (fm_get_current_pos (lv) == -1)      if (fm_get_current_pos (lv) == -1)
836          return WPTERR_GENERAL;              return WPTERR_GENERAL;
837      rc = fm_state_new (&ctx);      rc = fm_state_new (&ctx);
838      if (rc)      if (rc)
839          BUG (0);          BUG (0);
# Line 841  fm_parse_files (listview_ctrl_t lv, HWND Line 854  fm_parse_files (listview_ctrl_t lv, HWND
854            
855      /* Commands we need before we can perform the main command */      /* Commands we need before we can perform the main command */
856      switch (fm_cmd) {      switch (fm_cmd) {
857        case FM_ENCRYPT_ZIP:
858      case FM_ENCRYPT:      case FM_ENCRYPT:
859      case FM_SIGNENCRYPT:      case FM_SIGNENCRYPT:
860          if (fm_cmd == FM_SIGNENCRYPT)          if (fm_cmd == FM_SIGNENCRYPT)
# Line 887  fm_parse_files (listview_ctrl_t lv, HWND Line 901  fm_parse_files (listview_ctrl_t lv, HWND
901          memset (&confirm, 0, sizeof confirm);          memset (&confirm, 0, sizeof confirm);
902          confirm.lv_files = lv;          confirm.lv_files = lv;
903          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILES_SECDEL, ctx->dlg,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_FILES_SECDEL, ctx->dlg,
904                              file_secdel_confirm_dlg_proc, (LPARAM)&confirm);                          file_secdel_confirm_dlg_proc, (LPARAM)&confirm);
905          if (!confirm.yes)          if (!confirm.yes)
906              goto leave;              goto leave;
907      }      }
908            
909      for( i = 0; i < listview_count_items( lv, 0 ); i++ ) {      if (fm_cmd == FM_ENCRYPT_ZIP)
910            fm_encrypt_into_zip (ctx, lv);
911    
912        for (i = 0; i < listview_count_items (lv, 0); i++) {
913          if( !listview_get_item_state( lv, i ) )          if( !listview_get_item_state( lv, i ) )
914              continue;              continue;
915          listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 );          listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 );
# Line 905  fm_parse_files (listview_ctrl_t lv, HWND Line 922  fm_parse_files (listview_ctrl_t lv, HWND
922          if( !fm_check_file_type( lv, i, fm_cmd ) )          if( !fm_check_file_type( lv, i, fm_cmd ) )
923              continue;              continue;
924          sig_detached = fm_check_detached_sig( lv, i );          sig_detached = fm_check_detached_sig( lv, i );
925          switch( fm_cmd ) {          switch (fm_cmd) {
926          case FM_LIST:        rc = fm_list( fname, dlg );       break;          case FM_LIST:        rc = fm_list( fname, dlg );       break;
927          case FM_WIPE:        rc = fm_wipe( fname );            break;          case FM_WIPE:        rc = fm_wipe( fname );            break;
928          case FM_ENCRYPT:     rc = fm_encrypt( ctx, fname, 0 ); break;          case FM_ENCRYPT:     rc = fm_encrypt( ctx, fname, 0 ); break;
# Line 927  fm_parse_files (listview_ctrl_t lv, HWND Line 944  fm_parse_files (listview_ctrl_t lv, HWND
944              rc = fm_import (ctx, fname);              rc = fm_import (ctx, fname);
945              break;              break;
946          }          }
947          fm_set_status (lv, i, fm_cmd, !rc, ctx->output);          fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output);
948          free_if_alloc (ctx->output);          free_if_alloc (ctx->output);
949          progress_cleanup (&pfx);          progress_cleanup (&pfx);
950      }      }
951    
952      if (fm_cmd == FM_WIPE) {      if (fm_cmd == FM_WIPE) {
953          secure_unlink_set_cb (NULL, NULL);          secure_unlink_set_cb (NULL, NULL);
954          progress_cleanup (&pfx2);          progress_cleanup (&pfx2);
# Line 943  fm_parse_files (listview_ctrl_t lv, HWND Line 961  fm_parse_files (listview_ctrl_t lv, HWND
961      /* remove wipe files from the list */      /* remove wipe files from the list */
962      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
963      while (n--) {      while (n--) {
         char status[128];  
964          listview_get_item_text (lv, n, 0, status, sizeof (status) - 1);          listview_get_item_text (lv, n, 0, status, sizeof (status) - 1);
965          if( !strcmp (status, "WIPED"))          if (!strcmp (status, "WIPED"))
966              listview_del_item (lv, n);              listview_del_item (lv, n);
967      }      }
968            
# Line 989  ask_filename (fm_state_t c, const char * Line 1006  ask_filename (fm_state_t c, const char *
1006  {  {
1007      const char * s;      const char * s;
1008    
1009      s = get_filename_dlg (c->dlg, FILE_SAVE, msg, NULL, NULL);      s = get_filesave_dlg (c->dlg, msg, NULL, NULL);
1010      if (!s)      if (!s)
1011          return WPTERR_GENERAL;          return WPTERR_GENERAL;
1012    
# Line 1013  fm_encrypt (fm_state_t c, const char *na Line 1030  fm_encrypt (fm_state_t c, const char *na
1030      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1031      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1032      char *keyid = NULL, ext[5];      char *keyid = NULL, ext[5];
1033      int no_compr = 0;      /*int no_compr = 0;*/
1034      int rc = 0;      int rc = 0;
1035    
1036      c->output = new char[strlen (name) + 5 + 1];      c->output = new char[strlen (name) + 5 + 1];
# Line 1062  fm_encrypt (fm_state_t c, const char *na Line 1079  fm_encrypt (fm_state_t c, const char *na
1079              gpgme_signers_add (ctx, key);              gpgme_signers_add (ctx, key);
1080          }          }
1081          else {          else {
1082              gpgme_key_t key = gpgme_signers_enum (ctx, 0);              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);
1083              if (key && key->subkeys) {              if (sigkey && sigkey->subkeys) {
1084                  keyid = m_strdup (key->subkeys->keyid);                  keyid = m_strdup (sigkey->subkeys->keyid);
1085                  if (!keyid)                  if (!keyid)
1086                      BUG (NULL);                      BUG (NULL);
1087              }              }
# Line 1103  fm_encrypt (fm_state_t c, const char *na Line 1120  fm_encrypt (fm_state_t c, const char *na
1120              goto leave;              goto leave;
1121          }          }
1122      }      }
     if (c->wipe)  
         secure_unlink (name, WIPE_MODE_SIMPLE);  
1123            
1124  leave:  leave:
1125      if (in)      if (in)
# Line 1112  leave: Line 1127  leave:
1127      if (out)      if (out)
1128          gpg_file_data_release (out);          gpg_file_data_release (out);
1129      free_if_alloc (keyid);      free_if_alloc (keyid);
1130        if (!rc && c->wipe)
1131            secure_unlink (name, WIPE_MODE_SIMPLE);
1132      return rc;      return rc;
1133  }  }
1134    
# Line 1123  fm_sym_encrypt (fm_state_t c, const char Line 1140  fm_sym_encrypt (fm_state_t c, const char
1140      gpgme_error_t err;          gpgme_error_t err;    
1141      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1142      int rc = 0, cancel = 0;      int rc = 0, cancel = 0;
     char * src = NULL, * dst = NULL;  
1143      char ext[5], * pass;          char ext[5], * pass;    
1144            
1145      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);
# Line 1234  fm_decrypt (fm_state_t c, const char *na Line 1250  fm_decrypt (fm_state_t c, const char *na
1250      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res;
1251      gpgme_verify_result_t sigres;      gpgme_verify_result_t sigres;
1252      file_data_t in =NULL, out=NULL;      file_data_t in =NULL, out=NULL;
     int is_signed = 0;  
1253      int rc = 0;      int rc = 0;
1254            
1255      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
# Line 1387  fm_add_sig_stat (file_sig_ctx_t log) Line 1402  fm_add_sig_stat (file_sig_ctx_t log)
1402  {  {
1403      gpgme_key_t key;          gpgme_key_t key;    
1404      const char *kid;      const char *kid;
     int not_found = 0;  
1405    
1406      kid = log->sig->fpr;      kid = log->sig->fpr;
1407      if (!kid)      if (!kid)
# Line 1434  verify_pasted (listview_ctrl_t lv, fm_st Line 1448  verify_pasted (listview_ctrl_t lv, fm_st
1448      }      }
1449      fm_verify (ctx, 1, fname);      fm_verify (ctx, 1, fname);
1450      if (del_end)      if (del_end)
1451          unlink (fname);          remove (fname);
1452      free_if_alloc (fname);      free_if_alloc (fname);
1453      return 0;      return 0;
1454  }  }
# Line 1640  leave: Line 1654  leave:
1654  int  int
1655  fm_export (fm_state_t c)  fm_export (fm_state_t c)
1656  {  {
1657      int rc = 0, id = 0;      int rc = 0;
1658      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1659      gpgme_error_t err;      gpgme_error_t err;
1660      gpgme_key_t *rset = c->recp;      gpgme_key_t *rset = c->recp;
# Line 1664  fm_export (fm_state_t c) Line 1678  fm_export (fm_state_t c)
1678          strcat (p, ".asc");          strcat (p, ".asc");
1679      }      }
1680    
1681      name = get_filename_dlg (c->dlg, FILE_SAVE, _("Choose Name for Key File"),      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),
1682                               NULL, p? p : NULL);                               NULL, p? p : NULL);
1683                                                            
1684      if (!name)      if (!name)
# Line 1753  fm_parse_command_line (char *cmdl) Line 1767  fm_parse_command_line (char *cmdl)
1767                  detached = 1;                  detached = 1;
1768              fm_verify (ctx, detached, fn);              fm_verify (ctx, detached, fn);
1769              file_verify_wait ();              file_verify_wait ();
1770              break;              break;
1771    
1772            default:
1773                break;
1774          }          }
1775      }      }
1776    
# Line 1774  default_dirname (const char *name) Line 1791  default_dirname (const char *name)
1791  } /* default_dirname */  } /* default_dirname */
1792    
1793    
1794    /* Store all selected files from @lv in a zip archive
1795       and encrypt the zip archive then.
1796       Return value: 0 on success. */
1797    int
1798    fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)
1799    {
1800        PK_FILE_LIST list=NULL;
1801        const char *outfile;
1802        char *out_enc;
1803        int nitems = listview_count_items (lv, 0);
1804        int i, idx = -1;
1805        int rc;
1806    
1807        if (!nitems) {
1808            msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"),
1809                     _("File Manager"), MB_ERR);
1810            return -1;
1811        }
1812    
1813        outfile = get_filesave_dlg (NULL, _("Choose File Name for Output"),
1814                                    NULL, "encrypted_files.zip");
1815        if (!outfile)
1816            return -1;
1817    
1818        for (i=0; i < nitems; i++) {
1819            char name[300];
1820            if (!listview_get_item_state (lv, i))
1821                continue;
1822            if (idx == -1)
1823                idx = i;
1824            listview_get_item_text (lv, i, 1, name, sizeof (name)-1);
1825            pk_list_add (&list, name);
1826        }    
1827    
1828        pk_archiv_create (list, outfile);
1829        pk_list_free (list);
1830    
1831        rc = fm_encrypt (ctx, outfile, 0);
1832        DeleteFile (outfile);
1833        if (rc)
1834            return rc;
1835    
1836        out_enc = make_filename (NULL, outfile, "gpg");
1837        fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc);
1838        free_if_alloc (out_enc);
1839    
1840        for (i=0; i < nitems; i++) {
1841            if (i != idx && listview_get_item_state (lv, i))
1842                listview_del_item (lv, i);
1843        }
1844        return 0;
1845    }
1846    
1847    
1848  int  int
1849  fm_encrypt_directory( fm_state_t c, const char * name )  fm_encrypt_directory( fm_state_t c, const char * name )
1850  {  {
# Line 1808  fm_encrypt_directory( fm_state_t c, cons Line 1879  fm_encrypt_directory( fm_state_t c, cons
1879              free_if_alloc( p );              free_if_alloc( p );
1880          }          }
1881      }      }
1882      s = get_filename_dlg( c->dlg, FILE_SAVE, _("Choose a Name for the Archive"),      s = get_filesave_dlg( c->dlg, _("Choose a Name for the Archive"),
1883                            NULL, default_dirname( name ) );                            NULL, default_dirname( name ) );
1884      if( !s ) {      if( !s ) {
1885          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );          msg_box( c->dlg, _("Invalid archive name. Exit."), _("Encrypt Directory"), MB_ERR );
# Line 1821  fm_encrypt_directory( fm_state_t c, cons Line 1892  fm_encrypt_directory( fm_state_t c, cons
1892          msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR );          msg_box( c->dlg, _("Could not create zip archive."), _("Encrypt Directory"), MB_ERR );
1893      else {      else {
1894          fm_encrypt( c, s, 0 );          fm_encrypt( c, s, 0 );
1895          unlink( s );          remove( s );
1896      }      }
1897  leave:  leave:
1898      FindClose (hd);      FindClose (hd);
# Line 1870  fm_print_md( listview_ctrl_t lv, HWND dl Line 1941  fm_print_md( listview_ctrl_t lv, HWND dl
1941  } /* fm_print_md */  } /* fm_print_md */
1942    
1943    
1944    /* Send the selected file in @lv via MAPI to a mail recipient. */
1945  int  int
1946  fm_send_file (listview_ctrl_t lv)  fm_send_file (listview_ctrl_t lv)
1947  {  {
# Line 1877  fm_send_file (listview_ctrl_t lv) Line 1949  fm_send_file (listview_ctrl_t lv)
1949      int rc;      int rc;
1950    
1951      rc = listview_get_item_text (lv, -1, 1, buf, sizeof (buf)-1);      rc = listview_get_item_text (lv, -1, 1, buf, sizeof (buf)-1);
1952      if (rc == -1)      if (rc != -1)
1953          return 0;          mapi_send_ascfile (buf);
     /*mapi_send_ascfile (buf); XXX */  
1954      return 0;      return 0;
1955  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26