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

Diff of /trunk/Src/wptPINDlg.cpp

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

revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 47 by werner, Mon Oct 31 14:04:59 2005 UTC
# Line 1  Line 1 
 /* wptPINDlg.cpp - PIN callback for smart cards  
  *      Copyright (C) 2003, 2004, 2005 Timo Schulz  
  *  
  * This file is part of WinPT.  
  *  
  * WinPT is free software; you can redistribute it and/or modify  
  * it under the terms of the GNU General Public License as published by  
  * the Free Software Foundation; either version 2 of the License, or  
  * (at your option) any later version.  
  *  
  * WinPT is distributed in the hope that it will be useful,  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
  * GNU General Public License for more details.  
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  
  */  
 #include <windows.h>  
   
 #include "../resource.h"  
 #include "wptW32API.h"  
 #include "wptTypes.h"  
 #include "wptGPG.h"  
 #include "wptCommonCtl.h"  
 #include "wptCard.h"  
 #include "wptUTF8.h"  
   
   
 BOOL CALLBACK  
 pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
 {  
     static int hide = 1;  
     static pin_cb_ctx_s * pin;  
     const char * s;  
     int n, len;  
   
     switch (msg) {  
     case WM_INITDIALOG:  
         hide = 1;  
         pin = (struct pin_cb_ctx_s *)lparam;  
         if (!pin)  
             BUG (0);  
         if (pin->info_text)  
             s = pin->info_text;  
         else  
             s = _("Please enter the PIN");  
         CheckDlgButton (dlg, IDC_PIN_HIDE, BST_CHECKED);  
         SetDlgItemText (dlg, IDC_PIN_INFO, s);  
         center_window (dlg);  
         SetFocus( GetDlgItem (dlg, IDC_PIN_VALUE ));  
         SetForegroundWindow (dlg);  
         return FALSE;  
           
     case WM_COMMAND:  
         if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_PIN_HIDE) {  
             HWND hwnd = GetDlgItem (dlg, IDC_PIN_VALUE);  
             hide ^= 1;  
             SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);  
             SetFocus (hwnd);  
         }  
         switch( LOWORD( wparam ) ) {  
         case IDOK:  
             n = SendDlgItemMessage( dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0 );  
             if( !n ) {  
                 msg_box( dlg, _("Please enter a PIN."), _("PIN"), MB_ERR );  
                 return FALSE;  
             }  
             if (!pin->which || pin->which == GPGME_EDITCARD_CHAPIN) {  
                 free_if_alloc (pin->apin);  
                 pin->apin = new char[n+2];  
                 if (!pin->apin)  
                     BUG (0);  
                 len = GetDlgItemText( dlg, IDC_PIN_VALUE, pin->apin, n+1 );  
                 if (len < 8) {  
                     msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."),  
                              _("PIN"), MB_ERR);  
                     free_if_alloc (pin->apin);  
                     return FALSE;  
                 }  
                 if (is_8bit_string (pin->apin)) {  
                     msg_box (dlg, _("PIN's are currently limited to US-ASCII"),  
                              _("PIN"), MB_ERR);  
                     free_if_alloc (pin->apin);  
                     return FALSE;  
                 }  
             }  
             else if( pin->which == GPGME_EDITCARD_CHUPIN) {  
                 free_if_alloc (pin->upin);  
                 pin->upin = new char[n+2];  
                 if (!pin->upin)  
                     BUG( NULL );  
                 len = GetDlgItemText( dlg, IDC_PIN_VALUE, pin->upin, n+1 );  
                 if (len < 6) {  
                     msg_box( dlg, _("'User PIN' must be at least 6 characters long."),  
                              _("PIN"), MB_ERR );  
                     free_if_alloc( pin->upin );  
                     return FALSE;  
                 }  
                 if (is_8bit_string (pin->upin)) {  
                     msg_box (dlg, _("PIN's are currently limited to US-ASCII"),  
                              _("PIN"), MB_ERR);  
                     free_if_alloc (pin->upin);  
                     return FALSE;  
                 }  
             }  
             EndDialog( dlg, TRUE );  
             break;  
   
         case IDCANCEL:  
             pin->apin = NULL;  
             pin->upin = NULL;  
             EndDialog (dlg, FALSE);  
             break;  
         }  
         break;  
     }  
     return FALSE;  
 } /* pin_cb_dlg_proc */  
