diff --git a/CHANGELOG b/CHANGELOG index bcb7e8433..4b88744c1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Changes since 1.0.0 * -DCYGWIN replaced with -DCONFIG_PLATFORM_CYGWIN (and the same for solaris) axhttpd Changes +* main.c now becomes axhttpd.c * Header file issue fixed (in mime_types.c) * chroot() now used for better security * Basic authentication implemented (with .htpasswd) diff --git a/Makefile b/Makefile index 549fb8a88..6be5fbe5f 100644 --- a/Makefile +++ b/Makefile @@ -68,13 +68,15 @@ docs: # build the Win32 demo release version win32_demo: - -@rm -fr ../axTLS.release_test > /dev/null 2>&1 $(MAKE) win32releaseconf install: $(PREFIX) all cp --no-dereference $(STAGE)/libax* $(PREFIX)/lib chmod 755 $(PREFIX)/lib/libax* -install -m 755 $(STAGE)/ax* $(PREFIX)/bin +ifdef CONFIG_AXHTTPD + -install -m 755 $(STAGE)/htpasswd $(PREFIX)/bin +endif ifdef CONFIG_PERL_BINDINGS -install -m 755 $(STAGE)/axtlsp.pm `perl -e 'use Config; print $$Config{installarchlib};'` endif diff --git a/config/axhttpd.aip b/config/axhttpd.aip index be886602f..959385677 100755 --- a/config/axhttpd.aip +++ b/config/axhttpd.aip @@ -22,40 +22,22 @@ - - - - - - - - - + - - - - - - - - - - - + @@ -64,45 +46,25 @@ - - - - - - - - - - - - - + + - - - - - - - + - - - @@ -115,82 +77,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - + + + + - - - - - + + - - - - - + - - - - - + @@ -221,14 +127,6 @@ - - - - - - - - @@ -237,6 +135,7 @@ + diff --git a/config/win32config b/config/win32config index 13bb3c46b..6687e9070 100644 --- a/config/win32config +++ b/config/win32config @@ -10,7 +10,7 @@ CONFIG_PLATFORM_WIN32=y # # General Configuration # -PREFIX="/usr/local" +PREFIX="" # CONFIG_DEBUG is not set # @@ -51,17 +51,19 @@ CONFIG_WIN32_USE_CRYPTO_LIB=y CONFIG_AXHTTPD=y # -# Awhttpd Configuration +# Axhttpd Configuration # # CONFIG_HTTP_STATIC_BUILD is not set -CONFIG_HTTP_HTTPS_PORT=443 -CONFIG_HTTP_WEBROOT="www" CONFIG_HTTP_PORT=80 +CONFIG_HTTP_HTTPS_PORT=443 +CONFIG_HTTP_SESSION_CACHE_SIZE=5 +CONFIG_HTTP_WEBROOT="www" CONFIG_HTTP_TIMEOUT=5 # CONFIG_HTTP_HAS_CGI is not set CONFIG_HTTP_CGI_EXTENSIONS="" CONFIG_HTTP_DIRECTORIES=y # CONFIG_HTTP_PERM_CHECK is not set +CONFIG_HTTP_HAS_AUTHORIZATION=y # CONFIG_HTTP_HAS_IPV6 is not set CONFIG_HTTP_ALL_MIME_TYPES=y CONFIG_HTTP_VERBOSE=y diff --git a/httpd/Makefile b/httpd/Makefile index 2541c67af..e86cd5505 100644 --- a/httpd/Makefile +++ b/httpd/Makefile @@ -93,7 +93,7 @@ $(TARGET): $(OBJ) $(LD) $(LDFLAGS) $(LIBS) /out:$@ $(OBJ) $(TARGET2): htpasswd.obj - $(LD) $(LDFLAGS) $(LIBS) /out:$@ $(OBJ) + $(LD) $(LDFLAGS) $(LIBS) /out:$@ $< endif endif # CONFIG_AXHTTPD diff --git a/httpd/axhttpd.c b/httpd/axhttpd.c index e35a77387..bca16f83f 100644 --- a/httpd/axhttpd.c +++ b/httpd/axhttpd.c @@ -536,8 +536,15 @@ char *my_strncpy(char *dest, const char *src, size_t n) int isdir(const char *tpbuf) { struct stat st; + char path[MAXREQUESTLENGTH]; + strcpy(path, tpbuf); - if (stat(tpbuf, &st) == -1) +#ifdef WIN32 /* win32 stat() can't handle trailing '\' */ + if (path[strlen(path)-1] == '\\') + path[strlen(path)-1] = 0; +#endif + + if (stat(path, &st) == -1) return 0; if ((st.st_mode & S_IFMT) == S_IFDIR) diff --git a/httpd/htpasswd.c b/httpd/htpasswd.c index e4887f62a..54fbbfb88 100644 --- a/httpd/htpasswd.c +++ b/httpd/htpasswd.c @@ -64,6 +64,32 @@ static void usage(void) exit(1); } +#ifdef WIN32 +static char * getpass(const char *prompt) +{ + static char buf[127]; + FILE *fp = stdin; + + printf(prompt); TTY_FLUSH(); +#if 0 + fp = fopen("/dev/tty", "w"); + if (fp == NULL) + { + printf("null\n"); TTY_FLUSH(); + fp = stdin; + } +#endif + + fgets(buf, sizeof(buf), fp); + while (buf[strlen(buf)-1] < ' ') + buf[strlen(buf)-1] = '\0'; + + //if (fp != stdin) + // fclose(fp); + return buf; +} +#endif + int main(int argc, char *argv[]) { char* pw; diff --git a/httpd/proc.c b/httpd/proc.c index d0a4ebe71..d6f6788a7 100644 --- a/httpd/proc.c +++ b/httpd/proc.c @@ -26,6 +26,8 @@ #include #include "axhttp.h" +static const char * index_file = "index.html"; + static int special_read(struct connstruct *cn, void *buf, size_t count); static int special_write(struct connstruct *cn, const uint8_t *buf, size_t count); @@ -333,7 +335,7 @@ void procsendhead(struct connstruct *cn) if (auth_check(cn)) /* see if there is a '.htpasswd' file */ { #ifdef CONFIG_HTTP_VERBOSE - printf("axhttpd: access to %s denied\n", cn->actualfile); TTY_FLUSH(); + printf("axhttpd: access to %s denied\n", cn->filereq); TTY_FLUSH(); #endif removeconnection(cn); return; @@ -370,12 +372,12 @@ void procsendhead(struct connstruct *cn) #endif /* look for "index.html"? */ - if ((stbuf.st_mode & S_IFMT) == S_IFDIR) + if (isdir(cn->actualfile)) { char tbuf[MAXREQUESTLENGTH]; - sprintf(tbuf, "%s%s", cn->actualfile, "index.html"); + sprintf(tbuf, "%s%s", cn->actualfile, index_file); if (stat(tbuf, &stbuf) != -1) - strcat(cn->actualfile, "index.html"); + strcat(cn->actualfile, index_file); else { #if defined(CONFIG_HTTP_DIRECTORIES) @@ -445,8 +447,7 @@ void procsendhead(struct connstruct *cn) special_write(cn, buf, strlen(buf)); #ifdef CONFIG_HTTP_VERBOSE - printf("axhttpd: %s send %s\n", - cn->is_ssl ? "https" : "http", cn->actualfile); + printf("axhttpd: %s:/%s\n", cn->is_ssl ? "https" : "http", cn->filereq); TTY_FLUSH(); #endif @@ -600,23 +601,14 @@ static void proccgi(struct connstruct *cn, int has_pathinfo) execv(cn->actualfile, myargs); #else /* WIN32 */ - _pipe(tpipe, 4096, O_BINARY| O_NOINHERIT); + _pipe(tpipe, 8192, O_BINARY| O_NOINHERIT); myargs[0] = "sh"; myargs[1] = "-c"; - myargs[2] = cn->actualfile; + myargs[2] = &cn->filereq[1]; /* ignore the inital "/" */ myargs[3] = cn->cgiargs; myargs[4] = NULL; - /* convert all the forward slashes to back slashes */ - { - char *t = myargs[2]; - while ((t = strchr(t, '\\'))) - { - *t++ = '/'; - } - } - tmp_stdout = _dup(_fileno(stdout)); _dup2(tpipe[1], _fileno(stdout)); close(tpipe[1]); @@ -793,6 +785,7 @@ static void buildactualfile(struct connstruct *cn) char *cp; snprintf(cn->actualfile, MAXREQUESTLENGTH, "%s", cn->filereq); +#ifndef WIN32 /* Add directory slash if not there */ if (isdir(cn->actualfile) && cn->actualfile[strlen(cn->actualfile)-1] != '/') @@ -804,17 +797,32 @@ static void buildactualfile(struct connstruct *cn) cn->dirname[0] = 0; else *cp = 0; - -#ifdef WIN32 - /* convert all the forward slashes to back slashes */ +#else { + char curr_dir[MAXREQUESTLENGTH]; + char path[MAXREQUESTLENGTH]; char *t = cn->actualfile; + + GetCurrentDirectory(MAXREQUESTLENGTH, curr_dir); + + /* convert all the forward slashes to back slashes */ while ((t = strchr(t, '/'))) *t++ = '\\'; - t = cn->dirname; - while ((t = strchr(t, '/'))) - *t++ = '\\'; + snprintf(path, MAXREQUESTLENGTH, "%s%s", curr_dir, cn->actualfile); + memcpy(cn->actualfile, path, MAXREQUESTLENGTH); + + /* Add directory slash if not there */ + if (isdir(cn->actualfile) && + cn->actualfile[strlen(cn->actualfile)-1] != '\\') + strcat(cn->actualfile, "\\"); + + /* work out the directory name */ + strncpy(cn->dirname, cn->actualfile, MAXREQUESTLENGTH); + if ((cp = strrchr(cn->dirname, '\\')) == NULL) + cn->dirname[0] = 0; + else + *cp = 0; } #endif } @@ -998,8 +1006,7 @@ static void send_error(struct connstruct *cn, int err) title = "Forbidden"; text = "File is protected"; #ifdef CONFIG_HTTP_VERBOSE - printf("axhttpd: access to %s:/%s denied\n", - cn->is_ssl ? "https" : "http", cn->actualfile); TTY_FLUSH(); + printf("axhttpd: access to %s denied\n", cn->filereq); TTY_FLUSH(); #endif break; diff --git a/www/test_dir/prot/.htpasswd b/www/test_dir/prot/.htpasswd index 16d3fe1a3..333d9173c 100644 --- a/www/test_dir/prot/.htpasswd +++ b/www/test_dir/prot/.htpasswd @@ -1 +1,3 @@ abcd:CQhgDPyy0rvEU8OMxnQIvg==$YdJfIKZimFLYxPf/rbnhtQ== +yaya:Syuss5jE2FNGVdr0kKGoHg==$WLw/SgHZFuAoOuml3GTJVw== +