~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/plugins/kdb/db2/db2_exp.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman, Russ Allbery, Sam Hartman
  • Date: 2008-08-21 10:41:41 UTC
  • mfrom: (11.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080821104141-a0f9c4o4cpo8xd0o
Tags: 1.6.dfsg.4~beta1-4
[ Russ Allbery ]
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #487669, #491774)
  - Italian, thanks Luca Monducci.  (Closes: #493962)

[ Sam Hartman ]
* Translation Updates:
    - Dutch, Thanks Vincent Zweije, Closes: #495733

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2006 by the Massachusetts Institute of Technology.
 
3
 * All Rights Reserved.
 
4
 *
 
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.
 
9
 * 
 
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.
 
23
 */
 
24
 
 
25
/**********************************************************************
 
26
*
 
27
*       C %name:                db2_exp.c %
 
28
*       Instance:               idc_sec_2
 
29
*       Description:    
 
30
*       %created_by:    spradeep %
 
31
*       %date_created:  Tue Apr  5 11:44:00 2005 %
 
32
*
 
33
**********************************************************************/
 
34
#ifndef lint
 
35
static char *_csrc = "@(#) %filespec: db2_exp.c~5 %  (%full_filespec: db2_exp.c~5:csrc:idc_sec#2 %)";
 
36
#endif
 
37
 
 
38
#include "k5-int.h"
 
39
 
 
40
#if HAVE_UNISTD_H
 
41
#include <unistd.h>
 
42
#endif
 
43
 
 
44
#include <db.h>
 
45
#include <stdio.h>
 
46
#include <errno.h>
 
47
#include <utime.h>
 
48
#include "kdb5.h"
 
49
#include "kdb_db2.h"
 
50
#include "kdb_xdr.h"
 
51
#include "policy_db.h"
 
52
 
 
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.
 
56
 
 
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.)  */
 
61
 
 
62
static k5_mutex_t *krb5_db2_mutex;
 
63
 
 
64
#define WRAP(NAME,TYPE,ARGLIST,ARGNAMES,ERROR_RESULT)   \
 
65
        static TYPE wrap_##NAME ARGLIST                 \
 
66
        {                                               \
 
67
            TYPE result;                                \
 
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);           \
 
72
            return result;                              \
 
73
        }                                               \
 
74
        /* hack: decl to allow a following ";" */       \
 
75
        static TYPE wrap_##NAME ()
 
76
 
 
77
/* Two special cases: void (can't assign result), and krb5_error_code
 
78
   (return error from locking code).  */
 
79
 
 
80
#define WRAP_VOID(NAME,ARGLIST,ARGNAMES)                \
 
81
        static void wrap_##NAME ARGLIST                 \
 
82
        {                                               \
 
83
            int code = k5_mutex_lock (krb5_db2_mutex);  \
 
84
            if (code) { return; }                       \
 
85
            NAME ARGNAMES;                              \
 
86
            k5_mutex_unlock (krb5_db2_mutex);           \
 
87
        }                                               \
 
88
        /* hack: decl to allow a following ";" */       \
 
89
        static void wrap_##NAME ()
 
90
 
 
91
#define WRAP_K(NAME,ARGLIST,ARGNAMES)                   \
 
92
        WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES,code)
 
93
 
 
94
WRAP_K (krb5_db2_open,
 
95
        ( krb5_context kcontext,
 
96
          char *conf_section,
 
97
          char **db_args,
 
98
          int mode ),
 
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,
 
108
        (krb5_context ctx,
 
109
                   char *s,
 
110
         time_t *t),
 
111
        (ctx, s, t));
 
112
WRAP_K (krb5_db2_db_set_option,
 
113
        ( krb5_context kcontext, 
 
114
          int option, 
 
115
          void *value ),
 
116
        (kcontext, option, value));
 
117
 
 
118
WRAP_K (krb5_db2_db_lock,
 
119
        ( krb5_context    context,
 
120
          int             in_mode),
 
121
        (context, in_mode));
 
