s4-winbind Add a proxy method to update DNS records with a read-write DC
authorAndrew Bartlett <abartlet@samba.org>
Fri, 17 Sep 2010 00:11:48 +0000 (10:11 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 17 Sep 2010 09:02:18 +0000 (19:02 +1000)
This must be done in winbindd as it already has the schannel connection
and the credential chain.  If we re-established that elsewhere, we
would break the chain in winbindd.

Andrew Bartlett

Signed-Off-By: Andrew Tridgell <tridge@samba.org>
librpc/idl/netlogon.idl
source4/librpc/idl/winbind.idl
source4/winbind/wb_irpc.c
source4/winbind/wb_server.h
source4/winbind/wb_update_rodc_dns.c [new file with mode: 0644]
source4/winbind/wscript_build

index 62d2af55889659fd92c10e0922836bde14b80439..1685cf9a1e90a6de3cd4418879527a2c380fd12a 100644 (file)
@@ -1715,7 +1715,7 @@ interface netlogon
                uint32 status;
        } NL_DNS_NAME_INFO;
 
-       typedef struct {
+       typedef [public] struct {
                uint32 count;
                [size_is(count)] NL_DNS_NAME_INFO *names;
        } NL_DNS_NAME_INFO_ARRAY;
index 849b8166a77d677f42aaacccb39ca8cad83f25cf..f9bccb87c5cb3afb2f086ebf6b87be793cfa6c8f 100644 (file)
@@ -47,4 +47,9 @@ interface winbind
                [in,out] [size_is(count)] id_map ids[]
        );
 
+       NTSTATUS winbind_DsrUpdateReadOnlyServerDnsRecords(
+               [in,unique] [string,charset(UTF16)] uint16 *site_name,
+               [in] uint32 dns_ttl,
+               [in,out,ref] NL_DNS_NAME_INFO_ARRAY *dns_names
+               );
 }
index bfb31e66a76d11ae3474234a2833fdcf16335c84..1eed89fd41256f372bf5399acacdc5ebaf383331 100644 (file)
@@ -71,6 +71,52 @@ static void wb_irpc_SamLogon_callback(struct composite_context *ctx)
        irpc_send_reply(s->msg, status);
 }
 
+struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state {
+       struct irpc_message *msg;
+       struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
+};
+
+static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx);
+
+static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *msg,
+                                struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
+{
+       struct wbsrv_service *service = talloc_get_type(msg->private_data,
+                                       struct wbsrv_service);
+       struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s;
+       struct composite_context *ctx;
+
+       DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n"));
+
+       s = talloc(msg, struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
+       NT_STATUS_HAVE_NO_MEMORY(s);
+
+       s->msg = msg;
+       s->req = req;
+
+       ctx = wb_update_rodc_dns_send(msg, service, req);
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       ctx->async.fn = wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback;
+       ctx->async.private_data = s;
+
+       msg->defer_reply = true;
+       return NT_STATUS_OK;
+}
+
+static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx)
+{
+       struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s = talloc_get_type(ctx->async.private_data,
+                                          struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
+       NTSTATUS status;
+
+       DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback called\n"));
+
+       status = wb_update_rodc_dns_recv(ctx, s, s->req);
+
+       irpc_send_reply(s->msg, status);
+}
+
 struct wb_irpc_get_idmap_state {
        struct irpc_message *msg;
        struct winbind_get_idmap *req;
@@ -149,6 +195,10 @@ NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
                               wb_irpc_SamLogon, service);
        NT_STATUS_NOT_OK_RETURN(status);
 
+       status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_DSRUPDATEREADONLYSERVERDNSRECORDS,
+                              wb_irpc_DsrUpdateReadOnlyServerDnsRecords, service);
+       NT_STATUS_NOT_OK_RETURN(status);
+
        status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
                               wb_irpc_get_idmap, service);
        NT_STATUS_NOT_OK_RETURN(status);
