mirror of
https://github.com/NishiOwO/ncsa-httpd.git
synced 2025-04-21 08:44:40 +00:00
NCSA HTTPd 1.4.2
This commit is contained in:
parent
c582f067b4
commit
703e80090a
319
cgi-bin/mail
Executable file
319
cgi-bin/mail
Executable file
@ -0,0 +1,319 @@
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
# ======================================================================
|
||||
# WebMonitor Standalone Module: mail
|
||||
#
|
||||
# CGI script for providing form and script
|
||||
# to send mail to configured system users
|
||||
#
|
||||
# required files: mail.list
|
||||
# Text file with users nicknames and
|
||||
# email addresses in the format of
|
||||
# <nickname>:<email address>
|
||||
# Keep "mail.list" in same directory as mail script
|
||||
# NOTE: you can even have group aliases!
|
||||
# just separate the addresses with commas
|
||||
# Make sure you 'chmod 0644 mail.list' so the server can read it
|
||||
# +-----------------------------------------
|
||||
# Example: |webmaster:admin@machine
|
||||
# |john-doe:jdoe
|
||||
# |carlos:cpero@ncsa.uiuc.edu
|
||||
# |group:leader@domain.com,member@domain.com
|
||||
# +-----------------------------------------
|
||||
# ======================================================================
|
||||
# Carlos A. Pero (cpero@ncsa.uiuc.edu) last update 4/30/95
|
||||
# ======================================================================
|
||||
# Documentation for WebMonitor can be found at
|
||||
# <URL:http://hoohoo.ncsa.uiuc.edu/webmonitor/>
|
||||
# ======================================================================
|
||||
# This code is in the public domain. Specifically, we give to the public
|
||||
# domain all rights for future licensing of the source code, all resale
|
||||
# rights, and all publishing rights.
|
||||
#
|
||||
# We ask, but do not require, that the following message be included in
|
||||
# all derived works:
|
||||
#
|
||||
# Portions developed at the National Center for Supercomputing
|
||||
# Applications at the University of Illinois at Urbana-Champaign.
|
||||
#
|
||||
#
|
||||
# THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED,
|
||||
# FOR THE SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT
|
||||
# LIMITATION, WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
# ======================================================================
|
||||
# This script can be referenced 2 ways for the best flexibility:
|
||||
#
|
||||
# DIRECTLY, <A HREF="/cgi-bin/mail?nickname">
|
||||
# This will generate an email form for the person named in 'nickname',
|
||||
# and if they exist in the 'mail.list' file.
|
||||
# If no 'nickname' is specified in the QUERY_STRING when the script is
|
||||
# first invoked, or the nickname cannot be found in the 'mail.list',
|
||||
# an email form with a SELECT box of all valid nicknames is generated.
|
||||
# When the email form is submitted, it will call itself via method of POST,
|
||||
# and send the email to the recipient, outputting a confirmation message.
|
||||
# If the HTTP_REFERER was trasmitted when the script was first invoked,
|
||||
# there will be a hyperlink available to go back to that page (such as
|
||||
# the user's home page).
|
||||
#
|
||||
# FORWARDING RESULTS, <FORM METHOD="POST" ACTION="/cgi-bin/mail?nickname">
|
||||
# This will forward the results from the FORM, which can exist anywhere,
|
||||
# to the recipient specified by 'nickname'. Since the 'nickname' is in
|
||||
# the QUERY_STRING, the FORM *must* use the METHOD="POST", otherwise the
|
||||
# recipient's nickname will be blown away.
|
||||
# Users may want to include a:
|
||||
# <INPUT TYPE="hidden" NAME="next-url" VALUE="/~user/received.html">
|
||||
# If this is present in the FORM input, the client will be redirected
|
||||
# to this HTML file as a confirmation message instead of the default.
|
||||
# In addition, the user can also define any of the following input names
|
||||
# in their form to better customize the output mailed back to them.
|
||||
# <INPUT TYPE="hidden" NAME="subject" VALUE="My survey results">
|
||||
# <INPUT TYPE="hidden" NAME="from-name" VALUE="Average Web user">
|
||||
# <INPUT TYPE="hidden" NAME="from-email" VALUE="jdoe@domain.com">
|
||||
# These values will then be used in the header of the email message.
|
||||
# Otherwise, default values will be substituted.
|
||||
# ======================================================================
|
||||
|
||||
|
||||
########################################################################
|
||||
########## Configurable variables ######################################
|
||||
|
||||
$SENDMAIL = '/usr/sbin/sendmail';
|
||||
# The location of your sendmail binary
|
||||
|
||||
## Also, make sure the first line of this script points
|
||||
## to your PERL binary
|
||||
|
||||
########## Nothing else to change ######################################
|
||||
########################################################################
|
||||
|
||||
|
||||
$SCRIPT = $ENV{'SCRIPT_NAME'};
|
||||
|
||||
#### Do standard HTTP stuff ####
|
||||
&cgi_receive;
|
||||
&cgi_decode;
|
||||
&cgi_header;
|
||||
|
||||
#### Output email form unless you are receiving FORM input already ####
|
||||
&print_form unless keys %FORM;
|
||||
|
||||
#### Make sure required fields are filled out ####
|
||||
if ($FORM{'nickname'}) {
|
||||
#### This section is for receiving from this form ####
|
||||
&error_blank_field('your name') unless ($FORM{'from-name'});
|
||||
&error_blank_field('your email address in the form of <I>name@domain</I>') unless ($FORM{'from-email'} =~ /\@/);
|
||||
&error_blank_field('the subject of the message') unless ($FORM{'subject'});
|
||||
&error_blank_field('your message') unless ($FORM{'message'});
|
||||
}
|
||||
else {
|
||||
#### This section is for user's forms ####
|
||||
#### Such as ACTION="/cgi-bin/mail?carlos" to have results forwarded ####
|
||||
$FORM{'nickname'} = $ENV{'QUERY_STRING'};
|
||||
}
|
||||
|
||||
#### Lookup email address based on 'nickname' ####
|
||||
open (MAILNAMES, "mail.list") || die ("$SCRIPT: Can't open mail.list: $!\n");
|
||||
while (<MAILNAMES>) {
|
||||
chop;
|
||||
($nick, $addr) = split(/:/, $_);
|
||||
$ADDRESS{$nick} = $addr;
|
||||
}
|
||||
close (MAILNAMES);
|
||||
&error_blank_field('the nickname of the recipient') unless ($ADDRESS{$FORM{'nickname'}});
|
||||
|
||||
#### Make sure all necessary variables for email message are filled in
|
||||
($FORM{'subject'}) || ($FORM{'subject'} = "FORM results");
|
||||
($FORM{'from-email'}) || ($FORM{'from-email'} = $ADDRESS{$FORM{'nickname'}});
|
||||
($FORM{'from-name'}) || ($FORM{'from-name'} = "WebMonitor mail");
|
||||
|
||||
open (MAIL, "| $SENDMAIL $ADDRESS{$FORM{'nickname'}}") || die ("$SCRIPT: Can't open $mailprog: $!\n");
|
||||
print MAIL "Reply-to: $FORM{'from-email'} ($FORM{'from-name'})\n";
|
||||
print MAIL "From: $FORM{'from-email'} ($FORM{'from-name'})\n";
|
||||
print MAIL "To: $ADDRESS{$FORM{'nickname'}}\n";
|
||||
print MAIL "Subject: $FORM{'subject'}\n";
|
||||
print MAIL "\n";
|
||||
print MAIL "=============================================================\n";
|
||||
print MAIL "NOTE: This message was sent through the WebMonitor mail form\n";
|
||||
print MAIL "=============================================================\n";
|
||||
print MAIL "REMOTE HOST: $ENV{'REMOTE_HOST'}\n";
|
||||
print MAIL "REMOTE ADDRESS: $ENV{'REMOTE_ADDR'}\n";
|
||||
print MAIL "HTTP_USER_AGENT: $ENV{'HTTP_USER_AGENT'}\n";
|
||||
print MAIL "=============================================================\n";
|
||||
print MAIL "\n";
|
||||
if ($ENV{'QUERY_STRING'}) {
|
||||
&dump_values(FORM, MAIL);
|
||||
}
|
||||
else {
|
||||
print MAIL "$FORM{'message'}\n";
|
||||
}
|
||||
print MAIL "\n";
|
||||
close (MAIL);
|
||||
|
||||
#### Now, redirect if "next-url" is included
|
||||
if ($FORM{'next-url'}) {
|
||||
print "Location: $FORM{'next-url'}\n";
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#### Prevent HTML output
|
||||
foreach $key (keys %FORM) {
|
||||
$FORM{$key} =~ s/</\</g;
|
||||
$FORM{$key} =~ s/>/\>/g;
|
||||
}
|
||||
|
||||
#### Output confirmation message ####
|
||||
print qq|<HTML><HEAD><TITLE>WebMonitor-Email Sent</TITLE></HEAD><BODY>\n|;
|
||||
print qq|<H1>$ENV{'SERVER_NAME'} Email Sent</H1>\n|;
|
||||
print qq|The following message has been sent.\n|;
|
||||
print qq|You can now return to <A HREF="$FORM{'previous-url'}">where you were</A>.\n| if ($FORM{'previous-url'});
|
||||
print qq|<HR>\n|;
|
||||
print "<PRE>\n";
|
||||
print "Reply-to: $FORM{'from-email'} ($FORM{'from-name'})\n";
|
||||
print "From: $FORM{'from-email'} ($FORM{'from-name'})\n";
|
||||
print "To: $ADDRESS{$FORM{'nickname'}}\n";
|
||||
print "Subject: $FORM{'subject'}\n";
|
||||
print "\n";
|
||||
if ($ENV{'QUERY_STRING'}) {
|
||||
&dump_values(FORM, STDOUT);
|
||||
}
|
||||
else {
|
||||
print "$FORM{'message'}\n";
|
||||
}
|
||||
print "\n";
|
||||
print "</PRE>\n";
|
||||
print "</BODY>\n";
|
||||
exit;
|
||||
|
||||
#####################################################################
|
||||
#### SUBROUTINES ####################################################
|
||||
|
||||
sub error_blank_field {
|
||||
local($variable) = @_;
|
||||
print "\n" if ($FORM{'next-url'});
|
||||
print "<HTML><HEAD><TITLE>WebMonitor-Email Error</TITLE></HEAD><BODY>\n";
|
||||
print "<H1>Error!</H1>\n";
|
||||
print "You did not fill in $variable.\n";
|
||||
print "Please go back to the form and do so.\n";
|
||||
print "</BODY>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
sub cgi_header {
|
||||
print "Content-type: text/html\n";
|
||||
print "\n" unless ($FORM{'next-url'});
|
||||
}
|
||||
|
||||
sub cgi_receive {
|
||||
if ($ENV{'REQUEST_METHOD'} eq "POST") {
|
||||
read(STDIN, $incoming, $ENV{'CONTENT_LENGTH'});
|
||||
}
|
||||
else {
|
||||
$incoming = $ENV{'QUERY_STRING'};
|
||||
}
|
||||
}
|
||||
|
||||
sub cgi_decode {
|
||||
@pairs = split(/&/, $incoming);
|
||||
|
||||
foreach (@pairs) {
|
||||
($name, $value) = split(/=/, $_);
|
||||
|
||||
$name =~ tr/+/ /;
|
||||
$value =~ tr/+/ /;
|
||||
$name =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie;
|
||||
$value =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie;
|
||||
|
||||
#### Strip out semicolons unless for special character
|
||||
$value =~ s/;/$$/g;
|
||||
$value =~ s/&(\S{1,6})$$/&\1;/g;
|
||||
$value =~ s/$$/ /g;
|
||||
|
||||
$value =~ s/\|/ /g;
|
||||
$value =~ s/^!/ /g; ## Allow exclamation points in sentences
|
||||
|
||||
#### Skip blank text entry fields
|
||||
next if ($value eq "");
|
||||
|
||||
#### Check for "assign-dynamic" field names
|
||||
#### Mainly for on-the-fly input names, especially checkboxes
|
||||
if ($name =~ /^assign-dynamic/) {
|
||||
$name = $value;
|
||||
$value = "on";
|
||||
}
|
||||
|
||||
#### Allow for multiple values of a single name
|
||||
$FORM{$name} .= ", " if ($FORM{$name});
|
||||
|
||||
$FORM{$name} .= $value;
|
||||
}
|
||||
}
|
||||
|
||||
sub dump_values {
|
||||
local($env, $handle) = @_;
|
||||
eval "\@keys = keys \%$env";
|
||||
eval "\@values = values \%$env";
|
||||
($handle eq "STDOUT") && (print $handle "<PRE>\n");
|
||||
while ($#keys >= 0) {
|
||||
$key = pop(@keys);
|
||||
$value = pop(@values);
|
||||
if ($value =~ /[\cM\n]/) {
|
||||
print $handle "($key)\n";
|
||||
print $handle "-" x 70, "\n", $value, "-" x 70, "\n";
|
||||
}
|
||||
else {
|
||||
print $handle "($key) $value\n";
|
||||
}
|
||||
}
|
||||
($handle eq "STDOUT") && (print $handle "</PRE>\n");
|
||||
|
||||
}
|
||||
|
||||
sub print_form {
|
||||
#### Assign path_info and query_string if necessary
|
||||
#### $path_info = "";
|
||||
|
||||
open (MAILNAMES, "mail.list") || die ("$SCRIPT: Can't open mail.list: $!\n");
|
||||
while (<MAILNAMES>) {
|
||||
chop;
|
||||
($nickname, $address) = split(/:/, $_);
|
||||
$ADDRESS{$nickname} = $address;
|
||||
}
|
||||
close (MAILNAMES);
|
||||
|
||||
print qq|<HTML><HEAD><TITLE>WebMonitor-Email Form</TITLE></HEAD><BODY>\n|;
|
||||
print qq|<H1>$ENV{'SERVER_NAME'} <A HREF="http://hoohoo.ncsa.uiuc.edu/webmonitor/module-mail.html">Email Form</A></H1>\n|;
|
||||
print qq|<FORM METHOD="POST" ACTION="$SCRIPT$path_info$query_string">\n|;
|
||||
print qq|<HR>\n|;
|
||||
print qq|<INPUT TYPE="submit" VALUE="Send Email"> to |;
|
||||
|
||||
|
||||
if ($ADDRESS{$ENV{'QUERY_STRING'}}) {
|
||||
print qq|<B>$ENV{'QUERY_STRING'}</B> <I>($ADDRESS{$ENV{'QUERY_STRING'}})</I>\n|;
|
||||
print qq|<INPUT TYPE="hidden" NAME="nickname" VALUE="$ENV{'QUERY_STRING'}">\n|;
|
||||
}
|
||||
else {
|
||||
print qq|<SELECT NAME="nickname">\n|;
|
||||
print qq|<OPTION>Select name...\n|;
|
||||
foreach $nickname (sort keys %ADDRESS) {
|
||||
print qq|<OPTION>$nickname\n|;
|
||||
}
|
||||
print qq|</SELECT>\n|;
|
||||
}
|
||||
|
||||
|
||||
print qq|<HR>\n|;
|
||||
print qq|<PRE>|;
|
||||
print qq| Your Name: <INPUT NAME="from-name" SIZE="30">\n|;
|
||||
print qq|Email Address: <INPUT NAME="from-email" SIZE="30">\n|;
|
||||
print qq| Subject: <INPUT NAME="subject" SIZE="40"> <INPUT TYPE="reset" VALUE="Clear Message">\n|;
|
||||
print qq|</PRE>\n|;
|
||||
print qq|<TEXTAREA NAME="message" ROWS="15" COLS="70"></TEXTAREA>\n|;
|
||||
print qq|<INPUT TYPE="hidden" NAME="previous-url" VALUE="$ENV{'HTTP_REFERER'}">\n|;
|
||||
print qq|</FORM>\n|;
|
||||
print qq|</BODY>\n|;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
7
cgi-bin/test-env
Executable file
7
cgi-bin/test-env
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Prints out all of the environment variables as used
|
||||
#
|
||||
echo Content-type: text/plain
|
||||
echo
|
||||
env
|
284
src/http_ipc.c
Normal file
284
src/http_ipc.c
Normal file
@ -0,0 +1,284 @@
|
||||
/*
|
||||
* http_ipc.c
|
||||
* Handles the file descriptor passing. Should work under BSD and
|
||||
* SYSV.
|
||||
*
|
||||
* All code contained herein is covered by the Copyright as distributed
|
||||
* in the README file in the main directory of the distribution of
|
||||
* NCSA HTTPD.
|
||||
*
|
||||
* Based (with modifications) on code by W. Richard Stevens,
|
||||
* in _Advanced Programming in the UNIX Environment_
|
||||
*
|
||||
* 03-06-95 blong
|
||||
* Added #ifdefs to handle not using this at all for machines like
|
||||
* Linux.
|
||||
*
|
||||
* 04-17-95 blong
|
||||
* Added NEED_SPIPE with s_pipe from Stevens _Unix Network Programming_
|
||||
* for SVR3.2 systems without socketpair.
|
||||
*/
|
||||
|
||||
#ifndef NO_PASS
|
||||
|
||||
#include "httpd.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined(FD_BSD)
|
||||
#include <sys/uio.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#elif defined(FD_SYSV)
|
||||
#ifdef NEED_SPIPE
|
||||
#define SPX_DEVICE "/dev/spx"
|
||||
#include <sys/stream.h>
|
||||
#endif
|
||||
#include <stropts.h>
|
||||
#endif
|
||||
#include "new.h"
|
||||
|
||||
#ifdef FD_SYSV
|
||||
|
||||
int pass_fd(int clifd, int fd) {
|
||||
char buf[2];
|
||||
|
||||
buf[0] = 0;
|
||||
if (fd < 0) {
|
||||
buf[1] = -fd;
|
||||
if (buf[1] == 0)
|
||||
buf[1] = 1;
|
||||
} else {
|
||||
buf[1] = 0;
|
||||
}
|
||||
|
||||
if (write(clifd, buf, 2) != 2) {
|
||||
fprintf(stderr,"pass_fd: write failed\n");
|
||||
perror("pass_fd");
|
||||
return -1;
|
||||
}
|
||||
if (fd >= 0)
|
||||
if (ioctl(clifd, I_SENDFD, fd) < 0) {
|
||||
fprintf(stderr,"pass_fd: ioctl failed\n");
|
||||
perror("ioctl");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int recv_fd(int servfd) {
|
||||
int newfd, nread, flag, status;
|
||||
char *ptr, buf[IOBUFSIZE];
|
||||
struct strbuf dat;
|
||||
struct strrecvfd recvfd;
|
||||
|
||||
status = -1;
|
||||
for ( ; ; ) {
|
||||
dat.buf = buf;
|
||||
dat.maxlen = IOBUFSIZE;
|
||||
flag = 0;
|
||||
if (getmsg(servfd, NULL, &dat, &flag) < 0) {
|
||||
fprintf(stderr,"httpd:getmsg error recv_fd\n");
|
||||
perror("getmsg");
|
||||
exit(1);
|
||||
}
|
||||
nread = dat.len;
|
||||
if (nread == 0) {
|
||||
fprintf(stderr,"httpd: connection closed by server\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (ptr = buf; ptr < &buf[nread]; ) {
|
||||
if (*ptr++ == 0) {
|
||||
if (ptr != &buf[nread-1]) {
|
||||
fprintf(stderr,"httpd: message format error recv_fd\n");
|
||||
perror("recv_fd");
|
||||
exit(1);
|
||||
}
|
||||
status = *ptr & 255;
|
||||
if (status == 0) {
|
||||
if (ioctl(servfd, I_RECVFD, &recvfd) < 0)
|
||||
return -1;
|
||||
newfd = recvfd.fd;
|
||||
} else
|
||||
newfd = -status;
|
||||
nread -= 2;
|
||||
}
|
||||
}
|
||||
if (status >= 0)
|
||||
return (newfd);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NEED_SPIPE
|
||||
|
||||
int s_pipe(int fd[2]) {
|
||||
struct strfdinsert ins;
|
||||
queue_t *pointer;
|
||||
|
||||
/*
|
||||
* First open the stream clone device "/dev/spx" twice,
|
||||
* obtaining the two file descriptors.
|
||||
*/
|
||||
|
||||
if ((fd[0] = open(SPX_DEVICE, O_RDWR)) < 0)
|
||||
return -1;
|
||||
if ((fd[1] = open(SPX_DEVICE, O_RDWR)) < 0)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Now link these two streams together with an I_FDINSERT ioctl
|
||||
*/
|
||||
|
||||
ins.ctlbuf.buf = (char *) &pointer;
|
||||
ins.ctlbuf.maxlen = sizeof(queue_t *);
|
||||
ins.ctlbuf.len = sizeof(queue_t *);
|
||||
|
||||
ins.databuf.buf = (char *) 0;
|
||||
ins.databuf.len = -1;
|
||||
ins.databuf.maxlen = 0;
|
||||
|
||||
ins.fildes = fd[1];
|
||||
ins.flags = 0;
|
||||
ins.offset = 0;
|
||||
|
||||
if (ioctl(fd[0], I_FDINSERT, (char *) &ins) < 0) {
|
||||
close(fd[0]);
|
||||
close(fd[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#endif /* NEED_SPIPE */
|
||||
|
||||
#endif /* FD_SYSV */
|
||||
|
||||
#ifdef FD_BSD
|
||||
|
||||
#ifdef FD_BSDRENO
|
||||
static struct cmsghdr *cmptr = NULL;
|
||||
#define CONTROLLEN (sizeof(struct cmsghdr) + sizeof(int))
|
||||
#endif
|
||||
|
||||
int pass_fd(int clifd, int fd) {
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
char buf[2];
|
||||
|
||||
iov[0].iov_base = buf;
|
||||
iov[0].iov_len = 2;
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
if (fd < 0) {
|
||||
#ifdef FD_BSDRENO
|
||||
msg.msg_control = NULL;
|
||||
msg.msg_controllen = 0;
|
||||
#else
|
||||
msg.msg_accrights = NULL;
|
||||
msg.msg_accrightslen = 0;
|
||||
#endif
|
||||
buf[1] = -fd;
|
||||
if (buf[1] == 0)
|
||||
buf[1] = 1;
|
||||
} else {
|
||||
#ifdef FD_BSDRENO
|
||||
if (cmptr == NULL && (cmptr = malloc(CONTROLLEN)) == NULL)
|
||||
return -1;
|
||||
cmptr->cmsg_level = SOL_SOCKET;
|
||||
cmptr->cmsg_type = SCM_RIGHTS;
|
||||
cmptr->cmsg_len = CONTROLLEN;
|
||||
msg.msg_control = (caddr_t) cmptr;
|
||||
msg.msg_controllen = CONTROLLEN;
|
||||
*(int *)CMSG_DATA(cmptr) = fd;
|
||||
#else
|
||||
msg.msg_accrights = (caddr_t) &fd;
|
||||
msg.msg_accrightslen = sizeof(int);
|
||||
#endif
|
||||
buf[1] = 0;
|
||||
}
|
||||
buf[0] = 0;
|
||||
|
||||
/* if (write(clifd, buf, 2) != 2)
|
||||
return -1; */
|
||||
|
||||
if (sendmsg(clifd, &msg, 0) != 2)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int recv_fd(int servfd) {
|
||||
int nread, status;
|
||||
int newfd = -1;
|
||||
char *ptr, buf[IOBUFSIZE];
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
|
||||
status = -1;
|
||||
for ( ; ; ) {
|
||||
iov[0].iov_base = buf;
|
||||
iov[0].iov_len = sizeof(buf);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
#ifdef FD_BSDRENO
|
||||
if (cmptr == NULL && (cmptr = malloc(CONTROLLEN)) == NULL)
|
||||
return -1;
|
||||
msg.msg_control = (caddr_t) cmptr;
|
||||
msg.msg_controllen = CONTROLLEN;
|
||||
#else
|
||||
msg.msg_accrights = (caddr_t) &newfd;
|
||||
msg.msg_accrightslen = sizeof(int);
|
||||
#endif
|
||||
|
||||
if ((nread = recvmsg(servfd, &msg, 0)) < 0) {
|
||||
fprintf(stderr,"httpd: recvmsg error");
|
||||
perror("recvmsg");
|
||||
exit(1);
|
||||
} else if (nread == 0) {
|
||||
fprintf(stderr, "httpd: connection closed by server");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (ptr = buf; ptr < &buf[nread]; ) {
|
||||
if (*ptr++ == 0) {
|
||||
if (ptr != &buf[nread-1]) {
|
||||
fprintf(stderr, "httpd:message format error");
|
||||
exit(1);
|
||||
}
|
||||
status = *ptr & 255;
|
||||
if (status == 0) {
|
||||
#ifdef FD_BSDRENO
|
||||
if (msg.msg_controllen != CONTROLLEN)
|
||||
#else
|
||||
if (msg.msg_accrightslen != sizeof(int))
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "httpd: status = 0 but no fd");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef FD_BSDRENO
|
||||
newfd = *(int *)CMSG_DATA(cmptr);
|
||||
#endif
|
||||
} else
|
||||
newfd = -status;
|
||||
nread -= 2;
|
||||
}
|
||||
}
|
||||
if (nread > 0)
|
||||
return -1;
|
||||
if (status >= 0)
|
||||
return newfd;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
99
src/new.h
Normal file
99
src/new.h
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* New Header file, since I didn't like recompiling the whole thing
|
||||
* every time I wanted to do anything.
|
||||
*
|
||||
* One of these days, I'll have to make some real header files for this code.
|
||||
*
|
||||
* All code contained herein is covered by the Copyright as distributed
|
||||
* in the README file in the main directory of the distribution of
|
||||
* NCSA HTTPD.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
/* #defines for new muli-child approach
|
||||
DEFAULT_START_DAEMON defines how many children start at httpd start
|
||||
DEFAULT_MAX_DAEMON defines how many children can start
|
||||
*/
|
||||
|
||||
#define DEFAULT_START_DAEMON 5
|
||||
#define DEFAULT_MAX_DAEMON 10
|
||||
|
||||
/* For New Error Handling */
|
||||
#define NUM_ERRORS 10
|
||||
#define CGI_ERROR 1
|
||||
#define TEXT_ERROR 2
|
||||
|
||||
typedef struct _ChildInfo {
|
||||
int parentfd;
|
||||
int childfd;
|
||||
int pid;
|
||||
int busy;
|
||||
} ChildInfo;
|
||||
|
||||
typedef struct _ErrorMessage {
|
||||
int Type;
|
||||
int ErrorNum;
|
||||
char* ErrorFile;
|
||||
} ErrorMessage;
|
||||
|
||||
/* in http_log.c */
|
||||
extern const char StatLine200[];
|
||||
extern const char StatLine302[];
|
||||
extern const char StatLine304[];
|
||||
extern const char StatLine400[];
|
||||
extern const char StatLine401[];
|
||||
extern const char StatLine403[];
|
||||
extern const char StatLine404[];
|
||||
extern const char StatLine500[];
|
||||
extern const char StatLine501[];
|
||||
extern int ErrorStat;
|
||||
extern int numErrorsDefined;
|
||||
|
||||
/* in http_mime.c */
|
||||
extern char *status_line;
|
||||
extern struct mime_ext *types[27];
|
||||
extern struct mime_ext *forced_types;
|
||||
extern struct mime_ext *encoding_types;
|
||||
extern struct mime_ext *Saved_Forced;
|
||||
extern struct mime_ext *Saved_Encoding;
|
||||
char* set_stat_line();
|
||||
void reset_mime_vars();
|
||||
|
||||
/* for http_ipc.c */
|
||||
int pass_fd(int spipefd, int filedes);
|
||||
int recv_fd(int spipefd);
|
||||
#ifdef NEED_SPIPE
|
||||
int s_pipe(int fd[2]);
|
||||
#endif
|
||||
|
||||
/* for http_log.c */
|
||||
int add_error(char* errornum, char* name);
|
||||
int have_error(int errornum);
|
||||
void reset_error();
|
||||
|
||||
/* for http_config.c */
|
||||
extern int max_servers;
|
||||
extern int start_servers;
|
||||
/* number of security directives in access config file */
|
||||
extern int num_sec_config;
|
||||
|
||||
/* for httpd.c */
|
||||
void speed_hack_libs();
|
||||
void set_group_privs();
|
||||
void set_signals();
|
||||
|
||||
/* new globals in http_request.c */
|
||||
extern char method[];
|
||||
extern char protocal[];
|
||||
extern char the_request[];
|
||||
extern char failed_request[];
|
||||
extern char as_requested[];
|
||||
extern char url2[];
|
||||
extern char failed_url[];
|
||||
extern char args2[];
|
||||
void initialize_request();
|
||||
|
||||
/* for http_access.c */
|
||||
void reset_security();
|
12
src/oops
Normal file
12
src/oops
Normal file
@ -0,0 +1,12 @@
|
||||
*** ../../sgi5/httpd_1.4.2/src/http_get.c Thu Jun 22 18:48:27 1995
|
||||
--- http_get.c Fri Jun 23 11:09:57 1995
|
||||
***************
|
||||
*** 208,214 ****
|
||||
}
|
||||
else {
|
||||
probe_content_type(ifile);
|
||||
- fprintf(stderr,"content_type: %s\n",content_type);
|
||||
if(!strcmp(content_type,CGI_MAGIC_TYPE))
|
||||
send_cgi("GET",ifile,pa,args,&finfo,in,fd);
|
||||
else
|
||||
--- 208,213 ----
|
Loading…
x
Reference in New Issue
Block a user