From e742661bd2507d39dfa47e40531dc1dca636cbbe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 16 Feb 2021 17:22:40 +0100 Subject: [PATCH] tstream: Add tstream_npa_existing_stream() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Apr 1 20:36:19 UTC 2021 on sn-devel-184 --- libcli/named_pipe_auth/npa_tstream.c | 37 +++++++++++++++++----------- libcli/named_pipe_auth/npa_tstream.h | 9 +++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libcli/named_pipe_auth/npa_tstream.c b/libcli/named_pipe_auth/npa_tstream.c index fcd616819c3..a6fa0211d20 100644 --- a/libcli/named_pipe_auth/npa_tstream.c +++ b/libcli/named_pipe_auth/npa_tstream.c @@ -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; diff --git a/libcli/named_pipe_auth/npa_tstream.h b/libcli/named_pipe_auth/npa_tstream.h index 72174ea6bf3..27e4d9c5a21 100644 --- a/libcli/named_pipe_auth/npa_tstream.h +++ b/libcli/named_pipe_auth/npa_tstream.h @@ -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, -- 2.47.3