blob: ded901473e337b14516352c051db5276e83e2e43 [file] [log] [blame]
Andrew G. Morgandbeb06b2020-08-15 11:17:55 -07001# Common version number defines for libcap
2LIBTITLE=libcap
3VERSION=2
Andrew G. Morgancfd4c3b2021-02-04 21:52:17 -08004MINOR=48
Andrew G. Morgandbeb06b2020-08-15 11:17:55 -07005
Andrew Morgan2c9c0532007-07-10 20:50:21 -07006#
Andrew Morgan2c9c0532007-07-10 20:50:21 -07007## Optional prefixes:
8#
9
Rolf Eike Beer6f8b1202016-05-10 17:57:11 +020010# common 'packaging' directory
Andrew Morgan2c9c0532007-07-10 20:50:21 -070011
Mike Frysinger76f6f0a2008-02-16 16:52:31 -050012FAKEROOT=$(DESTDIR)
Andrew Morgan2c9c0532007-07-10 20:50:21 -070013
14# Autoconf-style prefixes are activated when $(prefix) is defined.
Andrew G Morgan93308182013-12-24 10:08:05 -080015# Otherwise binaries and libraries are installed in /{lib,sbin}/,
Andrew Morgan2c9c0532007-07-10 20:50:21 -070016# header files in /usr/include/ and documentation in /usr/man/man?/.
Andrew G. Morgan85748f42010-08-08 17:42:11 -070017# These choices are motivated by the fact that getcap and setcap are
18# administrative operations that could be needed to recover a system.
Andrew Morgan2c9c0532007-07-10 20:50:21 -070019
Andrew Morgan5216fff2007-07-10 22:38:22 -070020ifndef lib
Andrew G Morgan93308182013-12-24 10:08:05 -080021lib=$(shell ldd /usr/bin/ld|egrep "ld-linux|ld.so"|cut -d/ -f2)
Andrew Morgan5216fff2007-07-10 22:38:22 -070022endif
23
Andrew Morgan2c9c0532007-07-10 20:50:21 -070024ifdef prefix
25exec_prefix=$(prefix)
26lib_prefix=$(exec_prefix)
27inc_prefix=$(lib_prefix)
Andrew Morgan5216fff2007-07-10 22:38:22 -070028man_prefix=$(prefix)/share
Andrew Morgan2c9c0532007-07-10 20:50:21 -070029else
30prefix=/usr
31exec_prefix=
32lib_prefix=$(exec_prefix)
33inc_prefix=$(prefix)
Andrew Morgan5216fff2007-07-10 22:38:22 -070034man_prefix=$(prefix)/share
Andrew Morgan2c9c0532007-07-10 20:50:21 -070035endif
36
37# Target directories
38
Benedikt Morbach0ee94212014-05-20 23:30:53 +020039MANDIR=$(man_prefix)/man
40SBINDIR=$(exec_prefix)/sbin
41INCDIR=$(inc_prefix)/include
42LIBDIR=$(lib_prefix)/$(lib)
Rolf Eike Beer48f44c62016-05-10 17:55:17 +020043PKGCONFIGDIR=$(LIBDIR)/pkgconfig
Andrew G. Morgan1a61e6f2019-12-07 17:23:41 -080044GOPKGDIR=$(prefix)/share/gocode/src
Andrew Morgan2c9c0532007-07-10 20:50:21 -070045
Andrew G. Morgan28f5bc72021-01-23 18:10:49 -080046# Once go1.16 is released, I plan to set this value to 1 and keep it
47# there. The Go packages should always remain backwardly compatible,
48# but I may have to up it if Go's syntax dramatically changes in a
Andrew G. Morgan19eebc52020-07-05 14:07:52 -070049# backwards incompatible manner. (Let's hope not.)
Andrew G. Morgan876ac712020-07-02 21:36:16 -070050GOMAJOR=0
Andrew Morgan2c9c0532007-07-10 20:50:21 -070051
52# Compilation specifics
53
Andrew G Morganc3290662014-01-01 17:56:31 -080054KERNEL_HEADERS := $(topdir)/libcap/include/uapi
55IPATH += -fPIC -I$(KERNEL_HEADERS) -I$(topdir)/libcap/include
Andrew G. Morgan8bdd0ef2008-09-10 19:50:50 -070056
Rolf Eike Beerde3dbde2020-09-30 09:17:02 +020057CC := $(CROSS_COMPILE)gcc
Rolf Eike Beer44a15c12016-05-10 18:01:22 +020058DEFINES := -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
Rolf Eike Beerbbe21152020-09-30 09:02:45 +020059COPTS ?= -O2
60CFLAGS ?= $(COPTS) $(DEFINES)
Fabrice Fontaine22f2e202020-07-30 09:48:44 +020061BUILD_CC ?= $(CC)
Rolf Eike Beerbbe21152020-09-30 09:02:45 +020062BUILD_COPTS ?= -O2
63BUILD_CFLAGS ?= $(BUILD_COPTS) $(DEFINES) $(IPATH)
Rolf Eike Beerde3dbde2020-09-30 09:17:02 +020064AR := $(CROSS_COMPILE)ar
65RANLIB := $(CROSS_COMPILE)ranlib
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070066DEBUG = -g #-DDEBUG
Torsten Werner7ebd7c52009-09-30 21:23:15 +020067WARNINGS=-Wall -Wwrite-strings \
Andrew Morgan2c9c0532007-07-10 20:50:21 -070068 -Wpointer-arith -Wcast-qual -Wcast-align \
Andrew Morgan5216fff2007-07-10 22:38:22 -070069 -Wstrict-prototypes -Wmissing-prototypes \
70 -Wnested-externs -Winline -Wshadow
Andrew Morgancd45c572007-08-13 23:16:50 -070071LD=$(CC) -Wl,-x -shared
Fabrice Fontaine22f2e202020-07-30 09:48:44 +020072LDFLAGS ?= #-g
Andrew G. Morgane9f55d92019-12-02 20:48:13 -080073LIBCAPLIB := -L$(topdir)/libcap -lcap
Andrew G. Morgan6b1d98b2020-10-13 06:21:55 -070074PSXLINKFLAGS := -lpthread -Wl,-wrap,pthread_create
75LIBPSXLIB := -L$(topdir)/libcap -lpsx $(PSXLINKFLAGS)
Andrew G. Morgane9f55d92019-12-02 20:48:13 -080076
Matthieu Crapet3c228702014-03-28 14:11:15 +010077BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes)
Andrew Morgan2c9c0532007-07-10 20:50:21 -070078
Andrew Morgan54f055e2007-07-21 22:18:02 -070079SYSTEM_HEADERS = /usr/include
Andrew Morgan2c9c0532007-07-10 20:50:21 -070080INCS=$(topdir)/libcap/include/sys/capability.h
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070081LDFLAGS += -L$(topdir)/libcap
Torsten Werner7ebd7c52009-09-30 21:23:15 +020082CFLAGS += -Dlinux $(WARNINGS) $(DEBUG)
Matthieu Crapet3c228702014-03-28 14:11:15 +010083INDENT := $(shell if [ -n "$$(which indent 2>/dev/null)" ]; then echo "| indent -kr" ; fi)
Andrew G. Morganf025e2f2020-11-01 15:00:02 -080084
85# SHARED tracks whether or not the SHARED libraries (libcap.so,
86# libpsx.so and pam_cap.so) are built. (Some environments don't
87# support shared libraries.)
88SHARED ?= yes
89# DYNAMIC controls how capsh etc are linked - to shared or static libraries
90DYNAMIC := $(shell if [ ! -d "$(topdir)/.git" ]; then echo $(SHARED); else echo no ; fi)
91
92PAM_CAP ?= $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo $(SHARED) ; else echo no ; fi)
Andrew G. Morgan0a42b492008-10-19 19:37:28 -070093
Andrew G. Morgan24375fb2020-10-27 20:20:47 -070094# If your system does not support pthreads, override this as "no".
95#
96# make PTHREADS=no ...
97#
98# This implies no Go support and no C/C++ libpsx build. Why might you
99# need libpsx for non-Go use? Tl;dr for POSIX semantics security:
100#
101# https://sites.google.com/site/fullycapable/who-ordered-libpsx
102#
103PTHREADS ?= yes
104
105ifeq ($(PTHREADS),yes)
Andrew G. Morgan068edb72021-02-04 21:13:27 -0800106GO ?= go
107GOLANG ?= $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
Andrew G. Morgan0615d992019-05-19 14:57:20 -0700108ifeq ($(GOLANG),yes)
Andrew G. Morgan068edb72021-02-04 21:13:27 -0800109GOROOT ?= $(shell $(GO) env GOROOT)
110GOCGO ?= $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
111GOOSARCH ?= $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
112CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh $(GO))
113ifeq ($(CGO_REQUIRED),1)
114# Strictly speaking go1.15 doesn't need this, but 1.16 is when the
115# real golang support arrives for non-cgo support, so drop the last
116# vestige of legacy workarounds then.
117CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]*
118endif
Andrew G. Morganb2b267e2019-11-30 18:33:42 -0800119CGO_CFLAGS := -I$(topdir)/libcap/include
120CGO_LDFLAGS := -L$(topdir)/libcap
Andrew G. Morgan0615d992019-05-19 14:57:20 -0700121endif
Andrew G. Morgan24375fb2020-10-27 20:20:47 -0700122endif
Andrew G. Morgan0615d992019-05-19 14:57:20 -0700123
Andrew G. Morgancbca9ab2020-04-05 19:31:19 -0700124# If you want capsh to launch with something other than /bin/bash
125# build like this:
126#
127# make CAPSH_SHELL='-DSHELL=\"/bin/sh\"'
128#
129# or undefine the following:
130#CAPSH_SHELL := '-DSHELL="/bin/sh"'
131
Andrew G. Morgan2b5f5632019-12-13 17:30:23 -0800132# When installing setcap, you can arrange for the installation process
133# to set its inheritable bit to be able to place capabilities on files.
134# It can be used in conjunction with pam_cap (associated with su and
135# certain users say) to make it useful for specially blessed users.
Andrew G. Morgan85748f42010-08-08 17:42:11 -0700136#
Andrew G. Morgan2b5f5632019-12-13 17:30:23 -0800137# make RAISE_SETFCAP=yes install
Andrew G. Morgan85748f42010-08-08 17:42:11 -0700138#
Andrew G. Morgan2b5f5632019-12-13 17:30:23 -0800139# This is now defaulted to no because some distributions have started
140# shipping with all users blessed with full inheritable sets which makes
141# no sense whatsoever!
142#
143# Indeed, it looks alarmingly like these distributions are recreating
144# the environment for what became known as the sendmail-capabilities
145# bug from 2000:
146#
147# https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue
148#
149# they are also nullifying the difference between a p-bit and an i-bit.
150#
151# Folk really should read this document, which explains there is a really
152# important difference being lost here:
153#
154# https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33528.pdf
155#
156# In the context of this tree, on such such systems, a yes setting will
157# guarantee that every user, by default, is able to bless any binary with
158# any capability - a ready made local exploit machanism.
159RAISE_SETFCAP := no
160
161# If set to yes, this will cause the go "web" demo app to force the needed p
162# bit to be able to bind to port 80 without running as root.
163RAISE_GO_FILECAP := no
Andrew G. Morgan85748f42010-08-08 17:42:11 -0700164
Andrew Morgan2c9c0532007-07-10 20:50:21 -0700165# Global cleanup stuff
166
167LOCALCLEAN=rm -f *~ core
168DISTCLEAN=@find . \( -name '*.orig' -o -name '*.rej' \) | xargs rm -f