Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/lib/ssl_compat/ssl_compat.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2023 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#include <config.h>
20
21
#if defined(HAVE_OPENSSL) && !defined(HAVE_SSL_READ_EX)
22
23
# include <sys/types.h>
24
# if defined(HAVE_WOLFSSL)
25
# include <wolfssl/options.h>
26
# endif
27
# include <openssl/ssl.h>
28
29
# include <sudo_compat.h>
30
# include <sudo_ssl_compat.h>
31
32
/*
33
* Emulate SSL_read_ex() using SSL_read().
34
*/
35
int
36
SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes)
37
{
38
int nr = SSL_read(ssl, buf, (int)num);
39
if (nr < 0)
40
nr = 0;
41
*readbytes = (size_t)nr;
42
return nr > 0;
43
}
44
45
/*
46
* Emulate SSL_write_ex() using SSL_write().
47
*/
48
int
49
SSL_write_ex(SSL *ssl, const void *buf, size_t num, size_t *written)
50
{
51
int nw = SSL_write(ssl, buf, (int)num);
52
if (nw < 0)
53
nw = 0;
54
*written = (size_t)nw;
55
return nw > 0;
56
}
57
#endif /* HAVE_OPENSSL && !HAVE_SSL_READ_EX */
58
59