From: Werner Koch Date: Tue, 13 Mar 2001 20:17:22 +0000 (+0000) Subject: Add a few key flags - needs the lates CVS gpg X-Git-Tag: gpgme-0-2-1~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ca12983e7c751204ac90f2ea828fe9f321dce73c;p=gpgme.git Add a few key flags - needs the lates CVS gpg --- diff --git a/ChangeLog b/ChangeLog index f11e6da..e3c455a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2001-02-28 Werner Koch + + Released 0.2.0. + 2001-01-18 Werner Koch * autogen.sh: Added option --build-w32. diff --git a/configure.in b/configure.in index b00aa3b..903b24c 100644 --- a/configure.in +++ b/configure.in @@ -13,11 +13,11 @@ AM_MAINTAINER_MODE # AGE, set REVISION to 0. # 3. Interfaces removed (BAD, breaks upward compatibility): Increment # CURRENT, set AGE and REVISION to 0. -AM_INIT_AUTOMAKE(gpgme,0.1.4b) -LIBGPGME_LT_CURRENT=2 -LIBGPGME_LT_AGE=2 +AM_INIT_AUTOMAKE(gpgme,0.2.0a) +LIBGPGME_LT_CURRENT=3 +LIBGPGME_LT_AGE=3 LIBGPGME_LT_REVISION=0 -NEED_GPG_VERSION=1.0.4d +NEED_GPG_VERSION=1.0.4e ############################################## AC_SUBST(LIBGPGME_LT_CURRENT) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index e8c0c9b..9f1f83b 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,19 @@ +2001-03-13 Werner Koch + + * context.h: Add invalid and revoke flags to user_id structure. + * keylist.c (gpgme_op_keylist_start): Use --fixed-list-mode. + (keylist_colon_handler): Adjust for that. + (set_userid_flags): New. + (set_mainkey_trust_info): Handle new key invalid flag + (set_subkey_trust_info): Ditto. + * gpgme.h: Add new attributes for key and user ID flags. + * key.c (_gpgme_key_append_name): Init these flags + (gpgme_key_get_as_xml): Print them. + (one_uid_as_xml): New helper for above. + (gpgme_key_get_string_attr, gpgme_key_get_ulong_attr): + Return the new attributes. Enhanced, so that subkey information + can be returned now. + 2001-02-28 Werner Koch * w32-io.c (destroy_reader): Set sop_me flag. diff --git a/gpgme/context.h b/gpgme/context.h index 57d9d1f..de6ca72 100644 --- a/gpgme/context.h +++ b/gpgme/context.h @@ -108,6 +108,8 @@ struct gpgme_data_s { struct user_id_s { struct user_id_s *next; + unsigned int revoked:1; + unsigned int invalid:1; GpgmeValidity validity; const char *name_part; /* all 3 point into strings behind name */ const char *email_part; /* or to read-only strings */ diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index 778e66c..562af19 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -43,7 +43,7 @@ extern "C" { * let autoconf (using the AM_PATH_GPGME macro) check that this * header matches the installed library. * Warning: Do not edit the next line. configure will do that for you! */ -#define GPGME_VERSION "0.1.4b" +#define GPGME_VERSION "0.2.0a" @@ -129,7 +129,11 @@ typedef enum { GPGME_ATTR_VALIDITY= 12, GPGME_ATTR_LEVEL = 13, GPGME_ATTR_TYPE = 14, - GPGME_ATTR_IS_SECRET= 15 + GPGME_ATTR_IS_SECRET= 15, + GPGME_ATTR_KEY_REVOKED = 16, + GPGME_ATTR_KEY_INVALID = 17, + GPGME_ATTR_UID_REVOKED = 18, + GPGME_ATTR_UID_INVALID = 19 } GpgmeAttr; typedef enum { diff --git a/gpgme/key.c b/gpgme/key.c index 3ee49f7..35a5404 100644 --- a/gpgme/key.c +++ b/gpgme/key.c @@ -259,6 +259,8 @@ _gpgme_key_append_name ( GpgmeKey key, const char *s ) uid = xtrymalloc ( sizeof *uid + 2*strlen (s)+3 ); if ( !uid ) return mk_error (Out_Of_Core); + uid->revoked = 0; + uid->invalid = 0; uid->validity = 0; uid->name_part = NULL; uid->email_part = NULL; @@ -362,6 +364,25 @@ add_tag_and_time ( GpgmeData d, const char *tag, time_t val ) add_tag_and_string ( d, tag, buf ); } +static void +one_uid_as_xml (GpgmeData d, struct user_id_s *u) +{ + _gpgme_data_append_string (d, " \n"); + if ( u->invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( u->revoked ) + _gpgme_data_append_string ( d, " \n"); + add_tag_and_string ( d, "raw", u->name ); + if ( *u->name_part ) + add_tag_and_string ( d, "name", u->name_part ); + if ( *u->email_part ) + add_tag_and_string ( d, "email", u->email_part ); + if ( *u->comment_part ) + add_tag_and_string ( d, "comment", u->comment_part ); + _gpgme_data_append_string (d, " \n"); +} + + char * gpgme_key_get_as_xml ( GpgmeKey key ) { @@ -377,8 +398,16 @@ gpgme_key_get_as_xml ( GpgmeKey key ) _gpgme_data_append_string ( d, "\n" " \n" ); - if ( key->secret ) + if ( key->keys.secret ) _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.revoked ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.expired ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.disabled ) + _gpgme_data_append_string ( d, " \n"); add_tag_and_string (d, "keyid", key->keys.keyid ); if (key->keys.fingerprint) add_tag_and_string (d, "fpr", key->keys.fingerprint ); @@ -388,23 +417,30 @@ gpgme_key_get_as_xml ( GpgmeKey key ) /*add_tag_and_time (d, "expires", key->expires );*/ _gpgme_data_append_string (d, " \n"); - /* Now the user IDs */ - for ( u = key->uids; u; u = u->next ) { - _gpgme_data_append_string (d, " \n"); - add_tag_and_string ( d, "raw", u->name ); - if ( *u->name_part ) - add_tag_and_string ( d, "name", u->name_part ); - if ( *u->email_part ) - add_tag_and_string ( d, "email", u->email_part ); - if ( *u->comment_part ) - add_tag_and_string ( d, "comment", u->comment_part ); - _gpgme_data_append_string (d, " \n"); + /* Now the user IDs. We are listing the last one firs becuase this is + * the primary one. */ + for (u = key->uids; u && u->next; u = u->next ) + ; + if (u) { + one_uid_as_xml (d,u); + for ( u = key->uids; u && u->next; u = u->next ) { + one_uid_as_xml (d,u); + } } - + + /* and now the subkeys */ for (k=key->keys.next; k; k = k->next ) { _gpgme_data_append_string (d, " \n"); if ( k->secret ) _gpgme_data_append_string ( d, " \n"); + if ( k->flags.invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.revoked ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.expired ) + _gpgme_data_append_string ( d, " \n"); + if ( k->flags.disabled ) + _gpgme_data_append_string ( d, " \n"); add_tag_and_string (d, "keyid", k->keyid ); if (k->fingerprint) add_tag_and_string (d, "fpr", k->fingerprint ); @@ -424,6 +460,7 @@ gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, const void *reserved, int idx ) { const char *val = NULL; + struct subkey_s *k; struct user_id_s *u; if (!key) @@ -435,13 +472,22 @@ gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, switch (what) { case GPGME_ATTR_KEYID: - val = key->keys.keyid; + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->keyid; break; case GPGME_ATTR_FPR: - val = key->keys.fingerprint; + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->fingerprint; break; case GPGME_ATTR_ALGO: - val = pkalgo_to_string (key->keys.key_algo); + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = pkalgo_to_string (k->key_algo); break; case GPGME_ATTR_LEN: case GPGME_ATTR_CREATED: @@ -486,6 +532,10 @@ gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, break; case GPGME_ATTR_LEVEL: /* not used here */ case GPGME_ATTR_TYPE: + case GPGME_ATTR_KEY_REVOKED: + case GPGME_ATTR_KEY_INVALID: + case GPGME_ATTR_UID_REVOKED: + case GPGME_ATTR_UID_INVALID: break; case GPGME_ATTR_IS_SECRET: if (key->secret) @@ -501,6 +551,7 @@ gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what, const void *reserved, int idx ) { unsigned long val = 0; + struct subkey_s *k; struct user_id_s *u; if (!key) @@ -512,13 +563,22 @@ gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what, switch (what) { case GPGME_ATTR_ALGO: - val = (unsigned long)key->keys.key_algo; + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = (unsigned long)k->key_algo; break; case GPGME_ATTR_LEN: - val = (unsigned long)key->keys.key_len; + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = (unsigned long)k->key_len; break; case GPGME_ATTR_CREATED: - val = key->keys.timestamp < 0? 0L:(unsigned long)key->keys.timestamp; + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->timestamp < 0? 0L:(unsigned long)k->timestamp; break; case GPGME_ATTR_VALIDITY: for (u=key->uids; u && idx; u=u->next, idx-- ) @@ -529,6 +589,30 @@ gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what, case GPGME_ATTR_IS_SECRET: val = !!key->secret; break; + case GPGME_ATTR_KEY_REVOKED: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->flags.revoked; + break; + case GPGME_ATTR_KEY_INVALID: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = k->flags.invalid; + break; + case GPGME_ATTR_UID_REVOKED: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + if (u) + val = u->revoked; + break; + case GPGME_ATTR_UID_INVALID: + for (u=key->uids; u && idx; u=u->next, idx-- ) + ; + if (u) + val = u->invalid; + break; default: break; } diff --git a/gpgme/key.h b/gpgme/key.h index 91a4c84..83d46ed 100644 --- a/gpgme/key.h +++ b/gpgme/key.h @@ -32,6 +32,7 @@ struct subkey_s { unsigned int revoked:1 ; unsigned int expired:1 ; unsigned int disabled:1 ; + unsigned int invalid:1 ; } flags; unsigned int key_algo; unsigned int key_len; @@ -45,6 +46,7 @@ struct gpgme_key_s { unsigned int revoked:1 ; unsigned int expired:1 ; unsigned int disabled:1 ; + unsigned int invalid:1 ; } gloflags; unsigned int ref_count; unsigned int secret:1; diff --git a/gpgme/keylist.c b/gpgme/keylist.c index 4e852f9..a42cde8 100644 --- a/gpgme/keylist.c +++ b/gpgme/keylist.c @@ -98,6 +98,21 @@ set_mainkey_trust_info ( GpgmeKey key, const char *s ) case 'e': key->keys.flags.expired = 1; break; case 'r': key->keys.flags.revoked = 1; break; case 'd': key->keys.flags.disabled = 1; break; + case 'i': key->keys.flags.invalid = 1; break; + } + } +} + + +static void +set_userid_flags ( GpgmeKey key, const char *s ) +{ + /* look at letters and stop at the first digit */ + for (; *s && !my_isdigit (*s); s++ ) { + switch (*s) { + case 'r': key->uids->revoked = 1; break; + case 'i': key->uids->invalid = 1; break; + case 'n': key->uids->validity = 1; break; case 'm': key->uids->validity = 2; break; case 'f': key->uids->validity = 3; break; @@ -115,6 +130,7 @@ set_subkey_trust_info ( struct subkey_s *k, const char *s ) case 'e': k->flags.expired = 1; break; case 'r': k->flags.revoked = 1; break; case 'd': k->flags.disabled = 1; break; + case 'i': k->flags.invalid = 1; break; } } } @@ -201,7 +217,8 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) else if ( rectype == RT_PUB || rectype == RT_SEC ) { switch (field) { case 2: /* trust info */ - trust_info = p; /*save for later */ + trust_info = p; + set_mainkey_trust_info (key, trust_info); break; case 3: /* key length */ i = atoi (p); @@ -226,13 +243,7 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) break; case 9: /* ownertrust */ break; - case 10: /* This is the first name listed */ - if ( _gpgme_key_append_name ( key, p) ) - ctx->out_of_core = 1; - else { - if (trust_info) - set_mainkey_trust_info (key, trust_info); - } + case 10: /* not used due to --fixed-list-mode option */ break; case 11: /* signature class */ break; @@ -283,12 +294,12 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) case 2: /* trust info */ trust_info = p; /*save for later */ break; - case 10: /* the 2nd, 3rd,... user ID */ + case 10: /* user ID */ if ( _gpgme_key_append_name ( key, p) ) ctx->out_of_core = 1; else { if (trust_info) - set_mainkey_trust_info (key, trust_info); + set_userid_flags (key, trust_info); } pend = NULL; /* we can stop here */ break; @@ -393,6 +404,7 @@ gpgme_op_keylist_start ( GpgmeCtx c, const char *pattern, int secret_only ) for ( i=0; i < c->verbosity; i++ ) _gpgme_gpg_add_arg ( c->gpg, "--verbose" ); _gpgme_gpg_add_arg ( c->gpg, "--with-colons" ); + _gpgme_gpg_add_arg ( c->gpg, "--fixed-list-mode" ); _gpgme_gpg_add_arg ( c->gpg, "--with-fingerprint" ); if (c->keylist_mode == 1) _gpgme_gpg_add_arg ( c->gpg, "--no-expensive-trust-checks" ); diff --git a/gpgme/w32-io.c b/gpgme/w32-io.c index 311eb3c..4e2c1c9 100644 --- a/gpgme/w32-io.c +++ b/gpgme/w32-io.c @@ -269,9 +269,11 @@ create_reader (HANDLE fd) static void destroy_reader (struct reader_context_s *c) { + LOCK (c->mutex) c->stop_me = 1; if (c->have_space_ev) SetEvent (c->have_space_ev); + UNLOCK (c->mutex) DEBUG1 ("waiting for thread %p termination ...", c->thread_hd ); WaitForSingleObject (c->stopped, INFINITE); @@ -520,9 +522,11 @@ create_writer (HANDLE fd) static void destroy_writer (struct writer_context_s *c) { + LOCK (c->mutex) c->stop_me = 1; if (c->have_data) SetEvent (c->have_data); + UNLOCK (c->mutex) DEBUG1 ("waiting for thread %p termination ...", c->thread_hd ); WaitForSingleObject (c->stopped, INFINITE);