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