/[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 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC
# Line 17  Line 17 
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>  #include <windows.h>
21    
22  #include "../resource.h"  #include "../resource.h"
# Line 34  Line 33 
33  #include "wptCard.h"  #include "wptCard.h"
34  #include "wptFileManager.h"  #include "wptFileManager.h"
35  #include "wptContext.h"  #include "wptContext.h"
36    #include "wptCardEdit.h"
37    
38  HINSTANCE glob_hinst; /* global instance for the dialogs */  HINSTANCE glob_hinst; /* global instance for the dialogs */
39  HWND glob_hwnd; /* global window handle for the dialogs */  HWND glob_hwnd; /* global window handle for the dialogs */
# Line 41  HWND activ_hwnd; Line 41  HWND activ_hwnd;
41  LOCK mo_file;  LOCK mo_file;
42  int scard_support = 0;  int scard_support = 0;
43  int debug = 0;  int debug = 0;
44    int mobile = 0;
45  int gpg_read_only = 0;  int gpg_read_only = 0;
46  char gpgver[3];  char gpgver[3];
47    
48    /* Internal IPC */
49    int start_keymanager = 0;
50    
51  static void  static void
52  update_keycache (HWND hwnd)  update_keycache (HWND hwnd)
# Line 95  static int Line 98  static int
98  check_default_key (gpgme_keycache_t kc)  check_default_key (gpgme_keycache_t kc)
99  {  {
100      gpgme_key_t key;      gpgme_key_t key;
101      gpgme_error_t err = GPGME_No_Error;      gpgme_error_t err = GPG_ERR_NO_ERROR;
102      char * defkey;      char * defkey;
103    
104      defkey = get_gnupg_default_key ();      defkey = get_gnupg_default_key ();
# Line 127  get_prog_part (const char * fname, int u Line 130  get_prog_part (const char * fname, int u
130              return NULL;              return NULL;
131          strncpy (currdir, cmd, 255);          strncpy (currdir, cmd, 255);
132          j = strlen (currdir);          j = strlen (currdir);
133          while (j--)          while (j--) {
         {        
134              if (currdir[j] == '\\')              if (currdir[j] == '\\')
135                  break;                            break;          
136          }          }
# Line 142  get_prog_part (const char * fname, int u Line 144  get_prog_part (const char * fname, int u
144  static int  static int
145  check_crypto_engine (void)  check_crypto_engine (void)
146  {  {
147      int ma=1, mi=2, pa=4; /* GPG 1.2.4 */      int ma=1, mi=4, pa=0; /* GPG 1.4.0 */
148      int rc;      int rc;
149    
150      rc = check_gnupg_engine (&ma, &mi, &pa);      rc = check_gnupg_engine (&ma, &mi, &pa);
# Line 153  check_crypto_engine (void) Line 155  check_crypto_engine (void)
155      else if (rc) {      else if (rc) {
156          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
157                   _("Sorry, you need a newer GPG version.\n"                   _("Sorry, you need a newer GPG version.\n"
158                     "GPG version %d.%d.%d requred GPG version 1.2.4"),                     "GPG version %d.%d.%d required GPG version 1.4.0"),
159                     ma, mi, pa);                     ma, mi, pa);
160          return rc;          return rc;
161      }      }
162      /* We enable smartcard support for GPG: 1.9.x and >= 1.3.90 */      /* We enable smartcard support for GPG: 1.9.x or >= 1.4.0 */
163      if (ma > 1 || mi >= 9 || mi > 3)      if (ma >= 1 && mi >= 4)
164          scard_support = 1;          scard_support = 1;
165    
166      gpgver[0] = ma;      gpgver[0] = ma;
# Line 187  load_keyserver_conf (int quiet) Line 189  load_keyserver_conf (int quiet)
189  }  }
190    
191    
192    static void
193    enable_mobile_mode (void)
194    {
195        memset (&reg_prefs, 0, sizeof (reg_prefs));
196        reg_prefs.always_trust = 0;
197        reg_prefs.auto_backup = 0;
198        reg_prefs.cache_time = 0;
199        reg_prefs.expert = 0;
200        reg_prefs.keylist_mode = 1;
201        reg_prefs.kserv_conf = m_strdup ("keyserver.conf");
202        reg_prefs.no_zip_mmedia = 1;
203        reg_prefs.use_tmpfiles = 1;
204        reg_prefs.word_wrap = 80;
205        reg_prefs.use_viewer = 0; /* XXX */
206    }
207    
208    char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid);
209    
210  int WINAPI  int WINAPI
211    #ifndef WINPT_IPC
212  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
213    #else
214    win_main (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
215    #endif
216  {  {
217      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};
218      HACCEL accel_tab;      HACCEL accel_tab;
# Line 196  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 220  WinMain (HINSTANCE hinst, HINSTANCE hpre
220      int first_start = 0, start_gpgprefs = 0;      int first_start = 0, start_gpgprefs = 0;
221      const char * s;      const char * s;
222      MSG msg;      MSG msg;
223      HWND hwnd;      HWND hwnd = NULL;
224    
225      glob_hinst = hinst;      glob_hinst = hinst;
226            
     gpgme_lib_init ();  
227      #ifdef _DEBUG      #ifdef _DEBUG
228      gpgme_set_debug_mode (1);      gpgme_set_debug_mode (1);
229      #endif      #endif
     gpgme_set_pgm_string ("WinPT "PGM_VERSION);  
230    
231      s = PTD_get_version ();      s = PTD_get_version ();
232      if (strcmp (s, "0.8.0"))      if (strcmp (s, "0.8.0")) {
     {  
233          log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR,          log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR,
234                   _("Please update your PTD.dll to the newest version, "                   _("Please update your PTD.dll to the newest version, "
235                     "the version (%s) you use is too old."), s);                     "the version (%s) you use is too old."), s);
236          return 0;          return 0;
237      }      }
238    
239      if (gpg_md_selftest ())      if (gpg_md_selftest ()) {
     {  
240          msg_box (NULL, _("Cryptographic selftest failed."),          msg_box (NULL, _("Cryptographic selftest failed."),
241                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
242          return 0;          return 0;
243      }      }
244    
245        if (cmdline && stristr (cmdline, "--mobile")) {
246            msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",
247                     "WinPT", MB_INFO);
248            mobile = 1;
249        }
250    
251      set_default_kserver ();      set_default_kserver ();
252      regist_inst_gnupg (1);  
253      regist_inst_winpt (1, &created);      if (!mobile) {
254      if (!created)          regist_inst_gnupg (1);
255      {          regist_inst_winpt (1, &created);
256        }
257        else {
258            enable_mobile_mode ();
259            /* XXX: ask for GPG path */
260            created = 1; /* Disable registry writing */
261        }
262    
263        if (!created) {
264          memset (&reg_prefs, 0, sizeof (reg_prefs));          memset (&reg_prefs, 0, sizeof (reg_prefs));
265          reg_prefs.use_tmpfiles = 1; /* default */          reg_prefs.use_tmpfiles = 1; /* default */
266            reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */
267          get_reg_winpt_prefs (&reg_prefs);          get_reg_winpt_prefs (&reg_prefs);
268          if (!reg_prefs.no_hotkeys)          if (!reg_prefs.no_hotkeys)
269              hotkeys_modify ();              hotkeys_modify ();
270      }      }
271    
272      rc = gnupg_check_homedir ();      rc = gnupg_check_homedir ();
273      if (rc)      if (rc) {
     {  
274          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
275                   _("GPG home directory is not set correctly.\n"                   _("GPG home directory is not set correctly.\n"
276                     "Please check the GPG registry settings:\n%s."),                     "Please check the GPG registry settings:\n%s."),
# Line 245  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 279  WinMain (HINSTANCE hinst, HINSTANCE hpre
279                                             _("Select GPG Public Keyring"),                                             _("Select GPG Public Keyring"),
280                                             _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),                                             _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),
281                                             NULL);                                             NULL);
282          if (s && !file_exist_check (s))          if (s != NULL) {
         {  
283              size_t n;              size_t n;
284              char * p = strrchr (s, '\\');              char * p = strrchr (s, '\\');
285              if (!p)              if (!p)
# Line 265  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 298  WinMain (HINSTANCE hinst, HINSTANCE hpre
298                  gnupg_check_homedir (); /* change gpgProgram if needed */                  gnupg_check_homedir (); /* change gpgProgram if needed */
299              }              }
300          }          }
301          else          else {
         {  
302              msg_box (NULL, _("GPG home directory could not be determited."),              msg_box (NULL, _("GPG home directory could not be determited."),
303                       _("WinPT Error"), MB_ERR);                       _("WinPT Error"), MB_ERR);
304              goto start;              goto start;
# Line 274  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 306  WinMain (HINSTANCE hinst, HINSTANCE hpre
306      }      }
307    
308      rc = check_gnupg_prog ();      rc = check_gnupg_prog ();
309      if (rc)      if (rc) {
     {  
310          if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n"          if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n"
311                               "Do you want to start the GPG preferences to "                               "Do you want to start the GPG preferences to "
312                               "correct  this problem?"), _("WinPT Error"),                               "correct  this problem?"), _("WinPT Error"),
# Line 333  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 364  WinMain (HINSTANCE hinst, HINSTANCE hpre
364      }      }
365    
366      load_keyserver_conf (cmdline? 1 : 0);      load_keyserver_conf (cmdline? 1 : 0);
367        if (start_keymanager) {
368            dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,
369                                GetDesktopWindow(), keymanager_dlg_proc, NULL,
370                                _("Key Manager"), IDS_WINPT_KEYMISC);
371            keycache_release ();
372            free_gnupg_table ();
373            return 0;
374        }
375    
376      if (cmdline && (stristr (cmdline, "--keymanager")      if (cmdline && (stristr (cmdline, "--keymanager")
377                  || stristr (cmdline, "--cardmanager"))) {                  || stristr (cmdline, "--cardmanager"))) {
378          update_keycache (GetDesktopWindow ());          update_keycache (GetDesktopWindow ());
379          if (stristr (cmdline, "keymanager"))          if (stristr (cmdline, "keymanager"))
380              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC,
381                              GetDesktopWindow(), keymanager_dlg_proc, NULL,                              GetDesktopWindow(), keymanager_dlg_proc, NULL,
382                              _("Key Manager"), IDS_WINPT_KEYMISC);                              _("Key Manager"), IDS_WINPT_KEYMISC);  
383          else {          else {
384              gpgme_card_t crd = smartcard_init ();              gpg_card_t crd = smartcard_init ();
385              if (crd)              if (crd)
386                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,                  dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT,
387                                    GetDesktopWindow(), card_edit_dlg_proc,                                    GetDesktopWindow(), card_edit_dlg_proc,
388                                    (LPARAM)crd, _("Card Manager"),                                    (LPARAM)crd, _("Card Manager"),
389                                    IDS_WINPT_CARD_EDIT);                                    IDS_WINPT_CARD_EDIT);
390              gpgme_card_release (crd);              gpg_card_release (crd);
391          }          }
392          keycache_release ();          keycache_release ();
393          free_gnupg_table ();          free_gnupg_table ();
# Line 360  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 400  WinMain (HINSTANCE hinst, HINSTANCE hpre
400          return 0;          return 0;
401      }      }
402    
403      /*if (file_exist_check ("loadimage.exe"))      if (cmdline) {
404          PTD_create_loadimage (NULL);*/          if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) {
405                        gpg_set_debug_mode (1);
406      if (cmdline && stristr (cmdline, "--enable-debug")) {              winpt_debug_msg ();
407          gpgme_set_debug_mode (1);              debug = 1;
408          winpt_debug_msg ();          }
         debug = 1;  
409      }      }
410    
411      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
# Line 393  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 432  WinMain (HINSTANCE hinst, HINSTANCE hpre
432      UpdateWindow (hwnd);      UpdateWindow (hwnd);
433    
434      if (!first_start && !start_gpgprefs) {      if (!first_start && !start_gpgprefs) {
435          gnupg_backup_options (1);          gnupg_backup_options ();        
         gnupg_backup_options (0);  
           
436          rc = check_crypto_engine ();          rc = check_crypto_engine ();
437          if (rc) {          if (rc) {
438              DestroyWindow (hwnd);              DestroyWindow (hwnd);
# Line 403  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 440  WinMain (HINSTANCE hinst, HINSTANCE hpre
440              return 0;              return 0;
441          }          }
442      }      }
443        
444      if (start_gpgprefs)      if (start_gpgprefs) {
     {  
445          char *ring;          char *ring;
446          size_t size = 0;          size_t size = 0;
447          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd,
# Line 417  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 453  WinMain (HINSTANCE hinst, HINSTANCE hpre
453      }      }
454    
455      if (first_start) {      if (first_start) {
456          struct key_wizard_s c, dummy;          struct first_start_s fs;
457            struct genkey_s c;
458            HWND h;
459  start:  start:
460          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, hwnd,          h = GetDesktopWindow ();
461                          first_run_dlg_proc, (LPARAM)&dummy);          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
462          switch (dummy.interactive)                              gpgprefs_dlg_proc, NULL);
463          {          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
464                            first_run_dlg_proc, (LPARAM)&fs);
465            switch (fs.choice) {
466          case SETUP_KEYGEN:          case SETUP_KEYGEN:
467              c.interactive = 1;              c.interactive = 1;
468                c.first_start = 1;
469              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,              rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD,
470                                   hwnd, keygen_wizard_dlg_proc, (LPARAM)&c);                                   h, keygen_wizard_dlg_proc, (LPARAM)&c);
471              if (!rc)              if (!rc)
472                  goto start;                  goto start;
             update_keycache (hwnd);  
             check_crypto_engine ();  
473              break;              break;
474    
475          case SETUP_IMPORT:          case SETUP_IMPORT:
# Line 439  start: Line 478  start:
478                  msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);                  msg_box (hwnd, winpt_strerror (rc), _("WinPT Error"), MB_ERR);
479                  goto start;                  goto start;
480              }              }
             update_keycache (hwnd);  
             check_crypto_engine ();  
481              break;              break;
482    
         case SETUP_EXISTING:  
             break; /* todo */  
   
483          case -1:          case -1:
484              DestroyWindow (hwnd);              DestroyWindow (hwnd);
485              free_gnupg_table ();              free_gnupg_table ();
486              return 0;              return 0;
487          }          }
488            update_keycache (hwnd);
489            check_crypto_engine ();
490      }      }
491      else {      else {
492          gpgme_keycache_t c;          gpgme_keycache_t c;

Legend:
Removed from v.2  
changed lines
  Added in v.23

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26