
#######
# Where the executable goes
BINDIR=/usr/local/bin

#######
# Man pages

# Directory for super(1) and setuid(1) man pages
MANDIR=/usr/local/man/man1

# Extension on the super(1) and setuid(1) man pages
MANEXT=1

# Directory for the man page describing the format of the super.tab file.
# Note: file formats usually go into section 4 (SysV) or section 5 (BSD).
MAN_FMT_DIR=/usr/local/man/man4

# Extension on the super.tab format man page.
MAN_FMT_EXT=4

#######
# CONFIG_FLAGS

#   1. USE_NETGROUP: This indicates whether the hostname "+xxx" should mean
#	any host in netgroup "xxx"; e.g. `joe@+xyz' means allow
#	joe to execute the command from any host in NIS netgroup xyz.
#	If USE_NETGROUP is not defined, `joe@+xyz' means joe at host `+xyz'.
#	(Netgroups are typically defined in /etc/netgroup on your NIS master.)

#   2. USE_SYSLOG: This indicates whether the error-message printing routine
#	should be compiled with the option of calling syslog().  You should
#	define this if you have syslog() available.  The actual printing to
#	syslog at runtime is controlled by the global option syslog=y|n.
#	See also SYSLOG_PRIORITY, below.

#   3. MAXFD: if you don't have the system call getdtablesize() to return the
#	number of file descriptors, define
#		MAXFD=<expression to give max ok value of a file descr>.
#	If MAXFD is not defined, getdtablesize() is used.
#	Examples: 	-DMAXFD=63	-- hardwired for 64 max descriptors;
#			-DMAXFD="sysconf(_SC_OPEN_MAX)-1" -- HP-UX 8.x, 9.x

#   4. SUPERFILE: if you want the superfile to be other than
#	/usr/local/lib/super.tab, add -DSUPERFILE=\"FullPathName\"

#   5. SAFE_PATH: this is the setting of the PATH variable for any command
#	executed by super.  The default is "/bin:/usr/bin:/usr/ucb".
#	If you prefer a different path, add -DSAFE_PATH=\"MyPreferredPath\",
#	and change the description of PATH in the man page to match.

#   6. TIMESTAMP_DIR: This is the directory in which timestamp files are
#	kept for commands requiring passwords to be entered.  The default
#	is "/usr/local/lib/superstamps".  If you prefer a different path,
#	add -DTIMESTAMP_DIR=\"/My/Preferred/Directory\".

#   7. L14: define this if your filenames can only be 14 characters long.
#	Timestamp filenames usually look like hostname/user; with this option,
#	the hostname part is truncated to 14 characters.

#   8. INTERPRETER_HACK: If your execve() function doesn't support the
#	"#!" hack, in which executable scripts beginning
#		"#! interpreter [arg]"
#	are automatically passed to the interpreter, define -DINTERPRETER_HACK.
#	Super will include code to implement "#!" processing.

#   9. USE_GETHOSTBYNAME: If you have a nameserver, you should enable
#	this, which does the following:  If super tries and fails to match
#	the hostname (as returned by gethostname()), it will try removing
#	trailing components of the fully-qualified hostname and seeing if
#	they match the host pattern.

#   12. ONETRUENAME: the name under which the program assumes it is installed.
#	If argv[0] isn't [/.../]ONETRUENAME, we assume we're running via
#	symlink, and act as if `super xxx args' had been typed instead of
#	`super args', where xxx is argv[0].  The default is "super", and
#	you should _not_ change this without a good reason!

#   13. RLOG_MACHINE: If you enable the use of syslog() (-DUSE_SYSLOG),
#	by default standard syslog() calls will be used.  But you also have
#	the option of using rsyslog(), which will direct the syslog messages to
#	a host on your network.  If you want to use rsyslog(), then you
#	must define RLOG_MACHINE, and you should also define SYSLOG_PRIORITY
#	(see following item).  RLOG_MACHINE specifies the machine
#	which will receive the networked syslog messages.  For example:
#		-DRLOG_MACHINE=\"toto.domain\"
#	(If you distribute this code, be careful to remove the name of
#	your collecting machine from this Makefile.  Note that the "make
#	shar" command, below, will strip this for you.).

#   14. SYSLOG_PRIORITY: This variable specifies the priority of syslog
#	messages.  If you don't define it, the default is LOG_ERR.
#	(Regardless of this setting, _successful_ executions are logged
#	at priority LOG_INFO.)

#	If you are using standard syslog(), you may define it symbolically,
#	for example:
#		-DSYSLOG_PRIORITY=LOG_ERR
#	or
#		-DSYSLOG_PRIORITY="(LOG_LOCAL1 | LOG_WARNING)"

