Novell Database Abstraction Layer merge.
[krb5.git] / src / lib / kdb / kdb5.h
1 #ifndef _KRB5_KDB5_H_
2 #define _KRB5_KDB5_H_
3
4 #if HAVE_UNISTD_H
5 #include <unistd.h>
6 #endif
7
8 #include <errno.h>
9 #include <utime.h>
10 #include <utime.h>
11 #include <k5-int.h>
12 #include "err_handle.h"
13
14 #define KDB_MAX_DB_NAME 128
15 #define KDB_REALM_SECTION  "realms"
16 #define KDB_MODULE_POINTER "database_module"
17 #define KDB_MODULE_SECTION "db_modules"
18 #define KDB_LIB_POINTER    "db_library"
19 #define KDB_DATABASE_CONF_FILE  DEFAULT_SECURE_PROFILE_PATH
20 #define KDB_DATABASE_ENV_PROF KDC_PROFILE_ENV
21
22 #define KRB5_KDB_OPEN_RW                0
23 #define KRB5_KDB_OPEN_RO                1
24
25 #define KRB5_KDB_OPT_SET_DB_NAME        0
26 #define KRB5_KDB_OPT_SET_LOCK_MODE      1
27
28 #define KRB5_DB_GET_DB_CONTEXT(kcontext)   ( ((kdb5_dal_handle*) (kcontext)->db_context)->db_context )
29 #define KRB5_DB_GET_PROFILE(kcontext)  ( (kcontext)->profile )
30 #define KRB5_DB_GET_REALM(kcontext)    ( (kcontext)->default_realm )
31
32 #ifndef KRB5_DB_LOCKMODE_SHARED
33 #define KRB5_DB_LOCKMODE_SHARED       0x0001
34 #endif
35
36 #ifndef KRB5_DB_LOCKMODE_EXCLUSIVE
37 #define KRB5_DB_LOCKMODE_EXCLUSIVE    0x0002
38 #endif
39
40 #ifndef KRB5_DB_LOCKMODE_DONTBLOCK
41 #define KRB5_DB_LOCKMODE_DONTBLOCK    0x0004
42 #endif
43
44 #ifndef KRB5_DB_LOCKMODE_PERMANENT
45 #define KRB5_DB_LOCKMODE_PERMANENT    0x0008
46 #endif
47
48 typedef struct _kdb_vftabl{
49     short int maj_ver;
50     short int min_ver;
51
52     short int is_thread_safe;
53
54     krb5_error_code (*init_library)(krb5_set_err_func_t);
55     krb5_error_code (*fini_library)();
56     krb5_error_code (*init_module) ( krb5_context kcontext,
57                                      char * conf_section,
58                                      char ** db_args,
59                                      int mode );
60
61     krb5_error_code (*fini_module) ( krb5_context kcontext );
62
63     krb5_error_code (*db_create) ( krb5_context kcontext,
64                                    char * conf_section,
65                                    char ** db_args );
66
67     krb5_error_code (*db_destroy) ( krb5_context kcontext,
68                                     char *conf_section,
69                                     char ** db_args );
70
71     krb5_error_code (*db_get_age) ( krb5_context kcontext, 
72                                     char *db_name, 
73                                     time_t *age );
74
75     krb5_error_code (*db_set_option) ( krb5_context kcontext,
76                                        int option,
77                                        void *value );
78
79     krb5_error_code (*db_lock) ( krb5_context kcontext,
80                                  int mode );
81
82     krb5_error_code (*db_unlock) ( krb5_context kcontext);
83
84     krb5_error_code (*db_get_principal) ( krb5_context kcontext,
85                                           krb5_const_principal search_for,
86                                           krb5_db_entry *entries,
87                                           int *nentries,
88                                           krb5_boolean *more );
89
90     krb5_error_code (*db_free_principal) ( krb5_context kcontext,
91                                            krb5_db_entry *entry,
92                                            int count );
93
94     krb5_error_code (*db_put_principal) ( krb5_context kcontext,
95                                           krb5_db_entry *entries,
96                                           int *nentries,
97                                           char **db_args);
98
99     krb5_error_code (*db_delete_principal) ( krb5_context kcontext,
100                                              krb5_const_principal search_for,
101                                              int *nentries );
102
103     krb5_error_code (*db_iterate) ( krb5_context kcontext,
104                                     char *match_entry,
105                                     int (*func) (krb5_pointer, krb5_db_entry *),
106                                     krb5_pointer func_arg );
107
108     krb5_error_code (*db_create_policy) ( krb5_context kcontext,
109                                           osa_policy_ent_t policy );
110
111     krb5_error_code (*db_get_policy) ( krb5_context kcontext,
112                                        char *name,
113                                        osa_policy_ent_t *policy,
114                                        int *cnt);
115
116     krb5_error_code (*db_put_policy) ( krb5_context kcontext,
117                                        osa_policy_ent_t policy );
118
119     krb5_error_code (*db_iter_policy) ( krb5_context kcontext,
120                                         char *match_entry,
121                                         osa_adb_iter_policy_func func,
122                                         void *data );
123
124
125     krb5_error_code (*db_delete_policy) ( krb5_context kcontext,
126                                           char *policy );
127
128     void (*db_free_policy) ( krb5_context kcontext,
129                              osa_policy_ent_t val );
130
131     krb5_error_code (*db_supported_realms) ( krb5_context kcontext,
132                                             char **realms );
133
134     krb5_error_code (*db_free_supported_realms) ( krb5_context kcontext,
135                                                   char **realms );
136
137
138     const char * (*errcode_2_string) ( krb5_context kcontext,
139                                        long err_code );
140
141     void * (*db_alloc) (krb5_context kcontext, void *ptr, size_t size);
142     void   (*db_free)  (krb5_context kcontext, void *ptr);
143
144
145
146     /* optional functions */
147     krb5_error_code (*set_master_key)    ( krb5_context kcontext, 
148                                            char *pwd, 
149                                            krb5_keyblock *key);
150
151     krb5_error_code (*get_master_key)    ( krb5_context kcontext,
152                                            krb5_keyblock **key);
153
154
155     krb5_error_code (*setup_master_key_name) ( krb5_context kcontext,
156                                                char *keyname,
157                                                char *realm, 
158                                                char **fullname, 
159                                                krb5_principal  *principal);
160
161     krb5_error_code (*store_master_key)  ( krb5_context kcontext, 
162                                            char *db_arg, 
163                                            krb5_principal mname,
164                                            krb5_keyblock *key,
165                                            char *master_pwd);
166
167     krb5_error_code (*fetch_master_key)  ( krb5_context kcontext,
168                                            krb5_principal mname,
169                                            krb5_keyblock *key,
170                                            int *kvno,
171                                            char *db_args);
172
173     krb5_error_code (*verify_master_key) ( krb5_context kcontext,
174                                            krb5_principal mprinc,
175                                            krb5_keyblock *mkey );
176
177     krb5_error_code (*dbe_search_enctype) ( krb5_context kcontext, 
178                                             krb5_db_entry *dbentp, 
179                                             krb5_int32 *start, 
180                                             krb5_int32 ktype, 
181                                             krb5_int32 stype, 
182                                             krb5_int32 kvno, 
183                                             krb5_key_data **kdatap);
184     
185
186     krb5_error_code
187     (*db_change_pwd) ( krb5_context       context,
188                        krb5_keyblock       * master_key,
189                        krb5_key_salt_tuple      * ks_tuple,
190                        int                        ks_tuple_count,
191                        char             * passwd,
192                        int                        new_kvno,
193                        krb5_boolean       keepold,
194                        krb5_db_entry    * db_entry);
195
196 } kdb_vftabl;
197
198 typedef struct _db_library {
199     char name[KDB_MAX_DB_NAME];
200     int reference_cnt;
201 #ifdef HAVE_PTHREAD_H
202     pthread_mutex_t lib_lock;
203     pthread_cond_t unlocked; /*  To check whether some one has called db_unlock */
204     int recursive_cnt;               /* this is used as lock to help recursive locking */
205     pthread_t lock_holder;
206     int excl;
207 #endif
208     void *dl_handle;
209     kdb_vftabl vftabl;
210     struct _db_library *next, *prev;
211 } *db_library;
212
213 typedef struct _kdb5_dal_handle
214 {
215     void *db_context;               /* helps us to change db_library without affecting modules to some extend */
216     db_library lib_handle;
217 } kdb5_dal_handle;
218
219 #endif  /* end of _KRB5_KDB5_H_ */