122347Spst##
222347Spst# Makefile.source and Makefile: Directions for building and installing OPIE.
322347Spst#
429964Sache# %%% portions-copyright-cmetz-96
592906Smarkm# Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
622347Spst# Reserved. The Inner Net License Version 2 applies to these portions of
722347Spst# the software.
822347Spst# You should have received a copy of the license with this software. If
922347Spst# you didn't get a copy, you may request one from <license@inner.net>.
1022347Spst#
1122347Spst# Portions of this software are Copyright 1995 by Randall Atkinson and Dan
1222347Spst# McDonald, All Rights Reserved. All Rights under this copyright are assigned
1322347Spst# to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and   
1422347Spst# License Agreement applies to this software.   
1522347Spst#
1622347Spst#	History:
1722347Spst#
1892906Smarkm#	Modified by cmetz for OPIE 2.4. Add libmissing to include header path.
1992906Smarkm#		Renamed realclean to distclean. Added opieauto rules. Made
2092906Smarkm#		system program install more tolerant of non-existent files.
2129964Sache#	Modified by cmetz for OPIE 2.31. Moved logwtmp.o into libopie.
2222347Spst#	Modified by cmetz for OPIE 2.3. Removed manual config -- it's
2322347Spst#		Autoconf or bust. Replaced user configuration options
2422347Spst#		with options.h. Eliminated unused variables. Pass down
2522347Spst#		$(DEBUG) instead of several other variables to the
2622347Spst#		subdirs. Extended/standard key file support. Added
2722347Spst#		dependencies on subdir files. Made opietest call silent.
2822347Spst#		Removed opie-md4, opie-md5, and key aliases. Removed
2922347Spst#		test target. Make uninstall remove man page aliases.
3022347Spst#	Modified by cmetz for OPIE 2.22. Removed @LIBOBJS@ from MISSING for
3122347Spst#		Autoconf target. Re-ordered LFLAGS because some ld's won't
3222347Spst#		include libmissing properly if it's not at the end.
3322347Spst#       Modified by cmetz for OPIE 2.21. Added getusershell.o to IRIX
3422347Spst#               missing functions.
3522347Spst#       Modified by cmetz for OPIE 2.2. Added NEW_PROMPTS definition.
3622347Spst#               Added MISSING and new flags-passing for libmissing.
3722347Spst#               Quote MISSING or lose. Update TEST target for FTPD
3822347Spst#               variable. Removed line formatting for compile commands
3922347Spst#               since macro expansion confuses the issue anyway.
4022347Spst#               Added targets for opieserv. Added targets for opietest.
4122347Spst#               Removed obselete options.h target. Swapped libmissing
4222347Spst#               and libopie. Updated manual config options. Added more
4322347Spst#               explanatory text. Fixed uses of old SYSV and BSD4_3
4422347Spst#               symbols.
4522347Spst#       Modified at NRL for OPIE 2.2: Renamed LDFLAGS setting to LIBS,
4622347Spst#               renamed LDFLAGS in targets to LFLAGS. Added targets for
4722347Spst#               libopie and libmissing directories. Got rid of PROTOTYPES.
4822347Spst#               Added opiegen. Fixed RANLIB Autoconf target. 
4922347Spst#       Modified at NRL for OPIE 2.11: Fixed fatal mistype of Autoconf.
5022347Spst#	Modified at NRL for OPIE 2.1: Changed targets to reflect source
5122347Spst#		file name changes. Changed explanation and flags for static
5222347Spst#		linking. Changed opieinfo target. Removed WHOAMI. Added
5322347Spst#		Autoconf targets. Changed if conditionals to use test
5422347Spst#               instead of [. Changed SU_DIR to SU to help autoconf.
5522347Spst#               Changed FTPDIR and FTPDNAME to FTPD to help autoconf.
5622347Spst#               Changed HP-UX to HP-UX9 and HP-UX10. Make uninstall
5722347Spst#               target depend on config. HPUX *is* no longer necessary, but
5822347Spst#               something does have to be there. Sub in Autoconf @CC@.
5922347Spst#       Modified at NRL for OPIE 2.04: Re-worded explanation of SU_STAR_CHECK.
6022347Spst#       Modified at NRL for OPIE 2.02: Added SU_STAR_CHECK flag.
6122347Spst#       Modified at NRL for OPIE 2.01: Test target makes opiesu and opielogin 
6222347Spst#               setuid. install target clears that. uninstall target needs to
6322347Spst#               remove the opiekey symlinks. opieinfo target needs to 
6422347Spst#               substitute for $(EXISTS). ifdefs target needs to check for 
6522347Spst#               starting hash. $(LFLAGS) and -o should be at the end of all 
6622347Spst#               link commands to spoon-feed drain bamaged link editors. Added
6722347Spst#               A/UX defaults.
6822347Spst#	Modified heavily at NRL for OPIE 2.0.
6922347Spst#	Written at Bellcore for the S/Key Version 1 software distribution
7022347Spst#		(Makefile).
7122347Spst
7222347Spst#============================================================================
7322347Spst# CONFIGURATION PARAMETERS -- CHANGE THESE TO SUIT YOUR MACHINE
7422347Spst
7522347Spst# Shell to use for make(1)
7622347Spst# It's usually a good idea to leave this as-is. On some systems, ksh or bash
7722347Spst# may be necessary
7822347SpstSHELL=/bin/sh
7922347Spst
8022347Spst# OWNER is the username who should own the OPIE binaries.
8122347Spst# GROUP is the groupname associated with the OPIE binaries.
8222347Spst#
8322347SpstOWNER=0
8422347SpstGROUP=bin
8522347Spst
8692906Smarkm# Where should the OPIE standard and extended databases be stored?
8722347Spst#
8892906Smarkm# Some sites might want to put this elsewhere. If you want to use an old
8922347Spst# S/Key database, you should create a link from /etc/skeykeys to /etc/opiekeys.
9029964SacheKEY_FILE=/etc/opiekeys
9122347Spst
9222347Spst# Are we debugging?
9322347Spst#
9422347Spst# The first line will build a normal version of OPIE. You should use it.
9522347Spst#
9622347Spst# The second is for brave souls porting OPIE to a new system or trying to
9722347Spst# debug it and should definitely NOT be used to build a production copy
9822347Spst# of OPIE. 
9922347Spst#
10022347Spst# The third is the above using nifty heap debugger called "Electric Fence".
10122347SpstDEBUG=-O
10222347Spst#DEBUG=-DDEBUG=1 -g
10322347Spst#DEBUG=-DDEBUG=1 -g -lefence
10422347Spst
10522347Spst# These parameters are determined by Autoconf and are probably correct.
10622347Spst# If OPIE doesn't build or work right, try tweaking these.
10722347SpstCC=@CC@
10822347SpstYACC=@YACC@
10922347SpstFTPD=@FTPD@
11022347SpstLIBS=@LIBS@
11122347SpstOPTIONS=@DEFS@
11222347SpstEXISTS=@EXISTS@
11322347SpstMKDIR=@MKDIR@
11422347SpstCHOWN=@CHOWN@
11522347SpstLOCALBIN=@LOCALBIN@
11622347SpstLOCALMAN=@LOCALMAN@
11722347SpstSU=@SU@
11822347SpstALT_SU=@ALT_SU@
11922347SpstLOGIN=@LOGIN@
12029964SacheLOCK_DIR=@LOCK_DIR@
12192906SmarkmOPIEAUTO=@OPIEAUTO@
12222347Spst
12322347SpstBACKUP=opie.old
12422347Spst
12592906SmarkmCFLAGS=$(DEBUG) -Ilibmissing
12622347Spst
12722347SpstLFLAGS=-Llibopie -Llibmissing -lopie $(LIBS) -lmissing -lopie
12822347SpstLDEPS=libmissing/libmissing.a libopie/libopie.a
12922347Spst
13022347Spstall:	client server
13122347Spst
13222347Spstifdefs:	
13322347Spst	egrep '^#*if*def' *.c *.h | cut -f2 -d: | sort | uniq
13422347Spst
13592906Smarkmclient: libopie/libopie.a libmissing/libmissing.a opietest-passed opiekey opiegen $(OPIEAUTO)
13622347Spst
13722347Spstclient-install: client
13822347Spst	@echo "Installing OPIE client software..."
13922347Spst	@echo "Copying OPIE key-related files"
14022347Spst	@if test ! -d $(LOCALBIN); then $(MKDIR) $(LOCALBIN); chmod 755 $(LOCALBIN); fi 
14192906Smarkm	@cp opiekey $(OPIEAUTO) $(LOCALBIN)
14222347Spst	@$(CHOWN) $(OWNER) $(LOCALBIN)/opiekey
14392906Smarkm	@if test ! -z "$(OPIEAUTO)"; then $(CHOWN) $(OWNER) $(LOCALBIN)/opieauto; fi
14422347Spst	@chgrp $(GROUP) $(LOCALBIN)/opiekey
14522347Spst	@echo "Changing file permissions"
14622347Spst	@chmod 0511 $(LOCALBIN)/opiekey
14792906Smarkm	@if test ! -z "$(OPIEAUTO)"; then chmod 0511 $(LOCALBIN)/opieauto; fi
14822347Spst	@echo "Symlinking aliases to opiekey"
14922347Spst	@-ln -s $(LOCALBIN)/opiekey $(LOCALBIN)/otp-md4
15022347Spst	@-ln -s $(LOCALBIN)/opiekey $(LOCALBIN)/otp-md5
15122347Spst	@echo "Installing manual pages"
15222347Spst	@-for i in otp-md4 otp-md5; do ln -s opiekey.1 $(LOCALMAN)/man1/$$i.1; done
15322347Spst	@if test ! -d $(LOCALMAN)/man1; then $(MKDIR) $(LOCALMAN)/man1; chmod 755 $(LOCALMAN)/man1; fi; cp opiekey.1 $(LOCALMAN)/man1/opiekey.1; $(CHOWN) $(OWNER) $(LOCALMAN)/man1/opiekey.1; chgrp $(GROUP) $(LOCALMAN)/man1/opiekey.1; chmod 644 $(LOCALMAN)/man1/opiekey.1
15422347Spst
15522347Spstserver:	libopie/libopie.a libmissing/libmissing.a opietest-passed opielogin opiesu opiepasswd opieinfo opieftpd opieserv
15622347Spst
15722347Spstserver-install: server
15822347Spst	@echo "Installing OPIE server software..."
15922347Spst	@echo "Copying OPIE user programs"
16022347Spst	@if test ! -d $(LOCALBIN); then $(MKDIR) $(LOCALBIN); chmod 755 $(LOCALBIN); fi 
16122347Spst	@cp opiepasswd opieinfo $(LOCALBIN)
16222347Spst	@echo "Changing ownership"
16322347Spst	@$(CHOWN) $(OWNER) $(LOCALBIN)/opiepasswd $(LOCALBIN)/opieinfo
16422347Spst	@chgrp $(GROUP) $(LOCALBIN)/opiepasswd $(LOCALBIN)/opieinfo
16522347Spst	@echo "Changing file permissions"
16622347Spst	@chmod 0555 $(LOCALBIN)/opieinfo
16722347Spst	@chmod 4511 $(LOCALBIN)/opiepasswd
16822347Spst	@echo "Installing OPIE system programs..."
16992906Smarkm	@if test ! -z $(LOGIN); \
17092906Smarkm	then \
17192906Smarkm		if test ! $(EXISTS) $(LOGIN).$(BACKUP); \
17292906Smarkm		then \
17392906Smarkm			echo "Renaming existing $(LOGIN) to $(LOGIN).$(BACKUP)"; \
17492906Smarkm			mv $(LOGIN) $(LOGIN).$(BACKUP); \
17592906Smarkm			echo "Clearing permissions on $(LOGIN)"; \
17692906Smarkm			chmod 0 $(LOGIN).$(BACKUP); \
17792906Smarkm		fi; \
17892906Smarkm		echo "Copying OPIE login to $(LOGIN)"; \
17992906Smarkm		cp opielogin $(LOGIN); \
18092906Smarkm		echo "Changing ownership of $(LOGIN)"; \
18192906Smarkm		$(CHOWN) $(OWNER) $(LOGIN); \
18292906Smarkm		chgrp $(GROUP) $(LOGIN); \
18392906Smarkm		echo "Changing file permissions of $(LOGIN)"; \
18492906Smarkm		chmod 4111 $(LOGIN); \
18592906Smarkm	fi
18692906Smarkm	@if test ! -z $(SU); \
18792906Smarkm	then \
18892906Smarkm		if test ! $(EXISTS) $(SU).$(BACKUP); \
18992906Smarkm		then \
19092906Smarkm			echo "Renaming existing $(SU) to $(SU).$(BACKUP)"; \
19192906Smarkm			mv $(SU) $(SU).$(BACKUP); \
19292906Smarkm			echo "Clearing permissions on $(SU)"; \
19392906Smarkm			chmod 0 $(SU).$(BACKUP); \
19492906Smarkm		fi; \
19592906Smarkm		echo "Copying OPIE su to $(SU)"; \
19692906Smarkm		cp opiesu $(SU); \
19792906Smarkm		echo "Changing ownership of $(SU)"; \
19892906Smarkm		$(CHOWN) $(OWNER) $(SU); \
19992906Smarkm		chgrp $(GROUP) $(SU); \
20092906Smarkm		echo "Changing file permissions of $(SU)"; \
20192906Smarkm		chmod 4111 $(SU); \
20292906Smarkm	fi
20392906Smarkm	@if test ! -z $(ALT_SU); \
20492906Smarkm	then \
20592906Smarkm		if test ! $(EXISTS) $(ALT_SU).$(BACKUP); \
20692906Smarkm		then \
20792906Smarkm			echo "Renaming existing $(ALT_SU) to $(ALT_SU).$(BACKUP)"; \
20892906Smarkm			mv $(ALT_SU) $(ALT_SU).$(BACKUP); \
20992906Smarkm			echo "Clearing permissions on $(ALT_SU)"; \
21092906Smarkm			chmod 0 $(ALT_SU).$(BACKUP); \
21192906Smarkm		fi; \
21292906Smarkm		echo "Copying OPIE su to $(ALT_SU)"; \
21392906Smarkm		cp opiesu $(ALT_SU); \
21492906Smarkm		echo "Changing ownership of $(ALT_SU)"; \
21592906Smarkm		$(CHOWN) $(OWNER) $(ALT_SU); \
21692906Smarkm		chgrp $(GROUP) $(ALT_SU); \
21792906Smarkm		echo "Changing file permissions of $(ALT_SU)"; \
21892906Smarkm		chmod 4111 $(ALT_SU); \
21992906Smarkm	fi
22092906Smarkm	@if test ! -z $(FTPD); \
22192906Smarkm	then \
22292906Smarkm		if test ! $(EXISTS) $(FTPD).$(BACKUP); \
22392906Smarkm		then \
22492906Smarkm			echo "Renaming existing $(FTPD) to $(FTPD).$(BACKUP)"; \
22592906Smarkm			mv $(FTPD) $(FTPD).$(BACKUP); \
22692906Smarkm			echo "Clearing permissions on $(FTPD).$(BACKUP)"; \
22792906Smarkm			chmod 0 $(FTPD).$(BACKUP); \
22892906Smarkm		fi; \
22992906Smarkm		echo "Copying OPIE ftp daemon to $(FTPD)"; \
23092906Smarkm		cp opieftpd $(FTPD); \
23192906Smarkm		echo "Changing ownership of $(FTPD)"; \
23292906Smarkm		$(CHOWN) $(OWNER) $(FTPD); \
23392906Smarkm		chgrp $(GROUP) $(FTPD); \
23492906Smarkm		echo "Changing file permissions of $(FTPD)"; \
23592906Smarkm		chmod 0100 $(FTPD); \
23692906Smarkm	fi
23792906Smarkm	@echo "Making sure OPIE database file exists";
23829964Sache	@touch $(KEY_FILE)
23929964Sache	@echo "Changing permissions of OPIE database file"
24029964Sache	@chmod 0644 $(KEY_FILE)
24129964Sache	@echo "Changing ownership of OPIE database file"
24229964Sache	@$(CHOWN) $(OWNER) $(KEY_FILE)
24329964Sache	@chgrp $(GROUP) $(KEY_FILE)
24429964Sache	@-if test ! -z "$(LOCK_DIR)"; then echo "Creating OPIE lock directory"; mkdir $(LOCK_DIR); $(CHOWN) 0 $(LOCK_DIR); chgrp 0 $(LOCK_DIR); chmod 0700 $(LOCK_DIR); fi;
24529964Sache	@-if test ! -z "$(ACCESS_FILE)"; then echo "Creating OPIE access file (don't say we didn't warn you)"; touch $(ACCESS_FILE); $(CHOWN) 0 $(ACCESS_FILE); chgrp 0 $(ACCESS_FILE); chmod 0444 $(ACCESS_FILE); fi;
24622347Spst	@echo "Installing manual pages"
24722347Spst	@if test ! -d $(LOCALMAN); then $(MKDIR) $(LOCALMAN); chmod 755 $(LOCALMAN); fi
24822347Spst	@for i in 1 4 5 8; do for j in *.$$i; do if test ! -d $(LOCALMAN)/man$$i; then $(MKDIR) $(LOCALMAN)/man$$i; chmod 755 $(LOCALMAN)/man$$i; fi; cp $$j $(LOCALMAN)/man$$i/$$j; $(CHOWN) $(OWNER) $(LOCALMAN)/man$$i/$$j; chgrp $(GROUP) $(LOCALMAN)/man$$i/$$j; chmod 644 $(LOCALMAN)/man$$i/$$j; done; done
24922347Spst	@echo "REMEMBER to run opiepasswd on your users immediately."
25022347Spst
25122347Spstinstall: client-install server-install
25222347Spst
25322347Spstuninstall:
25422347Spst	@echo "Un-installing OPIE..."
25522347Spst	@echo "Removing symlinks"
25622347Spst	@-for i in otp-md4 otp-md5; do rm $(LOCALBIN)/$$i; done
25722347Spst	@echo "Removing OPIE programs"
25822347Spst	@-for i in opiekey opiepasswd opieinfo; do rm $(LOCALBIN)/$$i; done
25922347Spst	@echo "Removing OPIE manual pages"
26022347Spst	@-for i in 1 4 5 8; do for j in *.$$i; do rm $(LOCALMAN)/man$$i/$$j; done; done
26122347Spst	@-rm $(LOCALMAN)/man1/otp-md4.1 $(LOCALMAN)/man1/otp-md5.1
26222347Spst	@echo "Restoring old binaries"
26322347Spst	@-for i in $(SU) $(ALT_SU) $(LOGIN) $(FTPD); do FILE=`basename $$i`; if test ! $(EXISTS) $$i.$(BACKUP); then echo "No $$i.$(BACKUP)! Aborting."; exit 1; else echo "Removing $$FILE"; rm $$i || true; echo "Restoring old $$FILE"; mv $$i.$(BACKUP) $$i; fi; done
26422347Spst	@echo "Resetting permissions"
26522347Spst	@chmod 4111 $(SU) $(LOGIN)
26622347Spst	@chmod 0100 $(FTPD)
26722347Spst	@if test ! -z "$(ALT_SU)"; then chmod 4111 $(ALT_SU); fi
26822347Spst	@echo "OPIE is now un-installed."
26922347Spst	@echo "Please verify by hand that this process worked."
27022347Spst
27122347Spstopietest-passed:	opietest
27222347Spst	-./opietest && touch opietest-passed
27322347Spst
27422347Spstlibopie/libopie.a: libopie/*.c *.h
27529964Sache	(cd libopie ; $(MAKE) libopie.a CFL='$(CFLAGS) -DKEY_FILE=\"$(KEY_FILE)\"')
27622347Spst
27722347Spstlibmissing/libmissing.a: libmissing/*.c
27822347Spst	(cd libmissing ; $(MAKE) libmissing.a CFL='$(CFLAGS)')
27922347Spst
28022347Spstclean:
28122347Spst	-rm -f *.o opiekey opiegen opielogin opiepasswd opiesu opieftpd
28292906Smarkm	-rm -f opieserv opieinfo opietest opieauto *core* opietest-passed
28322347Spst	-rm -f Makefile.munge configure.munger y.tab.c .gdb*
28422347Spst	(cd libopie ; $(MAKE) clean)
28522347Spst	(cd libmissing ; $(MAKE) clean)
28622347Spst
28792906Smarkmrealclean: distclean
28892906Smarkm
28992906Smarkmdistclean: clean
29022347Spst	-rm -f *~ core* "\#*\#" Makefile make.log
29122347Spst	-rm -f config.log config.status config.cache config.h
29292906Smarkm	(cd libopie ; $(MAKE) distclean)
29392906Smarkm	(cd libmissing ; $(MAKE) distclean)
29422347Spst
29522347Spstopiekey:	opiekey.o $(LDEPS)
29622347Spst		$(CC) $(CFLAGS) opiekey.o $(LFLAGS) -o opiekey
29722347Spst
29822347Spstopiegen:	opiegen.o $(LDEPS)
29922347Spst		$(CC) $(CFLAGS) opiegen.o $(LFLAGS) -o opiegen
30022347Spst
30122347Spstopieserv:	opieserv.o $(LDEPS)
30222347Spst		$(CC) $(CFLAGS) opieserv.o $(LFLAGS) -o opieserv
30322347Spst
30429964Sacheopieftpd:	opieftpd.o glob.o popen.o y.tab.o $(LDEPS)
30529964Sache		$(CC) $(CFLAGS) opieftpd.o glob.o popen.o y.tab.o $(LFLAGS) -o opieftpd
30622347Spst
30722347Spstopielogin:	opielogin.o permsfile.o $(LDEPS)
30822347Spst		$(CC) $(CFLAGS) opielogin.o permsfile.o $(LFLAGS) -o opielogin
30922347Spst
31022347Spstopiepasswd:	opiepasswd.o $(LDEPS)
31122347Spst		$(CC) $(CFLAGS) opiepasswd.o $(LFLAGS) -o opiepasswd
31222347Spst
31322347Spstopiesu:		opiesu.o $(LDEPS)
31422347Spst		$(CC) $(CFLAGS) opiesu.o $(LFLAGS) -o opiesu
31522347Spst
31622347Spsty.tab.c:	ftpcmd.y
31722347Spst		$(YACC) ftpcmd.y
31822347Spst
31922347Spstopieinfo:	opieinfo.o $(LDEPS)
32022347Spst		$(CC) $(CFLAGS) opieinfo.o $(LFLAGS) -o opieinfo
32122347Spst
32222347Spstopietest:	opietest.o $(LDEPS)
32322347Spst		$(CC) $(CFLAGS) opietest.o $(LFLAGS) -o opietest
32492906Smarkm
32592906Smarkmopieauto:	opieauto.o $(LDEPS)
32692906Smarkm		$(CC) $(CFLAGS) opieauto.o $(LFLAGS) -o opieauto
32792906Smarkm
328