]> git.sur5r.net Git - openldap/blob - servers/slapd/starttls.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / starttls.c
1 /* $OpenLDAP$ */
2 /* 
3  * Copyright 1999 The OpenLDAP Foundation.
4  * All rights reserved.
5  *
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.
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15 #include <ac/socket.h>
16
17 #include "slap.h"
18
19 #ifdef HAVE_TLS
20
21 int
22 starttls_extop (
23         SLAP_EXTOP_CALLBACK_FN cb,
24         Connection *conn,
25         Operation *op,
26         char * reqoid,
27         struct berval * reqdata,
28         char ** rspoid,
29         struct berval ** rspdata,
30         LDAPControl ***rspctrls,
31         char ** text,
32         struct berval *** refs )
33 {
34         void *ctx;
35
36         if ( reqdata != NULL ) {
37                 /* no request data should be provided */
38                 return LDAP_PROTOCOL_ERROR;
39         }
40
41         /* can't start TLS if it is already started */
42         if (conn->c_is_tls != 0)
43                 return(LDAP_OPERATIONS_ERROR);
44
45         /* fail if TLS could not be initialized */
46         if (ldap_pvt_tls_get_option(NULL, LDAP_OPT_X_TLS_CERT, &ctx) != 0
47                 || ctx == NULL)
48         {
49                 if (default_referral != NULL) {
50                         /* caller will put the referral into the result */
51                         return(LDAP_REFERRAL);
52                 }
53                 return(LDAP_UNAVAILABLE);
54         }
55
56         /* can't start TLS if there are other op's around */
57         if (conn->c_ops != NULL) {
58                 if (conn->c_ops != op || op->o_next != NULL)
59                         return(LDAP_OPERATIONS_ERROR);
60         }
61         if (conn->c_pending_ops != NULL) {
62                 if (conn->c_pending_ops != op || op->o_next != NULL)
63                         return(LDAP_OPERATIONS_ERROR);
64         }
65
66     conn->c_is_tls = 1;
67     conn->c_needs_tls_accept = 1;
68
69     return(LDAP_SUCCESS);
70 }
71
72 #endif  /* HAVE_TLS */