Commit graph

183 commits

Author SHA1 Message Date
Laslo Hunhold
f6f98c9e64 Remove server-architecture specifics from serve() and add them to main()
To make the code a bit more flexible, let's get rid of the forking-code
in serve() and do it in main(). This way, we are more liberal in the
future to possibly handle it in a different way.
2018-02-05 17:15:29 +01:00
Laslo Hunhold
e35d3e1287 Refine manpage concerning the UNIX-domain socket file 2018-02-05 17:15:05 +01:00
Laslo Hunhold
33d3d85f4f Refine error messages
I forgot that they can fail with errno = 0, which indicates that the
given entry was not found.
2018-02-04 21:40:51 +01:00
Laslo Hunhold
2c74631df9 Update LICENSE 2018-02-04 21:33:33 +01:00
Laslo Hunhold
ccdb51b96d Refactor the single source file into multiple modules
And many other things, too many to list here. For example, it now
properly logs uds instead of erroring out.
Separating concerns in many places definitely improves the readability.
2018-02-04 21:27:33 +01:00
Laslo Hunhold
d480539e3e Homogenize license statement 2017-08-30 23:33:11 +02:00
Hiltjo Posthuma
5defa985db config.mk: improve feature test macros and compatibility
- add missing header netinet/in.h for socket declarations (POSIX).
- rename sendfile to responsefile, sendfile(2) is a syscall on FreeBSD.
- remove _XOPEN_SOURCE: this will give a warning about strptime on Linux
  glibc, but unbreaks the build on NetBSD and FreeBSD.

thanks also to josuah and quinq for testing!
2017-08-30 23:30:58 +02:00
Laslo Hunhold
7e199ee04d Don't default to clang 2017-08-14 00:06:26 +02:00
Laslo Hunhold
bf23f53b12 Update MANPREFIX according to FHS
http://www.pathname.com/fhs/2.2/fhs-4.11.html
2017-08-13 23:30:13 +02:00
Laslo Hunhold
bed475cef1 Make sure we flush the buffers before leaving 2017-08-08 22:06:21 +02:00
Laslo Hunhold
0b1c60eea2 Rename _i,_argused to i_,argused_
Thanks Michael Forney for reporting this! We cannot use identifiers
beginning with an underscore, says the C99-standard, section 7.1.3:

"All identifiers that begin with an underscore are always reserved for
use as identifiers with file scope in both the ordinary and tag name
spaces."

We go around this by putting the underscore at the end.
2017-08-04 17:57:58 +02:00
Laslo Hunhold
3a7c6ec0b9 Change the license formatting a bit to be in line with the OSI
The (c)-symbol has become more of a remnant after the Berne convention
has been signed. Given the ISC exploits some simplifications introduced
with the Berne convention, it just makes sense to drop this relict as
well and just state our Copyright without much ado about nothing.

