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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26