GetHostByAddr flag

Jeffrey M. Vinocur jeff at litech.org
Thu Feb 15 00:21:51 UTC 2001


Attached is a context diff that changes the compile-time constant
DO_NNRP_GETHOSTBYADDR to a commandline flag (`nnrpd -n`).

(My line numbers are slightly divergent, but I think the context diff will
take care of that.)

I didn't touch the autoconf stuff at all, although nothing horrible will
break if it is left in.  (The constant is now completely ignored, which
means that compiling without it will result in unexpected default
behavior.)

(This is definitely not well-tested, FYI.  But it compiles, and it's not
very complicated, so...)


-- 
Jeffrey M. Vinocur
jeff at litech.org


-- Attached file included as plaintext by Listar --
-- File: gethostbyaddr

diff -c -r inn-2.3.1/doc/man/nnrpd.8 inn-2.3.1-modified/doc/man/nnrpd.8
*** inn-2.3.1/doc/man/nnrpd.8	Thu Jan 11 10:39:28 2001
--- inn-2.3.1-modified/doc/man/nnrpd.8	Wed Feb 14 19:04:19 2001
***************
*** 17,22 ****
--- 20,28 ----
  .B \-i
  ]
  [
+ .B \-n
+ ]
+ [
  .B \-o
  ]
  [
***************
*** 119,124 ****
--- 136,146 ----
  is running in standalone mode since this call only works when
  .I nnrpd
  is started as root.
+ .TP
+ .B \-n
+ The ``\-n'' flag turns off resolution of IP addresses to names.  If you only
+ use IP-based restrictions in readers.conf and can handle IP addresses in your
+ logs, using this flag may result in some additional speed.
  .TP
  .B \-o
  The ``\-o'' flag causes all articles to be spooled instead of sending
diff -c -r inn-2.3.1/nnrpd/nnrpd.c inn-2.3.1-modified/nnrpd/nnrpd.c
*** inn-2.3.1/nnrpd/nnrpd.c	Thu Jan 11 10:39:38 2001
--- inn-2.3.1-modified/nnrpd/nnrpd.c	Wed Feb 14 19:06:41 2001
***************
*** 87,95 ****
  #if HAVE_GETSPNAM
  STATIC char	*ShadowGroup;
  #endif
- #if	defined(DO_NNRP_GETHOSTBYADDR)
  STATIC char 	*HostErrorStr;
! #endif	/* defined(DO_NNRP_GETHOSTBYADDR) */
  
  extern FUNCTYPE	CMDauthinfo();
  extern FUNCTYPE	CMDdate();
--- 87,94 ----
  #if HAVE_GETSPNAM
  STATIC char	*ShadowGroup;
  #endif
  STATIC char 	*HostErrorStr;
! BOOL	GetHostByAddr = TRUE;  /* formerly DO_NNRP_GETHOSTBYADDR */
  
  extern FUNCTYPE	CMDauthinfo();
  extern FUNCTYPE	CMDdate();
***************
*** 350,356 ****
  }
  
  
- #if	defined(DO_NNRP_GETHOSTBYADDR)
  #ifndef	INADDR_LOOPBACK
  #define	INADDR_LOOPBACK	0x7f000001
  #endif	/* INADDR_LOOPBACK */
--- 349,354 ----
***************
*** 410,416 ****
  	    *p = tolower(*p);
      return TRUE;
  }
- #endif	/* defined(DO_NNRP_GETHOSTBYADDR) */
  
  
  /*
--- 408,413 ----
***************
*** 450,480 ****
  	}
  
  	/* Get client's name. */
! #if	defined(DO_NNRP_GETHOSTBYADDR)
! 	HostErrorStr = NULL;
! 	if (!Address2Name(&sin.sin_addr, ClientHost, (int)sizeof ClientHost)) {
! 	    (void)strcpy(ClientHost, inet_ntoa(sin.sin_addr));
! 	    if (HostErrorStr == NULL) {
! 		syslog(L_NOTICE,
! 		    "? cant gethostbyaddr %s %m -- using IP address for access",
! 		    ClientHost);
! 	    } else {
! 		syslog(L_NOTICE,
! 		    "? cant gethostbyaddr %s %s -- using IP address for access",
! 		    ClientHost, HostErrorStr);
  	    }
- 	    ClientAddr = ClientHost;
-             ClientIP = inet_addr(ClientHost);
  	}
  	else {
! 	    ClientAddr = buff;
! 	    (void)strcpy(buff, inet_ntoa(sin.sin_addr));
!             ClientIP = inet_addr(buff);
  	}
