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

Annotation of /trunk/Src/wptPINDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 3225 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptPINDlg.cpp - PIN callback for smart cards
2     * Copyright (C) 2003, 2004 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    
21     #include <windows.h>
22    
23     #include "../resource.h"
24     #include "wptW32API.h"
25     #include "wptTypes.h"
26     #include "wptGPG.h"
27     #include "wptCommonCtl.h"
28     #include "wptCard.h"
29     #include "wptUTF8.h"
30    
31    
32     BOOL CALLBACK
33     pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
34     {
35     static pin_cb_ctx_s * pin;
36     const char * s;
37     int n, len;
38    
39     switch( msg ) {
40     case WM_INITDIALOG:
41     pin = (struct pin_cb_ctx_s *)lparam;
42     if (!pin)
43     BUG (0);
44     if (pin->info_text)
45     s = pin->info_text;
46     else
47     s = _("Please enter the PIN");
48     SetDlgItemText( dlg, IDC_PIN_INFO, s );
49     center_window( dlg );
50     SetFocus( GetDlgItem( dlg, IDC_PIN_VALUE ) );
51     SetForegroundWindow( dlg );
52     return FALSE;
53    
54     case WM_COMMAND:
55     switch( LOWORD( wparam ) ) {
56     case IDOK:
57     n = SendDlgItemMessage( dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0 );
58     if( !n ) {
59     msg_box( dlg, _("Please enter a PIN."), _("PIN"), MB_ERR );
60     return FALSE;
61     }
62     if (!pin->which || pin->which == GPGME_EDITCARD_CHAPIN) {
63     free_if_alloc (pin->apin);
64     pin->apin = new char[n+2];
65     if (!pin->apin)
66     BUG (0);
67     len = GetDlgItemText( dlg, IDC_PIN_VALUE, pin->apin, n+1 );
68     if (len < 8) {
69     msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."),
70     _("PIN"), MB_ERR);
71     free_if_alloc (pin->apin);
72     return FALSE;
73     }
74     if (is_8bit_string (pin->apin)) {
75     msg_box (dlg, _("PIN's are currently limited to US-ASCII"),
76     _("PIN"), MB_ERR);
77     free_if_alloc (pin->apin);
78     return FALSE;
79     }
80     }
81     else if( pin->which == GPGME_EDITCARD_CHUPIN) {
82     free_if_alloc (pin->upin);
83     pin->upin = new char[n+2];
84     if (!pin->upin)
85     BUG( NULL );
86     len = GetDlgItemText( dlg, IDC_PIN_VALUE, pin->upin, n+1 );
87     if (len < 6) {
88     msg_box( dlg, _("'User PIN' must be at least 6 characters long."),
89     _("PIN"), MB_ERR );
90     free_if_alloc( pin->upin );
91     return FALSE;
92     }
93     if (is_8bit_string (pin->upin)) {
94     msg_box (dlg, _("PIN's are currently limited to US-ASCII"),
95     _("PIN"), MB_ERR);
96     free_if_alloc (pin->upin);
97     return FALSE;
98     }
99     }
100     EndDialog( dlg, TRUE );
101     break;
102    
103     case IDCANCEL:
104     pin->apin = NULL;
105     pin->upin = NULL;
106     EndDialog (dlg, FALSE);
107     break;
108     }
109     break;
110     }
111     return FALSE;
112     } /* pin_cb_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26