55 |
|
|
56 |
|
|
57 |
static time_t |
static time_t |
58 |
parse_timestamp( char * p ) |
parse_timestamp (char * p) |
59 |
{ |
{ |
60 |
return *p ? (time_t)strtoul( p, NULL, 10 ) : 0; |
return *p ? (time_t)strtoul (p, NULL, 10) : 0; |
61 |
} |
} |
62 |
|
|
63 |
|
|
163 |
|
|
164 |
/* Note: we are allowed to modify line */ |
/* Note: we are allowed to modify line */ |
165 |
static void |
static void |
166 |
keylist_colon_handler( gpgme_ctx_t ctx, char * line ) |
keylist_colon_handler (gpgme_ctx_t ctx, char *line) |
167 |
{ |
{ |
168 |
enum { |
enum { |
169 |
RT_NONE, |
RT_NONE, |
170 |
RT_SIG, |
RT_SIG, |
171 |
RT_UID, |
RT_UID, |
172 |
RT_SUB, |
RT_SUB, |
173 |
RT_PUB, |
RT_PUB, |
174 |
RT_FPR, |
RT_FPR, |
177 |
RT_PKD, |
RT_PKD, |
178 |
} rectype = RT_NONE; |
} rectype = RT_NONE; |
179 |
gpgme_key_t key = ctx->tmp_key; |
gpgme_key_t key = ctx->tmp_key; |
180 |
struct subkey_s * sk = NULL; |
struct subkey_s *sk = NULL; |
181 |
struct signature_s * sig = NULL; |
struct signature_s *sig = NULL; |
182 |
struct subkey_s * s = NULL; |
struct subkey_s *s = NULL; |
183 |
struct user_id_s * u = NULL; |
struct user_id_s *u = NULL; |
184 |
struct mpi_s * m = NULL, * mt = NULL; |
struct mpi_s *m = NULL, * mt = NULL; |
185 |
const char * trust_info = NULL; |
const char *trust_info = NULL; |
186 |
char * p, * pend; |
char *p, *pend; |
187 |
int field = 0; |
int field = 0; |
188 |
unsigned long val=0; |
unsigned long val=0; |
189 |
int i; |
int i; |
190 |
|
|
191 |
if( ctx->out_of_core ) |
if (ctx->out_of_core) |
192 |
return; |
return; |
193 |
if( !line ) { /* EOF */ |
if( !line ) { /* EOF */ |
194 |
if( ctx->tmp_key ) |
if( ctx->tmp_key ) |
283 |
set_mainkey_trust_info( key, trust_info ); |
set_mainkey_trust_info( key, trust_info ); |
284 |
break; |
break; |
285 |
case 3: /* key length */ |
case 3: /* key length */ |
286 |
i = atoi( p ); |
i = atoi (p); |
287 |
if( i > 1 ) /* ignore invalid values */ |
if( i > 1 ) /* ignore invalid values */ |
288 |
key->keys.key_len = i; |
key->keys.key_len = i; |
289 |
break; |
break; |
290 |
case 4: /* pubkey algo */ |
case 4: /* pubkey algo */ |
291 |
i = atoi ( p ); |
i = atoi (p); |
292 |
if( i > 0 && i < 128 ) |
if (i > 0 && i < 128) |
293 |
key->keys.key_algo = i; |
key->keys.key_algo = i; |
294 |
break; |
break; |
295 |
case 5: /* long keyid */ |
case 5: /* long keyid */ |
325 |
break; |
break; |
326 |
} |
} |
327 |
} |
} |
328 |
else if( (rectype == RT_SUB || rectype== RT_SSB) && sk ) { |
else if ((rectype == RT_SUB || rectype== RT_SSB) && sk) { |
329 |
switch( field ) { |
switch (field) { |
330 |
case 2: /* trust info */ |
case 2: /* trust info */ |
331 |
set_subkey_trust_info( sk, p ); |
set_subkey_trust_info (sk, p); |
332 |
break; |
break; |
333 |
|
|
334 |
case 3: /* key length */ |
case 3: /* key length */ |
335 |
i = atoi( p ); |
i = atoi( p ); |
336 |
if ( i > 1 ) /* ignore invalid values */ |
if ( i > 1 ) /* ignore invalid values */ |
337 |
sk->key_len = i; |
sk->key_len = i; |
338 |
break; |
break; |
339 |
|
|
340 |
case 4: /* pubkey algo */ |
case 4: /* pubkey algo */ |
341 |
i = atoi( p ); |
i = atoi (p); |
342 |
if( i > 0 && i < 128 ) |
if (i > 0 && i < 128) |
343 |
sk->key_algo = i; |
sk->key_algo = i; |
344 |
break; |
break; |
345 |
|
|
346 |
case 5: /* long keyid */ |
case 5: /* long keyid */ |
347 |
memset (sk->keyid, 0, sizeof sk->keyid); |
memset (sk->keyid, 0, sizeof sk->keyid); |
348 |
strncpy (sk->keyid, p, DIM (sk->keyid)-1); |
strncpy (sk->keyid, p, DIM (sk->keyid)-1); |
571 |
* Return value: 0 on success or an errorcode. |
* Return value: 0 on success or an errorcode. |
572 |
**/ |
**/ |
573 |
gpgme_error_t |
gpgme_error_t |
574 |
gpgme_op_keylist_start( gpgme_ctx_t ctx, const char *pattern, int secret_only ) |
gpgme_op_keylist_start (gpgme_ctx_t ctx, const char *pattern, int secret_only) |
575 |
{ |
{ |
576 |
gpgme_error_t rc = 0; |
gpgme_error_t rc = 0; |
577 |
|
|
578 |
if( !ctx ) |
if (!ctx) |
579 |
return mk_error( Invalid_Value ); |
return mk_error (Invalid_Value); |
580 |
ctx->pending = 1; |
ctx->pending = 1; |
581 |
|
|
582 |
_gpgme_release_result( ctx ); |
_gpgme_release_result (ctx); |
583 |
ctx->out_of_core = 0; |
ctx->out_of_core = 0; |
584 |
ctx->cb.progess_tmp = 0; |
ctx->cb.progess_tmp = 0; |
585 |
|
|
586 |
_gpgme_gpg_release( &ctx->gpg ); |
_gpgme_gpg_release (&ctx->gpg); |
587 |
gpgme_key_release( ctx->tmp_key ); |
gpgme_key_release (ctx->tmp_key); |
588 |
ctx->tmp_key = NULL; |
ctx->tmp_key = NULL; |
589 |
/* Fixme: release key_queue */ |
/* Fixme: release key_queue */ |
590 |
|
|
591 |
rc = _gpgme_gpg_new( &ctx->gpg ); |
rc = _gpgme_gpg_new (&ctx->gpg); |
592 |
if( rc ) |
if (rc) |
593 |
goto leave; |
goto leave; |
594 |
|
|
595 |
_gpgme_gpg_set_status_handler( ctx->gpg, keylist_status_handler, ctx ); |
_gpgme_gpg_set_status_handler (ctx->gpg, keylist_status_handler, ctx); |
596 |
rc = _gpgme_gpg_set_colon_line_handler( ctx->gpg, keylist_colon_handler, ctx ); |
rc = _gpgme_gpg_set_colon_line_handler (ctx->gpg, keylist_colon_handler, ctx); |
597 |
if ( rc ) |
if (rc) |
598 |
goto leave; |
goto leave; |
599 |
|
|
600 |
/* build the commandline */ |
/* build the commandline */ |
601 |
if (ctx->use_logging) |
if (ctx->use_logging) |
602 |
_gpgme_gpg_set_logging_handler (ctx->gpg, ctx); |
_gpgme_gpg_set_logging_handler (ctx->gpg, ctx); |
603 |
_gpgme_gpg_set_list_options (ctx->gpg, ctx->list_opts); |
_gpgme_gpg_set_list_options (ctx->gpg, ctx->list_opts); |
604 |
_gpgme_gpg_add_arg( ctx->gpg, "--with-colons" ); |
_gpgme_gpg_add_arg (ctx->gpg, "--with-colons"); |
605 |
_gpgme_gpg_add_arg( ctx->gpg, "--fixed-list-mode" ); |
_gpgme_gpg_add_arg (ctx->gpg, "--fixed-list-mode"); |
606 |
_gpgme_gpg_add_arg( ctx->gpg, "--with-fingerprint" ); |
_gpgme_gpg_add_arg (ctx->gpg, "--with-fingerprint"); |
607 |
_gpgme_gpg_add_arg( ctx->gpg, "--with-fingerprint" ); /* for the subkey */ |
_gpgme_gpg_add_arg (ctx->gpg, "--with-fingerprint"); /* for the subkey */ |
608 |
if( ctx->keylist_mode & 1 ) |
if (ctx->keylist_mode & 1) |
609 |
_gpgme_gpg_add_arg( ctx->gpg, "--no-expensive-trust-checks" ); |
_gpgme_gpg_add_arg (ctx->gpg, "--no-expensive-trust-checks"); |
610 |
if( ctx->keylist_mode & 2 ) |
if (ctx->keylist_mode & 2) |
611 |
_gpgme_gpg_add_arg( ctx->gpg, "--with-key-data" ); |
_gpgme_gpg_add_arg (ctx->gpg, "--with-key-data"); |
612 |
if( ctx->keylist_mode & 4 ) |
if (ctx->keylist_mode & 4) |
613 |
_gpgme_gpg_add_arg( ctx->gpg, "--fast-list-mode" ); |
_gpgme_gpg_add_arg (ctx->gpg, "--fast-list-mode"); |
614 |
if( 1 || !ctx->keylist_mode ) /* XXX: do all combinations make sense? */ |
if (secret_only) |
615 |
_gpgme_gpg_add_arg( ctx->gpg, "-vvv" ); /* to list and check sigs */ |
_gpgme_gpg_add_arg (ctx->gpg, "--list-secret-keys"); |
616 |
_gpgme_gpg_add_arg ( ctx->gpg, secret_only? |
else { |
617 |
"--list-secret-keys": /*"--list-keys"*/ "-k" ); |
if (ctx->keylist_mode & 8) |
618 |
|
_gpgme_gpg_add_arg (ctx->gpg, "--check-sigs"); |
619 |
|
else |
620 |
|
_gpgme_gpg_add_arg (ctx->gpg, "--list-keys"); |
621 |
|
} |
622 |
|
|
623 |
/* Tell the gpg object about the data */ |
/* Tell the gpg object about the data */ |
624 |
_gpgme_gpg_add_arg ( ctx->gpg, "--" ); |
_gpgme_gpg_add_arg ( ctx->gpg, "--" ); |