2016-03-17 21:23:27 +00:00
|
|
|
/* authd/provider.h - authentication provider framework
|
|
|
|
* Copyright (c) 2016 Elizabeth Myers <elizabeth@interlinked.me>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice is present in all copies.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CHARYBDIS_AUTHD_PROVIDER_H__
|
|
|
|
#define __CHARYBDIS_AUTHD_PROVIDER_H__
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
2016-03-23 00:13:54 +00:00
|
|
|
#include "rb_dictionary.h"
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-03-23 00:13:54 +00:00
|
|
|
#define MAX_PROVIDERS 32 /* This should be enough */
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
/* Registered providers */
|
|
|
|
typedef enum
|
|
|
|
{
|
2016-03-23 00:13:54 +00:00
|
|
|
PROVIDER_RDNS,
|
|
|
|
PROVIDER_IDENT,
|
|
|
|
PROVIDER_BLACKLIST,
|
2016-03-17 21:23:27 +00:00
|
|
|
} provider_t;
|
|
|
|
|
2016-03-25 00:36:41 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
L_DEBUG = 'D',
|
|
|
|
L_INFO = 'I',
|
|
|
|
L_WARN = 'W',
|
|
|
|
L_CRIT ='C',
|
|
|
|
} notice_level_t;
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
struct auth_client
|
|
|
|
{
|
|
|
|
uint16_t cid; /* Client ID */
|
|
|
|
|
|
|
|
char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
|
|
|
|
uint16_t l_port; /* Listener port */
|
2016-03-23 23:56:29 +00:00
|
|
|
struct rb_sockaddr_storage l_addr; /* Listener address/port */
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
char c_ip[HOSTIPLEN + 1]; /* Client IP address */
|
|
|
|
uint16_t c_port; /* Client port */
|
2016-03-23 23:56:29 +00:00
|
|
|
struct rb_sockaddr_storage c_addr; /* Client address/port */
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
|
|
|
|
char username[USERLEN + 1]; /* Used for ident lookup */
|
|
|
|
|
2016-03-23 00:13:54 +00:00
|
|
|
uint32_t providers; /* Providers at work,
|
2016-03-17 21:23:27 +00:00
|
|
|
* none left when set to 0 */
|
2016-03-26 01:46:58 +00:00
|
|
|
uint32_t providers_done; /* Providers completed */
|
2016-03-19 20:02:11 +00:00
|
|
|
|
2016-03-23 00:13:54 +00:00
|
|
|
void *data[MAX_PROVIDERS]; /* Provider-specific data slots */
|
2016-03-17 21:23:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef bool (*provider_init_t)(void);
|
|
|
|
typedef void (*provider_destroy_t)(void);
|
|
|
|
|
2016-03-25 00:23:49 +00:00
|
|
|
typedef bool (*provider_start_t)(struct auth_client *);
|
|
|
|
typedef void (*provider_cancel_t)(struct auth_client *);
|
|
|
|
typedef void (*provider_complete_t)(struct auth_client *, provider_t provider);
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
struct auth_provider
|
|
|
|
{
|
|
|
|
rb_dlink_node node;
|
|
|
|
|
|
|
|
provider_t id;
|
|
|
|
|
|
|
|
provider_init_t init; /* Initalise the provider */
|
|
|
|
provider_destroy_t destroy; /* Terminate the provider */
|
|
|
|
|
2016-03-25 00:23:49 +00:00
|
|
|
provider_start_t start; /* Perform authentication */
|
2016-03-17 21:23:27 +00:00
|
|
|
provider_cancel_t cancel; /* Authentication cancelled */
|
|
|
|
provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
|
|
|
|
};
|
|
|
|
|
|
|
|
extern rb_dlink_list auth_providers;
|
2016-03-23 14:15:18 +00:00
|
|
|
extern rb_dictionary *auth_clients;
|
2016-03-23 00:13:54 +00:00
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
extern struct auth_provider rdns_provider;
|
|
|
|
extern struct auth_provider ident_provider;
|
2016-03-26 01:07:36 +00:00
|
|
|
extern struct auth_provider blacklist_provider;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
void load_provider(struct auth_provider *provider);
|
|
|
|
void unload_provider(struct auth_provider *provider);
|
|
|
|
|
|
|
|
void init_providers(void);
|
|
|
|
void destroy_providers(void);
|
|
|
|
void cancel_providers(struct auth_client *auth);
|
|
|
|
|
|
|
|
void provider_done(struct auth_client *auth, provider_t id);
|
|
|
|
void accept_client(struct auth_client *auth, provider_t id);
|
2016-03-19 20:02:11 +00:00
|
|
|
void reject_client(struct auth_client *auth, provider_t id, const char *reason);
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-03-25 00:23:49 +00:00
|
|
|
void notice_client(struct auth_client *auth, const char *fmt, ...);
|
2016-03-25 00:36:41 +00:00
|
|
|
void warn_opers(notice_level_t level, const char *fmt, ...);
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
void handle_new_connection(int parc, char *parv[]);
|
|
|
|
|
|
|
|
/* Provider is operating on this auth_client (set this if you have async work to do) */
|
2016-03-26 01:46:58 +00:00
|
|
|
static inline void set_provider_on(struct auth_client *auth, provider_t provider)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-03-23 00:13:54 +00:00
|
|
|
auth->providers |= (1 << provider);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Provider is no longer operating on this auth client (you should use provider_done) */
|
2016-03-26 01:46:58 +00:00
|
|
|
static inline void set_provider_off(struct auth_client *auth, provider_t provider)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-03-23 00:13:54 +00:00
|
|
|
auth->providers &= ~(1 << provider);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 01:46:58 +00:00
|
|
|
/* Set the provider to done (you should use provider_done) */
|
|
|
|
static inline void set_provider_done(struct auth_client *auth, provider_t provider)
|
|
|
|
{
|
|
|
|
auth->providers_done |= (1 << provider);
|
|
|
|
}
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
/* Check if provider is operating on this auth client */
|
2016-03-26 01:46:58 +00:00
|
|
|
static inline bool is_provider_on(struct auth_client *auth, provider_t provider)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-03-23 00:13:54 +00:00
|
|
|
return auth->providers & (1 << provider);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 01:46:58 +00:00
|
|
|
static inline bool is_provider_done(struct auth_client *auth, provider_t provider)
|
|
|
|
{
|
|
|
|
return auth->providers_done & (1 << provider);
|
|
|
|
}
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
#endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */
|