Index: head/release/picobsd/tinyware/simple_httpd/simple_httpd.c =================================================================== --- head/release/picobsd/tinyware/simple_httpd/simple_httpd.c (revision 352926) +++ head/release/picobsd/tinyware/simple_httpd/simple_httpd.c (nonexistent) @@ -1,501 +0,0 @@ -/*- - * Simple_HTTPd v1.1 - a very small, barebones HTTP server - * - * Copyright (c) 1998-1999 Marc Nicholas - * All rights reserved. - * - * Major rewrite by William Lloyd - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int http_port = 80; -static int daemonize = 1; -static int verbose = 0; -static int http_sock, con_sock; - -static const char *fetch_mode = NULL; -static char homedir[100]; -static char logfile[80]; -static char *adate(void); -static void init_servconnection(void); -static void http_date(void); -static void http_output(const char *html); -static void http_request(void); -static void log_line(char *req); -static void wait_connection(void); - -static struct hostent *hst; -static struct sockaddr_in source; - -/* HTTP basics */ -static char httpd_server_ident[] = "Server: FreeBSD/PicoBSD simple_httpd 1.1\r"; - -static char http_200[] = "HTTP/1.0 200 OK\r"; - -static const char *default_mime_type = "application/octet-stream"; - -static const char *mime_type[][2] = { - { "txt", "text/plain" }, - { "htm", "text/html" }, - { "html", "text/html" }, - { "gif", "image/gif" }, - { "jpg", "image/jpeg" }, - { "mp3", "audio/mpeg" } -}; - -static const int mime_type_max = sizeof(mime_type) / sizeof(mime_type[0]) - 1; - -/* Two parts, HTTP Header and then HTML */ -static const char *http_404[2] = - {"HTTP/1.0 404 Not found\r\n", -"Error

Error 404

\ -Not found - file doesn't exist or you do not have permission.\n\r\n" -}; - -static const char *http_405[2] = - {"HTTP/1.0 405 Method Not allowed\r\nAllow: GET,HEAD\r\n", -"Error

Error 405

\ -This server only supports GET and HEAD requests.\n\r\n" -}; - -/* - * Only called on initial invocation - */ -static void -init_servconnection(void) -{ - struct sockaddr_in server; - - /* Create a socket */ - http_sock = socket(AF_INET, SOCK_STREAM, 0); - if (http_sock < 0) { - perror("socket"); - exit(1); - } - server.sin_family = AF_INET; - server.sin_port = htons(http_port); - server.sin_addr.s_addr = INADDR_ANY; - if (bind(http_sock, (struct sockaddr *) & server, sizeof(server)) < 0) { - perror("bind socket"); - exit(1); - } - if (verbose) printf("simple_httpd:%d\n",http_port); -} - -/* - * Wait here until we see an incoming http request - */ -static void -wait_connection(void) -{ - socklen_t lg; - - lg = sizeof(struct sockaddr_in); - - con_sock = accept(http_sock, (struct sockaddr *) & source, &lg); - if (con_sock <= 0) { - perror("accept"); - exit(1); - } -} - -/* - * Print timestamp for HTTP HEAD and GET - */ -static void -http_date(void) -{ - time_t tl; - char buff[50]; - - tl = time(NULL); - strftime(buff, 50, "Date: %a, %d %h %Y %H:%M:%S %Z\r\n", gmtime(&tl)); - write(con_sock, buff, strlen(buff)); - /* return(buff); */ -} - -/* - * Send data to the open socket - */ -static void -http_output(const char *html) -{ - write(con_sock, html, strlen(html)); - write(con_sock, "\r\n", 2); -} - - -/* - * Create and write the log information to file - * Log file format is one line per entry - */ -static void -log_line(char *req) -{ - 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); - - /* If DNS hostname exists */ - 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); - - if (daemonize) { - log=fopen(logfile,"a"); - fprintf(log,"%s\n",msg); - fclose(log); - } else - printf("%s\n",msg); - - /* This is for CGI scripts */ - putenv(env_addr); - putenv(env_host); -} - -/* - * We have a connection. Identify what type of request GET, HEAD, CGI, etc - * and do what needs to be done - */ -static void -http_request(void) -{ - int fd, lg, i; - int cmd = 0; - char *p, *par; - const char *filename, *c, *ext, *type; - struct stat file_status; - char req[1024]; - char buff[8192]; - - lg = read(con_sock, req, 1024); - - if ((p=strstr(req,"\n"))) *p=0; - if ((p=strstr(req,"\r"))) *p=0; - - log_line(req); - - c = strtok(req, " "); - - /* Error msg if request is nothing */ - if (c == NULL) { - http_output(http_404[0]); - http_output(http_404[1]); - goto end_request; - } - - if (strncmp(c, "GET", 3) == 0) cmd = 1; - if (strncmp(c, "HEAD", 4) == 0) cmd = 2; - - /* Do error msg for any other type of request */ - if (cmd == 0) { - http_output(http_405[0]); - http_output(http_405[1]); - goto end_request; - } - - filename = strtok(NULL, " "); - - c = strtok(NULL, " "); - if (fetch_mode != NULL) filename=fetch_mode; - if (filename == NULL || - strlen(filename)==1) filename="/index.html"; - - 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");*/ - printf("HTTP/1.0 200 OK\r\n"); - /* Plug in environment variable, others in log_line */ - setenv("SERVER_SOFTWARE", "FreeBSD/PicoBSD", 1); - - execlp (filename,filename,par,(char *)0); - } - wait(&i); - return; - } - conti: - if (filename == NULL) { - http_output(http_405[0]); - http_output(http_405[1]); - goto end_request; - } - /* End of CGI handling */ - - /* Reject any request with '..' in it, bad hacker */ - c = filename; - while (*c != '\0') - if (c[0] == '.' && c[1] == '.') { - http_output(http_404[0]); - http_output(http_404[1]); - goto end_request; - } else - c++; - - /* Open filename */ - fd = open(filename, O_RDONLY); - if (fd < 0) { - http_output(http_404[0]); - http_output(http_404[1]); - goto end_request; - } - - /* Get file status information */ - if (fstat(fd, &file_status) < 0) { - http_output(http_404[0]); - http_output(http_404[1]); - goto end_request2; - } - - /* Is it a regular file? */ - if (!S_ISREG(file_status.st_mode)) { - http_output(http_404[0]); - 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); - http_output(httpd_server_ident); - http_date(); - - sprintf(buff, "Content-length: %jd\r\n", (intmax_t)file_status.st_size); - write(con_sock, buff, strlen(buff)); - - strcpy(buff, "Content-type: "); - type = default_mime_type; - if ((ext = strrchr(filename, '.')) != NULL) { - for (i = mime_type_max; i >= 0; i--) - if (strcmp(ext + 1, mime_type[i][0]) == 0) { - type = mime_type[i][1]; - break; - } - } - strcat(buff, type); - http_output(buff); - - strftime(buff, 50, "Last-Modified: %a, %d %h %Y %H:%M:%S %Z\r\n\r\n", gmtime(&file_status.st_mtime)); - write(con_sock, buff, strlen(buff)); - - /* Send data only if GET request */ - if (cmd == 1) { - while ((lg = read(fd, buff, 8192)) > 0) - write(con_sock, buff, lg); - } - -end_request2: - close(fd); -end_request: - close(con_sock); - -} - -/* - * Simple httpd server for use in PicoBSD or other embedded application. - * Should satisfy simple httpd needs. For more demanding situations - * apache is probably a better (but much larger) choice. - */ -int -main(int argc, char *argv[]) -{ - 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"); - - /* Defaults for log file */ - if (geteuid()) { - strcpy(logfile,getenv("HOME")); - strcat(logfile,"/"); - strcat(logfile,"jhttp.log"); - } else - strcpy(logfile,"/var/log/jhttpd.log"); - - /* Parse command line arguments */ - while ((ch = getopt(argc, argv, "d:f:g:l:p:vDh")) != -1) - switch (ch) { - case 'd': - strcpy(homedir,optarg); - break; - case 'f': - daemonize = 0; - verbose = 1; - fetch_mode = optarg; - break; - case 'g': - httpd_group = atoi(optarg); - break; - case 'l': - strcpy(logfile,optarg); - break; - case 'p': - http_port = atoi(optarg); - break; - case 'v': - verbose = 1; - break; - case 'D': - daemonize = 0; - break; - case '?': - case 'h': - default: - 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()) { - http_port = 1080; - } - - /* Do we really have rights in the html directory? */ - if (fetch_mode == NULL) { - if (chdir(homedir)) { - perror("chdir"); - puts(homedir); - exit(1); - } - } - - /* Create log file if it doesn't exit */ - if ((access(logfile,W_OK)) && daemonize) { - ld = open (logfile,O_WRONLY); - chmod (logfile,00600); - close(ld); - } - - init_servconnection(); - - if (verbose) { - printf("Server started with options \n"); - printf("port: %d\n",http_port); - if (fetch_mode == NULL) printf("html home: %s\n",homedir); - if (daemonize) printf("logfile: %s\n",logfile); - } - - /* httpd is spawned */ - if (daemonize) { - if ((server_pid = fork()) != 0) { - wait3(0,WNOHANG,0); - if (verbose) printf("pid: %d\n",server_pid); - exit(0); - } - wait3(0,WNOHANG,0); - } - - 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); - - label: - wait_connection(); - - if (fork()) { - wait3(0,WNOHANG,0); - close(con_sock); - goto label; - } - - http_request(); - - wait3(0,WNOHANG,0); - exit(0); -} - - -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; -} Property changes on: head/release/picobsd/tinyware/simple_httpd/simple_httpd.c ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: head/release/picobsd/tinyware/simple_httpd/README =================================================================== --- head/release/picobsd/tinyware/simple_httpd/README (revision 352926) +++ head/release/picobsd/tinyware/simple_httpd/README (nonexistent) @@ -1,167 +0,0 @@ -Simple_httpd - A small and free Web server - -"Simple_httpd is like /usr/bin/mail is to mail clients, no frills." - -This HTTP server can be used in any FreeBSD/PicoBSD application. - -It has been tested under FreeBSD 2.2.x, 3.x and 4.x. It might work -on other OS systems, but it's for FreeBSD primarily. - -The main advantage to Simple_httpd is that it is very small. -The 25K binary can satisfy most needs in a small or embedded -appplication. If you want a full featured server see -/usr/ports/www/apache* or http://www.apache.org - -Simple_httpd is released under a BSD style copyright that unlike -GPL is embedded developer friendly. - -The server is designed to be run in one of two modes. The standard -mode is a httpd server running in the background serving up a directory -of html,gif,cgi whatever. Your traditional www server. - -The "fetch" mode supports file transfer over httpd. This -is best thought of as mate for fetch(1). This feature can be -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 environment variables before calling -the script. - -CGI Environment variables are below: - -SERVER_SOFTWARE = FreeBSD/PicoBSD -REMOTE_HOST = client.canada_lower_taxes.com -REMOTE_ADDR = 200.122.13.108 - -In most target applications for this server the extra DNS traffic from -the remote_addr lookup will likely be on the local lan anyway and not -on the other side of the internet. You can turn it off yourself in -the code if you want to speed the whole process up. Be sure to turn -it off for the logfile also. - -How to use it? -============== - -Compile with make, run as follows - -usage: simple_httpd [-vD] - [-d directory] - [-g grpid] - [-l logfile] - [-p port] -or -usage: simple_httpd [-p port] -f filename - --v -Run the server verbose. Show the program options that will be used for this -process. Will only show information during startup, no messages will -be displayed while serving requests. In other words you can still -daemonize without fear of output on stdout. - --D -Do not daemonize. The server will not run in the background. It will -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. - --d directory -The html document directory, if nothing is provided the default is -/httphome if UID is root, otherwise document root is ${HOME}/public_html - --l logfile -Set the logfile to use. Log messages will be written to /var/log/jhttpd.log -if you are root and ${HOME}/jhttpd.log otherwise. If you don't want a -log file try "-l /dev/null" - --p port -Set the port httpd server will listen to. Default is port 80 if -you are root and 1080 if you are not. - --f filename -This is the only option needed to use the "fetch" feature. The file -specified will be the ONLY file served to ANY GET request from a browser -or fetch(1). - -Example -======= - -Standard Mode: --------------- -If you have the FreeBSD handbook installed on your machine and would -like to serve it up over http for a quick look you could do this - -simple_httpd -d /usr/share/doc/handbook -l /usr/tmp/jlog.txt -p 1088 -v - -Any browser would be able to look at the handbook with -http://whatever_host/handbook.html:1088 - -I'm using 1088 as the port since I already have apache running on port 80 -and port 1080 on my host. - -Please note, the handbook is not installed by default in FreeBSD 3.x -It must be installed from the ports collection first if you want to -try this. - -Another simple example is to browse your local ports collection: - -cd /usr/ports -make readmes #wait about 1 hour! -simple_httpd -p 1080 -v -d /usr/ports - -Then point your browser at http://whatever_host/README.html - -Fetch Mode: --------------- -This is designed to be used in conjunction with fetch(3). It allows -for easy transfer of files from one host to another without messy -authentication or pathnames required with ftp. The file to be -served up must be readable by the user running simple_httpd. -This is not a magic way to avoid permissions and read files. - -The daemon will only serve up ONE file. The file specified will -be returned for every GET request regardless of what the browser -asks for. This allows for on the fly naming. - -sender# simple_httpd -f /usr/tmp/big_file.tgz -receiver# fetch http://sender.com/Industrial_Secrets.tgz - -big_file.tgz was transferred from one machine to another and renamed -Industrial_Secrets.tgz at the same time. - -Tunneling over other TCP ports. Choose something that firewall -will probably pass. See /etc/services. - -sender# simple_httpd -p 53 -f /usr/tmp/big_file.tgz -receiver# fetch http://sender.com:53/Industrial_Secrets.tgz - -To Do -===== - -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 -probably want to restrict traffic to local ethernet anyway. -ie: Allow anything from my class C. - -The server always has 1 zombie process hanging around when it -runs as a daemon. Should fix so that it doesn't happen. - -Anything to make it faster! - -Man page - -If anyone has any improvements or ways to easily implement something -please let me know. If you make some neat embedded -device with PicoBSD I want to know too! - -Credits -======= - -This program was originally contributed by Marc Nicholas - -Major rewrite by William Lloyd - -$FreeBSD$ Property changes on: head/release/picobsd/tinyware/simple_httpd/README ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: head/release/picobsd/tinyware/simple_httpd/Makefile =================================================================== --- head/release/picobsd/tinyware/simple_httpd/Makefile (revision 352926) +++ head/release/picobsd/tinyware/simple_httpd/Makefile (nonexistent) @@ -1,8 +0,0 @@ -# $FreeBSD$ -# -PROG=simple_httpd -SRCS= simple_httpd.c -MAN= -WARNS?=6 - -.include Property changes on: head/release/picobsd/tinyware/simple_httpd/Makefile ___________________________________________________________________ Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Index: head/share/mk/src.opts.mk =================================================================== --- head/share/mk/src.opts.mk (revision 352926) +++ head/share/mk/src.opts.mk (revision 352927) @@ -1,596 +1,597 @@ # $FreeBSD$ # # Option file for FreeBSD /usr/src builds. # # Users define WITH_FOO and WITHOUT_FOO on the command line or in /etc/src.conf # and /etc/make.conf files. These translate in the build system to MK_FOO={yes,no} # with sensible (usually) defaults. # # Makefiles must include bsd.opts.mk after defining specific MK_FOO options that # are applicable for that Makefile (typically there are none, but sometimes there # are exceptions). Recursive makes usually add MK_FOO=no for options that they wish # to omit from that make. # # Makefiles must include bsd.mkopt.mk before they test the value of any MK_FOO # variable. # # Makefiles may also assume that this file is included by src.opts.mk should it # need variables defined there prior to the end of the Makefile where # bsd.{subdir,lib.bin}.mk is traditionally included. # # The old-style YES_FOO and NO_FOO are being phased out. No new instances of them # should be added. Old instances should be removed since they were just to # bridge the gap between FreeBSD 4 and FreeBSD 5. # # Makefiles should never test WITH_FOO or WITHOUT_FOO directly (although an # exception is made for _WITHOUT_SRCONF which turns off this mechanism # completely inside bsd.*.mk files). # .if !target(____) ____: .include # # Define MK_* variables (which are either "yes" or "no") for users # to set via WITH_*/WITHOUT_* in /etc/src.conf and override in the # make(1) environment. # These should be tested with `== "no"' or `!= "no"' in makefiles. # The NO_* variables should only be set by makefiles for variables # that haven't been converted over. # # These options are used by the src builds. Those listed in # __DEFAULT_YES_OPTIONS default to 'yes' and will build unless turned # off. __DEFAULT_NO_OPTIONS will default to 'no' and won't build # unless turned on. Any options listed in 'BROKEN_OPTIONS' will be # hard-wired to 'no'. "Broken" here means not working or # not-appropriate and/or not supported. It doesn't imply something is # wrong with the code. There's not a single good word for this, so # BROKEN was selected as the least imperfect one considered at the # time. Options are added to BROKEN_OPTIONS list on a per-arch basis. # At this time, there's no provision for mutually incompatible options. __DEFAULT_YES_OPTIONS = \ ACCT \ ACPI \ AMD \ APM \ AT \ ATM \ AUDIT \ AUTHPF \ AUTOFS \ BHYVE \ BINUTILS \ BINUTILS_BOOTSTRAP \ BLACKLIST \ BLUETOOTH \ BOOT \ BOOTPARAMD \ BOOTPD \ BSD_CPIO \ BSD_CRTBEGIN \ BSDINSTALL \ BSNMP \ BZIP2 \ CALENDAR \ CAPSICUM \ CASPER \ CCD \ CDDL \ CPP \ CROSS_COMPILER \ CRYPT \ CUSE \ CXX \ CXGBETOOL \ DIALOG \ DICT \ DMAGENT \ DYNAMICROOT \ EE \ EFI \ ELFTOOLCHAIN_BOOTSTRAP \ EXAMPLES \ FDT \ FILE \ FINGER \ FLOPPY \ FMTREE \ FORTH \ FP_LIBC \ FREEBSD_UPDATE \ FTP \ GAMES \ GCOV \ GDB \ GNU_DIFF \ GNU_GREP \ GPIO \ HAST \ HTML \ HYPERV \ ICONV \ INET \ INET6 \ INETD \ IPFILTER \ IPFW \ ISCSI \ JAIL \ KDUMP \ KVM \ LDNS \ LDNS_UTILS \ LEGACY_CONSOLE \ LIB32 \ LIBPTHREAD \ LIBTHR \ LLVM_COV \ LOADER_GELI \ LOADER_LUA \ LOADER_OFW \ LOADER_UBOOT \ LOCALES \ LOCATE \ LPR \ LS_COLORS \ LZMA_SUPPORT \ MAIL \ MAILWRAPPER \ MAKE \ MLX5TOOL \ NDIS \ NETCAT \ NETGRAPH \ NLS_CATALOGS \ NS_CACHING \ NTP \ NVME \ OFED \ OPENSSL \ PAM \ PF \ PKGBOOTSTRAP \ PMC \ PORTSNAP \ PPP \ QUOTAS \ RADIUS_SUPPORT \ RBOOTD \ RESCUE \ ROUTED \ SENDMAIL \ SERVICESDB \ SETUID_LOGIN \ SHAREDOCS \ SOURCELESS \ SOURCELESS_HOST \ SOURCELESS_UCODE \ SVNLITE \ SYSCONS \ SYSTEM_COMPILER \ SYSTEM_LINKER \ TALK \ TCP_WRAPPERS \ TCSH \ TELNET \ TEXTPROC \ TFTP \ UNBOUND \ USB \ UTMPX \ VI \ VT \ WIRELESS \ WPA_SUPPLICANT_EAPOL \ ZFS \ LOADER_ZFS \ ZONEINFO __DEFAULT_NO_OPTIONS = \ BEARSSL \ BSD_GREP \ CLANG_EXTRAS \ DTRACE_TESTS \ EXPERIMENTAL \ GNU_GREP_COMPAT \ HESIOD \ + HTTPD \ LIBSOFT \ LOADER_FIREWIRE \ LOADER_FORCE_LE \ LOADER_VERBOSE \ LOADER_VERIEXEC_PASS_MANIFEST \ OFED_EXTRA \ OPENLDAP \ REPRODUCIBLE_BUILD \ RPCBIND_WARMSTART_SUPPORT \ SHARED_TOOLCHAIN \ SORT_THREADS \ SVN \ ZONEINFO_LEAPSECONDS_SUPPORT \ ZONEINFO_OLD_TIMEZONES_SUPPORT \ # LEFT/RIGHT. Left options which default to "yes" unless their corresponding # RIGHT option is disabled. __DEFAULT_DEPENDENT_OPTIONS= \ CLANG_FULL/CLANG \ LLVM_TARGET_ALL/CLANG \ LOADER_VERIEXEC/BEARSSL \ LOADER_EFI_SECUREBOOT/LOADER_VERIEXEC \ VERIEXEC/BEARSSL \ # MK_*_SUPPORT options which default to "yes" unless their corresponding # MK_* variable is set to "no". # .for var in \ BLACKLIST \ BZIP2 \ INET \ INET6 \ KERBEROS \ KVM \ NETGRAPH \ PAM \ TESTS \ WIRELESS __DEFAULT_DEPENDENT_OPTIONS+= ${var}_SUPPORT/${var} .endfor # # Default behaviour of some options depends on the architecture. Unfortunately # this means that we have to test TARGET_ARCH (the buildworld case) as well # as MACHINE_ARCH (the non-buildworld case). Normally TARGET_ARCH is not # used at all in bsd.*.mk, but we have to make an exception here if we want # to allow defaults for some things like clang to vary by target architecture. # Additional, per-target behavior should be rarely added only after much # gnashing of teeth and grinding of gears. # .if defined(TARGET_ARCH) __T=${TARGET_ARCH} .else __T=${MACHINE_ARCH} .endif .if defined(TARGET) __TT=${TARGET} .else __TT=${MACHINE} .endif # Default GOOGLETEST to off for MIPS while LLVM PR 43263 is active. Part # of the fusefs tests trigger excessively long compile times. It does # eventually succeed, but this shouldn't be forced on those building by default. .if ${__TT} == "mips" __DEFAULT_NO_OPTIONS+= GOOGLETEST .else __DEFAULT_YES_OPTIONS+= GOOGLETEST .endif # All supported backends for LLVM_TARGET_XXX __LLVM_TARGETS= \ aarch64 \ arm \ mips \ powerpc \ sparc \ x86 __LLVM_TARGET_FILT= C/(amd64|i386)/x86/:S/sparc64/sparc/:S/arm64/aarch64/:S/powerpc64/powerpc/ .for __llt in ${__LLVM_TARGETS} # Default the given TARGET's LLVM_TARGET support to the value of MK_CLANG. .if ${__TT:${__LLVM_TARGET_FILT}} == ${__llt} __DEFAULT_DEPENDENT_OPTIONS+= LLVM_TARGET_${__llt:${__LLVM_TARGET_FILT}:tu}/CLANG # Disable other targets for arm and armv6, to work around "relocation truncated # to fit" errors with BFD ld, since libllvm.a will get too large to link. .elif ${__T} == "arm" || ${__T} == "armv6" __DEFAULT_NO_OPTIONS+=LLVM_TARGET_${__llt:tu} # aarch64 needs arm for -m32 support. .elif ${__TT} == "arm64" && ${__llt} == "arm" __DEFAULT_DEPENDENT_OPTIONS+= LLVM_TARGET_ARM/LLVM_TARGET_AARCH64 # Default the rest of the LLVM_TARGETs to the value of MK_LLVM_TARGET_ALL # which is based on MK_CLANG. .else __DEFAULT_DEPENDENT_OPTIONS+= LLVM_TARGET_${__llt:${__LLVM_TARGET_FILT}:tu}/LLVM_TARGET_ALL .endif .endfor __DEFAULT_NO_OPTIONS+=LLVM_TARGET_BPF __DEFAULT_NO_OPTIONS+=LLVM_TARGET_RISCV .include # If the compiler is not C++11 capable, disable Clang and use GCC instead. # This means that architectures that have GCC 4.2 as default can not # build Clang without using an external compiler. .if ${COMPILER_FEATURES:Mc++11} && (${__T} == "aarch64" || \ ${__T} == "amd64" || ${__TT} == "arm" || ${__T} == "i386") # Clang is enabled, and will be installed as the default /usr/bin/cc. __DEFAULT_YES_OPTIONS+=CLANG CLANG_BOOTSTRAP CLANG_IS_CC LLD __DEFAULT_NO_OPTIONS+=GCC GCC_BOOTSTRAP GNUCXX GPL_DTC .elif ${COMPILER_FEATURES:Mc++11} && ${__T:Mriscv*} == "" && ${__T} != "sparc64" # If an external compiler that supports C++11 is used as ${CC} and Clang # supports the target, then Clang is enabled but GCC is installed as the # default /usr/bin/cc. __DEFAULT_YES_OPTIONS+=CLANG GCC GCC_BOOTSTRAP GNUCXX GPL_DTC LLD __DEFAULT_NO_OPTIONS+=CLANG_BOOTSTRAP CLANG_IS_CC .else # Everything else disables Clang, and uses GCC instead. __DEFAULT_YES_OPTIONS+=GCC GCC_BOOTSTRAP GNUCXX GPL_DTC __DEFAULT_NO_OPTIONS+=CLANG CLANG_BOOTSTRAP CLANG_IS_CC LLD .endif # In-tree binutils/gcc are older versions without modern architecture support. .if ${__T} == "aarch64" || ${__T:Mriscv*} != "" BROKEN_OPTIONS+=BINUTILS BINUTILS_BOOTSTRAP GCC GCC_BOOTSTRAP GDB .endif .if ${__T:Mriscv*} != "" BROKEN_OPTIONS+=OFED .endif .if ${__T} == "aarch64" || ${__T} == "amd64" || ${__T} == "i386" || \ ${__T:Mriscv*} != "" || ${__TT} == "mips" __DEFAULT_YES_OPTIONS+=LLVM_LIBUNWIND .else __DEFAULT_NO_OPTIONS+=LLVM_LIBUNWIND .endif .if ${__T} == "aarch64" || ${__T} == "amd64" || ${__T} == "armv7" || \ ${__T} == "i386" __DEFAULT_YES_OPTIONS+=LLD_BOOTSTRAP LLD_IS_LD .else __DEFAULT_NO_OPTIONS+=LLD_BOOTSTRAP LLD_IS_LD .endif .if ${__T} == "aarch64" || ${__T} == "amd64" || ${__T} == "i386" __DEFAULT_YES_OPTIONS+=LLDB .else __DEFAULT_NO_OPTIONS+=LLDB .endif # LLVM lacks support for FreeBSD 64-bit atomic operations for ARMv4/ARMv5 .if ${__T} == "arm" BROKEN_OPTIONS+=LLDB .endif # GDB in base is generally less functional than GDB in ports. Ports GDB # sparc64 kernel support has not been tested. .if ${__T} == "sparc64" __DEFAULT_NO_OPTIONS+=GDB_LIBEXEC .else __DEFAULT_YES_OPTIONS+=GDB_LIBEXEC .endif # Only doing soft float API stuff on armv6 and armv7 .if ${__T} != "armv6" && ${__T} != "armv7" BROKEN_OPTIONS+=LIBSOFT .endif .if ${__T:Mmips*} BROKEN_OPTIONS+=SSP .endif # EFI doesn't exist on mips, powerpc, sparc or riscv. .if ${__T:Mmips*} || ${__T:Mpowerpc*} || ${__T:Msparc64} || ${__T:Mriscv*} BROKEN_OPTIONS+=EFI .endif # OFW is only for powerpc and sparc64, exclude others .if ${__T:Mpowerpc*} == "" && ${__T:Msparc64} == "" BROKEN_OPTIONS+=LOADER_OFW .endif # UBOOT is only for arm, mips and powerpc, exclude others .if ${__T:Marm*} == "" && ${__T:Mmips*} == "" && ${__T:Mpowerpc*} == "" BROKEN_OPTIONS+=LOADER_UBOOT .endif # GELI and Lua in loader currently cause boot failures on sparc64 and powerpc. # Further debugging is required -- probably they are just broken on big # endian systems generically (they jump to null pointers or try to read # crazy high addresses, which is typical of endianness problems). .if ${__T} == "sparc64" || ${__T:Mpowerpc*} BROKEN_OPTIONS+=LOADER_GELI LOADER_LUA .endif .if ${__T:Mmips64*} # profiling won't work on MIPS64 because there is only assembly for o32 BROKEN_OPTIONS+=PROFILE .endif .if ${__T} != "aarch64" && ${__T} != "amd64" && ${__T} != "i386" && \ ${__T} != "powerpc64" && ${__T} != "sparc64" BROKEN_OPTIONS+=CXGBETOOL BROKEN_OPTIONS+=MLX5TOOL .endif # HyperV is currently x86-only .if ${__T} != "amd64" && ${__T} != "i386" BROKEN_OPTIONS+=HYPERV .endif # NVME is only aarch64, x86 and powerpc64 .if ${__T} != "aarch64" && ${__T} != "amd64" && ${__T} != "i386" && ${__T} != "powerpc64" BROKEN_OPTIONS+=NVME .endif # Sparc64 need extra crt*.o files .if ${__T:Msparc64} BROKEN_OPTIONS+=BSD_CRTBEGIN .endif .if ${COMPILER_FEATURES:Mc++11} && (${__T} == "amd64" || ${__T} == "i386") __DEFAULT_YES_OPTIONS+=OPENMP .else __DEFAULT_NO_OPTIONS+=OPENMP .endif .include # # MK_* options that default to "yes" if the compiler is a C++11 compiler. # .for var in \ LIBCPLUSPLUS .if !defined(MK_${var}) .if ${COMPILER_FEATURES:Mc++11} .if defined(WITHOUT_${var}) MK_${var}:= no .else MK_${var}:= yes .endif .else .if defined(WITH_${var}) MK_${var}:= yes .else MK_${var}:= no .endif .endif .endif .endfor # # Force some options off if their dependencies are off. # Order is somewhat important. # .if !${COMPILER_FEATURES:Mc++11} MK_GOOGLETEST:= no MK_LLVM_LIBUNWIND:= no .endif .if ${MK_CAPSICUM} == "no" MK_CASPER:= no .endif .if ${MK_LIBPTHREAD} == "no" MK_LIBTHR:= no .endif .if ${MK_LDNS} == "no" MK_LDNS_UTILS:= no MK_UNBOUND:= no .endif .if ${MK_SOURCELESS} == "no" MK_SOURCELESS_HOST:= no MK_SOURCELESS_UCODE:= no .endif .if ${MK_CDDL} == "no" MK_ZFS:= no MK_LOADER_ZFS:= no MK_CTF:= no .endif .if ${MK_CRYPT} == "no" MK_OPENSSL:= no MK_OPENSSH:= no MK_KERBEROS:= no .endif .if ${MK_CXX} == "no" MK_CLANG:= no MK_GNUCXX:= no MK_TESTS:= no .endif .if ${MK_DIALOG} == "no" MK_BSDINSTALL:= no .endif .if ${MK_MAIL} == "no" MK_MAILWRAPPER:= no MK_SENDMAIL:= no MK_DMAGENT:= no .endif .if ${MK_NETGRAPH} == "no" MK_ATM:= no MK_BLUETOOTH:= no .endif .if ${MK_NLS} == "no" MK_NLS_CATALOGS:= no .endif .if ${MK_OPENSSL} == "no" MK_OPENSSH:= no MK_KERBEROS:= no .endif .if ${MK_PF} == "no" MK_AUTHPF:= no .endif .if ${MK_OFED} == "no" MK_OFED_EXTRA:= no .endif .if ${MK_PORTSNAP} == "no" # freebsd-update depends on phttpget from portsnap MK_FREEBSD_UPDATE:= no .endif .if ${MK_TESTS} == "no" MK_DTRACE_TESTS:= no .endif .if ${MK_TESTS_SUPPORT} == "no" MK_GOOGLETEST:= no .endif .if ${MK_ZONEINFO} == "no" MK_ZONEINFO_LEAPSECONDS_SUPPORT:= no MK_ZONEINFO_OLD_TIMEZONES_SUPPORT:= no .endif .if ${MK_CROSS_COMPILER} == "no" MK_BINUTILS_BOOTSTRAP:= no MK_CLANG_BOOTSTRAP:= no MK_ELFTOOLCHAIN_BOOTSTRAP:= no MK_GCC_BOOTSTRAP:= no MK_LLD_BOOTSTRAP:= no .endif .if ${MK_TOOLCHAIN} == "no" MK_BINUTILS:= no MK_CLANG:= no MK_GCC:= no MK_GDB:= no MK_INCLUDES:= no MK_LLD:= no MK_LLDB:= no .endif .if ${MK_CLANG} == "no" MK_CLANG_EXTRAS:= no MK_CLANG_FULL:= no MK_LLVM_COV:= no .endif .if ${MK_LOADER_VERIEXEC} == "no" MK_LOADER_VERIEXEC_PASS_MANIFEST := no .endif # # MK_* options whose default value depends on another option. # .for vv in \ GSSAPI/KERBEROS \ MAN_UTILS/MAN .if defined(WITH_${vv:H}) MK_${vv:H}:= yes .elif defined(WITHOUT_${vv:H}) MK_${vv:H}:= no .else MK_${vv:H}:= ${MK_${vv:T}} .endif .endfor # # Set defaults for the MK_*_SUPPORT variables. # .if !${COMPILER_FEATURES:Mc++11} MK_LLDB:= no .endif # gcc 4.8 and newer supports libc++, so suppress gnuc++ in that case. # while in theory we could build it with that, we don't want to do # that since it creates too much confusion for too little gain. # XXX: This is incomplete and needs X_COMPILER_TYPE/VERSION checks too # to prevent Makefile.inc1 from bootstrapping unneeded dependencies # and to support 'make delete-old' when supplying an external toolchain. .if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40800 MK_GNUCXX:=no MK_GCC:=no .endif .endif # !target(____) Index: head/tools/build/options/WITHOUT_HTTPD =================================================================== --- head/tools/build/options/WITHOUT_HTTPD (nonexistent) +++ head/tools/build/options/WITHOUT_HTTPD (revision 352927) @@ -0,0 +1,2 @@ +.\" $FreeBSD$ +Set to neither build nor install httpd Property changes on: head/tools/build/options/WITHOUT_HTTPD ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/options/WITH_HTTPD =================================================================== --- head/tools/build/options/WITH_HTTPD (nonexistent) +++ head/tools/build/options/WITH_HTTPD (revision 352927) @@ -0,0 +1,2 @@ +.\" $FreeBSD$ +Set to build and install httpd Property changes on: head/tools/build/options/WITH_HTTPD ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/usr.sbin/Makefile =================================================================== --- head/usr.sbin/Makefile (revision 352926) +++ head/usr.sbin/Makefile (revision 352927) @@ -1,222 +1,223 @@ # From: @(#)Makefile 5.20 (Berkeley) 6/12/93 # $FreeBSD$ .include SUBDIR= adduser \ arp \ binmiscctl \ camdd \ cdcontrol \ chkgrp \ chown \ chroot \ ckdist \ clear_locks \ crashinfo \ cron \ ctladm \ ctld \ daemon \ dconschat \ devctl \ devinfo \ diskinfo \ dumpcis \ etcupdate \ extattr \ extattrctl \ fifolog \ fstyp \ fwcontrol \ getfmac \ getpmac \ gstat \ i2c \ ifmcstat \ iostat \ iovctl \ kldxref \ mailwrapper \ makefs \ memcontrol \ mergemaster \ mfiutil \ mixer \ mlxcontrol \ mountd \ mount_smbfs \ mpsutil \ mptutil \ mtest \ newsyslog \ nfscbd \ nfsd \ nfsdumpstate \ nfsrevoke \ nfsuserd \ nmtree \ nologin \ pciconf \ periodic \ pnfsdscopymr \ pnfsdsfile \ pnfsdskill \ powerd \ prometheus_sysctl_exporter \ pstat \ pw \ pwd_mkdb \ pwm \ quot \ rarpd \ rmt \ rpcbind \ rpc.lockd \ rpc.statd \ rpc.umntall \ rtprio \ rwhod \ service \ services_mkdb \ sesutil \ setfib \ setfmac \ setpmac \ smbmsg \ snapinfo \ spi \ spray \ syslogd \ sysrc \ tcpdrop \ tcpdump \ traceroute \ trim \ trpt \ tzsetup \ ugidfw \ vigr \ vipw \ wake \ watch \ watchdogd \ zic \ zonectl # NB: keep these sorted by MK_* knobs SUBDIR.${MK_ACCT}+= accton SUBDIR.${MK_ACCT}+= sa SUBDIR.${MK_AMD}+= amd SUBDIR.${MK_AUDIT}+= audit SUBDIR.${MK_AUDIT}+= auditd .if ${MK_OPENSSL} != "no" SUBDIR.${MK_AUDIT}+= auditdistd .endif SUBDIR.${MK_AUDIT}+= auditreduce SUBDIR.${MK_AUDIT}+= praudit SUBDIR.${MK_AUTHPF}+= authpf SUBDIR.${MK_AUTOFS}+= autofs SUBDIR.${MK_BLACKLIST}+= blacklistctl SUBDIR.${MK_BLACKLIST}+= blacklistd SUBDIR.${MK_BLUETOOTH}+= bluetooth SUBDIR.${MK_BOOTPARAMD}+= bootparamd SUBDIR.${MK_BSDINSTALL}+= bsdinstall SUBDIR.${MK_BSNMP}+= bsnmpd SUBDIR.${MK_CXGBETOOL}+= cxgbetool SUBDIR.${MK_DIALOG}+= bsdconfig SUBDIR.${MK_EFI}+= efivar efidp efibootmgr .if ${MK_OPENSSL} != "no" SUBDIR.${MK_EFI}+= uefisign .endif SUBDIR.${MK_FLOPPY}+= fdcontrol SUBDIR.${MK_FLOPPY}+= fdformat SUBDIR.${MK_FLOPPY}+= fdread SUBDIR.${MK_FLOPPY}+= fdwrite SUBDIR.${MK_FMTREE}+= fmtree SUBDIR.${MK_FREEBSD_UPDATE}+= freebsd-update SUBDIR.${MK_GSSAPI}+= gssd SUBDIR.${MK_GPIO}+= gpioctl +SUBDIR.${MK_HTTPD}+= httpd SUBDIR.${MK_INET6}+= ip6addrctl SUBDIR.${MK_INET6}+= mld6query SUBDIR.${MK_INET6}+= ndp SUBDIR.${MK_INET6}+= rip6query SUBDIR.${MK_INET6}+= route6d SUBDIR.${MK_INET6}+= rrenumd SUBDIR.${MK_INET6}+= rtadvctl SUBDIR.${MK_INET6}+= rtadvd SUBDIR.${MK_INET6}+= rtsold SUBDIR.${MK_INET6}+= traceroute6 SUBDIR.${MK_INETD}+= inetd SUBDIR.${MK_IPFW}+= ipfwpcap SUBDIR.${MK_ISCSI}+= iscsid SUBDIR.${MK_JAIL}+= jail SUBDIR.${MK_JAIL}+= jexec SUBDIR.${MK_JAIL}+= jls # XXX MK_SYSCONS SUBDIR.${MK_LEGACY_CONSOLE}+= kbdcontrol SUBDIR.${MK_LEGACY_CONSOLE}+= kbdmap SUBDIR.${MK_LEGACY_CONSOLE}+= moused SUBDIR.${MK_LEGACY_CONSOLE}+= vidcontrol .if ${MK_LIBTHR} != "no" || ${MK_LIBPTHREAD} != "no" SUBDIR.${MK_PPP}+= pppctl SUBDIR.${MK_NS_CACHING}+= nscd .endif SUBDIR.${MK_LPR}+= lpr SUBDIR.${MK_MAN_UTILS}+= manctl SUBDIR.${MK_MLX5TOOL}+= mlx5tool SUBDIR.${MK_NETGRAPH}+= flowctl SUBDIR.${MK_NETGRAPH}+= ngctl SUBDIR.${MK_NETGRAPH}+= nghook SUBDIR.${MK_NIS}+= rpc.yppasswdd SUBDIR.${MK_NIS}+= rpc.ypupdated SUBDIR.${MK_NIS}+= rpc.ypxfrd SUBDIR.${MK_NIS}+= ypbind SUBDIR.${MK_NIS}+= ypldap SUBDIR.${MK_NIS}+= yp_mkdb SUBDIR.${MK_NIS}+= yppoll SUBDIR.${MK_NIS}+= yppush SUBDIR.${MK_NIS}+= ypserv SUBDIR.${MK_NIS}+= ypset SUBDIR.${MK_NTP}+= ntp SUBDIR.${MK_OPENSSL}+= keyserv SUBDIR.${MK_PF}+= ftp-proxy SUBDIR.${MK_PKGBOOTSTRAP}+= pkg .if ${COMPILER_FEATURES:Mc++11} SUBDIR.${MK_PMC}+= pmc .endif SUBDIR.${MK_PMC}+= pmcannotate pmccontrol pmcstat pmcstudy SUBDIR.${MK_PORTSNAP}+= portsnap SUBDIR.${MK_PPP}+= ppp SUBDIR.${MK_QUOTAS}+= edquota SUBDIR.${MK_QUOTAS}+= quotaon SUBDIR.${MK_QUOTAS}+= repquota SUBDIR.${MK_SENDMAIL}+= editmap SUBDIR.${MK_SENDMAIL}+= mailstats SUBDIR.${MK_SENDMAIL}+= makemap SUBDIR.${MK_SENDMAIL}+= praliases SUBDIR.${MK_SENDMAIL}+= sendmail SUBDIR.${MK_TCP_WRAPPERS}+= tcpdchk SUBDIR.${MK_TCP_WRAPPERS}+= tcpdmatch SUBDIR.${MK_TOOLCHAIN}+= config SUBDIR.${MK_TOOLCHAIN}+= crunch SUBDIR.${MK_UNBOUND}+= unbound SUBDIR.${MK_USB}+= uathload SUBDIR.${MK_USB}+= uhsoctl SUBDIR.${MK_USB}+= usbconfig SUBDIR.${MK_USB}+= usbdump SUBDIR.${MK_UTMPX}+= ac SUBDIR.${MK_UTMPX}+= lastlogin SUBDIR.${MK_UTMPX}+= utx SUBDIR.${MK_WIRELESS}+= ancontrol SUBDIR.${MK_WIRELESS}+= wlandebug SUBDIR.${MK_WIRELESS}+= wpa SUBDIR.${MK_TESTS}+= tests .include SUBDIR_PARALLEL= .include Index: head/usr.sbin/httpd/Makefile =================================================================== --- head/usr.sbin/httpd/Makefile (nonexistent) +++ head/usr.sbin/httpd/Makefile (revision 352927) @@ -0,0 +1,8 @@ +# $FreeBSD$ +# +PROG= httpd +SRCS= simple_httpd.c +MAN= +WARNS?=6 + +.include Property changes on: head/usr.sbin/httpd/Makefile ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/usr.sbin/httpd/simple_httpd.c =================================================================== --- head/usr.sbin/httpd/simple_httpd.c (nonexistent) +++ head/usr.sbin/httpd/simple_httpd.c (revision 352927) @@ -0,0 +1,501 @@ +/*- + * Simple_HTTPd v1.1 - a very small, barebones HTTP server + * + * Copyright (c) 1998-1999 Marc Nicholas + * All rights reserved. + * + * Major rewrite by William Lloyd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int http_port = 80; +static int daemonize = 1; +static int verbose = 0; +static int http_sock, con_sock; + +static const char *fetch_mode = NULL; +static char homedir[100]; +static char logfile[80]; +static char *adate(void); +static void init_servconnection(void); +static void http_date(void); +static void http_output(const char *html); +static void http_request(void); +static void log_line(char *req); +static void wait_connection(void); + +static struct hostent *hst; +static struct sockaddr_in source; + +/* HTTP basics */ +static char httpd_server_ident[] = "Server: FreeBSD/PicoBSD simple_httpd 1.1\r"; + +static char http_200[] = "HTTP/1.0 200 OK\r"; + +static const char *default_mime_type = "application/octet-stream"; + +static const char *mime_type[][2] = { + { "txt", "text/plain" }, + { "htm", "text/html" }, + { "html", "text/html" }, + { "gif", "image/gif" }, + { "jpg", "image/jpeg" }, + { "mp3", "audio/mpeg" } +}; + +static const int mime_type_max = sizeof(mime_type) / sizeof(mime_type[0]) - 1; + +/* Two parts, HTTP Header and then HTML */ +static const char *http_404[2] = + {"HTTP/1.0 404 Not found\r\n", +"Error

Error 404

\ +Not found - file doesn't exist or you do not have permission.\n\r\n" +}; + +static const char *http_405[2] = + {"HTTP/1.0 405 Method Not allowed\r\nAllow: GET,HEAD\r\n", +"Error

Error 405

\ +This server only supports GET and HEAD requests.\n\r\n" +}; + +/* + * Only called on initial invocation + */ +static void +init_servconnection(void) +{ + struct sockaddr_in server; + + /* Create a socket */ + http_sock = socket(AF_INET, SOCK_STREAM, 0); + if (http_sock < 0) { + perror("socket"); + exit(1); + } + server.sin_family = AF_INET; + server.sin_port = htons(http_port); + server.sin_addr.s_addr = INADDR_ANY; + if (bind(http_sock, (struct sockaddr *) & server, sizeof(server)) < 0) { + perror("bind socket"); + exit(1); + } + if (verbose) printf("simple_httpd:%d\n",http_port); +} + +/* + * Wait here until we see an incoming http request + */ +static void +wait_connection(void) +{ + socklen_t lg; + + lg = sizeof(struct sockaddr_in); + + con_sock = accept(http_sock, (struct sockaddr *) & source, &lg); + if (con_sock <= 0) { + perror("accept"); + exit(1); + } +} + +/* + * Print timestamp for HTTP HEAD and GET + */ +static void +http_date(void) +{ + time_t tl; + char buff[50]; + + tl = time(NULL); + strftime(buff, 50, "Date: %a, %d %h %Y %H:%M:%S %Z\r\n", gmtime(&tl)); + write(con_sock, buff, strlen(buff)); + /* return(buff); */ +} + +/* + * Send data to the open socket + */ +static void +http_output(const char *html) +{ + write(con_sock, html, strlen(html)); + write(con_sock, "\r\n", 2); +} + + +/* + * Create and write the log information to file + * Log file format is one line per entry + */ +static void +log_line(char *req) +{ + 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); + + /* If DNS hostname exists */ + 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); + + if (daemonize) { + log=fopen(logfile,"a"); + fprintf(log,"%s\n",msg); + fclose(log); + } else + printf("%s\n",msg); + + /* This is for CGI scripts */ + putenv(env_addr); + putenv(env_host); +} + +/* + * We have a connection. Identify what type of request GET, HEAD, CGI, etc + * and do what needs to be done + */ +static void +http_request(void) +{ + int fd, lg, i; + int cmd = 0; + char *p, *par; + const char *filename, *c, *ext, *type; + struct stat file_status; + char req[1024]; + char buff[8192]; + + lg = read(con_sock, req, 1024); + + if ((p=strstr(req,"\n"))) *p=0; + if ((p=strstr(req,"\r"))) *p=0; + + log_line(req); + + c = strtok(req, " "); + + /* Error msg if request is nothing */ + if (c == NULL) { + http_output(http_404[0]); + http_output(http_404[1]); + goto end_request; + } + + if (strncmp(c, "GET", 3) == 0) cmd = 1; + if (strncmp(c, "HEAD", 4) == 0) cmd = 2; + + /* Do error msg for any other type of request */ + if (cmd == 0) { + http_output(http_405[0]); + http_output(http_405[1]); + goto end_request; + } + + filename = strtok(NULL, " "); + + c = strtok(NULL, " "); + if (fetch_mode != NULL) filename=fetch_mode; + if (filename == NULL || + strlen(filename)==1) filename="/index.html"; + + 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");*/ + printf("HTTP/1.0 200 OK\r\n"); + /* Plug in environment variable, others in log_line */ + setenv("SERVER_SOFTWARE", "FreeBSD/PicoBSD", 1); + + execlp (filename,filename,par,(char *)0); + } + wait(&i); + return; + } + conti: + if (filename == NULL) { + http_output(http_405[0]); + http_output(http_405[1]); + goto end_request; + } + /* End of CGI handling */ + + /* Reject any request with '..' in it, bad hacker */ + c = filename; + while (*c != '\0') + if (c[0] == '.' && c[1] == '.') { + http_output(http_404[0]); + http_output(http_404[1]); + goto end_request; + } else + c++; + + /* Open filename */ + fd = open(filename, O_RDONLY); + if (fd < 0) { + http_output(http_404[0]); + http_output(http_404[1]); + goto end_request; + } + + /* Get file status information */ + if (fstat(fd, &file_status) < 0) { + http_output(http_404[0]); + http_output(http_404[1]); + goto end_request2; + } + + /* Is it a regular file? */ + if (!S_ISREG(file_status.st_mode)) { + http_output(http_404[0]); + 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); + http_output(httpd_server_ident); + http_date(); + + sprintf(buff, "Content-length: %jd\r\n", (intmax_t)file_status.st_size); + write(con_sock, buff, strlen(buff)); + + strcpy(buff, "Content-type: "); + type = default_mime_type; + if ((ext = strrchr(filename, '.')) != NULL) { + for (i = mime_type_max; i >= 0; i--) + if (strcmp(ext + 1, mime_type[i][0]) == 0) { + type = mime_type[i][1]; + break; + } + } + strcat(buff, type); + http_output(buff); + + strftime(buff, 50, "Last-Modified: %a, %d %h %Y %H:%M:%S %Z\r\n\r\n", gmtime(&file_status.st_mtime)); + write(con_sock, buff, strlen(buff)); + + /* Send data only if GET request */ + if (cmd == 1) { + while ((lg = read(fd, buff, 8192)) > 0) + write(con_sock, buff, lg); + } + +end_request2: + close(fd); +end_request: + close(con_sock); + +} + +/* + * Simple httpd server for use in PicoBSD or other embedded application. + * Should satisfy simple httpd needs. For more demanding situations + * apache is probably a better (but much larger) choice. + */ +int +main(int argc, char *argv[]) +{ + 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"); + + /* Defaults for log file */ + if (geteuid()) { + strcpy(logfile,getenv("HOME")); + strcat(logfile,"/"); + strcat(logfile,"jhttp.log"); + } else + strcpy(logfile,"/var/log/jhttpd.log"); + + /* Parse command line arguments */ + while ((ch = getopt(argc, argv, "d:f:g:l:p:vDh")) != -1) + switch (ch) { + case 'd': + strcpy(homedir,optarg); + break; + case 'f': + daemonize = 0; + verbose = 1; + fetch_mode = optarg; + break; + case 'g': + httpd_group = atoi(optarg); + break; + case 'l': + strcpy(logfile,optarg); + break; + case 'p': + http_port = atoi(optarg); + break; + case 'v': + verbose = 1; + break; + case 'D': + daemonize = 0; + break; + case '?': + case 'h': + default: + 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()) { + http_port = 1080; + } + + /* Do we really have rights in the html directory? */ + if (fetch_mode == NULL) { + if (chdir(homedir)) { + perror("chdir"); + puts(homedir); + exit(1); + } + } + + /* Create log file if it doesn't exit */ + if ((access(logfile,W_OK)) && daemonize) { + ld = open (logfile,O_WRONLY); + chmod (logfile,00600); + close(ld); + } + + init_servconnection(); + + if (verbose) { + printf("Server started with options \n"); + printf("port: %d\n",http_port); + if (fetch_mode == NULL) printf("html home: %s\n",homedir); + if (daemonize) printf("logfile: %s\n",logfile); + } + + /* httpd is spawned */ + if (daemonize) { + if ((server_pid = fork()) != 0) { + wait3(0,WNOHANG,0); + if (verbose) printf("pid: %d\n",server_pid); + exit(0); + } + wait3(0,WNOHANG,0); + } + + 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); + + label: + wait_connection(); + + if (fork()) { + wait3(0,WNOHANG,0); + close(con_sock); + goto label; + } + + http_request(); + + wait3(0,WNOHANG,0); + exit(0); +} + + +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; +} Property changes on: head/usr.sbin/httpd/simple_httpd.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/usr.sbin/httpd/README =================================================================== --- head/usr.sbin/httpd/README (nonexistent) +++ head/usr.sbin/httpd/README (revision 352927) @@ -0,0 +1,167 @@ +Simple_httpd - A small and free Web server + +"Simple_httpd is like /usr/bin/mail is to mail clients, no frills." + +This HTTP server can be used in any FreeBSD/PicoBSD application. + +It has been tested under FreeBSD 2.2.x, 3.x and 4.x. It might work +on other OS systems, but it's for FreeBSD primarily. + +The main advantage to Simple_httpd is that it is very small. +The 25K binary can satisfy most needs in a small or embedded +appplication. If you want a full featured server see +/usr/ports/www/apache* or http://www.apache.org + +Simple_httpd is released under a BSD style copyright that unlike +GPL is embedded developer friendly. + +The server is designed to be run in one of two modes. The standard +mode is a httpd server running in the background serving up a directory +of html,gif,cgi whatever. Your traditional www server. + +The "fetch" mode supports file transfer over httpd. This +is best thought of as mate for fetch(1). This feature can be +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 environment variables before calling +the script. + +CGI Environment variables are below: + +SERVER_SOFTWARE = FreeBSD/PicoBSD +REMOTE_HOST = client.canada_lower_taxes.com +REMOTE_ADDR = 200.122.13.108 + +In most target applications for this server the extra DNS traffic from +the remote_addr lookup will likely be on the local lan anyway and not +on the other side of the internet. You can turn it off yourself in +the code if you want to speed the whole process up. Be sure to turn +it off for the logfile also. + +How to use it? +============== + +Compile with make, run as follows + +usage: simple_httpd [-vD] + [-d directory] + [-g grpid] + [-l logfile] + [-p port] +or +usage: simple_httpd [-p port] -f filename + +-v +Run the server verbose. Show the program options that will be used for this +process. Will only show information during startup, no messages will +be displayed while serving requests. In other words you can still +daemonize without fear of output on stdout. + +-D +Do not daemonize. The server will not run in the background. It will +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. + +-d directory +The html document directory, if nothing is provided the default is +/httphome if UID is root, otherwise document root is ${HOME}/public_html + +-l logfile +Set the logfile to use. Log messages will be written to /var/log/jhttpd.log +if you are root and ${HOME}/jhttpd.log otherwise. If you don't want a +log file try "-l /dev/null" + +-p port +Set the port httpd server will listen to. Default is port 80 if +you are root and 1080 if you are not. + +-f filename +This is the only option needed to use the "fetch" feature. The file +specified will be the ONLY file served to ANY GET request from a browser +or fetch(1). + +Example +======= + +Standard Mode: +-------------- +If you have the FreeBSD handbook installed on your machine and would +like to serve it up over http for a quick look you could do this + +simple_httpd -d /usr/share/doc/handbook -l /usr/tmp/jlog.txt -p 1088 -v + +Any browser would be able to look at the handbook with +http://whatever_host/handbook.html:1088 + +I'm using 1088 as the port since I already have apache running on port 80 +and port 1080 on my host. + +Please note, the handbook is not installed by default in FreeBSD 3.x +It must be installed from the ports collection first if you want to +try this. + +Another simple example is to browse your local ports collection: + +cd /usr/ports +make readmes #wait about 1 hour! +simple_httpd -p 1080 -v -d /usr/ports + +Then point your browser at http://whatever_host/README.html + +Fetch Mode: +-------------- +This is designed to be used in conjunction with fetch(3). It allows +for easy transfer of files from one host to another without messy +authentication or pathnames required with ftp. The file to be +served up must be readable by the user running simple_httpd. +This is not a magic way to avoid permissions and read files. + +The daemon will only serve up ONE file. The file specified will +be returned for every GET request regardless of what the browser +asks for. This allows for on the fly naming. + +sender# simple_httpd -f /usr/tmp/big_file.tgz +receiver# fetch http://sender.com/Industrial_Secrets.tgz + +big_file.tgz was transferred from one machine to another and renamed +Industrial_Secrets.tgz at the same time. + +Tunneling over other TCP ports. Choose something that firewall +will probably pass. See /etc/services. + +sender# simple_httpd -p 53 -f /usr/tmp/big_file.tgz +receiver# fetch http://sender.com:53/Industrial_Secrets.tgz + +To Do +===== + +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 +probably want to restrict traffic to local ethernet anyway. +ie: Allow anything from my class C. + +The server always has 1 zombie process hanging around when it +runs as a daemon. Should fix so that it doesn't happen. + +Anything to make it faster! + +Man page + +If anyone has any improvements or ways to easily implement something +please let me know. If you make some neat embedded +device with PicoBSD I want to know too! + +Credits +======= + +This program was originally contributed by Marc Nicholas + +Major rewrite by William Lloyd + +$FreeBSD$ Property changes on: head/usr.sbin/httpd/README ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property