/[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 127 by twoaday, Mon Dec 12 11:19:56 2005 UTC revision 128 by twoaday, Mon Dec 19 13:05:59 2005 UTC
# 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  /* 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
160     keyring. if not, bail out because encryption won't work properly then. */     keyring. if not, bail out because encryption won't work properly then. */
161  static int  static int
# Line 121  check_default_key (gpg_keycache_t kc) Line 163  check_default_key (gpg_keycache_t kc)
163  {  {
164      gpgme_key_t key;      gpgme_key_t key;
165      gpgme_error_t err = GPG_ERR_NO_ERROR;      gpgme_error_t err = GPG_ERR_NO_ERROR;
166      char * defkey;      char *defkey;
167    
168      defkey = get_gnupg_default_key ();      defkey = get_gnupg_default_key ();
169      if (defkey)      if (defkey)
# Line 169  get_prog_part (const char * fname, int u Line 211  get_prog_part (const char * fname, int u
211    
212  /* Check that the underlying crypto engine fullfills the minimal  /* Check that the underlying crypto engine fullfills the minimal
213     requirements so all commands work properly. */     requirements so all commands work properly. */
214  static int  static bool
215  check_crypto_engine (void)  check_crypto_engine (void)
216  {  {
217      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 221  check_crypto_engine (void)
221      if (rc == -1) {      if (rc == -1) {
222          msg_box (NULL, _("Could not read GnuPG version."),          msg_box (NULL, _("Could not read GnuPG version."),
223                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
224          return rc;          return false;
225      }      }
226      else if (rc) {      else if (rc) {
227          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
228                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
229                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),
230                     ma, mi, pa);                     ma, mi, pa);
231          return rc;          return false;
232      }      }
233      /* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */      /* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */
234      if (ma > 1 || pa >= 3)          if (ma > 1 || pa >= 3)    
# Line 195  check_crypto_engine (void) Line 237  check_crypto_engine (void)
237      gpgver[0] = ma;      gpgver[0] = ma;
238      gpgver[1] = mi;      gpgver[1] = mi;
239      gpgver[2] = pa;      gpgver[2] = pa;
240      return rc;      return true;
241  }  }
242    
243    
# Line 289  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 331  WinMain (HINSTANCE hinst, HINSTANCE hpre
331          return 0;          return 0;
332      }      }
333      */      */
334    
335      if (gpg_md_selftest ()) {      if (gpg_md_selftest ()) {
336          msg_box (NULL, _("Cryptographic selftest failed."),          msg_box (NULL, _("Cryptographic selftest failed."),
337                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
# Line 335  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 378  WinMain (HINSTANCE hinst, HINSTANCE hpre
378          gnupg_load_config ();          gnupg_load_config ();
379      }      }
380    
381        if (is_gpg4win_installed ())
382            load_gpg_env (); /* XXX: check return code. */
383    
384      rc = gnupg_check_homedir ();      rc = gnupg_check_homedir ();
385      if (rc) {      if (rc) {
386          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
# Line 485  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 531  WinMain (HINSTANCE hinst, HINSTANCE hpre
531    
532      if (!first_start && !start_gpgprefs) {      if (!first_start && !start_gpgprefs) {
533          gnupg_backup_options ();                  gnupg_backup_options ();        
534          rc = check_crypto_engine ();          if (!check_crypto_engine ()) {
         if (rc) {  
535              DestroyWindow (hwnd);              DestroyWindow (hwnd);
536              free_gnupg_table ();              free_gnupg_table ();
537              return 0;              return 0;

Legend:
Removed from v.127  
changed lines
  Added in v.128

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26