/[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 177 by twoaday, Tue Feb 14 15:46:29 2006 UTC revision 219 by twoaday, Sat May 27 08:56:00 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 63  char* gpg_keylist_to_pattern (gpgme_key_ Line 58  char* gpg_keylist_to_pattern (gpgme_key_
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    
 /*-- wptFileVerifyDlg.cpp --*/  
 void file_verify_add_state (file_sig_ctx_t c);  
 void file_verify_use_event (void);  
 void file_verify_wait (void);  
61    
62  static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",  /* Symbolic column IDs. */
63    enum {
64        FM_COL_STAT = 0,
65        FM_COL_NAME = 1,
66        FM_COL_OP   = 2
67    };
68    
69    static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg",
70                                    ".mp3", ".wav", ".mid", ".wma",                                    ".mp3", ".wav", ".mid", ".wma",
71                                    ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};                                    ".gif", ".jpg", ".png", ".jpeg", ".dib", 0};
72    
# Line 117  overwrite_file (const char *fname) Line 115  overwrite_file (const char *fname)
115  void  void
116  remove_crit_file_attrs (const char *fname, int force)  remove_crit_file_attrs (const char *fname, int force)
117  {  {
118      u32 fattr;      DWORD fattr;
119      int id = 0;      int id = 0;
120    
121      if (file_exist_check (fname))      if (file_exist_check (fname))
# Line 146  is_directory (const char *fname) Line 144  is_directory (const char *fname)
144  }  }
145    
146    
147  /* Return -1 if the given name @name is a valid PGP extension. */  /* Return -1 if the given name @name is a valid GPG extension. */
148  static int  int
149  is_openpgp_ext (const char *name)  is_openpgp_ext (const char *name)
150  {  {
151      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 200  file_get_extension (gpgme_ctx_t ctx, gpg
200          return ".asc";          return ".asc";
201      if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH)      if (!use_armor && sigmode == GPGME_SIG_MODE_DETACH)
202          return ".sig";          return ".sig";
203      return ".gpg";      return reg_prefs.default_ext == 1? ".pgp" : ".gpg";
204  }  }
205    
206    
# Line 227  fm_quote_file (const char * name) Line 225  fm_quote_file (const char * name)
225    
226  /* Check the armor type of the file @fname and return  /* Check the armor type of the file @fname and return
227     a string representation of it. */     a string representation of it. */
228  static const char *  static const char*
229  fm_check_armor_type (const char *fname, int *r_type)  fm_check_armor_type (const char *fname, int *r_type)
230  {  {
231      FILE * fp;      FILE *fp;
232      char header[768], * p;      char header[768], *p;
233            
234      if (r_type)      if (r_type)
235          *r_type = PGP_NONE;          *r_type = PGP_NONE;
# Line 377  fm_get_file_type (const char *fname, int Line 375  fm_get_file_type (const char *fname, int
375  int  int
376  fm_build (listview_ctrl_t *lv, HWND ctrl)  fm_build (listview_ctrl_t *lv, HWND ctrl)
377  {  {
378      int i, rc = 0;      int i;
379      listview_ctrl_t c;      listview_ctrl_t c;
380      struct listview_column_s col[] = {      struct listview_column_s col[] = {
381          {0,  80, (char *)_("Status") },          {0,  80, (char *)_("Status") },
382          {1, 256, (char *)_("Name") },          {1, 256, (char *)_("Name") },
383          {2, 128, (char *)_("Operation") },          {2, 128, (char *)_("Operation") },
384          {0,   0, NULL }          {0,   0, NULL}  
385      };      };
386                    
387      rc = listview_new (&c);      listview_new (&c, ctrl);
     if (rc)  
         BUG (NULL);  
     c->ctrl = ctrl;  
388      for (i = 0; col[i].width; i++)      for (i = 0; col[i].width; i++)
389          listview_add_column (c, &col[i]);          listview_add_column (c, &col[i]);
390      listview_set_ext_style (c);      listview_set_ext_style (c);
# Line 412  fm_delete (listview_ctrl_t lv) Line 407  fm_delete (listview_ctrl_t lv)
407  int  int
408  fm_state_new (fm_state_t * ctx)  fm_state_new (fm_state_t * ctx)
409  {  {
410      gpgme_error_t rc;      fm_state_s *c;
     fm_state_s * c;  
411    
412      c = new fm_state_s;      c = new fm_state_s;
413      if (!c)      if (!c)
414          BUG (0);          BUG (0);
415      memset (c, 0, sizeof *c);      memset (c, 0, sizeof *c);
416      rc = gpgme_new (&c->ctx);      if (gpgme_new (&c->ctx))
     if (rc)  
417          BUG (0);          BUG (0);
     /* XXX rc = gpgme_recipients_new (&c->recp);*/  
     /* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */  
418      *ctx = c;      *ctx = c;
419      return 0;      return 0;
420  } /* fm_state_new */  }
421    
422    
423  /* Release the FM state handle @c. */  /* Release the FM state handle @c. */
# Line 442  fm_state_release (fm_state_t c) Line 433  fm_state_release (fm_state_t c)
433      safe_free (c->recp);      safe_free (c->recp);
434      free_if_alloc (c->opaque);      free_if_alloc (c->opaque);
435      free_if_alloc (c->output);      free_if_alloc (c->output);
436      delete c; c = NULL;          delete c;
437  }  }
438    
439    
440  static int  static int
441  fm_check_for_entry( listview_ctrl_t lv, const char *file )  fm_check_for_entry( listview_ctrl_t lv, const char *file )
442  {  {
# Line 459  fm_check_for_entry( listview_ctrl_t lv, Line 451  fm_check_for_entry( listview_ctrl_t lv,
451      }      }
452    
453      return 0;      return 0;
454  } /* fm_check_for_entry */  }
455    
456    
457  static int  static int
# Line 483  fm_set_ftype (listview_ctrl_t lv, const Line 475  fm_set_ftype (listview_ctrl_t lv, const
475  }  }
476    
477    
478    /* Add all files from the directory @path to the list view @lv. */
479  static int  static int
480  fm_add_dir_files (listview_ctrl_t lv, char *path)  fm_add_dir_files (listview_ctrl_t lv, char *path)
481  {  {
# Line 547  add_single_file (listview_ctrl_t lv, con Line 540  add_single_file (listview_ctrl_t lv, con
540      if (!type)      if (!type)
541          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
542      if (!strcmp (type, "UNKNOWN"))            if (!strcmp (type, "UNKNOWN"))      
543          type = gnupg_check_file_ext (name, NULL);                    type = gnupg_check_file_ext (name, NULL);
544      rc = listview_add_item (lv, "");              rc = listview_add_item (lv, "");
545      if (!rc) {        if (!rc) {
546          listview_add_sub_item (lv, 0, 0, type);          listview_add_sub_item (lv, 0, 0, type);
547          listview_add_sub_item (lv, 0, 1, name);          listview_add_sub_item (lv, 0, 1, name);
548      }      }
# Line 601  fm_add_opened_files (listview_ctrl_t lv, Line 594  fm_add_opened_files (listview_ctrl_t lv,
594          else {          else {
595              char *p = make_filename (path, name, NULL);              char *p = make_filename (path, name, NULL);
596              rc = add_single_file (lv, p);              rc = add_single_file (lv, p);
597              free (p);              safe_free (p);
598          }          }
599          n++;          n++;
600      }      }
601      if (n == 1) /* single file selected. */      if (n == 1) /* single file selected. */
602          rc = add_single_file (lv, path);          rc = add_single_file (lv, path);
603      if (path)      safe_free (path);
         free (path);  
