auth-client.h revision 90ed03ab289947f5576d2c616ada27724f50e9cd
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef AUTH_CLIENT_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#define AUTH_CLIENT_H
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "network.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#include "auth-client-interface.h"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct auth_client;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct auth_client_request;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
935960e45571872e38f730964f8ca1d116a1b532Timo Sirainenenum auth_request_flags {
935960e45571872e38f730964f8ca1d116a1b532Timo Sirainen AUTH_REQUEST_FLAG_SECURED = 0x01,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen AUTH_REQUEST_FLAG_VALID_CLIENT_CERT = 0x02
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenenum auth_request_status {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen AUTH_REQUEST_STATUS_FAIL = -1,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen AUTH_REQUEST_STATUS_CONTINUE,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen AUTH_REQUEST_STATUS_OK
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct auth_mech_desc {
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody char *name;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen enum mech_security_flags flags;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen};
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenstruct auth_connect_id {
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen unsigned int server_pid;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen unsigned int connect_uid;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen};
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenstruct auth_request_info {
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody const char *mech;
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen const char *service;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const char *cert_username;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen enum auth_request_flags flags;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen struct ip_addr local_ip, remote_ip;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int local_port, remote_port;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const char *initial_resp_base64;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainentypedef void auth_request_callback_t(struct auth_client_request *request,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen enum auth_request_status status,
263fa7b43fb222f9805b80f62090907fe3f9ec13Timo Sirainen const char *data_base64,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const char *const *args, void *context);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainentypedef void auth_connect_notify_callback_t(struct auth_client *client,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen bool connected, void *context);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Create new authentication client. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct auth_client *
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainenauth_client_init(const char *auth_socket_path, unsigned int client_pid,
f7f25f9e1a38678d0e97d2e609beac16285fac6bTimo Sirainen bool debug);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid auth_client_deinit(struct auth_client **client);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid auth_client_connect(struct auth_client *client);
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenvoid auth_client_disconnect(struct auth_client *client);
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenbool auth_client_is_connected(struct auth_client *client);
35fcdde46a71ac151c2518d48c841019f1181bb2Timo Sirainenvoid auth_client_set_connect_notify(struct auth_client *client,
35fcdde46a71ac151c2518d48c841019f1181bb2Timo Sirainen auth_connect_notify_callback_t *callback,
35fcdde46a71ac151c2518d48c841019f1181bb2Timo Sirainen void *context);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenconst struct auth_mech_desc *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenauth_client_get_available_mechs(struct auth_client *client,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int *mech_count);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenconst struct auth_mech_desc *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenauth_client_find_mech(struct auth_client *client, const char *name);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Return current connection's identifiers. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid auth_client_get_connect_id(struct auth_client *client,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int *server_pid_r,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int *connect_uid_r);
5733207dc3ec10e6e5a6e0a8b30fbd1b061062b9Timo Sirainen
cf7857bce68a33cdabe88bb15568e21921eb5ac7Aki Tuomi/* Create a new authentication request. callback is called whenever something
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen happens for the request. */
3e10cd470988298dc2b37f548ad03da4d7c11ffaTimo Sirainenstruct auth_client_request *
74c369c0587c5f6bb13d730675d8bc455c5c3f8eTimo Sirainenauth_client_request_new(struct auth_client *client,
74c369c0587c5f6bb13d730675d8bc455c5c3f8eTimo Sirainen const struct auth_request_info *request_info,
311cf367b949f360c9a90822f06f39df31ec69e3Timo Sirainen auth_request_callback_t *callback, void *context);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Continue authentication. Call when
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen reply->result == AUTH_CLIENT_REQUEST_CONTINUE */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid auth_client_request_continue(struct auth_client_request *request,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen const char *data_base64);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Abort ongoing authentication request. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid auth_client_request_abort(struct auth_client_request **request);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Return ID of this request. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenunsigned int auth_client_request_get_id(struct auth_client_request *request);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/* Return the PID of the server that handled this request. */
df27aa70a3f0250767eb8a154981cd7f5dadcc91Timo Sirainenunsigned int
cf7857bce68a33cdabe88bb15568e21921eb5ac7Aki Tuomiauth_client_request_get_server_pid(struct auth_client_request *request);
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen/* Return cookie of the server that handled this request. */
3e10cd470988298dc2b37f548ad03da4d7c11ffaTimo Sirainenconst char *auth_client_request_get_cookie(struct auth_client_request *request);
74c369c0587c5f6bb13d730675d8bc455c5c3f8eTimo Sirainen
74c369c0587c5f6bb13d730675d8bc455c5c3f8eTimo Sirainen#endif
311cf367b949f360c9a90822f06f39df31ec69e3Timo Sirainen