/[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 172 by twoaday, Mon Jan 30 13:47:35 2006 UTC revision 220 by twoaday, Tue May 30 15:31:49 2006 UTC
# Line 1  Line 1 
1  /* wptFileManager.cpp - File Manager routines  /* wptFileManager.cpp - File Manager routines
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 18  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
 /* TODO:  
  *    check_armor_type: we should check the whole file and not only the first line!  
  */  
21    
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
# Line 53  Line 50 
50  #include "wptKeyManager.h"  #include "wptKeyManager.h"
51  #include "openpgp.h"  #include "openpgp.h"
52    
 #define op_begin()  SetCursor (LoadCursor (NULL, IDC_WAIT))  
 #define op_end()    SetCursor (LoadCursor (NULL, IDC_ARROW))  
53    
54  void progress_cleanup (progress_filter_s *pfx);  void progress_cleanup (progress_filter_s *pfx);
55  BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg,  BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg,
# Line 62  BOOL CALLBACK file_secdel_confirm_dlg_pr Line 57  BOOL CALLBACK file_secdel_confirm_dlg_pr
57  char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n);  char* gpg_keylist_to_pattern (gpgme_key_t *rset, int n);
58  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,
59                                   int prev_was_bad, int fd);                                   int prev_was_bad, int fd);
60    void verify_show_signature_state (gpgme_signature_t sig);
61    
62    
63  /*-- wptFileVerifyDlg.cpp --*/  /* Symbolic column IDs. */
64  void file_verify_add_state (file_sig_ctx_t c);  enum {
65  void file_verify_use_event (void);      FM_COL_STAT = 0,
66  void file_verify_wait (void);      FM_COL_NAME = 1,
67        FM_COL_OP   = 2
68    };
69    
70  static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",  static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",
71                                    ".mp3", ".wav", ".mid", ".wma",                                    ".mp3", ".wav", ".mid", ".wma",
72                                    ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};                                    ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};
73    
# Line 117  overwrite_file (const char *fname) Line 116  overwrite_file (const char *fname)
116  void  void
117  remove_crit_file_attrs (const char *fname, int force)  remove_crit_file_attrs (const char *fname, int force)
118  {  {
119      u32 fattr;      DWORD fattr;
120      int id = 0;      int id = 0;
121    
122      if (file_exist_check (fname))      if (file_exist_check (fname))
# Line 146  is_directory (const char *fname) Line 145  is_directory (const char *fname)
145  }  }
146    
147    
148  /* Return -1 if the given name @name is a valid PGP extension. */  /* Return -1 if the given name @name is a valid GPG extension. */
149  static 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") || stristr (name, ".asc")
# Line 202  file_get_extension (gpgme_ctx_t ctx, gpg Line 201  file_get_extension (gpgme_ctx_t ctx, gpg
201          return ".asc";          return ".asc";
202      if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH)      if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH)
203          return ".sig";          return ".sig";
204      return ".gpg";      return reg_prefs.default_ext == 1? ".pgp" : ".gpg";
205  }  }
206    
207    
# Line 227  fm_quote_file (const char * name) Line 226  fm_quote_file (const char * name)
226    
227  /* Check the armor type of the file @fname and return  /* Check the armor type of the file @fname and return
228     a string representation of it. */     a string representation of it. */
229  static const char *  static const char*
230  fm_check_armor_type (const char *fname, int *r_type)  fm_check_armor_type (const char *fname, int *r_type)
231  {  {
232      FILE * fp;      FILE *fp;
233      char header[768], * p;      char header[768], *p;
234            
235      if (r_type)      if (r_type)
236          *r_type = PGP_NONE;          *r_type = PGP_NONE;
# Line 377  fm_get_file_type (const char *fname, int Line 376  fm_get_file_type (const char *fname, int
376  int  int
377  fm_build (listview_ctrl_t *lv, HWND ctrl)  fm_build (listview_ctrl_t *lv, HWND ctrl)
378  {  {
379      int i, rc = 0;      int i;
380      listview_ctrl_t c;      listview_ctrl_t c;
381      struct listview_column_s col[] = {      struct listview_column_s col[] = {
382          {0,  80, (char *)_("Status") },          {0,  80, (char *)_("Status") },
383          {1, 256, (char *)_("Name") },          {1, 256, (char *)_("Name") },
384          {2, 128, (char *)_("Operation") },          {2, 128, (char *)_("Operation") },
385          {0,   0, NULL }          {0,   0, NULL}  
386      };      };
387                    
388      rc = listview_new (&c);      listview_new (&c, ctrl);
     if (rc)  
         BUG (NULL);  
     c->ctrl = ctrl;  
389      for (i = 0; col[i].width; i++)      for (i = 0; col[i].width; i++)
390          listview_add_column (c, &col[i]);          listview_add_column (c, &col[i]);
391      listview_set_ext_style (c);      listview_set_ext_style (c);
# Line 412  fm_delete (listview_ctrl_t lv) Line 408  fm_delete (listview_ctrl_t lv)
408  int  int
409  fm_state_new (fm_state_t * ctx)  fm_state_new (fm_state_t * ctx)
410  {  {
411      gpgme_error_t rc;      fm_state_s *c;
     fm_state_s * c;  
412    
413      c = new fm_state_s;      c = new fm_state_s;
414      if (!c)      if (!c)
415          BUG (0);          BUG (0);
416      memset (c, 0, sizeof *c);      memset (c, 0, sizeof *c);
417      rc = gpgme_new (&c->ctx);      if (gpgme_new (&c->ctx))
     if (rc)  
418          BUG (0);          BUG (0);
     /* XXX rc = gpgme_recipients_new (&c->recp);*/  
     /* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */  
419      *ctx = c;      *ctx = c;
420      return 0;      return 0;
421  } /* fm_state_new */  }
422    
423    
424  /* Release the FM state handle @c. */  /* Release the FM state handle @c. */
# Line 442  fm_state_release (fm_state_t c) Line 434  fm_state_release (fm_state_t c)
434      safe_free (c->recp);      safe_free (c->recp);
435      free_if_alloc (c->opaque);      free_if_alloc (c->opaque);
436      free_if_alloc (c->output);      free_if_alloc (c->output);
437      delete c; c = NULL;          delete c;
438  }  }
439    
440    
441  static int  static int
442  fm_check_for_entry( listview_ctrl_t lv, const char *file )  fm_check_for_entry( listview_ctrl_t lv, const char *file )
443  {  {
# Line 459  fm_check_for_entry( listview_ctrl_t lv, Line 452  fm_check_for_entry( listview_ctrl_t lv,
452      }      }
453    
454      return 0;      return 0;
455  } /* fm_check_for_entry */  }
456    
457    
458  static int  static int
# Line 483  fm_set_ftype (listview_ctrl_t lv, const Line 476  fm_set_ftype (listview_ctrl_t lv, const
476  }  }
477    
478    
479    /* Add all files from the directory @path to the list view @lv. */
480  static int  static int
481  fm_add_dir_files (listview_ctrl_t lv, char *path)  fm_add_dir_files (listview_ctrl_t lv, char *path)
482  {  {
# Line 547  add_single_file (listview_ctrl_t lv, con Line 541  add_single_file (listview_ctrl_t lv, con
541      if (!type)      if (!type)
542          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
543      if (!strcmp (type, "UNKNOWN"))            if (!strcmp (type, "UNKNOWN"))      
544          type = gnupg_check_file_ext (name, NULL);                    type = gnupg_check_file_ext (name, NULL);
545      rc = listview_add_item (lv, "");              rc = listview_add_item (lv, "");
546      if (!rc) {        if (!rc) {
547          listview_add_sub_item (lv, 0, 0, type);          listview_add_sub_item (lv, 0, 0, type);
548          listview_add_sub_item (lv, 0, 1, name);          listview_add_sub_item (lv, 0, 1, name);
549      }      }
# Line 601  fm_add_opened_files (listview_ctrl_t lv, Line 595  fm_add_opened_files (listview_ctrl_t lv,
595          else {          else {
596              char *p = make_filename (path, name, NULL);              char *p = make_filename (path, name, NULL);
597              rc = add_single_file (lv, p);              rc = add_single_file (lv, p);
598              free (p);              safe_free (p);
599          }          }
600          n++;          n++;
601      }      }
602      if (n == 1) /* single file selected. */      if (n == 1) /* single file selected. */
603          rc = add_single_file (lv, path);          rc = add_single_file (lv, path);
604      if (path)      safe_free (path);
         free (path);  
