diff options
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.c | 149 | ||||
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.h | 1 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.c | 101 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.h | 20 | ||||
-rw-r--r-- | openbsd-compat/libressl-api-compat.c | 4 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 1 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.c | 22 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.h | 43 | ||||
-rw-r--r-- | openbsd-compat/port-aix.c | 3 | ||||
-rw-r--r-- | openbsd-compat/port-aix.h | 5 | ||||
-rw-r--r-- | openbsd-compat/regress/Makefile.in | 2 | ||||
-rw-r--r-- | openbsd-compat/regress/utimensattest.c | 97 | ||||
-rw-r--r-- | openbsd-compat/sys-queue.h | 1 |
13 files changed, 415 insertions, 34 deletions
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c index fb49e30f5..54628e260 100644 --- a/openbsd-compat/bsd-cygwin_util.c +++ b/openbsd-compat/bsd-cygwin_util.c | |||
@@ -37,6 +37,9 @@ | |||
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <stdarg.h> | 39 | #include <stdarg.h> |
40 | #include <stdlib.h> | ||
41 | #include <wchar.h> | ||
42 | #include <wctype.h> | ||
40 | 43 | ||
41 | #include "xmalloc.h" | 44 | #include "xmalloc.h" |
42 | 45 | ||
@@ -117,4 +120,150 @@ free_windows_environment(char **p) | |||
117 | free(p); | 120 | free(p); |
118 | } | 121 | } |
119 | 122 | ||
123 | /* | ||
124 | * Returns true if the given string matches the pattern (which may contain ? | ||
125 | * and * as wildcards), and zero if it does not match. | ||
126 | * | ||
127 | * The Cygwin version of this function must be case-insensitive and take | ||
128 | * Unicode characters into account. | ||
129 | */ | ||
130 | |||
131 | static int | ||
132 | __match_pattern (const wchar_t *s, const wchar_t *pattern) | ||
133 | { | ||
134 | for (;;) { | ||
135 | /* If at end of pattern, accept if also at end of string. */ | ||
136 | if (!*pattern) | ||
137 | return !*s; | ||
138 | |||
139 | if (*pattern == '*') { | ||
140 | /* Skip the asterisk. */ | ||
141 | pattern++; | ||
142 | |||
143 | /* If at end of pattern, accept immediately. */ | ||
144 | if (!*pattern) | ||
145 | return 1; | ||
146 | |||
147 | /* If next character in pattern is known, optimize. */ | ||
148 | if (*pattern != '?' && *pattern != '*') { | ||
149 | /* | ||
150 | * Look instances of the next character in | ||
151 | * pattern, and try to match starting from | ||
152 | * those. | ||
153 | */ | ||
154 | for (; *s; s++) | ||
155 | if (*s == *pattern && | ||
156 | __match_pattern(s + 1, pattern + 1)) | ||
157 | return 1; | ||
158 | /* Failed. */ | ||
159 | return 0; | ||
160 | } | ||
161 | /* | ||
162 | * Move ahead one character at a time and try to | ||
163 | * match at each position. | ||
164 | */ | ||
165 | for (; *s; s++) | ||
166 | if (__match_pattern(s, pattern)) | ||
167 | return 1; | ||
168 | /* Failed. */ | ||
169 | return 0; | ||
170 | } | ||
171 | /* | ||
172 | * There must be at least one more character in the string. | ||
173 | * If we are at the end, fail. | ||
174 | */ | ||
175 | if (!*s) | ||
176 | return 0; | ||
177 | |||
178 | /* Check if the next character of the string is acceptable. */ | ||
179 | if (*pattern != '?' && towlower(*pattern) != towlower(*s)) | ||
180 | return 0; | ||
181 | |||
182 | /* Move to the next character, both in string and in pattern. */ | ||
183 | s++; | ||
184 | pattern++; | ||
185 | } | ||
186 | /* NOTREACHED */ | ||
187 | } | ||
188 | |||
189 | static int | ||
190 | _match_pattern(const char *s, const char *pattern) | ||
191 | { | ||
192 | wchar_t *ws; | ||
193 | wchar_t *wpattern; | ||
194 | size_t len; | ||
195 | int ret; | ||
196 | |||
197 | if ((len = mbstowcs(NULL, s, 0)) < 0) | ||
198 | return 0; | ||
199 | ws = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t)); | ||
200 | mbstowcs(ws, s, len + 1); | ||
201 | if ((len = mbstowcs(NULL, pattern, 0)) < 0) | ||
202 | return 0; | ||
203 | wpattern = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t)); | ||
204 | mbstowcs(wpattern, pattern, len + 1); | ||
205 | ret = __match_pattern (ws, wpattern); | ||
206 | free(ws); | ||
207 | free(wpattern); | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | /* | ||
212 | * Tries to match the string against the | ||
213 | * comma-separated sequence of subpatterns (each possibly preceded by ! to | ||
214 | * indicate negation). Returns -1 if negation matches, 1 if there is | ||
215 | * a positive match, 0 if there is no match at all. | ||
216 | */ | ||
217 | int | ||
218 | cygwin_ug_match_pattern_list(const char *string, const char *pattern) | ||
219 | { | ||
220 | char sub[1024]; | ||
221 | int negated; | ||
222 | int got_positive; | ||
223 | u_int i, subi, len = strlen(pattern); | ||
224 | |||
225 | got_positive = 0; | ||
226 | for (i = 0; i < len;) { | ||
227 | /* Check if the subpattern is negated. */ | ||
228 | if (pattern[i] == '!') { | ||
229 | negated = 1; | ||
230 | i++; | ||
231 | } else | ||
232 | negated = 0; | ||
233 | |||
234 | /* | ||
235 | * Extract the subpattern up to a comma or end. Convert the | ||
236 | * subpattern to lowercase. | ||
237 | */ | ||
238 | for (subi = 0; | ||
239 | i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; | ||
240 | subi++, i++) | ||
241 | sub[subi] = pattern[i]; | ||
242 | /* If subpattern too long, return failure (no match). */ | ||
243 | if (subi >= sizeof(sub) - 1) | ||
244 | return 0; | ||
245 | |||
246 | /* If the subpattern was terminated by a comma, then skip it. */ | ||
247 | if (i < len && pattern[i] == ',') | ||
248 | i++; | ||
249 | |||
250 | /* Null-terminate the subpattern. */ | ||
251 | sub[subi] = '\0'; | ||
252 | |||
253 | /* Try to match the subpattern against the string. */ | ||
254 | if (_match_pattern(string, sub)) { | ||
255 | if (negated) | ||
256 | return -1; /* Negative */ | ||
257 | else | ||
258 | got_positive = 1; /* Positive */ | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /* | ||
263 | * Return success if got a positive match. If there was a negative | ||
264 | * match, we have already returned -1 and never get here. | ||
265 | */ | ||
266 | return got_positive; | ||
267 | } | ||
268 | |||
120 | #endif /* HAVE_CYGWIN */ | 269 | #endif /* HAVE_CYGWIN */ |
diff --git a/openbsd-compat/bsd-cygwin_util.h b/openbsd-compat/bsd-cygwin_util.h index 202c055db..55c5a5b81 100644 --- a/openbsd-compat/bsd-cygwin_util.h +++ b/openbsd-compat/bsd-cygwin_util.h | |||
@@ -55,6 +55,7 @@ int binary_open(const char *, int , ...); | |||
55 | int check_ntsec(const char *); | 55 | int check_ntsec(const char *); |
56 | char **fetch_windows_environment(void); | 56 | char **fetch_windows_environment(void); |
57 | void free_windows_environment(char **); | 57 | void free_windows_environment(char **); |
58 | int cygwin_ug_match_pattern_list(const char *, const char *); | ||
58 | 59 | ||
59 | #ifndef NO_BINARY_OPEN | 60 | #ifndef NO_BINARY_OPEN |
60 | #define open binary_open | 61 | #define open binary_open |
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 5d7540a70..aa1c7d7a3 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -25,6 +25,7 @@ | |||
25 | # include <sys/time.h> | 25 | # include <sys/time.h> |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #include <fcntl.h> | ||
28 | #include <string.h> | 29 | #include <string.h> |
29 | #include <signal.h> | 30 | #include <signal.h> |
30 | #include <stdlib.h> | 31 | #include <stdlib.h> |
@@ -117,6 +118,106 @@ int utimes(char *filename, struct timeval *tvp) | |||
117 | } | 118 | } |
118 | #endif | 119 | #endif |
119 | 120 | ||
121 | #ifndef HAVE_UTIMENSAT | ||
122 | /* | ||
123 | * A limited implementation of utimensat() that only implements the | ||
124 | * functionality used by OpenSSH, currently only AT_FDCWD and | ||
125 | * AT_SYMLINK_NOFOLLOW. | ||
126 | */ | ||
127 | int | ||
128 | utimensat(int fd, const char *path, const struct timespec times[2], | ||
129 | int flag) | ||
130 | { | ||
131 | struct timeval tv[2]; | ||
132 | int ret, oflags = O_WRONLY; | ||
133 | |||
134 | tv[0].tv_sec = times[0].tv_sec; | ||
135 | tv[0].tv_usec = times[0].tv_nsec / 1000; | ||
136 | tv[1].tv_sec = times[1].tv_sec; | ||
137 | tv[1].tv_usec = times[1].tv_nsec / 1000; | ||
138 | |||
139 | if (fd != AT_FDCWD) { | ||
140 | errno = ENOSYS; | ||
141 | return -1; | ||
142 | } | ||
143 | # ifndef HAVE_FUTIMES | ||
144 | return utimes(path, tv); | ||
145 | # else | ||
146 | # ifdef O_NOFOLLOW | ||
147 | if (flag & AT_SYMLINK_NOFOLLOW) | ||
148 | oflags |= O_NOFOLLOW; | ||
149 | # endif /* O_NOFOLLOW */ | ||
150 | if ((fd = open(path, oflags)) == -1) | ||
151 | return -1; | ||
152 | ret = futimes(fd, tv); | ||
153 | close(fd); | ||
154 | return ret; | ||
155 | # endif | ||
156 | } | ||
157 | #endif | ||
158 | |||
159 | #ifndef HAVE_FCHOWNAT | ||
160 | /* | ||
161 | * A limited implementation of fchownat() that only implements the | ||
162 | * functionality used by OpenSSH, currently only AT_FDCWD and | ||
163 | * AT_SYMLINK_NOFOLLOW. | ||
164 | */ | ||
165 | int | ||
166 | fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag) | ||
167 | { | ||
168 | int ret, oflags = O_WRONLY; | ||
169 | |||
170 | if (fd != AT_FDCWD) { | ||
171 | errno = ENOSYS; | ||
172 | return -1; | ||
173 | } | ||
174 | # ifndef HAVE_FCHOWN | ||
175 | return chown(pathname, owner, group); | ||
176 | # else | ||
177 | # ifdef O_NOFOLLOW | ||
178 | if (flag & AT_SYMLINK_NOFOLLOW) | ||
179 | oflags |= O_NOFOLLOW; | ||
180 | # endif /* O_NOFOLLOW */ | ||
181 | if ((fd = open(path, oflags)) == -1) | ||
182 | return -1; | ||
183 | ret = fchown(fd, owner, group); | ||
184 | close(fd); | ||
185 | return ret; | ||
186 | # endif | ||
187 | } | ||
188 | #endif | ||
189 | |||
190 | #ifndef HAVE_FCHMODAT | ||
191 | /* | ||
192 | * A limited implementation of fchmodat() that only implements the | ||
193 | * functionality used by OpenSSH, currently only AT_FDCWD and | ||
194 | * AT_SYMLINK_NOFOLLOW. | ||
195 | */ | ||
196 | int | ||
197 | fchmodat(int fd, const char *path, mode_t mode, int flag) | ||
198 | { | ||
199 | int ret, oflags = O_WRONLY; | ||
200 | |||
201 | if (fd != AT_FDCWD) { | ||
202 | errno = ENOSYS; | ||
203 | return -1; | ||
204 | } | ||
205 | # ifndef HAVE_FCHMOD | ||
206 | return chown(pathname, owner, group); | ||
207 | # else | ||
208 | # ifdef O_NOFOLLOW | ||
209 | if (flag & AT_SYMLINK_NOFOLLOW) | ||
210 | oflags |= O_NOFOLLOW; | ||
211 | # endif /* O_NOFOLLOW */ | ||
212 | if ((fd = open(path, oflags)) == -1) | ||
213 | return -1; | ||
214 | ret = fchmod(fd, mode); | ||
215 | close(fd); | ||
216 | return ret; | ||
217 | # endif | ||
218 | } | ||
219 | #endif | ||
220 | |||
120 | #ifndef HAVE_TRUNCATE | 221 | #ifndef HAVE_TRUNCATE |
121 | int truncate(const char *path, off_t length) | 222 | int truncate(const char *path, off_t length) |
122 | { | 223 | { |
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 52ec52853..cb158cd5c 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h | |||
@@ -64,6 +64,26 @@ struct timeval { | |||
64 | int utimes(char *, struct timeval *); | 64 | int utimes(char *, struct timeval *); |
65 | #endif /* HAVE_UTIMES */ | 65 | #endif /* HAVE_UTIMES */ |
66 | 66 | ||
67 | #ifndef HAVE_UTIMENSAT | ||
68 | /* start with the high bits and work down to minimise risk of overlap */ | ||
69 | # ifndef AT_SYMLINK_NOFOLLOW | ||
70 | # define AT_SYMLINK_NOFOLLOW 0x80000000 | ||
71 | # endif | ||
72 | int utimensat(int, const char *, const struct timespec[2], int); | ||
73 | #endif | ||
74 | |||
75 | #ifndef AT_FDCWD | ||
76 | # define AT_FDCWD (-2) | ||
77 | #endif | ||
78 | |||
79 | #ifndef HAVE_FCHMODAT | ||
80 | int fchmodat(int, const char *, mode_t, int); | ||
81 | #endif | ||
82 | |||
83 | #ifndef HAVE_FCHOWNAT | ||
84 | int fchownat(int, const char *, uid_t, gid_t, int); | ||
85 | #endif | ||
86 | |||
67 | #ifndef HAVE_TRUNCATE | 87 | #ifndef HAVE_TRUNCATE |
68 | int truncate (const char *, off_t); | 88 | int truncate (const char *, off_t); |
69 | #endif /* HAVE_TRUNCATE */ | 89 | #endif /* HAVE_TRUNCATE */ |
diff --git a/openbsd-compat/libressl-api-compat.c b/openbsd-compat/libressl-api-compat.c index de3e64a63..ae00ff593 100644 --- a/openbsd-compat/libressl-api-compat.c +++ b/openbsd-compat/libressl-api-compat.c | |||
@@ -152,7 +152,9 @@ | |||
152 | #include <openssl/dsa.h> | 152 | #include <openssl/dsa.h> |
153 | #include <openssl/rsa.h> | 153 | #include <openssl/rsa.h> |
154 | #include <openssl/evp.h> | 154 | #include <openssl/evp.h> |
155 | #ifdef OPENSSL_HAS_ECC | ||
155 | #include <openssl/ecdsa.h> | 156 | #include <openssl/ecdsa.h> |
157 | #endif | ||
156 | #include <openssl/dh.h> | 158 | #include <openssl/dh.h> |
157 | 159 | ||
158 | #ifndef HAVE_DSA_GET0_PQG | 160 | #ifndef HAVE_DSA_GET0_PQG |
@@ -417,6 +419,7 @@ DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s) | |||
417 | } | 419 | } |
418 | #endif /* HAVE_DSA_SIG_SET0 */ | 420 | #endif /* HAVE_DSA_SIG_SET0 */ |
419 | 421 | ||
422 | #ifdef OPENSSL_HAS_ECC | ||
420 | #ifndef HAVE_ECDSA_SIG_GET0 | 423 | #ifndef HAVE_ECDSA_SIG_GET0 |
421 | void | 424 | void |
422 | ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) | 425 | ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) |
@@ -442,6 +445,7 @@ ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) | |||
442 | return 1; | 445 | return 1; |
443 | } | 446 | } |
444 | #endif /* HAVE_ECDSA_SIG_SET0 */ | 447 | #endif /* HAVE_ECDSA_SIG_SET0 */ |
448 | #endif /* OPENSSL_HAS_ECC */ | ||
445 | 449 | ||
446 | #ifndef HAVE_DH_GET0_PQG | 450 | #ifndef HAVE_DH_GET0_PQG |
447 | void | 451 | void |
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index f5c833bf2..865aaee53 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -61,6 +61,7 @@ void closefrom(int); | |||
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | #ifndef HAVE_GETLINE | 63 | #ifndef HAVE_GETLINE |
64 | #include <stdio.h> | ||
64 | ssize_t getline(char **, size_t *, FILE *); | 65 | ssize_t getline(char **, size_t *, FILE *); |
65 | #endif | 66 | #endif |
66 | 67 | ||
diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c index ea0b0c9fb..c1749210d 100644 --- a/openbsd-compat/openssl-compat.c +++ b/openbsd-compat/openssl-compat.c | |||
@@ -66,23 +66,31 @@ ssh_compatible_openssl(long headerver, long libver) | |||
66 | return 0; | 66 | return 0; |
67 | } | 67 | } |
68 | 68 | ||
69 | #ifdef USE_OPENSSL_ENGINE | ||
70 | void | 69 | void |
71 | ssh_OpenSSL_add_all_algorithms(void) | 70 | ssh_libcrypto_init(void) |
72 | { | 71 | { |
72 | #if defined(HAVE_OPENSSL_INIT_CRYPTO) && \ | ||
73 | defined(OPENSSL_INIT_ADD_ALL_CIPHERS) && \ | ||
74 | defined(OPENSSL_INIT_ADD_ALL_DIGESTS) | ||
75 | OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS | | ||
76 | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL); | ||
77 | #elif defined(HAVE_OPENSSL_ADD_ALL_ALGORITHMS) | ||
73 | OpenSSL_add_all_algorithms(); | 78 | OpenSSL_add_all_algorithms(); |
79 | #endif | ||
74 | 80 | ||
81 | #ifdef USE_OPENSSL_ENGINE | ||
75 | /* Enable use of crypto hardware */ | 82 | /* Enable use of crypto hardware */ |
76 | ENGINE_load_builtin_engines(); | 83 | ENGINE_load_builtin_engines(); |
77 | ENGINE_register_all_complete(); | 84 | ENGINE_register_all_complete(); |
78 | 85 | ||
79 | #if OPENSSL_VERSION_NUMBER < 0x10001000L | 86 | /* Load the libcrypto config file to pick up engines defined there */ |
80 | OPENSSL_config(NULL); | 87 | # if defined(HAVE_OPENSSL_INIT_CRYPTO) && defined(OPENSSL_INIT_LOAD_CONFIG) |
81 | #else | ||
82 | OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS | | 88 | OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS | |
83 | OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL); | 89 | OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL); |
84 | #endif | 90 | # else |
91 | OPENSSL_config(NULL); | ||
92 | # endif | ||
93 | #endif /* USE_OPENSSL_ENGINE */ | ||
85 | } | 94 | } |
86 | #endif | ||
87 | 95 | ||
88 | #endif /* WITH_OPENSSL */ | 96 | #endif /* WITH_OPENSSL */ |
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h index 9e0264c04..917bc6f7c 100644 --- a/openbsd-compat/openssl-compat.h +++ b/openbsd-compat/openssl-compat.h | |||
@@ -21,16 +21,32 @@ | |||
21 | #ifdef WITH_OPENSSL | 21 | #ifdef WITH_OPENSSL |
22 | 22 | ||
23 | #include <openssl/opensslv.h> | 23 | #include <openssl/opensslv.h> |
24 | #include <openssl/crypto.h> | ||
24 | #include <openssl/evp.h> | 25 | #include <openssl/evp.h> |
25 | #include <openssl/rsa.h> | 26 | #include <openssl/rsa.h> |
26 | #include <openssl/dsa.h> | 27 | #include <openssl/dsa.h> |
28 | #ifdef OPENSSL_HAS_ECC | ||
27 | #include <openssl/ecdsa.h> | 29 | #include <openssl/ecdsa.h> |
30 | #endif | ||
28 | #include <openssl/dh.h> | 31 | #include <openssl/dh.h> |
29 | 32 | ||
30 | int ssh_compatible_openssl(long, long); | 33 | int ssh_compatible_openssl(long, long); |
34 | void ssh_libcrypto_init(void); | ||
35 | |||
36 | #if (OPENSSL_VERSION_NUMBER < 0x1000100fL) | ||
37 | # error OpenSSL 1.0.1 or greater is required | ||
38 | #endif | ||
39 | |||
40 | #ifndef OPENSSL_VERSION | ||
41 | # define OPENSSL_VERSION SSLEAY_VERSION | ||
42 | #endif | ||
43 | |||
44 | #ifndef HAVE_OPENSSL_VERSION | ||
45 | # define OpenSSL_version(x) SSLeay_version(x) | ||
46 | #endif | ||
31 | 47 | ||
32 | #if (OPENSSL_VERSION_NUMBER <= 0x0090805fL) | 48 | #ifndef HAVE_OPENSSL_VERSION_NUM |
33 | # error OpenSSL 0.9.8f or greater is required | 49 | # define OpenSSL_version_num SSLeay |
34 | #endif | 50 | #endif |
35 | 51 | ||
36 | #if OPENSSL_VERSION_NUMBER < 0x10000001L | 52 | #if OPENSSL_VERSION_NUMBER < 0x10000001L |
@@ -77,27 +93,6 @@ void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t); | |||
77 | # endif | 93 | # endif |
78 | #endif | 94 | #endif |
79 | 95 | ||
80 | /* | ||
81 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents | ||
82 | * to automatically handle OpenSSL engine initialisation. | ||
83 | * | ||
84 | * In order for the compat library to call the real functions, it must | ||
85 | * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and | ||
86 | * implement the ssh_* equivalents. | ||
87 | */ | ||
88 | #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS | ||
89 | |||
90 | # ifdef USE_OPENSSL_ENGINE | ||
91 | # ifdef OpenSSL_add_all_algorithms | ||
92 | # undef OpenSSL_add_all_algorithms | ||
93 | # endif | ||
94 | # define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms() | ||
95 | # endif | ||
96 | |||
97 | void ssh_OpenSSL_add_all_algorithms(void); | ||
98 | |||
99 | #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ | ||
100 | |||
101 | /* LibreSSL/OpenSSL 1.1x API compat */ | 96 | /* LibreSSL/OpenSSL 1.1x API compat */ |
102 | #ifndef HAVE_DSA_GET0_PQG | 97 | #ifndef HAVE_DSA_GET0_PQG |
103 | void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, | 98 | void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, |
@@ -161,6 +156,7 @@ void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); | |||
161 | int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s); | 156 | int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s); |
162 | #endif /* DSA_SIG_SET0 */ | 157 | #endif /* DSA_SIG_SET0 */ |
163 | 158 | ||
159 | #ifdef OPENSSL_HAS_ECC | ||
164 | #ifndef HAVE_ECDSA_SIG_GET0 | 160 | #ifndef HAVE_ECDSA_SIG_GET0 |
165 | void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); | 161 | void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); |
166 | #endif /* HAVE_ECDSA_SIG_GET0 */ | 162 | #endif /* HAVE_ECDSA_SIG_GET0 */ |
@@ -168,6 +164,7 @@ void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); | |||
168 | #ifndef HAVE_ECDSA_SIG_SET0 | 164 | #ifndef HAVE_ECDSA_SIG_SET0 |
169 | int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); | 165 | int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); |
170 | #endif /* HAVE_ECDSA_SIG_SET0 */ | 166 | #endif /* HAVE_ECDSA_SIG_SET0 */ |
167 | #endif /* OPENSSL_HAS_ECC */ | ||
171 | 168 | ||
172 | #ifndef HAVE_DH_GET0_PQG | 169 | #ifndef HAVE_DH_GET0_PQG |
173 | void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, | 170 | void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, |
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c index 943177c70..fc80dc39f 100644 --- a/openbsd-compat/port-aix.c +++ b/openbsd-compat/port-aix.c | |||
@@ -313,7 +313,8 @@ sys_auth_get_lastlogin_msg(const char *user, uid_t uid) | |||
313 | * record_failed_login: generic "login failed" interface function | 313 | * record_failed_login: generic "login failed" interface function |
314 | */ | 314 | */ |
315 | void | 315 | void |
316 | record_failed_login(const char *user, const char *hostname, const char *ttyname) | 316 | record_failed_login(struct ssh *ssh, const char *user, const char *hostname, |
317 | const char *ttyname) | ||
317 | { | 318 | { |
318 | if (geteuid() != 0) | 319 | if (geteuid() != 0) |
319 | return; | 320 | return; |
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h index 748c0e4e3..904de3096 100644 --- a/openbsd-compat/port-aix.h +++ b/openbsd-compat/port-aix.h | |||
@@ -30,6 +30,7 @@ | |||
30 | # include <sys/socket.h> | 30 | # include <sys/socket.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | struct ssh; | ||
33 | struct sshbuf; | 34 | struct sshbuf; |
34 | 35 | ||
35 | /* These should be in the system headers but are not. */ | 36 | /* These should be in the system headers but are not. */ |
@@ -89,8 +90,8 @@ void aix_usrinfo(struct passwd *); | |||
89 | # define CUSTOM_SYS_AUTH_ALLOWED_USER 1 | 90 | # define CUSTOM_SYS_AUTH_ALLOWED_USER 1 |
90 | int sys_auth_allowed_user(struct passwd *, struct sshbuf *); | 91 | int sys_auth_allowed_user(struct passwd *, struct sshbuf *); |
91 | # define CUSTOM_SYS_AUTH_RECORD_LOGIN 1 | 92 | # define CUSTOM_SYS_AUTH_RECORD_LOGIN 1 |
92 | int sys_auth_record_login(const char *, const char *, | 93 | int sys_auth_record_login(const char *, const char *, const char *, |
93 | const char *, struct sshbuf *); | 94 | struct sshbuf *); |
94 | # define CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG | 95 | # define CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG |
95 | char *sys_auth_get_lastlogin_msg(const char *, uid_t); | 96 | char *sys_auth_get_lastlogin_msg(const char *, uid_t); |
96 | # define CUSTOM_FAILED_LOGIN 1 | 97 | # define CUSTOM_FAILED_LOGIN 1 |
diff --git a/openbsd-compat/regress/Makefile.in b/openbsd-compat/regress/Makefile.in index 529331be5..c5aae61e2 100644 --- a/openbsd-compat/regress/Makefile.in +++ b/openbsd-compat/regress/Makefile.in | |||
@@ -14,7 +14,7 @@ LIBS=@LIBS@ | |||
14 | LDFLAGS=@LDFLAGS@ $(LIBCOMPAT) | 14 | LDFLAGS=@LDFLAGS@ $(LIBCOMPAT) |
15 | 15 | ||
16 | TESTPROGS=closefromtest$(EXEEXT) snprintftest$(EXEEXT) strduptest$(EXEEXT) \ | 16 | TESTPROGS=closefromtest$(EXEEXT) snprintftest$(EXEEXT) strduptest$(EXEEXT) \ |
17 | strtonumtest$(EXEEXT) opensslvertest$(EXEEXT) | 17 | strtonumtest$(EXEEXT) opensslvertest$(EXEEXT) utimensattest$(EXEEXT) |
18 | 18 | ||
19 | all: t-exec ${OTHERTESTS} | 19 | all: t-exec ${OTHERTESTS} |
20 | 20 | ||
diff --git a/openbsd-compat/regress/utimensattest.c b/openbsd-compat/regress/utimensattest.c new file mode 100644 index 000000000..a7bc7634b --- /dev/null +++ b/openbsd-compat/regress/utimensattest.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2019 Darren Tucker | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <sys/types.h> | ||
18 | #include <sys/stat.h> | ||
19 | |||
20 | #include <errno.h> | ||
21 | #include <fcntl.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <unistd.h> | ||
26 | |||
27 | #define TMPFILE "utimensat.tmp" | ||
28 | #define TMPFILE2 "utimensat.tmp2" | ||
29 | |||
30 | #ifndef AT_SYMLINK_NOFOLLOW | ||
31 | # define AT_SYMLINK_NOFOLLOW 0x80000000 | ||
32 | #endif | ||
33 | |||
34 | int utimensat(int, const char *, const struct timespec[2], int); | ||
35 | |||
36 | void | ||
37 | fail(char *msg, long expect, long got) | ||
38 | { | ||
39 | int saved_errno = errno; | ||
40 | |||
41 | if (expect == got && got == 0) | ||
42 | fprintf(stderr, "utimensat: %s: %s\n", msg, | ||
43 | strerror(saved_errno)); | ||
44 | else | ||
45 | fprintf(stderr, "utimensat: %s: expected %ld got %ld\n", | ||
46 | msg, expect, got); | ||
47 | exit(1); | ||
48 | } | ||
49 | |||
50 | int | ||
51 | main(void) | ||
52 | { | ||
53 | int fd; | ||
54 | struct stat sb; | ||
55 | struct timespec ts[2]; | ||
56 | |||
57 | if ((fd = open(TMPFILE, O_CREAT, 0600)) == -1) | ||
58 | fail("open", 0, 0); | ||
59 | close(fd); | ||
60 | |||
61 | ts[0].tv_sec = 12345678; | ||
62 | ts[0].tv_nsec = 23456789; | ||
63 | ts[1].tv_sec = 34567890; | ||
64 | ts[1].tv_nsec = 45678901; | ||
65 | if (utimensat(AT_FDCWD, TMPFILE, ts, AT_SYMLINK_NOFOLLOW) == -1) | ||
66 | fail("utimensat", 0, 0); | ||
67 | |||
68 | if (stat(TMPFILE, &sb) == -1) | ||
69 | fail("stat", 0, 0 ); | ||
70 | if (sb.st_atime != 12345678) | ||
71 | fail("st_atime", 0, 0 ); | ||
72 | if (sb.st_mtime != 34567890) | ||
73 | fail("st_mtime", 0, 0 ); | ||
74 | #if 0 | ||
75 | /* | ||
76 | * Results expected to be rounded to the nearest microsecond. | ||
77 | * Depends on timestamp precision in kernel and filesystem so | ||
78 | * disabled by default. | ||
79 | */ | ||
80 | if (sb.st_atim.tv_nsec != 23456000) | ||
81 | fail("atim.tv_nsec", 23456000, sb.st_atim.tv_nsec); | ||
82 | if (sb.st_mtim.tv_nsec != 45678000) | ||
83 | fail("mtim.tv_nsec", 45678000, sb.st_mtim.tv_nsec); | ||
84 | #endif | ||
85 | |||
86 | if (rename(TMPFILE, TMPFILE2) == -1) | ||
87 | fail("rename", 0, 0); | ||
88 | if (symlink(TMPFILE2, TMPFILE) == -1) | ||
89 | fail("symlink", 0, 0); | ||
90 | |||
91 | if (utimensat(AT_FDCWD, TMPFILE, ts, AT_SYMLINK_NOFOLLOW) != -1) | ||
92 | fail("utimensat followed symlink", 0, 0); | ||
93 | |||
94 | if (!(unlink(TMPFILE) == 0 && unlink(TMPFILE2) == 0)) | ||
95 | fail("unlink", 0, 0); | ||
96 | exit(0); | ||
97 | } | ||
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h index af93d6814..5108f394c 100644 --- a/openbsd-compat/sys-queue.h +++ b/openbsd-compat/sys-queue.h | |||
@@ -81,6 +81,7 @@ | |||
81 | #undef SIMPLEQ_EMPTY | 81 | #undef SIMPLEQ_EMPTY |
82 | #undef SIMPLEQ_NEXT | 82 | #undef SIMPLEQ_NEXT |
83 | #undef SIMPLEQ_FOREACH | 83 | #undef SIMPLEQ_FOREACH |
84 | #undef SIMPLEQ_FOREACH_SAFE | ||
84 | #undef SIMPLEQ_INIT | 85 | #undef SIMPLEQ_INIT |
85 | #undef SIMPLEQ_INSERT_HEAD | 86 | #undef SIMPLEQ_INSERT_HEAD |
86 | #undef SIMPLEQ_INSERT_TAIL | 87 | #undef SIMPLEQ_INSERT_TAIL |