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

Annotation of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 212 - (hide annotations)
Tue May 9 10:29:07 2006 UTC (18 years, 9 months ago) by twoaday
File size: 5897 byte(s)

1 werner 36 /* wptKeyRevokersDlg.cpp - Designated Revoker Keys
2     * Copyright (C) 2002, 2003, 2005 Timo Schulz
3     * Copyright (C) 2005 g10 Code GmbH
4     *
5     * This file is part of WinPT.
6     *
7     * WinPT is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * WinPT is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with WinPT; if not, write to the Free Software Foundation,
19     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     */
21     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <commctrl.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptCommonCtl.h"
30     #include "wptNLS.h"
31     #include "wptTypes.h"
32     #include "wptGPG.h"
33     #include "wptCommonCtl.h"
34     #include "wptContext.h"
35     #include "wptDlgs.h"
36     #include "wptErrors.h"
37     #include "wptKeyserver.h"
38 werner 47 #include "wptW32API.h"
39 werner 36 #include "wptVersion.h"
40     #include "wptKeyEdit.h"
41 werner 47 #include "wptKeylist.h"
42 twoaday 212 #include "wptKeyManager.h"
43 werner 36
44 twoaday 212 /* symbolic column IDs */
45 twoaday 129 enum revoke_col_t {
46     REV_COL_NAME = 0,
47     REV_COL_KEYID = 1,
48     REV_COL_ALGO = 2
49     };
50    
51 werner 36 /* Initialize the listview given in @ctrl and return it in @r_lv. */
52 twoaday 208 static void
53 werner 36 revokelist_build (listview_ctrl_t *r_lv, HWND ctrl)
54     {
55     listview_ctrl_t lv;
56     struct listview_column_s rlist[] = {
57 twoaday 129 {0, 160, (char *)_("Name") },
58     {1, 80, (char *)_("Key ID")},
59     {2, 55, (char *)_("Algorithm")},
60 werner 36 {0}
61     };
62 twoaday 208 int i;
63 werner 36
64 twoaday 208 listview_new (&lv, ctrl);
65     lv->items = DIM (rlist)-1;
66 werner 36 for (i = 0; i < lv->items; i++)
67     listview_add_column (lv, &rlist[i]);
68     listview_set_ext_style (lv);
69     *r_lv = lv;
70 twoaday 208 }
71    
72    
73     /* Get the key revokers of the key @key.
74     If reload is 1, an update is forced otherwise the
75     cached revokers are returned. */
76     gpgme_error_t
77     key_get_revokers (winpt_key_t key, int reload, gpg_desig_rev_t *r_rev)
78     {
79     gpgme_error_t err;
80     gpg_desig_rev_t rev;
81     GpgKeyEdit *ke;
82    
83     if (!reload && key->ext->rev) {
84     *r_rev = key->ext->rev;
85     return 0;
86     }
87     ke = new GpgKeyEdit (key->keyid);
88     if (!ke)
89     BUG (NULL);
90     err = ke->getDesignatedRevoker (&rev);
91     delete ke;
92     if (err) {
93     gpg_desig_rev_release (rev);
94     return err;
95     }
96     if (key->ext->rev)
97     gpg_desig_rev_release (rev);
98     key->ext->rev = rev;
99     *r_rev = rev;
100 werner 36 return 0;
101     }
102    
103    
104     /* Initialize the listview @ctrl with all designated revokers of the
105 twoaday 208 key @key.
106 werner 36 Return value: the initialized listview or NULL on error. */
107     static listview_ctrl_t
108 twoaday 208 revokelist_init (HWND ctrl, winpt_key_t key)
109 werner 36 {
110     gpgme_error_t err;
111 twoaday 208 struct winpt_key_s revkey;
112 werner 36 gpg_desig_rev_t rev=NULL, r;
113 twoaday 129 listview_ctrl_t lv;
114     const char *alg;
115 twoaday 204 const char *uid = NULL;
116 twoaday 193 char keyid[32];
117 werner 36
118 twoaday 208 err = key_get_revokers (key, 0, &rev);
119 werner 36 if (err) {
120 twoaday 129 msg_box (NULL, gpgme_strerror (err),
121     _("Designated Key Revokers"), MB_ERR);
122 werner 36 return NULL;
123     }
124 twoaday 208 revokelist_build (&lv, ctrl);
125 werner 36 for (r = rev; r; r = r->next) {
126 twoaday 208 memset (&revkey, 0, sizeof (revkey));
127     if (winpt_get_pubkey (r->fpr+32, &revkey))
128 twoaday 204 uid = _("user ID not found");
129 werner 36 else
130 twoaday 208 uid = revkey.ext->uids->name;
131 twoaday 193 _snprintf (keyid, sizeof (keyid)-1, "0x%s", r->fpr+32);
132 twoaday 212 listview_add_item2 (lv, "", revkey.ext);
133 twoaday 129 alg = get_key_pubalgo (r->pubkey_algo);
134     listview_add_sub_item (lv, 0, REV_COL_ALGO, alg);
135 twoaday 193 listview_add_sub_item (lv, 0, REV_COL_KEYID, keyid);
136 twoaday 129 listview_add_sub_item (lv, 0, REV_COL_NAME, uid);
137 werner 36 }
138     return lv;
139     }
140    
141    
142     /* Dialog box procedure to show designated revokers. */
143     BOOL CALLBACK
144     key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
145     {
146     static listview_ctrl_t lv;
147 twoaday 161 static int key_update = 0;
148 twoaday 208 winpt_key_t key;
149 werner 36 char buf[128], keyid[32];
150     int rc;
151    
152 twoaday 208 switch (msg) {
153 werner 36 case WM_INITDIALOG:
154     gpg_keycache_t ctx;
155 twoaday 208 key = (winpt_key_t)lparam;
156 werner 36 if (!key)
157     dlg_fatal_error( dlg, "Could not get dilaog param" );
158     ctx = keycache_get_ctx (1);
159 twoaday 208 lv = revokelist_init (GetDlgItem (dlg, IDC_KEYREVOKERS_LIST), key);
160 twoaday 88
161     SetDlgItemText (dlg, IDC_KEYREVOKERS_INF, _("Designated Revoker Keys"));
162     SetWindowText (dlg, _("Key Revokers"));
163     SetForegroundWindow (dlg);
164 werner 36 return TRUE;
165    
166     case WM_NOTIFY:
167     NMHDR *notify;
168     notify = (NMHDR *)lparam;
169 twoaday 208 if (notify && notify->code == (UINT)NM_DBLCLK &&
170 werner 36 notify->idFrom == IDC_KEYREVOKERS_LIST) {
171     int idx = listview_get_curr_pos (lv);
172 twoaday 212
173 twoaday 129 listview_get_item_text (lv, idx, REV_COL_KEYID, keyid, DIM (keyid)-1);
174     listview_get_item_text (lv, idx, REV_COL_NAME, buf, sizeof (buf)-1);
175     if (!strcmp (buf, _("user ID not found"))) {
176 werner 36 int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO,
177 twoaday 208 _("Do you want to retrieve %s via the default keyserver?"), keyid);
178 werner 36 if (id == IDNO)
179     break;
180 twoaday 208 rc = hkp_recv_key (dlg, default_keyserver,
181 twoaday 129 default_keyserver_port, keyid, 0, 0);
182     if (!rc) {
183 twoaday 208 struct winpt_key_s pk;
184    
185 twoaday 161 keycache_update (0, keyid);
186     key_update = 1;
187 twoaday 208 memset (&pk, 0, sizeof (pk));
188     if (winpt_get_pubkey (keyid, &pk))
189 werner 36 BUG (NULL);
190 twoaday 208 if (pk.ext && pk.ext->uids)
191     listview_add_sub_item (lv, idx, REV_COL_NAME, pk.ext->uids->name);
192 werner 36 }
193     }
194     else {
195     struct winpt_key_s k;
196 twoaday 212
197 werner 36 memset (&k, 0, sizeof k);
198 twoaday 212 km_get_key (lv, idx, &k);
199 werner 36 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
200     keyprops_dlg_proc, (LPARAM)&k);
201     }
202     }
203     break;
204    
205     case WM_DESTROY:
206     if (lv) {
207     listview_release (lv);
208     lv = NULL;
209     }
210     return FALSE;
211    
212     case WM_COMMAND:
213     switch (LOWORD (wparam)) {
214     case IDOK:
215 twoaday 161 EndDialog (dlg, key_update);
216 werner 36 break;
217 twoaday 208
218     case IDCANCEL:
219     EndDialog (dlg, 0);
220     break;
221 werner 36 }
222     break;
223     }
224    
225     return FALSE;
226     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26