fixed www stuff
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@54 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
@ -32,7 +32,7 @@ CONFIG_SSL_FULL_MODE=y
|
||||
# CONFIG_SSL_PROT_LOW is not set
|
||||
CONFIG_SSL_PROT_MEDIUM=y
|
||||
# CONFIG_SSL_PROT_HIGH is not set
|
||||
# CONFIG_SSL_USE_DEFAULT_KEY is not set
|
||||
CONFIG_SSL_USE_DEFAULT_KEY=y
|
||||
CONFIG_SSL_ENABLE_V23_HANDSHAKE=y
|
||||
CONFIG_SSL_HAS_PEM=y
|
||||
CONFIG_SSL_USE_PKCS12=y
|
||||
@ -43,13 +43,17 @@ CONFIG_USE_DEV_URANDOM=y
|
||||
# CONFIG_WIN32_USE_CRYPTO_LIB is not set
|
||||
# CONFIG_PERFORMANCE_TESTING is not set
|
||||
# CONFIG_SSL_TEST is not set
|
||||
# CONFIG_AXHTTPD is not set
|
||||
CONFIG_AXHTTPD=y
|
||||
|
||||
#
|
||||
# Axhttpd Configuration
|
||||
#
|
||||
# CONFIG_HTTP_STATIC_BUILD is not set
|
||||
CONFIG_HTTP_HTTPS_PORT=0
|
||||
CONFIG_HTTP_SESSION_CACHE_SIZE=0
|
||||
CONFIG_HTTP_WEBROOT=""
|
||||
CONFIG_HTTP_PORT=0
|
||||
CONFIG_HTTP_TIMEOUT=0
|
||||
CONFIG_HTTP_HTTPS_PORT=443
|
||||
CONFIG_HTTP_SESSION_CACHE_SIZE=5
|
||||
CONFIG_HTTP_WEBROOT="../www"
|
||||
CONFIG_HTTP_PORT=80
|
||||
CONFIG_HTTP_TIMEOUT=5
|
||||
# CONFIG_HTTP_HAS_CGI is not set
|
||||
CONFIG_HTTP_CGI_EXTENSION=""
|
||||
# CONFIG_HTTP_DIRECTORIES is not set
|
||||
@ -62,7 +66,7 @@ CONFIG_HTTP_ALL_MIME_TYPES=y
|
||||
#
|
||||
# Language Bindings
|
||||
#
|
||||
# CONFIG_BINDINGS is not set
|
||||
CONFIG_BINDINGS=y
|
||||
# CONFIG_CSHARP_BINDINGS is not set
|
||||
# CONFIG_VBNET_BINDINGS is not set
|
||||
CONFIG_DOT_NET_FRAMEWORK_BASE=""
|
||||
|
74
httpd/main.c
@ -21,6 +21,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include "axhttp.h"
|
||||
|
||||
// GLOBALS
|
||||
@ -247,7 +248,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
active = select(wnum > rnum ? wnum+1 : rnum+1,
|
||||
rnum != -1 ? &rfds : NULL, wnum != -1 ? &wfds : NULL,
|
||||
rnum != -1 ? &rfds : NULL,
|
||||
wnum != -1 ? &wfds : NULL,
|
||||
NULL, NULL);
|
||||
|
||||
// New connection?
|
||||
@ -271,41 +273,41 @@ int main(int argc, char *argv[])
|
||||
to = tp;
|
||||
tp = tp->next;
|
||||
|
||||
if (to->state == STATE_WANT_TO_READ_HEAD)
|
||||
if (FD_ISSET(to->networkdesc, &rfds))
|
||||
{
|
||||
active--;
|
||||
procreadhead(to);
|
||||
}
|
||||
if (to->state == STATE_WANT_TO_READ_HEAD &&
|
||||
FD_ISSET(to->networkdesc, &rfds))
|
||||
{
|
||||
active--;
|
||||
procreadhead(to);
|
||||
}
|
||||
|
||||
if (to->state == STATE_WANT_TO_SEND_HEAD)
|
||||
if (FD_ISSET(to->networkdesc, &wfds))
|
||||
{
|
||||
active--;
|
||||
procsendhead(to);
|
||||
}
|
||||
if (to->state == STATE_WANT_TO_SEND_HEAD &&
|
||||
FD_ISSET(to->networkdesc, &wfds))
|
||||
{
|
||||
active--;
|
||||
procsendhead(to);
|
||||
}
|
||||
|
||||
if (to->state == STATE_WANT_TO_READ_FILE)
|
||||
if (FD_ISSET(to->filedesc, &rfds))
|
||||
{
|
||||
active--;
|
||||
procreadfile(to);
|
||||
}
|
||||
if (to->state == STATE_WANT_TO_READ_FILE &&
|
||||
FD_ISSET(to->filedesc, &rfds))
|
||||
{
|
||||
active--;
|
||||
procreadfile(to);
|
||||
}
|
||||
|
||||
if (to->state == STATE_WANT_TO_SEND_FILE)
|
||||
if (FD_ISSET(to->networkdesc, &wfds))
|
||||
{
|
||||
active--;
|
||||
procsendfile(to);
|
||||
}
|
||||
if (to->state == STATE_WANT_TO_SEND_FILE &&
|
||||
FD_ISSET(to->networkdesc, &wfds))
|
||||
{
|
||||
active--;
|
||||
procsendfile(to);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_HTTP_DIRECTORIES)
|
||||
if (to->state == STATE_DOING_DIR)
|
||||
if (FD_ISSET(to->networkdesc, &wfds))
|
||||
{
|
||||
active--;
|
||||
procdodir(to);
|
||||
}
|
||||
if (to->state == STATE_DOING_DIR &&
|
||||
FD_ISSET(to->networkdesc, &wfds))
|
||||
{
|
||||
active--;
|
||||
procdodir(to);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -452,9 +454,7 @@ static void handlenewconnection(int listenfd, int is_ssl)
|
||||
ipbuf, sizeof(ipbuf));
|
||||
}
|
||||
else
|
||||
{
|
||||
*ipbuf = '\0';
|
||||
}
|
||||
|
||||
addconnection(connfd, ipbuf, is_ssl);
|
||||
}
|
||||
@ -500,9 +500,13 @@ static int openlistener(int port)
|
||||
#endif
|
||||
|
||||
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &tp, sizeof(tp));
|
||||
bind(sd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
|
||||
listen(sd, BACKLOG);
|
||||
if (bind(sd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
|
||||
{
|
||||
close(sd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
listen(sd, BACKLOG);
|
||||
return sd;
|
||||
}
|
||||
|
||||
|
268
httpd/misc.c
@ -1,268 +0,0 @@
|
||||
/*
|
||||
* Copyright(C) 2006 Cameron Rich
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "axhttp.h"
|
||||
|
||||
void nada(int sigtype) { }
|
||||
|
||||
void die(int sigtype)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||
#ifndef WIN32
|
||||
void reaper(int sigtype)
|
||||
{
|
||||
wait3(NULL,WNOHANG,NULL);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void stripcrlf(char *p)
|
||||
{
|
||||
while (p && *p)
|
||||
{
|
||||
if (*p=='\n' || *p=='\r')
|
||||
{
|
||||
*p='\0';
|
||||
return;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Wrapper function for strncpy() that guarantees
|
||||
a null-terminated string. This is to avoid any possible
|
||||
issues due to strncpy()'s behaviour. Thanks to
|
||||
Werner Almesberger for pointing out this potential
|
||||
issue. Needless to say, make sure sizeof(dest) > 0
|
||||
and sizeof(dest) >= n.
|
||||
*/
|
||||
char *my_strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
strncpy(dest, src, n);
|
||||
dest[n-1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* strnlen is a GNU Extension */
|
||||
#ifndef __HAVE_ARCH_STRNLEN
|
||||
size_t strnlen (const char * str, size_t maxlen)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
for (p=str; maxlen-- && *p!='\0'; ++p);
|
||||
return (p - str);
|
||||
}
|
||||
#endif
|
||||
|
||||
int sanitizefile(char *buf)
|
||||
{
|
||||
int len, i;
|
||||
|
||||
// Don't accept anything not starting with a /
|
||||
if (*buf != '/')
|
||||
return 0;
|
||||
|
||||
len = strlen(buf);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
// Check for "/." : In other words, don't send files starting with a .
|
||||
// Notice, GOBBLES, that this includes ".."
|
||||
if (buf[i] == '/' && buf[i+1] == '.')
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sanitizehost(char *buf)
|
||||
{
|
||||
while(*buf != '\0')
|
||||
{
|
||||
// Handle the port
|
||||
if (*buf == ':')
|
||||
{
|
||||
*buf = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Enforce some basic URL rules...
|
||||
if (isalnum(*buf)==0 && *buf != '-' && *buf != '.') return 0;
|
||||
if (*buf == '.' && *(buf+1) == '.') return 0;
|
||||
if (*buf == '.' && *(buf+1) == '-') return 0;
|
||||
if (*buf == '-' && *(buf+1) == '.') return 0;
|
||||
buf++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void buildactualfile(struct connstruct *cn)
|
||||
{
|
||||
snprintf(cn->actualfile, MAXREQUESTLENGTH, "%s%s",
|
||||
webroot,
|
||||
cn->filereq);
|
||||
|
||||
/* Add directory slash if not there */
|
||||
if (isdir(cn->actualfile) &&
|
||||
cn->actualfile[strlen(cn->actualfile)-1] != '/')
|
||||
strcat(cn->actualfile, "/");
|
||||
|
||||
#ifdef WIN32
|
||||
/* convert all the forward slashes to back slashes */
|
||||
{
|
||||
char *t = cn->actualfile;
|
||||
while ((t = strchr(t, '/')))
|
||||
{
|
||||
*t++ = '\\';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CONFIG_HTTP_DIRECTORIES)
|
||||
int issockwriteable(int sd)
|
||||
{
|
||||
fd_set wfds;
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(sd, &wfds);
|
||||
|
||||
select(FD_SETSIZE, NULL, &wfds, NULL, &tv);
|
||||
|
||||
return FD_ISSET(sd, &wfds);
|
||||
}
|
||||
#endif
|
||||
|
||||
int isdir(char *tpbuf)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(tpbuf, &st) == -1)
|
||||
return 0;
|
||||
|
||||
if ((st.st_mode & S_IFMT) == S_IFDIR)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||
int iscgi(char *fn)
|
||||
{
|
||||
struct cgiextstruct *tp;
|
||||
int fnlen, extlen;
|
||||
|
||||
fnlen = strlen(fn);
|
||||
tp = cgiexts;
|
||||
|
||||
while (tp != NULL)
|
||||
{
|
||||
extlen = strlen(tp->ext);
|
||||
|
||||
if (strcasecmp(fn+(fnlen-extlen), tp->ext) == 0)
|
||||
return 1;
|
||||
|
||||
tp = tp->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void split(char *tp, char *sp[], int maxwords, char sc)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* Skip leading whitespace */
|
||||
while(*tp == sc) tp++;
|
||||
|
||||
if (*tp == '\0')
|
||||
{
|
||||
sp[i] = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i==maxwords-2)
|
||||
{
|
||||
sp[maxwords-2] = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
sp[i] = tp;
|
||||
|
||||
while(*tp != sc && *tp != '\0')
|
||||
tp++;
|
||||
|
||||
if (*tp == sc)
|
||||
*tp++ = '\0';
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int trycgi_withpathinfo(struct connstruct *cn)
|
||||
{
|
||||
char tpfile[MAXREQUESTLENGTH];
|
||||
char fr_str[MAXREQUESTLENGTH];
|
||||
char *fr_rs[MAXCGIARGS]; // filereq splitted
|
||||
int i = 0, offset;
|
||||
|
||||
my_strncpy(fr_str, cn->filereq, MAXREQUESTLENGTH);
|
||||
split(fr_str, fr_rs, MAXCGIARGS, '/');
|
||||
|
||||
while (fr_rs[i] != NULL)
|
||||
{
|
||||
snprintf(tpfile, sizeof(tpfile), "%s/%s%s",
|
||||
webroot, cn->virtualhostreq, fr_str);
|
||||
|
||||
if (iscgi(tpfile) && isdir(tpfile) == 0)
|
||||
{
|
||||
/* We've found our CGI file! */
|
||||
my_strncpy(cn->actualfile, tpfile, MAXREQUESTLENGTH);
|
||||
my_strncpy(cn->cgiscriptinfo, fr_str, MAXREQUESTLENGTH);
|
||||
|
||||
offset = (fr_rs[i] + strlen(fr_rs[i])) - fr_str;
|
||||
my_strncpy(cn->cgipathinfo, cn->filereq+offset, MAXREQUESTLENGTH);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
*(fr_rs[i]+strlen(fr_rs[i])) = '/';
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Couldn't find any CGIs :( */
|
||||
*(cn->cgiscriptinfo) = '\0';
|
||||
*(cn->cgipathinfo) = '\0';
|
||||
return -1;
|
||||
}
|
||||
#endif
|
@ -284,7 +284,7 @@ void procreadhead(struct connstruct *cn)
|
||||
return;
|
||||
}
|
||||
|
||||
while(*next != '\r' && *next != '\n' && *next != '\0')
|
||||
while (*next != '\r' && *next != '\n' && *next != '\0')
|
||||
next++;
|
||||
|
||||
if (*next == '\r')
|
||||
|
@ -33,6 +33,8 @@ TARGET1=../$(STAGE)/libaxtls.a
|
||||
BASETARGET=libaxtls.so
|
||||
ifdef CONFIG_PLATFORM_CYGWIN
|
||||
TARGET2=../$(STAGE)/libaxtls.dll.a
|
||||
else
|
||||
TARGET2=../$(STAGE)/$(LIBMINOR)
|
||||
endif
|
||||
|
||||
# shared library major/minor numbers
|
||||
@ -47,7 +49,7 @@ endif
|
||||
libs: $(TARGET1) $(TARGET2)
|
||||
|
||||
OBJ=\
|
||||
aes.o \
|
||||
aes.o \
|
||||
asn1.o \
|
||||
bigint.o \
|
||||
crypto_misc.o \
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |