winbind: Expose WINBINDD_XIDS_TO_SIDS externally
authorVolker Lendecke <vl@samba.org>
Fri, 14 Aug 2015 15:15:33 +0000 (17:15 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 22 Feb 2016 19:29:15 +0000 (20:29 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
nsswitch/winbind_struct_protocol.h
source3/winbindd/winbindd.c
source3/winbindd/winbindd_proto.h
source3/winbindd/winbindd_xids_to_sids.c [new file with mode: 0644]
source3/wscript_build

index 0dffa4be528c61ee208d2d07fc83b48080e3800a..178906d582b258dfbb1d2bed8fe8813b66b41a0b 100644 (file)
@@ -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,
 
index d555127b84514737ef1c181d0ff5b7eed0cf10a3..ec49ea508a81b0777967b586482e70210bd5e6cb 100644 (file)
@@ -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",
index f3c5c994957d44ae9ab5fbdbd8e829b9045a8c19..063e7930b2534773aced94601b2dd76f7f4b67fe 100644 (file)
@@ -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 (file)
index 0000000..d1424cd
--- /dev/null
@@ -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;
+}
index 67a787e7941237812d1f958446123c822e85b58e..a14551f0577325a8181a2fdc02217b7920c71d4e 100755 (executable)
@@ -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