Commit graph

201 commits

Author SHA1 Message Date
Josuah Demangeon
c3ddb2dd14 permit prefix to be empty in -v format string
The previous parsing of the -v vhosts made sure there were 4 tokens.
If there was no prefix specified, usage() is called.  Now, it only
checks for the firsts 3, with .prefix set to null if there are only
3 tokens.
2018-04-02 09:57:58 +02:00
Josuah Demangeon
69bb7710eb fix segfault on parsing of -v and -m
The length is initially 0 so it needs to be incremented before
reallocarray to avoid ...alloc(0); and keep some space for the element
to insert.
2018-04-02 09:53:41 +02:00
Laslo Hunhold
6770dc06e6 Add netinet/in.h to sock.c
It was missing but necessary for some defines.
2018-03-05 10:24:46 +01:00
Laslo Hunhold
a20136fa18 Update the documentation to reflect the new flag-centric usage 2018-03-05 09:51:29 +01:00
Hiltjo Posthuma
444b8f5b32 http_send_response: fix undefined behaviour for copying the target string
... the format string and buffer were the same (undefined behaviour).
2018-03-05 01:21:14 +01:00
Laslo Hunhold
ed8b7e8954 Fix a logic error
We want to xor s.host and udsname, so it especially errors out when none
are given.
2018-03-05 01:04:51 +01:00
Hiltjo Posthuma
01ed0dac83 util: don't initialize server, it's already done in main()
... this removes a stupid compiler warning too.
2018-03-05 01:00:50 +01:00
Laslo Hunhold
c8401c591f Add esnprintf() and refactor some code
The (size_t) discards the case where the return value of snprintf is < 0. This
is rather unlikely, but we'll keep it in mind anyway.
2018-03-05 00:59:37 +01:00
Laslo Hunhold
1879e14e79 Be extra pedantic again and remove all warnings
Since now config.def.h has been reduced we don't have any more unused
variables and thus the manual fiddling with error-levels is no longer
necessary.
To get a completely clean result though we have to still cast some
variables here and there.
2018-03-05 00:30:53 +01:00
Quentin Rameau
3ff3e5ea6e Add some missing headers and interface visibility macro
strings.h for strncasecmp
time.h for strptime
2018-03-05 00:21:54 +01:00
Laslo Hunhold
6b55e36036 Introduce flag-centric usage
The config.h-interface has proven to be very effective for a lot of
suckless tools, but it just does not make too much sense for a web
server like quark.

 $ quark

If you run multiple instances of it, you want to see in the command line
(or top) what it does, and given the amount of options it's logical to
just express them as options given in the command line.
It also is a problem if you can modify quark via the config.h,
contradicting the manual. Just saying "Well, then don't touch config.h"
is also not good, as the vhost and map options were only exposed via
this interface.

What is left in config.h are mime-types and two constants relating to
the incoming HTTP-header-limits.

In order to introduce these changes, some structs and safe utility
functions were added and imported from OpenBSD respectively.
2018-03-05 00:14:25 +01:00
Laslo Hunhold
b40b11a40e Fix the regex in the example
Thanks Hiltjo!
2018-02-27 13:00:23 +01:00
Laslo Hunhold
7b7f166dd5 Add target prefix mapping
This allows e.g. to redirect when a directory has been moved.
2018-02-27 12:43:05 +01:00
Laslo Hunhold
02d6ae5a57 Add support for adding a prefix to a target when matching vhosts
This makes quark's vhost-handling very powerful while still being
simple.

Imagine you have a website with a subdomain you really want
to move back to your main domain.
Say the subdomain is called "old.example.org" and you want to serve it
under "example.org" but in the subdirectory "old/", i.e. you want to
redirect a request "old.example.org/subdir/" to "example.org/old/subdir".

For a vhost-handler that only takes 4 arguments for each vhost this is
actually pretty powerful.
2018-02-27 11:36:24 +01:00
Laslo Hunhold
4948053bee Use scheme-relative (aka protocol-relative) URLs for redirects
This ensures that quark really does not care if the incoming connection
is plain HTTP or relayed TLS-traffic from a proxy or tunnel. Depending
on the previous negotiation, the client will make the right decision on
which scheme to use in a given context.
2018-02-27 03:38:55 +01:00
Laslo Hunhold
72aa1646f6 If fork fails, close the incoming socket 2018-02-23 22:40:47 +01:00
Laslo Hunhold
53c3963497 Actually exit the child process once finished serving
Thanks Rodrigo S. Cañibano for noticing this!
2018-02-23 22:29:00 +01:00
Josuah Demangeon
55d7f000cd add headers to make it compile under OpenBSD
- 'struct in6_addr' is defined in <netinet/in.h>
- 'AF_INET6' is defined in <sys/socket.h>
2018-02-12 20:35:37 +01:00
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