Committer : entrope
CVSROOT : /cvsroot/undernet-ircu
Module : ircu2.10
Commit time: 2005-06-27 13:26:04 UTC
Modified files:
ChangeLog include/client.h include/res.h include/s_bsd.h
ircd/hash.c ircd/ircd_auth.c ircd/ircd_res.c ircd/list.c
ircd/s_auth.c ircd/s_bsd.c ircd/s_conf.c ircd/s_serv.c
ircd/s_user.c
Log message:
Rewrite DNS lookup API to remove a memory leak and keep it from coming back.
---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.654 ircu2.10/ChangeLog:1.655
--- ircu2.10/ChangeLog:1.654 Mon Jun 27 06:11:52 2005
+++ ircu2.10/ChangeLog Mon Jun 27 06:25:49 2005
@@ -1,5 +1,56 @@
2005-06-27 Michael Poole <[EMAIL PROTECTED]>
+ * include/client.h (struct Connection): Remove con_dns_reply (and
+ associated macros).
+
+ * include/res.h (gethost_byname): Change calling signature to
+ clarify memory ownership.
+ (gethost_byaddr): Likewise.
+
+ * include/s_bsd.h (release_dns_reply): Remove function.
+
+ * ircd/hash.c: #include "match.h" to quash warning.
+
+ * ircd/ircd_auth.c (struct IAuth): Remove i_query field.
+ (iauth_dns_callback): Adjust for new gethost_byname signature.
+ (iauth_reconnect): Likewise.
+
+ * ircd/ircd_res.c (struct reslist): Make elements of query field
+ inline rather than in a contained structure.
+ (make_request): Reflect removal of DNSQuery.
+ (do_query_name): Likewise.
+ (do_query_number): Likewise.
+ (make_dnsreply): Remove now-unused function.
+ (timeout_resolver): Adjust to new callback signature.
+ (delete_resolver_queries): Reflect removal of DNSQuery.
+ (gethost_byname): Update to new signature.
+ (gethost_byaddr): Likewise.
+ (res_readreply): Reflect removal of DNSReply.
+
+ * ircd/list.c (dealloc_connection): con_dns_reply no longer
+ exists, so do not free it.
+
+ * ircd/s_auth.c (auth_verify_hostname): constify.
+ (auth_dns_callback): Adjust to new callback signature.
+ (start_auth): Adjust to new gethost_byaddr() signature.
+
+ * ircd/s_bsd.c (connect_dns_callback): Adjust to new callback
+ signature.
+ (release_dns_reply): Remove unused function.
+ (connect_server): Adjust to new gethost_byname() signature.
+
+ * ircd/s_conf.c (conf_dns_callback): Adjust to new callback
+ signature.
+ (conf_dns_lookup): Adjust to new gethost_byname() signature.
+ (attach_iline): Use cli_sockhost() instead of DNS reply.
+ (conf_check_server): Simplify use of DNS results.
+
+ * ircd/s_serv.c (server_estab): Remove call to removed function.
+
+ * ircd/s_user.c (register_user): Remove call to removed function.
+
+2005-06-27 Michael Poole <[EMAIL PROTECTED]>
+
* include/s_misc.h (get_sockhost): Remove the unused (and
deceptively named) get_sockhost().
Index: ircu2.10/include/client.h
diff -u ircu2.10/include/client.h:1.47 ircu2.10/include/client.h:1.48
--- ircu2.10/include/client.h:1.47 Mon Apr 4 18:46:05 2005
+++ ircu2.10/include/client.h Mon Jun 27 06:25:51 2005
@@ -19,7 +19,7 @@
*/
/** @file
* @brief Structures and functions for handling local clients.
- * @version $Id: client.h,v 1.47 2005/04/05 01:46:05 entrope Exp $
+ * @version $Id: client.h,v 1.48 2005/06/27 13:25:51 entrope Exp $
*/
#ifndef INCLUDED_client_h
#define INCLUDED_client_h
@@ -210,8 +210,6 @@
struct SLink* con_confs; /**< Associated configuration records. */
HandlerType con_handler; /**< Message index into command table
for parsing. */
- struct DNSReply* con_dns_reply; /**< DNS reply received during client
- registration. */
struct ListingArgs* con_listing; /**< Current LIST status. */
unsigned long con_unreg; /**< Indicate what still needs to be done
*/
unsigned int con_max_sendq; /**< cached max send queue for client */
@@ -367,8 +365,6 @@
#define cli_confs(cli) con_confs(cli_connect(cli))
/** Get handler type for client. */
#define cli_handler(cli) con_handler(cli_connect(cli))
-/** Get DNS reply for client. */
-#define cli_dns_reply(cli) con_dns_reply(cli_connect(cli))
/** Get LIST status for client. */
#define cli_listing(cli) con_listing(cli_connect(cli))
/** Get cached max SendQ for client. */
@@ -448,8 +444,6 @@
#define con_confs(con) ((con)->con_confs)
/** Get command handler for the connection. */
#define con_handler(con) ((con)->con_handler)
-/** Get DNS reply for the connection. */
-#define con_dns_reply(con) ((con)->con_dns_reply)
/** Get the LIST status for the connection. */
#define con_listing(con) ((con)->con_listing)
/** Get remining steps before registration completes. */
Index: ircu2.10/include/res.h
diff -u ircu2.10/include/res.h:1.16 ircu2.10/include/res.h:1.17
--- ircu2.10/include/res.h:1.16 Tue Dec 28 13:12:03 2004
+++ ircu2.10/include/res.h Mon Jun 27 06:25:51 2005
@@ -1,6 +1,6 @@
/** @file
* @brief IRC resolver API.
- * @version $Id: res.h,v 1.16 2004/12/28 21:12:03 entrope Exp $
+ * @version $Id: res.h,v 1.17 2005/06/27 13:25:51 entrope Exp $
*/
#ifndef INCLUDED_res_h
@@ -66,19 +66,8 @@
unsigned short port; /**< Port number, host-endian. */
};
-/** DNS reply structure. */
-struct DNSReply
-{
- char *h_name; /**< Hostname. */
- struct irc_in_addr addr; /**< IP address. */
-};
-
-/** DNS callback structure. */
-struct DNSQuery
-{
- void *vptr; /**< pointer used by callback to identify request */
- void (*callback)(void* vptr, struct DNSReply *reply); /**< callback to call
*/
-};
+/** DNS callback function signature. */
+typedef void (*dns_callback_f)(void *vptr, const struct irc_in_addr *addr,
const char *h_name);
/** DNS query and response header. */
typedef struct
@@ -123,8 +112,8 @@
extern size_t cres_mem(struct Client* cptr);
extern void delete_resolver_queries(const void *vptr);
extern void report_dns_servers(struct Client *source_p, const struct StatDesc
*sd, char *param);
-extern void gethost_byname(const char *name, const struct DNSQuery *query);
-extern void gethost_byaddr(const struct irc_in_addr *addr, const struct
DNSQuery *query);
+extern void gethost_byname(const char *name, dns_callback_f callback, void
*ctx);
+extern void gethost_byaddr(const struct irc_in_addr *addr, dns_callback_f
callback, void *ctx);
/** Evaluate to non-zero if \a ADDR is a valid address (not all 0s and not all
1s). */
#define irc_in_addr_valid(ADDR) (((ADDR)->in6_16[0] && ~(ADDR)->in6_16[0]) \
Index: ircu2.10/include/s_bsd.h
diff -u ircu2.10/include/s_bsd.h:1.20 ircu2.10/include/s_bsd.h:1.21
--- ircu2.10/include/s_bsd.h:1.20 Tue Dec 28 19:08:09 2004
+++ ircu2.10/include/s_bsd.h Mon Jun 27 06:25:51 2005
@@ -1,6 +1,6 @@
/** @file s_bsd.h
* @brief Wrapper functions to avoid direct use of BSD APIs.
- * @version $Id: s_bsd.h,v 1.20 2004/12/29 03:08:09 entrope Exp $
+ * @version $Id: s_bsd.h,v 1.21 2005/06/27 13:25:51 entrope Exp $
*/
#ifndef INCLUDED_s_bsd_h
#define INCLUDED_s_bsd_h
@@ -59,7 +59,6 @@
*/
extern unsigned int deliver_it(struct Client *cptr, struct MsgQ *buf);
extern int connect_server(struct ConfItem* aconf, struct Client* by);
-extern void release_dns_reply(struct Client* cptr);
extern int net_close_unregistered_connections(struct Client* source);
extern void close_connection(struct Client *cptr);
extern void add_connection(struct Listener* listener, int fd);
Index: ircu2.10/ircd/hash.c
diff -u ircu2.10/ircd/hash.c:1.17 ircu2.10/ircd/hash.c:1.18
--- ircu2.10/ircd/hash.c:1.17 Mon Jun 20 06:22:45 2005
+++ ircu2.10/ircd/hash.c Mon Jun 27 06:25:51 2005
@@ -30,6 +30,7 @@
#include "ircd_reply.h"
#include "ircd_string.h"
#include "ircd.h"
+#include "match.h"
#include "msg.h"
#include "numeric.h"
#include "random.h"
@@ -45,7 +46,7 @@
/** @file
* @brief Hash table management.
- * @version $Id: hash.c,v 1.17 2005/06/20 13:22:45 a1kmm Exp $
+ * @version $Id: hash.c,v 1.18 2005/06/27 13:25:51 entrope Exp $
*
* This file used to use some very complicated hash function. Now it
* uses CRC-32, but effectively remaps each input byte according to a
Index: ircu2.10/ircd/ircd_auth.c
diff -u ircu2.10/ircd/ircd_auth.c:1.16 ircu2.10/ircd/ircd_auth.c:1.17
--- ircu2.10/ircd/ircd_auth.c:1.16 Mon May 2 20:47:42 2005
+++ ircu2.10/ircd/ircd_auth.c Mon Jun 27 06:25:51 2005
@@ -19,7 +19,7 @@
*/
/** @file
* @brief IAuth client implementation for an IRC server.
- * @version $Id: ircd_auth.c,v 1.16 2005/05/03 03:47:42 entrope Exp $
+ * @version $Id: ircd_auth.c,v 1.17 2005/06/27 13:25:51 entrope Exp $
*/
#include "config.h"
@@ -82,7 +82,6 @@
struct Timer i_reconn_timer; /**< when to reconnect the connection
*/
struct Timer i_request_timer; /**< when the current request times
out */
struct IAuthFlags i_flags; /**< connection state/status/flags */
- struct DNSQuery i_query; /**< DNS lookup for iauth server */
unsigned int i_recvM; /**< messages received */
unsigned int i_sendM; /**< messages sent */
unsigned int i_recvK; /**< kilobytes received */
@@ -406,13 +405,13 @@
* @param[in] vptr Pointer to the IAuth struct.
* @param[in] he DNS reply parameters.
*/
-static void iauth_dns_callback(void *vptr, struct DNSReply *he)
+static void iauth_dns_callback(void *vptr, const struct irc_in_addr *addr,
const char *h_name)
{
struct IAuth *iauth = vptr;
- if (!he) {
+ if (!addr) {
log_write(LS_IAUTH, L_NOTICE, 0, "IAuth connection to %s failed: host
lookup failed", i_host(iauth));
} else {
- memcpy(&i_addr(iauth).addr, &he->addr, sizeof(i_addr(iauth).addr));
+ memcpy(&i_addr(iauth).addr, addr, sizeof(i_addr(iauth).addr));
if (!irc_in_addr_valid(&i_addr(iauth).addr)) {
log_write(LS_IAUTH, L_NOTICE, 0, "IAuth connection to %s failed: host
came back as unresolved", i_host(iauth));
return;
@@ -461,9 +460,7 @@
log_write(LS_IAUTH, L_DEBUG, 0, "IAuth attempt connection to %s port %p.",
i_host(iauth), i_port(iauth));
if (!irc_in_addr_valid(&i_addr(iauth).addr)
&& !ircd_aton(&i_addr(iauth).addr, i_host(iauth))) {
- i_query(iauth).vptr = iauth;
- i_query(iauth).callback = iauth_dns_callback;
- gethost_byname(i_host(iauth), &i_query(iauth));
+ gethost_byname(i_host(iauth), iauth_dns_callback, iauth);
return;
}
local = irc_in_addr_is_ipv4(&i_addr(iauth).addr) ? &VirtualHost_v4 :
&VirtualHost_v6;
Index: ircu2.10/ircd/ircd_res.c
diff -u ircu2.10/ircd/ircd_res.c:1.22 ircu2.10/ircd/ircd_res.c:1.23
--- ircu2.10/ircd/ircd_res.c:1.22 Sun Jun 19 04:33:32 2005
+++ ircu2.10/ircd/ircd_res.c Mon Jun 27 06:25:51 2005
@@ -18,7 +18,7 @@
*/
/** @file
* @brief IRC resolver functions.
- * @version $Id: ircd_res.c,v 1.22 2005/06/19 11:33:32 a1kmm Exp $
+ * @version $Id: ircd_res.c,v 1.23 2005/06/27 13:25:51 entrope Exp $
*/
#include "client.h"
@@ -115,17 +115,18 @@
time_t timeout; /**< When this request times out. */
struct irc_in_addr addr; /**< Address for this request. */
char *name; /**< Hostname for this request. */
- struct DNSQuery query; /**< Query callback for this request. */
+ dns_callback_f callback; /**< Callback function on completion. */
+ void *callback_ctx; /**< Context pointer for callback. */
};
/** Base of request list. */
static struct dlink request_list;
static void rem_request(struct reslist *request);
-static struct reslist *make_request(const struct DNSQuery *query);
-static void do_query_name(const struct DNSQuery *query,
+static struct reslist *make_request(dns_callback_f callback, void *ctx);
+static void do_query_name(dns_callback_f callback, void *ctx,
const char* name, struct reslist *request, int);
-static void do_query_number(const struct DNSQuery *query,
+static void do_query_number(dns_callback_f callback, void *ctx,
const struct irc_in_addr *,
struct reslist *request);
static void query_name(const char *name, int query_class, int query_type,
@@ -134,7 +135,6 @@
static void resend_query(struct reslist *request);
static int proc_answer(struct reslist *request, HEADER *header, char *, char
*);
static struct reslist *find_id(int id);
-static struct DNSReply *make_dnsreply(struct reslist *request);
static void res_readreply(struct Event *ev);
static void timeout_resolver(struct Event *notused);
@@ -248,7 +248,7 @@
* @return Newly allocated and linked-in reslist.
*/
static struct reslist *
-make_request(const struct DNSQuery* query)
+make_request(dns_callback_f callback, void *ctx)
{
struct reslist *request;
@@ -264,7 +264,8 @@
request->resend = 1;
request->timeout = feature_int(FEAT_IRCD_RES_TIMEOUT);
memset(&request->addr, 0, sizeof(request->addr));
- memcpy(&request->query, query, sizeof(request->query));
+ request->callback = callback;
+ request->callback_ctx = ctx;
add_dlink(&request->node, &request_list);
return(request);
@@ -313,7 +314,7 @@
if (--request->retries <= 0)
{
Debug((DEBUG_DNS, "Request %p out of retries; destroying", request));
- (*request->query.callback)(request->query.vptr, 0);
+ (*request->callback)(request->callback_ctx, NULL, NULL);
rem_request(request);
continue;
}
@@ -352,7 +353,7 @@
{
next_ptr = ptr->next;
request = (struct reslist*)ptr;
- if (vptr == request->query.vptr) {
+ if (vptr == request->callback_ctx) {
Debug((DEBUG_DNS, "Removing request %p with vptr %p", request, vptr));
rem_request(request);
}
@@ -417,9 +418,9 @@
* @param[in] query Callback information.
*/
void
-gethost_byname(const char *name, const struct DNSQuery *query)
+gethost_byname(const char *name, dns_callback_f callback, void *ctx)
{
- do_query_name(query, name, NULL, T_AAAA);
+ do_query_name(callback, ctx, name, NULL, T_AAAA);
}
/** Try to look up hostname for an address.
@@ -427,9 +428,9 @@
* @param[in] query Callback information.
*/
void
-gethost_byaddr(const struct irc_in_addr *addr, const struct DNSQuery *query)
+gethost_byaddr(const struct irc_in_addr *addr, dns_callback_f callback, void
*ctx)
{
- do_query_number(query, addr, NULL);
+ do_query_number(callback, ctx, addr, NULL);
}
/** Send a query to look up the address for a name.
@@ -439,7 +440,7 @@
* @param[in] type Preferred request type.
*/
static void
-do_query_name(const struct DNSQuery *query, const char *name,
+do_query_name(dns_callback_f callback, void *ctx, const char *name,
struct reslist *request, int type)
{
char host_name[HOSTLEN + 1];
@@ -449,7 +450,7 @@
if (request == NULL)
{
- request = make_request(query);
+ request = make_request(callback, ctx);
DupString(request->name, host_name);
#ifdef IPV6
if (type != T_A)
@@ -470,7 +471,7 @@
* @param[in] request DNS lookup structure (may be NULL).
*/
static void
-do_query_number(const struct DNSQuery *query, const struct irc_in_addr *addr,
+do_query_number(dns_callback_f callback, void *ctx, const struct irc_in_addr
*addr,
struct reslist *request)
{
char ipbuf[128];
@@ -515,7 +516,7 @@
}
if (request == NULL)
{
- request = make_request(query);
+ request = make_request(callback, ctx);
request->state= REQ_PTR;
request->type = T_PTR;
memcpy(&request->addr, addr, sizeof(request->addr));
@@ -575,15 +576,15 @@
switch(request->type)
{
case T_PTR:
- do_query_number(NULL, &request->addr, request);
+ do_query_number(NULL, NULL, &request->addr, request);
break;
case T_A:
- do_query_name(NULL, request->name, request, request->type);
+ do_query_name(NULL, NULL, request->name, request, request->type);
break;
case T_AAAA:
/* didn't work, try A */
if (request->state == REQ_AAAA)
- do_query_name(NULL, request->name, request, T_A);
+ do_query_name(NULL, NULL, request->name, request, T_A);
default:
break;
}
@@ -752,7 +753,6 @@
char buf[sizeof(HEADER) + MAXPACKET];
HEADER *header;
struct reslist *request = NULL;
- struct DNSReply *reply = NULL;
unsigned int rc;
int answer_count;
@@ -815,7 +815,7 @@
* send any more (no retries granted).
*/
Debug((DEBUG_DNS, "Request %p has bad response (state %d type %d rcode
%d)", request, request->state, request->type, header->rcode));
- (*request->query.callback)(request->query.vptr, 0);
+ (*request->callback)(request->callback_ctx, NULL, NULL);
rem_request(request);
}
}
@@ -839,7 +839,7 @@
* don't bother trying again, the client address doesn't resolve
*/
Debug((DEBUG_DNS, "Request %p PTR had empty name", request));
- (*request->query.callback)(request->query.vptr, reply);
+ (*request->callback)(request->callback_ctx, NULL, NULL);
rem_request(request);
return;
}
@@ -850,10 +850,10 @@
*/
#ifdef IPV6
if (!irc_in_addr_is_ipv4(&request->addr))
- do_query_name(&request->query, request->name, NULL, T_AAAA);
+ do_query_name(request->callback, request->callback_ctx, request->name,
NULL, T_AAAA);
else
#endif
- do_query_name(&request->query, request->name, NULL, T_A);
+ do_query_name(request->callback, request->callback_ctx, request->name,
NULL, T_A);
Debug((DEBUG_DNS, "Request %p switching to forward resolution",
request));
rem_request(request);
}
@@ -862,8 +862,7 @@
/*
* got a name and address response, client resolved
*/
- reply = make_dnsreply(request);
- (*request->query.callback)(request->query.vptr, (reply) ? reply : 0);
+ (*request->callback)(request->callback_ctx, &request->addr,
request->name);
Debug((DEBUG_DNS, "Request %p got forward resolution", request));
rem_request(request);
}
@@ -881,23 +880,6 @@
}
}
-/** Build a DNSReply for a completed request.
- * @param[in] request Completed DNS request.
- * @return Newly allocated DNSReply containing host name and address.
- */
-static struct DNSReply *
-make_dnsreply(struct reslist *request)
-{
- struct DNSReply *cp;
- assert(request != 0);
-
- cp = (struct DNSReply *)MyMalloc(sizeof(struct DNSReply));
-
- DupString(cp->h_name, request->name);
- memcpy(&cp->addr, &request->addr, sizeof(cp->addr));
- return(cp);
-}
-
/** Statistics callback to list DNS servers.
* @param[in] source_p Client requesting statistics.
* @param[in] sd Stats descriptor for request (ignored).
Index: ircu2.10/ircd/list.c
diff -u ircu2.10/ircd/list.c:1.33 ircu2.10/ircd/list.c:1.34
--- ircu2.10/ircd/list.c:1.33 Thu Jun 16 20:55:12 2005
+++ ircu2.10/ircd/list.c Mon Jun 27 06:25:51 2005
@@ -19,7 +19,7 @@
*/
/** @file
* @brief Singly and doubly linked list manipulation implementation.
- * @version $Id: list.c,v 1.33 2005/06/17 03:55:12 entrope Exp $
+ * @version $Id: list.c,v 1.34 2005/06/27 13:25:51 entrope Exp $
*/
#include "config.h"
@@ -165,10 +165,6 @@
Debug((DEBUG_LIST, "Deallocating connection %p", con));
- if (con_dns_reply(con)) {
- MyFree(con_dns_reply(con));
- con_dns_reply(con) = 0;
- }
if (-1 < con_fd(con))
close(con_fd(con));
MsgQClear(&(con_sendQ(con)));
Index: ircu2.10/ircd/s_auth.c
diff -u ircu2.10/ircd/s_auth.c:1.36 ircu2.10/ircd/s_auth.c:1.37
--- ircu2.10/ircd/s_auth.c:1.36 Sun Mar 20 08:06:29 2005
+++ ircu2.10/ircd/s_auth.c Mon Jun 27 06:25:51 2005
@@ -27,7 +27,7 @@
*/
/** @file
* @brief Implementation of DNS and ident lookups.
- * @version $Id: s_auth.c,v 1.36 2005/03/20 16:06:29 entrope Exp $
+ * @version $Id: s_auth.c,v 1.37 2005/06/27 13:25:51 entrope Exp $
*/
#include "config.h"
@@ -111,7 +111,7 @@
* @return Non-zero if the hostname is valid.
*/
static int
-auth_verify_hostname(char *host, int maxlen)
+auth_verify_hostname(const char *host, int maxlen)
{
int i;
@@ -304,7 +304,7 @@
* @param vptr The pending struct AuthRequest.
* @param hp Pointer to the DNS reply (or NULL, if lookup failed).
*/
-static void auth_dns_callback(void* vptr, struct DNSReply* hp)
+static void auth_dns_callback(void* vptr, const struct irc_in_addr *addr,
const char *h_name)
{
struct AuthRequest* auth = (struct AuthRequest*) vptr;
assert(auth);
@@ -315,31 +315,30 @@
*/
ClearDNSPending(auth);
- if (hp) {
+ if (addr) {
/*
* Verify that the host to ip mapping is correct both ways and that
* the ip#(s) for the socket is listed for the host.
*/
- if (irc_in_addr_cmp(&hp->addr, &cli_ip(auth->client))) {
+ if (irc_in_addr_cmp(addr, &cli_ip(auth->client))) {
if (IsUserPort(auth->client))
sendheader(auth->client, REPORT_IP_MISMATCH);
sendto_opmask_butone(0, SNO_IPMISMATCH, "IP# Mismatch: %s != %s[%s]",
- cli_sock_ip(auth->client), hp->h_name,
- ircd_ntoa(&hp->addr));
+ cli_sock_ip(auth->client), h_name,
+ ircd_ntoa(addr));
if (feature_bool(FEAT_KILL_IPMISMATCH)) {
auth_kill_client(auth);
return;
}
}
- else if (!auth_verify_hostname(hp->h_name, HOSTLEN))
+ else if (!auth_verify_hostname(h_name, HOSTLEN))
{
if (IsUserPort(auth->client))
sendheader(auth->client, REPORT_INVAL_DNS);
}
else
{
- cli_dns_reply(auth->client) = hp;
- ircd_strncpy(cli_sockhost(auth->client), hp->h_name, HOSTLEN);
+ ircd_strncpy(cli_sockhost(auth->client), h_name, HOSTLEN);
if (IsUserPort(auth->client))
sendheader(auth->client, REPORT_FIN_DNS);
}
@@ -554,15 +553,9 @@
if (irc_in_addr_is_loopback(&cli_ip(client)))
strcpy(cli_sockhost(client), cli_name(&me));
else {
- struct DNSQuery query;
-
- query.vptr = auth;
- query.callback = auth_dns_callback;
-
if (IsUserPort(auth->client))
sendheader(client, REPORT_DO_DNS);
-
- gethost_byaddr(&cli_ip(client), &query);
+ gethost_byaddr(&cli_ip(client), auth_dns_callback, auth);
SetDNSPending(auth);
}
}
Index: ircu2.10/ircd/s_bsd.c
diff -u ircu2.10/ircd/s_bsd.c:1.77 ircu2.10/ircd/s_bsd.c:1.78
--- ircu2.10/ircd/s_bsd.c:1.77 Mon May 30 09:51:04 2005
+++ ircu2.10/ircd/s_bsd.c Mon Jun 27 06:25:52 2005
@@ -19,7 +19,7 @@
*/
/** @file
* @brief Functions that now (or in the past) relied on BSD APIs.
- * @version $Id: s_bsd.c,v 1.77 2005/05/30 16:51:04 entrope Exp $
+ * @version $Id: s_bsd.c,v 1.78 2005/06/27 13:25:52 entrope Exp $
*/
#include "config.h"
@@ -172,14 +172,13 @@
* @param vptr The struct ConfItem representing the Connect block.
* @param hp A pointer to the DNS lookup results (NULL on failure).
*/
-static void connect_dns_callback(void* vptr, struct DNSReply* hp)
+static void connect_dns_callback(void* vptr, const struct irc_in_addr *addr,
const char *h_name)
{
struct ConfItem* aconf = (struct ConfItem*) vptr;
assert(aconf);
aconf->dns_pending = 0;
- if (hp) {
- memcpy(&aconf->address, &hp->addr, sizeof(aconf->address));
- MyFree(hp);
+ if (addr) {
+ memcpy(&aconf->address, addr, sizeof(aconf->address));
connect_server(aconf, 0);
}
else
@@ -323,21 +322,6 @@
return bytes_written;
}
-/** Free the client's DNS reply, if any.
- * @param cptr Client to operate on.
- */
-void release_dns_reply(struct Client* cptr)
-{
- assert(0 != cptr);
- assert(MyConnect(cptr));
-
- if (cli_dns_reply(cptr)) {
- MyFree(cli_dns_reply(cptr)->h_name);
- MyFree(cli_dns_reply(cptr));
- cli_dns_reply(cptr) = 0;
- }
-}
-
/** Complete non-blocking connect()-sequence. Check access and
* terminate connection, if trouble detected.
* @param cptr Client to which we have connected, with all ConfItem structs
attached.
@@ -759,14 +743,9 @@
if (!irc_in_addr_valid(&aconf->address.addr)
&& !ircd_aton(&aconf->address.addr, aconf->host)) {
char buf[HOSTLEN + 1];
- struct DNSQuery query;
- query.vptr = aconf;
- query.callback = connect_dns_callback;
host_from_uh(buf, aconf->host, HOSTLEN);
- buf[HOSTLEN] = '\0';
-
- gethost_byname(buf, &query);
+ gethost_byname(buf, connect_dns_callback, aconf);
aconf->dns_pending = 1;
return 0;
}
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.78 ircu2.10/ircd/s_conf.c:1.79
--- ircu2.10/ircd/s_conf.c:1.78 Mon Jun 13 21:47:00 2005
+++ ircu2.10/ircd/s_conf.c Mon Jun 27 06:25:52 2005
@@ -19,7 +19,7 @@
*/
/** @file
* @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.78 2005/06/14 04:47:00 entrope Exp $
+ * @version $Id: s_conf.c,v 1.79 2005/06/27 13:25:52 entrope Exp $
*/
#include "config.h"
@@ -228,15 +228,13 @@
* @param vptr Pointer to struct ConfItem for the block.
* @param hp DNS reply, or NULL if the lookup failed.
*/
-static void conf_dns_callback(void* vptr, struct DNSReply* hp)
+static void conf_dns_callback(void* vptr, const struct irc_in_addr *addr,
const char *h_name)
{
struct ConfItem* aconf = (struct ConfItem*) vptr;
assert(aconf);
aconf->dns_pending = 0;
- if (hp) {
- memcpy(&aconf->address.addr, &hp->addr, sizeof(aconf->address.addr));
- MyFree(hp);
- }
+ if (addr)
+ memcpy(&aconf->address.addr, addr, sizeof(aconf->address.addr));
}
/** Start a nameserver lookup of the conf host. If the conf entry is
@@ -247,13 +245,9 @@
{
if (!aconf->dns_pending) {
char buf[HOSTLEN + 1];
- struct DNSQuery query;
- query.vptr = aconf;
- query.callback = conf_dns_callback;
- host_from_uh(buf, aconf->host, HOSTLEN);
- buf[HOSTLEN] = '\0';
- gethost_byname(buf, &query);
+ host_from_uh(buf, aconf->host, HOSTLEN);
+ gethost_byname(buf, conf_dns_callback, aconf);
aconf->dns_pending = 1;
}
}
@@ -374,11 +368,9 @@
enum AuthorizationCheckResult attach_iline(struct Client* cptr)
{
struct ConfItem* aconf;
- struct DNSReply* hp;
assert(0 != cptr);
- hp = cli_dns_reply(cptr);
for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
if (aconf->status != CONF_CLIENT)
continue;
@@ -392,7 +384,7 @@
if (match(aconf->username, cli_username(cptr)))
continue;
}
- if (aconf->host && (!hp || match(aconf->host, hp->h_name)))
+ if (aconf->host && match(aconf->host, cli_sockhost(cptr)))
continue;
if ((aconf->addrbits >= 0)
&& !ipmask_check(&cli_ip(cptr), &aconf->address.addr, aconf->addrbits))
@@ -1141,28 +1133,10 @@
}
}
- if (!c_conf) {
- if (cli_dns_reply(cptr)) {
- struct DNSReply* hp = cli_dns_reply(cptr);
- const char* name = hp->h_name;
- /*
- * If we are missing a C or N line from above, search for
- * it under all known hostnames we have for this ip#.
- */
- if ((c_conf = find_conf_byhost(lp, hp->h_name, CONF_SERVER)))
- ircd_strncpy(cli_sockhost(cptr), name, HOSTLEN);
- else
- c_conf = find_conf_byip(lp, &hp->addr, CONF_SERVER);
- }
- else {
- /*
- * Check for C lines with the hostname portion the ip number
- * of the host the server runs on. This also checks the case where
- * there is a server connecting from 'localhost'.
- */
- c_conf = find_conf_byhost(lp, cli_sockhost(cptr), CONF_SERVER);
- }
- }
+ /* Try finding the Connect block by DNS name and IP next. */
+ if (!c_conf && !(c_conf = find_conf_byhost(lp, cli_sockhost(cptr),
CONF_SERVER)))
+ c_conf = find_conf_byip(lp, &cli_ip(cptr), CONF_SERVER);
+
/*
* Attach by IP# only if all other checks have failed.
* It is quite possible to get here with the strange things that can
Index: ircu2.10/ircd/s_serv.c
diff -u ircu2.10/ircd/s_serv.c:1.38 ircu2.10/ircd/s_serv.c:1.39
--- ircu2.10/ircd/s_serv.c:1.38 Fri Mar 25 21:43:49 2005
+++ ircu2.10/ircd/s_serv.c Mon Jun 27 06:25:52 2005
@@ -22,7 +22,7 @@
*/
/** @file
* @brief Miscellaneous server support functions.
- * @version $Id: s_serv.c,v 1.38 2005/03/26 05:43:49 entrope Exp $
+ * @version $Id: s_serv.c,v 1.39 2005/06/27 13:25:52 entrope Exp $
*/
#include "config.h"
@@ -148,9 +148,6 @@
SetServer(cptr);
cli_handler(cptr) = SERVER_HANDLER;
Count_unknownbecomesserver(UserStats);
-
- release_dns_reply(cptr);
-
SetBurst(cptr);
/* nextping = CurrentTime; */
Index: ircu2.10/ircd/s_user.c
diff -u ircu2.10/ircd/s_user.c:1.97 ircu2.10/ircd/s_user.c:1.98
--- ircu2.10/ircd/s_user.c:1.97 Mon Jun 13 21:47:00 2005
+++ ircu2.10/ircd/s_user.c Mon Jun 27 06:25:52 2005
@@ -22,7 +22,7 @@
*/
/** @file
* @brief Miscellaneous user-related helper functions.
- * @version $Id: s_user.c,v 1.97 2005/06/14 04:47:00 entrope Exp $
+ * @version $Id: s_user.c,v 1.98 2005/06/27 13:25:52 entrope Exp $
*/
#include "config.h"
@@ -563,7 +563,6 @@
SetUser(sptr);
cli_handler(sptr) = CLIENT_HANDLER;
- release_dns_reply(sptr);
SetLocalNumNick(sptr);
send_reply(sptr,
RPL_WELCOME,
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches