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

Diff of /trunk/Src/wptGPG.cpp

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

revision 137 by twoaday, Mon Jan 9 14:01:51 2006 UTC revision 197 by twoaday, Mon Apr 10 07:38:06 2006 UTC
# Line 116  get_gnupg_cfgfile (void) Line 116  get_gnupg_cfgfile (void)
116      if (!path)      if (!path)
117          return NULL;          return NULL;
118      p = get_reg_entry_gpg ("OptFile");      p = get_reg_entry_gpg ("OptFile");
119      if (p && !strcmp (p, "")) {      if (p) {
120          nlen = strlen (path) + 64;          nlen = strlen (p) + 4;
         optfile = new char[nlen + 1];  
         if (!optfile)  
             BUG (0);  
         _snprintf (optfile, nlen, "%s\\"GPG_CONF, path);  
     }  
     else if (p) {  
         nlen = strlen( p ) + 4;  
121          optfile = new char[nlen + 1];          optfile = new char[nlen + 1];
122          if (!optfile)          if (!optfile)
123              BUG (NULL);              BUG (NULL);
# Line 207  get_gnupg_prog (void) Line 200  get_gnupg_prog (void)
200     Return value: the keyid of the secret key. */     Return value: the keyid of the secret key. */
201  static char *  static char *
202  default_key_from_cache (int *ret_no_useable)  default_key_from_cache (int *ret_no_useable)
203  {  {    
204        gpgme_key_t key, pk;
205        gpg_keycache_t sec, pub;
206      const char *s;      const char *s;
207      char *keyid = NULL;      char *keyid = NULL;
     gpgme_key_t key;  
     gpg_keycache_t sec = keycache_get_ctx (0);  
208    
209        sec = keycache_get_ctx (0);
210      if (!sec)      if (!sec)
211          BUG (0);          BUG (0);
212        pub = keycache_get_ctx (1);
213      gpg_keycache_rewind (sec);      gpg_keycache_rewind (sec);
214      while (!gpg_keycache_next_key (sec, 1, &key)) {      while (!gpg_keycache_next_key (sec, 1, &key)) {
215          if (key_is_useable (key)) {          if (key_is_useable (key) && !get_pubkey (key->subkeys->keyid, &pk)) {
216              s = key->subkeys->keyid;              s = key->subkeys->keyid;
217              if (s)                  if (s)    
218                  keyid = m_strdup (s+8);                  keyid = m_strdup (s+8);
219              break;              break;
220          }          }
221      }      }
222      if (!keyid)      if (!keyid)
223          *ret_no_useable = 1;          *ret_no_useable = 1;    
224      return keyid;      return keyid;
225  }  }
226    
# Line 250  gnupg_load_config (void) Line 245  gnupg_load_config (void)
245      o = find_option (opt, "ask-cert-level");      o = find_option (opt, "ask-cert-level");
246      if (o)      if (o)
247          reg_prefs.gpg.ask_cert_level = 1;          reg_prefs.gpg.ask_cert_level = 1;
248        o = find_option (opt, "ask-cert-expire");
249        if (o)
250            reg_prefs.gpg.ask_cert_expire = 1;
251      release_gpg_options (opt);      release_gpg_options (opt);
252      free_if_alloc (conf);      free_if_alloc (conf);
253      return 0;      return 0;
# Line 261  get_gnupg_default_key (void) Line 259  get_gnupg_default_key (void)
259  {      {    
260      gpg_optfile_t opt = NULL;      gpg_optfile_t opt = NULL;
261      gpg_option_t e;      gpg_option_t e;
262      char * keyid = NULL, * optfile = NULL;      char *keyid = NULL, *optfile = NULL;
263      int no_usable=0, rc = 0;      int no_usable=0, rc = 0;
264    
265      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
# Line 272  get_gnupg_default_key (void) Line 270  get_gnupg_default_key (void)
270          free_if_alloc (optfile);          free_if_alloc (optfile);
271          return default_key_from_cache (&no_usable);          return default_key_from_cache (&no_usable);
272      }      }
273      e = find_option( opt, "default-key" );      e = find_option (opt, "default-key");
274      if ( e )      if (e)
275          keyid = m_strdup( e->val );          keyid = m_strdup (e->val);
276      if( !e ) {      if (!e) {
277          e = find_option( opt, "local-user" );          e = find_option (opt, "local-user");
278          if( e )          if (e)
279              keyid = m_strdup( e->val );              keyid = m_strdup (e->val);
280      }      }
281      if( !e ) {      if (!e) {
282          e = find_option( opt, "encrypt-to" );          e = find_option (opt, "encrypt-to");
283          if( e )          if (e)
284              keyid = m_strdup( e->val );              keyid = m_strdup (e->val);
285      }      }
286      free_if_alloc (optfile);      free_if_alloc (optfile);
287      release_gpg_options (opt);      release_gpg_options (opt);    
288    
289      if (!keyid)      if (!keyid)
290          keyid = default_key_from_cache (&no_usable);          keyid = default_key_from_cache (&no_usable);
291      return keyid;      return keyid;
292  } /* get_gnupg_default_key */  }
293    
294    
295  /* Check if GPG4WIN is available and if so, use the  /* Check if GPG4WIN is available and if so, use the
# Line 364  check_gnupg_engine (const char *need_gpg Line 362  check_gnupg_engine (const char *need_gpg
362      int rc = 1;      int rc = 1;
363    
364      /* Convert the needed GPG version to the integer format. */      /* Convert the needed GPG version to the integer format. */
365      rc = parse_version_nr (need_gpg_ver,      if (parse_version_nr (need_gpg_ver,
366                             &need_major, &need_minor, &need_patch);                            &need_major, &need_minor, &need_patch))
367      if (rc)          return 1;
         return rc;  
