1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * Copyright 2006 by the Massachusetts Institute of Technology.
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
26 /**********************************************************************
28 * C %name: db2_exp.c %
31 * %created_by: spradeep %
32 * %date_created: Tue Apr 5 11:44:00 2005 %
34 **********************************************************************/
48 #include "policy_db.h"
50 /* Quick and dirty wrapper functions to provide for thread safety
51 within the plugin, instead of making the kdb5 library do it. Eventually
52 these should be integrated into the real functions.
54 Some of the functions wrapped here are also called directly from
55 within this library (e.g., create calls open), so simply dropping
56 locking code into the top and bottom of each referenced function
57 won't do. (We aren't doing recursive locks, currently.) */
59 k5_mutex_t *krb5_db2_mutex;
61 #define WRAP(NAME,TYPE,ARGLIST,ARGNAMES,ERROR_RESULT) \
62 static TYPE wrap_##NAME ARGLIST \
65 int code = k5_mutex_lock (krb5_db2_mutex); \
66 if (code) { return ERROR_RESULT; } \
67 result = NAME ARGNAMES; \
68 k5_mutex_unlock (krb5_db2_mutex); \
71 /* hack: decl to allow a following ";" */ \
72 static TYPE wrap_##NAME ()
74 /* Two special cases: void (can't assign result), and krb5_error_code
75 (return error from locking code). */
77 #define WRAP_VOID(NAME,ARGLIST,ARGNAMES) \
78 static void wrap_##NAME ARGLIST \
80 int code = k5_mutex_lock (krb5_db2_mutex); \
81 if (code) { return; } \
83 k5_mutex_unlock (krb5_db2_mutex); \
85 /* hack: decl to allow a following ";" */ \
86 static void wrap_##NAME ()
88 #define WRAP_K(NAME,ARGLIST,ARGNAMES) \
89 WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES,code)
91 WRAP_K (krb5_db2_open,
92 ( krb5_context kcontext,
96 (kcontext, conf_section, db_args, mode));
97 WRAP_K (krb5_db2_fini, (krb5_context ctx), (ctx));
98 WRAP_K (krb5_db2_create,
99 ( krb5_context kcontext, char *conf_section, char **db_args ),
100 (kcontext, conf_section, db_args));
101 WRAP_K (krb5_db2_destroy,
102 ( krb5_context kcontext, char *conf_section, char **db_args ),
103 (kcontext, conf_section, db_args));
104 WRAP_K (krb5_db2_get_age,
110 WRAP_K (krb5_db2_lock,
111 ( krb5_context context,
114 WRAP_K (krb5_db2_unlock, (krb5_context ctx), (ctx));
116 WRAP_K (krb5_db2_get_principal,
118 krb5_const_principal p,
122 WRAP_VOID (krb5_db2_free_principal,
126 WRAP_K (krb5_db2_put_principal,
131 WRAP_K (krb5_db2_delete_principal,
132 (krb5_context context,
133 krb5_const_principal searchfor),
134 (context, searchfor));
136 WRAP_K (krb5_db2_iterate,
137 (krb5_context ctx, char *s,
138 krb5_error_code (*f) (krb5_pointer,
143 WRAP_K (krb5_db2_create_policy,
144 (krb5_context context, osa_policy_ent_t entry),
146 WRAP_K (krb5_db2_get_policy,
147 ( krb5_context kcontext,
149 osa_policy_ent_t *policy),
150 (kcontext, name, policy));
151 WRAP_K (krb5_db2_put_policy,
152 ( krb5_context kcontext, osa_policy_ent_t policy ),
154 WRAP_K (krb5_db2_iter_policy,
155 ( krb5_context kcontext,
157 osa_adb_iter_policy_func func,
159 (kcontext, match_entry, func, data));
160 WRAP_K (krb5_db2_delete_policy,
161 ( krb5_context kcontext, char *policy ),
163 WRAP_VOID (krb5_db2_free_policy,
164 ( krb5_context kcontext, osa_policy_ent_t entry ),
167 WRAP_K (krb5_db2_promote_db,
168 ( krb5_context kcontext, char *conf_section, char **db_args ),
169 (kcontext, conf_section, db_args));
171 WRAP_K (krb5_db2_check_policy_as,
172 (krb5_context kcontext, krb5_kdc_req *request, krb5_db_entry *client,
173 krb5_db_entry *server, krb5_timestamp kdc_time, const char **status,
175 (kcontext, request, client, server, kdc_time, status, e_data));
177 WRAP_VOID (krb5_db2_audit_as_req,
178 (krb5_context kcontext, krb5_kdc_req *request,
179 krb5_db_entry *client, krb5_db_entry *server,
180 krb5_timestamp authtime, krb5_error_code error_code),
181 (kcontext, request, client, server, authtime, error_code));
183 static krb5_error_code
188 c = krb5int_mutex_alloc (&krb5_db2_mutex);
191 return krb5_db2_lib_init ();
194 static krb5_error_code
197 krb5int_mutex_free (krb5_db2_mutex);
198 krb5_db2_mutex = NULL;
199 return krb5_db2_lib_cleanup();
207 kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_db2, kdb_function_table) = {
208 KRB5_KDB_DAL_MAJOR_VERSION, /* major version number */
209 0, /* minor version number 0 */
210 /* init_library */ hack_init,
211 /* fini_library */ hack_cleanup,
212 /* init_module */ wrap_krb5_db2_open,
213 /* fini_module */ wrap_krb5_db2_fini,
214 /* create */ wrap_krb5_db2_create,
215 /* destroy */ wrap_krb5_db2_destroy,
216 /* get_age */ wrap_krb5_db2_get_age,
217 /* lock */ wrap_krb5_db2_lock,
218 /* unlock */ wrap_krb5_db2_unlock,
219 /* get_principal */ wrap_krb5_db2_get_principal,
220 /* free_principal */ wrap_krb5_db2_free_principal,
221 /* put_principal */ wrap_krb5_db2_put_principal,
222 /* delete_principal */ wrap_krb5_db2_delete_principal,
223 /* iterate */ wrap_krb5_db2_iterate,
224 /* create_policy */ wrap_krb5_db2_create_policy,
225 /* get_policy */ wrap_krb5_db2_get_policy,
226 /* put_policy */ wrap_krb5_db2_put_policy,
227 /* iter_policy */ wrap_krb5_db2_iter_policy,
228 /* delete_policy */ wrap_krb5_db2_delete_policy,
229 /* free_policy */ wrap_krb5_db2_free_policy,
230 /* alloc */ krb5_db2_alloc,
231 /* free */ krb5_db2_free,
232 /* blah blah blah */ 0,0,0,0,0,
233 /* promote_db */ wrap_krb5_db2_promote_db,
235 /* check_policy_as */ wrap_krb5_db2_check_policy_as,
237 /* audit_as_req */ wrap_krb5_db2_audit_as_req,