/[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 36 by werner, Thu Oct 27 15:25:13 2005 UTC revision 168 by twoaday, Fri Jan 27 10:08:10 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 22  Line 22 
22  #endif  #endif
23    
24  #include <windows.h>  #include <windows.h>
25  #include <windows.h>  #include <shlobj.h>
26    
27  #include "../resource.h"  #include "resource.h"
28  #include "wptTypes.h"  #include "wptTypes.h"
29  #include "wptW32API.h"  #include "wptW32API.h"
30  #include "wptVersion.h"  #include "wptVersion.h"
# Line 39  Line 39 
39  #include "wptFileManager.h"  #include "wptFileManager.h"
40  #include "wptContext.h"  #include "wptContext.h"
41  #include "wptCardEdit.h"  #include "wptCardEdit.h"
42    #include "wptCrypto.h"
   
 #define MIN_GPG_VER   "1.4.3"   /* Minimal GPG version. */  
 #define MIN_GPGME_VER "1.2.0"   /* Minimal GPGME version. */  
 #define MIN_PTD_VER   "0.8.1"   /* Minimal PTD version. */  
43    
44    
45  HINSTANCE glob_hinst;   /* global instance for the dialogs */  HINSTANCE glob_hinst;   /* global instance for the dialogs */
46  HWND glob_hwnd;         /* global window handle for the dialogs */  HWND glob_hwnd;         /* global window handle for the dialogs */
47  HWND activ_hwnd;  HWND activ_hwnd;
 LOCK mo_file;  
48  int scard_support = 0;  int scard_support = 0;
49  int debug = 0;  int debug = 0;
50  int mobile = 0;  int mobile = 0;
# Line 98  static void Line 93  static void
93  load_gettext (int prev_inst)  load_gettext (int prev_inst)
94  {  {
95      char *nls = NULL;      char *nls = NULL;
     char *file = NULL;  
96    
97      nls = get_gettext_lang ();      nls = get_gettext_lang ();
98      if (nls) {      if (nls != NULL) {
99          set_gettext_file ("winpt", nls);          set_gettext_file ("winpt", nls);
         file = make_filename (nls, "winpt", "mo");  
         if (!file_exist_check (nls) && init_file_lock (&mo_file, file))  {  
             if (!prev_inst)  
                 msg_box (NULL, _("Could not initizalize file lock.\n"  
                                  "Native Language Support"),  
                          _("WinPT Error"), MB_ERR);  
         }  
100          free_if_alloc (nls);          free_if_alloc (nls);
         free_if_alloc (file);  
101      }      }
102  }  }
103    
104    
105    /* Return true if the GPG environment is useable. */
106    static bool
107    gpg_prefs_ok (void)
108    {
109        char *p;
110    
111        p = get_reg_entry_gpg4win ("gpg.exe");
112        if (!p || file_exist_check (p) != 0) {
113            free_if_alloc (p);
114            p = get_reg_entry_gpg ("gpgProgram");
115            if (!p || file_exist_check (p) != 0) {
116                free_if_alloc (p);
117                return false;
118            }
119        }
120        free_if_alloc (p);
121        p = get_reg_entry_gpg4win (NULL);    
122        if (!p || dir_exist_check (p) != 0) {
123            free_if_alloc (p);
124            p = get_reg_entry_gpg ("HomeDir");
125            if (!p || dir_exist_check (p) != 0) {
126                free_if_alloc (p);
127                return false;
128            }
129        }
130        free_if_alloc (p);
131        return true;
132    }
133    
134    
135    
136    /* Load the GPG environment. On the first start, some
137       checks are performed to find out in what state GPG is.
138       Return value: 0  everything OK.
139                     >0  fatal error.
140                     -1 public keyring is empty or does not exist. */
141    static int
142    load_gpg_env (void)
143    {
144        SECURITY_ATTRIBUTES sec_attr;
145        char *p;
146        char *pkr;
147    
148        p = get_reg_entry_gpg4win ("gpg.exe");
149        if (!p)
150            return (1);
151        if (file_exist_check (p)) {
152            free_if_alloc (p);
153            return (1);
154        }
155        free_if_alloc (p);
156    
157        p = get_reg_entry_gpg ("HomeDir");
158        if (!p || dir_exist_check (p) != 0) {
159            free_if_alloc (p);
160            p = multi_gnupg_path (0);
161        }
162        if (p && dir_exist_check (p)) {
163            memset (&sec_attr, 0, sizeof (sec_attr));
164            sec_attr.nLength = sizeof (sec_attr);
165            if (!CreateDirectory (p, &sec_attr)) {
166                msg_box (NULL, _("Could not create GPG home directory"),
167                         _("WinPT Error"), MB_ERR);
168                free_if_alloc (p);
169                return (2);
170            }
171        }
172        pkr = make_filename (p, "pubring", "gpg");
173        free_if_alloc (p);
174        if (!pkr)
175            return -1;
176        if (get_file_size (pkr) == 0) {
177            free_if_alloc (pkr);
178            return -1;
179        }
180        return 0;
181    }
182    
183    
184  /* 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
185     keyring. if not, bail out because encryption won't work properly then. */     keyring. if not, bail out because encryption won't work properly then. */
186  static int  static int
# Line 123  check_default_key (gpg_keycache_t kc) Line 188  check_default_key (gpg_keycache_t kc)
188  {  {
189      gpgme_key_t key;      gpgme_key_t key;
190      gpgme_error_t err = GPG_ERR_NO_ERROR;      gpgme_error_t err = GPG_ERR_NO_ERROR;
191      char * defkey;      char *defkey;
192    
193      defkey = get_gnupg_default_key ();      defkey = get_gnupg_default_key ();
194      if (defkey)      if (defkey)
195          err = gpg_keycache_find_key (kc, defkey, 0, &key);          err = gpg_keycache_find_key (kc, defkey, 0, &key);
196        else
197            msg_box (NULL, _("No useable secret key found."),
198                     _("WinPT Error"), MB_ERR);
199      free_if_alloc (defkey);      free_if_alloc (defkey);
200      return err? -1 : 0;      return err? -1 : 0;
201  }  }
202    
203    
204  /* Return the WinPT program file name (with full pathname). */  /* Return the WinPT program file name (with full pathname). */
205  static const char *  static const char*
206  get_prog_part (const char * fname, int use_cwd)  get_prog_part (const char * fname, int use_cwd)
207  {  {
208      static char program[512];      static char program[512];
# Line 168  get_prog_part (const char * fname, int u Line 236  get_prog_part (const char * fname, int u
236    
237  /* Check that the underlying crypto engine fullfills the minimal  /* Check that the underlying crypto engine fullfills the minimal
238     requirements so all commands work properly. */     requirements so all commands work properly. */
239  static int  static bool
240  check_crypto_engine (void)  check_crypto_engine (void)
241  {  {
242      int ma=1, mi=4, pa=3; /* GPG 1.4.3 */      int ma=0, mi=0, pa=0;
243      int rc;      int rc;
244    
245      rc = check_gnupg_engine (&ma, &mi, &pa);      rc = check_gnupg_engine (NEED_GPG_VERSION, &ma, &mi, &pa);
246      if (rc == -1) {      if (rc == -1) {
247          msg_box (NULL, _("Could not read GnuPG version."),          msg_box (NULL, _("Could not read GnuPG version."),
248                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
249          return rc;          return false;
250      }      }
251      else if (rc) {      else if (rc) {
252          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
253                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
254                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),                     "GPG version %d.%d.%d required GPG version "NEED_GPG_VERSION),
255                     ma, mi, pa);                     ma, mi, pa);
256          return rc;          return false;
257      }      }
258      /* We enable smartcard support for GPG: 1.9 or >= 1.4 */      /* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */
259      if (ma >= 1 && mi >= 4)      if (ma > 1 || pa >= 3)    
260          scard_support = 1;          scard_support = 1;
261    
262      gpgver[0] = ma;      gpgver[0] = ma;
263      gpgver[1] = mi;      gpgver[1] = mi;
264      gpgver[2] = pa;      gpgver[2] = pa;
265      return rc;      return true;
266  }  }
267    
268    
# Line 203  check_crypto_engine (void) Line 271  check_crypto_engine (void)
271  static int  static int
272  load_keyserver_conf (int quiet)  load_keyserver_conf (int quiet)
273  {  {
274      const char * t;      char *buf;
275        const char *t;
276      int rc;      int rc;
277    
278      if (reg_prefs.kserv_conf)      /* Create $APPDATA\winpt if needed. */
279          t = reg_prefs.kserv_conf;      buf = make_special_filename (CSIDL_APPDATA, "winpt", NULL);
280      else if (!file_exist_check (get_prog_part ("keyserver.conf", 0)))      if (buf && dir_exist_check (buf) && !CreateDirectory (buf, NULL)) {
281            MessageBox (NULL, _("Failed to create WinPT directory"),
282                        _("Keyserver"), MB_ERR);
283            free_if_alloc (buf);
284            return -1;
285        }
286        free_if_alloc (buf);
287    
288        /* Check for $APPDATA\winpt\keyserver.conf */
289        buf = make_special_filename (CSIDL_APPDATA, "winpt\\keyserver.conf", NULL);
290    
291        if (!file_exist_check (get_prog_part ("keyserver.conf", 0)))
292          t = get_prog_part ("keyserver.conf", 0);          t = get_prog_part ("keyserver.conf", 0);
293      else      else
294          t = "keyserver.conf";          t = "keyserver.conf";
295        if (file_exist_check (t) == 0 && file_exist_check (buf) != 0) {
296            //log_box (_("Keyserver"), MB_INFO,
297            //       _("keyserver.conf will be copied to \"%s\"\r\n"), buf);
298            if (!CopyFile (t, buf, FALSE)) {
299                MessageBox (NULL, _("Failed to copy the keyserver.conf"),
300                            _("Keyserver"), MB_ERR);
301                free_if_alloc (buf);
302                return -1;
303            }
304            t = buf;
305        }
306        else
307            t = buf;
308        
309      rc = kserver_load_conf (t);      rc = kserver_load_conf (t);
310      if (rc && !quiet)      if (rc && !quiet)
311          msg_box (NULL, winpt_strerror (rc), _("Keyserver"), MB_ERR);          msg_box (NULL, winpt_strerror (rc), _("Keyserver"), MB_ERR);
312        else {
313            free_if_alloc (reg_prefs.kserv_conf);
314            reg_prefs.kserv_conf = m_strdup (t);
315        }
316        free_if_alloc (buf);
317      return rc;      return rc;
318  }  }
319    
320    
321    /* Check if both keyrings are empty. This indicates that
322       WinPT should offer to generate a key pair. */
323    static bool
324    check_for_empty_keyrings (bool pub_only)
325    {
326        char *p;
327        int n = 0;
328    
329        p = get_gnupg_keyring (1, 0);
330        if (file_exist_check (p) == 0 && get_file_size (p) == 0)
331            n++;
332        free_if_alloc (p);
333        if (pub_only)
334            return n == 1? true : false;
335        p = get_gnupg_keyring (0, 0);
336        if (file_exist_check (p) == 0 && get_file_size (p) == 0)
337            n++;
338        free_if_alloc (p);
339        return n==2? true : false;
340    }
341    
342    
343  /* Enable the mobility mode. */  /* Enable the mobility mode. */
344  static void  static void
345  enable_mobile_mode (void)  enable_mobile_mode (void)
# Line 236  enable_mobile_mode (void) Line 357  enable_mobile_mode (void)
357      reg_prefs.use_viewer = 0; /* XXX */      reg_prefs.use_viewer = 0; /* XXX */
358  }  }
359    
 char* multi_gnupg_path (void);  
