Path: blob/main/crypto/krb5/src/lib/kadm5/server_internal.h
39536 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved3*4* $Header$5*/67/*8* This header file is used internally by the Admin API server9* libraries and Admin server. IF YOU THINK YOU NEED TO USE THIS FILE10* FOR ANYTHING, YOU'RE ALMOST CERTAINLY WRONG.11*/1213#ifndef __KADM5_SERVER_INTERNAL_H__14#define __KADM5_SERVER_INTERNAL_H__1516#include "autoconf.h"17#ifdef HAVE_MEMORY_H18#include <memory.h>19#endif20#include <stdlib.h>21#include <errno.h>22#include <kdb.h>23#include <kadm5/admin.h>24#include <krb5/plugin.h>25#include "admin_internal.h"2627/*28* This is the history key version for a newly created DB. We use this value29* for principals which have no password history yet to avoid having to look up30* the history key. Values other than 2 will cause compatibility issues with31* pre-1.8 libkadm5 code; the older code will reject key changes when it sees32* an unexpected value of admin_history_kvno.33*/34#define INITIAL_HIST_KVNO 23536/* A pwqual_handle represents a password quality plugin module. */37typedef struct pwqual_handle_st *pwqual_handle;3839typedef struct kadm5_hook_handle_st *kadm5_hook_handle;4041typedef struct _kadm5_server_handle_t {42krb5_ui_4 magic_number;43krb5_ui_4 struct_version;44krb5_ui_4 api_version;45krb5_context context;46krb5_principal current_caller;47kadm5_config_params params;48struct _kadm5_server_handle_t *lhandle;49char **db_args;50pwqual_handle *qual_handles;51kadm5_hook_handle *hook_handles;52} kadm5_server_handle_rec, *kadm5_server_handle_t;5354#define OSA_ADB_PRINC_VERSION_1 0x12345C015556typedef struct _osa_pw_hist_t {57int n_key_data;58krb5_key_data *key_data;59} osa_pw_hist_ent, *osa_pw_hist_t;6061typedef struct _osa_princ_ent_t {62int version;63char *policy;64long aux_attributes;65unsigned int old_key_len;66unsigned int old_key_next;67krb5_kvno admin_history_kvno;68osa_pw_hist_ent *old_keys;69} osa_princ_ent_rec, *osa_princ_ent_t;707172kadm5_ret_t passwd_check(kadm5_server_handle_t handle,73const char *pass, kadm5_policy_ent_t policy,74krb5_principal principal);75kadm5_ret_t principal_exists(krb5_principal principal);76krb5_error_code kdb_init_master(kadm5_server_handle_t handle,77char *r, int from_keyboard);78krb5_error_code kdb_get_active_mkey(kadm5_server_handle_t handle,79krb5_kvno *act_kvno_out,80krb5_keyblock **act_mkey_out);81krb5_error_code kdb_init_hist(kadm5_server_handle_t handle,82char *r);83krb5_error_code kdb_get_hist_key(kadm5_server_handle_t handle,84krb5_keyblock **keyblocks_out,85krb5_kvno *kvno_out);86void kdb_free_keyblocks(kadm5_server_handle_t handle,87krb5_keyblock *keyblocks);88krb5_error_code kdb_get_entry(kadm5_server_handle_t handle,89krb5_principal principal,90krb5_db_entry **kdb, osa_princ_ent_rec *adb);91krb5_error_code kdb_free_entry(kadm5_server_handle_t handle,92krb5_db_entry *kdb, osa_princ_ent_rec *adb);93krb5_error_code kdb_put_entry(kadm5_server_handle_t handle,94krb5_db_entry *kdb, osa_princ_ent_rec *adb);95krb5_error_code kdb_delete_entry(kadm5_server_handle_t handle,96krb5_principal name);97krb5_error_code kdb_iter_entry(kadm5_server_handle_t handle,98char *match_entry,99void (*iter_fct)(void *, krb5_principal),100void *data);101102kadm5_ret_t init_pwqual(kadm5_server_handle_t handle);103void destroy_pwqual(kadm5_server_handle_t handle);104105/* XXX this ought to be in libkrb5.a, but isn't */106kadm5_ret_t krb5_copy_key_data_contents(krb5_context context,107krb5_key_data *from,108krb5_key_data *to);109kadm5_ret_t krb5_free_key_data_contents(krb5_context context,110krb5_key_data *key);111112/*113* *Warning*114* *Warning* This is going to break if we115* *Warning* ever go multi-threaded116* *Warning*117*/118extern krb5_principal current_caller;119120/*121* Why is this (or something similar) not defined *anywhere* in krb5?122*/123#define KSUCCESS 0124#define WORD_NOT_FOUND 1125126/*127* all the various mask bits or'd together128*/129130#define ALL_PRINC_MASK \131(KADM5_PRINCIPAL | KADM5_PRINC_EXPIRE_TIME | KADM5_PW_EXPIRATION | \132KADM5_LAST_PWD_CHANGE | KADM5_ATTRIBUTES | KADM5_MAX_LIFE | \133KADM5_MOD_TIME | KADM5_MOD_NAME | KADM5_KVNO | KADM5_MKVNO | \134KADM5_AUX_ATTRIBUTES | KADM5_POLICY_CLR | KADM5_POLICY | \135KADM5_MAX_RLIFE | KADM5_TL_DATA | KADM5_KEY_DATA | KADM5_FAIL_AUTH_COUNT )136137#define ALL_POLICY_MASK \138(KADM5_POLICY | KADM5_PW_MAX_LIFE | KADM5_PW_MIN_LIFE | \139KADM5_PW_MIN_LENGTH | KADM5_PW_MIN_CLASSES | KADM5_PW_HISTORY_NUM | \140KADM5_REF_COUNT | KADM5_PW_MAX_FAILURE | KADM5_PW_FAILURE_COUNT_INTERVAL | \141KADM5_PW_LOCKOUT_DURATION | KADM5_POLICY_ATTRIBUTES | \142KADM5_POLICY_MAX_LIFE | KADM5_POLICY_MAX_RLIFE | \143KADM5_POLICY_ALLOWED_KEYSALTS | KADM5_POLICY_TL_DATA)144145#define SERVER_CHECK_HANDLE(handle) \146{ \147kadm5_server_handle_t srvr = \148(kadm5_server_handle_t) handle; \149\150if (! srvr->current_caller) \151return KADM5_BAD_SERVER_HANDLE; \152if (! srvr->lhandle) \153return KADM5_BAD_SERVER_HANDLE; \154}155156#define CHECK_HANDLE(handle) \157GENERIC_CHECK_HANDLE(handle, KADM5_OLD_SERVER_API_VERSION, \158KADM5_NEW_SERVER_API_VERSION) \159SERVER_CHECK_HANDLE(handle)160161bool_t xdr_osa_princ_ent_rec(XDR *xdrs, osa_princ_ent_t objp);162163void164osa_free_princ_ent(osa_princ_ent_t val);165166/*** Password quality plugin consumer interface ***/167168/* Load all available password quality plugin modules, bind each module to the169* realm's dictionary file, and store the result into *handles_out. Free the170* result with k5_pwqual_free_handles. */171krb5_error_code172k5_pwqual_load(krb5_context context, const char *dict_file,173pwqual_handle **handles_out);174175/* Release a handle list allocated by k5_pwqual_load. */176void177k5_pwqual_free_handles(krb5_context context, pwqual_handle *handles);178179/* Return the name of a password quality plugin module. */180const char *181k5_pwqual_name(krb5_context context, pwqual_handle handle);182183/* Check a password using a password quality plugin module. */184krb5_error_code185k5_pwqual_check(krb5_context context, pwqual_handle handle,186const char *password, const char *policy_name,187krb5_principal princ);188189/*** initvt functions for built-in password quality modules ***/190191/* The dict module checks passwords against the realm's dictionary. */192krb5_error_code193pwqual_dict_initvt(krb5_context context, int maj_ver, int min_ver,194krb5_plugin_vtable vtable);195196/* The empty module rejects empty passwords (even with no password policy). */197krb5_error_code198pwqual_empty_initvt(krb5_context context, int maj_ver, int min_ver,199krb5_plugin_vtable vtable);200201/* The hesiod module checks passwords against GECOS fields from Hesiod passwd202* information (only if the tree was built with Hesiod support). */203krb5_error_code204pwqual_hesiod_initvt(krb5_context context, int maj_ver, int min_ver,205krb5_plugin_vtable vtable);206207/* The princ module checks passwords against principal components. */208krb5_error_code209pwqual_princ_initvt(krb5_context context, int maj_ver, int min_ver,210krb5_plugin_vtable vtable);211212/** @{213* @name kadm5_hook plugin support214*/215216/** Load all kadm5_hook plugins. */217krb5_error_code218k5_kadm5_hook_load(krb5_context context,219kadm5_hook_handle **handles_out);220221/** Free handles allocated by k5_kadm5_hook_load(). */222void223k5_kadm5_hook_free_handles(krb5_context context, kadm5_hook_handle *handles);224225/** Call the chpass entry point on every kadm5_hook in @a handles. */226kadm5_ret_t227k5_kadm5_hook_chpass (krb5_context context,228kadm5_hook_handle *handles,229int stage, krb5_principal princ,230krb5_boolean keepold,231int n_ks_tuple,232krb5_key_salt_tuple *ks_tuple,233const char *newpass);234235/** Call the create entry point for kadm5_hook_plugins. */236kadm5_ret_t237k5_kadm5_hook_create (krb5_context context,238kadm5_hook_handle *handles,239int stage,240kadm5_principal_ent_t princ, long mask,241int n_ks_tuple,242krb5_key_salt_tuple *ks_tuple,243const char *newpass);244245/** Call modify kadm5_hook entry point. */246kadm5_ret_t247k5_kadm5_hook_modify (krb5_context context,248kadm5_hook_handle *handles,249int stage,250kadm5_principal_ent_t princ, long mask);251252/** Call remove kadm5_hook entry point. */253kadm5_ret_t254k5_kadm5_hook_remove (krb5_context context,255kadm5_hook_handle *handles,256int stage,257krb5_principal princ);258259/** Call rename kadm5_hook entry point. */260kadm5_ret_t261k5_kadm5_hook_rename (krb5_context context,262kadm5_hook_handle *handles,263int stage,264krb5_principal oprinc, krb5_principal nprinc);265266/** Call alias kadm5_hook entry point. */267kadm5_ret_t268k5_kadm5_hook_alias (krb5_context context,269kadm5_hook_handle *handles,270int stage,271krb5_principal alias, krb5_principal target);272273/** @}*/274275#endif /* __KADM5_SERVER_INTERNAL_H__ */276277278