/[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 32 by twoaday, Mon Oct 24 08:03:48 2005 UTC revision 59 by twoaday, Wed Nov 2 13:50:48 2005 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-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20  #include <windows.h>  #ifdef HAVE_CONFIG_H
21    #include <config.h>
22  #include "../resource.h"  #endif
23  #include "wptTypes.h"  
24  #include "wptW32API.h"  #include <windows.h>
25  #include "wptVersion.h"  
26  #include "wptErrors.h"  #include "resource.h"
27  #include "wptGPG.h"  #include "wptTypes.h"
28  #include "wptRegistry.h"  #include "wptW32API.h"
29  #include "wptCommonCtl.h"  #include "wptVersion.h"
30  #include "wptDlgs.h"  #include "wptErrors.h"
31  #include "wptNLS.h"  #include "wptGPG.h"
32  #include "wptKeyserver.h"  #include "wptRegistry.h"
33  #include "wptCard.h"  #include "wptCommonCtl.h"
34  #include "wptFileManager.h"  #include "wptDlgs.h"
35  #include "wptContext.h"  #include "wptNLS.h"
36  #include "wptCardEdit.h"  #include "wptKeyserver.h"
37    #include "wptCard.h"
38    #include "wptFileManager.h"
39  #define MIN_GPG_VER   "1.4.3"   /* Minimal GPG version. */  #include "wptContext.h"
40  #define MIN_GPGME_VER "1.2.0"   /* Minimal GPGME version. */  #include "wptCardEdit.h"
41  #define MIN_PTD_VER   "0.8.1"   /* Minimal PTD version. */  #include "wptCrypto.h"
42    
43    #define MIN_GPG_VER   "1.4.3"   /* Minimal GPG version. */
44  HINSTANCE glob_hinst;   /* global instance for the dialogs */  #define MIN_GPGME_VER "1.2.0"   /* Minimal GPGME version. */
45  HWND glob_hwnd;         /* global window handle for the dialogs */  #define MIN_PTD_VER   "0.8.1"   /* Minimal PTD version. */
46  HWND activ_hwnd;  
47  LOCK mo_file;  
48  int scard_support = 0;  HINSTANCE glob_hinst;   /* global instance for the dialogs */
49  int debug = 0;  HWND glob_hwnd;         /* global window handle for the dialogs */
50  int mobile = 0;  HWND activ_hwnd;
51  int gpg_read_only = 0;  LOCK mo_file;
52  char gpgver[3];  int scard_support = 0;
53    int debug = 0;
54    int mobile = 0;
55  /* Load the key cache and rebuild the signature cache. */  int gpg_read_only = 0;
56  static void  char gpgver[3];
57  update_keycache (HWND hwnd)  
58  {  
59      refresh_cache_s rcs = {0};  /* Load the key cache and rebuild the signature cache. */
60      rcs.kr_reload = 0;  static void
61      rcs.kr_update = 1;  update_keycache (HWND hwnd)
62      rcs.tr_update = 1;  {
63      DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd,      refresh_cache_s rcs = {0};
64                      keycache_dlg_proc, (LPARAM)&rcs);      rcs.kr_reload = 0;
65  }      rcs.kr_update = 1;
66        rcs.tr_update = 1;
67        DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd,
68  /* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */                      keycache_dlg_proc, (LPARAM)&rcs);
69  void  }
70  gpg_set_debug_mode (int val)  
71  {        
72      if (val)  /* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */
73          putenv ("GPGME_DEBUG=5:gpgme.dbg");  void
74      else  gpg_set_debug_mode (int val)
75          putenv ("GPGME_DEBUG=");  {      
76  }      if (val)
77            putenv ("GPGME_DEBUG=5:gpgme.dbg");
78        else
79  /* Return the name of the gettext language file. */          putenv ("GPGME_DEBUG=");
80  static char*  }
81  get_gettext_lang (void)  
82  {      
83      char *fname;  /* Return the name of the gettext language file. */
84      fname = get_reg_entry_mo ();  static char*
85      if (!fname)  get_gettext_lang (void)
86          return NULL;  {    
87      return fname;      char *fname;
88  }      fname = get_reg_entry_mo ();
89        if (!fname)
90            return NULL;
91  /* Initialize the gettext sub system. */      return fname;
92  static void  }
93  load_gettext (void)  
94  {  
95      char *nls = NULL;  /* Initialize the gettext sub system. */
96      char *file = NULL;  static void
97    load_gettext (int prev_inst)
98      nls = get_gettext_lang ();  {
99      if (nls) {      char *nls = NULL;
100          set_gettext_file ("winpt", nls);      char *file = NULL;
101          file = make_filename (nls, "winpt", "mo");  
102          if (!file_exist_check (nls) && init_file_lock (&mo_file, file))  {      nls = get_gettext_lang ();
103              msg_box (NULL, _("Could not initizalize file lock.\n"      if (nls) {
104                               "Native Language Support"),          set_gettext_file ("winpt", nls);
105                       _("WinPT Error"), MB_ERR);          file = make_filename (nls, "winpt", "mo");
106          }          if (!file_exist_check (nls) && init_file_lock (&mo_file, file))  {
107          free_if_alloc (nls);              if (!prev_inst)
108          free_if_alloc (file);                  msg_box (NULL, _("Could not initizalize file lock.\n"
109      }                                   "Native Language Support"),
110  }                           _("WinPT Error"), MB_ERR);
111            }
112            free_if_alloc (nls);
113  /* check if the default key from the gpg.conf file is available in the          free_if_alloc (file);
114     keyring. if not, bail out because encryption won't work properly then. */      }
115  static int  }
116  check_default_key (gpg_keycache_t kc)  
117  {  
118      gpgme_key_t key;  /* check if the default key from the gpg.conf file is available in the
119      gpgme_error_t err = GPG_ERR_NO_ERROR;     keyring. if not, bail out because encryption won't work properly then. */
120      char * defkey;  static int
121    check_default_key (gpg_keycache_t kc)
122      defkey = get_gnupg_default_key ();  {
123      if (defkey)      gpgme_key_t key;
124          err = gpg_keycache_find_key (kc, defkey, 0, &key);      gpgme_error_t err = GPG_ERR_NO_ERROR;
125      free_if_alloc (defkey);      char * defkey;
126      return err? -1 : 0;  
127  }      defkey = get_gnupg_default_key ();
128        if (defkey)
129            err = gpg_keycache_find_key (kc, defkey, 0, &key);
130  /* Return the WinPT program file name (with full pathname). */      free_if_alloc (defkey);
131  static const char *      return err? -1 : 0;
132  get_prog_part (const char * fname, int use_cwd)  }
133  {  
134      static char program[512];  
135      char currdir[256];  /* Return the WinPT program file name (with full pathname). */
136      char *cmd = NULL;  static const char *
137      int j;  get_prog_part (const char * fname, int use_cwd)
138            {
139      memset (currdir, 0, DIM (currdir));      static char program[512];
140      memset (program, 0, DIM (program));      char currdir[256];
141                char *cmd = NULL;
142      if (use_cwd) {      int j;
143          GetCurrentDirectory (DIM (currdir)-1, currdir);          
144          _snprintf (program, DIM (program)-1, "%s\\%s", currdir, fname);      memset (currdir, 0, DIM (currdir));
145      }      memset (program, 0, DIM (program));
146      else {          
147          cmd = GetCommandLine ();      if (use_cwd) {
148          if (cmd == NULL)          GetCurrentDirectory (DIM (currdir)-1, currdir);
149              return NULL;          _snprintf (program, DIM (program)-1, "%s\\%s", currdir, fname);
150          strncpy (currdir, cmd, sizeof (currdir)-1);      }
151          j = strlen (currdir);      else {
152          while (j--) {          cmd = GetCommandLine ();
153              if (currdir[j] == '\\')          if (cmd == NULL)
154                  break;              return NULL;
155          }          strncpy (currdir, cmd, sizeof (currdir)-1);
156          currdir[j] = 0;          j = strlen (currdir);
157          _snprintf (program, DIM (program)-1, "%s\\%s", currdir + 1, fname);          while (j--) {
158      }              if (currdir[j] == '\\')
159      return program;                  break;
160  }          }
161            currdir[j] = 0;
162            _snprintf (program, DIM (program)-1, "%s\\%s", currdir + 1, fname);
163  /* Check that the underlying crypto engine fullfills the minimal      }
164     requirements so all commands work properly. */      return program;
165  static int  }
166  check_crypto_engine (void)  
167  {  
168      int ma=1, mi=4, pa=3; /* GPG 1.4.3 */  /* Check that the underlying crypto engine fullfills the minimal
169      int rc;     requirements so all commands work properly. */
170    static int
171      rc = check_gnupg_engine (&ma, &mi, &pa);  check_crypto_engine (void)
172      if (rc == -1) {  {
173          msg_box (NULL, _("Could not read GnuPG version."),      int ma=1, mi=4, pa=3; /* GPG 1.4.3 */
174                   _("WinPT Error"), MB_ERR);      int rc;
175          return rc;  
176      }      rc = check_gnupg_engine (&ma, &mi, &pa);
177      else if (rc) {      if (rc == -1) {
178          log_box (_("WinPT Error"), MB_ERR,          msg_box (NULL, _("Could not read GnuPG version."),
179                   _("Sorry, you need a newer GPG version.\n"                   _("WinPT Error"), MB_ERR);
180                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),          return rc;
181                     ma, mi, pa);      }
182          return rc;      else if (rc) {
183      }          log_box (_("WinPT Error"), MB_ERR,
184      /* We enable smartcard support for GPG: 1.9 or >= 1.4 */                   _("Sorry, you need a newer GPG version.\n"
185      if (ma >= 1 && mi >= 4)                     "GPG version %d.%d.%d required GPG version "MIN_GPG_VER),
186          scard_support = 1;                     ma, mi, pa);
187            return rc;
188      gpgver[0] = ma;      }
189      gpgver[1] = mi;      /* We enable smartcard support for GPG: 1.9 or >= 1.4 */
190      gpgver[2] = pa;      if ((ma == 1 && mi >= 4) || ma > 1)
191      return rc;          scard_support = 1;
192  }  
193        gpgver[0] = ma;
194        gpgver[1] = mi;
195  /* Try to load the keyserver config file. If @quiet is 1      gpgver[2] = pa;
196     do not show any errors. */      return rc;
197  static int  }
198  load_keyserver_conf (int quiet)  
199  {  
200      const char * t;  /* Try to load the keyserver config file. If @quiet is 1
201      int rc;     do not show any errors. */
202    static int
203      if (reg_prefs.kserv_conf)  load_keyserver_conf (int quiet)
204          t = reg_prefs.kserv_conf;  {
205      else if (!file_exist_check (get_prog_part ("keyserver.conf", 0)))      const char * t;
206          t = get_prog_part ("keyserver.conf", 0);      int rc;
207      else  
208          t = "keyserver.conf";      if (reg_prefs.kserv_conf)
209      rc = kserver_load_conf (t);          t = reg_prefs.kserv_conf;
210      if (rc && !quiet)      else if (!file_exist_check (get_prog_part ("keyserver.conf", 0)))
211          msg_box (NULL, winpt_strerror (rc), _("Keyserver"), MB_ERR);          t = get_prog_part ("keyserver.conf", 0);
212      return rc;      else
213  }          t = "keyserver.conf";
214        rc = kserver_load_conf (t);
215        if (rc && !quiet)
216  /* Enable the mobility mode. */          msg_box (NULL, winpt_strerror (rc), _("Keyserver"), MB_ERR);
217  static void      return rc;
218  enable_mobile_mode (void)  }
219  {  
220      memset (&reg_prefs, 0, sizeof (reg_prefs));  
221      reg_prefs.always_trust = 0;  /* Enable the mobility mode. */
222      reg_prefs.auto_backup = 0;  static void
223      reg_prefs.cache_time = 0;  enable_mobile_mode (void)
224      reg_prefs.expert = 0;  {
225      reg_prefs.keylist_mode = 1;      memset (&reg_prefs, 0, sizeof (reg_prefs));
226      reg_prefs.kserv_conf = m_strdup ("keyserver.conf");      reg_prefs.always_trust = 0;
227      reg_prefs.no_zip_mmedia = 1;      reg_prefs.auto_backup = 0;
228      reg_prefs.use_tmpfiles = 1;      reg_prefs.cache_time = 0;
229      reg_prefs.word_wrap = 80;      reg_prefs.expert = 0;
230      reg_prefs.use_viewer = 0; /* XXX */      reg_prefs.keylist_mode = 1;
231  }      reg_prefs.kserv_conf = m_strdup ("keyserver.conf");
232        reg_prefs.no_zip_mmedia = 1;
233        reg_prefs.use_tmpfiles = 1;
234  /* Main entry point. */      reg_prefs.word_wrap = 80;
235  int WINAPI      reg_prefs.use_viewer = 0; /* XXX */
236  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)  }
237  {  
238      WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME};  char* multi_gnupg_path (void);
239      HACCEL accel_tab;  
240      int rc, ec, created = 0, use_cwd = 0, nfiles = 0;  const char * fm_get_file_type (const char *fname, int *r_type);
241      int first_start = 0, start_gpgprefs = 0;  
242      const char * s;  /* Main entry point. */
243      MSG msg;  int WINAPI
244      HWND hwnd = NULL;  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
245    {
246      glob_hinst = hinst;      WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME};
247        HACCEL accel_tab;
248      #ifdef _DEBUG      int rc, ec, created = 0, nfiles = 0;
249      gpg_set_debug_mode (1);      int first_start = 0, start_gpgprefs = 0;
250      debug = 1;      int winpt_inst_found = 0;
251      #endif      const char *s;
252        MSG msg;
253      s = PTD_get_version ();      HWND hwnd = NULL;
254      if (strcmp (s, MIN_PTD_VER)) {  
255          log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR,      glob_hinst = hinst;
256                   _("Please update your PTD.dll to the newest version, "  
257                     "the version (%s) you use is too old."), s);  #ifdef _DEBUG
258          return 0;      gpg_set_debug_mode (1);
259      }      debug = 1;
260    #endif
261      if (gpg_md_selftest ()) {  
262          msg_box (NULL, _("Cryptographic selftest failed."),      if (gpg_md_selftest ()) {
263                   _("WinPT Error"), MB_ERR);          msg_box (NULL, _("Cryptographic selftest failed."),
264          return 0;                   _("WinPT Error"), MB_ERR);
265      }          return 0;
266        }
267      s = gpgme_check_version (MIN_GPGME_VER);  
268      if (!s || !*s) {      s = gpgme_check_version (MIN_GPGME_VER);
269          msg_box (NULL, _("A newer GPGME version is needed; at least "MIN_GPGME_VER),      if (!s || !*s) {
270                   _("WinPT Error"), MB_ERR);          msg_box (NULL, _("A newer GPGME version is needed; at least "MIN_GPGME_VER),
271          return 0;                   _("WinPT Error"), MB_ERR);
272      }          return 0;
273        }
274      if (cmdline && stristr (cmdline, "--mobile")) {  
275          msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",      CreateMutex (NULL, TRUE, PGM_NAME);
276                   "WinPT", MB_INFO);      if (GetLastError () == ERROR_ALREADY_EXISTS)
277          mobile = 1;          winpt_inst_found = 1;
278      }  
279        if (cmdline && stristr (cmdline, "--mobile")) {
280      set_default_kserver ();          msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",
281                     "WinPT", MB_INFO);
282      if (!mobile) {          mobile = 1;
283          regist_inst_gnupg (1);      }
284          regist_inst_winpt (1, &created);  
285      }      set_default_kserver ();
286      else {  
287          enable_mobile_mode ();      if (!mobile) {
288          /* XXX: ask for GPG path */          regist_inst_gnupg (1);
289          created = 1; /* Disable registry writing */          regist_inst_winpt (1, &created);
290      }      }
291        else {
292      if (!created) {          enable_mobile_mode ();
293          memset (&reg_prefs, 0, sizeof (reg_prefs));          /* XXX: ask for GPG path */
294          reg_prefs.use_tmpfiles = 1; /* default */          created = 1; /* Disable registry writing */
295          reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */      }
296          get_reg_winpt_prefs (&reg_prefs);  
297          if (!reg_prefs.no_hotkeys)      if (!created) {
298              hotkeys_modify ();          memset (&reg_prefs, 0, sizeof (reg_prefs));
299      }          reg_prefs.use_tmpfiles = 1; /* default */
300            reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */
301      rc = gnupg_check_homedir ();          get_reg_winpt_prefs (&reg_prefs);
302      if (rc) {          if (!reg_prefs.no_hotkeys)
303          log_box (_("WinPT Error"), MB_ERR,              hotkeys_modify ();
304                   _("GPG home directory is not set correctly.\n"          gnupg_load_config ();
305                     "Please check the GPG registry settings:\n%s."),      }
306                   winpt_strerror (rc));  
307          const char * s = get_fileopen_dlg (GetActiveWindow (),      rc = gnupg_check_homedir ();
308                                             _("Select GPG Public Keyring"),      if (rc) {
309                                             _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),          log_box (_("WinPT Error"), MB_ERR,
310                                             NULL);                   _("GPG home directory is not set correctly.\n"
311          if (s != NULL) {                     "Please check the GPG registry settings:\n%s."),
312              size_t n;                   winpt_strerror (rc));
313              char * p = strrchr (s, '\\');          s = get_fileopen_dlg (GetActiveWindow (),
314              if (!p)                                _("Select GPG Public Keyring"),
315                  BUG (0);                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),
316              n = p - s;                                NULL);
317              if (n)          if (s != NULL) {
318              {              size_t n;
319                  char * file = new char[n+1];              char * p = strrchr (s, '\\');
320                  if (!file)              if (!p)
321                      BUG (NULL);                  BUG (0);
322                  memset (file, 0, n);              n = p - s;
323                  memcpy (file, s, n);              if (n) {
324                  file[n] = '\0';                          char * file = new char[n+1];
325                  set_reg_entry_gpg ("HomeDir", file);                  if (!file)
326                  free_if_alloc (file);                      BUG (NULL);
327                  gnupg_check_homedir (); /* change gpgProgram if needed */                  memset (file, 0, n);
328              }                  memcpy (file, s, n);
329          }                  file[n] = '\0';        
330          else {                  set_reg_entry_gpg ("HomeDir", file);
331              msg_box (NULL, _("GPG home directory could not be determited."),                  free_if_alloc (file);
332                       _("WinPT Error"), MB_ERR);                  gnupg_check_homedir (); /* change gpgProgram if needed */
333              goto start;              }
334          }          }
335      }          else {
336                msg_box (NULL, _("GPG home directory could not be determited."),
337      rc = check_gnupg_prog ();                       _("WinPT Error"), MB_ERR);
338      if (rc) {              goto start;
339          if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n"          }
340                               "Do you want to start the GPG preferences to "      }
341                               "correct  this problem?"), _("WinPT Error"),  
342                               MB_INFO|MB_YESNO) == IDYES)      rc = check_gnupg_prog ();
343              start_gpgprefs = 1;      if (rc) {
344          else          if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n"
345          {                               "Do you want to start the GPG preferences to "
346              msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR);                               "correct  this problem?"), _("WinPT Error"),
347              return 0;                               MB_INFO|MB_YESNO) == IDYES)
348          }              start_gpgprefs = 1;
349      }          else
350            {
351      rc = gnupg_access_files ();              msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
352      if (!start_gpgprefs && rc) {              return 0;
353          if (rc == WPTERR_GPG_KEYRINGS || rc == WPTERR_GPG_OPT_KEYRINGS) {          }
354              ec = msg_box (NULL,      }
355                  _("Could not access and/or find the public and secret keyring.\n"  
356                    "If this is an accident, quit the program and fix it.\n\n"      rc = gnupg_access_files ();
357                    "Continue if you want that WinPT offers you more choices.\n"),      if (!start_gpgprefs && rc) {
358                    "WinPT", MB_INFO|MB_YESNO);          if (rc == WPTERR_GPG_KEYRINGS || rc == WPTERR_GPG_OPT_KEYRINGS) {
359              if (ec == IDYES)              ec = msg_box (NULL,
360                  first_start = 1;                  _("Could not access and/or find the public and secret keyring.\n"
361          }                    "If this is an accident, quit the program and fix it.\n\n"
362          if (!first_start) {                    "Continue if you want that WinPT offers you more choices.\n"),
363              msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR);                    "WinPT", MB_INFO|MB_YESNO);
364              return 0;              if (ec == IDYES)
365          }                  first_start = 1;
366      }          }
367            if (!first_start) {
368      if (!first_start) {              msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
369          rc = gpg_check_permissions (1);              return 0;
370          if (rc && rc == 2)          }
371              gpg_read_only = 1;      }
372          else if (rc)  
373              return 0;      if (!first_start) {
374      }          rc = gpg_check_permissions (1);
375            if (rc && rc == 2)
376      load_gettext ();              gpg_read_only = 1;
377      init_gnupg_table ();          else if (rc)
378                return 0;
379      nfiles = fm_parse_command_line (cmdline);      }
380      if (nfiles > 0) {  
381          free_gnupg_table ();      load_gettext (winpt_inst_found);
382          return 0;      init_gnupg_table ();
383      }  
384        nfiles = fm_parse_command_line (cmdline);
385      if (cmdline && stristr (cmdline, "--wipe-freespace")) {      if (nfiles > 0) {
386          dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL,          free_gnupg_table ();
387                              GetDesktopWindow(), space_wipefrees_dlg_proc, NULL,          return 0;
388                              _("Wipe Free Space"), IDS_WINPT_SPACE_SECDEL);      }
389          free_gnupg_table ();  
390          return 0;      if (cmdline && stristr (cmdline, "--wipe-freespace")) {
391      }          dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL,
392                                GetDesktopWindow(), space_wipefrees_dlg_proc, NULL,
393      load_keyserver_conf (cmdline? 1 : 0);                              _("Wipe Free Space"), IDS_WINPT_SPACE_SECDEL);
394            free_gnupg_table ();
395      if (cmdline && (stristr (cmdline, "--keymanager")          return 0;
396                  || stristr (cmdline, "--cardmanager"))) {      }
397          update_keycache (GetDesktopWindow ());  
398          if (stristr (cmdline, "keymanager"))      load_keyserver_conf (cmdline? 1 : 0);
399              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,  
400                              GetDesktopWindow(), keymanager_dlg_proc, NULL,      if (cmdline && (stristr (cmdline, "--keymanager")
401                              _("Key Manager"), IDS_WINPT_KEYMISC);                    || stristr (cmdline, "--cardmanager"))) {
402          else {          update_keycache (GetDesktopWindow ());
403              gpg_card_t crd = gpg_card_load ();          if (stristr (cmdline, "keymanager"))
404              if (crd)              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,
405                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,                              GetDesktopWindow(), keymanager_dlg_proc, NULL,
406                                    GetDesktopWindow(), card_edit_dlg_proc,                              _("Key Manager"), IDS_WINPT_KEYMISC);  
407                                    (LPARAM)crd, _("Card Manager"),          else {
408                                    IDS_WINPT_CARD_EDIT);              gpg_card_t crd = gpg_card_load ();
409              gpg_card_release (crd);              if (crd)
410          }                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,
411          keycache_release (0);                                    GetDesktopWindow(), card_edit_dlg_proc,
412          free_gnupg_table ();                                    (LPARAM)crd, _("Card Manager"),
413          return 0;                                    IDS_WINPT_CARD_EDIT);
414      }              gpg_card_release (crd);
415            }
416      CreateMutex (NULL, TRUE, PGM_NAME);          keycache_release (0);
417      if (GetLastError () == ERROR_ALREADY_EXISTS) {          free_gnupg_table ();
418          free_gnupg_table ();          return 0;
419          return 0;      }
420      }  
421        /* If we found another WinPT instance, just quit to avoid it
422      if (cmdline) {         will be executed twice. */
423          if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) {      if (winpt_inst_found) {
424              gpg_set_debug_mode (1);          log_debug ("%s", "WinMain: WinPT is already running.");
425              winpt_debug_msg ();          free_gnupg_table ();
426              debug = 1;          return 0;
427          }      }
428      }  
429        if (cmdline) {
430      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));          if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) {
431      rc = RegisterClass (&wc);              gpg_set_debug_mode (1);
432      if (rc == FALSE) {              winpt_debug_msg ();
433          msg_box (NULL, _("Could not register window class"),              debug = 1;
434                   _("WinPT Error"), MB_ERR);          }
435          free_gnupg_table ();      }
436          return 0;  
437      }      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
438        rc = RegisterClass (&wc);
439      hwnd = CreateWindow (PGM_NAME,      if (rc == FALSE) {
440                           PGM_NAME,          msg_box (NULL, _("Could not register window class"),
441                           0, 0, 0, 0, 0,                   _("WinPT Error"), MB_ERR);
442                           NULL,          free_gnupg_table ();
443                           NULL,          return 0;
444                           hinst,      }
445                           NULL);  
446      if (hwnd == NULL) {      hwnd = CreateWindow (PGM_NAME,
447          msg_box (NULL, _("Could not create window"), _("WinPT Error"), MB_ERR);                           PGM_NAME,
448          free_gnupg_table ();                           0, 0, 0, 0, 0,
449          return 0;                           NULL,
450      }                           NULL,
451      glob_hwnd = hwnd;                           hinst,
452      UpdateWindow (hwnd);                           NULL);
453        if (hwnd == NULL) {
454      if (!first_start && !start_gpgprefs) {          msg_box (NULL, _("Could not create window"), _("WinPT Error"), MB_ERR);
455          gnupg_backup_options ();                  free_gnupg_table ();
456          rc = check_crypto_engine ();          return 0;
457          if (rc) {      }
458              DestroyWindow (hwnd);      glob_hwnd = hwnd;
459              free_gnupg_table ();      UpdateWindow (hwnd);
460              return 0;  
461          }      if (!first_start && !start_gpgprefs) {
462      }          gnupg_backup_options ();        
463                rc = check_crypto_engine ();
464      if (start_gpgprefs) {          if (rc) {
465          char *ring;              DestroyWindow (hwnd);
466          size_t size = 0;              free_gnupg_table ();
467          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,              return 0;
468                          gpgprefs_dlg_proc, NULL);          }
469          ring = get_gnupg_keyring (0, !NO_STRICT);      }
470          if (gnupg_access_keyring (0) == -1 && get_file_size (ring) == 0)      
471              first_start = 1; /* The keyring is empty! */      if (start_gpgprefs) {
472          free_if_alloc (ring);          char *ring;
473      }  
474            DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
475      if (first_start) {                          gpgprefs_dlg_proc, 0);
476          struct first_start_s fs;          ring = get_gnupg_keyring (0, !NO_STRICT);
477          struct genkey_s c;          if (gnupg_access_keyring (0) == -1 && get_file_size (ring) == 0)
478          HWND h;              first_start = 1; /* The keyring is empty! */
479  start:          free_if_alloc (ring);
480          h = GetDesktopWindow ();      }
481          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,  
482                              gpgprefs_dlg_proc, NULL);      if (first_start) {
483          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,          struct first_start_s fs;
484                          first_run_dlg_proc, (LPARAM)&fs);          struct genkey_s c;
485          switch (fs.choice) {          HWND h;
486          case SETUP_KEYGEN:  start:
487              c.interactive = 1;          h = GetDesktopWindow ();
488              c.first_start = 1;          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
489              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,                              gpgprefs_dlg_proc, 0);
490                                   h, keygen_wizard_dlg_proc, (LPARAM)&c);          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
491              if (!rc)                          first_run_dlg_proc, (LPARAM)&fs);
492                  goto start;          switch (fs.choice) {
493              break;          case SETUP_KEYGEN:
494                c.interactive = 1;
495          case SETUP_IMPORT:              c.first_start = 1;
496              rc = gnupg_copy_keyrings ();              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,
497              if (rc) {                                   h, keygen_wizard_dlg_proc, (LPARAM)&c);
498                  msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);              if (!rc)
499                  goto start;                  goto start;
500              }              break;
501              break;  
502            case SETUP_IMPORT:
503          case -1:              rc = gnupg_copy_keyrings ();
504              DestroyWindow (hwnd);              if (rc) {
505              free_gnupg_table ();                  msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
506              return 0;                  goto start;
507          }              }
508          update_keycache (hwnd);              break;
509          check_crypto_engine ();  
510      }          case -1:
511      else {              DestroyWindow (hwnd);
512          gpg_keycache_t c;              free_gnupg_table ();
513          update_keycache (hwnd);              return 0;
514          c = keycache_get_ctx (1);          }
515          if (!c || !gpg_keycache_get_size (c)) {          update_keycache (hwnd);
516              gnupg_display_error ();          check_crypto_engine ();
517              msg_box (hwnd, _("The keycache was not initialized or is empty.\n"      }
518                               "Please check your GPG config (keyrings, pathes...)"),      else {
519                               _("WinPT Error"), MB_ERR);          gpg_keycache_t c;
520              ec = msg_box (NULL, _("It seems that GPG is not set properly.\n"          update_keycache (hwnd);
521                                    "Do you want to start the GPG preferences dialog?"),          c = keycache_get_ctx (1);
522                              "WinPT", MB_INFO|MB_YESNO);          if (!c || !gpg_keycache_get_size (c)) {
523              if (ec == IDYES) {              gnupg_display_error ();
524                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,              msg_box (hwnd, _("The keycache was not initialized or is empty.\n"
525                                  gpgprefs_dlg_proc, NULL);                               "Please check your GPG config (keyrings, pathes...)"),
526                  update_keycache (hwnd);                               _("WinPT Error"), MB_ERR);
527              }              ec = msg_box (NULL, _("It seems that GPG is not set properly.\n"
528              else {                                    "Do you want to start the GPG preferences dialog?"),
529                  DestroyWindow (hwnd);                              "WinPT", MB_INFO|MB_YESNO);
530                  free_gnupg_table ();              if (ec == IDYES) {
531                  return 0;                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
532              }                                  gpgprefs_dlg_proc, 0);
533          }                  update_keycache (hwnd);
534          if (check_default_key (c)) {              }
535              char * p = get_gnupg_default_key ();              else {
536              log_box (_("WinPT Error"), MB_ERR,                  DestroyWindow (hwnd);
537                       _("Default key from the GPG options file could not be found.\n"                  free_gnupg_table ();
538                         "Please check your gpg.conf (options) to correct this:\n\n"                  return 0;
539                         "%s: public key not found."), p? p : "[null]");              }
540              free_if_alloc (p);          }
541              DestroyWindow (hwnd);          if (check_default_key (c)) {
542              free_gnupg_table ();              char * p = get_gnupg_default_key ();
543              return 0;              log_box (_("WinPT Error"), MB_ERR,
544          }                       _("Default key from the GPG options file could not be found.\n"
545          if (count_insecure_elgkeys ())                         "Please check your gpg.conf (options) to correct this:\n\n"
546              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_ELGWARN, glob_hwnd,                         "%s: public key not found."), p? p : "[null]");
547                              elgamal_warn_dlg_proc, NULL);              free_if_alloc (p);
548      }              DestroyWindow (hwnd);
549                free_gnupg_table ();
550      accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR);              return 0;
551      keyring_check_last_access (); /* init */          }
552      while (GetMessage (&msg, hwnd, 0, 0)) {          if (count_insecure_elgkeys ())
553          if (!TranslateAccelerator (msg.hwnd, accel_tab, &msg)) {              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_ELGWARN, glob_hwnd,
554              TranslateMessage (&msg);                              elgamal_warn_dlg_proc, 0);
555              DispatchMessage (&msg);      }
556          }  
557      }      accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR);
558                keyring_check_last_access (); /* init */
559      return 0;      while (GetMessage (&msg, hwnd, 0, 0)) {
560  }          if (!TranslateAccelerator (msg.hwnd, accel_tab, &msg)) {
561                TranslateMessage (&msg);
562                DispatchMessage (&msg);
563            }
564        }
565            
566        return 0;
567    }

Legend:
Removed from v.32  
changed lines
  Added in v.59

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26