Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:55:36

0001 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
0002 /*
0003  * Copyright 1990, 1991, 2016 by the Massachusetts Institute of Technology.
0004  * All Rights Reserved.
0005  *
0006  * Export of this software from the United States of America may
0007  *   require a specific license from the United States Government.
0008  *   It is the responsibility of any person or organization contemplating
0009  *   export to obtain such a license before exporting.
0010  *
0011  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
0012  * distribute this software and its documentation for any purpose and
0013  * without fee is hereby granted, provided that the above copyright
0014  * notice appear in all copies and that both that copyright notice and
0015  * this permission notice appear in supporting documentation, and that
0016  * the name of M.I.T. not be used in advertising or publicity pertaining
0017  * to distribution of the software without specific, written prior
0018  * permission.  Furthermore if you modify this software you must label
0019  * your software as modified software and not distribute it in such a
0020  * fashion that it might be confused with the original M.I.T. software.
0021  * M.I.T. makes no representations about the suitability of
0022  * this software for any purpose.  It is provided "as is" without express
0023  * or implied warranty.
0024  */
0025 /*
0026  * Copyright (C) 1998 by the FundsXpress, INC.
0027  *
0028  * All rights reserved.
0029  *
0030  * Export of this software from the United States of America may require
0031  * a specific license from the United States Government.  It is the
0032  * responsibility of any person or organization contemplating export to
0033  * obtain such a license before exporting.
0034  *
0035  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
0036  * distribute this software and its documentation for any purpose and
0037  * without fee is hereby granted, provided that the above copyright
0038  * notice appear in all copies and that both that copyright notice and
0039  * this permission notice appear in supporting documentation, and that
0040  * the name of FundsXpress. not be used in advertising or publicity pertaining
0041  * to distribution of the software without specific, written prior
0042  * permission.  FundsXpress makes no representations about the suitability of
0043  * this software for any purpose.  It is provided "as is" without express
0044  * or implied warranty.
0045  *
0046  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
0047  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
0048  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
0049  */
0050 /*
0051  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
0052  * Use is subject to license terms.
0053  */
0054 
0055 /* KDC Database interface definitions */
0056 
0057 /* This API is not considered as stable as the main krb5 API.
0058  *
0059  * - We may make arbitrary incompatible changes between feature
0060  *   releases (e.g. from 1.7 to 1.8).
0061  * - We will make some effort to avoid making incompatible changes for
0062  *   bugfix releases, but will make them if necessary.
0063  */
0064 
0065 #ifndef KRB5_KDB5__
0066 #define KRB5_KDB5__
0067 
0068 #include <time.h>
0069 #include <krb5.h>
0070 
0071 /* This version will be incremented when incompatible changes are made to the
0072  * KDB API, and will be kept in sync with the libkdb major version. */
0073 #define KRB5_KDB_API_VERSION 10
0074 
0075 /* Salt types */
0076 #define KRB5_KDB_SALTTYPE_NORMAL        0
0077 /* #define KRB5_KDB_SALTTYPE_V4            1 */
0078 #define KRB5_KDB_SALTTYPE_NOREALM       2
0079 #define KRB5_KDB_SALTTYPE_ONLYREALM     3
0080 #define KRB5_KDB_SALTTYPE_SPECIAL       4
0081 /* #define KRB5_KDB_SALTTYPE_AFS3          5 */
0082 #define KRB5_KDB_SALTTYPE_CERTHASH      6
0083 
0084 /* Attributes */
0085 #define KRB5_KDB_DISALLOW_POSTDATED     0x00000001
0086 #define KRB5_KDB_DISALLOW_FORWARDABLE   0x00000002
0087 #define KRB5_KDB_DISALLOW_TGT_BASED     0x00000004
0088 #define KRB5_KDB_DISALLOW_RENEWABLE     0x00000008
0089 #define KRB5_KDB_DISALLOW_PROXIABLE     0x00000010
0090 #define KRB5_KDB_DISALLOW_DUP_SKEY      0x00000020
0091 #define KRB5_KDB_DISALLOW_ALL_TIX       0x00000040
0092 #define KRB5_KDB_REQUIRES_PRE_AUTH      0x00000080
0093 #define KRB5_KDB_REQUIRES_HW_AUTH       0x00000100
0094 #define KRB5_KDB_REQUIRES_PWCHANGE      0x00000200
0095 #define KRB5_KDB_DISALLOW_SVR           0x00001000
0096 #define KRB5_KDB_PWCHANGE_SERVICE       0x00002000
0097 #define KRB5_KDB_SUPPORT_DESMD5         0x00004000
0098 #define KRB5_KDB_NEW_PRINC              0x00008000
0099 #define KRB5_KDB_OK_AS_DELEGATE         0x00100000
0100 #define KRB5_KDB_OK_TO_AUTH_AS_DELEGATE 0x00200000 /* S4U2Self OK */
0101 #define KRB5_KDB_NO_AUTH_DATA_REQUIRED  0x00400000
0102 #define KRB5_KDB_LOCKDOWN_KEYS          0x00800000
0103 
0104 /* Creation flags */
0105 #define KRB5_KDB_CREATE_BTREE           0x00000001
0106 #define KRB5_KDB_CREATE_HASH            0x00000002
0107 
0108 /* Entry get flags */
0109 /* Okay to generate a referral on lookup */
0110 #define KRB5_KDB_FLAG_REFERRAL_OK               0x00000010
0111 /* Client principal lookup (client referrals only) */
0112 #define KRB5_KDB_FLAG_CLIENT                    0x00000040
0113 /* Map cross-realm principals */
0114 #define KRB5_KDB_FLAG_MAP_PRINCIPALS            0x00000080
0115 /* Protocol transition */
0116 #define KRB5_KDB_FLAG_PROTOCOL_TRANSITION       0x00000100
0117 /* Constrained delegation */
0118 #define KRB5_KDB_FLAG_CONSTRAINED_DELEGATION    0x00000200
0119 /* User-to-user */
0120 #define KRB5_KDB_FLAG_USER_TO_USER              0x00000800
0121 /* Cross-realm */
0122 #define KRB5_KDB_FLAG_CROSS_REALM               0x00001000
0123 /* Issuing referral */
0124 #define KRB5_KDB_FLAG_ISSUING_REFERRAL          0x00004000
0125 
0126 
0127 #define KRB5_KDB_FLAGS_S4U                      ( KRB5_KDB_FLAG_PROTOCOL_TRANSITION | \
0128                                                   KRB5_KDB_FLAG_CONSTRAINED_DELEGATION )
0129 
0130 /* KDB iteration flags */
0131 #define KRB5_DB_ITER_WRITE      0x00000001
0132 #define KRB5_DB_ITER_REV        0x00000002
0133 #define KRB5_DB_ITER_RECURSE    0x00000004
0134 
0135 /* String attribute names recognized by krb5 */
0136 #define KRB5_KDB_SK_PAC_PRIVSVR_ENCTYPE         "pac_privsvr_enctype"
0137 #define KRB5_KDB_SK_SESSION_ENCTYPES            "session_enctypes"
0138 #define KRB5_KDB_SK_REQUIRE_AUTH                "require_auth"
0139 
0140 #if !defined(_WIN32)
0141 
0142 /*
0143  * Note --- these structures cannot be modified without changing the
0144  * database version number in libkdb.a, but should be expandable by
0145  * adding new tl_data types.
0146  */
0147 typedef struct _krb5_tl_data {
0148     struct _krb5_tl_data* tl_data_next;         /* NOT saved */
0149     krb5_int16            tl_data_type;
0150     krb5_ui_2             tl_data_length;
0151     krb5_octet          * tl_data_contents;
0152 } krb5_tl_data;
0153 
0154 /* String attributes (currently stored inside tl-data) map C string keys to
0155  * values.  They can be set via kadmin and consumed by KDC plugins. */
0156 typedef struct krb5_string_attr_st {
0157     char *key;
0158     char *value;
0159 } krb5_string_attr;
0160 
0161 /*
0162  * If this ever changes up the version number and make the arrays be as
0163  * big as necessary.
0164  *
0165  * Currently the first type is the enctype and the second is the salt type.
0166  */
0167 typedef struct _krb5_key_data {
0168     krb5_int16            key_data_ver;         /* Version */
0169     krb5_ui_2             key_data_kvno;        /* Key Version */
0170     krb5_int16            key_data_type[2];     /* Array of types */
0171     krb5_ui_2             key_data_length[2];   /* Array of lengths */
0172     krb5_octet          * key_data_contents[2]; /* Array of pointers */
0173 } krb5_key_data;
0174 
0175 #define KRB5_KDB_V1_KEY_DATA_ARRAY      2       /* # of array elements */
0176 
0177 typedef struct _krb5_keysalt {
0178     krb5_int16            type;
0179     krb5_data             data;                 /* Length, data */
0180 } krb5_keysalt;
0181 
0182 /*
0183  * A principal database entry.  Extensions to this structure currently use the
0184  * tl_data list.  The e_data and e_length fields are not used by any calling
0185  * code except kdb5_util dump and load, which marshal and unmarshal the array
0186  * in the dump record.  KDB modules may use these fields internally as long as
0187  * they set e_length appropriately (non-zero if the data should be marshalled
0188  * across dump and load, zero if not) and handle null e_data values in
0189  * caller-constructed principal entries.
0190  */
0191 typedef struct _krb5_db_entry_new {
0192     krb5_magic            magic;                /* NOT saved */
0193     krb5_ui_2             len;
0194     krb5_ui_4             mask;                 /* members currently changed/set */
0195     krb5_flags            attributes;
0196     krb5_deltat           max_life;
0197     krb5_deltat           max_renewable_life;
0198     krb5_timestamp        expiration;           /* When the client expires */
0199     krb5_timestamp        pw_expiration;        /* When its passwd expires */
0200     krb5_timestamp        last_success;         /* Last successful passwd */
0201     krb5_timestamp        last_failed;          /* Last failed passwd attempt */
0202     krb5_kvno             fail_auth_count;      /* # of failed passwd attempt */
0203     krb5_int16            n_tl_data;
0204     krb5_int16            n_key_data;
0205     krb5_ui_2             e_length;             /* Length of extra data */
0206     krb5_octet          * e_data;               /* Extra data to be saved */
0207 
0208     krb5_principal        princ;                /* Length, data */
0209     krb5_tl_data        * tl_data;              /* Linked list */
0210 
0211     /* key_data must be sorted by kvno in descending order. */
0212     krb5_key_data       * key_data;             /* Array */
0213 } krb5_db_entry;
0214 
0215 typedef struct _osa_policy_ent_t {
0216     int               version;
0217     char      *name;
0218     krb5_ui_4       pw_min_life;
0219     krb5_ui_4       pw_max_life;
0220     krb5_ui_4       pw_min_length;
0221     krb5_ui_4       pw_min_classes;
0222     krb5_ui_4       pw_history_num;
0223     krb5_ui_4       policy_refcnt;              /* no longer used */
0224     /* Only valid if version > 1 */
0225     krb5_ui_4       pw_max_fail;                /* pwdMaxFailure */
0226     krb5_ui_4       pw_failcnt_interval;        /* pwdFailureCountInterval */
0227     krb5_ui_4       pw_lockout_duration;        /* pwdLockoutDuration */
0228     /* Only valid if version > 2 */
0229     krb5_ui_4       attributes;
0230     krb5_ui_4       max_life;
0231     krb5_ui_4       max_renewable_life;
0232     char          * allowed_keysalts;
0233     krb5_int16      n_tl_data;
0234     krb5_tl_data  * tl_data;
0235 } osa_policy_ent_rec, *osa_policy_ent_t;
0236 
0237 typedef       void    (*osa_adb_iter_policy_func) (void *, osa_policy_ent_t);
0238 
0239 typedef struct __krb5_key_salt_tuple {
0240     krb5_enctype        ks_enctype;
0241     krb5_int32          ks_salttype;
0242 } krb5_key_salt_tuple;
0243 
0244 #define KRB5_KDB_MAGIC_NUMBER           0xdbdbdbdb
0245 #define KRB5_KDB_V1_BASE_LENGTH         38
0246 
0247 #define KRB5_KDB_MAX_ALLOWED_KS_LEN     512
0248 
0249 #define KRB5_TL_LAST_PWD_CHANGE         0x0001
0250 #define KRB5_TL_MOD_PRINC               0x0002
0251 #define KRB5_TL_KADM_DATA               0x0003
0252 #define KRB5_TL_KADM5_E_DATA            0x0004
0253 #define KRB5_TL_RB1_CHALLENGE           0x0005
0254 #ifdef SECURID
0255 #define KRB5_TL_SECURID_STATE           0x0006
0256 #endif /* SECURID */
0257 #define KRB5_TL_USER_CERTIFICATE        0x0007
0258 #define KRB5_TL_MKVNO                   0x0008
0259 #define KRB5_TL_ACTKVNO                 0x0009
0260 #define KRB5_TL_MKEY_AUX                0x000a
0261 
0262 /* String attributes may not always be represented in tl-data.  kadmin clients
0263  * must use the get_strings and set_string RPCs. */
0264 #define KRB5_TL_STRING_ATTRS            0x000b
0265 
0266 #define KRB5_TL_PAC_LOGON_INFO          0x0100 /* NDR encoded validation info */
0267 #define KRB5_TL_SERVER_REFERRAL         0x0200 /* ASN.1 encoded ServerReferralInfo */
0268 #define KRB5_TL_SVR_REFERRAL_DATA       0x0300 /* ASN.1 encoded PA-SVR-REFERRAL-DATA */
0269 #define KRB5_TL_CONSTRAINED_DELEGATION_ACL 0x0400 /* Each entry is a permitted SPN */
0270 #define KRB5_TL_LM_KEY                  0x0500 /* LM OWF */
0271 #define KRB5_TL_X509_SUBJECT_ISSUER_NAME 0x0600 /* <I>IssuerDN<S>SubjectDN */
0272 #define KRB5_TL_LAST_ADMIN_UNLOCK       0x0700 /* Timestamp of admin unlock */
0273 
0274 #define KRB5_TL_DB_ARGS                 0x7fff
0275 
0276 /* version number for KRB5_TL_ACTKVNO data */
0277 #define KRB5_TL_ACTKVNO_VER     1
0278 
0279 /* version number for KRB5_TL_MKEY_AUX data */
0280 #define KRB5_TL_MKEY_AUX_VER    1
0281 
0282 typedef struct _krb5_actkvno_node {
0283     struct _krb5_actkvno_node *next;
0284     krb5_kvno      act_kvno;
0285     krb5_timestamp act_time;
0286 } krb5_actkvno_node;
0287 
0288 typedef struct _krb5_mkey_aux_node {
0289     struct _krb5_mkey_aux_node *next;
0290     krb5_kvno        mkey_kvno; /* kvno of mkey protecting the latest_mkey */
0291     krb5_key_data    latest_mkey; /* most recent mkey */
0292 } krb5_mkey_aux_node;
0293 
0294 typedef struct _krb5_keylist_node {
0295     krb5_keyblock keyblock;
0296     krb5_kvno     kvno;
0297     struct _krb5_keylist_node *next;
0298 } krb5_keylist_node;
0299 
0300 /*
0301  * Determines the number of failed KDC requests before DISALLOW_ALL_TIX is set
0302  * on the principal.
0303  */
0304 #define KRB5_MAX_FAIL_COUNT             5
0305 
0306 /* XXX depends on knowledge of krb5_parse_name() formats */
0307 #define KRB5_KDB_M_NAME         "K/M"   /* Kerberos/Master */
0308 
0309 /* prompts used by default when reading the KDC password from the keyboard. */
0310 #define KRB5_KDC_MKEY_1 "Enter KDC database master key"
0311 #define KRB5_KDC_MKEY_2 "Re-enter KDC database master key to verify"
0312 
0313 
0314 extern char *krb5_mkey_pwd_prompt1;
0315 extern char *krb5_mkey_pwd_prompt2;
0316 
0317 /*
0318  * These macros specify the encoding of data within the database.
0319  *
0320  * Data encoding is little-endian.
0321  */
0322 #ifdef _KRB5_INT_H
0323 #include "k5-platform.h"
0324 #define krb5_kdb_decode_int16(cp, i16)          \
0325     *((krb5_int16 *) &(i16)) = load_16_le(cp)
0326 #define krb5_kdb_decode_int32(cp, i32)          \
0327     *((krb5_int32 *) &(i32)) = load_32_le(cp)
0328 #define krb5_kdb_encode_int16(i16, cp)  store_16_le(i16, cp)
0329 #define krb5_kdb_encode_int32(i32, cp)  store_32_le(i32, cp)
0330 #endif /* _KRB5_INT_H */
0331 
0332 #define KRB5_KDB_OPEN_RW                0
0333 #define KRB5_KDB_OPEN_RO                1
0334 
0335 #ifndef KRB5_KDB_SRV_TYPE_KDC
0336 #define KRB5_KDB_SRV_TYPE_KDC           0x0100
0337 #endif
0338 
0339 #ifndef KRB5_KDB_SRV_TYPE_ADMIN
0340 #define KRB5_KDB_SRV_TYPE_ADMIN         0x0200
0341 #endif
0342 
0343 /* 0x0300 was KRB5_KDB_SRV_TYPE_PASSWD but it is no longer used. */
0344 
0345 #ifndef KRB5_KDB_SRV_TYPE_OTHER
0346 #define KRB5_KDB_SRV_TYPE_OTHER         0x0400
0347 #endif
0348 
0349 #define KRB5_KDB_OPT_SET_DB_NAME        0
0350 #define KRB5_KDB_OPT_SET_LOCK_MODE      1
0351 
0352 #define KRB5_DB_LOCKMODE_SHARED       0x0001
0353 #define KRB5_DB_LOCKMODE_EXCLUSIVE    0x0002
0354 #define KRB5_DB_LOCKMODE_PERMANENT    0x0008
0355 
0356 /* libkdb.spec */
0357 krb5_error_code krb5_db_setup_lib_handle(krb5_context kcontext);
0358 krb5_error_code krb5_db_open( krb5_context kcontext, char **db_args, int mode );
0359 krb5_error_code krb5_db_init  ( krb5_context kcontext );
0360 krb5_error_code krb5_db_create ( krb5_context kcontext, char **db_args );
0361 krb5_error_code krb5_db_inited  ( krb5_context kcontext );
0362 krb5_error_code kdb5_db_create ( krb5_context kcontext, char **db_args );
0363 krb5_error_code krb5_db_fini ( krb5_context kcontext );
0364 const char * krb5_db_errcode2string ( krb5_context kcontext, long err_code );
0365 krb5_error_code krb5_db_destroy ( krb5_context kcontext, char **db_args );
0366 krb5_error_code krb5_db_promote ( krb5_context kcontext, char **db_args );
0367 krb5_error_code krb5_db_get_age ( krb5_context kcontext, char *db_name, time_t *t );
0368 krb5_error_code krb5_db_lock ( krb5_context kcontext, int lock_mode );
0369 krb5_error_code krb5_db_unlock ( krb5_context kcontext );
0370 krb5_error_code krb5_db_get_principal ( krb5_context kcontext,
0371                                         krb5_const_principal search_for,
0372                                         unsigned int flags,
0373                                         krb5_db_entry **entry );
0374 void krb5_db_free_principal ( krb5_context kcontext, krb5_db_entry *entry );
0375 krb5_error_code krb5_db_put_principal ( krb5_context kcontext,
0376                                         krb5_db_entry *entry );
0377 krb5_error_code krb5_db_delete_principal ( krb5_context kcontext,
0378                                            krb5_principal search_for );
0379 krb5_error_code krb5_db_rename_principal ( krb5_context kcontext,
0380                                            krb5_principal source,
0381                                            krb5_principal target );
0382 
0383 /*
0384  * Iterate over principals in the KDB.  If the callback may write to the DB,
0385  * the caller must get an exclusive lock with krb5_db_lock before iterating,
0386  * and release it with krb5_db_unlock after iterating.
0387  */
0388 krb5_error_code krb5_db_iterate ( krb5_context kcontext,
0389                                   char *match_entry,
0390                                   int (*func) (krb5_pointer, krb5_db_entry *),
0391                                   krb5_pointer func_arg, krb5_flags iterflags );
0392 
0393 
0394 krb5_error_code krb5_db_store_master_key  ( krb5_context kcontext,
0395                                             char *keyfile,
0396                                             krb5_principal mname,
0397                                             krb5_kvno kvno,
0398                                             krb5_keyblock *key,
0399                                             char *master_pwd);
0400 krb5_error_code krb5_db_store_master_key_list  ( krb5_context kcontext,
0401                                                  char *keyfile,
0402                                                  krb5_principal mname,
0403                                                  char *master_pwd);
0404 krb5_error_code krb5_db_fetch_mkey  ( krb5_context   context,
0405                                       krb5_principal mname,
0406                                       krb5_enctype   etype,
0407                                       krb5_boolean   fromkeyboard,
0408                                       krb5_boolean   twice,
0409                                       char          *db_args,
0410                                       krb5_kvno     *kvno,
0411                                       krb5_data     *salt,
0412                                       krb5_keyblock *key);
0413 krb5_error_code
0414 krb5_db_fetch_mkey_list( krb5_context    context,
0415                          krb5_principal  mname,
0416                          const krb5_keyblock * mkey );
0417 
0418 krb5_error_code
0419 krb5_dbe_find_enctype( krb5_context     kcontext,
0420                        krb5_db_entry    *dbentp,
0421                        krb5_int32               ktype,
0422                        krb5_int32               stype,
0423                        krb5_int32               kvno,
0424                        krb5_key_data    **kdatap);
0425 
0426 
0427 krb5_error_code krb5_dbe_search_enctype ( krb5_context kcontext,
0428                                           krb5_db_entry *dbentp,
0429                                           krb5_int32 *start,
0430                                           krb5_int32 ktype,
0431                                           krb5_int32 stype,
0432                                           krb5_int32 kvno,
0433                                           krb5_key_data **kdatap);
0434 
0435 krb5_error_code
0436 krb5_db_setup_mkey_name ( krb5_context context,
0437                           const char *keyname,
0438                           const char *realm,
0439                           char **fullname,
0440                           krb5_principal *principal);
0441 
0442 /**
0443  * Decrypts the key given in @@a key_data. If @a mkey is specified, that
0444  * master key is used. If @a mkey is NULL, then all master keys are tried.
0445  */
0446 krb5_error_code
0447 krb5_dbe_decrypt_key_data( krb5_context         context,
0448                            const krb5_keyblock        * mkey,
0449                            const krb5_key_data        * key_data,
0450                            krb5_keyblock      * dbkey,
0451                            krb5_keysalt       * keysalt);
0452 
0453 krb5_error_code
0454 krb5_dbe_encrypt_key_data( krb5_context                 context,
0455                            const krb5_keyblock        * mkey,
0456                            const krb5_keyblock        * dbkey,
0457                            const krb5_keysalt         * keysalt,
0458                            int                          keyver,
0459                            krb5_key_data              * key_data);
0460 
0461 krb5_error_code
0462 krb5_dbe_fetch_act_key_list(krb5_context          context,
0463                             krb5_principal       princ,
0464                             krb5_actkvno_node  **act_key_list);
0465 
0466 krb5_error_code
0467 krb5_dbe_find_act_mkey( krb5_context          context,
0468                         krb5_actkvno_node   * act_mkey_list,
0469                         krb5_kvno           * act_kvno,
0470                         krb5_keyblock      ** act_mkey);
0471 
0472 krb5_error_code
0473 krb5_dbe_find_mkey( krb5_context         context,
0474                     krb5_db_entry      * entry,
0475                     krb5_keyblock      ** mkey);
0476 
0477 /* Set *mkvno to mkvno in entry tl_data, or 0 if not present. */
0478 krb5_error_code
0479 krb5_dbe_lookup_mkvno( krb5_context    context,
0480                        krb5_db_entry * entry,
0481                        krb5_kvno     * mkvno);
0482 
0483 krb5_keylist_node *
0484 krb5_db_mkey_list_alias( krb5_context kcontext );
0485 
0486 /* Set *mkvno to mkvno in entry tl_data, or minimum value from mkey_list. */
0487 krb5_error_code
0488 krb5_dbe_get_mkvno( krb5_context        context,
0489                     krb5_db_entry     * entry,
0490                     krb5_kvno         * mkvno);
0491 
0492 krb5_error_code
0493 krb5_dbe_lookup_mod_princ_data( krb5_context          context,
0494                                 krb5_db_entry       * entry,
0495                                 krb5_timestamp      * mod_time,
0496                                 krb5_principal      * mod_princ);
0497 
0498 krb5_error_code
0499 krb5_dbe_lookup_mkey_aux( krb5_context         context,
0500                           krb5_db_entry      * entry,
0501                           krb5_mkey_aux_node ** mkey_aux_data_list);
0502 krb5_error_code
0503 krb5_dbe_update_mkvno( krb5_context    context,
0504                        krb5_db_entry * entry,
0505                        krb5_kvno       mkvno);
0506 
0507 krb5_error_code
0508 krb5_dbe_lookup_actkvno( krb5_context         context,
0509                          krb5_db_entry      * entry,
0510                          krb5_actkvno_node ** actkvno_list);
0511 
0512 krb5_error_code
0513 krb5_dbe_update_mkey_aux( krb5_context          context,
0514                           krb5_db_entry       * entry,
0515                           krb5_mkey_aux_node  * mkey_aux_data_list);
0516 
0517 krb5_error_code
0518 krb5_dbe_update_actkvno(krb5_context    context,
0519                         krb5_db_entry * entry,
0520                         const krb5_actkvno_node *actkvno_list);
0521 
0522 krb5_error_code
0523 krb5_dbe_update_last_pwd_change( krb5_context     context,
0524                                  krb5_db_entry  * entry,
0525                                  krb5_timestamp   stamp);
0526 
0527 krb5_error_code
0528 krb5_dbe_update_last_admin_unlock( krb5_context     context,
0529                                    krb5_db_entry  * entry,
0530                                    krb5_timestamp   stamp);
0531 
0532 krb5_error_code
0533 krb5_dbe_lookup_tl_data( krb5_context          context,
0534                          krb5_db_entry       * entry,
0535                          krb5_tl_data        * ret_tl_data);
0536 
0537 krb5_error_code
0538 krb5_dbe_create_key_data( krb5_context          context,
0539                           krb5_db_entry       * entry);
0540 
0541 
0542 krb5_error_code
0543 krb5_dbe_update_mod_princ_data( krb5_context          context,
0544                                 krb5_db_entry       * entry,
0545                                 krb5_timestamp        mod_date,
0546                                 krb5_const_principal  mod_princ);
0547 
0548 /*
0549  * These are wrappers around realloc() and free().  Applications and KDB
0550  * modules can use them when manipulating principal and policy entries to
0551  * ensure that they allocate and free memory in a manner compatible with the
0552  * library.  Using libkrb5 or libkbd5 functions to construct values (such as
0553  * krb5_copy_principal() to construct the princ field of a krb5_db_entry) is
0554  * also safe.  On Unix platforms, just using malloc() and free() is safe as
0555  * long as the application or module does not use a malloc replacement.
0556  */
0557 void *krb5_db_alloc( krb5_context kcontext,
0558                      void *ptr,
0559                      size_t size );
0560 void krb5_db_free( krb5_context kcontext,
0561                    void *ptr);
0562 
0563 
0564 krb5_error_code
0565 krb5_dbe_lookup_last_pwd_change( krb5_context          context,
0566                                  krb5_db_entry       * entry,
0567                                  krb5_timestamp      * stamp);
0568 
0569 krb5_error_code
0570 krb5_dbe_lookup_last_admin_unlock( krb5_context          context,
0571                                    krb5_db_entry       * entry,
0572                                    krb5_timestamp      * stamp);
0573 
0574 /* Retrieve the set of string attributes in entry, in no particular order.
0575  * Free *strings_out with krb5_dbe_free_strings when done. */
0576 krb5_error_code
0577 krb5_dbe_get_strings(krb5_context context, krb5_db_entry *entry,
0578                      krb5_string_attr **strings_out, int *count_out);
0579 
0580 /* Retrieve a single string attribute from entry, or NULL if there is no
0581  * attribute for key.  Free *value_out with krb5_dbe_free_string when done. */
0582 krb5_error_code
0583 krb5_dbe_get_string(krb5_context context, krb5_db_entry *entry,
0584                     const char *key, char **value_out);
0585 
0586 /* Change or add a string attribute in entry, or delete it if value is NULL. */
0587 krb5_error_code
0588 krb5_dbe_set_string(krb5_context context, krb5_db_entry *entry,
0589                     const char *key, const char *value);
0590 
0591 krb5_error_code
0592 krb5_dbe_delete_tl_data( krb5_context    context,
0593                          krb5_db_entry * entry,
0594                          krb5_int16      tl_data_type);
0595 
0596 krb5_error_code
0597 krb5_db_update_tl_data(krb5_context          context,
0598                        krb5_int16          * n_tl_datap,
0599                        krb5_tl_data        **tl_datap,
0600                        krb5_tl_data        * new_tl_data);
0601 
0602 krb5_error_code
0603 krb5_dbe_update_tl_data( krb5_context          context,
0604                          krb5_db_entry       * entry,
0605                          krb5_tl_data        * new_tl_data);
0606 
0607 /* Compute the salt for a key data entry given the corresponding principal. */
0608 krb5_error_code
0609 krb5_dbe_compute_salt(krb5_context context, const krb5_key_data *key,
0610                       krb5_const_principal princ, krb5_int16 *salttype_out,
0611                       krb5_data **salt_out);
0612 
0613 /*
0614  * Modify the key data of entry to explicitly store salt values using the
0615  * KRB5_KDB_SALTTYPE_SPECIAL salt type.
0616  */
0617 krb5_error_code
0618 krb5_dbe_specialize_salt(krb5_context context, krb5_db_entry *entry);
0619 
0620 krb5_error_code
0621 krb5_dbe_cpw( krb5_context        kcontext,
0622               krb5_keyblock       * master_key,
0623               krb5_key_salt_tuple       * ks_tuple,
0624               int                         ks_tuple_count,
0625               char              * passwd,
0626               int                         new_kvno,
0627               krb5_boolean        keepold,
0628               krb5_db_entry     * db_entry);
0629 
0630 
0631 krb5_error_code
0632 krb5_dbe_ark( krb5_context        context,
0633               krb5_keyblock       * master_key,
0634               krb5_key_salt_tuple       * ks_tuple,
0635               int                         ks_tuple_count,
0636               krb5_db_entry     * db_entry);
0637 
0638 krb5_error_code
0639 krb5_dbe_crk( krb5_context        context,
0640               krb5_keyblock       * master_key,
0641               krb5_key_salt_tuple       * ks_tuple,
0642               int                         ks_tuple_count,
0643               krb5_boolean        keepold,
0644               krb5_db_entry     * db_entry);
0645 
0646 krb5_error_code
0647 krb5_dbe_apw( krb5_context        context,
0648               krb5_keyblock       * master_key,
0649               krb5_key_salt_tuple       * ks_tuple,
0650               int                         ks_tuple_count,
0651               char              * passwd,
0652               krb5_db_entry     * db_entry);
0653 
0654 int
0655 krb5_db_get_key_data_kvno( krb5_context    context,
0656                            int             count,
0657                            krb5_key_data * data);
0658 
0659 krb5_error_code krb5_db_check_transited_realms(krb5_context kcontext,
0660                                                const krb5_data *tr_contents,
0661                                                const krb5_data *client_realm,
0662                                                const krb5_data *server_realm);
0663 
0664 krb5_error_code krb5_db_check_policy_as(krb5_context kcontext,
0665                                         krb5_kdc_req *request,
0666                                         krb5_db_entry *client,
0667                                         krb5_db_entry *server,
0668                                         krb5_timestamp kdc_time,
0669                                         const char **status,
0670                                         krb5_pa_data ***e_data);
0671 
0672 krb5_error_code krb5_db_check_policy_tgs(krb5_context kcontext,
0673                                          krb5_kdc_req *request,
0674                                          krb5_db_entry *server,
0675                                          krb5_ticket *ticket,
0676                                          const char **status,
0677                                          krb5_pa_data ***e_data);
0678 
0679 void krb5_db_audit_as_req(krb5_context kcontext, krb5_kdc_req *request,
0680                           const krb5_address *local_addr,
0681                           const krb5_address *remote_addr,
0682                           krb5_db_entry *client, krb5_db_entry *server,
0683                           krb5_timestamp authtime, krb5_error_code error_code);
0684 
0685 void krb5_db_refresh_config(krb5_context kcontext);
0686 
0687 krb5_error_code krb5_db_check_allowed_to_delegate(krb5_context kcontext,
0688                                                   krb5_const_principal client,
0689                                                   const krb5_db_entry *server,
0690                                                   krb5_const_principal proxy);
0691 
0692 krb5_error_code krb5_db_get_s4u_x509_principal(krb5_context kcontext,
0693                                                const krb5_data *client_cert,
0694                                                krb5_const_principal in_princ,
0695                                                unsigned int flags,
0696                                                krb5_db_entry **entry);
0697 
0698 krb5_error_code krb5_db_allowed_to_delegate_from(krb5_context context,
0699                                                  krb5_const_principal client,
0700                                                  krb5_const_principal server,
0701                                                  krb5_pac server_pac,
0702                                                  const krb5_db_entry *proxy);
0703 
0704 /**
0705  * Sort an array of @a krb5_key_data keys in descending order by their kvno.
0706  * Key data order within a kvno is preserved.
0707  *
0708  * @param key_data
0709  *     The @a krb5_key_data array to sort.  This is sorted in place so the
0710  *     array will be modified.
0711  * @param key_data_length
0712  *     The length of @a key_data.
0713  */
0714 void
0715 krb5_dbe_sort_key_data(krb5_key_data *key_data, size_t key_data_length);
0716 
0717 krb5_error_code
0718 krb5_db_issue_pac(krb5_context context, unsigned int flags,
0719                   krb5_db_entry *client, krb5_keyblock *replaced_reply_key,
0720                   krb5_db_entry *server, krb5_db_entry *krbtgt,
0721                   krb5_timestamp authtime, krb5_pac old_pac, krb5_pac new_pac,
0722                   krb5_data ***auth_indicators);
0723 
0724 /* default functions. Should not be directly called */
0725 /*
0726  *   Default functions prototype
0727  */
0728 
0729 krb5_error_code
0730 krb5_dbe_def_search_enctype( krb5_context kcontext,
0731                              krb5_db_entry *dbentp,
0732                              krb5_int32 *start,
0733                              krb5_int32 ktype,
0734                              krb5_int32 stype,
0735                              krb5_int32 kvno,
0736                              krb5_key_data **kdatap);
0737 
0738 krb5_error_code
0739 krb5_def_store_mkey_list( krb5_context context,
0740                           char *keyfile,
0741                           krb5_principal mname,
0742                           krb5_keylist_node *keylist,
0743                           char *master_pwd);
0744 
0745 krb5_error_code
0746 krb5_db_def_fetch_mkey( krb5_context   context,
0747                         krb5_principal mname,
0748                         krb5_keyblock *key,
0749                         krb5_kvno     *kvno,
0750                         char          *db_args);
0751 
0752 krb5_error_code
0753 krb5_def_fetch_mkey_list( krb5_context            context,
0754                           krb5_principal        mprinc,
0755                           const krb5_keyblock  *mkey,
0756                           krb5_keylist_node  **mkeys_list);
0757 
0758 krb5_error_code
0759 krb5_dbe_def_cpw( krb5_context    context,
0760                   krb5_keyblock       * master_key,
0761                   krb5_key_salt_tuple   * ks_tuple,
0762                   int                     ks_tuple_count,
0763                   char          * passwd,
0764                   int                     new_kvno,
0765                   krb5_boolean    keepold,
0766                   krb5_db_entry * db_entry);
0767 
0768 krb5_error_code
0769 krb5_dbe_def_decrypt_key_data( krb5_context             context,
0770                                const krb5_keyblock    * mkey,
0771                                const krb5_key_data    * key_data,
0772                                krb5_keyblock          * dbkey,
0773                                krb5_keysalt           * keysalt);
0774 
0775 krb5_error_code
0776 krb5_dbe_def_encrypt_key_data( krb5_context             context,
0777                                const krb5_keyblock    * mkey,
0778                                const krb5_keyblock    * dbkey,
0779                                const krb5_keysalt     * keysalt,
0780                                int                      keyver,
0781                                krb5_key_data          * key_data);
0782 
0783 krb5_error_code
0784 krb5_db_def_rename_principal( krb5_context kcontext,
0785                               krb5_const_principal source,
0786                               krb5_const_principal target);
0787 
0788 krb5_error_code
0789 krb5_db_create_policy( krb5_context kcontext,
0790                        osa_policy_ent_t policy);
0791 
0792 krb5_error_code
0793 krb5_db_get_policy ( krb5_context kcontext,
0794                      char *name,
0795                      osa_policy_ent_t *policy );
0796 
0797 krb5_error_code
0798 krb5_db_put_policy( krb5_context kcontext,
0799                     osa_policy_ent_t policy);
0800 
0801 krb5_error_code
0802 krb5_db_iter_policy( krb5_context kcontext,
0803                      char *match_entry,
0804                      osa_adb_iter_policy_func func,
0805                      void *data);
0806 
0807 krb5_error_code
0808 krb5_db_delete_policy( krb5_context kcontext,
0809                        char *policy);
0810 
0811 void
0812 krb5_db_free_policy( krb5_context kcontext,
0813                      osa_policy_ent_t policy);
0814 
0815 
0816 krb5_error_code
0817 krb5_db_set_context(krb5_context, void *db_context);
0818 
0819 krb5_error_code
0820 krb5_db_get_context(krb5_context, void **db_context);
0821 
0822 void
0823 krb5_dbe_free_key_data_contents(krb5_context, krb5_key_data *);
0824 
0825 void
0826 krb5_dbe_free_key_list(krb5_context, krb5_keylist_node *);
0827 
0828 void
0829 krb5_dbe_free_actkvno_list(krb5_context, krb5_actkvno_node *);
0830 
0831 void
0832 krb5_dbe_free_mkey_aux_list(krb5_context, krb5_mkey_aux_node *);
0833 
0834 void
0835 krb5_dbe_free_tl_data(krb5_context, krb5_tl_data *);
0836 
0837 void
0838 krb5_dbe_free_strings(krb5_context, krb5_string_attr *, int count);
0839 
0840 void
0841 krb5_dbe_free_string(krb5_context, char *);
0842 
0843 /*
0844  * Register the KDB keytab type, allowing "KDB:" to be used as a keytab name.
0845  * For this type to work, the context used for keytab operations must have an
0846  * associated database handle (via krb5_db_open()).
0847  */
0848 krb5_error_code krb5_db_register_keytab(krb5_context context);
0849 
0850 #define KRB5_KDB_DEF_FLAGS      0
0851 
0852 #define KDB_MAX_DB_NAME                 128
0853 #define KDB_REALM_SECTION               "realms"
0854 #define KDB_MODULE_POINTER              "database_module"
0855 #define KDB_MODULE_DEF_SECTION          "dbdefaults"
0856 #define KDB_MODULE_SECTION              "dbmodules"
0857 #define KDB_LIB_POINTER                 "db_library"
0858 #define KDB_DATABASE_CONF_FILE          DEFAULT_SECURE_PROFILE_PATH
0859 #define KDB_DATABASE_ENV_PROF           KDC_PROFILE_ENV
0860 
0861 #define KRB5_KDB_OPEN_RW                0
0862 #define KRB5_KDB_OPEN_RO                1
0863 
0864 #define KRB5_KDB_OPT_SET_DB_NAME        0
0865 #define KRB5_KDB_OPT_SET_LOCK_MODE      1
0866 
0867 /*
0868  * This number indicates the date of the last incompatible change to the DAL.
0869  * The maj_ver field of the module's vtable structure must match this version.
0870  */
0871 #define KRB5_KDB_DAL_MAJOR_VERSION 9
0872 
0873 /*
0874  * Note the following when converting a module to DAL version 9:
0875  *
0876  * - get_authdata_info() and sign_authdata() have been removed, and issue_pac()
0877  *   has been added.
0878  *
0879  * - check_allowed_to_delegate() must handle a null proxy argument, returning
0880  *   success if server has any authorized delegation targets in the traditional
0881  *   scheme.
0882  *
0883  * - allowed_to_delegate_from() accepts a krb5_pac parameter (in place
0884  *   server_ad_info) for the impersonator's PAC.
0885  *
0886  * - check_allowed_to_delegate() and allowed_to_delegate_from() must return
0887  *   KRB5KDC_ERR_BADOPTION on authorization failure.
0888  *
0889  * - the KRB5_KDB_FLAG_ISSUE_PAC and KRB5_FLAG_CLIENT_REFERRALS_ONLY flags have
0890  *   been combined into KRB5_KDB_FLAG_CLIENT.
0891  *
0892  * - the KRB5_KDB_FLAG_CANONICALIZE flag has been renamed to
0893  *   KRB5_KDB_FLAG_REFERRAL_OK, and is only passed to get_principal() when a
0894  *   realm referral is allowed (AS client and TGS server lookups, when the
0895  *   CANONICALIZE option is requested or, for AS requests, when the client is
0896  *   an enterprise principal).  As of DAL version 8 the KDB module should
0897  *   always canonicalize aliases within a realm; the KDC will decide whether to
0898  *   use the original or canonical principal.
0899  */
0900 
0901 /*
0902  * A krb5_context can hold one database object.  Modules should use
0903  * krb5_db_set_context and krb5_db_get_context to store state associated with
0904  * the database object.
0905  *
0906  * Some module functions are mandatory for KDC operation; others are optional
0907  * or apply only to administrative operations.  If a function is optional, a
0908  * module can leave the function pointer as NULL.  Alternatively, modules can
0909  * return KRB5_PLUGIN_OP_NOTSUPP when asked to perform an inapplicable action.
0910  *
0911  * Some module functions have default implementations which will call back into
0912  * the vtable interface.  Leave these functions as NULL to use the default
0913  * implementations.
0914  *
0915  * The documentation in these comments describes the DAL as it is currently
0916  * implemented and used, not as it should be.  So if anything seems off, that
0917  * probably means the current state of things is off.
0918  *
0919  * Modules must allocate memory for principal entries, policy entries, and
0920  * other structures using an allocator compatible with malloc() as seen by
0921  * libkdb5 and libkrb5.  Modules may link against libkdb5 and call
0922  * krb5_db_alloc() to be certain that the same malloc implementation is used.
0923  */
0924 
0925 typedef struct _kdb_vftabl {
0926     short int maj_ver;
0927     short int min_ver;
0928 
0929     /*
0930      * Mandatory: Invoked after the module library is loaded, when the first DB
0931      * using the module is opened, across all contexts.
0932      */
0933     krb5_error_code (*init_library)(void);
0934 
0935     /*
0936      * Mandatory: Invoked before the module library is unloaded, after the last
0937      * DB using the module is closed, across all contexts.
0938      */
0939     krb5_error_code (*fini_library)(void);
0940 
0941     /*
0942      * Mandatory: Initialize a database object.  Profile settings should be
0943      * read from conf_section inside KDB_MODULE_SECTION.  db_args communicates
0944      * command-line arguments for module-specific flags.  mode will be one of
0945      * KRB5_KDB_OPEN_{RW,RO} or'd with one of
0946      * KRB5_KDB_SRV_TYPE_{KDC,ADMIN,PASSWD,OTHER}.
0947      */
0948     krb5_error_code (*init_module)(krb5_context kcontext, char *conf_section,
0949                                    char **db_args, int mode);
0950 
0951     /*
0952      * Mandatory: Finalize the database object contained in a context.  Free
0953      * any state contained in the db_context pointer and null it out.
0954      */
0955     krb5_error_code (*fini_module)(krb5_context kcontext);
0956 
0957     /*
0958      * Optional: Initialize a database object while creating the underlying
0959      * database.  conf_section and db_args have the same meaning as in
0960      * init_module.  This function may return an error if the database already
0961      * exists.  Used by kdb5_util create.
0962      *
0963      * If db_args contains the value "temporary", the module should create an
0964      * exclusively locked side copy of the database suitable for loading in a
0965      * propagation from primary to replica.  This side copy will later be
0966      * promoted with promote_db, allowing complete updates of the DB with no
0967      * loss in read availability.  If the module cannot comply with this
0968      * architecture, it should return an error.
0969      */
0970     krb5_error_code (*create)(krb5_context kcontext, char *conf_section,
0971                               char **db_args);
0972 
0973     /*
0974      * Optional: Destroy a database.  conf_section and db_args have the same
0975      * meaning as in init_module.  Used by kdb5_util destroy.  In current
0976      * usage, the database is destroyed while open, so the module should handle
0977      * that.
0978      */
0979     krb5_error_code (*destroy)(krb5_context kcontext, char *conf_section,
0980                                char **db_args);
0981 
0982     /*
0983      * Deprecated: No longer used as of krb5 1.10; can be removed in the next
0984      * DAL revision.  Modules should leave as NULL.
0985      */
0986     krb5_error_code (*get_age)(krb5_context kcontext, char *db_name,
0987                                time_t *age);
0988 
0989     /*
0990      * Optional: Lock the database, with semantics depending on the mode
0991      * argument:
0992      *
0993      * KRB5_DB_LOCKMODE_SHARED: Lock may coexist with other shared locks.
0994      * KRB5_DB_LOCKMODE_EXCLUSIVE: Lock may not coexist with other locks.
0995      * KRB5_DB_LOCKMODE_PERMANENT: Exclusive lock surviving process exit.
0996      *
0997      * Used by the "kadmin lock" command, incremental propagation, and
0998      * kdb5_util dump.  Incremental propagation support requires shared locks
0999      * to operate.  kdb5_util dump will continue unlocked if the module returns
1000      * KRB5_PLUGIN_OP_NOTSUPP.
1001      */
1002     krb5_error_code (*lock)(krb5_context kcontext, int mode);
1003 
1004     /* Optional: Release a lock created with db_lock. */
1005     krb5_error_code (*unlock)(krb5_context kcontext);
1006 
1007     /*
1008      * Mandatory: Set *entry to an allocated entry for the principal
1009      * search_for.  If the principal is not found, return KRB5_KDB_NOENTRY.
1010      *
1011      * The meaning of flags are as follows:
1012      *
1013      * KRB5_KDB_FLAG_REFERRAL_OK: Set by the KDC when looking up entries for an
1014      *     AS client with canonicalization requested or for an enterprise
1015      *     principal, or for a TGS request server with canonicalization
1016      *     requested.  Determines whether the module should return out-of-realm
1017      *     referrals.
1018      *
1019      * KRB5_KDB_FLAG_CLIENT: Set by the KDC when looking up a client principal
1020      *     during an AS or TGS request.  Affects how the module should return
1021      *     out-of-realm referrals.
1022      *
1023      * KRB5_KDB_FLAG_MAP_PRINCIPALS: Set by the KDC when looking up the client
1024      *     entry during TGS requests, except for S4U TGS requests and requests
1025      *     where the server entry has the KRB5_KDB_NO_AUTH_DATA_REQUIRED
1026      *     attribute.  Indicates that the module should map foreign principals
1027      *     to local principals if it supports doing so.
1028      *
1029      * KRB5_KDB_FLAG_PROTOCOL_TRANSITION: Set by the KDC when looking up the
1030      *     client entry during an S4U2Self TGS request.  This affects the PAC
1031      *     information which should be included when authorization data is
1032      *     generated; see the Microsoft S4U specification for details.
1033      *
1034      * KRB5_KDB_FLAG_CONSTRAINED_DELEGATION: Set by the KDC when looking up the
1035      *     client entry during an S4U2Proxy TGS request.  Also affects PAC
1036      *     generation.
1037      *
1038      * KRB5_KDB_FLAG_CROSS_REALM: Set by the KDC after looking up a server
1039      *     entry during a TGS request, if the header ticket was issued by a
1040      *     different realm.
1041      *
1042      * KRB5_KDB_FLAG_ISSUING_REFERRAL: Set by the KDC after looking up a server
1043      *     entry during a TGS request, if the requested server principal is not
1044      *     part of the realm being served, and a referral or alternate TGT will
1045      *     be issued instead.
1046      *
1047      * A module may return an in-realm alias by setting (*entry)->princ to the
1048      * canonical name.  The KDC will decide based on the request whether to use
1049      * the requested name or the canonical name in the issued ticket.
1050      *
1051      * A module can return a referral to another realm if flags contains
1052      * KRB5_KDB_FLAG_REFERRAL_OK.  If KRB5_KDB_FLAG_CLIENT is also set, the
1053      * module should return a referral by simply filling in an out-of-realm
1054      * name in (*entry)->princ and setting all other fields to NULL.
1055      * Otherwise, the module should return the entry for the cross-realm TGS of
1056      * the referred-to realm.
1057      */
1058     krb5_error_code (*get_principal)(krb5_context kcontext,
1059                                      krb5_const_principal search_for,
1060                                      unsigned int flags,
1061                                      krb5_db_entry **entry);
1062 
1063     /*
1064      * Optional: Create or modify a principal entry.  db_args communicates
1065      * command-line arguments for module-specific flags.
1066      *
1067      * The mask field of an entry indicates the changed fields.  Mask values
1068      * are defined in kadmin's admin.h header.  If KADM5_PRINCIPAL is set in
1069      * the mask, the entry is new; otherwise it already exists.  All fields of
1070      * an entry are expected to contain correct values, regardless of whether
1071      * they are specified in the mask, so it is acceptable for a module to
1072      * ignore the mask and update the entire entry.
1073      */
1074     krb5_error_code (*put_principal)(krb5_context kcontext,
1075                                      krb5_db_entry *entry, char **db_args);
1076 
1077     /*
1078      * Optional: Delete the entry for the principal search_for.  If the
1079      * principal did not exist, return KRB5_KDB_NOENTRY.
1080      */
1081     krb5_error_code (*delete_principal)(krb5_context kcontext,
1082                                         krb5_const_principal search_for);
1083 
1084     /*
1085      * Optional with default: Rename a principal.  If the source principal does
1086      * not exist, return KRB5_KDB_NOENTRY.  If the target exists, return an
1087      * error.
1088      *
1089      * NOTE: If the module chooses to implement a custom function for renaming
1090      * a principal instead of using the default, then rename operations will
1091      * fail if iprop logging is enabled.
1092      */
1093     krb5_error_code (*rename_principal)(krb5_context kcontext,
1094                                         krb5_const_principal source,
1095                                         krb5_const_principal target);
1096 
1097     /*
1098      * Optional: For each principal entry in the database, invoke func with the
1099      * arguments func_arg and the entry data.  If match_entry is specified, the
1100      * module may narrow the iteration to principal names matching that regular
1101      * expression; a module may alternatively ignore match_entry.
1102      */
1103     krb5_error_code (*iterate)(krb5_context kcontext,
1104                                char *match_entry,
1105                                int (*func)(krb5_pointer, krb5_db_entry *),
1106                                krb5_pointer func_arg, krb5_flags iterflags);
1107 
1108     /*
1109      * Optional: Create a password policy entry.  Return an error if the policy
1110      * already exists.
1111      */
1112     krb5_error_code (*create_policy)(krb5_context kcontext,
1113                                      osa_policy_ent_t policy);
1114 
1115     /*
1116      * Optional: Set *policy to the policy entry of the specified name.  If the
1117      * entry does not exist, return KRB5_KDB_NOENTRY.
1118      */
1119     krb5_error_code (*get_policy)(krb5_context kcontext, char *name,
1120                                   osa_policy_ent_t *policy);
1121 
1122     /*
1123      * Optional: Modify an existing password policy entry to match the values
1124      * in policy.  Return an error if the policy does not already exist.
1125      */
1126     krb5_error_code (*put_policy)(krb5_context kcontext,
1127                                   osa_policy_ent_t policy);
1128 
1129     /*
1130      * Optional: For each password policy entry in the database, invoke func
1131      * with the arguments data and the entry data.  If match_entry is
1132      * specified, the module may narrow the iteration to policy names matching
1133      * that regular expression; a module may alternatively ignore match_entry.
1134      */
1135     krb5_error_code (*iter_policy)(krb5_context kcontext, char *match_entry,
1136                                    osa_adb_iter_policy_func func,
1137                                    void *data);
1138 
1139     /*
1140      * Optional: Delete the password policy entry with the name policy.  Return
1141      * an error if the entry does not exist.
1142      */
1143     krb5_error_code (*delete_policy)(krb5_context kcontext, char *policy);
1144 
1145     /*
1146      * Optional with default: Retrieve a master keyblock from the stash file
1147      * db_args, filling in *key and *kvno.  mname is the name of the master
1148      * principal for the realm.
1149      *
1150      * The default implementation reads the master keyblock from a keytab or
1151      * old-format stash file.
1152      */
1153     krb5_error_code (*fetch_master_key)(krb5_context kcontext,
1154                                         krb5_principal mname,
1155                                         krb5_keyblock *key, krb5_kvno *kvno,
1156                                         char *db_args);
1157 
1158     /*
1159      * Optional with default: Given a keyblock for some version of the
1160      * database's master key, fetch the decrypted master key values from the
1161      * database and store the list into *mkeys_list.  The caller will free
1162      * *mkeys_list using a libkdb5 function which uses the standard free()
1163      * function, so the module must not use a custom allocator.
1164      *
1165      * The caller may not know the version number of the master key it has, in
1166      * which case it will pass IGNORE_VNO.
1167      *
1168      * The default implementation ignores kvno and tries the key against the
1169      * current master key data and all KRB5_TL_MKEY_AUX values, which contain
1170      * copies of the master keys encrypted with old master keys.
1171      */
1172     krb5_error_code (*fetch_master_key_list)(krb5_context kcontext,
1173                                              krb5_principal mname,
1174                                              const krb5_keyblock *key,
1175                                              krb5_keylist_node **mkeys_list);
1176 
1177     /*
1178      * Optional with default: Save a list of master keyblocks, obtained from
1179      * fetch_master_key_list, into the stash file db_arg.  The caller will set
1180      * master_pwd to NULL, so the module should just ignore it.  mname is the
1181      * name of the master principal for the realm.
1182      *
1183      * The default implementation saves the list of master keys in a
1184      * keytab-format file.
1185      */
1186     krb5_error_code (*store_master_key_list)(krb5_context kcontext,
1187                                              char *db_arg,
1188                                              krb5_principal mname,
1189                                              krb5_keylist_node *keylist,
1190                                              char *master_pwd);
1191 
1192     /*
1193      * Optional with default: Starting at position *start, scan the key data of
1194      * a database entry for a key matching the enctype ktype, the salt type
1195      * stype, and the version kvno.  Store the resulting key into *kdatap and
1196      * set *start to the position after the key found.  If ktype is negative,
1197      * match any enctype.  If stype is negative, match any salt type.  If kvno
1198      * is zero or negative, find the most recent key version satisfying the
1199      * other constraints.
1200      */
1201     krb5_error_code (*dbe_search_enctype)(krb5_context kcontext,
1202                                           krb5_db_entry *dbentp,
1203                                           krb5_int32 *start, krb5_int32 ktype,
1204                                           krb5_int32 stype, krb5_int32 kvno,
1205                                           krb5_key_data **kdatap);
1206 
1207 
1208     /*
1209      * Optional with default: Change the key data for db_entry to include keys
1210      * derived from the password passwd in each of the specified key-salt
1211      * types, at version new_kvno.  Discard the old key data if keepold is not
1212      * set.
1213      *
1214      * The default implementation uses the keyblock master_key to encrypt each
1215      * new key, via the function encrypt_key_data.
1216      */
1217     krb5_error_code (*change_pwd)(krb5_context context,
1218                                   krb5_keyblock *master_key,
1219                                   krb5_key_salt_tuple *ks_tuple,
1220                                   int ks_tuple_count, char *passwd,
1221                                   int new_kvno, krb5_boolean keepold,
1222                                   krb5_db_entry *db_entry);
1223 
1224     /*
1225      * Optional: Promote a temporary database to be the live one.  context must
1226      * be initialized with an exclusively locked database created with the
1227      * "temporary" db_arg.  On success, the database object contained in
1228      * context will be finalized.
1229      *
1230      * This method is used by kdb5_util load to replace the live database with
1231      * minimal loss of read availability.
1232      */
1233     krb5_error_code (*promote_db)(krb5_context context, char *conf_section,
1234                                   char **db_args);
1235 
1236     /*
1237      * Optional with default: Decrypt the key in key_data with master keyblock
1238      * mkey, placing the result into dbkey.  Copy the salt from key_data, if
1239      * any, into keysalt.  Either dbkey or keysalt may be left unmodified on
1240      * successful return if key_data does not contain key or salt information.
1241      *
1242      * The default implementation expects the encrypted key (in krb5_c_encrypt
1243      * format) to be stored in key_data_contents[0], with length given by
1244      * key_data_length[0].  If key_data_ver is 2, it expects the salt to be
1245      * stored, unencrypted, in key_data_contents[1], with length given by
1246      * key_data_length[1].
1247      */
1248     krb5_error_code (*decrypt_key_data)(krb5_context kcontext,
1249                                         const krb5_keyblock *mkey,
1250                                         const krb5_key_data *key_data,
1251                                         krb5_keyblock *dbkey,
1252                                         krb5_keysalt *keysalt);
1253 
1254     /*
1255      * Optional with default: Encrypt dbkey with master keyblock mkey, placing
1256      * the result into key_data along with keysalt.
1257      *
1258      * The default implementation stores the encrypted key (in krb5_c_encrypt
1259      * format) in key_data_contents[0] and the length in key_data_length[0].
1260      * If keysalt is specified, it sets key_data_ver to 2, and stores the salt
1261      * in key_data_contents[1] and its length in key_data_length[1].  If
1262      * keysalt is not specified, key_data_ver is set to 1.
1263      */
1264     krb5_error_code (*encrypt_key_data)(krb5_context kcontext,
1265                                         const krb5_keyblock *mkey,
1266                                         const krb5_keyblock *dbkey,
1267                                         const krb5_keysalt *keysalt,
1268                                         int keyver, krb5_key_data *key_data);
1269 
1270     /*
1271      * Optional: Perform a policy check on a cross-realm ticket's transited
1272      * field.  Return 0 if the check authoritatively succeeds,
1273      * KRB5_PLUGIN_NO_HANDLE to use the core transited-checking mechanisms, or
1274      * another error (other than KRB5_PLUGIN_OP_NOTSUPP) if the check fails.
1275      */
1276     krb5_error_code (*check_transited_realms)(krb5_context kcontext,
1277                                               const krb5_data *tr_contents,
1278                                               const krb5_data *client_realm,
1279                                               const krb5_data *server_realm);
1280 
1281     /*
1282      * Optional: Perform a policy check on an AS request, in addition to the
1283      * standard policy checks.  Return 0 if the AS request is allowed.  If the
1284      * AS request is not allowed:
1285      *   - Place a short string literal into *status.
1286      *   - If desired, place data into e_data.  Any data placed here will be
1287      *     freed by the caller using the standard free function.
1288      *   - Return an appropriate error (such as KRB5KDC_ERR_POLICY).
1289      */
1290     krb5_error_code (*check_policy_as)(krb5_context kcontext,
1291                                        krb5_kdc_req *request,
1292                                        krb5_db_entry *client,
1293                                        krb5_db_entry *server,
1294                                        krb5_timestamp kdc_time,
1295                                        const char **status,
1296                                        krb5_pa_data ***e_data);
1297 
1298     /*
1299      * Optional: Perform a policy check on a TGS request, in addition to the
1300      * standard policy checks.  Return 0 if the TGS request is allowed.  If the
1301      * TGS request is not allowed:
1302      *   - Place a short string literal into *status.
1303      *   - If desired, place data into e_data.  Any data placed here will be
1304      *     freed by the caller using the standard free function.
1305      *   - Return an appropriate error (such as KRB5KDC_ERR_POLICY).
1306      * The input parameter ticket contains the TGT used in the TGS request.
1307      */
1308     krb5_error_code (*check_policy_tgs)(krb5_context kcontext,
1309                                         krb5_kdc_req *request,
1310                                         krb5_db_entry *server,
1311                                         krb5_ticket *ticket,
1312                                         const char **status,
1313                                         krb5_pa_data ***e_data);
1314 
1315     /*
1316      * Optional: This method informs the module of a successful or unsuccessful
1317      * AS request.
1318      */
1319     void (*audit_as_req)(krb5_context kcontext, krb5_kdc_req *request,
1320                          const krb5_address *local_addr,
1321                          const krb5_address *remote_addr,
1322                          krb5_db_entry *client, krb5_db_entry *server,
1323                          krb5_timestamp authtime, krb5_error_code error_code);
1324 
1325     /* Note: there is currently no method for auditing TGS requests. */
1326 
1327     /*
1328      * Optional: This method informs the module of a request to reload
1329      * configuration or other state (that is, the KDC received a SIGHUP).
1330      */
1331     void (*refresh_config)(krb5_context kcontext);
1332 
1333     /*
1334      * Optional: Perform a policy check on server being allowed to obtain
1335      * tickets from client to proxy.  If proxy is NULL, check if server has any
1336      * authorized delegation targets (client will also be NULL in this case).
1337      * (Note that proxy is the target of the delegation, not the delegating
1338      * service; the term "proxy" is from the viewpoint of the delegating
1339      * service asking another service to perform some of its work in the
1340      * authentication context of the client.  This terminology comes from the
1341      * Microsoft S4U protocol documentation.)  Return 0 if policy allows
1342      * delegation to the specified target (or to any target if proxy is NULL),
1343      * or KRB5KDC_ERR_BADOPTION if not.  If this method is not implemented, all
1344      * S4U2Proxy delegation requests will be rejected.
1345      */
1346     krb5_error_code (*check_allowed_to_delegate)(krb5_context context,
1347                                                  krb5_const_principal client,
1348                                                  const krb5_db_entry *server,
1349                                                  krb5_const_principal proxy);
1350 
1351     /*
1352      * Optional: Free the e_data pointer of a database entry.  If this method
1353      * is not implemented, the e_data pointer in principal entries will be
1354      * freed with free() as seen by libkdb5.
1355      */
1356     void (*free_principal_e_data)(krb5_context kcontext, krb5_octet *e_data);
1357 
1358     /*
1359      * Optional: get a client principal entry based on an X.509 certificate.
1360      *
1361      * If flags include KRB5_KDB_FLAG_REFERRAL_OK, the certificate was
1362      * presented in an AS request.  princ->realm indicates the request realm,
1363      * but the data components should be ignored.  The module can return an
1364      * out-of-realm client referral as it would for get_principal().
1365      *
1366      * Otherwise, princ is from a TGS request.  If it contains data components
1367      * (and not just a realm), the module should verify that it is the same as
1368      * the lookup result for client_cert.  The module should not return a
1369      * referral.
1370      */
1371     krb5_error_code (*get_s4u_x509_principal)(krb5_context kcontext,
1372                                               const krb5_data *client_cert,
1373                                               krb5_const_principal princ,
1374                                               unsigned int flags,
1375                                               krb5_db_entry **entry_out);
1376 
1377     /*
1378      * Optional: Perform a policy check on server being allowed to obtain
1379      * tickets from client to proxy.  This method is similar to
1380      * check_allowed_to_delegate, but it operates on the target server DB entry
1381      * (called "proxy" here as in Microsoft's protocol documentation) rather
1382      * than the intermediate server entry.  server_pac is the verified PAC from
1383      * the authdata of the intermediate server.  Return 0 if policy allows the
1384      * delegation, or KRB5KDC_ERR_BADOPTION if not.
1385      *
1386      * This method is called for S4U2Proxy requests and implements the
1387      * resource-based constrained delegation variant, which can support
1388      * cross-realm delegation.  If this method is not implemented or if it
1389      * returns a policy error, the KDC will fall back to
1390      * check_allowed_to_delegate if the intermediate and target servers are in
1391      * the same realm and the evidence ticket is forwardable.
1392      */
1393     krb5_error_code (*allowed_to_delegate_from)(krb5_context context,
1394                                                 krb5_const_principal client,
1395                                                 krb5_const_principal server,
1396                                                 krb5_pac server_pac,
1397                                                 const krb5_db_entry *proxy);
1398 
1399     /*
1400      * Optional: Add buffers to new_pac using krb5_pac_add_buffer() before it
1401      * is signed.
1402      *
1403      * The caller will handle the following buffer types, so do not copy or add
1404      * them:
1405      *
1406      *   KRB5_PAC_SERVER_CHECKSUM
1407      *   KRB5_PAC_PRIVSVR_CHECKSUM
1408      *   KRB5_PAC_TICKET_CHECKSUM
1409      *   KRB5_PAC_CLIENT_INFO
1410      *   KRB5_PAC_DELEGATION_INFO
1411      *
1412      * For TGS requests, old_pac is the PAC of the header ticket, except when
1413      * KRB5_KDB_FLAG_CONTRAINED_DELEGATION is present in flags, in which case
1414      * it is the PAC of the second ticket.  If
1415      * KRB5_KDB_FLAG_PROTOCOL_TRANSITION is present in flags and client is not
1416      * NULL, old_pac is the PAC of the requesting service, not the subject of
1417      * the S4U2Self request, and its buffers should not be copied into new_pac.
1418      * The signatures and PAC_CLIENT_INFO of old_pac have been verified by the
1419      * caller.
1420      *
1421      * If replaced_reply_key is not null, the request is an AS request and the
1422      * reply key was replaced by a preauth mechanism such as PKINIT, meaning
1423      * the Kerberos password or long-term key was not used.  The module may use
1424      * this key to encrypt a PAC_CREDENTIALS_INFO buffer containing credentials
1425      * (such as an NTLM hash) that the client would ordinarily derive from the
1426      * Kerberos password or long-term key.
1427      *
1428      * server is the database entry of the server the ticket will be issued to,
1429      * which may be a referral TGS.
1430      *
1431      * signing_krbtgt is the database entry of the krbtgt principal used to
1432      * verify old_pac (or null if old_pac is null).  If
1433      * KRB5_KDB_FLAG_CROSS_REALM is present in flags, this entry will be an
1434      * incoming cross-realm TGS, and the PAC fields should undergo appropriate
1435      * filtering based on the trust level of the cross-realm relationship.
1436      *
1437      * auth_indicators points to NULL or a null-terminated list of krb5_data
1438      * pointers, each containing an authentication indicator (RFC 8129).  The
1439      * method may modify this list, or free it and replace *auth_indicators
1440      * with NULL, to change which auth indicators will be included in the
1441      * ticket.
1442      */
1443     krb5_error_code (*issue_pac)(krb5_context context, unsigned int flags,
1444                                  krb5_db_entry *client,
1445                                  krb5_keyblock *replaced_reply_key,
1446                                  krb5_db_entry *server,
1447                                  krb5_db_entry *signing_krbtgt,
1448                                  krb5_timestamp authtime, krb5_pac old_pac,
1449                                  krb5_pac new_pac,
1450                                  krb5_data ***auth_indicators);
1451 
1452     /* End of minor version 0 for major version 9. */
1453 } kdb_vftabl;
1454 
1455 #endif /* !defined(_WIN32) */
1456 
1457 #endif /* KRB5_KDB5__ */