~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/winbind/wb_update_rodc_dns.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Unix SMB/CIFS implementation.
 
3
 
 
4
   Do a netr_DsrUpdateReadOnlyServerDnsRecords to a remote DC
 
5
 
 
6
   Copyright (C) Andrew Bartlett 2010
 
7
   Copyright (C) Andrew Tridgell 2010
 
8
 
 
9
   based heavily on wb_sam_logon.c which is copyright:
 
10
 
 
11
   Copyright (C) Volker Lendecke 2005
 
12
   Copyright (C) Andrew Bartlett 2005
 
13
   Copyright (C) Stefan Metzmacher 2006
 
14
 
 
15
   This program is free software; you can redistribute it and/or modify
 
16
   it under the terms of the GNU General Public License as published by
 
17
   the Free Software Foundation; either version 3 of the License, or
 
18
   (at your option) any later version.
 
19
 
 
20
   This program is distributed in the hope that it will be useful,
 
21
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
   GNU General Public License for more details.
 
24
 
 
25
   You should have received a copy of the GNU General Public License
 
26
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
27
*/
 
28
 
 
29
#include "includes.h"
 
30
#include "libcli/composite/composite.h"
 
31
#include "winbind/wb_server.h"
 
32
#include "smbd/service_task.h"
 
33
#include "auth/credentials/credentials.h"
 
34
#include "libcli/auth/libcli_auth.h"
 
35
#include "librpc/gen_ndr/ndr_netlogon_c.h"
 
36
#include "librpc/gen_ndr/winbind.h"
 
37
 
 
38
struct wb_update_rodc_dns_state {
 
39
        struct composite_context *ctx;
 
40
 
 
41
        struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
 
42
 
 
43
        struct netlogon_creds_CredentialState *creds_state;
 
44
        struct netr_Authenticator auth1, auth2;
 
45
 
 
46
        TALLOC_CTX *r_mem_ctx;
 
47
        struct netr_DsrUpdateReadOnlyServerDnsRecords r;
 
48
};
 
49
 
 
50
static void wb_update_rodc_dns_recv_domain(struct composite_context *ctx);
 
51
static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq);
 
52
 
 
53
/*
 
54
    Find the connection to the DC (or find an existing connection)
 
55
*/
 
