/[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 304 by twoaday, Wed Mar 21 10:59:31 2007 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 1  Line 1 
1  /* wptGPG.cpp - GnuPG configuration  /* wptGPG.cpp - GnuPG configuration
2   *      Copyright (C) 2001-2007 Timo Schulz   *      Copyright (C) 2001-2009 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 27  Line 27 
27    
28  #include "wptGPG.h"  #include "wptGPG.h"
29  #include "wptGpgCmds.h"  #include "wptGpgCmds.h"
 #include "wptGPGOptSkel.h"  
30  #include "wptTypes.h"  #include "wptTypes.h"
31  #include "wptNLS.h"  #include "wptNLS.h"
32  #include "wptRegistry.h"  #include "wptRegistry.h"
# Line 160  get_gnupg_keyring (int pub, int strict) Line 159  get_gnupg_keyring (int pub, int strict)
159          return keyring;          return keyring;
160      }      }
161      if (file_exist_check (keyring) ||      if (file_exist_check (keyring) ||
162          pub && get_file_size (keyring) == 0) {          (pub && get_file_size (keyring) == 0)) {
163          free_if_alloc (keyring);          free_if_alloc (keyring);
164          optfile = make_filename (path, GPG_CONF, NULL);          optfile = make_filename (path, GPG_CONF, NULL);
165          keyring = get_keyring_from_conf (optfile, pub);          keyring = get_keyring_from_conf (optfile, pub);
# Line 333  check_gnupg_prog (void) Line 332  check_gnupg_prog (void)
332    
333  static int  static int
334  parse_version_nr (const char *buf, int *major, int *minor, int *patch)  parse_version_nr (const char *buf, int *major, int *minor, int *patch)
335  {  {  
336      char tmp[8];      char *p;
337      int i;      char *tmp = m_strdup(buf);
338            
339      i=0;      int pos=0;
340      while (buf && *buf != '.' && i < 8)      while ((p = strsep(&tmp, ".")) != NULL) {
341          tmp[i++] = *buf++;          switch (++pos) {
342      tmp[i] = 0; buf++;          case 1: *major = atoi (p); break;
343      *major = atoi (tmp);          case 2: *minor = atoi (p); break;
344      i=0;          case 3: *patch = atoi (p); break;
345      while (buf && *buf != '.' && i < 8)          }
346          tmp[i++] = *buf++;      }
347      tmp[i] = 0; buf++;      delete[] tmp;  
348      *minor = atoi (tmp);      if (pos != 3)
349      i=0;          return -1;  
     while (buf && isdigit (*buf) && i < 8)  
         tmp[i++] = *buf++;  
     tmp[i] = 0;  
     *patch = atoi (tmp);  
350      return 0;      return 0;
351  }  }
352    
# Line 363  int Line 358  int
358  check_gnupg_engine (const char *need_gpg_ver,  check_gnupg_engine (const char *need_gpg_ver,
359                      int *r_major, int *r_minor, int *r_patch)                      int *r_major, int *r_minor, int *r_patch)
360  {  {
     gpgme_ctx_t ctx;  
361      gpgme_engine_info_t inf;      gpgme_engine_info_t inf;
362      char *eng = NULL;      char *eng = NULL;
363      int major=0, minor=0, patch=0;      int major=0, minor=0, patch=0;
# Line 375  check_gnupg_engine (const char *need_gpg Line 369  check_gnupg_engine (const char *need_gpg
369                            &need_major, &need_minor, &need_patch))                            &need_major, &need_minor, &need_patch))
370          return 1;          return 1;
371            
372      gpgme_new (&ctx);      if (gpgme_get_engine_info (&inf))
373      inf = gpgme_ctx_get_engine_info (ctx);       return -1;
     if (!inf) {  
         gpgme_release (ctx);  
         return -1;  
     }  
374    
375      /* We need to exec GPG again to find out if IDEA is available. */      /* We need to exec GPG again to find out if IDEA is available. */
376      if (gpg_get_version (&eng)) {      if (gpg_get_version (&eng))
377          gpgme_release (ctx);       return -1;
         return -1;  
     }  
378      if (strstr (eng, "IDEA"))      if (strstr (eng, "IDEA"))
379          idea_available = 1;          idea_available = 1;
380      safe_free (eng);      safe_free (eng);
381      if (parse_version_nr (inf->version, &major, &minor, &patch)) {    
382          gpgme_release (ctx);      if (parse_version_nr (inf->version, &major, &minor, &patch))
383          return 1;          return 1;
     }  
     gpgme_release (ctx);  
384    
385      if (major > need_major)      if (major > need_major)
386          rc = 0;          rc = 0;
# Line 506  gnupg_access_files (void) Line 492  gnupg_access_files (void)
492  }  }
493    
494    
 static int  
 create_gpg_conf (void)  
 {  
     FILE *fp;  
     char *s, *optfile;  
   
     s = get_gnupg_path ();  
     if (!s)  
         return WPTERR_FILE_CREAT;  
     optfile = make_filename (s, GPG_CONF, NULL);  
     fp = fopen (optfile, "wb");  
     if (!fp) {  
         return WPTERR_FILE_CREAT;  
         goto fail;  
     }  
     fwrite (options_skel, 1, strlen (options_skel), fp);  
     fclose (fp);  
   
 fail:  
     free_if_alloc (s);  
     free_if_alloc (optfile);  
     return 0;  
 }  
   