122
WRAP_K (krb5_db2_db_unlock, (krb5_context ctx), (ctx));
 
123
 
 
124
WRAP_K (krb5_db2_db_get_principal,
 
125
        (krb5_context ctx,
 
126
                   krb5_const_principal p,
 
127
                   krb5_db_entry *d,
 
128
                   int * i,
 
129
         krb5_boolean *b),
 
130
        (ctx, p, d, i, b));
 
131
WRAP_K (krb5_db2_db_free_principal,
 
132
        (krb5_context ctx,
 
133
                   krb5_db_entry *d,
 
134
         int i),
 
135
        (ctx, d, i));
 
136
WRAP_K (krb5_db2_db_put_principal,
 
137
        (krb5_context ctx,
 
138
         krb5_db_entry *d,
 
139
         int *i,
 
140
         char **db_args),
 
141
        (ctx, d, i, db_args));
 
142
WRAP_K (krb5_db2_db_delete_principal,
 
143
        (krb5_context context,
 
144
         krb5_const_principal searchfor,
 
145
         int *nentries),
 
146
        (context, searchfor, nentries));
 
147
 
 
148
WRAP_K (krb5_db2_db_iterate,
 
149
        (krb5_context ctx, char *s,
 
150
         krb5_error_code (*f) (krb5_pointer,
 
151
                              krb5_db_entry *),
 
152
         krb5_pointer p),
 
153
        (ctx, s, f, p));
 
154
 
 
155
WRAP_K (krb5_db2_create_policy,
 
156
        (krb5_context context, osa_policy_ent_t entry),
 
157
        (context, entry));
 
158
WRAP_K (krb5_db2_get_policy,
 
159
        ( krb5_context kcontext,
 
160
          char *name,
 
161
          osa_policy_ent_t *policy,
 
162
          int *cnt),
 
163
        (kcontext, name, policy, cnt));
 
164
WRAP_K (krb5_db2_put_policy,
 
165
        ( krb5_context kcontext, osa_policy_ent_t policy ),
 
166
        (kcontext, policy));
 
167
WRAP_K (krb5_db2_iter_policy,
 
168
        ( krb5_context kcontext,
 
169
          char *match_entry,
 
170
          osa_adb_iter_policy_func func,
 
171
          void *data ),
 
172
        (kcontext, match_entry, func, data));
 
173
WRAP_K (krb5_db2_delete_policy,
 
174
        ( krb5_context kcontext, char *policy ),
 
175
        (kcontext, policy));
 
176
WRAP_VOID (krb5_db2_free_policy,
 
177
           ( krb5_context kcontext, osa_policy_ent_t entry ),
 
178
           (kcontext, entry));
 
179
 
 
180
WRAP (krb5_db2_alloc, void *,
 
181
      ( krb5_context kcontext,  
 
182
        void *ptr, 
 
183
        size_t size ),
 
184
      (kcontext, ptr, size), NULL);
 
185
WRAP_VOID (krb5_db2_free,
 
186
           ( krb5_context kcontext, void *ptr ),
 
187
           (kcontext, ptr));
 
188
 
 
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),
 
194
        (context, key));
 
195
WRAP_K (krb5_db2_promote_db,
 
196
        ( krb5_context kcontext, char *conf_section, char **db_args ),
 
197
        (kcontext, conf_section, db_args));
 
198
 
 
199
static krb5_error_code
 
200
hack_init ()
 
201
{
 
202
    krb5_error_code c;
 
203
    c = krb5int_mutex_alloc (&krb5_db2_mutex);
 
204
    if (c)
 
205
        return c;
 
206
    return krb5_db2_lib_init ();
 
207
}
 
208
 
 
209
static krb5_error_code
 
210
hack_cleanup (void)
 
211
{
 
212
    krb5int_mutex_free (krb5_db2_mutex);
 
213
    krb5_db2_mutex = NULL;
 
214
    return krb5_db2_lib_cleanup();
 
215
}
 
216
 
 
217
 
 
218
/*
 
219
 *      Exposed API
 
220
 */
 
221
 
 
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,
 
256
};