605      return rc;      return rc;
606  }  }
607    
608    
609  int  int
610  fm_assume_onepass_sig (const char * fname)  fm_assume_onepass_sig (const char *fname)
611  {  {    
     gpgme_data_t dat;  
612      armor_filter_context_t afx;      armor_filter_context_t afx;
613      gpg_iobuf_t fp;      gpg_iobuf_t fp;
614      PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt);      gpgme_data_t dat;
615        PACKET *pkt;
616        char tmpfile[MAX_PATH+1];
617      int check = 0;      int check = 0;
618    
619        pkt = (PACKET *)calloc (1, sizeof *pkt);
620      if (!fname) {      if (!fname) {
621            get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp");
622          gpg_data_new_from_clipboard (&dat, 0);          gpg_data_new_from_clipboard (&dat, 0);
623          gpg_data_release_and_set_file (dat, "gpgme.tmp");          gpg_data_release_and_set_file (dat, tmpfile);
624    
625          fp = gpg_iobuf_open ("gpgme.tmp");          fp = gpg_iobuf_open (tmpfile);
626          if (!fp)          if (!fp)
627              return 0;              return 0;
628          gpg_iobuf_ioctl (fp, 3, 1, NULL);          gpg_iobuf_ioctl (fp, 3, 1, NULL);
# Line 639  fm_assume_onepass_sig (const char * fnam Line 635  fm_assume_onepass_sig (const char * fnam
635              && pkt->pkttype == PKT_COMPRESSED)              && pkt->pkttype == PKT_COMPRESSED)
636              check = 1;                check = 1;  
637          gpg_free_packet (pkt);          gpg_free_packet (pkt);
         safe_free (pkt);  
638          gpg_iobuf_close (fp);          gpg_iobuf_close (fp);
639          remove ("gpgme.tmp");          remove (tmpfile);
640      }      }
641      /* XXX: implement it for real files */      /* XXX: implement it for real files */
642        safe_free (pkt);
643      return check;      return check;
644  }  }
645    
# Line 656  fm_get_current_pos (listview_ctrl_t lv) Line 652  fm_get_current_pos (listview_ctrl_t lv)
652      items = listview_count_items (lv, 0);      items = listview_count_items (lv, 0);
653      if (!items)      if (!items)
654          return -1;          return -1;
655      else if (items == 1)      else if (items == 1) {
     {  
656          listview_select_one (lv, 0);          listview_select_one (lv, 0);
657          return 0;          return 0;
658      }      }
659      else if (items > 1)      else if (items > 1) {
     {  
660          i = listview_get_curr_pos (lv);          i = listview_get_curr_pos (lv);
661          if (i == -1)          if (i == -1) {
662          {              msg_box (lv->ctrl, _("Please select a file."),
663              msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR);                       _("File Manager"), MB_ERR);
664              return -1;              return -1;
665          }          }
666          return i;          return i;
667      }      }
668    
669      return -1;      return -1;
670  } /* fm_get_current_pos */  }
671    
672    
673  static int  static int
674  fm_check_detached_sig( listview_ctrl_t lv, int pos )  fm_check_detached_sig (listview_ctrl_t lv, int pos)
675  {  {
676      char type[128];      char type[128];
677    
678      listview_get_item_text( lv, pos, 0, type, 127 );      listview_get_item_text (lv, pos, 0, type, sizeof (type)-1);
679      return !strcmp( type, "SIGNED-DETACH" )? 1 : 0;      return !strcmp (type, "SIGNED-DETACH")? 1 : 0;
680  } /* fm_check_detached_sig */  }
681    
682    
683  int  int
# Line 740  fm_check_file_type (listview_ctrl_t lv, Line 734  fm_check_file_type (listview_ctrl_t lv,
734      }      }
735            
736      return rc;      return rc;
737  } /* fm_check_file_type */  }
738    
739    
740  /* Set the file status of the given command @fm_cmd.  /* Set the file status of the given command @fm_cmd.
# Line 811  fm_clearsign_8bit (listview_ctrl_t lv, f Line 805  fm_clearsign_8bit (listview_ctrl_t lv, f
805      if (!cnt)      if (!cnt)
806          return 0;          return 0;
807      n = -1;      n = -1;
808      i = log_box (_("File Manager"), MB_WARN|MB_YESNO,      i = log_box (_("File Manager"), MB_WARN|MB_YESNO,
809                   _("\"%s\" does not seems to be a text file.\n"                   _("\"%s\" does not seems to be a text file.\n"
810                     "Do you really want to clearsign it?"), name);                     "Do you really want to clearsign it?"), name);
811      if (i == IDYES)      if (i == IDYES)
# Line 819  fm_clearsign_8bit (listview_ctrl_t lv, f Line 813  fm_clearsign_8bit (listview_ctrl_t lv, f
813      return n;      return n;
814  }  }
815    
816    
817  int  int
818  fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd)  fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd)
819  {  {
# Line 921  fm_parse_files (listview_ctrl_t lv, HWND Line 916  fm_parse_files (listview_ctrl_t lv, HWND
916          fm_encrypt_into_zip (ctx, lv);          fm_encrypt_into_zip (ctx, lv);
917    
918      for (i = 0; i < listview_count_items (lv, 0); i++) {      for (i = 0; i < listview_count_items (lv, 0); i++) {
919          if( !listview_get_item_state( lv, i ) )          if (!listview_get_item_state (lv, i))
920              continue;              continue;
921          listview_get_item_text(lv, i, 1, fname, sizeof (fname) - 1);          listview_get_item_text (lv, i, 1, fname, sizeof (fname) - 1);
922          if( file_exist_check (fname) && !is_directory (fname)) {          if( file_exist_check (fname) && !is_directory (fname)) {
923              log_box (_("File Manager"), MB_ERR,              log_box (_("File Manager"), MB_ERR,
924                       _("\"%s\" does not exist"), fname);                       _("\"%s\" does not exist"), fname);
# Line 942  fm_parse_files (listview_ctrl_t lv, HWND Line 937  fm_parse_files (listview_ctrl_t lv, HWND
937          case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break;          case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break;
938          case FM_DECRYPT:     rc = fm_decrypt( ctx, fname );    break;          case FM_DECRYPT:     rc = fm_decrypt( ctx, fname );    break;
939          case FM_SIGN:        rc = fm_sign( ctx, fname );       break;          case FM_SIGN:        rc = fm_sign( ctx, fname );       break;
940          case FM_SYMENC:      rc = fm_sym_encrypt( ctx, fname );break;          case FM_SYMENC:      rc = fm_sym_encrypt (ctx, fname); break;
941          case FM_VERIFY:      rc = fm_verify (ctx, sig_detached, fname);break;          case FM_VERIFY:      rc = fm_verify (ctx, sig_detached, fname);break;
942          case FM_IMPORT:          case FM_IMPORT:
943              free_if_alloc (ctx->opaque);              free_if_alloc (ctx->opaque);
944              ctx->opaque = m_strdup (fname);              ctx->opaque = m_strdup (fname);
945              if (!ctx->opaque)              DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg,
946                  BUG (0);                              file_import_dlg_proc, (LPARAM)ctx);
             DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg,  
                            file_import_dlg_proc, (LPARAM)ctx );  
947              if (ctx->cancel == 1)              if (ctx->cancel == 1)
948                  continue;                  continue;
949              rc = fm_import (ctx, fname);              rc = fm_import (ctx, fname);
950              break;              break;
951          }          }
952            if (ctx->cancel == 1) {
953                ctx->cancel = 0;
954                continue;
955            }
956          fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output);          fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output);
957          free_if_alloc (ctx->output);          free_if_alloc (ctx->output);
958          progress_cleanup (&pfx);          progress_cleanup (&pfx);
# Line 1026  ask_filename (fm_state_t c, const char * Line 1023  ask_filename (fm_state_t c, const char *
1023          free_if_alloc (*dst);          free_if_alloc (*dst);
1024      free_if_alloc (c->output);      free_if_alloc (c->output);
1025      c->output = m_strdup (s);      c->output = m_strdup (s);
     if (!c->output)  
         BUG (0);  
1026      if (dst)      if (dst)
1027          *dst = fm_quote_file (s);          *dst = fm_quote_file (s);
1028      return 0;      return 0;
# Line 1095  fm_encrypt (fm_state_t c, const char *na Line 1090  fm_encrypt (fm_state_t c, const char *na
1090              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);
1091              if (sigkey && sigkey->subkeys) {              if (sigkey && sigkey->subkeys) {
1092                  keyid = m_strdup (sigkey->subkeys->keyid);                  keyid = m_strdup (sigkey->subkeys->keyid);
                 if (!keyid)  
                     BUG (NULL);  
1093              }              }
1094          }          }
1095          if (!c->init_cb || !c->cache_cb) {          if (!c->init_cb || !c->cache_cb) {
# Line 1156  fm_sym_encrypt (fm_state_t c, const char Line 1149  fm_sym_encrypt (fm_state_t c, const char
1149      char ext[5], * pass;          char ext[5], * pass;    
1150            
1151      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);      pass = request_passphrase2 (_("Symmetric"), 0, &cancel);
1152      if (cancel)      if (cancel) {
1153            c->cancel = 1;
1154          return 0;          return 0;
1155        }
1156            
1157      /* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/      /* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/
1158      c->output = new char[strlen (name) + 5 + 1];      c->output = new char[strlen (name) + 5 + 1];
# Line 1205  leave: Line 1200  leave:
1200  }  }
1201    
1202    
 /* Show the human readable verify result from @sigres. */  
 static void  
 show_verify_result (gpgme_verify_result_t sigres)  
 {  
     gpgme_key_t key=NULL;  
     gpgme_signature_t sig=sigres->signatures;  
     const char *s, *keyid;  
     int sigok = 0;  
     int type;  
     char buf[384];  
   
     sig = sigres->signatures;  
     sigok = sig->summary & GPGME_SIGSUM_GREEN;  
     s = sigok? _("Good signature") : _("BAD signature");  
     type = sigok? MB_OK: MB_ICONWARNING|MB_OK;  
     keyid = sig->fpr;  
     if (!keyid)  
         return;  
   
     keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;  
     get_pubkey (sig->fpr, &key);  
     _snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n"  
                                     "%s from \"%s\""),  
                 strtimestamp (sig->timestamp),  
                 get_key_pubalgo (sig->pubkey_algo),  
                 keyid, s, key? key->uids->uid : _("user ID not found"));  
     msg_box (NULL, buf, _("Decrypt Verify"), type);  
 }  
   
   
