diff options
Diffstat (limited to 'openbsd-compat')
32 files changed, 681 insertions, 129 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index b44a7851e..a60e5a68d 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.41 2007/06/25 12:15:13 dtucker Exp $ | 1 | # $Id: Makefile.in,v 1.43 2008/06/08 17:32:29 dtucker Exp $ |
2 | 2 | ||
3 | sysconfdir=@sysconfdir@ | 3 | sysconfdir=@sysconfdir@ |
4 | piddir=@piddir@ | 4 | piddir=@piddir@ |
@@ -16,9 +16,9 @@ RANLIB=@RANLIB@ | |||
16 | INSTALL=@INSTALL@ | 16 | INSTALL=@INSTALL@ |
17 | LDFLAGS=-L. @LDFLAGS@ | 17 | LDFLAGS=-L. @LDFLAGS@ |
18 | 18 | ||
19 | OPENBSD=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 sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o | 19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.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 sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o |
20 | 20 | ||
21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o | 21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o |
22 | 22 | ||
23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o | 23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o |
24 | 24 | ||
diff --git a/openbsd-compat/base64.c b/openbsd-compat/base64.c index 9a60f583b..9e7466716 100644 --- a/openbsd-compat/base64.c +++ b/openbsd-compat/base64.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: base64.c,v 1.4 2002/01/02 23:00:10 deraadt Exp $ */ | 1 | /* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1996 by Internet Software Consortium. | 4 | * Copyright (c) 1996 by Internet Software Consortium. |
@@ -62,9 +62,6 @@ | |||
62 | 62 | ||
63 | #include "base64.h" | 63 | #include "base64.h" |
64 | 64 | ||
65 | /* XXX abort illegal in library */ | ||
66 | #define Assert(Cond) if (!(Cond)) abort() | ||
67 | |||
68 | static const char Base64[] = | 65 | static const char Base64[] = |
69 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | 66 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
70 | static const char Pad64 = '='; | 67 | static const char Pad64 = '='; |
@@ -151,10 +148,6 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) | |||
151 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | 148 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); |
152 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | 149 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); |
153 | output[3] = input[2] & 0x3f; | 150 | output[3] = input[2] & 0x3f; |
154 | Assert(output[0] < 64); | ||
155 | Assert(output[1] < 64); | ||
156 | Assert(output[2] < 64); | ||
157 | Assert(output[3] < 64); | ||
158 | 151 | ||
159 | if (datalength + 4 > targsize) | 152 | if (datalength + 4 > targsize) |
160 | return (-1); | 153 | return (-1); |
@@ -174,9 +167,6 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) | |||
174 | output[0] = input[0] >> 2; | 167 | output[0] = input[0] >> 2; |
175 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | 168 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); |
176 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | 169 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); |
177 | Assert(output[0] < 64); | ||
178 | Assert(output[1] < 64); | ||
179 | Assert(output[2] < 64); | ||
180 | 170 | ||
181 | if (datalength + 4 > targsize) | 171 | if (datalength + 4 > targsize) |
182 | return (-1); | 172 | return (-1); |
diff --git a/openbsd-compat/bindresvport.c b/openbsd-compat/bindresvport.c index 65afed1e3..c0d5bdb5c 100644 --- a/openbsd-compat/bindresvport.c +++ b/openbsd-compat/bindresvport.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* This file has be substantially modified from the original OpenBSD source */ | 1 | /* This file has be substantially modified from the original OpenBSD source */ |
2 | 2 | ||
3 | /* $OpenBSD: bindresvport.c,v 1.16 2005/04/01 07:44:03 otto Exp $ */ | 3 | /* $OpenBSD: bindresvport.c,v 1.17 2005/12/21 01:40:22 millert Exp $ */ |
4 | 4 | ||
5 | /* | 5 | /* |
6 | * Copyright 1996, Jason Downs. All rights reserved. | 6 | * Copyright 1996, Jason Downs. All rights reserved. |
@@ -54,8 +54,8 @@ bindresvport_sa(int sd, struct sockaddr *sa) | |||
54 | { | 54 | { |
55 | int error, af; | 55 | int error, af; |
56 | struct sockaddr_storage myaddr; | 56 | struct sockaddr_storage myaddr; |
57 | struct sockaddr_in *sin; | 57 | struct sockaddr_in *in; |
58 | struct sockaddr_in6 *sin6; | 58 | struct sockaddr_in6 *in6; |
59 | u_int16_t *portp; | 59 | u_int16_t *portp; |
60 | u_int16_t port; | 60 | u_int16_t port; |
61 | socklen_t salen; | 61 | socklen_t salen; |
@@ -74,13 +74,13 @@ bindresvport_sa(int sd, struct sockaddr *sa) | |||
74 | af = sa->sa_family; | 74 | af = sa->sa_family; |
75 | 75 | ||
76 | if (af == AF_INET) { | 76 | if (af == AF_INET) { |
77 | sin = (struct sockaddr_in *)sa; | 77 | in = (struct sockaddr_in *)sa; |
78 | salen = sizeof(struct sockaddr_in); | 78 | salen = sizeof(struct sockaddr_in); |
79 | portp = &sin->sin_port; | 79 | portp = &in->sin_port; |
80 | } else if (af == AF_INET6) { | 80 | } else if (af == AF_INET6) { |
81 | sin6 = (struct sockaddr_in6 *)sa; | 81 | in6 = (struct sockaddr_in6 *)sa; |
82 | salen = sizeof(struct sockaddr_in6); | 82 | salen = sizeof(struct sockaddr_in6); |
83 | portp = &sin6->sin6_port; | 83 | portp = &in6->sin6_port; |
84 | } else { | 84 | } else { |
85 | errno = EPFNOSUPPORT; | 85 | errno = EPFNOSUPPORT; |
86 | return (-1); | 86 | return (-1); |
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c index d45fb182a..9d4c8690e 100644 --- a/openbsd-compat/bsd-arc4random.c +++ b/openbsd-compat/bsd-arc4random.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | 20 | ||
21 | #include <string.h> | 21 | #include <string.h> |
22 | #include <stdlib.h> | ||
22 | #include <stdarg.h> | 23 | #include <stdarg.h> |
23 | 24 | ||
24 | #include "log.h" | 25 | #include "log.h" |
@@ -82,3 +83,68 @@ arc4random_stir(void) | |||
82 | rc4_ready = REKEY_BYTES; | 83 | rc4_ready = REKEY_BYTES; |
83 | } | 84 | } |
84 | #endif /* !HAVE_ARC4RANDOM */ | 85 | #endif /* !HAVE_ARC4RANDOM */ |
86 | |||
87 | #ifndef ARC4RANDOM_BUF | ||
88 | void | ||
89 | arc4random_buf(void *_buf, size_t n) | ||
90 | { | ||
91 | size_t i; | ||
92 | u_int32_t r = 0; | ||
93 | char *buf = (char *)_buf; | ||
94 | |||
95 | for (i = 0; i < n; i++) { | ||
96 | if (i % 4 == 0) | ||
97 | r = arc4random(); | ||
98 | buf[i] = r & 0xff; | ||
99 | r >>= 8; | ||
100 | } | ||
101 | i = r = 0; | ||
102 | } | ||
103 | #endif /* !HAVE_ARC4RANDOM_BUF */ | ||
104 | |||
105 | #ifndef ARC4RANDOM_UNIFORM | ||
106 | /* | ||
107 | * Calculate a uniformly distributed random number less than upper_bound | ||
108 | * avoiding "modulo bias". | ||
109 | * | ||
110 | * Uniformity is achieved by generating new random numbers until the one | ||
111 | * returned is outside the range [0, 2**32 % upper_bound). This | ||
112 | * guarantees the selected random number will be inside | ||
113 | * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) | ||
114 | * after reduction modulo upper_bound. | ||
115 | */ | ||
116 | u_int32_t | ||
117 | arc4random_uniform(u_int32_t upper_bound) | ||
118 | { | ||
119 | u_int32_t r, min; | ||
120 | |||
121 | if (upper_bound < 2) | ||
122 | return 0; | ||
123 | |||
124 | #if (ULONG_MAX > 0xffffffffUL) | ||
125 | min = 0x100000000UL % upper_bound; | ||
126 | #else | ||
127 | /* Calculate (2**32 % upper_bound) avoiding 64-bit math */ | ||
128 | if (upper_bound > 0x80000000) | ||
129 | min = 1 + ~upper_bound; /* 2**32 - upper_bound */ | ||
130 | else { | ||
131 | /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ | ||
132 | min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; | ||
133 | } | ||
134 | #endif | ||
135 | |||
136 | /* | ||
137 | * This could theoretically loop forever but each retry has | ||
138 | * p > 0.5 (worst case, usually far better) of selecting a | ||
139 | * number inside the range we need, so it should rarely need | ||
140 | * to re-roll. | ||
141 | */ | ||
142 | for (;;) { | ||
143 | r = arc4random(); | ||
144 | if (r >= min) | ||
145 | break; | ||
146 | } | ||
147 | |||
148 | return r % upper_bound; | ||
149 | } | ||
150 | #endif /* !HAVE_ARC4RANDOM_UNIFORM */ | ||
diff --git a/openbsd-compat/bsd-asprintf.c b/openbsd-compat/bsd-asprintf.c index 00fa0dfd8..3368195d4 100644 --- a/openbsd-compat/bsd-asprintf.c +++ b/openbsd-compat/bsd-asprintf.c | |||
@@ -55,6 +55,7 @@ vasprintf(char **str, const char *fmt, va_list ap) | |||
55 | if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ | 55 | if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ |
56 | *str = string; | 56 | *str = string; |
57 | } else if (ret == INT_MAX || ret < 0) { /* Bad length */ | 57 | } else if (ret == INT_MAX || ret < 0) { /* Bad length */ |
58 | free(string); | ||
58 | goto fail; | 59 | goto fail; |
59 | } else { /* bigger than initial, realloc allowing for nul */ | 60 | } else { /* bigger than initial, realloc allowing for nul */ |
60 | len = (size_t)ret + 1; | 61 | len = (size_t)ret + 1; |
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c index dbf8176b6..38be7e350 100644 --- a/openbsd-compat/bsd-cygwin_util.c +++ b/openbsd-compat/bsd-cygwin_util.c | |||
@@ -175,45 +175,7 @@ check_nt_auth(int pwd_authenticated, struct passwd *pw) | |||
175 | int | 175 | int |
176 | check_ntsec(const char *filename) | 176 | check_ntsec(const char *filename) |
177 | { | 177 | { |
178 | char *cygwin; | 178 | return (pathconf(filename, _PC_POSIX_PERMISSIONS)); |
179 | int allow_ntea = 0, allow_ntsec = 0; | ||
180 | struct statfs fsstat; | ||
181 | |||
182 | /* Windows 95/98/ME don't support file system security at all. */ | ||
183 | if (!is_winnt) | ||
184 | return (0); | ||
185 | |||
186 | /* Evaluate current CYGWIN settings. */ | ||
187 | cygwin = getenv("CYGWIN"); | ||
188 | allow_ntea = ntea_on(cygwin); | ||
189 | allow_ntsec = ntsec_on(cygwin) || | ||
190 | (has_capability(HAS_NTSEC_BY_DEFAULT) && !ntsec_off(cygwin)); | ||
191 | |||
192 | /* | ||
193 | * `ntea' is an emulation of POSIX attributes. It doesn't support | ||
194 | * real file level security as ntsec on NTFS file systems does | ||
195 | * but it supports FAT filesystems. `ntea' is minimum requirement | ||
196 | * for security checks. | ||
197 | */ | ||
198 | if (allow_ntea) | ||
199 | return (1); | ||
200 | |||
201 | /* | ||
202 | * Retrieve file system flags. In Cygwin, file system flags are | ||
203 | * copied to f_type which has no meaning in Win32 itself. | ||
204 | */ | ||
205 | if (statfs(filename, &fsstat)) | ||
206 | return (1); | ||
207 | |||
208 | /* | ||
209 | * Only file systems supporting ACLs are able to set permissions. | ||
210 | * `ntsec' is the setting in Cygwin which switches using of NTFS | ||
211 | * ACLs to support POSIX permissions on files. | ||
212 | */ | ||
213 | if (fsstat.f_type & FS_PERSISTENT_ACLS) | ||
214 | return (allow_ntsec); | ||
215 | |||
216 | return (0); | ||
217 | } | 179 | } |
218 | 180 | ||
219 | void | 181 | void |
diff --git a/openbsd-compat/bsd-poll.c b/openbsd-compat/bsd-poll.c index 836882eea..284db3a1f 100644 --- a/openbsd-compat/bsd-poll.c +++ b/openbsd-compat/bsd-poll.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: bsd-poll.c,v 1.1 2007/06/25 12:15:13 dtucker Exp $ */ | 1 | /* $Id: bsd-poll.c,v 1.3 2008/04/04 05:16:36 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au). | 4 | * Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au). |
@@ -17,12 +17,13 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | #if !defined(HAVE_POLL) && defined(HAVE_SELECT) | 20 | #if !defined(HAVE_POLL) |
21 | 21 | ||
22 | #ifdef HAVE_SYS_SELECT_H | 22 | #ifdef HAVE_SYS_SELECT_H |
23 | # include <sys/select.h> | 23 | # include <sys/select.h> |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #include <stdlib.h> | ||
26 | #include <errno.h> | 27 | #include <errno.h> |
27 | #include "bsd-poll.h" | 28 | #include "bsd-poll.h" |
28 | 29 | ||
diff --git a/openbsd-compat/bsd-statvfs.c b/openbsd-compat/bsd-statvfs.c new file mode 100644 index 000000000..844d5b464 --- /dev/null +++ b/openbsd-compat/bsd-statvfs.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /* $Id: bsd-statvfs.c,v 1.1 2008/06/08 17:32:29 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Darren Tucker <dtucker@zip.com.au> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | ||
15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | ||
16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | |||
21 | #include <errno.h> | ||
22 | |||
23 | #ifndef HAVE_STATVFS | ||
24 | int statvfs(const char *path, struct statvfs *buf) | ||
25 | { | ||
26 | errno = ENOSYS; | ||
27 | return -1; | ||
28 | } | ||
29 | #endif | ||
30 | |||
31 | #ifndef HAVE_FSTATVFS | ||
32 | int fstatvfs(int fd, struct statvfs *buf) | ||
33 | { | ||
34 | errno = ENOSYS; | ||
35 | return -1; | ||
36 | } | ||
37 | #endif | ||
diff --git a/openbsd-compat/bsd-statvfs.h b/openbsd-compat/bsd-statvfs.h new file mode 100644 index 000000000..da215ffc6 --- /dev/null +++ b/openbsd-compat/bsd-statvfs.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* $Id: bsd-statvfs.h,v 1.1 2008/06/08 17:32:29 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Darren Tucker <dtucker@zip.com.au> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | ||
15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | ||
16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | #ifdef HAVE_SYS_STATFS_H | ||
24 | #include <sys/statfs.h> | ||
25 | #endif | ||
26 | |||
27 | #ifndef HAVE_STATVFS | ||
28 | |||
29 | #ifndef HAVE_FSBLKCNT_T | ||
30 | typedef unsigned long fsblkcnt_t; | ||
31 | #endif | ||
32 | #ifndef HAVE_FSFILCNT_T | ||
33 | typedef unsigned long fsfilcnt_t; | ||
34 | #endif | ||
35 | |||
36 | #ifndef ST_RDONLY | ||
37 | #define ST_RDONLY 1 | ||
38 | #endif | ||
39 | #ifndef ST_NOSUID | ||
40 | #define ST_NOSUID 2 | ||
41 | #endif | ||
42 | |||
43 | /* as defined in IEEE Std 1003.1, 2004 Edition */ | ||
44 | struct statvfs { | ||
45 | unsigned long f_bsize; /* File system block size. */ | ||
46 | unsigned long f_frsize; /* Fundamental file system block size. */ | ||
47 | fsblkcnt_t f_blocks; /* Total number of blocks on file system in */ | ||
48 | /* units of f_frsize. */ | ||
49 | fsblkcnt_t f_bfree; /* Total number of free blocks. */ | ||
50 | fsblkcnt_t f_bavail; /* Number of free blocks available to */ | ||
51 | /* non-privileged process. */ | ||
52 | fsfilcnt_t f_files; /* Total number of file serial numbers. */ | ||
53 | fsfilcnt_t f_ffree; /* Total number of free file serial numbers. */ | ||
54 | fsfilcnt_t f_favail; /* Number of file serial numbers available to */ | ||
55 | /* non-privileged process. */ | ||
56 | unsigned long f_fsid; /* File system ID. */ | ||
57 | unsigned long f_flag; /* BBit mask of f_flag values. */ | ||
58 | unsigned long f_namemax;/* Maximum filename length. */ | ||
59 | }; | ||
60 | #endif | ||
61 | |||
62 | #ifndef HAVE_STATVFS | ||
63 | int statvfs(const char *, struct statvfs *); | ||
64 | #endif | ||
65 | |||
66 | #ifndef HAVE_FSTATVFS | ||
67 | int fstatvfs(int, struct statvfs *); | ||
68 | #endif | ||
diff --git a/openbsd-compat/fake-rfc2553.c b/openbsd-compat/fake-rfc2553.c index b6ea3d21e..096d9e092 100644 --- a/openbsd-compat/fake-rfc2553.c +++ b/openbsd-compat/fake-rfc2553.c | |||
@@ -51,6 +51,8 @@ int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, | |||
51 | struct hostent *hp; | 51 | struct hostent *hp; |
52 | char tmpserv[16]; | 52 | char tmpserv[16]; |
53 | 53 | ||
54 | if (sa->sa_family != AF_UNSPEC && sa->sa_family != AF_INET) | ||
55 | return (EAI_FAMILY); | ||
54 | if (serv != NULL) { | 56 | if (serv != NULL) { |
55 | snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); | 57 | snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); |
56 | if (strlcpy(serv, tmpserv, servlen) >= servlen) | 58 | if (strlcpy(serv, tmpserv, servlen) >= servlen) |
@@ -95,6 +97,8 @@ gai_strerror(int err) | |||
95 | return ("memory allocation failure."); | 97 | return ("memory allocation failure."); |
96 | case EAI_NONAME: | 98 | case EAI_NONAME: |
97 | return ("nodename nor servname provided, or not known"); | 99 | return ("nodename nor servname provided, or not known"); |
100 | case EAI_FAMILY: | ||
101 | return ("ai_family not supported"); | ||
98 | default: | 102 | default: |
99 | return ("unknown/invalid error."); | 103 | return ("unknown/invalid error."); |
100 | } | 104 | } |
@@ -159,6 +163,9 @@ getaddrinfo(const char *hostname, const char *servname, | |||
159 | u_long addr; | 163 | u_long addr; |
160 | 164 | ||
161 | port = 0; | 165 | port = 0; |
166 | if (hints && hints->ai_family != AF_UNSPEC && | ||
167 | hints->ai_family != AF_INET) | ||
168 | return (EAI_FAMILY); | ||
162 | if (servname != NULL) { | 169 | if (servname != NULL) { |
163 | char *cp; | 170 | char *cp; |
164 | 171 | ||
diff --git a/openbsd-compat/fake-rfc2553.h b/openbsd-compat/fake-rfc2553.h index 5c2ce5b1b..3e9090fc8 100644 --- a/openbsd-compat/fake-rfc2553.h +++ b/openbsd-compat/fake-rfc2553.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: fake-rfc2553.h,v 1.13 2006/07/24 03:51:52 djm Exp $ */ | 1 | /* $Id: fake-rfc2553.h,v 1.16 2008/07/14 11:37:37 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (C) 2000-2003 Damien Miller. All rights reserved. | 4 | * Copyright (C) 2000-2003 Damien Miller. All rights reserved. |
@@ -77,6 +77,7 @@ struct sockaddr_in6 { | |||
77 | u_int16_t sin6_port; | 77 | u_int16_t sin6_port; |
78 | u_int32_t sin6_flowinfo; | 78 | u_int32_t sin6_flowinfo; |
79 | struct in6_addr sin6_addr; | 79 | struct in6_addr sin6_addr; |
80 | u_int32_t sin6_scope_id; | ||
80 | }; | 81 | }; |
81 | #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */ | 82 | #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */ |
82 | 83 | ||
@@ -128,6 +129,9 @@ struct sockaddr_in6 { | |||
128 | #ifndef EAI_SYSTEM | 129 | #ifndef EAI_SYSTEM |
129 | # define EAI_SYSTEM (INT_MAX - 4) | 130 | # define EAI_SYSTEM (INT_MAX - 4) |
130 | #endif | 131 | #endif |
132 | #ifndef EAI_FAMILY | ||
133 | # define EAI_FAMILY (INT_MAX - 5) | ||
134 | #endif | ||
131 | 135 | ||
132 | #ifndef HAVE_STRUCT_ADDRINFO | 136 | #ifndef HAVE_STRUCT_ADDRINFO |
133 | struct addrinfo { | 137 | struct addrinfo { |
@@ -152,7 +156,7 @@ int getaddrinfo(const char *, const char *, | |||
152 | #endif /* !HAVE_GETADDRINFO */ | 156 | #endif /* !HAVE_GETADDRINFO */ |
153 | 157 | ||
154 | #if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO) | 158 | #if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO) |
155 | #define gai_strerror(a) (ssh_gai_strerror(a)) | 159 | #define gai_strerror(a) (_ssh_compat_gai_strerror(a)) |
156 | char *gai_strerror(int); | 160 | char *gai_strerror(int); |
157 | #endif /* !HAVE_GAI_STRERROR */ | 161 | #endif /* !HAVE_GAI_STRERROR */ |
158 | 162 | ||
diff --git a/openbsd-compat/fmt_scaled.c b/openbsd-compat/fmt_scaled.c new file mode 100644 index 000000000..edd682a49 --- /dev/null +++ b/openbsd-compat/fmt_scaled.c | |||
@@ -0,0 +1,274 @@ | |||
1 | /* $OpenBSD: fmt_scaled.c,v 1.9 2007/03/20 03:42:52 tedu Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * 3. The name of the author may not be used to endorse or promote products | ||
15 | * derived from this software without specific prior written permission. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | */ | ||
28 | |||
29 | /* OPENBSD ORIGINAL: lib/libutil/fmt_scaled.c */ | ||
30 | |||
31 | /* | ||
32 | * fmt_scaled: Format numbers scaled for human comprehension | ||
33 | * scan_scaled: Scan numbers in this format. | ||
34 | * | ||
35 | * "Human-readable" output uses 4 digits max, and puts a unit suffix at | ||
36 | * the end. Makes output compact and easy-to-read esp. on huge disks. | ||
37 | * Formatting code was originally in OpenBSD "df", converted to library routine. | ||
38 | * Scanning code written for OpenBSD libutil. | ||
39 | */ | ||
40 | |||
41 | #include "includes.h" | ||
42 | |||
43 | #ifndef HAVE_FMT_SCALED | ||
44 | |||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <errno.h> | ||
48 | #include <string.h> | ||
49 | #include <ctype.h> | ||
50 | #include <limits.h> | ||
51 | |||
52 | typedef enum { | ||
53 | NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6 | ||
54 | } unit_type; | ||
55 | |||
56 | /* These three arrays MUST be in sync! XXX make a struct */ | ||
57 | static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA }; | ||
58 | static char scale_chars[] = "BKMGTPE"; | ||
59 | static long long scale_factors[] = { | ||
60 | 1LL, | ||
61 | 1024LL, | ||
62 | 1024LL*1024, | ||
63 | 1024LL*1024*1024, | ||
64 | 1024LL*1024*1024*1024, | ||
65 | 1024LL*1024*1024*1024*1024, | ||
66 | 1024LL*1024*1024*1024*1024*1024, | ||
67 | }; | ||
68 | #define SCALE_LENGTH (sizeof(units)/sizeof(units[0])) | ||
69 | |||
70 | #define MAX_DIGITS (SCALE_LENGTH * 3) /* XXX strlen(sprintf("%lld", -1)? */ | ||
71 | |||
72 | /** Convert the given input string "scaled" into numeric in "result". | ||
73 | * Return 0 on success, -1 and errno set on error. | ||
74 | */ | ||
75 | int | ||
76 | scan_scaled(char *scaled, long long *result) | ||
77 | { | ||
78 | char *p = scaled; | ||
79 | int sign = 0; | ||
80 | unsigned int i, ndigits = 0, fract_digits = 0; | ||
81 | long long scale_fact = 1, whole = 0, fpart = 0; | ||
82 | |||
83 | /* Skip leading whitespace */ | ||
84 | while (isascii(*p) && isspace(*p)) | ||
85 | ++p; | ||
86 | |||
87 | /* Then at most one leading + or - */ | ||
88 | while (*p == '-' || *p == '+') { | ||
89 | if (*p == '-') { | ||
90 | if (sign) { | ||
91 | errno = EINVAL; | ||
92 | return -1; | ||
93 | } | ||
94 | sign = -1; | ||
95 | ++p; | ||
96 | } else if (*p == '+') { | ||
97 | if (sign) { | ||
98 | errno = EINVAL; | ||
99 | return -1; | ||
100 | } | ||
101 | sign = +1; | ||
102 | ++p; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /* Main loop: Scan digits, find decimal point, if present. | ||
107 | * We don't allow exponentials, so no scientific notation | ||
108 | * (but note that E for Exa might look like e to some!). | ||
109 | * Advance 'p' to end, to get scale factor. | ||
110 | */ | ||
111 | for (; isascii(*p) && (isdigit(*p) || *p=='.'); ++p) { | ||
112 | if (*p == '.') { | ||
113 | if (fract_digits > 0) { /* oops, more than one '.' */ | ||
114 | errno = EINVAL; | ||
115 | return -1; | ||
116 | } | ||
117 | fract_digits = 1; | ||
118 | continue; | ||
119 | } | ||
120 | |||
121 | i = (*p) - '0'; /* whew! finally a digit we can use */ | ||
122 | if (fract_digits > 0) { | ||
123 | if (fract_digits >= MAX_DIGITS-1) | ||
124 | /* ignore extra fractional digits */ | ||
125 | continue; | ||
126 | fract_digits++; /* for later scaling */ | ||
127 | fpart *= 10; | ||
128 | fpart += i; | ||
129 | } else { /* normal digit */ | ||
130 | if (++ndigits >= MAX_DIGITS) { | ||
131 | errno = ERANGE; | ||
132 | return -1; | ||
133 | } | ||
134 | whole *= 10; | ||
135 | whole += i; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | if (sign) { | ||
140 | whole *= sign; | ||
141 | fpart *= sign; | ||
142 | } | ||
143 | |||
144 | /* If no scale factor given, we're done. fraction is discarded. */ | ||
145 | if (!*p) { | ||
146 | *result = whole; | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | /* Validate scale factor, and scale whole and fraction by it. */ | ||
151 | for (i = 0; i < SCALE_LENGTH; i++) { | ||
152 | |||
153 | /** Are we there yet? */ | ||
154 | if (*p == scale_chars[i] || | ||
155 | *p == tolower(scale_chars[i])) { | ||
156 | |||
157 | /* If it ends with alphanumerics after the scale char, bad. */ | ||
158 | if (isalnum(*(p+1))) { | ||
159 | errno = EINVAL; | ||
160 | return -1; | ||
161 | } | ||
162 | scale_fact = scale_factors[i]; | ||
163 | |||
164 | /* scale whole part */ | ||
165 | whole *= scale_fact; | ||
166 | |||
167 | /* truncate fpart so it does't overflow. | ||
168 | * then scale fractional part. | ||
169 | */ | ||
170 | while (fpart >= LLONG_MAX / scale_fact) { | ||
171 | fpart /= 10; | ||
172 | fract_digits--; | ||
173 | } | ||
174 | fpart *= scale_fact; | ||
175 | if (fract_digits > 0) { | ||
176 | for (i = 0; i < fract_digits -1; i++) | ||
177 | fpart /= 10; | ||
178 | } | ||
179 | whole += fpart; | ||
180 | *result = whole; | ||
181 | return 0; | ||
182 | } | ||
183 | } | ||
184 | errno = ERANGE; | ||
185 | return -1; | ||
186 | } | ||
187 | |||
188 | /* Format the given "number" into human-readable form in "result". | ||
189 | * Result must point to an allocated buffer of length FMT_SCALED_STRSIZE. | ||
190 | * Return 0 on success, -1 and errno set if error. | ||
191 | */ | ||
192 | int | ||
193 | fmt_scaled(long long number, char *result) | ||
194 | { | ||
195 | long long abval, fract = 0; | ||
196 | unsigned int i; | ||
197 | unit_type unit = NONE; | ||
198 | |||
199 | abval = (number < 0LL) ? -number : number; /* no long long_abs yet */ | ||
200 | |||
201 | /* Not every negative long long has a positive representation. | ||
202 | * Also check for numbers that are just too darned big to format | ||
203 | */ | ||
204 | if (abval < 0 || abval / 1024 >= scale_factors[SCALE_LENGTH-1]) { | ||
205 | errno = ERANGE; | ||
206 | return -1; | ||
207 | } | ||
208 | |||
209 | /* scale whole part; get unscaled fraction */ | ||
210 | for (i = 0; i < SCALE_LENGTH; i++) { | ||
211 | if (abval/1024 < scale_factors[i]) { | ||
212 | unit = units[i]; | ||
213 | fract = (i == 0) ? 0 : abval % scale_factors[i]; | ||
214 | number /= scale_factors[i]; | ||
215 | if (i > 0) | ||
216 | fract /= scale_factors[i - 1]; | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | fract = (10 * fract + 512) / 1024; | ||
222 | /* if the result would be >= 10, round main number */ | ||
223 | if (fract == 10) { | ||
224 | if (number >= 0) | ||
225 | number++; | ||
226 | else | ||
227 | number--; | ||
228 | fract = 0; | ||
229 | } | ||
230 | |||
231 | if (number == 0) | ||
232 | strlcpy(result, "0B", FMT_SCALED_STRSIZE); | ||
233 | else if (unit == NONE || number >= 100 || number <= -100) { | ||
234 | if (fract >= 5) { | ||
235 | if (number >= 0) | ||
236 | number++; | ||
237 | else | ||
238 | number--; | ||
239 | } | ||
240 | (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c", | ||
241 | number, scale_chars[unit]); | ||
242 | } else | ||
243 | (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c", | ||
244 | number, fract, scale_chars[unit]); | ||
245 | |||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | #ifdef MAIN | ||
250 | /* | ||
251 | * This is the original version of the program in the man page. | ||
252 | * Copy-and-paste whatever you need from it. | ||
253 | */ | ||
254 | int | ||
255 | main(int argc, char **argv) | ||
256 | { | ||
257 | char *cinput = "1.5K", buf[FMT_SCALED_STRSIZE]; | ||
258 | long long ninput = 10483892, result; | ||
259 | |||
260 | if (scan_scaled(cinput, &result) == 0) | ||
261 | printf("\"%s\" -> %lld\n", cinput, result); | ||
262 | else | ||
263 | perror(cinput); | ||
264 | |||
265 | if (fmt_scaled(ninput, buf) == 0) | ||
266 | printf("%lld -> \"%s\"\n", ninput, buf); | ||
267 | else | ||
268 | fprintf(stderr, "%lld invalid (%s)\n", ninput, strerror(errno)); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | #endif | ||
273 | |||
274 | #endif /* HAVE_FMT_SCALED */ | ||
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c index 80af3f542..785b22569 100644 --- a/openbsd-compat/getrrsetbyname.c +++ b/openbsd-compat/getrrsetbyname.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getrrsetbyname.c,v 1.10 2005/03/30 02:58:28 tedu Exp $ */ | 1 | /* $OpenBSD: getrrsetbyname.c,v 1.11 2007/10/11 18:36:41 jakob Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. | 4 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. |
@@ -288,7 +288,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
288 | rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass, | 288 | rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass, |
289 | rrset->rri_rdtype); | 289 | rrset->rri_rdtype); |
290 | rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass, | 290 | rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass, |
291 | T_SIG); | 291 | T_RRSIG); |
292 | 292 | ||
293 | /* allocate memory for answers */ | 293 | /* allocate memory for answers */ |
294 | rrset->rri_rdatas = calloc(rrset->rri_nrdatas, | 294 | rrset->rri_rdatas = calloc(rrset->rri_nrdatas, |
@@ -318,7 +318,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
318 | rdata = &rrset->rri_rdatas[index_ans++]; | 318 | rdata = &rrset->rri_rdatas[index_ans++]; |
319 | 319 | ||
320 | if (rr->class == rrset->rri_rdclass && | 320 | if (rr->class == rrset->rri_rdclass && |
321 | rr->type == T_SIG) | 321 | rr->type == T_RRSIG) |
322 | rdata = &rrset->rri_sigs[index_sig++]; | 322 | rdata = &rrset->rri_sigs[index_sig++]; |
323 | 323 | ||
324 | if (rdata) { | 324 | if (rdata) { |
diff --git a/openbsd-compat/getrrsetbyname.h b/openbsd-compat/getrrsetbyname.h index 39995b63f..1283f5506 100644 --- a/openbsd-compat/getrrsetbyname.h +++ b/openbsd-compat/getrrsetbyname.h | |||
@@ -62,8 +62,8 @@ | |||
62 | #define HFIXEDSZ 12 | 62 | #define HFIXEDSZ 12 |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #ifndef T_SIG | 65 | #ifndef T_RRSIG |
66 | #define T_SIG 24 | 66 | #define T_RRSIG 46 |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | /* | 69 | /* |
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index b3dd2b171..74b506403 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: glob.c,v 1.25 2005/08/08 08:05:34 espie Exp $ */ | 1 | /* $OpenBSD: glob.c,v 1.26 2005/11/28 17:50:12 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1989, 1993 | 3 | * Copyright (c) 1989, 1993 |
4 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -48,7 +48,8 @@ | |||
48 | 48 | ||
49 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | 49 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ |
50 | !defined(GLOB_HAS_GL_MATCHC) || \ | 50 | !defined(GLOB_HAS_GL_MATCHC) || \ |
51 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 | 51 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ |
52 | defined(BROKEN_GLOB) | ||
52 | 53 | ||
53 | static long | 54 | static long |
54 | get_arg_max(void) | 55 | get_arg_max(void) |
@@ -149,7 +150,7 @@ static int glob0(const Char *, glob_t *); | |||
149 | static int glob1(Char *, Char *, glob_t *, size_t *); | 150 | static int glob1(Char *, Char *, glob_t *, size_t *); |
150 | static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, | 151 | static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, |
151 | glob_t *, size_t *); | 152 | glob_t *, size_t *); |
152 | static int glob3(Char *, Char *, Char *, Char *, Char *, Char *, | 153 | static int glob3(Char *, Char *, Char *, Char *, Char *, |
153 | Char *, Char *, glob_t *, size_t *); | 154 | Char *, Char *, glob_t *, size_t *); |
154 | static int globextend(const Char *, glob_t *, size_t *); | 155 | static int globextend(const Char *, glob_t *, size_t *); |
155 | static const Char * | 156 | static const Char * |
@@ -571,16 +572,16 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | |||
571 | } else | 572 | } else |
572 | /* Need expansion, recurse. */ | 573 | /* Need expansion, recurse. */ |
573 | return(glob3(pathbuf, pathbuf_last, pathend, | 574 | return(glob3(pathbuf, pathbuf_last, pathend, |
574 | pathend_last, pattern, pattern_last, | 575 | pathend_last, pattern, p, pattern_last, |
575 | p, pattern_last, pglob, limitp)); | 576 | pglob, limitp)); |
576 | } | 577 | } |
577 | /* NOTREACHED */ | 578 | /* NOTREACHED */ |
578 | } | 579 | } |
579 | 580 | ||
580 | static int | 581 | static int |
581 | glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | 582 | glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
582 | Char *pattern, Char *pattern_last, Char *restpattern, | 583 | Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob, |
583 | Char *restpattern_last, glob_t *pglob, size_t *limitp) | 584 | size_t *limitp) |
584 | { | 585 | { |
585 | struct dirent *dp; | 586 | struct dirent *dp; |
586 | DIR *dirp; | 587 | DIR *dirp; |
diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h index 9ba07f76e..a2b36f974 100644 --- a/openbsd-compat/glob.h +++ b/openbsd-compat/glob.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: glob.h,v 1.9 2004/10/07 16:56:11 millert Exp $ */ | 1 | /* $OpenBSD: glob.h,v 1.10 2005/12/13 00:35:22 millert Exp $ */ |
2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ | 2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -39,7 +39,8 @@ | |||
39 | 39 | ||
40 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | 40 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ |
41 | !defined(GLOB_HAS_GL_MATCHC) || \ | 41 | !defined(GLOB_HAS_GL_MATCHC) || \ |
42 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 | 42 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ |
43 | defined(BROKEN_GLOB) | ||
43 | 44 | ||
44 | #ifndef _GLOB_H_ | 45 | #ifndef _GLOB_H_ |
45 | #define _GLOB_H_ | 46 | #define _GLOB_H_ |
@@ -66,7 +67,6 @@ typedef struct { | |||
66 | int (*gl_stat)(const char *, struct stat *); | 67 | int (*gl_stat)(const char *, struct stat *); |
67 | } glob_t; | 68 | } glob_t; |
68 | 69 | ||
69 | /* Flags */ | ||
70 | #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ | 70 | #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ |
71 | #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ | 71 | #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ |
72 | #define GLOB_ERR 0x0004 /* Return on error. */ | 72 | #define GLOB_ERR 0x0004 /* Return on error. */ |
@@ -75,6 +75,13 @@ typedef struct { | |||
75 | #define GLOB_NOSORT 0x0020 /* Don't sort. */ | 75 | #define GLOB_NOSORT 0x0020 /* Don't sort. */ |
76 | #define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ | 76 | #define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ |
77 | 77 | ||
78 | /* Error values returned by glob(3) */ | ||
79 | #define GLOB_NOSPACE (-1) /* Malloc call failed. */ | ||
80 | #define GLOB_ABORTED (-2) /* Unignored error. */ | ||
81 | #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ | ||
82 | #define GLOB_NOSYS (-4) /* Function not supported. */ | ||
83 | #define GLOB_ABEND GLOB_ABORTED | ||
84 | |||
78 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ | 85 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ |
79 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ | 86 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ |
80 | #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ | 87 | #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ |
@@ -83,13 +90,6 @@ typedef struct { | |||
83 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ | 90 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ |
84 | #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ | 91 | #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ |
85 | 92 | ||
86 | /* Error values returned by glob(3) */ | ||
87 | #define GLOB_NOSPACE (-1) /* Malloc call failed. */ | ||
88 | #define GLOB_ABORTED (-2) /* Unignored error. */ | ||
89 | #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ | ||
90 | #define GLOB_NOSYS (-4) /* Function not supported. */ | ||
91 | #define GLOB_ABEND GLOB_ABORTED | ||
92 | |||
93 | int glob(const char *, int, int (*)(const char *, int), glob_t *); | 93 | int glob(const char *, int, int (*)(const char *, int), glob_t *); |
94 | void globfree(glob_t *); | 94 | void globfree(glob_t *); |
95 | 95 | ||
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 6406af19d..50c6d990b 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openbsd-compat.h,v 1.43 2007/06/25 12:15:13 dtucker Exp $ */ | 1 | /* $Id: openbsd-compat.h,v 1.46 2008/06/08 17:32:29 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. | 4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. |
@@ -101,6 +101,11 @@ int daemon(int nochdir, int noclose); | |||
101 | char *dirname(const char *path); | 101 | char *dirname(const char *path); |
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | #ifndef HAVE_FMT_SCALED | ||
105 | #define FMT_SCALED_STRSIZE 7 | ||
106 | int fmt_scaled(long long number, char *result); | ||
107 | #endif | ||
108 | |||
104 | #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) | 109 | #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) |
105 | char *inet_ntoa(struct in_addr in); | 110 | char *inet_ntoa(struct in_addr in); |
106 | #endif | 111 | #endif |
@@ -139,6 +144,7 @@ int writev(int, struct iovec *, int); | |||
139 | 144 | ||
140 | /* Home grown routines */ | 145 | /* Home grown routines */ |
141 | #include "bsd-misc.h" | 146 | #include "bsd-misc.h" |
147 | #include "bsd-statvfs.h" | ||
142 | #include "bsd-waitpid.h" | 148 | #include "bsd-waitpid.h" |
143 | #include "bsd-poll.h" | 149 | #include "bsd-poll.h" |
144 | 150 | ||
@@ -151,6 +157,14 @@ unsigned int arc4random(void); | |||
151 | void arc4random_stir(void); | 157 | void arc4random_stir(void); |
152 | #endif /* !HAVE_ARC4RANDOM */ | 158 | #endif /* !HAVE_ARC4RANDOM */ |
153 | 159 | ||
160 | #ifndef HAVE_ARC4RANDOM_BUF | ||
161 | void arc4random_buf(void *, size_t); | ||
162 | #endif | ||
163 | |||
164 | #ifndef HAVE_ARC4RANDOM_UNIFORM | ||
165 | u_int32_t arc4random_uniform(u_int32_t); | ||
166 | #endif | ||
167 | |||
154 | #ifndef HAVE_ASPRINTF | 168 | #ifndef HAVE_ASPRINTF |
155 | int asprintf(char **, const char *, ...); | 169 | int asprintf(char **, const char *, ...); |
156 | #endif | 170 | #endif |
diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c index 45ebd3f66..49238ba80 100644 --- a/openbsd-compat/openssl-compat.c +++ b/openbsd-compat/openssl-compat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.c,v 1.4 2006/02/22 11:24:47 dtucker Exp $ */ | 1 | /* $Id: openssl-compat.c,v 1.6 2008/02/28 08:13:52 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h index f1d2f19fc..6a1bed5b2 100644 --- a/openbsd-compat/openssl-compat.h +++ b/openbsd-compat/openssl-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.h,v 1.10 2007/06/14 13:47:31 dtucker Exp $ */ | 1 | /* $Id: openssl-compat.h,v 1.12 2008/02/28 08:22:04 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
@@ -19,6 +19,11 @@ | |||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | #include <openssl/evp.h> | 20 | #include <openssl/evp.h> |
21 | 21 | ||
22 | /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */ | ||
23 | #if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f) | ||
24 | # define OPENSSL_free(x) Free(x) | ||
25 | #endif | ||
26 | |||
22 | #if OPENSSL_VERSION_NUMBER < 0x00906000L | 27 | #if OPENSSL_VERSION_NUMBER < 0x00906000L |
23 | # define SSH_OLD_EVP | 28 | # define SSH_OLD_EVP |
24 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | 29 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) |
@@ -79,8 +84,8 @@ extern const EVP_CIPHER *evp_acss(void); | |||
79 | # ifdef SSLeay_add_all_algorithms | 84 | # ifdef SSLeay_add_all_algorithms |
80 | # undef SSLeay_add_all_algorithms | 85 | # undef SSLeay_add_all_algorithms |
81 | # endif | 86 | # endif |
82 | # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() | 87 | # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() |
83 | #endif | 88 | # endif |
84 | 89 | ||
85 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, | 90 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, |
86 | unsigned char *, int); | 91 | unsigned char *, int); |
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c index 94faec670..5b1cb7387 100644 --- a/openbsd-compat/port-aix.c +++ b/openbsd-compat/port-aix.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * | 2 | * |
3 | * Copyright (c) 2001 Gert Doering. All rights reserved. | 3 | * Copyright (c) 2001 Gert Doering. All rights reserved. |
4 | * Copyright (c) 2003,2004,2005 Darren Tucker. All rights reserved. | 4 | * Copyright (c) 2003,2004,2005,2006 Darren Tucker. All rights reserved. |
5 | * | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions |
@@ -394,4 +394,47 @@ sshaix_getnameinfo(const struct sockaddr *sa, size_t salen, char *host, | |||
394 | } | 394 | } |
395 | # endif /* AIX_GETNAMEINFO_HACK */ | 395 | # endif /* AIX_GETNAMEINFO_HACK */ |
396 | 396 | ||
397 | # if defined(USE_GETGRSET) | ||
398 | # include <stdlib.h> | ||
399 | int | ||
400 | getgrouplist(const char *user, gid_t pgid, gid_t *groups, int *grpcnt) | ||
401 | { | ||
402 | char *cp, *grplist, *grp; | ||
403 | gid_t gid; | ||
404 | int ret = 0, ngroups = 0, maxgroups; | ||
405 | long l; | ||
406 | |||
407 | maxgroups = *grpcnt; | ||
408 | |||
409 | if ((cp = grplist = getgrset(user)) == NULL) | ||
410 | return -1; | ||
411 | |||
412 | /* handle zero-length case */ | ||
413 | if (maxgroups <= 0) { | ||
414 | *grpcnt = 0; | ||
415 | return -1; | ||
416 | } | ||
417 | |||
418 | /* copy primary group */ | ||
419 | groups[ngroups++] = pgid; | ||
420 | |||
421 | /* copy each entry from getgrset into group list */ | ||
422 | while ((grp = strsep(&grplist, ",")) != NULL) { | ||
423 | l = strtol(grp, NULL, 10); | ||
424 | if (ngroups >= maxgroups || l == LONG_MIN || l == LONG_MAX) { | ||
425 | ret = -1; | ||
426 | goto out; | ||
427 | } | ||
428 | gid = (gid_t)l; | ||
429 | if (gid == pgid) | ||
430 | continue; /* we have already added primary gid */ | ||
431 | groups[ngroups++] = gid; | ||
432 | } | ||
433 | out: | ||
434 | free(cp); | ||
435 | *grpcnt = ngroups; | ||
436 | return ret; | ||
437 | } | ||
438 | # endif /* USE_GETGRSET */ | ||
439 | |||
397 | #endif /* _AIX */ | 440 | #endif /* _AIX */ |
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h index 5a04bedad..ecb9feae8 100644 --- a/openbsd-compat/port-aix.h +++ b/openbsd-compat/port-aix.h | |||
@@ -1,9 +1,9 @@ | |||
1 | /* $Id: port-aix.h,v 1.27 2006/09/18 13:54:33 dtucker Exp $ */ | 1 | /* $Id: port-aix.h,v 1.29 2008/03/09 05:36:55 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * | 4 | * |
5 | * Copyright (c) 2001 Gert Doering. All rights reserved. | 5 | * Copyright (c) 2001 Gert Doering. All rights reserved. |
6 | * Copyright (c) 2004, 2005 Darren Tucker. All rights reserved. | 6 | * Copyright (c) 2004,2005,2006 Darren Tucker. All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions |
@@ -103,4 +103,14 @@ int sshaix_getnameinfo(const struct sockaddr *, size_t, char *, size_t, | |||
103 | # define getnameinfo(a,b,c,d,e,f,g) (sshaix_getnameinfo(a,b,c,d,e,f,g)) | 103 | # define getnameinfo(a,b,c,d,e,f,g) (sshaix_getnameinfo(a,b,c,d,e,f,g)) |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | /* | ||
107 | * We use getgrset in preference to multiple getgrent calls for efficiency | ||
108 | * plus it supports NIS and LDAP groups. | ||
109 | */ | ||
110 | #if !defined(HAVE_GETGROUPLIST) && defined(HAVE_GETGRSET) | ||
111 | # define HAVE_GETGROUPLIST | ||
112 | # define USE_GETGRSET | ||
113 | int getgrouplist(const char *, gid_t, gid_t *, int *); | ||
114 | #endif | ||
115 | |||
106 | #endif /* _AIX */ | 116 | #endif /* _AIX */ |
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c index a9aa773ef..bc4924727 100644 --- a/openbsd-compat/port-linux.c +++ b/openbsd-compat/port-linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-linux.c,v 1.4 2007/06/27 22:48:03 djm Exp $ */ | 1 | /* $Id: port-linux.c,v 1.5 2008/03/26 20:27:21 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> | 4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> |
@@ -52,7 +52,7 @@ | |||
52 | extern Authctxt *the_authctxt; | 52 | extern Authctxt *the_authctxt; |
53 | 53 | ||
54 | /* Wrapper around is_selinux_enabled() to log its return value once only */ | 54 | /* Wrapper around is_selinux_enabled() to log its return value once only */ |
55 | static int | 55 | int |
56 | ssh_selinux_enabled(void) | 56 | ssh_selinux_enabled(void) |
57 | { | 57 | { |
58 | static int enabled = -1; | 58 | static int enabled = -1; |
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h index cb8a253c4..2a3271a93 100644 --- a/openbsd-compat/port-linux.h +++ b/openbsd-compat/port-linux.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-linux.h,v 1.1 2006/04/22 11:26:08 djm Exp $ */ | 1 | /* $Id: port-linux.h,v 1.2 2008/03/26 20:27:21 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2006 Damien Miller <djm@openbsd.org> | 4 | * Copyright (c) 2006 Damien Miller <djm@openbsd.org> |
@@ -20,6 +20,7 @@ | |||
20 | #define _PORT_LINUX_H | 20 | #define _PORT_LINUX_H |
21 | 21 | ||
22 | #ifdef WITH_SELINUX | 22 | #ifdef WITH_SELINUX |
23 | int ssh_selinux_enabled(void); | ||
23 | void ssh_selinux_setup_pty(char *, const char *); | 24 | void ssh_selinux_setup_pty(char *, const char *); |
24 | void ssh_selinux_setup_exec_context(char *); | 25 | void ssh_selinux_setup_exec_context(char *); |
25 | #endif | 26 | #endif |
diff --git a/openbsd-compat/port-tun.c b/openbsd-compat/port-tun.c index 276474db8..ddc92d0f3 100644 --- a/openbsd-compat/port-tun.c +++ b/openbsd-compat/port-tun.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | 31 | ||
32 | #include "openbsd-compat/sys-queue.h" | ||
32 | #include "log.h" | 33 | #include "log.h" |
33 | #include "misc.h" | 34 | #include "misc.h" |
34 | #include "buffer.h" | 35 | #include "buffer.h" |
diff --git a/openbsd-compat/regress/closefromtest.c b/openbsd-compat/regress/closefromtest.c index bb129fa16..145b09d7b 100644 --- a/openbsd-compat/regress/closefromtest.c +++ b/openbsd-compat/regress/closefromtest.c | |||
@@ -57,4 +57,5 @@ main(void) | |||
57 | for (i = 0; i < NUM_OPENS; i++) | 57 | for (i = 0; i < NUM_OPENS; i++) |
58 | if (close(fds[i]) != -1) | 58 | if (close(fds[i]) != -1) |
59 | fail("failed to close from lowest fd"); | 59 | fail("failed to close from lowest fd"); |
60 | return 0; | ||
60 | } | 61 | } |
diff --git a/openbsd-compat/regress/strtonumtest.c b/openbsd-compat/regress/strtonumtest.c index cb8585129..50ca5bd22 100644 --- a/openbsd-compat/regress/strtonumtest.c +++ b/openbsd-compat/regress/strtonumtest.c | |||
@@ -21,6 +21,20 @@ | |||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | 23 | ||
24 | /* LLONG_MAX is known as LONGLONG_MAX on AIX */ | ||
25 | #if defined(LONGLONG_MAX) && !defined(LLONG_MAX) | ||
26 | # define LLONG_MAX LONGLONG_MAX | ||
27 | # define LLONG_MIN LONGLONG_MIN | ||
28 | #endif | ||
29 | |||
30 | /* LLONG_MAX is known as LONG_LONG_MAX on HP-UX */ | ||
31 | #if defined(LONG_LONG_MAX) && !defined(LLONG_MAX) | ||
32 | # define LLONG_MAX LONG_LONG_MAX | ||
33 | # define LLONG_MIN LONG_LONG_MIN | ||
34 | #endif | ||
35 | |||
36 | long long strtonum(const char *, long long, long long, const char **); | ||
37 | |||
24 | int fail; | 38 | int fail; |
25 | 39 | ||
26 | void | 40 | void |
diff --git a/openbsd-compat/rresvport.c b/openbsd-compat/rresvport.c index 5b0275ce0..1cd61e58d 100644 --- a/openbsd-compat/rresvport.c +++ b/openbsd-compat/rresvport.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <errno.h> | 44 | #include <errno.h> |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <string.h> | 46 | #include <string.h> |
47 | #include <unistd.h> | ||
47 | 48 | ||
48 | #if 0 | 49 | #if 0 |
49 | int | 50 | int |
diff --git a/openbsd-compat/setenv.c b/openbsd-compat/setenv.c index b52a99c2c..e2a8b6dd3 100644 --- a/openbsd-compat/setenv.c +++ b/openbsd-compat/setenv.c | |||
@@ -47,7 +47,7 @@ extern char **environ; | |||
47 | * Explicitly removes '=' in argument name. | 47 | * Explicitly removes '=' in argument name. |
48 | */ | 48 | */ |
49 | static char * | 49 | static char * |
50 | __findenv(const char *name, int *offset) | 50 | __findenv(const char *name, size_t *offset) |
51 | { | 51 | { |
52 | extern char **environ; | 52 | extern char **environ; |
53 | int len, i; | 53 | int len, i; |
@@ -82,7 +82,7 @@ setenv(const char *name, const char *value, int rewrite) | |||
82 | { | 82 | { |
83 | static char **lastenv; /* last value of environ */ | 83 | static char **lastenv; /* last value of environ */ |
84 | char *C; | 84 | char *C; |
85 | int l_value, offset; | 85 | size_t l_value, offset; |
86 | 86 | ||
87 | if (*value == '=') /* no `=' in value */ | 87 | if (*value == '=') /* no `=' in value */ |
88 | ++value; | 88 | ++value; |
@@ -133,7 +133,7 @@ void | |||
133 | unsetenv(const char *name) | 133 | unsetenv(const char *name) |
134 | { | 134 | { |
135 | char **P; | 135 | char **P; |
136 | int offset; | 136 | size_t offset; |
137 | 137 | ||
138 | while (__findenv(name, &offset)) /* if set multiple times */ | 138 | while (__findenv(name, &offset)) /* if set multiple times */ |
139 | for (P = &environ[offset];; ++P) | 139 | for (P = &environ[offset];; ++P) |
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c index b511f6649..2965f689e 100644 --- a/openbsd-compat/setproctitle.c +++ b/openbsd-compat/setproctitle.c | |||
@@ -43,6 +43,8 @@ | |||
43 | #endif | 43 | #endif |
44 | #include <string.h> | 44 | #include <string.h> |
45 | 45 | ||
46 | #include <vis.h> | ||
47 | |||
46 | #define SPT_NONE 0 /* don't use it at all */ | 48 | #define SPT_NONE 0 /* don't use it at all */ |
47 | #define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */ | 49 | #define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */ |
48 | #define SPT_REUSEARGV 2 /* cover argv with title information */ | 50 | #define SPT_REUSEARGV 2 /* cover argv with title information */ |
@@ -121,7 +123,7 @@ setproctitle(const char *fmt, ...) | |||
121 | { | 123 | { |
122 | #if SPT_TYPE != SPT_NONE | 124 | #if SPT_TYPE != SPT_NONE |
123 | va_list ap; | 125 | va_list ap; |
124 | char buf[1024]; | 126 | char buf[1024], ptitle[1024]; |
125 | size_t len; | 127 | size_t len; |
126 | extern char *__progname; | 128 | extern char *__progname; |
127 | #if SPT_TYPE == SPT_PSTAT | 129 | #if SPT_TYPE == SPT_PSTAT |
@@ -142,14 +144,16 @@ setproctitle(const char *fmt, ...) | |||
142 | vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); | 144 | vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); |
143 | } | 145 | } |
144 | va_end(ap); | 146 | va_end(ap); |
147 | strnvis(ptitle, buf, sizeof(ptitle), | ||
148 | VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL); | ||
145 | 149 | ||
146 | #if SPT_TYPE == SPT_PSTAT | 150 | #if SPT_TYPE == SPT_PSTAT |
147 | pst.pst_command = buf; | 151 | pst.pst_command = ptitle; |
148 | pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0); | 152 | pstat(PSTAT_SETCMD, pst, strlen(ptitle), 0, 0); |
149 | #elif SPT_TYPE == SPT_REUSEARGV | 153 | #elif SPT_TYPE == SPT_REUSEARGV |
150 | /* debug("setproctitle: copy \"%s\" into len %d", | 154 | /* debug("setproctitle: copy \"%s\" into len %d", |
151 | buf, argv_env_len); */ | 155 | buf, argv_env_len); */ |
152 | len = strlcpy(argv_start, buf, argv_env_len); | 156 | len = strlcpy(argv_start, ptitle, argv_env_len); |
153 | for(; len < argv_env_len; len++) | 157 | for(; len < argv_env_len; len++) |
154 | argv_start[len] = SPT_PADCHAR; | 158 | argv_start[len] = SPT_PADCHAR; |
155 | #endif | 159 | #endif |
diff --git a/openbsd-compat/sigact.c b/openbsd-compat/sigact.c index 8b8e4dd2c..d67845cf1 100644 --- a/openbsd-compat/sigact.c +++ b/openbsd-compat/sigact.c | |||
@@ -36,6 +36,7 @@ | |||
36 | /* OPENBSD ORIGINAL: lib/libcurses/base/sigaction.c */ | 36 | /* OPENBSD ORIGINAL: lib/libcurses/base/sigaction.c */ |
37 | 37 | ||
38 | #include "includes.h" | 38 | #include "includes.h" |
39 | #include <errno.h> | ||
39 | #include <signal.h> | 40 | #include <signal.h> |
40 | #include "sigact.h" | 41 | #include "sigact.h" |
41 | 42 | ||
@@ -47,28 +48,39 @@ | |||
47 | int | 48 | int |
48 | sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) | 49 | sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) |
49 | { | 50 | { |
50 | return sigvec(sig, &(sigact->sv), &(osigact->sv)); | 51 | return sigvec(sig, sigact ? &sigact->sv : NULL, |
52 | osigact ? &osigact->sv : NULL); | ||
51 | } | 53 | } |
52 | 54 | ||
53 | int | 55 | int |
54 | sigemptyset (sigset_t * mask) | 56 | sigemptyset (sigset_t *mask) |
55 | { | 57 | { |
58 | if (!mask) { | ||
59 | errno = EINVAL; | ||
60 | return -1; | ||
61 | } | ||
56 | *mask = 0; | 62 | *mask = 0; |
57 | return 0; | 63 | return 0; |
58 | } | 64 | } |
59 | 65 | ||
60 | int | 66 | int |
61 | sigprocmask (int mode, sigset_t * mask, sigset_t * omask) | 67 | sigprocmask (int mode, sigset_t *mask, sigset_t *omask) |
62 | { | 68 | { |
63 | sigset_t current = sigsetmask(0); | 69 | sigset_t current = sigsetmask(0); |
64 | 70 | ||
65 | if (omask) *omask = current; | 71 | if (!mask) { |
72 | errno = EINVAL; | ||
73 | return -1; | ||
74 | } | ||
66 | 75 | ||
67 | if (mode==SIG_BLOCK) | 76 | if (omask) |
77 | *omask = current; | ||
78 | |||
79 | if (mode == SIG_BLOCK) | ||
68 | current |= *mask; | 80 | current |= *mask; |
69 | else if (mode==SIG_UNBLOCK) | 81 | else if (mode == SIG_UNBLOCK) |
70 | current &= ~*mask; | 82 | current &= ~*mask; |
71 | else if (mode==SIG_SETMASK) | 83 | else if (mode == SIG_SETMASK) |
72 | current = *mask; | 84 | current = *mask; |
73 | 85 | ||
74 | sigsetmask(current); | 86 | sigsetmask(current); |
@@ -76,28 +88,44 @@ sigprocmask (int mode, sigset_t * mask, sigset_t * omask) | |||
76 | } | 88 | } |
77 | 89 | ||
78 | int | 90 | int |
79 | sigsuspend (sigset_t * mask) | 91 | sigsuspend (sigset_t *mask) |
80 | { | 92 | { |
93 | if (!mask) { | ||
94 | errno = EINVAL; | ||
95 | return -1; | ||
96 | } | ||
81 | return sigpause(*mask); | 97 | return sigpause(*mask); |
82 | } | 98 | } |
83 | 99 | ||
84 | int | 100 | int |
85 | sigdelset (sigset_t * mask, int sig) | 101 | sigdelset (sigset_t *mask, int sig) |
86 | { | 102 | { |
103 | if (!mask) { | ||
104 | errno = EINVAL; | ||
105 | return -1; | ||
106 | } | ||
87 | *mask &= ~sigmask(sig); | 107 | *mask &= ~sigmask(sig); |
88 | return 0; | 108 | return 0; |
89 | } | 109 | } |
90 | 110 | ||
91 | int | 111 | int |
92 | sigaddset (sigset_t * mask, int sig) | 112 | sigaddset (sigset_t *mask, int sig) |
93 | { | 113 | { |
114 | if (!mask) { | ||
115 | errno = EINVAL; | ||
116 | return -1; | ||
117 | } | ||
94 | *mask |= sigmask(sig); | 118 | *mask |= sigmask(sig); |
95 | return 0; | 119 | return 0; |
96 | } | 120 | } |
97 | 121 | ||
98 | int | 122 | int |
99 | sigismember (sigset_t * mask, int sig) | 123 | sigismember (sigset_t *mask, int sig) |
100 | { | 124 | { |
125 | if (!mask) { | ||
126 | errno = EINVAL; | ||
127 | return -1; | ||
128 | } | ||
101 | return (*mask & sigmask(sig)) != 0; | 129 | return (*mask & sigmask(sig)) != 0; |
102 | } | 130 | } |
103 | 131 | ||
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h index 402343324..5cf0587bd 100644 --- a/openbsd-compat/sys-queue.h +++ b/openbsd-compat/sys-queue.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: queue.h,v 1.25 2004/04/08 16:08:21 henning Exp $ */ | 1 | /* $OpenBSD: queue.h,v 1.32 2007/04/30 18:42:34 pedro Exp $ */ |
2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ | 2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -167,6 +167,12 @@ | |||
167 | * For details on the use of these macros, see the queue(3) manual page. | 167 | * For details on the use of these macros, see the queue(3) manual page. |
168 | */ | 168 | */ |
169 | 169 | ||
170 | #if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) | ||
171 | #define _Q_INVALIDATE(a) (a) = ((void *)-1) | ||
172 | #else | ||
173 | #define _Q_INVALIDATE(a) | ||
174 | #endif | ||
175 | |||
170 | /* | 176 | /* |
171 | * Singly-linked List definitions. | 177 | * Singly-linked List definitions. |
172 | */ | 178 | */ |
@@ -229,13 +235,14 @@ struct { \ | |||
229 | #define SLIST_REMOVE(head, elm, type, field) do { \ | 235 | #define SLIST_REMOVE(head, elm, type, field) do { \ |
230 | if ((head)->slh_first == (elm)) { \ | 236 | if ((head)->slh_first == (elm)) { \ |
231 | SLIST_REMOVE_HEAD((head), field); \ | 237 | SLIST_REMOVE_HEAD((head), field); \ |
232 | } \ | 238 | } else { \ |
233 | else { \ | ||
234 | struct type *curelm = (head)->slh_first; \ | 239 | struct type *curelm = (head)->slh_first; \ |
235 | while( curelm->field.sle_next != (elm) ) \ | 240 | \ |
241 | while (curelm->field.sle_next != (elm)) \ | ||
236 | curelm = curelm->field.sle_next; \ | 242 | curelm = curelm->field.sle_next; \ |
237 | curelm->field.sle_next = \ | 243 | curelm->field.sle_next = \ |
238 | curelm->field.sle_next->field.sle_next; \ | 244 | curelm->field.sle_next->field.sle_next; \ |
245 | _Q_INVALIDATE((elm)->field.sle_next); \ | ||
239 | } \ | 246 | } \ |
240 | } while (0) | 247 | } while (0) |
241 | 248 | ||
@@ -303,6 +310,8 @@ struct { \ | |||
303 | (elm)->field.le_next->field.le_prev = \ | 310 | (elm)->field.le_next->field.le_prev = \ |
304 | (elm)->field.le_prev; \ | 311 | (elm)->field.le_prev; \ |
305 | *(elm)->field.le_prev = (elm)->field.le_next; \ | 312 | *(elm)->field.le_prev = (elm)->field.le_next; \ |
313 | _Q_INVALIDATE((elm)->field.le_prev); \ | ||
314 | _Q_INVALIDATE((elm)->field.le_next); \ | ||
306 | } while (0) | 315 | } while (0) |
307 | 316 | ||
308 | #define LIST_REPLACE(elm, elm2, field) do { \ | 317 | #define LIST_REPLACE(elm, elm2, field) do { \ |
@@ -311,6 +320,8 @@ struct { \ | |||
311 | &(elm2)->field.le_next; \ | 320 | &(elm2)->field.le_next; \ |
312 | (elm2)->field.le_prev = (elm)->field.le_prev; \ | 321 | (elm2)->field.le_prev = (elm)->field.le_prev; \ |
313 | *(elm2)->field.le_prev = (elm2); \ | 322 | *(elm2)->field.le_prev = (elm2); \ |
323 | _Q_INVALIDATE((elm)->field.le_prev); \ | ||
324 | _Q_INVALIDATE((elm)->field.le_next); \ | ||
314 | } while (0) | 325 | } while (0) |
315 | 326 | ||
316 | /* | 327 | /* |
@@ -369,8 +380,8 @@ struct { \ | |||
369 | (listelm)->field.sqe_next = (elm); \ | 380 | (listelm)->field.sqe_next = (elm); \ |
370 | } while (0) | 381 | } while (0) |
371 | 382 | ||
372 | #define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \ | 383 | #define SIMPLEQ_REMOVE_HEAD(head, field) do { \ |
373 | if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \ | 384 | if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ |
374 | (head)->sqh_last = &(head)->sqh_first; \ | 385 | (head)->sqh_last = &(head)->sqh_first; \ |
375 | } while (0) | 386 | } while (0) |
376 | 387 | ||
@@ -465,6 +476,8 @@ struct { \ | |||
465 | else \ | 476 | else \ |
466 | (head)->tqh_last = (elm)->field.tqe_prev; \ | 477 | (head)->tqh_last = (elm)->field.tqe_prev; \ |
467 | *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ | 478 | *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ |
479 | _Q_INVALIDATE((elm)->field.tqe_prev); \ | ||
480 | _Q_INVALIDATE((elm)->field.tqe_next); \ | ||
468 | } while (0) | 481 | } while (0) |
469 | 482 | ||
470 | #define TAILQ_REPLACE(head, elm, elm2, field) do { \ | 483 | #define TAILQ_REPLACE(head, elm, elm2, field) do { \ |
@@ -475,6 +488,8 @@ struct { \ | |||
475 | (head)->tqh_last = &(elm2)->field.tqe_next; \ | 488 | (head)->tqh_last = &(elm2)->field.tqe_next; \ |
476 | (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ | 489 | (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ |
477 | *(elm2)->field.tqe_prev = (elm2); \ | 490 | *(elm2)->field.tqe_prev = (elm2); \ |
491 | _Q_INVALIDATE((elm)->field.tqe_prev); \ | ||
492 | _Q_INVALIDATE((elm)->field.tqe_next); \ | ||
478 | } while (0) | 493 | } while (0) |
479 | 494 | ||
480 | /* | 495 | /* |
@@ -575,6 +590,8 @@ struct { \ | |||
575 | else \ | 590 | else \ |
576 | (elm)->field.cqe_prev->field.cqe_next = \ | 591 | (elm)->field.cqe_prev->field.cqe_next = \ |
577 | (elm)->field.cqe_next; \ | 592 | (elm)->field.cqe_next; \ |
593 | _Q_INVALIDATE((elm)->field.cqe_prev); \ | ||
594 | _Q_INVALIDATE((elm)->field.cqe_next); \ | ||
578 | } while (0) | 595 | } while (0) |
579 | 596 | ||
580 | #define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \ | 597 | #define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \ |
@@ -588,6 +605,8 @@ struct { \ | |||
588 | (head).cqh_first = (elm2); \ | 605 | (head).cqh_first = (elm2); \ |
589 | else \ | 606 | else \ |
590 | (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ | 607 | (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ |
608 | _Q_INVALIDATE((elm)->field.cqe_prev); \ | ||
609 | _Q_INVALIDATE((elm)->field.cqe_next); \ | ||
591 | } while (0) | 610 | } while (0) |
592 | 611 | ||
593 | #endif /* !_FAKE_QUEUE_H_ */ | 612 | #endif /* !_FAKE_QUEUE_H_ */ |
diff --git a/openbsd-compat/sys-tree.h b/openbsd-compat/sys-tree.h index c80b90b21..d4949b5e7 100644 --- a/openbsd-compat/sys-tree.h +++ b/openbsd-compat/sys-tree.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ | 1 | /* $OpenBSD: tree.h,v 1.10 2007/10/29 23:49:41 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> | 3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
4 | * All rights reserved. | 4 | * All rights reserved. |
@@ -289,7 +289,7 @@ void name##_SPLAY_MINMAX(struct name *head, int __comp) \ | |||
289 | (x) != NULL; \ | 289 | (x) != NULL; \ |
290 | (x) = SPLAY_NEXT(name, head, x)) | 290 | (x) = SPLAY_NEXT(name, head, x)) |
291 | 291 | ||
292 | /* Macros that define a red-back tree */ | 292 | /* Macros that define a red-black tree */ |
293 | #define RB_HEAD(name, type) \ | 293 | #define RB_HEAD(name, type) \ |
294 | struct name { \ | 294 | struct name { \ |
295 | struct type *rbh_root; /* root of the tree */ \ | 295 | struct type *rbh_root; /* root of the tree */ \ |
@@ -381,9 +381,9 @@ void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ | |||
381 | struct type *name##_RB_REMOVE(struct name *, struct type *); \ | 381 | struct type *name##_RB_REMOVE(struct name *, struct type *); \ |
382 | struct type *name##_RB_INSERT(struct name *, struct type *); \ | 382 | struct type *name##_RB_INSERT(struct name *, struct type *); \ |
383 | struct type *name##_RB_FIND(struct name *, struct type *); \ | 383 | struct type *name##_RB_FIND(struct name *, struct type *); \ |
384 | struct type *name##_RB_NEXT(struct name *, struct type *); \ | 384 | struct type *name##_RB_NEXT(struct type *); \ |
385 | struct type *name##_RB_MINMAX(struct name *, int); \ | 385 | struct type *name##_RB_MINMAX(struct name *, int); |
386 | \ | 386 | |
387 | 387 | ||
388 | /* Main rb operation. | 388 | /* Main rb operation. |
389 | * Moves node close to the key of elm to top | 389 | * Moves node close to the key of elm to top |
@@ -626,7 +626,7 @@ name##_RB_FIND(struct name *head, struct type *elm) \ | |||
626 | } \ | 626 | } \ |
627 | \ | 627 | \ |
628 | struct type * \ | 628 | struct type * \ |
629 | name##_RB_NEXT(struct name *head, struct type *elm) \ | 629 | name##_RB_NEXT(struct type *elm) \ |
630 | { \ | 630 | { \ |
631 | if (RB_RIGHT(elm, field)) { \ | 631 | if (RB_RIGHT(elm, field)) { \ |
632 | elm = RB_RIGHT(elm, field); \ | 632 | elm = RB_RIGHT(elm, field); \ |
@@ -667,13 +667,13 @@ name##_RB_MINMAX(struct name *head, int val) \ | |||
667 | #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) | 667 | #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) |
668 | #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) | 668 | #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) |
669 | #define RB_FIND(name, x, y) name##_RB_FIND(x, y) | 669 | #define RB_FIND(name, x, y) name##_RB_FIND(x, y) |
670 | #define RB_NEXT(name, x, y) name##_RB_NEXT(x, y) | 670 | #define RB_NEXT(name, x, y) name##_RB_NEXT(y) |
671 | #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) | 671 | #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) |
672 | #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) | 672 | #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) |
673 | 673 | ||
674 | #define RB_FOREACH(x, name, head) \ | 674 | #define RB_FOREACH(x, name, head) \ |
675 | for ((x) = RB_MIN(name, head); \ | 675 | for ((x) = RB_MIN(name, head); \ |
676 | (x) != NULL; \ | 676 | (x) != NULL; \ |
677 | (x) = name##_RB_NEXT(head, x)) | 677 | (x) = name##_RB_NEXT(x)) |
678 | 678 | ||
679 | #endif /* _SYS_TREE_H_ */ | 679 | #endif /* _SYS_TREE_H_ */ |