2 Unix SMB/CIFS implementation.
4 Winbind client library.
6 Copyright (C) 2008 Kai Blin <kai@samba.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "libcli/wbclient/wbclient.h"
27 * Initialize the wbclient context, talloc_free() when done.
29 * \param mem_ctx talloc context to allocate memory from
30 * \param msg_ctx message context to use
33 struct wbc_context
*wbc_init(TALLOC_CTX
*mem_ctx
,
34 struct imessaging_context
*msg_ctx
,
35 struct tevent_context
*event_ctx
)
37 struct wbc_context
*ctx
;
39 ctx
= talloc(mem_ctx
, struct wbc_context
);
40 if (ctx
== NULL
) return NULL
;
42 ctx
->event_ctx
= event_ctx
;
44 ctx
->irpc_handle
= irpc_binding_handle_by_name(ctx
, msg_ctx
,
47 if (ctx
->irpc_handle
== NULL
) {
55 struct wbc_idmap_state
{
56 struct composite_context
*ctx
;
57 struct winbind_get_idmap
*req
;
61 static void sids_to_xids_recv_ids(struct tevent_req
*subreq
);
63 struct composite_context
*wbc_sids_to_xids_send(struct wbc_context
*wbc_ctx
,
68 struct composite_context
*ctx
;
69 struct wbc_idmap_state
*state
;
70 struct tevent_req
*subreq
;
72 DEBUG(5, ("wbc_sids_to_xids called\n"));
74 ctx
= composite_create(mem_ctx
, wbc_ctx
->event_ctx
);
75 if (ctx
== NULL
) return NULL
;
77 state
= talloc(ctx
, struct wbc_idmap_state
);
78 if (composite_nomem(state
, ctx
)) return ctx
;
79 ctx
->private_data
= state
;
81 state
->req
= talloc(state
, struct winbind_get_idmap
);
82 if (composite_nomem(state
->req
, ctx
)) return ctx
;
84 state
->req
->in
.count
= count
;
85 state
->req
->in
.level
= WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS
;
86 state
->req
->in
.ids
= ids
;
89 subreq
= dcerpc_winbind_get_idmap_r_send(state
,
93 if (composite_nomem(subreq
, ctx
)) return ctx
;
95 tevent_req_set_callback(subreq
, sids_to_xids_recv_ids
, state
);
100 static void sids_to_xids_recv_ids(struct tevent_req
*subreq
)
102 struct wbc_idmap_state
*state
=
103 tevent_req_callback_data(subreq
,
104 struct wbc_idmap_state
);
106 state
->ctx
->status
= dcerpc_winbind_get_idmap_r_recv(subreq
, state
);
108 if (!composite_is_ok(state
->ctx
)) return;
110 state
->ids
= state
->req
->out
.ids
;
111 composite_done(state
->ctx
);
114 NTSTATUS
wbc_sids_to_xids_recv(struct composite_context
*ctx
,
117 NTSTATUS status
= composite_wait(ctx
);
118 DEBUG(5, ("wbc_sids_to_xids_recv called\n"));
119 if (NT_STATUS_IS_OK(status
)) {
120 struct wbc_idmap_state
*state
= talloc_get_type_abort(
122 struct wbc_idmap_state
);
129 static void xids_to_sids_recv_ids(struct tevent_req
*subreq
);
131 struct composite_context
*wbc_xids_to_sids_send(struct wbc_context
*wbc_ctx
,
136 struct composite_context
*ctx
;
137 struct wbc_idmap_state
*state
;
138 struct tevent_req
*subreq
;
140 DEBUG(5, ("wbc_xids_to_sids called\n"));
142 ctx
= composite_create(mem_ctx
, wbc_ctx
->event_ctx
);
143 if (ctx
== NULL
) return NULL
;
145 state
= talloc(ctx
, struct wbc_idmap_state
);
146 if (composite_nomem(state
, ctx
)) return ctx
;
147 ctx
->private_data
= state
;
149 state
->req
= talloc(state
, struct winbind_get_idmap
);
150 if (composite_nomem(state
->req
, ctx
)) return ctx
;
152 state
->req
->in
.count
= count
;
153 state
->req
->in
.level
= WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS
;
154 state
->req
->in
.ids
= ids
;
157 subreq
= dcerpc_winbind_get_idmap_r_send(state
,
159 wbc_ctx
->irpc_handle
,
161 if (composite_nomem(subreq
, ctx
)) return ctx
;
163 tevent_req_set_callback(subreq
, xids_to_sids_recv_ids
, state
);
168 static void xids_to_sids_recv_ids(struct tevent_req
*subreq
)
170 struct wbc_idmap_state
*state
=
171 tevent_req_callback_data(subreq
,
172 struct wbc_idmap_state
);
174 state
->ctx
->status
= dcerpc_winbind_get_idmap_r_recv(subreq
, state
);
176 if (!composite_is_ok(state
->ctx
)) return;
178 state
->ids
= state
->req
->out
.ids
;
179 composite_done(state
->ctx
);
182 NTSTATUS
wbc_xids_to_sids_recv(struct composite_context
*ctx
,
185 NTSTATUS status
= composite_wait(ctx
);
186 DEBUG(5, ("wbc_xids_to_sids_recv called\n"));
187 if (NT_STATUS_IS_OK(status
)) {
188 struct wbc_idmap_state
*state
= talloc_get_type_abort(
190 struct wbc_idmap_state
);