#	But if you are using rsyslog(), you should define it differently:
#	its value depends on the machine which will _receive_ the log
#	messages, NOT the sending machine.  It should be defined in the
#	Makefile because the value can differ on the machine that compiles
#	and runs super, compared to the value on the log host.

#	For example, if your receiving machine is a Sun running SunOS 4.1.3,
#	or HP-UX 8.x or 9.x, using -DRLOG_PRIORITY='((17<<3)+4)' will set
#	the priority of the networked syslog to the facility LOG_LOCAL1, with
#	the priority LOG_WARNING.  The log machine should have a line that
#	matches this in its syslog.conf file; for the above priority, use
#	an entry like:
#		/etc/syslog.conf:local1.warning        /var/adm/super.log

#   15. NEED_MEMSET: This indicates whether you have a memset() routine.
#	If you don't, define -DNEED_MEMSET and one will be compiled for you.

#   16. NEED_STRTOL: This indicates whether you have the strtol() function.
#	If you don't, define -DNEED_STRTOL and one will be compiled for you.

#   17. HAVE_LOCALE: Define this if you have <locale.h> and setlocale().

#   18. HAVE_LOCALTIME: Define this if you have localtime().

#   19. NEED_STRERROR: Define this if your system doesn't have strerror().

#   20. NEED_SYS_ERRLIST: If you don't have strerror() -- i.e. if you have
#	defined NEED_STRERROR -- then define this if you _don't_ have
#	sys_errlist[] _and_ sys_nerr.

# *************************************************
# NOTE: AT THIS WRITING, THE CONFIGURATIONS HAVE ONLY BEEN
# TESTED WITH SUPER 3.9 ON:
#	SUNOS 4.3.x
#	SUNOS 5.4, 5.5
#	Digital UNIX 3.2
#	HP-UX 9.x
# SOME OF THE OTHER SETTINGS ARE +++ GUESSES +++
# *************************************************

# AIX:
#CONFIG_FLAGS= \
#	-DUSE_NETGROUP \
#	-DMAXFD="sysconf(_SC_OPEN_MAX)-1" \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DUSE_SYSLOG \
#	-DUSE_GETHOSTBYNAME \
#	-DRLOG_MACHINE=\"toto.domain\" -DSYSLOG_PRIORITY='((17<<3)+4)'

# Clix 3.1 r.7.1.3 (Intergraph)
#CONFIG_FLAGS= \
#	-DUSE_NETGROUP \
#	-DINTERPRETER_HACK \
#	-DNEED_MEMSET \
#	-DNEED_STRTOL

# Digital UNIX
# (a.k.a DEC OSF/1 prior to Digital UNIX V3.2)
#CONFIG_FLAGS= \
#	-DUSE_NETGROUP \
#	-DMAXFD="sysconf(_SC_OPEN_MAX)-1" \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DUSE_SYSLOG \
#	-DUSE_GETHOSTBYNAME

# HP-UX 9.01:
CONFIG_FLAGS= \
	-DUSE_NETGROUP \
	-DMAXFD="sysconf(_SC_OPEN_MAX)-1" \
	-DHAVE_LOCALTIME \
	-DHAVE_LOCALE \
	-DUSE_SYSLOG \
	-DUSE_GETHOSTBYNAME \
	-DRLOG_MACHINE=\"toto.domain\" -DSYSLOG_PRIORITY='((17<<3)+4)'

# IRIX v4.0.5:
#CONFIG_FLAGS= \
#	-DUSE_NETGROUP \
#	-DUSE_SYSLOG \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DUSE_GETHOSTBYNAME \
#	-DSAFE_PATH=\"/bin:/usr/bin:/usr/bsd\"  

# IRIX v5.3:
#CONFIG_FLAGS= \
#	-DUSE_NETGROUP \
#	-DUSE_SYSLOG \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DUSE_GETHOSTBYNAME \
#	-DSAFE_PATH=\"/bin:/usr/bin:/usr/bsd\"  

# Linux v1.2:
#CONFIG_FLAGS= \
#	-DSAFE_PATH=\"/bin:/usr/bin\" \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DUSE_SYSLOG \
#	-DUSE_GETHOSTBYNAME \
#	-DSYSLOG_FACILITY=LOG_AUTH \
#	-DSYSLOG_PRIORITY=LOG_INFO \

# SCO 3.2v4
#CONFIG_FLAGS= \
#	-DHAVE_LOCALTIME \
#	-DUSE_SYSLOG


