Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linux support #4

Closed
wants to merge 201 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
861d30f
Add configure script
Duncaen May 6, 2016
a424761
Sync doas.c
Duncaen May 6, 2016
e0dd9ee
Actually open pam sessions
Duncaen May 6, 2016
2d34633
Add more compatibility functions for linux support
Duncaen May 6, 2016
8558e5d
Testing only seccomp pledge
Duncaen May 6, 2016
673f187
Fix typos and configure pledge detection
Duncaen May 7, 2016
5af624a
Enable style option only if bsd_auth.h is available
Duncaen May 7, 2016
33e3630
Add proper pam session handling
Duncaen May 8, 2016
e246f9e
configure: tune up a little bit
May 8, 2016
c387f2c
set PAM_USER, PAM_RUSER and PAM_TTY if available
Duncaen May 8, 2016
09843fc
Simply install and move version to configure script
Duncaen May 8, 2016
9972a8e
Fix horrible mistake
Duncaen May 8, 2016
ba41f89
fix make install
May 8, 2016
e18b632
Merge pull request #4 from frgm/master
Duncaen May 8, 2016
eb33da1
More configure and make cleanup
Duncaen May 8, 2016
cbae406
Make pam session handling more failsafe
Duncaen May 8, 2016
1200408
Add doas style prompt for pam authentication
Duncaen May 8, 2016
82fa799
bsd.prog.mk: add "uninstall" target
May 9, 2016
0f13894
fix configure script
May 9, 2016
c05b37b
Merge pull request #7 from frgm/master
Duncaen May 9, 2016
e60457f
remove nonstandard sys/cdefs.h
Duncaen Jun 2, 2016
e4bf599
check return value of setresuid
Duncaen Jun 2, 2016
a55cefe
remove version.h and define VERSION in configure script
Duncaen Jun 5, 2016
7f11114
sync with upstream (setenv)
Duncaen Jun 5, 2016
e939687
fix ld and cflags
Duncaen Jun 5, 2016
5c50281
add more restrictive permissions and root:root as owner for binary
Duncaen Jun 5, 2016
63a642e
bump version to 0.2
Duncaen Jun 5, 2016
21c6e42
Revert "sync with upstream (setenv)"
Duncaen Jun 8, 2016
4f7ed38
open pam sessions with right user and remove setusercontext shim
Duncaen Jun 8, 2016
f577047
remove pledge seccomp shim
Duncaen Jun 8, 2016
2a5702a
specify that default is deny if no rule matches
Jun 11, 2016
268a284
clarify some wording
Jun 11, 2016
9278ac5
don't use specified twice in a sentence, noticed by jmc
Jun 11, 2016
1a0ed98
the environment handling code was showing its age. just because envir…
Jun 16, 2016
a3ceebb
Move the RB_ code from doas.h to env.c, and limit the environment int…
Jun 19, 2016
03b3cb7
import sys-tree.h from openssh-portable
Duncaen Jun 24, 2016
0473a9b
rename doas_pam.c to pam.c
Duncaen Jun 24, 2016
f4a7d36
some more cleanup and refactoring of pam code
Duncaen Jun 25, 2016
788dd4b
fix err messages
Duncaen Jun 25, 2016
e88a009
add --without-pam configure option to allow passwd/shadow auth
Duncaen Jun 26, 2016
3f6bcba
bump version 0.3
Duncaen Jun 8, 2016
e0c0b37
remove unnecessary warning output
Duncaen Jun 26, 2016
1606730
remove pam_timestamp from pam config
Duncaen Jun 26, 2016
f30e68c
bump version 0.3.1
Duncaen Jun 26, 2016
aedbe76
fix sys/tree.h test
Duncaen Jun 27, 2016
c05e559
fix pamcleanup
Duncaen Jun 27, 2016
45d57da
fix --with(out)-pam configure option
Duncaen Jun 27, 2016
c88a56c
bump to version v0.3.2
Duncaen Jun 27, 2016
154b849
configure: fix usage() formatting
Jun 27, 2016
7c37e22
fix make install
Jun 27, 2016
33a5cf1
Merge pull request #8 from frgm/master
Duncaen Jun 27, 2016
555da71
move a space to the correct spot
Jun 24, 2016
5e9d768
revise environment handling. Add a setenv keyword for manipulating th…
Jun 27, 2016
3460a3c
somehow nopass snuck onto the :wheel example. i think it's better wit…
Jun 27, 2016
7bdae50
minor tweaks; ok tedu
Jun 27, 2016
03b7619
minor tweaks
Duncaen Jun 27, 2016
6ed45e5
use posix correct optstring
Duncaen Jun 29, 2016
6ec218c
add "recvfd" to doas(1) for use with skey.
Jul 12, 2016
24c9841
The string with path to shell could be taken directly from struct pas…
Jul 18, 2016
b3a6a29
configure: error out if no authentication found and fix default CC
Duncaen Sep 2, 2016
3611050
minor configure tweaks
Duncaen Sep 3, 2016
fc4df78
Print -a flag in usage() only if HAVE_BSD_AUTH_H
phikal Sep 5, 2016
01a8fd6
Add closefrom(2) from openssh-portable
Duncaen Sep 6, 2016
5a7014d
bump version to v6.0
Duncaen Sep 6, 2016
33d4bf7
move the authentication code to a function
Sep 1, 2016
3d4da2d
unconst these parameters; i won't be changing bsd auth today.
Sep 1, 2016
27235dd
add support for the verified auth ioctls using 'persist' rules. ok de…
Sep 2, 2016
f9b39a6
clarify that -L will exit without running a command.
Sep 2, 2016
30bd833
the sudo timeout was 5 minutes i believe, so we'll match that.
Sep 3, 2016
f5f27a8
don't allow combining nopass and persist in a single rule
Sep 4, 2016
380865b
-L means no command
Sep 4, 2016
b7e6671
use static in the right places to seperate modules better ok tedu
Sep 15, 2016
be66392
as a result of the env rework, arraylen() is only used in parse.y. mo…
Oct 5, 2016
a6f4fdf
move yyparse decl next to yyfp
Oct 5, 2016
25cd404
Add back the call to yyparse() that was accidentally dropped in the p…
Oct 5, 2016
293637b
missing semicolon at end of rule. yacc doesn't seem to mind, though. …
Nov 10, 2016
8150cd4
Be more explicit about the "args" syntax. In part from a patch from A…
Dec 5, 2016
75ec7b4
it has been six months and two days... remove keepenv { obsolete } sy…
Dec 29, 2016
ed8c643
envlist and arglist are both string lists; simplify ok benno
Jan 2, 2017
97d12a5
add a geteuid check to make sure we're root before plowing into setau…
Jan 14, 2017
998d490
simplify example. list of ports variables was non-exahustive, which m…
Mar 20, 2017
7413704
prepenv can take a const rule
Apr 6, 2017
f0fa08c
a little const here and there to prevent rules from changing
Apr 6, 2017
d8c2180
for password failure, print Authorization failed instead of EPERM. wi…
May 27, 2017
6d25808
no need to generate y.tab.h if nothing uses it, set YFLAGS to nothing…
Jul 3, 2017
1aa26de
man pages with pseudo synopses which list filenames end up creating v…
Jul 13, 2017
d823683
configure: fix usage
Duncaen Dec 11, 2017
4dc52eb
configure: update version
Duncaen Dec 11, 2017
1899c37
add initial timestamp file support, disabled by default and only with…
Duncaen Dec 11, 2017
ec70ae5
persist_timestamp: use /proc/self/stat to get tty_nr
Duncaen Dec 12, 2017
7c364fd
persist_timestamp: cleanup
Duncaen Dec 12, 2017
ef627e6
persist_timestamp: don't allow og+rwx permission for timestamp directory
Duncaen Dec 12, 2017
492b5e3
persist_timestamp: use CLOCK_MONOTONIC_RAW
Duncaen Dec 12, 2017
c745626
persist_timestamp: make tmpfs requirement optional and only available…
Duncaen Dec 12, 2017
619c319
persist_timestamp: add session id to timestamps
Duncaen Dec 12, 2017
7694068
persist_timestamp: use open directory fd to check and work with times…
Duncaen Dec 12, 2017
89c2c8e
persist_timestamp: persist_check was only used internally, make it st…
Duncaen Dec 12, 2017
5054c7a
persist_timestamp: remove goto from persist_open
Duncaen Dec 12, 2017
6cf64c2
persist_timestamp: create timestamp file with O_NOFOLLOW and don't le…
Duncaen Dec 12, 2017
c04c64a
persist_timestamp: move timespec macros to libopenbsd
Duncaen Dec 12, 2017
3018a66
persist_timestamp: add start time and document implementation details
Duncaen Apr 6, 2018
4b1b24b
pam: check watch child pid
Duncaen Apr 6, 2018
badba30
not necessarily the same name, but the indicated name
Feb 7, 2018
3f3c502
lowercase doas ee cummings style
Feb 7, 2018
9d63eb3
doas.c: put login_style in ifdef to compile on Linux
Jan 30, 2019
dbac3f3
adjust yyerror() to precede with "progname: " the error message string
gleydsonsoares Jan 30, 2019
6123150
libopenbsd/readpassphrase: update to latest version from openssh-port…
Duncaen Jan 30, 2019
365f922
libopenbsd/closefrom: correctly handle snprintf truncation
Duncaen Jan 30, 2019
77e474f
doas: remove v flag, not neccessary, upstream doesn't have it and __D…
Duncaen Jan 30, 2019
3df7947
doas: remove unnecessary configure checks, move shadow to its own file
Duncaen Jan 30, 2019
bf8b7be
libopenbsd: minor cleanup
Duncaen Jan 30, 2019
331dda0
timestamp: rename and simplify
Duncaen Jan 30, 2019
ed7fb0a
pam: add timestamp support
Duncaen Jan 30, 2019
39c5d01
Do for most running out of memory err() what was done for most runnin…
Jul 11, 2018
37bd661
clear the password even after a mismatch
Jan 17, 2019
a283d2f
shadow: clear the password even after a mismatch
Duncaen Jan 30, 2019
8872767
configure: list --with-timestamp in help, since without is default
Jan 30, 2019
55c5e6b
Add generated file parse.c to .gitignore and 'make clean'
Jan 30, 2019
38e072b
shadow: clear phassphrase earlier
Duncaen Jan 30, 2019
8b2a776
pam: close timestamp fd in both both processes
Duncaen Jan 30, 2019
fe5ec57
timestamp: error out if fstat and lstat st_ino and st_dev are not the…
Duncaen Jul 26, 2019
8cba47c
libopenbsd/closefrom.c: sync with sudo
Duncaen Jul 26, 2019
346e58e
libopenbsd: remove MacOSX compat functions, its not supported anyways
Duncaen Jul 26, 2019
a1d5a98
README.md: update the readme to match the current state
Duncaen Jul 26, 2019
9a9495d
libopenbsd/closefrom.c: remove config.h include
Duncaen Jul 26, 2019
dd13658
use getpwuid_r to avoid problems with hidden static storage. ok deraa…
Jun 10, 2019
dbc7d06
a few cleanups and simplifications possible now that static pw is gon…
Jun 12, 2019
01c658f
redo the environment inheritance to not inherit. it was intended to m…
Jun 16, 2019
55adb00
always reset the "su" variables, which is more consistent and predict…
Jun 17, 2019
78ab134
mention environment resetting here as well. ok millert
Jun 17, 2019
2103dd5
setusercontext resets PATH (which we want). but then it becomes impos…
Jun 17, 2019
2da129d
mention that doas(1) resets the umask(2); OK tedu@
Jun 19, 2019
025db69
more precisely describe what happens to the environment without keepe…
Jun 19, 2019
45b802a
tweak wording a bit. always talk about creating a new environment. al…
Jun 21, 2019
3f08ab4
add an example hint that shows how original path can be retained
Jun 24, 2019
6d8f0e6
fix some more fallout from setting path in setusercontext. restore pr…
Jun 29, 2019
f94cf30
snprintf/vsnprintf return < 0 on error, rather than -1.
Jul 3, 2019
ae7c4ba
note that authentication is required, unless otherwise configured. ok…
Jul 4, 2019
4356cb6
fix one last edge case regarding PATH, allows simpler config.
Jul 7, 2019
3916903
fixup unveil
Duncaen Oct 19, 2019
96d7807
correct some unveil(2) violations due to "login.conf.db" access (the …
Sep 14, 2019
3dac6fb
add some checks to avoid UID_MAX (-1) here. this is not problematic w…
Oct 18, 2019
ea76157
configure: make {UID,GID}_MAX configurable
Duncaen Nov 21, 2019
9be2d26
timestamp: simplify
Duncaen Nov 21, 2019
74449f0
doas.c: remove dead ifdefs to unclutter code
Duncaen Nov 23, 2019
84ce5c7
configure: remove version
Duncaen Nov 23, 2019
1fae30e
Change binary permissions to 4755. Closes #26
escondida Jan 8, 2020
5dc1cde
libopenbsd: define __dead as noreturn
Duncaen Dec 6, 2019
22370cb
doas.c: initialize mygetpwuid_r result
Duncaen Dec 6, 2019
78c1c0f
timestamp.c: already return on 22th field of /proc/ppid/stat
Duncaen Dec 6, 2019
05f9777
timestamp.c: add some more error/warning messages
Duncaen Feb 3, 2020
5debef0
timestamp.c: correctly NUL terminate buffer read from /proc/pid/stat
Duncaen Feb 3, 2020
31d95b9
timestamp.c: check fstat(2) instead of separate stat(2)
Duncaen Feb 3, 2020
50a47d3
timestamp.c: remove warning for normal case
Duncaen Feb 3, 2020
84ccfe0
Honor --sysconfdir option for doas.conf path.
snimmagadda Nov 2, 2020
b1ae418
Fallback definition for HOST_NAME_MAX.
snimmagadda Nov 5, 2020
25b1f36
briefly mention /etc/examples/ in the FILES section of all the manual…
Feb 10, 2020
1ae5587
list example files in FILES with a short description: generally, "Exa…
May 16, 2020
7441dfc
Improve error message on missing permission
Oct 9, 2020
1530e7a
Add nolog option to avoid syslog(3)
Oct 9, 2020
bfea01b
fix SEE ALSO;
Oct 9, 2020
fd03103
check for login_cap.h and use setusercontext if available
Duncaen Nov 5, 2020
46a5abc
move HOST_NAME_MAX to the top and add it to shadow.c
Duncaen Nov 12, 2020
4daae4a
opendoas: Fallback for setresuid(2).
snimmagadda Nov 12, 2020
a3264b9
use config.h and link objects instead of libopenbsd.a
Duncaen Nov 12, 2020
22b6897
libopenbsd: clean up readpassphrase compat and fix ifdefs
Duncaen Nov 12, 2020
0a42dd6
remove includes.h and move the prototypes to doas.h
Duncaen Nov 12, 2020
b38cfb8
pam.c: remove dead assignment
Duncaen Nov 12, 2020
46db70a
pam.c: free rsp in case of failure
Duncaen Nov 12, 2020
13660d7
set _OPENBSD_SOURCE on NetBSD
Duncaen Nov 12, 2020
ea3dfc9
link libutil for setusercontext on NetBSD
Duncaen Nov 12, 2020
af676f5
fix portability issues with configure script
Duncaen Nov 12, 2020
9bfe647
configure: define CURDIR for all targets
Duncaen Nov 12, 2020
b82ffa6
simplify makefile
Duncaen Nov 12, 2020
5310da9
add back execvpe fallback
Duncaen Nov 12, 2020
b324c30
libopenbsd/closefrom.h: include path.h for _PATH_DEV on MacOSX
Duncaen Nov 12, 2020
049eedb
configure: don't set --no-as-needed on MacOSX while running checks
Duncaen Nov 12, 2020
378157c
use wheel group on MacOSX
Duncaen Nov 12, 2020
790aab4
add pam.d file for MacOSX
Duncaen Nov 12, 2020
46d2543
configure: add freebsd support
Duncaen Nov 12, 2020
17629b9
configure: add setresgid, setreuid and setregid checks
Duncaen Nov 12, 2020
29123f7
configure: fix verrc check
Duncaen Nov 14, 2020
d67caab
configure: use LDLIBS instead of setting LDFLAGS
Duncaen Nov 14, 2020
dc56c2f
pam.d: include system-auth for auth, account and session
Duncaen Nov 14, 2020
b3e966b
configure: respect environment and make CFLAGS
Duncaen Nov 14, 2020
a1ab056
pam: use PAM_REINITIALIZE_CRED
Duncaen Nov 14, 2020
31abd37
remove unused pam.d file
Duncaen Nov 14, 2020
36cc28e
increment the line number after the line continuation; ok tedu
Sep 1, 2015
01ac841
after reading a too long line, restart at the beginning of the buffer so
Nov 27, 2015
d5acd52
correctly reset path for rules without specific command
Duncaen Jan 28, 2021
6e3c6ba
Be more explicit by stating that the -n flag is linked to the nopass …
Jan 15, 2021
e8e8713
s/authorization/authentication/g
Jan 16, 2021
2d7431c
Promote nrules/maxrules to size_t and make sure they can't overflow. …
Jan 27, 2021
454489f
espie reminds me that EOF can happen for errors as well, so check for…
Dec 4, 2015
24b1a95
apply missing man page changes
Duncaen Jan 28, 2021
cfa9f0d
remove pam.d configuration files
Duncaen Jan 28, 2021
9474e41
Replace build/installation instructions with discouragements
Duncaen Jan 28, 2021
adeb56b
fixed typo in README.md
qbe Feb 3, 2021
9a25a6d
fix some wording in README.md
Duncaen Feb 3, 2021
6266763
Fix: improve formatting and add Wikipedia reference.
mlavi Jan 17, 2022
b96106b
pam: always print pam_conv messages to stderr
Duncaen Feb 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ version.h

*.swp
*.swo

config.mk
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
portions copyright (c) 2015 Nathan Holstein
portions copyright (c) 2015 Ted Unangst
portions copyright (c) 2016 Duncan Overbruck

To the best of my knowledge, everything is released under the BSD license.

Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ LDFLAGS+= -lpam
include bsd.prog.mk

doas.o: version.h

/etc/pam.d/doas: pam.d__doas
cp $< $@
install: /etc/pam.d/doas
20 changes: 10 additions & 10 deletions bsd.prog.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Copyright 2015 Nathan Holstein

BINDIR?=/usr/bin
MANDIR?=/usr/share/man

default: ${PROG}

OPENBSD:=reallocarray.c strtonum.c execvpe.c setresuid.c \
auth_userokay.c setusercontext.c explicit_bzero.c
include config.mk

OPENBSD:=$(addprefix libopenbsd/,${OPENBSD:.c=.o})
libopenbsd.a: ${OPENBSD}
${AR} -r $@ $?
Expand All @@ -21,26 +18,29 @@ ${PROG}: ${OBJS} libopenbsd.a

.%.chmod: %
cp $< $@
chmod ${BINMODE} $@
chown ${BINOWN}:${BINGRP} $@
chmod ${BINMODE} $@

${BINDIR}:
${DESTRDIR}${BINDIR} ${DESTRDIR}${PAMDIR}:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DESTRDIR ?

mkdir -pm 0755 $@

${BINDIR}/${PROG}: .${PROG}.chmod ${BINDIR}
${DESTDIR}${BINDIR}/${PROG}: .${PROG}.chmod ${BINDIR}
mv $< $@

${DESTDIR}${PAMDIR}/doas: ${PAM_DOAS}
cp $< $@

VERSION:=\#define VERSION "$(shell git describe --dirty --tags --long --always)"
OLDVERSION:=$(shell [ -f version.h ] && cat version.h)
version.h: ; @echo '$(VERSION)' > $@
ifneq ($(VERSION),$(OLDVERSION))
.PHONY: version.h
endif

MAN:=$(join $(addprefix ${MANDIR}/man,$(patsubst .%,%/,$(suffix ${MAN}))),${MAN})
MAN:=$(join $(addprefix ${DESTDIR}${MANDIR}/man,$(patsubst .%,%/,$(suffix ${MAN}))),${MAN})
$(foreach M,${MAN},$(eval $M: $(notdir $M); cp $$< $$@))

install: ${BINDIR}/${PROG} ${MAN}
install: ${DESTDIR}${BINDIR}/${PROG} ${DESTDIR}${PAMDIR}/doas ${MAN}

clean:
rm -f version.h
Expand Down
300 changes: 300 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
#!/bin/sh

for x; do
opt=${x%%=*}
var=${x#*=}
case "$opt" in
--enable-debug) DEBUG=yes;;
--prefix) PREFIX=$var;;
--exec-prefix) EPREFIX=$var;;
--bindir) BINDIR=$var;;
--mandir) MANDIR=$var;;
--datadir) SHAREDIR=$var;;
--build) BUILD=$var;;
--host) HOST=$var;;
--target) TARGET=$var;;
--includedir) INCLUDEDIR=$var;;
--sysconfdir) SYSCONFDIR=$var;;
--pamdir) PAMDIR=$var;;
--localstatedir) LOCALSTATEDIR=$var;;
--libdir) LIBDIR=$var;;
--datadir|--infodir) ;; # ignore autotools
--verbose) unset SILENT;;
--pkgconfigdir) PKGCONFIGDIR=$var;;
--enable-static) BUILD_STATIC=yes;;
--enable-seccomp) BUILD_SECCOMP=yes;;
--help) usage;;
*) echo "$0: WARNING: unknown option $opt" >&2;;
esac
done

