openbsd-compat.h revision 240075
1240075Sdes/* $Id: openbsd-compat.h,v 1.52 2011/09/23 01:16:11 djm 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"
152181111Sdes#include "bsd-statvfs.h"
15398937Sdes#include "bsd-waitpid.h"
154181111Sdes#include "bsd-poll.h"
15598937Sdes
156124208Sdes#ifndef HAVE_GETPEEREID
157124208Sdesint getpeereid(int , uid_t *, gid_t *);
158124208Sdes#endif
159124208Sdes
160124208Sdes#ifndef HAVE_ARC4RANDOM
161124208Sdesunsigned int arc4random(void);
162124208Sdesvoid arc4random_stir(void);
163124208Sdes#endif /* !HAVE_ARC4RANDOM */
164124208Sdes
165181111Sdes#ifndef HAVE_ARC4RANDOM_BUF
166181111Sdesvoid arc4random_buf(void *, size_t);
167181111Sdes#endif
168181111Sdes
169181111Sdes#ifndef HAVE_ARC4RANDOM_UNIFORM
170181111Sdesu_int32_t arc4random_uniform(u_int32_t);
171181111Sdes#endif
172181111Sdes
173157016Sdes#ifndef HAVE_ASPRINTF
174157016Sdesint asprintf(char **, const char *, ...);
175157016Sdes#endif
176157016Sdes
177126274Sdes#ifndef HAVE_OPENPTY
178162852Sdes# include <sys/ioctl.h>	/* for struct winsize */
179126274Sdesint openpty(int *, int *, char *, struct termios *, struct winsize *);
180126274Sdes#endif /* HAVE_OPENPTY */
181124208Sdes
182124208Sdes/* #include <sys/types.h> XXX needed? For size_t */
183124208Sdes
184124208Sdes#ifndef HAVE_SNPRINTF
185162852Sdesint snprintf(char *, size_t, SNPRINTF_CONST char *, ...);
186124208Sdes#endif
187124208Sdes
188157016Sdes#ifndef HAVE_STRTOLL
189157016Sdeslong long strtoll(const char *, char **, int);
190157016Sdes#endif
191157016Sdes
192149749Sdes#ifndef HAVE_STRTONUM
193149749Sdeslong long strtonum(const char *, long long, long long, const char **);
194149749Sdes#endif
195149749Sdes
196162852Sdes#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
197162852Sdes# include <stdarg.h>
198162852Sdes#endif
199162852Sdes
200157016Sdes#ifndef HAVE_VASPRINTF
201157016Sdesint vasprintf(char **, const char *, va_list);
202157016Sdes#endif
203157016Sdes
204124208Sdes#ifndef HAVE_VSNPRINTF
205124208Sdesint vsnprintf(char *, size_t, const char *, va_list);
206124208Sdes#endif
207124208Sdes
208204917Sdes#ifndef HAVE_USER_FROM_UID
209204917Sdeschar *user_from_uid(uid_t, int);
210204917Sdes#endif
211204917Sdes
212204917Sdes#ifndef HAVE_GROUP_FROM_GID
213204917Sdeschar *group_from_gid(gid_t, int);
214204917Sdes#endif
215204917Sdes
216221420Sdes#ifndef HAVE_TIMINGSAFE_BCMP
217221420Sdesint timingsafe_bcmp(const void *, const void *, size_t);
218221420Sdes#endif
219221420Sdes
220124208Sdesvoid *xmmap(size_t size);
221124208Sdeschar *xcrypt(const char *password, const char *salt);
222124208Sdeschar *shadow_pw(struct passwd *pw);
223124208Sdes
22498937Sdes/* rfc2553 socket API replacements */
225124208Sdes#include "fake-rfc2553.h"
22698937Sdes
22798937Sdes/* Routines for a single OS platform */
22898937Sdes#include "bsd-cray.h"
229124208Sdes#include "bsd-cygwin_util.h"
230162852Sdes
231162852Sdes#include "port-aix.h"
23298937Sdes#include "port-irix.h"
233162852Sdes#include "port-linux.h"
234162852Sdes#include "port-solaris.h"
235162852Sdes#include "port-tun.h"
236149749Sdes#include "port-uw.h"
23798937Sdes
238124208Sdes#endif /* _OPENBSD_COMPAT_H */
239