mech.h revision 73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0fae
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef __MECH_H
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen#define __MECH_H
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen#include "network.h"
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen#include "auth-client-interface.h"
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenenum auth_client_result {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen AUTH_CLIENT_RESULT_CONTINUE = 1,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen AUTH_CLIENT_RESULT_SUCCESS,
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen AUTH_CLIENT_RESULT_FAILURE
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen};
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstruct auth_request;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstruct auth_client_connection;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainentypedef void mech_callback_t(struct auth_request *request,
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen enum auth_client_result result,
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen const void *reply, size_t reply_size);
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstruct auth_request {
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen int refcount;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen pool_t pool;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen char *user;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen struct mech_module *mech;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen struct auth_client_connection *conn;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen unsigned int id;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen time_t created;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen const char *protocol;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen struct ip_addr local_ip, remote_ip;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mech_callback_t *callback;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen unsigned int accept_input:1;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen /* ... mechanism specific data ... */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen};
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainenstruct mech_module {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char *mech_name;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
29543188462c9348f365ec29115d777ffe4769d3Timo Sirainen enum mech_security_flags flags;
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen unsigned int passdb_need_plain:1;
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen unsigned int passdb_need_credentials:1;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen struct auth_request *(*auth_new)(void);
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen void (*auth_initial)(struct auth_request *request,
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen const unsigned char *data, size_t data_size,
0f97c2b6ec76e7f600e983cb952cf265a6189114Timo Sirainen mech_callback_t *callback);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen void (*auth_continue)(struct auth_request *request,
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen const unsigned char *data, size_t data_size,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mech_callback_t *callback);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen void (*auth_free)(struct auth_request *request);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen};
34b724d1d7e50b1ab24267a3b6fc089b1147c1abAki Tuomi
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstruct mech_module_list {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen struct mech_module_list *next;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen struct mech_module module;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen};
1da5113b93f5dd0543a155040daa7ae3f3718b8bTimo Sirainen
1da5113b93f5dd0543a155040daa7ae3f3718b8bTimo Sirainenextern struct mech_module_list *mech_modules;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern buffer_t *mech_handshake;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern const char *const *auth_realms;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern const char *default_realm;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern const char *anonymous_username;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern char username_chars[256];
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern int ssl_require_client_cert;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid mech_register_module(struct mech_module *module);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid mech_unregister_module(struct mech_module *module);
0f97c2b6ec76e7f600e983cb952cf265a6189114Timo Sirainenstruct mech_module *mech_module_find(const char *name);
0f97c2b6ec76e7f600e983cb952cf265a6189114Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenconst string_t *auth_mechanisms_get_list(void);
2848ed04730e9f2ed91829d41312ebc3132b5613Timo Sirainen
2848ed04730e9f2ed91829d41312ebc3132b5613Timo Sirainenvoid mech_auth_finish(struct auth_request *request,
2848ed04730e9f2ed91829d41312ebc3132b5613Timo Sirainen const void *data, size_t data_size, int success);
2848ed04730e9f2ed91829d41312ebc3132b5613Timo Sirainen
cf05592015b99607095f970bf914f5d069bf0666Timo Sirainenint mech_fix_username(char *username, const char **error_r);
cf05592015b99607095f970bf914f5d069bf0666Timo Sirainen
cf05592015b99607095f970bf914f5d069bf0666Timo Sirainenstruct auth_request *auth_request_new(struct mech_module *mech);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid auth_request_destroy(struct auth_request *request);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid auth_request_ref(struct auth_request *request);
402e999a878e0cc41a0afb830fea0a93afc75f0dTimo Sirainenint auth_request_unref(struct auth_request *request);
402e999a878e0cc41a0afb830fea0a93afc75f0dTimo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenconst struct var_expand_table *
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenauth_request_get_var_expand_table(const struct auth_request *auth_request,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char *(*escape_func)(const char *));
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenconst char *get_log_prefix(const struct auth_request *auth_request);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid auth_failure_buf_flush(void);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid mech_init(void);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid mech_deinit(void);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen#endif
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen