diff options
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.in | 1 | ||||
-rw-r--r-- | openbsd-compat/arc4random.c | 16 | ||||
-rw-r--r-- | openbsd-compat/bcrypt_pbkdf.c | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-closefrom.c | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.c | 1 | ||||
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.h | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-getline.c | 113 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.c | 1 | ||||
-rw-r--r-- | openbsd-compat/bsd-nextstep.h | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-snprintf.c | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-waitpid.h | 2 | ||||
-rw-r--r-- | openbsd-compat/explicit_bzero.c | 2 | ||||
-rw-r--r-- | openbsd-compat/fmt_scaled.c | 9 | ||||
-rw-r--r-- | openbsd-compat/freezero.c | 1 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 4 | ||||
-rw-r--r-- | openbsd-compat/port-aix.c | 24 | ||||
-rw-r--r-- | openbsd-compat/port-aix.h | 7 | ||||
-rw-r--r-- | openbsd-compat/port-net.c | 4 | ||||
-rw-r--r-- | openbsd-compat/port-uw.c | 4 | ||||
-rw-r--r-- | openbsd-compat/sha2.c | 2 | ||||
-rw-r--r-- | openbsd-compat/strndup.c | 2 | ||||
-rw-r--r-- | openbsd-compat/strnlen.c | 2 | ||||
-rw-r--r-- | openbsd-compat/sys-queue.h | 5 |
23 files changed, 177 insertions, 33 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 8e3b42991..2fd9b952b 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -68,6 +68,7 @@ COMPAT= arc4random.o \ | |||
68 | bsd-cygwin_util.o \ | 68 | bsd-cygwin_util.o \ |
69 | bsd-err.o \ | 69 | bsd-err.o \ |
70 | bsd-flock.o \ | 70 | bsd-flock.o \ |
71 | bsd-getline.o \ | ||
71 | bsd-getpagesize.o \ | 72 | bsd-getpagesize.o \ |
72 | bsd-getpeereid.o \ | 73 | bsd-getpeereid.o \ |
73 | bsd-malloc.o \ | 74 | bsd-malloc.o \ |
diff --git a/openbsd-compat/arc4random.c b/openbsd-compat/arc4random.c index b6256b4f8..578f69f4f 100644 --- a/openbsd-compat/arc4random.c +++ b/openbsd-compat/arc4random.c | |||
@@ -33,6 +33,10 @@ | |||
33 | #include <string.h> | 33 | #include <string.h> |
34 | #include <unistd.h> | 34 | #include <unistd.h> |
35 | 35 | ||
36 | #ifdef HAVE_SYS_RANDOM_H | ||
37 | # include <sys/random.h> | ||
38 | #endif | ||
39 | |||
36 | #ifndef HAVE_ARC4RANDOM | 40 | #ifndef HAVE_ARC4RANDOM |
37 | 41 | ||
38 | #ifdef WITH_OPENSSL | 42 | #ifdef WITH_OPENSSL |
@@ -78,8 +82,9 @@ _rs_init(u_char *buf, size_t n) | |||
78 | } | 82 | } |
79 | 83 | ||
80 | #ifndef WITH_OPENSSL | 84 | #ifndef WITH_OPENSSL |
81 | #define SSH_RANDOM_DEV "/dev/urandom" | 85 | # ifndef SSH_RANDOM_DEV |
82 | /* XXX use getrandom() if supported on Linux */ | 86 | # define SSH_RANDOM_DEV "/dev/urandom" |
87 | # endif /* SSH_RANDOM_DEV */ | ||
83 | static void | 88 | static void |
84 | getrnd(u_char *s, size_t len) | 89 | getrnd(u_char *s, size_t len) |
85 | { | 90 | { |
@@ -87,6 +92,11 @@ getrnd(u_char *s, size_t len) | |||
87 | ssize_t r; | 92 | ssize_t r; |
88 | size_t o = 0; | 93 | size_t o = 0; |
89 | 94 | ||
95 | #ifdef HAVE_GETRANDOM | ||
96 | if ((r = getrandom(s, len, 0)) > 0 && (size_t)r == len) | ||
97 | return; | ||
98 | #endif /* HAVE_GETRANDOM */ | ||
99 | |||
90 | if ((fd = open(SSH_RANDOM_DEV, O_RDONLY)) == -1) | 100 | if ((fd = open(SSH_RANDOM_DEV, O_RDONLY)) == -1) |
91 | fatal("Couldn't open %s: %s", SSH_RANDOM_DEV, strerror(errno)); | 101 | fatal("Couldn't open %s: %s", SSH_RANDOM_DEV, strerror(errno)); |
92 | while (o < len) { | 102 | while (o < len) { |
@@ -101,7 +111,7 @@ getrnd(u_char *s, size_t len) | |||
101 | } | 111 | } |
102 | close(fd); | 112 | close(fd); |
103 | } | 113 | } |
104 | #endif | 114 | #endif /* WITH_OPENSSL */ |
105 | 115 | ||
106 | static void | 116 | static void |
107 | _rs_stir(void) | 117 | _rs_stir(void) |
diff --git a/openbsd-compat/bcrypt_pbkdf.c b/openbsd-compat/bcrypt_pbkdf.c index 0a07f9a0f..785234563 100644 --- a/openbsd-compat/bcrypt_pbkdf.c +++ b/openbsd-compat/bcrypt_pbkdf.c | |||
@@ -46,7 +46,7 @@ | |||
46 | * function with the following modifications: | 46 | * function with the following modifications: |
47 | * 1. The input password and salt are preprocessed with SHA512. | 47 | * 1. The input password and salt are preprocessed with SHA512. |
48 | * 2. The output length is expanded to 256 bits. | 48 | * 2. The output length is expanded to 256 bits. |
49 | * 3. Subsequently the magic string to be encrypted is lengthened and modifed | 49 | * 3. Subsequently the magic string to be encrypted is lengthened and modified |
50 | * to "OxychromaticBlowfishSwatDynamite" | 50 | * to "OxychromaticBlowfishSwatDynamite" |
51 | * 4. The hash function is defined to perform 64 rounds of initial state | 51 | * 4. The hash function is defined to perform 64 rounds of initial state |
52 | * expansion. (More rounds are performed by iterating the hash.) | 52 | * expansion. (More rounds are performed by iterating the hash.) |
diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c index 9380b33a7..b56476a2d 100644 --- a/openbsd-compat/bsd-closefrom.c +++ b/openbsd-compat/bsd-closefrom.c | |||
@@ -77,7 +77,7 @@ closefrom(int lowfd) | |||
77 | 77 | ||
78 | /* Check for a /proc/$$/fd directory. */ | 78 | /* Check for a /proc/$$/fd directory. */ |
79 | len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); | 79 | len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); |
80 | if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { | 80 | if (len > 0 && (size_t)len < sizeof(fdpath) && (dirp = opendir(fdpath))) { |
81 | while ((dent = readdir(dirp)) != NULL) { | 81 | while ((dent = readdir(dirp)) != NULL) { |
82 | fd = strtol(dent->d_name, &endp, 10); | 82 | fd = strtol(dent->d_name, &endp, 10); |
83 | if (dent->d_name != endp && *endp == '\0' && | 83 | if (dent->d_name != endp && *endp == '\0' && |
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c index 398a5f617..fb49e30f5 100644 --- a/openbsd-compat/bsd-cygwin_util.c +++ b/openbsd-compat/bsd-cygwin_util.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <fcntl.h> | 36 | #include <fcntl.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <stdarg.h> | ||
39 | 40 | ||
40 | #include "xmalloc.h" | 41 | #include "xmalloc.h" |
41 | 42 | ||
diff --git a/openbsd-compat/bsd-cygwin_util.h b/openbsd-compat/bsd-cygwin_util.h index 9cef694b9..202c055db 100644 --- a/openbsd-compat/bsd-cygwin_util.h +++ b/openbsd-compat/bsd-cygwin_util.h | |||
@@ -41,7 +41,7 @@ typedef void *HANDLE; | |||
41 | #define UNLEN 256 | 41 | #define UNLEN 256 |
42 | 42 | ||
43 | /* Cygwin functions for which declarations are only available when including | 43 | /* Cygwin functions for which declarations are only available when including |
44 | windows headers, so we have to define them here explicitely. */ | 44 | windows headers, so we have to define them here explicitly. */ |
45 | extern HANDLE cygwin_logon_user (const struct passwd *, const char *); | 45 | extern HANDLE cygwin_logon_user (const struct passwd *, const char *); |
46 | extern void cygwin_set_impersonation_token (const HANDLE); | 46 | extern void cygwin_set_impersonation_token (const HANDLE); |
47 | 47 | ||
diff --git a/openbsd-compat/bsd-getline.c b/openbsd-compat/bsd-getline.c new file mode 100644 index 000000000..d676f4cef --- /dev/null +++ b/openbsd-compat/bsd-getline.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /* $NetBSD: getline.c,v 1.1.1.6 2015/01/02 20:34:27 christos Exp $ */ | ||
2 | |||
3 | /* NetBSD: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp */ | ||
4 | |||
5 | /*- | ||
6 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * This code is derived from software contributed to The NetBSD Foundation | ||
10 | * by Christos Zoulas. | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer. | ||
17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer in the | ||
19 | * documentation and/or other materials provided with the distribution. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | * POSSIBILITY OF SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | /* NETBSD ORIGINAL: external/bsd/file/dist/src/getline.c */ | ||
35 | |||
36 | #include "includes.h" | ||
37 | |||
38 | #if 0 | ||
39 | #include "file.h" | ||
40 | #endif | ||
41 | |||
42 | #if !HAVE_GETLINE | ||
43 | #include <stdlib.h> | ||
44 | #include <stdio.h> | ||
45 | #include <unistd.h> | ||
46 | #include <errno.h> | ||
47 | #include <string.h> | ||
48 | |||
49 | static ssize_t | ||
50 | getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) | ||
51 | { | ||
52 | char *ptr, *eptr; | ||
53 | |||
54 | |||
55 | if (*buf == NULL || *bufsiz == 0) { | ||
56 | if ((*buf = malloc(BUFSIZ)) == NULL) | ||
57 | return -1; | ||
58 | *bufsiz = BUFSIZ; | ||
59 | } | ||
60 | |||
61 | for (ptr = *buf, eptr = *buf + *bufsiz;;) { | ||
62 | int c = fgetc(fp); | ||
63 | if (c == -1) { | ||
64 | if (feof(fp)) { | ||
65 | ssize_t diff = (ssize_t)(ptr - *buf); | ||
66 | if (diff != 0) { | ||
67 | *ptr = '\0'; | ||
68 | return diff; | ||
69 | } | ||
70 | } | ||
71 | return -1; | ||
72 | } | ||
73 | *ptr++ = c; | ||
74 | if (c == delimiter) { | ||
75 | *ptr = '\0'; | ||
76 | return ptr - *buf; | ||
77 | } | ||
78 | if (ptr + 2 >= eptr) { | ||
79 | char *nbuf; | ||
80 | size_t nbufsiz = *bufsiz * 2; | ||
81 | ssize_t d = ptr - *buf; | ||
82 | if ((nbuf = realloc(*buf, nbufsiz)) == NULL) | ||
83 | return -1; | ||
84 | *buf = nbuf; | ||
85 | *bufsiz = nbufsiz; | ||
86 | eptr = nbuf + nbufsiz; | ||
87 | ptr = nbuf + d; | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
92 | ssize_t | ||
93 | getline(char **buf, size_t *bufsiz, FILE *fp) | ||
94 | { | ||
95 | return getdelim(buf, bufsiz, '\n', fp); | ||
96 | } | ||
97 | |||
98 | #endif | ||
99 | |||
100 | #ifdef TEST | ||
101 | int | ||
102 | main(int argc, char *argv[]) | ||
103 | { | ||
104 | char *p = NULL; | ||
105 | ssize_t len; | ||
106 | size_t n = 0; | ||
107 | |||
108 | while ((len = getline(&p, &n, stdin)) != -1) | ||
109 | (void)printf("%" SIZE_T_FORMAT "d %s", len, p); | ||
110 | free(p); | ||
111 | return 0; | ||
112 | } | ||
113 | #endif | ||
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 3daf61071..b6893e171 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <signal.h> | 29 | #include <signal.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <stdio.h> | ||
31 | #include <time.h> | 32 | #include <time.h> |
32 | #include <unistd.h> | 33 | #include <unistd.h> |
33 | 34 | ||
diff --git a/openbsd-compat/bsd-nextstep.h b/openbsd-compat/bsd-nextstep.h index 610f9e381..4a45b15af 100644 --- a/openbsd-compat/bsd-nextstep.h +++ b/openbsd-compat/bsd-nextstep.h | |||
@@ -36,7 +36,7 @@ | |||
36 | /* NeXT's readdir() is BSD (struct direct) not POSIX (struct dirent) */ | 36 | /* NeXT's readdir() is BSD (struct direct) not POSIX (struct dirent) */ |
37 | #define dirent direct | 37 | #define dirent direct |
38 | 38 | ||
39 | /* Swap out NeXT's BSD wait() for a more POSIX complient one */ | 39 | /* Swap out NeXT's BSD wait() for a more POSIX compliant one */ |
40 | pid_t posix_wait(int *); | 40 | pid_t posix_wait(int *); |
41 | #define wait(a) posix_wait(a) | 41 | #define wait(a) posix_wait(a) |
42 | 42 | ||
diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c index d95b6a401..f27b9d808 100644 --- a/openbsd-compat/bsd-snprintf.c +++ b/openbsd-compat/bsd-snprintf.c | |||
@@ -30,7 +30,7 @@ | |||
30 | * probably requires libm on most operating systems. Don't yet | 30 | * probably requires libm on most operating systems. Don't yet |
31 | * support the exponent (e,E) and sigfig (g,G). Also, fmtint() | 31 | * support the exponent (e,E) and sigfig (g,G). Also, fmtint() |
32 | * was pretty badly broken, it just wasn't being exercised in ways | 32 | * was pretty badly broken, it just wasn't being exercised in ways |
33 | * which showed it, so that's been fixed. Also, formated the code | 33 | * which showed it, so that's been fixed. Also, formatted the code |
34 | * to mutt conventions, and removed dead code left over from the | 34 | * to mutt conventions, and removed dead code left over from the |
35 | * original. Also, there is now a builtin-test, just compile with: | 35 | * original. Also, there is now a builtin-test, just compile with: |
36 | * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm | 36 | * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm |
diff --git a/openbsd-compat/bsd-waitpid.h b/openbsd-compat/bsd-waitpid.h index 5ce3ee4b5..b551268ab 100644 --- a/openbsd-compat/bsd-waitpid.h +++ b/openbsd-compat/bsd-waitpid.h | |||
@@ -27,7 +27,7 @@ | |||
27 | #define _BSD_WAITPID_H | 27 | #define _BSD_WAITPID_H |
28 | 28 | ||
29 | #ifndef HAVE_WAITPID | 29 | #ifndef HAVE_WAITPID |
30 | /* Clean out any potental issues */ | 30 | /* Clean out any potential issues */ |
31 | #undef WIFEXITED | 31 | #undef WIFEXITED |
32 | #undef WIFSTOPPED | 32 | #undef WIFSTOPPED |
33 | #undef WIFSIGNALED | 33 | #undef WIFSIGNALED |
diff --git a/openbsd-compat/explicit_bzero.c b/openbsd-compat/explicit_bzero.c index 53a003472..6ef9825a9 100644 --- a/openbsd-compat/explicit_bzero.c +++ b/openbsd-compat/explicit_bzero.c | |||
@@ -41,7 +41,7 @@ explicit_bzero(void *p, size_t n) | |||
41 | /* | 41 | /* |
42 | * clang -fsanitize=memory needs to intercept memset-like functions | 42 | * clang -fsanitize=memory needs to intercept memset-like functions |
43 | * to correctly detect memory initialisation. Make sure one is called | 43 | * to correctly detect memory initialisation. Make sure one is called |
44 | * directly since our indirection trick above sucessfully confuses it. | 44 | * directly since our indirection trick above successfully confuses it. |
45 | */ | 45 | */ |
46 | #if defined(__has_feature) | 46 | #if defined(__has_feature) |
47 | # if __has_feature(memory_sanitizer) | 47 | # if __has_feature(memory_sanitizer) |
diff --git a/openbsd-compat/fmt_scaled.c b/openbsd-compat/fmt_scaled.c index 7c5193e26..2f76ef931 100644 --- a/openbsd-compat/fmt_scaled.c +++ b/openbsd-compat/fmt_scaled.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: fmt_scaled.c,v 1.16 2017/03/16 02:40:46 dtucker Exp $ */ | 1 | /* $OpenBSD: fmt_scaled.c,v 1.17 2018/05/14 04:39:04 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. | 4 | * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. |
@@ -188,7 +188,7 @@ scan_scaled(char *scaled, long long *result) | |||
188 | /* scale whole part */ | 188 | /* scale whole part */ |
189 | whole *= scale_fact; | 189 | whole *= scale_fact; |
190 | 190 | ||
191 | /* truncate fpart so it does't overflow. | 191 | /* truncate fpart so it doesn't overflow. |
192 | * then scale fractional part. | 192 | * then scale fractional part. |
193 | */ | 193 | */ |
194 | while (fpart >= LLONG_MAX / scale_fact) { | 194 | while (fpart >= LLONG_MAX / scale_fact) { |
@@ -246,12 +246,15 @@ fmt_scaled(long long number, char *result) | |||
246 | 246 | ||
247 | fract = (10 * fract + 512) / 1024; | 247 | fract = (10 * fract + 512) / 1024; |
248 | /* if the result would be >= 10, round main number */ | 248 | /* if the result would be >= 10, round main number */ |
249 | if (fract == 10) { | 249 | if (fract >= 10) { |
250 | if (number >= 0) | 250 | if (number >= 0) |
251 | number++; | 251 | number++; |
252 | else | 252 | else |
253 | number--; | 253 | number--; |
254 | fract = 0; | 254 | fract = 0; |
255 | } else if (fract < 0) { | ||
256 | /* shouldn't happen */ | ||
257 | fract = 0; | ||
255 | } | 258 | } |
256 | 259 | ||
257 | if (number == 0) | 260 | if (number == 0) |
diff --git a/openbsd-compat/freezero.c b/openbsd-compat/freezero.c index 90b9d3813..bad018ff0 100644 --- a/openbsd-compat/freezero.c +++ b/openbsd-compat/freezero.c | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | 18 | ||
19 | #include <stdlib.h> | ||
19 | #include <string.h> | 20 | #include <string.h> |
20 | 21 | ||
21 | #ifndef HAVE_FREEZERO | 22 | #ifndef HAVE_FREEZERO |
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index b48fb9342..f5c833bf2 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -60,6 +60,10 @@ int bindresvport_sa(int sd, struct sockaddr *sa); | |||
60 | void closefrom(int); | 60 | void closefrom(int); |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | #ifndef HAVE_GETLINE | ||
64 | ssize_t getline(char **, size_t *, FILE *); | ||
65 | #endif | ||
66 | |||
63 | #ifndef HAVE_GETPAGESIZE | 67 | #ifndef HAVE_GETPAGESIZE |
64 | int getpagesize(void); | 68 | int getpagesize(void); |
65 | #endif | 69 | #endif |
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c index 79c868966..943177c70 100644 --- a/openbsd-compat/port-aix.c +++ b/openbsd-compat/port-aix.c | |||
@@ -27,8 +27,9 @@ | |||
27 | #include "includes.h" | 27 | #include "includes.h" |
28 | 28 | ||
29 | #include "xmalloc.h" | 29 | #include "xmalloc.h" |
30 | #include "buffer.h" | 30 | #include "sshbuf.h" |
31 | #include "key.h" | 31 | #include "ssherr.h" |
32 | #include "sshkey.h" | ||
32 | #include "hostfile.h" | 33 | #include "hostfile.h" |
33 | #include "auth.h" | 34 | #include "auth.h" |
34 | #include "ssh.h" | 35 | #include "ssh.h" |
@@ -176,7 +177,7 @@ sys_auth_passwd(struct ssh *ssh, const char *password) | |||
176 | { | 177 | { |
177 | Authctxt *ctxt = ssh->authctxt; | 178 | Authctxt *ctxt = ssh->authctxt; |
178 | char *authmsg = NULL, *msg = NULL, *name = ctxt->pw->pw_name; | 179 | char *authmsg = NULL, *msg = NULL, *name = ctxt->pw->pw_name; |
179 | int authsuccess = 0, expired, reenter, result; | 180 | int r, authsuccess = 0, expired, reenter, result; |
180 | 181 | ||
181 | do { | 182 | do { |
182 | result = authenticate((char *)name, (char *)password, &reenter, | 183 | result = authenticate((char *)name, (char *)password, &reenter, |
@@ -203,7 +204,10 @@ sys_auth_passwd(struct ssh *ssh, const char *password) | |||
203 | */ | 204 | */ |
204 | expired = passwdexpired(name, &msg); | 205 | expired = passwdexpired(name, &msg); |
205 | if (msg && *msg) { | 206 | if (msg && *msg) { |
206 | buffer_append(ctxt->loginmsg, msg, strlen(msg)); | 207 | if ((r = sshbuf_put(ctxt->loginmsg, |
208 | msg, strlen(msg))) != 0) | ||
209 | fatal("%s: buffer error: %s", | ||
210 | __func__, ssh_err(r)); | ||
207 | aix_remove_embedded_newlines(msg); | 211 | aix_remove_embedded_newlines(msg); |
208 | } | 212 | } |
209 | debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg); | 213 | debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg); |
@@ -234,10 +238,10 @@ sys_auth_passwd(struct ssh *ssh, const char *password) | |||
234 | * Returns 1 if login is allowed, 0 if not allowed. | 238 | * Returns 1 if login is allowed, 0 if not allowed. |
235 | */ | 239 | */ |
236 | int | 240 | int |
237 | sys_auth_allowed_user(struct passwd *pw, Buffer *loginmsg) | 241 | sys_auth_allowed_user(struct passwd *pw, struct sshbuf *loginmsg) |
238 | { | 242 | { |
239 | char *msg = NULL; | 243 | char *msg = NULL; |
240 | int result, permitted = 0; | 244 | int r, result, permitted = 0; |
241 | struct stat st; | 245 | struct stat st; |
242 | 246 | ||
243 | /* | 247 | /* |
@@ -260,8 +264,10 @@ sys_auth_allowed_user(struct passwd *pw, Buffer *loginmsg) | |||
260 | */ | 264 | */ |
261 | if (result == -1 && errno == EPERM && stat(_PATH_NOLOGIN, &st) == 0) | 265 | if (result == -1 && errno == EPERM && stat(_PATH_NOLOGIN, &st) == 0) |
262 | permitted = 1; | 266 | permitted = 1; |
263 | else if (msg != NULL) | 267 | else if (msg != NULL) { |
264 | buffer_append(loginmsg, msg, strlen(msg)); | 268 | if ((r = sshbuf_put(loginmsg, msg, strlen(msg))) != 0) |
269 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
270 | } | ||
265 | if (msg == NULL) | 271 | if (msg == NULL) |
266 | msg = xstrdup("(none)"); | 272 | msg = xstrdup("(none)"); |
267 | aix_remove_embedded_newlines(msg); | 273 | aix_remove_embedded_newlines(msg); |
@@ -275,7 +281,7 @@ sys_auth_allowed_user(struct passwd *pw, Buffer *loginmsg) | |||
275 | 281 | ||
276 | int | 282 | int |
277 | sys_auth_record_login(const char *user, const char *host, const char *ttynm, | 283 | sys_auth_record_login(const char *user, const char *host, const char *ttynm, |
278 | Buffer *loginmsg) | 284 | struct sshbuf *loginmsg) |
279 | { | 285 | { |
280 | char *msg = NULL; | 286 | char *msg = NULL; |
281 | int success = 0; | 287 | int success = 0; |
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h index 9c0a4dd3e..748c0e4e3 100644 --- a/openbsd-compat/port-aix.h +++ b/openbsd-compat/port-aix.h | |||
@@ -30,7 +30,7 @@ | |||
30 | # include <sys/socket.h> | 30 | # include <sys/socket.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include "buffer.h" | 33 | struct sshbuf; |
34 | 34 | ||
35 | /* These should be in the system headers but are not. */ | 35 | /* These should be in the system headers but are not. */ |
36 | int usrinfo(int, char *, int); | 36 | int usrinfo(int, char *, int); |
@@ -87,9 +87,10 @@ void aix_usrinfo(struct passwd *); | |||
87 | #ifdef WITH_AIXAUTHENTICATE | 87 | #ifdef WITH_AIXAUTHENTICATE |
88 | # define CUSTOM_SYS_AUTH_PASSWD 1 | 88 | # define CUSTOM_SYS_AUTH_PASSWD 1 |
89 | # define CUSTOM_SYS_AUTH_ALLOWED_USER 1 | 89 | # define CUSTOM_SYS_AUTH_ALLOWED_USER 1 |
90 | int sys_auth_allowed_user(struct passwd *, Buffer *); | 90 | int sys_auth_allowed_user(struct passwd *, struct sshbuf *); |
91 | # define CUSTOM_SYS_AUTH_RECORD_LOGIN 1 | 91 | # define CUSTOM_SYS_AUTH_RECORD_LOGIN 1 |
92 | int sys_auth_record_login(const char *, const char *, const char *, Buffer *); | 92 | int sys_auth_record_login(const char *, const char *, |
93 | const char *, struct sshbuf *); | ||
93 | # define CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG | 94 | # define CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG |
94 | char *sys_auth_get_lastlogin_msg(const char *, uid_t); | 95 | char *sys_auth_get_lastlogin_msg(const char *, uid_t); |
95 | # define CUSTOM_FAILED_LOGIN 1 | 96 | # define CUSTOM_FAILED_LOGIN 1 |
diff --git a/openbsd-compat/port-net.c b/openbsd-compat/port-net.c index 7050629c3..bb535626f 100644 --- a/openbsd-compat/port-net.c +++ b/openbsd-compat/port-net.c | |||
@@ -185,7 +185,7 @@ sys_tun_open(int tun, int mode, char **ifname) | |||
185 | else | 185 | else |
186 | debug("%s: %s mode %d fd %d", __func__, ifr.ifr_name, mode, fd); | 186 | debug("%s: %s mode %d fd %d", __func__, ifr.ifr_name, mode, fd); |
187 | 187 | ||
188 | if (ifname != NULL && (*ifname = strdup(ifr.ifr_name))) | 188 | if (ifname != NULL && (*ifname = strdup(ifr.ifr_name)) == NULL) |
189 | goto failed; | 189 | goto failed; |
190 | 190 | ||
191 | return (fd); | 191 | return (fd); |
@@ -272,7 +272,7 @@ sys_tun_open(int tun, int mode, char **ifname) | |||
272 | goto failed; | 272 | goto failed; |
273 | } | 273 | } |
274 | 274 | ||
275 | if (ifname != NULL && (*ifname = strdup(ifr.ifr_name))) | 275 | if (ifname != NULL && (*ifname = strdup(ifr.ifr_name)) == NULL) |
276 | goto failed; | 276 | goto failed; |
277 | 277 | ||
278 | close(sock); | 278 | close(sock); |
diff --git a/openbsd-compat/port-uw.c b/openbsd-compat/port-uw.c index 014cac264..9edb1b481 100644 --- a/openbsd-compat/port-uw.c +++ b/openbsd-compat/port-uw.c | |||
@@ -38,8 +38,6 @@ | |||
38 | 38 | ||
39 | #include "xmalloc.h" | 39 | #include "xmalloc.h" |
40 | #include "packet.h" | 40 | #include "packet.h" |
41 | #include "buffer.h" | ||
42 | #include "key.h" | ||
43 | #include "auth-options.h" | 41 | #include "auth-options.h" |
44 | #include "log.h" | 42 | #include "log.h" |
45 | #include "misc.h" /* servconf.h needs misc.h for struct ForwardOptions */ | 43 | #include "misc.h" /* servconf.h needs misc.h for struct ForwardOptions */ |
@@ -99,7 +97,7 @@ nischeck(char *namep) | |||
99 | 97 | ||
100 | if ((fd = fopen (password_file, "r")) == NULL) { | 98 | if ((fd = fopen (password_file, "r")) == NULL) { |
101 | /* | 99 | /* |
102 | * If the passwd file has dissapeared we are in a bad state. | 100 | * If the passwd file has disappeared we are in a bad state. |
103 | * However, returning 0 will send us back through the | 101 | * However, returning 0 will send us back through the |
104 | * authentication scheme that has checked the ia database for | 102 | * authentication scheme that has checked the ia database for |
105 | * passwords earlier. | 103 | * passwords earlier. |
diff --git a/openbsd-compat/sha2.c b/openbsd-compat/sha2.c index a22099bbe..b55ea30ac 100644 --- a/openbsd-compat/sha2.c +++ b/openbsd-compat/sha2.c | |||
@@ -72,7 +72,7 @@ | |||
72 | * Please make sure that your system defines BYTE_ORDER. If your | 72 | * Please make sure that your system defines BYTE_ORDER. If your |
73 | * architecture is little-endian, make sure it also defines | 73 | * architecture is little-endian, make sure it also defines |
74 | * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are | 74 | * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are |
75 | * equivilent. | 75 | * equivalent. |
76 | * | 76 | * |
77 | * If your system does not define the above, then you can do so by | 77 | * If your system does not define the above, then you can do so by |
78 | * hand like this: | 78 | * hand like this: |
diff --git a/openbsd-compat/strndup.c b/openbsd-compat/strndup.c index ebb4eccfb..30ac6f046 100644 --- a/openbsd-compat/strndup.c +++ b/openbsd-compat/strndup.c | |||
@@ -16,7 +16,7 @@ | |||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include "config.h" | 19 | #include "includes.h" |
20 | #if !defined(HAVE_STRNDUP) || defined(BROKEN_STRNDUP) | 20 | #if !defined(HAVE_STRNDUP) || defined(BROKEN_STRNDUP) |
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | 22 | ||
diff --git a/openbsd-compat/strnlen.c b/openbsd-compat/strnlen.c index 8cc6b96b5..7ad3573a6 100644 --- a/openbsd-compat/strnlen.c +++ b/openbsd-compat/strnlen.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | /* OPENBSD ORIGINAL: lib/libc/string/strnlen.c */ | 19 | /* OPENBSD ORIGINAL: lib/libc/string/strnlen.c */ |
20 | 20 | ||
21 | #include "config.h" | 21 | #include "includes.h" |
22 | #if !defined(HAVE_STRNLEN) || defined(BROKEN_STRNLEN) | 22 | #if !defined(HAVE_STRNLEN) || defined(BROKEN_STRNLEN) |
23 | #include <sys/types.h> | 23 | #include <sys/types.h> |
24 | 24 | ||
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h index 28aaaa37a..af93d6814 100644 --- a/openbsd-compat/sys-queue.h +++ b/openbsd-compat/sys-queue.h | |||
@@ -45,6 +45,7 @@ | |||
45 | #undef SLIST_HEAD_INITIALIZER | 45 | #undef SLIST_HEAD_INITIALIZER |
46 | #undef SLIST_ENTRY | 46 | #undef SLIST_ENTRY |
47 | #undef SLIST_FOREACH_PREVPTR | 47 | #undef SLIST_FOREACH_PREVPTR |
48 | #undef SLIST_FOREACH_SAFE | ||
48 | #undef SLIST_FIRST | 49 | #undef SLIST_FIRST |
49 | #undef SLIST_END | 50 | #undef SLIST_END |
50 | #undef SLIST_EMPTY | 51 | #undef SLIST_EMPTY |
@@ -54,6 +55,7 @@ | |||
54 | #undef SLIST_INSERT_AFTER | 55 | #undef SLIST_INSERT_AFTER |
55 | #undef SLIST_INSERT_HEAD | 56 | #undef SLIST_INSERT_HEAD |
56 | #undef SLIST_REMOVE_HEAD | 57 | #undef SLIST_REMOVE_HEAD |
58 | #undef SLIST_REMOVE_AFTER | ||
57 | #undef SLIST_REMOVE | 59 | #undef SLIST_REMOVE |
58 | #undef SLIST_REMOVE_NEXT | 60 | #undef SLIST_REMOVE_NEXT |
59 | #undef LIST_HEAD | 61 | #undef LIST_HEAD |
@@ -64,6 +66,7 @@ | |||
64 | #undef LIST_EMPTY | 66 | #undef LIST_EMPTY |
65 | #undef LIST_NEXT | 67 | #undef LIST_NEXT |
66 | #undef LIST_FOREACH | 68 | #undef LIST_FOREACH |
69 | #undef LIST_FOREACH_SAFE | ||
67 | #undef LIST_INIT | 70 | #undef LIST_INIT |
68 | #undef LIST_INSERT_AFTER | 71 | #undef LIST_INSERT_AFTER |
69 | #undef LIST_INSERT_BEFORE | 72 | #undef LIST_INSERT_BEFORE |
@@ -94,6 +97,8 @@ | |||
94 | #undef TAILQ_EMPTY | 97 | #undef TAILQ_EMPTY |
95 | #undef TAILQ_FOREACH | 98 | #undef TAILQ_FOREACH |
96 | #undef TAILQ_FOREACH_REVERSE | 99 | #undef TAILQ_FOREACH_REVERSE |
100 | #undef TAILQ_FOREACH_SAFE | ||
101 | #undef TAILQ_FOREACH_REVERSE_SAFE | ||
97 | #undef TAILQ_INIT | 102 | #undef TAILQ_INIT |
98 | #undef TAILQ_INSERT_HEAD | 103 | #undef TAILQ_INSERT_HEAD |
99 | #undef TAILQ_INSERT_TAIL | 104 | #undef TAILQ_INSERT_TAIL |