passdb.h revision 74674a53a72dab535c61f455b2246ef2797844ea
7cb128dc4cae2a03a742f63ba7afee23c78e3af0Phil Carmody#ifndef PASSDB_H
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch#define PASSDB_H
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch#include "md5.h"
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch#define IS_VALID_PASSWD(pass) \
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch ((pass)[0] != '\0' && (pass)[0] != '*' && (pass)[0] != '!')
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschstruct auth_request;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschstruct auth_passdb_settings;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschenum passdb_result {
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen PASSDB_RESULT_INTERNAL_FAILURE = -1,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch PASSDB_RESULT_SCHEME_NOT_AVAILABLE = -2,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch PASSDB_RESULT_USER_UNKNOWN = -3,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch PASSDB_RESULT_USER_DISABLED = -4,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch PASSDB_RESULT_PASS_EXPIRED = -5,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen PASSDB_RESULT_PASSWORD_MISMATCH = 0,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch PASSDB_RESULT_OK = 1
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch};
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainentypedef void verify_plain_callback_t(enum passdb_result result,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch struct auth_request *request);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschtypedef void lookup_credentials_callback_t(enum passdb_result result,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen const unsigned char *credentials,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen size_t size,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen struct auth_request *request);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainentypedef void set_credentials_callback_t(bool success,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen struct auth_request *request);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainenstruct passdb_module_interface {
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen const char *name;
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen struct passdb_module *(*preinit)(pool_t pool, const char *args);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch void (*init)(struct passdb_module *module);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen void (*deinit)(struct passdb_module *module);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen /* Check if plaintext password matches */
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen void (*verify_plain)(struct auth_request *request, const char *password,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen verify_plain_callback_t *callback);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen /* Return authentication credentials, set in
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen auth_request->credentials. */
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen void (*lookup_credentials)(struct auth_request *request,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen lookup_credentials_callback_t *callback);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen /* Update credentials */
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen int (*set_credentials)(struct auth_request *request,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen const char *new_credentials,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen set_credentials_callback_t *callback);
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen};
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainenstruct passdb_module {
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen const char *args;
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen /* The default caching key for this module, or NULL if caching isn't
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen wanted. This is updated by settings in auth_passdb. */
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch#define default_cache_key cache_key /* FIXME: remove in v2.3 - for API backwards compatibility */
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch const char *default_cache_key;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch /* Default password scheme for this module.
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch If cache_key is set, must not be NULL. */
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch const char *default_pass_scheme;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch /* If blocking is set to TRUE, use child processes to access
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch this passdb. */
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch bool blocking;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch /* id is used by blocking passdb to identify the passdb */
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch unsigned int id;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch /* number of time init() has been called */
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch int init_refcount;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch struct passdb_template *default_fields_tmpl;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch struct passdb_template *override_fields_tmpl;
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen struct passdb_module_interface iface;
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch};
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch/* Try to get credentials in wanted scheme (request->credentials_scheme) from
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch given input. Returns FALSE if this wasn't possible (unknown scheme,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch conversion not possible or invalid credentials).
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch If wanted scheme is "", the credentials are returned as-is without any
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch checks. This is useful mostly just to see if there exist any credentials
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch at all. */
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainenbool passdb_get_credentials(struct auth_request *auth_request,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen const char *input, const char *input_scheme,
83773f7eb5e12e68f5efee7278bdab35d2ee84c0Timo Sirainen const unsigned char **credentials_r,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch size_t *size_r);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdb_handle_credentials(enum passdb_result result,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch const char *password, const char *scheme,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch lookup_credentials_callback_t *callback,
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch struct auth_request *auth_request);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschstruct passdb_module *
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschpassdb_preinit(pool_t pool, const struct auth_passdb_settings *set);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdb_init(struct passdb_module *passdb);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdb_deinit(struct passdb_module *passdb);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdb_register_module(struct passdb_module_interface *iface);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdb_unregister_module(struct passdb_module_interface *iface);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdbs_generate_md5(unsigned char md5[MD5_RESULTLEN]);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdbs_init(void);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Boschvoid passdbs_deinit(void);
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch#include "auth-request.h"
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch#endif
836e690c0e2d7494b8c0a6f4984dd13248841f2fStephan Bosch