-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Makefile
1455 lines (1112 loc) · 45.1 KB
/
Makefile
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
EXTERNAL_JSON=external/cJSON/
EXTERNAL_LUA=external/lua-5.2.3/
EXTERNAL_ZLIB=external/zlib-1.2.11/
EXTERNAL_PCRE2=external/pcre2-10.32/
ZLIB_SYSTEM?=yes
PCRE2_SYSTEM?=yes
LUA_PLAT=posix
LUA_ENABLE?=no
MAXAGENTS?=2048
REUSE_ID?=no
# XXX Becareful NO EXTRA Spaces here
PREFIX?=/var/ossec
PG_CONFIG?=pg_config
MY_CONFIG?=mysql_config
PRELUDE_CONFIG?=libprelude-config
OSSEC_GROUP?=ossec
OSSEC_USER?=ossec
OSSEC_USER_MAIL?=ossecm
OSSEC_USER_REM?=ossecr
INSTALL_LOCALTIME?=yes
INSTALL_RESOLVCONF?=yes
USE_PRELUDE?=no
USE_ZEROMQ?=no
USE_GEOIP?=no
USE_INOTIFY=no
USE_PCRE2_JIT=yes
USE_SYSTEMD?=yes
ifneq (${TARGET},winagent)
USE_OPENSSL?=auto
else
USE_OPENSSL?=no
endif
ONEWAY?=no
CLEANFULL?=no
export MYLDFLAGS= "${LDFLAGS}"
export MYCFLAGS= "${CFLAGS}"
DEFINES=-DMAX_AGENTS=${MAXAGENTS} -DOSSECHIDS
DEFINES+=-DDEFAULTDIR=\"${PREFIX}\"
DEFINES+=-DUSER=\"${OSSEC_USER}\"
DEFINES+=-DREMUSER=\"${OSSEC_USER_REM}\"
DEFINES+=-DGROUPGLOBAL=\"${OSSEC_GROUP}\"
DEFINES+=-DMAILUSER=\"${OSSEC_USER_MAIL}\"
DEFINES+=-D${uname_S}
# Uncomment the DEFINES statement below if you are
# running Linux and want to use AF_UNSPEC instead of
# AF_INET6 to fully support IPv4 addresses.
#DEFINES+=-DNOV4MAP
ifneq (,$(filter ${REUSE_ID},yes y Y 1))
DEFINES+=-DREUSE_ID
endif
OSSEC_LDFLAGS=${LDFLAGS} -lm
ifneq (${TARGET},winagent)
ifeq (${uname_S},Linux)
DEFINES+=-DINOTIFY_ENABLED
OSSEC_LDFLAGS+=-lpthread
ifeq (${USE_SYSTEMD},yes)
DEFINES+=-DHAVE_SYSTEMD
OSSEC_LDFLAGS+=-lsystemd
endif
# DEFINES+=-DUSE_MAGIC
# OSSEC_LDFLAGS+=-lmagic
else
ifeq (${uname_S},AIX)
DEFINES+=-DAIX
DEFINES+=-DHIGHFIRST
CFLAGS+=-I./external/compat/aix
OSSEC_LDFLAGS+=-lpthread
PATH:=${PATH}:/usr/vac/bin
else
ifeq (${uname_S},SunOS)
DEFINES+=-DSOLARIS
DEFINES+=-DHIGHFIRST
OSSEC_LDFLAGS+=-lsocket -lnsl -lresolv
LUA_PLAT=solaris
PATH:=${PATH}:/usr/ccs/bin:/usr/xpg4/bin:/opt/csw/gcc3/bin:/opt/csw/bin:/usr/sfw/bin
else
ifeq (${uname_S},Darwin)
DEFINES+=-DDarwin
DEFINES+=-DHIGHFIRST
LUA_PLAT=macosx
else
ifeq (${uname_S},FreeBSD)
DEFINES+=-DFreeBSD
OSSEC_LDFLAGS+=-pthread
LUA_PLAT=freebsd
CFLAGS+=-I/usr/local/include
OSSEC_LDFLAGS+=-L/usr/local/lib
else
ifeq (${uname_S},NetBSD)
DEFINES+=-DNetBSD
OSSEC_LDFLAGS+=-pthread
LUA_PLAT=posix
CFLAGS+=-I/usr/local/include
OSSEC_LDFLAGS+=-L/usr/local/lib
USE_PCRE2_JIT=n
else
ifeq (${uname_S},OpenBSD)
# DEFINES+=-DOpenBSD
DEFINES+=-pthread
DNS_CFLAGS+=-lutil
LUA_PLAT=posix
CFLAGS+=-I/usr/local/include
OSSEC_LDFLAGS+=-L/usr/local/lib
USE_PCRE2_JIT=n
else
ifeq (${uname_S},HP-UX)
DEFINES+=-DHPUX
DEFINES+=-D_XOPEN_SOURCE_EXTENDED
DEFINES+=-DHIGHFIRST
DEFINES+=-D_REENTRANT
else
$(warning Unknown platform)
endif # HPUX
endif # OpenBSD
endif # NetBSD
endif # FreeBSD
endif # Darwin
endif # SunOS
endif # AIX
endif # Linux
endif # winagent
## OpenBSD doesn't need the imsg stuff.
ifneq (${uname_S},OpenBSD)
CFLAGS+=-I./external/compat
COMPAT_FILES+=./external/compat/imsg.c ./external/compat/imsg-buffer.c
endif
ifeq (${uname_S},AIX)
INSTALL_CMD?=./install-shim-aix.ksh -m $(1) -o $(2) -g $(3)
else
INSTALL_CMD?=install -m $(1) -o $(2) -g $(3)
endif
ifdef DEBUGAD
DEFINES+=-DDEBUGAD
endif
OSSEC_CFLAGS=${CFLAGS}
#ANALYSISD_FLAGS="-lsqlite3"
ifdef DEBUG
OSSEC_CFLAGS+=-g
endif #DEBUG
ifneq (,$(filter ${CLEANFULL},yes y Y 1))
DEFINES+=-DCLEANFULL
endif
ifneq (,$(filter ${ONEWAY},yes y Y 1))
DEFINES+=-DONEWAY_ENABLED
endif
ifneq (${ZLIB_SYSTEM},no)
DEFINES+=-DZLIB_SYSTEM
endif
ifeq (${TARGET}, winagent)
PCRE2_SYSTEM=no
endif
ifeq (${PCRE2_SYSTEM},no)
PCRE2_INCLUDE=-I./${EXTERNAL_PCRE2}/install/include/
DEFINES+=${PCRE2_INCLUDE}
DEFINES+=-DPCRE2_STATIC
else
PCRE2_LOCATION?=$(shell pcre2-config --prefix)/lib
OSSEC_LDFLAGS+=-lpcre2-8
endif
OSSEC_CFLAGS+=${DEFINES}
OSSEC_CFLAGS+=-Wall -Wextra
OSSEC_CFLAGS+=-I./ -I./headers/
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"
MING_BASE:=
ifeq (${TARGET}, winagent)
CC=gcc
ZLIB_SYSTEM=no
PCRE2_SYSTEM=no
ifneq (,$(shell which amd64-mingw32msvc-gcc))
MING_BASE:=amd64-mingw32msvc-
else
ifneq (,$(shell which i686-pc-mingw32-gcc))
MING_BASE:=i686-pc-mingw32-
else
ifneq (,$(shell which i686-w64-mingw32-gcc))
MING_BASE:=i686-w64-mingw32-
else
$(error No windows cross-compiler found!) #MING_BASE:=unknown-
endif
endif
endif
endif #winagent
OSSEC_CC =${QUIET_CC}${MING_BASE}${CC}
OSSEC_CCBIN =${QUIET_CCBIN}${MING_BASE}${CC}
OSSEC_LINK =${QUIET_LINK}${MING_BASE}ar ${AR_FLAGS} -crs
OSSEC_RANLIB =${QUIET_RANLIB}${MING_BASE}ranlib
OSSEC_WINDRES =${QUIET_CCBIN}${MING_BASE}windres
ifneq (,$(filter ${USE_PCRE2_JIT},yes y Y 1))
DEFINES+=-DUSE_PCRE2_JIT
PCRE2_CONFIGURE_JIT=--enable-jit
else
PCRE2_CONFIGURE_JIT=--disable-jit
endif
ifneq (,$(filter ${USE_INOTIFY},auto yes y Y 1))
DEFINES+=-DINOTIFY_ENABLED
ifeq (${uname_S},FreeBSD)
OSSEC_LDFLAGS+=-linotify -L/usr/local/lib -I/usr/local/include
OSSEC_CFLAGS+=-I/usr/local/include
endif
endif
ifneq (,$(filter ${USE_PRELUDE},auto yes y Y 1))
DEFINES+=-DPRELUDE_OUTPUT_ENABLED
OSSEC_LDFLAGS+=-lprelude
OSSEC_LDFLAGS+=$(shell sh -c '${PRELUDE_CONFIG} --pthread-cflags')
OSSEC_LDFLAGS+=$(shell sh -c '${PRELUDE_CONFIG} --libs')
endif # USE_PRELUDE
ifneq (,$(filter ${USE_ZEROMQ},auto yes y Y 1))
DEFINES+=-DZEROMQ_OUTPUT_ENABLED
#LDFLAGS+=-L/usr/local/lib -I/usr/local/include -lzmq -lczmq
OSSEC_LDFLAGS+=-lzmq -lczmq -lm
endif # USE_ZEROMQ
ifneq (,$(filter ${USE_GEOIP},auto yes y Y 1))
DEFINES+=-DLIBGEOIP_ENABLED
OSSEC_LDFLAGS+=-lGeoIP
endif # USE_GEOIP
ifneq (,$(filter ${USE_SQLITE},auto yes y Y 1))
DEFINES+=-DSQLITE_ENABLED
ANALYSISD_FLAGS="-lsqlite3"
endif # USE_SQLITE
MI :=
PI :=
ifdef DATABASE
ifeq (${DATABASE},mysql)
DEFINES+=-DMYSQL_DATABASE_ENABLED
ifdef MYSQL_CFLAGS
MI = ${MYSQL_CFLAGS}
else
MI := $(shell sh -c '${MY_CONFIG} --include 2>/dev/null || echo ')
ifeq (${MI},) # BEGIN MI manual detection
ifneq (,$(wildcard /usr/include/mysql/mysql.h))
MI="-I/usr/include/mysql/"
else
ifneq (,$(wildcard /usr/local/include/mysql/mysql.h))
MI="-I/usr/local/include/mysql/"
endif #
endif #MI
endif
endif # MYSQL_CFLAGS
ifdef MYSQL_LIBS
ML = ${MYSQL_LIBS}
else
ML := $(shell sh -c '${MY_CONFIG} --libs 2>/dev/null || echo ')
ifeq (${ML},)
ifneq (,$(wildcard /usr/lib/mysql/*))
ML="-L/usr/lib/mysql -lmysqlclient"
else
ifneq (,$(wildcard /usr/lib64/mysql/*))
ML="-L/usr/lib64/mysql -lmysqlclient"
else
ifneq (,$(wildcard /usr/local/lib/mysql/*))
ML="-L/usr/local/lib/mysql -lmysqlclient"
else
ifneq (,$(wildcard /usr/local/lib64/mysql/*))
ML="-L/usr/local/lib64/mysql -lmysqlclient"
endif # local/lib64
endif # local/lib
endif # lib54
endif # lib
endif
endif # MYSQL_LIBS
OSSEC_LDFLAGS+=${ML}
else # DATABASE
ifeq (${DATABASE}, pgsql)
DEFINES+=-DPGSQL_DATABASE_ENABLED
ifneq (${PGSQL_LIBS},)
PL:=${PGSQL_LIBS}
else
PL:=$(shell sh -c '(${PG_CONFIG} --libdir --pkglibdir 2>/dev/null | sed "s/^/-L/g" | xargs ) || echo ')
endif
ifneq (${PGSQL_CFLAGS},)
PI:=${PGSQL_CFLAGS}
else
PI:=$(shell sh -c '(${PG_CONFIG} --includedir --pkgincludedir 2>/dev/null | sed "s/^/-I/g" | xargs ) || echo ')
endif
# XXX need some basic autodetech stuff here.
OSSEC_LDFLAGS+=${PL}
OSSEC_LDFLAGS+=-lpq
endif # pgsql
endif # mysql
endif # DATABASE
# openssl ###########
ifeq (${USE_OPENSSL},auto)
ifneq (,$(wildcard /usr/include/openssl/ssl.h))
DEFINES+=-DLIBOPENSSL_ENABLED
OSSEC_LDFLAGS+=-lssl -lcrypto
else
ifneq (,$(wildcard /usr/local/include/openssl/ssl.h))
DEFINES+=-DLIBOPENSSL_ENABLED
OSSEC_LDFLAGS+=-lssl -lcrypto
endif
endif
endif # USE_OPENSSL
ifneq (,$(filter ${USE_OPENSSL},yes y Y 1))
DEFINES+=-DLIBOPENSSL_ENABLED
ifeq (${OPENSSL_LIBS},)
OSSEC_LDFLAGS+=-lssl -lcrypto
else
OSSEC_LDFLAGS+=${OPENSSL_LIBS}
endif
ifneq (${OPENSSL_CFLAGS},)
OSSEC_CFLAGS+=${OPENSSL_CFLAGS}
endif
endif
####################
#### Target ########
####################
OSSEC_CONTROL_SRC=./init/ossec-server.sh
OSSEC_CONF_SRC=../etc/ossec-server.conf
ifndef TARGET
TARGET=failtarget
endif # TARGET
ifeq (${TARGET},agent)
DEFINES+=-DCLIENT
OSSEC_CONTROL_SRC=./init/ossec-client.sh
OSSEC_CONF_SRC=../etc/ossec-agent.conf
endif
ifeq (${TARGET},local)
DEFINES+=-DLOCAL
OSSEC_CONTROL_SRC=./init/ossec-local.sh
OSSEC_CONF_SRC=../etc/ossec-local.conf
endif
.PHONY: build
build: ${TARGET}
ifneq (${TARGET},failtarget)
${MAKE} settings
@echo
${QUIET_NOTICE}
@echo "Done building ${TARGET}"
${QUIET_ENDCOLOR}
endif
@echo
.PHONY: install install-agent install-server install-local install-hybrid
install: install-${TARGET}
install-agent: install-common
$(call INSTALL_CMD,0550,root,0) ossec-agentd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) agent-auth ${PREFIX}/bin
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/rids
install-local: install-server-generic
install-hybrid: install-server-generic
install-server: install-server-generic
install-common: build
./init/adduser.sh ${OSSEC_USER} ${OSSEC_USER_MAIL} ${OSSEC_USER_REM} ${OSSEC_GROUP} ${PREFIX}
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/logs
$(call INSTALL_CMD,0660,${OSSEC_USER},${OSSEC_GROUP}) /dev/null ${PREFIX}/logs/ossec.log
$(call INSTALL_CMD,0550,root,0) -d ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-logcollector ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-syscheckd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-execd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) manage_agents ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ../contrib/util.sh ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) ${OSSEC_CONTROL_SRC} ${PREFIX}/bin/ossec-control
ifeq (${LUA_ENABLE},yes)
$(call INSTALL_CMD,0550,root,0) -d ${PREFIX}/lua
$(call INSTALL_CMD,0550,root,0) -d ${PREFIX}/lua/native
$(call INSTALL_CMD,0550,root,0) -d ${PREFIX}/lua/compiled
$(call INSTALL_CMD,0550,root,0) ${EXTERNAL_LUA}src/ossec-lua ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) ${EXTERNAL_LUA}src/ossec-luac ${PREFIX}/bin/
endif
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/queue
$(call INSTALL_CMD,0770,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/alerts
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/ossec
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/syscheck
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/diff
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/etc
ifeq (${INSTALL_LOCALTIME},yes)
$(call INSTALL_CMD,0440,root,${OSSEC_GROUP}) /etc/localtime ${PREFIX}/etc
endif
ifeq (${INSTALL_RESOLVCONF},yes)
$(call INSTALL_CMD,0440,root,${OSSEC_GROUP}) /etc/resolv.conf ${PREFIX}/etc
endif
$(call INSTALL_CMD,1550,root,${OSSEC_GROUP}) -d ${PREFIX}/tmp
ifneq (,$(wildcard /etc/TIMEZONE))
$(call INSTALL_CMD,440,root,${OSSEC_GROUP}) /etc/TIMEZONE ${PREFIX}/etc/
endif
# Solaris Needs some extra files
ifeq (${uname_S},SunOS)
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/usr/share/lib/zoneinfo/
cp -r /usr/share/lib/zoneinfo/* ${PREFIX}/usr/share/lib/zoneinfo/
endif
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) -b ../etc/internal_options.conf ${PREFIX}/etc/
ifeq (,$(wildcard ${PREFIX}/etc/local_internal_options.conf))
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) ../etc/local_internal_options.conf ${PREFIX}/etc/local_internal_options.conf
endif
ifeq (,$(wildcard ${PREFIX}/etc/client.keys))
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) /dev/null ${PREFIX}/etc/client.keys
endif
ifeq (,$(wildcard ${PREFIX}/etc/ossec.conf))
ifneq (,$(wildcard ../etc/ossec.mc))
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) ../etc/ossec.mc ${PREFIX}/etc/ossec.conf
else
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) ${OSSEC_CONF_SRC} ${PREFIX}/etc/ossec.conf
endif
endif
$(call INSTALL_CMD,0770,root,${OSSEC_GROUP}) -d ${PREFIX}/etc/shared
$(call INSTALL_CMD,0640,${OSSEC_USER},${OSSEC_GROUP}) rootcheck/db/*.txt ${PREFIX}/etc/shared/
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/active-response
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/active-response/bin
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/agentless
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) agentlessd/scripts/* ${PREFIX}/agentless/
$(call INSTALL_CMD,0700,root,${OSSEC_GROUP}) -d ${PREFIX}/.ssh
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) ../active-response/*.sh ${PREFIX}/active-response/bin/
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) ../active-response/firewalls/*.sh ${PREFIX}/active-response/bin/
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/var
$(call INSTALL_CMD,0770,root,${OSSEC_GROUP}) -d ${PREFIX}/var/run
./init/fw-check.sh execute
install-server-generic: install-common
$(call INSTALL_CMD,0660,${OSSEC_USER},${OSSEC_GROUP}) /dev/null ${PREFIX}/logs/active-responses.log
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/logs/archives
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/logs/alerts
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/logs/firewall
$(call INSTALL_CMD,0550,root,0) ossec-agentlessd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-analysisd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-monitord ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-reportd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-maild ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-remoted ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-logtest ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-csyslogd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-authd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-dbd ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) ossec-makelists ${PREFIX}/bin
$(call INSTALL_CMD,0550,root,0) verify-agent-conf ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) clear_stats ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) list_agents ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) ossec-regex ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) syscheck_update ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) agent_control ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) syscheck_control ${PREFIX}/bin/
$(call INSTALL_CMD,0550,root,0) rootcheck_control ${PREFIX}/bin/
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/stats
$(call INSTALL_CMD,0550,root,${OSSEC_GROUP}) -d ${PREFIX}/rules
ifneq (,$(wildcard ${PREFIX}/rules/local_rules.xml))
cp ${PREFIX}/rules/local_rules.xml ${PREFIX}/rules/local_rules.xml.installbackup
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) -b ../etc/rules/*.xml ${PREFIX}/rules
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) ${PREFIX}/rules/local_rules.xml.installbackup ${PREFIX}/rules/local_rules.xml
rm ${PREFIX}/rules/local_rules.xml.installbackup
else
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) -b ../etc/rules/*.xml ${PREFIX}/rules
endif
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/fts
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/rootcheck
$(call INSTALL_CMD,0750,${OSSEC_USER_REM},${OSSEC_GROUP}) -d ${PREFIX}/queue/agent-info
$(call INSTALL_CMD,0750,${OSSEC_USER},${OSSEC_GROUP}) -d ${PREFIX}/queue/agentless
$(call INSTALL_CMD,0750,${OSSEC_USER_REM},${OSSEC_GROUP}) -d ${PREFIX}/queue/rids
$(call INSTALL_CMD,0640,root,${OSSEC_GROUP}) ../etc/decoder.xml ${PREFIX}/etc/
rm -f ${PREFIX}/etc/shared/merged.mg
.PHONY: failtarget
failtarget:
@echo "TARGET is required: "
@echo " make TARGET=server to build the server"
@echo " make TARGET=local - local version of server"
@echo " make TARGET=hybrid - hybrid version of server"
@echo " make TARGET=agent to build the unix agent"
@echo " make TARGET=winagent to build the windows agent"
.PHONY: help
help: failtarget
@echo
@echo "General options: "
@echo " make V=1 Display full compiler messages"
@echo " make DEBUG=1 Build with symbols and without optimization"
@echo " make PREFIX=/path Install OSSEC to '/path'. Defaults to /var/ossec"
@echo " make MAXAGENTS=NUMBER Set the number of maximum agents to NUMBER. Defaults to 2048"
@echo " make REUSE_ID=yes Enables agent ID re-use"
@echo
@echo "Database options: "
@echo " make DATABASE=mysql Build with MYSQL Support"
@echo " Use MYSQL_CFLAGS and MYSQL_LIBS to override defaults"
@echo " make DATABASE=pgsql Build with PostgreSQL Support "
@echo " Use PGSQL_CFLAGS and PGSQL_LIBS to override defaults"
@echo
@echo "Geoip support: "
@echo " make USE_GEOIP=1 Build with GeoIP support"
@echo
@echo "External source options: "
@echo " make LUA_ENABLE=no Disable LUA build"
@echo " make ZLIB_SYSTEM=yes Use zlib sources from system"
@echo " make PCRE2_SYSTEM=yes Use pcre2 sources from system"
@echo
@echo "Examples: Client with debugging enabled"
@echo " make TARGET=agent DEBUG=1"
.PHONY: settings
settings:
@echo
@echo "General settings:"
@echo " TARGET: ${TARGET}"
@echo " V: ${V}"
@echo " DEBUG: ${DEBUG}"
@echo " DEBUGAD: ${DEBUGAD}"
@echo " PREFIX: ${PREFIX}"
@echo " MAXAGENTS: ${MAXAGENTS}"
@echo " REUSE_ID: ${REUSE_ID}"
@echo " DATABASE: ${DATABASE}"
@echo " ONEWAY: ${ONEWAY}"
@echo " CLEANFULL: ${CLEANFULL}"
@echo "User settings:"
@echo " OSSEC_GROUP: ${OSSEC_GROUP}"
@echo " OSSEC_USER: ${OSSEC_USER}"
@echo " OSSEC_USER_MAIL: ${OSSEC_USER_MAIL}"
@echo " OSSEC_USER_REM: ${OSSEC_USER_REM}"
@echo "ZLIB settings:"
@echo " ZLIB_SYSTEM: ${ZLIB_SYSTEM}"
@echo " ZLIB_INCLUDE: ${ZLIB_INCLUDE}"
@echo " ZLIB_LIB: ${ZLIB_LIB}"
@echo "PCRE2 settings:"
@echo " PCRE2_SYSTEM: ${PCRE2_SYSTEM}"
@echo " PCRE2_INCLUDE: ${PCRE2_INCLUDE}"
@echo "Lua settings:"
@echo " LUA_PLAT: ${LUA_PLAT}"
@echo " LUA_ENABLE: ${LUA_ENABLE}"
@echo "USE settings:"
@echo " USE_ZEROMQ: ${USE_ZEROMQ}"
@echo " USE_GEOIP: ${USE_GEOIP}"
@echo " USE_PRELUDE: ${USE_PRELUDE}"
@echo " USE_OPENSSL: ${USE_OPENSSL}"
@echo " USE_INOTIFY: ${USE_INOTIFY}"
@echo " USE_SQLITE: ${USE_SQLITE}"
@echo " USE_PCRE2_JIT: ${USE_PCRE2_JIT}"
@echo " USE_SYSTEMD: ${USE_SYSTEMD}"
@echo "Mysql settings:"
@echo " includes: ${MI}"
@echo " libs: ${ML}"
@echo "Pgsql settings:"
@echo " includes: ${PI}"
@echo " libs: ${PL}"
@echo "Defines:"
@echo " ${DEFINES}"
@echo "Compiler:"
@echo " CFLAGS ${OSSEC_CFLAGS}"
@echo " LDFLAGS ${OSSEC_LDFLAGS}"
@echo " CC ${CC}"
@echo " MAKE ${MAKE}"
BUILD_SERVER+=external
BUILD_SERVER+=ossec-maild
BUILD_SERVER+=ossec-csyslogd
BUILD_SERVER+=ossec-agentlessd
BUILD_SERVER+=ossec-execd
BUILD_SERVER+=ossec-logcollector
BUILD_SERVER+=ossec-remoted
BUILD_SERVER+=ossec-agentd
BUILD_SERVER+=manage_agents
BUILD_SERVER+=utils
BUILD_SERVER+=ossec-syscheckd
BUILD_SERVER+=ossec-monitord
BUILD_SERVER+=ossec-reportd
ifneq (,$(filter ${USE_OPENSSL},auto yes))
BUILD_SERVER+=ossec-authd
endif
BUILD_SERVER+=ossec-analysisd
BUILD_SERVER+=ossec-logtest
BUILD_SERVER+=ossec-makelists
BUILD_SERVER+=ossec-dbd
BUILD_AGENT+=external
BUILD_AGENT+=ossec-agentd
ifneq (,$(filter ${USE_OPENSSL},auto yes))
BUILD_AGENT+=agent-auth
endif
BUILD_AGENT+=ossec-logcollector
BUILD_AGENT+=ossec-syscheckd
BUILD_AGENT+=ossec-execd
BUILD_AGENT+=manage_agents
.PHONY: server local hybrid agent
ifeq (${MAKECMDGOALS},server)
$(error Do not use 'server' directly, use 'TARGET=server')
endif
server: ${BUILD_SERVER}
ifeq (${MAKECMDGOALS},local)
$(error Do not use 'local' directly, use 'TARGET=local')
endif
local: ${BUILD_SERVER}
ifeq (${MAKECMDGOALS},hybrid)
$(error Do not use 'hybrid' directly, use 'TARGET=hybrid')
endif
hybrid: ${BUILD_SERVER}
ifeq (${MAKECMDGOALS},agent)
$(error Do not use 'agent' directly, use 'TARGET=agent')
endif
agent: ${BUILD_AGENT}
WINDOWS_BINS:=win32/ossec-agent.exe win32/ossec-agent-eventchannel.exe win32/ossec-rootcheck.exe win32/manage_agents.exe win32/setup-windows.exe win32/setup-syscheck.exe win32/setup-iis.exe win32/add-localfile.exe win32/os_win32ui.exe win32/agent-auth.exe
ifeq (${MAKECMDGOALS},winagent)
$(error Do not use 'winagent' directly, use 'TARGET=winagent')
endif
.PHONY: winagent
winagent:
${MAKE} ${WINDOWS_BINS} CFLAGS="-DCLIENT -DWIN32 -I./${EXTERNAL_ZLIB} -I./${EXTERNAL_PCRE2}/install/include" LDFLAGS="-lwsock32 -lwevtapi -lshlwapi -lcomctl32 -lws2_32"
#cd ${EXTERNAL_LUA}src/ && ${MAKE} CC=${MING_BASE}${CC} -f Makefile.mingw mingw
#cp ${EXTERNAL_LUA}src/ossec-lua.exe win32/
#cp ${EXTERNAL_LUA}src/ossec-luac.exe win32/
cd win32/ && ./unix2dos.pl ossec.conf > default-ossec.conf
cd win32/ && ./unix2dos.pl help.txt > help_win.txt
cd win32/ && ./unix2dos.pl ../../etc/internal_options.conf > internal_options.conf
cd win32/ && ./unix2dos.pl ../../etc/local_internal_options-win.conf > default-local_internal_options.conf
cd win32/ && ./unix2dos.pl ../../LICENSE > LICENSE.txt
cd win32/ && ./unix2dos.pl ../../active-response/win/route-null.cmd > route-null.cmd
cd win32/ && ./unix2dos.pl ../../active-response/win/restart-ossec.cmd > restart-ossec.cmd
cd win32/ && makensis ossec-installer.nsi
####################
#### External ######
####################
.PHONY: external lua
ifeq (${PCRE2_SYSTEM},no)
external: libcJSON.a ${EXTERNAL_ZLIB}libz.a lua libpcre2-8.a
else
external: libcJSON.a ${EXTERNAL_ZLIB}libz.a lua
endif
lua:
ifeq (${LUA_ENABLE},yes)
cd ${EXTERNAL_LUA} && ${MAKE} ${LUA_PLAT}
endif
${EXTERNAL_ZLIB}libz.a:
ifeq (${TARGET},winagent)
cd ${EXTERNAL_ZLIB} && cp zconf.h.in zconf.h && ${MAKE} -f win32/Makefile.gcc PREFIX=${MING_BASE} libz.a
else
ifeq (${ZLIB_SYSTEM},no)
cd ${EXTERNAL_ZLIB} && ./configure && ${MAKE} libz.a
endif
endif
#### zlib ##########
ifeq (${ZLIB_SYSTEM},no)
ZLIB_LIB=os_zlib.a ${EXTERNAL_ZLIB}libz.a
ZLIB_INCLUDE=-I./${EXTERNAL_ZLIB}
else
ZLIB_LIB=os_zlib.a
ZLIB_INCLUDE=
OSSEC_LDFLAGS+=-lz
endif
os_zlib_c := os_zlib/os_zlib.c
os_zlib_o := $(os_zlib_c:.c=.o)
os_zlib/%.o: os_zlib/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $< -o $@
os_zlib.a: ${os_zlib_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### cJSON #########
JSON_LIB=libcJSON.a
JSON_INCLUDE=-I./${EXTERNAL_JSON}
cjson_c := ${EXTERNAL_JSON}cJSON.c
cjson_o := $(cjson_c:.c=.o)
${EXTERNAL_JSON}%.o: ${EXTERNAL_JSON}%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
libcJSON.a: ${cjson_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### pcre2 ##########
ifeq (${PCRE2_SYSTEM},no)
libpcre2-8.a: ${EXTERNAL_PCRE2}/install/lib/libpcre2-8.a
cp $< $@
${OSSEC_RANLIB} $@
${EXTERNAL_PCRE2}/install/lib/libpcre2-8.a:
ifeq (${TARGET}, winagent)
cd ${EXTERNAL_PCRE2} && \
CC= ./configure \
--prefix=$(shell pwd)/${EXTERNAL_PCRE2}/install \
${PCRE2_CONFIGURE_JIT} \
--disable-shared \
--enable-static \
--host=${MING_BASE:%-=%} && \
make install-libLTLIBRARIES install-nodist_includeHEADERS
else
cd ${EXTERNAL_PCRE2} && \
./configure \
--prefix=$(shell pwd)/${EXTERNAL_PCRE2}/install \
${PCRE2_CONFIGURE_JIT} \
--disable-shared \
--enable-static && \
make install-libLTLIBRARIES install-nodist_includeHEADERS
endif
endif
####################
#### OSSEC Libs ####
####################
ossec_libs = os_crypto.a config.a shared.a os_net.a os_regex.a os_xml.a
#### os_xml ########
os_xml_c := $(wildcard os_xml/*.c)
os_xml_o := $(os_xml_c:.c=.o)
os_xml/%.o: os_xml/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
os_xml.a: ${os_xml_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### os_regex ######
os_regex_c := $(wildcard os_regex/*.c)
os_regex_o := $(os_regex_c:.c=.o)
os_regex/%.o: os_regex/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
ifeq (${PCRE2_SYSTEM},no)
os_regex.a: ${os_regex_o} libpcre2-8.a
(mkdir -p libpcre2_objs && cd libpcre2_objs && ${QUIET_LINK}${MING_BASE}ar -x ../libpcre2-8.a)
${OSSEC_LINK} $@ ${os_regex_o} $(addprefix libpcre2_objs/,$(shell ${MING_BASE}ar -t libpcre2-8.a))
${OSSEC_RANLIB} $@
rm -rf libpcre2_objs
else
os_regex.a: ${os_regex_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
endif
#### os_net ##########
os_net_c := $(wildcard os_net/*.c)
os_net_o := $(os_net_c:.c=.o)
os_net/%.o: os_net/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
os_net.a: ${os_net_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### Shared ##########
shared_c := $(wildcard shared/*.c)
shared_o := $(shared_c:.c=.o)
shared/%.o: shared/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
shared.a: ${shared_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### Config ##########
config_c := $(wildcard config/*.c)
config_o := $(config_c:.c=.o)
config/%.o: config/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
config.a: ${config_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### crypto ##########
crypto_blowfish_c := os_crypto/blowfish/bf_op.c \
os_crypto/blowfish/bf_skey.c \
os_crypto/blowfish/bf_enc.c
crypto_blowfish_o := $(crypto_blowfish_c:.c=.o)
os_crypto/blowfish/%.o: os_crypto/blowfish/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -Wno-implicit-fallthrough -c $^ -o $@
crypto_md5_c := os_crypto/md5/md5.c \
os_crypto/md5/md5_op.c
crypto_md5_o := $(crypto_md5_c:.c=.o)
os_crypto/md5/%.o: os_crypto/md5/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
crypto_sha1_c := os_crypto/sha1/sha1_op.c
crypto_sha1_o := $(crypto_sha1_c:.c=.o)
os_crypto/sha1/%.o: os_crypto/sha1/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -Wno-implicit-fallthrough -c $^ -o $@
crypto_md5_sha1_c := os_crypto/md5_sha1/md5_sha1_op.c
crypto_md5_sha1_o := $(crypto_md5_sha1_c:.c=.o)
os_crypto/md5_sha1/%.o: os_crypto/md5_sha1/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -c $^ -o $@
crypto_shared_c := $(wildcard os_crypto/shared/*.c)
crypto_shared_o := $(crypto_shared_c:.c=.o)
os_crypto/shared/%.o: os_crypto/shared/%.c ${ZLIB_LIB}
${OSSEC_CC} ${OSSEC_CFLAGS} -c $< -o $@
crypto_o := ${crypto_blowfish_o} \
${crypto_md5_o} \
${crypto_sha1_o} \
${crypto_shared_o} \
${crypto_md5_sha1_o}
os_crypto.a: ${crypto_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@
#### os_mail #########
os_maild_c := $(wildcard os_maild/*.c)
os_maild_o := $(os_maild_c:.c=.o)
os_maild/%.o: os_maild/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -DARGV0=\"ossec-maild\" -c $^ -o $@
ossec-maild: ${os_maild_o} ${ossec_libs}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} $^ ${OSSEC_LDFLAGS} ${DNS_CFLAGS} ${COMPAT_FILES} -o $@
#### os_dbd ##########
os_dbd_c := $(wildcard os_dbd/*.c)
os_dbd_o := $(os_dbd_c:.c=.o)
os_dbd/%.o: os_dbd/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} ${MI} ${PI} -DARGV0=\"ossec-dbd\" -c $^ -o $@
ossec-dbd: ${os_dbd_o} ${ossec_libs}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${MI} ${PI} ${JSON_INCLUDE} $^ -lm ${OSSEC_LDFLAGS} -o $@
#### os_csyslogd #####
os_csyslogd_c := $(wildcard os_csyslogd/*.c)
os_csyslogd_o := $(os_csyslogd_c:.c=.o)
os_csyslogd/%.o: os_csyslogd/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} ${JSON_INCLUDE} -DARGV0=\"ossec-csyslogd\" -c $^ -o $@
ossec-csyslogd: ${os_csyslogd_o} ${ossec_libs} ${JSON_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${JSON_INCLUDE} $^ -lm ${OSSEC_LDFLAGS} -o $@
#### agentlessd ####
os_agentlessd_c := $(wildcard agentlessd/*.c)
os_agentlessd_o := $(os_agentlessd_c:.c=.o)
agentlessd/%.o: agentlessd/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -DARGV0=\"ossec-agentlessd\" -c $^ -o $@
ossec-agentlessd: ${os_agentlessd_o} ${ossec_libs}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} $^ ${OSSEC_LDFLAGS} -o $@
#### os_execd #####
os_execd_c := $(wildcard os_execd/*.c)
os_execd_o := $(os_execd_c:.c=.o)
os_execd/%.o: os_execd/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -DARGV0=\"ossec-execd\" -c $^ -o $@
ossec-execd: ${os_execd_o} ${ossec_libs} ${JSON_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${JSON_INCLUDE} $^ -lm ${OSSEC_LDFLAGS} -o $@
#### logcollectord ####
os_logcollector_c := $(wildcard logcollector/*.c)
os_logcollector_o := $(os_logcollector_c:.c=.o)
os_logcollector_eventchannel_o := $(os_logcollector_c:.c=-event.o)
logcollector/%.o: logcollector/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -DARGV0=\"ossec-logcollector\" -c $^ -o $@
logcollector/%-event.o: logcollector/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -DEVENTCHANNEL_SUPPORT -DARGV0=\"ossec-logcollector\" -c $^ -o $@
ossec-logcollector: ${os_logcollector_o} ${ossec_libs}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} $^ ${OSSEC_LDFLAGS} -o $@