/[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 21 by twoaday, Sun Feb 6 11:11:40 2005 UTC revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC
# Line 39  Line 39 
39  #define item_ctrl_id( cmd ) \  #define item_ctrl_id( cmd ) \
40      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)
41    
42    #define item_ctrl_id2(cmd) \
43        ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_HIDE : IDC_DECRYPT_SIGN_HIDE)
44    
45    
46  BOOL CALLBACK  BOOL CALLBACK
47  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48  {      {    
49      static passphrase_cb_s * c;      static passphrase_cb_s * c;
     static int hide = 1;  
50      gpgme_key_t key;      gpgme_key_t key;
51      const char * s, * id;      const char * s, * id;
52      char info[768] = {0};      char info[768] = {0};
# Line 53  passphrase_callback_proc (HWND dlg, UINT Line 55  passphrase_callback_proc (HWND dlg, UINT
55    
56      switch( msg )  {      switch( msg )  {
57      case WM_INITDIALOG:      case WM_INITDIALOG:
         hide = 1;  
58          c = (passphrase_cb_s *)lparam;          c = (passphrase_cb_s *)lparam;
59          if (!c)          if (!c)
60              BUG (0);              BUG (0);
# Line 117  passphrase_callback_proc (HWND dlg, UINT Line 118  passphrase_callback_proc (HWND dlg, UINT
118                  if ( LOWORD( wparam ) == IDC_DECRYPT_HIDE                  if ( LOWORD( wparam ) == IDC_DECRYPT_HIDE
119                      || LOWORD( wparam ) == IDC_DECRYPT_SIGN_HIDE ) {                      || LOWORD( wparam ) == IDC_DECRYPT_SIGN_HIDE ) {
120                      HWND hwnd;                      HWND hwnd;
121                      hide ^= 1;                      int hide = IsDlgButtonChecked (dlg, item_ctrl_id2 (c->gpg_cmd));
122                      hwnd = GetDlgItem( dlg, item_ctrl_id( c->gpg_cmd ) );                      hwnd = GetDlgItem (dlg, item_ctrl_id (c->gpg_cmd));
123                      SendMessage( hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0 );                      SendMessage( hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0 );
124                      SetFocus( hwnd );                      SetFocus (hwnd);
125                  }                  }
126              }              }
127    
# Line 153  passphrase_callback_proc (HWND dlg, UINT Line 154  passphrase_callback_proc (HWND dlg, UINT
154    
155    
156  static const char *  static const char *
157  parse_gpg_keyid( const char * desc )  parse_gpg_keyid (const char * desc)
158  {  {
159      static char keyid[16+1];      static char keyid[16+1];
160      char * p;      char * p;
161            
162      p = strrchr( desc, '\n' );      p = strrchr (desc, '\n');
163      if( !p )      if( !p )
164          return NULL;          return NULL;
165      /* the format of the desc buffer looks like this:      /* the format of the desc buffer looks like this:
166         request_keyid[16] main_keyid[16] keytype[1] keylength[4]         request_keyid[16] main_keyid[16] keytype[1] keylength[4]
167         we use the main keyid to use only one cache entry. */         we use the main keyid to use only one cache entry. */
168      strncpy( keyid, desc+(p-desc+1+17), 16 );      strncpy (keyid, desc+(p-desc+1+17), 16);
169      return keyid;      return keyid;
170  } /* parse_gpg_keyid */  } /* parse_gpg_keyid */
171    
# Line 263  passphrase_cb( void * opaque, const char Line 264  passphrase_cb( void * opaque, const char
264          return NULL;          return NULL;
265    
266      if( desc ) {      if( desc ) {
267          keyid = parse_gpg_keyid( desc );          keyid = parse_gpg_keyid (desc);
268          pass = agent_get_cache( keyid, &item );          pass = agent_get_cache( keyid, &item );
269          if( pass ) {          if( pass ) {
270              agent_unlock_cache_entry( &item );              agent_unlock_cache_entry( &item );
# Line 286  passphrase_cb( void * opaque, const char Line 287  passphrase_cb( void * opaque, const char
287                        "Card: %s"), buf );                        "Card: %s"), buf );
288              c->is_card = 1;              c->is_card = 1;
289          }          }
290          else if( desc ) {          else if(desc) {
291              strcpy( c->info, desc );              strcpy (c->info, desc);
292              parse_gpg_description( c->info, sizeof c->info - 1 );              parse_gpg_description (c->info, sizeof c->info - 1);
293          }          }
294          if( c->gpg_cmd == GPG_CMD_DECRYPT ) {          if( c->gpg_cmd == GPG_CMD_DECRYPT ) {
295              rc = DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_DECRYPT,              rc = DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_DECRYPT,
# Line 313  passphrase_cb( void * opaque, const char Line 314  passphrase_cb( void * opaque, const char
314    
315    
316  void  void
317  set_gpg_passphrase_cb( gpgme_ctx_t c, passphrase_cb_s * ctx, int cmd,  set_gpg_passphrase_cb (gpgme_ctx_t c, passphrase_cb_s *ctx, int cmd,
318                         HWND hwnd, const char * title )                         HWND hwnd, const char *title)
319  {  {
320      ctx->gpg_cmd = cmd;      ctx->gpg_cmd = cmd;
321      ctx->is_card = 0;      ctx->is_card = 0;
322      ctx->cancel = 0;      ctx->cancel = 0;
323      ctx->hwnd = hwnd;      ctx->hwnd = hwnd;
324      ctx->pwd_init = 1;      ctx->pwd_init = 1;
325      if( strlen( title ) > 256 )      if (strlen (title) > 256)
326          BUG( NULL ); /* check bounds */          BUG (NULL); /* check bounds */
327      strcpy( ctx->title, title );      strcpy (ctx->title, title);
328      gpgme_set_passphrase_cb( c, passphrase_cb, ctx );      gpgme_set_passphrase_cb (c, passphrase_cb, ctx);
329  } /* set_gpg_passphrase_cb */  } /* set_gpg_passphrase_cb */
330    
331    
332    int
333    check_passwd_quality (const char *pass, int strict)
334    {
335        int i, nd=0, nc=0, n;
336    
337        n = strlen (pass);
338        if (n < 8)
339            return -1;
340    
341        for (i=0; i < n; i++) {
342            if (isdigit (pass[i])) nd++;
343            if (isalpha (pass[i])) nc++;
344        }
345    
346        if (nd == n || nc == n)
347            return -1;
348    
349        return 0;
350    }

Legend:
Removed from v.21  
changed lines
  Added in v.22

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26