Path: blob/main/crypto/krb5/src/plugins/kdb/db2/db2_exp.c
34914 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */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 may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425/**********************************************************************26*27* C %name: db2_exp.c %28* Instance: idc_sec_229* Description:30* %created_by: spradeep %31* %date_created: Tue Apr 5 11:44:00 2005 %32*33**********************************************************************/34#include "k5-int.h"3536#if HAVE_UNISTD_H37#include <unistd.h>38#endif3940#include <db.h>41#include <stdio.h>42#include <errno.h>43#include <utime.h>44#include "kdb5.h"45#include "kdb_db2.h"46#include "kdb_xdr.h"47#include "policy_db.h"4849/* Quick and dirty wrapper functions to provide for thread safety50within the plugin, instead of making the kdb5 library do it. Eventually51these should be integrated into the real functions.5253Some of the functions wrapped here are also called directly from54within this library (e.g., create calls open), so simply dropping55locking code into the top and bottom of each referenced function56won't do. (We aren't doing recursive locks, currently.) */5758k5_mutex_t *krb5_db2_mutex;5960#define WRAP(NAME,TYPE,ARGLIST,ARGNAMES) \61static TYPE wrap_##NAME ARGLIST \62{ \63TYPE result; \64k5_mutex_lock (krb5_db2_mutex); \65result = NAME ARGNAMES; \66k5_mutex_unlock (krb5_db2_mutex); \67return result; \68} \69/* hack: decl to allow a following ";" */ \70static TYPE wrap_##NAME ARGLIST7172/* Two special cases: void (can't assign result), and krb5_error_code73(return error from locking code). */7475#define WRAP_VOID(NAME,ARGLIST,ARGNAMES) \76static void wrap_##NAME ARGLIST \77{ \78k5_mutex_lock (krb5_db2_mutex); \79NAME ARGNAMES; \80k5_mutex_unlock (krb5_db2_mutex); \81} \82/* hack: decl to allow a following ";" */ \83static void wrap_##NAME ARGLIST8485#define WRAP_K(NAME,ARGLIST,ARGNAMES) \86WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES)8788WRAP_K (krb5_db2_open,89( krb5_context kcontext,90char *conf_section,91char **db_args,92int mode ),93(kcontext, conf_section, db_args, mode));94WRAP_K (krb5_db2_fini, (krb5_context ctx), (ctx));95WRAP_K (krb5_db2_create,96( krb5_context kcontext, char *conf_section, char **db_args ),97(kcontext, conf_section, db_args));98WRAP_K (krb5_db2_destroy,99( krb5_context kcontext, char *conf_section, char **db_args ),100(kcontext, conf_section, db_args));101WRAP_K (krb5_db2_get_age,102(krb5_context ctx,103char *s,104time_t *t),105(ctx, s, t));106107WRAP_K (krb5_db2_lock,108( krb5_context context,109int in_mode),110(context, in_mode));111WRAP_K (krb5_db2_unlock, (krb5_context ctx), (ctx));112113WRAP_K (krb5_db2_get_principal,114(krb5_context ctx,115krb5_const_principal p,116unsigned int f,117krb5_db_entry **d),118(ctx, p, f, d));119WRAP_K (krb5_db2_put_principal,120(krb5_context ctx,121krb5_db_entry *d,122char **db_args),123(ctx, d, db_args));124WRAP_K (krb5_db2_delete_principal,125(krb5_context context,126krb5_const_principal searchfor),127(context, searchfor));128129WRAP_K (krb5_db2_iterate,130(krb5_context ctx, char *s,131krb5_error_code (*f) (krb5_pointer,132krb5_db_entry *),133krb5_pointer p, krb5_flags flags),134(ctx, s, f, p, flags));135136WRAP_K (krb5_db2_create_policy,137(krb5_context context, osa_policy_ent_t entry),138(context, entry));139WRAP_K (krb5_db2_get_policy,140( krb5_context kcontext,141char *name,142osa_policy_ent_t *policy),143(kcontext, name, policy));144WRAP_K (krb5_db2_put_policy,145( krb5_context kcontext, osa_policy_ent_t policy ),146(kcontext, policy));147WRAP_K (krb5_db2_iter_policy,148( krb5_context kcontext,149char *match_entry,150osa_adb_iter_policy_func func,151void *data ),152(kcontext, match_entry, func, data));153WRAP_K (krb5_db2_delete_policy,154( krb5_context kcontext, char *policy ),155(kcontext, policy));156157WRAP_K (krb5_db2_promote_db,158( krb5_context kcontext, char *conf_section, char **db_args ),159(kcontext, conf_section, db_args));160161WRAP_K (krb5_db2_check_policy_as,162(krb5_context kcontext, krb5_kdc_req *request, krb5_db_entry *client,163krb5_db_entry *server, krb5_timestamp kdc_time, const char **status,164krb5_pa_data ***e_data),165(kcontext, request, client, server, kdc_time, status, e_data));166167WRAP_VOID (krb5_db2_audit_as_req,168(krb5_context kcontext, krb5_kdc_req *request,169const krb5_address *local_addr,170const krb5_address *remote_addr,171krb5_db_entry *client, krb5_db_entry *server,172krb5_timestamp authtime, krb5_error_code error_code),173(kcontext, request, local_addr, remote_addr, client, server,174authtime, error_code));175176static krb5_error_code177hack_init (void)178{179krb5_error_code c;180181c = krb5int_mutex_alloc (&krb5_db2_mutex);182if (c)183return c;184return krb5_db2_lib_init ();185}186187static krb5_error_code188hack_cleanup (void)189{190krb5int_mutex_free (krb5_db2_mutex);191krb5_db2_mutex = NULL;192return krb5_db2_lib_cleanup();193}194195196/*197* Exposed API198*/199200kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_db2, kdb_function_table) = {201KRB5_KDB_DAL_MAJOR_VERSION, /* major version number */2020, /* minor version number 0 */203/* init_library */ hack_init,204/* fini_library */ hack_cleanup,205/* init_module */ wrap_krb5_db2_open,206/* fini_module */ wrap_krb5_db2_fini,207/* create */ wrap_krb5_db2_create,208/* destroy */ wrap_krb5_db2_destroy,209/* get_age */ wrap_krb5_db2_get_age,210/* lock */ wrap_krb5_db2_lock,211/* unlock */ wrap_krb5_db2_unlock,212/* get_principal */ wrap_krb5_db2_get_principal,213/* put_principal */ wrap_krb5_db2_put_principal,214/* delete_principal */ wrap_krb5_db2_delete_principal,215/* rename_principal */ NULL,216/* iterate */ wrap_krb5_db2_iterate,217/* create_policy */ wrap_krb5_db2_create_policy,218/* get_policy */ wrap_krb5_db2_get_policy,219/* put_policy */ wrap_krb5_db2_put_policy,220/* iter_policy */ wrap_krb5_db2_iter_policy,221/* delete_policy */ wrap_krb5_db2_delete_policy,222/* fetch_master_key */ NULL,223/* fetch_master_key_list */ NULL,224/* store_master_key_list */ NULL,225/* dbe_search_enctype */ NULL,226/* change_pwd */ NULL,227/* promote_db */ wrap_krb5_db2_promote_db,228/* decrypt_key_data */ NULL,229/* encrypt_key_data */ NULL,230/* check_transited_realms */ NULL,231/* check_policy_as */ wrap_krb5_db2_check_policy_as,232/* check_policy_tgs */ NULL,233/* audit_as_req */ wrap_krb5_db2_audit_as_req,234};235236237