* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
- * $Id: s_auth.c 1683 2006-06-20 14:26:16Z jilles $ */
+ * $Id: s_auth.c 3354 2007-04-03 09:21:31Z nenolod $ */
/*
* Changes:
*/
#include "stdinc.h"
#include "config.h"
-#include "tools.h"
#include "s_auth.h"
#include "s_conf.h"
#include "client.h"
#include "common.h"
-#include "event.h"
#include "irc_string.h"
#include "sprintf_irc.h"
#include "ircd.h"
#include "numeric.h"
#include "packet.h"
#include "res.h"
-#include "commio.h"
-#include "s_log.h"
+#include "logger.h"
#include "s_stats.h"
#include "send.h"
-#include "memory.h"
#include "hook.h"
#include "blacklist.h"
static const char *HeaderMessages[] =
{
- "NOTICE AUTH :*** Looking up your hostname...",
- "NOTICE AUTH :*** Found your hostname",
- "NOTICE AUTH :*** Couldn't look up your hostname",
- "NOTICE AUTH :*** Checking Ident",
- "NOTICE AUTH :*** Got Ident response",
- "NOTICE AUTH :*** No Ident response",
- "NOTICE AUTH :*** Your hostname is too long, ignoring hostname",
- "NOTICE AUTH :*** Your forward and reverse DNS do not match, ignoring hostname",
- "NOTICE AUTH :*** Cannot verify hostname validity, ignoring hostname",
+ ":*** 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",
};
typedef enum
}
ReportType;
-#define sendheader(c, r) sendto_one(c, HeaderMessages[(r)])
+#define sendheader(c, r) sendto_one_notice(c, HeaderMessages[(r)])
-static dlink_list auth_poll_list;
-static BlockHeap *auth_heap;
+static rb_dlink_list auth_poll_list;
+static rb_bh *auth_heap;
static EVH timeout_auth_queries_event;
static PF read_auth_reply;
{
/* This hook takes a struct Client for its argument */
memset(&auth_poll_list, 0, sizeof(auth_poll_list));
- eventAddIsh("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1);
- auth_heap = BlockHeapCreate(sizeof(struct AuthRequest), LCLIENT_HEAP_SIZE);
+ rb_event_addish("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1);
+ auth_heap = rb_bh_create(sizeof(struct AuthRequest), LCLIENT_HEAP_SIZE, "auth_heap");
}
/*
static struct AuthRequest *
make_auth_request(struct Client *client)
{
- struct AuthRequest *request = BlockHeapAlloc(auth_heap);
+ struct AuthRequest *request = rb_bh_alloc(auth_heap);
client->localClient->auth_request = request;
- request->fd = -1;
+ request->F = NULL;
request->client = client;
- request->timeout = CurrentTime + ConfigFileEntry.connect_timeout;
+ request->timeout = rb_current_time() + ConfigFileEntry.connect_timeout;
return request;
}
static void
free_auth_request(struct AuthRequest *request)
{
- BlockHeapFree(auth_heap, request);
+ rb_bh_free(auth_heap, request);
}
/*
return;
client->localClient->auth_request = NULL;
- dlinkDelete(&auth->node, &auth_poll_list);
+ rb_dlinkDelete(&auth->node, &auth_poll_list);
free_auth_request(auth);
- if(client->localClient->fd > highest_fd)
- highest_fd = client->localClient->fd;
/*
* When a client has auth'ed, we want to start reading what it sends
* -- adrian
*/
client->localClient->allow_read = MAX_FLOOD;
- comm_setflush(client->localClient->fd, 1000, flood_recalc, client);
- dlinkAddTail(client, &client->node, &global_client_list);
- read_packet(client->localClient->fd, client);
+ rb_dlinkAddTail(client, &client->node, &global_client_list);
+ read_packet(client->localClient->F, client);
}
/*
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"auth_dns_callback(): auth->client->localClient (%s) is NULL", get_client_name(auth->client, HIDE_IP));
- dlinkDelete(&auth->node, &auth_poll_list);
+ rb_dlinkDelete(&auth->node, &auth_poll_list);
free_auth_request(auth);
/* and they will silently drop through and all will hopefully be ok... -nenolod */
good = 0;
}
}
-#ifdef IPV6
+#ifdef RB_IPV6
else if(auth->client->localClient->ip.ss_family == AF_INET6)
{
struct sockaddr_in6 *ip, *ip_fwd;
static void
auth_error(struct AuthRequest *auth)
{
- ++ServerStats->is_abad;
+ ++ServerStats.is_abad;
- comm_close(auth->fd);
- auth->fd = -1;
+ rb_close(auth->F);
+ auth->F = NULL;
ClearAuth(auth);
sendheader(auth->client, REPORT_FAIL_ID);
static int
start_auth_query(struct AuthRequest *auth)
{
- struct irc_sockaddr_storage localaddr;
- socklen_t locallen = sizeof(struct irc_sockaddr_storage);
- int fd;
+ struct rb_sockaddr_storage localaddr, destaddr;
+ socklen_t locallen = sizeof(struct rb_sockaddr_storage);
+ rb_fde_t *F;
int family;
if(IsAnyDead(auth->client))
return 0;
family = auth->client->localClient->ip.ss_family;
- if((fd = comm_socket(family, SOCK_STREAM, 0, "ident")) == -1)
+ if((F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL)
{
- report_error("creating auth stream socket %s:%s",
- get_client_name(auth->client, SHOW_IP),
- log_client_name(auth->client, SHOW_IP), errno);
- ++ServerStats->is_abad;
+ ilog_error("creating auth stream socket");
+ ++ServerStats.is_abad;
return 0;
}
- if((MAXCONNECTIONS - 10) < fd)
+
+ /*
+ * TBD: this is a pointless arbitrary limit .. we either have a socket or not. -nenolod
+ */
+ if((maxconnections - 10) < rb_get_fd(F))
{
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Can't allocate fd for auth on %s",
get_client_name(auth->client, SHOW_IP));
- comm_close(fd);
+ rb_close(F);
return 0;
}
* and machines with multiple IP addresses are common now
*/
memset(&localaddr, 0, locallen);
- getsockname(auth->client->localClient->fd,
+ getsockname(rb_get_fd(auth->client->localClient->F),
(struct sockaddr *) &localaddr, &locallen);
- mangle_mapped_sockaddr((struct sockaddr *)&localaddr);
-#ifdef IPV6
+ /* XXX mangle_mapped_sockaddr((struct sockaddr *)&localaddr); */
+#ifdef RB_IPV6
if(localaddr.ss_family == AF_INET6)
{
((struct sockaddr_in6 *)&localaddr)->sin6_port = 0;
} else
#endif
((struct sockaddr_in *)&localaddr)->sin_port = 0;
+
+ destaddr = auth->client->localClient->ip;
+#ifdef RB_IPV6
+ if(localaddr.ss_family == AF_INET6)
+ {
+ ((struct sockaddr_in6 *)&destaddr)->sin6_port = htons(113);
+ } else
+#endif
+ ((struct sockaddr_in *)&destaddr)->sin_port = htons(113);
- auth->fd = fd;
+ auth->F = F;
SetAuthConnect(auth);
- comm_connect_tcp(fd, auth->client->sockhost, 113,
- (struct sockaddr *) &localaddr, GET_SS_LEN(localaddr),
+ rb_connect_tcp(F, (struct sockaddr *)&destaddr,
+ (struct sockaddr *) &localaddr, GET_SS_LEN(&localaddr),
auth_connect_callback, auth,
- localaddr.ss_family, GlobalSetOptions.ident_timeout);
+ GlobalSetOptions.ident_timeout);
return 1; /* We suceed here for now */
}
if(client == NULL)
return;
- /* to aid bopm which needs something unique to match against */
- sendto_one(client, "NOTICE AUTH :*** Processing connection to %s",
- me.name);
-
auth = make_auth_request(client);
auth->dns_query.ptr = auth;
if(ConfigFileEntry.disable_auth == 0)
start_auth_query(auth);
- dlinkAdd(auth, &auth->node, &auth_poll_list);
+ rb_dlinkAdd(auth, &auth->node, &auth_poll_list);
}
/*
static void
timeout_auth_queries_event(void *notused)
{
- dlink_node *ptr;
- dlink_node *next_ptr;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
struct AuthRequest *auth;
- DLINK_FOREACH_SAFE(ptr, next_ptr, auth_poll_list.head)
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, auth_poll_list.head)
{
auth = ptr->data;
- if(auth->timeout < CurrentTime)
+ if(auth->timeout < rb_current_time())
{
- if(auth->fd >= 0)
- comm_close(auth->fd);
+ if(auth->F != NULL)
+ rb_close(auth->F);
if(IsDoingAuth(auth))
{
ClearAuth(auth);
- ++ServerStats->is_abad;
+ ++ServerStats.is_abad;
sendheader(auth->client, REPORT_FAIL_ID);
auth->client->localClient->auth_request = NULL;
}
sendheader(auth->client, REPORT_FAIL_DNS);
}
- auth->client->localClient->lasttime = CurrentTime;
+ auth->client->localClient->lasttime = rb_current_time();
release_auth_client(auth);
}
}
}
/*
- * auth_connect_callback() - deal with the result of comm_connect_tcp()
+ * auth_connect_callback() - deal with the result of rb_connect_tcp()
*
* If the connection failed, we simply close the auth fd and report
* a failure. If the connection suceeded send the ident server a query
* problems arise. -avalon
*/
static void
-auth_connect_callback(int fd, int error, void *data)
+auth_connect_callback(rb_fde_t *F, int error, void *data)
{
struct AuthRequest *auth = data;
struct sockaddr_in us;
socklen_t tlen = sizeof(struct sockaddr_in);
/* Check the error */
- if(error != COMM_OK)
+ if(error != RB_OK)
{
/* We had an error during connection :( */
auth_error(auth);
}
if(getsockname
- (auth->client->localClient->fd, (struct sockaddr *) &us,
+ (rb_get_fd(auth->client->localClient->F), (struct sockaddr *) &us,
(socklen_t *) & ulen)
- || getpeername(auth->client->localClient->fd,
+ || getpeername(rb_get_fd(auth->client->localClient->F),
(struct sockaddr *) &them, (socklen_t *) & tlen))
{
ilog(L_IOERROR, "auth get{sock,peer}name error for %s:%m",
auth_error(auth);
return;
}
- ircsnprintf(authbuf, sizeof(authbuf), "%u , %u\r\n",
+ rb_snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n",
(unsigned int) ntohs(them.sin_port), (unsigned int) ntohs(us.sin_port));
- if(write(auth->fd, authbuf, strlen(authbuf)) == -1)
+ if(write(rb_get_fd(auth->F), authbuf, strlen(authbuf)) == -1)
{
auth_error(auth);
return;
}
ClearAuthConnect(auth);
SetAuthPending(auth);
- read_auth_reply(auth->fd, auth);
+ read_auth_reply(auth->F, auth);
}
#define AUTH_BUFSIZ 128
static void
-read_auth_reply(int fd, void *data)
+read_auth_reply(rb_fde_t *F, void *data)
{
struct AuthRequest *auth = data;
char *s = NULL;
int count;
char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */
- len = read(auth->fd, buf, AUTH_BUFSIZ);
+ len = read(rb_get_fd(F), buf, AUTH_BUFSIZ);
- if(len < 0 && ignoreErrno(errno))
+ if(len < 0 && rb_ignore_errno(errno))
{
- comm_setselect(fd, FDLIST_IDLECLIENT, COMM_SELECT_READ, read_auth_reply, auth, 0);
+ rb_setselect(F, RB_SELECT_READ, read_auth_reply, auth);
return;
}
}
}
- comm_close(auth->fd);
- auth->fd = -1;
+ rb_close(auth->F);
+ auth->F = NULL;
ClearAuth(auth);
if(s == NULL)
{
- ++ServerStats->is_abad;
+ ++ServerStats.is_abad;
strcpy(auth->client->username, "unknown");
sendheader(auth->client, REPORT_FAIL_ID);
}
else
{
sendheader(auth->client, REPORT_FIN_ID);
- ++ServerStats->is_asuc;
+ ++ServerStats.is_asuc;
SetGotId(auth->client);
}
if(IsDNSPending(auth))
delete_resolver_queries(&auth->dns_query);
- if(auth->fd >= 0)
- comm_close(auth->fd);
+ if(auth->F != NULL)
+ rb_close(auth->F);
- dlinkDelete(&auth->node, &auth_poll_list);
+ rb_dlinkDelete(&auth->node, &auth_poll_list);
free_auth_request(auth);
}