360    
361  /* Main entry point. */  /* Main entry point. */
362  int WINAPI  int WINAPI
# Line 244  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 364  WinMain (HINSTANCE hinst, HINSTANCE hpre
364  {  {
365      WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME};      WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME};
366      HACCEL accel_tab;      HACCEL accel_tab;
367      int rc, ec, created = 0, use_cwd = 0, nfiles = 0;      MSG msg;
368        HWND hwnd = NULL;
369        WORD ver[3], ptdver[4];
370        int rc, ec, created = 0;
371      int first_start = 0, start_gpgprefs = 0;      int first_start = 0, start_gpgprefs = 0;
372      int winpt_inst_found = 0;      int winpt_inst_found = 0;
373        int start_manager = 0;
374      const char *s;      const char *s;
     MSG msg;  
     HWND hwnd = NULL;  
375    
376      glob_hinst = hinst;      glob_hinst = hinst;
377        if (cmdline && stristr (cmdline, "--stop")) {
378            hwnd = FindWindow ("WinPT", "WinPT");
379            if (hwnd != NULL)
380                PostMessage (hwnd, WM_DESTROY, 0, 0);
381            return 0;
382        }
383    
384        /*
385        OSVERSIONINFO osinf;
386        memset (&osinf, 0, sizeof (osinf));
387        if (GetVersionEx (&osinf) &&
388            osinf.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
389            osinf.dwMinorVersion == 0) {
390            msg_box (NULL, "WinPT propably does not work on Windows 95 without restrictions",
391                     "WinPT Warning", MB_INFO);
392        }
393        */
394    
395      #ifdef _DEBUG      #ifdef _DEBUG
396      gpg_set_debug_mode (1);      gpg_set_debug_mode (1);
397      debug = 1;      debug = 1;
398      #endif      #endif
399    
400      s = PTD_get_version ();      get_file_version ("WinPT.exe", &ver[0], &ver[1], &ver[2], &ver[3]);
401      if (strcmp (s, MIN_PTD_VER)) {      get_file_version ("PTD.dll", &ptdver[0], &ptdver[1],
402          log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR,                                   &ptdver[2], &ptdver[3]);
403                   _("Please update your PTD.dll to the newest version, "      /* XXX
404                     "the version (%s) you use is too old."), s);      if (ptdver[0] != ver[0] || ptdver[1] != ver[1]|| ptdver[2] != ver[2]) {
405            log_box (_("WinPT Error"), MB_ERR,
406                     _("The PTD.dll file has a different version than WinPT.exe\n"
407                       "Please update the PTD.dll to version %d.%d.%d"),
408                       ver[0], ver[1], ver[2]);
409          return 0;          return 0;
410      }      }
411        */
412    
413      if (gpg_md_selftest ()) {      if (gpg_md_selftest ()) {
414          msg_box (NULL, _("Cryptographic selftest failed."),          msg_box (NULL, _("Cryptographic selftest failed."),
# Line 272  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 416  WinMain (HINSTANCE hinst, HINSTANCE hpre
416          return 0;          return 0;
417      }      }
418    
419      s = gpgme_check_version (MIN_GPGME_VER);      s = gpgme_check_version (NEED_GPGME_VERSION);
420      if (!s || !*s) {      if (!s || !*s) {
421          msg_box (NULL, _("A newer GPGME version is needed; at least "MIN_GPGME_VER),          msg_box (NULL, _("A newer GPGME version is needed; at least "NEED_GPGME_VERSION),
422                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
423          return 0;          return 0;
424      }      }
# Line 290  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 434  WinMain (HINSTANCE hinst, HINSTANCE hpre
434      }      }
435    
436      set_default_kserver ();      set_default_kserver ();
437        load_gettext (winpt_inst_found);
438    
439      if (!mobile) {      if (!mobile) {
440          regist_inst_gnupg (1);          regist_inst_gnupg (1);
# Line 308  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 453  WinMain (HINSTANCE hinst, HINSTANCE hpre
453          get_reg_winpt_prefs (&reg_prefs);          get_reg_winpt_prefs (&reg_prefs);
454          if (!reg_prefs.no_hotkeys)          if (!reg_prefs.no_hotkeys)
455              hotkeys_modify ();              hotkeys_modify ();
456            gnupg_load_config ();
457        }
458        else { /* default settings. */
459            reg_prefs.keylist_mode = 1;
460      }      }
461    
462        if (is_gpg4win_installed ())
463            load_gpg_env (); /* XXX: check return code. */
464    
465      rc = gnupg_check_homedir ();      rc = gnupg_check_homedir ();
466      if (rc) {      if (rc) {
467          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
468                   _("GPG home directory is not set correctly.\n"                   _("GPG home directory is not set correctly.\n"
469                     "Please check the GPG registry settings:\n%s."),                     "Please check the GPG registry settings:\n%s."),
470                   winpt_strerror (rc));                   winpt_strerror (rc));
471          const char * s = get_fileopen_dlg (GetActiveWindow (),          s = get_fileopen_dlg (GetActiveWindow (),
472                                             _("Select GPG Public Keyring"),                                _("Select GPG Public Keyring"),
473                                             _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",
474                                             NULL);                                NULL);
475          if (s != NULL) {          if (s != NULL) {
476              size_t n;              size_t n;
477              char * p = strrchr (s, '\\');              char *p = strrchr (s, '\\');
478              if (!p)              if (!p)
479                  BUG (0);                  BUG (0);
480              n = p - s;              n = p - s;
481              if (n) {              if (n) {
482                  char * file = new char[n+1];                  char *file = new char[n+1];
483                  if (!file)                  if (!file)
484                      BUG (NULL);                      BUG (NULL);
485                  memset (file, 0, n);                  memset (file, 0, n);
# Line 352  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 504  WinMain (HINSTANCE hinst, HINSTANCE hpre
504                               "correct  this problem?"), _("WinPT Error"),                               "correct  this problem?"), _("WinPT Error"),
505                               MB_INFO|MB_YESNO) == IDYES)                               MB_INFO|MB_YESNO) == IDYES)
506              start_gpgprefs = 1;              start_gpgprefs = 1;
507          else          else {
         {  
508              msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR);              msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
509              return 0;              return 0;
510          }          }
# Line 375  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 526  WinMain (HINSTANCE hinst, HINSTANCE hpre
526              return 0;              return 0;
527          }          }
528      }      }
529        if (check_for_empty_keyrings (false))
530            first_start = 1;
531    
532      if (!first_start) {      if (!first_start) {
533          rc = gpg_check_permissions (1);          rc = gpg_check_permissions (1);
# Line 383  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 536  WinMain (HINSTANCE hinst, HINSTANCE hpre
536          else if (rc)          else if (rc)
537              return 0;              return 0;
538      }      }
539        
     load_gettext (winpt_inst_found);  