368            
369      gpgme_new (&ctx);      gpgme_new (&ctx);
370      inf = gpgme_ctx_get_engine_info (ctx);      inf = gpgme_ctx_get_engine_info (ctx);
# Line 382  check_gnupg_engine (const char *need_gpg Line 379  check_gnupg_engine (const char *need_gpg
379      if (strstr (eng, "IDEA"))      if (strstr (eng, "IDEA"))
380          idea_available = 1;          idea_available = 1;
381      free (eng);      free (eng);
382      rc = parse_version_nr (inf->version, &major, &minor, &patch);      if (parse_version_nr (inf->version, &major, &minor, &patch)) {
     if (rc) {  
383          gpgme_release (ctx);          gpgme_release (ctx);
384          return rc;          return 1;
385      }      }
386    
387      if (major > need_major)      if (major > need_major)
# Line 563  leave: Line 559  leave:
559  } /* get_gnupg_config */  } /* get_gnupg_config */
560    
561    
562    /* Set the default key in the gpg.conf.
563       If @key is NULL, the entry will be deleted. */
564  int  int
565  set_gnupg_default_key (const char * key)  set_gnupg_default_key (const char *key)
566  {  {
567      gpg_optfile_t opt;      gpg_optfile_t opt;
568      gpg_option_t e;      gpg_option_t e;
# Line 573  set_gnupg_default_key (const char * key) Line 571  set_gnupg_default_key (const char * key)
571    
572      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
573      if (!optfile)      if (!optfile)
574          return -1;          return WPTERR_FILE_OPEN;
575      rc = parse_gpg_options (optfile, &opt);      rc = parse_gpg_options (optfile, &opt);
576      if( rc ) {      if (rc) {
577          free_if_alloc (optfile);          free_if_alloc (optfile);
578          return -1;          return WPTERR_GENERAL;
579      }      }
580      e = find_option (opt, "default-key");      e = find_option (opt, "default-key");
581      if (e) {      if (e && !key)
582            e->used = 0;
583        else if (e) {
584          free_if_alloc (e->val);          free_if_alloc (e->val);
585          e->val = m_strdup (key);          e->val = m_strdup (key);
586          e->used = 1;          e->used = 1;
587      }      }
588      else      else if (key)
589          add_entry (opt, ENTRY_MULTI, "default-key", key);          add_entry (opt, ENTRY_MULTI, "default-key", key);
590      rc = commit_gpg_options (optfile, opt);      rc = commit_gpg_options (optfile, opt);
591    
# Line 593  set_gnupg_default_key (const char * key) Line 593  set_gnupg_default_key (const char * key)
593      release_gpg_options (opt);      release_gpg_options (opt);
594    
595      return rc;      return rc;
596  } /* set_gnupg_default_key */  }
597    
598    
599  /*  /*
# Line 916  gnupg_copy_keyrings (void) Line 916  gnupg_copy_keyrings (void)
916      hwnd = GetDesktopWindow ();      hwnd = GetDesktopWindow ();
917    
918      pring = get_fileopen_dlg (hwnd, _("Please choose your public keyring"),      pring = get_fileopen_dlg (hwnd, _("Please choose your public keyring"),
919                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),NULL);                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",NULL);
920      if (!pring) {      if (!pring) {
921          msg_box (hwnd, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR);          msg_box (hwnd, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR);
922          free_if_alloc (path);          free_if_alloc (path);
# Line 936  gnupg_copy_keyrings (void) Line 936  gnupg_copy_keyrings (void)
936      free_if_alloc (file);      free_if_alloc (file);
937    
938      sring = get_fileopen_dlg (hwnd, _("Please choose your secret keyring"),      sring = get_fileopen_dlg (hwnd, _("Please choose your secret keyring"),
939                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"), NULL);                                "GPG Keyrings (*.gpg)\0*.gpg\0\0", NULL);
940      if (!sring) {      if (!sring) {
941          msg_box( NULL, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR );          msg_box( NULL, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR );
942          return WPTERR_GENERAL;          return WPTERR_GENERAL;
# Line 1113  gnupg_backup_keyrings (void) Line 1113  gnupg_backup_keyrings (void)
1113  void  void
1114  gnupg_display_error (void)  gnupg_display_error (void)
1115  {        {      
1116      char tmpath[512], * errstr;      char tmpath[512], *errstr;
1117      size_t size = 0;      size_t size = 0;
1118      FILE * fp;      FILE *fp;
1119    
1120      GetTempPath (sizeof tmpath - 32, (tmpath));      get_temp_name (tmpath, sizeof (tmpath), "gpg_stderr");
     strcat (tmpath, "gpg_stderr");  
1121      size = get_file_size (tmpath);      size = get_file_size (tmpath);
1122      if (file_exist_check (tmpath) || size <= 0)      if (file_exist_check (tmpath) || size <= 0)
1123          return;          return;

Legend:
Removed from v.137  
changed lines
  Added in v.197

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26