index ddb77d05f66afdd40d1b8c255f63dd2f98a69036..f20bc0aa510f6cf25a649b61af8c7517efa3ab61 100644 (file)
@@ -176,6 +176,7 @@ struct wbsrv_samba3_call {
 struct netr_LMSessionKey;
 struct netr_UserSessionKey;
 struct winbind_SamLogon;
+struct winbind_DsrUpdateReadOnlyServerDnsRecords;
 
 #include "winbind/wb_async_helpers.h"
 #include "winbind/wb_proto.h"
diff --git a/source4/winbind/wb_update_rodc_dns.c b/source4/winbind/wb_update_rodc_dns.c
new file mode 100644 (file)
index 0000000..5ad2d0c
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Do a netr_DsrUpdateReadOnlyServerDnsRecords to a remote DC
+
+   Copyright (C) Andrew Bartlett 2010
+   Copyright (C) Andrew Tridgell 2010
+
+   based heavily on wb_sam_logon.c which is copyright:
+
+   Copyright (C) Volker Lendecke 2005
+   Copyright (C) Andrew Bartlett 2005
+   Copyright (C) Stefan Metzmacher 2006
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "libcli/composite/composite.h"
+#include "winbind/wb_server.h"
+#include "smbd/service_task.h"
+#include "auth/credentials/credentials.h"
+#include "libcli/auth/libcli_auth.h"
+#include "librpc/gen_ndr/ndr_netlogon_c.h"
+#include "librpc/gen_ndr/winbind.h"
+
+struct wb_update_rodc_dns_state {
+       struct composite_context *ctx;
+
+       struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
+
+        struct netlogon_creds_CredentialState *creds_state;
+        struct netr_Authenticator auth1, auth2;
+
+       TALLOC_CTX *r_mem_ctx;
+        struct netr_DsrUpdateReadOnlyServerDnsRecords r;
+};
+
+static void wb_update_rodc_dns_recv_domain(struct composite_context *ctx);
+static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq);
+
+/*
+    Find the connection to the DC (or find an existing connection)
+*/
+struct composite_context *wb_update_rodc_dns_send(TALLOC_CTX *mem_ctx,
+                                           struct wbsrv_service *service,
+                                           struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
+{
+       struct composite_context *c, *creq;
+       struct wb_update_rodc_dns_state *s;
+
+       c = composite_create(mem_ctx, service->task->event_ctx);
+       if (!c) return NULL;
+
+       s = talloc_zero(c, struct wb_update_rodc_dns_state);
+       if (composite_nomem(s, c)) return c;
+       s->ctx = c;
+       s->req = req;
+
+       c->private_data = s;
+
+       creq = wb_sid2domain_send(s, service, service->primary_sid);
+       composite_continue(c, creq, wb_update_rodc_dns_recv_domain, s);
+       return c;
+}
+
+/*
+    Having finished making the connection to the DC
+    Send of a DsrUpdateReadOnlyServerDnsRecords request to authenticate a user.
+*/
+static void wb_update_rodc_dns_recv_domain(struct composite_context *creq)
+{
+       struct wb_update_rodc_dns_state *s = talloc_get_type(creq->async.private_data,
+                                      struct wb_update_rodc_dns_state);
+       struct wbsrv_domain *domain;
+       struct tevent_req *subreq;
+
+       s->ctx->status = wb_sid2domain_recv(creq, &domain);
+       if (!composite_is_ok(s->ctx)) return;
+
+       s->creds_state = cli_credentials_get_netlogon_creds(domain->libnet_ctx->cred);
+       netlogon_creds_client_authenticator(s->creds_state, &s->auth1);
+
+       s->r.in.server_name = talloc_asprintf(s, "\\\\%s",
+                             dcerpc_server_name(domain->netlogon_pipe));
+       if (composite_nomem(s->r.in.server_name, s->ctx)) return;
+
+       s->r.in.computer_name = cli_credentials_get_workstation(domain->libnet_ctx->cred);
+       s->r.in.credential = &s->auth1;
+       s->r.out.return_authenticator = &s->auth2;
+       s->r.in.site_name = s->req->in.site_name;
+       s->r.in.dns_ttl = s->req->in.dns_ttl;
+       s->r.in.dns_names = s->req->in.dns_names;
+       s->r.out.dns_names = s->req->in.dns_names;
+
+       /*
+        * use a new talloc context for the DsrUpdateReadOnlyServerDnsRecords call
+        * because then we can just to a talloc_steal on this context
+        * in the final _recv() function to give the caller all the content of
+        * the s->r.out.dns_names
+        */
+       s->r_mem_ctx = talloc_new(s);
+       if (composite_nomem(s->r_mem_ctx, s->ctx)) return;
+
+       subreq = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_send(s,
+                                                 s->ctx->event_ctx,
+                                                 domain->netlogon_pipe->binding_handle,
+                                                 &s->r);
+       if (composite_nomem(subreq, s->ctx)) return;
+       tevent_req_set_callback(subreq, wb_update_rodc_dns_recv_response, s);
+}
+
+/*
+   NTLM Authentication
+
+   Check the DsrUpdateReadOnlyServerDnsRecords reply and decrypt the session keys
+*/
+static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq)
+{
+       struct wb_update_rodc_dns_state *s = tevent_req_callback_data(subreq,
+                                      struct wb_update_rodc_dns_state);
+
+       s->ctx->status = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_recv(subreq, s->r_mem_ctx);
+       TALLOC_FREE(subreq);
+       if (!composite_is_ok(s->ctx)) return;
+
+       s->ctx->status = s->r.out.result;
+       if (!composite_is_ok(s->ctx)) return;
+
+       if ((s->r.out.return_authenticator == NULL) ||
+           (!netlogon_creds_client_check(s->creds_state,
+                                         &s->r.out.return_authenticator->cred))) {
+               DEBUG(0, ("Credentials check failed!\n"));
+               composite_error(s->ctx, NT_STATUS_ACCESS_DENIED);
+               return;
+       }
+
+       composite_done(s->ctx);
+}
+
+NTSTATUS wb_update_rodc_dns_recv(struct composite_context *c,
+                          TALLOC_CTX *mem_ctx,
+                          struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
+{
+       struct wb_update_rodc_dns_state *s = talloc_get_type(c->private_data,
+                                      struct wb_update_rodc_dns_state);
+       NTSTATUS status = composite_wait(c);
+
+       if (NT_STATUS_IS_OK(status)) {
+               talloc_steal(mem_ctx, s->r_mem_ctx);
+               req->out.dns_names      = s->r.out.dns_names;
+       }
+
+       talloc_free(s);
+       return status;
+}
index c9682f3eeca65ef640c271f58d9d94b9cf33af54..2c8a6f8317d2f1f7e9ed43437e2f70fff7c3e825 100644 (file)
@@ -2,7 +2,7 @@
 
 
 bld.SAMBA_MODULE('WINBIND',
-       source='wb_server.c wb_irpc.c wb_samba3_protocol.c wb_samba3_cmd.c wb_init_domain.c wb_dom_info.c wb_dom_info_trusted.c wb_sid2domain.c wb_name2domain.c wb_sids2xids.c wb_xids2sids.c wb_gid2sid.c wb_sid2uid.c wb_sid2gid.c wb_uid2sid.c wb_connect_lsa.c wb_connect_sam.c wb_cmd_lookupname.c wb_cmd_lookupsid.c wb_cmd_getdcname.c wb_cmd_getgrnam.c wb_cmd_getgrgid.c wb_cmd_getpwnam.c wb_cmd_getpwuid.c wb_cmd_userdomgroups.c wb_cmd_usersids.c wb_cmd_list_groups.c wb_cmd_list_trustdom.c wb_cmd_list_users.c wb_cmd_setpwent.c wb_cmd_getpwent.c wb_cmd_getgrent.c wb_cmd_setgrent.c wb_cmd_getgroups.c wb_pam_auth.c wb_sam_logon.c',
+       source='wb_server.c wb_irpc.c wb_samba3_protocol.c wb_samba3_cmd.c wb_init_domain.c wb_dom_info.c wb_dom_info_trusted.c wb_sid2domain.c wb_name2domain.c wb_sids2xids.c wb_xids2sids.c wb_gid2sid.c wb_sid2uid.c wb_sid2gid.c wb_uid2sid.c wb_connect_lsa.c wb_connect_sam.c wb_cmd_lookupname.c wb_cmd_lookupsid.c wb_cmd_getdcname.c wb_cmd_getgrnam.c wb_cmd_getgrgid.c wb_cmd_getpwnam.c wb_cmd_getpwuid.c wb_cmd_userdomgroups.c wb_cmd_usersids.c wb_cmd_list_groups.c wb_cmd_list_trustdom.c wb_cmd_list_users.c wb_cmd_setpwent.c wb_cmd_getpwent.c wb_cmd_getgrent.c wb_cmd_setgrent.c wb_cmd_getgroups.c wb_pam_auth.c wb_sam_logon.c wb_update_rodc_dns.c',
        autoproto='wb_proto.h',
        subsystem='service',
        init_function='server_service_winbind_init',