summaryrefslogtreecommitdiff
path: root/google_compute_engine_oslogin/Makefile
blob: 7e70019028600186a26556ade6ebbc222475cda2 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
SHELL = /bin/sh

BASENAME = oslogin
NAME = google-compute-engine-$(BASENAME)
MAJOR = 1
MINOR = 0
REVISION = 1

NSS_LIBRARY_NAME = libnss_$(NAME)-$(MAJOR).$(MINOR).$(REVISION).so
NSS_LIBRARY_SONAME = libnss_$(BASENAME).so.2
NSS_INSTALL_PATH = /lib
PAM_INSTALL_PATH = /lib/security
AUTHKEYS_INSTALL_PATH = /usr/bin

CXX = g++
CXXFLAGS += -fPIC# -Wall
PAMFLAGS = $(LDFLAGS) -shared
NSSFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(NSS_LIBRARY_SONAME)

# UTILS
UTILS_DIR = utils
UTILS_SRC = $(UTILS_DIR)/$(BASENAME)_utils.cc
UTILS = $(UTILS_DIR)/$(BASENAME)_utils.o

# AUTHORIZED KEYS
AUTHKEYS_DIR = authorized_keys
AUTHKEYS_SRC = $(AUTHKEYS_DIR)/authorized_keys.cc
AUTHKEYS_BIN = google_authorized_keys

# NSS
NSS = nss_$(BASENAME)
NSS_DIR = nss_module
NSS_SRC = $(NSS_DIR)/$(NSS).cc

# PAM
PAM = pam_$(BASENAME)
PAM_DIR = pam_module
PAM_ADMIN = $(PAM)_admin
PAM_ADMIN_SRC = $(PAM_DIR)/$(PAM_ADMIN).cc
PAM_ADMIN_OBJ = $(PAM_DIR)/$(PAM_ADMIN).o
PAM_ADMIN_MOD = $(PAM_ADMIN).so
PAM_LOGIN = $(PAM)_login
PAM_LOGIN_SRC = $(PAM_DIR)/$(PAM_LOGIN).cc
PAM_LOGIN_OBJ = $(PAM_DIR)/$(PAM_LOGIN).o
PAM_LOGIN_MOD = $(PAM_LOGIN).so

# HELPER SCRIPTS
BIN_DIR = bin
OSLOGIN_HELPER = $(BIN_DIR)/google_oslogin_control
BIN_INSTALL_PATH = /usr/bin

# SELINUX POLICY
INSTALL_SELINUX =
POLICY_DIR = policy
SELINUX_MODULE_SRC = $(POLICY_DIR)/oslogin$(DIST).te
SELINUX_MOD_FILE = $(POLICY_DIR)/oslogin$(DIST).mod
SELINUX_MODULE = $(POLICY_DIR)/oslogin$(DIST).pp
SELINUX_INSTALL_NAME = oslogin.pp
SELINUX_INSTALL_PATH = /usr/share/selinux/packages

LIBS = -lcurl -ljson-c
PAM_LIBS = -lpam $(LIBS)

ifdef INSTALL_SELINUX
all: $(NSS) $(PAM) $(AUTHKEYS_BIN) $(SELINUX_MODULE)
else
all: $(NSS) $(PAM) $(AUTHKEYS_BIN)
endif

$(NSS): $(NSS_LIBRARY_SOURCE) $(UTILS)
	$(CXX) $(CXXFLAGS) $(NSSFLAGS) -o $(NSS_LIBRARY_NAME) \
	$(NSS_SRC) $(UTILS) $(LIBS)

$(PAM): $(PAM_ADMIN_MOD) $(PAM_LOGIN_MOD)

$(PAM_LOGIN_MOD): $(PAM_LOGIN_OBJ) $(UTILS)
	$(CXX) $(PAMFLAGS) -o $(PAM_LOGIN_MOD) $(PAM_LOGIN_OBJ) $(UTILS) $(PAM_LIBS)

$(PAM_ADMIN_MOD): $(PAM_ADMIN_OBJ) $(UTILS)
	$(CXX) $(PAMFLAGS) -o $(PAM_ADMIN_MOD) $(PAM_ADMIN_OBJ) $(UTILS) $(PAM_LIBS)

