├── regress ├── err ├── hello ├── serve-bigfile ├── slow ├── valid.ext ├── example.mime.types ├── fuzz │ ├── README.md │ ├── iri.c │ ├── proxy.c │ └── Makefile ├── fill-file.c ├── max-length-reply ├── env ├── invalid ├── regress ├── puny-test.c ├── Makefile └── lib.sh ├── site ├── footer.html ├── vim-screenshot.png ├── README.md ├── header.html ├── mdoc2html.sh ├── menu.pl ├── subst ├── style.css ├── index.gmi ├── Makefile ├── faq.gmi ├── gem2html ├── contrib.gmi └── quickstart.gmi ├── contrib ├── gmid.sysusers ├── Docker.gmid.conf ├── vim │ ├── ftplugin │ │ └── gmid.vim │ ├── ftdetect │ │ └── gmid.vim │ ├── indent │ │ └── gmid.vim │ ├── syntax_checkers │ │ └── gmid │ │ │ └── gmid.vim │ └── ale_linters │ │ └── gmid │ │ └── gmid.vim ├── Makefile ├── gmid.service ├── Dockerfile ├── README ├── gencert ├── mime.types └── renew-certs ├── have ├── reallocarray.c ├── setresgid.c ├── setresuid.c ├── __progname.c ├── explicit_bzero.c ├── recallocarray.c ├── noop.c ├── freezero.c ├── libtls.c ├── wait_any.c ├── arc4random.c ├── getdtablesize.c ├── getprogname.c ├── getdtablecount.c ├── libevent.c ├── pr_set_name.c ├── X509_LOOKUP_mem.c ├── arc4random_buf.c ├── endian_h.c ├── ASN1_time_tm_cmp.c ├── ASN1_time_parse.c ├── SSL_CTX_load_verify_mem.c ├── err.c ├── getentropy.c ├── sys_endian_h.c ├── strnvis.c ├── timingsafe_memcmp.c ├── SSL_CTX_use_certificate_chain_mem.c ├── strlcpy.c ├── openssl.c ├── strlcat.c ├── strtonum.c ├── machine_endian.c ├── program_invocation_short_name.c ├── ASN1_time_tm_clamp_notafter.c ├── memmem.c ├── setproctitle.c ├── queue_h.c ├── Makefile ├── imsg.c ├── tree_h.c ├── vasprintf.c ├── landlock.c └── libevent2.c ├── keys ├── gmid-1.7.pub ├── gmid-1.8.pub ├── gmid-2.0.pub ├── gmid-2.1.pub └── Makefile ├── .dockerignore ├── compat ├── explicit_bzero.c ├── libtls │ ├── Makefile │ ├── asn.c │ ├── tls_peer.c │ ├── tls_bio_cb.c │ └── tls_keypair.c ├── Makefile ├── getdtablesize.c ├── getdtablecount.c ├── freezero.c ├── setresgid.c ├── getprogname.c ├── reallocarray.c ├── setproctitle.c ├── vasprintf.c ├── strlcpy.c ├── timingsafe_memcmp.c ├── setresuid.c ├── strlcat.c ├── strtonum.c ├── err.c ├── arc4random.h ├── recallocarray.c ├── getentropy.c └── vis │ └── vis.h ├── .gitignore ├── LICENSE ├── .github └── workflows │ └── alpine-release.yml ├── iri.h ├── .cirrus.yml ├── log.h ├── gemexp.1 ├── titan.1 ├── gg.1 ├── utf8.c ├── logger.c ├── gmid.8 ├── mime.c ├── README.md ├── proc.h ├── log.c ├── dirs.c └── proxy-proto.c /regress/err: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exit 1 4 | -------------------------------------------------------------------------------- /site/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /contrib/gmid.sysusers: -------------------------------------------------------------------------------- 1 | u gmid - "gmid Gemini server" - - 2 | -------------------------------------------------------------------------------- /regress/hello: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf "20 text/gemini\r\n" 4 | echo "# hello world" 5 | -------------------------------------------------------------------------------- /site/vim-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omar-polo/gmid/HEAD/site/vim-screenshot.png -------------------------------------------------------------------------------- /regress/serve-bigfile: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf "20 application/octet-stream\r\n" 4 | 5 | exec cat bigfile 6 | -------------------------------------------------------------------------------- /regress/slow: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf "20 " 4 | sleep 1 5 | printf "text/gemini\r\n" 6 | echo "# hello world" 7 | -------------------------------------------------------------------------------- /have/reallocarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | return !reallocarray(NULL, 2, 2); 7 | } 8 | -------------------------------------------------------------------------------- /keys/gmid-1.7.pub: -------------------------------------------------------------------------------- 1 | untrusted comment: signify public key 2 | RWSK+qgSqgu20CEZZQTAExCxaGaOwGO7AWqru6BKLqQhQDy8Iz1tjXNE 3 | -------------------------------------------------------------------------------- /keys/gmid-1.8.pub: -------------------------------------------------------------------------------- 1 | untrusted comment: signify public key 2 | RWTy3UJQzpxBUAymBwb2EGLLm0b3H/1n8hzhaC9HYFYzNuTavGt9QSwC 3 | -------------------------------------------------------------------------------- /keys/gmid-2.0.pub: -------------------------------------------------------------------------------- 1 | untrusted comment: signify public key 2 | RWQ+Bm0F0FtPLtTnpRe09x/Z6Fiodk4toTZe2TJ4yCqDZ6l0c5wiU9te 3 | -------------------------------------------------------------------------------- /keys/gmid-2.1.pub: -------------------------------------------------------------------------------- 1 | untrusted comment: signify public key 2 | RWSMZUrn4u03g0AwurM9kGiIfhetO5OISPlMMb4+th+Bw8ViotgbzKss 3 | -------------------------------------------------------------------------------- /have/setresgid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | return setresgid(-1, -1, -1) == -1; 8 | } 9 | -------------------------------------------------------------------------------- /have/setresuid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | return setresuid(-1, -1, -1) == -1; 8 | } 9 | -------------------------------------------------------------------------------- /regress/valid.ext: -------------------------------------------------------------------------------- 1 | authorityKeyIdentifier=keyid,issuer 2 | basicConstraints=CA:FALSE 3 | keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment 4 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | ** 2 | !*.c 3 | !*.h 4 | !*.y 5 | !*.[1-9] 6 | !compat 7 | !have/*.c 8 | !Makefile 9 | !configure 10 | !contrib/Docker.gmid.conf 11 | !contrib/gencert 12 | -------------------------------------------------------------------------------- /have/__progname.c: -------------------------------------------------------------------------------- 1 | /* public domain */ 2 | 3 | #include 4 | 5 | extern const char *__progname; 6 | 7 | int 8 | main(void) 9 | { 10 | puts(__progname); 11 | } 12 | -------------------------------------------------------------------------------- /have/explicit_bzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | char buf[] = "hello world"; 7 | 8 | explicit_bzero(buf, sizeof(buf)); 9 | return strcmp(buf, ""); 10 | } 11 | -------------------------------------------------------------------------------- /have/recallocarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | void *p; 7 | 8 | if ((p = calloc(2, 2)) == NULL) 9 | return 1; 10 | return !recallocarray(p, 2, 3, 2); 11 | } 12 | -------------------------------------------------------------------------------- /site/README.md: -------------------------------------------------------------------------------- 1 | # gmid website/capsule 2 | 3 | These are the sources for the gmid website and Gemini capsule. 4 | 5 | Unlike gmid itself, to build the site you'll need OpenBSD' make (on 6 | linux `bmake` *may* work.) 7 | -------------------------------------------------------------------------------- /contrib/Docker.gmid.conf: -------------------------------------------------------------------------------- 1 | user gmid 2 | chroot "/var/gemini" 3 | 4 | server "localhost" { 5 | listen on * port 1965 6 | cert "/etc/ssl/localhost.pem" 7 | key "/etc/ssl/private/localhost.key" 8 | root "/" 9 | } 10 | -------------------------------------------------------------------------------- /compat/explicit_bzero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Public domain. 3 | * Written by Matthew Dempsky. 4 | */ 5 | 6 | #include "../config.h" 7 | 8 | #include 9 | 10 | void 11 | explicit_bzero(void *buf, size_t len) 12 | { 13 | memset(buf, 0, len); 14 | } 15 | -------------------------------------------------------------------------------- /contrib/vim/ftplugin/gmid.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_ftplugin") 2 | finish 3 | endif 4 | let b:did_ftplugin = 1 5 | let b:undo_ftplugin = "setl cms< sua<" 6 | 7 | setlocal suffixesadd+=.conf,.gmid 8 | 9 | " vim-commentary support 10 | setlocal commentstring=#\ %s 11 | -------------------------------------------------------------------------------- /keys/Makefile: -------------------------------------------------------------------------------- 1 | DISTFILES = Makefile gmid-1.7.pub gmid-1.8.pub gmid-2.0.pub gmid-2.1.pub 2 | 3 | all: false 4 | 5 | dist: ${DISTFILES} 6 | mkdir -p ${DESTDIR} 7 | ${INSTALL} -m 0644 ${DISTFILES} ${DESTDIR}/ 8 | 9 | .PHONY: all dist 10 | include ../config.mk 11 | -------------------------------------------------------------------------------- /regress/example.mime.types: -------------------------------------------------------------------------------- 1 | # example mime.types file FOR REGRESS TESTS ONLY! 2 | 3 | application/vnd.apple.mpegurl m3u8 4 | application/x-perl pl pm 5 | 6 | # some empty lines because I can 7 | 8 | text/x-mandoc 1 2 3 4 5 6 7 8 9 9 | text/x-mandoc 3bsd 10 | -------------------------------------------------------------------------------- /contrib/vim/ftdetect/gmid.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype detection file 2 | " Language: gmid(1) configuration files 3 | " Licence: ISC 4 | 5 | au BufNewFile,BufRead *.gmid set filetype=gmid 6 | au BufNewFile,BufRead */etc/gmid/* set filetype=gmid 7 | au BufNewFile,BufRead gmid.conf set filetype=gmid 8 | -------------------------------------------------------------------------------- /site/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TITLE | gmid 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /contrib/vim/indent/gmid.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_indent") 2 | finish 3 | endif 4 | let b:did_indent = 1 5 | 6 | setlocal indentexpr= 7 | 8 | " cindent actually works for simple file structure 9 | setlocal cindent 10 | " Just make sure that the comments are not reset as defs would be. 11 | setlocal cinkeys-=0# 12 | " And indentation works correctly without semicolons. 13 | setlocal cinoptions=+0 14 | -------------------------------------------------------------------------------- /regress/fuzz/README.md: -------------------------------------------------------------------------------- 1 | # Fuzzying gmid 2 | 3 | Here are some notes on how to fuzz some parts of gmid using afl. 4 | 5 | - run `make -C ../../ clean` beforehand so that we compile all relevant 6 | sources with afl-clang. Then, clean again before rebuilding gmid. 7 | 8 | - run `make fuzz-iri` to fuzz the IRI parser. 9 | 10 | - run `make fuzz-proto` to fuzz the proxy v1 protocol parser. 11 | -------------------------------------------------------------------------------- /contrib/Makefile: -------------------------------------------------------------------------------- 1 | DISTFILES = Makefile \ 2 | Docker.gmid.conf \ 3 | Dockerfile \ 4 | README \ 5 | gencert \ 6 | gmid.service \ 7 | gmid.sysusers \ 8 | mime.types \ 9 | renew-certs 10 | 11 | all: 12 | false 13 | 14 | dist: ${DISTFILES} 15 | mkdir -p ${DESTDIR}/ 16 | ${INSTALL} -m 0644 ${DISTFILES} ${DESTDIR}/ 17 | cd ${DESTDIR} && chmod 755 gencert renew-certs 18 | cp -R vim ${DESTDIR}/vim 19 | 20 | .PHONY: all dist 21 | include ../config.mk 22 | -------------------------------------------------------------------------------- /contrib/gmid.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=The gmid Gemini server 3 | Documentation=https://gmid.omarpolo.com/ 4 | After=network-online.target syslog.target 5 | Wants=network-online.target 6 | 7 | [Service] 8 | Type=simple 9 | ExecStart=/usr/local/bin/gmid -f -c /etc/gmid.conf 10 | ExecStop=/bin/kill -TERM $MAINPID 11 | ExecReload=/bin/kill -HUP $MAINPID 12 | Restart=on-failure 13 | RestartSec=30 14 | StandardOutput=journal 15 | StandardError=inherit 16 | SyslogIdentifier=gmid 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /site/mdoc2html.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # usage: mdoc2html.sh src out 4 | # 5 | # converts the manpage `src' to the HTML file `out', tweaking the 6 | # style 7 | 8 | set -e 9 | 10 | : ${1:?missing input file} 11 | : ${2:?missing output file} 12 | 13 | man -Thtml -l "$1" > "$2" 14 | 15 | exec ed "$2" < 17 | a 18 | body { 19 | max-width: 960px; 20 | margin: 0 auto; 21 | padding: 0 10px; 22 | font-size: 1rem; 23 | } 24 | 25 | pre { 26 | overflow: auto; 27 | } 28 | . 29 | wq 30 | EOF 31 | -------------------------------------------------------------------------------- /compat/libtls/Makefile: -------------------------------------------------------------------------------- 1 | DISTFILES = Makefile \ 2 | asn.c \ 3 | by_mem.c \ 4 | openssl.c \ 5 | tls.c \ 6 | tls.h \ 7 | tls_bio_cb.c \ 8 | tls_client.c \ 9 | tls_config.c \ 10 | tls_conninfo.c \ 11 | tls_internal.h \ 12 | tls_keypair.c \ 13 | tls_ocsp.c \ 14 | tls_peer.c \ 15 | tls_server.c \ 16 | tls_signer.c \ 17 | tls_util.c \ 18 | tls_verify.c 19 | 20 | all: 21 | false 22 | 23 | dist: ${DISTFILES} 24 | mkdir -p ${DESTDIR}/ 25 | ${INSTALL} -m 0644 ${DISTFILES} ${DESTDIR}/ 26 | 27 | .PHONY: all dist 28 | include ../../config.mk 29 | -------------------------------------------------------------------------------- /contrib/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | WORKDIR /build 3 | RUN apk update && \ 4 | apk upgrade && \ 5 | apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main \ 6 | alpine-sdk \ 7 | linux-headers \ 8 | bison \ 9 | libevent-dev \ 10 | openssl-dev 11 | COPY . . 12 | RUN ./configure && make && make install 13 | RUN adduser -H -S -s /sbin/nologin gmid 14 | RUN mkdir /var/gemini 15 | RUN ./contrib/gencert -e localhost && \ 16 | mv localhost.pem /etc/ssl && \ 17 | mv localhost.key /etc/ssl/private 18 | RUN mv contrib/Docker.gmid.conf /etc/gmid.conf 19 | ENTRYPOINT ["gmid", "-f"] 20 | -------------------------------------------------------------------------------- /regress/fuzz/iri.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "iri.h" 6 | 7 | int 8 | main(void) 9 | { 10 | struct iri iri; 11 | const char *errstr = NULL; 12 | char buf[64]; 13 | char *line = NULL; 14 | size_t linesize = 0; 15 | ssize_t linelen; 16 | 17 | if ((linelen = getline(&line, &linesize, stdin)) == -1) 18 | return (1); 19 | 20 | if (line[linelen-1] == '\n') 21 | line[--linelen] = '\0'; 22 | 23 | if (parse_iri(line, &iri, &errstr)) { 24 | if (serialize_iri(&iri, buf, sizeof(buf))) 25 | puts(buf); 26 | } 27 | 28 | free(line); 29 | if (ferror(stdin)) { 30 | perror("getline"); 31 | return (1); 32 | } 33 | 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /regress/fill-file.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* I need a big file made up of ascii characters. dd if=/dev/zero is 4 | * thus not an option, truncate is not portable. This is some order 5 | * of magnitude faster than the equivalent sh script */ 6 | 7 | int 8 | main(int argc, char **argv) 9 | { 10 | FILE *out; 11 | int i, j; 12 | 13 | if (argc != 2) { 14 | fprintf(stderr, "USAGE: %s \n", *argv); 15 | return 1; 16 | } 17 | 18 | if ((out = fopen(argv[1], "w")) == NULL) { 19 | fprintf(stderr, "cannot open file: %s\n", argv[1]); 20 | return 1; 21 | } 22 | 23 | for (i = 0; i < 1024; ++i) 24 | for (j = 0; j < 1024; ++j) 25 | fprintf(out, "a\n"); 26 | 27 | fclose(out); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /site/menu.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use v5.10; 4 | use strict; 5 | use warnings; 6 | 7 | my $page = shift or die 'missing page'; 8 | my $outtype = shift or die 'missing output type'; 9 | my @pages = (); 10 | 11 | while (<>) { 12 | chomp; 13 | @pages = (@pages, $_); 14 | } 15 | 16 | my $did = 0; 17 | for (@pages) { 18 | my ($href, $text) = m/^([^\s]*)\s*(.*)$/; 19 | 20 | if ($outtype eq 'gemini') { 21 | if ($href ne $page) { 22 | say "=> $href $text"; 23 | } 24 | } else { 25 | if (!$did) { 26 | $did = 1; 27 | } else { 28 | print "| "; 29 | } 30 | 31 | if ($href eq $page) { 32 | print "$text "; 33 | } else { 34 | print "$text "; 35 | } 36 | } 37 | } 38 | 39 | say ""; 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.pem 3 | TAGS 4 | gmid 5 | gg 6 | gemexp 7 | titan 8 | **/*.[do] 9 | *.swp 10 | docs 11 | y.tab.* 12 | compile_flags.txt 13 | config.h 14 | config.h.old 15 | config.log 16 | config.log.old 17 | config.mk 18 | configure.local 19 | !contrib/gmid 20 | !contrib/vim/ale_linters/gmid 21 | !contrib/vim/syntax_checkers/gmid 22 | regress/testdata 23 | regress/*.pem 24 | regress/*.key 25 | regress/*.crt 26 | regress/*.csr 27 | regress/*.srl 28 | regress/reg.conf 29 | regress/fcgi-test 30 | regress/fcgi.sock 31 | regress/fill-file 32 | regress/iri_test 33 | regress/puny-test 34 | regress/gmid.pid 35 | 36 | regress/fuzz/in 37 | regress/fuzz/iri 38 | regress/fuzz/min 39 | regress/fuzz/out 40 | regress/fuzz/proxy 41 | 42 | site/gemini 43 | site/www 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020, 2021, 2022 Omar Polo 2 | 3 | Permission to use, copy, modify, and distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /compat/Makefile: -------------------------------------------------------------------------------- 1 | DISTFILES = Makefile \ 2 | arc4random.c \ 3 | arc4random.h \ 4 | chacha_private.h \ 5 | err.c \ 6 | explicit_bzero.c \ 7 | freezero.c \ 8 | getdtablecount.c \ 9 | getdtablesize.c \ 10 | getentropy.c \ 11 | getprogname.c \ 12 | imsg-buffer.c \ 13 | imsg.c \ 14 | imsg.h \ 15 | memmem.c \ 16 | queue.h \ 17 | reallocarray.c \ 18 | recallocarray.c \ 19 | setproctitle.c \ 20 | setresgid.c \ 21 | setresuid.c \ 22 | strlcat.c \ 23 | strlcpy.c \ 24 | strtonum.c \ 25 | timingsafe_memcmp.c \ 26 | tree.h \ 27 | vasprintf.c \ 28 | vis.c 29 | 30 | all: 31 | false 32 | 33 | dist: ${DISTFILES} 34 | mkdir -p ${DESTDIR}/ 35 | ${INSTALL} -m 0644 ${DISTFILES} ${DESTDIR}/ 36 | mkdir -p ${DESTDIR}/vis 37 | ${INSTALL} -m 0644 vis/vis.h ${DESTDIR}/vis 38 | ${MAKE} -C libtls DESTDIR=${DESTDIR}/libtls dist 39 | 40 | .PHONY: all dist 41 | include ../config.mk 42 | -------------------------------------------------------------------------------- /have/noop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | int 18 | main(void) 19 | { 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /have/freezero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | freezero(NULL, 0); 23 | } 24 | -------------------------------------------------------------------------------- /have/libtls.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | return tls_init() != 0; 23 | } 24 | -------------------------------------------------------------------------------- /have/wait_any.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | return WAIT_ANY; 23 | } 24 | -------------------------------------------------------------------------------- /have/arc4random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | return arc4random(); 23 | } 24 | -------------------------------------------------------------------------------- /have/getdtablesize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | return getdtablesize() == 0; 23 | } 24 | -------------------------------------------------------------------------------- /have/getprogname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | return getprogname() == NULL; 23 | } 24 | -------------------------------------------------------------------------------- /have/getdtablecount.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | return getdtablecount() == 0; 23 | } 24 | -------------------------------------------------------------------------------- /contrib/README: -------------------------------------------------------------------------------- 1 | This directory is for additional contributed files which may be 2 | useful. 3 | 4 | Dockerfile 5 | 6 | Sample Dockerfile to build alpine-based gmid images. 7 | 8 | gencert 9 | 10 | Simple shell script to generate self-signed certificates. 11 | 12 | gmid.service 13 | 14 | Simple systemd service file. 15 | 16 | gmid.sysusers 17 | 18 | Sample systemd-sysusers' config file. 19 | 20 | mime.types 21 | 22 | A copy of OpenBSD' /usr/share/misc/mime.types to be included 23 | within a `types' block. 24 | 25 | renew-certs 26 | 27 | Flexible script meant to be run in a cronjob to watch for cert 28 | expiration. It can optionally regen the (self-signed) 29 | certificate in place and restart the server too. 30 | 31 | vim 32 | 33 | Syntax highlighting of gmid configuration for vim, to be 34 | placed into ~/.vim/ or /usr/share/vim/vimfiles/. 35 | 36 | To enable Syntastic checker, put this line in your vimrc: 37 | 38 | let g:syntastic_gmid_checkers = ['gmid'] 39 | -------------------------------------------------------------------------------- /have/libevent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | int 22 | main(void) 23 | { 24 | event_init(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /have/pr_set_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | prctl(PR_SET_NAME, "foo"); 24 | } 25 | -------------------------------------------------------------------------------- /have/X509_LOOKUP_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | return X509_LOOKUP_mem() != NULL; 24 | } 25 | -------------------------------------------------------------------------------- /compat/getdtablesize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | 21 | int 22 | getdtablesize(void) 23 | { 24 | return sysconf(_SC_OPEN_MAX); 25 | } 26 | -------------------------------------------------------------------------------- /have/arc4random_buf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | char buf[128]; 23 | 24 | arc4random_buf(buf, sizeof(buf)); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /have/endian_h.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | uint16_t x; 24 | 25 | x = 42; 26 | return (htobe16(x)); 27 | } 28 | -------------------------------------------------------------------------------- /have/ASN1_time_tm_cmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | int 22 | main(void) 23 | { 24 | return ASN1_time_tm_cmp(NULL, NULL); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /have/ASN1_time_parse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | int 22 | main(void) 23 | { 24 | return ASN1_time_parse("", 0, NULL, 0); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /have/SSL_CTX_load_verify_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | return SSL_CTX_load_verify_mem(NULL, NULL, 0); 24 | } 25 | -------------------------------------------------------------------------------- /have/err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | warnx("%d. warnx", 1); 23 | warn("%d. warn", 2); 24 | err(0, "%d. err", 3); 25 | return 1; 26 | } 27 | -------------------------------------------------------------------------------- /have/getentropy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | char buf[1024]; 24 | 25 | return getentropy(buf, sizeof(buf)); 26 | } 27 | -------------------------------------------------------------------------------- /have/sys_endian_h.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | uint16_t x; 24 | 25 | x = 42; 26 | return (htobe16(x)); 27 | } 28 | -------------------------------------------------------------------------------- /have/strnvis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | char buf[128]; 24 | 25 | return strnvis(buf, "Hello, world!\n", sizeof(buf), 0); 26 | } 27 | -------------------------------------------------------------------------------- /contrib/vim/syntax_checkers/gmid/gmid.vim: -------------------------------------------------------------------------------- 1 | " Syntax checking plugin for syntastic 2 | " Language: gmid(1) configuration file 3 | " Licence: ISC 4 | 5 | if exists('g:loaded_syntastic_gmid_gmid_checker') 6 | finish 7 | endif 8 | let g:loaded_syntastic_gmid_gmid_checker = 1 9 | 10 | let s:save_cpo = &cpo 11 | set cpo&vim 12 | 13 | function! SyntaxCheckers_gmid_gmid_GetLocList() dict 14 | let makeprg = self.makeprgBuild({ 'args': '-nc' }) 15 | 16 | let errorformat = 17 | \ '%-Gconfig OK,' . 18 | \ '%f:%l %tarning: %m,' . 19 | \ '%f:%l %trror: %m' 20 | 21 | return SyntasticMake({ 22 | \ 'makeprg': makeprg, 23 | \ 'errorformat': errorformat, 24 | \ 'defaults': {'type': 'E'}, 25 | \ 'returns': [0, 1] }) 26 | endfunction 27 | 28 | call g:SyntasticRegistry.CreateAndRegisterChecker({ 29 | \ 'filetype': 'gmid', 30 | \ 'name': 'gmid', 31 | \ 'exec': 'gmid'}) 32 | 33 | let &cpo = s:save_cpo 34 | unlet s:save_cpo 35 | 36 | " vim: set sw=4 sts=4 et fdm=marker: 37 | -------------------------------------------------------------------------------- /have/timingsafe_memcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | const char *a = "foo"; 23 | const char *b = "bar"; 24 | 25 | return timingsafe_memcmp(a, b, 3); 26 | } 27 | -------------------------------------------------------------------------------- /have/SSL_CTX_use_certificate_chain_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | int 21 | main(void) 22 | { 23 | return SSL_CTX_use_certificate_chain_mem(NULL, NULL, 0); 24 | } 25 | -------------------------------------------------------------------------------- /have/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | char buf[2] = ""; 23 | return ! (strlcpy(buf, "a", sizeof(buf)) == 1 && 24 | buf[0] == 'a' && buf[1] == '\0'); 25 | } 26 | -------------------------------------------------------------------------------- /regress/fuzz/proxy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "gmid.h" 6 | 7 | int 8 | main(void) 9 | { 10 | struct proxy_protocol_v1 pp1; 11 | char buf[1024]; 12 | char *line = NULL; 13 | size_t consumed, linesize = 0; 14 | ssize_t linelen; 15 | 16 | memset(&pp1, 0, sizeof(pp1)); 17 | memset(buf, 0, sizeof(buf)); 18 | 19 | if ((linelen = getline(&line, &linesize, stdin)) == -1) 20 | return (1); 21 | 22 | if (proxy_proto_v1_parse(&pp1, line, linelen, &consumed) != -1) { 23 | switch (pp1.proto) { 24 | case PROTO_V4: 25 | inet_ntop(AF_INET, &pp1.srcaddr.v4, buf, sizeof(buf)); 26 | break; 27 | case PROTO_V6: 28 | inet_ntop(AF_INET6, &pp1.srcaddr.v6, buf, sizeof(buf)); 29 | break; 30 | case PROTO_UNKNOWN: 31 | strlcpy(buf, "UNKNOWN", sizeof(buf)); 32 | break; 33 | default: 34 | abort(); 35 | } 36 | puts(buf); 37 | } 38 | 39 | free(line); 40 | if (ferror(stdin)) { 41 | perror("getline"); 42 | return (1); 43 | } 44 | 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /have/openssl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | X509 *x509; 23 | 24 | if ((x509 = X509_new()) == NULL) 25 | return 1; 26 | X509_free(x509); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /regress/max-length-reply: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf '20 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\r\n' 4 | -------------------------------------------------------------------------------- /have/strlcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | char buf[3] = "a"; 23 | return ! (strlcat(buf, "b", sizeof(buf)) == 2 && 24 | buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0'); 25 | } 26 | -------------------------------------------------------------------------------- /compat/getdtablecount.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* XXX: on linux it's possible to glob("/proc/$pid/fd/ *") to know the 18 | * dtablecount. */ 19 | 20 | #include "../config.h" 21 | 22 | int 23 | getdtablecount(void) 24 | { 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /have/strtonum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | const char *str = "42", *errstr; 23 | int res; 24 | 25 | res = strtonum(str, 1, 64, &errstr); 26 | return res != 42 || errstr != NULL; 27 | } 28 | -------------------------------------------------------------------------------- /have/machine_endian.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | int 22 | main(void) 23 | { 24 | uint16_t x; 25 | 26 | x = 42; 27 | return (OSSwapHostToBigInt16(x)); 28 | } 29 | -------------------------------------------------------------------------------- /have/program_invocation_short_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | extern char *program_invocation_short_name; 21 | 22 | int 23 | main(void) 24 | { 25 | return program_invocation_short_name == NULL; 26 | } 27 | -------------------------------------------------------------------------------- /compat/freezero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | #include 21 | 22 | void 23 | freezero(void *ptr, size_t len) 24 | { 25 | if (ptr == NULL) 26 | return; 27 | 28 | memset(ptr, 0, len); 29 | free(ptr); 30 | } 31 | -------------------------------------------------------------------------------- /have/ASN1_time_tm_clamp_notafter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | struct tm; 22 | 23 | int ASN1_time_tm_clamp_notafter(struct tm *tm); 24 | 25 | int 26 | main(void) 27 | { 28 | return ASN1_time_tm_clamp_notafter(NULL); 29 | } 30 | -------------------------------------------------------------------------------- /have/memmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | int 20 | main(void) 21 | { 22 | char big[33], little[2]; 23 | 24 | memset(big, 0, sizeof(big)); 25 | memset(little, 0, sizeof(little)); 26 | return (memmem(big, sizeof(big), little, sizeof(little)) == NULL); 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/alpine-release.yml: -------------------------------------------------------------------------------- 1 | name: release docker image 2 | on: 3 | push: 4 | tags: 5 | - '*' 6 | branches: 7 | - master 8 | env: 9 | IMAGE_NAME: "gmid" 10 | jobs: 11 | build: 12 | permissions: write-all 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v1 16 | 17 | - name: build the image 18 | run: docker build -f contrib/Dockerfile -t gmid:alpine . 19 | 20 | - name: login to ghcr.io 21 | uses: docker/login-action@v2 22 | with: 23 | registry: ghcr.io 24 | username: ${{ github.actor }} 25 | password: ${{ secrets.GITHUB_TOKEN }} 26 | 27 | - name: push the image 28 | run: | 29 | IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME 30 | IMAGE_ID=$(echo $IMAGE_ID | tr A-Z a-z) 31 | # strip git ref prefix from version 32 | VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') 33 | echo IMAGE_ID=$IMAGE_ID 34 | echo VERSION=$VERSION 35 | docker tag gmid:alpine $IMAGE_ID:$VERSION 36 | docker push $IMAGE_ID:$VERSION 37 | -------------------------------------------------------------------------------- /have/setproctitle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * FreeBSD has setproctitle in a different header than OpenBSD. 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | int 27 | main(void) 28 | { 29 | setproctitle("%s", "frobnicator"); 30 | } 31 | -------------------------------------------------------------------------------- /contrib/vim/ale_linters/gmid/gmid.vim: -------------------------------------------------------------------------------- 1 | " Linter for ALE 2 | " Language: gmid(1) configuration file 3 | " Licence: ISC 4 | 5 | call ale#Set('gmid_executable', 'gmid') 6 | 7 | function! ale_linters#gmid#gmid#Handle(buffer, lines) abort 8 | let l:output = [] 9 | let l:gmid_type_to_ale_type = { 10 | \ 'error': 'E', 11 | \ 'warning': 'W', 12 | \} 13 | 14 | let l:pattern = '\v^(.*):(\d*) ([a-z]+): (.*)$' 15 | for l:match in ale#util#GetMatches(a:lines, l:pattern) 16 | call add(l:output, { 17 | \ 'filename': l:match[1], 18 | \ 'lnum': l:match[2], 19 | \ 'type': get(l:gmid_type_to_ale_type, l:match[3], 'E'), 20 | \ 'text': l:match[4], 21 | \}) 22 | endfor 23 | 24 | return l:output 25 | endfunction 26 | 27 | call ale#linter#Define('gmid', { 28 | \ 'name': 'gmid', 29 | \ 'executable': {buffer -> ale#Var(buffer, 'gmid_executable')}, 30 | \ 'command': '%e -nc %s', 31 | \ 'output_stream': 'both', 32 | \ 'lint_file': 1, 33 | \ 'callback': 'ale_linters#gmid#gmid#Handle', 34 | \}) 35 | 36 | " vim: set sw=4 sts=4 et fdm=marker: 37 | -------------------------------------------------------------------------------- /have/queue_h.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TAILQ_HEAD(tailhead, entry) head; 22 | struct entry { 23 | TAILQ_ENTRY(entry) entries; 24 | } *np, *nt; 25 | 26 | int 27 | main(void) 28 | { 29 | TAILQ_INIT(&head); 30 | TAILQ_FOREACH_SAFE(np, &head, entries, nt) { 31 | /* nop */; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /have/Makefile: -------------------------------------------------------------------------------- 1 | DISTFILES = ASN1_time_parse.c \ 2 | ASN1_time_tm_clamp_notafter.c \ 3 | ASN1_time_tm_cmp.c \ 4 | Makefile \ 5 | SSL_CTX_load_verify_mem.c \ 6 | SSL_CTX_use_certificate_chain_mem.c \ 7 | X509_LOOKUP_mem.c \ 8 | __progname.c \ 9 | arc4random.c \ 10 | arc4random_buf.c \ 11 | endian_h.c \ 12 | err.c \ 13 | explicit_bzero.c \ 14 | freezero.c \ 15 | getdtablecount.c \ 16 | getdtablesize.c \ 17 | getentropy.c \ 18 | getprogname.c \ 19 | imsg.c \ 20 | landlock.c \ 21 | libevent.c \ 22 | libevent2.c \ 23 | libtls.c \ 24 | machine_endian.c \ 25 | memmem.c \ 26 | noop.c \ 27 | openssl.c \ 28 | pr_set_name.c \ 29 | program_invocation_short_name.c \ 30 | queue_h.c \ 31 | reallocarray.c \ 32 | recallocarray.c \ 33 | setproctitle.c \ 34 | setresgid.c \ 35 | setresuid.c \ 36 | strlcat.c \ 37 | strlcpy.c \ 38 | strnvis.c \ 39 | strtonum.c \ 40 | sys_endian_h.c \ 41 | timingsafe_memcmp.c \ 42 | tree_h.c \ 43 | vasprintf.c \ 44 | wait_any.c 45 | 46 | all: 47 | false 48 | 49 | dist: ${DISTFILES} 50 | mkdir -p ${DESTDIR}/ 51 | ${INSTALL} -m 0644 ${DISTFILES} ${DESTDIR}/ 52 | 53 | .PHONY: all dist 54 | include ../config.mk 55 | -------------------------------------------------------------------------------- /have/imsg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | main(void) 25 | { 26 | struct imsgbuf imsgbuf; 27 | struct imsg imsg; 28 | 29 | if (imsgbuf_init(&imsgbuf, -1) == -1) 30 | return 1; 31 | imsgbuf_allow_fdpass(&imsgbuf); 32 | return imsg_get_fd(&imsg); 33 | } 34 | -------------------------------------------------------------------------------- /iri.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | struct iri { 18 | char *schema; 19 | char *host; 20 | char *port; 21 | uint16_t port_no; 22 | char *path; 23 | char *query; 24 | char *fragment; 25 | }; 26 | 27 | int parse_iri(char*, struct iri*, const char**); 28 | int serialize_iri(struct iri*, char*, size_t); 29 | int encode_path(char *, size_t, const char *); 30 | char *pct_decode_str(char *); 31 | -------------------------------------------------------------------------------- /compat/setresgid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au). 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | #include 21 | 22 | int 23 | setresgid(gid_t rgid, gid_t egid, gid_t sgid) 24 | { 25 | /* this is the only configuration tested */ 26 | 27 | if (rgid != egid || egid != sgid) 28 | return -1; 29 | 30 | if (setregid(rgid, egid) == -1) 31 | return -1; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /have/tree_h.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | struct tree { 22 | int i; 23 | SPLAY_ENTRY(tree) entry; 24 | }; 25 | SPLAY_HEAD(tree_id, tree); 26 | 27 | static int 28 | tree_cmp(struct tree *a, struct tree *b) 29 | { 30 | if (a->i == b->i) 31 | return 0; 32 | else if (a->i < b->i) 33 | return -1; 34 | else 35 | return +1; 36 | } 37 | 38 | SPLAY_PROTOTYPE(tree_id, tree, entry, tree_cmp); 39 | SPLAY_GENERATE(tree_id, tree, entry, tree_cmp); 40 | 41 | int 42 | main(void) 43 | { 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /have/vasprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | static int testfn(char **, const char*, ...); 22 | 23 | static int 24 | testfn(char **ret, const char *fmt, ...) 25 | { 26 | va_list ap; 27 | int irc; 28 | 29 | va_start(ap, fmt); 30 | irc = vasprintf(ret, fmt, ap); 31 | va_end(ap); 32 | 33 | return irc; 34 | } 35 | 36 | int 37 | main(void) 38 | { 39 | char *ret; 40 | 41 | if (testfn(&ret, "%s.", "Text") != 5) 42 | return 1; 43 | if (strcmp(ret, "Text.")) 44 | return 2; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /compat/getprogname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #if HAVE___PROGNAME 20 | 21 | #include 22 | 23 | extern char *__progname; 24 | 25 | const char * 26 | getprogname(void) 27 | { 28 | return __progname; 29 | } 30 | 31 | #elif HAVE_PROGRAM_INVOCATION_SHORT_NAME 32 | 33 | #include 34 | 35 | extern char *program_invocation_short_name; 36 | 37 | const char * 38 | getprogname(void) 39 | { 40 | return program_invocation_short_name; 41 | } 42 | 43 | #else 44 | # warning Found no way to get the program name, will use "gmid" for all utilities. 45 | const char * 46 | getprogname(void) 47 | { 48 | return "gmid"; 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /site/subst: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 3 | # Copyright (c) 2022 Omar Polo 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | # 17 | # subst -- filter that replaces key=values pairs 18 | # 19 | # usage: subst key1=val1 [... keyn=valn] [files...] 20 | # 21 | # Use `--' before the first file if it may contain an = in its name. 22 | # If no files are given, read and substitute from standard input. 23 | 24 | use v5.10; 25 | use strict; 26 | use warnings; 27 | 28 | my @args = (); 29 | 30 | while (1) { 31 | $_ = shift; 32 | last if !$_; 33 | 34 | if ($_ eq '--') { 35 | last; 36 | } elsif ($_ !~ m/=/) { 37 | unshift @ARGV, $_; 38 | last; 39 | } 40 | 41 | my ($match, $repl) = m/^([^\s]*)=(.*)$/; 42 | push @args, "-e", "s,$match,$repl,g"; 43 | } 44 | 45 | # OK, shelling out to sed is a bit lame... 46 | exec "sed", @args, @ARGV; 47 | -------------------------------------------------------------------------------- /compat/reallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "../config.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /* 26 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 27 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 28 | */ 29 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) 30 | 31 | void * 32 | reallocarray(void *optr, size_t nmemb, size_t size) 33 | { 34 | if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 35 | nmemb > 0 && SIZE_MAX / nmemb < size) { 36 | errno = ENOMEM; 37 | return NULL; 38 | } 39 | return realloc(optr, size * nmemb); 40 | } 41 | -------------------------------------------------------------------------------- /have/landlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #ifndef landlock_create_ruleset 25 | static inline int 26 | landlock_create_ruleset(const struct landlock_ruleset_attr *attr, size_t size, 27 | __u32 flags) 28 | { 29 | return syscall(__NR_landlock_create_ruleset, attr, size, flags); 30 | } 31 | #endif 32 | 33 | int 34 | main(void) 35 | { 36 | int rfd; 37 | const struct landlock_ruleset_attr rsattr = { 38 | .handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE | 39 | LANDLOCK_ACCESS_FS_READ_DIR 40 | }; 41 | 42 | rfd = landlock_create_ruleset(&rsattr, sizeof(rsattr), 0); 43 | return rfd == -1; 44 | } 45 | -------------------------------------------------------------------------------- /.cirrus.yml: -------------------------------------------------------------------------------- 1 | # seems that inside the CI it's not currently possible to bind to ::1 2 | # so set HAVE_IPV6=no. 3 | 4 | linux_amd64_task: 5 | container: 6 | image: alpine:latest 7 | test_script: 8 | - apk add alpine-sdk linux-headers bison libretls-dev libevent-dev 9 | - ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations' -Werror 10 | - make 11 | - make regress REGRESS_HOST="*" HAVE_IPV6=no 12 | 13 | linux_arm_task: 14 | arm_container: 15 | image: alpine:latest 16 | test_script: 17 | - apk add alpine-sdk linux-headers bison libretls-dev libevent-dev 18 | - ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations' -Werror 19 | - make 20 | - make regress REGRESS_HOST="*" HAVE_IPV6=no 21 | 22 | freebsd_14_task: 23 | freebsd_instance: 24 | image_family: freebsd-14-2 25 | install_script: pkg install -y libevent libressl pkgconf 26 | script: 27 | - ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations' -Werror 28 | - make 29 | - make regress HAVE_IPV6=no 30 | 31 | # 32 | # There are some issues with imsg fd passing on macos at the moment that 33 | # seem to be triggered only in applications that do a heavy use of them, 34 | # like gmid or opensmtpd. Still, keep macos to ensure gmid builds here. 35 | # 36 | mac_task: 37 | macos_instance: 38 | image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest 39 | test_script: 40 | - brew install libevent openssl libretls 41 | - PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig" ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations' -Werror 42 | - make 43 | - SKIP_RUNTIME_TESTS=1 make regress 44 | -------------------------------------------------------------------------------- /compat/setproctitle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Nicholas Marriott 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 13 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 14 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #if HAVE_PR_SET_NAME 26 | 27 | #include 28 | 29 | void 30 | setproctitle(const char *fmt, ...) 31 | { 32 | char title[16], name[16], *cp; 33 | va_list ap; 34 | int used; 35 | 36 | va_start(ap, fmt); 37 | vsnprintf(title, sizeof title, fmt, ap); 38 | va_end(ap); 39 | 40 | used = snprintf(name, sizeof name, "%s: %s", getprogname(), title); 41 | if (used >= (int)sizeof name) { 42 | cp = strrchr(name, ' '); 43 | if (cp != NULL) 44 | *cp = '\0'; 45 | } 46 | prctl(PR_SET_NAME, name); 47 | } 48 | #else 49 | void 50 | setproctitle(const char *fmt, ...) 51 | { 52 | (void)fmt; 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /compat/vasprintf.c: -------------------------------------------------------------------------------- 1 | /* from mandoc, with tweaks */ 2 | /* 3 | * Copyright (c) 2015 Ingo Schwarze 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | * 17 | * This fallback implementation is not efficient: 18 | * It does the formatting twice. 19 | * Short of fiddling with the unknown internals of the system's 20 | * printf(3) or completely reimplementing printf(3), i can't think 21 | * of another portable solution. 22 | */ 23 | 24 | #include "../config.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | int 31 | vasprintf(char **ret, const char *format, va_list ap) 32 | { 33 | char buf[2]; 34 | va_list ap2; 35 | int sz; 36 | 37 | va_copy(ap2, ap); 38 | sz = vsnprintf(buf, sizeof(buf), format, ap2); 39 | va_end(ap2); 40 | 41 | if (sz != -1 && (*ret = malloc(sz + 1)) != NULL) { 42 | if (vsnprintf(*ret, sz + 1, format, ap) == sz) 43 | return sz; 44 | free(*ret); 45 | } 46 | *ret = NULL; 47 | return -1; 48 | } 49 | -------------------------------------------------------------------------------- /have/libevent2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static void 29 | rw_cb(struct bufferevent *bev, void *d) 30 | { 31 | return; 32 | } 33 | 34 | static void 35 | err_cb(struct bufferevent *bev, short err, void *d) 36 | { 37 | return; 38 | } 39 | 40 | int 41 | main(void) 42 | { 43 | struct bufferevent *bev; 44 | 45 | event_init(); 46 | 47 | if ((bev = bufferevent_new(0, rw_cb, rw_cb, err_cb, NULL)) == NULL) 48 | return 1; 49 | 50 | evbuffer_unfreeze(bev->input, 0); 51 | evbuffer_unfreeze(bev->output, 1); 52 | 53 | bufferevent_free(bev); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /regress/fuzz/Makefile: -------------------------------------------------------------------------------- 1 | DISTFILES = Makefile \ 2 | iri.c 3 | 4 | include ../../config.mk 5 | 6 | CC = afl-clang 7 | 8 | COBJS = ${COMPATS:.c=.o} 9 | REG_COMPATS = ${COBJS:%=../../%} 10 | 11 | IRI_SRCS = iri.c ../../iri.c ../../utf8.c ../../log.c 12 | IRI_OBJS = ${IRI_SRCS:.c=.o} ${REG_COMPATS} 13 | 14 | PROXY_SRCS = proxy.c ../../proxy-proto.c ../../log.c 15 | PROXY_OBJS = ${PROXY_SRCS:.c=.o} ${REG_COMPATS} 16 | 17 | .PHONY: all data clean dist 18 | 19 | all: 20 | @echo run ${MAKE} fuzz-iri to fuzz the IRI parser 21 | @echo run ${MAKE} fuzz-proxy to fuzz the proxy v1 protocol parser 22 | 23 | fuzz-iri: iri 24 | rm -rf in out 25 | mkdir -p in out 26 | echo 'gemini://omarpolo.com/' > in/simple 27 | echo 'https://op:123@omarpolo.com/' > in/auth 28 | echo 'ftp://op@omarpolo.com/a/bb/c' > in/path 29 | echo 'gemini://omarpolo.com/?some=val' > in/query 30 | echo 'gemini://omarpolo.com/b/#xyz' > in/fragment 31 | echo 'gemini://omarpolo.com/b/?x=y#xyz' > in/qf 32 | echo 'ssh://omarpolo.com/%2F/' > in/enc 33 | echo 'http://omarpolo.com/foo/.././' > in/dots 34 | echo 'http://omarpolo.com/////././' > in/slash 35 | afl-fuzz -i in -o out -- ./iri 36 | 37 | fuzz-proxy: proxy 38 | rm -rf in out 39 | mkdir -p in out 40 | printf 'PROXY TCP4 255.255.255.255 255.255.255.255 65535 65535\r\n' >in/ipv4 41 | printf 'PROXY TCP6 fe80::1 fd4b:b287:5c6f:1f4::2 65535 65535\r\n' >in/ipv6 42 | printf 'PROXY UNKNOWN\r\n' > in/unknown 43 | afl-fuzz -i in -o out -- ./proxy 44 | 45 | iri: ${IRI_OBJS} 46 | ${CC} ${IRI_OBJS} -o $@ ${LIBS} ${LDFLAGS} 47 | 48 | proxy: ${PROXY_OBJS} 49 | ${CC} ${PROXY_OBJS} -o $@ ${LIBS} ${LDFLAGS} 50 | 51 | .c.o: 52 | ${CC} -I../.. ${CFLAGS} -c $< -o $@ 53 | 54 | clean: 55 | rm -f *.o iri 56 | -------------------------------------------------------------------------------- /compat/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998, 2015 Todd C. Miller 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | #include 21 | 22 | /* 23 | * Copy string src to buffer dst of size dsize. At most dsize-1 24 | * chars will be copied. Always NUL terminates (unless dsize == 0). 25 | * Returns strlen(src); if retval >= dsize, truncation occurred. 26 | */ 27 | size_t 28 | strlcpy(char *dst, const char *src, size_t dsize) 29 | { 30 | const char *osrc = src; 31 | size_t nleft = dsize; 32 | 33 | /* Copy as many bytes as will fit. */ 34 | if (nleft != 0) { 35 | while (--nleft != 0) { 36 | if ((*dst++ = *src++) == '\0') 37 | break; 38 | } 39 | } 40 | 41 | /* Not enough room in dst, add NUL and traverse rest of src. */ 42 | if (nleft == 0) { 43 | if (dsize != 0) 44 | *dst = '\0'; /* NUL-terminate dst */ 45 | while (*src++) 46 | ; 47 | } 48 | 49 | return(src - osrc - 1); /* count does not include NUL */ 50 | } 51 | -------------------------------------------------------------------------------- /compat/timingsafe_memcmp.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: timingsafe_memcmp.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */ 2 | /* 3 | * Copyright (c) 2014 Google Inc. 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "../config.h" 19 | 20 | #include 21 | #include 22 | 23 | int 24 | timingsafe_memcmp(const void *b1, const void *b2, size_t len) 25 | { 26 | const unsigned char *p1 = b1, *p2 = b2; 27 | size_t i; 28 | int res = 0, done = 0; 29 | 30 | for (i = 0; i < len; i++) { 31 | /* lt is -1 if p1[i] < p2[i]; else 0. */ 32 | int lt = (p1[i] - p2[i]) >> CHAR_BIT; 33 | 34 | /* gt is -1 if p1[i] > p2[i]; else 0. */ 35 | int gt = (p2[i] - p1[i]) >> CHAR_BIT; 36 | 37 | /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */ 38 | int cmp = lt - gt; 39 | 40 | /* set res = cmp if !done. */ 41 | res |= cmp & ~done; 42 | 43 | /* set done if p1[i] != p2[i]. */ 44 | done |= lt | gt; 45 | } 46 | 47 | return (res); 48 | } 49 | -------------------------------------------------------------------------------- /compat/setresuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au). 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | int 25 | setresuid(uid_t ruid, uid_t euid, uid_t suid) 26 | { 27 | uid_t ouid; 28 | int ret = -1; 29 | 30 | /* Allow only the tested configuration. */ 31 | 32 | if (ruid != euid || euid != suid) { 33 | errno = ENOSYS; 34 | return -1; 35 | } 36 | ouid = getuid(); 37 | 38 | if ((ret = setreuid(euid, euid)) == -1) 39 | return -1; 40 | 41 | /* 42 | * When real, effective and saved uids are the same and we have 43 | * changed uids, sanity check that we cannot restore the old uid. 44 | */ 45 | 46 | if (ruid == euid && euid == suid && ouid != ruid && 47 | setuid(ouid) != -1 && seteuid(ouid) != -1) { 48 | errno = EINVAL; 49 | return -1; 50 | } 51 | 52 | /* 53 | * Finally, check that the real and effective uids are what we 54 | * expect. 55 | */ 56 | if (getuid() != ruid || geteuid() != euid) { 57 | errno = EACCES; 58 | return -1; 59 | } 60 | 61 | return ret; 62 | } 63 | -------------------------------------------------------------------------------- /log.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: log.h,v 1.2 2021/12/13 18:28:40 deraadt Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2003, 2004 Henning Brauer 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef LOG_H 20 | #define LOG_H 21 | 22 | #include 23 | 24 | void log_init(int, int); 25 | void log_procinit(const char *); 26 | void log_setverbose(int); 27 | int log_getverbose(void); 28 | void log_warn(const char *, ...) 29 | __attribute__((__format__ (printf, 1, 2))); 30 | void log_warnx(const char *, ...) 31 | __attribute__((__format__ (printf, 1, 2))); 32 | void log_info(const char *, ...) 33 | __attribute__((__format__ (printf, 1, 2))); 34 | void log_debug(const char *, ...) 35 | __attribute__((__format__ (printf, 1, 2))); 36 | void logit(int, const char *, ...) 37 | __attribute__((__format__ (printf, 2, 3))); 38 | void vlog(int, const char *, va_list) 39 | __attribute__((__format__ (printf, 2, 0))); 40 | __dead void fatal(const char *, ...) 41 | __attribute__((__format__ (printf, 1, 2))); 42 | __dead void fatalx(const char *, ...) 43 | __attribute__((__format__ (printf, 1, 2))); 44 | 45 | #endif /* LOG_H */ 46 | -------------------------------------------------------------------------------- /compat/strlcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998, 2015 Todd C. Miller 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | #include 21 | 22 | /* 23 | * Appends src to string dst of size dsize (unlike strncat, dsize is the 24 | * full size of dst, not space left). At most dsize-1 characters 25 | * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). 26 | * Returns strlen(src) + MIN(dsize, strlen(initial dst)). 27 | * If retval >= dsize, truncation occurred. 28 | */ 29 | size_t 30 | strlcat(char *dst, const char *src, size_t dsize) 31 | { 32 | const char *odst = dst; 33 | const char *osrc = src; 34 | size_t n = dsize; 35 | size_t dlen; 36 | 37 | /* Find the end of dst and adjust bytes left but don't go past end. */ 38 | while (n-- != 0 && *dst != '\0') 39 | dst++; 40 | dlen = dst - odst; 41 | n = dsize - dlen; 42 | 43 | if (n-- == 0) 44 | return(dlen + strlen(src)); 45 | while (*src != '\0') { 46 | if (n != 0) { 47 | *dst++ = *src; 48 | n--; 49 | } 50 | src++; 51 | } 52 | *dst = '\0'; 53 | 54 | return(dlen + (src - osrc)); /* count does not include NUL */ 55 | } 56 | -------------------------------------------------------------------------------- /regress/env: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | printf "20 text/plain; lang=en\r\n" 6 | 7 | cat < means "not set". 21 | 22 | EOF 23 | 24 | echo GATEWAY_INTERFACE=$GATEWAY_INTERFACE 25 | echo GEMINI_DOCUMENT_ROOT=$GEMINI_DOCUMENT_ROOT 26 | echo GEMINI_SCRIPT_FILENAME=$GEMINI_SCRIPT_FILENAME 27 | echo GEMINI_URL=$GEMINI_URL 28 | echo GEMINI_URL_PATH=$GEMINI_URL_PATH 29 | echo PWD=$PWD 30 | echo PATH_INFO=${PATH_INFO:-""} 31 | echo PATH_TRANSLATED=${PATH_TRANSLATED:-""} 32 | echo QUERY_STRING=$QUERY_STRING 33 | echo REMOTE_ADDR=$REMOTE_ADDR 34 | echo REMOTE_HOST=$REMOTE_HOST 35 | echo REQUEST_METHOD=$REQUEST_METHOD 36 | echo SCRIPT_NAME=$SCRIPT_NAME 37 | echo SERVER_NAME=$SERVER_NAME 38 | echo SERVER_PORT=$SERVER_PORT 39 | echo SERVER_PROTOCOL=$SERVER_PROTOCOL 40 | echo SERVER_SOFTWARE=$SERVER_SOFTWARE 41 | echo AUTH_TYPE=$AUTH_TYPE 42 | echo REMOTE_USER=$REMOTE_USER 43 | echo TLS_CLIENT_ISSUER=$TLS_CLIENT_ISSUER 44 | echo TLS_CLIENT_HASH=$TLS_CLIENT_HASH 45 | echo TLS_CLIENT_NOT_AFTER=$TLS_CLIENT_NOT_AFTER 46 | echo TLS_CLIENT_NOT_BEFORE=$TLS_CLIENT_NOT_BEFORE 47 | echo 48 | echo 49 | echo " CGI Argument List" 50 | echo 51 | echo "- $0" 52 | for i in "$@"; do 53 | echo "- $i" 54 | done 55 | 56 | cat < "; 33 | } 34 | 35 | blockquote p { 36 | font-style: italic; 37 | display: inline; 38 | } 39 | 40 | p.link::before { 41 | content: "→ "; 42 | } 43 | 44 | strong::before { content: "*" } 45 | strong::after { content: "*" } 46 | 47 | hr { 48 | border: 0; 49 | height: 1px; 50 | background-color: #222; 51 | width: 100%; 52 | display: block; 53 | margin: 2em auto; 54 | } 55 | 56 | ul.link-list { 57 | list-style: disclosure-closed; 58 | } 59 | 60 | img { 61 | border-radius: 5px; 62 | } 63 | 64 | pre { 65 | overflow: auto; 66 | padding: 1rem; 67 | background-color: #f0f0f0; 68 | border-radius: 3px; 69 | } 70 | 71 | pre.banner { 72 | display: flex; 73 | flex-direction: row; 74 | justify-content: center; 75 | } 76 | 77 | code, kbd { 78 | color: #9d109d; 79 | } 80 | 81 | img { 82 | display: block; 83 | margin: 0 auto; 84 | max-width: 100%; 85 | } 86 | 87 | @media (prefers-color-scheme: dark) { 88 | body { 89 | background-color: #222; 90 | color: white; 91 | } 92 | 93 | a { 94 | color: aqua; 95 | } 96 | 97 | hr { 98 | background-color: #ddd; 99 | } 100 | 101 | pre { 102 | background-color: #353535; 103 | } 104 | 105 | code, kbd { 106 | color: #ff4cff; 107 | } 108 | } 109 | 110 | @media (max-width: 400px) { 111 | pre.banner { font-size: 9px; } 112 | } 113 | 114 | @media (max-width: 500px) { 115 | pre.banner { font-size: 10px; } 116 | } 117 | -------------------------------------------------------------------------------- /compat/strtonum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Ted Unangst and Todd Miller 3 | * All rights reserved. 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "../config.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define INVALID 1 25 | #define TOOSMALL 2 26 | #define TOOLARGE 3 27 | 28 | long long 29 | strtonum(const char *numstr, long long minval, long long maxval, 30 | const char **errstrp) 31 | { 32 | long long ll = 0; 33 | int error = 0; 34 | char *ep; 35 | struct errval { 36 | const char *errstr; 37 | int err; 38 | } ev[4] = { 39 | { NULL, 0 }, 40 | { "invalid", EINVAL }, 41 | { "too small", ERANGE }, 42 | { "too large", ERANGE }, 43 | }; 44 | 45 | ev[0].err = errno; 46 | errno = 0; 47 | if (minval > maxval) { 48 | error = INVALID; 49 | } else { 50 | ll = strtoll(numstr, &ep, 10); 51 | if (numstr == ep || *ep != '\0') 52 | error = INVALID; 53 | else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) 54 | error = TOOSMALL; 55 | else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) 56 | error = TOOLARGE; 57 | } 58 | if (errstrp != NULL) 59 | *errstrp = ev[error].errstr; 60 | errno = ev[error].err; 61 | if (error) 62 | ll = 0; 63 | 64 | return (ll); 65 | } 66 | -------------------------------------------------------------------------------- /regress/invalid: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | printf 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii' 4 | -------------------------------------------------------------------------------- /compat/err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "../config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static void vwarn_impl(const char*, va_list); 26 | static void vwarnx_impl(const char*, va_list); 27 | 28 | static void 29 | vwarn_impl(const char *fmt, va_list ap) 30 | { 31 | fprintf(stderr, "%s: ", getprogname()); 32 | vfprintf(stderr, fmt, ap); 33 | fprintf(stderr, ": %s\n", strerror(errno)); 34 | } 35 | 36 | static void 37 | vwarnx_impl(const char *fmt, va_list ap) 38 | { 39 | fprintf(stderr, "%s: ", getprogname()); 40 | vfprintf(stderr, fmt, ap); 41 | fprintf(stderr, "\n"); 42 | } 43 | 44 | void 45 | err(int ret, const char *fmt, ...) 46 | { 47 | va_list ap; 48 | 49 | va_start(ap, fmt); 50 | vwarn_impl(fmt, ap); 51 | va_end(ap); 52 | exit(ret); 53 | } 54 | 55 | void 56 | errx(int ret, const char *fmt, ...) 57 | { 58 | va_list ap; 59 | 60 | va_start(ap, fmt); 61 | vwarnx_impl(fmt, ap); 62 | va_end(ap); 63 | exit(ret); 64 | } 65 | 66 | void 67 | warn(const char *fmt, ...) 68 | { 69 | va_list ap; 70 | 71 | va_start(ap, fmt); 72 | vwarn_impl(fmt, ap); 73 | va_end(ap); 74 | } 75 | 76 | void 77 | warnx(const char *fmt, ...) 78 | { 79 | va_list ap; 80 | 81 | va_start(ap, fmt); 82 | vwarnx_impl(fmt, ap); 83 | va_end(ap); 84 | } 85 | -------------------------------------------------------------------------------- /site/index.gmi: -------------------------------------------------------------------------------- 1 | # gmid 2 | 3 | > A Gemini server 4 | 5 | gmid is a full-featured Gemini server written with security in mind. It can serve static files, has an optional FastCGI and proxying support and a rich configuration syntax. 6 | 7 | gmid also bundles a small gemini client called ‘gg’ (gemini get), a small command-line server for quick testing called ‘gemexp’ and a titan implementation. 8 | 9 | => gmid.8.MANEXT gmid(8) - Gemini server 10 | => gmid.conf.5.MANEXT gmid.conf(5) - gmid configuration file 11 | => gg.1.MANEXT gg(1) - gemini client 12 | => gemexp.1.MANEXT gemexp(1) - export a directory over Gemini 13 | => titan.1.MANEXT titan(1) - Titan client 14 | 15 | ## Install 16 | 17 | Some distros provide a package — thanks to the maintainers! 18 | 19 | => REPOLOGY Repology: packaging status for gmid 20 | 21 | Otherwise, compile it from source: it’s easy and takes less than a minute on a raspberry pi 3 22 | 23 | => SITE/gmid-VERS.tar.gz gmid-VERS.tar.gz 24 | 25 | => https://git.omarpolo.com/?action=summary&path=gmid.git git repository 26 | => https://codeberg.org/op/gmid/ Codeberg mirror 27 | => GITHUB GitHub mirror 28 | 29 | The dependencies are: 30 | 31 | * libevent 32 | * LibreSSL or OpenSSL 33 | * yacc or GNU bison 34 | 35 | Once all the dependencies are installed, building is as easy as: 36 | 37 | ```Example of how to compile from source 38 | $ curl -LO SITE/gmid-VERS.tar.gz 39 | $ tar xzvf gmid-VERS.tar.gz 40 | $ cd gmid-VERS 41 | $ ./configure 42 | $ make 43 | $ sudo make install # eventually 44 | ``` 45 | 46 | A SHA256 file is available. However, it only checks for accidental corruption. You can use signify (gmid-VERS.sha256.sig) and the public key PUBKEY to cryptographically verify the downloaded tarball. The signify public key for the previous and the next release is included in the tarball. 47 | 48 | => SITE/gmid-VERS.sha256 gmid-VERS.sha256 49 | => SITE/gmid-VERS.sha256.sig gmid-VERS.sha256.sig 50 | 51 | To verify the signatures with signify(1): 52 | 53 | ```Example of how to verify the signature with signify 54 | % signify -C -p PUBKEY -x gmid-VERS.sha256.sig 55 | Signature Verified 56 | gmid-VERS.tar.gz: OK 57 | ``` 58 | 59 | Git tags are signed with the following ssh key: 60 | 61 | ``` 62 | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ0nD5I8BNVJknT87gnpLIJWK0fXTayDktQOlS38CGj4 op@omarpolo.com 63 | ``` 64 | -------------------------------------------------------------------------------- /regress/regress: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -f gmid.pid 4 | 5 | . ./lib.sh 6 | . ./tests.sh 7 | 8 | trap 'onexit' INT TERM EXIT 9 | 10 | if [ $# -ne 0 ]; then 11 | while [ $# -ne 0 ]; do 12 | run_test $1 13 | shift 14 | done 15 | 16 | tests_done 17 | fi 18 | 19 | # Run standalone unit tests. 20 | run_test test_punycode 21 | run_test test_iri 22 | run_test test_gg_n_flag 23 | 24 | # Run configuration parsing tests. 25 | run_test test_parse_comments_at_start 26 | run_test test_dump_config 27 | 28 | if [ "${SKIP_RUNTIME_TESTS:-0}" -eq 1 ]; then 29 | echo 30 | echo "======================" 31 | echo "runtime tests skipped!" 32 | echo "======================" 33 | echo 34 | 35 | tests_done 36 | fi 37 | 38 | # Run regression tests for the gemexp binary. 39 | run_test test_gemexp 40 | 41 | # Run regression tests for the gmid binary. 42 | run_test test_static_files 43 | run_test test_alias 44 | run_test test_alias_long_hostname 45 | run_test test_directory_redirect 46 | run_test test_serve_big_files 47 | run_test test_dont_execute_scripts 48 | run_test test_custom_mime 49 | run_test test_default_type 50 | run_test test_custom_lang 51 | run_test test_parse_custom_lang_per_location 52 | run_test test_custom_index 53 | run_test test_custom_index_default_type_per_location 54 | run_test test_auto_index 55 | run_test test_block 56 | run_test test_block_return_fmt 57 | run_test test_require_client_ca 58 | run_test test_root_inside_location 59 | run_test test_root_inside_location_with_redirect 60 | run_test test_fastcgi 61 | run_test test_fastcgi_inside_location 62 | run_test test_fastcgi_location_match 63 | run_test test_fastcgi_deprecated_syntax 64 | run_test test_macro_expansion 65 | run_test test_proxy_relay_to 66 | run_test test_proxy_with_certs 67 | # run_test test_unknown_host # XXX: breaks on some distro 68 | run_test test_include_mime 69 | run_test test_log_file 70 | run_test test_log_common 71 | run_test test_log_combined 72 | run_test test_ipv4_addr 73 | run_test test_ipv6_addr need_ipv6 74 | run_test test_ipv6_server need_ipv6 75 | run_test test_high_prefork 76 | run_test test_proxy_protocol_v1 77 | 78 | # TODO: add test that uses only a TLSv1.2 or TLSv1.3 79 | # TODO: add a test that attempt to serve a non-regular file 80 | # TODO: add a test where the index is not a regular file 81 | # TODO: add a test that logs and uses a client cert 82 | 83 | tests_done 84 | -------------------------------------------------------------------------------- /site/Makefile: -------------------------------------------------------------------------------- 1 | MANPAGES = gemexp.1 \ 2 | gg.1 \ 3 | gmid.conf.5 \ 4 | gmid.8 \ 5 | titan.1 6 | 7 | PAGES = index.gmi \ 8 | changelog.gmi \ 9 | contrib.gmi \ 10 | quickstart.gmi \ 11 | faq.gmi 12 | 13 | TITLE_index.gmi = home 14 | TITLE_changelog.gmi = changelog 15 | TITLE_contrib.gmi = contrib 16 | TITLE_quickstart.gmi = guide 17 | TITLE_faq.gmi = faq 18 | 19 | REPOLOGY_BANNER = https://repology.org/badge/vertical-allrepos/gmid.svg 20 | REPOLOGY_URL = https://repology.org/project/gmid/versions 21 | 22 | SUBST = ./subst GITHUB=https://github.com/omar-polo/gmid \ 23 | SITE=https://ftp.omarpolo.com \ 24 | VERS=2.1.1 \ 25 | PUBKEY=gmid-2.1.pub \ 26 | TREE=https://github.com/omar-polo/gmid/blob/master 27 | 28 | SUBST_GEM = ${SUBST} MANEXT=txt EXT=gmi REPOLOGY=${REPOLOGY_URL} 29 | SUBST_WWW = ${SUBST} MANEXT=html EXT=html REPOLOGY=${REPOLOGY_BANNER} 30 | 31 | .PHONY: all dirs manpages serve-www serve-gemini upload clean titles 32 | 33 | all: dirs manpages pages 34 | cp style.css mandoc.css www/ 35 | cp vim-screenshot.png www/ 36 | cp vim-screenshot.png gemini/ 37 | 38 | dirs: 39 | mkdir -p gemini www 40 | 41 | MANOPTS = -Oman='%N.%S.html;https://man.openbsd.org/%N.%S',style=mandoc.css 42 | 43 | manpages: 44 | .for m in ${MANPAGES} 45 | @echo generating www/${m:T}.html 46 | cd .. && man -Thtml ${MANOPTS} -l $m > site/www/${m:T}.html 47 | man -O width=65 -Tutf8 -l $m | col -b > gemini/${m:T}.txt 48 | .endfor 49 | 50 | pages: 51 | .for p in ${PAGES} 52 | ${MAKE} titles-gem | ./menu.pl $p gemini > gemini/$p 53 | ${SUBST_GEM} $p >> gemini/$p 54 | 55 | ${SUBST_WWW} TITLE=${TITLE_${p}:Q} header.html > www/${p:.gmi=.html} 56 | ${MAKE} titles-www | ./menu.pl "${p:.gmi=.html}" html >> www/${p:.gmi=.html} 57 | ${SUBST_WWW} $p | ./gem2html >> www/${p:.gmi=.html} 58 | cat footer.html >> www/${p:.gmi=.html} 59 | .endfor 60 | 61 | serve-www: 62 | python3 -m http.server --directory www 8888 63 | 64 | serve-gemini: 65 | ./../gemexp ./gemini 66 | 67 | upload: 68 | openrsync --rsync-path=openrsync --del -a www/ antartica:/var/www/gmid.omarpolo.com 69 | openrsync --rsync-path=openrsync --del -a gemini/ antartica:/var/gemini/gmid.omarpolo.com 70 | 71 | titles-gem: 72 | .for p in ${PAGES} 73 | @printf "%s %s\n" "${p}" ${TITLE_${p}:Q} 74 | .endfor 75 | 76 | titles-www: 77 | .for p in ${PAGES} 78 | @printf "%s %s\n" "${p:.gmi=.html}" ${TITLE_${p}:Q} 79 | .endfor 80 | -------------------------------------------------------------------------------- /site/faq.gmi: -------------------------------------------------------------------------------- 1 | # Frequently Asked Questions 2 | 3 | ## How can I report a bug, suggest a feature or send a patch? 4 | 5 | Just drop an email to or open an issue/pull request on Codeberg or Github. 6 | 7 | => https://codeberg.org/op/gmid Codeberg mirror 8 | => https://github.com/omar-polo/gmid GitHub mirror 9 | 10 | When reporting a bug please include the relevant information to reproduce the issue you're facing: your configuration file, the gmid version, and your operating system or distro at least. 11 | 12 | 13 | ## How can I define the right MIME types for my files? 14 | 15 | gmid, like many other servers, uses a list of known file extensions to decide what MIME type use. A few of them are built-in for convenience but it's quite easy to add custom ones: 16 | 17 | ``` example of how to use the type rule in the configuration file 18 | types { 19 | application/postscript ps eps ai 20 | application/rss+xml rss 21 | 22 | # it's also possible to just include a file here 23 | include "/usr/share/misc/mime.types" 24 | } 25 | ``` 26 | 27 | 28 | ## How to run CGI scripts? 29 | 30 | As of gmid 2.0, to run CGI scripts an external program like fcgiwrap or slowcgi are needed. 31 | 32 | From the gmid side, one `fastcgi' block needs to be defined with the `socket' pointing at the fcgiwrap or slowcgi socket inside the chroot. The `SCRIPT_NAME' parameter pointing to the script path is often needed since gmid is unable to deduce the right path otherwise. 33 | 34 | ``` example configuration that runs a CGI via slowcgi 35 | server "example.com" { 36 | listen on * 37 | cert "/path/to/cert" 38 | key "/path/to/key" 39 | 40 | location "/cgi-bin/hello" { 41 | fastcgi { 42 | socket "/run/slowcgi.sock" 43 | param SCRIPT_NAME = "/cgi-bin/hello" 44 | } 45 | } 46 | } 47 | ``` 48 | 49 | Then, fcgiwrap or slowcgi need to be started as well. 50 | 51 | 52 | ## How to automatically renew the certificates? 53 | 54 | It depends on how the certificate were obtained. For example, if acme-client or certbot are used they provide their own mechanism to renew the certs and restart daemons. 55 | 56 | In case of a self-signed certificate, contrib/renew-certs could help. It's meant to be scheduled periodically with cron(8) and automatically generate a new key and certificate when one is about to expire and restarts gmid. 57 | 58 | => TREE/contrib/renew-certs contrib/renew-certs 59 | -------------------------------------------------------------------------------- /regress/puny-test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Omar Polo 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include "../gmid.h" 21 | 22 | const struct suite { 23 | const char *src; 24 | const char *res; 25 | } t[] = { 26 | {"foo", "foo"}, 27 | {"h.n", "h.n"}, 28 | {"xn-invalid", "xn-invalid"}, 29 | {"naïve", "naïve"}, 30 | {"xn--8ca", "è"}, 31 | {"xn--caff-8oa", "caffè"}, 32 | {"xn--nave-6pa", "naïve"}, 33 | {"xn--e-0mbbc", "τeστ"}, 34 | {"xn--8ca67lbac", "τèστ"}, 35 | {"xn--28j2a3ar1p", "こんにちは"}, 36 | {"xn--hello--ur7iy09x", "hello-世界"}, 37 | {"xn--hi--hi-rr7iy09x", "hi-世界-hi"}, 38 | {"xn--caf-8la.foo.org", "cafè.foo.org"}, 39 | /* 3 bytes */ 40 | {"xn--j6h", "♨"}, 41 | /* 4 bytes */ 42 | {"xn--x73l", "𩸽"}, 43 | {"xn--x73laaa", "𩸽𩸽𩸽𩸽"}, 44 | {NULL, NULL} 45 | }; 46 | 47 | void 48 | sandbox_logger_process(void) 49 | { 50 | /* to make the linker happy! */ 51 | return; 52 | } 53 | 54 | int 55 | main(int argc, char **argv) 56 | { 57 | const struct suite *i; 58 | int failed; 59 | char buf[64]; /* name len */ 60 | const char *parse_err; 61 | 62 | failed = 0; 63 | for (i = t; i->src != NULL; ++i) { 64 | memset(buf, 0, sizeof(buf)); 65 | if (!puny_decode(i->src, buf, sizeof(buf), &parse_err)) { 66 | printf("decode: failure with %s: %s\n", 67 | i->src, parse_err); 68 | failed = 1; 69 | continue; 70 | } 71 | 72 | if (strcmp(buf, i->res)) { 73 | printf("ERR: expected \"%s\", got \"%s\"\n", 74 | i->res, buf); 75 | failed = 1; 76 | continue; 77 | } else 78 | printf("OK: %s => %s\n", i->src, buf); 79 | } 80 | 81 | return failed; 82 | } 83 | -------------------------------------------------------------------------------- /compat/libtls/asn.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: a_time_tm.c,v 1.15 2018/04/25 11:48:21 tb Exp $ */ 2 | /* 3 | * Copyright (c) 2015 Bob Beck 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "config.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define GENTIME_LENGTH 15 27 | #define UTCTIME_LENGTH 13 28 | 29 | #define V_ASN1_UTCTIME 23 30 | #define V_ASN1_GENERALIZEDTIME 24 31 | 32 | #ifndef HAVE_ASN1_TIME_TM_CMP 33 | int 34 | ASN1_time_tm_cmp(struct tm *tm1, struct tm *tm2) 35 | { 36 | if (tm1->tm_year < tm2->tm_year) 37 | return (-1); 38 | if (tm1->tm_year > tm2->tm_year) 39 | return (1); 40 | if (tm1->tm_mon < tm2->tm_mon) 41 | return (-1); 42 | if (tm1->tm_mon > tm2->tm_mon) 43 | return (1); 44 | if (tm1->tm_mday < tm2->tm_mday) 45 | return (-1); 46 | if (tm1->tm_mday > tm2->tm_mday) 47 | return (1); 48 | if (tm1->tm_hour < tm2->tm_hour) 49 | return (-1); 50 | if (tm1->tm_hour > tm2->tm_hour) 51 | return (1); 52 | if (tm1->tm_min < tm2->tm_min) 53 | return (-1); 54 | if (tm1->tm_min > tm2->tm_min) 55 | return (1); 56 | if (tm1->tm_sec < tm2->tm_sec) 57 | return (-1); 58 | if (tm1->tm_sec > tm2->tm_sec) 59 | return (1); 60 | return 0; 61 | } 62 | #endif 63 | 64 | #ifndef HAVE_ASN1_TIME_TM_CLAMP_NOTAFTER 65 | int 66 | ASN1_time_tm_clamp_notafter(struct tm *tm) 67 | { 68 | #ifdef SMALL_TIME_T 69 | struct tm broken_os_epoch_tm; 70 | time_t broken_os_epoch_time = INT_MAX; 71 | 72 | if (gmtime_r(&broken_os_epoch_time, &broken_os_epoch_tm) == NULL) 73 | return 0; 74 | 75 | if (ASN1_time_tm_cmp(tm, &broken_os_epoch_tm) == 1) 76 | memcpy(tm, &broken_os_epoch_tm, sizeof(*tm)); 77 | #endif 78 | return 1; 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /contrib/gencert: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # NAME 4 | # gencert - generate certificates 5 | # 6 | # SYNOPSIS 7 | # ./gencert [-efh] [-D days] [-d destdir] hostname 8 | # 9 | # DESCRIPTION 10 | # A simple script to generate self-signed X.509 certificates for 11 | # gmid. 12 | # 13 | # The option are as follows: 14 | # -D Specify the number of days the certificate 15 | # will be valid for. Use 365 (a year) by default. 16 | # -d Save the certificates to the given directory. 17 | # By default the current directory is used. 18 | # -e Use an EC key instead of RSA. 19 | # -f Forcefully overwrite existing certificates 20 | # without prompting. 21 | # -h Display usage and exit. 22 | # 23 | # SEE ALSO 24 | # openssl(1) 25 | # 26 | 27 | progname="$(basename -- "$0")" 28 | 29 | usage() { 30 | echo "usage: $progname [-fhe] [-d destdir] [-D days] hostname" >&2 31 | echo "Please read the comment at the top of $0 for the usage." >&2 32 | exit $1 33 | } 34 | 35 | ec=no 36 | force=no 37 | destdir=. 38 | days=365 39 | 40 | while getopts "D:d:efh" flag; do 41 | case $flag in 42 | D) days="$OPTARG" ;; 43 | d) destdir="${OPTARG%/}" ;; 44 | e) ec=yes ;; 45 | f) force=yes ;; 46 | h) usage 0 ;; 47 | ?) usage 1 ;; 48 | esac 49 | done 50 | 51 | shift $(($OPTIND - 1)) 52 | 53 | if [ $# -ne 1 ]; then 54 | usage 1 55 | fi 56 | 57 | if [ ! -d "${destdir}" ]; then 58 | echo "${progname}: ${destdir} is not a directory." >&2 59 | usage 1 60 | fi 61 | 62 | hostname="${1}" 63 | pem="${destdir}/${hostname}.pem" 64 | key="${destdir}/${hostname}.key" 65 | 66 | if [ -f "$pem" -o -f "$key" ]; then 67 | if [ $force = no ]; then 68 | while :; do 69 | printf "Overwrite existing certificate $pem? [y/n] " 70 | if ! read -r reply; then 71 | echo 72 | exit 1 73 | fi 74 | case "$reply" in 75 | [yY]) echo "overwriting"; break ;; 76 | [nN]) echo "quitting"; exit 0 ;; 77 | esac 78 | done 79 | fi 80 | fi 81 | 82 | if [ $ec = yes ]; then 83 | openssl ecparam -name secp384r1 -genkey -noout -out "${key}" && \ 84 | openssl req -new -x509 -key "${key}" -out "${pem}" -days "${days}" \ 85 | -nodes -subj "/CN=$hostname" 86 | else 87 | openssl req -x509 \ 88 | -newkey rsa:4096 \ 89 | -out "${pem}" \ 90 | -keyout "${key}" \ 91 | -days "${days}" \ 92 | -nodes \ 93 | -subj "/CN=$hostname" 94 | fi 95 | 96 | e=$? 97 | if [ $e -ne 0 ]; then 98 | exit $e 99 | fi 100 | 101 | echo 102 | echo "Generated files:" 103 | echo " $pem : certificate" 104 | echo " $key : private key" 105 | -------------------------------------------------------------------------------- /gemexp.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2022, 2023 Omar Polo 2 | .\" 3 | .\" Permission to use, copy, modify, and distribute this software for any 4 | .\" purpose with or without fee is hereby granted, provided that the above 5 | .\" copyright notice and this permission notice appear in all copies. 6 | .\" 7 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | .Dd July 3, 2024 15 | .Dt GEMEXP 1 16 | .Os 17 | .Sh NAME 18 | .Nm gemexp 19 | .Nd export a directory over Gemini 20 | .Sh SYNOPSIS 21 | .Nm 22 | .Bk -words 23 | .Op Fl hRVv 24 | .Op Fl d Ar certs-dir 25 | .Op Fl H Ar hostname 26 | .Op Fl p Ar port 27 | .Op Ar directory 28 | .Ek 29 | .Sh DESCRIPTION 30 | .Nm 31 | exports the given 32 | .Ar directory 33 | over the Gemini protocol. 34 | It's intended to be used interactively mostly for testing purposes, 35 | for a full-fledged daemon look for 36 | .Xr gmid 8 . 37 | .Pp 38 | The arguments are as follows: 39 | .Bl -tag -width Ds 40 | .It Fl d Ar certs-path 41 | Directory where certificates are stored. 42 | By default is 43 | .Pa $XDG_DATA_HOME/gemexp , 44 | i.e.\& 45 | .Pa ~/.local/share/gemexp . 46 | .It Fl H Ar hostname 47 | The 48 | .Ar hostname 49 | to use, 50 | .Ar localhost 51 | by default. 52 | Certificates for the given 53 | .Ar hostname 54 | are searched inside the 55 | .Ar certs-dir 56 | specified with the 57 | .Fl d 58 | option. 59 | The certificate files are named 60 | .Ar hostname Ns .pem 61 | and 62 | .Ar hostname Ns .key 63 | and are implicitly generated if not found. 64 | .It Fl h , Fl -help 65 | Print the usage and exit. 66 | .It Fl p Ar port 67 | The port to bind to, 1965 by default. 68 | .It Fl R 69 | Generate an RSA key instead of an EC one. 70 | .It Fl V , Fl -version 71 | Print the version and exit. 72 | .It Fl v 73 | Verbose mode. 74 | .It Ar directory 75 | The root directory to serve, or the current working directory if not 76 | specified. 77 | .El 78 | .Sh SEE ALSO 79 | .Xr gg 1 , 80 | .Xr gmid 8 81 | .Sh ACKNOWLEDGEMENTS 82 | .Nm 83 | uses the 84 | .Dq Flexible and Economical 85 | UTF-8 decoder written by 86 | .An Bjoern Hoehrmann . 87 | .Sh AUTHORS 88 | .An -nosplit 89 | The 90 | .Nm 91 | program was written by 92 | .An Omar Polo Aq Mt op@omarpolo.com . 93 | -------------------------------------------------------------------------------- /compat/arc4random.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: arc4random_linux.h,v 1.12 2019/07/11 10:37:28 inoguchi Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1996, David Mazieres 5 | * Copyright (c) 2008, Damien Miller 6 | * Copyright (c) 2013, Markus Friedl 7 | * Copyright (c) 2014, Theo de Raadt 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | /* 23 | * Stub functions for portability. From LibreSSL with some adaptations. 24 | */ 25 | 26 | #include 27 | 28 | #include 29 | 30 | /* OpenSSH isn't multithreaded */ 31 | #define _ARC4_LOCK() 32 | #define _ARC4_UNLOCK() 33 | #define _ARC4_ATFORK(f) 34 | 35 | static inline void 36 | _getentropy_fail(void) 37 | { 38 | fatal("getentropy failed"); 39 | } 40 | 41 | static volatile sig_atomic_t _rs_forked; 42 | 43 | static inline void 44 | _rs_forkhandler(void) 45 | { 46 | _rs_forked = 1; 47 | } 48 | 49 | static inline void 50 | _rs_forkdetect(void) 51 | { 52 | static pid_t _rs_pid = 0; 53 | pid_t pid = getpid(); 54 | 55 | if (_rs_pid == 0 || _rs_pid == 1 || _rs_pid != pid || _rs_forked) { 56 | _rs_pid = pid; 57 | _rs_forked = 0; 58 | if (rs) 59 | memset(rs, 0, sizeof(*rs)); 60 | } 61 | } 62 | 63 | static inline int 64 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 65 | { 66 | #if defined(MAP_ANON) && defined(MAP_PRIVATE) 67 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, 68 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) 69 | return (-1); 70 | 71 | if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, 72 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { 73 | munmap(*rsp, sizeof(**rsp)); 74 | *rsp = NULL; 75 | return (-1); 76 | } 77 | #else 78 | if ((*rsp = calloc(1, sizeof(**rsp))) == NULL) 79 | return (-1); 80 | if ((*rsxp = calloc(1, sizeof(**rsxp))) == NULL) { 81 | free(*rsp); 82 | *rsp = NULL; 83 | return (-1); 84 | } 85 | #endif 86 | 87 | _ARC4_ATFORK(_rs_forkhandler); 88 | return (0); 89 | } 90 | -------------------------------------------------------------------------------- /titan.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2023 Omar Polo 2 | .\" 3 | .\" Permission to use, copy, modify, and distribute this software for any 4 | .\" purpose with or without fee is hereby granted, provided that the above 5 | .\" copyright notice and this permission notice appear in all copies. 6 | .\" 7 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | .Dd October 20, 2023 15 | .Dt TITAN 1 16 | .Os 17 | .Sh NAME 18 | .Nm titan 19 | .Nd Titan client 20 | .Sh SYNOPSIS 21 | .Nm 22 | .Bk -words 23 | .Op Fl C Ar cert 24 | .Op Fl K Ar key 25 | .Op Fl m Ar mime 26 | .Op Fl t Ar token 27 | .Ar url 28 | .Op Ar file 29 | .Ek 30 | .Sh DESCRIPTION 31 | .Nm 32 | allows one to upload data to a Titan server. 33 | If no 34 | .Ar file 35 | is given on the command line, 36 | .Nm 37 | reads from standard input. 38 | .Pp 39 | The options are as follows: 40 | .Bl -tag -width Ds 41 | .It Fl C Ar cert 42 | Specify the TLS client certificate to use. 43 | .It Fl K Ar cert 44 | Specify the TLS client certificate key to use. 45 | Defaults to 46 | .Fl C 47 | if provided. 48 | .It Fl m Ar mime 49 | Specify the mime of the content being sent. 50 | Unset by default. 51 | .It Fl t Ar token 52 | Specify the token for the transaction. 53 | Unset by default. 54 | .El 55 | .Pp 56 | .Nm 57 | alters the passed 58 | .Ar url 59 | to include the parameter for the file size as well as the MIME and the 60 | token if 61 | .Fl m 62 | or 63 | .Fl t 64 | are given. 65 | .Sh EXIT STATUS 66 | The 67 | .Nm 68 | utility exits with one of the following values: 69 | .Pp 70 | .Bl -tag -width Ds -offset indent -compact 71 | .It 0 72 | The transaction completed successfully and the response code was in the 73 | 2x or 3x range. 74 | .It 1 75 | An error occurred. 76 | .It 2 77 | The response code was not in the 2x or 3x range. 78 | .El 79 | .Sh SEE ALSO 80 | .Xr ftp 1 , 81 | .Xr gg 1 82 | .Sh STANDARDS 83 | .Nm 84 | implements the 85 | .Dq Titan Specification 86 | .Lk gemini://transjovian.org/titan/page/The%20Titan%20Specification 87 | .Sh AUTHORS 88 | .An -nosplit 89 | The 90 | .Nm 91 | utility was written by 92 | .An Omar Polo Aq Mt op@omarpolo.com . 93 | .Sh CAVEATS 94 | .Nm 95 | doesn't perform TOFU 96 | .Pq Trust On First Use 97 | or any X.509 certificate validation beyond the name verification. 98 | -------------------------------------------------------------------------------- /compat/libtls/tls_peer.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: tls_peer.c,v 1.8 2017/04/10 17:11:13 jsing Exp $ */ 2 | /* 3 | * Copyright (c) 2015 Joel Sing 4 | * Copyright (c) 2015 Bob Beck 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "config.h" 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include "tls_internal.h" 27 | 28 | const char * 29 | tls_peer_cert_hash(struct tls *ctx) 30 | { 31 | if (ctx->conninfo == NULL) 32 | return (NULL); 33 | return (ctx->conninfo->hash); 34 | } 35 | const char * 36 | tls_peer_cert_issuer(struct tls *ctx) 37 | { 38 | if (ctx->conninfo == NULL) 39 | return (NULL); 40 | return (ctx->conninfo->issuer); 41 | } 42 | 43 | const char * 44 | tls_peer_cert_subject(struct tls *ctx) 45 | { 46 | if (ctx->conninfo == NULL) 47 | return (NULL); 48 | return (ctx->conninfo->subject); 49 | } 50 | 51 | int 52 | tls_peer_cert_provided(struct tls *ctx) 53 | { 54 | return (ctx->ssl_peer_cert != NULL); 55 | } 56 | 57 | int 58 | tls_peer_cert_contains_name(struct tls *ctx, const char *name) 59 | { 60 | int match; 61 | 62 | if (ctx->ssl_peer_cert == NULL) 63 | return (0); 64 | 65 | if (tls_check_name(ctx, ctx->ssl_peer_cert, name, &match) == -1) 66 | return (0); 67 | 68 | return (match); 69 | } 70 | 71 | time_t 72 | tls_peer_cert_notbefore(struct tls *ctx) 73 | { 74 | if (ctx->ssl_peer_cert == NULL) 75 | return (-1); 76 | if (ctx->conninfo == NULL) 77 | return (-1); 78 | return (ctx->conninfo->notbefore); 79 | } 80 | 81 | time_t 82 | tls_peer_cert_notafter(struct tls *ctx) 83 | { 84 | if (ctx->ssl_peer_cert == NULL) 85 | return (-1); 86 | if (ctx->conninfo == NULL) 87 | return (-1); 88 | return (ctx->conninfo->notafter); 89 | } 90 | 91 | const uint8_t * 92 | tls_peer_cert_chain_pem(struct tls *ctx, size_t *size) 93 | { 94 | if (ctx->ssl_peer_cert == NULL) 95 | return (NULL); 96 | if (ctx->conninfo == NULL) 97 | return (NULL); 98 | *size = ctx->conninfo->peer_cert_len; 99 | return (ctx->conninfo->peer_cert); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /compat/recallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: recallocarray.c,v 1.2 2021/03/18 11:16:58 claudio Exp $ */ 2 | /* 3 | * Copyright (c) 2008, 2017 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "../config.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | /* 27 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 28 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 29 | */ 30 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) 31 | 32 | /* 33 | * Even though specified in POSIX, the PAGESIZE and PAGE_SIZE 34 | * macros have very poor portability. Since we only use this 35 | * to avoid free() overhead for small shrinking, simply pick 36 | * an arbitrary number. 37 | */ 38 | #define getpagesize() (1UL << 12) 39 | 40 | void * 41 | recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) 42 | { 43 | size_t oldsize, newsize; 44 | void *newptr; 45 | 46 | if (ptr == NULL) 47 | return calloc(newnmemb, size); 48 | 49 | if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 50 | newnmemb > 0 && SIZE_MAX / newnmemb < size) { 51 | errno = ENOMEM; 52 | return NULL; 53 | } 54 | newsize = newnmemb * size; 55 | 56 | if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 57 | oldnmemb > 0 && SIZE_MAX / oldnmemb < size) { 58 | errno = EINVAL; 59 | return NULL; 60 | } 61 | oldsize = oldnmemb * size; 62 | 63 | /* 64 | * Don't bother too much if we're shrinking just a bit, 65 | * we do not shrink for series of small steps, oh well. 66 | */ 67 | if (newsize <= oldsize) { 68 | size_t d = oldsize - newsize; 69 | 70 | if (d < oldsize / 2 && d < (size_t)getpagesize()) { 71 | memset((char *)ptr + newsize, 0, d); 72 | return ptr; 73 | } 74 | } 75 | 76 | newptr = malloc(newsize); 77 | if (newptr == NULL) 78 | return NULL; 79 | 80 | if (newsize > oldsize) { 81 | memcpy(newptr, ptr, oldsize); 82 | memset((char *)newptr + oldsize, 0, newsize - oldsize); 83 | } else 84 | memcpy(newptr, ptr, newsize); 85 | 86 | explicit_bzero(ptr, oldsize); 87 | free(ptr); 88 | 89 | return newptr; 90 | } 91 | -------------------------------------------------------------------------------- /compat/getentropy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996, David Mazieres 3 | * Copyright (c) 2008, Damien Miller 4 | * Copyright (c) 2013, Markus Friedl 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "../config.h" 20 | 21 | #ifndef SSH_RANDOM_DEV 22 | # define SSH_RANDOM_DEV "/dev/urandom" 23 | #endif /* SSH_RANDOM_DEV */ 24 | 25 | #include 26 | #ifdef HAVE_SYS_RANDOM_H 27 | # include 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #ifdef WITH_OPENSSL 36 | #include 37 | #include 38 | #endif 39 | 40 | #include "log.h" 41 | 42 | int _ssh_compat_getentropy(void *, size_t); 43 | 44 | static int 45 | seed_from_prngd(unsigned char *buf, size_t bytes) 46 | { 47 | return -1; 48 | } 49 | 50 | int 51 | _ssh_compat_getentropy(void *s, size_t len) 52 | { 53 | #if defined(WITH_OPENSSL) && defined(OPENSSL_PRNG_ONLY) 54 | if (RAND_bytes(s, len) <= 0) 55 | fatal("Couldn't obtain random bytes (error 0x%lx)", 56 | (unsigned long)ERR_get_error()); 57 | #else 58 | int fd, save_errno; 59 | ssize_t r; 60 | size_t o = 0; 61 | 62 | #ifdef WITH_OPENSSL 63 | if (RAND_bytes(s, len) == 1) 64 | return 0; 65 | #endif 66 | #ifdef HAVE_GETENTROPY 67 | if ((r = getentropy(s, len)) == 0) 68 | return 0; 69 | #endif /* HAVE_GETENTROPY */ 70 | #ifdef HAVE_GETRANDOM 71 | if ((r = getrandom(s, len, 0)) > 0 && (size_t)r == len) 72 | return 0; 73 | #endif /* HAVE_GETRANDOM */ 74 | 75 | if ((fd = open(SSH_RANDOM_DEV, O_RDONLY)) == -1) { 76 | save_errno = errno; 77 | /* Try egd/prngd before giving up. */ 78 | if (seed_from_prngd(s, len) == 0) 79 | return 0; 80 | fatal("Couldn't open %s: %s", SSH_RANDOM_DEV, 81 | strerror(save_errno)); 82 | } 83 | while (o < len) { 84 | r = read(fd, (u_char *)s + o, len - o); 85 | if (r < 0) { 86 | if (errno == EAGAIN || errno == EINTR || 87 | errno == EWOULDBLOCK) 88 | continue; 89 | fatal("read %s: %s", SSH_RANDOM_DEV, strerror(errno)); 90 | } 91 | o += r; 92 | } 93 | close(fd); 94 | #endif /* WITH_OPENSSL */ 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /site/gem2html: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 3 | # Copyright (c) 2022 Omar Polo 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | use v5.10; 18 | use strict; 19 | use warnings; 20 | 21 | my $in_pre = 0; 22 | my $in_list = 0; 23 | 24 | while (<>) { 25 | chomp; 26 | if ($in_pre && m/^```/) { 27 | $in_pre = 0; 28 | say ""; 29 | } elsif (!$in_pre && m/^```/) { 30 | if ($in_list) { 31 | $in_list = 0; 32 | say ""; 33 | } 34 | $in_pre = 1; 35 | print "
";
 36 | 	} elsif ($in_pre) {
 37 | 		say san($_);
 38 | 	} elsif ($in_list && m/^$/) {
 39 | 		say "";
 40 | 		$in_list = 0;
 41 | 	} elsif (m/^\*\s+(.*)/) { # NB: at least one space
 42 | 		if (!$in_list) {
 43 | 			$in_list = "item";
 44 | 			say "
    "; 45 | } elsif ($in_list eq "link") { 46 | $in_list = "item"; 47 | say "
"; 48 | say "
    "; 49 | } 50 | output("li", $1); 51 | } elsif (m/^=>\s*([^\s]*)\s*(.*)$/) { 52 | my $href = $1; 53 | my $alt = $2; 54 | 55 | # special case: images 56 | if ($1 =~ /\.(png|jpg|svg)$/) { 57 | if ($in_list) { 58 | say "
"; 59 | $in_list = 0; 60 | } 61 | say "$alt"; 62 | next; 63 | } 64 | 65 | if (!$in_list) { 66 | $in_list = "link"; 67 | say ""; 71 | say "