/[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 159 by twoaday, Wed Jan 18 13:57:31 2006 UTC revision 190 by twoaday, Mon Mar 27 10:05:14 2006 UTC
# Line 40  Line 40 
40  #include "wptContext.h"  #include "wptContext.h"
41  #include "wptCardEdit.h"  #include "wptCardEdit.h"
42  #include "wptCrypto.h"  #include "wptCrypto.h"
43    #include "wptUTF8.h"
44    
45    void remove_crit_file_attrs (const char *fname, int force);
46    
47    
48  HINSTANCE glob_hinst;   /* global instance for the dialogs */  HINSTANCE glob_hinst;   /* global instance for the dialogs */
# Line 47  HWND glob_hwnd;                /* global window handle Line 50  HWND glob_hwnd;                /* global window handle
50  HWND activ_hwnd;  HWND activ_hwnd;
51  int scard_support = 0;  int scard_support = 0;
52  int debug = 0;  int debug = 0;
53  int mobile = 0;  int mobile_mode_active = 0;
54  int gpg_read_only = 0;  int gpg_read_only = 0;
55  char gpgver[3];  char gpgver[3];
56    
57    
58  /* Load the key cache and rebuild the signature cache. */  /* Load the key cache and rebuild the signature cache. */
59  static void  void
60  update_keycache (HWND hwnd)  update_keycache (HWND hwnd)
61  {  {
62      refresh_cache_s rcs = {0};      refresh_cache_s rcs = {0};
# Line 68  update_keycache (HWND hwnd) Line 71  update_keycache (HWND hwnd)
71  /* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */  /* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */
72  void  void
73  gpg_set_debug_mode (int val)  gpg_set_debug_mode (int val)
74  {        {
75      if (val)      static char buf[256];
76          putenv ("GPGME_DEBUG=5:gpgme.dbg");      char tmp[128];
77        
78        /* XXX: no gpgme.dbg is created. */
79        if (val > 0) {
80            GetTempPath (sizeof (tmp)-1, tmp);
81            _snprintf (buf, sizeof (buf)-1, "GPGME_DEBUG=5:%sgpgme.dbg", tmp);
82            putenv (buf);
83        }
84      else      else
85          putenv ("GPGME_DEBUG=");          putenv ("GPGME_DEBUG=");
86  }  }
# Line 102  load_gettext (int prev_inst) Line 112  load_gettext (int prev_inst)
112  }  }
113    
114    
115    /* Return true if the GPG environment is useable. */
116    static bool
117    gpg_prefs_ok (void)
118    {
119        char *p;
120    
121        p = get_reg_entry_gpg4win ("gpg.exe");
122        if (!p || file_exist_check (p) != 0) {
123            free_if_alloc (p);
124            p = get_reg_entry_gpg ("gpgProgram");
125            if (!p || file_exist_check (p) != 0) {
126                free_if_alloc (p);
127                log_debug ("gpg_prefs_ok: could not locate gpg.exe");
128                return false;
129            }
130        }
131        free_if_alloc (p);
132        p = get_reg_entry_gpg4win (NULL);    
133        if (!p || dir_exist_check (p) != 0) {
134            free_if_alloc (p);
135            p = get_reg_entry_gpg ("HomeDir");
136            if (!p || dir_exist_check (p) != 0) {
137                free_if_alloc (p);
138                log_debug ("gpg_prefs_ok: could not determine home directory");
139                return false;
140            }
141        }
142        free_if_alloc (p);
143        return true;
144    }
145    
146    
147    /* Check gpg files if they are read-only and ask the user
148       if this should be corrected. */
149    static void
150    check_readonly_attr (const char *homedir)
151    {
152        const char *files[] = {"pubring.gpg", "secring.gpg", "trustdb.gpg", NULL};
153        char *file;
154        int i;
155    
156        for (i=0; files[i] != NULL; i++) {
157            file = make_filename (homedir, files[i], NULL);
158            remove_crit_file_attrs (file, 0);
159            free_if_alloc (file);
160        }
161    }
162    
163    
164  /* Load the GPG environment. On the first start, some  /* Load the GPG environment. On the first start, some
165     checks are performed to find out in what state GPG is.     checks are performed to find out in what state GPG is.
166     Return value: 0  everything OK.     Return value: 0  everything OK.
# Line 122  load_gpg_env (void) Line 181  load_gpg_env (void)
181          return (1);          return (1);
182      }      }
183      free_if_alloc (p);      free_if_alloc (p);
184      p = multi_gnupg_path (0);  
185        p = get_reg_entry_gpg ("HomeDir");
186        if (!p || dir_exist_check (p) != 0) {
187            free_if_alloc (p);
188            p = multi_gnupg_path (0);
189        }
190      if (p && dir_exist_check (p)) {      if (p && dir_exist_check (p)) {
191          memset (&sec_attr, 0, sizeof (sec_attr));          memset (&sec_attr, 0, sizeof (sec_attr));
192          sec_attr.nLength = sizeof (sec_attr);          sec_attr.nLength = sizeof (sec_attr);
# Line 133  load_gpg_env (void) Line 197  load_gpg_env (void)
197              return (2);              return (2);
198          }          }
199      }      }
200        check_readonly_attr (p);
201      pkr = make_filename (p, "pubring", "gpg");      pkr = make_filename (p, "pubring", "gpg");
202      free_if_alloc (p);      free_if_alloc (p);
203      if (!pkr)      if (!pkr)
# Line 305  check_for_empty_keyrings (bool pub_only) Line 370  check_for_empty_keyrings (bool pub_only)
370    
371    
372  /* Enable the mobility mode. */  /* Enable the mobility mode. */
373  static void  static int
374  enable_mobile_mode (void)  enable_mobile_mode (void)
375  {  {
376        if (dir_exist_check ("temp") != 0) {
377            if (!CreateDirectory ("temp", NULL)) {
378                MessageBox (NULL, "Could not create mobile temp directory",
379                            "WinPT Mobile Error", MB_ERR);
380                return -1;
381            }
382        }
383    
384      memset (&reg_prefs, 0, sizeof (reg_prefs));      memset (&reg_prefs, 0, sizeof (reg_prefs));
385      reg_prefs.always_trust = 0;      reg_prefs.always_trust = 0;
386      reg_prefs.auto_backup = 0;      reg_prefs.auto_backup = 0;
387      reg_prefs.cache_time = 0;      reg_prefs.cache_time = 0;
388      reg_prefs.expert = 0;      reg_prefs.expert = 0;
     reg_prefs.keylist_mode = 1;  
389      reg_prefs.kserv_conf = m_strdup ("keyserver.conf");      reg_prefs.kserv_conf = m_strdup ("keyserver.conf");
390      reg_prefs.no_zip_mmedia = 1;      reg_prefs.no_zip_mmedia = 1;
391      reg_prefs.use_tmpfiles = 1;      reg_prefs.use_tmpfiles = 1;
392      reg_prefs.word_wrap = 80;      reg_prefs.word_wrap = 80;
393      reg_prefs.use_viewer = 0; /* XXX */      reg_prefs.use_viewer = 0; /* XXX */
394        return 0;
395    }
396    
397    
398    void
399    set_default_keyserver (void)
400    {
401        char *host = get_reg_entry_keyserver ("Default");
402        char *str_port = get_reg_entry_keyserver ("Default_Port");
403        WORD port = HKP_PORT;
404    
405        if (!host)
406            keyserver_set_default (NULL, 0);
407        else {
408            if (str_port && *str_port)
409                port = atoi (str_port);
410            keyserver_set_default (host, port);
411        }
412        free_if_alloc (host);
413        free_if_alloc (str_port);
414    }
415    
416    
417    /* Display info message that WinPT is now in debug mode. */
418    void
419    winpt_debug_msg (void)
420    {      
421        char output[512];
422        char temp[128];
423            
424        GetTempPath (sizeof temp -1, temp);
425        _snprintf (output, sizeof output - 1,
426            "The GPGME output file is %sgpgme.dbg\n"
427            "The WinPT output file is %swinpt.log\n", temp, temp);
428        MessageBox (NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO);
429  }  }
430    
431    
# Line 394  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 501  WinMain (HINSTANCE hinst, HINSTANCE hpre
501      if (cmdline && stristr (cmdline, "--mobile")) {      if (cmdline && stristr (cmdline, "--mobile")) {
502          msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",          msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!",
503                   "WinPT", MB_INFO);                   "WinPT", MB_INFO);
504          mobile = 1;          mobile_mode_active = 1;
505      }      }
506        
507      set_default_kserver ();      set_default_keyserver ();
508      load_gettext (winpt_inst_found);      load_gettext (winpt_inst_found);
509    
510      if (!mobile) {      if (!mobile_mode_active) {
511          regist_inst_gnupg (1);          regist_inst_gnupg (1);
512          regist_inst_winpt (1, &created);          regist_inst_winpt (1, &created);
513      }      }
514      else {      else {
515          enable_mobile_mode ();          if (enable_mobile_mode ())
516          /* XXX: ask for GPG path */              return 0;
517          created = 1; /* Disable registry writing */          created = 1; /* Disable registry writing */
518      }      }
519    
# Line 415  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 522  WinMain (HINSTANCE hinst, HINSTANCE hpre
522          reg_prefs.use_tmpfiles = 1; /* default */          reg_prefs.use_tmpfiles = 1; /* default */
523          reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */          reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */
524          get_reg_winpt_prefs (&reg_prefs);          get_reg_winpt_prefs (&reg_prefs);
         if (!reg_prefs.no_hotkeys)  
             hotkeys_modify ();  
