aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-02-11 11:54:16 +0000
committerRon Yorston <rmy@pobox.com>2024-02-11 11:54:16 +0000
commit58627310e90247040894d3aeab2fc79bcced11be (patch)
tree899d60c13f3fd6d6c07fe9df83a00b3220fbe61c /networking
parent5809565f70bd51451ef51da7dfc33716458abec3 (diff)
downloadbusybox-w32-58627310e90247040894d3aeab2fc79bcced11be.tar.gz
busybox-w32-58627310e90247040894d3aeab2fc79bcced11be.tar.bz2
busybox-w32-58627310e90247040894d3aeab2fc79bcced11be.zip
httpd: enable interpreter script feature
The web server in BusyBox has an optional feature to allow pages with a given suffix to be processed by a script interpreter: PHP, for example. Enable this in the busybox-w32 build. Costs 256-320 bytes. (GitHub issue #266)
Diffstat (limited to 'networking')
-rw-r--r--networking/httpd.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 26656fd16..c76ce3658 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1580,7 +1580,6 @@ static void cgi_handler(char **argv)
1580{ 1580{
1581 struct fd_pair fromCgi; /* CGI -> httpd pipe */ 1581 struct fd_pair fromCgi; /* CGI -> httpd pipe */
1582 struct fd_pair toCgi; /* httpd -> CGI pipe */ 1582 struct fd_pair toCgi; /* httpd -> CGI pipe */
1583 char *dir, *script;
1584 1583
1585 xfunc_error_retval = 242; 1584 xfunc_error_retval = 242;
1586 1585
@@ -1595,16 +1594,12 @@ static void cgi_handler(char **argv)
1595 xmove_fd(toCgi.rd, 0); /* replace stdin with the pipe */ 1594 xmove_fd(toCgi.rd, 0); /* replace stdin with the pipe */
1596 xmove_fd(fromCgi.wr, 1); /* replace stdout with the pipe */ 1595 xmove_fd(fromCgi.wr, 1); /* replace stdout with the pipe */
1597 1596
1598 dir = argv[1]; 1597 if (argv[1][0] && chdir_or_warn(argv[1]) != 0) {
1599 script = argv[2];
1600
1601 if (chdir_or_warn(dir) != 0) {
1602 goto error_execing_cgi; 1598 goto error_execing_cgi;
1603 } 1599 }
1604 1600
1605 /* set argv[0] to name without path */ 1601 /* set argv[0] to name without path */
1606 argv[0] = script; 1602 argv += 2;
1607 argv[1] = NULL;
1608 1603
1609 /* _NOT_ execvp. We do not search PATH. argv[0] is a filename 1604 /* _NOT_ execvp. We do not search PATH. argv[0] is a filename
1610 * without any dir components and will only match a file 1605 * without any dir components and will only match a file
@@ -1655,6 +1650,7 @@ static void send_cgi_and_exit(
1655 char *script, *last_slash; 1650 char *script, *last_slash;
1656 int pid; 1651 int pid;
1657#if ENABLE_PLATFORM_MINGW32 1652#if ENABLE_PLATFORM_MINGW32
1653 const char *script_dir;
1658 char **argv; 1654 char **argv;
1659#endif 1655#endif
1660 1656
@@ -1693,7 +1689,11 @@ static void send_cgi_and_exit(
1693 *script = '\0'; /* cut off /PATH_INFO */ 1689 *script = '\0'; /* cut off /PATH_INFO */
1694 1690
1695 /* SCRIPT_FILENAME is required by PHP in CGI mode */ 1691 /* SCRIPT_FILENAME is required by PHP in CGI mode */
1692#if ENABLE_PLATFORM_MINGW32
1693 if (!is_relative_path(home_httpd)) {
1694#else
1696 if (home_httpd[0] == '/') { 1695 if (home_httpd[0] == '/') {
1696#endif
1697 char *fullpath = concat_path_file(home_httpd, url); 1697 char *fullpath = concat_path_file(home_httpd, url);
1698 setenv1("SCRIPT_FILENAME", fullpath); 1698 setenv1("SCRIPT_FILENAME", fullpath);
1699 } 1699 }
@@ -1745,13 +1745,15 @@ static void send_cgi_and_exit(
1745 1745
1746#if ENABLE_PLATFORM_MINGW32 1746#if ENABLE_PLATFORM_MINGW32
1747 /* Find script's dir */ 1747 /* Find script's dir */
1748 script_dir = "";
1748 script = last_slash; 1749 script = last_slash;
1749 if (script != url) { /* paranoia */ 1750 if (script != url) { /* paranoia */
1750 *script = '\0'; 1751 *script = '\0';
1752 script_dir = url + 1;
1751 } 1753 }
1752 script++; 1754 script++;
1753 1755
1754 argv = xzalloc((server_argc + 8) * sizeof(char *)); 1756 argv = xzalloc((server_argc + 9) * sizeof(char *));
1755 argv[0] = (char *)bb_busybox_exec_path; 1757 argv[0] = (char *)bb_busybox_exec_path;
1756 argv[1] = (char *)"--busybox"; 1758 argv[1] = (char *)"--busybox";
1757 argv[2] = (char *)"-httpd"; // don't daemonise in main() 1759 argv[2] = (char *)"-httpd"; // don't daemonise in main()
@@ -1759,9 +1761,27 @@ static void send_cgi_and_exit(
1759 memcpy(argv + 4, server_argv, sizeof(*argv) * server_argc); 1761 memcpy(argv + 4, server_argv, sizeof(*argv) * server_argc);
1760 argv[server_argc + 4] = xasprintf("%d:%d:%d:%d", toCgi.wr, toCgi.rd, 1762 argv[server_argc + 4] = xasprintf("%d:%d:%d:%d", toCgi.wr, toCgi.rd,
1761 fromCgi.wr, fromCgi.rd); 1763 fromCgi.wr, fromCgi.rd);
1762 argv[server_argc + 5] = (char *)url + 1; // script directory 1764 argv[server_argc + 5] = (char *)script_dir; // script directory
1763 argv[server_argc + 6] = (char *)script; // script name 1765 argv[server_argc + 6] = (char *)script; // script name
1764 /* argv[server_argc + 7] = NULL; - xzalloc did it */ 1766
1767#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
1768 {
1769 char *suffix = strrchr(script, '.');
1770
1771 if (suffix) {
1772 Htaccess *cur;
1773 for (cur = script_i; cur; cur = cur->next) {
1774 if (strcmp(cur->before_colon + 1, suffix) == 0) {
1775 /* found interpreter name */
1776 argv[server_argc + 6] = (char *)cur->after_colon;
1777 argv[server_argc + 7] = (char *)script;
1778 break;
1779 }
1780 }
1781 }
1782 }
1783#endif
1784 /* argv[server_argc + N] = NULL; - xzalloc did it */
1765 1785
1766 pid = foreground ? mingw_spawn(argv) : mingw_spawn_detach(argv); 1786 pid = foreground ? mingw_spawn(argv) : mingw_spawn_detach(argv);
1767 if (pid == -1) 1787 if (pid == -1)