]> git.sur5r.net Git - openldap/blob - servers/slapd/starttls.c
Start TLS extended op routine.
[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         char ** text )
30 {
31         /* can't start TLS if it is already started */
32         if (conn->c_is_tls != 0)
33                 return(LDAP_OPERATIONS_ERROR);
34
35         /* can't start TLS if there are other op's around */
36         if (conn->c_ops != NULL) {
37                 if (conn->c_ops != op || op->o_next != NULL)
38                         return(LDAP_OPERATIONS_ERROR);
39         }
40         if (conn->c_pending_ops != NULL) {
41                 if (conn->c_pending_ops != op || op->o_next != NULL)
42                         return(LDAP_OPERATIONS_ERROR);
43         }
44
45         /* here's some pseudo-code if HAVE_TLS is defined
46          * but for some reason TLS is not available.
47          */
48         /*
49                 if (tls not really supported) {
50                         if (referral exists) {
51                                 // caller will need to put the referral into the result
52                                 return(LDAP_REFERRAL);
53                         }
54                         return(LDAP_UNAVAILABLE);
55                 }
56         */
57
58     conn->c_is_tls = 1;
59     conn->c_needs_tls_accept = 1;
60     return(LDAP_SUCCESS);
61 }
62
63 #endif  /* HAVE_TLS */