/[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 133 by twoaday, Mon Jan 9 09:15:29 2006 UTC revision 200 by twoaday, Mon Apr 17 09:12:50 2006 UTC
# Line 1  Line 1 
1  /* wptGPG.cpp - GnuPG configuration  /* wptGPG.cpp - GnuPG configuration
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 115  get_gnupg_cfgfile (void) Line 115  get_gnupg_cfgfile (void)
115      path = get_gnupg_path ();      path = get_gnupg_path ();
116      if (!path)      if (!path)
117          return NULL;          return NULL;
118      p = get_reg_entry_gpg ("OptFile");      nlen = strlen (path) + 64;
119      if (p && !strcmp (p, "")) {      optfile = new char[nlen + 1];
120          nlen = strlen (path) + 64;      if (!optfile)
121          optfile = new char[nlen + 1];          BUG (NULL);    
122          if (!optfile)      _snprintf (optfile, nlen, "%s\\"GPG_CONF, path);
123              BUG (0);  
         _snprintf (optfile, nlen, "%s\\"GPG_CONF, path);  
     }  
     else if (p) {  
         nlen = strlen( p ) + 4;  
         optfile = new char[nlen + 1];  
         if (!optfile)  
             BUG (NULL);  
         _snprintf (optfile, nlen, "%s", p);  
     }  
     else {  
         nlen = strlen (path) + 64;  
         optfile = new char[nlen + 1];  
         if( !optfile)  
             BUG (NULL);  
         _snprintf (optfile, nlen, "%s\\"GPG_CONF, path);  
     }  
124      free_if_alloc (path);      free_if_alloc (path);
125      free_if_alloc (p);      free_if_alloc (p);
126      return optfile;      return optfile;
# Line 207  get_gnupg_prog (void) Line 191  get_gnupg_prog (void)
191     Return value: the keyid of the secret key. */     Return value: the keyid of the secret key. */
192  static char *  static char *
193  default_key_from_cache (int *ret_no_useable)  default_key_from_cache (int *ret_no_useable)
194  {  {    
195        gpgme_key_t key, pk;
196        gpg_keycache_t sec, pub;
197      const char *s;      const char *s;
198      char *keyid = NULL;      char *keyid = NULL;
     gpgme_key_t key;  
     gpg_keycache_t sec = keycache_get_ctx (0);  
199    
200        sec = keycache_get_ctx (0);
201      if (!sec)      if (!sec)
202          BUG (0);          BUG (0);
203        pub = keycache_get_ctx (1);
204      gpg_keycache_rewind (sec);      gpg_keycache_rewind (sec);
205      while (!gpg_keycache_next_key (sec, 1, &key)) {      while (!gpg_keycache_next_key (sec, 1, &key)) {
206          if (key_is_useable (key)) {          if (key_is_useable (key) && !get_pubkey (key->subkeys->keyid, &pk)) {
207              s = key->subkeys->keyid;              s = key->subkeys->keyid;
208              if (s)                  if (s)
209                  keyid = m_strdup (s+8);                  keyid = m_strdup (s+8);
210              break;              break;
211          }          }
212      }      }
213      if (!keyid)      if (!keyid)
214          *ret_no_useable = 1;          *ret_no_useable = 1;    
215      return keyid;      return keyid;
216  }  }
217    
# Line 239  gnupg_load_config (void) Line 225  gnupg_load_config (void)
225      int rc;      int rc;
226      gpg_optfile_t opt;      gpg_optfile_t opt;
227      gpg_option_t o;      gpg_option_t o;
228      char *conf = get_gnupg_cfgfile ();      char *conf;
229        
230        conf = get_gnupg_cfgfile ();
231      if (!conf)      if (!conf)
232          return -1;          return -1;
233      rc = parse_gpg_options (conf, &opt);      rc = parse_gpg_options (conf, &opt);
# Line 250  gnupg_load_config (void) Line 238  gnupg_load_config (void)
238      o = find_option (opt, "ask-cert-level");      o = find_option (opt, "ask-cert-level");
239      if (o)      if (o)
240          reg_prefs.gpg.ask_cert_level = 1;          reg_prefs.gpg.ask_cert_level = 1;
241        o = find_option (opt, "ask-cert-expire");
242        if (o)
243            reg_prefs.gpg.ask_cert_expire = 1;
244      release_gpg_options (opt);      release_gpg_options (opt);
245      free_if_alloc (conf);      free_if_alloc (conf);
246      return 0;      return 0;
# Line 261  get_gnupg_default_key (void) Line 252  get_gnupg_default_key (void)
252  {      {    
253      gpg_optfile_t opt = NULL;      gpg_optfile_t opt = NULL;
254      gpg_option_t e;      gpg_option_t e;
255      char * keyid = NULL, * optfile = NULL;      char *keyid = NULL, *optfile = NULL;
256      int no_usable=0, rc = 0;      int no_usable=0, rc = 0;
257    
258      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
# Line 272  get_gnupg_default_key (void) Line 263  get_gnupg_default_key (void)
263          free_if_alloc (optfile);          free_if_alloc (optfile);
264          return default_key_from_cache (&no_usable);          return default_key_from_cache (&no_usable);
265      }      }
266      e = find_option( opt, "default-key" );      e = find_option (opt, "default-key");
267      if ( e )      if (!e)
268          keyid = m_strdup( e->val );          e = find_option (opt, "local-user");
269      if( !e ) {      if (e)
270          e = find_option( opt, "local-user" );          keyid = m_strdup (e->val);
271          if( e )  
             keyid = m_strdup( e->val );  
     }  
     if( !e ) {  
         e = find_option( opt, "encrypt-to" );  
         if( e )  
             keyid = m_strdup( e->val );  
     }  
272      free_if_alloc (optfile);      free_if_alloc (optfile);
273      release_gpg_options (opt);      release_gpg_options (opt);
   
274      if (!keyid)      if (!keyid)
275          keyid = default_key_from_cache (&no_usable);          keyid = default_key_from_cache (&no_usable);
276      return keyid;      return keyid;
277  } /* get_gnupg_default_key */  }
278    
279    
280  /* Check if GPG4WIN is available and if so, use the  /* Check if GPG4WIN is available and if so, use the
# Line 325  check_gnupg_prog (void) Line 308  check_gnupg_prog (void)
308    
309    
310  static int  static int
311  parse_version_nr (const char * buf, int *major, int *minor, int *patch)  parse_version_nr (const char *buf, int *major, int *minor, int *patch)
312  {  {
313      char tmp[8];      char tmp[8];
314      int i;      int i;
# Line 334  parse_version_nr (const char * buf, int Line 317  parse_version_nr (const char * buf, int
317      while (buf && *buf != '.' && i < 8)      while (buf && *buf != '.' && i < 8)
318          tmp[i++] = *buf++;          tmp[i++] = *buf++;
319      tmp[i] = 0; buf++;      tmp[i] = 0; buf++;
320      *major = atol( tmp );      *major = atoi (tmp);
321      i=0;      i=0;
322      while (buf && *buf != '.' && i < 8)      while (buf && *buf != '.' && i < 8)
323          tmp[i++] = *buf++;          tmp[i++] = *buf++;
324      tmp[i] = 0; buf++;      tmp[i] = 0; buf++;
325      *minor = atol (tmp);      *minor = atoi (tmp);
326      i=0;      i=0;
327      while (buf && isdigit (*buf) && i < 8)      while (buf && isdigit (*buf) && i < 8)
328          tmp[i++] = *buf++;          tmp[i++] = *buf++;
329      tmp[i] = 0;      tmp[i] = 0;
330      *patch = atol (tmp);      *patch = atoi (tmp);
331      return 0;      return 0;
332  }  }
333    
# Line 353  parse_version_nr (const char * buf, int Line 336  parse_version_nr (const char * buf, int
336     version given in @r_major.@r_minor.@r_patch. On success these     version given in @r_major.@r_minor.@r_patch. On success these
337     variables contain the GPG version which is installed. */     variables contain the GPG version which is installed. */
338  int  int
339  check_gnupg_engine (int *r_major, int *r_minor, int *r_patch)  check_gnupg_engine (const char *need_gpg_ver,
340                        int *r_major, int *r_minor, int *r_patch)
341  {  {
342      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
343      gpgme_engine_info_t inf;      gpgme_engine_info_t inf;
344      char *eng = NULL;      char *eng = NULL;
345      int major=0, minor=0, patch=0;      int major=0, minor=0, patch=0;
346        int need_major = 0, need_minor = 0, need_patch = 0;
347      int rc = 1;      int rc = 1;
348            
349        /* Convert the needed GPG version to the integer format. */
350        if (parse_version_nr (need_gpg_ver,
351                              &need_major, &need_minor, &need_patch))
352            return 1;
353        
354      gpgme_new (&ctx);      gpgme_new (&ctx);
355      inf = gpgme_ctx_get_engine_info (ctx);      inf = gpgme_ctx_get_engine_info (ctx);
356      if (!inf) {      if (!inf) {
# Line 373  check_gnupg_engine (int *r_major, int *r Line 363  check_gnupg_engine (int *r_major, int *r
363          return -1;          return -1;
364      if (strstr (eng, "IDEA"))      if (strstr (eng, "IDEA"))
365          idea_available = 1;          idea_available = 1;
366      free (eng);      safe_free (eng);
367      rc = parse_version_nr (inf->version, &major, &minor, &patch);      if (parse_version_nr (inf->version, &major, &minor, &patch)) {
     if (rc) {  
368          gpgme_release (ctx);          gpgme_release (ctx);
369          return rc;          return 1;
370      }      }
371        gpgme_release (ctx);
372    
373      if (major > *r_major)      if (major > need_major)
374          rc = 0;          rc = 0;
375      else if (major == *r_major && minor > *r_minor)                else if (major == need_major && minor > need_minor)      
376          rc = 0;          rc = 0;
377      else if (major == *r_major && minor == *r_minor &&      else if (major == need_major && minor == need_minor &&
378               patch >= *r_patch)               patch >= need_patch)
379          rc = 0;          rc = 0;
380    
381        /* Return the current GPG version. */
382      *r_major = major;      *r_major = major;
383      *r_minor = minor;      *r_minor = minor;
384      *r_patch = patch;      *r_patch = patch;
# Line 400  check_gnupg_cfgfile (const char *fname, Line 391  check_gnupg_cfgfile (const char *fname,
391  {  {
392      gpg_optfile_t opt;          gpg_optfile_t opt;    
393      gpg_option_t e;      gpg_option_t e;
     int rc = 0;  
394    
395      *r_secrings = 0;      *r_secrings = 0;
396      *r_pubrings = 0;      *r_pubrings = 0;
397      rc = parse_gpg_options( fname, &opt );      if (parse_gpg_options (fname, &opt))
     if( rc )  
398          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
399    
400      for( e = opt->list; e; e = e->next ) {      for (e = opt->list; e; e = e->next) {
401          if( !strcmp( e->name, "secret-keyring" ) ) {          if (!strcmp( e->name, "secret-keyring")) {
402              if( !file_exist_check( e->val ) )              if (!file_exist_check (e->val))
403                  r_secrings[0]++;                  r_secrings[0]++;
404          }          }
405          else if( !strcmp( e->name, "keyring" ) ) {          else if (!strcmp (e->name, "keyring")) {
406              if( !file_exist_check( e->val ) )              if (!file_exist_check (e->val))
407                  r_pubrings[0]++;                  r_pubrings[0]++;
408          }          }
409      }      }
410      release_gpg_options( opt );      release_gpg_options (opt);
411      return 0;      return 0;
412  } /* check_gnupg_cfgfile */  }
413    
414    
415  /* Usually GPG creates the pubring.gpg, secring.gpg on  /* Usually GPG creates the pubring.gpg, secring.gpg on
# Line 430  static void Line 419  static void
419  create_empty_keyring (int _pub)  create_empty_keyring (int _pub)
420  {  {
421      char *name;      char *name;
422      FILE *f;      FILE *fp;
423    
424      name = get_gnupg_keyring (_pub, 0);      name = get_gnupg_keyring (_pub, 0);
425      if (file_exist_check (name) != 0) {      if (name && file_exist_check (name) != 0) {
426          f = fopen (name, "ab");          fp = fopen (name, "ab");
427          if (f != NULL)          if (fp != NULL)
428              fclose (f);              fclose (fp);
429      }      }
430      free_if_alloc (name);      free_if_alloc (name);
431  }  }
# Line 470  gnupg_access_files (void) Line 459  gnupg_access_files (void)
459          rc = file_exist_check (optfile);          rc = file_exist_check (optfile);
460          if (!rc && get_file_size (optfile) > 0) {          if (!rc && get_file_size (optfile) > 0) {
461              rc = check_gnupg_cfgfile (optfile, &secrings, &pubrings);              rc = check_gnupg_cfgfile (optfile, &secrings, &pubrings);
462              if (!rc && secrings && pubrings) {              if (!rc && secrings > 0 && pubrings > 0) {
463                  free_if_alloc (optfile);                  free_if_alloc (optfile);
464                  return 0; /* found two keyrings in the option file */                  return 0; /* found two keyrings in the option file */
465              }              }
# Line 496  create_gpg_options (void) Line 485  create_gpg_options (void)
485      char *s, *optfile;      char *s, *optfile;
486    
487      s = get_gnupg_path ();      s = get_gnupg_path ();
488      if( s == NULL )      if (!s)
489          return WPTERR_FILE_CREAT;          return WPTERR_FILE_CREAT;
490      optfile = make_filename (s, GPG_CONF, NULL);      optfile = make_filename (s, GPG_CONF, NULL);
491      fp = fopen (optfile, "wb");      fp = fopen (optfile, "wb");
492      if (fp == NULL) {        if (!fp) {
493          return WPTERR_FILE_CREAT;          return WPTERR_FILE_CREAT;
494          goto fail;          goto fail;
495      }      }
# Line 511  fail: Line 500  fail:
500      free_if_alloc (s);      free_if_alloc (s);
501      free_if_alloc (optfile);      free_if_alloc (optfile);
502      return 0;      return 0;
503  } /* create_gpg_options */  }
504    
505    
506  /*  /* Return the contents of the options file as a char buf. */
507   * Return the contents of the options file as a char buf.  char*
  */  
 char *  
