1 /* 2 * ProFTPD - FTP server daemon 3 * Copyright (c) 2017 The ProFTPD Project team 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 * 19 * As a special exemption, Public Flood Software/MacGyver aka Habeeb J. Dihu 20 * and other respective copyright holders give permission to link this program 21 * with OpenSSL, and distribute the resulting executable, without including 22 * the source code for OpenSSL in the source distribution. 23 */ 24 25 /* OS/Platform header file includes. */ 26 27 #ifndef PR_OS_H 28 #define PR_OS_H 29 30 #ifndef _GNU_SOURCE 31 # define _GNU_SOURCE 32 #endif 33 34 #include "config.h" 35 36 /* Manually override the socklen_t type on HP-UX 11 boxes. For more 37 * details on why, see: 38 * http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16317 39 */ 40 #if defined(HPUX11) && !defined(_XOPEN_SOURCE_EXTENDED) 41 # undef socklen_t 42 # define socklen_t int 43 #endif 44 45 #include "default_paths.h" 46 47 #include <stdlib.h> 48 #include <stdio.h> 49 #include <stdarg.h> 50 #include <pwd.h> 51 #include <grp.h> 52 53 #ifdef HAVE_STROPTS_H 54 # include <stropts.h> 55 #endif 56 57 #ifdef HAVE_SYS_TYPES_H 58 # include <sys/types.h> 59 #endif 60 61 #ifdef HAVE_INTTYPES_H 62 # include <inttypes.h> 63 #endif 64 65 #ifdef HAVE_UNISTD_H 66 # include <unistd.h> 67 #endif 68 69 #ifdef HAVE_LIMITS_H 70 # include <limits.h> 71 #endif 72 73 #ifdef HAVE_SIGNAL_H 74 # include <signal.h> 75 #endif 76 77 #ifdef HAVE_SYS_ACL_H 78 # include <sys/acl.h> 79 #endif 80 81 #ifdef HAVE_SYS_SELECT_H 82 # include <sys/select.h> 83 #endif 84 85 #ifdef HAVE_SYS_STAT_H 86 # include <sys/stat.h> 87 #endif 88 89 #ifdef HAVE_SYS_FILE_H 90 # include <sys/file.h> 91 #endif 92 93 #ifdef HAVE_SYS_WAIT_H 94 # include <sys/wait.h> 95 #endif 96 97 #ifndef WEXITSTATUS 98 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val)>>8) 99 #endif 100 #ifndef WIFEXITED 101 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 102 #endif 103 104 #ifdef HAVE_MEMORY_H 105 # include <memory.h> 106 #endif 107 108 #ifdef HAVE_STRINGS_H 109 # include <strings.h> 110 #endif 111 112 #ifdef STDC_HEADERS 113 # include <string.h> 114 #else 115 # ifndef HAVE_STRCHR 116 # define strchr index 117 # define strrchr rindex 118 # endif 119 char *strchr(),*strrchr(); 120 # ifndef HAVE_MEMCPY 121 # define memcpy(d,s,n) bcopy((s),(d),(n)) 122 # define memmove(d,s,n) bcopy((s),(d),(n)) 123 # endif 124 #endif 125 126 #ifdef HAVE_BSTRING_H 127 # include <bstring.h> 128 #endif 129 130 #ifdef HAVE_SYS_TIME_H 131 # include <sys/time.h> 132 #endif 133 134 #ifdef HAVE_SYS_PARAM_H 135 # include <sys/param.h> 136 #endif 137 138 #ifdef HAVE_SYS_RESOURCE_H 139 # include <sys/resource.h> 140 #endif 141 142 #ifdef HAVE_SYS_SOCKET_H 143 # include <sys/socket.h> 144 #endif 145 146 #ifdef HAVE_NETDB_H 147 # include <netdb.h> 148 #endif 149 150 #ifdef HAVE_NETINET_IN_H 151 # include <netinet/in.h> 152 #endif 153 154 #ifdef HAVE_NETINET_IN_SYSTM_H 155 # include <netinet/in_systm.h> 156 #endif 157 158 #ifdef HAVE_NETINET_IP_H 159 # include <netinet/ip.h> 160 #endif 161 162 #ifdef HAVE_NETINET_TCP_H 163 # include <netinet/tcp.h> 164 #endif 165 166 #ifdef HAVE_ARPA_INET_H 167 # include <arpa/inet.h> 168 #endif 169 170 #if (defined(HAVE_SHADOW_H) && defined(USESHADOW)) 171 # include <shadow.h> 172 #endif 173 174 #ifndef TM_IN_SYS_TIME 175 # include <time.h> 176 #endif 177 178 #ifdef HAVE_SYSLOG_H 179 # include <syslog.h> 180 #endif 181 182 #ifdef HAVE_DIRENT_H 183 # include <dirent.h> 184 # define NAMLEN(dirent) strlen((dirent)->d_name) 185 #else 186 # define dirent direct 187 # define NAMLEN(dirent) ((dirent)->d_namlen) 188 # ifdef HAVE_SYS_NDIR_H 189 # include <sys/ndir.h> 190 # endif 191 # ifdef HAVE_SYS_DIR_H 192 # include <sys/dir.h> 193 # endif 194 # ifdef HAVE_NDIR_H 195 # include <ndir.h> 196 # endif 197 #endif 198 199 #ifdef HAVE_FCNTL_H 200 # include <fcntl.h> 201 #endif 202 203 #ifdef HAVE_SYS_IOCTL_H 204 # ifdef SOLARIS2 205 # define BSD_COMP 1 206 # endif 207 # include <sys/ioctl.h> 208 #endif 209 210 #ifdef HAVE_ERRNO_H 211 # include <errno.h> 212 #endif 213 214 #ifdef HAVE_CTYPE_H 215 # include <ctype.h> 216 #endif 217 218 #ifdef HAVE_FNMATCH 219 # include <fnmatch.h> 220 #endif 221 222 #ifdef HAVE_UTIME_H 223 # include <utime.h> 224 #endif 225 226 #ifdef HAVE_UTMP_H 227 # include <utmp.h> 228 #endif 229 230 #ifdef HAVE_UTMPX_H 231 # include <utmpx.h> 232 #endif 233 234 /* Solaris 2.5 needs sys/termios.h for TIOCNOTTY. Due to complications 235 * with termio.h/termios.h, prefer to include termios.h. If not found, 236 * then try termio.h 237 */ 238 239 #ifdef HAVE_TERMIOS_H 240 # include <termios.h> 241 #else 242 # ifdef HAVE_SYS_TERMIOS_H 243 # include <sys/termios.h> 244 # else 245 # ifdef HAVE_SYS_TERMIO_H 246 # include <sys/termio.h> 247 # endif /* HAVE_SYS_TERMIO_H */ 248 # endif /* HAVE_SYS_TERMIOS_H */ 249 #endif /* HAVE_TERMIOS_H */ 250 251 #ifdef PR_USE_NLS 252 # ifdef HAVE_LIBINTL_H 253 # include <libintl.h> 254 # endif 255 # define _(str) dgettext("proftpd", str) 256 # ifdef HAVE_LOCALE_H 257 # include <locale.h> 258 # endif 259 #else 260 # define _(str) (str) 261 # define textdomain(dir) 262 # define bindtextdomain(pkg, dir) 263 #endif /* PR_USE_NLS */ 264 265 /* AIX, when compiled using -D_NO_PROTO, lacks some prototypes without 266 * which ProFTPD may do some funny (and not good) things. Provide the 267 * prototypes as necessary here. 268 * 269 * As examples of what these "not good" things might be: 270 * 271 * 1. The ScoreboardFile will grow endlessly; session slots will not 272 * be cleared and reused properly. 273 * 274 * 2. The mod_delay module will complain of being unable to load the 275 * table into memory due to "Invalid argument". 276 */ 277 278 #if defined(_NO_PROTO) && (defined(AIX4) || defined(AIX5)) 279 off_t lseek(int, off_t, int); 280 #endif 281 282 /* See if we have bcopy, if not define them to use the memcpy functions */ 283 284 #ifndef HAVE_BCOPY 285 # define bcopy(s,d,n) memcpy((d),(s),(n)) 286 # define bzero(d,n) memset((d),0,(n)) 287 #endif 288 289 /* Solaris has __vsnprintf, but no vsnprintf */ 290 #if ! defined(HAVE_VSNPRINTF) && defined(HAVE___VSNPRINTF) 291 # undef vsnprintf 292 # define vsnprintf __vsnprintf 293 # define HAVE_VSNPRINTF 1 294 #endif 295 296 #if ! defined(HAVE_SNPRINTF) && defined(HAVE___SNPRINTF) 297 # undef snprintf 298 # define snprintf __snprintf 299 # define HAVE_SNPRINTF 300 #endif 301 302 /* If we are BSD, make minor adjustments */ 303 304 #if defined(BSD) && !defined(O_APPEND) 305 # define O_APPEND F_APPEND 306 #endif 307 308 #ifndef O_NONBLOCK 309 #define O_NONBLOCK O_NDELAY 310 #endif 311 312 #ifndef O_NDELAY 313 #define O_NDELAY O_NONBLOCK 314 #endif 315 316 #if defined(HAVE_GETOPT) && defined(AIX3) 317 /* AIX 3.2.5 libc exports symbol optopt but is forgotten in includes */ 318 extern int optopt; 319 #endif 320 321 /* Necessary for alloca to work */ 322 #if !defined(__alloca) && !defined(__GNU_LIBRARY__) 323 # ifdef __GNUC__ 324 # undef alloca 325 # define alloca(n) __builtin_alloca(n) 326 # else /* Not GCC */ 327 # ifdef HAVE_ALLOCA_H 328 # include <alloca.h> 329 # else /* No HAVE_ALLOCA_H */ 330 # ifndef _AIX 331 # ifdef WINDOWS32 332 # include <malloc.h> 333 # else 334 extern char *alloca(); 335 # endif /* WINDOWS32 */ 336 # endif /* Not _AIX */ 337 # endif /* sparc or HAVE_ALLOCA_H */ 338 # endif /* GCC */ 339 340 # define __alloca alloca 341 342 #endif 343 344 #ifdef HAVE_SETPASSENT 345 # define setpwent() setpassent(1) 346 #endif /* HAVE_SETPASSENT */ 347 348 #ifdef HAVE_SETGROUPENT 349 # define setgrent() setgroupent(1) 350 #endif /* HAVE_SETGROUPENT */ 351 352 #endif /* PR_OS_H */ 353