From: josh@Cayman.COM (Josh Littlefield)
Newsgroups: comp.infosystems.gopher
Subject: Re: Bug in gopherd 1.02 securityfile code
Date: 27 Aug 92 00:20:24 GMT
Followup-To: comp.infosystems.gopher
Organization: Cayman Systems Inc., Cambridge, MA
In-reply-to: devet@wsinis08.info.win.tue.nl's message of 21 Aug 92 21:29:33 GMT

In article <4008@svin02.info.win.tue.nl> devet@wsinis08.info.win.tue.nl (Arjan de Vet) writes:

   There's a bug in the function Can_Read in gopherd.c (1.02):

   [....]

   The variable host_name contains the *name* and not the internet address, so
   comparing host_name with an Internet address as is done above is not very
   usefull. Does anybody know how to get the internet address of the host
   connected to sockfd? If you have a patch, please post.

I haven't gotten gopher 1.02, but I fixed this myself in gopher 1.0.
I found a raft of little bugs in gopher 1.0 which I've meant to feed
back, but work got in the way.

Here are the diffs from the 1.0 gopherd.c to fix your problem.  Also
included are some other fixes and optimizations:

hunk 1: change deamonizing -- I had problems with processes not
	cleaning up.
hunk 2: part of security fix
hunk 3:  "  "
hunk 4:  "  "
hunk 5: part of optimization to prevent constantly opening `.cap/*'
	files when scanning a directory if `.cap' dir doesn't exist.
hunk 6:  "  "
hunk 7:  "  "
hunk 8:  "  "
hunk 9: fix bug which prevented cache from working

================ cut here ================
*** gopherd.c-dist	Thu Jun 18 15:23:30 1992
--- gopherd.c	Mon Jul  6 17:28:17 1992
***************
*** 333,339 ****
  
  
       if (DEBUG == FALSE && RunFromInetd==FALSE)
! 	  daemon_start(0);
  
  
       /*** Hmmm, does this look familiar? :-) ***/
--- 333,339 ----
  
  
       if (DEBUG == FALSE && RunFromInetd==FALSE)
! 	  daemon_start(1);
  
  
       /*** Hmmm, does this look familiar? :-) ***/
***************
*** 586,592 ****
       struct sockaddr sa;
       int             length;
       char            host_name[256];
!      char *cp;
       boolean         MatchReturn;
       char            inputline[MAXLINE];
  
--- 586,592 ----
       struct sockaddr sa;
       int             length;
       char            host_name[256];
!      char *cp, *hap;
       boolean         MatchReturn;
       char            inputline[MAXLINE];
  
***************
*** 596,601 ****
--- 596,602 ----
       length = sizeof (sa);
       getpeername(sockfd, &sa, &length);
       inet_netnames(sockfd, &sa, host_name);
+      hap = inet_ntoa(((struct sockaddr_in *)&sa)->sin_addr);
  
       fseek(SECFileHandle, 0, 0);  /** Go to beginning of Security File **/
       
***************
*** 615,620 ****
--- 616,625 ----
  	       /** Check for a match from the beginning **/
  	       if (strstr(host_name,cp) == host_name)
  		    return(MatchReturn);
+ 
+ 	       /** Check against host inet addr even if we know his name **/
+ 	       if (strstr(hap,cp) == hap)
+ 		    return(MatchReturn);
  		    
  	  }
  	  
***************
*** 1204,1209 ****
--- 1209,1215 ----
       char                  sidename[256];
       char                  filename[256];
       static char           newpath[512];
+      boolean		   dotcap;
  
       FILE                  *SideFile;
       
***************
*** 1242,1247 ****
--- 1248,1257 ----
  	  return;
       }
  
+      strcpy(sidename, "./.cap");
+      dotcap = isadir(sidename);
+      strcat(sidename,"/");
+ 
       for (dp = readdir(ZeDir); dp != NULL; dp = readdir(ZeDir)) {
  
            strcpy(newpath, pathname);
***************
*** 1249,1258 ****
                 strcat(newpath, "/");
            strcat(newpath, dp->d_name);
  
- 	  strcpy(sidename, "./.cap/");
  	  strcpy(filename, dp->d_name);
! 	  strcat(sidename, dp->d_name);
! 	  
  	  /** Only chew list out files that don't start with a dot **/
  	  /** or aren't named dev, usr, bin, etc, or core.         **/
  
--- 1259,1266 ----
                 strcat(newpath, "/");
            strcat(newpath, dp->d_name);
  
  	  strcpy(filename, dp->d_name);
! 
  	  /** Only chew list out files that don't start with a dot **/
  	  /** or aren't named dev, usr, bin, etc, or core.         **/
  
***************
*** 1308,1319 ****
  	       else
  		    GSsetTitle(Gopherp, filename);
  
  
! 	       if ((SideFile = rfopen(sidename, "r"))!=0) {
! 		    if (DEBUG == TRUE)
! 			 printf("Side file name: %s\n", sidename);
! 		    Process_Side(SideFile, Gopherp);
! 	       }
  
  
  	       /*** Add the entry to the directory ***/
--- 1316,1330 ----
  	       else
  		    GSsetTitle(Gopherp, filename);
  
+ 	       if (dotcap == 1) {
+ 	            strcpy(sidename + 7, dp->d_name);
  
! 	            if ((SideFile = rfopen(sidename, "r"))!=0) {
! 		         if (DEBUG == TRUE)
! 			     printf("Side file name: %s\n", sidename);
! 		         Process_Side(SideFile, Gopherp);
! 	            }
! 		}
  
  
  	       /*** Add the entry to the directory ***/
***************
*** 1350,1356 ****
  
  	  cachefd = uopen(cachefile, O_WRONLY|O_CREAT|O_TRUNC, 0755);
  
! 	  if (cachefd != 0) {
  	       if (DEBUG) {
  		    printf("Caching directory...\n");
  	       }
--- 1361,1367 ----
  
  	  cachefd = uopen(cachefile, O_WRONLY|O_CREAT|O_TRUNC, 0755);
  
! 	  if (cachefd >= 0) {
  	       if (DEBUG) {
  		    printf("Caching directory...\n");
  	       }
--
/--------------------------------------*--------------------------------------\
| Josh Littlefield                                     Cayman Systems, Inc.   |
| josh@cayman.com                                      University Park at MIT |
| (617) 494-1999                                       26 Landsdowne Street   |
| fax: (617) 494-5167                                  Cambridge, MA  02139   |
\--------------------------------------*--------------------------------------/
Newsgroups: comp.infosystems.gopher