Commit Graph

809 Commits

Author SHA1 Message Date
Anna “CyberTailor”
9c84a04f9c check freedesktop's libbsd 2021-07-08 16:55:58 +02:00
Anna “CyberTailor”
9797799ad4 regress/Makefile: add missing LDFLAGS 2021-07-08 16:55:08 +02:00
Omar Polo
2e2e189b01 PF_UNIX is not a valid protocol for socketpair
OpenBSD accept it, but FreeBSD disallows it.  PF_UNSPEC (or 0) should
be used instead.  The FastCGI bit in the regress suite still doesn't
work on FreeBSD, but at least now it starts.
2021-07-08 10:09:24 +00:00
Omar Polo
e7c6502bf3 don't leak a file descriptor
make sure we always close every fd in every possible code path; while
there, also add a log_err if fork(2) failed.
2021-07-08 09:40:23 +00:00
Omar Polo
a8a1f43921 style(9)-ify 2021-07-07 09:46:37 +00:00
Omar Polo
68ef117092 always append -W flags to CFLAGS 2021-07-07 09:19:24 +00:00
Omar Polo
8a50fc0330 initialize the logger early
Initialize the logger as soon as possible and log by default to
stderr.  With this, some (common?) errors are printed early instead of
ending up in syslog.

	# NB: this is in configless mode
	% ./gmid -p 80
	[2021-07-07 11:05:57] bind: Address already in use
	% ./gmid -p 81
	[2021-07-07 11:13:53] bind: Permission denied
	%
2021-07-07 09:18:24 +00:00
Omar Polo
d336aeafd4 refactor add_{cflags,ldflags} 2021-07-07 08:46:23 +00:00
Omar Polo
489e1655a0 add --enable-sandbox
patch from Anna "CyberTailor"

It's handy for helpers like ebuild's use_enable.

(the sandbox is still always enabled by default)
2021-07-07 08:43:33 +00:00
Omar Polo
1a572d4221 check libimsg too
patch from Anna "CyberTailor"
2021-07-07 08:41:27 +00:00
Omar Polo
af15474448 always append LDFLAGS and CFLAGS
Initial patch from Anna "CyberTailor", tweaked by me (drop guessing_*
and always append CFLAGS)
2021-07-07 08:38:19 +00:00
Omar Polo
321341f6c0 add -T timeout to gg; don't let the regress test hang 2021-07-06 13:09:24 +00:00
Omar Polo
6edcfca97f try to preserve as much as possible CFLAGS and LDFLAGS from env
but still try to autodetect with pkg-config if they aren't provided.

Passing CFLAGS/LDFLAGS from the command line will still override the
guessed ones.
2021-07-06 13:01:11 +00:00
Omar Polo
eb877bffaa explain the OpenBSD bit 2021-07-06 12:18:53 +00:00
Omar Polo
ca3f67564c don't log too much by default 2021-07-06 11:53:24 +00:00
Omar Polo
fb4102a5ff test macro expansion too 2021-07-06 11:52:28 +00:00
Omar Polo
3759d3eb56 show macro usage in the example 2021-07-06 11:41:24 +00:00
Omar Polo
7700ab07d3 fmt 2021-07-06 10:56:13 +00:00
Omar Polo
59c7ee13b4 fmt 2021-07-06 10:56:01 +00:00
Omar Polo
090b8a89fa gracefully shut down fastcgi backends
we need to delete the events associated with the backends, otherwise
the server process won't ever quit.

Here, we add a pending counter to every backend and shut down
immediately if they aren't handling any client; otherwise we try to
close them as soon as possible (i.e. when they close the connection to
the last connected client.)
2021-07-06 10:54:27 +00:00
Omar Polo
ea976e8743 don't let CGI scripts inherit our stderr
our stderr could have been sent to the logger process, so it may be
invalid.  Furthermore, in the future we may want to capture also the
stderr of the processes.
2021-07-06 10:48:59 +00:00
Omar Polo
ef945cf415 reset fcgi array in free_config
otherwise path, port and/or prog could become an invalid pointer.
2021-07-06 10:46:50 +00:00
Omar Polo
4aa1dd553a typo 2021-07-03 18:30:07 +00:00
Omar Polo
b24021d4a2 fix seccomp filter for ppc64le
before we matched ppc64le as ppc64 (which is big ending I presume), so
the seccomp filter would always kill gmid