604      return rc;      return rc;
605  }  }
606    
607    
608  int  int
609  fm_assume_onepass_sig (const char * fname)  fm_assume_onepass_sig (const char *fname)
610  {  {    
     gpgme_data_t dat;  
611      armor_filter_context_t afx;      armor_filter_context_t afx;
612      gpg_iobuf_t fp;      gpg_iobuf_t fp;
613      PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt);      gpgme_data_t dat;
614        PACKET *pkt;
615        char tmpfile[MAX_PATH+1];
616      int check = 0;      int check = 0;
617    
618        pkt = (PACKET *)calloc (1, sizeof *pkt);
619      if (!fname) {      if (!fname) {
620            get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp");
621          gpg_data_new_from_clipboard (&dat, 0);          gpg_data_new_from_clipboard (&dat, 0);
622          gpg_data_release_and_set_file (dat, "gpgme.tmp");          gpg_data_release_and_set_file (dat, tmpfile);
623    
624          fp = gpg_iobuf_open ("gpgme.tmp");          fp = gpg_iobuf_open (tmpfile);
625          if (!fp)          if (!fp)
626              return 0;              return 0;
627          gpg_iobuf_ioctl (fp, 3, 1, NULL);          gpg_iobuf_ioctl (fp, 3, 1, NULL);
# Line 639  fm_assume_onepass_sig (const char * fnam Line 634  fm_assume_onepass_sig (const char * fnam
634              && pkt->pkttype == PKT_COMPRESSED)              && pkt->pkttype == PKT_COMPRESSED)
635              check = 1;                check = 1;  
636          gpg_free_packet (pkt);          gpg_free_packet (pkt);
         safe_free (pkt);  
637          gpg_iobuf_close (fp);          gpg_iobuf_close (fp);
638          remove ("gpgme.tmp");          remove (tmpfile);
639      }      }
640      /* XXX: implement it for real files */      /* XXX: implement it for real files */
641        safe_free (pkt);
642      return check;      return check;
643  }  }
644    
# Line 656  fm_get_current_pos (listview_ctrl_t lv) Line 651  fm_get_current_pos (listview_ctrl_t lv)
651      items = listview_count_items (lv, 0);      items = listview_count_items (lv, 0);
652      if (!items)      if (!items)
653          return -1;          return -1;
654      else if (items == 1)      else if (items == 1) {
     {  
655          listview_select_one (lv, 0);          listview_select_one (lv, 0);
656          return 0;          return 0;
657      }      }
658      else if (items > 1)      else if (items > 1) {
     {  
659          i = listview_get_curr_pos (lv);          i = listview_get_curr_pos (lv);
660          if (i == -1)          if (i == -1) {
661          {              msg_box (lv->ctrl, _("Please select a file."),
662              msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR);                       _("File Manager"), MB_ERR);
663              return -1;              return -1;
664          }          }
665          return i;          return i;
666      }      }
667    
668      return -1;      return -1;
669  } /* fm_get_current_pos */  }
670    
671    
672  static int  static int
673  fm_check_detached_sig( listview_ctrl_t lv, int pos )  fm_check_detached_sig (listview_ctrl_t lv, int pos)
674  {  {
675      char type[128];      char type[128];
676    
677      listview_get_item_text( lv, pos, 0, type, 127 );      listview_get_item_text (lv, pos, 0, type, sizeof (type)-1);
678      return !strcmp( type, "SIGNED-DETACH" )? 1 : 0;      return !strcmp (type, "SIGNED-DETACH")? 1 : 0;
679  } /* fm_check_detached_sig */  }
680    
681    
682  int  int
# Line 740  fm_check_file_type (listview_ctrl_t lv, Line 733  fm_check_file_type (listview_ctrl_t lv,
733      }      }
734            
735      return rc;      return rc;
736  } /* fm_check_file_type */  }
737    
738    
739  /* 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 804  fm_clearsign_8bit (listview_ctrl_t lv, f
804      if (!cnt)      if (!cnt)
805          return 0;          return 0;
806      n = -1;      n = -1;
807      i = log_box (_("File Manager"), MB_WARN|MB_YESNO,      i = log_box (_("File Manager"), MB_WARN|MB_YESNO,
808                   _("\"%s\" does not seems to be a text file.\n"                   _("\"%s\" does not seems to be a text file.\n"
809                     "Do you really want to clearsign it?"), name);                     "Do you really want to clearsign it?"), name);
810      if (i == IDYES)      if (i == IDYES)
# Line 819  fm_clearsign_8bit (listview_ctrl_t lv, f Line 812  fm_clearsign_8bit (listview_ctrl_t lv, f
812      return n;      return n;
813  }  }
814    
815    
816  int  int
817  fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd)  fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd)
818  {  {
# Line 947  fm_parse_files (listview_ctrl_t lv, HWND Line 941  fm_parse_files (listview_ctrl_t lv, HWND
941          case FM_IMPORT:          case FM_IMPORT:
942              free_if_alloc (ctx->opaque);              free_if_alloc (ctx->opaque);
943              ctx->opaque = m_strdup (fname);              ctx->opaque = m_strdup (fname);
             if (!ctx->opaque)  
                 BUG (0);  
944              DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg,              DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg,
945                              file_import_dlg_proc, (LPARAM)ctx);                              file_import_dlg_proc, (LPARAM)ctx);
946              if (ctx->cancel == 1)              if (ctx->cancel == 1)
# Line 1030  ask_filename (fm_state_t c, const char * Line 1022  ask_filename (fm_state_t c, const char *
1022          free_if_alloc (*dst);          free_if_alloc (*dst);
1023      free_if_alloc (c->output);      free_if_alloc (c->output);
1024      c->output = m_strdup (s);      c->output = m_strdup (s);
     if (!c->output)  
         BUG (0);  
1025      if (dst)      if (dst)
1026          *dst = fm_quote_file (s);          *dst = fm_quote_file (s);
1027      return 0;      return 0;
# Line 1099  fm_encrypt (fm_state_t c, const char *na Line 1089  fm_encrypt (fm_state_t c, const char *na
1089              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);              gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0);
1090              if (sigkey && sigkey->subkeys) {              if (sigkey && sigkey->subkeys) {
1091                  keyid = m_strdup (sigkey->subkeys->keyid);                  keyid = m_strdup (sigkey->subkeys->keyid);
                 if (!keyid)  
                     BUG (NULL);  
1092              }              }
1093          }          }
1094          if (!c->init_cb || !c->cache_cb) {          if (!c->init_cb || !c->cache_cb) {
# Line 1211  leave: Line 1199  leave:
1199  }  }
1200    
1201    
1202    char* get_pka_status (gpgme_signature_t sig);
1203    
1204    
1205  /* Show the human readable verify result from @sigres. */  /* Show the human readable verify result from @sigres. */
1206  static void  static void
1207  show_verify_result (gpgme_verify_result_t sigres)  show_verify_result (gpgme_verify_result_t sigres)
1208  {  {    
     gpgme_key_t key=NULL;  
1209      gpgme_signature_t sig=sigres->signatures;      gpgme_signature_t sig=sigres->signatures;
1210      const char *s, *keyid;      winpt_key_s key;
1211      int sigok = 0;      const char *s, *keyid, *uid;
1212      int type;      char *pka_info;
1213      char buf[384];      char buf[384];
1214        int sigok = 0;
1215    
1216      sig = sigres->signatures;      sig = sigres->signatures;
1217      sigok = sig->summary & GPGME_SIGSUM_GREEN;      sigok = sig->summary & GPGME_SIGSUM_GREEN;
1218      s = sigok? _("Good signature") : _("BAD signature");      s = sigok? _("Good signature") : _("BAD signature");
     type = sigok? MB_OK: MB_ICONWARNING|MB_OK;  
1219      keyid = sig->fpr;      keyid = sig->fpr;
1220      if (!keyid)      if (!keyid)
1221          return;          return;
1222        pka_info = get_pka_status (sig);
1223      keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24;      keyid = get_keyid_from_fpr (sig->fpr);
1224      get_pubkey (sig->fpr, &key);      memset (&key, 0, sizeof (key));
1225        if (!winpt_get_pubkey (sig->fpr, &key))
1226            uid = key.ext->uids->uid;
1227        else
1228            uid = _("user ID not found");
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\"\n%s"),
1231                  strtimestamp (sig->timestamp),                  strtimestamp (sig->timestamp),
1232                  get_key_pubalgo (sig->pubkey_algo),                  get_key_pubalgo (sig->pubkey_algo),
1233                  keyid, s, key? key->uids->uid : _("user ID not found"));                  keyid, s, uid, pka_info? pka_info : "");
1234      msg_box (NULL, buf, _("Decrypt Verify"), type);      msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK);
1235        free_if_alloc (pka_info);
1236        winpt_release_pubkey (&key);
1237  }  }
1238    
1239    
1240  /* Check the recipients if we have at least one secret key. */  /* Check the recipients if we have at least one secret key. */
1241  bool  bool
1242  secret_key_available (gpgme_recipient_t rset)  is_seckey_available (gpgme_recipient_t rset)
1243  {  {
1244      gpgme_recipient_t r;      gpgme_recipient_t r;
1245      gpgme_key_t key;      winpt_key_s key;
1246    
1247      for (r=rset; r; r = r->next) {      for (r=rset; r; r = r->next) {
1248          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)          if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY)
1249              continue;              continue;
1250          else {          else {
1251                memset (&key, 0, sizeof (key));
1252              /* extra check to make sure the key is available right now. */              /* extra check to make sure the key is available right now. */
1253              if (!get_seckey (r->keyid, &key))              if (!winpt_get_seckey (r->keyid, &key)) {
1254                    winpt_release_pubkey (&key);
1255                  return true;                  return true;
1256                }
1257                winpt_release_pubkey (&key);
1258          }          }
1259      }      }
1260      return false;      return false;
1261  }  }
1262    
1263    
1264    /* If the decrypt result contains the original file name,
1265       we use it instead of the artificial "output - .gpg" string. */
1266    static int
1267    restore_original_name (const char *output, const char *file_name)
1268    {
1269        char *dir;
1270        char *orig;
1271        int rc = 0;
1272    
1273        dir = strrchr (output, '\\');
1274        if (!dir)
1275            orig = strdup (file_name);
1276        else {
1277            orig = (char*)calloc (1, strlen (file_name)+ 1 +
1278                                     strlen (output)+1);
1279            if (!orig)
1280                BUG (0);
1281            memcpy (orig, output, (dir-output)+1);
1282            strcat (orig, file_name);
1283        }
1284        /* XXX: we need to find out if the string needs to be utf8 decoded. */
1285        if (overwrite_file (orig)) {
1286            DeleteFile (orig);
1287            if (!MoveFile (output, orig))
1288                rc = -1;
1289        }
1290        safe_free (orig);
1291        return rc;
1292    }
1293    
1294    
1295  /* Decrypt the file @name. */  /* Decrypt the file @name. */
1296  int  int
1297  fm_decrypt (fm_state_t c, const char *name)  fm_decrypt (fm_state_t c, const char *name)
# Line 1269  fm_decrypt (fm_state_t c, const char *na Line 1300  fm_decrypt (fm_state_t c, const char *na
1300      gpgme_ctx_t ctx = c->ctx;          gpgme_ctx_t ctx = c->ctx;    
1301      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res;
1302      gpgme_verify_result_t sigres;      gpgme_verify_result_t sigres;
1303      file_data_t in =NULL, out=NULL;      file_data_t in = NULL, out = NULL;
1304      int rc = 0;      int rc = 0;
1305            
1306      if (!c->init_cb || !c->cache_cb) {      if (!c->init_cb || !c->cache_cb) {
# Line 1279  fm_decrypt (fm_state_t c, const char *na Line 1310  fm_decrypt (fm_state_t c, const char *na
1310      }      }
1311            
1312      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (0);  
1313      if (is_openpgp_ext (c->output))      if (is_openpgp_ext (c->output))
1314          c->output[strlen (c->output)-4] = '\0';          c->output[strlen (c->output)-4] = '\0';
1315      else {      else {
# Line 1290  fm_decrypt (fm_state_t c, const char *na Line 1319  fm_decrypt (fm_state_t c, const char *na
1319          if (s) {          if (s) {
1320              free_if_alloc (c->output);              free_if_alloc (c->output);
1321              c->output = m_strdup (s);              c->output = m_strdup (s);
             if (!c->output)  
                 BUG (NULL);  
1322          }          }
1323      }      }
1324    
# Line 1301  fm_decrypt (fm_state_t c, const char *na Line 1328  fm_decrypt (fm_state_t c, const char *na
1328              goto leave;              goto leave;
1329      }      }
1330    
1331        /* we fetch all recipients here to make sure they list is complete. */
1332        release_gpg_recipients (&c->pass_cb.recipients);
1333        gpg_get_recipients (name, &c->pass_cb.recipients);
1334    
1335      err = gpg_file_data_new (name, F_DATA_READ, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
1336      if (err)      if (err)
1337          goto leave;          goto leave;
# Line 1308  fm_decrypt (fm_state_t c, const char *na Line 1339  fm_decrypt (fm_state_t c, const char *na
1339      err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);      err = gpg_file_data_new (c->output, F_DATA_WRITE, &out);
1340      if (err)      if (err)
1341          goto leave;          goto leave;
1342        
1343      op_begin ();      op_begin ();
1344      err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat);      err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat);
1345      op_end ();      op_end ();
# Line 1320  fm_decrypt (fm_state_t c, const char *na Line 1351  fm_decrypt (fm_state_t c, const char *na
1351      }      }
1352    
1353      res = gpgme_op_decrypt_result (ctx);      res = gpgme_op_decrypt_result (ctx);
1354      if (res && res->recipients && !secret_key_available (res->recipients)) {      if (res && res->recipients && !is_seckey_available (res->recipients)) {
1355          const char *keyid = res->recipients->keyid;          const char *keyid = res->recipients->keyid;
1356          char *p = get_key_userid (keyid+8);          char *p = get_key_userid (keyid+8);
1357          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;          gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo;
1358                    
1359          log_box( _("Decryption"), MB_ERR,          log_box (_("Decryption"), MB_ERR,
1360                   _("Encrypted with %s key, ID %s.%s\n"                   _("Encrypted with %s key, ID %s.%s\n"
1361                     "Decryption failed: secret key not available."),                     "Decryption failed: secret key not available."),
1362                     get_key_pubalgo (pkalgo), keyid+8, p);                     get_key_pubalgo (pkalgo), keyid+8, p);
# Line 1342  fm_decrypt (fm_state_t c, const char *na Line 1373  fm_decrypt (fm_state_t c, const char *na
1373          log_box ("Decrypt", MB_ERR,          log_box ("Decrypt", MB_ERR,
1374                   _("Decryption failed.\n%s: does not exist."), c->output);                   _("Decryption failed.\n%s: does not exist."), c->output);
1375          rc = WPTERR_GENERAL;          rc = WPTERR_GENERAL;
1376            goto leave;
1377        }
1378        else if (res && res->file_name) {
1379            char *file;
1380            int id = IDNO;
1381    
1382            file = strrchr (c->output, '\\');
1383            if (!file)
1384                file = c->output;
1385            else
1386                file++;
1387            if (strcmp (res->file_name, file))
1388                id = log_box (_("Decrypt"), MB_QUEST_ASK,
1389                              _("The original file name is '%s'.\n\n"
1390                                "Do you want to use this instead of '%s'?"),
1391                          res->file_name, file);
1392            if (id == IDYES) {
1393                /* before we can move the file, it needs to be closed first. */
1394                gpg_file_data_release (out);
1395                out = NULL;
1396                restore_original_name (c->output, res->file_name);
1397            }
1398      }      }
       
