auth-client.h revision 9c3577aeb78a27920439ad9f1e62ee03699378c3
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef __AUTH_CLIENT_H
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#define __AUTH_CLIENT_H
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#include "network.h"
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen#include "../auth/auth-client-interface.h"
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct auth_client;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct auth_request;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenenum auth_request_flags {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen AUTH_REQUEST_FLAG_SECURED = 0x01,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen AUTH_REQUEST_FLAG_VALID_CLIENT_CERT = 0x02
f7423cbbd9dea363a5df18ebb96da055a977ae79Timo Sirainen};
2cd2518bab14292a67cf8a490b58ab9ef89879daTimo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct auth_mech_desc {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen char *name;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen enum mech_security_flags flags;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
6ec925f52d04ec8700e47cb005bd7ddc65ac5614Timo Sirainen
c60178b2610a9b193ff72aa18448398ef72529a1Timo Sirainenstruct auth_connect_id {
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen unsigned int server_pid;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int connect_uid;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
cf2e6953d03a1c22f272ec19432fc03c136ac1bbTimo Sirainenstruct auth_request_info {
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen const char *mech;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen const char *service;
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen const char *cert_username;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen enum auth_request_flags flags;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct ip_addr local_ip, remote_ip;
617e13833c798435e2be425b99c27ecaad1b8393Timo Sirainen unsigned int local_port, remote_port;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen const char *initial_resp_base64;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainentypedef void auth_request_callback_t(struct auth_request *request, int status,
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen const char *data_base64,
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen const char *const *args, void *context);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainentypedef void auth_connect_notify_callback_t(struct auth_client *client,
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen bool connected, void *context);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen/* Create new authentication client. */
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainenstruct auth_client *auth_client_new(unsigned int client_pid);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainenvoid auth_client_free(struct auth_client **client);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen/* Destroy all connections and reconnect. */
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainenvoid auth_client_reconnect(struct auth_client *client);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainenbool auth_client_is_connected(struct auth_client *client);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainenvoid auth_client_set_connect_notify(struct auth_client *client,
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen auth_connect_notify_callback_t *callback,
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen void *context);
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainenconst struct auth_mech_desc *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenauth_client_get_available_mechs(struct auth_client *client,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int *mech_count);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenconst struct auth_mech_desc *
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenauth_client_find_mech(struct auth_client *client, const char *name);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen/* Reserve connection for specific mechanism. The id can be given to
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen auth_client_request_new() to force it to use the same connection, or fail.
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen This is currently useful only for APOP authentication. Returns TRUE if
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen successfull. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenbool auth_client_reserve_connection(struct auth_client *client,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen const char *mech,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct auth_connect_id *id_r);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Create a new authentication request. callback is called whenever something
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen happens for the request. id can be NULL. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct auth_request *
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenauth_client_request_new(struct auth_client *client, struct auth_connect_id *id,
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen const struct auth_request_info *request_info,
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen auth_request_callback_t *callback, void *context,
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen const char **error_r);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen/* Continue authentication. Call when
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen reply->result == AUTH_CLIENT_REQUEST_CONTINUE */
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainenvoid auth_client_request_continue(struct auth_request *request,
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen const char *data_base64);
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen/* Abort ongoing authentication request. */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenvoid auth_client_request_abort(struct auth_request *request);
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen/* Return ID of this request. */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenunsigned int auth_client_request_get_id(struct auth_request *request);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen/* Return the PID of the server that handled this request. */
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainenunsigned int auth_client_request_get_server_pid(struct auth_request *request);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenvoid auth_client_connect_missing_servers(struct auth_client *client);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen#endif
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen