]> git.sur5r.net Git - openldap/blob - servers/slapd/starttls.c
Start TLS extension: check that TLS was inited successfully, return default referral...
[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 * oid,
27         struct berval * reqdata,
28         struct berval ** rspdata,
29         LDAPControl ***rspctrls,
30         char ** text )
31 {
32         void *ctx;
33
34         if ( reqdata != NULL ) {
35                 /* no request data should be provided */
36                 return LDAP_PROTOCOL_ERROR;
37         }
38
39         /* can't start TLS if it is already started */
40         if (conn->c_is_tls != 0)
41                 return(LDAP_OPERATIONS_ERROR);
42
43         /* fail if TLS could not be initialized */
44         if (ldap_pvt_tls_get_option(NULL, LDAP_OPT_X_TLS_CERT, &ctx) != 0
45                 || ctx == NULL)
46         {
47                 if (default_referral != NULL) {
48                         /* caller will put the referral into the result */
49                         return(LDAP_REFERRAL);
50                 }
51                 return(LDAP_UNAVAILABLE);
52         }
53
54         /* can't start TLS if there are other op's around */
55         if (conn->c_ops != NULL) {
56                 if (conn->c_ops != op || op->o_next != NULL)
57                         return(LDAP_OPERATIONS_ERROR);
58         }
59         if (conn->c_pending_ops != NULL) {
60                 if (conn->c_pending_ops != op || op->o_next != NULL)
61                         return(LDAP_OPERATIONS_ERROR);
62         }
63
64     conn->c_is_tls = 1;
65     conn->c_needs_tls_accept = 1;
66
67     return(LDAP_SUCCESS);
68 }
69
70 #endif  /* HAVE_TLS */