$(PAM_LOGIN_OBJ): $(PAM_LOGIN_SRC)
	$(CXX) $(CXXFLAGS) -c $(PAM_LOGIN_SRC) -o $(PAM_LOGIN_OBJ)

$(PAM_ADMIN_OBJ): $(PAM_ADMIN_SRC)
	$(CXX) $(CXXFLAGS) -c $(PAM_ADMIN_SRC) -o $(PAM_ADMIN_OBJ)

$(AUTHKEYS_BIN): $(AUTHKEYS_SRC) $(UTILS_SRC)
	$(CXX) $(LDFLAGS) -o $(AUTHKEYS_BIN) $(AUTHKEYS_SRC) $(UTILS_SRC) $(LIBS)

$(UTILS): $(UTILS_SRC)
	$(CXX) $(CXXFLAGS) -c $(UTILS_SRC) -o $(UTILS)

$(SELINUX_MOD_FILE): $(SELINUX_MODULE_SRC)
	checkmodule -M -m -o $(SELINUX_MOD_FILE) $(SELINUX_MODULE_SRC)

$(SELINUX_MODULE): $(SELINUX_MOD_FILE)
	semodule_package -o $(SELINUX_MODULE) -m  $(SELINUX_MOD_FILE)


ifdef INSTALL_SELINUX
install: $(NSS_LIBRARY_NAME) $(PAM_ADMIN_MOD) $(PAM_LOGIN_MOD) $(AUTHKEYS_BIN) $(SELINUX_MODULE)
else
install: $(NSS_LIBRARY_NAME) $(PAM_ADMIN_MOD) $(PAM_LOGIN_MOD) $(AUTHKEYS_BIN)
endif
	mkdir -p $(DESTDIR)$(PREFIX)/$(NSS_INSTALL_PATH)
	mkdir -p $(DESTDIR)$(PREFIX)/$(PAM_INSTALL_PATH)
	mkdir -p $(DESTDIR)$(PREFIX)/$(AUTHKEYS_INSTALL_PATH)
	mkdir -p $(DESTDIR)$(PREFIX)/$(BIN_INSTALL_PATH)
	install -m 0644 $(NSS_LIBRARY_NAME) $(DESTDIR)$(PREFIX)/$(NSS_INSTALL_PATH)
	install -m 0644 $(PAM_ADMIN_MOD) $(PAM_LOGIN_MOD) $(DESTDIR)$(PREFIX)/$(PAM_INSTALL_PATH)
	install -m 0755 $(AUTHKEYS_BIN) $(DESTDIR)$(PREFIX)/$(AUTHKEYS_INSTALL_PATH)
	install -m 0755 $(OSLOGIN_HELPER) $(DESTDIR)$(PREFIX)/$(BIN_INSTALL_PATH)
ifdef INSTALL_SELINUX
	mkdir -p $(DESTDIR)$(PREFIX)/$(SELINUX_INSTALL_PATH)
	install -T -m 0644 $(SELINUX_MODULE) $(DESTDIR)$(PREFIX)/$(SELINUX_INSTALL_PATH)/$(SELINUX_INSTALL_NAME)
endif

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/$(NSS_INSTALL_PATH)/$(NSS_LIBRARY_NAME)
	rm -f $(DESTDIR)$(PREFIX)/$(PAM_INSTALL_PATH)/$(PAM_ADMIN_MOD)
	rm -f $(DESTDIR)$(PREFIX)/$(PAM_INSTALL_PATH)/$(PAM_LOGIN_MOD)
	rm -f $(DESTDIR)$(PREFIX)/$(AUTHKEYS_INSTALL_PATH)/$(AUTHKEYS_BIN)
	rm -f $(DESTDIR)$(PREFIX)/$(BIN_INSTALL_PATH)/$(OSLOGIN_HELPER)
clean:
	rm -f $(UTILS) $(NSS_LIBRARY_NAME) $(PAM_ADMIN_OBJ) $(PAM_ADMIN_MOD) $(PAM_LOGIN_OBJ) $(PAM_LOGIN_MOD) $(AUTHKEYS_BIN)