540      init_gnupg_table ();      init_gnupg_table ();
541    
542      nfiles = fm_parse_command_line (cmdline);      if (fm_parse_command_line (cmdline) > 0) {
     if (nfiles > 0) {  
543          free_gnupg_table ();          free_gnupg_table ();
544          return 0;          return 0;
545      }      }
546    
547      if (cmdline && stristr (cmdline, "--wipe-freespace")) {      if (cmdline && stristr (cmdline, "--wipe-freespace")) {
548          dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL,          dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL,
549                              GetDesktopWindow(), space_wipefrees_dlg_proc, NULL,                              GetDesktopWindow(), space_wipefrees_dlg_proc, 0,
550                              _("Wipe Free Space"), IDS_WINPT_SPACE_SECDEL);                              _("Wipe Free Space"), IDS_WINPT_SPACE_SECDEL);
551          free_gnupg_table ();          free_gnupg_table ();
552          return 0;          return 0;
# Line 405  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 556  WinMain (HINSTANCE hinst, HINSTANCE hpre
556    
557      if (cmdline && (stristr (cmdline, "--keymanager")      if (cmdline && (stristr (cmdline, "--keymanager")
558                  || stristr (cmdline, "--cardmanager"))) {                  || stristr (cmdline, "--cardmanager"))) {
559          update_keycache (GetDesktopWindow ());          /* If an instance of WinPT is running, just send the command
560               to open the key manager. Otherwise start a new instance.
561             */
562            HWND tray = FindWindow ("WinPT", "WinPT");
563          if (stristr (cmdline, "keymanager"))          if (stristr (cmdline, "keymanager"))
564              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,              start_manager = ID_WINPT_KEY;
565                              GetDesktopWindow(), keymanager_dlg_proc, NULL,          else
566                              _("Key Manager"), IDS_WINPT_KEYMISC);                start_manager = ID_WINPT_CARD;
567          else {          if (tray != NULL) {
568              gpg_card_t crd = gpg_card_load ();              PostMessage (tray, WM_COMMAND, start_manager, 0);
569              if (crd)              free_gnupg_table ();
570                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,              return 0;
                                   GetDesktopWindow(), card_edit_dlg_proc,  
                                   (LPARAM)crd, _("Card Manager"),  
                                   IDS_WINPT_CARD_EDIT);  
             gpg_card_release (crd);  
571          }          }
         keycache_release (0);  
         free_gnupg_table ();  
         return 0;  
