openbsd-compat.h revision 248619
1248619Sdes/* $Id: openbsd-compat.h,v 1.55 2013/02/15 01:20:42 dtucker Exp $ */ 298937Sdes 3124208Sdes/* 4124208Sdes * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 5124208Sdes * Copyright (c) 2003 Ben Lindstrom. All rights reserved. 6124208Sdes * Copyright (c) 2002 Tim Rice. All rights reserved. 7124208Sdes * 8124208Sdes * Redistribution and use in source and binary forms, with or without 9124208Sdes * modification, are permitted provided that the following conditions 10124208Sdes * are met: 11124208Sdes * 1. Redistributions of source code must retain the above copyright 12124208Sdes * notice, this list of conditions and the following disclaimer. 13124208Sdes * 2. Redistributions in binary form must reproduce the above copyright 14124208Sdes * notice, this list of conditions and the following disclaimer in the 15124208Sdes * documentation and/or other materials provided with the distribution. 16124208Sdes * 17124208Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18124208Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19124208Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20124208Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21124208Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22124208Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23124208Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24124208Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25124208Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26124208Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27124208Sdes */ 2898937Sdes 29124208Sdes#ifndef _OPENBSD_COMPAT_H 30124208Sdes#define _OPENBSD_COMPAT_H 3198937Sdes 32124208Sdes#include "includes.h" 33124208Sdes 34162852Sdes#include <sys/types.h> 35162852Sdes#include <pwd.h> 36162852Sdes 37162852Sdes#include <sys/socket.h> 38162852Sdes 3998937Sdes/* OpenBSD function replacements */ 4098937Sdes#include "base64.h" 4198937Sdes#include "sigact.h" 4298937Sdes#include "glob.h" 4398937Sdes#include "readpassphrase.h" 44113908Sdes#include "vis.h" 45124208Sdes#include "getrrsetbyname.h" 46162852Sdes#include "sha2.h" 4798937Sdes 48124208Sdes#ifndef HAVE_BASENAME 49124208Sdeschar *basename(const char *path); 50124208Sdes#endif 51124208Sdes 52124208Sdes#ifndef HAVE_BINDRESVPORT_SA 53124208Sdesint bindresvport_sa(int sd, struct sockaddr *sa); 54124208Sdes#endif 55124208Sdes 56137015Sdes#ifndef HAVE_CLOSEFROM 57137015Sdesvoid closefrom(int); 58137015Sdes#endif 59137015Sdes 60124208Sdes#ifndef HAVE_GETCWD 61124208Sdeschar *getcwd(char *pt, size_t size); 62124208Sdes#endif 63124208Sdes 64124208Sdes#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) 65124208Sdeschar *realpath(const char *path, char *resolved); 66124208Sdes#endif 67124208Sdes 68124208Sdes#ifndef HAVE_RRESVPORT_AF 69124208Sdesint rresvport_af(int *alport, sa_family_t af); 70124208Sdes#endif 71124208Sdes 72124208Sdes#ifndef HAVE_STRLCPY 73124208Sdes/* #include <sys/types.h> XXX Still needed? */ 74124208Sdessize_t strlcpy(char *dst, const char *src, size_t siz); 75124208Sdes#endif 76124208Sdes 77124208Sdes#ifndef HAVE_STRLCAT 78124208Sdes/* #include <sys/types.h> XXX Still needed? */ 79124208Sdessize_t strlcat(char *dst, const char *src, size_t siz); 80124208Sdes#endif 81124208Sdes 82124208Sdes#ifndef HAVE_SETENV 83124208Sdesint setenv(register const char *name, register const char *value, int rewrite); 84124208Sdes#endif 85124208Sdes 86124208Sdes#ifndef HAVE_STRMODE 87124208Sdesvoid strmode(int mode, char *p); 88124208Sdes#endif 89124208Sdes 90215116Sdes#ifndef HAVE_STRPTIME 91215116Sdes#include <time.h> 92215116Sdeschar *strptime(const char *buf, const char *fmt, struct tm *tm); 93215116Sdes#endif 94215116Sdes 95124208Sdes#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) 96124208Sdesint mkstemps(char *path, int slen); 97124208Sdesint mkstemp(char *path); 98124208Sdeschar *mkdtemp(char *path); 99124208Sdes#endif 100124208Sdes 101124208Sdes#ifndef HAVE_DAEMON 102124208Sdesint daemon(int nochdir, int noclose); 103124208Sdes#endif 104124208Sdes 105124208Sdes#ifndef HAVE_DIRNAME 106124208Sdeschar *dirname(const char *path); 107124208Sdes#endif 108124208Sdes 109181111Sdes#ifndef HAVE_FMT_SCALED 110181111Sdes#define FMT_SCALED_STRSIZE 7 111181111Sdesint fmt_scaled(long long number, char *result); 112181111Sdes#endif 113181111Sdes 114124208Sdes#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) 115124208Sdeschar *inet_ntoa(struct in_addr in); 116124208Sdes#endif 117124208Sdes 118124208Sdes#ifndef HAVE_INET_NTOP 119240075Sdesconst char *inet_ntop(int af, const void *src, char *dst, socklen_t size); 120124208Sdes#endif 121124208Sdes 122124208Sdes#ifndef HAVE_INET_ATON 123124208Sdesint inet_aton(const char *cp, struct in_addr *addr); 124124208Sdes#endif 125124208Sdes 126124208Sdes#ifndef HAVE_STRSEP 127124208Sdeschar *strsep(char **stringp, const char *delim); 128124208Sdes#endif 129124208Sdes 130124208Sdes#ifndef HAVE_SETPROCTITLE 131124208Sdesvoid setproctitle(const char *fmt, ...); 132124208Sdesvoid compat_init_setproctitle(int argc, char *argv[]); 133124208Sdes#endif 134124208Sdes 135124208Sdes#ifndef HAVE_GETGROUPLIST 136124208Sdes/* #include <grp.h> XXXX Still needed ? */ 137124208Sdesint getgrouplist(const char *, gid_t, gid_t *, int *); 138124208Sdes#endif 139124208Sdes 140124208Sdes#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET) 141124208Sdesint BSDgetopt(int argc, char * const *argv, const char *opts); 142124208Sdes#endif 143124208Sdes 144162852Sdes#if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0 145162852Sdes# include <sys/types.h> 146162852Sdes# include <sys/uio.h> 147162852Sdesint writev(int, struct iovec *, int); 148162852Sdes#endif 149124208Sdes 15098937Sdes/* Home grown routines */ 15198937Sdes#include "bsd-misc.h" 152248619Sdes#include "bsd-setres_id.h" 153181111Sdes#include "bsd-statvfs.h" 15498937Sdes#include "bsd-waitpid.h" 155181111Sdes#include "bsd-poll.h" 15698937Sdes 157124208Sdes#ifndef HAVE_GETPEEREID 158124208Sdesint getpeereid(int , uid_t *, gid_t *); 159124208Sdes#endif 160124208Sdes 161124208Sdes#ifndef HAVE_ARC4RANDOM 162124208Sdesunsigned int arc4random(void); 163124208Sdesvoid arc4random_stir(void); 164124208Sdes#endif /* !HAVE_ARC4RANDOM */ 165124208Sdes 166181111Sdes#ifndef HAVE_ARC4RANDOM_BUF 167181111Sdesvoid arc4random_buf(void *, size_t); 168181111Sdes#endif 169181111Sdes 170181111Sdes#ifndef HAVE_ARC4RANDOM_UNIFORM 171181111Sdesu_int32_t arc4random_uniform(u_int32_t); 172181111Sdes#endif 173181111Sdes 174157016Sdes#ifndef HAVE_ASPRINTF 175157016Sdesint asprintf(char **, const char *, ...); 176157016Sdes#endif 177157016Sdes 178126274Sdes#ifndef HAVE_OPENPTY 179162852Sdes# include <sys/ioctl.h> /* for struct winsize */ 180126274Sdesint openpty(int *, int *, char *, struct termios *, struct winsize *); 181126274Sdes#endif /* HAVE_OPENPTY */ 182124208Sdes 183124208Sdes/* #include <sys/types.h> XXX needed? For size_t */ 184124208Sdes 185124208Sdes#ifndef HAVE_SNPRINTF 186162852Sdesint snprintf(char *, size_t, SNPRINTF_CONST char *, ...); 187124208Sdes#endif 188124208Sdes 189157016Sdes#ifndef HAVE_STRTOLL 190157016Sdeslong long strtoll(const char *, char **, int); 191157016Sdes#endif 192157016Sdes 193248619Sdes#ifndef HAVE_STRTOUL 194248619Sdesunsigned long strtoul(const char *, char **, int); 195248619Sdes#endif 196248619Sdes 197248619Sdes#ifndef HAVE_STRTOULL 198248619Sdesunsigned long long strtoull(const char *, char **, int); 199248619Sdes#endif 200248619Sdes 201149749Sdes#ifndef HAVE_STRTONUM 202149749Sdeslong long strtonum(const char *, long long, long long, const char **); 203149749Sdes#endif 204149749Sdes 205162852Sdes#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) 206162852Sdes# include <stdarg.h> 207162852Sdes#endif 208162852Sdes 209157016Sdes#ifndef HAVE_VASPRINTF 210157016Sdesint vasprintf(char **, const char *, va_list); 211157016Sdes#endif 212157016Sdes 213124208Sdes#ifndef HAVE_VSNPRINTF 214124208Sdesint vsnprintf(char *, size_t, const char *, va_list); 215124208Sdes#endif 216124208Sdes 217204917Sdes#ifndef HAVE_USER_FROM_UID 218204917Sdeschar *user_from_uid(uid_t, int); 219204917Sdes#endif 220204917Sdes 221204917Sdes#ifndef HAVE_GROUP_FROM_GID 222204917Sdeschar *group_from_gid(gid_t, int); 223204917Sdes#endif 224204917Sdes 225221420Sdes#ifndef HAVE_TIMINGSAFE_BCMP 226221420Sdesint timingsafe_bcmp(const void *, const void *, size_t); 227221420Sdes#endif 228221420Sdes 229124208Sdesvoid *xmmap(size_t size); 230124208Sdeschar *xcrypt(const char *password, const char *salt); 231124208Sdeschar *shadow_pw(struct passwd *pw); 232124208Sdes 23398937Sdes/* rfc2553 socket API replacements */ 234124208Sdes#include "fake-rfc2553.h" 23598937Sdes 23698937Sdes/* Routines for a single OS platform */ 23798937Sdes#include "bsd-cray.h" 238124208Sdes#include "bsd-cygwin_util.h" 239162852Sdes 240162852Sdes#include "port-aix.h" 24198937Sdes#include "port-irix.h" 242162852Sdes#include "port-linux.h" 243162852Sdes#include "port-solaris.h" 244162852Sdes#include "port-tun.h" 245149749Sdes#include "port-uw.h" 24698937Sdes 247124208Sdes#endif /* _OPENBSD_COMPAT_H */ 248