auth-client.h revision 8eea67470c1bd8562a62e7445d930bb2079b1a43
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen#ifndef __AUTH_CLIENT_H
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen#define __AUTH_CLIENT_H
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen#include "network.h"
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen#include "../auth/auth-client-interface.h"
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenstruct auth_client;
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenstruct auth_request;
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainenstruct auth_mech_desc {
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainen char *name;
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainen unsigned int plaintext:1;
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainen unsigned int advertise:1;
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainen};
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainen
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainenstruct auth_connect_id {
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen unsigned int server_pid;
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen unsigned int connect_uid;
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen};
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainenstruct auth_request_info {
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen const char *mech;
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen const char *protocol;
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen enum auth_client_request_new_flags flags;
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen struct ip_addr local_ip, remote_ip;
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen const unsigned char *initial_resp_data;
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen size_t initial_resp_size;
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen};
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* reply is NULL if auth connection died */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainentypedef void auth_request_callback_t(struct auth_request *request,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen struct auth_client_request_reply *reply,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen const unsigned char *data, void *context);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainentypedef void auth_connect_notify_callback_t(struct auth_client *client,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen int connected, void *context);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* Create new authentication client. */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenstruct auth_client *auth_client_new(unsigned int client_pid);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenvoid auth_client_free(struct auth_client *client);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenint auth_client_is_connected(struct auth_client *client);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenvoid auth_client_set_connect_notify(struct auth_client *client,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen auth_connect_notify_callback_t *callback,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen void *context);
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainenconst struct auth_mech_desc *
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainenauth_client_get_available_mechs(struct auth_client *client,
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainen unsigned int *mech_count);
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainenconst struct auth_mech_desc *
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo Sirainenauth_client_find_mech(struct auth_client *client, const char *name);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen/* Reserve connection for specific mechanism. The id can be given to
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen auth_client_request_new() to force it to use the same connection, or fail.
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen This is currently useful only for APOP authentication. Returns TRUE if
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen successfull. */
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainenint auth_client_reserve_connection(struct auth_client *client, const char *mech,
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen struct auth_connect_id *id_r);
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* Create a new authentication request. callback is called whenever something
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainen happens for the request. id can be NULL. */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenstruct auth_request *
8eea67470c1bd8562a62e7445d930bb2079b1a43Timo Sirainenauth_client_request_new(struct auth_client *client, struct auth_connect_id *id,
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainen const struct auth_request_info *request_info,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen auth_request_callback_t *callback, void *context,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen const char **error_r);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* Continue authentication. Call when
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen reply->result == AUTH_CLIENT_REQUEST_CONTINUE */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenvoid auth_client_request_continue(struct auth_request *request,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen const unsigned char *data, size_t data_size);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* Abort ongoing authentication request. */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenvoid auth_client_request_abort(struct auth_request *request);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* Return ID of this request. */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenunsigned int auth_client_request_get_id(struct auth_request *request);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen/* Return the PID of the server that handled this request. */
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainenunsigned int auth_client_request_get_server_pid(struct auth_request *request);
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen/* -- Using lib-auth with external I/O loop -- */
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainentypedef void *input_func_add_t(int fd, void (*cb)(void *), void *context);
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainentypedef void *input_func_remove_t(void *io);
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainenstruct auth_client *auth_client_new_external(unsigned int client_pid,
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen const char *socket_paths,
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen input_func_add_t *add_func,
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen input_func_remove_t *remove_func);
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen/* Call every few seconds. */
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainenvoid auth_client_connect_missing_servers(struct auth_client *client);
acf3b7bf3a8891b118a71c45e6c48d17bc90b259Timo Sirainen
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen#endif