]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tstream: Add tstream_npa_existing_stream()
authorVolker Lendecke <vl@samba.org>
Tue, 16 Feb 2021 16:22:40 +0000 (17:22 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 1 Apr 2021 20:36:19 +0000 (20:36 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Apr  1 20:36:19 UTC 2021 on sn-devel-184

libcli/named_pipe_auth/npa_tstream.c
libcli/named_pipe_auth/npa_tstream.h

index fcd616819c3b8ac01811ffddc71bfde75f271f28..a6fa0211d20bf107d73683db1e6a2051d680bca8 100644 (file)
@@ -949,15 +949,14 @@ static const struct tstream_context_ops tstream_npa_ops = {
        .disconnect_recv        = tstream_npa_disconnect_recv,
 };
 
-int _tstream_npa_existing_socket(TALLOC_CTX *mem_ctx,
-                                int fd,
+int _tstream_npa_existing_stream(TALLOC_CTX *mem_ctx,
+                                struct tstream_context **transport,
                                 uint16_t file_type,
                                 struct tstream_context **_stream,
                                 const char *location)
 {
        struct tstream_context *stream;
        struct tstream_npa *npas;
-       int ret;
 
        switch (file_type) {
        case FILE_TYPE_BYTE_MODE_PIPE:
@@ -977,23 +976,33 @@ int _tstream_npa_existing_socket(TALLOC_CTX *mem_ctx,
        if (!stream) {
                return -1;
        }
-       ZERO_STRUCTP(npas);
-
-       npas->file_type = file_type;
 
-       ret = tstream_bsd_existing_socket(stream, fd,
-                                         &npas->unix_stream);
-       if (ret == -1) {
-               int saved_errno = errno;
-               talloc_free(stream);
-               errno = saved_errno;
-               return -1;
-       }
+       *npas = (struct tstream_npa) {
+               .file_type = file_type,
+               .unix_stream = talloc_move(npas, transport),
+       };
 
        *_stream = stream;
        return 0;
 }
 
+int _tstream_npa_existing_socket(TALLOC_CTX *mem_ctx,
+                                int fd,
+                                uint16_t file_type,
+                                struct tstream_context **_stream,
+                                const char *location)
+{
+       struct tstream_context *transport = NULL;
+       int ret;
+
+       ret = _tstream_bsd_existing_socket(
+               mem_ctx, fd, &transport, location);
+       if (ret == -1) {
+               return -1;
+       }
+       return _tstream_npa_existing_stream(
+               mem_ctx, &transport, file_type, _stream, location);
+}
 
 struct tstream_npa_accept_state {
        struct tevent_context *ev;
index 72174ea6bf3b7d806240fbb72590495b43ffc297..27e4d9c5a214001297e4bb0d0028d85e56a6b5f0 100644 (file)
@@ -47,6 +47,15 @@ int _tstream_npa_connect_recv(struct tevent_req *req,
        _tstream_npa_connect_recv(req, perrno, mem_ctx, stream, f, d, a, \
                                  __location__)
 
+int _tstream_npa_existing_stream(TALLOC_CTX *mem_ctx,
+                                struct tstream_context **transport,
+                                uint16_t file_type,
+                                struct tstream_context **_stream,
+                                const char *location);
+#define tstream_npa_existing_stream(mem_ctx, transport, ft, stream) \
+       _tstream_npa_existing_stream(mem_ctx, transport, ft, stream, \
+                                    __location__)
+
 int _tstream_npa_existing_socket(TALLOC_CTX *mem_ctx,
                                 int fd,
                                 uint16_t file_type,