508  get_gnupg_config (void)  get_gnupg_config (void)
509  {  {
510      FILE * fp;      FILE *fp;
511      char * p = NULL, * optfile = NULL;      char *p = NULL, *optfile = NULL;
512      int fsize, rc = 0;      int fsize, rc = 0;
513                    
514      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
515      if( optfile == NULL )      if (optfile == NULL)
516          return NULL;          return NULL;
517      fsize = get_file_size( optfile );      fsize = get_file_size (optfile);
518      if( !fsize ) {      if (!fsize) {
519          rc = create_gpg_options( );          rc = create_gpg_options ();
520          if ( rc )          if (rc)
521              return NULL;              return NULL;
522          fsize = get_file_size( optfile );          fsize = get_file_size (optfile);
523      }      }
524      if( fsize > 100000 )      if (fsize > 100000)
525          goto leave; /* too large */          goto leave; /* too large */
526      p = new char[fsize+1];      p = new char[fsize+1];
527      if( p == NULL )      if (!p)
528          BUG( NULL );          BUG (NULL);
529      fp = fopen( optfile, "rb" );      fp = fopen( optfile, "rb" );
530      if( fp == NULL ) {      if (!fp) {
531          free_if_alloc( p );          free_if_alloc (p);
532          return NULL;          return NULL;
533      }      }
534      fread( p, 1, fsize, fp );      fread (p, 1, fsize, fp);
535      fclose( fp );      fclose (fp);
536      p[fsize] = '\0';      p[fsize] = '\0';
537      free_if_alloc( optfile );      free_if_alloc (optfile);
538    
539  leave:  leave:
540      return p;      return p;
541  } /* get_gnupg_config */  }
542    
543    
544    /* Set the default key in the gpg.conf.
545       If @key is NULL, the entry will be deleted. */
546  int  int
547  set_gnupg_default_key (const char * key)  set_gnupg_default_key (const char *key)
548  {  {
549      gpg_optfile_t opt;      gpg_optfile_t opt;
550      gpg_option_t e;      gpg_option_t e;
# Line 564  set_gnupg_default_key (const char * key) Line 553  set_gnupg_default_key (const char * key)
553    
554      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
555      if (!optfile)      if (!optfile)
556          return -1;          return WPTERR_FILE_OPEN;
557      rc = parse_gpg_options (optfile, &opt);      rc = parse_gpg_options (optfile, &opt);
558      if( rc ) {      if (rc) {
559          free_if_alloc (optfile);          free_if_alloc (optfile);
560          return -1;          return WPTERR_GENERAL;
561      }      }
562      e = find_option (opt, "default-key");      e = find_option (opt, "default-key");
563      if (e) {      if (e && !key)
564            e->used = 0;
565        else if (e) {
566          free_if_alloc (e->val);          free_if_alloc (e->val);
567          e->val = m_strdup (key);          e->val = m_strdup (key);
568          e->used = 1;          e->used = 1;
569      }      }
570      else      else if (key)
571          add_entry (opt, ENTRY_MULTI, "default-key", key);          add_entry (opt, ENTRY_MULTI, "default-key", key);
572      rc = commit_gpg_options (optfile, opt);      rc = commit_gpg_options (optfile, opt);
573    
# Line 584  set_gnupg_default_key (const char * key) Line 575  set_gnupg_default_key (const char * key)
575      release_gpg_options (opt);      release_gpg_options (opt);
576    
577      return rc;      return rc;
578  } /* set_gnupg_default_key */  }
579    
580    
581  /*  /* Set the contents of the options file. */
  * Set the contents of the options file.  
  */  
