r24366: Implemet backend for wbinfo -Y, sid2gid
[ira/wip.git] / source / winbind / wb_sid2uid.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Map a SID to a uid
5
6    Copyright (C) Kai Blin 2007
7
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.
12
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.
17
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/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/composite/composite.h"
24 #include "winbind/wb_server.h"
25 #include "smbd/service_task.h"
26 #include "winbind/wb_helper.h"
27 #include "libcli/security/proto.h"
28
29 struct sid2uid_state {
30         struct composite_context *ctx;
31         struct wbsrv_service *service;
32         uid_t uid;
33 };
34
35 struct composite_context *wb_sid2uid_send(TALLOC_CTX *mem_ctx,
36                 struct wbsrv_service *service, const struct dom_sid *sid)
37 {
38         struct composite_context *result;
39         struct sid2uid_state *state;
40
41         DEBUG(5, ("wb_sid2uid_send called\n"));
42
43         result = composite_create(mem_ctx, service->task->event_ctx);
44         if (!result) return NULL;
45
46         state = talloc(result, struct sid2uid_state);
47         if(composite_nomem(state, result)) return result;
48
49         state->ctx = result;
50         result->private_data = state;
51         state->service = service;
52
53         /*FIXME: This is a stub so far. */
54         state->ctx->status = dom_sid_split_rid(result, sid, NULL, &state->uid);
55         if(!composite_is_ok(state->ctx)) return result;
56
57         DEBUG(5, ("Rid is %d\n", state->uid));
58
59         composite_done(state->ctx);
60         return result;
61 }
62
63 NTSTATUS wb_sid2uid_recv(struct composite_context *ctx, uid_t *uid)
64 {
65         NTSTATUS status = composite_wait(ctx);
66
67         DEBUG(5, ("wb_sid2uid_recv called\n"));
68
69         if (NT_STATUS_IS_OK(status)) {
70                 struct sid2uid_state *state =
71                         talloc_get_type(ctx->private_data,
72                                 struct sid2uid_state);
73                 *uid = state->uid;
74         }
75         talloc_free(ctx);
76         return status;
77 }
78