kdb.h 57 KB

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