/*1* Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233/* $Id$ */3435#ifndef __HDB_H__36#define __HDB_H__3738#include <krb5.h>3940#include <hdb_err.h>4142#include <heim_asn1.h>43#include <hdb_asn1.h>4445struct hdb_dbinfo;4647enum hdb_lockop{ HDB_RLOCK, HDB_WLOCK };4849/* flags for various functions */50#define HDB_F_DECRYPT 1 /* decrypt keys */51#define HDB_F_REPLACE 2 /* replace entry */52#define HDB_F_GET_CLIENT 4 /* fetch client */53#define HDB_F_GET_SERVER 8 /* fetch server */54#define HDB_F_GET_KRBTGT 16 /* fetch krbtgt */55#define HDB_F_GET_ANY 28 /* fetch any of client,server,krbtgt */56#define HDB_F_CANON 32 /* want canonicalition */57#define HDB_F_ADMIN_DATA 64 /* want data that kdc don't use */58#define HDB_F_KVNO_SPECIFIED 128 /* we want a particular KVNO */59#define HDB_F_CURRENT_KVNO 256 /* we want the current KVNO */60/* 512, 1024, 2048 are reserved for kvno operations that is not part of the 1.5 branch */61#define HDB_F_ALL_KVNOS 2048 /* we want all the keys, live or not */62#define HDB_F_FOR_AS_REQ 4096 /* fetch is for a AS REQ */63#define HDB_F_FOR_TGS_REQ 8192 /* fetch is for a TGS REQ */6465/* hdb_capability_flags */66#define HDB_CAP_F_HANDLE_ENTERPRISE_PRINCIPAL 167#define HDB_CAP_F_HANDLE_PASSWORDS 268#define HDB_CAP_F_PASSWORD_UPDATE_KEYS 46970/* auth status values */71#define HDB_AUTH_SUCCESS 072#define HDB_AUTH_WRONG_PASSWORD 173#define HDB_AUTH_INVALID_SIGNATURE 27475/* key usage for master key */76#define HDB_KU_MKEY 0x4844427778typedef struct hdb_master_key_data *hdb_master_key;7980/**81* hdb_entry_ex is a wrapper structure around the hdb_entry structure82* that allows backends to keep a pointer to the backing store, ie in83* ->hdb_fetch_kvno(), so that we the kadmin/kpasswd backend gets around to84* ->hdb_store(), the backend doesn't need to lookup the entry again.85*/8687typedef struct hdb_entry_ex {88void *ctx;89hdb_entry entry;90void (*free_entry)(krb5_context, struct hdb_entry_ex *);91} hdb_entry_ex;929394/**95* HDB backend function pointer structure96*97* The HDB structure is what the KDC and kadmind framework uses to98* query the backend database when talking about principals.99*/100101typedef struct HDB{102void *hdb_db;103void *hdb_dbc; /** don't use, only for DB3 */104char *hdb_name;105int hdb_master_key_set;106hdb_master_key hdb_master_key;107int hdb_openp;108int hdb_capability_flags;109/**110* Open (or create) the a Kerberos database.111*112* Open (or create) the a Kerberos database that was resolved with113* hdb_create(). The third and fourth flag to the function are the114* same as open(), thus passing O_CREAT will create the data base115* if it doesn't exists.116*117* Then done the caller should call hdb_close(), and to release118* all resources hdb_destroy().119*/120krb5_error_code (*hdb_open)(krb5_context, struct HDB*, int, mode_t);121/**122* Close the database for transaction123*124* Closes the database for further transactions, wont release any125* permanant resources. the database can be ->hdb_open-ed again.126*/127krb5_error_code (*hdb_close)(krb5_context, struct HDB*);128/**129* Free an entry after use.130*/131void (*hdb_free)(krb5_context, struct HDB*, hdb_entry_ex*);132/**133* Fetch an entry from the backend134*135* Fetch an entry from the backend, flags are what type of entry136* should be fetch: client, server, krbtgt.137* knvo (if specified and flags HDB_F_KVNO_SPECIFIED set) is the kvno to get138*/139krb5_error_code (*hdb_fetch_kvno)(krb5_context, struct HDB*,140krb5_const_principal, unsigned, krb5_kvno,141hdb_entry_ex*);142/**143* Store an entry to database144*/145krb5_error_code (*hdb_store)(krb5_context, struct HDB*,146unsigned, hdb_entry_ex*);147/**148* Remove an entry from the database.149*/150krb5_error_code (*hdb_remove)(krb5_context, struct HDB*,151krb5_const_principal);152/**153* As part of iteration, fetch one entry154*/155krb5_error_code (*hdb_firstkey)(krb5_context, struct HDB*,156unsigned, hdb_entry_ex*);157/**158* As part of iteration, fetch next entry159*/160krb5_error_code (*hdb_nextkey)(krb5_context, struct HDB*,161unsigned, hdb_entry_ex*);162/**163* Lock database164*165* A lock can only be held by one consumers. Transaction can still166* happen on the database while the lock is held, so the entry is167* only useful for syncroning creation of the database and renaming of the database.168*/169krb5_error_code (*hdb_lock)(krb5_context, struct HDB*, int);170/**171* Unlock database172*/173krb5_error_code (*hdb_unlock)(krb5_context, struct HDB*);174/**175* Rename the data base.176*177* Assume that the database is not hdb_open'ed and not locked.178*/179krb5_error_code (*hdb_rename)(krb5_context, struct HDB*, const char*);180/**181* Get an hdb_entry from a classical DB backend182*183* If the database is a classical DB (ie BDB, NDBM, GDBM, etc)184* backend, this function will take a principal key (krb5_data)185* and return all data related to principal in the return186* krb5_data. The returned encoded entry is of type hdb_entry or187* hdb_entry_alias.188*/189krb5_error_code (*hdb__get)(krb5_context, struct HDB*,190krb5_data, krb5_data*);191/**192* Store an hdb_entry from a classical DB backend193*194* Same discussion as in @ref HDB::hdb__get195*/196krb5_error_code (*hdb__put)(krb5_context, struct HDB*, int,197krb5_data, krb5_data);198/**199* Delete and hdb_entry from a classical DB backend200*201* Same discussion as in @ref HDB::hdb__get202*/203krb5_error_code (*hdb__del)(krb5_context, struct HDB*, krb5_data);204/**205* Destroy the handle to the database.206*207* Destroy the handle to the database, deallocate all memory and208* related resources. Does not remove any permanent data. Its the209* logical reverse of hdb_create() function that is the entry210* point for the module.211*/212krb5_error_code (*hdb_destroy)(krb5_context, struct HDB*);213/**214* Get the list of realms this backend handles.215* This call is optional to support. The returned realms are used216* for announcing the realms over bonjour. Free returned array217* with krb5_free_host_realm().218*/219krb5_error_code (*hdb_get_realms)(krb5_context, struct HDB *, krb5_realm **);220/**221* Change password.222*223* Will update keys for the entry when given password. The new224* keys must be written into the entry and will then later be225* ->hdb_store() into the database. The backend will still perform226* all other operations, increasing the kvno, and update227* modification timestamp.228*229* The backend needs to call _kadm5_set_keys() and perform password230* quality checks.231*/232krb5_error_code (*hdb_password)(krb5_context, struct HDB*, hdb_entry_ex*, const char *, int);233234/**235* Auth feedback236*237* This is a feedback call that allows backends that provides238* lockout functionality to register failure and/or successes.239*240* In case the entry is locked out, the backend should set the241* hdb_entry.flags.locked-out flag.242*/243krb5_error_code (*hdb_auth_status)(krb5_context, struct HDB *, hdb_entry_ex *, int);244/**245* Check if delegation is allowed.246*/247krb5_error_code (*hdb_check_constrained_delegation)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal);248249/**250* Check if this name is an alias for the supplied client for PKINIT userPrinicpalName logins251*/252krb5_error_code (*hdb_check_pkinit_ms_upn_match)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal);253254/**255* Check if s4u2self is allowed from this client to this server256*/257krb5_error_code (*hdb_check_s4u2self)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal);258}HDB;259260#define HDB_INTERFACE_VERSION 7261262struct hdb_so_method {263int version;264const char *prefix;265krb5_error_code (*create)(krb5_context, HDB **, const char *filename);266};267268typedef krb5_error_code (*hdb_foreach_func_t)(krb5_context, HDB*,269hdb_entry_ex*, void*);270extern krb5_kt_ops hdb_kt_ops;271272struct hdb_method {273int interface_version;274const char *prefix;275krb5_error_code (*create)(krb5_context, HDB **, const char *filename);276};277278extern const int hdb_interface_version;279280#include <hdb-protos.h>281282#endif /* __HDB_H__ */283284285