summaryrefslogtreecommitdiff
path: root/source3/libads/sasl_wrapping.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-07-17 11:14:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:28:45 -0500
commit307e51ed1420fcf9e91e8ac7c0a1689e13f3edec (patch)
treec9f50b863659db83481d30fe566fb04a1ecdee2a /source3/libads/sasl_wrapping.c
parent4e23e4bd18658a9c40802ce654b6f1d1a921b47d (diff)
downloadsamba-307e51ed1420fcf9e91e8ac7c0a1689e13f3edec.tar.gz
samba-307e51ed1420fcf9e91e8ac7c0a1689e13f3edec.tar.bz2
samba-307e51ed1420fcf9e91e8ac7c0a1689e13f3edec.zip
r23926: implement output buffer handling for the SASL write wrapper
metze (This used to be commit 65ce6fa21adec704b3cde30c57001e5620f048e4)
Diffstat (limited to 'source3/libads/sasl_wrapping.c')
-rw-r--r--source3/libads/sasl_wrapping.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/source3/libads/sasl_wrapping.c b/source3/libads/sasl_wrapping.c
index 9617961969..419557a7bb 100644
--- a/source3/libads/sasl_wrapping.c
+++ b/source3/libads/sasl_wrapping.c
@@ -170,9 +170,75 @@ eagain:
return -1;
}
+static ber_slen_t ads_saslwrap_prepare_outbuf(ADS_STRUCT *ads, uint32 len)
+{
+ ads->ldap.out.ofs = 4;
+ ads->ldap.out.left = 4;
+ ads->ldap.out.size = 4 + ads->ldap.out.sig_size + len;
+ ads->ldap.out.buf = talloc_array(ads->ldap.mem_ctx,
+ uint8, ads->ldap.out.size);
+ if (!ads->ldap.out.buf) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static void ads_saslwrap_shrink_outbuf(ADS_STRUCT *ads)
+{
+ talloc_free(ads->ldap.out.buf);
+
+ ads->ldap.out.buf = NULL;
+ ads->ldap.out.size = 0;
+ ads->ldap.out.ofs = 0;
+ ads->ldap.out.left = 0;
+}
+
static ber_slen_t ads_saslwrap_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
{
- return LBER_SBIOD_WRITE_NEXT(sbiod, buf, len);
+ ADS_STRUCT *ads = (ADS_STRUCT *)sbiod->sbiod_pvt;
+ ber_slen_t ret, rlen;
+
+ /* if the buffer is empty, we need to wrap in incoming buffer */
+ if (ads->ldap.out.left == 0) {
+ ADS_STATUS status;
+
+ if (len == 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ rlen = MIN(len, ads->ldap.out.max);
+
+ ret = ads_saslwrap_prepare_outbuf(ads, rlen);
+ if (ret < 0) return ret;
+
+ status = ads->ldap.wrap_ops->wrap(ads, buf, rlen);
+ if (!ADS_ERR_OK(status)) {
+ errno = EACCES;
+ return -1;
+ }
+
+ RSIVAL(ads->ldap.out.buf, 0, ads->ldap.out.size - 4);
+ } else {
+ rlen = -1;
+ }
+
+ ret = LBER_SBIOD_WRITE_NEXT(sbiod,
+ ads->ldap.out.buf + ads->ldap.out.ofs,
+ ads->ldap.out.left);
+ if (ret < 0) return ret;
+ ads->ldap.out.ofs += ret;
+ ads->ldap.out.left -= ret;
+
+ if (ads->ldap.out.left == 0) {
+ ads_saslwrap_shrink_outbuf(ads);
+ }
+
+ if (rlen > 0) return rlen;
+
+ errno = EAGAIN;
+ return -1;
}
static int ads_saslwrap_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)