]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - keydb_db4.c
"Recognize" some extra subpacket types
[onak.git] / keydb_db4.c
index b443942aea33530a8db6c97001896dcccd226075..85aeab559e9c60a7f6300401d176bfd6c19f5ee7 100644 (file)
@@ -332,6 +332,55 @@ static void db4_initdb(bool readonly)
        return;
 }
 
        return;
 }
 
+/**
+ *     getfullkeyid - Maps a 32bit key id to a 64bit one.
+ *     @keyid: The 32bit keyid.
+ *
+ *     This function maps a 32bit key id to the full 64bit one. It returns the
+ *     full keyid. If the key isn't found a keyid of 0 is returned.
+ */
+static uint64_t db4_getfullkeyid(uint64_t keyid)
+{
+       DBT       key, data;
+       DBC      *cursor = NULL;
+       uint32_t  shortkeyid = 0;
+       int       ret = 0;
+
+       if (keyid < 0x100000000LL) {
+               ret = id32db->cursor(id32db,
+                               txn,
+                               &cursor,
+                               0);   /* flags */
+
+               shortkeyid = keyid & 0xFFFFFFFF;
+
+               memset(&key, 0, sizeof(key));
+               memset(&data, 0, sizeof(data));
+               key.data = &shortkeyid;
+               key.size = sizeof(shortkeyid);
+               data.flags = DB_DBT_MALLOC;
+
+               ret = cursor->c_get(cursor,
+                       &key,
+                       &data,
+                       DB_SET);
+
+               if (ret == 0) {
+                       keyid = *(uint64_t *) data.data;
+
+                       if (data.data != NULL) {
+                               free(data.data);
+                               data.data = NULL;
+                       }
+               }
+
+               ret = cursor->c_close(cursor);
+               cursor = NULL;
+       }
+       
+       return keyid;
+}
+
 /**
  *     fetch_key - Given a keyid fetch the key from storage.
  *     @keyid: The keyid to fetch.
 /**
  *     fetch_key - Given a keyid fetch the key from storage.
  *     @keyid: The keyid to fetch.
@@ -354,7 +403,7 @@ static int db4_fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
        struct buffer_ctx fetchbuf;
 
        if (keyid < 0x100000000LL) {
        struct buffer_ctx fetchbuf;
 
        if (keyid < 0x100000000LL) {
-               keyid = getfullkeyid(keyid);
+               keyid = db4_getfullkeyid(keyid);
        }
 
        memset(&key, 0, sizeof(key));
        }
 
        memset(&key, 0, sizeof(key));
@@ -426,6 +475,7 @@ static int db4_fetch_key_text(const char *search,
        struct ll *curword = NULL;
        struct keyarray keylist = { NULL, 0, 0 };
        struct keyarray newkeylist = { NULL, 0, 0 };
        struct ll *curword = NULL;
        struct keyarray keylist = { NULL, 0, 0 };
        struct keyarray newkeylist = { NULL, 0, 0 };
+       int firstpass = 1;
 
        numkeys = 0;
        searchtext = strdup(search);
 
        numkeys = 0;
        searchtext = strdup(search);
@@ -458,8 +508,12 @@ static int db4_fetch_key_text(const char *search,
                                                data.data)[i];
                        }
 
                                                data.data)[i];
                        }
 
-                       if (keylist.count == 0 ||
-                                       array_find(&keylist, keyid)) {
+                       /*
+                        * Only add the keys containing this word if this is
+                        * our first pass (ie we have no existing key list),
+                        * or the key contained a previous word.
+                        */
+                       if (firstpass || array_find(&keylist, keyid)) {
                                array_add(&newkeylist, keyid);
                        }
 
                                array_add(&newkeylist, keyid);
                        }
 
@@ -481,6 +535,7 @@ static int db4_fetch_key_text(const char *search,
                }
                ret = cursor->c_close(cursor);
                cursor = NULL;
                }
                ret = cursor->c_close(cursor);
                cursor = NULL;
+               firstpass = 0;
                db4_endtrans();
        }
        llfree(wordlist, NULL);
                db4_endtrans();
        }
        llfree(wordlist, NULL);
@@ -1011,55 +1066,6 @@ static int db4_iterate_keys(void (*iterfunc)(void *ctx,
        return numkeys;
 }
 
        return numkeys;
 }
 
-/**
- *     getfullkeyid - Maps a 32bit key id to a 64bit one.
- *     @keyid: The 32bit keyid.
- *
- *     This function maps a 32bit key id to the full 64bit one. It returns the
- *     full keyid. If the key isn't found a keyid of 0 is returned.
- */
-static uint64_t db4_getfullkeyid(uint64_t keyid)
-{
-       DBT       key, data;
-       DBC      *cursor = NULL;
-       uint32_t  shortkeyid = 0;
-       int       ret = 0;
-
-       if (keyid < 0x100000000LL) {
-               ret = id32db->cursor(id32db,
-                               txn,
-                               &cursor,
-                               0);   /* flags */
-
-               shortkeyid = keyid & 0xFFFFFFFF;
-
-               memset(&key, 0, sizeof(key));
-               memset(&data, 0, sizeof(data));
-               key.data = &shortkeyid;
-               key.size = sizeof(shortkeyid);
-               data.flags = DB_DBT_MALLOC;
-
-               ret = cursor->c_get(cursor,
-                       &key,
-                       &data,
-                       DB_SET);
-
-               if (ret == 0) {
-                       keyid = *(uint64_t *) data.data;
-
-                       if (data.data != NULL) {
-                               free(data.data);
-                               data.data = NULL;
-                       }
-               }
-
-               ret = cursor->c_close(cursor);
-               cursor = NULL;
-       }
-       
-       return keyid;
-}
-
 /*
  * Include the basic keydb routines.
  */
 /*
  * Include the basic keydb routines.
  */