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>
26 struct berval * reqdata,
28 struct berval ** rspdata,
29 LDAPControl ***rspctrls,
31 struct berval *** refs )
36 if ( reqdata != NULL ) {
37 /* no request data should be provided */
38 *text = "no request data expected";
39 return LDAP_PROTOCOL_ERROR;
42 /* acquire connection lock */
43 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
45 /* can't start TLS if it is already started */
46 if (conn->c_is_tls != 0) {
47 *text = "TLS already started";
48 rc = LDAP_OPERATIONS_ERROR;
52 /* fail if TLS could not be initialized */
53 if (ldap_pvt_tls_get_option(NULL, LDAP_OPT_X_TLS_CERT, &ctx) != 0
56 if (default_referral != NULL) {
57 /* caller will put the referral in the result */
62 *text = "Could not initialize TLS";
63 rc = LDAP_UNAVAILABLE;
67 /* can't start TLS if there are other op's around */
68 if (( conn->c_ops != NULL &&
69 (conn->c_ops != op || op->o_next != NULL)) ||
70 ( conn->c_pending_ops != NULL))
72 *text = "cannot start TLS when operations our outstanding";
73 rc = LDAP_OPERATIONS_ERROR;
78 conn->c_needs_tls_accept = 1;
83 /* give up connection lock */
84 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
87 * RACE CONDITION: we give up lock before sending result
88 * Should be resolved by reworking connection state, not
89 * by moving send here (so as to ensure proper TLS sequencing)