/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2024 Alexander Barton (alex@barton.de) and Contributors.
*
* 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
#include "resolve.h"
-static void Do_ResolveAddr PARAMS(( const ng_ipaddr_t *Addr, int Sock, int w_fd ));
+static void Do_ResolveAddr_Ident PARAMS(( const ng_ipaddr_t *Addr, int Sock, int w_fd ));
static void Do_ResolveName PARAMS(( const char *Host, int w_fd ));
#ifdef WANT_IPV6
/**
- * Resolve IP (asynchronous!).
+ * Resolve IP address and do IDENT lookup asynchronously.
*/
GLOBAL bool
-Resolve_Addr(PROC_STAT * s, const ng_ipaddr_t *Addr, int identsock,
- void (*cbfunc) (int, short))
+Resolve_Addr_Ident(PROC_STAT * s, const ng_ipaddr_t *Addr, int identsock,
+ void (*cbfunc) (int, short))
{
int pipefd[2];
pid_t pid;
/* Sub process */
Log_Init_Subprocess("Resolver");
Conn_CloseAllSockets(identsock);
- Do_ResolveAddr(Addr, identsock, pipefd[1]);
+ Do_ResolveAddr_Ident(Addr, identsock, pipefd[1]);
Log_Exit_Subprocess("Resolver");
exit(0);
}
pid = Proc_Fork(s, pipefd, cbfunc, RESOLVER_TIMEOUT);
if (pid > 0) {
/* Main process */
-#ifdef DEBUG
Log( LOG_DEBUG, "Resolver for \"%s\" created (PID %d).", Host, pid );
-#endif
return true;
} else if( pid == 0 ) {
/* Sub process */
return false;
} /* Resolve_Name */
+#if !defined(HAVE_WORKING_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
#ifdef h_errno
static char *
Get_Error( int H_Error )
return "unknown error";
}
#endif
+#endif
/* Do "IDENT" (aka "AUTH") lookup and append result to resolved_addr array */
if (identsock < 0)
return;
-#ifdef DEBUG
Log_Subprocess(LOG_DEBUG, "Doing IDENT lookup on socket %d ...",
identsock);
-#endif
res = ident_id( identsock, 10 );
-#ifdef DEBUG
Log_Subprocess(LOG_DEBUG, "Ok, IDENT lookup on socket %d done: \"%s\"",
identsock, res ? res : "(NULL)");
-#endif
if (!res) /* no result */
return;
if (!array_cats(resolved_addr, res))
* @return true if lookup successful, false if domain name not found
*/
static bool
+#ifdef HAVE_WORKING_GETADDRINFO
ForwardLookup(const char *hostname, array *IpAddr, int af)
+#else
+ForwardLookup(const char *hostname, array *IpAddr, UNUSED int af)
+#endif
{
ng_ipaddr_t addr;
struct addrinfo *a, *ai_results;
static struct addrinfo hints;
-#ifdef AI_ADDRCONFIG /* glibc has this, but not e.g. netbsd 4.0 */
- hints.ai_flags = AI_ADDRCONFIG;
-#endif
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_family = af;
static void
-Do_ResolveAddr(const ng_ipaddr_t *Addr, int identsock, int w_fd)
+Do_ResolveAddr_Ident(const ng_ipaddr_t *Addr, int identsock, int w_fd)
{
/* Resolver sub-process: resolve IP address and write result into
* pipe to parent. */
size_t len;
array resolved_addr;
+ hostname[0] = '\0';
array_init(&resolved_addr);
ng_ipaddr_tostr_r(Addr, tmp_ip_str);
-#ifdef DEBUG
+
+ /* Skip DNS lookup when DNS is disabled; just return an empty ("") host
+ * name but still issue an IDENT query, if supported and enabled. */
+ if (!Conf_DNS)
+ goto dns_done;
+
Log_Subprocess(LOG_DEBUG, "Now resolving %s ...", tmp_ip_str);
-#endif
if (!ReverseLookup(Addr, hostname, sizeof(hostname)))
goto dns_done;
Log_Forgery_NoIP(tmp_ip_str, hostname);
strlcpy(hostname, tmp_ip_str, sizeof(hostname));
}
-#ifdef DEBUG
Log_Subprocess(LOG_DEBUG, "Ok, translated %s to \"%s\".", tmp_ip_str, hostname);
-#endif
dns_done:
len = strlen(hostname);
hostname[len] = '\n';
ArrayWrite(w_fd, &resolved_addr);
array_free(&resolved_addr);
-} /* Do_ResolveAddr */
+} /* Do_ResolveAddr_Ident */
static void
* to parent. */
array IpAddrs;
int af;
-#ifdef DEBUG
ng_ipaddr_t *addr;
size_t len;
-#endif
Log_Subprocess(LOG_DEBUG, "Now resolving \"%s\" ...", Host);
array_init(&IpAddrs);
close(w_fd);
return;
}
-#ifdef DEBUG
len = array_length(&IpAddrs, sizeof(*addr));
assert(len > 0);
addr = array_start(&IpAddrs);
Log_Subprocess(LOG_DEBUG, "translated \"%s\" to %s.",
Host, ng_ipaddr_tostr(addr));
}
-#endif
/* Write result into pipe to parent */
ArrayWrite(w_fd, &IpAddrs);