1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# git-authz - who may move which refs. C99 and libc, nothing else.
#
# make build ./git-authz
# make test build, then run the unit suite and the behavioural suite
# make install install into $(DESTDIR)$(PREFIX)
# make clean
#
# No configure script, no cmake, no generated headers: the only portability
# knob this program needs is CFLAGS. Warnings are variables so that a strict
# build is a command line and not a build system:
#
# make WARN="-Wall -Wextra -Wpedantic -Werror"
CC ?= cc
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
SHAREDIR ?= $(PREFIX)/share/git-host
SYSCONFDIR ?= /etc/git-host
HOOKDIR ?= $(SHAREDIR)/hooks
STD ?= -std=c99
WARN ?= -Wall -Wextra -Wpedantic
CFLAGS ?= -O2 -g
CPPFLAGS += -D_POSIX_C_SOURCE=200809L
PROG = git-authz
UNIT = tests/unit
OBJS = src/util.o src/glob.o src/policy.o src/hook.o src/validate.o src/edit.o \
src/main.o
all: $(PROG)
$(PROG): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS)
src/%.o: src/%.c src/authz.h
$(CC) $(STD) $(WARN) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
# AddressSanitizer/UBSan build of everything, so that the behavioural suite -
# which is what actually exercises the editing code paths - runs against them:
#
# make clean && make sanitizer
#
# Leaks are checked, which is why every command frees what it read: a program
# that exits in a millisecond does not need the memory back, but it does need
# the leak report to stay empty, or the one real leak hides among forty.
sanitizer: CFLAGS := -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer
sanitizer: LDFLAGS := -fsanitize=address,undefined
sanitizer: test
# The unit test links the parts it tests, not the command line, so that a
# broken argument parser cannot hide a working matcher (or the other way round).
$(UNIT): tests/unit.c src/util.o src/glob.o src/policy.o
$(CC) $(STD) $(WARN) $(CPPFLAGS) $(CFLAGS) -o $@ tests/unit.c \
src/util.o src/glob.o src/policy.o
test: $(PROG) $(UNIT)
mkdir -p tests/tmp
$(UNIT)
AUTHZ=./$(PROG) sh tests/run.sh
# The hook is a symlink to the program, named 'pre-receive', because that name
# is what core.hooksPath looks for and what selects authorize mode inside the
# binary. The link is relative so that a staged install, an unpacked prefix and
# the image built from either all resolve to the binary that came with them
# rather than to whatever lives at the same absolute path on the reading side.
#
# The policy is configuration: an existing one is an operator's file, so it is
# kept and the new one arrives beside it as authz.conf.new.
install: $(PROG)
install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(HOOKDIR) $(DESTDIR)$(SYSCONFDIR)
install -m 0755 $(PROG) $(DESTDIR)$(BINDIR)/$(PROG)
@if [ -e $(DESTDIR)$(SYSCONFDIR)/authz.conf ]; then \
install -m 0644 authz.conf $(DESTDIR)$(SYSCONFDIR)/authz.conf.new; \
echo " kept $(DESTDIR)$(SYSCONFDIR)/authz.conf; new example is authz.conf.new"; \
else \
install -m 0644 authz.conf $(DESTDIR)$(SYSCONFDIR)/authz.conf; \
fi
link=`awk -v from='$(HOOKDIR)' -v to='$(BINDIR)/$(PROG)' -f build/relpath.awk`; \
rm -f $(DESTDIR)$(HOOKDIR)/pre-receive; \
ln -s "$$link" $(DESTDIR)$(HOOKDIR)/pre-receive; \
echo " $(HOOKDIR)/pre-receive -> $$link"
uninstall:
rm -f $(DESTDIR)$(BINDIR)/$(PROG) $(DESTDIR)$(HOOKDIR)/pre-receive
clean:
rm -f $(OBJS) $(PROG) $(UNIT)
rm -rf tests/tmp
.PHONY: all test install uninstall clean
|