PageRenderTime 24ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/openbsd-compat/openbsd-compat.h

https://gitlab.com/adam.lukaitis/Win32-OpenSSH
C Header | 304 lines | 204 code | 60 blank | 40 comment | 12 complexity | 8e3b376a429d57eaee8d0d6d540d27d0 MD5 | raw file
  1. /* $Id: openbsd-compat.h,v 1.51 2010/10/07 10:25:29 djm Exp $ */
  2. /*
  3. * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
  4. * Copyright (c) 2003 Ben Lindstrom. All rights reserved.
  5. * Copyright (c) 2002 Tim Rice. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _OPENBSD_COMPAT_H
  28. #define _OPENBSD_COMPAT_H
  29. #include "includes.h"
  30. #include <sys/types.h>
  31. #include <pwd.h>
  32. #include <sys/socket.h>
  33. /* OpenBSD function replacements */
  34. #include "base64.h"
  35. #include "sigact.h"
  36. #include "glob.h"
  37. #include "readpassphrase.h"
  38. #include "vis.h"
  39. #include "getrrsetbyname.h"
  40. #include "sha1.h"
  41. #include "sha2.h"
  42. #include "rmd160.h"
  43. #include "md5.h"
  44. #include "blf.h"
  45. #ifndef HAVE_BASENAME
  46. char *basename(const char *path);
  47. #endif
  48. #ifndef HAVE_BINDRESVPORT_SA
  49. int bindresvport_sa(int sd, struct sockaddr *sa);
  50. #endif
  51. #ifndef HAVE_CLOSEFROM
  52. void closefrom(int);
  53. #endif
  54. #ifndef HAVE_GETCWD
  55. char *getcwd(char *pt, size_t size);
  56. #endif
  57. #ifndef HAVE_REALLOCARRAY
  58. void *reallocarray(void *, size_t, size_t);
  59. #endif
  60. #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
  61. /*
  62. * glibc's FORTIFY_SOURCE can redefine this and prevent us picking up the
  63. * compat version.
  64. */
  65. # ifdef BROKEN_REALPATH
  66. # define realpath(x, y) _ssh_compat_realpath(x, y)
  67. # endif
  68. char *realpath(const char *path, char *resolved);
  69. #endif
  70. #ifndef HAVE_RRESVPORT_AF
  71. int rresvport_af(int *alport, sa_family_t af);
  72. #endif
  73. #ifndef HAVE_STRLCPY
  74. /* #include <sys/types.h> XXX Still needed? */
  75. size_t strlcpy(char *dst, const char *src, size_t siz);
  76. #endif
  77. #ifndef HAVE_STRLCAT
  78. /* #include <sys/types.h> XXX Still needed? */
  79. size_t strlcat(char *dst, const char *src, size_t siz);
  80. #endif
  81. #ifndef HAVE_SETENV
  82. int setenv(register const char *name, register const char *value, int rewrite);
  83. #endif
  84. #ifndef HAVE_STRMODE
  85. void strmode(int mode, char *p);
  86. #endif
  87. #ifndef HAVE_STRPTIME
  88. #include <time.h>
  89. char *strptime(const char *buf, const char *fmt, struct tm *tm);
  90. #endif
  91. #if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
  92. int mkstemps(char *path, int slen);
  93. int mkstemp(char *path);
  94. char *mkdtemp(char *path);
  95. #endif
  96. #ifndef HAVE_DAEMON
  97. int daemon(int nochdir, int noclose);
  98. #endif
  99. #ifndef HAVE_DIRNAME
  100. char *dirname(const char *path);
  101. #endif
  102. #ifndef HAVE_FMT_SCALED
  103. #define FMT_SCALED_STRSIZE 7
  104. int fmt_scaled(long long number, char *result);
  105. #endif
  106. #ifndef HAVE_SCAN_SCALED
  107. int scan_scaled(char *, long long *);
  108. #endif
  109. #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
  110. char *inet_ntoa(struct in_addr in);
  111. #endif
  112. #ifndef HAVE_INET_NTOP
  113. const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
  114. #endif
  115. #ifndef HAVE_INET_ATON
  116. int inet_aton(const char *cp, struct in_addr *addr);
  117. #endif
  118. #ifndef HAVE_STRSEP
  119. char *strsep(char **stringp, const char *delim);
  120. #endif
  121. #ifndef HAVE_SETPROCTITLE
  122. void setproctitle(const char *fmt, ...);
  123. void compat_init_setproctitle(int argc, char *argv[]);
  124. #endif
  125. #ifndef HAVE_GETGROUPLIST
  126. /* #include <grp.h> XXXX Still needed ? */
  127. int getgrouplist(const char *, gid_t, gid_t *, int *);
  128. #endif
  129. #if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
  130. int BSDgetopt(int argc, char * const *argv, const char *opts);
  131. #include "openbsd-compat/getopt.h"
  132. #endif
  133. #if defined(HAVE_DECL_WRITEV) && HAVE_DECL_WRITEV == 0
  134. # include <sys/types.h>
  135. # include <sys/uio.h>
  136. int writev(int, struct iovec *, int);
  137. #endif
  138. /* Home grown routines */
  139. #include "bsd-misc.h"
  140. #include "bsd-setres_id.h"
  141. #include "bsd-statvfs.h"
  142. #include "bsd-waitpid.h"
  143. #include "bsd-poll.h"
  144. #ifndef HAVE_GETPEEREID
  145. int getpeereid(int , uid_t *, gid_t *);
  146. #endif
  147. #ifdef HAVE_ARC4RANDOM
  148. # ifndef HAVE_ARC4RANDOM_STIR
  149. # define arc4random_stir()
  150. # endif
  151. #else
  152. unsigned int arc4random(void);
  153. void arc4random_stir(void);
  154. #endif /* !HAVE_ARC4RANDOM */
  155. #ifndef HAVE_ARC4RANDOM_BUF
  156. void arc4random_buf(void *, size_t);
  157. #endif
  158. #ifndef HAVE_ARC4RANDOM_UNIFORM
  159. u_int32_t arc4random_uniform(u_int32_t);
  160. #endif
  161. #ifndef HAVE_ASPRINTF
  162. int asprintf(char **, const char *, ...);
  163. #endif
  164. #ifndef HAVE_OPENPTY
  165. # include <sys/ioctl.h> /* for struct winsize */
  166. int openpty(int *, int *, char *, struct termios *, struct winsize *);
  167. #endif /* HAVE_OPENPTY */
  168. /* #include <sys/types.h> XXX needed? For size_t */
  169. #ifndef HAVE_SNPRINTF
  170. int snprintf(char *, size_t, SNPRINTF_CONST char *, ...);
  171. #endif
  172. #ifndef HAVE_STRTOLL
  173. long long strtoll(const char *, char **, int);
  174. #endif
  175. #ifndef HAVE_STRTOUL
  176. unsigned long strtoul(const char *, char **, int);
  177. #endif
  178. #ifndef HAVE_STRTOULL
  179. unsigned long long strtoull(const char *, char **, int);
  180. #endif
  181. #ifndef HAVE_STRTONUM
  182. long long strtonum(const char *, long long, long long, const char **);
  183. #endif
  184. #ifndef WIN32_FIXME
  185. /* multibyte character support */
  186. #ifndef HAVE_MBLEN
  187. # define mblen(x, y) (1)
  188. #endif
  189. #endif
  190. #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
  191. # include <stdarg.h>
  192. #endif
  193. #ifndef HAVE_VASPRINTF
  194. int vasprintf(char **, const char *, va_list);
  195. #endif
  196. #ifndef HAVE_VSNPRINTF
  197. int vsnprintf(char *, size_t, const char *, va_list);
  198. #endif
  199. #ifndef HAVE_USER_FROM_UID
  200. char *user_from_uid(uid_t, int);
  201. #endif
  202. #ifndef HAVE_GROUP_FROM_GID
  203. char *group_from_gid(gid_t, int);
  204. #endif
  205. #ifndef HAVE_TIMINGSAFE_BCMP
  206. int timingsafe_bcmp(const void *, const void *, size_t);
  207. #endif
  208. #ifndef HAVE_BCRYPT_PBKDF
  209. int bcrypt_pbkdf(const char *, size_t, const u_int8_t *, size_t,
  210. u_int8_t *, size_t, unsigned int);
  211. #endif
  212. #ifndef HAVE_EXPLICIT_BZERO
  213. void explicit_bzero(void *p, size_t n);
  214. #endif
  215. void *xmmap(size_t size);
  216. char *xcrypt(const char *password, const char *salt);
  217. char *shadow_pw(struct passwd *pw);
  218. /* rfc2553 socket API replacements */
  219. #include "fake-rfc2553.h"
  220. /* Routines for a single OS platform */
  221. #include "bsd-cray.h"
  222. #include "bsd-cygwin_util.h"
  223. #include "port-aix.h"
  224. #include "port-irix.h"
  225. #include "port-linux.h"
  226. #include "port-solaris.h"
  227. #include "port-tun.h"
  228. #include "port-uw.h"
  229. /* _FORTIFY_SOURCE breaks FD_ISSET(n)/FD_SET(n) for n > FD_SETSIZE. Avoid. */
  230. #if defined(HAVE_FEATURES_H) && defined(_FORTIFY_SOURCE)
  231. # include <features.h>
  232. # if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ)
  233. # if __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0)
  234. # include <sys/socket.h> /* Ensure include guard is defined */
  235. # undef FD_SET
  236. # undef FD_ISSET
  237. # define FD_SET(n, set) kludge_FD_SET(n, set)
  238. # define FD_ISSET(n, set) kludge_FD_ISSET(n, set)
  239. void kludge_FD_SET(int, fd_set *);
  240. int kludge_FD_ISSET(int, fd_set *);
  241. # endif /* __GLIBC_PREREQ(2, 15) && (_FORTIFY_SOURCE > 0) */
  242. # endif /* __GNU_LIBRARY__ && __GLIBC_PREREQ */
  243. #endif /* HAVE_FEATURES_H && _FORTIFY_SOURCE */
  244. #endif /* _OPENBSD_COMPAT_H */