From: Volker Lendecke Date: Thu, 31 Oct 2024 16:04:44 +0000 (+0100) Subject: tldap: Add tldap_context_create_from_plain_stream() X-Git-Tag: tdb-1.4.13~597 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e88db0a6b519518febed4b4876acbc256dda23e8;p=thirdparty%2Fsamba.git tldap: Add tldap_context_create_from_plain_stream() Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- diff --git a/source3/include/tldap.h b/source3/include/tldap.h index 950c2a646a3..0a05da83fdf 100644 --- a/source3/include/tldap.h +++ b/source3/include/tldap.h @@ -122,6 +122,9 @@ typedef uint8_t TLDAPRC; bool tevent_req_ldap_error(struct tevent_req *req, TLDAPRC rc); bool tevent_req_is_ldap_error(struct tevent_req *req, TLDAPRC *perr); +struct tstream_context; +struct tldap_context *tldap_context_create_from_plain_stream( + TALLOC_CTX *mem_ctx, struct tstream_context **stream); struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd); struct tstream_context *tldap_get_plain_tstream(struct tldap_context *ld); bool tldap_has_tls_tstream(struct tldap_context *ld); diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c index 25193cd978c..88f636952fb 100644 --- a/source3/lib/tldap.c +++ b/source3/lib/tldap.c @@ -174,20 +174,16 @@ static int tldap_next_msgid(struct tldap_context *ld) return result; } -struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd) +struct tldap_context *tldap_context_create_from_plain_stream( + TALLOC_CTX *mem_ctx, struct tstream_context **stream) { struct tldap_context *ctx; - int ret; ctx = talloc_zero(mem_ctx, struct tldap_context); if (ctx == NULL) { return NULL; } - ret = tstream_bsd_existing_socket(ctx, fd, &ctx->plain); - if (ret == -1) { - TALLOC_FREE(ctx); - return NULL; - } + ctx->plain = talloc_move(ctx, stream); ctx->active = ctx->plain; ctx->msgid = 1; ctx->ld_version = 3; @@ -199,6 +195,25 @@ struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd) return ctx; } +struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd) +{ + struct tldap_context *ctx = NULL; + struct tstream_context *stream = NULL; + int ret; + + ret = tstream_bsd_existing_socket(mem_ctx, fd, &stream); + if (ret == -1) { + return NULL; + } + + ctx = tldap_context_create_from_plain_stream(mem_ctx, &stream); + if (ctx == NULL) { + TALLOC_FREE(stream); + return NULL; + } + return ctx; +} + bool tldap_connection_ok(struct tldap_context *ld) { int ret;