1203  /* Check the recipients if we have at least one secret key. */  /* Check the recipients if we have at least one secret key. */
1204  bool  bool
1205  secret_key_available (gpgme_recipient_t rset)  is_seckey_available (gpgme_recipient_t rset)
1206  {  {
1207      gpgme_recipient_t r;      gpgme_recipient_t r;
1208      gpgme_key_t key;      winpt_key_s key;
1209    
1210      for (r=rset; r; r = r->next) {      for (r=rset; r; r = r->next) {
1211          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)
1212              continue;              continue;
1213          else {          else {
1214                memset (&key, 0, sizeof (key));
1215              /* extra check to make sure the key is available right now. */              /* extra check to make sure the key is available right now. */
1216              if (!get_seckey (r->keyid, &key))              if (!winpt_get_seckey (r->keyid, &key)) {
1217                    winpt_release_pubkey (&key);
1218                  return true;                  return true;
1219                }
1220                winpt_release_pubkey (&key);
1221          }          }
1222      }      }
1223      return false;      return false;
1224  }  }
1225    
1226    
1227    /* If the decrypt result contains the original file name,
1228       we use it instead of the artificial "output - .gpg" string. */
1229    static int
1230    restore_original_name (const char *output, const char *file_name)
1231    {
1232        char *dir;
1233        char *orig;
1234        int rc = 0;
1235    
1236        dir = strrchr (output, '\\');
1237        if (!dir)
1238            orig = strdup (file_name);
1239        else {
1240            orig = (char*)calloc (1, strlen (file_name)+ 1 +
1241                                     strlen (output)+1);
1242            if (!orig)
1243                BUG (0);
1244            memcpy (orig, output, (dir-output)+1);
1245            strcat (orig, file_name);
1246        }
1247        /* XXX: we need to find out if the string needs to be utf8 decoded. */
1248        if (overwrite_file (orig)) {
1249            DeleteFile (orig);
1250            if (!MoveFile (output, orig))
1251                rc = -1;
1252        }
1253        safe_free (orig);
1254        return rc;
1255    }
1256    
1257    
1258  /* Decrypt the file @name. */  /* Decrypt the file @name. */
1259  int  int
1260  fm_decrypt (fm_state_t c, const char *name)  fm_decrypt (fm_state_t c, const char *name)
# Line 1263  fm_decrypt (fm_state_t c, const char *na Line 1263  fm_decrypt (fm_state_t c, const char *na
1263      gpgme_ctx_t ctx = c->ctx;          gpgme_ctx_t ctx = c->ctx;    
1264      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res;
1265      gpgme_verify_result_t sigres;      gpgme_verify_result_t sigres;
1266      file_data_t in =NULL, out=NULL;      file_data_t in = NULL, out = NULL;
1267      int rc = 0;      int rc = 0;
1268            
1269      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
# Line 1273  fm_decrypt (fm_state_t c, const char *na Line 1273  fm_decrypt (fm_state_t c, const char *na
1273      }      }
1274            
1275      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (0);  
1276      if (is_openpgp_ext (c->output))      if (is_openpgp_ext (c->output))
1277          c->output[strlen (c->output)-4] = '\0';          c->output[strlen (c->output)-4] = '\0';
1278      else {      else {
# Line 1284  fm_decrypt (fm_state_t c, const char *na Line 1282  fm_decrypt (fm_state_t c, const char *na
1282          if (s) {          if (s) {
1283              free_if_alloc (c->output);              free_if_alloc (c->output);
1284              c->output = m_strdup (s);              c->output = m_strdup (s);
             if (!c->output)  
                 BUG (NULL);  
1285          }          }
1286      }      }
1287    
# Line 1295  fm_decrypt (fm_state_t c, const char *na Line 1291  fm_decrypt (fm_state_t c, const char *na
1291              goto leave;              goto leave;
1292      }      }
1293    
1294        /* we fetch all recipients here to make sure they list is complete. */
1295        release_gpg_recipients (&c->pass_cb.recipients);
1296        gpg_get_recipients (name, &c->pass_cb.recipients);
1297    
1298      err = gpg_file_data_new (name, F_DATA_READ, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1299      if (err)      if (err)
1300          goto leave;          goto leave;
# Line 1302  fm_decrypt (fm_state_t c, const char *na Line 1302  fm_decrypt (fm_state_t c, const char *na
1302      err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);      err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1303      if (err)      if (err)
1304          goto leave;          goto leave;
1305        
1306      op_begin ();      op_begin ();
1307      err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat);      err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat);
1308      op_end ();      op_end ();
# Line 1314  fm_decrypt (fm_state_t c, const char *na Line 1314  fm_decrypt (fm_state_t c, const char *na
1314      }      }
1315    
1316      res = gpgme_op_decrypt_result (ctx);      res = gpgme_op_decrypt_result (ctx);
1317      if (res && res->recipients && !secret_key_available (res->recipients)) {      if (res && res->recipients && !is_seckey_available (res->recipients)) {
1318          const char *keyid = res->recipients->keyid;          const char *keyid = res->recipients->keyid;
1319          char *p = get_key_userid (keyid+8);          char *p = get_key_userid (keyid+8);
1320          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;
1321                    
1322          log_box( _("Decryption"), MB_ERR,          log_box (_("Decryption"), MB_ERR,
1323                   _("Encrypted with %s key, ID %s.%s\n"                   _("Encrypted with %s key, ID %s.%s\n"
1324                     "Decryption failed: secret key not available."),                     "Decryption failed: secret key not available."),
1325                     get_key_pubalgo (pkalgo), keyid+8, p);                     get_key_pubalgo (pkalgo), keyid+8, p);
# Line 1336  fm_decrypt (fm_state_t c, const char *na Line 1336  fm_decrypt (fm_state_t c, const char *na
1336          log_box ("Decrypt", MB_ERR,          log_box ("Decrypt", MB_ERR,
1337                   _("Decryption failed.\n%s: does not exist."), c->output);                   _("Decryption failed.\n%s: does not exist."), c->output);
1338          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1339            goto leave;
1340        }
1341        else if (res && res->file_name) {
1342            char *file;
1343            int id = IDNO;
1344    
1345            file = strrchr (c->output, '\\');
1346            if (!file)
1347                file = c->output;
1348            else
1349                file++;
1350            if (strcmp (res->file_name, file))
1351                id = log_box (_("Decrypt"), MB_QUEST_ASK,
1352                              _("The original file name is '%s'.\n\n"
1353                                "Do you want to use this instead of '%s'?"),
1354                          res->file_name, file);
1355            if (id == IDYES) {
1356                /* before we can move the file, it needs to be closed first. */
1357                gpg_file_data_release (out);
1358                out = NULL;
1359                restore_original_name (c->output, res->file_name);
1360            }
1361      }      }
       
