~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source4/winbind/wb_dom_info.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   Unix SMB/CIFS implementation.
 
3
 
 
4
   Get a struct wb_dom_info for a domain using DNS, netbios, possibly cldap
 
5
   etc.
 
6
 
 
7
   Copyright (C) Volker Lendecke 2005
 
8
   
 
9
   This program is free software; you can redistribute it and/or modify
 
10
   it under the terms of the GNU General Public License as published by
 
11
   the Free Software Foundation; either version 3 of the License, or
 
12
   (at your option) any later version.
 
13
   
 
14
   This program is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
   GNU General Public License for more details.
 
18
   
 
19
   You should have received a copy of the GNU General Public License
 
20
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
*/
 
22
 
 
23
#include "includes.h"
 
24
#include "libcli/composite/composite.h"
 
25
#include "libcli/resolve/resolve.h"
 
26
#include "libcli/security/security.h"
 
27
#include "winbind/wb_server.h"
 
28
#include "smbd/service_task.h"
 
29
#include "librpc/gen_ndr/ndr_irpc.h"
 
30
#include "librpc/gen_ndr/samr.h"
 
31
#include "lib/messaging/irpc.h"
 
32
#include "libcli/finddcs.h"
 
33
#include "param/param.h"
 
34
 
 
35
struct get_dom_info_state {
 
36
        struct composite_context *ctx;
 
37
        struct wb_dom_info *info;
 
38
};
 
39
 
 
40
static void get_dom_info_recv_addrs(struct composite_context *ctx);
 
41
 
 
42
struct composite_context *wb_get_dom_info_send(TALLOC_CTX *mem_ctx,
 
43
                                               struct wbsrv_service *service,
 
44
                                               const char *domain_name,
 
45
                                               const struct dom_sid *sid)
 
46
{
 
47
        struct composite_context *result, *ctx;
 
48
        struct get_dom_info_state *state;
 
49
        struct dom_sid *dom_sid;
 
50
        result = composite_create(mem_ctx, service->task->event_ctx);
 
51
        if (result == NULL) goto failed;
 
52
 
 
53
        state = talloc(result, struct get_dom_info_state);
 
54
        if (state == NULL) goto failed;
 
55
        state->ctx = result;
 
56
        result->private_data = state;
 
57
 
 
58
        state->info = talloc_zero(state, struct wb_dom_info);
 
59
        if (state->info == NULL) goto failed;
 
60
 
 
61
        state->info->name = talloc_strdup(state->info, domain_name);
 
62
        if (state->info->name == NULL) goto failed;
 
63
 
 
64
        state->info->sid = dom_sid_dup(state->info, sid);
 
65
        if (state->info->sid == NULL) goto failed;
 
66
 
 
67
        dom_sid = dom_sid_dup(mem_ctx, sid);
 
68
        if (dom_sid == NULL) goto failed;
 
69
 
 
70
        ctx = finddcs_send(mem_ctx, lp_netbios_name(service->task->lp_ctx),
 
71
                           lp_nbt_port(service->task->lp_ctx),
 
72
                           domain_name, NBT_NAME_LOGON, 
 
73
                           dom_sid, 
 
74
                           lp_iconv_convenience(service->task->lp_ctx),
 
75
                           lp_resolve_context(service->task->lp_ctx), 
 
76
                           service->task->event_ctx, 
 
77
                           service->task->msg_ctx);
 
78
        if (ctx == NULL) goto failed;
 
79
 
 
80
        composite_continue(state->ctx, ctx, get_dom_info_recv_addrs, state);
 
81
        return result;
 
82
 
 
83
 failed:
 
84
        talloc_free(result);
 
85
        return NULL;
 
86
}
 
87
 
 
88
static void get_dom_info_recv_addrs(struct composite_context *ctx)
 
89
{
 
90
        struct get_dom_info_state *state =
 
91
                talloc_get_type(ctx->async.private_data,
 
92
                                struct get_dom_info_state);
 
93
 
 
94
        state->ctx->status = finddcs_recv(ctx, state->info,
 
95
                                          &state->info->num_dcs,
 
96
                                          &state->info->dcs);
 
97
        if (!composite_is_ok(state->ctx)) return;
 
98
 
 
99
        composite_done(state->ctx);
 
100
}
 
101
 
 
102
NTSTATUS wb_get_dom_info_recv(struct composite_context *ctx,
 
103
                              TALLOC_CTX *mem_ctx,
 
104
                              struct wb_dom_info **result)
 
105
{
 
106
        NTSTATUS status = composite_wait(ctx);
 
107
        if (NT_STATUS_IS_OK(status)) {
 
108
                struct get_dom_info_state *state =
 
109
                        talloc_get_type(ctx->private_data,
 
110
                                        struct get_dom_info_state);
 
111
                *result = talloc_steal(mem_ctx, state->info);
 
112
        }
 
113
        talloc_free(ctx);
 
114
        return status;
 
115
}
 
116
 
 
117
NTSTATUS wb_get_dom_info(TALLOC_CTX *mem_ctx,
 
118
                         struct wbsrv_service *service,
 
119
                         const char *domain_name,
 
120
                         const struct dom_sid *sid,
 
121
                         struct wb_dom_info **result)
 
122
{
 
123
        struct composite_context *ctx =
 
124
                wb_get_dom_info_send(mem_ctx, service, domain_name, sid);
 
125
        return wb_get_dom_info_recv(ctx, mem_ctx, result);
 
126
}