1 |
/* wptKeyTrustPathDlg.cpp - List a trust path for a key. |
/* wptKeyTrustPathDlg.cpp - List a trust path for a key. |
2 |
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* 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 |
* 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 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
20 |
#if 0 |
#if 0 |
21 |
#include <windows.h> |
#ifdef HAVE_CONFIG_H |
22 |
#include <commctrl.h> |
#include <config.h> |
23 |
|
#endif |
24 |
#include "../resource.h" |
|
25 |
#include "wptGPGME.h" |
#include <windows.h> |
26 |
#include "wptCommonCtl.h" |
#include <windows.h> |
27 |
#include "wptContext.h" /* for passphrase_s */ |
#include <commctrl.h> |
28 |
#include "wptDlgs.h" |
|
29 |
#include "wptTypes.h" |
#include "../resource.h" |
30 |
#include "wptNLS.h" |
#include "wptGPGME.h" |
31 |
|
#include "wptCommonCtl.h" |
32 |
struct trust_path_s { |
#include "wptContext.h" /* for passphrase_s */ |
33 |
int level; |
#include "wptDlgs.h" |
34 |
int type; |
#include "wptTypes.h" |
35 |
char otrust[2]; |
#include "wptNLS.h" |
36 |
char valid[2]; |
|
37 |
char keyid[16+1]; |
struct trust_path_s { |
38 |
char uid[128]; |
int level; |
39 |
}; |
int type; |
40 |
|
char otrust[2]; |
41 |
|
char valid[2]; |
42 |
static void |
char keyid[16+1]; |
43 |
copy_trust_item(trust_path_s *tp, GpgmeTrustItem ti) |
char uid[128]; |
44 |
{ |
}; |
45 |
const char *t; |
|
46 |
|
|
47 |
tp->level = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_LEVEL, NULL, 0 ); |
static void |
48 |
tp->type = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_TYPE, NULL, 0 ); |
copy_trust_item(trust_path_s *tp, GpgmeTrustItem ti) |
49 |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_OTRUST, NULL, 0); |
{ |
50 |
strcpy( tp->otrust, t ); |
const char *t; |
51 |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_VALIDITY, NULL, 0 ); |
|
52 |
strcpy( tp->valid, t ); |
tp->level = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_LEVEL, NULL, 0 ); |
53 |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_KEYID, NULL, 0 ); |
tp->type = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_TYPE, NULL, 0 ); |
54 |
strcpy( tp->keyid, t ); |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_OTRUST, NULL, 0); |
55 |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_USERID, NULL, 0 ); |
strcpy( tp->otrust, t ); |
56 |
strcpy( tp->uid, t ); |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_VALIDITY, NULL, 0 ); |
57 |
} /* copy_trust_item */ |
strcpy( tp->valid, t ); |
58 |
|
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_KEYID, NULL, 0 ); |
59 |
|
strcpy( tp->keyid, t ); |
60 |
static HTREEITEM |
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_USERID, NULL, 0 ); |
61 |
treeview_insert_item( HWND tree, HTREEITEM parent, const char *text ) |
strcpy( tp->uid, t ); |
62 |
{ |
} /* copy_trust_item */ |
63 |
TVINSERTSTRUCT ti; |
|
64 |
HTREEITEM node; |
|
65 |
|
static HTREEITEM |
66 |
memset( &ti, 0, sizeof ti ); |
treeview_insert_item( HWND tree, HTREEITEM parent, const char *text ) |
67 |
ti.hParent = parent; |
{ |
68 |
ti.hInsertAfter = TVI_LAST; |
TVINSERTSTRUCT ti; |
69 |
ti.item.mask = TVIF_TEXT; |
HTREEITEM node; |
70 |
ti.item.pszText = (char *)text; |
|
71 |
node = TreeView_InsertItem( tree, &ti ); |
memset( &ti, 0, sizeof ti ); |
72 |
return node; |
ti.hParent = parent; |
73 |
} /* treeview_insert_item */ |
ti.hInsertAfter = TVI_LAST; |
74 |
|
ti.item.mask = TVIF_TEXT; |
75 |
|
ti.item.pszText = (char *)text; |
76 |
HTREEITEM |
node = TreeView_InsertItem( tree, &ti ); |
77 |
treeview_create_child_item( HWND tree, trust_path_s *tp, HTREEITEM parent ) |
return node; |
78 |
{ |
} /* treeview_insert_item */ |
79 |
char info[1024]; |
|
80 |
HTREEITEM node; |
|
81 |
|
HTREEITEM |
82 |
if( tp->type == 0 ) /* root */ |
treeview_create_child_item( HWND tree, trust_path_s *tp, HTREEITEM parent ) |
83 |
_snprintf( info, sizeof info-1, "%s", tp->uid ); |
{ |
84 |
else if( tp->type == 1 )/* key */ |
char info[1024]; |
85 |
_snprintf(info, sizeof info -1, "0x%s (otrust=%s, validity=%s)", |
HTREEITEM node; |
86 |
tp->keyid, tp->otrust, tp->valid ); |
|
87 |
else if( tp->type == 2 ) /* userid */ |
if( tp->type == 0 ) /* root */ |
88 |
_snprintf( info, sizeof info -1, "%s (validity=%s)", tp->uid, tp->valid ); |
_snprintf( info, sizeof info-1, "%s", tp->uid ); |
89 |
node = treeview_insert_item( tree, parent, info ); |
else if( tp->type == 1 )/* key */ |
90 |
return node; |
_snprintf(info, sizeof info -1, "0x%s (otrust=%s, validity=%s)", |
91 |
} /* treeview_create_child_item */ |
tp->keyid, tp->otrust, tp->valid ); |
92 |
|
else if( tp->type == 2 ) /* userid */ |
93 |
|
_snprintf( info, sizeof info -1, "%s (validity=%s)", tp->uid, tp->valid ); |
94 |
void |
node = treeview_insert_item( tree, parent, info ); |
95 |
treeview_add_trustpath(HWND tree, HTREEITEM node, trust_path_s c[], int n, int level) |
return node; |
96 |
{ |
} /* treeview_create_child_item */ |
97 |
HTREEITEM _node; |
|
98 |
int i; |
|
99 |
|
void |
100 |
for( i=0; i<n; i++ ) { |
treeview_add_trustpath(HWND tree, HTREEITEM node, trust_path_s c[], int n, int level) |
101 |
if( c[i].level == level ) { |
{ |
102 |
_node = treeview_create_child_item( tree, &c[i], node ); |
HTREEITEM _node; |
103 |
treeview_add_trustpath( tree, _node, c, n, i ); |
int i; |
104 |
} |
|
105 |
} |
for( i=0; i<n; i++ ) { |
106 |
} /* treeview_add_trustpath */ |
if( c[i].level == level ) { |
107 |
|
_node = treeview_create_child_item( tree, &c[i], node ); |
108 |
|
treeview_add_trustpath( tree, _node, c, n, i ); |
109 |
BOOL CALLBACK |
} |
110 |
keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
} |
111 |
{ |
} /* treeview_add_trustpath */ |
112 |
winpt_key_t k; |
|
113 |
HWND tree; |
|
114 |
GpgmeTrustItem trust_item; |
BOOL CALLBACK |
115 |
gpgme_ctx_t ctx; |
keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
116 |
gpgme_error_t ec; |
{ |
117 |
trust_path_s tp[256] = {0}; |
winpt_key_t k; |
118 |
int pos = 0; |
HWND tree; |
119 |
|
GpgmeTrustItem trust_item; |
120 |
switch( msg ) { |
gpgme_ctx_t ctx; |
121 |
case WM_INITDIALOG: |
gpgme_error_t ec; |
122 |
if( !lparam ) |
trust_path_s tp[256] = {0}; |
123 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
int pos = 0; |
124 |
k = (winpt_key_t )lparam; |
|
125 |
#ifndef LANG_DE |
switch( msg ) { |
126 |
SetWindowText( dlg, _("List Trust Path") ); |
case WM_INITDIALOG: |
127 |
#endif |
if( !lparam ) |
128 |
tree = GetDlgItem( dlg, IDC_KEYTRUST_TREE ); |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
129 |
ec = gpgme_new( &ctx ); |
k = (winpt_key_t )lparam; |
130 |
if( ec ) |
#ifndef LANG_DE |
131 |
BUG( NULL ); |
SetWindowText( dlg, _("List Trust Path") ); |
132 |
ec = gpgme_op_trustlist_start( ctx, k->keyid, 6 ); |
#endif |
133 |
if( ec ) { |
tree = GetDlgItem( dlg, IDC_KEYTRUST_TREE ); |
134 |
msg_box( dlg, gpgme_strerror( err ), _("Trustlist"), MB_ERR ); |
ec = gpgme_new( &ctx ); |
135 |
gpgme_release( ctx ); |
if( ec ) |
136 |
return FALSE; |
BUG( NULL ); |
137 |
} |
ec = gpgme_op_trustlist_start( ctx, k->keyid, 6 ); |
138 |
memset( &tp[0], 0, sizeof tp[0] ); |
if( ec ) { |
139 |
tp[0].level = -1; pos++; |
msg_box( dlg, gpgme_strerror( err ), _("Trustlist"), MB_ERR ); |
140 |
strcpy( tp[0].uid, k->uid ); |
gpgme_release( ctx ); |
141 |
strcpy( tp[0].keyid, k->keyid ); |
return FALSE; |
142 |
|
} |
143 |
while( !gpgme_op_trustlist_next( ctx, &trust_item ) ) { |
memset( &tp[0], 0, sizeof tp[0] ); |
144 |
copy_trust_item( &tp[pos++], trust_item ); |
tp[0].level = -1; pos++; |
145 |
if( pos > 256 ) |
strcpy( tp[0].uid, k->uid ); |
146 |
break; |
strcpy( tp[0].keyid, k->keyid ); |
147 |
gpgme_trust_item_release( trust_item ); |
|
148 |
} |
while( !gpgme_op_trustlist_next( ctx, &trust_item ) ) { |
149 |
gpgme_release( ctx ); |
copy_trust_item( &tp[pos++], trust_item ); |
150 |
treeview_add_trustpath( tree, NULL, tp, pos, -1 ); |
if( pos > 256 ) |
151 |
return TRUE; |
break; |
152 |
|
gpgme_trust_item_release( trust_item ); |
153 |
case WM_SYSCOMMAND: |
} |
154 |
if( LOWORD( wparam ) == SC_CLOSE ) |
gpgme_release( ctx ); |
155 |
EndDialog( dlg, FALSE ); |
treeview_add_trustpath( tree, NULL, tp, pos, -1 ); |
156 |
return FALSE; |
return TRUE; |
157 |
|
|
158 |
case WM_COMMAND: |
case WM_SYSCOMMAND: |
159 |
switch( LOWORD(wparam) ) { |
if( LOWORD( wparam ) == SC_CLOSE ) |
160 |
case IDOK: |
EndDialog( dlg, FALSE ); |
161 |
EndDialog( dlg, TRUE ); |
return FALSE; |
162 |
return TRUE; |
|
163 |
} |
case WM_COMMAND: |
164 |
} |
switch( LOWORD(wparam) ) { |
165 |
|
case IDOK: |
166 |
return FALSE; |
EndDialog( dlg, TRUE ); |
167 |
|
return TRUE; |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
|
return FALSE; |
172 |
} /* keytrust_dlg_proc */ |
} /* keytrust_dlg_proc */ |
173 |
#else |
#else |
174 |
#include <windows.h> |
#include <windows.h> |
175 |
BOOL CALLBACK keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, |
BOOL CALLBACK keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, |
176 |
LPARAM lparam ) { return FALSE; } |
LPARAM lparam ) { return FALSE; } |
177 |
/* GPG 1.2.x does not support this yet */ |
/* GPG 1.2.x does not support this yet */ |
178 |
#endif |
#endif |