1399      sigres = gpgme_op_verify_result (ctx);      sigres = gpgme_op_verify_result (ctx);
1400      if (sigres && sigres->signatures)      if (sigres && sigres->signatures)
1401          show_verify_result (sigres);          show_verify_result (sigres);
# Line 1422  leave: Line 1474  leave:
1474  static void  static void
1475  fm_add_sig_stat (file_sig_ctx_t log)  fm_add_sig_stat (file_sig_ctx_t log)
1476  {  {
1477      gpgme_key_t key;          struct winpt_key_s key;
1478      const char *kid;      const char *kid;
1479    
1480      kid = log->sig->fpr;      memset (&key, 0, sizeof (key));
1481      if (!kid)      kid = get_keyid_from_fpr (log->sig->fpr);
1482          BUG (NULL);      log->use_uid = 0;
1483      if (strlen (kid) == 40)      if (!winpt_get_pubkey (kid, &key)) {
1484          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;  
1485          log->use_uid = 1;          log->use_uid = 1;
1486      }      }
1487        winpt_release_pubkey (&key);
1488      file_verify_add_state (log);      file_verify_add_state (log);
1489  }  }
1490    
# Line 1527  get_output_file (fm_state_t c, const cha Line 1574  get_output_file (fm_state_t c, const cha
1574      else      else
1575          title = _("Selected Output File");          title = _("Selected Output File");
1576    
1577      if (strstr (name, ".sig")      if (stristr (name, ".sig") ||
1578          || strstr (name, ".asc")          stristr (name, ".asc") ||
1579          || strstr (name, ".gpg")) {          stristr (name, ".gpg") ||
1580            stristr (name, ".pgp")) {
1581          _snprintf (fname, sizeof (fname) - 1, "%s", name);          _snprintf (fname, sizeof (fname) - 1, "%s", name);
1582          fname[strlen (fname) - 4] = '\0';          fname[strlen (fname) - 4] = '\0';
1583          if (file_exist_check (fname) == 0 && detached)            if (file_exist_check (fname) == 0 && detached)  
# Line 1551  get_output_file (fm_state_t c, const cha Line 1599  get_output_file (fm_state_t c, const cha
1599      if (file) {          if (file) {    
1600          free_if_alloc (c->output);              free_if_alloc (c->output);    
1601          c->output = m_strdup (file);          c->output = m_strdup (file);
         if (!c->output)  
             BUG (NULL);  
1602      }      }
1603      else {      else {
1604          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);          msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR);
# Line 1561  get_output_file (fm_state_t c, const cha Line 1607  get_output_file (fm_state_t c, const cha
1607      if (detached)      if (detached)
1608          c->sigmode = GPGME_SIG_MODE_DETACH;          c->sigmode = GPGME_SIG_MODE_DETACH;
1609      else {      else {
1610          if (strstr (name, ".asc"))          if (stristr (name, ".asc"))
1611              c->sigmode = GPGME_SIG_MODE_CLEAR;              c->sigmode = GPGME_SIG_MODE_CLEAR;
1612          else          else
1613              c->sigmode = GPGME_SIG_MODE_NORMAL;              c->sigmode = GPGME_SIG_MODE_NORMAL;
# Line 1583  fm_verify (fm_state_t c, int detached, c Line 1629  fm_verify (fm_state_t c, int detached, c
1629      file_data_t in=NULL, out=NULL;      file_data_t in=NULL, out=NULL;
1630      int rc = 0;      int rc = 0;
1631    
1632      if (strstr (name, ".sig"))      if (stristr (name, ".sig"))
1633          detached = 1;          detached = 1;
1634    
1635      if (get_output_file (c, name, detached))      if (get_output_file (c, name, detached))
# Line 1591  fm_verify (fm_state_t c, int detached, c Line 1637  fm_verify (fm_state_t c, int detached, c
1637    
1638      memset (&log, 0, sizeof (log));      memset (&log, 0, sizeof (log));
1639      log.file = m_strdup (name);      log.file = m_strdup (name);
     if (!log.file)  
         BUG (NULL);  
1640      file_verify_create_dlg ();      file_verify_create_dlg ();
1641    
1642      err = gpg_file_data_new (name, F_DATA_READ, &in);      err = gpg_file_data_new (name, F_DATA_READ, &in);
# Line 1646  fm_import (fm_state_t c, const char *nam Line 1690  fm_import (fm_state_t c, const char *nam
1690    
1691      free_if_alloc (c->output);      free_if_alloc (c->output);
1692      c->output = m_strdup (name);      c->output = m_strdup (name);
     if (!c->output)  
         BUG (NULL);  
1693    
1694      err = gpg_file_data_new (name, F_DATA_READ, &keydata);      err = gpg_file_data_new (name, F_DATA_READ, &keydata);
1695      if (err)      if (err)
# Line 1681  leave: Line 1723  leave:
1723  /* Export the selected keys from the File Manager to a file. */  /* Export the selected keys from the File Manager to a file. */
1724  int  int
1725  fm_export (fm_state_t c)  fm_export (fm_state_t c)
1726  {  {    
     int rc = 0;  
1727      gpgme_ctx_t ctx = c->ctx;      gpgme_ctx_t ctx = c->ctx;
1728      gpgme_error_t err;      gpgme_error_t err;
1729      gpgme_key_t *rset = c->recp;      gpgme_key_t *rset = c->recp;
1730      file_data_t keydata = NULL;      file_data_t keydata = NULL;
1731      const char *name;      const char *name;
1732      char *p = NULL, *patt = NULL;      char *p = NULL, *patt = NULL;
1733        int rc = 0;
1734    
1735      if (!rset || !rset[0]) {      if (!rset || !rset[0]) {
1736          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 1702  fm_export (fm_state_t c) Line 1744  fm_export (fm_state_t c)
1744      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),      name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"),
1745                               NULL, p? p : NULL);                               NULL, p? p : NULL);
1746      if (!name)      if (!name)
1747          name = "keys.gpg";          name = reg_prefs.default_ext? "keys.pgp" : "keys.gpg";
1748    
1749      patt = gpg_keylist_to_pattern (rset, c->n_recp);      patt = gpg_keylist_to_pattern (rset, c->n_recp);
1750    
# Line 1723  fm_export (fm_state_t c) Line 1765  fm_export (fm_state_t c)
1765  leave:  leave:
1766      if (keydata)      if (keydata)
1767          gpg_file_data_release (keydata);          gpg_file_data_release (keydata);
1768      if (patt)      safe_free (patt);
         free (patt);  
1769      free_if_alloc (p);      free_if_alloc (p);
1770      return rc;      return rc;
1771  }  }
# Line 1781  fm_parse_command_line (char *cmdl) Line 1822  fm_parse_command_line (char *cmdl)
1822    
1823          case PGP_SIG:          case PGP_SIG:
1824          case PGP_CLEARSIG:          case PGP_CLEARSIG:
             file_verify_use_event ();  
1825              if (type == PGP_SIG)                  if (type == PGP_SIG)    
1826                  detached = 1;                  detached = 1;
1827              fm_verify (ctx, detached, fn);              fm_verify (ctx, detached, fn);
# Line 1818  int Line 1858  int
1858  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)  fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv)
1859  {  {
1860      PK_FILE_LIST list=NULL;      PK_FILE_LIST list=NULL;
1861      const char *outfile;      const char *outfile, *ext;
1862      char *out_enc;      char *out_enc;
1863      int nitems = listview_count_items (lv, 0);      int nitems;
1864      int i, idx = -1;      int i, idx = -1;
1865      int rc;      int rc;
1866    
1867        nitems = listview_count_items (lv, 0);
1868      if (!nitems) {      if (!nitems) {
1869          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"),
1870                   _("File Manager"), MB_ERR);                   _("File Manager"), MB_ERR);
# Line 1853  fm_encrypt_into_zip (fm_state_t ctx, lis Line 1894  fm_encrypt_into_zip (fm_state_t ctx, lis
1894      if (rc)      if (rc)
1895          return rc;          return rc;
1896    
1897      out_enc = make_filename (NULL, outfile, "gpg");      ext = file_get_extension (ctx->ctx, ctx->sigmode)+1;
1898        out_enc = make_filename (NULL, outfile, ext);
1899      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);
1900      free_if_alloc (out_enc);      free_if_alloc (out_enc);
1901    
# Line 1928  fm_cmp_cb (LPARAM first, LPARAM second, Line 1970  fm_cmp_cb (LPARAM first, LPARAM second,
1970      const char *a = 0;      const char *a = 0;
1971      const char *b = 0;      const char *b = 0;
1972    
1973      switch( (int)sortby ) {      switch ((int)sortby) {
1974      case FM_SORT_STAT:      case FM_SORT_STAT:
1975          break;          break;
1976      case FM_SORT_NAME:      case FM_SORT_NAME:
# Line 1944  fm_cmp_cb (LPARAM first, LPARAM second, Line 1986  fm_cmp_cb (LPARAM first, LPARAM second,
1986  int  int
1987  fm_sort (listview_ctrl_t lv, int sortby)  fm_sort (listview_ctrl_t lv, int sortby)
1988  {  {
1989      return listview_sort_items( lv, sortby, fm_cmp_cb );      return listview_sort_items (lv, sortby, fm_cmp_cb);
1990  }  }
1991    
1992    

Legend:
Removed from v.177  
changed lines
  Added in v.219

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26