]> the.earth.li Git - onak.git/blob - keydb_fs.c
Add cleankey.o to CORE_OBJS
[onak.git] / keydb_fs.c
1 /*
2  * keydb_fs.c - Routines to store and fetch keys in a filesystem hierarchy.
3  *
4  * Copyright 2004 Daniel Silverstone <dsilvers@digital-scurf.org>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <sys/types.h>
21 #include <sys/uio.h>
22 #include <sys/stat.h>
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <limits.h>
30 #include <dirent.h>
31
32 #include "charfuncs.h"
33 #include "decodekey.h"
34 #include "keydb.h"
35 #include "keyid.h"
36 #include "keystructs.h"
37 #include "ll.h"
38 #include "mem.h"
39 #include "onak-conf.h"
40 #include "parsekey.h"
41 #include "log.h"
42 #include "wordlist.h"
43
44 /* Hack: We should really dynamically allocate our path buffers */
45 #ifndef PATH_MAX
46 #define PATH_MAX 1024
47 #endif
48
49 struct onak_fs_dbctx {
50         int lockfile_fd;
51         bool lockfile_readonly;
52 };
53
54 /*****************************************************************************/
55
56 /* Helper functions */
57
58 #define FNV_offset_basis 2166136261ul
59 #define FNV_mixing_prime 16777619ul
60
61 static uint32_t calchash(uint8_t * ptr)
62 {
63         register uint32_t h = FNV_offset_basis;
64         register uint32_t p = FNV_mixing_prime;
65         register uint32_t n = strlen((char *) ptr);
66         register uint8_t *c = ptr;
67         while (n--) {
68                 h *= p;
69                 h ^= *c++;
70         }
71         return h ? h : 1;       /* prevent a hash of zero happening */
72 }
73
74
75 static void keypath(char *buffer, size_t length, uint64_t _keyid,
76                 char *basepath)
77 {
78         uint64_t keyid = _keyid << 32;
79         snprintf(buffer, length, "%s/key/%02X/%02X/%08X/%016" PRIX64,
80                  basepath, (uint8_t) ((keyid >> 56) & 0xFF),
81                  (uint8_t) ((keyid >> 48) & 0xFF),
82                  (uint32_t) (keyid >> 32), _keyid);
83 }
84
85 static void keydir(char *buffer, size_t length, uint64_t _keyid,
86                 char *basepath)
87 {
88         uint64_t keyid = _keyid << 32;
89         snprintf(buffer, length, "%s/key/%02X/%02X/%08X", basepath,
90                  (uint8_t) ((keyid >> 56) & 0xFF),
91                  (uint8_t) ((keyid >> 48) & 0xFF),
92                  (uint32_t) (keyid >> 32));
93 }
94
95 static void prove_path_to(uint64_t keyid, char *what, char *basepath)
96 {
97         static char buffer[PATH_MAX];
98         snprintf(buffer, sizeof(buffer), "%s/%s", basepath, what);
99         mkdir(buffer, 0777);
100
101         snprintf(buffer, sizeof(buffer), "%s/%s/%02X", basepath, what,
102                  (uint8_t) ((keyid >> 24) & 0xFF));
103         mkdir(buffer, 0777);
104
105         snprintf(buffer, sizeof(buffer), "%s/%s/%02X/%02X", basepath,
106                  what,
107                  (uint8_t) ((keyid >> 24) & 0xFF),
108                  (uint8_t) ((keyid >> 16) & 0xFF));
109         mkdir(buffer, 0777);
110
111         snprintf(buffer, sizeof(buffer), "%s/%s/%02X/%02X/%08X", basepath,
112                  what,
113                  (uint8_t) ((keyid >> 24) & 0xFF),
114                  (uint8_t) ((keyid >> 16) & 0xFF), (uint32_t) (keyid));
115         mkdir(buffer, 0777);
116 }
117
118 static void wordpath(char *buffer, size_t length, char *word, uint32_t hash,
119                 uint64_t keyid, char *basepath)
120 {
121         snprintf(buffer, length, "%s/words/%02X/%02X/%08X/%s/%016" PRIX64,
122                  basepath, (uint8_t) ((hash >> 24) & 0xFF),
123                  (uint8_t) ((hash >> 16) & 0xFF), hash, word, keyid);
124 }
125
126 static void worddir(char *buffer, size_t length, char *word, uint32_t hash,
127                 char *basepath)
128 {
129         snprintf(buffer, length, "%s/words/%02X/%02X/%08X/%s", basepath,
130                  (uint8_t) ((hash >> 24) & 0xFF),
131                  (uint8_t) ((hash >> 16) & 0xFF), hash, word);
132 }
133
134 static void subkeypath(char *buffer, size_t length, uint64_t subkey,
135                 char *basepath)
136 {
137         snprintf(buffer, length, "%s/subkeys/%02X/%02X/%08X/%016" PRIX64,
138                  basepath,
139                  (uint8_t) ((subkey >> 24) & 0xFF),
140                  (uint8_t) ((subkey >> 16) & 0xFF),
141                  (uint32_t) (subkey & 0xFFFFFFFF),
142                  subkey);
143 }
144
145 static void subkeydir(char *buffer, size_t length, uint64_t subkey,
146                 char *basepath)
147 {
148         snprintf(buffer, length, "%s/subkeys/%02X/%02X/%08X",
149                  basepath,
150                  (uint8_t) ((subkey >> 24) & 0xFF),
151                  (uint8_t) ((subkey >> 16) & 0xFF),
152                  (uint32_t) (subkey & 0xFFFFFFFF));
153 }
154
155 static void skshashpath(char *buffer, size_t length,
156                 const struct skshash *hash, char *basepath)
157 {
158         snprintf(buffer, length, "%s/skshash/%02X/%02X/%02X%02X%02X%02X/"
159                 "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
160                  basepath,
161                  hash->hash[0], hash->hash[1],
162                  hash->hash[0], hash->hash[1], hash->hash[2], hash->hash[3],
163                  hash->hash[4], hash->hash[5], hash->hash[6], hash->hash[7],
164                  hash->hash[8], hash->hash[9], hash->hash[10], hash->hash[11],
165                  hash->hash[12], hash->hash[13], hash->hash[14],
166                  hash->hash[15]);
167 }
168
169 /*****************************************************************************/
170
171 /**
172  *      starttrans - Start a transaction.
173  */
174 static bool fs_starttrans(struct onak_dbctx *dbctx)
175 {
176         struct onak_fs_dbctx *privctx = (struct onak_fs_dbctx *) dbctx->priv;
177         struct flock lockstruct;
178         int remaining = 20;
179         lockstruct.l_type =
180             F_RDLCK | ((privctx->lockfile_readonly) ? 0 : F_WRLCK);
181         lockstruct.l_whence = SEEK_SET;
182         lockstruct.l_start = 0;
183         lockstruct.l_len = 1;
184
185         while (fcntl(privctx->lockfile_fd, F_SETLK, &lockstruct) == -1) {
186                 if (remaining-- == 0)
187                         return false;   /* Hope to hell that noodles DTRT */
188                 usleep(100);
189         }
190         return true;
191 }
192
193 /**
194  *      endtrans - End a transaction.
195  */
196 static void fs_endtrans(struct onak_dbctx *dbctx)
197 {
198         struct onak_fs_dbctx *privctx = (struct onak_fs_dbctx *) dbctx->priv;
199         struct flock lockstruct;
200
201         lockstruct.l_type = F_UNLCK;
202         lockstruct.l_whence = SEEK_SET;
203         lockstruct.l_start = 0;
204         lockstruct.l_len = 1;
205         fcntl(privctx->lockfile_fd, F_SETLK, &lockstruct);
206 }
207
208 static uint64_t fs_getfullkeyid(struct onak_dbctx *dbctx, uint64_t keyid)
209 {
210         static char buffer[PATH_MAX];
211         DIR *d = NULL;
212         struct dirent *de = NULL;
213         uint64_t ret = 0;
214
215         keydir(buffer, sizeof(buffer), keyid, dbctx->config->location);
216
217         d = opendir(buffer);
218         if (d) {
219                 do {
220                         de = readdir(d);
221                         if (de && de->d_name[0] != '.') {
222                                 ret = strtoull(de->d_name, NULL, 16);
223                         }
224                 } while (de && de->d_name[0] == '.');
225                 closedir(d);    
226         }
227
228         if (ret == 0) {
229                 subkeydir(buffer, sizeof(buffer), keyid,
230                         dbctx->config->location);
231
232                 d = opendir(buffer);
233                 if (d) {
234                         do {
235                                 de = readdir(d);
236                                 if (de && de->d_name[0] != '.') {
237                                         ret = strtoull(de->d_name, NULL, 16);
238                                 }
239                         } while (de && de->d_name[0] == '.');
240                         closedir(d);
241                 }
242         }
243
244         return ret;
245 }
246
247 /**
248  *      fetch_key - Given a keyid fetch the key from storage.
249  *      @keyid: The keyid to fetch.
250  *      @publickey: A pointer to a structure to return the key in.
251  *      @intrans: If we're already in a transaction.
252  */
253 static int fs_fetch_key_id(struct onak_dbctx *dbctx,
254               uint64_t keyid,
255               struct openpgp_publickey **publickey,
256               bool intrans)
257 {
258         static char buffer[PATH_MAX];
259         int ret = 0, fd;
260         struct openpgp_packet_list *packets = NULL;
261
262         if (!intrans)
263                 fs_starttrans(dbctx);
264
265         if ((keyid >> 32) == 0)
266                 keyid = fs_getfullkeyid(dbctx, keyid);
267
268         keypath(buffer, sizeof(buffer), keyid, dbctx->config->location);
269         fd = open(buffer, O_RDONLY);
270         if (fd == -1 && errno == ENOENT) {
271                 subkeypath(buffer, sizeof(buffer), keyid,
272                         dbctx->config->location);
273                 fd = open(buffer, O_RDONLY);
274         }
275
276         if (fd != -1) {
277                 /* File is present, load it in... */
278                 read_openpgp_stream(file_fetchchar, &fd, &packets, 0);
279                 parse_keys(packets, publickey);
280                 free_packet_list(packets);
281                 packets = NULL;
282                 close(fd);
283                 ret = 1;
284         }
285
286         if (!intrans)
287                 fs_endtrans(dbctx);
288         return ret;
289 }
290
291 /**
292  *      store_key - Takes a key and stores it.
293  *      @publickey: A pointer to the public key to store.
294  *      @intrans: If we're already in a transaction.
295  *      @update: If true the key exists and should be updated.
296  */
297 static int fs_store_key(struct onak_dbctx *dbctx,
298               struct openpgp_publickey *publickey, bool intrans,
299               bool update)
300 {
301         static char buffer[PATH_MAX];
302         static char wbuffer[PATH_MAX];
303         int ret = 0, fd;
304         struct openpgp_packet_list *packets = NULL;
305         struct openpgp_packet_list *list_end = NULL;
306         struct openpgp_publickey *next = NULL;
307         uint64_t keyid;
308         struct ll *wordlist = NULL, *wl = NULL;
309         struct skshash hash;
310         struct openpgp_fingerprint *subkeyids = NULL;
311         uint32_t hashid;
312         int i = 0;
313
314         if (get_keyid(publickey, &keyid) != ONAK_E_OK) {
315                 logthing(LOGTHING_ERROR, "Couldn't find key ID for key.");
316                 return 0;
317         }
318
319         if (!intrans)
320                 fs_starttrans(dbctx);
321
322         prove_path_to(keyid, "key", dbctx->config->location);
323         keypath(buffer, sizeof(buffer), keyid, dbctx->config->location);
324
325         if ((fd =
326              open(buffer, O_WRONLY | (update ? O_TRUNC : O_CREAT),
327                   0644)) != -1) {
328                 next = publickey->next;
329                 publickey->next = NULL;
330                 flatten_publickey(publickey, &packets, &list_end);
331                 publickey->next = next;
332
333                 write_openpgp_stream(file_putchar, &fd, packets);
334                 close(fd);
335                 free_packet_list(packets);
336                 packets = NULL;
337                 ret = 1;
338         }
339
340         if (ret) {
341                 wl = wordlist = makewordlistfromkey(wordlist, publickey);
342                 while (wl) {
343                         uint32_t hash = calchash((uint8_t *) (wl->object));
344                         prove_path_to(hash, "words", dbctx->config->location);
345
346                         worddir(wbuffer, sizeof(wbuffer), wl->object, hash,
347                                 dbctx->config->location);
348                         mkdir(wbuffer, 0777);
349                         wordpath(wbuffer, sizeof(wbuffer), wl->object, hash,
350                                 keyid, dbctx->config->location);
351                         link(buffer, wbuffer);
352
353                         wl = wl->next;
354                 }
355                 llfree(wordlist, free);
356                 
357                 subkeyids = keysubkeys(publickey);
358                 i = 0;
359                 while (subkeyids != NULL && subkeyids[i].length != 0) {
360                         keyid = fingerprint2keyid(&subkeyids[i]);
361
362                         prove_path_to(keyid, "subkeys",
363                                 dbctx->config->location);
364
365                         subkeydir(wbuffer, sizeof(wbuffer), keyid,
366                                 dbctx->config->location);
367                         mkdir(wbuffer, 0777);
368                         subkeypath(wbuffer, sizeof(wbuffer), keyid,
369                                 dbctx->config->location);
370                         link(buffer, wbuffer);
371
372                         i++;
373                 }
374                 if (subkeyids != NULL) {
375                         free(subkeyids);
376                         subkeyids = NULL;
377                 }
378
379                 get_skshash(publickey, &hash);
380                 hashid = (hash.hash[0] << 24) + (hash.hash[1] << 16) +
381                                 (hash.hash[2] << 8) + hash.hash[3];
382                 prove_path_to(hashid, "skshash", dbctx->config->location);
383                 skshashpath(wbuffer, sizeof(wbuffer), &hash,
384                         dbctx->config->location);
385                 link(buffer, wbuffer);
386         }
387
388         if (!intrans)
389                 fs_endtrans(dbctx);
390         return ret;
391 }
392
393 /**
394  *      delete_key - Given a keyid delete the key from storage.
395  *      @keyid: The keyid to delete.
396  *      @intrans: If we're already in a transaction.
397  */
398 static int fs_delete_key(struct onak_dbctx *dbctx, uint64_t keyid, bool intrans)
399 {
400         static char buffer[PATH_MAX];
401         int ret;
402         struct openpgp_publickey *pk = NULL;
403         struct skshash hash;
404         struct ll *wordlist = NULL, *wl = NULL;
405         struct openpgp_fingerprint *subkeyids = NULL;
406         uint64_t subkeyid;
407         int i = 0;
408
409         if ((keyid >> 32) == 0)
410                 keyid = fs_getfullkeyid(dbctx, keyid);
411
412         if (!intrans)
413                 fs_starttrans(dbctx);
414
415         ret = fs_fetch_key_id(dbctx, keyid, &pk, true);
416
417         if (ret) {
418                 logthing(LOGTHING_DEBUG, "Wordlist for key %016" PRIX64,
419                          keyid);
420                 wl = wordlist = makewordlistfromkey(wordlist, pk);
421                 logthing(LOGTHING_DEBUG,
422                          "Wordlist for key %016" PRIX64 " done", keyid);
423                 while (wl) {
424                         uint32_t hash = calchash((uint8_t *) (wl->object));
425                         prove_path_to(hash, "words", dbctx->config->location);
426
427                         wordpath(buffer, sizeof(buffer), wl->object, hash,
428                                 keyid, dbctx->config->location);
429                         unlink(buffer);
430
431                         wl = wl->next;
432                 }
433
434                 subkeyids = keysubkeys(pk);
435                 i = 0;
436                 while (subkeyids != NULL && subkeyids[i].length != 0) {
437                         subkeyid = fingerprint2keyid(&subkeyids[i]);
438                         prove_path_to(subkeyid, "subkeys",
439                                 dbctx->config->location);
440
441                         subkeypath(buffer, sizeof(buffer), subkeyid,
442                                 dbctx->config->location);
443                         unlink(buffer);
444
445                         i++;
446                 }
447                 if (subkeyids != NULL) {
448                         free(subkeyids);
449                         subkeyids = NULL;
450                 }
451
452                 get_skshash(pk, &hash);
453                 skshashpath(buffer, sizeof(buffer), &hash,
454                         dbctx->config->location);
455                 unlink(buffer);
456         }
457
458         keypath(buffer, sizeof(buffer), keyid, dbctx->config->location);
459         unlink(buffer);
460
461         if (!intrans)
462                 fs_endtrans(dbctx);
463         return 1;
464 }
465
466 static struct ll *internal_get_key_by_word(char *word, struct ll *mct,
467                 char *basepath)
468 {
469         struct ll *keys = NULL;
470         DIR *d = NULL;
471         char buffer[PATH_MAX];
472         uint32_t hash = calchash((uint8_t *) (word));
473         struct dirent *de;
474
475         worddir(buffer, sizeof(buffer), word, hash, basepath);
476         d = opendir(buffer);
477         logthing(LOGTHING_DEBUG, "Scanning for word %s in dir %s", word,
478                  buffer);
479         if (d) {
480                 do {
481                         de = readdir(d);
482                         if (de && de->d_name[0] != '.') {
483                                 if ((!mct)
484                                     || (llfind(mct, de->d_name,
485                                         (int (*)(const void *, const void *))
486                                                     strcmp) !=
487                                         NULL)) {
488                                         logthing(LOGTHING_DEBUG,
489                                                  "Found %s // %s", word,
490                                                  de->d_name);
491                                         keys =
492                                             lladd(keys,
493                                                   strdup(de->d_name));
494                                 }
495                         }
496                 } while (de);
497                 closedir(d);
498         }
499
500         return keys;
501 }
502
503 /*
504  *      fetch_key_text - Trys to find the keys that contain the supplied text.
505  *      @search: The text to search for.
506  *      @publickey: A pointer to a structure to return the key in.
507  */
508 static int fs_fetch_key_text(struct onak_dbctx *dbctx,
509                    const char *search,
510                    struct openpgp_publickey **publickey)
511 {
512         struct ll *wordlist = NULL, *wl = NULL;
513         struct ll *keylist = NULL;
514         char      *searchtext = NULL;
515         int addedkeys = 0;
516
517         logthing(LOGTHING_DEBUG, "Search was '%s'", search);
518
519         searchtext = strdup(search);
520         wl = wordlist = makewordlist(wordlist, searchtext);
521
522         keylist = internal_get_key_by_word(wordlist->object, NULL,
523                 dbctx->config->location);
524
525         if (!keylist) {
526                 llfree(wordlist, NULL);
527                 free(searchtext);
528                 searchtext = NULL;
529                 return 0;
530         }
531
532         wl = wl->next;
533         while (wl) {
534                 struct ll *nkl =
535                     internal_get_key_by_word(wl->object, keylist,
536                         dbctx->config->location);
537                 if (!nkl) {
538                         llfree(wordlist, NULL);
539                         llfree(keylist, free);
540                         free(searchtext);
541                         searchtext = NULL;
542                         return 0;
543                 }
544                 llfree(keylist, free);
545                 keylist = nkl;
546                 wl = wl->next;
547         }
548
549         llfree(wordlist, NULL);
550
551         /* Now add the keys... */
552         wl = keylist;
553         while (wl) {
554                 logthing(LOGTHING_DEBUG, "Adding key: %s", wl->object);
555                 addedkeys +=
556                     fs_fetch_key_id(dbctx,
557                               strtoull(wl->object, NULL, 16), publickey,
558                               false);
559                 if (addedkeys >= config.maxkeys)
560                         break;
561                 wl = wl->next;
562         }
563
564         llfree(keylist, free);
565         free(searchtext);
566         searchtext = NULL;
567
568         return addedkeys;
569 }
570
571 /**
572  *      fetch_key_skshash - Given an SKS hash fetch the key from storage.
573  *      @hash: The hash to fetch.
574  *      @publickey: A pointer to a structure to return the key in.
575  *      @intrans: If we're already in a transaction.
576  */
577 static int fs_fetch_key_skshash(struct onak_dbctx *dbctx,
578               const struct skshash *hash,
579               struct openpgp_publickey **publickey)
580 {
581         static char buffer[PATH_MAX];
582         int ret = 0, fd;
583         struct openpgp_packet_list *packets = NULL;
584
585         skshashpath(buffer, sizeof(buffer), hash, dbctx->config->location);
586         if ((fd = open(buffer, O_RDONLY)) != -1) {
587                 read_openpgp_stream(file_fetchchar, &fd, &packets, 0);
588                 parse_keys(packets, publickey);
589                 free_packet_list(packets);
590                 packets = NULL;
591                 close(fd);
592                 ret = 1;
593         }
594
595         return ret;
596 }
597
598 /**
599  *      iterate_keys - call a function once for each key in the db.
600  *      @iterfunc: The function to call.
601  *      @ctx: A context pointer
602  *
603  *      Calls iterfunc once for each key in the database. ctx is passed
604  *      unaltered to iterfunc. This function is intended to aid database dumps
605  *      and statistic calculations.
606  *
607  *      Returns the number of keys we iterated over.
608  */
609 static int fs_iterate_keys(struct onak_dbctx *dbctx,
610                 void (*iterfunc)(void *ctx,
611                 struct openpgp_publickey *key), void *ctx)
612 {
613         return 0;
614 }
615
616 /*
617  * Include the basic keydb routines.
618  */
619 #define NEED_KEYID2UID 1
620 #define NEED_GETKEYSIGS 1
621 #define NEED_UPDATEKEYS 1
622 #define NEED_GET_FP 1
623 #include "keydb.c"
624
625 /**
626  *      cleanupdb - De-initialize the key database.
627  */
628 static void fs_cleanupdb(struct onak_dbctx *dbctx)
629 {
630         struct onak_fs_dbctx *privctx = (struct onak_fs_dbctx *) dbctx->priv;
631
632         /* Mmmm nothing to do here? */
633         close(privctx->lockfile_fd);
634 }
635
636 /**
637  *      initdb - Initialize the key database.
638  */
639 struct onak_dbctx *keydb_fs_init(struct onak_db_config *dbcfg, bool readonly)
640 {
641         char buffer[PATH_MAX];
642         struct onak_dbctx *dbctx;
643         struct onak_fs_dbctx *privctx;
644
645         dbctx = malloc(sizeof(struct onak_dbctx));
646         if (dbctx == NULL) {
647                 return NULL;
648         }
649         dbctx->config = dbcfg;
650         dbctx->priv = privctx = malloc(sizeof(*privctx));
651         if (privctx == NULL) {
652                 free(dbctx);
653                 return NULL;
654         }
655
656         privctx->lockfile_readonly = readonly;
657
658         snprintf(buffer, sizeof(buffer), "%s/.lock", dbcfg->location);
659
660         if (access(dbcfg->location, R_OK | W_OK | X_OK) == -1) {
661                 if (errno != ENOENT) {
662                         logthing(LOGTHING_CRITICAL,
663                                  "Unable to access keydb_fs root of '%s'. (%s)",
664                                  dbcfg->location, strerror(errno));
665                         exit(1);        /* Lacking rwx on the key dir */
666                 }
667                 mkdir(dbcfg->location, 0777);
668                 privctx->lockfile_fd = open(buffer, O_RDWR | O_CREAT, 0600);
669         }
670         if (chdir(dbcfg->location) == -1) {
671                 /* Shouldn't happen after the above */
672                 logthing(LOGTHING_CRITICAL,
673                         "Couldn't change to database directory: %s",
674                         strerror(errno));
675                 free(dbctx->priv);
676                 free(dbctx);
677                 return NULL;
678         }
679         privctx->lockfile_fd = open(buffer,
680                                  (privctx->lockfile_readonly) ?
681                                  O_RDONLY : O_RDWR);
682         if (privctx->lockfile_fd == -1)
683                 privctx->lockfile_fd = open(buffer, O_RDWR | O_CREAT, 0600);
684         if (privctx->lockfile_fd == -1) {
685                 logthing(LOGTHING_CRITICAL,
686                          "Unable to open lockfile '%s'. (%s)",
687                          buffer, strerror(errno));
688                 exit(1);        /* Lacking rwx on the key dir */
689         }
690
691         dbctx->cleanupdb                = fs_cleanupdb;
692         dbctx->starttrans               = fs_starttrans;
693         dbctx->endtrans                 = fs_endtrans;
694         dbctx->fetch_key_id             = fs_fetch_key_id;
695         dbctx->fetch_key_fp             = generic_fetch_key_fp;
696         dbctx->fetch_key_text           = fs_fetch_key_text;
697         dbctx->fetch_key_skshash        = fs_fetch_key_skshash;
698         dbctx->store_key                = fs_store_key;
699         dbctx->update_keys              = generic_update_keys;
700         dbctx->delete_key               = fs_delete_key;
701         dbctx->getkeysigs               = generic_getkeysigs;
702         dbctx->cached_getkeysigs        = generic_cached_getkeysigs;
703         dbctx->keyid2uid                = generic_keyid2uid;
704         dbctx->getfullkeyid             = fs_getfullkeyid;
705         dbctx->iterate_keys             = fs_iterate_keys;
706
707         return dbctx;
708 }