s3:smbd: also create ncalrpc/np directory before forking rpc daemons
[Samba.git] / source4 / winbind / wb_sid2uid.c
blobf1d9bdd6779a89aa0dfd1cf66a472e46675d8ecb
1 /*
2 Unix SMB/CIFS implementation.
4 Map a SID to a uid
6 Copyright (C) 2007-2008 Kai Blin
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/>.
22 #include "includes.h"
23 #include "libcli/composite/composite.h"
24 #include "winbind/wb_server.h"
25 #include "smbd/service_task.h"
26 #include "libcli/security/security.h"
28 struct sid2uid_state {
29 struct composite_context *ctx;
30 struct wbsrv_service *service;
31 uid_t uid;
34 static void sid2uid_recv_uid(struct composite_context *ctx);
36 struct composite_context *wb_sid2uid_send(TALLOC_CTX *mem_ctx,
37 struct wbsrv_service *service, const struct dom_sid *sid)
39 struct composite_context *result, *ctx;
40 struct sid2uid_state *state;
41 struct id_map *ids;
43 DEBUG(5, ("wb_sid2uid_send called\n"));
45 result = composite_create(mem_ctx, service->task->event_ctx);
46 if (!result) return NULL;
48 state = talloc(result, struct sid2uid_state);
49 if (composite_nomem(state, result)) return result;
51 state->ctx = result;
52 result->private_data = state;
53 state->service = service;
55 ids = talloc(result, struct id_map);
56 if (composite_nomem(ids, result)) return result;
58 ids->sid = dom_sid_dup(result, sid);
59 if (composite_nomem(ids->sid, result)) return result;
61 ctx = wb_sids2xids_send(result, service, 1, ids);
62 if (composite_nomem(ctx, result)) return result;
64 composite_continue(result, ctx, sid2uid_recv_uid, state);
65 return result;
68 static void sid2uid_recv_uid(struct composite_context *ctx)
70 struct sid2uid_state *state = talloc_get_type(ctx->async.private_data,
71 struct sid2uid_state);
73 struct id_map *ids = NULL;
75 state->ctx->status = wb_sids2xids_recv(ctx, &ids, NULL);
76 if (!composite_is_ok(state->ctx)) return;
78 if (ids->status != ID_MAPPED) {
79 composite_error(state->ctx, NT_STATUS_UNSUCCESSFUL);
80 return;
83 if (ids->xid.type == ID_TYPE_BOTH ||
84 ids->xid.type == ID_TYPE_UID) {
85 state->uid = ids->xid.id;
86 composite_done(state->ctx);
87 } else {
88 composite_error(state->ctx, NT_STATUS_INVALID_SID);
92 NTSTATUS wb_sid2uid_recv(struct composite_context *ctx, uid_t *uid)
94 NTSTATUS status = composite_wait(ctx);
96 DEBUG(5, ("wb_sid2uid_recv called\n"));
98 if (NT_STATUS_IS_OK(status)) {
99 struct sid2uid_state *state =
100 talloc_get_type(ctx->private_data,
101 struct sid2uid_state);
102 *uid = state->uid;
104 talloc_free(ctx);
105 return status;