summaryrefslogtreecommitdiff
path: root/regress/libexec/ftpd/Makefile
blob: 35ccfc7484ef8a3fa2aff76bc3332c444e13b360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#	$OpenBSD: Makefile,v 1.12 2024/03/05 07:01:40 anton Exp $

.PHONY: setup-ftpd

REGRESS_TARGETS =	run-ftpd-get
REGRESS_TARGETS +=	run-ftpd-get-active
REGRESS_TARGETS +=	run-ftpd-put
REGRESS_TARGETS +=	run-ftpd-put-active
REGRESS_TARGETS +=	run-ftpd-ls
REGRESS_TARGETS +=	run-ftpd-nlist
REGRESS_TARGETS +=	run-ftpd-delete
REGRESS_TARGETS +=	run-ftpd-mkdir
REGRESS_TARGETS +=	run-ftpd-rename
REGRESS_TARGETS +=	run-ftpd-size
REGRESS_ROOT_TARGETS =	${REGRESS_TARGETS}
REGRESS_CLEANUP =	cleanup-ftpd
REGRESS_SETUP =		setup-ftpd
CLEANFILES =		ftpd.regress ftpd.regress.local

TCPSERVER =		/usr/local/bin/tcpserver
FTPD ?=			/usr/libexec/ftpd

FTPDIR != getent passwd ftp | cut -d: -f6

.if empty(FTPDIR)
regress:
	@echo user ftp is required in /etc/passwd for this regress
	@echo SKIPPED
.elif ! exists(${FTPDIR})
regress:
	@echo user ftp needs existing home directory ${FTPDIR} for this regress
	@echo SKIPPED
.endif

.if ! exists(${TCPSERVER})
regress:
	@echo package ucspi-tcp is required for this regress
	@echo SKIPPED
.endif

setup-ftpd:
	${SUDO} pkill tcpserver || true
	${SUDO} pkill ftpd || true
	nc 127.0.0.1 21 >/dev/null 2>&1 || true
	# start ftpd
	${SUDO} ${TCPSERVER} 127.0.0.1 21 ${KTRACE} ${FTPD} -A & \
	    timeout=$$(($$(date +%s) + 5)); \
	    while fstat -p $$! | ! grep -q 'tcp .* 127.0.0.1:21$$'; \
		do test $$(date +%s) -lt $$timeout || exit 1; done
	# prepare test files
	${SUDO} dd if=/dev/random of="${FTPDIR}/ftpd.regress" count=1 bs=1m
	${SUDO} chown ftp:ftp "${FTPDIR}/ftpd.regress"
	dd if=/dev/random of="ftpd.regress.local" count=1 bs=1m

run-ftpd-get:
	ftp_proxy= ftp -a ftp://127.0.0.1/ftpd.regress
	cmp ${FTPDIR}/ftpd.regress ftpd.regress
	rm ftpd.regress

run-ftpd-get-active:
	ftp_proxy= ftp -a -A ftp://127.0.0.1/ftpd.regress
	cmp ${FTPDIR}/ftpd.regress ftpd.regress
	rm ftpd.regress

run-ftpd-put:
	echo put ftpd.regress.local | ftp -a 127.0.0.1
	cmp ${FTPDIR}/ftpd.regress.local ftpd.regress.local
	${SUDO} rm ${FTPDIR}/ftpd.regress.local

run-ftpd-put-active:
	echo put ftpd.regress.local | ftp -a -A 127.0.0.1
	cmp ${FTPDIR}/ftpd.regress.local ftpd.regress.local
	${SUDO} rm ${FTPDIR}/ftpd.regress.local

run-ftpd-ls:
	echo ls | ftp -a 127.0.0.1 | grep -q 'ftpd.regress'

run-ftpd-nlist:
	echo nlist | ftp -a 127.0.0.1 | grep -q 'ftpd.regress'

run-ftpd-delete:
	echo delete ftpd.regress | ftp -a 127.0.0.1
	test ! -f ${FTPDIR}/ftpd.regress

run-ftpd-mkdir:
	echo mkdir ftpd.regress.dir.create | ftp -a 127.0.0.1
	test -d ${FTPDIR}/ftpd.regress.dir.create
	${SUDO} rm -r ${FTPDIR}/ftpd.regress.dir.create

run-ftpd-rename:
	echo rename ftpd.regress ftpd.regress.new | ftp -a 127.0.0.1
	test ! -f ${FTPDIR}/ftpd.regress
	test   -f ${FTPDIR}/ftpd.regress.new

run-ftpd-size:
	test $$(echo "binary\nsize ftpd.regress" | ftp -a 127.0.0.1 | cut -f 2)\
	    -eq $$(stat -f %z ${FTPDIR}/ftpd.regress)

cleanup-ftpd:
	${SUDO} pkill tcpserver || true
	${SUDO} pkill ftpd || true
	${SUDO} rm -f ${FTPDIR}/ftpd.regress

.include <bsd.regress.mk>