# Solaris 2.x:
#CONFIG_FLAGS= \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DUSE_NETGROUP \
#	-DUSE_SYSLOG \
#	-DUSE_GETHOSTBYNAME \
#	-DMAXFD="sysconf(_SC_OPEN_MAX)-1" \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE
   
# SunOS 4.1.3:  explicitly put in HAVE_LOCALTIME in case you are
# compiling with the bundled cc, which isn't STD C, but does have
# the localtime() function.
#CONFIG_FLAGS= \
#	-DUSE_NETGROUP \
#	-DUSE_SYSLOG \
#	-DHAVE_LOCALTIME \
#	-DHAVE_LOCALE \
#	-DNEED_STRERROR \
#	-DUSE_GETHOSTBYNAME

# TI SYSV 3.3:
#CONFIG_FLAGS= \
#	-DMAXFD=63 \
#	-DUSE_SYSLOG \
#	-DL14 \
#	-DUSE_GETHOSTBYNAME \
#	-DINTERPRETER_HACK \
#	-DHAVE_LOCALTIME \
#	-DNEED_STRERROR \
#	-DNEED_SYS_ERRLIST

# Ultrix V4.3A:
#CONFIG_FLAGS= \
#	-DUSE_GETHOSTBYNAME \
#	-DHAVE_LOCALTIME \
#	-DUSE_SYSLOG

# UnixWare 2.0:
#CONFIG_FLAGS= \
#	-DHAVE_LOCALTIME \
#	-DUSE_SYSLOG

# #####
# C compiler and CFLAGS

# AIX
# CC=cc
# CFLAGS= -O -D_ALL_SOURCE $(CONFIG_FLAGS)

# Clix 3.1 r.7.1.3 (Intergraph)
# CC=cc
# CFLAGS=  -O $(CONFIG_FLAGS)

# Digital UNIX
# (known as DEC OSF/1 prior to Digital UNIX V3.2)
#
# If you are running V2.0 to V3.2, and you have the DEC C
# compiler installed, you should add -migrate to CFLAGS.
# CC=cc
# CFLAGS= -std -migrate -DDigital_UNIX $(CONFIG_FLAGS)
# CFLAGS= -std -DDigital_UNIX $(CONFIG_FLAGS)

# HP-UX 9.01:
#    Note: unpatched HP-UX 9.01 c89 has a bug, so that compiling with -O
#    doesn't work.  Patched version is OK.
CC=c89
CFLAGS= -g -Aa -D_HPUX_SOURCE $(CONFIG_FLAGS)

# IRIX v4.0.5:
# CC=cc
# CFLAGS= -O -DUSE_NETGROUP $(CONFIG_FLAGS)

# Linux v1.2:
# CC=gcc
# CFLAGS= -O2

# SCO 3.2v4
# CC=cc
# CFLAGS= -O -DSCO $(CONFIG_FLAGS)

# Solaris 2.2, 2.3; SunOS 5.2, 5.3, gcc:
# CC=gcc
# CFLAGS= -O -DSUNOS5 $(CONFIG_FLAGS)

# Solaris 2.4; SunOS 5.4, gcc 2.7.1:
# CC=gcc
# CFLAGS= -O -DSUNOS5_4 $(CONFIG_FLAGS)

# Solaris 2.4; SunOS 5.4; Sun 3.0.1 C compiler:
# CC=??? (sorry, don't know its name)
# CFLAGS= -O -Xc -DSUNOS5_4 -D_POSIX_C_SOURCE -D__EXTENSIONS__ $(CONFIG_FLAGS)

# SunOS 4.1.3:
# CC=gcc
# CFLAGS= -O $(CONFIG_FLAGS)

# TI SYS V 3.3:
# CC=gcc
# CFLAGS=-O $(CONFIG_FLAGS) -traditional

# Ultrix V4.3A
# CC=cc
# CFLAGS= -g3 -O $(CONFIG_FLAGS)

# UnixWare 2.0:
# CC=cc
# CFLAGS= -O

#######
# LDFLAGS,LDLIBS

# Default:
# LDFLAGS=
# LDLIBS=

# AIX
# LDFLAGS=
# LDLIBS=

# Clix 3.1 r.7.1.3 (Intergraph)
# LDFLAGS=
# LDLIBS=-lbsd

# Digital UNIX or DEC OSF/1 (prior to Digital UNIX V3.2)
# LDFLAGS=
# LDLIBS=

# HP-UX 9.01:
LDFLAGS=
LDLIBS=

