24RCSID(
"$Id: 7f03983b541acd48e9ebe89ecc7e0c5e95c4ae4c $")
28#include <freeradius-devel/ldap/base.h>
29#include <freeradius-devel/util/debug.h>
51 UNUSED int fd_errno,
void *uctx)
110#if LDAP_VENDOR_VERSION >= 20609
111static void _ldap_start_tls_io_handshake(
fr_event_list_t *
el,
int fd,
int flags,
void *uctx);
129 bool need_read, need_write;
131 ret = ldap_install_tls(c->
handle);
138 case LDAP_X_CONNECTING:
139 if ((ldap_get_option(c->
handle, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS) ||
140 (ldap_get_option(c->
handle, LDAP_OPT_DESC, &fd) != LDAP_OPT_SUCCESS) || (fd < 0)) {
141 ERROR(
"Failed getting the socket to continue the TLS handshake");
145 need_read = ber_sockbuf_ctrl(sb, LBER_SB_OPT_NEEDS_READ, NULL);
146 need_write = ber_sockbuf_ctrl(sb, LBER_SB_OPT_NEEDS_WRITE, NULL);
148 "TLS handshake waiting on neither read nor write"))
goto error;
151 need_read ? _ldap_start_tls_io_handshake : NULL,
152 need_write ? _ldap_start_tls_io_handshake : NULL,
155 PERROR(
"Failed inserting TLS handshake I/O handler");
161 ERROR(
"ldap_install_tls failed: %s", ldap_err2string(ret));
199 if (ldap_get_option(c->
handle, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS) {
200 ERROR(
"Failed getting the socket for the TLS handshake");
206 ber_sockbuf_ctrl(sb, LBER_SB_OPT_SET_NONBLOCK, (
void *)0);
207 ret = ldap_install_tls(c->
handle);
208 ber_sockbuf_ctrl(sb, LBER_SB_OPT_SET_NONBLOCK, (
void *)1);
210 if (ret != LDAP_SUCCESS) {
211 ERROR(
"ldap_install_tls failed: %s", ldap_err2string(ret));
248 PERROR(
"StartTLS failed");
280 ret = ldap_start_tls(c->
handle, our_serverctrls, our_clientctrls, &tls_ctx->
msgid);
288 case LDAP_X_CONNECTING:
289 ret = ldap_get_option(c->
handle, LDAP_OPT_DESC, &fd);
307 ret = ldap_get_option(c->
handle, LDAP_OPT_DESC, &fd);
308 if ((ret != LDAP_OPT_SUCCESS) || (fd < 0))
goto error;
317 PERROR(
"Failed setting LDAP connection non-blocking");
330 ERROR(
"ldap_start_tls failed: %s", ldap_err2string(ret));
351 DEBUG2(
"Starting TLS negotiation");
364 if ((ldap_get_option(c->
handle, LDAP_OPT_DESC, &fd) == LDAP_SUCCESS) && (fd >= 0)) {
#define USES_APPLE_DEPRECATED_API
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define fr_cond_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define fr_event_fd_insert(...)
LDAP * handle
libldap handle.
void fr_ldap_control_merge(LDAPControl *serverctrls_out[], LDAPControl *clientctrls_out[], size_t serverctrls_len, size_t clientctrls_len, fr_ldap_connection_t *conn, LDAPControl *serverctrls_in[], LDAPControl *clientctrls_in[])
Merge connection and call specific client and server controls.
int fd
File descriptor for this connection.
void fr_ldap_state_error(fr_ldap_connection_t *c)
Signal that there's been an error on the connection.
fr_ldap_state_t fr_ldap_state_next(fr_ldap_connection_t *c)
Move between LDAP connection states.
#define LDAP_MAX_CONTROLS
Maximum number of client/server controls.
fr_ldap_rcode_t
Codes returned by fr_ldap internal functions.
@ LDAP_PROC_SUCCESS
Operation was successful.
@ LDAP_PROC_PENDING
fr_ldap_result() was polling and hasn't read the final message yet.
connection_t * conn
Connection state handle.
Tracks the state of a libldap connection handle.
fr_ldap_rcode_t fr_ldap_result(LDAPMessage **result, LDAPControl ***ctrls, fr_ldap_connection_t const *conn, int msgid, int all, char const *dn, fr_time_delta_t timeout)
Parse response from LDAP server dealing with any errors.
Stores all information relating to an event list.
int fr_nonblock(UNUSED int fd)
static void _ldap_start_tls_io_error(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, UNUSED int fd_errno, void *uctx)
Error reading from or writing to the file descriptor.
static void ldap_start_tls_handshake(UNUSED fr_event_list_t *el, fr_ldap_start_tls_ctx_t *tls_ctx)
Run the TLS handshake to completion.
fr_ldap_connection_t * c
The current connection.
static void _ldap_start_tls_io_write(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
Send an extended operation to the LDAP server, requesting a transition to TLS.
int fr_ldap_start_tls_async(fr_ldap_connection_t *c, LDAPControl **serverctrls, LDAPControl **clientctrls)
Install I/O handlers for Start TLS negotiation.
LDAPControl ** serverctrls
Controls to pass to the server.
LDAPControl ** clientctrls
Controls to pass to the client (library).
static void _ldap_start_tls_io_read(fr_event_list_t *el, UNUSED int fd, UNUSED int flags, void *uctx)
Event handler for the response to the StartTLS extended operation.
Holds arguments for the start_tls operation.
#define fr_time_delta_wrap(_time)
static fr_event_list_t * el