1362      sigres = gpgme_op_verify_result (ctx);      sigres = gpgme_op_verify_result (ctx);
1363      if (sigres && sigres->signatures)      if (sigres && sigres->signatures)
1364          show_verify_result (sigres);          verify_show_signature_state (sigres->signatures);
1365            
1366  leave:  leave:
1367      if (in)      if (in)
# Line 1416  leave: Line 1437  leave:
1437  static void  static void
1438  fm_add_sig_stat (file_sig_ctx_t log)  fm_add_sig_stat (file_sig_ctx_t log)
1439  {  {
1440      gpgme_key_t key;          struct winpt_key_s key;
1441      const char *kid;      const char *kid;
1442    
1443      kid = log->sig->fpr;      memset (&key, 0, sizeof (key));
1444      if (!kid)      kid = get_keyid_from_fpr (log->sig->fpr);
1445          BUG (NULL);      log->use_uid = 0;
1446      if (strlen (kid) == 40)      if (!winpt_get_pubkey (kid, &key)) {
1447          kid += 32;                log->user_id = key.ext->uids->uid;
     else if (strlen (kid) == 32)  
         kid += 24;  
     if (get_pubkey (kid, &key))  
         log->use_uid = 0;  
     else {  
         log->user_id = key->uids->uid;  
1448          log->use_uid = 1;          log->use_uid = 1;
1449      }      }
1450        winpt_release_pubkey (&key);
1451      file_verify_add_state (log);      file_verify_add_state (log);
1452  }  }
1453    
# Line 1521  get_output_file (fm_state_t c, const cha Line 1537  get_output_file (fm_state_t c, const cha
1537      else      else
1538          title = _("Selected Output File");          title = _("Selected Output File");
1539    
1540      if (strstr (name, ".sig")      if (stristr (name, ".sig") ||
1541          || strstr (name, ".asc")          stristr (name, ".asc") ||
1542          || strstr (name, ".gpg")) {          stristr (name, ".gpg") ||
1543            stristr (name, ".pgp")) {
1544          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1545          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1546          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1545  get_output_file (fm_state_t c, const cha Line 1562  get_output_file (fm_state_t c, const cha
1562      if (file) {          if (file) {    
1563          free_if_alloc (c->output);              free_if_alloc (c->output);    
1564          c->output = m_strdup (file);          c->output = m_strdup (file);
         if (!c->output)  
             BUG (NULL);  
1565      }      }
1566      else {      else {
1567          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);
# Line 1555  get_output_file (fm_state_t c, const cha Line 1570  get_output_file (fm_state_t c, const cha
1570      if (detached)      if (detached)
1571          c->sigmode = GPGME_SIG_MODE_DETACH;          c->sigmode = GPGME_SIG_MODE_DETACH;
1572      else {      else {
1573          if (strstr (name, ".asc"))          if (stristr (name, ".asc"))
1574              c->sigmode = GPGME_SIG_MODE_CLEAR;              c->sigmode = GPGME_SIG_MODE_CLEAR;
1575          else          else
1576              c->sigmode = GPGME_SIG_MODE_NORMAL;              c->sigmode = GPGME_SIG_MODE_NORMAL;
# Line 1577  fm_verify (fm_state_t c, int detached, c Line 1592  fm_verify (fm_state_t c, int detached, c
1592      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1593      int rc = 0;      int rc = 0;
1594    
1595      if (strstr (name, ".sig"))      if (stristr (name, ".sig"))
1596          detached = 1;          detached = 1;
1597    
1598      if (get_output_file (c, name, detached))      if (get_output_file (c, name, detached))
# Line 1585  fm_verify (fm_state_t c, int detached, c Line 1600  fm_verify (fm_state_t c, int detached, c
1600    
1601      memset (&log, 0, sizeof (log));      memset (&log, 0, sizeof (log));
1602      log.file = m_strdup (name);      log.file = m_strdup (name);
     if (!log.file)  
         BUG (NULL);  
1603      file_verify_create_dlg ();      file_verify_create_dlg ();
1604    
1605      err = gpg_file_data_new (name, F_DATA_READ, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
# Line 1640  fm_import (fm_state_t c, const char *nam Line 1653  fm_import (fm_state_t c, const char *nam
1653    
1654      free_if_alloc (c->output);      free_if_alloc (c->output);
1655      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (NULL);  
1656    
1657      err = gpg_file_data_new (name, F_DATA_READ, &keydata);      err = gpg_file_data_new (name, F_DATA_READ, &keydata);
1658      if (err)      if (err)
# Line 1675  leave: Line 1686  leave:
1686  /* Export the selected keys from the File Manager to a file. */  /* Export the selected keys from the File Manager to a file. */
1687  int  int
1688  fm_export (fm_state_t c)  fm_export (fm_state_t c)
1689  {  {    
     int rc = 0;  
1690      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1691      gpgme_error_t err;      gpgme_error_t err;
1692      gpgme_key_t *rset = c->recp;      gpgme_key_t *rset = c->recp;
1693      file_data_t keydata = NULL;      file_data_t keydata = NULL;
1694      const char *name;      const char *name;
1695      char *p = NULL, *patt = NULL;      char *p = NULL, *patt = NULL;
1696        int rc = 0;
1697    
1698      if (!rset || !rset[0]) {      if (!rset || !rset[0]) {
1699          msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR);          msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR);
# Line 1696  fm_export (fm_state_t c) Line 1707  fm_export (fm_state_t c)
1707      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),
1708                               NULL, p? p : NULL);                               NULL, p? p : NULL);
1709      if (!name)      if (!name)
1710          name = "keys.gpg";          name = reg_prefs.default_ext? "keys.pgp" : "keys.gpg";
1711    
1712      patt = gpg_keylist_to_pattern (rset, c->n_recp);      patt = gpg_keylist_to_pattern (rset, c->n_recp);
1713    
# Line 1717  fm_export (fm_state_t c) Line 1728  fm_export (fm_state_t c)
1728  leave:  leave:
1729      if (keydata)      if (keydata)
1730          gpg_file_data_release (keydata);          gpg_file_data_release (keydata);
1731      if (patt)      safe_free (patt);
         free (patt);  
1732      free_if_alloc (p);      free_if_alloc (p);
1733      return rc;      return rc;
1734  }  }
# Line 1775  fm_parse_command_line (char *cmdl) Line 1785  fm_parse_command_line (char *cmdl)
1785    
1786          case PGP_SIG:          case PGP_SIG:
1787          case PGP_CLEARSIG:          case PGP_CLEARSIG:
             file_verify_use_event ();  
1788              if (type == PGP_SIG)                  if (type == PGP_SIG)    
1789                  detached = 1;                  detached = 1;
1790              fm_verify (ctx, detached, fn);              fm_verify (ctx, detached, fn);
# Line 1812  int Line 1821  int
1821  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)
1822  {  {
1823      PK_FILE_LIST list=NULL;      PK_FILE_LIST list=NULL;
1824      const char *outfile;      const char *outfile, *ext;
1825      char *out_enc;      char *out_enc;
1826      int nitems = listview_count_items (lv, 0);      int nitems;
1827      int i, idx = -1;      int i, idx = -1;
1828      int rc;      int rc;
1829    
1830        nitems = listview_count_items (lv, 0);
1831      if (!nitems) {      if (!nitems) {
1832          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"),
1833                   _("File Manager"), MB_ERR);                   _("File Manager"), MB_ERR);
# Line 1847  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1857  fm_encrypt_into_zip (fm_state_t ctx, lis
1857      if (rc)      if (rc)
1858          return rc;          return rc;
1859    
1860      out_enc = make_filename (NULL, outfile, "gpg");      ext = file_get_extension (ctx->ctx, ctx->sigmode)+1;
1861        out_enc = make_filename (NULL, outfile, ext);
1862      fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc);      fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc);
1863      free_if_alloc (out_enc);      free_if_alloc (out_enc);
1864    
# Line 1922  fm_cmp_cb (LPARAM first, LPARAM second, Line 1933  fm_cmp_cb (LPARAM first, LPARAM second,
1933      const char *a = 0;      const char *a = 0;
1934      const char *b = 0;      const char *b = 0;
1935    
1936      switch( (int)sortby ) {      switch ((int)sortby) {
1937      case FM_SORT_STAT:      case FM_SORT_STAT:
1938          break;          break;
1939      case FM_SORT_NAME:      case FM_SORT_NAME:
# Line 1938  fm_cmp_cb (LPARAM first, LPARAM second, Line 1949  fm_cmp_cb (LPARAM first, LPARAM second,
1949  int  int
1950  fm_sort (listview_ctrl_t lv, int sortby)  fm_sort (listview_ctrl_t lv, int sortby)
1951  {  {
1952      return listview_sort_items( lv, sortby, fm_cmp_cb );      return listview_sort_items (lv, sortby, fm_cmp_cb);
1953  }  }
1954    
1955    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26