admin.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2. /* lib/kadm5/admin.h */
  3. /*
  4. * Copyright 2001, 2008 by the Massachusetts Institute of Technology.
  5. * All Rights Reserved.
  6. *
  7. * Export of this software from the United States of America may
  8. * require a specific license from the United States Government.
  9. * It is the responsibility of any person or organization contemplating
  10. * export to obtain such a license before exporting.
  11. *
  12. * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
  13. * distribute this software and its documentation for any purpose and
  14. * without fee is hereby granted, provided that the above copyright
  15. * notice appear in all copies and that both that copyright notice and
  16. * this permission notice appear in supporting documentation, and that
  17. * the name of M.I.T. not be used in advertising or publicity pertaining
  18. * to distribution of the software without specific, written prior
  19. * permission. Furthermore if you modify this software you must label
  20. * your software as modified software and not distribute it in such a
  21. * fashion that it might be confused with the original M.I.T. software.
  22. * M.I.T. makes no representations about the suitability of
  23. * this software for any purpose. It is provided "as is" without express
  24. * or implied warranty.
  25. */
  26. /*
  27. * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
  28. *
  29. * $Header$
  30. */
  31. /*
  32. * This API is not considered as stable as the main krb5 API.
  33. *
  34. * - We may make arbitrary incompatible changes between feature
  35. * releases (e.g. from 1.7 to 1.8).
  36. * - We will make some effort to avoid making incompatible changes for
  37. * bugfix releases, but will make them if necessary.
  38. */
  39. #ifndef __KADM5_ADMIN_H__
  40. #define __KADM5_ADMIN_H__
  41. #include <sys/types.h>
  42. #include <gssrpc/rpc.h>
  43. #include <krb5.h>
  44. #include <kdb.h>
  45. #include <com_err.h>
  46. #include <kadm5/kadm_err.h>
  47. #include <kadm5/chpass_util_strings.h>
  48. #ifndef KADM5INT_BEGIN_DECLS
  49. #if defined(__cplusplus)
  50. #define KADM5INT_BEGIN_DECLS extern "C" {
  51. #define KADM5INT_END_DECLS }
  52. #else
  53. #define KADM5INT_BEGIN_DECLS
  54. #define KADM5INT_END_DECLS
  55. #endif
  56. #endif
  57. KADM5INT_BEGIN_DECLS
  58. #define KADM5_ADMIN_SERVICE "kadmin/admin"
  59. #define KADM5_CHANGEPW_SERVICE "kadmin/changepw"
  60. #define KADM5_HIST_PRINCIPAL "kadmin/history"
  61. #define KADM5_KIPROP_HOST_SERVICE "kiprop"
  62. typedef krb5_principal kadm5_princ_t;
  63. typedef char *kadm5_policy_t;
  64. typedef long kadm5_ret_t;
  65. #define KADM5_PW_FIRST_PROMPT \
  66. (error_message(CHPASS_UTIL_NEW_PASSWORD_PROMPT))
  67. #define KADM5_PW_SECOND_PROMPT \
  68. (error_message(CHPASS_UTIL_NEW_PASSWORD_AGAIN_PROMPT))
  69. /*
  70. * Successful return code
  71. */
  72. #define KADM5_OK 0
  73. /*
  74. * Field masks
  75. */
  76. /* kadm5_principal_ent_t */
  77. #define KADM5_PRINCIPAL 0x000001
  78. #define KADM5_PRINC_EXPIRE_TIME 0x000002
  79. #define KADM5_PW_EXPIRATION 0x000004
  80. #define KADM5_LAST_PWD_CHANGE 0x000008
  81. #define KADM5_ATTRIBUTES 0x000010
  82. #define KADM5_MAX_LIFE 0x000020
  83. #define KADM5_MOD_TIME 0x000040
  84. #define KADM5_MOD_NAME 0x000080
  85. #define KADM5_KVNO 0x000100
  86. #define KADM5_MKVNO 0x000200
  87. #define KADM5_AUX_ATTRIBUTES 0x000400
  88. #define KADM5_POLICY 0x000800
  89. #define KADM5_POLICY_CLR 0x001000
  90. /* version 2 masks */
  91. #define KADM5_MAX_RLIFE 0x002000
  92. #define KADM5_LAST_SUCCESS 0x004000
  93. #define KADM5_LAST_FAILED 0x008000
  94. #define KADM5_FAIL_AUTH_COUNT 0x010000
  95. #define KADM5_KEY_DATA 0x020000
  96. #define KADM5_TL_DATA 0x040000
  97. #ifdef notyet /* Novell */
  98. #define KADM5_CPW_FUNCTION 0x080000
  99. #define KADM5_RANDKEY_USED 0x100000
  100. #endif
  101. #define KADM5_LOAD 0x200000
  102. /* all but KEY_DATA, TL_DATA, LOAD */
  103. #define KADM5_PRINCIPAL_NORMAL_MASK 0x41ffff
  104. /* kadm5_policy_ent_t */
  105. #define KADM5_PW_MAX_LIFE 0x004000
  106. #define KADM5_PW_MIN_LIFE 0x008000
  107. #define KADM5_PW_MIN_LENGTH 0x010000
  108. #define KADM5_PW_MIN_CLASSES 0x020000
  109. #define KADM5_PW_HISTORY_NUM 0x040000
  110. #define KADM5_REF_COUNT 0x080000
  111. #define KADM5_PW_MAX_FAILURE 0x100000
  112. #define KADM5_PW_FAILURE_COUNT_INTERVAL 0x200000
  113. #define KADM5_PW_LOCKOUT_DURATION 0x400000
  114. /* kadm5_config_params */
  115. #define KADM5_CONFIG_REALM 0x00000001
  116. #define KADM5_CONFIG_DBNAME 0x00000002
  117. #define KADM5_CONFIG_MKEY_NAME 0x00000004
  118. #define KADM5_CONFIG_MAX_LIFE 0x00000008
  119. #define KADM5_CONFIG_MAX_RLIFE 0x00000010
  120. #define KADM5_CONFIG_EXPIRATION 0x00000020
  121. #define KADM5_CONFIG_FLAGS 0x00000040
  122. #define KADM5_CONFIG_ADMIN_KEYTAB 0x00000080
  123. #define KADM5_CONFIG_STASH_FILE 0x00000100
  124. #define KADM5_CONFIG_ENCTYPE 0x00000200
  125. #define KADM5_CONFIG_ADBNAME 0x00000400
  126. #define KADM5_CONFIG_ADB_LOCKFILE 0x00000800
  127. /*#define KADM5_CONFIG_PROFILE 0x00001000*/
  128. #define KADM5_CONFIG_ACL_FILE 0x00002000
  129. #define KADM5_CONFIG_KADMIND_PORT 0x00004000
  130. #define KADM5_CONFIG_ENCTYPES 0x00008000
  131. #define KADM5_CONFIG_ADMIN_SERVER 0x00010000
  132. #define KADM5_CONFIG_DICT_FILE 0x00020000
  133. #define KADM5_CONFIG_MKEY_FROM_KBD 0x00040000
  134. #define KADM5_CONFIG_KPASSWD_PORT 0x00080000
  135. #define KADM5_CONFIG_OLD_AUTH_GSSAPI 0x00100000
  136. #define KADM5_CONFIG_NO_AUTH 0x00200000
  137. #define KADM5_CONFIG_AUTH_NOFALLBACK 0x00400000
  138. #ifdef notyet /* Novell */
  139. #define KADM5_CONFIG_KPASSWD_SERVER 0x00800000
  140. #endif
  141. #define KADM5_CONFIG_IPROP_ENABLED 0x01000000
  142. #define KADM5_CONFIG_ULOG_SIZE 0x02000000
  143. #define KADM5_CONFIG_POLL_TIME 0x04000000
  144. #define KADM5_CONFIG_IPROP_LOGFILE 0x08000000
  145. #define KADM5_CONFIG_IPROP_PORT 0x10000000
  146. #define KADM5_CONFIG_KVNO 0x20000000
  147. /*
  148. * permission bits
  149. */
  150. #define KADM5_PRIV_GET 0x01
  151. #define KADM5_PRIV_ADD 0x02
  152. #define KADM5_PRIV_MODIFY 0x04
  153. #define KADM5_PRIV_DELETE 0x08
  154. /*
  155. * API versioning constants
  156. */
  157. #define KADM5_MASK_BITS 0xffffff00
  158. #define KADM5_STRUCT_VERSION_MASK 0x12345600
  159. #define KADM5_STRUCT_VERSION_1 (KADM5_STRUCT_VERSION_MASK|0x01)
  160. #define KADM5_STRUCT_VERSION KADM5_STRUCT_VERSION_1
  161. #define KADM5_API_VERSION_MASK 0x12345700
  162. #define KADM5_API_VERSION_2 (KADM5_API_VERSION_MASK|0x02)
  163. #define KADM5_API_VERSION_3 (KADM5_API_VERSION_MASK|0x03)
  164. typedef struct _kadm5_principal_ent_t {
  165. krb5_principal principal;
  166. krb5_timestamp princ_expire_time;
  167. krb5_timestamp last_pwd_change;
  168. krb5_timestamp pw_expiration;
  169. krb5_deltat max_life;
  170. krb5_principal mod_name;
  171. krb5_timestamp mod_date;
  172. krb5_flags attributes;
  173. krb5_kvno kvno;
  174. krb5_kvno mkvno;
  175. char *policy;
  176. long aux_attributes;
  177. /* version 2 fields */
  178. krb5_deltat max_renewable_life;
  179. krb5_timestamp last_success;
  180. krb5_timestamp last_failed;
  181. krb5_kvno fail_auth_count;
  182. krb5_int16 n_key_data;
  183. krb5_int16 n_tl_data;
  184. krb5_tl_data *tl_data;
  185. krb5_key_data *key_data;
  186. } kadm5_principal_ent_rec, *kadm5_principal_ent_t;
  187. typedef struct _kadm5_policy_ent_t {
  188. char *policy;
  189. long pw_min_life;
  190. long pw_max_life;
  191. long pw_min_length;
  192. long pw_min_classes;
  193. long pw_history_num;
  194. long policy_refcnt;
  195. /* version 3 fields */
  196. krb5_kvno pw_max_fail;
  197. krb5_deltat pw_failcnt_interval;
  198. krb5_deltat pw_lockout_duration;
  199. } kadm5_policy_ent_rec, *kadm5_policy_ent_t;
  200. /*
  201. * Data structure returned by kadm5_get_config_params()
  202. */
  203. typedef struct _kadm5_config_params {
  204. long mask;
  205. char * realm;
  206. int kadmind_port;
  207. int kpasswd_port;
  208. char * admin_server;
  209. #ifdef notyet /* Novell */ /* ABI change? */
  210. char * kpasswd_server;
  211. #endif
  212. /* Deprecated except for db2 backwards compatibility. Don't add
  213. new uses except as fallbacks for parameters that should be
  214. specified in the database module section of the config
  215. file. */
  216. char * dbname;
  217. char * admin_keytab;
  218. char * acl_file;
  219. char * dict_file;
  220. int mkey_from_kbd;
  221. char * stash_file;
  222. char * mkey_name;
  223. krb5_enctype enctype;
  224. krb5_deltat max_life;
  225. krb5_deltat max_rlife;
  226. krb5_timestamp expiration;
  227. krb5_flags flags;
  228. krb5_key_salt_tuple *keysalts;
  229. krb5_int32 num_keysalts;
  230. krb5_kvno kvno;
  231. bool_t iprop_enabled;
  232. uint32_t iprop_ulogsize;
  233. krb5_deltat iprop_poll_time;
  234. char * iprop_logfile;
  235. /* char * iprop_server;*/
  236. int iprop_port;
  237. } kadm5_config_params;
  238. /***********************************************************************
  239. * This is the old krb5_realm_read_params, which I mutated into
  240. * kadm5_get_config_params but which old code (kdb5_* and krb5kdc)
  241. * still uses.
  242. ***********************************************************************/
  243. /*
  244. * Data structure returned by krb5_read_realm_params()
  245. */
  246. typedef struct __krb5_realm_params {
  247. char * realm_profile;
  248. char * realm_mkey_name;
  249. char * realm_stash_file;
  250. char * realm_kdc_ports;
  251. char * realm_kdc_tcp_ports;
  252. char * realm_acl_file;
  253. char * realm_host_based_services;
  254. char * realm_no_host_referral;
  255. krb5_int32 realm_kadmind_port;
  256. krb5_enctype realm_enctype;
  257. krb5_deltat realm_max_life;
  258. krb5_deltat realm_max_rlife;
  259. krb5_timestamp realm_expiration;
  260. krb5_flags realm_flags;
  261. krb5_key_salt_tuple *realm_keysalts;
  262. unsigned int realm_reject_bad_transit:1;
  263. unsigned int realm_restrict_anon:1;
  264. unsigned int realm_kadmind_port_valid:1;
  265. unsigned int realm_enctype_valid:1;
  266. unsigned int realm_max_life_valid:1;
  267. unsigned int realm_max_rlife_valid:1;
  268. unsigned int realm_expiration_valid:1;
  269. unsigned int realm_flags_valid:1;
  270. unsigned int realm_reject_bad_transit_valid:1;
  271. unsigned int realm_restrict_anon_valid:1;
  272. krb5_int32 realm_num_keysalts;
  273. } krb5_realm_params;
  274. /*
  275. * functions
  276. */
  277. krb5_error_code kadm5_get_config_params(krb5_context context,
  278. int use_kdc_config,
  279. kadm5_config_params *params_in,
  280. kadm5_config_params *params_out);
  281. krb5_error_code kadm5_free_config_params(krb5_context context,
  282. kadm5_config_params *params);
  283. krb5_error_code kadm5_free_realm_params(krb5_context kcontext,
  284. kadm5_config_params *params);
  285. krb5_error_code kadm5_get_admin_service_name(krb5_context, char *,
  286. char *, size_t);
  287. /*
  288. * For all initialization functions, the caller must first initialize
  289. * a context with kadm5_init_krb5_context which will survive as long
  290. * as the resulting handle. The caller should free the context with
  291. * krb5_free_context.
  292. */
  293. kadm5_ret_t kadm5_init(krb5_context context, char *client_name,
  294. char *pass, char *service_name,
  295. kadm5_config_params *params,
  296. krb5_ui_4 struct_version,
  297. krb5_ui_4 api_version,
  298. char **db_args,
  299. void **server_handle);
  300. kadm5_ret_t kadm5_init_anonymous(krb5_context context, char *client_name,
  301. char *service_name,
  302. kadm5_config_params *params,
  303. krb5_ui_4 struct_version,
  304. krb5_ui_4 api_version,
  305. char **db_args,
  306. void **server_handle);
  307. kadm5_ret_t kadm5_init_with_password(krb5_context context,
  308. char *client_name,
  309. char *pass,
  310. char *service_name,
  311. kadm5_config_params *params,
  312. krb5_ui_4 struct_version,
  313. krb5_ui_4 api_version,
  314. char **db_args,
  315. void **server_handle);
  316. kadm5_ret_t kadm5_init_with_skey(krb5_context context,
  317. char *client_name,
  318. char *keytab,
  319. char *service_name,
  320. kadm5_config_params *params,
  321. krb5_ui_4 struct_version,
  322. krb5_ui_4 api_version,
  323. char **db_args,
  324. void **server_handle);
  325. kadm5_ret_t kadm5_init_with_creds(krb5_context context,
  326. char *client_name,
  327. krb5_ccache cc,
  328. char *service_name,
  329. kadm5_config_params *params,
  330. krb5_ui_4 struct_version,
  331. krb5_ui_4 api_version,
  332. char **db_args,
  333. void **server_handle);
  334. kadm5_ret_t kadm5_lock(void *server_handle);
  335. kadm5_ret_t kadm5_unlock(void *server_handle);
  336. kadm5_ret_t kadm5_flush(void *server_handle);
  337. kadm5_ret_t kadm5_destroy(void *server_handle);
  338. kadm5_ret_t kadm5_create_principal(void *server_handle,
  339. kadm5_principal_ent_t ent,
  340. long mask, char *pass);
  341. kadm5_ret_t kadm5_create_principal_3(void *server_handle,
  342. kadm5_principal_ent_t ent,
  343. long mask,
  344. int n_ks_tuple,
  345. krb5_key_salt_tuple *ks_tuple,
  346. char *pass);
  347. kadm5_ret_t kadm5_delete_principal(void *server_handle,
  348. krb5_principal principal);
  349. kadm5_ret_t kadm5_modify_principal(void *server_handle,
  350. kadm5_principal_ent_t ent,
  351. long mask);
  352. kadm5_ret_t kadm5_rename_principal(void *server_handle,
  353. krb5_principal,krb5_principal);
  354. kadm5_ret_t kadm5_get_principal(void *server_handle,
  355. krb5_principal principal,
  356. kadm5_principal_ent_t ent,
  357. long mask);
  358. kadm5_ret_t kadm5_chpass_principal(void *server_handle,
  359. krb5_principal principal,
  360. char *pass);
  361. kadm5_ret_t kadm5_chpass_principal_3(void *server_handle,
  362. krb5_principal principal,
  363. krb5_boolean keepold,
  364. int n_ks_tuple,
  365. krb5_key_salt_tuple *ks_tuple,
  366. char *pass);
  367. kadm5_ret_t kadm5_randkey_principal(void *server_handle,
  368. krb5_principal principal,
  369. krb5_keyblock **keyblocks,
  370. int *n_keys);
  371. kadm5_ret_t kadm5_randkey_principal_3(void *server_handle,
  372. krb5_principal principal,
  373. krb5_boolean keepold,
  374. int n_ks_tuple,
  375. krb5_key_salt_tuple *ks_tuple,
  376. krb5_keyblock **keyblocks,
  377. int *n_keys);
  378. kadm5_ret_t kadm5_setv4key_principal(void *server_handle,
  379. krb5_principal principal,
  380. krb5_keyblock *keyblock);
  381. kadm5_ret_t kadm5_setkey_principal(void *server_handle,
  382. krb5_principal principal,
  383. krb5_keyblock *keyblocks,
  384. int n_keys);
  385. kadm5_ret_t kadm5_setkey_principal_3(void *server_handle,
  386. krb5_principal principal,
  387. krb5_boolean keepold,
  388. int n_ks_tuple,
  389. krb5_key_salt_tuple *ks_tuple,
  390. krb5_keyblock *keyblocks,
  391. int n_keys);
  392. kadm5_ret_t kadm5_decrypt_key(void *server_handle,
  393. kadm5_principal_ent_t entry, krb5_int32
  394. ktype, krb5_int32 stype, krb5_int32
  395. kvno, krb5_keyblock *keyblock,
  396. krb5_keysalt *keysalt, int *kvnop);
  397. kadm5_ret_t kadm5_create_policy(void *server_handle,
  398. kadm5_policy_ent_t ent,
  399. long mask);
  400. /*
  401. * kadm5_create_policy_internal is not part of the supported,
  402. * exposed API. It is available only in the server library, and you
  403. * shouldn't use it unless you know why it's there and how it's
  404. * different from kadm5_create_policy.
  405. */
  406. kadm5_ret_t kadm5_create_policy_internal(void *server_handle,
  407. kadm5_policy_ent_t
  408. entry, long mask);
  409. kadm5_ret_t kadm5_delete_policy(void *server_handle,
  410. kadm5_policy_t policy);
  411. kadm5_ret_t kadm5_modify_policy(void *server_handle,
  412. kadm5_policy_ent_t ent,
  413. long mask);
  414. /*
  415. * kadm5_modify_policy_internal is not part of the supported,
  416. * exposed API. It is available only in the server library, and you
  417. * shouldn't use it unless you know why it's there and how it's
  418. * different from kadm5_modify_policy.
  419. */
  420. kadm5_ret_t kadm5_modify_policy_internal(void *server_handle,
  421. kadm5_policy_ent_t
  422. entry, long mask);
  423. kadm5_ret_t kadm5_get_policy(void *server_handle,
  424. kadm5_policy_t policy,
  425. kadm5_policy_ent_t ent);
  426. kadm5_ret_t kadm5_get_privs(void *server_handle,
  427. long *privs);
  428. kadm5_ret_t kadm5_chpass_principal_util(void *server_handle,
  429. krb5_principal princ,
  430. char *new_pw,
  431. char **ret_pw,
  432. char *msg_ret,
  433. unsigned int msg_len);
  434. kadm5_ret_t kadm5_free_principal_ent(void *server_handle,
  435. kadm5_principal_ent_t
  436. ent);
  437. kadm5_ret_t kadm5_free_policy_ent(void *server_handle,
  438. kadm5_policy_ent_t ent);
  439. kadm5_ret_t kadm5_get_principals(void *server_handle,
  440. char *exp, char ***princs,
  441. int *count);
  442. kadm5_ret_t kadm5_get_policies(void *server_handle,
  443. char *exp, char ***pols,
  444. int *count);
  445. kadm5_ret_t kadm5_free_key_data(void *server_handle,
  446. krb5_int16 *n_key_data,
  447. krb5_key_data *key_data);
  448. kadm5_ret_t kadm5_free_name_list(void *server_handle, char **names,
  449. int count);
  450. krb5_error_code kadm5_init_krb5_context (krb5_context *);
  451. krb5_error_code kadm5_init_iprop(void *server_handle, char **db_args);
  452. /*
  453. * kadm5_get_principal_keys is used only by kadmin.local to extract existing
  454. * keys from the database without changing them. It should never be exposed
  455. * to the network protocol.
  456. */
  457. kadm5_ret_t kadm5_get_principal_keys(void *server_handle,
  458. krb5_principal principal,
  459. krb5_keyblock **keyblocks,
  460. int *n_keys);
  461. kadm5_ret_t kadm5_purgekeys(void *server_handle,
  462. krb5_principal principal,
  463. int keepkvno);
  464. kadm5_ret_t kadm5_get_strings(void *server_handle,
  465. krb5_principal principal,
  466. krb5_string_attr **strings_out,
  467. int *count_out);
  468. kadm5_ret_t kadm5_set_string(void *server_handle,
  469. krb5_principal principal,
  470. const char *key,
  471. const char *value);
  472. kadm5_ret_t kadm5_free_strings(void *server_handle,
  473. krb5_string_attr *strings,
  474. int count);
  475. KADM5INT_END_DECLS
  476. #endif /* __KADM5_ADMIN_H__ */