source: vendor/3.5.0/source4/winbind/wb_gid2sid.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 2.9 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 Command backend for wbinfo -G
5
6 Copyright (C) 2007-2008 Kai Blin
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#include "winbind/idmap.h"
29
30struct gid2sid_state {
31 struct composite_context *ctx;
32 struct wbsrv_service *service;
33 struct dom_sid *sid;
34};
35
36static void gid2sid_recv_sid(struct composite_context *ctx);
37
38struct composite_context *wb_gid2sid_send(TALLOC_CTX *mem_ctx,
39 struct wbsrv_service *service, gid_t gid)
40{
41 struct composite_context *result, *ctx;
42 struct gid2sid_state *state;
43 struct unixid *unixid;
44 struct id_mapping *ids;
45
46 DEBUG(5, ("wb_gid2sid_send called\n"));
47
48 result = composite_create(mem_ctx, service->task->event_ctx);
49 if (!result) return NULL;
50
51 state = talloc(result, struct gid2sid_state);
52 if (composite_nomem(state, result)) return result;
53
54 state->ctx = result;
55 result->private_data = state;
56 state->service = service;
57
58 unixid = talloc(result, struct unixid);
59 if (composite_nomem(unixid, result)) return result;
60 unixid->id = gid;
61 unixid->type = ID_TYPE_GID;
62
63 ids = talloc(result, struct id_mapping);
64 if (composite_nomem(ids, result)) return result;
65 ids->unixid = unixid;
66 ids->sid = NULL;
67
68 ctx = wb_xids2sids_send(result, service, 1, ids);
69 if (composite_nomem(ctx, result)) return result;
70
71 composite_continue(result, ctx, gid2sid_recv_sid, state);
72 return result;
73}
74
75static void gid2sid_recv_sid(struct composite_context *ctx)
76{
77 struct gid2sid_state *state = talloc_get_type(ctx->async.private_data,
78 struct gid2sid_state);
79 struct id_mapping *ids = NULL;
80 state->ctx->status = wb_xids2sids_recv(ctx, &ids);
81 if (!composite_is_ok(state->ctx)) return;
82
83 if (!NT_STATUS_IS_OK(ids->status)) {
84 composite_error(state->ctx, ids->status);
85 return;
86 }
87
88 state->sid = ids->sid;
89 composite_done(state->ctx);
90}
91
92NTSTATUS wb_gid2sid_recv(struct composite_context *ctx, TALLOC_CTX *mem_ctx,
93 struct dom_sid **sid)
94{
95 NTSTATUS status = composite_wait(ctx);
96
97 DEBUG(5, ("wb_gid2sid_recv called.\n"));
98
99 if (NT_STATUS_IS_OK(status)) {
100 struct gid2sid_state *state =
101 talloc_get_type(ctx->private_data,
102 struct gid2sid_state);
103 *sid = talloc_steal(mem_ctx, state->sid);
104 }
105 talloc_free(ctx);
106 return status;
107}
108
Note: See TracBrowser for help on using the repository browser.