openbsd-compat.h revision 255767
162053Smarkm/* $Id: openbsd-compat.h,v 1.58 2013/06/05 22:30:21 dtucker Exp $ */ 262765Smarkm 362053Smarkm/* 462053Smarkm * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 562053Smarkm * Copyright (c) 2003 Ben Lindstrom. All rights reserved. 662053Smarkm * Copyright (c) 2002 Tim Rice. All rights reserved. 762053Smarkm * 862053Smarkm * Redistribution and use in source and binary forms, with or without 962053Smarkm * modification, are permitted provided that the following conditions 1062053Smarkm * are met: 1162053Smarkm * 1. Redistributions of source code must retain the above copyright 1262053Smarkm * notice, this list of conditions and the following disclaimer. 1362053Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1462053Smarkm * notice, this list of conditions and the following disclaimer in the 1562053Smarkm * documentation and/or other materials provided with the distribution. 1662053Smarkm * 1762053Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1862053Smarkm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1962053Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2062053Smarkm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2162053Smarkm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2262053Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2362053Smarkm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2462053Smarkm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2562053Smarkm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2662053Smarkm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2762053Smarkm */ 2862053Smarkm 2962053Smarkm#ifndef _OPENBSD_COMPAT_H 3062053Smarkm#define _OPENBSD_COMPAT_H 3162053Smarkm 3262053Smarkm#include "includes.h" 3362053Smarkm 3462053Smarkm#include <sys/types.h> 3562765Smarkm#include <pwd.h> 3662053Smarkm 3762053Smarkm#include <sys/socket.h> 3862053Smarkm 3962053Smarkm/* OpenBSD function replacements */ 4062765Smarkm#include "base64.h" 4162053Smarkm#include "sigact.h" 4262053Smarkm#include "glob.h" 4362053Smarkm#include "readpassphrase.h" 4462117Smarkm#include "vis.h" 4562053Smarkm#include "getrrsetbyname.h" 4662765Smarkm#include "sha2.h" 4762053Smarkm 4862765Smarkm#ifndef HAVE_BASENAME 4962765Smarkmchar *basename(const char *path); 5062765Smarkm#endif 5162053Smarkm 5262765Smarkm#ifndef HAVE_BINDRESVPORT_SA 5362765Smarkmint bindresvport_sa(int sd, struct sockaddr *sa); 5462765Smarkm#endif 5562765Smarkm 5662765Smarkm#ifndef HAVE_CLOSEFROM 5762765Smarkmvoid closefrom(int); 5862765Smarkm#endif 5962765Smarkm 6062765Smarkm#ifndef HAVE_GETCWD 6162765Smarkmchar *getcwd(char *pt, size_t size); 6262765Smarkm#endif 6362765Smarkm 6462765Smarkm#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) 6562765Smarkmchar *realpath(const char *path, char *resolved); 6662765Smarkm#endif 6762765Smarkm 6862765Smarkm#ifndef HAVE_RRESVPORT_AF 6962765Smarkmint rresvport_af(int *alport, sa_family_t af); 7062765Smarkm#endif 7162053Smarkm 7262765Smarkm#ifndef HAVE_STRLCPY 7362053Smarkm/* #include <sys/types.h> XXX Still needed? */ 7462765Smarkmsize_t strlcpy(char *dst, const char *src, size_t siz); 7562765Smarkm#endif 7662765Smarkm 7762765Smarkm#ifndef HAVE_STRLCAT 7862765Smarkm/* #include <sys/types.h> XXX Still needed? */ 7962765Smarkmsize_t strlcat(char *dst, const char *src, size_t siz); 8062765Smarkm#endif 8162765Smarkm 8262765Smarkm#ifndef HAVE_SETENV 8362765Smarkmint setenv(register const char *name, register const char *value, int rewrite); 8462765Smarkm#endif 8562053Smarkm 8662053Smarkm#ifndef HAVE_STRMODE 8762053Smarkmvoid strmode(int mode, char *p); 8862765Smarkm#endif 8962053Smarkm 9062765Smarkm#ifndef HAVE_STRPTIME 9162765Smarkm#include <time.h> 9262765Smarkmchar *strptime(const char *buf, const char *fmt, struct tm *tm); 9362765Smarkm#endif 9462765Smarkm 9562765Smarkm#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) 9662765Smarkmint mkstemps(char *path, int slen); 9762765Smarkmint mkstemp(char *path); 9862765Smarkmchar *mkdtemp(char *path); 9962765Smarkm#endif 10062765Smarkm 10162053Smarkm#ifndef HAVE_DAEMON 10262053Smarkmint daemon(int nochdir, int noclose); 10362053Smarkm#endif 10462765Smarkm 10562053Smarkm#ifndef HAVE_DIRNAME 10662053Smarkmchar *dirname(const char *path); 10762765Smarkm#endif 10862765Smarkm 10962765Smarkm#ifndef HAVE_FMT_SCALED 11062765Smarkm#define FMT_SCALED_STRSIZE 7 11162053Smarkmint fmt_scaled(long long number, char *result); 11262053Smarkm#endif 11362053Smarkm 11462765Smarkm#ifndef HAVE_SCAN_SCALED 11562765Smarkmint scan_scaled(char *, long long *); 11662765Smarkm#endif 11762765Smarkm 11862765Smarkm#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) 11962765Smarkmchar *inet_ntoa(struct in_addr in); 12062765Smarkm#endif 12162765Smarkm 12262765Smarkm#ifndef HAVE_INET_NTOP 12362765Smarkmconst char *inet_ntop(int af, const void *src, char *dst, socklen_t size); 12462765Smarkm#endif 12562765Smarkm 12662765Smarkm#ifndef HAVE_INET_ATON 12762765Smarkmint inet_aton(const char *cp, struct in_addr *addr); 12862765Smarkm#endif 12962765Smarkm 13062053Smarkm#ifndef HAVE_STRSEP 13162053Smarkmchar *strsep(char **stringp, const char *delim); 13262765Smarkm#endif 13362765Smarkm 13462765Smarkm#ifndef HAVE_SETPROCTITLE 13562765Smarkmvoid setproctitle(const char *fmt, ...); 13662765Smarkmvoid compat_init_setproctitle(int argc, char *argv[]); 13762765Smarkm#endif 13862765Smarkm 13962765Smarkm#ifndef HAVE_GETGROUPLIST 14062765Smarkm/* #include <grp.h> XXXX Still needed ? */ 14162765Smarkmint getgrouplist(const char *, gid_t, gid_t *, int *); 14262765Smarkm#endif 14362765Smarkm 14462765Smarkm#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET) 14562053Smarkmint BSDgetopt(int argc, char * const *argv, const char *opts); 14662053Smarkm#include "openbsd-compat/getopt.h" 14762053Smarkm#endif 14862765Smarkm 14962765Smarkm#if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0 15062765Smarkm# include <sys/types.h> 15162053Smarkm# include <sys/uio.h> 15262765Smarkmint writev(int, struct iovec *, int); 15362765Smarkm#endif 15462765Smarkm 15562765Smarkm/* Home grown routines */ 15662765Smarkm#include "bsd-misc.h" 15762765Smarkm#include "bsd-setres_id.h" 15862765Smarkm#include "bsd-statvfs.h" 15962765Smarkm#include "bsd-waitpid.h" 16062765Smarkm#include "bsd-poll.h" 16162765Smarkm 16262765Smarkm#ifndef HAVE_GETPEEREID 16362765Smarkmint getpeereid(int , uid_t *, gid_t *); 16462053Smarkm#endif 16562053Smarkm 16662053Smarkm#ifndef HAVE_ARC4RANDOM 16762053Smarkmunsigned int arc4random(void); 16862053Smarkmvoid arc4random_stir(void); 16962765Smarkm#endif /* !HAVE_ARC4RANDOM */ 17062765Smarkm 17162053Smarkm#ifndef HAVE_ARC4RANDOM_BUF 17262765Smarkmvoid arc4random_buf(void *, size_t); 17362053Smarkm#endif 17462765Smarkm 17562053Smarkm#ifndef HAVE_ARC4RANDOM_UNIFORM 17662053Smarkmu_int32_t arc4random_uniform(u_int32_t); 17762765Smarkm#endif 17862053Smarkm 17962053Smarkm#ifndef HAVE_ASPRINTF 18062053Smarkmint asprintf(char **, const char *, ...); 18162765Smarkm#endif 18262765Smarkm 18362765Smarkm#ifndef HAVE_OPENPTY 18462765Smarkm# include <sys/ioctl.h> /* for struct winsize */ 18562765Smarkmint openpty(int *, int *, char *, struct termios *, struct winsize *); 18662053Smarkm#endif /* HAVE_OPENPTY */ 18762765Smarkm 18862053Smarkm/* #include <sys/types.h> XXX needed? For size_t */ 18962765Smarkm 19062765Smarkm#ifndef HAVE_SNPRINTF 19162765Smarkmint snprintf(char *, size_t, SNPRINTF_CONST char *, ...); 19262765Smarkm#endif 19362765Smarkm 19462765Smarkm#ifndef HAVE_STRTOLL 19562053Smarkmlong long strtoll(const char *, char **, int); 19662053Smarkm#endif 19762053Smarkm 19862053Smarkm#ifndef HAVE_STRTOUL 19962053Smarkmunsigned long strtoul(const char *, char **, int); 20062053Smarkm#endif 20162053Smarkm 20262053Smarkm#ifndef HAVE_STRTOULL 20362053Smarkmunsigned long long strtoull(const char *, char **, int); 20462053Smarkm#endif 20562053Smarkm 20662053Smarkm#ifndef HAVE_STRTONUM 20762053Smarkmlong long strtonum(const char *, long long, long long, const char **); 20862053Smarkm#endif 20962053Smarkm 21062053Smarkm/* multibyte character support */ 21162053Smarkm#ifndef HAVE_MBLEN 21262053Smarkm# define mblen(x, y) 1 21362053Smarkm#endif 21462053Smarkm 21562053Smarkm#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) 21662053Smarkm# include <stdarg.h> 21762765Smarkm#endif 21862053Smarkm 21962053Smarkm#ifndef HAVE_VASPRINTF 22062765Smarkmint vasprintf(char **, const char *, va_list); 22162053Smarkm#endif 22262765Smarkm 22362765Smarkm#ifndef HAVE_VSNPRINTF 22462765Smarkmint vsnprintf(char *, size_t, const char *, va_list); 22562765Smarkm#endif 22662765Smarkm 22762765Smarkm#ifndef HAVE_USER_FROM_UID 22862765Smarkmchar *user_from_uid(uid_t, int); 22962765Smarkm#endif 23062053Smarkm 23162765Smarkm#ifndef HAVE_GROUP_FROM_GID 23262053Smarkmchar *group_from_gid(gid_t, int); 23362765Smarkm#endif 23462053Smarkm 23562053Smarkm#ifndef HAVE_TIMINGSAFE_BCMP 23662053Smarkmint timingsafe_bcmp(const void *, const void *, size_t); 23762053Smarkm#endif 23862765Smarkm 23962765Smarkmvoid *xmmap(size_t size); 24062765Smarkmchar *xcrypt(const char *password, const char *salt); 24162765Smarkmchar *shadow_pw(struct passwd *pw); 24262765Smarkm 24362765Smarkm/* rfc2553 socket API replacements */ 24462053Smarkm#include "fake-rfc2553.h" 24562765Smarkm 24662765Smarkm/* Routines for a single OS platform */ 24762053Smarkm#include "bsd-cray.h" 24862765Smarkm#include "bsd-cygwin_util.h" 24962053Smarkm 25062053Smarkm#include "port-aix.h" 25162053Smarkm#include "port-irix.h" 25262053Smarkm#include "port-linux.h" 25362053Smarkm#include "port-solaris.h" 25462053Smarkm#include "port-tun.h" 25562765Smarkm#include "port-uw.h" 25662765Smarkm 25762053Smarkm#endif /* _OPENBSD_COMPAT_H */ 25862053Smarkm