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