summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2010-08-23 22:56:08 +0100
committerColin Watson <cjwatson@debian.org>2010-08-23 22:56:08 +0100
commit31e30b835fd9695d3b6647cab4867001b092e28f (patch)
tree138e715c25661825457c7280cd66e3f4853d474c /openbsd-compat
parent78eedc2c60ff4718200f9271d8ee4f437da3a0c5 (diff)
parent43094ebf14c9b16f1ea398bc5b65a7335e947288 (diff)
merge 5.6p1
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/openbsd-compat.h7
-rw-r--r--openbsd-compat/openssl-compat.h13
-rw-r--r--openbsd-compat/port-tun.c8
-rw-r--r--openbsd-compat/port-uw.c2
-rw-r--r--openbsd-compat/strptime.c401
6 files changed, 427 insertions, 8 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index d65b77b5b..d22efd66c 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.44 2010/01/15 01:38:30 dtucker Exp $ 1# $Id: Makefile.in,v 1.45 2010/08/16 03:15:23 dtucker Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=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 pwcache.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 19OPENBSD=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 pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o vis.o
20 20
21COMPAT=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 21COMPAT=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
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index cad2408d6..e15d2bd96 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.49 2010/01/16 12:58:37 dtucker Exp $ */ 1/* $Id: openbsd-compat.h,v 1.50 2010/08/16 03:15:23 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.
@@ -87,6 +87,11 @@ int setenv(register const char *name, register const char *value, int rewrite);
87void strmode(int mode, char *p); 87void strmode(int mode, char *p);
88#endif 88#endif
89 89
90#ifndef HAVE_STRPTIME
91#include <time.h>
92char *strptime(const char *buf, const char *fmt, struct tm *tm);
93#endif
94
90#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) 95#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
91int mkstemps(char *path, int slen); 96int mkstemps(char *path, int slen);
92int mkstemp(char *path); 97int mkstemp(char *path);
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h
index fcc762867..b7caa650c 100644
--- a/openbsd-compat/openssl-compat.h
+++ b/openbsd-compat/openssl-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openssl-compat.h,v 1.14 2009/03/07 11:22:35 dtucker Exp $ */ 1/* $Id: openssl-compat.h,v 1.15 2010/05/12 07:50:02 djm 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>
@@ -18,6 +18,16 @@
18 18
19#include "includes.h" 19#include "includes.h"
20#include <openssl/evp.h> 20#include <openssl/evp.h>
21#include <openssl/rsa.h>
22#include <openssl/dsa.h>
23
24/* Only in 0.9.8 */
25#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
26# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
27#endif
28#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
29# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
30#endif
21 31
22/* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */ 32/* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */
23#if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f) 33#if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f)
@@ -97,3 +107,4 @@ int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int);
97int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); 107int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
98void ssh_SSLeay_add_all_algorithms(void); 108void ssh_SSLeay_add_all_algorithms(void);
99#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ 109#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
110
diff --git a/openbsd-compat/port-tun.c b/openbsd-compat/port-tun.c
index ddc92d0f3..0d756f74f 100644
--- a/openbsd-compat/port-tun.c
+++ b/openbsd-compat/port-tun.c
@@ -173,9 +173,11 @@ sys_tun_open(int tun, int mode)
173 173
174 if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) 174 if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1)
175 goto failed; 175 goto failed;
176 ifr.ifr_flags |= IFF_UP; 176 if ((ifr.ifr_flags & IFF_UP) == 0) {
177 if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) 177 ifr.ifr_flags |= IFF_UP;
178 goto failed; 178 if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1)
179 goto failed;
180 }
179 181
180 close(sock); 182 close(sock);
181 return (fd); 183 return (fd);
diff --git a/openbsd-compat/port-uw.c b/openbsd-compat/port-uw.c
index be9905a6a..b1fbfa208 100644
--- a/openbsd-compat/port-uw.c
+++ b/openbsd-compat/port-uw.c
@@ -39,10 +39,10 @@
39#include "xmalloc.h" 39#include "xmalloc.h"
40#include "packet.h" 40#include "packet.h"
41#include "buffer.h" 41#include "buffer.h"
42#include "key.h"
42#include "auth-options.h" 43#include "auth-options.h"
43#include "log.h" 44#include "log.h"
44#include "servconf.h" 45#include "servconf.h"
45#include "key.h"
46#include "hostfile.h" 46#include "hostfile.h"
47#include "auth.h" 47#include "auth.h"
48#include "ssh.h" 48#include "ssh.h"
diff --git a/openbsd-compat/strptime.c b/openbsd-compat/strptime.c
new file mode 100644
index 000000000..d8d83d907
--- /dev/null
+++ b/openbsd-compat/strptime.c
@@ -0,0 +1,401 @@
1/* $OpenBSD: strptime.c,v 1.12 2008/06/26 05:42:05 ray Exp $ */
2/* $NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $ */
3
4/*-
5 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code was contributed to The NetBSD Foundation by Klaus Klein.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/* OPENBSD ORIGINAL: lib/libc/time/strptime.c */
33
34#include "includes.h"
35
36#ifndef HAVE_STRPTIME
37
38#define TM_YEAR_BASE 1900 /* from tzfile.h */
39
40#include <ctype.h>
41#include <locale.h>
42#include <string.h>
43#include <time.h>
44
45/* #define _ctloc(x) (_CurrentTimeLocale->x) */
46
47/*
48 * We do not implement alternate representations. However, we always
49 * check whether a given modifier is allowed for a certain conversion.
50 */
51#define _ALT_E 0x01
52#define _ALT_O 0x02
53#define _LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
54
55
56static int _conv_num(const unsigned char **, int *, int, int);
57static char *_strptime(const char *, const char *, struct tm *, int);
58
59
60char *
61strptime(const char *buf, const char *fmt, struct tm *tm)
62{
63 return(_strptime(buf, fmt, tm, 1));
64}
65
66static char *
67_strptime(const char *buf, const char *fmt, struct tm *tm, int initialize)
68{
69 unsigned char c;
70 const unsigned char *bp;
71 size_t len;
72 int alt_format, i;
73 static int century, relyear;
74
75 if (initialize) {
76 century = TM_YEAR_BASE;
77 relyear = -1;
78 }
79
80 bp = (unsigned char *)buf;
81 while ((c = *fmt) != '\0') {
82 /* Clear `alternate' modifier prior to new conversion. */
83 alt_format = 0;
84
85 /* Eat up white-space. */
86 if (isspace(c)) {
87 while (isspace(*bp))
88 bp++;
89
90 fmt++;
91 continue;
92 }
93
94 if ((c = *fmt++) != '%')
95 goto literal;
96
97
98again: switch (c = *fmt++) {
99 case '%': /* "%%" is converted to "%". */
100literal:
101 if (c != *bp++)
102 return (NULL);
103
104 break;
105
106 /*
107 * "Alternative" modifiers. Just set the appropriate flag
108 * and start over again.
109 */
110 case 'E': /* "%E?" alternative conversion modifier. */
111 _LEGAL_ALT(0);
112 alt_format |= _ALT_E;
113 goto again;
114
115 case 'O': /* "%O?" alternative conversion modifier. */
116 _LEGAL_ALT(0);
117 alt_format |= _ALT_O;
118 goto again;
119
120 /*
121 * "Complex" conversion rules, implemented through recursion.
122 */
123#if 0
124 case 'c': /* Date and time, using the locale's format. */
125 _LEGAL_ALT(_ALT_E);
126 if (!(bp = _strptime(bp, _ctloc(d_t_fmt), tm, 0)))
127 return (NULL);
128 break;
129#endif
130 case 'D': /* The date as "%m/%d/%y". */
131 _LEGAL_ALT(0);
132 if (!(bp = _strptime(bp, "%m/%d/%y", tm, 0)))
133 return (NULL);
134 break;
135
136 case 'R': /* The time as "%H:%M". */
137 _LEGAL_ALT(0);
138 if (!(bp = _strptime(bp, "%H:%M", tm, 0)))
139 return (NULL);
140 break;
141
142 case 'r': /* The time as "%I:%M:%S %p". */
143 _LEGAL_ALT(0);
144 if (!(bp = _strptime(bp, "%I:%M:%S %p", tm, 0)))
145 return (NULL);
146 break;
147
148 case 'T': /* The time as "%H:%M:%S". */
149 _LEGAL_ALT(0);
150 if (!(bp = _strptime(bp, "%H:%M:%S", tm, 0)))
151 return (NULL);
152 break;
153#if 0
154 case 'X': /* The time, using the locale's format. */
155 _LEGAL_ALT(_ALT_E);
156 if (!(bp = _strptime(bp, _ctloc(t_fmt), tm, 0)))
157 return (NULL);
158 break;
159
160 case 'x': /* The date, using the locale's format. */
161 _LEGAL_ALT(_ALT_E);
162 if (!(bp = _strptime(bp, _ctloc(d_fmt), tm, 0)))
163 return (NULL);
164 break;
165#endif
166 /*
167 * "Elementary" conversion rules.
168 */
169#if 0
170 case 'A': /* The day of week, using the locale's form. */
171 case 'a':
172 _LEGAL_ALT(0);
173 for (i = 0; i < 7; i++) {
174 /* Full name. */
175 len = strlen(_ctloc(day[i]));
176 if (strncasecmp(_ctloc(day[i]), bp, len) == 0)
177 break;
178
179 /* Abbreviated name. */
180 len = strlen(_ctloc(abday[i]));
181 if (strncasecmp(_ctloc(abday[i]), bp, len) == 0)
182 break;
183 }
184
185 /* Nothing matched. */
186 if (i == 7)
187 return (NULL);
188
189 tm->tm_wday = i;
190 bp += len;
191 break;
192
193 case 'B': /* The month, using the locale's form. */
194 case 'b':
195 case 'h':
196 _LEGAL_ALT(0);
197 for (i = 0; i < 12; i++) {
198 /* Full name. */
199 len = strlen(_ctloc(mon[i]));
200 if (strncasecmp(_ctloc(mon[i]), bp, len) == 0)
201 break;
202
203 /* Abbreviated name. */
204 len = strlen(_ctloc(abmon[i]));
205 if (strncasecmp(_ctloc(abmon[i]), bp, len) == 0)
206 break;
207 }
208
209 /* Nothing matched. */
210 if (i == 12)
211 return (NULL);
212
213 tm->tm_mon = i;
214 bp += len;
215 break;
216#endif
217
218 case 'C': /* The century number. */
219 _LEGAL_ALT(_ALT_E);
220 if (!(_conv_num(&bp, &i, 0, 99)))
221 return (NULL);
222
223 century = i * 100;
224 break;
225
226 case 'd': /* The day of month. */
227 case 'e':
228 _LEGAL_ALT(_ALT_O);
229 if (!(_conv_num(&bp, &tm->tm_mday, 1, 31)))
230 return (NULL);
231 break;
232
233 case 'k': /* The hour (24-hour clock representation). */
234 _LEGAL_ALT(0);
235 /* FALLTHROUGH */
236 case 'H':
237 _LEGAL_ALT(_ALT_O);
238 if (!(_conv_num(&bp, &tm->tm_hour, 0, 23)))
239 return (NULL);
240 break;
241
242 case 'l': /* The hour (12-hour clock representation). */
243 _LEGAL_ALT(0);
244 /* FALLTHROUGH */
245 case 'I':
246 _LEGAL_ALT(_ALT_O);
247 if (!(_conv_num(&bp, &tm->tm_hour, 1, 12)))
248 return (NULL);
249 break;
250
251 case 'j': /* The day of year. */
252 _LEGAL_ALT(0);
253 if (!(_conv_num(&bp, &tm->tm_yday, 1, 366)))
254 return (NULL);
255 tm->tm_yday--;
256 break;
257
258 case 'M': /* The minute. */
259 _LEGAL_ALT(_ALT_O);
260 if (!(_conv_num(&bp, &tm->tm_min, 0, 59)))
261 return (NULL);
262 break;
263
264 case 'm': /* The month. */
265 _LEGAL_ALT(_ALT_O);
266 if (!(_conv_num(&bp, &tm->tm_mon, 1, 12)))
267 return (NULL);
268 tm->tm_mon--;
269 break;
270
271#if 0
272 case 'p': /* The locale's equivalent of AM/PM. */
273 _LEGAL_ALT(0);
274 /* AM? */
275 len = strlen(_ctloc(am_pm[0]));
276 if (strncasecmp(_ctloc(am_pm[0]), bp, len) == 0) {
277 if (tm->tm_hour > 12) /* i.e., 13:00 AM ?! */
278 return (NULL);
279 else if (tm->tm_hour == 12)
280 tm->tm_hour = 0;
281
282 bp += len;
283 break;
284 }
285 /* PM? */
286 len = strlen(_ctloc(am_pm[1]));
287 if (strncasecmp(_ctloc(am_pm[1]), bp, len) == 0) {
288 if (tm->tm_hour > 12) /* i.e., 13:00 PM ?! */
289 return (NULL);
290 else if (tm->tm_hour < 12)
291 tm->tm_hour += 12;
292
293 bp += len;
294 break;
295 }
296
297 /* Nothing matched. */
298 return (NULL);
299#endif
300 case 'S': /* The seconds. */
301 _LEGAL_ALT(_ALT_O);
302 if (!(_conv_num(&bp, &tm->tm_sec, 0, 61)))
303 return (NULL);
304 break;
305
306 case 'U': /* The week of year, beginning on sunday. */
307 case 'W': /* The week of year, beginning on monday. */
308 _LEGAL_ALT(_ALT_O);
309 /*
310 * XXX This is bogus, as we can not assume any valid
311 * information present in the tm structure at this
312 * point to calculate a real value, so just check the
313 * range for now.
314 */
315 if (!(_conv_num(&bp, &i, 0, 53)))
316 return (NULL);
317 break;
318
319 case 'w': /* The day of week, beginning on sunday. */
320 _LEGAL_ALT(_ALT_O);
321 if (!(_conv_num(&bp, &tm->tm_wday, 0, 6)))
322 return (NULL);
323 break;
324
325 case 'Y': /* The year. */
326 _LEGAL_ALT(_ALT_E);
327 if (!(_conv_num(&bp, &i, 0, 9999)))
328 return (NULL);
329
330 relyear = -1;
331 tm->tm_year = i - TM_YEAR_BASE;
332 break;
333
334 case 'y': /* The year within the century (2 digits). */
335 _LEGAL_ALT(_ALT_E | _ALT_O);
336 if (!(_conv_num(&bp, &relyear, 0, 99)))
337 return (NULL);
338 break;
339
340 /*
341 * Miscellaneous conversions.
342 */
343 case 'n': /* Any kind of white-space. */
344 case 't':
345 _LEGAL_ALT(0);
346 while (isspace(*bp))
347 bp++;
348 break;
349
350
351 default: /* Unknown/unsupported conversion. */
352 return (NULL);
353 }
354
355
356 }
357
358 /*
359 * We need to evaluate the two digit year spec (%y)
360 * last as we can get a century spec (%C) at any time.
361 */
362 if (relyear != -1) {
363 if (century == TM_YEAR_BASE) {
364 if (relyear <= 68)
365 tm->tm_year = relyear + 2000 - TM_YEAR_BASE;
366 else
367 tm->tm_year = relyear + 1900 - TM_YEAR_BASE;
368 } else {
369 tm->tm_year = relyear + century - TM_YEAR_BASE;
370 }
371 }
372
373 return ((char *)bp);
374}
375
376
377static int
378_conv_num(const unsigned char **buf, int *dest, int llim, int ulim)
379{
380 int result = 0;
381 int rulim = ulim;
382
383 if (**buf < '0' || **buf > '9')
384 return (0);
385
386 /* we use rulim to break out of the loop when we run out of digits */
387 do {
388 result *= 10;
389 result += *(*buf)++ - '0';
390 rulim /= 10;
391 } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
392
393 if (result < llim || result > ulim)
394 return (0);
395
396 *dest = result;
397 return (1);
398}
399
400#endif /* HAVE_STRPTIME */
401