https://opensource.org/licenses/ISC
2017-08-04 17:14:02 +02:00
Laslo Hunhold
08ef9966b5 Import updated arg.h from farbfeld 2017-08-04 17:12:54 +02:00
Laslo Hunhold
84d77d096b Import fixed arg.h from farbfeld
This fixes the handling of a { NULL } argv[] without returning argc =
-1.
2017-08-02 13:54:10 +02:00
Laslo Hunhold
075e314bdd Improve vhost handling and fix an uninitialized variable use
It was not a good thing to depend on the value of i so late in the code
again. If for some reason a loop is added beforehand it would break the
logic.
2017-08-02 08:51:16 +02:00
Laslo Hunhold
63bafbf1d1 Import rewritten arg.h from farbfeld 2017-08-02 08:38:06 +02:00
Quentin Rameau
ecb0d9e54e Do not remove existing socket file
Check for its presence and bail out if found.
If the socket file is present, either a server is already bound to it,
or the last one errored out and we'd want to inspect this.
Also it could be an unrelated file given by error.
2017-07-25 22:42:13 +02:00
Quentin Rameau
d2223ba259 Forward catched signals to children 2017-07-24 16:49:24 +02:00
Quentin Rameau
36ec9b2239 Re-localize insock, don't manually close the socket
The OS will take care of it.
2017-07-24 16:49:24 +02:00
Quentin Rameau
1a0eca12a5 Don't warn on cleanup unlink error
We may catch an exit signal before we actually bound to the socket.
2017-07-24 16:49:24 +02:00
Quentin Rameau
24167b5c07 Restore default handlers in children 2017-07-24 16:49:24 +02:00
Quentin Rameau
1c5f45c090 Handle more signals, replace signal() with sigaction() 2017-07-24 16:49:24 +02:00
Quentin Rameau
947b5a6a0a Register signal handlers in handlesignals() 2017-07-24 16:49:24 +02:00
Quentin Rameau
3373992ca5 Get rid of atexit()
This was a bad idea in a forking model where exit() is called from
children.
2017-07-24 16:49:24 +02:00
Quentin Rameau
0fed1d5bd2 Use die() instead of fprintf+exit 2017-07-24 16:49:24 +02:00
Quentin Rameau
820f644fe3 Don't ignore SIGCHLD in the main thread
We are waiting on the child process.
2017-07-24 16:49:24 +02:00
Quentin Rameau
da8a3d2e29 Fix typo in signal handler, SIGINT -> SIGCHLD 2017-07-24 16:49:24 +02:00
Quentin Rameau
b04ba86f9d Fix sending of zero-size files 2017-07-22 13:32:06 +02:00
Quentin Rameau
432898af71 Adjust last-byte-pos greater than files 2017-07-22 13:32:06 +02:00
Quentin Rameau
64e7dc3fda Fix Content-Length calculation 2017-07-22 13:32:06 +02:00
Hiltjo Posthuma
2a5ab48294 use extended regex and fix example regex for realsies 2017-07-22 13:23:10 +02:00
Hiltjo Posthuma
0fc6b0cccd don't allow named service->port translation
this will also mess up the redirect (to a named service otherwise).
2017-07-22 13:23:10 +02:00
Hiltjo Posthuma
4f2cc50416 if there is no matching vhost return 404 Not Found 2017-07-22 13:23:10 +02:00
Hiltjo Posthuma
c20aa17ae8 encode(): fix buffer-overflow and NUL terminate it 2017-07-22 13:23:10 +02:00
Laslo Hunhold
8ec042a1ba Properly escape backslash in regex 2017-07-21 18:37:55 +02:00
Laslo Hunhold
10d2ffe53a Fix example regex in vhosts
Thanks Hiltjo for noticing this!
2017-07-21 18:36:02 +02:00
Laslo Hunhold
a80f984ea3 Fix syntax error 2017-07-13 23:17:18 +02:00
Quentin Rameau
21115d4a1b Fix logic error in vhost chrooting (from e592bbc)
Thanks Hiltjo for having spotted it!
2017-07-13 21:11:06 +02:00
Laslo Hunhold
d7f5c6029e Fix the style a bit and prevent out-of-bounds index access for vhost[] 2017-07-11 15:02:24 +02:00
Laslo Hunhold
d3c1091669 Allow switching vhosts using flags and rework the usage 2017-07-11 15:02:00 +02:00
Quentin Rameau
141bb88af1 Cleanup socket file at exit.
We can't unlink the file if it's outside the chroot, so we need to keep
a simple worker outside of it.
2017-07-11 14:09:27 +02:00
Quentin Rameau
260ef0a988 Make the socketfile accessible by clients 2017-07-11 14:09:27 +02:00
Quentin Rameau
3b3fdd00e2 Split synopsis to reflect the dual usage. 2017-07-11 14:09:27 +02:00
Quentin Rameau
e46344e449 Change -U udsname to -U sockfile for clarification. 2017-07-11 14:09:27 +02:00
Laslo Hunhold
d7cf0d7f57 Reorder config.def.h a bit 2017-07-11 13:52:41 +02:00
Laslo Hunhold
06eba20e9d Add Quentin to LICENSE 2017-07-11 13:46:31 +02:00
Quentin Rameau
e592bbc0fe Integrate compiled regex into vhost array 2017-07-11 13:45:57 +02:00
Laslo Hunhold
233bf68b4b Style fix
Thanks Quentin!
2017-07-11 13:03:24 +02:00
Laslo Hunhold
000553d8c5 Add vhost support
As given in the config, we match a regex of hosts to a canonical host
which points to an internal directory.
Regexes are compiled on initialization, so we can error out early.
The rest is just modifications to use relative directories rather than
absolute ones, as we chdir() into the vhost directories dynamically.

Given we normalize the targets beforehand, there is no danger of
malformed requests escaping the vhost-context.
2017-07-11 12:55:39 +02:00
Laslo Hunhold
9e9facc9bf Properly serve empty files 2017-07-11 12:33:21 +02:00