525          gnupg_load_config ();          gnupg_load_config ();
526      }      }
527    
# Line 431  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 536  WinMain (HINSTANCE hinst, HINSTANCE hpre
536                   winpt_strerror (rc));                   winpt_strerror (rc));
537          s = get_fileopen_dlg (GetActiveWindow (),          s = get_fileopen_dlg (GetActiveWindow (),
538                                _("Select GPG Public Keyring"),                                _("Select GPG Public Keyring"),
539                                _("GPG Keyrings (*.gpg)\0*.gpg\0\0"),                                "GPG Keyrings (*.gpg)\0*.gpg\0\0",
540                                NULL);                                NULL);
541          if (s != NULL) {          if (s != NULL) {
542              size_t n;              size_t n;
# Line 540  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 645  WinMain (HINSTANCE hinst, HINSTANCE hpre
645          return 0;          return 0;
646      }      }
647    
648      if (cmdline) {      if (cmdline && (stristr (cmdline, "--enable-debug") ||
649          if (stristr (cmdline, "--enable-debug") ||                      stristr (cmdline, "--debug"))) {
650              stristr (cmdline, "--debug")) {          gpg_set_debug_mode (1);
651              gpg_set_debug_mode (1);          winpt_debug_msg ();
652              winpt_debug_msg ();          debug = 1;
             debug = 1;  
         }  
653      }      }
654    
655      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));      wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
# Line 590  WinMain (HINSTANCE hinst, HINSTANCE hpre Line 693  WinMain (HINSTANCE hinst, HINSTANCE hpre
693      }      }
694    
695      if (first_start) {      if (first_start) {
         struct first_start_s fs;  
696          struct genkey_s c;          struct genkey_s c;
697            int choice;
698          HWND h;          HWND h;
699  start:  start:
700          h = GetDesktopWindow ();          h = GetDesktopWindow ();
701          DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,          if (!gpg_prefs_ok ())
702                DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h,
703                              gpgprefs_dlg_proc, 0);                              gpgprefs_dlg_proc, 0);
704          DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,          choice = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h,
705                          first_run_dlg_proc, (LPARAM)&fs);                                   first_run_dlg_proc, 0);
706          switch (fs.choice) {          switch (choice) {
707          case SETUP_KEYGEN:          case SETUP_KEYGEN:
708              c.interactive = 1;              c.interactive = 1;
709              c.first_start = 1;              c.first_start = 1;
# Line 617  start: Line 721  start:
721              }              }
722              break;              break;
723    
724          case -1: /* Cancel/Abort. */          case 0: /* Cancel/Abort. */
725            default:
726              DestroyWindow (hwnd);              DestroyWindow (hwnd);
727              free_gnupg_table ();              free_gnupg_table ();
728              return 0;              return 0;
729          }          }
730          update_keycache (hwnd);          update_keycache (hwnd);
731          check_crypto_engine ();          if (!check_crypto_engine ()) {
732                DestroyWindow (hwnd);
733                free_gnupg_table ();
734                return 0;
735            }
736      }      }
737      else {      else {
738          gpg_keycache_t c;          gpg_keycache_t c, sec_c;
739          update_keycache (hwnd);          update_keycache (hwnd);
740          c = keycache_get_ctx (1);          c = keycache_get_ctx (1);
741          if (!c || !gpg_keycache_get_size (c)) {          if (!c || !gpg_keycache_get_size (c)) {
# Line 648  start: Line 757  start:
757                  return 0;                  return 0;
758              }              }
759          }          }
760          if (check_default_key (c)) {          sec_c = keycache_get_ctx (0);
761            if (check_default_key (sec_c)) {
762              char *p = get_gnupg_default_key ();              char *p = get_gnupg_default_key ();
763              log_box (_("WinPT Error"), MB_ERR,              log_box (_("WinPT Error"), MB_ERR,
764                       _("Default key from the GPG options file could not be found.\n"                       _("Default key (from the GPG config file) could not be found.\n"
765                         "Please check your gpg.conf (options) to correct this:\n\n"                         "Please check your gpg.conf or set a new default key to correct it:\n\n"
766                         "%s: public key not found."), p? p : "[null]");                         "%s: public key not found."), p? p : "[null]");
767              free_if_alloc (p);              free_if_alloc (p);
768              DestroyWindow (hwnd);              DestroyWindow (hwnd);

Legend:
Removed from v.159  
changed lines
  Added in v.190

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26