r17168: Now that TLS (and soon SASL) is below the socket layer, we need to
authorAndrew Bartlett <abartlet@samba.org>
Fri, 21 Jul 2006 01:34:56 +0000 (01:34 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:10:15 +0000 (14:10 -0500)
make the testnonblock skip some things.  The socket *under* the tls
socket is still tested.

Andrew Bartlett
(This used to be commit 9c33c6a20a77e3f15eac3d62488117517afad940)

source4/lib/socket/socket.c
source4/lib/socket/socket.h
source4/lib/tls/config.mk
source4/lib/tls/tls.c

index e1f8bb4d8685060409b8875ed610f6a4d90804f9..ac64bc4ddc272f0e69fe5fbd9b24d5fa0d910450 100644 (file)
@@ -66,6 +66,7 @@ _PUBLIC_ NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socke
        /* by enabling "testnonblock" mode, all socket receive and
           send calls on non-blocking sockets will randomly recv/send
           less data than requested */
+
        if (!(flags & SOCKET_FLAG_BLOCK) &&
            type == SOCKET_TYPE_STREAM &&
            lp_parm_bool(-1, "socket", "testnonblock", False)) {
@@ -185,14 +186,21 @@ _PUBLIC_ NTSTATUS socket_recv(struct socket_context *sock, void *buf,
                return NT_STATUS_NOT_IMPLEMENTED;
        }
 
-       if ((sock->flags & SOCKET_FLAG_TESTNONBLOCK) && wantlen > 1) {
-               if (random() % 10 == 0) {
-                       *nread = 0;
-                       return STATUS_MORE_ENTRIES;
+       if ((sock->flags & SOCKET_FLAG_TESTNONBLOCK) 
+           && wantlen > 1) {
+
+               /* The returning of 0 and MORE_ENTRIES is incompatible
+                  with TLS and SASL sockets, as there is not a
+                  constant event source to re-trigger the reads */
+
+               if (!(sock->flags & SOCKET_FLAG_FAKE)) {
+                       if (random() % 10 == 0) {
+                               *nread = 0;
+                               return STATUS_MORE_ENTRIES;
+                       }
                }
                return sock->ops->fn_recv(sock, buf, 1+(random() % wantlen), nread);
        }
-
        return sock->ops->fn_recv(sock, buf, wantlen, nread);
 }
 
@@ -229,17 +237,21 @@ _PUBLIC_ NTSTATUS socket_send(struct socket_context *sock,
        if (!sock->ops->fn_send) {
                return NT_STATUS_NOT_IMPLEMENTED;
        }
-
-       if ((sock->flags & SOCKET_FLAG_TESTNONBLOCK) && blob->length > 1) {
-               DATA_BLOB blob2 = *blob;
+       
+       if ((sock->flags & SOCKET_FLAG_TESTNONBLOCK)
+           && blob->length > 1) {
                if (random() % 10 == 0) {
                        *sendlen = 0;
                        return STATUS_MORE_ENTRIES;
                }
-               blob2.length = 1+(random() % blob2.length);
-               return sock->ops->fn_send(sock, &blob2, sendlen);
+               /* The variable size sends are incompatilbe with TLS and SASL
+                * sockets, which require re-sends to be consistant */
+               if (!(sock->flags & SOCKET_FLAG_FAKE)) {
+                       DATA_BLOB blob2 = *blob;
+                       blob2.length = 1+(random() % blob2.length);
+                       return sock->ops->fn_send(sock, &blob2, sendlen);
+               }
        }
-
        return sock->ops->fn_send(sock, blob, sendlen);
 }
 
index fefa999e08195a0d9e6678db089724cde8ec8248..c0cf429887c3e0ecc57ee01c44b8927ef346d7e6 100644 (file)
@@ -102,6 +102,7 @@ enum socket_state {
 #define SOCKET_FLAG_BLOCK        0x00000001
 #define SOCKET_FLAG_PEEK         0x00000002
 #define SOCKET_FLAG_TESTNONBLOCK 0x00000004
+#define SOCKET_FLAG_FAKE         0x00000008 /* This is an implementation not directly on top of a real socket */
 
 struct socket_context {
        enum socket_type type;
index 2ab296049b940774dfd807a083da8eeaea82768b..f75c613e731a55a83871ecd49a5a02a8b6a508c2 100644 (file)
@@ -5,7 +5,7 @@ OBJ_FILES = \
                tls.o \
                tlscert.o
 PUBLIC_DEPENDENCIES = \
-               LIBTALLOC GNUTLS LIBSAMBA-CONFIG
+               LIBTALLOC GNUTLS LIBSAMBA-CONFIG samba-socket
 #
 # End SUBSYSTEM LIBTLS
 ################################################
index 936c18c0c6c9da2108f6e0a582c964be1908baeb..1ba8ae977917592734cbc70a43958ce2b552d0a2 100644 (file)
@@ -443,7 +443,8 @@ struct socket_context *tls_init_server(struct tls_params *params,
        NTSTATUS nt_status;
        
        nt_status = socket_create_with_ops(socket, &tls_socket_ops, &new_sock, 
-                                          SOCKET_TYPE_STREAM, 0);
+                                          SOCKET_TYPE_STREAM, 
+                                          socket->flags | SOCKET_FLAG_FAKE);
        if (!NT_STATUS_IS_OK(nt_status)) {
                return NULL;
        }
@@ -522,7 +523,8 @@ struct socket_context *tls_init_client(struct socket_context *socket,
        NTSTATUS nt_status;
        
        nt_status = socket_create_with_ops(socket, &tls_socket_ops, &new_sock, 
-                                          SOCKET_TYPE_STREAM, 0);
+                                          SOCKET_TYPE_STREAM, 
+                                          socket->flags | SOCKET_FLAG_FAKE);
        if (!NT_STATUS_IS_OK(nt_status)) {
                return NULL;
        }