3 * Copyright 1999-2000 The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
15 #include <ac/socket.h>
23 SLAP_EXTOP_CALLBACK_FN cb,
27 struct berval * reqdata,
29 struct berval ** rspdata,
30 LDAPControl ***rspctrls,
32 struct berval *** refs )
37 if ( reqdata != NULL ) {
38 /* no request data should be provided */
39 *text = "no request data expected";
40 return LDAP_PROTOCOL_ERROR;
43 /* acquire connection lock */
44 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
46 /* can't start TLS if it is already started */
47 if (conn->c_is_tls != 0) {
48 *text = "TLS already started";
49 rc = LDAP_OPERATIONS_ERROR;
53 /* fail if TLS could not be initialized */
54 if (ldap_pvt_tls_get_option(NULL, LDAP_OPT_X_TLS_CERT, &ctx) != 0
57 if (default_referral != NULL) {
58 /* caller will put the referral in the result */
63 *text = "Could not initialize TLS";
64 rc = LDAP_UNAVAILABLE;
68 /* can't start TLS if there are other op's around */
69 if (( conn->c_ops != NULL &&
70 (conn->c_ops != op || op->o_next != NULL)) ||
71 ( conn->c_pending_ops != NULL))
73 *text = "cannot start TLS when operations our outstanding";
74 rc = LDAP_OPERATIONS_ERROR;
79 conn->c_needs_tls_accept = 1;
84 /* give up connection lock */
85 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
88 * RACE CONDITION: we give up lock before sending result
89 * Should be resolved by reworking connection state, not
90 * by moving send here (so as to ensure proper TLS sequencing)