495    
496  /* Return the contents of the options file as a char buf. */  /* Return the contents of the options file as a char buf. */
497  char*  char*
498  get_gnupg_config (void)  get_gnupg_config (void)
499  {  {
500      FILE *fp;      FILE *fp;
501      char *p = NULL, *optfile = NULL;      char *p = NULL, *optfile;
502      int fsize;      int fsize;
503                    
504      optfile = get_gnupg_cfgfile ();      optfile = get_gnupg_cfgfile ();
505      if (!optfile)      if (!optfile)
506          return NULL;          return NULL;
507      fsize = get_file_size (optfile);      fsize = get_file_size (optfile);
508      if (!fsize) {      if (fsize < 1 || fsize > 100000)
509          if (create_gpg_conf ())          goto leave; /* too large or does not exist */
510              return NULL;      
511          fsize = get_file_size (optfile);      fp = fopen (optfile, "rb");
512      }      if (!fp)
513      if (fsize > 100000)          goto leave;
         goto leave; /* too large */  
514      p = new char[fsize+1];      p = new char[fsize+1];
515      if (!p)      if (!p)
516          BUG (NULL);          BUG (NULL);
     fp = fopen( optfile, "rb" );  
     if (!fp) {  
         free_if_alloc (p);  
         return NULL;  
     }  
517      fread (p, 1, fsize, fp);      fread (p, 1, fsize, fp);
518      fclose (fp);      fclose (fp);
519      p[fsize] = '\0';      p[fsize] = '\0';
520      free_if_alloc (optfile);      
   
521  leave:  leave:
522        free_if_alloc (optfile);
523      return p;      return p;
524  }  }
525    
# Line 747  init_gnupg_table (void) Line 703  init_gnupg_table (void)
703  void  void
704  free_gnupg_table (void)  free_gnupg_table (void)
705  {  {
706      int j;      for (int j=0; j < gpg_table_count; j++) {
   
     for (j=0; j < gpg_table_count; j++) {  
707          free_if_alloc (gpg_table[j].object);          free_if_alloc (gpg_table[j].object);
708          free_if_alloc (gpg_table[j].fpath_object);          free_if_alloc (gpg_table[j].fpath_object);
709      }      }
# Line 761  int Line 715  int
715  keyring_check_last_access (void)  keyring_check_last_access (void)
716  {  {
717      int nfiles;      int nfiles;
     int pos;  
718    
719      nfiles = 0;      nfiles = 0;
720      for (pos = 0; pos < gpg_table_count; pos++) {      for (int pos = 0; pos < gpg_table_count; pos++) {
721          get_last_gnupg_access (&gpg_table[pos]);          get_last_gnupg_access (&gpg_table[pos]);
722          check_last_gnupg_access (&gpg_table[pos]);          check_last_gnupg_access (&gpg_table[pos]);
723          if (gpg_table[pos].modified)          if (gpg_table[pos].modified)
# Line 900  gnupg_check_homedir (void) Line 853  gnupg_check_homedir (void)
853      int val;      int val;
854      int rc = 0;      int rc = 0;
855    
 #ifdef WINPT_MOBILE  
     return 0;  
 #endif  
   
856      homedir = get_reg_entry_gpg (GPG_REG_HOME);      homedir = get_reg_entry_gpg (GPG_REG_HOME);
857      if (!homedir)      if (!homedir)
858          homedir = multi_gnupg_path (0);          homedir = multi_gnupg_path (0);
# Line 929  int Line 878  int
878  gnupg_copy_keyrings (void)  gnupg_copy_keyrings (void)
879  {  {
880      const char *pring, *sring;      const char *pring, *sring;
881      char *file = NULL, *path = NULL;      char *file = NULL, *path;
882      int id = 0, rc = 0;      int id, rc = 0;
883      HWND hwnd;      HWND hwnd;
884            
885      path = get_gnupg_path ();      path = get_gnupg_path ();
# Line 939  gnupg_copy_keyrings (void) Line 888  gnupg_copy_keyrings (void)
888      hwnd = GetDesktopWindow ();      hwnd = GetDesktopWindow ();
889    
890      pring = get_fileopen_dlg (hwnd, _("Please choose your Public Keyring"),      pring = get_fileopen_dlg (hwnd, _("Please choose your Public Keyring"),
891                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",NULL);                                "GPG Keyrings (*.gpg)\0*.gpg\0\0", NULL);
892      if (!pring) {      if (!pring) {
893          msg_box (hwnd, _("No keyring was chosen. Exit."),          msg_box (hwnd, _("No keyring was chosen. Exit."),
894                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
895          free_if_alloc (path);          free_if_alloc (path);
896          return WPTERR_GENERAL;          return WPTERR_GENERAL;
897      }      }
898      file = make_filename (path, "pubring", "gpg");      file = make_filename (path, "pubring", "gpg");
899      if (file_exist_check (file) == 0) {      if (file_exist_check (file) == 0) {
900          id = msg_box (hwnd, _("Overwrite old public keyring?"),          id = msg_box (hwnd, _("Overwrite old public keyring?"),
901                        "WinPT", MB_INFO|MB_YESNO);                        "WinPT", MB_INFO|MB_YESNO);
902          if (id == IDNO)          if (id == IDNO)
903              goto fail;              goto fail;
904      }      }
905      if (!CopyFile (pring, file, FALSE)) {      if (!CopyFile (pring, file, FALSE)) {
906          msg_box (hwnd, _("Could not copy file."), _("WinPT Error"), MB_ERR);          msg_box (hwnd, _("Could not copy public keyring."),
907                     _("WinPT Error"), MB_ERR);
908          rc = WPTERR_FILE_READ;          rc = WPTERR_FILE_READ;
909          goto fail;          goto fail;
910      }      }
# Line 975  gnupg_copy_keyrings (void) Line 925  gnupg_copy_keyrings (void)
925              goto fail;              goto fail;
926      }      }
927      if (!CopyFile (sring, file, FALSE)) {      if (!CopyFile (sring, file, FALSE)) {
928          msg_box (NULL, _("Could not copy file."), _("WinPT Error"), MB_ERR);          msg_box (NULL, _("Could not copy secret keyring."), _("WinPT Error"), MB_ERR);
929          rc = WPTERR_FILE_READ;          rc = WPTERR_FILE_READ;
930      }      }
931    

Legend:
Removed from v.304  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26