Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 May 1995 14:20:01 -0700
From:      henrich@crh.cl.msu.edu (Charles Henrich)
To:        freebsd-bugs
Subject:   bin/401: REMOTE_HOST REMOTE_PORT REMOTE_IP
Message-ID:  <199505132120.OAA12694@freefall.cdrom.com>
In-Reply-To: Your message of Sat, 13 May 1995 17:14:53 -0400 <199505132114.RAA26502@bsdprd1.ais.msu.edu>

next in thread | previous in thread | raw e-mail | index | archive | help

>Number:         401
>Category:       bin
>Synopsis:       Add REMOTE_* variables
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs (FreeBSD bugs mailing list)
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 13 14:20:01 1995
>Originator:     Charles Henrich &
>Organization:
Michigan State University
>Release:        FreeBSD 2.1.0-Development i386
>Environment:

	FreeBSD 950412-SNAP
	

>Description:

        Modifications to inetd, telnetd, rlogind to make the following 
        environment variables available to all processes.

        REMOTE_IP    (Contains IP or -1.-1.-1.-1 (always a dotquad parseable)
        REMOTE_HOST  (Contains hostname or ip if resolver fails)
        REMOTE_PORT  (Contains the port of the remote host or -1 if failure)

	

>How-To-Repeat:

	

>Fix:

As well as applying the following three patches, need to add
-DDO_REMOTEVARS to telnetd and rlogind Makefile(s).  The code in inetd
wasnt #ifdef'd because working around the existing code would have been 
ugly/nasty.

-------------------------------------------------------------------------------

*** usr.sbin/inetd/inetd.c	Sat May 13 14:27:21 1995
--- usr.sbin/inetd/inetd.c.new	Sat May 13 14:27:15 1995
***************
*** 252,257 ****
--- 252,258 ----
  	pid_t pid;
  	char buf[50];
  	struct  sockaddr_in peer;
+ 	struct hostent *hs;
  	int i;
  
  	Argv = argv;
***************
*** 354,372 ****
  						sep->se_service);
  				    continue;
  			    }
! 			    if(log) {
! 				i = sizeof peer;
! 				if(getpeername(ctrl, (struct sockaddr *)
! 						&peer, &i)) {
  					syslog(LOG_WARNING,
  						"getpeername(for %s): %m",
  						sep->se_service);
- 					continue;
  				}
! 				syslog(LOG_INFO,"%s from %s",
! 					sep->se_service,
! 					inet_ntoa(peer.sin_addr));
  			    }
  			    /*
  			     * Call tcpmux to find the real service to exec.
  			     */
--- 355,416 ----
  						sep->se_service);
  				    continue;
  			    }
! 
! 			    /***********************************************/
! 			    /*                                             */
! 			    /* Originally getpeername was only called      */
! 			    /* inside the if(log) block, and in that case  */
! 			    /* if getpeername returned an error the code   */
! 			    /* would continue back to the top of the loop. */
! 			    /* This doesnt make any sense, so in the new   */
! 			    /* case (we always do a getpeername for the    */
! 			    /* REMOTE_* vars) we just set the variables to */
! 			    /* UNKNOWN, -1.-1.-1.-1, -1 and drop through   */
! 			    /* as it should. -Crh (henrich@msu.edu)        */
! 			    /*                                             */
! 			    /***********************************************/
! 
! 			    i = sizeof peer;
! 			    if(getpeername(ctrl, (struct sockaddr *)
! 					   &peer, &i)) {
! 
! 			        if(log) {
  					syslog(LOG_WARNING,
  						"getpeername(for %s): %m",
  						sep->se_service);
  				}
! 
! 				(void)setenv("REMOTE_HOST", "UNKNOWN", 1);
! 				(void)setenv("REMOTE_IP", "-1.-1.-1.-1", 1);
! 				(void)setenv("REMOTE_PORT", "-1", 1);
! 
! 			    } else { 
! 
!  				if(log) {
! 					syslog(LOG_INFO,"%s from %s",
! 						sep->se_service,
! 						inet_ntoa(peer.sin_addr));
! 				}
! 
! 			    	hs=gethostbyaddr((char *)&peer.sin_addr,
! 					         sizeof(peer.sin_addr), 
! 					         AF_INET);
! 	
! 			    	if(hs != NULL) {
! 				    	(void)setenv("REMOTE_HOST", hs->h_name,
! 						     1);
! 			    	} else {
! 			            	(void)setenv("REMOTE_HOST", 
! 					 	 inet_ntoa(peer.sin_addr), 1);
! 			    	}
! 				
! 				(void)setenv("REMOTE_IP", 
! 					     inet_ntoa(peer.sin_addr), 1);
! 
! 				sprintf(buf,"%hd", ntohs(peer.sin_port));
! 				(void)setenv("REMOTE_PORT", buf, 1);
  			    }
+ 
  			    /*
  			     * Call tcpmux to find the real service to exec.
  			     */

-------------------------------------------------------------------------------

*** libexec/telnetd/telnetd.c	Fri Aug 12 19:00:02 1994
--- libexec/telnetd/telnetd.c.new	Sat May 13 16:05:46 1995
***************
*** 758,763 ****
--- 758,766 ----
  	int level;
  	int ptynum;
  	char user_name[256];
+ #ifdef DO_REMOTEVARS
+         char remote_port[20];
+ #endif /* DO_REMOTEVARS */
  
  	/*
  	 * Find an available pty to use.
***************
*** 833,838 ****
--- 836,848 ----
  	*user_name = 0;
  	level = getterminaltype(user_name);
  	setenv("TERM", terminaltype ? terminaltype : "network", 1);
+ 
+ #ifdef DO_REMOTEVARS
+         setenv("REMOTE_HOST", remote_host_name, 1);
+         setenv("REMOTE_IP", inet_ntoa(who->sin_addr), 1);
+         sprintf(remote_port,"%hd", ntohs(who->sin_port));
+         setenv("REMOTE_PORT", remote_port, 1);
+ #endif /* DO_REMOTEVARS */
  
  	/*
  	 * Start up the login process on the slave side of the terminal

-------------------------------------------------------------------------------

*** libexec/rlogind/rlogind.c	Sat May 13 16:07:38 1995
--- libexec/rlogind/rlogind.c.new	Sat May 13 17:02:46 1995
***************
*** 200,205 ****
--- 200,208 ----
  	register struct hostent *hp;
  	char hostname[2 * MAXHOSTNAMELEN + 1];
  	char c;
+ #ifdef DO_REMOTEVARS
+         char remote_port[20];
+ #endif /* DO_REMOTEVARS */
  
  	alarm(60);
  	read(f, &c, 1);
***************
*** 293,298 ****
--- 296,315 ----
  		if (f > 2)	/* f should always be 0, but... */
  			(void) close(f);
  		setup_term(0);
+ 
+ #ifdef DO_REMOTEVARS
+ 		setenv("REMOTE_HOST", hostname, 1);
+ 		setenv("REMOTE_IP", inet_ntoa(fromp->sin_addr), 1);
+ 
+                 /**********************************************************/
+                 /* fromp->sin_port is in host-byte-order for some strange */
+                 /* reason here, so we dont do a ntohs here.               */
+                 /**********************************************************/
+ 
+ 		sprintf(remote_port,"%hd", fromp->sin_port);
+ 		setenv("REMOTE_PORT", remote_port, 1);
+ #endif /* DO_REMOTEVARS */
+ 
  		if (strchr(lusername, '-')) {
  			syslog(LOG_ERR, "tried to pass user \"%s\" to login",
  			       lusername);
>Audit-Trail:
>Unformatted:





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199505132120.OAA12694>