1 |
twoaday |
121 |
/* XXX: Re-implement the code. */ |
2 |
|
|
|
3 |
|
|
#if 0 |
4 |
|
|
gpg_optfile_t |
5 |
|
|
km_groupdb_open (void) |
6 |
|
|
{ |
7 |
|
|
gpg_optfile_t opt; |
8 |
|
|
char * optfile; |
9 |
|
|
int err = 0; |
10 |
|
|
|
11 |
|
|
optfile = get_gnupg_cfgfile(); |
12 |
|
|
if( !optfile ) |
13 |
|
|
BUG( NULL ); |
14 |
|
|
if( parse_gpg_options( optfile, &opt ) ) |
15 |
|
|
err = 1; |
16 |
|
|
free_if_alloc( optfile ); |
17 |
|
|
return err? NULL : opt; |
18 |
|
|
} /* km_groupdb_open */ |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
int |
22 |
|
|
km_groupdb_expand_recipients( const char *name, gpgme_recipients_t rset ) |
23 |
|
|
{ |
24 |
|
|
gpg_keycache_t kc; |
25 |
|
|
gpgme_key_t pk; |
26 |
|
|
gpg_optfile_t opt; |
27 |
|
|
gpg_group_t grp; |
28 |
|
|
gpg_member_t mbr; |
29 |
|
|
int no_trust = 0, n; |
30 |
|
|
|
31 |
|
|
kc = keycache_get_ctx( 1 ); |
32 |
|
|
if( !kc ) |
33 |
|
|
BUG( NULL ); |
34 |
|
|
|
35 |
|
|
opt = km_groupdb_open( ); |
36 |
|
|
if( !opt ) |
37 |
|
|
return WPTERR_FILE_OPEN; |
38 |
|
|
|
39 |
|
|
grp = find_group( opt, name ); |
40 |
|
|
if( !grp ) |
41 |
|
|
return WPTERR_GENERAL; |
42 |
|
|
|
43 |
|
|
/* we are paranoid and check that all group members exist in the |
44 |
|
|
key cache. there is no need that it is really the real key, but |
45 |
|
|
an entry should be available. the rest is up to GPG. */ |
46 |
|
|
for( mbr = grp->list; mbr; mbr = mbr->next ) { |
47 |
|
|
if( gpgme_keycache_find_key( kc, mbr->name, 0, &pk ) ) |
48 |
|
|
BUG( NULL ); |
49 |
|
|
n = count_userids (pk); |
50 |
|
|
while( n-- ) { |
51 |
|
|
gpgme_user_id_t u = get_nth_userid (pk, n); |
52 |
|
|
const char * s = u->uid; |
53 |
|
|
if( s && stristr( s, mbr->name ) |
54 |
|
|
&& u->validity < 3 ) |
55 |
|
|
no_trust++; |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
gpgme_recipients_add_name( rset, name ); |
60 |
|
|
release_gpg_options( opt ); |
61 |
|
|
|
62 |
|
|
return no_trust; |
63 |
|
|
} /* km_groupdb_expand_recipients */ |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
static HTREEITEM |
67 |
|
|
km_tv_insert_item( HWND tree, HTREEITEM parent, const char *text ) |
68 |
|
|
{ |
69 |
|
|
TVINSERTSTRUCT tvis; |
70 |
|
|
HTREEITEM node; |
71 |
|
|
|
72 |
|
|
memset( &tvis, 0, sizeof tvis ); |
73 |
|
|
tvis.hParent = parent; |
74 |
|
|
tvis.hInsertAfter = TVI_LAST; |
75 |
|
|
tvis.item.mask = TVIF_TEXT; |
76 |
|
|
tvis.item.pszText = (char *)text; |
77 |
|
|
node = TreeView_InsertItem( tree, &tvis ); |
78 |
|
|
return node; |
79 |
|
|
} /* km_tv_insert_item */ |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
int |
83 |
|
|
km_groups_new( km_group_t *r_gc, HWND ctrl ) |
84 |
|
|
{ |
85 |
|
|
km_group_t gc; |
86 |
|
|
|
87 |
|
|
gc = new km_group_s; |
88 |
|
|
if (!gc) |
89 |
|
|
BUG (NULL); |
90 |
|
|
gc->tree = ctrl; |
91 |
|
|
gc->gh = km_groupdb_open (); |
92 |
|
|
*r_gc = gc; |
93 |
|
|
return 0; |
94 |
|
|
} /* km_groups_new */ |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
void |
98 |
|
|
km_groups_sync( km_group_t gc ) |
99 |
|
|
{ |
100 |
|
|
char * optfile; |
101 |
|
|
|
102 |
|
|
optfile = get_gnupg_cfgfile (); |
103 |
|
|
if( !optfile ) |
104 |
|
|
BUG( NULL ); |
105 |
|
|
commit_gpg_options( optfile, gc->gh ); |
106 |
|
|
free_if_alloc( optfile ); |
107 |
|
|
gc->need_sync = 0; |
108 |
|
|
} /* km_groups_sync */ |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
void |
112 |
|
|
km_groups_release (km_group_t gc) |
113 |
|
|
{ |
114 |
|
|
if( gc ) { |
115 |
|
|
/* xxx: this reset the default key (sync=1) */ |
116 |
|
|
gc->need_sync=0; |
117 |
|
|
if (gc->need_sync) |
118 |
|
|
km_groups_sync (gc); |
119 |
|
|
if (gc->gh) |
120 |
|
|
release_gpg_options( gc->gh ); |
121 |
|
|
gc->gh = NULL; |
122 |
|
|
gc->tree = NULL; |
123 |
|
|
delete gc; |
124 |
|
|
} |
125 |
|
|
} /* km_groups_release */ |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
int |
129 |
|
|
km_groups_load( km_group_t gc ) |
130 |
|
|
{ |
131 |
|
|
HTREEITEM n; |
132 |
|
|
gpg_group_t grp, g; |
133 |
|
|
gpg_member_t mbr; |
134 |
|
|
u32 gid = 0; |
135 |
|
|
|
136 |
|
|
if( !gc->gh ) |
137 |
|
|
return 0; |
138 |
|
|
grp = gc->gh->grp; |
139 |
|
|
if( !grp ) |
140 |
|
|
return 0; /* no groups */ |
141 |
|
|
|
142 |
|
|
for( g = grp; g; g = g->next ) { |
143 |
|
|
n = km_tv_insert_item( gc->tree, NULL, g->name ); |
144 |
|
|
for( mbr = g->list; mbr; mbr = mbr->next ) { |
145 |
|
|
if( mbr->used && mbr->name ) |
146 |
|
|
km_tv_insert_item( gc->tree, n, mbr->name ); |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
|
DragAcceptFiles( gc->tree, TRUE ); |
150 |
|
|
gc->need_sync = 0; |
151 |
|
|
return 0; |
152 |
|
|
} /* km_groups_load */ |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
int |
156 |
|
|
km_groups_add (km_group_t gc, listview_ctrl_t lv, int km_index) |
157 |
|
|
{ |
158 |
|
|
TVITEM tvi; |
159 |
|
|
char uid[128], valid[64], text[128]; |
160 |
|
|
int i_valid; |
161 |
|
|
|
162 |
|
|
memset( &tvi, 0, sizeof tvi ); |
163 |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
164 |
|
|
tvi.pszText = text; |
165 |
|
|
tvi.cchTextMax = sizeof text -1; |
166 |
|
|
tvi.mask = TVIF_TEXT; |
167 |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
listview_get_item_text( lv, km_index, 0, uid, sizeof uid -1 ); |
171 |
|
|
listview_get_item_text( lv, km_index, 5, valid, sizeof valid -1 ); |
172 |
|
|
|
173 |
|
|
if( strstr( valid, "Ultimate" ) ) |
174 |
|
|
i_valid = 5; |
175 |
|
|
else if( !strstr( valid, "Full" ) ) |
176 |
|
|
i_valid = 4; |
177 |
|
|
else if( !strstr( valid, "Marginal" ) ) |
178 |
|
|
i_valid = 3; |
179 |
|
|
else |
180 |
|
|
i_valid = 0; |
181 |
|
|
|
182 |
|
|
/* we can't add the full name. one way would be to use the first |
183 |
|
|
text until a space appears. |
184 |
|
|
group_add_entry(&gc->gh, gid, i_valid, uid); |
185 |
|
|
treeview_add_item(gc->tree, tvi.hItem, uid); |
186 |
|
|
*/ |
187 |
|
|
gc->need_sync = 1; |
188 |
|
|
|
189 |
|
|
return 0; |
190 |
|
|
} /* km_groups_add */ |
191 |
|
|
|
192 |
|
|
|
193 |
|
|
static int |
194 |
|
|
km_groups_del_main( km_group_t gc ) |
195 |
|
|
{ |
196 |
|
|
TVITEM tvi; |
197 |
|
|
char text[128]; |
198 |
|
|
int id; |
199 |
|
|
|
200 |
|
|
memset( &tvi, 0, sizeof tvi ); |
201 |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
202 |
|
|
tvi.pszText = text; |
203 |
|
|
tvi.cchTextMax = sizeof text -1; |
204 |
|
|
tvi.mask = TVIF_TEXT; |
205 |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
206 |
|
|
|
207 |
|
|
id = log_box( _("Key Manager"), MB_INFO_ASK, |
208 |
|
|
_("Do you really want to delete this group?\n\n%s"), text); |
209 |
|
|
if( id == IDNO ) |
210 |
|
|
return 0; |
211 |
|
|
delete_group( gc->gh, text ); |
212 |
|
|
TreeView_DeleteItem( gc->tree, &tvi ); |
213 |
|
|
gc->need_sync = 1; |
214 |
|
|
|
215 |
|
|
return 0; |
216 |
|
|
} /* km_groups_del */ |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
static int |
220 |
|
|
km_groups_del_entry( km_group_t gc ) |
221 |
|
|
{ |
222 |
|
|
TVITEM tvi; |
223 |
|
|
HTREEITEM root; |
224 |
|
|
int id; |
225 |
|
|
char text[128], info[256]; |
226 |
|
|
gpg_group_t grp = NULL; |
227 |
|
|
|
228 |
|
|
memset( &tvi, 0, sizeof tvi ); |
229 |
|
|
tvi.hItem = TreeView_GetSelection( gc->tree ); |
230 |
|
|
tvi.pszText = text; |
231 |
|
|
tvi.cchTextMax = sizeof text-1; |
232 |
|
|
tvi.mask = TVIF_TEXT; |
233 |
|
|
TreeView_GetItem( gc->tree, &tvi ); |
234 |
|
|
|
235 |
|
|
_snprintf( info, sizeof info -1, |
236 |
|
|
_("Do you really want to delete this entry?\n\n%s"), text ); |
237 |
|
|
|
238 |
|
|
id = msg_box( gc->tree, info, _("Key Manager"), MB_INFO_ASK ); |
239 |
|
|
if( id == IDNO ) |
240 |
|
|
return 0; |
241 |
|
|
|
242 |
|
|
root = TreeView_GetParent( gc->tree, tvi.hItem ); |
243 |
|
|
if( root ) { |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
delete_member( gc->gh, /*fixme*/NULL, text ); |
247 |
|
|
TreeView_DeleteItem( gc->tree, &tvi ); |
248 |
|
|
gc->need_sync = 1; |
249 |
|
|
return 0; |
250 |
|
|
} /* km_groups_del_entry */ |
251 |
|
|
|
252 |
|
|
|
253 |
|
|
int |
254 |
|
|
km_groups_del( km_group_t gc ) |
255 |
|
|
{ |
256 |
|
|
if ( TreeView_GetParent( gc->tree, TreeView_GetSelection( gc->tree ) ) ) |
257 |
|
|
return km_groups_del_entry( gc ); |
258 |
|
|
else |
259 |
|
|
return km_groups_del_main( gc ); |
260 |
|
|
} /* km_groups_del */ |
261 |
|
|
#endif |