| 1 |
# simple make file for the pam_cap module |
| 2 |
|
| 3 |
topdir=$(shell pwd)/.. |
| 4 |
include ../Make.Rules |
| 5 |
|
| •6 |
# hardening=+all adds this universally, but we don't want this for the module |
| 7 |
CFLAGS := $(filter-out -fPIE,$(CFLAGS)) |
| 8 |
LDFLAGS := $(filter-out -fPIE,$(filter-out -pie,$(LDFLAGS))) |
| 9 |
|
| 10 |
# Always build pam_cap sources this way: |
| 11 |
CFLAGS += -fPIC |
| 12 |
|
| 13 |
all: pam_cap.so |
| 14 |
$(MAKE) testlink |
| 15 |
|
| 16 |
install: all |
| 17 |
mkdir -p -m 0755 $(FAKEROOT)$(LIBDIR)/security |
| 18 |
install -m 0755 pam_cap.so $(FAKEROOT)$(LIBDIR)/security |
| 19 |
|
| 20 |
../libcap/loader.txt: |
| 21 |
$(MAKE) -C ../libcap loader.txt |
| 22 |
|
| 23 |
execable.o: execable.c ../libcap/execable.h ../libcap/loader.txt |
| 24 |
$(CC) $(CFLAGS) $(CPPFLAGS) -DLIBCAP_VERSION=\"libcap-$(VERSION).$(MINOR)\" -DSHARED_LOADER=\"$(shell cat ../libcap/loader.txt)\" -c execable.c -o $@ |
| 25 |
|
| 26 |
LIBCAP: |
| 27 |
$(MAKE) -C ../libcap all |
| 28 |
touch $@ |
| 29 |
|
| 30 |
pam_cap.so: pam_cap.o execable.o pam_cap_linkopts LIBCAP |
| 31 |
cat pam_cap_linkopts | xargs -e $(LD) $(LDFLAGS) -o $@ pam_cap.o execable.o $(LIBCAPLIB) |
| 32 |
|
| 33 |
# Some distributions force link everything at compile time, and don't |
| 34 |
# take advantage of libpam's dlopen runtime options to resolve ill |
| 35 |
# defined symbols from its own linkage as needed. (As the original |
| 36 |
# author of that part of libpam, I consider this force linking |
| 37 |
# premature optimization.) We debugged its consequences to pam_cap.so |
| 38 |
# as part of: |
| 39 |
# |
| 40 |
# https://bugzilla.kernel.org/show_bug.cgi?id=214023 |
| 41 |
# |
| 42 |
# If the current build environment is one of those, or we can't |
| 43 |
# reliably prove it isn't, extend the link options for pam_cap.so to |
| 44 |
# force linkage against libpam and the gazillion other things libpam |
| 45 |
# is linked against... |
| 46 |
# |
| 47 |
# If you want to force this behavior one way or the other, use the |
| 48 |
# make FORCELINKPAM=yes or FORCELINKPAM=no override. |
| 49 |
ifeq ($(FORCELINKPAM),yes) |
| 50 |
pam_cap_linkopts: Makefile |
| 51 |
echo "-Wl,-e,__so_start -lpam" > $@ |
| 52 |
else |
| 53 |
ifeq ($(FORCELINKPAM),no) |
| 54 |
pam_cap_linkopts: Makefile |
| 55 |
echo "-Wl,-e,__so_start" > $@ |
| 56 |
else |
| 57 |
pam_cap_linkopts: lazylink.so |
| 58 |
echo "-Wl,-e,__so_start" > $@ |
| 59 |
./lazylink.so || echo "-lpam" >> $@ |
| 60 |
|
| 61 |
lazylink.so: lazylink.c ../libcap/execable.h ../libcap/loader.txt |
| 62 |
$(LD) -o $@ $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) lazylink.c -DSHARED_LOADER=\"$(shell cat ../libcap/loader.txt)\" -Wl,-e,__so_start |
| 63 |
endif |
| 64 |
endif |
| 65 |
|
| 66 |
../libcap/libcap.a: |
| 67 |
$(MAKE) -C ../libcap libcap.a |
| 68 |
|
| 69 |
# Avoid $(LDFLAGS) here to avoid conflicts with --static for a in-tree |
| 70 |
# test binary. |
| 71 |
test_pam_cap: test_pam_cap.c pam_cap.c ../libcap/libcap.a |
| 72 |
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ test_pam_cap.c $(LIBCAPLIB) --static |
| 73 |
|
| 74 |
testlink: test.o pam_cap.o |
| 75 |
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ -lpam -ldl $(LIBCAPLIB) |
| 76 |
|
| 77 |
incapable.conf: |
| 78 |
echo "^cap_setuid alpha" > $@ && chmod o+w $@ |
| 79 |
|
| 80 |
test: testlink test_pam_cap pam_cap.so incapable.conf |
| 81 |
./test_pam_cap |
| 82 |
LD_LIBRARY_PATH=../libcap ./pam_cap.so |
| 83 |
LD_LIBRARY_PATH=../libcap ./pam_cap.so --help |
| 84 |
@echo "module can be run as an executable!" |
| 85 |
|
| 86 |
sudotest: test_pam_cap incapable.conf |
| 87 |
$(SUDO) ./test_pam_cap root 0x0 0x0 0x0 config=./capability.conf |
| 88 |
$(SUDO) ./test_pam_cap root 0x0 0x0 0x0 config=./sudotest.conf |
| 89 |
$(SUDO) ./test_pam_cap alpha 0x0 0x0 0x0 config=./capability.conf |
| 90 |
$(SUDO) ./test_pam_cap alpha 0x0 0x1 0x80 config=./sudotest.conf |
| 91 |
$(SUDO) ./test_pam_cap beta 0x0 0x1 0x0 config=./sudotest.conf |
| 92 |
$(SUDO) ./test_pam_cap gamma 0x0 0x0 0x81 config=./sudotest.conf |
| 93 |
$(SUDO) ./test_pam_cap delta 0x41 0x80 0x41 config=./sudotest.conf |
| 94 |
|
| 95 |
clean: |
| 96 |
rm -f *.o *.so testlink lazylink.so test_pam_cap pam_cap_linkopts *~ |
| 97 |
rm -f LIBCAP incapable.conf |