]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tldap: Add tldap_context_create_from_plain_stream()
authorVolker Lendecke <vl@samba.org>
Thu, 31 Oct 2024 16:04:44 +0000 (17:04 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 11 Nov 2024 14:03:04 +0000 (14:03 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/include/tldap.h
source3/lib/tldap.c

index 950c2a646a3cb9646b5c6fa36225b91e55390cbb..0a05da83fdf3d560488e97985d5727328fd695fe 100644 (file)
@@ -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);
index 25193cd978c16fffc21de08c0e1f6ab27655c110..88f636952fb6f9a83eca7e6600bbb23958d3c51b 100644 (file)
@@ -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;