new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / headers / shared.h
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All rights reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 /*
11  *  The stack smashing protector defeats some BoF via: gcc -fstack-protector
12  *  Reference: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/cpp.pdf
13  */
14
15 #if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) && (__GNUC_PATCHLEVEL__ >= 2)) || \
16                           ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || \
17                            (__GNUC__ >= 5))
18
19 /* Heuristically enable the stack protector on sensitive functions */
20 #define __SSP__ 1
21
22 /* FORTIFY_SOURCE is RedHat / Fedora specific */
23 #define FORTIFY_SOURCE
24 #endif
25
26 #ifndef __SHARED_H
27 #define __SHARED_H
28
29 #ifndef _LARGEFILE64_SOURCE
30 #define _LARGEFILE64_SOURCE
31 #endif
32
33 #ifndef _FILE_OFFSET_BITS
34 #define _FILE_OFFSET_BITS 64
35 #endif
36
37 /* Global headers */
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <sys/time.h>
41 #include <sys/param.h>
42
43 #ifdef __OpenBSD__
44 #include <sys/mount.h>
45 #endif
46
47 #ifndef WIN32
48 #include <sys/wait.h>
49
50 /* HPUX does not have select.h */
51 #ifndef HPUX
52 #include <sys/select.h>
53 #endif
54
55 #include <sys/utsname.h>
56 #endif /* WIN32 */
57
58 #include <stdio.h>
59 #include <unistd.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <stdarg.h>
63 #include <fcntl.h>
64 #include <dirent.h>
65 #include <ctype.h>
66 #include <signal.h>
67
68 /* The mingw32 builder used by travis.ci can't find glob.h 
69  * Yet glob must work on actual win32.  
70  */
71 #ifndef __MINGW32__ 
72 #include <glob.h>
73 #endif
74
75 #ifndef WIN32
76 #include <netdb.h>
77 #include <netinet/in.h>
78 #include <arpa/inet.h>
79 #include <sys/socket.h>
80 #include <sys/un.h>
81 #else
82 /* WINVER needs to be 0x0501 or higher to pull in IPv6 functions */
83 #ifndef WINVER
84 #define WINVER  0x0501
85 #endif
86 #include <winsock2.h>
87 #include <windows.h>
88 #include <io.h>
89 #include <ws2tcpip.h>
90 #include <shlwapi.h>
91 #endif
92
93 #include <time.h>
94 #include <errno.h>
95
96 #include "defs.h"
97 #include "help.h"
98
99 #include "os_err.h"
100
101 #ifndef _LARGEFILE64_SOURCE
102 #define _LARGEFILE64_SOURCE
103 #endif
104
105 #ifndef _FILE_OFFSET_BITS
106 #define _FILE_OFFSET_BITS 64
107 #endif
108
109 /* Global portability code */
110
111 #ifdef SOLARIS
112 #include <limits.h>
113 typedef uint32_t u_int32_t;
114 typedef uint16_t u_int16_t;
115 typedef uint8_t u_int8_t;
116
117 #ifndef va_copy
118 #define va_copy __va_copy
119 #endif
120
121 #endif /* SOLARIS */
122
123 #if defined HPUX
124 #include <limits.h>
125 typedef uint32_t u_int32_t;
126 typedef uint16_t u_int16_t;
127 typedef uint8_t u_int8_t;
128
129 #define MSG_DONTWAIT 0
130 #endif
131
132 #ifdef Darwin
133 typedef int sock2len_t;
134 #endif
135
136 #ifndef WIN32
137 #define CloseSocket(x) close(x)
138 #endif
139
140 #ifdef WIN32
141 typedef int uid_t;
142 typedef int gid_t;
143 typedef int socklen_t;
144 #define sleep(x) Sleep(x * 1000)
145 #define srandom(x) srand(x)
146 #define random(x) rand(x)
147 #define lstat(x,y) stat(x,y)
148 #define CloseSocket(x) closesocket(x)
149 void WinSetError();
150 typedef unsigned short int u_int16_t;
151 typedef unsigned char u_int8_t;
152
153 #define MSG_DONTWAIT    0
154
155 #ifndef PROCESSOR_ARCHITECTURE_AMD64
156 #define PROCESSOR_ARCHITECTURE_AMD64 9
157 #endif
158 #endif /* WIN32 */
159
160 #ifdef AIX
161 #define MSG_DONTWAIT MSG_NONBLOCK
162 #endif
163
164 /* Local name */
165 extern const char *__local_name;
166
167 /*** Global prototypes ***/
168 /*** These functions will exit on error. No need to check return code ***/
169
170 /* for calloc: x = calloc(4,sizeof(char)) -> os_calloc(4,sizeof(char),x) */
171 #define os_calloc(x,y,z) ((z = (__typeof__(z)) calloc(x,y)))?(void)1:ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno))
172
173 #define os_strdup(x,y) ((y = strdup(x)))?(void)1:ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno))
174
175 #define os_malloc(x,y) ((y = (__typeof__(y)) malloc(x)))?(void)1:ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno))
176
177 #define os_free(x) (x)?free(x):merror("free a null")
178
179 #define os_realloc(x,y,z) ((z = (__typeof__(z))realloc(x,y)))?(void)1:ErrorExit(MEM_ERROR, __local_name, errno, strerror(errno))
180
181 #define os_clearnl(x,p) if((p = strrchr(x, '\n')))*p = '\0';
182
183 #ifdef CLIENT
184 #define isAgent 1
185 #else
186 #define isAgent 0
187 #endif
188
189 #include "debug_op.h"
190 #include "wait_op.h"
191 #include "agent_op.h"
192 #include "file_op.h"
193 #include "fs_op.h"
194 #include "mem_op.h"
195 #include "math_op.h"
196 #include "mq_op.h"
197 #include "privsep_op.h"
198 #include "pthreads_op.h"
199 #include "regex_op.h"
200 #include "sig_op.h"
201 #include "list_op.h"
202 #include "dirtree_op.h"
203 #include "hash_op.h"
204 #include "store_op.h"
205 #include "rc.h"
206 #include "ar.h"
207 #include "validate_op.h"
208 #include "file-queue.h"
209 #include "read-agents.h"
210 #include "report_op.h"
211 #include "string_op.h"
212 #include "randombytes.h"
213
214 #include "os_xml/os_xml.h"
215 #include "os_regex/os_regex.h"
216
217 #include "error_messages/error_messages.h"
218 #include "custom_output_search.h"
219
220 #endif /* __SHARED_H */
221