CONFIG_MK=config.mk
rm -f "$CONFIG_MK"

cat <<EOF >>$CONFIG_MK
DESTDIR ?= /
PREFIX ?= ${PREFIX:="/usr"}
EPREFIX ?= ${EPREFIX:="${PREFIX}"}
SHAREDIR ?= ${SHAREDIR:="${PREFIX}/share"}
BINDIR ?= ${BINDIR:="${PREFIX}/bin"}
MANDIR ?= ${MANDIR:="${SHAREDIR}/man"}
SYSCONFDIR?= ${SYSCONFDIR:="/etc"}
PAMDIR ?= ${PAMDIR:="${SYSCONFDIR}/pam.d"}
EOF

if [ -z "$BUILD" ]; then
BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')"
fi
if [ -z "$HOST" ]; then
[ -z "$TARGET" ] && TARGET=$BUILD
HOST=$TARGET
fi
if [ -z "$TARGET" ]; then
[ -z "$HOST" ] && HOST=$BUILD
TARGET=$HOST
fi

if [ -z "$OS" ]; then
# Derive OS from cpu-manufacturer-os-kernel
CPU=${TARGET%%-*}
REST=${TARGET#*-}
MANU=${REST%%-*}
REST=${REST#*-}
OS=${REST%%-*}
REST=${REST#*-}
KERNEL=${REST%%-*}
fi

case "$OS" in
linux)
OS_CFLAGS="-D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=60000 -DGID_MAX=60000"
printf 'CURDIR := .\n' >>$CONFIG_MK
printf 'PAM_DOAS = pam.d__doas__linux\n' >>$CONFIG_MK
;;
esac

[ -n "$OS_CFLAGS" ] && \
printf 'CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK

# Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features
XCC="${CC:=clang} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS"
# Make sure to disable --as-needed for CC tests.
XCC="$XCC -Wl,--no-as-needed"

check_func() {
func="$1"; src="$2"; shift 2
printf 'Checking for %-14s\t\t' "$func ..."
printf '%s\n' "$src" >"_$func.c"
if $XCC "_$func.c" -o "_$func" 2>/dev/null; then
printf 'yes.\n'
upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
printf 'CFLAGS += -DHAVE_%s\n' "$upperfunc" >>$CONFIG_MK
else
printf 'no.\n'
fi
rm -f "_$func.c" "_$func"
}

src='
#include <string.h>
int main(void) {
explicit_bzero(NULL, 0);
return 0;
}'
check_func "explicit_bzero" "$src" || {
printf 'OPENBSD += explicit_bzero.c\n' >>$CONFIG_MK
}


#
# Check for strlcat().
#
src='
#include <string.h>
int main(void) {
const char s1[] = "foo";
char s2[10];
strlccat(s2, s1, sizeof(s2));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strlccat ?

return 0;
}'
check_func "strlcat" "$src" || {
printf 'OPENBSD += strlcat.c\n' >>$CONFIG_MK
}

#
# Check for strlcpy().
#
src='
#include <string.h>
int main(void) {
const char s1[] = "foo";
char s2[10];
strlcpy(s2, s1, sizeof(s2));
return 0;
}'
check_func "strlcpy" "$src" || {
printf 'OPENBSD += strlcpy.c\n' >>$CONFIG_MK
}

#
# Check for errc().
#
src='
#include <err.h>
int main(void) {
errc(0, 0, "");
return 0;
}'
check_func "errc" "$src" || {
printf 'OPENBSD += errc.c\n' >>$CONFIG_MK
}

#
# Check for verrc().
#
src='
#include <err.h>
int main(void) {
verrc(0, 0, "");
return 0;
}'
check_func "verrc" "$src" || {
printf 'OPENBSD += verrc.c\n' >>$CONFIG_MK
}

#
# Check for setprogname().
#
src='
#include <stdlib.h>
int main(void) {
setprogname("");
return 0;
}'
check_func "setprogname" "$src" || {
printf 'OPENBSD += progname.c\n' >>$CONFIG_MK
}

#
# Check for readpassphrase().
#
src='
#include <readpassphrase.h>
int main(void) {
char buf[12];
readpassphrase("", buf, sizeof(buf), 0);
return 0;
}'
check_func "readpassphrase" "$src" || {
printf 'OPENBSD += readpassphrase.c\n' >>$CONFIG_MK
}

#
# Check for strtonum().
#
src='
#include <stdlib.h>
int main(void) {
const char *errstr;
strtonum("", 1, 64, &errstr);
return 0;
}'
check_func "strtonum" "$src" || {
printf 'OPENBSD += strtonum.c\n' >>$CONFIG_MK
}

#
# Check for reallocarray().
#
src='
#include <stdlib.h>
int main(void) {
reallocarray(NULL, 0, 0);
return 0;
}'
check_func "reallocarray" "$src" || {
printf 'OPENBSD += reallocarray.c\n' >>$CONFIG_MK
}

#
# Check for bsd_auth.h.
#
src='
#include <bsd_auth.h>
int main(void) {
return 0;
}'
check_func "bsd_auth_h" "$src" || {
printf 'OPENBSD += auth_userokay.c\n' >>$CONFIG_MK
}

#
# Check for login_cap.h.
#
src='
#include <login_cap.h>
int main(void) {
return 0;
}'
check_func "login_cap_h" "$src" || {
printf 'OPENBSD += setusercontext.c\n' >>$CONFIG_MK
}

#
# Check for execvpe().
#
src='
#include <unistd.h>
int main(void) {
const char *p = { "", NULL };
execvpe("", p, p);
return 0;
}'
check_func "execvpe" "$src" || {
printf 'OPENBSD += execvpe.c\n' >>$CONFIG_MK
}

#
# Check for setresuid().
#
src='
#include <unistd.h>
int main(void) {
setresuid(0, 0, 0);
return 0;
}'
check_func "setresuid" "$src" || {
printf 'OPENBSD += setresuid.c\n' >>$CONFIG_MK
}

#
# Check for pledge().
#
src='
#include <unistd.h>
int main(void) {
pledge("", NULL);
return 0;
}'
check_func "pledge" "$src" && {
have_pledge=1
}

#
# Check for seccomp.h
#
src='
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <unistd.h>
int main(void) {
prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, NULL);
return 0;
}'
if [ -n "$have_pledge" -a -n "$BUILD_SECCOMP" ]; then
check_func "seccomp_h" "$src" && {
printf 'OPENBSD += pledge-seccomp.c\n' >>$CONFIG_MK
}
elif [ -n "$have_pledge" ]; then
printf 'OPENBSD += pledge-noop.c\n' >>$CONFIG_MK
fi
Loading