/[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 333 by twoaday, Tue Oct 13 10:51:21 2009 UTC revision 409 by twoaday, Mon Feb 6 19:39:00 2012 UTC
# Line 46  HWND glob_hwnd;                /* global window handle Line 46  HWND glob_hwnd;                /* global window handle
46  int scard_support = 0;  int scard_support = 0;
47  int debug = 0;  int debug = 0;
48  int gpg_read_only = 0;  int gpg_read_only = 0;
 int emulate_utf8_bug = 0;  
49  char gpgver[3];  char gpgver[3];
50  /* End */  /* End */
51    
52    
53    /* Retrieve the product verion of the given file @fname.
54       Format: MAJOR.MINOR.PATCH1.PATCH2
55       Return value: 0 on success. */
56    int
57    get_file_version (const char *fname, WORD *major, WORD *minor, WORD *patch1, WORD *patch2)
58    {
59        VS_FIXEDFILEINFO *inf;
60        char file[MAX_PATH+1] = {0};
61        LPVOID buf, data;
62        DWORD size;
63        UINT qlen;
64        int err = 0;
65    
66        strncpy (file, fname, MAX_PATH);
67        size = GetFileVersionInfoSize (file, NULL);
68        if (!size)
69            return -1;
70        
71        buf = (LPVOID)new char[size];
72        if (!buf)
73            BUG (NULL);
74        if (!GetFileVersionInfo (file, 0, size, buf)) {
75            err = -1;
76            goto fail;
77        }
78    
79        qlen = 0;
80        VerQueryValue (buf, (char*)"\\", &data, &qlen);
81        if (!qlen) {
82            err = -1;
83            goto fail;
84        }
85        
86        inf = (VS_FIXEDFILEINFO*)data;
87        *major = HIWORD (inf->dwProductVersionMS);
88        *minor = LOWORD (inf->dwProductVersionMS);
89        *patch1 = HIWORD (inf->dwProductVersionLS);
90        *patch2 = LOWORD (inf->dwProductVersionLS);
91    
92    fail:
93        delete [](char*)buf;
94        return err;
95    }
96    
97    
98  /* Load the key cache and rebuild the signature cache. */  /* Load the key cache and rebuild the signature cache. */
99  int  int
100  update_keycache (HWND hwnd)  update_keycache (HWND hwnd)
101  {  {
     int err;  
102      refresh_cache_s rcs;      refresh_cache_s rcs;
103    
104      /* no need to rebuild the sig cache each time. */      /* no need to rebuild the sig cache each time. */
105      memset (&rcs, 0, sizeof (rcs));      memset (&rcs, 0, sizeof (rcs));
106      rcs.kring_update = 1;      rcs.kring_update = 1;
107      err = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd,      int err = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, hwnd,
108                      keycache_dlg_proc, (LPARAM)&rcs);                      keycache_dlg_proc, (LPARAM)&rcs);
109      if (err) {      if (err) {
110          char *cfgf = get_gnupg_config ();          char *cfgf = get_gnupg_config ();
# Line 80  void Line 123  void
123  gpg_set_debug_mode (int val)  gpg_set_debug_mode (int val)
124  {  {
125      static char buf[MAX_PATH+1];      static char buf[MAX_PATH+1];
     char tmp[128];  
126            
127      /* XXX: no gpgme.dbg is created. */      /* XXX: no gpgme.dbg is created. */
128      if (val > 0) {      if (val > 0) {
129            char tmp[128];
130          GetTempPath (DIM (tmp)-1, tmp);          GetTempPath (DIM (tmp)-1, tmp);
131          _snprintf (buf, DIM (buf)-1, "GPGME_DEBUG=5:%sgpgme.dbg", tmp);          _snprintf (buf, DIM (buf)-1, "GPGME_DEBUG=5:%sgpgme.dbg", tmp);
132          putenv (buf);          putenv (buf);
# Line 129  static void Line 172  static void
172  check_readonly_attr (const char *homedir)  check_readonly_attr (const char *homedir)
173  {  {
174      const char *files[] = {"pubring.gpg", "secring.gpg", "trustdb.gpg", NULL};      const char *files[] = {"pubring.gpg", "secring.gpg", "trustdb.gpg", NULL};
175        
176        log_debug("check if there are gpg files with a read-only attribute");
177      for (int i=0; files[i] != NULL; i++) {      for (int i=0; files[i] != NULL; i++) {
178          char *file = make_filename (homedir, files[i], NULL);          char *file = make_filename (homedir, files[i], NULL);
179          remove_crit_file_attrs (file, 0);          remove_crit_file_attrs (file, 0);
# Line 296  winpt_debug_msg (void) Line 340  winpt_debug_msg (void)
340      char output[512];      char output[512];
341      char temp[MAX_PATH+1];      char temp[MAX_PATH+1];
342                    
343      GetTempPath (DIM (temp) -1, temp);      GetTempPath (DIM (temp) - 1, temp);
344      _snprintf (output, DIM (output)-1,      _snprintf (output, DIM (output)-1,
345          "The GPGME output file is %sgpgme.dbg\n"          "The GPGME output file is %sgpgme.dbg\n"
346          "The WinPT output file is %swinpt.log\n", temp, temp);          "The WinPT output file is %swinpt.log\n", temp, temp);
# Line 311  count_insecure_elgkeys (void) Line 355  count_insecure_elgkeys (void)
355  {  {
356      gpg_keycache_t pc;      gpg_keycache_t pc;
357      gpgme_key_t key;      gpgme_key_t key;
     int n;  
358    
359      n=0;      int n = 0;
360      pc = keycache_get_ctx (1);      pc = keycache_get_ctx (1);
361      while (!gpg_keycache_next_key (pc, 0, &key)) {      while (!gpg_keycache_next_key (pc, 0, &key)) {
362          if (key->subkeys->pubkey_algo == GPGME_PK_ELG)          if (key->subkeys->pubkey_algo == GPGME_PK_ELG)
# Line 324  count_insecure_elgkeys (void) Line 367  count_insecure_elgkeys (void)
367  }  }
368    
369    
370    /* Return 1 if the current OS version is at least Windows XP */
371    static int
372    check_os_version (void)
373    {
374        OSVERSIONINFOA osver;    
375        memset (&osver, 0, sizeof (osver));
376        osver.dwOSVersionInfoSize = sizeof (osver);
377            
378        if (!GetVersionEx (&osver)) {
379            MessageBox (NULL, _("Could not read the OS version."), _("WinPT Error"), MB_ERR);
380            return 0;
381        }
382    
383        if (osver.dwMajorVersion < 5 ||
384            (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0)) {
385            MessageBox (NULL, _("WinPT requires Windows XP or higher."), _("WinPT Error"), MB_ERR);
386            return 0;
387        }
388        
389        return 1;
390    }
391        
392  /* Main entry point. */  /* Main entry point. */
393  int WINAPI  int WINAPI
394  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)  WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd)
# Line 333  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 398  WinMain (HINSTANCE hinst, HINSTANCE hpre
398      MSG msg;      MSG msg;
399      HWND hwnd = NULL;      HWND hwnd = NULL;
400      WORD ver[3], ptdver[4];      WORD ver[3], ptdver[4];
401      OSVERSIONINFOA osver;      
402      const char *s;      const char *s;
403      int rc, ec, created = 0;      int rc, ec, created = 0;
404      int first_start = 0, start_gpgprefs = 0;      int first_start = 0, start_gpgprefs = 0;
405      int winpt_inst_found = 0;      int winpt_inst_found = 0;
406      int start_manager = 0;          int start_manager = 0;    
407        
408      memset (&osver, 0, sizeof (osver));      log_debug("check OS version");
409      osver.dwOSVersionInfoSize = sizeof (osver);      if (!check_os_version ())
     if (!GetVersionEx (&osver)) {  
         MessageBox (NULL, _("Could not read the OS version."),  
                     _("WinPT Error"), MB_ERR);  
         return 0;  
     }  
     /*  
     if (osver.dwMajorVersion < 5) {  
         MessageBox (NULL, _("WinPT requires Windows XP or higher."),  
                     _("WinPT Warning"), MB_INFO);  
410          return 0;          return 0;
411      }*/      
           
412      glob_hinst = hinst;      glob_hinst = hinst;
413        
414        /* Allow to shutdown the process, for instance by an installer */
415      if (cmdline && stristr (cmdline, "--stop")) {      if (cmdline && stristr (cmdline, "--stop")) {
416          hwnd = FindWindow ("WinPT", "WinPT");          hwnd = FindWindow ("WinPT", "WinPT");
417          if (hwnd != NULL)          if (hwnd != NULL) {
418                log_debug("shutdown an existing WinPT process");
419              PostMessage (hwnd, WM_DESTROY, 0, 0);              PostMessage (hwnd, WM_DESTROY, 0, 0);
420            }
421          return 0;          return 0;
422      }          }    
423    
424        log_debug("check PTD and GPGME version");
425      get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]);      get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]);
426      ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1],        ec = get_file_version ("PTD.dll", &ptdver[0], &ptdver[1], &ptdver[2], &ptdver[3]);
427                                   &ptdver[2], &ptdver[3]);      if (!ec && (ptdver[0] != ver[0] || ptdver[1] != ver[1] || ptdver[2] != ver[2])) {
       
     if (!ec && (ptdver[0] != ver[0] ||  
                 ptdver[1] != ver[1] ||  
                 ptdver[2] != ver[2])) {  
428          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
429                   _("The PTD.dll file has a different version than WinPT.exe\n"                   _("The PTD.dll file has a different version than WinPT.exe\n"
430                     "Please update the PTD.dll to version %d.%d.%d"),                     "Please update the PTD.dll to version %d.%d.%d"),
# Line 376  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 432  WinMain (HINSTANCE hinst, HINSTANCE hpre
432          return 0;          return 0;
433      }      }
434    
     if (gpg_md_selftest ()) {  
         msg_box (GetDesktopWindow (), _("Cryptographic selftest failed."),  
                  _("WinPT Error"), MB_ERR);  
         return 0;  
     }  
   
435      s = gpgme_check_version (NEED_GPGME_VERSION);      s = gpgme_check_version (NEED_GPGME_VERSION);
436      if (!s || !*s) {      if (!s || !*s) {
437          msg_box (GetDesktopWindow (),          msg_box (GetDesktopWindow (),
438                   _("A newer GPGME version is needed; at least "NEED_GPGME_VERSION),                   _("A newer GPGME version is needed; at least "NEED_GPGME_VERSION),
439                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
440          return 0;          return 0;
# Line 411  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 461  WinMain (HINSTANCE hinst, HINSTANCE hpre
461                       _("WinPT Error"), MB_ERR);                       _("WinPT Error"), MB_ERR);
462      }      }
463    
464      if (is_gpg4win_installed ())      if (is_gpg4win_installed ()) {
465            log_debug("gpg4win: load gpg environment");
466          load_gpg_env (); /* TODO: check return code. */          load_gpg_env (); /* TODO: check return code. */
467        }
468    
469      rc = gnupg_check_homedir ();      rc = gnupg_check_homedir ();
470      if (rc) {      if (rc) {  
         char *p;  
   
471          log_box (_("WinPT Error"), MB_ERR,          log_box (_("WinPT Error"), MB_ERR,
472                   _("GPG home directory is not set correctly.\n"                   _("GPG home directory is not set correctly.\n"
473                     "Please check the GPG registry settings:\n%s."),                     "Please check the GPG registry settings:\n%s."),
# Line 426  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 476  WinMain (HINSTANCE hinst, HINSTANCE hpre
476                                _("Select GPG Public Keyring"),                                _("Select GPG Public Keyring"),
477                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",
478                                NULL);                                NULL);
479          if (s != NULL && (p=strrchr (s, '\\'))) {          
480            char * p;
481            if (s != NULL && (p = strrchr (s, '\\'))) {
482              char *path = substr (s, 0, (p-s));              char *path = substr (s, 0, (p-s));
483    
484              set_reg_entry_gpg ("HomeDir", path);              set_reg_entry_gpg ("HomeDir", path);
# Line 528  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 580  WinMain (HINSTANCE hinst, HINSTANCE hpre
580      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
581      rc = RegisterClass (&wc);      rc = RegisterClass (&wc);
582      if (rc == FALSE) {      if (rc == FALSE) {
583          msg_box (GetDesktopWindow (),          msg_box (GetDesktopWindow (), _("Could not register window class"),
                  _("Could not register window class"),  
584                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
585          free_gnupg_table ();          free_gnupg_table ();
586          return 0;          return 0;
# Line 543  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 594  WinMain (HINSTANCE hinst, HINSTANCE hpre
594                           hinst,                           hinst,
595                           NULL);                           NULL);
596      if (hwnd == NULL) {      if (hwnd == NULL) {
597          msg_box (GetDesktopWindow (),          msg_box (GetDesktopWindow (),
598                   _("Could not create window"),                   _("Could not create window"),
599                   _("WinPT Error"), MB_ERR);                   _("WinPT Error"), MB_ERR);
600          free_gnupg_table ();          free_gnupg_table ();
# Line 553  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 604  WinMain (HINSTANCE hinst, HINSTANCE hpre
604      UpdateWindow (hwnd);      UpdateWindow (hwnd);
605    
606      if (!first_start && !start_gpgprefs) {      if (!first_start && !start_gpgprefs) {
607            log_debug("backup gpg config file and check back-end");
608          gnupg_backup_options ();                  gnupg_backup_options ();        
609          if (!check_crypto_engine ()) {          if (!check_crypto_engine ()) {
610              DestroyWindow (hwnd);              DestroyWindow (hwnd);
# Line 670  start: Line 722  start:
722                              elgamal_warn_dlg_proc, 0);                              elgamal_warn_dlg_proc, 0);
723      }      }
724        
     if (strstr (cmdline, "--emulate-utf8-bug")) {  
         MessageBox (NULL, "Please use this mode only for resetting your passphrase to a non-utf8 form.",  
                     "WinPT Warning", MB_WARN);  
         emulate_utf8_bug = 1;  
     }  
725      if (start_manager)      if (start_manager)
726          PostMessage (hwnd, WM_COMMAND, start_manager, 0);          PostMessage (hwnd, WM_COMMAND, start_manager, 0);
727    

Legend:
Removed from v.333  
changed lines
  Added in v.409

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26