1 /* keybox-init.c - Initalization of the library
2 * Copyright (C) 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include "../jnlib/mischelp.h"
28 #include "keybox-defs.h"
30 static KB_NAME kb_names
;
34 Register a filename for plain keybox files. Returns a pointer to be
35 used to create a handles etc or NULL to indicate that it has already
38 keybox_register_file (const char *fname
, int secret
)
42 for (kr
=kb_names
; kr
; kr
= kr
->next
)
44 if (same_file_p (kr
->fname
, fname
) )
45 return NULL
; /* Already registered. */
48 kr
= xtrymalloc (sizeof *kr
+ strlen (fname
));
51 strcpy (kr
->fname
, fname
);
52 kr
->secret
= !!secret
;
53 /* kr->lockhd = NULL;*/
55 kr
->did_full_scan
= 0;
56 /* keep a list of all issued pointers */
60 /* create the offset table the first time a function here is used */
62 /* kb_offtbl = new_offset_hash_table (); */
68 keybox_is_writable (void *token
)
72 return r
? !access (r
->fname
, W_OK
) : 0;
77 /* Create a new handle for the resource associated with TOKEN. SECRET
78 is just a cross-check.
80 The returned handle must be released using keybox_release (). */
82 keybox_new (void *token
, int secret
)
85 KB_NAME resource
= token
;
87 assert (resource
&& !resource
->secret
== !secret
);
88 hd
= xtrycalloc (1, sizeof *hd
);
92 hd
->secret
= !!secret
;
98 keybox_release (KEYBOX_HANDLE hd
)
102 _keybox_release_blob (hd
->found
.blob
);
108 xfree (hd
->word_match
.name
);
109 xfree (hd
->word_match
.pattern
);
115 keybox_get_resource_name (KEYBOX_HANDLE hd
)
119 return hd
->kb
->fname
;
123 keybox_set_ephemeral (KEYBOX_HANDLE hd
, int yes
)
126 return gpg_error (GPG_ERR_INV_HANDLE
);