/[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 248 by twoaday, Fri Jul 28 11:11:09 2006 UTC revision 270 by twoaday, Sat Oct 21 18:08:57 2006 UTC
# Line 43  Line 43 
43  #define GPG_REG_EXE     "gpgProgram"    /* registry name for the binary. */  #define GPG_REG_EXE     "gpgProgram"    /* registry name for the binary. */
44  #define GPG_REG_HOME    "HomeDir"       /* registry name of the home dir. */  #define GPG_REG_HOME    "HomeDir"       /* registry name of the home dir. */
45    
46  struct gpg_watcher_s {  /* Context to monitor GPG file changes. */
47      FILETIME    last_access;  struct gpg_monitor_s {
48        FILETIME    last_access;    /* last write access. */
49      FILETIME    access;      FILETIME    access;
50      char        *object;      char        *object;        /* name of the object. */
51      int         modified;      char        *fpath_object;  /* full path to the object. */
52        int         modified;       /* 1 = modified. */
53  };  };
54    typedef struct gpg_monitor_s *gpg_monitor_t;
55    
56    static const char *gpg_objs[] = {"pubring.gpg", "secring.gpg", "trustdb.gpg"};
57  /* XXX need to watch for gpg.conf due to the fact keyring entries could be changed */  static gpg_monitor_s gpg_table[3];
 static const char * gpg_objs[] = {"pubring.gpg", "secring.gpg", "trustdb.gpg"};  
 static gpg_watcher_s gpg_table[3];  
58  static int gpg_table_count = DIM (gpg_table);  static int gpg_table_count = DIM (gpg_table);
59    
60  int idea_available = 0;  int idea_available = 0; /* if the IDEA extension is available. */
61    
62    
63  static int check_keyring (char ** r_path);  static int check_keyring (char ** r_path);
64    
# Line 95  get_gnupg_path (void) Line 97  get_gnupg_path (void)
97      if (path && dir_exist_check (path) == 0)      if (path && dir_exist_check (path) == 0)
98          return path;          return path;
99      free_if_alloc (path);      free_if_alloc (path);
100      path = multi_gnupg_path (1);      return multi_gnupg_path (1);
     return path;  
101  }  }
102    
103    
# Line 104  get_gnupg_path (void) Line 105  get_gnupg_path (void)
105     A value of NULL indicates an error. */     A value of NULL indicates an error. */
106  char*  char*
107  get_gnupg_cfgfile (void)  get_gnupg_cfgfile (void)
108  {      {
     char *p = NULL;  
109      char *optfile = NULL;      char *optfile = NULL;
110      char *path = NULL;      char *path;
111      size_t nlen = 0;      size_t nlen;
112    
113      path = get_gnupg_path ();      path = get_gnupg_path ();
114      if (!path)      if (!path)
# Line 116  get_gnupg_cfgfile (void) Line 116  get_gnupg_cfgfile (void)
116      nlen = strlen (path) + 64;      nlen = strlen (path) + 64;
117      optfile = new char[nlen + 1];      optfile = new char[nlen + 1];
118      if (!optfile)      if (!optfile)
119          BUG (NULL);              BUG (NULL);
120      _snprintf (optfile, nlen, "%s\\"GPG_CONF, path);      _snprintf (optfile, nlen, "%s\\"GPG_CONF, path);
121    
122      free_if_alloc (path);      free_if_alloc (path);
     free_if_alloc (p);  
123      return optfile;      return optfile;
124  }  }
125    
# Line 173  get_gnupg_prog (void) Line 172  get_gnupg_prog (void)
172      if (!path)      if (!path)
173          return NULL;              return NULL;    
174      pgm = make_filename (path, "gpg", "exe");      pgm = make_filename (path, "gpg", "exe");
175      free_if_alloc (path);          free_if_alloc (path);
176      return pgm;      return pgm;
177  }  }
178    
# Line 181  get_gnupg_prog (void) Line 180  get_gnupg_prog (void)
180  /* Retrieve the first usable secret key from cache.  /* Retrieve the first usable secret key from cache.
181     If no usable was found, @ret_no_useable is 1.     If no usable was found, @ret_no_useable is 1.
182     Return value: the keyid of the secret key. */     Return value: the keyid of the secret key. */
183  static char *  static char*
184  default_key_from_cache (int *ret_no_useable)  default_key_from_cache (int *ret_no_useable)
185  {      {    
186      gpgme_key_t key, pk;      gpgme_key_t key, pk;
# Line 211  default_key_from_cache (int *ret_no_usea Line 210  default_key_from_cache (int *ret_no_usea
210     Return value: 0 on success. */     Return value: 0 on success. */
211  int  int
212  gnupg_load_config (void)  gnupg_load_config (void)
213  {  {    
     int rc;  
214      gpg_optfile_t opt;      gpg_optfile_t opt;
     gpg_option_t o;  
215      char *conf;      char *conf;
216            
217      conf = get_gnupg_cfgfile ();      conf = get_gnupg_cfgfile ();
218      if (!conf)      if (!conf)
219          return -1;          return -1;
220      rc = parse_gpg_options (conf, &opt);      if (parse_config (conf, &opt)) {
     if (rc) {  
221          free_if_alloc (conf);          free_if_alloc (conf);
222          return -1;          return -1;
223      }      }
224      o = find_option (opt, "ask-cert-level");      if (find_option (opt, "ask-cert-level"))
     if (o)  
225          reg_prefs.gpg.ask_cert_level = 1;          reg_prefs.gpg.ask_cert_level = 1;
226      o = find_option (opt, "ask-cert-expire");      if (find_option (opt, "ask-cert-expire"))
     if (o)  
227          reg_prefs.gpg.ask_cert_expire = 1;          reg_prefs.gpg.ask_cert_expire = 1;
228      release_gpg_options (opt);      release_config (opt);
229      free_if_alloc (conf);      free_if_alloc (conf);
230      return 0;      return 0;
231  }  }
# Line 261  get_gnupg_default_key (void) Line 255  get_gnupg_default_key (void)
255      gpg_optfile_t opt = NULL;      gpg_optfile_t opt = NULL;
256      gpg_option_t e;      gpg_option_t e;
257      char *keyid = NULL, *optfile = NULL;      char *keyid = NULL, *optfile = NULL;
258      int no_usable=0, rc = 0;      int no_usable=0;
259    
260      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
261      if (!optfile)      if (!optfile)
262          return default_key_from_cache (&no_usable);          return default_key_from_cache (&no_usable);
263      rc = parse_gpg_options (optfile, &opt);      if (parse_config (optfile, &opt)) {
     if (rc) {  
264          free_if_alloc (optfile);          free_if_alloc (optfile);
265          return default_key_from_cache (&no_usable);          return default_key_from_cache (&no_usable);
266      }      }
# Line 278  get_gnupg_default_key (void) Line 271  get_gnupg_default_key (void)
271          keyid = extract_keyid (e->val);          keyid = extract_keyid (e->val);
272    
273      free_if_alloc (optfile);      free_if_alloc (optfile);
274      release_gpg_options (opt);      release_config (opt);
275      if (!keyid)      if (!keyid)
276          keyid = default_key_from_cache (&no_usable);          keyid = default_key_from_cache (&no_usable);
277      return keyid;      return keyid;
# Line 396  check_gnupg_engine (const char *need_gpg Line 389  check_gnupg_engine (const char *need_gpg
389  }  }
390    
391    
392  int  /* Count the keyring entries in the gpg.conf file.
393  check_gnupg_cfgfile (const char *fname, int *r_secrings, int *r_pubrings)     Return value: 0 on success. */
394    static int
395    cfgfile_count_keyrings (const char *fname, int *r_secrings, int *r_pubrings)
396  {  {
397      gpg_optfile_t opt;          gpg_optfile_t opt;    
398      gpg_option_t e;      gpg_option_t e;
# Line 405  check_gnupg_cfgfile (const char *fname, Line 400  check_gnupg_cfgfile (const char *fname,
400      *r_secrings = 0;      *r_secrings = 0;
401      *r_pubrings = 0;      *r_pubrings = 0;
402    
403      if (parse_gpg_options (fname, &opt))      if (parse_config (fname, &opt))
404          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
405      for (e = opt->list; e; e = e->next) {      for (e = opt->list; e; e = e->next) {
406          if (!strcmp( e->name, "secret-keyring")) {          if (!strcmp (e->name, "secret-keyring")) {
407              if (!file_exist_check (e->val))              if (!file_exist_check (e->val))
408                  r_secrings[0]++;                  r_secrings[0]++;
409          }          }
# Line 417  check_gnupg_cfgfile (const char *fname, Line 412  check_gnupg_cfgfile (const char *fname,
412                  r_pubrings[0]++;                  r_pubrings[0]++;
413          }          }
414      }      }
415      release_gpg_options (opt);      release_config (opt);
416      return 0;      return 0;
417  }  }
418    
# Line 468  gnupg_access_files (void) Line 463  gnupg_access_files (void)
463              return WPTERR_GPG_KEYRINGS;              return WPTERR_GPG_KEYRINGS;
464          rc = file_exist_check (optfile);          rc = file_exist_check (optfile);
465          if (!rc && get_file_size (optfile) > 0) {          if (!rc && get_file_size (optfile) > 0) {
466              rc = check_gnupg_cfgfile (optfile, &secrings, &pubrings);              rc = cfgfile_count_keyrings (optfile, &secrings, &pubrings);
467              if (!rc && secrings > 0 && pubrings > 0) {              if (!rc && secrings > 0 && pubrings > 0) {
468                  free_if_alloc (optfile);                  free_if_alloc (optfile);
469                  return 0; /* found two keyrings in the option file */                  return 0; /* found two keyrings in the option file */
# Line 489  gnupg_access_files (void) Line 484  gnupg_access_files (void)
484    
485    
486  static int  static int
487  create_gpg_options (void)  create_gpg_conf (void)
488  {  {
489      FILE *fp;      FILE *fp;
490      char *s, *optfile;      char *s, *optfile;
# Line 519  get_gnupg_config (void) Line 514  get_gnupg_config (void)
514  {  {
515      FILE *fp;      FILE *fp;
516      char *p = NULL, *optfile = NULL;      char *p = NULL, *optfile = NULL;
517      int fsize, rc = 0;      int fsize;
518                    
519      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
520      if (optfile == NULL)      if (!optfile)
521          return NULL;          return NULL;
522      fsize = get_file_size (optfile);      fsize = get_file_size (optfile);
523      if (!fsize) {      if (!fsize) {
524          rc = create_gpg_options ();          if (create_gpg_conf ())
         if (rc)  
525              return NULL;              return NULL;
526          fsize = get_file_size (optfile);          fsize = get_file_size (optfile);
527      }      }
# Line 564  set_gnupg_default_key (const char *key) Line 558  set_gnupg_default_key (const char *key)
558      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
559      if (!optfile)      if (!optfile)
560          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
561      rc = parse_gpg_options (optfile, &opt);      rc = parse_config (optfile, &opt);
562      if (rc) {      if (rc) {
563          free_if_alloc (optfile);          free_if_alloc (optfile);
564          return WPTERR_GENERAL;          return WPTERR_GENERAL;
# Line 579  set_gnupg_default_key (const char *key) Line 573  set_gnupg_default_key (const char *key)
573      }      }
574      else if (key)      else if (key)
575          add_entry (opt, ENTRY_MULTI, "default-key", key);          add_entry (opt, ENTRY_MULTI, "default-key", key);
576      rc = commit_gpg_options (optfile, opt);      rc = commit_config (optfile, opt);
577    
578      free_if_alloc (optfile);      free_if_alloc (optfile);
579      release_gpg_options (opt);      release_config (opt);
   
580      return rc;      return rc;
581  }  }
582    
# Line 593  int Line 586  int
586  set_gnupg_options (const char *buf, size_t buflen)  set_gnupg_options (const char *buf, size_t buflen)
587  {  {
588      FILE *fp;        FILE *fp;  
589      char *optfile = NULL;      char *optfile;
590    
591      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
592      if (!optfile)      if (!optfile)
# Line 611  set_gnupg_options (const char *buf, size Line 604  set_gnupg_options (const char *buf, size
604  }  }
605    
606    
607  /*  /* Check if the parameter for the option @buf is an existing file name.
608   * Check if the line contains a valid GPG argument.     Return value: 0 on success. */
609   */  static int
610    check_arg_file_exist (const char *buf)
611    {
612        const char *s = "load-extension ";
613    
614        /* XXX: this is a bit of a kludge because we just
615                detect errors for 'load-extension'. */
616        if (!strncmp (buf, s, strlen (s)))
617            buf += strlen (s);
618        else
619            return 0;
620        return file_exist_check (buf);
621    }
622    
623    
624    /* Check if the line contains a valid GPG argument. */
625  static int  static int
626  check_line (const char *buf)  check_line (const char *buf)
627  {  {
628      int j, len;      int j, len;
629      int rc = 0;      int rc;
630    
631      if (*buf == '#' || *buf == '\r' || *buf == '\n')      if (*buf == '#' || *buf == '\r' || *buf == '\n')
632          return 1;          return 1;
# Line 628  check_line (const char *buf) Line 636  check_line (const char *buf)
636          if (!strncmp (valid_gpg_args[j], buf, len))          if (!strncmp (valid_gpg_args[j], buf, len))
637              rc = 1;              rc = 1;
638      }      }
   
639      return rc;      return rc;
640  }  }
641    
642    
643  int  int
644  check_gnupg_options (const char *buf)  check_gnupg_options (const char *buf, int showerr)
645  {  {
646      char line[1024];      char line[1024];
647      int nbytes = 0;      int nbytes = 0, lineno=0;
648      unsigned j;      unsigned j;
649                    
650      for ( j = 0; j<strlen( buf ) && j < sizeof(line); j++ ) {      for  (j = 0; j < strlen (buf) && j < sizeof (line); j++) {
651          line[nbytes++] = buf[j];          line[nbytes++] = buf[j];
652          if ( buf[j] == '\n' || j == ( strlen( buf ) - 1 ) ) {          if (buf[j] == '\n' || j == (strlen (buf) - 1)) {
653              line[nbytes] = '\0';              line[nbytes] = '\0';
654              if( !check_line( line ) ) {              lineno++;
655                  msg_box( NULL, line, "options", MB_OK );              if (!check_line (line)) {
656                    if (showerr)
657                        log_box ("GPG Config File", MB_ERR,
658                                 "gpg.conf:%d: invalid keyword '%s'",
659                                 lineno, line);
660                  return 1;                        return 1;      
661              }              }
662                if (check_arg_file_exist (line))
663                    return WPTERR_FILE_EXIST;
664              nbytes = 0;              nbytes = 0;
665          }                }
666      }      }
   
667      return 0;      return 0;
668  }  }
669    
670    
671  /* Store the last access of the file inside the watcher @ctx. */  /* Store the last access of the file inside the watcher @ctx. */
672  static int  static int
673  get_last_gnupg_access (gpg_watcher_s *ctx)  get_last_gnupg_access (gpg_monitor_t ctx)
674  {  {
675      HANDLE fd;      HANDLE fd;
     char *path;  
     char *file;  
676    
677      path = get_gnupg_path ();      fd = CreateFile (ctx->fpath_object, GENERIC_READ, FILE_SHARE_READ,
678      file =  make_filename (path, ctx->object, NULL);                       NULL, OPEN_ALWAYS, 0, NULL);
679      fd = CreateFile (file, GENERIC_READ, FILE_SHARE_READ, NULL,      if (fd == INVALID_HANDLE_VALUE)
                      OPEN_ALWAYS, 0, NULL);  
     if (fd == INVALID_HANDLE_VALUE) {  
         free_if_alloc (path);  
         free_if_alloc (file);  
680          return WPTERR_FILE_OPEN;          return WPTERR_FILE_OPEN;
     }  
681      GetFileTime (fd, NULL, NULL, &ctx->access);      GetFileTime (fd, NULL, NULL, &ctx->access);
682      CloseHandle (fd);      CloseHandle (fd);
     free_if_alloc (path);  
     free_if_alloc (file);  
683      return 0;      return 0;
684  }  }
685    
686    
687  /* Check if the file inside watcher @ctx was modified. */  /* Check if the file inside watcher @ctx was modified. */
688  static void  static void
689  check_last_gnupg_access (gpg_watcher_s *ctx)  check_last_gnupg_access (gpg_monitor_t ctx)
690  {                {              
691      ctx->modified = 0;      ctx->modified = 0;
692    
693      if (ctx->last_access.dwHighDateTime != ctx->access.dwHighDateTime &&      if (ctx->last_access.dwHighDateTime != ctx->access.dwHighDateTime &&
694          ctx->last_access.dwLowDateTime != ctx->access.dwLowDateTime)          ctx->last_access.dwLowDateTime != ctx->access.dwLowDateTime)
695          ctx->modified = 1;          ctx->modified = 1;
696        
     /* XXX: find a better way. without it, winpt --keymanager loads  
             the key cache twice. */  
697      if (ctx->last_access.dwLowDateTime == 0)      if (ctx->last_access.dwLowDateTime == 0)
698          ctx->modified = 0;          ctx->modified = 0;
699    
# Line 701  check_last_gnupg_access (gpg_watcher_s * Line 702  check_last_gnupg_access (gpg_watcher_s *
702  }  }
703    
704    
705  /* Init GPG watcher table for all monitored files. */  /* Init GPG monitor table for all monitored files. */
706  void  void
707  init_gnupg_table (void)  init_gnupg_table (void)
708  {        {      
709      char *p;      char *path;
710      int j;      int j;
711    
712        path = get_gnupg_path ();
713      for (j = 0; j < gpg_table_count; j++) {      for (j = 0; j < gpg_table_count; j++) {
714          p = gpg_table[j].object = m_strdup (gpg_objs[j]);          gpg_table[j].object = m_strdup (gpg_objs[j]);
715            gpg_table[j].fpath_object = make_filename (path, gpg_objs[j], NULL);
716          memset (&gpg_table[j].access, 0, sizeof (FILETIME));          memset (&gpg_table[j].access, 0, sizeof (FILETIME));
717          memset (&gpg_table[j].last_access, 0, sizeof (FILETIME));          memset (&gpg_table[j].last_access, 0, sizeof (FILETIME));
718          gpg_table[j].modified = 0;          gpg_table[j].modified = 0;
719      }      }
720        free_if_alloc (path);
721  }  }
722    
723    
724    /* Release the GPG monitor table. */
725  void  void
726  free_gnupg_table (void)  free_gnupg_table (void)
727  {  {
728      int j;      int j;
729    
730      for (j=0; j < gpg_table_count; j++)      for (j=0; j < gpg_table_count; j++) {
731          free_if_alloc (gpg_table[j].object);          free_if_alloc (gpg_table[j].object);
732            free_if_alloc (gpg_table[j].fpath_object);
733        }
734  }  }
735    
736    
737  /* Return the amount of files modified since the last call. */  /* Return the amount of files modified since the last call. */
738  int  int
739  keyring_check_last_access (void)  keyring_check_last_access (void)
740  {        {
741      int rc, j;      int nfiles;
742        int pos;
743    
744      rc = 0;      nfiles = 0;
745      for (j = 0; j < gpg_table_count; j++) {      for (pos = 0; pos < gpg_table_count; pos++) {
746          get_last_gnupg_access (&gpg_table[j]);          get_last_gnupg_access (&gpg_table[pos]);
747          check_last_gnupg_access (&gpg_table[j]);          check_last_gnupg_access (&gpg_table[pos]);
748          if (gpg_table[j].modified)          if (gpg_table[pos].modified)
749              rc++;                    nfiles++;
750      }      }
751    
752      return rc;      return nfiles;
753  }  }
754    
755    
# Line 764  gnupg_check_file_ext (const char *fname, Line 772  gnupg_check_file_ext (const char *fname,
772              *r_type = PGP_SIG;              *r_type = PGP_SIG;
773          return "SIGNED";          return "SIGNED";
774      }      }
775      else if  (!stricmp (file_ext, ".gpg") || !stricmp (file_ext, ".pgp")) {      else if  (!stricmp (file_ext, ".gpg") ||
776                  !stricmp (file_ext, ".pgp")) {
777          if (r_type)          if (r_type)
778              *r_type = PGP_MESSAGE;              *r_type = PGP_MESSAGE;
779          return "ENCRYPTED";          return "ENCRYPTED";
# Line 774  gnupg_check_file_ext (const char *fname, Line 783  gnupg_check_file_ext (const char *fname,
783    
784    
785  char*  char*
786  get_gnupg_keyring_from_options (const char * fname, int pub)  get_gnupg_keyring_from_options (const char *fname, int pub)
787  {  {
788      gpg_optfile_t opt;      gpg_optfile_t opt;
789      gpg_option_t e;      gpg_option_t e;
790      char * kring = NULL;      char *kring = NULL;
791      int rc = 0;      int rc;
792    
793      rc = parse_gpg_options (fname, &opt);      rc = parse_config (fname, &opt);
794      if (rc)      if (rc)
795          return NULL;          return NULL;
796      if (pub)      if (pub)
# Line 790  get_gnupg_keyring_from_options (const ch Line 799  get_gnupg_keyring_from_options (const ch
799          e = find_option (opt, "secret-keyring");          e = find_option (opt, "secret-keyring");
800      if (e)      if (e)
801          kring = m_strdup (e->val);          kring = m_strdup (e->val);
802      release_gpg_options (opt);      release_config (opt);
803    
804      return kring;      return kring;
805  }  }
806    
807    
808    /* Check if the device file @fname is stored on, is write-protected. */
 /* XXX: does not work with write-protected floppies */  
809  static int  static int
810  my_access (const char *fname)  my_access (const char *fname)
811  {  {
812      HANDLE hd;      HANDLE hd;
813    
814      hd = CreateFile (fname, GENERIC_WRITE, FILE_SHARE_WRITE,      hd = CreateFile (fname, GENERIC_WRITE, FILE_SHARE_WRITE,
815                       NULL, OPEN_EXISTING, 0, NULL);                       NULL, OPEN_EXISTING, 0, NULL);
816      if (hd == INVALID_HANDLE_VALUE)      if (hd == INVALID_HANDLE_VALUE)
# Line 867  gpg_check_permissions (int showmsg) Line 876  gpg_check_permissions (int showmsg)
876  int  int
877  gnupg_check_homedir (void)  gnupg_check_homedir (void)
878  {        {      
879      char *homedir = NULL;      char *homedir;
880      int val = 0;      int val;
881      int rc = 0;      int rc = 0;
882    
883      homedir = get_reg_entry_gpg (GPG_REG_HOME);      homedir = get_reg_entry_gpg (GPG_REG_HOME);
# Line 895  gnupg_check_homedir (void) Line 904  gnupg_check_homedir (void)
904  int  int
905  gnupg_copy_keyrings (void)  gnupg_copy_keyrings (void)
906  {  {
907      const char * pring, * sring;      const char *pring, *sring;
908      char * file = NULL, * path = NULL;      char *file = NULL, *path = NULL;
909      int id = 0, rc = 0;      int id = 0, rc = 0;
910      HWND hwnd;      HWND hwnd;
911            
# Line 957  fail: Line 966  fail:
966  void  void
967  gnupg_backup_options (void)  gnupg_backup_options (void)
968  {  {
969      char *cfgfile = NULL;      char *cfgfile;
970      char bak[512];      char bak[MAX_PATH+32];
971    
972      cfgfile = get_gnupg_cfgfile ();      cfgfile = get_gnupg_cfgfile ();
973      if (!cfgfile)      if (!cfgfile)
# Line 977  backup_one_file (const char *srcpath, co Line 986  backup_one_file (const char *srcpath, co
986      BOOL rc;      BOOL rc;
987    
988      src = make_filename (srcpath, srcn, "gpg");      src = make_filename (srcpath, srcn, "gpg");
     if (!src)  
         BUG (NULL);  
989      dst = make_filename (dstpath, dstn, "gpg");      dst = make_filename (dstpath, dstn, "gpg");
     if (!dst)  
         BUG (NULL);  
990      rc = CopyFile (src, dst, FALSE);      rc = CopyFile (src, dst, FALSE);
991      free_if_alloc (src);      free_if_alloc (src);
992      free_if_alloc (dst);      free_if_alloc (dst);
# Line 1005  check_keyring (char **r_path) Line 1010  check_keyring (char **r_path)
1010      if (!*r_path)      if (!*r_path)
1011          return 0;          return 0;
1012      p = make_filename (*r_path, "pubring", "gpg");      p = make_filename (*r_path, "pubring", "gpg");
1013      if (!p || get_file_size (p) <= 0)      if (get_file_size (p) <= 0)
1014          return 0;          return 0;
1015    
1016      opt = get_gnupg_cfgfile ();      opt = get_gnupg_cfgfile ();
# Line 1081  gnupg_backup_keyrings (int auto_backup, Line 1086  gnupg_backup_keyrings (int auto_backup,
1086          else {          else {
1087              rc = 0;              rc = 0;
1088              fclose (fp);              fclose (fp);
1089              remove (tmpfile);              DeleteFile (tmpfile);
1090          }          }
1091          free_if_alloc (tmpfile);          free_if_alloc (tmpfile);
1092          if (!fp || rc == IDCANCEL)          if (!fp || rc == IDCANCEL)
# Line 1101  gnupg_backup_keyrings (int auto_backup, Line 1106  gnupg_backup_keyrings (int auto_backup,
1106  }  }
1107    
1108    
 /* Display GPG error from file if possible. */  
 void  
 gnupg_display_error (void)  
 {        
     char tmpath[512], *errstr;  
     size_t size = 0;  
     FILE *fp;  
   
     get_temp_name (tmpath, sizeof (tmpath), "gpg_stderr");  
     size = get_file_size (tmpath);  
     if (file_exist_check (tmpath) || size <= 0)  
         return;  
     fp = fopen( tmpath, "rb" );  
     if (!fp) {  
         msg_box (NULL, _("No GPG error description available."),  
                  _("GPG Error"), MB_INFO);  
         return;  
     }  
     errstr = new char[size+1];  
     if (!errstr)  
         BUG (0);  
     fread (errstr, 1, size, fp);  
     errstr[size] = '\0';  
     fclose (fp);  
     msg_box (NULL, errstr, _("GPG Error"), MB_INFO);  
     free_if_alloc (errstr);  
 }  
   
   
   
1109  /* check that the requested GPG keyring exist and.  /* check that the requested GPG keyring exist and.
1110     Return value: 0 for success. */     Return value: 0 for success. */
1111  int  int

Legend:
Removed from v.248  
changed lines
  Added in v.270

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26