| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | Map SIDs to unixids.
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) 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 sids2xids_state {
|
|---|
| 28 | struct composite_context *ctx;
|
|---|
| 29 | struct wbsrv_service *service;
|
|---|
| 30 | struct id_map *ids;
|
|---|
| 31 | int count;
|
|---|
| 32 | };
|
|---|
| 33 |
|
|---|
| 34 | struct composite_context *wb_sids2xids_send(TALLOC_CTX *mem_ctx,
|
|---|
| 35 | struct wbsrv_service *service,
|
|---|
| 36 | unsigned int count, struct id_map *ids)
|
|---|
| 37 | {
|
|---|
| 38 | struct composite_context *result;
|
|---|
| 39 | struct sids2xids_state *state;
|
|---|
| 40 | struct id_map **pointer_array;
|
|---|
| 41 | unsigned int i;
|
|---|
| 42 |
|
|---|
| 43 | DEBUG(5, ("wb_sids2xids_send called\n"));
|
|---|
| 44 |
|
|---|
| 45 | result = composite_create(mem_ctx, service->task->event_ctx);
|
|---|
| 46 | if (!result) return NULL;
|
|---|
| 47 |
|
|---|
| 48 | state = talloc(result, struct sids2xids_state);
|
|---|
| 49 | if (composite_nomem(state, result)) return result;
|
|---|
| 50 |
|
|---|
| 51 | state->ctx = result;
|
|---|
| 52 | result->private_data = state;
|
|---|
| 53 | state->service = service;
|
|---|
| 54 | state->count = count;
|
|---|
| 55 | state->ids = ids;
|
|---|
| 56 |
|
|---|
| 57 | /* We need to convert between calling conventions here - the
|
|---|
| 58 | * values are filled in by reference, so we just need to
|
|---|
| 59 | * provide pointers to them */
|
|---|
| 60 | pointer_array = talloc_array(state, struct id_map *, count+1);
|
|---|
| 61 | if (composite_nomem(pointer_array, result)) return result;
|
|---|
| 62 |
|
|---|
| 63 | for (i=0; i < count; i++) {
|
|---|
| 64 | pointer_array[i] = &ids[i];
|
|---|
| 65 | }
|
|---|
| 66 | pointer_array[i] = NULL;
|
|---|
| 67 |
|
|---|
| 68 | state->ctx->status = idmap_sids_to_xids(service->idmap_ctx, mem_ctx,
|
|---|
| 69 | pointer_array);
|
|---|
| 70 | if (!composite_is_ok(state->ctx)) return result;
|
|---|
| 71 |
|
|---|
| 72 | composite_done(state->ctx);
|
|---|
| 73 | return result;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | NTSTATUS wb_sids2xids_recv(struct composite_context *ctx,
|
|---|
| 77 | struct id_map **ids)
|
|---|
| 78 | {
|
|---|
| 79 | NTSTATUS status = composite_wait(ctx);
|
|---|
| 80 | struct sids2xids_state *state = talloc_get_type(ctx->private_data,
|
|---|
| 81 | struct sids2xids_state);
|
|---|
| 82 |
|
|---|
| 83 | DEBUG(5, ("wb_sids2xids_recv called\n"));
|
|---|
| 84 |
|
|---|
| 85 | /* We don't have to mess with pointer_array on the way out, as
|
|---|
| 86 | * the results are filled into the pointers the caller
|
|---|
| 87 | * supplied */
|
|---|
| 88 | *ids = state->ids;
|
|---|
| 89 |
|
|---|
| 90 | talloc_free(ctx);
|
|---|
| 91 | return status;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|