2
* Copyright 2006 by the Massachusetts Institute of Technology.
5
* Export of this software from the United States of America may
6
* require a specific license from the United States Government.
7
* It is the responsibility of any person or organization contemplating
8
* export to obtain such a license before exporting.
10
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
11
* distribute this software and its documentation for any purpose and
12
* without fee is hereby granted, provided that the above copyright
13
* notice appear in all copies and that both that copyright notice and
14
* this permission notice appear in supporting documentation, and that
15
* the name of M.I.T. not be used in advertising or publicity pertaining
16
* to distribution of the software without specific, written prior
17
* permission. Furthermore if you modify this software you must label
18
* your software as modified software and not distribute it in such a
19
* fashion that it might be confused with the original M.I.T. software.
20
* M.I.T. makes no representations about the suitability of
21
* this software for any purpose. It is provided "as is" without express
22
* or implied warranty.
25
/**********************************************************************
27
* C %name: db2_exp.c %
30
* %created_by: spradeep %
31
* %date_created: Tue Apr 5 11:44:00 2005 %
33
**********************************************************************/
35
static char *_csrc = "@(#) %filespec: db2_exp.c~5 % (%full_filespec: db2_exp.c~5:csrc:idc_sec#2 %)";
51
#include "policy_db.h"
53
/* Quick and dirty wrapper functions to provide for thread safety
54
within the plugin, instead of making the kdb5 library do it. Eventually
55
these should be integrated into the real functions.
57
Some of the functions wrapped here are also called directly from
58
within this library (e.g., create calls open), so simply dropping
59
locking code into the top and bottom of each referenced function
60
won't do. (We aren't doing recursive locks, currently.) */
62
static k5_mutex_t *krb5_db2_mutex;
64
#define WRAP(NAME,TYPE,ARGLIST,ARGNAMES,ERROR_RESULT) \
65
static TYPE wrap_##NAME ARGLIST \
68
int code = k5_mutex_lock (krb5_db2_mutex); \
69
if (code) { return ERROR_RESULT; } \
70
result = NAME ARGNAMES; \
71
k5_mutex_unlock (krb5_db2_mutex); \
74
/* hack: decl to allow a following ";" */ \
75
static TYPE wrap_##NAME ()
77
/* Two special cases: void (can't assign result), and krb5_error_code
78
(return error from locking code). */
80
#define WRAP_VOID(NAME,ARGLIST,ARGNAMES) \
81
static void wrap_##NAME ARGLIST \
83
int code = k5_mutex_lock (krb5_db2_mutex); \
84
if (code) { return; } \
86
k5_mutex_unlock (krb5_db2_mutex); \
88
/* hack: decl to allow a following ";" */ \
89
static void wrap_##NAME ()
91
#define WRAP_K(NAME,ARGLIST,ARGNAMES) \
92
WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES,code)
94
WRAP_K (krb5_db2_open,
95
( krb5_context kcontext,
99
(kcontext, conf_section, db_args, mode));
100
WRAP_K (krb5_db2_db_fini, (krb5_context ctx), (ctx));
101
WRAP_K (krb5_db2_create,
102
( krb5_context kcontext, char *conf_section, char **db_args ),
103
(kcontext, conf_section, db_args));
104
WRAP_K (krb5_db2_destroy,
105
( krb5_context kcontext, char *conf_section, char **db_args ),
106
(kcontext, conf_section, db_args));
107
WRAP_K (krb5_db2_db_get_age,
112
WRAP_K (krb5_db2_db_set_option,
113
( krb5_context kcontext,
116
(kcontext, option, value));
118
WRAP_K (krb5_db2_db_lock,
119
( krb5_context context,
122
WRAP_K (krb5_db2_db_unlock, (krb5_context ctx), (ctx));
124
WRAP_K (krb5_db2_db_get_principal,
126
krb5_const_principal p,
131
WRAP_K (krb5_db2_db_free_principal,
136
WRAP_K (krb5_db2_db_put_principal,
141
(ctx, d, i, db_args));
142
WRAP_K (krb5_db2_db_delete_principal,
143
(krb5_context context,
144
krb5_const_principal searchfor,
146
(context, searchfor, nentries));
148
WRAP_K (krb5_db2_db_iterate,
149
(krb5_context ctx, char *s,
150
krb5_error_code (*f) (krb5_pointer,
155
WRAP_K (krb5_db2_create_policy,
156
(krb5_context context, osa_policy_ent_t entry),
158
WRAP_K (krb5_db2_get_policy,
159
( krb5_context kcontext,
161
osa_policy_ent_t *policy,
163
(kcontext, name, policy, cnt));
164
WRAP_K (krb5_db2_put_policy,
165
( krb5_context kcontext, osa_policy_ent_t policy ),
167
WRAP_K (krb5_db2_iter_policy,
168
( krb5_context kcontext,
170
osa_adb_iter_policy_func func,
172
(kcontext, match_entry, func, data));
173
WRAP_K (krb5_db2_delete_policy,
174
( krb5_context kcontext, char *policy ),
176
WRAP_VOID (krb5_db2_free_policy,
177
( krb5_context kcontext, osa_policy_ent_t entry ),
180
WRAP (krb5_db2_alloc, void *,
181
( krb5_context kcontext,
184
(kcontext, ptr, size), NULL);
185
WRAP_VOID (krb5_db2_free,
186
( krb5_context kcontext, void *ptr ),
189
WRAP_K (krb5_db2_set_master_key_ext,
190
( krb5_context kcontext, char *pwd, krb5_keyblock *key),
191
(kcontext, pwd, key));
192
WRAP_K (krb5_db2_db_get_mkey,
193
( krb5_context context, krb5_keyblock **key),
195
WRAP_K (krb5_db2_promote_db,
196
( krb5_context kcontext, char *conf_section, char **db_args ),
197
(kcontext, conf_section, db_args));
199
static krb5_error_code
203
c = krb5int_mutex_alloc (&krb5_db2_mutex);
206
return krb5_db2_lib_init ();
209
static krb5_error_code
212
krb5int_mutex_free (krb5_db2_mutex);
213
krb5_db2_mutex = NULL;
214
return krb5_db2_lib_cleanup();
222
kdb_vftabl kdb_function_table = {
223
1, /* major version number 1 */
224
0, /* minor version number 0 */
225
/* init_library */ hack_init,
226
/* fini_library */ hack_cleanup,
227
/* init_module */ wrap_krb5_db2_open,
228
/* fini_module */ wrap_krb5_db2_db_fini,
229
/* db_create */ wrap_krb5_db2_create,
230
/* db_destroy */ wrap_krb5_db2_destroy,
231
/* db_get_age */ wrap_krb5_db2_db_get_age,
232
/* db_set_option */ wrap_krb5_db2_db_set_option,
233
/* db_lock */ wrap_krb5_db2_db_lock,
234
/* db_unlock */ wrap_krb5_db2_db_unlock,
235
/* db_get_principal */ wrap_krb5_db2_db_get_principal,
236
/* db_free_principal */ wrap_krb5_db2_db_free_principal,
237
/* db_put_principal */ wrap_krb5_db2_db_put_principal,
238
/* db_delete_principal */ wrap_krb5_db2_db_delete_principal,
239
/* db_iterate */ wrap_krb5_db2_db_iterate,
240
/* db_create_policy */ wrap_krb5_db2_create_policy,
241
/* db_get_policy */ wrap_krb5_db2_get_policy,
242
/* db_put_policy */ wrap_krb5_db2_put_policy,
243
/* db_iter_policy */ wrap_krb5_db2_iter_policy,
244
/* db_delete_policy */ wrap_krb5_db2_delete_policy,
245
/* db_free_policy */ wrap_krb5_db2_free_policy,
246
/* db_supported_realms */ NULL,
247
/* db_free_supported_realms */ NULL,
248
/* errcode_2_string */ NULL,
249
/* release_errcode_string */ NULL,
250
/* db_alloc */ wrap_krb5_db2_alloc,
251
/* db_free */ wrap_krb5_db2_free,
252
/* set_master_key */ wrap_krb5_db2_set_master_key_ext,
253
/* get_master_key */ wrap_krb5_db2_db_get_mkey,
254
/* blah blah blah */ 0,0,0,0,0,0,
255
/* promote_db */ wrap_krb5_db2_promote_db,