diff options
Diffstat (limited to 'src/lib/libcrypto/bio')
| -rw-r--r-- | src/lib/libcrypto/bio/b_dump.c | 182 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/b_posix.c | 88 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/b_print.c | 109 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 444 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bf_buff.c | 520 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bf_lbuf.c | 377 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bf_nbio.c | 252 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bf_null.c | 196 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bio.h | 774 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bio_cb.c | 145 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bio_err.c | 156 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 624 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_acpt.c | 453 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_bio.c | 884 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_conn.c | 604 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_dgram.c | 658 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_fd.c | 267 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 320 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_log.c | 213 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_mem.c | 321 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_null.c | 158 | ||||
| -rw-r--r-- | src/lib/libcrypto/bio/bss_sock.c | 239 |
22 files changed, 0 insertions, 7984 deletions
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c deleted file mode 100644 index 0214addc8b..0000000000 --- a/src/lib/libcrypto/bio/b_dump.c +++ /dev/null | |||
| @@ -1,182 +0,0 @@ | |||
| 1 | /* $OpenBSD: b_dump.c,v 1.21 2015/04/23 06:11:19 deraadt Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Stolen from tjh's ssl/ssl_trc.c stuff. | ||
| 61 | */ | ||
| 62 | |||
| 63 | #include <stdio.h> | ||
| 64 | #include <string.h> | ||
| 65 | |||
| 66 | #include <openssl/bio.h> | ||
| 67 | |||
| 68 | #define TRUNCATE | ||
| 69 | #define DUMP_WIDTH 16 | ||
| 70 | #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4)) | ||
| 71 | |||
| 72 | int | ||
| 73 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), | ||
| 74 | void *u, const char *s, int len) | ||
| 75 | { | ||
| 76 | return BIO_dump_indent_cb(cb, u, s, len, 0); | ||
| 77 | } | ||
| 78 | |||
| 79 | int | ||
| 80 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | ||
| 81 | void *u, const char *s, int len, int indent) | ||
| 82 | { | ||
| 83 | int ret = 0; | ||
| 84 | char buf[288 + 1], tmp[20], str[128 + 1]; | ||
| 85 | int i, j, rows, trc; | ||
| 86 | unsigned char ch; | ||
| 87 | int dump_width; | ||
| 88 | |||
| 89 | trc = 0; | ||
| 90 | |||
| 91 | #ifdef TRUNCATE | ||
| 92 | for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) | ||
| 93 | trc++; | ||
| 94 | #endif | ||
| 95 | |||
| 96 | if (indent < 0) | ||
| 97 | indent = 0; | ||
| 98 | if (indent) { | ||
| 99 | if (indent > 128) | ||
| 100 | indent = 128; | ||
| 101 | memset(str, ' ', indent); | ||
| 102 | } | ||
| 103 | str[indent] = '\0'; | ||
| 104 | |||
| 105 | dump_width = DUMP_WIDTH_LESS_INDENT(indent); | ||
| 106 | rows = (len / dump_width); | ||
| 107 | if ((rows * dump_width) < len) | ||
| 108 | rows++; | ||
| 109 | for (i = 0; i < rows; i++) { | ||
| 110 | strlcpy(buf, str, sizeof buf); | ||
| 111 | snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width); | ||
| 112 | strlcat(buf, tmp, sizeof buf); | ||
| 113 | for (j = 0; j < dump_width; j++) { | ||
| 114 | if (((i*dump_width) + j) >= len) { | ||
| 115 | strlcat(buf, " ", sizeof buf); | ||
| 116 | } else { | ||
| 117 | ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff; | ||
| 118 | snprintf(tmp, sizeof tmp, "%02x%c", ch, | ||
| 119 | j == 7 ? '-' : ' '); | ||
| 120 | strlcat(buf, tmp, sizeof buf); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | strlcat(buf, " ", sizeof buf); | ||
| 124 | for (j = 0; j < dump_width; j++) { | ||
| 125 | if (((i*dump_width) + j) >= len) | ||
| 126 | break; | ||
| 127 | ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; | ||
| 128 | snprintf(tmp, sizeof tmp, "%c", | ||
| 129 | ((ch >= ' ') && (ch <= '~')) ? ch : '.'); | ||
| 130 | strlcat(buf, tmp, sizeof buf); | ||
| 131 | } | ||
| 132 | strlcat(buf, "\n", sizeof buf); | ||
| 133 | /* if this is the last call then update the ddt_dump thing so | ||
| 134 | * that we will move the selection point in the debug window | ||
| 135 | */ | ||
| 136 | ret += cb((void *)buf, strlen(buf), u); | ||
| 137 | } | ||
| 138 | #ifdef TRUNCATE | ||
| 139 | if (trc > 0) { | ||
| 140 | snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n", | ||
| 141 | str, len + trc); | ||
| 142 | ret += cb((void *)buf, strlen(buf), u); | ||
| 143 | } | ||
| 144 | #endif | ||
| 145 | return (ret); | ||
| 146 | } | ||
| 147 | |||
| 148 | static int | ||
| 149 | write_fp(const void *data, size_t len, void *fp) | ||
| 150 | { | ||
| 151 | return fwrite(data, 1, len, fp); | ||
| 152 | } | ||
| 153 | |||
| 154 | int | ||
| 155 | BIO_dump_fp(FILE *fp, const char *s, int len) | ||
| 156 | { | ||
| 157 | return BIO_dump_cb(write_fp, fp, s, len); | ||
| 158 | } | ||
| 159 | |||
| 160 | int | ||
| 161 | BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) | ||
| 162 | { | ||
| 163 | return BIO_dump_indent_cb(write_fp, fp, s, len, indent); | ||
| 164 | } | ||
| 165 | |||
| 166 | static int | ||
| 167 | write_bio(const void *data, size_t len, void *bp) | ||
| 168 | { | ||
| 169 | return BIO_write((BIO *)bp, (const char *)data, len); | ||
| 170 | } | ||
| 171 | |||
| 172 | int | ||
| 173 | BIO_dump(BIO *bp, const char *s, int len) | ||
| 174 | { | ||
| 175 | return BIO_dump_cb(write_bio, bp, s, len); | ||
| 176 | } | ||
| 177 | |||
| 178 | int | ||
| 179 | BIO_dump_indent(BIO *bp, const char *s, int len, int indent) | ||
| 180 | { | ||
| 181 | return BIO_dump_indent_cb(write_bio, bp, s, len, indent); | ||
| 182 | } | ||
diff --git a/src/lib/libcrypto/bio/b_posix.c b/src/lib/libcrypto/bio/b_posix.c deleted file mode 100644 index a850bc6aea..0000000000 --- a/src/lib/libcrypto/bio/b_posix.c +++ /dev/null | |||
| @@ -1,88 +0,0 @@ | |||
| 1 | /* $OpenBSD: b_posix.c,v 1.1 2014/12/03 22:14:38 bcook Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Functions that need to be overridden by non-POSIX operating systems. | ||
| 61 | */ | ||
| 62 | |||
| 63 | #include <fcntl.h> | ||
| 64 | #include <unistd.h> | ||
| 65 | |||
| 66 | #include <openssl/bio.h> | ||
| 67 | |||
| 68 | int | ||
| 69 | BIO_sock_init(void) | ||
| 70 | { | ||
| 71 | return (1); | ||
| 72 | } | ||
| 73 | |||
| 74 | void | ||
| 75 | BIO_sock_cleanup(void) | ||
| 76 | { | ||
| 77 | } | ||
| 78 | |||
| 79 | int | ||
| 80 | BIO_socket_nbio(int s, int mode) | ||
| 81 | { | ||
| 82 | int flags = fcntl(s, F_GETFD); | ||
| 83 | if (mode && !(flags & O_NONBLOCK)) | ||
| 84 | return (fcntl(s, F_SETFL, flags | O_NONBLOCK) != -1); | ||
| 85 | else if (!mode && (flags & O_NONBLOCK)) | ||
| 86 | return (fcntl(s, F_SETFL, flags & ~O_NONBLOCK) != -1); | ||
| 87 | return (1); | ||
| 88 | } | ||
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c deleted file mode 100644 index 09747767dd..0000000000 --- a/src/lib/libcrypto/bio/b_print.c +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | /* $OpenBSD: b_print.c,v 1.25 2014/06/12 15:49:28 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* Theo de Raadt places this file in the public domain. */ | ||
| 4 | |||
| 5 | #include <openssl/bio.h> | ||
| 6 | |||
| 7 | int | ||
| 8 | BIO_printf(BIO *bio, const char *format, ...) | ||
| 9 | { | ||
| 10 | va_list args; | ||
| 11 | int ret; | ||
| 12 | |||
| 13 | va_start(args, format); | ||
| 14 | ret = BIO_vprintf(bio, format, args); | ||
| 15 | va_end(args); | ||
| 16 | return (ret); | ||
| 17 | } | ||
| 18 | |||
| 19 | #ifdef HAVE_FUNOPEN | ||
| 20 | static int | ||
| 21 | _BIO_write(void *cookie, const char *buf, int nbytes) | ||
| 22 | { | ||
| 23 | return BIO_write(cookie, buf, nbytes); | ||
| 24 | } | ||
| 25 | |||
| 26 | int | ||
| 27 | BIO_vprintf(BIO *bio, const char *format, va_list args) | ||
| 28 | { | ||
| 29 | int ret; | ||
| 30 | FILE *fp; | ||
| 31 | |||
| 32 | fp = funopen(bio, NULL, &_BIO_write, NULL, NULL); | ||
| 33 | if (fp == NULL) { | ||
| 34 | ret = -1; | ||
| 35 | goto fail; | ||
| 36 | } | ||
| 37 | ret = vfprintf(fp, format, args); | ||
| 38 | fclose(fp); | ||
| 39 | fail: | ||
| 40 | return (ret); | ||
| 41 | } | ||
| 42 | |||
| 43 | #else /* !HAVE_FUNOPEN */ | ||
| 44 | |||
| 45 | int | ||
| 46 | BIO_vprintf(BIO *bio, const char *format, va_list args) | ||
| 47 | { | ||
| 48 | int ret; | ||
| 49 | char *buf = NULL; | ||
| 50 | |||
| 51 | ret = vasprintf(&buf, format, args); | ||
| 52 | if (buf == NULL) { | ||
| 53 | ret = -1; | ||
| 54 | goto fail; | ||
| 55 | } | ||
| 56 | BIO_write(bio, buf, ret); | ||
| 57 | free(buf); | ||
| 58 | fail: | ||
| 59 | return (ret); | ||
| 60 | } | ||
| 61 | |||
| 62 | #endif /* HAVE_FUNOPEN */ | ||
| 63 | |||
| 64 | /* | ||
| 65 | * BIO_snprintf and BIO_vsnprintf return -1 for overflow, | ||
| 66 | * due to the history of this API. Justification: | ||
| 67 | * | ||
| 68 | * Traditional snprintf surfaced in 4.4BSD, and returned | ||
| 69 | * "number of bytes wanted". Solaris and Windows opted to | ||
| 70 | * return -1. A draft standard was written which returned -1. | ||
| 71 | * Due to the large volume of code already using the first | ||
| 72 | * semantics, the draft was repaired before standardization to | ||
| 73 | * specify "number of bytes wanted" plus "-1 for character conversion | ||
| 74 | * style errors". Solaris adapted to this rule, but Windows stuck | ||
| 75 | * with -1. | ||
| 76 | * | ||
| 77 | * Original OpenSSL comment which is full of lies: | ||
| 78 | * | ||
| 79 | * "In case of truncation, return -1 like traditional snprintf. | ||
| 80 | * (Current drafts for ISO/IEC 9899 say snprintf should return | ||
| 81 | * the number of characters that would have been written, | ||
| 82 | * had the buffer been large enough.)" | ||
| 83 | */ | ||
| 84 | int | ||
| 85 | BIO_snprintf(char *buf, size_t n, const char *format, ...) | ||
| 86 | { | ||
| 87 | va_list args; | ||
| 88 | int ret; | ||
| 89 | |||
| 90 | va_start(args, format); | ||
| 91 | ret = vsnprintf(buf, n, format, args); | ||
| 92 | va_end(args); | ||
| 93 | |||
| 94 | if (ret >= n || ret == -1) | ||
| 95 | return (-1); | ||
| 96 | return (ret); | ||
| 97 | } | ||
| 98 | |||
| 99 | int | ||
| 100 | BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | ||
| 101 | { | ||
| 102 | int ret; | ||
| 103 | |||
| 104 | ret = vsnprintf(buf, n, format, args); | ||
| 105 | |||
| 106 | if (ret >= n || ret == -1) | ||
| 107 | return (-1); | ||
| 108 | return (ret); | ||
| 109 | } | ||
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c deleted file mode 100644 index ece88277df..0000000000 --- a/src/lib/libcrypto/bio/b_sock.c +++ /dev/null | |||
| @@ -1,444 +0,0 @@ | |||
| 1 | /* $OpenBSD: b_sock.c,v 1.61 2014/12/03 22:14:38 bcook Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <sys/ioctl.h> | ||
| 60 | #include <sys/socket.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <arpa/inet.h> | ||
| 64 | #include <netinet/in.h> | ||
| 65 | #include <netinet/tcp.h> | ||
| 66 | |||
| 67 | #include <errno.h> | ||
| 68 | #include <limits.h> | ||
| 69 | #include <netdb.h> | ||
| 70 | #include <stdio.h> | ||
| 71 | #include <stdlib.h> | ||
| 72 | #include <unistd.h> | ||
| 73 | |||
| 74 | #include <openssl/bio.h> | ||
| 75 | #include <openssl/buffer.h> | ||
| 76 | #include <openssl/err.h> | ||
| 77 | |||
| 78 | int | ||
| 79 | BIO_get_host_ip(const char *str, unsigned char *ip) | ||
| 80 | { | ||
| 81 | int i; | ||
| 82 | int err = 1; | ||
| 83 | struct hostent *he; | ||
| 84 | |||
| 85 | if (inet_pton(AF_INET, str, ip) == 1) | ||
| 86 | return (1); | ||
| 87 | |||
| 88 | /* do a gethostbyname */ | ||
| 89 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
| 90 | he = BIO_gethostbyname(str); | ||
| 91 | if (he == NULL) { | ||
| 92 | BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP); | ||
| 93 | goto err; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (he->h_addrtype != AF_INET) { | ||
| 97 | BIOerr(BIO_F_BIO_GET_HOST_IP, | ||
| 98 | BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); | ||
| 99 | goto err; | ||
| 100 | } | ||
| 101 | for (i = 0; i < 4; i++) | ||
| 102 | ip[i] = he->h_addr_list[0][i]; | ||
| 103 | err = 0; | ||
| 104 | |||
| 105 | err: | ||
| 106 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | ||
| 107 | if (err) { | ||
| 108 | ERR_asprintf_error_data("host=%s", str); | ||
| 109 | return 0; | ||
| 110 | } else | ||
| 111 | return 1; | ||
| 112 | } | ||
| 113 | |||
| 114 | int | ||
| 115 | BIO_get_port(const char *str, unsigned short *port_ptr) | ||
| 116 | { | ||
| 117 | struct addrinfo *res = NULL; | ||
| 118 | struct addrinfo hints = { | ||
| 119 | .ai_family = AF_UNSPEC, | ||
| 120 | .ai_socktype = SOCK_STREAM, | ||
| 121 | .ai_flags = AI_PASSIVE, | ||
| 122 | }; | ||
| 123 | long port; | ||
| 124 | char *ep; | ||
| 125 | |||
| 126 | if (str == NULL) { | ||
| 127 | BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_SPECIFIED); | ||
| 128 | return (0); | ||
| 129 | } | ||
| 130 | |||
| 131 | errno = 0; | ||
| 132 | port = strtol(str, &ep, 10); | ||
| 133 | if (str[0] != '\0' && *ep == '\0') { | ||
| 134 | if (errno == ERANGE && (port == LONG_MAX || port == LONG_MIN)) { | ||
| 135 | BIOerr(BIO_F_BIO_GET_PORT, BIO_R_INVALID_PORT_NUMBER); | ||
| 136 | return (0); | ||
| 137 | } | ||
| 138 | if (port < 0 || port > 65535) { | ||
| 139 | BIOerr(BIO_F_BIO_GET_PORT, BIO_R_INVALID_PORT_NUMBER); | ||
| 140 | return (0); | ||
| 141 | } | ||
| 142 | goto done; | ||
| 143 | } | ||
| 144 | |||
| 145 | if (getaddrinfo(NULL, str, &hints, &res) == 0) { | ||
| 146 | port = ntohs(((struct sockaddr_in *)(res->ai_addr))->sin_port); | ||
| 147 | goto done; | ||
| 148 | } | ||
| 149 | |||
| 150 | if (strcmp(str, "http") == 0) | ||
| 151 | port = 80; | ||
| 152 | else if (strcmp(str, "telnet") == 0) | ||
| 153 | port = 23; | ||
| 154 | else if (strcmp(str, "socks") == 0) | ||
| 155 | port = 1080; | ||
| 156 | else if (strcmp(str, "https") == 0) | ||
| 157 | port = 443; | ||
| 158 | else if (strcmp(str, "ssl") == 0) | ||
| 159 | port = 443; | ||
| 160 | else if (strcmp(str, "ftp") == 0) | ||
| 161 | port = 21; | ||
| 162 | else if (strcmp(str, "gopher") == 0) | ||
| 163 | port = 70; | ||
| 164 | else { | ||
| 165 | SYSerr(SYS_F_GETSERVBYNAME, errno); | ||
| 166 | ERR_asprintf_error_data("service='%s'", str); | ||
| 167 | return (0); | ||
| 168 | } | ||
| 169 | |||
| 170 | done: | ||
| 171 | if (res) | ||
| 172 | freeaddrinfo(res); | ||
| 173 | *port_ptr = (unsigned short)port; | ||
| 174 | return (1); | ||
| 175 | } | ||
| 176 | |||
| 177 | int | ||
| 178 | BIO_sock_error(int sock) | ||
| 179 | { | ||
| 180 | socklen_t len; | ||
| 181 | int err; | ||
| 182 | |||
| 183 | len = sizeof(err); | ||
| 184 | if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) != 0) | ||
| 185 | return (1); | ||
| 186 | return (err); | ||
| 187 | } | ||
| 188 | |||
| 189 | struct hostent * | ||
| 190 | BIO_gethostbyname(const char *name) | ||
| 191 | { | ||
| 192 | return gethostbyname(name); | ||
| 193 | } | ||
| 194 | |||
| 195 | int | ||
| 196 | BIO_socket_ioctl(int fd, long type, void *arg) | ||
| 197 | { | ||
| 198 | int ret; | ||
| 199 | |||
| 200 | ret = ioctl(fd, type, arg); | ||
| 201 | if (ret < 0) | ||
| 202 | SYSerr(SYS_F_IOCTLSOCKET, errno); | ||
| 203 | return (ret); | ||
| 204 | } | ||
| 205 | |||
| 206 | int | ||
| 207 | BIO_get_accept_socket(char *host, int bind_mode) | ||
| 208 | { | ||
| 209 | int ret = 0; | ||
| 210 | union { | ||
| 211 | struct sockaddr sa; | ||
| 212 | struct sockaddr_in sa_in; | ||
| 213 | struct sockaddr_in6 sa_in6; | ||
| 214 | } server, client; | ||
| 215 | int s = -1, cs, addrlen; | ||
| 216 | unsigned char ip[4]; | ||
| 217 | unsigned short port; | ||
| 218 | char *str = NULL, *e; | ||
| 219 | char *h, *p; | ||
| 220 | unsigned long l; | ||
| 221 | int err_num; | ||
| 222 | |||
| 223 | if (host == NULL || (str = strdup(host)) == NULL) | ||
| 224 | return (-1); | ||
| 225 | |||
| 226 | h = p = NULL; | ||
| 227 | h = str; | ||
| 228 | for (e = str; *e; e++) { | ||
| 229 | if (*e == ':') { | ||
| 230 | p = e; | ||
| 231 | } else if (*e == '/') { | ||
| 232 | *e = '\0'; | ||
| 233 | break; | ||
| 234 | } | ||
| 235 | } | ||
| 236 | /* points at last ':', '::port' is special [see below] */ | ||
| 237 | if (p) | ||
| 238 | *p++ = '\0'; | ||
| 239 | else | ||
| 240 | p = h, h = NULL; | ||
| 241 | |||
| 242 | do { | ||
| 243 | struct addrinfo *res, hint; | ||
| 244 | |||
| 245 | /* | ||
| 246 | * '::port' enforces IPv6 wildcard listener. Some OSes, | ||
| 247 | * e.g. Solaris, default to IPv6 without any hint. Also | ||
| 248 | * note that commonly IPv6 wildchard socket can service | ||
| 249 | * IPv4 connections just as well... | ||
| 250 | */ | ||
| 251 | memset(&hint, 0, sizeof(hint)); | ||
| 252 | hint.ai_flags = AI_PASSIVE; | ||
| 253 | if (h) { | ||
| 254 | if (strchr(h, ':')) { | ||
| 255 | if (h[1] == '\0') | ||
| 256 | h = NULL; | ||
| 257 | hint.ai_family = AF_INET6; | ||
| 258 | } else if (h[0] == '*' && h[1] == '\0') { | ||
| 259 | hint.ai_family = AF_INET; | ||
| 260 | h = NULL; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | if (getaddrinfo(h, p, &hint, &res)) | ||
| 265 | break; | ||
| 266 | |||
| 267 | addrlen = res->ai_addrlen <= sizeof(server) ? | ||
| 268 | res->ai_addrlen : sizeof(server); | ||
| 269 | memcpy(&server, res->ai_addr, addrlen); | ||
| 270 | |||
| 271 | freeaddrinfo(res); | ||
| 272 | goto again; | ||
| 273 | } while (0); | ||
| 274 | |||
| 275 | if (!BIO_get_port(p, &port)) | ||
| 276 | goto err; | ||
| 277 | |||
| 278 | memset((char *)&server, 0, sizeof(server)); | ||
| 279 | server.sa_in.sin_family = AF_INET; | ||
| 280 | server.sa_in.sin_port = htons(port); | ||
| 281 | addrlen = sizeof(server.sa_in); | ||
| 282 | |||
| 283 | if (h == NULL || strcmp(h, "*") == 0) | ||
| 284 | server.sa_in.sin_addr.s_addr = INADDR_ANY; | ||
| 285 | else { | ||
| 286 | if (!BIO_get_host_ip(h, &(ip[0]))) | ||
| 287 | goto err; | ||
| 288 | l = (unsigned long)((unsigned long)ip[0]<<24L)| | ||
| 289 | ((unsigned long)ip[1]<<16L)| | ||
| 290 | ((unsigned long)ip[2]<< 8L)| | ||
| 291 | ((unsigned long)ip[3]); | ||
| 292 | server.sa_in.sin_addr.s_addr = htonl(l); | ||
| 293 | } | ||
| 294 | |||
| 295 | again: | ||
| 296 | s = socket(server.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); | ||
| 297 | if (s == -1) { | ||
| 298 | SYSerr(SYS_F_SOCKET, errno); | ||
| 299 | ERR_asprintf_error_data("port='%s'", host); | ||
| 300 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, | ||
| 301 | BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
| 302 | goto err; | ||
| 303 | } | ||
| 304 | |||
| 305 | if (bind_mode == BIO_BIND_REUSEADDR) { | ||
| 306 | int i = 1; | ||
| 307 | |||
| 308 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)); | ||
| 309 | bind_mode = BIO_BIND_NORMAL; | ||
| 310 | } | ||
| 311 | if (bind(s, &server.sa, addrlen) == -1) { | ||
| 312 | err_num = errno; | ||
| 313 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && | ||
| 314 | (err_num == EADDRINUSE)) { | ||
| 315 | client = server; | ||
| 316 | if (h == NULL || strcmp(h, "*") == 0) { | ||
| 317 | if (client.sa.sa_family == AF_INET6) { | ||
| 318 | memset(&client.sa_in6.sin6_addr, 0, | ||
| 319 | sizeof(client.sa_in6.sin6_addr)); | ||
| 320 | client.sa_in6.sin6_addr.s6_addr[15] = 1; | ||
| 321 | } else if (client.sa.sa_family == AF_INET) { | ||
| 322 | client.sa_in.sin_addr.s_addr = | ||
| 323 | htonl(0x7F000001); | ||
| 324 | } else | ||
| 325 | goto err; | ||
| 326 | } | ||
| 327 | cs = socket(client.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); | ||
| 328 | if (cs != -1) { | ||
| 329 | int ii; | ||
| 330 | ii = connect(cs, &client.sa, addrlen); | ||
| 331 | close(cs); | ||
| 332 | if (ii == -1) { | ||
| 333 | bind_mode = BIO_BIND_REUSEADDR; | ||
| 334 | close(s); | ||
| 335 | goto again; | ||
| 336 | } | ||
| 337 | /* else error */ | ||
| 338 | } | ||
| 339 | /* else error */ | ||
| 340 | } | ||
| 341 | SYSerr(SYS_F_BIND, err_num); | ||
| 342 | ERR_asprintf_error_data("port='%s'", host); | ||
| 343 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, | ||
| 344 | BIO_R_UNABLE_TO_BIND_SOCKET); | ||
| 345 | goto err; | ||
| 346 | } | ||
| 347 | if (listen(s, SOMAXCONN) == -1) { | ||
| 348 | SYSerr(SYS_F_BIND, errno); | ||
| 349 | ERR_asprintf_error_data("port='%s'", host); | ||
| 350 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, | ||
| 351 | BIO_R_UNABLE_TO_LISTEN_SOCKET); | ||
| 352 | goto err; | ||
| 353 | } | ||
| 354 | ret = 1; | ||
| 355 | err: | ||
| 356 | free(str); | ||
| 357 | if ((ret == 0) && (s != -1)) { | ||
| 358 | close(s); | ||
| 359 | s = -1; | ||
| 360 | } | ||
| 361 | return (s); | ||
| 362 | } | ||
| 363 | |||
| 364 | int | ||
| 365 | BIO_accept(int sock, char **addr) | ||
| 366 | { | ||
| 367 | int ret = -1; | ||
| 368 | unsigned long l; | ||
| 369 | unsigned short port; | ||
| 370 | char *p, *tmp; | ||
| 371 | |||
| 372 | struct { | ||
| 373 | socklen_t len; | ||
| 374 | union { | ||
| 375 | struct sockaddr sa; | ||
| 376 | struct sockaddr_in sa_in; | ||
| 377 | struct sockaddr_in6 sa_in6; | ||
| 378 | } from; | ||
| 379 | } sa; | ||
| 380 | |||
| 381 | sa.len = sizeof(sa.from); | ||
| 382 | memset(&sa.from, 0, sizeof(sa.from)); | ||
| 383 | ret = accept(sock, &sa.from.sa, &sa.len); | ||
| 384 | if (ret == -1) { | ||
| 385 | if (BIO_sock_should_retry(ret)) | ||
| 386 | return -2; | ||
| 387 | SYSerr(SYS_F_ACCEPT, errno); | ||
| 388 | BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR); | ||
| 389 | goto end; | ||
| 390 | } | ||
| 391 | |||
| 392 | if (addr == NULL) | ||
| 393 | goto end; | ||
| 394 | |||
| 395 | do { | ||
| 396 | char h[NI_MAXHOST], s[NI_MAXSERV]; | ||
| 397 | size_t nl; | ||
| 398 | |||
| 399 | if (getnameinfo(&sa.from.sa, sa.len, h, sizeof(h), | ||
| 400 | s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV)) | ||
| 401 | break; | ||
| 402 | nl = strlen(h) + strlen(s) + 2; | ||
| 403 | p = *addr; | ||
| 404 | if (p) | ||
| 405 | *p = '\0'; | ||
| 406 | if (!(tmp = realloc(p, nl))) { | ||
| 407 | close(ret); | ||
| 408 | ret = -1; | ||
| 409 | free(p); | ||
| 410 | *addr = NULL; | ||
| 411 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | ||
| 412 | goto end; | ||
| 413 | } | ||
| 414 | p = tmp; | ||
| 415 | *addr = p; | ||
| 416 | snprintf(*addr, nl, "%s:%s", h, s); | ||
| 417 | goto end; | ||
| 418 | } while (0); | ||
| 419 | if (sa.from.sa.sa_family != AF_INET) | ||
| 420 | goto end; | ||
| 421 | l = ntohl(sa.from.sa_in.sin_addr.s_addr); | ||
| 422 | port = ntohs(sa.from.sa_in.sin_port); | ||
| 423 | if (*addr == NULL) { | ||
| 424 | if ((p = malloc(24)) == NULL) { | ||
| 425 | close(ret); | ||
| 426 | ret = -1; | ||
| 427 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | ||
| 428 | goto end; | ||
| 429 | } | ||
| 430 | *addr = p; | ||
| 431 | } | ||
| 432 | snprintf(*addr, 24, "%d.%d.%d.%d:%d", | ||
| 433 | (unsigned char)(l >> 24L) & 0xff, (unsigned char)(l >> 16L) & 0xff, | ||
| 434 | (unsigned char)(l >> 8L) & 0xff, (unsigned char)(l) & 0xff, port); | ||
| 435 | |||
| 436 | end: | ||
| 437 | return (ret); | ||
| 438 | } | ||
| 439 | |||
| 440 | int | ||
| 441 | BIO_set_tcp_ndelay(int s, int on) | ||
| 442 | { | ||
| 443 | return (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) == 0); | ||
| 444 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c deleted file mode 100644 index 588cc48a28..0000000000 --- a/src/lib/libcrypto/bio/bf_buff.c +++ /dev/null | |||
| @@ -1,520 +0,0 @@ | |||
| 1 | /* $OpenBSD: bf_buff.c,v 1.23 2015/07/19 18:29:31 miod Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/bio.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | |||
| 66 | static int buffer_write(BIO *h, const char *buf, int num); | ||
| 67 | static int buffer_read(BIO *h, char *buf, int size); | ||
| 68 | static int buffer_puts(BIO *h, const char *str); | ||
| 69 | static int buffer_gets(BIO *h, char *str, int size); | ||
| 70 | static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 71 | static int buffer_new(BIO *h); | ||
| 72 | static int buffer_free(BIO *data); | ||
| 73 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | ||
| 74 | #define DEFAULT_BUFFER_SIZE 4096 | ||
| 75 | |||
| 76 | static BIO_METHOD methods_buffer = { | ||
| 77 | .type = BIO_TYPE_BUFFER, | ||
| 78 | .name = "buffer", | ||
| 79 | .bwrite = buffer_write, | ||
| 80 | .bread = buffer_read, | ||
| 81 | .bputs = buffer_puts, | ||
| 82 | .bgets = buffer_gets, | ||
| 83 | .ctrl = buffer_ctrl, | ||
| 84 | .create = buffer_new, | ||
| 85 | .destroy = buffer_free, | ||
| 86 | .callback_ctrl = buffer_callback_ctrl | ||
| 87 | }; | ||
| 88 | |||
| 89 | BIO_METHOD * | ||
| 90 | BIO_f_buffer(void) | ||
| 91 | { | ||
| 92 | return (&methods_buffer); | ||
| 93 | } | ||
| 94 | |||
| 95 | static int | ||
| 96 | buffer_new(BIO *bi) | ||
| 97 | { | ||
| 98 | BIO_F_BUFFER_CTX *ctx; | ||
| 99 | |||
| 100 | ctx = malloc(sizeof(BIO_F_BUFFER_CTX)); | ||
| 101 | if (ctx == NULL) | ||
| 102 | return (0); | ||
| 103 | ctx->ibuf = malloc(DEFAULT_BUFFER_SIZE); | ||
| 104 | if (ctx->ibuf == NULL) { | ||
| 105 | free(ctx); | ||
| 106 | return (0); | ||
| 107 | } | ||
| 108 | ctx->obuf = malloc(DEFAULT_BUFFER_SIZE); | ||
| 109 | if (ctx->obuf == NULL) { | ||
| 110 | free(ctx->ibuf); | ||
| 111 | free(ctx); | ||
| 112 | return (0); | ||
| 113 | } | ||
| 114 | ctx->ibuf_size = DEFAULT_BUFFER_SIZE; | ||
| 115 | ctx->obuf_size = DEFAULT_BUFFER_SIZE; | ||
| 116 | ctx->ibuf_len = 0; | ||
| 117 | ctx->ibuf_off = 0; | ||
| 118 | ctx->obuf_len = 0; | ||
| 119 | ctx->obuf_off = 0; | ||
| 120 | |||
| 121 | bi->init = 1; | ||
| 122 | bi->ptr = (char *)ctx; | ||
| 123 | bi->flags = 0; | ||
| 124 | return (1); | ||
| 125 | } | ||
| 126 | |||
| 127 | static int | ||
| 128 | buffer_free(BIO *a) | ||
| 129 | { | ||
| 130 | BIO_F_BUFFER_CTX *b; | ||
| 131 | |||
| 132 | if (a == NULL) | ||
| 133 | return (0); | ||
| 134 | b = (BIO_F_BUFFER_CTX *)a->ptr; | ||
| 135 | free(b->ibuf); | ||
| 136 | free(b->obuf); | ||
| 137 | free(a->ptr); | ||
| 138 | a->ptr = NULL; | ||
| 139 | a->init = 0; | ||
| 140 | a->flags = 0; | ||
| 141 | return (1); | ||
| 142 | } | ||
| 143 | |||
| 144 | static int | ||
| 145 | buffer_read(BIO *b, char *out, int outl) | ||
| 146 | { | ||
| 147 | int i, num = 0; | ||
| 148 | BIO_F_BUFFER_CTX *ctx; | ||
| 149 | |||
| 150 | if (out == NULL) | ||
| 151 | return (0); | ||
| 152 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | ||
| 153 | |||
| 154 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
| 155 | return (0); | ||
| 156 | num = 0; | ||
| 157 | BIO_clear_retry_flags(b); | ||
| 158 | |||
| 159 | start: | ||
| 160 | i = ctx->ibuf_len; | ||
| 161 | /* If there is stuff left over, grab it */ | ||
| 162 | if (i != 0) { | ||
| 163 | if (i > outl) | ||
| 164 | i = outl; | ||
| 165 | memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i); | ||
| 166 | ctx->ibuf_off += i; | ||
| 167 | ctx->ibuf_len -= i; | ||
| 168 | num += i; | ||
| 169 | if (outl == i) | ||
| 170 | return (num); | ||
| 171 | outl -= i; | ||
| 172 | out += i; | ||
| 173 | } | ||
| 174 | |||
| 175 | /* We may have done a partial read. try to do more. | ||
| 176 | * We have nothing in the buffer. | ||
| 177 | * If we get an error and have read some data, just return it | ||
| 178 | * and let them retry to get the error again. | ||
| 179 | * copy direct to parent address space */ | ||
| 180 | if (outl > ctx->ibuf_size) { | ||
| 181 | for (;;) { | ||
| 182 | i = BIO_read(b->next_bio, out, outl); | ||
| 183 | if (i <= 0) { | ||
| 184 | BIO_copy_next_retry(b); | ||
| 185 | if (i < 0) | ||
| 186 | return ((num > 0) ? num : i); | ||
| 187 | if (i == 0) | ||
| 188 | return (num); | ||
| 189 | } | ||
| 190 | num += i; | ||
| 191 | if (outl == i) | ||
| 192 | return (num); | ||
| 193 | out += i; | ||
| 194 | outl -= i; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | /* else */ | ||
| 198 | |||
| 199 | /* we are going to be doing some buffering */ | ||
| 200 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); | ||
| 201 | if (i <= 0) { | ||
| 202 | BIO_copy_next_retry(b); | ||
| 203 | if (i < 0) | ||
| 204 | return ((num > 0) ? num : i); | ||
| 205 | if (i == 0) | ||
| 206 | return (num); | ||
| 207 | } | ||
| 208 | ctx->ibuf_off = 0; | ||
| 209 | ctx->ibuf_len = i; | ||
| 210 | |||
| 211 | /* Lets re-read using ourselves :-) */ | ||
| 212 | goto start; | ||
| 213 | } | ||
| 214 | |||
| 215 | static int | ||
| 216 | buffer_write(BIO *b, const char *in, int inl) | ||
| 217 | { | ||
| 218 | int i, num = 0; | ||
| 219 | BIO_F_BUFFER_CTX *ctx; | ||
| 220 | |||
| 221 | if ((in == NULL) || (inl <= 0)) | ||
| 222 | return (0); | ||
| 223 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | ||
| 224 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
| 225 | return (0); | ||
| 226 | |||
| 227 | BIO_clear_retry_flags(b); | ||
| 228 | start: | ||
| 229 | i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off); | ||
| 230 | /* add to buffer and return */ | ||
| 231 | if (i >= inl) { | ||
| 232 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl); | ||
| 233 | ctx->obuf_len += inl; | ||
| 234 | return (num + inl); | ||
| 235 | } | ||
| 236 | /* else */ | ||
| 237 | /* stuff already in buffer, so add to it first, then flush */ | ||
| 238 | if (ctx->obuf_len != 0) { | ||
| 239 | if (i > 0) /* lets fill it up if we can */ | ||
| 240 | { | ||
| 241 | memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i); | ||
| 242 | in += i; | ||
| 243 | inl -= i; | ||
| 244 | num += i; | ||
| 245 | ctx->obuf_len += i; | ||
| 246 | } | ||
| 247 | /* we now have a full buffer needing flushing */ | ||
| 248 | for (;;) { | ||
| 249 | i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]), | ||
| 250 | ctx->obuf_len); | ||
| 251 | if (i <= 0) { | ||
| 252 | BIO_copy_next_retry(b); | ||
| 253 | |||
| 254 | if (i < 0) | ||
| 255 | return ((num > 0) ? num : i); | ||
| 256 | if (i == 0) | ||
| 257 | return (num); | ||
| 258 | } | ||
| 259 | ctx->obuf_off += i; | ||
| 260 | ctx->obuf_len -= i; | ||
| 261 | if (ctx->obuf_len == 0) | ||
| 262 | break; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | /* we only get here if the buffer has been flushed and we | ||
| 266 | * still have stuff to write */ | ||
| 267 | ctx->obuf_off = 0; | ||
| 268 | |||
| 269 | /* we now have inl bytes to write */ | ||
| 270 | while (inl >= ctx->obuf_size) { | ||
| 271 | i = BIO_write(b->next_bio, in, inl); | ||
| 272 | if (i <= 0) { | ||
| 273 | BIO_copy_next_retry(b); | ||
| 274 | if (i < 0) | ||
| 275 | return ((num > 0) ? num : i); | ||
| 276 | if (i == 0) | ||
| 277 | return (num); | ||
| 278 | } | ||
| 279 | num += i; | ||
| 280 | in += i; | ||
| 281 | inl -= i; | ||
| 282 | if (inl == 0) | ||
| 283 | return (num); | ||
| 284 | } | ||
| 285 | |||
| 286 | /* copy the rest into the buffer since we have only a small | ||
| 287 | * amount left */ | ||
| 288 | goto start; | ||
| 289 | } | ||
| 290 | |||
| 291 | static long | ||
| 292 | buffer_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 293 | { | ||
| 294 | BIO *dbio; | ||
| 295 | BIO_F_BUFFER_CTX *ctx; | ||
| 296 | long ret = 1; | ||
| 297 | char *p1, *p2; | ||
| 298 | int r, i, *ip; | ||
| 299 | int ibs, obs; | ||
| 300 | |||
| 301 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | ||
| 302 | |||
| 303 | switch (cmd) { | ||
| 304 | case BIO_CTRL_RESET: | ||
| 305 | ctx->ibuf_off = 0; | ||
| 306 | ctx->ibuf_len = 0; | ||
| 307 | ctx->obuf_off = 0; | ||
| 308 | ctx->obuf_len = 0; | ||
| 309 | if (b->next_bio == NULL) | ||
| 310 | return (0); | ||
| 311 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 312 | break; | ||
| 313 | case BIO_CTRL_INFO: | ||
| 314 | ret = (long)ctx->obuf_len; | ||
| 315 | break; | ||
| 316 | case BIO_C_GET_BUFF_NUM_LINES: | ||
| 317 | ret = 0; | ||
| 318 | p1 = ctx->ibuf; | ||
| 319 | for (i = 0; i < ctx->ibuf_len; i++) { | ||
| 320 | if (p1[ctx->ibuf_off + i] == '\n') | ||
| 321 | ret++; | ||
| 322 | } | ||
| 323 | break; | ||
| 324 | case BIO_CTRL_WPENDING: | ||
| 325 | ret = (long)ctx->obuf_len; | ||
| 326 | if (ret == 0) { | ||
| 327 | if (b->next_bio == NULL) | ||
| 328 | return (0); | ||
| 329 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 330 | } | ||
| 331 | break; | ||
| 332 | case BIO_CTRL_PENDING: | ||
| 333 | ret = (long)ctx->ibuf_len; | ||
| 334 | if (ret == 0) { | ||
| 335 | if (b->next_bio == NULL) | ||
| 336 | return (0); | ||
| 337 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 338 | } | ||
| 339 | break; | ||
| 340 | case BIO_C_SET_BUFF_READ_DATA: | ||
| 341 | if (num > ctx->ibuf_size) { | ||
| 342 | p1 = malloc(num); | ||
| 343 | if (p1 == NULL) | ||
| 344 | goto malloc_error; | ||
| 345 | free(ctx->ibuf); | ||
| 346 | ctx->ibuf = p1; | ||
| 347 | } | ||
| 348 | ctx->ibuf_off = 0; | ||
| 349 | ctx->ibuf_len = (int)num; | ||
| 350 | memcpy(ctx->ibuf, ptr, num); | ||
| 351 | ret = 1; | ||
| 352 | break; | ||
| 353 | case BIO_C_SET_BUFF_SIZE: | ||
| 354 | if (ptr != NULL) { | ||
| 355 | ip = (int *)ptr; | ||
| 356 | if (*ip == 0) { | ||
| 357 | ibs = (int)num; | ||
| 358 | obs = ctx->obuf_size; | ||
| 359 | } | ||
| 360 | else /* if (*ip == 1) */ | ||
| 361 | { | ||
| 362 | ibs = ctx->ibuf_size; | ||
| 363 | obs = (int)num; | ||
| 364 | } | ||
| 365 | } else { | ||
| 366 | ibs = (int)num; | ||
| 367 | obs = (int)num; | ||
| 368 | } | ||
| 369 | p1 = ctx->ibuf; | ||
| 370 | p2 = ctx->obuf; | ||
| 371 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) { | ||
| 372 | p1 = malloc(num); | ||
| 373 | if (p1 == NULL) | ||
| 374 | goto malloc_error; | ||
| 375 | } | ||
| 376 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { | ||
| 377 | p2 = malloc(num); | ||
| 378 | if (p2 == NULL) { | ||
| 379 | if (p1 != ctx->ibuf) | ||
| 380 | free(p1); | ||
| 381 | goto malloc_error; | ||
| 382 | } | ||
| 383 | } | ||
| 384 | if (ctx->ibuf != p1) { | ||
| 385 | free(ctx->ibuf); | ||
| 386 | ctx->ibuf = p1; | ||
| 387 | ctx->ibuf_off = 0; | ||
| 388 | ctx->ibuf_len = 0; | ||
| 389 | ctx->ibuf_size = ibs; | ||
| 390 | } | ||
| 391 | if (ctx->obuf != p2) { | ||
| 392 | free(ctx->obuf); | ||
| 393 | ctx->obuf = p2; | ||
| 394 | ctx->obuf_off = 0; | ||
| 395 | ctx->obuf_len = 0; | ||
| 396 | ctx->obuf_size = obs; | ||
| 397 | } | ||
| 398 | break; | ||
| 399 | case BIO_C_DO_STATE_MACHINE: | ||
| 400 | if (b->next_bio == NULL) | ||
| 401 | return (0); | ||
| 402 | BIO_clear_retry_flags(b); | ||
| 403 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 404 | BIO_copy_next_retry(b); | ||
| 405 | break; | ||
| 406 | |||
| 407 | case BIO_CTRL_FLUSH: | ||
| 408 | if (b->next_bio == NULL) | ||
| 409 | return (0); | ||
| 410 | if (ctx->obuf_len <= 0) { | ||
| 411 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 412 | break; | ||
| 413 | } | ||
| 414 | |||
| 415 | for (;;) { | ||
| 416 | BIO_clear_retry_flags(b); | ||
| 417 | if (ctx->obuf_len > 0) { | ||
| 418 | r = BIO_write(b->next_bio, | ||
| 419 | &(ctx->obuf[ctx->obuf_off]), | ||
| 420 | ctx->obuf_len); | ||
| 421 | BIO_copy_next_retry(b); | ||
| 422 | if (r <= 0) | ||
| 423 | return ((long)r); | ||
| 424 | ctx->obuf_off += r; | ||
| 425 | ctx->obuf_len -= r; | ||
| 426 | } else { | ||
| 427 | ctx->obuf_len = 0; | ||
| 428 | ctx->obuf_off = 0; | ||
| 429 | break; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 433 | break; | ||
| 434 | case BIO_CTRL_DUP: | ||
| 435 | dbio = (BIO *)ptr; | ||
| 436 | if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) || | ||
| 437 | !BIO_set_write_buffer_size(dbio, ctx->obuf_size)) | ||
| 438 | ret = 0; | ||
| 439 | break; | ||
| 440 | default: | ||
| 441 | if (b->next_bio == NULL) | ||
| 442 | return (0); | ||
| 443 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 444 | break; | ||
| 445 | } | ||
| 446 | return (ret); | ||
| 447 | malloc_error: | ||
| 448 | BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE); | ||
| 449 | return (0); | ||
| 450 | } | ||
| 451 | |||
| 452 | static long | ||
| 453 | buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
| 454 | { | ||
| 455 | long ret = 1; | ||
| 456 | |||
| 457 | if (b->next_bio == NULL) | ||
| 458 | return (0); | ||
| 459 | switch (cmd) { | ||
| 460 | default: | ||
| 461 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | ||
| 462 | break; | ||
| 463 | } | ||
| 464 | return (ret); | ||
| 465 | } | ||
| 466 | |||
| 467 | static int | ||
| 468 | buffer_gets(BIO *b, char *buf, int size) | ||
| 469 | { | ||
| 470 | BIO_F_BUFFER_CTX *ctx; | ||
| 471 | int num = 0, i, flag; | ||
| 472 | char *p; | ||
| 473 | |||
| 474 | ctx = (BIO_F_BUFFER_CTX *)b->ptr; | ||
| 475 | size--; /* reserve space for a '\0' */ | ||
| 476 | BIO_clear_retry_flags(b); | ||
| 477 | |||
| 478 | for (;;) { | ||
| 479 | if (ctx->ibuf_len > 0) { | ||
| 480 | p = &(ctx->ibuf[ctx->ibuf_off]); | ||
| 481 | flag = 0; | ||
| 482 | for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) { | ||
| 483 | *(buf++) = p[i]; | ||
| 484 | if (p[i] == '\n') { | ||
| 485 | flag = 1; | ||
| 486 | i++; | ||
| 487 | break; | ||
| 488 | } | ||
| 489 | } | ||
| 490 | num += i; | ||
| 491 | size -= i; | ||
| 492 | ctx->ibuf_len -= i; | ||
| 493 | ctx->ibuf_off += i; | ||
| 494 | if (flag || size == 0) { | ||
| 495 | *buf = '\0'; | ||
| 496 | return (num); | ||
| 497 | } | ||
| 498 | } | ||
| 499 | else /* read another chunk */ | ||
| 500 | { | ||
| 501 | i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size); | ||
| 502 | if (i <= 0) { | ||
| 503 | BIO_copy_next_retry(b); | ||
| 504 | *buf = '\0'; | ||
| 505 | if (i < 0) | ||
| 506 | return ((num > 0) ? num : i); | ||
| 507 | if (i == 0) | ||
| 508 | return (num); | ||
| 509 | } | ||
| 510 | ctx->ibuf_len = i; | ||
| 511 | ctx->ibuf_off = 0; | ||
| 512 | } | ||
| 513 | } | ||
| 514 | } | ||
| 515 | |||
| 516 | static int | ||
| 517 | buffer_puts(BIO *b, const char *str) | ||
| 518 | { | ||
| 519 | return (buffer_write(b, str, strlen(str))); | ||
| 520 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c deleted file mode 100644 index 7978fdb347..0000000000 --- a/src/lib/libcrypto/bio/bf_lbuf.c +++ /dev/null | |||
| @@ -1,377 +0,0 @@ | |||
| 1 | /* $OpenBSD: bf_lbuf.c,v 1.13 2015/07/19 18:29:31 miod Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | |||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | |||
| 65 | static int linebuffer_write(BIO *h, const char *buf, int num); | ||
| 66 | static int linebuffer_read(BIO *h, char *buf, int size); | ||
| 67 | static int linebuffer_puts(BIO *h, const char *str); | ||
| 68 | static int linebuffer_gets(BIO *h, char *str, int size); | ||
| 69 | static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 70 | static int linebuffer_new(BIO *h); | ||
| 71 | static int linebuffer_free(BIO *data); | ||
| 72 | static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | ||
| 73 | |||
| 74 | /* A 10k maximum should be enough for most purposes */ | ||
| 75 | #define DEFAULT_LINEBUFFER_SIZE 1024*10 | ||
| 76 | |||
| 77 | /* #define DEBUG */ | ||
| 78 | |||
| 79 | static BIO_METHOD methods_linebuffer = { | ||
| 80 | .type = BIO_TYPE_LINEBUFFER, | ||
| 81 | .name = "linebuffer", | ||
| 82 | .bwrite = linebuffer_write, | ||
| 83 | .bread = linebuffer_read, | ||
| 84 | .bputs = linebuffer_puts, | ||
| 85 | .bgets = linebuffer_gets, | ||
| 86 | .ctrl = linebuffer_ctrl, | ||
| 87 | .create = linebuffer_new, | ||
| 88 | .destroy = linebuffer_free, | ||
| 89 | .callback_ctrl = linebuffer_callback_ctrl | ||
| 90 | }; | ||
| 91 | |||
| 92 | BIO_METHOD * | ||
| 93 | BIO_f_linebuffer(void) | ||
| 94 | { | ||
| 95 | return (&methods_linebuffer); | ||
| 96 | } | ||
| 97 | |||
| 98 | typedef struct bio_linebuffer_ctx_struct { | ||
| 99 | char *obuf; /* the output char array */ | ||
| 100 | int obuf_size; /* how big is the output buffer */ | ||
| 101 | int obuf_len; /* how many bytes are in it */ | ||
| 102 | } BIO_LINEBUFFER_CTX; | ||
| 103 | |||
| 104 | static int | ||
| 105 | linebuffer_new(BIO *bi) | ||
| 106 | { | ||
| 107 | BIO_LINEBUFFER_CTX *ctx; | ||
| 108 | |||
| 109 | ctx = malloc(sizeof(BIO_LINEBUFFER_CTX)); | ||
| 110 | if (ctx == NULL) | ||
| 111 | return (0); | ||
| 112 | ctx->obuf = malloc(DEFAULT_LINEBUFFER_SIZE); | ||
| 113 | if (ctx->obuf == NULL) { | ||
| 114 | free(ctx); | ||
| 115 | return (0); | ||
| 116 | } | ||
| 117 | ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE; | ||
| 118 | ctx->obuf_len = 0; | ||
| 119 | |||
| 120 | bi->init = 1; | ||
| 121 | bi->ptr = (char *)ctx; | ||
| 122 | bi->flags = 0; | ||
| 123 | return (1); | ||
| 124 | } | ||
| 125 | |||
| 126 | static int | ||
| 127 | linebuffer_free(BIO *a) | ||
| 128 | { | ||
| 129 | BIO_LINEBUFFER_CTX *b; | ||
| 130 | |||
| 131 | if (a == NULL) | ||
| 132 | return (0); | ||
| 133 | b = (BIO_LINEBUFFER_CTX *)a->ptr; | ||
| 134 | free(b->obuf); | ||
| 135 | free(a->ptr); | ||
| 136 | a->ptr = NULL; | ||
| 137 | a->init = 0; | ||
| 138 | a->flags = 0; | ||
| 139 | return (1); | ||
| 140 | } | ||
| 141 | |||
| 142 | static int | ||
| 143 | linebuffer_read(BIO *b, char *out, int outl) | ||
| 144 | { | ||
| 145 | int ret = 0; | ||
| 146 | |||
| 147 | if (out == NULL) | ||
| 148 | return (0); | ||
| 149 | if (b->next_bio == NULL) | ||
| 150 | return (0); | ||
| 151 | ret = BIO_read(b->next_bio, out, outl); | ||
| 152 | BIO_clear_retry_flags(b); | ||
| 153 | BIO_copy_next_retry(b); | ||
| 154 | return (ret); | ||
| 155 | } | ||
| 156 | |||
| 157 | static int | ||
| 158 | linebuffer_write(BIO *b, const char *in, int inl) | ||
| 159 | { | ||
| 160 | int i, num = 0, foundnl; | ||
| 161 | BIO_LINEBUFFER_CTX *ctx; | ||
| 162 | |||
| 163 | if ((in == NULL) || (inl <= 0)) | ||
| 164 | return (0); | ||
| 165 | ctx = (BIO_LINEBUFFER_CTX *)b->ptr; | ||
| 166 | if ((ctx == NULL) || (b->next_bio == NULL)) | ||
| 167 | return (0); | ||
| 168 | |||
| 169 | BIO_clear_retry_flags(b); | ||
| 170 | |||
| 171 | do { | ||
| 172 | const char *p; | ||
| 173 | |||
| 174 | for (p = in; p < in + inl && *p != '\n'; p++) | ||
| 175 | ; | ||
| 176 | if (*p == '\n') { | ||
| 177 | p++; | ||
| 178 | foundnl = 1; | ||
| 179 | } else | ||
| 180 | foundnl = 0; | ||
| 181 | |||
| 182 | /* If a NL was found and we already have text in the save | ||
| 183 | buffer, concatenate them and write */ | ||
| 184 | while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) && | ||
| 185 | ctx->obuf_len > 0) { | ||
| 186 | int orig_olen = ctx->obuf_len; | ||
| 187 | |||
| 188 | i = ctx->obuf_size - ctx->obuf_len; | ||
| 189 | if (p - in > 0) { | ||
| 190 | if (i >= p - in) { | ||
| 191 | memcpy(&(ctx->obuf[ctx->obuf_len]), | ||
| 192 | in, p - in); | ||
| 193 | ctx->obuf_len += p - in; | ||
| 194 | inl -= p - in; | ||
| 195 | num += p - in; | ||
| 196 | in = p; | ||
| 197 | } else { | ||
| 198 | memcpy(&(ctx->obuf[ctx->obuf_len]), | ||
| 199 | in, i); | ||
| 200 | ctx->obuf_len += i; | ||
| 201 | inl -= i; | ||
| 202 | in += i; | ||
| 203 | num += i; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len); | ||
| 208 | if (i <= 0) { | ||
| 209 | ctx->obuf_len = orig_olen; | ||
| 210 | BIO_copy_next_retry(b); | ||
| 211 | if (i < 0) | ||
| 212 | return ((num > 0) ? num : i); | ||
| 213 | if (i == 0) | ||
| 214 | return (num); | ||
| 215 | } | ||
| 216 | if (i < ctx->obuf_len) | ||
| 217 | memmove(ctx->obuf, ctx->obuf + i, | ||
| 218 | ctx->obuf_len - i); | ||
| 219 | ctx->obuf_len -= i; | ||
| 220 | } | ||
| 221 | |||
| 222 | /* Now that the save buffer is emptied, let's write the input | ||
| 223 | buffer if a NL was found and there is anything to write. */ | ||
| 224 | if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) { | ||
| 225 | i = BIO_write(b->next_bio, in, p - in); | ||
| 226 | if (i <= 0) { | ||
| 227 | BIO_copy_next_retry(b); | ||
| 228 | if (i < 0) | ||
| 229 | return ((num > 0) ? num : i); | ||
| 230 | if (i == 0) | ||
| 231 | return (num); | ||
| 232 | } | ||
| 233 | num += i; | ||
| 234 | in += i; | ||
| 235 | inl -= i; | ||
| 236 | } | ||
| 237 | } while (foundnl && inl > 0); | ||
| 238 | /* We've written as much as we can. The rest of the input buffer, if | ||
| 239 | any, is text that doesn't and with a NL and therefore needs to be | ||
| 240 | saved for the next trip. */ | ||
| 241 | if (inl > 0) { | ||
| 242 | memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl); | ||
| 243 | ctx->obuf_len += inl; | ||
| 244 | num += inl; | ||
| 245 | } | ||
| 246 | return num; | ||
| 247 | } | ||
| 248 | |||
| 249 | static long | ||
| 250 | linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 251 | { | ||
| 252 | BIO *dbio; | ||
| 253 | BIO_LINEBUFFER_CTX *ctx; | ||
| 254 | long ret = 1; | ||
| 255 | char *p; | ||
| 256 | int r; | ||
| 257 | int obs; | ||
| 258 | |||
| 259 | ctx = (BIO_LINEBUFFER_CTX *)b->ptr; | ||
| 260 | |||
| 261 | switch (cmd) { | ||
| 262 | case BIO_CTRL_RESET: | ||
| 263 | ctx->obuf_len = 0; | ||
| 264 | if (b->next_bio == NULL) | ||
| 265 | return (0); | ||
| 266 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 267 | break; | ||
| 268 | case BIO_CTRL_INFO: | ||
| 269 | ret = (long)ctx->obuf_len; | ||
| 270 | break; | ||
| 271 | case BIO_CTRL_WPENDING: | ||
| 272 | ret = (long)ctx->obuf_len; | ||
| 273 | if (ret == 0) { | ||
| 274 | if (b->next_bio == NULL) | ||
| 275 | return (0); | ||
| 276 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 277 | } | ||
| 278 | break; | ||
| 279 | case BIO_C_SET_BUFF_SIZE: | ||
| 280 | obs = (int)num; | ||
| 281 | p = ctx->obuf; | ||
| 282 | if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) { | ||
| 283 | p = malloc(num); | ||
| 284 | if (p == NULL) | ||
| 285 | goto malloc_error; | ||
| 286 | } | ||
| 287 | if (ctx->obuf != p) { | ||
| 288 | if (ctx->obuf_len > obs) { | ||
| 289 | ctx->obuf_len = obs; | ||
| 290 | } | ||
| 291 | memcpy(p, ctx->obuf, ctx->obuf_len); | ||
| 292 | free(ctx->obuf); | ||
| 293 | ctx->obuf = p; | ||
| 294 | ctx->obuf_size = obs; | ||
| 295 | } | ||
| 296 | break; | ||
| 297 | case BIO_C_DO_STATE_MACHINE: | ||
| 298 | if (b->next_bio == NULL) | ||
| 299 | return (0); | ||
| 300 | BIO_clear_retry_flags(b); | ||
| 301 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 302 | BIO_copy_next_retry(b); | ||
| 303 | break; | ||
| 304 | |||
| 305 | case BIO_CTRL_FLUSH: | ||
| 306 | if (b->next_bio == NULL) | ||
| 307 | return (0); | ||
| 308 | if (ctx->obuf_len <= 0) { | ||
| 309 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 310 | break; | ||
| 311 | } | ||
| 312 | |||
| 313 | for (;;) { | ||
| 314 | BIO_clear_retry_flags(b); | ||
| 315 | if (ctx->obuf_len > 0) { | ||
| 316 | r = BIO_write(b->next_bio, | ||
| 317 | ctx->obuf, ctx->obuf_len); | ||
| 318 | BIO_copy_next_retry(b); | ||
| 319 | if (r <= 0) | ||
| 320 | return ((long)r); | ||
| 321 | if (r < ctx->obuf_len) | ||
| 322 | memmove(ctx->obuf, ctx->obuf + r, | ||
| 323 | ctx->obuf_len - r); | ||
| 324 | ctx->obuf_len -= r; | ||
| 325 | } else { | ||
| 326 | ctx->obuf_len = 0; | ||
| 327 | ret = 1; | ||
| 328 | break; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 332 | break; | ||
| 333 | case BIO_CTRL_DUP: | ||
| 334 | dbio = (BIO *)ptr; | ||
| 335 | if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size)) | ||
| 336 | ret = 0; | ||
| 337 | break; | ||
| 338 | default: | ||
| 339 | if (b->next_bio == NULL) | ||
| 340 | return (0); | ||
| 341 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 342 | break; | ||
| 343 | } | ||
| 344 | return (ret); | ||
| 345 | malloc_error: | ||
| 346 | BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE); | ||
| 347 | return (0); | ||
| 348 | } | ||
| 349 | |||
| 350 | static long | ||
| 351 | linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
| 352 | { | ||
| 353 | long ret = 1; | ||
| 354 | |||
| 355 | if (b->next_bio == NULL) | ||
| 356 | return (0); | ||
| 357 | switch (cmd) { | ||
| 358 | default: | ||
| 359 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | ||
| 360 | break; | ||
| 361 | } | ||
| 362 | return (ret); | ||
| 363 | } | ||
| 364 | |||
| 365 | static int | ||
| 366 | linebuffer_gets(BIO *b, char *buf, int size) | ||
| 367 | { | ||
| 368 | if (b->next_bio == NULL) | ||
| 369 | return (0); | ||
| 370 | return (BIO_gets(b->next_bio, buf, size)); | ||
| 371 | } | ||
| 372 | |||
| 373 | static int | ||
| 374 | linebuffer_puts(BIO *b, const char *str) | ||
| 375 | { | ||
| 376 | return (linebuffer_write(b, str, strlen(str))); | ||
| 377 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c deleted file mode 100644 index 24e2e7e8b9..0000000000 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ /dev/null | |||
| @@ -1,252 +0,0 @@ | |||
| 1 | /* $OpenBSD: bf_nbio.c,v 1.19 2015/02/07 13:19:15 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/bio.h> | ||
| 64 | |||
| 65 | /* BIO_put and BIO_get both add to the digest, | ||
| 66 | * BIO_gets returns the digest */ | ||
| 67 | |||
| 68 | static int nbiof_write(BIO *h, const char *buf, int num); | ||
| 69 | static int nbiof_read(BIO *h, char *buf, int size); | ||
| 70 | static int nbiof_puts(BIO *h, const char *str); | ||
| 71 | static int nbiof_gets(BIO *h, char *str, int size); | ||
| 72 | static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 73 | static int nbiof_new(BIO *h); | ||
| 74 | static int nbiof_free(BIO *data); | ||
| 75 | static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | ||
| 76 | |||
| 77 | typedef struct nbio_test_st { | ||
| 78 | /* only set if we sent a 'should retry' error */ | ||
| 79 | int lrn; | ||
| 80 | int lwn; | ||
| 81 | } NBIO_TEST; | ||
| 82 | |||
| 83 | static BIO_METHOD methods_nbiof = { | ||
| 84 | .type = BIO_TYPE_NBIO_TEST, | ||
| 85 | .name = "non-blocking IO test filter", | ||
| 86 | .bwrite = nbiof_write, | ||
| 87 | .bread = nbiof_read, | ||
| 88 | .bputs = nbiof_puts, | ||
| 89 | .bgets = nbiof_gets, | ||
| 90 | .ctrl = nbiof_ctrl, | ||
| 91 | .create = nbiof_new, | ||
| 92 | .destroy = nbiof_free, | ||
| 93 | .callback_ctrl = nbiof_callback_ctrl | ||
| 94 | }; | ||
| 95 | |||
| 96 | BIO_METHOD * | ||
| 97 | BIO_f_nbio_test(void) | ||
| 98 | { | ||
| 99 | return (&methods_nbiof); | ||
| 100 | } | ||
| 101 | |||
| 102 | static int | ||
| 103 | nbiof_new(BIO *bi) | ||
| 104 | { | ||
| 105 | NBIO_TEST *nt; | ||
| 106 | |||
| 107 | if (!(nt = malloc(sizeof(NBIO_TEST)))) | ||
| 108 | return (0); | ||
| 109 | nt->lrn = -1; | ||
| 110 | nt->lwn = -1; | ||
| 111 | bi->ptr = (char *)nt; | ||
| 112 | bi->init = 1; | ||
| 113 | bi->flags = 0; | ||
| 114 | return (1); | ||
| 115 | } | ||
| 116 | |||
| 117 | static int | ||
| 118 | nbiof_free(BIO *a) | ||
| 119 | { | ||
| 120 | if (a == NULL) | ||
| 121 | return (0); | ||
| 122 | free(a->ptr); | ||
| 123 | a->ptr = NULL; | ||
| 124 | a->init = 0; | ||
| 125 | a->flags = 0; | ||
| 126 | return (1); | ||
| 127 | } | ||
| 128 | |||
| 129 | static int | ||
| 130 | nbiof_read(BIO *b, char *out, int outl) | ||
| 131 | { | ||
| 132 | int ret = 0; | ||
| 133 | int num; | ||
| 134 | unsigned char n; | ||
| 135 | |||
| 136 | if (out == NULL) | ||
| 137 | return (0); | ||
| 138 | if (b->next_bio == NULL) | ||
| 139 | return (0); | ||
| 140 | |||
| 141 | BIO_clear_retry_flags(b); | ||
| 142 | |||
| 143 | arc4random_buf(&n, 1); | ||
| 144 | num = (n & 0x07); | ||
| 145 | |||
| 146 | if (outl > num) | ||
| 147 | outl = num; | ||
| 148 | |||
| 149 | if (num == 0) { | ||
| 150 | ret = -1; | ||
| 151 | BIO_set_retry_read(b); | ||
| 152 | } else { | ||
| 153 | ret = BIO_read(b->next_bio, out, outl); | ||
| 154 | if (ret < 0) | ||
| 155 | BIO_copy_next_retry(b); | ||
| 156 | } | ||
| 157 | return (ret); | ||
| 158 | } | ||
| 159 | |||
| 160 | static int | ||
| 161 | nbiof_write(BIO *b, const char *in, int inl) | ||
| 162 | { | ||
| 163 | NBIO_TEST *nt; | ||
| 164 | int ret = 0; | ||
| 165 | int num; | ||
| 166 | unsigned char n; | ||
| 167 | |||
| 168 | if ((in == NULL) || (inl <= 0)) | ||
| 169 | return (0); | ||
| 170 | if (b->next_bio == NULL) | ||
| 171 | return (0); | ||
| 172 | nt = (NBIO_TEST *)b->ptr; | ||
| 173 | |||
| 174 | BIO_clear_retry_flags(b); | ||
| 175 | |||
| 176 | if (nt->lwn > 0) { | ||
| 177 | num = nt->lwn; | ||
| 178 | nt->lwn = 0; | ||
| 179 | } else { | ||
| 180 | arc4random_buf(&n, 1); | ||
| 181 | num = (n&7); | ||
| 182 | } | ||
| 183 | |||
| 184 | if (inl > num) | ||
| 185 | inl = num; | ||
| 186 | |||
| 187 | if (num == 0) { | ||
| 188 | ret = -1; | ||
| 189 | BIO_set_retry_write(b); | ||
| 190 | } else { | ||
| 191 | ret = BIO_write(b->next_bio, in, inl); | ||
| 192 | if (ret < 0) { | ||
| 193 | BIO_copy_next_retry(b); | ||
| 194 | nt->lwn = inl; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | return (ret); | ||
| 198 | } | ||
| 199 | |||
| 200 | static long | ||
| 201 | nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 202 | { | ||
| 203 | long ret; | ||
| 204 | |||
| 205 | if (b->next_bio == NULL) | ||
| 206 | return (0); | ||
| 207 | switch (cmd) { | ||
| 208 | case BIO_C_DO_STATE_MACHINE: | ||
| 209 | BIO_clear_retry_flags(b); | ||
| 210 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 211 | BIO_copy_next_retry(b); | ||
| 212 | break; | ||
| 213 | case BIO_CTRL_DUP: | ||
| 214 | ret = 0L; | ||
| 215 | break; | ||
| 216 | default: | ||
| 217 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 218 | break; | ||
| 219 | } | ||
| 220 | return (ret); | ||
| 221 | } | ||
| 222 | |||
| 223 | static long | ||
| 224 | nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
| 225 | { | ||
| 226 | long ret = 1; | ||
| 227 | |||
| 228 | if (b->next_bio == NULL) | ||
| 229 | return (0); | ||
| 230 | switch (cmd) { | ||
| 231 | default: | ||
| 232 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | ||
| 233 | break; | ||
| 234 | } | ||
| 235 | return (ret); | ||
| 236 | } | ||
| 237 | |||
| 238 | static int | ||
| 239 | nbiof_gets(BIO *bp, char *buf, int size) | ||
| 240 | { | ||
| 241 | if (bp->next_bio == NULL) | ||
| 242 | return (0); | ||
| 243 | return (BIO_gets(bp->next_bio, buf, size)); | ||
| 244 | } | ||
| 245 | |||
| 246 | static int | ||
| 247 | nbiof_puts(BIO *bp, const char *str) | ||
| 248 | { | ||
| 249 | if (bp->next_bio == NULL) | ||
| 250 | return (0); | ||
| 251 | return (BIO_puts(bp->next_bio, str)); | ||
| 252 | } | ||
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c deleted file mode 100644 index 09d54b6b21..0000000000 --- a/src/lib/libcrypto/bio/bf_null.c +++ /dev/null | |||
| @@ -1,196 +0,0 @@ | |||
| 1 | /* $OpenBSD: bf_null.c,v 1.11 2014/07/11 08:44:47 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | |||
| 62 | #include <openssl/bio.h> | ||
| 63 | |||
| 64 | /* BIO_put and BIO_get both add to the digest, | ||
| 65 | * BIO_gets returns the digest */ | ||
| 66 | |||
| 67 | static int nullf_write(BIO *h, const char *buf, int num); | ||
| 68 | static int nullf_read(BIO *h, char *buf, int size); | ||
| 69 | static int nullf_puts(BIO *h, const char *str); | ||
| 70 | static int nullf_gets(BIO *h, char *str, int size); | ||
| 71 | static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 72 | static int nullf_new(BIO *h); | ||
| 73 | static int nullf_free(BIO *data); | ||
| 74 | static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | ||
| 75 | |||
| 76 | static BIO_METHOD methods_nullf = { | ||
| 77 | .type = BIO_TYPE_NULL_FILTER, | ||
| 78 | .name = "NULL filter", | ||
| 79 | .bwrite = nullf_write, | ||
| 80 | .bread = nullf_read, | ||
| 81 | .bputs = nullf_puts, | ||
| 82 | .bgets = nullf_gets, | ||
| 83 | .ctrl = nullf_ctrl, | ||
| 84 | .create = nullf_new, | ||
| 85 | .destroy = nullf_free, | ||
| 86 | .callback_ctrl = nullf_callback_ctrl | ||
| 87 | }; | ||
| 88 | |||
| 89 | BIO_METHOD * | ||
| 90 | BIO_f_null(void) | ||
| 91 | { | ||
| 92 | return (&methods_nullf); | ||
| 93 | } | ||
| 94 | |||
| 95 | static int | ||
| 96 | nullf_new(BIO *bi) | ||
| 97 | { | ||
| 98 | bi->init = 1; | ||
| 99 | bi->ptr = NULL; | ||
| 100 | bi->flags = 0; | ||
| 101 | return (1); | ||
| 102 | } | ||
| 103 | |||
| 104 | static int | ||
| 105 | nullf_free(BIO *a) | ||
| 106 | { | ||
| 107 | if (a == NULL) | ||
| 108 | return (0); | ||
| 109 | /* a->ptr=NULL; | ||
| 110 | a->init=0; | ||
| 111 | a->flags=0;*/ | ||
| 112 | return (1); | ||
| 113 | } | ||
| 114 | |||
| 115 | static int | ||
| 116 | nullf_read(BIO *b, char *out, int outl) | ||
| 117 | { | ||
| 118 | int ret = 0; | ||
| 119 | |||
| 120 | if (out == NULL) | ||
| 121 | return (0); | ||
| 122 | if (b->next_bio == NULL) | ||
| 123 | return (0); | ||
| 124 | ret = BIO_read(b->next_bio, out, outl); | ||
| 125 | BIO_clear_retry_flags(b); | ||
| 126 | BIO_copy_next_retry(b); | ||
| 127 | return (ret); | ||
| 128 | } | ||
| 129 | |||
| 130 | static int | ||
| 131 | nullf_write(BIO *b, const char *in, int inl) | ||
| 132 | { | ||
| 133 | int ret = 0; | ||
| 134 | |||
| 135 | if ((in == NULL) || (inl <= 0)) | ||
| 136 | return (0); | ||
| 137 | if (b->next_bio == NULL) | ||
| 138 | return (0); | ||
| 139 | ret = BIO_write(b->next_bio, in, inl); | ||
| 140 | BIO_clear_retry_flags(b); | ||
| 141 | BIO_copy_next_retry(b); | ||
| 142 | return (ret); | ||
| 143 | } | ||
| 144 | |||
| 145 | static long | ||
| 146 | nullf_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 147 | { | ||
| 148 | long ret; | ||
| 149 | |||
| 150 | if (b->next_bio == NULL) | ||
| 151 | return (0); | ||
| 152 | switch (cmd) { | ||
| 153 | case BIO_C_DO_STATE_MACHINE: | ||
| 154 | BIO_clear_retry_flags(b); | ||
| 155 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 156 | BIO_copy_next_retry(b); | ||
| 157 | break; | ||
| 158 | case BIO_CTRL_DUP: | ||
| 159 | ret = 0L; | ||
| 160 | break; | ||
| 161 | default: | ||
| 162 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | ||
| 163 | } | ||
| 164 | return (ret); | ||
| 165 | } | ||
| 166 | |||
| 167 | static long | ||
| 168 | nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
| 169 | { | ||
| 170 | long ret = 1; | ||
| 171 | |||
| 172 | if (b->next_bio == NULL) | ||
| 173 | return (0); | ||
| 174 | switch (cmd) { | ||
| 175 | default: | ||
| 176 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | ||
| 177 | break; | ||
| 178 | } | ||
| 179 | return (ret); | ||
| 180 | } | ||
| 181 | |||
| 182 | static int | ||
| 183 | nullf_gets(BIO *bp, char *buf, int size) | ||
| 184 | { | ||
| 185 | if (bp->next_bio == NULL) | ||
| 186 | return (0); | ||
| 187 | return (BIO_gets(bp->next_bio, buf, size)); | ||
| 188 | } | ||
| 189 | |||
| 190 | static int | ||
| 191 | nullf_puts(BIO *bp, const char *str) | ||
| 192 | { | ||
| 193 | if (bp->next_bio == NULL) | ||
| 194 | return (0); | ||
| 195 | return (BIO_puts(bp->next_bio, str)); | ||
| 196 | } | ||
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h deleted file mode 100644 index 5243367073..0000000000 --- a/src/lib/libcrypto/bio/bio.h +++ /dev/null | |||
| @@ -1,774 +0,0 @@ | |||
| 1 | /* $OpenBSD: bio.h,v 1.29 2015/06/20 01:17:27 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_BIO_H | ||
| 60 | #define HEADER_BIO_H | ||
| 61 | #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__OpenBSD__) | ||
| 62 | #define __bounded__(x, y, z) | ||
| 63 | #endif | ||
| 64 | #include <openssl/opensslconf.h> | ||
| 65 | |||
| 66 | # include <stdio.h> | ||
| 67 | #include <stdarg.h> | ||
| 68 | |||
| 69 | #include <openssl/crypto.h> | ||
| 70 | |||
| 71 | |||
| 72 | #ifdef __cplusplus | ||
| 73 | extern "C" { | ||
| 74 | #endif | ||
| 75 | |||
| 76 | /* These are the 'types' of BIOs */ | ||
| 77 | #define BIO_TYPE_NONE 0 | ||
| 78 | #define BIO_TYPE_MEM (1|0x0400) | ||
| 79 | #define BIO_TYPE_FILE (2|0x0400) | ||
| 80 | |||
| 81 | #define BIO_TYPE_FD (4|0x0400|0x0100) | ||
| 82 | #define BIO_TYPE_SOCKET (5|0x0400|0x0100) | ||
| 83 | #define BIO_TYPE_NULL (6|0x0400) | ||
| 84 | #define BIO_TYPE_SSL (7|0x0200) | ||
| 85 | #define BIO_TYPE_MD (8|0x0200) /* passive filter */ | ||
| 86 | #define BIO_TYPE_BUFFER (9|0x0200) /* filter */ | ||
| 87 | #define BIO_TYPE_CIPHER (10|0x0200) /* filter */ | ||
| 88 | #define BIO_TYPE_BASE64 (11|0x0200) /* filter */ | ||
| 89 | #define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */ | ||
| 90 | #define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */ | ||
| 91 | #define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */ | ||
| 92 | #define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ | ||
| 93 | #define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ | ||
| 94 | #define BIO_TYPE_NULL_FILTER (17|0x0200) | ||
| 95 | #define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ | ||
| 96 | #define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ | ||
| 97 | #define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ | ||
| 98 | #define BIO_TYPE_DGRAM (21|0x0400|0x0100) | ||
| 99 | #define BIO_TYPE_ASN1 (22|0x0200) /* filter */ | ||
| 100 | #define BIO_TYPE_COMP (23|0x0200) /* filter */ | ||
| 101 | |||
| 102 | #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ | ||
| 103 | #define BIO_TYPE_FILTER 0x0200 | ||
| 104 | #define BIO_TYPE_SOURCE_SINK 0x0400 | ||
| 105 | |||
| 106 | /* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. | ||
| 107 | * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ | ||
| 108 | #define BIO_NOCLOSE 0x00 | ||
| 109 | #define BIO_CLOSE 0x01 | ||
| 110 | |||
| 111 | /* These are used in the following macros and are passed to | ||
| 112 | * BIO_ctrl() */ | ||
| 113 | #define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ | ||
| 114 | #define BIO_CTRL_EOF 2 /* opt - are we at the eof */ | ||
| 115 | #define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ | ||
| 116 | #define BIO_CTRL_SET 4 /* man - set the 'IO' type */ | ||
| 117 | #define BIO_CTRL_GET 5 /* man - get the 'IO' type */ | ||
| 118 | #define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ | ||
| 119 | #define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ | ||
| 120 | #define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ | ||
| 121 | #define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ | ||
| 122 | #define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ | ||
| 123 | #define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ | ||
| 124 | #define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ | ||
| 125 | #define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ | ||
| 126 | /* callback is int cb(BIO *bio,state,ret); */ | ||
| 127 | #define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ | ||
| 128 | #define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ | ||
| 129 | |||
| 130 | #define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ | ||
| 131 | |||
| 132 | /* dgram BIO stuff */ | ||
| 133 | #define BIO_CTRL_DGRAM_CONNECT 31 /* BIO dgram special */ | ||
| 134 | #define BIO_CTRL_DGRAM_SET_CONNECTED 32 /* allow for an externally | ||
| 135 | * connected socket to be | ||
| 136 | * passed in */ | ||
| 137 | #define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33 /* setsockopt, essentially */ | ||
| 138 | #define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34 /* getsockopt, essentially */ | ||
| 139 | #define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35 /* setsockopt, essentially */ | ||
| 140 | #define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36 /* getsockopt, essentially */ | ||
| 141 | |||
| 142 | #define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */ | ||
| 143 | #define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */ | ||
| 144 | |||
| 145 | /* #ifdef IP_MTU_DISCOVER */ | ||
| 146 | #define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */ | ||
| 147 | /* #endif */ | ||
| 148 | |||
| 149 | #define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */ | ||
| 150 | #define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 | ||
| 151 | #define BIO_CTRL_DGRAM_GET_MTU 41 /* get cached value for MTU */ | ||
| 152 | #define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for | ||
| 153 | * MTU. want to use this | ||
| 154 | * if asking the kernel | ||
| 155 | * fails */ | ||
| 156 | |||
| 157 | #define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU | ||
| 158 | * was exceed in the | ||
| 159 | * previous write | ||
| 160 | * operation */ | ||
| 161 | |||
| 162 | #define BIO_CTRL_DGRAM_GET_PEER 46 | ||
| 163 | #define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ | ||
| 164 | |||
| 165 | #define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45 /* Next DTLS handshake timeout to | ||
| 166 | * adjust socket timeouts */ | ||
| 167 | |||
| 168 | |||
| 169 | /* modifiers */ | ||
| 170 | #define BIO_FP_READ 0x02 | ||
| 171 | #define BIO_FP_WRITE 0x04 | ||
| 172 | #define BIO_FP_APPEND 0x08 | ||
| 173 | #define BIO_FP_TEXT 0x10 | ||
| 174 | |||
| 175 | #define BIO_FLAGS_READ 0x01 | ||
| 176 | #define BIO_FLAGS_WRITE 0x02 | ||
| 177 | #define BIO_FLAGS_IO_SPECIAL 0x04 | ||
| 178 | #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) | ||
| 179 | #define BIO_FLAGS_SHOULD_RETRY 0x08 | ||
| 180 | |||
| 181 | /* Used in BIO_gethostbyname() */ | ||
| 182 | #define BIO_GHBN_CTRL_HITS 1 | ||
| 183 | #define BIO_GHBN_CTRL_MISSES 2 | ||
| 184 | #define BIO_GHBN_CTRL_CACHE_SIZE 3 | ||
| 185 | #define BIO_GHBN_CTRL_GET_ENTRY 4 | ||
| 186 | #define BIO_GHBN_CTRL_FLUSH 5 | ||
| 187 | |||
| 188 | /* Mostly used in the SSL BIO */ | ||
| 189 | /* Not used anymore | ||
| 190 | * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10 | ||
| 191 | * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20 | ||
| 192 | * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40 | ||
| 193 | */ | ||
| 194 | |||
| 195 | #define BIO_FLAGS_BASE64_NO_NL 0x100 | ||
| 196 | |||
| 197 | /* This is used with memory BIOs: it means we shouldn't free up or change the | ||
| 198 | * data in any way. | ||
| 199 | */ | ||
| 200 | #define BIO_FLAGS_MEM_RDONLY 0x200 | ||
| 201 | |||
| 202 | typedef struct bio_st BIO; | ||
| 203 | |||
| 204 | void BIO_set_flags(BIO *b, int flags); | ||
| 205 | int BIO_test_flags(const BIO *b, int flags); | ||
| 206 | void BIO_clear_flags(BIO *b, int flags); | ||
| 207 | |||
| 208 | #define BIO_get_flags(b) BIO_test_flags(b, ~(0x0)) | ||
| 209 | #define BIO_set_retry_special(b) \ | ||
| 210 | BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) | ||
| 211 | #define BIO_set_retry_read(b) \ | ||
| 212 | BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) | ||
| 213 | #define BIO_set_retry_write(b) \ | ||
| 214 | BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) | ||
| 215 | |||
| 216 | /* These are normally used internally in BIOs */ | ||
| 217 | #define BIO_clear_retry_flags(b) \ | ||
| 218 | BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | ||
| 219 | #define BIO_get_retry_flags(b) \ | ||
| 220 | BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | ||
| 221 | |||
| 222 | /* These should be used by the application to tell why we should retry */ | ||
| 223 | #define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) | ||
| 224 | #define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) | ||
| 225 | #define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) | ||
| 226 | #define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) | ||
| 227 | #define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) | ||
| 228 | |||
| 229 | /* The next three are used in conjunction with the | ||
| 230 | * BIO_should_io_special() condition. After this returns true, | ||
| 231 | * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO | ||
| 232 | * stack and return the 'reason' for the special and the offending BIO. | ||
| 233 | * Given a BIO, BIO_get_retry_reason(bio) will return the code. */ | ||
| 234 | /* Returned from the SSL bio when the certificate retrieval code had an error */ | ||
| 235 | #define BIO_RR_SSL_X509_LOOKUP 0x01 | ||
| 236 | /* Returned from the connect BIO when a connect would have blocked */ | ||
| 237 | #define BIO_RR_CONNECT 0x02 | ||
| 238 | /* Returned from the accept BIO when an accept would have blocked */ | ||
| 239 | #define BIO_RR_ACCEPT 0x03 | ||
| 240 | |||
| 241 | /* These are passed by the BIO callback */ | ||
| 242 | #define BIO_CB_FREE 0x01 | ||
| 243 | #define BIO_CB_READ 0x02 | ||
| 244 | #define BIO_CB_WRITE 0x03 | ||
| 245 | #define BIO_CB_PUTS 0x04 | ||
| 246 | #define BIO_CB_GETS 0x05 | ||
| 247 | #define BIO_CB_CTRL 0x06 | ||
| 248 | |||
| 249 | /* The callback is called before and after the underling operation, | ||
| 250 | * The BIO_CB_RETURN flag indicates if it is after the call */ | ||
| 251 | #define BIO_CB_RETURN 0x80 | ||
| 252 | #define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) | ||
| 253 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) | ||
| 254 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) | ||
| 255 | |||
| 256 | long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, | ||
| 257 | int, long, long); | ||
| 258 | void BIO_set_callback(BIO *b, | ||
| 259 | long (*callback)(struct bio_st *, int, const char *, int, long, long)); | ||
| 260 | char *BIO_get_callback_arg(const BIO *b); | ||
| 261 | void BIO_set_callback_arg(BIO *b, char *arg); | ||
| 262 | |||
| 263 | const char * BIO_method_name(const BIO *b); | ||
| 264 | int BIO_method_type(const BIO *b); | ||
| 265 | |||
| 266 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); | ||
| 267 | |||
| 268 | typedef struct bio_method_st { | ||
| 269 | int type; | ||
| 270 | const char *name; | ||
| 271 | int (*bwrite)(BIO *, const char *, int); | ||
| 272 | int (*bread)(BIO *, char *, int); | ||
| 273 | int (*bputs)(BIO *, const char *); | ||
| 274 | int (*bgets)(BIO *, char *, int); | ||
| 275 | long (*ctrl)(BIO *, int, long, void *); | ||
| 276 | int (*create)(BIO *); | ||
| 277 | int (*destroy)(BIO *); | ||
| 278 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); | ||
| 279 | } BIO_METHOD; | ||
| 280 | |||
| 281 | struct bio_st { | ||
| 282 | BIO_METHOD *method; | ||
| 283 | /* bio, mode, argp, argi, argl, ret */ | ||
| 284 | long (*callback)(struct bio_st *, int, const char *, int, long, long); | ||
| 285 | char *cb_arg; /* first argument for the callback */ | ||
| 286 | |||
| 287 | int init; | ||
| 288 | int shutdown; | ||
| 289 | int flags; /* extra storage */ | ||
| 290 | int retry_reason; | ||
| 291 | int num; | ||
| 292 | void *ptr; | ||
| 293 | struct bio_st *next_bio; /* used by filter BIOs */ | ||
| 294 | struct bio_st *prev_bio; /* used by filter BIOs */ | ||
| 295 | int references; | ||
| 296 | unsigned long num_read; | ||
| 297 | unsigned long num_write; | ||
| 298 | |||
| 299 | CRYPTO_EX_DATA ex_data; | ||
| 300 | }; | ||
| 301 | |||
| 302 | DECLARE_STACK_OF(BIO) | ||
| 303 | |||
| 304 | typedef struct bio_f_buffer_ctx_struct { | ||
| 305 | /* Buffers are setup like this: | ||
| 306 | * | ||
| 307 | * <---------------------- size -----------------------> | ||
| 308 | * +---------------------------------------------------+ | ||
| 309 | * | consumed | remaining | free space | | ||
| 310 | * +---------------------------------------------------+ | ||
| 311 | * <-- off --><------- len -------> | ||
| 312 | */ | ||
| 313 | |||
| 314 | /* BIO *bio; */ /* this is now in the BIO struct */ | ||
| 315 | int ibuf_size; /* how big is the input buffer */ | ||
| 316 | int obuf_size; /* how big is the output buffer */ | ||
| 317 | |||
| 318 | char *ibuf; /* the char array */ | ||
| 319 | int ibuf_len; /* how many bytes are in it */ | ||
| 320 | int ibuf_off; /* write/read offset */ | ||
| 321 | |||
| 322 | char *obuf; /* the char array */ | ||
| 323 | int obuf_len; /* how many bytes are in it */ | ||
| 324 | int obuf_off; /* write/read offset */ | ||
| 325 | } BIO_F_BUFFER_CTX; | ||
| 326 | |||
| 327 | /* Prefix and suffix callback in ASN1 BIO */ | ||
| 328 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); | ||
| 329 | |||
| 330 | |||
| 331 | /* connect BIO stuff */ | ||
| 332 | #define BIO_CONN_S_BEFORE 1 | ||
| 333 | #define BIO_CONN_S_GET_IP 2 | ||
| 334 | #define BIO_CONN_S_GET_PORT 3 | ||
| 335 | #define BIO_CONN_S_CREATE_SOCKET 4 | ||
| 336 | #define BIO_CONN_S_CONNECT 5 | ||
| 337 | #define BIO_CONN_S_OK 6 | ||
| 338 | #define BIO_CONN_S_BLOCKED_CONNECT 7 | ||
| 339 | #define BIO_CONN_S_NBIO 8 | ||
| 340 | /*#define BIO_CONN_get_param_hostname BIO_ctrl */ | ||
| 341 | |||
| 342 | #define BIO_C_SET_CONNECT 100 | ||
| 343 | #define BIO_C_DO_STATE_MACHINE 101 | ||
| 344 | #define BIO_C_SET_NBIO 102 | ||
| 345 | #define BIO_C_SET_PROXY_PARAM 103 | ||
| 346 | #define BIO_C_SET_FD 104 | ||
| 347 | #define BIO_C_GET_FD 105 | ||
| 348 | #define BIO_C_SET_FILE_PTR 106 | ||
| 349 | #define BIO_C_GET_FILE_PTR 107 | ||
| 350 | #define BIO_C_SET_FILENAME 108 | ||
| 351 | #define BIO_C_SET_SSL 109 | ||
| 352 | #define BIO_C_GET_SSL 110 | ||
| 353 | #define BIO_C_SET_MD 111 | ||
| 354 | #define BIO_C_GET_MD 112 | ||
| 355 | #define BIO_C_GET_CIPHER_STATUS 113 | ||
| 356 | #define BIO_C_SET_BUF_MEM 114 | ||
| 357 | #define BIO_C_GET_BUF_MEM_PTR 115 | ||
| 358 | #define BIO_C_GET_BUFF_NUM_LINES 116 | ||
| 359 | #define BIO_C_SET_BUFF_SIZE 117 | ||
| 360 | #define BIO_C_SET_ACCEPT 118 | ||
| 361 | #define BIO_C_SSL_MODE 119 | ||
| 362 | #define BIO_C_GET_MD_CTX 120 | ||
| 363 | #define BIO_C_GET_PROXY_PARAM 121 | ||
| 364 | #define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ | ||
| 365 | #define BIO_C_GET_CONNECT 123 | ||
| 366 | #define BIO_C_GET_ACCEPT 124 | ||
| 367 | #define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 | ||
| 368 | #define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 | ||
| 369 | #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 | ||
| 370 | #define BIO_C_FILE_SEEK 128 | ||
| 371 | #define BIO_C_GET_CIPHER_CTX 129 | ||
| 372 | #define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ | ||
| 373 | #define BIO_C_SET_BIND_MODE 131 | ||
| 374 | #define BIO_C_GET_BIND_MODE 132 | ||
| 375 | #define BIO_C_FILE_TELL 133 | ||
| 376 | #define BIO_C_GET_SOCKS 134 | ||
| 377 | #define BIO_C_SET_SOCKS 135 | ||
| 378 | |||
| 379 | #define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ | ||
| 380 | #define BIO_C_GET_WRITE_BUF_SIZE 137 | ||
| 381 | #define BIO_C_MAKE_BIO_PAIR 138 | ||
| 382 | #define BIO_C_DESTROY_BIO_PAIR 139 | ||
| 383 | #define BIO_C_GET_WRITE_GUARANTEE 140 | ||
| 384 | #define BIO_C_GET_READ_REQUEST 141 | ||
| 385 | #define BIO_C_SHUTDOWN_WR 142 | ||
| 386 | #define BIO_C_NREAD0 143 | ||
| 387 | #define BIO_C_NREAD 144 | ||
| 388 | #define BIO_C_NWRITE0 145 | ||
| 389 | #define BIO_C_NWRITE 146 | ||
| 390 | #define BIO_C_RESET_READ_REQUEST 147 | ||
| 391 | #define BIO_C_SET_MD_CTX 148 | ||
| 392 | |||
| 393 | #define BIO_C_SET_PREFIX 149 | ||
| 394 | #define BIO_C_GET_PREFIX 150 | ||
| 395 | #define BIO_C_SET_SUFFIX 151 | ||
| 396 | #define BIO_C_GET_SUFFIX 152 | ||
| 397 | |||
| 398 | #define BIO_C_SET_EX_ARG 153 | ||
| 399 | #define BIO_C_GET_EX_ARG 154 | ||
| 400 | |||
| 401 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) | ||
| 402 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) | ||
| 403 | |||
| 404 | /* BIO_s_connect() and BIO_s_socks4a_connect() */ | ||
| 405 | #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) | ||
| 406 | #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) | ||
| 407 | #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) | ||
| 408 | #define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port) | ||
| 409 | #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) | ||
| 410 | #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) | ||
| 411 | #define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2) | ||
| 412 | #define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3,0) | ||
| 413 | |||
| 414 | |||
| 415 | #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) | ||
| 416 | |||
| 417 | /* BIO_s_accept_socket() */ | ||
| 418 | #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) | ||
| 419 | #define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) | ||
| 420 | /* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ | ||
| 421 | #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?(void *)"a":NULL) | ||
| 422 | #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) | ||
| 423 | |||
| 424 | #define BIO_BIND_NORMAL 0 | ||
| 425 | #define BIO_BIND_REUSEADDR_IF_UNUSED 1 | ||
| 426 | #define BIO_BIND_REUSEADDR 2 | ||
| 427 | #define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) | ||
| 428 | #define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) | ||
| 429 | |||
| 430 | #define BIO_do_connect(b) BIO_do_handshake(b) | ||
| 431 | #define BIO_do_accept(b) BIO_do_handshake(b) | ||
| 432 | #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) | ||
| 433 | |||
| 434 | /* BIO_s_proxy_client() */ | ||
| 435 | #define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) | ||
| 436 | #define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) | ||
| 437 | /* BIO_set_nbio(b,n) */ | ||
| 438 | #define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) | ||
| 439 | /* BIO *BIO_get_filter_bio(BIO *bio); */ | ||
| 440 | #define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)())) | ||
| 441 | #define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) | ||
| 442 | #define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) | ||
| 443 | |||
| 444 | #define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) | ||
| 445 | #define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) | ||
| 446 | #define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) | ||
| 447 | #define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) | ||
| 448 | |||
| 449 | #define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) | ||
| 450 | #define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) | ||
| 451 | |||
| 452 | #define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) | ||
| 453 | #define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) | ||
| 454 | |||
| 455 | #define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) | ||
| 456 | #define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) | ||
| 457 | |||
| 458 | /* name is cast to lose const, but might be better to route through a function | ||
| 459 | so we can do it safely */ | ||
| 460 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 461 | BIO_CLOSE|BIO_FP_READ,(char *)name) | ||
| 462 | #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 463 | BIO_CLOSE|BIO_FP_WRITE,name) | ||
| 464 | #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 465 | BIO_CLOSE|BIO_FP_APPEND,name) | ||
| 466 | #define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 467 | BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) | ||
| 468 | |||
| 469 | /* WARNING WARNING, this ups the reference count on the read bio of the | ||
| 470 | * SSL structure. This is because the ssl read BIO is now pointed to by | ||
| 471 | * the next_bio field in the bio. So when you free the BIO, make sure | ||
| 472 | * you are doing a BIO_free_all() to catch the underlying BIO. */ | ||
| 473 | #define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) | ||
| 474 | #define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) | ||
| 475 | #define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) | ||
| 476 | #define BIO_set_ssl_renegotiate_bytes(b,num) \ | ||
| 477 | BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL); | ||
| 478 | #define BIO_get_num_renegotiates(b) \ | ||
| 479 | BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL); | ||
| 480 | #define BIO_set_ssl_renegotiate_timeout(b,seconds) \ | ||
| 481 | BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL); | ||
| 482 | |||
| 483 | /* defined in evp.h */ | ||
| 484 | /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ | ||
| 485 | |||
| 486 | #define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) | ||
| 487 | #define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) | ||
| 488 | #define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) | ||
| 489 | #define BIO_set_mem_eof_return(b,v) \ | ||
| 490 | BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) | ||
| 491 | |||
| 492 | /* For the BIO_f_buffer() type */ | ||
| 493 | #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) | ||
| 494 | #define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) | ||
| 495 | #define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) | ||
| 496 | #define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) | ||
| 497 | #define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) | ||
| 498 | |||
| 499 | /* Don't use the next one unless you know what you are doing :-) */ | ||
| 500 | #define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) | ||
| 501 | |||
| 502 | #define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) | ||
| 503 | #define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) | ||
| 504 | #define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) | ||
| 505 | #define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) | ||
| 506 | #define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) | ||
| 507 | #define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) | ||
| 508 | /* ...pending macros have inappropriate return type */ | ||
| 509 | size_t BIO_ctrl_pending(BIO *b); | ||
| 510 | size_t BIO_ctrl_wpending(BIO *b); | ||
| 511 | #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) | ||
| 512 | #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \ | ||
| 513 | cbp) | ||
| 514 | #define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb) | ||
| 515 | |||
| 516 | /* For the BIO_f_buffer() type */ | ||
| 517 | #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) | ||
| 518 | |||
| 519 | /* For BIO_s_bio() */ | ||
| 520 | #define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) | ||
| 521 | #define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) | ||
| 522 | #define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) | ||
| 523 | #define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) | ||
| 524 | #define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) | ||
| 525 | /* macros with inappropriate type -- but ...pending macros use int too: */ | ||
| 526 | #define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) | ||
| 527 | #define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) | ||
| 528 | size_t BIO_ctrl_get_write_guarantee(BIO *b); | ||
| 529 | size_t BIO_ctrl_get_read_request(BIO *b); | ||
| 530 | int BIO_ctrl_reset_read_request(BIO *b); | ||
| 531 | |||
| 532 | /* ctrl macros for dgram */ | ||
| 533 | #define BIO_ctrl_dgram_connect(b,peer) \ | ||
| 534 | (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer) | ||
| 535 | #define BIO_ctrl_set_connected(b, state, peer) \ | ||
| 536 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, state, (char *)peer) | ||
| 537 | #define BIO_dgram_recv_timedout(b) \ | ||
| 538 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) | ||
| 539 | #define BIO_dgram_send_timedout(b) \ | ||
| 540 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) | ||
| 541 | #define BIO_dgram_get_peer(b,peer) \ | ||
| 542 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer) | ||
| 543 | #define BIO_dgram_set_peer(b,peer) \ | ||
| 544 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer) | ||
| 545 | |||
| 546 | /* These two aren't currently implemented */ | ||
| 547 | /* int BIO_get_ex_num(BIO *bio); */ | ||
| 548 | /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ | ||
| 549 | int BIO_set_ex_data(BIO *bio, int idx, void *data); | ||
| 550 | void *BIO_get_ex_data(BIO *bio, int idx); | ||
| 551 | int | ||
| 552 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 553 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 554 | unsigned long BIO_number_read(BIO *bio); | ||
| 555 | unsigned long BIO_number_written(BIO *bio); | ||
| 556 | |||
| 557 | /* For BIO_f_asn1() */ | ||
| 558 | int | ||
| 559 | BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, | ||
| 560 | asn1_ps_func *prefix_free); | ||
| 561 | int | ||
| 562 | BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, | ||
| 563 | asn1_ps_func **pprefix_free); | ||
| 564 | int | ||
| 565 | BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, | ||
| 566 | asn1_ps_func *suffix_free); | ||
| 567 | int | ||
| 568 | BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | ||
| 569 | asn1_ps_func **psuffix_free); | ||
| 570 | |||
| 571 | BIO_METHOD *BIO_s_file(void ); | ||
| 572 | BIO *BIO_new_file(const char *filename, const char *mode); | ||
| 573 | BIO *BIO_new_fp(FILE *stream, int close_flag); | ||
| 574 | # define BIO_s_file_internal BIO_s_file | ||
| 575 | BIO * BIO_new(BIO_METHOD *type); | ||
| 576 | int BIO_set(BIO *a, BIO_METHOD *type); | ||
| 577 | int BIO_free(BIO *a); | ||
| 578 | void BIO_vfree(BIO *a); | ||
| 579 | int BIO_read(BIO *b, void *data, int len) | ||
| 580 | __attribute__((__bounded__(__buffer__,2,3))); | ||
| 581 | int BIO_gets(BIO *bp, char *buf, int size) | ||
| 582 | __attribute__((__bounded__ (__string__,2,3))); | ||
| 583 | int BIO_write(BIO *b, const void *data, int len) | ||
| 584 | __attribute__((__bounded__(__buffer__,2,3))); | ||
| 585 | int BIO_puts(BIO *bp, const char *buf); | ||
| 586 | int BIO_indent(BIO *b, int indent, int max); | ||
| 587 | long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); | ||
| 588 | long BIO_callback_ctrl(BIO *b, int cmd, | ||
| 589 | void (*fp)(struct bio_st *, int, const char *, int, long, long)); | ||
| 590 | char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg); | ||
| 591 | long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); | ||
| 592 | BIO * BIO_push(BIO *b, BIO *append); | ||
| 593 | BIO * BIO_pop(BIO *b); | ||
| 594 | void BIO_free_all(BIO *a); | ||
| 595 | BIO * BIO_find_type(BIO *b, int bio_type); | ||
| 596 | BIO * BIO_next(BIO *b); | ||
| 597 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); | ||
| 598 | int BIO_get_retry_reason(BIO *bio); | ||
| 599 | BIO * BIO_dup_chain(BIO *in); | ||
| 600 | |||
| 601 | int BIO_nread0(BIO *bio, char **buf); | ||
| 602 | int BIO_nread(BIO *bio, char **buf, int num); | ||
| 603 | int BIO_nwrite0(BIO *bio, char **buf); | ||
| 604 | int BIO_nwrite(BIO *bio, char **buf, int num); | ||
| 605 | |||
| 606 | long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, | ||
| 607 | long argl, long ret); | ||
| 608 | |||
| 609 | BIO_METHOD *BIO_s_mem(void); | ||
| 610 | BIO *BIO_new_mem_buf(void *buf, int len); | ||
| 611 | BIO_METHOD *BIO_s_socket(void); | ||
| 612 | BIO_METHOD *BIO_s_connect(void); | ||
| 613 | BIO_METHOD *BIO_s_accept(void); | ||
| 614 | BIO_METHOD *BIO_s_fd(void); | ||
| 615 | BIO_METHOD *BIO_s_log(void); | ||
| 616 | BIO_METHOD *BIO_s_bio(void); | ||
| 617 | BIO_METHOD *BIO_s_null(void); | ||
| 618 | BIO_METHOD *BIO_f_null(void); | ||
| 619 | BIO_METHOD *BIO_f_buffer(void); | ||
| 620 | BIO_METHOD *BIO_f_nbio_test(void); | ||
| 621 | #ifndef OPENSSL_NO_DGRAM | ||
| 622 | BIO_METHOD *BIO_s_datagram(void); | ||
| 623 | #endif | ||
| 624 | |||
| 625 | /* BIO_METHOD *BIO_f_ber(void); */ | ||
| 626 | |||
| 627 | int BIO_sock_should_retry(int i); | ||
| 628 | int BIO_sock_non_fatal_error(int _error); | ||
| 629 | int BIO_dgram_non_fatal_error(int _error); | ||
| 630 | |||
| 631 | int BIO_fd_should_retry(int i); | ||
| 632 | int BIO_fd_non_fatal_error(int _error); | ||
| 633 | int | ||
| 634 | BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), | ||
| 635 | void *u, const char *s, int len); | ||
| 636 | int | ||
| 637 | BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), | ||
| 638 | void *u, const char *s, int len, int indent); | ||
| 639 | int BIO_dump(BIO *b, const char *bytes, int len); | ||
| 640 | int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent); | ||
| 641 | int BIO_dump_fp(FILE *fp, const char *s, int len); | ||
| 642 | int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); | ||
| 643 | struct hostent *BIO_gethostbyname(const char *name); | ||
| 644 | /* We might want a thread-safe interface too: | ||
| 645 | * struct hostent *BIO_gethostbyname_r(const char *name, | ||
| 646 | * struct hostent *result, void *buffer, size_t buflen); | ||
| 647 | * or something similar (caller allocates a struct hostent, | ||
| 648 | * pointed to by "result", and additional buffer space for the various | ||
| 649 | * substructures; if the buffer does not suffice, NULL is returned | ||
| 650 | * and an appropriate error code is set). | ||
| 651 | */ | ||
| 652 | int BIO_sock_error(int sock); | ||
| 653 | int BIO_socket_ioctl(int fd, long type, void *arg); | ||
| 654 | int BIO_socket_nbio(int fd, int mode); | ||
| 655 | int BIO_get_port(const char *str, unsigned short *port_ptr); | ||
| 656 | int BIO_get_host_ip(const char *str, unsigned char *ip); | ||
| 657 | int BIO_get_accept_socket(char *host_port, int mode); | ||
| 658 | int BIO_accept(int sock, char **ip_port); | ||
| 659 | int BIO_sock_init(void ); | ||
| 660 | void BIO_sock_cleanup(void); | ||
| 661 | int BIO_set_tcp_ndelay(int sock, int turn_on); | ||
| 662 | |||
| 663 | BIO *BIO_new_socket(int sock, int close_flag); | ||
| 664 | BIO *BIO_new_dgram(int fd, int close_flag); | ||
| 665 | BIO *BIO_new_fd(int fd, int close_flag); | ||
| 666 | BIO *BIO_new_connect(char *host_port); | ||
| 667 | BIO *BIO_new_accept(char *host_port); | ||
| 668 | |||
| 669 | int | ||
| 670 | BIO_new_bio_pair(BIO **bio1, size_t writebuf1, | ||
| 671 | BIO **bio2, size_t writebuf2); | ||
| 672 | /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. | ||
| 673 | * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. | ||
| 674 | * Size 0 uses default value. | ||
| 675 | */ | ||
| 676 | |||
| 677 | void BIO_copy_next_retry(BIO *b); | ||
| 678 | |||
| 679 | /*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/ | ||
| 680 | |||
| 681 | int | ||
| 682 | BIO_printf(BIO *bio, const char *format, ...) | ||
| 683 | __attribute__((__format__(__printf__, 2, 3), __nonnull__(2))); | ||
| 684 | int | ||
| 685 | BIO_vprintf(BIO *bio, const char *format, va_list args) | ||
| 686 | __attribute__((__format__(__printf__, 2, 0), __nonnull__(2))); | ||
| 687 | int | ||
| 688 | BIO_snprintf(char *buf, size_t n, const char *format, ...) | ||
| 689 | __attribute__((__deprecated__, __format__(__printf__, 3, 4), | ||
| 690 | __nonnull__(3))); | ||
| 691 | int | ||
| 692 | BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | ||
| 693 | __attribute__((__deprecated__, __format__(__printf__, 3, 0), | ||
| 694 | __nonnull__(3))); | ||
| 695 | |||
| 696 | /* BEGIN ERROR CODES */ | ||
| 697 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 698 | * made after this point may be overwritten when the script is next run. | ||
| 699 | */ | ||
| 700 | void ERR_load_BIO_strings(void); | ||
| 701 | |||
| 702 | /* Error codes for the BIO functions. */ | ||
| 703 | |||
| 704 | /* Function codes. */ | ||
| 705 | #define BIO_F_ACPT_STATE 100 | ||
| 706 | #define BIO_F_BIO_ACCEPT 101 | ||
| 707 | #define BIO_F_BIO_BER_GET_HEADER 102 | ||
| 708 | #define BIO_F_BIO_CALLBACK_CTRL 131 | ||
| 709 | #define BIO_F_BIO_CTRL 103 | ||
| 710 | #define BIO_F_BIO_GETHOSTBYNAME 120 | ||
| 711 | #define BIO_F_BIO_GETS 104 | ||
| 712 | #define BIO_F_BIO_GET_ACCEPT_SOCKET 105 | ||
| 713 | #define BIO_F_BIO_GET_HOST_IP 106 | ||
| 714 | #define BIO_F_BIO_GET_PORT 107 | ||
| 715 | #define BIO_F_BIO_MAKE_PAIR 121 | ||
| 716 | #define BIO_F_BIO_NEW 108 | ||
| 717 | #define BIO_F_BIO_NEW_FILE 109 | ||
| 718 | #define BIO_F_BIO_NEW_MEM_BUF 126 | ||
| 719 | #define BIO_F_BIO_NREAD 123 | ||
| 720 | #define BIO_F_BIO_NREAD0 124 | ||
| 721 | #define BIO_F_BIO_NWRITE 125 | ||
| 722 | #define BIO_F_BIO_NWRITE0 122 | ||
| 723 | #define BIO_F_BIO_PUTS 110 | ||
| 724 | #define BIO_F_BIO_READ 111 | ||
| 725 | #define BIO_F_BIO_SOCK_INIT 112 | ||
| 726 | #define BIO_F_BIO_WRITE 113 | ||
| 727 | #define BIO_F_BUFFER_CTRL 114 | ||
| 728 | #define BIO_F_CONN_CTRL 127 | ||
| 729 | #define BIO_F_CONN_STATE 115 | ||
| 730 | #define BIO_F_DGRAM_SCTP_READ 132 | ||
| 731 | #define BIO_F_FILE_CTRL 116 | ||
| 732 | #define BIO_F_FILE_READ 130 | ||
| 733 | #define BIO_F_LINEBUFFER_CTRL 129 | ||
| 734 | #define BIO_F_MEM_READ 128 | ||
| 735 | #define BIO_F_MEM_WRITE 117 | ||
| 736 | #define BIO_F_SSL_NEW 118 | ||
| 737 | #define BIO_F_WSASTARTUP 119 | ||
| 738 | |||
| 739 | /* Reason codes. */ | ||
| 740 | #define BIO_R_ACCEPT_ERROR 100 | ||
| 741 | #define BIO_R_BAD_FOPEN_MODE 101 | ||
| 742 | #define BIO_R_BAD_HOSTNAME_LOOKUP 102 | ||
| 743 | #define BIO_R_BROKEN_PIPE 124 | ||
| 744 | #define BIO_R_CONNECT_ERROR 103 | ||
| 745 | #define BIO_R_EOF_ON_MEMORY_BIO 127 | ||
| 746 | #define BIO_R_ERROR_SETTING_NBIO 104 | ||
| 747 | #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 | ||
| 748 | #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 | ||
| 749 | #define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 | ||
| 750 | #define BIO_R_INVALID_ARGUMENT 125 | ||
| 751 | #define BIO_R_INVALID_IP_ADDRESS 108 | ||
| 752 | #define BIO_R_INVALID_PORT_NUMBER 129 | ||
| 753 | #define BIO_R_IN_USE 123 | ||
| 754 | #define BIO_R_KEEPALIVE 109 | ||
| 755 | #define BIO_R_NBIO_CONNECT_ERROR 110 | ||
| 756 | #define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 | ||
| 757 | #define BIO_R_NO_HOSTNAME_SPECIFIED 112 | ||
| 758 | #define BIO_R_NO_PORT_DEFINED 113 | ||
| 759 | #define BIO_R_NO_PORT_SPECIFIED 114 | ||
| 760 | #define BIO_R_NO_SUCH_FILE 128 | ||
| 761 | #define BIO_R_NULL_PARAMETER 115 | ||
| 762 | #define BIO_R_TAG_MISMATCH 116 | ||
| 763 | #define BIO_R_UNABLE_TO_BIND_SOCKET 117 | ||
| 764 | #define BIO_R_UNABLE_TO_CREATE_SOCKET 118 | ||
| 765 | #define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 | ||
| 766 | #define BIO_R_UNINITIALIZED 120 | ||
| 767 | #define BIO_R_UNSUPPORTED_METHOD 121 | ||
| 768 | #define BIO_R_WRITE_TO_READ_ONLY_BIO 126 | ||
| 769 | #define BIO_R_WSASTARTUP 122 | ||
| 770 | |||
| 771 | #ifdef __cplusplus | ||
| 772 | } | ||
| 773 | #endif | ||
| 774 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c deleted file mode 100644 index ab0e3a92ce..0000000000 --- a/src/lib/libcrypto/bio/bio_cb.c +++ /dev/null | |||
| @@ -1,145 +0,0 @@ | |||
| 1 | /* $OpenBSD: bio_cb.c,v 1.16 2014/12/08 03:54:19 bcook Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/bio.h> | ||
| 65 | |||
| 66 | long | ||
| 67 | BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl, | ||
| 68 | long ret) | ||
| 69 | { | ||
| 70 | BIO *b; | ||
| 71 | char buf[256]; | ||
| 72 | char *p; | ||
| 73 | long r = 1; | ||
| 74 | size_t p_maxlen; | ||
| 75 | |||
| 76 | if (BIO_CB_RETURN & cmd) | ||
| 77 | r = ret; | ||
| 78 | |||
| 79 | snprintf(buf, sizeof buf, "BIO[%p]:", bio); | ||
| 80 | p = &(buf[14]); | ||
| 81 | p_maxlen = sizeof buf - 14; | ||
| 82 | switch (cmd) { | ||
| 83 | case BIO_CB_FREE: | ||
| 84 | snprintf(p, p_maxlen, "Free - %s\n", bio->method->name); | ||
| 85 | break; | ||
| 86 | case BIO_CB_READ: | ||
| 87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | ||
| 88 | snprintf(p, p_maxlen, | ||
| 89 | "read(%d,%lu) - %s fd=%d\n", | ||
| 90 | bio->num, (unsigned long)argi, | ||
| 91 | bio->method->name, bio->num); | ||
| 92 | else | ||
| 93 | snprintf(p, p_maxlen, "read(%d,%lu) - %s\n", | ||
| 94 | bio->num, (unsigned long)argi, bio->method->name); | ||
| 95 | break; | ||
| 96 | case BIO_CB_WRITE: | ||
| 97 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | ||
| 98 | snprintf(p, p_maxlen, | ||
| 99 | "write(%d,%lu) - %s fd=%d\n", | ||
| 100 | bio->num, (unsigned long)argi, | ||
| 101 | bio->method->name, bio->num); | ||
| 102 | else | ||
| 103 | snprintf(p, p_maxlen, "write(%d,%lu) - %s\n", | ||
| 104 | bio->num, (unsigned long)argi, bio->method->name); | ||
| 105 | break; | ||
| 106 | case BIO_CB_PUTS: | ||
| 107 | snprintf(p, p_maxlen, | ||
| 108 | "puts() - %s\n", bio->method->name); | ||
| 109 | break; | ||
| 110 | case BIO_CB_GETS: | ||
| 111 | snprintf(p, p_maxlen, "gets(%lu) - %s\n", | ||
| 112 | (unsigned long)argi, bio->method->name); | ||
| 113 | break; | ||
| 114 | case BIO_CB_CTRL: | ||
| 115 | snprintf(p, p_maxlen, "ctrl(%lu) - %s\n", | ||
| 116 | (unsigned long)argi, bio->method->name); | ||
| 117 | break; | ||
| 118 | case BIO_CB_RETURN|BIO_CB_READ: | ||
| 119 | snprintf(p, p_maxlen, "read return %ld\n", ret); | ||
| 120 | break; | ||
| 121 | case BIO_CB_RETURN|BIO_CB_WRITE: | ||
| 122 | snprintf(p, p_maxlen, "write return %ld\n", ret); | ||
| 123 | break; | ||
| 124 | case BIO_CB_RETURN|BIO_CB_GETS: | ||
| 125 | snprintf(p, p_maxlen, "gets return %ld\n", ret); | ||
| 126 | break; | ||
| 127 | case BIO_CB_RETURN|BIO_CB_PUTS: | ||
| 128 | snprintf(p, p_maxlen, "puts return %ld\n", ret); | ||
| 129 | break; | ||
| 130 | case BIO_CB_RETURN|BIO_CB_CTRL: | ||
| 131 | snprintf(p, p_maxlen, "ctrl return %ld\n", ret); | ||
| 132 | break; | ||
| 133 | default: | ||
| 134 | snprintf(p, p_maxlen, | ||
| 135 | "bio callback - unknown type (%d)\n", cmd); | ||
| 136 | break; | ||
| 137 | } | ||
| 138 | |||
| 139 | b = (BIO *)bio->cb_arg; | ||
| 140 | if (b != NULL) | ||
| 141 | BIO_write(b, buf, strlen(buf)); | ||
| 142 | else | ||
| 143 | fputs(buf, stderr); | ||
| 144 | return (r); | ||
| 145 | } | ||
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c deleted file mode 100644 index 80788585ba..0000000000 --- a/src/lib/libcrypto/bio/bio_err.c +++ /dev/null | |||
| @@ -1,156 +0,0 @@ | |||
| 1 | /* $OpenBSD: bio_err.c,v 1.16 2014/07/10 22:45:56 jsing Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | |||
| 63 | #include <openssl/opensslconf.h> | ||
| 64 | |||
| 65 | #include <openssl/err.h> | ||
| 66 | #include <openssl/bio.h> | ||
| 67 | |||
| 68 | /* BEGIN ERROR CODES */ | ||
| 69 | #ifndef OPENSSL_NO_ERR | ||
| 70 | |||
| 71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0) | ||
| 72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason) | ||
| 73 | |||
| 74 | static ERR_STRING_DATA BIO_str_functs[] = { | ||
| 75 | {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, | ||
| 76 | {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"}, | ||
| 77 | {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"}, | ||
| 78 | {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"}, | ||
| 79 | {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, | ||
| 80 | {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, | ||
| 81 | {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, | ||
| 82 | {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"}, | ||
| 83 | {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"}, | ||
| 84 | {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"}, | ||
| 85 | {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"}, | ||
| 86 | {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, | ||
| 87 | {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"}, | ||
| 88 | {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"}, | ||
| 89 | {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"}, | ||
| 90 | {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"}, | ||
| 91 | {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"}, | ||
| 92 | {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"}, | ||
| 93 | {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, | ||
| 94 | {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, | ||
| 95 | {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, | ||
| 96 | {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, | ||
| 97 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, | ||
| 98 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, | ||
| 99 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, | ||
| 100 | {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"}, | ||
| 101 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, | ||
| 102 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, | ||
| 103 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, | ||
| 104 | {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"}, | ||
| 105 | {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"}, | ||
| 106 | {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"}, | ||
| 107 | {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"}, | ||
| 108 | {0, NULL} | ||
| 109 | }; | ||
| 110 | |||
| 111 | static ERR_STRING_DATA BIO_str_reasons[] = { | ||
| 112 | {ERR_REASON(BIO_R_ACCEPT_ERROR) , "accept error"}, | ||
| 113 | {ERR_REASON(BIO_R_BAD_FOPEN_MODE) , "bad fopen mode"}, | ||
| 114 | {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) , "bad hostname lookup"}, | ||
| 115 | {ERR_REASON(BIO_R_BROKEN_PIPE) , "broken pipe"}, | ||
| 116 | {ERR_REASON(BIO_R_CONNECT_ERROR) , "connect error"}, | ||
| 117 | {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) , "EOF on memory BIO"}, | ||
| 118 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) , "error setting nbio"}, | ||
| 119 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET), "error setting nbio on accepted socket"}, | ||
| 120 | {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET), "error setting nbio on accept socket"}, | ||
| 121 | {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET), "gethostbyname addr is not af inet"}, | ||
| 122 | {ERR_REASON(BIO_R_INVALID_ARGUMENT) , "invalid argument"}, | ||
| 123 | {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) , "invalid ip address"}, | ||
| 124 | {ERR_REASON(BIO_R_INVALID_PORT_NUMBER) , "invalid port number"}, | ||
| 125 | {ERR_REASON(BIO_R_IN_USE) , "in use"}, | ||
| 126 | {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"}, | ||
| 127 | {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"}, | ||
| 128 | {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"}, | ||
| 129 | {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"}, | ||
| 130 | {ERR_REASON(BIO_R_NO_PORT_DEFINED) , "no port defined"}, | ||
| 131 | {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) , "no port specified"}, | ||
| 132 | {ERR_REASON(BIO_R_NO_SUCH_FILE) , "no such file"}, | ||
| 133 | {ERR_REASON(BIO_R_NULL_PARAMETER) , "null parameter"}, | ||
| 134 | {ERR_REASON(BIO_R_TAG_MISMATCH) , "tag mismatch"}, | ||
| 135 | {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) , "unable to bind socket"}, | ||
| 136 | {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET), "unable to create socket"}, | ||
| 137 | {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET), "unable to listen socket"}, | ||
| 138 | {ERR_REASON(BIO_R_UNINITIALIZED) , "uninitialized"}, | ||
| 139 | {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) , "unsupported method"}, | ||
| 140 | {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO), "write to read only BIO"}, | ||
| 141 | {ERR_REASON(BIO_R_WSASTARTUP) , "WSAStartup"}, | ||
| 142 | {0, NULL} | ||
| 143 | }; | ||
| 144 | |||
| 145 | #endif | ||
| 146 | |||
| 147 | void | ||
| 148 | ERR_load_BIO_strings(void) | ||
| 149 | { | ||
| 150 | #ifndef OPENSSL_NO_ERR | ||
| 151 | if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) { | ||
| 152 | ERR_load_strings(0, BIO_str_functs); | ||
| 153 | ERR_load_strings(0, BIO_str_reasons); | ||
| 154 | } | ||
| 155 | #endif | ||
| 156 | } | ||
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c deleted file mode 100644 index 0be56aacde..0000000000 --- a/src/lib/libcrypto/bio/bio_lib.c +++ /dev/null | |||
| @@ -1,624 +0,0 @@ | |||
| 1 | /* $OpenBSD: bio_lib.c,v 1.22 2015/02/10 11:22:21 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | |||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/crypto.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | #include <openssl/stack.h> | ||
| 66 | |||
| 67 | BIO * | ||
| 68 | BIO_new(BIO_METHOD *method) | ||
| 69 | { | ||
| 70 | BIO *ret = NULL; | ||
| 71 | |||
| 72 | ret = malloc(sizeof(BIO)); | ||
| 73 | if (ret == NULL) { | ||
| 74 | BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); | ||
| 75 | return (NULL); | ||
| 76 | } | ||
| 77 | if (!BIO_set(ret, method)) { | ||
| 78 | free(ret); | ||
| 79 | ret = NULL; | ||
| 80 | } | ||
| 81 | return (ret); | ||
| 82 | } | ||
| 83 | |||
| 84 | int | ||
| 85 | BIO_set(BIO *bio, BIO_METHOD *method) | ||
| 86 | { | ||
| 87 | bio->method = method; | ||
| 88 | bio->callback = NULL; | ||
| 89 | bio->cb_arg = NULL; | ||
| 90 | bio->init = 0; | ||
| 91 | bio->shutdown = 1; | ||
| 92 | bio->flags = 0; | ||
| 93 | bio->retry_reason = 0; | ||
| 94 | bio->num = 0; | ||
| 95 | bio->ptr = NULL; | ||
| 96 | bio->prev_bio = NULL; | ||
| 97 | bio->next_bio = NULL; | ||
| 98 | bio->references = 1; | ||
| 99 | bio->num_read = 0L; | ||
| 100 | bio->num_write = 0L; | ||
| 101 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); | ||
| 102 | if (method->create != NULL) | ||
| 103 | if (!method->create(bio)) { | ||
| 104 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, | ||
| 105 | &bio->ex_data); | ||
| 106 | return (0); | ||
| 107 | } | ||
| 108 | return (1); | ||
| 109 | } | ||
| 110 | |||
| 111 | int | ||
| 112 | BIO_free(BIO *a) | ||
| 113 | { | ||
| 114 | int i; | ||
| 115 | |||
| 116 | if (a == NULL) | ||
| 117 | return (0); | ||
| 118 | |||
| 119 | i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO); | ||
| 120 | if (i > 0) | ||
| 121 | return (1); | ||
| 122 | if ((a->callback != NULL) && | ||
| 123 | ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0)) | ||
| 124 | return (i); | ||
| 125 | |||
| 126 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); | ||
| 127 | |||
| 128 | if (a->method != NULL && a->method->destroy != NULL) | ||
| 129 | a->method->destroy(a); | ||
| 130 | free(a); | ||
| 131 | return (1); | ||
| 132 | } | ||
| 133 | |||
| 134 | void | ||
| 135 | BIO_vfree(BIO *a) | ||
| 136 | { | ||
| 137 | BIO_free(a); | ||
| 138 | } | ||
| 139 | |||
| 140 | void | ||
| 141 | BIO_clear_flags(BIO *b, int flags) | ||
| 142 | { | ||
| 143 | b->flags &= ~flags; | ||
| 144 | } | ||
| 145 | |||
| 146 | int | ||
| 147 | BIO_test_flags(const BIO *b, int flags) | ||
| 148 | { | ||
| 149 | return (b->flags & flags); | ||
| 150 | } | ||
| 151 | |||
| 152 | void | ||
| 153 | BIO_set_flags(BIO *b, int flags) | ||
| 154 | { | ||
| 155 | b->flags |= flags; | ||
| 156 | } | ||
| 157 | |||
| 158 | long | ||
| 159 | (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int, | ||
| 160 | long, long) | ||
| 161 | { | ||
| 162 | return b->callback; | ||
| 163 | } | ||
| 164 | |||
| 165 | void | ||
| 166 | BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int, | ||
| 167 | long, long)) | ||
| 168 | { | ||
| 169 | b->callback = cb; | ||
| 170 | } | ||
| 171 | |||
| 172 | void | ||
| 173 | BIO_set_callback_arg(BIO *b, char *arg) | ||
| 174 | { | ||
| 175 | b->cb_arg = arg; | ||
| 176 | } | ||
| 177 | |||
| 178 | char * | ||
| 179 | BIO_get_callback_arg(const BIO *b) | ||
| 180 | { | ||
| 181 | return b->cb_arg; | ||
| 182 | } | ||
| 183 | |||
| 184 | const char * | ||
| 185 | BIO_method_name(const BIO *b) | ||
| 186 | { | ||
| 187 | return b->method->name; | ||
| 188 | } | ||
| 189 | |||
| 190 | int | ||
| 191 | BIO_method_type(const BIO *b) | ||
| 192 | { | ||
| 193 | return b->method->type; | ||
| 194 | } | ||
| 195 | |||
| 196 | int | ||
| 197 | BIO_read(BIO *b, void *out, int outl) | ||
| 198 | { | ||
| 199 | int i; | ||
| 200 | long (*cb)(BIO *, int, const char *, int, long, long); | ||
| 201 | |||
| 202 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { | ||
| 203 | BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD); | ||
| 204 | return (-2); | ||
| 205 | } | ||
| 206 | |||
| 207 | cb = b->callback; | ||
| 208 | if ((cb != NULL) && | ||
| 209 | ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0)) | ||
| 210 | return (i); | ||
| 211 | |||
| 212 | if (!b->init) { | ||
| 213 | BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED); | ||
| 214 | return (-2); | ||
| 215 | } | ||
| 216 | |||
| 217 | i = b->method->bread(b, out, outl); | ||
| 218 | |||
| 219 | if (i > 0) | ||
| 220 | b->num_read += (unsigned long)i; | ||
| 221 | |||
| 222 | if (cb != NULL) | ||
| 223 | i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, | ||
| 224 | 0L, (long)i); | ||
| 225 | return (i); | ||
| 226 | } | ||
| 227 | |||
| 228 | int | ||
| 229 | BIO_write(BIO *b, const void *in, int inl) | ||
| 230 | { | ||
| 231 | int i; | ||
| 232 | long (*cb)(BIO *, int, const char *, int, long, long); | ||
| 233 | |||
| 234 | if (b == NULL) | ||
| 235 | return (0); | ||
| 236 | |||
| 237 | cb = b->callback; | ||
| 238 | if ((b->method == NULL) || (b->method->bwrite == NULL)) { | ||
| 239 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD); | ||
| 240 | return (-2); | ||
| 241 | } | ||
| 242 | |||
| 243 | if ((cb != NULL) && | ||
| 244 | ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) | ||
| 245 | return (i); | ||
| 246 | |||
| 247 | if (!b->init) { | ||
| 248 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED); | ||
| 249 | return (-2); | ||
| 250 | } | ||
| 251 | |||
| 252 | i = b->method->bwrite(b, in, inl); | ||
| 253 | |||
| 254 | if (i > 0) | ||
| 255 | b->num_write += (unsigned long)i; | ||
| 256 | |||
| 257 | if (cb != NULL) | ||
| 258 | i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, | ||
| 259 | 0L, (long)i); | ||
| 260 | return (i); | ||
| 261 | } | ||
| 262 | |||
| 263 | int | ||
| 264 | BIO_puts(BIO *b, const char *in) | ||
| 265 | { | ||
| 266 | int i; | ||
| 267 | long (*cb)(BIO *, int, const char *, int, long, long); | ||
| 268 | |||
| 269 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) { | ||
| 270 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD); | ||
| 271 | return (-2); | ||
| 272 | } | ||
| 273 | |||
| 274 | cb = b->callback; | ||
| 275 | |||
| 276 | if ((cb != NULL) && | ||
| 277 | ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0)) | ||
| 278 | return (i); | ||
| 279 | |||
| 280 | if (!b->init) { | ||
| 281 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED); | ||
| 282 | return (-2); | ||
| 283 | } | ||
| 284 | |||
| 285 | i = b->method->bputs(b, in); | ||
| 286 | |||
| 287 | if (i > 0) | ||
| 288 | b->num_write += (unsigned long)i; | ||
| 289 | |||
| 290 | if (cb != NULL) | ||
| 291 | i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i); | ||
| 292 | return (i); | ||
| 293 | } | ||
| 294 | |||
| 295 | int | ||
| 296 | BIO_gets(BIO *b, char *in, int inl) | ||
| 297 | { | ||
| 298 | int i; | ||
| 299 | long (*cb)(BIO *, int, const char *, int, long, long); | ||
| 300 | |||
| 301 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) { | ||
| 302 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD); | ||
| 303 | return (-2); | ||
| 304 | } | ||
| 305 | |||
| 306 | cb = b->callback; | ||
| 307 | |||
| 308 | if ((cb != NULL) && | ||
| 309 | ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0)) | ||
| 310 | return (i); | ||
| 311 | |||
| 312 | if (!b->init) { | ||
| 313 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED); | ||
| 314 | return (-2); | ||
| 315 | } | ||
| 316 | |||
| 317 | i = b->method->bgets(b, in, inl); | ||
| 318 | |||
| 319 | if (cb != NULL) | ||
| 320 | i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i); | ||
| 321 | return (i); | ||
| 322 | } | ||
| 323 | |||
| 324 | int | ||
| 325 | BIO_indent(BIO *b, int indent, int max) | ||
| 326 | { | ||
| 327 | if (indent < 0) | ||
| 328 | indent = 0; | ||
| 329 | if (indent > max) | ||
| 330 | indent = max; | ||
| 331 | while (indent--) | ||
| 332 | if (BIO_puts(b, " ") != 1) | ||
| 333 | return 0; | ||
| 334 | return 1; | ||
| 335 | } | ||
| 336 | |||
| 337 | long | ||
| 338 | BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) | ||
| 339 | { | ||
| 340 | int i; | ||
| 341 | |||
| 342 | i = iarg; | ||
| 343 | return (BIO_ctrl(b, cmd, larg, (char *)&i)); | ||
| 344 | } | ||
| 345 | |||
| 346 | char * | ||
| 347 | BIO_ptr_ctrl(BIO *b, int cmd, long larg) | ||
| 348 | { | ||
| 349 | char *p = NULL; | ||
| 350 | |||
| 351 | if (BIO_ctrl(b, cmd, larg, (char *)&p) <= 0) | ||
| 352 | return (NULL); | ||
| 353 | else | ||
| 354 | return (p); | ||
| 355 | } | ||
| 356 | |||
| 357 | long | ||
| 358 | BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | ||
| 359 | { | ||
| 360 | long ret; | ||
| 361 | long (*cb)(BIO *, int, const char *, int, long, long); | ||
| 362 | |||
| 363 | if (b == NULL) | ||
| 364 | return (0); | ||
| 365 | |||
| 366 | if ((b->method == NULL) || (b->method->ctrl == NULL)) { | ||
| 367 | BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD); | ||
| 368 | return (-2); | ||
| 369 | } | ||
| 370 | |||
| 371 | cb = b->callback; | ||
| 372 | |||
| 373 | if ((cb != NULL) && | ||
| 374 | ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0)) | ||
| 375 | return (ret); | ||
| 376 | |||
| 377 | ret = b->method->ctrl(b, cmd, larg, parg); | ||
| 378 | |||
| 379 | if (cb != NULL) | ||
| 380 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret); | ||
| 381 | return (ret); | ||
| 382 | } | ||
| 383 | |||
| 384 | long | ||
| 385 | BIO_callback_ctrl(BIO *b, int cmd, | ||
| 386 | void (*fp)(struct bio_st *, int, const char *, int, long, long)) | ||
| 387 | { | ||
| 388 | long ret; | ||
| 389 | long (*cb)(BIO *, int, const char *, int, long, long); | ||
| 390 | |||
| 391 | if (b == NULL) | ||
| 392 | return (0); | ||
| 393 | |||
| 394 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) { | ||
| 395 | BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD); | ||
| 396 | return (-2); | ||
| 397 | } | ||
| 398 | |||
| 399 | cb = b->callback; | ||
| 400 | |||
| 401 | if ((cb != NULL) && | ||
| 402 | ((ret = cb(b, BIO_CB_CTRL, (void *)&fp, cmd, 0, 1L)) <= 0)) | ||
| 403 | return (ret); | ||
| 404 | |||
| 405 | ret = b->method->callback_ctrl(b, cmd, fp); | ||
| 406 | |||
| 407 | if (cb != NULL) | ||
| 408 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, (void *)&fp, cmd, 0, ret); | ||
| 409 | return (ret); | ||
| 410 | } | ||
| 411 | |||
| 412 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | ||
| 413 | * do; but those macros have inappropriate return type, and for interfacing | ||
| 414 | * from other programming languages, C macros aren't much of a help anyway. */ | ||
| 415 | size_t | ||
| 416 | BIO_ctrl_pending(BIO *bio) | ||
| 417 | { | ||
| 418 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | ||
| 419 | } | ||
| 420 | |||
| 421 | size_t | ||
| 422 | BIO_ctrl_wpending(BIO *bio) | ||
| 423 | { | ||
| 424 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | ||
| 425 | } | ||
| 426 | |||
| 427 | |||
| 428 | /* put the 'bio' on the end of b's list of operators */ | ||
| 429 | BIO * | ||
| 430 | BIO_push(BIO *b, BIO *bio) | ||
| 431 | { | ||
| 432 | BIO *lb; | ||
| 433 | |||
| 434 | if (b == NULL) | ||
| 435 | return (bio); | ||
| 436 | lb = b; | ||
| 437 | while (lb->next_bio != NULL) | ||
| 438 | lb = lb->next_bio; | ||
| 439 | lb->next_bio = bio; | ||
| 440 | if (bio != NULL) | ||
| 441 | bio->prev_bio = lb; | ||
| 442 | /* called to do internal processing */ | ||
| 443 | BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb); | ||
| 444 | return (b); | ||
| 445 | } | ||
| 446 | |||
| 447 | /* Remove the first and return the rest */ | ||
| 448 | BIO * | ||
| 449 | BIO_pop(BIO *b) | ||
| 450 | { | ||
| 451 | BIO *ret; | ||
| 452 | |||
| 453 | if (b == NULL) | ||
| 454 | return (NULL); | ||
| 455 | ret = b->next_bio; | ||
| 456 | |||
| 457 | BIO_ctrl(b, BIO_CTRL_POP, 0, b); | ||
| 458 | |||
| 459 | if (b->prev_bio != NULL) | ||
| 460 | b->prev_bio->next_bio = b->next_bio; | ||
| 461 | if (b->next_bio != NULL) | ||
| 462 | b->next_bio->prev_bio = b->prev_bio; | ||
| 463 | |||
| 464 | b->next_bio = NULL; | ||
| 465 | b->prev_bio = NULL; | ||
| 466 | return (ret); | ||
| 467 | } | ||
| 468 | |||
| 469 | BIO * | ||
| 470 | BIO_get_retry_BIO(BIO *bio, int *reason) | ||
| 471 | { | ||
| 472 | BIO *b, *last; | ||
| 473 | |||
| 474 | b = last = bio; | ||
| 475 | for (;;) { | ||
| 476 | if (!BIO_should_retry(b)) | ||
| 477 | break; | ||
| 478 | last = b; | ||
| 479 | b = b->next_bio; | ||
| 480 | if (b == NULL) | ||
| 481 | break; | ||
| 482 | } | ||
| 483 | if (reason != NULL) | ||
| 484 | *reason = last->retry_reason; | ||
| 485 | return (last); | ||
| 486 | } | ||
| 487 | |||
| 488 | int | ||
| 489 | BIO_get_retry_reason(BIO *bio) | ||
| 490 | { | ||
| 491 | return (bio->retry_reason); | ||
| 492 | } | ||
| 493 | |||
| 494 | BIO * | ||
| 495 | BIO_find_type(BIO *bio, int type) | ||
| 496 | { | ||
| 497 | int mt, mask; | ||
| 498 | |||
| 499 | if (!bio) | ||
| 500 | return NULL; | ||
| 501 | mask = type & 0xff; | ||
| 502 | do { | ||
| 503 | if (bio->method != NULL) { | ||
| 504 | mt = bio->method->type; | ||
| 505 | if (!mask) { | ||
| 506 | if (mt & type) | ||
| 507 | return (bio); | ||
| 508 | } else if (mt == type) | ||
| 509 | return (bio); | ||
| 510 | } | ||
| 511 | bio = bio->next_bio; | ||
| 512 | } while (bio != NULL); | ||
| 513 | return (NULL); | ||
| 514 | } | ||
| 515 | |||
| 516 | BIO * | ||
| 517 | BIO_next(BIO *b) | ||
| 518 | { | ||
| 519 | if (!b) | ||
| 520 | return NULL; | ||
| 521 | return b->next_bio; | ||
| 522 | } | ||
| 523 | |||
| 524 | void | ||
| 525 | BIO_free_all(BIO *bio) | ||
| 526 | { | ||
| 527 | BIO *b; | ||
| 528 | int ref; | ||
| 529 | |||
| 530 | while (bio != NULL) { | ||
| 531 | b = bio; | ||
| 532 | ref = b->references; | ||
| 533 | bio = bio->next_bio; | ||
| 534 | BIO_free(b); | ||
| 535 | /* Since ref count > 1, don't free anyone else. */ | ||
| 536 | if (ref > 1) | ||
| 537 | break; | ||
| 538 | } | ||
| 539 | } | ||
| 540 | |||
| 541 | BIO * | ||
| 542 | BIO_dup_chain(BIO *in) | ||
| 543 | { | ||
| 544 | BIO *ret = NULL, *eoc = NULL, *bio, *new_bio; | ||
| 545 | |||
| 546 | for (bio = in; bio != NULL; bio = bio->next_bio) { | ||
| 547 | if ((new_bio = BIO_new(bio->method)) == NULL) | ||
| 548 | goto err; | ||
| 549 | new_bio->callback = bio->callback; | ||
| 550 | new_bio->cb_arg = bio->cb_arg; | ||
| 551 | new_bio->init = bio->init; | ||
| 552 | new_bio->shutdown = bio->shutdown; | ||
| 553 | new_bio->flags = bio->flags; | ||
| 554 | |||
| 555 | /* This will let SSL_s_sock() work with stdin/stdout */ | ||
| 556 | new_bio->num = bio->num; | ||
| 557 | |||
| 558 | if (!BIO_dup_state(bio, (char *)new_bio)) { | ||
| 559 | BIO_free(new_bio); | ||
| 560 | goto err; | ||
| 561 | } | ||
| 562 | |||
| 563 | /* copy app data */ | ||
| 564 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, | ||
| 565 | &new_bio->ex_data, &bio->ex_data)) | ||
| 566 | goto err; | ||
| 567 | |||
| 568 | if (ret == NULL) { | ||
| 569 | eoc = new_bio; | ||
| 570 | ret = eoc; | ||
| 571 | } else { | ||
| 572 | BIO_push(eoc, new_bio); | ||
| 573 | eoc = new_bio; | ||
| 574 | } | ||
| 575 | } | ||
| 576 | return (ret); | ||
| 577 | err: | ||
| 578 | BIO_free(ret); | ||
| 579 | return (NULL); | ||
| 580 | |||
| 581 | } | ||
| 582 | |||
| 583 | void | ||
| 584 | BIO_copy_next_retry(BIO *b) | ||
| 585 | { | ||
| 586 | BIO_set_flags(b, BIO_get_retry_flags(b->next_bio)); | ||
| 587 | b->retry_reason = b->next_bio->retry_reason; | ||
| 588 | } | ||
| 589 | |||
| 590 | int | ||
| 591 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 592 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 593 | { | ||
| 594 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, | ||
| 595 | new_func, dup_func, free_func); | ||
| 596 | } | ||
| 597 | |||
| 598 | int | ||
| 599 | BIO_set_ex_data(BIO *bio, int idx, void *data) | ||
| 600 | { | ||
| 601 | return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data)); | ||
| 602 | } | ||
| 603 | |||
| 604 | void * | ||
| 605 | BIO_get_ex_data(BIO *bio, int idx) | ||
| 606 | { | ||
| 607 | return (CRYPTO_get_ex_data(&(bio->ex_data), idx)); | ||
| 608 | } | ||
| 609 | |||
| 610 | unsigned long | ||
| 611 | BIO_number_read(BIO *bio) | ||
| 612 | { | ||
| 613 | if (bio) | ||
| 614 | return bio->num_read; | ||
| 615 | return 0; | ||
| 616 | } | ||
| 617 | |||
| 618 | unsigned long | ||
| 619 | BIO_number_written(BIO *bio) | ||
| 620 | { | ||
| 621 | if (bio) | ||
| 622 | return bio->num_write; | ||
| 623 | return 0; | ||
| 624 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c deleted file mode 100644 index 4e3c982c2d..0000000000 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ /dev/null | |||
| @@ -1,453 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_acpt.c,v 1.26 2015/07/18 22:09:30 beck Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <sys/socket.h> | ||
| 60 | |||
| 61 | #include <errno.h> | ||
| 62 | #include <stdio.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <unistd.h> | ||
| 65 | |||
| 66 | #include <openssl/bio.h> | ||
| 67 | #include <openssl/buffer.h> | ||
| 68 | #include <openssl/err.h> | ||
| 69 | |||
| 70 | #define SOCKET_PROTOCOL IPPROTO_TCP | ||
| 71 | |||
| 72 | typedef struct bio_accept_st { | ||
| 73 | int state; | ||
| 74 | char *param_addr; | ||
| 75 | |||
| 76 | int accept_sock; | ||
| 77 | int accept_nbio; | ||
| 78 | |||
| 79 | char *addr; | ||
| 80 | int nbio; | ||
| 81 | /* If 0, it means normal, if 1, do a connect on bind failure, | ||
| 82 | * and if there is no-one listening, bind with SO_REUSEADDR. | ||
| 83 | * If 2, always use SO_REUSEADDR. */ | ||
| 84 | int bind_mode; | ||
| 85 | BIO *bio_chain; | ||
| 86 | } BIO_ACCEPT; | ||
| 87 | |||
| 88 | static int acpt_write(BIO *h, const char *buf, int num); | ||
| 89 | static int acpt_read(BIO *h, char *buf, int size); | ||
| 90 | static int acpt_puts(BIO *h, const char *str); | ||
| 91 | static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 92 | static int acpt_new(BIO *h); | ||
| 93 | static int acpt_free(BIO *data); | ||
| 94 | static int acpt_state(BIO *b, BIO_ACCEPT *c); | ||
| 95 | static void acpt_close_socket(BIO *data); | ||
| 96 | static BIO_ACCEPT *BIO_ACCEPT_new(void ); | ||
| 97 | static void BIO_ACCEPT_free(BIO_ACCEPT *a); | ||
| 98 | |||
| 99 | #define ACPT_S_BEFORE 1 | ||
| 100 | #define ACPT_S_GET_ACCEPT_SOCKET 2 | ||
| 101 | #define ACPT_S_OK 3 | ||
| 102 | |||
| 103 | static BIO_METHOD methods_acceptp = { | ||
| 104 | .type = BIO_TYPE_ACCEPT, | ||
| 105 | .name = "socket accept", | ||
| 106 | .bwrite = acpt_write, | ||
| 107 | .bread = acpt_read, | ||
| 108 | .bputs = acpt_puts, | ||
| 109 | .ctrl = acpt_ctrl, | ||
| 110 | .create = acpt_new, | ||
| 111 | .destroy = acpt_free | ||
| 112 | }; | ||
| 113 | |||
| 114 | BIO_METHOD * | ||
| 115 | BIO_s_accept(void) | ||
| 116 | { | ||
| 117 | return (&methods_acceptp); | ||
| 118 | } | ||
| 119 | |||
| 120 | static int | ||
| 121 | acpt_new(BIO *bi) | ||
| 122 | { | ||
| 123 | BIO_ACCEPT *ba; | ||
| 124 | |||
| 125 | bi->init = 0; | ||
| 126 | bi->num = -1; | ||
| 127 | bi->flags = 0; | ||
| 128 | if ((ba = BIO_ACCEPT_new()) == NULL) | ||
| 129 | return (0); | ||
| 130 | bi->ptr = (char *)ba; | ||
| 131 | ba->state = ACPT_S_BEFORE; | ||
| 132 | bi->shutdown = 1; | ||
| 133 | return (1); | ||
| 134 | } | ||
| 135 | |||
| 136 | static BIO_ACCEPT * | ||
| 137 | BIO_ACCEPT_new(void) | ||
| 138 | { | ||
| 139 | BIO_ACCEPT *ret; | ||
| 140 | |||
| 141 | if ((ret = calloc(1, sizeof(BIO_ACCEPT))) == NULL) | ||
| 142 | return (NULL); | ||
| 143 | ret->accept_sock = -1; | ||
| 144 | ret->bind_mode = BIO_BIND_NORMAL; | ||
| 145 | return (ret); | ||
| 146 | } | ||
| 147 | |||
| 148 | static void | ||
| 149 | BIO_ACCEPT_free(BIO_ACCEPT *a) | ||
| 150 | { | ||
| 151 | if (a == NULL) | ||
| 152 | return; | ||
| 153 | |||
| 154 | free(a->param_addr); | ||
| 155 | free(a->addr); | ||
| 156 | BIO_free(a->bio_chain); | ||
| 157 | free(a); | ||
| 158 | } | ||
| 159 | |||
| 160 | static void | ||
| 161 | acpt_close_socket(BIO *bio) | ||
| 162 | { | ||
| 163 | BIO_ACCEPT *c; | ||
| 164 | |||
| 165 | c = (BIO_ACCEPT *)bio->ptr; | ||
| 166 | if (c->accept_sock != -1) { | ||
| 167 | shutdown(c->accept_sock, SHUT_RDWR); | ||
| 168 | close(c->accept_sock); | ||
| 169 | c->accept_sock = -1; | ||
| 170 | bio->num = -1; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | static int | ||
| 175 | acpt_free(BIO *a) | ||
| 176 | { | ||
| 177 | BIO_ACCEPT *data; | ||
| 178 | |||
| 179 | if (a == NULL) | ||
| 180 | return (0); | ||
| 181 | data = (BIO_ACCEPT *)a->ptr; | ||
| 182 | |||
| 183 | if (a->shutdown) { | ||
| 184 | acpt_close_socket(a); | ||
| 185 | BIO_ACCEPT_free(data); | ||
| 186 | a->ptr = NULL; | ||
| 187 | a->flags = 0; | ||
| 188 | a->init = 0; | ||
| 189 | } | ||
| 190 | return (1); | ||
| 191 | } | ||
| 192 | |||
| 193 | static int | ||
| 194 | acpt_state(BIO *b, BIO_ACCEPT *c) | ||
| 195 | { | ||
| 196 | BIO *bio = NULL, *dbio; | ||
| 197 | int s = -1; | ||
| 198 | int i; | ||
| 199 | |||
| 200 | again: | ||
| 201 | switch (c->state) { | ||
| 202 | case ACPT_S_BEFORE: | ||
| 203 | if (c->param_addr == NULL) { | ||
| 204 | BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED); | ||
| 205 | return (-1); | ||
| 206 | } | ||
| 207 | s = BIO_get_accept_socket(c->param_addr, c->bind_mode); | ||
| 208 | if (s == -1) | ||
| 209 | return (-1); | ||
| 210 | |||
| 211 | if (c->accept_nbio) { | ||
| 212 | if (!BIO_socket_nbio(s, 1)) { | ||
| 213 | close(s); | ||
| 214 | BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); | ||
| 215 | return (-1); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | c->accept_sock = s; | ||
| 219 | b->num = s; | ||
| 220 | c->state = ACPT_S_GET_ACCEPT_SOCKET; | ||
| 221 | return (1); | ||
| 222 | /* break; */ | ||
| 223 | case ACPT_S_GET_ACCEPT_SOCKET: | ||
| 224 | if (b->next_bio != NULL) { | ||
| 225 | c->state = ACPT_S_OK; | ||
| 226 | goto again; | ||
| 227 | } | ||
| 228 | BIO_clear_retry_flags(b); | ||
| 229 | b->retry_reason = 0; | ||
| 230 | i = BIO_accept(c->accept_sock, &(c->addr)); | ||
| 231 | |||
| 232 | /* -2 return means we should retry */ | ||
| 233 | if (i == -2) { | ||
| 234 | BIO_set_retry_special(b); | ||
| 235 | b->retry_reason = BIO_RR_ACCEPT; | ||
| 236 | return -1; | ||
| 237 | } | ||
| 238 | |||
| 239 | if (i < 0) | ||
| 240 | return (i); | ||
| 241 | |||
| 242 | bio = BIO_new_socket(i, BIO_CLOSE); | ||
| 243 | if (bio == NULL) | ||
| 244 | goto err; | ||
| 245 | |||
| 246 | BIO_set_callback(bio, BIO_get_callback(b)); | ||
| 247 | BIO_set_callback_arg(bio, BIO_get_callback_arg(b)); | ||
| 248 | |||
| 249 | if (c->nbio) { | ||
| 250 | if (!BIO_socket_nbio(i, 1)) { | ||
| 251 | BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); | ||
| 252 | goto err; | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | /* If the accept BIO has an bio_chain, we dup it and | ||
| 257 | * put the new socket at the end. */ | ||
| 258 | if (c->bio_chain != NULL) { | ||
| 259 | if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL) | ||
| 260 | goto err; | ||
| 261 | if (!BIO_push(dbio, bio)) goto err; | ||
| 262 | bio = dbio; | ||
| 263 | } | ||
| 264 | if (BIO_push(b, bio) | ||
| 265 | == NULL) goto err; | ||
| 266 | |||
| 267 | c->state = ACPT_S_OK; | ||
| 268 | return (1); | ||
| 269 | |||
| 270 | err: | ||
| 271 | if (bio != NULL) | ||
| 272 | BIO_free(bio); | ||
| 273 | return (0); | ||
| 274 | /* break; */ | ||
| 275 | case ACPT_S_OK: | ||
| 276 | if (b->next_bio == NULL) { | ||
| 277 | c->state = ACPT_S_GET_ACCEPT_SOCKET; | ||
| 278 | goto again; | ||
| 279 | } | ||
| 280 | return (1); | ||
| 281 | /* break; */ | ||
| 282 | default: | ||
| 283 | return (0); | ||
| 284 | /* break; */ | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | static int | ||
| 289 | acpt_read(BIO *b, char *out, int outl) | ||
| 290 | { | ||
| 291 | int ret = 0; | ||
| 292 | BIO_ACCEPT *data; | ||
| 293 | |||
| 294 | BIO_clear_retry_flags(b); | ||
| 295 | data = (BIO_ACCEPT *)b->ptr; | ||
| 296 | |||
| 297 | while (b->next_bio == NULL) { | ||
| 298 | ret = acpt_state(b, data); | ||
| 299 | if (ret <= 0) | ||
| 300 | return (ret); | ||
| 301 | } | ||
| 302 | |||
| 303 | ret = BIO_read(b->next_bio, out, outl); | ||
| 304 | BIO_copy_next_retry(b); | ||
| 305 | return (ret); | ||
| 306 | } | ||
| 307 | |||
| 308 | static int | ||
| 309 | acpt_write(BIO *b, const char *in, int inl) | ||
| 310 | { | ||
| 311 | int ret; | ||
| 312 | BIO_ACCEPT *data; | ||
| 313 | |||
| 314 | BIO_clear_retry_flags(b); | ||
| 315 | data = (BIO_ACCEPT *)b->ptr; | ||
| 316 | |||
| 317 | while (b->next_bio == NULL) { | ||
| 318 | ret = acpt_state(b, data); | ||
| 319 | if (ret <= 0) | ||
| 320 | return (ret); | ||
| 321 | } | ||
| 322 | |||
| 323 | ret = BIO_write(b->next_bio, in, inl); | ||
| 324 | BIO_copy_next_retry(b); | ||
| 325 | return (ret); | ||
| 326 | } | ||
| 327 | |||
| 328 | static long | ||
| 329 | acpt_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 330 | { | ||
| 331 | int *ip; | ||
| 332 | long ret = 1; | ||
| 333 | BIO_ACCEPT *data; | ||
| 334 | char **pp; | ||
| 335 | |||
| 336 | data = (BIO_ACCEPT *)b->ptr; | ||
| 337 | |||
| 338 | switch (cmd) { | ||
| 339 | case BIO_CTRL_RESET: | ||
| 340 | ret = 0; | ||
| 341 | data->state = ACPT_S_BEFORE; | ||
| 342 | acpt_close_socket(b); | ||
| 343 | b->flags = 0; | ||
| 344 | break; | ||
| 345 | case BIO_C_DO_STATE_MACHINE: | ||
| 346 | /* use this one to start the connection */ | ||
| 347 | ret = (long)acpt_state(b, data); | ||
| 348 | break; | ||
| 349 | case BIO_C_SET_ACCEPT: | ||
| 350 | if (ptr != NULL) { | ||
| 351 | if (num == 0) { | ||
| 352 | b->init = 1; | ||
| 353 | free(data->param_addr); | ||
| 354 | data->param_addr = strdup(ptr); | ||
| 355 | } else if (num == 1) { | ||
| 356 | data->accept_nbio = (ptr != NULL); | ||
| 357 | } else if (num == 2) { | ||
| 358 | BIO_free(data->bio_chain); | ||
| 359 | data->bio_chain = (BIO *)ptr; | ||
| 360 | } | ||
| 361 | } | ||
| 362 | break; | ||
| 363 | case BIO_C_SET_NBIO: | ||
| 364 | data->nbio = (int)num; | ||
| 365 | break; | ||
| 366 | case BIO_C_SET_FD: | ||
| 367 | b->init = 1; | ||
| 368 | b->num= *((int *)ptr); | ||
| 369 | data->accept_sock = b->num; | ||
| 370 | data->state = ACPT_S_GET_ACCEPT_SOCKET; | ||
| 371 | b->shutdown = (int)num; | ||
| 372 | b->init = 1; | ||
| 373 | break; | ||
| 374 | case BIO_C_GET_FD: | ||
| 375 | if (b->init) { | ||
| 376 | ip = (int *)ptr; | ||
| 377 | if (ip != NULL) | ||
| 378 | *ip = data->accept_sock; | ||
| 379 | ret = data->accept_sock; | ||
| 380 | } else | ||
| 381 | ret = -1; | ||
| 382 | break; | ||
| 383 | case BIO_C_GET_ACCEPT: | ||
| 384 | if (b->init) { | ||
| 385 | if (ptr != NULL) { | ||
| 386 | pp = (char **)ptr; | ||
| 387 | *pp = data->param_addr; | ||
| 388 | } else | ||
| 389 | ret = -1; | ||
| 390 | } else | ||
| 391 | ret = -1; | ||
| 392 | break; | ||
| 393 | case BIO_CTRL_GET_CLOSE: | ||
| 394 | ret = b->shutdown; | ||
| 395 | break; | ||
| 396 | case BIO_CTRL_SET_CLOSE: | ||
| 397 | b->shutdown = (int)num; | ||
| 398 | break; | ||
| 399 | case BIO_CTRL_PENDING: | ||
| 400 | case BIO_CTRL_WPENDING: | ||
| 401 | ret = 0; | ||
| 402 | break; | ||
| 403 | case BIO_CTRL_FLUSH: | ||
| 404 | break; | ||
| 405 | case BIO_C_SET_BIND_MODE: | ||
| 406 | data->bind_mode = (int)num; | ||
| 407 | break; | ||
| 408 | case BIO_C_GET_BIND_MODE: | ||
| 409 | ret = (long)data->bind_mode; | ||
| 410 | break; | ||
| 411 | case BIO_CTRL_DUP: | ||
| 412 | /* dbio=(BIO *)ptr; | ||
| 413 | if (data->param_port) EAY EAY | ||
| 414 | BIO_set_port(dbio,data->param_port); | ||
| 415 | if (data->param_hostname) | ||
| 416 | BIO_set_hostname(dbio,data->param_hostname); | ||
| 417 | BIO_set_nbio(dbio,data->nbio); | ||
| 418 | */ | ||
| 419 | break; | ||
| 420 | |||
| 421 | default: | ||
| 422 | ret = 0; | ||
| 423 | break; | ||
| 424 | } | ||
| 425 | return (ret); | ||
| 426 | } | ||
| 427 | |||
| 428 | static int | ||
| 429 | acpt_puts(BIO *bp, const char *str) | ||
| 430 | { | ||
| 431 | int n, ret; | ||
| 432 | |||
| 433 | n = strlen(str); | ||
| 434 | ret = acpt_write(bp, str, n); | ||
| 435 | return (ret); | ||
| 436 | } | ||
| 437 | |||
| 438 | BIO * | ||
| 439 | BIO_new_accept(char *str) | ||
| 440 | { | ||
| 441 | BIO *ret; | ||
| 442 | |||
| 443 | ret = BIO_new(BIO_s_accept()); | ||
| 444 | if (ret == NULL) | ||
| 445 | return (NULL); | ||
| 446 | if (BIO_set_accept_port(ret, str)) | ||
| 447 | return (ret); | ||
| 448 | else { | ||
| 449 | BIO_free(ret); | ||
| 450 | return (NULL); | ||
| 451 | } | ||
| 452 | } | ||
| 453 | |||
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c deleted file mode 100644 index 26ae962aeb..0000000000 --- a/src/lib/libcrypto/bio/bss_bio.c +++ /dev/null | |||
| @@ -1,884 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_bio.c,v 1.20 2014/06/12 15:49:28 deraadt Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* Special method for a BIO where the other endpoint is also a BIO | ||
| 57 | * of this kind, handled by the same thread (i.e. the "peer" is actually | ||
| 58 | * ourselves, wearing a different hat). | ||
| 59 | * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces | ||
| 60 | * for which no specific BIO method is available. | ||
| 61 | * See ssl/ssltest.c for some hints on how this can be used. */ | ||
| 62 | |||
| 63 | /* BIO_DEBUG implies BIO_PAIR_DEBUG */ | ||
| 64 | #ifdef BIO_DEBUG | ||
| 65 | # ifndef BIO_PAIR_DEBUG | ||
| 66 | # define BIO_PAIR_DEBUG | ||
| 67 | # endif | ||
| 68 | #endif | ||
| 69 | |||
| 70 | /* disable assert() unless BIO_PAIR_DEBUG has been defined */ | ||
| 71 | #ifndef BIO_PAIR_DEBUG | ||
| 72 | # ifndef NDEBUG | ||
| 73 | # define NDEBUG | ||
| 74 | # endif | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #include <assert.h> | ||
| 78 | #include <limits.h> | ||
| 79 | #include <stdlib.h> | ||
| 80 | #include <string.h> | ||
| 81 | |||
| 82 | #include <openssl/bio.h> | ||
| 83 | #include <openssl/err.h> | ||
| 84 | #include <openssl/crypto.h> | ||
| 85 | |||
| 86 | static int bio_new(BIO *bio); | ||
| 87 | static int bio_free(BIO *bio); | ||
| 88 | static int bio_read(BIO *bio, char *buf, int size); | ||
| 89 | static int bio_write(BIO *bio, const char *buf, int num); | ||
| 90 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr); | ||
| 91 | static int bio_puts(BIO *bio, const char *str); | ||
| 92 | |||
| 93 | static int bio_make_pair(BIO *bio1, BIO *bio2); | ||
| 94 | static void bio_destroy_pair(BIO *bio); | ||
| 95 | |||
| 96 | static BIO_METHOD methods_biop = { | ||
| 97 | .type = BIO_TYPE_BIO, | ||
| 98 | .name = "BIO pair", | ||
| 99 | .bwrite = bio_write, | ||
| 100 | .bread = bio_read, | ||
| 101 | .bputs = bio_puts, | ||
| 102 | .ctrl = bio_ctrl, | ||
| 103 | .create = bio_new, | ||
| 104 | .destroy = bio_free | ||
| 105 | }; | ||
| 106 | |||
| 107 | BIO_METHOD * | ||
| 108 | BIO_s_bio(void) | ||
| 109 | { | ||
| 110 | return &methods_biop; | ||
| 111 | } | ||
| 112 | |||
| 113 | struct bio_bio_st { | ||
| 114 | BIO *peer; /* NULL if buf == NULL. | ||
| 115 | * If peer != NULL, then peer->ptr is also a bio_bio_st, | ||
| 116 | * and its "peer" member points back to us. | ||
| 117 | * peer != NULL iff init != 0 in the BIO. */ | ||
| 118 | |||
| 119 | /* This is for what we write (i.e. reading uses peer's struct): */ | ||
| 120 | int closed; /* valid iff peer != NULL */ | ||
| 121 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ | ||
| 122 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ | ||
| 123 | size_t size; | ||
| 124 | char *buf; /* "size" elements (if != NULL) */ | ||
| 125 | |||
| 126 | size_t request; /* valid iff peer != NULL; 0 if len != 0, | ||
| 127 | * otherwise set by peer to number of bytes | ||
| 128 | * it (unsuccessfully) tried to read, | ||
| 129 | * never more than buffer space (size-len) warrants. */ | ||
| 130 | }; | ||
| 131 | |||
| 132 | static int | ||
| 133 | bio_new(BIO *bio) | ||
| 134 | { | ||
| 135 | struct bio_bio_st *b; | ||
| 136 | |||
| 137 | b = malloc(sizeof *b); | ||
| 138 | if (b == NULL) | ||
| 139 | return 0; | ||
| 140 | |||
| 141 | b->peer = NULL; | ||
| 142 | b->size = 17 * 1024; /* enough for one TLS record (just a default) */ | ||
| 143 | b->buf = NULL; | ||
| 144 | |||
| 145 | bio->ptr = b; | ||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | static int | ||
| 150 | bio_free(BIO *bio) | ||
| 151 | { | ||
| 152 | struct bio_bio_st *b; | ||
| 153 | |||
| 154 | if (bio == NULL) | ||
| 155 | return 0; | ||
| 156 | b = bio->ptr; | ||
| 157 | |||
| 158 | assert(b != NULL); | ||
| 159 | |||
| 160 | if (b->peer) | ||
| 161 | bio_destroy_pair(bio); | ||
| 162 | |||
| 163 | free(b->buf); | ||
| 164 | free(b); | ||
| 165 | return 1; | ||
| 166 | } | ||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | static int | ||
| 171 | bio_read(BIO *bio, char *buf, int size_) | ||
| 172 | { | ||
| 173 | size_t size = size_; | ||
| 174 | size_t rest; | ||
| 175 | struct bio_bio_st *b, *peer_b; | ||
| 176 | |||
| 177 | BIO_clear_retry_flags(bio); | ||
| 178 | |||
| 179 | if (!bio->init) | ||
| 180 | return 0; | ||
| 181 | |||
| 182 | b = bio->ptr; | ||
| 183 | assert(b != NULL); | ||
| 184 | assert(b->peer != NULL); | ||
| 185 | peer_b = b->peer->ptr; | ||
| 186 | assert(peer_b != NULL); | ||
| 187 | assert(peer_b->buf != NULL); | ||
| 188 | |||
| 189 | peer_b->request = 0; /* will be set in "retry_read" situation */ | ||
| 190 | |||
| 191 | if (buf == NULL || size == 0) | ||
| 192 | return 0; | ||
| 193 | |||
| 194 | if (peer_b->len == 0) { | ||
| 195 | if (peer_b->closed) | ||
| 196 | return 0; /* writer has closed, and no data is left */ | ||
| 197 | else { | ||
| 198 | BIO_set_retry_read(bio); /* buffer is empty */ | ||
| 199 | if (size <= peer_b->size) | ||
| 200 | peer_b->request = size; | ||
| 201 | else | ||
| 202 | /* don't ask for more than the peer can | ||
| 203 | * deliver in one write */ | ||
| 204 | peer_b->request = peer_b->size; | ||
| 205 | return -1; | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | /* we can read */ | ||
| 210 | if (peer_b->len < size) | ||
| 211 | size = peer_b->len; | ||
| 212 | |||
| 213 | /* now read "size" bytes */ | ||
| 214 | |||
| 215 | rest = size; | ||
| 216 | |||
| 217 | assert(rest > 0); | ||
| 218 | do /* one or two iterations */ | ||
| 219 | { | ||
| 220 | size_t chunk; | ||
| 221 | |||
| 222 | assert(rest <= peer_b->len); | ||
| 223 | if (peer_b->offset + rest <= peer_b->size) | ||
| 224 | chunk = rest; | ||
| 225 | else | ||
| 226 | /* wrap around ring buffer */ | ||
| 227 | chunk = peer_b->size - peer_b->offset; | ||
| 228 | assert(peer_b->offset + chunk <= peer_b->size); | ||
| 229 | |||
| 230 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); | ||
| 231 | |||
| 232 | peer_b->len -= chunk; | ||
| 233 | if (peer_b->len) { | ||
| 234 | peer_b->offset += chunk; | ||
| 235 | assert(peer_b->offset <= peer_b->size); | ||
| 236 | if (peer_b->offset == peer_b->size) | ||
| 237 | peer_b->offset = 0; | ||
| 238 | buf += chunk; | ||
| 239 | } else { | ||
| 240 | /* buffer now empty, no need to advance "buf" */ | ||
| 241 | assert(chunk == rest); | ||
| 242 | peer_b->offset = 0; | ||
| 243 | } | ||
| 244 | rest -= chunk; | ||
| 245 | } while (rest); | ||
| 246 | |||
| 247 | return size; | ||
| 248 | } | ||
| 249 | |||
| 250 | /* non-copying interface: provide pointer to available data in buffer | ||
| 251 | * bio_nread0: return number of available bytes | ||
| 252 | * bio_nread: also advance index | ||
| 253 | * (example usage: bio_nread0(), read from buffer, bio_nread() | ||
| 254 | * or just bio_nread(), read from buffer) | ||
| 255 | */ | ||
| 256 | /* WARNING: The non-copying interface is largely untested as of yet | ||
| 257 | * and may contain bugs. */ | ||
| 258 | static ssize_t | ||
| 259 | bio_nread0(BIO *bio, char **buf) | ||
| 260 | { | ||
| 261 | struct bio_bio_st *b, *peer_b; | ||
| 262 | ssize_t num; | ||
| 263 | |||
| 264 | BIO_clear_retry_flags(bio); | ||
| 265 | |||
| 266 | if (!bio->init) | ||
| 267 | return 0; | ||
| 268 | |||
| 269 | b = bio->ptr; | ||
| 270 | assert(b != NULL); | ||
| 271 | assert(b->peer != NULL); | ||
| 272 | peer_b = b->peer->ptr; | ||
| 273 | assert(peer_b != NULL); | ||
| 274 | assert(peer_b->buf != NULL); | ||
| 275 | |||
| 276 | peer_b->request = 0; | ||
| 277 | |||
| 278 | if (peer_b->len == 0) { | ||
| 279 | char dummy; | ||
| 280 | |||
| 281 | /* avoid code duplication -- nothing available for reading */ | ||
| 282 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ | ||
| 283 | } | ||
| 284 | |||
| 285 | num = peer_b->len; | ||
| 286 | if (peer_b->size < peer_b->offset + num) | ||
| 287 | /* no ring buffer wrap-around for non-copying interface */ | ||
| 288 | num = peer_b->size - peer_b->offset; | ||
| 289 | assert(num > 0); | ||
| 290 | |||
| 291 | if (buf != NULL) | ||
| 292 | *buf = peer_b->buf + peer_b->offset; | ||
| 293 | return num; | ||
| 294 | } | ||
| 295 | |||
| 296 | static ssize_t | ||
| 297 | bio_nread(BIO *bio, char **buf, size_t num_) | ||
| 298 | { | ||
| 299 | struct bio_bio_st *b, *peer_b; | ||
| 300 | ssize_t num, available; | ||
| 301 | |||
| 302 | if (num_ > SSIZE_MAX) | ||
| 303 | num = SSIZE_MAX; | ||
| 304 | else | ||
| 305 | num = (ssize_t)num_; | ||
| 306 | |||
| 307 | available = bio_nread0(bio, buf); | ||
| 308 | if (num > available) | ||
| 309 | num = available; | ||
| 310 | if (num <= 0) | ||
| 311 | return num; | ||
| 312 | |||
| 313 | b = bio->ptr; | ||
| 314 | peer_b = b->peer->ptr; | ||
| 315 | |||
| 316 | peer_b->len -= num; | ||
| 317 | if (peer_b->len) { | ||
| 318 | peer_b->offset += num; | ||
| 319 | assert(peer_b->offset <= peer_b->size); | ||
| 320 | if (peer_b->offset == peer_b->size) | ||
| 321 | peer_b->offset = 0; | ||
| 322 | } else | ||
| 323 | peer_b->offset = 0; | ||
| 324 | |||
| 325 | return num; | ||
| 326 | } | ||
| 327 | |||
| 328 | |||
| 329 | static int | ||
| 330 | bio_write(BIO *bio, const char *buf, int num_) | ||
| 331 | { | ||
| 332 | size_t num = num_; | ||
| 333 | size_t rest; | ||
| 334 | struct bio_bio_st *b; | ||
| 335 | |||
| 336 | BIO_clear_retry_flags(bio); | ||
| 337 | |||
| 338 | if (!bio->init || buf == NULL || num == 0) | ||
| 339 | return 0; | ||
| 340 | |||
| 341 | b = bio->ptr; | ||
| 342 | |||
| 343 | assert(b != NULL); | ||
| 344 | assert(b->peer != NULL); | ||
| 345 | assert(b->buf != NULL); | ||
| 346 | |||
| 347 | b->request = 0; | ||
| 348 | if (b->closed) { | ||
| 349 | /* we already closed */ | ||
| 350 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); | ||
| 351 | return -1; | ||
| 352 | } | ||
| 353 | |||
| 354 | assert(b->len <= b->size); | ||
| 355 | |||
| 356 | if (b->len == b->size) { | ||
| 357 | BIO_set_retry_write(bio); /* buffer is full */ | ||
| 358 | return -1; | ||
| 359 | } | ||
| 360 | |||
| 361 | /* we can write */ | ||
| 362 | if (num > b->size - b->len) | ||
| 363 | num = b->size - b->len; | ||
| 364 | |||
| 365 | /* now write "num" bytes */ | ||
| 366 | |||
| 367 | rest = num; | ||
| 368 | |||
| 369 | assert(rest > 0); | ||
| 370 | do /* one or two iterations */ | ||
| 371 | { | ||
| 372 | size_t write_offset; | ||
| 373 | size_t chunk; | ||
| 374 | |||
| 375 | assert(b->len + rest <= b->size); | ||
| 376 | |||
| 377 | write_offset = b->offset + b->len; | ||
| 378 | if (write_offset >= b->size) | ||
| 379 | write_offset -= b->size; | ||
| 380 | /* b->buf[write_offset] is the first byte we can write to. */ | ||
| 381 | |||
| 382 | if (write_offset + rest <= b->size) | ||
| 383 | chunk = rest; | ||
| 384 | else | ||
| 385 | /* wrap around ring buffer */ | ||
| 386 | chunk = b->size - write_offset; | ||
| 387 | |||
| 388 | memcpy(b->buf + write_offset, buf, chunk); | ||
| 389 | |||
| 390 | b->len += chunk; | ||
| 391 | |||
| 392 | assert(b->len <= b->size); | ||
| 393 | |||
| 394 | rest -= chunk; | ||
| 395 | buf += chunk; | ||
| 396 | } while (rest); | ||
| 397 | |||
| 398 | return num; | ||
| 399 | } | ||
| 400 | |||
| 401 | /* non-copying interface: provide pointer to region to write to | ||
| 402 | * bio_nwrite0: check how much space is available | ||
| 403 | * bio_nwrite: also increase length | ||
| 404 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | ||
| 405 | * or just bio_nwrite(), write to buffer) | ||
| 406 | */ | ||
| 407 | static ssize_t | ||
| 408 | bio_nwrite0(BIO *bio, char **buf) | ||
| 409 | { | ||
| 410 | struct bio_bio_st *b; | ||
| 411 | size_t num; | ||
| 412 | size_t write_offset; | ||
| 413 | |||
| 414 | BIO_clear_retry_flags(bio); | ||
| 415 | |||
| 416 | if (!bio->init) | ||
| 417 | return 0; | ||
| 418 | |||
| 419 | b = bio->ptr; | ||
| 420 | |||
| 421 | assert(b != NULL); | ||
| 422 | assert(b->peer != NULL); | ||
| 423 | assert(b->buf != NULL); | ||
| 424 | |||
| 425 | b->request = 0; | ||
| 426 | if (b->closed) { | ||
| 427 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); | ||
| 428 | return -1; | ||
| 429 | } | ||
| 430 | |||
| 431 | assert(b->len <= b->size); | ||
| 432 | |||
| 433 | if (b->len == b->size) { | ||
| 434 | BIO_set_retry_write(bio); | ||
| 435 | return -1; | ||
| 436 | } | ||
| 437 | |||
| 438 | num = b->size - b->len; | ||
| 439 | write_offset = b->offset + b->len; | ||
| 440 | if (write_offset >= b->size) | ||
| 441 | write_offset -= b->size; | ||
| 442 | if (write_offset + num > b->size) | ||
| 443 | /* no ring buffer wrap-around for non-copying interface | ||
| 444 | * (to fulfil the promise by BIO_ctrl_get_write_guarantee, | ||
| 445 | * BIO_nwrite may have to be called twice) */ | ||
| 446 | num = b->size - write_offset; | ||
| 447 | |||
| 448 | if (buf != NULL) | ||
| 449 | *buf = b->buf + write_offset; | ||
| 450 | assert(write_offset + num <= b->size); | ||
| 451 | |||
| 452 | return num; | ||
| 453 | } | ||
| 454 | |||
| 455 | static ssize_t | ||
| 456 | bio_nwrite(BIO *bio, char **buf, size_t num_) | ||
| 457 | { | ||
| 458 | struct bio_bio_st *b; | ||
| 459 | ssize_t num, space; | ||
| 460 | |||
| 461 | if (num_ > SSIZE_MAX) | ||
| 462 | num = SSIZE_MAX; | ||
| 463 | else | ||
| 464 | num = (ssize_t)num_; | ||
| 465 | |||
| 466 | space = bio_nwrite0(bio, buf); | ||
| 467 | if (num > space) | ||
| 468 | num = space; | ||
| 469 | if (num <= 0) | ||
| 470 | return num; | ||
| 471 | b = bio->ptr; | ||
| 472 | assert(b != NULL); | ||
| 473 | b->len += num; | ||
| 474 | assert(b->len <= b->size); | ||
| 475 | |||
| 476 | return num; | ||
| 477 | } | ||
| 478 | |||
| 479 | |||
| 480 | static long | ||
| 481 | bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | ||
| 482 | { | ||
| 483 | long ret; | ||
| 484 | struct bio_bio_st *b = bio->ptr; | ||
| 485 | |||
| 486 | assert(b != NULL); | ||
| 487 | |||
| 488 | switch (cmd) { | ||
| 489 | /* specific CTRL codes */ | ||
| 490 | |||
| 491 | case BIO_C_SET_WRITE_BUF_SIZE: | ||
| 492 | if (b->peer) { | ||
| 493 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); | ||
| 494 | ret = 0; | ||
| 495 | } else if (num == 0) { | ||
| 496 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); | ||
| 497 | ret = 0; | ||
| 498 | } else { | ||
| 499 | size_t new_size = num; | ||
| 500 | |||
| 501 | if (b->size != new_size) { | ||
| 502 | if (b->buf) { | ||
| 503 | free(b->buf); | ||
| 504 | b->buf = NULL; | ||
| 505 | } | ||
| 506 | b->size = new_size; | ||
| 507 | } | ||
| 508 | ret = 1; | ||
| 509 | } | ||
| 510 | break; | ||
| 511 | |||
| 512 | case BIO_C_GET_WRITE_BUF_SIZE: | ||
| 513 | ret = (long) b->size; | ||
| 514 | break; | ||
| 515 | |||
| 516 | case BIO_C_MAKE_BIO_PAIR: | ||
| 517 | { | ||
| 518 | BIO *other_bio = ptr; | ||
| 519 | |||
| 520 | if (bio_make_pair(bio, other_bio)) | ||
| 521 | ret = 1; | ||
| 522 | else | ||
| 523 | ret = 0; | ||
| 524 | } | ||
| 525 | break; | ||
| 526 | |||
| 527 | case BIO_C_DESTROY_BIO_PAIR: | ||
| 528 | /* Affects both BIOs in the pair -- call just once! | ||
| 529 | * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ | ||
| 530 | bio_destroy_pair(bio); | ||
| 531 | ret = 1; | ||
| 532 | break; | ||
| 533 | |||
| 534 | case BIO_C_GET_WRITE_GUARANTEE: | ||
| 535 | /* How many bytes can the caller feed to the next write | ||
| 536 | * without having to keep any? */ | ||
| 537 | if (b->peer == NULL || b->closed) | ||
| 538 | ret = 0; | ||
| 539 | else | ||
| 540 | ret = (long) b->size - b->len; | ||
| 541 | break; | ||
| 542 | |||
| 543 | case BIO_C_GET_READ_REQUEST: | ||
| 544 | /* If the peer unsuccessfully tried to read, how many bytes | ||
| 545 | * were requested? (As with BIO_CTRL_PENDING, that number | ||
| 546 | * can usually be treated as boolean.) */ | ||
| 547 | ret = (long) b->request; | ||
| 548 | break; | ||
| 549 | |||
| 550 | case BIO_C_RESET_READ_REQUEST: | ||
| 551 | /* Reset request. (Can be useful after read attempts | ||
| 552 | * at the other side that are meant to be non-blocking, | ||
| 553 | * e.g. when probing SSL_read to see if any data is | ||
| 554 | * available.) */ | ||
| 555 | b->request = 0; | ||
| 556 | ret = 1; | ||
| 557 | break; | ||
| 558 | |||
| 559 | case BIO_C_SHUTDOWN_WR: | ||
| 560 | /* similar to shutdown(..., SHUT_WR) */ | ||
| 561 | b->closed = 1; | ||
| 562 | ret = 1; | ||
| 563 | break; | ||
| 564 | |||
| 565 | case BIO_C_NREAD0: | ||
| 566 | /* prepare for non-copying read */ | ||
| 567 | ret = (long) bio_nread0(bio, ptr); | ||
| 568 | break; | ||
| 569 | |||
| 570 | case BIO_C_NREAD: | ||
| 571 | /* non-copying read */ | ||
| 572 | ret = (long) bio_nread(bio, ptr, (size_t) num); | ||
| 573 | break; | ||
| 574 | |||
| 575 | case BIO_C_NWRITE0: | ||
| 576 | /* prepare for non-copying write */ | ||
| 577 | ret = (long) bio_nwrite0(bio, ptr); | ||
| 578 | break; | ||
| 579 | |||
| 580 | case BIO_C_NWRITE: | ||
| 581 | /* non-copying write */ | ||
| 582 | ret = (long) bio_nwrite(bio, ptr, (size_t) num); | ||
| 583 | break; | ||
| 584 | |||
| 585 | |||
| 586 | /* standard CTRL codes follow */ | ||
| 587 | |||
| 588 | case BIO_CTRL_RESET: | ||
| 589 | if (b->buf != NULL) { | ||
| 590 | b->len = 0; | ||
| 591 | b->offset = 0; | ||
| 592 | } | ||
| 593 | ret = 0; | ||
| 594 | break; | ||
| 595 | |||
| 596 | |||
| 597 | case BIO_CTRL_GET_CLOSE: | ||
| 598 | ret = bio->shutdown; | ||
| 599 | break; | ||
| 600 | |||
| 601 | case BIO_CTRL_SET_CLOSE: | ||
| 602 | bio->shutdown = (int) num; | ||
| 603 | ret = 1; | ||
| 604 | break; | ||
| 605 | |||
| 606 | case BIO_CTRL_PENDING: | ||
| 607 | if (b->peer != NULL) { | ||
| 608 | struct bio_bio_st *peer_b = b->peer->ptr; | ||
| 609 | |||
| 610 | ret = (long) peer_b->len; | ||
| 611 | } else | ||
| 612 | ret = 0; | ||
| 613 | break; | ||
| 614 | |||
| 615 | case BIO_CTRL_WPENDING: | ||
| 616 | if (b->buf != NULL) | ||
| 617 | ret = (long) b->len; | ||
| 618 | else | ||
| 619 | ret = 0; | ||
| 620 | break; | ||
| 621 | |||
| 622 | case BIO_CTRL_DUP: | ||
| 623 | /* See BIO_dup_chain for circumstances we have to expect. */ | ||
| 624 | { | ||
| 625 | BIO *other_bio = ptr; | ||
| 626 | struct bio_bio_st *other_b; | ||
| 627 | |||
| 628 | assert(other_bio != NULL); | ||
| 629 | other_b = other_bio->ptr; | ||
| 630 | assert(other_b != NULL); | ||
| 631 | |||
| 632 | assert(other_b->buf == NULL); /* other_bio is always fresh */ | ||
| 633 | |||
| 634 | other_b->size = b->size; | ||
| 635 | } | ||
| 636 | |||
| 637 | ret = 1; | ||
| 638 | break; | ||
| 639 | |||
| 640 | case BIO_CTRL_FLUSH: | ||
| 641 | ret = 1; | ||
| 642 | break; | ||
| 643 | |||
| 644 | case BIO_CTRL_EOF: | ||
| 645 | { | ||
| 646 | BIO *other_bio = ptr; | ||
| 647 | |||
| 648 | if (other_bio) { | ||
| 649 | struct bio_bio_st *other_b = other_bio->ptr; | ||
| 650 | |||
| 651 | assert(other_b != NULL); | ||
| 652 | ret = other_b->len == 0 && other_b->closed; | ||
| 653 | } else | ||
| 654 | ret = 1; | ||
| 655 | } | ||
| 656 | break; | ||
| 657 | |||
| 658 | default: | ||
| 659 | ret = 0; | ||
| 660 | } | ||
| 661 | return ret; | ||
| 662 | } | ||
| 663 | |||
| 664 | static int | ||
| 665 | bio_puts(BIO *bio, const char *str) | ||
| 666 | { | ||
| 667 | return bio_write(bio, str, strlen(str)); | ||
| 668 | } | ||
| 669 | |||
| 670 | |||
| 671 | static int | ||
| 672 | bio_make_pair(BIO *bio1, BIO *bio2) | ||
| 673 | { | ||
| 674 | struct bio_bio_st *b1, *b2; | ||
| 675 | |||
| 676 | assert(bio1 != NULL); | ||
| 677 | assert(bio2 != NULL); | ||
| 678 | |||
| 679 | b1 = bio1->ptr; | ||
| 680 | b2 = bio2->ptr; | ||
| 681 | |||
| 682 | if (b1->peer != NULL || b2->peer != NULL) { | ||
| 683 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); | ||
| 684 | return 0; | ||
| 685 | } | ||
| 686 | |||
| 687 | if (b1->buf == NULL) { | ||
| 688 | b1->buf = malloc(b1->size); | ||
| 689 | if (b1->buf == NULL) { | ||
| 690 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | ||
| 691 | return 0; | ||
| 692 | } | ||
| 693 | b1->len = 0; | ||
| 694 | b1->offset = 0; | ||
| 695 | } | ||
| 696 | |||
| 697 | if (b2->buf == NULL) { | ||
| 698 | b2->buf = malloc(b2->size); | ||
| 699 | if (b2->buf == NULL) { | ||
| 700 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | ||
| 701 | return 0; | ||
| 702 | } | ||
| 703 | b2->len = 0; | ||
| 704 | b2->offset = 0; | ||
| 705 | } | ||
| 706 | |||
| 707 | b1->peer = bio2; | ||
| 708 | b1->closed = 0; | ||
| 709 | b1->request = 0; | ||
| 710 | b2->peer = bio1; | ||
| 711 | b2->closed = 0; | ||
| 712 | b2->request = 0; | ||
| 713 | |||
| 714 | bio1->init = 1; | ||
| 715 | bio2->init = 1; | ||
| 716 | |||
| 717 | return 1; | ||
| 718 | } | ||
| 719 | |||
| 720 | static void | ||
| 721 | bio_destroy_pair(BIO *bio) | ||
| 722 | { | ||
| 723 | struct bio_bio_st *b = bio->ptr; | ||
| 724 | |||
| 725 | if (b != NULL) { | ||
| 726 | BIO *peer_bio = b->peer; | ||
| 727 | |||
| 728 | if (peer_bio != NULL) { | ||
| 729 | struct bio_bio_st *peer_b = peer_bio->ptr; | ||
| 730 | |||
| 731 | assert(peer_b != NULL); | ||
| 732 | assert(peer_b->peer == bio); | ||
| 733 | |||
| 734 | peer_b->peer = NULL; | ||
| 735 | peer_bio->init = 0; | ||
| 736 | assert(peer_b->buf != NULL); | ||
| 737 | peer_b->len = 0; | ||
| 738 | peer_b->offset = 0; | ||
| 739 | |||
| 740 | b->peer = NULL; | ||
| 741 | bio->init = 0; | ||
| 742 | assert(b->buf != NULL); | ||
| 743 | b->len = 0; | ||
| 744 | b->offset = 0; | ||
| 745 | } | ||
| 746 | } | ||
| 747 | } | ||
| 748 | |||
| 749 | |||
| 750 | /* Exported convenience functions */ | ||
| 751 | int | ||
| 752 | BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, BIO **bio2_p, size_t writebuf2) | ||
| 753 | { | ||
| 754 | BIO *bio1 = NULL, *bio2 = NULL; | ||
| 755 | long r; | ||
| 756 | int ret = 0; | ||
| 757 | |||
| 758 | bio1 = BIO_new(BIO_s_bio()); | ||
| 759 | if (bio1 == NULL) | ||
| 760 | goto err; | ||
| 761 | bio2 = BIO_new(BIO_s_bio()); | ||
| 762 | if (bio2 == NULL) | ||
| 763 | goto err; | ||
| 764 | |||
| 765 | if (writebuf1) { | ||
| 766 | r = BIO_set_write_buf_size(bio1, writebuf1); | ||
| 767 | if (!r) | ||
| 768 | goto err; | ||
| 769 | } | ||
| 770 | if (writebuf2) { | ||
| 771 | r = BIO_set_write_buf_size(bio2, writebuf2); | ||
| 772 | if (!r) | ||
| 773 | goto err; | ||
| 774 | } | ||
| 775 | |||
| 776 | r = BIO_make_bio_pair(bio1, bio2); | ||
| 777 | if (!r) | ||
| 778 | goto err; | ||
| 779 | ret = 1; | ||
| 780 | |||
| 781 | err: | ||
| 782 | if (ret == 0) { | ||
| 783 | if (bio1) { | ||
| 784 | BIO_free(bio1); | ||
| 785 | bio1 = NULL; | ||
| 786 | } | ||
| 787 | if (bio2) { | ||
| 788 | BIO_free(bio2); | ||
| 789 | bio2 = NULL; | ||
| 790 | } | ||
| 791 | } | ||
| 792 | |||
| 793 | *bio1_p = bio1; | ||
| 794 | *bio2_p = bio2; | ||
| 795 | return ret; | ||
| 796 | } | ||
| 797 | |||
| 798 | size_t | ||
| 799 | BIO_ctrl_get_write_guarantee(BIO *bio) | ||
| 800 | { | ||
| 801 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); | ||
| 802 | } | ||
| 803 | |||
| 804 | size_t | ||
| 805 | BIO_ctrl_get_read_request(BIO *bio) | ||
| 806 | { | ||
| 807 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); | ||
| 808 | } | ||
| 809 | |||
| 810 | int | ||
| 811 | BIO_ctrl_reset_read_request(BIO *bio) | ||
| 812 | { | ||
| 813 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); | ||
| 814 | } | ||
| 815 | |||
| 816 | |||
| 817 | /* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now | ||
| 818 | * (conceivably some other BIOs could allow non-copying reads and writes too.) | ||
| 819 | */ | ||
| 820 | int | ||
| 821 | BIO_nread0(BIO *bio, char **buf) | ||
| 822 | { | ||
| 823 | long ret; | ||
| 824 | |||
| 825 | if (!bio->init) { | ||
| 826 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); | ||
| 827 | return -2; | ||
| 828 | } | ||
| 829 | |||
| 830 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); | ||
| 831 | if (ret > INT_MAX) | ||
| 832 | return INT_MAX; | ||
| 833 | else | ||
| 834 | return (int) ret; | ||
| 835 | } | ||
| 836 | |||
| 837 | int | ||
| 838 | BIO_nread(BIO *bio, char **buf, int num) | ||
| 839 | { | ||
| 840 | int ret; | ||
| 841 | |||
| 842 | if (!bio->init) { | ||
| 843 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); | ||
| 844 | return -2; | ||
| 845 | } | ||
| 846 | |||
| 847 | ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf); | ||
| 848 | if (ret > 0) | ||
| 849 | bio->num_read += ret; | ||
| 850 | return ret; | ||
| 851 | } | ||
| 852 | |||
| 853 | int | ||
| 854 | BIO_nwrite0(BIO *bio, char **buf) | ||
| 855 | { | ||
| 856 | long ret; | ||
| 857 | |||
| 858 | if (!bio->init) { | ||
| 859 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); | ||
| 860 | return -2; | ||
| 861 | } | ||
| 862 | |||
| 863 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); | ||
| 864 | if (ret > INT_MAX) | ||
| 865 | return INT_MAX; | ||
| 866 | else | ||
| 867 | return (int) ret; | ||
| 868 | } | ||
| 869 | |||
| 870 | int | ||
| 871 | BIO_nwrite(BIO *bio, char **buf, int num) | ||
| 872 | { | ||
| 873 | int ret; | ||
| 874 | |||
| 875 | if (!bio->init) { | ||
| 876 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); | ||
| 877 | return -2; | ||
| 878 | } | ||
| 879 | |||
| 880 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); | ||
| 881 | if (ret > 0) | ||
| 882 | bio->num_write += ret; | ||
| 883 | return ret; | ||
| 884 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c deleted file mode 100644 index 7f50936677..0000000000 --- a/src/lib/libcrypto/bio/bss_conn.c +++ /dev/null | |||
| @@ -1,604 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_conn.c,v 1.32 2014/11/26 05:37:26 bcook Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <sys/socket.h> | ||
| 60 | |||
| 61 | #include <netinet/in.h> | ||
| 62 | |||
| 63 | #include <errno.h> | ||
| 64 | #include <netdb.h> | ||
| 65 | #include <stdio.h> | ||
| 66 | #include <string.h> | ||
| 67 | #include <unistd.h> | ||
| 68 | |||
| 69 | #include <openssl/bio.h> | ||
| 70 | #include <openssl/buffer.h> | ||
| 71 | #include <openssl/err.h> | ||
| 72 | |||
| 73 | #define SOCKET_PROTOCOL IPPROTO_TCP | ||
| 74 | |||
| 75 | typedef struct bio_connect_st { | ||
| 76 | int state; | ||
| 77 | |||
| 78 | char *param_hostname; | ||
| 79 | char *param_port; | ||
| 80 | int nbio; | ||
| 81 | |||
| 82 | unsigned char ip[4]; | ||
| 83 | unsigned short port; | ||
| 84 | |||
| 85 | struct sockaddr_in them; | ||
| 86 | |||
| 87 | /* int socket; this will be kept in bio->num so that it is | ||
| 88 | * compatible with the bss_sock bio */ | ||
| 89 | |||
| 90 | /* called when the connection is initially made | ||
| 91 | * callback(BIO,state,ret); The callback should return | ||
| 92 | * 'ret'. state is for compatibility with the ssl info_callback */ | ||
| 93 | int (*info_callback)(const BIO *bio, int state, int ret); | ||
| 94 | } BIO_CONNECT; | ||
| 95 | |||
| 96 | static int conn_write(BIO *h, const char *buf, int num); | ||
| 97 | static int conn_read(BIO *h, char *buf, int size); | ||
| 98 | static int conn_puts(BIO *h, const char *str); | ||
| 99 | static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 100 | static int conn_new(BIO *h); | ||
| 101 | static int conn_free(BIO *data); | ||
| 102 | static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *); | ||
| 103 | |||
| 104 | static int conn_state(BIO *b, BIO_CONNECT *c); | ||
| 105 | static void conn_close_socket(BIO *data); | ||
| 106 | BIO_CONNECT *BIO_CONNECT_new(void); | ||
| 107 | void BIO_CONNECT_free(BIO_CONNECT *a); | ||
| 108 | |||
| 109 | static BIO_METHOD methods_connectp = { | ||
| 110 | .type = BIO_TYPE_CONNECT, | ||
| 111 | .name = "socket connect", | ||
| 112 | .bwrite = conn_write, | ||
| 113 | .bread = conn_read, | ||
| 114 | .bputs = conn_puts, | ||
| 115 | .ctrl = conn_ctrl, | ||
| 116 | .create = conn_new, | ||
| 117 | .destroy = conn_free, | ||
| 118 | .callback_ctrl = conn_callback_ctrl | ||
| 119 | }; | ||
| 120 | |||
| 121 | static int | ||
| 122 | conn_state(BIO *b, BIO_CONNECT *c) | ||
| 123 | { | ||
| 124 | int ret = -1, i; | ||
| 125 | unsigned long l; | ||
| 126 | char *p, *q; | ||
| 127 | int (*cb)(const BIO *, int, int) = NULL; | ||
| 128 | |||
| 129 | if (c->info_callback != NULL) | ||
| 130 | cb = c->info_callback; | ||
| 131 | |||
| 132 | for (;;) { | ||
| 133 | switch (c->state) { | ||
| 134 | case BIO_CONN_S_BEFORE: | ||
| 135 | p = c->param_hostname; | ||
| 136 | if (p == NULL) { | ||
| 137 | BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED); | ||
| 138 | goto exit_loop; | ||
| 139 | } | ||
| 140 | for (; *p != '\0'; p++) { | ||
| 141 | if ((*p == ':') || (*p == '/')) | ||
| 142 | break; | ||
| 143 | } | ||
| 144 | |||
| 145 | i= *p; | ||
| 146 | if ((i == ':') || (i == '/')) { | ||
| 147 | *(p++) = '\0'; | ||
| 148 | if (i == ':') { | ||
| 149 | for (q = p; *q; q++) | ||
| 150 | if (*q == '/') { | ||
| 151 | *q = '\0'; | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | free(c->param_port); | ||
| 155 | c->param_port = strdup(p); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | if (c->param_port == NULL) { | ||
| 160 | BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED); | ||
| 161 | ERR_asprintf_error_data("host=%s", | ||
| 162 | c->param_hostname); | ||
| 163 | goto exit_loop; | ||
| 164 | } | ||
| 165 | c->state = BIO_CONN_S_GET_IP; | ||
| 166 | break; | ||
| 167 | |||
| 168 | case BIO_CONN_S_GET_IP: | ||
| 169 | if (BIO_get_host_ip(c->param_hostname, &(c->ip[0])) <= 0) | ||
| 170 | goto exit_loop; | ||
| 171 | c->state = BIO_CONN_S_GET_PORT; | ||
| 172 | break; | ||
| 173 | |||
| 174 | case BIO_CONN_S_GET_PORT: | ||
| 175 | if (c->param_port == NULL) { | ||
| 176 | /* abort(); */ | ||
| 177 | goto exit_loop; | ||
| 178 | } else if (BIO_get_port(c->param_port, &c->port) <= 0) | ||
| 179 | goto exit_loop; | ||
| 180 | c->state = BIO_CONN_S_CREATE_SOCKET; | ||
| 181 | break; | ||
| 182 | |||
| 183 | case BIO_CONN_S_CREATE_SOCKET: | ||
| 184 | /* now setup address */ | ||
| 185 | memset((char *)&c->them, 0, sizeof(c->them)); | ||
| 186 | c->them.sin_family = AF_INET; | ||
| 187 | c->them.sin_port = htons((unsigned short)c->port); | ||
| 188 | l = (unsigned long) | ||
| 189 | ((unsigned long)c->ip[0] << 24L)| | ||
| 190 | ((unsigned long)c->ip[1] << 16L)| | ||
| 191 | ((unsigned long)c->ip[2] << 8L)| | ||
| 192 | ((unsigned long)c->ip[3]); | ||
| 193 | c->them.sin_addr.s_addr = htonl(l); | ||
| 194 | c->state = BIO_CONN_S_CREATE_SOCKET; | ||
| 195 | |||
| 196 | ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL); | ||
| 197 | if (ret == -1) { | ||
| 198 | SYSerr(SYS_F_SOCKET, errno); | ||
| 199 | ERR_asprintf_error_data("host=%s:%s", | ||
| 200 | c->param_hostname, c->param_port); | ||
| 201 | BIOerr(BIO_F_CONN_STATE, | ||
| 202 | BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
| 203 | goto exit_loop; | ||
| 204 | } | ||
| 205 | b->num = ret; | ||
| 206 | c->state = BIO_CONN_S_NBIO; | ||
| 207 | break; | ||
| 208 | |||
| 209 | case BIO_CONN_S_NBIO: | ||
| 210 | if (c->nbio) { | ||
| 211 | if (!BIO_socket_nbio(b->num, 1)) { | ||
| 212 | BIOerr(BIO_F_CONN_STATE, | ||
| 213 | BIO_R_ERROR_SETTING_NBIO); | ||
| 214 | ERR_asprintf_error_data("host=%s:%s", | ||
| 215 | c->param_hostname, c->param_port); | ||
| 216 | goto exit_loop; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | c->state = BIO_CONN_S_CONNECT; | ||
| 220 | |||
| 221 | #if defined(SO_KEEPALIVE) | ||
| 222 | i = 1; | ||
| 223 | i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i)); | ||
| 224 | if (i < 0) { | ||
| 225 | SYSerr(SYS_F_SOCKET, errno); | ||
| 226 | ERR_asprintf_error_data("host=%s:%s", | ||
| 227 | c->param_hostname, c->param_port); | ||
| 228 | BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE); | ||
| 229 | goto exit_loop; | ||
| 230 | } | ||
| 231 | #endif | ||
| 232 | break; | ||
| 233 | |||
| 234 | case BIO_CONN_S_CONNECT: | ||
| 235 | BIO_clear_retry_flags(b); | ||
| 236 | ret = connect(b->num, | ||
| 237 | (struct sockaddr *)&c->them, | ||
| 238 | sizeof(c->them)); | ||
| 239 | b->retry_reason = 0; | ||
| 240 | if (ret < 0) { | ||
| 241 | if (BIO_sock_should_retry(ret)) { | ||
| 242 | BIO_set_retry_special(b); | ||
| 243 | c->state = BIO_CONN_S_BLOCKED_CONNECT; | ||
| 244 | b->retry_reason = BIO_RR_CONNECT; | ||
| 245 | } else { | ||
| 246 | SYSerr(SYS_F_CONNECT, errno); | ||
| 247 | ERR_asprintf_error_data("host=%s:%s", | ||
| 248 | c->param_hostname, c->param_port); | ||
| 249 | BIOerr(BIO_F_CONN_STATE, | ||
| 250 | BIO_R_CONNECT_ERROR); | ||
| 251 | } | ||
| 252 | goto exit_loop; | ||
| 253 | } else | ||
| 254 | c->state = BIO_CONN_S_OK; | ||
| 255 | break; | ||
| 256 | |||
| 257 | case BIO_CONN_S_BLOCKED_CONNECT: | ||
| 258 | i = BIO_sock_error(b->num); | ||
| 259 | if (i) { | ||
| 260 | BIO_clear_retry_flags(b); | ||
| 261 | SYSerr(SYS_F_CONNECT, i); | ||
| 262 | ERR_asprintf_error_data("host=%s:%s", | ||
| 263 | c->param_hostname, c->param_port); | ||
| 264 | BIOerr(BIO_F_CONN_STATE, | ||
| 265 | BIO_R_NBIO_CONNECT_ERROR); | ||
| 266 | ret = 0; | ||
| 267 | goto exit_loop; | ||
| 268 | } else | ||
| 269 | c->state = BIO_CONN_S_OK; | ||
| 270 | break; | ||
| 271 | |||
| 272 | case BIO_CONN_S_OK: | ||
| 273 | ret = 1; | ||
| 274 | goto exit_loop; | ||
| 275 | default: | ||
| 276 | /* abort(); */ | ||
| 277 | goto exit_loop; | ||
| 278 | } | ||
| 279 | |||
| 280 | if (cb != NULL) { | ||
| 281 | if (!(ret = cb((BIO *)b, c->state, ret))) | ||
| 282 | goto end; | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | /* Loop does not exit */ | ||
| 287 | exit_loop: | ||
| 288 | if (cb != NULL) | ||
| 289 | ret = cb((BIO *)b, c->state, ret); | ||
| 290 | end: | ||
| 291 | return (ret); | ||
| 292 | } | ||
| 293 | |||
| 294 | BIO_CONNECT * | ||
| 295 | BIO_CONNECT_new(void) | ||
| 296 | { | ||
| 297 | BIO_CONNECT *ret; | ||
| 298 | |||
| 299 | if ((ret = malloc(sizeof(BIO_CONNECT))) == NULL) | ||
| 300 | return (NULL); | ||
| 301 | ret->state = BIO_CONN_S_BEFORE; | ||
| 302 | ret->param_hostname = NULL; | ||
| 303 | ret->param_port = NULL; | ||
| 304 | ret->info_callback = NULL; | ||
| 305 | ret->nbio = 0; | ||
| 306 | ret->ip[0] = 0; | ||
| 307 | ret->ip[1] = 0; | ||
| 308 | ret->ip[2] = 0; | ||
| 309 | ret->ip[3] = 0; | ||
| 310 | ret->port = 0; | ||
| 311 | memset((char *)&ret->them, 0, sizeof(ret->them)); | ||
| 312 | return (ret); | ||
| 313 | } | ||
| 314 | |||
| 315 | void | ||
| 316 | BIO_CONNECT_free(BIO_CONNECT *a) | ||
| 317 | { | ||
| 318 | if (a == NULL) | ||
| 319 | return; | ||
| 320 | |||
| 321 | free(a->param_hostname); | ||
| 322 | free(a->param_port); | ||
| 323 | free(a); | ||
| 324 | } | ||
| 325 | |||
| 326 | BIO_METHOD * | ||
| 327 | BIO_s_connect(void) | ||
| 328 | { | ||
| 329 | return (&methods_connectp); | ||
| 330 | } | ||
| 331 | |||
| 332 | static int | ||
| 333 | conn_new(BIO *bi) | ||
| 334 | { | ||
| 335 | bi->init = 0; | ||
| 336 | bi->num = -1; | ||
| 337 | bi->flags = 0; | ||
| 338 | if ((bi->ptr = (char *)BIO_CONNECT_new()) == NULL) | ||
| 339 | return (0); | ||
| 340 | else | ||
| 341 | return (1); | ||
| 342 | } | ||
| 343 | |||
| 344 | static void | ||
| 345 | conn_close_socket(BIO *bio) | ||
| 346 | { | ||
| 347 | BIO_CONNECT *c; | ||
| 348 | |||
| 349 | c = (BIO_CONNECT *)bio->ptr; | ||
| 350 | if (bio->num != -1) { | ||
| 351 | /* Only do a shutdown if things were established */ | ||
| 352 | if (c->state == BIO_CONN_S_OK) | ||
| 353 | shutdown(bio->num, SHUT_RDWR); | ||
| 354 | close(bio->num); | ||
| 355 | bio->num = -1; | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | static int | ||
| 360 | conn_free(BIO *a) | ||
| 361 | { | ||
| 362 | BIO_CONNECT *data; | ||
| 363 | |||
| 364 | if (a == NULL) | ||
| 365 | return (0); | ||
| 366 | data = (BIO_CONNECT *)a->ptr; | ||
| 367 | |||
| 368 | if (a->shutdown) { | ||
| 369 | conn_close_socket(a); | ||
| 370 | BIO_CONNECT_free(data); | ||
| 371 | a->ptr = NULL; | ||
| 372 | a->flags = 0; | ||
| 373 | a->init = 0; | ||
| 374 | } | ||
| 375 | return (1); | ||
| 376 | } | ||
| 377 | |||
| 378 | static int | ||
| 379 | conn_read(BIO *b, char *out, int outl) | ||
| 380 | { | ||
| 381 | int ret = 0; | ||
| 382 | BIO_CONNECT *data; | ||
| 383 | |||
| 384 | data = (BIO_CONNECT *)b->ptr; | ||
| 385 | if (data->state != BIO_CONN_S_OK) { | ||
| 386 | ret = conn_state(b, data); | ||
| 387 | if (ret <= 0) | ||
| 388 | return (ret); | ||
| 389 | } | ||
| 390 | |||
| 391 | if (out != NULL) { | ||
| 392 | errno = 0; | ||
| 393 | ret = read(b->num, out, outl); | ||
| 394 | BIO_clear_retry_flags(b); | ||
| 395 | if (ret <= 0) { | ||
| 396 | if (BIO_sock_should_retry(ret)) | ||
| 397 | BIO_set_retry_read(b); | ||
| 398 | } | ||
| 399 | } | ||
| 400 | return (ret); | ||
| 401 | } | ||
| 402 | |||
| 403 | static int | ||
| 404 | conn_write(BIO *b, const char *in, int inl) | ||
| 405 | { | ||
| 406 | int ret; | ||
| 407 | BIO_CONNECT *data; | ||
| 408 | |||
| 409 | data = (BIO_CONNECT *)b->ptr; | ||
| 410 | if (data->state != BIO_CONN_S_OK) { | ||
| 411 | ret = conn_state(b, data); | ||
| 412 | if (ret <= 0) | ||
| 413 | return (ret); | ||
| 414 | } | ||
| 415 | |||
| 416 | errno = 0; | ||
| 417 | ret = write(b->num, in, inl); | ||
| 418 | BIO_clear_retry_flags(b); | ||
| 419 | if (ret <= 0) { | ||
| 420 | if (BIO_sock_should_retry(ret)) | ||
| 421 | BIO_set_retry_write(b); | ||
| 422 | } | ||
| 423 | return (ret); | ||
| 424 | } | ||
| 425 | |||
| 426 | static long | ||
| 427 | conn_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 428 | { | ||
| 429 | BIO *dbio; | ||
| 430 | int *ip; | ||
| 431 | const char **pptr; | ||
| 432 | long ret = 1; | ||
| 433 | BIO_CONNECT *data; | ||
| 434 | |||
| 435 | data = (BIO_CONNECT *)b->ptr; | ||
| 436 | |||
| 437 | switch (cmd) { | ||
| 438 | case BIO_CTRL_RESET: | ||
| 439 | ret = 0; | ||
| 440 | data->state = BIO_CONN_S_BEFORE; | ||
| 441 | conn_close_socket(b); | ||
| 442 | b->flags = 0; | ||
| 443 | break; | ||
| 444 | case BIO_C_DO_STATE_MACHINE: | ||
| 445 | /* use this one to start the connection */ | ||
| 446 | if (data->state != BIO_CONN_S_OK) | ||
| 447 | ret = (long)conn_state(b, data); | ||
| 448 | else | ||
| 449 | ret = 1; | ||
| 450 | break; | ||
| 451 | case BIO_C_GET_CONNECT: | ||
| 452 | if (ptr != NULL) { | ||
| 453 | pptr = (const char **)ptr; | ||
| 454 | if (num == 0) { | ||
| 455 | *pptr = data->param_hostname; | ||
| 456 | |||
| 457 | } else if (num == 1) { | ||
| 458 | *pptr = data->param_port; | ||
| 459 | } else if (num == 2) { | ||
| 460 | *pptr = (char *)&(data->ip[0]); | ||
| 461 | } else if (num == 3) { | ||
| 462 | *((int *)ptr) = data->port; | ||
| 463 | } | ||
| 464 | if ((!b->init) || (ptr == NULL)) | ||
| 465 | *pptr = "not initialized"; | ||
| 466 | ret = 1; | ||
| 467 | } | ||
| 468 | break; | ||
| 469 | case BIO_C_SET_CONNECT: | ||
| 470 | if (ptr != NULL) { | ||
| 471 | b->init = 1; | ||
| 472 | if (num == 0) { | ||
| 473 | free(data->param_hostname); | ||
| 474 | data->param_hostname = strdup(ptr); | ||
| 475 | } else if (num == 1) { | ||
| 476 | free(data->param_port); | ||
| 477 | data->param_port = strdup(ptr); | ||
| 478 | } else if (num == 2) { | ||
| 479 | unsigned char *p = ptr; | ||
| 480 | free(data->param_hostname); | ||
| 481 | if (asprintf(&data->param_hostname, | ||
| 482 | "%u.%u.%u.%u", p[0], p[1], | ||
| 483 | p[2], p[3]) == -1) | ||
| 484 | data->param_hostname = NULL; | ||
| 485 | memcpy(&(data->ip[0]), ptr, 4); | ||
| 486 | } else if (num == 3) { | ||
| 487 | free(data->param_port); | ||
| 488 | data->port= *(int *)ptr; | ||
| 489 | if (asprintf(&data->param_port, "%d", | ||
| 490 | data->port) == -1) | ||
| 491 | data->param_port = NULL; | ||
| 492 | } | ||
| 493 | } | ||
| 494 | break; | ||
| 495 | case BIO_C_SET_NBIO: | ||
| 496 | data->nbio = (int)num; | ||
| 497 | break; | ||
| 498 | case BIO_C_GET_FD: | ||
| 499 | if (b->init) { | ||
| 500 | ip = (int *)ptr; | ||
| 501 | if (ip != NULL) | ||
| 502 | *ip = b->num; | ||
| 503 | ret = b->num; | ||
| 504 | } else | ||
| 505 | ret = -1; | ||
| 506 | break; | ||
| 507 | case BIO_CTRL_GET_CLOSE: | ||
| 508 | ret = b->shutdown; | ||
| 509 | break; | ||
| 510 | case BIO_CTRL_SET_CLOSE: | ||
| 511 | b->shutdown = (int)num; | ||
| 512 | break; | ||
| 513 | case BIO_CTRL_PENDING: | ||
| 514 | case BIO_CTRL_WPENDING: | ||
| 515 | ret = 0; | ||
| 516 | break; | ||
| 517 | case BIO_CTRL_FLUSH: | ||
| 518 | break; | ||
| 519 | case BIO_CTRL_DUP: | ||
| 520 | { | ||
| 521 | dbio = (BIO *)ptr; | ||
| 522 | if (data->param_port) | ||
| 523 | BIO_set_conn_port(dbio, data->param_port); | ||
| 524 | if (data->param_hostname) | ||
| 525 | BIO_set_conn_hostname(dbio, | ||
| 526 | data->param_hostname); | ||
| 527 | BIO_set_nbio(dbio, data->nbio); | ||
| 528 | /* FIXME: the cast of the function seems unlikely to be a good idea */ | ||
| 529 | (void)BIO_set_info_callback(dbio, | ||
| 530 | (bio_info_cb *)data->info_callback); | ||
| 531 | } | ||
| 532 | break; | ||
| 533 | case BIO_CTRL_SET_CALLBACK: | ||
| 534 | { | ||
| 535 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | ||
| 536 | BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 537 | ret = -1; | ||
| 538 | #else | ||
| 539 | ret = 0; | ||
| 540 | #endif | ||
| 541 | } | ||
| 542 | break; | ||
| 543 | case BIO_CTRL_GET_CALLBACK: | ||
| 544 | { | ||
| 545 | int (**fptr)(const BIO *bio, int state, int xret); | ||
| 546 | |||
| 547 | fptr = (int (**)(const BIO *bio, int state, int xret))ptr; | ||
| 548 | *fptr = data->info_callback; | ||
| 549 | } | ||
| 550 | break; | ||
| 551 | default: | ||
| 552 | ret = 0; | ||
| 553 | break; | ||
| 554 | } | ||
| 555 | return (ret); | ||
| 556 | } | ||
| 557 | |||
| 558 | static long | ||
| 559 | conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
| 560 | { | ||
| 561 | long ret = 1; | ||
| 562 | BIO_CONNECT *data; | ||
| 563 | |||
| 564 | data = (BIO_CONNECT *)b->ptr; | ||
| 565 | |||
| 566 | switch (cmd) { | ||
| 567 | case BIO_CTRL_SET_CALLBACK: | ||
| 568 | { | ||
| 569 | data->info_callback = (int (*)(const struct bio_st *, int, int))fp; | ||
| 570 | } | ||
| 571 | break; | ||
| 572 | default: | ||
| 573 | ret = 0; | ||
| 574 | break; | ||
| 575 | } | ||
| 576 | return (ret); | ||
| 577 | } | ||
| 578 | |||
| 579 | static int | ||
| 580 | conn_puts(BIO *bp, const char *str) | ||
| 581 | { | ||
| 582 | int n, ret; | ||
| 583 | |||
| 584 | n = strlen(str); | ||
| 585 | ret = conn_write(bp, str, n); | ||
| 586 | return (ret); | ||
| 587 | } | ||
| 588 | |||
| 589 | BIO * | ||
| 590 | BIO_new_connect(char *str) | ||
| 591 | { | ||
| 592 | BIO *ret; | ||
| 593 | |||
| 594 | ret = BIO_new(BIO_s_connect()); | ||
| 595 | if (ret == NULL) | ||
| 596 | return (NULL); | ||
| 597 | if (BIO_set_conn_hostname(ret, str)) | ||
| 598 | return (ret); | ||
| 599 | else { | ||
| 600 | BIO_free(ret); | ||
| 601 | return (NULL); | ||
| 602 | } | ||
| 603 | } | ||
| 604 | |||
diff --git a/src/lib/libcrypto/bio/bss_dgram.c b/src/lib/libcrypto/bio/bss_dgram.c deleted file mode 100644 index a9657402ce..0000000000 --- a/src/lib/libcrypto/bio/bss_dgram.c +++ /dev/null | |||
| @@ -1,658 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_dgram.c,v 1.41 2015/07/20 23:15:28 doug Exp $ */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <sys/socket.h> | ||
| 61 | #include <sys/time.h> | ||
| 62 | |||
| 63 | #include <netinet/in.h> | ||
| 64 | |||
| 65 | #include <errno.h> | ||
| 66 | #include <netdb.h> | ||
| 67 | #include <stdio.h> | ||
| 68 | #include <string.h> | ||
| 69 | #include <unistd.h> | ||
| 70 | |||
| 71 | #include <openssl/opensslconf.h> | ||
| 72 | |||
| 73 | #include <openssl/bio.h> | ||
| 74 | |||
| 75 | #ifndef OPENSSL_NO_DGRAM | ||
| 76 | |||
| 77 | |||
| 78 | static int dgram_write(BIO *h, const char *buf, int num); | ||
| 79 | static int dgram_read(BIO *h, char *buf, int size); | ||
| 80 | static int dgram_puts(BIO *h, const char *str); | ||
| 81 | static long dgram_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 82 | static int dgram_new(BIO *h); | ||
| 83 | static int dgram_free(BIO *data); | ||
| 84 | static int dgram_clear(BIO *bio); | ||
| 85 | |||
| 86 | |||
| 87 | static int BIO_dgram_should_retry(int s); | ||
| 88 | |||
| 89 | static BIO_METHOD methods_dgramp = { | ||
| 90 | .type = BIO_TYPE_DGRAM, | ||
| 91 | .name = "datagram socket", | ||
| 92 | .bwrite = dgram_write, | ||
| 93 | .bread = dgram_read, | ||
| 94 | .bputs = dgram_puts, | ||
| 95 | .ctrl = dgram_ctrl, | ||
| 96 | .create = dgram_new, | ||
| 97 | .destroy = dgram_free | ||
| 98 | }; | ||
| 99 | |||
| 100 | |||
| 101 | typedef struct bio_dgram_data_st { | ||
| 102 | union { | ||
| 103 | struct sockaddr sa; | ||
| 104 | struct sockaddr_in sa_in; | ||
| 105 | struct sockaddr_in6 sa_in6; | ||
| 106 | } peer; | ||
| 107 | unsigned int connected; | ||
| 108 | unsigned int _errno; | ||
| 109 | unsigned int mtu; | ||
| 110 | struct timeval next_timeout; | ||
| 111 | struct timeval socket_timeout; | ||
| 112 | } bio_dgram_data; | ||
| 113 | |||
| 114 | |||
| 115 | BIO_METHOD * | ||
| 116 | BIO_s_datagram(void) | ||
| 117 | { | ||
| 118 | return (&methods_dgramp); | ||
| 119 | } | ||
| 120 | |||
| 121 | BIO * | ||
| 122 | BIO_new_dgram(int fd, int close_flag) | ||
| 123 | { | ||
| 124 | BIO *ret; | ||
| 125 | |||
| 126 | ret = BIO_new(BIO_s_datagram()); | ||
| 127 | if (ret == NULL) | ||
| 128 | return (NULL); | ||
| 129 | BIO_set_fd(ret, fd, close_flag); | ||
| 130 | return (ret); | ||
| 131 | } | ||
| 132 | |||
| 133 | static int | ||
| 134 | dgram_new(BIO *bi) | ||
| 135 | { | ||
| 136 | bio_dgram_data *data = NULL; | ||
| 137 | |||
| 138 | bi->init = 0; | ||
| 139 | bi->num = 0; | ||
| 140 | data = calloc(1, sizeof(bio_dgram_data)); | ||
| 141 | if (data == NULL) | ||
| 142 | return 0; | ||
| 143 | bi->ptr = data; | ||
| 144 | |||
| 145 | bi->flags = 0; | ||
| 146 | return (1); | ||
| 147 | } | ||
| 148 | |||
| 149 | static int | ||
| 150 | dgram_free(BIO *a) | ||
| 151 | { | ||
| 152 | bio_dgram_data *data; | ||
| 153 | |||
| 154 | if (a == NULL) | ||
| 155 | return (0); | ||
| 156 | if (!dgram_clear(a)) | ||
| 157 | return 0; | ||
| 158 | |||
| 159 | data = (bio_dgram_data *)a->ptr; | ||
| 160 | free(data); | ||
| 161 | |||
| 162 | return (1); | ||
| 163 | } | ||
| 164 | |||
| 165 | static int | ||
| 166 | dgram_clear(BIO *a) | ||
| 167 | { | ||
| 168 | if (a == NULL) | ||
| 169 | return (0); | ||
| 170 | if (a->shutdown) { | ||
| 171 | if (a->init) { | ||
| 172 | shutdown(a->num, SHUT_RDWR); | ||
| 173 | close(a->num); | ||
| 174 | } | ||
| 175 | a->init = 0; | ||
| 176 | a->flags = 0; | ||
| 177 | } | ||
| 178 | return (1); | ||
| 179 | } | ||
| 180 | |||
| 181 | static void | ||
| 182 | dgram_adjust_rcv_timeout(BIO *b) | ||
| 183 | { | ||
| 184 | #if defined(SO_RCVTIMEO) | ||
| 185 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | ||
| 186 | |||
| 187 | /* Is a timer active? */ | ||
| 188 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) { | ||
| 189 | struct timeval timenow, timeleft; | ||
| 190 | |||
| 191 | /* Read current socket timeout */ | ||
| 192 | socklen_t sz = sizeof(data->socket_timeout); | ||
| 193 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
| 194 | &(data->socket_timeout), &sz) < 0) { | ||
| 195 | perror("getsockopt"); | ||
| 196 | } | ||
| 197 | |||
| 198 | /* Get current time */ | ||
| 199 | gettimeofday(&timenow, NULL); | ||
| 200 | |||
| 201 | /* Calculate time left until timer expires */ | ||
| 202 | memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval)); | ||
| 203 | timeleft.tv_sec -= timenow.tv_sec; | ||
| 204 | timeleft.tv_usec -= timenow.tv_usec; | ||
| 205 | if (timeleft.tv_usec < 0) { | ||
| 206 | timeleft.tv_sec--; | ||
| 207 | timeleft.tv_usec += 1000000; | ||
| 208 | } | ||
| 209 | |||
| 210 | if (timeleft.tv_sec < 0) { | ||
| 211 | timeleft.tv_sec = 0; | ||
| 212 | timeleft.tv_usec = 1; | ||
| 213 | } | ||
| 214 | |||
| 215 | /* Adjust socket timeout if next handhake message timer | ||
| 216 | * will expire earlier. | ||
| 217 | */ | ||
| 218 | if ((data->socket_timeout.tv_sec == 0 && | ||
| 219 | data->socket_timeout.tv_usec == 0) || | ||
| 220 | (data->socket_timeout.tv_sec > timeleft.tv_sec) || | ||
| 221 | (data->socket_timeout.tv_sec == timeleft.tv_sec && | ||
| 222 | data->socket_timeout.tv_usec >= timeleft.tv_usec)) { | ||
| 223 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
| 224 | &timeleft, sizeof(struct timeval)) < 0) { | ||
| 225 | perror("setsockopt"); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | #endif | ||
| 230 | } | ||
| 231 | |||
| 232 | static void | ||
| 233 | dgram_reset_rcv_timeout(BIO *b) | ||
| 234 | { | ||
| 235 | #if defined(SO_RCVTIMEO) | ||
| 236 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | ||
| 237 | |||
| 238 | /* Is a timer active? */ | ||
| 239 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) { | ||
| 240 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
| 241 | &(data->socket_timeout), sizeof(struct timeval)) < 0) { | ||
| 242 | perror("setsockopt"); | ||
| 243 | } | ||
| 244 | } | ||
| 245 | #endif | ||
| 246 | } | ||
| 247 | |||
| 248 | static int | ||
| 249 | dgram_read(BIO *b, char *out, int outl) | ||
| 250 | { | ||
| 251 | int ret = 0; | ||
| 252 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | ||
| 253 | |||
| 254 | struct { | ||
| 255 | socklen_t len; | ||
| 256 | union { | ||
| 257 | struct sockaddr sa; | ||
| 258 | struct sockaddr_in sa_in; | ||
| 259 | struct sockaddr_in6 sa_in6; | ||
| 260 | } peer; | ||
| 261 | } sa; | ||
| 262 | |||
| 263 | sa.len = sizeof(sa.peer); | ||
| 264 | |||
| 265 | if (out != NULL) { | ||
| 266 | errno = 0; | ||
| 267 | memset(&sa.peer, 0, sizeof(sa.peer)); | ||
| 268 | dgram_adjust_rcv_timeout(b); | ||
| 269 | ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa, &sa.len); | ||
| 270 | |||
| 271 | if (! data->connected && ret >= 0) | ||
| 272 | BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer); | ||
| 273 | |||
| 274 | BIO_clear_retry_flags(b); | ||
| 275 | if (ret < 0) { | ||
| 276 | if (BIO_dgram_should_retry(ret)) { | ||
| 277 | BIO_set_retry_read(b); | ||
| 278 | data->_errno = errno; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | |||
| 282 | dgram_reset_rcv_timeout(b); | ||
| 283 | } | ||
| 284 | return (ret); | ||
| 285 | } | ||
| 286 | |||
| 287 | static int | ||
| 288 | dgram_write(BIO *b, const char *in, int inl) | ||
| 289 | { | ||
| 290 | int ret; | ||
| 291 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | ||
| 292 | errno = 0; | ||
| 293 | |||
| 294 | if (data->connected) | ||
| 295 | ret = write(b->num, in, inl); | ||
| 296 | else { | ||
| 297 | int peerlen = sizeof(data->peer); | ||
| 298 | |||
| 299 | if (data->peer.sa.sa_family == AF_INET) | ||
| 300 | peerlen = sizeof(data->peer.sa_in); | ||
| 301 | else if (data->peer.sa.sa_family == AF_INET6) | ||
| 302 | peerlen = sizeof(data->peer.sa_in6); | ||
| 303 | ret = sendto(b->num, in, inl, 0, &data->peer.sa, peerlen); | ||
| 304 | } | ||
| 305 | |||
| 306 | BIO_clear_retry_flags(b); | ||
| 307 | if (ret <= 0) { | ||
| 308 | if (BIO_dgram_should_retry(ret)) { | ||
| 309 | BIO_set_retry_write(b); | ||
| 310 | |||
| 311 | data->_errno = errno; | ||
| 312 | /* | ||
| 313 | * higher layers are responsible for querying MTU, | ||
| 314 | * if necessary | ||
| 315 | */ | ||
| 316 | } | ||
| 317 | } | ||
| 318 | return (ret); | ||
| 319 | } | ||
| 320 | |||
| 321 | static long | ||
| 322 | dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 323 | { | ||
| 324 | long ret = 1; | ||
| 325 | int *ip; | ||
| 326 | struct sockaddr *to = NULL; | ||
| 327 | bio_dgram_data *data = NULL; | ||
| 328 | #if (defined(IP_MTU_DISCOVER) || defined(IP_MTU)) | ||
| 329 | int sockopt_val = 0; | ||
| 330 | socklen_t sockopt_len; /* assume that system supporting IP_MTU is | ||
| 331 | * modern enough to define socklen_t */ | ||
| 332 | socklen_t addr_len; | ||
| 333 | union { | ||
| 334 | struct sockaddr sa; | ||
| 335 | struct sockaddr_in s4; | ||
| 336 | struct sockaddr_in6 s6; | ||
| 337 | } addr; | ||
| 338 | #endif | ||
| 339 | |||
| 340 | data = (bio_dgram_data *)b->ptr; | ||
| 341 | |||
| 342 | switch (cmd) { | ||
| 343 | case BIO_CTRL_RESET: | ||
| 344 | num = 0; | ||
| 345 | case BIO_C_FILE_SEEK: | ||
| 346 | ret = 0; | ||
| 347 | break; | ||
| 348 | case BIO_C_FILE_TELL: | ||
| 349 | case BIO_CTRL_INFO: | ||
| 350 | ret = 0; | ||
| 351 | break; | ||
| 352 | case BIO_C_SET_FD: | ||
| 353 | dgram_clear(b); | ||
| 354 | b->num= *((int *)ptr); | ||
| 355 | b->shutdown = (int)num; | ||
| 356 | b->init = 1; | ||
| 357 | break; | ||
| 358 | case BIO_C_GET_FD: | ||
| 359 | if (b->init) { | ||
| 360 | ip = (int *)ptr; | ||
| 361 | if (ip != NULL) | ||
| 362 | *ip = b->num; | ||
| 363 | ret = b->num; | ||
| 364 | } else | ||
| 365 | ret = -1; | ||
| 366 | break; | ||
| 367 | case BIO_CTRL_GET_CLOSE: | ||
| 368 | ret = b->shutdown; | ||
| 369 | break; | ||
| 370 | case BIO_CTRL_SET_CLOSE: | ||
| 371 | b->shutdown = (int)num; | ||
| 372 | break; | ||
| 373 | case BIO_CTRL_PENDING: | ||
| 374 | case BIO_CTRL_WPENDING: | ||
| 375 | ret = 0; | ||
| 376 | break; | ||
| 377 | case BIO_CTRL_DUP: | ||
| 378 | case BIO_CTRL_FLUSH: | ||
| 379 | ret = 1; | ||
| 380 | break; | ||
| 381 | case BIO_CTRL_DGRAM_CONNECT: | ||
| 382 | to = (struct sockaddr *)ptr; | ||
| 383 | switch (to->sa_family) { | ||
| 384 | case AF_INET: | ||
| 385 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); | ||
| 386 | break; | ||
| 387 | case AF_INET6: | ||
| 388 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); | ||
| 389 | break; | ||
| 390 | default: | ||
| 391 | memcpy(&data->peer, to, sizeof(data->peer.sa)); | ||
| 392 | break; | ||
| 393 | } | ||
| 394 | break; | ||
| 395 | /* (Linux)kernel sets DF bit on outgoing IP packets */ | ||
| 396 | case BIO_CTRL_DGRAM_MTU_DISCOVER: | ||
| 397 | #if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) | ||
| 398 | addr_len = (socklen_t)sizeof(addr); | ||
| 399 | memset((void *)&addr, 0, sizeof(addr)); | ||
| 400 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) { | ||
| 401 | ret = 0; | ||
| 402 | break; | ||
| 403 | } | ||
| 404 | switch (addr.sa.sa_family) { | ||
| 405 | case AF_INET: | ||
| 406 | sockopt_val = IP_PMTUDISC_DO; | ||
| 407 | ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER, | ||
| 408 | &sockopt_val, sizeof(sockopt_val)); | ||
| 409 | if (ret < 0) | ||
| 410 | perror("setsockopt"); | ||
| 411 | break; | ||
| 412 | #if defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) | ||
| 413 | case AF_INET6: | ||
| 414 | sockopt_val = IPV6_PMTUDISC_DO; | ||
| 415 | ret = setsockopt(b->num, IPPROTO_IPV6, | ||
| 416 | IPV6_MTU_DISCOVER, &sockopt_val, | ||
| 417 | sizeof(sockopt_val)); | ||
| 418 | if (ret < 0) | ||
| 419 | perror("setsockopt"); | ||
| 420 | break; | ||
| 421 | #endif | ||
| 422 | default: | ||
| 423 | ret = -1; | ||
| 424 | break; | ||
| 425 | } | ||
| 426 | #else | ||
| 427 | ret = -1; | ||
| 428 | #endif | ||
| 429 | break; | ||
| 430 | case BIO_CTRL_DGRAM_QUERY_MTU: | ||
| 431 | #if defined(IP_MTU) | ||
| 432 | addr_len = (socklen_t)sizeof(addr); | ||
| 433 | memset((void *)&addr, 0, sizeof(addr)); | ||
| 434 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) { | ||
| 435 | ret = 0; | ||
| 436 | break; | ||
| 437 | } | ||
| 438 | sockopt_len = sizeof(sockopt_val); | ||
| 439 | switch (addr.sa.sa_family) { | ||
| 440 | case AF_INET: | ||
| 441 | ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, | ||
| 442 | &sockopt_val, &sockopt_len); | ||
| 443 | if (ret < 0 || sockopt_val < 0) { | ||
| 444 | ret = 0; | ||
| 445 | } else { | ||
| 446 | /* we assume that the transport protocol is UDP and no | ||
| 447 | * IP options are used. | ||
| 448 | */ | ||
| 449 | data->mtu = sockopt_val - 8 - 20; | ||
| 450 | ret = data->mtu; | ||
| 451 | } | ||
| 452 | break; | ||
| 453 | #if defined(IPV6_MTU) | ||
| 454 | case AF_INET6: | ||
| 455 | ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, | ||
| 456 | &sockopt_val, &sockopt_len); | ||
| 457 | if (ret < 0 || sockopt_val < 0) { | ||
| 458 | ret = 0; | ||
| 459 | } else { | ||
| 460 | /* we assume that the transport protocol is UDP and no | ||
| 461 | * IPV6 options are used. | ||
| 462 | */ | ||
| 463 | data->mtu = sockopt_val - 8 - 40; | ||
| 464 | ret = data->mtu; | ||
| 465 | } | ||
| 466 | break; | ||
| 467 | #endif | ||
| 468 | default: | ||
| 469 | ret = 0; | ||
| 470 | break; | ||
| 471 | } | ||
| 472 | #else | ||
| 473 | ret = 0; | ||
| 474 | #endif | ||
| 475 | break; | ||
| 476 | case BIO_CTRL_DGRAM_GET_FALLBACK_MTU: | ||
| 477 | switch (data->peer.sa.sa_family) { | ||
| 478 | case AF_INET: | ||
| 479 | ret = 576 - 20 - 8; | ||
| 480 | break; | ||
| 481 | case AF_INET6: | ||
| 482 | #ifdef IN6_IS_ADDR_V4MAPPED | ||
| 483 | if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr)) | ||
| 484 | ret = 576 - 20 - 8; | ||
| 485 | else | ||
| 486 | #endif | ||
| 487 | ret = 1280 - 40 - 8; | ||
| 488 | break; | ||
| 489 | default: | ||
| 490 | ret = 576 - 20 - 8; | ||
| 491 | break; | ||
| 492 | } | ||
| 493 | break; | ||
| 494 | case BIO_CTRL_DGRAM_GET_MTU: | ||
| 495 | return data->mtu; | ||
| 496 | break; | ||
| 497 | case BIO_CTRL_DGRAM_SET_MTU: | ||
| 498 | data->mtu = num; | ||
| 499 | ret = num; | ||
| 500 | break; | ||
| 501 | case BIO_CTRL_DGRAM_SET_CONNECTED: | ||
| 502 | to = (struct sockaddr *)ptr; | ||
| 503 | |||
| 504 | if (to != NULL) { | ||
| 505 | data->connected = 1; | ||
| 506 | switch (to->sa_family) { | ||
| 507 | case AF_INET: | ||
| 508 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); | ||
| 509 | break; | ||
| 510 | case AF_INET6: | ||
| 511 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); | ||
| 512 | break; | ||
| 513 | default: | ||
| 514 | memcpy(&data->peer, to, sizeof(data->peer.sa)); | ||
| 515 | break; | ||
| 516 | } | ||
| 517 | } else { | ||
| 518 | data->connected = 0; | ||
| 519 | memset(&(data->peer), 0, sizeof(data->peer)); | ||
| 520 | } | ||
| 521 | break; | ||
| 522 | case BIO_CTRL_DGRAM_GET_PEER: | ||
| 523 | switch (data->peer.sa.sa_family) { | ||
| 524 | case AF_INET: | ||
| 525 | ret = sizeof(data->peer.sa_in); | ||
| 526 | break; | ||
| 527 | case AF_INET6: | ||
| 528 | ret = sizeof(data->peer.sa_in6); | ||
| 529 | break; | ||
| 530 | default: | ||
| 531 | ret = sizeof(data->peer.sa); | ||
| 532 | break; | ||
| 533 | } | ||
| 534 | if (num == 0 || num > ret) | ||
| 535 | num = ret; | ||
| 536 | memcpy(ptr, &data->peer, (ret = num)); | ||
| 537 | break; | ||
| 538 | case BIO_CTRL_DGRAM_SET_PEER: | ||
| 539 | to = (struct sockaddr *) ptr; | ||
| 540 | switch (to->sa_family) { | ||
| 541 | case AF_INET: | ||
| 542 | memcpy(&data->peer, to, sizeof(data->peer.sa_in)); | ||
| 543 | break; | ||
| 544 | case AF_INET6: | ||
| 545 | memcpy(&data->peer, to, sizeof(data->peer.sa_in6)); | ||
| 546 | break; | ||
| 547 | default: | ||
| 548 | memcpy(&data->peer, to, sizeof(data->peer.sa)); | ||
| 549 | break; | ||
| 550 | } | ||
| 551 | break; | ||
| 552 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: | ||
| 553 | memcpy(&(data->next_timeout), ptr, sizeof(struct timeval)); | ||
| 554 | break; | ||
| 555 | #if defined(SO_RCVTIMEO) | ||
| 556 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: | ||
| 557 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr, | ||
| 558 | sizeof(struct timeval)) < 0) { | ||
| 559 | perror("setsockopt"); | ||
| 560 | ret = -1; | ||
| 561 | } | ||
| 562 | break; | ||
| 563 | case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT: | ||
| 564 | { | ||
| 565 | socklen_t sz = sizeof(struct timeval); | ||
| 566 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
| 567 | ptr, &sz) < 0) { | ||
| 568 | perror("getsockopt"); | ||
| 569 | ret = -1; | ||
| 570 | } else | ||
| 571 | ret = sz; | ||
| 572 | } | ||
| 573 | break; | ||
| 574 | #endif | ||
| 575 | #if defined(SO_SNDTIMEO) | ||
| 576 | case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT: | ||
| 577 | if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr, | ||
| 578 | sizeof(struct timeval)) < 0) { | ||
| 579 | perror("setsockopt"); | ||
| 580 | ret = -1; | ||
| 581 | } | ||
| 582 | break; | ||
| 583 | case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT: | ||
| 584 | { | ||
| 585 | socklen_t sz = sizeof(struct timeval); | ||
| 586 | if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, | ||
| 587 | ptr, &sz) < 0) { | ||
| 588 | perror("getsockopt"); | ||
| 589 | ret = -1; | ||
| 590 | } else | ||
| 591 | ret = sz; | ||
| 592 | } | ||
| 593 | break; | ||
| 594 | #endif | ||
| 595 | case BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP: | ||
| 596 | /* fall-through */ | ||
| 597 | case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP: | ||
| 598 | if (data->_errno == EAGAIN) { | ||
| 599 | ret = 1; | ||
| 600 | data->_errno = 0; | ||
| 601 | } else | ||
| 602 | ret = 0; | ||
| 603 | break; | ||
| 604 | #ifdef EMSGSIZE | ||
| 605 | case BIO_CTRL_DGRAM_MTU_EXCEEDED: | ||
| 606 | if (data->_errno == EMSGSIZE) { | ||
| 607 | ret = 1; | ||
| 608 | data->_errno = 0; | ||
| 609 | } else | ||
| 610 | ret = 0; | ||
| 611 | break; | ||
| 612 | #endif | ||
| 613 | default: | ||
| 614 | ret = 0; | ||
| 615 | break; | ||
| 616 | } | ||
| 617 | return (ret); | ||
| 618 | } | ||
| 619 | |||
| 620 | static int | ||
| 621 | dgram_puts(BIO *bp, const char *str) | ||
| 622 | { | ||
| 623 | int n, ret; | ||
| 624 | |||
| 625 | n = strlen(str); | ||
| 626 | ret = dgram_write(bp, str, n); | ||
| 627 | return (ret); | ||
| 628 | } | ||
| 629 | |||
| 630 | |||
| 631 | static int | ||
| 632 | BIO_dgram_should_retry(int i) | ||
| 633 | { | ||
| 634 | int err; | ||
| 635 | |||
| 636 | if ((i == 0) || (i == -1)) { | ||
| 637 | err = errno; | ||
| 638 | return (BIO_dgram_non_fatal_error(err)); | ||
| 639 | } | ||
| 640 | return (0); | ||
| 641 | } | ||
| 642 | |||
| 643 | int | ||
| 644 | BIO_dgram_non_fatal_error(int err) | ||
| 645 | { | ||
| 646 | switch (err) { | ||
| 647 | case EINTR: | ||
| 648 | case EAGAIN: | ||
| 649 | case EINPROGRESS: | ||
| 650 | case EALREADY: | ||
| 651 | return (1); | ||
| 652 | default: | ||
| 653 | break; | ||
| 654 | } | ||
| 655 | return (0); | ||
| 656 | } | ||
| 657 | |||
| 658 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c deleted file mode 100644 index b21dbd92ed..0000000000 --- a/src/lib/libcrypto/bio/bss_fd.c +++ /dev/null | |||
| @@ -1,267 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_fd.c,v 1.18 2015/02/12 03:54:07 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <unistd.h> | ||
| 63 | |||
| 64 | #include <openssl/opensslconf.h> | ||
| 65 | |||
| 66 | #include <openssl/bio.h> | ||
| 67 | |||
| 68 | static int fd_write(BIO *h, const char *buf, int num); | ||
| 69 | static int fd_read(BIO *h, char *buf, int size); | ||
| 70 | static int fd_puts(BIO *h, const char *str); | ||
| 71 | static int fd_gets(BIO *h, char *buf, int size); | ||
| 72 | static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 73 | static int fd_new(BIO *h); | ||
| 74 | static int fd_free(BIO *data); | ||
| 75 | int BIO_fd_should_retry(int s); | ||
| 76 | |||
| 77 | static BIO_METHOD methods_fdp = { | ||
| 78 | .type = BIO_TYPE_FD, | ||
| 79 | .name = "file descriptor", | ||
| 80 | .bwrite = fd_write, | ||
| 81 | .bread = fd_read, | ||
| 82 | .bputs = fd_puts, | ||
| 83 | .bgets = fd_gets, | ||
| 84 | .ctrl = fd_ctrl, | ||
| 85 | .create = fd_new, | ||
| 86 | .destroy = fd_free | ||
| 87 | }; | ||
| 88 | |||
| 89 | BIO_METHOD * | ||
| 90 | BIO_s_fd(void) | ||
| 91 | { | ||
| 92 | return (&methods_fdp); | ||
| 93 | } | ||
| 94 | |||
| 95 | BIO * | ||
| 96 | BIO_new_fd(int fd, int close_flag) | ||
| 97 | { | ||
| 98 | BIO *ret; | ||
| 99 | ret = BIO_new(BIO_s_fd()); | ||
| 100 | if (ret == NULL) | ||
| 101 | return (NULL); | ||
| 102 | BIO_set_fd(ret, fd, close_flag); | ||
| 103 | return (ret); | ||
| 104 | } | ||
| 105 | |||
| 106 | static int | ||
| 107 | fd_new(BIO *bi) | ||
| 108 | { | ||
| 109 | bi->init = 0; | ||
| 110 | bi->num = -1; | ||
| 111 | bi->ptr = NULL; | ||
| 112 | bi->flags=0; | ||
| 113 | return (1); | ||
| 114 | } | ||
| 115 | |||
| 116 | static int | ||
| 117 | fd_free(BIO *a) | ||
| 118 | { | ||
| 119 | if (a == NULL) | ||
| 120 | return (0); | ||
| 121 | if (a->shutdown) { | ||
| 122 | if (a->init) { | ||
| 123 | close(a->num); | ||
| 124 | } | ||
| 125 | a->init = 0; | ||
| 126 | a->flags = 0; | ||
| 127 | } | ||
| 128 | return (1); | ||
| 129 | } | ||
| 130 | |||
| 131 | static int | ||
| 132 | fd_read(BIO *b, char *out, int outl) | ||
| 133 | { | ||
| 134 | int ret = 0; | ||
| 135 | |||
| 136 | if (out != NULL) { | ||
| 137 | errno = 0; | ||
| 138 | ret = read(b->num, out, outl); | ||
| 139 | BIO_clear_retry_flags(b); | ||
| 140 | if (ret <= 0) { | ||
| 141 | if (BIO_fd_should_retry(ret)) | ||
| 142 | BIO_set_retry_read(b); | ||
| 143 | } | ||
| 144 | } | ||
| 145 | return (ret); | ||
| 146 | } | ||
| 147 | |||
| 148 | static int | ||
| 149 | fd_write(BIO *b, const char *in, int inl) | ||
| 150 | { | ||
| 151 | int ret; | ||
| 152 | errno = 0; | ||
| 153 | ret = write(b->num, in, inl); | ||
| 154 | BIO_clear_retry_flags(b); | ||
| 155 | if (ret <= 0) { | ||
| 156 | if (BIO_fd_should_retry(ret)) | ||
| 157 | BIO_set_retry_write(b); | ||
| 158 | } | ||
| 159 | return (ret); | ||
| 160 | } | ||
| 161 | |||
| 162 | static long | ||
| 163 | fd_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 164 | { | ||
| 165 | long ret = 1; | ||
| 166 | int *ip; | ||
| 167 | |||
| 168 | switch (cmd) { | ||
| 169 | case BIO_CTRL_RESET: | ||
| 170 | num = 0; | ||
| 171 | case BIO_C_FILE_SEEK: | ||
| 172 | ret = (long)lseek(b->num, num, 0); | ||
| 173 | break; | ||
| 174 | case BIO_C_FILE_TELL: | ||
| 175 | case BIO_CTRL_INFO: | ||
| 176 | ret = (long)lseek(b->num, 0, 1); | ||
| 177 | break; | ||
| 178 | case BIO_C_SET_FD: | ||
| 179 | fd_free(b); | ||
| 180 | b->num= *((int *)ptr); | ||
| 181 | b->shutdown = (int)num; | ||
| 182 | b->init = 1; | ||
| 183 | break; | ||
| 184 | case BIO_C_GET_FD: | ||
| 185 | if (b->init) { | ||
| 186 | ip = (int *)ptr; | ||
| 187 | if (ip != NULL) | ||
| 188 | *ip = b->num; | ||
| 189 | ret = b->num; | ||
| 190 | } else | ||
| 191 | ret = -1; | ||
| 192 | break; | ||
| 193 | case BIO_CTRL_GET_CLOSE: | ||
| 194 | ret = b->shutdown; | ||
| 195 | break; | ||
| 196 | case BIO_CTRL_SET_CLOSE: | ||
| 197 | b->shutdown = (int)num; | ||
| 198 | break; | ||
| 199 | case BIO_CTRL_PENDING: | ||
| 200 | case BIO_CTRL_WPENDING: | ||
| 201 | ret = 0; | ||
| 202 | break; | ||
| 203 | case BIO_CTRL_DUP: | ||
| 204 | case BIO_CTRL_FLUSH: | ||
| 205 | ret = 1; | ||
| 206 | break; | ||
| 207 | default: | ||
| 208 | ret = 0; | ||
| 209 | break; | ||
| 210 | } | ||
| 211 | return (ret); | ||
| 212 | } | ||
| 213 | |||
| 214 | static int | ||
| 215 | fd_puts(BIO *bp, const char *str) | ||
| 216 | { | ||
| 217 | int n, ret; | ||
| 218 | |||
| 219 | n = strlen(str); | ||
| 220 | ret = fd_write(bp, str, n); | ||
| 221 | return (ret); | ||
| 222 | } | ||
| 223 | |||
| 224 | static int | ||
| 225 | fd_gets(BIO *bp, char *buf, int size) | ||
| 226 | { | ||
| 227 | int ret = 0; | ||
| 228 | char *ptr = buf; | ||
| 229 | char *end = buf + size - 1; | ||
| 230 | |||
| 231 | while ((ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n')) | ||
| 232 | ptr++; | ||
| 233 | |||
| 234 | ptr[0] = '\0'; | ||
| 235 | |||
| 236 | if (buf[0] != '\0') | ||
| 237 | ret = strlen(buf); | ||
| 238 | return (ret); | ||
| 239 | } | ||
| 240 | |||
| 241 | int | ||
| 242 | BIO_fd_should_retry(int i) | ||
| 243 | { | ||
| 244 | int err; | ||
| 245 | |||
| 246 | if ((i == 0) || (i == -1)) { | ||
| 247 | err = errno; | ||
| 248 | return (BIO_fd_non_fatal_error(err)); | ||
| 249 | } | ||
| 250 | return (0); | ||
| 251 | } | ||
| 252 | |||
| 253 | int | ||
| 254 | BIO_fd_non_fatal_error(int err) | ||
| 255 | { | ||
| 256 | switch (err) { | ||
| 257 | case ENOTCONN: | ||
| 258 | case EINTR: | ||
| 259 | case EAGAIN: | ||
| 260 | case EINPROGRESS: | ||
| 261 | case EALREADY: | ||
| 262 | return (1); | ||
| 263 | default: | ||
| 264 | break; | ||
| 265 | } | ||
| 266 | return (0); | ||
| 267 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c deleted file mode 100644 index c710076fea..0000000000 --- a/src/lib/libcrypto/bio/bss_file.c +++ /dev/null | |||
| @@ -1,320 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_file.c,v 1.31 2014/11/11 19:26:12 miod Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* | ||
| 60 | * 03-Dec-1997 rdenny@dc3.com Fix bug preventing use of stdin/stdout | ||
| 61 | * with binary data (e.g. asn1parse -inform DER < xxx) under | ||
| 62 | * Windows | ||
| 63 | */ | ||
| 64 | |||
| 65 | #ifndef HEADER_BSS_FILE_C | ||
| 66 | #define HEADER_BSS_FILE_C | ||
| 67 | |||
| 68 | #if defined(__linux) || defined(__sun) || defined(__hpux) | ||
| 69 | /* Following definition aliases fopen to fopen64 on above mentioned | ||
| 70 | * platforms. This makes it possible to open and sequentially access | ||
| 71 | * files larger than 2GB from 32-bit application. It does not allow to | ||
| 72 | * traverse them beyond 2GB with fseek/ftell, but on the other hand *no* | ||
| 73 | * 32-bit platform permits that, not with fseek/ftell. Not to mention | ||
| 74 | * that breaking 2GB limit for seeking would require surgery to *our* | ||
| 75 | * API. But sequential access suffices for practical cases when you | ||
| 76 | * can run into large files, such as fingerprinting, so we can let API | ||
| 77 | * alone. For reference, the list of 32-bit platforms which allow for | ||
| 78 | * sequential access of large files without extra "magic" comprise *BSD, | ||
| 79 | * Darwin, IRIX... | ||
| 80 | */ | ||
| 81 | #ifndef _FILE_OFFSET_BITS | ||
| 82 | #define _FILE_OFFSET_BITS 64 | ||
| 83 | #endif | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #include <errno.h> | ||
| 87 | #include <stdio.h> | ||
| 88 | #include <string.h> | ||
| 89 | |||
| 90 | #include <openssl/bio.h> | ||
| 91 | #include <openssl/err.h> | ||
| 92 | |||
| 93 | static int file_write(BIO *h, const char *buf, int num); | ||
| 94 | static int file_read(BIO *h, char *buf, int size); | ||
| 95 | static int file_puts(BIO *h, const char *str); | ||
| 96 | static int file_gets(BIO *h, char *str, int size); | ||
| 97 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 98 | static int file_new(BIO *h); | ||
| 99 | static int file_free(BIO *data); | ||
| 100 | |||
| 101 | static BIO_METHOD methods_filep = { | ||
| 102 | .type = BIO_TYPE_FILE, | ||
| 103 | .name = "FILE pointer", | ||
| 104 | .bwrite = file_write, | ||
| 105 | .bread = file_read, | ||
| 106 | .bputs = file_puts, | ||
| 107 | .bgets = file_gets, | ||
| 108 | .ctrl = file_ctrl, | ||
| 109 | .create = file_new, | ||
| 110 | .destroy = file_free | ||
| 111 | }; | ||
| 112 | |||
| 113 | BIO * | ||
| 114 | BIO_new_file(const char *filename, const char *mode) | ||
| 115 | { | ||
| 116 | BIO *ret; | ||
| 117 | FILE *file = NULL; | ||
| 118 | |||
| 119 | file = fopen(filename, mode); | ||
| 120 | |||
| 121 | if (file == NULL) { | ||
| 122 | SYSerr(SYS_F_FOPEN, errno); | ||
| 123 | ERR_asprintf_error_data("fopen('%s', '%s')", filename, mode); | ||
| 124 | if (errno == ENOENT) | ||
| 125 | BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); | ||
| 126 | else | ||
| 127 | BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); | ||
| 128 | return (NULL); | ||
| 129 | } | ||
| 130 | if ((ret = BIO_new(BIO_s_file())) == NULL) { | ||
| 131 | fclose(file); | ||
| 132 | return (NULL); | ||
| 133 | } | ||
| 134 | |||
| 135 | BIO_set_fp(ret, file, BIO_CLOSE); | ||
| 136 | return (ret); | ||
| 137 | } | ||
| 138 | |||
| 139 | BIO * | ||
| 140 | BIO_new_fp(FILE *stream, int close_flag) | ||
| 141 | { | ||
| 142 | BIO *ret; | ||
| 143 | |||
| 144 | if ((ret = BIO_new(BIO_s_file())) == NULL) | ||
| 145 | return (NULL); | ||
| 146 | |||
| 147 | BIO_set_fp(ret, stream, close_flag); | ||
| 148 | return (ret); | ||
| 149 | } | ||
| 150 | |||
| 151 | BIO_METHOD * | ||
| 152 | BIO_s_file(void) | ||
| 153 | { | ||
| 154 | return (&methods_filep); | ||
| 155 | } | ||
| 156 | |||
| 157 | static int | ||
| 158 | file_new(BIO *bi) | ||
| 159 | { | ||
| 160 | bi->init = 0; | ||
| 161 | bi->num = 0; | ||
| 162 | bi->ptr = NULL; | ||
| 163 | bi->flags=0; | ||
| 164 | return (1); | ||
| 165 | } | ||
| 166 | |||
| 167 | static int | ||
| 168 | file_free(BIO *a) | ||
| 169 | { | ||
| 170 | if (a == NULL) | ||
| 171 | return (0); | ||
| 172 | if (a->shutdown) { | ||
| 173 | if ((a->init) && (a->ptr != NULL)) { | ||
| 174 | fclose (a->ptr); | ||
| 175 | a->ptr = NULL; | ||
| 176 | a->flags = 0; | ||
| 177 | } | ||
| 178 | a->init = 0; | ||
| 179 | } | ||
| 180 | return (1); | ||
| 181 | } | ||
| 182 | |||
| 183 | static int | ||
| 184 | file_read(BIO *b, char *out, int outl) | ||
| 185 | { | ||
| 186 | int ret = 0; | ||
| 187 | |||
| 188 | if (b->init && out != NULL) { | ||
| 189 | ret = fread(out, 1, outl, (FILE *)b->ptr); | ||
| 190 | if (ret == 0 && ferror((FILE *)b->ptr)) { | ||
| 191 | SYSerr(SYS_F_FREAD, errno); | ||
| 192 | BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); | ||
| 193 | ret = -1; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | return (ret); | ||
| 197 | } | ||
| 198 | |||
| 199 | static int | ||
| 200 | file_write(BIO *b, const char *in, int inl) | ||
| 201 | { | ||
| 202 | int ret = 0; | ||
| 203 | |||
| 204 | if (b->init && in != NULL) | ||
| 205 | ret = fwrite(in, 1, inl, (FILE *)b->ptr); | ||
| 206 | return (ret); | ||
| 207 | } | ||
| 208 | |||
| 209 | static long | ||
| 210 | file_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 211 | { | ||
| 212 | long ret = 1; | ||
| 213 | FILE *fp = (FILE *)b->ptr; | ||
| 214 | FILE **fpp; | ||
| 215 | char p[4]; | ||
| 216 | |||
| 217 | switch (cmd) { | ||
| 218 | case BIO_C_FILE_SEEK: | ||
| 219 | case BIO_CTRL_RESET: | ||
| 220 | ret = (long)fseek(fp, num, 0); | ||
| 221 | break; | ||
| 222 | case BIO_CTRL_EOF: | ||
| 223 | ret = (long)feof(fp); | ||
| 224 | break; | ||
| 225 | case BIO_C_FILE_TELL: | ||
| 226 | case BIO_CTRL_INFO: | ||
| 227 | ret = ftell(fp); | ||
| 228 | break; | ||
| 229 | case BIO_C_SET_FILE_PTR: | ||
| 230 | file_free(b); | ||
| 231 | b->shutdown = (int)num&BIO_CLOSE; | ||
| 232 | b->ptr = ptr; | ||
| 233 | b->init = 1; | ||
| 234 | break; | ||
| 235 | case BIO_C_SET_FILENAME: | ||
| 236 | file_free(b); | ||
| 237 | b->shutdown = (int)num&BIO_CLOSE; | ||
| 238 | if (num & BIO_FP_APPEND) { | ||
| 239 | if (num & BIO_FP_READ) | ||
| 240 | strlcpy(p, "a+", sizeof p); | ||
| 241 | else strlcpy(p, "a", sizeof p); | ||
| 242 | } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) | ||
| 243 | strlcpy(p, "r+", sizeof p); | ||
| 244 | else if (num & BIO_FP_WRITE) | ||
| 245 | strlcpy(p, "w", sizeof p); | ||
| 246 | else if (num & BIO_FP_READ) | ||
| 247 | strlcpy(p, "r", sizeof p); | ||
| 248 | else { | ||
| 249 | BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); | ||
| 250 | ret = 0; | ||
| 251 | break; | ||
| 252 | } | ||
| 253 | fp = fopen(ptr, p); | ||
| 254 | if (fp == NULL) { | ||
| 255 | SYSerr(SYS_F_FOPEN, errno); | ||
| 256 | ERR_asprintf_error_data("fopen('%s', '%s')", ptr, p); | ||
| 257 | BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); | ||
| 258 | ret = 0; | ||
| 259 | break; | ||
| 260 | } | ||
| 261 | b->ptr = fp; | ||
| 262 | b->init = 1; | ||
| 263 | break; | ||
| 264 | case BIO_C_GET_FILE_PTR: | ||
| 265 | /* the ptr parameter is actually a FILE ** in this case. */ | ||
| 266 | if (ptr != NULL) { | ||
| 267 | fpp = (FILE **)ptr; | ||
| 268 | *fpp = (FILE *)b->ptr; | ||
| 269 | } | ||
| 270 | break; | ||
| 271 | case BIO_CTRL_GET_CLOSE: | ||
| 272 | ret = (long)b->shutdown; | ||
| 273 | break; | ||
| 274 | case BIO_CTRL_SET_CLOSE: | ||
| 275 | b->shutdown = (int)num; | ||
| 276 | break; | ||
| 277 | case BIO_CTRL_FLUSH: | ||
| 278 | fflush((FILE *)b->ptr); | ||
| 279 | break; | ||
| 280 | case BIO_CTRL_DUP: | ||
| 281 | ret = 1; | ||
| 282 | break; | ||
| 283 | |||
| 284 | case BIO_CTRL_WPENDING: | ||
| 285 | case BIO_CTRL_PENDING: | ||
| 286 | case BIO_CTRL_PUSH: | ||
| 287 | case BIO_CTRL_POP: | ||
| 288 | default: | ||
| 289 | ret = 0; | ||
| 290 | break; | ||
| 291 | } | ||
| 292 | return (ret); | ||
| 293 | } | ||
| 294 | |||
| 295 | static int | ||
| 296 | file_gets(BIO *bp, char *buf, int size) | ||
| 297 | { | ||
| 298 | int ret = 0; | ||
| 299 | |||
| 300 | buf[0] = '\0'; | ||
| 301 | if (!fgets(buf, size,(FILE *)bp->ptr)) | ||
| 302 | goto err; | ||
| 303 | if (buf[0] != '\0') | ||
| 304 | ret = strlen(buf); | ||
| 305 | err: | ||
| 306 | return (ret); | ||
| 307 | } | ||
| 308 | |||
| 309 | static int | ||
| 310 | file_puts(BIO *bp, const char *str) | ||
| 311 | { | ||
| 312 | int n, ret; | ||
| 313 | |||
| 314 | n = strlen(str); | ||
| 315 | ret = file_write(bp, str, n); | ||
| 316 | return (ret); | ||
| 317 | } | ||
| 318 | |||
| 319 | |||
| 320 | #endif /* HEADER_BSS_FILE_C */ | ||
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c deleted file mode 100644 index fcaa985aa0..0000000000 --- a/src/lib/libcrypto/bio/bss_log.c +++ /dev/null | |||
| @@ -1,213 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_log.c,v 1.21 2014/07/11 08:44:47 jsing Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * licensing@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* | ||
| 57 | Why BIO_s_log? | ||
| 58 | |||
| 59 | BIO_s_log is useful for system daemons (or services under NT). | ||
| 60 | It is one-way BIO, it sends all stuff to syslogd (on system that | ||
| 61 | commonly use that), or event log (on NT), or OPCOM (on OpenVMS). | ||
| 62 | |||
| 63 | */ | ||
| 64 | |||
| 65 | #include <errno.h> | ||
| 66 | #include <stdio.h> | ||
| 67 | #include <string.h> | ||
| 68 | #include <syslog.h> | ||
| 69 | |||
| 70 | #include <openssl/buffer.h> | ||
| 71 | #include <openssl/err.h> | ||
| 72 | |||
| 73 | #ifndef NO_SYSLOG | ||
| 74 | |||
| 75 | static int slg_write(BIO *h, const char *buf, int num); | ||
| 76 | static int slg_puts(BIO *h, const char *str); | ||
| 77 | static long slg_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 78 | static int slg_new(BIO *h); | ||
| 79 | static int slg_free(BIO *data); | ||
| 80 | static void xopenlog(BIO* bp, char* name, int level); | ||
| 81 | static void xsyslog(BIO* bp, int priority, const char* string); | ||
| 82 | static void xcloselog(BIO* bp); | ||
| 83 | |||
| 84 | static BIO_METHOD methods_slg = { | ||
| 85 | .type = BIO_TYPE_MEM, | ||
| 86 | .name = "syslog", | ||
| 87 | .bwrite = slg_write, | ||
| 88 | .bputs = slg_puts, | ||
| 89 | .ctrl = slg_ctrl, | ||
| 90 | .create = slg_new, | ||
| 91 | .destroy = slg_free | ||
| 92 | }; | ||
| 93 | |||
| 94 | BIO_METHOD * | ||
| 95 | BIO_s_log(void) | ||
| 96 | { | ||
| 97 | return (&methods_slg); | ||
| 98 | } | ||
| 99 | |||
| 100 | static int | ||
| 101 | slg_new(BIO *bi) | ||
| 102 | { | ||
| 103 | bi->init = 1; | ||
| 104 | bi->num = 0; | ||
| 105 | bi->ptr = NULL; | ||
| 106 | xopenlog(bi, "application", LOG_DAEMON); | ||
| 107 | return (1); | ||
| 108 | } | ||
| 109 | |||
| 110 | static int | ||
| 111 | slg_free(BIO *a) | ||
| 112 | { | ||
| 113 | if (a == NULL) | ||
| 114 | return (0); | ||
| 115 | xcloselog(a); | ||
| 116 | return (1); | ||
| 117 | } | ||
| 118 | |||
| 119 | static int | ||
| 120 | slg_write(BIO *b, const char *in, int inl) | ||
| 121 | { | ||
| 122 | int ret = inl; | ||
| 123 | char* buf; | ||
| 124 | char* pp; | ||
| 125 | int priority, i; | ||
| 126 | static const struct { | ||
| 127 | int strl; | ||
| 128 | char str[10]; | ||
| 129 | int log_level; | ||
| 130 | } | ||
| 131 | mapping[] = { | ||
| 132 | { 6, "PANIC ", LOG_EMERG }, | ||
| 133 | { 6, "EMERG ", LOG_EMERG }, | ||
| 134 | { 4, "EMR ", LOG_EMERG }, | ||
| 135 | { 6, "ALERT ", LOG_ALERT }, | ||
| 136 | { 4, "ALR ", LOG_ALERT }, | ||
| 137 | { 5, "CRIT ", LOG_CRIT }, | ||
| 138 | { 4, "CRI ", LOG_CRIT }, | ||
| 139 | { 6, "ERROR ", LOG_ERR }, | ||
| 140 | { 4, "ERR ", LOG_ERR }, | ||
| 141 | { 8, "WARNING ", LOG_WARNING }, | ||
| 142 | { 5, "WARN ", LOG_WARNING }, | ||
| 143 | { 4, "WAR ", LOG_WARNING }, | ||
| 144 | { 7, "NOTICE ", LOG_NOTICE }, | ||
| 145 | { 5, "NOTE ", LOG_NOTICE }, | ||
| 146 | { 4, "NOT ", LOG_NOTICE }, | ||
| 147 | { 5, "INFO ", LOG_INFO }, | ||
| 148 | { 4, "INF ", LOG_INFO }, | ||
| 149 | { 6, "DEBUG ", LOG_DEBUG }, | ||
| 150 | { 4, "DBG ", LOG_DEBUG }, | ||
| 151 | { 0, "", LOG_ERR } /* The default */ | ||
| 152 | }; | ||
| 153 | |||
| 154 | if ((buf = malloc(inl + 1)) == NULL) { | ||
| 155 | return (0); | ||
| 156 | } | ||
| 157 | strlcpy(buf, in, inl + 1); | ||
| 158 | i = 0; | ||
| 159 | while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0) | ||
| 160 | i++; | ||
| 161 | priority = mapping[i].log_level; | ||
| 162 | pp = buf + mapping[i].strl; | ||
| 163 | |||
| 164 | xsyslog(b, priority, pp); | ||
| 165 | |||
| 166 | free(buf); | ||
| 167 | return (ret); | ||
| 168 | } | ||
| 169 | |||
| 170 | static long | ||
| 171 | slg_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 172 | { | ||
| 173 | switch (cmd) { | ||
| 174 | case BIO_CTRL_SET: | ||
| 175 | xcloselog(b); | ||
| 176 | xopenlog(b, ptr, num); | ||
| 177 | break; | ||
| 178 | default: | ||
| 179 | break; | ||
| 180 | } | ||
| 181 | return (0); | ||
| 182 | } | ||
| 183 | |||
| 184 | static int | ||
| 185 | slg_puts(BIO *bp, const char *str) | ||
| 186 | { | ||
| 187 | int n, ret; | ||
| 188 | |||
| 189 | n = strlen(str); | ||
| 190 | ret = slg_write(bp, str, n); | ||
| 191 | return (ret); | ||
| 192 | } | ||
| 193 | |||
| 194 | |||
| 195 | static void | ||
| 196 | xopenlog(BIO* bp, char* name, int level) | ||
| 197 | { | ||
| 198 | openlog(name, LOG_PID|LOG_CONS, level); | ||
| 199 | } | ||
| 200 | |||
| 201 | static void | ||
| 202 | xsyslog(BIO *bp, int priority, const char *string) | ||
| 203 | { | ||
| 204 | syslog(priority, "%s", string); | ||
| 205 | } | ||
| 206 | |||
| 207 | static void | ||
| 208 | xcloselog(BIO* bp) | ||
| 209 | { | ||
| 210 | closelog(); | ||
| 211 | } | ||
| 212 | |||
| 213 | #endif /* NO_SYSLOG */ | ||
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c deleted file mode 100644 index 119bd672f6..0000000000 --- a/src/lib/libcrypto/bio/bss_mem.c +++ /dev/null | |||
| @@ -1,321 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_mem.c,v 1.14 2015/03/21 08:05:20 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/bio.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | #include <openssl/buffer.h> | ||
| 66 | |||
| 67 | static int mem_write(BIO *h, const char *buf, int num); | ||
| 68 | static int mem_read(BIO *h, char *buf, int size); | ||
| 69 | static int mem_puts(BIO *h, const char *str); | ||
| 70 | static int mem_gets(BIO *h, char *str, int size); | ||
| 71 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 72 | static int mem_new(BIO *h); | ||
| 73 | static int mem_free(BIO *data); | ||
| 74 | |||
| 75 | static BIO_METHOD mem_method = { | ||
| 76 | .type = BIO_TYPE_MEM, | ||
| 77 | .name = "memory buffer", | ||
| 78 | .bwrite = mem_write, | ||
| 79 | .bread = mem_read, | ||
| 80 | .bputs = mem_puts, | ||
| 81 | .bgets = mem_gets, | ||
| 82 | .ctrl = mem_ctrl, | ||
| 83 | .create = mem_new, | ||
| 84 | .destroy = mem_free | ||
| 85 | }; | ||
| 86 | |||
| 87 | /* bio->num is used to hold the value to return on 'empty', if it is | ||
| 88 | * 0, should_retry is not set */ | ||
| 89 | |||
| 90 | BIO_METHOD * | ||
| 91 | BIO_s_mem(void) | ||
| 92 | { | ||
| 93 | return (&mem_method); | ||
| 94 | } | ||
| 95 | |||
| 96 | BIO * | ||
| 97 | BIO_new_mem_buf(void *buf, int len) | ||
| 98 | { | ||
| 99 | BIO *ret; | ||
| 100 | BUF_MEM *b; | ||
| 101 | size_t sz; | ||
| 102 | |||
| 103 | if (!buf) { | ||
| 104 | BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER); | ||
| 105 | return NULL; | ||
| 106 | } | ||
| 107 | sz = (len < 0) ? strlen(buf) : (size_t)len; | ||
| 108 | if (!(ret = BIO_new(BIO_s_mem()))) | ||
| 109 | return NULL; | ||
| 110 | b = (BUF_MEM *)ret->ptr; | ||
| 111 | b->data = buf; | ||
| 112 | b->length = sz; | ||
| 113 | b->max = sz; | ||
| 114 | ret->flags |= BIO_FLAGS_MEM_RDONLY; | ||
| 115 | /* Since this is static data retrying wont help */ | ||
| 116 | ret->num = 0; | ||
| 117 | return ret; | ||
| 118 | } | ||
| 119 | |||
| 120 | static int | ||
| 121 | mem_new(BIO *bi) | ||
| 122 | { | ||
| 123 | BUF_MEM *b; | ||
| 124 | |||
| 125 | if ((b = BUF_MEM_new()) == NULL) | ||
| 126 | return (0); | ||
| 127 | bi->shutdown = 1; | ||
| 128 | bi->init = 1; | ||
| 129 | bi->num = -1; | ||
| 130 | bi->ptr = (char *)b; | ||
| 131 | return (1); | ||
| 132 | } | ||
| 133 | |||
| 134 | static int | ||
| 135 | mem_free(BIO *a) | ||
| 136 | { | ||
| 137 | if (a == NULL) | ||
| 138 | return (0); | ||
| 139 | if (a->shutdown) { | ||
| 140 | if ((a->init) && (a->ptr != NULL)) { | ||
| 141 | BUF_MEM *b; | ||
| 142 | b = (BUF_MEM *)a->ptr; | ||
| 143 | if (a->flags & BIO_FLAGS_MEM_RDONLY) | ||
| 144 | b->data = NULL; | ||
| 145 | BUF_MEM_free(b); | ||
| 146 | a->ptr = NULL; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | return (1); | ||
| 150 | } | ||
| 151 | |||
| 152 | static int | ||
| 153 | mem_read(BIO *b, char *out, int outl) | ||
| 154 | { | ||
| 155 | int ret = -1; | ||
| 156 | BUF_MEM *bm; | ||
| 157 | |||
| 158 | bm = (BUF_MEM *)b->ptr; | ||
| 159 | BIO_clear_retry_flags(b); | ||
| 160 | ret = (outl >=0 && (size_t)outl > bm->length) ? (int)bm->length : outl; | ||
| 161 | if ((out != NULL) && (ret > 0)) { | ||
| 162 | memcpy(out, bm->data, ret); | ||
| 163 | bm->length -= ret; | ||
| 164 | if (b->flags & BIO_FLAGS_MEM_RDONLY) | ||
| 165 | bm->data += ret; | ||
| 166 | else { | ||
| 167 | memmove(&(bm->data[0]), &(bm->data[ret]), bm->length); | ||
| 168 | } | ||
| 169 | } else if (bm->length == 0) { | ||
| 170 | ret = b->num; | ||
| 171 | if (ret != 0) | ||
| 172 | BIO_set_retry_read(b); | ||
| 173 | } | ||
| 174 | return (ret); | ||
| 175 | } | ||
| 176 | |||
| 177 | static int | ||
| 178 | mem_write(BIO *b, const char *in, int inl) | ||
| 179 | { | ||
| 180 | int ret = -1; | ||
| 181 | int blen; | ||
| 182 | BUF_MEM *bm; | ||
| 183 | |||
| 184 | bm = (BUF_MEM *)b->ptr; | ||
| 185 | if (in == NULL) { | ||
| 186 | BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER); | ||
| 187 | goto end; | ||
| 188 | } | ||
| 189 | |||
| 190 | if (b->flags & BIO_FLAGS_MEM_RDONLY) { | ||
| 191 | BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO); | ||
| 192 | goto end; | ||
| 193 | } | ||
| 194 | |||
| 195 | BIO_clear_retry_flags(b); | ||
| 196 | blen = bm->length; | ||
| 197 | if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl)) | ||
| 198 | goto end; | ||
| 199 | memcpy(&(bm->data[blen]), in, inl); | ||
| 200 | ret = inl; | ||
| 201 | end: | ||
| 202 | return (ret); | ||
| 203 | } | ||
| 204 | |||
| 205 | static long | ||
| 206 | mem_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 207 | { | ||
| 208 | long ret = 1; | ||
| 209 | char **pptr; | ||
| 210 | |||
| 211 | BUF_MEM *bm = (BUF_MEM *)b->ptr; | ||
| 212 | |||
| 213 | switch (cmd) { | ||
| 214 | case BIO_CTRL_RESET: | ||
| 215 | if (bm->data != NULL) { | ||
| 216 | /* For read only case reset to the start again */ | ||
| 217 | if (b->flags & BIO_FLAGS_MEM_RDONLY) { | ||
| 218 | bm->data -= bm->max - bm->length; | ||
| 219 | bm->length = bm->max; | ||
| 220 | } else { | ||
| 221 | memset(bm->data, 0, bm->max); | ||
| 222 | bm->length = 0; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | break; | ||
| 226 | case BIO_CTRL_EOF: | ||
| 227 | ret = (long)(bm->length == 0); | ||
| 228 | break; | ||
| 229 | case BIO_C_SET_BUF_MEM_EOF_RETURN: | ||
| 230 | b->num = (int)num; | ||
| 231 | break; | ||
| 232 | case BIO_CTRL_INFO: | ||
| 233 | ret = (long)bm->length; | ||
| 234 | if (ptr != NULL) { | ||
| 235 | pptr = (char **)ptr; | ||
| 236 | *pptr = (char *)&(bm->data[0]); | ||
| 237 | } | ||
| 238 | break; | ||
| 239 | case BIO_C_SET_BUF_MEM: | ||
| 240 | mem_free(b); | ||
| 241 | b->shutdown = (int)num; | ||
| 242 | b->ptr = ptr; | ||
| 243 | break; | ||
| 244 | case BIO_C_GET_BUF_MEM_PTR: | ||
| 245 | if (ptr != NULL) { | ||
| 246 | pptr = (char **)ptr; | ||
| 247 | *pptr = (char *)bm; | ||
| 248 | } | ||
| 249 | break; | ||
| 250 | case BIO_CTRL_GET_CLOSE: | ||
| 251 | ret = (long)b->shutdown; | ||
| 252 | break; | ||
| 253 | case BIO_CTRL_SET_CLOSE: | ||
| 254 | b->shutdown = (int)num; | ||
| 255 | break; | ||
| 256 | |||
| 257 | case BIO_CTRL_WPENDING: | ||
| 258 | ret = 0L; | ||
| 259 | break; | ||
| 260 | case BIO_CTRL_PENDING: | ||
| 261 | ret = (long)bm->length; | ||
| 262 | break; | ||
| 263 | case BIO_CTRL_DUP: | ||
| 264 | case BIO_CTRL_FLUSH: | ||
| 265 | ret = 1; | ||
| 266 | break; | ||
| 267 | case BIO_CTRL_PUSH: | ||
| 268 | case BIO_CTRL_POP: | ||
| 269 | default: | ||
| 270 | ret = 0; | ||
| 271 | break; | ||
| 272 | } | ||
| 273 | return (ret); | ||
| 274 | } | ||
| 275 | |||
| 276 | static int | ||
| 277 | mem_gets(BIO *bp, char *buf, int size) | ||
| 278 | { | ||
| 279 | int i, j; | ||
| 280 | int ret = -1; | ||
| 281 | char *p; | ||
| 282 | BUF_MEM *bm = (BUF_MEM *)bp->ptr; | ||
| 283 | |||
| 284 | BIO_clear_retry_flags(bp); | ||
| 285 | j = bm->length; | ||
| 286 | if ((size - 1) < j) | ||
| 287 | j = size - 1; | ||
| 288 | if (j <= 0) { | ||
| 289 | *buf = '\0'; | ||
| 290 | return 0; | ||
| 291 | } | ||
| 292 | p = bm->data; | ||
| 293 | for (i = 0; i < j; i++) { | ||
| 294 | if (p[i] == '\n') { | ||
| 295 | i++; | ||
| 296 | break; | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | /* | ||
| 301 | * i is now the max num of bytes to copy, either j or up to | ||
| 302 | * and including the first newline | ||
| 303 | */ | ||
| 304 | |||
| 305 | i = mem_read(bp, buf, i); | ||
| 306 | if (i > 0) | ||
| 307 | buf[i] = '\0'; | ||
| 308 | ret = i; | ||
| 309 | return (ret); | ||
| 310 | } | ||
| 311 | |||
| 312 | static int | ||
| 313 | mem_puts(BIO *bp, const char *str) | ||
| 314 | { | ||
| 315 | int n, ret; | ||
| 316 | |||
| 317 | n = strlen(str); | ||
| 318 | ret = mem_write(bp, str, n); | ||
| 319 | /* memory semantics is that it will always work */ | ||
| 320 | return (ret); | ||
| 321 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c deleted file mode 100644 index 42ee626b13..0000000000 --- a/src/lib/libcrypto/bio/bss_null.c +++ /dev/null | |||
| @@ -1,158 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_null.c,v 1.10 2014/07/11 08:44:47 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/bio.h> | ||
| 64 | |||
| 65 | static int null_write(BIO *h, const char *buf, int num); | ||
| 66 | static int null_read(BIO *h, char *buf, int size); | ||
| 67 | static int null_puts(BIO *h, const char *str); | ||
| 68 | static int null_gets(BIO *h, char *str, int size); | ||
| 69 | static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 70 | static int null_new(BIO *h); | ||
| 71 | static int null_free(BIO *data); | ||
| 72 | |||
| 73 | static BIO_METHOD null_method = { | ||
| 74 | .type = BIO_TYPE_NULL, | ||
| 75 | .name = "NULL", | ||
| 76 | .bwrite = null_write, | ||
| 77 | .bread = null_read, | ||
| 78 | .bputs = null_puts, | ||
| 79 | .bgets = null_gets, | ||
| 80 | .ctrl = null_ctrl, | ||
| 81 | .create = null_new, | ||
| 82 | .destroy = null_free | ||
| 83 | }; | ||
| 84 | |||
| 85 | BIO_METHOD * | ||
| 86 | BIO_s_null(void) | ||
| 87 | { | ||
| 88 | return (&null_method); | ||
| 89 | } | ||
| 90 | |||
| 91 | static int | ||
| 92 | null_new(BIO *bi) | ||
| 93 | { | ||
| 94 | bi->init = 1; | ||
| 95 | bi->num = 0; | ||
| 96 | bi->ptr = (NULL); | ||
| 97 | return (1); | ||
| 98 | } | ||
| 99 | |||
| 100 | static int | ||
| 101 | null_free(BIO *a) | ||
| 102 | { | ||
| 103 | if (a == NULL) | ||
| 104 | return (0); | ||
| 105 | return (1); | ||
| 106 | } | ||
| 107 | |||
| 108 | static int | ||
| 109 | null_read(BIO *b, char *out, int outl) | ||
| 110 | { | ||
| 111 | return (0); | ||
| 112 | } | ||
| 113 | |||
| 114 | static int | ||
| 115 | null_write(BIO *b, const char *in, int inl) | ||
| 116 | { | ||
| 117 | return (inl); | ||
| 118 | } | ||
| 119 | |||
| 120 | static long | ||
| 121 | null_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 122 | { | ||
| 123 | long ret = 1; | ||
| 124 | |||
| 125 | switch (cmd) { | ||
| 126 | case BIO_CTRL_RESET: | ||
| 127 | case BIO_CTRL_EOF: | ||
| 128 | case BIO_CTRL_SET: | ||
| 129 | case BIO_CTRL_SET_CLOSE: | ||
| 130 | case BIO_CTRL_FLUSH: | ||
| 131 | case BIO_CTRL_DUP: | ||
| 132 | ret = 1; | ||
| 133 | break; | ||
| 134 | case BIO_CTRL_GET_CLOSE: | ||
| 135 | case BIO_CTRL_INFO: | ||
| 136 | case BIO_CTRL_GET: | ||
| 137 | case BIO_CTRL_PENDING: | ||
| 138 | case BIO_CTRL_WPENDING: | ||
| 139 | default: | ||
| 140 | ret = 0; | ||
| 141 | break; | ||
| 142 | } | ||
| 143 | return (ret); | ||
| 144 | } | ||
| 145 | |||
| 146 | static int | ||
| 147 | null_gets(BIO *bp, char *buf, int size) | ||
| 148 | { | ||
| 149 | return (0); | ||
| 150 | } | ||
| 151 | |||
| 152 | static int | ||
| 153 | null_puts(BIO *bp, const char *str) | ||
| 154 | { | ||
| 155 | if (str == NULL) | ||
| 156 | return (0); | ||
| 157 | return (strlen(str)); | ||
| 158 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c deleted file mode 100644 index dd470eb65e..0000000000 --- a/src/lib/libcrypto/bio/bss_sock.c +++ /dev/null | |||
| @@ -1,239 +0,0 @@ | |||
| 1 | /* $OpenBSD: bss_sock.c,v 1.23 2014/07/11 08:44:47 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <sys/socket.h> | ||
| 60 | |||
| 61 | #include <errno.h> | ||
| 62 | #include <stdio.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <unistd.h> | ||
| 65 | |||
| 66 | #include <openssl/bio.h> | ||
| 67 | |||
| 68 | static int sock_write(BIO *h, const char *buf, int num); | ||
| 69 | static int sock_read(BIO *h, char *buf, int size); | ||
| 70 | static int sock_puts(BIO *h, const char *str); | ||
| 71 | static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
| 72 | static int sock_new(BIO *h); | ||
| 73 | static int sock_free(BIO *data); | ||
| 74 | int BIO_sock_should_retry(int s); | ||
| 75 | |||
| 76 | static BIO_METHOD methods_sockp = { | ||
| 77 | .type = BIO_TYPE_SOCKET, | ||
| 78 | .name = "socket", | ||
| 79 | .bwrite = sock_write, | ||
| 80 | .bread = sock_read, | ||
| 81 | .bputs = sock_puts, | ||
| 82 | .ctrl = sock_ctrl, | ||
| 83 | .create = sock_new, | ||
| 84 | .destroy = sock_free | ||
| 85 | }; | ||
| 86 | |||
| 87 | BIO_METHOD * | ||
| 88 | BIO_s_socket(void) | ||
| 89 | { | ||
| 90 | return (&methods_sockp); | ||
| 91 | } | ||
| 92 | |||
| 93 | BIO * | ||
| 94 | BIO_new_socket(int fd, int close_flag) | ||
| 95 | { | ||
| 96 | BIO *ret; | ||
| 97 | |||
| 98 | ret = BIO_new(BIO_s_socket()); | ||
| 99 | if (ret == NULL) | ||
| 100 | return (NULL); | ||
| 101 | BIO_set_fd(ret, fd, close_flag); | ||
| 102 | return (ret); | ||
| 103 | } | ||
| 104 | |||
| 105 | static int | ||
| 106 | sock_new(BIO *bi) | ||
| 107 | { | ||
| 108 | bi->init = 0; | ||
| 109 | bi->num = 0; | ||
| 110 | bi->ptr = NULL; | ||
| 111 | bi->flags = 0; | ||
| 112 | return (1); | ||
| 113 | } | ||
| 114 | |||
| 115 | static int | ||
| 116 | sock_free(BIO *a) | ||
| 117 | { | ||
| 118 | if (a == NULL) | ||
| 119 | return (0); | ||
| 120 | if (a->shutdown) { | ||
| 121 | if (a->init) { | ||
| 122 | shutdown(a->num, SHUT_RDWR); | ||
| 123 | close(a->num); | ||
| 124 | } | ||
| 125 | a->init = 0; | ||
| 126 | a->flags = 0; | ||
| 127 | } | ||
| 128 | return (1); | ||
| 129 | } | ||
| 130 | |||
| 131 | static int | ||
| 132 | sock_read(BIO *b, char *out, int outl) | ||
| 133 | { | ||
| 134 | int ret = 0; | ||
| 135 | |||
| 136 | if (out != NULL) { | ||
| 137 | errno = 0; | ||
| 138 | ret = read(b->num, out, outl); | ||
| 139 | BIO_clear_retry_flags(b); | ||
| 140 | if (ret <= 0) { | ||
| 141 | if (BIO_sock_should_retry(ret)) | ||
| 142 | BIO_set_retry_read(b); | ||
| 143 | } | ||
| 144 | } | ||
| 145 | return (ret); | ||
| 146 | } | ||
| 147 | |||
| 148 | static int | ||
| 149 | sock_write(BIO *b, const char *in, int inl) | ||
| 150 | { | ||
| 151 | int ret; | ||
| 152 | |||
| 153 | errno = 0; | ||
| 154 | ret = write(b->num, in, inl); | ||
| 155 | BIO_clear_retry_flags(b); | ||
| 156 | if (ret <= 0) { | ||
| 157 | if (BIO_sock_should_retry(ret)) | ||
| 158 | BIO_set_retry_write(b); | ||
| 159 | } | ||
| 160 | return (ret); | ||
| 161 | } | ||
| 162 | |||
| 163 | static long | ||
| 164 | sock_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
| 165 | { | ||
| 166 | long ret = 1; | ||
| 167 | int *ip; | ||
| 168 | |||
| 169 | switch (cmd) { | ||
| 170 | case BIO_C_SET_FD: | ||
| 171 | sock_free(b); | ||
| 172 | b->num= *((int *)ptr); | ||
| 173 | b->shutdown = (int)num; | ||
| 174 | b->init = 1; | ||
| 175 | break; | ||
| 176 | case BIO_C_GET_FD: | ||
| 177 | if (b->init) { | ||
| 178 | ip = (int *)ptr; | ||
| 179 | if (ip != NULL) | ||
| 180 | *ip = b->num; | ||
| 181 | ret = b->num; | ||
| 182 | } else | ||
| 183 | ret = -1; | ||
| 184 | break; | ||
| 185 | case BIO_CTRL_GET_CLOSE: | ||
| 186 | ret = b->shutdown; | ||
| 187 | break; | ||
| 188 | case BIO_CTRL_SET_CLOSE: | ||
| 189 | b->shutdown = (int)num; | ||
| 190 | break; | ||
| 191 | case BIO_CTRL_DUP: | ||
| 192 | case BIO_CTRL_FLUSH: | ||
| 193 | ret = 1; | ||
| 194 | break; | ||
| 195 | default: | ||
| 196 | ret = 0; | ||
| 197 | break; | ||
| 198 | } | ||
| 199 | return (ret); | ||
| 200 | } | ||
| 201 | |||
| 202 | static int | ||
| 203 | sock_puts(BIO *bp, const char *str) | ||
| 204 | { | ||
| 205 | int n, ret; | ||
| 206 | |||
| 207 | n = strlen(str); | ||
| 208 | ret = sock_write(bp, str, n); | ||
| 209 | return (ret); | ||
| 210 | } | ||
| 211 | |||
| 212 | int | ||
| 213 | BIO_sock_should_retry(int i) | ||
| 214 | { | ||
| 215 | int err; | ||
| 216 | |||
| 217 | if ((i == 0) || (i == -1)) { | ||
| 218 | err = errno; | ||
| 219 | return (BIO_sock_non_fatal_error(err)); | ||
| 220 | } | ||
| 221 | return (0); | ||
| 222 | } | ||
| 223 | |||
| 224 | int | ||
| 225 | BIO_sock_non_fatal_error(int err) | ||
| 226 | { | ||
| 227 | switch (err) { | ||
| 228 | case ENOTCONN: | ||
| 229 | case EINTR: | ||
| 230 | case EAGAIN: | ||
| 231 | case EINPROGRESS: | ||
| 232 | case EALREADY: | ||
| 233 | return (1); | ||
| 234 | default: | ||
| 235 | break; | ||
| 236 | } | ||
| 237 | return (0); | ||
| 238 | } | ||
| 239 | |||
