From: Volker Lendecke Date: Tue, 29 Oct 2024 12:06:13 +0000 (+0100) Subject: libnet4: Use netlogon_pings() in unbecome_dc X-Git-Tag: tdb-1.4.13~580 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e7844537b676d3e69c2470899ab2fcb801f8cf23;p=thirdparty%2Fsamba.git libnet4: Use netlogon_pings() in unbecome_dc Enable LDAPS lookups Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- diff --git a/source4/libnet/libnet_unbecome_dc.c b/source4/libnet/libnet_unbecome_dc.c index dba7b90c6f5..4ee9e20c558 100644 --- a/source4/libnet/libnet_unbecome_dc.c +++ b/source4/libnet/libnet_unbecome_dc.c @@ -21,6 +21,7 @@ #include "libnet/libnet.h" #include "libcli/composite/composite.h" #include "libcli/cldap/cldap.h" +#include "source3/libads/netlogon_ping.h" #include #include #include "ldb_wrap.h" @@ -192,8 +193,6 @@ struct libnet_UnbecomeDC_state { struct libnet_context *libnet; struct { - struct cldap_socket *sock; - struct cldap_netlogon io; struct NETLOGON_SAM_LOGON_RESPONSE_EX netlogon; } cldap; @@ -257,20 +256,11 @@ static void unbecomeDC_recv_cldap(struct tevent_req *req); static void unbecomeDC_send_cldap(struct libnet_UnbecomeDC_state *s) { struct composite_context *c = s->creq; + struct libnet_context *libnet = s->libnet; struct tevent_req *req; struct tsocket_address *dest_address; int ret; - s->cldap.io.in.dest_address = NULL; - s->cldap.io.in.dest_port = 0; - s->cldap.io.in.realm = s->domain.dns_name; - s->cldap.io.in.host = s->dest_dsa.netbios_name; - s->cldap.io.in.user = NULL; - s->cldap.io.in.domain_guid = NULL; - s->cldap.io.in.domain_sid = NULL; - s->cldap.io.in.acct_control = -1; - s->cldap.io.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; - ret = tsocket_address_inet_from_strings( s, "ip", s->source_dsa.address, 389, &dest_address); if (ret != 0) { @@ -278,11 +268,23 @@ static void unbecomeDC_send_cldap(struct libnet_UnbecomeDC_state *s) if (!composite_is_ok(c)) return; } - c->status = cldap_socket_init(s, NULL, dest_address, &s->cldap.sock); - if (!composite_is_ok(c)) return; + req = netlogon_pings_send(s, /* mem_ctx */ + libnet->event_ctx, /* ev */ + lpcfg_client_netlogon_ping_protocol( + libnet->lp_ctx), /* proto */ + &dest_address, /* servers*/ + 1, /* num_servers */ + (struct netlogon_ping_filter){ + .ntversion = NETLOGON_NT_VERSION_5 | + NETLOGON_NT_VERSION_5EX, + .acct_ctrl = -1, + .domain = s->domain.dns_name, + .hostname = s->dest_dsa.netbios_name, + }, + 1, /* min_servers */ + tevent_timeval_current_ofs(2, + 0)); /* timeout */ - req = cldap_netlogon_send(s, s->libnet->event_ctx, - s->cldap.sock, &s->cldap.io); if (composite_nomem(req, c)) return; tevent_req_set_callback(req, unbecomeDC_recv_cldap, s); } @@ -294,14 +296,22 @@ static void unbecomeDC_recv_cldap(struct tevent_req *req) struct libnet_UnbecomeDC_state *s = tevent_req_callback_data(req, struct libnet_UnbecomeDC_state); struct composite_context *c = s->creq; + struct netlogon_samlogon_response **responses = NULL; + struct netlogon_samlogon_response *resp = NULL; - c->status = cldap_netlogon_recv(req, s, &s->cldap.io); + c->status = netlogon_pings_recv(req, s, &responses); talloc_free(req); - if (!composite_is_ok(c)) return; - - map_netlogon_samlogon_response(s->cldap.io.out.netlogon); + if (!composite_is_ok(c)) { + DBG_ERR("Failed to send, receive or parse CLDAP reply " + "for our host %s: %s\n", + s->dest_dsa.netbios_name, + nt_errstr(c->status)); + return; + } + resp = responses[0]; - s->cldap.netlogon = s->cldap.io.out.netlogon->data.nt5_ex; + map_netlogon_samlogon_response(resp); + s->cldap.netlogon = resp->data.nt5_ex; s->domain.dns_name = s->cldap.netlogon.dns_domain; s->domain.netbios_name = s->cldap.netlogon.domain_name;