582  int  int
583  set_gnupg_options( const char *buf, size_t buflen )  set_gnupg_options( const char *buf, size_t buflen )
584  {  {
# Line 666  get_last_gnupg_access (gpg_watcher_s *ct Line 655  get_last_gnupg_access (gpg_watcher_s *ct
655    
656      path = get_gnupg_path ();      path = get_gnupg_path ();
657      file =  make_filename (path, ctx->object, NULL);      file =  make_filename (path, ctx->object, NULL);
658      fd = CreateFile (file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);      fd = CreateFile (file, GENERIC_READ, FILE_SHARE_READ, NULL,
659                         OPEN_ALWAYS, 0, NULL);
660      if (fd == INVALID_HANDLE_VALUE) {      if (fd == INVALID_HANDLE_VALUE) {
661          free_if_alloc (path);          free_if_alloc (path);
662          free_if_alloc (file);          free_if_alloc (file);
# Line 824  gpg_check_permissions (int showmsg) Line 814  gpg_check_permissions (int showmsg)
814      int failed = 0, ans=0, attrs=0;      int failed = 0, ans=0, attrs=0;
815    
816      p = get_gnupg_path ();      p = get_gnupg_path ();
817      if (check_keyring (&p) && p) {      if (p && check_keyring (&p)) {
818          name = make_filename (p, "pubring", "gpg");          name = make_filename (p, "pubring", "gpg");
819          if ((attrs=GetFileAttributes (name)) & FILE_ATTRIBUTE_READONLY) {          if ((attrs=GetFileAttributes (name)) & FILE_ATTRIBUTE_READONLY) {
820              ans = msg_box (NULL,              ans = msg_box (NULL,
# Line 906  gnupg_copy_keyrings (void) Line 896  gnupg_copy_keyrings (void)
896          return WPTERR_GENERAL;          return WPTERR_GENERAL;
897      hwnd = GetDesktopWindow ();      hwnd = GetDesktopWindow ();
898    
899      pring = get_fileopen_dlg (hwnd, _("Please choose your public keyring"),      pring = get_fileopen_dlg (hwnd, _("Please choose your Public Keyring"),
900                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),NULL);                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",NULL);
901      if (!pring) {      if (!pring) {
902          msg_box (hwnd, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR);          msg_box (hwnd, _("No keyring was chosen. Exit."),
903                     _("WinPT Error"), MB_ERR);
904          free_if_alloc (path);          free_if_alloc (path);
905          return WPTERR_GENERAL;          return WPTERR_GENERAL;
906      }      }
907      file = make_filename (path, "pubring", "gpg");      file = make_filename (path, "pubring", "gpg");
908      if (file_exist_check (file) == 0) {      if (file_exist_check (file) == 0) {
909          id = msg_box (hwnd, _("Overwrite old public keyring?"), "WinPT", MB_INFO|MB_YESNO);          id = msg_box (hwnd, _("Overwrite old public keyring?"),
910                          "WinPT", MB_INFO|MB_YESNO);
911          if (id == IDNO)          if (id == IDNO)
912              goto fail;              goto fail;
913      }      }
# Line 926  gnupg_copy_keyrings (void) Line 918  gnupg_copy_keyrings (void)
918      }      }
919      free_if_alloc (file);      free_if_alloc (file);
920    
921      sring = get_fileopen_dlg (hwnd, _("Please choose your secret keyring"),      sring = get_fileopen_dlg (hwnd, _("Please choose your Secret Keyring"),
922                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"), NULL);                                "GPG Keyrings (*.gpg)\0*.gpg\0\0", NULL);
923      if (!sring) {      if (!sring) {
924          msg_box( NULL, _("No keyring was chosen. Exit."), _("WinPT Error"), MB_ERR );          msg_box (NULL, _("No keyring was chosen. Exit."),
925                     _("WinPT Error"), MB_ERR);
926          return WPTERR_GENERAL;          return WPTERR_GENERAL;
927      }      }
928      file = make_filename (path, "secring", "gpg");      file = make_filename (path, "secring", "gpg");
929      if (file_exist_check (file) == 0) {      if (file_exist_check (file) == 0) {
930          id = msg_box (hwnd, _("Overwrite old secret keyring?"), "WinPT", MB_INFO|MB_YESNO);          id = msg_box (hwnd, _("Overwrite old secret keyring?"),
931          if( id == IDNO )                        "WinPT", MB_INFO|MB_YESNO);
932            if (id == IDNO)
933              goto fail;              goto fail;
934      }      }
935      if (!CopyFile (sring, file, FALSE)) {      if (!CopyFile (sring, file, FALSE)) {
936          msg_box( NULL, _("Could not copy file."), _("WinPT Error"), MB_ERR);          msg_box (NULL, _("Could not copy file."), _("WinPT Error"), MB_ERR);
937          rc = WPTERR_FILE_READ;          rc = WPTERR_FILE_READ;
938      }      }
939    
# Line 947  fail: Line 941  fail:
941      free_if_alloc (file);      free_if_alloc (file);
942      free_if_alloc (path);      free_if_alloc (path);
943      return rc;      return rc;
944  } /* gnupg_import_keyrings */  }
945    
946    
947  /* Backup the gpg.conf file. */  /* Backup the gpg.conf file. */
# Line 970  static int Line 964  static int
964  backup_one_file (const char *srcpath, const char *srcn,  backup_one_file (const char *srcpath, const char *srcn,
965                   const char *dstpath, const char *dstn)                   const char *dstpath, const char *dstn)
966  {  {
967      char * src, * dst;      char *src, *dst;
968      BOOL rc;      BOOL rc;
969    
970      src = make_filename (srcpath, srcn, "gpg");      src = make_filename (srcpath, srcn, "gpg");
# Line 982  backup_one_file (const char *srcpath, co Line 976  backup_one_file (const char *srcpath, co
976      rc = CopyFile (src, dst, FALSE);      rc = CopyFile (src, dst, FALSE);
977      free_if_alloc (src);      free_if_alloc (src);
978      free_if_alloc (dst);      free_if_alloc (dst);
979      if (!rc)      if (!rc) {
     {  
980          log_box (_("Backup"), MB_ERR, _("Backup keyring \"%s\" failed"), srcn);          log_box (_("Backup"), MB_ERR, _("Backup keyring \"%s\" failed"), srcn);
981          return WPTERR_GENERAL;          return WPTERR_GENERAL;
982      }      }
983      return 0;      return 0;
984  } /* backup_one_file */  }
985    
986    
987  /* Figure out first public keyring which is not empty.  /* Figure out first public keyring which is not empty.
# Line 1049  get_backup_name (const char *templ) Line 1042  get_backup_name (const char *templ)
1042  /* Make backups of all keyrings. The public key ring is  /* Make backups of all keyrings. The public key ring is
1043     rotated like this pubring-%d.gpg. */     rotated like this pubring-%d.gpg. */
1044  void  void
1045  gnupg_backup_keyrings (void)  gnupg_backup_keyrings (int auto_backup, int backup_mode)
1046  {  {
1047      char *srcpath = NULL, *dstpath = NULL;      char *srcpath = NULL, *dstpath = NULL;
1048      char *name=NULL;      char *name=NULL;
1049      int rc, bakmode=0;      int rc;
1050    
1051      if (!reg_prefs.auto_backup)      if (!auto_backup)
1052          return;          return;
     bakmode = reg_prefs.backup.mode;  
1053      srcpath = get_gnupg_path ();      srcpath = get_gnupg_path ();
1054      check_keyring (&srcpath);      check_keyring (&srcpath);
1055      if (bakmode == 1) {      if (backup_mode == 1) {
1056          dstpath = multi_gnupg_path (1);          dstpath = multi_gnupg_path (1);
1057          check_keyring (&dstpath);          check_keyring (&dstpath);
1058      }      }
1059      else if (bakmode == 2) {      else if (backup_mode == 2) {
1060          char *tmpfile;          char *tmpfile;
1061          FILE *fp;          FILE *fp;
1062    
# Line 1087  gnupg_backup_keyrings (void) Line 1079  gnupg_backup_keyrings (void)
1079              return;              return;
1080      }      }
1081      else {      else {
1082          log_box (_("Backup"), MB_ERR, _("Invalid backup mode %d"), bakmode);          log_box (_("Backup"), MB_ERR, _("Invalid backup mode %d"), backup_mode);
1083          return;          return;
1084      }      }
1085      name = get_backup_name ("pubring-bak");      name = get_backup_name ("pubring-bak");
# Line 1104  gnupg_backup_keyrings (void) Line 1096  gnupg_backup_keyrings (void)
1096  void  void
1097  gnupg_display_error (void)  gnupg_display_error (void)
1098  {        {      
1099      char tmpath[512], * errstr;      char tmpath[512], *errstr;
1100      size_t size = 0;      size_t size = 0;
1101      FILE * fp;      FILE *fp;
1102    
1103      GetTempPath (sizeof tmpath - 32, (tmpath));      get_temp_name (tmpath, sizeof (tmpath), "gpg_stderr");
     strcat (tmpath, "gpg_stderr");  
1104      size = get_file_size (tmpath);      size = get_file_size (tmpath);
1105      if (file_exist_check (tmpath) || size <= 0)      if (file_exist_check (tmpath) || size <= 0)
1106          return;          return;

Legend:
Removed from v.133  
changed lines
  Added in v.200

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26