diff options
Diffstat (limited to 'src/lib/libcrypto/bio')
-rw-r--r-- | src/lib/libcrypto/bio/Makefile.ssl | 216 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_print.c | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 242 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio.h | 64 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_cb.c | 24 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_err.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_acpt.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_dgram.c | 380 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_fd.c | 27 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 67 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_log.c | 55 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_mem.c | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_sock.c | 13 |
14 files changed, 688 insertions, 441 deletions
diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl deleted file mode 100644 index d0b9e297b0..0000000000 --- a/src/lib/libcrypto/bio/Makefile.ssl +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/bio/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bio | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
12 | INSTALLTOP=/usr/local/ssl | ||
13 | MAKE= make -f Makefile.ssl | ||
14 | MAKEDEPPROG= makedepend | ||
15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
16 | MAKEFILE= Makefile.ssl | ||
17 | AR= ar r | ||
18 | |||
19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | TEST= | ||
23 | APPS= | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC= bio_lib.c bio_cb.c bio_err.c \ | ||
27 | bss_mem.c bss_null.c bss_fd.c \ | ||
28 | bss_file.c bss_sock.c bss_conn.c \ | ||
29 | bf_null.c bf_buff.c b_print.c b_dump.c \ | ||
30 | b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c | ||
31 | # bf_lbuf.c | ||
32 | LIBOBJ= bio_lib.o bio_cb.o bio_err.o \ | ||
33 | bss_mem.o bss_null.o bss_fd.o \ | ||
34 | bss_file.o bss_sock.o bss_conn.o \ | ||
35 | bf_null.o bf_buff.o b_print.o b_dump.o \ | ||
36 | b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o | ||
37 | # bf_lbuf.o | ||
38 | |||
39 | SRC= $(LIBSRC) | ||
40 | |||
41 | EXHEADER= bio.h | ||
42 | HEADER= bss_file.c $(EXHEADER) | ||
43 | |||
44 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
45 | |||
46 | top: | ||
47 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
48 | |||
49 | all: lib | ||
50 | |||
51 | lib: $(LIBOBJ) | ||
52 | $(AR) $(LIB) $(LIBOBJ) | ||
53 | $(RANLIB) $(LIB) || echo Never mind. | ||
54 | @touch lib | ||
55 | |||
56 | files: | ||
57 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
58 | |||
59 | links: | ||
60 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
61 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
62 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
63 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
64 | |||
65 | install: | ||
66 | @for i in $(EXHEADER); \ | ||
67 | do \ | ||
68 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
69 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
70 | done; | ||
71 | |||
72 | tags: | ||
73 | ctags $(SRC) | ||
74 | |||
75 | tests: | ||
76 | |||
77 | lint: | ||
78 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
79 | |||
80 | depend: | ||
81 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
82 | |||
83 | dclean: | ||
84 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
85 | mv -f Makefile.new $(MAKEFILE) | ||
86 | |||
87 | clean: | ||
88 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
89 | |||
90 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
91 | |||
92 | b_dump.o: ../../e_os.h ../../include/openssl/bio.h | ||
93 | b_dump.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
94 | b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
95 | b_dump.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
96 | b_dump.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
97 | b_dump.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
98 | b_dump.o: ../cryptlib.h b_dump.c | ||
99 | b_print.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
100 | b_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
101 | b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
102 | b_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
103 | b_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
104 | b_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
105 | b_print.o: ../cryptlib.h b_print.c | ||
106 | b_sock.o: ../../e_os.h ../../include/openssl/bio.h | ||
107 | b_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
108 | b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
109 | b_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
110 | b_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
111 | b_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
112 | b_sock.o: ../cryptlib.h b_sock.c | ||
113 | bf_buff.o: ../../e_os.h ../../include/openssl/bio.h | ||
114 | bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
115 | bf_buff.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
116 | bf_buff.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
117 | bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
118 | bf_buff.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
119 | bf_buff.o: ../cryptlib.h bf_buff.c | ||
120 | bf_nbio.o: ../../e_os.h ../../include/openssl/bio.h | ||
121 | bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
122 | bf_nbio.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
123 | bf_nbio.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
124 | bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
125 | bf_nbio.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
126 | bf_nbio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
127 | bf_nbio.o: ../cryptlib.h bf_nbio.c | ||
128 | bf_null.o: ../../e_os.h ../../include/openssl/bio.h | ||
129 | bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
130 | bf_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
131 | bf_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
132 | bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
133 | bf_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
134 | bf_null.o: ../cryptlib.h bf_null.c | ||
135 | bio_cb.o: ../../e_os.h ../../include/openssl/bio.h | ||
136 | bio_cb.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
137 | bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
138 | bio_cb.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
139 | bio_cb.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
140 | bio_cb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
141 | bio_cb.o: ../cryptlib.h bio_cb.c | ||
142 | bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
143 | bio_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
144 | bio_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
145 | bio_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
146 | bio_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
147 | bio_err.o: bio_err.c | ||
148 | bio_lib.o: ../../e_os.h ../../include/openssl/bio.h | ||
149 | bio_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
150 | bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
151 | bio_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
152 | bio_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
153 | bio_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
154 | bio_lib.o: ../cryptlib.h bio_lib.c | ||
155 | bss_acpt.o: ../../e_os.h ../../include/openssl/bio.h | ||
156 | bss_acpt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
157 | bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
158 | bss_acpt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
159 | bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
160 | bss_acpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
161 | bss_acpt.o: ../cryptlib.h bss_acpt.c | ||
162 | bss_bio.o: ../../e_os.h ../../include/openssl/bio.h | ||
163 | bss_bio.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
164 | bss_bio.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
165 | bss_bio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
166 | bss_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
167 | bss_bio.o: ../../include/openssl/symhacks.h bss_bio.c | ||
168 | bss_conn.o: ../../e_os.h ../../include/openssl/bio.h | ||
169 | bss_conn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
170 | bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
171 | bss_conn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
172 | bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
173 | bss_conn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
174 | bss_conn.o: ../cryptlib.h bss_conn.c | ||
175 | bss_fd.o: ../../e_os.h ../../include/openssl/bio.h | ||
176 | bss_fd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
177 | bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
178 | bss_fd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
179 | bss_fd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
180 | bss_fd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
181 | bss_fd.o: ../cryptlib.h bss_fd.c | ||
182 | bss_file.o: ../../e_os.h ../../include/openssl/bio.h | ||
183 | bss_file.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
184 | bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
185 | bss_file.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
186 | bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
187 | bss_file.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
188 | bss_file.o: ../cryptlib.h bss_file.c | ||
189 | bss_log.o: ../../e_os.h ../../include/openssl/bio.h | ||
190 | bss_log.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
191 | bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
192 | bss_log.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
193 | bss_log.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
194 | bss_log.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
195 | bss_log.o: ../cryptlib.h bss_log.c | ||
196 | bss_mem.o: ../../e_os.h ../../include/openssl/bio.h | ||
197 | bss_mem.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
198 | bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
199 | bss_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
200 | bss_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
201 | bss_mem.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
202 | bss_mem.o: ../cryptlib.h bss_mem.c | ||
203 | bss_null.o: ../../e_os.h ../../include/openssl/bio.h | ||
204 | bss_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
205 | bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
206 | bss_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
207 | bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
208 | bss_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
209 | bss_null.o: ../cryptlib.h bss_null.c | ||
210 | bss_sock.o: ../../e_os.h ../../include/openssl/bio.h | ||
211 | bss_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
212 | bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
213 | bss_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
214 | bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
215 | bss_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
216 | bss_sock.o: ../cryptlib.h bss_sock.c | ||
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index 2fffcfc025..143a7cfefa 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c | |||
@@ -115,8 +115,8 @@ | |||
115 | #define LDOUBLE double | 115 | #define LDOUBLE double |
116 | #endif | 116 | #endif |
117 | 117 | ||
118 | #if HAVE_LONG_LONG | 118 | #ifdef HAVE_LONG_LONG |
119 | # if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__) | 119 | # if defined(_WIN32) && !defined(__GNUC__) |
120 | # define LLONG __int64 | 120 | # define LLONG __int64 |
121 | # else | 121 | # else |
122 | # define LLONG long long | 122 | # define LLONG long long |
@@ -808,7 +808,6 @@ int BIO_vprintf (BIO *bio, const char *format, va_list args) | |||
808 | } | 808 | } |
809 | 809 | ||
810 | /* As snprintf is not available everywhere, we provide our own implementation. | 810 | /* As snprintf is not available everywhere, we provide our own implementation. |
811 | * In case of overflow or error, this returns -1. | ||
812 | * This function has nothing to do with BIOs, but it's closely related | 811 | * This function has nothing to do with BIOs, but it's closely related |
813 | * to BIO_printf, and we need *some* name prefix ... | 812 | * to BIO_printf, and we need *some* name prefix ... |
814 | * (XXX the function should be renamed, but to what?) */ | 813 | * (XXX the function should be renamed, but to what?) */ |
@@ -833,10 +832,10 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | |||
833 | _dopr(&buf, NULL, &n, &retlen, &truncated, format, args); | 832 | _dopr(&buf, NULL, &n, &retlen, &truncated, format, args); |
834 | 833 | ||
835 | if (truncated) | 834 | if (truncated) |
836 | /* In case of truncation, return -1 unlike traditional snprintf. | 835 | /* In case of truncation, return -1 like traditional snprintf. |
837 | * (Current drafts for ISO/IEC 9899 say snprintf should return | 836 | * (Current drafts for ISO/IEC 9899 say snprintf should return |
838 | * the number of characters that would have been written, | 837 | * the number of characters that would have been written, |
839 | * had the buffer been large enough, as it did historically.) */ | 838 | * had the buffer been large enough.) */ |
840 | return -1; | 839 | return -1; |
841 | else | 840 | else |
842 | return (retlen <= INT_MAX) ? (int)retlen : -1; | 841 | return (retlen <= INT_MAX) ? (int)retlen : -1; |
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index ead477d8a2..12b0a53a81 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -72,11 +72,9 @@ NETDB_DEFINE_CONTEXT | |||
72 | 72 | ||
73 | #ifndef OPENSSL_NO_SOCK | 73 | #ifndef OPENSSL_NO_SOCK |
74 | 74 | ||
75 | #ifdef OPENSSL_SYS_WIN16 | 75 | #include <openssl/dso.h> |
76 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ | 76 | |
77 | #else | ||
78 | #define SOCKET_PROTOCOL IPPROTO_TCP | 77 | #define SOCKET_PROTOCOL IPPROTO_TCP |
79 | #endif | ||
80 | 78 | ||
81 | #ifdef SO_MAXCONN | 79 | #ifdef SO_MAXCONN |
82 | #define MAX_LISTEN SO_MAXCONN | 80 | #define MAX_LISTEN SO_MAXCONN |
@@ -90,6 +88,17 @@ NETDB_DEFINE_CONTEXT | |||
90 | static int wsa_init_done=0; | 88 | static int wsa_init_done=0; |
91 | #endif | 89 | #endif |
92 | 90 | ||
91 | /* | ||
92 | * WSAAPI specifier is required to make indirect calls to run-time | ||
93 | * linked WinSock 2 functions used in this module, to be specific | ||
94 | * [get|free]addrinfo and getnameinfo. This is because WinSock uses | ||
95 | * uses non-C calling convention, __stdcall vs. __cdecl, on x86 | ||
96 | * Windows. On non-WinSock platforms WSAAPI needs to be void. | ||
97 | */ | ||
98 | #ifndef WSAAPI | ||
99 | #define WSAAPI | ||
100 | #endif | ||
101 | |||
93 | #if 0 | 102 | #if 0 |
94 | static unsigned long BIO_ghbn_hits=0L; | 103 | static unsigned long BIO_ghbn_hits=0L; |
95 | static unsigned long BIO_ghbn_miss=0L; | 104 | static unsigned long BIO_ghbn_miss=0L; |
@@ -226,6 +235,10 @@ int BIO_sock_error(int sock) | |||
226 | int j,i; | 235 | int j,i; |
227 | int size; | 236 | int size; |
228 | 237 | ||
238 | #if defined(OPENSSL_SYS_BEOS_R5) | ||
239 | return 0; | ||
240 | #endif | ||
241 | |||
229 | size=sizeof(int); | 242 | size=sizeof(int); |
230 | /* Note: under Windows the third parameter is of type (char *) | 243 | /* Note: under Windows the third parameter is of type (char *) |
231 | * whereas under other systems it is (void *) if you don't have | 244 | * whereas under other systems it is (void *) if you don't have |
@@ -466,7 +479,12 @@ int BIO_sock_init(void) | |||
466 | 479 | ||
467 | wsa_init_done=1; | 480 | wsa_init_done=1; |
468 | memset(&wsa_state,0,sizeof(wsa_state)); | 481 | memset(&wsa_state,0,sizeof(wsa_state)); |
469 | if (WSAStartup(0x0101,&wsa_state)!=0) | 482 | /* Not making wsa_state available to the rest of the |
483 | * code is formally wrong. But the structures we use | ||
484 | * are [beleived to be] invariable among Winsock DLLs, | ||
485 | * while API availability is [expected to be] probed | ||
486 | * at run-time with DSO_global_lookup. */ | ||
487 | if (WSAStartup(0x0202,&wsa_state)!=0) | ||
470 | { | 488 | { |
471 | err=WSAGetLastError(); | 489 | err=WSAGetLastError(); |
472 | SYSerr(SYS_F_WSASTARTUP,err); | 490 | SYSerr(SYS_F_WSASTARTUP,err); |
@@ -510,8 +528,8 @@ void BIO_sock_cleanup(void) | |||
510 | if (wsa_init_done) | 528 | if (wsa_init_done) |
511 | { | 529 | { |
512 | wsa_init_done=0; | 530 | wsa_init_done=0; |
513 | #ifndef OPENSSL_SYS_WINCE | 531 | #if 0 /* this call is claimed to be non-present in Winsock2 */ |
514 | WSACancelBlockingCall(); /* Winsock 1.1 specific */ | 532 | WSACancelBlockingCall(); |
515 | #endif | 533 | #endif |
516 | WSACleanup(); | 534 | WSACleanup(); |
517 | } | 535 | } |
@@ -581,12 +599,18 @@ static int get_ip(const char *str, unsigned char ip[4]) | |||
581 | int BIO_get_accept_socket(char *host, int bind_mode) | 599 | int BIO_get_accept_socket(char *host, int bind_mode) |
582 | { | 600 | { |
583 | int ret=0; | 601 | int ret=0; |
584 | struct sockaddr_in server,client; | 602 | union { |
585 | int s=INVALID_SOCKET,cs; | 603 | struct sockaddr sa; |
604 | struct sockaddr_in sa_in; | ||
605 | #if OPENSSL_USE_IPV6 | ||
606 | struct sockaddr_in6 sa_in6; | ||
607 | #endif | ||
608 | } server,client; | ||
609 | int s=INVALID_SOCKET,cs,addrlen; | ||
586 | unsigned char ip[4]; | 610 | unsigned char ip[4]; |
587 | unsigned short port; | 611 | unsigned short port; |
588 | char *str=NULL,*e; | 612 | char *str=NULL,*e; |
589 | const char *h,*p; | 613 | char *h,*p; |
590 | unsigned long l; | 614 | unsigned long l; |
591 | int err_num; | 615 | int err_num; |
592 | 616 | ||
@@ -600,8 +624,7 @@ int BIO_get_accept_socket(char *host, int bind_mode) | |||
600 | { | 624 | { |
601 | if (*e == ':') | 625 | if (*e == ':') |
602 | { | 626 | { |
603 | p= &(e[1]); | 627 | p=e; |
604 | *e='\0'; | ||
605 | } | 628 | } |
606 | else if (*e == '/') | 629 | else if (*e == '/') |
607 | { | 630 | { |
@@ -609,21 +632,70 @@ int BIO_get_accept_socket(char *host, int bind_mode) | |||
609 | break; | 632 | break; |
610 | } | 633 | } |
611 | } | 634 | } |
612 | 635 | if (p) *p++='\0'; /* points at last ':', '::port' is special [see below] */ | |
613 | if (p == NULL) | 636 | else p=h,h=NULL; |
637 | |||
638 | #ifdef EAI_FAMILY | ||
639 | do { | ||
640 | static union { void *p; | ||
641 | int (WSAAPI *f)(const char *,const char *, | ||
642 | const struct addrinfo *, | ||
643 | struct addrinfo **); | ||
644 | } p_getaddrinfo = {NULL}; | ||
645 | static union { void *p; | ||
646 | void (WSAAPI *f)(struct addrinfo *); | ||
647 | } p_freeaddrinfo = {NULL}; | ||
648 | struct addrinfo *res,hint; | ||
649 | |||
650 | if (p_getaddrinfo.p==NULL) | ||
651 | { | ||
652 | if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL || | ||
653 | (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL) | ||
654 | p_getaddrinfo.p=(void*)-1; | ||
655 | } | ||
656 | if (p_getaddrinfo.p==(void *)-1) break; | ||
657 | |||
658 | /* '::port' enforces IPv6 wildcard listener. Some OSes, | ||
659 | * e.g. Solaris, default to IPv6 without any hint. Also | ||
660 | * note that commonly IPv6 wildchard socket can service | ||
661 | * IPv4 connections just as well... */ | ||
662 | memset(&hint,0,sizeof(hint)); | ||
663 | if (h) | ||
614 | { | 664 | { |
615 | p=h; | 665 | if (strchr(h,':')) |
616 | h="*"; | 666 | { |
667 | if (h[1]=='\0') h=NULL; | ||
668 | #if OPENSSL_USE_IPV6 | ||
669 | hint.ai_family = AF_INET6; | ||
670 | #else | ||
671 | h=NULL; | ||
672 | #endif | ||
673 | } | ||
674 | else if (h[0]=='*' && h[1]=='\0') | ||
675 | h=NULL; | ||
617 | } | 676 | } |
618 | 677 | ||
678 | if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break; | ||
679 | |||
680 | addrlen = res->ai_addrlen<=sizeof(server) ? | ||
681 | res->ai_addrlen : | ||
682 | sizeof(server); | ||
683 | memcpy(&server, res->ai_addr, addrlen); | ||
684 | |||
685 | (*p_freeaddrinfo.f)(res); | ||
686 | goto again; | ||
687 | } while (0); | ||
688 | #endif | ||
689 | |||
619 | if (!BIO_get_port(p,&port)) goto err; | 690 | if (!BIO_get_port(p,&port)) goto err; |
620 | 691 | ||
621 | memset((char *)&server,0,sizeof(server)); | 692 | memset((char *)&server,0,sizeof(server)); |
622 | server.sin_family=AF_INET; | 693 | server.sa_in.sin_family=AF_INET; |
623 | server.sin_port=htons(port); | 694 | server.sa_in.sin_port=htons(port); |
695 | addrlen = sizeof(server.sa_in); | ||
624 | 696 | ||
625 | if (strcmp(h,"*") == 0) | 697 | if (h == NULL || strcmp(h,"*") == 0) |
626 | server.sin_addr.s_addr=INADDR_ANY; | 698 | server.sa_in.sin_addr.s_addr=INADDR_ANY; |
627 | else | 699 | else |
628 | { | 700 | { |
629 | if (!BIO_get_host_ip(h,&(ip[0]))) goto err; | 701 | if (!BIO_get_host_ip(h,&(ip[0]))) goto err; |
@@ -632,11 +704,11 @@ int BIO_get_accept_socket(char *host, int bind_mode) | |||
632 | ((unsigned long)ip[1]<<16L)| | 704 | ((unsigned long)ip[1]<<16L)| |
633 | ((unsigned long)ip[2]<< 8L)| | 705 | ((unsigned long)ip[2]<< 8L)| |
634 | ((unsigned long)ip[3]); | 706 | ((unsigned long)ip[3]); |
635 | server.sin_addr.s_addr=htonl(l); | 707 | server.sa_in.sin_addr.s_addr=htonl(l); |
636 | } | 708 | } |
637 | 709 | ||
638 | again: | 710 | again: |
639 | s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | 711 | s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); |
640 | if (s == INVALID_SOCKET) | 712 | if (s == INVALID_SOCKET) |
641 | { | 713 | { |
642 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | 714 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); |
@@ -654,22 +726,42 @@ again: | |||
654 | bind_mode=BIO_BIND_NORMAL; | 726 | bind_mode=BIO_BIND_NORMAL; |
655 | } | 727 | } |
656 | #endif | 728 | #endif |
657 | if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) | 729 | if (bind(s,&server.sa,addrlen) == -1) |
658 | { | 730 | { |
659 | #ifdef SO_REUSEADDR | 731 | #ifdef SO_REUSEADDR |
660 | err_num=get_last_socket_error(); | 732 | err_num=get_last_socket_error(); |
661 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && | 733 | if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && |
734 | #ifdef OPENSSL_SYS_WINDOWS | ||
735 | /* Some versions of Windows define EADDRINUSE to | ||
736 | * a dummy value. | ||
737 | */ | ||
738 | (err_num == WSAEADDRINUSE)) | ||
739 | #else | ||
662 | (err_num == EADDRINUSE)) | 740 | (err_num == EADDRINUSE)) |
741 | #endif | ||
663 | { | 742 | { |
664 | memcpy((char *)&client,(char *)&server,sizeof(server)); | 743 | client = server; |
665 | if (strcmp(h,"*") == 0) | 744 | if (h == NULL || strcmp(h,"*") == 0) |
666 | client.sin_addr.s_addr=htonl(0x7F000001); | 745 | { |
667 | cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | 746 | #if OPENSSL_USE_IPV6 |
747 | if (client.sa.sa_family == AF_INET6) | ||
748 | { | ||
749 | memset(&client.sa_in6.sin6_addr,0,sizeof(client.sa_in6.sin6_addr)); | ||
750 | client.sa_in6.sin6_addr.s6_addr[15]=1; | ||
751 | } | ||
752 | else | ||
753 | #endif | ||
754 | if (client.sa.sa_family == AF_INET) | ||
755 | { | ||
756 | client.sa_in.sin_addr.s_addr=htonl(0x7F000001); | ||
757 | } | ||
758 | else goto err; | ||
759 | } | ||
760 | cs=socket(client.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); | ||
668 | if (cs != INVALID_SOCKET) | 761 | if (cs != INVALID_SOCKET) |
669 | { | 762 | { |
670 | int ii; | 763 | int ii; |
671 | ii=connect(cs,(struct sockaddr *)&client, | 764 | ii=connect(cs,&client.sa,addrlen); |
672 | sizeof(client)); | ||
673 | closesocket(cs); | 765 | closesocket(cs); |
674 | if (ii == INVALID_SOCKET) | 766 | if (ii == INVALID_SOCKET) |
675 | { | 767 | { |
@@ -708,20 +800,52 @@ err: | |||
708 | int BIO_accept(int sock, char **addr) | 800 | int BIO_accept(int sock, char **addr) |
709 | { | 801 | { |
710 | int ret=INVALID_SOCKET; | 802 | int ret=INVALID_SOCKET; |
711 | static struct sockaddr_in from; | ||
712 | unsigned long l; | 803 | unsigned long l; |
713 | unsigned short port; | 804 | unsigned short port; |
714 | int len; | ||
715 | char *p; | 805 | char *p; |
716 | 806 | ||
717 | memset((char *)&from,0,sizeof(from)); | 807 | struct { |
718 | len=sizeof(from); | 808 | /* |
719 | /* Note: under VMS with SOCKETSHR the fourth parameter is currently | 809 | * As for following union. Trouble is that there are platforms |
720 | * of type (int *) whereas under other systems it is (void *) if | 810 | * that have socklen_t and there are platforms that don't, on |
721 | * you don't have a cast it will choke the compiler: if you do | 811 | * some platforms socklen_t is int and on some size_t. So what |
722 | * have a cast then you can either go for (int *) or (void *). | 812 | * one can do? One can cook #ifdef spaghetti, which is nothing |
813 | * but masochistic. Or one can do union between int and size_t. | ||
814 | * One naturally does it primarily for 64-bit platforms where | ||
815 | * sizeof(int) != sizeof(size_t). But would it work? Note that | ||
816 | * if size_t member is initialized to 0, then later int member | ||
817 | * assignment naturally does the job on little-endian platforms | ||
818 | * regardless accept's expectations! What about big-endians? | ||
819 | * If accept expects int*, then it works, and if size_t*, then | ||
820 | * length value would appear as unreasonably large. But this | ||
821 | * won't prevent it from filling in the address structure. The | ||
822 | * trouble of course would be if accept returns more data than | ||
823 | * actual buffer can accomodate and overwrite stack... That's | ||
824 | * where early OPENSSL_assert comes into picture. Besides, the | ||
825 | * only 64-bit big-endian platform found so far that expects | ||
826 | * size_t* is HP-UX, where stack grows towards higher address. | ||
827 | * <appro> | ||
723 | */ | 828 | */ |
724 | ret=accept(sock,(struct sockaddr *)&from,(void *)&len); | 829 | union { size_t s; int i; } len; |
830 | union { | ||
831 | struct sockaddr sa; | ||
832 | struct sockaddr_in sa_in; | ||
833 | #if OPENSSL_USE_IPV6 | ||
834 | struct sockaddr_in6 sa_in6; | ||
835 | #endif | ||
836 | } from; | ||
837 | } sa; | ||
838 | |||
839 | sa.len.s=0; | ||
840 | sa.len.i=sizeof(sa.from); | ||
841 | memset(&sa.from,0,sizeof(sa.from)); | ||
842 | ret=accept(sock,&sa.from.sa,(void *)&sa.len); | ||
843 | if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0) | ||
844 | { | ||
845 | OPENSSL_assert(sa.len.s<=sizeof(sa.from)); | ||
846 | sa.len.i = (int)sa.len.s; | ||
847 | /* use sa.len.i from this point */ | ||
848 | } | ||
725 | if (ret == INVALID_SOCKET) | 849 | if (ret == INVALID_SOCKET) |
726 | { | 850 | { |
727 | if(BIO_sock_should_retry(ret)) return -2; | 851 | if(BIO_sock_should_retry(ret)) return -2; |
@@ -732,8 +856,46 @@ int BIO_accept(int sock, char **addr) | |||
732 | 856 | ||
733 | if (addr == NULL) goto end; | 857 | if (addr == NULL) goto end; |
734 | 858 | ||
735 | l=ntohl(from.sin_addr.s_addr); | 859 | #ifdef EAI_FAMILY |
736 | port=ntohs(from.sin_port); | 860 | do { |
861 | char h[NI_MAXHOST],s[NI_MAXSERV]; | ||
862 | size_t nl; | ||
863 | static union { void *p; | ||
864 | int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/, | ||
865 | char *,size_t,char *,size_t,int); | ||
866 | } p_getnameinfo = {NULL}; | ||
867 | /* 2nd argument to getnameinfo is specified to | ||
868 | * be socklen_t. Unfortunately there is a number | ||
869 | * of environments where socklen_t is not defined. | ||
870 | * As it's passed by value, it's safe to pass it | ||
871 | * as size_t... <appro> */ | ||
872 | |||
873 | if (p_getnameinfo.p==NULL) | ||
874 | { | ||
875 | if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL) | ||
876 | p_getnameinfo.p=(void*)-1; | ||
877 | } | ||
878 | if (p_getnameinfo.p==(void *)-1) break; | ||
879 | |||
880 | if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s), | ||
881 | NI_NUMERICHOST|NI_NUMERICSERV)) break; | ||
882 | nl = strlen(h)+strlen(s)+2; | ||
883 | p = *addr; | ||
884 | if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); } | ||
885 | else { p = OPENSSL_malloc(nl); } | ||
886 | if (p==NULL) | ||
887 | { | ||
888 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
889 | goto end; | ||
890 | } | ||
891 | *addr = p; | ||
892 | BIO_snprintf(*addr,nl,"%s:%s",h,s); | ||
893 | goto end; | ||
894 | } while(0); | ||
895 | #endif | ||
896 | if (sa.from.sa.sa_family != AF_INET) goto end; | ||
897 | l=ntohl(sa.from.sa_in.sin_addr.s_addr); | ||
898 | port=ntohs(sa.from.sa_in.sin_port); | ||
737 | if (*addr == NULL) | 899 | if (*addr == NULL) |
738 | { | 900 | { |
739 | if ((p=OPENSSL_malloc(24)) == NULL) | 901 | if ((p=OPENSSL_malloc(24)) == NULL) |
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index cecb6a7207..152802fbdf 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h | |||
@@ -95,6 +95,7 @@ extern "C" { | |||
95 | #define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ | 95 | #define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ |
96 | #define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ | 96 | #define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ |
97 | #define BIO_TYPE_DGRAM (21|0x0400|0x0100) | 97 | #define BIO_TYPE_DGRAM (21|0x0400|0x0100) |
98 | #define BIO_TYPE_ASN1 (22|0x0200) /* filter */ | ||
98 | #define BIO_TYPE_COMP (23|0x0200) /* filter */ | 99 | #define BIO_TYPE_COMP (23|0x0200) /* filter */ |
99 | 100 | ||
100 | #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ | 101 | #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ |
@@ -156,8 +157,11 @@ extern "C" { | |||
156 | * previous write | 157 | * previous write |
157 | * operation */ | 158 | * operation */ |
158 | 159 | ||
160 | #define BIO_CTRL_DGRAM_GET_PEER 46 | ||
159 | #define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ | 161 | #define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ |
160 | 162 | ||
163 | #define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45 /* Next DTLS handshake timeout to | ||
164 | * adjust socket timeouts */ | ||
161 | 165 | ||
162 | /* modifiers */ | 166 | /* modifiers */ |
163 | #define BIO_FP_READ 0x02 | 167 | #define BIO_FP_READ 0x02 |
@@ -262,7 +266,6 @@ int BIO_method_type(const BIO *b); | |||
262 | 266 | ||
263 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); | 267 | typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); |
264 | 268 | ||
265 | #ifndef OPENSSL_SYS_WIN16 | ||
266 | typedef struct bio_method_st | 269 | typedef struct bio_method_st |
267 | { | 270 | { |
268 | int type; | 271 | int type; |
@@ -276,21 +279,6 @@ typedef struct bio_method_st | |||
276 | int (*destroy)(BIO *); | 279 | int (*destroy)(BIO *); |
277 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); | 280 | long (*callback_ctrl)(BIO *, int, bio_info_cb *); |
278 | } BIO_METHOD; | 281 | } BIO_METHOD; |
279 | #else | ||
280 | typedef struct bio_method_st | ||
281 | { | ||
282 | int type; | ||
283 | const char *name; | ||
284 | int (_far *bwrite)(); | ||
285 | int (_far *bread)(); | ||
286 | int (_far *bputs)(); | ||
287 | int (_far *bgets)(); | ||
288 | long (_far *ctrl)(); | ||
289 | int (_far *create)(); | ||
290 | int (_far *destroy)(); | ||
291 | long (_far *callback_ctrl)(); | ||
292 | } BIO_METHOD; | ||
293 | #endif | ||
294 | 282 | ||
295 | struct bio_st | 283 | struct bio_st |
296 | { | 284 | { |
@@ -331,6 +319,9 @@ typedef struct bio_f_buffer_ctx_struct | |||
331 | int obuf_off; /* write/read offset */ | 319 | int obuf_off; /* write/read offset */ |
332 | } BIO_F_BUFFER_CTX; | 320 | } BIO_F_BUFFER_CTX; |
333 | 321 | ||
322 | /* Prefix and suffix callback in ASN1 BIO */ | ||
323 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); | ||
324 | |||
334 | /* connect BIO stuff */ | 325 | /* connect BIO stuff */ |
335 | #define BIO_CONN_S_BEFORE 1 | 326 | #define BIO_CONN_S_BEFORE 1 |
336 | #define BIO_CONN_S_GET_IP 2 | 327 | #define BIO_CONN_S_GET_IP 2 |
@@ -393,6 +384,13 @@ typedef struct bio_f_buffer_ctx_struct | |||
393 | #define BIO_C_RESET_READ_REQUEST 147 | 384 | #define BIO_C_RESET_READ_REQUEST 147 |
394 | #define BIO_C_SET_MD_CTX 148 | 385 | #define BIO_C_SET_MD_CTX 148 |
395 | 386 | ||
387 | #define BIO_C_SET_PREFIX 149 | ||
388 | #define BIO_C_GET_PREFIX 150 | ||
389 | #define BIO_C_SET_SUFFIX 151 | ||
390 | #define BIO_C_GET_SUFFIX 152 | ||
391 | |||
392 | #define BIO_C_SET_EX_ARG 153 | ||
393 | #define BIO_C_GET_EX_ARG 154 | ||
396 | 394 | ||
397 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) | 395 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) |
398 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) | 396 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) |
@@ -405,7 +403,7 @@ typedef struct bio_f_buffer_ctx_struct | |||
405 | #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) | 403 | #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) |
406 | #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) | 404 | #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) |
407 | #define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2) | 405 | #define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2) |
408 | #define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3) | 406 | #define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3,0) |
409 | 407 | ||
410 | 408 | ||
411 | #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) | 409 | #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) |
@@ -414,7 +412,7 @@ typedef struct bio_f_buffer_ctx_struct | |||
414 | #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) | 412 | #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) |
415 | #define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) | 413 | #define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) |
416 | /* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ | 414 | /* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ |
417 | #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) | 415 | #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?(void *)"a":NULL) |
418 | #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) | 416 | #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) |
419 | 417 | ||
420 | #define BIO_BIND_NORMAL 0 | 418 | #define BIO_BIND_NORMAL 0 |
@@ -541,6 +539,8 @@ int BIO_ctrl_reset_read_request(BIO *b); | |||
541 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) | 539 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) |
542 | #define BIO_dgram_send_timedout(b) \ | 540 | #define BIO_dgram_send_timedout(b) \ |
543 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) | 541 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) |
542 | #define BIO_dgram_get_peer(b,peer) \ | ||
543 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer) | ||
544 | #define BIO_dgram_set_peer(b,peer) \ | 544 | #define BIO_dgram_set_peer(b,peer) \ |
545 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer) | 545 | (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer) |
546 | 546 | ||
@@ -554,22 +554,21 @@ int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | |||
554 | unsigned long BIO_number_read(BIO *bio); | 554 | unsigned long BIO_number_read(BIO *bio); |
555 | unsigned long BIO_number_written(BIO *bio); | 555 | unsigned long BIO_number_written(BIO *bio); |
556 | 556 | ||
557 | /* For BIO_f_asn1() */ | ||
558 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, | ||
559 | asn1_ps_func *prefix_free); | ||
560 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, | ||
561 | asn1_ps_func **pprefix_free); | ||
562 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, | ||
563 | asn1_ps_func *suffix_free); | ||
564 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | ||
565 | asn1_ps_func **psuffix_free); | ||
566 | |||
557 | # ifndef OPENSSL_NO_FP_API | 567 | # ifndef OPENSSL_NO_FP_API |
558 | # if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL) | ||
559 | BIO_METHOD *BIO_s_file_internal(void); | ||
560 | BIO *BIO_new_file_internal(char *filename, char *mode); | ||
561 | BIO *BIO_new_fp_internal(FILE *stream, int close_flag); | ||
562 | # define BIO_s_file BIO_s_file_internal | ||
563 | # define BIO_new_file BIO_new_file_internal | ||
564 | # define BIO_new_fp BIO_new_fp_internal | ||
565 | # else /* FP_API */ | ||
566 | BIO_METHOD *BIO_s_file(void ); | 568 | BIO_METHOD *BIO_s_file(void ); |
567 | BIO *BIO_new_file(const char *filename, const char *mode); | 569 | BIO *BIO_new_file(const char *filename, const char *mode); |
568 | BIO *BIO_new_fp(FILE *stream, int close_flag); | 570 | BIO *BIO_new_fp(FILE *stream, int close_flag); |
569 | # define BIO_s_file_internal BIO_s_file | 571 | # define BIO_s_file_internal BIO_s_file |
570 | # define BIO_new_file_internal BIO_new_file | ||
571 | # define BIO_new_fp_internal BIO_s_file | ||
572 | # endif /* FP_API */ | ||
573 | # endif | 572 | # endif |
574 | BIO * BIO_new(BIO_METHOD *type); | 573 | BIO * BIO_new(BIO_METHOD *type); |
575 | int BIO_set(BIO *a,BIO_METHOD *type); | 574 | int BIO_set(BIO *a,BIO_METHOD *type); |
@@ -598,13 +597,8 @@ int BIO_nread(BIO *bio, char **buf, int num); | |||
598 | int BIO_nwrite0(BIO *bio, char **buf); | 597 | int BIO_nwrite0(BIO *bio, char **buf); |
599 | int BIO_nwrite(BIO *bio, char **buf, int num); | 598 | int BIO_nwrite(BIO *bio, char **buf, int num); |
600 | 599 | ||
601 | #ifndef OPENSSL_SYS_WIN16 | ||
602 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | 600 | long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, |
603 | long argl,long ret); | 601 | long argl,long ret); |
604 | #else | ||
605 | long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, | ||
606 | long argl,long ret); | ||
607 | #endif | ||
608 | 602 | ||
609 | BIO_METHOD *BIO_s_mem(void); | 603 | BIO_METHOD *BIO_s_mem(void); |
610 | BIO *BIO_new_mem_buf(void *buf, int len); | 604 | BIO *BIO_new_mem_buf(void *buf, int len); |
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c index 6f4254a114..9bcbc321d9 100644 --- a/src/lib/libcrypto/bio/bio_cb.c +++ b/src/lib/libcrypto/bio/bio_cb.c | |||
@@ -85,28 +85,32 @@ long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp, | |||
85 | break; | 85 | break; |
86 | case BIO_CB_READ: | 86 | case BIO_CB_READ: |
87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | 87 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) |
88 | BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s fd=%d\n", | 88 | BIO_snprintf(p,p_maxlen,"read(%d,%lu) - %s fd=%d\n", |
89 | bio->num,argi,bio->method->name,bio->num); | 89 | bio->num,(unsigned long)argi, |
90 | bio->method->name,bio->num); | ||
90 | else | 91 | else |
91 | BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s\n", | 92 | BIO_snprintf(p,p_maxlen,"read(%d,%lu) - %s\n", |
92 | bio->num,argi,bio->method->name); | 93 | bio->num,(unsigned long)argi, |
94 | bio->method->name); | ||
93 | break; | 95 | break; |
94 | case BIO_CB_WRITE: | 96 | case BIO_CB_WRITE: |
95 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | 97 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) |
96 | BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s fd=%d\n", | 98 | BIO_snprintf(p,p_maxlen,"write(%d,%lu) - %s fd=%d\n", |
97 | bio->num,argi,bio->method->name,bio->num); | 99 | bio->num,(unsigned long)argi, |
100 | bio->method->name,bio->num); | ||
98 | else | 101 | else |
99 | BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s\n", | 102 | BIO_snprintf(p,p_maxlen,"write(%d,%lu) - %s\n", |
100 | bio->num,argi,bio->method->name); | 103 | bio->num,(unsigned long)argi, |
104 | bio->method->name); | ||
101 | break; | 105 | break; |
102 | case BIO_CB_PUTS: | 106 | case BIO_CB_PUTS: |
103 | BIO_snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name); | 107 | BIO_snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name); |
104 | break; | 108 | break; |
105 | case BIO_CB_GETS: | 109 | case BIO_CB_GETS: |
106 | BIO_snprintf(p,p_maxlen,"gets(%d) - %s\n",argi,bio->method->name); | 110 | BIO_snprintf(p,p_maxlen,"gets(%lu) - %s\n",(unsigned long)argi,bio->method->name); |
107 | break; | 111 | break; |
108 | case BIO_CB_CTRL: | 112 | case BIO_CB_CTRL: |
109 | BIO_snprintf(p,p_maxlen,"ctrl(%d) - %s\n",argi,bio->method->name); | 113 | BIO_snprintf(p,p_maxlen,"ctrl(%lu) - %s\n",(unsigned long)argi,bio->method->name); |
110 | break; | 114 | break; |
111 | case BIO_CB_RETURN|BIO_CB_READ: | 115 | case BIO_CB_RETURN|BIO_CB_READ: |
112 | BIO_snprintf(p,p_maxlen,"read return %ld\n",ret); | 116 | BIO_snprintf(p,p_maxlen,"read return %ld\n",ret); |
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c index 6603f1c74d..a224edd5a0 100644 --- a/src/lib/libcrypto/bio/bio_err.c +++ b/src/lib/libcrypto/bio/bio_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/bio/bio_err.c */ | 1 | /* crypto/bio/bio_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 3f52ae953c..77f4de9c32 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
@@ -429,7 +429,7 @@ BIO *BIO_push(BIO *b, BIO *bio) | |||
429 | if (bio != NULL) | 429 | if (bio != NULL) |
430 | bio->prev_bio=lb; | 430 | bio->prev_bio=lb; |
431 | /* called to do internal processing */ | 431 | /* called to do internal processing */ |
432 | BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL); | 432 | BIO_ctrl(b,BIO_CTRL_PUSH,0,lb); |
433 | return(b); | 433 | return(b); |
434 | } | 434 | } |
435 | 435 | ||
@@ -441,7 +441,7 @@ BIO *BIO_pop(BIO *b) | |||
441 | if (b == NULL) return(NULL); | 441 | if (b == NULL) return(NULL); |
442 | ret=b->next_bio; | 442 | ret=b->next_bio; |
443 | 443 | ||
444 | BIO_ctrl(b,BIO_CTRL_POP,0,NULL); | 444 | BIO_ctrl(b,BIO_CTRL_POP,0,b); |
445 | 445 | ||
446 | if (b->prev_bio != NULL) | 446 | if (b->prev_bio != NULL) |
447 | b->prev_bio->next_bio=b->next_bio; | 447 | b->prev_bio->next_bio=b->next_bio; |
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c index d090b7272f..826f761143 100644 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ b/src/lib/libcrypto/bio/bss_acpt.c | |||
@@ -100,8 +100,8 @@ static int acpt_new(BIO *h); | |||
100 | static int acpt_free(BIO *data); | 100 | static int acpt_free(BIO *data); |
101 | static int acpt_state(BIO *b, BIO_ACCEPT *c); | 101 | static int acpt_state(BIO *b, BIO_ACCEPT *c); |
102 | static void acpt_close_socket(BIO *data); | 102 | static void acpt_close_socket(BIO *data); |
103 | BIO_ACCEPT *BIO_ACCEPT_new(void ); | 103 | static BIO_ACCEPT *BIO_ACCEPT_new(void ); |
104 | void BIO_ACCEPT_free(BIO_ACCEPT *a); | 104 | static void BIO_ACCEPT_free(BIO_ACCEPT *a); |
105 | 105 | ||
106 | #define ACPT_S_BEFORE 1 | 106 | #define ACPT_S_BEFORE 1 |
107 | #define ACPT_S_GET_ACCEPT_SOCKET 2 | 107 | #define ACPT_S_GET_ACCEPT_SOCKET 2 |
@@ -141,7 +141,7 @@ static int acpt_new(BIO *bi) | |||
141 | return(1); | 141 | return(1); |
142 | } | 142 | } |
143 | 143 | ||
144 | BIO_ACCEPT *BIO_ACCEPT_new(void) | 144 | static BIO_ACCEPT *BIO_ACCEPT_new(void) |
145 | { | 145 | { |
146 | BIO_ACCEPT *ret; | 146 | BIO_ACCEPT *ret; |
147 | 147 | ||
@@ -154,7 +154,7 @@ BIO_ACCEPT *BIO_ACCEPT_new(void) | |||
154 | return(ret); | 154 | return(ret); |
155 | } | 155 | } |
156 | 156 | ||
157 | void BIO_ACCEPT_free(BIO_ACCEPT *a) | 157 | static void BIO_ACCEPT_free(BIO_ACCEPT *a) |
158 | { | 158 | { |
159 | if(a == NULL) | 159 | if(a == NULL) |
160 | return; | 160 | return; |
diff --git a/src/lib/libcrypto/bio/bss_dgram.c b/src/lib/libcrypto/bio/bss_dgram.c index c3da6dc82f..eb7e365467 100644 --- a/src/lib/libcrypto/bio/bss_dgram.c +++ b/src/lib/libcrypto/bio/bss_dgram.c | |||
@@ -66,7 +66,13 @@ | |||
66 | 66 | ||
67 | #include <openssl/bio.h> | 67 | #include <openssl/bio.h> |
68 | 68 | ||
69 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) | ||
70 | #include <sys/timeb.h> | ||
71 | #endif | ||
72 | |||
73 | #ifdef OPENSSL_SYS_LINUX | ||
69 | #define IP_MTU 14 /* linux is lame */ | 74 | #define IP_MTU 14 /* linux is lame */ |
75 | #endif | ||
70 | 76 | ||
71 | #ifdef WATT32 | 77 | #ifdef WATT32 |
72 | #define sock_write SockWrite /* Watt-32 uses same names */ | 78 | #define sock_write SockWrite /* Watt-32 uses same names */ |
@@ -84,6 +90,8 @@ static int dgram_clear(BIO *bio); | |||
84 | 90 | ||
85 | static int BIO_dgram_should_retry(int s); | 91 | static int BIO_dgram_should_retry(int s); |
86 | 92 | ||
93 | static void get_current_time(struct timeval *t); | ||
94 | |||
87 | static BIO_METHOD methods_dgramp= | 95 | static BIO_METHOD methods_dgramp= |
88 | { | 96 | { |
89 | BIO_TYPE_DGRAM, | 97 | BIO_TYPE_DGRAM, |
@@ -100,10 +108,18 @@ static BIO_METHOD methods_dgramp= | |||
100 | 108 | ||
101 | typedef struct bio_dgram_data_st | 109 | typedef struct bio_dgram_data_st |
102 | { | 110 | { |
103 | struct sockaddr peer; | 111 | union { |
112 | struct sockaddr sa; | ||
113 | struct sockaddr_in sa_in; | ||
114 | #if OPENSSL_USE_IPV6 | ||
115 | struct sockaddr_in6 sa_in6; | ||
116 | #endif | ||
117 | } peer; | ||
104 | unsigned int connected; | 118 | unsigned int connected; |
105 | unsigned int _errno; | 119 | unsigned int _errno; |
106 | unsigned int mtu; | 120 | unsigned int mtu; |
121 | struct timeval next_timeout; | ||
122 | struct timeval socket_timeout; | ||
107 | } bio_dgram_data; | 123 | } bio_dgram_data; |
108 | 124 | ||
109 | BIO_METHOD *BIO_s_datagram(void) | 125 | BIO_METHOD *BIO_s_datagram(void) |
@@ -165,31 +181,140 @@ static int dgram_clear(BIO *a) | |||
165 | } | 181 | } |
166 | return(1); | 182 | return(1); |
167 | } | 183 | } |
168 | 184 | ||
185 | static void dgram_adjust_rcv_timeout(BIO *b) | ||
186 | { | ||
187 | #if defined(SO_RCVTIMEO) | ||
188 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | ||
189 | int sz = sizeof(int); | ||
190 | |||
191 | /* Is a timer active? */ | ||
192 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) | ||
193 | { | ||
194 | struct timeval timenow, timeleft; | ||
195 | |||
196 | /* Read current socket timeout */ | ||
197 | #ifdef OPENSSL_SYS_WINDOWS | ||
198 | int timeout; | ||
199 | if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
200 | (void*)&timeout, &sz) < 0) | ||
201 | { perror("getsockopt"); } | ||
202 | else | ||
203 | { | ||
204 | data->socket_timeout.tv_sec = timeout / 1000; | ||
205 | data->socket_timeout.tv_usec = (timeout % 1000) * 1000; | ||
206 | } | ||
207 | #else | ||
208 | if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
209 | &(data->socket_timeout), (void *)&sz) < 0) | ||
210 | { perror("getsockopt"); } | ||
211 | #endif | ||
212 | |||
213 | /* Get current time */ | ||
214 | get_current_time(&timenow); | ||
215 | |||
216 | /* Calculate time left until timer expires */ | ||
217 | memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval)); | ||
218 | timeleft.tv_sec -= timenow.tv_sec; | ||
219 | timeleft.tv_usec -= timenow.tv_usec; | ||
220 | if (timeleft.tv_usec < 0) | ||
221 | { | ||
222 | timeleft.tv_sec--; | ||
223 | timeleft.tv_usec += 1000000; | ||
224 | } | ||
225 | |||
226 | if (timeleft.tv_sec < 0) | ||
227 | { | ||
228 | timeleft.tv_sec = 0; | ||
229 | timeleft.tv_usec = 1; | ||
230 | } | ||
231 | |||
232 | /* Adjust socket timeout if next handhake message timer | ||
233 | * will expire earlier. | ||
234 | */ | ||
235 | if ((data->socket_timeout.tv_sec == 0 && data->socket_timeout.tv_usec == 0) || | ||
236 | (data->socket_timeout.tv_sec > timeleft.tv_sec) || | ||
237 | (data->socket_timeout.tv_sec == timeleft.tv_sec && | ||
238 | data->socket_timeout.tv_usec >= timeleft.tv_usec)) | ||
239 | { | ||
240 | #ifdef OPENSSL_SYS_WINDOWS | ||
241 | timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000; | ||
242 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
243 | (void*)&timeout, sizeof(timeout)) < 0) | ||
244 | { perror("setsockopt"); } | ||
245 | #else | ||
246 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &timeleft, | ||
247 | sizeof(struct timeval)) < 0) | ||
248 | { perror("setsockopt"); } | ||
249 | #endif | ||
250 | } | ||
251 | } | ||
252 | #endif | ||
253 | } | ||
254 | |||
255 | static void dgram_reset_rcv_timeout(BIO *b) | ||
256 | { | ||
257 | #if defined(SO_RCVTIMEO) | ||
258 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | ||
259 | |||
260 | /* Is a timer active? */ | ||
261 | if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) | ||
262 | { | ||
263 | #ifdef OPENSSL_SYS_WINDOWS | ||
264 | int timeout = data->socket_timeout.tv_sec * 1000 + | ||
265 | data->socket_timeout.tv_usec / 1000; | ||
266 | if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, | ||
267 | (void*)&timeout, sizeof(timeout)) < 0) | ||
268 | { perror("setsockopt"); } | ||
269 | #else | ||
270 | if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data->socket_timeout), | ||
271 | sizeof(struct timeval)) < 0) | ||
272 | { perror("setsockopt"); } | ||
273 | #endif | ||
274 | } | ||
275 | #endif | ||
276 | } | ||
277 | |||
169 | static int dgram_read(BIO *b, char *out, int outl) | 278 | static int dgram_read(BIO *b, char *out, int outl) |
170 | { | 279 | { |
171 | int ret=0; | 280 | int ret=0; |
172 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 281 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
173 | 282 | ||
174 | struct sockaddr peer; | 283 | struct { |
175 | int peerlen = sizeof(peer); | 284 | /* |
285 | * See commentary in b_sock.c. <appro> | ||
286 | */ | ||
287 | union { size_t s; int i; } len; | ||
288 | union { | ||
289 | struct sockaddr sa; | ||
290 | struct sockaddr_in sa_in; | ||
291 | #if OPENSSL_USE_IPV6 | ||
292 | struct sockaddr_in6 sa_in6; | ||
293 | #endif | ||
294 | } peer; | ||
295 | } sa; | ||
296 | |||
297 | sa.len.s=0; | ||
298 | sa.len.i=sizeof(sa.peer); | ||
176 | 299 | ||
177 | if (out != NULL) | 300 | if (out != NULL) |
178 | { | 301 | { |
179 | clear_socket_error(); | 302 | clear_socket_error(); |
180 | memset(&peer, 0x00, peerlen); | 303 | memset(&sa.peer, 0x00, sizeof(sa.peer)); |
181 | /* Last arg in recvfrom is signed on some platforms and | 304 | dgram_adjust_rcv_timeout(b); |
182 | * unsigned on others. It is of type socklen_t on some | 305 | ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len); |
183 | * but this is not universal. Cast to (void *) to avoid | 306 | if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0) |
184 | * compiler warnings. | 307 | { |
185 | */ | 308 | OPENSSL_assert(sa.len.s<=sizeof(sa.peer)); |
186 | ret=recvfrom(b->num,out,outl,0,&peer,(void *)&peerlen); | 309 | sa.len.i = (int)sa.len.s; |
310 | } | ||
311 | dgram_reset_rcv_timeout(b); | ||
187 | 312 | ||
188 | if ( ! data->connected && ret > 0) | 313 | if ( ! data->connected && ret >= 0) |
189 | BIO_ctrl(b, BIO_CTRL_DGRAM_CONNECT, 0, &peer); | 314 | BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer); |
190 | 315 | ||
191 | BIO_clear_retry_flags(b); | 316 | BIO_clear_retry_flags(b); |
192 | if (ret <= 0) | 317 | if (ret < 0) |
193 | { | 318 | { |
194 | if (BIO_dgram_should_retry(ret)) | 319 | if (BIO_dgram_should_retry(ret)) |
195 | { | 320 | { |
@@ -207,19 +332,29 @@ static int dgram_write(BIO *b, const char *in, int inl) | |||
207 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; | 332 | bio_dgram_data *data = (bio_dgram_data *)b->ptr; |
208 | clear_socket_error(); | 333 | clear_socket_error(); |
209 | 334 | ||
210 | if ( data->connected ) | 335 | if ( data->connected ) |
211 | ret=writesocket(b->num,in,inl); | 336 | ret=writesocket(b->num,in,inl); |
212 | else | 337 | else |
338 | { | ||
339 | int peerlen = sizeof(data->peer); | ||
340 | |||
341 | if (data->peer.sa.sa_family == AF_INET) | ||
342 | peerlen = sizeof(data->peer.sa_in); | ||
343 | #if OPENSSL_USE_IVP6 | ||
344 | else if (data->peer.sa.sa_family == AF_INET6) | ||
345 | peerlen = sizeof(data->peer.sa_in6); | ||
346 | #endif | ||
213 | #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK) | 347 | #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK) |
214 | ret=sendto(b->num, (char *)in, inl, 0, &data->peer, sizeof(data->peer)); | 348 | ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen); |
215 | #else | 349 | #else |
216 | ret=sendto(b->num, in, inl, 0, &data->peer, sizeof(data->peer)); | 350 | ret=sendto(b->num, in, inl, 0, &data->peer.sa, peerlen); |
217 | #endif | 351 | #endif |
352 | } | ||
218 | 353 | ||
219 | BIO_clear_retry_flags(b); | 354 | BIO_clear_retry_flags(b); |
220 | if (ret <= 0) | 355 | if (ret <= 0) |
221 | { | 356 | { |
222 | if (BIO_sock_should_retry(ret)) | 357 | if (BIO_dgram_should_retry(ret)) |
223 | { | 358 | { |
224 | BIO_set_retry_write(b); | 359 | BIO_set_retry_write(b); |
225 | data->_errno = get_last_socket_error(); | 360 | data->_errno = get_last_socket_error(); |
@@ -240,8 +375,20 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
240 | int *ip; | 375 | int *ip; |
241 | struct sockaddr *to = NULL; | 376 | struct sockaddr *to = NULL; |
242 | bio_dgram_data *data = NULL; | 377 | bio_dgram_data *data = NULL; |
378 | #if defined(IP_MTU_DISCOVER) || defined(IP_MTU) | ||
243 | long sockopt_val = 0; | 379 | long sockopt_val = 0; |
244 | unsigned int sockopt_len = 0; | 380 | unsigned int sockopt_len = 0; |
381 | #endif | ||
382 | #ifdef OPENSSL_SYS_LINUX | ||
383 | socklen_t addr_len; | ||
384 | union { | ||
385 | struct sockaddr sa; | ||
386 | struct sockaddr_in s4; | ||
387 | #if OPENSSL_USE_IPV6 | ||
388 | struct sockaddr_in6 s6; | ||
389 | #endif | ||
390 | } addr; | ||
391 | #endif | ||
245 | 392 | ||
246 | data = (bio_dgram_data *)b->ptr; | 393 | data = (bio_dgram_data *)b->ptr; |
247 | 394 | ||
@@ -294,30 +441,110 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
294 | else | 441 | else |
295 | { | 442 | { |
296 | #endif | 443 | #endif |
297 | memcpy(&(data->peer),to, sizeof(struct sockaddr)); | 444 | switch (to->sa_family) |
445 | { | ||
446 | case AF_INET: | ||
447 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | ||
448 | break; | ||
449 | #if OPENSSL_USE_IPV6 | ||
450 | case AF_INET6: | ||
451 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | ||
452 | break; | ||
453 | #endif | ||
454 | default: | ||
455 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | ||
456 | break; | ||
457 | } | ||
298 | #if 0 | 458 | #if 0 |
299 | } | 459 | } |
300 | #endif | 460 | #endif |
301 | break; | 461 | break; |
302 | /* (Linux)kernel sets DF bit on outgoing IP packets */ | 462 | /* (Linux)kernel sets DF bit on outgoing IP packets */ |
303 | #ifdef IP_MTU_DISCOVER | ||
304 | case BIO_CTRL_DGRAM_MTU_DISCOVER: | 463 | case BIO_CTRL_DGRAM_MTU_DISCOVER: |
305 | sockopt_val = IP_PMTUDISC_DO; | 464 | #ifdef OPENSSL_SYS_LINUX |
306 | if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER, | 465 | addr_len = (socklen_t)sizeof(addr); |
307 | &sockopt_val, sizeof(sockopt_val))) < 0) | 466 | memset((void *)&addr, 0, sizeof(addr)); |
308 | perror("setsockopt"); | 467 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) |
468 | { | ||
469 | ret = 0; | ||
470 | break; | ||
471 | } | ||
472 | sockopt_len = sizeof(sockopt_val); | ||
473 | switch (addr.sa.sa_family) | ||
474 | { | ||
475 | case AF_INET: | ||
476 | sockopt_val = IP_PMTUDISC_DO; | ||
477 | if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER, | ||
478 | &sockopt_val, sizeof(sockopt_val))) < 0) | ||
479 | perror("setsockopt"); | ||
480 | break; | ||
481 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) | ||
482 | case AF_INET6: | ||
483 | sockopt_val = IPV6_PMTUDISC_DO; | ||
484 | if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER, | ||
485 | &sockopt_val, sizeof(sockopt_val))) < 0) | ||
486 | perror("setsockopt"); | ||
487 | break; | ||
488 | #endif | ||
489 | default: | ||
490 | ret = -1; | ||
491 | break; | ||
492 | } | ||
493 | ret = -1; | ||
494 | #else | ||
309 | break; | 495 | break; |
310 | #endif | 496 | #endif |
311 | case BIO_CTRL_DGRAM_QUERY_MTU: | 497 | case BIO_CTRL_DGRAM_QUERY_MTU: |
312 | sockopt_len = sizeof(sockopt_val); | 498 | #ifdef OPENSSL_SYS_LINUX |
313 | if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val, | 499 | addr_len = (socklen_t)sizeof(addr); |
314 | &sockopt_len)) < 0 || sockopt_val < 0) | 500 | memset((void *)&addr, 0, sizeof(addr)); |
315 | { ret = 0; } | 501 | if (getsockname(b->num, &addr.sa, &addr_len) < 0) |
316 | else | 502 | { |
503 | ret = 0; | ||
504 | break; | ||
505 | } | ||
506 | sockopt_len = sizeof(sockopt_val); | ||
507 | switch (addr.sa.sa_family) | ||
317 | { | 508 | { |
318 | data->mtu = sockopt_val; | 509 | case AF_INET: |
319 | ret = data->mtu; | 510 | if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val, |
511 | &sockopt_len)) < 0 || sockopt_val < 0) | ||
512 | { | ||
513 | ret = 0; | ||
514 | } | ||
515 | else | ||
516 | { | ||
517 | /* we assume that the transport protocol is UDP and no | ||
518 | * IP options are used. | ||
519 | */ | ||
520 | data->mtu = sockopt_val - 8 - 20; | ||
521 | ret = data->mtu; | ||
522 | } | ||
523 | break; | ||
524 | #if OPENSSL_USE_IPV6 && defined(IPV6_MTU) | ||
525 | case AF_INET6: | ||
526 | if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val, | ||
527 | &sockopt_len)) < 0 || sockopt_val < 0) | ||
528 | { | ||
529 | ret = 0; | ||
530 | } | ||
531 | else | ||
532 | { | ||
533 | /* we assume that the transport protocol is UDP and no | ||
534 | * IPV6 options are used. | ||
535 | */ | ||
536 | data->mtu = sockopt_val - 8 - 40; | ||
537 | ret = data->mtu; | ||
538 | } | ||
539 | break; | ||
540 | #endif | ||
541 | default: | ||
542 | ret = 0; | ||
543 | break; | ||
320 | } | 544 | } |
545 | #else | ||
546 | ret = 0; | ||
547 | #endif | ||
321 | break; | 548 | break; |
322 | case BIO_CTRL_DGRAM_GET_MTU: | 549 | case BIO_CTRL_DGRAM_GET_MTU: |
323 | return data->mtu; | 550 | return data->mtu; |
@@ -332,19 +559,66 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
332 | if ( to != NULL) | 559 | if ( to != NULL) |
333 | { | 560 | { |
334 | data->connected = 1; | 561 | data->connected = 1; |
335 | memcpy(&(data->peer),to, sizeof(struct sockaddr)); | 562 | switch (to->sa_family) |
563 | { | ||
564 | case AF_INET: | ||
565 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | ||
566 | break; | ||
567 | #if OPENSSL_USE_IPV6 | ||
568 | case AF_INET6: | ||
569 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | ||
570 | break; | ||
571 | #endif | ||
572 | default: | ||
573 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | ||
574 | break; | ||
575 | } | ||
336 | } | 576 | } |
337 | else | 577 | else |
338 | { | 578 | { |
339 | data->connected = 0; | 579 | data->connected = 0; |
340 | memset(&(data->peer), 0x00, sizeof(struct sockaddr)); | 580 | memset(&(data->peer), 0x00, sizeof(data->peer)); |
341 | } | 581 | } |
342 | break; | 582 | break; |
343 | case BIO_CTRL_DGRAM_SET_PEER: | 583 | case BIO_CTRL_DGRAM_GET_PEER: |
344 | to = (struct sockaddr *) ptr; | 584 | switch (data->peer.sa.sa_family) |
345 | 585 | { | |
346 | memcpy(&(data->peer), to, sizeof(struct sockaddr)); | 586 | case AF_INET: |
347 | break; | 587 | ret=sizeof(data->peer.sa_in); |
588 | break; | ||
589 | #if OPENSSL_USE_IPV6 | ||
590 | case AF_INET6: | ||
591 | ret=sizeof(data->peer.sa_in6); | ||
592 | break; | ||
593 | #endif | ||
594 | default: | ||
595 | ret=sizeof(data->peer.sa); | ||
596 | break; | ||
597 | } | ||
598 | if (num==0 || num>ret) | ||
599 | num=ret; | ||
600 | memcpy(ptr,&data->peer,(ret=num)); | ||
601 | break; | ||
602 | case BIO_CTRL_DGRAM_SET_PEER: | ||
603 | to = (struct sockaddr *) ptr; | ||
604 | switch (to->sa_family) | ||
605 | { | ||
606 | case AF_INET: | ||
607 | memcpy(&data->peer,to,sizeof(data->peer.sa_in)); | ||
608 | break; | ||
609 | #if OPENSSL_USE_IPV6 | ||
610 | case AF_INET6: | ||
611 | memcpy(&data->peer,to,sizeof(data->peer.sa_in6)); | ||
612 | break; | ||
613 | #endif | ||
614 | default: | ||
615 | memcpy(&data->peer,to,sizeof(data->peer.sa)); | ||
616 | break; | ||
617 | } | ||
618 | break; | ||
619 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: | ||
620 | memcpy(&(data->next_timeout), ptr, sizeof(struct timeval)); | ||
621 | break; | ||
348 | #if defined(SO_RCVTIMEO) | 622 | #if defined(SO_RCVTIMEO) |
349 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: | 623 | case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT: |
350 | #ifdef OPENSSL_SYS_WINDOWS | 624 | #ifdef OPENSSL_SYS_WINDOWS |
@@ -507,10 +781,6 @@ int BIO_dgram_non_fatal_error(int err) | |||
507 | # endif | 781 | # endif |
508 | #endif | 782 | #endif |
509 | 783 | ||
510 | #if defined(ENOTCONN) | ||
511 | case ENOTCONN: | ||
512 | #endif | ||
513 | |||
514 | #ifdef EINTR | 784 | #ifdef EINTR |
515 | case EINTR: | 785 | case EINTR: |
516 | #endif | 786 | #endif |
@@ -533,11 +803,6 @@ int BIO_dgram_non_fatal_error(int err) | |||
533 | case EALREADY: | 803 | case EALREADY: |
534 | #endif | 804 | #endif |
535 | 805 | ||
536 | /* DF bit set, and packet larger than MTU */ | ||
537 | #ifdef EMSGSIZE | ||
538 | case EMSGSIZE: | ||
539 | #endif | ||
540 | |||
541 | return(1); | 806 | return(1); |
542 | /* break; */ | 807 | /* break; */ |
543 | default: | 808 | default: |
@@ -546,3 +811,20 @@ int BIO_dgram_non_fatal_error(int err) | |||
546 | return(0); | 811 | return(0); |
547 | } | 812 | } |
548 | #endif | 813 | #endif |
814 | |||
815 | static void get_current_time(struct timeval *t) | ||
816 | { | ||
817 | #ifdef OPENSSL_SYS_WIN32 | ||
818 | struct _timeb tb; | ||
819 | _ftime(&tb); | ||
820 | t->tv_sec = (long)tb.time; | ||
821 | t->tv_usec = (long)tb.millitm * 1000; | ||
822 | #elif defined(OPENSSL_SYS_VMS) | ||
823 | struct timeb tb; | ||
824 | ftime(&tb); | ||
825 | t->tv_sec = (long)tb.time; | ||
826 | t->tv_usec = (long)tb.millitm * 1000; | ||
827 | #else | ||
828 | gettimeofday(t, NULL); | ||
829 | #endif | ||
830 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c index 4c229bf641..d1bf85aae1 100644 --- a/src/lib/libcrypto/bio/bss_fd.c +++ b/src/lib/libcrypto/bio/bss_fd.c | |||
@@ -60,6 +60,13 @@ | |||
60 | #include <errno.h> | 60 | #include <errno.h> |
61 | #define USE_SOCKETS | 61 | #define USE_SOCKETS |
62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
63 | |||
64 | #if defined(OPENSSL_NO_POSIX_IO) | ||
65 | /* | ||
66 | * One can argue that one should implement dummy placeholder for | ||
67 | * BIO_s_fd here... | ||
68 | */ | ||
69 | #else | ||
63 | /* | 70 | /* |
64 | * As for unconditional usage of "UPLINK" interface in this module. | 71 | * As for unconditional usage of "UPLINK" interface in this module. |
65 | * Trouble is that unlike Unix file descriptors [which are indexes | 72 | * Trouble is that unlike Unix file descriptors [which are indexes |
@@ -77,6 +84,7 @@ | |||
77 | static int fd_write(BIO *h, const char *buf, int num); | 84 | static int fd_write(BIO *h, const char *buf, int num); |
78 | static int fd_read(BIO *h, char *buf, int size); | 85 | static int fd_read(BIO *h, char *buf, int size); |
79 | static int fd_puts(BIO *h, const char *str); | 86 | static int fd_puts(BIO *h, const char *str); |
87 | static int fd_gets(BIO *h, char *buf, int size); | ||
80 | static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 88 | static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
81 | static int fd_new(BIO *h); | 89 | static int fd_new(BIO *h); |
82 | static int fd_free(BIO *data); | 90 | static int fd_free(BIO *data); |
@@ -88,7 +96,7 @@ static BIO_METHOD methods_fdp= | |||
88 | fd_write, | 96 | fd_write, |
89 | fd_read, | 97 | fd_read, |
90 | fd_puts, | 98 | fd_puts, |
91 | NULL, /* fd_gets, */ | 99 | fd_gets, |
92 | fd_ctrl, | 100 | fd_ctrl, |
93 | fd_new, | 101 | fd_new, |
94 | fd_free, | 102 | fd_free, |
@@ -227,6 +235,22 @@ static int fd_puts(BIO *bp, const char *str) | |||
227 | return(ret); | 235 | return(ret); |
228 | } | 236 | } |
229 | 237 | ||
238 | static int fd_gets(BIO *bp, char *buf, int size) | ||
239 | { | ||
240 | int ret=0; | ||
241 | char *ptr=buf; | ||
242 | char *end=buf+size-1; | ||
243 | |||
244 | while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') ) | ||
245 | ptr++; | ||
246 | |||
247 | ptr[0]='\0'; | ||
248 | |||
249 | if (buf[0] != '\0') | ||
250 | ret=strlen(buf); | ||
251 | return(ret); | ||
252 | } | ||
253 | |||
230 | int BIO_fd_should_retry(int i) | 254 | int BIO_fd_should_retry(int i) |
231 | { | 255 | { |
232 | int err; | 256 | int err; |
@@ -292,3 +316,4 @@ int BIO_fd_non_fatal_error(int err) | |||
292 | } | 316 | } |
293 | return(0); | 317 | return(0); |
294 | } | 318 | } |
319 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index e692a08e58..8bfa0bcd97 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -118,10 +118,47 @@ static BIO_METHOD methods_filep= | |||
118 | 118 | ||
119 | BIO *BIO_new_file(const char *filename, const char *mode) | 119 | BIO *BIO_new_file(const char *filename, const char *mode) |
120 | { | 120 | { |
121 | BIO *ret; | 121 | BIO *ret; |
122 | FILE *file; | 122 | FILE *file=NULL; |
123 | |||
124 | #if defined(_WIN32) && defined(CP_UTF8) | ||
125 | int sz, len_0 = (int)strlen(filename)+1; | ||
123 | 126 | ||
124 | if ((file=fopen(filename,mode)) == NULL) | 127 | /* |
128 | * Basically there are three cases to cover: a) filename is | ||
129 | * pure ASCII string; b) actual UTF-8 encoded string and | ||
130 | * c) locale-ized string, i.e. one containing 8-bit | ||
131 | * characters that are meaningful in current system locale. | ||
132 | * If filename is pure ASCII or real UTF-8 encoded string, | ||
133 | * MultiByteToWideChar succeeds and _wfopen works. If | ||
134 | * filename is locale-ized string, chances are that | ||
135 | * MultiByteToWideChar fails reporting | ||
136 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall | ||
137 | * back to fopen... | ||
138 | */ | ||
139 | if ((sz=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS, | ||
140 | filename,len_0,NULL,0))>0) | ||
141 | { | ||
142 | WCHAR wmode[8]; | ||
143 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); | ||
144 | |||
145 | if (MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS, | ||
146 | filename,len_0,wfilename,sz) && | ||
147 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, | ||
148 | wmode,sizeof(wmode)/sizeof(wmode[0])) && | ||
149 | (file=_wfopen(wfilename,wmode))==NULL && errno==ENOENT | ||
150 | ) /* UTF-8 decode succeeded, but no file, filename | ||
151 | * could still have been locale-ized... */ | ||
152 | file = fopen(filename,mode); | ||
153 | } | ||
154 | else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION) | ||
155 | { | ||
156 | file = fopen(filename,mode); | ||
157 | } | ||
158 | #else | ||
159 | file=fopen(filename,mode); | ||
160 | #endif | ||
161 | if (file == NULL) | ||
125 | { | 162 | { |
126 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | 163 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); |
127 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | 164 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); |
@@ -131,7 +168,7 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
131 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | 168 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); |
132 | return(NULL); | 169 | return(NULL); |
133 | } | 170 | } |
134 | if ((ret=BIO_new(BIO_s_file_internal())) == NULL) | 171 | if ((ret=BIO_new(BIO_s_file())) == NULL) |
135 | { | 172 | { |
136 | fclose(file); | 173 | fclose(file); |
137 | return(NULL); | 174 | return(NULL); |
@@ -241,7 +278,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
241 | if (b->flags&BIO_FLAGS_UPLINK) | 278 | if (b->flags&BIO_FLAGS_UPLINK) |
242 | ret=(long)UP_fseek(b->ptr,num,0); | 279 | ret=(long)UP_fseek(b->ptr,num,0); |
243 | else | 280 | else |
244 | ret=(long)fseek(fp,num,SEEK_SET); | 281 | ret=(long)fseek(fp,num,0); |
245 | break; | 282 | break; |
246 | case BIO_CTRL_EOF: | 283 | case BIO_CTRL_EOF: |
247 | if (b->flags&BIO_FLAGS_UPLINK) | 284 | if (b->flags&BIO_FLAGS_UPLINK) |
@@ -272,9 +309,9 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
272 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); | 309 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); |
273 | #endif | 310 | #endif |
274 | #endif | 311 | #endif |
275 | #ifdef UP_fsetmode | 312 | #ifdef UP_fsetmod |
276 | if (b->flags&BIO_FLAGS_UPLINK) | 313 | if (b->flags&BIO_FLAGS_UPLINK) |
277 | UP_fsetmode(b->ptr,num&BIO_FP_TEXT?'t':'b'); | 314 | UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b')); |
278 | else | 315 | else |
279 | #endif | 316 | #endif |
280 | { | 317 | { |
@@ -286,8 +323,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
286 | _setmode(fd,_O_BINARY); | 323 | _setmode(fd,_O_BINARY); |
287 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) | 324 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) |
288 | int fd = fileno((FILE*)ptr); | 325 | int fd = fileno((FILE*)ptr); |
289 | /* Under CLib there are differences in file modes | 326 | /* Under CLib there are differences in file modes */ |
290 | */ | ||
291 | if (num & BIO_FP_TEXT) | 327 | if (num & BIO_FP_TEXT) |
292 | setmode(fd,O_TEXT); | 328 | setmode(fd,O_TEXT); |
293 | else | 329 | else |
@@ -308,7 +344,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
308 | else | 344 | else |
309 | _setmode(fd,_O_BINARY); | 345 | _setmode(fd,_O_BINARY); |
310 | } | 346 | } |
311 | #elif defined(OPENSSL_SYS_OS2) | 347 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
312 | int fd = fileno((FILE*)ptr); | 348 | int fd = fileno((FILE*)ptr); |
313 | if (num & BIO_FP_TEXT) | 349 | if (num & BIO_FP_TEXT) |
314 | setmode(fd, O_TEXT); | 350 | setmode(fd, O_TEXT); |
@@ -404,11 +440,18 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) | |||
404 | 440 | ||
405 | buf[0]='\0'; | 441 | buf[0]='\0'; |
406 | if (bp->flags&BIO_FLAGS_UPLINK) | 442 | if (bp->flags&BIO_FLAGS_UPLINK) |
407 | UP_fgets(buf,size,bp->ptr); | 443 | { |
444 | if (!UP_fgets(buf,size,bp->ptr)) | ||
445 | goto err; | ||
446 | } | ||
408 | else | 447 | else |
409 | fgets(buf,size,(FILE *)bp->ptr); | 448 | { |
449 | if (!fgets(buf,size,(FILE *)bp->ptr)) | ||
450 | goto err; | ||
451 | } | ||
410 | if (buf[0] != '\0') | 452 | if (buf[0] != '\0') |
411 | ret=strlen(buf); | 453 | ret=strlen(buf); |
454 | err: | ||
412 | return(ret); | 455 | return(ret); |
413 | } | 456 | } |
414 | 457 | ||
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c index 6360dbc820..7ead044b37 100644 --- a/src/lib/libcrypto/bio/bss_log.c +++ b/src/lib/libcrypto/bio/bss_log.c | |||
@@ -70,7 +70,6 @@ | |||
70 | 70 | ||
71 | #if defined(OPENSSL_SYS_WINCE) | 71 | #if defined(OPENSSL_SYS_WINCE) |
72 | #elif defined(OPENSSL_SYS_WIN32) | 72 | #elif defined(OPENSSL_SYS_WIN32) |
73 | # include <process.h> | ||
74 | #elif defined(OPENSSL_SYS_VMS) | 73 | #elif defined(OPENSSL_SYS_VMS) |
75 | # include <opcdef.h> | 74 | # include <opcdef.h> |
76 | # include <descrip.h> | 75 | # include <descrip.h> |
@@ -122,18 +121,6 @@ static int MS_CALLBACK slg_free(BIO *data); | |||
122 | static void xopenlog(BIO* bp, char* name, int level); | 121 | static void xopenlog(BIO* bp, char* name, int level); |
123 | static void xsyslog(BIO* bp, int priority, const char* string); | 122 | static void xsyslog(BIO* bp, int priority, const char* string); |
124 | static void xcloselog(BIO* bp); | 123 | static void xcloselog(BIO* bp); |
125 | #ifdef OPENSSL_SYS_WIN32 | ||
126 | LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx; | ||
127 | HANDLE (WINAPI *register_event_source)() = NULL; | ||
128 | BOOL (WINAPI *deregister_event_source)() = NULL; | ||
129 | BOOL (WINAPI *report_event)() = NULL; | ||
130 | #define DL_PROC(m,f) (GetProcAddress( m, f )) | ||
131 | #ifdef UNICODE | ||
132 | #define DL_PROC_X(m,f) DL_PROC( m, f "W" ) | ||
133 | #else | ||
134 | #define DL_PROC_X(m,f) DL_PROC( m, f "A" ) | ||
135 | #endif | ||
136 | #endif | ||
137 | 124 | ||
138 | static BIO_METHOD methods_slg= | 125 | static BIO_METHOD methods_slg= |
139 | { | 126 | { |
@@ -175,7 +162,7 @@ static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl) | |||
175 | char* buf; | 162 | char* buf; |
176 | char* pp; | 163 | char* pp; |
177 | int priority, i; | 164 | int priority, i; |
178 | static struct | 165 | static const struct |
179 | { | 166 | { |
180 | int strl; | 167 | int strl; |
181 | char str[10]; | 168 | char str[10]; |
@@ -249,35 +236,20 @@ static int MS_CALLBACK slg_puts(BIO *bp, const char *str) | |||
249 | 236 | ||
250 | static void xopenlog(BIO* bp, char* name, int level) | 237 | static void xopenlog(BIO* bp, char* name, int level) |
251 | { | 238 | { |
252 | if ( !register_event_source ) | 239 | if (GetVersion() < 0x80000000) |
253 | { | 240 | bp->ptr = RegisterEventSourceA(NULL,name); |
254 | HANDLE advapi; | 241 | else |
255 | if ( !(advapi = GetModuleHandle("advapi32")) ) | 242 | bp->ptr = NULL; |
256 | return; | ||
257 | register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi, | ||
258 | "RegisterEventSource" ); | ||
259 | deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi, | ||
260 | "DeregisterEventSource"); | ||
261 | report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi, | ||
262 | "ReportEvent" ); | ||
263 | if ( !(register_event_source && deregister_event_source && | ||
264 | report_event) ) | ||
265 | { | ||
266 | register_event_source = NULL; | ||
267 | deregister_event_source = NULL; | ||
268 | report_event = NULL; | ||
269 | return; | ||
270 | } | ||
271 | } | ||
272 | bp->ptr= (char *)register_event_source(NULL, name); | ||
273 | } | 243 | } |
274 | 244 | ||
275 | static void xsyslog(BIO *bp, int priority, const char *string) | 245 | static void xsyslog(BIO *bp, int priority, const char *string) |
276 | { | 246 | { |
277 | LPCSTR lpszStrings[2]; | 247 | LPCSTR lpszStrings[2]; |
278 | WORD evtype= EVENTLOG_ERROR_TYPE; | 248 | WORD evtype= EVENTLOG_ERROR_TYPE; |
279 | int pid = _getpid(); | 249 | char pidbuf[DECIMAL_SIZE(DWORD)+4]; |
280 | char pidbuf[DECIMAL_SIZE(pid)+4]; | 250 | |
251 | if (bp->ptr == NULL) | ||
252 | return; | ||
281 | 253 | ||
282 | switch (priority) | 254 | switch (priority) |
283 | { | 255 | { |
@@ -301,19 +273,18 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
301 | break; | 273 | break; |
302 | } | 274 | } |
303 | 275 | ||
304 | sprintf(pidbuf, "[%d] ", pid); | 276 | sprintf(pidbuf, "[%u] ", GetCurrentProcessId()); |
305 | lpszStrings[0] = pidbuf; | 277 | lpszStrings[0] = pidbuf; |
306 | lpszStrings[1] = string; | 278 | lpszStrings[1] = string; |
307 | 279 | ||
308 | if(report_event && bp->ptr) | 280 | ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0, |
309 | report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0, | ||
310 | lpszStrings, NULL); | 281 | lpszStrings, NULL); |
311 | } | 282 | } |
312 | 283 | ||
313 | static void xcloselog(BIO* bp) | 284 | static void xcloselog(BIO* bp) |
314 | { | 285 | { |
315 | if(deregister_event_source && bp->ptr) | 286 | if(bp->ptr) |
316 | deregister_event_source((HANDLE)(bp->ptr)); | 287 | DeregisterEventSource((HANDLE)(bp->ptr)); |
317 | bp->ptr= NULL; | 288 | bp->ptr= NULL; |
318 | } | 289 | } |
319 | 290 | ||
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index e7ab9cb3a3..37d4194e4b 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c | |||
@@ -94,16 +94,18 @@ BIO *BIO_new_mem_buf(void *buf, int len) | |||
94 | { | 94 | { |
95 | BIO *ret; | 95 | BIO *ret; |
96 | BUF_MEM *b; | 96 | BUF_MEM *b; |
97 | size_t sz; | ||
98 | |||
97 | if (!buf) { | 99 | if (!buf) { |
98 | BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER); | 100 | BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER); |
99 | return NULL; | 101 | return NULL; |
100 | } | 102 | } |
101 | if(len == -1) len = strlen(buf); | 103 | sz = (len<0) ? strlen(buf) : (size_t)len; |
102 | if(!(ret = BIO_new(BIO_s_mem())) ) return NULL; | 104 | if(!(ret = BIO_new(BIO_s_mem())) ) return NULL; |
103 | b = (BUF_MEM *)ret->ptr; | 105 | b = (BUF_MEM *)ret->ptr; |
104 | b->data = buf; | 106 | b->data = buf; |
105 | b->length = len; | 107 | b->length = sz; |
106 | b->max = len; | 108 | b->max = sz; |
107 | ret->flags |= BIO_FLAGS_MEM_RDONLY; | 109 | ret->flags |= BIO_FLAGS_MEM_RDONLY; |
108 | /* Since this is static data retrying wont help */ | 110 | /* Since this is static data retrying wont help */ |
109 | ret->num = 0; | 111 | ret->num = 0; |
@@ -144,22 +146,16 @@ static int mem_read(BIO *b, char *out, int outl) | |||
144 | { | 146 | { |
145 | int ret= -1; | 147 | int ret= -1; |
146 | BUF_MEM *bm; | 148 | BUF_MEM *bm; |
147 | int i; | ||
148 | char *from,*to; | ||
149 | 149 | ||
150 | bm=(BUF_MEM *)b->ptr; | 150 | bm=(BUF_MEM *)b->ptr; |
151 | BIO_clear_retry_flags(b); | 151 | BIO_clear_retry_flags(b); |
152 | ret=(outl > bm->length)?bm->length:outl; | 152 | ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl; |
153 | if ((out != NULL) && (ret > 0)) { | 153 | if ((out != NULL) && (ret > 0)) { |
154 | memcpy(out,bm->data,ret); | 154 | memcpy(out,bm->data,ret); |
155 | bm->length-=ret; | 155 | bm->length-=ret; |
156 | /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */ | ||
157 | if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret; | 156 | if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret; |
158 | else { | 157 | else { |
159 | from=(char *)&(bm->data[ret]); | 158 | memmove(&(bm->data[0]),&(bm->data[ret]),bm->length); |
160 | to=(char *)&(bm->data[0]); | ||
161 | for (i=0; i<bm->length; i++) | ||
162 | to[i]=from[i]; | ||
163 | } | 159 | } |
164 | } else if (bm->length == 0) | 160 | } else if (bm->length == 0) |
165 | { | 161 | { |
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index 30c3ceab46..3df31938c1 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
@@ -172,15 +172,6 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
172 | 172 | ||
173 | switch (cmd) | 173 | switch (cmd) |
174 | { | 174 | { |
175 | case BIO_CTRL_RESET: | ||
176 | num=0; | ||
177 | case BIO_C_FILE_SEEK: | ||
178 | ret=0; | ||
179 | break; | ||
180 | case BIO_C_FILE_TELL: | ||
181 | case BIO_CTRL_INFO: | ||
182 | ret=0; | ||
183 | break; | ||
184 | case BIO_C_SET_FD: | 175 | case BIO_C_SET_FD: |
185 | sock_free(b); | 176 | sock_free(b); |
186 | b->num= *((int *)ptr); | 177 | b->num= *((int *)ptr); |
@@ -203,10 +194,6 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
203 | case BIO_CTRL_SET_CLOSE: | 194 | case BIO_CTRL_SET_CLOSE: |
204 | b->shutdown=(int)num; | 195 | b->shutdown=(int)num; |
205 | break; | 196 | break; |
206 | case BIO_CTRL_PENDING: | ||
207 | case BIO_CTRL_WPENDING: | ||
208 | ret=0; | ||
209 | break; | ||
210 | case BIO_CTRL_DUP: | 197 | case BIO_CTRL_DUP: |
211 | case BIO_CTRL_FLUSH: | 198 | case BIO_CTRL_FLUSH: |
212 | ret=1; | 199 | ret=1; |