summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-09-17 10:11:48 +1000
committerAndrew Tridgell <tridge@samba.org>2010-09-17 19:02:18 +1000
commit39bd61e018d8495f9a7368d1656c6f52d422e6e3 (patch)
tree6821a78e2d4ad9b83a68483721095881d7e31fde
parentb772f4cdffda7f7e1bd0a7951bec0304102606d2 (diff)
downloadsamba-39bd61e018d8495f9a7368d1656c6f52d422e6e3.tar.gz
samba-39bd61e018d8495f9a7368d1656c6f52d422e6e3.tar.bz2
samba-39bd61e018d8495f9a7368d1656c6f52d422e6e3.zip
s4-winbind Add a proxy method to update DNS records with a read-write DC
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>
-rw-r--r--librpc/idl/netlogon.idl2
-rw-r--r--source4/librpc/idl/winbind.idl5
-rw-r--r--source4/winbind/wb_irpc.c50
-rw-r--r--source4/winbind/wb_server.h1
-rw-r--r--source4/winbind/wb_update_rodc_dns.c167
-rw-r--r--source4/winbind/wscript_build2
6 files changed, 225 insertions, 2 deletions
diff --git a/librpc/idl/netlogon.idl b/librpc/idl/netlogon.idl
index 62d2af5588..1685cf9a1e 100644
--- a/librpc/idl/netlogon.idl
+++ b/librpc/idl/netlogon.idl
@@ -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;
diff --git a/source4/librpc/idl/winbind.idl b/source4/librpc/idl/winbind.idl
index 849b8166a7..f9bccb87c5 100644
--- a/source4/librpc/idl/winbind.idl
+++ b/source4/librpc/idl/winbind.idl
@@ -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
+ );
}
diff --git a/source4/winbind/wb_irpc.c b/source4/winbind/wb_irpc.c
index bfb31e66a7..1eed89fd41 100644
--- a/source4/winbind/wb_irpc.c
+++ b/source4/winbind/wb_irpc.c
@@ -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);
diff --git a/source4/winbind/wb_server.h b/source4/winbind/wb_server.h
index ddb77d05f6..f20bc0aa51 100644
--- a/source4/winbind/wb_server.h
+++ b/source4/winbind/wb_server.h
@@ -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
index 0000000000..5ad2d0cbb0
--- /dev/null
+++ b/source4/winbind/wb_update_rodc_dns.c
@@ -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;
+}
diff --git a/source4/winbind/wscript_build b/source4/winbind/wscript_build
index c9682f3eec..2c8a6f8317 100644
--- a/source4/winbind/wscript_build
+++ b/source4/winbind/wscript_build
@@ -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',