providers/ident: cleanup things

This commit is contained in:
Elizabeth Myers 2016-03-26 15:39:55 -05:00
parent 646e6567c7
commit 06f3496ab3

View file

@ -18,6 +18,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Largely adapted from old s_auth.c, but reworked for authd. rDNS code
* moved to its own provider.
*
* --Elizafox 13 March 2016
*/
#include "stdinc.h"
#include "match.h"
#include "authd.h"
@ -60,83 +66,9 @@ static struct ev_entry *timeout_ev;
static int ident_timeout = 5;
bool ident_init(void)
{
timeout_ev = rb_event_addish("timeout_ident_queries_event", timeout_ident_queries_event, NULL, 1);
return (timeout_ev != NULL);
}
void ident_destroy(void)
{
struct auth_client *auth;
rb_dictionary_iter iter;
/* Nuke all ident queries */
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
if(auth->data[PROVIDER_IDENT] != NULL)
client_fail(auth, REPORT_FAIL);
}
}
bool ident_start(struct auth_client *auth)
{
struct ident_query *query = rb_malloc(sizeof(struct ident_query));
struct rb_sockaddr_storage l_addr, c_addr;
int family;
rb_fde_t *F;
auth->data[PROVIDER_IDENT] = query;
query->timeout = rb_current_time() + ident_timeout;
if((F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL)
{
client_fail(auth, REPORT_FAIL);
return true; /* Not a fatal error */
}
query->F = F;
/* Build sockaddr_storages for rb_connect_tcp below */
memcpy(&l_addr, &auth->l_addr, sizeof(l_addr));
memcpy(&c_addr, &auth->c_addr, sizeof(c_addr));
/* Set the ports correctly */
#ifdef RB_IPV6
if(GET_SS_FAMILY(&l_addr) == AF_INET6)
((struct sockaddr_in6 *)&l_addr)->sin6_port = 0;
else
#endif
((struct sockaddr_in *)&l_addr)->sin_port = 0;
#ifdef RB_IPV6
if(GET_SS_FAMILY(&c_addr) == AF_INET6)
((struct sockaddr_in6 *)&c_addr)->sin6_port = htons(113);
else
#endif
((struct sockaddr_in *)&c_addr)->sin_port = htons(113);
rb_connect_tcp(F, (struct sockaddr *)&c_addr,
(struct sockaddr *)&l_addr,
GET_SS_LEN(&l_addr), ident_connected,
query, ident_timeout);
notice_client(auth->cid, messages[REPORT_LOOKUP]);
set_provider_on(auth, PROVIDER_IDENT);
return true;
}
void ident_cancel(struct auth_client *auth)
{
struct ident_query *query = auth->data[PROVIDER_IDENT];
if(query != NULL)
client_fail(auth, REPORT_FAIL);
}
/* Timeout outstanding queries */
static void timeout_ident_queries_event(void *notused)
static void
timeout_ident_queries_event(void *notused)
{
struct auth_client *auth;
rb_dictionary_iter iter;
@ -161,7 +93,8 @@ static void timeout_ident_queries_event(void *notused)
* a write buffer far greater than this message to store it in should
* problems arise. -avalon
*/
static void ident_connected(rb_fde_t *F, int error, void *data)
static void
ident_connected(rb_fde_t *F, int error, void *data)
{
struct auth_client *auth = data;
struct ident_query *query = auth->data[PROVIDER_IDENT];
@ -240,7 +173,8 @@ read_ident_reply(rb_fde_t *F, void *data)
client_success(auth);
}
static void client_fail(struct auth_client *auth, ident_message report)
static void
client_fail(struct auth_client *auth, ident_message report)
{
struct ident_query *query = auth->data[PROVIDER_IDENT];
@ -254,7 +188,8 @@ static void client_fail(struct auth_client *auth, ident_message report)
provider_done(auth, PROVIDER_IDENT);
}
static void client_success(struct auth_client *auth)
static void
client_success(struct auth_client *auth)
{
struct ident_query *query = auth->data[PROVIDER_IDENT];
@ -269,8 +204,7 @@ static void client_success(struct auth_client *auth)
/* get_valid_ident
* parse ident query reply from identd server
*
* Torn out of old s_auth.c because there was nothing wrong with it
* --Elizafox
* Taken from old s_auth.c --Elizafox
*
* Inputs - pointer to ident buf
* Outputs - NULL if no valid ident found, otherwise pointer to name
@ -331,6 +265,84 @@ get_valid_ident(char *buf)
return (colon3Ptr);
}
static bool
ident_init(void)
{
timeout_ev = rb_event_addish("timeout_ident_queries_event", timeout_ident_queries_event, NULL, 1);
return (timeout_ev != NULL);
}
static void
ident_destroy(void)
{
struct auth_client *auth;
rb_dictionary_iter iter;
/* Nuke all ident queries */
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
if(auth->data[PROVIDER_IDENT] != NULL)
client_fail(auth, REPORT_FAIL);
}
}
static bool ident_start(struct auth_client *auth)
{
struct ident_query *query = rb_malloc(sizeof(struct ident_query));
struct rb_sockaddr_storage l_addr, c_addr;
int family;
rb_fde_t *F;
auth->data[PROVIDER_IDENT] = query;
query->timeout = rb_current_time() + ident_timeout;
if((F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL)
{
client_fail(auth, REPORT_FAIL);
return true; /* Not a fatal error */
}
query->F = F;
/* Build sockaddr_storages for rb_connect_tcp below */
memcpy(&l_addr, &auth->l_addr, sizeof(l_addr));
memcpy(&c_addr, &auth->c_addr, sizeof(c_addr));
/* Set the ports correctly */
#ifdef RB_IPV6
if(GET_SS_FAMILY(&l_addr) == AF_INET6)
((struct sockaddr_in6 *)&l_addr)->sin6_port = 0;
else
#endif
((struct sockaddr_in *)&l_addr)->sin_port = 0;
#ifdef RB_IPV6
if(GET_SS_FAMILY(&c_addr) == AF_INET6)
((struct sockaddr_in6 *)&c_addr)->sin6_port = htons(113);
else
#endif
((struct sockaddr_in *)&c_addr)->sin_port = htons(113);
rb_connect_tcp(F, (struct sockaddr *)&c_addr,
(struct sockaddr *)&l_addr,
GET_SS_LEN(&l_addr), ident_connected,
query, ident_timeout);
notice_client(auth->cid, messages[REPORT_LOOKUP]);
set_provider_on(auth, PROVIDER_IDENT);
return true;
}
static void
ident_cancel(struct auth_client *auth)
{
struct ident_query *query = auth->data[PROVIDER_IDENT];
if(query != NULL)
client_fail(auth, REPORT_FAIL);
}
struct auth_provider ident_provider =
{