/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2023 Todd C. Miller <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*/1718#include <config.h>1920#if defined(HAVE_OPENSSL) && !defined(HAVE_SSL_READ_EX)2122# include <sys/types.h>23# if defined(HAVE_WOLFSSL)24# include <wolfssl/options.h>25# endif26# include <openssl/ssl.h>2728# include <sudo_compat.h>29# include <sudo_ssl_compat.h>3031/*32* Emulate SSL_read_ex() using SSL_read().33*/34int35SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes)36{37int nr = SSL_read(ssl, buf, (int)num);38if (nr < 0)39nr = 0;40*readbytes = (size_t)nr;41return nr > 0;42}4344/*45* Emulate SSL_write_ex() using SSL_write().46*/47int48SSL_write_ex(SSL *ssl, const void *buf, size_t num, size_t *written)49{50int nw = SSL_write(ssl, buf, (int)num);51if (nw < 0)52nw = 0;53*written = (size_t)nw;54return nw > 0;55}56#endif /* HAVE_OPENSSL && !HAVE_SSL_READ_EX */575859