]> cat aescling's git repositories - httpd-execline.git/commitdiff
isolate chroot-exclusive contents
authorsingle-right-quote <34298117+single-right-quote@users.noreply.github.com>
Fri, 14 Aug 2020 19:57:23 +0000 (19:57 +0000)
committersingle-right-quote <34298117+single-right-quote@users.noreply.github.com>
Fri, 14 Aug 2020 20:03:09 +0000 (20:03 +0000)
also rename several folders in anticipation of further restructuring

as a bonus, `supported-hostname-test.execline` no longer needs special cases

23 files changed:
binaries/supported-hostname-test.execline [deleted file]
run.template
visible-to-httpd/binaries/get-line-from-client.execline [moved from binaries/get-line-from-client.execline with 100% similarity]
visible-to-httpd/binaries/headers.execline [moved from binaries/headers.execline with 100% similarity]
visible-to-httpd/binaries/http-error-response.execline [moved from binaries/http-error-response.execline with 83% similarity]
visible-to-httpd/binaries/http-header-parse.execline [moved from binaries/http-header-parse.execline with 100% similarity]
visible-to-httpd/binaries/http-start-line-parse.execline [moved from binaries/http-start-line-parse.execline with 100% similarity]
visible-to-httpd/binaries/httpd.execline [moved from binaries/httpd.execline with 90% similarity]
visible-to-httpd/binaries/log.execline [moved from binaries/log.execline with 100% similarity]
visible-to-httpd/binaries/supported-hostname-test.execline [new file with mode: 0755]
visible-to-httpd/configuration/Content-Type_table/c [moved from data/Content-Type_table/c with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/css [moved from data/Content-Type_table/css with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/execline [moved from data/Content-Type_table/execline with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/html [moved from data/Content-Type_table/html with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/ico [moved from data/Content-Type_table/ico with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/jpeg [moved from data/Content-Type_table/jpeg with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/jpg [moved from data/Content-Type_table/jpg with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/js [moved from data/Content-Type_table/js with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/market [moved from data/Content-Type_table/market with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/png [moved from data/Content-Type_table/png with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/txt [moved from data/Content-Type_table/txt with 100% similarity]
visible-to-httpd/configuration/Content-Type_table/xhtml [moved from data/Content-Type_table/xhtml with 100% similarity]
visible-to-httpd/configuration/default_headers/default.example [moved from data/extra_headers/default.example with 100% similarity]

diff --git a/binaries/supported-hostname-test.execline b/binaries/supported-hostname-test.execline
deleted file mode 100755 (executable)
index 80a7af9..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/binaries/execlineb -WS1
-# `supported-hostname-test.execline hostname`
-# 
-# tests if `hostname` is supported by this server, by checking if
-# a directory by that exact name exists in the current working directory  
-# immediately 404s otherwise
-#
-# hard depends on these external `httpd.execline` subscripts:
-#
-# + ./http-error-response.execline: and thus,
-# + ./log.execline
-#
-
-# protect Special Subdirectories
-#
-# + `/binaries` is change root--available static binaries and helper scripts
-# + `tcp-access-rules` for the pseudo-firewall
-# + `.` and `..` are to disallow clients being Naughty
-# + the other directories are for process supervision things
-#
-# note: general policy for this server is to 404 where we "should" 403.
-#
-ifelse {
-       s6-test \${1} = binaries -o
-               \${1} = data -o
-               \${1} = event -o
-               \${1} = log -o
-               \${1} = supervise -o
-               \${1} = tcp-access-rules -o
-               \${1} = . -o
-               \${1} = ..
-}
-{
-       if {
-               http-error-response.execline
-                       404
-                       "not found"
-                       "illegal host: \""${1}\"
-       }
-       exit 1
-}
-# reject unsupported hostnames
-#
-ifelse { s6-test ! -d \${1} }
-{
-       if {
-               http-error-response.execline
-                       404
-                       "not found"
-                       "unsupported host: \""${1}\"
-       }
-       exit 1
-}
-exit 0
index 342814e3bc9bcb9283e76ffad989b474b0493a9a..b74022d793fe2318cd560d66c5b343d3eaab0f00 100755 (executable)
@@ -21,6 +21,8 @@ export TLS_GID ${YOUR_TLS_USER_GROUP_ID_HERE}
 # user for ./binaries/httpd.execline (after `chroot(8)`)
 s6-envuidgid ${YOUR_HTTP_USER_NAME_HERE}
 
+cd visible-to-httpd
+
 # somewhat verbose command line to make the httpd able to log the PID reported by s6-tcpserver  
 # (s6-tcpserver prints the pid of `s6-tlsd`, but `./httpd.execline` is a child of said PID)
 s6-tcpserver4
similarity index 83%
rename from binaries/http-error-response.execline
rename to visible-to-httpd/binaries/http-error-response.execline
index 934d716e99b5a0e131aa668a6bac650c2c13d9ad..0fae1983605a73eeb19756d26baf31b659cae5a8 100755 (executable)
@@ -1,7 +1,7 @@
 #!/binaries/execlineb -WS2
 # http-error-response.execline STATUS_CODE STATUS_MESSAGE [LOG_MESSAGE]
 #
-# if `data/status-code/table/${hostname}/${STATUS_CODE} exists, `cat(1)` that
+# if `configuration/status-code/table/${hostname}/${STATUS_CODE} exists, `cat(1)` that
 # otherwise, fall back on a very generic error message
 #
 # TODO:
@@ -28,7 +28,7 @@ backtick -i -n Content-Length {
 
 backtick -i -n Date { date -u "+%a, %d %b %Y %T GMT" }
 
-backtick -i -n extra_headers { cat data/extra_headers/default }
+backtick -i -n extra_headers { cat configuration/default_headers/default }
 
 multisubstitute {
 # TODO:        importas -i -u Content-Length Content-Length
@@ -47,10 +47,10 @@ Date: "${Date}"\r
 }
 
 if {
-       ifelse { s6-test -r data/status-code_table/${hostname}/${1} }
+       ifelse { s6-test -r configuration/error_response_pages/${hostname}/${1} }
        {
                # TODO: support `Content-Types`?? and `Content-Length`
-               cat data/status-code_table/${hostname}/${1}
+               cat configuration/error_response_pages/${hostname}/${1}
        }
                s6-echo -n -- "<!DOCTYPE html>
 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
similarity index 90%
rename from binaries/httpd.execline
rename to visible-to-httpd/binaries/httpd.execline
index cf3607546e872751190897b9e29ec2909bcf6adf..32fb08d1011cb1fad55697695cd03679b412e549 100755 (executable)
@@ -104,6 +104,8 @@ if -X -n -t {
 
        #### 3. process requested resource ###
        backtick -i -n resource {
+               cd supported_domains
+
                backtick -i -n candidate_resource {
                        backtick -in with_dot_and_dot_dot {
                                pipeline { s6-echo -n -- ${requested_resource} }
@@ -134,7 +136,8 @@ if -X -n -t {
                        s6-echo -n -- ${candidate_resource}
        }
        importas -i resource resource
-       ifelse { s6-test ! -r \${resource} }
+
+       ifelse { s6-test ! -r supported_domains/${resource} }
        {
                http-error-response.execline
                        404
@@ -172,18 +175,18 @@ if -X -n -t {
                        tr := ./
                }
 
-               # use `./data/Content-Type_table` as a key-value store: files with
+               # use `./configuration/Content-Type_table` as a key-value store: files with
                # the name ${extension} map to the `Content-Type` embedded in
-               # their contents. for example, `./data/Content-Type_table/xhtml`
+               # their contents. for example, `./configuration/Content-Type_table/xhtml`
                # contains the text “application/xhtml+xml” (with no newline)  
                # (it is fine if the file contains a single newline at the end)
                #
                # if no key exists with the extension’s name, we fall back on
                # “application/octet-stream”, as we should
                importas -i -u extension extension
-               ifelse { s6-test -r \\./data/Content-Type_table/${extension} }
+               ifelse { s6-test -r configuration/Content-Type_table/${extension} }
                {
-                       cat ./data/Content-Type_table/${extension}
+                       cat configuration/Content-Type_table/${extension}
                }
                        s6-echo -n -- application/octet-stream
        }
@@ -192,7 +195,7 @@ if -X -n -t {
        # TODO: separate this out, ideally make reusable
 
        # file length in bytes: SHOULD be provided
-       backtick -i -n Content-Length { stat -c%s -- ${resource} }
+       backtick -i -n Content-Length { stat -c%s -- supported_domains/${resource} }
 
        # "[weekday], [month-day] [month] [year] [hours:minutes:seconds] GMT"  
        # (example: "Tue, 03 Mar 2020 21:06:08 GMT")
@@ -200,7 +203,7 @@ if -X -n -t {
 
        # the date the resource was last modified SHOULD be provided
        backtick -i -n Last-Modified {
-               backtick -i -n seconds_since_epoch { stat -c%Y -- ${resource} }
+               backtick -i -n seconds_since_epoch { stat -c %Y -- supported_domains/${resource} }
                importas -i -u seconds_since_epoch seconds_since_epoch
                date -d @${seconds_since_epoch} -u ${date_format}
        }
@@ -208,23 +211,22 @@ if -X -n -t {
        # current time of response: SHOULD be provided (why?)
        backtick -i -n Date { date -u ${date_format} }
 
-
        # allow for arbitrary HTTP header and HTTP status code overrides.
        # for an example where the former might be useful, consider Content
        # Security Policy; for the latter, consider HTTP 301 redirects
        #
        # be warned!! we do not validate these overrides!
        backtick -i -n extra_headers {
-               ifelse { s6-test -r \\data/extra_headers/override/${resource} }
+               ifelse { s6-test -r configuration/default_headers/override/${resource} }
                {
-                       cat data/extra_headers/override/${resource}
+                       cat configuration/default_headers/override/${resource}
                }
-                       cat data/extra_headers/default
+                       cat configuration/default_headers/default
        }
 
        backtick -D "200 ok" -n status_code_and_message {
-               if { s6-test -r \\data/status_override/${resource} }
-                       cat data/status_override/${resource}
+               if { s6-test -r configuration/overrides/${resource} }
+                       cat configuration/overrides/${resource}
        }
 
        ##### 4.3. send the response ###
@@ -248,7 +250,7 @@ Date: "${Date}"\r
        }
        foreground {
                if -t { s6-test \${method} = GET }
-                       cat ${resource}
+                       cat supported_domains/${resource}
        }
        # hack: write(3p) does not guarantee that all the
        # content actually gets written before this process
diff --git a/visible-to-httpd/binaries/supported-hostname-test.execline b/visible-to-httpd/binaries/supported-hostname-test.execline
new file mode 100755 (executable)
index 0000000..060537e
--- /dev/null
@@ -0,0 +1,26 @@
+#!/binaries/execlineb -WS1
+# `supported-hostname-test.execline hostname`
+# 
+# tests if `hostname` is supported by this server, by checking if
+# a directory by that exact name exists in the current working directory  
+# immediately 404s otherwise
+#
+# hard depends on these external `httpd.execline` subscripts:
+#
+# + ./http-error-response.execline: and thus,
+# + ./log.execline
+#
+
+# reject unsupported hostnames
+#
+ifelse { s6-test ! -d \supported_domains/${1} }
+{
+       if {
+               http-error-response.execline
+                       404
+                       "not found"
+                       "unsupported host: \""${1}\"
+       }
+       exit 1
+}
+exit 0