572      }      }
573    
574      /* If we found another WinPT instance, just quit to avoid it      /* If we found another WinPT instance, just quit to avoid it
# Line 433  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 580  WinMain (HINSTANCE hinst, HINSTANCE hpre
580      }      }
581    
582      if (cmdline) {      if (cmdline) {
583          if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) {          if (stristr (cmdline, "--enable-debug") ||
584                stristr (cmdline, "--debug")) {
585              gpg_set_debug_mode (1);              gpg_set_debug_mode (1);
586              winpt_debug_msg ();              winpt_debug_msg ();
587              debug = 1;              debug = 1;
# Line 466  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 614  WinMain (HINSTANCE hinst, HINSTANCE hpre
614    
615      if (!first_start && !start_gpgprefs) {      if (!first_start && !start_gpgprefs) {
616          gnupg_backup_options ();                  gnupg_backup_options ();        
617          rc = check_crypto_engine ();          if (!check_crypto_engine ()) {
         if (rc) {  
618              DestroyWindow (hwnd);              DestroyWindow (hwnd);
619              free_gnupg_table ();              free_gnupg_table ();
620              return 0;              return 0;
# Line 475  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 622  WinMain (HINSTANCE hinst, HINSTANCE hpre
622      }      }
623            
624      if (start_gpgprefs) {      if (start_gpgprefs) {
         char *ring;  
         size_t size = 0;  
625          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
626                          gpgprefs_dlg_proc, NULL);                          gpgprefs_dlg_proc, 0);
627          ring = get_gnupg_keyring (0, !NO_STRICT);          if (check_for_empty_keyrings (true))
628          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);  
629      }      }
630    
631      if (first_start) {      if (first_start) {
         struct first_start_s fs;  
632          struct genkey_s c;          struct genkey_s c;
633            int choice;
634          HWND h;          HWND h;
635  start:  start:
636          h = GetDesktopWindow ();          h = GetDesktopWindow ();
637          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,          if (!gpg_prefs_ok ())
638                              gpgprefs_dlg_proc, NULL);              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
639          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,                              gpgprefs_dlg_proc, 0);
640                          first_run_dlg_proc, (LPARAM)&fs);          choice = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
641          switch (fs.choice) {                                   first_run_dlg_proc, 0);
642            switch (choice) {
643          case SETUP_KEYGEN:          case SETUP_KEYGEN:
644              c.interactive = 1;              c.interactive = 1;
645              c.first_start = 1;              c.first_start = 1;
# Line 513  start: Line 657  start:
657              }              }
658              break;              break;
659    
660          case -1:          case 0: /* Cancel/Abort. */
661            default:
662              DestroyWindow (hwnd);              DestroyWindow (hwnd);
663              free_gnupg_table ();              free_gnupg_table ();
664              return 0;              return 0;
665          }          }
666          update_keycache (hwnd);          update_keycache (hwnd);
667          check_crypto_engine ();          if (!check_crypto_engine ()) {
668                DestroyWindow (hwnd);
669                free_gnupg_table ();
670                return 0;
671            }
672      }      }
673      else {      else {
674          gpg_keycache_t c;          gpg_keycache_t c;
# Line 535  start: Line 684  start:
684                              "WinPT", MB_INFO|MB_YESNO);                              "WinPT", MB_INFO|MB_YESNO);
685              if (ec == IDYES) {              if (ec == IDYES) {
686                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
687                                  gpgprefs_dlg_proc, NULL);                                  gpgprefs_dlg_proc, 0);
688                  update_keycache (hwnd);                  update_keycache (hwnd);
689              }              }
690              else {              else {
# Line 545  start: Line 694  start:
694              }              }
695          }          }
696          if (check_default_key (c)) {          if (check_default_key (c)) {
697              char * p = get_gnupg_default_key ();              char *p = get_gnupg_default_key ();
698              log_box (_("WinPT Error"), MB_ERR,              log_box (_("WinPT Error"), MB_ERR,
699                       _("Default key from the GPG options file could not be found.\n"                       _("Default key from the GPG options file could not be found.\n"
700                         "Please check your gpg.conf (options) to correct this:\n\n"                         "Please check your gpg.conf (options) to correct this:\n\n"
# Line 557  start: Line 706  start:
706          }          }
707          if (count_insecure_elgkeys ())          if (count_insecure_elgkeys ())
708              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_ELGWARN, glob_hwnd,              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_ELGWARN, glob_hwnd,
709                              elgamal_warn_dlg_proc, NULL);                              elgamal_warn_dlg_proc, 0);
710      }      }
711    
712        if (start_manager)
713            PostMessage (hwnd, WM_COMMAND, start_manager, 0);
714    
715      accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR);      accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR);
716      keyring_check_last_access (); /* init */      keyring_check_last_access (); /* init */
717      while (GetMessage (&msg, hwnd, 0, 0)) {      while (GetMessage (&msg, hwnd, 0, 0)) {

Legend:
Removed from v.36  
changed lines
  Added in v.168

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26