2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* s_auth.c: Functions for querying a users ident.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*
|
2016-03-08 19:47:41 +00:00
|
|
|
*/
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes:
|
|
|
|
* July 6, 1999 - Rewrote most of the code here. When a client connects
|
|
|
|
* to the server and passes initial socket validation checks, it
|
|
|
|
* is owned by this module (auth) which returns it to the rest of the
|
|
|
|
* server when dns and auth queries are finished. Until the client is
|
|
|
|
* released, the server does not know it exists and does not process
|
|
|
|
* any messages from it.
|
|
|
|
* --Bleep Thomas Helvey <tomh@inxpress.net>
|
|
|
|
*/
|
|
|
|
#include "stdinc.h"
|
2016-03-20 00:14:26 +00:00
|
|
|
#include "defaults.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_auth.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "common.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "packet.h"
|
2016-01-08 12:31:08 +00:00
|
|
|
#include "dns.h"
|
2008-04-03 02:52:01 +00:00
|
|
|
#include "logger.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_stats.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "blacklist.h"
|
2013-09-10 05:35:56 +00:00
|
|
|
#include "s_assert.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-06-20 22:58:08 +00:00
|
|
|
struct AuthRequest
|
|
|
|
{
|
|
|
|
rb_dlink_node node;
|
|
|
|
struct Client *client; /* pointer to client struct for request */
|
2016-01-08 12:31:08 +00:00
|
|
|
uint16_t dns_id; /* DNS Query */
|
2008-06-20 22:58:08 +00:00
|
|
|
unsigned int flags; /* current state of request */
|
|
|
|
rb_fde_t *F; /* file descriptor for auth queries */
|
|
|
|
time_t timeout; /* time when query expires */
|
2008-06-20 23:52:57 +00:00
|
|
|
uint16_t lport;
|
|
|
|
uint16_t rport;
|
2008-06-20 22:58:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flag values for AuthRequest
|
|
|
|
* NAMESPACE: AM_xxx - Authentication Module
|
|
|
|
*/
|
|
|
|
#define AM_AUTH_CONNECTING (1 << 0)
|
|
|
|
#define AM_AUTH_PENDING (1 << 1)
|
|
|
|
#define AM_DNS_PENDING (1 << 2)
|
|
|
|
|
|
|
|
#define SetDNSPending(x) ((x)->flags |= AM_DNS_PENDING)
|
|
|
|
#define ClearDNSPending(x) ((x)->flags &= ~AM_DNS_PENDING)
|
|
|
|
#define IsDNSPending(x) ((x)->flags & AM_DNS_PENDING)
|
|
|
|
|
|
|
|
#define SetAuthConnect(x) ((x)->flags |= AM_AUTH_CONNECTING)
|
|
|
|
#define ClearAuthConnect(x) ((x)->flags &= ~AM_AUTH_CONNECTING)
|
|
|
|
#define IsAuthConnect(x) ((x)->flags & AM_AUTH_CONNECTING)
|
|
|
|
|
|
|
|
#define SetAuthPending(x) ((x)->flags |= AM_AUTH_PENDING)
|
|
|
|
#define ClearAuthPending(x) ((x)->flags &= AM_AUTH_PENDING)
|
|
|
|
#define IsAuthPending(x) ((x)->flags & AM_AUTH_PENDING)
|
|
|
|
|
|
|
|
#define ClearAuth(x) ((x)->flags &= ~(AM_AUTH_PENDING | AM_AUTH_CONNECTING))
|
|
|
|
#define IsDoingAuth(x) ((x)->flags & (AM_AUTH_PENDING | AM_AUTH_CONNECTING))
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* a bit different approach
|
|
|
|
* this replaces the original sendheader macros
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char *HeaderMessages[] =
|
|
|
|
{
|
2007-01-25 07:23:01 +00:00
|
|
|
":*** Looking up your hostname...",
|
|
|
|
":*** Found your hostname",
|
|
|
|
":*** Couldn't look up your hostname",
|
|
|
|
":*** Checking Ident",
|
|
|
|
":*** Got Ident response",
|
|
|
|
":*** No Ident response",
|
|
|
|
":*** Your hostname is too long, ignoring hostname",
|
|
|
|
":*** Your forward and reverse DNS do not match, ignoring hostname",
|
|
|
|
":*** Cannot verify hostname validity, ignoring hostname",
|
2007-01-25 06:40:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
REPORT_DO_DNS,
|
|
|
|
REPORT_FIN_DNS,
|
|
|
|
REPORT_FAIL_DNS,
|
|
|
|
REPORT_DO_ID,
|
|
|
|
REPORT_FIN_ID,
|
|
|
|
REPORT_FAIL_ID,
|
|
|
|
REPORT_HOST_TOOLONG,
|
|
|
|
REPORT_HOST_MISMATCH,
|
|
|
|
REPORT_HOST_UNKNOWN
|
|
|
|
}
|
|
|
|
ReportType;
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
#define sendheader(c, r) sendto_one_notice(c, "%s", HeaderMessages[(r)])
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
static rb_dlink_list auth_poll_list;
|
2008-04-02 00:28:05 +00:00
|
|
|
static rb_bh *auth_heap;
|
2007-01-25 06:40:21 +00:00
|
|
|
static EVH timeout_auth_queries_event;
|
|
|
|
|
|
|
|
static PF read_auth_reply;
|
|
|
|
static CNCB auth_connect_callback;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_auth()
|
|
|
|
*
|
|
|
|
* Initialise the auth code
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
init_auth(void)
|
|
|
|
{
|
|
|
|
/* This hook takes a struct Client for its argument */
|
|
|
|
memset(&auth_poll_list, 0, sizeof(auth_poll_list));
|
2008-04-02 01:43:35 +00:00
|
|
|
rb_event_addish("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1);
|
2008-04-02 19:14:34 +00:00
|
|
|
auth_heap = rb_bh_create(sizeof(struct AuthRequest), LCLIENT_HEAP_SIZE, "auth_heap");
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make_auth_request - allocate a new auth request
|
|
|
|
*/
|
|
|
|
static struct AuthRequest *
|
|
|
|
make_auth_request(struct Client *client)
|
|
|
|
{
|
2008-04-02 00:28:05 +00:00
|
|
|
struct AuthRequest *request = rb_bh_alloc(auth_heap);
|
2007-01-25 06:40:21 +00:00
|
|
|
client->localClient->auth_request = request;
|
2008-04-02 19:14:34 +00:00
|
|
|
request->F = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
request->client = client;
|
2008-04-01 23:53:20 +00:00
|
|
|
request->timeout = rb_current_time() + ConfigFileEntry.connect_timeout;
|
2007-01-25 06:40:21 +00:00
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* free_auth_request - cleanup auth request allocations
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
free_auth_request(struct AuthRequest *request)
|
|
|
|
{
|
2008-04-02 00:28:05 +00:00
|
|
|
rb_bh_free(auth_heap, request);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* release_auth_client - release auth client from auth system
|
|
|
|
* this adds the client into the local client lists so it can be read by
|
|
|
|
* the main io processing loop
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
release_auth_client(struct AuthRequest *auth)
|
|
|
|
{
|
|
|
|
struct Client *client = auth->client;
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
if(IsDNSPending(auth) || IsDoingAuth(auth))
|
|
|
|
return;
|
|
|
|
|
|
|
|
client->localClient->auth_request = NULL;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkDelete(&auth->node, &auth_poll_list);
|
2014-03-03 04:25:47 +00:00
|
|
|
free_auth_request(auth);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When a client has auth'ed, we want to start reading what it sends
|
|
|
|
* us. This is what read_packet() does.
|
|
|
|
* -- adrian
|
|
|
|
*/
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkAddTail(client, &client->node, &global_client_list);
|
2008-04-02 19:14:34 +00:00
|
|
|
read_packet(client->localClient->F, client);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* auth_dns_callback - called when resolver query finishes
|
|
|
|
* if the query resulted in a successful search, hp will contain
|
|
|
|
* a non-null pointer, otherwise hp will be null.
|
|
|
|
* set the client on it's way to a connection completion, regardless
|
|
|
|
* of success of failure
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-08 12:31:08 +00:00
|
|
|
auth_dns_callback(const char *result, int status, int aftype, void *vptr)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
struct AuthRequest *auth = (struct AuthRequest *) vptr;
|
|
|
|
ClearDNSPending(auth);
|
|
|
|
|
|
|
|
/* XXX: this shouldn't happen, but it does. -nenolod */
|
|
|
|
if(auth->client->localClient == NULL)
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"auth_dns_callback(): auth->client->localClient (%s) is NULL", get_client_name(auth->client, HIDE_IP));
|
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkDelete(&auth->node, &auth_poll_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
free_auth_request(auth);
|
|
|
|
|
|
|
|
/* and they will silently drop through and all will hopefully be ok... -nenolod */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-08 12:31:08 +00:00
|
|
|
if(result != NULL && status)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
int good = 1;
|
|
|
|
|
2016-01-08 12:31:08 +00:00
|
|
|
if(good && strlen(result) <= HOSTLEN)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2016-01-08 12:31:08 +00:00
|
|
|
rb_strlcpy(auth->client->host, result, sizeof(auth->client->host));
|
2007-01-25 06:40:21 +00:00
|
|
|
sendheader(auth->client, REPORT_FIN_DNS);
|
|
|
|
}
|
2016-01-08 12:31:08 +00:00
|
|
|
else if (strlen(result) > HOSTLEN)
|
2007-01-25 06:40:21 +00:00
|
|
|
sendheader(auth->client, REPORT_HOST_TOOLONG);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sendheader(auth->client, REPORT_FAIL_DNS);
|
|
|
|
|
|
|
|
release_auth_client(auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* authsenderr - handle auth send errors
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
auth_error(struct AuthRequest *auth)
|
|
|
|
{
|
2008-04-04 15:54:37 +00:00
|
|
|
++ServerStats.is_abad;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
rb_close(auth->F);
|
|
|
|
auth->F = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
ClearAuth(auth);
|
|
|
|
sendheader(auth->client, REPORT_FAIL_ID);
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
release_auth_client(auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-03-03 04:25:47 +00:00
|
|
|
* start_auth_query - Flag the client to show that an attempt to
|
2007-01-25 06:40:21 +00:00
|
|
|
* contact the ident server on
|
|
|
|
* the client's host. The connect and subsequently the socket are all put
|
|
|
|
* into 'non-blocking' mode. Should the connect or any later phase of the
|
|
|
|
* identifing process fail, it is aborted and the user is given a username
|
|
|
|
* of "unknown".
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
start_auth_query(struct AuthRequest *auth)
|
|
|
|
{
|
2008-04-02 19:14:34 +00:00
|
|
|
struct rb_sockaddr_storage localaddr, destaddr;
|
|
|
|
rb_fde_t *F;
|
2007-01-25 06:40:21 +00:00
|
|
|
int family;
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
if(IsAnyDead(auth->client))
|
|
|
|
return 0;
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
family = auth->client->localClient->ip.ss_family;
|
2008-04-02 19:14:34 +00:00
|
|
|
if((F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2008-04-03 02:47:03 +00:00
|
|
|
ilog_error("creating auth stream socket");
|
2008-04-04 15:54:37 +00:00
|
|
|
++ServerStats.is_abad;
|
2007-01-25 06:40:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-04-03 09:21:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TBD: this is a pointless arbitrary limit .. we either have a socket or not. -nenolod
|
|
|
|
*/
|
2008-04-02 19:14:34 +00:00
|
|
|
if((maxconnections - 10) < rb_get_fd(F))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Can't allocate fd for auth on %s",
|
|
|
|
get_client_name(auth->client, SHOW_IP));
|
2008-04-02 19:14:34 +00:00
|
|
|
rb_close(F);
|
2007-01-25 06:40:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendheader(auth->client, REPORT_DO_ID);
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
/*
|
2007-01-25 06:40:21 +00:00
|
|
|
* get the local address of the client and bind to that to
|
|
|
|
* make the auth request. This used to be done only for
|
|
|
|
* ifdef VIRTUAL_HOST, but needs to be done for all clients
|
|
|
|
* since the ident request must originate from that same address--
|
|
|
|
* and machines with multiple IP addresses are common now
|
|
|
|
*/
|
2008-08-27 22:49:04 +00:00
|
|
|
localaddr = auth->client->preClient->lip;
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
/* XXX mangle_mapped_sockaddr((struct sockaddr *)&localaddr); */
|
2008-04-05 16:57:30 +00:00
|
|
|
#ifdef RB_IPV6
|
2007-01-25 06:40:21 +00:00
|
|
|
if(localaddr.ss_family == AF_INET6)
|
|
|
|
{
|
2008-06-20 23:52:57 +00:00
|
|
|
auth->lport = ntohs(((struct sockaddr_in6 *)&localaddr)->sin6_port);
|
2007-01-25 06:40:21 +00:00
|
|
|
((struct sockaddr_in6 *)&localaddr)->sin6_port = 0;
|
2008-06-20 23:52:57 +00:00
|
|
|
}
|
|
|
|
else
|
2007-01-25 06:40:21 +00:00
|
|
|
#endif
|
2008-06-20 23:52:57 +00:00
|
|
|
{
|
|
|
|
auth->lport = ntohs(((struct sockaddr_in *)&localaddr)->sin_port);
|
|
|
|
((struct sockaddr_in *)&localaddr)->sin_port = 0;
|
|
|
|
}
|
2008-04-02 19:14:34 +00:00
|
|
|
|
|
|
|
destaddr = auth->client->localClient->ip;
|
2008-04-05 16:57:30 +00:00
|
|
|
#ifdef RB_IPV6
|
2008-04-02 19:14:34 +00:00
|
|
|
if(localaddr.ss_family == AF_INET6)
|
|
|
|
{
|
2008-06-20 23:52:57 +00:00
|
|
|
auth->rport = ntohs(((struct sockaddr_in6 *)&destaddr)->sin6_port);
|
2008-04-03 18:46:20 +00:00
|
|
|
((struct sockaddr_in6 *)&destaddr)->sin6_port = htons(113);
|
2008-06-20 23:52:57 +00:00
|
|
|
}
|
|
|
|
else
|
2008-04-02 19:14:34 +00:00
|
|
|
#endif
|
2008-06-20 23:52:57 +00:00
|
|
|
{
|
|
|
|
auth->rport = ntohs(((struct sockaddr_in *)&destaddr)->sin_port);
|
|
|
|
((struct sockaddr_in *)&destaddr)->sin_port = htons(113);
|
|
|
|
}
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
auth->F = F;
|
2007-01-25 06:40:21 +00:00
|
|
|
SetAuthConnect(auth);
|
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
rb_connect_tcp(F, (struct sockaddr *)&destaddr,
|
|
|
|
(struct sockaddr *) &localaddr, GET_SS_LEN(&localaddr),
|
2014-03-03 04:25:47 +00:00
|
|
|
auth_connect_callback, auth,
|
2008-04-02 19:14:34 +00:00
|
|
|
GlobalSetOptions.ident_timeout);
|
2007-01-25 06:40:21 +00:00
|
|
|
return 1; /* We suceed here for now */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GetValidIdent - parse ident query reply from identd server
|
2014-03-03 04:25:47 +00:00
|
|
|
*
|
2007-01-25 06:40:21 +00:00
|
|
|
* Inputs - pointer to ident buf
|
|
|
|
* Output - NULL if no valid ident found, otherwise pointer to name
|
|
|
|
* Side effects -
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
GetValidIdent(char *buf)
|
|
|
|
{
|
|
|
|
int remp = 0;
|
|
|
|
int locp = 0;
|
|
|
|
char *colon1Ptr;
|
|
|
|
char *colon2Ptr;
|
|
|
|
char *colon3Ptr;
|
|
|
|
char *commaPtr;
|
|
|
|
char *remotePortString;
|
|
|
|
|
|
|
|
/* All this to get rid of a sscanf() fun. */
|
|
|
|
remotePortString = buf;
|
|
|
|
|
|
|
|
colon1Ptr = strchr(remotePortString, ':');
|
|
|
|
if(!colon1Ptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*colon1Ptr = '\0';
|
|
|
|
colon1Ptr++;
|
|
|
|
colon2Ptr = strchr(colon1Ptr, ':');
|
|
|
|
if(!colon2Ptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*colon2Ptr = '\0';
|
|
|
|
colon2Ptr++;
|
|
|
|
commaPtr = strchr(remotePortString, ',');
|
|
|
|
|
|
|
|
if(!commaPtr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*commaPtr = '\0';
|
|
|
|
commaPtr++;
|
|
|
|
|
|
|
|
remp = atoi(remotePortString);
|
|
|
|
if(!remp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
locp = atoi(commaPtr);
|
|
|
|
if(!locp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* look for USERID bordered by first pair of colons */
|
|
|
|
if(!strstr(colon1Ptr, "USERID"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
colon3Ptr = strchr(colon2Ptr, ':');
|
|
|
|
if(!colon3Ptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*colon3Ptr = '\0';
|
|
|
|
colon3Ptr++;
|
|
|
|
return (colon3Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start_auth - starts auth (identd) and dns queries for a client
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
start_auth(struct Client *client)
|
|
|
|
{
|
|
|
|
struct AuthRequest *auth = 0;
|
|
|
|
s_assert(0 != client);
|
|
|
|
if(client == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auth = make_auth_request(client);
|
|
|
|
|
|
|
|
sendheader(client, REPORT_DO_DNS);
|
|
|
|
|
|
|
|
/* No DNS cache now, remember? -- adrian */
|
2016-01-08 12:31:08 +00:00
|
|
|
auth->dns_id = lookup_ip(client->sockhost, GET_SS_FAMILY(&client->localClient->ip), auth_dns_callback, auth);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
SetDNSPending(auth);
|
|
|
|
|
|
|
|
if(ConfigFileEntry.disable_auth == 0)
|
|
|
|
start_auth_query(auth);
|
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkAdd(auth, &auth->node, &auth_poll_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* timeout_auth_queries - timeout resolver and identd requests
|
|
|
|
* allow clients through if requests failed
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
timeout_auth_queries_event(void *notused)
|
|
|
|
{
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct AuthRequest *auth;
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, auth_poll_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
auth = ptr->data;
|
|
|
|
|
2008-04-01 23:53:20 +00:00
|
|
|
if(auth->timeout < rb_current_time())
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2008-04-02 19:14:34 +00:00
|
|
|
if(auth->F != NULL)
|
|
|
|
rb_close(auth->F);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(IsDoingAuth(auth))
|
|
|
|
{
|
|
|
|
ClearAuth(auth);
|
2008-04-04 15:54:37 +00:00
|
|
|
++ServerStats.is_abad;
|
2007-01-25 06:40:21 +00:00
|
|
|
sendheader(auth->client, REPORT_FAIL_ID);
|
|
|
|
auth->client->localClient->auth_request = NULL;
|
|
|
|
}
|
|
|
|
if(IsDNSPending(auth))
|
|
|
|
{
|
|
|
|
ClearDNSPending(auth);
|
2016-01-08 12:31:08 +00:00
|
|
|
cancel_lookup(auth->dns_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
sendheader(auth->client, REPORT_FAIL_DNS);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:53:20 +00:00
|
|
|
auth->client->localClient->lasttime = rb_current_time();
|
2007-01-25 06:40:21 +00:00
|
|
|
release_auth_client(auth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-04-01 20:38:40 +00:00
|
|
|
* auth_connect_callback() - deal with the result of rb_connect_tcp()
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* If the connection failed, we simply close the auth fd and report
|
|
|
|
* a failure. If the connection suceeded send the ident server a query
|
|
|
|
* giving "theirport , ourport". The write is only attempted *once* so
|
|
|
|
* it is deemed to be a fail if the entire write doesn't write all the
|
|
|
|
* data given. This shouldnt be a problem since the socket should have
|
|
|
|
* a write buffer far greater than this message to store it in should
|
|
|
|
* problems arise. -avalon
|
|
|
|
*/
|
|
|
|
static void
|
2008-04-02 19:14:34 +00:00
|
|
|
auth_connect_callback(rb_fde_t *F, int error, void *data)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
struct AuthRequest *auth = data;
|
|
|
|
char authbuf[32];
|
2015-03-01 22:46:20 +00:00
|
|
|
int authlen;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* Check the error */
|
2008-04-02 19:14:34 +00:00
|
|
|
if(error != RB_OK)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
/* We had an error during connection :( */
|
|
|
|
auth_error(auth);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-10 01:25:32 +00:00
|
|
|
snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n",
|
2008-06-20 23:52:57 +00:00
|
|
|
auth->rport, auth->lport);
|
2015-03-01 22:46:20 +00:00
|
|
|
authlen = strlen(authbuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2015-03-01 22:46:20 +00:00
|
|
|
if(rb_write(auth->F, authbuf, authlen) != authlen)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
auth_error(auth);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ClearAuthConnect(auth);
|
|
|
|
SetAuthPending(auth);
|
2008-04-02 19:14:34 +00:00
|
|
|
read_auth_reply(auth->F, auth);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-03-03 04:25:47 +00:00
|
|
|
* read_auth_reply - read the reply (if any) from the ident server
|
2007-01-25 06:40:21 +00:00
|
|
|
* we connected to.
|
|
|
|
* We only give it one shot, if the reply isn't good the first time
|
|
|
|
* fail the authentication entirely. --Bleep
|
|
|
|
*/
|
|
|
|
#define AUTH_BUFSIZ 128
|
|
|
|
|
|
|
|
static void
|
2008-04-02 19:14:34 +00:00
|
|
|
read_auth_reply(rb_fde_t *F, void *data)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
struct AuthRequest *auth = data;
|
|
|
|
char *s = NULL;
|
|
|
|
char *t = NULL;
|
|
|
|
int len;
|
|
|
|
int count;
|
|
|
|
char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */
|
|
|
|
|
2008-06-21 00:29:21 +00:00
|
|
|
len = rb_read(F, buf, AUTH_BUFSIZ);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
if(len < 0 && rb_ignore_errno(errno))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2008-04-02 19:14:34 +00:00
|
|
|
rb_setselect(F, RB_SELECT_READ, read_auth_reply, auth);
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len > 0)
|
|
|
|
{
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
if((s = GetValidIdent(buf)))
|
|
|
|
{
|
|
|
|
t = auth->client->username;
|
|
|
|
|
|
|
|
while (*s == '~' || *s == '^')
|
|
|
|
s++;
|
|
|
|
|
|
|
|
for (count = USERLEN; *s && count; s++)
|
|
|
|
{
|
|
|
|
if(*s == '@')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!IsSpace(*s) && *s != ':' && *s != '[')
|
|
|
|
{
|
|
|
|
*t++ = *s;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*t = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
rb_close(auth->F);
|
|
|
|
auth->F = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
ClearAuth(auth);
|
|
|
|
|
|
|
|
if(s == NULL)
|
|
|
|
{
|
2008-04-04 15:54:37 +00:00
|
|
|
++ServerStats.is_abad;
|
2007-01-25 06:40:21 +00:00
|
|
|
strcpy(auth->client->username, "unknown");
|
|
|
|
sendheader(auth->client, REPORT_FAIL_ID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendheader(auth->client, REPORT_FIN_ID);
|
2008-04-04 15:54:37 +00:00
|
|
|
++ServerStats.is_asuc;
|
2007-01-25 06:40:21 +00:00
|
|
|
SetGotId(auth->client);
|
|
|
|
}
|
|
|
|
|
|
|
|
release_auth_client(auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* delete_auth_queries()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
delete_auth_queries(struct Client *target_p)
|
|
|
|
{
|
|
|
|
struct AuthRequest *auth;
|
|
|
|
|
|
|
|
if(target_p == NULL || target_p->localClient == NULL ||
|
|
|
|
target_p->localClient->auth_request == NULL)
|
|
|
|
return;
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
auth = target_p->localClient->auth_request;
|
|
|
|
target_p->localClient->auth_request = NULL;
|
|
|
|
|
|
|
|
if(IsDNSPending(auth))
|
2016-01-08 12:31:08 +00:00
|
|
|
cancel_lookup(auth->dns_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-02 19:14:34 +00:00
|
|
|
if(auth->F != NULL)
|
|
|
|
rb_close(auth->F);
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkDelete(&auth->node, &auth_poll_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
free_auth_request(auth);
|
|
|
|
}
|