56
struct composite_context *wb_update_rodc_dns_send(TALLOC_CTX *mem_ctx,
 
57
                                            struct wbsrv_service *service,
 
58
                                            struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
 
59
{
 
60
        struct composite_context *c, *creq;
 
61
        struct wb_update_rodc_dns_state *s;
 
62
 
 
63
        c = composite_create(mem_ctx, service->task->event_ctx);
 
64
        if (!c) return NULL;
 
65
 
 
66
        s = talloc_zero(c, struct wb_update_rodc_dns_state);
 
67
        if (composite_nomem(s, c)) return c;
 
68
        s->ctx = c;
 
69
        s->req = req;
 
70
 
 
71
        c->private_data = s;
 
72
 
 
73
        creq = wb_sid2domain_send(s, service, service->primary_sid);
 
74
        composite_continue(c, creq, wb_update_rodc_dns_recv_domain, s);
 
75
        return c;
 
76
}
 
77
 
 
78
/*
 
79
    Having finished making the connection to the DC
 
80
    Send of a DsrUpdateReadOnlyServerDnsRecords request to authenticate a user.
 
81
*/
 
82
static void wb_update_rodc_dns_recv_domain(struct composite_context *creq)
 
83
{
 
84
        struct wb_update_rodc_dns_state *s = talloc_get_type(creq->async.private_data,
 
85
                                       struct wb_update_rodc_dns_state);
 
86
        struct wbsrv_domain *domain;
 
87
        struct tevent_req *subreq;
 
88
 
 
89
        s->ctx->status = wb_sid2domain_recv(creq, &domain);
 
90
        if (!composite_is_ok(s->ctx)) return;
 
91
 
 
92
        s->creds_state = cli_credentials_get_netlogon_creds(domain->libnet_ctx->cred);
 
93
        netlogon_creds_client_authenticator(s->creds_state, &s->auth1);
 
94
 
 
95
        s->r.in.server_name = talloc_asprintf(s, "\\\\%s",
 
96
                              dcerpc_server_name(domain->netlogon_pipe));
 
97
        if (composite_nomem(s->r.in.server_name, s->ctx)) return;
 
98
 
 
99
        s->r.in.computer_name = cli_credentials_get_workstation(domain->libnet_ctx->cred);
 
100
        s->r.in.credential = &s->auth1;
 
101
        s->r.out.return_authenticator = &s->auth2;
 
102
        s->r.in.site_name = s->req->in.site_name;
 
103
        s->r.in.dns_ttl = s->req->in.dns_ttl;
 
104
        s->r.in.dns_names = s->req->in.dns_names;
 
105
        s->r.out.dns_names = s->req->in.dns_names;
 
106
 
 
107
        /*
 
108
         * use a new talloc context for the DsrUpdateReadOnlyServerDnsRecords call
 
109
         * because then we can just to a talloc_steal on this context
 
110
         * in the final _recv() function to give the caller all the content of
 
111
         * the s->r.out.dns_names
 
112
         */
 
113
        s->r_mem_ctx = talloc_new(s);
 
114
        if (composite_nomem(s->r_mem_ctx, s->ctx)) return;
 
115
 
 
116
        subreq = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_send(s,
 
117
                                                  s->ctx->event_ctx,
 
118
                                                  domain->netlogon_pipe->binding_handle,
 
119
                                                  &s->r);
 
120
        if (composite_nomem(subreq, s->ctx)) return;
 
121
        tevent_req_set_callback(subreq, wb_update_rodc_dns_recv_response, s);
 
122
}
 
123
 
 
124
/*
 
125
   NTLM Authentication
 
126
 
 
127
   Check the DsrUpdateReadOnlyServerDnsRecords reply and decrypt the session keys
 
128
*/
 
129
static void wb_update_rodc_dns_recv_response(struct tevent_req *subreq)
 
130
{
 
131
        struct wb_update_rodc_dns_state *s = tevent_req_callback_data(subreq,
 
132
                                       struct wb_update_rodc_dns_state);
 
133
 
 
134
        s->ctx->status = dcerpc_netr_DsrUpdateReadOnlyServerDnsRecords_r_recv(subreq, s->r_mem_ctx);
 
135
        TALLOC_FREE(subreq);
 
136
        if (!composite_is_ok(s->ctx)) return;
 
137
 
 
138
        s->ctx->status = s->r.out.result;
 
139
        if (!composite_is_ok(s->ctx)) return;
 
140
 
 
141
        if ((s->r.out.return_authenticator == NULL) ||
 
142
            (!netlogon_creds_client_check(s->creds_state,
 
143
                                          &s->r.out.return_authenticator->cred))) {
 
144
                DEBUG(0, ("Credentials check failed!\n"));
 
145
                composite_error(s->ctx, NT_STATUS_ACCESS_DENIED);
 
146
                return;
 
147
        }
 
148
 
 
149
        composite_done(s->ctx);
 
150
}
 
151
 
 
152
NTSTATUS wb_update_rodc_dns_recv(struct composite_context *c,
 
153
                           TALLOC_CTX *mem_ctx,
 
154
                           struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
 
155
{
 
156
        struct wb_update_rodc_dns_state *s = talloc_get_type(c->private_data,
 
157
                                       struct wb_update_rodc_dns_state);
 
158
        NTSTATUS status = composite_wait(c);
 
159
 
 
160
        if (NT_STATUS_IS_OK(status)) {
 
161
                talloc_steal(mem_ctx, s->r_mem_ctx);
 
162
                req->out.dns_names      = s->r.out.dns_names;
 
163
        }
 
164
 
 
165
        talloc_free(s);
 
166
        return status;
 
167
}