kdb.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2. /*
  3. * Copyright 1990, 1991, 2016 by the Massachusetts Institute of Technology.
  4. * All Rights Reserved.
  5. *
  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.
  10. *
  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.
  24. */
  25. /*
  26. * Copyright (C) 1998 by the FundsXpress, INC.
  27. *
  28. * All rights reserved.
  29. *
  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.
  34. *
  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.
  45. *
  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.
  49. */
  50. /*
  51. * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  52. * Use is subject to license terms.
  53. */
  54. /* KDC Database interface definitions */
  55. /* This API is not considered as stable as the main krb5 API.
  56. *
  57. * - We may make arbitrary incompatible changes between feature
  58. * releases (e.g. from 1.7 to 1.8).
  59. * - We will make some effort to avoid making incompatible changes for
  60. * bugfix releases, but will make them if necessary.
  61. */
  62. #ifndef KRB5_KDB5__
  63. #define KRB5_KDB5__
  64. #include <krb5.h>
  65. /* This version will be incremented when incompatible changes are made to the
  66. * KDB API, and will be kept in sync with the libkdb major version. */
  67. #define KRB5_KDB_API_VERSION 10
  68. /* Salt types */
  69. #define KRB5_KDB_SALTTYPE_NORMAL 0
  70. /* #define KRB5_KDB_SALTTYPE_V4 1 */
  71. #define KRB5_KDB_SALTTYPE_NOREALM 2
  72. #define KRB5_KDB_SALTTYPE_ONLYREALM 3
  73. #define KRB5_KDB_SALTTYPE_SPECIAL 4
  74. /* #define KRB5_KDB_SALTTYPE_AFS3 5 */
  75. #define KRB5_KDB_SALTTYPE_CERTHASH 6
  76. /* Attributes */
  77. #define KRB5_KDB_DISALLOW_POSTDATED 0x00000001
  78. #define KRB5_KDB_DISALLOW_FORWARDABLE 0x00000002
  79. #define KRB5_KDB_DISALLOW_TGT_BASED 0x00000004
  80. #define KRB5_KDB_DISALLOW_RENEWABLE 0x00000008
  81. #define KRB5_KDB_DISALLOW_PROXIABLE 0x00000010
  82. #define KRB5_KDB_DISALLOW_DUP_SKEY 0x00000020
  83. #define KRB5_KDB_DISALLOW_ALL_TIX 0x00000040
  84. #define KRB5_KDB_REQUIRES_PRE_AUTH 0x00000080
  85. #define KRB5_KDB_REQUIRES_HW_AUTH 0x00000100
  86. #define KRB5_KDB_REQUIRES_PWCHANGE 0x00000200
  87. #define KRB5_KDB_DISALLOW_SVR 0x00001000
  88. #define KRB5_KDB_PWCHANGE_SERVICE 0x00002000
  89. #define KRB5_KDB_SUPPORT_DESMD5 0x00004000
  90. #define KRB5_KDB_NEW_PRINC 0x00008000
  91. #define KRB5_KDB_OK_AS_DELEGATE 0x00100000
  92. #define KRB5_KDB_OK_TO_AUTH_AS_DELEGATE 0x00200000 /* S4U2Self OK */
  93. #define KRB5_KDB_NO_AUTH_DATA_REQUIRED 0x00400000
  94. #define KRB5_KDB_LOCKDOWN_KEYS 0x00800000
  95. /* Creation flags */
  96. #define KRB5_KDB_CREATE_BTREE 0x00000001
  97. #define KRB5_KDB_CREATE_HASH 0x00000002
  98. /* Entry get flags */
  99. /* Okay to generate a referral on lookup */
  100. #define KRB5_KDB_FLAG_REFERRAL_OK 0x00000010
  101. /* Client principal lookup (client referrals only) */
  102. #define KRB5_KDB_FLAG_CLIENT 0x00000040
  103. /* Map cross-realm principals */
  104. #define KRB5_KDB_FLAG_MAP_PRINCIPALS 0x00000080
  105. /* Protocol transition */
  106. #define KRB5_KDB_FLAG_PROTOCOL_TRANSITION 0x00000100
  107. /* Constrained delegation */
  108. #define KRB5_KDB_FLAG_CONSTRAINED_DELEGATION 0x00000200
  109. /* User-to-user */
  110. #define KRB5_KDB_FLAG_USER_TO_USER 0x00000800
  111. /* Cross-realm */
  112. #define KRB5_KDB_FLAG_CROSS_REALM 0x00001000
  113. /* Issuing referral */
  114. #define KRB5_KDB_FLAG_ISSUING_REFERRAL 0x00004000
  115. #define KRB5_KDB_FLAGS_S4U ( KRB5_KDB_FLAG_PROTOCOL_TRANSITION | \
  116. KRB5_KDB_FLAG_CONSTRAINED_DELEGATION )
  117. /* KDB iteration flags */
  118. #define KRB5_DB_ITER_WRITE 0x00000001
  119. #define KRB5_DB_ITER_REV 0x00000002
  120. #define KRB5_DB_ITER_RECURSE 0x00000004
  121. /* String attribute names recognized by krb5 */
  122. #define KRB5_KDB_SK_SESSION_ENCTYPES "session_enctypes"
  123. #define KRB5_KDB_SK_REQUIRE_AUTH "require_auth"
  124. #if !defined(_WIN32)
  125. /*
  126. * Note --- these structures cannot be modified without changing the
  127. * database version number in libkdb.a, but should be expandable by
  128. * adding new tl_data types.
  129. */
  130. typedef struct _krb5_tl_data {
  131. struct _krb5_tl_data* tl_data_next; /* NOT saved */
  132. krb5_int16 tl_data_type;
  133. krb5_ui_2 tl_data_length;
  134. krb5_octet * tl_data_contents;
  135. } krb5_tl_data;
  136. /* String attributes (currently stored inside tl-data) map C string keys to
  137. * values. They can be set via kadmin and consumed by KDC plugins. */
  138. typedef struct krb5_string_attr_st {
  139. char *key;
  140. char *value;
  141. } krb5_string_attr;
  142. /*
  143. * If this ever changes up the version number and make the arrays be as
  144. * big as necessary.
  145. *
  146. * Currently the first type is the enctype and the second is the salt type.
  147. */
  148. typedef struct _krb5_key_data {
  149. krb5_int16 key_data_ver; /* Version */
  150. krb5_ui_2 key_data_kvno; /* Key Version */
  151. krb5_int16 key_data_type[2]; /* Array of types */
  152. krb5_ui_2 key_data_length[2]; /* Array of lengths */
  153. krb5_octet * key_data_contents[2]; /* Array of pointers */
  154. } krb5_key_data;
  155. #define KRB5_KDB_V1_KEY_DATA_ARRAY 2 /* # of array elements */
  156. typedef struct _krb5_keysalt {
  157. krb5_int16 type;
  158. krb5_data data; /* Length, data */
  159. } krb5_keysalt;
  160. /*
  161. * A principal database entry. Extensions to this structure currently use the
  162. * tl_data list. The e_data and e_length fields are not used by any calling
  163. * code except kdb5_util dump and load, which marshal and unmarshal the array
  164. * in the dump record. KDB modules may use these fields internally as long as
  165. * they set e_length appropriately (non-zero if the data should be marshalled
  166. * across dump and load, zero if not) and handle null e_data values in
  167. * caller-constructed principal entries.
  168. */
  169. typedef struct _krb5_db_entry_new {
  170. krb5_magic magic; /* NOT saved */
  171. krb5_ui_2 len;
  172. krb5_ui_4 mask; /* members currently changed/set */
  173. krb5_flags attributes;
  174. krb5_deltat max_life;
  175. krb5_deltat max_renewable_life;
  176. krb5_timestamp expiration; /* When the client expires */
  177. krb5_timestamp pw_expiration; /* When its passwd expires */
  178. krb5_timestamp last_success; /* Last successful passwd */
  179. krb5_timestamp last_failed; /* Last failed passwd attempt */
  180. krb5_kvno fail_auth_count; /* # of failed passwd attempt */
  181. krb5_int16 n_tl_data;
  182. krb5_int16 n_key_data;
  183. krb5_ui_2 e_length; /* Length of extra data */
  184. krb5_octet * e_data; /* Extra data to be saved */
  185. krb5_principal princ; /* Length, data */
  186. krb5_tl_data * tl_data; /* Linked list */
  187. /* key_data must be sorted by kvno in descending order. */
  188. krb5_key_data * key_data; /* Array */
  189. } krb5_db_entry;
  190. typedef struct _osa_policy_ent_t {
  191. int version;
  192. char *name;
  193. krb5_ui_4 pw_min_life;
  194. krb5_ui_4 pw_max_life;
  195. krb5_ui_4 pw_min_length;
  196. krb5_ui_4 pw_min_classes;
  197. krb5_ui_4 pw_history_num;
  198. krb5_ui_4 policy_refcnt; /* no longer used */
  199. /* Only valid if version > 1 */
  200. krb5_ui_4 pw_max_fail; /* pwdMaxFailure */
  201. krb5_ui_4 pw_failcnt_interval; /* pwdFailureCountInterval */
  202. krb5_ui_4 pw_lockout_duration; /* pwdLockoutDuration */
  203. /* Only valid if version > 2 */
  204. krb5_ui_4 attributes;
  205. krb5_ui_4 max_life;
  206. krb5_ui_4 max_renewable_life;
  207. char * allowed_keysalts;
  208. krb5_int16 n_tl_data;
  209. krb5_tl_data * tl_data;
  210. } osa_policy_ent_rec, *osa_policy_ent_t;
  211. typedef void (*osa_adb_iter_policy_func) (void *, osa_policy_ent_t);
  212. typedef struct __krb5_key_salt_tuple {
  213. krb5_enctype ks_enctype;
  214. krb5_int32 ks_salttype;
  215. } krb5_key_salt_tuple;
  216. #define KRB5_KDB_MAGIC_NUMBER 0xdbdbdbdb
  217. #define KRB5_KDB_V1_BASE_LENGTH 38
  218. #define KRB5_KDB_MAX_ALLOWED_KS_LEN 512
  219. #define KRB5_TL_LAST_PWD_CHANGE 0x0001
  220. #define KRB5_TL_MOD_PRINC 0x0002
  221. #define KRB5_TL_KADM_DATA 0x0003
  222. #define KRB5_TL_KADM5_E_DATA 0x0004
  223. #define KRB5_TL_RB1_CHALLENGE 0x0005
  224. #ifdef SECURID
  225. #define KRB5_TL_SECURID_STATE 0x0006
  226. #endif /* SECURID */
  227. #define KRB5_TL_USER_CERTIFICATE 0x0007
  228. #define KRB5_TL_MKVNO 0x0008
  229. #define KRB5_TL_ACTKVNO 0x0009
  230. #define KRB5_TL_MKEY_AUX 0x000a
  231. /* String attributes may not always be represented in tl-data. kadmin clients
  232. * must use the get_strings and set_string RPCs. */
  233. #define KRB5_TL_STRING_ATTRS 0x000b
  234. #define KRB5_TL_PAC_LOGON_INFO 0x0100 /* NDR encoded validation info */
  235. #define KRB5_TL_SERVER_REFERRAL 0x0200 /* ASN.1 encoded ServerReferralInfo */
  236. #define KRB5_TL_SVR_REFERRAL_DATA 0x0300 /* ASN.1 encoded PA-SVR-REFERRAL-DATA */
  237. #define KRB5_TL_CONSTRAINED_DELEGATION_ACL 0x0400 /* Each entry is a permitted SPN */
  238. #define KRB5_TL_LM_KEY 0x0500 /* LM OWF */
  239. #define KRB5_TL_X509_SUBJECT_ISSUER_NAME 0x0600 /* <I>IssuerDN<S>SubjectDN */
  240. #define KRB5_TL_LAST_ADMIN_UNLOCK 0x0700 /* Timestamp of admin unlock */
  241. #define KRB5_TL_DB_ARGS 0x7fff
  242. /* version number for KRB5_TL_ACTKVNO data */
  243. #define KRB5_TL_ACTKVNO_VER 1
  244. /* version number for KRB5_TL_MKEY_AUX data */
  245. #define KRB5_TL_MKEY_AUX_VER 1
  246. typedef struct _krb5_actkvno_node {
  247. struct _krb5_actkvno_node *next;
  248. krb5_kvno act_kvno;
  249. krb5_timestamp act_time;
  250. } krb5_actkvno_node;
  251. typedef struct _krb5_mkey_aux_node {
  252. struct _krb5_mkey_aux_node *next;
  253. krb5_kvno mkey_kvno; /* kvno of mkey protecting the latest_mkey */
  254. krb5_key_data latest_mkey; /* most recent mkey */
  255. } krb5_mkey_aux_node;
  256. typedef struct _krb5_keylist_node {
  257. krb5_keyblock keyblock;
  258. krb5_kvno kvno;
  259. struct _krb5_keylist_node *next;
  260. } krb5_keylist_node;
  261. /*
  262. * Determines the number of failed KDC requests before DISALLOW_ALL_TIX is set
  263. * on the principal.
  264. */
  265. #define KRB5_MAX_FAIL_COUNT 5
  266. /* XXX depends on knowledge of krb5_parse_name() formats */
  267. #define KRB5_KDB_M_NAME "K/M" /* Kerberos/Master */
  268. /* prompts used by default when reading the KDC password from the keyboard. */
  269. #define KRB5_KDC_MKEY_1 "Enter KDC database master key"
  270. #define KRB5_KDC_MKEY_2 "Re-enter KDC database master key to verify"
  271. extern char *krb5_mkey_pwd_prompt1;
  272. extern char *krb5_mkey_pwd_prompt2;
  273. /*
  274. * These macros specify the encoding of data within the database.
  275. *
  276. * Data encoding is little-endian.
  277. */
  278. #ifdef _KRB5_INT_H
  279. #include "k5-platform.h"
  280. #define krb5_kdb_decode_int16(cp, i16) \
  281. *((krb5_int16 *) &(i16)) = load_16_le(cp)
  282. #define krb5_kdb_decode_int32(cp, i32) \
  283. *((krb5_int32 *) &(i32)) = load_32_le(cp)
  284. #define krb5_kdb_encode_int16(i16, cp) store_16_le(i16, cp)
  285. #define krb5_kdb_encode_int32(i32, cp) store_32_le(i32, cp)
  286. #endif /* _KRB5_INT_H */
  287. #define KRB5_KDB_OPEN_RW 0
  288. #define KRB5_KDB_OPEN_RO 1
  289. #ifndef KRB5_KDB_SRV_TYPE_KDC
  290. #define KRB5_KDB_SRV_TYPE_KDC 0x0100
  291. #endif
  292. #ifndef KRB5_KDB_SRV_TYPE_ADMIN
  293. #define KRB5_KDB_SRV_TYPE_ADMIN 0x0200
  294. #endif
  295. /* 0x0300 was KRB5_KDB_SRV_TYPE_PASSWD but it is no longer used. */
  296. #ifndef KRB5_KDB_SRV_TYPE_OTHER
  297. #define KRB5_KDB_SRV_TYPE_OTHER 0x0400
  298. #endif
  299. #define KRB5_KDB_OPT_SET_DB_NAME 0
  300. #define KRB5_KDB_OPT_SET_LOCK_MODE 1
  301. #define KRB5_DB_LOCKMODE_SHARED 0x0001
  302. #define KRB5_DB_LOCKMODE_EXCLUSIVE 0x0002
  303. #define KRB5_DB_LOCKMODE_PERMANENT 0x0008
  304. /* libkdb.spec */
  305. krb5_error_code krb5_db_setup_lib_handle(krb5_context kcontext);
  306. krb5_error_code krb5_db_open( krb5_context kcontext, char **db_args, int mode );
  307. krb5_error_code krb5_db_init ( krb5_context kcontext );
  308. krb5_error_code krb5_db_create ( krb5_context kcontext, char **db_args );
  309. krb5_error_code krb5_db_inited ( krb5_context kcontext );
  310. krb5_error_code kdb5_db_create ( krb5_context kcontext, char **db_args );
  311. krb5_error_code krb5_db_fini ( krb5_context kcontext );
  312. const char * krb5_db_errcode2string ( krb5_context kcontext, long err_code );
  313. krb5_error_code krb5_db_destroy ( krb5_context kcontext, char **db_args );
  314. krb5_error_code krb5_db_promote ( krb5_context kcontext, char **db_args );
  315. krb5_error_code krb5_db_get_age ( krb5_context kcontext, char *db_name, time_t *t );
  316. krb5_error_code krb5_db_lock ( krb5_context kcontext, int lock_mode );
  317. krb5_error_code krb5_db_unlock ( krb5_context kcontext );
  318. krb5_error_code krb5_db_get_principal ( krb5_context kcontext,
  319. krb5_const_principal search_for,
  320. unsigned int flags,
  321. krb5_db_entry **entry );
  322. void krb5_db_free_principal ( krb5_context kcontext, krb5_db_entry *entry );
  323. krb5_error_code krb5_db_put_principal ( krb5_context kcontext,
  324. krb5_db_entry *entry );
  325. krb5_error_code krb5_db_delete_principal ( krb5_context kcontext,
  326. krb5_principal search_for );
  327. krb5_error_code krb5_db_rename_principal ( krb5_context kcontext,
  328. krb5_principal source,
  329. krb5_principal target );
  330. /*
  331. * Iterate over principals in the KDB. If the callback may write to the DB,
  332. * the caller must get an exclusive lock with krb5_db_lock before iterating,
  333. * and release it with krb5_db_unlock after iterating.
  334. */
  335. krb5_error_code krb5_db_iterate ( krb5_context kcontext,
  336. char *match_entry,
  337. int (*func) (krb5_pointer, krb5_db_entry *),
  338. krb5_pointer func_arg, krb5_flags iterflags );
  339. krb5_error_code krb5_db_store_master_key ( krb5_context kcontext,
  340. char *keyfile,
  341. krb5_principal mname,
  342. krb5_kvno kvno,
  343. krb5_keyblock *key,
  344. char *master_pwd);
  345. krb5_error_code krb5_db_store_master_key_list ( krb5_context kcontext,
  346. char *keyfile,
  347. krb5_principal mname,
  348. char *master_pwd);
  349. krb5_error_code krb5_db_fetch_mkey ( krb5_context context,
  350. krb5_principal mname,
  351. krb5_enctype etype,
  352. krb5_boolean fromkeyboard,
  353. krb5_boolean twice,
  354. char *db_args,
  355. krb5_kvno *kvno,
  356. krb5_data *salt,
  357. krb5_keyblock *key);
  358. krb5_error_code
  359. krb5_db_fetch_mkey_list( krb5_context context,
  360. krb5_principal mname,
  361. const krb5_keyblock * mkey );
  362. krb5_error_code
  363. krb5_dbe_find_enctype( krb5_context kcontext,
  364. krb5_db_entry *dbentp,
  365. krb5_int32 ktype,
  366. krb5_int32 stype,
  367. krb5_int32 kvno,
  368. krb5_key_data **kdatap);
  369. krb5_error_code krb5_dbe_search_enctype ( krb5_context kcontext,
  370. krb5_db_entry *dbentp,
  371. krb5_int32 *start,
  372. krb5_int32 ktype,
  373. krb5_int32 stype,
  374. krb5_int32 kvno,
  375. krb5_key_data **kdatap);
  376. krb5_error_code
  377. krb5_db_setup_mkey_name ( krb5_context context,
  378. const char *keyname,
  379. const char *realm,
  380. char **fullname,
  381. krb5_principal *principal);
  382. /**
  383. * Decrypts the key given in @@a key_data. If @a mkey is specified, that
  384. * master key is used. If @a mkey is NULL, then all master keys are tried.
  385. */
  386. krb5_error_code
  387. krb5_dbe_decrypt_key_data( krb5_context context,
  388. const krb5_keyblock * mkey,
  389. const krb5_key_data * key_data,
  390. krb5_keyblock * dbkey,
  391. krb5_keysalt * keysalt);
  392. krb5_error_code
  393. krb5_dbe_encrypt_key_data( krb5_context context,
  394. const krb5_keyblock * mkey,
  395. const krb5_keyblock * dbkey,
  396. const krb5_keysalt * keysalt,
  397. int keyver,
  398. krb5_key_data * key_data);
  399. krb5_error_code
  400. krb5_dbe_fetch_act_key_list(krb5_context context,
  401. krb5_principal princ,
  402. krb5_actkvno_node **act_key_list);
  403. krb5_error_code
  404. krb5_dbe_find_act_mkey( krb5_context context,
  405. krb5_actkvno_node * act_mkey_list,
  406. krb5_kvno * act_kvno,
  407. krb5_keyblock ** act_mkey);
  408. krb5_error_code
  409. krb5_dbe_find_mkey( krb5_context context,
  410. krb5_db_entry * entry,
  411. krb5_keyblock ** mkey);
  412. /* Set *mkvno to mkvno in entry tl_data, or 0 if not present. */
  413. krb5_error_code
  414. krb5_dbe_lookup_mkvno( krb5_context context,
  415. krb5_db_entry * entry,
  416. krb5_kvno * mkvno);
  417. krb5_keylist_node *
  418. krb5_db_mkey_list_alias( krb5_context kcontext );
  419. /* Set *mkvno to mkvno in entry tl_data, or minimum value from mkey_list. */
  420. krb5_error_code
  421. krb5_dbe_get_mkvno( krb5_context context,
  422. krb5_db_entry * entry,
  423. krb5_kvno * mkvno);
  424. krb5_error_code
  425. krb5_dbe_lookup_mod_princ_data( krb5_context context,
  426. krb5_db_entry * entry,
  427. krb5_timestamp * mod_time,
  428. krb5_principal * mod_princ);
  429. krb5_error_code
  430. krb5_dbe_lookup_mkey_aux( krb5_context context,
  431. krb5_db_entry * entry,
  432. krb5_mkey_aux_node ** mkey_aux_data_list);
  433. krb5_error_code
  434. krb5_dbe_update_mkvno( krb5_context context,
  435. krb5_db_entry * entry,
  436. krb5_kvno mkvno);
  437. krb5_error_code
  438. krb5_dbe_lookup_actkvno( krb5_context context,
  439. krb5_db_entry * entry,
  440. krb5_actkvno_node ** actkvno_list);
  441. krb5_error_code
  442. krb5_dbe_update_mkey_aux( krb5_context context,
  443. krb5_db_entry * entry,
  444. krb5_mkey_aux_node * mkey_aux_data_list);
  445. krb5_error_code
  446. krb5_dbe_update_actkvno(krb5_context context,
  447. krb5_db_entry * entry,
  448. const krb5_actkvno_node *actkvno_list);
  449. krb5_error_code
  450. krb5_dbe_update_last_pwd_change( krb5_context context,
  451. krb5_db_entry * entry,
  452. krb5_timestamp stamp);
  453. krb5_error_code
  454. krb5_dbe_update_last_admin_unlock( krb5_context context,
  455. krb5_db_entry * entry,
  456. krb5_timestamp stamp);
  457. krb5_error_code
  458. krb5_dbe_lookup_tl_data( krb5_context context,
  459. krb5_db_entry * entry,
  460. krb5_tl_data * ret_tl_data);
  461. krb5_error_code
  462. krb5_dbe_create_key_data( krb5_context context,
  463. krb5_db_entry * entry);
  464. krb5_error_code
  465. krb5_dbe_update_mod_princ_data( krb5_context context,
  466. krb5_db_entry * entry,
  467. krb5_timestamp mod_date,
  468. krb5_const_principal mod_princ);
  469. /*
  470. * These are wrappers around realloc() and free(). Applications and KDB
  471. * modules can use them when manipulating principal and policy entries to
  472. * ensure that they allocate and free memory in a manner compatible with the
  473. * library. Using libkrb5 or libkbd5 functions to construct values (such as
  474. * krb5_copy_principal() to construct the princ field of a krb5_db_entry) is
  475. * also safe. On Unix platforms, just using malloc() and free() is safe as
  476. * long as the application or module does not use a malloc replacement.
  477. */
  478. void *krb5_db_alloc( krb5_context kcontext,
  479. void *ptr,
  480. size_t size );
  481. void krb5_db_free( krb5_context kcontext,
  482. void *ptr);
  483. krb5_error_code
  484. krb5_dbe_lookup_last_pwd_change( krb5_context context,
  485. krb5_db_entry * entry,
  486. krb5_timestamp * stamp);
  487. krb5_error_code
  488. krb5_dbe_lookup_last_admin_unlock( krb5_context context,
  489. krb5_db_entry * entry,
  490. krb5_timestamp * stamp);
  491. /* Retrieve the set of string attributes in entry, in no particular order.
  492. * Free *strings_out with krb5_dbe_free_strings when done. */
  493. krb5_error_code
  494. krb5_dbe_get_strings(krb5_context context, krb5_db_entry *entry,
  495. krb5_string_attr **strings_out, int *count_out);
  496. /* Retrieve a single string attribute from entry, or NULL if there is no
  497. * attribute for key. Free *value_out with krb5_dbe_free_string when done. */
  498. krb5_error_code
  499. krb5_dbe_get_string(krb5_context context, krb5_db_entry *entry,
  500. const char *key, char **value_out);
  501. /* Change or add a string attribute in entry, or delete it if value is NULL. */
  502. krb5_error_code
  503. krb5_dbe_set_string(krb5_context context, krb5_db_entry *entry,
  504. const char *key, const char *value);
  505. krb5_error_code
  506. krb5_dbe_delete_tl_data( krb5_context context,
  507. krb5_db_entry * entry,
  508. krb5_int16 tl_data_type);
  509. krb5_error_code
  510. krb5_db_update_tl_data(krb5_context context,
  511. krb5_int16 * n_tl_datap,
  512. krb5_tl_data **tl_datap,
  513. krb5_tl_data * new_tl_data);
  514. krb5_error_code
  515. krb5_dbe_update_tl_data( krb5_context context,
  516. krb5_db_entry * entry,
  517. krb5_tl_data * new_tl_data);
  518. /* Compute the salt for a key data entry given the corresponding principal. */
  519. krb5_error_code
  520. krb5_dbe_compute_salt(krb5_context context, const krb5_key_data *key,
  521. krb5_const_principal princ, krb5_int16 *salttype_out,
  522. krb5_data **salt_out);
  523. /*
  524. * Modify the key data of entry to explicitly store salt values using the
  525. * KRB5_KDB_SALTTYPE_SPECIAL salt type.
  526. */
  527. krb5_error_code
  528. krb5_dbe_specialize_salt(krb5_context context, krb5_db_entry *entry);
  529. krb5_error_code
  530. krb5_dbe_cpw( krb5_context kcontext,
  531. krb5_keyblock * master_key,
  532. krb5_key_salt_tuple * ks_tuple,
  533. int ks_tuple_count,
  534. char * passwd,
  535. int new_kvno,
  536. krb5_boolean keepold,
  537. krb5_db_entry * db_entry);
  538. krb5_error_code
  539. krb5_dbe_ark( krb5_context context,
  540. krb5_keyblock * master_key,
  541. krb5_key_salt_tuple * ks_tuple,
  542. int ks_tuple_count,
  543. krb5_db_entry * db_entry);
  544. krb5_error_code
  545. krb5_dbe_crk( krb5_context context,
  546. krb5_keyblock * master_key,
  547. krb5_key_salt_tuple * ks_tuple,
  548. int ks_tuple_count,
  549. krb5_boolean keepold,
  550. krb5_db_entry * db_entry);
  551. krb5_error_code
  552. krb5_dbe_apw( krb5_context context,
  553. krb5_keyblock * master_key,
  554. krb5_key_salt_tuple * ks_tuple,
  555. int ks_tuple_count,
  556. char * passwd,
  557. krb5_db_entry * db_entry);
  558. int
  559. krb5_db_get_key_data_kvno( krb5_context context,
  560. int count,
  561. krb5_key_data * data);
  562. krb5_error_code krb5_db_check_transited_realms(krb5_context kcontext,
  563. const krb5_data *tr_contents,
  564. const krb5_data *client_realm,
  565. const krb5_data *server_realm);
  566. krb5_error_code krb5_db_check_policy_as(krb5_context kcontext,
  567. krb5_kdc_req *request,
  568. krb5_db_entry *client,
  569. krb5_db_entry *server,
  570. krb5_timestamp kdc_time,
  571. const char **status,
  572. krb5_pa_data ***e_data);
  573. krb5_error_code krb5_db_check_policy_tgs(krb5_context kcontext,
  574. krb5_kdc_req *request,
  575. krb5_db_entry *server,
  576. krb5_ticket *ticket,
  577. const char **status,
  578. krb5_pa_data ***e_data);
  579. void krb5_db_audit_as_req(krb5_context kcontext, krb5_kdc_req *request,
  580. const krb5_address *local_addr,
  581. const krb5_address *remote_addr,
  582. krb5_db_entry *client, krb5_db_entry *server,
  583. krb5_timestamp authtime, krb5_error_code error_code);
  584. void krb5_db_refresh_config(krb5_context kcontext);
  585. krb5_error_code krb5_db_check_allowed_to_delegate(krb5_context kcontext,
  586. krb5_const_principal client,
  587. const krb5_db_entry *server,
  588. krb5_const_principal proxy);
  589. krb5_error_code krb5_db_get_s4u_x509_principal(krb5_context kcontext,
  590. const krb5_data *client_cert,
  591. krb5_const_principal in_princ,
  592. unsigned int flags,
  593. krb5_db_entry **entry);
  594. krb5_error_code krb5_db_allowed_to_delegate_from(krb5_context context,
  595. krb5_const_principal client,
  596. krb5_const_principal server,
  597. krb5_pac server_pac,
  598. const krb5_db_entry *proxy);
  599. /**
  600. * Sort an array of @a krb5_key_data keys in descending order by their kvno.
  601. * Key data order within a kvno is preserved.
  602. *
  603. * @param key_data
  604. * The @a krb5_key_data array to sort. This is sorted in place so the
  605. * array will be modified.
  606. * @param key_data_length
  607. * The length of @a key_data.
  608. */
  609. void
  610. krb5_dbe_sort_key_data(krb5_key_data *key_data, size_t key_data_length);
  611. krb5_error_code
  612. krb5_db_issue_pac(krb5_context context, unsigned int flags,
  613. krb5_db_entry *client, krb5_keyblock *replaced_reply_key,
  614. krb5_db_entry *server, krb5_db_entry *krbtgt,
  615. krb5_timestamp authtime, krb5_pac old_pac, krb5_pac new_pac,
  616. krb5_data ***auth_indicators);
  617. /* default functions. Should not be directly called */
  618. /*
  619. * Default functions prototype
  620. */
  621. krb5_error_code
  622. krb5_dbe_def_search_enctype( krb5_context kcontext,
  623. krb5_db_entry *dbentp,
  624. krb5_int32 *start,
  625. krb5_int32 ktype,
  626. krb5_int32 stype,
  627. krb5_int32 kvno,
  628. krb5_key_data **kdatap);
  629. krb5_error_code
  630. krb5_def_store_mkey_list( krb5_context context,
  631. char *keyfile,
  632. krb5_principal mname,
  633. krb5_keylist_node *keylist,
  634. char *master_pwd);
  635. krb5_error_code
  636. krb5_db_def_fetch_mkey( krb5_context context,
  637. krb5_principal mname,
  638. krb5_keyblock *key,
  639. krb5_kvno *kvno,
  640. char *db_args);
  641. krb5_error_code
  642. krb5_def_fetch_mkey_list( krb5_context context,
  643. krb5_principal mprinc,
  644. const krb5_keyblock *mkey,
  645. krb5_keylist_node **mkeys_list);
  646. krb5_error_code
  647. krb5_dbe_def_cpw( krb5_context context,
  648. krb5_keyblock * master_key,
  649. krb5_key_salt_tuple * ks_tuple,
  650. int ks_tuple_count,
  651. char * passwd,
  652. int new_kvno,
  653. krb5_boolean keepold,
  654. krb5_db_entry * db_entry);
  655. krb5_error_code
  656. krb5_dbe_def_decrypt_key_data( krb5_context context,
  657. const krb5_keyblock * mkey,
  658. const krb5_key_data * key_data,
  659. krb5_keyblock * dbkey,
  660. krb5_keysalt * keysalt);
  661. krb5_error_code
  662. krb5_dbe_def_encrypt_key_data( krb5_context context,
  663. const krb5_keyblock * mkey,
  664. const krb5_keyblock * dbkey,
  665. const krb5_keysalt * keysalt,
  666. int keyver,
  667. krb5_key_data * key_data);
  668. krb5_error_code
  669. krb5_db_def_rename_principal( krb5_context kcontext,
  670. krb5_const_principal source,
  671. krb5_const_principal target);
  672. krb5_error_code
  673. krb5_db_create_policy( krb5_context kcontext,
  674. osa_policy_ent_t policy);
  675. krb5_error_code
  676. krb5_db_get_policy ( krb5_context kcontext,
  677. char *name,
  678. osa_policy_ent_t *policy );
  679. krb5_error_code
  680. krb5_db_put_policy( krb5_context kcontext,
  681. osa_policy_ent_t policy);
  682. krb5_error_code
  683. krb5_db_iter_policy( krb5_context kcontext,
  684. char *match_entry,
  685. osa_adb_iter_policy_func func,
  686. void *data);
  687. krb5_error_code
  688. krb5_db_delete_policy( krb5_context kcontext,
  689. char *policy);
  690. void
  691. krb5_db_free_policy( krb5_context kcontext,
  692. osa_policy_ent_t policy);
  693. krb5_error_code
  694. krb5_db_set_context(krb5_context, void *db_context);
  695. krb5_error_code
  696. krb5_db_get_context(krb5_context, void **db_context);
  697. void
  698. krb5_dbe_free_key_data_contents(krb5_context, krb5_key_data *);
  699. void
  700. krb5_dbe_free_key_list(krb5_context, krb5_keylist_node *);
  701. void
  702. krb5_dbe_free_actkvno_list(krb5_context, krb5_actkvno_node *);
  703. void
  704. krb5_dbe_free_mkey_aux_list(krb5_context, krb5_mkey_aux_node *);
  705. void
  706. krb5_dbe_free_tl_data(krb5_context, krb5_tl_data *);
  707. void
  708. krb5_dbe_free_strings(krb5_context, krb5_string_attr *, int count);
  709. void
  710. krb5_dbe_free_string(krb5_context, char *);
  711. /*
  712. * Register the KDB keytab type, allowing "KDB:" to be used as a keytab name.
  713. * For this type to work, the context used for keytab operations must have an
  714. * associated database handle (via krb5_db_open()).
  715. */
  716. krb5_error_code krb5_db_register_keytab(krb5_context context);
  717. #define KRB5_KDB_DEF_FLAGS 0
  718. #define KDB_MAX_DB_NAME 128
  719. #define KDB_REALM_SECTION "realms"
  720. #define KDB_MODULE_POINTER "database_module"
  721. #define KDB_MODULE_DEF_SECTION "dbdefaults"
  722. #define KDB_MODULE_SECTION "dbmodules"
  723. #define KDB_LIB_POINTER "db_library"
  724. #define KDB_DATABASE_CONF_FILE DEFAULT_SECURE_PROFILE_PATH
  725. #define KDB_DATABASE_ENV_PROF KDC_PROFILE_ENV
  726. #define KRB5_KDB_OPEN_RW 0
  727. #define KRB5_KDB_OPEN_RO 1
  728. #define KRB5_KDB_OPT_SET_DB_NAME 0
  729. #define KRB5_KDB_OPT_SET_LOCK_MODE 1
  730. /*
  731. * This number indicates the date of the last incompatible change to the DAL.
  732. * The maj_ver field of the module's vtable structure must match this version.
  733. */
  734. #define KRB5_KDB_DAL_MAJOR_VERSION 9
  735. /*
  736. * Note the following when converting a module to DAL version 9:
  737. *
  738. * - get_authdata_info() and sign_authdata() have been removed, and issue_pac()
  739. * has been added.
  740. *
  741. * - check_allowed_to_delegate() must handle a null proxy argument, returning
  742. * success if server has any authorized delegation targets in the traditional
  743. * scheme.
  744. *
  745. * - allowed_to_delegate_from() accepts a krb5_pac parameter (in place
  746. * server_ad_info) for the impersonator's PAC.
  747. *
  748. * - check_allowed_to_delegate() and allowed_to_delegate_from() must return
  749. * KRB5KDC_ERR_BADOPTION on authorization failure.
  750. *
  751. * - the KRB5_KDB_FLAG_ISSUE_PAC and KRB5_FLAG_CLIENT_REFERRALS_ONLY flags have
  752. * been combined into KRB5_KDB_FLAG_CLIENT.
  753. *
  754. * - the KRB5_KDB_FLAG_CANONICALIZE flag has been renamed to
  755. * KRB5_KDB_FLAG_REFERRAL_OK, and is only passed to get_principal() when a
  756. * realm referral is allowed (AS client and TGS server lookups, when the
  757. * CANONICALIZE option is requested or, for AS requests, when the client is
  758. * an enterprise principal). As of DAL version 8 the KDB module should
  759. * always canonicalize aliases within a realm; the KDC will decide whether to
  760. * use the original or canonical principal.
  761. */
  762. /*
  763. * A krb5_context can hold one database object. Modules should use
  764. * krb5_db_set_context and krb5_db_get_context to store state associated with
  765. * the database object.
  766. *
  767. * Some module functions are mandatory for KDC operation; others are optional
  768. * or apply only to administrative operations. If a function is optional, a
  769. * module can leave the function pointer as NULL. Alternatively, modules can
  770. * return KRB5_PLUGIN_OP_NOTSUPP when asked to perform an inapplicable action.
  771. *
  772. * Some module functions have default implementations which will call back into
  773. * the vtable interface. Leave these functions as NULL to use the default
  774. * implementations.
  775. *
  776. * The documentation in these comments describes the DAL as it is currently
  777. * implemented and used, not as it should be. So if anything seems off, that
  778. * probably means the current state of things is off.
  779. *
  780. * Modules must allocate memory for principal entries, policy entries, and
  781. * other structures using an allocator compatible with malloc() as seen by
  782. * libkdb5 and libkrb5. Modules may link against libkdb5 and call
  783. * krb5_db_alloc() to be certain that the same malloc implementation is used.
  784. */
  785. typedef struct _kdb_vftabl {
  786. short int maj_ver;
  787. short int min_ver;
  788. /*
  789. * Mandatory: Invoked after the module library is loaded, when the first DB
  790. * using the module is opened, across all contexts.
  791. */
  792. krb5_error_code (*init_library)(void);
  793. /*
  794. * Mandatory: Invoked before the module library is unloaded, after the last
  795. * DB using the module is closed, across all contexts.
  796. */
  797. krb5_error_code (*fini_library)(void);
  798. /*
  799. * Mandatory: Initialize a database object. Profile settings should be
  800. * read from conf_section inside KDB_MODULE_SECTION. db_args communicates
  801. * command-line arguments for module-specific flags. mode will be one of
  802. * KRB5_KDB_OPEN_{RW,RO} or'd with one of
  803. * KRB5_KDB_SRV_TYPE_{KDC,ADMIN,PASSWD,OTHER}.
  804. */
  805. krb5_error_code (*init_module)(krb5_context kcontext, char *conf_section,
  806. char **db_args, int mode);
  807. /*
  808. * Mandatory: Finalize the database object contained in a context. Free
  809. * any state contained in the db_context pointer and null it out.
  810. */
  811. krb5_error_code (*fini_module)(krb5_context kcontext);
  812. /*
  813. * Optional: Initialize a database object while creating the underlying
  814. * database. conf_section and db_args have the same meaning as in
  815. * init_module. This function may return an error if the database already
  816. * exists. Used by kdb5_util create.
  817. *
  818. * If db_args contains the value "temporary", the module should create an
  819. * exclusively locked side copy of the database suitable for loading in a
  820. * propagation from primary to replica. This side copy will later be
  821. * promoted with promote_db, allowing complete updates of the DB with no
  822. * loss in read availability. If the module cannot comply with this
  823. * architecture, it should return an error.
  824. */
  825. krb5_error_code (*create)(krb5_context kcontext, char *conf_section,
  826. char **db_args);
  827. /*
  828. * Optional: Destroy a database. conf_section and db_args have the same
  829. * meaning as in init_module. Used by kdb5_util destroy. In current
  830. * usage, the database is destroyed while open, so the module should handle
  831. * that.
  832. */
  833. krb5_error_code (*destroy)(krb5_context kcontext, char *conf_section,
  834. char **db_args);
  835. /*
  836. * Deprecated: No longer used as of krb5 1.10; can be removed in the next
  837. * DAL revision. Modules should leave as NULL.
  838. */
  839. krb5_error_code (*get_age)(krb5_context kcontext, char *db_name,
  840. time_t *age);
  841. /*
  842. * Optional: Lock the database, with semantics depending on the mode
  843. * argument:
  844. *
  845. * KRB5_DB_LOCKMODE_SHARED: Lock may coexist with other shared locks.
  846. * KRB5_DB_LOCKMODE_EXCLUSIVE: Lock may not coexist with other locks.
  847. * KRB5_DB_LOCKMODE_PERMANENT: Exclusive lock surviving process exit.
  848. *
  849. * Used by the "kadmin lock" command, incremental propagation, and
  850. * kdb5_util dump. Incremental propagation support requires shared locks
  851. * to operate. kdb5_util dump will continue unlocked if the module returns
  852. * KRB5_PLUGIN_OP_NOTSUPP.
  853. */
  854. krb5_error_code (*lock)(krb5_context kcontext, int mode);
  855. /* Optional: Release a lock created with db_lock. */
  856. krb5_error_code (*unlock)(krb5_context kcontext);
  857. /*
  858. * Mandatory: Set *entry to an allocated entry for the principal
  859. * search_for. If the principal is not found, return KRB5_KDB_NOENTRY.
  860. *
  861. * The meaning of flags are as follows:
  862. *
  863. * KRB5_KDB_FLAG_REFERRAL_OK: Set by the KDC when looking up entries for an
  864. * AS client with canonicalization requested or for an enterprise
  865. * principal, or for a TGS request server with canonicalization
  866. * requested. Determines whether the module should return out-of-realm
  867. * referrals.
  868. *
  869. * KRB5_KDB_FLAG_CLIENT: Set by the KDC when looking up a client principal
  870. * during an AS or TGS request. Affects how the module should return
  871. * out-of-realm referrals.
  872. *
  873. * KRB5_KDB_FLAG_MAP_PRINCIPALS: Set by the KDC when looking up the client
  874. * entry during TGS requests, except for S4U TGS requests and requests
  875. * where the server entry has the KRB5_KDB_NO_AUTH_DATA_REQUIRED
  876. * attribute. Indicates that the module should map foreign principals
  877. * to local principals if it supports doing so.
  878. *
  879. * KRB5_KDB_FLAG_PROTOCOL_TRANSITION: Set by the KDC when looking up the
  880. * client entry during an S4U2Self TGS request. This affects the PAC
  881. * information which should be included when authorization data is
  882. * generated; see the Microsoft S4U specification for details.
  883. *
  884. * KRB5_KDB_FLAG_CONSTRAINED_DELEGATION: Set by the KDC when looking up the
  885. * client entry during an S4U2Proxy TGS request. Also affects PAC
  886. * generation.
  887. *
  888. * KRB5_KDB_FLAG_CROSS_REALM: Set by the KDC after looking up a server
  889. * entry during a TGS request, if the header ticket was issued by a
  890. * different realm.
  891. *
  892. * KRB5_KDB_FLAG_ISSUING_REFERRAL: Set by the KDC after looking up a server
  893. * entry during a TGS request, if the requested server principal is not
  894. * part of the realm being served, and a referral or alternate TGT will
  895. * be issued instead.
  896. *
  897. * A module may return an in-realm alias by setting (*entry)->princ to the
  898. * canonical name. The KDC will decide based on the request whether to use
  899. * the requested name or the canonical name in the issued ticket.
  900. *
  901. * A module can return a referral to another realm if flags contains
  902. * KRB5_KDB_FLAG_REFERRAL_OK. If KRB5_KDB_FLAG_CLIENT is also set, the
  903. * module should return a referral by simply filling in an out-of-realm
  904. * name in (*entry)->princ and setting all other fields to NULL.
  905. * Otherwise, the module should return the entry for the cross-realm TGS of
  906. * the referred-to realm.
  907. */
  908. krb5_error_code (*get_principal)(krb5_context kcontext,
  909. krb5_const_principal search_for,
  910. unsigned int flags,
  911. krb5_db_entry **entry);
  912. /*
  913. * Optional: Create or modify a principal entry. db_args communicates
  914. * command-line arguments for module-specific flags.
  915. *
  916. * The mask field of an entry indicates the changed fields. Mask values
  917. * are defined in kadmin's admin.h header. If KADM5_PRINCIPAL is set in
  918. * the mask, the entry is new; otherwise it already exists. All fields of
  919. * an entry are expected to contain correct values, regardless of whether
  920. * they are specified in the mask, so it is acceptable for a module to
  921. * ignore the mask and update the entire entry.
  922. */
  923. krb5_error_code (*put_principal)(krb5_context kcontext,
  924. krb5_db_entry *entry, char **db_args);
  925. /*
  926. * Optional: Delete the entry for the principal search_for. If the
  927. * principal did not exist, return KRB5_KDB_NOENTRY.
  928. */
  929. krb5_error_code (*delete_principal)(krb5_context kcontext,
  930. krb5_const_principal search_for);
  931. /*
  932. * Optional with default: Rename a principal. If the source principal does
  933. * not exist, return KRB5_KDB_NOENTRY. If the target exists, return an
  934. * error.
  935. *
  936. * NOTE: If the module chooses to implement a custom function for renaming
  937. * a principal instead of using the default, then rename operations will
  938. * fail if iprop logging is enabled.
  939. */
  940. krb5_error_code (*rename_principal)(krb5_context kcontext,
  941. krb5_const_principal source,
  942. krb5_const_principal target);
  943. /*
  944. * Optional: For each principal entry in the database, invoke func with the
  945. * arguments func_arg and the entry data. If match_entry is specified, the
  946. * module may narrow the iteration to principal names matching that regular
  947. * expression; a module may alternatively ignore match_entry.
  948. */
  949. krb5_error_code (*iterate)(krb5_context kcontext,
  950. char *match_entry,
  951. int (*func)(krb5_pointer, krb5_db_entry *),
  952. krb5_pointer func_arg, krb5_flags iterflags);
  953. /*
  954. * Optional: Create a password policy entry. Return an error if the policy
  955. * already exists.
  956. */
  957. krb5_error_code (*create_policy)(krb5_context kcontext,
  958. osa_policy_ent_t policy);
  959. /*
  960. * Optional: Set *policy to the policy entry of the specified name. If the
  961. * entry does not exist, return KRB5_KDB_NOENTRY.
  962. */
  963. krb5_error_code (*get_policy)(krb5_context kcontext, char *name,
  964. osa_policy_ent_t *policy);
  965. /*
  966. * Optional: Modify an existing password policy entry to match the values
  967. * in policy. Return an error if the policy does not already exist.
  968. */
  969. krb5_error_code (*put_policy)(krb5_context kcontext,
  970. osa_policy_ent_t policy);
  971. /*
  972. * Optional: For each password policy entry in the database, invoke func
  973. * with the arguments data and the entry data. If match_entry is
  974. * specified, the module may narrow the iteration to policy names matching
  975. * that regular expression; a module may alternatively ignore match_entry.
  976. */
  977. krb5_error_code (*iter_policy)(krb5_context kcontext, char *match_entry,
  978. osa_adb_iter_policy_func func,
  979. void *data);
  980. /*
  981. * Optional: Delete the password policy entry with the name policy. Return
  982. * an error if the entry does not exist.
  983. */
  984. krb5_error_code (*delete_policy)(krb5_context kcontext, char *policy);
  985. /*
  986. * Optional with default: Retrieve a master keyblock from the stash file
  987. * db_args, filling in *key and *kvno. mname is the name of the master
  988. * principal for the realm.
  989. *
  990. * The default implementation reads the master keyblock from a keytab or
  991. * old-format stash file.
  992. */
  993. krb5_error_code (*fetch_master_key)(krb5_context kcontext,
  994. krb5_principal mname,
  995. krb5_keyblock *key, krb5_kvno *kvno,
  996. char *db_args);
  997. /*
  998. * Optional with default: Given a keyblock for some version of the
  999. * database's master key, fetch the decrypted master key values from the
  1000. * database and store the list into *mkeys_list. The caller will free
  1001. * *mkeys_list using a libkdb5 function which uses the standard free()
  1002. * function, so the module must not use a custom allocator.
  1003. *
  1004. * The caller may not know the version number of the master key it has, in
  1005. * which case it will pass IGNORE_VNO.
  1006. *
  1007. * The default implementation ignores kvno and tries the key against the
  1008. * current master key data and all KRB5_TL_MKEY_AUX values, which contain
  1009. * copies of the master keys encrypted with old master keys.
  1010. */
  1011. krb5_error_code (*fetch_master_key_list)(krb5_context kcontext,
  1012. krb5_principal mname,
  1013. const krb5_keyblock *key,
  1014. krb5_keylist_node **mkeys_list);
  1015. /*
  1016. * Optional with default: Save a list of master keyblocks, obtained from
  1017. * fetch_master_key_list, into the stash file db_arg. The caller will set
  1018. * master_pwd to NULL, so the module should just ignore it. mname is the
  1019. * name of the master principal for the realm.
  1020. *
  1021. * The default implementation saves the list of master keys in a
  1022. * keytab-format file.
  1023. */
  1024. krb5_error_code (*store_master_key_list)(krb5_context kcontext,
  1025. char *db_arg,
  1026. krb5_principal mname,
  1027. krb5_keylist_node *keylist,
  1028. char *master_pwd);
  1029. /*
  1030. * Optional with default: Starting at position *start, scan the key data of
  1031. * a database entry for a key matching the enctype ktype, the salt type
  1032. * stype, and the version kvno. Store the resulting key into *kdatap and
  1033. * set *start to the position after the key found. If ktype is negative,
  1034. * match any enctype. If stype is negative, match any salt type. If kvno
  1035. * is zero or negative, find the most recent key version satisfying the
  1036. * other constraints.
  1037. */
  1038. krb5_error_code (*dbe_search_enctype)(krb5_context kcontext,
  1039. krb5_db_entry *dbentp,
  1040. krb5_int32 *start, krb5_int32 ktype,
  1041. krb5_int32 stype, krb5_int32 kvno,
  1042. krb5_key_data **kdatap);
  1043. /*
  1044. * Optional with default: Change the key data for db_entry to include keys
  1045. * derived from the password passwd in each of the specified key-salt
  1046. * types, at version new_kvno. Discard the old key data if keepold is not
  1047. * set.
  1048. *
  1049. * The default implementation uses the keyblock master_key to encrypt each
  1050. * new key, via the function encrypt_key_data.
  1051. */
  1052. krb5_error_code (*change_pwd)(krb5_context context,
  1053. krb5_keyblock *master_key,
  1054. krb5_key_salt_tuple *ks_tuple,
  1055. int ks_tuple_count, char *passwd,
  1056. int new_kvno, krb5_boolean keepold,
  1057. krb5_db_entry *db_entry);
  1058. /*
  1059. * Optional: Promote a temporary database to be the live one. context must
  1060. * be initialized with an exclusively locked database created with the
  1061. * "temporary" db_arg. On success, the database object contained in
  1062. * context will be finalized.
  1063. *
  1064. * This method is used by kdb5_util load to replace the live database with
  1065. * minimal loss of read availability.
  1066. */
  1067. krb5_error_code (*promote_db)(krb5_context context, char *conf_section,
  1068. char **db_args);
  1069. /*
  1070. * Optional with default: Decrypt the key in key_data with master keyblock
  1071. * mkey, placing the result into dbkey. Copy the salt from key_data, if
  1072. * any, into keysalt. Either dbkey or keysalt may be left unmodified on
  1073. * successful return if key_data does not contain key or salt information.
  1074. *
  1075. * The default implementation expects the encrypted key (in krb5_c_encrypt
  1076. * format) to be stored in key_data_contents[0], with length given by
  1077. * key_data_length[0]. If key_data_ver is 2, it expects the salt to be
  1078. * stored, unencrypted, in key_data_contents[1], with length given by
  1079. * key_data_length[1].
  1080. */
  1081. krb5_error_code (*decrypt_key_data)(krb5_context kcontext,
  1082. const krb5_keyblock *mkey,
  1083. const krb5_key_data *key_data,
  1084. krb5_keyblock *dbkey,
  1085. krb5_keysalt *keysalt);
  1086. /*
  1087. * Optional with default: Encrypt dbkey with master keyblock mkey, placing
  1088. * the result into key_data along with keysalt.
  1089. *
  1090. * The default implementation stores the encrypted key (in krb5_c_encrypt
  1091. * format) in key_data_contents[0] and the length in key_data_length[0].
  1092. * If keysalt is specified, it sets key_data_ver to 2, and stores the salt
  1093. * in key_data_contents[1] and its length in key_data_length[1]. If
  1094. * keysalt is not specified, key_data_ver is set to 1.
  1095. */
  1096. krb5_error_code (*encrypt_key_data)(krb5_context kcontext,
  1097. const krb5_keyblock *mkey,
  1098. const krb5_keyblock *dbkey,
  1099. const krb5_keysalt *keysalt,
  1100. int keyver, krb5_key_data *key_data);
  1101. /*
  1102. * Optional: Perform a policy check on a cross-realm ticket's transited
  1103. * field. Return 0 if the check authoritatively succeeds,
  1104. * KRB5_PLUGIN_NO_HANDLE to use the core transited-checking mechanisms, or
  1105. * another error (other than KRB5_PLUGIN_OP_NOTSUPP) if the check fails.
  1106. */
  1107. krb5_error_code (*check_transited_realms)(krb5_context kcontext,
  1108. const krb5_data *tr_contents,
  1109. const krb5_data *client_realm,
  1110. const krb5_data *server_realm);
  1111. /*
  1112. * Optional: Perform a policy check on an AS request, in addition to the
  1113. * standard policy checks. Return 0 if the AS request is allowed. If the
  1114. * AS request is not allowed:
  1115. * - Place a short string literal into *status.
  1116. * - If desired, place data into e_data. Any data placed here will be
  1117. * freed by the caller using the standard free function.
  1118. * - Return an appropriate error (such as KRB5KDC_ERR_POLICY).
  1119. */
  1120. krb5_error_code (*check_policy_as)(krb5_context kcontext,
  1121. krb5_kdc_req *request,
  1122. krb5_db_entry *client,
  1123. krb5_db_entry *server,
  1124. krb5_timestamp kdc_time,
  1125. const char **status,
  1126. krb5_pa_data ***e_data);
  1127. /*
  1128. * Optional: Perform a policy check on a TGS request, in addition to the
  1129. * standard policy checks. Return 0 if the TGS request is allowed. If the
  1130. * TGS request is not allowed:
  1131. * - Place a short string literal into *status.
  1132. * - If desired, place data into e_data. Any data placed here will be
  1133. * freed by the caller using the standard free function.
  1134. * - Return an appropriate error (such as KRB5KDC_ERR_POLICY).
  1135. * The input parameter ticket contains the TGT used in the TGS request.
  1136. */
  1137. krb5_error_code (*check_policy_tgs)(krb5_context kcontext,
  1138. krb5_kdc_req *request,
  1139. krb5_db_entry *server,
  1140. krb5_ticket *ticket,
  1141. const char **status,
  1142. krb5_pa_data ***e_data);
  1143. /*
  1144. * Optional: This method informs the module of a successful or unsuccessful
  1145. * AS request.
  1146. */
  1147. void (*audit_as_req)(krb5_context kcontext, krb5_kdc_req *request,
  1148. const krb5_address *local_addr,
  1149. const krb5_address *remote_addr,
  1150. krb5_db_entry *client, krb5_db_entry *server,
  1151. krb5_timestamp authtime, krb5_error_code error_code);
  1152. /* Note: there is currently no method for auditing TGS requests. */
  1153. /*
  1154. * Optional: This method informs the module of a request to reload
  1155. * configuration or other state (that is, the KDC received a SIGHUP).
  1156. */
  1157. void (*refresh_config)(krb5_context kcontext);
  1158. /*
  1159. * Optional: Perform a policy check on server being allowed to obtain
  1160. * tickets from client to proxy. If proxy is NULL, check if server has any
  1161. * authorized delegation targets (client will also be NULL in this case).
  1162. * (Note that proxy is the target of the delegation, not the delegating
  1163. * service; the term "proxy" is from the viewpoint of the delegating
  1164. * service asking another service to perform some of its work in the
  1165. * authentication context of the client. This terminology comes from the
  1166. * Microsoft S4U protocol documentation.) Return 0 if policy allows
  1167. * delegation to the specified target (or to any target if proxy is NULL),
  1168. * or KRB5KDC_ERR_BADOPTION if not. If this method is not implemented, all
  1169. * S4U2Proxy delegation requests will be rejected.
  1170. */
  1171. krb5_error_code (*check_allowed_to_delegate)(krb5_context context,
  1172. krb5_const_principal client,
  1173. const krb5_db_entry *server,
  1174. krb5_const_principal proxy);
  1175. /*
  1176. * Optional: Free the e_data pointer of a database entry. If this method
  1177. * is not implemented, the e_data pointer in principal entries will be
  1178. * freed with free() as seen by libkdb5.
  1179. */
  1180. void (*free_principal_e_data)(krb5_context kcontext, krb5_octet *e_data);
  1181. /*
  1182. * Optional: get a client principal entry based on an X.509 certificate.
  1183. *
  1184. * If flags include KRB5_KDB_FLAG_REFERRAL_OK, the certificate was
  1185. * presented in an AS request. princ->realm indicates the request realm,
  1186. * but the data components should be ignored. The module can return an
  1187. * out-of-realm client referral as it would for get_principal().
  1188. *
  1189. * Otherwise, princ is from a TGS request. If it contains data components
  1190. * (and not just a realm), the module should verify that it is the same as
  1191. * the lookup result for client_cert. The module should not return a
  1192. * referral.
  1193. */
  1194. krb5_error_code (*get_s4u_x509_principal)(krb5_context kcontext,
  1195. const krb5_data *client_cert,
  1196. krb5_const_principal princ,
  1197. unsigned int flags,
  1198. krb5_db_entry **entry_out);
  1199. /*
  1200. * Optional: Perform a policy check on server being allowed to obtain
  1201. * tickets from client to proxy. This method is similar to
  1202. * check_allowed_to_delegate, but it operates on the target server DB entry
  1203. * (called "proxy" here as in Microsoft's protocol documentation) rather
  1204. * than the intermediate server entry. server_pac is the verified PAC from
  1205. * the authdata of the intermediate server. Return 0 if policy allows the
  1206. * delegation, or KRB5KDC_ERR_BADOPTION if not.
  1207. *
  1208. * This method is called for S4U2Proxy requests and implements the
  1209. * resource-based constrained delegation variant, which can support
  1210. * cross-realm delegation. If this method is not implemented or if it
  1211. * returns a policy error, the KDC will fall back to
  1212. * check_allowed_to_delegate if the intermediate and target servers are in
  1213. * the same realm and the evidence ticket is forwardable.
  1214. */
  1215. krb5_error_code (*allowed_to_delegate_from)(krb5_context context,
  1216. krb5_const_principal client,
  1217. krb5_const_principal server,
  1218. krb5_pac server_pac,
  1219. const krb5_db_entry *proxy);
  1220. /*
  1221. * Optional: Add buffers to new_pac using krb5_pac_add_buffer() before it
  1222. * is signed.
  1223. *
  1224. * The caller will handle the following buffer types, so do not copy or add
  1225. * them:
  1226. *
  1227. * KRB5_PAC_SERVER_CHECKSUM
  1228. * KRB5_PAC_PRIVSVR_CHECKSUM
  1229. * KRB5_PAC_TICKET_CHECKSUM
  1230. * KRB5_PAC_CLIENT_INFO
  1231. * KRB5_PAC_DELEGATION_INFO
  1232. *
  1233. * For TGS requests, old_pac is the PAC of the header ticket, except when
  1234. * KRB5_KDB_FLAG_CONTRAINED_DELEGATION is present in flags, in which case
  1235. * it is the PAC of the second ticket. If
  1236. * KRB5_KDB_FLAG_PROTOCOL_TRANSITION is present in flags and client is not
  1237. * NULL, old_pac is the PAC of the requesting service, not the subject of
  1238. * the S4U2Self request, and its buffers should not be copied into new_pac.
  1239. * The signatures and PAC_CLIENT_INFO of old_pac have been verified by the
  1240. * caller.
  1241. *
  1242. * If replaced_reply_key is not null, the request is an AS request and the
  1243. * reply key was replaced by a preauth mechanism such as PKINIT, meaning
  1244. * the Kerberos password or long-term key was not used. The module may use
  1245. * this key to encrypt a PAC_CREDENTIALS_INFO buffer containing credentials
  1246. * (such as an NTLM hash) that the client would ordinarily derive from the
  1247. * Kerberos password or long-term key.
  1248. *
  1249. * server is the database entry of the server the ticket will be issued to,
  1250. * which may be a referral TGS.
  1251. *
  1252. * signing_krbtgt is the database entry of the krbtgt principal used to
  1253. * verify old_pac (or null if old_pac is null). If
  1254. * KRB5_KDB_FLAG_CROSS_REALM is present in flags, this entry will be an
  1255. * incoming cross-realm TGS, and the PAC fields should undergo appropriate
  1256. * filtering based on the trust level of the cross-realm relationship.
  1257. *
  1258. * auth_indicators points to NULL or a null-terminated list of krb5_data
  1259. * pointers, each containing an authentication indicator (RFC 8129). The
  1260. * method may modify this list, or free it and replace *auth_indicators
  1261. * with NULL, to change which auth indicators will be included in the
  1262. * ticket.
  1263. */
  1264. krb5_error_code (*issue_pac)(krb5_context context, unsigned int flags,
  1265. krb5_db_entry *client,
  1266. krb5_keyblock *replaced_reply_key,
  1267. krb5_db_entry *server,
  1268. krb5_db_entry *signing_krbtgt,
  1269. krb5_timestamp authtime, krb5_pac old_pac,
  1270. krb5_pac new_pac,
  1271. krb5_data ***auth_indicators);
  1272. /* End of minor version 0 for major version 9. */
  1273. } kdb_vftabl;
  1274. #endif /* !defined(_WIN32) */
  1275. #endif /* KRB5_KDB5__ */