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

Diff of /trunk/Src/WinPT.cpp

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

revision 121 by twoaday, Mon Dec 12 11:19:56 2005 UTC revision 135 by twoaday, Mon Jan 9 09:50:55 2006 UTC
# Line 1  Line 1 
1  /* WinPT.cpp - Windows Privacy Tray (WinPT)  /* WinPT.cpp - Windows Privacy Tray (WinPT)
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 40  Line 40 
40  #include "wptCardEdit.h"  #include "wptCardEdit.h"
41  #include "wptCrypto.h"  #include "wptCrypto.h"
42    
43  #define MIN_GPG_VER   "1.4.2"   /* Minimal GPG version. */  #define MIN_GPG_VER   "1.4.2"            /* Minimal GPG version. */
44  #define MIN_GPGME_VER "1.2.0"   /* Minimal GPGME version. */  #define MIN_GPGME_VER NEED_GPGME_VERSION /* Minimal GPGME version. */
45    
46    
47  HINSTANCE glob_hinst;   /* global instance for the dialogs */  HINSTANCE glob_hinst;   /* global instance for the dialogs */
# Line 114  load_gettext (int prev_inst) Line 114  load_gettext (int prev_inst)
114  }  }
115    
116    
117    /* Load the GPG environment. On the first start, some
118       checks are performed to find out in what state GPG is.
119       Return value: 0  everything OK.
120                     >0  fatal error.
121                     -1 public keyring is empty or does not exist. */
122    static int
123    load_gpg_env (void)
124    {
125        SECURITY_ATTRIBUTES sec_attr;
126        char *p;
127        char *pkr;
128    
129        p = get_reg_entry_gpg4win ("gpg.exe");
130        if (!p)
131            return (1);
132        if (file_exist_check (p)) {
133            free_if_alloc (p);
134            return (1);
135        }
136        free_if_alloc (p);
137        p = multi_gnupg_path (0);
138        if (p && dir_exist_check (p)) {
139            memset (&sec_attr, 0, sizeof (sec_attr));
140            sec_attr.nLength = sizeof (sec_attr);
141            if (!CreateDirectory (p, &sec_attr)) {
142                msg_box (NULL, _("Could not create GPG home directory"),
143                         _("WinPT Error"), MB_ERR);
144                free_if_alloc (p);
145                return (2);
146            }
147        }
148        pkr = make_filename (p, "pubring", "gpg");
149        free_if_alloc (p);
150        if (!pkr)
151            return -1;
152        if (get_file_size (pkr) == 0) {
153            free_if_alloc (pkr);
154            return -1;
155        }
156        return 0;
157    }
158    
159    
160  /* check if the default key from the gpg.conf file is available in the  /* check if the default key from the gpg.conf file is available in the
161     keyring. if not, bail out because encryption won't work properly then. */     keyring. if not, bail out because encryption won't work properly then. */
162  static int  static int
# Line 121  check_default_key (gpg_keycache_t kc) Line 164  check_default_key (gpg_keycache_t kc)
164  {  {
165      gpgme_key_t key;      gpgme_key_t key;
166      gpgme_error_t err = GPG_ERR_NO_ERROR;      gpgme_error_t err = GPG_ERR_NO_ERROR;
167      char * defkey;      char *defkey;
168    
169      defkey = get_gnupg_default_key ();      defkey = get_gnupg_default_key ();
170      if (defkey)      if (defkey)
# Line 169  get_prog_part (const char * fname, int u Line 212  get_prog_part (const char * fname, int u
212    
213  /* Check that the underlying crypto engine fullfills the minimal  /* Check that the underlying crypto engine fullfills the minimal
214     requirements so all commands work properly. */     requirements so all commands work properly. */
215  static int  static bool
216  check_crypto_engine (void)  check_crypto_engine (void)
217  {  {
218      int ma=1, mi=4, pa=2; /* GPG 1.4.2 */      int ma=1, mi=4, pa=2; /* GPG 1.4.2 */
# Line 179  check_crypto_engine (void) Line 222  check_crypto_engine (void)
222      if (rc == -1) {      if (rc == -1) {
223          msg_box (NULL, _("Could not read GnuPG version."),          msg_box (NULL, _("Could not read GnuPG version."),
224                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
225          return rc;          return false;
226      }      }
227      else if (rc) {      else if (rc) {
228          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
229                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
230                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),
231                     ma, mi, pa);                     ma, mi, pa);
232          return rc;          return false;
233      }      }
234      /* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */      /* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */
235      if (ma > 1 || pa >= 3)          if (ma > 1 || pa >= 3)    
# Line 195  check_crypto_engine (void) Line 238  check_crypto_engine (void)
238      gpgver[0] = ma;      gpgver[0] = ma;
239      gpgver[1] = mi;      gpgver[1] = mi;
240      gpgver[2] = pa;      gpgver[2] = pa;
241      return rc;      return true;
242  }  }
243    
244    
# Line 220  load_keyserver_conf (int quiet) Line 263  load_keyserver_conf (int quiet)
263  }  }
264    
265    
266    /* Check if both keyrings are empty. This indicates that
267       WinPT should offer to generate a key pair. */
268    static bool
269    check_for_empty_keyrings (bool pub_only)
270    {
271        char *p;
272        int n = 0;
273    
274        p = get_gnupg_keyring (1, 0);
275        if (file_exist_check (p) == 0 && get_file_size (p) == 0)
276            n++;
277        free_if_alloc (p);
278        if (pub_only)
279            return n == 1? true : false;
280        p = get_gnupg_keyring (0, 0);
281        if (file_exist_check (p) == 0 && get_file_size (p) == 0)
282            n++;
283        free_if_alloc (p);
284        return n==2? true : false;
285    }
286    
287    
288  /* Enable the mobility mode. */  /* Enable the mobility mode. */
289  static void  static void
290  enable_mobile_mode (void)  enable_mobile_mode (void)
# Line 289  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 354  WinMain (HINSTANCE hinst, HINSTANCE hpre
354          return 0;          return 0;
355      }      }
356      */      */
357    
358      if (gpg_md_selftest ()) {      if (gpg_md_selftest ()) {
359          msg_box (NULL, _("Cryptographic selftest failed."),          msg_box (NULL, _("Cryptographic selftest failed."),
360                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
# Line 335  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 401  WinMain (HINSTANCE hinst, HINSTANCE hpre
401          gnupg_load_config ();          gnupg_load_config ();
402      }      }
403    
404        if (is_gpg4win_installed ())
405            load_gpg_env (); /* XXX: check return code. */
406    
407      rc = gnupg_check_homedir ();      rc = gnupg_check_homedir ();
408      if (rc) {      if (rc) {
409          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
# Line 399  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 468  WinMain (HINSTANCE hinst, HINSTANCE hpre
468              return 0;              return 0;
469          }          }
470      }      }
471        if (check_for_empty_keyrings (false))
472            first_start = 1;
473    
474      if (!first_start) {      if (!first_start) {
475          rc = gpg_check_permissions (1);          rc = gpg_check_permissions (1);
# Line 485  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 556  WinMain (HINSTANCE hinst, HINSTANCE hpre
556    
557      if (!first_start && !start_gpgprefs) {      if (!first_start && !start_gpgprefs) {
558          gnupg_backup_options ();                  gnupg_backup_options ();        
559          rc = check_crypto_engine ();          if (!check_crypto_engine ()) {
         if (rc) {  
560              DestroyWindow (hwnd);              DestroyWindow (hwnd);
561              free_gnupg_table ();              free_gnupg_table ();
562              return 0;              return 0;
# Line 494  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 564  WinMain (HINSTANCE hinst, HINSTANCE hpre
564      }      }
565            
566      if (start_gpgprefs) {      if (start_gpgprefs) {
         char *ring;  
567          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
568                          gpgprefs_dlg_proc, 0);                          gpgprefs_dlg_proc, 0);
569          ring = get_gnupg_keyring (0, !NO_STRICT);          if (check_for_empty_keyrings (true))
570          if (gnupg_access_keyring (0) == -1 && get_file_size (ring) == 0)              first_start = 1; /* The public keyring is empty! */
             first_start = 1; /* The keyring is empty! */  
         free_if_alloc (ring);  
571      }      }
572    
573      if (first_start) {      if (first_start) {
# Line 531  start: Line 598  start:
598              }              }
599              break;              break;
600    
601          case -1:          case -1: /* Cancel/Abort. */
602              DestroyWindow (hwnd);              DestroyWindow (hwnd);
603              free_gnupg_table ();              free_gnupg_table ();
604              return 0;              return 0;

Legend:
Removed from v.121  
changed lines
  Added in v.135

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26