vfs_gpfs: Move call to load GPFS library
[Samba.git] / source3 / winbindd / winbindd_sids_to_xids.c
blob187b2994f277ac4516f39d432484e548ecfe15a7
1 /*
2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_SIDS_TO_XIDS
4 Copyright (C) Volker Lendecke 2011
5 Copyright (C) Michael Adam 2012
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "winbindd.h"
23 #include "../libcli/security/security.h"
26 struct winbindd_sids_to_xids_state {
27 struct tevent_context *ev;
28 struct dom_sid *sids;
29 uint32_t num_sids;
30 struct unixid *xids;
33 static void winbindd_sids_to_xids_done(struct tevent_req *subreq);
35 struct tevent_req *winbindd_sids_to_xids_send(TALLOC_CTX *mem_ctx,
36 struct tevent_context *ev,
37 struct winbindd_cli_state *cli,
38 struct winbindd_request *request)
40 struct tevent_req *req, *subreq;
41 struct winbindd_sids_to_xids_state *state;
43 req = tevent_req_create(mem_ctx, &state,
44 struct winbindd_sids_to_xids_state);
45 if (req == NULL) {
46 return NULL;
48 state->ev = ev;
50 D_NOTICE("[%s (%u)] Winbind external command SIDS_TO_XIDS start.\n",
51 cli->client_name,
52 (unsigned int)cli->pid);
54 if (request->extra_len == 0) {
55 tevent_req_done(req);
56 return tevent_req_post(req, ev);
58 if (request->extra_data.data[request->extra_len-1] != '\0') {
59 D_DEBUG("Got invalid sids list\n");
60 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
61 return tevent_req_post(req, ev);
63 if (!parse_sidlist(state, request->extra_data.data,
64 &state->sids, &state->num_sids)) {
65 D_DEBUG("parse_sidlist failed\n");
66 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
67 return tevent_req_post(req, ev);
70 D_DEBUG("Resolving %"PRIu32" SID(s).\n", state->num_sids);
72 subreq = wb_sids2xids_send(state, ev, state->sids, state->num_sids);
73 if (tevent_req_nomem(subreq, req)) {
74 return tevent_req_post(req, ev);
77 tevent_req_set_callback(subreq, winbindd_sids_to_xids_done, req);
78 return req;
81 static void winbindd_sids_to_xids_done(struct tevent_req *subreq)
83 struct tevent_req *req = tevent_req_callback_data(
84 subreq, struct tevent_req);
85 struct winbindd_sids_to_xids_state *state = tevent_req_data(
86 req, struct winbindd_sids_to_xids_state);
87 NTSTATUS status;
89 state->xids = talloc_zero_array(state, struct unixid, state->num_sids);
90 if (tevent_req_nomem(state->xids, req)) {
91 return;
94 status = wb_sids2xids_recv(subreq, state->xids, state->num_sids);
95 TALLOC_FREE(subreq);
96 if (tevent_req_nterror(req, status)) {
97 return;
99 tevent_req_done(req);
102 NTSTATUS winbindd_sids_to_xids_recv(struct tevent_req *req,
103 struct winbindd_response *response)
105 struct winbindd_sids_to_xids_state *state = tevent_req_data(
106 req, struct winbindd_sids_to_xids_state);
107 NTSTATUS status;
108 char *result = NULL;
109 uint32_t i;
111 D_NOTICE("Winbind external command SIDS_TO_XIDS end.\n");
112 if (tevent_req_is_nterror(req, &status)) {
113 D_WARNING("Could not convert sids: %s\n", nt_errstr(status));
114 return status;
117 result = talloc_strdup(response, "");
119 for (i=0; i<state->num_sids; i++) {
120 char type = '\0';
121 bool found = true;
122 struct unixid xid;
124 xid = state->xids[i];
126 switch (xid.type) {
127 case ID_TYPE_UID:
128 type = 'U';
129 break;
130 case ID_TYPE_GID:
131 type = 'G';
132 break;
133 case ID_TYPE_BOTH:
134 type = 'B';
135 break;
136 default:
137 found = false;
138 break;
141 if (xid.id == UINT32_MAX) {
142 found = false;
145 if (found) {
146 talloc_asprintf_addbuf(
147 &result,
148 "%c%lu\n",
149 type,
150 (unsigned long)xid.id);
151 } else {
152 talloc_asprintf_addbuf(&result, "\n");
156 if (result == NULL) {
157 return NT_STATUS_NO_MEMORY;
160 response->extra_data.data = result;
161 response->length += talloc_get_size(result);
163 return NT_STATUS_OK;