1#
2# Makefile - One-time password login system
3#
4# Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/>
5#
6
7VERSION=1.5
8
9CC=gcc
10CFLAGS+=-fPIC
11
12%.gz: %
13	gzip -9c $< >$@
14
15TARGETS=otpw-gen pam_otpw.so pam_otpw.8.gz otpw-gen.1.gz
16
17all: $(TARGETS)
18
19otpw-gen: otpw-gen.o rmd160.o md.o otpw.o
20	$(CC) -o $@ $+
21demologin: demologin.o otpw.o rmd160.o md.o
22	$(CC) -o $@ $+ -lcrypt
23
24otpw-gen.o: otpw-gen.c md.h otpw.h
25otpw.o: otpw.c otpw.h md.h
26md.o: md.c md.h rmd160.h
27rmd160.o: rmd160.c rmd160.h
28otpw-l.o: otpw-l.c otpw.c otpw.h md.h
29pam_otpw.o: pam_otpw.c otpw.h md.h
30pam_otpw.so: pam_otpw.o otpw-l.o rmd160.o md.o
31	${LD} --shared -o $@ $+ -lcrypt -lpam
32
33distribution:
34	git archive --prefix otpw-$(VERSION)/ -o otpw-$(VERSION).tar.gz v$(VERSION)
35
36release:
37	git diff --exit-code v$(VERSION) -- otpw.html
38	rsync -t otpw-$(VERSION).tar.gz $(HOME)/public_html/download/
39	rsync -t otpw.html $(HOME)/public_html/
40
41#PAMLIB=/lib/security
42PAMLIB=/lib/x86_64-linux-gnu/security
43
44install: install-pam install-gen
45
46install-pam: pam_otpw.so pam_otpw.8.gz
47	rsync -t pam_otpw.so $(PAMLIB)/
48	rsync -t pam_otpw.8.gz /usr/share/man/man8/
49	perl -i.bak -pe 's/^(\@include common-auth)$$/\# $$1\nauth required pam_otpw.so/' /etc/pam.d/sshd
50	perl -i.bak -pe 's/^(ChallengeResponseAuthentication\s+)no$$/$$1yes/' \
51	  /etc/ssh/sshd_config
52	killall -SIGHUP sshd
53
54install-gen: otpw-gen otpw-gen.1.gz
55	rsync -t otpw-gen /usr/bin/
56	rsync -t otpw-gen.1.gz /usr/share/man/man1/
57	-getent passwd otpw && \
58	  chown otpw /usr/bin/otpw-gen && chmod u+s /usr/bin/otpw-gen
59
60install-pseudouser:
61	adduser --system --gecos 'Pseudouser for storing one-time password files' --home /var/lib/otpw otpw
62
63uninstall-pseudouser:
64	deluser --remove-home otpw
65
66uninstall:
67	rm -f $(PAMLIB)/pam_otpw.so /usr/share/man/man8/pam_otpw.8.gz
68	rm -f /usr/bin/otpw-gen /usr/share/man/man1/otpw-gen.1.gz
69
70clean:
71	rm -f $(TARGETS) *~ *.o core
72
73test-login:
74	ssh -o PreferredAuthentications=keyboard-interactive localhost
75