Update account expiration to use new samdb_result_account_expires() function.
[Samba/kamenim.git] / source4 / winbind / wb_sid2uid.c
blob0de45fdea9b50065e1eb637490ee9a301ca51574
1 /*
2 Unix SMB/CIFS implementation.
4 Map a SID to a uid
6 Copyright (C) Kai Blin 2007-2008
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 "winbind/wb_helper.h"
27 #include "libcli/security/proto.h"
28 #include "winbind/idmap.h"
30 struct sid2uid_state {
31 struct composite_context *ctx;
32 struct wbsrv_service *service;
33 uid_t uid;
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;
40 struct sid2uid_state *state;
42 DEBUG(5, ("wb_sid2uid_send called\n"));
44 result = composite_create(mem_ctx, service->task->event_ctx);
45 if (!result) return NULL;
47 state = talloc(result, struct sid2uid_state);
48 if(composite_nomem(state, result)) return result;
50 state->ctx = result;
51 result->private_data = state;
52 state->service = service;
54 state->ctx->status = idmap_sid_to_uid(service->idmap_ctx, state, sid,
55 &state->uid);
56 if (NT_STATUS_EQUAL(state->ctx->status, NT_STATUS_RETRY)) {
57 state->ctx->status = idmap_sid_to_uid(service->idmap_ctx, state,
58 sid, &state->uid);
60 if (!composite_is_ok(state->ctx)) return result;
62 composite_done(state->ctx);
63 return result;
66 NTSTATUS wb_sid2uid_recv(struct composite_context *ctx, uid_t *uid)
68 NTSTATUS status = composite_wait(ctx);
70 DEBUG(5, ("wb_sid2uid_recv called\n"));
72 if (NT_STATUS_IS_OK(status)) {
73 struct sid2uid_state *state =
74 talloc_get_type(ctx->private_data,
75 struct sid2uid_state);
76 *uid = state->uid;
78 talloc_free(ctx);
79 return status;