| 1 | /*
 | 
|---|
| 2 |    Unix SMB/CIFS implementation.
 | 
|---|
| 3 | 
 | 
|---|
| 4 |    Command backend for wbinfo -U
 | 
|---|
| 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 | 
 | 
|---|
| 27 | struct uid2sid_state {
 | 
|---|
| 28 |         struct composite_context *ctx;
 | 
|---|
| 29 |         struct wbsrv_service *service;
 | 
|---|
| 30 |         struct dom_sid *sid;
 | 
|---|
| 31 | };
 | 
|---|
| 32 | 
 | 
|---|
| 33 | static void uid2sid_recv_sid(struct composite_context *ctx);
 | 
|---|
| 34 | 
 | 
|---|
| 35 | struct composite_context *wb_uid2sid_send(TALLOC_CTX *mem_ctx,
 | 
|---|
| 36 |                 struct wbsrv_service *service, uid_t uid)
 | 
|---|
| 37 | {
 | 
|---|
| 38 |         struct composite_context *result, *ctx;
 | 
|---|
| 39 |         struct uid2sid_state *state;
 | 
|---|
| 40 |         struct id_map *ids;
 | 
|---|
| 41 | 
 | 
|---|
| 42 |         DEBUG(5, ("wb_uid2sid_send called\n"));
 | 
|---|
| 43 | 
 | 
|---|
| 44 |         result = composite_create(mem_ctx, service->task->event_ctx);
 | 
|---|
| 45 |         if (!result) return NULL;
 | 
|---|
| 46 | 
 | 
|---|
| 47 |         state = talloc(result, struct uid2sid_state);
 | 
|---|
| 48 |         if (composite_nomem(state, result)) return result;
 | 
|---|
| 49 | 
 | 
|---|
| 50 |         state->ctx = result;
 | 
|---|
| 51 |         result->private_data = state;
 | 
|---|
| 52 |         state->service = service;
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         ids = talloc(result, struct id_map);
 | 
|---|
| 55 |         if (composite_nomem(ids, result)) return result;
 | 
|---|
| 56 |         ids->sid = NULL;
 | 
|---|
| 57 |         ids->xid.id = uid;
 | 
|---|
| 58 |         ids->xid.type = ID_TYPE_UID;
 | 
|---|
| 59 | 
 | 
|---|
| 60 |         ctx = wb_xids2sids_send(result, service, 1, ids);
 | 
|---|
| 61 |         if (composite_nomem(ctx, result)) return result;
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         composite_continue(result, ctx, uid2sid_recv_sid, state);
 | 
|---|
| 64 |         return result;
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | static void uid2sid_recv_sid(struct composite_context *ctx)
 | 
|---|
| 68 | {
 | 
|---|
| 69 |         struct uid2sid_state *state = talloc_get_type(ctx->async.private_data,
 | 
|---|
| 70 |                                                       struct uid2sid_state);
 | 
|---|
| 71 |         struct id_map *ids = NULL;
 | 
|---|
| 72 | 
 | 
|---|
| 73 |         state->ctx->status = wb_xids2sids_recv(ctx, &ids);
 | 
|---|
| 74 |         if (!composite_is_ok(state->ctx)) return;
 | 
|---|
| 75 | 
 | 
|---|
| 76 |         if (ids->status != ID_MAPPED) {
 | 
|---|
| 77 |                 composite_error(state->ctx, NT_STATUS_UNSUCCESSFUL);
 | 
|---|
| 78 |                 return;
 | 
|---|
| 79 |         }
 | 
|---|
| 80 | 
 | 
|---|
| 81 |         state->sid = ids->sid;
 | 
|---|
| 82 | 
 | 
|---|
| 83 |         composite_done(state->ctx);
 | 
|---|
| 84 | }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | NTSTATUS wb_uid2sid_recv(struct composite_context *ctx, TALLOC_CTX *mem_ctx,
 | 
|---|
| 87 |                 struct dom_sid **sid)
 | 
|---|
| 88 | {
 | 
|---|
| 89 |         NTSTATUS status = composite_wait(ctx);
 | 
|---|
| 90 | 
 | 
|---|
| 91 |         DEBUG(5, ("wb_uid2sid_recv called.\n"));
 | 
|---|
| 92 | 
 | 
|---|
| 93 |         if (NT_STATUS_IS_OK(status)) {
 | 
|---|
| 94 |                 struct uid2sid_state *state =
 | 
|---|
| 95 |                         talloc_get_type(ctx->private_data,
 | 
|---|
| 96 |                                 struct uid2sid_state);
 | 
|---|
| 97 |                 *sid = talloc_steal(mem_ctx, state->sid);
 | 
|---|
| 98 |         }
 | 
|---|
| 99 |         talloc_free(ctx);
 | 
|---|
| 100 |         return status;
 | 
|---|
| 101 | }
 | 
|---|
| 102 | 
 | 
|---|