[Midnightbsd-cvs] src [11839] trunk/release/picobsd/tinyware/simple_httpd/simple_httpd.c: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Thu Jul 12 20:33:31 EDT 2018


Revision: 11839
          http://svnweb.midnightbsd.org/src/?rev=11839
Author:   laffer1
Date:     2018-07-12 20:33:30 -0400 (Thu, 12 Jul 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/release/picobsd/tinyware/simple_httpd/Makefile
    trunk/release/picobsd/tinyware/simple_httpd/README
    trunk/release/picobsd/tinyware/simple_httpd/simple_httpd.c

Property Changed:
----------------
    trunk/release/picobsd/tinyware/simple_httpd/README

Modified: trunk/release/picobsd/tinyware/simple_httpd/Makefile
===================================================================
--- trunk/release/picobsd/tinyware/simple_httpd/Makefile	2018-07-13 00:31:45 UTC (rev 11838)
+++ trunk/release/picobsd/tinyware/simple_httpd/Makefile	2018-07-13 00:33:30 UTC (rev 11839)
@@ -1,7 +1,9 @@
-# $FreeBSD: src/release/picobsd/tinyware/simple_httpd/Makefile,v 1.8 2004/12/21 08:47:06 ru Exp $
+# $MidnightBSD$
+# $FreeBSD: stable/10/release/picobsd/tinyware/simple_httpd/Makefile 276486 2014-12-31 23:25:37Z ngie $
 #
 PROG=simple_httpd
 SRCS= 	simple_httpd.c
-NO_MAN=
+MAN=
+WARNS?=6
 
 .include <bsd.prog.mk>

Modified: trunk/release/picobsd/tinyware/simple_httpd/README
===================================================================
--- trunk/release/picobsd/tinyware/simple_httpd/README	2018-07-13 00:31:45 UTC (rev 11838)
+++ trunk/release/picobsd/tinyware/simple_httpd/README	2018-07-13 00:33:30 UTC (rev 11839)
@@ -21,14 +21,14 @@
 
 The "fetch" mode supports file transfer over httpd.  This 
 is best thought of as mate for fetch(1).  This feature can be
-usefull to transfer a file from one host to another.
+useful to transfer a file from one host to another.
 
 Simple_httpd has the ability to run CGI scripts.  All CGI
 scripts must be located in ${DOCUMENT_ROOT}/cgi-bin.  The
-server currently only sets 3 enviroment variables before calling
+server currently only sets 3 environment variables before calling
 the script.
 
-CGI Enviroment variables are below:
+CGI Environment variables are below:
 
 SERVER_SOFTWARE = FreeBSD/PicoBSD
 REMOTE_HOST = client.canada_lower_taxes.com
@@ -61,7 +61,7 @@
 
 -D
 Do not daemonize.  The server will not run in the background.  It will
-stay attached to the tty.  This is usefull for debugging.  In this
+stay attached to the tty.  This is useful for debugging.  In this
 mode no log file is created.  Logging info is to stdout.
 
 This option is automatically selected if fetch option is selected.
@@ -139,7 +139,7 @@
 To Do
 =====
 
-Simple authentication would be very usefull[understatment].
+Simple authentication would be very useful [understatment].
 /etc/passwd or PAM would be nice.
 
 I think a netmask option would be good. Most internet appliances
@@ -164,4 +164,5 @@
 
 Major rewrite by William Lloyd <wlloyd at slap.net>
 
-$FreeBSD: src/release/picobsd/tinyware/simple_httpd/README,v 1.6 1999/08/28 01:33:59 peter Exp $
+$FreeBSD: stable/10/release/picobsd/tinyware/simple_httpd/README 229779 2012-01-07 16:09:43Z uqs $
+$MidnightBSD$


Property changes on: trunk/release/picobsd/tinyware/simple_httpd/README
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/release/picobsd/tinyware/simple_httpd/simple_httpd.c
===================================================================
--- trunk/release/picobsd/tinyware/simple_httpd/simple_httpd.c	2018-07-13 00:31:45 UTC (rev 11838)
+++ trunk/release/picobsd/tinyware/simple_httpd/simple_httpd.c	2018-07-13 00:33:30 UTC (rev 11839)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Simple_HTTPd v1.1 - a very small, barebones HTTP server
  * 
@@ -27,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/release/picobsd/tinyware/simple_httpd/simple_httpd.c,v 1.16 2004/08/16 09:38:34 dwmalone Exp $
+ * $FreeBSD: stable/10/release/picobsd/tinyware/simple_httpd/simple_httpd.c 273512 2014-10-23 02:50:18Z pfg $
  */
 
 #include <sys/stat.h>
@@ -42,6 +43,7 @@
 #include <netdb.h>
 #include <signal.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -67,7 +69,7 @@
 struct sockaddr_in source;
 
 /* HTTP basics */
-static char httpd_server_ident[] = "Server: FreeBSD/PicoBSD simple_httpd 1.1\r";
+static char httpd_server_ident[] = "Server: MidnightBSD/PicoBSD simple_httpd 1.1\r";
 
 static char http_200[] = "HTTP/1.0 200 OK\r";
 
@@ -159,8 +161,8 @@
 void
 http_output(const char *html)
 {
-        write(con_sock, html, strlen(html));
-        write(con_sock, "\r\n", 2);
+	write(con_sock, html, strlen(html));
+	write(con_sock, "\r\n", 2);
 }
 
 
@@ -171,30 +173,30 @@
 void
 log_line(char *req)
 {
-        char            log_buff[256];
-        char            msg[1024];
-	char            env_host[80], env_addr[80];
-	long            addr;
-	FILE           *log;
+	char	log_buff[256];
+	char	msg[1024];
+	char	env_host[80], env_addr[80];
+	long	addr;
+	FILE	*log;
 
 	strcpy(log_buff,inet_ntoa(source.sin_addr));
 	sprintf(env_addr, "REMOTE_ADDR=%s",log_buff);
 
-        addr=inet_addr(log_buff);
-        
-        strcpy(msg,adate());
-        strcat(msg,"    ");                 
-        hst=gethostbyaddr((char*) &addr, 4, AF_INET);
+	addr=inet_addr(log_buff);
 
+	strcpy(msg,adate());
+	strcat(msg,"    ");
+	hst=gethostbyaddr((char*) &addr, 4, AF_INET);
+
 	/* If DNS hostname exists */
-        if (hst) {
+	if (hst) {
 	  strcat(msg,hst->h_name);
 	  sprintf(env_host, "REMOTE_HOST=%s",hst->h_name);
 	}
-        strcat(msg," (");
-        strcat(msg,log_buff);
-        strcat(msg,")   ");
-        strcat(msg,req);
+	strcat(msg," (");
+	strcat(msg,log_buff);
+	strcat(msg,")   ");
+	strcat(msg,req);
 
 	if (daemonize) {
 	  log=fopen(logfile,"a");
@@ -225,8 +227,8 @@
 
 	lg = read(con_sock, req, 1024);
 
-        if ((p=strstr(req,"\n"))) *p=0;
-        if ((p=strstr(req,"\r"))) *p=0;
+	if ((p=strstr(req,"\n"))) *p=0;
+	if ((p=strstr(req,"\r"))) *p=0;
 
 	log_line(req);
 
@@ -252,40 +254,40 @@
 	filename = strtok(NULL, " ");
 
 	c = strtok(NULL, " ");
-	if (fetch_mode != NULL) filename=fetch_mode; 
-	if (filename == NULL || 
-            strlen(filename)==1) filename="/index.html"; 
+	if (fetch_mode != NULL) filename=fetch_mode;
+	if (filename == NULL ||
+	    strlen(filename)==1) filename="/index.html";
 
-	while (filename[0]== '/') filename++;        
+	while (filename[0]== '/') filename++;
 	
-        /* CGI handling.  Untested */
-        if (!strncmp(filename,"cgi-bin/",8))           
-           {
-           par=0;
-           if ((par=strstr(filename,"?")))                        
-              {
-               *par=0;            
-                par++;      
-              } 
-           if (access(filename,X_OK)) goto conti;
-           stat (filename,&file_status);
-           if (setuid(file_status.st_uid)) return;
-           if (seteuid(file_status.st_uid)) return;
-           if (!fork())
-              {
-               close(1);
-               dup(con_sock);
-               /*printf("HTTP/1.0 200 OK\nContent-type: text/html\n\n\n");*/
+	/* CGI handling.  Untested */
+	if (!strncmp(filename,"cgi-bin/",8))
+	   {
+	   par=0;
+	   if ((par=strstr(filename,"?")))
+	      {
+	       *par=0;
+	        par++;
+	      } 
+	   if (access(filename,X_OK)) goto conti;
+	   stat (filename,&file_status);
+	   if (setuid(file_status.st_uid)) return;
+	   if (seteuid(file_status.st_uid)) return;
+	   if (!fork())
+	      {
+	       close(1);
+	       dup(con_sock);
+	       /*printf("HTTP/1.0 200 OK\nContent-type: text/html\n\n\n");*/
 	       printf("HTTP/1.0 200 OK\r\n");
-               /* Plug in environment variable, others in log_line */
-	       putenv("SERVER_SOFTWARE=FreeBSD/PicoBSD");
+	       /* Plug in environment variable, others in log_line */
+	       setenv("SERVER_SOFTWARE", "MidnightBSD/PicoBSD", 1);
 
 	       execlp (filename,filename,par,(char *)0);
-              } 
-            wait(&i);
-            return;
-            }
-        conti:
+	      } 
+	    wait(&i);
+	    return;
+	    }
+	conti:
 	if (filename == NULL) {
 	  http_output(http_405[0]);
 	  http_output(http_405[1]);
@@ -306,8 +308,8 @@
 	/* Open filename */
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
-	        http_output(http_404[0]);
-	        http_output(http_404[1]);
+		http_output(http_404[0]);
+		http_output(http_404[1]);
 		goto end_request;
 	}
 
@@ -324,7 +326,7 @@
 	  http_output(http_404[1]);
 	  goto end_request2;
 	}
-     
+
 	/* Past this point we are serving either a GET or HEAD */
 	/* Print all the header info */
 	http_output(http_200);
@@ -331,7 +333,7 @@
 	http_output(httpd_server_ident);
 	http_date();
 
-	sprintf(buff, "Content-length: %lld\r\n", file_status.st_size);
+	sprintf(buff, "Content-length: %jd\r\n", (intmax_t)file_status.st_size);
 	write(con_sock, buff, strlen(buff));
 
 	strcpy(buff, "Content-type: ");
@@ -370,14 +372,14 @@
 int
 main(int argc, char *argv[])
 {
-        int ch, ld;
-	int             httpd_group = 65534;
-        pid_t server_pid;
-  
+	int ch, ld;
+	pid_t httpd_group = 65534;
+	pid_t server_pid;
+
 	/* Default for html directory */
 	strcpy (homedir,getenv("HOME"));
-        if (!geteuid()) strcpy (homedir,"/httphome");
-           else         strcat (homedir,"/httphome");
+	if (!geteuid())	strcpy (homedir,"/httphome");
+	   else		strcat (homedir,"/httphome");
 
 	/* Defaults for log file */
 	if (geteuid()) {
@@ -419,10 +421,10 @@
 	    printf("usage: simple_httpd [[-d directory][-g grpid][-l logfile][-p port][-vD]]\n");
 	    exit(1);
 	    /* NOTREACHED */
-	  }                           
+	  }
 
 	/* Not running as root and no port supplied, assume 1080 */
-        if ((http_port == 80) && geteuid()) {
+	if ((http_port == 80) && geteuid()) {
 	  http_port = 1080;
 	}
 
@@ -436,15 +438,15 @@
 	}
 
 	/* Create log file if it doesn't exit */
-	if ((access(logfile,W_OK)) && daemonize) { 
-	  ld = open (logfile,O_WRONLY);         
+	if ((access(logfile,W_OK)) && daemonize) {
+	  ld = open (logfile,O_WRONLY);
 	  chmod (logfile,00600);
 	  close(ld);
 	}
 
-        init_servconnection();                  
+	init_servconnection();
 
-        if (verbose) {
+	if (verbose) {
 	  printf("Server started with options \n"); 
 	  printf("port: %d\n",http_port);
 	  if (fetch_mode == NULL) printf("html home: %s\n",homedir);
@@ -452,7 +454,7 @@
 	}
 
 	/* httpd is spawned */
-        if (daemonize) {
+	if (daemonize) {
 	  if ((server_pid = fork()) != 0) {
 	    wait3(0,WNOHANG,0);
 	    if (verbose) printf("pid: %d\n",server_pid);
@@ -461,16 +463,17 @@
 	  wait3(0,WNOHANG,0);
 	}
 
-	if (fetch_mode == NULL) setpgrp(0,httpd_group);
+	if (fetch_mode == NULL)
+		setpgrp((pid_t)0, httpd_group);
 
 	/* How many connections do you want? 
 	 * Keep this lower than the available number of processes
 	 */
-        if (listen(http_sock,15) < 0) exit(1);
+	if (listen(http_sock,15) < 0) exit(1);
 
-        label:	
+	label:	
 	wait_connection();
-    
+
 	if (fork()) {
 	  wait3(0,WNOHANG,0);
 	  close(con_sock);
@@ -487,13 +490,13 @@
 char *
 adate(void)
 {
-        static char out[50];
-        time_t now;
-        struct tm *t;
-        time(&now);
-        t = localtime(&now);
-        sprintf(out, "%02d:%02d:%02d %02d/%02d/%02d",
-                     t->tm_hour, t->tm_min, t->tm_sec,
-                     t->tm_mday, t->tm_mon+1, t->tm_year );
-        return out;
+	static char out[50];
+	time_t now;
+	struct tm *t;
+	time(&now);
+	t = localtime(&now);
+	sprintf(out, "%02d:%02d:%02d %02d/%02d/%02d",
+		     t->tm_hour, t->tm_min, t->tm_sec,
+		     t->tm_mday, t->tm_mon+1, t->tm_year );
+	return out;
 }



More information about the Midnightbsd-cvs mailing list