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) \
62 static TYPE wrap_##NAME ARGLIST \
65 k5_mutex_lock (krb5_db2_mutex); \
66 result = NAME ARGNAMES; \
67 k5_mutex_unlock (krb5_db2_mutex); \
70 /* hack: decl to allow a following ";" */ \
71 static TYPE wrap_##NAME ()
73 /* Two special cases: void (can't assign result), and krb5_error_code
74 (return error from locking code). */
76 #define WRAP_VOID(NAME,ARGLIST,ARGNAMES) \
77 static void wrap_##NAME ARGLIST \
79 k5_mutex_lock (krb5_db2_mutex); \
81 k5_mutex_unlock (krb5_db2_mutex); \
83 /* hack: decl to allow a following ";" */ \
84 static void wrap_##NAME ()
86 #define WRAP_K(NAME,ARGLIST,ARGNAMES) \
87 WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES)
89 WRAP_K (krb5_db2_open,
90 ( krb5_context kcontext,
94 (kcontext, conf_section, db_args, mode));
95 WRAP_K (krb5_db2_fini, (krb5_context ctx), (ctx));
96 WRAP_K (krb5_db2_create,
97 ( krb5_context kcontext, char *conf_section, char **db_args ),
98 (kcontext, conf_section, db_args));
99 WRAP_K (krb5_db2_destroy,
100 ( krb5_context kcontext, char *conf_section, char **db_args ),
101 (kcontext, conf_section, db_args));
102 WRAP_K (krb5_db2_get_age,
108 WRAP_K (krb5_db2_lock,
109 ( krb5_context context,
112 WRAP_K (krb5_db2_unlock, (krb5_context ctx), (ctx));
114 WRAP_K (krb5_db2_get_principal,
116 krb5_const_principal p,
120 WRAP_K (krb5_db2_put_principal,
125 WRAP_K (krb5_db2_delete_principal,
126 (krb5_context context,
127 krb5_const_principal searchfor),
128 (context, searchfor));
130 WRAP_K (krb5_db2_iterate,
131 (krb5_context ctx, char *s,
132 krb5_error_code (*f) (krb5_pointer,
134 krb5_pointer p, krb5_flags flags),
135 (ctx, s, f, p, flags));
137 WRAP_K (krb5_db2_create_policy,
138 (krb5_context context, osa_policy_ent_t entry),
140 WRAP_K (krb5_db2_get_policy,
141 ( krb5_context kcontext,
143 osa_policy_ent_t *policy),
144 (kcontext, name, policy));
145 WRAP_K (krb5_db2_put_policy,
146 ( krb5_context kcontext, osa_policy_ent_t policy ),
148 WRAP_K (krb5_db2_iter_policy,
149 ( krb5_context kcontext,
151 osa_adb_iter_policy_func func,
153 (kcontext, match_entry, func, data));
154 WRAP_K (krb5_db2_delete_policy,
155 ( krb5_context kcontext, char *policy ),
158 WRAP_K (krb5_db2_promote_db,
159 ( krb5_context kcontext, char *conf_section, char **db_args ),
160 (kcontext, conf_section, db_args));
162 WRAP_K (krb5_db2_check_policy_as,
163 (krb5_context kcontext, krb5_kdc_req *request, krb5_db_entry *client,
164 krb5_db_entry *server, krb5_timestamp kdc_time, const char **status,
165 krb5_pa_data ***e_data),
166 (kcontext, request, client, server, kdc_time, status, e_data));
168 WRAP_VOID (krb5_db2_audit_as_req,
169 (krb5_context kcontext, krb5_kdc_req *request,
170 const krb5_address *local_addr,
171 const krb5_address *remote_addr,
172 krb5_db_entry *client, krb5_db_entry *server,
173 krb5_timestamp authtime, krb5_error_code error_code),
174 (kcontext, request, local_addr, remote_addr, client, server,
175 authtime, error_code));
177 static krb5_error_code
182 c = krb5int_mutex_alloc (&krb5_db2_mutex);
185 return krb5_db2_lib_init ();
188 static krb5_error_code
191 krb5int_mutex_free (krb5_db2_mutex);
192 krb5_db2_mutex = NULL;
193 return krb5_db2_lib_cleanup();
201 kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_db2, kdb_function_table) = {
202 KRB5_KDB_DAL_MAJOR_VERSION, /* major version number */
203 0, /* minor version number 0 */
204 /* init_library */ hack_init,
205 /* fini_library */ hack_cleanup,
206 /* init_module */ wrap_krb5_db2_open,
207 /* fini_module */ wrap_krb5_db2_fini,
208 /* create */ wrap_krb5_db2_create,
209 /* destroy */ wrap_krb5_db2_destroy,
210 /* get_age */ wrap_krb5_db2_get_age,
211 /* lock */ wrap_krb5_db2_lock,
212 /* unlock */ wrap_krb5_db2_unlock,
213 /* get_principal */ wrap_krb5_db2_get_principal,
214 /* put_principal */ wrap_krb5_db2_put_principal,
215 /* delete_principal */ wrap_krb5_db2_delete_principal,
216 /* rename_principal */ NULL,
217 /* iterate */ wrap_krb5_db2_iterate,
218 /* create_policy */ wrap_krb5_db2_create_policy,
219 /* get_policy */ wrap_krb5_db2_get_policy,
220 /* put_policy */ wrap_krb5_db2_put_policy,
221 /* iter_policy */ wrap_krb5_db2_iter_policy,
222 /* delete_policy */ wrap_krb5_db2_delete_policy,
223 /* blah blah blah */ 0,0,0,0,0,
224 /* promote_db */ wrap_krb5_db2_promote_db,
226 /* check_policy_as */ wrap_krb5_db2_check_policy_as,
228 /* audit_as_req */ wrap_krb5_db2_audit_as_req,