- #else
- 	(void)strcpy(ClientHost, inet_ntoa(sin.sin_addr));
-         ClientIP = inet_addr(ClientHost);
- #endif /* defined(DO_NNRP_GETHOSTBYADDR) */
  	(void)strncpy(ClientIp, inet_ntoa(sin.sin_addr), sizeof(ClientIp));
  	length = sizeof sin;
  	if (getsockname(STDIN, (struct sockaddr *)&sin, &length) < 0) {
--- 447,478 ----
  	}
  
  	/* Get client's name. */
! 	if (GetHostByAddr) {
! 	    HostErrorStr = NULL;
! 	    if (!Address2Name(&sin.sin_addr, ClientHost, (int)sizeof ClientHost)) {
! 		(void)strcpy(ClientHost, inet_ntoa(sin.sin_addr));
! 		if (HostErrorStr == NULL) {
! 		    syslog(L_NOTICE,
! 			"? cant gethostbyaddr %s %m -- using IP address for access",
! 			ClientHost);
! 		} else {
! 		    syslog(L_NOTICE,
! 			"? cant gethostbyaddr %s %s -- using IP address for access",
! 			ClientHost, HostErrorStr);
! 		}
! 		ClientAddr = ClientHost;
! 		ClientIP = inet_addr(ClientHost);
! 	    }
! 	    else {
! 		ClientAddr = buff;
! 		(void)strcpy(buff, inet_ntoa(sin.sin_addr));
! 		ClientIP = inet_addr(buff);
  	    }
  	}
  	else {
! 	    (void)strcpy(ClientHost, inet_ntoa(sin.sin_addr));
! 	    ClientIP = inet_addr(ClientHost);
  	}
  	(void)strncpy(ClientIp, inet_ntoa(sin.sin_addr), sizeof(ClientIp));
  	length = sizeof sin;
  	if (getsockname(STDIN, (struct sockaddr *)&sin, &length) < 0) {
***************
*** 482,504 ****
  	    Printf("%d Can't figure out where you connected to.  Goodbye\r\n", NNTP_ACCESS_VAL);
  	    ExitWithStats(1, TRUE);
  	}
! #ifdef DO_NNRP_GETHOSTBYADDR
! 	HostErrorStr = NULL;
! 	if (!Address2Name(&sin.sin_addr, ServerHost, sizeof(ServerHost))) {
! 	    strcpy(ServerHost, inet_ntoa(sin.sin_addr));
! 	    if (HostErrorStr == NULL) {
! 		syslog(L_NOTICE,
! 		    "? cant gethostbyaddr %s %m -- using IP address for access",
! 		    ServerHost);
! 	    } else {
! 		syslog(L_NOTICE,
! 		    "? cant gethostbyaddr %s %s -- using IP address for access",
! 		    ServerHost, HostErrorStr);
  	    }
  	}
! #else
!         strcpy(ServerHost, inet_ntoa(sin.sin_addr));
! #endif /* DO_NNRP_GETHOSTBYADDR */
      }
  
      strncpy (LogName,ClientHost,sizeof(LogName) - 1) ;
--- 480,503 ----
  	    Printf("%d Can't figure out where you connected to.  Goodbye\r\n", NNTP_ACCESS_VAL);
  	    ExitWithStats(1, TRUE);
  	}
! 	if (GetHostByAddr) {
! 	    HostErrorStr = NULL;
! 	    if (!Address2Name(&sin.sin_addr, ServerHost, sizeof(ServerHost))) {
! 		strcpy(ServerHost, inet_ntoa(sin.sin_addr));
! 		if (HostErrorStr == NULL) {
! 		    syslog(L_NOTICE,
! 			"? cant gethostbyaddr %s %m -- using IP address for access",
! 			ServerHost);
! 		} else {
! 		    syslog(L_NOTICE,
! 			"? cant gethostbyaddr %s %s -- using IP address for access",
! 			ServerHost, HostErrorStr);
! 		}
  	    }
  	}
! 	else {
! 	    strcpy(ServerHost, inet_ntoa(sin.sin_addr));
! 	}
      }
  
      strncpy (LogName,ClientHost,sizeof(LogName) - 1) ;
***************
*** 802,807 ****
--- 802,810 ----
   	    if (ListenAddr == -1)
   	    	ListenAddr = htonl(INADDR_ANY);
   	    break;
+ 	case 'c':			/* alternate readers.conf */
+ 	    AltConfigFile = COPY(optarg);
+ 	    break;
   	case 'D':			/* standalone daemon mode */
   	    DaemonMode = TRUE;
   	    break;
***************
*** 813,818 ****
--- 816,824 ----
  	case 'i':			/* Initial command */
  	    PushedBack = COPY(optarg);
  	    break;
+ 	case 'n':			/* No DNS lookups */
+ 	    GetHostByAddr = FALSE;
+ 	    break;
  	case 'o':
  	    Offlinepost = TRUE;		/* Offline posting only */
  	    break;



More information about the inn-patches mailing list