r23893: add dummy callbacks for LDAP SASL wrapping,
[obnox/samba/samba-obnox.git] / source / libads / sasl_wrapping.c
1 /* 
2    Unix SMB/CIFS implementation.
3    ads sasl wrapping code
4    Copyright (C) Stefan Metzmacher 2007
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21
22 #ifdef HAVE_ADS_SASL_WRAPPING
23
24 static int ads_saslwrap_setup(Sockbuf_IO_Desc *sbiod, void *arg)
25 {
26         ADS_STRUCT *ads = (ADS_STRUCT *)arg;
27
28         ads->ldap.sbiod = sbiod;
29
30         sbiod->sbiod_pvt = ads;
31
32         return 0;
33 }
34
35 static int ads_saslwrap_remove(Sockbuf_IO_Desc *sbiod)
36 {
37         return 0;
38 }
39
40 static ber_slen_t ads_saslwrap_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
41 {
42         return LBER_SBIOD_READ_NEXT(sbiod, buf, len);
43 }
44
45 static ber_slen_t ads_saslwrap_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
46 {
47         return LBER_SBIOD_WRITE_NEXT(sbiod, buf, len);
48 }
49
50
51 static int ads_saslwrap_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)
52 {
53         return LBER_SBIOD_CTRL_NEXT(sbiod, opt, arg);
54 }
55
56 static int ads_saslwrap_close(Sockbuf_IO_Desc *sbiod)
57 {
58         return 0;
59 }
60
61 static const Sockbuf_IO ads_saslwrap_sockbuf_io = {
62         ads_saslwrap_setup,     /* sbi_setup */
63         ads_saslwrap_remove,    /* sbi_remove */
64         ads_saslwrap_ctrl,      /* sbi_ctrl */
65         ads_saslwrap_read,      /* sbi_read */
66         ads_saslwrap_write,     /* sbi_write */
67         ads_saslwrap_close      /* sbi_close */
68 };
69
70 ADS_STATUS ads_setup_sasl_wrapping(ADS_STRUCT *ads)
71 {
72         ADS_STATUS status;
73         Sockbuf *sb;
74         Sockbuf_IO *io = discard_const_p(Sockbuf_IO, &ads_saslwrap_sockbuf_io);
75         int rc;
76
77         rc = ldap_get_option(ads->ldap.ld, LDAP_OPT_SOCKBUF, &sb);
78         status = ADS_ERROR_LDAP(rc);
79         if (!ADS_ERR_OK(status)) {
80                 return status;
81         }
82
83         /* debugging for the layer above SASL */
84         rc = ber_sockbuf_add_io(sb, io, LBER_SBIOD_LEVEL_TRANSPORT,
85                                 (void *)"ads_sasl_wrapping_above" );
86         status = ADS_ERROR_LDAP(rc);
87         if (!ADS_ERR_OK(status)) {
88                 return status;
89         }
90
91         /* setup the real wrapping callbacks */
92         rc = ber_sockbuf_add_io(sb, io, LBER_SBIOD_LEVEL_TRANSPORT, ads);
93         status = ADS_ERROR_LDAP(rc);
94         if (!ADS_ERR_OK(status)) {
95                 return status;
96         }
97
98         /* debugging for the layer below SASL */
99         rc = ber_sockbuf_add_io(sb, io, LBER_SBIOD_LEVEL_TRANSPORT,
100                                 (void *)"ads_sasl_wrapping_below" );
101         status = ADS_ERROR_LDAP(rc);
102         if (!ADS_ERR_OK(status)) {
103                 return status;
104         }
105
106         return ADS_SUCCESS;
107 }
108
109 #endif /* HAVE_ADS_SASL_WRAPPING */