>From bc@mtiweb.com Thu Sep 7 21:54:19 1995 From: Barry Caplin To: bc@nag.com Subject: subdocroot patch Apply the following patch to the /usr/src/httpd_1.4.1 tree. Then, in httpd/conf/src.conf add lines of the form: SubDocumentRoot www.name.com fullpathname just after the DocumentRoot section. where www.name.com is the web address of the virtual domain you are defining, and fullpathname is the full pathname of the directory where name.com's html is. diff -u --recursive --new-file httpd_1.4.1/src/http_alias.c httpd_1.4.1_sem/src/http_alias.c --- httpd_1.4.1/src/http_alias.c Wed May 17 21:00:20 1995 +++ httpd_1.4.1_sem/src/http_alias.c Tue Jun 13 14:42:16 1995 @@ -74,6 +74,12 @@ register int x,l; char w[MAX_STRING_LEN]; struct passwd *pw; + int cs_len; + struct sockaddr_in cs; + int rc; + long my_addr; + + this_subdoc = -1; getparents(name); @@ -107,6 +113,33 @@ strsubfirst(strlen(w) + 2,name,real); return STD_DOCUMENT; } + /* check for subdoc */ + cs_len = sizeof(cs); + rc = getsockname(0,(struct sockaddr *)&cs, &cs_len); + if (rc == 0) { + unsigned char dot1,dot2,dot3,dot4; + char saddr[MAX_STRING_LEN]; + + /* get the remote IP.. */ + my_addr = ntohl(cs.sin_addr.s_addr); + dot4 = my_addr & 0x000000ff; + dot3 = (my_addr >> 8) & 0x0000ff; + dot2 = (my_addr >> 16) & 0x00ff; + dot1 = my_addr >> 24; + sprintf(saddr,"%u.%u.%u.%u",dot1,dot2,dot3,dot4); + + for (rc = 0; rc < MAX_SUBDOCS; rc++) { + if (subdocument_roots[rc].host_address[0] == 0) + break; + + if (!strncmp(subdocument_roots[rc].host_address,saddr,MAX_STRING_LEN)) { + strsubfirst(0,name,subdocument_roots[rc].subdocumentroot); + this_subdoc = rc; + return STD_DOCUMENT; + } + } + } + /* no alias, add document root */ strsubfirst(0,name,document_root); return STD_DOCUMENT; diff -u --recursive --new-file httpd_1.4.1/src/http_config.c httpd_1.4.1_sem/src/http_config.c --- httpd_1.4.1/src/http_config.c Wed May 17 21:11:34 1995 +++ httpd_1.4.1_sem/src/http_config.c Tue Jun 13 14:40:27 1995 @@ -43,6 +43,7 @@ char annotation_server[MAX_STRING_LEN]; /* SSG 4/5/95 annotation server url */ int timeout; int do_rfc931; +int this_subdoc; #ifndef NO_PASS int max_servers; @@ -246,6 +247,7 @@ char index_name[MAX_STRING_LEN]; char access_name[MAX_STRING_LEN]; char document_root[MAX_STRING_LEN]; +subdoc_list subdocument_roots[MAX_SUBDOCS]; char default_type[MAX_STRING_LEN]; char local_default_type[MAX_STRING_LEN]; char default_icon[MAX_STRING_LEN]; @@ -255,6 +257,7 @@ FILE *cfg; char l[MAX_STRING_LEN],w[MAX_STRING_LEN]; int n=0; + int num_roots = 0; strcpy(user_dir,DEFAULT_USER_DIR); strcpy(index_name,DEFAULT_INDEX); @@ -262,6 +265,12 @@ strcpy(document_root,DOCUMENT_LOCATION); strcpy(default_type,DEFAULT_TYPE); default_icon[0] = '\0'; + for (n=0;nh_addr[0]; + dot2 = (unsigned char) he->h_addr[1]; + dot3 = (unsigned char) he->h_addr[2]; + dot4 = (unsigned char) he->h_addr[3]; + + sprintf(host_address,"%u.%u.%u.%u",dot1,dot2,dot3,dot4); + } else { + strncpy(host_address,w,MAX_STRING_LEN-1); + he = gethostbyname(w); + if (he == NULL) { + strncpy(host_name,w,MAX_STRING_LEN-1); + } else { + strncpy(host_name,he->h_name,MAX_STRING_LEN-1); + } + } + + if (!is_directory(w2)) { + fprintf(errors,"Syntax error on line %d of %s:\n",n, + srm_confname); + fprintf(errors,"%s is not a valid directory.\n",w2); + exit(1); + } + + if (num_roots < MAX_SUBDOCS) { + + strncpy(subdocument_roots[num_roots].host_address, + host_address,MAX_STRING_LEN-1); + + strncpy(subdocument_roots[num_roots].host_name, + host_name,MAX_STRING_LEN-1); + + strncpy(subdocument_roots[num_roots].subdocumentroot, + w2,MAX_STRING_LEN-1); + + num_roots = num_roots + 1; + } + } else if(!strcasecmp(w,"Alias")) { char w2[MAX_STRING_LEN]; diff -u --recursive --new-file httpd_1.4.1/src/http_log.c httpd_1.4.1_sem/src/http_log.c --- httpd_1.4.1/src/http_log.c Wed May 17 21:00:22 1995 +++ httpd_1.4.1_sem/src/http_log.c Tue Jun 13 14:39:59 1995 @@ -49,6 +49,8 @@ FILE *error_log; /* static FILE *xfer_log; */ static int xfer_log; +static int sxfer_log[MAX_STRING_LEN]; +static int num_subdocs; static int xfer_flags = ( O_WRONLY | O_APPEND | O_CREAT ); static mode_t xfer_mode = ( S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); FILE *agent_log; @@ -74,6 +76,22 @@ perror("open"); exit(1); } + for (num_subdocs = 0; num_subdocs < MAX_SUBDOCS; num_subdocs++) { + char my_log[MAX_STRING_LEN]; + + if (subdocument_roots[num_subdocs].host_name[0] == 0) + break; + + sprintf(my_log,"%s.%s",xfer_fname, + subdocument_roots[num_subdocs].host_name); + + if((sxfer_log[num_subdocs] = open(my_log,xfer_flags,xfer_mode)) < 0) { + fprintf(stderr,"httpd: could not open transfer log file %s.\n", + my_log); + perror("open"); + exit(1); + } + } if(!(agent_log = fopen(agent_fname,"a"))) { fprintf(stderr,"httpd: could not open agent log file %s.\n", agent_fname); @@ -102,9 +120,12 @@ } void close_logs() { + int i; fflush(error_log); fflush(agent_log); fflush(referer_log); + for (i=0;i