diff options
author | Werner Koch <[email protected]> | 2009-12-08 16:30:33 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2009-12-08 16:30:33 +0000 |
commit | 9a96043be4bed4e18320918e042b1601c9d93e95 (patch) | |
tree | 0066f7268d25aa95d59cf5fbb7570e487b809c52 /sm | |
parent | Support CERT records via ADNS (diff) | |
download | gnupg-9a96043be4bed4e18320918e042b1601c9d93e95.tar.gz gnupg-9a96043be4bed4e18320918e042b1601c9d93e95.zip |
Unification of the search descriptor usage.
Diffstat (limited to 'sm')
-rw-r--r-- | sm/ChangeLog | 9 | ||||
-rw-r--r-- | sm/certlist.c | 4 | ||||
-rw-r--r-- | sm/delete.c | 2 | ||||
-rw-r--r-- | sm/export.c | 4 | ||||
-rw-r--r-- | sm/import.c | 2 | ||||
-rw-r--r-- | sm/keydb.c | 284 | ||||
-rw-r--r-- | sm/keydb.h | 4 | ||||
-rw-r--r-- | sm/keylist.c | 2 | ||||
-rw-r--r-- | sm/sign.c | 2 |
9 files changed, 21 insertions, 292 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog index a96b90327..bb2b4b37f 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,12 @@ +2009-12-08 Werner Koch <[email protected]> + + * keydb.c (keydb_search_kid): Fix code even that it is not used. + (classify_user_id): Adjust for change of u.kid type. + (keydb_classify_name): Replace GPG_ERR_INV_NAME by + GPG_ERR_INV_USER_ID. + (keydb_classify_name): Remove. Replace all callers by + classify_user_id. + 2009-12-08 Marcus Brinkmann <[email protected]> * call-dirmngr.c (start_dirmngr_ext): Convert posix fd to assuan fd. diff --git a/sm/certlist.c b/sm/certlist.c index 4137437a6..8221e4ac3 100644 --- a/sm/certlist.c +++ b/sm/certlist.c @@ -301,7 +301,7 @@ gpgsm_add_to_certlist (ctrl_t ctrl, const char *name, int secret, KEYDB_HANDLE kh = NULL; ksba_cert_t cert = NULL; - rc = keydb_classify_name (name, &desc); + rc = classify_user_id (name, &desc); if (!rc) { kh = keydb_new (0); @@ -480,7 +480,7 @@ gpgsm_find_cert (const char *name, ksba_sexp_t keyid, ksba_cert_t *r_cert) KEYDB_HANDLE kh = NULL; *r_cert = NULL; - rc = keydb_classify_name (name, &desc); + rc = classify_user_id (name, &desc); if (!rc) { kh = keydb_new (0); diff --git a/sm/delete.c b/sm/delete.c index fd49ebeab..e2835a98b 100644 --- a/sm/delete.c +++ b/sm/delete.c @@ -45,7 +45,7 @@ delete_one (ctrl_t ctrl, const char *username) int duplicates = 0; int is_ephem = 0; - rc = keydb_classify_name (username, &desc); + rc = classify_user_id (username, &desc); if (rc) { log_error (_("certificate `%s' not found: %s\n"), diff --git a/sm/export.c b/sm/export.c index fcf1dccc1..b194d0dd1 100644 --- a/sm/export.c +++ b/sm/export.c @@ -180,7 +180,7 @@ gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream) { for (ndesc=0, sl=names; sl; sl = sl->next) { - rc = keydb_classify_name (sl->d, desc+ndesc); + rc = classify_user_id (sl->d, desc+ndesc); if (rc) { log_error ("key `%s' not found: %s\n", @@ -359,7 +359,7 @@ gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp) goto leave; } - rc = keydb_classify_name (name, desc); + rc = classify_user_id (name, desc); if (rc) { log_error ("key `%s' not found: %s\n", diff --git a/sm/import.c b/sm/import.c index 5a0eded8f..bcc2d6d44 100644 --- a/sm/import.c +++ b/sm/import.c @@ -452,7 +452,7 @@ reimport_one (ctrl_t ctrl, struct stats_s *stats, int in_fd) stats->count++; - err = keydb_classify_name (line, &desc); + err = classify_user_id (line, &desc); if (err) { print_import_problem (ctrl, NULL, 0); diff --git a/sm/keydb.c b/sm/keydb.c index a1f0e9c18..ddf9a4830 100644 --- a/sm/keydb.c +++ b/sm/keydb.c @@ -949,8 +949,8 @@ keydb_search_kid (KEYDB_HANDLE hd, u32 *kid) memset (&desc, 0, sizeof desc); desc.mode = KEYDB_SEARCH_MODE_LONG_KID; -/* desc.u.kid[0] = kid[0]; */ -/* desc.u.kid[1] = kid[1]; */ + desc.u.kid[0] = kid[0]; + desc.u.kid[1] = kid[1]; return keydb_search (hd, &desc, 1); } @@ -1016,284 +1016,6 @@ keydb_search_subject (KEYDB_HANDLE hd, const char *name) } -static int -classify_user_id (const char *name, - KEYDB_SEARCH_DESC *desc, - int *force_exact ) -{ - const char *s; - int hexprefix = 0; - int hexlength; - int mode = 0; - - /* clear the structure so that the mode field is set to zero unless - * we set it to the correct value right at the end of this function */ - memset (desc, 0, sizeof *desc); - *force_exact = 0; - /* Skip leading spaces. Fixme: what about trailing white space? */ - for(s = name; *s && spacep (s); s++ ) - ; - - switch (*s) - { - case 0: /* empty string is an error */ - return 0; - - case '.': /* an email address, compare from end */ - mode = KEYDB_SEARCH_MODE_MAILEND; - s++; - desc->u.name = s; - break; - - case '<': /* an email address */ - mode = KEYDB_SEARCH_MODE_MAIL; - s++; - desc->u.name = s; - break; - - case '@': /* part of an email address */ - mode = KEYDB_SEARCH_MODE_MAILSUB; - s++; - desc->u.name = s; - break; - - case '=': /* exact compare */ - mode = KEYDB_SEARCH_MODE_EXACT; - s++; - desc->u.name = s; - break; - - case '*': /* case insensitive substring search */ - mode = KEYDB_SEARCH_MODE_SUBSTR; - s++; - desc->u.name = s; - break; - - case '+': /* compare individual words */ - mode = KEYDB_SEARCH_MODE_WORDS; - s++; - desc->u.name = s; - break; - - case '/': /* subject's DN */ - s++; - if (!*s || spacep (s)) - return 0; /* no DN or prefixed with a space */ - desc->u.name = s; - mode = KEYDB_SEARCH_MODE_SUBJECT; - break; - - case '#': - { - const char *si; - - s++; - if ( *s == '/') - { /* "#/" indicates an issuer's DN */ - s++; - if (!*s || spacep (s)) - return 0; /* no DN or prefixed with a space */ - desc->u.name = s; - mode = KEYDB_SEARCH_MODE_ISSUER; - } - else - { /* serialnumber + optional issuer ID */ - for (si=s; *si && *si != '/'; si++) - { - if (!strchr("01234567890abcdefABCDEF", *si)) - return 0; /* invalid digit in serial number*/ - } - desc->sn = (const unsigned char*)s; - desc->snlen = -1; - if (!*si) - mode = KEYDB_SEARCH_MODE_SN; - else - { - s = si+1; - if (!*s || spacep (s)) - return 0; /* no DN or prefixed with a space */ - desc->u.name = s; - mode = KEYDB_SEARCH_MODE_ISSUER_SN; - } - } - } - break; - - case ':': /*Unified fingerprint */ - { - const char *se, *si; - int i; - - se = strchr (++s,':'); - if (!se) - return 0; - for (i=0,si=s; si < se; si++, i++ ) - { - if (!strchr("01234567890abcdefABCDEF", *si)) - return 0; /* invalid digit */ - } - if (i != 32 && i != 40) - return 0; /* invalid length of fpr*/ - for (i=0,si=s; si < se; i++, si +=2) - desc->u.fpr[i] = hextobyte(si); - for (; i < 20; i++) - desc->u.fpr[i]= 0; - s = se + 1; - mode = KEYDB_SEARCH_MODE_FPR; - } - break; - - case '&': /* Keygrip*/ - { - if (hex2bin (s+1, desc->u.grip, 20) < 0) - return 0; /* Invalid. */ - mode = KEYDB_SEARCH_MODE_KEYGRIP; - } - break; - - default: - if (s[0] == '0' && s[1] == 'x') - { - hexprefix = 1; - s += 2; - } - - hexlength = strspn(s, "0123456789abcdefABCDEF"); - if (hexlength >= 8 && s[hexlength] =='!') - { - *force_exact = 1; - hexlength++; /* just for the following check */ - } - - /* check if a hexadecimal number is terminated by EOS or blank */ - if (hexlength && s[hexlength] && !spacep (s+hexlength)) - { - if (hexprefix) /* a "0x" prefix without correct */ - return 0; /* termination is an error */ - /* The first chars looked like a hex number, but really is - not */ - hexlength = 0; - } - - if (*force_exact) - hexlength--; /* remove the bang */ - - if (hexlength == 8 - || (!hexprefix && hexlength == 9 && *s == '0')) - { /* short keyid */ - unsigned long kid; - if (hexlength == 9) - s++; - kid = strtoul( s, NULL, 16 ); - desc->u.kid[4] = kid >> 24; - desc->u.kid[5] = kid >> 16; - desc->u.kid[6] = kid >> 8; - desc->u.kid[7] = kid; - mode = KEYDB_SEARCH_MODE_SHORT_KID; - } - else if (hexlength == 16 - || (!hexprefix && hexlength == 17 && *s == '0')) - { /* complete keyid */ - unsigned long kid0, kid1; - char buf[9]; - if (hexlength == 17) - s++; - mem2str(buf, s, 9 ); - kid0 = strtoul (buf, NULL, 16); - kid1 = strtoul (s+8, NULL, 16); - desc->u.kid[0] = kid0 >> 24; - desc->u.kid[1] = kid0 >> 16; - desc->u.kid[2] = kid0 >> 8; - desc->u.kid[3] = kid0; - desc->u.kid[4] = kid1 >> 24; - desc->u.kid[5] = kid1 >> 16; - desc->u.kid[6] = kid1 >> 8; - desc->u.kid[7] = kid1; - mode = KEYDB_SEARCH_MODE_LONG_KID; - } - else if (hexlength == 32 - || (!hexprefix && hexlength == 33 && *s == '0')) - { /* md5 fingerprint */ - int i; - if (hexlength == 33) - s++; - memset(desc->u.fpr+16, 0, 4); - for (i=0; i < 16; i++, s+=2) - { - int c = hextobyte(s); - if (c == -1) - return 0; - desc->u.fpr[i] = c; - } - mode = KEYDB_SEARCH_MODE_FPR16; - } - else if (hexlength == 40 - || (!hexprefix && hexlength == 41 && *s == '0')) - { /* sha1/rmd160 fingerprint */ - int i; - if (hexlength == 41) - s++; - for (i=0; i < 20; i++, s+=2) - { - int c = hextobyte(s); - if (c == -1) - return 0; - desc->u.fpr[i] = c; - } - mode = KEYDB_SEARCH_MODE_FPR20; - } - else if (!hexprefix) - { - /* The fingerprint in an X.509 listing is often delimited by - colons, so we try to single this case out. */ - mode = 0; - hexlength = strspn (s, ":0123456789abcdefABCDEF"); - if (hexlength == 59 && (!s[hexlength] || spacep (s+hexlength))) - { - int i; - - for (i=0; i < 20; i++, s += 3) - { - int c = hextobyte(s); - if (c == -1 || (i < 19 && s[2] != ':')) - break; - desc->u.fpr[i] = c; - } - if (i == 20) - mode = KEYDB_SEARCH_MODE_FPR20; - } - if (!mode) /* default is substring search */ - { - *force_exact = 0; - desc->u.name = s; - mode = KEYDB_SEARCH_MODE_SUBSTR; - } - } - else - { /* hex number with a prefix but a wrong length */ - return 0; - } - } - - desc->mode = mode; - return mode; -} - - -int -keydb_classify_name (const char *name, KEYDB_SEARCH_DESC *desc) -{ - int dummy; - KEYDB_SEARCH_DESC dummy_desc; - - if (!desc) - desc = &dummy_desc; - - if (!classify_user_id (name, desc, &dummy)) - return gpg_error (GPG_ERR_INV_NAME); - return 0; -} - /* Store the certificate in the key DB but make sure that it does not already exists. We do this simply by comparing the fingerprint. @@ -1483,7 +1205,7 @@ keydb_clear_some_cert_flags (ctrl_t ctrl, strlist_t names) { for (ndesc=0, sl=names; sl; sl = sl->next) { - rc = keydb_classify_name (sl->d, desc+ndesc); + rc = classify_user_id (sl->d, desc+ndesc); if (rc) { log_error ("key `%s' not found: %s\n", diff --git a/sm/keydb.h b/sm/keydb.h index a440c5047..a62ce99cb 100644 --- a/sm/keydb.h +++ b/sm/keydb.h @@ -22,7 +22,7 @@ #include <ksba.h> -#include "../kbx/keybox-search-desc.h" +#include "../common/userids.h" typedef struct keydb_handle *KEYDB_HANDLE; @@ -69,8 +69,6 @@ int keydb_search_issuer_sn (KEYDB_HANDLE hd, const char *issuer, const unsigned char *serial); int keydb_search_subject (KEYDB_HANDLE hd, const char *issuer); -int keydb_classify_name (const char *name, KEYDB_SEARCH_DESC *desc); - int keydb_store_cert (ksba_cert_t cert, int ephemeral, int *existed); gpg_error_t keydb_set_cert_flags (ksba_cert_t cert, int ephemeral, int which, int idx, diff --git a/sm/keylist.c b/sm/keylist.c index 9b8538c84..e323b2740 100644 --- a/sm/keylist.c +++ b/sm/keylist.c @@ -1334,7 +1334,7 @@ list_internal_keys (ctrl_t ctrl, strlist_t names, estream_t fp, { for (ndesc=0, sl=names; sl; sl = sl->next) { - rc = keydb_classify_name (sl->d, desc+ndesc); + rc = classify_user_id (sl->d, desc+ndesc); if (rc) { log_error ("key `%s' not found: %s\n", @@ -209,7 +209,7 @@ get_default_signer (ctrl_t ctrl) return cert; } - rc = keydb_classify_name (opt.local_user, &desc); + rc = classify_user_id (opt.local_user, &desc); if (rc) { log_error ("failed to find default signer: %s\n", gpg_strerror (rc)); |