]> git.sommitrealweird.co.uk Git - onak.git/commitdiff
Inital subkey searching support for db3 backend.
authorJonathan McDowell <noodles@earth.li>
Fri, 11 Jun 2004 18:18:22 +0000 (18:18 +0000)
committerJonathan McDowell <noodles@earth.li>
Fri, 11 Jun 2004 18:18:22 +0000 (18:18 +0000)
Adds support for searching on keys via a subkey. Only supported by the db3
backend so far.

decodekey.c
decodekey.h
keydb_db3.c

index 8fca1762464a474bfebc994edafec13bedf2d6ec..5818488b766a92a9ad98dc595277097ecc0695f0 100644 (file)
@@ -249,3 +249,30 @@ char **keyuids(struct openpgp_publickey *key, char **primary)
 
        return uids;
 }
+
+/**
+ *     keysubkeys - Takes a key and returns an array of its subkey keyids.
+ *     @key: The key to get the subkeys of.
+ *
+ *     keysubkeys takes a public key structure and returns an array of the
+ *     subkey keyids for that key.
+ */
+uint64_t *keysubkeys(struct openpgp_publickey *key)
+{
+       struct openpgp_signedpacket_list *cursubkey = NULL;
+       uint64_t                         *subkeys = NULL;
+       int                               count = 0;
+        
+       if (key != NULL && key->subkeys != NULL) {
+               subkeys = malloc((spsize(key->subkeys) + 1) *
+                               sizeof (uint64_t));
+               cursubkey = key->subkeys;
+               while (cursubkey != NULL) {
+                       subkeys[count++] = get_packetid(cursubkey->packet);
+                       cursubkey = cursubkey -> next;
+               }
+               subkeys[count] = NULL;
+       }
+
+       return subkeys;
+}
index 91929d32b4dd91e19eeea57383db591c2f0d8579..ba3027b07fbc58dccb6f773a2332189b0f3954c4 100644 (file)
@@ -44,4 +44,13 @@ uint64_t sig_keyid(struct openpgp_packet *packet);
  */
 char **keyuids(struct openpgp_publickey *key, char **primary);
 
+/**
+ *     keysubkeys - Takes a key and returns an array of its subkey keyids.
+ *     @key: The key to get the subkeys of.
+ *
+ *     keysubkeys takes a public key structure and returns an array of the
+ *     subkey keyids for that key.
+ */
+uint64_t *keysubkeys(struct openpgp_publickey *key);
+
 #endif
index 27b090e0ee6c133dc2239d396c29c5955506c78e..191ebc6ff2bb5cabc84281b85a69099f06b4fab7 100644 (file)
@@ -490,6 +490,7 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update)
        DBT        data;
        uint64_t   keyid = 0;
        uint32_t   shortkeyid = 0;
+       uint64_t  *subkeyids = NULL;
        char     **uids = NULL;
        char      *primary = NULL;
        unsigned char worddb_data[12];
@@ -660,6 +661,39 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update)
                }
        }
 
+       if (!deadlock) {
+               subkeyids = keysubkeys(publickey);
+               i = 0;
+               while (subkeyids != NULL && subkeyids[i] != 0) {
+                       shortkeyid = subkeyids[i++] & 0xFFFFFFFF;
+
+                       memset(&key, 0, sizeof(key));
+                       memset(&data, 0, sizeof(data));
+                       key.data = &shortkeyid;
+                       key.size = sizeof(shortkeyid);
+                       data.data = &keyid;
+                       data.size = sizeof(keyid);
+
+                       ret = id32db->put(id32db,
+                               txn,
+                               &key,
+                               &data,
+                               0);
+                       if (ret != 0) {
+                               logthing(LOGTHING_ERROR,
+                                       "Problem storing short keyid: %s",
+                                       db_strerror(ret));
+                               if (ret == DB_LOCK_DEADLOCK) {
+                                       deadlock = true;
+                               }
+                       }
+               }
+               if (subkeyids != NULL) {
+                       free(subkeyids);
+                       subkeyids = NULL;
+               }
+       }
+
        return deadlock ? -1 : 0 ;
 }
 
@@ -677,6 +711,7 @@ int delete_key(uint64_t keyid, bool intrans)
        DBT key, data;
        DBC *cursor = NULL;
        uint32_t   shortkeyid = 0;
+       uint64_t  *subkeyids = NULL;
        int ret = 0;
        int i;
        char **uids = NULL;
@@ -811,6 +846,48 @@ int delete_key(uint64_t keyid, bool intrans)
                                deadlock = true;
                        }
                }
+
+               subkeyids = keysubkeys(publickey);
+               i = 0;
+               while (subkeyids != NULL && subkeyids[i] != 0) {
+                       shortkeyid = subkeyids[i++] & 0xFFFFFFFF;
+
+                       memset(&key, 0, sizeof(key));
+                       memset(&data, 0, sizeof(data));
+                       key.data = &shortkeyid;
+                       key.size = sizeof(shortkeyid);
+                       data.data = &keyid;
+                       data.size = sizeof(keyid);
+
+                       ret = cursor->c_get(cursor,
+                               &key,
+                               &data,
+                               DB_GET_BOTH);
+
+                       if (ret == 0) {
+                               ret = cursor->c_del(cursor, 0);
+                               if (ret != 0) {
+                                       logthing(LOGTHING_ERROR,
+                                               "Problem deleting short"
+                                               " keyid: %s",
+                                               db_strerror(ret));
+                               }
+                       }
+
+                       if (ret != 0) {
+                               logthing(LOGTHING_ERROR,
+                                       "Problem deleting short keyid: %s",
+                                       db_strerror(ret));
+                               if (ret == DB_LOCK_DEADLOCK) {
+                                       deadlock = true;
+                               }
+                       }
+               }
+               if (subkeyids != NULL) {
+                       free(subkeyids);
+                       subkeyids = NULL;
+               }
+
                ret = cursor->c_close(cursor);
                cursor = NULL;
        }