summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2003-06-05 18:52:47 +1000
committerDamien Miller <djm@mindrot.org>2003-06-05 18:52:47 +1000
commitc28e38d23a3d074e02c1f63b64569a31d499a0e8 (patch)
treef3e1582ecddf28f770a1ed84c26d64177e735656
parentb95bb7f9b13905ade12cac848e34339ae8a1cc2f (diff)
- (djm) Merge all the openbsd/fake-* into fake-rfc2553.[ch]
-rw-r--r--ChangeLog3
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/fake-gai-errnos.h19
-rw-r--r--openbsd-compat/fake-getaddrinfo.h42
-rw-r--r--openbsd-compat/fake-getnameinfo.c52
-rw-r--r--openbsd-compat/fake-getnameinfo.h26
-rw-r--r--openbsd-compat/fake-rfc2553.c (renamed from openbsd-compat/fake-getaddrinfo.c)44
-rw-r--r--openbsd-compat/fake-rfc2553.h115
-rw-r--r--openbsd-compat/fake-socket.h48
-rw-r--r--openbsd-compat/inet_ntop.c1
-rw-r--r--openbsd-compat/openbsd-compat.h6
-rw-r--r--ssh.h1
12 files changed, 159 insertions, 202 deletions
diff --git a/ChangeLog b/ChangeLog
index 3cfbd1602..25fd59145 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
5 "SetUID demystified" - Hao Chen, David Wagner and Drew Dean 5 "SetUID demystified" - Hao Chen, David Wagner and Drew Dean
6 Proceedings of USENIX Security Symposium 2002 6 Proceedings of USENIX Security Symposium 2002
7 - (djm) Don't use xmalloc() or pull in toplevel headers in fake-* code 7 - (djm) Don't use xmalloc() or pull in toplevel headers in fake-* code
8 - (djm) Merge all the openbsd/fake-* into fake-rfc2553.[ch]
8 9
920030604 1020030604
10 - (djm) Bug #573 - Remove unneeded Krb headers and compat goop. Patch from 11 - (djm) Bug #573 - Remove unneeded Krb headers and compat goop. Patch from
@@ -466,4 +467,4 @@
466 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. 467 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo.
467 Report from murple@murple.net, diagnosis from dtucker@zip.com.au 468 Report from murple@murple.net, diagnosis from dtucker@zip.com.au
468 469
469$Id: ChangeLog,v 1.2784 2003/06/05 00:04:12 djm Exp $ 470$Id: ChangeLog,v 1.2785 2003/06/05 08:52:48 djm Exp $
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index ab6e4e407..fb481efd2 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.26 2003/05/15 02:27:08 djm Exp $ 1# $Id: Makefile.in,v 1.27 2003/06/05 08:52:48 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o 19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o 21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o xmmap.o
22 22
23PORTS=port-irix.o port-aix.o 23PORTS=port-irix.o port-aix.o
24 24
diff --git a/openbsd-compat/fake-gai-errnos.h b/openbsd-compat/fake-gai-errnos.h
deleted file mode 100644
index 8fca7db0c..000000000
--- a/openbsd-compat/fake-gai-errnos.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * fake library for ssh
3 *
4 * This file is included in getaddrinfo.c and getnameinfo.c.
5 * See getaddrinfo.c and getnameinfo.c.
6 */
7
8#ifndef _FAKE_GAI_ERRNOS_H
9#define _FAKE_GAI_ERRNOS_H
10
11/* $Id: fake-gai-errnos.h,v 1.3 2003/05/18 14:13:39 djm Exp $ */
12
13/* for old netdb.h */
14#ifndef EAI_NODATA
15# define EAI_NODATA 1
16# define EAI_MEMORY 2
17#endif
18
19#endif /* !_FAKE_GAI_ERRNOS_H */
diff --git a/openbsd-compat/fake-getaddrinfo.h b/openbsd-compat/fake-getaddrinfo.h
deleted file mode 100644
index 62e93ddbc..000000000
--- a/openbsd-compat/fake-getaddrinfo.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/* $Id: fake-getaddrinfo.h,v 1.6 2003/06/05 00:04:12 djm Exp $ */
2
3#ifndef _FAKE_GETADDRINFO_H
4#define _FAKE_GETADDRINFO_H
5
6#include "config.h"
7
8#include "fake-gai-errnos.h"
9
10#ifndef AI_PASSIVE
11# define AI_PASSIVE (1)
12# define AI_CANONNAME (1<<1)
13# define AI_NUMERICHOST (1<<2)
14#endif
15
16#ifndef HAVE_STRUCT_ADDRINFO
17struct addrinfo {
18 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
19 int ai_family; /* PF_xxx */
20 int ai_socktype; /* SOCK_xxx */
21 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
22 size_t ai_addrlen; /* length of ai_addr */
23 char *ai_canonname; /* canonical name for hostname */
24 struct sockaddr *ai_addr; /* binary address */
25 struct addrinfo *ai_next; /* next structure in linked list */
26};
27#endif /* !HAVE_STRUCT_ADDRINFO */
28
29#ifndef HAVE_GETADDRINFO
30int getaddrinfo(const char *, const char *,
31 const struct addrinfo *, struct addrinfo **);
32#endif /* !HAVE_GETADDRINFO */
33
34#ifndef HAVE_GAI_STRERROR
35char *gai_strerror(int);
36#endif /* !HAVE_GAI_STRERROR */
37
38#ifndef HAVE_FREEADDRINFO
39void freeaddrinfo(struct addrinfo *);
40#endif /* !HAVE_FREEADDRINFO */
41
42#endif /* _FAKE_GETADDRINFO_H */
diff --git a/openbsd-compat/fake-getnameinfo.c b/openbsd-compat/fake-getnameinfo.c
deleted file mode 100644
index f3b0913de..000000000
--- a/openbsd-compat/fake-getnameinfo.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * fake library for ssh
3 *
4 * This file includes getnameinfo().
5 * These funtions are defined in rfc2133.
6 *
7 * But these functions are not implemented correctly. The minimum subset
8 * is implemented for ssh use only. For exapmle, this routine assumes
9 * that ai_family is AF_INET. Don't use it for another purpose.
10 */
11
12#include "includes.h"
13#include "ssh.h"
14
15RCSID("$Id: fake-getnameinfo.c,v 1.3 2003/05/18 14:13:39 djm Exp $");
16
17#ifndef HAVE_GETNAMEINFO
18int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
19 size_t hostlen, char *serv, size_t servlen, int flags)
20{
21 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
22 struct hostent *hp;
23 char tmpserv[16];
24
25 if (serv != NULL) {
26 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
27 if (strlcpy(serv, tmpserv, servlen) >= servlen)
28 return (EAI_MEMORY);
29 }
30
31 if (host != NULL) {
32 if (flags & NI_NUMERICHOST) {
33 if (strlcpy(host, inet_ntoa(sin->sin_addr),
34 hostlen) >= hostlen)
35 return (EAI_MEMORY);
36 else
37 return (0);
38 } else {
39 hp = gethostbyaddr((char *)&sin->sin_addr,
40 sizeof(struct in_addr), AF_INET);
41 if (hp == NULL)
42 return (EAI_NODATA);
43
44 if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
45 return (EAI_MEMORY);
46 else
47 return (0);
48 }
49 }
50 return (0);
51}
52#endif /* !HAVE_GETNAMEINFO */
diff --git a/openbsd-compat/fake-getnameinfo.h b/openbsd-compat/fake-getnameinfo.h
deleted file mode 100644
index 6c1bb30a4..000000000
--- a/openbsd-compat/fake-getnameinfo.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/* $Id: fake-getnameinfo.h,v 1.4 2003/06/04 23:48:33 djm Exp $ */
2
3#ifndef _FAKE_GETNAMEINFO_H
4#define _FAKE_GETNAMEINFO_H
5
6#include "config.h"
7
8#ifndef HAVE_GETNAMEINFO
9int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
10 char *, size_t, int);
11#endif /* !HAVE_GETNAMEINFO */
12
13#ifndef NI_NUMERICHOST
14# define NI_NUMERICHOST (1)
15# define NI_NAMEREQD (1<<1)
16# define NI_NUMERICSERV (1<<2)
17#endif
18
19#ifndef NI_MAXSERV
20# define NI_MAXSERV 32
21#endif /* !NI_MAXSERV */
22#ifndef NI_MAXHOST
23# define NI_MAXHOST 1025
24#endif /* !NI_MAXHOST */
25
26#endif /* _FAKE_GETNAMEINFO_H */
diff --git a/openbsd-compat/fake-getaddrinfo.c b/openbsd-compat/fake-rfc2553.c
index 1ca7ab051..ca13a40bc 100644
--- a/openbsd-compat/fake-getaddrinfo.c
+++ b/openbsd-compat/fake-rfc2553.c
@@ -1,17 +1,49 @@
1/* 1/*
2 * fake library for ssh 2 * Pseudo-implementation of RFC2553 name / address resolution functions
3 *
4 * This file includes getaddrinfo(), freeaddrinfo() and gai_strerror().
5 * These funtions are defined in rfc2133.
6 * 3 *
7 * But these functions are not implemented correctly. The minimum subset 4 * But these functions are not implemented correctly. The minimum subset
8 * is implemented for ssh use only. For exapmle, this routine assumes 5 * is implemented for ssh use only. For exapmle, this routine assumes
9 * that ai_family is AF_INET. Don't use it for another purpose. 6 * that ai_family is AF_INET. Don't use it for another purpose.
10 */ 7 */
11 8
12#include "includes.h" 9RCSID("$Id: fake-rfc2553.c,v 1.1 2003/06/05 08:52:48 djm Exp $");
10
11#ifndef HAVE_GETNAMEINFO
12int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
13 size_t hostlen, char *serv, size_t servlen, int flags)
14{
15 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
16 struct hostent *hp;
17 char tmpserv[16];
18
19 if (serv != NULL) {
20 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
21 if (strlcpy(serv, tmpserv, servlen) >= servlen)
22 return (EAI_MEMORY);
23 }
13 24
14RCSID("$Id: fake-getaddrinfo.c,v 1.10 2003/06/05 00:04:12 djm Exp $"); 25 if (host != NULL) {
26 if (flags & NI_NUMERICHOST) {
27 if (strlcpy(host, inet_ntoa(sin->sin_addr),
28 hostlen) >= hostlen)
29 return (EAI_MEMORY);
30 else
31 return (0);
32 } else {
33 hp = gethostbyaddr((char *)&sin->sin_addr,
34 sizeof(struct in_addr), AF_INET);
35 if (hp == NULL)
36 return (EAI_NODATA);
37
38 if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
39 return (EAI_MEMORY);
40 else
41 return (0);
42 }
43 }
44 return (0);
45}
46#endif /* !HAVE_GETNAMEINFO */
15 47
16#ifndef HAVE_GAI_STRERROR 48#ifndef HAVE_GAI_STRERROR
17char * 49char *
diff --git a/openbsd-compat/fake-rfc2553.h b/openbsd-compat/fake-rfc2553.h
new file mode 100644
index 000000000..d9952bec8
--- /dev/null
+++ b/openbsd-compat/fake-rfc2553.h
@@ -0,0 +1,115 @@
1/*
2 * Pseudo-implementation of RFC2553 name / address resolution functions
3 *
4 * But these functions are not implemented correctly. The minimum subset
5 * is implemented for ssh use only. For exapmle, this routine assumes
6 * that ai_family is AF_INET. Don't use it for another purpose.
7 */
8
9/* $Id: fake-rfc2553.h,v 1.1 2003/06/05 08:52:48 djm Exp $ */
10
11#ifndef _FAKE_RFC2553_H
12#define _FAKE_RFC2553_H
13
14#include "includes.h"
15#include "sys/types.h"
16
17/*
18 * First, socket and INET6 related definitions
19 */
20#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
21# define _SS_MAXSIZE 128 /* Implementation specific max size */
22# define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
23struct sockaddr_storage {
24 struct sockaddr ss_sa;
25 char __ss_pad2[_SS_PADSIZE];
26};
27# define ss_family ss_sa.sa_family
28#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
29
30#ifndef IN6_IS_ADDR_LOOPBACK
31# define IN6_IS_ADDR_LOOPBACK(a) \
32 (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
33 ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
34#endif /* !IN6_IS_ADDR_LOOPBACK */
35
36#ifndef HAVE_STRUCT_IN6_ADDR
37struct in6_addr {
38 u_int8_t s6_addr[16];
39};
40#endif /* !HAVE_STRUCT_IN6_ADDR */
41
42#ifndef HAVE_STRUCT_SOCKADDR_IN6
43struct sockaddr_in6 {
44 unsigned short sin6_family;
45 u_int16_t sin6_port;
46 u_int32_t sin6_flowinfo;
47 struct in6_addr sin6_addr;
48};
49#endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
50
51#ifndef AF_INET6
52/* Define it to something that should never appear */
53#define AF_INET6 AF_MAX
54#endif
55
56/*
57 * Next, RFC2553 name / address resolution API
58 */
59
60#ifndef NI_NUMERICHOST
61# define NI_NUMERICHOST (1)
62# define NI_NAMEREQD (1<<1)
63# define NI_NUMERICSERV (1<<2)
64#endif
65#ifndef AI_PASSIVE
66# define AI_PASSIVE (1)
67# define AI_CANONNAME (1<<1)
68# define AI_NUMERICHOST (1<<2)
69#endif
70
71#ifndef NI_MAXSERV
72# define NI_MAXSERV 32
73#endif /* !NI_MAXSERV */
74#ifndef NI_MAXHOST
75# define NI_MAXHOST 1025
76#endif /* !NI_MAXHOST */
77
78#ifndef EAI_NODATA
79# define EAI_NODATA 1
80# define EAI_MEMORY 2
81#endif
82
83#ifndef HAVE_STRUCT_ADDRINFO
84struct addrinfo {
85 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
86 int ai_family; /* PF_xxx */
87 int ai_socktype; /* SOCK_xxx */
88 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
89 size_t ai_addrlen; /* length of ai_addr */
90 char *ai_canonname; /* canonical name for hostname */
91 struct sockaddr *ai_addr; /* binary address */
92 struct addrinfo *ai_next; /* next structure in linked list */
93};
94#endif /* !HAVE_STRUCT_ADDRINFO */
95
96#ifndef HAVE_GETADDRINFO
97int getaddrinfo(const char *, const char *,
98 const struct addrinfo *, struct addrinfo **);
99#endif /* !HAVE_GETADDRINFO */
100
101#ifndef HAVE_GAI_STRERROR
102char *gai_strerror(int);
103#endif /* !HAVE_GAI_STRERROR */
104
105#ifndef HAVE_FREEADDRINFO
106void freeaddrinfo(struct addrinfo *);
107#endif /* !HAVE_FREEADDRINFO */
108
109#ifndef HAVE_GETNAMEINFO
110int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
111 char *, size_t, int);
112#endif /* !HAVE_GETNAMEINFO */
113
114#endif /* !_FAKE_RFC2553_H */
115
diff --git a/openbsd-compat/fake-socket.h b/openbsd-compat/fake-socket.h
deleted file mode 100644
index 1e0d245e0..000000000
--- a/openbsd-compat/fake-socket.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/* $Id: fake-socket.h,v 1.4 2003/06/04 23:56:35 djm Exp $ */
2
3#ifndef _FAKE_SOCKET_H
4#define _FAKE_SOCKET_H
5
6#include "includes.h"
7#include "sys/types.h"
8
9#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
10
11# define _SS_MAXSIZE 128 /* Implementation specific max size */
12# define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
13
14struct sockaddr_storage {
15 struct sockaddr ss_sa;
16 char __ss_pad2[_SS_PADSIZE];
17};
18# define ss_family ss_sa.sa_family
19#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
20
21#ifndef IN6_IS_ADDR_LOOPBACK
22# define IN6_IS_ADDR_LOOPBACK(a) \
23 (((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
24 ((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
25#endif /* !IN6_IS_ADDR_LOOPBACK */
26
27#ifndef HAVE_STRUCT_IN6_ADDR
28struct in6_addr {
29 u_int8_t s6_addr[16];
30};
31#endif /* !HAVE_STRUCT_IN6_ADDR */
32
33#ifndef HAVE_STRUCT_SOCKADDR_IN6
34struct sockaddr_in6 {
35 unsigned short sin6_family;
36 u_int16_t sin6_port;
37 u_int32_t sin6_flowinfo;
38 struct in6_addr sin6_addr;
39};
40#endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
41
42#ifndef AF_INET6
43/* Define it to something that should never appear */
44#define AF_INET6 AF_MAX
45#endif
46
47#endif /* !_FAKE_SOCKET_H */
48
diff --git a/openbsd-compat/inet_ntop.c b/openbsd-compat/inet_ntop.c
index 3bea519af..075eac44f 100644
--- a/openbsd-compat/inet_ntop.c
+++ b/openbsd-compat/inet_ntop.c
@@ -31,7 +31,6 @@ static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Ex
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/socket.h> 33#include <sys/socket.h>
34#include "openbsd-compat/fake-socket.h"
35#include <netinet/in.h> 34#include <netinet/in.h>
36#include <arpa/inet.h> 35#include <arpa/inet.h>
37#ifndef HAVE_CYGWIN 36#ifndef HAVE_CYGWIN
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 0b660cf92..2c97671b1 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.21 2003/05/15 02:27:08 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.22 2003/06/05 08:52:48 djm Exp $ */
2 2
3#ifndef _OPENBSD_H 3#ifndef _OPENBSD_H
4#define _OPENBSD_H 4#define _OPENBSD_H
@@ -38,9 +38,7 @@
38#include "bsd-waitpid.h" 38#include "bsd-waitpid.h"
39 39
40/* rfc2553 socket API replacements */ 40/* rfc2553 socket API replacements */
41#include "fake-getaddrinfo.h" 41#include "fake-rfc2553.h"
42#include "fake-getnameinfo.h"
43#include "fake-socket.h"
44 42
45/* Routines for a single OS platform */ 43/* Routines for a single OS platform */
46#include "bsd-cray.h" 44#include "bsd-cray.h"
diff --git a/ssh.h b/ssh.h
index 0a6ad1317..a2d47e1ef 100644
--- a/ssh.h
+++ b/ssh.h
@@ -20,7 +20,6 @@
20#include <stdarg.h> /* For va_list */ 20#include <stdarg.h> /* For va_list */
21#include <syslog.h> /* For LOG_AUTH and friends */ 21#include <syslog.h> /* For LOG_AUTH and friends */
22#include <sys/socket.h> /* For struct sockaddr_storage */ 22#include <sys/socket.h> /* For struct sockaddr_storage */
23#include "openbsd-compat/fake-socket.h" /* For struct sockaddr_storage */
24#ifdef HAVE_SYS_SELECT_H 23#ifdef HAVE_SYS_SELECT_H
25# include <sys/select.h> 24# include <sys/select.h>
26#endif 25#endif