#4 related
2021-07-03 17:38:50 +00:00
Omar Polo
7322a054f5 use -subj /CN=name when generating the keys for the tests
`printf | openssl` is ugly :/
2021-07-03 08:13:42 +00:00
Omar Polo
8bb8cf2ad4 configure: add --disable-sandbox
Calling `configure' with --disable-sandbox will disable the sandbox
support *completely* at compile time.  gmid will still complain at
compile time and during the startup.

Users shouldn't disable the sandbox if possible, but instead report
problem upstream so they get fixed (hopefully.)

#4 related
2021-07-02 09:26:59 +00:00
Omar Polo
137def5ff4 reworked seccomp filter
* SECCOMP_AUDIT_ARCH extended to support more architectures
* relax fcntl policy: allow the syscall regardless of the flags
* wrap every syscall in a ifdef, and add some (statx, fcntl64, ...)
  used in x86

Some bits were taken from dhcpcd[0], thanks!

#4 related


[0]: https://roy.marples.name/git/dhcpcd/blob/HEAD:/src/privsep-linux.c
2021-07-02 09:11:40 +00:00
Omar Polo
4f9a27603c revert 2c16dbd548 -- macro names can't be reserved words
While one can define a macro using a reserved word as name using
-Dname=val, inside the configuration file it'll fail.
2021-07-02 09:05:22 +00:00
Omar Polo
2c16dbd548 macro names can be reserved words 2021-06-29 16:49:38 +00:00
Omar Polo
4ede0fe495 fix macro example 2021-06-29 16:45:09 +00:00
Omar Polo
eaf7f776f1 document the c-like handling of strings 2021-06-29 16:44:17 +00:00
Omar Polo
bfb076ed7e don't expand macros inside the quotes
Now that we have this auto concat string thingy, macros can simply
expand to standalone strings in place, as single words.

Forgot to point it out in previous commits, but now we can

	cert = "/etc/keys"

	server "foo" {
		cert $cert "/foo.crt"
		...
	}
2021-06-29 16:35:06 +00:00
Omar Polo
7252049dd7 align 2021-06-29 16:10:40 +00:00
Omar Polo
98f5217822 [config] concat two or more strings next to each others 2021-06-29 16:10:10 +00:00
Omar Polo
8b743ddacb document macros: both -D and syntax 2021-06-29 14:19:35 +00:00
Omar Polo
6b86655a10 don't require the strict order macro > options > servers 2021-06-29 12:42:44 +00:00
Omar Polo
f98e9045ae add -D to define macros from the cmd line 2021-06-29 12:39:34 +00:00
Omar Polo
3b21cca385 allow to define macros in the config file
Macros can be defined at the top of the configuration file:

	dir = "/var/gemini"
	cert = "/etc/keys"

and re-used later, for example

	server "foo" {
		root "$dir/foo"       # -> /var/gemini/foo
		cert "$cert/foo.pem" # -> /etc/keys/foo.pem
	}
2021-06-29 12:17:40 +00:00
Omar Polo
fafc684957 trailing whitespaces 2021-06-29 11:21:32 +00:00
Omar Polo
8235a81c8f give a name to the anonymous union 2021-06-29 11:11:43 +00:00
Omar Polo
0be2a537e6 sync the usage; while there also change order and capitalize 2021-06-29 11:04:29 +00:00
Omar Polo
ba65dcc8fa mention -V/--version and --help in the manpage 2021-06-29 11:00:28 +00:00
Omar Polo
fdb43a4c0e define GMID_STRING and reuse-it
GMID_VERSION follows the CGI/FastCGI style, i.e. project_name/version.

Define GMID_STRING with a more "human" variant "project_name version",
and reuse that in the --help and --version codepath.
2021-06-29 10:56:07 +00:00
Omar Polo
0233b0f6b9 add version in usage 2021-06-29 10:51:42 +00:00
Omar Polo
9327bc045a use getprogname() in usage() 2021-06-29 10:50:39 +00:00
Omar Polo
5777923bb0 use getopt_long, add --help as synonym of -h and -V/--version 2021-06-29 10:49:59 +00:00
Omar Polo
2c43dcceb6 document `log' option 2021-06-17 09:27:09 +00:00
Omar Polo
1b78bd563a strncpy -> strlcpy
quoting strncpy(3)

     strncpy() only NUL terminates the destination string when the
     length of the source string is less than the length parameter.

strlcpy is more intuitive.

this is another warning gcc 8 found that clang didn't.
2021-06-16 15:06:10 +00:00
Omar Polo
80fbf1e934 make sure l is always initialized
I can't think of cases where we reach serialize_iri and path is NULL,
but let's keep the safe side and initialize l.  gcc 8 found this,
clang didn't.
2021-06-16 15:04:42 +00:00
Omar Polo
2d383cbd5f remove last occurrences of lex 2021-06-16 15:00:52 +00:00