1 |
twoaday |
2 |
/* ownertrust.c - Ownertrust handling |
2 |
|
|
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of MyGPGME. |
5 |
|
|
* |
6 |
|
|
* MyGPGME 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 |
|
|
* MyGPGME 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 this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include <stdio.h> |
22 |
|
|
#include <stdlib.h> |
23 |
|
|
#include <string.h> |
24 |
|
|
#include <assert.h> |
25 |
|
|
|
26 |
|
|
#include "context.h" |
27 |
|
|
#include "ops.h" |
28 |
|
|
#include "key.h" |
29 |
|
|
#include "util.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
static gpgme_error_t |
33 |
|
|
key_trust_export_start( gpgme_ctx_t c, gpgme_data_t out ) |
34 |
|
|
{ |
35 |
|
|
gpgme_error_t rc; |
36 |
|
|
|
37 |
|
|
fail_on_pending_request( c ); |
38 |
|
|
c->pending = 1; |
39 |
|
|
|
40 |
|
|
_gpgme_gpg_release( &c->gpg ); |
41 |
|
|
rc = _gpgme_gpg_new( &c->gpg ); |
42 |
|
|
if( rc ) |
43 |
|
|
goto leave; |
44 |
|
|
|
45 |
|
|
_gpgme_data_set_mode( out, GPGME_DATA_MODE_IN ); |
46 |
|
|
_gpgme_gpg_add_arg( c->gpg, "--export-ownertrust" ); |
47 |
|
|
_gpgme_gpg_add_arg( c->gpg, "--output" ); |
48 |
|
|
_gpgme_gpg_add_arg( c->gpg, "-" ); |
49 |
|
|
_gpgme_gpg_add_data( c->gpg, out, 1 ); |
50 |
|
|
rc = _gpgme_gpg_spawn( c->gpg, c ); |
51 |
|
|
|
52 |
|
|
leave: |
53 |
|
|
if( rc ) { |
54 |
|
|
c->pending = 0; |
55 |
|
|
_gpgme_gpg_release( &c->gpg ); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
return rc; |
59 |
|
|
} /* gpgme_op_key_trust_export_start */ |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
gpgme_error_t |
63 |
|
|
gpgme_op_key_trust_export( gpgme_ctx_t c, gpgme_data_t out ) |
64 |
|
|
{ |
65 |
|
|
gpgme_error_t rc = key_trust_export_start( c, out ); |
66 |
|
|
if( !rc ) { |
67 |
|
|
gpgme_wait( c, 1 ); |
68 |
|
|
c->pending = 0; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
return rc; |
72 |
|
|
} /* gpgme_op_key_trust_export */ |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
static gpgme_error_t |
76 |
|
|
key_trust_import_start( gpgme_ctx_t c, gpgme_data_t in ) |
77 |
|
|
{ |
78 |
|
|
gpgme_error_t rc; |
79 |
|
|
|
80 |
|
|
fail_on_pending_request( c ); |
81 |
|
|
c->pending = 1; |
82 |
|
|
|
83 |
|
|
_gpgme_gpg_release( &c->gpg ); |
84 |
|
|
rc = _gpgme_gpg_new( &c->gpg ); |
85 |
|
|
if( rc ) |
86 |
|
|
goto leave; |
87 |
|
|
|
88 |
|
|
_gpgme_data_set_mode( in, GPGME_DATA_MODE_OUT ); |
89 |
|
|
_gpgme_gpg_add_arg( c->gpg, "--import-ownertrust" ); |
90 |
|
|
_gpgme_gpg_add_arg( c->gpg, "--" ); |
91 |
|
|
_gpgme_gpg_add_data( c->gpg, in, 0 ); |
92 |
|
|
|
93 |
|
|
rc = _gpgme_gpg_spawn( c->gpg, c ); |
94 |
|
|
|
95 |
|
|
leave: |
96 |
|
|
if( rc ) { |
97 |
|
|
c->pending = 0; |
98 |
|
|
_gpgme_gpg_release( &c->gpg ); |
99 |
|
|
} |
100 |
|
|
return rc; |
101 |
|
|
} /* key_trust_import_start */ |
102 |
|
|
|
103 |
|
|
|
104 |
|
|
gpgme_error_t |
105 |
|
|
gpgme_op_key_trust_import( gpgme_ctx_t ctx, gpgme_data_t in ) |
106 |
|
|
{ |
107 |
|
|
gpgme_error_t err; |
108 |
|
|
|
109 |
|
|
err = key_trust_import_start( ctx, in ); |
110 |
|
|
if( !err ) { |
111 |
|
|
gpgme_wait( ctx, 1 ); |
112 |
|
|
ctx->pending = 0; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
return err; |
116 |
|
|
} /* gpgme_op_key_trust_import */ |
117 |
|
|
|
118 |
|
|
|
119 |
|
|
gpgme_error_t |
120 |
|
|
gpgme_op_ownertrust_export_file( const char *output ) |
121 |
|
|
{ |
122 |
|
|
gpgme_error_t err; |
123 |
|
|
gpgme_ctx_t ctx; |
124 |
|
|
gpgme_data_t otrust; |
125 |
|
|
|
126 |
|
|
err = gpgme_new( &ctx ); |
127 |
|
|
if( !err ) |
128 |
|
|
err = gpgme_data_new( &otrust ); |
129 |
|
|
if( !err ) |
130 |
|
|
err = gpgme_op_key_trust_export( ctx, otrust ); |
131 |
|
|
if( !err ) |
132 |
|
|
err = gpgme_data_release_and_set_file( otrust, output ); |
133 |
|
|
|
134 |
|
|
gpgme_release( ctx ); |
135 |
|
|
return err; |
136 |
|
|
} /* gpgme_op_ownertrust_export_file */ |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
gpgme_error_t |
140 |
|
|
gpgme_op_ownertrust_import_file( const char *input ) |
141 |
|
|
{ |
142 |
|
|
gpgme_error_t err; |
143 |
|
|
gpgme_ctx_t ctx; |
144 |
|
|
gpgme_data_t otrust = NULL; |
145 |
|
|
|
146 |
|
|
err = gpgme_new( &ctx ); |
147 |
|
|
if( !err ) |
148 |
|
|
err = gpgme_data_new_from_file (&otrust, input); |
149 |
|
|
if( !err ) |
150 |
|
|
err = gpgme_op_key_trust_import( ctx, otrust ); |
151 |
|
|
|
152 |
|
|
gpgme_data_release( otrust ); |
153 |
|
|
gpgme_release( ctx ); |
154 |
|
|
return err; |
155 |
|
|
} /* gpgme_op_ownertrust_import_file */ |
156 |
|
|
|
157 |
|
|
|
158 |
|
|
static gpgme_error_t |
159 |
twoaday |
21 |
rebuild_cache_start (gpgme_ctx_t c) |
160 |
twoaday |
2 |
{ |
161 |
|
|
gpgme_error_t rc = 0; |
162 |
|
|
|
163 |
twoaday |
21 |
_gpgme_gpg_release (&c->gpg); |
164 |
|
|
rc = _gpgme_gpg_new (&c->gpg); |
165 |
|
|
if (rc) |
166 |
twoaday |
2 |
goto leave; |
167 |
|
|
|
168 |
twoaday |
21 |
_gpgme_gpg_add_arg (c->gpg, "--rebuild-keydb-cache"); |
169 |
|
|
rc = _gpgme_gpg_spawn (c->gpg, c); |
170 |
twoaday |
2 |
|
171 |
|
|
leave: |
172 |
twoaday |
21 |
if (rc) { |
173 |
|
|
c->pending = 0; |
174 |
|
|
_gpgme_gpg_release (&c->gpg); |
175 |
twoaday |
2 |
} |
176 |
|
|
return rc; |
177 |
|
|
} /* rebuild_cache_start */ |
178 |
|
|
|
179 |
|
|
|
180 |
|
|
gpgme_error_t |
181 |
twoaday |
21 |
gpgme_op_rebuild_cache (void) |
182 |
twoaday |
2 |
{ |
183 |
|
|
gpgme_error_t err; |
184 |
|
|
gpgme_ctx_t ctx; |
185 |
|
|
|
186 |
twoaday |
21 |
err = gpgme_new (&ctx); |
187 |
|
|
if (err) |
188 |
twoaday |
2 |
return err; |
189 |
twoaday |
21 |
err = rebuild_cache_start (ctx); |
190 |
|
|
if (!err) { |
191 |
|
|
gpgme_wait (ctx, 1); |
192 |
twoaday |
2 |
ctx->pending = 0; |
193 |
|
|
} |
194 |
twoaday |
21 |
gpgme_release (ctx); |
195 |
twoaday |
2 |
|
196 |
|
|
return err; |
197 |
|
|
} /* gpgme_op_rebuild_cache */ |
198 |
|
|
|