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 /* can't start TLS if there are other op's around */
53 if (( conn->c_ops != NULL &&
54 (conn->c_ops != op || op->o_next != NULL)) ||
55 ( conn->c_pending_ops != NULL))
57 *text = "cannot start TLS when operations our outstanding";
58 rc = LDAP_OPERATIONS_ERROR;
62 if ( ( global_disallows & SLAP_DISALLOW_TLS_AUTHC ) &&
63 ( conn->c_dn != NULL ) )
65 *text = "cannot start TLS after authentication";
66 rc = LDAP_OPERATIONS_ERROR;
70 if ( ( global_allows & SLAP_ALLOW_TLS_2_ANON ) &&
71 ( conn->c_dn != NULL ) )
73 /* force to anonymous */
74 connection2anonymous( conn );
77 /* fail if TLS could not be initialized */
78 if (ldap_pvt_tls_get_option(NULL, LDAP_OPT_X_TLS_CERT, &ctx) != 0
81 if (default_referral != NULL) {
82 /* caller will put the referral in the result */
87 *text = "Could not initialize TLS";
88 rc = LDAP_UNAVAILABLE;
93 conn->c_needs_tls_accept = 1;
98 /* give up connection lock */
99 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
102 * RACE CONDITION: we give up lock before sending result
103 * Should be resolved by reworking connection state, not
104 * by moving send here (so as to ensure proper TLS sequencing)
110 #endif /* HAVE_TLS */