1    /* wptPINDlg.cpp - PIN callback for smart cards
2     *      Copyright (C) 2003, 2004, 2005 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    #ifdef HAVE_CONFIG_H
21    #include <config.h>
22    #endif
23    
24    #include <windows.h>
25    #include <windows.h>
26    
27    #include "resource.h"
28    #include "wptW32API.h"
29    #include "wptTypes.h"
30    #include "wptGPG.h"
31    #include "wptCommonCtl.h"
32    #include "wptCard.h"
33    #include "wptUTF8.h"
34    
35    
36    /* Dialog procedure to reuqest the PIN from the user. */
37    BOOL CALLBACK
38    pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
39    {
40        static int hide = 1;
41        static pin_cb_ctx_s * pin;
42        const char * s;
43        int n, len;
44    
45        switch (msg) {
46        case WM_INITDIALOG:
47            hide = 1;
48            pin = (struct pin_cb_ctx_s *)lparam;
49            if (!pin)
50                BUG (0);
51            if (pin->info_text)
52                s = pin->info_text;
53            else
54                s = _("Please enter the PIN");
55            SetDlgItemText (dlg, IDC_PIN_HIDE, _("&Hide Typing"));
56            CheckDlgButton (dlg, IDC_PIN_HIDE, BST_CHECKED);
57            SetDlgItemText (dlg, IDC_PIN_INFO, s);
58            center_window (dlg, NULL);
59            SetFocus( GetDlgItem (dlg, IDC_PIN_VALUE ));
60            SetForegroundWindow (dlg);
61            return FALSE;
62            
63        case WM_COMMAND:
64            if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_PIN_HIDE) {
65                HWND hwnd = GetDlgItem (dlg, IDC_PIN_VALUE);
66                hide ^= 1;
67                SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
68                SetFocus (hwnd);
69            }
70            switch( LOWORD( wparam ) ) {
71            case IDOK:
72                n = SendDlgItemMessage( dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0 );
73                if( !n ) {
74                    msg_box( dlg, _("Please enter a PIN."), _("PIN"), MB_ERR );
75                    return FALSE;
76                }
77                if (!pin->which || pin->which == CARD_ADMIN_PIN) {
78                    sfree_if_alloc (pin->apin);
79                    pin->apin = new char[n+2];
80                    if (!pin->apin)
81                        BUG (0);
82                    len = GetDlgItemText( dlg, IDC_PIN_VALUE, pin->apin, n+1 );
83                    if (len < 8) {
84                        msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."),
85                                 _("PIN"), MB_ERR);
86                        sfree_if_alloc (pin->apin);
87                        return TRUE;
88                    }
89                    if (is_8bit_string (pin->apin)) {
90                        msg_box (dlg, _("PIN's are currently limited to US-ASCII"),
91                                 _("PIN"), MB_ERR);
92                        sfree_if_alloc (pin->apin);
93                        return TRUE;
94                    }
95                }
96                else if( pin->which == CARD_USER_PIN) {
97                    sfree_if_alloc (pin->upin);
98                    pin->upin = new char[n+2];
99                    if (!pin->upin)
100                        BUG( NULL );
101                    len = GetDlgItemText( dlg, IDC_PIN_VALUE, pin->upin, n+1 );
102                    if (len < 6) {
103                        msg_box( dlg, _("'User PIN' must be at least 6 characters long."),
104                                 _("PIN"), MB_ERR );
105                        sfree_if_alloc (pin->upin);
106                        return TRUE;
107                    }
108                    if (is_8bit_string (pin->upin)) {
109                        msg_box (dlg, _("PIN's are currently limited to US-ASCII"),
110                                 _("PIN"), MB_ERR);
111                        sfree_if_alloc (pin->upin);
112                        return TRUE;
113                    }
114                }
115                EndDialog (dlg, TRUE);
116                break;
117    
118            case IDCANCEL:
119                pin->apin = NULL;
120                pin->upin = NULL;
121                EndDialog (dlg, FALSE);
122                break;
123            }
124            break;
125        }
126        return FALSE;
127    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26