From de8f24ea083384bb66b32ec105dc4743c5663cdf Mon Sep 17 00:00:00 2001 From: beck <> Date: Wed, 29 Sep 1999 04:37:45 +0000 Subject: OpenSSL 0.9.4 merge --- src/lib/libcrypto/bio/Makefile.ssl | 170 +++++++++-- src/lib/libcrypto/bio/b_dump.c | 13 +- src/lib/libcrypto/bio/b_print.c | 19 +- src/lib/libcrypto/bio/b_sock.c | 319 ++++++++++++-------- src/lib/libcrypto/bio/bf_buff.c | 49 +--- src/lib/libcrypto/bio/bf_nbio.c | 50 +--- src/lib/libcrypto/bio/bf_null.c | 48 +-- src/lib/libcrypto/bio/bio.err | 46 --- src/lib/libcrypto/bio/bio.h | 343 ++++++++++------------ src/lib/libcrypto/bio/bio_cb.c | 13 +- src/lib/libcrypto/bio/bio_err.c | 131 +++++---- src/lib/libcrypto/bio/bio_lib.c | 147 ++++------ src/lib/libcrypto/bio/bss_acpt.c | 132 ++++----- src/lib/libcrypto/bio/bss_bio.c | 588 +++++++++++++++++++++++++++++++++++++ src/lib/libcrypto/bio/bss_conn.c | 146 ++++----- src/lib/libcrypto/bio/bss_file.c | 60 +--- src/lib/libcrypto/bio/bss_log.c | 232 +++++++++++++++ src/lib/libcrypto/bio/bss_mem.c | 59 ++-- src/lib/libcrypto/bio/bss_null.c | 46 +-- src/lib/libcrypto/bio/bss_rtcp.c | 56 ++-- src/lib/libcrypto/bio/bss_sock.c | 118 +++----- 21 files changed, 1709 insertions(+), 1076 deletions(-) delete mode 100644 src/lib/libcrypto/bio/bio.err create mode 100644 src/lib/libcrypto/bio/bss_bio.c create mode 100644 src/lib/libcrypto/bio/bss_log.c (limited to 'src/lib/libcrypto/bio') diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl index 42e11e1c94..f54c7ee1f0 100644 --- a/src/lib/libcrypto/bio/Makefile.ssl +++ b/src/lib/libcrypto/bio/Makefile.ssl @@ -7,36 +7,36 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=bio -ERRC=bio_err GENERAL=Makefile TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= bio_lib.c bio_cb.c $(ERRC).c \ +LIBSRC= bio_lib.c bio_cb.c bio_err.c \ bss_mem.c bss_null.c bss_fd.c \ bss_file.c bss_sock.c bss_conn.c \ bf_null.c bf_buff.c b_print.c b_dump.c \ - b_sock.c bss_acpt.c bf_nbio.c -LIBOBJ= bio_lib.o bio_cb.o $(ERRC).o \ + b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c +LIBOBJ= bio_lib.o bio_cb.o bio_err.o \ bss_mem.o bss_null.o bss_fd.o \ bss_file.o bss_sock.o bss_conn.o \ bf_null.o bf_buff.o b_print.o b_dump.o \ - b_sock.o bss_acpt.o bf_nbio.o + b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o SRC= $(LIBSRC) -EXHEADER= bio.h bss_file.c -HEADER= $(EXHEADER) +EXHEADER= bio.h +HEADER= bss_file.c $(EXHEADER) ALL= $(GENERAL) $(SRC) $(HEADER) @@ -47,24 +47,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: - @for i in $(EXHEADER) bss_file.c ; \ + @for i in $(EXHEADER); \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -76,17 +75,136 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +b_dump.o: ../../include/openssl/stack.h ../cryptlib.h +b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +b_print.o: ../../include/openssl/stack.h ../cryptlib.h +b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +b_sock.o: ../../include/openssl/stack.h ../cryptlib.h +bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bf_buff.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bf_buff.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bf_buff.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bf_buff.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bf_buff.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bf_buff.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bf_buff.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bf_buff.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bf_buff.o: ../../include/openssl/stack.h ../cryptlib.h +bf_nbio.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bf_nbio.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bf_nbio.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bf_nbio.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bf_nbio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bf_nbio.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bf_nbio.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bf_nbio.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +bf_nbio.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +bf_nbio.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +bf_nbio.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +bf_nbio.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +bf_nbio.o: ../cryptlib.h +bf_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bf_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bf_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bf_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bf_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bf_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bf_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bf_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bf_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bf_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bf_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bf_null.o: ../../include/openssl/stack.h ../cryptlib.h +bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bio_cb.o: ../../include/openssl/stack.h ../cryptlib.h +bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h +bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h +bio_err.o: ../../include/openssl/stack.h +bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bio_lib.o: ../../include/openssl/stack.h ../cryptlib.h +bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_acpt.o: ../../include/openssl/opensslconf.h +bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_acpt.o: ../cryptlib.h +bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h +bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h +bss_bio.o: ../../include/openssl/stack.h +bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_conn.o: ../../include/openssl/opensslconf.h +bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_conn.o: ../cryptlib.h +bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bss_fd.o: ../../include/openssl/stack.h ../cryptlib.h bss_sock.c +bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_file.o: ../../include/openssl/opensslconf.h +bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_file.o: ../cryptlib.h +bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bss_log.o: ../../include/openssl/stack.h ../cryptlib.h +bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bss_mem.o: ../../include/openssl/stack.h ../cryptlib.h +bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_null.o: ../../include/openssl/opensslconf.h +bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_null.o: ../cryptlib.h +bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_sock.o: ../../include/openssl/opensslconf.h +bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_sock.o: ../cryptlib.h diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c index db84ad3d47..a7cd828978 100644 --- a/src/lib/libcrypto/bio/b_dump.c +++ b/src/lib/libcrypto/bio/b_dump.c @@ -62,15 +62,12 @@ #include #include "cryptlib.h" -#include "bio.h" +#include #define TRUNCATE #define DUMP_WIDTH 16 -int BIO_dump(bio,s,len) -BIO *bio; -char *s; -int len; +int BIO_dump(BIO *bio, const char *s, int len) { int ret=0; char buf[160+1],tmp[20]; @@ -105,7 +102,13 @@ int len; if (((i*DUMP_WIDTH)+j)>=len) break; ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; +#ifndef CHARSET_EBCDIC sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); +#else + sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) + ? os_toebcdic[ch] + : '.'); +#endif strcat(buf,tmp); } strcat(buf,"\n"); diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index cdadeb839a..f448004298 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c @@ -61,32 +61,27 @@ */ #include +#include #include "cryptlib.h" -#include "bio.h" +#include -int BIO_printf ( VAR_PLIST( BIO *, bio ) ) -VAR_ALIST +int BIO_printf (BIO *bio, ...) { - VAR_BDEFN(args, BIO *, bio); + va_list args; char *format; int ret; MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ - VAR_INIT(args, BIO *, bio); - VAR_ARG(args, char *, format); + va_start(args, bio); + format=va_arg(args, char *); hugebuf[0]='\0'; -/* no-one uses _doprnt anymore and it appears to be broken under SunOS 4.1.4 */ -#if 0 && defined(sun) && !defined(VAR_ANSI) /**/ - _doprnt(hugebuf,format,args); -#else /* !sun */ vsprintf(hugebuf,format,args); -#endif /* sun */ ret=BIO_write(bio,hugebuf,strlen(hugebuf)); - VAR_END( args ); + va_end(args); return(ret); } diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index a45909527c..d29b29ff8b 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c @@ -63,9 +63,7 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" - -/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ +#include #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -96,21 +94,14 @@ static struct ghbn_cache_st unsigned long order; } ghbn_cache[GHBN_NUM]; -#ifndef NOPROTO -static int get_ip(char *str,unsigned char *ip); +static int get_ip(const char *str,unsigned char *ip); static void ghbn_free(struct hostent *a); static struct hostent *ghbn_dup(struct hostent *a); -#else -static int get_ip(); -static void ghbn_free(); -static struct hostent *ghbn_dup(); -#endif - -int BIO_get_host_ip(str,ip) -char *str; -unsigned char *ip; +int BIO_get_host_ip(const char *str, unsigned char *ip) { int i; + int err = 1; + int locked = 0; struct hostent *he; i=get_ip(str,ip); @@ -118,37 +109,45 @@ unsigned char *ip; if (i < 0) { BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); - ERR_add_error_data(2,"host=",str); - return(0); + goto err; } - else - { /* do a gethostbyname */ - if (!BIO_sock_init()) return(0); - he=BIO_gethostbyname(str); - if (he == NULL) - { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); - ERR_add_error_data(2,"host=",str); - return(0); - } + /* do a gethostbyname */ + if (!BIO_sock_init()) + return(0); /* don't generate another error code here */ - /* cast to short because of win16 winsock definition */ - if ((short)he->h_addrtype != AF_INET) - { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); - ERR_add_error_data(2,"host=",str); - return(0); - } - for (i=0; i<4; i++) - ip[i]=he->h_addr_list[0][i]; + CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); + locked = 1; + he=BIO_gethostbyname(str); + if (he == NULL) + { + BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); + goto err; } - return(1); + + /* cast to short because of win16 winsock definition */ + if ((short)he->h_addrtype != AF_INET) + { + BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); + goto err; + } + for (i=0; i<4; i++) + ip[i]=he->h_addr_list[0][i]; + err = 0; + + err: + if (locked) + CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); + if (err) + { + ERR_add_error_data(2,"host=",str); + return 0; + } + else + return 1; } -int BIO_get_port(str,port_ptr) -char *str; -short *port_ptr; +int BIO_get_port(const char *str, unsigned short *port_ptr) { int i; struct servent *s; @@ -163,8 +162,12 @@ short *port_ptr; *port_ptr=(unsigned short)i; else { - s=getservbyname(str,"tcp"); - if (s == NULL) + CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); + s=getservbyname(str,"tcp"); + if(s != NULL) + *port_ptr=ntohs((unsigned short)s->s_port); + CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); + if(s == NULL) { if (strcmp(str,"http") == 0) *port_ptr=80; @@ -190,31 +193,30 @@ short *port_ptr; ERR_add_error_data(3,"service='",str,"'"); return(0); } - return(1); } - *port_ptr=htons((unsigned short)s->s_port); } return(1); } -int BIO_sock_error(sock) -int sock; +int BIO_sock_error(int sock) { - int j,i,size; + int j,i; + int size; size=sizeof(int); - - i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size); + /* Note: under Windows the third parameter is of type (char *) + * whereas under other systems it is (void *) if you don't have + * a cast it will choke the compiler: if you do have a cast then + * you can either go for (char *) or (void *). + */ + i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size); if (i < 0) return(1); else return(j); } -long BIO_ghbn_ctrl(cmd,iarg,parg) -int cmd; -int iarg; -char *parg; +long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) { int i; char **p; @@ -223,13 +225,13 @@ char *parg; { case BIO_GHBN_CTRL_HITS: return(BIO_ghbn_hits); - break; + /* break; */ case BIO_GHBN_CTRL_MISSES: return(BIO_ghbn_miss); - break; + /* break; */ case BIO_GHBN_CTRL_CACHE_SIZE: return(GHBN_NUM); - break; + /* break; */ case BIO_GHBN_CTRL_GET_ENTRY: if ((iarg >= 0) && (iarg 0)) @@ -241,7 +243,7 @@ char *parg; return(1); } return(0); - break; + /* break; */ case BIO_GHBN_CTRL_FLUSH: for (i=0; ih_aliases[i] != NULL; i++) ; i++; - ret->h_aliases=(char **)malloc(sizeof(char *)*i); - memset(ret->h_aliases,0,sizeof(char *)*i); - if (ret == NULL) goto err; + ret->h_aliases = (char **)Malloc(i*sizeof(char *)); + if (ret->h_aliases == NULL) + goto err; + memset(ret->h_aliases, 0, i*sizeof(char *)); for (i=0; a->h_addr_list[i] != NULL; i++) ; i++; - ret->h_addr_list=(char **)malloc(sizeof(char *)*i); - memset(ret->h_addr_list,0,sizeof(char *)*i); - if (ret->h_addr_list == NULL) goto err; + ret->h_addr_list=(char **)Malloc(i*sizeof(char *)); + if (ret->h_addr_list == NULL) + goto err; + memset(ret->h_addr_list, 0, i*sizeof(char *)); j=strlen(a->h_name)+1; - if ((ret->h_name=malloc(j)) == NULL) goto err; - memcpy((char *)ret->h_name,a->h_name,j); + if ((ret->h_name=Malloc(j)) == NULL) goto err; + memcpy((char *)ret->h_name,a->h_name,j+1); for (i=0; a->h_aliases[i] != NULL; i++) { j=strlen(a->h_aliases[i])+1; - if ((ret->h_aliases[i]=malloc(j)) == NULL) goto err; - memcpy(ret->h_aliases[i],a->h_aliases[i],j); + if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; + memcpy(ret->h_aliases[i],a->h_aliases[i],j+1); } ret->h_length=a->h_length; ret->h_addrtype=a->h_addrtype; for (i=0; a->h_addr_list[i] != NULL; i++) { - if ((ret->h_addr_list[i]=malloc(a->h_length)) == NULL) + if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL) goto err; memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); } - return(ret); + if (0) + { err: - if (ret != NULL) - ghbn_free(ret); - return(NULL); + if (ret != NULL) + ghbn_free(ret); + ret=NULL; + } + MemCheck_on(); + return(ret); } -static void ghbn_free(a) -struct hostent *a; +static void ghbn_free(struct hostent *a) { int i; + if(a == NULL) + return; + if (a->h_aliases != NULL) { for (i=0; a->h_aliases[i] != NULL; i++) - free(a->h_aliases[i]); - free(a->h_aliases); + Free(a->h_aliases[i]); + Free(a->h_aliases); } if (a->h_addr_list != NULL) { for (i=0; a->h_addr_list[i] != NULL; i++) - free(a->h_addr_list[i]); - free(a->h_addr_list); + Free(a->h_addr_list[i]); + Free(a->h_addr_list); } - if (a->h_name != NULL) free((char *)a->h_name); - free(a); + if (a->h_name != NULL) Free((char *)a->h_name); + Free(a); } -struct hostent *BIO_gethostbyname(name) -char *name; +struct hostent *BIO_gethostbyname(const char *name) { struct hostent *ret; int i,lowi=0,j; @@ -330,7 +339,12 @@ char *name; /* return(gethostbyname(name)); */ - CRYPTO_w_lock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); +#if 0 /* It doesn't make sense to use locking here: The function interface + * is not thread-safe, because threads can never be sure when + * some other thread destroys the data they were given a pointer to. + */ + CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); +#endif j=strlen(name); if (j < 128) { @@ -356,15 +370,29 @@ char *name; BIO_ghbn_miss++; ret=gethostbyname(name); - if (ret == NULL) return(NULL); - if (j > 128) return(ret); /* too big to cache */ + if (ret == NULL) + goto end; + if (j > 128) /* too big to cache */ + { +#if 0 /* If we were trying to make this function thread-safe (which + * is bound to fail), we'd have to give up in this case + * (or allocate more memory). */ + ret = NULL; +#endif + goto end; + } /* else add to cache */ if (ghbn_cache[lowi].ent != NULL) - ghbn_free(ghbn_cache[lowi].ent); + ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ + ghbn_cache[lowi].name[0] = '\0'; + if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL) + { + BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE); + goto end; + } strncpy(ghbn_cache[lowi].name,name,128); - ghbn_cache[lowi].ent=ghbn_dup(ret); ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; } else @@ -373,11 +401,14 @@ char *name; ret= ghbn_cache[i].ent; ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; } - CRYPTO_w_unlock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); +end: +#if 0 + CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); +#endif return(ret); } -int BIO_sock_init() +int BIO_sock_init(void) { #ifdef WINDOWS static struct WSAData wsa_state; @@ -403,7 +434,7 @@ int BIO_sock_init() return(1); } -void BIO_sock_cleanup() +void BIO_sock_cleanup(void) { #ifdef WINDOWS if (wsa_init_done) @@ -415,10 +446,9 @@ void BIO_sock_cleanup() #endif } -int BIO_socket_ioctl(fd,type,arg) -int fd; -long type; -unsigned long *arg; +#if !defined(VMS) || __VMS_VER >= 70000000 + +int BIO_socket_ioctl(int fd, long type, unsigned long *arg) { int i; @@ -427,12 +457,11 @@ unsigned long *arg; SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error()); return(i); } +#endif /* __VMS_VER */ /* The reason I have implemented this instead of using sscanf is because * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ -static int get_ip(str,ip) -char *str; -unsigned char ip[4]; +static int get_ip(const char *str, unsigned char ip[4]) { unsigned int tmp[4]; int num=0,c,ok=0; @@ -467,16 +496,17 @@ unsigned char ip[4]; return(1); } -int BIO_get_accept_socket(host) -char *host; +int BIO_get_accept_socket(char *host, int bind_mode) { int ret=0; - struct sockaddr_in server; - int s= -1; + struct sockaddr_in server,client; + int s= -1,cs; unsigned char ip[4]; - short port; - char *str,*h,*p,*e; + unsigned short port; + char *str,*e; + const char *h,*p; unsigned long l; + int err_num; if (!BIO_sock_init()) return(INVALID_SOCKET); @@ -508,7 +538,7 @@ char *host; memset((char *)&server,0,sizeof(server)); server.sin_family=AF_INET; - server.sin_port=htons((unsigned short)port); + server.sin_port=htons(port); if (strcmp(h,"*") == 0) server.sin_addr.s_addr=INADDR_ANY; @@ -517,12 +547,13 @@ char *host; if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET); l=(unsigned long) ((unsigned long)ip[0]<<24L)| - ((unsigned long)ip[0]<<16L)| - ((unsigned long)ip[0]<< 8L)| - ((unsigned long)ip[0]); + ((unsigned long)ip[1]<<16L)| + ((unsigned long)ip[2]<< 8L)| + ((unsigned long)ip[3]); server.sin_addr.s_addr=htonl(l); } +again: s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); if (s == INVALID_SOCKET) { @@ -531,9 +562,45 @@ char *host; BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); goto err; } + +#ifdef SO_REUSEADDR + if (bind_mode == BIO_BIND_REUSEADDR) + { + int i=1; + + ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)); + bind_mode=BIO_BIND_NORMAL; + } +#endif if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) { - SYSerr(SYS_F_BIND,get_last_socket_error()); +#ifdef SO_REUSEADDR + err_num=get_last_socket_error(); + if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && + (err_num == EADDRINUSE)) + { + memcpy((char *)&client,(char *)&server,sizeof(server)); + if (strcmp(h,"*") == 0) + client.sin_addr.s_addr=htonl(0x7F000001); + cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); + if (cs != INVALID_SOCKET) + { + int ii; + ii=connect(cs,(struct sockaddr *)&client, + sizeof(client)); + closesocket(cs); + if (ii == INVALID_SOCKET) + { + bind_mode=BIO_BIND_REUSEADDR; + closesocket(s); + goto again; + } + /* else error */ + } + /* else error */ + } +#endif + SYSerr(SYS_F_BIND,err_num); ERR_add_error_data(3,"port='",host,"'"); BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); goto err; @@ -550,30 +617,29 @@ err: if (str != NULL) Free(str); if ((ret == 0) && (s != INVALID_SOCKET)) { -#ifdef WINDOWS closesocket(s); -#else - close(s); -#endif s= INVALID_SOCKET; } return(s); } -int BIO_accept(sock,addr) -int sock; -char **addr; +int BIO_accept(int sock, char **addr) { int ret=INVALID_SOCKET; static struct sockaddr_in from; unsigned long l; - short port; + unsigned short port; int len; char *p; memset((char *)&from,0,sizeof(from)); len=sizeof(from); - ret=accept(sock,(struct sockaddr *)&from,&len); + /* Note: under VMS with SOCKETSHR the fourth parameter is currently + * of type (int *) whereas under other systems it is (void *) if + * you don't have a cast it will choke the compiler: if you do + * have a cast then you can either go for (int *) or (void *). + */ + ret=accept(sock,(struct sockaddr *)&from,(void *)&len); if (ret == INVALID_SOCKET) { SYSerr(SYS_F_ACCEPT,get_last_socket_error()); @@ -604,9 +670,7 @@ end: return(ret); } -int BIO_set_tcp_ndelay(s,on) -int s; -int on; +int BIO_set_tcp_ndelay(int s, int on) { int ret=0; #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) @@ -626,3 +690,14 @@ int on; } #endif +int BIO_socket_nbio(int s, int mode) + { + int ret= -1; + unsigned long l; + + l=mode; +#ifdef FIONBIO + ret=BIO_socket_ioctl(s,FIONBIO,&l); +#endif + return(ret == 0); + } diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c index 7912b88473..acd8148138 100644 --- a/src/lib/libcrypto/bio/bf_buff.c +++ b/src/lib/libcrypto/bio/bf_buff.c @@ -59,10 +59,9 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "evp.h" +#include +#include -#ifndef NOPROTO static int buffer_write(BIO *h,char *buf,int num); static int buffer_read(BIO *h,char *buf,int size); static int buffer_puts(BIO *h,char *str); @@ -70,16 +69,6 @@ static int buffer_gets(BIO *h,char *str,int size); static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int buffer_new(BIO *h); static int buffer_free(BIO *data); -#else -static int buffer_write(); -static int buffer_read(); -static int buffer_puts(); -static int buffer_gets(); -static long buffer_ctrl(); -static int buffer_new(); -static int buffer_free(); -#endif - #define DEFAULT_BUFFER_SIZE 1024 static BIO_METHOD methods_buffer= @@ -95,13 +84,12 @@ static BIO_METHOD methods_buffer= buffer_free, }; -BIO_METHOD *BIO_f_buffer() +BIO_METHOD *BIO_f_buffer(void) { return(&methods_buffer); } -static int buffer_new(bi) -BIO *bi; +static int buffer_new(BIO *bi) { BIO_F_BUFFER_CTX *ctx; @@ -124,8 +112,7 @@ BIO *bi; return(1); } -static int buffer_free(a) -BIO *a; +static int buffer_free(BIO *a) { BIO_F_BUFFER_CTX *b; @@ -140,10 +127,7 @@ BIO *a; return(1); } -static int buffer_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int buffer_read(BIO *b, char *out, int outl) { int i,num=0; BIO_F_BUFFER_CTX *ctx; @@ -209,10 +193,7 @@ start: goto start; } -static int buffer_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int buffer_write(BIO *b, char *in, int inl) { int i,num=0; BIO_F_BUFFER_CTX *ctx; @@ -285,11 +266,7 @@ start: goto start; } -static long buffer_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; BIO_F_BUFFER_CTX *ctx; @@ -432,6 +409,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_ break; } } + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); break; case BIO_CTRL_DUP: dbio=(BIO *)ptr; @@ -449,10 +427,7 @@ malloc_error: return(0); } -static int buffer_gets(b,buf,size) -BIO *b; -char *buf; -int size; +static int buffer_gets(BIO *b, char *buf, int size) { BIO_F_BUFFER_CTX *ctx; int num=0,i,flag; @@ -503,9 +478,7 @@ int size; } } -static int buffer_puts(b,str) -BIO *b; -char *str; +static int buffer_puts(BIO *b, char *str) { return(BIO_write(b,str,strlen(str))); } diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index 034b3024df..cbec2bae29 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c @@ -59,14 +59,13 @@ #include #include #include "cryptlib.h" -#include "rand.h" -#include "bio.h" -#include "evp.h" +#include +#include +#include /* BIO_put and BIO_get both add to the digest, * BIO_gets returns the digest */ -#ifndef NOPROTO static int nbiof_write(BIO *h,char *buf,int num); static int nbiof_read(BIO *h,char *buf,int size); static int nbiof_puts(BIO *h,char *str); @@ -74,16 +73,6 @@ static int nbiof_gets(BIO *h,char *str,int size); static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int nbiof_new(BIO *h); static int nbiof_free(BIO *data); -#else -static int nbiof_write(); -static int nbiof_read(); -static int nbiof_puts(); -static int nbiof_gets(); -static long nbiof_ctrl(); -static int nbiof_new(); -static int nbiof_free(); -#endif - typedef struct nbio_test_st { /* only set if we sent a 'should retry' error */ @@ -104,13 +93,12 @@ static BIO_METHOD methods_nbiof= nbiof_free, }; -BIO_METHOD *BIO_f_nbio_test() +BIO_METHOD *BIO_f_nbio_test(void) { return(&methods_nbiof); } -static int nbiof_new(bi) -BIO *bi; +static int nbiof_new(BIO *bi) { NBIO_TEST *nt; @@ -123,8 +111,7 @@ BIO *bi; return(1); } -static int nbiof_free(a) -BIO *a; +static int nbiof_free(BIO *a) { if (a == NULL) return(0); if (a->ptr != NULL) @@ -135,10 +122,7 @@ BIO *a; return(1); } -static int nbiof_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int nbiof_read(BIO *b, char *out, int outl) { NBIO_TEST *nt; int ret=0; @@ -173,10 +157,7 @@ int outl; return(ret); } -static int nbiof_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int nbiof_write(BIO *b, char *in, int inl) { NBIO_TEST *nt; int ret=0; @@ -221,11 +202,7 @@ int inl; return(ret); } -static long nbiof_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret; @@ -247,19 +224,14 @@ char *ptr; return(ret); } -static int nbiof_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int nbiof_gets(BIO *bp, char *buf, int size) { if (bp->next_bio == NULL) return(0); return(BIO_gets(bp->next_bio,buf,size)); } -static int nbiof_puts(bp,str) -BIO *bp; -char *str; +static int nbiof_puts(BIO *bp, char *str) { if (bp->next_bio == NULL) return(0); return(BIO_puts(bp->next_bio,str)); diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c index a47a65741a..3254a55dce 100644 --- a/src/lib/libcrypto/bio/bf_null.c +++ b/src/lib/libcrypto/bio/bf_null.c @@ -59,13 +59,12 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "evp.h" +#include +#include /* BIO_put and BIO_get both add to the digest, * BIO_gets returns the digest */ -#ifndef NOPROTO static int nullf_write(BIO *h,char *buf,int num); static int nullf_read(BIO *h,char *buf,int size); static int nullf_puts(BIO *h,char *str); @@ -73,16 +72,6 @@ static int nullf_gets(BIO *h,char *str,int size); static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int nullf_new(BIO *h); static int nullf_free(BIO *data); -#else -static int nullf_write(); -static int nullf_read(); -static int nullf_puts(); -static int nullf_gets(); -static long nullf_ctrl(); -static int nullf_new(); -static int nullf_free(); -#endif - static BIO_METHOD methods_nullf= { BIO_TYPE_NULL_FILTER, @@ -96,13 +85,12 @@ static BIO_METHOD methods_nullf= nullf_free, }; -BIO_METHOD *BIO_f_null() +BIO_METHOD *BIO_f_null(void) { return(&methods_nullf); } -static int nullf_new(bi) -BIO *bi; +static int nullf_new(BIO *bi) { bi->init=1; bi->ptr=NULL; @@ -110,8 +98,7 @@ BIO *bi; return(1); } -static int nullf_free(a) -BIO *a; +static int nullf_free(BIO *a) { if (a == NULL) return(0); /* a->ptr=NULL; @@ -120,10 +107,7 @@ BIO *a; return(1); } -static int nullf_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int nullf_read(BIO *b, char *out, int outl) { int ret=0; @@ -135,10 +119,7 @@ int outl; return(ret); } -static int nullf_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int nullf_write(BIO *b, char *in, int inl) { int ret=0; @@ -150,11 +131,7 @@ int inl; return(ret); } -static long nullf_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret; @@ -175,19 +152,14 @@ char *ptr; return(ret); } -static int nullf_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int nullf_gets(BIO *bp, char *buf, int size) { if (bp->next_bio == NULL) return(0); return(BIO_gets(bp->next_bio,buf,size)); } -static int nullf_puts(bp,str) -BIO *bp; -char *str; +static int nullf_puts(BIO *bp, char *str) { if (bp->next_bio == NULL) return(0); return(BIO_puts(bp->next_bio,str)); diff --git a/src/lib/libcrypto/bio/bio.err b/src/lib/libcrypto/bio/bio.err deleted file mode 100644 index 6e2f2b63ca..0000000000 --- a/src/lib/libcrypto/bio/bio.err +++ /dev/null @@ -1,46 +0,0 @@ -/* Error codes for the BIO functions. */ - -/* Function codes. */ -#define BIO_F_ACPT_STATE 100 -#define BIO_F_BIO_ACCEPT 101 -#define BIO_F_BIO_CTRL 102 -#define BIO_F_BIO_GETS 103 -#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 -#define BIO_F_BIO_GET_HOST_IP 105 -#define BIO_F_BIO_GET_PORT 106 -#define BIO_F_BIO_NEW 107 -#define BIO_F_BIO_NEW_FILE 108 -#define BIO_F_BIO_PUTS 109 -#define BIO_F_BIO_READ 110 -#define BIO_F_BIO_SOCK_INIT 111 -#define BIO_F_BIO_WRITE 112 -#define BIO_F_BUFFER_CTRL 113 -#define BIO_F_CONN_STATE 114 -#define BIO_F_FILE_CTRL 115 -#define BIO_F_MEM_WRITE 116 -#define BIO_F_SSL_NEW 117 -#define BIO_F_WSASTARTUP 118 - -/* Reason codes. */ -#define BIO_R_ACCEPT_ERROR 100 -#define BIO_R_BAD_FOPEN_MODE 101 -#define BIO_R_BAD_HOSTNAME_LOOKUP 102 -#define BIO_R_CONNECT_ERROR 103 -#define BIO_R_ERROR_SETTING_NBIO 104 -#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 -#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 -#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 -#define BIO_R_INVALID_IP_ADDRESS 108 -#define BIO_R_KEEPALIVE 109 -#define BIO_R_NBIO_CONNECT_ERROR 110 -#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 -#define BIO_R_NO_HOSTHNAME_SPECIFIED 112 -#define BIO_R_NO_PORT_DEFINED 113 -#define BIO_R_NO_PORT_SPECIFIED 114 -#define BIO_R_NULL_PARAMETER 115 -#define BIO_R_UNABLE_TO_BIND_SOCKET 116 -#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 -#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 -#define BIO_R_UNINITALISED 119 -#define BIO_R_UNSUPPORTED_METHOD 120 -#define BIO_R_WSASTARTUP 121 diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index 300b330e00..54bf622a3b 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h @@ -63,7 +63,9 @@ extern "C" { #endif -#include "crypto.h" +#include +#include +#include /* These are the 'types' of BIOs */ #define BIO_TYPE_NONE 0 @@ -84,6 +86,8 @@ extern "C" { #define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ #define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ #define BIO_TYPE_NULL_FILTER (17|0x0200) +#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ +#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ #define BIO_TYPE_FILTER 0x0200 @@ -202,7 +206,7 @@ extern "C" { typedef struct bio_method_st { int type; - char *name; + const char *name; int (*bwrite)(); int (*bread)(); int (*bputs)(); @@ -215,7 +219,7 @@ typedef struct bio_method_st typedef struct bio_method_st { int type; - char *name; + const char *name; int (_far *bwrite)(); int (_far *bread)(); int (_far *bputs)(); @@ -229,12 +233,8 @@ typedef struct bio_method_st typedef struct bio_st { BIO_METHOD *method; -#ifndef NOPROTO /* bio, mode, argp, argi, argl, ret */ - long (*callback)(struct bio_st *,int,char *,int, long,long); -#else - long (*callback)(); -#endif + long (*callback)(struct bio_st *,int,const char *,int, long,long); char *cb_arg; /* first argument for the callback */ int init; @@ -242,7 +242,7 @@ typedef struct bio_st int flags; /* extra storage */ int retry_reason; int num; - char *ptr; + void *ptr; struct bio_st *next_bio; /* used by filter BIOs */ struct bio_st *prev_bio; /* used by filter BIOs */ int references; @@ -276,7 +276,7 @@ typedef struct bio_f_buffer_ctx_struct #define BIO_CONN_S_OK 6 #define BIO_CONN_S_BLOCKED_CONNECT 7 #define BIO_CONN_S_NBIO 8 -#define BIO_CONN_get_param_hostname BIO_ctrl +/*#define BIO_CONN_get_param_hostname BIO_ctrl */ #define BIO_number_read(b) ((b)->num_read) #define BIO_number_written(b) ((b)->num_write) @@ -309,18 +309,28 @@ typedef struct bio_f_buffer_ctx_struct #define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 #define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +#define BIO_C_FILE_SEEK 128 +#define BIO_C_GET_CIPHER_CTX 129 +#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ +#define BIO_C_SET_BIND_MODE 131 +#define BIO_C_GET_BIND_MODE 132 +#define BIO_C_FILE_TELL 133 +#define BIO_C_GET_SOCKS 134 +#define BIO_C_SET_SOCKS 135 + +#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ +#define BIO_C_GET_WRITE_BUF_SIZE 137 +#define BIO_C_MAKE_BIO_PAIR 138 +#define BIO_C_DESTROY_BIO_PAIR 139 +#define BIO_C_GET_WRITE_GUARANTEE 140 +#define BIO_C_GET_READ_REQUEST 141 +#define BIO_C_SHUTDOWN_WR 142 + #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) #define BIO_get_app_data(s) BIO_get_ex_data(s,0) -int BIO_get_ex_num(BIO *bio); -int BIO_set_ex_data(BIO *bio,int idx,char *data); -char *BIO_get_ex_data(BIO *bio,int idx); -void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); -int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), - int (*dup_func)(), void (*free_func)()); - -/* BIO_s_connect_socket() */ +/* BIO_s_connect() and BIO_s_socks4a_connect() */ #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) @@ -328,7 +338,8 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) #define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) -#define BIO_get_conn_int port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) +#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) + #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) @@ -339,6 +350,12 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) +#define BIO_BIND_NORMAL 0 +#define BIO_BIND_REUSEADDR_IF_UNUSED 1 +#define BIO_BIND_REUSEADDR 2 +#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) +#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) + #define BIO_do_connect(b) BIO_do_handshake(b) #define BIO_do_accept(b) BIO_do_handshake(b) #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) @@ -364,12 +381,26 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) #define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) +#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) +#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) + +/* name is cast to lose const, but might be better to route through a function + so we can do it safely */ +#ifdef CONST_STRICT +/* If you are wondering why this isn't defined, its because CONST_STRICT is + * purely a compile-time kludge to allow const to be checked. + */ +int BIO_read_filename(BIO *b,const char *name); +#else #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ - BIO_CLOSE|BIO_FP_READ,name) + BIO_CLOSE|BIO_FP_READ,(char *)name) +#endif #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_WRITE,name) #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_APPEND,name) +#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) /* WARNING WARNING, this ups the reference count on the read bio of the * SSL structure. This is because the ssl read BIO is now pointed to by @@ -388,8 +419,11 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), /* defined in evp.h */ /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ +#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) #define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) #define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) +#define BIO_set_mem_eof_return(b,v) \ + BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) /* For the BIO_f_buffer() type */ #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) @@ -407,6 +441,9 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) #define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) #define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) +/* ...pending macros have inappropriate return type */ +size_t BIO_ctrl_pending(BIO *b); +size_t BIO_ctrl_wpending(BIO *b); #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) #define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) @@ -414,11 +451,32 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), /* For the BIO_f_buffer() type */ #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) +/* For BIO_s_bio() */ +#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) +#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) +#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) +#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) +/* macros with inappropriate type -- but ...pending macros use int too: */ +#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) +#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) +size_t BIO_ctrl_get_write_guarantee(BIO *b); +size_t BIO_ctrl_get_read_request(BIO *b); + + + #ifdef NO_STDIO #define NO_FP_API #endif -#ifndef NOPROTO + +/* These two aren't currently implemented */ +/* int BIO_get_ex_num(BIO *bio); */ +/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ +int BIO_set_ex_data(BIO *bio,int idx,char *data); +char *BIO_get_ex_data(BIO *bio,int idx); +int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), + int (*dup_func)(), void (*free_func)()); + # if defined(WIN16) && defined(_WINDLL) BIO_METHOD *BIO_s_file_internal(void); BIO *BIO_new_file_internal(char *filename, char *mode); @@ -428,39 +486,20 @@ BIO *BIO_new_fp_internal(FILE *stream, int close_flag); # define BIO_new_fp BIO_new_fp_internal # else /* FP_API */ BIO_METHOD *BIO_s_file(void ); -BIO *BIO_new_file(char *filename, char *mode); +BIO *BIO_new_file(const char *filename, const char *mode); BIO *BIO_new_fp(FILE *stream, int close_flag); # define BIO_s_file_internal BIO_s_file # define BIO_new_file_internal BIO_new_file # define BIO_new_fp_internal BIO_s_file # endif /* FP_API */ -#else -# if defined(WIN16) && defined(_WINDLL) -BIO_METHOD *BIO_s_file_internal(); -BIO *BIO_new_file_internal(); -BIO *BIO_new_fp_internal(); -# define BIO_s_file BIO_s_file_internal -# define BIO_new_file BIO_new_file_internal -# define BIO_new_fp BIO_new_fp_internal -# else /* FP_API */ -BIO_METHOD *BIO_s_file(); -BIO *BIO_new_file(); -BIO *BIO_new_fp(); -# define BIO_s_file_internal BIO_s_file -# define BIO_new_file_internal BIO_new_file -# define BIO_new_fp_internal BIO_s_file -# endif /* FP_API */ -#endif - -#ifndef NOPROTO BIO * BIO_new(BIO_METHOD *type); int BIO_set(BIO *a,BIO_METHOD *type); int BIO_free(BIO *a); -int BIO_read(BIO *b, char *data, int len); +int BIO_read(BIO *b, void *data, int len); int BIO_gets(BIO *bp,char *buf, int size); -int BIO_write(BIO *b, char *data, int len); -int BIO_puts(BIO *bp,char *buf); -long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg); +int BIO_write(BIO *b, const char *data, int len); +int BIO_puts(BIO *bp,const char *buf); +long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); BIO * BIO_push(BIO *b,BIO *append); @@ -472,10 +511,10 @@ int BIO_get_retry_reason(BIO *bio); BIO * BIO_dup_chain(BIO *in); #ifndef WIN16 -long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, +long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, long argl,long ret); #else -long _far _loadds BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, +long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, long argl,long ret); #endif @@ -484,23 +523,35 @@ BIO_METHOD *BIO_s_socket(void); BIO_METHOD *BIO_s_connect(void); BIO_METHOD *BIO_s_accept(void); BIO_METHOD *BIO_s_fd(void); +BIO_METHOD *BIO_s_log(void); +BIO_METHOD *BIO_s_bio(void); BIO_METHOD *BIO_s_null(void); BIO_METHOD *BIO_f_null(void); -BIO_METHOD *BIO_f_nbio_test(void); BIO_METHOD *BIO_f_buffer(void); +BIO_METHOD *BIO_f_nbio_test(void); +/* BIO_METHOD *BIO_f_ber(void); */ int BIO_sock_should_retry(int i); int BIO_sock_non_fatal_error(int error); int BIO_fd_should_retry(int i); int BIO_fd_non_fatal_error(int error); -int BIO_dump(BIO *b,char *bytes,int len); - -struct hostent *BIO_gethostbyname(char *name); +int BIO_dump(BIO *b,const char *bytes,int len); + +struct hostent *BIO_gethostbyname(const char *name); +/* We might want a thread-safe interface too: + * struct hostent *BIO_gethostbyname_r(const char *name, + * struct hostent *result, void *buffer, size_t buflen); + * or something similar (caller allocates a struct hostent, + * pointed to by "result", and additional buffer space for the various + * substructures; if the buffer does not suffice, NULL is returned + * and an appropriate error code is set). + */ int BIO_sock_error(int sock); int BIO_socket_ioctl(int fd, long type, unsigned long *arg); -int BIO_get_port(char *str, short *port_ptr); -int BIO_get_host_ip(char *str, unsigned char *ip); -int BIO_get_accept_socket(char *host_port); +int BIO_socket_nbio(int fd,int mode); +int BIO_get_port(const char *str, unsigned short *port_ptr); +int BIO_get_host_ip(const char *str, unsigned char *ip); +int BIO_get_accept_socket(char *host_port,int mode); int BIO_accept(int sock,char **ip_port); int BIO_sock_init(void ); void BIO_sock_cleanup(void); @@ -513,174 +564,78 @@ BIO *BIO_new_fd(int fd, int close_flag); BIO *BIO_new_connect(char *host_port); BIO *BIO_new_accept(char *host_port); +int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, + BIO **bio2, size_t writebuf2); +/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. + * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. + * Size 0 uses default value. + */ + void BIO_copy_next_retry(BIO *b); long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); -#else - -BIO * BIO_new(); -int BIO_set(); -int BIO_free(); -int BIO_read(); -int BIO_gets(); -int BIO_write(); -int BIO_puts(); -char * BIO_ptr_ctrl(); -long BIO_ctrl(); -long BIO_int_ctrl(); -BIO * BIO_push(); -BIO * BIO_pop(); -void BIO_free_all(); -BIO * BIO_find_type(); -BIO * BIO_get_retry_BIO(); -int BIO_get_retry_reason(); -BIO * BIO_dup_chain(); - -#ifndef WIN16 -long BIO_debug_callback(); -#else -long _far _loadds BIO_debug_callback(); -#endif - -BIO_METHOD *BIO_s_mem(); -BIO_METHOD *BIO_s_socket(); -BIO_METHOD *BIO_s_connect(); -BIO_METHOD *BIO_s_accept(); -BIO_METHOD *BIO_s_fd(); -BIO_METHOD *BIO_s_null(); -BIO_METHOD *BIO_f_null(); -BIO_METHOD *BIO_f_buffer(); -BIO_METHOD *BIO_f_nbio_test(); - -int BIO_sock_should_retry(); -int BIO_sock_non_fatal_error(); -int BIO_fd_should_retry(); -int BIO_fd_non_fatal_error(); -int BIO_dump(); - -struct hostent *BIO_gethostbyname(); -int BIO_sock_error(); -int BIO_socket_ioctl(); -int BIO_get_port(); -int BIO_get_host_ip(); -int BIO_get_accept_socket(); -int BIO_accept(); -int BIO_sock_init(); -void BIO_sock_cleanup(); -int BIO_set_tcp_ndelay(); - -void ERR_load_BIO_strings(); - -BIO *BIO_new_socket(); -BIO *BIO_new_fd(); -BIO *BIO_new_connect(); -BIO *BIO_new_accept(); - -void BIO_copy_next_retry(); - -int BIO_ghbn_ctrl(); - -#endif - -/* Tim Hudson's portable varargs stuff */ - -#ifndef NOPROTO -#define VAR_ANSI /* select ANSI version by default */ -#endif - -#ifdef VAR_ANSI -/* ANSI version of a "portable" macro set for variable length args */ -#ifndef __STDARG_H__ /**/ -#include -#endif /**/ - -#define VAR_PLIST(arg1type,arg1) arg1type arg1, ... -#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) arg1type arg1,arg2type arg2,... -#define VAR_ALIST -#define VAR_BDEFN(args,arg1type,arg1) va_list args -#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args -#define VAR_INIT(args,arg1type,arg1) va_start(args,arg1); -#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args,arg2); -#define VAR_ARG(args,type,arg) arg=va_arg(args,type) -#define VAR_END(args) va_end(args); - -#else - -/* K&R version of a "portable" macro set for variable length args */ -#ifndef __VARARGS_H__ -#include -#endif - -#define VAR_PLIST(arg1type,arg1) va_alist -#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) va_alist -#define VAR_ALIST va_dcl -#define VAR_BDEFN(args,arg1type,arg1) va_list args; arg1type arg1 -#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args; \ - arg1type arg1; arg2type arg2 -#define VAR_INIT(args,arg1type,arg1) va_start(args); \ - arg1=va_arg(args,arg1type); -#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args); \ - arg1=va_arg(args,arg1type); arg2=va_arg(args,arg2type); -#define VAR_ARG(args,type,arg) arg=va_arg(args,type) -#define VAR_END(args) va_end(args); - -#endif - -#ifndef NOPROTO -int BIO_printf( VAR_PLIST( BIO *, bio ) ); -#else -int BIO_printf(); -#endif +int BIO_printf(BIO *bio, ...); /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the BIO functions. */ /* Function codes. */ #define BIO_F_ACPT_STATE 100 #define BIO_F_BIO_ACCEPT 101 -#define BIO_F_BIO_CTRL 102 -#define BIO_F_BIO_GETS 103 -#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 -#define BIO_F_BIO_GET_HOST_IP 105 -#define BIO_F_BIO_GET_PORT 106 -#define BIO_F_BIO_NEW 107 -#define BIO_F_BIO_NEW_FILE 108 -#define BIO_F_BIO_PUTS 109 -#define BIO_F_BIO_READ 110 -#define BIO_F_BIO_SOCK_INIT 111 -#define BIO_F_BIO_WRITE 112 -#define BIO_F_BUFFER_CTRL 113 -#define BIO_F_CONN_STATE 114 -#define BIO_F_FILE_CTRL 115 -#define BIO_F_MEM_WRITE 116 -#define BIO_F_SSL_NEW 117 -#define BIO_F_WSASTARTUP 118 +#define BIO_F_BIO_BER_GET_HEADER 102 +#define BIO_F_BIO_CTRL 103 +#define BIO_F_BIO_GETHOSTBYNAME 120 +#define BIO_F_BIO_GETS 104 +#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 +#define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_PORT 107 +#define BIO_F_BIO_MAKE_PAIR 121 +#define BIO_F_BIO_NEW 108 +#define BIO_F_BIO_NEW_FILE 109 +#define BIO_F_BIO_PUTS 110 +#define BIO_F_BIO_READ 111 +#define BIO_F_BIO_SOCK_INIT 112 +#define BIO_F_BIO_WRITE 113 +#define BIO_F_BUFFER_CTRL 114 +#define BIO_F_CONN_STATE 115 +#define BIO_F_FILE_CTRL 116 +#define BIO_F_MEM_WRITE 117 +#define BIO_F_SSL_NEW 118 +#define BIO_F_WSASTARTUP 119 /* Reason codes. */ #define BIO_R_ACCEPT_ERROR 100 #define BIO_R_BAD_FOPEN_MODE 101 #define BIO_R_BAD_HOSTNAME_LOOKUP 102 +#define BIO_R_BROKEN_PIPE 124 #define BIO_R_CONNECT_ERROR 103 #define BIO_R_ERROR_SETTING_NBIO 104 #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 #define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 +#define BIO_R_INVALID_ARGUMENT 125 #define BIO_R_INVALID_IP_ADDRESS 108 +#define BIO_R_IN_USE 123 #define BIO_R_KEEPALIVE 109 #define BIO_R_NBIO_CONNECT_ERROR 110 #define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 -#define BIO_R_NO_HOSTHNAME_SPECIFIED 112 +#define BIO_R_NO_HOSTNAME_SPECIFIED 112 #define BIO_R_NO_PORT_DEFINED 113 #define BIO_R_NO_PORT_SPECIFIED 114 #define BIO_R_NULL_PARAMETER 115 -#define BIO_R_UNABLE_TO_BIND_SOCKET 116 -#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 -#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 -#define BIO_R_UNINITALISED 119 -#define BIO_R_UNSUPPORTED_METHOD 120 -#define BIO_R_WSASTARTUP 121 - +#define BIO_R_TAG_MISMATCH 116 +#define BIO_R_UNABLE_TO_BIND_SOCKET 117 +#define BIO_R_UNABLE_TO_CREATE_SOCKET 118 +#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 +#define BIO_R_UNINITIALIZED 120 +#define BIO_R_UNSUPPORTED_METHOD 121 +#define BIO_R_WSASTARTUP 122 + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c index bc6ed9eda1..37c7c22666 100644 --- a/src/lib/libcrypto/bio/bio_cb.c +++ b/src/lib/libcrypto/bio/bio_cb.c @@ -60,16 +60,11 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "err.h" +#include +#include -long MS_CALLBACK BIO_debug_callback(bio,cmd,argp,argi,argl,ret) -BIO *bio; -int cmd; -char *argp; -int argi; -long argl; -long ret; +long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp, + int argi, long argl, long ret) { BIO *b; MS_STATIC char buf[256]; diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c index 37e14ca107..712d98a3a1 100644 --- a/src/lib/libcrypto/bio/bio_err.c +++ b/src/lib/libcrypto/bio/bio_err.c @@ -1,63 +1,65 @@ -/* lib/bio/bio_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/bio/bio_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "bio.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -65,11 +67,14 @@ static ERR_STRING_DATA BIO_str_functs[]= { {ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"}, {ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"}, +{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"}, {ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"}, +{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"}, {ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"}, {ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"}, {ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"}, {ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"}, +{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"}, {ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, {ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, {ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, @@ -80,9 +85,9 @@ static ERR_STRING_DATA BIO_str_functs[]= {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, -{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_NEW"}, +{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"}, {ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA BIO_str_reasons[]= @@ -90,36 +95,40 @@ static ERR_STRING_DATA BIO_str_reasons[]= {BIO_R_ACCEPT_ERROR ,"accept error"}, {BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"}, {BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"}, +{BIO_R_BROKEN_PIPE ,"broken pipe"}, {BIO_R_CONNECT_ERROR ,"connect error"}, {BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"}, {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"}, {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"}, {BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"}, +{BIO_R_INVALID_ARGUMENT ,"invalid argument"}, {BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"}, +{BIO_R_IN_USE ,"in use"}, {BIO_R_KEEPALIVE ,"keepalive"}, {BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"}, {BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"}, -{BIO_R_NO_HOSTHNAME_SPECIFIED ,"no hosthname specified"}, +{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"}, {BIO_R_NO_PORT_DEFINED ,"no port defined"}, {BIO_R_NO_PORT_SPECIFIED ,"no port specified"}, {BIO_R_NULL_PARAMETER ,"null parameter"}, +{BIO_R_TAG_MISMATCH ,"tag mismatch"}, {BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"}, {BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"}, {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, -{BIO_R_UNINITALISED ,"uninitalised"}, +{BIO_R_UNINITIALIZED ,"uninitialized"}, {BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, {BIO_R_WSASTARTUP ,"wsastartup"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_BIO_strings() +void ERR_load_BIO_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_BIO,BIO_str_functs); diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 7a66b0892e..b72688ea90 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c @@ -58,16 +58,15 @@ #include #include -#include "crypto.h" +#include #include "cryptlib.h" -#include "bio.h" -#include "stack.h" +#include +#include static STACK *bio_meth=NULL; static int bio_meth_num=0; -BIO *BIO_new(method) -BIO_METHOD *method; +BIO *BIO_new(BIO_METHOD *method) { BIO *ret=NULL; @@ -85,9 +84,7 @@ BIO_METHOD *method; return(ret); } -int BIO_set(bio,method) -BIO *bio; -BIO_METHOD *method; +int BIO_set(BIO *bio, BIO_METHOD *method) { bio->method=method; bio->callback=NULL; @@ -110,8 +107,7 @@ BIO_METHOD *method; return(1); } -int BIO_free(a) -BIO *a; +int BIO_free(BIO *a) { int ret=0,i; @@ -121,7 +117,7 @@ BIO *a; #ifdef REF_PRINT REF_PRINT("BIO",a); #endif - if (i > 0) return(1); + if (i > 0) return(1); #ifdef REF_CHECK if (i < 0) { @@ -141,10 +137,7 @@ BIO *a; return(1); } -int BIO_read(b,out,outl) -BIO *b; -char *out; -int outl; +int BIO_read(BIO *b, void *out, int outl) { int i; long (*cb)(); @@ -162,11 +155,12 @@ int outl; if (!b->init) { - BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); return(-2); } i=b->method->bread(b,out,outl); + if (i > 0) b->num_read+=(unsigned long)i; if (cb != NULL) @@ -175,10 +169,7 @@ int outl; return(i); } -int BIO_write(b,in,inl) -BIO *b; -char *in; -int inl; +int BIO_write(BIO *b, const char *in, int inl) { int i; long (*cb)(); @@ -199,22 +190,27 @@ int inl; if (!b->init) { - BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); return(-2); } i=b->method->bwrite(b,in,inl); + if (i > 0) b->num_write+=(unsigned long)i; - if (cb != NULL) + /* This is evil and not thread safe. If the BIO has been freed, + * we must not call the callback. The only way to be able to + * determine this is the reference count which is now invalid since + * the memory has been free()ed. + */ + if (b->references <= 0) abort(); + if (cb != NULL) /* && (b->references >= 1)) */ i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, 0L,(long)i); return(i); } -int BIO_puts(b,in) -BIO *b; -char *in; +int BIO_puts(BIO *b, const char *in) { int i; long (*cb)(); @@ -233,7 +229,7 @@ char *in; if (!b->init) { - BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); return(-2); } @@ -245,10 +241,7 @@ char *in; return(i); } -int BIO_gets(b,in,inl) -BIO *b; -char *in; -int inl; +int BIO_gets(BIO *b, char *in, int inl) { int i; long (*cb)(); @@ -267,7 +260,7 @@ int inl; if (!b->init) { - BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); return(-2); } @@ -279,11 +272,7 @@ int inl; return(i); } -long BIO_int_ctrl(b,cmd,larg,iarg) -BIO *b; -int cmd; -long larg; -int iarg; +long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) { int i; @@ -291,10 +280,7 @@ int iarg; return(BIO_ctrl(b,cmd,larg,(char *)&i)); } -char *BIO_ptr_ctrl(b,cmd,larg) -BIO *b; -int cmd; -long larg; +char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) { char *p=NULL; @@ -304,11 +290,7 @@ long larg; return(p); } -long BIO_ctrl(b,cmd,larg,parg) -BIO *b; -int cmd; -long larg; -char *parg; +long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) { long ret; long (*cb)(); @@ -335,9 +317,22 @@ char *parg; return(ret); } +/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros + * do; but those macros have inappropriate return type, and for interfacing + * from other programming languages, C macros aren't much of a help anyway. */ +size_t BIO_ctrl_pending(BIO *bio) + { + return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); + } + +size_t BIO_ctrl_wpending(BIO *bio) + { + return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); + } + + /* put the 'bio' on the end of b's list of operators */ -BIO *BIO_push(b,bio) -BIO *b,*bio; +BIO *BIO_push(BIO *b, BIO *bio) { BIO *lb; @@ -354,8 +349,7 @@ BIO *b,*bio; } /* Remove the first and return the rest */ -BIO *BIO_pop(b) -BIO *b; +BIO *BIO_pop(BIO *b) { BIO *ret; @@ -373,9 +367,7 @@ BIO *b; return(ret); } -BIO *BIO_get_retry_BIO(bio,reason) -BIO *bio; -int *reason; +BIO *BIO_get_retry_BIO(BIO *bio, int *reason) { BIO *b,*last; @@ -391,15 +383,12 @@ int *reason; return(last); } -int BIO_get_retry_reason(bio) -BIO *bio; +int BIO_get_retry_reason(BIO *bio) { return(bio->retry_reason); } -BIO *BIO_find_type(bio,type) -BIO *bio; -int type; +BIO *BIO_find_type(BIO *bio, int type) { int mt,mask; @@ -421,8 +410,7 @@ int type; return(NULL); } -void BIO_free_all(bio) -BIO *bio; +void BIO_free_all(BIO *bio) { BIO *b; int ref; @@ -438,8 +426,7 @@ BIO *bio; } } -BIO *BIO_dup_chain(in) -BIO *in; +BIO *BIO_dup_chain(BIO *in) { BIO *ret=NULL,*eoc=NULL,*bio,*new; @@ -461,9 +448,9 @@ BIO *in; goto err; } - /* copy app data */ - if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) - goto err; + /* copy app data */ + if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) + goto err; if (ret == NULL) { @@ -483,36 +470,26 @@ err: return(NULL); } -void BIO_copy_next_retry(b) -BIO *b; +void BIO_copy_next_retry(BIO *b) { BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); b->retry_reason=b->next_bio->retry_reason; } -int BIO_get_ex_new_index(argl,argp,new_func,dup_func,free_func) -long argl; -char *argp; -int (*new_func)(); -int (*dup_func)(); -void (*free_func)(); - { - bio_meth_num++; - return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, - argl,argp,new_func,dup_func,free_func)); - } - -int BIO_set_ex_data(bio,idx,data) -BIO *bio; -int idx; -char *data; +int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), + int (*dup_func)(), void (*free_func)()) + { + bio_meth_num++; + return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, + argl,argp,new_func,dup_func,free_func)); + } + +int BIO_set_ex_data(BIO *bio, int idx, char *data) { return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); } -char *BIO_get_ex_data(bio,idx) -BIO *bio; -int idx; +char *BIO_get_ex_data(BIO *bio, int idx) { return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); } diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c index e49902fa9f..47af80f76d 100644 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ b/src/lib/libcrypto/bio/bss_acpt.c @@ -62,9 +62,7 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" - -/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ +#include #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -72,6 +70,11 @@ #define SOCKET_PROTOCOL IPPROTO_TCP #endif +#if (defined(VMS) && __VMS_VER < 70000000) +/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ +#undef FIONBIO +#endif + typedef struct bio_accept_st { int state; @@ -82,39 +85,24 @@ typedef struct bio_accept_st char *addr; int nbio; + /* If 0, it means normal, if 1, do a connect on bind failure, + * and if there is no-one listening, bind with SO_REUSEADDR. + * If 2, always use SO_REUSEADDR. */ + int bind_mode; BIO *bio_chain; } BIO_ACCEPT; -#ifndef NOPROTO static int acpt_write(BIO *h,char *buf,int num); static int acpt_read(BIO *h,char *buf,int size); static int acpt_puts(BIO *h,char *str); static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int acpt_new(BIO *h); static int acpt_free(BIO *data); -#else -static int acpt_write(); -static int acpt_read(); -static int acpt_puts(); -static long acpt_ctrl(); -static int acpt_new(); -static int acpt_free(); -#endif - -#ifndef NOPROTO static int acpt_state(BIO *b, BIO_ACCEPT *c); static void acpt_close_socket(BIO *data); BIO_ACCEPT *BIO_ACCEPT_new(void ); void BIO_ACCEPT_free(BIO_ACCEPT *a); -#else - -static int acpt_state(); -static void acpt_close_socket(); -BIO_ACCEPT *BIO_ACCEPT_new(); -void BIO_ACCEPT_free(); -#endif - #define ACPT_S_BEFORE 1 #define ACPT_S_GET_ACCEPT_SOCKET 2 #define ACPT_S_OK 3 @@ -132,13 +120,12 @@ static BIO_METHOD methods_acceptp= acpt_free, }; -BIO_METHOD *BIO_s_accept() +BIO_METHOD *BIO_s_accept(void) { return(&methods_acceptp); } -static int acpt_new(bi) -BIO *bi; +static int acpt_new(BIO *bi) { BIO_ACCEPT *ba; @@ -153,7 +140,7 @@ BIO *bi; return(1); } -BIO_ACCEPT *BIO_ACCEPT_new() +BIO_ACCEPT *BIO_ACCEPT_new(void) { BIO_ACCEPT *ret; @@ -162,20 +149,22 @@ BIO_ACCEPT *BIO_ACCEPT_new() memset(ret,0,sizeof(BIO_ACCEPT)); ret->accept_sock=INVALID_SOCKET; + ret->bind_mode=BIO_BIND_NORMAL; return(ret); } -void BIO_ACCEPT_free(a) -BIO_ACCEPT *a; +void BIO_ACCEPT_free(BIO_ACCEPT *a) { + if(a == NULL) + return; + if (a->param_addr != NULL) Free(a->param_addr); if (a->addr != NULL) Free(a->addr); if (a->bio_chain != NULL) BIO_free(a->bio_chain); Free(a); } -static void acpt_close_socket(bio) -BIO *bio; +static void acpt_close_socket(BIO *bio) { BIO_ACCEPT *c; @@ -183,18 +172,13 @@ BIO *bio; if (c->accept_sock != INVALID_SOCKET) { shutdown(c->accept_sock,2); -# ifdef WINDOWS closesocket(c->accept_sock); -# else - close(c->accept_sock); -# endif c->accept_sock=INVALID_SOCKET; bio->num=INVALID_SOCKET; } } -static int acpt_free(a) -BIO *a; +static int acpt_free(BIO *a) { BIO_ACCEPT *data; @@ -212,12 +196,9 @@ BIO *a; return(1); } -static int acpt_state(b,c) -BIO *b; -BIO_ACCEPT *c; +static int acpt_state(BIO *b, BIO_ACCEPT *c) { BIO *bio=NULL,*dbio; - unsigned long l=1; int s= -1; int i; @@ -230,31 +211,24 @@ again: BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); return(-1); } - s=BIO_get_accept_socket(c->param_addr); + s=BIO_get_accept_socket(c->param_addr,c->bind_mode); if (s == INVALID_SOCKET) return(-1); -#ifdef FIONBIO if (c->accept_nbio) { - i=BIO_socket_ioctl(b->num,FIONBIO,&l); - if (i < 0) + if (!BIO_socket_nbio(s,1)) { -#ifdef WINDOWS closesocket(s); -#else - close(s); -# endif BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); return(-1); } } -#endif c->accept_sock=s; b->num=s; c->state=ACPT_S_GET_ACCEPT_SOCKET; return(1); - break; + /* break; */ case ACPT_S_GET_ACCEPT_SOCKET: if (b->next_bio != NULL) { @@ -269,17 +243,14 @@ again: BIO_set_callback(bio,BIO_get_callback(b)); BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); -#ifdef FIONBIO if (c->nbio) { - i=BIO_socket_ioctl(i,FIONBIO,&l); - if (i < 0) + if (!BIO_socket_nbio(i,1)) { BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); goto err; } } -#endif /* If the accept BIO has an bio_chain, we dup it and * put the new socket at the end. */ @@ -298,15 +269,9 @@ err: if (bio != NULL) BIO_free(bio); else if (s >= 0) - { -#ifdef WINDOWS closesocket(s); -#else - close(s); -# endif - } return(0); - break; + /* break; */ case ACPT_S_OK: if (b->next_bio == NULL) { @@ -314,23 +279,20 @@ err: goto again; } return(1); - break; + /* break; */ default: return(0); - break; + /* break; */ } } -static int acpt_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int acpt_read(BIO *b, char *out, int outl) { int ret=0; BIO_ACCEPT *data; - BIO_clear_retry_flags(b); + BIO_clear_retry_flags(b); data=(BIO_ACCEPT *)b->ptr; while (b->next_bio == NULL) @@ -344,10 +306,7 @@ int outl; return(ret); } -static int acpt_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int acpt_write(BIO *b, char *in, int inl) { int ret; BIO_ACCEPT *data; @@ -366,11 +325,7 @@ int inl; return(ret); } -static long acpt_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; int *ip; @@ -417,13 +372,21 @@ char *ptr; case BIO_C_SET_NBIO: data->nbio=(int)num; break; + case BIO_C_SET_FD: + b->init=1; + b->num= *((int *)ptr); + data->accept_sock=b->num; + data->state=ACPT_S_GET_ACCEPT_SOCKET; + b->shutdown=(int)num; + b->init=1; + break; case BIO_C_GET_FD: if (b->init) { ip=(int *)ptr; if (ip != NULL) *ip=data->accept_sock; - ret=b->num; + ret=data->accept_sock; } else ret= -1; @@ -454,6 +417,12 @@ char *ptr; break; case BIO_CTRL_FLUSH: break; + case BIO_C_SET_BIND_MODE: + data->bind_mode=(int)num; + break; + case BIO_C_GET_BIND_MODE: + ret=(long)data->bind_mode; + break; case BIO_CTRL_DUP: dbio=(BIO *)ptr; /* if (data->param_port) EAY EAY @@ -470,9 +439,7 @@ char *ptr; return(ret); } -static int acpt_puts(bp,str) -BIO *bp; -char *str; +static int acpt_puts(BIO *bp, char *str) { int n,ret; @@ -481,8 +448,7 @@ char *str; return(ret); } -BIO *BIO_new_accept(str) -char *str; +BIO *BIO_new_accept(char *str) { BIO *ret; diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c new file mode 100644 index 0000000000..562e9d8de2 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_bio.c @@ -0,0 +1,588 @@ +/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */ + +/* Special method for a BIO where the other endpoint is also a BIO + * of this kind, handled by the same thread (i.e. the "peer" is actually + * ourselves, wearing a different hat). + * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces + * for which no specific BIO method is available. + * See ssl/ssltest.c for some hints on how this can be used. */ + +#ifndef BIO_PAIR_DEBUG +# undef NDEBUG /* avoid conflicting definitions */ +# define NDEBUG +#endif + +#include +#include +#include + +#include +#include +#include + +static int bio_new(BIO *bio); +static int bio_free(BIO *bio); +static int bio_read(BIO *bio, char *buf, int size); +static int bio_write(BIO *bio, char *buf, int num); +static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr); +static int bio_puts(BIO *bio, char *str); + +static int bio_make_pair(BIO *bio1, BIO *bio2); +static void bio_destroy_pair(BIO *bio); + +static BIO_METHOD methods_biop = +{ + BIO_TYPE_BIO, + "BIO pair", + bio_write, + bio_read, + bio_puts, + NULL /* no bio_gets */, + bio_ctrl, + bio_new, + bio_free +}; + +BIO_METHOD *BIO_s_bio(void) + { + return &methods_biop; + } + +struct bio_bio_st +{ + BIO *peer; /* NULL if buf == NULL. + * If peer != NULL, then peer->ptr is also a bio_bio_st, + * and its "peer" member points back to us. + * peer != NULL iff init != 0 in the BIO. */ + + /* This is for what we write (i.e. reading uses peer's struct): */ + int closed; /* valid iff peer != NULL */ + size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ + size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ + size_t size; + char *buf; /* "size" elements (if != NULL) */ + + size_t request; /* valid iff peer != NULL; 0 if len != 0, + * otherwise set by peer to number of bytes + * it (unsuccesfully) tried to read, + * never more than buffer space (size-len) warrants. */ +}; + +static int bio_new(BIO *bio) + { + struct bio_bio_st *b; + + b = Malloc(sizeof *b); + if (b == NULL) + return 0; + + b->peer = NULL; + b->size = 17*1024; /* enough for one TLS record (just a default) */ + b->buf = NULL; + + bio->ptr = b; + return 1; + } + + +static int bio_free(BIO *bio) + { + struct bio_bio_st *b; + + if (bio == NULL) + return 0; + b = bio->ptr; + + assert(b != NULL); + + if (b->peer) + bio_destroy_pair(bio); + + if (b->buf != NULL) + { + Free(b->buf); + } + + Free(b); + + return 1; + } + + + +static int bio_read(BIO *bio, char *buf, int size_) + { + size_t size = size_; + size_t rest; + struct bio_bio_st *b, *peer_b; + + BIO_clear_retry_flags(bio); + + if (!bio->init) + return 0; + + b = bio->ptr; + assert(b != NULL); + assert(b->peer != NULL); + peer_b = b->peer->ptr; + assert(peer_b != NULL); + assert(peer_b->buf != NULL); + + peer_b->request = 0; /* will be set in "retry_read" situation */ + + if (buf == NULL || size == 0) + return 0; + + if (peer_b->len == 0) + { + if (peer_b->closed) + return 0; /* writer has closed, and no data is left */ + else + { + BIO_set_retry_read(bio); /* buffer is empty */ + if (size <= peer_b->size) + peer_b->request = size; + else + /* don't ask for more than the peer can + * deliver in one write */ + peer_b->request = peer_b->size; + return -1; + } + } + + /* we can read */ + if (peer_b->len < size) + size = peer_b->len; + + /* now read "size" bytes */ + + rest = size; + + assert(rest > 0); + do /* one or two iterations */ + { + size_t chunk; + + assert(rest <= peer_b->len); + if (peer_b->offset + rest <= peer_b->size) + chunk = rest; + else + /* wrap around ring buffer */ + chunk = peer_b->size - peer_b->offset; + assert(peer_b->offset + chunk <= peer_b->size); + + memcpy(buf, peer_b->buf + peer_b->offset, chunk); + + peer_b->len -= chunk; + if (peer_b->len) + { + peer_b->offset += chunk; + assert(peer_b->offset <= peer_b->size); + if (peer_b->offset == peer_b->size) + peer_b->offset = 0; + buf += chunk; + } + else + { + /* buffer now empty, no need to advance "buf" */ + assert(chunk == rest); + peer_b->offset = 0; + } + rest -= chunk; + } + while (rest); + + return size; + } + +static int bio_write(BIO *bio, char *buf, int num_) + { + size_t num = num_; + size_t rest; + struct bio_bio_st *b; + + BIO_clear_retry_flags(bio); + + if (!bio->init || buf == NULL || num == 0) + return 0; + + b = bio->ptr; + assert(b != NULL); + assert(b->peer != NULL); + assert(b->buf != NULL); + + b->request = 0; + if (b->closed) + { + /* we already closed */ + BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); + return -1; + } + + assert(b->len <= b->size); + + if (b->len == b->size) + { + BIO_set_retry_write(bio); /* buffer is full */ + return -1; + } + + /* we can write */ + if (num > b->size - b->len) + num = b->size - b->len; + + /* now write "num" bytes */ + + rest = num; + + assert(rest > 0); + do /* one or two iterations */ + { + size_t write_offset; + size_t chunk; + + assert(b->len + rest <= b->size); + + write_offset = b->offset + b->len; + if (write_offset >= b->size) + write_offset -= b->size; + /* b->buf[write_offset] is the first byte we can write to. */ + + if (write_offset + rest <= b->size) + chunk = rest; + else + /* wrap around ring buffer */ + chunk = b->size - write_offset; + + memcpy(b->buf + write_offset, buf, chunk); + + b->len += chunk; + + assert(b->len <= b->size); + + rest -= chunk; + buf += chunk; + } + while (rest); + + return num; + } + + +static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) + { + long ret; + struct bio_bio_st *b = bio->ptr; + + assert(b != NULL); + + switch (cmd) + { + /* specific CTRL codes */ + + case BIO_C_SET_WRITE_BUF_SIZE: + if (b->peer) + { + BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); + ret = 0; + } + else if (num == 0) + { + BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); + ret = 0; + } + else + { + size_t new_size = num; + + if (b->size != new_size) + { + if (b->buf) + { + Free(b->buf); + b->buf = NULL; + } + b->size = new_size; + } + ret = 1; + } + break; + + case BIO_C_GET_WRITE_BUF_SIZE: + num = (long) b->size; + + case BIO_C_MAKE_BIO_PAIR: + { + BIO *other_bio = ptr; + + if (bio_make_pair(bio, other_bio)) + ret = 1; + else + ret = 0; + } + break; + + case BIO_C_DESTROY_BIO_PAIR: + /* Effects both BIOs in the pair -- call just once! + * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ + bio_destroy_pair(bio); + ret = 1; + break; + + case BIO_C_GET_WRITE_GUARANTEE: + /* How many bytes can the caller feed to the next write + * withouth having to keep any? */ + if (b->peer == NULL || b->closed) + ret = 0; + else + ret = (long) b->size - b->len; + break; + + case BIO_C_GET_READ_REQUEST: + /* If the peer unsuccesfully tried to read, how many bytes + * were requested? (As with BIO_CTRL_PENDING, that number + * can usually be treated as boolean.) */ + ret = (long) b->request; + break; + + case BIO_C_SHUTDOWN_WR: + /* similar to shutdown(..., SHUT_WR) */ + b->closed = 1; + ret = 1; + break; + + + /* standard CTRL codes follow */ + + case BIO_CTRL_RESET: + if (b->buf != NULL) + { + b->len = 0; + b->offset = 0; + } + ret = 0; + break; + + case BIO_CTRL_GET_CLOSE: + ret = bio->shutdown; + break; + + case BIO_CTRL_SET_CLOSE: + bio->shutdown = (int) num; + ret = 1; + break; + + case BIO_CTRL_PENDING: + if (b->peer != NULL) + { + struct bio_bio_st *peer_b = b->peer->ptr; + + ret = (long) peer_b->len; + } + else + ret = 0; + break; + + case BIO_CTRL_WPENDING: + if (b->buf != NULL) + ret = (long) b->len; + else + ret = 0; + break; + + case BIO_CTRL_DUP: + /* See BIO_dup_chain for circumstances we have to expect. */ + { + BIO *other_bio = ptr; + struct bio_bio_st *other_b; + + assert(other_bio != NULL); + other_b = other_bio->ptr; + assert(other_b != NULL); + + assert(other_b->buf == NULL); /* other_bio is always fresh */ + + other_b->size = b->size; + } + + ret = 1; + break; + + case BIO_CTRL_FLUSH: + ret = 1; + break; + + case BIO_CTRL_EOF: + { + BIO *other_bio = ptr; + + if (other_bio) + { + struct bio_bio_st *other_b = other_bio->ptr; + + assert(other_b != NULL); + ret = other_b->len == 0 && other_b->closed; + } + else + ret = 1; + } + break; + + default: + ret = 0; + } + return ret; + } + +static int bio_puts(BIO *bio, char *str) + { + return bio_write(bio, str, strlen(str)); + } + + +static int bio_make_pair(BIO *bio1, BIO *bio2) + { + struct bio_bio_st *b1, *b2; + + assert(bio1 != NULL); + assert(bio2 != NULL); + + b1 = bio1->ptr; + b2 = bio2->ptr; + + if (b1->peer != NULL || b2->peer != NULL) + { + BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); + return 0; + } + + if (b1->buf == NULL) + { + b1->buf = Malloc(b1->size); + if (b1->buf == NULL) + { + BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); + return 0; + } + b1->len = 0; + b1->offset = 0; + } + + if (b2->buf == NULL) + { + b2->buf = Malloc(b2->size); + if (b2->buf == NULL) + { + BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); + return 0; + } + b2->len = 0; + b2->offset = 0; + } + + b1->peer = bio2; + b1->closed = 0; + b1->request = 0; + b2->peer = bio1; + b2->closed = 0; + b2->request = 0; + + bio1->init = 1; + bio2->init = 1; + + return 1; + } + +static void bio_destroy_pair(BIO *bio) + { + struct bio_bio_st *b = bio->ptr; + + if (b != NULL) + { + BIO *peer_bio = b->peer; + + if (peer_bio != NULL) + { + struct bio_bio_st *peer_b = peer_bio->ptr; + + assert(peer_b != NULL); + assert(peer_b->peer == bio); + + peer_b->peer = NULL; + peer_bio->init = 0; + assert(peer_b->buf != NULL); + peer_b->len = 0; + peer_b->offset = 0; + + b->peer = NULL; + bio->init = 0; + assert(b->buf != NULL); + b->len = 0; + b->offset = 0; + } + } + } + + +/* Exported convenience functions */ +int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, + BIO **bio2_p, size_t writebuf2) + { + BIO *bio1 = NULL, *bio2 = NULL; + long r; + int ret = 0; + + bio1 = BIO_new(BIO_s_bio()); + if (bio1 == NULL) + goto err; + bio2 = BIO_new(BIO_s_bio()); + if (bio2 == NULL) + goto err; + + if (writebuf1) + { + r = BIO_set_write_buf_size(bio1, writebuf1); + if (!r) + goto err; + } + if (writebuf2) + { + r = BIO_set_write_buf_size(bio2, writebuf2); + if (!r) + goto err; + } + + r = BIO_make_bio_pair(bio1, bio2); + if (!r) + goto err; + ret = 1; + + err: + if (ret == 0) + { + if (bio1) + { + BIO_free(bio1); + bio1 = NULL; + } + if (bio2) + { + BIO_free(bio2); + bio2 = NULL; + } + } + + *bio1_p = bio1; + *bio2_p = bio2; + return ret; + } + +size_t BIO_ctrl_get_write_guarantee(BIO *bio) + { + return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); + } + +size_t BIO_ctrl_get_read_request(BIO *bio) + { + return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); + } diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index 6e547bf866..68c46e3d69 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c @@ -62,9 +62,7 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" - -/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ +#include #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -72,6 +70,12 @@ #define SOCKET_PROTOCOL IPPROTO_TCP #endif +#if (defined(VMS) && __VMS_VER < 70000000) +/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ +#undef FIONBIO +#endif + + typedef struct bio_connect_st { int state; @@ -81,13 +85,12 @@ typedef struct bio_connect_st int nbio; unsigned char ip[4]; - short port; + unsigned short port; struct sockaddr_in them; /* int socket; this will be kept in bio->num so that it is * compatable with the bss_sock bio */ - int error; /* called when the connection is initially made * callback(BIO,state,ret); The callback should return @@ -95,38 +98,18 @@ typedef struct bio_connect_st int (*info_callback)(); } BIO_CONNECT; -#ifndef NOPROTO static int conn_write(BIO *h,char *buf,int num); static int conn_read(BIO *h,char *buf,int size); static int conn_puts(BIO *h,char *str); static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int conn_new(BIO *h); static int conn_free(BIO *data); -#else -static int conn_write(); -static int conn_read(); -static int conn_puts(); -static long conn_ctrl(); -static int conn_new(); -static int conn_free(); -#endif - -#ifndef NOPROTO static int conn_state(BIO *b, BIO_CONNECT *c); static void conn_close_socket(BIO *data); BIO_CONNECT *BIO_CONNECT_new(void ); void BIO_CONNECT_free(BIO_CONNECT *a); -#else - -static int conn_state(); -static void conn_close_socket(); -BIO_CONNECT *BIO_CONNECT_new(); -void BIO_CONNECT_free(); - -#endif - static BIO_METHOD methods_connectp= { BIO_TYPE_CONNECT, @@ -140,9 +123,7 @@ static BIO_METHOD methods_connectp= conn_free, }; -static int conn_state(b,c) -BIO *b; -BIO_CONNECT *c; +static int conn_state(BIO *b, BIO_CONNECT *c) { int ret= -1,i; unsigned long l; @@ -160,7 +141,7 @@ BIO_CONNECT *c; p=c->param_hostname; if (p == NULL) { - BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED); + BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); goto exit_loop; } for ( ; *p != '\0'; p++) @@ -187,7 +168,7 @@ BIO_CONNECT *c; } } - if (p == NULL) + if (c->param_port == NULL) { BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); ERR_add_error_data(2,"host=",c->param_hostname); @@ -203,7 +184,12 @@ BIO_CONNECT *c; break; case BIO_CONN_S_GET_PORT: - if (BIO_get_port(c->param_port,&c->port) <= 0) + if (c->param_port == NULL) + { + abort(); + goto exit_loop; + } + else if (BIO_get_port(c->param_port,&c->port) <= 0) goto exit_loop; c->state=BIO_CONN_S_CREATE_SOCKET; break; @@ -235,12 +221,9 @@ BIO_CONNECT *c; break; case BIO_CONN_S_NBIO: -#ifdef FIONBIO if (c->nbio) { - l=1; - ret=BIO_socket_ioctl(b->num,FIONBIO,&l); - if (ret < 0) + if (!BIO_socket_nbio(b->num,1)) { BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); ERR_add_error_data(4,"host=", @@ -249,7 +232,6 @@ BIO_CONNECT *c; goto exit_loop; } } -#endif c->state=BIO_CONN_S_CONNECT; #ifdef SO_KEEPALIVE @@ -326,17 +308,15 @@ BIO_CONNECT *c; } } - if (1) - { + /* Loop does not exit */ exit_loop: - if (cb != NULL) - ret=cb((BIO *)b,c->state,ret); - } + if (cb != NULL) + ret=cb((BIO *)b,c->state,ret); end: return(ret); } -BIO_CONNECT *BIO_CONNECT_new() +BIO_CONNECT *BIO_CONNECT_new(void) { BIO_CONNECT *ret; @@ -353,13 +333,14 @@ BIO_CONNECT *BIO_CONNECT_new() ret->ip[3]=0; ret->port=0; memset((char *)&ret->them,0,sizeof(ret->them)); - ret->error=0; return(ret); } -void BIO_CONNECT_free(a) -BIO_CONNECT *a; +void BIO_CONNECT_free(BIO_CONNECT *a) { + if(a == NULL) + return; + if (a->param_hostname != NULL) Free(a->param_hostname); if (a->param_port != NULL) @@ -367,13 +348,12 @@ BIO_CONNECT *a; Free(a); } -BIO_METHOD *BIO_s_connect() +BIO_METHOD *BIO_s_connect(void) { return(&methods_connectp); } -static int conn_new(bi) -BIO *bi; +static int conn_new(BIO *bi) { bi->init=0; bi->num=INVALID_SOCKET; @@ -384,8 +364,7 @@ BIO *bi; return(1); } -static void conn_close_socket(bio) -BIO *bio; +static void conn_close_socket(BIO *bio) { BIO_CONNECT *c; @@ -395,17 +374,12 @@ BIO *bio; /* Only do a shutdown if things were established */ if (c->state == BIO_CONN_S_OK) shutdown(bio->num,2); -# ifdef WINDOWS closesocket(bio->num); -# else - close(bio->num); -# endif bio->num=INVALID_SOCKET; } } -static int conn_free(a) -BIO *a; +static int conn_free(BIO *a) { BIO_CONNECT *data; @@ -423,10 +397,7 @@ BIO *a; return(1); } -static int conn_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int conn_read(BIO *b, char *out, int outl) { int ret=0; BIO_CONNECT *data; @@ -442,11 +413,7 @@ int outl; if (out != NULL) { clear_socket_error(); -#if defined(WINDOWS) - ret=recv(b->num,out,outl,0); -#else - ret=read(b->num,out,outl); -#endif + ret=readsocket(b->num,out,outl); BIO_clear_retry_flags(b); if (ret <= 0) { @@ -457,10 +424,7 @@ int outl; return(ret); } -static int conn_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int conn_write(BIO *b, char *in, int inl) { int ret; BIO_CONNECT *data; @@ -473,11 +437,7 @@ int inl; } clear_socket_error(); -#if defined(WINDOWS) - ret=send(b->num,in,inl,0); -#else - ret=write(b->num,in,inl); -#endif + ret=writesocket(b->num,in,inl); BIO_clear_retry_flags(b); if (ret <= 0) { @@ -487,15 +447,11 @@ int inl; return(ret); } -static long conn_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; int *ip; - char **pptr; + const char **pptr; long ret=1; BIO_CONNECT *data; @@ -519,7 +475,7 @@ char *ptr; case BIO_C_GET_CONNECT: if (ptr != NULL) { - pptr=(char **)ptr; + pptr=(const char **)ptr; if (num == 0) { *pptr=data->param_hostname; @@ -559,9 +515,26 @@ char *ptr; data->param_port=BUF_strdup(ptr); } else if (num == 2) - memcpy(data->ip,ptr,4); + { + char buf[16]; + + sprintf(buf,"%d.%d.%d.%d", + ptr[0],ptr[1],ptr[2],ptr[3]); + if (data->param_hostname != NULL) + Free(data->param_hostname); + data->param_hostname=BUF_strdup(buf); + memcpy(&(data->ip[0]),ptr,4); + } else if (num == 3) + { + char buf[16]; + + sprintf(buf,"%d",*(int *)ptr); + if (data->param_port != NULL) + Free(data->param_port); + data->param_port=BUF_strdup(buf); data->port= *(int *)ptr; + } } break; case BIO_C_SET_NBIO: @@ -597,7 +570,7 @@ char *ptr; if (data->param_hostname) BIO_set_conn_hostname(dbio,data->param_hostname); BIO_set_nbio(dbio,data->nbio); - BIO_set_info_callback(dbio,data->info_callback); + (void)BIO_set_info_callback(dbio,data->info_callback); break; case BIO_CTRL_SET_CALLBACK: data->info_callback=(int (*)())ptr; @@ -617,9 +590,7 @@ char *ptr; return(ret); } -static int conn_puts(bp,str) -BIO *bp; -char *str; +static int conn_puts(BIO *bp, char *str) { int n,ret; @@ -628,8 +599,7 @@ char *str; return(ret); } -BIO *BIO_new_connect(str) -char *str; +BIO *BIO_new_connect(char *str) { BIO *ret; diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 1484cf849e..52c0c39df0 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c @@ -68,12 +68,11 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "err.h" +#include +#include #if !defined(NO_STDIO) -#ifndef NOPROTO static int MS_CALLBACK file_write(BIO *h,char *buf,int num); static int MS_CALLBACK file_read(BIO *h,char *buf,int size); static int MS_CALLBACK file_puts(BIO *h,char *str); @@ -81,16 +80,6 @@ static int MS_CALLBACK file_gets(BIO *h,char *str,int size); static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int MS_CALLBACK file_new(BIO *h); static int MS_CALLBACK file_free(BIO *data); -#else -static int MS_CALLBACK file_write(); -static int MS_CALLBACK file_read(); -static int MS_CALLBACK file_puts(); -static int MS_CALLBACK file_gets(); -static long MS_CALLBACK file_ctrl(); -static int MS_CALLBACK file_new(); -static int MS_CALLBACK file_free(); -#endif - static BIO_METHOD methods_filep= { BIO_TYPE_FILE, @@ -104,9 +93,7 @@ static BIO_METHOD methods_filep= file_free, }; -BIO *BIO_new_file(filename,mode) -char *filename; -char *mode; +BIO *BIO_new_file(const char *filename, const char *mode) { BIO *ret; FILE *file; @@ -125,9 +112,7 @@ char *mode; return(ret); } -BIO *BIO_new_fp(stream,close_flag) -FILE *stream; -int close_flag; +BIO *BIO_new_fp(FILE *stream, int close_flag) { BIO *ret; @@ -138,13 +123,12 @@ int close_flag; return(ret); } -BIO_METHOD *BIO_s_file() +BIO_METHOD *BIO_s_file(void) { return(&methods_filep); } -static int MS_CALLBACK file_new(bi) -BIO *bi; +static int MS_CALLBACK file_new(BIO *bi) { bi->init=0; bi->num=0; @@ -152,8 +136,7 @@ BIO *bi; return(1); } -static int MS_CALLBACK file_free(a) -BIO *a; +static int MS_CALLBACK file_free(BIO *a) { if (a == NULL) return(0); if (a->shutdown) @@ -168,10 +151,7 @@ BIO *a; return(1); } -static int MS_CALLBACK file_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int MS_CALLBACK file_read(BIO *b, char *out, int outl) { int ret=0; @@ -182,10 +162,7 @@ int outl; return(ret); } -static int MS_CALLBACK file_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int MS_CALLBACK file_write(BIO *b, char *in, int inl) { int ret=0; @@ -201,11 +178,7 @@ int inl; return(ret); } -static long MS_CALLBACK file_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; FILE *fp=(FILE *)b->ptr; @@ -214,18 +187,20 @@ char *ptr; switch (cmd) { + case BIO_C_FILE_SEEK: case BIO_CTRL_RESET: ret=(long)fseek(fp,num,0); break; case BIO_CTRL_EOF: ret=(long)feof(fp); break; + case BIO_C_FILE_TELL: case BIO_CTRL_INFO: ret=ftell(fp); break; case BIO_C_SET_FILE_PTR: file_free(b); - b->shutdown=(int)num; + b->shutdown=(int)num&BIO_CLOSE; b->ptr=(char *)ptr; b->init=1; #if defined(MSDOS) || defined(WINDOWS) @@ -307,10 +282,7 @@ char *ptr; return(ret); } -static int MS_CALLBACK file_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) { int ret=0; @@ -321,9 +293,7 @@ int size; return(ret); } -static int MS_CALLBACK file_puts(bp,str) -BIO *bp; -char *str; +static int MS_CALLBACK file_puts(BIO *bp, char *str) { int n,ret; diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c new file mode 100644 index 0000000000..db82e757e7 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_log.c @@ -0,0 +1,232 @@ +/* crypto/bio/bss_log.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + Why BIO_s_log? + + BIO_s_log is useful for system daemons (or services under NT). + It is one-way BIO, it sends all stuff to syslogd (or event log + under NT). + +*/ + + +#include +#include + +#ifndef WIN32 +#ifdef __ultrix +#include +#else +#include +#endif +#endif + +#include "cryptlib.h" +#include +#include +#ifndef NO_SYSLOG + + +static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); +static int MS_CALLBACK slg_puts(BIO *h,char *str); +static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); +static int MS_CALLBACK slg_new(BIO *h); +static int MS_CALLBACK slg_free(BIO *data); +static int xopenlog(BIO* bp, const char* name, int level); +static int xcloselog(BIO* bp); + +static BIO_METHOD methods_slg= + { + BIO_TYPE_MEM,"syslog", + slg_write, + NULL, + slg_puts, + NULL, + slg_ctrl, + slg_new, + slg_free, + }; + +BIO_METHOD *BIO_s_log(void) + { + return(&methods_slg); + } + +static int MS_CALLBACK slg_new(BIO *bi) + { + bi->init=1; + bi->num=0; + bi->ptr=NULL; +#ifndef WIN32 + xopenlog(bi, "application", LOG_DAEMON); +#else + xopenlog(bi, "application", 0); +#endif + return(1); + } + +static int MS_CALLBACK slg_free(BIO *a) + { + if (a == NULL) return(0); + xcloselog(a); + return(1); + } + +static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) + { + int ret= inl; + char* buf= in; + char* pp; +#if defined(WIN32) + LPTSTR lpszStrings[1]; + WORD evtype= EVENTLOG_ERROR_TYPE; +#else + int priority; +#endif + + if((buf= (char *)Malloc(inl+ 1)) == NULL){ + return(0); + } + strncpy(buf, in, inl); + buf[inl]= '\0'; +#if defined(WIN32) + if(strncmp(buf, "ERR ", 4) == 0){ + evtype= EVENTLOG_ERROR_TYPE; + pp= buf+ 4; + }else if(strncmp(buf, "WAR ", 4) == 0){ + evtype= EVENTLOG_WARNING_TYPE; + pp= buf+ 4; + }else if(strncmp(buf, "INF ", 4) == 0){ + evtype= EVENTLOG_INFORMATION_TYPE; + pp= buf+ 4; + }else{ + evtype= EVENTLOG_ERROR_TYPE; + pp= buf; + } + lpszStrings[0]= pp; + + if(b->ptr) + ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0, + lpszStrings, NULL); +#else + if(strncmp(buf, "ERR ", 4) == 0){ + priority= LOG_ERR; + pp= buf+ 4; + }else if(strncmp(buf, "WAR ", 4) == 0){ + priority= LOG_WARNING; + pp= buf+ 4; + }else if(strncmp(buf, "INF ", 4) == 0){ + priority= LOG_INFO; + pp= buf+ 4; + }else{ + priority= LOG_ERR; + pp= buf; + } + + syslog(priority, "%s", pp); +#endif + Free(buf); + return(ret); + } + +static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr) + { + switch (cmd) + { + case BIO_CTRL_SET: + xcloselog(b); + xopenlog(b, ptr, num); + break; + default: + break; + } + return(0); + } + +static int MS_CALLBACK slg_puts(BIO *bp, char *str) + { + int n,ret; + + n=strlen(str); + ret=slg_write(bp,str,n); + return(ret); + } + +static int xopenlog(BIO* bp, const char* name, int level) +{ +#if defined(WIN32) + if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){ + return(0); + } +#else + openlog(name, LOG_PID|LOG_CONS, level); +#endif + return(1); +} + +static int xcloselog(BIO* bp) +{ +#if defined(WIN32) + if(bp->ptr) + DeregisterEventSource((HANDLE)(bp->ptr)); + bp->ptr= NULL; +#else + closelog(); +#endif + return(1); +} + +#endif diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index 40c4e39f02..7e749a503e 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c @@ -59,9 +59,8 @@ #include #include #include "cryptlib.h" -#include "bio.h" +#include -#ifndef NOPROTO static int mem_write(BIO *h,char *buf,int num); static int mem_read(BIO *h,char *buf,int size); static int mem_puts(BIO *h,char *str); @@ -69,16 +68,6 @@ static int mem_gets(BIO *h,char *str,int size); static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int mem_new(BIO *h); static int mem_free(BIO *data); -#else -static int mem_write(); -static int mem_read(); -static int mem_puts(); -static int mem_gets(); -static long mem_ctrl(); -static int mem_new(); -static int mem_free(); -#endif - static BIO_METHOD mem_method= { BIO_TYPE_MEM, @@ -92,13 +81,15 @@ static BIO_METHOD mem_method= mem_free, }; -BIO_METHOD *BIO_s_mem() +/* bio->num is used to hold the value to return on 'empty', if it is + * 0, should_retry is not set */ + +BIO_METHOD *BIO_s_mem(void) { return(&mem_method); } -static int mem_new(bi) -BIO *bi; +static int mem_new(BIO *bi) { BUF_MEM *b; @@ -106,13 +97,12 @@ BIO *bi; return(0); bi->shutdown=1; bi->init=1; - bi->num=0; + bi->num= -1; bi->ptr=(char *)b; return(1); } -static int mem_free(a) -BIO *a; +static int mem_free(BIO *a) { if (a == NULL) return(0); if (a->shutdown) @@ -126,10 +116,7 @@ BIO *a; return(1); } -static int mem_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int mem_read(BIO *b, char *out, int outl) { int ret= -1; BUF_MEM *bm; @@ -151,16 +138,14 @@ int outl; } else if (bm->length == 0) { - BIO_set_retry_read(b); - ret= -1; + if (b->num != 0) + BIO_set_retry_read(b); + ret= b->num; } return(ret); } -static int mem_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int mem_write(BIO *b, char *in, int inl) { int ret= -1; int blen; @@ -183,11 +168,7 @@ end: return(ret); } -static long mem_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long mem_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; char **pptr; @@ -204,6 +185,9 @@ char *ptr; case BIO_CTRL_EOF: ret=(long)(bm->length == 0); break; + case BIO_C_SET_BUF_MEM_EOF_RETURN: + b->num=(int)num; + break; case BIO_CTRL_INFO: ret=(long)bm->length; if (ptr != NULL) @@ -250,10 +234,7 @@ char *ptr; return(ret); } -static int mem_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int mem_gets(BIO *bp, char *buf, int size) { int i,j; int ret= -1; @@ -283,9 +264,7 @@ int size; return(ret); } -static int mem_puts(bp,str) -BIO *bp; -char *str; +static int mem_puts(BIO *bp, char *str) { int n,ret; diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c index 0791a2471a..d04be888e5 100644 --- a/src/lib/libcrypto/bio/bss_null.c +++ b/src/lib/libcrypto/bio/bss_null.c @@ -59,9 +59,8 @@ #include #include #include "cryptlib.h" -#include "bio.h" +#include -#ifndef NOPROTO static int null_write(BIO *h,char *buf,int num); static int null_read(BIO *h,char *buf,int size); static int null_puts(BIO *h,char *str); @@ -69,16 +68,6 @@ static int null_gets(BIO *h,char *str,int size); static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int null_new(BIO *h); static int null_free(BIO *data); -#else -static int null_write(); -static int null_read(); -static int null_puts(); -static int null_gets(); -static long null_ctrl(); -static int null_new(); -static int null_free(); -#endif - static BIO_METHOD null_method= { BIO_TYPE_NULL, @@ -92,13 +81,12 @@ static BIO_METHOD null_method= null_free, }; -BIO_METHOD *BIO_s_null() +BIO_METHOD *BIO_s_null(void) { return(&null_method); } -static int null_new(bi) -BIO *bi; +static int null_new(BIO *bi) { bi->init=1; bi->num=0; @@ -106,34 +94,23 @@ BIO *bi; return(1); } -static int null_free(a) -BIO *a; +static int null_free(BIO *a) { if (a == NULL) return(0); return(1); } -static int null_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int null_read(BIO *b, char *out, int outl) { return(0); } -static int null_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int null_write(BIO *b, char *in, int inl) { return(inl); } -static long null_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long null_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; @@ -159,17 +136,12 @@ char *ptr; return(ret); } -static int null_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int null_gets(BIO *bp, char *buf, int size) { return(0); } -static int null_puts(bp,str) -BIO *bp; -char *str; +static int null_puts(BIO *bp, char *str) { if (str == NULL) return(0); return(strlen(str)); diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c index 6eb434dee8..2ef040057e 100644 --- a/src/lib/libcrypto/bio/bss_rtcp.c +++ b/src/lib/libcrypto/bio/bss_rtcp.c @@ -58,6 +58,7 @@ /* Written by David L. Jones * Date: 22-JUL-1996 + * Revised: 25-SEP-1997 Update for 0.8.1, BIO_CTRL_SET -> BIO_C_SET_FD */ /* VMS */ #include @@ -65,10 +66,11 @@ #include #include #include "cryptlib.h" -#include "bio.h" +#include #include /* VMS IO$_ definitions */ -extern int SYS$QIOW(); +#include + typedef unsigned short io_channel; /*************************************************************************/ struct io_status { short status, count; long flags; }; @@ -107,18 +109,24 @@ static BIO_METHOD rtcp_method= rtcp_free, }; -BIO_METHOD *BIO_s_rtcp() +BIO_METHOD *BIO_s_rtcp(void) { return(&rtcp_method); } /*****************************************************************************/ /* Decnet I/O routines. */ + +#ifdef __DECC +#pragma message save +#pragma message disable DOLLARID +#endif + static int get ( io_channel chan, char *buffer, int maxlen, int *length ) { int status; struct io_status iosb; - status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0, + status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen, 0, 0, 0, 0 ); if ( (status&1) == 1 ) status = iosb.status; if ( (status&1) == 1 ) *length = iosb.count; @@ -129,15 +137,19 @@ static int put ( io_channel chan, char *buffer, int length ) { int status; struct io_status iosb; - status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, + status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer, length, 0, 0, 0, 0 ); if ( (status&1) == 1 ) status = iosb.status; return status; } + +#ifdef __DECC +#pragma message restore +#endif + /***************************************************************************/ -static int rtcp_new(bi) -BIO *bi; +static int rtcp_new(BIO *bi) { struct rpc_ctx *ctx; bi->init=1; @@ -150,8 +162,7 @@ BIO *bi; return(1); } -static int rtcp_free(a) -BIO *a; +static int rtcp_free(BIO *a) { if (a == NULL) return(0); if ( a->ptr ) Free ( a->ptr ); @@ -159,10 +170,7 @@ BIO *a; return(1); } -static int rtcp_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int rtcp_read(BIO *b, char *out, int outl) { int status, length; struct rpc_ctx *ctx; @@ -209,10 +217,7 @@ int outl; return length; } -static int rtcp_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int rtcp_write(BIO *b, char *in, int inl) { int status, i, segment, length; struct rpc_ctx *ctx; @@ -241,11 +246,7 @@ int inl; return(i); } -static long rtcp_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long rtcp_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; @@ -255,7 +256,7 @@ char *ptr; case BIO_CTRL_EOF: ret = 1; break; - case BIO_CTRL_SET: + case BIO_C_SET_FD: b->num = num; ret = 1; break; @@ -276,17 +277,12 @@ char *ptr; return(ret); } -static int rtcp_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int rtcp_gets(BIO *bp, char *buf, int size) { return(0); } -static int rtcp_puts(bp,str) -BIO *bp; -char *str; +static int rtcp_puts(BIO *bp, char *str) { int length; if (str == NULL) return(0); diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index d907a2867b..d336b99fe8 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c @@ -62,10 +62,9 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" +#include #ifndef BIO_FD -#ifndef NOPROTO static int sock_write(BIO *h,char *buf,int num); static int sock_read(BIO *h,char *buf,int size); static int sock_puts(BIO *h,char *str); @@ -73,19 +72,8 @@ static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int sock_new(BIO *h); static int sock_free(BIO *data); int BIO_sock_should_retry(int s); -#else -static int sock_write(); -static int sock_read(); -static int sock_puts(); -static long sock_ctrl(); -static int sock_new(); -static int sock_free(); -int BIO_sock_should_retry(); -#endif - #else -#ifndef NOPROTO static int fd_write(BIO *h,char *buf,int num); static int fd_read(BIO *h,char *buf,int size); static int fd_puts(BIO *h,char *str); @@ -93,15 +81,6 @@ static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int fd_new(BIO *h); static int fd_free(BIO *data); int BIO_fd_should_retry(int s); -#else -static int fd_write(); -static int fd_read(); -static int fd_puts(); -static long fd_ctrl(); -static int fd_new(); -static int fd_free(); -int BIO_fd_should_retry(); -#endif #endif #ifndef BIO_FD @@ -118,7 +97,7 @@ static BIO_METHOD methods_sockp= sock_free, }; -BIO_METHOD *BIO_s_socket() +BIO_METHOD *BIO_s_socket(void) { return(&methods_sockp); } @@ -135,19 +114,17 @@ static BIO_METHOD methods_fdp= fd_free, }; -BIO_METHOD *BIO_s_fd() +BIO_METHOD *BIO_s_fd(void) { return(&methods_fdp); } #endif #ifndef BIO_FD -BIO *BIO_new_socket(fd,close_flag) +BIO *BIO_new_socket(int fd, int close_flag) #else -BIO *BIO_new_fd(fd,close_flag) +BIO *BIO_new_fd(int fd,int close_flag) #endif -int fd; -int close_flag; { BIO *ret; @@ -162,11 +139,10 @@ int close_flag; } #ifndef BIO_FD -static int sock_new(bi) +static int sock_new(BIO *bi) #else -static int fd_new(bi) +static int fd_new(BIO *bi) #endif -BIO *bi; { bi->init=0; bi->num=0; @@ -176,11 +152,10 @@ BIO *bi; } #ifndef BIO_FD -static int sock_free(a) +static int sock_free(BIO *a) #else -static int fd_free(a) +static int fd_free(BIO *a) #endif -BIO *a; { if (a == NULL) return(0); if (a->shutdown) @@ -189,11 +164,7 @@ BIO *a; { #ifndef BIO_FD shutdown(a->num,2); -# ifdef WINDOWS closesocket(a->num); -# else - close(a->num); -# endif #else /* BIO_FD */ close(a->num); #endif @@ -206,21 +177,18 @@ BIO *a; } #ifndef BIO_FD -static int sock_read(b,out,outl) +static int sock_read(BIO *b, char *out, int outl) #else -static int fd_read(b,out,outl) +static int fd_read(BIO *b, char *out,int outl) #endif -BIO *b; -char *out; -int outl; { int ret=0; if (out != NULL) { -#if defined(WINDOWS) && !defined(BIO_FD) +#ifndef BIO_FD clear_socket_error(); - ret=recv(b->num,out,outl,0); + ret=readsocket(b->num,out,outl); #else clear_sys_error(); ret=read(b->num,out,outl); @@ -240,19 +208,16 @@ int outl; } #ifndef BIO_FD -static int sock_write(b,in,inl) +static int sock_write(BIO *b, char *in, int inl) #else -static int fd_write(b,in,inl) +static int fd_write(BIO *b, char *in, int inl) #endif -BIO *b; -char *in; -int inl; { int ret; -#if defined(WINDOWS) && !defined(BIO_FD) +#ifndef BIO_FD clear_socket_error(); - ret=send(b->num,in,inl,0); + ret=writesocket(b->num,in,inl); #else clear_sys_error(); ret=write(b->num,in,inl); @@ -271,14 +236,10 @@ int inl; } #ifndef BIO_FD -static long sock_ctrl(b,cmd,num,ptr) +static long sock_ctrl(BIO *b, int cmd, long num, char *ptr) #else -static long fd_ctrl(b,cmd,num,ptr) +static long fd_ctrl(BIO *b, int cmd, long num, char *ptr) #endif -BIO *b; -int cmd; -long num; -char *ptr; { long ret=1; int *ip; @@ -286,14 +247,21 @@ char *ptr; switch (cmd) { case BIO_CTRL_RESET: + num=0; + case BIO_C_FILE_SEEK: #ifdef BIO_FD - ret=(long)lseek(b->num,0,0); + ret=(long)lseek(b->num,num,0); #else ret=0; #endif break; + case BIO_C_FILE_TELL: case BIO_CTRL_INFO: +#ifdef BIO_FD + ret=(long)lseek(b->num,0,1); +#else ret=0; +#endif break; case BIO_C_SET_FD: #ifndef BIO_FD @@ -329,7 +297,6 @@ char *ptr; case BIO_CTRL_FLUSH: ret=1; break; - break; default: ret=0; break; @@ -338,22 +305,17 @@ char *ptr; } #ifdef undef -static int sock_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int sock_gets(BIO *bp, char *buf,int size) { return(-1); } #endif #ifndef BIO_FD -static int sock_puts(bp,str) +static int sock_puts(BIO *bp, char *str) #else -static int fd_puts(bp,str) +static int fd_puts(BIO *bp, char *str) #endif -BIO *bp; -char *str; { int n,ret; @@ -367,23 +329,22 @@ char *str; } #ifndef BIO_FD -int BIO_sock_should_retry(i) +int BIO_sock_should_retry(int i) #else -int BIO_fd_should_retry(i) +int BIO_fd_should_retry(int i) #endif -int i; { int err; if ((i == 0) || (i == -1)) { -#if !defined(BIO_FD) && defined(WINDOWS) +#ifndef BIO_FD err=get_last_socket_error(); #else err=get_last_sys_error(); #endif -#if defined(WINDOWS) /* more microsoft stupidity */ +#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ if ((i == -1) && (err == 0)) return(1); #endif @@ -398,11 +359,10 @@ int i; } #ifndef BIO_FD -int BIO_sock_non_fatal_error(err) +int BIO_sock_non_fatal_error(int err) #else -int BIO_fd_non_fatal_error(err) +int BIO_fd_non_fatal_error(int err) #endif -int err; { switch (err) { @@ -411,8 +371,10 @@ int err; case WSAEWOULDBLOCK: # endif -# if defined(WSAENOTCONN) +# if 0 /* This appears to always be an error */ +# if defined(WSAENOTCONN) case WSAENOTCONN: +# endif # endif #endif @@ -452,7 +414,7 @@ int err; case EALREADY: #endif return(1); - break; + /* break; */ default: break; } -- cgit v1.2.3-55-g6feb