1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * Copyright 1990,1991 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 * Copyright (C) 1998 by the FundsXpress, INC.
28 * All rights reserved.
30 * Export of this software from the United States of America may require
31 * a specific license from the United States Government. It is the
32 * responsibility of any person or organization contemplating export to
33 * obtain such a license before exporting.
35 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
36 * distribute this software and its documentation for any purpose and
37 * without fee is hereby granted, provided that the above copyright
38 * notice appear in all copies and that both that copyright notice and
39 * this permission notice appear in supporting documentation, and that
40 * the name of FundsXpress. not be used in advertising or publicity pertaining
41 * to distribution of the software without specific, written prior
42 * permission. FundsXpress makes no representations about the suitability of
43 * this software for any purpose. It is provided "as is" without express
44 * or implied warranty.
46 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
48 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
51 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
52 * Use is subject to license terms.
55 /* KDC Database interface definitions */
57 /* This API is not considered as stable as the main krb5 API.
59 * - We may make arbitrary incompatible changes between feature
60 * releases (e.g. from 1.7 to 1.8).
61 * - We will make some effort to avoid making incompatible changes for
62 * bugfix releases, but will make them if necessary.
70 /* This version will be incremented when incompatible changes are made to the
71 * KDB API, and will be kept in sync with the libkdb major version. */
72 #define KRB5_KDB_API_VERSION 6
75 #define KRB5_KDB_SALTTYPE_NORMAL 0
76 #define KRB5_KDB_SALTTYPE_V4 1
77 #define KRB5_KDB_SALTTYPE_NOREALM 2
78 #define KRB5_KDB_SALTTYPE_ONLYREALM 3
79 #define KRB5_KDB_SALTTYPE_SPECIAL 4
80 #define KRB5_KDB_SALTTYPE_AFS3 5
81 #define KRB5_KDB_SALTTYPE_CERTHASH 6
84 #define KRB5_KDB_DISALLOW_POSTDATED 0x00000001
85 #define KRB5_KDB_DISALLOW_FORWARDABLE 0x00000002
86 #define KRB5_KDB_DISALLOW_TGT_BASED 0x00000004
87 #define KRB5_KDB_DISALLOW_RENEWABLE 0x00000008
88 #define KRB5_KDB_DISALLOW_PROXIABLE 0x00000010
89 #define KRB5_KDB_DISALLOW_DUP_SKEY 0x00000020
90 #define KRB5_KDB_DISALLOW_ALL_TIX 0x00000040
91 #define KRB5_KDB_REQUIRES_PRE_AUTH 0x00000080
92 #define KRB5_KDB_REQUIRES_HW_AUTH 0x00000100
93 #define KRB5_KDB_REQUIRES_PWCHANGE 0x00000200
94 #define KRB5_KDB_DISALLOW_SVR 0x00001000
95 #define KRB5_KDB_PWCHANGE_SERVICE 0x00002000
96 #define KRB5_KDB_SUPPORT_DESMD5 0x00004000
97 #define KRB5_KDB_NEW_PRINC 0x00008000
98 #define KRB5_KDB_OK_AS_DELEGATE 0x00100000
99 #define KRB5_KDB_OK_TO_AUTH_AS_DELEGATE 0x00200000 /* S4U2Self OK */
100 #define KRB5_KDB_NO_AUTH_DATA_REQUIRED 0x00400000
103 #define KRB5_KDB_CREATE_BTREE 0x00000001
104 #define KRB5_KDB_CREATE_HASH 0x00000002
106 /* Private flag used to indicate principal is local TGS */
107 #define KRB5_KDB_TICKET_GRANTING_SERVICE 0x01000000
108 /* Private flag used to indicate xrealm relationship is non-transitive */
109 #define KRB5_KDB_XREALM_NON_TRANSITIVE 0x02000000
111 /* Entry get flags */
112 /* Name canonicalization requested */
113 #define KRB5_KDB_FLAG_CANONICALIZE 0x00000010
114 /* Include authorization data generated by backend */
115 #define KRB5_KDB_FLAG_INCLUDE_PAC 0x00000020
116 /* Is AS-REQ (client referrals only) */
117 #define KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY 0x00000040
118 /* Map cross-realm principals */
119 #define KRB5_KDB_FLAG_MAP_PRINCIPALS 0x00000080
120 /* Protocol transition */
121 #define KRB5_KDB_FLAG_PROTOCOL_TRANSITION 0x00000100
122 /* Constrained delegation */
123 #define KRB5_KDB_FLAG_CONSTRAINED_DELEGATION 0x00000200
125 #define KRB5_KDB_FLAG_USER_TO_USER 0x00000800
127 #define KRB5_KDB_FLAG_CROSS_REALM 0x00001000
128 /* Allow in-realm aliases */
129 #define KRB5_KDB_FLAG_ALIAS_OK 0x00002000
131 #define KRB5_KDB_FLAGS_S4U ( KRB5_KDB_FLAG_PROTOCOL_TRANSITION | \
132 KRB5_KDB_FLAG_CONSTRAINED_DELEGATION )
137 * Note --- these structures cannot be modified without changing the
138 * database version number in libkdb.a, but should be expandable by
139 * adding new tl_data types.
141 typedef struct _krb5_tl_data {
142 struct _krb5_tl_data* tl_data_next; /* NOT saved */
143 krb5_int16 tl_data_type;
144 krb5_ui_2 tl_data_length;
145 krb5_octet * tl_data_contents;
148 /* String attributes (currently stored inside tl-data) map C string keys to
149 * values. They can be set via kadmin and consumed by KDC plugins. */
150 typedef struct krb5_string_attr_st {
156 * If this ever changes up the version number and make the arrays be as
159 * Currently the first type is the enctype and the second is the salt type.
161 typedef struct _krb5_key_data {
162 krb5_int16 key_data_ver; /* Version */
163 krb5_int16 key_data_kvno; /* Key Version */
164 krb5_int16 key_data_type[2]; /* Array of types */
165 krb5_ui_2 key_data_length[2]; /* Array of lengths */
166 krb5_octet * key_data_contents[2]; /* Array of pointers */
169 #define KRB5_KDB_V1_KEY_DATA_ARRAY 2 /* # of array elements */
171 typedef struct _krb5_keysalt {
173 krb5_data data; /* Length, data */
177 * A principal database entry. Extensions to this structure currently use the
178 * tl_data list. The e_data and e_length fields are not used by any calling
179 * code except kdb5_util dump and load, which marshal and unmarshal the array
180 * in the dump record. KDB modules may use these fields internally as long as
181 * they set e_length appropriately (non-zero if the data should be marshalled
182 * across dump and load, zero if not) and handle null e_data values in
183 * caller-constructed principal entries.
185 typedef struct _krb5_db_entry_new {
186 krb5_magic magic; /* NOT saved */
188 krb5_ui_4 mask; /* members currently changed/set */
189 krb5_flags attributes;
190 krb5_deltat max_life;
191 krb5_deltat max_renewable_life;
192 krb5_timestamp expiration; /* When the client expires */
193 krb5_timestamp pw_expiration; /* When its passwd expires */
194 krb5_timestamp last_success; /* Last successful passwd */
195 krb5_timestamp last_failed; /* Last failed passwd attempt */
196 krb5_kvno fail_auth_count; /* # of failed passwd attempt */
197 krb5_int16 n_tl_data;
198 krb5_int16 n_key_data;
199 krb5_ui_2 e_length; /* Length of extra data */
200 krb5_octet * e_data; /* Extra data to be saved */
202 krb5_principal princ; /* Length, data */
203 krb5_tl_data * tl_data; /* Linked list */
204 krb5_key_data * key_data; /* Array */
207 typedef struct _osa_policy_ent_t {
210 krb5_ui_4 pw_min_life;
211 krb5_ui_4 pw_max_life;
212 krb5_ui_4 pw_min_length;
213 krb5_ui_4 pw_min_classes;
214 krb5_ui_4 pw_history_num;
215 krb5_ui_4 policy_refcnt;
216 /* Only valid if version > 1 */
217 krb5_ui_4 pw_max_fail; /* pwdMaxFailure */
218 krb5_ui_4 pw_failcnt_interval; /* pwdFailureCountInterval */
219 krb5_ui_4 pw_lockout_duration; /* pwdLockoutDuration */
220 } osa_policy_ent_rec, *osa_policy_ent_t;
222 typedef void (*osa_adb_iter_policy_func) (void *, osa_policy_ent_t);
224 typedef struct __krb5_key_salt_tuple {
225 krb5_enctype ks_enctype;
226 krb5_int32 ks_salttype;
227 } krb5_key_salt_tuple;
229 #define KRB5_KDB_MAGIC_NUMBER 0xdbdbdbdb
230 #define KRB5_KDB_V1_BASE_LENGTH 38
232 #define KRB5_TL_LAST_PWD_CHANGE 0x0001
233 #define KRB5_TL_MOD_PRINC 0x0002
234 #define KRB5_TL_KADM_DATA 0x0003
235 #define KRB5_TL_KADM5_E_DATA 0x0004
236 #define KRB5_TL_RB1_CHALLENGE 0x0005
238 #define KRB5_TL_SECURID_STATE 0x0006
240 #define KRB5_TL_USER_CERTIFICATE 0x0007
241 #define KRB5_TL_MKVNO 0x0008
242 #define KRB5_TL_ACTKVNO 0x0009
243 #define KRB5_TL_MKEY_AUX 0x000a
245 /* String attributes may not always be represented in tl-data. kadmin clients
246 * must use the get_strings and set_string RPCs. */
247 #define KRB5_TL_STRING_ATTRS 0x000b
249 #define KRB5_TL_PAC_LOGON_INFO 0x0100 /* NDR encoded validation info */
250 #define KRB5_TL_SERVER_REFERRAL 0x0200 /* ASN.1 encoded ServerReferralInfo */
251 #define KRB5_TL_SVR_REFERRAL_DATA 0x0300 /* ASN.1 encoded PA-SVR-REFERRAL-DATA */
252 #define KRB5_TL_CONSTRAINED_DELEGATION_ACL 0x0400 /* Each entry is a permitted SPN */
253 #define KRB5_TL_LM_KEY 0x0500 /* LM OWF */
254 #define KRB5_TL_X509_SUBJECT_ISSUER_NAME 0x0600 /* <I>IssuerDN<S>SubjectDN */
255 #define KRB5_TL_LAST_ADMIN_UNLOCK 0x0700 /* Timestamp of admin unlock */
257 #define KRB5_TL_DB_ARGS 0x7fff
259 /* version number for KRB5_TL_ACTKVNO data */
260 #define KRB5_TL_ACTKVNO_VER 1
262 /* version number for KRB5_TL_MKEY_AUX data */
263 #define KRB5_TL_MKEY_AUX_VER 1
265 typedef struct _krb5_actkvno_node {
266 struct _krb5_actkvno_node *next;
268 krb5_timestamp act_time;
271 typedef struct _krb5_mkey_aux_node {
272 struct _krb5_mkey_aux_node *next;
273 krb5_kvno mkey_kvno; /* kvno of mkey protecting the latest_mkey */
274 krb5_key_data latest_mkey; /* most recent mkey */
275 } krb5_mkey_aux_node;
277 typedef struct _krb5_keylist_node {
278 krb5_keyblock keyblock;
280 struct _krb5_keylist_node *next;
284 * Determines the number of failed KDC requests before DISALLOW_ALL_TIX is set
287 #define KRB5_MAX_FAIL_COUNT 5
289 /* XXX depends on knowledge of krb5_parse_name() formats */
290 #define KRB5_KDB_M_NAME "K/M" /* Kerberos/Master */
292 /* prompts used by default when reading the KDC password from the keyboard. */
293 #define KRB5_KDC_MKEY_1 "Enter KDC database master key"
294 #define KRB5_KDC_MKEY_2 "Re-enter KDC database master key to verify"
297 extern char *krb5_mkey_pwd_prompt1;
298 extern char *krb5_mkey_pwd_prompt2;
301 * These macros specify the encoding of data within the database.
303 * Data encoding is little-endian.
306 #include "k5-platform.h"
307 #define krb5_kdb_decode_int16(cp, i16) \
308 *((krb5_int16 *) &(i16)) = load_16_le(cp)
309 #define krb5_kdb_decode_int32(cp, i32) \
310 *((krb5_int32 *) &(i32)) = load_32_le(cp)
311 #define krb5_kdb_encode_int16(i16, cp) store_16_le(i16, cp)
312 #define krb5_kdb_encode_int32(i32, cp) store_32_le(i32, cp)
313 #endif /* _KRB5_INT_H */
315 #define KRB5_KDB_OPEN_RW 0
316 #define KRB5_KDB_OPEN_RO 1
318 #ifndef KRB5_KDB_SRV_TYPE_KDC
319 #define KRB5_KDB_SRV_TYPE_KDC 0x0100
322 #ifndef KRB5_KDB_SRV_TYPE_ADMIN
323 #define KRB5_KDB_SRV_TYPE_ADMIN 0x0200
326 #ifndef KRB5_KDB_SRV_TYPE_PASSWD
327 #define KRB5_KDB_SRV_TYPE_PASSWD 0x0300
330 #ifndef KRB5_KDB_SRV_TYPE_OTHER
331 #define KRB5_KDB_SRV_TYPE_OTHER 0x0400
334 #define KRB5_KDB_OPT_SET_DB_NAME 0
335 #define KRB5_KDB_OPT_SET_LOCK_MODE 1
337 #define KRB5_DB_LOCKMODE_SHARED 0x0001
338 #define KRB5_DB_LOCKMODE_EXCLUSIVE 0x0002
339 #define KRB5_DB_LOCKMODE_DONTBLOCK 0x0004
340 #define KRB5_DB_LOCKMODE_PERMANENT 0x0008
343 krb5_error_code krb5_db_setup_lib_handle(krb5_context kcontext);
344 krb5_error_code krb5_db_open( krb5_context kcontext, char **db_args, int mode );
345 krb5_error_code krb5_db_init ( krb5_context kcontext );
346 krb5_error_code krb5_db_create ( krb5_context kcontext, char **db_args );
347 krb5_error_code krb5_db_inited ( krb5_context kcontext );
348 krb5_error_code kdb5_db_create ( krb5_context kcontext, char **db_args );
349 krb5_error_code krb5_db_fini ( krb5_context kcontext );
350 const char * krb5_db_errcode2string ( krb5_context kcontext, long err_code );
351 krb5_error_code krb5_db_destroy ( krb5_context kcontext, char **db_args );
352 krb5_error_code krb5_db_promote ( krb5_context kcontext, char **db_args );
353 krb5_error_code krb5_db_get_age ( krb5_context kcontext, char *db_name, time_t *t );
354 krb5_error_code krb5_db_lock ( krb5_context kcontext, int lock_mode );
355 krb5_error_code krb5_db_unlock ( krb5_context kcontext );
356 krb5_error_code krb5_db_get_principal ( krb5_context kcontext,
357 krb5_const_principal search_for,
359 krb5_db_entry **entry );
360 void krb5_db_free_principal ( krb5_context kcontext, krb5_db_entry *entry );
361 krb5_error_code krb5_db_put_principal ( krb5_context kcontext,
362 krb5_db_entry *entry );
363 krb5_error_code krb5_db_delete_principal ( krb5_context kcontext,
364 krb5_principal search_for );
365 krb5_error_code krb5_db_iterate ( krb5_context kcontext,
367 int (*func) (krb5_pointer, krb5_db_entry *),
368 krb5_pointer func_arg );
371 krb5_error_code krb5_db_store_master_key ( krb5_context kcontext,
373 krb5_principal mname,
377 krb5_error_code krb5_db_store_master_key_list ( krb5_context kcontext,
379 krb5_principal mname,
381 krb5_error_code krb5_db_fetch_mkey ( krb5_context context,
382 krb5_principal mname,
384 krb5_boolean fromkeyboard,
391 krb5_db_fetch_mkey_list( krb5_context context,
392 krb5_principal mname,
393 const krb5_keyblock * mkey );
396 krb5_dbe_find_enctype( krb5_context kcontext,
397 krb5_db_entry *dbentp,
401 krb5_key_data **kdatap);
404 krb5_error_code krb5_dbe_search_enctype ( krb5_context kcontext,
405 krb5_db_entry *dbentp,
410 krb5_key_data **kdatap);
413 krb5_db_setup_mkey_name ( krb5_context context,
417 krb5_principal *principal);
420 * Decrypts the key given in @@a key_data. If @a mkey is specified, that
421 * master key is used. If @a mkey is NULL, then all master keys are tried.
424 krb5_dbe_decrypt_key_data( krb5_context context,
425 const krb5_keyblock * mkey,
426 const krb5_key_data * key_data,
427 krb5_keyblock * dbkey,
428 krb5_keysalt * keysalt);
431 krb5_dbe_encrypt_key_data( krb5_context context,
432 const krb5_keyblock * mkey,
433 const krb5_keyblock * dbkey,
434 const krb5_keysalt * keysalt,
436 krb5_key_data * key_data);
439 krb5_dbe_fetch_act_key_list(krb5_context context,
440 krb5_principal princ,
441 krb5_actkvno_node **act_key_list);
444 krb5_dbe_find_act_mkey( krb5_context context,
445 krb5_actkvno_node * act_mkey_list,
446 krb5_kvno * act_kvno,
447 krb5_keyblock ** act_mkey);
450 krb5_dbe_find_mkey( krb5_context context,
451 krb5_db_entry * entry,
452 krb5_keyblock ** mkey);
454 /* Set *mkvno to mkvno in entry tl_data, or 0 if not present. */
456 krb5_dbe_lookup_mkvno( krb5_context context,
457 krb5_db_entry * entry,
461 krb5_db_mkey_list_alias( krb5_context kcontext );
463 /* Set *mkvno to mkvno in entry tl_data, or minimum value from mkey_list. */
465 krb5_dbe_get_mkvno( krb5_context context,
466 krb5_db_entry * entry,
470 krb5_dbe_lookup_mod_princ_data( krb5_context context,
471 krb5_db_entry * entry,
472 krb5_timestamp * mod_time,
473 krb5_principal * mod_princ);
476 krb5_dbe_lookup_mkey_aux( krb5_context context,
477 krb5_db_entry * entry,
478 krb5_mkey_aux_node ** mkey_aux_data_list);
480 krb5_dbe_update_mkvno( krb5_context context,
481 krb5_db_entry * entry,
485 krb5_dbe_lookup_actkvno( krb5_context context,
486 krb5_db_entry * entry,
487 krb5_actkvno_node ** actkvno_list);
490 krb5_dbe_update_mkey_aux( krb5_context context,
491 krb5_db_entry * entry,
492 krb5_mkey_aux_node * mkey_aux_data_list);
495 krb5_dbe_update_actkvno(krb5_context context,
496 krb5_db_entry * entry,
497 const krb5_actkvno_node *actkvno_list);
500 krb5_dbe_update_last_pwd_change( krb5_context context,
501 krb5_db_entry * entry,
502 krb5_timestamp stamp);
505 krb5_dbe_update_last_admin_unlock( krb5_context context,
506 krb5_db_entry * entry,
507 krb5_timestamp stamp);
510 krb5_dbe_lookup_tl_data( krb5_context context,
511 krb5_db_entry * entry,
512 krb5_tl_data * ret_tl_data);
515 krb5_dbe_create_key_data( krb5_context context,
516 krb5_db_entry * entry);
520 krb5_dbe_update_mod_princ_data( krb5_context context,
521 krb5_db_entry * entry,
522 krb5_timestamp mod_date,
523 krb5_const_principal mod_princ);
525 void *krb5_db_alloc( krb5_context kcontext,
529 void krb5_db_free( krb5_context kcontext,
534 krb5_dbe_lookup_last_pwd_change( krb5_context context,
535 krb5_db_entry * entry,
536 krb5_timestamp * stamp);
539 krb5_dbe_lookup_last_admin_unlock( krb5_context context,
540 krb5_db_entry * entry,
541 krb5_timestamp * stamp);
543 /* Retrieve the set of string attributes in entry, in no particular order.
544 * Free *strings_out with krb5_dbe_free_strings when done. */
546 krb5_dbe_get_strings(krb5_context context, krb5_db_entry *entry,
547 krb5_string_attr **strings_out, int *count_out);
549 /* Retrieve a single string attribute from entry, or NULL if there is no
550 * attribute for key. Free *value_out with krb5_dbe_free_string when done. */
552 krb5_dbe_get_string(krb5_context context, krb5_db_entry *entry,
553 const char *key, char **value_out);
555 /* Change or add a string attribute in entry, or delete it if value is NULL. */
557 krb5_dbe_set_string(krb5_context context, krb5_db_entry *entry,
558 const char *key, const char *value);
561 krb5_dbe_delete_tl_data( krb5_context context,
562 krb5_db_entry * entry,
563 krb5_int16 tl_data_type);
566 krb5_dbe_update_tl_data( krb5_context context,
567 krb5_db_entry * entry,
568 krb5_tl_data * new_tl_data);
570 /* Compute the salt for a key data entry given the corresponding principal. */
572 krb5_dbe_compute_salt(krb5_context context, const krb5_key_data *key,
573 krb5_const_principal princ, krb5_int16 *salttype_out,
574 krb5_data **salt_out);
577 krb5_dbe_cpw( krb5_context kcontext,
578 krb5_keyblock * master_key,
579 krb5_key_salt_tuple * ks_tuple,
583 krb5_boolean keepold,
584 krb5_db_entry * db_entry);
588 krb5_dbe_ark( krb5_context context,
589 krb5_keyblock * master_key,
590 krb5_key_salt_tuple * ks_tuple,
592 krb5_db_entry * db_entry);
595 krb5_dbe_crk( krb5_context context,
596 krb5_keyblock * master_key,
597 krb5_key_salt_tuple * ks_tuple,
599 krb5_boolean keepold,
600 krb5_db_entry * db_entry);
603 krb5_dbe_apw( krb5_context context,
604 krb5_keyblock * master_key,
605 krb5_key_salt_tuple * ks_tuple,
608 krb5_db_entry * db_entry);
611 krb5_db_get_key_data_kvno( krb5_context context,
613 krb5_key_data * data);
615 krb5_error_code krb5_db_sign_authdata(krb5_context kcontext,
617 krb5_const_principal client_princ,
618 krb5_db_entry *client,
619 krb5_db_entry *server,
620 krb5_db_entry *krbtgt,
621 krb5_keyblock *client_key,
622 krb5_keyblock *server_key,
623 krb5_keyblock *krbtgt_key,
624 krb5_keyblock *session_key,
625 krb5_timestamp authtime,
626 krb5_authdata **tgt_auth_data,
627 krb5_authdata ***signed_auth_data);
629 krb5_error_code krb5_db_check_transited_realms(krb5_context kcontext,
630 const krb5_data *tr_contents,
631 const krb5_data *client_realm,
632 const krb5_data *server_realm);
634 krb5_error_code krb5_db_check_policy_as(krb5_context kcontext,
635 krb5_kdc_req *request,
636 krb5_db_entry *client,
637 krb5_db_entry *server,
638 krb5_timestamp kdc_time,
640 krb5_pa_data ***e_data);
642 krb5_error_code krb5_db_check_policy_tgs(krb5_context kcontext,
643 krb5_kdc_req *request,
644 krb5_db_entry *server,
647 krb5_pa_data ***e_data);
649 void krb5_db_audit_as_req(krb5_context kcontext, krb5_kdc_req *request,
650 krb5_db_entry *client, krb5_db_entry *server,
651 krb5_timestamp authtime, krb5_error_code error_code);
653 void krb5_db_refresh_config(krb5_context kcontext);
655 krb5_error_code krb5_db_check_allowed_to_delegate(krb5_context kcontext,
656 krb5_const_principal client,
657 const krb5_db_entry *server,
658 krb5_const_principal proxy);
660 /* default functions. Should not be directly called */
662 * Default functions prototype
666 krb5_dbe_def_search_enctype( krb5_context kcontext,
667 krb5_db_entry *dbentp,
672 krb5_key_data **kdatap);
675 krb5_def_store_mkey_list( krb5_context context,
677 krb5_principal mname,
678 krb5_keylist_node *keylist,
682 krb5_db_def_fetch_mkey( krb5_context context,
683 krb5_principal mname,
689 krb5_def_fetch_mkey_list( krb5_context context,
690 krb5_principal mprinc,
691 const krb5_keyblock *mkey,
692 krb5_keylist_node **mkeys_list);
695 krb5_dbe_def_cpw( krb5_context context,
696 krb5_keyblock * master_key,
697 krb5_key_salt_tuple * ks_tuple,
701 krb5_boolean keepold,
702 krb5_db_entry * db_entry);
705 krb5_dbe_def_decrypt_key_data( krb5_context context,
706 const krb5_keyblock * mkey,
707 const krb5_key_data * key_data,
708 krb5_keyblock * dbkey,
709 krb5_keysalt * keysalt);
712 krb5_dbe_def_encrypt_key_data( krb5_context context,
713 const krb5_keyblock * mkey,
714 const krb5_keyblock * dbkey,
715 const krb5_keysalt * keysalt,
717 krb5_key_data * key_data);
720 krb5_db_create_policy( krb5_context kcontext,
721 osa_policy_ent_t policy);
724 krb5_db_get_policy ( krb5_context kcontext,
726 osa_policy_ent_t *policy );
729 krb5_db_put_policy( krb5_context kcontext,
730 osa_policy_ent_t policy);
733 krb5_db_iter_policy( krb5_context kcontext,
735 osa_adb_iter_policy_func func,
739 krb5_db_delete_policy( krb5_context kcontext,
743 krb5_db_free_policy( krb5_context kcontext,
744 osa_policy_ent_t policy);
748 krb5_db_set_context(krb5_context, void *db_context);
751 krb5_db_get_context(krb5_context, void **db_context);
754 krb5_dbe_free_key_data_contents(krb5_context, krb5_key_data *);
757 krb5_dbe_free_key_list(krb5_context, krb5_keylist_node *);
760 krb5_dbe_free_actkvno_list(krb5_context, krb5_actkvno_node *);
763 krb5_dbe_free_mkey_aux_list(krb5_context, krb5_mkey_aux_node *);
766 krb5_dbe_free_tl_data(krb5_context, krb5_tl_data *);
769 krb5_dbe_free_strings(krb5_context, krb5_string_attr *, int count);
772 krb5_dbe_free_string(krb5_context, char *);
774 #define KRB5_KDB_DEF_FLAGS 0
776 #define KDB_MAX_DB_NAME 128
777 #define KDB_REALM_SECTION "realms"
778 #define KDB_MODULE_POINTER "database_module"
779 #define KDB_MODULE_DEF_SECTION "dbdefaults"
780 #define KDB_MODULE_SECTION "dbmodules"
781 #define KDB_LIB_POINTER "db_library"
782 #define KDB_DATABASE_CONF_FILE DEFAULT_SECURE_PROFILE_PATH
783 #define KDB_DATABASE_ENV_PROF KDC_PROFILE_ENV
785 #define KRB5_KDB_OPEN_RW 0
786 #define KRB5_KDB_OPEN_RO 1
788 #define KRB5_KDB_OPT_SET_DB_NAME 0
789 #define KRB5_KDB_OPT_SET_LOCK_MODE 1
792 * This number indicates the date of the last incompatible change to the DAL.
793 * The maj_ver field of the module's vtable structure must match this version.
795 #define KRB5_KDB_DAL_MAJOR_VERSION 3
798 * A krb5_context can hold one database object. Modules should use
799 * krb5_db_set_context and krb5_db_get_context to store state associated with
800 * the database object.
802 * Some module functions are mandatory for KDC operation; others are optional
803 * or apply only to administrative operations. If a function is optional, a
804 * module can leave the function pointer as NULL. Alternatively, modules can
805 * return KRB5_PLUGIN_OP_NOTSUPP when asked to perform an inapplicable action.
807 * Some module functions have default implementations which will call back into
808 * the vtable interface. Leave these functions as NULL to use the default
811 * The documentation in these comments describes the DAL as it is currently
812 * implemented and used, not as it should be. So if anything seems off, that
813 * probably means the current state of things is off.
816 typedef struct _kdb_vftabl {
821 * Mandatory: Invoked after the module library is loaded, when the first DB
822 * using the module is opened, across all contexts.
824 krb5_error_code (*init_library)(void);
827 * Mandatory: Invoked before the module library is unloaded, after the last
828 * DB using the module is closed, across all contexts.
830 krb5_error_code (*fini_library)(void);
833 * Mandatory: Initialize a database object. Profile settings should be
834 * read from conf_section inside KDB_MODULE_SECTION. db_args communicates
835 * command-line arguments for module-specific flags. mode will be one of
836 * KRB5_KDB_OPEN_{RW,RO} or'd with one of
837 * KRB5_KDB_SRV_TYPE_{KDC,ADMIN,PASSWD,OTHER}.
839 krb5_error_code (*init_module)(krb5_context kcontext, char *conf_section,
840 char **db_args, int mode);
843 * Mandatory: Finalize the database object contained in a context. Free
844 * any state contained in the db_context pointer and null it out.
846 krb5_error_code (*fini_module)(krb5_context kcontext);
849 * Optional: Initialize a database object while creating the underlying
850 * database. conf_section and db_args have the same meaning as in
851 * init_module. This function may return an error if the database already
852 * exists. Used by kdb5_util create.
854 * If db_args contains the value "temporary", the module should create an
855 * exclusively locked side copy of the database suitable for loading in a
856 * propagation from master to slave. This side copy will later be promoted
857 * with promote_db, allowing complete updates of the DB with no loss in
858 * read availability. If the module cannot comply with this architecture,
859 * it should return an error.
861 krb5_error_code (*create)(krb5_context kcontext, char *conf_section,
865 * Optional: Destroy a database. conf_section and db_args have the same
866 * meaning as in init_module. Used by kdb5_util destroy. In current
867 * usage, the database is destroyed while open, so the module should handle
870 krb5_error_code (*destroy)(krb5_context kcontext, char *conf_section,
874 * Deprecated: No longer used as of krb5 1.10; can be removed in the next
875 * DAL revision. Modules should leave as NULL.
877 krb5_error_code (*get_age)(krb5_context kcontext, char *db_name,
881 * Optional: Lock the database, with semantics depending on the mode
884 * KRB5_DB_LOCKMODE_SHARED: Lock may coexist with other shared locks.
885 * KRB5_DB_LOCKMODE_EXCLUSIVE: Lock may not coexist with other locks.
886 * KRB5_DB_LOCKMODE_PERMANENT: Exclusive lock surviving process exit.
887 * (KRB5_DB_LOCKMODE_DONTBLOCK is unused and unimplemented.)
889 * Used by the "kadmin lock" command, incremental propagation, and
890 * kdb5_util dump. Incremental propagation support requires shared locks
891 * to operate. kdb5_util dump will continue unlocked if the module returns
892 * KRB5_PLUGIN_OP_NOTSUPP.
894 krb5_error_code (*lock)(krb5_context kcontext, int mode);
896 /* Optional: Release a lock created with db_lock. */
897 krb5_error_code (*unlock)(krb5_context kcontext);
900 * Mandatory: Set *entry to an allocated entry for the principal
901 * search_for. If the principal is not found, return KRB5_KDB_NOENTRY.
903 * The meaning of flags are as follows:
905 * KRB5_KDB_FLAG_CANONICALIZE: Set by the KDC when looking up entries for
906 * an AS or TGS request with canonicalization requested. Determines
907 * whether the module should return out-of-realm referrals.
909 * KRB5_KDB_FLAG_INCLUDE_PAC: Set by the KDC during an AS request when the
910 * client requested PAC information during padata, and during most TGS
911 * requests. Indicates that the module should include PAC information
912 * when its sign_authdata method is invoked.
914 * KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY: Set by the KDC when looking up the
915 * client entry in an AS request. Affects how the module should return
916 * out-of-realm referrals.
918 * KRB5_KDB_FLAG_MAP_PRINCIPALS: Set by the KDC when looking up the client
919 * entry during TGS requests, except for S4U TGS requests and requests
920 * where the server entry has the KRB5_KDB_NO_AUTH_DATA_REQUIRED
921 * attribute. Indicates that the module should map foreign principals
922 * to local principals if it supports doing so.
924 * KRB5_KDB_FLAG_PROTOCOL_TRANSITION: Set by the KDC when looking up the
925 * client entry during an S4U2Self TGS request. This affects the PAC
926 * information which should be included when authorization data is
927 * generated; see the Microsoft S4U specification for details.
929 * KRB5_KDB_FLAG_CONSTRAINED_DELEGATION: Set by the KDC when looking up the
930 * client entry during an S4U2Proxy TGS request. Also affects PAC
933 * KRB5_KDB_FLAG_CROSS_REALM: Set by the KDC when looking up a client entry
934 * during a TGS request, if the client principal is not part of the
935 * realm being served.
937 * KRB5_KDB_FLAG_ALIAS_OK: Set by the KDC for server principal lookups and
938 * for AS request client principal lookups with canonicalization
939 * requested; also set by the admin interface. Determines whether the
940 * module should return in-realm aliases.
942 * A module can return in-realm aliases if KRB5_KDB_FLAG_ALIAS_OK is set.
943 * To return an in-realm alias, fill in a different value for
944 * entries->princ than the one requested.
946 * A module can return out-of-realm referrals if KRB5_KDB_FLAG_CANONICALIZE
947 * is set. For AS request clients (KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY is
948 * also set), the module should do so by simply filling in an out-of-realm
949 * name in entries->princ and setting all other fields to NULL. Otherwise,
950 * the module should return the entry for the cross-realm TGS of the
951 * referred-to realm. For TGS referals, the module can also include
952 * tl-data of type KRB5_TL_SERVER_REFERRAL containing ASN.1-encoded Windows
953 * referral data as documented in draft-ietf-krb-wg-kerberos-referrals-11
954 * appendix A; this will be returned to the client as encrypted padata.
956 krb5_error_code (*get_principal)(krb5_context kcontext,
957 krb5_const_principal search_for,
959 krb5_db_entry **entry);
962 * Mandatory: Free a database entry. The entry may have been constructed
963 * by the caller (using the db_alloc function to allocate associated
964 * memory); thus, a plugin must allocate each field of a principal entry
967 void (*free_principal)(krb5_context kcontext, krb5_db_entry *entry);
970 * Optional: Create or modify a principal entry. db_args communicates
971 * command-line arguments for module-specific flags.
973 * The mask field of an entry indicates the changed fields. Mask values
974 * are defined in kadmin's admin.h header. If KADM5_PRINCIPAL is set in
975 * the mask, the entry is new; otherwise it already exists. All fields of
976 * an entry are expected to contain correct values, regardless of whether
977 * they are specified in the mask, so it is acceptable for a module to
978 * ignore the mask and update the entire entry.
980 krb5_error_code (*put_principal)(krb5_context kcontext,
981 krb5_db_entry *entry, char **db_args);
984 * Optional: Delete the entry for the principal search_for. If the
985 * principal did not exist, return KRB5_KDB_NOENTRY.
987 krb5_error_code (*delete_principal)(krb5_context kcontext,
988 krb5_const_principal search_for);
991 * Optional: For each principal entry in the database, invoke func with the
992 * argments func_arg and the entry data. If match_entry is specified, the
993 * module may narrow the iteration to principal names matching that regular
994 * expression; a module may alternatively ignore match_entry.
996 krb5_error_code (*iterate)(krb5_context kcontext,
998 int (*func)(krb5_pointer, krb5_db_entry *),
999 krb5_pointer func_arg);
1002 * Optional: Create a password policy entry. Return an error if the policy
1005 krb5_error_code (*create_policy)(krb5_context kcontext,
1006 osa_policy_ent_t policy);
1009 * Optional: Set *policy to the policy entry of the specified name. If the
1010 * entry does not exist, return KRB5_KDB_NOENTRY.
1012 krb5_error_code (*get_policy)(krb5_context kcontext, char *name,
1013 osa_policy_ent_t *policy);
1016 * Optional: Modify an existing password policy entry to match the values
1017 * in policy. Return an error if the policy does not already exist.
1019 krb5_error_code (*put_policy)(krb5_context kcontext,
1020 osa_policy_ent_t policy);
1023 * Optional: For each password policy entry in the database, invoke func
1024 * with the argments data and the entry data. If match_entry is specified,
1025 * the module may narrow the iteration to policy names matching that
1026 * regular expression; a module may alternatively ignore match_entry.
1028 krb5_error_code (*iter_policy)(krb5_context kcontext, char *match_entry,
1029 osa_adb_iter_policy_func func,
1033 * Optional: Delete the password policy entry with the name policy. Return
1034 * an error if the entry does not exist.
1036 krb5_error_code (*delete_policy)(krb5_context kcontext, char *policy);
1038 /* Optional: Free a policy entry returned by db_get_policy. */
1039 void (*free_policy)(krb5_context kcontext, osa_policy_ent_t val);
1042 * Mandatory: Has the semantics of realloc(ptr, size). Callers use this to
1043 * allocate memory for new or changed principal entries, so the module
1044 * should expect to potentially see this memory in db_free_principal.
1046 void *(*alloc)(krb5_context kcontext, void *ptr, size_t size);
1049 * Mandatory: Has the semantics of free(ptr). Callers use this to free
1050 * fields from a principal entry (such as key data) before changing it in
1051 * place, and in some cases to free data they allocated with db_alloc.
1053 void (*free)(krb5_context kcontext, void *ptr);
1056 * Optional with default: Retrieve a master keyblock from the stash file
1057 * db_args, filling in *key and *kvno. mname is the name of the master
1058 * principal for the realm.
1060 * The default implementation reads the master keyblock from a keytab or
1061 * old-format stash file.
1063 krb5_error_code (*fetch_master_key)(krb5_context kcontext,
1064 krb5_principal mname,
1065 krb5_keyblock *key, krb5_kvno *kvno,
1069 * Optional with default: Given a keyblock for some version of the
1070 * database's master key, fetch the decrypted master key values from the
1071 * database and store the list into *mkeys_list. The caller will free
1072 * *mkeys_list using a libkdb5 function which uses the standard free()
1073 * function, so the module must not use a custom allocator.
1075 * The caller may not know the version number of the master key it has, in
1076 * which case it will pass IGNORE_VNO.
1078 * The default implementation ignores kvno and tries the key against the
1079 * current master key data and all KRB5_TL_MKEY_AUX values, which contain
1080 * copies of the master keys encrypted with old master keys.
1082 krb5_error_code (*fetch_master_key_list)(krb5_context kcontext,
1083 krb5_principal mname,
1084 const krb5_keyblock *key,
1085 krb5_keylist_node **mkeys_list);
1088 * Optional with default: Save a list of master keyblocks, obtained from
1089 * fetch_master_key_list, into the stash file db_arg. The caller will set
1090 * master_pwd to NULL, so the module should just ignore it. mname is the
1091 * name of the master principal for the realm.
1093 * The default implementation saves the list of master keys in a
1094 * keytab-format file.
1096 krb5_error_code (*store_master_key_list)(krb5_context kcontext,
1098 krb5_principal mname,
1099 krb5_keylist_node *keylist,
1103 * Optional with default: Starting at position *start, scan the key data of
1104 * a database entry for a key matching the enctype ktype, the salt type
1105 * stype, and the version kvno. Store the resulting key into *kdatap and
1106 * set *start to the position after the key found. If ktype is negative,
1107 * match any enctype. If stype is negative, match any salt type. If kvno
1108 * is zero or negative, find the most recent key version satisfying the
1109 * other constraints.
1111 krb5_error_code (*dbe_search_enctype)(krb5_context kcontext,
1112 krb5_db_entry *dbentp,
1113 krb5_int32 *start, krb5_int32 ktype,
1114 krb5_int32 stype, krb5_int32 kvno,
1115 krb5_key_data **kdatap);
1119 * Optional with default: Change the key data for db_entry to include keys
1120 * derived from the password passwd in each of the specified key-salt
1121 * types, at version new_kvno. Discard the old key data if keepold is not
1124 * The default implementation uses the keyblock master_key to encrypt each
1125 * new key, via the function encrypt_key_data.
1127 krb5_error_code (*change_pwd)(krb5_context context,
1128 krb5_keyblock *master_key,
1129 krb5_key_salt_tuple *ks_tuple,
1130 int ks_tuple_count, char *passwd,
1131 int new_kvno, krb5_boolean keepold,
1132 krb5_db_entry *db_entry);
1135 * Optional: Promote a temporary database to be the live one. context must
1136 * be initialized with an exclusively locked database created with the
1137 * "temporary" db_arg. On success, the database object contained in
1138 * context will be finalized.
1140 * This method is used by kdb5_util load to replace the live database with
1141 * minimal loss of read availability.
1143 krb5_error_code (*promote_db)(krb5_context context, char *conf_section,
1147 * Optional with default: Decrypt the key in key_data with master keyblock
1148 * mkey, placing the result into dbkey. Copy the salt from key_data, if
1149 * any, into keysalt. Either dbkey or keysalt may be left unmodified on
1150 * successful return if key_data does not contain key or salt information.
1152 * The default implementation expects the encrypted key (in krb5_c_encrypt
1153 * format) to be stored in key_data_contents[0], with length given by
1154 * key_data_length[0]. If key_data_ver is 2, it expects the salt to be
1155 * stored, unencrypted, in key_data_contents[1], with length given by
1156 * key_data_length[1].
1158 krb5_error_code (*decrypt_key_data)(krb5_context kcontext,
1159 const krb5_keyblock *mkey,
1160 const krb5_key_data *key_data,
1161 krb5_keyblock *dbkey,
1162 krb5_keysalt *keysalt);
1165 * Optional with default: Encrypt dbkey with master keyblock mkey, placing
1166 * the result into key_data along with keysalt.
1168 * The default implementation stores the encrypted key (in krb5_c_encrypt
1169 * format) in key_data_contents[0] and the length in key_data_length[0].
1170 * If keysalt is specified, it sets key_data_ver to 2, and stores the salt
1171 * in key_data_contents[1] and its length in key_data_length[1]. If
1172 * keysalt is not specified, key_data_ver is set to 1.
1174 krb5_error_code (*encrypt_key_data)(krb5_context kcontext,
1175 const krb5_keyblock *mkey,
1176 const krb5_keyblock *dbkey,
1177 const krb5_keysalt *keysalt,
1178 int keyver, krb5_key_data *key_data);
1181 * Optional: Generate signed authorization data, such as a Windows PAC, for
1182 * the ticket to be returned to the client. Place the signed authorization
1183 * data, if any, in *signed_auth_data. This function will be invoked for
1184 * an AS request if the client included padata requesting a PAC. This
1185 * function will be invoked for a TGS request if there is authorization
1186 * data in the TGT, if the client is from another realm, or if the TGS
1187 * request is an S4U2Self or S4U2Proxy request. This function will not be
1188 * invoked during TGS requests if the server principal has the
1189 * no_auth_data_required attribute set. Input parameters are:
1191 * flags: The flags used to look up the client principal.
1193 * client_princ: For S4U2Proxy TGS requests, the client principal
1194 * requested by the service; for regular TGS requests, the
1195 * possibly-canonicalized client principal.
1197 * client: The DB entry of the client. For S4U2Self, this will be the DB
1198 * entry for the client principal requested by the service).
1200 * server: The DB entry of the service principal.
1202 * krbtgt: For TGS requests, the DB entry of the (possibly foreign)
1203 * ticket granting service of the TGT. For AS requests, the DB entry
1204 * of the service principal.
1206 * client_key: The reply key for the KDC request, before any FAST armor
1207 * is applied. For AS requests, this may be the client's long-term key
1208 * or a key chosen by a preauth mechanism. For TGS requests, this may
1209 * be the subkey found in the AP-REQ or the session key of the TGT.
1211 * server_key: The server key used to encrypt the returned ticket.
1213 * krbtgt_key: For TGS requests, the key of the (possibly foreign) ticket
1214 * granting service of the TGT. for AS requests, the service
1217 * session_key: The session key of the ticket being granted to the
1220 * authtime: The timestamp of the original client authentication time.
1221 * For AS requests, this is the current time. For TGS requests, this
1222 * is the authtime of the subject ticket (TGT or S4U2Proxy evidence
1225 * tgt_auth_data: For TGS requests, the authorization data present in the
1226 * subject ticket. For AS requests, NULL.
1228 krb5_error_code (*sign_authdata)(krb5_context kcontext,
1230 krb5_const_principal client_princ,
1231 krb5_db_entry *client,
1232 krb5_db_entry *server,
1233 krb5_db_entry *krbtgt,
1234 krb5_keyblock *client_key,
1235 krb5_keyblock *server_key,
1236 krb5_keyblock *krbtgt_key,
1237 krb5_keyblock *session_key,
1238 krb5_timestamp authtime,
1239 krb5_authdata **tgt_auth_data,
1240 krb5_authdata ***signed_auth_data);
1243 * Optional: Perform a policy check on a cross-realm ticket's transited
1244 * field and return an error (other than KRB5_PLUGIN_OP_NOTSUPP) if the
1247 krb5_error_code (*check_transited_realms)(krb5_context kcontext,
1248 const krb5_data *tr_contents,
1249 const krb5_data *client_realm,
1250 const krb5_data *server_realm);
1253 * Optional: Perform a policy check on an AS request, in addition to the
1254 * standard policy checks. Return 0 if the AS request is allowed. If the
1255 * AS request is not allowed:
1256 * - Place a short string literal into *status.
1257 * - If desired, place data into e_data. Any data placed here will be
1258 * freed by the caller using the standard free function.
1259 * - Return an appropriate error (such as KDC_ERR_POLICY).
1261 krb5_error_code (*check_policy_as)(krb5_context kcontext,
1262 krb5_kdc_req *request,
1263 krb5_db_entry *client,
1264 krb5_db_entry *server,
1265 krb5_timestamp kdc_time,
1266 const char **status,
1267 krb5_pa_data ***e_data);
1270 * Optional: Perform a policy check on a TGS request, in addition to the
1271 * standard policy checks. Return 0 if the TGS request is allowed. If the
1272 * TGS request is not allowed:
1273 * - Place a short string literal into *status.
1274 * - If desired, place data into e_data. Any data placed here will be
1275 * freed by the caller using the standard free function.
1276 * - Return an appropriate error (such as KDC_ERR_POLICY).
1277 * The input parameter ticket contains the TGT used in the TGS request.
1279 krb5_error_code (*check_policy_tgs)(krb5_context kcontext,
1280 krb5_kdc_req *request,
1281 krb5_db_entry *server,
1282 krb5_ticket *ticket,
1283 const char **status,
1284 krb5_pa_data ***e_data);
1287 * Optional: This method informs the module of a successful or unsuccessful
1290 void (*audit_as_req)(krb5_context kcontext, krb5_kdc_req *request,
1291 krb5_db_entry *client, krb5_db_entry *server,
1292 krb5_timestamp authtime, krb5_error_code error_code);
1294 /* Note: there is currently no method for auditing TGS requests. */
1297 * Optional: This method informs the module of a request to reload
1298 * configuration or other state (that is, the KDC received a SIGHUP).
1300 void (*refresh_config)(krb5_context kcontext);
1303 * Optional: Perform a policy check on server being allowed to obtain
1304 * tickets from client to proxy. (Note that proxy is the target of the
1305 * delegation, not the delegating service; the term "proxy" is from the
1306 * viewpoint of the delegating service asking another service to perform
1307 * some of its work in the authentication context of the client. This
1308 * terminology comes from the Microsoft S4U protocol documentation.)
1309 * Return 0 if policy allows it, or an appropriate error (such as
1310 * KRB5KDC_ERR_POLICY) if not. If this method is not implemented, all
1311 * S4U2Proxy delegation requests will be rejected.
1313 krb5_error_code (*check_allowed_to_delegate)(krb5_context context,
1314 krb5_const_principal client,
1315 const krb5_db_entry *server,
1316 krb5_const_principal proxy);
1319 #endif /* !defined(_WIN32) */
1321 #endif /* KRB5_KDB5__ */