# IRIX v4.0.5:	-lsun is for the NIS stuff (so that you can use
#	netgroup entries).  -lmalloc avoids a problem with the
#	default malloc routine that causes a core dump.
# LDFLAGS =
# LDLIBS = -lmalloc -lsun

# Linux v1.2:
# LDFLAGS=
# LDLIBS=

# SCO 3.2v4
# LDFLAGS=
# LDLIBS= -lsocket -lmalloc -lufc -lsec

# Solaris 2.2, 2.3, 2.4: don't use -Bstatic or -static: it should not be needed
# for security (see LD_LIBRARY_PATH in ld(1)), and the groupname-lookup
# routines are for some reason only available in shared libs (see getgrnam(3)).
# LDFLAGS=
# LDLIBS= -lnsl

# SunOS 4.1.3: no special flags needed.  N.B.: If you use SunOS 4.0.x, you
# should link statically for security.  (I don't know about the proper
# flags for SunOS 4.1.1).
# LDFLAGS=
# LDLIBS=

# TI SYS V 3.3:
# LDFLAGS=
# LDLIBS=-lsocket


# Ultrix V4.3A
# LDFLAGS=
# LDLIBS=

# UnixWare 2.0
# LDFLAGS= -L/usr/ucblib
# LDLIBS= -lgen -lcrypt -lucb


####################################################################
# You shouldn't have to modify anything below this line.
####################################################################

SRC= $(SUPER_SRC) $(SETUID_SRC)

SUPER_C_SRC = super.c approve.c checks.c colon.c braces.c error.c \
	hsearch.c options.c regex.c re_fail.c rsyslog.c \
	strqtokS.c time.c utils.c wildmat.c

SUPER_H_SRC = hsearch.h version.h options.h super.h

SUPER_SRC = $(SUPER_C_SRC) $(SUPER_H_SRC)

SETUID_SRC = setuid.c

SUPER_OBJ= super.o approve.o checks.o colon.o braces.o error.o \
	hsearch.o options.o regex.o re_fail.o rsyslog.o \
	strqtokS.o time.o utils.o wildmat.o

ALL= README Artistic Copying WhatsNew Makefile super.1 super.5 setuid.1 sample.tab sample.cdmount $(SRC)

all: super setuid

super: $(SUPER_OBJ)
	$(CC) $(LDFLAGS) -o super $(SUPER_OBJ) $(LDLIBS)

setuid: setuid.o
	$(CC) $(LDFLAGS) -o setuid setuid.o

cflow:
	cflow $(SUPER_C_SRC) > cflow.out
	cflow -r $(SUPER_C_SRC) > cflow.rev

# NOTICE NOTICE NOTICE!
# You must install super as "super", and not use any other program name.
# This is because at run-time, the program assumes that if it's invoked
# with a different name, it must have been invoked via a symlink, and
# it treats
#	% myothernameforsuper args
# as if you typed
#	% super myothernameforsuper args
# If you insist on installing under another name, then you must
# change the #define ONETRUENAME from "super" to your other
# name, and edit the documentation to match.
install:
	cp super $(BINDIR)/super
	chmod 04755 $(BINDIR)/super
	cp setuid $(BINDIR)/setuid
	cp super.1 $(MANDIR)/super.$(MANEXT)
	cp setuid.1 $(MANDIR)/setuid.$(MANEXT)
	cp super.5 $(MAN_FMT_DIR)/super.$(MAN_FMT_EXT)

clean:
	rm -f super setuid *.o

$(ALL): 
	co $@

# Because of the wide variation in shar commands, the shar arguments
# used below sticks to a minimal set, and we generate various shar file
# headers by hand.  
shar: $(ALL)
	( echo "#include <stdio.h>" ; \
	echo '#include "version.h"' ; \
	echo 'main() {printf("%s.%s\\n",Version,Patchlevel);exit(0);}') > temp.c
	cc temp.c
	V=super-`./a.out`; mkdir $$V && cp $(ALL) $$V && \
	    sed -e 's/-DRLOG_MACHINE=\"toto.domain\"]*"/-DRLOG_MACHINE=\\"toto.domain\\"/' Makefile >> $$V/Makefile.orig && \
	    chmod +w $$V/Makefile && \
	    cp $$V/Makefile.orig $$V/Makefile && \
	    (echo "Submitted-by: will@nfra.nl" ; \
	    echo "Archive-name: $$V/part01" ; echo "" ; \
	    echo "---- Cut Here and feed the following to sh ----" ; \
	    shar $$V ) > $$V.shar && rm -rf $$V
	rm a.out temp.c

depend:
	makedepend -- $(CFLAGS) -- $(SRC)

