-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
240 lines (192 loc) · 8.05 KB
/
CMakeLists.txt
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#**********************************************************************
# otpasswd -- One-time password manager and PAM module.
# Copyright (C) 2009 by Tomasz bla Fortuna <bla@thera.be>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See LICENSE file for details.
##
##
# Global thingies
##
cmake_minimum_required(VERSION 2.4.7)
PROJECT(otpasswd)
SET(${PROJECT_NAME}_MAJOR_VERSION 0)
SET(${PROJECT_NAME}_MINOR_VERSION 7beta1)
# Cmake says this is required for locating gmp/libotp.a
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
# FIXME: -fPIC is required for .a library on x64 only!
# How to add it only to this target?
ADD_DEFINITIONS("-Wall -fPIC")
option(PROFILE "Enable coverage tests" OFF)
option(DEBUG "Enable additional debug information" OFF)
option(NLS "Enable National Language Support (NLS)" OFF)
# option( MYSQL "Generate code for MySQL database" OFF )
# option( LDAP "Generate code for LDAP" OFF )
# If PROFILE option given - enable coverage tests
IF (PROFILE)
ADD_DEFINITIONS("-static -fprofile-arcs -ftest-coverage")
LINK_LIBRARIES(gcov)
ENDIF (PROFILE)
IF (DEBUG)
ADD_DEFINITIONS("-ggdb")
ADD_DEFINITIONS("-DDEBUG_POSITIONS=1")
ADD_DEFINITIONS("-DDEBUG=1")
ELSE ()
ADD_DEFINITIONS("-s -O2")
ENDIF (DEBUG)
IF (NLS)
ADD_DEFINITIONS("-DUSE_NLS=1")
ENDIF (NLS)
# Detect system
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ADD_DEFINITIONS("-DOS_LINUX")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
ADD_DEFINITIONS("-DOS_FREEBSD")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
# Detect include dirs
FIND_PATH(PAM_INCLUDE_DIR pam_modules.h /usr/include/security /usr/include/pam)
INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR})
# Module and PAM uses libotp, so add it's include to path...
INCLUDE_DIRECTORIES(common/ libotp/ crypto/ agent/)
##
# Manuals
# Rules for building compressed manuals
##
# See if gzip is available to compress manuals
FIND_PROGRAM(GZIP_TOOL
NAMES gzip
PATHS /bin
/usr/bin
/usr/local/bin)
IF(NOT GZIP_TOOL)
MESSAGE(SEND_ERROR "Unable to find 'gzip' program")
ENDIF(NOT GZIP_TOOL)
# List manual sources
SET(man_src_1 docs/otpasswd.1 docs/agent_otp.1 )
SET(man_src_5 docs/otpasswd.5 )
SET(man_src_8 docs/pam_otpasswd.8)
SET(man_src "${man_src_1}" "${man_src_5}" "${man_src_8}")
# Generate list compressed manuals
STRING(REGEX REPLACE "(\\.[0-9]+)(;|$)" "\\1.gz\\2" man_gz_1 "${man_src_1}")
STRING(REGEX REPLACE "(\\.[0-9]+)(;|$)" "\\1.gz\\2" man_gz_5 "${man_src_5}")
STRING(REGEX REPLACE "(\\.[0-9]+)(;|$)" "\\1.gz\\2" man_gz_8 "${man_src_8}")
STRING(REGEX REPLACE "(\\.[0-9]+)(;|$)" "\\1.gz\\2" man_gz "${man_src}" )
# Generate build rules for building compressed manuals
FOREACH(man ${man_src})
ADD_CUSTOM_COMMAND(OUTPUT ${man}.gz
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/docs
COMMAND ${GZIP_TOOL} -c ${CMAKE_CURRENT_SOURCE_DIR}/${man} > ${CMAKE_CURRENT_BINARY_DIR}/${man}.gz
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${man}
COMMENT "Building ${man}.gz")
ENDFOREACH(man)
##
# Targets
##
# Common functions library (64 bit numbers and logging)
ADD_LIBRARY(common STATIC common/print.c common/num.c
common/crypto.c crypto/polarssl_aes.c
crypto/coreutils_sha256.c)
# Library containing common functions
ADD_LIBRARY(otp STATIC libotp/ppp.c libotp/state.c
libotp/db_file.c libotp/db_mysql.c libotp/db_ldap.c
libotp/config.c)
# Library containing agent functions (for both agent and its clients)
ADD_LIBRARY(agent STATIC agent/agent_interface.c agent/agent_private.c)
# Pam module target
ADD_LIBRARY(pam_otpasswd SHARED pam/pam_helpers.c pam/pam_otpasswd.c)
SET_TARGET_PROPERTIES(pam_otpasswd PROPERTIES PREFIX "")
# Password management target
ADD_EXECUTABLE(otpasswd utility/otpasswd.c utility/actions.c utility/actions_helpers.c utility/cards.c)
# Agent server
ADD_EXECUTABLE(agent_otp agent/agent.c agent/request.c agent/testcases.c agent/security.c)
# Linking targets
TARGET_LINK_LIBRARIES(pam_otpasswd otp common pam)
TARGET_LINK_LIBRARIES(otpasswd agent common otp)
TARGET_LINK_LIBRARIES(agent_otp agent common otp)
# Man page target
ADD_CUSTOM_TARGET(man ALL DEPENDS ${man_gz})
##
# Install target
##
SET(CMAKE_INSTALL_PREFIX /usr)
INSTALL(TARGETS pam_otpasswd otpasswd agent_otp
RUNTIME DESTINATION bin
LIBRARY DESTINATION /lib/security)
#INSTALL(TARGETS libotp
# LIBRARY DESTINATION /lib)
INSTALL(FILES examples/otpasswd-login DESTINATION /etc/pam.d)
INSTALL(FILES examples/otpasswd.conf.dist DESTINATION /etc/otpasswd)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${man_gz_1} DESTINATION "share/man/man1")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${man_gz_5} DESTINATION "share/man/man5")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${man_gz_8} DESTINATION "share/man/man8")
##
# Tests / Coverage
# WARNING: THIS TESTS MODIFY USER STATE!
##
ENABLE_TESTING()
ADD_TEST(internal_check ./agent_otp --testcase)
# This may fail if user does not have state file!
# This tests are used mostly to have some rationale
# coverage test results
ADD_TEST(state_key0_fail tools/test_generate_no.sh)
ADD_TEST(state_key1 tools/test_generate_yes.sh)
ADD_TEST(state_flag0 ./otpasswd -v -c codelength=4)
ADD_TEST(state_print1 ./otpasswd -v -t "D10[123]")
ADD_TEST(state_print2 ./otpasswd -v -t "[123]")
ADD_TEST(state_print3 ./otpasswd -v -t "123")
ADD_TEST(state_print4 ./otpasswd -v -l "[124]")
ADD_TEST(state_print5 ./otpasswd -v -t "current")
ADD_TEST(state_print6 ./otpasswd -v -t "next")
ADD_TEST(state_print7 ./otpasswd -v -t "[next]")
ADD_TEST(state_print8 ./otpasswd -v -t "10D[123]")
ADD_TEST(state_skip1 ./otpasswd -v -s "[300]")
ADD_TEST(state_flag1a ./otpasswd -v -c show=off)
ADD_TEST(state_flag1b ./otpasswd -v -c show=on)
ADD_TEST(state_flag2 ./otpasswd -v -c codelength=12)
ADD_TEST(state_flag3 ./otpasswd -v -c alphabet=5)
ADD_TEST(state_flag4 ./otpasswd -v -c alphabet=2)
ADD_TEST(state_flag5 ./otpasswd -v -c alphabet=list)
ADD_TEST(state_flag6 ./otpasswd -v -i)
ADD_TEST(state_flag7 ./otpasswd -v --info-key)
ADD_TEST(state_spass ./otpasswd -v --password=asdfghjklASDDFGHJKL@@@%23)
ADD_TEST(state_spass_fail ./otpasswd -v --password=a)
ADD_TEST(state_label ./otpasswd -v -c "label=Set label")
ADD_TEST(state_contact ./otpasswd -v -c "contact=123456")
ADD_TEST(state_unset ./otpasswd -v -c contact= -c label=)
ADD_TEST(state_multi ./otpasswd -v -c contact=aAaA -c label=label)
ADD_TEST(state_warnings ./otpasswd -v -w)
# Tests which should fail
ADD_TEST(fail_ok1 ./otpasswd -v -l "[0]")
ADD_TEST(fail_ok2 ./otpasswd -v -l "0")
ADD_TEST(fail_ok3 ./otpasswd -v -t "340282366920938463463374607431768211457")
ADD_TEST(fail_ok4 ./otpasswd -v -s "-5")
ADD_TEST(fail_ok5 ./otpasswd -v -c contact="f`g")
ADD_TEST(fail_ok6 ./otpasswd -v -c label="f`g")
ADD_TEST(fail_ok7 ./otpasswd -v -c label="012345678901234567890123456789012345678901234567890")
ADD_TEST(fail_ok8 ./otpasswd -v -c contact="0123456789012345678901234567890123456789012345678900123456789")
ADD_TEST(fail_ok9 ./otpasswd -v -c codelength=17)
ADD_TEST(fail_ok10 ./otpasswd -v -c codelength=1)
ADD_TEST(fail_ok11 ./otpasswd -v -c alphabet=-1)
ADD_TEST(fail_ok12 ./otpasswd -v -c alphabet=33)
ADD_TEST(fail_ok13 ./otpasswd -v -c alphabet)
ADD_TEST(fail_ok14 ./otpasswd -v -c alphabet=2 illegal_arg)
ADD_TEST(fail_ok15 ./otpasswd -a '___')
ADD_TEST(fail_ok16 ./otpasswd --nonexisting-command a)
# Remove state - everything should fail then!
ADD_TEST(remove_key tools/test_remove_yes.sh)
SET_TESTS_PROPERTIES(state_key0_fail state_spass_fail fail_ok1 fail_ok2 fail_ok3
fail_ok4 fail_ok5 fail_ok6 fail_ok7 fail_ok8 fail_ok9 fail_ok10 fail_ok11
fail_ok12 fail_ok13 fail_ok14 fail_ok15 fail_ok16
PROPERTIES WILL_FAIL TRUE)