Documentation Source Text

Check-in [a537e6f3fc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhancements to althttpd.c: Add the --input FILE command-line option to simplify debugging using lldb. Improvements to comments.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a537e6f3fcc89bc13b0ef92d8e958ac751841b7d35ac97c4cac9225982564818
User & Date: drh 2019-02-15 17:00:20
Context
2019-02-15
18:16
In althttpd.c, refactor some of the CGI processing logic as a preliminary step toward adding SCGI support. check-in: 3e667aef3a user: drh tags: trunk
17:00
Enhancements to althttpd.c: Add the --input FILE command-line option to simplify debugging using lldb. Improvements to comments. check-in: a537e6f3fc user: drh tags: trunk
11:43
Fix a typo in the ALTER TABLE documentation. check-in: 625c9fbdad user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to misc/althttpd.c.

     6      6   **     * Launched from inetd/xinetd/stunnel4, or as a stand-alone server
     7      7   **     * One process per request
     8      8   **     * Deliver static content or run CGI
     9      9   **     * Virtual sites based on the "Host:" property of the HTTP header
    10     10   **     * Runs in a chroot jail
    11     11   **     * Unified log file in a CSV format
    12     12   **     * Small code base (this 1 file) to facilitate security auditing
    13         -**     * Simple setup - no configuration files to mess with.
           13  +**     * Simple setup - no configuration files to misconfigure
    14     14   ** 
    15     15   ** This file implements a small and simple but secure and effective web
    16     16   ** server.  There are no frills.  Anything that could be reasonably
    17     17   ** omitted has been.
    18     18   **
    19     19   ** Setup rules:
    20     20   **
    21     21   **    (1) Launch as root from inetd like this:
    22     22   **
    23     23   **            httpd -logfile logfile -root /home/www -user nobody
    24     24   **
    25         -**        It will automatically chroot to /home/www and become user nobody.
           25  +**        It will automatically chroot to /home/www and become user "nobody".
    26     26   **        The logfile name should be relative to the chroot jail.
    27     27   **
    28         -**    (2) Directories of the form "*.website" (ex: www_hwaci_com.website)
           28  +**    (2) Directories of the form "*.website" (ex: www_sqlite_org.website)
    29     29   **        contain content.  The directory is chosen based on the HTTP_HOST
    30     30   **        request header.  If there is no HTTP_HOST header or if the
    31     31   **        corresponding host directory does not exist, then the
    32     32   **        "default.website" is used.  If the HTTP_HOST header contains any
    33     33   **        charaters other than [a-zA-Z0-9_.,*~/] then a 403 error is
    34     34   **        generated.
    35     35   **
................................................................................
  1441   1441          NotFound(300); /* LOG: Path element begins with "." or "-" */
  1442   1442       }
  1443   1443     }
  1444   1444   
  1445   1445     /* Figure out what the root of the filesystem should be.  If the
  1446   1446     ** HTTP_HOST parameter exists (stored in zHttpHost) then remove the
  1447   1447     ** port number from the end (if any), convert all characters to lower
  1448         -  ** case, and convert all "." to "_".  Then try to find a directory
  1449         -  ** with that name and the extension .website.  If not found, look
  1450         -  ** for "default.website".
         1448  +  ** case, and convert non-alphanumber characters (including ".") to "_".
         1449  +  ** Then try to find a directory with that name and the extension .website.
         1450  +  ** If not found, look for "default.website".
  1451   1451     */
  1452   1452     if( zScript[0]!='/' ){
  1453   1453       NotFound(310); /* LOG: URI does not start with "/" */
  1454   1454     }
  1455   1455     if( strlen(zRoot)+40 >= sizeof(zLine) ){
  1456         -     NotFound(320); /* LOG: URI too long */
         1456  +    NotFound(320); /* LOG: URI too long */
  1457   1457     }
  1458   1458     if( zHttpHost==0 || zHttpHost[0]==0 ){
  1459   1459       NotFound(330);  /* LOG: Missing HOST: parameter */
  1460   1460     }else if( strlen(zHttpHost)+strlen(zRoot)+10 >= sizeof(zLine) ){
  1461   1461       NotFound(340);  /* LOG: HOST parameter too long */
  1462   1462     }else{
  1463   1463       sprintf(zLine, "%s/%s", zRoot, zHttpHost);
................................................................................
  2013   2013         if( atoi(zArg)==0 ){
  2014   2014           useChrootJail = 0;
  2015   2015         }
  2016   2016       }else if( strcmp(z, "-debug")==0 ){
  2017   2017         if( atoi(zArg) ){
  2018   2018           useTimeout = 0;
  2019   2019         }
         2020  +    }else if( strcmp(z, "-input")==0 ){
         2021  +      fclose(stdin);
         2022  +      stdin = fopen(zArg, "rb");
         2023  +      if( stdin==0 ){
         2024  +        Malfunction(501, /* LOG: cannot open --input file */
         2025  +                    "cannot open --input file \"%s\"\n", zArg);
         2026  +      }
  2020   2027       }else if( strcmp(z, "-datetest")==0 ){
  2021   2028         TestParseRfc822Date();
  2022   2029         printf("Ok\n");
  2023   2030         exit(0);
  2024   2031       }else{
  2025   2032         Malfunction(510, /* LOG: unknown command-line argument on launch */
  2026   2033                     "unknown argument: [%s]\n", z);
................................................................................
  2159   2166   INSERT INTO xref VALUES(450,'dup(1) failed');
  2160   2167   INSERT INTO xref VALUES(460,'Excess URI content past static file name');
  2161   2168   INSERT INTO xref VALUES(470,'ETag Cache Hit');
  2162   2169   INSERT INTO xref VALUES(480,'fopen() failed for static content');
  2163   2170   INSERT INTO xref VALUES(2,'Normal HEAD reply');
  2164   2171   INSERT INTO xref VALUES(0,'Normal reply');
  2165   2172   INSERT INTO xref VALUES(500,'unknown IP protocol');
         2173  +INSERT INTO xref VALUES(501,'cannot open --input file');
  2166   2174   INSERT INTO xref VALUES(510,'unknown command-line argument on launch');
  2167   2175   INSERT INTO xref VALUES(520,'--root argument missing');
  2168   2176   INSERT INTO xref VALUES(530,'chdir() failed');
  2169   2177   INSERT INTO xref VALUES(540,'chroot() failed');
  2170   2178   INSERT INTO xref VALUES(550,'server startup failed');
  2171   2179   INSERT INTO xref VALUES(560,'setgid() failed');
  2172   2180   INSERT INTO xref VALUES(570,'setuid() failed');
  2173   2181   INSERT INTO xref VALUES(580,'unknown user');
  2174   2182   INSERT INTO xref VALUES(590,'cannot run as root');
  2175   2183   INSERT INTO xref VALUES(600,'malloc() failed');
  2176   2184   INSERT INTO xref VALUES(610,'malloc() failed');
  2177   2185   COMMIT;
  2178   2186   #endif /* SQL */