xref: /freebsd/crypto/heimdal/lib/hdb/hdb.h (revision c19800e8cd5640693f36f2040db4ab5e8d738146)
1b528cefcSMark Murray /*
2c19800e8SDoug Rabson  * Copyright (c) 1997 - 2007 Kungliga Tekniska H�gskolan
3b528cefcSMark Murray  * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray  * All rights reserved.
5b528cefcSMark Murray  *
6b528cefcSMark Murray  * Redistribution and use in source and binary forms, with or without
7b528cefcSMark Murray  * modification, are permitted provided that the following conditions
8b528cefcSMark Murray  * are met:
9b528cefcSMark Murray  *
10b528cefcSMark Murray  * 1. Redistributions of source code must retain the above copyright
11b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer.
12b528cefcSMark Murray  *
13b528cefcSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
14b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer in the
15b528cefcSMark Murray  *    documentation and/or other materials provided with the distribution.
16b528cefcSMark Murray  *
17b528cefcSMark Murray  * 3. Neither the name of the Institute nor the names of its contributors
18b528cefcSMark Murray  *    may be used to endorse or promote products derived from this software
19b528cefcSMark Murray  *    without specific prior written permission.
20b528cefcSMark Murray  *
21b528cefcSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22b528cefcSMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23b528cefcSMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24b528cefcSMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25b528cefcSMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26b528cefcSMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27b528cefcSMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28b528cefcSMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29b528cefcSMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30b528cefcSMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b528cefcSMark Murray  * SUCH DAMAGE.
32b528cefcSMark Murray  */
33b528cefcSMark Murray 
34c19800e8SDoug Rabson /* $Id: hdb.h 22198 2007-12-07 13:09:25Z lha $ */
35b528cefcSMark Murray 
36b528cefcSMark Murray #ifndef __HDB_H__
37b528cefcSMark Murray #define __HDB_H__
38b528cefcSMark Murray 
39b528cefcSMark Murray #include <hdb_err.h>
40b528cefcSMark Murray 
41c19800e8SDoug Rabson #include <heim_asn1.h>
42b528cefcSMark Murray #include <hdb_asn1.h>
43b528cefcSMark Murray 
44c19800e8SDoug Rabson struct hdb_dbinfo;
45c19800e8SDoug Rabson 
46b528cefcSMark Murray enum hdb_lockop{ HDB_RLOCK, HDB_WLOCK };
47b528cefcSMark Murray 
48b528cefcSMark Murray /* flags for various functions */
49b528cefcSMark Murray #define HDB_F_DECRYPT		1	/* decrypt keys */
50b528cefcSMark Murray #define HDB_F_REPLACE		2	/* replace entry */
51c19800e8SDoug Rabson #define HDB_F_GET_CLIENT	4	/* fetch client */
52c19800e8SDoug Rabson #define HDB_F_GET_SERVER	8	/* fetch server */
53c19800e8SDoug Rabson #define HDB_F_GET_KRBTGT	16	/* fetch krbtgt */
54c19800e8SDoug Rabson #define HDB_F_GET_ANY		28	/* fetch any of client,server,krbtgt */
55c19800e8SDoug Rabson #define HDB_F_CANON		32	/* want canonicalition */
56b528cefcSMark Murray 
575e9cd1aeSAssar Westerlund /* key usage for master key */
585e9cd1aeSAssar Westerlund #define HDB_KU_MKEY	0x484442
595e9cd1aeSAssar Westerlund 
605e9cd1aeSAssar Westerlund typedef struct hdb_master_key_data *hdb_master_key;
615e9cd1aeSAssar Westerlund 
62c19800e8SDoug Rabson typedef struct hdb_entry_ex {
63c19800e8SDoug Rabson     void *ctx;
64c19800e8SDoug Rabson     hdb_entry entry;
65c19800e8SDoug Rabson     void (*free_entry)(krb5_context, struct hdb_entry_ex *);
66c19800e8SDoug Rabson } hdb_entry_ex;
67b528cefcSMark Murray 
68c19800e8SDoug Rabson 
69c19800e8SDoug Rabson typedef struct HDB{
70c19800e8SDoug Rabson     void *hdb_db;
71c19800e8SDoug Rabson     void *hdb_dbc;
72c19800e8SDoug Rabson     char *hdb_name;
73c19800e8SDoug Rabson     int hdb_master_key_set;
74c19800e8SDoug Rabson     hdb_master_key hdb_master_key;
75c19800e8SDoug Rabson     int hdb_openp;
76c19800e8SDoug Rabson 
77c19800e8SDoug Rabson     krb5_error_code (*hdb_open)(krb5_context,
78c19800e8SDoug Rabson 				struct HDB*,
79c19800e8SDoug Rabson 				int,
80c19800e8SDoug Rabson 				mode_t);
81c19800e8SDoug Rabson     krb5_error_code (*hdb_close)(krb5_context,
82c19800e8SDoug Rabson 				 struct HDB*);
83c19800e8SDoug Rabson     void	    (*hdb_free)(krb5_context,
84c19800e8SDoug Rabson 				struct HDB*,
85c19800e8SDoug Rabson 				hdb_entry_ex*);
86c19800e8SDoug Rabson     krb5_error_code (*hdb_fetch)(krb5_context,
87c19800e8SDoug Rabson 				 struct HDB*,
88c19800e8SDoug Rabson 				 krb5_const_principal,
89c19800e8SDoug Rabson 				 unsigned,
90c19800e8SDoug Rabson 				 hdb_entry_ex*);
91c19800e8SDoug Rabson     krb5_error_code (*hdb_store)(krb5_context,
92c19800e8SDoug Rabson 				 struct HDB*,
93c19800e8SDoug Rabson 				 unsigned,
94c19800e8SDoug Rabson 				 hdb_entry_ex*);
95c19800e8SDoug Rabson     krb5_error_code (*hdb_remove)(krb5_context,
96c19800e8SDoug Rabson 				  struct HDB*,
97c19800e8SDoug Rabson 				  krb5_const_principal);
98c19800e8SDoug Rabson     krb5_error_code (*hdb_firstkey)(krb5_context,
99c19800e8SDoug Rabson 				    struct HDB*,
100c19800e8SDoug Rabson 				    unsigned,
101c19800e8SDoug Rabson 				    hdb_entry_ex*);
102c19800e8SDoug Rabson     krb5_error_code (*hdb_nextkey)(krb5_context,
103c19800e8SDoug Rabson 				   struct HDB*,
104c19800e8SDoug Rabson 				   unsigned,
105c19800e8SDoug Rabson 				   hdb_entry_ex*);
106c19800e8SDoug Rabson     krb5_error_code (*hdb_lock)(krb5_context,
107c19800e8SDoug Rabson 				struct HDB*,
108c19800e8SDoug Rabson 				int operation);
109c19800e8SDoug Rabson     krb5_error_code (*hdb_unlock)(krb5_context,
110c19800e8SDoug Rabson 				  struct HDB*);
111c19800e8SDoug Rabson     krb5_error_code (*hdb_rename)(krb5_context,
112c19800e8SDoug Rabson 				  struct HDB*,
113c19800e8SDoug Rabson 				  const char*);
114c19800e8SDoug Rabson     krb5_error_code (*hdb__get)(krb5_context,
115c19800e8SDoug Rabson 				struct HDB*,
116c19800e8SDoug Rabson 				krb5_data,
117c19800e8SDoug Rabson 				krb5_data*);
118c19800e8SDoug Rabson     krb5_error_code (*hdb__put)(krb5_context,
119c19800e8SDoug Rabson 				struct HDB*,
120c19800e8SDoug Rabson 				int,
121c19800e8SDoug Rabson 				krb5_data,
122c19800e8SDoug Rabson 				krb5_data);
123c19800e8SDoug Rabson     krb5_error_code (*hdb__del)(krb5_context,
124c19800e8SDoug Rabson 				struct HDB*,
125c19800e8SDoug Rabson 				krb5_data);
126c19800e8SDoug Rabson     krb5_error_code (*hdb_destroy)(krb5_context,
127c19800e8SDoug Rabson 				   struct HDB*);
128b528cefcSMark Murray }HDB;
129b528cefcSMark Murray 
130c19800e8SDoug Rabson #define HDB_INTERFACE_VERSION	4
131c19800e8SDoug Rabson 
132c19800e8SDoug Rabson struct hdb_so_method {
133c19800e8SDoug Rabson     int version;
134c19800e8SDoug Rabson     const char *prefix;
135c19800e8SDoug Rabson     krb5_error_code (*create)(krb5_context, HDB **, const char *filename);
136c19800e8SDoug Rabson };
137b528cefcSMark Murray 
138b528cefcSMark Murray typedef krb5_error_code (*hdb_foreach_func_t)(krb5_context, HDB*,
139c19800e8SDoug Rabson 					      hdb_entry_ex*, void*);
140b528cefcSMark Murray extern krb5_kt_ops hdb_kt_ops;
141b528cefcSMark Murray 
142b528cefcSMark Murray #include <hdb-protos.h>
143b528cefcSMark Murray 
144b528cefcSMark Murray #endif /* __HDB_H__ */
145