/[winpt]/trunk/Src/wptPassphraseCB.cpp
ViewVC logotype

Diff of /trunk/Src/wptPassphraseCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 76 by twoaday, Sat Nov 5 12:28:12 2005 UTC revision 77 by twoaday, Mon Nov 14 15:01:01 2005 UTC
# Line 41  Line 41 
41  #include "wptAgent.h"  #include "wptAgent.h"
42  #include "wptRegistry.h"  #include "wptRegistry.h"
43    
   
   
44  const char* get_symkey_algo (int algo);  const char* get_symkey_algo (int algo);
45    
46  #define item_ctrl_id( cmd ) \  #define item_ctrl_id( cmd ) \
# Line 67  burn_passphrase (char **pwd) Line 65  burn_passphrase (char **pwd)
65  static BOOL CALLBACK  static BOOL CALLBACK
66  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
67  {      {    
68      static passphrase_cb_s * c;      static passphrase_cb_s *c;
69      gpgme_decrypt_result_t res = NULL;      gpgme_decrypt_result_t res=NULL;
70      gpgme_sign_result_t res_sig = NULL;      gpgme_sign_result_t res_sig=NULL;
71      gpgme_key_t key;      gpgme_key_t key;
72      gpgme_recipient_t recip=NULL, r;      gpgme_recipient_t recip=NULL, r;
73      void *item;      void *item;
# Line 201  passphrase_callback_proc (HWND dlg, UINT Line 199  passphrase_callback_proc (HWND dlg, UINT
199                  }                  }
200                  res = gpgme_op_decrypt_result (c->gpg);                  res = gpgme_op_decrypt_result (c->gpg);
201                  if (!res)                  if (!res)
202                      res_sig = gpgme_op_sign_result (c->gpg);                      res_sig = gpgme_op_sign_result (c->gpg);            
203                  if (reg_prefs.cache_time > 0 && !c->is_card &&                  if (reg_prefs.cache_time > 0 && !c->is_card &&
204                      ((res && res->recipients) || (res_sig && res_sig->signatures))) {                      (res || res_sig)) {
205                      if (agent_get_cache (c->keyid, &item))                      if (agent_get_cache (c->keyid, &item))                      
206                          agent_unlock_cache_entry (&item);                          agent_unlock_cache_entry (&item);
207                      else                      else
208                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);
209                  }                  }
210                  c->cancel = 0;                  c->cancel = 0;
# Line 234  parse_gpg_keyid (const char *pass_info) Line 232  parse_gpg_keyid (const char *pass_info)
232      static char keyid[16+1];      static char keyid[16+1];
233            
234      /* XXX: check for leading alpha-chars? */      /* XXX: check for leading alpha-chars? */
235      if (strlen (pass_info) < 16)      if (strlen (pass_info) < 16) {
236            log_debug ("parse_gpg_keyid: error '%s'\r\n", pass_info);
237          return NULL;          return NULL;
238        }
239      /* the format of the desc buffer looks like this:      /* the format of the desc buffer looks like this:
240         request_keyid[16] main_keyid[16] keytype[1] keylength[4]         request_keyid[16] main_keyid[16] keytype[1] keylength[4]
241         we use the main keyid to use only one cache entry. */         we use the main keyid to use only one cache entry. */
# Line 261  parse_gpg_description (const char *uid_h Line 261  parse_gpg_description (const char *uid_h
261      /* Each uid_hint contains a long key-ID so it is at least 16 bytes. */      /* Each uid_hint contains a long key-ID so it is at least 16 bytes. */
262      if (strlen (uid_hint) < 17) {      if (strlen (uid_hint) < 17) {
263          *desc = 0;          *desc = 0;
264            log_debug ("parse_gpg_description: error '%s'\r\n", uid_hint);
265          return -1;          return -1;
266      }      }
267    
# Line 301  extract_serial_no (const char *id) Line 302  extract_serial_no (const char *id)
302      char *p;      char *p;
303    
304      p = strchr (id, '/');      p = strchr (id, '/');
305      if (!p)      if (!p) {
306            log_debug ("extract_serial_no: error '%s'\r\n", id);
307          return NULL;          return NULL;
308        }
309      strncpy (buf, id+(p-id)-6, 6);      strncpy (buf, id+(p-id)-6, 6);
310      return buf;      return buf;
311  }  }
# Line 319  passphrase_cb (void *hook, const char *u Line 322  passphrase_cb (void *hook, const char *u
322      void *item;      void *item;
323      const char *keyid=NULL, *pass;      const char *keyid=NULL, *pass;
324      DWORD n;      DWORD n;
325      int rc=0;      int rc = 0;
326    
327      if (!c)      if (!c) {
328            log_debug ("passphrase_cb: error '!c'\r\n");
329          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
330        }
331      c->bad_pwd = prev_was_bad? 1 : 0;      c->bad_pwd = prev_was_bad? 1 : 0;
332      if (prev_was_bad && !c->cancel) {      if (prev_was_bad && !c->cancel) {
333          if (c->pwd)          if (c->pwd)
# Line 345  passphrase_cb (void *hook, const char *u Line 350  passphrase_cb (void *hook, const char *u
350          }          }
351    
352          keyid = parse_gpg_keyid (passphrase_info);          keyid = parse_gpg_keyid (passphrase_info);
353          pass = agent_get_cache (keyid+8, &item);          pass = agent_get_cache (keyid+8, &item);        
354          if (pass) {          if (pass) {
355              agent_unlock_cache_entry (&item);              agent_unlock_cache_entry (&item);
356              c->pwd_init = 0;              c->pwd_init = 0;
# Line 398  passphrase_cb (void *hook, const char *u Line 403  passphrase_cb (void *hook, const char *u
403          return 0;          return 0;
404      }      }
405    
406      WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL);      if (!WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL))
407      WriteFile (hd, "\n", 1, &n, NULL);          log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
408        if (!WriteFile (hd, "\n", 1, &n, NULL))
409            log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
410      return 0;      return 0;
411  }  }
412    

Legend:
Removed from v.76  
changed lines
  Added in v.77

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26