From d4180f85d53f7381da9fcc7257cf61d0b29497a0 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Thu, 30 Apr 2020 02:06:46 +0200 Subject: merge histories --- .builds/freebsd.yml | 23 + .builds/openbsd.yml | 16 + .gitattributes | 1 + .github/FUNDING.yml | 3 + .github/workflows/alpine.yml | 15 + .github/workflows/arch.yml | 15 + .github/workflows/clang.yml | 35 + .github/workflows/coverity.yml | 15 + .github/workflows/ubuntu-gcc10.yml | 15 + .github/workflows/ubuntu.yml | 15 + .gitignore | 56 + CHANGES.md | 67 + INSTALL | 237 ++ LICENSE | 342 ++ Makefile | 10 - Makefile.am | 3 + README.md | 201 ++ aliases.5 | 102 - aliases.c | 227 -- bootstrap | 151 + bounce.c | 818 ----- ca.c | 761 ----- cert.c | 414 --- ci/COVERITY.MD5SUM | 1 + ci/README.md | 83 + ci/docker/Dockerfile.alpine | 50 + ci/docker/Dockerfile.archlinux | 62 + ci/docker/Dockerfile.ubuntu | 52 + ci/docker/Dockerfile.ubuntu-gcc10 | 54 + ci/scripts/clang_scan.sh | 60 + ci/scripts/coverity_scan.sh | 77 + ci/scripts/generate_certs.sh | 33 + ci/scripts/imports/badge.sh | 72 + ci/scripts/ssl.conf | 23 + compress_backend.c | 70 - compress_gzip.c | 184 - config.c | 343 -- configure.ac | 2066 +++++++++++ contrib/Makefile.am | 1 + contrib/libexec/Makefile.am | 1 + contrib/libexec/encrypt/Makefile.am | 13 + contrib/libexec/encrypt/encrypt.c | 102 + contrib/libexec/lockspool/Makefile.am | 20 + contrib/libexec/lockspool/locking.c | 181 + contrib/libexec/lockspool/lockspool.1 | 77 + contrib/libexec/lockspool/lockspool.c | 124 + contrib/libexec/lockspool/mail.local.h | 42 + contrib/libexec/lockspool/pathnames.h | 38 + contrib/libexec/mail.local/Makefile.am | 22 + contrib/libexec/mail.local/locking.c | 182 + contrib/libexec/mail.local/mail.local.8 | 183 + contrib/libexec/mail.local/mail.local.c | 392 +++ contrib/libexec/mail.local/mail.local.h | 42 + contrib/libexec/mail.local/pathnames.h | 38 + control.c | 802 ----- crypto.c | 398 --- dict.c | 267 -- dict.h | 48 - dns.c | 367 -- enqueue.c | 927 ----- envelope.c | 778 ----- esc.c | 120 - etc/README.md | 6 + etc/aliases | 100 + expand.c | 324 -- foobar/.builds/freebsd.yml | 23 - foobar/.builds/openbsd.yml | 16 - foobar/.gitattributes | 1 - foobar/.github/FUNDING.yml | 3 - foobar/.github/workflows/alpine.yml | 15 - foobar/.github/workflows/arch.yml | 15 - foobar/.github/workflows/clang.yml | 35 - foobar/.github/workflows/coverity.yml | 15 - foobar/.github/workflows/ubuntu-gcc10.yml | 15 - foobar/.github/workflows/ubuntu.yml | 15 - foobar/.gitignore | 56 - foobar/portable/CHANGES.md | 67 - foobar/portable/INSTALL | 237 -- foobar/portable/LICENSE | 342 -- foobar/portable/Makefile.am | 3 - foobar/portable/README.md | 201 -- foobar/portable/bootstrap | 151 - foobar/portable/ci/COVERITY.MD5SUM | 1 - foobar/portable/ci/README.md | 83 - foobar/portable/ci/docker/Dockerfile.alpine | 50 - foobar/portable/ci/docker/Dockerfile.archlinux | 62 - foobar/portable/ci/docker/Dockerfile.ubuntu | 52 - foobar/portable/ci/docker/Dockerfile.ubuntu-gcc10 | 54 - foobar/portable/ci/scripts/clang_scan.sh | 60 - foobar/portable/ci/scripts/coverity_scan.sh | 77 - foobar/portable/ci/scripts/generate_certs.sh | 33 - foobar/portable/ci/scripts/imports/badge.sh | 72 - foobar/portable/ci/scripts/ssl.conf | 23 - foobar/portable/configure.ac | 2066 ----------- foobar/portable/contrib/Makefile.am | 1 - foobar/portable/contrib/libexec/Makefile.am | 1 - .../portable/contrib/libexec/encrypt/Makefile.am | 13 - foobar/portable/contrib/libexec/encrypt/encrypt.c | 102 - .../portable/contrib/libexec/lockspool/Makefile.am | 20 - .../portable/contrib/libexec/lockspool/locking.c | 181 - .../portable/contrib/libexec/lockspool/lockspool.1 | 77 - .../portable/contrib/libexec/lockspool/lockspool.c | 124 - .../contrib/libexec/lockspool/mail.local.h | 42 - .../portable/contrib/libexec/lockspool/pathnames.h | 38 - .../contrib/libexec/mail.local/Makefile.am | 22 - .../portable/contrib/libexec/mail.local/locking.c | 182 - .../contrib/libexec/mail.local/mail.local.8 | 183 - .../contrib/libexec/mail.local/mail.local.c | 392 --- .../contrib/libexec/mail.local/mail.local.h | 42 - .../contrib/libexec/mail.local/pathnames.h | 38 - foobar/portable/etc/README.md | 6 - foobar/portable/etc/aliases | 100 - foobar/portable/mk/Makefile.am | 4 - foobar/portable/mk/mail/Makefile.am | 5 - foobar/portable/mk/mail/mail.lmtp/Makefile.am | 22 - foobar/portable/mk/mail/mail.maildir/Makefile.am | 22 - foobar/portable/mk/mail/mail.mboxfile/Makefile.am | 22 - foobar/portable/mk/mail/mail.mda/Makefile.am | 22 - foobar/portable/mk/mdoc2man.awk | 391 --- foobar/portable/mk/pathnames | 10 - foobar/portable/mk/smtp/Makefile.am | 59 - foobar/portable/mk/smtpctl/Makefile.am | 99 - foobar/portable/mk/smtpd/Makefile.am | 194 -- foobar/portable/openbsd-compat/Makefile.am | 231 -- foobar/portable/openbsd-compat/NOTES | 37 - .../SSL_CTX_use_certificate_chain_mem.c | 174 - foobar/portable/openbsd-compat/arc4random.c | 246 -- foobar/portable/openbsd-compat/base64.c | 306 -- foobar/portable/openbsd-compat/base64.h | 65 - foobar/portable/openbsd-compat/basename.c | 67 - foobar/portable/openbsd-compat/bsd-err.c | 94 - foobar/portable/openbsd-compat/bsd-err.h | 29 - foobar/portable/openbsd-compat/bsd-misc.h | 24 - foobar/portable/openbsd-compat/bsd-vis.h | 95 - foobar/portable/openbsd-compat/bsd-waitpid.c | 50 - foobar/portable/openbsd-compat/bsd-waitpid.h | 51 - foobar/portable/openbsd-compat/chacha_private.h | 224 -- foobar/portable/openbsd-compat/clock_gettime.c | 59 - foobar/portable/openbsd-compat/closefrom.c | 107 - foobar/portable/openbsd-compat/crypt_checkpass.c | 33 - foobar/portable/openbsd-compat/daemon.c | 82 - foobar/portable/openbsd-compat/defines.h | 510 --- foobar/portable/openbsd-compat/dirname.c | 72 - foobar/portable/openbsd-compat/empty.c | 0 foobar/portable/openbsd-compat/entropy.c | 69 - foobar/portable/openbsd-compat/entropy.h | 37 - foobar/portable/openbsd-compat/err_h/err.h | 18 - foobar/portable/openbsd-compat/errc.c | 56 - foobar/portable/openbsd-compat/event_asr_run.c | 88 - foobar/portable/openbsd-compat/explicit_bzero.c | 15 - foobar/portable/openbsd-compat/fgetln.c | 61 - foobar/portable/openbsd-compat/fmt_scaled.c | 274 -- foobar/portable/openbsd-compat/fparseln.c | 179 - foobar/portable/openbsd-compat/freezero.c | 34 - foobar/portable/openbsd-compat/getopt.c | 123 - foobar/portable/openbsd-compat/getpeereid.c | 69 - foobar/portable/openbsd-compat/imsg-buffer.c | 310 -- foobar/portable/openbsd-compat/imsg.c | 330 -- foobar/portable/openbsd-compat/imsg.h | 115 - foobar/portable/openbsd-compat/includes.h | 75 - foobar/portable/openbsd-compat/inet_net_pton.c | 236 -- foobar/portable/openbsd-compat/libasr/asr.c | 867 ----- foobar/portable/openbsd-compat/libasr/asr.h | 95 - foobar/portable/openbsd-compat/libasr/asr_compat.c | 102 - foobar/portable/openbsd-compat/libasr/asr_compat.h | 80 - foobar/portable/openbsd-compat/libasr/asr_debug.c | 362 -- .../portable/openbsd-compat/libasr/asr_private.h | 359 -- foobar/portable/openbsd-compat/libasr/asr_run.3 | 316 -- foobar/portable/openbsd-compat/libasr/asr_utils.c | 574 ---- .../portable/openbsd-compat/libasr/getaddrinfo.c | 55 - .../openbsd-compat/libasr/getaddrinfo_async.c | 756 ---- .../portable/openbsd-compat/libasr/gethostnamadr.c | 200 -- .../openbsd-compat/libasr/gethostnamadr_async.c | 676 ---- .../portable/openbsd-compat/libasr/getnameinfo.c | 205 -- .../openbsd-compat/libasr/getnameinfo_async.c | 300 -- .../portable/openbsd-compat/libasr/getnetnamadr.c | 134 - .../openbsd-compat/libasr/getnetnamadr_async.c | 52 - .../openbsd-compat/libasr/getrrsetbyname.c | 83 - .../openbsd-compat/libasr/getrrsetbyname_async.c | 590 ---- foobar/portable/openbsd-compat/libasr/libasr.la | 41 - foobar/portable/openbsd-compat/libasr/res_debug.c | 2 - foobar/portable/openbsd-compat/libasr/res_init.c | 103 - .../portable/openbsd-compat/libasr/res_mkquery.c | 119 - foobar/portable/openbsd-compat/libasr/res_query.c | 112 - .../openbsd-compat/libasr/res_search_async.c | 327 -- foobar/portable/openbsd-compat/libasr/res_send.c | 61 - .../openbsd-compat/libasr/res_send_async.c | 806 ----- foobar/portable/openbsd-compat/libasr/sethostent.c | 36 - .../openbsd-compat/libasr/thread_private.h | 8 - foobar/portable/openbsd-compat/libressl.c | 131 - foobar/portable/openbsd-compat/nanosleep.c | 63 - foobar/portable/openbsd-compat/openbsd-compat.h | 340 -- foobar/portable/openbsd-compat/paths_h/paths.h | 8 - foobar/portable/openbsd-compat/pidfile.c | 112 - foobar/portable/openbsd-compat/progname.c | 62 - foobar/portable/openbsd-compat/reallocarray.c | 42 - foobar/portable/openbsd-compat/recallocarray.c | 84 - foobar/portable/openbsd-compat/res_hnok.c | 169 - foobar/portable/openbsd-compat/res_randomid.c | 13 - foobar/portable/openbsd-compat/setegid.c | 39 - foobar/portable/openbsd-compat/seteuid.c | 39 - foobar/portable/openbsd-compat/setproctitle.c | 167 - foobar/portable/openbsd-compat/setresgid.c | 41 - foobar/portable/openbsd-compat/setresuid.c | 43 - foobar/portable/openbsd-compat/signal.c | 60 - foobar/portable/openbsd-compat/strerror.c | 44 - foobar/portable/openbsd-compat/strlcat.c | 59 - foobar/portable/openbsd-compat/strlcpy.c | 55 - foobar/portable/openbsd-compat/strmode.c | 146 - foobar/portable/openbsd-compat/strndup.c | 39 - foobar/portable/openbsd-compat/strnlen.c | 32 - foobar/portable/openbsd-compat/strsep.c | 79 - foobar/portable/openbsd-compat/strtonum.c | 72 - foobar/portable/openbsd-compat/sys/queue.h | 653 ---- foobar/portable/openbsd-compat/sys/tree.h | 755 ---- foobar/portable/openbsd-compat/usleep.c | 43 - foobar/portable/openbsd-compat/vis.c | 222 -- foobar/portable/smtpd/Makefile | 10 - foobar/portable/smtpd/aliases.5 | 102 - foobar/portable/smtpd/aliases.c | 234 -- foobar/portable/smtpd/bounce.c | 820 ----- foobar/portable/smtpd/ca.c | 777 ----- foobar/portable/smtpd/cert.c | 416 --- foobar/portable/smtpd/compress_backend.c | 72 - foobar/portable/smtpd/compress_gzip.c | 186 - foobar/portable/smtpd/config.c | 350 -- foobar/portable/smtpd/control.c | 817 ----- foobar/portable/smtpd/crypto.c | 400 --- foobar/portable/smtpd/dict.c | 269 -- foobar/portable/smtpd/dict.h | 48 - foobar/portable/smtpd/dns.c | 379 --- foobar/portable/smtpd/enqueue.c | 932 ----- foobar/portable/smtpd/envelope.c | 786 ----- foobar/portable/smtpd/esc.c | 116 - foobar/portable/smtpd/expand.c | 332 -- foobar/portable/smtpd/filter.c | 868 ----- foobar/portable/smtpd/forward.5 | 83 - foobar/portable/smtpd/forward.c | 104 - foobar/portable/smtpd/iobuf.c | 462 --- foobar/portable/smtpd/iobuf.h | 67 - foobar/portable/smtpd/ioev.c | 1064 ------ foobar/portable/smtpd/ioev.h | 70 - foobar/portable/smtpd/libressl.c | 213 -- foobar/portable/smtpd/limit.c | 124 - foobar/portable/smtpd/lka.c | 914 ----- foobar/portable/smtpd/lka_filter.c | 1746 ---------- foobar/portable/smtpd/lka_session.c | 556 --- foobar/portable/smtpd/log.c | 220 -- foobar/portable/smtpd/log.h | 52 - foobar/portable/smtpd/mail.lmtp.8 | 55 - foobar/portable/smtpd/mail.lmtp.c | 332 -- foobar/portable/smtpd/mail.maildir.8 | 45 - foobar/portable/smtpd/mail.maildir.c | 284 -- foobar/portable/smtpd/mail.mboxfile.8 | 34 - foobar/portable/smtpd/mail.mboxfile.c | 109 - foobar/portable/smtpd/mail.mda.8 | 35 - foobar/portable/smtpd/mail.mda.c | 70 - foobar/portable/smtpd/mail/Makefile | 20 - foobar/portable/smtpd/mailaddr.c | 135 - foobar/portable/smtpd/makemap.8 | 174 - foobar/portable/smtpd/makemap.c | 522 --- foobar/portable/smtpd/mda.c | 919 ----- foobar/portable/smtpd/mda_mbox.c | 94 - foobar/portable/smtpd/mda_unpriv.c | 110 - foobar/portable/smtpd/mda_variables.c | 374 -- foobar/portable/smtpd/mproc.c | 676 ---- foobar/portable/smtpd/mta.c | 2647 -------------- foobar/portable/smtpd/mta_session.c | 2004 ----------- foobar/portable/smtpd/newaliases.8 | 86 - foobar/portable/smtpd/parse.y | 3598 -------------------- foobar/portable/smtpd/parser.c | 341 -- foobar/portable/smtpd/parser.h | 43 - foobar/portable/smtpd/pony.c | 212 -- foobar/portable/smtpd/proxy.c | 387 --- foobar/portable/smtpd/queue.c | 750 ---- foobar/portable/smtpd/queue_backend.c | 806 ----- foobar/portable/smtpd/queue_fs.c | 695 ---- foobar/portable/smtpd/queue_null.c | 120 - foobar/portable/smtpd/queue_proc.c | 337 -- foobar/portable/smtpd/queue_ram.c | 336 -- foobar/portable/smtpd/report_smtp.c | 335 -- foobar/portable/smtpd/resolver.c | 462 --- foobar/portable/smtpd/rfc5322.c | 266 -- foobar/portable/smtpd/rfc5322.h | 41 - foobar/portable/smtpd/ruleset.c | 265 -- foobar/portable/smtpd/runq.c | 183 - foobar/portable/smtpd/scheduler.c | 618 ---- foobar/portable/smtpd/scheduler_backend.c | 82 - foobar/portable/smtpd/scheduler_null.c | 164 - foobar/portable/smtpd/scheduler_proc.c | 446 --- foobar/portable/smtpd/scheduler_ramqueue.c | 1204 ------- foobar/portable/smtpd/sendmail.8 | 86 - foobar/portable/smtpd/smtp.1 | 96 - foobar/portable/smtpd/smtp.c | 387 --- foobar/portable/smtpd/smtp.h | 95 - foobar/portable/smtpd/smtp/Makefile | 24 - foobar/portable/smtpd/smtp_client.c | 923 ----- foobar/portable/smtpd/smtp_session.c | 3223 ------------------ foobar/portable/smtpd/smtpc.c | 465 --- foobar/portable/smtpd/smtpctl.8 | 336 -- foobar/portable/smtpd/smtpctl.c | 1469 -------- foobar/portable/smtpd/smtpctl/Makefile | 56 - foobar/portable/smtpd/smtpd-api.h | 290 -- foobar/portable/smtpd/smtpd-defines.h | 68 - foobar/portable/smtpd/smtpd-filters.7 | 653 ---- foobar/portable/smtpd/smtpd.8 | 167 - foobar/portable/smtpd/smtpd.c | 2326 ------------- foobar/portable/smtpd/smtpd.conf | 19 - foobar/portable/smtpd/smtpd.conf.5 | 1240 ------- foobar/portable/smtpd/smtpd.h | 1784 ---------- foobar/portable/smtpd/smtpd/Makefile | 102 - foobar/portable/smtpd/spfwalk.c | 391 --- foobar/portable/smtpd/srs.c | 379 --- foobar/portable/smtpd/ssl.c | 458 --- foobar/portable/smtpd/ssl.h | 71 - foobar/portable/smtpd/ssl_smtpd.c | 105 - foobar/portable/smtpd/ssl_verify.c | 297 -- foobar/portable/smtpd/stat_backend.c | 124 - foobar/portable/smtpd/stat_ramstat.c | 162 - foobar/portable/smtpd/table.5 | 258 -- foobar/portable/smtpd/table.c | 709 ---- foobar/portable/smtpd/table_db.c | 282 -- foobar/portable/smtpd/table_getpwnam.c | 120 - foobar/portable/smtpd/table_proc.c | 283 -- foobar/portable/smtpd/table_static.c | 398 --- foobar/portable/smtpd/to.c | 880 ----- foobar/portable/smtpd/tree.c | 259 -- foobar/portable/smtpd/tree.h | 48 - foobar/portable/smtpd/unpack_dns.c | 300 -- foobar/portable/smtpd/unpack_dns.h | 96 - foobar/portable/smtpd/util.c | 870 ----- foobar/portable/smtpd/waitq.c | 104 - foobar/portable/smtpscript/LICENSE | 15 - foobar/portable/smtpscript/Makefile | 3 - foobar/portable/smtpscript/Makefile.inc | 3 - foobar/portable/smtpscript/README.md | 40 - foobar/portable/smtpscript/iobuf.c | 466 --- foobar/portable/smtpscript/iobuf.h | 71 - foobar/portable/smtpscript/parse.y | 905 ----- foobar/portable/smtpscript/smtpscript.c | 1009 ------ foobar/portable/smtpscript/smtpscript.h | 79 - foobar/portable/smtpscript/smtpscript/Makefile | 12 - foobar/portable/smtpscript/ssl.c | 167 - forward.5 | 83 - forward.c | 97 - iobuf.c | 460 --- iobuf.h | 67 - ioev.c | 1062 ------ ioev.h | 70 - limit.c | 122 - lka.c | 906 ----- lka_filter.c | 1744 ---------- lka_session.c | 554 --- log.c | 218 -- log.h | 46 - mail.lmtp.8 | 55 - mail.lmtp.c | 330 -- mail.maildir.8 | 45 - mail.maildir.c | 282 -- mail.mboxfile.8 | 34 - mail.mboxfile.c | 100 - mail.mda.8 | 35 - mail.mda.c | 68 - mail/Makefile | 20 - mailaddr.c | 133 - makemap.8 | 174 - makemap.c | 506 --- mda.c | 912 ----- mda_mbox.c | 92 - mda_unpriv.c | 108 - mda_variables.c | 372 -- mk/Makefile.am | 4 + mk/mail/Makefile.am | 5 + mk/mail/mail.lmtp/Makefile.am | 22 + mk/mail/mail.maildir/Makefile.am | 22 + mk/mail/mail.mboxfile/Makefile.am | 22 + mk/mail/mail.mda/Makefile.am | 22 + mk/mdoc2man.awk | 391 +++ mk/pathnames | 10 + mk/smtp/Makefile.am | 59 + mk/smtpctl/Makefile.am | 99 + mk/smtpd/Makefile.am | 194 ++ mproc.c | 676 ---- mta.c | 2644 -------------- mta_session.c | 2002 ----------- newaliases.8 | 86 - openbsd-compat/Makefile.am | 231 ++ openbsd-compat/NOTES | 37 + openbsd-compat/SSL_CTX_use_certificate_chain_mem.c | 174 + openbsd-compat/arc4random.c | 246 ++ openbsd-compat/base64.c | 306 ++ openbsd-compat/base64.h | 65 + openbsd-compat/basename.c | 67 + openbsd-compat/bsd-err.c | 94 + openbsd-compat/bsd-err.h | 29 + openbsd-compat/bsd-misc.h | 24 + openbsd-compat/bsd-vis.h | 95 + openbsd-compat/bsd-waitpid.c | 50 + openbsd-compat/bsd-waitpid.h | 51 + openbsd-compat/chacha_private.h | 224 ++ openbsd-compat/clock_gettime.c | 59 + openbsd-compat/closefrom.c | 107 + openbsd-compat/crypt_checkpass.c | 33 + openbsd-compat/daemon.c | 82 + openbsd-compat/defines.h | 510 +++ openbsd-compat/dirname.c | 72 + openbsd-compat/empty.c | 0 openbsd-compat/entropy.c | 69 + openbsd-compat/entropy.h | 37 + openbsd-compat/err_h/err.h | 18 + openbsd-compat/errc.c | 56 + openbsd-compat/event_asr_run.c | 88 + openbsd-compat/explicit_bzero.c | 15 + openbsd-compat/fgetln.c | 61 + openbsd-compat/fmt_scaled.c | 274 ++ openbsd-compat/fparseln.c | 179 + openbsd-compat/freezero.c | 34 + openbsd-compat/getopt.c | 123 + openbsd-compat/getpeereid.c | 69 + openbsd-compat/imsg-buffer.c | 310 ++ openbsd-compat/imsg.c | 330 ++ openbsd-compat/imsg.h | 115 + openbsd-compat/includes.h | 75 + openbsd-compat/inet_net_pton.c | 236 ++ openbsd-compat/libasr/asr.c | 867 +++++ openbsd-compat/libasr/asr.h | 95 + openbsd-compat/libasr/asr_compat.c | 102 + openbsd-compat/libasr/asr_compat.h | 80 + openbsd-compat/libasr/asr_debug.c | 362 ++ openbsd-compat/libasr/asr_private.h | 359 ++ openbsd-compat/libasr/asr_run.3 | 316 ++ openbsd-compat/libasr/asr_utils.c | 574 ++++ openbsd-compat/libasr/getaddrinfo.c | 55 + openbsd-compat/libasr/getaddrinfo_async.c | 756 ++++ openbsd-compat/libasr/gethostnamadr.c | 200 ++ openbsd-compat/libasr/gethostnamadr_async.c | 676 ++++ openbsd-compat/libasr/getnameinfo.c | 205 ++ openbsd-compat/libasr/getnameinfo_async.c | 300 ++ openbsd-compat/libasr/getnetnamadr.c | 134 + openbsd-compat/libasr/getnetnamadr_async.c | 52 + openbsd-compat/libasr/getrrsetbyname.c | 83 + openbsd-compat/libasr/getrrsetbyname_async.c | 590 ++++ openbsd-compat/libasr/libasr.la | 41 + openbsd-compat/libasr/res_debug.c | 2 + openbsd-compat/libasr/res_init.c | 103 + openbsd-compat/libasr/res_mkquery.c | 119 + openbsd-compat/libasr/res_query.c | 112 + openbsd-compat/libasr/res_search_async.c | 327 ++ openbsd-compat/libasr/res_send.c | 61 + openbsd-compat/libasr/res_send_async.c | 806 +++++ openbsd-compat/libasr/sethostent.c | 36 + openbsd-compat/libasr/thread_private.h | 8 + openbsd-compat/libressl.c | 131 + openbsd-compat/nanosleep.c | 63 + openbsd-compat/openbsd-compat.h | 340 ++ openbsd-compat/paths_h/paths.h | 8 + openbsd-compat/pidfile.c | 112 + openbsd-compat/progname.c | 62 + openbsd-compat/reallocarray.c | 42 + openbsd-compat/recallocarray.c | 84 + openbsd-compat/res_hnok.c | 169 + openbsd-compat/res_randomid.c | 13 + openbsd-compat/setegid.c | 39 + openbsd-compat/seteuid.c | 39 + openbsd-compat/setproctitle.c | 167 + openbsd-compat/setresgid.c | 41 + openbsd-compat/setresuid.c | 43 + openbsd-compat/signal.c | 60 + openbsd-compat/strerror.c | 44 + openbsd-compat/strlcat.c | 59 + openbsd-compat/strlcpy.c | 55 + openbsd-compat/strmode.c | 146 + openbsd-compat/strndup.c | 39 + openbsd-compat/strnlen.c | 32 + openbsd-compat/strsep.c | 79 + openbsd-compat/strtonum.c | 72 + openbsd-compat/sys/queue.h | 653 ++++ openbsd-compat/sys/tree.h | 755 ++++ openbsd-compat/usleep.c | 43 + openbsd-compat/vis.c | 222 ++ parse.y | 3574 ------------------- parser.c | 335 -- parser.h | 43 - pony.c | 208 -- proxy.c | 385 --- queue.c | 744 ---- queue_backend.c | 804 ----- queue_fs.c | 680 ---- queue_null.c | 118 - queue_proc.c | 335 -- queue_ram.c | 334 -- report_smtp.c | 329 -- resolver.c | 457 --- rfc5322.c | 264 -- rfc5322.h | 41 - ruleset.c | 263 -- runq.c | 181 - scheduler.c | 613 ---- scheduler_backend.c | 80 - scheduler_null.c | 162 - scheduler_proc.c | 444 --- scheduler_ramqueue.c | 1202 ------- sendmail.8 | 86 - smtp.1 | 96 - smtp.c | 366 -- smtp.h | 95 - smtp/Makefile | 23 - smtp_client.c | 923 ----- smtp_session.c | 3213 ----------------- smtpc.c | 457 --- smtpctl.8 | 336 -- smtpctl.c | 1435 -------- smtpctl/Makefile | 56 - smtpd-api.h | 290 -- smtpd-defines.h | 52 - smtpd-filters.7 | 653 ---- smtpd.8 | 167 - smtpd.c | 2147 ------------ smtpd.conf.5 | 1240 ------- smtpd.h | 1757 ---------- smtpd/Makefile | 104 +- smtpd/aliases.5 | 102 + smtpd/aliases.c | 234 ++ smtpd/bounce.c | 820 +++++ smtpd/ca.c | 777 +++++ smtpd/cert.c | 416 +++ smtpd/compress_backend.c | 72 + smtpd/compress_gzip.c | 186 + smtpd/config.c | 350 ++ smtpd/control.c | 817 +++++ smtpd/crypto.c | 400 +++ smtpd/dict.c | 269 ++ smtpd/dict.h | 48 + smtpd/dns.c | 379 +++ smtpd/enqueue.c | 932 +++++ smtpd/envelope.c | 786 +++++ smtpd/esc.c | 116 + smtpd/expand.c | 332 ++ smtpd/filter.c | 868 +++++ smtpd/forward.5 | 83 + smtpd/forward.c | 104 + smtpd/iobuf.c | 462 +++ smtpd/iobuf.h | 67 + smtpd/ioev.c | 1064 ++++++ smtpd/ioev.h | 70 + smtpd/libressl.c | 213 ++ smtpd/limit.c | 124 + smtpd/lka.c | 914 +++++ smtpd/lka_filter.c | 1746 ++++++++++ smtpd/lka_session.c | 556 +++ smtpd/log.c | 220 ++ smtpd/log.h | 52 + smtpd/mail.lmtp.8 | 55 + smtpd/mail.lmtp.c | 332 ++ smtpd/mail.maildir.8 | 45 + smtpd/mail.maildir.c | 284 ++ smtpd/mail.mboxfile.8 | 34 + smtpd/mail.mboxfile.c | 109 + smtpd/mail.mda.8 | 35 + smtpd/mail.mda.c | 70 + smtpd/mail/Makefile | 20 + smtpd/mailaddr.c | 135 + smtpd/makemap.8 | 174 + smtpd/makemap.c | 522 +++ smtpd/mda.c | 919 +++++ smtpd/mda_mbox.c | 94 + smtpd/mda_unpriv.c | 110 + smtpd/mda_variables.c | 374 ++ smtpd/mproc.c | 676 ++++ smtpd/mta.c | 2647 ++++++++++++++ smtpd/mta_session.c | 2004 +++++++++++ smtpd/newaliases.8 | 86 + smtpd/parse.y | 3598 ++++++++++++++++++++ smtpd/parser.c | 341 ++ smtpd/parser.h | 43 + smtpd/pony.c | 212 ++ smtpd/proxy.c | 387 +++ smtpd/queue.c | 750 ++++ smtpd/queue_backend.c | 806 +++++ smtpd/queue_fs.c | 695 ++++ smtpd/queue_null.c | 120 + smtpd/queue_proc.c | 337 ++ smtpd/queue_ram.c | 336 ++ smtpd/report_smtp.c | 335 ++ smtpd/resolver.c | 462 +++ smtpd/rfc5322.c | 266 ++ smtpd/rfc5322.h | 41 + smtpd/ruleset.c | 265 ++ smtpd/runq.c | 183 + smtpd/scheduler.c | 618 ++++ smtpd/scheduler_backend.c | 82 + smtpd/scheduler_null.c | 164 + smtpd/scheduler_proc.c | 446 +++ smtpd/scheduler_ramqueue.c | 1204 +++++++ smtpd/sendmail.8 | 86 + smtpd/smtp.1 | 96 + smtpd/smtp.c | 387 +++ smtpd/smtp.h | 95 + smtpd/smtp/Makefile | 24 + smtpd/smtp_client.c | 923 +++++ smtpd/smtp_session.c | 3223 ++++++++++++++++++ smtpd/smtpc.c | 465 +++ smtpd/smtpctl.8 | 336 ++ smtpd/smtpctl.c | 1469 ++++++++ smtpd/smtpctl/Makefile | 56 + smtpd/smtpd-api.h | 290 ++ smtpd/smtpd-defines.h | 68 + smtpd/smtpd-filters.7 | 653 ++++ smtpd/smtpd.8 | 167 + smtpd/smtpd.c | 2326 +++++++++++++ smtpd/smtpd.conf | 19 + smtpd/smtpd.conf.5 | 1240 +++++++ smtpd/smtpd.h | 1784 ++++++++++ smtpd/smtpd/Makefile | 102 + smtpd/spfwalk.c | 391 +++ smtpd/srs.c | 379 +++ smtpd/ssl.c | 458 +++ smtpd/ssl.h | 71 + smtpd/ssl_smtpd.c | 105 + smtpd/ssl_verify.c | 297 ++ smtpd/stat_backend.c | 124 + smtpd/stat_ramstat.c | 162 + smtpd/table.5 | 258 ++ smtpd/table.c | 709 ++++ smtpd/table_db.c | 282 ++ smtpd/table_getpwnam.c | 120 + smtpd/table_proc.c | 283 ++ smtpd/table_static.c | 398 +++ smtpd/to.c | 880 +++++ smtpd/tree.c | 259 ++ smtpd/tree.h | 48 + smtpd/unpack_dns.c | 300 ++ smtpd/unpack_dns.h | 96 + smtpd/util.c | 870 +++++ smtpd/waitq.c | 104 + smtpscript/LICENSE | 15 + smtpscript/Makefile | 3 + smtpscript/Makefile.inc | 3 + smtpscript/README.md | 40 + smtpscript/iobuf.c | 466 +++ smtpscript/iobuf.h | 71 + smtpscript/parse.y | 905 +++++ smtpscript/smtpscript.c | 1009 ++++++ smtpscript/smtpscript.h | 79 + smtpscript/smtpscript/Makefile | 12 + smtpscript/ssl.c | 167 + spfwalk.c | 384 --- srs.c | 377 -- ssl.c | 452 --- ssl.h | 70 - ssl_smtpd.c | 103 - ssl_verify.c | 296 -- stat_backend.c | 122 - stat_ramstat.c | 161 - table.5 | 258 -- table.c | 699 ---- table_db.c | 275 -- table_getpwnam.c | 118 - table_proc.c | 279 -- table_static.c | 396 --- to.c | 827 ----- tree.c | 257 -- tree.h | 48 - unpack_dns.c | 295 -- unpack_dns.h | 96 - util.c | 844 ----- waitq.c | 102 - 667 files changed, 79110 insertions(+), 131720 deletions(-) create mode 100644 .builds/freebsd.yml create mode 100644 .builds/openbsd.yml create mode 100644 .gitattributes create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/alpine.yml create mode 100644 .github/workflows/arch.yml create mode 100644 .github/workflows/clang.yml create mode 100644 .github/workflows/coverity.yml create mode 100644 .github/workflows/ubuntu-gcc10.yml create mode 100644 .github/workflows/ubuntu.yml create mode 100644 .gitignore create mode 100644 CHANGES.md create mode 100644 INSTALL create mode 100644 LICENSE delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 README.md delete mode 100644 aliases.5 delete mode 100644 aliases.c create mode 100755 bootstrap delete mode 100644 bounce.c delete mode 100644 ca.c delete mode 100644 cert.c create mode 100644 ci/COVERITY.MD5SUM create mode 100644 ci/README.md create mode 100644 ci/docker/Dockerfile.alpine create mode 100644 ci/docker/Dockerfile.archlinux create mode 100644 ci/docker/Dockerfile.ubuntu create mode 100644 ci/docker/Dockerfile.ubuntu-gcc10 create mode 100755 ci/scripts/clang_scan.sh create mode 100755 ci/scripts/coverity_scan.sh create mode 100755 ci/scripts/generate_certs.sh create mode 100644 ci/scripts/imports/badge.sh create mode 100644 ci/scripts/ssl.conf delete mode 100644 compress_backend.c delete mode 100644 compress_gzip.c delete mode 100644 config.c create mode 100644 configure.ac create mode 100644 contrib/Makefile.am create mode 100644 contrib/libexec/Makefile.am create mode 100644 contrib/libexec/encrypt/Makefile.am create mode 100644 contrib/libexec/encrypt/encrypt.c create mode 100644 contrib/libexec/lockspool/Makefile.am create mode 100644 contrib/libexec/lockspool/locking.c create mode 100644 contrib/libexec/lockspool/lockspool.1 create mode 100644 contrib/libexec/lockspool/lockspool.c create mode 100644 contrib/libexec/lockspool/mail.local.h create mode 100644 contrib/libexec/lockspool/pathnames.h create mode 100644 contrib/libexec/mail.local/Makefile.am create mode 100644 contrib/libexec/mail.local/locking.c create mode 100644 contrib/libexec/mail.local/mail.local.8 create mode 100644 contrib/libexec/mail.local/mail.local.c create mode 100644 contrib/libexec/mail.local/mail.local.h create mode 100644 contrib/libexec/mail.local/pathnames.h delete mode 100644 control.c delete mode 100644 crypto.c delete mode 100644 dict.c delete mode 100644 dict.h delete mode 100644 dns.c delete mode 100644 enqueue.c delete mode 100644 envelope.c delete mode 100644 esc.c create mode 100644 etc/README.md create mode 100644 etc/aliases delete mode 100644 expand.c delete mode 100644 foobar/.builds/freebsd.yml delete mode 100644 foobar/.builds/openbsd.yml delete mode 100644 foobar/.gitattributes delete mode 100644 foobar/.github/FUNDING.yml delete mode 100644 foobar/.github/workflows/alpine.yml delete mode 100644 foobar/.github/workflows/arch.yml delete mode 100644 foobar/.github/workflows/clang.yml delete mode 100644 foobar/.github/workflows/coverity.yml delete mode 100644 foobar/.github/workflows/ubuntu-gcc10.yml delete mode 100644 foobar/.github/workflows/ubuntu.yml delete mode 100644 foobar/.gitignore delete mode 100644 foobar/portable/CHANGES.md delete mode 100644 foobar/portable/INSTALL delete mode 100644 foobar/portable/LICENSE delete mode 100644 foobar/portable/Makefile.am delete mode 100644 foobar/portable/README.md delete mode 100755 foobar/portable/bootstrap delete mode 100644 foobar/portable/ci/COVERITY.MD5SUM delete mode 100644 foobar/portable/ci/README.md delete mode 100644 foobar/portable/ci/docker/Dockerfile.alpine delete mode 100644 foobar/portable/ci/docker/Dockerfile.archlinux delete mode 100644 foobar/portable/ci/docker/Dockerfile.ubuntu delete mode 100644 foobar/portable/ci/docker/Dockerfile.ubuntu-gcc10 delete mode 100755 foobar/portable/ci/scripts/clang_scan.sh delete mode 100755 foobar/portable/ci/scripts/coverity_scan.sh delete mode 100755 foobar/portable/ci/scripts/generate_certs.sh delete mode 100644 foobar/portable/ci/scripts/imports/badge.sh delete mode 100644 foobar/portable/ci/scripts/ssl.conf delete mode 100644 foobar/portable/configure.ac delete mode 100644 foobar/portable/contrib/Makefile.am delete mode 100644 foobar/portable/contrib/libexec/Makefile.am delete mode 100644 foobar/portable/contrib/libexec/encrypt/Makefile.am delete mode 100644 foobar/portable/contrib/libexec/encrypt/encrypt.c delete mode 100644 foobar/portable/contrib/libexec/lockspool/Makefile.am delete mode 100644 foobar/portable/contrib/libexec/lockspool/locking.c delete mode 100644 foobar/portable/contrib/libexec/lockspool/lockspool.1 delete mode 100644 foobar/portable/contrib/libexec/lockspool/lockspool.c delete mode 100644 foobar/portable/contrib/libexec/lockspool/mail.local.h delete mode 100644 foobar/portable/contrib/libexec/lockspool/pathnames.h delete mode 100644 foobar/portable/contrib/libexec/mail.local/Makefile.am delete mode 100644 foobar/portable/contrib/libexec/mail.local/locking.c delete mode 100644 foobar/portable/contrib/libexec/mail.local/mail.local.8 delete mode 100644 foobar/portable/contrib/libexec/mail.local/mail.local.c delete mode 100644 foobar/portable/contrib/libexec/mail.local/mail.local.h delete mode 100644 foobar/portable/contrib/libexec/mail.local/pathnames.h delete mode 100644 foobar/portable/etc/README.md delete mode 100644 foobar/portable/etc/aliases delete mode 100644 foobar/portable/mk/Makefile.am delete mode 100644 foobar/portable/mk/mail/Makefile.am delete mode 100644 foobar/portable/mk/mail/mail.lmtp/Makefile.am delete mode 100644 foobar/portable/mk/mail/mail.maildir/Makefile.am delete mode 100644 foobar/portable/mk/mail/mail.mboxfile/Makefile.am delete mode 100644 foobar/portable/mk/mail/mail.mda/Makefile.am delete mode 100644 foobar/portable/mk/mdoc2man.awk delete mode 100644 foobar/portable/mk/pathnames delete mode 100644 foobar/portable/mk/smtp/Makefile.am delete mode 100644 foobar/portable/mk/smtpctl/Makefile.am delete mode 100644 foobar/portable/mk/smtpd/Makefile.am delete mode 100644 foobar/portable/openbsd-compat/Makefile.am delete mode 100644 foobar/portable/openbsd-compat/NOTES delete mode 100644 foobar/portable/openbsd-compat/SSL_CTX_use_certificate_chain_mem.c delete mode 100644 foobar/portable/openbsd-compat/arc4random.c delete mode 100644 foobar/portable/openbsd-compat/base64.c delete mode 100644 foobar/portable/openbsd-compat/base64.h delete mode 100644 foobar/portable/openbsd-compat/basename.c delete mode 100644 foobar/portable/openbsd-compat/bsd-err.c delete mode 100644 foobar/portable/openbsd-compat/bsd-err.h delete mode 100644 foobar/portable/openbsd-compat/bsd-misc.h delete mode 100644 foobar/portable/openbsd-compat/bsd-vis.h delete mode 100644 foobar/portable/openbsd-compat/bsd-waitpid.c delete mode 100644 foobar/portable/openbsd-compat/bsd-waitpid.h delete mode 100644 foobar/portable/openbsd-compat/chacha_private.h delete mode 100644 foobar/portable/openbsd-compat/clock_gettime.c delete mode 100644 foobar/portable/openbsd-compat/closefrom.c delete mode 100644 foobar/portable/openbsd-compat/crypt_checkpass.c delete mode 100644 foobar/portable/openbsd-compat/daemon.c delete mode 100644 foobar/portable/openbsd-compat/defines.h delete mode 100644 foobar/portable/openbsd-compat/dirname.c delete mode 100644 foobar/portable/openbsd-compat/empty.c delete mode 100644 foobar/portable/openbsd-compat/entropy.c delete mode 100644 foobar/portable/openbsd-compat/entropy.h delete mode 100644 foobar/portable/openbsd-compat/err_h/err.h delete mode 100644 foobar/portable/openbsd-compat/errc.c delete mode 100644 foobar/portable/openbsd-compat/event_asr_run.c delete mode 100644 foobar/portable/openbsd-compat/explicit_bzero.c delete mode 100644 foobar/portable/openbsd-compat/fgetln.c delete mode 100644 foobar/portable/openbsd-compat/fmt_scaled.c delete mode 100644 foobar/portable/openbsd-compat/fparseln.c delete mode 100644 foobar/portable/openbsd-compat/freezero.c delete mode 100644 foobar/portable/openbsd-compat/getopt.c delete mode 100644 foobar/portable/openbsd-compat/getpeereid.c delete mode 100644 foobar/portable/openbsd-compat/imsg-buffer.c delete mode 100644 foobar/portable/openbsd-compat/imsg.c delete mode 100644 foobar/portable/openbsd-compat/imsg.h delete mode 100644 foobar/portable/openbsd-compat/includes.h delete mode 100644 foobar/portable/openbsd-compat/inet_net_pton.c delete mode 100644 foobar/portable/openbsd-compat/libasr/asr.c delete mode 100644 foobar/portable/openbsd-compat/libasr/asr.h delete mode 100644 foobar/portable/openbsd-compat/libasr/asr_compat.c delete mode 100644 foobar/portable/openbsd-compat/libasr/asr_compat.h delete mode 100644 foobar/portable/openbsd-compat/libasr/asr_debug.c delete mode 100644 foobar/portable/openbsd-compat/libasr/asr_private.h delete mode 100644 foobar/portable/openbsd-compat/libasr/asr_run.3 delete mode 100644 foobar/portable/openbsd-compat/libasr/asr_utils.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getaddrinfo.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getaddrinfo_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/gethostnamadr.c delete mode 100644 foobar/portable/openbsd-compat/libasr/gethostnamadr_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getnameinfo.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getnameinfo_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getnetnamadr.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getnetnamadr_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getrrsetbyname.c delete mode 100644 foobar/portable/openbsd-compat/libasr/getrrsetbyname_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/libasr.la delete mode 100644 foobar/portable/openbsd-compat/libasr/res_debug.c delete mode 100644 foobar/portable/openbsd-compat/libasr/res_init.c delete mode 100644 foobar/portable/openbsd-compat/libasr/res_mkquery.c delete mode 100644 foobar/portable/openbsd-compat/libasr/res_query.c delete mode 100644 foobar/portable/openbsd-compat/libasr/res_search_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/res_send.c delete mode 100644 foobar/portable/openbsd-compat/libasr/res_send_async.c delete mode 100644 foobar/portable/openbsd-compat/libasr/sethostent.c delete mode 100644 foobar/portable/openbsd-compat/libasr/thread_private.h delete mode 100644 foobar/portable/openbsd-compat/libressl.c delete mode 100644 foobar/portable/openbsd-compat/nanosleep.c delete mode 100644 foobar/portable/openbsd-compat/openbsd-compat.h delete mode 100644 foobar/portable/openbsd-compat/paths_h/paths.h delete mode 100644 foobar/portable/openbsd-compat/pidfile.c delete mode 100644 foobar/portable/openbsd-compat/progname.c delete mode 100644 foobar/portable/openbsd-compat/reallocarray.c delete mode 100644 foobar/portable/openbsd-compat/recallocarray.c delete mode 100644 foobar/portable/openbsd-compat/res_hnok.c delete mode 100644 foobar/portable/openbsd-compat/res_randomid.c delete mode 100644 foobar/portable/openbsd-compat/setegid.c delete mode 100644 foobar/portable/openbsd-compat/seteuid.c delete mode 100644 foobar/portable/openbsd-compat/setproctitle.c delete mode 100644 foobar/portable/openbsd-compat/setresgid.c delete mode 100644 foobar/portable/openbsd-compat/setresuid.c delete mode 100644 foobar/portable/openbsd-compat/signal.c delete mode 100644 foobar/portable/openbsd-compat/strerror.c delete mode 100644 foobar/portable/openbsd-compat/strlcat.c delete mode 100644 foobar/portable/openbsd-compat/strlcpy.c delete mode 100644 foobar/portable/openbsd-compat/strmode.c delete mode 100644 foobar/portable/openbsd-compat/strndup.c delete mode 100644 foobar/portable/openbsd-compat/strnlen.c delete mode 100644 foobar/portable/openbsd-compat/strsep.c delete mode 100644 foobar/portable/openbsd-compat/strtonum.c delete mode 100644 foobar/portable/openbsd-compat/sys/queue.h delete mode 100644 foobar/portable/openbsd-compat/sys/tree.h delete mode 100644 foobar/portable/openbsd-compat/usleep.c delete mode 100644 foobar/portable/openbsd-compat/vis.c delete mode 100644 foobar/portable/smtpd/Makefile delete mode 100644 foobar/portable/smtpd/aliases.5 delete mode 100644 foobar/portable/smtpd/aliases.c delete mode 100644 foobar/portable/smtpd/bounce.c delete mode 100644 foobar/portable/smtpd/ca.c delete mode 100644 foobar/portable/smtpd/cert.c delete mode 100644 foobar/portable/smtpd/compress_backend.c delete mode 100644 foobar/portable/smtpd/compress_gzip.c delete mode 100644 foobar/portable/smtpd/config.c delete mode 100644 foobar/portable/smtpd/control.c delete mode 100644 foobar/portable/smtpd/crypto.c delete mode 100644 foobar/portable/smtpd/dict.c delete mode 100644 foobar/portable/smtpd/dict.h delete mode 100644 foobar/portable/smtpd/dns.c delete mode 100644 foobar/portable/smtpd/enqueue.c delete mode 100644 foobar/portable/smtpd/envelope.c delete mode 100644 foobar/portable/smtpd/esc.c delete mode 100644 foobar/portable/smtpd/expand.c delete mode 100644 foobar/portable/smtpd/filter.c delete mode 100644 foobar/portable/smtpd/forward.5 delete mode 100644 foobar/portable/smtpd/forward.c delete mode 100644 foobar/portable/smtpd/iobuf.c delete mode 100644 foobar/portable/smtpd/iobuf.h delete mode 100644 foobar/portable/smtpd/ioev.c delete mode 100644 foobar/portable/smtpd/ioev.h delete mode 100644 foobar/portable/smtpd/libressl.c delete mode 100644 foobar/portable/smtpd/limit.c delete mode 100644 foobar/portable/smtpd/lka.c delete mode 100644 foobar/portable/smtpd/lka_filter.c delete mode 100644 foobar/portable/smtpd/lka_session.c delete mode 100644 foobar/portable/smtpd/log.c delete mode 100644 foobar/portable/smtpd/log.h delete mode 100644 foobar/portable/smtpd/mail.lmtp.8 delete mode 100644 foobar/portable/smtpd/mail.lmtp.c delete mode 100644 foobar/portable/smtpd/mail.maildir.8 delete mode 100644 foobar/portable/smtpd/mail.maildir.c delete mode 100644 foobar/portable/smtpd/mail.mboxfile.8 delete mode 100644 foobar/portable/smtpd/mail.mboxfile.c delete mode 100644 foobar/portable/smtpd/mail.mda.8 delete mode 100644 foobar/portable/smtpd/mail.mda.c delete mode 100644 foobar/portable/smtpd/mail/Makefile delete mode 100644 foobar/portable/smtpd/mailaddr.c delete mode 100644 foobar/portable/smtpd/makemap.8 delete mode 100644 foobar/portable/smtpd/makemap.c delete mode 100644 foobar/portable/smtpd/mda.c delete mode 100644 foobar/portable/smtpd/mda_mbox.c delete mode 100644 foobar/portable/smtpd/mda_unpriv.c delete mode 100644 foobar/portable/smtpd/mda_variables.c delete mode 100644 foobar/portable/smtpd/mproc.c delete mode 100644 foobar/portable/smtpd/mta.c delete mode 100644 foobar/portable/smtpd/mta_session.c delete mode 100644 foobar/portable/smtpd/newaliases.8 delete mode 100644 foobar/portable/smtpd/parse.y delete mode 100644 foobar/portable/smtpd/parser.c delete mode 100644 foobar/portable/smtpd/parser.h delete mode 100644 foobar/portable/smtpd/pony.c delete mode 100644 foobar/portable/smtpd/proxy.c delete mode 100644 foobar/portable/smtpd/queue.c delete mode 100644 foobar/portable/smtpd/queue_backend.c delete mode 100644 foobar/portable/smtpd/queue_fs.c delete mode 100644 foobar/portable/smtpd/queue_null.c delete mode 100644 foobar/portable/smtpd/queue_proc.c delete mode 100644 foobar/portable/smtpd/queue_ram.c delete mode 100644 foobar/portable/smtpd/report_smtp.c delete mode 100644 foobar/portable/smtpd/resolver.c delete mode 100644 foobar/portable/smtpd/rfc5322.c delete mode 100644 foobar/portable/smtpd/rfc5322.h delete mode 100644 foobar/portable/smtpd/ruleset.c delete mode 100644 foobar/portable/smtpd/runq.c delete mode 100644 foobar/portable/smtpd/scheduler.c delete mode 100644 foobar/portable/smtpd/scheduler_backend.c delete mode 100644 foobar/portable/smtpd/scheduler_null.c delete mode 100644 foobar/portable/smtpd/scheduler_proc.c delete mode 100644 foobar/portable/smtpd/scheduler_ramqueue.c delete mode 100644 foobar/portable/smtpd/sendmail.8 delete mode 100644 foobar/portable/smtpd/smtp.1 delete mode 100644 foobar/portable/smtpd/smtp.c delete mode 100644 foobar/portable/smtpd/smtp.h delete mode 100644 foobar/portable/smtpd/smtp/Makefile delete mode 100644 foobar/portable/smtpd/smtp_client.c delete mode 100644 foobar/portable/smtpd/smtp_session.c delete mode 100644 foobar/portable/smtpd/smtpc.c delete mode 100644 foobar/portable/smtpd/smtpctl.8 delete mode 100644 foobar/portable/smtpd/smtpctl.c delete mode 100644 foobar/portable/smtpd/smtpctl/Makefile delete mode 100644 foobar/portable/smtpd/smtpd-api.h delete mode 100644 foobar/portable/smtpd/smtpd-defines.h delete mode 100644 foobar/portable/smtpd/smtpd-filters.7 delete mode 100644 foobar/portable/smtpd/smtpd.8 delete mode 100644 foobar/portable/smtpd/smtpd.c delete mode 100644 foobar/portable/smtpd/smtpd.conf delete mode 100644 foobar/portable/smtpd/smtpd.conf.5 delete mode 100644 foobar/portable/smtpd/smtpd.h delete mode 100644 foobar/portable/smtpd/smtpd/Makefile delete mode 100644 foobar/portable/smtpd/spfwalk.c delete mode 100644 foobar/portable/smtpd/srs.c delete mode 100644 foobar/portable/smtpd/ssl.c delete mode 100644 foobar/portable/smtpd/ssl.h delete mode 100644 foobar/portable/smtpd/ssl_smtpd.c delete mode 100644 foobar/portable/smtpd/ssl_verify.c delete mode 100644 foobar/portable/smtpd/stat_backend.c delete mode 100644 foobar/portable/smtpd/stat_ramstat.c delete mode 100644 foobar/portable/smtpd/table.5 delete mode 100644 foobar/portable/smtpd/table.c delete mode 100644 foobar/portable/smtpd/table_db.c delete mode 100644 foobar/portable/smtpd/table_getpwnam.c delete mode 100644 foobar/portable/smtpd/table_proc.c delete mode 100644 foobar/portable/smtpd/table_static.c delete mode 100644 foobar/portable/smtpd/to.c delete mode 100644 foobar/portable/smtpd/tree.c delete mode 100644 foobar/portable/smtpd/tree.h delete mode 100644 foobar/portable/smtpd/unpack_dns.c delete mode 100644 foobar/portable/smtpd/unpack_dns.h delete mode 100644 foobar/portable/smtpd/util.c delete mode 100644 foobar/portable/smtpd/waitq.c delete mode 100644 foobar/portable/smtpscript/LICENSE delete mode 100644 foobar/portable/smtpscript/Makefile delete mode 100644 foobar/portable/smtpscript/Makefile.inc delete mode 100644 foobar/portable/smtpscript/README.md delete mode 100644 foobar/portable/smtpscript/iobuf.c delete mode 100644 foobar/portable/smtpscript/iobuf.h delete mode 100644 foobar/portable/smtpscript/parse.y delete mode 100644 foobar/portable/smtpscript/smtpscript.c delete mode 100644 foobar/portable/smtpscript/smtpscript.h delete mode 100644 foobar/portable/smtpscript/smtpscript/Makefile delete mode 100644 foobar/portable/smtpscript/ssl.c delete mode 100644 forward.5 delete mode 100644 forward.c delete mode 100644 iobuf.c delete mode 100644 iobuf.h delete mode 100644 ioev.c delete mode 100644 ioev.h delete mode 100644 limit.c delete mode 100644 lka.c delete mode 100644 lka_filter.c delete mode 100644 lka_session.c delete mode 100644 log.c delete mode 100644 log.h delete mode 100644 mail.lmtp.8 delete mode 100644 mail.lmtp.c delete mode 100644 mail.maildir.8 delete mode 100644 mail.maildir.c delete mode 100644 mail.mboxfile.8 delete mode 100644 mail.mboxfile.c delete mode 100644 mail.mda.8 delete mode 100644 mail.mda.c delete mode 100644 mail/Makefile delete mode 100644 mailaddr.c delete mode 100644 makemap.8 delete mode 100644 makemap.c delete mode 100644 mda.c delete mode 100644 mda_mbox.c delete mode 100644 mda_unpriv.c delete mode 100644 mda_variables.c create mode 100644 mk/Makefile.am create mode 100644 mk/mail/Makefile.am create mode 100644 mk/mail/mail.lmtp/Makefile.am create mode 100644 mk/mail/mail.maildir/Makefile.am create mode 100644 mk/mail/mail.mboxfile/Makefile.am create mode 100644 mk/mail/mail.mda/Makefile.am create mode 100644 mk/mdoc2man.awk create mode 100644 mk/pathnames create mode 100644 mk/smtp/Makefile.am create mode 100644 mk/smtpctl/Makefile.am create mode 100644 mk/smtpd/Makefile.am delete mode 100644 mproc.c delete mode 100644 mta.c delete mode 100644 mta_session.c delete mode 100644 newaliases.8 create mode 100644 openbsd-compat/Makefile.am create mode 100644 openbsd-compat/NOTES create mode 100644 openbsd-compat/SSL_CTX_use_certificate_chain_mem.c create mode 100644 openbsd-compat/arc4random.c create mode 100644 openbsd-compat/base64.c create mode 100644 openbsd-compat/base64.h create mode 100644 openbsd-compat/basename.c create mode 100644 openbsd-compat/bsd-err.c create mode 100644 openbsd-compat/bsd-err.h create mode 100644 openbsd-compat/bsd-misc.h create mode 100644 openbsd-compat/bsd-vis.h create mode 100644 openbsd-compat/bsd-waitpid.c create mode 100644 openbsd-compat/bsd-waitpid.h create mode 100644 openbsd-compat/chacha_private.h create mode 100644 openbsd-compat/clock_gettime.c create mode 100644 openbsd-compat/closefrom.c create mode 100644 openbsd-compat/crypt_checkpass.c create mode 100644 openbsd-compat/daemon.c create mode 100644 openbsd-compat/defines.h create mode 100644 openbsd-compat/dirname.c create mode 100644 openbsd-compat/empty.c create mode 100644 openbsd-compat/entropy.c create mode 100644 openbsd-compat/entropy.h create mode 100644 openbsd-compat/err_h/err.h create mode 100644 openbsd-compat/errc.c create mode 100644 openbsd-compat/event_asr_run.c create mode 100644 openbsd-compat/explicit_bzero.c create mode 100644 openbsd-compat/fgetln.c create mode 100644 openbsd-compat/fmt_scaled.c create mode 100644 openbsd-compat/fparseln.c create mode 100644 openbsd-compat/freezero.c create mode 100644 openbsd-compat/getopt.c create mode 100644 openbsd-compat/getpeereid.c create mode 100644 openbsd-compat/imsg-buffer.c create mode 100644 openbsd-compat/imsg.c create mode 100644 openbsd-compat/imsg.h create mode 100644 openbsd-compat/includes.h create mode 100644 openbsd-compat/inet_net_pton.c create mode 100644 openbsd-compat/libasr/asr.c create mode 100644 openbsd-compat/libasr/asr.h create mode 100644 openbsd-compat/libasr/asr_compat.c create mode 100644 openbsd-compat/libasr/asr_compat.h create mode 100644 openbsd-compat/libasr/asr_debug.c create mode 100644 openbsd-compat/libasr/asr_private.h create mode 100644 openbsd-compat/libasr/asr_run.3 create mode 100644 openbsd-compat/libasr/asr_utils.c create mode 100644 openbsd-compat/libasr/getaddrinfo.c create mode 100644 openbsd-compat/libasr/getaddrinfo_async.c create mode 100644 openbsd-compat/libasr/gethostnamadr.c create mode 100644 openbsd-compat/libasr/gethostnamadr_async.c create mode 100644 openbsd-compat/libasr/getnameinfo.c create mode 100644 openbsd-compat/libasr/getnameinfo_async.c create mode 100644 openbsd-compat/libasr/getnetnamadr.c create mode 100644 openbsd-compat/libasr/getnetnamadr_async.c create mode 100644 openbsd-compat/libasr/getrrsetbyname.c create mode 100644 openbsd-compat/libasr/getrrsetbyname_async.c create mode 100644 openbsd-compat/libasr/libasr.la create mode 100644 openbsd-compat/libasr/res_debug.c create mode 100644 openbsd-compat/libasr/res_init.c create mode 100644 openbsd-compat/libasr/res_mkquery.c create mode 100644 openbsd-compat/libasr/res_query.c create mode 100644 openbsd-compat/libasr/res_search_async.c create mode 100644 openbsd-compat/libasr/res_send.c create mode 100644 openbsd-compat/libasr/res_send_async.c create mode 100644 openbsd-compat/libasr/sethostent.c create mode 100644 openbsd-compat/libasr/thread_private.h create mode 100644 openbsd-compat/libressl.c create mode 100644 openbsd-compat/nanosleep.c create mode 100644 openbsd-compat/openbsd-compat.h create mode 100644 openbsd-compat/paths_h/paths.h create mode 100644 openbsd-compat/pidfile.c create mode 100644 openbsd-compat/progname.c create mode 100644 openbsd-compat/reallocarray.c create mode 100644 openbsd-compat/recallocarray.c create mode 100644 openbsd-compat/res_hnok.c create mode 100644 openbsd-compat/res_randomid.c create mode 100644 openbsd-compat/setegid.c create mode 100644 openbsd-compat/seteuid.c create mode 100644 openbsd-compat/setproctitle.c create mode 100644 openbsd-compat/setresgid.c create mode 100644 openbsd-compat/setresuid.c create mode 100644 openbsd-compat/signal.c create mode 100644 openbsd-compat/strerror.c create mode 100644 openbsd-compat/strlcat.c create mode 100644 openbsd-compat/strlcpy.c create mode 100644 openbsd-compat/strmode.c create mode 100644 openbsd-compat/strndup.c create mode 100644 openbsd-compat/strnlen.c create mode 100644 openbsd-compat/strsep.c create mode 100644 openbsd-compat/strtonum.c create mode 100644 openbsd-compat/sys/queue.h create mode 100644 openbsd-compat/sys/tree.h create mode 100644 openbsd-compat/usleep.c create mode 100644 openbsd-compat/vis.c delete mode 100644 parse.y delete mode 100644 parser.c delete mode 100644 parser.h delete mode 100644 pony.c delete mode 100644 proxy.c delete mode 100644 queue.c delete mode 100644 queue_backend.c delete mode 100644 queue_fs.c delete mode 100644 queue_null.c delete mode 100644 queue_proc.c delete mode 100644 queue_ram.c delete mode 100644 report_smtp.c delete mode 100644 resolver.c delete mode 100644 rfc5322.c delete mode 100644 rfc5322.h delete mode 100644 ruleset.c delete mode 100644 runq.c delete mode 100644 scheduler.c delete mode 100644 scheduler_backend.c delete mode 100644 scheduler_null.c delete mode 100644 scheduler_proc.c delete mode 100644 scheduler_ramqueue.c delete mode 100644 sendmail.8 delete mode 100644 smtp.1 delete mode 100644 smtp.c delete mode 100644 smtp.h delete mode 100644 smtp/Makefile delete mode 100644 smtp_client.c delete mode 100644 smtp_session.c delete mode 100644 smtpc.c delete mode 100644 smtpctl.8 delete mode 100644 smtpctl.c delete mode 100644 smtpctl/Makefile delete mode 100644 smtpd-api.h delete mode 100644 smtpd-defines.h delete mode 100644 smtpd-filters.7 delete mode 100644 smtpd.8 delete mode 100644 smtpd.c delete mode 100644 smtpd.conf.5 delete mode 100644 smtpd.h create mode 100644 smtpd/aliases.5 create mode 100644 smtpd/aliases.c create mode 100644 smtpd/bounce.c create mode 100644 smtpd/ca.c create mode 100644 smtpd/cert.c create mode 100644 smtpd/compress_backend.c create mode 100644 smtpd/compress_gzip.c create mode 100644 smtpd/config.c create mode 100644 smtpd/control.c create mode 100644 smtpd/crypto.c create mode 100644 smtpd/dict.c create mode 100644 smtpd/dict.h create mode 100644 smtpd/dns.c create mode 100644 smtpd/enqueue.c create mode 100644 smtpd/envelope.c create mode 100644 smtpd/esc.c create mode 100644 smtpd/expand.c create mode 100644 smtpd/filter.c create mode 100644 smtpd/forward.5 create mode 100644 smtpd/forward.c create mode 100644 smtpd/iobuf.c create mode 100644 smtpd/iobuf.h create mode 100644 smtpd/ioev.c create mode 100644 smtpd/ioev.h create mode 100644 smtpd/libressl.c create mode 100644 smtpd/limit.c create mode 100644 smtpd/lka.c create mode 100644 smtpd/lka_filter.c create mode 100644 smtpd/lka_session.c create mode 100644 smtpd/log.c create mode 100644 smtpd/log.h create mode 100644 smtpd/mail.lmtp.8 create mode 100644 smtpd/mail.lmtp.c create mode 100644 smtpd/mail.maildir.8 create mode 100644 smtpd/mail.maildir.c create mode 100644 smtpd/mail.mboxfile.8 create mode 100644 smtpd/mail.mboxfile.c create mode 100644 smtpd/mail.mda.8 create mode 100644 smtpd/mail.mda.c create mode 100644 smtpd/mail/Makefile create mode 100644 smtpd/mailaddr.c create mode 100644 smtpd/makemap.8 create mode 100644 smtpd/makemap.c create mode 100644 smtpd/mda.c create mode 100644 smtpd/mda_mbox.c create mode 100644 smtpd/mda_unpriv.c create mode 100644 smtpd/mda_variables.c create mode 100644 smtpd/mproc.c create mode 100644 smtpd/mta.c create mode 100644 smtpd/mta_session.c create mode 100644 smtpd/newaliases.8 create mode 100644 smtpd/parse.y create mode 100644 smtpd/parser.c create mode 100644 smtpd/parser.h create mode 100644 smtpd/pony.c create mode 100644 smtpd/proxy.c create mode 100644 smtpd/queue.c create mode 100644 smtpd/queue_backend.c create mode 100644 smtpd/queue_fs.c create mode 100644 smtpd/queue_null.c create mode 100644 smtpd/queue_proc.c create mode 100644 smtpd/queue_ram.c create mode 100644 smtpd/report_smtp.c create mode 100644 smtpd/resolver.c create mode 100644 smtpd/rfc5322.c create mode 100644 smtpd/rfc5322.h create mode 100644 smtpd/ruleset.c create mode 100644 smtpd/runq.c create mode 100644 smtpd/scheduler.c create mode 100644 smtpd/scheduler_backend.c create mode 100644 smtpd/scheduler_null.c create mode 100644 smtpd/scheduler_proc.c create mode 100644 smtpd/scheduler_ramqueue.c create mode 100644 smtpd/sendmail.8 create mode 100644 smtpd/smtp.1 create mode 100644 smtpd/smtp.c create mode 100644 smtpd/smtp.h create mode 100644 smtpd/smtp/Makefile create mode 100644 smtpd/smtp_client.c create mode 100644 smtpd/smtp_session.c create mode 100644 smtpd/smtpc.c create mode 100644 smtpd/smtpctl.8 create mode 100644 smtpd/smtpctl.c create mode 100644 smtpd/smtpctl/Makefile create mode 100644 smtpd/smtpd-api.h create mode 100644 smtpd/smtpd-defines.h create mode 100644 smtpd/smtpd-filters.7 create mode 100644 smtpd/smtpd.8 create mode 100644 smtpd/smtpd.c create mode 100644 smtpd/smtpd.conf create mode 100644 smtpd/smtpd.conf.5 create mode 100644 smtpd/smtpd.h create mode 100644 smtpd/smtpd/Makefile create mode 100644 smtpd/spfwalk.c create mode 100644 smtpd/srs.c create mode 100644 smtpd/ssl.c create mode 100644 smtpd/ssl.h create mode 100644 smtpd/ssl_smtpd.c create mode 100644 smtpd/ssl_verify.c create mode 100644 smtpd/stat_backend.c create mode 100644 smtpd/stat_ramstat.c create mode 100644 smtpd/table.5 create mode 100644 smtpd/table.c create mode 100644 smtpd/table_db.c create mode 100644 smtpd/table_getpwnam.c create mode 100644 smtpd/table_proc.c create mode 100644 smtpd/table_static.c create mode 100644 smtpd/to.c create mode 100644 smtpd/tree.c create mode 100644 smtpd/tree.h create mode 100644 smtpd/unpack_dns.c create mode 100644 smtpd/unpack_dns.h create mode 100644 smtpd/util.c create mode 100644 smtpd/waitq.c create mode 100644 smtpscript/LICENSE create mode 100644 smtpscript/Makefile create mode 100644 smtpscript/Makefile.inc create mode 100644 smtpscript/README.md create mode 100644 smtpscript/iobuf.c create mode 100644 smtpscript/iobuf.h create mode 100644 smtpscript/parse.y create mode 100644 smtpscript/smtpscript.c create mode 100644 smtpscript/smtpscript.h create mode 100644 smtpscript/smtpscript/Makefile create mode 100644 smtpscript/ssl.c delete mode 100644 spfwalk.c delete mode 100644 srs.c delete mode 100644 ssl.c delete mode 100644 ssl.h delete mode 100644 ssl_smtpd.c delete mode 100644 ssl_verify.c delete mode 100644 stat_backend.c delete mode 100644 stat_ramstat.c delete mode 100644 table.5 delete mode 100644 table.c delete mode 100644 table_db.c delete mode 100644 table_getpwnam.c delete mode 100644 table_proc.c delete mode 100644 table_static.c delete mode 100644 to.c delete mode 100644 tree.c delete mode 100644 tree.h delete mode 100644 unpack_dns.c delete mode 100644 unpack_dns.h delete mode 100644 util.c delete mode 100644 waitq.c diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml new file mode 100644 index 00000000..51993106 --- /dev/null +++ b/.builds/freebsd.yml @@ -0,0 +1,23 @@ +image: freebsd/latest +packages: +- autoconf +- automake +- bison +- libevent +- libtool +- libressl +- libasr +- py37-ansible +- db6 +- python3 +- python37 +- python +sources: +- https://github.com/OpenSMTPD/OpenSMTPD +- https://github.com/OpenSMTPD/ci +tasks: +- ansible: | + ls -lah + BUILD_DIR=$(pwd)/OpenSMTPD + cd ci/ansible + ansible-playbook test.yml --inventory inventory/freebsd --skip-tags checkout --extra-vars "build_dir=$BUILD_DIR" diff --git a/.builds/openbsd.yml b/.builds/openbsd.yml new file mode 100644 index 00000000..a0557a99 --- /dev/null +++ b/.builds/openbsd.yml @@ -0,0 +1,16 @@ +image: openbsd/6.6 +packages: +- autoconf-2.69p2 +- automake-1.14.1p1 +- libtool +sources: +- https://github.com/OpenSMTPD/OpenSMTPD +tasks: +- configure: | + cd OpenSMTPD + export AUTOCONF_VERSION=2.69 + ./bootstrap + ./configure +- build: | + cd OpenSMTPD + make diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..eaca2e77 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*/CVS export-ignore diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..36cb5950 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +github: [poolpOrg] +patreon: gilles + diff --git a/.github/workflows/alpine.yml b/.github/workflows/alpine.yml new file mode 100644 index 00000000..6f2d29f6 --- /dev/null +++ b/.github/workflows/alpine.yml @@ -0,0 +1,15 @@ +name: Alpine Linux (amd64 musl openssl) +on: + push: + branches: + - portable + pull_request: + branches: + - portable +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Alpine Linux (amd64 musl openssl) + run: docker build . --file ci/docker/Dockerfile.alpine --tag opensmtpd:alpine diff --git a/.github/workflows/arch.yml b/.github/workflows/arch.yml new file mode 100644 index 00000000..a3528152 --- /dev/null +++ b/.github/workflows/arch.yml @@ -0,0 +1,15 @@ +name: Archlinux (amd64 glibc libressl) +on: + push: + branches: + - portable + pull_request: + branches: + - portable +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Archlinux (amd64 glibc libressl) + run: docker build . --file ci/docker/Dockerfile.archlinux --tag opensmtpd:archlinux diff --git a/.github/workflows/clang.yml b/.github/workflows/clang.yml new file mode 100644 index 00000000..15ccd31d --- /dev/null +++ b/.github/workflows/clang.yml @@ -0,0 +1,35 @@ +name: Clang Scan + +on: + schedule: + - cron: '0 23 * * *' # Daily at 23:00 UTC +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: install dependencies + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 9 + sudo apt install \ + clang-tools-9 \ + libasr-dev \ + libevent-dev \ + libssl-dev \ + bison + - uses: actions/checkout@v1 + - name: run scan-build + run: | + export PATH=$PATH:/usr/lib/llvm-9/bin/ + CLANG_SCAN_BADGE_REQUIRED=1 ci/scripts/clang_scan.sh + - name: publish results + run: | + aws s3 rm --recursive s3://opensmtpd/reports/clang/ + cd clang-report + cd "$( find . -type d | sort | tail -n1 )" + aws s3 sync . s3://opensmtpd/reports/clang + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 00000000..d25bb4f7 --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,15 @@ +name: Coverity Scan +on: + schedule: + - cron: '0 23 * * *' # Daily at 23:00 UTC +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: dependencies + run: sudo apt install libasr-dev libevent-dev libssl-dev bison + - name: scan + run: sh ci/scripts/coverity_scan.sh + env: + token: ${{ secrets.COVERITY_SCAN_TOKEN }} diff --git a/.github/workflows/ubuntu-gcc10.yml b/.github/workflows/ubuntu-gcc10.yml new file mode 100644 index 00000000..9f70d7f0 --- /dev/null +++ b/.github/workflows/ubuntu-gcc10.yml @@ -0,0 +1,15 @@ +name: Ubuntu (amd64 glibc openssl gcc10) +on: + push: + branches: + - portable + pull_request: + branches: + - portable +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Ubuntu (amd64 glibc openssl gcc10) + run: docker build . --file ci/docker/Dockerfile.ubuntu-gcc10 --tag opensmtpd:ubuntu-gcc10 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 00000000..c068c6d5 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,15 @@ +name: Ubuntu (amd64 glibc openssl) +on: + push: + branches: + - portable + pull_request: + branches: + - portable +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Ubuntu (amd64 glibc openssl) + run: docker build . --file ci/docker/Dockerfile.ubuntu --tag opensmtpd:ubuntu diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f9f88aa5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +*.d +*.o +*.a +*.in +*.out +*.log +.#* +.deps +m4 +aclocal.m4 +autom4te.cache +compile +config.guess +config.h +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +missing +parse.c +stamp-h1 +ylwrap +tags +obj + +#Other VCS files +CVS/ +smtpd/CVS +smtpd/smtpctl/CVS +smtpd/smtpd/CVS +smtpd/mail/CVS +smtpd/mail/CVS +smtpd/mail/*/CVS +smtpd/smtpctl/CVS/* + +#Editor temporary files +*~ +.idea + +# Coverity +cov-int/ +cov-analysis-linux64/ +cov-analysis-linux64.tgz +opensmtpd.tgz + +# Clang scan-build +clang-report/ + + +# TLS certs +open.smtpd.cert +open.smtpd.csr +open.smtpd.key diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 00000000..db25a4db --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,67 @@ +# Release 6.6.3p1 (2020-02-10) + +Following the 6.6.2p1 release, various improvements were done in OpenBSD -current to mitigate the risk of similar bugs. + +This release back-ports them to the portable version of OpenSMTPD. + +# Release 6.6.2p1 (2020-01-28) + +This is CRITICAL security bugfix for +[CVE-2020-7247](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7247) + +Read more details in +[this blog post](https://poolp.org/posts/2020-01-30/opensmtpd-advisory-dissected/) + +# Release 6.6.1p1 (2019-11-06) + +## Changes in this release (since 6.6.0p1) + +This is a bugfix release. No new features were added. + +- Fixed crash on recipient expansion [#968](https://github.com/OpenSMTPD/OpenSMTPD/issues/968) +- Fixed broken build with LibreSSL [#944](https://github.com/OpenSMTPD/OpenSMTPD/issues/944) +- Fixed crash in `arc4random` caused by differences in OpenSSL vs LibreSSL compatibility layer plumbing [#958](https://github.com/OpenSMTPD/OpenSMTPD/issues/958) +- Fixed issue where `from any` rules never matched by IPv6 sources [#969](https://github.com/OpenSMTPD/OpenSMTPD/issues/969) +- Fixed crash that happened during mail relay on musl distros [#929](https://github.com/OpenSMTPD/OpenSMTPD/issues/929) +- Added reference aliases file in `etc/aliases` +- Fixed multiple compilation warnings +[#965](https://github.com/OpenSMTPD/OpenSMTPD/issues/965) +[#966](https://github.com/OpenSMTPD/OpenSMTPD/issues/966) +[#967](https://github.com/OpenSMTPD/OpenSMTPD/issues/967) +[#978](https://github.com/OpenSMTPD/OpenSMTPD/issues/978) +[#977](https://github.com/OpenSMTPD/OpenSMTPD/issues/977) +[#975](https://github.com/OpenSMTPD/OpenSMTPD/issues/975) + + + +# Release 6.6.0p1 (2019-10-26) + +## Dependencies note: + +This release builds with LibreSSL > 3.0.2 or OpenSSL > 1.1.0. + +It's preferable to depend on LibreSSL as OpenSMTPD is written and tested +with that dependency. In addition, the features parity is not respected, +some features will not be available with OpenSSL, like ECDSA server-side +certificates support in this release. OpenSSL library is considered as a +best effort target TLS library and provided as a commodity, LibreSSL has +become our target TLS library. + + +## Changes in this release (since 6.4.0): + +- various improvements to documentation and code +- reverse dns session matching criteria added to smtpd.conf(5) +- regex table lookup support added to smtpd.conf(5) +- introduced support for ECDSA certificates with an ECDSA privsep engine +- introduced builtin filters for basic filtering of incoming sessions +- introduced option to deliver junk to a Junk folder in mail.maildir(8) +- fixed the smtp(1) client so it uses correct default port for SMTPS +- fixed an smtpd(8) crash on excessively large input +- ensured mail rejected by an LMTP server stay queued + + +## Experimental features: + +- introduced a filters API to allow writing standalone filters for smtpd +- introduced proxy-v2 support allowing smtpd to operate behind a proxy diff --git a/INSTALL b/INSTALL new file mode 100644 index 00000000..d3c5b40a --- /dev/null +++ b/INSTALL @@ -0,0 +1,237 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006, 2007 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 6. Often, you can also type `make uninstall' to remove the installed + files again. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..f1cea087 --- /dev/null +++ b/LICENSE @@ -0,0 +1,342 @@ +This file is part of the OpenSMTPD software. + +The licences which components of this software fall under are as +follows. First, we will summarize and say that all components +are under a BSD licence, or a licence more free than that. + +OpenSMTPD contains no GPL code. + +Portable OpenSMTPD is divided in 4 parts: +- Original OpenSMTPD +- mail.local +- openbsd-compat +- smtpctl encrypt sub command + + + +OpenSMTPD +========= + + +1) Almost all code is licensed under an ISC-style license, to the following + copyright holders: + + Gilles Chehade + Eric Faurot + Jacek Masiulaniec + Pierre-Yves Ritschard + Henning Brauer + Esben Norby + Markus Friedl + Daniel Hartmeier + Theo de Raadt + Claudio Jeker + Reyk Floeter + Janne Johansson + Alexander Schrijver + Marc Balmer + Ashish Shukla + Ryan Kavanagh + Charles Longeau + + +2) ssl_privsep.c + + /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + + /* + * SSL operations needed when running in a privilege separated environment. + * Adapted from openssl's ssl_rsa.c by Pierre-Yves Ritschard . + */ + + + +mail.local +========== + + +1) mail.local is covered by a 3-clause BSD license, to the following + copyright holders: + + The Regents of the University of California. + David Mazieres + Theo de Raadt + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + + + +openbsd-compat +============== + + +Most of the OpenBSD compatibility layer is based on the work by Damien Miller for +Portable OpenSSH. + +1) Almost all code is licensed under an ISC-style license, to the following + copyright holders: + + Internet Software Consortium. + David Mazieres + Damien Miller + Markus Friedl + Todd C. Miller + Henning Brauer + Pierre-Yves Ritschard + Reyk Floeter + Theo de Raadt + Ted Unangst + Charles Longeau + + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +2) base64.{c,h} in addition to beeing covered by an ISC-style licence, is also + covered by this one: + + * Portions Copyright (c) 1995 by International Business Machines, Inc. + * + * International Business Machines, Inc. (hereinafter called IBM) grants + * permission under its copyrights to use, copy, modify, and distribute this + * Software with or without fee, provided that the above copyright notice and + * all paragraphs of this notice appear in all copies, and that the name of IBM + * not be used in connection with the marketing of any product incorporating + * the Software or modifications thereof, without specific, written prior + * permission. + * + * To the extent it has a right to do so, IBM grants an immunity from suit + * under its patents, if any, for the use, sale or manufacture of products to + * the extent that such products are used for performing Domain Name System + * dynamic updates in TCP/IP networks by means of the Software. No immunity is + * granted for any product per se or for any other function of any product. + * + * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, + * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN + * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +3) Portable OpenSMTPD includes code under the 2-clause BSD license, from the + following copyright holders: + + Ben Lindstrom + Damien Miller + Marc Espie + Tim Rice + The NetBSD Foundation, Inc. + Jason R. Thorpe? + Niels Provos + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +4) Some code is under a 3-clause BSD license, from the + following copyright holders: + + The Regents of the University of California. + Ian F. Darwin + Damien Miller + Eric P. Allman + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + + +5) Some code is under a 4-clause BSD license, from the + following copyright holder: + + Christos Zoulas + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +6) includes.h, log.h, setresguid.c, xmalloc.c, xmalloc.c + + * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland + * All rights reserved + * + * As far as I am concerned, the code I have written for this software + * can be used freely for any purpose. Any derived versions of this + * software must be clearly marked as such, and if the derived work is + * incompatible with the protocol description in the RFC file, it must be + * called by a name other than "ssh" or "Secure Shell". + + +7) chacha_private.h + +D. J. Bernstein +Public domain. + + +8) bootstrap (only there in the git repository) + + # Copyright (c) 2002-2011 Sam Hocevar + # + # This program is free software. It comes without any warranty, to + # the extent permitted by applicable law. You can redistribute it + # and/or modify it under the terms of the Do What The Fuck You Want + # To Public License, Version 2, as published by Sam Hocevar. See + # http://sam.zoy.org/wtfpl/COPYING for more details. + + + +smtpctl encrypt sub command +=========================== + + +smtpctl encrypt sub command is licensed under an ISC-style license, to the +following copyright holders: + + Sunil Nimmagadda + Gilles Chehade diff --git a/Makefile b/Makefile deleted file mode 100644 index a3dbc9d1..00000000 --- a/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $OpenBSD: Makefile,v 1.18 2018/05/24 11:38:24 gilles Exp $ - -.include - -SUBDIR = smtpd -SUBDIR+= smtpctl -SUBDIR+= smtp -SUBDIR+= mail - -.include diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..7d95a5b8 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = openbsd-compat mk contrib + +ACLOCAL_AMFLAGS = -I m4 diff --git a/README.md b/README.md new file mode 100644 index 00000000..c00663cd --- /dev/null +++ b/README.md @@ -0,0 +1,201 @@ +# OpenSMTPD + +[![Version](https://img.shields.io/badge/Version-6.6.3p1-brihtgreen.svg)](https://github.com/OpenSMTPD/OpenSMTPD/releases/tag/6.6.3p1) +[![Coverity Scan analysis](https://scan.coverity.com/projects/278/badge.svg)](https://scan.coverity.com/projects/opensmtpd-opensmtpd) +[![Packaging status](https://repology.org/badge/tiny-repos/opensmtpd.svg)](https://repology.org/project/opensmtpd/versions) +[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://www.isc.org/licenses/) +[![Clang Analysis](https://opensmtpd.email/reports/clang/badge.svg)](https://opensmtpd.email/reports/clang/index.html) + + +OpenSMTPD is a FREE implementation of the server-side SMTP protocol as +defined by [RFC 5321](https://tools.ietf.org/html/rfc5321), with some +additional standard extensions. + +It allows ordinary machines to exchange e-mails with other systems +speaking the SMTP protocol. + +OpenSMTPD runs on top of the OpenBSD operating system but also has a +portable version that can build and run on several systems, including: + +* Linux +* FreeBSD +* NetBSD +* DragonFly + +For more information: http://www.opensmtpd.org/portable.html + +People interested about OpenSMTPD are encouraged to subscribe to our +mailing list: http://www.opensmtpd.org/list.html + +and to join the IRC channel: #OpenSMTPD @ irc.freenode.net + +Also note that we have a wiki at +https://github.com/OpenSMTPD/OpenSMTPD/wiki that you are encouraged to +contribute to. + +Cheers! + + +# How to build, configure and use Portable OpenSMTPD + +## Dependencies + +Portable OpenSMTPD relies on: + * autoconf (http://www.gnu.org/software/autoconf/) + * automake (http://www.gnu.org/software/automake/) + * bison (http://www.gnu.org/software/bison/) + or byacc (http://invisible-island.net/byacc/byacc.html) + * libevent (http://libevent.org/) + * libtool (http://www.gnu.org/software/libtool/) + * libressl (https://www.libressl.org/) + or OpenSSL (https://www.openssl.org/) + + +By default OpenSMTPD expects latest versions of all dependencies unless noted otherwise. + +Note that some distributions have different packages for a same library, you should always use the `-dev` or `-devel` package (for example, `libevent-dev` or `libevent-devel`) if you're going to build OpenSMTPD yourself. + + +## Get the source + + git clone -b portable git://github.com/OpenSMTPD/OpenSMTPD.git opensmtpd + + +## Build + + cd opensmtpd* + ./bootstrap # Only if you build from git sources + ./configure + make + sudo make install + +### Special notes for FreeBSD/DragonFlyBSD/Mac OS X: + +Please launch configure with special directive about libevent and +libasr directory: + +### FreeBSD / DragonFlyBSD: + + ./configure --with-libasr=/usr/local + +### Mac OS X: + + ./configure --with-libevent=/opt/local --with-libasr=/opt/local + + +## Install + + sudo make install + + +## Setup historical interface + +OpenSMTPD provides a single utility `smtpctl` to control the daemon and +the local submission subsystem. + +To accomodate systems that require historical interfaces such as `sendmail`, +`newaliases` or `makemap`, the `smtpctl` utility can operate in compatibility +mode if called with the historical name. + +On mailwrapper-enabled systems, this is achieved by editing `/etc/mailer.conf` +and adding the following lines: + + sendmail /usr/sbin/smtpctl + send-mail /usr/sbin/smtpctl + mailq /usr/sbin/smtpctl + makemap /usr/sbin/smtpctl + newaliases /usr/sbin/smtpctl + + +Whereas on systems that don't provide mailwrapper, it can be achieved by +setting the appropriate symbolic links: + + ln -s /usr/sbin/smtpctl sendmail + ln -s /usr/sbin/smtpctl send-mail + ln -s /usr/sbin/smtpctl mailq + ln -s /usr/sbin/smtpctl makemap + ln -s /usr/sbin/smtpctl newaliases + + +The OpenSMTPD project leaves it up to the package maintainers to setup the +links in their packages as it is very hard for us to accomodate all systems +with the prefered method in a clean way. + + +## Configure /etc/smtpd.conf + +Please have a look at the complete format description of smtpd.conf +configuration file (https://man.openbsd.org/smtpd.conf) + + +## Add OpenSMTPD users + +To operate, OpenSMTPD requires at least one user, by default `_smtpd`; and +preferably two users, by default `_smtpd` and `_smtpq`. + +Using two users instead of one will increase security by a large factor +so... if you want to voluntarily reduce security or you have absolute +more faith in our code than we do, by all means use one. + + +The instructions below assume the default users however, the configure +script allows overriding these using the options: +`--with-user-smtpd`, `--with-user-queue`, and `--with-group-queue`. + + +### NetBSD, Linux (Debian, Arch Linux, ...) + + mkdir /var/empty + useradd -c "SMTP Daemon" -d /var/empty -s /sbin/nologin _smtpd + useradd -c "SMTPD Queue" -d /var/empty -s /sbin/nologin _smtpq + +### DragonFlyBSD, FreeBSD + + pw useradd _smtpd -c "SMTP Daemon" -d /var/empty -s /sbin/nologin + pw useradd _smtpq -c "SMTPD Queue" -d /var/empty -s /sbin/nologin + +### Mac OS X + +First we need a group with an unused GID below `500`, list the current +ones used: + + /usr/bin/dscl . -list /Groups PrimaryGroupID | sort -n -k2,2 + +Add a group - here we have picked `444`: + + /usr/bin/sudo /usr/bin/dscl . -create /Groups/_smtpd + PrimaryGroupID 444 + +Then the user. Again we need an unused UID below `500`, list the current +ones used: + + /usr/bin/dscl . -list /Users UniqueID | sort -n -k2,2 + +Add a user - here we have picked `444`: + + /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd UniqueID 444 + /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd AuthenticationAuthority + /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd PasswordPolicyOptions + /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd dsAttrTypeNative:KerberosKeys + /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd dsAttrTypeNative:ShadowHashData + /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd RealName "SMTP Daemon" + /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd Password "*" + /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd PrimaryGroupID 444 + /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd NFSHomeDirectory /var/empty + /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd UserShell /usr/bin/false + +repeat for the `_smtpq` user. + + +## Launch smtpd + +First, kill any running sendmail/exim/qmail/postfix or other. + +Then: + + smtpd + +or in debug and verbose mode + + smtpd -dv + diff --git a/aliases.5 b/aliases.5 deleted file mode 100644 index 7c250c81..00000000 --- a/aliases.5 +++ /dev/null @@ -1,102 +0,0 @@ -.\" $OpenBSD: aliases.5,v 1.16 2020/04/23 21:28:10 jmc Exp $ -.\" -.\" Copyright (c) 2012 Gilles Chehade -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: April 23 2020 $ -.Dt ALIASES 5 -.Os -.Sh NAME -.Nm aliases -.Nd aliases file for smtpd -.Sh DESCRIPTION -This manual page describes the format of the -.Nm -file, as used by -.Xr smtpd 8 . -An alias in its simplest form is used to assign an arbitrary name -to an email address, or a group of email addresses. -This provides a convenient way to send mail. -For example an alias could refer to all users of a group: -email to that alias would be sent to all members of the group. -Much more complex aliases can be defined however: -an alias can refer to other aliases, -be used to send mail to a file instead of another person, -or to execute various commands. -.Pp -Within the file, -.Ql # -is a comment delimiter; anything placed after it is discarded. -The file consists of key/value mappings of the form: -.Bd -filled -offset indent -key: value1, value2, value3, ... -.Ed -.Pp -.Em key -is always folded to lowercase before alias lookups to ensure that -there can be no ambiguity. -The key is expanded to the corresponding values, -which consist of one or more of the following: -.Bl -tag -width Ds -.It Em user -A user on the host machine. -The user must have a valid entry in the -.Xr passwd 5 -database file. -.It Ar /path/to/file -Append messages to -.Ar file , -specified by its absolute pathname. -.It | Ns Ar command -Pipe the message to -.Ar command -on its standard input. -The command is run under the privileges of the daemon's unprivileged account. -.It : Ns Ar include : Ns Ar /path/to/file -Include any definitions in -.Ar file -as alias entries. -The format of the file is identical to this one. -.It Ar user-part@domain-part -An email address in RFC 5322 format. -If an address extension is appended to the user-part, -it is first compared for an exact match. -It is then stripped so that an address such as user+ext@example.com -will only use the part that precedes -.Sq + -as a -.Em key . -.It Ar error : Ns Ar code message -A status code and message to return. -The code must be 3 digits, -starting 4XX (TempFail) or 5XX (PermFail). -The message must be present and can be freely chosen. -.El -.Sh FILES -.Bl -tag -width "/etc/mail/aliasesXXX" -compact -.It Pa /etc/mail/aliases -Default -.Nm -file. -.El -.Sh SEE ALSO -.Xr smtpd.conf 5 , -.Xr makemap 8 , -.Xr newaliases 8 , -.Xr smtpd 8 -.Sh HISTORY -The -.Nm -file format appeared in -.Bx 4.0 . diff --git a/aliases.c b/aliases.c deleted file mode 100644 index 1c602e9f..00000000 --- a/aliases.c +++ /dev/null @@ -1,227 +0,0 @@ -/* $OpenBSD: aliases.c,v 1.78 2020/04/28 21:46:43 eric Exp $ */ - -/* - * Copyright (c) 2008 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" - -static int aliases_expand_include(struct expand *, const char *); - -int -aliases_get(struct expand *expand, const char *username) -{ - struct expandnode *xn; - char buf[SMTPD_MAXLOCALPARTSIZE]; - size_t nbaliases; - int ret; - union lookup lk; - struct dispatcher *dsp; - struct table *mapping = NULL; - char *pbuf; - - dsp = dict_xget(env->sc_dispatchers, expand->rule->dispatcher); - mapping = table_find(env, dsp->u.local.table_alias); - - xlowercase(buf, username, sizeof(buf)); - - /* first, check if entry has a user-part tag */ - pbuf = strchr(buf, *env->sc_subaddressing_delim); - if (pbuf) { - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret < 0) - return (-1); - if (ret) - goto expand; - *pbuf = '\0'; - } - - /* no user-part tag, try looking up user */ - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret <= 0) - return ret; - -expand: - /* foreach node in table_alias expandtree, we merge */ - nbaliases = 0; - RB_FOREACH(xn, expandtree, &lk.expand->tree) { - if (xn->type == EXPAND_INCLUDE) - nbaliases += aliases_expand_include(expand, - xn->u.buffer); - else { - expand_insert(expand, xn); - nbaliases++; - } - } - - expand_free(lk.expand); - - log_debug("debug: aliases_get: returned %zd aliases", nbaliases); - return nbaliases; -} - -int -aliases_virtual_get(struct expand *expand, const struct mailaddr *maddr) -{ - struct expandnode *xn; - union lookup lk; - char buf[LINE_MAX]; - char user[LINE_MAX]; - char tag[LINE_MAX]; - char domain[LINE_MAX]; - char *pbuf; - int nbaliases; - int ret; - struct dispatcher *dsp; - struct table *mapping = NULL; - - dsp = dict_xget(env->sc_dispatchers, expand->rule->dispatcher); - mapping = table_find(env, dsp->u.local.table_virtual); - - if (!bsnprintf(user, sizeof(user), "%s", maddr->user)) - return 0; - if (!bsnprintf(domain, sizeof(domain), "%s", maddr->domain)) - return 0; - xlowercase(user, user, sizeof(user)); - xlowercase(domain, domain, sizeof(domain)); - - memset(tag, '\0', sizeof tag); - pbuf = strchr(user, *env->sc_subaddressing_delim); - if (pbuf) { - if (!bsnprintf(tag, sizeof(tag), "%s", pbuf + 1)) - return 0; - xlowercase(tag, tag, sizeof(tag)); - *pbuf = '\0'; - } - - /* first, check if entry has a user-part tag */ - if (tag[0]) { - if (!bsnprintf(buf, sizeof(buf), "%s%c%s@%s", - user, *env->sc_subaddressing_delim, tag, domain)) - return 0; - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret < 0) - return (-1); - if (ret) - goto expand; - } - - /* then, check if entry exists without user-part tag */ - if (!bsnprintf(buf, sizeof(buf), "%s@%s", user, domain)) - return 0; - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret < 0) - return (-1); - if (ret) - goto expand; - - if (tag[0]) { - /* Failed ? We lookup for username + user-part tag */ - if (!bsnprintf(buf, sizeof(buf), "%s%c%s", - user, *env->sc_subaddressing_delim, tag)) - return 0; - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret < 0) - return (-1); - if (ret) - goto expand; - } - - /* Failed ? We lookup for username only */ - if (!bsnprintf(buf, sizeof(buf), "%s", user)) - return 0; - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret < 0) - return (-1); - if (ret) - goto expand; - - /* Do not try catch-all entries if there is no domain */ - if (domain[0] == '\0') - return 0; - - if (!bsnprintf(buf, sizeof(buf), "@%s", domain)) - return 0; - /* Failed ? We lookup for catch all for virtual domain */ - ret = table_lookup(mapping, K_ALIAS, buf, &lk); - if (ret < 0) - return (-1); - if (ret) - goto expand; - - /* Failed ? We lookup for a *global* catch all */ - ret = table_lookup(mapping, K_ALIAS, "@", &lk); - if (ret <= 0) - return (ret); - -expand: - /* foreach node in table_virtual expand, we merge */ - nbaliases = 0; - RB_FOREACH(xn, expandtree, &lk.expand->tree) { - if (xn->type == EXPAND_INCLUDE) - nbaliases += aliases_expand_include(expand, - xn->u.buffer); - else { - expand_insert(expand, xn); - nbaliases++; - } - } - - expand_free(lk.expand); - - log_debug("debug: aliases_virtual_get: '%s' resolved to %d nodes", - buf, nbaliases); - - return nbaliases; -} - -static int -aliases_expand_include(struct expand *expand, const char *filename) -{ - FILE *fp; - char *line; - size_t len, lineno = 0; - char delim[3] = { '\\', '#', '\0' }; - - fp = fopen(filename, "r"); - if (fp == NULL) { - log_warn("warn: failed to open include file \"%s\".", filename); - return 0; - } - - while ((line = fparseln(fp, &len, &lineno, delim, 0)) != NULL) { - expand_line(expand, line, 0); - free(line); - } - - fclose(fp); - return 1; -} diff --git a/bootstrap b/bootstrap new file mode 100755 index 00000000..24e29440 --- /dev/null +++ b/bootstrap @@ -0,0 +1,151 @@ +#! /bin/sh + +# bootstrap: generic bootstrap/autogen.sh script for autotools projects +# +# Copyright (c) 2002-2011 Sam Hocevar +# +# This program is free software. It comes without any warranty, to +# the extent permitted by applicable law. You can redistribute it +# and/or modify it under the terms of the Do What The Fuck You Want +# To Public License, Version 2, as published by Sam Hocevar. See +# http://sam.zoy.org/wtfpl/COPYING for more details. +# +# The latest version of this script can be found at the following place: +# http://caca.zoy.org/wiki/build + +# Die if an error occurs +set -e + +# Guess whether we are using configure.ac or configure.in +if test -f configure.ac; then + conffile="configure.ac" +elif test -f configure.in; then + conffile="configure.in" +else + echo "$0: could not find configure.ac or configure.in" + exit 1 +fi + +# Check for needed features +auxdir="`sed -ne 's/^[ \t]*A._CONFIG_AUX_DIR *([[ ]*\([^] )]*\).*/\1/p' $conffile`" +pkgconfig="`grep '^[ \t]*PKG_PROG_PKG_CONFIG' $conffile >/dev/null 2>&1 && echo yes || echo no`" +libtool="`grep '^[ \t]*A._PROG_LIBTOOL' $conffile >/dev/null 2>&1 && echo yes || echo no`" +header="`grep '^[ \t]*A._CONFIG_HEADER' $conffile >/dev/null 2>&1 && echo yes || echo no`" +makefile="`[ -f Makefile.am ] && echo yes || echo no`" +aclocalflags="`sed -ne 's/^[ \t]*ACLOCAL_AMFLAGS[ \t]*=//p' Makefile.am 2>/dev/null || :`" + +# Check for automake +amvers="no" +for v in 16.1 16 15 14 13; do + if automake-1.${v} --version >/dev/null 2>&1; then + amvers="-1.${v}" + break + elif automake1.${v} --version >/dev/null 2>&1; then + amvers="1.${v}" + break + fi +done + +if test "${amvers}" = "no" && automake --version > /dev/null 2>&1; then + amvers="`automake --version | sed -e '1s/[^0-9]*//' -e q`" + if `echo "$amvers\n1.14" | sort -V | head -n 1 | grep -q "$amvers"`; then + amvers="no" + else + amvers="" + fi +fi + +if test "$amvers" = "no"; then + echo "$0: you need automake version 1.14 or later" + exit 1 +fi + +# Check for autoconf +acvers="no" +for v in "" "269" "-2.69"; do + if autoconf${v} --version >/dev/null 2>&1; then + acvers="${v}" + break + fi +done + +if test "$acvers" = "no"; then + echo "$0: you need autoconf" + exit 1 +fi + +# Check for libtool +if test "$libtool" = "yes"; then + libtoolize="no" + if glibtoolize --version >/dev/null 2>&1; then + libtoolize="glibtoolize" + else + for v in "16" "15" "" "14"; do + if libtoolize${v} --version >/dev/null 2>&1; then + libtoolize="libtoolize${v}" + break + fi + done + fi + + if test "$libtoolize" = "no"; then + echo "$0: you need libtool" + exit 1 + fi +fi + +# Check for pkg-config +if test "$pkgconfig" = "yes"; then + if ! pkg-config --version >/dev/null 2>&1; then + echo "$0: you need pkg-config" + exit 1 + fi +fi + +# Remove old cruft +for x in aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh; do rm -f $x autotools/$x; if test -n "$auxdir"; then rm -f "$auxdir/$x"; fi; done +rm -Rf autom4te.cache +if test -n "$auxdir"; then + if test ! -d "$auxdir"; then + mkdir "$auxdir" + fi + aclocalflags="${aclocalflags} -I $auxdir -I ." +fi + +# Honour M4PATH because sometimes M4 doesn't +save_IFS=$IFS +IFS=: +tmp="$M4PATH" +for x in $tmp; do + if test -n "$x"; then + aclocalflags="${aclocalflags} -I $x" + fi +done +IFS=$save_IFS + +# Explain what we are doing from now +set -x + +# Bootstrap package +if test "$libtool" = "yes"; then + ${libtoolize} --copy --force + if test -n "$auxdir" -a ! "$auxdir" = "." -a -f "ltmain.sh"; then + echo "$0: working around a minor libtool issue" + mv ltmain.sh "$auxdir/" + fi +fi + +aclocal${amvers} ${aclocalflags} +autoconf${acvers} +if test "$header" = "yes"; then + autoheader${acvers} +fi +if test "$makefile" = "yes"; then + #add --include-deps if you want to bootstrap with any other compiler than gcc + #automake${amvers} --add-missing --copy --include-deps + automake${amvers} --foreign --add-missing --copy +fi + +# Remove cruft that we no longer want +rm -Rf autom4te.cache + diff --git a/bounce.c b/bounce.c deleted file mode 100644 index e6fc5578..00000000 --- a/bounce.c +++ /dev/null @@ -1,818 +0,0 @@ -/* $OpenBSD: bounce.c,v 1.82 2020/04/24 11:34:07 eric Exp $ */ - -/* - * Copyright (c) 2009 Gilles Chehade - * Copyright (c) 2009 Jacek Masiulaniec - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" - -#define BOUNCE_MAXRUN 2 -#define BOUNCE_HIWAT 65535 - -enum { - BOUNCE_EHLO, - BOUNCE_MAIL, - BOUNCE_RCPT, - BOUNCE_DATA, - BOUNCE_DATA_NOTICE, - BOUNCE_DATA_MESSAGE, - BOUNCE_DATA_END, - BOUNCE_QUIT, - BOUNCE_CLOSE, -}; - -struct bounce_envelope { - TAILQ_ENTRY(bounce_envelope) entry; - uint64_t id; - struct mailaddr dest; - char *report; - uint8_t esc_class; - uint8_t esc_code; -}; - -struct bounce_message { - SPLAY_ENTRY(bounce_message) sp_entry; - TAILQ_ENTRY(bounce_message) entry; - uint32_t msgid; - struct delivery_bounce bounce; - char *smtpname; - char *to; - time_t timeout; - TAILQ_HEAD(, bounce_envelope) envelopes; -}; - -struct bounce_session { - char *smtpname; - struct bounce_message *msg; - FILE *msgfp; - int state; - struct io *io; - uint64_t boundary; -}; - -SPLAY_HEAD(bounce_message_tree, bounce_message); -static int bounce_message_cmp(const struct bounce_message *, - const struct bounce_message *); -SPLAY_PROTOTYPE(bounce_message_tree, bounce_message, sp_entry, - bounce_message_cmp); - -static void bounce_drain(void); -static void bounce_send(struct bounce_session *, const char *, ...); -static int bounce_next_message(struct bounce_session *); -static int bounce_next(struct bounce_session *); -static void bounce_delivery(struct bounce_message *, int, const char *); -static void bounce_status(struct bounce_session *, const char *, ...); -static void bounce_io(struct io *, int, void *); -static void bounce_timeout(int, short, void *); -static void bounce_free(struct bounce_session *); -static const char *action_str(const struct delivery_bounce *); - -static struct tree wait_fd; -static struct bounce_message_tree messages; -static TAILQ_HEAD(, bounce_message) pending; - -static int nmessage = 0; -static int running = 0; -static struct event ev_timer; - -static void -bounce_init(void) -{ - static int init = 0; - - if (init == 0) { - TAILQ_INIT(&pending); - SPLAY_INIT(&messages); - tree_init(&wait_fd); - evtimer_set(&ev_timer, bounce_timeout, NULL); - init = 1; - } -} - -void -bounce_add(uint64_t evpid) -{ - char buf[LINE_MAX], *line; - struct envelope evp; - struct bounce_message key, *msg; - struct bounce_envelope *be; - - bounce_init(); - - if (queue_envelope_load(evpid, &evp) == 0) { - m_create(p_scheduler, IMSG_QUEUE_DELIVERY_PERMFAIL, 0, 0, -1); - m_add_evpid(p_scheduler, evpid); - m_close(p_scheduler); - return; - } - - if (evp.type != D_BOUNCE) - errx(1, "bounce: evp:%016" PRIx64 " is not of type D_BOUNCE!", - evp.id); - - key.msgid = evpid_to_msgid(evpid); - key.bounce = evp.agent.bounce; - key.smtpname = evp.smtpname; - - switch (evp.esc_class) { - case ESC_STATUS_OK: - key.bounce.type = B_DELIVERED; - break; - case ESC_STATUS_TEMPFAIL: - key.bounce.type = B_DELAYED; - break; - default: - key.bounce.type = B_FAILED; - } - - key.bounce.dsn_ret = evp.dsn_ret; - key.bounce.ttl = evp.ttl; - msg = SPLAY_FIND(bounce_message_tree, &messages, &key); - if (msg == NULL) { - msg = xcalloc(1, sizeof(*msg)); - msg->msgid = key.msgid; - msg->bounce = key.bounce; - - TAILQ_INIT(&msg->envelopes); - - msg->smtpname = xstrdup(evp.smtpname); - (void)snprintf(buf, sizeof(buf), "%s@%s", evp.sender.user, - evp.sender.domain); - msg->to = xstrdup(buf); - nmessage += 1; - SPLAY_INSERT(bounce_message_tree, &messages, msg); - log_debug("debug: bounce: new message %08" PRIx32, - msg->msgid); - stat_increment("bounce.message", 1); - } else - TAILQ_REMOVE(&pending, msg, entry); - - line = evp.errorline; - if (strlen(line) > 4 && (*line == '1' || *line == '6')) - line += 4; - (void)snprintf(buf, sizeof(buf), "%s@%s: %s", evp.dest.user, - evp.dest.domain, line); - - be = xmalloc(sizeof *be); - be->id = evpid; - be->report = xstrdup(buf); - (void)strlcpy(be->dest.user, evp.dest.user, sizeof(be->dest.user)); - (void)strlcpy(be->dest.domain, evp.dest.domain, - sizeof(be->dest.domain)); - be->esc_class = evp.esc_class; - be->esc_code = evp.esc_code; - TAILQ_INSERT_TAIL(&msg->envelopes, be, entry); - log_debug("debug: bounce: adding report %16"PRIx64": %s", be->id, be->report); - - msg->timeout = time(NULL) + 1; - TAILQ_INSERT_TAIL(&pending, msg, entry); - - stat_increment("bounce.envelope", 1); - bounce_drain(); -} - -void -bounce_fd(int fd) -{ - struct bounce_session *s; - struct bounce_message *msg; - - log_debug("debug: bounce: got enqueue socket %d", fd); - - if (fd == -1 || TAILQ_EMPTY(&pending)) { - log_debug("debug: bounce: cancelling"); - if (fd != -1) - close(fd); - running -= 1; - bounce_drain(); - return; - } - - msg = TAILQ_FIRST(&pending); - - s = xcalloc(1, sizeof(*s)); - s->smtpname = xstrdup(msg->smtpname); - s->state = BOUNCE_EHLO; - s->io = io_new(); - io_set_callback(s->io, bounce_io, s); - io_set_fd(s->io, fd); - io_set_timeout(s->io, 30000); - io_set_read(s->io); - s->boundary = generate_uid(); - - log_debug("debug: bounce: new session %p", s); - stat_increment("bounce.session", 1); -} - -static void -bounce_timeout(int fd, short ev, void *arg) -{ - log_debug("debug: bounce: timeout"); - - bounce_drain(); -} - -static void -bounce_drain() -{ - struct bounce_message *msg; - struct timeval tv; - time_t t; - - log_debug("debug: bounce: drain: nmessage=%d running=%d", - nmessage, running); - - while (1) { - if (running >= BOUNCE_MAXRUN) { - log_debug("debug: bounce: max session reached"); - return; - } - - if (nmessage == 0) { - log_debug("debug: bounce: no more messages"); - return; - } - - if (running >= nmessage) { - log_debug("debug: bounce: enough sessions running"); - return; - } - - if ((msg = TAILQ_FIRST(&pending)) == NULL) { - log_debug("debug: bounce: no more pending messages"); - return; - } - - t = time(NULL); - if (msg->timeout > t) { - log_debug("debug: bounce: next message not ready yet"); - if (!evtimer_pending(&ev_timer, NULL)) { - log_debug("debug: bounce: setting timer"); - tv.tv_sec = msg->timeout - t; - tv.tv_usec = 0; - evtimer_add(&ev_timer, &tv); - } - return; - } - - log_debug("debug: bounce: requesting new enqueue socket..."); - m_compose(p_pony, IMSG_QUEUE_SMTP_SESSION, 0, 0, -1, NULL, 0); - - running += 1; - } -} - -static void -bounce_send(struct bounce_session *s, const char *fmt, ...) -{ - va_list ap; - char *p; - int len; - - va_start(ap, fmt); - if ((len = vasprintf(&p, fmt, ap)) == -1) - fatal("bounce: vasprintf"); - va_end(ap); - - log_trace(TRACE_BOUNCE, "bounce: %p: >>> %s", s, p); - - io_xprintf(s->io, "%s\r\n", p); - - free(p); -} - -static const char * -bounce_duration(long long int d) -{ - static char buf[32]; - - if (d < 60) { - (void)snprintf(buf, sizeof buf, "%lld second%s", d, - (d == 1) ? "" : "s"); - } else if (d < 3600) { - d = d / 60; - (void)snprintf(buf, sizeof buf, "%lld minute%s", d, - (d == 1) ? "" : "s"); - } - else if (d < 3600 * 24) { - d = d / 3600; - (void)snprintf(buf, sizeof buf, "%lld hour%s", d, - (d == 1) ? "" : "s"); - } - else { - d = d / (3600 * 24); - (void)snprintf(buf, sizeof buf, "%lld day%s", d, - (d == 1) ? "" : "s"); - } - return (buf); -} - -#define NOTICE_INTRO \ - " Hi!\r\n\r\n" \ - " This is the MAILER-DAEMON, please DO NOT REPLY to this email.\r\n" - -const char *notice_error = - " An error has occurred while attempting to deliver a message for\r\n" - " the following list of recipients:\r\n\r\n"; - -const char *notice_warning = - " A message is delayed for more than %s for the following\r\n" - " list of recipients:\r\n\r\n"; - -const char *notice_warning2 = - " Please note that this is only a temporary failure report.\r\n" - " The message is kept in the queue for up to %s.\r\n" - " You DO NOT NEED to re-send the message to these recipients.\r\n\r\n"; - -const char *notice_success = - " Your message was successfully delivered to these recipients.\r\n\r\n"; - -const char *notice_relay = - " Your message was relayed to these recipients.\r\n\r\n"; - -static int -bounce_next_message(struct bounce_session *s) -{ - struct bounce_message *msg; - char buf[LINE_MAX]; - int fd; - time_t now; - - again: - - now = time(NULL); - - TAILQ_FOREACH(msg, &pending, entry) { - if (msg->timeout > now) - continue; - if (strcmp(msg->smtpname, s->smtpname)) - continue; - break; - } - if (msg == NULL) - return (0); - - TAILQ_REMOVE(&pending, msg, entry); - SPLAY_REMOVE(bounce_message_tree, &messages, msg); - - if ((fd = queue_message_fd_r(msg->msgid)) == -1) { - bounce_delivery(msg, IMSG_QUEUE_DELIVERY_TEMPFAIL, - "Could not open message fd"); - goto again; - } - - if ((s->msgfp = fdopen(fd, "r")) == NULL) { - (void)snprintf(buf, sizeof(buf), "fdopen: %s", strerror(errno)); - log_warn("warn: bounce: fdopen"); - close(fd); - bounce_delivery(msg, IMSG_QUEUE_DELIVERY_TEMPFAIL, buf); - goto again; - } - - s->msg = msg; - return (1); -} - -static int -bounce_next(struct bounce_session *s) -{ - struct bounce_envelope *evp; - char *line = NULL; - size_t n, sz = 0; - ssize_t len; - - switch (s->state) { - case BOUNCE_EHLO: - bounce_send(s, "EHLO %s", s->smtpname); - s->state = BOUNCE_MAIL; - break; - - case BOUNCE_MAIL: - case BOUNCE_DATA_END: - log_debug("debug: bounce: %p: getting next message...", s); - if (bounce_next_message(s) == 0) { - log_debug("debug: bounce: %p: no more messages", s); - bounce_send(s, "QUIT"); - s->state = BOUNCE_CLOSE; - break; - } - log_debug("debug: bounce: %p: found message %08"PRIx32, - s, s->msg->msgid); - bounce_send(s, "MAIL FROM: <>"); - s->state = BOUNCE_RCPT; - break; - - case BOUNCE_RCPT: - bounce_send(s, "RCPT TO: <%s>", s->msg->to); - s->state = BOUNCE_DATA; - break; - - case BOUNCE_DATA: - bounce_send(s, "DATA"); - s->state = BOUNCE_DATA_NOTICE; - break; - - case BOUNCE_DATA_NOTICE: - /* Construct an appropriate notice. */ - - io_xprintf(s->io, - "Subject: Delivery status notification: %s\r\n" - "From: Mailer Daemon \r\n" - "To: %s\r\n" - "Date: %s\r\n" - "MIME-Version: 1.0\r\n" - "Content-Type: multipart/mixed;" - "boundary=\"%16" PRIu64 "/%s\"\r\n" - "\r\n" - "This is a MIME-encapsulated message.\r\n" - "\r\n", - action_str(&s->msg->bounce), - s->smtpname, - s->msg->to, - time_to_text(time(NULL)), - s->boundary, - s->smtpname); - - io_xprintf(s->io, - "--%16" PRIu64 "/%s\r\n" - "Content-Description: Notification\r\n" - "Content-Type: text/plain; charset=us-ascii\r\n" - "\r\n" - NOTICE_INTRO - "\r\n", - s->boundary, s->smtpname); - - switch (s->msg->bounce.type) { - case B_FAILED: - io_xprint(s->io, notice_error); - break; - case B_DELAYED: - io_xprintf(s->io, notice_warning, - bounce_duration(s->msg->bounce.delay)); - break; - case B_DELIVERED: - io_xprint(s->io, s->msg->bounce.mta_without_dsn ? - notice_relay : notice_success); - break; - default: - log_warn("warn: bounce: unknown bounce_type"); - } - - TAILQ_FOREACH(evp, &s->msg->envelopes, entry) { - io_xprint(s->io, evp->report); - io_xprint(s->io, "\r\n"); - } - io_xprint(s->io, "\r\n"); - - if (s->msg->bounce.type == B_DELAYED) - io_xprintf(s->io, notice_warning2, - bounce_duration(s->msg->bounce.ttl)); - - io_xprintf(s->io, - " Below is a copy of the original message:\r\n" - "\r\n"); - - io_xprintf(s->io, - "--%16" PRIu64 "/%s\r\n" - "Content-Description: Delivery Report\r\n" - "Content-Type: message/delivery-status\r\n" - "\r\n", - s->boundary, s->smtpname); - - io_xprintf(s->io, - "Reporting-MTA: dns; %s\r\n" - "\r\n", - s->smtpname); - - TAILQ_FOREACH(evp, &s->msg->envelopes, entry) { - io_xprintf(s->io, - "Final-Recipient: rfc822; %s@%s\r\n" - "Action: %s\r\n" - "Status: %s\r\n" - "\r\n", - evp->dest.user, - evp->dest.domain, - action_str(&s->msg->bounce), - esc_code(evp->esc_class, evp->esc_code)); - } - - log_trace(TRACE_BOUNCE, "bounce: %p: >>> [... %zu bytes ...]", - s, io_queued(s->io)); - - s->state = BOUNCE_DATA_MESSAGE; - break; - - case BOUNCE_DATA_MESSAGE: - io_xprintf(s->io, - "--%16" PRIu64 "/%s\r\n" - "Content-Description: Message headers\r\n" - "Content-Type: text/rfc822-headers\r\n" - "\r\n", - s->boundary, s->smtpname); - - n = io_queued(s->io); - while (io_queued(s->io) < BOUNCE_HIWAT) { - if ((len = getline(&line, &sz, s->msgfp)) == -1) - break; - if (len == 1 && line[0] == '\n' && /* end of headers */ - s->msg->bounce.type == B_DELIVERED && - s->msg->bounce.dsn_ret == DSN_RETHDRS) { - free(line); - fclose(s->msgfp); - s->msgfp = NULL; - io_xprintf(s->io, - "\r\n--%16" PRIu64 "/%s--\r\n", s->boundary, - s->smtpname); - bounce_send(s, "."); - s->state = BOUNCE_DATA_END; - return (0); - } - line[len - 1] = '\0'; - io_xprintf(s->io, "%s%s\r\n", - (len == 2 && line[0] == '.') ? "." : "", line); - } - free(line); - - if (ferror(s->msgfp)) { - fclose(s->msgfp); - s->msgfp = NULL; - bounce_delivery(s->msg, IMSG_QUEUE_DELIVERY_TEMPFAIL, - "Error reading message"); - s->msg = NULL; - return (-1); - } - - io_xprintf(s->io, - "\r\n--%16" PRIu64 "/%s--\r\n", s->boundary, s->smtpname); - - log_trace(TRACE_BOUNCE, "bounce: %p: >>> [... %zu bytes ...]", - s, io_queued(s->io) - n); - - if (feof(s->msgfp)) { - fclose(s->msgfp); - s->msgfp = NULL; - bounce_send(s, "."); - s->state = BOUNCE_DATA_END; - } - break; - - case BOUNCE_QUIT: - bounce_send(s, "QUIT"); - s->state = BOUNCE_CLOSE; - break; - - default: - fatalx("bounce: bad state"); - } - - return (0); -} - - -static void -bounce_delivery(struct bounce_message *msg, int delivery, const char *status) -{ - struct bounce_envelope *be; - struct envelope evp; - size_t n; - const char *f; - - n = 0; - while ((be = TAILQ_FIRST(&msg->envelopes))) { - if (delivery == IMSG_QUEUE_DELIVERY_TEMPFAIL) { - if (queue_envelope_load(be->id, &evp) == 0) { - fatalx("could not reload envelope!"); - } - evp.retry++; - evp.lasttry = msg->timeout; - envelope_set_errormsg(&evp, "%s", status); - queue_envelope_update(&evp); - m_create(p_scheduler, delivery, 0, 0, -1); - m_add_envelope(p_scheduler, &evp); - m_close(p_scheduler); - } else { - m_create(p_scheduler, delivery, 0, 0, -1); - m_add_evpid(p_scheduler, be->id); - m_close(p_scheduler); - queue_envelope_delete(be->id); - } - TAILQ_REMOVE(&msg->envelopes, be, entry); - free(be->report); - free(be); - n += 1; - } - - - if (delivery == IMSG_QUEUE_DELIVERY_TEMPFAIL) - f = "TempFail"; - else if (delivery == IMSG_QUEUE_DELIVERY_PERMFAIL) - f = "PermFail"; - else - f = NULL; - - if (f) - log_warnx("warn: %s injecting failure report on message %08" - PRIx32 " to <%s> for %zu envelope%s: %s", - f, msg->msgid, msg->to, n, n > 1 ? "s":"", status); - - nmessage -= 1; - stat_decrement("bounce.message", 1); - stat_decrement("bounce.envelope", n); - free(msg->smtpname); - free(msg->to); - free(msg); -} - -static void -bounce_status(struct bounce_session *s, const char *fmt, ...) -{ - va_list ap; - char *status; - int len, delivery; - - /* Ignore if there is no message */ - if (s->msg == NULL) - return; - - va_start(ap, fmt); - if ((len = vasprintf(&status, fmt, ap)) == -1) - fatal("bounce: vasprintf"); - va_end(ap); - - if (*status == '2') - delivery = IMSG_QUEUE_DELIVERY_OK; - else if (*status == '5' || *status == '6') - delivery = IMSG_QUEUE_DELIVERY_PERMFAIL; - else - delivery = IMSG_QUEUE_DELIVERY_TEMPFAIL; - - bounce_delivery(s->msg, delivery, status); - s->msg = NULL; - if (s->msgfp) - fclose(s->msgfp); - - free(status); -} - -static void -bounce_free(struct bounce_session *s) -{ - log_debug("debug: bounce: %p: deleting session", s); - - io_free(s->io); - - free(s->smtpname); - free(s); - - running -= 1; - stat_decrement("bounce.session", 1); - bounce_drain(); -} - -static void -bounce_io(struct io *io, int evt, void *arg) -{ - struct bounce_session *s = arg; - const char *error; - char *line, *msg; - int cont; - size_t len; - - log_trace(TRACE_IO, "bounce: %p: %s %s", s, io_strevent(evt), - io_strio(io)); - - switch (evt) { - case IO_DATAIN: - nextline: - line = io_getline(s->io, &len); - if (line == NULL && io_datalen(s->io) >= LINE_MAX) { - bounce_status(s, "Input too long"); - bounce_free(s); - return; - } - - if (line == NULL) - break; - - /* Strip trailing '\r' */ - if (len && line[len - 1] == '\r') - line[--len] = '\0'; - - log_trace(TRACE_BOUNCE, "bounce: %p: <<< %s", s, line); - - if ((error = parse_smtp_response(line, len, &msg, &cont))) { - bounce_status(s, "Bad response: %s", error); - bounce_free(s); - return; - } - if (cont) - goto nextline; - - if (s->state == BOUNCE_CLOSE) { - bounce_free(s); - return; - } - - if (line[0] != '2' && line[0] != '3') { /* fail */ - bounce_status(s, "%s", line); - s->state = BOUNCE_QUIT; - } else if (s->state == BOUNCE_DATA_END) { /* accepted */ - bounce_status(s, "%s", line); - } - - if (bounce_next(s) == -1) { - bounce_free(s); - return; - } - - io_set_write(io); - break; - - case IO_LOWAT: - if (s->state == BOUNCE_DATA_MESSAGE) - if (bounce_next(s) == -1) { - bounce_free(s); - return; - } - if (io_queued(s->io) == 0) - io_set_read(io); - break; - - default: - bounce_status(s, "442 i/o error %d", evt); - bounce_free(s); - break; - } -} - -static int -bounce_message_cmp(const struct bounce_message *a, - const struct bounce_message *b) -{ - int r; - - if (a->msgid < b->msgid) - return (-1); - if (a->msgid > b->msgid) - return (1); - if ((r = strcmp(a->smtpname, b->smtpname))) - return (r); - - return memcmp(&a->bounce, &b->bounce, sizeof (a->bounce)); -} - -static const char * -action_str(const struct delivery_bounce *b) -{ - switch (b->type) { - case B_FAILED: - return ("failed"); - case B_DELAYED: - return ("delayed"); - case B_DELIVERED: - if (b->mta_without_dsn) - return ("relayed"); - - return ("delivered"); - default: - log_warn("warn: bounce: unknown bounce_type"); - return (""); - } -} - -SPLAY_GENERATE(bounce_message_tree, bounce_message, sp_entry, - bounce_message_cmp); diff --git a/ca.c b/ca.c deleted file mode 100644 index fdc177e2..00000000 --- a/ca.c +++ /dev/null @@ -1,761 +0,0 @@ -/* $OpenBSD: ca.c,v 1.36 2019/09/21 07:46:53 semarie Exp $ */ - -/* - * Copyright (c) 2014 Reyk Floeter - * Copyright (c) 2012 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" -#include "ssl.h" - -static int ca_verify_cb(int, X509_STORE_CTX *); - -static int rsae_send_imsg(int, const unsigned char *, unsigned char *, - RSA *, int, unsigned int); -static int rsae_pub_enc(int, const unsigned char *, unsigned char *, - RSA *, int); -static int rsae_pub_dec(int,const unsigned char *, unsigned char *, - RSA *, int); -static int rsae_priv_enc(int, const unsigned char *, unsigned char *, - RSA *, int); -static int rsae_priv_dec(int, const unsigned char *, unsigned char *, - RSA *, int); -static int rsae_mod_exp(BIGNUM *, const BIGNUM *, RSA *, BN_CTX *); -static int rsae_bn_mod_exp(BIGNUM *, const BIGNUM *, const BIGNUM *, - const BIGNUM *, BN_CTX *, BN_MONT_CTX *); -static int rsae_init(RSA *); -static int rsae_finish(RSA *); -static int rsae_keygen(RSA *, int, BIGNUM *, BN_GENCB *); - -static ECDSA_SIG *ecdsae_do_sign(const unsigned char *, int, const BIGNUM *, - const BIGNUM *, EC_KEY *); -static int ecdsae_sign_setup(EC_KEY *, BN_CTX *, BIGNUM **, BIGNUM **); -static int ecdsae_do_verify(const unsigned char *, int, const ECDSA_SIG *, - EC_KEY *); - - -static uint64_t reqid = 0; - -static void -ca_shutdown(void) -{ - log_debug("debug: ca agent exiting"); - _exit(0); -} - -int -ca(void) -{ - struct passwd *pw; - - purge_config(PURGE_LISTENERS|PURGE_TABLES|PURGE_RULES|PURGE_DISPATCHERS); - - if ((pw = getpwnam(SMTPD_USER)) == NULL) - fatalx("unknown user " SMTPD_USER); - - if (chroot(PATH_CHROOT) == -1) - fatal("ca: chroot"); - if (chdir("/") == -1) - fatal("ca: chdir(\"/\")"); - - config_process(PROC_CA); - - if (setgroups(1, &pw->pw_gid) || - setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || - setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) - fatal("ca: cannot drop privileges"); - - imsg_callback = ca_imsg; - event_init(); - - signal(SIGINT, SIG_IGN); - signal(SIGTERM, SIG_IGN); - signal(SIGPIPE, SIG_IGN); - signal(SIGHUP, SIG_IGN); - - config_peer(PROC_CONTROL); - config_peer(PROC_PARENT); - config_peer(PROC_PONY); - - /* Ignore them until we get our config */ - mproc_disable(p_pony); - - if (pledge("stdio", NULL) == -1) - err(1, "pledge"); - - event_dispatch(); - fatalx("exited event loop"); - - return (0); -} - -void -ca_init(void) -{ - BIO *in = NULL; - EVP_PKEY *pkey = NULL; - struct pki *pki; - const char *k; - void *iter_dict; - - log_debug("debug: init private ssl-tree"); - iter_dict = NULL; - while (dict_iter(env->sc_pki_dict, &iter_dict, &k, (void **)&pki)) { - if (pki->pki_key == NULL) - continue; - - if ((in = BIO_new_mem_buf(pki->pki_key, - pki->pki_key_len)) == NULL) - fatalx("ca_launch: key"); - - if ((pkey = PEM_read_bio_PrivateKey(in, - NULL, NULL, NULL)) == NULL) - fatalx("ca_launch: PEM"); - BIO_free(in); - - pki->pki_pkey = pkey; - - freezero(pki->pki_key, pki->pki_key_len); - pki->pki_key = NULL; - } -} - -static int -ca_verify_cb(int ok, X509_STORE_CTX *ctx) -{ - switch (X509_STORE_CTX_get_error(ctx)) { - case X509_V_OK: - break; - case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: - break; - case X509_V_ERR_CERT_NOT_YET_VALID: - case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: - break; - case X509_V_ERR_CERT_HAS_EXPIRED: - case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: - break; - case X509_V_ERR_NO_EXPLICIT_POLICY: - break; - } - return ok; -} - -int -ca_X509_verify(void *certificate, void *chain, const char *CAfile, - const char *CRLfile, const char **errstr) -{ - X509_STORE *store = NULL; - X509_STORE_CTX *xsc = NULL; - int ret = 0; - long error = 0; - - if ((store = X509_STORE_new()) == NULL) - goto end; - - if (!X509_STORE_load_locations(store, CAfile, NULL)) { - log_warn("warn: unable to load CA file %s", CAfile); - goto end; - } - X509_STORE_set_default_paths(store); - - if ((xsc = X509_STORE_CTX_new()) == NULL) - goto end; - - if (X509_STORE_CTX_init(xsc, store, certificate, chain) != 1) - goto end; - - X509_STORE_CTX_set_verify_cb(xsc, ca_verify_cb); - - ret = X509_verify_cert(xsc); - -end: - *errstr = NULL; - if (ret != 1) { - if (xsc) { - error = X509_STORE_CTX_get_error(xsc); - *errstr = X509_verify_cert_error_string(error); - } - else if (ERR_peek_last_error()) - *errstr = ERR_error_string(ERR_peek_last_error(), NULL); - } - - X509_STORE_CTX_free(xsc); - X509_STORE_free(store); - - return ret > 0 ? 1 : 0; -} - -void -ca_imsg(struct mproc *p, struct imsg *imsg) -{ - RSA *rsa = NULL; - EC_KEY *ecdsa = NULL; - const void *from = NULL; - unsigned char *to = NULL; - struct msg m; - const char *pkiname; - size_t flen, tlen, padding; - int buf_len; - struct pki *pki; - int ret = 0; - uint64_t id; - int v; - - if (imsg == NULL) - ca_shutdown(); - - switch (imsg->hdr.type) { - case IMSG_CONF_START: - return; - case IMSG_CONF_END: - ca_init(); - - /* Start fulfilling requests */ - mproc_enable(p_pony); - return; - - case IMSG_CTL_VERBOSE: - m_msg(&m, imsg); - m_get_int(&m, &v); - m_end(&m); - log_trace_verbose(v); - return; - - case IMSG_CTL_PROFILE: - m_msg(&m, imsg); - m_get_int(&m, &v); - m_end(&m); - profiling = v; - return; - - case IMSG_CA_RSA_PRIVENC: - case IMSG_CA_RSA_PRIVDEC: - m_msg(&m, imsg); - m_get_id(&m, &id); - m_get_string(&m, &pkiname); - m_get_data(&m, &from, &flen); - m_get_size(&m, &tlen); - m_get_size(&m, &padding); - m_end(&m); - - pki = dict_get(env->sc_pki_dict, pkiname); - if (pki == NULL || pki->pki_pkey == NULL || - (rsa = EVP_PKEY_get1_RSA(pki->pki_pkey)) == NULL) - fatalx("ca_imsg: invalid pki"); - - if ((to = calloc(1, tlen)) == NULL) - fatalx("ca_imsg: calloc"); - - switch (imsg->hdr.type) { - case IMSG_CA_RSA_PRIVENC: - ret = RSA_private_encrypt(flen, from, to, rsa, - padding); - break; - case IMSG_CA_RSA_PRIVDEC: - ret = RSA_private_decrypt(flen, from, to, rsa, - padding); - break; - } - - m_create(p, imsg->hdr.type, 0, 0, -1); - m_add_id(p, id); - m_add_int(p, ret); - if (ret > 0) - m_add_data(p, to, (size_t)ret); - m_close(p); - - free(to); - RSA_free(rsa); - return; - - case IMSG_CA_ECDSA_SIGN: - m_msg(&m, imsg); - m_get_id(&m, &id); - m_get_string(&m, &pkiname); - m_get_data(&m, &from, &flen); - m_end(&m); - - pki = dict_get(env->sc_pki_dict, pkiname); - if (pki == NULL || pki->pki_pkey == NULL || - (ecdsa = EVP_PKEY_get1_EC_KEY(pki->pki_pkey)) == NULL) - fatalx("ca_imsg: invalid pki"); - - buf_len = ECDSA_size(ecdsa); - if ((to = calloc(1, buf_len)) == NULL) - fatalx("ca_imsg: calloc"); - ret = ECDSA_sign(0, from, flen, to, &buf_len, ecdsa); - m_create(p, imsg->hdr.type, 0, 0, -1); - m_add_id(p, id); - m_add_int(p, ret); - if (ret > 0) - m_add_data(p, to, (size_t)buf_len); - m_close(p); - free(to); - EC_KEY_free(ecdsa); - return; - } - - errx(1, "ca_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type)); -} - -/* - * RSA privsep engine (called from unprivileged processes) - */ - -const RSA_METHOD *rsa_default = NULL; - -static RSA_METHOD *rsae_method = NULL; - -static int -rsae_send_imsg(int flen, const unsigned char *from, unsigned char *to, - RSA *rsa, int padding, unsigned int cmd) -{ - int ret = 0; - struct imsgbuf *ibuf; - struct imsg imsg; - int n, done = 0; - const void *toptr; - char *pkiname; - size_t tlen; - struct msg m; - uint64_t id; - - if ((pkiname = RSA_get_ex_data(rsa, 0)) == NULL) - return (0); - - /* - * Send a synchronous imsg because we cannot defer the RSA - * operation in OpenSSL's engine layer. - */ - m_create(p_ca, cmd, 0, 0, -1); - reqid++; - m_add_id(p_ca, reqid); - m_add_string(p_ca, pkiname); - m_add_data(p_ca, (const void *)from, (size_t)flen); - m_add_size(p_ca, (size_t)RSA_size(rsa)); - m_add_size(p_ca, (size_t)padding); - m_flush(p_ca); - - ibuf = &p_ca->imsgbuf; - - while (!done) { - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) - fatalx("imsg_read"); - if (n == 0) - fatalx("pipe closed"); - - while (!done) { - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatalx("imsg_get error"); - if (n == 0) - break; - - log_imsg(PROC_PONY, PROC_CA, &imsg); - - switch (imsg.hdr.type) { - case IMSG_CA_RSA_PRIVENC: - case IMSG_CA_RSA_PRIVDEC: - break; - default: - /* Another imsg is queued up in the buffer */ - pony_imsg(p_ca, &imsg); - imsg_free(&imsg); - continue; - } - - m_msg(&m, &imsg); - m_get_id(&m, &id); - if (id != reqid) - fatalx("invalid response id"); - m_get_int(&m, &ret); - if (ret > 0) - m_get_data(&m, &toptr, &tlen); - m_end(&m); - - if (ret > 0) - memcpy(to, toptr, tlen); - done = 1; - - imsg_free(&imsg); - } - } - mproc_event_add(p_ca); - - return (ret); -} - -static int -rsae_pub_enc(int flen,const unsigned char *from, unsigned char *to, RSA *rsa, - int padding) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (RSA_meth_get_pub_enc(rsa_default)(flen, from, to, rsa, padding)); -} - -static int -rsae_pub_dec(int flen,const unsigned char *from, unsigned char *to, RSA *rsa, - int padding) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (RSA_meth_get_pub_dec(rsa_default)(flen, from, to, rsa, padding)); -} - -static int -rsae_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, - int padding) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - if (RSA_get_ex_data(rsa, 0) != NULL) - return (rsae_send_imsg(flen, from, to, rsa, padding, - IMSG_CA_RSA_PRIVENC)); - return (RSA_meth_get_priv_enc(rsa_default)(flen, from, to, rsa, padding)); -} - -static int -rsae_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, - int padding) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - if (RSA_get_ex_data(rsa, 0) != NULL) - return (rsae_send_imsg(flen, from, to, rsa, padding, - IMSG_CA_RSA_PRIVDEC)); - - return (RSA_meth_get_priv_dec(rsa_default)(flen, from, to, rsa, padding)); -} - -static int -rsae_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (RSA_meth_get_mod_exp(rsa_default)(r0, I, rsa, ctx)); -} - -static int -rsae_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, - const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (RSA_meth_get_bn_mod_exp(rsa_default)(r, a, p, m, ctx, m_ctx)); -} - -static int -rsae_init(RSA *rsa) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - if (RSA_meth_get_init(rsa_default) == NULL) - return (1); - return (RSA_meth_get_init(rsa_default)(rsa)); -} - -static int -rsae_finish(RSA *rsa) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - if (RSA_meth_get_finish(rsa_default) == NULL) - return (1); - return (RSA_meth_get_finish(rsa_default)(rsa)); -} - -static int -rsae_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (RSA_meth_get_keygen(rsa_default)(rsa, bits, e, cb)); -} - - -/* - * ECDSA privsep engine (called from unprivileged processes) - */ - -const ECDSA_METHOD *ecdsa_default = NULL; - -static ECDSA_METHOD *ecdsae_method = NULL; - -ECDSA_METHOD * -ECDSA_METHOD_new_temporary(const char *name, int); - -ECDSA_METHOD * -ECDSA_METHOD_new_temporary(const char *name, int flags) -{ - ECDSA_METHOD *ecdsa; - - if ((ecdsa = calloc(1, sizeof (*ecdsa))) == NULL) - return NULL; - - if ((ecdsa->name = strdup(name)) == NULL) { - free(ecdsa); - return NULL; - } - - ecdsa->flags = flags; - return ecdsa; -} - -static ECDSA_SIG * -ecdsae_send_enc_imsg(const unsigned char *dgst, int dgst_len, - const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey) -{ - int ret = 0; - struct imsgbuf *ibuf; - struct imsg imsg; - int n, done = 0; - const void *toptr; - char *pkiname; - size_t tlen; - struct msg m; - uint64_t id; - ECDSA_SIG *sig = NULL; - - if ((pkiname = ECDSA_get_ex_data(eckey, 0)) == NULL) - return (0); - - /* - * Send a synchronous imsg because we cannot defer the ECDSA - * operation in OpenSSL's engine layer. - */ - m_create(p_ca, IMSG_CA_ECDSA_SIGN, 0, 0, -1); - reqid++; - m_add_id(p_ca, reqid); - m_add_string(p_ca, pkiname); - m_add_data(p_ca, (const void *)dgst, (size_t)dgst_len); - m_flush(p_ca); - - ibuf = &p_ca->imsgbuf; - - while (!done) { - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) - fatalx("imsg_read"); - if (n == 0) - fatalx("pipe closed"); - while (!done) { - if ((n = imsg_get(ibuf, &imsg)) == -1) - fatalx("imsg_get error"); - if (n == 0) - break; - - log_imsg(PROC_PONY, PROC_CA, &imsg); - - switch (imsg.hdr.type) { - case IMSG_CA_ECDSA_SIGN: - break; - default: - /* Another imsg is queued up in the buffer */ - pony_imsg(p_ca, &imsg); - imsg_free(&imsg); - continue; - } - - m_msg(&m, &imsg); - m_get_id(&m, &id); - if (id != reqid) - fatalx("invalid response id"); - m_get_int(&m, &ret); - if (ret > 0) - m_get_data(&m, &toptr, &tlen); - m_end(&m); - done = 1; - - if (ret > 0) - d2i_ECDSA_SIG(&sig, (const unsigned char **)&toptr, tlen); - imsg_free(&imsg); - } - } - mproc_event_add(p_ca); - - return (sig); -} - -ECDSA_SIG * -ecdsae_do_sign(const unsigned char *dgst, int dgst_len, - const BIGNUM *inv, const BIGNUM *rp, EC_KEY *eckey) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - if (ECDSA_get_ex_data(eckey, 0) != NULL) - return (ecdsae_send_enc_imsg(dgst, dgst_len, inv, rp, eckey)); - return (ecdsa_default->ecdsa_do_sign(dgst, dgst_len, inv, rp, eckey)); -} - -int -ecdsae_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, - BIGNUM **r) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (ecdsa_default->ecdsa_sign_setup(eckey, ctx, kinv, r)); -} - -int -ecdsae_do_verify(const unsigned char *dgst, int dgst_len, - const ECDSA_SIG *sig, EC_KEY *eckey) -{ - log_debug("debug: %s: %s", proc_name(smtpd_process), __func__); - return (ecdsa_default->ecdsa_do_verify(dgst, dgst_len, sig, eckey)); -} - - -static void -rsa_engine_init(void) -{ - ENGINE *e; - const char *errstr, *name; - - if ((rsae_method = RSA_meth_new("RSA privsep engine", 0)) == NULL) { - errstr = "RSA_meth_new"; - goto fail; - } - - RSA_meth_set_pub_enc(rsae_method, rsae_pub_enc); - RSA_meth_set_pub_dec(rsae_method, rsae_pub_dec); - RSA_meth_set_priv_enc(rsae_method, rsae_priv_enc); - RSA_meth_set_priv_dec(rsae_method, rsae_priv_dec); - RSA_meth_set_mod_exp(rsae_method, rsae_mod_exp); - RSA_meth_set_bn_mod_exp(rsae_method, rsae_bn_mod_exp); - RSA_meth_set_init(rsae_method, rsae_init); - RSA_meth_set_finish(rsae_method, rsae_finish); - RSA_meth_set_keygen(rsae_method, rsae_keygen); - - if ((e = ENGINE_get_default_RSA()) == NULL) { - if ((e = ENGINE_new()) == NULL) { - errstr = "ENGINE_new"; - goto fail; - } - if (!ENGINE_set_name(e, RSA_meth_get0_name(rsae_method))) { - errstr = "ENGINE_set_name"; - goto fail; - } - if ((rsa_default = RSA_get_default_method()) == NULL) { - errstr = "RSA_get_default_method"; - goto fail; - } - } else if ((rsa_default = ENGINE_get_RSA(e)) == NULL) { - errstr = "ENGINE_get_RSA"; - goto fail; - } - - if ((name = ENGINE_get_name(e)) == NULL) - name = "unknown RSA engine"; - - log_debug("debug: %s: using %s", __func__, name); - - if (RSA_meth_get_mod_exp(rsa_default) == NULL) - RSA_meth_set_mod_exp(rsae_method, NULL); - if (RSA_meth_get_bn_mod_exp(rsa_default) == NULL) - RSA_meth_set_bn_mod_exp(rsae_method, NULL); - if (RSA_meth_get_keygen(rsa_default) == NULL) - RSA_meth_set_keygen(rsae_method, NULL); - RSA_meth_set_flags(rsae_method, - RSA_meth_get_flags(rsa_default) | RSA_METHOD_FLAG_NO_CHECK); - RSA_meth_set0_app_data(rsae_method, - RSA_meth_get0_app_data(rsa_default)); - - if (!ENGINE_set_RSA(e, rsae_method)) { - errstr = "ENGINE_set_RSA"; - goto fail; - } - if (!ENGINE_set_default_RSA(e)) { - errstr = "ENGINE_set_default_RSA"; - goto fail; - } - - return; - - fail: - ssl_error(errstr); - fatalx("%s", errstr); -} - -static void -ecdsa_engine_init(void) -{ - ENGINE *e; - const char *errstr, *name; - - if ((ecdsae_method = ECDSA_METHOD_new_temporary("ECDSA privsep engine", 0)) == NULL) { - errstr = "ECDSA_METHOD_new_temporary"; - goto fail; - } - - ecdsae_method->ecdsa_do_sign = ecdsae_do_sign; - ecdsae_method->ecdsa_sign_setup = ecdsae_sign_setup; - ecdsae_method->ecdsa_do_verify = ecdsae_do_verify; - - if ((e = ENGINE_get_default_ECDSA()) == NULL) { - if ((e = ENGINE_new()) == NULL) { - errstr = "ENGINE_new"; - goto fail; - } - if (!ENGINE_set_name(e, ecdsae_method->name)) { - errstr = "ENGINE_set_name"; - goto fail; - } - if ((ecdsa_default = ECDSA_get_default_method()) == NULL) { - errstr = "ECDSA_get_default_method"; - goto fail; - } - } else if ((ecdsa_default = ENGINE_get_ECDSA(e)) == NULL) { - errstr = "ENGINE_get_ECDSA"; - goto fail; - } - - if ((name = ENGINE_get_name(e)) == NULL) - name = "unknown ECDSA engine"; - - log_debug("debug: %s: using %s", __func__, name); - - if (!ENGINE_set_ECDSA(e, ecdsae_method)) { - errstr = "ENGINE_set_ECDSA"; - goto fail; - } - if (!ENGINE_set_default_ECDSA(e)) { - errstr = "ENGINE_set_default_ECDSA"; - goto fail; - } - - return; - - fail: - ssl_error(errstr); - fatalx("%s", errstr); -} - -void -ca_engine_init(void) -{ - rsa_engine_init(); - ecdsa_engine_init(); -} diff --git a/cert.c b/cert.c deleted file mode 100644 index 05aff418..00000000 --- a/cert.c +++ /dev/null @@ -1,414 +0,0 @@ -/* $OpenBSD: cert.c,v 1.2 2018/12/11 07:25:57 eric Exp $ */ - -/* - * Copyright (c) 2018 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "log.h" -#include "smtpd.h" -#include "ssl.h" - -#define p_cert p_lka - -struct request { - SPLAY_ENTRY(request) entry; - uint32_t id; - void (*cb_get_certificate)(void *, int, const char *, - const void *, size_t); - void (*cb_verify)(void *, int); - void *arg; -}; - -#define MAX_CERTS 16 -#define MAX_CERT_LEN (MAX_IMSGSIZE - (IMSG_HEADER_SIZE + sizeof(size_t))) - -struct session { - SPLAY_ENTRY(session) entry; - uint32_t id; - struct mproc *proc; - char *cert[MAX_CERTS]; - size_t cert_len[MAX_CERTS]; - int cert_count; -}; - -SPLAY_HEAD(cert_reqtree, request); -SPLAY_HEAD(cert_sestree, session); - -static int request_cmp(struct request *, struct request *); -static int session_cmp(struct session *, struct session *); -SPLAY_PROTOTYPE(cert_reqtree, request, entry, request_cmp); -SPLAY_PROTOTYPE(cert_sestree, session, entry, session_cmp); - -static void cert_do_verify(struct session *, const char *, int); -static int cert_X509_verify(struct session *, const char *, const char *); - -static struct cert_reqtree reqs = SPLAY_INITIALIZER(&reqs); -static struct cert_sestree sess = SPLAY_INITIALIZER(&sess); - -int -cert_init(const char *name, int fallback, void (*cb)(void *, int, - const char *, const void *, size_t), void *arg) -{ - struct request *req; - - req = calloc(1, sizeof(*req)); - if (req == NULL) { - cb(arg, CA_FAIL, NULL, NULL, 0); - return 0; - } - while (req->id == 0 || SPLAY_FIND(cert_reqtree, &reqs, req)) - req->id = arc4random(); - req->cb_get_certificate = cb; - req->arg = arg; - SPLAY_INSERT(cert_reqtree, &reqs, req); - - m_create(p_cert, IMSG_CERT_INIT, req->id, 0, -1); - m_add_string(p_cert, name); - m_add_int(p_cert, fallback); - m_close(p_cert); - - return 1; -} - -int -cert_verify(const void *ssl, const char *name, int fallback, - void (*cb)(void *, int), void *arg) -{ - struct request *req; - X509 *x; - STACK_OF(X509) *xchain; - unsigned char *cert_der[MAX_CERTS]; - int cert_len[MAX_CERTS]; - int i, cert_count, ret; - - x = SSL_get_peer_certificate(ssl); - if (x == NULL) { - cb(arg, CERT_NOCERT); - return 0; - } - - ret = 0; - memset(cert_der, 0, sizeof(cert_der)); - - req = calloc(1, sizeof(*req)); - if (req == NULL) - goto end; - while (req->id == 0 || SPLAY_FIND(cert_reqtree, &reqs, req)) - req->id = arc4random(); - req->cb_verify = cb; - req->arg = arg; - SPLAY_INSERT(cert_reqtree, &reqs, req); - - cert_count = 1; - if ((xchain = SSL_get_peer_cert_chain(ssl))) { - cert_count += sk_X509_num(xchain); - if (cert_count > MAX_CERTS) { - log_warnx("warn: certificate chain too long"); - goto end; - } - } - - for (i = 0; i < cert_count; ++i) { - if (i != 0) { - if ((x = sk_X509_value(xchain, i - 1)) == NULL) { - log_warnx("warn: failed to retrieve certificate"); - goto end; - } - } - - cert_len[i] = i2d_X509(x, &cert_der[i]); - if (i == 0) - X509_free(x); - - if (cert_len[i] < 0) { - log_warnx("warn: failed to encode certificate"); - goto end; - } - - log_debug("debug: certificate %i: len=%d", i, cert_len[i]); - if (cert_len[i] > (int)MAX_CERT_LEN) { - log_warnx("warn: certificate too long"); - goto end; - } - } - - /* Send the cert chain, one cert at a time */ - for (i = 0; i < cert_count; ++i) { - m_create(p_cert, IMSG_CERT_CERTIFICATE, req->id, 0, -1); - m_add_data(p_cert, cert_der[i], cert_len[i]); - m_close(p_cert); - } - - /* Tell lookup process that it can start verifying, we're done */ - m_create(p_cert, IMSG_CERT_VERIFY, req->id, 0, -1); - m_add_string(p_cert, name); - m_add_int(p_cert, fallback); - m_close(p_cert); - - ret = 1; - - end: - for (i = 0; i < MAX_CERTS; ++i) - free(cert_der[i]); - - if (ret == 0) { - if (req) - SPLAY_REMOVE(cert_reqtree, &reqs, req); - free(req); - cb(arg, CERT_ERROR); - } - - return ret; -} - - -void -cert_dispatch_request(struct mproc *proc, struct imsg *imsg) -{ - struct pki *pki; - struct session key, *s; - const char *name; - const void *data; - size_t datalen; - struct msg m; - uint32_t reqid; - char buf[LINE_MAX]; - int fallback; - - reqid = imsg->hdr.peerid; - m_msg(&m, imsg); - - switch (imsg->hdr.type) { - - case IMSG_CERT_INIT: - m_get_string(&m, &name); - m_get_int(&m, &fallback); - m_end(&m); - - xlowercase(buf, name, sizeof(buf)); - log_debug("debug: looking up pki \"%s\"", buf); - pki = dict_get(env->sc_pki_dict, buf); - if (pki == NULL && fallback) - pki = dict_get(env->sc_pki_dict, "*"); - - m_create(proc, IMSG_CERT_INIT, reqid, 0, -1); - if (pki) { - m_add_int(proc, CA_OK); - m_add_string(proc, pki->pki_name); - m_add_data(proc, pki->pki_cert, pki->pki_cert_len); - } else { - m_add_int(proc, CA_FAIL); - m_add_string(proc, NULL); - m_add_data(proc, NULL, 0); - } - m_close(proc); - return; - - case IMSG_CERT_CERTIFICATE: - m_get_data(&m, &data, &datalen); - m_end(&m); - - key.id = reqid; - key.proc = proc; - s = SPLAY_FIND(cert_sestree, &sess, &key); - if (s == NULL) { - s = calloc(1, sizeof(*s)); - s->proc = proc; - s->id = reqid; - SPLAY_INSERT(cert_sestree, &sess, s); - } - - if (s->cert_count == MAX_CERTS) - fatalx("%s: certificate chain too long", __func__); - - s->cert[s->cert_count] = xmemdup(data, datalen); - s->cert_len[s->cert_count] = datalen; - s->cert_count++; - return; - - case IMSG_CERT_VERIFY: - m_get_string(&m, &name); - m_get_int(&m, &fallback); - m_end(&m); - - key.id = reqid; - key.proc = proc; - s = SPLAY_FIND(cert_sestree, &sess, &key); - if (s == NULL) - fatalx("%s: no certificate", __func__); - - SPLAY_REMOVE(cert_sestree, &sess, s); - cert_do_verify(s, name, fallback); - return; - - default: - fatalx("%s: %s", __func__, imsg_to_str(imsg->hdr.type)); - } -} - -void -cert_dispatch_result(struct mproc *proc, struct imsg *imsg) -{ - struct request key, *req; - struct msg m; - const void *cert; - const char *name; - size_t cert_len; - int res; - - key.id = imsg->hdr.peerid; - req = SPLAY_FIND(cert_reqtree, &reqs, &key); - if (req == NULL) - fatalx("%s: unknown request %08x", __func__, imsg->hdr.peerid); - - m_msg(&m, imsg); - - switch (imsg->hdr.type) { - - case IMSG_CERT_INIT: - m_get_int(&m, &res); - m_get_string(&m, &name); - m_get_data(&m, &cert, &cert_len); - m_end(&m); - SPLAY_REMOVE(cert_reqtree, &reqs, req); - req->cb_get_certificate(req->arg, res, name, cert, cert_len); - free(req); - break; - - case IMSG_CERT_VERIFY: - m_get_int(&m, &res); - m_end(&m); - SPLAY_REMOVE(cert_reqtree, &reqs, req); - req->cb_verify(req->arg, res); - free(req); - break; - } -} - -static void -cert_do_verify(struct session *s, const char *name, int fallback) -{ - struct ca *ca; - const char *cafile; - int i, res; - - ca = dict_get(env->sc_ca_dict, name); - if (ca == NULL) - if (fallback) - ca = dict_get(env->sc_ca_dict, "*"); - cafile = ca ? ca->ca_cert_file : CA_FILE; - - if (ca == NULL && !fallback) - res = CERT_NOCA; - else if (!cert_X509_verify(s, cafile, NULL)) - res = CERT_INVALID; - else - res = CERT_OK; - - for (i = 0; i < s->cert_count; ++i) - free(s->cert[i]); - - m_create(s->proc, IMSG_CERT_VERIFY, s->id, 0, -1); - m_add_int(s->proc, res); - m_close(s->proc); - - free(s); -} - -static int -cert_X509_verify(struct session *s, const char *CAfile, - const char *CRLfile) -{ - X509 *x509; - X509 *x509_tmp; - STACK_OF(X509) *x509_chain; - const unsigned char *d2i; - int i, ret = 0; - const char *errstr; - - x509 = NULL; - x509_tmp = NULL; - x509_chain = NULL; - - d2i = s->cert[0]; - if (d2i_X509(&x509, &d2i, s->cert_len[0]) == NULL) { - x509 = NULL; - goto end; - } - - if (s->cert_count > 1) { - x509_chain = sk_X509_new_null(); - for (i = 1; i < s->cert_count; ++i) { - d2i = s->cert[i]; - if (d2i_X509(&x509_tmp, &d2i, s->cert_len[i]) == NULL) - goto end; - sk_X509_insert(x509_chain, x509_tmp, i); - x509_tmp = NULL; - } - } - if (!ca_X509_verify(x509, x509_chain, CAfile, NULL, &errstr)) - log_debug("debug: X509 verify: %s", errstr); - else - ret = 1; - -end: - X509_free(x509); - X509_free(x509_tmp); - if (x509_chain) - sk_X509_pop_free(x509_chain, X509_free); - - return ret; -} - -static int -request_cmp(struct request *a, struct request *b) -{ - if (a->id < b->id) - return -1; - if (a->id > b->id) - return 1; - return 0; -} - -SPLAY_GENERATE(cert_reqtree, request, entry, request_cmp); - -static int -session_cmp(struct session *a, struct session *b) -{ - if (a->id < b->id) - return -1; - if (a->id > b->id) - return 1; - if (a->proc < b->proc) - return -1; - if (a->proc > b->proc) - return 1; - return 0; -} - -SPLAY_GENERATE(cert_sestree, session, entry, session_cmp); diff --git a/ci/COVERITY.MD5SUM b/ci/COVERITY.MD5SUM new file mode 100644 index 00000000..67b8a2de --- /dev/null +++ b/ci/COVERITY.MD5SUM @@ -0,0 +1 @@ +d0d7d7df9d6609e578f85096a755fb8f ./cov-analysis-linux64.tgz diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 00000000..2eee08f1 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,83 @@ +# Continuous Integration + +This directory contains CI/CD related scripts and resources + +CI/CD process leverages GitHub Actions as a primary automation platform since +up to 20 parallel workflows are available for opensource projects. + +On high level we have multiple dimensions to test: + + - OS Distribution + - TLS library implementation: libress, openssl + - libc implementations: glibc, musl + - compiler: gcc, clang (not yet tested) + +Within this matrix build tests, static code analysis, functional and +integration tests are planned. Currently only build tests and static code +analysis exist. Help is much needed with developing functional and integration +tests. + +## Directory strucuture + +- [docker](#dockerfiles) dockerfiles for various distributions +- [scripts](#scripts) useful scripts for ci/cd automation + + +## Design Considerations + +- Keep workflow yaml files and execution logic as separate as possible. + Reference ci scripts from workflow files to allow running same tests + locally, without depending on github. + + + +# Dockerfiles + +Dockerfiles in [docker](docker/) directory can be used for developing and +testing OpenSMTPD. These dockerfiles are intended to be used for dev/test +cycle ONLY and ARE NOT intended to be a delivery mechanism for end users and +should not be published on external resouces like DockerHub. Dockerfiles in +this folder can be used as a reference for package maintainers of various +distributions. + + +## Usage + +OpenSMTPD provides a set of dockerfiles for getting started with development +quickly locally or with GitHub's Actions. + +For each distribution there is a separate dockerfile with a distro name +suffixed. E.g. `Dockerfile.alpine` is a dockerfile that builds OpenSMTPD in +Alpine Linux environment. + +To build: + + docker build -f docker/Dockerfile.alpine -t opensmtpd-alpine + + +All configuration files that are in `/etc/mail` are taken from `etc/` directory. + + +To run the container that you've just built run: + + docker run --name smtpd_server -p 25:25 opensmtpd-alpine + + + +# Scripts + +Scripts to automate ci/cd actions: + +- [coverity_scan](scripts/coverity_scan.sh) - runs coverity scan and submits + the rusult to Coverity. See script contents for usage instructions. + +- [generate_certs](scripts/generate_certs.sh) - convenient script to quickly + generate some TLS certificates. Useful for testing. + +# Historical reference + +[Initial design discusstion](https://github.com/OpenSMTPD/OpenSMTPD/issues/947) + + + + diff --git a/ci/docker/Dockerfile.alpine b/ci/docker/Dockerfile.alpine new file mode 100644 index 00000000..2c7c66fc --- /dev/null +++ b/ci/docker/Dockerfile.alpine @@ -0,0 +1,50 @@ +FROM alpine:3.11 as build + +# creates /opensmtpd dir and makes all following commands to run in it +# https://docs.docker.com/engine/reference/builder/#workdir +WORKDIR /opensmtpd + +# install necessary packages +RUN apk add --no-cache \ + autoconf \ + automake \ + bison \ + ca-certificates \ + fts-dev \ + gcc \ + fts \ + libevent-dev \ + libtool \ + libtool \ + linux-pam-dev \ + make \ + musl-dev \ + libressl \ + libressl-dev \ + zlib-dev + +# create users and directories +# note: alpine uses busybox and useradd is not available there +# also long flags are not available too, so sorry for the +RUN mkdir -p /var/lib/opensmtpd/empty \ + && adduser _smtpd -h /var/lib/opensmtpd/empty/ -D -H -s /bin/false \ + && adduser _smtpq -h /var/lib/opensmtpd/empty/ -D -H -s /bin/false \ + && mkdir -p /var/spool/smtpd \ + && mkdir -p /var/mail \ + && mkdir -p /etc/mail \ + && chmod 711 /var/spool/smtpd + +# Copy contentes of the repo inside the container +# https://docs.docker.com/engine/reference/builder/#copy +COPY . /opensmtpd + +# build opensmtpd +RUN ./bootstrap \ + && ./configure \ + --with-gnu-ld \ + --sysconfdir=/etc/mail \ + --with-auth-pam \ + && make \ + && make install \ + && cp etc/aliases /etc/mail/aliases + diff --git a/ci/docker/Dockerfile.archlinux b/ci/docker/Dockerfile.archlinux new file mode 100644 index 00000000..dcd46684 --- /dev/null +++ b/ci/docker/Dockerfile.archlinux @@ -0,0 +1,62 @@ +FROM archlinux + +# Allow container to expose ports at runtime, if necessary +# https://docs.docker.com/engine/reference/#expose +EXPOSE 25 +EXPOSE 465 +EXPOSE 587 + +# creates /opensmtpd dir and makes all following commands to run in it +# https://docs.docker.com/engine/reference/builder/#workdir +WORKDIR /opensmtpd + +# install necessary packages +RUN pacman -Suy --noconfirm \ + base \ + make \ + m4 \ + grep \ + gcc \ + automake \ + autoconf \ + libtool \ + bison \ + gettext \ + libevent \ + libressl \ + pam \ + zlib + + +# create users and directories +RUN mkdir -p /var/lib/opensmtpd/empty \ + && useradd _smtpd \ + --home-dir /var/lib/opensmtpd/empty \ + --no-create-home \ + --shell /bin/false \ + && useradd _smtpq \ + --home-dir /var/lib/opensmtpd/empty \ + --no-create-home \ + --shell /bin/false \ + && mkdir -p /var/spool/smtpd \ + && mkdir -p /var/mail \ + && mkdir -p /etc/mail \ + && chmod 711 /var/spool/smtpd + + +# Copy contentes of the repo inside the container +# https://docs.docker.com/engine/reference/builder/#copy +COPY . /opensmtpd + + +# build opensmtpd +RUN ./bootstrap \ + && ./configure --with-gnu-ld \ + --sysconfdir=/etc/mail \ + --with-cflags='-I/usr/include/libressl -L/usr/lib/libressl -Wl,-rpath=/usr/lib/libressl' \ + --with-path-empty=/var/lib/opensmtpd/empty \ + --with-auth-pam \ + && make \ + && make install \ + && cp etc/aliases /etc/mail/aliases + diff --git a/ci/docker/Dockerfile.ubuntu b/ci/docker/Dockerfile.ubuntu new file mode 100644 index 00000000..6626033d --- /dev/null +++ b/ci/docker/Dockerfile.ubuntu @@ -0,0 +1,52 @@ +FROM ubuntu:latest + +# Allow container to expose ports at runtime, if necessary +# https://docs.docker.com/engine/reference/#expose +EXPOSE 25 +EXPOSE 465 +EXPOSE 587 + +# creates /opensmtpd dir and makes all following commands to run in it +# https://docs.docker.com/engine/reference/builder/#workdir +WORKDIR /opensmtpd + +# install necessary packages +RUN apt update \ + && apt install -y --no-install-recommends \ + autoconf \ + automake \ + bison \ + build-essential \ + libevent-dev \ + libssl-dev \ + libtool \ + libpam0g-dev \ + zlib1g-dev + +# create users and directories +RUN mkdir -p /var/lib/opensmtpd/empty \ + && useradd _smtpd \ + --home-dir /var/lib/opensmtpd/empty \ + --no-create-home \ + --shell /bin/false \ + && useradd _smtpq \ + --home-dir /var/lib/opensmtpd/empty \ + --no-create-home \ + --shell /bin/false \ + && mkdir -p /var/spool/smtpd \ + && mkdir -p /var/mail \ + && mkdir -p /etc/mail \ + && chmod 711 /var/spool/smtpd + +# Copy contentes of the repo inside the container +# https://docs.docker.com/engine/reference/builder/#copy +COPY . /opensmtpd + +RUN ./bootstrap \ + && ./configure \ + --with-gnu-ld \ + --sysconfdir=/etc/mail \ + --with-auth-pam \ + && make \ + && make install \ + && cp etc/aliases /etc/mail/aliases diff --git a/ci/docker/Dockerfile.ubuntu-gcc10 b/ci/docker/Dockerfile.ubuntu-gcc10 new file mode 100644 index 00000000..2ebbdf58 --- /dev/null +++ b/ci/docker/Dockerfile.ubuntu-gcc10 @@ -0,0 +1,54 @@ +FROM ubuntu:latest + +# Allow container to expose ports at runtime, if necessary +# https://docs.docker.com/engine/reference/#expose +EXPOSE 25 +EXPOSE 465 +EXPOSE 587 + +# creates /opensmtpd dir and makes all following commands to run in it +# https://docs.docker.com/engine/reference/builder/#workdir +WORKDIR /opensmtpd + +# install necessary packages +RUN apt update \ + && apt install -y --no-install-recommends \ + autoconf \ + automake \ + bison \ + build-essential \ + libevent-dev \ + libssl-dev \ + libtool \ + libpam0g-dev \ + zlib1g-dev \ + gcc-10 + +# create users and directories +RUN mkdir -p /var/lib/opensmtpd/empty \ + && useradd _smtpd \ + --home-dir /var/lib/opensmtpd/empty \ + --no-create-home \ + --shell /bin/false \ + && useradd _smtpq \ + --home-dir /var/lib/opensmtpd/empty \ + --no-create-home \ + --shell /bin/false \ + && mkdir -p /var/spool/smtpd \ + && mkdir -p /var/mail \ + && mkdir -p /etc/mail \ + && chmod 711 /var/spool/smtpd + +# Copy contentes of the repo inside the container +# https://docs.docker.com/engine/reference/builder/#copy +COPY . /opensmtpd + +RUN export CC=gcc-10 CXX=g++-10 +RUN ./bootstrap \ + && ./configure \ + --with-gnu-ld \ + --sysconfdir=/etc/mail \ + --with-auth-pam \ + && make \ + && make install \ + && cp etc/aliases /etc/mail/aliases diff --git a/ci/scripts/clang_scan.sh b/ci/scripts/clang_scan.sh new file mode 100755 index 00000000..714d55a7 --- /dev/null +++ b/ci/scripts/clang_scan.sh @@ -0,0 +1,60 @@ +#!/bin/sh +set -eu + +# Unconditionally go to the root level of the git repo. +# If you invoke it from outside of the repo go to +# the script location first +cd "$(dirname "$0")" +cd "$(git rev-parse --show-toplevel)" + +# Clang Scan script +# +# USAGE: +# - clang must be installed +# - make sure you have clean repository, +# e.g. git clean -ffdx +# - if you want to download github badge set CLANG_SCAN_BADGE_REQUIRED variable +# - Run script from anywhere inside the repository +# ./ci/scripts/clang_scan.sh +# or +# CLANG_SCAN_BADGE_REQUIRED=1 ./ci/scripts/clang_scan.sh +# + +if ! type scan-build > /dev/null; then + echo "clang scan-build is missing" + exit 1 +fi + +# Unconditionally go to the root level of the git repo. +# If you invoke it from outside of the repo go to +# the script location first +cd "$(dirname "$0")" +# This moves us to the root of the repo +cd "$(git rev-parse --show-toplevel)" + +# Get short SHA of the HEAD +sha=$(git rev-parse --short HEAD) + +results_dir=${CLANG_SCAN_RESULTS_DIR:-clang-report} +mkdir -p "$results_dir" + +# Build with scan-build +./bootstrap +./configure +scan-build -o "$results_dir" \ + --keep-empty \ + --html-title="OpenSMTPD $sha" make + + +set -x +# conditionally generate badge +if [ -z "${CLANG_SCAN_BADGE_REQUIRED:-}" ]; then + echo "Skipping badge generation" +else + echo "Generating badge" + . ci/scripts/imports/badge.sh + cd "$results_dir" + cd "$( find . -type d | sort | tail -n1 )" + issues_nr="$( find . -name "report-*" | wc -l)" + download_badge "$issues_nr" "clang analysis" "$(pwd)" 30 +fi diff --git a/ci/scripts/coverity_scan.sh b/ci/scripts/coverity_scan.sh new file mode 100755 index 00000000..ab302767 --- /dev/null +++ b/ci/scripts/coverity_scan.sh @@ -0,0 +1,77 @@ +#!/bin/sh +set -eu + +# Coverity Scan script +# Steps closely follow official documentation https://scan.coverity.com/download +# +# USAGE: provide coverity project token as 'token' environment variable and run +# token=abcdedf ./ci/scripts/coverity_scan.sh +# +# Or uncomment this line and put token here. But do not commit this to git. +# token="" +project_name="OpenSMTPD%2FOpenSMTPD" +cov_analysis_url="https://scan.coverity.com/download/cxx/linux64" +maintainer="ihor@antonovs.family" + +# Unconditionally go to the root level of the git repo. +# If you invoke it from outside of the repo go to +# the script location first +cd "$(dirname "$0")" +# This moves us to the root of the repo +cd "$(git rev-parse --show-toplevel)" + +# Get short SHA of the HEAD +sha=$(git rev-parse --short HEAD) + +# Download Coverity Build Tool if absent +set +x +# shellcheck disable=SC2154 +md5sum -c ./ci/COVERITY.MD5SUM || wget $cov_analysis_url \ + --post-data "token=$token&project=$project_name" \ + -O cov-analysis-linux64.tgz +set -x + +#Check MD5 +md5sum -c ./ci/COVERITY.MD5SUM + +# Extract Coverty Scan Tool +rm -rf ./cov-analysis-linux64 +mkdir -p cov-analysis-linux64 +tar xzf cov-analysis-linux64.tgz --strip 1 -C cov-analysis-linux64 + +# export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH + +# Build with cov-build +./bootstrap +./configure +cov-analysis-linux64/bin/cov-build --dir cov-int make + +# Compress the rusults +tar czvf opensmtpd.tgz cov-int + + +# Submit the result to Coverity Scan +# Some parts are shamelessly taken from: +# https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh +set +x +response=$(curl \ + --silent \ + --write-out "\n%{http_code}\n" \ + --form token="$token" \ + --form email="$maintainer" \ + --form file=@opensmtpd.tgz \ + --form version="portable-$sha" \ + --form description="daily scan" \ + "https://scan.coverity.com/builds?project=$project_name") +set -x + +status_code=$(echo "$response" | sed -n '$p') + +if [ "$status_code" != "200" ]; then + text=$(echo "$response" | sed '$d') + echo -e "Coverity Scan upload failed: $text" + exit 1 +fi + + + diff --git a/ci/scripts/generate_certs.sh b/ci/scripts/generate_certs.sh new file mode 100755 index 00000000..a9249c1e --- /dev/null +++ b/ci/scripts/generate_certs.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# Generate self-signed SSL certs +# Usage: ./generate_certs.sh + +days=3560 # 10 years +config="$(dirname "$0")/ssl.conf" +cert="open.smtpd.cert" +key="open.smtpd.key" +csr="open.smtpd.csr" + +# Key + CSR generation: +openssl req \ + -new \ + -x509 \ + -newkey rsa:2048 \ + -sha256 \ + -nodes \ + -keyout $key \ + -out $csr \ + -days $days \ + -config "$config" + +# Certificate generation: +openssl req \ + -new \ + -x509 \ + -newkey rsa:2048 \ + -days $days \ + -nodes \ + -config "$config" \ + -keyout $key \ + -out $cert diff --git a/ci/scripts/imports/badge.sh b/ci/scripts/imports/badge.sh new file mode 100644 index 00000000..d6cf0b3a --- /dev/null +++ b/ci/scripts/imports/badge.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# Copyright 2019 Neovim Project Contributors (https://neovim.io/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Helper functions for getting badges. + +# Get code quality color. +# ${1}: Amount of bugs actually found. +# ${2}: Maximum number of bugs above which color will be red. Defaults to 20. +# ${3}: Maximum number of bugs above which color will be yellow. Defaults to +# $1 / 2. +# Output: 24-bit hexadecimal representation of the color (xxxxxx). +get_code_quality_color() { + bugs=$1 ; shift # shift will fail if there is no argument + max_bugs=${1:-20} + yellow_threshold=${2:-$(( max_bugs / 2 ))} + + red=255 + green=255 + blue=0 + + bugs=$(( bugs < max_bugs ? bugs : max_bugs)) + if test $bugs -ge "$yellow_threshold" ; then + green=$(( 255 - 255 * (bugs - yellow_threshold) / yellow_threshold )) + else + red=$(( 255 * bugs / yellow_threshold )) + fi + + printf "%02x%02x%02x" $red $green $blue +} + +# Get code quality badge. +# ${1}: Amount of bugs actually found. +# ${2}: Badge text. +# ${3}: Directory where to save badge to. +# ${3}: Maximum number of bugs above which color will be red. Defaults to 20. +# ${4}: Maximum number of bugs above which color will be yellow. Defaults to +# $1 / 2. +# Output: 24-bit hexadecimal representation of the color (xxxxxx). +download_badge() { + bugs=$1 ; shift + badge_text="$1" ; shift + reports_dir="$1" ; shift + max_bugs=${1:-20} + yellow_threshold=${2:-$(( max_bugs / 2 ))} + + code_quality_color="$( + get_code_quality_color $bugs $max_bugs $yellow_threshold)" + badge="${badge_text}-${bugs}-${code_quality_color}" + + rm -f "$reports_dir/badge.svg" + + response="$( + curl --tlsv1 "https://img.shields.io/badge/${badge}.svg" \ + -o"$reports_dir/badge.svg" 2>&1)" + + if ! grep -F 'xmlns="http://www.w3.org/2000/svg"' "$reports_dir/badge.svg" ; then + echo "Failed to download badge to $reports_dir: $response" + rm -f "$reports_dir/badge.svg" + fi +} diff --git a/ci/scripts/ssl.conf b/ci/scripts/ssl.conf new file mode 100644 index 00000000..eddfb7f8 --- /dev/null +++ b/ci/scripts/ssl.conf @@ -0,0 +1,23 @@ +[req] +default_bits = 2048 +prompt = no +default_md = sha256 +x509_extensions = v3_req +distinguished_name = dn + + +# Puffy the pufferfish +# https://en.wikipedia.org/wiki/Tetraodontidae +[dn] +C = AZ +ST = Chordata +L = Actinopterygii_Tetraodontiformes +O = Tetraodontoidei_Tetraodontidae +CN = Puffy + +[v3_req] +subjectAltName = @alt_names + +[alt_names] +DNS.1 = puffy.bsd +DNS.2 = puffy.mail diff --git a/compress_backend.c b/compress_backend.c deleted file mode 100644 index 516dd1ee..00000000 --- a/compress_backend.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: compress_backend.c,v 1.9 2015/01/20 17:37:54 deraadt Exp $ */ - -/* - * Copyright (c) 2012 Charles Longeau - * Copyright (c) 2012 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" - -#define BUFFER_SIZE 16364 - -extern struct compress_backend compress_gzip; - -struct compress_backend * -compress_backend_lookup(const char *name) -{ - if (!strcmp(name, "gzip")) - return &compress_gzip; - - return NULL; -} - -size_t -compress_chunk(void *ib, size_t ibsz, void *ob, size_t obsz) -{ - return (env->sc_comp->compress_chunk(ib, ibsz, ob, obsz)); -} - -size_t -uncompress_chunk(void *ib, size_t ibsz, void *ob, size_t obsz) -{ - return (env->sc_comp->uncompress_chunk(ib, ibsz, ob, obsz)); -} - -int -compress_file(FILE *ifile, FILE *ofile) -{ - return (env->sc_comp->compress_file(ifile, ofile)); -} - -int -uncompress_file(FILE *ifile, FILE *ofile) -{ - return (env->sc_comp->uncompress_file(ifile, ofile)); -} diff --git a/compress_gzip.c b/compress_gzip.c deleted file mode 100644 index e7421cec..00000000 --- a/compress_gzip.c +++ /dev/null @@ -1,184 +0,0 @@ -/* $OpenBSD: compress_gzip.c,v 1.10 2015/12/28 22:08:30 jung Exp $ */ - -/* - * Copyright (c) 2012 Gilles Chehade - * Copyright (c) 2012 Charles Longeau - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "smtpd.h" -#include "log.h" - - -#define GZIP_BUFFER_SIZE 16384 - - -static size_t compress_gzip_chunk(void *, size_t, void *, size_t); -static size_t uncompress_gzip_chunk(void *, size_t, void *, size_t); -static int compress_gzip_file(FILE *, FILE *); -static int uncompress_gzip_file(FILE *, FILE *); - - -struct compress_backend compress_gzip = { - compress_gzip_chunk, - uncompress_gzip_chunk, - - compress_gzip_file, - uncompress_gzip_file, -}; - -static size_t -compress_gzip_chunk(void *ib, size_t ibsz, void *ob, size_t obsz) -{ - z_stream *strm; - size_t ret = 0; - - if ((strm = calloc(1, sizeof *strm)) == NULL) - return 0; - - strm->zalloc = Z_NULL; - strm->zfree = Z_NULL; - strm->opaque = Z_NULL; - if (deflateInit2(strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, - (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) - goto end; - - strm->avail_in = ibsz; - strm->next_in = (unsigned char *)ib; - strm->avail_out = obsz; - strm->next_out = (unsigned char *)ob; - if (deflate(strm, Z_FINISH) != Z_STREAM_END) - goto end; - - ret = strm->total_out; - -end: - deflateEnd(strm); - free(strm); - return ret; -} - - -static size_t -uncompress_gzip_chunk(void *ib, size_t ibsz, void *ob, size_t obsz) -{ - z_stream *strm; - size_t ret = 0; - - if ((strm = calloc(1, sizeof *strm)) == NULL) - return 0; - - strm->zalloc = Z_NULL; - strm->zfree = Z_NULL; - strm->opaque = Z_NULL; - strm->avail_in = 0; - strm->next_in = Z_NULL; - - if (inflateInit2(strm, (15+16)) != Z_OK) - goto end; - - strm->avail_in = ibsz; - strm->next_in = (unsigned char *)ib; - strm->avail_out = obsz; - strm->next_out = (unsigned char *)ob; - - if (inflate(strm, Z_FINISH) != Z_STREAM_END) - goto end; - - ret = strm->total_out; - -end: - deflateEnd(strm); - free(strm); - return ret; -} - - -static int -compress_gzip_file(FILE *in, FILE *out) -{ - gzFile gzf; - char ibuf[GZIP_BUFFER_SIZE]; - int r, w; - int ret = 0; - - if (in == NULL || out == NULL) - return (0); - - gzf = gzdopen(fileno(out), "wb"); - if (gzf == NULL) - return (0); - - while ((r = fread(ibuf, 1, GZIP_BUFFER_SIZE, in)) != 0) { - if ((w = gzwrite(gzf, ibuf, r)) != r) - goto end; - } - if (!feof(in)) - goto end; - - ret = 1; - -end: - gzclose(gzf); - return (ret); -} - - -static int -uncompress_gzip_file(FILE *in, FILE *out) -{ - gzFile gzf; - char obuf[GZIP_BUFFER_SIZE]; - int r, w; - int ret = 0; - - if (in == NULL || out == NULL) - return (0); - - gzf = gzdopen(fileno(in), "r"); - if (gzf == NULL) - return (0); - - while ((r = gzread(gzf, obuf, sizeof(obuf))) > 0) { - if ((w = fwrite(obuf, r, 1, out)) != 1) - goto end; - } - if (!gzeof(gzf)) - goto end; - - ret = 1; - -end: - gzclose(gzf); - return (ret); -} diff --git a/config.c b/config.c deleted file mode 100644 index 529420ac..00000000 --- a/config.c +++ /dev/null @@ -1,343 +0,0 @@ -/* $OpenBSD: config.c,v 1.51 2019/12/18 10:00:39 gilles Exp $ */ - -/* - * Copyright (c) 2008 Pierre-Yves Ritschard - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "smtpd.h" -#include "log.h" -#include "ssl.h" - -void set_local(struct smtpd *, const char *); -void set_localaddrs(struct smtpd *, struct table *); - -struct smtpd * -config_default(void) -{ - struct smtpd *conf = NULL; - struct mta_limits *limits = NULL; - struct table *t = NULL; - char hostname[HOST_NAME_MAX+1]; - - if (getmailname(hostname, sizeof hostname) == -1) - return NULL; - - if ((conf = calloc(1, sizeof(*conf))) == NULL) - return conf; - - (void)strlcpy(conf->sc_hostname, hostname, sizeof(conf->sc_hostname)); - - conf->sc_maxsize = DEFAULT_MAX_BODY_SIZE; - conf->sc_subaddressing_delim = SUBADDRESSING_DELIMITER; - conf->sc_ttl = SMTPD_QUEUE_EXPIRY; - conf->sc_srs_ttl = SMTPD_QUEUE_EXPIRY / 86400; - - conf->sc_mta_max_deferred = 100; - conf->sc_scheduler_max_inflight = 5000; - conf->sc_scheduler_max_schedule = 10; - conf->sc_scheduler_max_evp_batch_size = 256; - conf->sc_scheduler_max_msg_batch_size = 1024; - - conf->sc_session_max_rcpt = 1000; - conf->sc_session_max_mails = 100; - - conf->sc_mda_max_session = 50; - conf->sc_mda_max_user_session = 7; - conf->sc_mda_task_hiwat = 50; - conf->sc_mda_task_lowat = 30; - conf->sc_mda_task_release = 10; - - /* Report mails delayed for more than 4 hours */ - conf->sc_bounce_warn[0] = 3600 * 4; - - conf->sc_tables_dict = calloc(1, sizeof(*conf->sc_tables_dict)); - conf->sc_rules = calloc(1, sizeof(*conf->sc_rules)); - conf->sc_dispatchers = calloc(1, sizeof(*conf->sc_dispatchers)); - conf->sc_listeners = calloc(1, sizeof(*conf->sc_listeners)); - conf->sc_ca_dict = calloc(1, sizeof(*conf->sc_ca_dict)); - conf->sc_pki_dict = calloc(1, sizeof(*conf->sc_pki_dict)); - conf->sc_ssl_dict = calloc(1, sizeof(*conf->sc_ssl_dict)); - conf->sc_limits_dict = calloc(1, sizeof(*conf->sc_limits_dict)); - conf->sc_mda_wrappers = calloc(1, sizeof(*conf->sc_mda_wrappers)); - conf->sc_filter_processes_dict = calloc(1, sizeof(*conf->sc_filter_processes_dict)); - conf->sc_dispatcher_bounce = calloc(1, sizeof(*conf->sc_dispatcher_bounce)); - conf->sc_filters_dict = calloc(1, sizeof(*conf->sc_filters_dict)); - limits = calloc(1, sizeof(*limits)); - - if (conf->sc_tables_dict == NULL || - conf->sc_rules == NULL || - conf->sc_dispatchers == NULL || - conf->sc_listeners == NULL || - conf->sc_ca_dict == NULL || - conf->sc_pki_dict == NULL || - conf->sc_ssl_dict == NULL || - conf->sc_limits_dict == NULL || - conf->sc_mda_wrappers == NULL || - conf->sc_filter_processes_dict == NULL || - conf->sc_dispatcher_bounce == NULL || - conf->sc_filters_dict == NULL || - limits == NULL) - goto error; - - dict_init(conf->sc_dispatchers); - dict_init(conf->sc_mda_wrappers); - dict_init(conf->sc_ca_dict); - dict_init(conf->sc_pki_dict); - dict_init(conf->sc_ssl_dict); - dict_init(conf->sc_tables_dict); - dict_init(conf->sc_limits_dict); - dict_init(conf->sc_filter_processes_dict); - - limit_mta_set_defaults(limits); - - dict_xset(conf->sc_limits_dict, "default", limits); - - TAILQ_INIT(conf->sc_listeners); - TAILQ_INIT(conf->sc_rules); - - - /* bounce dispatcher */ - conf->sc_dispatcher_bounce->type = DISPATCHER_BOUNCE; - - /* - * declare special "localhost", "anyhost" and "localnames" tables - */ - set_local(conf, conf->sc_hostname); - - t = table_create(conf, "static", "", NULL); - table_add(t, "*", NULL); - - hostname[strcspn(hostname, ".")] = '\0'; - if (strcmp(conf->sc_hostname, hostname) != 0) - table_add(t, hostname, NULL); - - table_create(conf, "getpwnam", "", NULL); - - return conf; - -error: - free(conf->sc_tables_dict); - free(conf->sc_rules); - free(conf->sc_dispatchers); - free(conf->sc_listeners); - free(conf->sc_ca_dict); - free(conf->sc_pki_dict); - free(conf->sc_ssl_dict); - free(conf->sc_limits_dict); - free(conf->sc_mda_wrappers); - free(conf->sc_filter_processes_dict); - free(conf->sc_dispatcher_bounce); - free(conf->sc_filters_dict); - free(limits); - free(conf); - return NULL; -} - -void -set_local(struct smtpd *conf, const char *hostname) -{ - struct table *t; - - t = table_create(conf, "static", "", NULL); - table_add(t, "localhost", NULL); - table_add(t, hostname, NULL); - - set_localaddrs(conf, t); -} - -void -set_localaddrs(struct smtpd *conf, struct table *localnames) -{ - struct ifaddrs *ifap, *p; - struct sockaddr_storage ss; - struct sockaddr_in *sain; - struct sockaddr_in6 *sin6; - struct table *t; - char buf[NI_MAXHOST + 5]; - - t = table_create(conf, "static", "", NULL); - table_add(t, "local", NULL); - table_add(t, "0.0.0.0/0", NULL); - table_add(t, "::/0", NULL); - - if (getifaddrs(&ifap) == -1) - fatal("getifaddrs"); - - t = table_create(conf, "static", "", NULL); - table_add(t, "local", NULL); - - for (p = ifap; p != NULL; p = p->ifa_next) { - if (p->ifa_addr == NULL) - continue; - switch (p->ifa_addr->sa_family) { - case AF_INET: - sain = (struct sockaddr_in *)&ss; - *sain = *(struct sockaddr_in *)p->ifa_addr; - sain->sin_len = sizeof(struct sockaddr_in); - table_add(t, ss_to_text(&ss), NULL); - table_add(localnames, ss_to_text(&ss), NULL); - (void)snprintf(buf, sizeof buf, "[%s]", ss_to_text(&ss)); - table_add(localnames, buf, NULL); - break; - - case AF_INET6: - sin6 = (struct sockaddr_in6 *)&ss; - *sin6 = *(struct sockaddr_in6 *)p->ifa_addr; - sin6->sin6_len = sizeof(struct sockaddr_in6); - table_add(t, ss_to_text(&ss), NULL); - table_add(localnames, ss_to_text(&ss), NULL); - (void)snprintf(buf, sizeof buf, "[%s]", ss_to_text(&ss)); - table_add(localnames, buf, NULL); - (void)snprintf(buf, sizeof buf, "[ipv6:%s]", ss_to_text(&ss)); - table_add(localnames, buf, NULL); - break; - } - } - - freeifaddrs(ifap); -} - -void -purge_config(uint8_t what) -{ - struct dispatcher *d; - struct listener *l; - struct table *t; - struct rule *r; - struct pki *p; - const char *k; - void *iter_dict; - - if (what & PURGE_LISTENERS) { - while ((l = TAILQ_FIRST(env->sc_listeners)) != NULL) { - TAILQ_REMOVE(env->sc_listeners, l, entry); - free(l); - } - free(env->sc_listeners); - env->sc_listeners = NULL; - } - if (what & PURGE_TABLES) { - while (dict_root(env->sc_tables_dict, NULL, (void **)&t)) - table_destroy(env, t); - free(env->sc_tables_dict); - env->sc_tables_dict = NULL; - } - if (what & PURGE_RULES) { - while ((r = TAILQ_FIRST(env->sc_rules)) != NULL) { - TAILQ_REMOVE(env->sc_rules, r, r_entry); - free(r); - } - free(env->sc_rules); - env->sc_rules = NULL; - } - if (what & PURGE_DISPATCHERS) { - while (dict_poproot(env->sc_dispatchers, (void **)&d)) { - free(d); - } - free(env->sc_dispatchers); - env->sc_dispatchers = NULL; - } - if (what & PURGE_PKI) { - while (dict_poproot(env->sc_pki_dict, (void **)&p)) { - freezero(p->pki_cert, p->pki_cert_len); - freezero(p->pki_key, p->pki_key_len); - EVP_PKEY_free(p->pki_pkey); - free(p); - } - free(env->sc_pki_dict); - env->sc_pki_dict = NULL; - } else if (what & PURGE_PKI_KEYS) { - iter_dict = NULL; - while (dict_iter(env->sc_pki_dict, &iter_dict, &k, - (void **)&p)) { - freezero(p->pki_cert, p->pki_cert_len); - p->pki_cert = NULL; - freezero(p->pki_key, p->pki_key_len); - p->pki_key = NULL; - EVP_PKEY_free(p->pki_pkey); - p->pki_pkey = NULL; - } - } -} - -#ifndef CONFIG_MINIMUM - -void -config_process(enum smtp_proc_type proc) -{ - struct rlimit rl; - - smtpd_process = proc; - setproctitle("%s", proc_title(proc)); - - if (getrlimit(RLIMIT_NOFILE, &rl) == -1) - fatal("fdlimit: getrlimit"); - rl.rlim_cur = rl.rlim_max; - if (setrlimit(RLIMIT_NOFILE, &rl) == -1) - fatal("fdlimit: setrlimit"); -} - -void -config_peer(enum smtp_proc_type proc) -{ - struct mproc *p; - - if (proc == smtpd_process) - fatal("config_peers: cannot peer with oneself"); - - if (proc == PROC_CONTROL) - p = p_control; - else if (proc == PROC_LKA) - p = p_lka; - else if (proc == PROC_PARENT) - p = p_parent; - else if (proc == PROC_QUEUE) - p = p_queue; - else if (proc == PROC_SCHEDULER) - p = p_scheduler; - else if (proc == PROC_PONY) - p = p_pony; - else if (proc == PROC_CA) - p = p_ca; - else - fatalx("bad peer"); - - mproc_enable(p); -} - -#else - -void config_process(enum smtp_proc_type proc) {} -void config_peer(enum smtp_proc_type proc) {} - -#endif diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..33b929c1 --- /dev/null +++ b/configure.ac @@ -0,0 +1,2066 @@ +# $Id: configure.ac,v 1.519 2013/03/22 01:49:15 dtucker Exp $ +# +# Copyright (c) 2016 Gilles Chehade +# Copyright (c) 1999-2004 Damien Miller +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +# +# WE NEED TO CLEANUP CONFIGURE.AC AND MAKE IT FOLLOW THE +# STANDARD LAYOUT ... +# +# 3.1.3 Standard configure.ac Layout +# +# https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Autoconf-Input-Layout.html +# + + +# +# AUTOCONF REQUIREMENTS +# +AC_PREREQ(2.69) + + +# +# AC_INIT +# +AC_INIT([OpenSMTPD], + [portable], + [bugs@opensmtpd.org], + [opensmtpd], + [https://www.OpenSMTPD.org]) + +AM_INIT_AUTOMAKE([subdir-objects no-dependencies]) +LT_INIT + +# here we should test for variables set by libtool detection +if test "x$with_pic" != "xno"; then + CFLAGS="$CFLAGS ${pic_flag}" +fi + + +# +# PACKAGE INFORMATION +# +AC_LANG([C]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_HEADER([config.h]) +AC_PROG_CC +AC_CANONICAL_HOST +AC_C_BIGENDIAN + + +# +# CHECKS FOR PROGRAMS +# +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LIBTOOL +AC_PATH_PROG([AR], [ar]) +AC_PATH_PROG([CAT], [cat]) +AC_PATH_PROG([CHMOD], [chmod]) +AC_PATH_PROG([CHOWN], [chown]) +AC_PATH_PROG([ZCAT], [zcat]) +AC_PATH_PROG([SED], [sed]) +AC_PATH_PROG([TEST_MINUS_S_SH], [bash]) +AC_PATH_PROG([TEST_MINUS_S_SH], [ksh]) +AC_PATH_PROG([TEST_MINUS_S_SH], [sh]) +AC_PATH_PROG([SH], [sh]) +AC_PATH_PROG([GROFF], [groff]) +AC_PATH_PROG([NROFF], [nroff]) +AC_PATH_PROG([MANDOC], [mandoc]) +AC_PROG_YACC + +AC_SUBST([ZCAT]) + + +if test -z "$AR"; then + AC_MSG_ERROR([*** 'ar' missing, please install or fix your \$PATH ***]) +fi + +if test -z "$LD"; then + LD=$CC +fi +AC_SUBST([LD]) + +dnl select manpage formatter +if test -n "$MANDOC"; then + MANFMT="$MANDOC" +elif test -n "$NROFF"; then + MANFMT="$NROFF -mandoc" +elif test -n "$GROFF"; then + MANFMT="$GROFF -mandoc -Tascii" +else + AC_MSG_WARN([no manpage formatted found]) + MANFMT="false" +fi +AC_SUBST([MANFMT]) + + +# +# CHECKS FOR LIBRARIES +# + + + +# +# CHECKS FOR HEADERS +# +AC_CHECK_HEADERS([ \ + arpa/nameser_compat.h \ + crypt.h \ + dirent.h \ + err.h \ + fcntl.h \ + getopt.h \ + grp.h \ + libgen.h \ + limits.h \ + maillock.h \ + mach/mach_time.h \ + ndir.h \ + netdb.h \ + pam/pam_appl.h \ + paths.h \ + security/pam_appl.h \ + shadow.h \ + sys/cdefs.h \ + sys/dir.h \ + sys/file.h \ + sys/mount.h \ + sys/ndir.h \ + sys/pstat.h \ + sys/statfs.h \ + sys/time.h \ + sys/un.h \ + time.h \ + ucred.h \ + util.h \ + vis.h +]) + +AM_CONDITIONAL([NEED_ERR_H], [test x$HAVE_ERR_H = x1]) +AM_CONDITIONAL([SUPPORT_PATHS_H], [test x$HAVE_PATHS_H = x1]) + +# NetBSD requires sys/types.h before login_cap.h +AC_CHECK_HEADERS([login_cap.h], [], [], [ +#include +]) + +# older BSDs need sys/param.h before sys/mount.h +AC_CHECK_HEADERS([sys/mount.h], [], [], [ +#include +]) + +AC_CHECK_HEADERS([bsd/libutil.h libutil.h]) + +AC_CHECK_HEADER([fts.h], + [], + [AC_MSG_ERROR([*** fts.h missing - please install libfts ***])], + [ +#include +#include +]) + +need_libasr=no +AC_CHECK_HEADER([asr.h], + [], + [need_libasr=yes], + [ +#include +#include +#include +]) +AM_CONDITIONAL([NEED_LIBASR], [test x"$need_libasr" = x"yes"]) + +# +# CHECKS FOR TYPES +# +AC_CHECK_TYPES([long long, unsigned long long, long double, u_int, u_char]) +AC_CHECK_SIZEOF([short int], [2]) +AC_CHECK_SIZEOF([int], [4]) +AC_CHECK_SIZEOF([long int], [4]) +AC_CHECK_SIZEOF([long long int], [8]) + +AC_TYPE_INT8_T +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_UINT8_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_INTPTR_T +AC_TYPE_INTMAX_T +AC_TYPE_UINTPTR_T +AC_TYPE_UINTMAX_T +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T +AC_TYPE_OFF_T +AC_TYPE_MODE_T +AC_TYPE_PID_T +AC_TYPE_UID_T + +TYPE_SOCKLEN_T + +AC_CHECK_TYPES([sig_atomic_t], [], [], [ +#include +]) +AC_CHECK_TYPES([fsblkcnt_t, fsfilcnt_t], [], [], [ +#include +#ifdef HAVE_SYS_BITYPES_H +#include +#endif +#ifdef HAVE_SYS_STATFS_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include +#endif +]) + +AC_CHECK_TYPES([in_addr_t, in_port_t], [], [], [ +#include +#include +]) + +AC_CHECK_TYPES([sa_family_t], [], [], [ +#include +#include +#include +]) + +AC_CHECK_TYPES([struct timespec]) +AC_CHECK_TYPES([struct ifgroupreq]) +AC_CHECK_TYPES([struct sockaddr_storage], [], [], [ +#include +#include +]) +AC_CHECK_TYPES([struct sockaddr_in6], [], [], [ +#include +#include +]) +AC_CHECK_TYPES([struct in6_addr], [], [], [ +#include +#include +]) +AC_CHECK_TYPES([struct addrinfo], [], [], [ +#include +#include +#include +]) +AC_CHECK_TYPES([struct timeval], [], [], [ +#include +]) + +AC_CHECK_DECL([LLONG_MAX], [have_llong_max=1], , [#include ]) + + +# +# CHECKS FOR STRUCTURES +# +AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [], [ +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#include +]) + +AC_CHECK_MEMBERS([struct passwd.pw_gecos, struct passwd.pw_class, +struct passwd.pw_change, struct passwd.pw_expire], +[], [], [ +#include +#include +]) + +AC_CHECK_MEMBERS([struct stat.st_flags], , , + [ #include + #include ] +) + +AC_CHECK_MEMBERS([struct stat.st_mtim], , , + [ #include + #include ] +) + +AC_CHECK_MEMBERS([struct stat.st_mtimespec], , , + [ #include + #include ] +) + +AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , + [ #include + #include + #include ] +) + +AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , , + [ #include + #include + #include ] +) + +AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , , + [ #include + #include + #include ] +) + +AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_len], , , + [ #include + #include + #include ] +) + +AC_CHECK_MEMBERS([struct statfs.f_favail], , , + [ #include + #include ] +) + +AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family], [], [], [ +#include +#include +]) + +AC_CHECK_MEMBERS([struct sockaddr_storage.__ss_family], [], [], [ +#include +#include +]) + +AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.tm_zone], [], + [ + AC_CHECK_DECLS([timezone, altzone, tzname], + [], + [ AC_MSG_ERROR([cannot find timezone])], + [ #include ] + ) + ], + [ #include ] +) + +AC_CHECK_MEMBERS([struct DIR.d_type], [], [], [ +#include +#include +]) + +# +# CHECKS FOR DECLARATIONS +# +AC_CHECK_DECLS([O_NONBLOCK], [], [], [ +#include +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif +]) + +AC_CHECK_DECLS([AF_LOCAL, PF_LOCAL], [], [], [ +#include +]) + +AC_CHECK_DECLS([IPPORT_HILASTAUTO], [], [], [ +#include +]) + +AC_CHECK_DECLS([WAIT_MYPGRP], [], [], [ +#include +]) + +AC_CHECK_DECLS([writev], [], [], [ +#include +#include +#include +]) + +AC_CHECK_DECLS([LOG_PERROR], [], [], [ +#include +]) + + +# +# CHECKS FOR COMPILER CHARACTERISTICS +# +AC_C_INLINE + + +AC_ARG_WITH([libs], + [ --with-libs Specify additional libraries to link with], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + LIBS="$LIBS $withval" + fi + ] +) +# +# CHECKS FOR LIBRARY FUNCTIONS +# +AC_SEARCH_LIBS([basename], + [gen], + [ + AC_DEFINE([HAVE_BASENAME], [1], + [Define if you have the basename() function.]) + ]) + +AC_SEARCH_LIBS([closefrom], + [gen], + [ + AC_DEFINE([HAVE_CLOSEFROM], [1], + [Define if you have the closefrom() function.]) + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[int res = closefrom(0);]]) + ], + AC_DEFINE(HAVE_CLOSEFROM_INT, 1, [closefrom return int]) + ) + ]) + +AC_SEARCH_LIBS([fmt_scaled], + [util bsd], + [ + AC_DEFINE([HAVE_FMT_SCALED], [1], + [Define if you have the fmt_scaled() function.]) + ]) + +AC_SEARCH_LIBS([dirname], + [gen], + [ + AC_DEFINE([HAVE_DIRNAME], [1], + [Define if you have the dirname() function.]) + ]) + +AC_SEARCH_LIBS([inet_net_pton], + [resolv bsd], + [ + AC_DEFINE([HAVE_INET_NET_PTON], [1], + [Define if you have the inet_net_pton() function.]) + ]) + +AC_SEARCH_LIBS([clock_gettime], + [rt], + [ + AC_DEFINE([HAVE_CLOCK_GETTIME], [1], + [Define if you have the clock_gettime() function.]) + ]) + +AC_SEARCH_LIBS([fts_open], + [fts], + [ + AC_DEFINE([HAVE_FTS_OPEN], [1], + [Define if you have the fts_open() function.]) + ]) + +AC_SEARCH_LIBS([daemon], + [bsd], + [ + AC_DEFINE([HAVE_DAEMON], [1], + [Define if you have the daemon() function.]) + ]) + +AC_SEARCH_LIBS([fparseln], + [util], + [ + AC_DEFINE([HAVE_FPARSELN], [1], + [Define if you have the fparseln() function.]) + ]) + +AC_SEARCH_LIBS([res_hnok], + [resolv], + [ + AC_DEFINE([HAVE_RES_HNOK], [1], + [Define if you have the res_hnok() function.]) + ]) + +AC_SEARCH_LIBS([res_randomid], + [resolv], + [ + AC_DEFINE([HAVE_RES_RANDOMID], [1], + [Define if you have the res_randomid() function.]) + ]) + +AC_SEARCH_LIBS([res_9_b64_ntop], + [resolv], + [ + AC_DEFINE([HAVE_RES_9_B64_NTOP], [1], + [Define if you have the res_9_b64_ntop() function.]) + ]) + +AC_SEARCH_LIBS([__b64_pton], + [resolv], + [ + AC_DEFINE([HAVE___B64_PTON], [1], + [Define if you have the __b64_pton() function.]) + ]) + +AC_SEARCH_LIBS([b64_pton], + [resolv], + [ + AC_DEFINE([HAVE_B64_PTON], [1], + [Define if you have the b64_pton() function.]) + ]) + +AC_SEARCH_LIBS([__b64_ntop], + [resolv], + [ + AC_DEFINE([HAVE___B64_NTOP], [1], + [Define if you have the b64_ntop() function.]) + ]) + +AC_SEARCH_LIBS([b64_ntop], + [resolv], + [ + AC_DEFINE([HAVE_B64_NTOP], [1], + [Define if you have the b64_ntop() function.]) + ]) + +AC_SEARCH_LIBS([setsockopt], + [socket], + [ + AC_DEFINE([HAVE_SETSOCKOPT], [1], + [Define if you have the setsockopt() function.]) + ]) + +AC_SEARCH_LIBS([crypt], + [crypt], + [ + AC_DEFINE([HAVE_CRYPT], [1], + [Define if you have the crypt() function.]) + ]) + +AC_SEARCH_LIBS([imsg_init], + [util], + [ + AC_DEFINE([HAVE_IMSG], [1], + [Define if you have the imsg framework.]) + ]) + +AC_SEARCH_LIBS([event_asr_run], + [event], + [ + AC_DEFINE([HAVE_EVENT_ASR_RUN], [1], + [Define if you have the event_asr_run() function.]) + ]) + +AC_CHECK_FUNCS([ \ + asprintf \ + arc4random \ + bcopy \ + calloc_conceal \ + chflags \ + crypt_checkpass \ + dirfd \ + err \ + errc \ + errx \ + explicit_bzero \ + fchflags \ + fgetln \ + flock \ + freeaddrinfo \ + freezero \ + getaddrinfo \ + getdtablesize \ + getdtablecount \ + getline \ + getnameinfo \ + gettimeofday \ + getopt \ + getpeereid \ + getpeerucred \ + getspnam \ + inet_aton \ + inet_ntoa \ + inet_ntop \ + malloc_conceal \ + memmove \ + nanosleep \ + nsleep \ + pidfile \ + pledge \ + reallocarray \ + recallocarray \ + res_hnok \ + res_randomid \ + setenv \ + seteuid \ + setegid \ + setproctitle \ + setregid \ + setreuid \ + setresuid \ + setresgid \ + setsid \ + signal \ + sigaction \ + snprintf \ + socketpair \ + strdup \ + strerror \ + strlcat \ + strlcpy \ + strmode \ + strndup \ + strnlen \ + strnvis \ + strtonum \ + sysconf \ + tcgetpgrp \ + time \ + usleep \ + vasprintf \ + vsnprintf \ + waitpid \ + warn \ + warnx \ +]) + +AC_CHECK_DECL([strsep], + [AC_CHECK_FUNCS([strsep])], + [], + [ +#ifdef HAVE_STRING_H +# include +#endif + ]) + + +# These functions might be found in libressl +AC_CHECK_DECLS([strlcat, strlcpy], + [], + [], + []) + +# +# CHECKS FOR SYSTEM SERVICES +# +AC_MSG_CHECKING([for /proc/pid/fd directory]) +if test -d "/proc/$$/fd"; then + AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd]) + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + + +# +# AC_CONFIG_FILES +# + +# +# AC_OUTPUT +# + + +### +### EVERYTHING BELOW MUST BE CLEANED AND MOVED ABOVE +### + +#l150 (without _FORTIFY_SOURCE=2) +if test "$GCC" = "yes" -o "$GCC" = "egcs"; then + OSSH_CHECK_CFLAG_COMPILE([-Qunused-arguments]) + OSSH_CHECK_CFLAG_COMPILE([-Wunknown-warning-option]) + OSSH_CHECK_CFLAG_COMPILE([-Wall]) + OSSH_CHECK_CFLAG_COMPILE([-Wpointer-arith]) + OSSH_CHECK_CFLAG_COMPILE([-Wuninitialized]) + OSSH_CHECK_CFLAG_COMPILE([-Wsign-compare]) + OSSH_CHECK_CFLAG_COMPILE([-Wformat-security]) + OSSH_CHECK_CFLAG_COMPILE([-Wsizeof-pointer-memaccess]) + OSSH_CHECK_CFLAG_COMPILE([-Wpointer-sign], [-Wno-pointer-sign]) + OSSH_CHECK_CFLAG_COMPILE([-Wunused-result], [-Wno-unused-result]) + OSSH_CHECK_CFLAG_COMPILE([-fno-strict-aliasing]) +# OSSH_CHECK_CFLAG_COMPILE([-D_FORTIFY_SOURCE=2]) + if test "x$use_toolchain_hardening" = "x1"; then + OSSH_CHECK_LDFLAG_LINK([-Wl,-z,relro]) + OSSH_CHECK_LDFLAG_LINK([-Wl,-z,now]) + OSSH_CHECK_LDFLAG_LINK([-Wl,-z,noexecstack]) + # NB. -ftrapv expects certain support functions to be present in + # the compiler library (libgcc or similar) to detect integer operations + # that can overflow. We must check that the result of enabling it + # actually links. The test program compiled/linked includes a number + # of integer operations that should exercise this. + OSSH_CHECK_CFLAG_LINK([-ftrapv]) + fi + AC_MSG_CHECKING([gcc version]) + GCC_VER=`$CC -v 2>&1 | $AWK '/gcc version /{print $3}'` + case $GCC_VER in + 1.*) no_attrib_nonnull=1 ;; + 2.8* | 2.9*) + no_attrib_nonnull=1 + ;; + 2.*) no_attrib_nonnull=1 ;; + *) ;; + esac + AC_MSG_RESULT([$GCC_VER]) + + AC_MSG_CHECKING([if $CC accepts -fno-builtin-memset]) + saved_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fno-builtin-memset" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ char b[10]; memset(b, 0, sizeof(b)); ]])], + [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_RESULT([no]) + CFLAGS="$saved_CFLAGS" ] + ) + + # -fstack-protector-all doesn't always work for some GCC versions + # and/or platforms, so we test if we can. If it's not supported + # on a given platform gcc will emit a warning so we use -Werror. + if test "x$use_stack_protector" = "x1"; then + for t in -fstack-protector-strong -fstack-protector-all \ + -fstack-protector; do + AC_MSG_CHECKING([if $CC supports $t]) + saved_CFLAGS="$CFLAGS" + saved_LDFLAGS="$LDFLAGS" + CFLAGS="$CFLAGS $t -Werror" + LDFLAGS="$LDFLAGS $t -Werror" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ #include ]], + [[ + char x[256]; + snprintf(x, sizeof(x), "XXX"); + ]])], + [ AC_MSG_RESULT([yes]) + CFLAGS="$saved_CFLAGS $t" + LDFLAGS="$saved_LDFLAGS $t" + AC_MSG_CHECKING([if $t works]) + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ #include ]], + [[ + char x[256]; + snprintf(x, sizeof(x), "XXX"); + ]])], + [ AC_MSG_RESULT([yes]) + break ], + [ AC_MSG_RESULT([no]) ], + [ AC_MSG_WARN([cross compiling: cannot test]) + break ] + ) + ], + [ AC_MSG_RESULT([no]) ] + ) + CFLAGS="$saved_CFLAGS" + LDFLAGS="$saved_LDFLAGS" + done + fi + + if test -z "$have_llong_max"; then + # retry LLONG_MAX with -std=gnu99, needed on some Linuxes + unset ac_cv_have_decl_LLONG_MAX + saved_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -std=gnu99" + AC_CHECK_DECL([LLONG_MAX], + [have_llong_max=1], + [CFLAGS="$saved_CFLAGS"], + [#include ] + ) + fi +fi + +AC_MSG_CHECKING([if compiler allows __attribute__ on return types]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ +#include +__attribute__((__unused__)) static void foo(void){return;}]], + [[ exit(0); ]])], + [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_RESULT([no]) + AC_DEFINE(NO_ATTRIBUTE_ON_RETURN_TYPE, 1, + [compiler does not accept __attribute__ on return types]) ] +) + +if test "x$no_attrib_nonnull" != "x1"; then + AC_DEFINE([HAVE_ATTRIBUTE__NONNULL__], [1], [Have attribute nonnull]) +fi + +AC_ARG_WITH([rpath], + [ --without-rpath Disable auto-added -R linker paths], + [ + if test "x$withval" = "xno"; then + need_dash_r="" + fi + if test "x$withval" = "xyes"; then + need_dash_r=1 + fi + ] +) + + +AC_ARG_WITH([cflags], + [ --with-cflags Specify additional flags to pass to compiler], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + CFLAGS="$CFLAGS $withval" + fi + ] +) +AC_ARG_WITH([cppflags], + [ --with-cppflags Specify additional flags to pass to preprocessor] , + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + CPPFLAGS="$CPPFLAGS $withval" + fi + ] +) +AC_ARG_WITH([ldflags], + [ --with-ldflags Specify additional flags to pass to linker], + [ + if test -n "$withval" -a "$withval" != "xno" -a "${withval}" != "yes"; then + LDFLAGS="$LDFLAGS $withval" + fi + ] +) +AC_ARG_WITH([Werror], + [ --with-Werror Build main code with -Werror], + [ + if test -n "$withval" -a "$withval" != "no"; then + werror_flags="-Werror" + if test "${withval}" != "yes"; then + werror_flags="$withval" + fi + fi + ] +) + + + +AC_ARG_WITH([pie], + [ --with-pie Build Position Independent Executables if possible], [ + if test "x$withval" = "xno"; then + use_pie=no + fi + if test "x$withval" = "xyes"; then + use_pie=yes + fi + ] +) +if test -z "$use_pie"; then + use_pie=no +fi +if test "x$use_toolchain_hardening" != "x1" -a "x$use_pie" = "xauto"; then + # Turn off automatic PIE when toolchain hardening is off. + use_pie=no +fi +if test "x$use_pie" = "xauto"; then + # Automatic PIE requires gcc >= 4.x + AC_MSG_CHECKING([for gcc >= 4.x]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#if !defined(__GNUC__) || __GNUC__ < 4 +#error gcc is too old +#endif +]])], + [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_RESULT([no]) + use_pie=no ] +) +fi +if test "x$use_pie" != "xno"; then + SAVED_CFLAGS="$CFLAGS" + SAVED_LDFLAGS="$LDFLAGS" + OSSH_CHECK_CFLAG_COMPILE([-fPIE]) + OSSH_CHECK_LDFLAG_LINK([-pie]) + # We use both -fPIE and -pie or neither. + AC_MSG_CHECKING([whether both -fPIE and -pie are supported]) + if echo "x $CFLAGS" | grep ' -fPIE' >/dev/null 2>&1 && \ + echo "x $LDFLAGS" | grep ' -pie' >/dev/null 2>&1 ; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + CFLAGS="$SAVED_CFLAGS" + LDFLAGS="$SAVED_LDFLAGS" + fi +fi + + + + + + +#l432 (customized) +# Check for some target-specific stuff + +case "$host" in +*-*-darwin*) + use_pie=auto + AC_MSG_CHECKING([if we have working getaddrinfo]) + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +#include +#include +main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16)) + exit(0); + else + exit(1); +} + ]])], + [AC_MSG_RESULT([working])], + [AC_MSG_RESULT([buggy]) + AC_DEFINE([BROKEN_GETADDRINFO], [1], + [getaddrinfo is broken (if present)]) + ], + [AC_MSG_RESULT([assume it is working])]) + AC_DEFINE([SETEUID_BREAKS_SETUID], [1], [define if seteuid breaks setuid]) + AC_DEFINE([BROKEN_SETREUID], [1], [define if setreuid is broken]) + AC_DEFINE([BROKEN_SETREGID], [1], [define if setregid is broken]) + AC_DEFINE([BROKEN_GLOB], [1], [OS X glob does not do what we expect]) + AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV], + [Define to a Set Process Title type if your system is + supported by bsd-setproctitle.c]) + AC_DEFINE([BROKEN_STRNVIS], [1], + [OSX strnvis argument order is swapped compared to OpenBSD]) + BROKEN_STRNVIS=1 + ;; +*-*-dragonfly*) + ;; +*-*-linux* | *-gnu* | *-k*bsd*-gnu* ) + use_pie=auto + CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE" + AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV]) + ;; +*-*-netbsd*) + if test "x$withval" != "xno"; then + need_dash_r=1 + fi + AC_DEFINE([BROKEN_STRNVIS], [1], + [NetBSD strnvis argument order is swapped compared to OpenBSD]) + BROKEN_STRNVIS=1 + ;; +*-*-freebsd*) + AC_DEFINE([BROKEN_GLOB], [1], [FreeBSD glob does not do what we need]) + AC_DEFINE([BROKEN_STRNVIS], [1], + [FreeBSD strnvis argument order is swapped compared to OpenBSD]) + BROKEN_STRNVIS=1 + ;; +*-*-openbsd*) + use_pie=auto + AC_DEFINE([HAVE_ATTRIBUTE__SENTINEL__], [1], [OpenBSD's gcc has sentinel]) + AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD's gcc has bounded]) + + AC_DEFINE([BROKEN_STRNVIS], [0], + [FreeBSD strnvis argument order is swapped compared to OpenBSD]) + BROKEN_STRNVIS=0 + YACC='yacc' + ASR_LIB= + AC_DEFINE([NOOP_ASR_FREEADDRINFO], [0], [OpenBSD doesn't need ASR_FREEADDRINFO]) + ;; +*-sun-solaris*) + AC_DEFINE([HAVE_M_DATA], [1], [M_DATA is defined in sys/stream.h included by netinet/in.h]) + ;; +esac +AC_SUBST([ASR_LIB]) + + +AC_MSG_CHECKING([compiler and flags for sanity]) +AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#include ]], [[ exit(0); ]])], + [ AC_MSG_RESULT([yes]) ], + [ + AC_MSG_RESULT([no]) + AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***]) + ], + [ AC_MSG_WARN([cross compiling: not checking compiler sanity]) ] +) + + + +#l1747 + + + + +# Check for missing getpeereid (or equiv) support +NO_PEERCHECK="" +if test "x$ac_cv_func_getpeereid" != "xyes" -a "x$ac_cv_func_getpeerucred" != "xyes"; then + AC_MSG_CHECKING([whether system supports SO_PEERCRED getsockopt]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include ]], [[int i = SO_PEERCRED;]])], + [ AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_SO_PEERCRED], [1], [Have PEERCRED socket option]) + ], [AC_MSG_RESULT([no]) + NO_PEERCHECK=1 + ]) +fi + +#l4176 (customized s/ssh.1/smtpd/smtpd.8/) +# Options from here on. Some of these are preset by platform above +AC_ARG_WITH([mantype], + [ --with-mantype=man|cat|doc Set man page type], + [ + case "$withval" in + man|cat|doc) + MANTYPE=$withval + ;; + *) + AC_MSG_ERROR([invalid man type: $withval]) + ;; + esac + ] +) +if test -z "$MANTYPE"; then + TestPath="/usr/bin${PATH_SEPARATOR}/usr/ucb" + AC_PATH_PROGS([NROFF], [nroff awf], [/bin/false], [$TestPath]) + if ${NROFF} -mdoc ${srcdir}/smtpd/smtpd.8 >/dev/null 2>&1; then + MANTYPE=doc + elif ${NROFF} -man ${srcdir}/smtpd/smtpd.8 >/dev/null 2>&1; then + MANTYPE=man + else + MANTYPE=cat + fi +fi +AC_SUBST([MANTYPE]) +if test "$MANTYPE" = "doc"; then + mansubdir=man; +else + mansubdir=$MANTYPE; +fi +AC_SUBST([mansubdir]) +#l4207 + + +#l4432 (customized s/pid/sock/) +# Whether to enable BSD auth support +BSD_AUTH_MSG=no +AC_ARG_WITH([auth-bsdauth], + [ --with-auth-bsdauth Enable bsd_auth(3) authentication support], + [ + if test "x$withval" != "xno"; then + AC_DEFINE([BSD_AUTH], [1], + [Define if you have BSD auth support]) + BSD_AUTH_MSG=yes + fi + ] +) + + +#l2757 +# Check for PAM libs +PAM_MSG="no" +USE_PAM_SERVICE=smtpd +AC_ARG_WITH([auth-pam], + [ --with-auth-pam=SERVICE Enable PAM authentication support (default=smtpd)], + [ + if test "x$withval" != "xno"; then + if test -n "$withval" -a "x${withval}" != "xyes"; then + USE_PAM_SERVICE=$withval + fi + + if test "x$ac_cv_header_security_pam_appl_h" != "xyes" -a \ + test "x$ac_cv_header_pam_pam_appl_h" != "xyes"; then + AC_MSG_ERROR([PAM headers not found]) + fi + + saved_LIBS="$LIBS" + AC_CHECK_LIB([dl], [dlopen], , ) + AC_CHECK_LIB([pam], [pam_set_item], , [AC_MSG_ERROR([*** libpam missing])]) + AC_CHECK_FUNCS([pam_getenvlist]) + AC_CHECK_FUNCS([pam_putenv]) + LIBS="$saved_LIBS" + + PAM_MSG="yes" + + SMTPDLIBS="$SMTPDLIBS -lpam" + AC_DEFINE([USE_PAM], [1], + [Define if you want to enable PAM support]) + + if test "x$ac_cv_lib_dl_dlopen" = "xyes"; then + case "$LIBS" in + *-ldl*) + # libdl already in LIBS + ;; + *) + SMTPDLIBS="$SMTPDLIBS -ldl" + ;; + esac + fi + fi + ] +) +AC_DEFINE_UNQUOTED([USE_PAM_SERVICE], ["$USE_PAM_SERVICE"], [pam service]) +AC_SUBST([USE_PAM_SERVICE]) + + +# Check for older PAM +if test "x$PAM_MSG" = "xyes"; then + # Check PAM strerror arguments (old PAM) + AC_MSG_CHECKING([whether pam_strerror takes only one argument]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#if defined(HAVE_SECURITY_PAM_APPL_H) +#include +#elif defined (HAVE_PAM_PAM_APPL_H) +#include +#endif + ]], [[ +(void)pam_strerror((pam_handle_t *)NULL, -1); + ]])], [AC_MSG_RESULT([no])], [ + AC_DEFINE([HAVE_OLD_PAM], [1], + [Define if you have an old version of PAM + which takes only one argument to pam_strerror]) + AC_MSG_RESULT([yes]) + PAM_MSG="yes (old library)" + + ]) +fi +#l2816 + + +##gilles + +SMTPD_USER=_smtpd +AC_ARG_WITH([user-smtpd], + [ --with-user-smtpd=user Specify non-privileged user for smtpd (default=_smtpd)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + SMTPD_USER=$withval + fi + ] +) +AC_DEFINE_UNQUOTED([SMTPD_USER], ["$SMTPD_USER"], + [non-privileged user for privilege separation]) +AC_SUBST([SMTPD_USER]) + +SMTPD_QUEUE_USER=_smtpq +AC_ARG_WITH([user-queue], + [ --with-user-queue=user Specify non-privileged user for queue process (default=_smtpq)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + SMTPD_QUEUE_USER=$withval + fi + ] +) +AC_DEFINE_UNQUOTED([SMTPD_QUEUE_USER], ["$SMTPD_QUEUE_USER"], + [non-privileged user for queue process]) +AC_SUBST([SMTPD_QUEUE_USER]) + +SMTPD_QUEUE_GROUP=_smtpq +AC_ARG_WITH([group-queue], + [ --with-group-queue=group Specify non-privileged group for offline queue (default=_smtpq)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + SMTPD_QUEUE_GROUP=$withval + fi + ] +) +AC_DEFINE_UNQUOTED([SMTPD_QUEUE_GROUP], ["$SMTPD_QUEUE_GROUP"], + [non-privileged group for queue process]) +AC_SUBST([SMTPD_QUEUE_GROUP]) + +# Where to place spooler +spooldir=/var/spool/smtpd +AC_ARG_WITH([path-queue], + [ --with-path-queue=PATH Specify path to queue directory (default=/var/spool/smtpd)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + spooldir=$withval + if test ! -d $spooldir; then + AC_MSG_WARN([** no $spooldir directory on this system **]) + fi + fi + ] +) + +AC_DEFINE_UNQUOTED([PATH_SPOOL], ["$spooldir"], + [Specify location of spooler]) +AC_SUBST([spooldir]) + + +PRIVSEP_PATH=/var/empty +AC_ARG_WITH([path-empty], + [ --with-path-empty=PATH Specify path to empty directory (default=/var/empty)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + PRIVSEP_PATH=$withval + fi + ] +) +AC_SUBST([PRIVSEP_PATH]) +#l4022 + +#l4066 +dnl # --with-maildir=/path/to/mail gets top priority. +dnl # if maildir is set in the platform case statement above we use that. +dnl # Otherwise we run a program to get the dir from system headers. +dnl # We first look for _PATH_MAILDIR then MAILDIR then _PATH_MAIL +dnl # If we find _PATH_MAILDIR we do nothing because that is what +dnl # session.c expects anyway. Otherwise we set to the value found +dnl # stripping any trailing slash. If for some strage reason our program +dnl # does not find what it needs, we default to /var/spool/mail. +# Check for mail directory +AC_ARG_WITH([path-mbox], + [ --with-path-mbox=PATH Specify path to mbox directory (default=/var/spool/mail)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["$withval"], + [Set this to your mail directory if you do not have _PATH_MAILDIR]) + fi + ],[ + if test -n "$maildir"; then + AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["$maildir"]) + else + AC_MSG_CHECKING([system mail directory]) + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ +#include +#include +#include +#ifdef HAVE_PATHS_H +#include +#endif +#ifdef HAVE_MAILLOCK_H +#include +#endif +#define DATA "conftest.maildir" + ]], [[ + FILE *fd; + int rc; + + fd = fopen(DATA,"w"); + if(fd == NULL) + exit(1); + +#if defined (_PATH_MAILDIR) + if ((rc = fprintf(fd ,"_PATH_MAILDIR:%s\n", _PATH_MAILDIR)) <0) + exit(1); +#elif defined (MAILDIR) + if ((rc = fprintf(fd ,"MAILDIR:%s\n", MAILDIR)) <0) + exit(1); +#elif defined (_PATH_MAIL) + if ((rc = fprintf(fd ,"_PATH_MAIL:%s\n", _PATH_MAIL)) <0) + exit(1); +#else + exit (2); +#endif + + exit(0); + ]])], + [ + maildir_what=`awk -F: '{print $1}' conftest.maildir` + maildir=`awk -F: '{print $2}' conftest.maildir \ + | sed 's|/$||'` + AC_MSG_RESULT([$maildir from $maildir_what]) + if test "x$maildir_what" != "x_PATH_MAILDIR"; then + AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["$maildir"]) + fi + ], + [ + if test "X$ac_status" = "X2"; then +# our test program didn't find it. Default to /var/spool/mail + AC_MSG_RESULT([/var/spool/mail]) + AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["/var/spool/mail"]) + else + AC_MSG_RESULT([*** not found ***]) + fi + ], + [ + AC_MSG_WARN([cross compiling: use --with-maildir=/path/to/mail]) + ] + ) + fi + ] +) # maildir +#l4146 + +# Where to place smtpd.sock +sockdir=/var/run +# make sure the directory exists +if test ! -d $sockdir; then + sockdir=`eval echo ${sysconfdir}` + case $sockdir in + NONE/*) sockdir=`echo $sockdir | sed "s~NONE~$ac_default_prefix~"` ;; + esac +fi + +AC_ARG_WITH([path-socket], + [ --with-path-socket=PATH Specify path to smtpd.sock directory (default=/var/run)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + sockdir=$withval + if test ! -d $sockdir; then + AC_MSG_WARN([** no $sockdir directory on this system **]) + fi + fi + ] +) + +AC_DEFINE_UNQUOTED([SMTPD_SOCKDIR], ["$sockdir"], + [Specify location of smtpd.sock]) +AC_SUBST([sockdir]) +#l4470 + +# Where to place smtpd.pid +piddir=/var/run +AC_MSG_CHECKING([system pid directory]) +AC_RUN_IFELSE( + [ + AC_LANG_PROGRAM([[ +#include +#include +#ifdef HAVE_PATHS_H +#include +#endif +#define DATA "conftest.piddir" + ]], + [[ +#ifdef _PATH_VARRUN +FILE *fd; +int rc; + +if ((fd = fopen(DATA,"w")) == NULL) { exit(1); } +if ((rc = fprintf(fd ,"%s\n", _PATH_VARRUN)) < 0) { exit(2); } +exit(0); +#else +exit(-1); +#endif + ]]) + ], [ + piddir=`cat conftest.piddir` + AC_MSG_RESULT([$piddir from paths.h]) + ], + [ + AC_MSG_RESULT([$piddir from default value]) + ], + [ + AC_MSG_RESULT([$piddir from default value]) + ] +) + +AC_ARG_WITH([path-pidfile], + [ --with-path-pidfile=PATH Specify path to smtpd.pid directory (default=/var/run)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + piddir=$withval + fi + ] +) + +AC_DEFINE_UNQUOTED([SMTPD_PIDDIR], ["$piddir"], [Specify location of smtpd.pid]) +AC_SUBST([piddir]) + +CA_FILE=/etc/ssl/cert.pem +AC_ARG_WITH([path-CAfile], + [ --with-path-CAfile=FILE Specify path to CA certificate (default=/etc/ssl/cert.pem)], + [ + if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then + CA_FILE=$withval + fi + ] +) +AC_SUBST([CA_FILE]) + + + + + + +# compute LLONG_MIN and LLONG_MAX if we don't know them. +if test -z "$have_llong_max"; then + AC_MSG_CHECKING([for max value of long long]) + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ +#include +#include +/* Why is this so damn hard? */ +#ifdef __GNUC__ +# undef __GNUC__ +#endif +#define __USE_ISOC99 +#include +#define DATA "conftest.llminmax" +#define my_abs(a) ((a) < 0 ? ((a) * -1) : (a)) + +/* + * printf in libc on some platforms (eg old Tru64) does not understand %lld so + * we do this the hard way. + */ +static int +fprint_ll(FILE *f, long long n) +{ + unsigned int i; + int l[sizeof(long long) * 8]; + + if (n < 0) + if (fprintf(f, "-") < 0) + return -1; + for (i = 0; n != 0; i++) { + l[i] = my_abs(n % 10); + n /= 10; + } + do { + if (fprintf(f, "%d", l[--i]) < 0) + return -1; + } while (i != 0); + if (fprintf(f, " ") < 0) + return -1; + return 0; +} + ]], [[ + FILE *f; + long long i, llmin, llmax = 0; + + if((f = fopen(DATA,"w")) == NULL) + exit(1); + +#if defined(LLONG_MIN) && defined(LLONG_MAX) + fprintf(stderr, "Using system header for LLONG_MIN and LLONG_MAX\n"); + llmin = LLONG_MIN; + llmax = LLONG_MAX; +#else + fprintf(stderr, "Calculating LLONG_MIN and LLONG_MAX\n"); + /* This will work on one's complement and two's complement */ + for (i = 1; i > llmax; i <<= 1, i++) + llmax = i; + llmin = llmax + 1LL; /* wrap */ +#endif + + /* Sanity check */ + if (llmin + 1 < llmin || llmin - 1 < llmin || llmax + 1 > llmax + || llmax - 1 > llmax || llmin == llmax || llmin == 0 + || llmax == 0 || llmax < LONG_MAX || llmin > LONG_MIN) { + fprintf(f, "unknown unknown\n"); + exit(2); + } + + if (fprint_ll(f, llmin) < 0) + exit(3); + if (fprint_ll(f, llmax) < 0) + exit(4); + if (fclose(f) < 0) + exit(5); + exit(0); + ]])], + [ + llong_min=`$AWK '{print $1}' conftest.llminmax` + llong_max=`$AWK '{print $2}' conftest.llminmax` + + AC_MSG_RESULT([$llong_max]) + AC_DEFINE_UNQUOTED([LLONG_MAX], [${llong_max}LL], + [max value of long long calculated by configure]) + AC_MSG_CHECKING([for min value of long long]) + AC_MSG_RESULT([$llong_min]) + AC_DEFINE_UNQUOTED([LLONG_MIN], [${llong_min}LL], + [min value of long long calculated by configure]) + ], + [ + AC_MSG_RESULT([not found]) + ], + [ + AC_MSG_WARN([cross compiling: not checking]) + ] + ) +fi + + + + + +#l3561 + + +dnl make sure we're using the real structure members and not defines +AC_CACHE_CHECK([for msg_accrights field in struct msghdr], + ac_cv_have_accrights_in_msghdr, [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#include +#include + ]], [[ +#ifdef msg_accrights +#error "msg_accrights is a macro" +exit(1); +#endif +struct msghdr m; +m.msg_accrights = 0; +exit(0); + ]])], + [ ac_cv_have_accrights_in_msghdr="yes" ], + [ ac_cv_have_accrights_in_msghdr="no" ] + ) +]) +if test "x$ac_cv_have_accrights_in_msghdr" = "xyes"; then + AC_DEFINE([HAVE_ACCRIGHTS_IN_MSGHDR], [1], + [Define if your system uses access rights style + file descriptor passing]) +fi + + +AC_CACHE_CHECK([for msg_control field in struct msghdr], + ac_cv_have_control_in_msghdr, [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#include +#include + ]], [[ +#ifdef msg_control +#error "msg_control is a macro" +exit(1); +#endif +struct msghdr m; +m.msg_control = 0; +exit(0); + ]])], + [ ac_cv_have_control_in_msghdr="yes" ], + [ ac_cv_have_control_in_msghdr="no" ] + ) +]) +if test "x$ac_cv_have_control_in_msghdr" = "xyes"; then + AC_DEFINE([HAVE_CONTROL_IN_MSGHDR], [1], + [Define if your system uses ancillary data style + file descriptor passing]) +fi + +AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ extern char *__progname; printf("%s", __progname); ]])], + [ ac_cv_libc_defines___progname="yes" ], + [ ac_cv_libc_defines___progname="no" + ]) +]) +if test "x$ac_cv_libc_defines___progname" = "xyes"; then + AC_DEFINE([HAVE___PROGNAME], [1], [Define if libc defines __progname]) +fi + +AC_CACHE_CHECK([whether $CC implements __FUNCTION__], ac_cv_cc_implements___FUNCTION__, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ printf("%s", __FUNCTION__); ]])], + [ ac_cv_cc_implements___FUNCTION__="yes" ], + [ ac_cv_cc_implements___FUNCTION__="no" + ]) +]) +if test "x$ac_cv_cc_implements___FUNCTION__" = "xyes"; then + AC_DEFINE([HAVE___FUNCTION__], [1], + [Define if compiler implements __FUNCTION__]) +fi + +AC_CACHE_CHECK([whether $CC implements __func__], ac_cv_cc_implements___func__, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ printf("%s", __func__); ]])], + [ ac_cv_cc_implements___func__="yes" ], + [ ac_cv_cc_implements___func__="no" + ]) +]) +if test "x$ac_cv_cc_implements___func__" = "xyes"; then + AC_DEFINE([HAVE___func__], [1], [Define if compiler implements __func__]) +fi + +AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include +va_list x,y; + ]], [[ va_copy(x,y); ]])], + [ ac_cv_have_va_copy="yes" ], + [ ac_cv_have_va_copy="no" + ]) +]) +if test "x$ac_cv_have_va_copy" = "xyes"; then + AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists]) +fi + +AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include +va_list x,y; + ]], [[ __va_copy(x,y); ]])], + [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no" + ]) +]) +if test "x$ac_cv_have___va_copy" = "xyes"; then + AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists]) +fi + +AC_CACHE_CHECK([whether getopt has optreset support], + ac_cv_have_getopt_optreset, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ extern int optreset; optreset = 0; ]])], + [ ac_cv_have_getopt_optreset="yes" ], + [ ac_cv_have_getopt_optreset="no" + ]) +]) +if test "x$ac_cv_have_getopt_optreset" = "xyes"; then + AC_DEFINE([HAVE_GETOPT_OPTRESET], [1], + [Define if your getopt(3) defines and uses optreset]) +fi +#l3765 + + + + +#l4045 +STRIP_OPT=-s +AC_ARG_ENABLE([strip], + [ --disable-strip Disable calling strip(1) on install], + [ + if test "x$enableval" = "xno"; then + STRIP_OPT= + fi + ] +) +AC_SUBST([STRIP_OPT]) +#l4054 + + + +case "$host" in +*-*-openbsd*) + pkglibexecdir="$libexecdir/smtpd" + ;; +*) + pkglibexecdir="$libexecdir/opensmtpd" + ;; +esac +AC_SUBST([pkglibexecdir]) + + + + + + + + + +#l4742 +dnl Adding -Werror to CFLAGS early prevents configure tests from running. +dnl Add now. +CFLAGS="$CFLAGS $werror_flags" + +AC_SUBST([TEST_MALLOC_OPTIONS], [$TEST_MALLOC_OPTIONS]) + + +AC_EXEEXT +#l4757 + + +# Search for fts +AC_ARG_WITH([libfts], + [ --with-libfts=PATH Specify path to libfts installation (default: none, part of libc)], + [ if test "x$withval" = "xno"; then + AC_MSG_ERROR([*** fts is required ***]) + elif test "x$withval" != "xyes"; then + if test -d "$withval/lib"; then + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" + else + LDFLAGS="-L${withval}/lib ${LDFLAGS}" + fi + else + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" + else + LDFLAGS="-L${withval} ${LDFLAGS}" + fi + fi + if test -d "$withval/include"; then + CPPFLAGS="-I${withval}/include ${CPPFLAGS}" + else + CPPFLAGS="-I${withval} ${CPPFLAGS}" + fi + LIBS="-lfts $LIBS" + fi + ] +) + + + +##chl (based on OpenSSL checks, see above) +# Search for libevent +saved_CPPFLAGS="$CPPFLAGS" +saved_LDFLAGS="$LDFLAGS" +AC_ARG_WITH([libevent], + [ --with-libevent=PATH Specify path to libevent installation ], + [ + if test "x$withval" != "xno"; then + case "$withval" in + # Relative paths + ./*|../*) withval="`pwd`/$withval" + esac + if test -d "$withval/lib"; then + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" + else + LDFLAGS="-L${withval}/lib ${LDFLAGS}" + fi + elif test -d "$withval/lib64"; then + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval}/lib64 -R${withval}/lib64 ${LDFLAGS}" + else + LDFLAGS="-L${withval}/lib64 ${LDFLAGS}" + fi + else + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" + else + LDFLAGS="-L${withval} ${LDFLAGS}" + fi + fi + if test -d "$withval/include"; then + CPPFLAGS="-I${withval}/include ${CPPFLAGS}" + else + CPPFLAGS="-I${withval} ${CPPFLAGS}" + fi + need_libevent_autodetect=no + fi + ] +) + +if test "x${need_libevent_autodetect}" != "xno"; then + for path in /usr/local /usr; do + if test -f "${path}/include/event.h"; then + CPPFLAGS="-I${path}/include ${CPPFLAGS}" + LDFLAGS="-L${path}/lib ${LDFLAGS}" + fi + done +fi + +AC_CHECK_HEADER([event.h], ,[AC_MSG_ERROR([*** event.h missing - please install libevent ***])], +[#include ]) +LIBS="-levent $LIBS" +AC_MSG_CHECKING([if programs using libevent functions will link]) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ + #include + ]], [[ + event_base_new(); + ]])], + [ + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + ] +) + + +#l2174 (customized, bu adding -lssl to LIBS) +# Search for OpenSSL +saved_CPPFLAGS="$CPPFLAGS" +saved_LDFLAGS="$LDFLAGS" +AC_ARG_WITH([libssl], + [ --with-libssl=PATH Specify path to libssl installation ], + [ + if test "x$withval" != "xno"; then + case "$withval" in + # Relative paths + ./*|../*) withval="`pwd`/$withval" + esac + if test -d "$withval/lib"; then + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" + else + LDFLAGS="-L${withval}/lib ${LDFLAGS}" + fi + elif test -d "$withval/lib64"; then + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval}/lib64 -R${withval}/lib64 ${LDFLAGS}" + else + LDFLAGS="-L${withval}/lib64 ${LDFLAGS}" + fi + else + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" + else + LDFLAGS="-L${withval} ${LDFLAGS}" + fi + fi + if test -d "$withval/include"; then + CPPFLAGS="-I${withval}/include ${CPPFLAGS}" + else + CPPFLAGS="-I${withval} ${CPPFLAGS}" + fi + fi + ] +) +## XXX chl -lssl manually added +LIBS="-lcrypto -lssl $LIBS" +AC_TRY_LINK_FUNC([RAND_add], [AC_DEFINE([HAVE_OPENSSL], [1], + [Define if your ssl headers are included + with #include ])], + [ + dnl Check default openssl install dir + if test -n "${need_dash_r}"; then + LDFLAGS="-L/usr/local/ssl/lib -R/usr/local/ssl/lib ${saved_LDFLAGS}" + else + LDFLAGS="-L/usr/local/ssl/lib ${saved_LDFLAGS}" + fi + CPPFLAGS="-I/usr/local/ssl/include ${saved_CPPFLAGS}" + AC_CHECK_HEADER([openssl/opensslv.h], , + [AC_MSG_ERROR([*** LibreSSL headers missing - please install first or check config.log ***])]) + AC_TRY_LINK_FUNC([RAND_add], [AC_DEFINE([HAVE_OPENSSL])], + [ + AC_MSG_ERROR([*** Can't find recent LibreSSL libcrypto (see config.log for details) ***]) + ] + ) + ] +) + + +LIBS="-lcrypto -lssl $LIBS" +AC_MSG_CHECKING([whether SSL_CTX_use_certificate_chain_mem is available]) +AC_TRY_LINK_FUNC([SSL_CTX_use_certificate_chain_mem], + [ + AC_DEFINE([HAVE_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM], [1], + [Define if SSL_CTX_use_certificate_chain_mem exists in libssl]) + AC_MSG_RESULT([yes]) + ], + [ AC_MSG_RESULT([no])] +) + +LIBS="-lcrypto -lssl $LIBS" +AC_MSG_CHECKING([whether ECDSA is available]) +AC_TRY_LINK_FUNC([ENGINE_get_ECDSA], + [ + AC_DEFINE([SUPPORT_ECDSA], [1], + [Define if ECDSA is supported]) + AC_MSG_RESULT([yes]) + ], + [ AC_MSG_RESULT([no])] +) + +# Sanity check OpenSSL headers +AC_MSG_CHECKING([whether LibreSSL's headers match the library]) +AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[ +#include +#include +#include +#include + ]], [[ + exit(SSLeay() == OPENSSL_VERSION_NUMBER ? 0 : 1); + ]])], + [ + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + AC_MSG_ERROR([Your LibreSSL headers do not match your library.]) + ], + [ + AC_MSG_WARN([cross compiling: not checking]) + ] +) + +AC_MSG_CHECKING([if programs using LibreSSL functions will link]) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ #include ]], + [[ SSLeay_add_all_algorithms(); ]])], + [ + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + saved_LIBS="$LIBS" + LIBS="$LIBS -ldl" + AC_MSG_CHECKING([if programs using LibreSSL need -ldl]) + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ #include ]], + [[ SSLeay_add_all_algorithms(); ]])], + [ + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + LIBS="$saved_LIBS" + ] + ) + ] +) + +AC_CHECK_DECL([LIBRESSL_VERSION_NUMBER], , , [#include ]) + +#l2371 + + +dnl zlib is required +AC_ARG_WITH([libz], + [ --with-libz=PATH Specify path to libz installation], + [ if test "x$withval" = "xno"; then + AC_MSG_ERROR([*** zlib is required ***]) + elif test "x$withval" != "xyes"; then + if test -d "$withval/lib"; then + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" + else + LDFLAGS="-L${withval}/lib ${LDFLAGS}" + fi + else + if test -n "${need_dash_r}"; then + LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" + else + LDFLAGS="-L${withval} ${LDFLAGS}" + fi + fi + if test -d "$withval/include"; then + CPPFLAGS="-I${withval}/include ${CPPFLAGS}" + else + CPPFLAGS="-I${withval} ${CPPFLAGS}" + fi + fi ] +) + +AC_CHECK_HEADER([zlib.h], ,[AC_MSG_ERROR([*** zlib.h missing - please install first or check config.log ***])]) +AC_CHECK_LIB([z], [deflate], , + [ + saved_CPPFLAGS="$CPPFLAGS" + saved_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + dnl Check default zlib install dir + if test -n "${need_dash_r}"; then + LDFLAGS="-L/usr/local/lib -R/usr/local/lib ${saved_LDFLAGS}" + else + LDFLAGS="-L/usr/local/lib ${saved_LDFLAGS}" + fi + CPPFLAGS="-I/usr/local/include ${saved_CPPFLAGS}" + LIBS="$LIBS -lz" + AC_TRY_LINK_FUNC([deflate], [AC_DEFINE([HAVE_LIBZ])], + [ + AC_MSG_ERROR([*** zlib missing - please install first or check config.log ***]) + ] + ) + ] +) + + + + + +AC_ARG_WITH([table-db], + [ --with-table-db Enable building of table-db backend (default=no)], + [ + if test "x$withval" = "xyes"; then + use_db_api=1 + else + use_db_api=0 + fi + ] +) + +if test "x$use_db_api" = "x1"; then +# Search for libdb +AC_CHECK_HEADER(db_185.h, [AC_DEFINE([HAVE_DB_185_H], [], [if you have the header file]) ] , [ +AC_CHECK_HEADER(db.h, [AC_DEFINE([HAVE_DB_H], [], [if you have the header file]) ] , [ +AC_CHECK_HEADER(db1/db.h, [AC_DEFINE([HAVE_DB1_DB_H], [], [if you have the header file]) ] , [ + AC_MSG_ERROR([*** Can't find Berkeley DB headers (see config.log for details) ***]) +])])]) +fi + +save_LIBS="$LIBS" + +if test "x$use_db_api" = "x1"; then +DB_LIB= + +for libdb in db db1 c; do + AC_CHECK_LIB($libdb, dbopen, [ DB_LIB="$libdb"; break; ], + AC_CHECK_LIB($libdb, __db185_open, [ DB_LIB="$libdb"; break; ])) +done + +if test -z "$DB_LIB"; then + AC_MSG_ERROR([Berkeley DB not found or not built with --enable-185]) +fi + +DB_LIB="-l$DB_LIB" +AC_SUBST([DB_LIB]) +fi + +LIBS="$save_LIBS" + + +AM_CONDITIONAL([HAVE_DB_API], [test "x$use_db_api" = "x1"]) +AM_COND_IF([HAVE_DB_API], [AC_DEFINE([HAVE_DB_API], [1], [Define to 1 if HAVE_DB_API])]) + + + +if test "$need_libasr" = "no" -a "x$ac_cv_search_event_asr_run" = "xno"; then + LIBS="$LIBS -lasr" +fi + + +LIBS="$LIBS ${SMTPDLIBS}" +##end of chl + + +## +#AM_CONDITIONAL([NEED_BASENAME], [test "x$ac_cv_have_basename" != "xyes"]) +AM_CONDITIONAL([NEED_BASE64], [test "x$ac_cv_search_b64_ntop" = "xno" -a "x$ac_cv_search___b64_ntop" = "xno" ]) +AM_CONDITIONAL([NEED_BASENAME], [test "x$ac_cv_search_basename" = "xno"]) +AM_CONDITIONAL([NEED_CLOCK_GETTIME], [test "x$ac_cv_search_clock_gettime" = "xno"]) +AM_CONDITIONAL([NEED_CLOSEFROM], [test "x$ac_cv_search_closefrom" = "xno"]) +AM_CONDITIONAL([NEED_DAEMON], [test "x$ac_cv_search_daemon" = "xno"]) +AM_CONDITIONAL([NEED_DIRNAME], [test "x$ac_cv_search_dirname" = "xno"]) +AM_CONDITIONAL([NEED_EVENT_ASR_RUN], [test "x$ac_cv_search_event_asr_run" = "xno"]) +AM_CONDITIONAL([NEED_FMT_SCALED], [test "x$ac_cv_search_fmt_scaled" = "xno"]) +AM_CONDITIONAL([NEED_FPARSELN], [test "x$ac_cv_search_fparseln" = "xno"]) +AM_CONDITIONAL([NEED_IMSG], [test "x$ac_cv_search_imsg_init" = "xno"]) +AM_CONDITIONAL([NEED_INET_NET_PTON], [test "x$ac_cv_search_inet_net_pton" = "xno"]) + +AM_CONDITIONAL([NEED_ERR], [test "x$ac_cv_func_err" != "xyes"]) +AM_CONDITIONAL([NEED_ERRC], [test "x$ac_cv_func_errc" != "xyes"]) +AM_CONDITIONAL([NEED_CRYPT_CHECKPASS], [test "x$ac_cv_func_crypt_checkpass" != "xyes"]) +AM_CONDITIONAL([NEED_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" != "xyes"]) +AM_CONDITIONAL([NEED_FGETLN], [test "x$ac_cv_func_fgetln" != "xyes"]) +AM_CONDITIONAL([NEED_FREEZERO], [test "x$ac_cv_func_freezero" != "xyes"]) +AM_CONDITIONAL([NEED_GETOPT], [test "x$ac_cv_func_getopt" != "xyes"]) +AM_CONDITIONAL([NEED_GETPEEREID], [test "x$ac_cv_func_getpeereid" != "xyes"]) +AM_CONDITIONAL([NEED_NANOSLEEP], [test "x$ac_cv_func_nanosleep" != "xyes"]) +AM_CONDITIONAL([NEED_PIDFILE], [test "x$ac_cv_func_pidfile" != "xyes"]) +AM_CONDITIONAL([NEED_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" != "xyes"]) +AM_CONDITIONAL([NEED_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" != "xyes"]) +AM_CONDITIONAL([NEED_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" != "xyes"]) +AM_CONDITIONAL([NEED_SETEGID], [test "x$ac_cv_func_setegid" != "xyes"]) +AM_CONDITIONAL([NEED_SETEUID], [test "x$ac_cv_func_seteuid" != "xyes"]) +AM_CONDITIONAL([NEED_SETRESGID], [test "x$ac_cv_func_setresgid" != "xyes"]) +AM_CONDITIONAL([NEED_SETRESUID], [test "x$ac_cv_func_setresuid" != "xyes"]) +AM_CONDITIONAL([NEED_SIGNAL], [test "x$ac_cv_func_signal" != "xyes"]) +AM_CONDITIONAL([NEED_STRERROR], [test "x$ac_cv_func_strerror" != "xyes"]) +AM_CONDITIONAL([NEED_STRLCAT], [test "x$ac_cv_func_strlcat" != "xyes"]) +AM_CONDITIONAL([NEED_STRLCPY], [test "x$ac_cv_func_strlcpy" != "xyes"]) +AM_CONDITIONAL([NEED_STRMODE], [test "x$ac_cv_func_strmode" != "xyes"]) +AM_CONDITIONAL([NEED_STRSEP], [test "x$ac_cv_func_strsep" != "xyes"]) +AM_CONDITIONAL([NEED_STRTONUM], [test "x$ac_cv_func_strtonum" != "xyes"]) +AM_CONDITIONAL([NEED_STRNDUP], [test "x$ac_cv_func_strndup" != "xyes"]) +AM_CONDITIONAL([NEED_STRNLEN], [test "x$ac_cv_func_strnlen" != "xyes"]) +AM_CONDITIONAL([NEED_WAITPID], [test "x$ac_cv_func_waitpid" != "xyes"]) +AM_CONDITIONAL([NEED_VIS], [test "x$ac_cv_func_strnvis" != "xyes" -o "x$BROKEN_STRNVIS" = "x1"]) +AM_CONDITIONAL([NEED_USLEEP], [test "x$ac_cv_func_usleep" != "xyes"]) + +AM_CONDITIONAL([NEED_RES_HNOK], [test "x$ac_cv_search_res_hnok" = "xno" -a x"$ac_cv_func_res_hnok" != "xyes" -a x"$need_libasr" = x"yes"]) +AM_CONDITIONAL([NEED_RES_RANDOMID], [test "x$ac_cv_search_res_randomid" = "xno" -a x"$ac_cv_func_res_randomid" != "xyes" -a x"$need_libasr" = x"yes"]) + +AM_CONDITIONAL([NEED_ARC4RANDOM], [test "x$ac_cv_func_arc4random" != "xyes" -a "x$ac_cv_have_decl_LIBRESSL_VERSION_NUMBER" != "xyes"]) +AM_CONDITIONAL([NEED_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM], [test "x$ac_cv_have_decl_LIBRESSL_VERSION_NUMBER" != "xyes"]) + +AM_CONDITIONAL([NEED_PROGNAME], [test "x$ac_cv_libc_defines___progname" != "xyes"]) +## + + +AC_CONFIG_FILES([Makefile + openbsd-compat/Makefile + mk/Makefile + mk/mail/Makefile + mk/mail/mail.lmtp/Makefile + mk/mail/mail.maildir/Makefile + mk/mail/mail.mboxfile/Makefile + mk/mail/mail.mda/Makefile + mk/smtpd/Makefile + mk/smtpctl/Makefile + mk/smtp/Makefile + contrib/Makefile + contrib/libexec/Makefile + contrib/libexec/mail.local/Makefile + contrib/libexec/lockspool/Makefile + contrib/libexec/encrypt/Makefile + ]) + +#l4761 +AC_OUTPUT diff --git a/contrib/Makefile.am b/contrib/Makefile.am new file mode 100644 index 00000000..37a8e73a --- /dev/null +++ b/contrib/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = libexec diff --git a/contrib/libexec/Makefile.am b/contrib/libexec/Makefile.am new file mode 100644 index 00000000..0e3a271f --- /dev/null +++ b/contrib/libexec/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = mail.local lockspool encrypt diff --git a/contrib/libexec/encrypt/Makefile.am b/contrib/libexec/encrypt/Makefile.am new file mode 100644 index 00000000..6ad7b82d --- /dev/null +++ b/contrib/libexec/encrypt/Makefile.am @@ -0,0 +1,13 @@ +pkglibexec_PROGRAMS = encrypt + +encrypt_SOURCES = encrypt.c +encrypt_SOURCES += $(top_srcdir)/smtpd/log.c + +AM_CPPFLAGS = -I$(top_srcdir)/openbsd-compat + +LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a + +LDADD = $(LIBCOMPAT) + +uninstall-hook: + rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/contrib/libexec/encrypt/encrypt.c b/contrib/libexec/encrypt/encrypt.c new file mode 100644 index 00000000..80275921 --- /dev/null +++ b/contrib/libexec/encrypt/encrypt.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2013 Sunil Nimmagadda + * Copyright (c) 2013 Gilles Chehade + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "includes.h" + +#ifdef HAVE_CRYPT_H +#include /* needed for crypt() */ +#endif +#include +#include +#include +#include + +#define PASSWORD_LEN 128 +#define SALT_LEN 16 + +static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +static void to64(char *, long int, int); +static void print_passwd(const char *); + +int +main(int argc, char *argv[]) +{ + char *line; + size_t linesz; + ssize_t linelen; + + if (argc > 2) { + fprintf(stderr, "usage: encrypt \n"); + return (1); + } + + if (argc == 2) { + print_passwd(argv[1]); + return (0); + } + + line = NULL; + linesz = 0; + while ((linelen = getline(&line, &linesz, stdin)) != -1) { + if (line[linelen - 1] == '\n') + line[linelen - 1] = '\0'; + print_passwd(line); + } + free(line); + + return (0); +} + +void +print_passwd(const char *string) +{ + const char *ids[] = { "2a", "6", "5", "3", "2", "1", NULL }; + const char *id; + char salt[SALT_LEN+1]; + char buffer[PASSWORD_LEN]; + int n; + const char *p; + + for (n = 0; n < SALT_LEN; ++n) + to64(&salt[n], arc4random_uniform(0xff), 1); + salt[SALT_LEN] = '\0'; + + for (n = 0; ids[n]; n++) { + id = ids[n]; + (void)snprintf(buffer, sizeof buffer, "$%s$%s$", id, salt); + if ((p = crypt(string, buffer)) == NULL) + continue; + if (strncmp(p, buffer, strlen(buffer)) != 0) + continue; + printf("%s\n", p); + return; + } + + salt[2] = 0; + printf("%s\n", crypt(string, salt)); +} + +void +to64(char *s, long int v, int n) +{ + while (--n >= 0) { + *s++ = itoa64[v & 0x3f]; + v >>= 6; + } +} diff --git a/contrib/libexec/lockspool/Makefile.am b/contrib/libexec/lockspool/Makefile.am new file mode 100644 index 00000000..dacf5386 --- /dev/null +++ b/contrib/libexec/lockspool/Makefile.am @@ -0,0 +1,20 @@ +pkglibexec_PROGRAMS = lockspool + +lockspool_SOURCES = lockspool.c +lockspool_SOURCES += locking.c +lockspool_SOURCES += $(top_srcdir)/smtpd/log.c + +EXTRA_DIST = mail.local.h pathnames.h + +AM_CPPFLAGS = -I$(top_srcdir)/openbsd-compat -I$(top_srcdir)/mail.local + +LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a + +LDADD = $(LIBCOMPAT) + +install-exec-hook: $(CONFIGFILES) $(MANPAGES) + chown root $(DESTDIR)$(pkglibexecdir)/lockspool || true + chmod 4555 $(DESTDIR)$(pkglibexecdir)/lockspool || true + +uninstall-hook: + rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/contrib/libexec/lockspool/locking.c b/contrib/libexec/lockspool/locking.c new file mode 100644 index 00000000..e4922dd6 --- /dev/null +++ b/contrib/libexec/lockspool/locking.c @@ -0,0 +1,181 @@ +/* $OpenBSD: locking.c,v 1.14 2020/02/09 14:59:20 millert Exp $ */ + +/* + * Copyright (c) 1996-1998 Theo de Raadt + * Copyright (c) 1996-1998 David Mazieres + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "includes.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pathnames.h" +#include "mail.local.h" + +static char lpath[PATH_MAX]; + +void +rellock(void) +{ + + if (lpath[0]) + unlink(lpath); +} + +int +getlock(const char *name, struct passwd *pw) +{ + struct stat sb, fsb; + int lfd=-1; + char buf[8*1024]; + int tries = 0; + + (void)snprintf(lpath, sizeof lpath, "%s/%s.lock", + _PATH_MAILDIR, name); + + if (stat(_PATH_MAILDIR, &sb) != -1 && + (sb.st_mode & S_IWOTH) == S_IWOTH) { + /* + * We have a writeable spool, deal with it as + * securely as possible. + */ + time_t ctim = -1; + + seteuid(pw->pw_uid); + if (lstat(lpath, &sb) != -1) + ctim = sb.st_ctime; + while (1) { + /* + * Deal with existing user.lock files + * or directories or symbolic links that + * should not be here. + */ + if (readlink(lpath, buf, sizeof buf-1) != -1) { + if (lstat(lpath, &sb) != -1 && + S_ISLNK(sb.st_mode)) { + seteuid(sb.st_uid); + unlink(lpath); + seteuid(pw->pw_uid); + } + goto again; + } + if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL|O_EXLOCK, + S_IRUSR|S_IWUSR)) != -1) + break; +again: + if (tries > 10) { + mwarn("%s: %s", lpath, strerror(errno)); + seteuid(0); + return(-1); + } + if (tries > 9 && + (lfd = open(lpath, O_WRONLY|O_EXLOCK, 0)) != -1) { + if (fstat(lfd, &fsb) != -1 && + lstat(lpath, &sb) != -1) { + if (fsb.st_dev == sb.st_dev && + fsb.st_ino == sb.st_ino && + ctim == fsb.st_ctime ) { + seteuid(fsb.st_uid); + baditem(lpath); + seteuid(pw->pw_uid); + } + } + close(lfd); + } + sleep(1U << tries); + tries++; + continue; + } + seteuid(0); + } else { + /* + * Only root can write the spool directory. + */ + while (1) { + if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL, + S_IRUSR|S_IWUSR)) != -1) + break; + if (tries > 9) { + mwarn("%s: %s", lpath, strerror(errno)); + return(-1); + } + sleep(1U << tries); + tries++; + } + } + return(lfd); +} + +void +baditem(char *path) +{ + char npath[PATH_MAX]; + int fd; + + if (unlink(path) == 0) + return; + snprintf(npath, sizeof npath, "%s/mailXXXXXXXXXX", _PATH_MAILDIR); + if ((fd = mkstemp(npath)) == -1) + return; + close(fd); + if (rename(path, npath) == -1) + unlink(npath); + else + mwarn("nasty spool item %s renamed to %s", path, npath); + /* XXX if we fail to rename, another attempt will happen later */ +} + +void +mwarn(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(LOG_ERR, fmt, ap); + va_end(ap); +} + +void +merr(int eval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(LOG_ERR, fmt, ap); + va_end(ap); + exit(eval); +} diff --git a/contrib/libexec/lockspool/lockspool.1 b/contrib/libexec/lockspool/lockspool.1 new file mode 100644 index 00000000..ea5524bf --- /dev/null +++ b/contrib/libexec/lockspool/lockspool.1 @@ -0,0 +1,77 @@ +.\" $OpenBSD: lockspool.1,v 1.14 2019/01/25 00:19:26 millert Exp $ +.\" +.\" Copyright (c) 1998 Todd C. Miller +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: January 25 2019 $ +.Dt LOCKSPOOL 1 +.Os +.Sh NAME +.Nm lockspool +.Nd lock user's system mailbox +.Sh SYNOPSIS +.Nm lockspool +.Op Ar username +.Sh DESCRIPTION +.Nm +is useful for a client mail program to attain proper locking. +.Nm +obtains a +.Pa username.lock +for the calling user and retains it until stdin is closed or a signal like +.Dv SIGINT , +.Dv SIGTERM , +or +.Dv SIGHUP +is received. +Additionally, the superuser may specify the name of a user in order +to lock a different mailbox. +.Pp +If +.Nm +is able to create the lock file, +.Dq 1 +is written to stdout, otherwise +.Dq 0 +is written and an error message is written to stderr. +.Nm +will try up to 10 times to get the lock (sleeping +for a short period in between tries). +.Pp +Typical usage is for a user mail agent (such as +.Xr mail 1 ) +to open a pipe to +.Nm +when it needs to lock the user's mail spool. +Closing the pipe will cause +.Nm +to release the lock. +.Sh FILES +.Bl -tag -width /var/mail/username.lock -compact +.It Pa /var/mail/username.lock +user's mail lock file +.El +.Sh EXIT STATUS +The +.Nm +utility exits 0 on success, and 1 if an error occurs. +.Sh SEE ALSO +.Xr mail 1 , +.Xr mail.local 8 , +.Xr smtpd 8 +.Sh HISTORY +The +.Nm +program appeared in +.Ox 2.4 . diff --git a/contrib/libexec/lockspool/lockspool.c b/contrib/libexec/lockspool/lockspool.c new file mode 100644 index 00000000..9277241b --- /dev/null +++ b/contrib/libexec/lockspool/lockspool.c @@ -0,0 +1,124 @@ +/* $OpenBSD: lockspool.c,v 1.21 2020/02/09 14:59:20 millert Exp $ */ + +/* + * Copyright (c) 1998 Theo de Raadt + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "includes.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mail.local.h" + +void unhold(int); +void usage(void); + +extern char *__progname; + +int +main(int argc, char *argv[]) +{ + struct passwd *pw; + struct pollfd pfd; + ssize_t nread; + char *from, c; + int holdfd; + +#if HAVE_UNVEIL + if (unveil(_PATH_MAILDIR, "rwc") == -1) + err(1, "unveil"); +#endif +#if HAVE_PLEDGE + if (pledge("stdio rpath wpath getpw cpath fattr", NULL) == -1) + err(1, "pledge"); +#endif + + openlog(__progname, LOG_PERROR, LOG_MAIL); + + if (argc != 1 && argc != 2) + usage(); + if (argc == 2 && getuid() != 0) + merr(1, "you must be root to lock someone else's spool"); + + signal(SIGTERM, unhold); + signal(SIGINT, unhold); + signal(SIGHUP, unhold); + signal(SIGPIPE, unhold); + + if (argc == 2) + pw = getpwnam(argv[1]); + else + pw = getpwuid(getuid()); + if (pw == NULL) + exit (1); + from = pw->pw_name; + + holdfd = getlock(from, pw); + if (holdfd == -1) { + write(STDOUT_FILENO, "0\n", 2); + exit (1); + } + write(STDOUT_FILENO, "1\n", 2); + + /* wait for the other end of the pipe to close, then release the lock */ + pfd.fd = STDIN_FILENO; + pfd.events = POLLIN; + do { + if (poll(&pfd, 1, INFTIM) == -1) { + if (errno != EINTR) + break; + } + do { + nread = read(STDIN_FILENO, &c, 1); + } while (nread == 1 || (nread == -1 && errno == EINTR)); + } while (nread == -1 && errno == EAGAIN); + rellock(); + exit (0); +} + +/*ARGSUSED*/ +void +unhold(int signo) +{ + + rellock(); + _exit(0); +} + +void +usage(void) +{ + + merr(1, "usage: %s [username]", __progname); +} diff --git a/contrib/libexec/lockspool/mail.local.h b/contrib/libexec/lockspool/mail.local.h new file mode 100644 index 00000000..bc3137cb --- /dev/null +++ b/contrib/libexec/lockspool/mail.local.h @@ -0,0 +1,42 @@ +/* $OpenBSD: mail.local.h,v 1.7 2020/02/09 14:59:21 millert Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +void baditem(char *); +int deliver(int, char *, int); +void merr(int, const char *, ...); +void mwarn(const char *, ...); +int getlock(const char *, struct passwd *); +void notifybiff(char *); +void rellock(void); +int storemail(char *); +int lockspool(const char *, struct passwd *); +void unlockspool(void); +void usage(void); diff --git a/contrib/libexec/lockspool/pathnames.h b/contrib/libexec/lockspool/pathnames.h new file mode 100644 index 00000000..0a2c2731 --- /dev/null +++ b/contrib/libexec/lockspool/pathnames.h @@ -0,0 +1,38 @@ +/* $OpenBSD: pathnames.h,v 1.5 2003/06/02 19:38:24 millert Exp $*/ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)pathnames.h 5.3 (Berkeley) 1/17/91 + */ +#ifdef HAVE_PATHS_H +#include +#endif + +#define _PATH_LOCTMP "/tmp/local.XXXXXXXXXX" +#define _PATH_LOCKSPOOL PATH_LIBEXEC"/lockspool" diff --git a/contrib/libexec/mail.local/Makefile.am b/contrib/libexec/mail.local/Makefile.am new file mode 100644 index 00000000..bd5211a2 --- /dev/null +++ b/contrib/libexec/mail.local/Makefile.am @@ -0,0 +1,22 @@ +pkglibexec_PROGRAMS = mail.local + +mail_local_SOURCES = mail.local.c +mail_local_SOURCES += locking.c +mail_local_SOURCES += $(top_srcdir)/smtpd/log.c + +EXTRA_DIST = mail.local.h pathnames.h + +AM_CPPFLAGS = -I$(top_srcdir)/openbsd-compat -DPATH_LIBEXEC=\"$(pkglibexecdir)\" + +LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a + +LDADD = $(LIBCOMPAT) + +# need to define _GNU_SOURCE to get: +# EAI_NODATA defined +# {v,}asprintf +# setres{g,u}id +#CFLAGS += -D_GNU_SOURCE + +uninstall-hook: + rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/contrib/libexec/mail.local/locking.c b/contrib/libexec/mail.local/locking.c new file mode 100644 index 00000000..85a48d5e --- /dev/null +++ b/contrib/libexec/mail.local/locking.c @@ -0,0 +1,182 @@ +/* $OpenBSD: locking.c,v 1.14 2020/02/09 14:59:20 millert Exp $ */ + +/* + * Copyright (c) 1996-1998 Theo de Raadt + * Copyright (c) 1996-1998 David Mazieres + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "includes.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pathnames.h" +#include "mail.local.h" + +static char lpath[PATH_MAX]; + +void +rellock(void) +{ + + if (lpath[0]) + unlink(lpath); +} + +int +getlock(const char *name, struct passwd *pw) +{ + struct stat sb, fsb; + int lfd=-1; + char buf[8*1024]; + int tries = 0; + + (void)snprintf(lpath, sizeof lpath, "%s/%s.lock", + _PATH_MAILDIR, name); + + if (stat(_PATH_MAILDIR, &sb) != -1 && + (sb.st_mode & S_IWOTH) == S_IWOTH) { + /* + * We have a writeable spool, deal with it as + * securely as possible. + */ + time_t ctim = -1; + + seteuid(pw->pw_uid); + if (lstat(lpath, &sb) != -1) + ctim = sb.st_ctime; + while (1) { + /* + * Deal with existing user.lock files + * or directories or symbolic links that + * should not be here. + */ + if (readlink(lpath, buf, sizeof buf-1) != -1) { + if (lstat(lpath, &sb) != -1 && + S_ISLNK(sb.st_mode)) { + seteuid(sb.st_uid); + unlink(lpath); + seteuid(pw->pw_uid); + } + goto again; + } + if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL|O_EXLOCK, + S_IRUSR|S_IWUSR)) != -1) + break; +again: + if (tries > 10) { + mwarn("%s: %s", lpath, strerror(errno)); + seteuid(0); + return(-1); + } + if (tries > 9 && + (lfd = open(lpath, O_WRONLY|O_EXLOCK, 0)) != -1) { + if (fstat(lfd, &fsb) != -1 && + lstat(lpath, &sb) != -1) { + if (fsb.st_dev == sb.st_dev && + fsb.st_ino == sb.st_ino && + ctim == fsb.st_ctime ) { + seteuid(fsb.st_uid); + baditem(lpath); + seteuid(pw->pw_uid); + } + } + close(lfd); + } + sleep(1U << tries); + tries++; + continue; + } + seteuid(0); + } else { + /* + * Only root can write the spool directory. + */ + while (1) { + if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL, + S_IRUSR|S_IWUSR)) != -1) + break; + if (tries > 9) { + mwarn("%s: %s", lpath, strerror(errno)); + return(-1); + } + sleep(1U << tries); + tries++; + } + } + return(lfd); +} + +void +baditem(char *path) +{ + char npath[PATH_MAX]; + int fd; + + if (unlink(path) == 0) + return; + snprintf(npath, sizeof npath, "%s/mailXXXXXXXXXX", _PATH_MAILDIR); + if ((fd = mkstemp(npath)) == -1) + return; + close(fd); + if (rename(path, npath) == -1) + unlink(npath); + else + mwarn("nasty spool item %s renamed to %s", path, npath); + /* XXX if we fail to rename, another attempt will happen later */ +} + +void +mwarn(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(LOG_ERR, fmt, ap); + va_end(ap); +} + +void +merr(int eval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(LOG_ERR, fmt, ap); + va_end(ap); + exit(eval); +} diff --git a/contrib/libexec/mail.local/mail.local.8 b/contrib/libexec/mail.local/mail.local.8 new file mode 100644 index 00000000..330a4473 --- /dev/null +++ b/contrib/libexec/mail.local/mail.local.8 @@ -0,0 +1,183 @@ +.\" $OpenBSD: mail.local.8,v 1.31 2014/09/16 21:28:51 jmc Exp $ +.\" Copyright (c) 1990 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)mail.local.8 6.8 (Berkeley) 4/27/91 +.\" +.Dd $Mdocdate: September 16 2014 $ +.Dt MAIL.LOCAL 8 +.Os +.Sh NAME +.Nm mail.local +.Nd store mail in a mailbox +.Sh SYNOPSIS +.Nm mail.local +.Op Fl Ll +.Op Fl f Ar from +.Ar user ... +.Sh DESCRIPTION +.Nm +reads the standard input up to an end-of-file and appends it to each +.Ar user Ns 's +.Pa mail +file. +The +.Ar user +must be a valid user name. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl f Ar from +Specify the sender's name. +.It Fl L +Don't create a +.Pa username.lock +file while locking the spool. +.It Fl l +For compatibility, request that files named +.Pa username.lock +be used for locking. +(This is the default behavior.) +.El +.Pp +Individual mail messages in the mailbox are delimited by an empty +line followed by a line beginning with the string +.Dq "From\&\ " . +A line containing the string +.Dq "From\&\ " , +the sender's name and a timestamp is prepended to each delivered mail message. +A blank line is appended to each message. +A greater-than character +.Pq Ql > +is prepended to any line in the message which could be mistaken for a +.Dq "From\&\ " +delimiter line. +.Pp +Significant efforts have been made to ensure that +.Nm +acts as securely as possible if the spool directory is mode 1777 or 755. +The default of mode 755 is more secure, but it prevents mail clients from using +.Pa username.lock +style locking. +The use of 1777 is more flexible in an NFS shared-spool environment, +so many sites use it. +However, it does carry some risks, such as attackers filling the spool disk. +Some of these problems may be alleviated +by making the spool a separate filesystem, and placing quotas on it. +The use of any mode other than 1777 and 755 for the spool directory is +recommended against but may work properly. +.Pp +The mailbox is always locked using +.Xr flock 2 +while mail is appended. +Unless the +.Fl L +flag is specified, a +.Pa username.lock +file is also used. +.Pp +If the +.Xr biff 1 +service is returned by +.Xr getservbyname 3 , +the biff server is notified of delivered mail. +.Sh ENVIRONMENT +.Bl -tag -width indent +.It Ev TZ +Used to set the appropriate time zone on the timestamp. +.El +.Sh FILES +.Bl -tag -width /tmp/local.XXXXXXXXXX -compact +.It Pa /tmp/local.XXXXXXXXXX +temporary files +.It Pa /var/mail/user +user's mailbox directory +.El +.Sh EXIT STATUS +.Ex -std mail.local +.Sh SEE ALSO +.Xr biff 1 , +.Xr mail 1 , +.Xr flock 2 , +.Xr getservbyname 3 , +.Xr comsat 8 , +.Xr smtpd 8 +.Sh HISTORY +A superset of +.Nm +(handling mailbox reading as well as mail delivery) appeared in +.At v7 +as the program +.Xr mail 1 . +.Sh BUGS +Using quotas in +.Pa /var/mail +can be problematic if using +.Xr sendmail 8 +as an MTA, +since it asks +.Nm +to deliver a message to multiple recipients if possible. +This causes problems in a quota environment since a message may be +delivered to some users but not others due to disk quotas. +Even though the message was delivered to some of the recipients, +.Nm +will exit with an exit code > 0, causing +.Xr sendmail 8 +to attempt redelivery later. +That means that some users will keep getting the same message every time +.Xr sendmail 8 +runs its queue. +This problem does not exist for +.Xr smtpd 8 +users. +.Pp +If you are running +.Xr sendmail 8 +and have disk quotas on +.Pa /var/mail +it is imperative that you unset the +.Dq m +mailer flag for the +.Sq local +mailer. +To do this, locate the line beginning with +.Dq Mlocal +in +.Pa /etc/mail/sendmail.cf +and remove the +.Dq m +from the flags section, denoted by +.Dq F= . +Alternately, you can override the default mailer flags by adding the line: +.Pp +.Dl define(`LOCAL_MAILER_FLAGS', `rn9S')dnl +.Pp +to your +.Dq \.mc +file (this is the source file that is used to generate +.Pa /etc/mail/sendmail.cf ) . diff --git a/contrib/libexec/mail.local/mail.local.c b/contrib/libexec/mail.local/mail.local.c new file mode 100644 index 00000000..a574b3fe --- /dev/null +++ b/contrib/libexec/mail.local/mail.local.c @@ -0,0 +1,392 @@ +/* $OpenBSD: mail.local.c,v 1.39 2020/02/09 14:59:20 millert Exp $ */ + +/*- + * Copyright (c) 1996-1998 Theo de Raadt + * Copyright (c) 1996-1998 David Mazieres + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "includes.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pathnames.h" +#include "mail.local.h" + +int +main(int argc, char *argv[]) +{ + struct passwd *pw; + int ch, fd, eval, lockfile=1; + uid_t uid; + char *from; + + openlog("mail.local", LOG_PERROR, LOG_MAIL); + + from = NULL; + while ((ch = getopt(argc, argv, "lLdf:r:")) != -1) + switch (ch) { + case 'd': /* backward compatible */ + break; + case 'f': + case 'r': /* backward compatible */ + if (from) + merr(EX_USAGE, "multiple -f options"); + from = optarg; + break; + case 'l': + lockfile=1; + break; + case 'L': + lockfile=0; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (!*argv) + usage(); + + /* + * If from not specified, use the name from getlogin() if the + * uid matches, otherwise, use the name from the password file + * corresponding to the uid. + */ + uid = getuid(); + if (!from && (!(from = getlogin()) || + !(pw = getpwnam(from)) || pw->pw_uid != uid)) + from = (pw = getpwuid(uid)) ? pw->pw_name : "???"; + + fd = storemail(from); + for (eval = 0; *argv; ++argv) { + if ((ch = deliver(fd, *argv, lockfile)) != 0) + eval = ch; + } + exit(eval); +} + +int +storemail(char *from) +{ + FILE *fp = NULL; + time_t tval; + int fd, eline; + size_t len; + char *line, *tbuf; + + if ((tbuf = strdup(_PATH_LOCTMP)) == NULL) + merr(EX_OSERR, "unable to allocate memory"); + if ((fd = mkstemp(tbuf)) == -1 || !(fp = fdopen(fd, "w+"))) + merr(EX_OSERR, "unable to open temporary file"); + (void)unlink(tbuf); + free(tbuf); + + (void)time(&tval); + (void)fprintf(fp, "From %s %s", from, ctime(&tval)); + + for (eline = 1, tbuf = NULL; (line = fgetln(stdin, &len));) { + /* We have to NUL-terminate the line since fgetln does not */ + if (line[len - 1] == '\n') + line[len - 1] = '\0'; + else { + /* No trailing newline, so alloc space and copy */ + if ((tbuf = malloc(len + 1)) == NULL) + merr(EX_OSERR, "unable to allocate memory"); + memcpy(tbuf, line, len); + tbuf[len] = '\0'; + line = tbuf; + } + if (line[0] == '\0') + eline = 1; + else { + if (eline && line[0] == 'F' && len > 5 && + !memcmp(line, "From ", 5)) + (void)putc('>', fp); + eline = 0; + } + (void)fprintf(fp, "%s\n", line); + if (ferror(fp)) + break; + } + free(tbuf); + + /* Output a newline; note, empty messages are allowed. */ + (void)putc('\n', fp); + (void)fflush(fp); + if (ferror(fp)) + merr(EX_OSERR, "temporary file write error"); + return(fd); +} + +int +deliver(int fd, char *name, int lockfile) +{ + struct stat sb, fsb; + struct passwd *pw; + int mbfd=-1, lfd=-1, rval=EX_OSERR; + char biffmsg[100], buf[8*1024], path[PATH_MAX]; + off_t curoff; + size_t off; + ssize_t nr, nw; + + /* + * Disallow delivery to unknown names -- special mailboxes can be + * handled in the sendmail aliases file. + */ + if (!(pw = getpwnam(name))) { + mwarn("unknown name: %s", name); + return(EX_NOUSER); + } + + (void)snprintf(path, sizeof path, "%s/%s", _PATH_MAILDIR, name); + + if (lockfile) { + lfd = lockspool(name, pw); + if (lfd == -1) + return(EX_OSERR); + } + + /* after this point, always exit via bad to remove lockfile */ +retry: + if (lstat(path, &sb)) { + if (errno != ENOENT) { + mwarn("%s: %s", path, strerror(errno)); + goto bad; + } + if ((mbfd = open(path, O_APPEND|O_CREAT|O_EXCL|O_WRONLY|O_EXLOCK, + S_IRUSR|S_IWUSR)) == -1) { +#ifndef HAVE_O_EXLOCK + /* XXX : do something! */ +#endif + if (errno == EEXIST) { + /* file appeared since lstat */ + goto retry; + } else { + mwarn("%s: %s", path, strerror(errno)); + rval = EX_CANTCREAT; + goto bad; + } + } + /* + * Set the owner and group. Historically, binmail repeated + * this at each mail delivery. We no longer do this, assuming + * that if the ownership or permissions were changed there + * was a reason for doing so. + */ + if (fchown(mbfd, pw->pw_uid, pw->pw_gid) == -1) { + mwarn("chown %u:%u: %s", pw->pw_uid, pw->pw_gid, name); + goto bad; + } + } else { + if (sb.st_nlink != 1 || !S_ISREG(sb.st_mode)) { + mwarn("%s: linked or special file", path); + goto bad; + } + if ((mbfd = open(path, O_APPEND|O_WRONLY|O_EXLOCK, + S_IRUSR|S_IWUSR)) == -1) { + mwarn("%s: %s", path, strerror(errno)); + goto bad; + } + if (fstat(mbfd, &fsb) == -1) { + /* relating error to path may be bad style */ + mwarn("%s: %s", path, strerror(errno)); + goto bad; + } + if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) { + mwarn("%s: changed after open", path); + goto bad; + } + /* paranoia? */ + if (fsb.st_nlink != 1 || !S_ISREG(fsb.st_mode)) { + mwarn("%s: linked or special file", path); + rval = EX_CANTCREAT; + goto bad; + } + } + + curoff = lseek(mbfd, 0, SEEK_END); + (void)snprintf(biffmsg, sizeof biffmsg, "%s@%lld\n", name, curoff); + if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { + mwarn("temporary file: %s", strerror(errno)); + goto bad; + } + + while ((nr = read(fd, buf, sizeof(buf))) > 0) + for (off = 0; off < nr; off += nw) + if ((nw = write(mbfd, buf + off, nr - off)) == -1) { + mwarn("%s: %s", path, strerror(errno)); + (void)ftruncate(mbfd, curoff); + goto bad; + } + + if (nr == 0) { + rval = 0; + } else { + (void)ftruncate(mbfd, curoff); + mwarn("temporary file: %s", strerror(errno)); + } + +bad: + if (lfd != -1) + unlockspool(); + + if (mbfd != -1) { + (void)fsync(mbfd); /* Don't wait for update. */ + (void)close(mbfd); /* Implicit unlock. */ + } + + if (!rval) + notifybiff(biffmsg); + return(rval); +} + +void +notifybiff(char *msg) +{ + static struct addrinfo *res0; + struct addrinfo hints, *res; + static int f = -1; + size_t len; + int error; + + if (res0 == NULL) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + + error = getaddrinfo("localhost", "biff", &hints, &res0); + if (error) { + /* Be silent if biff service not available. */ + if (error != EAI_SERVICE) { + mwarn("localhost: %s", gai_strerror(error)); + } + return; + } + } + + if (f == -1) { + for (res = res0; res != NULL; res = res->ai_next) { + f = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (f != -1) + break; + } + } + if (f == -1) { + mwarn("socket: %s", strerror(errno)); + return; + } + + len = strlen(msg) + 1; /* XXX */ + if (sendto(f, msg, len, 0, res->ai_addr, res->ai_addrlen) != len) + mwarn("sendto biff: %s", strerror(errno)); +} + +static int lockfd = -1; +static pid_t lockpid = -1; + +int +lockspool(const char *name, struct passwd *pw) +{ + int pfd[2]; + char ch; + + if (geteuid() == 0) + return getlock(name, pw); + + /* If not privileged, open pipe to lockspool(1) instead */ + if (pipe2(pfd, O_CLOEXEC) == -1) { + merr(EX_OSERR, "pipe: %s", strerror(errno)); + return -1; + } + + signal(SIGPIPE, SIG_IGN); + switch ((lockpid = fork())) { + case -1: + merr(EX_OSERR, "fork: %s", strerror(errno)); + return -1; + case 0: + /* child */ + close(pfd[0]); + dup2(pfd[1], STDOUT_FILENO); + execl(_PATH_LOCKSPOOL, "lockspool", (char *)NULL); + merr(EX_OSERR, "execl: lockspool: %s", strerror(errno)); + /* NOTREACHED */ + break; + default: + /* parent */ + close(pfd[1]); + lockfd = pfd[0]; + break; + } + + if (read(lockfd, &ch, 1) != 1 || ch != '1') { + unlockspool(); + merr(EX_OSERR, "lockspool: unable to get lock"); + } + + return lockfd; +} + +void +unlockspool(void) +{ + if (lockpid != -1) { + waitpid(lockpid, NULL, 0); + lockpid = -1; + } else { + rellock(); + } + close(lockfd); + lockfd = -1; +} + +void +usage(void) +{ + merr(EX_USAGE, "usage: mail.local [-Ll] [-f from] user ..."); +} diff --git a/contrib/libexec/mail.local/mail.local.h b/contrib/libexec/mail.local/mail.local.h new file mode 100644 index 00000000..bc3137cb --- /dev/null +++ b/contrib/libexec/mail.local/mail.local.h @@ -0,0 +1,42 @@ +/* $OpenBSD: mail.local.h,v 1.7 2020/02/09 14:59:21 millert Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +void baditem(char *); +int deliver(int, char *, int); +void merr(int, const char *, ...); +void mwarn(const char *, ...); +int getlock(const char *, struct passwd *); +void notifybiff(char *); +void rellock(void); +int storemail(char *); +int lockspool(const char *, struct passwd *); +void unlockspool(void); +void usage(void); diff --git a/contrib/libexec/mail.local/pathnames.h b/contrib/libexec/mail.local/pathnames.h new file mode 100644 index 00000000..0a2c2731 --- /dev/null +++ b/contrib/libexec/mail.local/pathnames.h @@ -0,0 +1,38 @@ +/* $OpenBSD: pathnames.h,v 1.5 2003/06/02 19:38:24 millert Exp $*/ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)pathnames.h 5.3 (Berkeley) 1/17/91 + */ +#ifdef HAVE_PATHS_H +#include +#endif + +#define _PATH_LOCTMP "/tmp/local.XXXXXXXXXX" +#define _PATH_LOCKSPOOL PATH_LIBEXEC"/lockspool" diff --git a/control.c b/control.c deleted file mode 100644 index 6f9c9aca..00000000 --- a/control.c +++ /dev/null @@ -1,802 +0,0 @@ -/* $OpenBSD: control.c,v 1.123 2018/05/31 21:06:12 gilles Exp $ */ - -/* - * Copyright (c) 2012 Gilles Chehade - * Copyright (c) 2008 Pierre-Yves Ritschard - * Copyright (c) 2003, 2004 Henning Brauer - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" - -#define CONTROL_BACKLOG 5 - -struct ctl_conn { - uint32_t id; - uint8_t flags; -#define CTL_CONN_NOTIFY 0x01 - struct mproc mproc; - uid_t euid; - gid_t egid; -}; - -struct { - struct event ev; - int fd; -} control_state; - -static void control_imsg(struct mproc *, struct imsg *); -static void control_shutdown(void); -static void control_listen(void); -static void control_accept(int, short, void *); -static void control_close(struct ctl_conn *); -static void control_dispatch_ext(struct mproc *, struct imsg *); -static void control_digest_update(const char *, size_t, int); -static void control_broadcast_verbose(int, int); - -static struct stat_backend *stat_backend = NULL; -extern const char *backend_stat; - -static uint64_t connid = 0; -static struct tree ctl_conns; -static struct tree ctl_count; -static struct stat_digest digest; - -#define CONTROL_FD_RESERVE 5 -#define CONTROL_MAXCONN_PER_CLIENT 32 - -static void -control_imsg(struct mproc *p, struct imsg *imsg) -{ - struct ctl_conn *c; - struct stat_value val; - struct msg m; - const char *key; - const void *data; - size_t sz; - - if (imsg == NULL) { - if (p->proc != PROC_CLIENT) - control_shutdown(); - return; - } - - switch (imsg->hdr.type) { - case IMSG_CTL_OK: - case IMSG_CTL_FAIL: - case IMSG_CTL_LIST_MESSAGES: - case IMSG_CTL_LIST_ENVELOPES: - case IMSG_CTL_DISCOVER_EVPID: - case IMSG_CTL_DISCOVER_MSGID: - case IMSG_CTL_MTA_SHOW_HOSTS: - case IMSG_CTL_MTA_SHOW_RELAYS: - case IMSG_CTL_MTA_SHOW_ROUTES: - case IMSG_CTL_MTA_SHOW_HOSTSTATS: - case IMSG_CTL_MTA_SHOW_BLOCK: - c = tree_get(&ctl_conns, imsg->hdr.peerid); - if (c == NULL) - return; - imsg->hdr.peerid = 0; - m_forward(&c->mproc, imsg); - return; - - case IMSG_CTL_SMTP_SESSION: - c = tree_get(&ctl_conns, imsg->hdr.peerid); - if (c == NULL) - return; - m_compose(&c->mproc, IMSG_CTL_OK, 0, 0, imsg->fd, NULL, 0); - return; - - case IMSG_STAT_INCREMENT: - m_msg(&m, imsg); - m_get_string(&m, &key); - m_get_data(&m, &data, &sz); - m_end(&m); - if (sz != sizeof(val)) - fatalx("control: IMSG_STAT_INCREMENT size mismatch"); - memmove(&val, data, sz); - if (stat_backend) - stat_backend->increment(key, val.u.counter); - control_digest_update(key, val.u.counter, 1); - return; - - case IMSG_STAT_DECREMENT: - m_msg(&m, imsg); - m_get_string(&m, &key); - m_get_data(&m, &data, &sz); - m_end(&m); - if (sz != sizeof(val)) - fatalx("control: IMSG_STAT_DECREMENT size mismatch"); - memmove(&val, data, sz); - if (stat_backend) - stat_backend->decrement(key, val.u.counter); - control_digest_update(key, val.u.counter, 0); - return; - - case IMSG_STAT_SET: - m_msg(&m, imsg); - m_get_string(&m, &key); - m_get_data(&m, &data, &sz); - m_end(&m); - if (sz != sizeof(val)) - fatalx("control: IMSG_STAT_SET size mismatch"); - memmove(&val, data, sz); - if (stat_backend) - stat_backend->set(key, &val); - return; - } - - errx(1, "control_imsg: unexpected %s imsg", - imsg_to_str(imsg->hdr.type)); -} - -int -control_create_socket(void) -{ - struct sockaddr_un s_un; - int fd; - mode_t old_umask; - - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) - fatal("control: socket"); - - memset(&s_un, 0, sizeof(s_un)); - s_un.sun_family = AF_UNIX; - if (strlcpy(s_un.sun_path, SMTPD_SOCKET, - sizeof(s_un.sun_path)) >= sizeof(s_un.sun_path)) - fatal("control: socket name too long"); - - if (connect(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == 0) - fatalx("control socket already listening"); - - if (unlink(SMTPD_SOCKET) == -1) - if (errno != ENOENT) - fatal("control: cannot unlink socket"); - - old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH); - if (bind(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) { - (void)umask(old_umask); - fatal("control: bind"); - } - (void)umask(old_umask); - - if (chmod(SMTPD_SOCKET, - S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1) { - (void)unlink(SMTPD_SOCKET); - fatal("control: chmod"); - } - - io_set_nonblocking(fd); - control_state.fd = fd; - - return fd; -} - -int -control(void) -{ - struct passwd *pw; - - purge_config(PURGE_EVERYTHING); - - if ((pw = getpwnam(SMTPD_USER)) == NULL) - fatalx("unknown user " SMTPD_USER); - - stat_backend = env->sc_stat; - stat_backend->init(); - - if (chroot(PATH_CHROOT) == -1) - fatal("control: chroot"); - if (chdir("/") == -1) - fatal("control: chdir(\"/\")"); - - config_process(PROC_CONTROL); - - if (setgroups(1, &pw->pw_gid) || - setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || - setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) - fatal("control: cannot drop privileges"); - - imsg_callback = control_imsg; - event_init(); - - signal(SIGINT, SIG_IGN); - signal(SIGTERM, SIG_IGN); - signal(SIGPIPE, SIG_IGN); - signal(SIGHUP, SIG_IGN); - - tree_init(&ctl_conns); - tree_init(&ctl_count); - - memset(&digest, 0, sizeof digest); - digest.startup = time(NULL); - - config_peer(PROC_SCHEDULER); - config_peer(PROC_QUEUE); - config_peer(PROC_PARENT); - config_peer(PROC_LKA); - config_peer(PROC_PONY); - config_peer(PROC_CA); - - control_listen(); - - if (pledge("stdio unix recvfd sendfd", NULL) == -1) - err(1, "pledge"); - - event_dispatch(); - fatalx("exited event loop"); - - return (0); -} - -static void -control_shutdown(void) -{ - log_debug("debug: control agent exiting"); - _exit(0); -} - -static void -control_listen(void) -{ - if (listen(control_state.fd, CONTROL_BACKLOG) == -1) - fatal("control_listen"); - - event_set(&control_state.ev, control_state.fd, EV_READ|EV_PERSIST, - control_accept, NULL); - event_add(&control_state.ev, NULL); -} - -/* ARGSUSED */ -static void -control_accept(int listenfd, short event, void *arg) -{ - int connfd; - socklen_t len; - struct sockaddr_un s_un; - struct ctl_conn *c; - size_t *count; - uid_t euid; - gid_t egid; - - if (getdtablesize() - getdtablecount() < CONTROL_FD_RESERVE) - goto pause; - - len = sizeof(s_un); - if ((connfd = accept(listenfd, (struct sockaddr *)&s_un, &len)) == -1) { - if (errno == ENFILE || errno == EMFILE) - goto pause; - if (errno == EINTR || errno == EWOULDBLOCK || - errno == ECONNABORTED) - return; - fatal("control_accept: accept"); - } - - io_set_nonblocking(connfd); - - if (getpeereid(connfd, &euid, &egid) == -1) - fatal("getpeereid"); - - count = tree_get(&ctl_count, euid); - if (count == NULL) { - count = xcalloc(1, sizeof *count); - tree_xset(&ctl_count, euid, count); - } - - if (*count == CONTROL_MAXCONN_PER_CLIENT) { - close(connfd); - log_warnx("warn: too many connections to control socket " - "from user with uid %lu", (unsigned long int)euid); - return; - } - (*count)++; - - do { - ++connid; - } while (tree_get(&ctl_conns, connid)); - - c = xcalloc(1, sizeof(*c)); - c->euid = euid; - c->egid = egid; - c->id = connid; - c->mproc.proc = PROC_CLIENT; - c->mproc.handler = control_dispatch_ext; - c->mproc.data = c; - if ((c->mproc.name = strdup(proc_title(c->mproc.proc))) == NULL) - fatal("strdup"); - mproc_init(&c->mproc, connfd); - mproc_enable(&c->mproc); - tree_xset(&ctl_conns, c->id, c); - - stat_backend->increment("control.session", 1); - return; - -pause: - log_warnx("warn: ctl client limit hit, disabling new connections"); - event_del(&control_state.ev); -} - -static void -control_close(struct ctl_conn *c) -{ - size_t *count; - - count = tree_xget(&ctl_count, c->euid); - (*count)--; - if (*count == 0) { - tree_xpop(&ctl_count, c->euid); - free(count); - } - tree_xpop(&ctl_conns, c->id); - mproc_clear(&c->mproc); - free(c); - - stat_backend->decrement("control.session", 1); - - if (getdtablesize() - getdtablecount() < CONTROL_FD_RESERVE) - return; - - if (!event_pending(&control_state.ev, EV_READ, NULL)) { - log_warnx("warn: re-enabling ctl connections"); - event_add(&control_state.ev, NULL); - } -} - -static void -control_digest_update(const char *key, size_t value, int incr) -{ - size_t *p; - - p = NULL; - - if (!strcmp(key, "smtp.session")) { - if (incr) - p = &digest.clt_connect; - else - digest.clt_disconnect += value; - } - else if (!strcmp(key, "scheduler.envelope")) { - if (incr) - p = &digest.evp_enqueued; - else - digest.evp_dequeued += value; - } - else if (!strcmp(key, "scheduler.envelope.expired")) - p = &digest.evp_expired; - else if (!strcmp(key, "scheduler.envelope.removed")) - p = &digest.evp_removed; - else if (!strcmp(key, "scheduler.delivery.ok")) - p = &digest.dlv_ok; - else if (!strcmp(key, "scheduler.delivery.permfail")) - p = &digest.dlv_permfail; - else if (!strcmp(key, "scheduler.delivery.tempfail")) - p = &digest.dlv_tempfail; - else if (!strcmp(key, "scheduler.delivery.loop")) - p = &digest.dlv_loop; - - else if (!strcmp(key, "queue.bounce")) - p = &digest.evp_bounce; - - if (p) { - if (incr) - *p = *p + value; - else - *p = *p - value; - } -} - -/* ARGSUSED */ -static void -control_dispatch_ext(struct mproc *p, struct imsg *imsg) -{ - struct sockaddr_storage ss; - struct ctl_conn *c; - int v; - struct stat_kv *kvp; - char *key; - struct stat_value val; - size_t len; - uint64_t evpid; - uint32_t msgid; - - c = p->data; - - if (imsg == NULL) { - control_close(c); - return; - } - - if (imsg->hdr.peerid != IMSG_VERSION) { - m_compose(p, IMSG_CTL_FAIL, IMSG_VERSION, 0, -1, NULL, 0); - return; - } - - switch (imsg->hdr.type) { - case IMSG_CTL_SMTP_SESSION: - if (env->sc_flags & SMTPD_SMTP_PAUSED) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - m_compose(p_pony, IMSG_CTL_SMTP_SESSION, c->id, 0, -1, - &c->euid, sizeof(c->euid)); - return; - - case IMSG_CTL_GET_DIGEST: - if (c->euid) - goto badcred; - digest.timestamp = time(NULL); - m_compose(p, IMSG_CTL_GET_DIGEST, 0, 0, -1, &digest, sizeof digest); - return; - - case IMSG_CTL_GET_STATS: - if (c->euid) - goto badcred; - kvp = imsg->data; - if (!stat_backend->iter(&kvp->iter, &key, &val)) - kvp->iter = NULL; - else { - (void)strlcpy(kvp->key, key, sizeof kvp->key); - kvp->val = val; - } - m_compose(p, IMSG_CTL_GET_STATS, 0, 0, -1, kvp, sizeof *kvp); - return; - - case IMSG_CTL_VERBOSE: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) - goto badcred; - - memcpy(&v, imsg->data, sizeof(v)); - log_trace_verbose(v); - - control_broadcast_verbose(IMSG_CTL_VERBOSE, v); - - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_TRACE_ENABLE: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) - goto badcred; - - memcpy(&v, imsg->data, sizeof(v)); - tracing |= v; - log_trace_verbose(tracing); - - control_broadcast_verbose(IMSG_CTL_VERBOSE, tracing); - - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_TRACE_DISABLE: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) - goto badcred; - - memcpy(&v, imsg->data, sizeof(v)); - tracing &= ~v; - log_trace_verbose(tracing); - - control_broadcast_verbose(IMSG_CTL_VERBOSE, tracing); - - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_PROFILE_ENABLE: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) - goto badcred; - - memcpy(&v, imsg->data, sizeof(v)); - profiling |= v; - - control_broadcast_verbose(IMSG_CTL_PROFILE, profiling); - - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_PROFILE_DISABLE: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof(v)) - goto badcred; - - memcpy(&v, imsg->data, sizeof(v)); - profiling &= ~v; - - control_broadcast_verbose(IMSG_CTL_PROFILE, profiling); - - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_PAUSE_EVP: - if (c->euid) - goto badcred; - - imsg->hdr.peerid = c->id; - m_forward(p_scheduler, imsg); - return; - - case IMSG_CTL_PAUSE_MDA: - if (c->euid) - goto badcred; - - if (env->sc_flags & SMTPD_MDA_PAUSED) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - log_info("info: mda paused"); - env->sc_flags |= SMTPD_MDA_PAUSED; - m_compose(p_queue, IMSG_CTL_PAUSE_MDA, 0, 0, -1, NULL, 0); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_PAUSE_MTA: - if (c->euid) - goto badcred; - - if (env->sc_flags & SMTPD_MTA_PAUSED) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - log_info("info: mta paused"); - env->sc_flags |= SMTPD_MTA_PAUSED; - m_compose(p_queue, IMSG_CTL_PAUSE_MTA, 0, 0, -1, NULL, 0); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_PAUSE_SMTP: - if (c->euid) - goto badcred; - - if (env->sc_flags & SMTPD_SMTP_PAUSED) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - log_info("info: smtp paused"); - env->sc_flags |= SMTPD_SMTP_PAUSED; - m_compose(p_pony, IMSG_CTL_PAUSE_SMTP, 0, 0, -1, NULL, 0); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_RESUME_EVP: - if (c->euid) - goto badcred; - - imsg->hdr.peerid = c->id; - m_forward(p_scheduler, imsg); - return; - - case IMSG_CTL_RESUME_MDA: - if (c->euid) - goto badcred; - - if (!(env->sc_flags & SMTPD_MDA_PAUSED)) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - log_info("info: mda resumed"); - env->sc_flags &= ~SMTPD_MDA_PAUSED; - m_compose(p_queue, IMSG_CTL_RESUME_MDA, 0, 0, -1, NULL, 0); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_RESUME_MTA: - if (c->euid) - goto badcred; - - if (!(env->sc_flags & SMTPD_MTA_PAUSED)) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - log_info("info: mta resumed"); - env->sc_flags &= ~SMTPD_MTA_PAUSED; - m_compose(p_queue, IMSG_CTL_RESUME_MTA, 0, 0, -1, NULL, 0); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_RESUME_SMTP: - if (c->euid) - goto badcred; - - if (!(env->sc_flags & SMTPD_SMTP_PAUSED)) { - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); - return; - } - log_info("info: smtp resumed"); - env->sc_flags &= ~SMTPD_SMTP_PAUSED; - m_forward(p_pony, imsg); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_RESUME_ROUTE: - if (c->euid) - goto badcred; - - m_forward(p_pony, imsg); - m_compose(p, IMSG_CTL_OK, 0, 0, -1, NULL, 0); - return; - - case IMSG_CTL_LIST_MESSAGES: - if (c->euid) - goto badcred; - m_compose(p_scheduler, IMSG_CTL_LIST_MESSAGES, c->id, 0, -1, - imsg->data, imsg->hdr.len - sizeof(imsg->hdr)); - return; - - case IMSG_CTL_LIST_ENVELOPES: - if (c->euid) - goto badcred; - m_compose(p_scheduler, IMSG_CTL_LIST_ENVELOPES, c->id, 0, -1, - imsg->data, imsg->hdr.len - sizeof(imsg->hdr)); - return; - - case IMSG_CTL_MTA_SHOW_HOSTS: - case IMSG_CTL_MTA_SHOW_RELAYS: - case IMSG_CTL_MTA_SHOW_ROUTES: - case IMSG_CTL_MTA_SHOW_HOSTSTATS: - case IMSG_CTL_MTA_SHOW_BLOCK: - if (c->euid) - goto badcred; - - imsg->hdr.peerid = c->id; - m_forward(p_pony, imsg); - return; - - case IMSG_CTL_SHOW_STATUS: - if (c->euid) - goto badcred; - - m_compose(p, IMSG_CTL_SHOW_STATUS, 0, 0, -1, &env->sc_flags, - sizeof(env->sc_flags)); - return; - - case IMSG_CTL_MTA_BLOCK: - case IMSG_CTL_MTA_UNBLOCK: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE <= sizeof(ss)) - goto invalid; - memmove(&ss, imsg->data, sizeof(ss)); - m_create(p_pony, imsg->hdr.type, c->id, 0, -1); - m_add_sockaddr(p_pony, (struct sockaddr *)&ss); - m_add_string(p_pony, (char *)imsg->data + sizeof(ss)); - m_close(p_pony); - return; - - case IMSG_CTL_SCHEDULE: - if (c->euid) - goto badcred; - - imsg->hdr.peerid = c->id; - m_forward(p_scheduler, imsg); - return; - - case IMSG_CTL_REMOVE: - if (c->euid) - goto badcred; - - imsg->hdr.peerid = c->id; - m_forward(p_scheduler, imsg); - return; - - case IMSG_CTL_UPDATE_TABLE: - if (c->euid) - goto badcred; - - /* table name too long */ - len = strlen(imsg->data); - if (len >= LINE_MAX) - goto invalid; - - imsg->hdr.peerid = c->id; - m_forward(p_lka, imsg); - return; - - case IMSG_CTL_DISCOVER_EVPID: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof evpid) - goto invalid; - - memmove(&evpid, imsg->data, sizeof evpid); - m_create(p_queue, imsg->hdr.type, c->id, 0, -1); - m_add_evpid(p_queue, evpid); - m_close(p_queue); - return; - - case IMSG_CTL_DISCOVER_MSGID: - if (c->euid) - goto badcred; - - if (imsg->hdr.len - IMSG_HEADER_SIZE != sizeof msgid) - goto invalid; - - memmove(&msgid, imsg->data, sizeof msgid); - m_create(p_queue, imsg->hdr.type, c->id, 0, -1); - m_add_msgid(p_queue, msgid); - m_close(p_queue); - return; - - default: - log_debug("debug: control_dispatch_ext: " - "error handling %s imsg", - imsg_to_str(imsg->hdr.type)); - return; - } -badcred: -invalid: - m_compose(p, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); -} - -static void -control_broadcast_verbose(int msg, int v) -{ - m_create(p_lka, msg, 0, 0, -1); - m_add_int(p_lka, v); - m_close(p_lka); - - m_create(p_pony, msg, 0, 0, -1); - m_add_int(p_pony, v); - m_close(p_pony); - - m_create(p_queue, msg, 0, 0, -1); - m_add_int(p_queue, v); - m_close(p_queue); - - m_create(p_ca, msg, 0, 0, -1); - m_add_int(p_ca, v); - m_close(p_ca); - - m_create(p_scheduler, msg, 0, 0, -1); - m_add_int(p_scheduler, v); - m_close(p_scheduler); - - m_create(p_parent, msg, 0, 0, -1); - m_add_int(p_parent, v); - m_close(p_parent); -} diff --git a/crypto.c b/crypto.c deleted file mode 100644 index b6a7547c..00000000 --- a/crypto.c +++ /dev/null @@ -1,398 +0,0 @@ -/* $OpenBSD: crypto.c,v 1.8 2019/06/28 13:32:50 deraadt Exp $ */ - -/* - * Copyright (c) 2013 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -#include -#include - -#include - - -#define CRYPTO_BUFFER_SIZE 16384 - -#define GCM_TAG_SIZE 16 -#define IV_SIZE 12 -#define KEY_SIZE 32 - -/* bump if we ever switch from aes-256-gcm to anything else */ -#define API_VERSION 1 - - -int crypto_setup(const char *, size_t); -int crypto_encrypt_file(FILE *, FILE *); -int crypto_decrypt_file(FILE *, FILE *); -size_t crypto_encrypt_buffer(const char *, size_t, char *, size_t); -size_t crypto_decrypt_buffer(const char *, size_t, char *, size_t); - -static struct crypto_ctx { - unsigned char key[KEY_SIZE]; -} cp; - -int -crypto_setup(const char *key, size_t len) -{ - if (len != KEY_SIZE) - return 0; - - memset(&cp, 0, sizeof cp); - - /* openssl rand -hex 16 */ - memcpy(cp.key, key, sizeof cp.key); - - return 1; -} - -int -crypto_encrypt_file(FILE * in, FILE * out) -{ - EVP_CIPHER_CTX *ctx; - uint8_t ibuf[CRYPTO_BUFFER_SIZE]; - uint8_t obuf[CRYPTO_BUFFER_SIZE]; - uint8_t iv[IV_SIZE]; - uint8_t tag[GCM_TAG_SIZE]; - uint8_t version = API_VERSION; - size_t r, w; - int len; - int ret = 0; - struct stat sb; - - /* XXX - Do NOT encrypt files bigger than 64GB */ - if (fstat(fileno(in), &sb) == -1) - return 0; - if (sb.st_size >= 0x1000000000LL) - return 0; - - /* prepend version byte*/ - if ((w = fwrite(&version, 1, sizeof version, out)) != sizeof version) - return 0; - - /* generate and prepend IV */ - memset(iv, 0, sizeof iv); - arc4random_buf(iv, sizeof iv); - if ((w = fwrite(iv, 1, sizeof iv, out)) != sizeof iv) - return 0; - - ctx = EVP_CIPHER_CTX_new(); - if (ctx == NULL) - return 0; - - EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); - - /* encrypt until end of file */ - while ((r = fread(ibuf, 1, CRYPTO_BUFFER_SIZE, in)) != 0) { - if (!EVP_EncryptUpdate(ctx, obuf, &len, ibuf, r)) - goto end; - if (len && (w = fwrite(obuf, len, 1, out)) != 1) - goto end; - } - if (!feof(in)) - goto end; - - /* finalize and write last chunk if any */ - if (!EVP_EncryptFinal_ex(ctx, obuf, &len)) - goto end; - if (len && (w = fwrite(obuf, len, 1, out)) != 1) - goto end; - - /* get and append tag */ - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, sizeof tag, tag); - if ((w = fwrite(tag, sizeof tag, 1, out)) != 1) - goto end; - - fflush(out); - ret = 1; - -end: - EVP_CIPHER_CTX_free(ctx); - return ret; -} - -int -crypto_decrypt_file(FILE * in, FILE * out) -{ - EVP_CIPHER_CTX *ctx; - uint8_t ibuf[CRYPTO_BUFFER_SIZE]; - uint8_t obuf[CRYPTO_BUFFER_SIZE]; - uint8_t iv[IV_SIZE]; - uint8_t tag[GCM_TAG_SIZE]; - uint8_t version; - size_t r, w; - off_t sz; - int len; - int ret = 0; - struct stat sb; - - /* input file too small to be an encrypted file */ - if (fstat(fileno(in), &sb) == -1) - return 0; - if (sb.st_size <= (off_t) (sizeof version + sizeof tag + sizeof iv)) - return 0; - sz = sb.st_size; - - /* extract tag */ - if (fseek(in, -sizeof(tag), SEEK_END) == -1) - return 0; - if ((r = fread(tag, 1, sizeof tag, in)) != sizeof tag) - return 0; - - if (fseek(in, 0, SEEK_SET) == -1) - return 0; - - /* extract version */ - if ((r = fread(&version, 1, sizeof version, in)) != sizeof version) - return 0; - if (version != API_VERSION) - return 0; - - /* extract IV */ - memset(iv, 0, sizeof iv); - if ((r = fread(iv, 1, sizeof iv, in)) != sizeof iv) - return 0; - - /* real ciphertext length */ - sz -= sizeof version; - sz -= sizeof iv; - sz -= sizeof tag; - - ctx = EVP_CIPHER_CTX_new(); - if (ctx == NULL) - return 0; - - EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); - - /* set expected tag */ - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, sizeof tag, tag); - - /* decrypt until end of ciphertext */ - while (sz) { - if (sz > CRYPTO_BUFFER_SIZE) - r = fread(ibuf, 1, CRYPTO_BUFFER_SIZE, in); - else - r = fread(ibuf, 1, sz, in); - if (!r) - break; - if (!EVP_DecryptUpdate(ctx, obuf, &len, ibuf, r)) - goto end; - if (len && (w = fwrite(obuf, len, 1, out)) != 1) - goto end; - sz -= r; - } - if (ferror(in)) - goto end; - - /* finalize, write last chunk if any and perform authentication check */ - if (!EVP_DecryptFinal_ex(ctx, obuf, &len)) - goto end; - if (len && (w = fwrite(obuf, len, 1, out)) != 1) - goto end; - - fflush(out); - ret = 1; - -end: - EVP_CIPHER_CTX_free(ctx); - return ret; -} - -size_t -crypto_encrypt_buffer(const char *in, size_t inlen, char *out, size_t outlen) -{ - EVP_CIPHER_CTX *ctx; - uint8_t iv[IV_SIZE]; - uint8_t tag[GCM_TAG_SIZE]; - uint8_t version = API_VERSION; - off_t sz; - int olen; - int len = 0; - int ret = 0; - - /* output buffer does not have enough room */ - if (outlen < inlen + sizeof version + sizeof tag + sizeof iv) - return 0; - - /* input should not exceed 64GB */ - sz = inlen; - if (sz >= 0x1000000000LL) - return 0; - - /* prepend version */ - *out = version; - len++; - - /* generate IV */ - memset(iv, 0, sizeof iv); - arc4random_buf(iv, sizeof iv); - memcpy(out + len, iv, sizeof iv); - len += sizeof iv; - - ctx = EVP_CIPHER_CTX_new(); - if (ctx == NULL) - return 0; - - EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); - - /* encrypt buffer */ - if (!EVP_EncryptUpdate(ctx, out + len, &olen, in, inlen)) - goto end; - len += olen; - - /* finalize and write last chunk if any */ - if (!EVP_EncryptFinal_ex(ctx, out + len, &olen)) - goto end; - len += olen; - - /* get and append tag */ - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, sizeof tag, tag); - memcpy(out + len, tag, sizeof tag); - ret = len + sizeof tag; - -end: - EVP_CIPHER_CTX_free(ctx); - return ret; -} - -size_t -crypto_decrypt_buffer(const char *in, size_t inlen, char *out, size_t outlen) -{ - EVP_CIPHER_CTX *ctx; - uint8_t iv[IV_SIZE]; - uint8_t tag[GCM_TAG_SIZE]; - int olen; - int len = 0; - int ret = 0; - - /* out does not have enough room */ - if (outlen < inlen - sizeof tag + sizeof iv) - return 0; - - /* extract tag */ - memcpy(tag, in + inlen - sizeof tag, sizeof tag); - inlen -= sizeof tag; - - /* check version */ - if (*in != API_VERSION) - return 0; - in++; - inlen--; - - /* extract IV */ - memset(iv, 0, sizeof iv); - memcpy(iv, in, sizeof iv); - inlen -= sizeof iv; - in += sizeof iv; - - ctx = EVP_CIPHER_CTX_new(); - if (ctx == NULL) - return 0; - - EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); - - /* set expected tag */ - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, sizeof tag, tag); - - /* decrypt buffer */ - if (!EVP_DecryptUpdate(ctx, out, &olen, in, inlen)) - goto end; - len += olen; - - /* finalize, write last chunk if any and perform authentication check */ - if (!EVP_DecryptFinal_ex(ctx, out + len, &olen)) - goto end; - ret = len + olen; - -end: - EVP_CIPHER_CTX_free(ctx); - return ret; -} - -#if 0 -int -main(int argc, char *argv[]) -{ - if (argc != 3) { - printf("usage: crypto \n"); - return 1; - } - - if (!crypto_setup(argv[1], strlen(argv[1]))) { - printf("crypto_setup failed\n"); - return 1; - } - - { - char encbuffer[4096]; - size_t enclen; - char decbuffer[4096]; - size_t declen; - - printf("encrypt/decrypt buffer: "); - enclen = crypto_encrypt_buffer(argv[2], strlen(argv[2]), - encbuffer, sizeof encbuffer); - - /* uncomment below to provoke integrity check failure */ - /* - * encbuffer[13] = 0x42; - * encbuffer[14] = 0x42; - * encbuffer[15] = 0x42; - * encbuffer[16] = 0x42; - */ - - declen = crypto_decrypt_buffer(encbuffer, enclen, - decbuffer, sizeof decbuffer); - if (declen != 0 && !strncmp(argv[2], decbuffer, declen)) - printf("ok\n"); - else - printf("nope\n"); - } - - { - FILE *fpin; - FILE *fpout; - printf("encrypt/decrypt file: "); - - fpin = fopen("/etc/passwd", "r"); - fpout = fopen("/tmp/passwd.enc", "w"); - if (!crypto_encrypt_file(fpin, fpout)) { - printf("encryption failed\n"); - return 1; - } - fclose(fpin); - fclose(fpout); - - /* uncomment below to provoke integrity check failure */ - /* - * fpin = fopen("/tmp/passwd.enc", "a"); - * fprintf(fpin, "borken"); - * fclose(fpin); - */ - fpin = fopen("/tmp/passwd.enc", "r"); - fpout = fopen("/tmp/passwd.dec", "w"); - if (!crypto_decrypt_file(fpin, fpout)) - printf("nope\n"); - else - printf("ok\n"); - fclose(fpin); - fclose(fpout); - } - - - return 0; -} -#endif diff --git a/dict.c b/dict.c deleted file mode 100644 index 91156d5a..00000000 --- a/dict.c +++ /dev/null @@ -1,267 +0,0 @@ -/* $OpenBSD: dict.c,v 1.6 2018/12/23 16:06:24 gilles Exp $ */ - -/* - * Copyright (c) 2012 Gilles Chehade - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -#include -#include -#include -#include - -#include "dict.h" - -struct dictentry { - SPLAY_ENTRY(dictentry) entry; - const char *key; - void *data; -}; - -static int dictentry_cmp(struct dictentry *, struct dictentry *); - -SPLAY_PROTOTYPE(_dict, dictentry, entry, dictentry_cmp); - -int -dict_check(struct dict *d, const char *k) -{ - struct dictentry key; - - key.key = k; - return (SPLAY_FIND(_dict, &d->dict, &key) != NULL); -} - -static inline struct dictentry * -dict_alloc(const char *k, void *data) -{ - struct dictentry *e; - size_t s = strlen(k) + 1; - void *t; - - if ((e = malloc(sizeof(*e) + s)) == NULL) - return NULL; - - e->key = t = (char*)(e) + sizeof(*e); - e->data = data; - memmove(t, k, s); - - return (e); -} - -void * -dict_set(struct dict *d, const char *k, void *data) -{ - struct dictentry *entry, key; - char *old; - - key.key = k; - if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL) { - if ((entry = dict_alloc(k, data)) == NULL) - err(1, "dict_set: malloc"); - SPLAY_INSERT(_dict, &d->dict, entry); - old = NULL; - d->count += 1; - } else { - old = entry->data; - entry->data = data; - } - - return (old); -} - -void -dict_xset(struct dict *d, const char * k, void *data) -{ - struct dictentry *entry; - - if ((entry = dict_alloc(k, data)) == NULL) - err(1, "dict_xset: malloc"); - if (SPLAY_INSERT(_dict, &d->dict, entry)) - errx(1, "dict_xset(%p, %s)", d, k); - d->count += 1; -} - -void * -dict_get(struct dict *d, const char *k) -{ - struct dictentry key, *entry; - - key.key = k; - if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL) - return (NULL); - - return (entry->data); -} - -void * -dict_xget(struct dict *d, const char *k) -{ - struct dictentry key, *entry; - - key.key = k; - if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL) - errx(1, "dict_xget(%p, %s)", d, k); - - return (entry->data); -} - -void * -dict_pop(struct dict *d, const char *k) -{ - struct dictentry key, *entry; - void *data; - - key.key = k; - if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL) - return (NULL); - - data = entry->data; - SPLAY_REMOVE(_dict, &d->dict, entry); - free(entry); - d->count -= 1; - - return (data); -} - -void * -dict_xpop(struct dict *d, const char *k) -{ - struct dictentry key, *entry; - void *data; - - key.key = k; - if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL) - errx(1, "dict_xpop(%p, %s)", d, k); - - data = entry->data; - SPLAY_REMOVE(_dict, &d->dict, entry); - free(entry); - d->count -= 1; - - return (data); -} - -int -dict_poproot(struct dict *d, void **data) -{ - struct dictentry *entry; - - entry = SPLAY_ROOT(&d->dict); - if (entry == NULL) - return (0); - if (data) - *data = entry->data; - SPLAY_REMOVE(_dict, &d->dict, entry); - free(entry); - d->count -= 1; - - return (1); -} - -int -dict_root(struct dict *d, const char **k, void **data) -{ - struct dictentry *entry; - - entry = SPLAY_ROOT(&d->dict); - if (entry == NULL) - return (0); - if (k) - *k = entry->key; - if (data) - *data = entry->data; - return (1); -} - -int -dict_iter(struct dict *d, void **hdl, const char **k, void **data) -{ - struct dictentry *curr = *hdl; - - if (curr == NULL) - curr = SPLAY_MIN(_dict, &d->dict); - else - curr = SPLAY_NEXT(_dict, &d->dict, curr); - - if (curr) { - *hdl = curr; - if (k) - *k = curr->key; - if (data) - *data = curr->data; - return (1); - } - - return (0); -} - -int -dict_iterfrom(struct dict *d, void **hdl, const char *kfrom, const char **k, - void **data) -{ - struct dictentry *curr = *hdl, key; - - if (curr == NULL) { - if (kfrom == NULL) - curr = SPLAY_MIN(_dict, &d->dict); - else { - key.key = kfrom; - curr = SPLAY_FIND(_dict, &d->dict, &key); - if (curr == NULL) { - SPLAY_INSERT(_dict, &d->dict, &key); - curr = SPLAY_NEXT(_dict, &d->dict, &key); - SPLAY_REMOVE(_dict, &d->dict, &key); - } - } - } else - curr = SPLAY_NEXT(_dict, &d->dict, curr); - - if (curr) { - *hdl = curr; - if (k) - *k = curr->key; - if (data) - *data = curr->data; - return (1); - } - - return (0); -} - -void -dict_merge(struct dict *dst, struct dict *src) -{ - struct dictentry *entry; - - while (!SPLAY_EMPTY(&src->dict)) { - entry = SPLAY_ROOT(&src->dict); - SPLAY_REMOVE(_dict, &src->dict, entry); - if (SPLAY_INSERT(_dict, &dst->dict, entry)) - errx(1, "dict_merge: duplicate"); - } - dst->count += src->count; - src->count = 0; -} - -static int -dictentry_cmp(struct dictentry *a, struct dictentry *b) -{ - return strcmp(a->key, b->key); -} - -SPLAY_GENERATE(_dict, dictentry, entry, dictentry_cmp); diff --git a/dict.h b/dict.h deleted file mode 100644 index c5d47e1a..00000000 --- a/dict.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $OpenBSD: dict.h,v 1.1 2018/12/23 16:06:24 gilles Exp $ */ - -/* - * Copyright (c) 2013 Eric Faurot - * Copyright (c) 2011 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _DICT_H_ -#define _DICT_H_ - -SPLAY_HEAD(_dict, dictentry); - -struct dict { - struct _dict dict; - size_t count; -}; - - -/* dict.c */ -#define dict_init(d) do { SPLAY_INIT(&((d)->dict)); (d)->count = 0; } while(0) -#define dict_empty(d) SPLAY_EMPTY(&((d)->dict)) -#define dict_count(d) ((d)->count) -int dict_check(struct dict *, const char *); -void *dict_set(struct dict *, const char *, void *); -void dict_xset(struct dict *, const char *, void *); -void *dict_get(struct dict *, const char *); -void *dict_xget(struct dict *, const char *); -void *dict_pop(struct dict *, const char *); -void *dict_xpop(struct dict *, const char *); -int dict_poproot(struct dict *, void **); -int dict_root(struct dict *, const char **, void **); -int dict_iter(struct dict *, void **, const char **, void **); -int dict_iterfrom(struct dict *, void **, const char *, const char **, void **); -void dict_merge(struct dict *, struct dict *); - -#endif diff --git a/dns.c b/dns.c deleted file mode 100644 index d5b66af9..00000000 --- a/dns.c +++ /dev/null @@ -1,367 +0,0 @@ -/* $OpenBSD: dns.c,v 1.89 2019/09/18 11:26:30 eric Exp $ */ - -/* - * Copyright (c) 2008 Gilles Chehade - * Copyright (c) 2009 Jacek Masiulaniec - * Copyright (c) 2011-2014 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" -#include "unpack_dns.h" - -struct dns_lookup { - struct dns_session *session; - char *host; - int preference; -}; - -struct dns_session { - struct mproc *p; - uint64_t reqid; - int type; - char name[HOST_NAME_MAX+1]; - size_t mxfound; - int error; - int refcount; -}; - -static void dns_lookup_host(struct dns_session *, const char *, int); -static void dns_dispatch_host(struct asr_result *, void *); -static void dns_dispatch_mx(struct asr_result *, void *); -static void dns_dispatch_mx_preference(struct asr_result *, void *); - -static int -domainname_is_addr(const char *s, struct sockaddr *sa, socklen_t *sl) -{ - struct addrinfo hints, *res; - socklen_t sl2; - size_t l; - char buf[SMTPD_MAXDOMAINPARTSIZE]; - int i6, error; - - if (*s != '[') - return (0); - - i6 = (strncasecmp("[IPv6:", s, 6) == 0); - s += i6 ? 6 : 1; - - l = strlcpy(buf, s, sizeof(buf)); - if (l >= sizeof(buf) || l == 0 || buf[l - 1] != ']') - return (0); - - buf[l - 1] = '\0'; - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_NUMERICHOST; - hints.ai_socktype = SOCK_STREAM; - if (i6) - hints.ai_family = AF_INET6; - - res = NULL; - if ((error = getaddrinfo(buf, NULL, &hints, &res))) { - log_warnx("getaddrinfo: %s", gai_strerror(error)); - } - - if (!res) - return (0); - - if (sa && sl) { - sl2 = *sl; - if (sl2 > res->ai_addrlen) - sl2 = res->ai_addrlen; - memmove(sa, res->ai_addr, sl2); - *sl = res->ai_addrlen; - } - - freeaddrinfo(res); - return (1); -} - -void -dns_imsg(struct mproc *p, struct imsg *imsg) -{ - struct sockaddr_storage ss; - struct dns_session *s; - struct sockaddr *sa; - struct asr_query *as; - struct msg m; - const char *domain, *mx, *host; - socklen_t sl; - - s = xcalloc(1, sizeof *s); - s->type = imsg->hdr.type; - s->p = p; - - m_msg(&m, imsg); - m_get_id(&m, &s->reqid); - - switch (s->type) { - - case IMSG_MTA_DNS_HOST: - m_get_string(&m, &host); - m_end(&m); - dns_lookup_host(s, host, -1); - return; - - case IMSG_MTA_DNS_MX: - m_get_string(&m, &domain); - m_end(&m); - (void)strlcpy(s->name, domain, sizeof(s->name)); - - sa = (struct sockaddr *)&ss; - sl = sizeof(ss); - - if (domainname_is_addr(domain, sa, &sl)) { - m_create(s->p, IMSG_MTA_DNS_HOST, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_string(s->p, sockaddr_to_text(sa)); - m_add_sockaddr(s->p, sa); - m_add_int(s->p, -1); - m_close(s->p); - - m_create(s->p, IMSG_MTA_DNS_HOST_END, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_int(s->p, DNS_OK); - m_close(s->p); - free(s); - return; - } - - as = res_query_async(s->name, C_IN, T_MX, NULL); - if (as == NULL) { - log_warn("warn: res_query_async: %s", s->name); - m_create(s->p, IMSG_MTA_DNS_HOST_END, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_int(s->p, DNS_EINVAL); - m_close(s->p); - free(s); - return; - } - - event_asr_run(as, dns_dispatch_mx, s); - return; - - case IMSG_MTA_DNS_MX_PREFERENCE: - m_get_string(&m, &domain); - m_get_string(&m, &mx); - m_end(&m); - (void)strlcpy(s->name, mx, sizeof(s->name)); - - as = res_query_async(domain, C_IN, T_MX, NULL); - if (as == NULL) { - m_create(s->p, IMSG_MTA_DNS_MX_PREFERENCE, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_int(s->p, DNS_ENOTFOUND); - m_close(s->p); - free(s); - return; - } - - event_asr_run(as, dns_dispatch_mx_preference, s); - return; - - default: - log_warnx("warn: bad dns request %d", s->type); - fatal(NULL); - } -} - -static void -dns_dispatch_host(struct asr_result *ar, void *arg) -{ - struct dns_session *s; - struct dns_lookup *lookup = arg; - struct addrinfo *ai; - - s = lookup->session; - - for (ai = ar->ar_addrinfo; ai; ai = ai->ai_next) { - s->mxfound++; - m_create(s->p, IMSG_MTA_DNS_HOST, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_string(s->p, lookup->host); - m_add_sockaddr(s->p, ai->ai_addr); - m_add_int(s->p, lookup->preference); - m_close(s->p); - } - free(lookup->host); - free(lookup); - if (ar->ar_addrinfo) - freeaddrinfo(ar->ar_addrinfo); - - if (ar->ar_gai_errno) - s->error = ar->ar_gai_errno; - - if (--s->refcount) - return; - - m_create(s->p, IMSG_MTA_DNS_HOST_END, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_int(s->p, s->mxfound ? DNS_OK : DNS_ENOTFOUND); - m_close(s->p); - free(s); -} - -static void -dns_dispatch_mx(struct asr_result *ar, void *arg) -{ - struct dns_session *s = arg; - struct unpack pack; - struct dns_header h; - struct dns_query q; - struct dns_rr rr; - char buf[512]; - size_t found; - - if (ar->ar_h_errno && ar->ar_h_errno != NO_DATA && - ar->ar_h_errno != NOTIMP) { - - m_create(s->p, IMSG_MTA_DNS_HOST_END, 0, 0, -1); - m_add_id(s->p, s->reqid); - if (ar->ar_rcode == NXDOMAIN) - m_add_int(s->p, DNS_ENONAME); - else if (ar->ar_h_errno == NO_RECOVERY) - m_add_int(s->p, DNS_EINVAL); - else - m_add_int(s->p, DNS_RETRY); - m_close(s->p); - free(s); - free(ar->ar_data); - return; - } - - unpack_init(&pack, ar->ar_data, ar->ar_datalen); - unpack_header(&pack, &h); - unpack_query(&pack, &q); - - found = 0; - for (; h.ancount; h.ancount--) { - unpack_rr(&pack, &rr); - if (rr.rr_type != T_MX) - continue; - print_dname(rr.rr.mx.exchange, buf, sizeof(buf)); - buf[strlen(buf) - 1] = '\0'; - dns_lookup_host(s, buf, rr.rr.mx.preference); - found++; - } - free(ar->ar_data); - - /* fallback to host if no MX is found. */ - if (found == 0) - dns_lookup_host(s, s->name, 0); -} - -static void -dns_dispatch_mx_preference(struct asr_result *ar, void *arg) -{ - struct dns_session *s = arg; - struct unpack pack; - struct dns_header h; - struct dns_query q; - struct dns_rr rr; - char buf[512]; - int error; - - if (ar->ar_h_errno) { - if (ar->ar_rcode == NXDOMAIN) - error = DNS_ENONAME; - else if (ar->ar_h_errno == NO_RECOVERY - || ar->ar_h_errno == NO_DATA) - error = DNS_EINVAL; - else - error = DNS_RETRY; - } - else { - error = DNS_ENOTFOUND; - unpack_init(&pack, ar->ar_data, ar->ar_datalen); - unpack_header(&pack, &h); - unpack_query(&pack, &q); - for (; h.ancount; h.ancount--) { - unpack_rr(&pack, &rr); - if (rr.rr_type != T_MX) - continue; - print_dname(rr.rr.mx.exchange, buf, sizeof(buf)); - buf[strlen(buf) - 1] = '\0'; - if (!strcasecmp(s->name, buf)) { - error = DNS_OK; - break; - } - } - } - - free(ar->ar_data); - - m_create(s->p, IMSG_MTA_DNS_MX_PREFERENCE, 0, 0, -1); - m_add_id(s->p, s->reqid); - m_add_int(s->p, error); - if (error == DNS_OK) - m_add_int(s->p, rr.rr.mx.preference); - m_close(s->p); - free(s); -} - -static void -dns_lookup_host(struct dns_session *s, const char *host, int preference) -{ - struct dns_lookup *lookup; - struct addrinfo hints; - char hostcopy[HOST_NAME_MAX+1]; - char *p; - void *as; - - lookup = xcalloc(1, sizeof *lookup); - lookup->preference = preference; - lookup->host = xstrdup(host); - lookup->session = s; - s->refcount++; - - if (*host == '[') { - if (strncasecmp("[IPv6:", host, 6) == 0) - host += 6; - else - host += 1; - (void)strlcpy(hostcopy, host, sizeof hostcopy); - p = strchr(hostcopy, ']'); - if (p) - *p = 0; - host = hostcopy; - } - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_ADDRCONFIG; - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - as = getaddrinfo_async(host, NULL, &hints, NULL); - event_asr_run(as, dns_dispatch_host, lookup); -} diff --git a/enqueue.c b/enqueue.c deleted file mode 100644 index b92f8ca2..00000000 --- a/enqueue.c +++ /dev/null @@ -1,927 +0,0 @@ -/* $OpenBSD: enqueue.c,v 1.118 2020/03/18 20:17:14 eric Exp $ */ - -/* - * Copyright (c) 2005 Henning Brauer - * Copyright (c) 2009 Jacek Masiulaniec - * Copyright (c) 2012 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" - -extern struct imsgbuf *ibuf; - -void usage(void); -static void build_from(char *, struct passwd *); -static int parse_message(FILE *, int, int, FILE *); -static void parse_addr(char *, size_t, int); -static void parse_addr_terminal(int); -static char *qualify_addr(char *); -static void rcpt_add(char *); -static int open_connection(void); -static int get_responses(FILE *, int); -static int send_line(FILE *, int, char *, ...); -static int enqueue_offline(int, char *[], FILE *, FILE *); -static int savedeadletter(struct passwd *, FILE *); - -extern int srv_connected(void); - -enum headerfields { - HDR_NONE, - HDR_FROM, - HDR_TO, - HDR_CC, - HDR_BCC, - HDR_SUBJECT, - HDR_DATE, - HDR_MSGID, - HDR_MIME_VERSION, - HDR_CONTENT_TYPE, - HDR_CONTENT_DISPOSITION, - HDR_CONTENT_TRANSFER_ENCODING, - HDR_USER_AGENT -}; - -struct { - char *word; - enum headerfields type; -} keywords[] = { - { "From:", HDR_FROM }, - { "To:", HDR_TO }, - { "Cc:", HDR_CC }, - { "Bcc:", HDR_BCC }, - { "Subject:", HDR_SUBJECT }, - { "Date:", HDR_DATE }, - { "Message-Id:", HDR_MSGID }, - { "MIME-Version:", HDR_MIME_VERSION }, - { "Content-Type:", HDR_CONTENT_TYPE }, - { "Content-Disposition:", HDR_CONTENT_DISPOSITION }, - { "Content-Transfer-Encoding:", HDR_CONTENT_TRANSFER_ENCODING }, - { "User-Agent:", HDR_USER_AGENT }, -}; - -#define LINESPLIT 990 -#define SMTP_LINELEN 1000 -#define TIMEOUTMSG "Timeout\n" - -#define WSP(c) (c == ' ' || c == '\t') - -int verbose = 0; -static char host[HOST_NAME_MAX+1]; -char *user = NULL; -time_t timestamp; - -struct { - int fd; - char *from; - char *fromname; - char **rcpts; - char *dsn_notify; - char *dsn_ret; - char *dsn_envid; - int rcpt_cnt; - int need_linesplit; - int saw_date; - int saw_msgid; - int saw_from; - int saw_mime_version; - int saw_content_type; - int saw_content_disposition; - int saw_content_transfer_encoding; - int saw_user_agent; - int noheader; -} msg; - -struct { - uint quote; - uint comment; - uint esc; - uint brackets; - size_t wpos; - char buf[SMTP_LINELEN]; -} pstate; - -#define QP_TEST_WRAP(fp, buf, linelen, size) do { \ - if (((linelen) += (size)) + 1 > 76) { \ - fprintf((fp), "=\r\n"); \ - if (buf[0] == '.') \ - fprintf((fp), "."); \ - (linelen) = (size); \ - } \ -} while (0) - -/* RFC 2045 section 6.7 */ -static void -qp_encoded_write(FILE *fp, char *buf) -{ - size_t linelen = 0; - - for (;buf[0] != '\0' && buf[0] != '\n'; buf++) { - /* - * Point 3: Any TAB (HT) or SPACE characters on an encoded line - * MUST thus be followed on that line by a printable character. - * - * Ergo, only encode if the next character is EOL. - */ - if (buf[0] == ' ' || buf[0] == '\t') { - if (buf[1] == '\n') { - QP_TEST_WRAP(fp, buf, linelen, 3); - fprintf(fp, "=%2X", *buf & 0xff); - } else { - QP_TEST_WRAP(fp, buf, linelen, 1); - fprintf(fp, "%c", *buf & 0xff); - } - /* - * Point 1, with exclusion of point 2, skip EBCDIC NOTE. - * Do this after whitespace check, else they would match here. - */ - } else if (!((buf[0] >= 33 && buf[0] <= 60) || - (buf[0] >= 62 && buf[0] <= 126))) { - QP_TEST_WRAP(fp, buf, linelen, 3); - fprintf(fp, "=%2X", *buf & 0xff); - /* Point 2: 33 through 60 inclusive, and 62 through 126 */ - } else { - QP_TEST_WRAP(fp, buf, linelen, 1); - fprintf(fp, "%c", *buf); - } - } - fprintf(fp, "\r\n"); -} - -int -enqueue(int argc, char *argv[], FILE *ofp) -{ - int i, ch, tflag = 0; - char *fake_from = NULL, *buf = NULL; - struct passwd *pw; - FILE *fp = NULL, *fout; - size_t sz = 0, envid_sz = 0; - ssize_t len; - char *line; - int inheaders = 1; - int save_argc; - char **save_argv; - int no_getlogin = 0; - - memset(&msg, 0, sizeof(msg)); - time(×tamp); - - save_argc = argc; - save_argv = argv; - - while ((ch = getopt(argc, argv, - "A:B:b:E::e:F:f:iJ::L:mN:o:p:qr:R:StvV:x")) != -1) { - switch (ch) { - case 'f': - fake_from = optarg; - break; - case 'F': - msg.fromname = optarg; - break; - case 'N': - msg.dsn_notify = optarg; - break; - case 'r': - fake_from = optarg; - break; - case 'R': - msg.dsn_ret = optarg; - break; - case 'S': - no_getlogin = 1; - break; - case 't': - tflag = 1; - break; - case 'v': - verbose = 1; - break; - case 'V': - msg.dsn_envid = optarg; - break; - /* all remaining: ignored, sendmail compat */ - case 'A': - case 'B': - case 'b': - case 'E': - case 'e': - case 'i': - case 'L': - case 'm': - case 'o': - case 'p': - case 'x': - break; - case 'q': - /* XXX: implement "process all now" */ - return (EX_SOFTWARE); - default: - usage(); - } - } - - argc -= optind; - argv += optind; - - if (getmailname(host, sizeof(host)) == -1) - errx(EX_NOHOST, "getmailname"); - if (no_getlogin) { - if ((pw = getpwuid(getuid())) == NULL) - user = "anonymous"; - if (pw != NULL) - user = xstrdup(pw->pw_name); - } - else { - uid_t ruid = getuid(); - - if ((user = getlogin()) != NULL && *user != '\0') { - if ((pw = getpwnam(user)) == NULL || - (ruid != 0 && ruid != pw->pw_uid)) - pw = getpwuid(ruid); - } else if ((pw = getpwuid(ruid)) == NULL) { - user = "anonymous"; - } - user = xstrdup(pw ? pw->pw_name : user); - } - - build_from(fake_from, pw); - - while (argc > 0) { - rcpt_add(argv[0]); - argv++; - argc--; - } - - if ((fp = tmpfile()) == NULL) - err(EX_UNAVAILABLE, "tmpfile"); - - msg.noheader = parse_message(stdin, fake_from == NULL, tflag, fp); - - if (msg.rcpt_cnt == 0) - errx(EX_SOFTWARE, "no recipients"); - - /* init session */ - rewind(fp); - - /* check if working in offline mode */ - /* If the server is not running, enqueue the message offline */ - - if (!srv_connected()) { - if (pledge("stdio", NULL) == -1) - err(1, "pledge"); - - return (enqueue_offline(save_argc, save_argv, fp, ofp)); - } - - if ((msg.fd = open_connection()) == -1) - errx(EX_UNAVAILABLE, "server too busy"); - - if (pledge("stdio wpath cpath", NULL) == -1) - err(1, "pledge"); - - fout = fdopen(msg.fd, "a+"); - if (fout == NULL) - err(EX_UNAVAILABLE, "fdopen"); - - /* - * We need to call get_responses after every command because we don't - * support PIPELINING on the server-side yet. - */ - - /* banner */ - if (!get_responses(fout, 1)) - goto fail; - - if (!send_line(fout, verbose, "EHLO localhost\r\n")) - goto fail; - if (!get_responses(fout, 1)) - goto fail; - - if (msg.dsn_envid != NULL) - envid_sz = strlen(msg.dsn_envid); - - if (!send_line(fout, verbose, "MAIL FROM:<%s> %s%s %s%s\r\n", - msg.from, - msg.dsn_ret ? "RET=" : "", - msg.dsn_ret ? msg.dsn_ret : "", - envid_sz ? "ENVID=" : "", - envid_sz ? msg.dsn_envid : "")) - goto fail; - if (!get_responses(fout, 1)) - goto fail; - - for (i = 0; i < msg.rcpt_cnt; i++) { - if (!send_line(fout, verbose, "RCPT TO:<%s> %s%s\r\n", - msg.rcpts[i], - msg.dsn_notify ? "NOTIFY=" : "", - msg.dsn_notify ? msg.dsn_notify : "")) - goto fail; - if (!get_responses(fout, 1)) - goto fail; - } - - if (!send_line(fout, verbose, "DATA\r\n")) - goto fail; - if (!get_responses(fout, 1)) - goto fail; - - /* add From */ - if (!msg.saw_from && !send_line(fout, 0, "From: %s%s<%s>\r\n", - msg.fromname ? msg.fromname : "", msg.fromname ? " " : "", - msg.from)) - goto fail; - - /* add Date */ - if (!msg.saw_date && !send_line(fout, 0, "Date: %s\r\n", - time_to_text(timestamp))) - goto fail; - - if (msg.need_linesplit) { - /* we will always need to mime encode for long lines */ - if (!msg.saw_mime_version && !send_line(fout, 0, - "MIME-Version: 1.0\r\n")) - goto fail; - if (!msg.saw_content_type && !send_line(fout, 0, - "Content-Type: text/plain; charset=unknown-8bit\r\n")) - goto fail; - if (!msg.saw_content_disposition && !send_line(fout, 0, - "Content-Disposition: inline\r\n")) - goto fail; - if (!msg.saw_content_transfer_encoding && !send_line(fout, 0, - "Content-Transfer-Encoding: quoted-printable\r\n")) - goto fail; - } - - /* add separating newline */ - if (msg.noheader) { - if (!send_line(fout, 0, "\r\n")) - goto fail; - inheaders = 0; - } - - for (;;) { - if ((len = getline(&buf, &sz, fp)) == -1) { - if (feof(fp)) - break; - else - err(EX_UNAVAILABLE, "getline"); - } - - /* newlines have been normalized on first parsing */ - if (buf[len-1] != '\n') - errx(EX_SOFTWARE, "expect EOL"); - len--; - - if (buf[0] == '.') { - if (fputc('.', fout) == EOF) - goto fail; - } - - line = buf; - - if (inheaders) { - if (strncasecmp("from ", line, 5) == 0) - continue; - if (strncasecmp("return-path: ", line, 13) == 0) - continue; - } - - if (msg.saw_content_transfer_encoding || msg.noheader || - inheaders || !msg.need_linesplit) { - if (!send_line(fout, 0, "%.*s\r\n", (int)len, line)) - goto fail; - if (inheaders && buf[0] == '\n') - inheaders = 0; - continue; - } - - /* we don't have a content transfer encoding, use our default */ - qp_encoded_write(fout, line); - } - free(buf); - if (!send_line(fout, verbose, ".\r\n")) - goto fail; - if (!get_responses(fout, 1)) - goto fail; - - if (!send_line(fout, verbose, "QUIT\r\n")) - goto fail; - if (!get_responses(fout, 1)) - goto fail; - - fclose(fp); - fclose(fout); - - exit(EX_OK); - -fail: - if (pw) - savedeadletter(pw, fp); - exit(EX_SOFTWARE); -} - -static int -get_responses(FILE *fin, int n) -{ - char *buf = NULL; - size_t sz = 0; - ssize_t len; - int e, ret = 0; - - fflush(fin); - if ((e = ferror(fin))) { - warnx("ferror: %d", e); - goto err; - } - - while (n) { - if ((len = getline(&buf, &sz, fin)) == -1) { - if (ferror(fin)) { - warn("getline"); - goto err; - } else if (feof(fin)) - break; - else - err(EX_UNAVAILABLE, "getline"); - } - - /* account for \r\n linebreaks */ - if (len >= 2 && buf[len - 2] == '\r' && buf[len - 1] == '\n') - buf[--len - 1] = '\n'; - - if (len < 4) { - warnx("bad response"); - goto err; - } - - if (verbose) - printf("<<< %.*s", (int)len, buf); - - if (buf[3] == '-') - continue; - if (buf[0] != '2' && buf[0] != '3') { - warnx("command failed: %.*s", (int)len, buf); - goto err; - } - n--; - } - - ret = 1; -err: - free(buf); - return ret; -} - -static int -send_line(FILE *fp, int v, char *fmt, ...) -{ - int ret = 0; - va_list ap; - - va_start(ap, fmt); - if (vfprintf(fp, fmt, ap) >= 0) - ret = 1; - va_end(ap); - - if (ret && v) { - printf(">>> "); - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); - } - - return (ret); -} - -static void -build_from(char *fake_from, struct passwd *pw) -{ - char *p; - - if (fake_from == NULL) - msg.from = qualify_addr(user); - else { - if (fake_from[0] == '<') { - if (fake_from[strlen(fake_from) - 1] != '>') - errx(1, "leading < but no trailing >"); - fake_from[strlen(fake_from) - 1] = 0; - p = xstrdup(fake_from + 1); - - msg.from = qualify_addr(p); - free(p); - } else - msg.from = qualify_addr(fake_from); - } - - if (msg.fromname == NULL && fake_from == NULL && pw != NULL) { - int len, apos; - - len = strcspn(pw->pw_gecos, ","); - if ((p = memchr(pw->pw_gecos, '&', len))) { - apos = p - pw->pw_gecos; - if (asprintf(&msg.fromname, "%.*s%s%.*s", - apos, pw->pw_gecos, - pw->pw_name, - len - apos - 1, p + 1) == -1) - err(1, NULL); - msg.fromname[apos] = toupper((unsigned char)msg.fromname[apos]); - } else { - if (asprintf(&msg.fromname, "%.*s", len, - pw->pw_gecos) == -1) - err(1, NULL); - } - } -} - -static int -parse_message(FILE *fin, int get_from, int tflag, FILE *fout) -{ - char *buf = NULL; - size_t sz = 0; - ssize_t len; - uint i, cur = HDR_NONE; - uint header_seen = 0, header_done = 0; - - memset(&pstate, 0, sizeof(pstate)); - for (;;) { - if ((len = getline(&buf, &sz, fin)) == -1) { - if (feof(fin)) - break; - else - err(EX_UNAVAILABLE, "getline"); - } - - /* account for \r\n linebreaks */ - if (len >= 2 && buf[len - 2] == '\r' && buf[len - 1] == '\n') - buf[--len - 1] = '\n'; - - if (len == 1 && buf[0] == '\n') /* end of header */ - header_done = 1; - - if (!WSP(buf[0])) { /* whitespace -> continuation */ - if (cur == HDR_FROM) - parse_addr_terminal(1); - if (cur == HDR_TO || cur == HDR_CC || cur == HDR_BCC) - parse_addr_terminal(0); - cur = HDR_NONE; - } - - /* not really exact, if we are still in headers */ - if (len + (buf[len - 1] == '\n' ? 0 : 1) >= LINESPLIT) - msg.need_linesplit = 1; - - for (i = 0; !header_done && cur == HDR_NONE && - i < nitems(keywords); i++) - if ((size_t)len > strlen(keywords[i].word) && - !strncasecmp(buf, keywords[i].word, - strlen(keywords[i].word))) - cur = keywords[i].type; - - if (cur != HDR_NONE) - header_seen = 1; - - if (cur != HDR_BCC) { - if (!send_line(fout, 0, "%.*s", (int)len, buf)) - err(1, "write error"); - if (buf[len - 1] != '\n') { - if (fputc('\n', fout) == EOF) - err(1, "write error"); - } - } - - /* - * using From: as envelope sender is not sendmail compatible, - * but I really want it that way - maybe needs a knob - */ - if (cur == HDR_FROM) { - msg.saw_from++; - if (get_from) - parse_addr(buf, len, 1); - } - - if (tflag && (cur == HDR_TO || cur == HDR_CC || cur == HDR_BCC)) - parse_addr(buf, len, 0); - - if (cur == HDR_DATE) - msg.saw_date++; - if (cur == HDR_MSGID) - msg.saw_msgid++; - if (cur == HDR_MIME_VERSION) - msg.saw_mime_version = 1; - if (cur == HDR_CONTENT_TYPE) - msg.saw_content_type = 1; - if (cur == HDR_CONTENT_DISPOSITION) - msg.saw_content_disposition = 1; - if (cur == HDR_CONTENT_TRANSFER_ENCODING) - msg.saw_content_transfer_encoding = 1; - if (cur == HDR_USER_AGENT) - msg.saw_user_agent = 1; - } - - free(buf); - return (!header_seen); -} - -static void -parse_addr(char *s, size_t len, int is_from) -{ - size_t pos = 0; - int terminal = 0; - - /* unless this is a continuation... */ - if (!WSP(s[pos]) && s[pos] != ',' && s[pos] != ';') { - /* ... skip over everything before the ':' */ - for (; pos < len && s[pos] != ':'; pos++) - ; /* nothing */ - /* ... and check & reset parser state */ - parse_addr_terminal(is_from); - } - - /* skip over ':' ',' ';' and whitespace */ - for (; pos < len && !pstate.quote && (WSP(s[pos]) || s[pos] == ':' || - s[pos] == ',' || s[pos] == ';'); pos++) - ; /* nothing */ - - for (; pos < len; pos++) { - if (!pstate.esc && !pstate.quote && s[pos] == '(') - pstate.comment++; - if (!pstate.comment && !pstate.esc && s[pos] == '"') - pstate.quote = !pstate.quote; - - if (!pstate.comment && !pstate.quote && !pstate.esc) { - if (s[pos] == ':') { /* group */ - for (pos++; pos < len && WSP(s[pos]); pos++) - ; /* nothing */ - pstate.wpos = 0; - } - if (s[pos] == '\n' || s[pos] == '\r') - break; - if (s[pos] == ',' || s[pos] == ';') { - terminal = 1; - break; - } - if (s[pos] == '<') { - pstate.brackets = 1; - pstate.wpos = 0; - } - if (pstate.brackets && s[pos] == '>') - terminal = 1; - } - - if (!pstate.comment && !terminal && (!(!(pstate.quote || - pstate.esc) && (s[pos] == '<' || WSP(s[pos]))))) { - if (pstate.wpos >= sizeof(pstate.buf)) - errx(1, "address exceeds buffer size"); - pstate.buf[pstate.wpos++] = s[pos]; - } - - if (!pstate.quote && pstate.comment && s[pos] == ')') - pstate.comment--; - - if (!pstate.esc && !pstate.comment && s[pos] == '\\') - pstate.esc = 1; - else - pstate.esc = 0; - } - - if (terminal) - parse_addr_terminal(is_from); - - for (; pos < len && (s[pos] == '\r' || s[pos] == '\n'); pos++) - ; /* nothing */ - - if (pos < len) - parse_addr(s + pos, len - pos, is_from); -} - -static void -parse_addr_terminal(int is_from) -{ - if (pstate.comment || pstate.quote || pstate.esc) - errx(1, "syntax error in address"); - if (pstate.wpos) { - if (pstate.wpos >= sizeof(pstate.buf)) - errx(1, "address exceeds buffer size"); - pstate.buf[pstate.wpos] = '\0'; - if (is_from) - msg.from = qualify_addr(pstate.buf); - else - rcpt_add(pstate.buf); - pstate.wpos = 0; - } -} - -static char * -qualify_addr(char *in) -{ - char *out; - - if (strlen(in) > 0 && strchr(in, '@') == NULL) { - if (asprintf(&out, "%s@%s", in, host) == -1) - err(1, "qualify asprintf"); - } else - out = xstrdup(in); - - return (out); -} - -static void -rcpt_add(char *addr) -{ - void *nrcpts; - char *p; - int n; - - n = 1; - p = addr; - while ((p = strchr(p, ',')) != NULL) { - n++; - p++; - } - - if ((nrcpts = reallocarray(msg.rcpts, - msg.rcpt_cnt + n, sizeof(char *))) == NULL) - err(1, "rcpt_add realloc"); - msg.rcpts = nrcpts; - - while (n--) { - if ((p = strchr(addr, ',')) != NULL) - *p++ = '\0'; - msg.rcpts[msg.rcpt_cnt++] = qualify_addr(addr); - if (p == NULL) - break; - addr = p; - } -} - -static int -open_connection(void) -{ - struct imsg imsg; - int fd; - int n; - - imsg_compose(ibuf, IMSG_CTL_SMTP_SESSION, IMSG_VERSION, 0, -1, NULL, 0); - - while (ibuf->w.queued) - if (msgbuf_write(&ibuf->w) <= 0 && errno != EAGAIN) - err(1, "write error"); - - while (1) { - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) - errx(1, "imsg_read error"); - if (n == 0) - errx(1, "pipe closed"); - - if ((n = imsg_get(ibuf, &imsg)) == -1) - errx(1, "imsg_get error"); - if (n == 0) - continue; - - switch (imsg.hdr.type) { - case IMSG_CTL_OK: - break; - case IMSG_CTL_FAIL: - errx(1, "server disallowed submission request"); - default: - errx(1, "unexpected imsg reply type"); - } - - fd = imsg.fd; - imsg_free(&imsg); - - break; - } - - return fd; -} - -static int -enqueue_offline(int argc, char *argv[], FILE *ifile, FILE *ofile) -{ - int i, ch; - - for (i = 1; i < argc; i++) { - if (strchr(argv[i], '|') != NULL) { - warnx("%s contains illegal character", argv[i]); - ftruncate(fileno(ofile), 0); - exit(EX_SOFTWARE); - } - if (fprintf(ofile, "%s%s", i == 1 ? "" : "|", argv[i]) < 0) - goto write_error; - } - - if (fputc('\n', ofile) == EOF) - goto write_error; - - while ((ch = fgetc(ifile)) != EOF) { - if (fputc(ch, ofile) == EOF) - goto write_error; - } - - if (ferror(ifile)) { - warn("read error"); - ftruncate(fileno(ofile), 0); - exit(EX_UNAVAILABLE); - } - - if (fclose(ofile) == EOF) - goto write_error; - - return (EX_TEMPFAIL); -write_error: - warn("write error"); - ftruncate(fileno(ofile), 0); - exit(EX_UNAVAILABLE); -} - -static int -savedeadletter(struct passwd *pw, FILE *in) -{ - char buffer[PATH_MAX]; - FILE *fp; - char *buf = NULL; - size_t sz = 0; - ssize_t len; - - (void)snprintf(buffer, sizeof buffer, "%s/dead.letter", pw->pw_dir); - - if (fseek(in, 0, SEEK_SET) != 0) - return 0; - - if ((fp = fopen(buffer, "w")) == NULL) - return 0; - - /* add From */ - if (!msg.saw_from) - fprintf(fp, "From: %s%s<%s>\n", - msg.fromname ? msg.fromname : "", - msg.fromname ? " " : "", - msg.from); - - /* add Date */ - if (!msg.saw_date) - fprintf(fp, "Date: %s\n", time_to_text(timestamp)); - - if (msg.need_linesplit) { - /* we will always need to mime encode for long lines */ - if (!msg.saw_mime_version) - fprintf(fp, "MIME-Version: 1.0\n"); - if (!msg.saw_content_type) - fprintf(fp, "Content-Type: text/plain; " - "charset=unknown-8bit\n"); - if (!msg.saw_content_disposition) - fprintf(fp, "Content-Disposition: inline\n"); - if (!msg.saw_content_transfer_encoding) - fprintf(fp, "Content-Transfer-Encoding: " - "quoted-printable\n"); - } - - /* add separating newline */ - if (msg.noheader) - fprintf(fp, "\n"); - - while ((len = getline(&buf, &sz, in)) != -1) { - if (buf[len - 1] == '\n') - buf[len - 1] = '\0'; - fprintf(fp, "%s\n", buf); - } - - free(buf); - fprintf(fp, "\n"); - fclose(fp); - return 1; -} diff --git a/envelope.c b/envelope.c deleted file mode 100644 index 05a239e1..00000000 --- a/envelope.c +++ /dev/null @@ -1,778 +0,0 @@ -/* $OpenBSD: envelope.c,v 1.47 2019/11/25 14:18:32 gilles Exp $ */ - -/* - * Copyright (c) 2013 Eric Faurot - * Copyright (c) 2011-2013 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" - -static int envelope_ascii_load(struct envelope *, struct dict *); -static void envelope_ascii_dump(const struct envelope *, char **, size_t *, - const char *); - -void -envelope_set_errormsg(struct envelope *e, char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vsnprintf(e->errorline, sizeof(e->errorline), fmt, ap); - va_end(ap); - - /* this should not happen */ - if (ret < 0) - err(1, "vsnprintf"); - - if ((size_t)ret >= sizeof(e->errorline)) - (void)strlcpy(e->errorline + (sizeof(e->errorline) - 4), - "...", 4); -} - -void -envelope_set_esc_class(struct envelope *e, enum enhanced_status_class class) -{ - e->esc_class = class; -} - -void -envelope_set_esc_code(struct envelope *e, enum enhanced_status_code code) -{ - e->esc_code = code; -} - -static int -envelope_buffer_to_dict(struct dict *d, const char *ibuf, size_t buflen) -{ - static char lbuf[sizeof(struct envelope)]; - size_t len; - char *buf, *field, *nextline; - - memset(lbuf, 0, sizeof lbuf); - if (strlcpy(lbuf, ibuf, sizeof lbuf) >= sizeof lbuf) - goto err; - buf = lbuf; - - while (buflen > 0) { - len = strcspn(buf, "\n"); - buf[len] = '\0'; - nextline = buf + len + 1; - buflen -= (nextline - buf); - - field = buf; - while (*buf && (isalnum((unsigned char)*buf) || *buf == '-')) - buf++; - if (!*buf) - goto err; - - /* skip whitespaces before separator */ - while (*buf && isspace((unsigned char)*buf)) - *buf++ = 0; - - /* we *want* ':' */ - if (*buf != ':') - goto err; - *buf++ = 0; - - /* skip whitespaces after separator */ - while (*buf && isspace((unsigned char)*buf)) - *buf++ = 0; - dict_set(d, field, buf); - buf = nextline; - } - - return (1); - -err: - return (0); -} - -int -envelope_load_buffer(struct envelope *ep, const char *ibuf, size_t buflen) -{ - struct dict d; - const char *val, *errstr; - long long version; - int ret = 0; - - dict_init(&d); - if (!envelope_buffer_to_dict(&d, ibuf, buflen)) { - log_debug("debug: cannot parse envelope to dict"); - goto end; - } - - val = dict_get(&d, "version"); - if (val == NULL) { - log_debug("debug: envelope version not found"); - goto end; - } - version = strtonum(val, 1, 64, &errstr); - if (errstr) { - log_debug("debug: cannot parse envelope version: %s", val); - goto end; - } - - if (version != SMTPD_ENVELOPE_VERSION) { - log_debug("debug: bad envelope version %lld", version); - goto end; - } - - memset(ep, 0, sizeof *ep); - ret = envelope_ascii_load(ep, &d); - if (ret) - ep->version = SMTPD_ENVELOPE_VERSION; -end: - while (dict_poproot(&d, NULL)) - ; - return (ret); -} - -int -envelope_dump_buffer(const struct envelope *ep, char *dest, size_t len) -{ - char *p = dest; - - envelope_ascii_dump(ep, &dest, &len, "version"); - envelope_ascii_dump(ep, &dest, &len, "dispatcher"); - envelope_ascii_dump(ep, &dest, &len, "tag"); - envelope_ascii_dump(ep, &dest, &len, "type"); - envelope_ascii_dump(ep, &dest, &len, "smtpname"); - envelope_ascii_dump(ep, &dest, &len, "helo"); - envelope_ascii_dump(ep, &dest, &len, "hostname"); - envelope_ascii_dump(ep, &dest, &len, "username"); - envelope_ascii_dump(ep, &dest, &len, "errorline"); - envelope_ascii_dump(ep, &dest, &len, "sockaddr"); - envelope_ascii_dump(ep, &dest, &len, "sender"); - envelope_ascii_dump(ep, &dest, &len, "rcpt"); - envelope_ascii_dump(ep, &dest, &len, "dest"); - envelope_ascii_dump(ep, &dest, &len, "ctime"); - envelope_ascii_dump(ep, &dest, &len, "last-try"); - envelope_ascii_dump(ep, &dest, &len, "last-bounce"); - envelope_ascii_dump(ep, &dest, &len, "ttl"); - envelope_ascii_dump(ep, &dest, &len, "retry"); - envelope_ascii_dump(ep, &dest, &len, "flags"); - envelope_ascii_dump(ep, &dest, &len, "dsn-notify"); - envelope_ascii_dump(ep, &dest, &len, "dsn-ret"); - envelope_ascii_dump(ep, &dest, &len, "dsn-envid"); - envelope_ascii_dump(ep, &dest, &len, "dsn-orcpt"); - envelope_ascii_dump(ep, &dest, &len, "esc-class"); - envelope_ascii_dump(ep, &dest, &len, "esc-code"); - - switch (ep->type) { - case D_MDA: - envelope_ascii_dump(ep, &dest, &len, "mda-exec"); - envelope_ascii_dump(ep, &dest, &len, "mda-subaddress"); - envelope_ascii_dump(ep, &dest, &len, "mda-user"); - break; - case D_MTA: - break; - case D_BOUNCE: - envelope_ascii_dump(ep, &dest, &len, "bounce-ttl"); - envelope_ascii_dump(ep, &dest, &len, "bounce-delay"); - envelope_ascii_dump(ep, &dest, &len, "bounce-type"); - break; - default: - return (0); - } - - if (dest == NULL) - return (0); - - return (dest - p); -} - -static int -ascii_load_uint8(uint8_t *dest, char *buf) -{ - const char *errstr; - - *dest = strtonum(buf, 0, 0xff, &errstr); - if (errstr) - return 0; - return 1; -} - -static int -ascii_load_uint16(uint16_t *dest, char *buf) -{ - const char *errstr; - - *dest = strtonum(buf, 0, 0xffff, &errstr); - if (errstr) - return 0; - return 1; -} - -static int -ascii_load_uint32(uint32_t *dest, char *buf) -{ - const char *errstr; - - *dest = strtonum(buf, 0, 0xffffffff, &errstr); - if (errstr) - return 0; - return 1; -} - -static int -ascii_load_time(time_t *dest, char *buf) -{ - const char *errstr; - - *dest = strtonum(buf, 0, LLONG_MAX, &errstr); - if (errstr) - return 0; - return 1; -} - -static int -ascii_load_type(enum delivery_type *dest, char *buf) -{ - if (strcasecmp(buf, "mda") == 0) - *dest = D_MDA; - else if (strcasecmp(buf, "mta") == 0) - *dest = D_MTA; - else if (strcasecmp(buf, "bounce") == 0) - *dest = D_BOUNCE; - else - return 0; - return 1; -} - -static int -ascii_load_string(char *dest, char *buf, size_t len) -{ - if (strlcpy(dest, buf, len) >= len) - return 0; - return 1; -} - -static int -ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf) -{ - struct sockaddr_in6 ssin6; - struct sockaddr_in ssin; - - memset(&ssin, 0, sizeof ssin); - memset(&ssin6, 0, sizeof ssin6); - - if (!strcmp("local", buf)) { - ss->ss_family = AF_LOCAL; - } - else if (strncasecmp("IPv6:", buf, 5) == 0) { - /* XXX - remove this after 6.6 release */ - if (inet_pton(AF_INET6, buf + 5, &ssin6.sin6_addr) != 1) - return 0; - ssin6.sin6_family = AF_INET6; - memcpy(ss, &ssin6, sizeof(ssin6)); - ss->ss_len = sizeof(struct sockaddr_in6); - } - else if (buf[0] == '[' && buf[strlen(buf)-1] == ']') { - buf[strlen(buf)-1] = '\0'; - if (inet_pton(AF_INET6, buf+1, &ssin6.sin6_addr) != 1) - return 0; - ssin6.sin6_family = AF_INET6; - memcpy(ss, &ssin6, sizeof(ssin6)); - ss->ss_len = sizeof(struct sockaddr_in6); - } - else { - if (inet_pton(AF_INET, buf, &ssin.sin_addr) != 1) - return 0; - ssin.sin_family = AF_INET; - memcpy(ss, &ssin, sizeof(ssin)); - ss->ss_len = sizeof(struct sockaddr_in); - } - return 1; -} - -static int -ascii_load_mailaddr(struct mailaddr *dest, char *buf) -{ - if (!text_to_mailaddr(dest, buf)) - return 0; - return 1; -} - -static int -ascii_load_flags(enum envelope_flags *dest, char *buf) -{ - char *flag; - - while ((flag = strsep(&buf, " ,|")) != NULL) { - if (strcasecmp(flag, "authenticated") == 0) - *dest |= EF_AUTHENTICATED; - else if (strcasecmp(flag, "enqueued") == 0) - ; - else if (strcasecmp(flag, "bounce") == 0) - *dest |= EF_BOUNCE; - else if (strcasecmp(flag, "internal") == 0) - *dest |= EF_INTERNAL; - else - return 0; - } - return 1; -} - -static int -ascii_load_bounce_type(enum bounce_type *dest, char *buf) -{ - if (strcasecmp(buf, "error") == 0 || strcasecmp(buf, "failed") == 0) - *dest = B_FAILED; - else if (strcasecmp(buf, "warn") == 0 || - strcasecmp(buf, "delayed") == 0) - *dest = B_DELAYED; - else if (strcasecmp(buf, "dsn") == 0 || - strcasecmp(buf, "delivered") == 0) - *dest = B_DELIVERED; - else - return 0; - return 1; -} - -static int -ascii_load_dsn_ret(enum dsn_ret *ret, char *buf) -{ - if (strcasecmp(buf, "HDRS") == 0) - *ret = DSN_RETHDRS; - else if (strcasecmp(buf, "FULL") == 0) - *ret = DSN_RETFULL; - else - return 0; - return 1; -} - -static int -ascii_load_field(const char *field, struct envelope *ep, char *buf) -{ - if (strcasecmp("dispatcher", field) == 0) - return ascii_load_string(ep->dispatcher, buf, - sizeof ep->dispatcher); - - if (strcasecmp("bounce-delay", field) == 0) - return ascii_load_time(&ep->agent.bounce.delay, buf); - - if (strcasecmp("bounce-ttl", field) == 0) - return ascii_load_time(&ep->agent.bounce.ttl, buf); - - if (strcasecmp("bounce-type", field) == 0) - return ascii_load_bounce_type(&ep->agent.bounce.type, buf); - - if (strcasecmp("ctime", field) == 0) - return ascii_load_time(&ep->creation, buf); - - if (strcasecmp("dest", field) == 0) - return ascii_load_mailaddr(&ep->dest, buf); - - if (strcasecmp("username", field) == 0) - return ascii_load_string(ep->username, buf, sizeof(ep->username)); - - if (strcasecmp("errorline", field) == 0) - return ascii_load_string(ep->errorline, buf, - sizeof ep->errorline); - - if (strcasecmp("ttl", field) == 0) - return ascii_load_time(&ep->ttl, buf); - - if (strcasecmp("flags", field) == 0) - return ascii_load_flags(&ep->flags, buf); - - if (strcasecmp("helo", field) == 0) - return ascii_load_string(ep->helo, buf, sizeof ep->helo); - - if (strcasecmp("hostname", field) == 0) - return ascii_load_string(ep->hostname, buf, - sizeof ep->hostname); - - if (strcasecmp("last-bounce", field) == 0) - return ascii_load_time(&ep->lastbounce, buf); - - if (strcasecmp("last-try", field) == 0) - return ascii_load_time(&ep->lasttry, buf); - - if (strcasecmp("retry", field) == 0) - return ascii_load_uint16(&ep->retry, buf); - - if (strcasecmp("rcpt", field) == 0) - return ascii_load_mailaddr(&ep->rcpt, buf); - - if (strcasecmp("mda-exec", field) == 0) - return ascii_load_string(ep->mda_exec, buf, sizeof(ep->mda_exec)); - - if (strcasecmp("mda-subaddress", field) == 0) - return ascii_load_string(ep->mda_subaddress, buf, sizeof(ep->mda_subaddress)); - - if (strcasecmp("mda-user", field) == 0) - return ascii_load_string(ep->mda_user, buf, sizeof(ep->mda_user)); - - if (strcasecmp("sender", field) == 0) - return ascii_load_mailaddr(&ep->sender, buf); - - if (strcasecmp("smtpname", field) == 0) - return ascii_load_string(ep->smtpname, buf, - sizeof(ep->smtpname)); - - if (strcasecmp("sockaddr", field) == 0) - return ascii_load_sockaddr(&ep->ss, buf); - - if (strcasecmp("tag", field) == 0) - return ascii_load_string(ep->tag, buf, sizeof ep->tag); - - if (strcasecmp("type", field) == 0) - return ascii_load_type(&ep->type, buf); - - if (strcasecmp("version", field) == 0) - return ascii_load_uint32(&ep->version, buf); - - if (strcasecmp("dsn-notify", field) == 0) - return ascii_load_uint8(&ep->dsn_notify, buf); - - if (strcasecmp("dsn-orcpt", field) == 0) - return ascii_load_mailaddr(&ep->dsn_orcpt, buf); - - if (strcasecmp("dsn-ret", field) == 0) - return ascii_load_dsn_ret(&ep->dsn_ret, buf); - - if (strcasecmp("dsn-envid", field) == 0) - return ascii_load_string(ep->dsn_envid, buf, - sizeof(ep->dsn_envid)); - - if (strcasecmp("esc-class", field) == 0) - return ascii_load_uint8(&ep->esc_class, buf); - - if (strcasecmp("esc-code", field) == 0) - return ascii_load_uint8(&ep->esc_code, buf); - - return (0); -} - -static int -envelope_ascii_load(struct envelope *ep, struct dict *d) -{ - const char *field; - char *value; - void *hdl; - - hdl = NULL; - while (dict_iter(d, &hdl, &field, (void **)&value)) - if (!ascii_load_field(field, ep, value)) - goto err; - - return (1); - -err: - log_warnx("envelope: invalid field \"%s\"", field); - return (0); -} - - -static int -ascii_dump_uint8(uint8_t src, char *dest, size_t len) -{ - return bsnprintf(dest, len, "%d", src); -} - -static int -ascii_dump_uint16(uint16_t src, char *dest, size_t len) -{ - return bsnprintf(dest, len, "%d", src); -} - -static int -ascii_dump_uint32(uint32_t src, char *dest, size_t len) -{ - return bsnprintf(dest, len, "%d", src); -} - -static int -ascii_dump_time(time_t src, char *dest, size_t len) -{ - return bsnprintf(dest, len, "%lld", (long long) src); -} - -static int -ascii_dump_string(const char *src, char *dest, size_t len) -{ - return bsnprintf(dest, len, "%s", src); -} - -static int -ascii_dump_type(enum delivery_type type, char *dest, size_t len) -{ - char *p = NULL; - - switch (type) { - case D_MDA: - p = "mda"; - break; - case D_MTA: - p = "mta"; - break; - case D_BOUNCE: - p = "bounce"; - break; - default: - return 0; - } - - return bsnprintf(dest, len, "%s", p); -} - -static int -ascii_dump_mailaddr(const struct mailaddr *addr, char *dest, size_t len) -{ - return bsnprintf(dest, len, "%s@%s", - addr->user, addr->domain); -} - -static int -ascii_dump_flags(enum envelope_flags flags, char *buf, size_t len) -{ - size_t cpylen = 0; - - buf[0] = '\0'; - if (flags) { - if (flags & EF_AUTHENTICATED) - cpylen = strlcat(buf, "authenticated", len); - if (flags & EF_BOUNCE) { - if (buf[0] != '\0') - (void)strlcat(buf, " ", len); - cpylen = strlcat(buf, "bounce", len); - } - if (flags & EF_INTERNAL) { - if (buf[0] != '\0') - (void)strlcat(buf, " ", len); - cpylen = strlcat(buf, "internal", len); - } - } - - return cpylen < len ? 1 : 0; -} - -static int -ascii_dump_bounce_type(enum bounce_type type, char *dest, size_t len) -{ - char *p = NULL; - - switch (type) { - case B_FAILED: - p = "failed"; - break; - case B_DELAYED: - p = "delayed"; - break; - case B_DELIVERED: - p = "delivered"; - break; - default: - return 0; - } - return bsnprintf(dest, len, "%s", p); -} - - -static int -ascii_dump_dsn_ret(enum dsn_ret flag, char *dest, size_t len) -{ - size_t cpylen = 0; - - dest[0] = '\0'; - if (flag == DSN_RETFULL) - cpylen = strlcat(dest, "FULL", len); - else if (flag == DSN_RETHDRS) - cpylen = strlcat(dest, "HDRS", len); - - return cpylen < len ? 1 : 0; -} - -static int -ascii_dump_field(const char *field, const struct envelope *ep, - char *buf, size_t len) -{ - if (strcasecmp(field, "dispatcher") == 0) - return ascii_dump_string(ep->dispatcher, buf, len); - - if (strcasecmp(field, "bounce-delay") == 0) { - if (ep->agent.bounce.type != B_DELAYED) - return (1); - return ascii_dump_time(ep->agent.bounce.delay, buf, len); - } - - if (strcasecmp(field, "bounce-ttl") == 0) { - if (ep->agent.bounce.type != B_DELAYED) - return (1); - return ascii_dump_time(ep->agent.bounce.ttl, buf, len); - } - - if (strcasecmp(field, "bounce-type") == 0) - return ascii_dump_bounce_type(ep->agent.bounce.type, buf, len); - - if (strcasecmp(field, "ctime") == 0) - return ascii_dump_time(ep->creation, buf, len); - - if (strcasecmp(field, "dest") == 0) - return ascii_dump_mailaddr(&ep->dest, buf, len); - - if (strcasecmp(field, "username") == 0) { - if (ep->username[0]) - return ascii_dump_string(ep->username, buf, len); - return 1; - } - - if (strcasecmp(field, "errorline") == 0) - return ascii_dump_string(ep->errorline, buf, len); - - if (strcasecmp(field, "ttl") == 0) - return ascii_dump_time(ep->ttl, buf, len); - - if (strcasecmp(field, "flags") == 0) - return ascii_dump_flags(ep->flags, buf, len); - - if (strcasecmp(field, "helo") == 0) - return ascii_dump_string(ep->helo, buf, len); - - if (strcasecmp(field, "hostname") == 0) - return ascii_dump_string(ep->hostname, buf, len); - - if (strcasecmp(field, "last-bounce") == 0) - return ascii_dump_time(ep->lastbounce, buf, len); - - if (strcasecmp(field, "last-try") == 0) - return ascii_dump_time(ep->lasttry, buf, len); - - if (strcasecmp(field, "retry") == 0) - return ascii_dump_uint16(ep->retry, buf, len); - - if (strcasecmp(field, "rcpt") == 0) - return ascii_dump_mailaddr(&ep->rcpt, buf, len); - - if (strcasecmp(field, "mda-exec") == 0) { - if (ep->mda_exec[0]) - return ascii_dump_string(ep->mda_exec, buf, len); - return 1; - } - - if (strcasecmp(field, "mda-subaddress") == 0) { - if (ep->mda_subaddress[0]) - return ascii_dump_string(ep->mda_subaddress, buf, len); - return 1; - } - - if (strcasecmp(field, "mda-user") == 0) { - if (ep->mda_user[0]) - return ascii_dump_string(ep->mda_user, buf, len); - return 1; - } - - if (strcasecmp(field, "sender") == 0) - return ascii_dump_mailaddr(&ep->sender, buf, len); - - if (strcasecmp(field, "smtpname") == 0) - return ascii_dump_string(ep->smtpname, buf, len); - - if (strcasecmp(field, "sockaddr") == 0) - return ascii_dump_string(ss_to_text(&ep->ss), buf, len); - - if (strcasecmp(field, "tag") == 0) - return ascii_dump_string(ep->tag, buf, len); - - if (strcasecmp(field, "type") == 0) - return ascii_dump_type(ep->type, buf, len); - - if (strcasecmp(field, "version") == 0) - return ascii_dump_uint32(SMTPD_ENVELOPE_VERSION, buf, len); - - if (strcasecmp(field, "dsn-notify") == 0) - return ascii_dump_uint8(ep->dsn_notify, buf, len); - - if (strcasecmp(field, "dsn-ret") == 0) - return ascii_dump_dsn_ret(ep->dsn_ret, buf, len); - - if (strcasecmp(field, "dsn-orcpt") == 0) { - if (ep->dsn_orcpt.user[0] && ep->dsn_orcpt.domain[0]) - return ascii_dump_mailaddr(&ep->dsn_orcpt, buf, len); - return 1; - } - - if (strcasecmp(field, "dsn-envid") == 0) - return ascii_dump_string(ep->dsn_envid, buf, len); - - if (strcasecmp(field, "esc-class") == 0) { - if (ep->esc_class) - return ascii_dump_uint8(ep->esc_class, buf, len); - return 1; - } - - if (strcasecmp(field, "esc-code") == 0) { - /* this is not a pasto, we dump esc_code if esc_class is !0 */ - if (ep->esc_class) - return ascii_dump_uint8(ep->esc_code, buf, len); - return 1; - } - - return (0); -} - -static void -envelope_ascii_dump(const struct envelope *ep, char **dest, size_t *len, - const char *field) -{ - char buf[8192]; - int l; - - if (*dest == NULL) - return; - - memset(buf, 0, sizeof buf); - if (!ascii_dump_field(field, ep, buf, sizeof buf)) - goto err; - if (buf[0] == '\0') - return; - - l = snprintf(*dest, *len, "%s: %s\n", field, buf); - if (l < 0 || (size_t) l >= *len) - goto err; - *dest += l; - *len -= l; - - return; -err: - *dest = NULL; -} diff --git a/esc.c b/esc.c deleted file mode 100644 index a07320ce..00000000 --- a/esc.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $OpenBSD: esc.c,v 1.5 2016/09/03 22:16:39 gilles Exp $ */ - -/* - * Copyright (c) 2014 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "smtpd-defines.h" -#include "smtpd-api.h" - -static struct escode { - enum enhanced_status_code code; - const char *description; -} esc[] = { - /* 0.0 */ - { ESC_OTHER_STATUS, "Other/Undefined" }, - - /* 1.x */ - { ESC_OTHER_ADDRESS_STATUS, "Other/Undefined address status" }, - { ESC_BAD_DESTINATION_MAILBOX_ADDRESS, "Bad destination mailbox address" }, - { ESC_BAD_DESTINATION_SYSTEM_ADDRESS, "Bad destination system address" }, - { ESC_BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX, "Bad destination mailbox address syntax" }, - { ESC_DESTINATION_MAILBOX_ADDRESS_AMBIGUOUS, "Destination mailbox address ambiguous" }, - { ESC_DESTINATION_ADDRESS_VALID, "Destination address valid" }, - { ESC_DESTINATION_MAILBOX_HAS_MOVED, "Destination mailbox has moved, No forwarding address" }, - { ESC_BAD_SENDER_MAILBOX_ADDRESS_SYNTAX, "Bad sender's mailbox address syntax" }, - { ESC_BAD_SENDER_SYSTEM_ADDRESS, "Bad sender's system address syntax" }, - - /* 2.x */ - { ESC_OTHER_MAILBOX_STATUS, "Other/Undefined mailbox status" }, - { ESC_MAILBOX_DISABLED, "Mailbox disabled, not accepting messages" }, - { ESC_MAILBOX_FULL, "Mailbox full" }, - { ESC_MESSAGE_LENGTH_TOO_LARGE, "Message length exceeds administrative limit" }, - { ESC_MAILING_LIST_EXPANSION_PROBLEM, "Mailing list expansion problem" }, - - /* 3.x */ - { ESC_OTHER_MAIL_SYSTEM_STATUS, "Other/Undefined mail system status" }, - { ESC_MAIL_SYSTEM_FULL, "Mail system full" }, - { ESC_SYSTEM_NOT_ACCEPTING_MESSAGES, "System not accepting network messages" }, - { ESC_SYSTEM_NOT_CAPABLE_OF_SELECTED_FEATURES, "System not capable of selected features" }, - { ESC_MESSAGE_TOO_BIG_FOR_SYSTEM, "Message too big for system" }, - { ESC_SYSTEM_INCORRECTLY_CONFIGURED, "System incorrectly configured" }, - - /* 4.x */ - { ESC_OTHER_NETWORK_ROUTING_STATUS, "Other/Undefined network or routing status" }, - { ESC_NO_ANSWER_FROM_HOST, "No answer from host" }, - { ESC_BAD_CONNECTION, "Bad connection" }, - { ESC_DIRECTORY_SERVER_FAILURE, "Directory server failure" }, - { ESC_UNABLE_TO_ROUTE, "Unable to route" }, - { ESC_MAIL_SYSTEM_CONGESTION, "Mail system congestion" }, - { ESC_ROUTING_LOOP_DETECTED, "Routing loop detected" }, - { ESC_DELIVERY_TIME_EXPIRED, "Delivery time expired" }, - - /* 5.x */ - { ESC_INVALID_RECIPIENT, "Invalid recipient" }, - { ESC_INVALID_COMMAND, "Invalid command" }, - { ESC_SYNTAX_ERROR, "Syntax error" }, - { ESC_TOO_MANY_RECIPIENTS, "Too many recipients" }, - { ESC_INVALID_COMMAND_ARGUMENTS, "Invalid command arguments" }, - { ESC_WRONG_PROTOCOL_VERSION, "Wrong protocol version" }, - - /* 6.x */ - { ESC_OTHER_MEDIA_ERROR, "Other/Undefined media error" }, - { ESC_MEDIA_NOT_SUPPORTED, "Media not supported" }, - { ESC_CONVERSION_REQUIRED_AND_PROHIBITED, "Conversion required and prohibited" }, - { ESC_CONVERSION_REQUIRED_BUT_NOT_SUPPORTED, "Conversion required but not supported" }, - { ESC_CONVERSION_WITH_LOSS_PERFORMED, "Conversion with loss performed" }, - { ESC_CONVERSION_FAILED, "Conversion failed" }, - - /* 7.x */ - { ESC_OTHER_SECURITY_STATUS, "Other/Undefined security status" }, - { ESC_DELIVERY_NOT_AUTHORIZED_MESSAGE_REFUSED, "Delivery not authorized, message refused" }, - { ESC_MAILING_LIST_EXPANSION_PROHIBITED, "Mailing list expansion prohibited" }, - { ESC_SECURITY_CONVERSION_REQUIRED_NOT_POSSIBLE,"Security conversion required but not possible" }, - { ESC_SECURITY_FEATURES_NOT_SUPPORTED, "Security features not supported" }, - { ESC_CRYPTOGRAPHIC_FAILURE, "Cryptographic failure" }, - { ESC_CRYPTOGRAPHIC_ALGORITHM_NOT_SUPPORTED, "Cryptographic algorithm not supported" }, - { ESC_MESSAGE_TOO_BIG_FOR_SYSTEM, "Message integrity failure" }, -}; - -const char * -esc_code(enum enhanced_status_class class, enum enhanced_status_code code) -{ - static char buffer[6]; - - (void)snprintf(buffer, sizeof buffer, "%d.%d.%d", class, code / 10, code % 10); - return buffer; - -} - -const char * -esc_description(enum enhanced_status_code code) -{ - uint32_t i; - - for (i = 0; i < nitems(esc); ++i) - if (code == esc[i].code) - return esc[i].description; - return "Other/Undefined"; -} diff --git a/etc/README.md b/etc/README.md new file mode 100644 index 00000000..0c53cc6b --- /dev/null +++ b/etc/README.md @@ -0,0 +1,6 @@ +This directory will contain example OpenSMTPD config files that can be used as +a reference or for testing specific usecases. Tests that are run as part of +CI/CD process in docker containers will utilize these files. + + +* `aliases` file - default aliases map that is referenced by default OpenSMTPD config. diff --git a/etc/aliases b/etc/aliases new file mode 100644 index 00000000..09fb6cf5 --- /dev/null +++ b/etc/aliases @@ -0,0 +1,100 @@ +# +# $OpenBSD: aliases,v 1.67 2019/01/26 10:58:05 florian Exp $ +# +# Aliases in this file will NOT be expanded in the header from +# Mail, but WILL be visible over networks or from /usr/libexec/mail.local. +# +# >>>>>>>>>> The program "newaliases" must be run after +# >> NOTE >> this file is updated for any changes to +# >>>>>>>>>> show through to smtpd. +# + +# Basic system aliases -- these MUST be present +MAILER-DAEMON: postmaster +postmaster: root + +# General redirections for important pseudo accounts +daemon: root +ftp-bugs: root +operator: root +www: root + +# Redirections for pseudo accounts that should not receive mail +_bgpd: /dev/null +_dhcp: /dev/null +_dpb: /dev/null +_dvmrpd: /dev/null +_eigrpd: /dev/null +_file: /dev/null +_fingerd: /dev/null +_ftp: /dev/null +_hostapd: /dev/null +_identd: /dev/null +_iked: /dev/null +_isakmpd: /dev/null +_iscsid: /dev/null +_ldapd: /dev/null +_ldpd: /dev/null +_mopd: /dev/null +_nsd: /dev/null +_ntp: /dev/null +_ospfd: /dev/null +_ospf6d: /dev/null +_pbuild: /dev/null +_pfetch: /dev/null +_pflogd: /dev/null +_ping: /dev/null +_pkgfetch: /dev/null +_pkguntar: /dev/null +_portmap: /dev/null +_ppp: /dev/null +_rad: /dev/null +_radiusd: /dev/null +_rbootd: /dev/null +_relayd: /dev/null +_rebound: /dev/null +_ripd: /dev/null +_rstatd: /dev/null +_rusersd: /dev/null +_rwalld: /dev/null +_smtpd: /dev/null +_smtpq: /dev/null +_sndio: /dev/null +_snmpd: /dev/null +_spamd: /dev/null +_switchd: /dev/null +_syslogd: /dev/null +_tcpdump: /dev/null +_traceroute: /dev/null +_tftpd: /dev/null +_unbound: /dev/null +_unwind: /dev/null +_vmd: /dev/null +_x11: /dev/null +_ypldap: /dev/null +bin: /dev/null +build: /dev/null +nobody: /dev/null +_tftp_proxy: /dev/null +_ftp_proxy: /dev/null +_sndiop: /dev/null +_syspatch: /dev/null +_slaacd: /dev/null +sshd: /dev/null + +# Well-known aliases -- these should be filled in! +# root: +# manager: +# dumper: + +# RFC 2142: NETWORK OPERATIONS MAILBOX NAMES +abuse: root +# noc: root +security: root + +# RFC 2142: SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES +# hostmaster: root +# usenet: root +# news: usenet +# webmaster: root +# ftp: root diff --git a/expand.c b/expand.c deleted file mode 100644 index 99b25d51..00000000 --- a/expand.c +++ /dev/null @@ -1,324 +0,0 @@ -/* $OpenBSD: expand.c,v 1.31 2018/05/31 21:06:12 gilles Exp $ */ - -/* - * Copyright (c) 2009 Gilles Chehade - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "smtpd.h" -#include "log.h" - -static const char *expandnode_info(struct expandnode *); - -struct expandnode * -expand_lookup(struct expand *expand, struct expandnode *key) -{ - return RB_FIND(expandtree, &expand->tree, key); -} - -int -expand_to_text(struct expand *expand, char *buf, size_t sz) -{ - struct expandnode *xn; - - buf[0] = '\0'; - - RB_FOREACH(xn, expandtree, &expand->tree) { - if (buf[0]) - (void)strlcat(buf, ", ", sz); - if (strlcat(buf, expandnode_to_text(xn), sz) >= sz) - return 0; - } - - return 1; -} - -void -expand_insert(struct expand *expand, struct expandnode *node) -{ - struct expandnode *xn; - - node->rule = expand->rule; - node->parent = expand->parent; - - log_trace(TRACE_EXPAND, "expand: %p: expand_insert() called for %s", - expand, expandnode_info(node)); - if (node->type == EXPAND_USERNAME && - expand->parent && - expand->parent->type == EXPAND_USERNAME && - !strcmp(expand->parent->u.user, node->u.user)) { - log_trace(TRACE_EXPAND, "expand: %p: setting sameuser = 1", - expand); - node->sameuser = 1; - } - - if (expand_lookup(expand, node)) { - log_trace(TRACE_EXPAND, "expand: %p: node found, discarding", - expand); - return; - } - - xn = xmemdup(node, sizeof *xn); - xn->rule = expand->rule; - xn->parent = expand->parent; - if (xn->parent) - xn->depth = xn->parent->depth + 1; - else - xn->depth = 0; - RB_INSERT(expandtree, &expand->tree, xn); - if (expand->queue) - TAILQ_INSERT_TAIL(expand->queue, xn, tq_entry); - expand->nb_nodes++; - log_trace(TRACE_EXPAND, "expand: %p: inserted node %p", expand, xn); -} - -void -expand_clear(struct expand *expand) -{ - struct expandnode *xn; - - log_trace(TRACE_EXPAND, "expand: %p: clearing expand tree", expand); - if (expand->queue) - while ((xn = TAILQ_FIRST(expand->queue))) - TAILQ_REMOVE(expand->queue, xn, tq_entry); - - while ((xn = RB_ROOT(&expand->tree)) != NULL) { - RB_REMOVE(expandtree, &expand->tree, xn); - free(xn); - } -} - -void -expand_free(struct expand *expand) -{ - expand_clear(expand); - - log_trace(TRACE_EXPAND, "expand: %p: freeing expand tree", expand); - free(expand); -} - -int -expand_cmp(struct expandnode *e1, struct expandnode *e2) -{ - struct expandnode *p1, *p2; - int r; - - if (e1->type < e2->type) - return -1; - if (e1->type > e2->type) - return 1; - if (e1->sameuser < e2->sameuser) - return -1; - if (e1->sameuser > e2->sameuser) - return 1; - if (e1->realuser < e2->realuser) - return -1; - if (e1->realuser > e2->realuser) - return 1; - - r = memcmp(&e1->u, &e2->u, sizeof(e1->u)); - if (r) - return (r); - - if (e1->parent == e2->parent) - return (0); - - if (e1->parent == NULL) - return (-1); - if (e2->parent == NULL) - return (1); - - /* - * The same node can be expanded in for different dest context. - * Wen need to distinguish between those. - */ - for(p1 = e1->parent; p1->type != EXPAND_ADDRESS; p1 = p1->parent) - ; - for(p2 = e2->parent; p2->type != EXPAND_ADDRESS; p2 = p2->parent) - ; - if (p1 < p2) - return (-1); - if (p1 > p2) - return (1); - - if (e1->type != EXPAND_FILENAME && e1->type != EXPAND_FILTER) - return (0); - - /* - * For external delivery, we need to distinguish between users. - * If we can't find a username, we assume it is _smtpd. - */ - for(p1 = e1->parent; p1 && p1->type != EXPAND_USERNAME; p1 = p1->parent) - ; - for(p2 = e2->parent; p2 && p2->type != EXPAND_USERNAME; p2 = p2->parent) - ; - if (p1 < p2) - return (-1); - if (p1 > p2) - return (1); - - return (0); -} - -static int -expand_line_split(char **line, char **ret) -{ - static char buffer[LINE_MAX]; - int esc, dq, sq; - size_t i; - char *s; - - memset(buffer, 0, sizeof buffer); - esc = dq = sq = 0; - i = 0; - for (s = *line; (*s) && (i < sizeof(buffer)); ++s) { - if (esc) { - buffer[i++] = *s; - esc = 0; - continue; - } - if (*s == '\\') { - esc = 1; - continue; - } - if (*s == ',' && !dq && !sq) { - *ret = buffer; - *line = s+1; - return (1); - } - - buffer[i++] = *s; - esc = 0; - - if (*s == '"' && !sq) - dq ^= 1; - if (*s == '\'' && !dq) - sq ^= 1; - } - - if (esc || dq || sq || i == sizeof(buffer)) - return (-1); - - *ret = buffer; - *line = s; - return (i ? 1 : 0); -} - -int -expand_line(struct expand *expand, const char *s, int do_includes) -{ - struct expandnode xn; - char buffer[LINE_MAX]; - char *p, *subrcpt; - int ret; - - memset(buffer, 0, sizeof buffer); - if (strlcpy(buffer, s, sizeof buffer) >= sizeof buffer) - return 0; - - p = buffer; - while ((ret = expand_line_split(&p, &subrcpt)) > 0) { - subrcpt = strip(subrcpt); - if (subrcpt[0] == '\0') - continue; - if (!text_to_expandnode(&xn, subrcpt)) - return 0; - if (!do_includes) - if (xn.type == EXPAND_INCLUDE) - continue; - expand_insert(expand, &xn); - } - - if (ret >= 0) - return 1; - - /* expand_line_split() returned < 0 */ - return 0; -} - -static const char * -expandnode_info(struct expandnode *e) -{ - static char buffer[1024]; - const char *type = NULL; - const char *value = NULL; - char tmp[64]; - - switch (e->type) { - case EXPAND_FILTER: - type = "filter"; - break; - case EXPAND_FILENAME: - type = "filename"; - break; - case EXPAND_INCLUDE: - type = "include"; - break; - case EXPAND_USERNAME: - type = "username"; - break; - case EXPAND_ADDRESS: - type = "address"; - break; - case EXPAND_ERROR: - type = "error"; - break; - case EXPAND_INVALID: - default: - return NULL; - } - - if ((value = expandnode_to_text(e)) == NULL) - return NULL; - - (void)strlcpy(buffer, type, sizeof buffer); - (void)strlcat(buffer, ":", sizeof buffer); - if (strlcat(buffer, value, sizeof buffer) >= sizeof buffer) - return NULL; - - (void)snprintf(tmp, sizeof(tmp), "[parent=%p", e->parent); - if (strlcat(buffer, tmp, sizeof buffer) >= sizeof buffer) - return NULL; - - (void)snprintf(tmp, sizeof(tmp), ", rule=%p", e->rule); - if (strlcat(buffer, tmp, sizeof buffer) >= sizeof buffer) - return NULL; - - if (e->rule) { - (void)snprintf(tmp, sizeof(tmp), ", dispatcher=%p", e->rule->dispatcher); - if (strlcat(buffer, tmp, sizeof buffer) >= sizeof buffer) - return NULL; - } - - if (strlcat(buffer, "]", sizeof buffer) >= sizeof buffer) - return NULL; - - return buffer; -} - -RB_GENERATE(expandtree, expandnode, entry, expand_cmp); diff --git a/foobar/.builds/freebsd.yml b/foobar/.builds/freebsd.yml deleted file mode 100644 index 51993106..00000000 --- a/foobar/.builds/freebsd.yml +++ /dev/null @@ -1,23 +0,0 @@ -image: freebsd/latest -packages: -- autoconf -- automake -- bison -- libevent -- libtool -- libressl -- libasr -- py37-ansible -- db6 -- python3 -- python37 -- python -sources: -- https://github.com/OpenSMTPD/OpenSMTPD -- https://github.com/OpenSMTPD/ci -tasks: -- ansible: | - ls -lah - BUILD_DIR=$(pwd)/OpenSMTPD - cd ci/ansible - ansible-playbook test.yml --inventory inventory/freebsd --skip-tags checkout --extra-vars "build_dir=$BUILD_DIR" diff --git a/foobar/.builds/openbsd.yml b/foobar/.builds/openbsd.yml deleted file mode 100644 index a0557a99..00000000 --- a/foobar/.builds/openbsd.yml +++ /dev/null @@ -1,16 +0,0 @@ -image: openbsd/6.6 -packages: -- autoconf-2.69p2 -- automake-1.14.1p1 -- libtool -sources: -- https://github.com/OpenSMTPD/OpenSMTPD -tasks: -- configure: | - cd OpenSMTPD - export AUTOCONF_VERSION=2.69 - ./bootstrap - ./configure -- build: | - cd OpenSMTPD - make diff --git a/foobar/.gitattributes b/foobar/.gitattributes deleted file mode 100644 index eaca2e77..00000000 --- a/foobar/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*/CVS export-ignore diff --git a/foobar/.github/FUNDING.yml b/foobar/.github/FUNDING.yml deleted file mode 100644 index 36cb5950..00000000 --- a/foobar/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -github: [poolpOrg] -patreon: gilles - diff --git a/foobar/.github/workflows/alpine.yml b/foobar/.github/workflows/alpine.yml deleted file mode 100644 index 6f2d29f6..00000000 --- a/foobar/.github/workflows/alpine.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Alpine Linux (amd64 musl openssl) -on: - push: - branches: - - portable - pull_request: - branches: - - portable -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Alpine Linux (amd64 musl openssl) - run: docker build . --file ci/docker/Dockerfile.alpine --tag opensmtpd:alpine diff --git a/foobar/.github/workflows/arch.yml b/foobar/.github/workflows/arch.yml deleted file mode 100644 index a3528152..00000000 --- a/foobar/.github/workflows/arch.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Archlinux (amd64 glibc libressl) -on: - push: - branches: - - portable - pull_request: - branches: - - portable -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Archlinux (amd64 glibc libressl) - run: docker build . --file ci/docker/Dockerfile.archlinux --tag opensmtpd:archlinux diff --git a/foobar/.github/workflows/clang.yml b/foobar/.github/workflows/clang.yml deleted file mode 100644 index 15ccd31d..00000000 --- a/foobar/.github/workflows/clang.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Clang Scan - -on: - schedule: - - cron: '0 23 * * *' # Daily at 23:00 UTC -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: install dependencies - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 9 - sudo apt install \ - clang-tools-9 \ - libasr-dev \ - libevent-dev \ - libssl-dev \ - bison - - uses: actions/checkout@v1 - - name: run scan-build - run: | - export PATH=$PATH:/usr/lib/llvm-9/bin/ - CLANG_SCAN_BADGE_REQUIRED=1 ci/scripts/clang_scan.sh - - name: publish results - run: | - aws s3 rm --recursive s3://opensmtpd/reports/clang/ - cd clang-report - cd "$( find . -type d | sort | tail -n1 )" - aws s3 sync . s3://opensmtpd/reports/clang - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} diff --git a/foobar/.github/workflows/coverity.yml b/foobar/.github/workflows/coverity.yml deleted file mode 100644 index d25bb4f7..00000000 --- a/foobar/.github/workflows/coverity.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Coverity Scan -on: - schedule: - - cron: '0 23 * * *' # Daily at 23:00 UTC -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: dependencies - run: sudo apt install libasr-dev libevent-dev libssl-dev bison - - name: scan - run: sh ci/scripts/coverity_scan.sh - env: - token: ${{ secrets.COVERITY_SCAN_TOKEN }} diff --git a/foobar/.github/workflows/ubuntu-gcc10.yml b/foobar/.github/workflows/ubuntu-gcc10.yml deleted file mode 100644 index 9f70d7f0..00000000 --- a/foobar/.github/workflows/ubuntu-gcc10.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Ubuntu (amd64 glibc openssl gcc10) -on: - push: - branches: - - portable - pull_request: - branches: - - portable -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Ubuntu (amd64 glibc openssl gcc10) - run: docker build . --file ci/docker/Dockerfile.ubuntu-gcc10 --tag opensmtpd:ubuntu-gcc10 diff --git a/foobar/.github/workflows/ubuntu.yml b/foobar/.github/workflows/ubuntu.yml deleted file mode 100644 index c068c6d5..00000000 --- a/foobar/.github/workflows/ubuntu.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Ubuntu (amd64 glibc openssl) -on: - push: - branches: - - portable - pull_request: - branches: - - portable -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Ubuntu (amd64 glibc openssl) - run: docker build . --file ci/docker/Dockerfile.ubuntu --tag opensmtpd:ubuntu diff --git a/foobar/.gitignore b/foobar/.gitignore deleted file mode 100644 index f9f88aa5..00000000 --- a/foobar/.gitignore +++ /dev/null @@ -1,56 +0,0 @@ -*.d -*.o -*.a -*.in -*.out -*.log -.#* -.deps -m4 -aclocal.m4 -autom4te.cache -compile -config.guess -config.h -config.status -config.sub -configure -depcomp -install-sh -libtool -ltmain.sh -missing -parse.c -stamp-h1 -ylwrap -tags -obj - -#Other VCS files -CVS/ -smtpd/CVS -smtpd/smtpctl/CVS -smtpd/smtpd/CVS -smtpd/mail/CVS -smtpd/mail/CVS -smtpd/mail/*/CVS -smtpd/smtpctl/CVS/* - -#Editor temporary files -*~ -.idea - -# Coverity -cov-int/ -cov-analysis-linux64/ -cov-analysis-linux64.tgz -opensmtpd.tgz - -# Clang scan-build -clang-report/ - - -# TLS certs -open.smtpd.cert -open.smtpd.csr -open.smtpd.key diff --git a/foobar/portable/CHANGES.md b/foobar/portable/CHANGES.md deleted file mode 100644 index db25a4db..00000000 --- a/foobar/portable/CHANGES.md +++ /dev/null @@ -1,67 +0,0 @@ -# Release 6.6.3p1 (2020-02-10) - -Following the 6.6.2p1 release, various improvements were done in OpenBSD -current to mitigate the risk of similar bugs. - -This release back-ports them to the portable version of OpenSMTPD. - -# Release 6.6.2p1 (2020-01-28) - -This is CRITICAL security bugfix for -[CVE-2020-7247](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7247) - -Read more details in -[this blog post](https://poolp.org/posts/2020-01-30/opensmtpd-advisory-dissected/) - -# Release 6.6.1p1 (2019-11-06) - -## Changes in this release (since 6.6.0p1) - -This is a bugfix release. No new features were added. - -- Fixed crash on recipient expansion [#968](https://github.com/OpenSMTPD/OpenSMTPD/issues/968) -- Fixed broken build with LibreSSL [#944](https://github.com/OpenSMTPD/OpenSMTPD/issues/944) -- Fixed crash in `arc4random` caused by differences in OpenSSL vs LibreSSL compatibility layer plumbing [#958](https://github.com/OpenSMTPD/OpenSMTPD/issues/958) -- Fixed issue where `from any` rules never matched by IPv6 sources [#969](https://github.com/OpenSMTPD/OpenSMTPD/issues/969) -- Fixed crash that happened during mail relay on musl distros [#929](https://github.com/OpenSMTPD/OpenSMTPD/issues/929) -- Added reference aliases file in `etc/aliases` -- Fixed multiple compilation warnings -[#965](https://github.com/OpenSMTPD/OpenSMTPD/issues/965) -[#966](https://github.com/OpenSMTPD/OpenSMTPD/issues/966) -[#967](https://github.com/OpenSMTPD/OpenSMTPD/issues/967) -[#978](https://github.com/OpenSMTPD/OpenSMTPD/issues/978) -[#977](https://github.com/OpenSMTPD/OpenSMTPD/issues/977) -[#975](https://github.com/OpenSMTPD/OpenSMTPD/issues/975) - - - -# Release 6.6.0p1 (2019-10-26) - -## Dependencies note: - -This release builds with LibreSSL > 3.0.2 or OpenSSL > 1.1.0. - -It's preferable to depend on LibreSSL as OpenSMTPD is written and tested -with that dependency. In addition, the features parity is not respected, -some features will not be available with OpenSSL, like ECDSA server-side -certificates support in this release. OpenSSL library is considered as a -best effort target TLS library and provided as a commodity, LibreSSL has -become our target TLS library. - - -## Changes in this release (since 6.4.0): - -- various improvements to documentation and code -- reverse dns session matching criteria added to smtpd.conf(5) -- regex table lookup support added to smtpd.conf(5) -- introduced support for ECDSA certificates with an ECDSA privsep engine -- introduced builtin filters for basic filtering of incoming sessions -- introduced option to deliver junk to a Junk folder in mail.maildir(8) -- fixed the smtp(1) client so it uses correct default port for SMTPS -- fixed an smtpd(8) crash on excessively large input -- ensured mail rejected by an LMTP server stay queued - - -## Experimental features: - -- introduced a filters API to allow writing standalone filters for smtpd -- introduced proxy-v2 support allowing smtpd to operate behind a proxy diff --git a/foobar/portable/INSTALL b/foobar/portable/INSTALL deleted file mode 100644 index d3c5b40a..00000000 --- a/foobar/portable/INSTALL +++ /dev/null @@ -1,237 +0,0 @@ -Installation Instructions -************************* - -Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006, 2007 Free Software Foundation, Inc. - -This file is free documentation; the Free Software Foundation gives -unlimited permission to copy, distribute and modify it. - -Basic Installation -================== - -Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for -instructions specific to this package. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. - - Running `configure' might take a while. While running, it prints - some messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - - 6. Often, you can also type `make uninstall' to remove the installed - files again. - -Compilers and Options -===================== - -Some systems require unusual options for compilation or linking that the -`configure' script does not know about. Run `./configure --help' for -details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c99 CFLAGS=-g LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - -You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - With a non-GNU `make', it is safer to compile the package for one -architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before -reconfiguring for another architecture. - -Installation Names -================== - -By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - -Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - -There may be some features `configure' cannot figure out automatically, -but needs to determine by the type of machine the package will run on. -Usually, assuming the package is built to be run on the _same_ -architectures, `configure' can figure that out, but if it prints a -message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - -If you want to set default values for `configure' scripts to share, you -can create a site shell script called `config.site' that gives default -values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - -Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified `gcc' to be used as the C compiler (unless it is -overridden in the site shell script). - -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf bug. Until the bug is fixed you can use this workaround: - - CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash - -`configure' Invocation -====================== - -`configure' recognizes the following options to control how it operates. - -`--help' -`-h' - Print a summary of the options to `configure', and exit. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. - diff --git a/foobar/portable/LICENSE b/foobar/portable/LICENSE deleted file mode 100644 index f1cea087..00000000 --- a/foobar/portable/LICENSE +++ /dev/null @@ -1,342 +0,0 @@ -This file is part of the OpenSMTPD software. - -The licences which components of this software fall under are as -follows. First, we will summarize and say that all components -are under a BSD licence, or a licence more free than that. - -OpenSMTPD contains no GPL code. - -Portable OpenSMTPD is divided in 4 parts: -- Original OpenSMTPD -- mail.local -- openbsd-compat -- smtpctl encrypt sub command - - - -OpenSMTPD -========= - - -1) Almost all code is licensed under an ISC-style license, to the following - copyright holders: - - Gilles Chehade - Eric Faurot - Jacek Masiulaniec - Pierre-Yves Ritschard - Henning Brauer - Esben Norby - Markus Friedl - Daniel Hartmeier - Theo de Raadt - Claudio Jeker - Reyk Floeter - Janne Johansson - Alexander Schrijver - Marc Balmer - Ashish Shukla - Ryan Kavanagh - Charles Longeau - - -2) ssl_privsep.c - - /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - - /* - * SSL operations needed when running in a privilege separated environment. - * Adapted from openssl's ssl_rsa.c by Pierre-Yves Ritschard . - */ - - - -mail.local -========== - - -1) mail.local is covered by a 3-clause BSD license, to the following - copyright holders: - - The Regents of the University of California. - David Mazieres - Theo de Raadt - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - - - -openbsd-compat -============== - - -Most of the OpenBSD compatibility layer is based on the work by Damien Miller for -Portable OpenSSH. - -1) Almost all code is licensed under an ISC-style license, to the following - copyright holders: - - Internet Software Consortium. - David Mazieres - Damien Miller - Markus Friedl - Todd C. Miller - Henning Brauer - Pierre-Yves Ritschard - Reyk Floeter - Theo de Raadt - Ted Unangst - Charles Longeau - - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - - -2) base64.{c,h} in addition to beeing covered by an ISC-style licence, is also - covered by this one: - - * Portions Copyright (c) 1995 by International Business Machines, Inc. - * - * International Business Machines, Inc. (hereinafter called IBM) grants - * permission under its copyrights to use, copy, modify, and distribute this - * Software with or without fee, provided that the above copyright notice and - * all paragraphs of this notice appear in all copies, and that the name of IBM - * not be used in connection with the marketing of any product incorporating - * the Software or modifications thereof, without specific, written prior - * permission. - * - * To the extent it has a right to do so, IBM grants an immunity from suit - * under its patents, if any, for the use, sale or manufacture of products to - * the extent that such products are used for performing Domain Name System - * dynamic updates in TCP/IP networks by means of the Software. No immunity is - * granted for any product per se or for any other function of any product. - * - * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, - * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN - * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - - -3) Portable OpenSMTPD includes code under the 2-clause BSD license, from the - following copyright holders: - - Ben Lindstrom - Damien Miller - Marc Espie - Tim Rice - The NetBSD Foundation, Inc. - Jason R. Thorpe? - Niels Provos - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -4) Some code is under a 3-clause BSD license, from the - following copyright holders: - - The Regents of the University of California. - Ian F. Darwin - Damien Miller - Eric P. Allman - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - - -5) Some code is under a 4-clause BSD license, from the - following copyright holder: - - Christos Zoulas - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christos Zoulas. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -6) includes.h, log.h, setresguid.c, xmalloc.c, xmalloc.c - - * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland - * All rights reserved - * - * As far as I am concerned, the code I have written for this software - * can be used freely for any purpose. Any derived versions of this - * software must be clearly marked as such, and if the derived work is - * incompatible with the protocol description in the RFC file, it must be - * called by a name other than "ssh" or "Secure Shell". - - -7) chacha_private.h - -D. J. Bernstein -Public domain. - - -8) bootstrap (only there in the git repository) - - # Copyright (c) 2002-2011 Sam Hocevar - # - # This program is free software. It comes without any warranty, to - # the extent permitted by applicable law. You can redistribute it - # and/or modify it under the terms of the Do What The Fuck You Want - # To Public License, Version 2, as published by Sam Hocevar. See - # http://sam.zoy.org/wtfpl/COPYING for more details. - - - -smtpctl encrypt sub command -=========================== - - -smtpctl encrypt sub command is licensed under an ISC-style license, to the -following copyright holders: - - Sunil Nimmagadda - Gilles Chehade diff --git a/foobar/portable/Makefile.am b/foobar/portable/Makefile.am deleted file mode 100644 index 7d95a5b8..00000000 --- a/foobar/portable/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = openbsd-compat mk contrib - -ACLOCAL_AMFLAGS = -I m4 diff --git a/foobar/portable/README.md b/foobar/portable/README.md deleted file mode 100644 index c00663cd..00000000 --- a/foobar/portable/README.md +++ /dev/null @@ -1,201 +0,0 @@ -# OpenSMTPD - -[![Version](https://img.shields.io/badge/Version-6.6.3p1-brihtgreen.svg)](https://github.com/OpenSMTPD/OpenSMTPD/releases/tag/6.6.3p1) -[![Coverity Scan analysis](https://scan.coverity.com/projects/278/badge.svg)](https://scan.coverity.com/projects/opensmtpd-opensmtpd) -[![Packaging status](https://repology.org/badge/tiny-repos/opensmtpd.svg)](https://repology.org/project/opensmtpd/versions) -[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://www.isc.org/licenses/) -[![Clang Analysis](https://opensmtpd.email/reports/clang/badge.svg)](https://opensmtpd.email/reports/clang/index.html) - - -OpenSMTPD is a FREE implementation of the server-side SMTP protocol as -defined by [RFC 5321](https://tools.ietf.org/html/rfc5321), with some -additional standard extensions. - -It allows ordinary machines to exchange e-mails with other systems -speaking the SMTP protocol. - -OpenSMTPD runs on top of the OpenBSD operating system but also has a -portable version that can build and run on several systems, including: - -* Linux -* FreeBSD -* NetBSD -* DragonFly - -For more information: http://www.opensmtpd.org/portable.html - -People interested about OpenSMTPD are encouraged to subscribe to our -mailing list: http://www.opensmtpd.org/list.html - -and to join the IRC channel: #OpenSMTPD @ irc.freenode.net - -Also note that we have a wiki at -https://github.com/OpenSMTPD/OpenSMTPD/wiki that you are encouraged to -contribute to. - -Cheers! - - -# How to build, configure and use Portable OpenSMTPD - -## Dependencies - -Portable OpenSMTPD relies on: - * autoconf (http://www.gnu.org/software/autoconf/) - * automake (http://www.gnu.org/software/automake/) - * bison (http://www.gnu.org/software/bison/) - or byacc (http://invisible-island.net/byacc/byacc.html) - * libevent (http://libevent.org/) - * libtool (http://www.gnu.org/software/libtool/) - * libressl (https://www.libressl.org/) - or OpenSSL (https://www.openssl.org/) - - -By default OpenSMTPD expects latest versions of all dependencies unless noted otherwise. - -Note that some distributions have different packages for a same library, you should always use the `-dev` or `-devel` package (for example, `libevent-dev` or `libevent-devel`) if you're going to build OpenSMTPD yourself. - - -## Get the source - - git clone -b portable git://github.com/OpenSMTPD/OpenSMTPD.git opensmtpd - - -## Build - - cd opensmtpd* - ./bootstrap # Only if you build from git sources - ./configure - make - sudo make install - -### Special notes for FreeBSD/DragonFlyBSD/Mac OS X: - -Please launch configure with special directive about libevent and -libasr directory: - -### FreeBSD / DragonFlyBSD: - - ./configure --with-libasr=/usr/local - -### Mac OS X: - - ./configure --with-libevent=/opt/local --with-libasr=/opt/local - - -## Install - - sudo make install - - -## Setup historical interface - -OpenSMTPD provides a single utility `smtpctl` to control the daemon and -the local submission subsystem. - -To accomodate systems that require historical interfaces such as `sendmail`, -`newaliases` or `makemap`, the `smtpctl` utility can operate in compatibility -mode if called with the historical name. - -On mailwrapper-enabled systems, this is achieved by editing `/etc/mailer.conf` -and adding the following lines: - - sendmail /usr/sbin/smtpctl - send-mail /usr/sbin/smtpctl - mailq /usr/sbin/smtpctl - makemap /usr/sbin/smtpctl - newaliases /usr/sbin/smtpctl - - -Whereas on systems that don't provide mailwrapper, it can be achieved by -setting the appropriate symbolic links: - - ln -s /usr/sbin/smtpctl sendmail - ln -s /usr/sbin/smtpctl send-mail - ln -s /usr/sbin/smtpctl mailq - ln -s /usr/sbin/smtpctl makemap - ln -s /usr/sbin/smtpctl newaliases - - -The OpenSMTPD project leaves it up to the package maintainers to setup the -links in their packages as it is very hard for us to accomodate all systems -with the prefered method in a clean way. - - -## Configure /etc/smtpd.conf - -Please have a look at the complete format description of smtpd.conf -configuration file (https://man.openbsd.org/smtpd.conf) - - -## Add OpenSMTPD users - -To operate, OpenSMTPD requires at least one user, by default `_smtpd`; and -preferably two users, by default `_smtpd` and `_smtpq`. - -Using two users instead of one will increase security by a large factor -so... if you want to voluntarily reduce security or you have absolute -more faith in our code than we do, by all means use one. - - -The instructions below assume the default users however, the configure -script allows overriding these using the options: -`--with-user-smtpd`, `--with-user-queue`, and `--with-group-queue`. - - -### NetBSD, Linux (Debian, Arch Linux, ...) - - mkdir /var/empty - useradd -c "SMTP Daemon" -d /var/empty -s /sbin/nologin _smtpd - useradd -c "SMTPD Queue" -d /var/empty -s /sbin/nologin _smtpq - -### DragonFlyBSD, FreeBSD - - pw useradd _smtpd -c "SMTP Daemon" -d /var/empty -s /sbin/nologin - pw useradd _smtpq -c "SMTPD Queue" -d /var/empty -s /sbin/nologin - -### Mac OS X - -First we need a group with an unused GID below `500`, list the current -ones used: - - /usr/bin/dscl . -list /Groups PrimaryGroupID | sort -n -k2,2 - -Add a group - here we have picked `444`: - - /usr/bin/sudo /usr/bin/dscl . -create /Groups/_smtpd - PrimaryGroupID 444 - -Then the user. Again we need an unused UID below `500`, list the current -ones used: - - /usr/bin/dscl . -list /Users UniqueID | sort -n -k2,2 - -Add a user - here we have picked `444`: - - /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd UniqueID 444 - /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd AuthenticationAuthority - /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd PasswordPolicyOptions - /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd dsAttrTypeNative:KerberosKeys - /usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd dsAttrTypeNative:ShadowHashData - /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd RealName "SMTP Daemon" - /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd Password "*" - /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd PrimaryGroupID 444 - /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd NFSHomeDirectory /var/empty - /usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd UserShell /usr/bin/false - -repeat for the `_smtpq` user. - - -## Launch smtpd - -First, kill any running sendmail/exim/qmail/postfix or other. - -Then: - - smtpd - -or in debug and verbose mode - - smtpd -dv - diff --git a/foobar/portable/bootstrap b/foobar/portable/bootstrap deleted file mode 100755 index 24e29440..00000000 --- a/foobar/portable/bootstrap +++ /dev/null @@ -1,151 +0,0 @@ -#! /bin/sh - -# bootstrap: generic bootstrap/autogen.sh script for autotools projects -# -# Copyright (c) 2002-2011 Sam Hocevar -# -# This program is free software. It comes without any warranty, to -# the extent permitted by applicable law. You can redistribute it -# and/or modify it under the terms of the Do What The Fuck You Want -# To Public License, Version 2, as published by Sam Hocevar. See -# http://sam.zoy.org/wtfpl/COPYING for more details. -# -# The latest version of this script can be found at the following place: -# http://caca.zoy.org/wiki/build - -# Die if an error occurs -set -e - -# Guess whether we are using configure.ac or configure.in -if test -f configure.ac; then - conffile="configure.ac" -elif test -f configure.in; then - conffile="configure.in" -else - echo "$0: could not find configure.ac or configure.in" - exit 1 -fi - -# Check for needed features -auxdir="`sed -ne 's/^[ \t]*A._CONFIG_AUX_DIR *([[ ]*\([^] )]*\).*/\1/p' $conffile`" -pkgconfig="`grep '^[ \t]*PKG_PROG_PKG_CONFIG' $conffile >/dev/null 2>&1 && echo yes || echo no`" -libtool="`grep '^[ \t]*A._PROG_LIBTOOL' $conffile >/dev/null 2>&1 && echo yes || echo no`" -header="`grep '^[ \t]*A._CONFIG_HEADER' $conffile >/dev/null 2>&1 && echo yes || echo no`" -makefile="`[ -f Makefile.am ] && echo yes || echo no`" -aclocalflags="`sed -ne 's/^[ \t]*ACLOCAL_AMFLAGS[ \t]*=//p' Makefile.am 2>/dev/null || :`" - -# Check for automake -amvers="no" -for v in 16.1 16 15 14 13; do - if automake-1.${v} --version >/dev/null 2>&1; then - amvers="-1.${v}" - break - elif automake1.${v} --version >/dev/null 2>&1; then - amvers="1.${v}" - break - fi -done - -if test "${amvers}" = "no" && automake --version > /dev/null 2>&1; then - amvers="`automake --version | sed -e '1s/[^0-9]*//' -e q`" - if `echo "$amvers\n1.14" | sort -V | head -n 1 | grep -q "$amvers"`; then - amvers="no" - else - amvers="" - fi -fi - -if test "$amvers" = "no"; then - echo "$0: you need automake version 1.14 or later" - exit 1 -fi - -# Check for autoconf -acvers="no" -for v in "" "269" "-2.69"; do - if autoconf${v} --version >/dev/null 2>&1; then - acvers="${v}" - break - fi -done - -if test "$acvers" = "no"; then - echo "$0: you need autoconf" - exit 1 -fi - -# Check for libtool -if test "$libtool" = "yes"; then - libtoolize="no" - if glibtoolize --version >/dev/null 2>&1; then - libtoolize="glibtoolize" - else - for v in "16" "15" "" "14"; do - if libtoolize${v} --version >/dev/null 2>&1; then - libtoolize="libtoolize${v}" - break - fi - done - fi - - if test "$libtoolize" = "no"; then - echo "$0: you need libtool" - exit 1 - fi -fi - -# Check for pkg-config -if test "$pkgconfig" = "yes"; then - if ! pkg-config --version >/dev/null 2>&1; then - echo "$0: you need pkg-config" - exit 1 - fi -fi - -# Remove old cruft -for x in aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh; do rm -f $x autotools/$x; if test -n "$auxdir"; then rm -f "$auxdir/$x"; fi; done -rm -Rf autom4te.cache -if test -n "$auxdir"; then - if test ! -d "$auxdir"; then - mkdir "$auxdir" - fi - aclocalflags="${aclocalflags} -I $auxdir -I ." -fi - -# Honour M4PATH because sometimes M4 doesn't -save_IFS=$IFS -IFS=: -tmp="$M4PATH" -for x in $tmp; do - if test -n "$x"; then - aclocalflags="${aclocalflags} -I $x" - fi -done -IFS=$save_IFS - -# Explain what we are doing from now -set -x - -# Bootstrap package -if test "$libtool" = "yes"; then - ${libtoolize} --copy --force - if test -n "$auxdir" -a ! "$auxdir" = "." -a -f "ltmain.sh"; then - echo "$0: working around a minor libtool issue" - mv ltmain.sh "$auxdir/" - fi -fi - -aclocal${amvers} ${aclocalflags} -autoconf${acvers} -if test "$header" = "yes"; then - autoheader${acvers} -fi -if test "$makefile" = "yes"; then - #add --include-deps if you want to bootstrap with any other compiler than gcc - #automake${amvers} --add-missing --copy --include-deps - automake${amvers} --foreign --add-missing --copy -fi - -# Remove cruft that we no longer want -rm -Rf autom4te.cache - diff --git a/foobar/portable/ci/COVERITY.MD5SUM b/foobar/portable/ci/COVERITY.MD5SUM deleted file mode 100644 index 67b8a2de..00000000 --- a/foobar/portable/ci/COVERITY.MD5SUM +++ /dev/null @@ -1 +0,0 @@ -d0d7d7df9d6609e578f85096a755fb8f ./cov-analysis-linux64.tgz diff --git a/foobar/portable/ci/README.md b/foobar/portable/ci/README.md deleted file mode 100644 index 2eee08f1..00000000 --- a/foobar/portable/ci/README.md +++ /dev/null @@ -1,83 +0,0 @@ -# Continuous Integration - -This directory contains CI/CD related scripts and resources - -CI/CD process leverages GitHub Actions as a primary automation platform since -up to 20 parallel workflows are available for opensource projects. - -On high level we have multiple dimensions to test: - - - OS Distribution - - TLS library implementation: libress, openssl - - libc implementations: glibc, musl - - compiler: gcc, clang (not yet tested) - -Within this matrix build tests, static code analysis, functional and -integration tests are planned. Currently only build tests and static code -analysis exist. Help is much needed with developing functional and integration -tests. - -## Directory strucuture - -- [docker](#dockerfiles) dockerfiles for various distributions -- [scripts](#scripts) useful scripts for ci/cd automation - - -## Design Considerations - -- Keep workflow yaml files and execution logic as separate as possible. - Reference ci scripts from workflow files to allow running same tests - locally, without depending on github. - - - -# Dockerfiles - -Dockerfiles in [docker](docker/) directory can be used for developing and -testing OpenSMTPD. These dockerfiles are intended to be used for dev/test -cycle ONLY and ARE NOT intended to be a delivery mechanism for end users and -should not be published on external resouces like DockerHub. Dockerfiles in -this folder can be used as a reference for package maintainers of various -distributions. - - -## Usage - -OpenSMTPD provides a set of dockerfiles for getting started with development -quickly locally or with GitHub's Actions. - -For each distribution there is a separate dockerfile with a distro name -suffixed. E.g. `Dockerfile.alpine` is a dockerfile that builds OpenSMTPD in -Alpine Linux environment. - -To build: - - docker build -f docker/Dockerfile.alpine -t opensmtpd-alpine - - -All configuration files that are in `/etc/mail` are taken from `etc/` directory. - - -To run the container that you've just built run: - - docker run --name smtpd_server -p 25:25 opensmtpd-alpine - - - -# Scripts - -Scripts to automate ci/cd actions: - -- [coverity_scan](scripts/coverity_scan.sh) - runs coverity scan and submits - the rusult to Coverity. See script contents for usage instructions. - -- [generate_certs](scripts/generate_certs.sh) - convenient script to quickly - generate some TLS certificates. Useful for testing. - -# Historical reference - -[Initial design discusstion](https://github.com/OpenSMTPD/OpenSMTPD/issues/947) - - - - diff --git a/foobar/portable/ci/docker/Dockerfile.alpine b/foobar/portable/ci/docker/Dockerfile.alpine deleted file mode 100644 index 2c7c66fc..00000000 --- a/foobar/portable/ci/docker/Dockerfile.alpine +++ /dev/null @@ -1,50 +0,0 @@ -FROM alpine:3.11 as build - -# creates /opensmtpd dir and makes all following commands to run in it -# https://docs.docker.com/engine/reference/builder/#workdir -WORKDIR /opensmtpd - -# install necessary packages -RUN apk add --no-cache \ - autoconf \ - automake \ - bison \ - ca-certificates \ - fts-dev \ - gcc \ - fts \ - libevent-dev \ - libtool \ - libtool \ - linux-pam-dev \ - make \ - musl-dev \ - libressl \ - libressl-dev \ - zlib-dev - -# create users and directories -# note: alpine uses busybox and useradd is not available there -# also long flags are not available too, so sorry for the -RUN mkdir -p /var/lib/opensmtpd/empty \ - && adduser _smtpd -h /var/lib/opensmtpd/empty/ -D -H -s /bin/false \ - && adduser _smtpq -h /var/lib/opensmtpd/empty/ -D -H -s /bin/false \ - && mkdir -p /var/spool/smtpd \ - && mkdir -p /var/mail \ - && mkdir -p /etc/mail \ - && chmod 711 /var/spool/smtpd - -# Copy contentes of the repo inside the container -# https://docs.docker.com/engine/reference/builder/#copy -COPY . /opensmtpd - -# build opensmtpd -RUN ./bootstrap \ - && ./configure \ - --with-gnu-ld \ - --sysconfdir=/etc/mail \ - --with-auth-pam \ - && make \ - && make install \ - && cp etc/aliases /etc/mail/aliases - diff --git a/foobar/portable/ci/docker/Dockerfile.archlinux b/foobar/portable/ci/docker/Dockerfile.archlinux deleted file mode 100644 index dcd46684..00000000 --- a/foobar/portable/ci/docker/Dockerfile.archlinux +++ /dev/null @@ -1,62 +0,0 @@ -FROM archlinux - -# Allow container to expose ports at runtime, if necessary -# https://docs.docker.com/engine/reference/#expose -EXPOSE 25 -EXPOSE 465 -EXPOSE 587 - -# creates /opensmtpd dir and makes all following commands to run in it -# https://docs.docker.com/engine/reference/builder/#workdir -WORKDIR /opensmtpd - -# install necessary packages -RUN pacman -Suy --noconfirm \ - base \ - make \ - m4 \ - grep \ - gcc \ - automake \ - autoconf \ - libtool \ - bison \ - gettext \ - libevent \ - libressl \ - pam \ - zlib - - -# create users and directories -RUN mkdir -p /var/lib/opensmtpd/empty \ - && useradd _smtpd \ - --home-dir /var/lib/opensmtpd/empty \ - --no-create-home \ - --shell /bin/false \ - && useradd _smtpq \ - --home-dir /var/lib/opensmtpd/empty \ - --no-create-home \ - --shell /bin/false \ - && mkdir -p /var/spool/smtpd \ - && mkdir -p /var/mail \ - && mkdir -p /etc/mail \ - && chmod 711 /var/spool/smtpd - - -# Copy contentes of the repo inside the container -# https://docs.docker.com/engine/reference/builder/#copy -COPY . /opensmtpd - - -# build opensmtpd -RUN ./bootstrap \ - && ./configure --with-gnu-ld \ - --sysconfdir=/etc/mail \ - --with-cflags='-I/usr/include/libressl -L/usr/lib/libressl -Wl,-rpath=/usr/lib/libressl' \ - --with-path-empty=/var/lib/opensmtpd/empty \ - --with-auth-pam \ - && make \ - && make install \ - && cp etc/aliases /etc/mail/aliases - diff --git a/foobar/portable/ci/docker/Dockerfile.ubuntu b/foobar/portable/ci/docker/Dockerfile.ubuntu deleted file mode 100644 index 6626033d..00000000 --- a/foobar/portable/ci/docker/Dockerfile.ubuntu +++ /dev/null @@ -1,52 +0,0 @@ -FROM ubuntu:latest - -# Allow container to expose ports at runtime, if necessary -# https://docs.docker.com/engine/reference/#expose -EXPOSE 25 -EXPOSE 465 -EXPOSE 587 - -# creates /opensmtpd dir and makes all following commands to run in it -# https://docs.docker.com/engine/reference/builder/#workdir -WORKDIR /opensmtpd - -# install necessary packages -RUN apt update \ - && apt install -y --no-install-recommends \ - autoconf \ - automake \ - bison \ - build-essential \ - libevent-dev \ - libssl-dev \ - libtool \ - libpam0g-dev \ - zlib1g-dev - -# create users and directories -RUN mkdir -p /var/lib/opensmtpd/empty \ - && useradd _smtpd \ - --home-dir /var/lib/opensmtpd/empty \ - --no-create-home \ - --shell /bin/false \ - && useradd _smtpq \ - --home-dir /var/lib/opensmtpd/empty \ - --no-create-home \ - --shell /bin/false \ - && mkdir -p /var/spool/smtpd \ - && mkdir -p /var/mail \ - && mkdir -p /etc/mail \ - && chmod 711 /var/spool/smtpd - -# Copy contentes of the repo inside the container -# https://docs.docker.com/engine/reference/builder/#copy -COPY . /opensmtpd - -RUN ./bootstrap \ - && ./configure \ - --with-gnu-ld \ - --sysconfdir=/etc/mail \ - --with-auth-pam \ - && make \ - && make install \ - && cp etc/aliases /etc/mail/aliases diff --git a/foobar/portable/ci/docker/Dockerfile.ubuntu-gcc10 b/foobar/portable/ci/docker/Dockerfile.ubuntu-gcc10 deleted file mode 100644 index 2ebbdf58..00000000 --- a/foobar/portable/ci/docker/Dockerfile.ubuntu-gcc10 +++ /dev/null @@ -1,54 +0,0 @@ -FROM ubuntu:latest - -# Allow container to expose ports at runtime, if necessary -# https://docs.docker.com/engine/reference/#expose -EXPOSE 25 -EXPOSE 465 -EXPOSE 587 - -# creates /opensmtpd dir and makes all following commands to run in it -# https://docs.docker.com/engine/reference/builder/#workdir -WORKDIR /opensmtpd - -# install necessary packages -RUN apt update \ - && apt install -y --no-install-recommends \ - autoconf \ - automake \ - bison \ - build-essential \ - libevent-dev \ - libssl-dev \ - libtool \ - libpam0g-dev \ - zlib1g-dev \ - gcc-10 - -# create users and directories -RUN mkdir -p /var/lib/opensmtpd/empty \ - && useradd _smtpd \ - --home-dir /var/lib/opensmtpd/empty \ - --no-create-home \ - --shell /bin/false \ - && useradd _smtpq \ - --home-dir /var/lib/opensmtpd/empty \ - --no-create-home \ - --shell /bin/false \ - && mkdir -p /var/spool/smtpd \ - && mkdir -p /var/mail \ - && mkdir -p /etc/mail \ - && chmod 711 /var/spool/smtpd - -# Copy contentes of the repo inside the container -# https://docs.docker.com/engine/reference/builder/#copy -COPY . /opensmtpd - -RUN export CC=gcc-10 CXX=g++-10 -RUN ./bootstrap \ - && ./configure \ - --with-gnu-ld \ - --sysconfdir=/etc/mail \ - --with-auth-pam \ - && make \ - && make install \ - && cp etc/aliases /etc/mail/aliases diff --git a/foobar/portable/ci/scripts/clang_scan.sh b/foobar/portable/ci/scripts/clang_scan.sh deleted file mode 100755 index 714d55a7..00000000 --- a/foobar/portable/ci/scripts/clang_scan.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -set -eu - -# Unconditionally go to the root level of the git repo. -# If you invoke it from outside of the repo go to -# the script location first -cd "$(dirname "$0")" -cd "$(git rev-parse --show-toplevel)" - -# Clang Scan script -# -# USAGE: -# - clang must be installed -# - make sure you have clean repository, -# e.g. git clean -ffdx -# - if you want to download github badge set CLANG_SCAN_BADGE_REQUIRED variable -# - Run script from anywhere inside the repository -# ./ci/scripts/clang_scan.sh -# or -# CLANG_SCAN_BADGE_REQUIRED=1 ./ci/scripts/clang_scan.sh -# - -if ! type scan-build > /dev/null; then - echo "clang scan-build is missing" - exit 1 -fi - -# Unconditionally go to the root level of the git repo. -# If you invoke it from outside of the repo go to -# the script location first -cd "$(dirname "$0")" -# This moves us to the root of the repo -cd "$(git rev-parse --show-toplevel)" - -# Get short SHA of the HEAD -sha=$(git rev-parse --short HEAD) - -results_dir=${CLANG_SCAN_RESULTS_DIR:-clang-report} -mkdir -p "$results_dir" - -# Build with scan-build -./bootstrap -./configure -scan-build -o "$results_dir" \ - --keep-empty \ - --html-title="OpenSMTPD $sha" make - - -set -x -# conditionally generate badge -if [ -z "${CLANG_SCAN_BADGE_REQUIRED:-}" ]; then - echo "Skipping badge generation" -else - echo "Generating badge" - . ci/scripts/imports/badge.sh - cd "$results_dir" - cd "$( find . -type d | sort | tail -n1 )" - issues_nr="$( find . -name "report-*" | wc -l)" - download_badge "$issues_nr" "clang analysis" "$(pwd)" 30 -fi diff --git a/foobar/portable/ci/scripts/coverity_scan.sh b/foobar/portable/ci/scripts/coverity_scan.sh deleted file mode 100755 index ab302767..00000000 --- a/foobar/portable/ci/scripts/coverity_scan.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh -set -eu - -# Coverity Scan script -# Steps closely follow official documentation https://scan.coverity.com/download -# -# USAGE: provide coverity project token as 'token' environment variable and run -# token=abcdedf ./ci/scripts/coverity_scan.sh -# -# Or uncomment this line and put token here. But do not commit this to git. -# token="" -project_name="OpenSMTPD%2FOpenSMTPD" -cov_analysis_url="https://scan.coverity.com/download/cxx/linux64" -maintainer="ihor@antonovs.family" - -# Unconditionally go to the root level of the git repo. -# If you invoke it from outside of the repo go to -# the script location first -cd "$(dirname "$0")" -# This moves us to the root of the repo -cd "$(git rev-parse --show-toplevel)" - -# Get short SHA of the HEAD -sha=$(git rev-parse --short HEAD) - -# Download Coverity Build Tool if absent -set +x -# shellcheck disable=SC2154 -md5sum -c ./ci/COVERITY.MD5SUM || wget $cov_analysis_url \ - --post-data "token=$token&project=$project_name" \ - -O cov-analysis-linux64.tgz -set -x - -#Check MD5 -md5sum -c ./ci/COVERITY.MD5SUM - -# Extract Coverty Scan Tool -rm -rf ./cov-analysis-linux64 -mkdir -p cov-analysis-linux64 -tar xzf cov-analysis-linux64.tgz --strip 1 -C cov-analysis-linux64 - -# export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH - -# Build with cov-build -./bootstrap -./configure -cov-analysis-linux64/bin/cov-build --dir cov-int make - -# Compress the rusults -tar czvf opensmtpd.tgz cov-int - - -# Submit the result to Coverity Scan -# Some parts are shamelessly taken from: -# https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh -set +x -response=$(curl \ - --silent \ - --write-out "\n%{http_code}\n" \ - --form token="$token" \ - --form email="$maintainer" \ - --form file=@opensmtpd.tgz \ - --form version="portable-$sha" \ - --form description="daily scan" \ - "https://scan.coverity.com/builds?project=$project_name") -set -x - -status_code=$(echo "$response" | sed -n '$p') - -if [ "$status_code" != "200" ]; then - text=$(echo "$response" | sed '$d') - echo -e "Coverity Scan upload failed: $text" - exit 1 -fi - - - diff --git a/foobar/portable/ci/scripts/generate_certs.sh b/foobar/portable/ci/scripts/generate_certs.sh deleted file mode 100755 index a9249c1e..00000000 --- a/foobar/portable/ci/scripts/generate_certs.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -# Generate self-signed SSL certs -# Usage: ./generate_certs.sh - -days=3560 # 10 years -config="$(dirname "$0")/ssl.conf" -cert="open.smtpd.cert" -key="open.smtpd.key" -csr="open.smtpd.csr" - -# Key + CSR generation: -openssl req \ - -new \ - -x509 \ - -newkey rsa:2048 \ - -sha256 \ - -nodes \ - -keyout $key \ - -out $csr \ - -days $days \ - -config "$config" - -# Certificate generation: -openssl req \ - -new \ - -x509 \ - -newkey rsa:2048 \ - -days $days \ - -nodes \ - -config "$config" \ - -keyout $key \ - -out $cert diff --git a/foobar/portable/ci/scripts/imports/badge.sh b/foobar/portable/ci/scripts/imports/badge.sh deleted file mode 100644 index d6cf0b3a..00000000 --- a/foobar/portable/ci/scripts/imports/badge.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# Copyright 2019 Neovim Project Contributors (https://neovim.io/) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Helper functions for getting badges. - -# Get code quality color. -# ${1}: Amount of bugs actually found. -# ${2}: Maximum number of bugs above which color will be red. Defaults to 20. -# ${3}: Maximum number of bugs above which color will be yellow. Defaults to -# $1 / 2. -# Output: 24-bit hexadecimal representation of the color (xxxxxx). -get_code_quality_color() { - bugs=$1 ; shift # shift will fail if there is no argument - max_bugs=${1:-20} - yellow_threshold=${2:-$(( max_bugs / 2 ))} - - red=255 - green=255 - blue=0 - - bugs=$(( bugs < max_bugs ? bugs : max_bugs)) - if test $bugs -ge "$yellow_threshold" ; then - green=$(( 255 - 255 * (bugs - yellow_threshold) / yellow_threshold )) - else - red=$(( 255 * bugs / yellow_threshold )) - fi - - printf "%02x%02x%02x" $red $green $blue -} - -# Get code quality badge. -# ${1}: Amount of bugs actually found. -# ${2}: Badge text. -# ${3}: Directory where to save badge to. -# ${3}: Maximum number of bugs above which color will be red. Defaults to 20. -# ${4}: Maximum number of bugs above which color will be yellow. Defaults to -# $1 / 2. -# Output: 24-bit hexadecimal representation of the color (xxxxxx). -download_badge() { - bugs=$1 ; shift - badge_text="$1" ; shift - reports_dir="$1" ; shift - max_bugs=${1:-20} - yellow_threshold=${2:-$(( max_bugs / 2 ))} - - code_quality_color="$( - get_code_quality_color $bugs $max_bugs $yellow_threshold)" - badge="${badge_text}-${bugs}-${code_quality_color}" - - rm -f "$reports_dir/badge.svg" - - response="$( - curl --tlsv1 "https://img.shields.io/badge/${badge}.svg" \ - -o"$reports_dir/badge.svg" 2>&1)" - - if ! grep -F 'xmlns="http://www.w3.org/2000/svg"' "$reports_dir/badge.svg" ; then - echo "Failed to download badge to $reports_dir: $response" - rm -f "$reports_dir/badge.svg" - fi -} diff --git a/foobar/portable/ci/scripts/ssl.conf b/foobar/portable/ci/scripts/ssl.conf deleted file mode 100644 index eddfb7f8..00000000 --- a/foobar/portable/ci/scripts/ssl.conf +++ /dev/null @@ -1,23 +0,0 @@ -[req] -default_bits = 2048 -prompt = no -default_md = sha256 -x509_extensions = v3_req -distinguished_name = dn - - -# Puffy the pufferfish -# https://en.wikipedia.org/wiki/Tetraodontidae -[dn] -C = AZ -ST = Chordata -L = Actinopterygii_Tetraodontiformes -O = Tetraodontoidei_Tetraodontidae -CN = Puffy - -[v3_req] -subjectAltName = @alt_names - -[alt_names] -DNS.1 = puffy.bsd -DNS.2 = puffy.mail diff --git a/foobar/portable/configure.ac b/foobar/portable/configure.ac deleted file mode 100644 index 33b929c1..00000000 --- a/foobar/portable/configure.ac +++ /dev/null @@ -1,2066 +0,0 @@ -# $Id: configure.ac,v 1.519 2013/03/22 01:49:15 dtucker Exp $ -# -# Copyright (c) 2016 Gilles Chehade -# Copyright (c) 1999-2004 Damien Miller -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - - -# -# WE NEED TO CLEANUP CONFIGURE.AC AND MAKE IT FOLLOW THE -# STANDARD LAYOUT ... -# -# 3.1.3 Standard configure.ac Layout -# -# https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Autoconf-Input-Layout.html -# - - -# -# AUTOCONF REQUIREMENTS -# -AC_PREREQ(2.69) - - -# -# AC_INIT -# -AC_INIT([OpenSMTPD], - [portable], - [bugs@opensmtpd.org], - [opensmtpd], - [https://www.OpenSMTPD.org]) - -AM_INIT_AUTOMAKE([subdir-objects no-dependencies]) -LT_INIT - -# here we should test for variables set by libtool detection -if test "x$with_pic" != "xno"; then - CFLAGS="$CFLAGS ${pic_flag}" -fi - - -# -# PACKAGE INFORMATION -# -AC_LANG([C]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_HEADER([config.h]) -AC_PROG_CC -AC_CANONICAL_HOST -AC_C_BIGENDIAN - - -# -# CHECKS FOR PROGRAMS -# -AC_PROG_CPP -AC_PROG_INSTALL -AC_PROG_LIBTOOL -AC_PATH_PROG([AR], [ar]) -AC_PATH_PROG([CAT], [cat]) -AC_PATH_PROG([CHMOD], [chmod]) -AC_PATH_PROG([CHOWN], [chown]) -AC_PATH_PROG([ZCAT], [zcat]) -AC_PATH_PROG([SED], [sed]) -AC_PATH_PROG([TEST_MINUS_S_SH], [bash]) -AC_PATH_PROG([TEST_MINUS_S_SH], [ksh]) -AC_PATH_PROG([TEST_MINUS_S_SH], [sh]) -AC_PATH_PROG([SH], [sh]) -AC_PATH_PROG([GROFF], [groff]) -AC_PATH_PROG([NROFF], [nroff]) -AC_PATH_PROG([MANDOC], [mandoc]) -AC_PROG_YACC - -AC_SUBST([ZCAT]) - - -if test -z "$AR"; then - AC_MSG_ERROR([*** 'ar' missing, please install or fix your \$PATH ***]) -fi - -if test -z "$LD"; then - LD=$CC -fi -AC_SUBST([LD]) - -dnl select manpage formatter -if test -n "$MANDOC"; then - MANFMT="$MANDOC" -elif test -n "$NROFF"; then - MANFMT="$NROFF -mandoc" -elif test -n "$GROFF"; then - MANFMT="$GROFF -mandoc -Tascii" -else - AC_MSG_WARN([no manpage formatted found]) - MANFMT="false" -fi -AC_SUBST([MANFMT]) - - -# -# CHECKS FOR LIBRARIES -# - - - -# -# CHECKS FOR HEADERS -# -AC_CHECK_HEADERS([ \ - arpa/nameser_compat.h \ - crypt.h \ - dirent.h \ - err.h \ - fcntl.h \ - getopt.h \ - grp.h \ - libgen.h \ - limits.h \ - maillock.h \ - mach/mach_time.h \ - ndir.h \ - netdb.h \ - pam/pam_appl.h \ - paths.h \ - security/pam_appl.h \ - shadow.h \ - sys/cdefs.h \ - sys/dir.h \ - sys/file.h \ - sys/mount.h \ - sys/ndir.h \ - sys/pstat.h \ - sys/statfs.h \ - sys/time.h \ - sys/un.h \ - time.h \ - ucred.h \ - util.h \ - vis.h -]) - -AM_CONDITIONAL([NEED_ERR_H], [test x$HAVE_ERR_H = x1]) -AM_CONDITIONAL([SUPPORT_PATHS_H], [test x$HAVE_PATHS_H = x1]) - -# NetBSD requires sys/types.h before login_cap.h -AC_CHECK_HEADERS([login_cap.h], [], [], [ -#include -]) - -# older BSDs need sys/param.h before sys/mount.h -AC_CHECK_HEADERS([sys/mount.h], [], [], [ -#include -]) - -AC_CHECK_HEADERS([bsd/libutil.h libutil.h]) - -AC_CHECK_HEADER([fts.h], - [], - [AC_MSG_ERROR([*** fts.h missing - please install libfts ***])], - [ -#include -#include -]) - -need_libasr=no -AC_CHECK_HEADER([asr.h], - [], - [need_libasr=yes], - [ -#include -#include -#include -]) -AM_CONDITIONAL([NEED_LIBASR], [test x"$need_libasr" = x"yes"]) - -# -# CHECKS FOR TYPES -# -AC_CHECK_TYPES([long long, unsigned long long, long double, u_int, u_char]) -AC_CHECK_SIZEOF([short int], [2]) -AC_CHECK_SIZEOF([int], [4]) -AC_CHECK_SIZEOF([long int], [4]) -AC_CHECK_SIZEOF([long long int], [8]) - -AC_TYPE_INT8_T -AC_TYPE_INT16_T -AC_TYPE_INT32_T -AC_TYPE_INT64_T -AC_TYPE_UINT8_T -AC_TYPE_UINT16_T -AC_TYPE_UINT32_T -AC_TYPE_UINT64_T -AC_TYPE_INTPTR_T -AC_TYPE_INTMAX_T -AC_TYPE_UINTPTR_T -AC_TYPE_UINTMAX_T -AC_TYPE_SIZE_T -AC_TYPE_SSIZE_T -AC_TYPE_OFF_T -AC_TYPE_MODE_T -AC_TYPE_PID_T -AC_TYPE_UID_T - -TYPE_SOCKLEN_T - -AC_CHECK_TYPES([sig_atomic_t], [], [], [ -#include -]) -AC_CHECK_TYPES([fsblkcnt_t, fsfilcnt_t], [], [], [ -#include -#ifdef HAVE_SYS_BITYPES_H -#include -#endif -#ifdef HAVE_SYS_STATFS_H -#include -#endif -#ifdef HAVE_SYS_STATVFS_H -#include -#endif -]) - -AC_CHECK_TYPES([in_addr_t, in_port_t], [], [], [ -#include -#include -]) - -AC_CHECK_TYPES([sa_family_t], [], [], [ -#include -#include -#include -]) - -AC_CHECK_TYPES([struct timespec]) -AC_CHECK_TYPES([struct ifgroupreq]) -AC_CHECK_TYPES([struct sockaddr_storage], [], [], [ -#include -#include -]) -AC_CHECK_TYPES([struct sockaddr_in6], [], [], [ -#include -#include -]) -AC_CHECK_TYPES([struct in6_addr], [], [], [ -#include -#include -]) -AC_CHECK_TYPES([struct addrinfo], [], [], [ -#include -#include -#include -]) -AC_CHECK_TYPES([struct timeval], [], [], [ -#include -]) - -AC_CHECK_DECL([LLONG_MAX], [have_llong_max=1], , [#include ]) - - -# -# CHECKS FOR STRUCTURES -# -AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [], [ -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#include -]) - -AC_CHECK_MEMBERS([struct passwd.pw_gecos, struct passwd.pw_class, -struct passwd.pw_change, struct passwd.pw_expire], -[], [], [ -#include -#include -]) - -AC_CHECK_MEMBERS([struct stat.st_flags], , , - [ #include - #include ] -) - -AC_CHECK_MEMBERS([struct stat.st_mtim], , , - [ #include - #include ] -) - -AC_CHECK_MEMBERS([struct stat.st_mtimespec], , , - [ #include - #include ] -) - -AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , - [ #include - #include - #include ] -) - -AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , , - [ #include - #include - #include ] -) - -AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , , - [ #include - #include - #include ] -) - -AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_len], , , - [ #include - #include - #include ] -) - -AC_CHECK_MEMBERS([struct statfs.f_favail], , , - [ #include - #include ] -) - -AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family], [], [], [ -#include -#include -]) - -AC_CHECK_MEMBERS([struct sockaddr_storage.__ss_family], [], [], [ -#include -#include -]) - -AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.tm_zone], [], - [ - AC_CHECK_DECLS([timezone, altzone, tzname], - [], - [ AC_MSG_ERROR([cannot find timezone])], - [ #include ] - ) - ], - [ #include ] -) - -AC_CHECK_MEMBERS([struct DIR.d_type], [], [], [ -#include -#include -]) - -# -# CHECKS FOR DECLARATIONS -# -AC_CHECK_DECLS([O_NONBLOCK], [], [], [ -#include -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -]) - -AC_CHECK_DECLS([AF_LOCAL, PF_LOCAL], [], [], [ -#include -]) - -AC_CHECK_DECLS([IPPORT_HILASTAUTO], [], [], [ -#include -]) - -AC_CHECK_DECLS([WAIT_MYPGRP], [], [], [ -#include -]) - -AC_CHECK_DECLS([writev], [], [], [ -#include -#include -#include -]) - -AC_CHECK_DECLS([LOG_PERROR], [], [], [ -#include -]) - - -# -# CHECKS FOR COMPILER CHARACTERISTICS -# -AC_C_INLINE - - -AC_ARG_WITH([libs], - [ --with-libs Specify additional libraries to link with], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - LIBS="$LIBS $withval" - fi - ] -) -# -# CHECKS FOR LIBRARY FUNCTIONS -# -AC_SEARCH_LIBS([basename], - [gen], - [ - AC_DEFINE([HAVE_BASENAME], [1], - [Define if you have the basename() function.]) - ]) - -AC_SEARCH_LIBS([closefrom], - [gen], - [ - AC_DEFINE([HAVE_CLOSEFROM], [1], - [Define if you have the closefrom() function.]) - AC_COMPILE_IFELSE( - [ - AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[int res = closefrom(0);]]) - ], - AC_DEFINE(HAVE_CLOSEFROM_INT, 1, [closefrom return int]) - ) - ]) - -AC_SEARCH_LIBS([fmt_scaled], - [util bsd], - [ - AC_DEFINE([HAVE_FMT_SCALED], [1], - [Define if you have the fmt_scaled() function.]) - ]) - -AC_SEARCH_LIBS([dirname], - [gen], - [ - AC_DEFINE([HAVE_DIRNAME], [1], - [Define if you have the dirname() function.]) - ]) - -AC_SEARCH_LIBS([inet_net_pton], - [resolv bsd], - [ - AC_DEFINE([HAVE_INET_NET_PTON], [1], - [Define if you have the inet_net_pton() function.]) - ]) - -AC_SEARCH_LIBS([clock_gettime], - [rt], - [ - AC_DEFINE([HAVE_CLOCK_GETTIME], [1], - [Define if you have the clock_gettime() function.]) - ]) - -AC_SEARCH_LIBS([fts_open], - [fts], - [ - AC_DEFINE([HAVE_FTS_OPEN], [1], - [Define if you have the fts_open() function.]) - ]) - -AC_SEARCH_LIBS([daemon], - [bsd], - [ - AC_DEFINE([HAVE_DAEMON], [1], - [Define if you have the daemon() function.]) - ]) - -AC_SEARCH_LIBS([fparseln], - [util], - [ - AC_DEFINE([HAVE_FPARSELN], [1], - [Define if you have the fparseln() function.]) - ]) - -AC_SEARCH_LIBS([res_hnok], - [resolv], - [ - AC_DEFINE([HAVE_RES_HNOK], [1], - [Define if you have the res_hnok() function.]) - ]) - -AC_SEARCH_LIBS([res_randomid], - [resolv], - [ - AC_DEFINE([HAVE_RES_RANDOMID], [1], - [Define if you have the res_randomid() function.]) - ]) - -AC_SEARCH_LIBS([res_9_b64_ntop], - [resolv], - [ - AC_DEFINE([HAVE_RES_9_B64_NTOP], [1], - [Define if you have the res_9_b64_ntop() function.]) - ]) - -AC_SEARCH_LIBS([__b64_pton], - [resolv], - [ - AC_DEFINE([HAVE___B64_PTON], [1], - [Define if you have the __b64_pton() function.]) - ]) - -AC_SEARCH_LIBS([b64_pton], - [resolv], - [ - AC_DEFINE([HAVE_B64_PTON], [1], - [Define if you have the b64_pton() function.]) - ]) - -AC_SEARCH_LIBS([__b64_ntop], - [resolv], - [ - AC_DEFINE([HAVE___B64_NTOP], [1], - [Define if you have the b64_ntop() function.]) - ]) - -AC_SEARCH_LIBS([b64_ntop], - [resolv], - [ - AC_DEFINE([HAVE_B64_NTOP], [1], - [Define if you have the b64_ntop() function.]) - ]) - -AC_SEARCH_LIBS([setsockopt], - [socket], - [ - AC_DEFINE([HAVE_SETSOCKOPT], [1], - [Define if you have the setsockopt() function.]) - ]) - -AC_SEARCH_LIBS([crypt], - [crypt], - [ - AC_DEFINE([HAVE_CRYPT], [1], - [Define if you have the crypt() function.]) - ]) - -AC_SEARCH_LIBS([imsg_init], - [util], - [ - AC_DEFINE([HAVE_IMSG], [1], - [Define if you have the imsg framework.]) - ]) - -AC_SEARCH_LIBS([event_asr_run], - [event], - [ - AC_DEFINE([HAVE_EVENT_ASR_RUN], [1], - [Define if you have the event_asr_run() function.]) - ]) - -AC_CHECK_FUNCS([ \ - asprintf \ - arc4random \ - bcopy \ - calloc_conceal \ - chflags \ - crypt_checkpass \ - dirfd \ - err \ - errc \ - errx \ - explicit_bzero \ - fchflags \ - fgetln \ - flock \ - freeaddrinfo \ - freezero \ - getaddrinfo \ - getdtablesize \ - getdtablecount \ - getline \ - getnameinfo \ - gettimeofday \ - getopt \ - getpeereid \ - getpeerucred \ - getspnam \ - inet_aton \ - inet_ntoa \ - inet_ntop \ - malloc_conceal \ - memmove \ - nanosleep \ - nsleep \ - pidfile \ - pledge \ - reallocarray \ - recallocarray \ - res_hnok \ - res_randomid \ - setenv \ - seteuid \ - setegid \ - setproctitle \ - setregid \ - setreuid \ - setresuid \ - setresgid \ - setsid \ - signal \ - sigaction \ - snprintf \ - socketpair \ - strdup \ - strerror \ - strlcat \ - strlcpy \ - strmode \ - strndup \ - strnlen \ - strnvis \ - strtonum \ - sysconf \ - tcgetpgrp \ - time \ - usleep \ - vasprintf \ - vsnprintf \ - waitpid \ - warn \ - warnx \ -]) - -AC_CHECK_DECL([strsep], - [AC_CHECK_FUNCS([strsep])], - [], - [ -#ifdef HAVE_STRING_H -# include -#endif - ]) - - -# These functions might be found in libressl -AC_CHECK_DECLS([strlcat, strlcpy], - [], - [], - []) - -# -# CHECKS FOR SYSTEM SERVICES -# -AC_MSG_CHECKING([for /proc/pid/fd directory]) -if test -d "/proc/$$/fd"; then - AC_DEFINE([HAVE_PROC_PID], [1], [Define if you have /proc/$pid/fd]) - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi - - -# -# AC_CONFIG_FILES -# - -# -# AC_OUTPUT -# - - -### -### EVERYTHING BELOW MUST BE CLEANED AND MOVED ABOVE -### - -#l150 (without _FORTIFY_SOURCE=2) -if test "$GCC" = "yes" -o "$GCC" = "egcs"; then - OSSH_CHECK_CFLAG_COMPILE([-Qunused-arguments]) - OSSH_CHECK_CFLAG_COMPILE([-Wunknown-warning-option]) - OSSH_CHECK_CFLAG_COMPILE([-Wall]) - OSSH_CHECK_CFLAG_COMPILE([-Wpointer-arith]) - OSSH_CHECK_CFLAG_COMPILE([-Wuninitialized]) - OSSH_CHECK_CFLAG_COMPILE([-Wsign-compare]) - OSSH_CHECK_CFLAG_COMPILE([-Wformat-security]) - OSSH_CHECK_CFLAG_COMPILE([-Wsizeof-pointer-memaccess]) - OSSH_CHECK_CFLAG_COMPILE([-Wpointer-sign], [-Wno-pointer-sign]) - OSSH_CHECK_CFLAG_COMPILE([-Wunused-result], [-Wno-unused-result]) - OSSH_CHECK_CFLAG_COMPILE([-fno-strict-aliasing]) -# OSSH_CHECK_CFLAG_COMPILE([-D_FORTIFY_SOURCE=2]) - if test "x$use_toolchain_hardening" = "x1"; then - OSSH_CHECK_LDFLAG_LINK([-Wl,-z,relro]) - OSSH_CHECK_LDFLAG_LINK([-Wl,-z,now]) - OSSH_CHECK_LDFLAG_LINK([-Wl,-z,noexecstack]) - # NB. -ftrapv expects certain support functions to be present in - # the compiler library (libgcc or similar) to detect integer operations - # that can overflow. We must check that the result of enabling it - # actually links. The test program compiled/linked includes a number - # of integer operations that should exercise this. - OSSH_CHECK_CFLAG_LINK([-ftrapv]) - fi - AC_MSG_CHECKING([gcc version]) - GCC_VER=`$CC -v 2>&1 | $AWK '/gcc version /{print $3}'` - case $GCC_VER in - 1.*) no_attrib_nonnull=1 ;; - 2.8* | 2.9*) - no_attrib_nonnull=1 - ;; - 2.*) no_attrib_nonnull=1 ;; - *) ;; - esac - AC_MSG_RESULT([$GCC_VER]) - - AC_MSG_CHECKING([if $CC accepts -fno-builtin-memset]) - saved_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -fno-builtin-memset" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], - [[ char b[10]; memset(b, 0, sizeof(b)); ]])], - [ AC_MSG_RESULT([yes]) ], - [ AC_MSG_RESULT([no]) - CFLAGS="$saved_CFLAGS" ] - ) - - # -fstack-protector-all doesn't always work for some GCC versions - # and/or platforms, so we test if we can. If it's not supported - # on a given platform gcc will emit a warning so we use -Werror. - if test "x$use_stack_protector" = "x1"; then - for t in -fstack-protector-strong -fstack-protector-all \ - -fstack-protector; do - AC_MSG_CHECKING([if $CC supports $t]) - saved_CFLAGS="$CFLAGS" - saved_LDFLAGS="$LDFLAGS" - CFLAGS="$CFLAGS $t -Werror" - LDFLAGS="$LDFLAGS $t -Werror" - AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[ #include ]], - [[ - char x[256]; - snprintf(x, sizeof(x), "XXX"); - ]])], - [ AC_MSG_RESULT([yes]) - CFLAGS="$saved_CFLAGS $t" - LDFLAGS="$saved_LDFLAGS $t" - AC_MSG_CHECKING([if $t works]) - AC_RUN_IFELSE( - [AC_LANG_PROGRAM([[ #include ]], - [[ - char x[256]; - snprintf(x, sizeof(x), "XXX"); - ]])], - [ AC_MSG_RESULT([yes]) - break ], - [ AC_MSG_RESULT([no]) ], - [ AC_MSG_WARN([cross compiling: cannot test]) - break ] - ) - ], - [ AC_MSG_RESULT([no]) ] - ) - CFLAGS="$saved_CFLAGS" - LDFLAGS="$saved_LDFLAGS" - done - fi - - if test -z "$have_llong_max"; then - # retry LLONG_MAX with -std=gnu99, needed on some Linuxes - unset ac_cv_have_decl_LLONG_MAX - saved_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -std=gnu99" - AC_CHECK_DECL([LLONG_MAX], - [have_llong_max=1], - [CFLAGS="$saved_CFLAGS"], - [#include ] - ) - fi -fi - -AC_MSG_CHECKING([if compiler allows __attribute__ on return types]) -AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ -#include -__attribute__((__unused__)) static void foo(void){return;}]], - [[ exit(0); ]])], - [ AC_MSG_RESULT([yes]) ], - [ AC_MSG_RESULT([no]) - AC_DEFINE(NO_ATTRIBUTE_ON_RETURN_TYPE, 1, - [compiler does not accept __attribute__ on return types]) ] -) - -if test "x$no_attrib_nonnull" != "x1"; then - AC_DEFINE([HAVE_ATTRIBUTE__NONNULL__], [1], [Have attribute nonnull]) -fi - -AC_ARG_WITH([rpath], - [ --without-rpath Disable auto-added -R linker paths], - [ - if test "x$withval" = "xno"; then - need_dash_r="" - fi - if test "x$withval" = "xyes"; then - need_dash_r=1 - fi - ] -) - - -AC_ARG_WITH([cflags], - [ --with-cflags Specify additional flags to pass to compiler], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - CFLAGS="$CFLAGS $withval" - fi - ] -) -AC_ARG_WITH([cppflags], - [ --with-cppflags Specify additional flags to pass to preprocessor] , - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - CPPFLAGS="$CPPFLAGS $withval" - fi - ] -) -AC_ARG_WITH([ldflags], - [ --with-ldflags Specify additional flags to pass to linker], - [ - if test -n "$withval" -a "$withval" != "xno" -a "${withval}" != "yes"; then - LDFLAGS="$LDFLAGS $withval" - fi - ] -) -AC_ARG_WITH([Werror], - [ --with-Werror Build main code with -Werror], - [ - if test -n "$withval" -a "$withval" != "no"; then - werror_flags="-Werror" - if test "${withval}" != "yes"; then - werror_flags="$withval" - fi - fi - ] -) - - - -AC_ARG_WITH([pie], - [ --with-pie Build Position Independent Executables if possible], [ - if test "x$withval" = "xno"; then - use_pie=no - fi - if test "x$withval" = "xyes"; then - use_pie=yes - fi - ] -) -if test -z "$use_pie"; then - use_pie=no -fi -if test "x$use_toolchain_hardening" != "x1" -a "x$use_pie" = "xauto"; then - # Turn off automatic PIE when toolchain hardening is off. - use_pie=no -fi -if test "x$use_pie" = "xauto"; then - # Automatic PIE requires gcc >= 4.x - AC_MSG_CHECKING([for gcc >= 4.x]) - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ -#if !defined(__GNUC__) || __GNUC__ < 4 -#error gcc is too old -#endif -]])], - [ AC_MSG_RESULT([yes]) ], - [ AC_MSG_RESULT([no]) - use_pie=no ] -) -fi -if test "x$use_pie" != "xno"; then - SAVED_CFLAGS="$CFLAGS" - SAVED_LDFLAGS="$LDFLAGS" - OSSH_CHECK_CFLAG_COMPILE([-fPIE]) - OSSH_CHECK_LDFLAG_LINK([-pie]) - # We use both -fPIE and -pie or neither. - AC_MSG_CHECKING([whether both -fPIE and -pie are supported]) - if echo "x $CFLAGS" | grep ' -fPIE' >/dev/null 2>&1 && \ - echo "x $LDFLAGS" | grep ' -pie' >/dev/null 2>&1 ; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - CFLAGS="$SAVED_CFLAGS" - LDFLAGS="$SAVED_LDFLAGS" - fi -fi - - - - - - -#l432 (customized) -# Check for some target-specific stuff - -case "$host" in -*-*-darwin*) - use_pie=auto - AC_MSG_CHECKING([if we have working getaddrinfo]) - AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#include -#include -main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16)) - exit(0); - else - exit(1); -} - ]])], - [AC_MSG_RESULT([working])], - [AC_MSG_RESULT([buggy]) - AC_DEFINE([BROKEN_GETADDRINFO], [1], - [getaddrinfo is broken (if present)]) - ], - [AC_MSG_RESULT([assume it is working])]) - AC_DEFINE([SETEUID_BREAKS_SETUID], [1], [define if seteuid breaks setuid]) - AC_DEFINE([BROKEN_SETREUID], [1], [define if setreuid is broken]) - AC_DEFINE([BROKEN_SETREGID], [1], [define if setregid is broken]) - AC_DEFINE([BROKEN_GLOB], [1], [OS X glob does not do what we expect]) - AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV], - [Define to a Set Process Title type if your system is - supported by bsd-setproctitle.c]) - AC_DEFINE([BROKEN_STRNVIS], [1], - [OSX strnvis argument order is swapped compared to OpenBSD]) - BROKEN_STRNVIS=1 - ;; -*-*-dragonfly*) - ;; -*-*-linux* | *-gnu* | *-k*bsd*-gnu* ) - use_pie=auto - CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE" - AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV]) - ;; -*-*-netbsd*) - if test "x$withval" != "xno"; then - need_dash_r=1 - fi - AC_DEFINE([BROKEN_STRNVIS], [1], - [NetBSD strnvis argument order is swapped compared to OpenBSD]) - BROKEN_STRNVIS=1 - ;; -*-*-freebsd*) - AC_DEFINE([BROKEN_GLOB], [1], [FreeBSD glob does not do what we need]) - AC_DEFINE([BROKEN_STRNVIS], [1], - [FreeBSD strnvis argument order is swapped compared to OpenBSD]) - BROKEN_STRNVIS=1 - ;; -*-*-openbsd*) - use_pie=auto - AC_DEFINE([HAVE_ATTRIBUTE__SENTINEL__], [1], [OpenBSD's gcc has sentinel]) - AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD's gcc has bounded]) - - AC_DEFINE([BROKEN_STRNVIS], [0], - [FreeBSD strnvis argument order is swapped compared to OpenBSD]) - BROKEN_STRNVIS=0 - YACC='yacc' - ASR_LIB= - AC_DEFINE([NOOP_ASR_FREEADDRINFO], [0], [OpenBSD doesn't need ASR_FREEADDRINFO]) - ;; -*-sun-solaris*) - AC_DEFINE([HAVE_M_DATA], [1], [M_DATA is defined in sys/stream.h included by netinet/in.h]) - ;; -esac -AC_SUBST([ASR_LIB]) - - -AC_MSG_CHECKING([compiler and flags for sanity]) -AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -#include -#include ]], [[ exit(0); ]])], - [ AC_MSG_RESULT([yes]) ], - [ - AC_MSG_RESULT([no]) - AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***]) - ], - [ AC_MSG_WARN([cross compiling: not checking compiler sanity]) ] -) - - - -#l1747 - - - - -# Check for missing getpeereid (or equiv) support -NO_PEERCHECK="" -if test "x$ac_cv_func_getpeereid" != "xyes" -a "x$ac_cv_func_getpeerucred" != "xyes"; then - AC_MSG_CHECKING([whether system supports SO_PEERCRED getsockopt]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -#include ]], [[int i = SO_PEERCRED;]])], - [ AC_MSG_RESULT([yes]) - AC_DEFINE([HAVE_SO_PEERCRED], [1], [Have PEERCRED socket option]) - ], [AC_MSG_RESULT([no]) - NO_PEERCHECK=1 - ]) -fi - -#l4176 (customized s/ssh.1/smtpd/smtpd.8/) -# Options from here on. Some of these are preset by platform above -AC_ARG_WITH([mantype], - [ --with-mantype=man|cat|doc Set man page type], - [ - case "$withval" in - man|cat|doc) - MANTYPE=$withval - ;; - *) - AC_MSG_ERROR([invalid man type: $withval]) - ;; - esac - ] -) -if test -z "$MANTYPE"; then - TestPath="/usr/bin${PATH_SEPARATOR}/usr/ucb" - AC_PATH_PROGS([NROFF], [nroff awf], [/bin/false], [$TestPath]) - if ${NROFF} -mdoc ${srcdir}/smtpd/smtpd.8 >/dev/null 2>&1; then - MANTYPE=doc - elif ${NROFF} -man ${srcdir}/smtpd/smtpd.8 >/dev/null 2>&1; then - MANTYPE=man - else - MANTYPE=cat - fi -fi -AC_SUBST([MANTYPE]) -if test "$MANTYPE" = "doc"; then - mansubdir=man; -else - mansubdir=$MANTYPE; -fi -AC_SUBST([mansubdir]) -#l4207 - - -#l4432 (customized s/pid/sock/) -# Whether to enable BSD auth support -BSD_AUTH_MSG=no -AC_ARG_WITH([auth-bsdauth], - [ --with-auth-bsdauth Enable bsd_auth(3) authentication support], - [ - if test "x$withval" != "xno"; then - AC_DEFINE([BSD_AUTH], [1], - [Define if you have BSD auth support]) - BSD_AUTH_MSG=yes - fi - ] -) - - -#l2757 -# Check for PAM libs -PAM_MSG="no" -USE_PAM_SERVICE=smtpd -AC_ARG_WITH([auth-pam], - [ --with-auth-pam=SERVICE Enable PAM authentication support (default=smtpd)], - [ - if test "x$withval" != "xno"; then - if test -n "$withval" -a "x${withval}" != "xyes"; then - USE_PAM_SERVICE=$withval - fi - - if test "x$ac_cv_header_security_pam_appl_h" != "xyes" -a \ - test "x$ac_cv_header_pam_pam_appl_h" != "xyes"; then - AC_MSG_ERROR([PAM headers not found]) - fi - - saved_LIBS="$LIBS" - AC_CHECK_LIB([dl], [dlopen], , ) - AC_CHECK_LIB([pam], [pam_set_item], , [AC_MSG_ERROR([*** libpam missing])]) - AC_CHECK_FUNCS([pam_getenvlist]) - AC_CHECK_FUNCS([pam_putenv]) - LIBS="$saved_LIBS" - - PAM_MSG="yes" - - SMTPDLIBS="$SMTPDLIBS -lpam" - AC_DEFINE([USE_PAM], [1], - [Define if you want to enable PAM support]) - - if test "x$ac_cv_lib_dl_dlopen" = "xyes"; then - case "$LIBS" in - *-ldl*) - # libdl already in LIBS - ;; - *) - SMTPDLIBS="$SMTPDLIBS -ldl" - ;; - esac - fi - fi - ] -) -AC_DEFINE_UNQUOTED([USE_PAM_SERVICE], ["$USE_PAM_SERVICE"], [pam service]) -AC_SUBST([USE_PAM_SERVICE]) - - -# Check for older PAM -if test "x$PAM_MSG" = "xyes"; then - # Check PAM strerror arguments (old PAM) - AC_MSG_CHECKING([whether pam_strerror takes only one argument]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -#if defined(HAVE_SECURITY_PAM_APPL_H) -#include -#elif defined (HAVE_PAM_PAM_APPL_H) -#include -#endif - ]], [[ -(void)pam_strerror((pam_handle_t *)NULL, -1); - ]])], [AC_MSG_RESULT([no])], [ - AC_DEFINE([HAVE_OLD_PAM], [1], - [Define if you have an old version of PAM - which takes only one argument to pam_strerror]) - AC_MSG_RESULT([yes]) - PAM_MSG="yes (old library)" - - ]) -fi -#l2816 - - -##gilles - -SMTPD_USER=_smtpd -AC_ARG_WITH([user-smtpd], - [ --with-user-smtpd=user Specify non-privileged user for smtpd (default=_smtpd)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - SMTPD_USER=$withval - fi - ] -) -AC_DEFINE_UNQUOTED([SMTPD_USER], ["$SMTPD_USER"], - [non-privileged user for privilege separation]) -AC_SUBST([SMTPD_USER]) - -SMTPD_QUEUE_USER=_smtpq -AC_ARG_WITH([user-queue], - [ --with-user-queue=user Specify non-privileged user for queue process (default=_smtpq)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - SMTPD_QUEUE_USER=$withval - fi - ] -) -AC_DEFINE_UNQUOTED([SMTPD_QUEUE_USER], ["$SMTPD_QUEUE_USER"], - [non-privileged user for queue process]) -AC_SUBST([SMTPD_QUEUE_USER]) - -SMTPD_QUEUE_GROUP=_smtpq -AC_ARG_WITH([group-queue], - [ --with-group-queue=group Specify non-privileged group for offline queue (default=_smtpq)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - SMTPD_QUEUE_GROUP=$withval - fi - ] -) -AC_DEFINE_UNQUOTED([SMTPD_QUEUE_GROUP], ["$SMTPD_QUEUE_GROUP"], - [non-privileged group for queue process]) -AC_SUBST([SMTPD_QUEUE_GROUP]) - -# Where to place spooler -spooldir=/var/spool/smtpd -AC_ARG_WITH([path-queue], - [ --with-path-queue=PATH Specify path to queue directory (default=/var/spool/smtpd)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - spooldir=$withval - if test ! -d $spooldir; then - AC_MSG_WARN([** no $spooldir directory on this system **]) - fi - fi - ] -) - -AC_DEFINE_UNQUOTED([PATH_SPOOL], ["$spooldir"], - [Specify location of spooler]) -AC_SUBST([spooldir]) - - -PRIVSEP_PATH=/var/empty -AC_ARG_WITH([path-empty], - [ --with-path-empty=PATH Specify path to empty directory (default=/var/empty)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - PRIVSEP_PATH=$withval - fi - ] -) -AC_SUBST([PRIVSEP_PATH]) -#l4022 - -#l4066 -dnl # --with-maildir=/path/to/mail gets top priority. -dnl # if maildir is set in the platform case statement above we use that. -dnl # Otherwise we run a program to get the dir from system headers. -dnl # We first look for _PATH_MAILDIR then MAILDIR then _PATH_MAIL -dnl # If we find _PATH_MAILDIR we do nothing because that is what -dnl # session.c expects anyway. Otherwise we set to the value found -dnl # stripping any trailing slash. If for some strage reason our program -dnl # does not find what it needs, we default to /var/spool/mail. -# Check for mail directory -AC_ARG_WITH([path-mbox], - [ --with-path-mbox=PATH Specify path to mbox directory (default=/var/spool/mail)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["$withval"], - [Set this to your mail directory if you do not have _PATH_MAILDIR]) - fi - ],[ - if test -n "$maildir"; then - AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["$maildir"]) - else - AC_MSG_CHECKING([system mail directory]) - AC_RUN_IFELSE( - [AC_LANG_PROGRAM([[ -#include -#include -#include -#ifdef HAVE_PATHS_H -#include -#endif -#ifdef HAVE_MAILLOCK_H -#include -#endif -#define DATA "conftest.maildir" - ]], [[ - FILE *fd; - int rc; - - fd = fopen(DATA,"w"); - if(fd == NULL) - exit(1); - -#if defined (_PATH_MAILDIR) - if ((rc = fprintf(fd ,"_PATH_MAILDIR:%s\n", _PATH_MAILDIR)) <0) - exit(1); -#elif defined (MAILDIR) - if ((rc = fprintf(fd ,"MAILDIR:%s\n", MAILDIR)) <0) - exit(1); -#elif defined (_PATH_MAIL) - if ((rc = fprintf(fd ,"_PATH_MAIL:%s\n", _PATH_MAIL)) <0) - exit(1); -#else - exit (2); -#endif - - exit(0); - ]])], - [ - maildir_what=`awk -F: '{print $1}' conftest.maildir` - maildir=`awk -F: '{print $2}' conftest.maildir \ - | sed 's|/$||'` - AC_MSG_RESULT([$maildir from $maildir_what]) - if test "x$maildir_what" != "x_PATH_MAILDIR"; then - AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["$maildir"]) - fi - ], - [ - if test "X$ac_status" = "X2"; then -# our test program didn't find it. Default to /var/spool/mail - AC_MSG_RESULT([/var/spool/mail]) - AC_DEFINE_UNQUOTED([MAIL_DIRECTORY], ["/var/spool/mail"]) - else - AC_MSG_RESULT([*** not found ***]) - fi - ], - [ - AC_MSG_WARN([cross compiling: use --with-maildir=/path/to/mail]) - ] - ) - fi - ] -) # maildir -#l4146 - -# Where to place smtpd.sock -sockdir=/var/run -# make sure the directory exists -if test ! -d $sockdir; then - sockdir=`eval echo ${sysconfdir}` - case $sockdir in - NONE/*) sockdir=`echo $sockdir | sed "s~NONE~$ac_default_prefix~"` ;; - esac -fi - -AC_ARG_WITH([path-socket], - [ --with-path-socket=PATH Specify path to smtpd.sock directory (default=/var/run)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - sockdir=$withval - if test ! -d $sockdir; then - AC_MSG_WARN([** no $sockdir directory on this system **]) - fi - fi - ] -) - -AC_DEFINE_UNQUOTED([SMTPD_SOCKDIR], ["$sockdir"], - [Specify location of smtpd.sock]) -AC_SUBST([sockdir]) -#l4470 - -# Where to place smtpd.pid -piddir=/var/run -AC_MSG_CHECKING([system pid directory]) -AC_RUN_IFELSE( - [ - AC_LANG_PROGRAM([[ -#include -#include -#ifdef HAVE_PATHS_H -#include -#endif -#define DATA "conftest.piddir" - ]], - [[ -#ifdef _PATH_VARRUN -FILE *fd; -int rc; - -if ((fd = fopen(DATA,"w")) == NULL) { exit(1); } -if ((rc = fprintf(fd ,"%s\n", _PATH_VARRUN)) < 0) { exit(2); } -exit(0); -#else -exit(-1); -#endif - ]]) - ], [ - piddir=`cat conftest.piddir` - AC_MSG_RESULT([$piddir from paths.h]) - ], - [ - AC_MSG_RESULT([$piddir from default value]) - ], - [ - AC_MSG_RESULT([$piddir from default value]) - ] -) - -AC_ARG_WITH([path-pidfile], - [ --with-path-pidfile=PATH Specify path to smtpd.pid directory (default=/var/run)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - piddir=$withval - fi - ] -) - -AC_DEFINE_UNQUOTED([SMTPD_PIDDIR], ["$piddir"], [Specify location of smtpd.pid]) -AC_SUBST([piddir]) - -CA_FILE=/etc/ssl/cert.pem -AC_ARG_WITH([path-CAfile], - [ --with-path-CAfile=FILE Specify path to CA certificate (default=/etc/ssl/cert.pem)], - [ - if test -n "$withval" -a "$withval" != "no" -a "${withval}" != "yes"; then - CA_FILE=$withval - fi - ] -) -AC_SUBST([CA_FILE]) - - - - - - -# compute LLONG_MIN and LLONG_MAX if we don't know them. -if test -z "$have_llong_max"; then - AC_MSG_CHECKING([for max value of long long]) - AC_RUN_IFELSE( - [AC_LANG_PROGRAM([[ -#include -#include -/* Why is this so damn hard? */ -#ifdef __GNUC__ -# undef __GNUC__ -#endif -#define __USE_ISOC99 -#include -#define DATA "conftest.llminmax" -#define my_abs(a) ((a) < 0 ? ((a) * -1) : (a)) - -/* - * printf in libc on some platforms (eg old Tru64) does not understand %lld so - * we do this the hard way. - */ -static int -fprint_ll(FILE *f, long long n) -{ - unsigned int i; - int l[sizeof(long long) * 8]; - - if (n < 0) - if (fprintf(f, "-") < 0) - return -1; - for (i = 0; n != 0; i++) { - l[i] = my_abs(n % 10); - n /= 10; - } - do { - if (fprintf(f, "%d", l[--i]) < 0) - return -1; - } while (i != 0); - if (fprintf(f, " ") < 0) - return -1; - return 0; -} - ]], [[ - FILE *f; - long long i, llmin, llmax = 0; - - if((f = fopen(DATA,"w")) == NULL) - exit(1); - -#if defined(LLONG_MIN) && defined(LLONG_MAX) - fprintf(stderr, "Using system header for LLONG_MIN and LLONG_MAX\n"); - llmin = LLONG_MIN; - llmax = LLONG_MAX; -#else - fprintf(stderr, "Calculating LLONG_MIN and LLONG_MAX\n"); - /* This will work on one's complement and two's complement */ - for (i = 1; i > llmax; i <<= 1, i++) - llmax = i; - llmin = llmax + 1LL; /* wrap */ -#endif - - /* Sanity check */ - if (llmin + 1 < llmin || llmin - 1 < llmin || llmax + 1 > llmax - || llmax - 1 > llmax || llmin == llmax || llmin == 0 - || llmax == 0 || llmax < LONG_MAX || llmin > LONG_MIN) { - fprintf(f, "unknown unknown\n"); - exit(2); - } - - if (fprint_ll(f, llmin) < 0) - exit(3); - if (fprint_ll(f, llmax) < 0) - exit(4); - if (fclose(f) < 0) - exit(5); - exit(0); - ]])], - [ - llong_min=`$AWK '{print $1}' conftest.llminmax` - llong_max=`$AWK '{print $2}' conftest.llminmax` - - AC_MSG_RESULT([$llong_max]) - AC_DEFINE_UNQUOTED([LLONG_MAX], [${llong_max}LL], - [max value of long long calculated by configure]) - AC_MSG_CHECKING([for min value of long long]) - AC_MSG_RESULT([$llong_min]) - AC_DEFINE_UNQUOTED([LLONG_MIN], [${llong_min}LL], - [min value of long long calculated by configure]) - ], - [ - AC_MSG_RESULT([not found]) - ], - [ - AC_MSG_WARN([cross compiling: not checking]) - ] - ) -fi - - - - - -#l3561 - - -dnl make sure we're using the real structure members and not defines -AC_CACHE_CHECK([for msg_accrights field in struct msghdr], - ac_cv_have_accrights_in_msghdr, [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -#include -#include -#include - ]], [[ -#ifdef msg_accrights -#error "msg_accrights is a macro" -exit(1); -#endif -struct msghdr m; -m.msg_accrights = 0; -exit(0); - ]])], - [ ac_cv_have_accrights_in_msghdr="yes" ], - [ ac_cv_have_accrights_in_msghdr="no" ] - ) -]) -if test "x$ac_cv_have_accrights_in_msghdr" = "xyes"; then - AC_DEFINE([HAVE_ACCRIGHTS_IN_MSGHDR], [1], - [Define if your system uses access rights style - file descriptor passing]) -fi - - -AC_CACHE_CHECK([for msg_control field in struct msghdr], - ac_cv_have_control_in_msghdr, [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -#include -#include -#include - ]], [[ -#ifdef msg_control -#error "msg_control is a macro" -exit(1); -#endif -struct msghdr m; -m.msg_control = 0; -exit(0); - ]])], - [ ac_cv_have_control_in_msghdr="yes" ], - [ ac_cv_have_control_in_msghdr="no" ] - ) -]) -if test "x$ac_cv_have_control_in_msghdr" = "xyes"; then - AC_DEFINE([HAVE_CONTROL_IN_MSGHDR], [1], - [Define if your system uses ancillary data style - file descriptor passing]) -fi - -AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], - [[ extern char *__progname; printf("%s", __progname); ]])], - [ ac_cv_libc_defines___progname="yes" ], - [ ac_cv_libc_defines___progname="no" - ]) -]) -if test "x$ac_cv_libc_defines___progname" = "xyes"; then - AC_DEFINE([HAVE___PROGNAME], [1], [Define if libc defines __progname]) -fi - -AC_CACHE_CHECK([whether $CC implements __FUNCTION__], ac_cv_cc_implements___FUNCTION__, [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], - [[ printf("%s", __FUNCTION__); ]])], - [ ac_cv_cc_implements___FUNCTION__="yes" ], - [ ac_cv_cc_implements___FUNCTION__="no" - ]) -]) -if test "x$ac_cv_cc_implements___FUNCTION__" = "xyes"; then - AC_DEFINE([HAVE___FUNCTION__], [1], - [Define if compiler implements __FUNCTION__]) -fi - -AC_CACHE_CHECK([whether $CC implements __func__], ac_cv_cc_implements___func__, [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], - [[ printf("%s", __func__); ]])], - [ ac_cv_cc_implements___func__="yes" ], - [ ac_cv_cc_implements___func__="no" - ]) -]) -if test "x$ac_cv_cc_implements___func__" = "xyes"; then - AC_DEFINE([HAVE___func__], [1], [Define if compiler implements __func__]) -fi - -AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#include -va_list x,y; - ]], [[ va_copy(x,y); ]])], - [ ac_cv_have_va_copy="yes" ], - [ ac_cv_have_va_copy="no" - ]) -]) -if test "x$ac_cv_have_va_copy" = "xyes"; then - AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists]) -fi - -AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#include -va_list x,y; - ]], [[ __va_copy(x,y); ]])], - [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no" - ]) -]) -if test "x$ac_cv_have___va_copy" = "xyes"; then - AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists]) -fi - -AC_CACHE_CHECK([whether getopt has optreset support], - ac_cv_have_getopt_optreset, [ - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], - [[ extern int optreset; optreset = 0; ]])], - [ ac_cv_have_getopt_optreset="yes" ], - [ ac_cv_have_getopt_optreset="no" - ]) -]) -if test "x$ac_cv_have_getopt_optreset" = "xyes"; then - AC_DEFINE([HAVE_GETOPT_OPTRESET], [1], - [Define if your getopt(3) defines and uses optreset]) -fi -#l3765 - - - - -#l4045 -STRIP_OPT=-s -AC_ARG_ENABLE([strip], - [ --disable-strip Disable calling strip(1) on install], - [ - if test "x$enableval" = "xno"; then - STRIP_OPT= - fi - ] -) -AC_SUBST([STRIP_OPT]) -#l4054 - - - -case "$host" in -*-*-openbsd*) - pkglibexecdir="$libexecdir/smtpd" - ;; -*) - pkglibexecdir="$libexecdir/opensmtpd" - ;; -esac -AC_SUBST([pkglibexecdir]) - - - - - - - - - -#l4742 -dnl Adding -Werror to CFLAGS early prevents configure tests from running. -dnl Add now. -CFLAGS="$CFLAGS $werror_flags" - -AC_SUBST([TEST_MALLOC_OPTIONS], [$TEST_MALLOC_OPTIONS]) - - -AC_EXEEXT -#l4757 - - -# Search for fts -AC_ARG_WITH([libfts], - [ --with-libfts=PATH Specify path to libfts installation (default: none, part of libc)], - [ if test "x$withval" = "xno"; then - AC_MSG_ERROR([*** fts is required ***]) - elif test "x$withval" != "xyes"; then - if test -d "$withval/lib"; then - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" - else - LDFLAGS="-L${withval}/lib ${LDFLAGS}" - fi - else - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" - else - LDFLAGS="-L${withval} ${LDFLAGS}" - fi - fi - if test -d "$withval/include"; then - CPPFLAGS="-I${withval}/include ${CPPFLAGS}" - else - CPPFLAGS="-I${withval} ${CPPFLAGS}" - fi - LIBS="-lfts $LIBS" - fi - ] -) - - - -##chl (based on OpenSSL checks, see above) -# Search for libevent -saved_CPPFLAGS="$CPPFLAGS" -saved_LDFLAGS="$LDFLAGS" -AC_ARG_WITH([libevent], - [ --with-libevent=PATH Specify path to libevent installation ], - [ - if test "x$withval" != "xno"; then - case "$withval" in - # Relative paths - ./*|../*) withval="`pwd`/$withval" - esac - if test -d "$withval/lib"; then - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" - else - LDFLAGS="-L${withval}/lib ${LDFLAGS}" - fi - elif test -d "$withval/lib64"; then - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval}/lib64 -R${withval}/lib64 ${LDFLAGS}" - else - LDFLAGS="-L${withval}/lib64 ${LDFLAGS}" - fi - else - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" - else - LDFLAGS="-L${withval} ${LDFLAGS}" - fi - fi - if test -d "$withval/include"; then - CPPFLAGS="-I${withval}/include ${CPPFLAGS}" - else - CPPFLAGS="-I${withval} ${CPPFLAGS}" - fi - need_libevent_autodetect=no - fi - ] -) - -if test "x${need_libevent_autodetect}" != "xno"; then - for path in /usr/local /usr; do - if test -f "${path}/include/event.h"; then - CPPFLAGS="-I${path}/include ${CPPFLAGS}" - LDFLAGS="-L${path}/lib ${LDFLAGS}" - fi - done -fi - -AC_CHECK_HEADER([event.h], ,[AC_MSG_ERROR([*** event.h missing - please install libevent ***])], -[#include ]) -LIBS="-levent $LIBS" -AC_MSG_CHECKING([if programs using libevent functions will link]) -AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[ - #include - ]], [[ - event_base_new(); - ]])], - [ - AC_MSG_RESULT([yes]) - ], - [ - AC_MSG_RESULT([no]) - ] -) - - -#l2174 (customized, bu adding -lssl to LIBS) -# Search for OpenSSL -saved_CPPFLAGS="$CPPFLAGS" -saved_LDFLAGS="$LDFLAGS" -AC_ARG_WITH([libssl], - [ --with-libssl=PATH Specify path to libssl installation ], - [ - if test "x$withval" != "xno"; then - case "$withval" in - # Relative paths - ./*|../*) withval="`pwd`/$withval" - esac - if test -d "$withval/lib"; then - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" - else - LDFLAGS="-L${withval}/lib ${LDFLAGS}" - fi - elif test -d "$withval/lib64"; then - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval}/lib64 -R${withval}/lib64 ${LDFLAGS}" - else - LDFLAGS="-L${withval}/lib64 ${LDFLAGS}" - fi - else - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" - else - LDFLAGS="-L${withval} ${LDFLAGS}" - fi - fi - if test -d "$withval/include"; then - CPPFLAGS="-I${withval}/include ${CPPFLAGS}" - else - CPPFLAGS="-I${withval} ${CPPFLAGS}" - fi - fi - ] -) -## XXX chl -lssl manually added -LIBS="-lcrypto -lssl $LIBS" -AC_TRY_LINK_FUNC([RAND_add], [AC_DEFINE([HAVE_OPENSSL], [1], - [Define if your ssl headers are included - with #include ])], - [ - dnl Check default openssl install dir - if test -n "${need_dash_r}"; then - LDFLAGS="-L/usr/local/ssl/lib -R/usr/local/ssl/lib ${saved_LDFLAGS}" - else - LDFLAGS="-L/usr/local/ssl/lib ${saved_LDFLAGS}" - fi - CPPFLAGS="-I/usr/local/ssl/include ${saved_CPPFLAGS}" - AC_CHECK_HEADER([openssl/opensslv.h], , - [AC_MSG_ERROR([*** LibreSSL headers missing - please install first or check config.log ***])]) - AC_TRY_LINK_FUNC([RAND_add], [AC_DEFINE([HAVE_OPENSSL])], - [ - AC_MSG_ERROR([*** Can't find recent LibreSSL libcrypto (see config.log for details) ***]) - ] - ) - ] -) - - -LIBS="-lcrypto -lssl $LIBS" -AC_MSG_CHECKING([whether SSL_CTX_use_certificate_chain_mem is available]) -AC_TRY_LINK_FUNC([SSL_CTX_use_certificate_chain_mem], - [ - AC_DEFINE([HAVE_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM], [1], - [Define if SSL_CTX_use_certificate_chain_mem exists in libssl]) - AC_MSG_RESULT([yes]) - ], - [ AC_MSG_RESULT([no])] -) - -LIBS="-lcrypto -lssl $LIBS" -AC_MSG_CHECKING([whether ECDSA is available]) -AC_TRY_LINK_FUNC([ENGINE_get_ECDSA], - [ - AC_DEFINE([SUPPORT_ECDSA], [1], - [Define if ECDSA is supported]) - AC_MSG_RESULT([yes]) - ], - [ AC_MSG_RESULT([no])] -) - -# Sanity check OpenSSL headers -AC_MSG_CHECKING([whether LibreSSL's headers match the library]) -AC_RUN_IFELSE( - [AC_LANG_PROGRAM([[ -#include -#include -#include -#include - ]], [[ - exit(SSLeay() == OPENSSL_VERSION_NUMBER ? 0 : 1); - ]])], - [ - AC_MSG_RESULT([yes]) - ], - [ - AC_MSG_RESULT([no]) - AC_MSG_ERROR([Your LibreSSL headers do not match your library.]) - ], - [ - AC_MSG_WARN([cross compiling: not checking]) - ] -) - -AC_MSG_CHECKING([if programs using LibreSSL functions will link]) -AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[ #include ]], - [[ SSLeay_add_all_algorithms(); ]])], - [ - AC_MSG_RESULT([yes]) - ], - [ - AC_MSG_RESULT([no]) - saved_LIBS="$LIBS" - LIBS="$LIBS -ldl" - AC_MSG_CHECKING([if programs using LibreSSL need -ldl]) - AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[ #include ]], - [[ SSLeay_add_all_algorithms(); ]])], - [ - AC_MSG_RESULT([yes]) - ], - [ - AC_MSG_RESULT([no]) - LIBS="$saved_LIBS" - ] - ) - ] -) - -AC_CHECK_DECL([LIBRESSL_VERSION_NUMBER], , , [#include ]) - -#l2371 - - -dnl zlib is required -AC_ARG_WITH([libz], - [ --with-libz=PATH Specify path to libz installation], - [ if test "x$withval" = "xno"; then - AC_MSG_ERROR([*** zlib is required ***]) - elif test "x$withval" != "xyes"; then - if test -d "$withval/lib"; then - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}" - else - LDFLAGS="-L${withval}/lib ${LDFLAGS}" - fi - else - if test -n "${need_dash_r}"; then - LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}" - else - LDFLAGS="-L${withval} ${LDFLAGS}" - fi - fi - if test -d "$withval/include"; then - CPPFLAGS="-I${withval}/include ${CPPFLAGS}" - else - CPPFLAGS="-I${withval} ${CPPFLAGS}" - fi - fi ] -) - -AC_CHECK_HEADER([zlib.h], ,[AC_MSG_ERROR([*** zlib.h missing - please install first or check config.log ***])]) -AC_CHECK_LIB([z], [deflate], , - [ - saved_CPPFLAGS="$CPPFLAGS" - saved_LDFLAGS="$LDFLAGS" - save_LIBS="$LIBS" - dnl Check default zlib install dir - if test -n "${need_dash_r}"; then - LDFLAGS="-L/usr/local/lib -R/usr/local/lib ${saved_LDFLAGS}" - else - LDFLAGS="-L/usr/local/lib ${saved_LDFLAGS}" - fi - CPPFLAGS="-I/usr/local/include ${saved_CPPFLAGS}" - LIBS="$LIBS -lz" - AC_TRY_LINK_FUNC([deflate], [AC_DEFINE([HAVE_LIBZ])], - [ - AC_MSG_ERROR([*** zlib missing - please install first or check config.log ***]) - ] - ) - ] -) - - - - - -AC_ARG_WITH([table-db], - [ --with-table-db Enable building of table-db backend (default=no)], - [ - if test "x$withval" = "xyes"; then - use_db_api=1 - else - use_db_api=0 - fi - ] -) - -if test "x$use_db_api" = "x1"; then -# Search for libdb -AC_CHECK_HEADER(db_185.h, [AC_DEFINE([HAVE_DB_185_H], [], [if you have the header file]) ] , [ -AC_CHECK_HEADER(db.h, [AC_DEFINE([HAVE_DB_H], [], [if you have the header file]) ] , [ -AC_CHECK_HEADER(db1/db.h, [AC_DEFINE([HAVE_DB1_DB_H], [], [if you have the header file]) ] , [ - AC_MSG_ERROR([*** Can't find Berkeley DB headers (see config.log for details) ***]) -])])]) -fi - -save_LIBS="$LIBS" - -if test "x$use_db_api" = "x1"; then -DB_LIB= - -for libdb in db db1 c; do - AC_CHECK_LIB($libdb, dbopen, [ DB_LIB="$libdb"; break; ], - AC_CHECK_LIB($libdb, __db185_open, [ DB_LIB="$libdb"; break; ])) -done - -if test -z "$DB_LIB"; then - AC_MSG_ERROR([Berkeley DB not found or not built with --enable-185]) -fi - -DB_LIB="-l$DB_LIB" -AC_SUBST([DB_LIB]) -fi - -LIBS="$save_LIBS" - - -AM_CONDITIONAL([HAVE_DB_API], [test "x$use_db_api" = "x1"]) -AM_COND_IF([HAVE_DB_API], [AC_DEFINE([HAVE_DB_API], [1], [Define to 1 if HAVE_DB_API])]) - - - -if test "$need_libasr" = "no" -a "x$ac_cv_search_event_asr_run" = "xno"; then - LIBS="$LIBS -lasr" -fi - - -LIBS="$LIBS ${SMTPDLIBS}" -##end of chl - - -## -#AM_CONDITIONAL([NEED_BASENAME], [test "x$ac_cv_have_basename" != "xyes"]) -AM_CONDITIONAL([NEED_BASE64], [test "x$ac_cv_search_b64_ntop" = "xno" -a "x$ac_cv_search___b64_ntop" = "xno" ]) -AM_CONDITIONAL([NEED_BASENAME], [test "x$ac_cv_search_basename" = "xno"]) -AM_CONDITIONAL([NEED_CLOCK_GETTIME], [test "x$ac_cv_search_clock_gettime" = "xno"]) -AM_CONDITIONAL([NEED_CLOSEFROM], [test "x$ac_cv_search_closefrom" = "xno"]) -AM_CONDITIONAL([NEED_DAEMON], [test "x$ac_cv_search_daemon" = "xno"]) -AM_CONDITIONAL([NEED_DIRNAME], [test "x$ac_cv_search_dirname" = "xno"]) -AM_CONDITIONAL([NEED_EVENT_ASR_RUN], [test "x$ac_cv_search_event_asr_run" = "xno"]) -AM_CONDITIONAL([NEED_FMT_SCALED], [test "x$ac_cv_search_fmt_scaled" = "xno"]) -AM_CONDITIONAL([NEED_FPARSELN], [test "x$ac_cv_search_fparseln" = "xno"]) -AM_CONDITIONAL([NEED_IMSG], [test "x$ac_cv_search_imsg_init" = "xno"]) -AM_CONDITIONAL([NEED_INET_NET_PTON], [test "x$ac_cv_search_inet_net_pton" = "xno"]) - -AM_CONDITIONAL([NEED_ERR], [test "x$ac_cv_func_err" != "xyes"]) -AM_CONDITIONAL([NEED_ERRC], [test "x$ac_cv_func_errc" != "xyes"]) -AM_CONDITIONAL([NEED_CRYPT_CHECKPASS], [test "x$ac_cv_func_crypt_checkpass" != "xyes"]) -AM_CONDITIONAL([NEED_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" != "xyes"]) -AM_CONDITIONAL([NEED_FGETLN], [test "x$ac_cv_func_fgetln" != "xyes"]) -AM_CONDITIONAL([NEED_FREEZERO], [test "x$ac_cv_func_freezero" != "xyes"]) -AM_CONDITIONAL([NEED_GETOPT], [test "x$ac_cv_func_getopt" != "xyes"]) -AM_CONDITIONAL([NEED_GETPEEREID], [test "x$ac_cv_func_getpeereid" != "xyes"]) -AM_CONDITIONAL([NEED_NANOSLEEP], [test "x$ac_cv_func_nanosleep" != "xyes"]) -AM_CONDITIONAL([NEED_PIDFILE], [test "x$ac_cv_func_pidfile" != "xyes"]) -AM_CONDITIONAL([NEED_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" != "xyes"]) -AM_CONDITIONAL([NEED_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" != "xyes"]) -AM_CONDITIONAL([NEED_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" != "xyes"]) -AM_CONDITIONAL([NEED_SETEGID], [test "x$ac_cv_func_setegid" != "xyes"]) -AM_CONDITIONAL([NEED_SETEUID], [test "x$ac_cv_func_seteuid" != "xyes"]) -AM_CONDITIONAL([NEED_SETRESGID], [test "x$ac_cv_func_setresgid" != "xyes"]) -AM_CONDITIONAL([NEED_SETRESUID], [test "x$ac_cv_func_setresuid" != "xyes"]) -AM_CONDITIONAL([NEED_SIGNAL], [test "x$ac_cv_func_signal" != "xyes"]) -AM_CONDITIONAL([NEED_STRERROR], [test "x$ac_cv_func_strerror" != "xyes"]) -AM_CONDITIONAL([NEED_STRLCAT], [test "x$ac_cv_func_strlcat" != "xyes"]) -AM_CONDITIONAL([NEED_STRLCPY], [test "x$ac_cv_func_strlcpy" != "xyes"]) -AM_CONDITIONAL([NEED_STRMODE], [test "x$ac_cv_func_strmode" != "xyes"]) -AM_CONDITIONAL([NEED_STRSEP], [test "x$ac_cv_func_strsep" != "xyes"]) -AM_CONDITIONAL([NEED_STRTONUM], [test "x$ac_cv_func_strtonum" != "xyes"]) -AM_CONDITIONAL([NEED_STRNDUP], [test "x$ac_cv_func_strndup" != "xyes"]) -AM_CONDITIONAL([NEED_STRNLEN], [test "x$ac_cv_func_strnlen" != "xyes"]) -AM_CONDITIONAL([NEED_WAITPID], [test "x$ac_cv_func_waitpid" != "xyes"]) -AM_CONDITIONAL([NEED_VIS], [test "x$ac_cv_func_strnvis" != "xyes" -o "x$BROKEN_STRNVIS" = "x1"]) -AM_CONDITIONAL([NEED_USLEEP], [test "x$ac_cv_func_usleep" != "xyes"]) - -AM_CONDITIONAL([NEED_RES_HNOK], [test "x$ac_cv_search_res_hnok" = "xno" -a x"$ac_cv_func_res_hnok" != "xyes" -a x"$need_libasr" = x"yes"]) -AM_CONDITIONAL([NEED_RES_RANDOMID], [test "x$ac_cv_search_res_randomid" = "xno" -a x"$ac_cv_func_res_randomid" != "xyes" -a x"$need_libasr" = x"yes"]) - -AM_CONDITIONAL([NEED_ARC4RANDOM], [test "x$ac_cv_func_arc4random" != "xyes" -a "x$ac_cv_have_decl_LIBRESSL_VERSION_NUMBER" != "xyes"]) -AM_CONDITIONAL([NEED_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM], [test "x$ac_cv_have_decl_LIBRESSL_VERSION_NUMBER" != "xyes"]) - -AM_CONDITIONAL([NEED_PROGNAME], [test "x$ac_cv_libc_defines___progname" != "xyes"]) -## - - -AC_CONFIG_FILES([Makefile - openbsd-compat/Makefile - mk/Makefile - mk/mail/Makefile - mk/mail/mail.lmtp/Makefile - mk/mail/mail.maildir/Makefile - mk/mail/mail.mboxfile/Makefile - mk/mail/mail.mda/Makefile - mk/smtpd/Makefile - mk/smtpctl/Makefile - mk/smtp/Makefile - contrib/Makefile - contrib/libexec/Makefile - contrib/libexec/mail.local/Makefile - contrib/libexec/lockspool/Makefile - contrib/libexec/encrypt/Makefile - ]) - -#l4761 -AC_OUTPUT diff --git a/foobar/portable/contrib/Makefile.am b/foobar/portable/contrib/Makefile.am deleted file mode 100644 index 37a8e73a..00000000 --- a/foobar/portable/contrib/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = libexec diff --git a/foobar/portable/contrib/libexec/Makefile.am b/foobar/portable/contrib/libexec/Makefile.am deleted file mode 100644 index 0e3a271f..00000000 --- a/foobar/portable/contrib/libexec/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = mail.local lockspool encrypt diff --git a/foobar/portable/contrib/libexec/encrypt/Makefile.am b/foobar/portable/contrib/libexec/encrypt/Makefile.am deleted file mode 100644 index 6ad7b82d..00000000 --- a/foobar/portable/contrib/libexec/encrypt/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -pkglibexec_PROGRAMS = encrypt - -encrypt_SOURCES = encrypt.c -encrypt_SOURCES += $(top_srcdir)/smtpd/log.c - -AM_CPPFLAGS = -I$(top_srcdir)/openbsd-compat - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/contrib/libexec/encrypt/encrypt.c b/foobar/portable/contrib/libexec/encrypt/encrypt.c deleted file mode 100644 index 80275921..00000000 --- a/foobar/portable/contrib/libexec/encrypt/encrypt.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2013 Sunil Nimmagadda - * Copyright (c) 2013 Gilles Chehade - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#ifdef HAVE_CRYPT_H -#include /* needed for crypt() */ -#endif -#include -#include -#include -#include - -#define PASSWORD_LEN 128 -#define SALT_LEN 16 - -static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static void to64(char *, long int, int); -static void print_passwd(const char *); - -int -main(int argc, char *argv[]) -{ - char *line; - size_t linesz; - ssize_t linelen; - - if (argc > 2) { - fprintf(stderr, "usage: encrypt \n"); - return (1); - } - - if (argc == 2) { - print_passwd(argv[1]); - return (0); - } - - line = NULL; - linesz = 0; - while ((linelen = getline(&line, &linesz, stdin)) != -1) { - if (line[linelen - 1] == '\n') - line[linelen - 1] = '\0'; - print_passwd(line); - } - free(line); - - return (0); -} - -void -print_passwd(const char *string) -{ - const char *ids[] = { "2a", "6", "5", "3", "2", "1", NULL }; - const char *id; - char salt[SALT_LEN+1]; - char buffer[PASSWORD_LEN]; - int n; - const char *p; - - for (n = 0; n < SALT_LEN; ++n) - to64(&salt[n], arc4random_uniform(0xff), 1); - salt[SALT_LEN] = '\0'; - - for (n = 0; ids[n]; n++) { - id = ids[n]; - (void)snprintf(buffer, sizeof buffer, "$%s$%s$", id, salt); - if ((p = crypt(string, buffer)) == NULL) - continue; - if (strncmp(p, buffer, strlen(buffer)) != 0) - continue; - printf("%s\n", p); - return; - } - - salt[2] = 0; - printf("%s\n", crypt(string, salt)); -} - -void -to64(char *s, long int v, int n) -{ - while (--n >= 0) { - *s++ = itoa64[v & 0x3f]; - v >>= 6; - } -} diff --git a/foobar/portable/contrib/libexec/lockspool/Makefile.am b/foobar/portable/contrib/libexec/lockspool/Makefile.am deleted file mode 100644 index dacf5386..00000000 --- a/foobar/portable/contrib/libexec/lockspool/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -pkglibexec_PROGRAMS = lockspool - -lockspool_SOURCES = lockspool.c -lockspool_SOURCES += locking.c -lockspool_SOURCES += $(top_srcdir)/smtpd/log.c - -EXTRA_DIST = mail.local.h pathnames.h - -AM_CPPFLAGS = -I$(top_srcdir)/openbsd-compat -I$(top_srcdir)/mail.local - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - -install-exec-hook: $(CONFIGFILES) $(MANPAGES) - chown root $(DESTDIR)$(pkglibexecdir)/lockspool || true - chmod 4555 $(DESTDIR)$(pkglibexecdir)/lockspool || true - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/contrib/libexec/lockspool/locking.c b/foobar/portable/contrib/libexec/lockspool/locking.c deleted file mode 100644 index e4922dd6..00000000 --- a/foobar/portable/contrib/libexec/lockspool/locking.c +++ /dev/null @@ -1,181 +0,0 @@ -/* $OpenBSD: locking.c,v 1.14 2020/02/09 14:59:20 millert Exp $ */ - -/* - * Copyright (c) 1996-1998 Theo de Raadt - * Copyright (c) 1996-1998 David Mazieres - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the authors may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pathnames.h" -#include "mail.local.h" - -static char lpath[PATH_MAX]; - -void -rellock(void) -{ - - if (lpath[0]) - unlink(lpath); -} - -int -getlock(const char *name, struct passwd *pw) -{ - struct stat sb, fsb; - int lfd=-1; - char buf[8*1024]; - int tries = 0; - - (void)snprintf(lpath, sizeof lpath, "%s/%s.lock", - _PATH_MAILDIR, name); - - if (stat(_PATH_MAILDIR, &sb) != -1 && - (sb.st_mode & S_IWOTH) == S_IWOTH) { - /* - * We have a writeable spool, deal with it as - * securely as possible. - */ - time_t ctim = -1; - - seteuid(pw->pw_uid); - if (lstat(lpath, &sb) != -1) - ctim = sb.st_ctime; - while (1) { - /* - * Deal with existing user.lock files - * or directories or symbolic links that - * should not be here. - */ - if (readlink(lpath, buf, sizeof buf-1) != -1) { - if (lstat(lpath, &sb) != -1 && - S_ISLNK(sb.st_mode)) { - seteuid(sb.st_uid); - unlink(lpath); - seteuid(pw->pw_uid); - } - goto again; - } - if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL|O_EXLOCK, - S_IRUSR|S_IWUSR)) != -1) - break; -again: - if (tries > 10) { - mwarn("%s: %s", lpath, strerror(errno)); - seteuid(0); - return(-1); - } - if (tries > 9 && - (lfd = open(lpath, O_WRONLY|O_EXLOCK, 0)) != -1) { - if (fstat(lfd, &fsb) != -1 && - lstat(lpath, &sb) != -1) { - if (fsb.st_dev == sb.st_dev && - fsb.st_ino == sb.st_ino && - ctim == fsb.st_ctime ) { - seteuid(fsb.st_uid); - baditem(lpath); - seteuid(pw->pw_uid); - } - } - close(lfd); - } - sleep(1U << tries); - tries++; - continue; - } - seteuid(0); - } else { - /* - * Only root can write the spool directory. - */ - while (1) { - if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL, - S_IRUSR|S_IWUSR)) != -1) - break; - if (tries > 9) { - mwarn("%s: %s", lpath, strerror(errno)); - return(-1); - } - sleep(1U << tries); - tries++; - } - } - return(lfd); -} - -void -baditem(char *path) -{ - char npath[PATH_MAX]; - int fd; - - if (unlink(path) == 0) - return; - snprintf(npath, sizeof npath, "%s/mailXXXXXXXXXX", _PATH_MAILDIR); - if ((fd = mkstemp(npath)) == -1) - return; - close(fd); - if (rename(path, npath) == -1) - unlink(npath); - else - mwarn("nasty spool item %s renamed to %s", path, npath); - /* XXX if we fail to rename, another attempt will happen later */ -} - -void -mwarn(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog(LOG_ERR, fmt, ap); - va_end(ap); -} - -void -merr(int eval, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog(LOG_ERR, fmt, ap); - va_end(ap); - exit(eval); -} diff --git a/foobar/portable/contrib/libexec/lockspool/lockspool.1 b/foobar/portable/contrib/libexec/lockspool/lockspool.1 deleted file mode 100644 index ea5524bf..00000000 --- a/foobar/portable/contrib/libexec/lockspool/lockspool.1 +++ /dev/null @@ -1,77 +0,0 @@ -.\" $OpenBSD: lockspool.1,v 1.14 2019/01/25 00:19:26 millert Exp $ -.\" -.\" Copyright (c) 1998 Todd C. Miller -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: January 25 2019 $ -.Dt LOCKSPOOL 1 -.Os -.Sh NAME -.Nm lockspool -.Nd lock user's system mailbox -.Sh SYNOPSIS -.Nm lockspool -.Op Ar username -.Sh DESCRIPTION -.Nm -is useful for a client mail program to attain proper locking. -.Nm -obtains a -.Pa username.lock -for the calling user and retains it until stdin is closed or a signal like -.Dv SIGINT , -.Dv SIGTERM , -or -.Dv SIGHUP -is received. -Additionally, the superuser may specify the name of a user in order -to lock a different mailbox. -.Pp -If -.Nm -is able to create the lock file, -.Dq 1 -is written to stdout, otherwise -.Dq 0 -is written and an error message is written to stderr. -.Nm -will try up to 10 times to get the lock (sleeping -for a short period in between tries). -.Pp -Typical usage is for a user mail agent (such as -.Xr mail 1 ) -to open a pipe to -.Nm -when it needs to lock the user's mail spool. -Closing the pipe will cause -.Nm -to release the lock. -.Sh FILES -.Bl -tag -width /var/mail/username.lock -compact -.It Pa /var/mail/username.lock -user's mail lock file -.El -.Sh EXIT STATUS -The -.Nm -utility exits 0 on success, and 1 if an error occurs. -.Sh SEE ALSO -.Xr mail 1 , -.Xr mail.local 8 , -.Xr smtpd 8 -.Sh HISTORY -The -.Nm -program appeared in -.Ox 2.4 . diff --git a/foobar/portable/contrib/libexec/lockspool/lockspool.c b/foobar/portable/contrib/libexec/lockspool/lockspool.c deleted file mode 100644 index 9277241b..00000000 --- a/foobar/portable/contrib/libexec/lockspool/lockspool.c +++ /dev/null @@ -1,124 +0,0 @@ -/* $OpenBSD: lockspool.c,v 1.21 2020/02/09 14:59:20 millert Exp $ */ - -/* - * Copyright (c) 1998 Theo de Raadt - * Copyright (c) 1998 Todd C. Miller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mail.local.h" - -void unhold(int); -void usage(void); - -extern char *__progname; - -int -main(int argc, char *argv[]) -{ - struct passwd *pw; - struct pollfd pfd; - ssize_t nread; - char *from, c; - int holdfd; - -#if HAVE_UNVEIL - if (unveil(_PATH_MAILDIR, "rwc") == -1) - err(1, "unveil"); -#endif -#if HAVE_PLEDGE - if (pledge("stdio rpath wpath getpw cpath fattr", NULL) == -1) - err(1, "pledge"); -#endif - - openlog(__progname, LOG_PERROR, LOG_MAIL); - - if (argc != 1 && argc != 2) - usage(); - if (argc == 2 && getuid() != 0) - merr(1, "you must be root to lock someone else's spool"); - - signal(SIGTERM, unhold); - signal(SIGINT, unhold); - signal(SIGHUP, unhold); - signal(SIGPIPE, unhold); - - if (argc == 2) - pw = getpwnam(argv[1]); - else - pw = getpwuid(getuid()); - if (pw == NULL) - exit (1); - from = pw->pw_name; - - holdfd = getlock(from, pw); - if (holdfd == -1) { - write(STDOUT_FILENO, "0\n", 2); - exit (1); - } - write(STDOUT_FILENO, "1\n", 2); - - /* wait for the other end of the pipe to close, then release the lock */ - pfd.fd = STDIN_FILENO; - pfd.events = POLLIN; - do { - if (poll(&pfd, 1, INFTIM) == -1) { - if (errno != EINTR) - break; - } - do { - nread = read(STDIN_FILENO, &c, 1); - } while (nread == 1 || (nread == -1 && errno == EINTR)); - } while (nread == -1 && errno == EAGAIN); - rellock(); - exit (0); -} - -/*ARGSUSED*/ -void -unhold(int signo) -{ - - rellock(); - _exit(0); -} - -void -usage(void) -{ - - merr(1, "usage: %s [username]", __progname); -} diff --git a/foobar/portable/contrib/libexec/lockspool/mail.local.h b/foobar/portable/contrib/libexec/lockspool/mail.local.h deleted file mode 100644 index bc3137cb..00000000 --- a/foobar/portable/contrib/libexec/lockspool/mail.local.h +++ /dev/null @@ -1,42 +0,0 @@ -/* $OpenBSD: mail.local.h,v 1.7 2020/02/09 14:59:21 millert Exp $ */ - -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -void baditem(char *); -int deliver(int, char *, int); -void merr(int, const char *, ...); -void mwarn(const char *, ...); -int getlock(const char *, struct passwd *); -void notifybiff(char *); -void rellock(void); -int storemail(char *); -int lockspool(const char *, struct passwd *); -void unlockspool(void); -void usage(void); diff --git a/foobar/portable/contrib/libexec/lockspool/pathnames.h b/foobar/portable/contrib/libexec/lockspool/pathnames.h deleted file mode 100644 index 0a2c2731..00000000 --- a/foobar/portable/contrib/libexec/lockspool/pathnames.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.5 2003/06/02 19:38:24 millert Exp $*/ - -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)pathnames.h 5.3 (Berkeley) 1/17/91 - */ -#ifdef HAVE_PATHS_H -#include -#endif - -#define _PATH_LOCTMP "/tmp/local.XXXXXXXXXX" -#define _PATH_LOCKSPOOL PATH_LIBEXEC"/lockspool" diff --git a/foobar/portable/contrib/libexec/mail.local/Makefile.am b/foobar/portable/contrib/libexec/mail.local/Makefile.am deleted file mode 100644 index bd5211a2..00000000 --- a/foobar/portable/contrib/libexec/mail.local/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -pkglibexec_PROGRAMS = mail.local - -mail_local_SOURCES = mail.local.c -mail_local_SOURCES += locking.c -mail_local_SOURCES += $(top_srcdir)/smtpd/log.c - -EXTRA_DIST = mail.local.h pathnames.h - -AM_CPPFLAGS = -I$(top_srcdir)/openbsd-compat -DPATH_LIBEXEC=\"$(pkglibexecdir)\" - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - -# need to define _GNU_SOURCE to get: -# EAI_NODATA defined -# {v,}asprintf -# setres{g,u}id -#CFLAGS += -D_GNU_SOURCE - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/contrib/libexec/mail.local/locking.c b/foobar/portable/contrib/libexec/mail.local/locking.c deleted file mode 100644 index 85a48d5e..00000000 --- a/foobar/portable/contrib/libexec/mail.local/locking.c +++ /dev/null @@ -1,182 +0,0 @@ -/* $OpenBSD: locking.c,v 1.14 2020/02/09 14:59:20 millert Exp $ */ - -/* - * Copyright (c) 1996-1998 Theo de Raadt - * Copyright (c) 1996-1998 David Mazieres - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the authors may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "includes.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pathnames.h" -#include "mail.local.h" - -static char lpath[PATH_MAX]; - -void -rellock(void) -{ - - if (lpath[0]) - unlink(lpath); -} - -int -getlock(const char *name, struct passwd *pw) -{ - struct stat sb, fsb; - int lfd=-1; - char buf[8*1024]; - int tries = 0; - - (void)snprintf(lpath, sizeof lpath, "%s/%s.lock", - _PATH_MAILDIR, name); - - if (stat(_PATH_MAILDIR, &sb) != -1 && - (sb.st_mode & S_IWOTH) == S_IWOTH) { - /* - * We have a writeable spool, deal with it as - * securely as possible. - */ - time_t ctim = -1; - - seteuid(pw->pw_uid); - if (lstat(lpath, &sb) != -1) - ctim = sb.st_ctime; - while (1) { - /* - * Deal with existing user.lock files - * or directories or symbolic links that - * should not be here. - */ - if (readlink(lpath, buf, sizeof buf-1) != -1) { - if (lstat(lpath, &sb) != -1 && - S_ISLNK(sb.st_mode)) { - seteuid(sb.st_uid); - unlink(lpath); - seteuid(pw->pw_uid); - } - goto again; - } - if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL|O_EXLOCK, - S_IRUSR|S_IWUSR)) != -1) - break; -again: - if (tries > 10) { - mwarn("%s: %s", lpath, strerror(errno)); - seteuid(0); - return(-1); - } - if (tries > 9 && - (lfd = open(lpath, O_WRONLY|O_EXLOCK, 0)) != -1) { - if (fstat(lfd, &fsb) != -1 && - lstat(lpath, &sb) != -1) { - if (fsb.st_dev == sb.st_dev && - fsb.st_ino == sb.st_ino && - ctim == fsb.st_ctime ) { - seteuid(fsb.st_uid); - baditem(lpath); - seteuid(pw->pw_uid); - } - } - close(lfd); - } - sleep(1U << tries); - tries++; - continue; - } - seteuid(0); - } else { - /* - * Only root can write the spool directory. - */ - while (1) { - if ((lfd = open(lpath, O_CREAT|O_WRONLY|O_EXCL, - S_IRUSR|S_IWUSR)) != -1) - break; - if (tries > 9) { - mwarn("%s: %s", lpath, strerror(errno)); - return(-1); - } - sleep(1U << tries); - tries++; - } - } - return(lfd); -} - -void -baditem(char *path) -{ - char npath[PATH_MAX]; - int fd; - - if (unlink(path) == 0) - return; - snprintf(npath, sizeof npath, "%s/mailXXXXXXXXXX", _PATH_MAILDIR); - if ((fd = mkstemp(npath)) == -1) - return; - close(fd); - if (rename(path, npath) == -1) - unlink(npath); - else - mwarn("nasty spool item %s renamed to %s", path, npath); - /* XXX if we fail to rename, another attempt will happen later */ -} - -void -mwarn(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog(LOG_ERR, fmt, ap); - va_end(ap); -} - -void -merr(int eval, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog(LOG_ERR, fmt, ap); - va_end(ap); - exit(eval); -} diff --git a/foobar/portable/contrib/libexec/mail.local/mail.local.8 b/foobar/portable/contrib/libexec/mail.local/mail.local.8 deleted file mode 100644 index 330a4473..00000000 --- a/foobar/portable/contrib/libexec/mail.local/mail.local.8 +++ /dev/null @@ -1,183 +0,0 @@ -.\" $OpenBSD: mail.local.8,v 1.31 2014/09/16 21:28:51 jmc Exp $ -.\" Copyright (c) 1990 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)mail.local.8 6.8 (Berkeley) 4/27/91 -.\" -.Dd $Mdocdate: September 16 2014 $ -.Dt MAIL.LOCAL 8 -.Os -.Sh NAME -.Nm mail.local -.Nd store mail in a mailbox -.Sh SYNOPSIS -.Nm mail.local -.Op Fl Ll -.Op Fl f Ar from -.Ar user ... -.Sh DESCRIPTION -.Nm -reads the standard input up to an end-of-file and appends it to each -.Ar user Ns 's -.Pa mail -file. -The -.Ar user -must be a valid user name. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl f Ar from -Specify the sender's name. -.It Fl L -Don't create a -.Pa username.lock -file while locking the spool. -.It Fl l -For compatibility, request that files named -.Pa username.lock -be used for locking. -(This is the default behavior.) -.El -.Pp -Individual mail messages in the mailbox are delimited by an empty -line followed by a line beginning with the string -.Dq "From\&\ " . -A line containing the string -.Dq "From\&\ " , -the sender's name and a timestamp is prepended to each delivered mail message. -A blank line is appended to each message. -A greater-than character -.Pq Ql > -is prepended to any line in the message which could be mistaken for a -.Dq "From\&\ " -delimiter line. -.Pp -Significant efforts have been made to ensure that -.Nm -acts as securely as possible if the spool directory is mode 1777 or 755. -The default of mode 755 is more secure, but it prevents mail clients from using -.Pa username.lock -style locking. -The use of 1777 is more flexible in an NFS shared-spool environment, -so many sites use it. -However, it does carry some risks, such as attackers filling the spool disk. -Some of these problems may be alleviated -by making the spool a separate filesystem, and placing quotas on it. -The use of any mode other than 1777 and 755 for the spool directory is -recommended against but may work properly. -.Pp -The mailbox is always locked using -.Xr flock 2 -while mail is appended. -Unless the -.Fl L -flag is specified, a -.Pa username.lock -file is also used. -.Pp -If the -.Xr biff 1 -service is returned by -.Xr getservbyname 3 , -the biff server is notified of delivered mail. -.Sh ENVIRONMENT -.Bl -tag -width indent -.It Ev TZ -Used to set the appropriate time zone on the timestamp. -.El -.Sh FILES -.Bl -tag -width /tmp/local.XXXXXXXXXX -compact -.It Pa /tmp/local.XXXXXXXXXX -temporary files -.It Pa /var/mail/user -user's mailbox directory -.El -.Sh EXIT STATUS -.Ex -std mail.local -.Sh SEE ALSO -.Xr biff 1 , -.Xr mail 1 , -.Xr flock 2 , -.Xr getservbyname 3 , -.Xr comsat 8 , -.Xr smtpd 8 -.Sh HISTORY -A superset of -.Nm -(handling mailbox reading as well as mail delivery) appeared in -.At v7 -as the program -.Xr mail 1 . -.Sh BUGS -Using quotas in -.Pa /var/mail -can be problematic if using -.Xr sendmail 8 -as an MTA, -since it asks -.Nm -to deliver a message to multiple recipients if possible. -This causes problems in a quota environment since a message may be -delivered to some users but not others due to disk quotas. -Even though the message was delivered to some of the recipients, -.Nm -will exit with an exit code > 0, causing -.Xr sendmail 8 -to attempt redelivery later. -That means that some users will keep getting the same message every time -.Xr sendmail 8 -runs its queue. -This problem does not exist for -.Xr smtpd 8 -users. -.Pp -If you are running -.Xr sendmail 8 -and have disk quotas on -.Pa /var/mail -it is imperative that you unset the -.Dq m -mailer flag for the -.Sq local -mailer. -To do this, locate the line beginning with -.Dq Mlocal -in -.Pa /etc/mail/sendmail.cf -and remove the -.Dq m -from the flags section, denoted by -.Dq F= . -Alternately, you can override the default mailer flags by adding the line: -.Pp -.Dl define(`LOCAL_MAILER_FLAGS', `rn9S')dnl -.Pp -to your -.Dq \.mc -file (this is the source file that is used to generate -.Pa /etc/mail/sendmail.cf ) . diff --git a/foobar/portable/contrib/libexec/mail.local/mail.local.c b/foobar/portable/contrib/libexec/mail.local/mail.local.c deleted file mode 100644 index a574b3fe..00000000 --- a/foobar/portable/contrib/libexec/mail.local/mail.local.c +++ /dev/null @@ -1,392 +0,0 @@ -/* $OpenBSD: mail.local.c,v 1.39 2020/02/09 14:59:20 millert Exp $ */ - -/*- - * Copyright (c) 1996-1998 Theo de Raadt - * Copyright (c) 1996-1998 David Mazieres - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "includes.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pathnames.h" -#include "mail.local.h" - -int -main(int argc, char *argv[]) -{ - struct passwd *pw; - int ch, fd, eval, lockfile=1; - uid_t uid; - char *from; - - openlog("mail.local", LOG_PERROR, LOG_MAIL); - - from = NULL; - while ((ch = getopt(argc, argv, "lLdf:r:")) != -1) - switch (ch) { - case 'd': /* backward compatible */ - break; - case 'f': - case 'r': /* backward compatible */ - if (from) - merr(EX_USAGE, "multiple -f options"); - from = optarg; - break; - case 'l': - lockfile=1; - break; - case 'L': - lockfile=0; - break; - default: - usage(); - } - argc -= optind; - argv += optind; - - if (!*argv) - usage(); - - /* - * If from not specified, use the name from getlogin() if the - * uid matches, otherwise, use the name from the password file - * corresponding to the uid. - */ - uid = getuid(); - if (!from && (!(from = getlogin()) || - !(pw = getpwnam(from)) || pw->pw_uid != uid)) - from = (pw = getpwuid(uid)) ? pw->pw_name : "???"; - - fd = storemail(from); - for (eval = 0; *argv; ++argv) { - if ((ch = deliver(fd, *argv, lockfile)) != 0) - eval = ch; - } - exit(eval); -} - -int -storemail(char *from) -{ - FILE *fp = NULL; - time_t tval; - int fd, eline; - size_t len; - char *line, *tbuf; - - if ((tbuf = strdup(_PATH_LOCTMP)) == NULL) - merr(EX_OSERR, "unable to allocate memory"); - if ((fd = mkstemp(tbuf)) == -1 || !(fp = fdopen(fd, "w+"))) - merr(EX_OSERR, "unable to open temporary file"); - (void)unlink(tbuf); - free(tbuf); - - (void)time(&tval); - (void)fprintf(fp, "From %s %s", from, ctime(&tval)); - - for (eline = 1, tbuf = NULL; (line = fgetln(stdin, &len));) { - /* We have to NUL-terminate the line since fgetln does not */ - if (line[len - 1] == '\n') - line[len - 1] = '\0'; - else { - /* No trailing newline, so alloc space and copy */ - if ((tbuf = malloc(len + 1)) == NULL) - merr(EX_OSERR, "unable to allocate memory"); - memcpy(tbuf, line, len); - tbuf[len] = '\0'; - line = tbuf; - } - if (line[0] == '\0') - eline = 1; - else { - if (eline && line[0] == 'F' && len > 5 && - !memcmp(line, "From ", 5)) - (void)putc('>', fp); - eline = 0; - } - (void)fprintf(fp, "%s\n", line); - if (ferror(fp)) - break; - } - free(tbuf); - - /* Output a newline; note, empty messages are allowed. */ - (void)putc('\n', fp); - (void)fflush(fp); - if (ferror(fp)) - merr(EX_OSERR, "temporary file write error"); - return(fd); -} - -int -deliver(int fd, char *name, int lockfile) -{ - struct stat sb, fsb; - struct passwd *pw; - int mbfd=-1, lfd=-1, rval=EX_OSERR; - char biffmsg[100], buf[8*1024], path[PATH_MAX]; - off_t curoff; - size_t off; - ssize_t nr, nw; - - /* - * Disallow delivery to unknown names -- special mailboxes can be - * handled in the sendmail aliases file. - */ - if (!(pw = getpwnam(name))) { - mwarn("unknown name: %s", name); - return(EX_NOUSER); - } - - (void)snprintf(path, sizeof path, "%s/%s", _PATH_MAILDIR, name); - - if (lockfile) { - lfd = lockspool(name, pw); - if (lfd == -1) - return(EX_OSERR); - } - - /* after this point, always exit via bad to remove lockfile */ -retry: - if (lstat(path, &sb)) { - if (errno != ENOENT) { - mwarn("%s: %s", path, strerror(errno)); - goto bad; - } - if ((mbfd = open(path, O_APPEND|O_CREAT|O_EXCL|O_WRONLY|O_EXLOCK, - S_IRUSR|S_IWUSR)) == -1) { -#ifndef HAVE_O_EXLOCK - /* XXX : do something! */ -#endif - if (errno == EEXIST) { - /* file appeared since lstat */ - goto retry; - } else { - mwarn("%s: %s", path, strerror(errno)); - rval = EX_CANTCREAT; - goto bad; - } - } - /* - * Set the owner and group. Historically, binmail repeated - * this at each mail delivery. We no longer do this, assuming - * that if the ownership or permissions were changed there - * was a reason for doing so. - */ - if (fchown(mbfd, pw->pw_uid, pw->pw_gid) == -1) { - mwarn("chown %u:%u: %s", pw->pw_uid, pw->pw_gid, name); - goto bad; - } - } else { - if (sb.st_nlink != 1 || !S_ISREG(sb.st_mode)) { - mwarn("%s: linked or special file", path); - goto bad; - } - if ((mbfd = open(path, O_APPEND|O_WRONLY|O_EXLOCK, - S_IRUSR|S_IWUSR)) == -1) { - mwarn("%s: %s", path, strerror(errno)); - goto bad; - } - if (fstat(mbfd, &fsb) == -1) { - /* relating error to path may be bad style */ - mwarn("%s: %s", path, strerror(errno)); - goto bad; - } - if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) { - mwarn("%s: changed after open", path); - goto bad; - } - /* paranoia? */ - if (fsb.st_nlink != 1 || !S_ISREG(fsb.st_mode)) { - mwarn("%s: linked or special file", path); - rval = EX_CANTCREAT; - goto bad; - } - } - - curoff = lseek(mbfd, 0, SEEK_END); - (void)snprintf(biffmsg, sizeof biffmsg, "%s@%lld\n", name, curoff); - if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { - mwarn("temporary file: %s", strerror(errno)); - goto bad; - } - - while ((nr = read(fd, buf, sizeof(buf))) > 0) - for (off = 0; off < nr; off += nw) - if ((nw = write(mbfd, buf + off, nr - off)) == -1) { - mwarn("%s: %s", path, strerror(errno)); - (void)ftruncate(mbfd, curoff); - goto bad; - } - - if (nr == 0) { - rval = 0; - } else { - (void)ftruncate(mbfd, curoff); - mwarn("temporary file: %s", strerror(errno)); - } - -bad: - if (lfd != -1) - unlockspool(); - - if (mbfd != -1) { - (void)fsync(mbfd); /* Don't wait for update. */ - (void)close(mbfd); /* Implicit unlock. */ - } - - if (!rval) - notifybiff(biffmsg); - return(rval); -} - -void -notifybiff(char *msg) -{ - static struct addrinfo *res0; - struct addrinfo hints, *res; - static int f = -1; - size_t len; - int error; - - if (res0 == NULL) { - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - - error = getaddrinfo("localhost", "biff", &hints, &res0); - if (error) { - /* Be silent if biff service not available. */ - if (error != EAI_SERVICE) { - mwarn("localhost: %s", gai_strerror(error)); - } - return; - } - } - - if (f == -1) { - for (res = res0; res != NULL; res = res->ai_next) { - f = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (f != -1) - break; - } - } - if (f == -1) { - mwarn("socket: %s", strerror(errno)); - return; - } - - len = strlen(msg) + 1; /* XXX */ - if (sendto(f, msg, len, 0, res->ai_addr, res->ai_addrlen) != len) - mwarn("sendto biff: %s", strerror(errno)); -} - -static int lockfd = -1; -static pid_t lockpid = -1; - -int -lockspool(const char *name, struct passwd *pw) -{ - int pfd[2]; - char ch; - - if (geteuid() == 0) - return getlock(name, pw); - - /* If not privileged, open pipe to lockspool(1) instead */ - if (pipe2(pfd, O_CLOEXEC) == -1) { - merr(EX_OSERR, "pipe: %s", strerror(errno)); - return -1; - } - - signal(SIGPIPE, SIG_IGN); - switch ((lockpid = fork())) { - case -1: - merr(EX_OSERR, "fork: %s", strerror(errno)); - return -1; - case 0: - /* child */ - close(pfd[0]); - dup2(pfd[1], STDOUT_FILENO); - execl(_PATH_LOCKSPOOL, "lockspool", (char *)NULL); - merr(EX_OSERR, "execl: lockspool: %s", strerror(errno)); - /* NOTREACHED */ - break; - default: - /* parent */ - close(pfd[1]); - lockfd = pfd[0]; - break; - } - - if (read(lockfd, &ch, 1) != 1 || ch != '1') { - unlockspool(); - merr(EX_OSERR, "lockspool: unable to get lock"); - } - - return lockfd; -} - -void -unlockspool(void) -{ - if (lockpid != -1) { - waitpid(lockpid, NULL, 0); - lockpid = -1; - } else { - rellock(); - } - close(lockfd); - lockfd = -1; -} - -void -usage(void) -{ - merr(EX_USAGE, "usage: mail.local [-Ll] [-f from] user ..."); -} diff --git a/foobar/portable/contrib/libexec/mail.local/mail.local.h b/foobar/portable/contrib/libexec/mail.local/mail.local.h deleted file mode 100644 index bc3137cb..00000000 --- a/foobar/portable/contrib/libexec/mail.local/mail.local.h +++ /dev/null @@ -1,42 +0,0 @@ -/* $OpenBSD: mail.local.h,v 1.7 2020/02/09 14:59:21 millert Exp $ */ - -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -void baditem(char *); -int deliver(int, char *, int); -void merr(int, const char *, ...); -void mwarn(const char *, ...); -int getlock(const char *, struct passwd *); -void notifybiff(char *); -void rellock(void); -int storemail(char *); -int lockspool(const char *, struct passwd *); -void unlockspool(void); -void usage(void); diff --git a/foobar/portable/contrib/libexec/mail.local/pathnames.h b/foobar/portable/contrib/libexec/mail.local/pathnames.h deleted file mode 100644 index 0a2c2731..00000000 --- a/foobar/portable/contrib/libexec/mail.local/pathnames.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.5 2003/06/02 19:38:24 millert Exp $*/ - -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)pathnames.h 5.3 (Berkeley) 1/17/91 - */ -#ifdef HAVE_PATHS_H -#include -#endif - -#define _PATH_LOCTMP "/tmp/local.XXXXXXXXXX" -#define _PATH_LOCKSPOOL PATH_LIBEXEC"/lockspool" diff --git a/foobar/portable/etc/README.md b/foobar/portable/etc/README.md deleted file mode 100644 index 0c53cc6b..00000000 --- a/foobar/portable/etc/README.md +++ /dev/null @@ -1,6 +0,0 @@ -This directory will contain example OpenSMTPD config files that can be used as -a reference or for testing specific usecases. Tests that are run as part of -CI/CD process in docker containers will utilize these files. - - -* `aliases` file - default aliases map that is referenced by default OpenSMTPD config. diff --git a/foobar/portable/etc/aliases b/foobar/portable/etc/aliases deleted file mode 100644 index 09fb6cf5..00000000 --- a/foobar/portable/etc/aliases +++ /dev/null @@ -1,100 +0,0 @@ -# -# $OpenBSD: aliases,v 1.67 2019/01/26 10:58:05 florian Exp $ -# -# Aliases in this file will NOT be expanded in the header from -# Mail, but WILL be visible over networks or from /usr/libexec/mail.local. -# -# >>>>>>>>>> The program "newaliases" must be run after -# >> NOTE >> this file is updated for any changes to -# >>>>>>>>>> show through to smtpd. -# - -# Basic system aliases -- these MUST be present -MAILER-DAEMON: postmaster -postmaster: root - -# General redirections for important pseudo accounts -daemon: root -ftp-bugs: root -operator: root -www: root - -# Redirections for pseudo accounts that should not receive mail -_bgpd: /dev/null -_dhcp: /dev/null -_dpb: /dev/null -_dvmrpd: /dev/null -_eigrpd: /dev/null -_file: /dev/null -_fingerd: /dev/null -_ftp: /dev/null -_hostapd: /dev/null -_identd: /dev/null -_iked: /dev/null -_isakmpd: /dev/null -_iscsid: /dev/null -_ldapd: /dev/null -_ldpd: /dev/null -_mopd: /dev/null -_nsd: /dev/null -_ntp: /dev/null -_ospfd: /dev/null -_ospf6d: /dev/null -_pbuild: /dev/null -_pfetch: /dev/null -_pflogd: /dev/null -_ping: /dev/null -_pkgfetch: /dev/null -_pkguntar: /dev/null -_portmap: /dev/null -_ppp: /dev/null -_rad: /dev/null -_radiusd: /dev/null -_rbootd: /dev/null -_relayd: /dev/null -_rebound: /dev/null -_ripd: /dev/null -_rstatd: /dev/null -_rusersd: /dev/null -_rwalld: /dev/null -_smtpd: /dev/null -_smtpq: /dev/null -_sndio: /dev/null -_snmpd: /dev/null -_spamd: /dev/null -_switchd: /dev/null -_syslogd: /dev/null -_tcpdump: /dev/null -_traceroute: /dev/null -_tftpd: /dev/null -_unbound: /dev/null -_unwind: /dev/null -_vmd: /dev/null -_x11: /dev/null -_ypldap: /dev/null -bin: /dev/null -build: /dev/null -nobody: /dev/null -_tftp_proxy: /dev/null -_ftp_proxy: /dev/null -_sndiop: /dev/null -_syspatch: /dev/null -_slaacd: /dev/null -sshd: /dev/null - -# Well-known aliases -- these should be filled in! -# root: -# manager: -# dumper: - -# RFC 2142: NETWORK OPERATIONS MAILBOX NAMES -abuse: root -# noc: root -security: root - -# RFC 2142: SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES -# hostmaster: root -# usenet: root -# news: usenet -# webmaster: root -# ftp: root diff --git a/foobar/portable/mk/Makefile.am b/foobar/portable/mk/Makefile.am deleted file mode 100644 index f49c5289..00000000 --- a/foobar/portable/mk/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -SUBDIRS = smtpd -SUBDIRS += smtpctl -SUBDIRS += mail -SUBDIRS += smtp diff --git a/foobar/portable/mk/mail/Makefile.am b/foobar/portable/mk/mail/Makefile.am deleted file mode 100644 index cc6d96cb..00000000 --- a/foobar/portable/mk/mail/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -SUBDIRS = mail.lmtp -SUBDIRS += mail.maildir -SUBDIRS += mail.mboxfile -SUBDIRS += mail.mda - diff --git a/foobar/portable/mk/mail/mail.lmtp/Makefile.am b/foobar/portable/mk/mail/mail.lmtp/Makefile.am deleted file mode 100644 index 9847dfdf..00000000 --- a/foobar/portable/mk/mail/mail.lmtp/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -include $(top_srcdir)/mk/pathnames - -pkglibexec_PROGRAMS = mail.lmtp - -mail_lmtp_SOURCES = $(smtpd_srcdir)/mail.lmtp.c -mail_lmtp_SOURCES+= $(smtpd_srcdir)/log.c - -AM_CPPFLAGS= -I$(top_srcdir)/smtpd \ - -I$(top_srcdir)/openbsd-compat -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - - - - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/mk/mail/mail.maildir/Makefile.am b/foobar/portable/mk/mail/mail.maildir/Makefile.am deleted file mode 100644 index d8f696ee..00000000 --- a/foobar/portable/mk/mail/mail.maildir/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -include $(top_srcdir)/mk/pathnames - -pkglibexec_PROGRAMS = mail.maildir - -mail_maildir_SOURCES = $(smtpd_srcdir)/mail.maildir.c -mail_maildir_SOURCES+= $(smtpd_srcdir)/log.c - -AM_CPPFLAGS= -I$(top_srcdir)/smtpd \ - -I$(top_srcdir)/openbsd-compat -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - - - - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/mk/mail/mail.mboxfile/Makefile.am b/foobar/portable/mk/mail/mail.mboxfile/Makefile.am deleted file mode 100644 index d57362c0..00000000 --- a/foobar/portable/mk/mail/mail.mboxfile/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -include $(top_srcdir)/mk/pathnames - -pkglibexec_PROGRAMS = mail.mboxfile - -mail_mboxfile_SOURCES = $(smtpd_srcdir)/mail.mboxfile.c -mail_mboxfile_SOURCES+= $(smtpd_srcdir)/log.c - -AM_CPPFLAGS= -I$(top_srcdir)/smtpd \ - -I$(top_srcdir)/openbsd-compat -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - - - - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/mk/mail/mail.mda/Makefile.am b/foobar/portable/mk/mail/mail.mda/Makefile.am deleted file mode 100644 index b04aefda..00000000 --- a/foobar/portable/mk/mail/mail.mda/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -include $(top_srcdir)/mk/pathnames - -pkglibexec_PROGRAMS = mail.mda - -mail_mda_SOURCES = $(smtpd_srcdir)/mail.mda.c -mail_mda_SOURCES+= $(smtpd_srcdir)/log.c - -AM_CPPFLAGS= -I$(top_srcdir)/smtpd \ - -I$(top_srcdir)/openbsd-compat -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif - -LIBCOMPAT = $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD = $(LIBCOMPAT) - - - - -uninstall-hook: - rmdir $(DESTDIR)$(pkglibexecdir) 2> /dev/null || /bin/true diff --git a/foobar/portable/mk/mdoc2man.awk b/foobar/portable/mk/mdoc2man.awk deleted file mode 100644 index 726f628c..00000000 --- a/foobar/portable/mk/mdoc2man.awk +++ /dev/null @@ -1,391 +0,0 @@ -#!/usr/bin/awk -# -# Copyright (c) 2003 Peter Stuge -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -# Dramatically overhauled by Tim Kientzle. This version almost -# handles library-style pages with Fn, Ft, etc commands. Still -# a lot of problems... - -BEGIN { - displaylines = 0 - trailer = "" - out = "" - sep = "" - nextsep = " " -} - -# Add a word with appropriate preceding whitespace -# Maintain a short queue of the expected upcoming word separators. -function add(str) { - out=out sep str - sep = nextsep - nextsep = " " -} - -# Add a word with no following whitespace -# Use for opening punctuation such as '(' -function addopen(str) { - add(str) - sep = "" -} - -# Add a word with no preceding whitespace -# Use for closing punctuation such as ')' or '.' -function addclose(str) { - sep = "" - add(str) -} - -# Add a word with no space before or after -# Use for separating punctuation such as '=' -function addpunct(str) { - sep = "" - add(str) - sep = "" -} - -# Emit the current line so far -function endline() { - addclose(trailer) - trailer = "" - if(length(out) > 0) { - print out - out="" - } - if(displaylines > 0) { - displaylines = displaylines - 1 - if (displaylines == 0) - dispend() - } - # First word on next line has no preceding whitespace - sep = "" -} - -function linecmd(cmd) { - endline() - add(cmd) - endline() -} - -function breakline() { - linecmd(".br") -} - -# Start an indented display -function dispstart() { - linecmd(".RS 4") -} - -# End an indented display -function dispend() { - linecmd(".RE") -} - -# Collect rest of input line -function wtail() { - retval="" - while(w 0) { - sub("^[ \t]*", "", l) - if (match(l, "^\"")) { - l = substr(l, 2) - o = index(l, "\"") - if (o > 0) { - w = substr(l, 1, o-1) - l = substr(l, o+1) - dest[n++] = w - } else { - dest[n++] = l - l = "" - } - } else { - o = match(l, "[ \t]") - if (o > 0) { - w = substr(l, 1, o-1) - l = substr(l, o+1) - dest[n++] = w - } else { - dest[n++] = l - l = "" - } - } - } - return n-1 -} - -! /^\./ { - out = $0 - endline() - next -} - -/^\.\\"/ { next } - -{ - sub("^\\.","") - nwords=splitwords($0, words) - # TODO: Instead of iterating 'w' over the array, have a separate - # function that returns 'next word' and use that. This will allow - # proper handling of double-quoted arguments as well. - for(w=1;w<=nwords;w++) { - if(match(words[w],"^Li$")) { # Literal; rest of line is unformatted - dispstart() - displaylines = 1 - } else if(match(words[w],"^Dl$")) { # Display literal - dispstart() - displaylines = 1 - } else if(match(words[w],"^Bd$")) { # Begin display - if(match(words[w+1],"-literal")) { - dispstart() - linecmd(".nf") - displaylines=10000 - w=nwords - } - } else if(match(words[w],"^Ed$")) { # End display - displaylines = 0 - dispend() - } else if(match(words[w],"^Ns$")) { # Suppress space after next word - nextsep = "" - } else if(match(words[w],"^No$")) { # Normal text - add(words[++w]) - } else if(match(words[w],"^Dq$")) { # Quote - addopen("``") - add(words[++w]) - while(w") - } else if(match(words[w],"^Dd$")) { - date=wtail() - next - } else if(match(words[w],"^Dt$")) { - id=wtail() - next - } else if(match(words[w],"^Ox$")) { - add("OpenBSD") - } else if(match(words[w],"^Fx$")) { - add("FreeBSD") - } else if(match(words[w],"^Nx$")) { - add("NetBSD") - } else if(match(words[w],"^St$")) { - if (match(words[w+1], "^-p1003.1$")) { - w++ - add("IEEE Std 1003.1 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-96$")) { - w++ - add("ISO/IEC 9945-1:1996 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-88$")) { - w++ - add("IEEE Std 1003.1-1988 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-2001$")) { - w++ - add("IEEE Std 1003.1-2001 (``POSIX.1'')") - } else if(match(words[w+1], "^-susv2$")) { - w++ - add("Version 2 of the Single UNIX Specification (``SUSv2'')") - } - } else if(match(words[w],"^Ex$")) { - if (match(words[w+1], "^-std$")) { - w++ - add("The \\fB" name "\\fP utility exits 0 on success, and >0 if an error occurs.") - } - } else if(match(words[w],"^Os$")) { - add(".TH " id " \"" date "\" \"" wtail() "\"") - } else if(match(words[w],"^Sh$")) { - section=wtail() - add(".SH " section) - linecmd(".ad l") - } else if(match(words[w],"^Xr$")) { - add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w]) - } else if(match(words[w],"^Nm$")) { - if(match(section,"SYNOPSIS")) - breakline() - if(w >= nwords) - n=name - else if (match(words[w+1], "^[A-Z][a-z]$")) - n=name - else if (match(words[w+1], "^[.,;:]$")) - n=name - else { - n=words[++w] - if(!length(name)) - name=n - } - if(!length(n)) - n=name - add("\\fB\\%" n "\\fP") - } else if(match(words[w],"^Nd$")) { - add("\\- " wtail()) - } else if(match(words[w],"^Fl$")) { - add("\\fB\\-" words[++w] "\\fP") - } else if(match(words[w],"^Ar$")) { - addopen("\\fI") - if(w==nwords) - add("file ...\\fP") - else - add(words[++w] "\\fP") - } else if(match(words[w],"^Cm$")) { - add("\\fB" words[++w] "\\fP") - } else if(match(words[w],"^Op$")) { - addopen("[") - option=1 - trailer="]" trailer - } else if(match(words[w],"^Pp$")) { - linecmd(".PP") - } else if(match(words[w],"^An$")) { - endline() - } else if(match(words[w],"^Ss$")) { - add(".SS") - } else if(match(words[w],"^Ft$")) { - if (match(section, "SYNOPSIS")) { - breakline() - } - add("\\fI" wtail() "\\fP") - if (match(section, "SYNOPSIS")) { - breakline() - } - } else if(match(words[w],"^Fn$")) { - ++w - F = "\\fB\\%" words[w] "\\fP(" - Fsep = "" - while(w\\fP") - } else if(match(words[w],"^Pa$")) { - addopen("\\fI") - w++ - if(match(words[w],"^\\.")) - add("\\&") - add(words[w] "\\fP") - } else if(match(words[w],"^Dv$")) { - add(".BR") - } else if(match(words[w],"^Em|Ev$")) { - add(".IR") - } else if(match(words[w],"^Pq$")) { - addopen("(") - trailer=")" trailer - } else if(match(words[w],"^Aq$")) { - addopen("\\%<") - trailer=">" trailer - } else if(match(words[w],"^Brq$")) { - addopen("{") - trailer="}" trailer - } else if(match(words[w],"^S[xy]$")) { - add(".B " wtail()) - } else if(match(words[w],"^Ic$")) { - add("\\fB") - trailer="\\fP" trailer - } else if(match(words[w],"^Bl$")) { - oldoptlist=optlist - linecmd(".RS 5") - if(match(words[w+1],"-bullet")) - optlist=1 - else if(match(words[w+1],"-enum")) { - optlist=2 - enum=0 - } else if(match(words[w+1],"-tag")) - optlist=3 - else if(match(words[w+1],"-item")) - optlist=4 - else if(match(words[w+1],"-bullet")) - optlist=1 - w=nwords - } else if(match(words[w],"^El$")) { - linecmd(".RE") - optlist=oldoptlist - } else if(match(words[w],"^It$")&&optlist) { - if(optlist==1) - add(".IP \\(bu") - else if(optlist==2) - add(".IP " ++enum ".") - else if(optlist==3) { - add(".TP") - endline() - if(match(words[w+1],"^Pa$|^Ev$")) { - add(".B") - w++ - } - } else if(optlist==4) - add(".IP") - } else if(match(words[w],"^Xo$")) { - # TODO: Figure out how to handle this - } else if(match(words[w],"^Xc$")) { - # TODO: Figure out how to handle this - } else if(match(words[w],"^[=]$")) { - addpunct(words[w]) - } else if(match(words[w],"^[[{(]$")) { - addopen(words[w]) - } else if(match(words[w],"^[\\])}.,;:]$")) { - addclose(words[w]) - } else { - add(words[w]) - } - } - if(match(out,"^\\.[^a-zA-Z]")) - sub("^\\.","",out) - endline() -} diff --git a/foobar/portable/mk/pathnames b/foobar/portable/mk/pathnames deleted file mode 100644 index b233ec33..00000000 --- a/foobar/portable/mk/pathnames +++ /dev/null @@ -1,10 +0,0 @@ -smtpd_srcdir = $(top_srcdir)/smtpd -compat_srcdir = $(top_srcdir)/openbsd-compat -regress_srcdir = $(top_srcdir)/regress/bin - -PATHS= -DSMTPD_CONFDIR=\"$(sysconfdir)\" \ - -DPATH_CHROOT=\"$(PRIVSEP_PATH)\" \ - -DPATH_SMTPCTL=\"$(sbindir)/smtpctl\" \ - -DPATH_MAILLOCAL=\"$(pkglibexecdir)/mail.local\" \ - -DPATH_MAKEMAP=\"$(sbindir)/makemap\" \ - -DPATH_LIBEXEC=\"$(pkglibexecdir)\" diff --git a/foobar/portable/mk/smtp/Makefile.am b/foobar/portable/mk/smtp/Makefile.am deleted file mode 100644 index e955a271..00000000 --- a/foobar/portable/mk/smtp/Makefile.am +++ /dev/null @@ -1,59 +0,0 @@ -include $(top_srcdir)/mk/pathnames - -bin_PROGRAMS= smtp - -smtp_SOURCES= $(smtpd_srcdir)/iobuf.c -smtp_SOURCES+= $(smtpd_srcdir)/ioev.c -smtp_SOURCES+= $(smtpd_srcdir)/log.c -smtp_SOURCES+= $(smtpd_srcdir)/smtp_client.c -smtp_SOURCES+= $(smtpd_srcdir)/smtpc.c -smtp_SOURCES+= $(smtpd_srcdir)/ssl.c -smtp_SOURCES+= $(smtpd_srcdir)/ssl_verify.c - -smtp_CFLAGS= -DIO_TLS - -AM_CPPFLAGS= -I$(top_srcdir)/smtpd \ - -I$(top_srcdir)/openbsd-compat -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif - -LIBCOMPAT= $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD= $(LIBCOMPAT) - -# need to define _GNU_SOURCE to get: -# EAI_NODATA defined -# {v,}asprintf -# setres{g,u}id -CFLAGS+= -D_GNU_SOURCE -CPPFLAGS= -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@ - -MANPAGES= smtp.1.out -MANPAGES_IN= $(smtpd_srcdir)/smtp.1 - -EXTRA_DIST= $(MANPAGES_IN) - -PATHSUBS= -e 's|/var/run/smtpd.sock|$(sockdir)/smtpd.sock|g' \ - -e 's|/usr/libexec|$(libexecdir)|g' \ - -e 's|/etc/mail/|$(sysconfdir)/|g' - -FIXPATHSCMD= $(SED) $(PATHSUBS) - - -$(MANPAGES): $(MANPAGES_IN) - manpage=$(smtpd_srcdir)/`echo $@ | sed 's/\.out$$//'`; \ - if test "$(MANTYPE)" = "man"; then \ - $(FIXPATHSCMD) $${manpage} | $(AWK) -f $(srcdir)/../mdoc2man.awk > $@; \ - else \ - $(FIXPATHSCMD) $${manpage} > $@; \ - fi - -install-exec-hook: $(CONFIGFILES) $(MANPAGES) - $(MKDIR_P) $(DESTDIR)$(mandir)/$(mansubdir)1 - $(INSTALL) -m 644 smtp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/smtp.1 - rm smtp.1.out - -uninstall-hook: - rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/smtp.1 - rmdir $(DESTDIR)$(mandir)/$(mansubdir)1 2> /dev/null || /bin/true diff --git a/foobar/portable/mk/smtpctl/Makefile.am b/foobar/portable/mk/smtpctl/Makefile.am deleted file mode 100644 index 3aac9bd7..00000000 --- a/foobar/portable/mk/smtpctl/Makefile.am +++ /dev/null @@ -1,99 +0,0 @@ -include $(top_srcdir)/mk/pathnames - -sbin_PROGRAMS= smtpctl - -smtpctl_SOURCES= $(smtpd_srcdir)/enqueue.c -smtpctl_SOURCES+= $(smtpd_srcdir)/parser.c -smtpctl_SOURCES+= $(smtpd_srcdir)/log.c -smtpctl_SOURCES+= $(smtpd_srcdir)/envelope.c -smtpctl_SOURCES+= $(smtpd_srcdir)/queue_backend.c -smtpctl_SOURCES+= $(smtpd_srcdir)/queue_fs.c -smtpctl_SOURCES+= $(smtpd_srcdir)/smtpctl.c -smtpctl_SOURCES+= $(smtpd_srcdir)/spfwalk.c -smtpctl_SOURCES+= $(smtpd_srcdir)/util.c -smtpctl_SOURCES+= $(smtpd_srcdir)/unpack_dns.c -smtpctl_SOURCES+= $(smtpd_srcdir)/compress_backend.c -smtpctl_SOURCES+= $(smtpd_srcdir)/compress_gzip.c -smtpctl_SOURCES+= $(smtpd_srcdir)/to.c -smtpctl_SOURCES+= $(smtpd_srcdir)/expand.c -smtpctl_SOURCES+= $(smtpd_srcdir)/tree.c -smtpctl_SOURCES+= $(smtpd_srcdir)/dict.c - -if HAVE_DB_API -smtpctl_SOURCES+= $(smtpd_srcdir)/config.c -smtpctl_SOURCES+= $(smtpd_srcdir)/parse.y -smtpctl_SOURCES+= $(smtpd_srcdir)/limit.c -smtpctl_SOURCES+= $(smtpd_srcdir)/table.c -smtpctl_SOURCES+= $(smtpd_srcdir)/table_static.c -smtpctl_SOURCES+= $(smtpd_srcdir)/table_db.c -smtpctl_SOURCES+= $(smtpd_srcdir)/table_getpwnam.c -smtpctl_SOURCES+= $(smtpd_srcdir)/table_proc.c -smtpctl_SOURCES+= $(smtpd_srcdir)/mailaddr.c -smtpctl_SOURCES+= $(smtpd_srcdir)/makemap.c -endif - -smtpctl_SOURCES+= $(smtpd_srcdir)/crypto.c - -smtpctl_CFLAGS= -DNO_IO -DCONFIG_MINIMUM -smtpctl_CFLAGS+= -DPATH_GZCAT=\"$(ZCAT)\" \ - -DPATH_ENCRYPT=\"$(pkglibexecdir)/encrypt\" - -AM_CPPFLAGS= -I$(top_srcdir)/smtpd \ - -I$(top_srcdir)/openbsd-compat -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif - -LIBCOMPAT= $(top_builddir)/openbsd-compat/libopenbsd.a - -LDADD= $(LIBCOMPAT) -if HAVE_DB_API -LDADD+= $(DB_LIB) -endif - -# need to define _GNU_SOURCE to get: -# EAI_NODATA defined -# {v,}asprintf -# setres{g,u}id -CFLAGS+= -D_GNU_SOURCE -CPPFLAGS= -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@ - -MANPAGES= smtpctl.8.out sendmail.8.out makemap.8.out newaliases.8.out -MANPAGES_IN= $(smtpd_srcdir)/smtpctl.8 $(smtpd_srcdir)/sendmail.8 $(smtpd_srcdir)/makemap.8 $(smtpd_srcdir)/newaliases.8 - -EXTRA_DIST= $(MANPAGES_IN) - -PATHSUBS= -e 's|/var/run/smtpd.sock|$(sockdir)/smtpd.sock|g' \ - -e 's|/usr/libexec|$(libexecdir)|g' \ - -e 's|/etc/mail/|$(sysconfdir)/|g' - -FIXPATHSCMD= $(SED) $(PATHSUBS) - -if NEED_LIBASR -AM_CPPFLAGS+= -I$(top_srcdir)/openbsd-compat/libasr -endif - -$(MANPAGES): $(MANPAGES_IN) - manpage=$(smtpd_srcdir)/`echo $@ | sed 's/\.out$$//'`; \ - if test "$(MANTYPE)" = "man"; then \ - $(FIXPATHSCMD) $${manpage} | $(AWK) -f $(srcdir)/../mdoc2man.awk > $@; \ - else \ - $(FIXPATHSCMD) $${manpage} > $@; \ - fi - -install-exec-hook: $(CONFIGFILES) $(MANPAGES) - $(MKDIR_P) $(DESTDIR)$(mandir)/$(mansubdir)8 - chgrp $(SMTPD_QUEUE_USER) $(DESTDIR)$(sbindir)/smtpctl || true - chmod 2555 $(DESTDIR)$(sbindir)/smtpctl || true - $(INSTALL) -m 644 smtpctl.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/smtpctl.8 - $(INSTALL) -m 644 sendmail.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sendmail.8 - $(INSTALL) -m 644 makemap.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/makemap.8 - $(INSTALL) -m 644 newaliases.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/newaliases.8 - rm smtpctl.8.out sendmail.8.out makemap.8.out newaliases.8.out - -uninstall-hook: - rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/smtpctl.8 - rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sendmail.8 - rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/makemap.8 - rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/newaliases.8 - rmdir $(DESTDIR)$(mandir)/$(mansubdir)8 2> /dev/null || /bin/true diff --git a/foobar/portable/mk/smtpd/Makefile.am b/foobar/portable/mk/smtpd/Makefile.am deleted file mode 100644 index bf7a483b..00000000 --- a/foobar/portable/mk/smtpd/Makefile.am +++ /dev/null @@ -1,194 +0,0 @@ -# In OpenBSD, smtpd's files are installed this way: -# -# /etc/mail/smtpd.conf -# /usr/sbin/smtpd -# -# -# For OpenSMTPD portable, here's where files are installed: -# (assuming PREFIX=/usr/local) -# -# /usr/local/etc/smtpd.conf -# /usr/local/sbin/smtpd - -include $(top_srcdir)/mk/pathnames - -sbin_PROGRAMS= smtpd - -smtpd_SOURCES= $(smtpd_srcdir)/aliases.c -smtpd_SOURCES+= $(smtpd_srcdir)/bounce.c -smtpd_SOURCES+= $(smtpd_srcdir)/ca.c -smtpd_SOURCES+= $(smtpd_srcdir)/cert.c -smtpd_SOURCES+= $(smtpd_srcdir)/compress_backend.c -smtpd_SOURCES+= $(smtpd_srcdir)/config.c -smtpd_SOURCES+= $(smtpd_srcdir)/control.c -smtpd_SOURCES+= $(smtpd_srcdir)/dict.c -smtpd_SOURCES+= $(smtpd_srcdir)/dns.c -smtpd_SOURCES+= $(smtpd_srcdir)/esc.c -smtpd_SOURCES+= $(smtpd_srcdir)/envelope.c -smtpd_SOURCES+= $(smtpd_srcdir)/expand.c -smtpd_SOURCES+= $(smtpd_srcdir)/forward.c -smtpd_SOURCES+= $(smtpd_srcdir)/iobuf.c -smtpd_SOURCES+= $(smtpd_srcdir)/ioev.c -smtpd_SOURCES+= $(smtpd_srcdir)/limit.c -smtpd_SOURCES+= $(smtpd_srcdir)/lka.c -smtpd_SOURCES+= $(smtpd_srcdir)/lka_filter.c -smtpd_SOURCES+= $(smtpd_srcdir)/lka_session.c -smtpd_SOURCES+= $(smtpd_srcdir)/log.c -smtpd_SOURCES+= $(smtpd_srcdir)/mda.c -smtpd_SOURCES+= $(smtpd_srcdir)/mda_mbox.c -smtpd_SOURCES+= $(smtpd_srcdir)/mda_unpriv.c -smtpd_SOURCES+= $(smtpd_srcdir)/mda_variables.c -smtpd_SOURCES+= $(smtpd_srcdir)/mproc.c -smtpd_SOURCES+= $(smtpd_srcdir)/mailaddr.c -smtpd_SOURCES+= $(smtpd_srcdir)/mta.c -smtpd_SOURCES+= $(smtpd_srcdir)/mta_session.c -smtpd_SOURCES+= $(smtpd_srcdir)/parse.y -smtpd_SOURCES+= $(smtpd_srcdir)/pony.c -smtpd_SOURCES+= $(smtpd_srcdir)/proxy.c -smtpd_SOURCES+= $(smtpd_srcdir)/queue.c -smtpd_SOURCES+= $(smtpd_srcdir)/queue_backend.c -smtpd_SOURCES+= $(smtpd_srcdir)/report_smtp.c -smtpd_SOURCES+= $(smtpd_srcdir)/resolver.c -smtpd_SOURCES+= $(smtpd_srcdir)/rfc5322.c -smtpd_SOURCES+= $(smtpd_srcdir)/ruleset.c -smtpd_SOURCES+= $(smtpd_srcdir)/runq.c -smtpd_SOURCES+= $(smtpd_srcdir)/scheduler.c -smtpd_SOURCES+= $(smtpd_srcdir)/scheduler_backend.c -smtpd_SOURCES+= $(smtpd_srcdir)/smtp.c -smtpd_SOURCES+= $(smtpd_srcdir)/smtp_session.c -smtpd_SOURCES+= $(smtpd_srcdir)/smtpd.c -smtpd_SOURCES+= $(smtpd_srcdir)/srs.c -smtpd_SOURCES+= $(smtpd_srcdir)/ssl.c -smtpd_SOURCES+= $(smtpd_srcdir)/ssl_smtpd.c -smtpd_SOURCES+= $(smtpd_srcdir)/ssl_verify.c -smtpd_SOURCES+= $(smtpd_srcdir)/stat_backend.c -smtpd_SOURCES+= $(smtpd_srcdir)/table.c -smtpd_SOURCES+= $(smtpd_srcdir)/to.c -smtpd_SOURCES+= $(smtpd_srcdir)/tree.c -smtpd_SOURCES+= $(smtpd_srcdir)/unpack_dns.c -smtpd_SOURCES+= $(smtpd_srcdir)/util.c -smtpd_SOURCES+= $(smtpd_srcdir)/waitq.c - -# backends -smtpd_SOURCES+= $(smtpd_srcdir)/crypto.c -smtpd_SOURCES+= $(smtpd_srcdir)/compress_gzip.c -if HAVE_DB_API -smtpd_SOURCES+= $(smtpd_srcdir)/table_db.c -endif -smtpd_SOURCES+= $(smtpd_srcdir)/table_getpwnam.c -smtpd_SOURCES+= $(smtpd_srcdir)/table_proc.c -smtpd_SOURCES+= $(smtpd_srcdir)/table_static.c -smtpd_SOURCES+= $(smtpd_srcdir)/queue_fs.c -smtpd_SOURCES+= $(smtpd_srcdir)/queue_null.c -smtpd_SOURCES+= $(smtpd_srcdir)/queue_proc.c -smtpd_SOURCES+= $(smtpd_srcdir)/queue_ram.c -smtpd_SOURCES+= $(smtpd_srcdir)/scheduler_null.c -smtpd_SOURCES+= $(smtpd_srcdir)/scheduler_proc.c -smtpd_SOURCES+= $(smtpd_srcdir)/scheduler_ramqueue.c -smtpd_SOURCES+= $(smtpd_srcdir)/stat_ramstat.c - - -smtpd_CFLAGS= -DIO_TLS -smtpd_CFLAGS+= -DCA_FILE=\"$(CA_FILE)\" - -AM_CPPFLAGS= -I$(smtpd_srcdir) \ - -I$(compat_srcdir) -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif -if !SUPPORT_PATHS_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/paths_h -endif - -LIBCOMPAT= $(top_builddir)/openbsd-compat/libopenbsd.a -if NEED_LIBASR -AM_CPPFLAGS+= -I$(top_srcdir)/openbsd-compat/libasr -endif - -LDADD= $(LIBCOMPAT) $(DB_LIB) $(ASR_LIB) - -# need to define _GNU_SOURCE to get: -# EAI_NODATA defined -# {v,}asprintf -# setres{g,u}id -CFLAGS+= -D_GNU_SOURCE -DNEED_EVENT_ASR_RUN -CPPFLAGS= -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@ - -MANPAGES= aliases.5.out forward.5.out smtpd.8.out \ - smtpd.conf.5.out table.5.out - -MANPAGES_IN= $(smtpd_srcdir)/aliases.5 -MANPAGES_IN+= $(smtpd_srcdir)/forward.5 -MANPAGES_IN+= $(smtpd_srcdir)/smtpd.8 -MANPAGES_IN+= $(smtpd_srcdir)/smtpd.conf.5 -MANPAGES_IN+= $(smtpd_srcdir)/table.5 - -CONFIGFILES= smtpd.conf.out -CONFIGFILES_IN= $(smtpd_srcdir)/smtpd.conf - -EXTRA_DIST= $(CONFIGFILES_IN) $(MANPAGES_IN) - - -EXTRA_DIST+= $(smtpd_srcdir)/smtpd.h -EXTRA_DIST+= $(smtpd_srcdir)/smtpd-api.h -EXTRA_DIST+= $(smtpd_srcdir)/smtpd-defines.h -EXTRA_DIST+= $(smtpd_srcdir)/ioev.h -EXTRA_DIST+= $(smtpd_srcdir)/iobuf.h -EXTRA_DIST+= $(smtpd_srcdir)/log.h -EXTRA_DIST+= $(smtpd_srcdir)/ssl.h -EXTRA_DIST+= $(smtpd_srcdir)/parser.h - -EXTRA_DIST+= $(backends_srcdir)/queue_utils.h -EXTRA_DIST+= $(filters_srcdir)/asr_event.h - -PATHSUBS= -e 's|/etc/mail/|$(sysconfdir)/|g' \ - -e 's|/var/run/smtpd.sock|$(sockdir)/smtpd.sock|g' \ - -e 's|/usr/local/libexec/smtpd/|$(pkglibexecdir)|g' - -FIXPATHSCMD= $(SED) $(PATHSUBS) - -$(MANPAGES): $(MANPAGES_IN) - manpage=$(smtpd_srcdir)/`echo $@ | sed 's/\.out$$//'`; \ - if test "$(MANTYPE)" = "man"; then \ - $(FIXPATHSCMD) $${manpage} | $(AWK) -f $(srcdir)/../mdoc2man.awk > $@; \ - else \ - $(FIXPATHSCMD) $${manpage} > $@; \ - fi - -$(CONFIGFILES): $(CONFIGFILES_IN) - conffile=$(smtpd_srcdir)/`echo $@ | sed 's/.out$$//'`; \ - $(CAT) $(srcdir)/$${conffile} > $@ - - -# smtpd.conf -# newaliases makemap -install-exec-hook: $(CONFIGFILES) $(MANPAGES) - $(MKDIR_P) $(DESTDIR)$(sysconfdir) - $(MKDIR_P) $(DESTDIR)$(bindir) - $(MKDIR_P) $(DESTDIR)$(mandir)/$(mansubdir)5 - $(MKDIR_P) $(DESTDIR)$(mandir)/$(mansubdir)8 - - @if [ ! -f $(DESTDIR)$(sysconfdir)/smtpd.conf ]; then \ - $(INSTALL) -m 644 smtpd.conf.out $(DESTDIR)$(sysconfdir)/smtpd.conf; \ - else \ - echo "$(DESTDIR)$(sysconfdir)/smtpd.conf already exists, install will not overwrite"; \ - fi - - $(INSTALL) -m 644 aliases.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/aliases.5 - $(INSTALL) -m 644 forward.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/forward.5 - $(INSTALL) -m 644 table.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/table.5 - $(INSTALL) -m 644 smtpd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/smtpd.8 - $(INSTALL) -m 644 smtpd.conf.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/smtpd.conf.5 - rm aliases.5.out forward.5.out table.5.out \ - smtpd.8.out smtpd.conf.5.out smtpd.conf.out - -uninstall-hook: -# XXX to make "make distcheck" happy we need to rm smtpd.conf -# rm $(DESTDIR)$(sysconfdir)/smtpd.conf - rm -f $(DESTDIR)$(mandir)/$(mansubdir)5/aliases.5 \ - $(DESTDIR)$(mandir)/$(mansubdir)5/forward.5 \ - $(DESTDIR)$(mandir)/$(mansubdir)5/table.5 \ - $(DESTDIR)$(mandir)/$(mansubdir)5/smtpd.conf.5 \ - $(DESTDIR)$(mandir)/$(mansubdir)8/smtpd.8 - rmdir $(DESTDIR)$(mandir)/$(mansubdir)5 \ - $(DESTDIR)$(mandir)/$(mansubdir)8 2> /dev/null || /bin/true diff --git a/foobar/portable/openbsd-compat/Makefile.am b/foobar/portable/openbsd-compat/Makefile.am deleted file mode 100644 index db1e93fa..00000000 --- a/foobar/portable/openbsd-compat/Makefile.am +++ /dev/null @@ -1,231 +0,0 @@ -noinst_LIBRARIES = libopenbsd.a - -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/smtpd -I$(top_srcdir)/openbsd-compat - -libopenbsd_a_SOURCES = empty.c - -if NEED_LIBASR -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/libasr - -libopenbsd_a_SOURCES += libasr/asr.c -libopenbsd_a_SOURCES += libasr/asr_debug.c -libopenbsd_a_SOURCES += libasr/asr_compat.c -libopenbsd_a_SOURCES += libasr/asr_utils.c -libopenbsd_a_SOURCES += libasr/getaddrinfo_async.c -libopenbsd_a_SOURCES += libasr/gethostnamadr_async.c -libopenbsd_a_SOURCES += libasr/getnameinfo_async.c -libopenbsd_a_SOURCES += libasr/getnetnamadr_async.c -libopenbsd_a_SOURCES += libasr/res_search_async.c -libopenbsd_a_SOURCES += libasr/res_send_async.c - -include_HEADERS = libasr/asr.h -endif - - - -if NEED_PROGNAME -libopenbsd_a_SOURCES += progname.c -endif - -if NEED_ARC4RANDOM -libopenbsd_a_SOURCES += arc4random.c -endif - -if NEED_BASE64 -libopenbsd_a_SOURCES += base64.c -endif - -if NEED_BASENAME -libopenbsd_a_SOURCES += basename.c -endif - -if NEED_CLOCK_GETTIME -libopenbsd_a_SOURCES += clock_gettime.c -endif - -if NEED_CLOSEFROM -libopenbsd_a_SOURCES += closefrom.c -endif - -if NEED_CRYPT_CHECKPASS -libopenbsd_a_SOURCES += crypt_checkpass.c -endif - -if NEED_DAEMON -libopenbsd_a_SOURCES += daemon.c -endif - -if NEED_DIRNAME -libopenbsd_a_SOURCES += dirname.c -endif - -if NEED_ERR -libopenbsd_a_SOURCES += bsd-err.c -endif - -if NEED_ERRC -libopenbsd_a_SOURCES += errc.c -endif - -if NEED_EVENT_ASR_RUN -libopenbsd_a_SOURCES += event_asr_run.c -endif - -if NEED_EXPLICIT_BZERO -libopenbsd_a_SOURCES += explicit_bzero.c -endif - -if NEED_FGETLN -libopenbsd_a_SOURCES += fgetln.c -endif - -if NEED_FMT_SCALED -libopenbsd_a_SOURCES += fmt_scaled.c -endif - -if NEED_FPARSELN -libopenbsd_a_SOURCES += fparseln.c -endif - -if NEED_FREEZERO -libopenbsd_a_SOURCES += freezero.c -endif - -if NEED_GETOPT -libopenbsd_a_SOURCES += getopt.c -endif - -if NEED_GETPEEREID -libopenbsd_a_SOURCES += getpeereid.c -endif - -if NEED_IMSG -libopenbsd_a_SOURCES += imsg.c -libopenbsd_a_SOURCES += imsg-buffer.c -endif - -if NEED_INET_NET_PTON -libopenbsd_a_SOURCES += inet_net_pton.c -endif - -if NEED_NANOSLEEP -libopenbsd_a_SOURCES += nanosleep.c -endif - -if NEED_PIDFILE -libopenbsd_a_SOURCES += pidfile.c -endif - -if NEED_REALLOCARRAY -libopenbsd_a_SOURCES += reallocarray.c -endif - -if NEED_RECALLOCARRAY -libopenbsd_a_SOURCES += recallocarray.c -endif - -if NEED_RES_HNOK -libopenbsd_a_SOURCES += res_hnok.c -endif - -if NEED_RES_RANDOMID -libopenbsd_a_SOURCES += res_randomid.c -endif - -if NEED_SETPROCTITLE -libopenbsd_a_SOURCES += setproctitle.c -endif - -if NEED_SETRESGID -libopenbsd_a_SOURCES += setresgid.c -endif - -if NEED_SETRESUID -libopenbsd_a_SOURCES += setresuid.c -endif - -if NEED_SETEGID -libopenbsd_a_SOURCES += setegid.c -endif - -if NEED_SETEUID -libopenbsd_a_SOURCES += seteuid.c -endif - -if NEED_SIGNAL -libopenbsd_a_SOURCES += signal.c -endif - -if NEED_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM -libopenbsd_a_SOURCES += SSL_CTX_use_certificate_chain_mem.c -endif - -if NEED_STRERROR -libopenbsd_a_SOURCES += strerror.c -endif - -if NEED_STRLCAT -libopenbsd_a_SOURCES += strlcat.c -endif - -if NEED_STRLCPY -libopenbsd_a_SOURCES += strlcpy.c -endif - -if NEED_STRMODE -libopenbsd_a_SOURCES += strmode.c -endif - -if NEED_STRSEP -libopenbsd_a_SOURCES += strsep.c -endif - -if NEED_STRTONUM -libopenbsd_a_SOURCES += strtonum.c -endif - -if NEED_STRNDUP -libopenbsd_a_SOURCES += strndup.c -endif - -if NEED_STRNLEN -libopenbsd_a_SOURCES += strnlen.c -endif - -if NEED_USLEEP -libopenbsd_a_SOURCES += usleep.c -endif - -if NEED_VIS -libopenbsd_a_SOURCES += vis.c -endif - -if NEED_WAITPID -libopenbsd_a_SOURCES += bsd-waitpid.c -endif - - - -EXTRA_DIST = base64.h -EXTRA_DIST += bsd-misc.h -EXTRA_DIST += bsd-waitpid.h -EXTRA_DIST += chacha_private.h -EXTRA_DIST += defines.h -EXTRA_DIST += entropy.h -EXTRA_DIST += imsg.h -EXTRA_DIST += includes.h -EXTRA_DIST += log.h -EXTRA_DIST += openbsd-compat.h -EXTRA_DIST += sys/queue.h -EXTRA_DIST += sys/tree.h -EXTRA_DIST += bsd-vis.h - -if NEED_LIBASR -EXTRA_DIST += libasr/asr_compat.h -EXTRA_DIST += libasr/asr_private.h -endif - - -if !NEED_ERR_H -AM_CPPFLAGS += -I$(top_srcdir)/openbsd-compat/err_h -endif diff --git a/foobar/portable/openbsd-compat/NOTES b/foobar/portable/openbsd-compat/NOTES deleted file mode 100644 index 42aefc7d..00000000 --- a/foobar/portable/openbsd-compat/NOTES +++ /dev/null @@ -1,37 +0,0 @@ -List of files and where they come from - -arc4random.c portable openssh -base64.{c,h} portable openssh -basename.c portable openssh -bsd-closefrom.c portable openssh -bsd-getpeereid.c portable openssh -bsd-waitpid.{c,h} portable openssh -clock_gettime.c handmade -daemon.c portable openssh -defines.h portable openssh -dirname.c portable openssh -entropy.{c,h} portable openssh -event_asr_run.c end of /usr/src/lib/libevent/event.c -fgetln.c part of /usr/src/usr.bin/make/util.c -fmt_scaled.c portable openssh -fparseln.c part of /usr/src/lib/libutil/fparseln.c -getopt.c portable openssh -imsg-buffer.c part of /usr/src/libutil/imsg-buffer.c -imsg.{c,h} part of /usr/src/libutil/imsg.c -includes.h portable openssh -log.h portable openssh -mktemp.c portable openssh -openbsd-compat.h portable openssh -pidfile.c /usr/src/lib/libutil/pidfile.c -pw_dup.c /usr/src/lib/libc/gen/pw_dup.c -reallocarray.c /usr/src/lib/libc/stdlib/reallocarray.c -setproctitle.c portable openssh -strlcat.c portable openssh -strlcpy.c portable openssh -strmode.c portable openssh -strsep.c portable openssh -strtonum.c portable openssh -sys/queue.h portable openssh -sys/tree.h portable openssh -vis.{c,h} portable openssh -xmalloc.{c,h} portable openssh diff --git a/foobar/portable/openbsd-compat/SSL_CTX_use_certificate_chain_mem.c b/foobar/portable/openbsd-compat/SSL_CTX_use_certificate_chain_mem.c deleted file mode 100644 index 3a47ff0e..00000000 --- a/foobar/portable/openbsd-compat/SSL_CTX_use_certificate_chain_mem.c +++ /dev/null @@ -1,174 +0,0 @@ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* - * SSL operations needed when running in a privilege separated environment. - * Adapted from openssl's ssl_rsa.c by Pierre-Yves Ritschard . - */ - -#include "includes.h" - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "log.h" -#include "ssl.h" - -#define SSL_ECDH_CURVE "prime256v1" - -/* - * Read a bio that contains our certificate in "PEM" format, - * possibly followed by a sequence of CA certificates that should be - * sent to the peer in the Certificate message. - */ -static int -ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in) -{ - int ret = 0; - X509 *x = NULL; - - ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */ - - x = PEM_read_bio_X509_AUX(in, NULL, SSL_CTX_get_default_passwd_cb(ctx), - SSL_CTX_get_default_passwd_cb_userdata(ctx)); - if (x == NULL) { - SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_PEM_LIB); - goto end; - } - - ret = SSL_CTX_use_certificate(ctx, x); - - if (ERR_peek_error() != 0) - ret = 0; - /* Key/certificate mismatch doesn't imply ret==0 ... */ - if (ret) { - /* - * If we could set up our certificate, now proceed to - * the CA certificates. - */ - X509 *ca; - STACK_OF(X509) *chain; - int r; - unsigned long err; - - SSL_CTX_get_extra_chain_certs_only(ctx, &chain); - if (chain != NULL) { - sk_X509_pop_free(chain, X509_free); - SSL_CTX_clear_extra_chain_certs(ctx); - } - - while ((ca = PEM_read_bio_X509(in, NULL, - SSL_CTX_get_default_passwd_cb(ctx), - SSL_CTX_get_default_passwd_cb_userdata(ctx))) != NULL) { - r = SSL_CTX_add_extra_chain_cert(ctx, ca); - if (!r) { - X509_free(ca); - ret = 0; - goto end; - } - /* - * Note that we must not free r if it was successfully - * added to the chain (while we must free the main - * certificate, since its reference count is increased - * by SSL_CTX_use_certificate). - */ - } - - /* When the while loop ends, it's usually just EOF. */ - err = ERR_peek_last_error(); - if (ERR_GET_LIB(err) == ERR_LIB_PEM && - ERR_GET_REASON(err) == PEM_R_NO_START_LINE) - ERR_clear_error(); - else - ret = 0; /* some real error */ - } - -end: - if (x != NULL) - X509_free(x); - return (ret); -} - -int -SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len) -{ - BIO *in; - int ret = 0; - - in = BIO_new_mem_buf(buf, len); - if (in == NULL) { - SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_BUF_LIB); - goto end; - } - - ret = ssl_ctx_use_certificate_chain_bio(ctx, in); - -end: - BIO_free(in); - return (ret); -} diff --git a/foobar/portable/openbsd-compat/arc4random.c b/foobar/portable/openbsd-compat/arc4random.c deleted file mode 100644 index f5cda877..00000000 --- a/foobar/portable/openbsd-compat/arc4random.c +++ /dev/null @@ -1,246 +0,0 @@ -/* OPENBSD ORIGINAL: lib/libc/crypto/arc4random.c */ - -/* $OpenBSD: arc4random.c,v 1.25 2013/10/01 18:34:57 markus Exp $ */ - -/* - * Copyright (c) 1996, David Mazieres - * Copyright (c) 2008, Damien Miller - * Copyright (c) 2013, Markus Friedl - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * ChaCha based random number generator for OpenBSD. - */ - -#include "includes.h" - -#include -#include -#include -#include - -#include -#include - -#include "log.h" - -#define KEYSTREAM_ONLY -#include "chacha_private.h" - -#ifdef __GNUC__ -#define inline __inline -#else /* !__GNUC__ */ -#define inline -#endif /* !__GNUC__ */ - -/* OpenSSH isn't multithreaded */ -#define _ARC4_LOCK() -#define _ARC4_UNLOCK() - -#define KEYSZ 32 -#define IVSZ 8 -#define BLOCKSZ 64 -#define RSBUFSZ (16*BLOCKSZ) -static int rs_initialized; -static pid_t rs_stir_pid; -static chacha_ctx rs; /* chacha context for random keystream */ -static u_char rs_buf[RSBUFSZ]; /* keystream blocks */ -static size_t rs_have; /* valid bytes at end of rs_buf */ -static size_t rs_count; /* bytes till reseed */ - -static inline void _rs_rekey(u_char *dat, size_t datlen); - -static inline void -_rs_init(u_char *buf, size_t n) -{ - if (n < KEYSZ + IVSZ) - return; - chacha_keysetup(&rs, buf, KEYSZ * 8, 0); - chacha_ivsetup(&rs, buf + KEYSZ); -} - -static void -_rs_stir(void) -{ - u_char rnd[KEYSZ + IVSZ]; - - if (RAND_bytes(rnd, sizeof(rnd)) <= 0) - fatal("Couldn't obtain random bytes (error %ld)", - ERR_get_error()); - - if (!rs_initialized) { - rs_initialized = 1; - _rs_init(rnd, sizeof(rnd)); - } else - _rs_rekey(rnd, sizeof(rnd)); - memset(rnd, 0, sizeof(rnd)); - - /* invalidate rs_buf */ - rs_have = 0; - memset(rs_buf, 0, RSBUFSZ); - - rs_count = 1600000; -} - -static inline void -_rs_stir_if_needed(size_t len) -{ - pid_t pid = getpid(); - - if (rs_count <= len || !rs_initialized || rs_stir_pid != pid) { - rs_stir_pid = pid; - _rs_stir(); - } else - rs_count -= len; -} - -static inline void -_rs_rekey(u_char *dat, size_t datlen) -{ -#ifndef KEYSTREAM_ONLY - memset(rs_buf, 0,RSBUFSZ); -#endif - /* fill rs_buf with the keystream */ - chacha_encrypt_bytes(&rs, rs_buf, rs_buf, RSBUFSZ); - /* mix in optional user provided data */ - if (dat) { - size_t i, m; - - m = MIN(datlen, KEYSZ + IVSZ); - for (i = 0; i < m; i++) - rs_buf[i] ^= dat[i]; - } - /* immediately reinit for backtracking resistance */ - _rs_init(rs_buf, KEYSZ + IVSZ); - memset(rs_buf, 0, KEYSZ + IVSZ); - rs_have = RSBUFSZ - KEYSZ - IVSZ; -} - -static inline void -_rs_random_buf(void *_buf, size_t n) -{ - u_char *buf = (u_char *)_buf; - size_t m; - - _rs_stir_if_needed(n); - while (n > 0) { - if (rs_have > 0) { - m = MIN(n, rs_have); - memcpy(buf, rs_buf + RSBUFSZ - rs_have, m); - memset(rs_buf + RSBUFSZ - rs_have, 0, m); - buf += m; - n -= m; - rs_have -= m; - } - if (rs_have == 0) - _rs_rekey(NULL, 0); - } -} - -static inline void -_rs_random_u32(uint32_t *val) -{ - _rs_stir_if_needed(sizeof(*val)); - if (rs_have < sizeof(*val)) - _rs_rekey(NULL, 0); - memcpy(val, rs_buf + RSBUFSZ - rs_have, sizeof(*val)); - memset(rs_buf + RSBUFSZ - rs_have, 0, sizeof(*val)); - rs_have -= sizeof(*val); - return; -} - -void -arc4random_stir(void) -{ - _ARC4_LOCK(); - _rs_stir(); - _ARC4_UNLOCK(); -} - -void -arc4random_addrandom(u_char *dat, int datlen) -{ - int m; - - _ARC4_LOCK(); - if (!rs_initialized) - _rs_stir(); - while (datlen > 0) { - m = MIN(datlen, KEYSZ + IVSZ); - _rs_rekey(dat, m); - dat += m; - datlen -= m; - } - _ARC4_UNLOCK(); -} - -uint32_t -arc4random(void) -{ - uint32_t val; - - _ARC4_LOCK(); - _rs_random_u32(&val); - _ARC4_UNLOCK(); - return val; -} - -/* - * If we are providing arc4random, then we can provide a more efficient - * arc4random_buf(). - */ -void -arc4random_buf(void *buf, size_t n) -{ - _ARC4_LOCK(); - _rs_random_buf(buf, n); - _ARC4_UNLOCK(); -} - -/* - * Calculate a uniformly distributed random number less than upper_bound - * avoiding "modulo bias". - * - * Uniformity is achieved by generating new random numbers until the one - * returned is outside the range [0, 2**32 % upper_bound). This - * guarantees the selected random number will be inside - * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) - * after reduction modulo upper_bound. - */ -uint32_t -arc4random_uniform(uint32_t upper_bound) -{ - uint32_t r, min; - - if (upper_bound < 2) - return 0; - - /* 2**32 % x == (2**32 - x) % x */ - min = -upper_bound % upper_bound; - - /* - * This could theoretically loop forever but each retry has - * p > 0.5 (worst case, usually far better) of selecting a - * number inside the range we need, so it should rarely need - * to re-roll. - */ - for (;;) { - r = arc4random(); - if (r >= min) - break; - } - - return r % upper_bound; -} diff --git a/foobar/portable/openbsd-compat/base64.c b/foobar/portable/openbsd-compat/base64.c deleted file mode 100644 index a3c5782b..00000000 --- a/foobar/portable/openbsd-compat/base64.c +++ /dev/null @@ -1,306 +0,0 @@ -/* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * Portions Copyright (c) 1995 by International Business Machines, Inc. - * - * International Business Machines, Inc. (hereinafter called IBM) grants - * permission under its copyrights to use, copy, modify, and distribute this - * Software with or without fee, provided that the above copyright notice and - * all paragraphs of this notice appear in all copies, and that the name of IBM - * not be used in connection with the marketing of any product incorporating - * the Software or modifications thereof, without specific, written prior - * permission. - * - * To the extent it has a right to do so, IBM grants an immunity from suit - * under its patents, if any, for the use, sale or manufacture of products to - * the extent that such products are used for performing Domain Name System - * dynamic updates in TCP/IP networks by means of the Software. No immunity is - * granted for any product per se or for any other function of any product. - * - * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, - * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN - * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -/* OPENBSD ORIGINAL: lib/libc/net/base64.c */ - -#include "includes.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include "base64.h" - -static const char Base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const char Pad64 = '='; - -/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) - The following encoding technique is taken from RFC 1521 by Borenstein - and Freed. It is reproduced here in a slightly edited form for - convenience. - - A 65-character subset of US-ASCII is used, enabling 6 bits to be - represented per printable character. (The extra 65th character, "=", - is used to signify a special processing function.) - - The encoding process represents 24-bit groups of input bits as output - strings of 4 encoded characters. Proceeding from left to right, a - 24-bit input group is formed by concatenating 3 8-bit input groups. - These 24 bits are then treated as 4 concatenated 6-bit groups, each - of which is translated into a single digit in the base64 alphabet. - - Each 6-bit group is used as an index into an array of 64 printable - characters. The character referenced by the index is placed in the - output string. - - Table 1: The Base64 Alphabet - - Value Encoding Value Encoding Value Encoding Value Encoding - 0 A 17 R 34 i 51 z - 1 B 18 S 35 j 52 0 - 2 C 19 T 36 k 53 1 - 3 D 20 U 37 l 54 2 - 4 E 21 V 38 m 55 3 - 5 F 22 W 39 n 56 4 - 6 G 23 X 40 o 57 5 - 7 H 24 Y 41 p 58 6 - 8 I 25 Z 42 q 59 7 - 9 J 26 a 43 r 60 8 - 10 K 27 b 44 s 61 9 - 11 L 28 c 45 t 62 + - 12 M 29 d 46 u 63 / - 13 N 30 e 47 v - 14 O 31 f 48 w (pad) = - 15 P 32 g 49 x - 16 Q 33 h 50 y - - Special processing is performed if fewer than 24 bits are available - at the end of the data being encoded. A full encoding quantum is - always completed at the end of a quantity. When fewer than 24 input - bits are available in an input group, zero bits are added (on the - right) to form an integral number of 6-bit groups. Padding at the - end of the data is performed using the '=' character. - - Since all base64 input is an integral number of octets, only the - ------------------------------------------------- - following cases can arise: - - (1) the final quantum of encoding input is an integral - multiple of 24 bits; here, the final unit of encoded - output will be an integral multiple of 4 characters - with no "=" padding, - (2) the final quantum of encoding input is exactly 8 bits; - here, the final unit of encoded output will be two - characters followed by two "=" padding characters, or - (3) the final quantum of encoding input is exactly 16 bits; - here, the final unit of encoded output will be three - characters followed by one "=" padding character. - */ - -int -b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) -{ - size_t datalength = 0; - u_char input[3]; - u_char output[4]; - u_int i; - - while (2 < srclength) { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; - } - - /* Now we worry about padding. */ - if (0 != srclength) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; i++) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; - else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; - } - if (datalength >= targsize) - return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return (datalength); -} - -/* skips all whitespace anywhere. - converts characters, four at a time, starting at (or after) - src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. - */ - -int -b64_pton(char const *src, u_char *target, size_t targsize) -{ - u_int tarindex, state; - int ch; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ - continue; - - if (ch == Pad64) - break; - - pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ - return (-1); - - switch (state) { - case 0: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return (-1); - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && target[tarindex] != 0) - return (-1); - } - } else { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return (-1); - } - - return (tarindex); -} diff --git a/foobar/portable/openbsd-compat/base64.h b/foobar/portable/openbsd-compat/base64.h deleted file mode 100644 index 732c6b3f..00000000 --- a/foobar/portable/openbsd-compat/base64.h +++ /dev/null @@ -1,65 +0,0 @@ -/* $Id: base64.h,v 1.6 2003/08/29 16:59:52 mouring Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * Portions Copyright (c) 1995 by International Business Machines, Inc. - * - * International Business Machines, Inc. (hereinafter called IBM) grants - * permission under its copyrights to use, copy, modify, and distribute this - * Software with or without fee, provided that the above copyright notice and - * all paragraphs of this notice appear in all copies, and that the name of IBM - * not be used in connection with the marketing of any product incorporating - * the Software or modifications thereof, without specific, written prior - * permission. - * - * To the extent it has a right to do so, IBM grants an immunity from suit - * under its patents, if any, for the use, sale or manufacture of products to - * the extent that such products are used for performing Domain Name System - * dynamic updates in TCP/IP networks by means of the Software. No immunity is - * granted for any product per se or for any other function of any product. - * - * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, - * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN - * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -#ifndef _BSD_BASE64_H -#define _BSD_BASE64_H - -#include "includes.h" - -#ifndef HAVE___B64_NTOP -# ifndef HAVE_B64_NTOP -int b64_ntop(u_char const *src, size_t srclength, char *target, - size_t targsize); -# endif /* !HAVE_B64_NTOP */ -# define __b64_ntop(a,b,c,d) b64_ntop(a,b,c,d) -#endif /* HAVE___B64_NTOP */ - -#ifndef HAVE___B64_PTON -# ifndef HAVE_B64_PTON -int b64_pton(char const *src, u_char *target, size_t targsize); -# endif /* !HAVE_B64_PTON */ -# define __b64_pton(a,b,c) b64_pton(a,b,c) -#endif /* HAVE___B64_PTON */ - -#endif /* _BSD_BASE64_H */ diff --git a/foobar/portable/openbsd-compat/basename.c b/foobar/portable/openbsd-compat/basename.c deleted file mode 100644 index ffa5c898..00000000 --- a/foobar/portable/openbsd-compat/basename.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $OpenBSD: basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $ */ - -/* - * Copyright (c) 1997, 2004 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* OPENBSD ORIGINAL: lib/libc/gen/basename.c */ - -#include "includes.h" -#ifndef HAVE_BASENAME -#include -#include - -char * -basename(const char *path) -{ - static char bname[MAXPATHLEN]; - size_t len; - const char *endp, *startp; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - bname[0] = '.'; - bname[1] = '\0'; - return (bname); - } - - /* Strip any trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* All slashes becomes "/" */ - if (endp == path && *endp == '/') { - bname[0] = '/'; - bname[1] = '\0'; - return (bname); - } - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - len = endp - startp + 1; - if (len >= sizeof(bname)) { - errno = ENAMETOOLONG; - return (NULL); - } - memcpy(bname, startp, len); - bname[len] = '\0'; - return (bname); -} - -#endif /* !defined(HAVE_BASENAME) */ diff --git a/foobar/portable/openbsd-compat/bsd-err.c b/foobar/portable/openbsd-compat/bsd-err.c deleted file mode 100644 index a7823fad..00000000 --- a/foobar/portable/openbsd-compat/bsd-err.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2015 Tim Rice - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include - -extern char *__progname; - -void -err(int r, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - vfprintf(stderr, fmt, args); - fprintf(stderr, ": "); - } - fprintf(stderr, "%s\n", strerror(errno)); - va_end(args); - exit(r); -} - -void -errx(int r, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) - vfprintf(stderr, fmt, args); - fprintf(stderr, "\n"); - va_end(args); - exit(r); -} - -void -warn(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - vfprintf(stderr, fmt, args); - fprintf(stderr, ": "); - } - fprintf(stderr, "%s\n", strerror(errno)); - va_end(args); -} - -void -warnx(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) - vfprintf(stderr, fmt, args); - fprintf(stderr, "\n"); - va_end(args); -} diff --git a/foobar/portable/openbsd-compat/bsd-err.h b/foobar/portable/openbsd-compat/bsd-err.h deleted file mode 100644 index f75d0eb4..00000000 --- a/foobar/portable/openbsd-compat/bsd-err.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Public domain - * err.h compatibility shim - */ - -#ifndef HAVE_ERR_H - -#ifndef LIBCRYPTOCOMPAT_ERR_H -#define LIBCRYPTOCOMPAT_ERR_H - -#include -#include -#include - -#define err(exitcode, format, args...) \ - errx(exitcode, format ": %s", ## args, strerror(errno)) - -#define errx(exitcode, format, args...) \ - do { warnx(format, ## args); exit(exitcode); } while (0) - -#define warn(format, args...) \ - warnx(format ": %s", ## args, strerror(errno)) - -#define warnx(format, args...) \ - fprintf(stderr, format "\n", ## args) - -#endif - -#endif diff --git a/foobar/portable/openbsd-compat/bsd-misc.h b/foobar/portable/openbsd-compat/bsd-misc.h deleted file mode 100644 index c638462d..00000000 --- a/foobar/portable/openbsd-compat/bsd-misc.h +++ /dev/null @@ -1,24 +0,0 @@ -/* $Id: bsd-misc.h,v 1.25 2013/08/04 11:48:41 dtucker Exp $ */ - -/* - * Copyright (c) 1999-2004 Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _BSD_MISC_H -#define _BSD_MISC_H - -#include "includes.h" - -#endif /* _BSD_MISC_H */ diff --git a/foobar/portable/openbsd-compat/bsd-vis.h b/foobar/portable/openbsd-compat/bsd-vis.h deleted file mode 100644 index d1286c99..00000000 --- a/foobar/portable/openbsd-compat/bsd-vis.h +++ /dev/null @@ -1,95 +0,0 @@ -/* $OpenBSD: vis.h,v 1.11 2005/08/09 19:38:31 millert Exp $ */ -/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ - -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)vis.h 5.9 (Berkeley) 4/3/91 - */ - -/* OPENBSD ORIGINAL: include/vis.h */ - -#include "includes.h" -#if !defined(HAVE_STRNVIS) || defined(BROKEN_STRNVIS) - -#ifndef _VIS_H_ -#define _VIS_H_ - -#include -#include - -/* - * to select alternate encoding format - */ -#define VIS_OCTAL 0x01 /* use octal \ddd format */ -#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ - -/* - * to alter set of characters encoded (default is to encode all - * non-graphic except space, tab, and newline). - */ -#define VIS_SP 0x04 /* also encode space */ -#define VIS_TAB 0x08 /* also encode tab */ -#define VIS_NL 0x10 /* also encode newline */ -#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) -#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ - -/* - * other - */ -#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ -#define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */ - -/* - * unvis return codes - */ -#define UNVIS_VALID 1 /* character valid */ -#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ -#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ -#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ -#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ - -/* - * unvis flags - */ -#define UNVIS_END 1 /* no more characters */ - -char *vis(char *, int, int, int); -int strvis(char *, const char *, int); -int strnvis(char *, const char *, size_t, int) - __attribute__ ((__bounded__(__string__,1,3))); -int strvisx(char *, const char *, size_t, int) - __attribute__ ((__bounded__(__string__,1,3))); -int strunvis(char *, const char *); -int unvis(char *, char, int *, int); -ssize_t strnunvis(char *, const char *, size_t) - __attribute__ ((__bounded__(__string__,1,3))); - -#endif /* !_VIS_H_ */ - -#endif /* !HAVE_STRNVIS || BROKEN_STRNVIS */ diff --git a/foobar/portable/openbsd-compat/bsd-waitpid.c b/foobar/portable/openbsd-compat/bsd-waitpid.c deleted file mode 100644 index 3ef68a53..00000000 --- a/foobar/portable/openbsd-compat/bsd-waitpid.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2000 Ben Lindstrom. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "includes.h" - -#include -#include -#include "bsd-waitpid.h" - -pid_t -waitpid(int pid, int *stat_loc, int options) -{ - union wait statusp; - pid_t wait_pid; - - if (pid <= 0) { - if (pid != -1) { - errno = EINVAL; - return (-1); - } - /* wait4() wants pid=0 for indiscriminate wait. */ - pid = 0; - } - wait_pid = wait4(pid, &statusp, options, NULL); - if (stat_loc) - *stat_loc = (int) statusp.w_status; - - return (wait_pid); -} diff --git a/foobar/portable/openbsd-compat/bsd-waitpid.h b/foobar/portable/openbsd-compat/bsd-waitpid.h deleted file mode 100644 index 2d853db6..00000000 --- a/foobar/portable/openbsd-compat/bsd-waitpid.h +++ /dev/null @@ -1,51 +0,0 @@ -/* $Id: bsd-waitpid.h,v 1.5 2003/08/29 16:59:52 mouring Exp $ */ - -/* - * Copyright (c) 2000 Ben Lindstrom. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef _BSD_WAITPID_H -#define _BSD_WAITPID_H - -#ifndef HAVE_WAITPID -/* Clean out any potental issues */ -#undef WIFEXITED -#undef WIFSTOPPED -#undef WIFSIGNALED - -/* Define required functions to mimic a POSIX look and feel */ -#define _W_INT(w) (*(int*)&(w)) /* convert union wait to int */ -#define WIFEXITED(w) (!((_W_INT(w)) & 0377)) -#define WIFSTOPPED(w) ((_W_INT(w)) & 0100) -#define WIFSIGNALED(w) (!WIFEXITED(w) && !WIFSTOPPED(w)) -#define WEXITSTATUS(w) (int)(WIFEXITED(w) ? ((_W_INT(w) >> 8) & 0377) : -1) -#define WTERMSIG(w) (int)(WIFSIGNALED(w) ? (_W_INT(w) & 0177) : -1) -#define WCOREFLAG 0x80 -#define WCOREDUMP(w) ((_W_INT(w)) & WCOREFLAG) - -/* Prototype */ -pid_t waitpid(int, int *, int); - -#endif /* !HAVE_WAITPID */ -#endif /* _BSD_WAITPID_H */ diff --git a/foobar/portable/openbsd-compat/chacha_private.h b/foobar/portable/openbsd-compat/chacha_private.h deleted file mode 100644 index 46613646..00000000 --- a/foobar/portable/openbsd-compat/chacha_private.h +++ /dev/null @@ -1,224 +0,0 @@ -/* -chacha-merged.c version 20080118 -D. J. Bernstein -Public domain. -*/ - -/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */ - -#include - -typedef unsigned char u8; -typedef unsigned int u32; - -typedef struct -{ - u32 input[16]; /* could be compressed */ -} chacha_ctx; - -#define U8C(v) (v##U) -#define U32C(v) (v##U) - -#define U8V(v) ((u8)(v) & U8C(0xFF)) -#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) - -#define ROTL32(v, n) \ - (U32V((v) << (n)) | ((v) >> (32 - (n)))) - -#define U8TO32_LITTLE(p) \ - (((u32)((p)[0]) ) | \ - ((u32)((p)[1]) << 8) | \ - ((u32)((p)[2]) << 16) | \ - ((u32)((p)[3]) << 24)) - -#define U32TO8_LITTLE(p, v) \ - do { \ - (p)[0] = U8V((v) ); \ - (p)[1] = U8V((v) >> 8); \ - (p)[2] = U8V((v) >> 16); \ - (p)[3] = U8V((v) >> 24); \ - } while (0) - -#define ROTATE(v,c) (ROTL32(v,c)) -#define XOR(v,w) ((v) ^ (w)) -#define PLUS(v,w) (U32V((v) + (w))) -#define PLUSONE(v) (PLUS((v),1)) - -#define QUARTERROUND(a,b,c,d) \ - a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \ - c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \ - a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ - c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); - -static const char sigma[16] = "expand 32-byte k"; -static const char tau[16] = "expand 16-byte k"; - -static void -chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits) -{ - const char *constants; - - x->input[4] = U8TO32_LITTLE(k + 0); - x->input[5] = U8TO32_LITTLE(k + 4); - x->input[6] = U8TO32_LITTLE(k + 8); - x->input[7] = U8TO32_LITTLE(k + 12); - if (kbits == 256) { /* recommended */ - k += 16; - constants = sigma; - } else { /* kbits == 128 */ - constants = tau; - } - x->input[8] = U8TO32_LITTLE(k + 0); - x->input[9] = U8TO32_LITTLE(k + 4); - x->input[10] = U8TO32_LITTLE(k + 8); - x->input[11] = U8TO32_LITTLE(k + 12); - x->input[0] = U8TO32_LITTLE(constants + 0); - x->input[1] = U8TO32_LITTLE(constants + 4); - x->input[2] = U8TO32_LITTLE(constants + 8); - x->input[3] = U8TO32_LITTLE(constants + 12); -} - -static void -chacha_ivsetup(chacha_ctx *x,const u8 *iv) -{ - x->input[12] = 0; - x->input[13] = 0; - x->input[14] = U8TO32_LITTLE(iv + 0); - x->input[15] = U8TO32_LITTLE(iv + 4); -} - -static void -chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes) -{ - u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; - u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; - u8 *ctarget = NULL; - u8 tmp[64]; - u_int i; - - if (!bytes) return; - - j0 = x->input[0]; - j1 = x->input[1]; - j2 = x->input[2]; - j3 = x->input[3]; - j4 = x->input[4]; - j5 = x->input[5]; - j6 = x->input[6]; - j7 = x->input[7]; - j8 = x->input[8]; - j9 = x->input[9]; - j10 = x->input[10]; - j11 = x->input[11]; - j12 = x->input[12]; - j13 = x->input[13]; - j14 = x->input[14]; - j15 = x->input[15]; - - for (;;) { - if (bytes < 64) { - for (i = 0;i < bytes;++i) tmp[i] = m[i]; - m = tmp; - ctarget = c; - c = tmp; - } - x0 = j0; - x1 = j1; - x2 = j2; - x3 = j3; - x4 = j4; - x5 = j5; - x6 = j6; - x7 = j7; - x8 = j8; - x9 = j9; - x10 = j10; - x11 = j11; - x12 = j12; - x13 = j13; - x14 = j14; - x15 = j15; - for (i = 20;i > 0;i -= 2) { - QUARTERROUND( x0, x4, x8,x12) - QUARTERROUND( x1, x5, x9,x13) - QUARTERROUND( x2, x6,x10,x14) - QUARTERROUND( x3, x7,x11,x15) - QUARTERROUND( x0, x5,x10,x15) - QUARTERROUND( x1, x6,x11,x12) - QUARTERROUND( x2, x7, x8,x13) - QUARTERROUND( x3, x4, x9,x14) - } - x0 = PLUS(x0,j0); - x1 = PLUS(x1,j1); - x2 = PLUS(x2,j2); - x3 = PLUS(x3,j3); - x4 = PLUS(x4,j4); - x5 = PLUS(x5,j5); - x6 = PLUS(x6,j6); - x7 = PLUS(x7,j7); - x8 = PLUS(x8,j8); - x9 = PLUS(x9,j9); - x10 = PLUS(x10,j10); - x11 = PLUS(x11,j11); - x12 = PLUS(x12,j12); - x13 = PLUS(x13,j13); - x14 = PLUS(x14,j14); - x15 = PLUS(x15,j15); - -#ifndef KEYSTREAM_ONLY - x0 = XOR(x0,U8TO32_LITTLE(m + 0)); - x1 = XOR(x1,U8TO32_LITTLE(m + 4)); - x2 = XOR(x2,U8TO32_LITTLE(m + 8)); - x3 = XOR(x3,U8TO32_LITTLE(m + 12)); - x4 = XOR(x4,U8TO32_LITTLE(m + 16)); - x5 = XOR(x5,U8TO32_LITTLE(m + 20)); - x6 = XOR(x6,U8TO32_LITTLE(m + 24)); - x7 = XOR(x7,U8TO32_LITTLE(m + 28)); - x8 = XOR(x8,U8TO32_LITTLE(m + 32)); - x9 = XOR(x9,U8TO32_LITTLE(m + 36)); - x10 = XOR(x10,U8TO32_LITTLE(m + 40)); - x11 = XOR(x11,U8TO32_LITTLE(m + 44)); - x12 = XOR(x12,U8TO32_LITTLE(m + 48)); - x13 = XOR(x13,U8TO32_LITTLE(m + 52)); - x14 = XOR(x14,U8TO32_LITTLE(m + 56)); - x15 = XOR(x15,U8TO32_LITTLE(m + 60)); -#endif - - j12 = PLUSONE(j12); - if (!j12) { - j13 = PLUSONE(j13); - /* stopping at 2^70 bytes per nonce is user's responsibility */ - } - - U32TO8_LITTLE(c + 0,x0); - U32TO8_LITTLE(c + 4,x1); - U32TO8_LITTLE(c + 8,x2); - U32TO8_LITTLE(c + 12,x3); - U32TO8_LITTLE(c + 16,x4); - U32TO8_LITTLE(c + 20,x5); - U32TO8_LITTLE(c + 24,x6); - U32TO8_LITTLE(c + 28,x7); - U32TO8_LITTLE(c + 32,x8); - U32TO8_LITTLE(c + 36,x9); - U32TO8_LITTLE(c + 40,x10); - U32TO8_LITTLE(c + 44,x11); - U32TO8_LITTLE(c + 48,x12); - U32TO8_LITTLE(c + 52,x13); - U32TO8_LITTLE(c + 56,x14); - U32TO8_LITTLE(c + 60,x15); - - if (bytes <= 64) { - if (bytes < 64) { - for (i = 0;i < bytes;++i) ctarget[i] = c[i]; - } - x->input[12] = j12; - x->input[13] = j13; - return; - } - bytes -= 64; - c += 64; -#ifndef KEYSTREAM_ONLY - m += 64; -#endif - } -} diff --git a/foobar/portable/openbsd-compat/clock_gettime.c b/foobar/portable/openbsd-compat/clock_gettime.c deleted file mode 100644 index 6c1ef0d4..00000000 --- a/foobar/portable/openbsd-compat/clock_gettime.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2012 Charles Longeau - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#ifdef HAVE_MACH_MACH_TIME_H -#include -#endif -#include -#include - -#if !defined(HAVE_CLOCK_GETTIME) -int -clock_gettime(int clock_id, struct timespec *tp) -{ - int ret = 0; - uint64_t time; - mach_timebase_info_data_t info; - static double scaling_factor = 0; - -#if 0 - struct timeval tv; - - ret = gettimeofday(&tv, NULL); - TIMEVAL_TO_TIMESPEC(&tv, tp); -#endif - -/* based on http://code-factor.blogspot.fr/2009/11/monotonic-timers.html */ - - time = mach_absolute_time(); - - if (scaling_factor == 0) { - ret = (int) mach_timebase_info(&info); - if (ret != 0) - fatal("mach_timebase_info failed"); - scaling_factor = info.numer/info.denom; - } - - time *= scaling_factor; - - tp->tv_sec = time / 1000000000; - tp->tv_nsec = time % 1000000000; - - return (ret); -} -#endif diff --git a/foobar/portable/openbsd-compat/closefrom.c b/foobar/portable/openbsd-compat/closefrom.c deleted file mode 100644 index 528949a6..00000000 --- a/foobar/portable/openbsd-compat/closefrom.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2004-2005 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#ifdef HAVE_FCNTL_H -# include -#endif -#include -#include -#include -#include -#include -#ifdef HAVE_DIRENT_H -# include -# define NAMLEN(dirent) strlen((dirent)->d_name) -#else -# define dirent direct -# define NAMLEN(dirent) (dirent)->d_namlen -# ifdef HAVE_SYS_NDIR_H -# include -# endif -# ifdef HAVE_SYS_DIR_H -# include -# endif -# ifdef HAVE_NDIR_H -# include -# endif -#endif - -#ifndef OPEN_MAX -# define OPEN_MAX 256 -#endif - -#if 0 -__unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $"; -#endif /* lint */ - -/* - * Close all file descriptors greater than or equal to lowfd. - */ -#ifdef HAVE_FCNTL_CLOSEM -void -closefrom(int lowfd) -{ - (void) fcntl(lowfd, F_CLOSEM, 0); -} -#else -void -closefrom(int lowfd) -{ - long fd, maxfd; -#if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID) - char fdpath[PATH_MAX], *endp; - struct dirent *dent; - DIR *dirp; - int len; - - /* Check for a /proc/$$/fd directory. */ - len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); - if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { - while ((dent = readdir(dirp)) != NULL) { - fd = strtol(dent->d_name, &endp, 10); - if (dent->d_name != endp && *endp == '\0' && - fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp)) - (void) close((int) fd); - } - (void) closedir(dirp); - } else -#endif - { - /* - * Fall back on sysconf() or getdtablesize(). We avoid checking - * resource limits since it is possible to open a file descriptor - * and then drop the rlimit such that it is below the open fd. - */ -#ifdef HAVE_SYSCONF - maxfd = sysconf(_SC_OPEN_MAX); -#else - maxfd = getdtablesize(); -#endif /* HAVE_SYSCONF */ - if (maxfd < 0) - maxfd = OPEN_MAX; - - for (fd = lowfd; fd < maxfd; fd++) - (void) close((int) fd); - } -} -#endif /* !HAVE_FCNTL_CLOSEM */ - diff --git a/foobar/portable/openbsd-compat/crypt_checkpass.c b/foobar/portable/openbsd-compat/crypt_checkpass.c deleted file mode 100644 index d10b3a57..00000000 --- a/foobar/portable/openbsd-compat/crypt_checkpass.c +++ /dev/null @@ -1,33 +0,0 @@ -/* OPENBSD ORIGINAL: lib/libc/crypt/cryptutil.c */ - -#include "includes.h" -#include -#ifdef HAVE_CRYPT_H -#include -#endif -#include -#include - -int -crypt_checkpass(const char *pass, const char *goodhash) -{ - char *c; - - if (goodhash == NULL) - goto fail; - - /* empty password */ - if (strlen(goodhash) == 0 && strlen(pass) == 0) - return 0; - - c = crypt(pass, goodhash); - if (c == NULL) - goto fail; - - if (strcmp(c, goodhash) == 0) - return 0; - -fail: - errno = EACCES; - return -1; -} diff --git a/foobar/portable/openbsd-compat/daemon.c b/foobar/portable/openbsd-compat/daemon.c deleted file mode 100644 index 3efe14c6..00000000 --- a/foobar/portable/openbsd-compat/daemon.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $OpenBSD: daemon.c,v 1.6 2005/08/08 08:05:33 espie Exp $ */ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* OPENBSD ORIGINAL: lib/libc/gen/daemon.c */ - -#include "includes.h" - -#ifndef HAVE_DAEMON - -#include - -#ifdef HAVE_SYS_STAT_H -# include -#endif - -#ifdef HAVE_FCNTL_H -# include -#endif - -#ifdef HAVE_UNISTD_H -# include -#endif - -int -daemon(int nochdir, int noclose) -{ - int fd; - - switch (fork()) { - case -1: - return (-1); - case 0: - break; - default: - _exit(0); - } - - if (setsid() == -1) - return (-1); - - if (!nochdir) - (void)chdir("/"); - - if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close (fd); - } - return (0); -} - -#endif /* !HAVE_DAEMON */ - diff --git a/foobar/portable/openbsd-compat/defines.h b/foobar/portable/openbsd-compat/defines.h deleted file mode 100644 index a6e528eb..00000000 --- a/foobar/portable/openbsd-compat/defines.h +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Copyright (c) 2016 Gilles Chehade . All rights reserved. - * Copyright (c) 1999-2003 Damien Miller. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _DEFINES_H -#define _DEFINES_H - -/* $Id: defines.h,v 1.181 2014/06/11 19:22:50 dtucker Exp $ */ - - -/* Constants */ -#ifndef EAUTH -# define EAUTH 80 -#endif - -#ifndef INFTIM -#define INFTIM (-1) -#endif - -#ifndef HOST_NAME_MAX -# ifdef _POSIX_HOST_NAME_MAX -# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX -# endif -#endif - -#ifndef PATH_MAX -# ifdef _POSIX_PATH_MAX -# define PATH_MAX _POSIX_PATH_MAX -# endif -#endif - -#ifndef MAXPATHLEN -# ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX -# else /* PATH_MAX */ -# define MAXPATHLEN 64 -# define PATH_MAX 64 -/* realpath uses a fixed buffer of size MAXPATHLEN, so force use of ours */ -# ifndef BROKEN_REALPATH -# define BROKEN_REALPATH 1 -# endif /* BROKEN_REALPATH */ -# endif /* PATH_MAX */ -#endif /* MAXPATHLEN */ - -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 64 -#endif - -#ifndef LOGIN_NAME_MAX -# define LOGIN_NAME_MAX 32 -#endif - -#ifndef MAXLOGNAME -#define MAXLOGNAME LOGIN_NAME_MAX -#endif - -#ifndef UID_MAX -#define UID_MAX UINT_MAX -#endif -#ifndef GID_MAX -#define GID_MAX UINT_MAX -#endif - -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - -#if !HAVE_DECL_O_NONBLOCK -# define O_NONBLOCK 00004 /* Non Blocking Open */ -#endif - -#ifndef O_EXLOCK -#define O_EXLOCK 0 -#endif - -#ifndef S_ISDIR -# define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR)) -#endif /* S_ISDIR */ - -#ifndef S_ISREG -# define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG)) -#endif /* S_ISREG */ - -#ifndef S_ISLNK -# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#endif /* S_ISLNK */ - -#ifndef S_IXUSR -# define S_ISUID 0004000 /* set-uid */ -# define S_ISGID 0002000 /* set-gid */ -# define S_ISVTX 0001000 /* sticky */ -# define S_IXUSR 0000100 /* execute/search permission, */ -# define S_IXGRP 0000010 /* execute/search permission, */ -# define S_IXOTH 0000001 /* execute/search permission, */ -# define _S_IWUSR 0000200 /* write permission, */ -# define S_IWUSR _S_IWUSR /* write permission, owner */ -# define S_IWGRP 0000020 /* write permission, group */ -# define S_IWOTH 0000002 /* write permission, other */ -# define S_IRUSR 0000400 /* read permission, owner */ -# define S_IRGRP 0000040 /* read permission, group */ -# define S_IROTH 0000004 /* read permission, other */ -# define S_IRWXU 0000700 /* read, write, execute */ -# define S_IRWXG 0000070 /* read, write, execute */ -# define S_IRWXO 0000007 /* read, write, execute */ -#endif /* S_IXUSR */ - -#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) -#define MAP_ANON MAP_ANONYMOUS -#endif - -#ifndef MAP_FAILED -# define MAP_FAILED ((void *)-1) -#endif - -/* -SCO Open Server 3 has INADDR_LOOPBACK defined in rpc/rpc.h but -including rpc/rpc.h breaks Solaris 6 -*/ -#ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK ((u_long)0x7f000001) -#endif - - -/* Types */ -#ifndef HAVE_U_CHAR -typedef unsigned char u_char; -# define HAVE_U_CHAR -#endif /* HAVE_U_CHAR */ - -#ifndef HAVE_U_INT -typedef unsigned int u_int; -# define HAVE_U_INT -#endif - -#ifndef HAVE_INTMAX_T -typedef long long intmax_t; -# define HAVE_INTMAX_T -#endif - -#ifndef HAVE_UINTMAX_T -typedef unsigned long long uintmax_t; -# define HAVE_UINTMAX_T -#endif - -#ifndef HAVE_SA_FAMILY_T -typedef int sa_family_t; -# define HAVE_SA_FAMILY_T -#endif /* HAVE_SA_FAMILY_T */ - -#ifndef HAVE_SIG_ATOMIC_T -typedef int sig_atomic_t; -# define HAVE_SIG_ATOMIC_T -#endif /* HAVE_SIG_ATOMIC_T */ - - -#ifndef ULLONG_MAX -# define ULLONG_MAX ((unsigned long long)-1) -#endif - -#ifndef SIZE_T_MAX -#define SIZE_T_MAX ULONG_MAX -#endif /* SIZE_T_MAX */ - -#ifndef SIZE_MAX -#define SIZE_MAX SIZE_T_MAX -#endif - - - -#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS) -# define ss_family __ss_family -#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */ - -#ifndef HAVE_SYS_UN_H -struct sockaddr_un { - short sun_family; /* AF_UNIX */ - char sun_path[108]; /* path name (gag) */ -}; -#endif /* HAVE_SYS_UN_H */ - -#ifndef HAVE_IN_ADDR_T -typedef uint32_t in_addr_t; -#endif - -#ifndef HAVE_IN_PORT_T -typedef uint16_t in_port_t; -#endif - - -/* Paths */ - -/* needed by compat/daemon.c */ -#ifndef _PATH_DEVNULL -# define _PATH_DEVNULL "/dev/null" -#endif - -/* user may have set a different path */ -#if !defined(_PATH_MAILDIR) -# define _PATH_MAILDIR "/var/spool/mail" -#endif - -#if defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) -# undef _PATH_MAILDIR -#endif /* defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) */ - -#ifdef MAIL_DIRECTORY -# define _PATH_MAILDIR MAIL_DIRECTORY -#endif - -#ifdef MAILDIR -# undef MAILDIR -#endif - - - -/* Macros */ - -/* needed by compat */ -#ifndef MAX -# define MAX(a,b) (((a)>(b))?(a):(b)) -#endif -#ifndef MIN -# define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -/* needed by smtpd */ -#ifndef timespeccmp -#define timespeccmp(a, b, cmp) \ - (((a)->tv_sec == (b)->tv_sec) ? \ - ((a)->tv_nsec cmp (b)->tv_nsec) : \ - ((a)->tv_sec cmp (b)->tv_sec)) -#endif - -/* needed by smtpd */ -#ifndef timespecsub -#define timespecsub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \ - if ((result)->tv_nsec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_nsec += 1000000000L; \ - } \ - } while (0) -#endif - -/* needed by smtpd */ -#ifndef TIMEVAL_TO_TIMESPEC -#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ - (ts)->tv_sec = (tv)->tv_sec; \ - (ts)->tv_nsec = (tv)->tv_usec * 1000; \ -} -#endif - -/* needed by compat */ -#ifndef TIMESPEC_TO_TIMEVAL -#define TIMESPEC_TO_TIMEVAL(tv, ts) { \ - (tv)->tv_sec = (ts)->tv_sec; \ - (tv)->tv_usec = (ts)->tv_nsec / 1000; \ -} -#endif - -#ifndef __P -# define __P(x) x -#endif - -#if !defined(IN6_IS_ADDR_V4MAPPED) -# define IN6_IS_ADDR_V4MAPPED(a) \ - ((((uint32_t *) (a))[0] == 0) && (((uint32_t *) (a))[1] == 0) && \ - (((uint32_t *) (a))[2] == htonl (0xffff))) -#endif /* !defined(IN6_IS_ADDR_V4MAPPED) */ - -#if !defined(__GNUC__) || (__GNUC__ < 2) -# define __attribute__(x) -#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ - -#ifndef __dead -# define __dead __attribute__((noreturn)) -#endif - -#if !defined(HAVE_ATTRIBUTE__SENTINEL__) && !defined(__sentinel__) -# define __sentinel__ -#endif - -#if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__) -# define __bounded__(x, y, z) -#endif - -#if !defined(HAVE_ATTRIBUTE__NONNULL__) && !defined(__nonnull__) -# define __nonnull__(x) -#endif - -#ifndef OSSH_ALIGNBYTES -#define OSSH_ALIGNBYTES (sizeof(int) - 1) -#endif -#ifndef __CMSG_ALIGN -#define __CMSG_ALIGN(p) (((u_int)(p) + OSSH_ALIGNBYTES) &~ OSSH_ALIGNBYTES) -#endif - -/* Length of the contents of a control message of length len */ -#ifndef CMSG_LEN -#define CMSG_LEN(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) -#endif - -/* Length of the space taken up by a padded control message of length len */ -#ifndef CMSG_SPACE -#define CMSG_SPACE(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len)) -#endif - -/* given pointer to struct cmsghdr, return pointer to data */ -#ifndef CMSG_DATA -#define CMSG_DATA(cmsg) ((u_char *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr))) -#endif /* CMSG_DATA */ - -/* - * RFC 2292 requires to check msg_controllen, in case that the kernel returns - * an empty list for some reasons. - */ -#ifndef CMSG_FIRSTHDR -#define CMSG_FIRSTHDR(mhdr) \ - ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ - (struct cmsghdr *)(mhdr)->msg_control : \ - (struct cmsghdr *)NULL) -#endif /* CMSG_FIRSTHDR */ - - -/* Set up BSD-style BYTE_ORDER definition if it isn't there already */ -/* XXX: doesn't try to cope with strange byte orders (PDP_ENDIAN) */ -#ifndef BYTE_ORDER -# ifndef LITTLE_ENDIAN -# define LITTLE_ENDIAN 1234 -# endif /* LITTLE_ENDIAN */ -# ifndef BIG_ENDIAN -# define BIG_ENDIAN 4321 -# endif /* BIG_ENDIAN */ -# ifdef WORDS_BIGENDIAN -# define BYTE_ORDER BIG_ENDIAN -# else /* WORDS_BIGENDIAN */ -# define BYTE_ORDER LITTLE_ENDIAN -# endif /* WORDS_BIGENDIAN */ -#endif /* BYTE_ORDER */ - -/* Function replacement / compatibility hacks */ - -#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) -# undef HAVE_GETADDRINFO -#endif -#if defined(BROKEN_GETADDRINFO) && defined(HAVE_FREEADDRINFO) -# undef HAVE_FREEADDRINFO -#endif -#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GAI_STRERROR) -# undef HAVE_GAI_STRERROR -#endif - -#if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) -# define memmove(s1, s2, n) bcopy((s2), (s1), (n)) -#endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */ - -#if !defined(HAVE___func__) && defined(HAVE___FUNCTION__) -# define __func__ __FUNCTION__ -#elif !defined(HAVE___func__) -# define __func__ "" -#endif - - -/* Maximum number of file descriptors available */ -/* needed by compat/bsd-closefrom.c */ -#ifndef OPEN_MAX -# ifdef HAVE_SYSCONF -# define OPEN_MAX sysconf(_SC_OPEN_MAX) -# else -# define OPEN_MAX 256 -# endif -#endif - - - -/** end of login recorder definitions */ - -#ifndef IOV_MAX -# if defined(_XOPEN_IOV_MAX) -# define IOV_MAX _XOPEN_IOV_MAX -# elif defined(DEF_IOV_MAX) -# define IOV_MAX DEF_IOV_MAX -# else -# define IOV_MAX 16 -# endif -#endif - -#ifndef EWOULDBLOCK -# define EWOULDBLOCK EAGAIN -#endif - -#ifndef INET6_ADDRSTRLEN /* for non IPv6 machines */ -#define INET6_ADDRSTRLEN 46 -#endif - -#ifndef HAVE_VA_COPY -# ifdef HAVE___VA_COPY -# define va_copy(dest, src) __va_copy(dest, src) -# else -# define va_copy(dest, src) (dest) = (src) -# endif -#endif - -/* OpenSMTPD-portable specific entries */ - -/* From OpenNTPD portable */ -#if !defined(SA_LEN) -# if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) -# define SA_LEN(x) ((x)->sa_len) -# else -# define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \ - sizeof(struct sockaddr_in6) : \ - sizeof(struct sockaddr_in)) -# endif -#endif - -/* From OpenBGPD portable */ -#if !defined(SS_LEN) -# if defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN) -# define SS_LEN(x) ((x)->ss_len) -# else -# define SS_LEN(x) SA_LEN((struct sockaddr *)(x)) -# endif -#endif - -#ifdef HAVE_SS_LEN -# define STORAGE_LEN(X) ((X).ss_len) -# define SET_STORAGE_LEN(X, Y) do { STORAGE_LEN(X) = (Y); } while(0) -#elif defined(HAVE___SS_LEN) -# define STORAGE_LEN(X) ((X).__ss_len) -# define SET_STORAGE_LEN(X, Y) do { STORAGE_LEN(X) = (Y); } while(0) -#else -# define STORAGE_LEN(X) (STORAGE_FAMILY(X) == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) -# define SET_STORAGE_LEN(X, Y) (void) 0 -#endif - -/* chl parts */ -#ifndef EAI_NODATA -# ifdef EAI_NONAME -# define EAI_NODATA EAI_NONAME -# else -# error "Neither EAI_NODATA and EAI_NONAME are defined! :(" -# endif -#endif -/* end of chl */ - -#ifndef HAVE_FPARSELN -/* - * fparseln() specific operation flags. - */ -#define FPARSELN_UNESCESC 0x01 -#define FPARSELN_UNESCCONT 0x02 -#define FPARSELN_UNESCCOMM 0x04 -#define FPARSELN_UNESCREST 0x08 -#define FPARSELN_UNESCALL 0x0f -#endif - -#ifdef HAVE_M_DATA -#undef M_DATA -#endif - -#ifndef SCOPE_DELIMITER -#define SCOPE_DELIMITER '%' -#endif - -#ifndef HAVE_FLOCK -#define LOCK_SH 0x01 /* shared file lock */ -#define LOCK_EX 0x02 /* exclusive file lock */ -#define LOCK_NB 0x04 /* don't block when locking */ -#define LOCK_UN 0x08 /* unlock file */ -#endif - -#if !HAVE_DECL_LOG_PERROR -#define LOG_PERROR 0 -#endif - -#ifndef MAXDNAME -#define MAXDNAME 1025 -#endif - -#endif /* _DEFINES_H */ diff --git a/foobar/portable/openbsd-compat/dirname.c b/foobar/portable/openbsd-compat/dirname.c deleted file mode 100644 index 30fcb496..00000000 --- a/foobar/portable/openbsd-compat/dirname.c +++ /dev/null @@ -1,72 +0,0 @@ -/* $OpenBSD: dirname.c,v 1.13 2005/08/08 08:05:33 espie Exp $ */ - -/* - * Copyright (c) 1997, 2004 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* OPENBSD ORIGINAL: lib/libc/gen/dirname.c */ - -#include "includes.h" -#ifndef HAVE_DIRNAME - -#include -#include -#include - -char * -dirname(const char *path) -{ - static char dname[MAXPATHLEN]; - size_t len; - const char *endp; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - dname[0] = '.'; - dname[1] = '\0'; - return (dname); - } - - /* Strip any trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* Find the start of the dir */ - while (endp > path && *endp != '/') - endp--; - - /* Either the dir is "/" or there are no slashes */ - if (endp == path) { - dname[0] = *endp == '/' ? '/' : '.'; - dname[1] = '\0'; - return (dname); - } else { - /* Move forward past the separating slashes */ - do { - endp--; - } while (endp > path && *endp == '/'); - } - - len = endp - path + 1; - if (len >= sizeof(dname)) { - errno = ENAMETOOLONG; - return (NULL); - } - memcpy(dname, path, len); - dname[len] = '\0'; - return (dname); -} -#endif diff --git a/foobar/portable/openbsd-compat/empty.c b/foobar/portable/openbsd-compat/empty.c deleted file mode 100644 index e69de29b..00000000 diff --git a/foobar/portable/openbsd-compat/entropy.c b/foobar/portable/openbsd-compat/entropy.c deleted file mode 100644 index 367d7135..00000000 --- a/foobar/portable/openbsd-compat/entropy.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2001 Damien Miller. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "includes.h" - -#include -#include -#ifdef HAVE_SYS_UN_H -# include -#endif - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include "smtpd/log.h" - -void -seed_rng(void) -{ -#ifndef LIBRESSL_VERSION - u_long mask; - - /* - * OpenSSL version numbers: MNNFFPPS: major minor fix patch status - * We match major, minor, fix and status (not patch) for <1.0.0. - * After that, we acceptable compatible fix versions (so we - * allow 1.0.1 to work with 1.0.0). Going backwards is only allowed - * within a patch series. - */ - mask = SSLeay() >= 0x1000000f ? 0xfff00000L : 0xfffff00fL; - if ((SSLeay() & mask) < (OPENSSL_VERSION_NUMBER & mask)) { - fatalx("OpenSSL version mismatch. Built against %lx, you have %lx\n", - (u_long)OPENSSL_VERSION_NUMBER, SSLeay()); - } -#endif - - if (RAND_status() != 1) - fatal("PRNG is not seeded"); -} diff --git a/foobar/portable/openbsd-compat/entropy.h b/foobar/portable/openbsd-compat/entropy.h deleted file mode 100644 index 496bed66..00000000 --- a/foobar/portable/openbsd-compat/entropy.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999-2000 Damien Miller. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $Id: entropy.h,v 1.6 2011/09/09 01:29:41 dtucker Exp $ */ - -#ifndef _RANDOMS_H -#define _RANDOMS_H - -/* #include "buffer.h" */ - -void seed_rng(void); - -/* void rexec_send_rng_seed(Buffer *); */ -/* void rexec_recv_rng_seed(Buffer *); */ - -#endif /* _RANDOMS_H */ diff --git a/foobar/portable/openbsd-compat/err_h/err.h b/foobar/portable/openbsd-compat/err_h/err.h deleted file mode 100644 index a56b6188..00000000 --- a/foobar/portable/openbsd-compat/err_h/err.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ERR_H -#define ERR_H - -#ifndef LIBCRYPTOCOMPAT_ERR_H -#define LIBCRYPTOCOMPAT_ERR_H - -__attribute__ ((noreturn)) -void err(int, const char *, ...); - -__attribute__ ((noreturn)) -void errx(int, const char *, ...); - -void warn(const char *, ...); -void warnx(const char *, ...); - -#endif - -#endif diff --git a/foobar/portable/openbsd-compat/errc.c b/foobar/portable/openbsd-compat/errc.c deleted file mode 100644 index 658a55b4..00000000 --- a/foobar/portable/openbsd-compat/errc.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $OpenBSD: basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $ */ - -/* - * Copyright (c) 1997, 2004 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* OPENBSD ORIGINAL: lib/libc/gen/errc.c */ - -#include "includes.h" - -#ifndef HAVE_ERRC - -#include -#include -#include -#include -#include - -extern char *__progname; - -__attribute__((noreturn)) -static void -_verrc(int eval, int code, const char *fmt, va_list ap) -{ - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, ": "); - } - (void)fprintf(stderr, "%s\n", strerror(code)); - exit(eval); -} - -void -errc(int eval, int code, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - _verrc(eval, code, fmt, ap); - va_end(ap); -} - -#endif diff --git a/foobar/portable/openbsd-compat/event_asr_run.c b/foobar/portable/openbsd-compat/event_asr_run.c deleted file mode 100644 index aef86154..00000000 --- a/foobar/portable/openbsd-compat/event_asr_run.c +++ /dev/null @@ -1,88 +0,0 @@ -/* $OpenBSD$ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include - -#include -#include -#include - -struct event_asr { - struct event ev; - struct asr_query *async; - void (*cb)(struct asr_result *, void *); - void *arg; -}; - -struct event_asr * event_asr_run(struct asr_query *, - void (*)(struct asr_result *, void *), void *); -void event_asr_abort(struct event_asr *); - -static void -event_asr_dispatch(int fd __attribute__((__unused__)), - short ev __attribute__((__unused__)), void *arg) -{ - struct event_asr *eva = arg; - struct asr_result ar; - struct timeval tv; - - event_del(&eva->ev); - - if (asr_run(eva->async, &ar)) { - eva->cb(&ar, eva->arg); - free(eva); - } else { - event_set(&eva->ev, ar.ar_fd, - ar.ar_cond == ASR_WANT_READ ? EV_READ : EV_WRITE, - event_asr_dispatch, eva); - tv.tv_sec = ar.ar_timeout / 1000; - tv.tv_usec = (ar.ar_timeout % 1000) * 1000; - event_add(&eva->ev, &tv); - } -} - -struct event_asr * -event_asr_run(struct asr_query *async, void (*cb)(struct asr_result *, void *), - void *arg) -{ - struct event_asr *eva; - struct timeval tv; - - eva = calloc(1, sizeof *eva); - if (eva == NULL) - return (NULL); - eva->async = async; - eva->cb = cb; - eva->arg = arg; - tv.tv_sec = 0; - tv.tv_usec = 0; - evtimer_set(&eva->ev, event_asr_dispatch, eva); - evtimer_add(&eva->ev, &tv); - return (eva); -} - -void -event_asr_abort(struct event_asr *eva) -{ - asr_abort(eva->async); - event_del(&eva->ev); - free(eva); -} diff --git a/foobar/portable/openbsd-compat/explicit_bzero.c b/foobar/portable/openbsd-compat/explicit_bzero.c deleted file mode 100644 index d9f4abf5..00000000 --- a/foobar/portable/openbsd-compat/explicit_bzero.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ -/* - * Public domain. - * Written by Matthew Dempsky. - */ - -#include "includes.h" - -#include - -void -explicit_bzero(void *buf, size_t len) -{ - memset(buf, 0, len); -} diff --git a/foobar/portable/openbsd-compat/fgetln.c b/foobar/portable/openbsd-compat/fgetln.c deleted file mode 100644 index 1c51ff78..00000000 --- a/foobar/portable/openbsd-compat/fgetln.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2015 Joerg Jung - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * portable fgetln() version, NOT reentrant - */ - -#include "includes.h" - -#include -#include -#include - -void *reallocarray(void *, size_t, size_t); - -char * -fgetln(FILE *fp, size_t *len) -{ - static char *buf = NULL; - static size_t bufsz = 0; - size_t r = 0; - char *p; - int c, e; - - if (buf == NULL) { - if ((buf = calloc(1, BUFSIZ)) == NULL) - return NULL; - bufsz = BUFSIZ; - } - - while ((c = getc(fp)) != EOF) { - buf[r++] = c; - if (r == bufsz) { - if (!(p = reallocarray(buf, 2, bufsz))) { - e = errno; - free(buf); - errno = e; - buf = NULL, bufsz = 0; - return NULL; - } - buf = p, bufsz = 2 * bufsz; - } - if (c == '\n') - break; - } - return (*len = r) ? buf : NULL; -} - diff --git a/foobar/portable/openbsd-compat/fmt_scaled.c b/foobar/portable/openbsd-compat/fmt_scaled.c deleted file mode 100644 index edd682a4..00000000 --- a/foobar/portable/openbsd-compat/fmt_scaled.c +++ /dev/null @@ -1,274 +0,0 @@ -/* $OpenBSD: fmt_scaled.c,v 1.9 2007/03/20 03:42:52 tedu Exp $ */ - -/* - * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* OPENBSD ORIGINAL: lib/libutil/fmt_scaled.c */ - -/* - * fmt_scaled: Format numbers scaled for human comprehension - * scan_scaled: Scan numbers in this format. - * - * "Human-readable" output uses 4 digits max, and puts a unit suffix at - * the end. Makes output compact and easy-to-read esp. on huge disks. - * Formatting code was originally in OpenBSD "df", converted to library routine. - * Scanning code written for OpenBSD libutil. - */ - -#include "includes.h" - -#ifndef HAVE_FMT_SCALED - -#include -#include -#include -#include -#include -#include - -typedef enum { - NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6 -} unit_type; - -/* These three arrays MUST be in sync! XXX make a struct */ -static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA }; -static char scale_chars[] = "BKMGTPE"; -static long long scale_factors[] = { - 1LL, - 1024LL, - 1024LL*1024, - 1024LL*1024*1024, - 1024LL*1024*1024*1024, - 1024LL*1024*1024*1024*1024, - 1024LL*1024*1024*1024*1024*1024, -}; -#define SCALE_LENGTH (sizeof(units)/sizeof(units[0])) - -#define MAX_DIGITS (SCALE_LENGTH * 3) /* XXX strlen(sprintf("%lld", -1)? */ - -/** Convert the given input string "scaled" into numeric in "result". - * Return 0 on success, -1 and errno set on error. - */ -int -scan_scaled(char *scaled, long long *result) -{ - char *p = scaled; - int sign = 0; - unsigned int i, ndigits = 0, fract_digits = 0; - long long scale_fact = 1, whole = 0, fpart = 0; - - /* Skip leading whitespace */ - while (isascii(*p) && isspace(*p)) - ++p; - - /* Then at most one leading + or - */ - while (*p == '-' || *p == '+') { - if (*p == '-') { - if (sign) { - errno = EINVAL; - return -1; - } - sign = -1; - ++p; - } else if (*p == '+') { - if (sign) { - errno = EINVAL; - return -1; - } - sign = +1; - ++p; - } - } - - /* Main loop: Scan digits, find decimal point, if present. - * We don't allow exponentials, so no scientific notation - * (but note that E for Exa might look like e to some!). - * Advance 'p' to end, to get scale factor. - */ - for (; isascii(*p) && (isdigit(*p) || *p=='.'); ++p) { - if (*p == '.') { - if (fract_digits > 0) { /* oops, more than one '.' */ - errno = EINVAL; - return -1; - } - fract_digits = 1; - continue; - } - - i = (*p) - '0'; /* whew! finally a digit we can use */ - if (fract_digits > 0) { - if (fract_digits >= MAX_DIGITS-1) - /* ignore extra fractional digits */ - continue; - fract_digits++; /* for later scaling */ - fpart *= 10; - fpart += i; - } else { /* normal digit */ - if (++ndigits >= MAX_DIGITS) { - errno = ERANGE; - return -1; - } - whole *= 10; - whole += i; - } - } - - if (sign) { - whole *= sign; - fpart *= sign; - } - - /* If no scale factor given, we're done. fraction is discarded. */ - if (!*p) { - *result = whole; - return 0; - } - - /* Validate scale factor, and scale whole and fraction by it. */ - for (i = 0; i < SCALE_LENGTH; i++) { - - /** Are we there yet? */ - if (*p == scale_chars[i] || - *p == tolower(scale_chars[i])) { - - /* If it ends with alphanumerics after the scale char, bad. */ - if (isalnum(*(p+1))) { - errno = EINVAL; - return -1; - } - scale_fact = scale_factors[i]; - - /* scale whole part */ - whole *= scale_fact; - - /* truncate fpart so it does't overflow. - * then scale fractional part. - */ - while (fpart >= LLONG_MAX / scale_fact) { - fpart /= 10; - fract_digits--; - } - fpart *= scale_fact; - if (fract_digits > 0) { - for (i = 0; i < fract_digits -1; i++) - fpart /= 10; - } - whole += fpart; - *result = whole; - return 0; - } - } - errno = ERANGE; - return -1; -} - -/* Format the given "number" into human-readable form in "result". - * Result must point to an allocated buffer of length FMT_SCALED_STRSIZE. - * Return 0 on success, -1 and errno set if error. - */ -int -fmt_scaled(long long number, char *result) -{ - long long abval, fract = 0; - unsigned int i; - unit_type unit = NONE; - - abval = (number < 0LL) ? -number : number; /* no long long_abs yet */ - - /* Not every negative long long has a positive representation. - * Also check for numbers that are just too darned big to format - */ - if (abval < 0 || abval / 1024 >= scale_factors[SCALE_LENGTH-1]) { - errno = ERANGE; - return -1; - } - - /* scale whole part; get unscaled fraction */ - for (i = 0; i < SCALE_LENGTH; i++) { - if (abval/1024 < scale_factors[i]) { - unit = units[i]; - fract = (i == 0) ? 0 : abval % scale_factors[i]; - number /= scale_factors[i]; - if (i > 0) - fract /= scale_factors[i - 1]; - break; - } - } - - fract = (10 * fract + 512) / 1024; - /* if the result would be >= 10, round main number */ - if (fract == 10) { - if (number >= 0) - number++; - else - number--; - fract = 0; - } - - if (number == 0) - strlcpy(result, "0B", FMT_SCALED_STRSIZE); - else if (unit == NONE || number >= 100 || number <= -100) { - if (fract >= 5) { - if (number >= 0) - number++; - else - number--; - } - (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c", - number, scale_chars[unit]); - } else - (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c", - number, fract, scale_chars[unit]); - - return 0; -} - -#ifdef MAIN -/* - * This is the original version of the program in the man page. - * Copy-and-paste whatever you need from it. - */ -int -main(int argc, char **argv) -{ - char *cinput = "1.5K", buf[FMT_SCALED_STRSIZE]; - long long ninput = 10483892, result; - - if (scan_scaled(cinput, &result) == 0) - printf("\"%s\" -> %lld\n", cinput, result); - else - perror(cinput); - - if (fmt_scaled(ninput, buf) == 0) - printf("%lld -> \"%s\"\n", ninput, buf); - else - fprintf(stderr, "%lld invalid (%s)\n", ninput, strerror(errno)); - - return 0; -} -#endif - -#endif /* HAVE_FMT_SCALED */ diff --git a/foobar/portable/openbsd-compat/fparseln.c b/foobar/portable/openbsd-compat/fparseln.c deleted file mode 100644 index dfa9093c..00000000 --- a/foobar/portable/openbsd-compat/fparseln.c +++ /dev/null @@ -1,179 +0,0 @@ -/* $OpenBSD: fparseln.c,v 1.6 2005/08/02 21:46:23 espie Exp $ */ -/* $NetBSD: fparseln.c,v 1.7 1999/07/02 15:49:12 simonb Exp $ */ - -/* - * Copyright (c) 1997 Christos Zoulas. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christos Zoulas. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* OPENBSD ORIGINAL: lib/libutil/fparseln.c */ - -#include "includes.h" - -#ifdef HAVE_SYS_CDEFS -#include -#endif - -#include -#include -#include - -static int isescaped(const char *, const char *, int); - -/* isescaped(): - * Return true if the character in *p that belongs to a string - * that starts in *sp, is escaped by the escape character esc. - */ -static int -isescaped(const char *sp, const char *p, int esc) -{ - const char *cp; - size_t ne; - - /* No escape character */ - if (esc == '\0') - return 1; - - /* Count the number of escape characters that precede ours */ - for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++) - continue; - - /* Return true if odd number of escape characters */ - return (ne & 1) != 0; -} - - -/* fparseln(): - * Read a line from a file parsing continuations ending in \ - * and eliminating trailing newlines, or comments starting with - * the comment char. - */ -char * -fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], - int flags) -{ - static const char dstr[3] = { '\\', '\\', '#' }; - char *buf = NULL, *ptr, *cp, esc, con, nl, com; - size_t s, len = 0; - int cnt = 1; - - if (str == NULL) - str = dstr; - - esc = str[0]; - con = str[1]; - com = str[2]; - - /* - * XXX: it would be cool to be able to specify the newline character, - * but unfortunately, fgetln does not let us - */ - nl = '\n'; - - while (cnt) { - cnt = 0; - - if (lineno) - (*lineno)++; - - if ((ptr = fgetln(fp, &s)) == NULL) - break; - - if (s && com) { /* Check and eliminate comments */ - for (cp = ptr; cp < ptr + s; cp++) - if (*cp == com && !isescaped(ptr, cp, esc)) { - s = cp - ptr; - cnt = s == 0 && buf == NULL; - break; - } - } - - if (s && nl) { /* Check and eliminate newlines */ - cp = &ptr[s - 1]; - - if (*cp == nl) - s--; /* forget newline */ - } - - if (s && con) { /* Check and eliminate continuations */ - cp = &ptr[s - 1]; - - if (*cp == con && !isescaped(ptr, cp, esc)) { - s--; /* forget escape */ - cnt = 1; - } - } - - if (s == 0 && buf != NULL) - continue; - - if ((cp = realloc(buf, len + s + 1)) == NULL) { - free(buf); - return NULL; - } - buf = cp; - - (void) memcpy(buf + len, ptr, s); - len += s; - buf[len] = '\0'; - } - - if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL && - strchr(buf, esc) != NULL) { - ptr = cp = buf; - while (cp[0] != '\0') { - int skipesc; - - while (cp[0] != '\0' && cp[0] != esc) - *ptr++ = *cp++; - if (cp[0] == '\0' || cp[1] == '\0') - break; - - skipesc = 0; - if (cp[1] == com) - skipesc += (flags & FPARSELN_UNESCCOMM); - if (cp[1] == con) - skipesc += (flags & FPARSELN_UNESCCONT); - if (cp[1] == esc) - skipesc += (flags & FPARSELN_UNESCESC); - if (cp[1] != com && cp[1] != con && cp[1] != esc) - skipesc = (flags & FPARSELN_UNESCREST); - - if (skipesc) - cp++; - else - *ptr++ = *cp++; - *ptr++ = *cp++; - } - *ptr = '\0'; - len = strlen(buf); - } - - if (size) - *size = len; - return buf; -} diff --git a/foobar/portable/openbsd-compat/freezero.c b/foobar/portable/openbsd-compat/freezero.c deleted file mode 100644 index da20d132..00000000 --- a/foobar/portable/openbsd-compat/freezero.c +++ /dev/null @@ -1,34 +0,0 @@ -/* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */ - -/* - * Copyright (c) 2004 Ted Unangst and Todd Miller - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* OPENBSD ORIGINAL: lib/libc/stdlib/malloc.c */ - -#include "includes.h" - -#include -#include - -void -freezero(void *ptr, size_t sz) -{ - if (ptr == NULL) - return; - explicit_bzero(ptr, sz); - free(ptr); -} diff --git a/foobar/portable/openbsd-compat/getopt.c b/foobar/portable/openbsd-compat/getopt.c deleted file mode 100644 index 5450e43d..00000000 --- a/foobar/portable/openbsd-compat/getopt.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 1987, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */ - -#include "includes.h" -#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET) - -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getopt.c,v 1.5 2003/06/02 20:18:37 millert Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include - -int BSDopterr = 1, /* if error message should be printed */ - BSDoptind = 1, /* index into parent argv vector */ - BSDoptopt, /* character checked for validity */ - BSDoptreset; /* reset getopt */ -char *BSDoptarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int -BSDgetopt(nargc, nargv, ostr) - int nargc; - char * const *nargv; - const char *ostr; -{ - extern char *__progname; - static char *place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ - - if (ostr == NULL) - return (-1); - - if (BSDoptreset || !*place) { /* update scanning pointer */ - BSDoptreset = 0; - if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') { - place = EMSG; - return (-1); - } - if (place[1] && *++place == '-') { /* found "--" */ - ++BSDoptind; - place = EMSG; - return (-1); - } - } /* option letter okay? */ - if ((BSDoptopt = (int)*place++) == (int)':' || - !(oli = strchr(ostr, BSDoptopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means -1. - */ - if (BSDoptopt == (int)'-') - return (-1); - if (!*place) - ++BSDoptind; - if (BSDopterr && *ostr != ':') - (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, BSDoptopt); - return (BADCH); - } - if (*++oli != ':') { /* don't need argument */ - BSDoptarg = NULL; - if (!*place) - ++BSDoptind; - } - else { /* need an argument */ - if (*place) /* no white space */ - BSDoptarg = place; - else if (nargc <= ++BSDoptind) { /* no arg */ - place = EMSG; - if (*ostr == ':') - return (BADARG); - if (BSDopterr) - (void)fprintf(stderr, - "%s: option requires an argument -- %c\n", - __progname, BSDoptopt); - return (BADCH); - } - else /* white space */ - BSDoptarg = nargv[BSDoptind]; - place = EMSG; - ++BSDoptind; - } - return (BSDoptopt); /* dump back option letter */ -} - -#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */ diff --git a/foobar/portable/openbsd-compat/getpeereid.c b/foobar/portable/openbsd-compat/getpeereid.c deleted file mode 100644 index c8ce808f..00000000 --- a/foobar/portable/openbsd-compat/getpeereid.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2002,2004 Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include - -#include - -#if defined(SO_PEERCRED) -int -getpeereid(int s, uid_t *euid, gid_t *gid) -{ - struct ucred cred; - socklen_t len = sizeof(cred); - - if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0) - return (-1); - *euid = cred.uid; - *gid = cred.gid; - - return (0); -} -#elif defined(HAVE_GETPEERUCRED) - -#ifdef HAVE_UCRED_H -# include -#endif - -int -getpeereid(int s, uid_t *euid, gid_t *gid) -{ - ucred_t *ucred = NULL; - - if (getpeerucred(s, &ucred) == -1) - return (-1); - if ((*euid = ucred_geteuid(ucred)) == -1) - return (-1); - if ((*gid = ucred_getrgid(ucred)) == -1) - return (-1); - - ucred_free(ucred); - - return (0); -} -#else -int -getpeereid(int s, uid_t *euid, gid_t *gid) -{ - *euid = geteuid(); - *gid = getgid(); - - return (0); -} -#endif /* defined(SO_PEERCRED) */ diff --git a/foobar/portable/openbsd-compat/imsg-buffer.c b/foobar/portable/openbsd-compat/imsg-buffer.c deleted file mode 100644 index e3762092..00000000 --- a/foobar/portable/openbsd-compat/imsg-buffer.c +++ /dev/null @@ -1,310 +0,0 @@ -/* $OpenBSD: imsg-buffer.c,v 1.3 2013/11/13 20:40:24 benno Exp $ */ - -/* - * Copyright (c) 2003, 2004 Henning Brauer - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include - -#include -#include -#include -#ifndef HAVE_EXPLICIT_BZERO -#include -#endif -#include - -#include "imsg.h" - -int ibuf_realloc(struct ibuf *, size_t); -void ibuf_enqueue(struct msgbuf *, struct ibuf *); -void ibuf_dequeue(struct msgbuf *, struct ibuf *); - -struct ibuf * -ibuf_open(size_t len) -{ - struct ibuf *buf; - - if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) - return (NULL); - if ((buf->buf = malloc(len)) == NULL) { - free(buf); - return (NULL); - } - buf->size = buf->max = len; - buf->fd = -1; - - return (buf); -} - -struct ibuf * -ibuf_dynamic(size_t len, size_t max) -{ - struct ibuf *buf; - - if (max < len) - return (NULL); - - if ((buf = ibuf_open(len)) == NULL) - return (NULL); - - if (max > 0) - buf->max = max; - - return (buf); -} - -int -ibuf_realloc(struct ibuf *buf, size_t len) -{ - u_char *b; - - /* on static buffers max is eq size and so the following fails */ - if (buf->wpos + len > buf->max) { - errno = ENOMEM; - return (-1); - } - - b = realloc(buf->buf, buf->wpos + len); - if (b == NULL) - return (-1); - buf->buf = b; - buf->size = buf->wpos + len; - - return (0); -} - -int -ibuf_add(struct ibuf *buf, const void *data, size_t len) -{ - if (buf->wpos + len > buf->size) - if (ibuf_realloc(buf, len) == -1) - return (-1); - - memcpy(buf->buf + buf->wpos, data, len); - buf->wpos += len; - return (0); -} - -void * -ibuf_reserve(struct ibuf *buf, size_t len) -{ - void *b; - - if (buf->wpos + len > buf->size) - if (ibuf_realloc(buf, len) == -1) - return (NULL); - - b = buf->buf + buf->wpos; - buf->wpos += len; - return (b); -} - -void * -ibuf_seek(struct ibuf *buf, size_t pos, size_t len) -{ - /* only allowed to seek in already written parts */ - if (pos + len > buf->wpos) - return (NULL); - - return (buf->buf + pos); -} - -size_t -ibuf_size(struct ibuf *buf) -{ - return (buf->wpos); -} - -size_t -ibuf_left(struct ibuf *buf) -{ - return (buf->max - buf->wpos); -} - -void -ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) -{ - ibuf_enqueue(msgbuf, buf); -} - -int -ibuf_write(struct msgbuf *msgbuf) -{ - struct iovec iov[IOV_MAX]; - struct ibuf *buf; - unsigned int i = 0; - ssize_t n; - - bzero(&iov, sizeof(iov)); - TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { - if (i >= IOV_MAX) - break; - iov[i].iov_base = buf->buf + buf->rpos; - iov[i].iov_len = buf->wpos - buf->rpos; - i++; - } - -again: - if ((n = writev(msgbuf->fd, iov, i)) == -1) { - if (errno == EINTR) - goto again; - if (errno == ENOBUFS) - errno = EAGAIN; - return (-1); - } - - if (n == 0) { /* connection closed */ - errno = 0; - return (0); - } - - msgbuf_drain(msgbuf, n); - - return (1); -} - -void -ibuf_free(struct ibuf *buf) -{ - free(buf->buf); - free(buf); -} - -void -msgbuf_init(struct msgbuf *msgbuf) -{ - msgbuf->queued = 0; - msgbuf->fd = -1; - TAILQ_INIT(&msgbuf->bufs); -} - -void -msgbuf_drain(struct msgbuf *msgbuf, size_t n) -{ - struct ibuf *buf, *next; - - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - ibuf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } -} - -void -msgbuf_clear(struct msgbuf *msgbuf) -{ - struct ibuf *buf; - - while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) - ibuf_dequeue(msgbuf, buf); -} - -int -msgbuf_write(struct msgbuf *msgbuf) -{ - struct iovec iov[IOV_MAX]; - struct ibuf *buf; - unsigned int i = 0; - ssize_t n; - struct msghdr msg; - struct cmsghdr *cmsg; - union { - struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int))]; - } cmsgbuf; - - bzero(&iov, sizeof(iov)); - bzero(&msg, sizeof(msg)); - TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { - if (i >= IOV_MAX) - break; - iov[i].iov_base = buf->buf + buf->rpos; - iov[i].iov_len = buf->wpos - buf->rpos; - i++; - if (buf->fd != -1) - break; - } - - msg.msg_iov = iov; - msg.msg_iovlen = i; - - if (buf != NULL && buf->fd != -1) { - msg.msg_control = (caddr_t)&cmsgbuf.buf; - msg.msg_controllen = sizeof(cmsgbuf.buf); - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - *(int *)CMSG_DATA(cmsg) = buf->fd; - } - -again: - if ((n = sendmsg(msgbuf->fd, &msg, 0)) == -1) { - if (errno == EINTR) - goto again; - if (errno == ENOBUFS) - errno = EAGAIN; - return (-1); - } - - if (n == 0) { /* connection closed */ - errno = 0; - return (0); - } - - /* - * assumption: fd got sent if sendmsg sent anything - * this works because fds are passed one at a time - */ - if (buf != NULL && buf->fd != -1) { - close(buf->fd); - buf->fd = -1; - } - - msgbuf_drain(msgbuf, n); - - return (1); -} - -void -ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) -{ - TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); - msgbuf->queued++; -} - -void -ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) -{ - TAILQ_REMOVE(&msgbuf->bufs, buf, entry); - - if (buf->fd != -1) - close(buf->fd); - - msgbuf->queued--; - ibuf_free(buf); -} diff --git a/foobar/portable/openbsd-compat/imsg.c b/foobar/portable/openbsd-compat/imsg.c deleted file mode 100644 index a5900a05..00000000 --- a/foobar/portable/openbsd-compat/imsg.c +++ /dev/null @@ -1,330 +0,0 @@ -/* $OpenBSD: imsg.c,v 1.5 2013/12/26 17:32:33 eric Exp $ */ - -/* - * Copyright (c) 2003, 2004 Henning Brauer - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include - -#include -#include -#include -#ifndef HAVE_EXPLICIT_BZERO -#include -#endif -#include - -#include "imsg.h" - -int imsg_fd_overhead = 0; - -int imsg_get_fd(struct imsgbuf *); - -int -available_fds(unsigned int n) -{ - unsigned int i; - int ret, fds[256]; - - if (n > (sizeof(fds)/sizeof(fds[0]))) - return (1); - - ret = 0; - for (i = 0; i < n; i++) { - fds[i] = -1; - if ((fds[i] = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - ret = 1; - break; - } - } - - for (i = 0; i < n && fds[i] >= 0; i++) - close(fds[i]); - - return (ret); -} - -void -imsg_init(struct imsgbuf *ibuf, int fd) -{ - msgbuf_init(&ibuf->w); - bzero(&ibuf->r, sizeof(ibuf->r)); - ibuf->fd = fd; - ibuf->w.fd = fd; - ibuf->pid = getpid(); - TAILQ_INIT(&ibuf->fds); -} - -ssize_t -imsg_read(struct imsgbuf *ibuf) -{ - struct msghdr msg; - struct cmsghdr *cmsg; - union { - struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int) * 1)]; - } cmsgbuf; - struct iovec iov; - ssize_t n = -1; - int fd; - struct imsg_fd *ifd; - - bzero(&msg, sizeof(msg)); - - iov.iov_base = ibuf->r.buf + ibuf->r.wpos; - iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = &cmsgbuf.buf; - msg.msg_controllen = sizeof(cmsgbuf.buf); - - if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL) - return (-1); - -again: - if (available_fds(imsg_fd_overhead + - (CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))) { - errno = EAGAIN; - free(ifd); - return (-1); - } - - if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) { - if (errno == EMSGSIZE) - goto fail; - if (errno != EINTR && errno != EAGAIN) - goto fail; - goto again; - } - - ibuf->r.wpos += n; - - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_RIGHTS) { - int i; - int j; - - /* - * We only accept one file descriptor. Due to C - * padding rules, our control buffer might contain - * more than one fd, and we must close them. - */ - j = ((char *)cmsg + cmsg->cmsg_len - - (char *)CMSG_DATA(cmsg)) / sizeof(int); - for (i = 0; i < j; i++) { - fd = ((int *)CMSG_DATA(cmsg))[i]; - if (ifd != NULL) { - ifd->fd = fd; - TAILQ_INSERT_TAIL(&ibuf->fds, ifd, - entry); - ifd = NULL; - } else - close(fd); - } - } - /* we do not handle other ctl data level */ - } - -fail: - if (ifd) - free(ifd); - return (n); -} - -ssize_t -imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) -{ - size_t av, left, datalen; - - av = ibuf->r.wpos; - - if (IMSG_HEADER_SIZE > av) - return (0); - - memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr)); - if (imsg->hdr.len < IMSG_HEADER_SIZE || - imsg->hdr.len > MAX_IMSGSIZE) { - errno = ERANGE; - return (-1); - } - if (imsg->hdr.len > av) - return (0); - datalen = imsg->hdr.len - IMSG_HEADER_SIZE; - ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE; - if ((imsg->data = malloc(datalen)) == NULL) - return (-1); - - if (imsg->hdr.flags & IMSGF_HASFD) - imsg->fd = imsg_get_fd(ibuf); - else - imsg->fd = -1; - - memcpy(imsg->data, ibuf->r.rptr, datalen); - - if (imsg->hdr.len < av) { - left = av - imsg->hdr.len; - memmove(&ibuf->r.buf, ibuf->r.buf + imsg->hdr.len, left); - ibuf->r.wpos = left; - } else - ibuf->r.wpos = 0; - - return (datalen + IMSG_HEADER_SIZE); -} - -int -imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, - pid_t pid, int fd, const void *data, uint16_t datalen) -{ - struct ibuf *wbuf; - - if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) - return (-1); - - if (imsg_add(wbuf, data, datalen) == -1) - return (-1); - - wbuf->fd = fd; - - imsg_close(ibuf, wbuf); - - return (1); -} - -int -imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, - pid_t pid, int fd, const struct iovec *iov, int iovcnt) -{ - struct ibuf *wbuf; - int i, datalen = 0; - - for (i = 0; i < iovcnt; i++) - datalen += iov[i].iov_len; - - if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) - return (-1); - - for (i = 0; i < iovcnt; i++) - if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1) - return (-1); - - wbuf->fd = fd; - - imsg_close(ibuf, wbuf); - - return (1); -} - -/* ARGSUSED */ -struct ibuf * -imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, - pid_t pid, uint16_t datalen) -{ - struct ibuf *wbuf; - struct imsg_hdr hdr; - - datalen += IMSG_HEADER_SIZE; - if (datalen > MAX_IMSGSIZE) { - errno = ERANGE; - return (NULL); - } - - hdr.type = type; - hdr.flags = 0; - hdr.peerid = peerid; - if ((hdr.pid = pid) == 0) - hdr.pid = ibuf->pid; - if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { - return (NULL); - } - if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) - return (NULL); - - return (wbuf); -} - -int -imsg_add(struct ibuf *msg, const void *data, uint16_t datalen) -{ - if (datalen) - if (ibuf_add(msg, data, datalen) == -1) { - ibuf_free(msg); - return (-1); - } - return (datalen); -} - -void -imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) -{ - struct imsg_hdr *hdr; - - hdr = (struct imsg_hdr *)msg->buf; - - hdr->flags &= ~IMSGF_HASFD; - if (msg->fd != -1) - hdr->flags |= IMSGF_HASFD; - - hdr->len = (uint16_t)msg->wpos; - - ibuf_close(&ibuf->w, msg); -} - -void -imsg_free(struct imsg *imsg) -{ - free(imsg->data); -} - -int -imsg_get_fd(struct imsgbuf *ibuf) -{ - int fd; - struct imsg_fd *ifd; - - if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL) - return (-1); - - fd = ifd->fd; - TAILQ_REMOVE(&ibuf->fds, ifd, entry); - free(ifd); - - return (fd); -} - -int -imsg_flush(struct imsgbuf *ibuf) -{ - while (ibuf->w.queued) - if (msgbuf_write(&ibuf->w) <= 0) - return (-1); - return (0); -} - -void -imsg_clear(struct imsgbuf *ibuf) -{ - int fd; - - msgbuf_clear(&ibuf->w); - while ((fd = imsg_get_fd(ibuf)) != -1) - close(fd); -} diff --git a/foobar/portable/openbsd-compat/imsg.h b/foobar/portable/openbsd-compat/imsg.h deleted file mode 100644 index 3757c8b9..00000000 --- a/foobar/portable/openbsd-compat/imsg.h +++ /dev/null @@ -1,115 +0,0 @@ -/* $OpenBSD: imsg.h,v 1.3 2013/12/26 17:32:33 eric Exp $ */ - -/* - * Copyright (c) 2006, 2007 Pierre-Yves Ritschard - * Copyright (c) 2006, 2007, 2008 Reyk Floeter - * Copyright (c) 2003, 2004 Henning Brauer - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _IMSG_H_ -#define _IMSG_H_ - -#define IBUF_READ_SIZE 65535 -#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) -#define MAX_IMSGSIZE 16384 - -#include "defines.h" - -struct ibuf { - TAILQ_ENTRY(ibuf) entry; - u_char *buf; - size_t size; - size_t max; - size_t wpos; - size_t rpos; - int fd; -}; - -struct msgbuf { - TAILQ_HEAD(, ibuf) bufs; - uint32_t queued; - int fd; -}; - -struct ibuf_read { - u_char buf[IBUF_READ_SIZE]; - u_char *rptr; - size_t wpos; -}; - -struct imsg_fd { - TAILQ_ENTRY(imsg_fd) entry; - int fd; -}; - -struct imsgbuf { - TAILQ_HEAD(, imsg_fd) fds; - struct ibuf_read r; - struct msgbuf w; - int fd; - pid_t pid; -}; - -#define IMSGF_HASFD 1 - -struct imsg_hdr { - uint32_t type; - uint16_t len; - uint16_t flags; - uint32_t peerid; - uint32_t pid; -}; - -struct imsg { - struct imsg_hdr hdr; - int fd; - void *data; -}; - - -/* buffer.c */ -struct ibuf *ibuf_open(size_t); -struct ibuf *ibuf_dynamic(size_t, size_t); -int ibuf_add(struct ibuf *, const void *, size_t); -void *ibuf_reserve(struct ibuf *, size_t); -void *ibuf_seek(struct ibuf *, size_t, size_t); -size_t ibuf_size(struct ibuf *); -size_t ibuf_left(struct ibuf *); -void ibuf_close(struct msgbuf *, struct ibuf *); -int ibuf_write(struct msgbuf *); -void ibuf_free(struct ibuf *); -void msgbuf_init(struct msgbuf *); -void msgbuf_clear(struct msgbuf *); -int msgbuf_write(struct msgbuf *); -void msgbuf_drain(struct msgbuf *, size_t); - -/* imsg.c */ -int available_fds(unsigned int); -void imsg_init(struct imsgbuf *, int); -ssize_t imsg_read(struct imsgbuf *); -ssize_t imsg_get(struct imsgbuf *, struct imsg *); -int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, - int, const void *, uint16_t); -int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, - int, const struct iovec *, int); -struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, - uint16_t); -int imsg_add(struct ibuf *, const void *, uint16_t); -void imsg_close(struct imsgbuf *, struct ibuf *); -void imsg_free(struct imsg *); -int imsg_flush(struct imsgbuf *); -void imsg_clear(struct imsgbuf *); - -#endif diff --git a/foobar/portable/openbsd-compat/includes.h b/foobar/portable/openbsd-compat/includes.h deleted file mode 100644 index cd044a20..00000000 --- a/foobar/portable/openbsd-compat/includes.h +++ /dev/null @@ -1,75 +0,0 @@ -/* $OpenBSD: includes.h,v 1.54 2006/07/22 20:48:23 stevesk Exp $ */ - -/* - * Author: Tatu Ylonen - * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland - * All rights reserved - * This file includes most of the needed system headers. - * - * As far as I am concerned, the code I have written for this software - * can be used freely for any purpose. Any derived versions of this - * software must be clearly marked as such, and if the derived work is - * incompatible with the protocol description in the RFC file, it must be - * called by a name other than "ssh" or "Secure Shell". - */ - -#ifndef INCLUDES_H -#define INCLUDES_H - -#include "config.h" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE /* activate extra prototypes for glibc */ -#endif - -#include -#include /* For CMSG_* */ - -#ifdef HAVE_LIMITS_H -# include /* For PATH_MAX */ -#endif -#ifdef HAVE_BSTRING_H -# include -#endif - -#ifdef HAVE_ENDIAN_H -# include -#endif -#ifdef HAVE_MAILLOCK_H -# include /* For _PATH_MAILDIR */ -#endif -#ifdef HAVE_PATHS_H -# include -#endif - -#ifdef HAVE_RPC_TYPES_H -# include /* For INADDR_LOOPBACK */ -#endif -#ifdef USE_PAM -#if defined(HAVE_SECURITY_PAM_APPL_H) -# include -#elif defined (HAVE_PAM_PAM_APPL_H) -# include -#endif -#endif -#include - -/* chl */ -#ifdef HAVE_NETDB_H -# include -#endif -/* end of chl*/ - -#if !defined(NETDB_INTERNAL) -# define NETDB_INTERNAL (-1) -#endif - -#include /* For OPENSSL_VERSION_NUMBER */ - -#include "defines.h" - -#include "openbsd-compat.h" - -#include "entropy.h" - -#endif /* INCLUDES_H */ diff --git a/foobar/portable/openbsd-compat/inet_net_pton.c b/foobar/portable/openbsd-compat/inet_net_pton.c deleted file mode 100644 index b65cb76f..00000000 --- a/foobar/portable/openbsd-compat/inet_net_pton.c +++ /dev/null @@ -1,236 +0,0 @@ -/* $OpenBSD: inet_net_pton.c,v 1.8 2013/11/25 18:23:51 deraadt Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include "includes.h" -#ifndef HAVE_INET_NET_PTON - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static int inet_net_pton_ipv4(const char *, u_char *, size_t); -static int inet_net_pton_ipv6(const char *, u_char *, size_t); - -/* - * static int - * inet_net_pton(af, src, dst, size) - * convert network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not a valid network specification. - * author: - * Paul Vixie (ISC), June 1996 - */ -int -inet_net_pton(int af, const char *src, void *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_pton_ipv4(src, dst, size)); - case AF_INET6: - return (inet_net_pton_ipv6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (-1); - } -} - -/* - * static int - * inet_net_pton_ipv4(src, dst, size) - * convert IPv4 network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not an IPv4 network specification. - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), June 1996 - */ -static int -inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) -{ - static const char - xdigits[] = "0123456789abcdef", - digits[] = "0123456789"; - int n, ch, tmp, dirty, bits; - const u_char *odst = dst; - - ch = (unsigned char)*src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii((unsigned char)src[1]) && isxdigit((unsigned char)src[1])) { - /* Hexadecimal: Eat nybble string. */ - if (size <= 0) - goto emsgsize; - *dst = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - *dst |= n; - if (!dirty++) - *dst <<= 4; - else if (size-- > 0) - *++dst = 0, dirty = 0; - else - goto emsgsize; - } - if (dirty) - size--; - } else if (isascii(ch) && isdigit(ch)) { - /* Decimal: eat dotted digit string. */ - for (;;) { - tmp = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - tmp *= 10; - tmp += n; - if (tmp > 255) - goto enoent; - } while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (size-- <= 0) - goto emsgsize; - *dst++ = (u_char) tmp; - if (ch == '\0' || ch == '/') - break; - if (ch != '.') - goto enoent; - ch = (unsigned char)*src++; - if (!isascii(ch) || !isdigit(ch)) - goto enoent; - } - } else - goto enoent; - - bits = -1; - if (ch == '/' && isascii((unsigned char)src[0]) && - isdigit((unsigned char)src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = (unsigned char)*src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - bits *= 10; - bits += n; - if (bits > 32) - goto emsgsize; - } while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (ch != '\0') - goto enoent; - } - - /* Firey death and destruction unless we prefetched EOS. */ - if (ch != '\0') - goto enoent; - - /* If nothing was written to the destination, we found no address. */ - if (dst == odst) - goto enoent; - /* If no CIDR spec was given, infer width from net class. */ - if (bits == -1) { - if (*odst >= 240) /* Class E */ - bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ - bits = 24; - else if (*odst >= 128) /* Class B */ - bits = 16; - else /* Class A */ - bits = 8; - /* If imputed mask is narrower than specified octets, widen. */ - if (bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; - } - /* Extend network to cover the actual mask. */ - while (bits > ((dst - odst) * 8)) { - if (size-- <= 0) - goto emsgsize; - *dst++ = '\0'; - } - return (bits); - - enoent: - errno = ENOENT; - return (-1); - - emsgsize: - errno = EMSGSIZE; - return (-1); -} - - -static int -inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) -{ - int ret; - int bits; - char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")]; - char *sep; - const char *errstr; - - if (strlcpy(buf, src, sizeof buf) >= sizeof buf) { - errno = EMSGSIZE; - return (-1); - } - - sep = strchr(buf, '/'); - if (sep != NULL) - *sep++ = '\0'; - - ret = inet_pton(AF_INET6, buf, dst); - if (ret != 1) - return (-1); - - if (sep == NULL) - return 128; - - bits = strtonum(sep, 0, 128, &errstr); - if (errstr) { - errno = EINVAL; - return (-1); - } - - return bits; -} - -#endif diff --git a/foobar/portable/openbsd-compat/libasr/asr.c b/foobar/portable/openbsd-compat/libasr/asr.c deleted file mode 100644 index 90bc59b4..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr.c +++ /dev/null @@ -1,867 +0,0 @@ -/* $OpenBSD: asr.c,v 1.61 2018/10/22 17:31:24 krw Exp $ */ -/* - * Copyright (c) 2010-2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "asr_private.h" - -#include "thread_private.h" - -#define DEFAULT_CONF "lookup file\n" -#define DEFAULT_LOOKUP "lookup bind file" - -#define RELOAD_DELAY 15 /* seconds */ - -static void asr_check_reload(struct asr *); -static struct asr_ctx *asr_ctx_create(void); -static void asr_ctx_ref(struct asr_ctx *); -static void asr_ctx_free(struct asr_ctx *); -static int asr_ctx_add_searchdomain(struct asr_ctx *, const char *); -static int asr_ctx_from_file(struct asr_ctx *, const char *); -static int asr_ctx_from_string(struct asr_ctx *, const char *); -static int asr_ctx_parse(struct asr_ctx *, const char *); -static int asr_parse_nameserver(struct sockaddr *, const char *); -static int asr_ndots(const char *); -static void pass0(char **, int, struct asr_ctx *); -static int strsplit(char *, char **, int); -static void asr_ctx_envopts(struct asr_ctx *); -static void *__THREAD_NAME(_asr); - -static struct asr *_asr = NULL; - -#ifndef HAVE_ISSETUGID -#define issetugid() ((getuid() != geteuid())) -#endif - -/* Allocate and configure an async "resolver". */ -static void * -_asr_resolver(void) -{ - static int init = 0; - struct asr *asr; - - if (init == 0) { -#ifdef DEBUG - if (getenv("ASR_DEBUG")) - _asr_debug = stderr; -#endif - init = 1; - } - - if ((asr = calloc(1, sizeof(*asr))) == NULL) - goto fail; - - asr_check_reload(asr); - if (asr->a_ctx == NULL) { - if ((asr->a_ctx = asr_ctx_create()) == NULL) - goto fail; - if (asr_ctx_from_string(asr->a_ctx, DEFAULT_CONF) == -1) - goto fail; - asr_ctx_envopts(asr->a_ctx); - } - -#ifdef DEBUG - _asr_dump_config(_asr_debug, asr); -#endif - return (asr); - - fail: - if (asr) { - if (asr->a_ctx) - asr_ctx_free(asr->a_ctx); - free(asr); - } - - return (NULL); -} - -/* - * Free the "asr" async resolver (or the thread-local resolver if NULL). - * Drop the reference to the current context. - */ -void -_asr_resolver_done(void *arg) -{ - struct asr *asr = arg; - struct asr **priv; - - if (asr == NULL) { - priv = _THREAD_PRIVATE(_asr, _asr, &_asr); - if (*priv == NULL) - return; - asr = *priv; - *priv = NULL; - } - - _asr_ctx_unref(asr->a_ctx); - free(asr); -} - -/* - * Cancel an async query. - */ -void -asr_abort(struct asr_query *as) -{ - _asr_async_free(as); -} - -/* - * Resume the "as" async query resolution. Return one of ASYNC_COND, - * or ASYNC_DONE and put query-specific return values in the user-allocated - * memory at "ar". - */ -int -asr_run(struct asr_query *as, struct asr_result *ar) -{ - int r, saved_errno = errno; - - DPRINT("asr: asr_run(%p, %p) %s ctx=[%p]\n", as, ar, - _asr_querystr(as->as_type), as->as_ctx); - r = as->as_run(as, ar); - - DPRINT("asr: asr_run(%p, %p) -> %s", as, ar, _asr_transitionstr(r)); -#ifdef DEBUG - if (r == ASYNC_COND) -#endif - DPRINT(" fd=%i timeout=%i", ar->ar_fd, ar->ar_timeout); - DPRINT("\n"); - if (r == ASYNC_DONE) - _asr_async_free(as); - - errno = saved_errno; - - return (r); -} -DEF_WEAK(asr_run); - -static int -poll_intrsafe(struct pollfd *fds, nfds_t nfds, int timeout) -{ - struct timespec pollstart, pollend, elapsed; - int r; - - if (clock_gettime(CLOCK_MONOTONIC, &pollstart)) - return -1; - - while ((r = poll(fds, 1, timeout)) == -1 && errno == EINTR) { - if (clock_gettime(CLOCK_MONOTONIC, &pollend)) - return -1; - timespecsub(&pollend, &pollstart, &elapsed); - timeout -= elapsed.tv_sec * 1000 + elapsed.tv_nsec / 1000000; - if (timeout < 1) - return 0; - } - - return r; -} - -/* - * Same as asr_run, but run in a loop that handles the fd conditions result. - */ -int -asr_run_sync(struct asr_query *as, struct asr_result *ar) -{ - struct pollfd fds[1]; - int r, saved_errno = errno; - - while ((r = asr_run(as, ar)) == ASYNC_COND) { - fds[0].fd = ar->ar_fd; - fds[0].events = (ar->ar_cond == ASR_WANT_READ) ? POLLIN:POLLOUT; - - if (poll_intrsafe(fds, 1, ar->ar_timeout) == -1) { - memset(ar, 0, sizeof(*ar)); - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; - ar->ar_gai_errno = EAI_SYSTEM; - ar->ar_rrset_errno = NETDB_INTERNAL; - _asr_async_free(as); - errno = saved_errno; - return ASYNC_DONE; - } - - /* - * Otherwise, just ignore the error and let asr_run() - * catch the failure. - */ - } - - errno = saved_errno; - - return (r); -} -DEF_WEAK(asr_run_sync); - -/* - * Create a new async request of the given "type" on the async context "ac". - * Take a reference on it so it does not get deleted while the async query - * is running. - */ -struct asr_query * -_asr_async_new(struct asr_ctx *ac, int type) -{ - struct asr_query *as; - - DPRINT("asr: asr_async_new(ctx=%p) type=%i refcount=%i\n", ac, type, - ac ? ac->ac_refcount : 0); - if (ac == NULL || (as = calloc(1, sizeof(*as))) == NULL) - return (NULL); - - ac->ac_refcount += 1; - as->as_ctx = ac; - as->as_fd = -1; - as->as_type = type; - as->as_state = ASR_STATE_INIT; - - return (as); -} - -/* - * Free an async query and unref the associated context. - */ -void -_asr_async_free(struct asr_query *as) -{ - DPRINT("asr: asr_async_free(%p)\n", as); - - if (as->as_subq) - _asr_async_free(as->as_subq); - - switch (as->as_type) { - case ASR_SEND: - if (as->as_fd != -1) - close(as->as_fd); - if (as->as.dns.obuf && !(as->as_flags & ASYNC_EXTOBUF)) - free(as->as.dns.obuf); - if (as->as.dns.ibuf) - free(as->as.dns.ibuf); - if (as->as.dns.dname) - free(as->as.dns.dname); - break; - - case ASR_SEARCH: - if (as->as.search.name) - free(as->as.search.name); - break; - - case ASR_GETRRSETBYNAME: - if (as->as.rrset.name) - free(as->as.rrset.name); - break; - - case ASR_GETHOSTBYNAME: - case ASR_GETHOSTBYADDR: - if (as->as.hostnamadr.name) - free(as->as.hostnamadr.name); - break; - - case ASR_GETADDRINFO: - if (as->as.ai.aifirst) - freeaddrinfo(as->as.ai.aifirst); - if (as->as.ai.hostname) - free(as->as.ai.hostname); - if (as->as.ai.servname) - free(as->as.ai.servname); - if (as->as.ai.fqdn) - free(as->as.ai.fqdn); - break; - - case ASR_GETNAMEINFO: - break; - } - - _asr_ctx_unref(as->as_ctx); - free(as); -} - -/* - * Get a context from the given resolver. This takes a new reference to - * the returned context, which *must* be explicitly dropped when done - * using this context. - */ -struct asr_ctx * -_asr_use_resolver(void *arg) -{ - struct asr *asr = arg; - struct asr **priv; - - if (asr == NULL) { - DPRINT("using thread-local resolver\n"); - priv = _THREAD_PRIVATE(_asr, _asr, &_asr); - if (*priv == NULL) { - DPRINT("setting up thread-local resolver\n"); - *priv = _asr_resolver(); - } - asr = *priv; - } - if (asr != NULL) { - asr_check_reload(asr); - asr_ctx_ref(asr->a_ctx); - return (asr->a_ctx); - } - return (NULL); -} - -static void -asr_ctx_ref(struct asr_ctx *ac) -{ - DPRINT("asr: asr_ctx_ref(ctx=%p) refcount=%i\n", ac, ac->ac_refcount); - ac->ac_refcount += 1; -} - -/* - * Drop a reference to an async context, freeing it if the reference - * count drops to 0. - */ -void -_asr_ctx_unref(struct asr_ctx *ac) -{ - DPRINT("asr: asr_ctx_unref(ctx=%p) refcount=%i\n", ac, - ac ? ac->ac_refcount : 0); - if (ac == NULL) - return; - if (--ac->ac_refcount) - return; - - asr_ctx_free(ac); -} - -static void -asr_ctx_free(struct asr_ctx *ac) -{ - int i; - - if (ac->ac_domain) - free(ac->ac_domain); - for (i = 0; i < ASR_MAXNS; i++) - free(ac->ac_ns[i]); - for (i = 0; i < ASR_MAXDOM; i++) - free(ac->ac_dom[i]); - - free(ac); -} - -/* - * Reload the configuration file if it has changed on disk. - */ -static void -asr_check_reload(struct asr *asr) -{ - struct asr_ctx *ac; - struct stat st; - struct timespec ts; - pid_t pid; - - pid = getpid(); - if (pid != asr->a_pid) { - asr->a_pid = pid; - asr->a_rtime = 0; - } - - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) - return; - - if ((ts.tv_sec - asr->a_rtime) < RELOAD_DELAY && asr->a_rtime != 0) - return; - asr->a_rtime = ts.tv_sec; - - DPRINT("asr: checking for update of \"%s\"\n", _PATH_RESCONF); - if (stat(_PATH_RESCONF, &st) == -1 || - asr->a_mtime == st.st_mtime || - (ac = asr_ctx_create()) == NULL) - return; - asr->a_mtime = st.st_mtime; - - DPRINT("asr: reloading config file\n"); - if (asr_ctx_from_file(ac, _PATH_RESCONF) == -1) { - asr_ctx_free(ac); - return; - } - - asr_ctx_envopts(ac); - if (asr->a_ctx) - _asr_ctx_unref(asr->a_ctx); - asr->a_ctx = ac; -} - -/* - * Construct a fully-qualified domain name for the given name and domain. - * If "name" ends with a '.' it is considered as a FQDN by itself. - * Otherwise, the domain, which must be a FQDN, is appended to "name" (it - * may have a leading dot which would be ignored). If the domain is null, - * then "." is used. Return the length of the constructed FQDN or (0) on - * error. - */ -size_t -_asr_make_fqdn(const char *name, const char *domain, char *buf, size_t buflen) -{ - size_t len; - - if (domain == NULL) - domain = "."; - else if ((len = strlen(domain)) == 0) - return (0); - else if (domain[len -1] != '.') - return (0); - - len = strlen(name); - if (len == 0) { - if (strlcpy(buf, domain, buflen) >= buflen) - return (0); - } else if (name[len - 1] != '.') { - if (domain[0] == '.') - domain += 1; - if (strlcpy(buf, name, buflen) >= buflen || - strlcat(buf, ".", buflen) >= buflen || - strlcat(buf, domain, buflen) >= buflen) - return (0); - } else { - if (strlcpy(buf, name, buflen) >= buflen) - return (0); - } - - return (strlen(buf)); -} - -/* - * Count the dots in a string. - */ -static int -asr_ndots(const char *s) -{ - int n; - - for (n = 0; *s; s++) - if (*s == '.') - n += 1; - - return (n); -} - -/* - * Allocate a new empty context. - */ -static struct asr_ctx * -asr_ctx_create(void) -{ - struct asr_ctx *ac; - - if ((ac = calloc(1, sizeof(*ac))) == NULL) - return (NULL); - - ac->ac_options = RES_RECURSE | RES_DEFNAMES | RES_DNSRCH; - ac->ac_refcount = 1; - ac->ac_ndots = 1; -#ifndef ASR_IPV4_BEFORE_IPV6 - ac->ac_family[0] = AF_INET6; - ac->ac_family[1] = AF_INET; -#else - ac->ac_family[0] = AF_INET; - ac->ac_family[1] = AF_INET6; -#endif - ac->ac_family[2] = -1; - - ac->ac_nscount = 0; - ac->ac_nstimeout = 5; - ac->ac_nsretries = 4; - - return (ac); -} - -struct asr_ctx * -_asr_no_resolver(void) -{ - return asr_ctx_create(); -} - -/* - * Add a search domain to the async context. - */ -static int -asr_ctx_add_searchdomain(struct asr_ctx *ac, const char *domain) -{ - char buf[MAXDNAME]; - - if (ac->ac_domcount == ASR_MAXDOM) - return (-1); - - if (_asr_make_fqdn(domain, NULL, buf, sizeof(buf)) == 0) - return (-1); - - if ((ac->ac_dom[ac->ac_domcount] = strdup(buf)) == NULL) - return (0); - - ac->ac_domcount += 1; - - return (1); -} - -static int -strsplit(char *line, char **tokens, int ntokens) -{ - int ntok; - char *cp, **tp; - - for (cp = line, tp = tokens, ntok = 0; - ntok < ntokens && (*tp = strsep(&cp, " \t")) != NULL; ) - if (**tp != '\0') { - tp++; - ntok++; - } - - return (ntok); -} - -/* - * Pass on a split config line. - */ -static void -pass0(char **tok, int n, struct asr_ctx *ac) -{ - int i, j, d; - const char *e; - struct sockaddr_storage ss; - - if (!strcmp(tok[0], "nameserver")) { - if (ac->ac_nscount == ASR_MAXNS) - return; - if (n != 2) - return; - if (asr_parse_nameserver((struct sockaddr *)&ss, tok[1])) - return; - if ((ac->ac_ns[ac->ac_nscount] = calloc(1, SS_LEN(&ss))) == NULL) - return; - memmove(ac->ac_ns[ac->ac_nscount], &ss, SS_LEN(&ss)); - ac->ac_nscount += 1; - - } else if (!strcmp(tok[0], "domain")) { - if (n != 2) - return; - if (ac->ac_domain) - return; - ac->ac_domain = strdup(tok[1]); - - } else if (!strcmp(tok[0], "lookup")) { - /* ensure that each lookup is only given once */ - for (i = 1; i < n; i++) - for (j = i + 1; j < n; j++) - if (!strcmp(tok[i], tok[j])) - return; - ac->ac_dbcount = 0; - for (i = 1; i < n && ac->ac_dbcount < ASR_MAXDB; i++) { - if (!strcmp(tok[i], "yp")) { - /* silently deprecated */ - } else if (!strcmp(tok[i], "bind")) - ac->ac_db[ac->ac_dbcount++] = ASR_DB_DNS; - else if (!strcmp(tok[i], "file")) - ac->ac_db[ac->ac_dbcount++] = ASR_DB_FILE; - } - } else if (!strcmp(tok[0], "search")) { - /* resolv.conf says the last line wins */ - for (i = 0; i < ASR_MAXDOM; i++) { - free(ac->ac_dom[i]); - ac->ac_dom[i] = NULL; - } - ac->ac_domcount = 0; - for (i = 1; i < n; i++) - asr_ctx_add_searchdomain(ac, tok[i]); - - } else if (!strcmp(tok[0], "family")) { - if (n == 1 || n > 3) - return; - for (i = 1; i < n; i++) - if (strcmp(tok[i], "inet4") && strcmp(tok[i], "inet6")) - return; - for (i = 1; i < n; i++) - ac->ac_family[i - 1] = strcmp(tok[i], "inet4") ? \ - AF_INET6 : AF_INET; - ac->ac_family[i - 1] = -1; - - } else if (!strcmp(tok[0], "options")) { - for (i = 1; i < n; i++) { - if (!strcmp(tok[i], "tcp")) - ac->ac_options |= RES_USEVC; - else if (!strcmp(tok[i], "edns0")) - ac->ac_options |= RES_USE_EDNS0; - else if ((!strncmp(tok[i], "ndots:", 6))) { - e = NULL; - d = strtonum(tok[i] + 6, 1, 16, &e); - if (e == NULL) - ac->ac_ndots = d; - } - } - } -} - -/* - * Setup an async context with the config specified in the string "str". - */ -static int -asr_ctx_from_string(struct asr_ctx *ac, const char *str) -{ - char buf[512], *ch; - - asr_ctx_parse(ac, str); - - if (ac->ac_dbcount == 0) { - /* No lookup directive */ - asr_ctx_parse(ac, DEFAULT_LOOKUP); - } - - if (ac->ac_nscount == 0) - asr_ctx_parse(ac, "nameserver 127.0.0.1"); - - if (ac->ac_domain == NULL) - if (gethostname(buf, sizeof buf) == 0) { - ch = strchr(buf, '.'); - if (ch) - ac->ac_domain = strdup(ch + 1); - else /* Assume root. see resolv.conf(5) */ - ac->ac_domain = strdup(""); - } - - /* If no search domain was specified, use the local subdomains */ - if (ac->ac_domcount == 0) - for (ch = ac->ac_domain; ch; ) { - asr_ctx_add_searchdomain(ac, ch); - ch = strchr(ch, '.'); - if (ch && asr_ndots(++ch) == 0) - break; - } - - return (0); -} - -/* - * Setup the "ac" async context from the file at location "path". - */ -static int -asr_ctx_from_file(struct asr_ctx *ac, const char *path) -{ - FILE *cf; - char buf[4096]; - ssize_t r; - - cf = fopen(path, "re"); - if (cf == NULL) - return (-1); - - r = fread(buf, 1, sizeof buf - 1, cf); - if (feof(cf) == 0) { - DPRINT("asr: config file too long: \"%s\"\n", path); - r = -1; - } - fclose(cf); - if (r == -1) - return (-1); - buf[r] = '\0'; - - return asr_ctx_from_string(ac, buf); -} - -/* - * Parse lines in the configuration string. For each one, split it into - * tokens and pass them to "pass0" for processing. - */ -static int -asr_ctx_parse(struct asr_ctx *ac, const char *str) -{ - size_t len; - const char *line; - char buf[1024]; - char *tok[10]; - int ntok; - - line = str; - while (*line) { - len = strcspn(line, "\n\0"); - if (len < sizeof buf) { - memmove(buf, line, len); - buf[len] = '\0'; - } else - buf[0] = '\0'; - line += len; - if (*line == '\n') - line++; - buf[strcspn(buf, ";#")] = '\0'; - if ((ntok = strsplit(buf, tok, 10)) == 0) - continue; - - pass0(tok, ntok, ac); - } - - return (0); -} - -/* - * Check for environment variables altering the configuration as described - * in resolv.conf(5). Although not documented there, this feature is disabled - * for setuid/setgid programs. - */ -static void -asr_ctx_envopts(struct asr_ctx *ac) -{ - char buf[4096], *e; - size_t s; - - if (issetugid()) { - ac->ac_options |= RES_NOALIASES; - return; - } - - if ((e = getenv("RES_OPTIONS")) != NULL) { - strlcpy(buf, "options ", sizeof buf); - strlcat(buf, e, sizeof buf); - s = strlcat(buf, "\n", sizeof buf); - if (s < sizeof buf) - asr_ctx_parse(ac, buf); - } - - if ((e = getenv("LOCALDOMAIN")) != NULL) { - strlcpy(buf, "search ", sizeof buf); - strlcat(buf, e, sizeof buf); - s = strlcat(buf, "\n", sizeof buf); - if (s < sizeof buf) - asr_ctx_parse(ac, buf); - } -} - -/* - * Parse a resolv.conf(5) nameserver string into a sockaddr. - */ -static int -asr_parse_nameserver(struct sockaddr *sa, const char *s) -{ - in_port_t portno = 53; - - if (_asr_sockaddr_from_str(sa, PF_UNSPEC, s) == -1) - return (-1); - - if (sa->sa_family == PF_INET) - ((struct sockaddr_in *)sa)->sin_port = htons(portno); - else if (sa->sa_family == PF_INET6) - ((struct sockaddr_in6 *)sa)->sin6_port = htons(portno); - - return (0); -} - -/* - * Turn a (uncompressed) DNS domain name into a regular nul-terminated string - * where labels are separated by dots. The result is put into the "buf" buffer, - * truncated if it exceeds "max" chars. The function returns "buf". - */ -char * -_asr_strdname(const char *_dname, char *buf, size_t max) -{ - const unsigned char *dname = _dname; - char *res; - size_t left, n, count; - - if (_dname[0] == 0) { - strlcpy(buf, ".", max); - return buf; - } - - res = buf; - left = max - 1; - for (n = 0; dname[0] && left; n += dname[0]) { - count = (dname[0] < (left - 1)) ? dname[0] : (left - 1); - memmove(buf, dname + 1, count); - dname += dname[0] + 1; - left -= count; - buf += count; - if (left) { - left -= 1; - *buf++ = '.'; - } - } - buf[0] = 0; - - return (res); -} - -/* - * Read and split the next line from the given namedb file. - * Return -1 on error, or put the result in the "tokens" array of - * size "ntoken" and returns the number of token on the line. - */ -int -_asr_parse_namedb_line(FILE *file, char **tokens, int ntoken, char *lbuf, size_t sz) -{ - size_t len; - char *buf; - int ntok; - - again: - if ((buf = fgetln(file, &len)) == NULL) - return (-1); - - if (len >= sz) - goto again; - - if (buf[len - 1] == '\n') - len--; - else { - memcpy(lbuf, buf, len); - buf = lbuf; - } - - buf[len] = '\0'; - buf[strcspn(buf, "#")] = '\0'; - if ((ntok = strsplit(buf, tokens, ntoken)) == 0) - goto again; - - return (ntok); -} - -/* - * Update the async context so that it uses the next configured DB. - * Return 0 on success, or -1 if no more DBs is available. - */ -int -_asr_iter_db(struct asr_query *as) -{ - if (as->as_db_idx >= as->as_ctx->ac_dbcount) { - DPRINT("asr_iter_db: done\n"); - return (-1); - } - - as->as_db_idx += 1; - DPRINT("asr_iter_db: %i\n", as->as_db_idx); - - return (0); -} diff --git a/foobar/portable/openbsd-compat/libasr/asr.h b/foobar/portable/openbsd-compat/libasr/asr.h deleted file mode 100644 index e9725e6b..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr.h +++ /dev/null @@ -1,95 +0,0 @@ -/* $OpenBSD: asr.h,v 1.1 2014/03/26 18:13:15 eric Exp $ */ -/* - * Copyright (c) 2012-2014 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Expected fd conditions - */ -#define ASR_WANT_READ 1 -#define ASR_WANT_WRITE 2 - -/* - * Structure through which asynchronous query results are returned when - * calling asr_run(). - */ -struct asr_result { - /* Fields set if the query is not done yet (asr_run returns 0) */ - int ar_cond; /* ASR_WANT_READ or ASR_WANT_WRITE */ - int ar_fd; /* the fd waiting for io condition */ - int ar_timeout; /* time to wait for in milliseconds */ - - /* Error fields. Depends on the query type. */ - int ar_errno; - int ar_h_errno; - int ar_gai_errno; - int ar_rrset_errno; - - /* Result for res_*_async() calls */ - int ar_count; /* number of answers in the dns reply */ - int ar_rcode; /* response code in the dns reply */ - void *ar_data; /* raw reply packet (must be freed) */ - int ar_datalen; /* reply packet length */ - struct sockaddr_storage ar_ns; /* nameserver that responded */ - - /* Result for other calls. Must be freed properly. */ - struct addrinfo *ar_addrinfo; - struct rrsetinfo *ar_rrsetinfo; - struct hostent *ar_hostent; - struct netent *ar_netent; -}; - -/* - * Asynchronous query management. - */ - -/* Forward declaration. The API uses opaque pointers as query handles. */ -struct asr_query; - -int asr_run(struct asr_query *, struct asr_result *); -int asr_run_sync(struct asr_query *, struct asr_result *); -void asr_abort(struct asr_query *); - -/* - * Asynchronous version of the resolver functions. Similar prototypes, with - * an extra context parameter at the end which must currently be set to NULL. - * All functions return a handle suitable for use with the management functions - * above. - */ -struct asr_query *res_send_async(const unsigned char *, int, void *); -struct asr_query *res_query_async(const char *, int, int, void *); -struct asr_query *res_search_async(const char *, int, int, void *); - -struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int, - unsigned int, void *); - -struct asr_query *gethostbyname_async(const char *, void *); -struct asr_query *gethostbyname2_async(const char *, int, void *); -struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *); - -struct asr_query *getnetbyname_async(const char *, void *); -struct asr_query *getnetbyaddr_async(in_addr_t, int, void *); - -struct asr_query *getaddrinfo_async(const char *, const char *, - const struct addrinfo *, void *); -struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *, - size_t, char *, size_t, int, void *); - -/* only there for -portable */ -void asr_freeaddrinfo(struct addrinfo *); - -/* from in event.h */ -struct event_asr * event_asr_run(struct asr_query *, - void (*)(struct asr_result *, void *), void *); diff --git a/foobar/portable/openbsd-compat/libasr/asr_compat.c b/foobar/portable/openbsd-compat/libasr/asr_compat.c deleted file mode 100644 index ee958357..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr_compat.c +++ /dev/null @@ -1,102 +0,0 @@ -/* $OpenBSD: asr_debug.c,v 1.25 2018/04/28 15:16:49 schwarze Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif - -#include "asr_compat.h" - -#ifndef HAVE___P_CLASS -const char * -__p_class(int c) -{ - switch(c) { - case C_IN: return "IN"; - case C_CHAOS: return "CHAOS"; - case C_HS: return "HESIOD"; - case C_ANY: return "ANY"; - default: return "?"; - } -}; -#endif /* !HAVE___P_CLASS */ - -#ifndef HAVE___P_TYPE -const char * -__p_type(int t) -{ - switch(t) { - case T_A: return "A"; - case T_NS: return "NS"; - case T_MD: return "MD"; - case T_MF: return "MF"; - case T_CNAME: return "CNAME"; - case T_SOA: return "SOA"; - case T_MB: return "MB"; - case T_MG: return "MG"; - case T_MR: return "MR"; - case T_NULL: return "NULL"; - case T_WKS: return "WKS"; - case T_PTR: return "PTR"; - case T_HINFO: return "HINFO"; - case T_MINFO: return "MINFO"; - case T_MX: return "MX"; - case T_TXT: return "TXT"; - case T_RP: return "RP"; - case T_AFSDB: return "AFSDB"; - case T_X25: return "X25"; - case T_ISDN: return "ISDN"; - case T_RT: return "RT"; - case T_NSAP: return "NSAP"; - case T_NSAP_PTR:return"NSAP_PTR"; - case T_SIG: return "SIG"; - case T_KEY: return "KEY"; - case T_PX: return "PX"; - case T_GPOS: return "GPOS"; - case T_AAAA: return "AAAA"; - case T_LOC: return "LOC"; - case T_NXT: return "NXT"; - case T_EID: return "EID"; - case T_NIMLOC: return "NIMLOC"; - case T_SRV: return "SRV"; - case T_ATMA: return "ATMA"; - case T_OPT: return "OPT"; - case T_IXFR: return "IXFR"; - case T_AXFR: return "AXFR"; - case T_MAILB: return "MAILB"; - case T_MAILA: return "MAILA"; -#ifdef T_UINFO - case T_UINFO: return "UINFO"; -#endif -#ifdef T_UID - case T_UID: return "UID"; -#endif -#ifdef T_GID - case T_GID: return "GID"; -#endif - case T_NAPTR: return "NAPTR"; -#ifdef T_UNSPEC - case T_UNSPEC: return "UNSPEC"; -#endif - case T_ANY: return "ANY"; - default: return "?"; - } -} -#endif /* !HAVE___P_TYPE */ diff --git a/foobar/portable/openbsd-compat/libasr/asr_compat.h b/foobar/portable/openbsd-compat/libasr/asr_compat.h deleted file mode 100644 index 2c7686a4..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr_compat.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2018 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -/* source compat */ -#define ASR_BUFSIZ 1024 - -#define DEF_WEAK(x) -#define __THREAD_NAME(x) __thread_name_ ## x - -#ifndef __BEGIN_HIDDEN_DECLS -#define __BEGIN_HIDDEN_DECLS -#endif -#ifndef __END_HIDDEN_DECLS -#define __END_HIDDEN_DECLS -#endif - -/* - * netdb.h - */ -#ifndef NETDB_SUCCESS -#define NETDB_SUCCESS 0 -#endif - -#ifndef NETDB_INTERNAL -#define NETDB_INTERNAL -1 -#endif - -#ifndef AI_FQDN -#define AI_FQDN AI_CANONNAME -#endif - -#ifndef AI_MASK -#define AI_MASK \ - (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG | AI_FQDN) -#endif - -#ifndef SCOPE_DELIMITER -#define SCOPE_DELIMITER '%' -#endif - -#ifndef _PATH_HOSTS -#define _PATH_HOSTS "/etc/hosts" -#endif - -#ifndef _PATH_NETWORKS -#define _PATH_NETWORKS "/etc/networks" -#endif - -/* - * arpa/nameserv.h - */ -#ifndef T_OPT -#define T_OPT 41 -#endif - -#ifndef DNS_MESSAGEEXTFLAG_DO -#define DNS_MESSAGEEXTFLAG_DO 0x8000U -#endif - -#ifndef HAVE___P_CLASS -const char * __p_class(int); -#endif - -#ifndef HAVE___P_TYPE -const char * __p_type(int); -#endif diff --git a/foobar/portable/openbsd-compat/libasr/asr_debug.c b/foobar/portable/openbsd-compat/libasr/asr_debug.c deleted file mode 100644 index be80436a..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr_debug.c +++ /dev/null @@ -1,362 +0,0 @@ -/* $OpenBSD: asr_debug.c,v 1.26 2019/07/03 03:24:03 deraadt Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif -#include -#include - -#include -#include -#include - -#include "asr_private.h" - -static const char *rcodetostr(uint16_t); -static const char *print_dname(const char *, char *, size_t); -static const char *print_header(const struct asr_dns_header *, char *, size_t); -static const char *print_query(const struct asr_dns_query *, char *, size_t); -static const char *print_rr(const struct asr_dns_rr *, char *, size_t); - -FILE *_asr_debug = NULL; - -#define OPCODE_SHIFT 11 - -static const char * -rcodetostr(uint16_t v) -{ - switch (v) { - case NOERROR: return "NOERROR"; - case FORMERR: return "FORMERR"; - case SERVFAIL: return "SERVFAIL"; - case NXDOMAIN: return "NXDOMAIN"; - case NOTIMP: return "NOTIMP"; - case REFUSED: return "REFUSED"; - default: return "?"; - } -} - -static const char * -print_dname(const char *_dname, char *buf, size_t max) -{ - return (_asr_strdname(_dname, buf, max)); -} - -static const char * -print_rr(const struct asr_dns_rr *rr, char *buf, size_t max) -{ - char *res; - char tmp[256]; - char tmp2[256]; - int r; - - res = buf; - - r = snprintf(buf, max, "%s %u %s %s ", - print_dname(rr->rr_dname, tmp, sizeof tmp), - rr->rr_ttl, - __p_class(rr->rr_class), - __p_type(rr->rr_type)); - if (r < 0 || (size_t)r >= max) { - buf[0] = '\0'; - return (buf); - } - - if ((size_t)r >= max) - return (buf); - - max -= r; - buf += r; - - switch (rr->rr_type) { - case T_CNAME: - print_dname(rr->rr.cname.cname, buf, max); - break; - case T_MX: - snprintf(buf, max, "%lu %s", - (unsigned long)rr->rr.mx.preference, - print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); - break; - case T_NS: - print_dname(rr->rr.ns.nsname, buf, max); - break; - case T_PTR: - print_dname(rr->rr.ptr.ptrname, buf, max); - break; - case T_SOA: - snprintf(buf, max, "%s %s %lu %lu %lu %lu %lu", - print_dname(rr->rr.soa.rname, tmp, sizeof tmp), - print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), - (unsigned long)rr->rr.soa.serial, - (unsigned long)rr->rr.soa.refresh, - (unsigned long)rr->rr.soa.retry, - (unsigned long)rr->rr.soa.expire, - (unsigned long)rr->rr.soa.minimum); - break; - case T_A: - if (rr->rr_class != C_IN) - goto other; - snprintf(buf, max, "%s", inet_ntop(AF_INET, - &rr->rr.in_a.addr, tmp, sizeof tmp)); - break; - case T_AAAA: - if (rr->rr_class != C_IN) - goto other; - snprintf(buf, max, "%s", inet_ntop(AF_INET6, - &rr->rr.in_aaaa.addr6, tmp, sizeof tmp)); - break; - default: - other: - snprintf(buf, max, "(rdlen=%i)", (int)rr->rr.other.rdlen); - break; - } - - return (res); -} - -static const char * -print_query(const struct asr_dns_query *q, char *buf, size_t max) -{ - char b[256]; - - snprintf(buf, max, "%s %s %s", - print_dname(q->q_dname, b, sizeof b), - __p_class(q->q_class), __p_type(q->q_type)); - - return (buf); -} - -static const char * -print_header(const struct asr_dns_header *h, char *buf, size_t max) -{ - snprintf(buf, max, - "id:0x%04x %s op:%i %s %s %s %s z:%i %s %s r:%s qd:%i an:%i ns:%i ar:%i", - ((int)h->id), - (h->flags & QR_MASK) ? "QR":" ", - (int)(OPCODE(h->flags) >> OPCODE_SHIFT), - (h->flags & AA_MASK) ? "AA":" ", - (h->flags & TC_MASK) ? "TC":" ", - (h->flags & RD_MASK) ? "RD":" ", - (h->flags & RA_MASK) ? "RA":" ", - (h->flags & Z_MASK), - (h->flags & AD_MASK) ? "AD":" ", - (h->flags & CD_MASK) ? "CD":" ", - rcodetostr(RCODE(h->flags)), - h->qdcount, h->ancount, h->nscount, h->arcount); - - return (buf); -} - -void -_asr_dump_packet(FILE *f, const void *data, size_t len) -{ - char buf[1024]; - struct asr_unpack p; - struct asr_dns_header h; - struct asr_dns_query q; - struct asr_dns_rr rr; - int i, an, ns, ar, n; - - if (f == NULL) - return; - - _asr_unpack_init(&p, data, len); - - if (_asr_unpack_header(&p, &h) == -1) { - fprintf(f, ";; BAD PACKET: %s\n", strerror(p.err)); - return; - } - - fprintf(f, ";; HEADER %s\n", print_header(&h, buf, sizeof buf)); - - if (h.qdcount) - fprintf(f, ";; QUERY SECTION:\n"); - for (i = 0; i < h.qdcount; i++) { - if (_asr_unpack_query(&p, &q) == -1) - goto error; - fprintf(f, "%s\n", print_query(&q, buf, sizeof buf)); - } - - an = 0; - ns = an + h.ancount; - ar = ns + h.nscount; - n = ar + h.arcount; - - for (i = 0; i < n; i++) { - if (i == an) - fprintf(f, "\n;; ANSWER SECTION:\n"); - if (i == ns) - fprintf(f, "\n;; AUTHORITY SECTION:\n"); - if (i == ar) - fprintf(f, "\n;; ADDITIONAL SECTION:\n"); - - if (_asr_unpack_rr(&p, &rr) == -1) - goto error; - fprintf(f, "%s\n", print_rr(&rr, buf, sizeof buf)); - } - - if (p.offset != len) - fprintf(f, ";; REMAINING GARBAGE %zu\n", len - p.offset); - - error: - if (p.err) - fprintf(f, ";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len, - strerror(p.err)); -} - -const char * -_asr_print_sockaddr(const struct sockaddr *sa, char *buf, size_t len) -{ - char h[256]; - int portno; - union { - const struct sockaddr *sa; - const struct sockaddr_in *sin; - const struct sockaddr_in6 *sin6; - } s; - - s.sa = sa; - - switch (sa->sa_family) { - case AF_INET: - inet_ntop(AF_INET, &s.sin->sin_addr, h, sizeof h); - portno = ntohs(s.sin->sin_port); - break; - case AF_INET6: - inet_ntop(AF_INET6, &s.sin6->sin6_addr, h, sizeof h); - portno = ntohs(s.sin6->sin6_port); - break; - default: - snprintf(buf, len, "?"); - return (buf); - } - - snprintf(buf, len, "%s:%i", h, portno); - return (buf); -} - -void -_asr_dump_config(FILE *f, struct asr *a) -{ - char buf[256]; - int i; - struct asr_ctx *ac; - unsigned int o; - - if (f == NULL) - return; - - ac = a->a_ctx; - - fprintf(f, "--------- ASR CONFIG ---------------\n"); - fprintf(f, "DOMAIN \"%s\"\n", ac->ac_domain); - fprintf(f, "SEARCH\n"); - for (i = 0; i < ac->ac_domcount; i++) - fprintf(f, " \"%s\"\n", ac->ac_dom[i]); - fprintf(f, "OPTIONS\n"); - fprintf(f, " options:"); - o = ac->ac_options; - -#define PRINTOPT(flag, n) if (o & (flag)) { fprintf(f, " " n); o &= ~(flag); } - PRINTOPT(RES_INIT, "INIT"); - PRINTOPT(RES_DEBUG, "DEBUG"); - PRINTOPT(RES_USEVC, "USEVC"); - PRINTOPT(RES_IGNTC, "IGNTC"); - PRINTOPT(RES_RECURSE, "RECURSE"); - PRINTOPT(RES_DEFNAMES, "DEFNAMES"); - PRINTOPT(RES_STAYOPEN, "STAYOPEN"); - PRINTOPT(RES_DNSRCH, "DNSRCH"); - PRINTOPT(RES_NOALIASES, "NOALIASES"); - PRINTOPT(RES_USE_EDNS0, "USE_EDNS0"); - PRINTOPT(RES_USE_DNSSEC, "USE_DNSSEC"); - if (o) - fprintf(f, " 0x%08x", o); - fprintf(f, "\n"); - - fprintf(f, " ndots: %i\n", ac->ac_ndots); - fprintf(f, " family:"); - for (i = 0; ac->ac_family[i] != -1; i++) - fprintf(f, " %s", (ac->ac_family[i] == AF_INET)?"inet4":"inet6"); - fprintf(f, "\n"); - fprintf(f, "NAMESERVERS timeout=%i retry=%i\n", - ac->ac_nstimeout, - ac->ac_nsretries); - for (i = 0; i < ac->ac_nscount; i++) - fprintf(f, " %s\n", _asr_print_sockaddr(ac->ac_ns[i], buf, - sizeof buf)); - fprintf(f, "LOOKUP %s", ac->ac_db); - fprintf(f, "\n------------------------------------\n"); -} - -#define CASE(n) case n: return #n - -const char * -_asr_statestr(int state) -{ - switch (state) { - CASE(ASR_STATE_INIT); - CASE(ASR_STATE_NEXT_DOMAIN); - CASE(ASR_STATE_NEXT_DB); - CASE(ASR_STATE_SAME_DB); - CASE(ASR_STATE_NEXT_FAMILY); - CASE(ASR_STATE_NEXT_NS); - CASE(ASR_STATE_UDP_SEND); - CASE(ASR_STATE_UDP_RECV); - CASE(ASR_STATE_TCP_WRITE); - CASE(ASR_STATE_TCP_READ); - CASE(ASR_STATE_PACKET); - CASE(ASR_STATE_SUBQUERY); - CASE(ASR_STATE_NOT_FOUND); - CASE(ASR_STATE_HALT); - default: - return "?"; - } -}; - -const char * -_asr_querystr(int type) -{ - switch (type) { - CASE(ASR_SEND); - CASE(ASR_SEARCH); - CASE(ASR_GETRRSETBYNAME); - CASE(ASR_GETHOSTBYNAME); - CASE(ASR_GETHOSTBYADDR); - CASE(ASR_GETADDRINFO); - CASE(ASR_GETNAMEINFO); - default: - return "?"; - } -} - -const char * -_asr_transitionstr(int type) -{ - switch (type) { - CASE(ASYNC_COND); - CASE(ASYNC_DONE); - default: - return "?"; - } -} diff --git a/foobar/portable/openbsd-compat/libasr/asr_private.h b/foobar/portable/openbsd-compat/libasr/asr_private.h deleted file mode 100644 index acf0e874..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr_private.h +++ /dev/null @@ -1,359 +0,0 @@ -/* $OpenBSD: asr_private.h,v 1.47 2018/04/28 15:16:49 schwarze Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "asr_compat.h" - -#define QR_MASK (0x1 << 15) -#define OPCODE_MASK (0xf << 11) -#define AA_MASK (0x1 << 10) -#define TC_MASK (0x1 << 9) -#define RD_MASK (0x1 << 8) -#define RA_MASK (0x1 << 7) -#define Z_MASK (0x1 << 6) -#define AD_MASK (0x1 << 5) -#define CD_MASK (0x1 << 4) -#define RCODE_MASK (0xf) - -#define OPCODE(v) ((v) & OPCODE_MASK) -#define RCODE(v) ((v) & RCODE_MASK) - - -struct asr_pack { - char *buf; - size_t len; - size_t offset; - int err; -}; - -struct asr_unpack { - const char *buf; - size_t len; - size_t offset; - int err; -}; - -struct asr_dns_header { - uint16_t id; - uint16_t flags; - uint16_t qdcount; - uint16_t ancount; - uint16_t nscount; - uint16_t arcount; -}; - -struct asr_dns_query { - char q_dname[MAXDNAME]; - uint16_t q_type; - uint16_t q_class; -}; - -struct asr_dns_rr { - char rr_dname[MAXDNAME]; - uint16_t rr_type; - uint16_t rr_class; - uint32_t rr_ttl; - union { - struct { - char cname[MAXDNAME]; - } cname; - struct { - uint16_t preference; - char exchange[MAXDNAME]; - } mx; - struct { - char nsname[MAXDNAME]; - } ns; - struct { - char ptrname[MAXDNAME]; - } ptr; - struct { - char mname[MAXDNAME]; - char rname[MAXDNAME]; - uint32_t serial; - uint32_t refresh; - uint32_t retry; - uint32_t expire; - uint32_t minimum; - } soa; - struct { - struct in_addr addr; - } in_a; - struct { - struct in6_addr addr6; - } in_aaaa; - struct { - uint16_t rdlen; - const void *rdata; - } other; - } rr; -}; - - -#define ASR_MAXNS 5 -#define ASR_MAXDB 3 -#define ASR_MAXDOM 10 - -enum async_type { - ASR_SEND, - ASR_SEARCH, - ASR_GETRRSETBYNAME, - ASR_GETHOSTBYNAME, - ASR_GETHOSTBYADDR, - ASR_GETADDRINFO, - ASR_GETNAMEINFO, -}; - -#define ASR_DB_FILE 'f' -#define ASR_DB_DNS 'b' - -struct asr_ctx { - int ac_refcount; - int ac_options; - int ac_ndots; - char *ac_domain; - int ac_domcount; - char *ac_dom[ASR_MAXDOM]; - int ac_dbcount; - char ac_db[ASR_MAXDB + 1]; - int ac_family[3]; - - int ac_nscount; - int ac_nstimeout; - int ac_nsretries; - struct sockaddr *ac_ns[ASR_MAXNS]; - -}; - -struct asr { - pid_t a_pid; - time_t a_mtime; - time_t a_rtime; - struct asr_ctx *a_ctx; -}; - -#define ASYNC_COND 0 -#define ASYNC_DONE 1 - -#define ASYNC_DOM_FQDN 0x00000001 -#define ASYNC_DOM_NDOTS 0x00000002 -#define ASYNC_DOM_DOMAIN 0x00000004 -#define ASYNC_DOM_ASIS 0x00000008 - -#define ASYNC_NODATA 0x00000100 -#define ASYNC_AGAIN 0x00000200 - -#define ASYNC_GETNET 0x00001000 -#define ASYNC_EXTOBUF 0x00002000 - -#define ASYNC_NO_INET 0x00010000 -#define ASYNC_NO_INET6 0x00020000 - -struct asr_query { - int (*as_run)(struct asr_query *, struct asr_result *); - struct asr_ctx *as_ctx; - int as_type; - int as_flags; - int as_state; - - /* cond */ - int as_timeout; - int as_fd; - struct asr_query *as_subq; - - /* loop indices in ctx */ - int as_dom_step; - int as_dom_idx; - int as_dom_flags; - int as_family_idx; - int as_db_idx; - - int as_count; - - union { - struct { - uint16_t reqid; - int class; - int type; - char *dname; /* not fqdn! */ - int rcode; /* response code */ - int ancount; /* answer count */ - - int nsidx; - int nsloop; - - /* io buffers for query/response */ - unsigned char *obuf; - size_t obuflen; - size_t obufsize; - unsigned char *ibuf; - size_t ibuflen; - size_t ibufsize; - size_t datalen; /* for tcp io */ - uint16_t pktlen; - } dns; - - struct { - int class; - int type; - char *name; - int saved_h_errno; - } search; - - struct { - int flags; - int class; - int type; - char *name; - } rrset; - - struct { - char *name; - int family; - char addr[16]; - int addrlen; - int subq_h_errno; - } hostnamadr; - - struct { - char *hostname; - char *servname; - int port_tcp; - int port_udp; - union { - struct sockaddr sa; - struct sockaddr_in sain; - struct sockaddr_in6 sain6; - } sa; - - struct addrinfo hints; - char *fqdn; - struct addrinfo *aifirst; - struct addrinfo *ailast; - } ai; - - struct { - char *hostname; - char *servname; - size_t hostnamelen; - size_t servnamelen; - union { - struct sockaddr sa; - struct sockaddr_in sain; - struct sockaddr_in6 sain6; - } sa; - int flags; - } ni; -#define MAXTOKEN 10 - } as; - -}; - -#define AS_DB(p) ((p)->as_ctx->ac_db[(p)->as_db_idx - 1]) -#define AS_FAMILY(p) ((p)->as_ctx->ac_family[(p)->as_family_idx]) - -enum asr_state { - ASR_STATE_INIT, - ASR_STATE_NEXT_DOMAIN, - ASR_STATE_NEXT_DB, - ASR_STATE_SAME_DB, - ASR_STATE_NEXT_FAMILY, - ASR_STATE_NEXT_NS, - ASR_STATE_UDP_SEND, - ASR_STATE_UDP_RECV, - ASR_STATE_TCP_WRITE, - ASR_STATE_TCP_READ, - ASR_STATE_PACKET, - ASR_STATE_SUBQUERY, - ASR_STATE_NOT_FOUND, - ASR_STATE_HALT, -}; - -#define MAXPACKETSZ 4096 - -__BEGIN_HIDDEN_DECLS - -/* asr_utils.c */ -void _asr_pack_init(struct asr_pack *, char *, size_t); -int _asr_pack_header(struct asr_pack *, const struct asr_dns_header *); -int _asr_pack_query(struct asr_pack *, uint16_t, uint16_t, const char *); -int _asr_pack_edns0(struct asr_pack *, uint16_t, int); -void _asr_unpack_init(struct asr_unpack *, const char *, size_t); -int _asr_unpack_header(struct asr_unpack *, struct asr_dns_header *); -int _asr_unpack_query(struct asr_unpack *, struct asr_dns_query *); -int _asr_unpack_rr(struct asr_unpack *, struct asr_dns_rr *); -int _asr_sockaddr_from_str(struct sockaddr *, int, const char *); -ssize_t _asr_dname_from_fqdn(const char *, char *, size_t); -ssize_t _asr_addr_as_fqdn(const char *, int, char *, size_t); - -/* asr.c */ -void _asr_resolver_done(void *); -struct asr_ctx *_asr_use_resolver(void *); -struct asr_ctx *_asr_no_resolver(void); -void _asr_ctx_unref(struct asr_ctx *); -struct asr_query *_asr_async_new(struct asr_ctx *, int); -void _asr_async_free(struct asr_query *); -size_t _asr_make_fqdn(const char *, const char *, char *, size_t); -char *_asr_strdname(const char *, char *, size_t); -int _asr_iter_db(struct asr_query *); -int _asr_parse_namedb_line(FILE *, char **, int, char *, size_t); - -/* *_async.c */ -struct asr_query *_res_query_async_ctx(const char *, int, int, struct asr_ctx *); -struct asr_query *_res_search_async_ctx(const char *, int, int, struct asr_ctx *); -struct asr_query *_gethostbyaddr_async_ctx(const void *, socklen_t, int, - struct asr_ctx *); - -int _asr_iter_domain(struct asr_query *, const char *, char *, size_t); - -#ifdef DEBUG - -#define DPRINT(...) do { if(_asr_debug) { \ - fprintf(_asr_debug, __VA_ARGS__); \ - } } while (0) -#define DPRINT_PACKET(n, p, s) do { if(_asr_debug) { \ - fprintf(_asr_debug, "----- %s -----\n", n); \ - _asr_dump_packet(_asr_debug, (p), (s)); \ - fprintf(_asr_debug, "--------------\n"); \ - } } while (0) - -#else /* DEBUG */ - -#define DPRINT(...) -#define DPRINT_PACKET(...) - -#endif /* DEBUG */ - -const char *_asr_querystr(int); -const char *_asr_statestr(int); -const char *_asr_transitionstr(int); -const char *_asr_print_sockaddr(const struct sockaddr *, char *, size_t); -void _asr_dump_config(FILE *, struct asr *); -void _asr_dump_packet(FILE *, const void *, size_t); - -extern FILE *_asr_debug; - -#define async_set_state(a, s) do { \ - DPRINT("asr: [%s@%p] %s -> %s\n", \ - _asr_querystr((a)->as_type), \ - as, \ - _asr_statestr((a)->as_state), \ - _asr_statestr((s))); \ - (a)->as_state = (s); } while (0) - -__END_HIDDEN_DECLS diff --git a/foobar/portable/openbsd-compat/libasr/asr_run.3 b/foobar/portable/openbsd-compat/libasr/asr_run.3 deleted file mode 100644 index 61c1b02c..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr_run.3 +++ /dev/null @@ -1,316 +0,0 @@ -.\" $OpenBSD: asr_run.3,v 1.3 2017/02/18 19:23:05 jca Exp $ -.\" -.\" Copyright (c) 2012-2014, Eric Faurot -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: February 18 2017 $ -.Dt ASR_RUN 3 -.Os -.Sh NAME -.Nm asr_run , -.Nm asr_run_sync , -.Nm asr_abort , -.Nm res_send_async , -.Nm res_query_async , -.Nm res_search_async , -.Nm getrrsetbyname_async , -.Nm gethostbyname_async , -.Nm gethostbyname2_async , -.Nm gethostbyaddr_async , -.Nm getnetbyname_async , -.Nm getnetbyaddr_async , -.Nm getaddrinfo_async , -.Nm getnameinfo_async -.Nd asynchronous resolver functions -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.In asr.h -.Ft int -.Fn asr_run "struct asr_query *aq" "struct asr_result *ar" -.Ft int -.Fn asr_run_sync "struct asr_query *aq" "struct asr_result *ar" -.Ft void -.Fn asr_abort "struct asr_query *aq" -.Ft struct asr_query * -.Fn res_send_async "const unsigned char *pkt" "int pktlen" "void *asr" -.Ft struct asr_query * -.Fn res_query_async "const char *name" "int class" "int type" "void *asr" -.Ft struct asr_query * -.Fn res_search_async "const char *name" "int class" "int type" "void *asr" -.Ft struct asr_query * -.Fn getrrsetbyname_async "const char *hostname" "unsigned int rdclass" "unsigned int rdtype" "unsigned int flags" "void *asr" -.Ft struct asr_query * -.Fn gethostbyname_async "const char *name" "void *asr" -.Ft struct asr_query * -.Fn gethostbyname2_async "const char *name" "int af" "void *asr" -.Ft struct asr_query * -.Fn gethostbyaddr_async "const void *addr" "socklen_t len" "int af" "void *asr" -.Ft struct asr_query * -.Fn getnetbyname_async "const char *name" "void *asr" -.Ft struct asr_query * -.Fn getnetbyaddr_async "in_addr_t net" "int type" "void *asr" -.Ft struct asr_query * -.Fn getaddrinfo_async "const char *hostname" "const char *servname" "const struct addrinfo *hints" "void *asr" -.Ft struct asr_query * -.Fn getnameinfo_async "const struct sockaddr *sa" "socklen_t salen" "char *host" "size_t hostlen" "char *serv" "size_t servlen" "int flags" "void *asr" -.Sh DESCRIPTION -The -.Nm asr -functions provide a simple interface for asynchronous address -resolution and nameserver querying. -They should be used in place of the classical resolver functions -of libc when blocking is not desirable. -.Pp -The principle of operation is as follows: -All async requests are made against an -.Nm asr -context which basically defines a list of sources to query and a -strategy to do so. -The user creates a query through one of the dedicated functions, and -gets a handle representing the internal query. -A query is a state-machine that can be run to try to fulfill a -particular request. -This is done by calling in a generic API that performs the state -transitions until it needs to give the control back to the user, -either because a result is available, or because the next transition -implies a blocking call (a file descriptor needs to be read from or -written to). -The user is responsible for dealing with the situation: either get -the result, or wait until the fd conditions are met, and then call -back into the resolving machinery when it is ready to proceed. -.Pp -The -.Fn asr_run -function drives the resolving process. -It runs the asynchronous query represented by the -.Fa aq -handle until a result is available, or until it cannot continue -without blocking. -The results are returned to the user through the -.Fa ar -parameter, which must be a valid pointer to user allocated memory. -.Fa ar -is defined as: -.Bd -literal -struct asr_result { - - /* Fields set if the query is not done yet (asr_run returns 0) */ - int ar_cond; /* ASR_WANT_READ or ASR_WANT_WRITE */ - int ar_fd; /* the fd waiting for io condition */ - int ar_timeout; /* time to wait for in milliseconds */ - - /* Error fields. Depends on the query type. */ - int ar_errno; - int ar_h_errno; - int ar_gai_errno; - int ar_rrset_errno; - - /* Result for res_*_async() calls */ - int ar_count; /* number of answers in the dns reply */ - int ar_rcode; /* response code in the dns reply */ - void *ar_data; /* raw reply packet (must be freed) */ - int ar_datalen; /* reply packet length */ - struct sockaddr_storage ar_ns; /* nameserver that responded */ - - /* Result for other calls. Must be freed properly. */ - struct addrinfo *ar_addrinfo; - struct rrsetinfo *ar_rrsetinfo; - struct hostent *ar_hostent; - struct netent *ar_netent; -}; -.Ed -.Pp -The function returns one of the following values: -.Bl -tag -width "0 " -offset indent -.It 0 -The query cannot be processed further until a specific condition on a -file descriptor becomes true. -The following members of the -.Fa ar -structure are filled: -.Pp -.Bl -tag -width "ar_timeout " -compact -.It Fa ar_cond -one of ASR_WANT_READ or ASR_WANT_WRITE, -.It Fa ar_fd -the file descriptor waiting for an IO operation, -.It Fa ar_timeout -the amount of time to wait for in milliseconds. -.El -.Pp -The caller is expected to call -.Fn asr_run -again once the condition holds or the timeout expires. -.It 1 -The query is completed. -The members relevant to the actual async query type are set accordingly, -including error conditions. -In any case, the query is cleared and its handle is invalidated. -.El -.Pp -Note that although the query itself may fail (the error being properly reported -in the -.Fa ar -structure), the -.Fn asr_run -function itself cannot fail and it always preserves errno. -.Pp -The -.Fn asr_run_sync -function is a wrapper around -.Fn asr_run -that handles the read/write conditions, thus falling back to a blocking -interface. -It only returns 1. -It also preserves errno. -.Pp -The -.Fn asr_abort -function clears a running query. -It can be called when the query is waiting on a file descriptor. -Note that a completed query is already cleared when -.Fn asr_run -returns, so -.Fn asr_abort -must not be called in this case. -.Pp -The remaining functions are used to initiate different kinds of query -on the -.Fa asr -resolver context. -The specific operational details for each of them are described below. -All functions return a handle to an internal query, or NULL if they could -not allocate the necessary resources to initiate the query. -All other errors (especially invalid parameters) are reported when calling -.Fn asr_run . -They usually have the same interface as an existing resolver function, with -an additional -.Ar asr -argument, which specifies the context to use for this request. -For now, the argument must always be NULL, which will use the default -context for the current thread. -.Pp -The -.Fn res_send_async , -.Fn res_query_async -and -.Fn res_search_async -functions are asynchronous versions of the standard libc resolver routines. -Their interface is very similar, except that the response buffer is always -allocated internally. -The return value is found upon completion in the -.Fa ar_datalen -member of the response structure. -In addition, the -.Fa ar_ns -structure contains the address of the DNS server that sent the response, -.Fa ar_rcode -contains the code returned by the server in the DNS response packet, and -.Fa ar_count -contains the number of answers in the packet. -If a response is received it is placed in a newly allocated buffer -and returned as -.Fa ar_data -member. -This buffer must be freed by the caller. -On error, the -.Fa ar_errno -and -.Fa ar_h_errno -members are set accordingly. -.Pp -The -.Fn getrrsetbyname_async -function is an asynchronous version of -.Xr getrrsetbyname 3 . -Upon completion, the return code is found in -.Fa ar_rrset_errno -and the address to the newly allocated result set is set in -.Fa ar_rrsetinfo . -As for the blocking function, it must be freed by calling -.Xr freerrset 3 . -.Pp -The -.Fn gethostbyname_async , -.Fn gethostbyname2_async -and -.Fn gethostbyaddr_async -functions provide an asynchronous version of the network host entry functions. -Upon completion, -.Ar ar_h_errno -is set and the resulting hostent address, if found, is set -in the -.Ar ar_hostent -field. -Note that unlike their blocking counterparts, these functions always return a -pointer to newly allocated memory, which must be released by the caller using -.Xr free 3 . -.Pp -Similarly, the -.Fn getnetbyname_async -and -.Fn getnetbyaddr_async -functions provide an asynchronous version of the network entry functions. -Upon completion, -.Ar ar_h_errno -is set and the resulting netent address, if found, is set -in the -.Ar ar_netent -field. -The memory there is also allocated for the request, and it must be freed by -.Xr free 3 . -.Pp -The -.Fn getaddrinfo_async -function is an asynchronous version of the -.Xr getaddrinfo 3 -call. -It provides a chain of addrinfo structures with all valid combinations of -socket address for the given -.Fa hostname , -.Fa servname -and -.Fa hints . -Those three parameters have the same meaning as for the blocking counterpart. -Upon completion the return code is set in -.Fa ar_gai_errno . -The -.Fa ar_errno -member may also be set. -On success, the -.Fa ar_addrinfo -member points to a newly allocated list of addrinfo. -This list must be freed with -.Xr freeaddrinfo 3 . -.Sh WORKING WITH THREADS -This implementation of the asynchronous resolver interface is thread-safe -and lock-free internally, but the following restriction applies: -Two different threads must not create queries on the same context or -run queries originating from the same context at the same time. -If they want to do that, all calls must be protected by a mutex around -that context. -.Pp -It is generally not a problem since the main point of the asynchronous -resolver is to multiplex queries within a single thread of control, -so sharing a resolver among threads is not useful. -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr gethostbyname 3 , -.Xr getnameinfo 3 , -.Xr getnetbyname 3 , -.Xr getrrsetbyname 3 , -.Xr res_send 3 , -.Xr resolv.conf 5 diff --git a/foobar/portable/openbsd-compat/libasr/asr_utils.c b/foobar/portable/openbsd-compat/libasr/asr_utils.c deleted file mode 100644 index e3d24c93..00000000 --- a/foobar/portable/openbsd-compat/libasr/asr_utils.c +++ /dev/null @@ -1,574 +0,0 @@ -/* $OpenBSD: asr_utils.c,v 1.18 2017/09/23 20:55:06 jca Exp $ */ -/* - * Copyright (c) 2009-2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "asr_private.h" - -static int dname_check_label(const char *, size_t); -static ssize_t dname_expand(const unsigned char *, size_t, size_t, size_t *, - char *, size_t); - -static int unpack_data(struct asr_unpack *, void *, size_t); -static int unpack_u16(struct asr_unpack *, uint16_t *); -static int unpack_u32(struct asr_unpack *, uint32_t *); -static int unpack_inaddr(struct asr_unpack *, struct in_addr *); -static int unpack_in6addr(struct asr_unpack *, struct in6_addr *); -static int unpack_dname(struct asr_unpack *, char *, size_t); - -static int pack_data(struct asr_pack *, const void *, size_t); -static int pack_u16(struct asr_pack *, uint16_t); -static int pack_dname(struct asr_pack *, const char *); - -static int -dname_check_label(const char *s, size_t l) -{ - if (l == 0 || l > 63) - return (-1); - - return (0); -} - -ssize_t -_asr_dname_from_fqdn(const char *str, char *dst, size_t max) -{ - ssize_t res; - size_t l, n; - char *d; - - res = 0; - - /* special case: the root domain */ - if (str[0] == '.') { - if (str[1] != '\0') - return (-1); - if (dst && max >= 1) - *dst = '\0'; - return (1); - } - - for (; *str; str = d + 1) { - - d = strchr(str, '.'); - if (d == NULL || d == str) - return (-1); - - l = (d - str); - - if (dname_check_label(str, l) == -1) - return (-1); - - res += l + 1; - - if (dst) { - *dst++ = l; - max -= 1; - n = (l > max) ? max : l; - memmove(dst, str, n); - max -= n; - if (max == 0) - dst = NULL; - else - dst += n; - } - } - - if (dst) - *dst++ = '\0'; - - return (res + 1); -} - -static ssize_t -dname_expand(const unsigned char *data, size_t len, size_t offset, - size_t *newoffset, char *dst, size_t max) -{ - size_t n, count, end, ptr, start; - ssize_t res; - - if (offset >= len) - return (-1); - - res = 0; - end = start = offset; - - for (; (n = data[offset]); ) { - if ((n & 0xc0) == 0xc0) { - if (offset + 2 > len) - return (-1); - ptr = 256 * (n & ~0xc0) + data[offset + 1]; - if (ptr >= start) - return (-1); - if (end < offset + 2) - end = offset + 2; - offset = start = ptr; - continue; - } - if (offset + n + 1 > len) - return (-1); - - if (dname_check_label(data + offset + 1, n) == -1) - return (-1); - - /* copy n + at offset+1 */ - if (dst != NULL && max != 0) { - count = (max < n + 1) ? (max) : (n + 1); - memmove(dst, data + offset, count); - dst += count; - max -= count; - } - res += n + 1; - offset += n + 1; - if (end < offset) - end = offset; - } - if (end < offset + 1) - end = offset + 1; - - if (dst != NULL && max != 0) - dst[0] = 0; - if (newoffset) - *newoffset = end; - return (res + 1); -} - -void -_asr_pack_init(struct asr_pack *pack, char *buf, size_t len) -{ - pack->buf = buf; - pack->len = len; - pack->offset = 0; - pack->err = 0; -} - -void -_asr_unpack_init(struct asr_unpack *unpack, const char *buf, size_t len) -{ - unpack->buf = buf; - unpack->len = len; - unpack->offset = 0; - unpack->err = 0; -} - -static int -unpack_data(struct asr_unpack *p, void *data, size_t len) -{ - if (p->err) - return (-1); - - if (p->len - p->offset < len) { - p->err = EOVERFLOW; - return (-1); - } - - memmove(data, p->buf + p->offset, len); - p->offset += len; - - return (0); -} - -static int -unpack_u16(struct asr_unpack *p, uint16_t *u16) -{ - if (unpack_data(p, u16, 2) == -1) - return (-1); - - *u16 = ntohs(*u16); - - return (0); -} - -static int -unpack_u32(struct asr_unpack *p, uint32_t *u32) -{ - if (unpack_data(p, u32, 4) == -1) - return (-1); - - *u32 = ntohl(*u32); - - return (0); -} - -static int -unpack_inaddr(struct asr_unpack *p, struct in_addr *a) -{ - return (unpack_data(p, a, 4)); -} - -static int -unpack_in6addr(struct asr_unpack *p, struct in6_addr *a6) -{ - return (unpack_data(p, a6, 16)); -} - -static int -unpack_dname(struct asr_unpack *p, char *dst, size_t max) -{ - ssize_t e; - - if (p->err) - return (-1); - - e = dname_expand(p->buf, p->len, p->offset, &p->offset, dst, max); - if (e == -1) { - p->err = EINVAL; - return (-1); - } - if (e < 0 || e > MAXDNAME) { - p->err = ERANGE; - return (-1); - } - - return (0); -} - -int -_asr_unpack_header(struct asr_unpack *p, struct asr_dns_header *h) -{ - if (unpack_data(p, h, HFIXEDSZ) == -1) - return (-1); - - h->flags = ntohs(h->flags); - h->qdcount = ntohs(h->qdcount); - h->ancount = ntohs(h->ancount); - h->nscount = ntohs(h->nscount); - h->arcount = ntohs(h->arcount); - - return (0); -} - -int -_asr_unpack_query(struct asr_unpack *p, struct asr_dns_query *q) -{ - unpack_dname(p, q->q_dname, sizeof(q->q_dname)); - unpack_u16(p, &q->q_type); - unpack_u16(p, &q->q_class); - - return (p->err) ? (-1) : (0); -} - -int -_asr_unpack_rr(struct asr_unpack *p, struct asr_dns_rr *rr) -{ - uint16_t rdlen; - size_t save_offset; - - unpack_dname(p, rr->rr_dname, sizeof(rr->rr_dname)); - unpack_u16(p, &rr->rr_type); - unpack_u16(p, &rr->rr_class); - unpack_u32(p, &rr->rr_ttl); - unpack_u16(p, &rdlen); - - if (p->err) - return (-1); - - if (p->len - p->offset < rdlen) { - p->err = EOVERFLOW; - return (-1); - } - - save_offset = p->offset; - - switch (rr->rr_type) { - - case T_CNAME: - unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname)); - break; - - case T_MX: - unpack_u16(p, &rr->rr.mx.preference); - unpack_dname(p, rr->rr.mx.exchange, sizeof(rr->rr.mx.exchange)); - break; - - case T_NS: - unpack_dname(p, rr->rr.ns.nsname, sizeof(rr->rr.ns.nsname)); - break; - - case T_PTR: - unpack_dname(p, rr->rr.ptr.ptrname, sizeof(rr->rr.ptr.ptrname)); - break; - - case T_SOA: - unpack_dname(p, rr->rr.soa.mname, sizeof(rr->rr.soa.mname)); - unpack_dname(p, rr->rr.soa.rname, sizeof(rr->rr.soa.rname)); - unpack_u32(p, &rr->rr.soa.serial); - unpack_u32(p, &rr->rr.soa.refresh); - unpack_u32(p, &rr->rr.soa.retry); - unpack_u32(p, &rr->rr.soa.expire); - unpack_u32(p, &rr->rr.soa.minimum); - break; - - case T_A: - if (rr->rr_class != C_IN) - goto other; - unpack_inaddr(p, &rr->rr.in_a.addr); - break; - - case T_AAAA: - if (rr->rr_class != C_IN) - goto other; - unpack_in6addr(p, &rr->rr.in_aaaa.addr6); - break; - default: - other: - rr->rr.other.rdata = p->buf + p->offset; - rr->rr.other.rdlen = rdlen; - p->offset += rdlen; - } - - if (p->err) - return (-1); - - /* make sure that the advertised rdlen is really ok */ - if (p->offset - save_offset != rdlen) - p->err = EINVAL; - - return (p->err) ? (-1) : (0); -} - -static int -pack_data(struct asr_pack *p, const void *data, size_t len) -{ - if (p->err) - return (-1); - - if (p->len < p->offset + len) { - p->err = EOVERFLOW; - return (-1); - } - - memmove(p->buf + p->offset, data, len); - p->offset += len; - - return (0); -} - -static int -pack_u16(struct asr_pack *p, uint16_t v) -{ - v = htons(v); - - return (pack_data(p, &v, 2)); -} - -static int -pack_dname(struct asr_pack *p, const char *dname) -{ - /* dname compression would be nice to have here. - * need additionnal context. - */ - return (pack_data(p, dname, strlen(dname) + 1)); -} - -int -_asr_pack_header(struct asr_pack *p, const struct asr_dns_header *h) -{ - struct asr_dns_header c; - - c.id = h->id; - c.flags = htons(h->flags); - c.qdcount = htons(h->qdcount); - c.ancount = htons(h->ancount); - c.nscount = htons(h->nscount); - c.arcount = htons(h->arcount); - - return (pack_data(p, &c, HFIXEDSZ)); -} - -int -_asr_pack_query(struct asr_pack *p, uint16_t type, uint16_t class, const char *dname) -{ - pack_dname(p, dname); - pack_u16(p, type); - pack_u16(p, class); - - return (p->err) ? (-1) : (0); -} - -int -_asr_pack_edns0(struct asr_pack *p, uint16_t pktsz, int dnssec_do) -{ - DPRINT("asr EDNS0 pktsz:%hu dnssec:%s\n", pktsz, - dnssec_do ? "yes" : "no"); - - pack_dname(p, ""); /* root */ - pack_u16(p, T_OPT); /* OPT */ - pack_u16(p, pktsz); /* UDP payload size */ - - /* extended RCODE and flags */ - pack_u16(p, 0); - pack_u16(p, dnssec_do ? DNS_MESSAGEEXTFLAG_DO : 0); - - pack_u16(p, 0); /* RDATA len */ - - return (p->err) ? (-1) : (0); -} - -int -_asr_sockaddr_from_str(struct sockaddr *sa, int family, const char *str) -{ - struct in_addr ina; - struct in6_addr in6a; - struct sockaddr_in *sin; - struct sockaddr_in6 *sin6; - char *cp, *str2; - const char *errstr; - - switch (family) { - case PF_UNSPEC: - if (_asr_sockaddr_from_str(sa, PF_INET, str) == 0) - return (0); - return _asr_sockaddr_from_str(sa, PF_INET6, str); - - case PF_INET: - if (inet_pton(PF_INET, str, &ina) != 1) - return (-1); - - sin = (struct sockaddr_in *)sa; - memset(sin, 0, sizeof *sin); -#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - sin->sin_len = sizeof(struct sockaddr_in); -#endif - sin->sin_family = PF_INET; - sin->sin_addr.s_addr = ina.s_addr; - return (0); - - case PF_INET6: - cp = strchr(str, SCOPE_DELIMITER); - if (cp) { - str2 = strdup(str); - if (str2 == NULL) - return (-1); - str2[cp - str] = '\0'; - if (inet_pton(PF_INET6, str2, &in6a) != 1) { - free(str2); - return (-1); - } - cp++; - free(str2); - } else if (inet_pton(PF_INET6, str, &in6a) != 1) - return (-1); - - sin6 = (struct sockaddr_in6 *)sa; - memset(sin6, 0, sizeof *sin6); -#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN - sin6->sin6_len = sizeof(struct sockaddr_in6); -#endif - sin6->sin6_family = PF_INET6; - sin6->sin6_addr = in6a; - - if (cp == NULL) - return (0); - - if (IN6_IS_ADDR_LINKLOCAL(&in6a) || - IN6_IS_ADDR_MC_LINKLOCAL(&in6a) || - IN6_IS_ADDR_MC_NODELOCAL(&in6a)) - if ((sin6->sin6_scope_id = if_nametoindex(cp))) - return (0); - - sin6->sin6_scope_id = strtonum(cp, 0, UINT32_MAX, &errstr); - if (errstr) - return (-1); - return (0); - - default: - break; - } - - return (-1); -} - -ssize_t -_asr_addr_as_fqdn(const char *addr, int family, char *dst, size_t max) -{ - const struct in6_addr *in6_addr; - in_addr_t in_addr; - - switch (family) { - case AF_INET: - in_addr = ntohl(*((const in_addr_t *)addr)); - snprintf(dst, max, - "%d.%d.%d.%d.in-addr.arpa.", - in_addr & 0xff, - (in_addr >> 8) & 0xff, - (in_addr >> 16) & 0xff, - (in_addr >> 24) & 0xff); - break; - case AF_INET6: - in6_addr = (const struct in6_addr *)addr; - snprintf(dst, max, - "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." - "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." - "ip6.arpa.", - in6_addr->s6_addr[15] & 0xf, - (in6_addr->s6_addr[15] >> 4) & 0xf, - in6_addr->s6_addr[14] & 0xf, - (in6_addr->s6_addr[14] >> 4) & 0xf, - in6_addr->s6_addr[13] & 0xf, - (in6_addr->s6_addr[13] >> 4) & 0xf, - in6_addr->s6_addr[12] & 0xf, - (in6_addr->s6_addr[12] >> 4) & 0xf, - in6_addr->s6_addr[11] & 0xf, - (in6_addr->s6_addr[11] >> 4) & 0xf, - in6_addr->s6_addr[10] & 0xf, - (in6_addr->s6_addr[10] >> 4) & 0xf, - in6_addr->s6_addr[9] & 0xf, - (in6_addr->s6_addr[9] >> 4) & 0xf, - in6_addr->s6_addr[8] & 0xf, - (in6_addr->s6_addr[8] >> 4) & 0xf, - in6_addr->s6_addr[7] & 0xf, - (in6_addr->s6_addr[7] >> 4) & 0xf, - in6_addr->s6_addr[6] & 0xf, - (in6_addr->s6_addr[6] >> 4) & 0xf, - in6_addr->s6_addr[5] & 0xf, - (in6_addr->s6_addr[5] >> 4) & 0xf, - in6_addr->s6_addr[4] & 0xf, - (in6_addr->s6_addr[4] >> 4) & 0xf, - in6_addr->s6_addr[3] & 0xf, - (in6_addr->s6_addr[3] >> 4) & 0xf, - in6_addr->s6_addr[2] & 0xf, - (in6_addr->s6_addr[2] >> 4) & 0xf, - in6_addr->s6_addr[1] & 0xf, - (in6_addr->s6_addr[1] >> 4) & 0xf, - in6_addr->s6_addr[0] & 0xf, - (in6_addr->s6_addr[0] >> 4) & 0xf); - break; - default: - return (-1); - } - return (0); -} diff --git a/foobar/portable/openbsd-compat/libasr/getaddrinfo.c b/foobar/portable/openbsd-compat/libasr/getaddrinfo.c deleted file mode 100644 index 37fe2d4d..00000000 --- a/foobar/portable/openbsd-compat/libasr/getaddrinfo.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: getaddrinfo.c,v 1.9 2015/10/08 14:08:44 eric Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include - -int -getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hints, struct addrinfo **res) -{ - struct asr_query *as; - struct asr_result ar; - int saved_errno = errno; - - if (hints == NULL || (hints->ai_flags & AI_NUMERICHOST) == 0) - res_init(); - - as = getaddrinfo_async(hostname, servname, hints, NULL); - if (as == NULL) { - if (errno == ENOMEM) { - errno = saved_errno; - return (EAI_MEMORY); - } - return (EAI_SYSTEM); - } - - asr_run_sync(as, &ar); - - *res = ar.ar_addrinfo; - if (ar.ar_gai_errno == EAI_SYSTEM) - errno = ar.ar_errno; - - return (ar.ar_gai_errno); -} -DEF_WEAK(getaddrinfo); diff --git a/foobar/portable/openbsd-compat/libasr/getaddrinfo_async.c b/foobar/portable/openbsd-compat/libasr/getaddrinfo_async.c deleted file mode 100644 index 1fd44ff7..00000000 --- a/foobar/portable/openbsd-compat/libasr/getaddrinfo_async.c +++ /dev/null @@ -1,756 +0,0 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.56 2018/11/03 09:13:24 eric Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "asr_private.h" - -struct match { - int family; - int socktype; - int protocol; -}; - -static int getaddrinfo_async_run(struct asr_query *, struct asr_result *); -static int get_port(const char *, const char *, int); -static int iter_family(struct asr_query *, int); -static int addrinfo_add(struct asr_query *, const struct sockaddr *, const char *); -static int addrinfo_from_file(struct asr_query *, int, FILE *); -static int addrinfo_from_pkt(struct asr_query *, char *, size_t); -static int addrconfig_setup(struct asr_query *); - -static const struct match matches[] = { - { PF_INET, SOCK_DGRAM, IPPROTO_UDP }, - { PF_INET, SOCK_STREAM, IPPROTO_TCP }, - { PF_INET, SOCK_RAW, 0 }, - { PF_INET6, SOCK_DGRAM, IPPROTO_UDP }, - { PF_INET6, SOCK_STREAM, IPPROTO_TCP }, - { PF_INET6, SOCK_RAW, 0 }, - { -1, 0, 0, }, -}; - -#define MATCH_FAMILY(a, b) ((a) == matches[(b)].family || (a) == PF_UNSPEC) -#define MATCH_PROTO(a, b) ((a) == matches[(b)].protocol || (a) == 0 || matches[(b)].protocol == 0) -/* Do not match SOCK_RAW unless explicitly specified */ -#define MATCH_SOCKTYPE(a, b) ((a) == matches[(b)].socktype || ((a) == 0 && \ - matches[(b)].socktype != SOCK_RAW)) - -enum { - DOM_INIT, - DOM_DOMAIN, - DOM_DONE -}; - -struct asr_query * -getaddrinfo_async(const char *hostname, const char *servname, - const struct addrinfo *hints, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - if (hints == NULL || (hints->ai_flags & AI_NUMERICHOST) == 0) - ac = _asr_use_resolver(asr); - else - ac = _asr_no_resolver(); - if ((as = _asr_async_new(ac, ASR_GETADDRINFO)) == NULL) - goto abort; /* errno set */ - as->as_run = getaddrinfo_async_run; - - if (hostname) { - if ((as->as.ai.hostname = strdup(hostname)) == NULL) - goto abort; /* errno set */ - } - if (servname && (as->as.ai.servname = strdup(servname)) == NULL) - goto abort; /* errno set */ - if (hints) - memmove(&as->as.ai.hints, hints, sizeof *hints); - else { - memset(&as->as.ai.hints, 0, sizeof as->as.ai.hints); - as->as.ai.hints.ai_family = PF_UNSPEC; - as->as.ai.hints.ai_flags = AI_ADDRCONFIG; - } - - _asr_ctx_unref(ac); - return (as); - abort: - if (as) - _asr_async_free(as); - _asr_ctx_unref(ac); - return (NULL); -} -DEF_WEAK(getaddrinfo_async); - -static int -getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar) -{ - char fqdn[MAXDNAME]; - const char *str; - struct addrinfo *ai; - int i, family, r; - FILE *f; - union { - struct sockaddr sa; - struct sockaddr_in sain; - struct sockaddr_in6 sain6; - } sa; - - next: - switch (as->as_state) { - - case ASR_STATE_INIT: - - /* - * First, make sure the parameters are valid. - */ - - as->as_count = 0; - - if (as->as.ai.hostname == NULL && - as->as.ai.servname == NULL) { - ar->ar_gai_errno = EAI_NONAME; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as.ai.hostname && as->as.ai.hostname[0] == '\0') { - ar->ar_gai_errno = EAI_NODATA; - async_set_state(as, ASR_STATE_HALT); - break; - } - - ai = &as->as.ai.hints; - -#ifdef EAI_BADHINTS - if (ai->ai_addrlen || - ai->ai_canonname || - ai->ai_addr || - ai->ai_next) { - ar->ar_gai_errno = EAI_BADHINTS; - async_set_state(as, ASR_STATE_HALT); - break; - } -#endif - - if (ai->ai_flags & ~AI_MASK || - (ai->ai_flags & AI_CANONNAME && ai->ai_flags & AI_FQDN)) { - ar->ar_gai_errno = EAI_BADFLAGS; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (ai->ai_family != PF_UNSPEC && - ai->ai_family != PF_INET && - ai->ai_family != PF_INET6) { - ar->ar_gai_errno = EAI_FAMILY; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (ai->ai_socktype && - ai->ai_socktype != SOCK_DGRAM && - ai->ai_socktype != SOCK_STREAM && - ai->ai_socktype != SOCK_RAW) { - ar->ar_gai_errno = EAI_SOCKTYPE; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (ai->ai_socktype == SOCK_RAW && - get_port(as->as.ai.servname, NULL, 1) != 0) { - ar->ar_gai_errno = EAI_SERVICE; - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Restrict result set to configured address families */ - if (ai->ai_flags & AI_ADDRCONFIG) { - if (addrconfig_setup(as) == -1) { - ar->ar_errno = errno; - ar->ar_gai_errno = EAI_SYSTEM; - async_set_state(as, ASR_STATE_HALT); - break; - } - } - - /* Make sure there is at least a valid combination */ - for (i = 0; matches[i].family != -1; i++) - if (MATCH_FAMILY(ai->ai_family, i) && - MATCH_SOCKTYPE(ai->ai_socktype, i) && - MATCH_PROTO(ai->ai_protocol, i)) - break; - if (matches[i].family == -1) { -#ifdef EAI_BADHINTS - ar->ar_gai_errno = EAI_BADHINTS; -#else - ar->ar_gai_errno = EAI_FAIL; -#endif - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (ai->ai_protocol == 0 || ai->ai_protocol == IPPROTO_UDP) - as->as.ai.port_udp = get_port(as->as.ai.servname, "udp", - as->as.ai.hints.ai_flags & AI_NUMERICSERV); - if (ai->ai_protocol == 0 || ai->ai_protocol == IPPROTO_TCP) - as->as.ai.port_tcp = get_port(as->as.ai.servname, "tcp", - as->as.ai.hints.ai_flags & AI_NUMERICSERV); - if (as->as.ai.port_tcp == -2 || as->as.ai.port_udp == -2 || - (as->as.ai.port_tcp == -1 && as->as.ai.port_udp == -1) || - (ai->ai_protocol && (as->as.ai.port_udp == -1 || - as->as.ai.port_tcp == -1))) { - ar->ar_gai_errno = EAI_SERVICE; - async_set_state(as, ASR_STATE_HALT); - break; - } - - ar->ar_gai_errno = 0; - - /* If hostname is NULL, use local address */ - if (as->as.ai.hostname == NULL) { - for (family = iter_family(as, 1); - family != -1; - family = iter_family(as, 0)) { - /* - * We could use statically built sockaddrs for - * those, rather than parsing over and over. - */ - if (family == PF_INET) - str = (ai->ai_flags & AI_PASSIVE) ? \ - "0.0.0.0" : "127.0.0.1"; - else /* PF_INET6 */ - str = (ai->ai_flags & AI_PASSIVE) ? \ - "::" : "::1"; - /* This can't fail */ - _asr_sockaddr_from_str(&sa.sa, family, str); - if ((r = addrinfo_add(as, &sa.sa, NULL))) { - ar->ar_gai_errno = r; - break; - } - } - if (ar->ar_gai_errno == 0 && as->as_count == 0) { - ar->ar_gai_errno = EAI_NODATA; - } - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Try numeric addresses first */ - for (family = iter_family(as, 1); - family != -1; - family = iter_family(as, 0)) { - - if (_asr_sockaddr_from_str(&sa.sa, family, - as->as.ai.hostname) == -1) - continue; - - if ((r = addrinfo_add(as, &sa.sa, NULL))) - ar->ar_gai_errno = r; - break; - } - if (ar->ar_gai_errno || as->as_count) { - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (ai->ai_flags & AI_NUMERICHOST) { - ar->ar_gai_errno = EAI_NONAME; - async_set_state(as, ASR_STATE_HALT); - break; - } - - async_set_state(as, ASR_STATE_NEXT_DB); - break; - - case ASR_STATE_NEXT_DB: - if (_asr_iter_db(as) == -1) { - async_set_state(as, ASR_STATE_NOT_FOUND); - break; - } - as->as_family_idx = 0; - async_set_state(as, ASR_STATE_SAME_DB); - break; - - case ASR_STATE_NEXT_FAMILY: - as->as_family_idx += 1; - if (as->as.ai.hints.ai_family != AF_UNSPEC || - AS_FAMILY(as) == -1) { - /* The family was specified, or we have tried all - * families with this DB. - */ - if (as->as_count) { - ar->ar_gai_errno = 0; - async_set_state(as, ASR_STATE_HALT); - } else - async_set_state(as, ASR_STATE_NEXT_DOMAIN); - break; - } - async_set_state(as, ASR_STATE_SAME_DB); - break; - - case ASR_STATE_NEXT_DOMAIN: - /* domain search is only for dns */ - if (AS_DB(as) != ASR_DB_DNS) { - async_set_state(as, ASR_STATE_NEXT_DB); - break; - } - as->as_family_idx = 0; - - free(as->as.ai.fqdn); - as->as.ai.fqdn = NULL; - r = _asr_iter_domain(as, as->as.ai.hostname, fqdn, sizeof(fqdn)); - if (r == -1) { - async_set_state(as, ASR_STATE_NEXT_DB); - break; - } - if (r == 0) { - ar->ar_gai_errno = EAI_FAIL; - async_set_state(as, ASR_STATE_HALT); - break; - } - as->as.ai.fqdn = strdup(fqdn); - if (as->as.ai.fqdn == NULL) { - ar->ar_gai_errno = EAI_MEMORY; - async_set_state(as, ASR_STATE_HALT); - break; - } - - async_set_state(as, ASR_STATE_SAME_DB); - break; - - case ASR_STATE_SAME_DB: - /* query the current DB again */ - switch (AS_DB(as)) { - case ASR_DB_DNS: - if (as->as.ai.fqdn == NULL) { - /* First try, initialize domain iteration */ - as->as_dom_flags = 0; - as->as_dom_step = DOM_INIT; - async_set_state(as, ASR_STATE_NEXT_DOMAIN); - break; - } - - family = (as->as.ai.hints.ai_family == AF_UNSPEC) ? - AS_FAMILY(as) : as->as.ai.hints.ai_family; - - if (family == AF_INET && - as->as_flags & ASYNC_NO_INET) { - async_set_state(as, ASR_STATE_NEXT_FAMILY); - break; - } else if (family == AF_INET6 && - as->as_flags & ASYNC_NO_INET6) { - async_set_state(as, ASR_STATE_NEXT_FAMILY); - break; - } - - as->as_subq = _res_query_async_ctx(as->as.ai.fqdn, - C_IN, (family == AF_INET6) ? T_AAAA : T_A, - as->as_ctx); - - if (as->as_subq == NULL) { - if (errno == ENOMEM) - ar->ar_gai_errno = EAI_MEMORY; - else - ar->ar_gai_errno = EAI_FAIL; - async_set_state(as, ASR_STATE_HALT); - break; - } - async_set_state(as, ASR_STATE_SUBQUERY); - break; - - case ASR_DB_FILE: - f = fopen(_PATH_HOSTS, "re"); - if (f == NULL) { - async_set_state(as, ASR_STATE_NEXT_DB); - break; - } - family = (as->as.ai.hints.ai_family == AF_UNSPEC) ? - AS_FAMILY(as) : as->as.ai.hints.ai_family; - - r = addrinfo_from_file(as, family, f); - if (r == -1) { - if (errno == ENOMEM) - ar->ar_gai_errno = EAI_MEMORY; - else - ar->ar_gai_errno = EAI_FAIL; - async_set_state(as, ASR_STATE_HALT); - } else - async_set_state(as, ASR_STATE_NEXT_FAMILY); - fclose(f); - break; - - default: - async_set_state(as, ASR_STATE_NEXT_DB); - } - break; - - case ASR_STATE_SUBQUERY: - if ((r = asr_run(as->as_subq, ar)) == ASYNC_COND) - return (ASYNC_COND); - - as->as_subq = NULL; - - if (ar->ar_datalen == -1) { - async_set_state(as, ASR_STATE_NEXT_FAMILY); - break; - } - - r = addrinfo_from_pkt(as, ar->ar_data, ar->ar_datalen); - if (r == -1) { - if (errno == ENOMEM) - ar->ar_gai_errno = EAI_MEMORY; - else - ar->ar_gai_errno = EAI_FAIL; - async_set_state(as, ASR_STATE_HALT); - } else - async_set_state(as, ASR_STATE_NEXT_FAMILY); - free(ar->ar_data); - break; - - case ASR_STATE_NOT_FOUND: - /* No result found. Maybe we can try again. */ - if (as->as_flags & ASYNC_AGAIN) - ar->ar_gai_errno = EAI_AGAIN; - else - ar->ar_gai_errno = EAI_NODATA; - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_HALT: - if (ar->ar_gai_errno == 0) { - ar->ar_count = as->as_count; - ar->ar_addrinfo = as->as.ai.aifirst; - as->as.ai.aifirst = NULL; - } else { - ar->ar_count = 0; - ar->ar_addrinfo = NULL; - } - return (ASYNC_DONE); - - default: - ar->ar_errno = EOPNOTSUPP; - ar->ar_gai_errno = EAI_SYSTEM; - async_set_state(as, ASR_STATE_HALT); - break; - } - goto next; -} - -/* - * Retreive the port number for the service name "servname" and - * the protocol "proto". - */ -static int -get_port(const char *servname, const char *proto, int numonly) -{ -#ifdef HAVE_GETSERVBYNAME_R_4_ARGS - struct servent se; -#endif -#ifdef HAVE_STRUCT_SERVENT_DATA - struct servent_data sed; -#endif - int port; - const char *e; - - if (servname == NULL) - return (0); - - e = NULL; - port = strtonum(servname, 0, USHRT_MAX, &e); - if (e == NULL) - return (port); - if (errno == ERANGE) - return (-2); /* invalid */ - if (numonly) - return (-2); - - port = -1; -#ifdef HAVE_STRUCT_SERVENT_DATA - memset(&sed, 0, sizeof(sed)); -#endif -#ifdef HAVE_GETSERVBYNAME_R_4_ARGS - if (getservbyname_r(servname, proto, &se, &sed) != -1) - port = ntohs(se.s_port); -#endif -#ifdef HAVE_ENDSERVENT_R - endservent_r(&sed); -#endif - - return (port); -} - -/* - * Iterate over the address families that are to be queried. Use the - * list on the async context, unless a specific family was given in hints. - */ -static int -iter_family(struct asr_query *as, int first) -{ - if (first) { - as->as_family_idx = 0; - if (as->as.ai.hints.ai_family != PF_UNSPEC) - return as->as.ai.hints.ai_family; - return AS_FAMILY(as); - } - - if (as->as.ai.hints.ai_family != PF_UNSPEC) - return (-1); - - as->as_family_idx++; - - return AS_FAMILY(as); -} - -/* - * Use the sockaddr at "sa" to extend the result list on the "as" context, - * with the specified canonical name "cname". This function adds one - * entry per protocol/socktype match. - */ -static int -addrinfo_add(struct asr_query *as, const struct sockaddr *sa, const char *cname) -{ - struct addrinfo *ai; - int i, port, proto; - - for (i = 0; matches[i].family != -1; i++) { - if (matches[i].family != sa->sa_family || - !MATCH_SOCKTYPE(as->as.ai.hints.ai_socktype, i) || - !MATCH_PROTO(as->as.ai.hints.ai_protocol, i)) - continue; - - proto = as->as.ai.hints.ai_protocol; - if (!proto) - proto = matches[i].protocol; - - if (proto == IPPROTO_TCP) - port = as->as.ai.port_tcp; - else if (proto == IPPROTO_UDP) - port = as->as.ai.port_udp; - else - port = 0; - - /* servname specified, but not defined for this protocol */ - if (port == -1) - continue; - - ai = calloc(1, sizeof(*ai) + SA_LEN(sa)); - if (ai == NULL) - return (EAI_MEMORY); - ai->ai_family = sa->sa_family; - ai->ai_socktype = matches[i].socktype; - ai->ai_protocol = proto; - ai->ai_flags = as->as.ai.hints.ai_flags; - ai->ai_addrlen = SA_LEN(sa); - ai->ai_addr = (void *)(ai + 1); - if (cname && - as->as.ai.hints.ai_flags & (AI_CANONNAME | AI_FQDN)) { - if ((ai->ai_canonname = strdup(cname)) == NULL) { - free(ai); - return (EAI_MEMORY); - } - } - memmove(ai->ai_addr, sa, SA_LEN(sa)); - if (sa->sa_family == PF_INET) - ((struct sockaddr_in *)ai->ai_addr)->sin_port = - htons(port); - else if (sa->sa_family == PF_INET6) - ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port = - htons(port); - - if (as->as.ai.aifirst == NULL) - as->as.ai.aifirst = ai; - if (as->as.ai.ailast) - as->as.ai.ailast->ai_next = ai; - as->as.ai.ailast = ai; - as->as_count += 1; - } - - return (0); -} - -void -asr_freeaddrinfo(struct addrinfo *ai) -{ - struct addrinfo *ai_next; - - while (ai) { - ai_next = ai->ai_next; - if (ai->ai_canonname) - free(ai->ai_canonname); - free(ai); - ai = ai_next; - } -} - -static int -addrinfo_from_file(struct asr_query *as, int family, FILE *f) -{ - char *tokens[MAXTOKEN], *c, buf[ASR_BUFSIZ + 1]; - int n, i; - union { - struct sockaddr sa; - struct sockaddr_in sain; - struct sockaddr_in6 sain6; - } u; - - for (;;) { - n = _asr_parse_namedb_line(f, tokens, MAXTOKEN, buf, sizeof(buf)); - if (n == -1) - break; /* ignore errors reading the file */ - - for (i = 1; i < n; i++) { - if (strcasecmp(as->as.ai.hostname, tokens[i])) - continue; - if (_asr_sockaddr_from_str(&u.sa, family, tokens[0]) == -1) - continue; - break; - } - if (i == n) - continue; - - if (as->as.ai.hints.ai_flags & (AI_CANONNAME | AI_FQDN)) - c = tokens[1]; - else - c = NULL; - - if (addrinfo_add(as, &u.sa, c)) - return (-1); /* errno set */ - } - return (0); -} - -static int -addrinfo_from_pkt(struct asr_query *as, char *pkt, size_t pktlen) -{ - struct asr_unpack p; - struct asr_dns_header h; - struct asr_dns_query q; - struct asr_dns_rr rr; - int i; - union { - struct sockaddr sa; - struct sockaddr_in sain; - struct sockaddr_in6 sain6; - } u; - char buf[MAXDNAME], *c; - - _asr_unpack_init(&p, pkt, pktlen); - _asr_unpack_header(&p, &h); - for (; h.qdcount; h.qdcount--) - _asr_unpack_query(&p, &q); - - for (i = 0; i < h.ancount; i++) { - _asr_unpack_rr(&p, &rr); - if (rr.rr_type != q.q_type || - rr.rr_class != q.q_class) - continue; - - memset(&u, 0, sizeof u); - if (rr.rr_type == T_A) { -#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - u.sain.sin_len = sizeof u.sain; -#endif - u.sain.sin_family = AF_INET; - u.sain.sin_addr = rr.rr.in_a.addr; - u.sain.sin_port = 0; - } else if (rr.rr_type == T_AAAA) { -#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN - u.sain6.sin6_len = sizeof u.sain6; -#endif - u.sain6.sin6_family = AF_INET6; - u.sain6.sin6_addr = rr.rr.in_aaaa.addr6; - u.sain6.sin6_port = 0; - } else - continue; - - if (as->as.ai.hints.ai_flags & AI_CANONNAME) { - _asr_strdname(rr.rr_dname, buf, sizeof buf); - buf[strlen(buf) - 1] = '\0'; - c = res_hnok(buf) ? buf : NULL; - } else if (as->as.ai.hints.ai_flags & AI_FQDN) - c = as->as.ai.fqdn; - else - c = NULL; - - if (addrinfo_add(as, &u.sa, c)) - return (-1); /* errno set */ - } - return (0); -} - -static int -addrconfig_setup(struct asr_query *as) -{ - struct ifaddrs *ifa, *ifa0; - struct sockaddr_in *sinp; - struct sockaddr_in6 *sin6p; - - if (getifaddrs(&ifa0) == -1) - return (-1); - - as->as_flags |= ASYNC_NO_INET | ASYNC_NO_INET6; - - for (ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - - switch (ifa->ifa_addr->sa_family) { - case PF_INET: - sinp = (struct sockaddr_in *)ifa->ifa_addr; - - if (sinp->sin_addr.s_addr == htonl(INADDR_LOOPBACK)) - continue; - - as->as_flags &= ~ASYNC_NO_INET; - break; - case PF_INET6: - sin6p = (struct sockaddr_in6 *)ifa->ifa_addr; - - if (IN6_IS_ADDR_LOOPBACK(&sin6p->sin6_addr)) - continue; - - if (IN6_IS_ADDR_LINKLOCAL(&sin6p->sin6_addr)) - continue; - - as->as_flags &= ~ASYNC_NO_INET6; - break; - } - } - - freeifaddrs(ifa0); - - return (0); -} diff --git a/foobar/portable/openbsd-compat/libasr/gethostnamadr.c b/foobar/portable/openbsd-compat/libasr/gethostnamadr.c deleted file mode 100644 index 2fce46b3..00000000 --- a/foobar/portable/openbsd-compat/libasr/gethostnamadr.c +++ /dev/null @@ -1,200 +0,0 @@ -/* $OpenBSD: gethostnamadr.c,v 1.13 2015/09/14 07:38:37 guenther Exp $ */ -/* - * Copyright (c) 2012,2013 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include /* ALIGN */ -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static int _gethostbyname(const char *, int, struct hostent *, char *, size_t, - int *); -static int _fillhostent(const struct hostent *, struct hostent *, char *, - size_t); - -static struct hostent _hostent; -static char _entbuf[4096]; - -static char *_empty[] = { NULL, }; - -static int -_fillhostent(const struct hostent *h, struct hostent *r, char *buf, size_t len) -{ - char **ptr, *end, *pos; - size_t n, i; - int naliases, naddrs; - - bzero(buf, len); - bzero(r, sizeof(*r)); - r->h_aliases = _empty; - r->h_addr_list = _empty; - - end = buf + len; - ptr = (char **)ALIGN(buf); - - if ((char *)ptr >= end) - return (ERANGE); - - for (naliases = 0; h->h_aliases[naliases]; naliases++) - ; - for (naddrs = 0; h->h_addr_list[naddrs]; naddrs++) - ; - - pos = (char *)(ptr + (naliases + 1) + (naddrs + 1)); - if (pos >= end) - return (ERANGE); - - r->h_name = NULL; - r->h_addrtype = h->h_addrtype; - r->h_length = h->h_length; - r->h_aliases = ptr; - r->h_addr_list = ptr + naliases + 1; - - n = strlcpy(pos, h->h_name, end - pos); - if (n >= end - pos) - return (ERANGE); - r->h_name = pos; - pos += n + 1; - - for (i = 0; i < naliases; i++) { - n = strlcpy(pos, h->h_aliases[i], end - pos); - if (n >= end - pos) - return (ERANGE); - r->h_aliases[i] = pos; - pos += n + 1; - } - - pos = (char *)ALIGN(pos); - if (pos >= end) - return (ERANGE); - - for (i = 0; i < naddrs; i++) { - if (r->h_length > end - pos) - return (ERANGE); - memmove(pos, h->h_addr_list[i], r->h_length); - r->h_addr_list[i] = pos; - pos += r->h_length; - } - - return (0); -} - -static int -_gethostbyname(const char *name, int af, struct hostent *ret, char *buf, - size_t buflen, int *h_errnop) -{ - struct asr_query *as; - struct asr_result ar; - int r; - - if (af == -1) - as = gethostbyname_async(name, NULL); - else - as = gethostbyname2_async(name, af, NULL); - - if (as == NULL) - return (errno); - - asr_run_sync(as, &ar); - - errno = ar.ar_errno; - *h_errnop = ar.ar_h_errno; - if (ar.ar_hostent == NULL) - return (0); - - r = _fillhostent(ar.ar_hostent, ret, buf, buflen); - free(ar.ar_hostent); - - return (r); -} - -struct hostent * -gethostbyname(const char *name) -{ - struct hostent *h; - - res_init(); - - if (_res.options & RES_USE_INET6 && - (h = gethostbyname2(name, AF_INET6))) - return (h); - - return gethostbyname2(name, AF_INET); -} -DEF_WEAK(gethostbyname); - -struct hostent * -gethostbyname2(const char *name, int af) -{ - int r; - - res_init(); - - r = _gethostbyname(name, af, &_hostent, _entbuf, sizeof(_entbuf), - &h_errno); - if (r) { - h_errno = NETDB_INTERNAL; - errno = r; - } - - if (h_errno) - return (NULL); - - return (&_hostent); -} -DEF_WEAK(gethostbyname2); - -struct hostent * -gethostbyaddr(const void *addr, socklen_t len, int af) -{ - struct asr_query *as; - struct asr_result ar; - int r; - - res_init(); - - as = gethostbyaddr_async(addr, len, af, NULL); - if (as == NULL) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - - asr_run_sync(as, &ar); - - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; - if (ar.ar_hostent == NULL) - return (NULL); - - r = _fillhostent(ar.ar_hostent, &_hostent, _entbuf, sizeof(_entbuf)); - free(ar.ar_hostent); - - if (r) { - h_errno = NETDB_INTERNAL; - errno = r; - return (NULL); - } - - return (&_hostent); -} diff --git a/foobar/portable/openbsd-compat/libasr/gethostnamadr_async.c b/foobar/portable/openbsd-compat/libasr/gethostnamadr_async.c deleted file mode 100644 index 2636e848..00000000 --- a/foobar/portable/openbsd-compat/libasr/gethostnamadr_async.c +++ /dev/null @@ -1,676 +0,0 @@ -/* $OpenBSD: gethostnamadr_async.c,v 1.45 2019/06/27 05:26:37 martijn Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif -#include - -#include -#include -#include -#include /* for res_hnok */ -#include -#include -#include -#include - -#include "asr_private.h" - -#define MAXALIASES 35 -#define MAXADDRS 35 - -struct hostent_ext { - struct hostent h; - char *aliases[MAXALIASES + 1]; - char *addrs[MAXADDRS + 1]; - char *end; - char *pos; -}; - -struct netent_ext { - struct netent n; - char *aliases[MAXALIASES + 1]; - char *end; - char *pos; -}; - -static int gethostnamadr_async_run(struct asr_query *, struct asr_result *); -static struct hostent_ext *hostent_alloc(int); -static int hostent_set_cname(struct hostent_ext *, const char *, int); -static int hostent_add_alias(struct hostent_ext *, const char *, int); -static int hostent_add_addr(struct hostent_ext *, const void *, size_t); -static struct hostent_ext *hostent_from_addr(int, const char *, const char *); -static struct hostent_ext *hostent_file_match(FILE *, int, int, const char *, - int); -static struct hostent_ext *hostent_from_packet(int, int, char *, size_t); -static void netent_from_hostent(struct asr_result *ar); - -struct asr_query * -gethostbyname_async(const char *name, void *asr) -{ - return gethostbyname2_async(name, AF_INET, asr); -} -DEF_WEAK(gethostbyname_async); - -struct asr_query * -gethostbyname2_async(const char *name, int af, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - /* the original segfaults */ - if (name == NULL) { - errno = EINVAL; - return (NULL); - } - - ac = _asr_use_resolver(asr); - if ((as = _asr_async_new(ac, ASR_GETHOSTBYNAME)) == NULL) - goto abort; /* errno set */ - as->as_run = gethostnamadr_async_run; - - as->as.hostnamadr.family = af; - if (af == AF_INET) - as->as.hostnamadr.addrlen = INADDRSZ; - else if (af == AF_INET6) - as->as.hostnamadr.addrlen = IN6ADDRSZ; - as->as.hostnamadr.name = strdup(name); - if (as->as.hostnamadr.name == NULL) - goto abort; /* errno set */ - - _asr_ctx_unref(ac); - return (as); - - abort: - if (as) - _asr_async_free(as); - _asr_ctx_unref(ac); - return (NULL); -} -DEF_WEAK(gethostbyname2_async); - -struct asr_query * -gethostbyaddr_async(const void *addr, socklen_t len, int af, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - ac = _asr_use_resolver(asr); - as = _gethostbyaddr_async_ctx(addr, len, af, ac); - _asr_ctx_unref(ac); - - return (as); -} -DEF_WEAK(gethostbyaddr_async); - -struct asr_query * -_gethostbyaddr_async_ctx(const void *addr, socklen_t len, int af, - struct asr_ctx *ac) -{ - struct asr_query *as; - - if ((as = _asr_async_new(ac, ASR_GETHOSTBYADDR)) == NULL) - goto abort; /* errno set */ - as->as_run = gethostnamadr_async_run; - - as->as.hostnamadr.family = af; - as->as.hostnamadr.addrlen = len; - if (len > 0) - memmove(as->as.hostnamadr.addr, addr, (len > 16) ? 16 : len); - - return (as); - - abort: - if (as) - _asr_async_free(as); - return (NULL); -} - -static int -gethostnamadr_async_run(struct asr_query *as, struct asr_result *ar) -{ - struct hostent_ext *h; - int r, type, saved_errno; - FILE *f; - char name[MAXDNAME], *data, addr[16], *c; - - next: - switch (as->as_state) { - - case ASR_STATE_INIT: - - if (as->as.hostnamadr.family != AF_INET && - as->as.hostnamadr.family != AF_INET6) { - ar->ar_h_errno = NETDB_INTERNAL; - ar->ar_errno = EAFNOSUPPORT; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if ((as->as.hostnamadr.family == AF_INET && - as->as.hostnamadr.addrlen != INADDRSZ) || - (as->as.hostnamadr.family == AF_INET6 && - as->as.hostnamadr.addrlen != IN6ADDRSZ)) { - ar->ar_h_errno = NETDB_INTERNAL; - ar->ar_errno = EINVAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as_type == ASR_GETHOSTBYNAME) { - - if (as->as.hostnamadr.name[0] == '\0') { - ar->ar_h_errno = NO_DATA; - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Name might be an IP address string */ - for (c = as->as.hostnamadr.name; *c; c++) - if (!isdigit((unsigned char)*c) && - *c != '.' && *c != ':') - break; - if (*c == 0 && - inet_pton(as->as.hostnamadr.family, - as->as.hostnamadr.name, addr) == 1) { - h = hostent_from_addr(as->as.hostnamadr.family, - as->as.hostnamadr.name, addr); - if (h == NULL) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; - } - else { - ar->ar_hostent = &h->h; - ar->ar_h_errno = NETDB_SUCCESS; - } - async_set_state(as, ASR_STATE_HALT); - break; - } - } - async_set_state(as, ASR_STATE_NEXT_DB); - break; - - case ASR_STATE_NEXT_DB: - - if (_asr_iter_db(as) == -1) { - async_set_state(as, ASR_STATE_NOT_FOUND); - break; - } - - switch (AS_DB(as)) { - - case ASR_DB_DNS: - - /* Create a subquery to do the DNS lookup */ - - if (as->as_type == ASR_GETHOSTBYNAME) { - type = (as->as.hostnamadr.family == AF_INET) ? - T_A : T_AAAA; - as->as_subq = _res_search_async_ctx( - as->as.hostnamadr.name, - C_IN, type, as->as_ctx); - } else { - _asr_addr_as_fqdn(as->as.hostnamadr.addr, - as->as.hostnamadr.family, - name, sizeof(name)); - as->as_subq = _res_query_async_ctx( - name, C_IN, T_PTR, as->as_ctx); - } - - if (as->as_subq == NULL) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - async_set_state(as, ASR_STATE_SUBQUERY); - break; - - case ASR_DB_FILE: - - /* Try to find a match in the host file */ - - if ((f = fopen(_PATH_HOSTS, "re")) == NULL) - break; - - if (as->as_type == ASR_GETHOSTBYNAME) - data = as->as.hostnamadr.name; - else - data = as->as.hostnamadr.addr; - - h = hostent_file_match(f, as->as_type, - as->as.hostnamadr.family, data, - as->as.hostnamadr.addrlen); - saved_errno = errno; - fclose(f); - errno = saved_errno; - - if (h == NULL) { - if (errno) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; - async_set_state(as, ASR_STATE_HALT); - } - /* otherwise not found */ - break; - } - ar->ar_hostent = &h->h; - ar->ar_h_errno = NETDB_SUCCESS; - async_set_state(as, ASR_STATE_HALT); - break; - } - break; - - case ASR_STATE_SUBQUERY: - - /* Run the DNS subquery. */ - - if ((r = asr_run(as->as_subq, ar)) == ASYNC_COND) - return (ASYNC_COND); - - /* Done. */ - as->as_subq = NULL; - - /* - * We either got no packet or a packet without an answer. - * Saveguard the h_errno and use the next DB. - */ - if (ar->ar_count == 0) { - free(ar->ar_data); - as->as.hostnamadr.subq_h_errno = ar->ar_h_errno; - async_set_state(as, ASR_STATE_NEXT_DB); - break; - } - - /* Read the hostent from the packet. */ - - h = hostent_from_packet(as->as_type, - as->as.hostnamadr.family, ar->ar_data, ar->ar_datalen); - free(ar->ar_data); - if (h == NULL) { - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as_type == ASR_GETHOSTBYADDR) { - if (hostent_add_addr(h, as->as.hostnamadr.addr, - as->as.hostnamadr.addrlen) == -1) { - free(h); - ar->ar_errno = errno; - ar->ar_h_errno = NETDB_INTERNAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - } - - /* - * No valid hostname or address found in the dns packet. - * Ignore it. - */ - if ((as->as_type == ASR_GETHOSTBYNAME && - h->h.h_addr_list[0] == NULL) || - h->h.h_name == NULL) { - free(h); - async_set_state(as, ASR_STATE_NEXT_DB); - break; - } - - ar->ar_hostent = &h->h; - ar->ar_h_errno = NETDB_SUCCESS; - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_NOT_FOUND: - ar->ar_errno = 0; - if (as->as.hostnamadr.subq_h_errno) - ar->ar_h_errno = as->as.hostnamadr.subq_h_errno; - else - ar->ar_h_errno = HOST_NOT_FOUND; - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_HALT: - if (ar->ar_h_errno == NETDB_SUCCESS && - as->as_flags & ASYNC_GETNET) - netent_from_hostent(ar); - if (ar->ar_h_errno) { - ar->ar_hostent = NULL; - ar->ar_netent = NULL; - } else - ar->ar_errno = 0; - return (ASYNC_DONE); - - default: - ar->ar_errno = EOPNOTSUPP; - ar->ar_h_errno = NETDB_INTERNAL; - ar->ar_gai_errno = EAI_SYSTEM; - async_set_state(as, ASR_STATE_HALT); - break; - } - goto next; -} - -/* - * Create a hostent from a numeric address string. - */ -static struct hostent_ext * -hostent_from_addr(int family, const char *name, const char *addr) -{ - struct hostent_ext *h; - - if ((h = hostent_alloc(family)) == NULL) - return (NULL); - if (hostent_set_cname(h, name, 0) == -1) - goto fail; - if (hostent_add_addr(h, addr, h->h.h_length) == -1) - goto fail; - return (h); -fail: - free(h); - return (NULL); -} - -/* - * Lookup the first matching entry in the hostfile, either by address or by - * name depending on reqtype, and build a hostent from the line. - */ -static struct hostent_ext * -hostent_file_match(FILE *f, int reqtype, int family, const char *data, - int datalen) -{ - char *tokens[MAXTOKEN], addr[16], buf[ASR_BUFSIZ + 1]; - struct hostent_ext *h; - int n, i; - - for (;;) { - n = _asr_parse_namedb_line(f, tokens, MAXTOKEN, buf, sizeof(buf)); - if (n == -1) { - errno = 0; /* ignore errors reading the file */ - return (NULL); - } - - /* there must be an address and at least one name */ - if (n < 2) - continue; - - if (reqtype == ASR_GETHOSTBYNAME) { - for (i = 1; i < n; i++) { - if (strcasecmp(data, tokens[i])) - continue; - if (inet_pton(family, tokens[0], addr) == 1) - goto found; - } - } else { - if (inet_pton(family, tokens[0], addr) == 1 && - memcmp(addr, data, datalen) == 0) - goto found; - } - } - -found: - if ((h = hostent_alloc(family)) == NULL) - return (NULL); - if (hostent_set_cname(h, tokens[1], 0) == -1) - goto fail; - for (i = 2; i < n; i ++) - if (hostent_add_alias(h, tokens[i], 0) == -1) - goto fail; - if (hostent_add_addr(h, addr, h->h.h_length) == -1) - goto fail; - return (h); -fail: - free(h); - return (NULL); -} - -/* - * Fill the hostent from the given DNS packet. - */ -static struct hostent_ext * -hostent_from_packet(int reqtype, int family, char *pkt, size_t pktlen) -{ - struct hostent_ext *h; - struct asr_unpack p; - struct asr_dns_header hdr; - struct asr_dns_query q; - struct asr_dns_rr rr; - char dname[MAXDNAME]; - - if ((h = hostent_alloc(family)) == NULL) - return (NULL); - - _asr_unpack_init(&p, pkt, pktlen); - _asr_unpack_header(&p, &hdr); - for (; hdr.qdcount; hdr.qdcount--) - _asr_unpack_query(&p, &q); - strlcpy(dname, q.q_dname, sizeof(dname)); - - for (; hdr.ancount; hdr.ancount--) { - _asr_unpack_rr(&p, &rr); - if (rr.rr_class != C_IN) - continue; - switch (rr.rr_type) { - - case T_CNAME: - if (reqtype == ASR_GETHOSTBYNAME) { - if (hostent_add_alias(h, rr.rr_dname, 1) == -1) - goto fail; - } else { - if (strcasecmp(rr.rr_dname, dname) == 0) - strlcpy(dname, rr.rr.cname.cname, - sizeof(dname)); - } - break; - - case T_PTR: - if (reqtype != ASR_GETHOSTBYADDR) - break; - if (strcasecmp(rr.rr_dname, dname) != 0) - continue; - if (hostent_set_cname(h, rr.rr.ptr.ptrname, 1) == -1) - hostent_add_alias(h, rr.rr.ptr.ptrname, 1); - break; - - case T_A: - if (reqtype != ASR_GETHOSTBYNAME) - break; - if (family != AF_INET) - break; - if (hostent_set_cname(h, rr.rr_dname, 1) == -1) - ; - if (hostent_add_addr(h, &rr.rr.in_a.addr, 4) == -1) - goto fail; - break; - - case T_AAAA: - if (reqtype != ASR_GETHOSTBYNAME) - break; - if (family != AF_INET6) - break; - if (hostent_set_cname(h, rr.rr_dname, 1) == -1) - ; - if (hostent_add_addr(h, &rr.rr.in_aaaa.addr6, 16) == -1) - goto fail; - break; - } - } - - return (h); -fail: - free(h); - return (NULL); -} - -static struct hostent_ext * -hostent_alloc(int family) -{ - struct hostent_ext *h; - size_t alloc; - - alloc = sizeof(*h) + 1024; - if ((h = calloc(1, alloc)) == NULL) - return (NULL); - - h->h.h_addrtype = family; - h->h.h_length = (family == AF_INET) ? 4 : 16; - h->h.h_aliases = h->aliases; - h->h.h_addr_list = h->addrs; - h->pos = (char *)(h) + sizeof(*h); - h->end = h->pos + 1024; - - return (h); -} - -static int -hostent_set_cname(struct hostent_ext *h, const char *name, int isdname) -{ - char buf[MAXDNAME]; - size_t n; - - if (h->h.h_name) - return (-1); - - if (isdname) { - _asr_strdname(name, buf, sizeof buf); - buf[strlen(buf) - 1] = '\0'; - if (!res_hnok(buf)) - return (-1); - name = buf; - } - - n = strlen(name) + 1; - if (h->pos + n >= h->end) - return (-1); - - h->h.h_name = h->pos; - memmove(h->pos, name, n); - h->pos += n; - return (0); -} - -static int -hostent_add_alias(struct hostent_ext *h, const char *name, int isdname) -{ - char buf[MAXDNAME]; - size_t i, n; - - for (i = 0; i < MAXALIASES; i++) - if (h->aliases[i] == NULL) - break; - if (i == MAXALIASES) - return (0); - - if (isdname) { - _asr_strdname(name, buf, sizeof buf); - buf[strlen(buf)-1] = '\0'; - if (!res_hnok(buf)) - return (-1); - name = buf; - } - - n = strlen(name) + 1; - if (h->pos + n >= h->end) - return (0); - - h->aliases[i] = h->pos; - memmove(h->pos, name, n); - h->pos += n; - return (0); -} - -static int -hostent_add_addr(struct hostent_ext *h, const void *addr, size_t size) -{ - int i; - - for (i = 0; i < MAXADDRS; i++) - if (h->addrs[i] == NULL) - break; - if (i == MAXADDRS) - return (0); - - if (h->pos + size >= h->end) - return (0); - - h->addrs[i] = h->pos; - memmove(h->pos, addr, size); - h->pos += size; - return (0); -} - -static void -netent_from_hostent(struct asr_result *ar) -{ - struct in_addr *addr; - struct netent_ext *n; - struct hostent_ext *h; - char **na, **ha; - size_t sz; - - /* Allocate and initialize the output. */ - if ((n = calloc(1, sizeof(*n) + 1024)) == NULL) { - ar->ar_h_errno = NETDB_INTERNAL; - ar->ar_errno = errno; - goto out; - } - n->pos = (char *)(n) + sizeof(*n); - n->end = n->pos + 1024; - n->n.n_name = n->pos; - n->n.n_aliases = n->aliases; - - /* Copy the fixed-size data. */ - h = (struct hostent_ext *)ar->ar_hostent; - addr = (struct in_addr *)h->h.h_addr; - n->n.n_net = ntohl(addr->s_addr); - n->n.n_addrtype = h->h.h_addrtype; - - /* Copy the network name. */ - sz = strlen(h->h.h_name) + 1; - memcpy(n->pos, h->h.h_name, sz); - n->pos += sz; - - /* - * Copy the aliases. - * No overflow check is needed because we are merely copying - * a part of the data from a structure of the same size. - */ - na = n->aliases; - for (ha = h->aliases; *ha != NULL; ha++) { - sz = strlen(*ha) + 1; - memcpy(n->pos, *ha, sz); - *na++ = n->pos; - n->pos += sz; - } - *na = NULL; - - /* Handle the return values. */ - ar->ar_netent = &n->n; -out: - free(ar->ar_hostent); - ar->ar_hostent = NULL; -} diff --git a/foobar/portable/openbsd-compat/libasr/getnameinfo.c b/foobar/portable/openbsd-compat/libasr/getnameinfo.c deleted file mode 100644 index 7bee468d..00000000 --- a/foobar/portable/openbsd-compat/libasr/getnameinfo.c +++ /dev/null @@ -1,205 +0,0 @@ -/* $OpenBSD: getnameinfo.c,v 1.9 2019/07/03 03:24:03 deraadt Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -static size_t asr_print_addr(const struct sockaddr *, char *, size_t); -static size_t asr_print_port(const struct sockaddr *, const char *, char *, size_t); - -#define SA_IN(sa) ((struct sockaddr_in*)(sa)) -#define SA_IN6(sa) ((struct sockaddr_in6*)(sa)) - -/* - * Print the textual representation (as given by inet_ntop(3)) of the address - * set in "sa". - * - * Return the total length of the string it tried to create or 0 if an error - * occured, in which case errno is set. On success, the constructed string - * is guaranteed to be NUL-terminated. Overflow must be detected by checking - * the returned size against buflen. - * - */ -static size_t -asr_print_addr(const struct sockaddr *sa, char *buf, size_t buflen) -{ - unsigned int ifidx; - char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")]; - char scope[IF_NAMESIZE + 1], *ifname; - const void *addr; - size_t s; - - switch(sa->sa_family) { - case AF_INET: - addr = &SA_IN(sa)->sin_addr; - break; - case AF_INET6: - addr = &SA_IN6(sa)->sin6_addr; - break; - default: - errno = EINVAL; - return (0); - } - - if (inet_ntop(sa->sa_family, addr, tmp, sizeof(tmp)) == NULL) - return (0); /* errno set */ - - s = strlcpy(buf, tmp, buflen); - - if (sa->sa_family == AF_INET6 && SA_IN6(sa)->sin6_scope_id) { - - scope[0] = SCOPE_DELIMITER; - scope[1] = '\0'; - - ifidx = SA_IN6(sa)->sin6_scope_id; - ifname = NULL; - - if (IN6_IS_ADDR_LINKLOCAL(&(SA_IN6(sa)->sin6_addr)) || - IN6_IS_ADDR_MC_LINKLOCAL(&(SA_IN6(sa)->sin6_addr)) || - IN6_IS_ADDR_MC_INTFACELOCAL(&(SA_IN6(sa)->sin6_addr))) - ifname = if_indextoname(ifidx, scope + 1); - - if (ifname == NULL) - (void)snprintf(scope + 1, sizeof(scope) - 1, "%u", ifidx); - - if (s < buflen) - (void)strlcat(buf, scope, buflen); - - s += strlen(scope); - } - - return (s); -} - -/* - * Print the textual representation of the port set on "sa". - * - * If proto is not NULL, it is used as parameter to "getservbyport_r(3)" to - * return a service name. If it's not set, or if no matching service is found, - * it prints the portno. - * - * Return the total length of the string it tried to create or 0 if an error - * occured, in which case errno is set. On success, the constructed string - * is guaranteed to be NUL-terminated. Overflow must be detected by checking - * the returned size against buflen. - */ -static size_t -asr_print_port(const struct sockaddr *sa, const char *proto, char *buf, size_t buflen) -{ - struct servent s; - struct servent_data sd; - int port, r, saved_errno; - size_t n; - - switch(sa->sa_family) { - case AF_INET: - port = SA_IN(sa)->sin_port; - break; - case AF_INET6: - port = SA_IN6(sa)->sin6_port; - break; - default: - errno = EINVAL; - return (0); - } - - if (proto) { - memset(&sd, 0, sizeof (sd)); - saved_errno = errno; - if (getservbyport_r(port, proto, &s, &sd) != -1) { - n = strlcpy(buf, s.s_name, buflen); - endservent_r(&sd); - return (n); - } - errno = saved_errno; - } - - r = snprintf(buf, buflen, "%u", ntohs(port)); - if (r < 0 || r >= buflen) /* Actually, this can not happen */ - return (0); - - return (r); -} - -int -getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags) -{ - struct asr_query *as; - struct asr_result ar; - int saved_errno = errno; - const char *proto; - size_t r; - - /* - * Take a shortcut if we don't care about hostname, - * or if NI_NUMERICHOST is set. - */ - if (host == NULL || hostlen == 0 || - (host && hostlen && (flags & NI_NUMERICHOST))) { - if (host) { - r = asr_print_addr(sa, host, hostlen); - if (r == 0) - return (EAI_SYSTEM); /* errno set */ - if (r >= hostlen) - return (EAI_OVERFLOW); - } - - if (serv && servlen) { - if (flags & NI_NUMERICSERV) - proto = NULL; - else - proto = (flags & NI_DGRAM) ? "udp" : "tcp"; - r = asr_print_port(sa, proto, serv, servlen); - if (r == 0) - return (EAI_SYSTEM); /* errno set */ - if (r >= servlen) - return (EAI_OVERFLOW); - } - - errno = saved_errno; - return (0); - } - - res_init(); - - as = getnameinfo_async(sa, salen, host, hostlen, serv, servlen, flags, - NULL); - if (as == NULL) { - if (errno == ENOMEM) { - errno = saved_errno; - return (EAI_MEMORY); - } - return (EAI_SYSTEM); - } - - asr_run_sync(as, &ar); - if (ar.ar_gai_errno == EAI_SYSTEM) - errno = ar.ar_errno; - - return (ar.ar_gai_errno); -} -DEF_WEAK(getnameinfo); diff --git a/foobar/portable/openbsd-compat/libasr/getnameinfo_async.c b/foobar/portable/openbsd-compat/libasr/getnameinfo_async.c deleted file mode 100644 index faba8860..00000000 --- a/foobar/portable/openbsd-compat/libasr/getnameinfo_async.c +++ /dev/null @@ -1,300 +0,0 @@ -/* $OpenBSD: getnameinfo_async.c,v 1.14 2019/07/03 03:24:03 deraadt Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "asr_private.h" - -static int getnameinfo_async_run(struct asr_query *, struct asr_result *); -static int _servname(struct asr_query *); -static int _numerichost(struct asr_query *); - -struct asr_query * -getnameinfo_async(const struct sockaddr *sa, socklen_t slen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - ac = _asr_use_resolver(asr); - if ((as = _asr_async_new(ac, ASR_GETNAMEINFO)) == NULL) - goto abort; /* errno set */ - as->as_run = getnameinfo_async_run; - - if (sa->sa_family == AF_INET) - memmove(&as->as.ni.sa.sa, sa, sizeof (as->as.ni.sa.sain)); - else if (sa->sa_family == AF_INET6) - memmove(&as->as.ni.sa.sa, sa, sizeof (as->as.ni.sa.sain6)); - -#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN - as->as.ni.sa.sa.sa_len = slen; -#endif - as->as.ni.hostname = host; - as->as.ni.hostnamelen = hostlen; - as->as.ni.servname = serv; - as->as.ni.servnamelen = servlen; - as->as.ni.flags = flags; - - _asr_ctx_unref(ac); - return (as); - - abort: - if (as) - _asr_async_free(as); - _asr_ctx_unref(ac); - return (NULL); -} -DEF_WEAK(getnameinfo_async); - -static int -getnameinfo_async_run(struct asr_query *as, struct asr_result *ar) -{ - void *addr; - socklen_t addrlen; - int r; - - next: - switch (as->as_state) { - - case ASR_STATE_INIT: - - /* Make sure the parameters are all valid. */ - - if (as->as.ni.sa.sa.sa_family != AF_INET && - as->as.ni.sa.sa.sa_family != AF_INET6) { - ar->ar_gai_errno = EAI_FAMILY; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if ((as->as.ni.sa.sa.sa_family == AF_INET && - (SA_LEN(&as->as.ni.sa.sa) != sizeof (as->as.ni.sa.sain))) || - (as->as.ni.sa.sa.sa_family == AF_INET6 && - (SA_LEN(&as->as.ni.sa.sa) != sizeof (as->as.ni.sa.sain6)))) { - ar->ar_gai_errno = EAI_FAIL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Set the service name first, if needed. */ - if (_servname(as) == -1) { - ar->ar_gai_errno = EAI_OVERFLOW; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as.ni.hostname == NULL || as->as.ni.hostnamelen == 0) { - ar->ar_gai_errno = 0; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as.ni.flags & NI_NUMERICHOST) { - if (_numerichost(as) == -1) { - if (errno == ENOMEM) - ar->ar_gai_errno = EAI_MEMORY; - else if (errno == ENOSPC) - ar->ar_gai_errno = EAI_OVERFLOW; - else { - ar->ar_errno = errno; - ar->ar_gai_errno = EAI_SYSTEM; - } - } else - ar->ar_gai_errno = 0; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as.ni.sa.sa.sa_family == AF_INET) { - addrlen = sizeof(as->as.ni.sa.sain.sin_addr); - addr = &as->as.ni.sa.sain.sin_addr; - } else { - addrlen = sizeof(as->as.ni.sa.sain6.sin6_addr); - addr = &as->as.ni.sa.sain6.sin6_addr; - } - - /* - * Create a subquery to lookup the address. - */ - as->as_subq = _gethostbyaddr_async_ctx(addr, addrlen, - as->as.ni.sa.sa.sa_family, - as->as_ctx); - if (as->as_subq == NULL) { - ar->ar_gai_errno = EAI_MEMORY; - async_set_state(as, ASR_STATE_HALT); - break; - } - - async_set_state(as, ASR_STATE_SUBQUERY); - break; - - case ASR_STATE_SUBQUERY: - - if ((r = asr_run(as->as_subq, ar)) == ASYNC_COND) - return (ASYNC_COND); - - /* - * Request done. - */ - as->as_subq = NULL; - - if (ar->ar_hostent == NULL) { - if (as->as.ni.flags & NI_NAMEREQD) { - ar->ar_gai_errno = EAI_NONAME; - } else if (_numerichost(as) == -1) { - if (errno == ENOMEM) - ar->ar_gai_errno = EAI_MEMORY; - else if (errno == ENOSPC) - ar->ar_gai_errno = EAI_OVERFLOW; - else { - ar->ar_errno = errno; - ar->ar_gai_errno = EAI_SYSTEM; - } - } else - ar->ar_gai_errno = 0; - } else { - if (strlcpy(as->as.ni.hostname, - ar->ar_hostent->h_name, - as->as.ni.hostnamelen) >= as->as.ni.hostnamelen) - ar->ar_gai_errno = EAI_OVERFLOW; - else - ar->ar_gai_errno = 0; - free(ar->ar_hostent); - } - - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_HALT: - return (ASYNC_DONE); - - default: - ar->ar_errno = EOPNOTSUPP; - ar->ar_gai_errno = EAI_SYSTEM; - async_set_state(as, ASR_STATE_HALT); - break; - } - goto next; -} - - -/* - * Set the service name on the result buffer is not NULL. - * return (-1) if the buffer is too small. - */ -static int -_servname(struct asr_query *as) -{ - struct servent s; -#ifdef HAVE_STRUCT_SERVENT_DATA - struct servent_data sd; -#endif - int port, r; - char *buf = as->as.ni.servname; - size_t buflen = as->as.ni.servnamelen; - - if (as->as.ni.servname == NULL || as->as.ni.servnamelen == 0) - return (0); - - if (as->as.ni.sa.sa.sa_family == AF_INET) - port = as->as.ni.sa.sain.sin_port; - else - port = as->as.ni.sa.sain6.sin6_port; - - if (!(as->as.ni.flags & NI_NUMERICSERV)) { -#ifdef HAVE_STRUCT_SERVENT_DATA - memset(&sd, 0, sizeof (sd)); -#endif -#ifdef HAVE_GETSERVBYPORT_R_4_ARGS - r = getservbyport_r(port, - (as->as.ni.flags & NI_DGRAM) ? "udp" : "tcp", - &s, &sd); -#else - r = -1; -#endif - if (r != -1) { - r = strlcpy(buf, s.s_name, buflen) >= buflen; -#ifdef HAVE_ENDSERVENT_R - endservent_r(&sd); -#endif - return (r ? -1 : 0); - } - } - - r = snprintf(buf, buflen, "%u", ntohs(port)); - if (r < 0 || (size_t)r >= buflen) - return (-1); - - return (0); -} - -/* - * Write the numeric address - */ -static int -_numerichost(struct asr_query *as) -{ - unsigned int ifidx; - char scope[IF_NAMESIZE + 1], *ifname; - void *addr; - char *buf = as->as.ni.hostname; - size_t buflen = as->as.ni.hostnamelen; - - if (as->as.ni.sa.sa.sa_family == AF_INET) - addr = &as->as.ni.sa.sain.sin_addr; - else - addr = &as->as.ni.sa.sain6.sin6_addr; - - if (inet_ntop(as->as.ni.sa.sa.sa_family, addr, buf, buflen) == NULL) - return (-1); /* errno set */ - - if (as->as.ni.sa.sa.sa_family == AF_INET6 && - as->as.ni.sa.sain6.sin6_scope_id) { - - scope[0] = SCOPE_DELIMITER; - scope[1] = '\0'; - - ifidx = as->as.ni.sa.sain6.sin6_scope_id; - ifname = NULL; - - if (IN6_IS_ADDR_LINKLOCAL(&as->as.ni.sa.sain6.sin6_addr) || - IN6_IS_ADDR_MC_LINKLOCAL(&as->as.ni.sa.sain6.sin6_addr) || - IN6_IS_ADDR_MC_NODELOCAL(&as->as.ni.sa.sain6.sin6_addr)) - ifname = if_indextoname(ifidx, scope + 1); - - if (ifname == NULL) - snprintf(scope + 1, sizeof(scope) - 1, "%u", ifidx); - - strlcat(buf, scope, buflen); - } - - return (0); -} diff --git a/foobar/portable/openbsd-compat/libasr/getnetnamadr.c b/foobar/portable/openbsd-compat/libasr/getnetnamadr.c deleted file mode 100644 index 141b4a9a..00000000 --- a/foobar/portable/openbsd-compat/libasr/getnetnamadr.c +++ /dev/null @@ -1,134 +0,0 @@ -/* $OpenBSD: getnetnamadr.c,v 1.9 2015/01/16 16:48:51 deraadt Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include /* ALIGN */ -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -static void _fillnetent(const struct netent *, struct netent *, char *buf, - size_t); - -static struct netent _netent; -static char _entbuf[4096]; - -static char *_empty[] = { NULL, }; - -static void -_fillnetent(const struct netent *e, struct netent *r, char *buf, size_t len) -{ - char **ptr, *end, *pos; - size_t n, i; - int naliases; - - bzero(buf, len); - bzero(r, sizeof(*r)); - r->n_aliases = _empty; - - end = buf + len; - ptr = (char **)ALIGN(buf); - - if ((char *)ptr >= end) - return; - - for (naliases = 0; e->n_aliases[naliases]; naliases++) - ; - - r->n_name = NULL; - r->n_addrtype = e->n_addrtype; - r->n_net = e->n_net; - r->n_aliases = ptr; - - pos = (char *)(ptr + (naliases + 1)); - if (pos > end) - r->n_aliases = _empty; - - n = strlcpy(pos, e->n_name, end - pos); - if (n >= end - pos) - return; - r->n_name = pos; - pos += n + 1; - - for (i = 0; i < naliases; i++) { - n = strlcpy(pos, e->n_aliases[i], end - pos); - if (n >= end - pos) - return; - r->n_aliases[i] = pos; - pos += n + 1; - } -} - -struct netent * -getnetbyname(const char *name) -{ - struct asr_query *as; - struct asr_result ar; - - res_init(); - - as = getnetbyname_async(name, NULL); - if (as == NULL) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - - asr_run_sync(as, &ar); - - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; - if (ar.ar_netent == NULL) - return (NULL); - - _fillnetent(ar.ar_netent, &_netent, _entbuf, sizeof(_entbuf)); - free(ar.ar_netent); - - return (&_netent); -} - -struct netent * -getnetbyaddr(in_addr_t net, int type) -{ - struct asr_query *as; - struct asr_result ar; - - res_init(); - - as = getnetbyaddr_async(net, type, NULL); - if (as == NULL) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - - asr_run_sync(as, &ar); - - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; - if (ar.ar_netent == NULL) - return (NULL); - - _fillnetent(ar.ar_netent, &_netent, _entbuf, sizeof(_entbuf)); - free(ar.ar_netent); - - return (&_netent); -} diff --git a/foobar/portable/openbsd-compat/libasr/getnetnamadr_async.c b/foobar/portable/openbsd-compat/libasr/getnetnamadr_async.c deleted file mode 100644 index 1e02d008..00000000 --- a/foobar/portable/openbsd-compat/libasr/getnetnamadr_async.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: getnetnamadr_async.c,v 1.26 2018/04/28 15:16:49 schwarze Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include - -#include "asr_private.h" - -struct asr_query * -getnetbyname_async(const char *name, void *asr) -{ - struct asr_query *as; - - if ((as = gethostbyname_async(name, asr)) != NULL) - as->as_flags |= ASYNC_GETNET; - return (as); -} -DEF_WEAK(getnetbyname_async); - -struct asr_query * -getnetbyaddr_async(in_addr_t net, int family, void *asr) -{ - struct in_addr in; - struct asr_query *as; - - in.s_addr = htonl(net); - as = gethostbyaddr_async(&in, sizeof(in), family, asr); - if (as != NULL) - as->as_flags |= ASYNC_GETNET; - return (as); -} -DEF_WEAK(getnetbyaddr_async); diff --git a/foobar/portable/openbsd-compat/libasr/getrrsetbyname.c b/foobar/portable/openbsd-compat/libasr/getrrsetbyname.c deleted file mode 100644 index 24df2c8b..00000000 --- a/foobar/portable/openbsd-compat/libasr/getrrsetbyname.c +++ /dev/null @@ -1,83 +0,0 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.6 2015/09/14 07:38:37 guenther Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -int -getrrsetbyname(const char *name, unsigned int class, unsigned int type, - unsigned int flags, struct rrsetinfo **res) -{ - struct asr_query *as; - struct asr_result ar; - int r, saved_errno = errno; - - res_init(); - - as = getrrsetbyname_async(name, class, type, flags, NULL); - if (as == NULL) { - r = (errno == ENOMEM) ? ERRSET_NOMEMORY : ERRSET_FAIL; - errno = saved_errno; - return (r); - } - - asr_run_sync(as, &ar); - - *res = ar.ar_rrsetinfo; - - return (ar.ar_rrset_errno); -} - -/* from net/getrrsetbyname.c */ -void -freerrset(struct rrsetinfo *rrset) -{ - u_int16_t i; - - if (rrset == NULL) - return; - - if (rrset->rri_rdatas) { - for (i = 0; i < rrset->rri_nrdatas; i++) { - if (rrset->rri_rdatas[i].rdi_data == NULL) - break; - free(rrset->rri_rdatas[i].rdi_data); - } - free(rrset->rri_rdatas); - } - - if (rrset->rri_sigs) { - for (i = 0; i < rrset->rri_nsigs; i++) { - if (rrset->rri_sigs[i].rdi_data == NULL) - break; - free(rrset->rri_sigs[i].rdi_data); - } - free(rrset->rri_sigs); - } - - if (rrset->rri_name) - free(rrset->rri_name); - free(rrset); -} -DEF_WEAK(freerrset); diff --git a/foobar/portable/openbsd-compat/libasr/getrrsetbyname_async.c b/foobar/portable/openbsd-compat/libasr/getrrsetbyname_async.c deleted file mode 100644 index 9ff7f6c7..00000000 --- a/foobar/portable/openbsd-compat/libasr/getrrsetbyname_async.c +++ /dev/null @@ -1,590 +0,0 @@ -/* $OpenBSD: getrrsetbyname_async.c,v 1.11 2017/02/23 17:04:02 eric Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "asr_private.h" - -static int getrrsetbyname_async_run(struct asr_query *, struct asr_result *); -static void get_response(struct asr_result *, const char *, int); - -struct asr_query * -getrrsetbyname_async(const char *hostname, unsigned int rdclass, - unsigned int rdtype, unsigned int flags, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - ac = _asr_use_resolver(asr); - if ((as = _asr_async_new(ac, ASR_GETRRSETBYNAME)) == NULL) - goto abort; /* errno set */ - as->as_run = getrrsetbyname_async_run; - - as->as.rrset.flags = flags; - as->as.rrset.class = rdclass; - as->as.rrset.type = rdtype; - as->as.rrset.name = strdup(hostname); - if (as->as.rrset.name == NULL) - goto abort; /* errno set */ - - _asr_ctx_unref(ac); - return (as); - abort: - if (as) - _asr_async_free(as); - - _asr_ctx_unref(ac); - return (NULL); -} -DEF_WEAK(getrrsetbyname_async); - -static int -getrrsetbyname_async_run(struct asr_query *as, struct asr_result *ar) -{ - next: - switch (as->as_state) { - - case ASR_STATE_INIT: - - /* Check for invalid class and type. */ - if (as->as.rrset.class > 0xffff || as->as.rrset.type > 0xffff) { - ar->ar_rrset_errno = ERRSET_INVAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Do not allow queries of class or type ANY. */ - if (as->as.rrset.class == 0xff || as->as.rrset.type == 0xff) { - ar->ar_rrset_errno = ERRSET_INVAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Do not allow flags yet, unimplemented. */ - if (as->as.rrset.flags) { - ar->ar_rrset_errno = ERRSET_INVAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Create a delegate the lookup to a subquery. */ - as->as_subq = _res_query_async_ctx( - as->as.rrset.name, - as->as.rrset.class, - as->as.rrset.type, - as->as_ctx); - if (as->as_subq == NULL) { - ar->ar_rrset_errno = ERRSET_FAIL; - async_set_state(as, ASR_STATE_HALT); - break; - } - - async_set_state(as, ASR_STATE_SUBQUERY); - break; - - case ASR_STATE_SUBQUERY: - - if ((asr_run(as->as_subq, ar)) == ASYNC_COND) - return (ASYNC_COND); - - as->as_subq = NULL; - - /* No packet received.*/ - if (ar->ar_datalen == -1) { - switch (ar->ar_h_errno) { - case HOST_NOT_FOUND: - ar->ar_rrset_errno = ERRSET_NONAME; - break; - case NO_DATA: - ar->ar_rrset_errno = ERRSET_NODATA; - break; - default: - ar->ar_rrset_errno = ERRSET_FAIL; - break; - } - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* Got a packet but no answer. */ - if (ar->ar_count == 0) { - free(ar->ar_data); - switch (ar->ar_rcode) { - case NXDOMAIN: - ar->ar_rrset_errno = ERRSET_NONAME; - break; - case NOERROR: - ar->ar_rrset_errno = ERRSET_NODATA; - break; - default: - ar->ar_rrset_errno = ERRSET_FAIL; - break; - } - async_set_state(as, ASR_STATE_HALT); - break; - } - - get_response(ar, ar->ar_data, ar->ar_datalen); - free(ar->ar_data); - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_HALT: - if (ar->ar_rrset_errno) - ar->ar_rrsetinfo = NULL; - return (ASYNC_DONE); - - default: - ar->ar_rrset_errno = ERRSET_FAIL; - async_set_state(as, ASR_STATE_HALT); - break; - } - goto next; -} - -/* The rest of this file is taken from the orignal implementation. */ - -/* $OpenBSD: getrrsetbyname_async.c,v 1.11 2017/02/23 17:04:02 eric Exp $ */ - -/* - * Copyright (c) 2001 Jakob Schlyter. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Portions Copyright (c) 1999-2001 Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define MAXPACKET 1024*64 - -struct dns_query { - char *name; - u_int16_t type; - u_int16_t class; - struct dns_query *next; -}; - -struct dns_rr { - char *name; - u_int16_t type; - u_int16_t class; - u_int16_t ttl; - u_int16_t size; - void *rdata; - struct dns_rr *next; -}; - -struct dns_response { - HEADER header; - struct dns_query *query; - struct dns_rr *answer; - struct dns_rr *authority; - struct dns_rr *additional; -}; - -static struct dns_response *parse_dns_response(const u_char *, int); -static struct dns_query *parse_dns_qsection(const u_char *, int, - const u_char **, int); -static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **, - int); - -static void free_dns_query(struct dns_query *); -static void free_dns_rr(struct dns_rr *); -static void free_dns_response(struct dns_response *); - -static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t); - -static void -get_response(struct asr_result *ar, const char *pkt, int pktlen) -{ - struct rrsetinfo *rrset = NULL; - struct dns_response *response = NULL; - struct dns_rr *rr; - struct rdatainfo *rdata; - unsigned int index_ans, index_sig; - - /* parse result */ - response = parse_dns_response(pkt, pktlen); - if (response == NULL) { - ar->ar_rrset_errno = ERRSET_FAIL; - goto fail; - } - - if (response->header.qdcount != 1) { - ar->ar_rrset_errno = ERRSET_FAIL; - goto fail; - } - - /* initialize rrset */ - rrset = calloc(1, sizeof(struct rrsetinfo)); - if (rrset == NULL) { - ar->ar_rrset_errno = ERRSET_NOMEMORY; - goto fail; - } - rrset->rri_rdclass = response->query->class; - rrset->rri_rdtype = response->query->type; - rrset->rri_ttl = response->answer->ttl; - rrset->rri_nrdatas = response->header.ancount; - - /* check for authenticated data */ - if (response->header.ad == 1) - rrset->rri_flags |= RRSET_VALIDATED; - - /* copy name from answer section */ - rrset->rri_name = strdup(response->answer->name); - if (rrset->rri_name == NULL) { - ar->ar_rrset_errno = ERRSET_NOMEMORY; - goto fail; - } - - /* count answers */ - rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass, - rrset->rri_rdtype); - rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass, - T_RRSIG); - - /* allocate memory for answers */ - rrset->rri_rdatas = calloc(rrset->rri_nrdatas, - sizeof(struct rdatainfo)); - if (rrset->rri_rdatas == NULL) { - ar->ar_rrset_errno = ERRSET_NOMEMORY; - goto fail; - } - - /* allocate memory for signatures */ - rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); - if (rrset->rri_sigs == NULL) { - ar->ar_rrset_errno = ERRSET_NOMEMORY; - goto fail; - } - - /* copy answers & signatures */ - for (rr = response->answer, index_ans = 0, index_sig = 0; - rr; rr = rr->next) { - - rdata = NULL; - - if (rr->class == rrset->rri_rdclass && - rr->type == rrset->rri_rdtype) - rdata = &rrset->rri_rdatas[index_ans++]; - - if (rr->class == rrset->rri_rdclass && - rr->type == T_RRSIG) - rdata = &rrset->rri_sigs[index_sig++]; - - if (rdata) { - rdata->rdi_length = rr->size; - rdata->rdi_data = malloc(rr->size); - - if (rdata->rdi_data == NULL) { - ar->ar_rrset_errno = ERRSET_NOMEMORY; - goto fail; - } - memcpy(rdata->rdi_data, rr->rdata, rr->size); - } - } - free_dns_response(response); - - ar->ar_rrsetinfo = rrset; - ar->ar_rrset_errno = ERRSET_SUCCESS; - return; - -fail: - if (rrset != NULL) - freerrset(rrset); - if (response != NULL) - free_dns_response(response); -} - -/* - * DNS response parsing routines - */ -static struct dns_response * -parse_dns_response(const u_char *answer, int size) -{ - struct dns_response *resp; - const u_char *cp; - - /* allocate memory for the response */ - resp = calloc(1, sizeof(*resp)); - if (resp == NULL) - return (NULL); - - /* initialize current pointer */ - cp = answer; - - /* copy header */ - memcpy(&resp->header, cp, HFIXEDSZ); - cp += HFIXEDSZ; - - /* fix header byte order */ - resp->header.qdcount = ntohs(resp->header.qdcount); - resp->header.ancount = ntohs(resp->header.ancount); - resp->header.nscount = ntohs(resp->header.nscount); - resp->header.arcount = ntohs(resp->header.arcount); - - /* there must be at least one query */ - if (resp->header.qdcount < 1) { - free_dns_response(resp); - return (NULL); - } - - /* parse query section */ - resp->query = parse_dns_qsection(answer, size, &cp, - resp->header.qdcount); - if (resp->header.qdcount && resp->query == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse answer section */ - resp->answer = parse_dns_rrsection(answer, size, &cp, - resp->header.ancount); - if (resp->header.ancount && resp->answer == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse authority section */ - resp->authority = parse_dns_rrsection(answer, size, &cp, - resp->header.nscount); - if (resp->header.nscount && resp->authority == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse additional section */ - resp->additional = parse_dns_rrsection(answer, size, &cp, - resp->header.arcount); - if (resp->header.arcount && resp->additional == NULL) { - free_dns_response(resp); - return (NULL); - } - - return (resp); -} - -static struct dns_query * -parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count) -{ - struct dns_query *head, *curr, *prev; - int i, length; - char name[MAXDNAME]; - - for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) { - - /* allocate and initialize struct */ - curr = calloc(1, sizeof(struct dns_query)); - if (curr == NULL) { - free_dns_query(head); - return (NULL); - } - if (head == NULL) - head = curr; - if (prev != NULL) - prev->next = curr; - - /* name */ - length = dn_expand(answer, answer + size, *cp, name, - sizeof(name)); - if (length < 0) { - free_dns_query(head); - return (NULL); - } - curr->name = strdup(name); - if (curr->name == NULL) { - free_dns_query(head); - return (NULL); - } - *cp += length; - - /* type */ - curr->type = _getshort(*cp); - *cp += INT16SZ; - - /* class */ - curr->class = _getshort(*cp); - *cp += INT16SZ; - } - - return (head); -} - -static struct dns_rr * -parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, - int count) -{ - struct dns_rr *head, *curr, *prev; - int i, length; - char name[MAXDNAME]; - - for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) { - - /* allocate and initialize struct */ - curr = calloc(1, sizeof(struct dns_rr)); - if (curr == NULL) { - free_dns_rr(head); - return (NULL); - } - if (head == NULL) - head = curr; - if (prev != NULL) - prev->next = curr; - - /* name */ - length = dn_expand(answer, answer + size, *cp, name, - sizeof(name)); - if (length < 0) { - free_dns_rr(head); - return (NULL); - } - curr->name = strdup(name); - if (curr->name == NULL) { - free_dns_rr(head); - return (NULL); - } - *cp += length; - - /* type */ - curr->type = _getshort(*cp); - *cp += INT16SZ; - - /* class */ - curr->class = _getshort(*cp); - *cp += INT16SZ; - - /* ttl */ - curr->ttl = _getlong(*cp); - *cp += INT32SZ; - - /* rdata size */ - curr->size = _getshort(*cp); - *cp += INT16SZ; - - /* rdata itself */ - curr->rdata = malloc(curr->size); - if (curr->rdata == NULL) { - free_dns_rr(head); - return (NULL); - } - memcpy(curr->rdata, *cp, curr->size); - *cp += curr->size; - } - - return (head); -} - -static void -free_dns_query(struct dns_query *p) -{ - if (p == NULL) - return; - - if (p->name) - free(p->name); - free_dns_query(p->next); - free(p); -} - -static void -free_dns_rr(struct dns_rr *p) -{ - if (p == NULL) - return; - - if (p->name) - free(p->name); - if (p->rdata) - free(p->rdata); - free_dns_rr(p->next); - free(p); -} - -static void -free_dns_response(struct dns_response *p) -{ - if (p == NULL) - return; - - free_dns_query(p->query); - free_dns_rr(p->answer); - free_dns_rr(p->authority); - free_dns_rr(p->additional); - free(p); -} - -static int -count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type) -{ - int n = 0; - - while (p) { - if (p->class == class && p->type == type) - n++; - p = p->next; - } - - return (n); -} diff --git a/foobar/portable/openbsd-compat/libasr/libasr.la b/foobar/portable/openbsd-compat/libasr/libasr.la deleted file mode 100644 index 71346e8a..00000000 --- a/foobar/portable/openbsd-compat/libasr/libasr.la +++ /dev/null @@ -1,41 +0,0 @@ -# libasr.la - a libtool library file -# Generated by libtool (GNU libtool) 2.4.6 -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='libasr.0.dylib' - -# Names of this library. -library_names='libasr.0.dylib libasr.dylib' - -# The name of the static archive. -old_library='libasr.a' - -# Linker flags that cannot go in dependency_libs. -inherited_linker_flags=' ' - -# Libraries that this one depends upon. -dependency_libs=' -L/usr/local/Cellar/openssl@1.1/1.1.1d//lib -L/usr/local/lib -lz -lcrypto -lssl -levent -lresolv' - -# Names of additional weak libraries provided by this library -weak_library_names='' - -# Version information for libasr. -current=0 -age=0 -revision=3 - -# Is this an already installed library? -installed=no - -# Should we warn about portability when linking against -modules? -shouldnotlink=no - -# Files to dlopen/dlpreopen -dlopen='' -dlpreopen='' - -# Directory that this library needs to be installed in: -libdir='/tmp/lib' diff --git a/foobar/portable/openbsd-compat/libasr/res_debug.c b/foobar/portable/openbsd-compat/libasr/res_debug.c deleted file mode 100644 index ca9c5ee0..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_debug.c +++ /dev/null @@ -1,2 +0,0 @@ -/* $OpenBSD: res_debug.c,v 1.1 2012/09/08 11:08:21 eric Exp $ */ -/* NOTHING */ diff --git a/foobar/portable/openbsd-compat/libasr/res_init.c b/foobar/portable/openbsd-compat/libasr/res_init.c deleted file mode 100644 index 04243c47..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_init.c +++ /dev/null @@ -1,103 +0,0 @@ -/* $OpenBSD: res_init.c,v 1.11 2019/06/17 05:54:45 otto Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "asr_private.h" -#include "thread_private.h" - - -struct __res_state _res; -struct __res_state_ext _res_ext; - -int h_errno; - -int -res_init(void) -{ - static void *resinit_mutex; - struct asr_ctx *ac; - int i; - - ac = _asr_use_resolver(NULL); - - /* - * The first thread to call res_init() will setup the global _res - * structure from the async context, not overriding fields set early - * by the user. - */ - _MUTEX_LOCK(&resinit_mutex); - if (!(_res.options & RES_INIT)) { - if (_res.retry == 0) - _res.retry = ac->ac_nsretries; - if (_res.retrans == 0) - _res.retrans = ac->ac_nstimeout; - if (_res.options == 0) - _res.options = ac->ac_options; - if (_res.lookups[0] == '\0') - strlcpy(_res.lookups, ac->ac_db, sizeof(_res.lookups)); - - for (i = 0; i < ac->ac_nscount && i < MAXNS; i++) { - /* - * No need to check for length since we copy to a - * struct sockaddr_storage with a size of 256 bytes - * and sa_len has only 8 bits. - */ - memcpy(&_res_ext.nsaddr_list[i], ac->ac_ns[i], - ac->ac_ns[i]->sa_len); - if (ac->ac_ns[i]->sa_len <= sizeof(_res.nsaddr_list[i])) - memcpy(&_res.nsaddr_list[i], ac->ac_ns[i], - ac->ac_ns[i]->sa_len); - else - memset(&_res.nsaddr_list[i], 0, - sizeof(_res.nsaddr_list[i])); - } - _res.nscount = i; - _res.options |= RES_INIT; - } - _MUTEX_UNLOCK(&resinit_mutex); - - /* - * If the program is not threaded, we want to reflect (some) changes - * made by the user to the global _res structure. - * This is a bit of a hack: if there is already an async query on - * this context, it might change things in its back. It is ok - * as long as the user only uses the blocking resolver API. - * If needed we could consider cloning the context if there is - * a running query. - */ - if (!__isthreaded) { - ac->ac_nsretries = _res.retry; - ac->ac_nstimeout = _res.retrans; - ac->ac_options = _res.options; - strlcpy(ac->ac_db, _res.lookups, sizeof(ac->ac_db)); - ac->ac_dbcount = strlen(ac->ac_db); - } - - _asr_ctx_unref(ac); - - return (0); -} -DEF_WEAK(res_init); diff --git a/foobar/portable/openbsd-compat/libasr/res_mkquery.c b/foobar/portable/openbsd-compat/libasr/res_mkquery.c deleted file mode 100644 index 959ecc47..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_mkquery.c +++ /dev/null @@ -1,119 +0,0 @@ -/* $OpenBSD: res_mkquery.c,v 1.13 2019/01/14 06:49:42 otto Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include /* for MAXDNAME */ -#include - -#include -#include -#include -#include - -#include "asr_private.h" - -/* This function is apparently needed by some ports. */ -int -res_mkquery(int op, const char *dname, int class, int type, - const unsigned char *data, int datalen, const unsigned char *newrr, - unsigned char *buf, int buflen) -{ - struct asr_ctx *ac; - struct asr_pack p; - struct asr_dns_header h; - char fqdn[MAXDNAME]; - char dn[MAXDNAME]; - - /* we currently only support QUERY */ - if (op != QUERY || data) - return (-1); - - if (dname[0] == '\0' || dname[strlen(dname) - 1] != '.') { - if (strlcpy(fqdn, dname, sizeof(fqdn)) >= sizeof(fqdn) || - strlcat(fqdn, ".", sizeof(fqdn)) >= sizeof(fqdn)) - return (-1); - dname = fqdn; - } - - if (_asr_dname_from_fqdn(dname, dn, sizeof(dn)) == -1) - return (-1); - - ac = _asr_use_resolver(NULL); - - memset(&h, 0, sizeof h); - h.id = res_randomid(); - if (ac->ac_options & RES_RECURSE) - h.flags |= RD_MASK; -#ifdef RES_USE_CD - if (ac->ac_options & RES_USE_CD) - h.flags |= CD_MASK; -#endif - h.qdcount = 1; - if (ac->ac_options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) - h.arcount = 1; - - _asr_pack_init(&p, buf, buflen); - _asr_pack_header(&p, &h); - _asr_pack_query(&p, type, class, dn); - if (ac->ac_options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) - _asr_pack_edns0(&p, MAXPACKETSZ, - ac->ac_options & RES_USE_DNSSEC); - - _asr_ctx_unref(ac); - - if (p.err) - return (-1); - - return (p.offset); -} - -/* - * This function is not documented, but used by sendmail. - * Put here because it uses asr_private.h too. - */ -int -res_querydomain(const char *name, - const char *domain, - int class, - int type, - u_char *answer, - int anslen) -{ - char fqdn[MAXDNAME], ndom[MAXDNAME]; - size_t n; - - /* we really want domain to end with a dot for now */ - if (domain && ((n = strlen(domain)) == 0 || domain[n - 1 ] != '.')) { - if (strlcpy(ndom, domain, sizeof(ndom)) >= sizeof(ndom) || - strlcat(ndom, ".", sizeof(ndom)) >= sizeof(ndom)) { - h_errno = NETDB_INTERNAL; - errno = EINVAL; - return (-1); - } - domain = ndom; - } - - if (_asr_make_fqdn(name, domain, fqdn, sizeof fqdn) == 0) { - h_errno = NETDB_INTERNAL; - errno = EINVAL; - return (-1); - } - - return (res_query(fqdn, class, type, answer, anslen)); -} diff --git a/foobar/portable/openbsd-compat/libasr/res_query.c b/foobar/portable/openbsd-compat/libasr/res_query.c deleted file mode 100644 index 3f891416..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_query.c +++ /dev/null @@ -1,112 +0,0 @@ -/* $OpenBSD: res_query.c,v 1.9 2015/10/05 02:57:16 guenther Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -int -res_query(const char *name, int class, int type, u_char *ans, int anslen) -{ - struct asr_query *as; - struct asr_result ar; - size_t len; - - res_init(); - - if (ans == NULL || anslen <= 0) { - h_errno = NO_RECOVERY; - errno = EINVAL; - return (-1); - } - - as = res_query_async(name, class, type, NULL); - if (as == NULL) { - if (errno == EINVAL) - h_errno = NO_RECOVERY; - else - h_errno = NETDB_INTERNAL; - return (-1); /* errno set */ - } - - asr_run_sync(as, &ar); - - if (ar.ar_errno) - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; - - if (ar.ar_h_errno != NETDB_SUCCESS) - return (-1); - - len = anslen; - if (ar.ar_datalen < len) - len = ar.ar_datalen; - memmove(ans, ar.ar_data, len); - free(ar.ar_data); - - return (ar.ar_datalen); -} -DEF_WEAK(res_query); - -int -res_search(const char *name, int class, int type, u_char *ans, int anslen) -{ - struct asr_query *as; - struct asr_result ar; - size_t len; - - res_init(); - - if (ans == NULL || anslen <= 0) { - h_errno = NO_RECOVERY; - errno = EINVAL; - return (-1); - } - - as = res_search_async(name, class, type, NULL); - if (as == NULL) { - if (errno == EINVAL) - h_errno = NO_RECOVERY; - else - h_errno = NETDB_INTERNAL; - return (-1); /* errno set */ - } - - asr_run_sync(as, &ar); - - if (ar.ar_errno) - errno = ar.ar_errno; - h_errno = ar.ar_h_errno; - - if (ar.ar_h_errno != NETDB_SUCCESS) - return (-1); - - len = anslen; - if (ar.ar_datalen < len) - len = ar.ar_datalen; - memmove(ans, ar.ar_data, len); - free(ar.ar_data); - - return (ar.ar_datalen); -} diff --git a/foobar/portable/openbsd-compat/libasr/res_search_async.c b/foobar/portable/openbsd-compat/libasr/res_search_async.c deleted file mode 100644 index 6436ab85..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_search_async.c +++ /dev/null @@ -1,327 +0,0 @@ -/* $OpenBSD: res_search_async.c,v 1.21 2017/02/27 10:44:46 jca Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "asr_private.h" - -static int res_search_async_run(struct asr_query *, struct asr_result *); -static size_t domcat(const char *, const char *, char *, size_t); - -/* - * Unlike res_query_async(), this function returns a valid packet only if - * h_errno is NETDB_SUCCESS. - */ -struct asr_query * -res_search_async(const char *name, int class, int type, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - DPRINT("asr: res_search_async(\"%s\", %i, %i)\n", name, class, type); - - ac = _asr_use_resolver(asr); - as = _res_search_async_ctx(name, class, type, ac); - _asr_ctx_unref(ac); - - return (as); -} -DEF_WEAK(res_search_async); - -struct asr_query * -_res_search_async_ctx(const char *name, int class, int type, struct asr_ctx *ac) -{ - struct asr_query *as; - - DPRINT("asr: res_search_async_ctx(\"%s\", %i, %i)\n", name, class, - type); - - if ((as = _asr_async_new(ac, ASR_SEARCH)) == NULL) - goto err; /* errno set */ - as->as_run = res_search_async_run; - if ((as->as.search.name = strdup(name)) == NULL) - goto err; /* errno set */ - - as->as.search.class = class; - as->as.search.type = type; - - return (as); - err: - if (as) - _asr_async_free(as); - return (NULL); -} - -#define HERRNO_UNSET -2 - -static int -res_search_async_run(struct asr_query *as, struct asr_result *ar) -{ - int r; - char fqdn[MAXDNAME]; - - next: - switch (as->as_state) { - - case ASR_STATE_INIT: - - if (as->as.search.name[0] == '\0') { - ar->ar_h_errno = NO_DATA; - async_set_state(as, ASR_STATE_HALT); - break; - } - - as->as.search.saved_h_errno = HERRNO_UNSET; - async_set_state(as, ASR_STATE_NEXT_DOMAIN); - break; - - case ASR_STATE_NEXT_DOMAIN: - /* - * Reset flags to be able to identify the case in - * STATE_SUBQUERY. - */ - as->as_dom_flags = 0; - - r = _asr_iter_domain(as, as->as.search.name, fqdn, sizeof(fqdn)); - if (r == -1) { - async_set_state(as, ASR_STATE_NOT_FOUND); - break; - } - if (r == 0) { - ar->ar_errno = EINVAL; - ar->ar_h_errno = NO_RECOVERY; - ar->ar_datalen = -1; - ar->ar_data = NULL; - async_set_state(as, ASR_STATE_HALT); - break; - } - as->as_subq = _res_query_async_ctx(fqdn, - as->as.search.class, as->as.search.type, as->as_ctx); - if (as->as_subq == NULL) { - ar->ar_errno = errno; - if (errno == EINVAL) - ar->ar_h_errno = NO_RECOVERY; - else - ar->ar_h_errno = NETDB_INTERNAL; - ar->ar_datalen = -1; - ar->ar_data = NULL; - async_set_state(as, ASR_STATE_HALT); - break; - } - async_set_state(as, ASR_STATE_SUBQUERY); - break; - - case ASR_STATE_SUBQUERY: - - if ((r = asr_run(as->as_subq, ar)) == ASYNC_COND) - return (ASYNC_COND); - as->as_subq = NULL; - - if (ar->ar_h_errno == NETDB_SUCCESS) { - async_set_state(as, ASR_STATE_HALT); - break; - } - - /* - * The original res_search() does this in the domain search - * loop, but only for ECONNREFUSED. I think we can do better - * because technically if we get an errno, it means - * we couldn't reach any nameserver, so there is no point - * in trying further. - */ - if (ar->ar_errno) { - async_set_state(as, ASR_STATE_HALT); - break; - } - - free(ar->ar_data); - - /* - * The original resolver does something like this. - */ - if (as->as_dom_flags & ASYNC_DOM_NDOTS) - as->as.search.saved_h_errno = ar->ar_h_errno; - - if (as->as_dom_flags & ASYNC_DOM_DOMAIN) { - if (ar->ar_h_errno == NO_DATA) - as->as_flags |= ASYNC_NODATA; - else if (ar->ar_h_errno == TRY_AGAIN) - as->as_flags |= ASYNC_AGAIN; - } - - async_set_state(as, ASR_STATE_NEXT_DOMAIN); - break; - - case ASR_STATE_NOT_FOUND: - - if (as->as.search.saved_h_errno != HERRNO_UNSET) - ar->ar_h_errno = as->as.search.saved_h_errno; - else if (as->as_flags & ASYNC_NODATA) - ar->ar_h_errno = NO_DATA; - else if (as->as_flags & ASYNC_AGAIN) - ar->ar_h_errno = TRY_AGAIN; - /* - * Else, we got the ar_h_errno value set by res_query_async() - * for the last domain. - */ - ar->ar_datalen = -1; - ar->ar_data = NULL; - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_HALT: - - return (ASYNC_DONE); - - default: - ar->ar_errno = EOPNOTSUPP; - ar->ar_h_errno = NETDB_INTERNAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - goto next; -} - -/* - * Concatenate a name and a domain name. The result has no trailing dot. - * Return the resulting string length, or 0 in case of error. - */ -static size_t -domcat(const char *name, const char *domain, char *buf, size_t buflen) -{ - size_t r; - - r = _asr_make_fqdn(name, domain, buf, buflen); - if (r == 0) - return (0); - buf[r - 1] = '\0'; - - return (r - 1); -} - -enum { - DOM_INIT, - DOM_DOMAIN, - DOM_DONE -}; - -/* - * Implement the search domain strategy. - * - * This function works as a generator that constructs complete domains in - * buffer "buf" of size "len" for the given host name "name", according to the - * search rules defined by the resolving context. It is supposed to be called - * multiple times (with the same name) to generate the next possible domain - * name, if any. - * - * It returns -1 if all possibilities have been exhausted, 0 if there was an - * error generating the next name, or the resulting name length. - */ -int -_asr_iter_domain(struct asr_query *as, const char *name, char * buf, size_t len) -{ - const char *c; - int dots; - - switch (as->as_dom_step) { - - case DOM_INIT: - /* First call */ - - /* - * If "name" is an FQDN, that's the only result and we - * don't try anything else. - */ - if (strlen(name) && name[strlen(name) - 1] == '.') { - DPRINT("asr: iter_domain(\"%s\") fqdn\n", name); - as->as_dom_flags |= ASYNC_DOM_FQDN; - as->as_dom_step = DOM_DONE; - return (domcat(name, NULL, buf, len)); - } - - /* - * Otherwise, we iterate through the specified search domains. - */ - as->as_dom_step = DOM_DOMAIN; - as->as_dom_idx = 0; - - /* - * If "name" as enough dots, use it as-is first, as indicated - * in resolv.conf(5). - */ - dots = 0; - for (c = name; *c; c++) - dots += (*c == '.'); - if (dots >= as->as_ctx->ac_ndots) { - DPRINT("asr: iter_domain(\"%s\") ndots\n", name); - as->as_dom_flags |= ASYNC_DOM_NDOTS; - if (strlcpy(buf, name, len) >= len) - return (0); - return (strlen(buf)); - } - /* Otherwise, starts using the search domains */ - /* FALLTHROUGH */ - - case DOM_DOMAIN: - if (as->as_dom_idx < as->as_ctx->ac_domcount && - (as->as_ctx->ac_options & RES_DNSRCH || ( - as->as_ctx->ac_options & RES_DEFNAMES && - as->as_dom_idx == 0 && - strchr(name, '.') == NULL))) { - DPRINT("asr: iter_domain(\"%s\") domain \"%s\"\n", - name, as->as_ctx->ac_dom[as->as_dom_idx]); - as->as_dom_flags |= ASYNC_DOM_DOMAIN; - return (domcat(name, - as->as_ctx->ac_dom[as->as_dom_idx++], buf, len)); - } - - /* No more domain to try. */ - - as->as_dom_step = DOM_DONE; - - /* - * If the name was not tried as an absolute name before, - * do it now. - */ - if (!(as->as_dom_flags & ASYNC_DOM_NDOTS)) { - DPRINT("asr: iter_domain(\"%s\") as is\n", name); - as->as_dom_flags |= ASYNC_DOM_ASIS; - if (strlcpy(buf, name, len) >= len) - return (0); - return (strlen(buf)); - } - /* Otherwise, we are done. */ - - case DOM_DONE: - default: - DPRINT("asr: iter_domain(\"%s\") done\n", name); - return (-1); - } -} diff --git a/foobar/portable/openbsd-compat/libasr/res_send.c b/foobar/portable/openbsd-compat/libasr/res_send.c deleted file mode 100644 index 32c94081..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_send.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $OpenBSD: res_send.c,v 1.8 2014/03/26 18:13:15 eric Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -int -res_send(const u_char *buf, int buflen, u_char *ans, int anslen) -{ - struct asr_query *as; - struct asr_result ar; - size_t len; - - res_init(); - - if (ans == NULL || anslen <= 0) { - errno = EINVAL; - return (-1); - } - - as = res_send_async(buf, buflen, NULL); - if (as == NULL) - return (-1); /* errno set */ - - asr_run_sync(as, &ar); - - if (ar.ar_errno) { - errno = ar.ar_errno; - return (-1); - } - - len = anslen; - if (ar.ar_datalen < len) - len = ar.ar_datalen; - memmove(ans, ar.ar_data, len); - free(ar.ar_data); - - return (ar.ar_datalen); -} diff --git a/foobar/portable/openbsd-compat/libasr/res_send_async.c b/foobar/portable/openbsd-compat/libasr/res_send_async.c deleted file mode 100644 index 7eeeef48..00000000 --- a/foobar/portable/openbsd-compat/libasr/res_send_async.c +++ /dev/null @@ -1,806 +0,0 @@ -/* $OpenBSD: res_send_async.c,v 1.39 2019/09/28 11:21:07 eric Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#include -#include -#include -#include -#ifdef HAVE_ARPA_NAMESER_COMPAT_H -#include -#endif -#include - -#include -#include -#include -#include -#include /* for res_random */ -#include -#include -#include - -#include "asr_private.h" - -#define OP_QUERY (0) - -static int res_send_async_run(struct asr_query *, struct asr_result *); -static int sockaddr_connect(const struct sockaddr *, int); -static int udp_send(struct asr_query *); -static int udp_recv(struct asr_query *); -static int tcp_write(struct asr_query *); -static int tcp_read(struct asr_query *); -static int validate_packet(struct asr_query *); -static int setup_query(struct asr_query *, const char *, const char *, int, int); -static int ensure_ibuf(struct asr_query *, size_t); -static int iter_ns(struct asr_query *); - -#define AS_NS_SA(p) ((p)->as_ctx->ac_ns[(p)->as.dns.nsidx - 1]) - - -struct asr_query * -res_send_async(const unsigned char *buf, int buflen, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - struct asr_unpack p; - struct asr_dns_header h; - struct asr_dns_query q; - - DPRINT_PACKET("asr: res_send_async()", buf, buflen); - - ac = _asr_use_resolver(asr); - if ((as = _asr_async_new(ac, ASR_SEND)) == NULL) { - _asr_ctx_unref(ac); - return (NULL); /* errno set */ - } - as->as_run = res_send_async_run; - - as->as_flags |= ASYNC_EXTOBUF; - as->as.dns.obuf = (unsigned char *)buf; - as->as.dns.obuflen = buflen; - as->as.dns.obufsize = buflen; - - _asr_unpack_init(&p, buf, buflen); - _asr_unpack_header(&p, &h); - _asr_unpack_query(&p, &q); - if (p.err) { - errno = EINVAL; - goto err; - } - as->as.dns.reqid = h.id; - as->as.dns.type = q.q_type; - as->as.dns.class = q.q_class; - as->as.dns.dname = strdup(q.q_dname); - if (as->as.dns.dname == NULL) - goto err; /* errno set */ - - _asr_ctx_unref(ac); - return (as); - err: - if (as) - _asr_async_free(as); - _asr_ctx_unref(ac); - return (NULL); -} -DEF_WEAK(res_send_async); - -/* - * Unlike res_query(), this version will actually return the packet - * if it has received a valid one (errno == 0) even if h_errno is - * not NETDB_SUCCESS. So the packet *must* be freed if necessary. - */ -struct asr_query * -res_query_async(const char *name, int class, int type, void *asr) -{ - struct asr_ctx *ac; - struct asr_query *as; - - DPRINT("asr: res_query_async(\"%s\", %i, %i)\n", name, class, type); - - ac = _asr_use_resolver(asr); - as = _res_query_async_ctx(name, class, type, ac); - _asr_ctx_unref(ac); - - return (as); -} -DEF_WEAK(res_query_async); - -struct asr_query * -_res_query_async_ctx(const char *name, int class, int type, struct asr_ctx *a_ctx) -{ - struct asr_query *as; - - DPRINT("asr: res_query_async_ctx(\"%s\", %i, %i)\n", name, class, type); - - if ((as = _asr_async_new(a_ctx, ASR_SEND)) == NULL) - return (NULL); /* errno set */ - as->as_run = res_send_async_run; - - /* This adds a "." to name if it doesn't already has one. - * That's how res_query() behaves (through res_mkquery"). - */ - if (setup_query(as, name, NULL, class, type) == -1) - goto err; /* errno set */ - - return (as); - - err: - if (as) - _asr_async_free(as); - - return (NULL); -} - -static int -res_send_async_run(struct asr_query *as, struct asr_result *ar) -{ - next: - switch (as->as_state) { - - case ASR_STATE_INIT: - - if (as->as_ctx->ac_nscount == 0) { - ar->ar_errno = ECONNREFUSED; - async_set_state(as, ASR_STATE_HALT); - break; - } - - async_set_state(as, ASR_STATE_NEXT_NS); - break; - - case ASR_STATE_NEXT_NS: - - if (iter_ns(as) == -1) { - ar->ar_errno = ETIMEDOUT; - async_set_state(as, ASR_STATE_HALT); - break; - } - - if (as->as_ctx->ac_options & RES_USEVC || - as->as.dns.obuflen > PACKETSZ) - async_set_state(as, ASR_STATE_TCP_WRITE); - else - async_set_state(as, ASR_STATE_UDP_SEND); - break; - - case ASR_STATE_UDP_SEND: - - if (udp_send(as) == -1) { - async_set_state(as, ASR_STATE_NEXT_NS); - break; - } - async_set_state(as, ASR_STATE_UDP_RECV); - ar->ar_cond = ASR_WANT_READ; - ar->ar_fd = as->as_fd; - ar->ar_timeout = as->as_timeout; - return (ASYNC_COND); - break; - - case ASR_STATE_UDP_RECV: - - if (udp_recv(as) == -1) { - if (errno == ENOMEM) { - ar->ar_errno = errno; - async_set_state(as, ASR_STATE_HALT); - break; - } - if (errno != EOVERFLOW) { - /* Fail or timeout */ - async_set_state(as, ASR_STATE_NEXT_NS); - break; - } - if (as->as_ctx->ac_options & RES_IGNTC) - async_set_state(as, ASR_STATE_PACKET); - else - async_set_state(as, ASR_STATE_TCP_WRITE); - } else - async_set_state(as, ASR_STATE_PACKET); - break; - - case ASR_STATE_TCP_WRITE: - - switch (tcp_write(as)) { - case -1: /* fail or timeout */ - async_set_state(as, ASR_STATE_NEXT_NS); - break; - case 0: - async_set_state(as, ASR_STATE_TCP_READ); - ar->ar_cond = ASR_WANT_READ; - ar->ar_fd = as->as_fd; - ar->ar_timeout = as->as_timeout; - return (ASYNC_COND); - case 1: - ar->ar_cond = ASR_WANT_WRITE; - ar->ar_fd = as->as_fd; - ar->ar_timeout = as->as_timeout; - return (ASYNC_COND); - } - break; - - case ASR_STATE_TCP_READ: - - switch (tcp_read(as)) { - case -1: /* Fail or timeout */ - if (errno == ENOMEM) { - ar->ar_errno = errno; - async_set_state(as, ASR_STATE_HALT); - } else - async_set_state(as, ASR_STATE_NEXT_NS); - break; - case 0: - async_set_state(as, ASR_STATE_PACKET); - break; - case 1: - ar->ar_cond = ASR_WANT_READ; - ar->ar_fd = as->as_fd; - ar->ar_timeout = as->as_timeout; - return (ASYNC_COND); - } - break; - - case ASR_STATE_PACKET: - - memmove(&ar->ar_ns, AS_NS_SA(as), SA_LEN(AS_NS_SA(as))); - ar->ar_datalen = as->as.dns.ibuflen; - ar->ar_data = as->as.dns.ibuf; - as->as.dns.ibuf = NULL; - ar->ar_errno = 0; - ar->ar_rcode = as->as.dns.rcode; - async_set_state(as, ASR_STATE_HALT); - break; - - case ASR_STATE_HALT: - - if (ar->ar_errno) { - ar->ar_h_errno = TRY_AGAIN; - ar->ar_count = 0; - ar->ar_datalen = -1; - ar->ar_data = NULL; - } else if (as->as.dns.ancount) { - ar->ar_h_errno = NETDB_SUCCESS; - ar->ar_count = as->as.dns.ancount; - } else { - ar->ar_count = 0; - switch (as->as.dns.rcode) { - case NXDOMAIN: - ar->ar_h_errno = HOST_NOT_FOUND; - break; - case SERVFAIL: - ar->ar_h_errno = TRY_AGAIN; - break; - case NOERROR: - ar->ar_h_errno = NO_DATA; - break; - default: - ar->ar_h_errno = NO_RECOVERY; - } - } - return (ASYNC_DONE); - - default: - - ar->ar_errno = EOPNOTSUPP; - ar->ar_h_errno = NETDB_INTERNAL; - async_set_state(as, ASR_STATE_HALT); - break; - } - goto next; -} - -static int -sockaddr_connect(const struct sockaddr *sa, int socktype) -{ - int errno_save, sock, flags; - - if ((sock = socket(sa->sa_family, socktype, 0)) == -1) - goto fail; - - if ((flags = fcntl(sock, F_GETFL, 0)) == -1) - goto fail; - - flags |= O_NONBLOCK; - - if ((flags = fcntl(sock, F_SETFL, flags)) == -1) - goto fail; - - if (connect(sock, sa, SA_LEN(sa)) == -1) { - /* - * In the TCP case, the caller will be asked to poll for - * POLLOUT so that we start writing the packet in tcp_write() - * when the connection is established, or fail there on error. - */ - if (errno == EINPROGRESS) - return (sock); - goto fail; - } - - return (sock); - - fail: - - if (sock != -1) { - errno_save = errno; - close(sock); - errno = errno_save; - } - - return (-1); -} - -/* - * Prepare the DNS packet for the query type "type", class "class" and domain - * name created by the concatenation on "name" and "dom". - * Return 0 on success, set errno and return -1 on error. - */ -static int -setup_query(struct asr_query *as, const char *name, const char *dom, - int class, int type) -{ - struct asr_pack p; - struct asr_dns_header h; - char fqdn[MAXDNAME]; - char dname[MAXDNAME]; - - if (as->as_flags & ASYNC_EXTOBUF) { - errno = EINVAL; - DPRINT("attempting to write in user packet"); - return (-1); - } - - if (_asr_make_fqdn(name, dom, fqdn, sizeof(fqdn)) > sizeof(fqdn)) { - errno = EINVAL; - DPRINT("asr_make_fqdn: name too long\n"); - return (-1); - } - - if (_asr_dname_from_fqdn(fqdn, dname, sizeof(dname)) == -1) { - errno = EINVAL; - DPRINT("asr_dname_from_fqdn: invalid\n"); - return (-1); - } - - if (as->as.dns.obuf == NULL) { - as->as.dns.obufsize = PACKETSZ; - as->as.dns.obuf = malloc(as->as.dns.obufsize); - if (as->as.dns.obuf == NULL) - return (-1); /* errno set */ - } - as->as.dns.obuflen = 0; - - memset(&h, 0, sizeof h); - h.id = res_randomid(); - if (as->as_ctx->ac_options & RES_RECURSE) - h.flags |= RD_MASK; -#ifdef RES_USE_CD - if (as->as_ctx->ac_options & RES_USE_CD) - h.flags |= CD_MASK; -#endif - h.qdcount = 1; - if (as->as_ctx->ac_options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) - h.arcount = 1; - - _asr_pack_init(&p, as->as.dns.obuf, as->as.dns.obufsize); - _asr_pack_header(&p, &h); - _asr_pack_query(&p, type, class, dname); - if (as->as_ctx->ac_options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) - _asr_pack_edns0(&p, MAXPACKETSZ, - as->as_ctx->ac_options & RES_USE_DNSSEC); - if (p.err) { - DPRINT("error packing query"); - errno = EINVAL; - return (-1); - } - - /* Remember the parameters. */ - as->as.dns.reqid = h.id; - as->as.dns.type = type; - as->as.dns.class = class; - if (as->as.dns.dname) - free(as->as.dns.dname); - as->as.dns.dname = strdup(dname); - if (as->as.dns.dname == NULL) { - DPRINT("strdup"); - return (-1); /* errno set */ - } - as->as.dns.obuflen = p.offset; - - DPRINT_PACKET("asr_setup_query", as->as.dns.obuf, as->as.dns.obuflen); - - return (0); -} - -/* - * Create a connect UDP socket and send the output packet. - * - * Return 0 on success, or -1 on error (errno set). - */ -static int -udp_send(struct asr_query *as) -{ - ssize_t n; - int save_errno; -#ifdef DEBUG - char buf[256]; -#endif - - DPRINT("asr: [%p] connecting to %s UDP\n", as, - _asr_print_sockaddr(AS_NS_SA(as), buf, sizeof buf)); - - as->as_fd = sockaddr_connect(AS_NS_SA(as), SOCK_DGRAM); - if (as->as_fd == -1) - return (-1); /* errno set */ - - n = send(as->as_fd, as->as.dns.obuf, as->as.dns.obuflen, 0); - if (n == -1) { - save_errno = errno; - close(as->as_fd); - errno = save_errno; - as->as_fd = -1; - return (-1); - } - - return (0); -} - -/* - * Try to receive a valid packet from the current UDP socket. - * - * Return 0 if a full packet could be read, or -1 on error (errno set). - */ -static int -udp_recv(struct asr_query *as) -{ - ssize_t n; - int save_errno; - - if (ensure_ibuf(as, MAXPACKETSZ) == -1) { - save_errno = errno; - close(as->as_fd); - errno = save_errno; - as->as_fd = -1; - return (-1); - } - - n = recv(as->as_fd, as->as.dns.ibuf, as->as.dns.ibufsize, 0); - save_errno = errno; - close(as->as_fd); - errno = save_errno; - as->as_fd = -1; - if (n == -1) - return (-1); - - as->as.dns.ibuflen = n; - - DPRINT_PACKET("asr_udp_recv()", as->as.dns.ibuf, as->as.dns.ibuflen); - - if (validate_packet(as) == -1) - return (-1); /* errno set */ - - return (0); -} - -/* - * Write the output packet to the TCP socket. - * - * Return 0 when all bytes have been sent, 1 there is no buffer space on the - * socket or it is not connected yet, or -1 on error (errno set). - */ -static int -tcp_write(struct asr_query *as) -{ - struct msghdr msg; - struct iovec iov[2]; - uint16_t len; - ssize_t n; - size_t offset; - int i; -#ifdef DEBUG - char buf[256]; -#endif - - /* First try to connect if not already */ - if (as->as_fd == -1) { - DPRINT("asr: [%p] connecting to %s TCP\n", as, - _asr_print_sockaddr(AS_NS_SA(as), buf, sizeof buf)); - as->as_fd = sockaddr_connect(AS_NS_SA(as), SOCK_STREAM); - if (as->as_fd == -1) - return (-1); /* errno set */ -/* - * Some systems (MacOS X) have SO_NOSIGPIPE instead of MSG_NOSIGNAL. - * If neither is available the system is probably broken. We might - * want to detect this at configure time. - */ -#ifdef SO_NOSIGPIPE - i = 1; - if (setsockopt(as->as_fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&i, - sizeof(i)) == -1) - return (-1); /* errno set */ -#endif - as->as.dns.datalen = 0; /* bytes sent */ - return (1); - } - - i = 0; - - /* Prepend de packet length if not sent already. */ - if (as->as.dns.datalen < sizeof(len)) { - offset = 0; - len = htons(as->as.dns.obuflen); - iov[i].iov_base = (char *)(&len) + as->as.dns.datalen; - iov[i].iov_len = sizeof(len) - as->as.dns.datalen; - i++; - } else - offset = as->as.dns.datalen - sizeof(len); - - iov[i].iov_base = as->as.dns.obuf + offset; - iov[i].iov_len = as->as.dns.obuflen - offset; - i++; - - memset(&msg, 0, sizeof msg); - msg.msg_iov = iov; - msg.msg_iovlen = i; - - send_again: -/* See above. */ -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - n = sendmsg(as->as_fd, &msg, MSG_NOSIGNAL); - if (n == -1) { - if (errno == EINTR) - goto send_again; - goto close; /* errno set */ - } - - as->as.dns.datalen += n; - - if (as->as.dns.datalen == as->as.dns.obuflen + sizeof(len)) { - /* All sent. Prepare for TCP read */ - as->as.dns.datalen = 0; - return (0); - } - - /* More data to write */ - return (1); - -close: - close(as->as_fd); - as->as_fd = -1; - return (-1); -} - -/* - * Try to read a valid packet from the current TCP socket. - * - * Return 0 if a full packet could be read, 1 if more data is needed and the - * socket must be read again, or -1 on error (errno set). - */ -static int -tcp_read(struct asr_query *as) -{ - ssize_t n; - size_t offset, len; - char *pos; - int save_errno, nfds; - struct pollfd pfd; - - /* We must read the packet len first */ - if (as->as.dns.datalen < sizeof(as->as.dns.pktlen)) { - - pos = (char *)(&as->as.dns.pktlen) + as->as.dns.datalen; - len = sizeof(as->as.dns.pktlen) - as->as.dns.datalen; - - read_again0: - n = read(as->as_fd, pos, len); - if (n == -1) { - if (errno == EINTR) - goto read_again0; - goto close; /* errno set */ - } - if (n == 0) { - errno = ECONNRESET; - goto close; - } - as->as.dns.datalen += n; - if (as->as.dns.datalen < sizeof(as->as.dns.pktlen)) - return (1); /* need more data */ - - as->as.dns.ibuflen = ntohs(as->as.dns.pktlen); - if (ensure_ibuf(as, as->as.dns.ibuflen) == -1) - goto close; /* errno set */ - - pfd.fd = as->as_fd; - pfd.events = POLLIN; - poll_again: - nfds = poll(&pfd, 1, 0); - if (nfds == -1) { - if (errno == EINTR) - goto poll_again; - goto close; /* errno set */ - } - if (nfds == 0) - return (1); /* no more data available */ - } - - offset = as->as.dns.datalen - sizeof(as->as.dns.pktlen); - pos = as->as.dns.ibuf + offset; - len = as->as.dns.ibuflen - offset; - - read_again: - n = read(as->as_fd, pos, len); - if (n == -1) { - if (errno == EINTR) - goto read_again; - goto close; /* errno set */ - } - if (n == 0) { - errno = ECONNRESET; - goto close; - } - as->as.dns.datalen += n; - - /* See if we got all the advertised bytes. */ - if (as->as.dns.datalen != as->as.dns.ibuflen + sizeof(as->as.dns.pktlen)) - return (1); - - DPRINT_PACKET("asr_tcp_read()", as->as.dns.ibuf, as->as.dns.ibuflen); - - if (validate_packet(as) == -1) - goto close; /* errno set */ - - errno = 0; -close: - save_errno = errno; - close(as->as_fd); - errno = save_errno; - as->as_fd = -1; - return (errno ? -1 : 0); -} - -/* - * Make sure the input buffer is at least "n" bytes long, and allocate or - * extend it if necessary. Return 0 on success, or set errno and return -1. - */ -static int -ensure_ibuf(struct asr_query *as, size_t n) -{ - char *t; - - if (as->as.dns.ibufsize >= n) - return (0); - - t = recallocarray(as->as.dns.ibuf, as->as.dns.ibufsize, n, 1); - if (t == NULL) - return (-1); /* errno set */ - as->as.dns.ibuf = t; - as->as.dns.ibufsize = n; - - return (0); -} - -/* - * Check if the received packet is valid. - * Return 0 on success, or set errno and return -1. - */ -static int -validate_packet(struct asr_query *as) -{ - struct asr_unpack p; - struct asr_dns_header h; - struct asr_dns_query q; - struct asr_dns_rr rr; - int r; - - _asr_unpack_init(&p, as->as.dns.ibuf, as->as.dns.ibuflen); - - _asr_unpack_header(&p, &h); - if (p.err) - goto inval; - - if (h.id != as->as.dns.reqid) { - DPRINT("incorrect reqid\n"); - goto inval; - } - if (h.qdcount != 1) - goto inval; - /* Should be zero, we could allow this */ - if ((h.flags & Z_MASK) != 0) - goto inval; - /* Actually, it depends on the request but we only use OP_QUERY */ - if (OPCODE(h.flags) != OP_QUERY) - goto inval; - /* Must be a response */ - if ((h.flags & QR_MASK) == 0) - goto inval; - - as->as.dns.rcode = RCODE(h.flags); - as->as.dns.ancount = h.ancount; - - _asr_unpack_query(&p, &q); - if (p.err) - goto inval; - - if (q.q_type != as->as.dns.type || - q.q_class != as->as.dns.class || - strcasecmp(q.q_dname, as->as.dns.dname)) { - DPRINT("incorrect type/class/dname '%s' != '%s'\n", - q.q_dname, as->as.dns.dname); - goto inval; - } - - /* Check for truncation */ - if (h.flags & TC_MASK && !(as->as_ctx->ac_options & RES_IGNTC)) { - DPRINT("truncated\n"); - errno = EOVERFLOW; - return (-1); - } - - /* Validate the rest of the packet */ - for (r = h.ancount + h.nscount + h.arcount; r; r--) - _asr_unpack_rr(&p, &rr); - - /* Report any error found when unpacking the RRs. */ - if (p.err) { - DPRINT("unpack: %s\n", strerror(p.err)); - errno = p.err; - return (-1); - } - - if (p.offset != as->as.dns.ibuflen) { - DPRINT("trailing garbage\n"); - errno = EMSGSIZE; - return (-1); - } - - return (0); - - inval: - errno = EINVAL; - return (-1); -} - -/* - * Set the async context nameserver index to the next nameserver, cycling - * over the list until the maximum retry counter is reached. Return 0 on - * success, or -1 if all nameservers were used. - */ -static int -iter_ns(struct asr_query *as) -{ - for (;;) { - if (as->as.dns.nsloop >= as->as_ctx->ac_nsretries) - return (-1); - - as->as.dns.nsidx += 1; - if (as->as.dns.nsidx <= as->as_ctx->ac_nscount) - break; - as->as.dns.nsidx = 0; - as->as.dns.nsloop++; - DPRINT("asr: iter_ns(): cycle %i\n", as->as.dns.nsloop); - } - - as->as_timeout = 1000 * (as->as_ctx->ac_nstimeout << as->as.dns.nsloop); - if (as->as.dns.nsloop > 0) - as->as_timeout /= as->as_ctx->ac_nscount; - if (as->as_timeout < 1000) - as->as_timeout = 1000; - - return (0); -} diff --git a/foobar/portable/openbsd-compat/libasr/sethostent.c b/foobar/portable/openbsd-compat/libasr/sethostent.c deleted file mode 100644 index 61fa3e2f..00000000 --- a/foobar/portable/openbsd-compat/libasr/sethostent.c +++ /dev/null @@ -1,36 +0,0 @@ -/* $OpenBSD: sethostent.c,v 1.2 2018/04/28 15:09:35 schwarze Exp $ */ -/* - * Copyright (c) 2012 Eric Faurot - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -void -sethostent(int stayopen) -{ -} - -void -endhostent(void) -{ -} - -struct hostent * -gethostent(void) -{ - h_errno = NETDB_INTERNAL; - return NULL; -} diff --git a/foobar/portable/openbsd-compat/libasr/thread_private.h b/foobar/portable/openbsd-compat/libasr/thread_private.h deleted file mode 100644 index 23951975..00000000 --- a/foobar/portable/openbsd-compat/libasr/thread_private.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * - */ -#define __is_threaded (0) -#define _THREAD_PRIVATE_MUTEX(x) -#define _THREAD_PRIVATE_MUTEX_LOCK(x) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(x) -#define _THREAD_PRIVATE(a, b, c) (c) diff --git a/foobar/portable/openbsd-compat/libressl.c b/foobar/portable/openbsd-compat/libressl.c deleted file mode 100644 index f4f2b52e..00000000 --- a/foobar/portable/openbsd-compat/libressl.c +++ /dev/null @@ -1,131 +0,0 @@ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -int -SSL_CTX_use_certificate_chain(SSL_CTX *ctx, char *buf, off_t len) -{ - int ret; - BIO*in; - X509*x; - X509*ca; - unsigned long err; - - ret = 0; - x = ca = NULL; - - if ((in = BIO_new_mem_buf(buf, len)) == NULL) { - SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB); - goto end; - } - - if ((x = PEM_read_bio_X509(in, NULL, - ctx->default_passwd_callback, - ctx->default_passwd_callback_userdata)) == NULL) { - SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB); - goto end; - } - - if (!SSL_CTX_use_certificate(ctx, x) || ERR_peek_error() != 0) - goto end; - - /* If we could set up our certificate, now proceed to - * the CA certificates. - */ - - if (ctx->extra_certs != NULL) { - sk_X509_pop_free(ctx->extra_certs, X509_free); - ctx->extra_certs = NULL; - } - - while ((ca = PEM_read_bio_X509(in, NULL, - ctx->default_passwd_callback, - ctx->default_passwd_callback_userdata)) != NULL) { - - if (!SSL_CTX_add_extra_chain_cert(ctx, ca)) - goto end; - } - - err = ERR_peek_last_error(); - if (ERR_GET_LIB(err) == ERR_LIB_PEM && - ERR_GET_REASON(err) == PEM_R_NO_START_LINE) - ERR_clear_error(); - else - goto end; - - ret = 1; -end: - if (ca != NULL) - X509_free(ca); - if (x != NULL) - X509_free(x); - if (in != NULL) - BIO_free(in); - return (ret); -} diff --git a/foobar/portable/openbsd-compat/nanosleep.c b/foobar/portable/openbsd-compat/nanosleep.c deleted file mode 100644 index 1256c0b5..00000000 --- a/foobar/portable/openbsd-compat/nanosleep.c +++ /dev/null @@ -1,63 +0,0 @@ - -/* - * Copyright (c) 1999-2004 Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#ifdef HAVE_SYS_SELECT_H -# include -#endif -#ifdef HAVE_SYS_TIME_H -# include -#endif - -#include -#include -#include -#include -#include -#include - -int -nanosleep(const struct timespec *req, struct timespec *rem) -{ - int rc, saverrno; - extern int errno; - struct timeval tstart, tstop, tremain, time2wait; - - TIMESPEC_TO_TIMEVAL(&time2wait, req); - (void) gettimeofday(&tstart, NULL); - rc = select(0, NULL, NULL, NULL, &time2wait); - if (rc == -1) { - saverrno = errno; - (void) gettimeofday (&tstop, NULL); - errno = saverrno; - tremain.tv_sec = time2wait.tv_sec - - (tstop.tv_sec - tstart.tv_sec); - tremain.tv_usec = time2wait.tv_usec - - (tstop.tv_usec - tstart.tv_usec); - tremain.tv_sec += tremain.tv_usec / 1000000L; - tremain.tv_usec %= 1000000L; - } else { - tremain.tv_sec = 0; - tremain.tv_usec = 0; - } - if (rem != NULL) - TIMEVAL_TO_TIMESPEC(&tremain, rem); - - return(rc); -} diff --git a/foobar/portable/openbsd-compat/openbsd-compat.h b/foobar/portable/openbsd-compat/openbsd-compat.h deleted file mode 100644 index 57748621..00000000 --- a/foobar/portable/openbsd-compat/openbsd-compat.h +++ /dev/null @@ -1,340 +0,0 @@ -/* $Id: openbsd-compat.h,v 1.51 2010/10/07 10:25:29 djm Exp $ */ - -/* - * Copyright (c) 1999-2003 Damien Miller. All rights reserved. - * Copyright (c) 2003 Ben Lindstrom. All rights reserved. - * Copyright (c) 2002 Tim Rice. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _OPENBSD_COMPAT_H -#define _OPENBSD_COMPAT_H - -#include "includes.h" - -#include - -#include -#include - -/* OpenBSD function replacements */ -#include "base64.h" - -#include -#include -#include "bsd-vis.h" - -#ifdef HAVE_SYS_TIME_H -#include -#endif - -#ifndef HAVE_BASENAME -char *basename(const char *path); -#endif - -#ifndef HAVE_CLOSEFROM -void closefrom(int); -#endif - -#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) -char *realpath(const char *path, char *resolved); -#endif - -#if !HAVE_DECL_STRLCPY -size_t strlcpy(char *dst, const char *src, size_t size); -#endif - -#if !HAVE_DECL_STRLCAT -size_t strlcat(char *dst, const char *src, size_t size); -#endif - -#ifndef HAVE_STRMODE -void strmode(int mode, char *p); -#endif - -#ifndef HAVE_DAEMON -int daemon(int nochdir, int noclose); -#endif - -#ifndef HAVE_DIRNAME -char *dirname(const char *path); -#endif - -#ifndef HAVE_FMT_SCALED -#define FMT_SCALED_STRSIZE 7 -int fmt_scaled(long long number, char *result); -#endif - -#ifndef HAVE_SCAN_SCALED -int scan_scaled(char *, long long *); -#endif - -#ifndef HAVE_INET_NTOP -const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); -#endif - -#ifndef HAVE_STRSEP -char *strsep(char **stringp, const char *delim); -#endif - -#ifndef HAVE_SETPROCTITLE -void setproctitle(const char *fmt, ...); -void compat_init_setproctitle(int argc, char *argv[]); -#endif - -#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET) -int BSDgetopt(int argc, char * const *argv, const char *opts); -#endif - -/* Home grown routines */ -#include "bsd-misc.h" -/* #include "bsd-setres_id.h" */ -/* #include "bsd-statvfs.h" */ -#include "bsd-waitpid.h" -/* #include "bsd-poll.h" */ - -#ifndef HAVE_GETPEEREID -int getpeereid(int , uid_t *, gid_t *); -#endif - -#if !defined(HAVE_ARC4RANDOM) || defined(LIBRESSL_VERSION_NUMBER) -unsigned int arc4random(void); -#endif - -#if 0 -#if defined(LIBRESSL_VERSION_NUMBER) -# define arc4random_stir() -#elif defined(HAVE_ARC4RANDOM_STIR) -void arc4random_stir(void); -#elif defined(HAVE_ARC4RANDOM) -/* Recent system/libressl implementation; no need for explicit stir */ -# define arc4random_stir() -#else -/* openbsd-compat/arc4random.c provides arc4random_stir() */ -void arc4random_stir(void); -#endif -#endif - -#if !defined(HAVE_ARC4RANDOM_BUF) || defined(LIBRESSL_VERSION_NUMBER) -void arc4random_buf(void *, size_t); -#endif - -#if !defined(HAVE_ARC4RANDOM_UNIFORM) || defined(LIBRESSL_VERSION_NUMBER) -uint32_t arc4random_uniform(uint32_t); -#endif - -#if !defined(SSL_OP_NO_CLIENT_RENEGOTIATION) && !defined(LIBRESSL_VERSION_NUMBER) -#define SSL_OP_NO_CLIENT_RENEGOTIATION 0 -#endif - -#ifndef HAVE_ASPRINTF -int asprintf(char **, const char *, ...); -#endif - -/* #include XXX needed? For size_t */ - -#ifndef HAVE_SNPRINTF -int snprintf(char *, size_t, const char *, ...); -#endif - -#ifndef HAVE_STRTOLL -long long strtoll(const char *, char **, int); -#endif - -#ifndef HAVE_STRTOUL -unsigned long strtoul(const char *, char **, int); -#endif - -#ifndef HAVE_STRTOULL -unsigned long long strtoull(const char *, char **, int); -#endif - -#ifndef HAVE_STRTONUM -long long strtonum(const char *nptr, long long minval, long long maxval, const char **errstr); -#endif - -#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) -# include -#endif - -#ifndef HAVE_VASPRINTF -int vasprintf(char **, const char *, va_list); -#endif - -#ifndef HAVE_VSNPRINTF -int vsnprintf(char *, size_t, const char *, va_list); -#endif - -#if !defined(HAVE_EXPLICIT_BZERO) || defined(LIBRESSL_VERSION_NUMBER) -void explicit_bzero(void *p, size_t n); -#endif - -/* OpenSMTPD-portable specific entries */ - -#ifndef HAVE_FGETLN -#include -#include -char * fgetln(FILE *stream, size_t *len); -#endif - -#ifndef HAVE_FPARSELN -#include -#include -char * fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags); -#endif - -#ifndef HAVE_FREEZERO -void freezero(void *, size_t); -#endif - -#ifndef HAVE_PIDFILE -int pidfile(const char *basename); -#endif - -#ifndef HAVE_PW_DUP -struct passwd *pw_dup(const struct passwd *); -#endif - -#if !defined(HAVE_REALLOCARRAY) || defined(LIBRESSL_VERSION_NUMBER) -void *reallocarray(void *, size_t, size_t); -#endif - -#if !defined(HAVE_RECALLOCARRAY) || defined(LIBRESSL_VERSION_NUMBER) -void *recallocarray(void *, size_t, size_t, size_t); -#endif - -#ifndef HAVE_ERRC -__attribute__ ((noreturn)) -void errc(int, int, const char *, ...); -#endif - -#ifndef HAVE_INET_NET_PTON -int inet_net_pton(int, const char *, void *, size_t); -#endif - -#ifndef HAVE_PLEDGE -#define pledge(promises, paths) 0 -#endif - -#ifndef HAVE_MALLOC_CONCEAL -#define malloc_conceal malloc -#endif - -#ifndef HAVE_CALLOC_CONCEAL -#define calloc_conceal calloc -#endif - -#ifndef HAVE_RES_HNOK -int res_hnok(const char *); -#endif - -#if !HAVE_DECL_AF_LOCAL -#define AF_LOCAL AF_UNIX -#endif - -#if !HAVE_DECL_PF_LOCAL -#define PF_LOCAL PF_UNIX -#endif - -#if !HAVE_DECL_WAIT_MYPGRP -#define WAIT_MYPGRP 0 -#endif - -#if !HAVE_DECL_IPPORT_HILASTAUTO -#define IPPORT_HILASTAUTO 65535 -#endif - -#ifndef HAVE_FLOCK -int flock(int, int); -#endif - -#ifndef HAVE_SETRESGID -int setresgid(uid_t, uid_t, uid_t); -#endif - -#ifndef HAVE_SETRESUID -int setresuid(uid_t, uid_t, uid_t); -#endif - -#ifndef HAVE_GETLINE -ssize_t getline(char **, size_t *, FILE *); -#endif - -#ifndef HAVE_CRYPT_CHECKPASS -int crypt_checkpass(const char *, const char *); -#endif - -#ifndef HAVE_STRNDUP -char * strndup(const char *, size_t); -#endif - -#ifndef HAVE_STRNLEN -char * strnlen(const char *, size_t); -#endif - -#ifndef HAVE_STRUCT_TIMEVAL -struct timeval { - long tv_sec; - long tv_usec; -} -#endif - -#ifdef NEED_NANOSLEEP -#ifndef HAVE_STRUCT_TIMESPEC -struct timespec { - time_t tv_sec; - long tv_nsec; -}; -#endif -int nanosleep(const struct timespec *, struct timespec *); -#endif - -#ifdef NEED_SETEGID -int setegid(uid_t); -#endif - -#ifdef NEED_SETEUID -int seteuid(uid_t); -#endif - -#ifdef NEED_SETSID -#define setsid() setpgrp(0, getpid()) -#endif - -#ifdef NEED_SIGNAL -typedef void (*mysig_t)(int); -mysig_t mysignal(int sig, mysig_t act); -#define signal(a,b) mysignal(a,b) -#endif - -#ifdef NEED_STRERROR -const char *strerror(int); -#endif - -#ifdef NEED_USLEEP -int usleep(unsigned int useconds); -#endif - -char *get_progname(char *); - - -#endif /* _OPENBSD_COMPAT_H */ diff --git a/foobar/portable/openbsd-compat/paths_h/paths.h b/foobar/portable/openbsd-compat/paths_h/paths.h deleted file mode 100644 index 6b66a9c1..00000000 --- a/foobar/portable/openbsd-compat/paths_h/paths.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef PATHS_H -#define PATHS_H - -#ifndef _PATH_DEFPATH -#define _PATH_DEFPATH "/bin:/usr/bin" -#endif - -#endif diff --git a/foobar/portable/openbsd-compat/pidfile.c b/foobar/portable/openbsd-compat/pidfile.c deleted file mode 100644 index d6f83880..00000000 --- a/foobar/portable/openbsd-compat/pidfile.c +++ /dev/null @@ -1,112 +0,0 @@ -/* $OpenBSD: pidfile.c,v 1.8 2008/06/26 05:42:05 ray Exp $ */ -/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */ - -/*- - * Copyright (c) 1999 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* OPENBSD ORIGINAL: lib/libutil/pidfile.c */ - -#include "includes.h" -#ifndef HAVE_PIDFILE - -#include -#include -#include -#include -#include - -static char *pidfile_path; -static pid_t pidfile_pid; - -static void pidfile_cleanup(void); - -extern char *__progname; - -int -pidfile(const char *basename) -{ - int save_errno; - pid_t pid; - FILE *f; - - if (basename == NULL) - basename = __progname; - - if (pidfile_path != NULL) { - free(pidfile_path); - pidfile_path = NULL; - } - - (void) asprintf(&pidfile_path, "%s/%s.pid", SMTPD_PIDDIR, basename); - if (pidfile_path == NULL) - return (-1); - - if ((f = fopen(pidfile_path, "w")) == NULL) { - save_errno = errno; - free(pidfile_path); - pidfile_path = NULL; - errno = save_errno; - return (-1); - } - - pid = getpid(); - if (fprintf(f, "%ld\n", (long)pid) <= 0) { - fclose(f); - save_errno = errno; - (void) unlink(pidfile_path); - free(pidfile_path); - pidfile_path = NULL; - errno = save_errno; - return (-1); - } - - fclose(f); - pidfile_pid = pid; - if (atexit(pidfile_cleanup) < 0) { - save_errno = errno; - (void) unlink(pidfile_path); - free(pidfile_path); - pidfile_path = NULL; - pidfile_pid = 0; - errno = save_errno; - return (-1); - } - - return (0); -} - -static void -pidfile_cleanup(void) -{ - - if (pidfile_path != NULL && pidfile_pid == getpid()) - (void) unlink(pidfile_path); -} - -#endif diff --git a/foobar/portable/openbsd-compat/progname.c b/foobar/portable/openbsd-compat/progname.c deleted file mode 100644 index b8b9ae30..00000000 --- a/foobar/portable/openbsd-compat/progname.c +++ /dev/null @@ -1,62 +0,0 @@ - -/* - * Copyright (c) 1999-2004 Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "includes.h" - -#include -#ifdef HAVE_SYS_SELECT_H -# include -#endif -#ifdef HAVE_SYS_TIME_H -# include -#endif - -#include -#include -#include -#include -#include -#include - -/* - * NB. duplicate __progname in case it is an alias for argv[0] - * Otherwise it may get clobbered by setproctitle() - */ -char *get_progname(char *argv0) -{ - char *retp; -#ifdef HAVE___PROGNAME - extern char *__progname; - - if ((retp = strdup(__progname)) == NULL) - err(1, NULL); -#else - char *p; - - if (argv0 == NULL) - return ("unknown"); /* XXX */ - p = strrchr(argv0, '/'); - if (p == NULL) - p = argv0; - else - p++; - - if ((retp = strdup(p)) == NULL) - err(1, NULL); -#endif - return retp; -} diff --git a/foobar/portable/openbsd-compat/reallocarray.c b/foobar/portable/openbsd-compat/reallocarray.c deleted file mode 100644 index 9beec719..00000000 --- a/foobar/portable/openbsd-compat/reallocarray.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */ -/* - * Copyright (c) 2008 Otto Moerbeek - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* OPENBSD ORIGINAL: lib/libc/stdlib/reallocarray.c */ - -#include "includes.h" - -#include -#include -#include -#include - -/* - * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX - * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW - */ -#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) - -void * -reallocarray(void *optr, size_t nmemb, size_t size) -{ - if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - nmemb > 0 && SIZE_MAX / nmemb < size) { - errno = ENOMEM; - return NULL; - } - return realloc(optr, size * nmemb); -} diff --git a/foobar/portable/openbsd-compat/recallocarray.c b/foobar/portable/openbsd-compat/recallocarray.c deleted file mode 100644 index fc0b5a8a..00000000 --- a/foobar/portable/openbsd-compat/recallocarray.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $OpenBSD: recallocarray.c,v 1.1 2017/03/06 18:44:21 otto Exp $ */ -/* - * Copyright (c) 2008, 2017 Otto Moerbeek - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* OPENBSD ORIGINAL: lib/libc/stdlib/recallocarray.c */ - -#include "includes.h" - -#include -#include -#include -#include -#include - -/* - * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX - * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW - */ -#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) - -void * -recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) -{ - size_t oldsize, newsize; - void *newptr; - - if (ptr == NULL) - return calloc(newnmemb, size); - - if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - newnmemb > 0 && SIZE_MAX / newnmemb < size) { - errno = ENOMEM; - return NULL; - } - newsize = newnmemb * size; - - if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - oldnmemb > 0 && SIZE_MAX / oldnmemb < size) { - errno = EINVAL; - return NULL; - } - oldsize = oldnmemb * size; - - /* - * Don't bother too much if we're shrinking just a bit, - * we do not shrink for series of small steps, oh well. - */ - if (newsize <= oldsize) { - size_t d = oldsize - newsize; - - if (d < oldsize / 2 && d < (size_t)getpagesize()) { - memset((char *)ptr + newsize, 0, d); - return ptr; - } - } - - newptr = malloc(newsize); - if (newptr == NULL) - return NULL; - - if (newsize > oldsize) { - memcpy(newptr, ptr, oldsize); - memset((char *)newptr + oldsize, 0, newsize - oldsize); - } else - memcpy(newptr, ptr, newsize); - - explicit_bzero(ptr, oldsize); - free(ptr); - - return newptr; -} diff --git a/foobar/portable/openbsd-compat/res_hnok.c b/foobar/portable/openbsd-compat/res_hnok.c deleted file mode 100644 index a4b54baf..00000000 --- a/foobar/portable/openbsd-compat/res_hnok.c +++ /dev/null @@ -1,169 +0,0 @@ -/* $OpenBSD: res_comp.c,v 1.14 2008/04/16 22:35:23 deraadt Exp $ */ - -/* - * ++Copyright++ 1985, 1993 - * - - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -/* OPENBSD ORIGINAL: lib/libc/net/res_comp.c */ - -#include "includes.h" - -/* - * Verify that a domain name uses an acceptable character set. - */ - -/* - * Note the conspicuous absence of ctype macros in these definitions. On - * non-ASCII hosts, we can't depend on string literals or ctype macros to - * tell us anything about network-format data. The rest of the BIND system - * is not careful about this, but for some reason, we're doing it right here. - */ -#define PERIOD 0x2e -#define hyphenchar(c) ((c) == 0x2d) -#define bslashchar(c) ((c) == 0x5c) -#define underscorechar(c) ((c) == 0x5f) -#define periodchar(c) ((c) == PERIOD) -#define asterchar(c) ((c) == 0x2a) -#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ - || ((c) >= 0x61 && (c) <= 0x7a)) -#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) - -#define borderchar(c) (alphachar(c) || digitchar(c)) -#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) - -int -res_hnok(const char *dn) -{ - int pch = PERIOD, ch = *dn++; - - while (ch != '\0') { - int nch = *dn++; - - if (periodchar(ch)) { - ; - } else if (periodchar(pch)) { - if (!borderchar(ch)) - return (0); - } else if (periodchar(nch) || nch == '\0') { - if (!borderchar(ch)) - return (0); - } else { - if (!middlechar(ch)) - return (0); - } - pch = ch, ch = nch; - } - return (1); -} - -#if 0 - -/* - * hostname-like (A, MX, WKS) owners can have "*" as their first label - * but must otherwise be as a host name. - */ -int -res_ownok(const char *dn) -{ - if (asterchar(dn[0])) { - if (periodchar(dn[1])) - return (res_hnok(dn+2)); - if (dn[1] == '\0') - return (1); - } - return (res_hnok(dn)); -} - -/* - * SOA RNAMEs and RP RNAMEs can have any printable character in their first - * label, but the rest of the name has to look like a host name. - */ -int -res_mailok(const char *dn) -{ - int ch, escaped = 0; - - /* "." is a valid missing representation */ - if (*dn == '\0') - return(1); - - /* otherwise