mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
added aborts to malloc and other system calls
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@62 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
@ -74,6 +74,12 @@ config CONFIG_HTTP_DIRECTORIES
|
||||
help
|
||||
Enable directory listing.
|
||||
|
||||
config CONFIG_HTTP_HAS_AUTHORIZATION
|
||||
bool "Enable authorization"
|
||||
default n
|
||||
help
|
||||
Pages/directories can have passwords associated with them.
|
||||
|
||||
config CONFIG_HTTP_PERM_CHECK
|
||||
bool "Permissions Check"
|
||||
default n
|
||||
@ -81,12 +87,6 @@ config CONFIG_HTTP_PERM_CHECK
|
||||
Enable permissions checking on the directories before reading the
|
||||
files in them.
|
||||
|
||||
config CONFIG_HTTP_HAS_AUTHORIZATION
|
||||
bool "Enable authorization"
|
||||
default n
|
||||
help
|
||||
Pages/directories can have passwords associated with them.
|
||||
|
||||
config CONFIG_HTTP_HAS_IPV6
|
||||
bool "Enable IPv6"
|
||||
default n
|
||||
@ -98,8 +98,6 @@ config CONFIG_HTTP_HAS_IPV6
|
||||
|
||||
config CONFIG_HTTP_ALL_MIME_TYPES
|
||||
bool "Use all mime types"
|
||||
default y if CONFIG_SSL_FULL_MODE
|
||||
default n if !CONFIG_SSL_FULL_MODE
|
||||
help
|
||||
Use the full list of supported mime types.
|
||||
|
||||
|
@ -63,7 +63,8 @@ endif
|
||||
OBJ= \
|
||||
axhttpd.o \
|
||||
proc.o \
|
||||
mime_types.o
|
||||
mime_types.o \
|
||||
tdate_parse.o
|
||||
|
||||
include ../config/makefile.post
|
||||
|
||||
|
35
httpd/README
35
httpd/README
@ -4,6 +4,10 @@ axhttpd is a small embedded web server using the axTLS library.
|
||||
It is based originally on the web server written by Doug Currie which is at:
|
||||
http://www.hcsw.org/awhttpd.
|
||||
|
||||
*****************************************************************************
|
||||
* axhttpd Features *
|
||||
*****************************************************************************
|
||||
|
||||
Basic Authentication
|
||||
====================
|
||||
|
||||
@ -16,30 +20,49 @@ utility program htpasswd is included to help manually edit .htpasswd files.
|
||||
The encryption of this password uses a proprietary algorithm due to the
|
||||
dependency of many crypt libraries on DES.
|
||||
|
||||
An example is in /test_dir/prot (username 'abcd', password is '1234').
|
||||
An example is in /test_dir/ssl_only (username 'abcd', password is '1234').
|
||||
|
||||
Note: This is an mconf configuration option.
|
||||
|
||||
HTTP Port Protection
|
||||
SSL Protection
|
||||
====================
|
||||
|
||||
Directories/files can be accessed using the 'http' or 'https' uri prefix. If
|
||||
normal http access for a directory needs to be disabled, then put
|
||||
"SSLRequireSSL" into a '.htaccess' file in the directory to be protected.
|
||||
|
||||
An example is in /test_dir/prot.
|
||||
Conversely, use "SSLDenySSL" to deny access to directories via SSL.
|
||||
|
||||
An example is in /test_dir/ssl_only and /test_dir/no_ssl.
|
||||
|
||||
Entire directories can be denied access with a "Deny all" directive
|
||||
(regardless of SSL or authentication).
|
||||
|
||||
CGI
|
||||
===
|
||||
|
||||
chroot() is now used for added security. However this has the impact of
|
||||
removing the regular filesystem, so any CGI applications no longer have the
|
||||
usual access.
|
||||
usual access (to things like /bin, /lib etc).
|
||||
|
||||
So any executables and libraries need to be copied into webroot (under /bin
|
||||
and /lib).
|
||||
So any executables and libraries need to be copied into webroot.
|
||||
|
||||
Failure to do so will result in mystical blank screens (and probably hundreds
|
||||
of axhttpd instances being created...).
|
||||
|
||||
Directory Listing
|
||||
=================
|
||||
|
||||
An mconf option. Allow the files in directories to be displayed.
|
||||
|
||||
Permissions Checking
|
||||
=====================
|
||||
|
||||
An mconf option. This will display the various file permissions to standard
|
||||
output of files in web root.
|
||||
|
||||
Other Features
|
||||
==============
|
||||
|
||||
Check the help options in mconf for all the other features used.
|
||||
|
||||
|
@ -71,7 +71,7 @@ struct connstruct
|
||||
char databuf[BLOCKSIZE];
|
||||
uint8_t is_ssl;
|
||||
uint8_t close_when_done;
|
||||
uint8_t modified_since;
|
||||
time_t if_modified_since;
|
||||
|
||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||
char cgiargs[MAXREQUESTLENGTH];
|
||||
@ -88,7 +88,7 @@ struct serverstruct
|
||||
struct serverstruct *next;
|
||||
int sd;
|
||||
int is_ssl;
|
||||
SSLCTX *ssl_ctx;
|
||||
SSL_CTX *ssl_ctx;
|
||||
};
|
||||
|
||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||
@ -99,7 +99,7 @@ struct cgiextstruct
|
||||
};
|
||||
#endif
|
||||
|
||||
// Global prototypes
|
||||
/* global prototypes */
|
||||
extern struct serverstruct *servers;
|
||||
extern struct connstruct *usedconns;
|
||||
extern struct connstruct *freeconns;
|
||||
@ -107,20 +107,26 @@ extern struct connstruct *freeconns;
|
||||
extern struct cgiextstruct *cgiexts;
|
||||
#endif
|
||||
|
||||
// conn.c prototypes
|
||||
/* conn.c prototypes */
|
||||
void removeconnection(struct connstruct *cn);
|
||||
|
||||
// proc.c prototypes
|
||||
/* proc.c prototypes */
|
||||
void procdodir(struct connstruct *cn);
|
||||
void procreadhead(struct connstruct *cn);
|
||||
void procsendhead(struct connstruct *cn);
|
||||
void procreadfile(struct connstruct *cn);
|
||||
void procsendfile(struct connstruct *cn);
|
||||
|
||||
// misc.c prototypes
|
||||
|
||||
/* misc.c prototypes */
|
||||
char *my_strncpy(char *dest, const char *src, size_t n);
|
||||
int isdir(const char *name);
|
||||
|
||||
// mime_types.c prototypes
|
||||
/* mime_types.c prototypes */
|
||||
void mime_init(void);
|
||||
const char *getmimetype(const char *fn);
|
||||
|
||||
/* tdate prototypes */
|
||||
void tdate_init(void);
|
||||
time_t tdate_parse(const char* str);
|
||||
|
||||
|
@ -120,6 +120,7 @@ int main(int argc, char *argv[])
|
||||
signal(SIGINT, sigint_cleanup);
|
||||
signal(SIGTERM, die);
|
||||
mime_init();
|
||||
tdate_init();
|
||||
|
||||
for (i = 0; i < INITIAL_CONNECTION_SLOTS; i++)
|
||||
{
|
||||
@ -587,7 +588,6 @@ static void addconnection(int sd, char *ip, int is_ssl)
|
||||
tp->state = STATE_WANT_TO_READ_HEAD;
|
||||
tp->reqtype = TYPE_GET;
|
||||
tp->close_when_done = 0;
|
||||
tp->modified_since = 0;
|
||||
tp->timeout = time(NULL) + CONFIG_HTTP_TIMEOUT;
|
||||
}
|
||||
|
||||
|
32
httpd/proc.c
32
httpd/proc.c
@ -67,7 +67,6 @@ static int procheadelem(struct connstruct *cn, char *buf)
|
||||
*delim = 0;
|
||||
value = delim+1;
|
||||
|
||||
/* printf("name: %s, value: %s\n", buf, value); */
|
||||
if (strcmp(buf, "GET") == 0 || strcmp(buf, "HEAD") == 0 ||
|
||||
strcmp(buf, "POST") == 0)
|
||||
{
|
||||
@ -89,6 +88,7 @@ static int procheadelem(struct connstruct *cn, char *buf)
|
||||
}
|
||||
|
||||
my_strncpy(cn->filereq, value, MAXREQUESTLENGTH);
|
||||
cn->if_modified_since = -1;
|
||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||
if ((cgi_delim = strchr(value, '?')))
|
||||
{
|
||||
@ -113,8 +113,7 @@ static int procheadelem(struct connstruct *cn, char *buf)
|
||||
}
|
||||
else if (strcmp(buf, "If-Modified-Since:") == 0)
|
||||
{
|
||||
/* TODO: parse this date properly with getdate() or similar */
|
||||
cn->modified_since = 1;
|
||||
cn->if_modified_since = tdate_parse(value);
|
||||
}
|
||||
#ifdef CONFIG_HTTP_HAS_AUTHORIZATION
|
||||
else if (strcmp(buf, "Authorization:") == 0 &&
|
||||
@ -408,13 +407,13 @@ void procsendhead(struct connstruct *cn)
|
||||
|
||||
strcpy(date, ctime(&now));
|
||||
|
||||
if (cn->modified_since)
|
||||
/* has the file been read before? */
|
||||
if (cn->if_modified_since != -1 && (cn->if_modified_since == 0 ||
|
||||
cn->if_modified_since >= stbuf.st_mtime))
|
||||
{
|
||||
/* file has already been read before */
|
||||
snprintf(buf, sizeof(buf), "HTTP/1.1 304 Not Modified\nServer: "
|
||||
"axhttpd V%s\nDate: %s\n", VERSION, date);
|
||||
special_write(cn, buf, strlen(buf));
|
||||
cn->modified_since = 0;
|
||||
cn->state = STATE_WANT_TO_READ_HEAD;
|
||||
return;
|
||||
}
|
||||
@ -442,7 +441,7 @@ void procsendhead(struct connstruct *cn)
|
||||
"Content-Type: %s\nContent-Length: %ld\n"
|
||||
"Date: %sLast-Modified: %s\n", VERSION,
|
||||
getmimetype(cn->actualfile), (long) stbuf.st_size,
|
||||
date, ctime(&(stbuf.st_mtime))); /* ctime() has a \n on the end */
|
||||
date, ctime(&stbuf.st_mtime)); /* ctime() has a \n on the end */
|
||||
|
||||
special_write(cn, buf, strlen(buf));
|
||||
|
||||
@ -977,15 +976,13 @@ static int htaccess_check(struct connstruct *cn)
|
||||
|
||||
while (fgets(line, sizeof(line), fp) != NULL)
|
||||
{
|
||||
if (!cn->is_ssl && strstr(line, "SSLRequireSSL"))
|
||||
if (strstr(line, "Deny all") || /* access to this dir denied */
|
||||
/* Access will be denied unless SSL is active */
|
||||
(!cn->is_ssl && strstr(line, "SSLRequireSSL")) ||
|
||||
/* Access will be denied if SSL is active */
|
||||
(cn->is_ssl && strstr(line, "SSLDenySSL")))
|
||||
{
|
||||
ret = -1; /* SSL port access required */
|
||||
break;
|
||||
}
|
||||
|
||||
if (strstr(line, "Deny all"))
|
||||
{
|
||||
ret = -1; /* access to this dir denied */
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -996,7 +993,7 @@ static int htaccess_check(struct connstruct *cn)
|
||||
|
||||
static void send_error(struct connstruct *cn, int err)
|
||||
{
|
||||
char buf[1024];
|
||||
char buf[MAXREQUESTLENGTH];
|
||||
char *title;
|
||||
char *text;
|
||||
|
||||
@ -1016,7 +1013,7 @@ static void send_error(struct connstruct *cn, int err)
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(buf, "HTTP/1.1 %d %s\n"
|
||||
snprintf(buf, MAXREQUESTLENGTH, "HTTP/1.1 %d %s\n"
|
||||
"Content-Type: text/html\n"
|
||||
"Cache-Control: no-cache,no-store\n"
|
||||
"Connection: close\n\n"
|
||||
@ -1026,4 +1023,3 @@ static void send_error(struct connstruct *cn, int err)
|
||||
special_write(cn, buf, strlen(buf));
|
||||
removeconnection(cn);
|
||||
}
|
||||
|
||||
|
107
httpd/tdate_parse.c
Normal file
107
httpd/tdate_parse.c
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright(C) 2007 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 <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "axhttp.h"
|
||||
|
||||
struct day_mon_map
|
||||
{
|
||||
const char* s;
|
||||
uint8_t l;
|
||||
};
|
||||
|
||||
static struct day_mon_map wday_tab[] =
|
||||
{
|
||||
{ "Sun", 0 }, { "Mon", 1 }, { "Tue", 2 }, { "Wed", 3 },
|
||||
{ "Thu", 4 }, { "Fri", 5 }, { "Sat", 6 },
|
||||
};
|
||||
|
||||
static struct day_mon_map mon_tab[] =
|
||||
{
|
||||
{ "Jan", 0 }, { "Feb", 1 }, { "Mar", 2 }, { "Apr", 3 },
|
||||
{ "May", 4 }, { "Jun", 5 }, { "Jul", 6 }, { "Aug", 7 },
|
||||
{ "Sep", 8 }, { "Oct", 9 }, { "Nov", 10 }, { "Dec", 11 },
|
||||
};
|
||||
|
||||
static int day_mon_map_compare(const char *v1, const char *v2)
|
||||
{
|
||||
return strcmp(((struct day_mon_map*)v1)->s, ((struct day_mon_map*)v2)->s);
|
||||
}
|
||||
|
||||
void tdate_init(void)
|
||||
{
|
||||
qsort(wday_tab, sizeof(wday_tab)/sizeof(struct day_mon_map),
|
||||
sizeof(struct day_mon_map),
|
||||
(int (*)(const void *, const void *))day_mon_map_compare);
|
||||
qsort(mon_tab, sizeof(mon_tab)/sizeof(struct day_mon_map),
|
||||
sizeof(struct day_mon_map),
|
||||
(int (*)(const void *, const void *))day_mon_map_compare);
|
||||
}
|
||||
|
||||
static int8_t day_mon_map_search(const char* str,
|
||||
const struct day_mon_map* tab, int n)
|
||||
{
|
||||
struct day_mon_map *search = bsearch(&str, tab, n,
|
||||
sizeof(struct day_mon_map),
|
||||
(int (*)(const void *, const void *))day_mon_map_compare);
|
||||
return search ? search->l : -1;
|
||||
}
|
||||
|
||||
time_t tdate_parse(const char* str)
|
||||
{
|
||||
struct tm tm;
|
||||
char str_mon[4], str_wday[4];
|
||||
int tm_sec, tm_min, tm_hour, tm_mday, tm_year;
|
||||
|
||||
/* Initialize. */
|
||||
memset(&tm, 0, sizeof(struct tm));
|
||||
|
||||
/* wdy, DD mth YY HH:MM:SS GMT */
|
||||
if ((sscanf(str, "%3[a-zA-Z], %d %3[a-zA-Z] %d %d:%d:%d GMT",
|
||||
str_wday, &tm_mday, str_mon, &tm_year, &tm_hour, &tm_min,
|
||||
&tm_sec) == 7) ||
|
||||
/* wdy mth DD HH:MM:SS YY */
|
||||
(sscanf(str, "%3[a-zA-Z] %3[a-zA-Z] %d %d:%d:%d %d",
|
||||
str_wday, str_mon, &tm_mday, &tm_hour, &tm_min, &tm_sec,
|
||||
&tm_year) == 7))
|
||||
{
|
||||
int8_t tm_wday = day_mon_map_search(str_wday, wday_tab,
|
||||
sizeof(wday_tab)/sizeof(struct day_mon_map));
|
||||
int8_t tm_mon = day_mon_map_search(str_mon, mon_tab,
|
||||
sizeof(mon_tab)/sizeof(struct day_mon_map));
|
||||
|
||||
if (tm_wday < 0 || tm_mon < 0)
|
||||
return -1;
|
||||
|
||||
tm.tm_wday = tm_wday;
|
||||
tm.tm_mon = tm_mon;
|
||||
tm.tm_mday = tm_mday;
|
||||
tm.tm_hour = tm_hour;
|
||||
tm.tm_min = tm_min;
|
||||
tm.tm_sec = tm_sec;
|
||||
tm.tm_year = tm_year - 1900;
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
return -1; /* error */
|
||||
}
|
Reference in New Issue
Block a user