diff options
author | Volker Lendecke <vl@samba.org> | 2015-08-14 17:15:33 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2016-02-22 20:29:15 +0100 |
commit | 5cd5ce70a14dc9a2c97532193f7a96aef53ba1a4 (patch) | |
tree | 4af66dfa37fc05d7854ae5a4a1a8422f7e6ef0ee | |
parent | e50c1a66486a6885fe644bce351e83d7d716f57d (diff) | |
download | samba-5cd5ce70a14dc9a2c97532193f7a96aef53ba1a4.tar.gz |
winbind: Expose WINBINDD_XIDS_TO_SIDS externally
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
-rw-r--r-- | nsswitch/winbind_struct_protocol.h | 4 | ||||
-rw-r--r-- | source3/winbindd/winbindd.c | 2 | ||||
-rw-r--r-- | source3/winbindd/winbindd_proto.h | 6 | ||||
-rw-r--r-- | source3/winbindd/winbindd_xids_to_sids.c | 136 | ||||
-rwxr-xr-x | source3/wscript_build | 1 |
5 files changed, 148 insertions, 1 deletions
diff --git a/nsswitch/winbind_struct_protocol.h b/nsswitch/winbind_struct_protocol.h index 0dffa4be528..178906d582b 100644 --- a/nsswitch/winbind_struct_protocol.h +++ b/nsswitch/winbind_struct_protocol.h @@ -53,8 +53,9 @@ typedef char fstring[FSTRING_LEN]; * removed WINBINDD_REMOVE_MAPPING * 26: added WINBINDD_DC_INFO * 27: added WINBINDD_LOOKUPSIDS + * 28: added WINBINDD_XIDS_TO_SIDS */ -#define WINBIND_INTERFACE_VERSION 27 +#define WINBIND_INTERFACE_VERSION 28 /* Have to deal with time_t being 4 or 8 bytes due to structure alignment. On a 64bit Linux box, we have to support a constant structure size @@ -113,6 +114,7 @@ enum winbindd_cmd { WINBINDD_SID_TO_UID, WINBINDD_SID_TO_GID, WINBINDD_SIDS_TO_XIDS, + WINBINDD_XIDS_TO_SIDS, WINBINDD_UID_TO_SID, WINBINDD_GID_TO_SID, diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index d555127b845..ec49ea508a8 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -618,6 +618,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = { winbindd_gid_to_sid_send, winbindd_gid_to_sid_recv }, { WINBINDD_SIDS_TO_XIDS, "SIDS_TO_XIDS", winbindd_sids_to_xids_send, winbindd_sids_to_xids_recv }, + { WINBINDD_XIDS_TO_SIDS, "XIDS_TO_SIDS", + winbindd_xids_to_sids_send, winbindd_xids_to_sids_recv }, { WINBINDD_GETPWSID, "GETPWSID", winbindd_getpwsid_send, winbindd_getpwsid_recv }, { WINBINDD_GETPWNAM, "GETPWNAM", diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index f3c5c994957..063e7930b25 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -912,6 +912,12 @@ struct tevent_req *wb_xids2sids_send(TALLOC_CTX *mem_ctx, uint32_t num_xids); NTSTATUS wb_xids2sids_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct dom_sid **sids); +struct tevent_req *winbindd_xids_to_sids_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct winbindd_cli_state *cli, + struct winbindd_request *request); +NTSTATUS winbindd_xids_to_sids_recv(struct tevent_req *req, + struct winbindd_response *response); struct tevent_req *winbindd_wins_byip_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct winbindd_cli_state *cli, diff --git a/source3/winbindd/winbindd_xids_to_sids.c b/source3/winbindd/winbindd_xids_to_sids.c new file mode 100644 index 00000000000..d1424cdb061 --- /dev/null +++ b/source3/winbindd/winbindd_xids_to_sids.c @@ -0,0 +1,136 @@ +/* + Unix SMB/CIFS implementation. + async implementation of WINBINDD_SIDS_TO_XIDS + Copyright (C) Volker Lendecke 2011 + Copyright (C) Michael Adam 2012 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "winbindd.h" +#include "../libcli/security/security.h" + + +struct winbindd_xids_to_sids_state { + struct tevent_context *ev; + + struct unixid *xids; + uint32_t num_xids; + + struct dom_sid *sids; +}; + +static void winbindd_xids_to_sids_done(struct tevent_req *subreq); + +struct tevent_req *winbindd_xids_to_sids_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct winbindd_cli_state *cli, + struct winbindd_request *request) +{ + struct tevent_req *req, *subreq; + struct winbindd_xids_to_sids_state *state; + + req = tevent_req_create(mem_ctx, &state, + struct winbindd_xids_to_sids_state); + if (req == NULL) { + return NULL; + } + state->ev = ev; + + DEBUG(3, ("xids_to_sids\n")); + + if (request->extra_len == 0) { + tevent_req_done(req); + return tevent_req_post(req, ev); + } + if (request->extra_data.data[request->extra_len-1] != '\0') { + DEBUG(10, ("Got invalid xids list\n")); + tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER); + return tevent_req_post(req, ev); + } + if (!parse_xidlist(state, request->extra_data.data, + &state->xids, &state->num_xids)) { + DEBUG(10, ("parse_sidlist failed\n")); + tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER); + return tevent_req_post(req, ev); + } + + DEBUG(10, ("num_xids: %d\n", (int)state->num_xids)); + + subreq = wb_xids2sids_send(state, ev, state->xids, state->num_xids); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, winbindd_xids_to_sids_done, req); + return req; +} + +static void winbindd_xids_to_sids_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct winbindd_xids_to_sids_state *state = tevent_req_data( + req, struct winbindd_xids_to_sids_state); + NTSTATUS status; + + status = wb_xids2sids_recv(subreq, state, &state->sids); + TALLOC_FREE(subreq); + if (tevent_req_nterror(req, status)) { + return; + } + tevent_req_done(req); +} + +NTSTATUS winbindd_xids_to_sids_recv(struct tevent_req *req, + struct winbindd_response *response) +{ + struct winbindd_xids_to_sids_state *state = tevent_req_data( + req, struct winbindd_xids_to_sids_state); + NTSTATUS status; + char *result = NULL; + uint32_t i; + + if (tevent_req_is_nterror(req, &status)) { + DEBUG(5, ("Could not convert sids: %s\n", nt_errstr(status))); + return status; + } + + result = talloc_strdup(response, ""); + if (result == NULL) { + return NT_STATUS_NO_MEMORY; + } + + for (i=0; i<state->num_xids; i++) { + char sidbuf[DOM_SID_STR_BUFLEN]; + + if (is_null_sid(&state->sids[i])) { + strlcpy(sidbuf, "-", sizeof(sidbuf)); + } else { + dom_sid_string_buf(&state->sids[i], + sidbuf, sizeof(sidbuf)); + } + + result = talloc_asprintf_append_buffer( + result, "%s\n", sidbuf); + if (result == NULL) { + return NT_STATUS_NO_MEMORY; + } + } + + response->extra_data.data = result; + response->length += talloc_get_size(result); + + return NT_STATUS_OK; +} diff --git a/source3/wscript_build b/source3/wscript_build index 67a787e7941..a14551f0577 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -951,6 +951,7 @@ bld.SAMBA3_BINARY('winbindd/winbindd', winbindd/winbindd_uid_to_sid.c winbindd/winbindd_gid_to_sid.c winbindd/winbindd_sids_to_xids.c + winbindd/winbindd_xids_to_sids.c winbindd/winbindd_allocate_uid.c winbindd/winbindd_allocate_gid.c winbindd/winbindd_getpwsid.c |