[Samba] NT_STATUS_OBJECT_NAME_NOT_FOUND after installing the last git version

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Feb 18 02:18:30 MST 2014


On Tue, Feb 18, 2014 at 09:13:35PM +1300, Andrew Bartlett wrote:
> On Mon, 2014-02-17 at 23:21 +1100, Alain Foucher wrote:
> > Did i miss some issues ?
> 
> Thank you very much for bringing this to our attention. 

Attached find a patchset that reverts the offending code. As
I don't have the time today to deal with this in an
appropriate manner, please review & push this until we have
a resolution for the problem this code causes.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 85fc85e3e2743b2f5c7203f7196ac55d71bb301a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:12:28 +0000
Subject: [PATCH 01/15] Revert "winbind4: Remove unused winbind_get_idmap irpc
 operation"

This reverts commit 41ff0f4454ef23d0ac3e31560d78a2b966769fea.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/librpc/idl/winbind.idl |   24 ++++++++++++--
 source4/winbind/wb_irpc.c      |   72 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/source4/librpc/idl/winbind.idl b/source4/librpc/idl/winbind.idl
index f79eba7..d091a14 100644
--- a/source4/librpc/idl/winbind.idl
+++ b/source4/librpc/idl/winbind.idl
@@ -4,10 +4,10 @@
 
 #include "idl_types.h"
 
-import "netlogon.idl";
+import "netlogon.idl", "lsa.idl", "security.idl", "idmap.idl";
 
 [
-  uuid("b875118e-47a3-4210-b5f7-c240cce656b2"),
+  uuid("245f3e6b-3c5d-6e21-3a2d-2a3d645b7221"),
   version(1.0),
   pointer_default(unique)
 ]
@@ -16,6 +16,15 @@ interface winbind
 	typedef [switch_type(uint16)] union netr_LogonLevel netr_LogonLevel;
 	typedef [switch_type(uint16)] union netr_Validation netr_Validation;
 
+	/* a call to get runtime informations */
+	void winbind_information(/* TODO */);
+
+	/*
+	 * a call to trigger some internal events,
+	 * for use in torture tests...
+	 */
+	NTSTATUS winbind_remote_control(/* TODO */);
+
 	/*
 	 * do a netr_LogonSamLogon() against the right DC
 	 */
@@ -27,6 +36,17 @@ interface winbind
 		[out] uint8 authoritative
 	);
 
+	typedef [v1_enum] enum {
+		WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS	= 1,
+		WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS	= 2
+	} winbind_get_idmap_level;
+
+	NTSTATUS winbind_get_idmap(
+		[in]     winbind_get_idmap_level level,
+		[in]     uint32 count,
+		[in,out] [size_is(count)] id_map ids[]
+	);
+
 	NTSTATUS winbind_DsrUpdateReadOnlyServerDnsRecords(
 		[in,unique] [string,charset(UTF16)] uint16 *site_name,
 		[in] uint32 dns_ttl,
diff --git a/source4/winbind/wb_irpc.c b/source4/winbind/wb_irpc.c
index 7a4ca69..628114e 100644
--- a/source4/winbind/wb_irpc.c
+++ b/source4/winbind/wb_irpc.c
@@ -125,6 +125,74 @@ static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct tevent_req
 	irpc_send_reply(s->msg, status);
 }
 
+struct wb_irpc_get_idmap_state {
+	struct irpc_message *msg;
+	struct winbind_get_idmap *req;
+	int level;
+};
+
+static void wb_irpc_get_idmap_callback(struct composite_context *ctx);
+
+static NTSTATUS wb_irpc_get_idmap(struct irpc_message *msg,
+				  struct winbind_get_idmap *req)
+{
+	struct wbsrv_service *service = talloc_get_type(msg->private_data,
+					struct wbsrv_service);
+	struct wb_irpc_get_idmap_state *s;
+	struct composite_context *ctx = NULL;
+
+	DEBUG(5, ("wb_irpc_get_idmap called\n"));
+
+	s = talloc(msg, struct wb_irpc_get_idmap_state);
+	NT_STATUS_HAVE_NO_MEMORY(s);
+
+	s->msg = msg;
+	s->req = req;
+	s->level = req->in.level;
+
+	switch(s->level) {
+		case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
+			ctx = wb_sids2xids_send(msg, service, req->in.count,
+						req->in.ids);
+			break;
+		case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
+			ctx = wb_xids2sids_send(msg, service, req->in.count,
+						req->in.ids);
+			break;
+	}
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	composite_continue(ctx, ctx, wb_irpc_get_idmap_callback, s);
+	msg->defer_reply = true;
+
+	return NT_STATUS_OK;
+}
+
+static void wb_irpc_get_idmap_callback(struct composite_context *ctx)
+{
+	struct wb_irpc_get_idmap_state *s;
+	NTSTATUS status;
+
+	DEBUG(5, ("wb_irpc_get_idmap_callback called\n"));
+
+	s = talloc_get_type(ctx->async.private_data,
+			    struct wb_irpc_get_idmap_state);
+
+	switch(s->level) {
+		case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
+			status = wb_sids2xids_recv(ctx, &s->req->out.ids, NULL);
+			break;
+		case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
+			status = wb_xids2sids_recv(ctx, &s->req->out.ids);
+			break;
+		default:
+			status = NT_STATUS_INTERNAL_ERROR;
+			break;
+	}
+
+	irpc_send_reply(s->msg, status);
+}
+
 NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
 {
 	NTSTATUS status;
@@ -139,5 +207,9 @@ NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
 			       wb_irpc_DsrUpdateReadOnlyServerDnsRecords, service);
 	NT_STATUS_NOT_OK_RETURN(status);
 
+	status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
+			       wb_irpc_get_idmap, service);
+	NT_STATUS_NOT_OK_RETURN(status);
+
 	return NT_STATUS_OK;
 }
-- 
1.7.9.5


From c9c2806de0934201610df6eb5e8f08cc06c8037b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:13 +0100
Subject: [PATCH 02/15] Revert "auth4: Remove unused wbc_context"

This reverts commit 6b04558c5e0547a807ac0fcb5eeb1085cfe602ac.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/auth/auth.h                |    1 +
 source4/libcli/wbclient/wbclient.c |   29 +++++++++++++++++++++++++++++
 source4/libcli/wbclient/wbclient.h |   13 ++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/source4/auth/auth.h b/source4/auth/auth.h
index 129f58d3..503bae9 100644
--- a/source4/auth/auth.h
+++ b/source4/auth/auth.h
@@ -97,6 +97,7 @@ struct auth_critical_sizes {
 			   const struct auth_usersupplied_info *user_info_in,
 			   const struct auth_usersupplied_info **user_info_encrypted);
 
+struct wbc_context;
 #include "auth/session.h"
 #include "auth/unix_token_proto.h"
 #include "auth/system_session_proto.h"
diff --git a/source4/libcli/wbclient/wbclient.c b/source4/libcli/wbclient/wbclient.c
index 165333a..3f8003b 100644
--- a/source4/libcli/wbclient/wbclient.c
+++ b/source4/libcli/wbclient/wbclient.c
@@ -28,6 +28,35 @@
 #include "libcli/util/error.h"
 #include "libcli/security/dom_sid.h"
 
+/**
+ * Initialize the wbclient context, talloc_free() when done.
+ *
+ * \param mem_ctx talloc context to allocate memory from
+ * \param msg_ctx message context to use
+ * \param
+ */
+struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
+			     struct imessaging_context *msg_ctx,
+			     struct tevent_context *event_ctx)
+{
+	struct wbc_context *ctx;
+
+	ctx = talloc(mem_ctx, struct wbc_context);
+	if (ctx == NULL) return NULL;
+
+	ctx->event_ctx = event_ctx;
+
+	ctx->irpc_handle = irpc_binding_handle_by_name(ctx, msg_ctx,
+						       "winbind_server",
+						       &ndr_table_winbind);
+	if (ctx->irpc_handle == NULL) {
+		talloc_free(ctx);
+		return NULL;
+	}
+
+	return ctx;
+}
+
 static int wb_simple_trans(struct tevent_context *ev, int fd,
 			   struct winbindd_request *wb_req,
 			   TALLOC_CTX *mem_ctx,
diff --git a/source4/libcli/wbclient/wbclient.h b/source4/libcli/wbclient/wbclient.h
index fc096cc..ba15a7c 100644
--- a/source4/libcli/wbclient/wbclient.h
+++ b/source4/libcli/wbclient/wbclient.h
@@ -18,7 +18,18 @@
    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 "librpc/gen_ndr/idmap.h"
+#include "lib/messaging/irpc.h"
+#include "libcli/composite/composite.h"
+#include "librpc/gen_ndr/ndr_winbind_c.h"
+
+struct wbc_context {
+	struct tevent_context *event_ctx;
+	struct dcerpc_binding_handle *irpc_handle;
+};
+
+struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
+			     struct imessaging_context *msg_ctx,
+			     struct tevent_context *event_ctx);
 
 NTSTATUS wbc_sids_to_xids(struct tevent_context *ev, struct id_map *ids,
 			  uint32_t count);
-- 
1.7.9.5


From cb06d2c7bdf975d466acef13c413c2673ff49985 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:21 +0100
Subject: [PATCH 03/15] Revert "ntvfs_unixuid: No wbc_context required"

This reverts commit f35f88d741f1f896268649238d4ddbda4abb1585.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/ntvfs/unixuid/vfs_unixuid.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/source4/ntvfs/unixuid/vfs_unixuid.c b/source4/ntvfs/unixuid/vfs_unixuid.c
index 88f3b8b..97a5959 100644
--- a/source4/ntvfs/unixuid/vfs_unixuid.c
+++ b/source4/ntvfs/unixuid/vfs_unixuid.c
@@ -33,6 +33,7 @@
 NTSTATUS ntvfs_unixuid_init(void);
 
 struct unixuid_private {
+	struct wbc_context *wbc_ctx;
 	struct security_unix_token *last_sec_ctx;
 	struct security_token *last_token;
 };
@@ -240,6 +241,13 @@ static NTSTATUS unixuid_connect(struct ntvfs_module_context *ntvfs,
 		return NT_STATUS_NO_MEMORY;
 	}
 
+	priv->wbc_ctx = wbc_init(priv, ntvfs->ctx->msg_ctx,
+				    ntvfs->ctx->event_ctx);
+	if (priv->wbc_ctx == NULL) {
+		talloc_free(priv);
+		return NT_STATUS_INTERNAL_ERROR;
+	}
+
 	priv->last_sec_ctx = NULL;
 	priv->last_token = NULL;
 	ntvfs->private_data = priv;
-- 
1.7.9.5


From 48a3cd5b654f7a55573b5812a1788f393fa97769 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:28 +0100
Subject: [PATCH 04/15] Revert "ntvfs_posix: No wbc_context required"

This reverts commit 55dd08c4e80827ffc4fe423f3e67aec499af06df.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/ntvfs/posix/vfs_posix.c |    7 +++++++
 source4/ntvfs/posix/vfs_posix.h |    1 +
 2 files changed, 8 insertions(+)

diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c
index 72d0767..2ca024b 100644
--- a/source4/ntvfs/posix/vfs_posix.c
+++ b/source4/ntvfs/posix/vfs_posix.c
@@ -271,6 +271,13 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
 					   pvfs->ntvfs->ctx->event_ctx,
 					   pvfs->ntvfs->ctx->config);
 
+	pvfs->wbc_ctx = wbc_init(pvfs,
+				 pvfs->ntvfs->ctx->msg_ctx,
+				 pvfs->ntvfs->ctx->event_ctx);
+	if (pvfs->wbc_ctx == NULL) {
+		return NT_STATUS_INTERNAL_DB_CORRUPTION;
+	}
+
 	/* allocate the search handle -> ptr tree */
 	pvfs->search.idtree = idr_init(pvfs);
 	NT_STATUS_HAVE_NO_MEMORY(pvfs->search.idtree);
diff --git a/source4/ntvfs/posix/vfs_posix.h b/source4/ntvfs/posix/vfs_posix.h
index 04d78f2..9a03658 100644
--- a/source4/ntvfs/posix/vfs_posix.h
+++ b/source4/ntvfs/posix/vfs_posix.h
@@ -47,6 +47,7 @@ struct pvfs_state {
 	struct brl_context *brl_context;
 	struct odb_context *odb_context;
 	struct notify_context *notify_context;
+	struct wbc_context *wbc_ctx;
 
 	/* a list of pending async requests. Needed to support
 	   ntcancel */
-- 
1.7.9.5


From 8729f2daa6cd232df663e8205dffaa9a970c2d7f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:35 +0100
Subject: [PATCH 05/15] Revert "dcesrv_unixinfo: No wbc_context required"

This reverts commit 5a4252789b54b6b270b3083f6e0732ba1fdd774b.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/rpc_server/unixinfo/dcesrv_unixinfo.c |   36 ++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/source4/rpc_server/unixinfo/dcesrv_unixinfo.c b/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
index 10eda45..821f53c 100644
--- a/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
+++ b/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
@@ -25,11 +25,30 @@
 #include "libcli/wbclient/wbclient.h"
 #include "system/passwd.h"
 
+static NTSTATUS dcerpc_unixinfo_bind(struct dcesrv_call_state *dce_call,
+				     const struct dcesrv_interface *iface)
+{
+	struct wbc_context *wbc_ctx;
+
+	wbc_ctx = wbc_init(dce_call->context, dce_call->msg_ctx,
+			   dce_call->event_ctx);
+	NT_STATUS_HAVE_NO_MEMORY(wbc_ctx);
+
+	dce_call->context->private_data = wbc_ctx;
+
+	return NT_STATUS_OK;
+}
+
+#define DCESRV_INTERFACE_UNIXINFO_BIND dcerpc_unixinfo_bind
+
 static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
 				  TALLOC_CTX *mem_ctx,
 				  struct unixinfo_SidToUid *r)
 {
 	NTSTATUS status;
+	struct wbc_context *wbc_ctx = talloc_get_type_abort(
+						dce_call->context->private_data,
+						struct wbc_context);
 	struct id_map *ids;
 
 	DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
@@ -40,7 +59,7 @@ static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
 	ids->sid = &r->in.sid;
 	ids->status = ID_UNKNOWN;
 	ZERO_STRUCT(ids->xid);
-	status = wbc_sids_to_xids(dce_call->event_ctx, ids, 1);
+	status = wbc_sids_to_xids(wbc_ctx->event_ctx, ids, 1);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	if (ids->xid.type == ID_TYPE_BOTH ||
@@ -56,6 +75,9 @@ static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
 				  TALLOC_CTX *mem_ctx,
 				  struct unixinfo_UidToSid *r)
 {
+	struct wbc_context *wbc_ctx = talloc_get_type_abort(
+						dce_call->context->private_data,
+						struct wbc_context);
 	struct id_map *ids;
 	uint32_t uid;
 	NTSTATUS status;
@@ -77,7 +99,7 @@ static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
 	ids->xid.id = uid;
 	ids->xid.type = ID_TYPE_UID;
 
-	status = wbc_xids_to_sids(dce_call->event_ctx, ids, 1);
+	status = wbc_xids_to_sids(wbc_ctx->event_ctx, ids, 1);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	r->out.sid = ids->sid;
@@ -89,6 +111,9 @@ static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
 				  struct unixinfo_SidToGid *r)
 {
 	NTSTATUS status;
+	struct wbc_context *wbc_ctx = talloc_get_type_abort(
+						dce_call->context->private_data,
+						struct wbc_context);
 	struct id_map *ids;
 
 	DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
@@ -99,7 +124,7 @@ static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
 	ids->sid = &r->in.sid;
 	ids->status = ID_UNKNOWN;
 	ZERO_STRUCT(ids->xid);
-	status = wbc_sids_to_xids(dce_call->event_ctx, ids, 1);
+	status = wbc_sids_to_xids(wbc_ctx->event_ctx, ids, 1);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	if (ids->xid.type == ID_TYPE_BOTH ||
@@ -115,6 +140,9 @@ static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
 				  TALLOC_CTX *mem_ctx,
 				  struct unixinfo_GidToSid *r)
 {
+	struct wbc_context *wbc_ctx = talloc_get_type_abort(
+						dce_call->context->private_data,
+						struct wbc_context);
 	struct id_map *ids;
 	uint32_t gid;
 	NTSTATUS status;
@@ -136,7 +164,7 @@ static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
 	ids->xid.id = gid;
 	ids->xid.type = ID_TYPE_GID;
 
-	status = wbc_xids_to_sids(dce_call->event_ctx, ids, 1);
+	status = wbc_xids_to_sids(wbc_ctx->event_ctx, ids, 1);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	r->out.sid = ids->sid;
-- 
1.7.9.5


From b6940fd2499b9e71959858e336152c3a9cda62b3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:42 +0100
Subject: [PATCH 06/15] Revert "unixuid: Use the tevent_context from the
 ntvfs_context"

This reverts commit 25e83a9b3e72cdb84c09ef8ada4784efd110f09a.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/ntvfs/unixuid/vfs_unixuid.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/source4/ntvfs/unixuid/vfs_unixuid.c b/source4/ntvfs/unixuid/vfs_unixuid.c
index 97a5959..3d5c438 100644
--- a/source4/ntvfs/unixuid/vfs_unixuid.c
+++ b/source4/ntvfs/unixuid/vfs_unixuid.c
@@ -154,8 +154,10 @@ static NTSTATUS nt_token_to_unix_security(struct ntvfs_module_context *ntvfs,
 					  struct security_token *token,
 					  struct security_unix_token **sec)
 {
+	struct unixuid_private *priv = ntvfs->private_data;
+
 	return security_token_to_unix_token(req,
-					    ntvfs->ctx->event_ctx,
+					    priv->wbc_ctx->event_ctx,
 					    token, sec);
 }
 
-- 
1.7.9.5


From ba1c07b3a0c114d4a17d3017a0b7c51f1af9dd39 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:49 +0100
Subject: [PATCH 07/15] Revert "pvfs: Use the tevent_context from the
 ntvfs_context"

This reverts commit 15700a9f6e5393cecf78052f510e015300c5bd85.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/ntvfs/posix/pvfs_acl.c      |    8 ++++----
 source4/ntvfs/posix/pvfs_acl_nfs4.c |    5 ++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/source4/ntvfs/posix/pvfs_acl.c b/source4/ntvfs/posix/pvfs_acl.c
index 657e103..3ef66e1 100644
--- a/source4/ntvfs/posix/pvfs_acl.c
+++ b/source4/ntvfs/posix/pvfs_acl.c
@@ -169,7 +169,7 @@ static NTSTATUS pvfs_default_acl(struct pvfs_state *pvfs,
 	ids[1].xid.type = ID_TYPE_GID;
 	ids[1].sid = NULL;
 
-	status = wbc_xids_to_sids(pvfs->ntvfs->ctx->event_ctx, ids, 2);
+	status = wbc_xids_to_sids(pvfs->wbc_ctx->event_ctx, ids, 2);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	sd->owner_sid = talloc_steal(sd, ids[0].sid);
@@ -313,7 +313,7 @@ NTSTATUS pvfs_acl_set(struct pvfs_state *pvfs,
 		}
 		if (!dom_sid_equal(sd->owner_sid, new_sd->owner_sid)) {
 			ids->sid = new_sd->owner_sid;
-			status = wbc_sids_to_xids(pvfs->ntvfs->ctx->event_ctx,
+			status = wbc_sids_to_xids(pvfs->wbc_ctx->event_ctx,
 						  ids, 1);
 			NT_STATUS_NOT_OK_RETURN(status);
 
@@ -331,7 +331,7 @@ NTSTATUS pvfs_acl_set(struct pvfs_state *pvfs,
 		}
 		if (!dom_sid_equal(sd->group_sid, new_sd->group_sid)) {
 			ids->sid = new_sd->group_sid;
-			status = wbc_sids_to_xids(pvfs->ntvfs->ctx->event_ctx,
+			status = wbc_sids_to_xids(pvfs->wbc_ctx->event_ctx,
 						  ids, 1);
 			NT_STATUS_NOT_OK_RETURN(status);
 
@@ -969,7 +969,7 @@ NTSTATUS pvfs_acl_inherited_sd(struct pvfs_state *pvfs,
 	ids[1].sid = NULL;
 	ids[1].status = ID_UNKNOWN;
 
-	status = wbc_xids_to_sids(pvfs->ntvfs->ctx->event_ctx, ids, 2);
+	status = wbc_xids_to_sids(pvfs->wbc_ctx->event_ctx, ids, 2);
 	NT_STATUS_NOT_OK_RETURN_AND_FREE(status, tmp_ctx);
 
 	sd->owner_sid = talloc_steal(sd, ids[0].sid);
diff --git a/source4/ntvfs/posix/pvfs_acl_nfs4.c b/source4/ntvfs/posix/pvfs_acl_nfs4.c
index dbb43e2..272cdbc 100644
--- a/source4/ntvfs/posix/pvfs_acl_nfs4.c
+++ b/source4/ntvfs/posix/pvfs_acl_nfs4.c
@@ -90,7 +90,7 @@ static NTSTATUS pvfs_acl_load_nfs4(struct pvfs_state *pvfs, struct pvfs_filename
 
 	/* Allocate memory for the sids from the security descriptor to be on
 	 * the safe side. */
-	status = wbc_xids_to_sids(pvfs->ntvfs->ctx->event_ctx, ids, num_ids);
+	status = wbc_xids_to_sids(pvfs->wbc_ctx->event_ctx, ids, num_ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	sd->owner_sid = talloc_steal(sd, ids[0].sid);
@@ -155,8 +155,7 @@ static NTSTATUS pvfs_acl_save_nfs4(struct pvfs_state *pvfs, struct pvfs_filename
 		ids[i].status = ID_UNKNOWN;
 	}
 
-	status = wbc_sids_to_xids(pvfs->ntvfs->ctx->event_ctx, ids,
-				  acl.a_count);
+	status = wbc_sids_to_xids(pvfs->wbc_ctx->event_ctx, ids, acl.a_count);
 	if (!NT_STATUS_IS_OK(status)) {
 		talloc_free(tmp_ctx);
 		return status;
-- 
1.7.9.5


From 12630fecbba09d7749cf55ab320eaef0880c86ce Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:49:56 +0100
Subject: [PATCH 08/15] Revert "auth4: Do not generate just a temporary
 wbc_context"

This reverts commit 5124a9e1183de990ca3146cd355152094495a779.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/auth/ntlm/auth.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/source4/auth/ntlm/auth.c b/source4/auth/ntlm/auth.c
index ccfd20a..a8c257f 100644
--- a/source4/auth/ntlm/auth.c
+++ b/source4/auth/ntlm/auth.c
@@ -461,12 +461,21 @@ static NTSTATUS auth_generate_session_info_wrapper(struct auth4_context *auth_co
 
 	if ((session_info_flags & AUTH_SESSION_INFO_UNIX_TOKEN)
 	    && NT_STATUS_IS_OK(status)) {
-		status = auth_session_info_fill_unix(auth_context->event_ctx,
+		struct wbc_context *wbc_ctx = wbc_init(auth_context,
+						       auth_context->msg_ctx,
+						       auth_context->event_ctx);
+		if (!wbc_ctx) {
+			TALLOC_FREE(*session_info);
+			DEBUG(1, ("Cannot contact winbind to provide unix token\n"));
+			return NT_STATUS_INVALID_SERVER_STATE;
+		}
+		status = auth_session_info_fill_unix(wbc_ctx->event_ctx,
 						     auth_context->lp_ctx,
 						     original_user_name, *session_info);
 		if (!NT_STATUS_IS_OK(status)) {
 			TALLOC_FREE(*session_info);
 		}
+		TALLOC_FREE(wbc_ctx);
 	}
 	return status;
 }
-- 
1.7.9.5


From 4d134e0916ffd9144442f8a97498a0d685a17695 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:03 +0100
Subject: [PATCH 09/15] Revert "auth4: auth_session_info_fill_unix only needs
 a tevent_context"

This reverts commit 75d7c4609c1c743f84ca9f2d0666aece9e5200d4.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/auth/ntlm/auth.c  |    3 +--
 source4/auth/unix_token.c |    4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/source4/auth/ntlm/auth.c b/source4/auth/ntlm/auth.c
index a8c257f..263dc80 100644
--- a/source4/auth/ntlm/auth.c
+++ b/source4/auth/ntlm/auth.c
@@ -469,8 +469,7 @@ static NTSTATUS auth_generate_session_info_wrapper(struct auth4_context *auth_co
 			DEBUG(1, ("Cannot contact winbind to provide unix token\n"));
 			return NT_STATUS_INVALID_SERVER_STATE;
 		}
-		status = auth_session_info_fill_unix(wbc_ctx->event_ctx,
-						     auth_context->lp_ctx,
+		status = auth_session_info_fill_unix(wbc_ctx, auth_context->lp_ctx,
 						     original_user_name, *session_info);
 		if (!NT_STATUS_IS_OK(status)) {
 			TALLOC_FREE(*session_info);
diff --git a/source4/auth/unix_token.c b/source4/auth/unix_token.c
index efc9a9d..32f62a7 100644
--- a/source4/auth/unix_token.c
+++ b/source4/auth/unix_token.c
@@ -121,14 +121,14 @@ NTSTATUS security_token_to_unix_token(TALLOC_CTX *mem_ctx,
 /*
   Fill in the auth_user_info_unix and auth_unix_token elements in a struct session_info
 */
-NTSTATUS auth_session_info_fill_unix(struct tevent_context *ev,
+NTSTATUS auth_session_info_fill_unix(struct wbc_context *wbc_ctx,
 				     struct loadparm_context *lp_ctx,
 				     const char *original_user_name,
 				     struct auth_session_info *session_info)
 {
 	char *su;
 	size_t len;
-	NTSTATUS status = security_token_to_unix_token(session_info, ev,
+	NTSTATUS status = security_token_to_unix_token(session_info, wbc_ctx->event_ctx,
 						       session_info->security_token,
 						       &session_info->unix_token);
 	if (!NT_STATUS_IS_OK(status)) {
-- 
1.7.9.5


From b16c116efb4e2593271a85e5425119bf6a9d5e34 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:10 +0100
Subject: [PATCH 10/15] Revert "auth4: security_token_to_unix_token only needs
 a tevent_context"

This reverts commit 1de725c2926b526200032c4f46132c17533986c7.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/auth/unix_token.c           |    6 +++---
 source4/ntvfs/unixuid/vfs_unixuid.c |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/source4/auth/unix_token.c b/source4/auth/unix_token.c
index 32f62a7..aee950d 100644
--- a/source4/auth/unix_token.c
+++ b/source4/auth/unix_token.c
@@ -29,7 +29,7 @@
   form a security_unix_token from the current security_token
 */
 NTSTATUS security_token_to_unix_token(TALLOC_CTX *mem_ctx,
-				      struct tevent_context *ev,
+				      struct wbc_context *wbc_ctx,
 				      struct security_token *token,
 				      struct security_unix_token **sec)
 {
@@ -55,7 +55,7 @@ NTSTATUS security_token_to_unix_token(TALLOC_CTX *mem_ctx,
 		ids[s].status = ID_UNKNOWN;
 	}
 
-	status = wbc_sids_to_xids(ev, ids, token->num_sids);
+	status = wbc_sids_to_xids(wbc_ctx->event_ctx, ids, token->num_sids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	g = token->num_sids;
@@ -128,7 +128,7 @@ NTSTATUS auth_session_info_fill_unix(struct wbc_context *wbc_ctx,
 {
 	char *su;
 	size_t len;
-	NTSTATUS status = security_token_to_unix_token(session_info, wbc_ctx->event_ctx,
+	NTSTATUS status = security_token_to_unix_token(session_info, wbc_ctx,
 						       session_info->security_token,
 						       &session_info->unix_token);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source4/ntvfs/unixuid/vfs_unixuid.c b/source4/ntvfs/unixuid/vfs_unixuid.c
index 3d5c438..b6da790 100644
--- a/source4/ntvfs/unixuid/vfs_unixuid.c
+++ b/source4/ntvfs/unixuid/vfs_unixuid.c
@@ -157,7 +157,7 @@ static NTSTATUS nt_token_to_unix_security(struct ntvfs_module_context *ntvfs,
 	struct unixuid_private *priv = ntvfs->private_data;
 
 	return security_token_to_unix_token(req,
-					    priv->wbc_ctx->event_ctx,
+					    priv->wbc_ctx,
 					    token, sec);
 }
 
-- 
1.7.9.5


From e984dd08f37c30d663d3c9e3e59777674099adba Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:16 +0100
Subject: [PATCH 11/15] Revert "libwbclient4: Remove unused composite-based
 functions"

This reverts commit ba5f02739cb454d2312f73f643f2c119e090ac5e.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/libcli/wbclient/wbclient.c |  142 ++++++++++++++++++++++++++++++++++++
 source4/libcli/wbclient/wbclient.h |   16 ++++
 2 files changed, 158 insertions(+)

diff --git a/source4/libcli/wbclient/wbclient.c b/source4/libcli/wbclient/wbclient.c
index 3f8003b..8cfe117 100644
--- a/source4/libcli/wbclient/wbclient.c
+++ b/source4/libcli/wbclient/wbclient.c
@@ -57,6 +57,148 @@ struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
 	return ctx;
 }
 
+struct wbc_idmap_state {
+	struct composite_context *ctx;
+	struct winbind_get_idmap *req;
+	struct id_map *ids;
+};
+
+static void sids_to_xids_recv_ids(struct tevent_req *subreq);
+
+struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
+						TALLOC_CTX *mem_ctx,
+						uint32_t count,
+						struct id_map *ids)
+{
+	struct composite_context *ctx;
+	struct wbc_idmap_state *state;
+	struct tevent_req *subreq;
+
+	DEBUG(5, ("wbc_sids_to_xids called\n"));
+
+	ctx = composite_create(mem_ctx, wbc_ctx->event_ctx);
+	if (ctx == NULL) return NULL;
+
+	state = talloc(ctx, struct wbc_idmap_state);
+	if (composite_nomem(state, ctx)) return ctx;
+	ctx->private_data = state;
+
+	state->req = talloc(state, struct winbind_get_idmap);
+	if (composite_nomem(state->req, ctx)) return ctx;
+
+	state->req->in.count = count;
+	state->req->in.level = WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS;
+	state->req->in.ids = ids;
+	state->ctx = ctx;
+
+	subreq = dcerpc_winbind_get_idmap_r_send(state,
+						 wbc_ctx->event_ctx,
+						 wbc_ctx->irpc_handle,
+						 state->req);
+	if (composite_nomem(subreq, ctx)) return ctx;
+
+	tevent_req_set_callback(subreq, sids_to_xids_recv_ids, state);
+
+	return ctx;
+}
+
+static void sids_to_xids_recv_ids(struct tevent_req *subreq)
+{
+	struct wbc_idmap_state *state =
+		tevent_req_callback_data(subreq,
+		struct wbc_idmap_state);
+
+	state->ctx->status = dcerpc_winbind_get_idmap_r_recv(subreq, state);
+	TALLOC_FREE(subreq);
+	if (!composite_is_ok(state->ctx)) return;
+
+	state->ids = state->req->out.ids;
+	composite_done(state->ctx);
+}
+
+NTSTATUS wbc_sids_to_xids_recv(struct composite_context *ctx,
+			       struct id_map **ids)
+{
+	NTSTATUS status = composite_wait(ctx);
+		DEBUG(5, ("wbc_sids_to_xids_recv called\n"));
+	if (NT_STATUS_IS_OK(status)) {
+		struct wbc_idmap_state *state =	talloc_get_type_abort(
+							ctx->private_data,
+							struct wbc_idmap_state);
+		*ids = state->ids;
+	}
+
+	return status;
+}
+
+static void xids_to_sids_recv_ids(struct tevent_req *subreq);
+
+struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
+						TALLOC_CTX *mem_ctx,
+						uint32_t count,
+						struct id_map *ids)
+{
+	struct composite_context *ctx;
+	struct wbc_idmap_state *state;
+	struct tevent_req *subreq;
+
+	DEBUG(5, ("wbc_xids_to_sids called\n"));
+
+	ctx = composite_create(mem_ctx, wbc_ctx->event_ctx);
+	if (ctx == NULL) return NULL;
+
+	state = talloc(ctx, struct wbc_idmap_state);
+	if (composite_nomem(state, ctx)) return ctx;
+	ctx->private_data = state;
+
+	state->req = talloc(state, struct winbind_get_idmap);
+	if (composite_nomem(state->req, ctx)) return ctx;
+
+	state->req->in.count = count;
+	state->req->in.level = WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS;
+	state->req->in.ids = ids;
+	state->ctx = ctx;
+
+	subreq = dcerpc_winbind_get_idmap_r_send(state,
+						 wbc_ctx->event_ctx,
+						 wbc_ctx->irpc_handle,
+						 state->req);
+	if (composite_nomem(subreq, ctx)) return ctx;
+
+	tevent_req_set_callback(subreq, xids_to_sids_recv_ids, state);
+
+	return ctx;
+}
+
+static void xids_to_sids_recv_ids(struct tevent_req *subreq)
+{
+	struct wbc_idmap_state *state =
+		tevent_req_callback_data(subreq,
+		struct wbc_idmap_state);
+
+	state->ctx->status = dcerpc_winbind_get_idmap_r_recv(subreq, state);
+	TALLOC_FREE(subreq);
+	if (!composite_is_ok(state->ctx)) return;
+
+	state->ids = state->req->out.ids;
+	composite_done(state->ctx);
+}
+
+NTSTATUS wbc_xids_to_sids_recv(struct composite_context *ctx,
+			       struct id_map **ids)
+{
+	NTSTATUS status = composite_wait(ctx);
+		DEBUG(5, ("wbc_xids_to_sids_recv called\n"));
+	if (NT_STATUS_IS_OK(status)) {
+		struct wbc_idmap_state *state =	talloc_get_type_abort(
+							ctx->private_data,
+							struct wbc_idmap_state);
+		*ids = state->ids;
+	}
+
+	return status;
+}
+
 static int wb_simple_trans(struct tevent_context *ev, int fd,
 			   struct winbindd_request *wb_req,
 			   TALLOC_CTX *mem_ctx,
diff --git a/source4/libcli/wbclient/wbclient.h b/source4/libcli/wbclient/wbclient.h
index ba15a7c..33a21f3 100644
--- a/source4/libcli/wbclient/wbclient.h
+++ b/source4/libcli/wbclient/wbclient.h
@@ -31,8 +31,24 @@ struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
 			     struct imessaging_context *msg_ctx,
 			     struct tevent_context *event_ctx);
 
+struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
+						TALLOC_CTX *mem_ctx,
+						uint32_t count,
+						struct id_map *ids);
+
+NTSTATUS wbc_sids_to_xids_recv(struct composite_context *ctx,
+			       struct id_map **ids);
+
 NTSTATUS wbc_sids_to_xids(struct tevent_context *ev, struct id_map *ids,
 			  uint32_t count);
 
+struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
+						TALLOC_CTX *mem_ctx,
+						uint32_t count,
+						struct id_map *ids);
+
+NTSTATUS wbc_xids_to_sids_recv(struct composite_context *ctx,
+			       struct id_map **ids);
+
 NTSTATUS wbc_xids_to_sids(struct tevent_context *ev, struct id_map *ids,
 			  uint32_t count);
-- 
1.7.9.5


From 1288901710b8b08683506ee76fae57d9c7737bb0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:23 +0100
Subject: [PATCH 12/15] Revert "source4: Use wbc_xids_to_sids"

This reverts commit d0932a1ae089fda0d41be21a9916caeca7c0c233.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/ntvfs/posix/pvfs_acl.c                |   12 ++++++++++--
 source4/ntvfs/posix/pvfs_acl_nfs4.c           |    5 ++++-
 source4/rpc_server/unixinfo/dcesrv_unixinfo.c |   12 ++++++++++--
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/source4/ntvfs/posix/pvfs_acl.c b/source4/ntvfs/posix/pvfs_acl.c
index 3ef66e1..2070fd1 100644
--- a/source4/ntvfs/posix/pvfs_acl.c
+++ b/source4/ntvfs/posix/pvfs_acl.c
@@ -151,6 +151,7 @@ static NTSTATUS pvfs_default_acl(struct pvfs_state *pvfs,
 	struct security_ace ace;
 	mode_t mode;
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	*psd = security_descriptor_initialise(req);
 	if (*psd == NULL) {
@@ -169,7 +170,10 @@ static NTSTATUS pvfs_default_acl(struct pvfs_state *pvfs,
 	ids[1].xid.type = ID_TYPE_GID;
 	ids[1].sid = NULL;
 
-	status = wbc_xids_to_sids(pvfs->wbc_ctx->event_ctx, ids, 2);
+	ctx = wbc_xids_to_sids_send(pvfs->wbc_ctx, ids, 2, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	status = wbc_xids_to_sids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	sd->owner_sid = talloc_steal(sd, ids[0].sid);
@@ -921,6 +925,7 @@ NTSTATUS pvfs_acl_inherited_sd(struct pvfs_state *pvfs,
 	NTSTATUS status;
 	struct security_descriptor *parent_sd, *sd;
 	struct id_map *ids;
+	struct composite_context *ctx;
 	TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
 
 	*ret_sd = NULL;
@@ -969,7 +974,10 @@ NTSTATUS pvfs_acl_inherited_sd(struct pvfs_state *pvfs,
 	ids[1].sid = NULL;
 	ids[1].status = ID_UNKNOWN;
 
-	status = wbc_xids_to_sids(pvfs->wbc_ctx->event_ctx, ids, 2);
+	ctx = wbc_xids_to_sids_send(pvfs->wbc_ctx, ids, 2, ids);
+	NT_STATUS_HAVE_NO_MEMORY_AND_FREE(ctx, tmp_ctx);
+
+	status = wbc_xids_to_sids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN_AND_FREE(status, tmp_ctx);
 
 	sd->owner_sid = talloc_steal(sd, ids[0].sid);
diff --git a/source4/ntvfs/posix/pvfs_acl_nfs4.c b/source4/ntvfs/posix/pvfs_acl_nfs4.c
index 272cdbc..bf4d9c2 100644
--- a/source4/ntvfs/posix/pvfs_acl_nfs4.c
+++ b/source4/ntvfs/posix/pvfs_acl_nfs4.c
@@ -42,6 +42,7 @@ static NTSTATUS pvfs_acl_load_nfs4(struct pvfs_state *pvfs, struct pvfs_filename
 	struct security_descriptor *sd;
 	int i, num_ids;
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	acl = talloc_zero(mem_ctx, struct nfs4acl);
 	NT_STATUS_HAVE_NO_MEMORY(acl);
@@ -90,7 +91,9 @@ static NTSTATUS pvfs_acl_load_nfs4(struct pvfs_state *pvfs, struct pvfs_filename
 
 	/* Allocate memory for the sids from the security descriptor to be on
 	 * the safe side. */
-	status = wbc_xids_to_sids(pvfs->wbc_ctx->event_ctx, ids, num_ids);
+	ctx = wbc_xids_to_sids_send(pvfs->wbc_ctx, sd, num_ids, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+	status = wbc_xids_to_sids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	sd->owner_sid = talloc_steal(sd, ids[0].sid);
diff --git a/source4/rpc_server/unixinfo/dcesrv_unixinfo.c b/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
index 821f53c..260d5ab 100644
--- a/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
+++ b/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
@@ -79,6 +79,7 @@ static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
 						dce_call->context->private_data,
 						struct wbc_context);
 	struct id_map *ids;
+	struct composite_context *ctx;
 	uint32_t uid;
 	NTSTATUS status;
 
@@ -99,7 +100,10 @@ static NTSTATUS dcesrv_unixinfo_UidToSid(struct dcesrv_call_state *dce_call,
 	ids->xid.id = uid;
 	ids->xid.type = ID_TYPE_UID;
 
-	status = wbc_xids_to_sids(wbc_ctx->event_ctx, ids, 1);
+	ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	status = wbc_xids_to_sids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	r->out.sid = ids->sid;
@@ -144,6 +148,7 @@ static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
 						dce_call->context->private_data,
 						struct wbc_context);
 	struct id_map *ids;
+	struct composite_context *ctx;
 	uint32_t gid;
 	NTSTATUS status;
 
@@ -164,7 +169,10 @@ static NTSTATUS dcesrv_unixinfo_GidToSid(struct dcesrv_call_state *dce_call,
 	ids->xid.id = gid;
 	ids->xid.type = ID_TYPE_GID;
 
-	status = wbc_xids_to_sids(wbc_ctx->event_ctx, ids, 1);
+	ctx = wbc_xids_to_sids_send(wbc_ctx, ids, 1, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	status = wbc_xids_to_sids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	r->out.sid = ids->sid;
-- 
1.7.9.5


From aa3a574b6ca79d380583d3ea8560eac7401d254b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:30 +0100
Subject: [PATCH 13/15] Revert "libwbclient4: Add wbc_xids_to_sids"

This reverts commit f275ce4e4367478b488810491c7bcd993c37caf1.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/libcli/wbclient/wbclient.c |  215 ------------------------------------
 1 file changed, 215 deletions(-)

diff --git a/source4/libcli/wbclient/wbclient.c b/source4/libcli/wbclient/wbclient.c
index 8cfe117..5b95be1 100644
--- a/source4/libcli/wbclient/wbclient.c
+++ b/source4/libcli/wbclient/wbclient.c
@@ -21,7 +21,6 @@
 
 #include "includes.h"
 #include <tevent.h>
-#include "lib/util/tevent_unix.h"
 #include "libcli/wbclient/wbclient.h"
 #include "nsswitch/wb_reqtrans.h"
 #include "system/network.h"
@@ -362,217 +361,3 @@ NTSTATUS wbc_sids_to_xids(struct tevent_context *ev, struct id_map *ids,
 
 	return NT_STATUS_OK;
 }
-
-struct wbc_id_to_sid_state {
-	struct winbindd_request wbreq;
-	struct dom_sid sid;
-};
-
-static void wbc_id_to_sid_done(struct tevent_req *subreq);
-
-static struct tevent_req *wbc_id_to_sid_send(TALLOC_CTX *mem_ctx,
-					     struct tevent_context *ev,
-					     int fd, const struct unixid *id)
-{
-	struct tevent_req *req, *subreq;
-	struct wbc_id_to_sid_state *state;
-
-	req = tevent_req_create(mem_ctx, &state, struct wbc_id_to_sid_state);
-	if (req == NULL) {
-		return NULL;
-	}
-
-	switch(id->type) {
-	case ID_TYPE_UID:
-		state->wbreq.cmd = WINBINDD_UID_TO_SID;
-		state->wbreq.data.uid = id->id;
-		break;
-	case ID_TYPE_GID:
-		state->wbreq.cmd = WINBINDD_GID_TO_SID;
-		state->wbreq.data.gid = id->id;
-		break;
-	default:
-		tevent_req_error(req, ENOENT);
-		return tevent_req_post(req, ev);
-	}
-
-	subreq = wb_simple_trans_send(state, ev, NULL, fd, &state->wbreq);
-	if (tevent_req_nomem(subreq, req)) {
-		return tevent_req_post(req, ev);
-	}
-	tevent_req_set_callback(subreq, wbc_id_to_sid_done, req);
-	return req;
-}
-
-static void wbc_id_to_sid_done(struct tevent_req *subreq)
-{
-	struct tevent_req *req = tevent_req_callback_data(
-		subreq, struct tevent_req);
-	struct wbc_id_to_sid_state *state = tevent_req_data(
-		req, struct wbc_id_to_sid_state);
-	struct winbindd_response *wbresp;
-	int ret, err;
-
-	ret = wb_simple_trans_recv(subreq, state, &wbresp, &err);
-	TALLOC_FREE(subreq);
-	if (ret == -1) {
-		tevent_req_error(req, err);
-		return;
-	}
-	if ((wbresp->result != WINBINDD_OK) ||
-	    !dom_sid_parse(wbresp->data.sid.sid, &state->sid)) {
-		tevent_req_error(req, ENOENT);
-		return;
-	}
-	tevent_req_done(req);
-}
-
-static int wbc_id_to_sid_recv(struct tevent_req *req, struct dom_sid *sid)
-{
-	struct wbc_id_to_sid_state *state = tevent_req_data(
-		req, struct wbc_id_to_sid_state);
-	int err;
-
-	if (tevent_req_is_unix_error(req, &err)) {
-		return err;
-	}
-	sid_copy(sid, &state->sid);
-	return 0;
-}
-
-struct wbc_ids_to_sids_state {
-	struct tevent_context *ev;
-	int fd;
-	struct id_map *ids;
-	uint32_t count;
-	uint32_t idx;
-};
-
-static void wbc_ids_to_sids_done(struct tevent_req *subreq);
-
-static struct tevent_req *wbc_ids_to_sids_send(
-	TALLOC_CTX *mem_ctx, struct tevent_context *ev,
-	int fd, struct id_map *ids, uint32_t count)
-{
-	struct tevent_req *req, *subreq;
-	struct wbc_ids_to_sids_state *state;
-
-	req = tevent_req_create(mem_ctx, &state,
-				struct wbc_ids_to_sids_state);
-	if (req == NULL) {
-		return NULL;
-	}
-	state->ev = ev;
-	state->fd = fd;
-	state->ids = ids;
-	state->count = count;
-
-	if (count == 0) {
-		tevent_req_done(req);
-		return tevent_req_post(req, ev);
-	}
-
-	subreq = wbc_id_to_sid_send(state, state->ev, state->fd,
-				    &state->ids[state->idx].xid);
-	if (tevent_req_nomem(subreq, req)) {
-		return tevent_req_post(req, ev);
-	}
-	tevent_req_set_callback(subreq, wbc_ids_to_sids_done, req);
-	return req;
-}
-
-static void wbc_ids_to_sids_done(struct tevent_req *subreq)
-{
-	struct tevent_req *req = tevent_req_callback_data(
-		subreq, struct tevent_req);
-	struct wbc_ids_to_sids_state *state = tevent_req_data(
-		req, struct wbc_ids_to_sids_state);
-	struct id_map *id;
-	struct dom_sid sid;
-	int ret;
-
-	ret = wbc_id_to_sid_recv(subreq, &sid);
-	TALLOC_FREE(subreq);
-
-	id = &state->ids[state->idx];
-	if (ret == 0) {
-		id->status = ID_MAPPED;
-		id->sid = dom_sid_dup(state->ids, &sid);
-		if (id->sid == NULL) {
-			tevent_req_error(req, ENOMEM);
-			return;
-		}
-	} else {
-		id->status = ID_UNMAPPED;
-		id->sid = NULL;
-	}
-
-	state->idx += 1;
-	if (state->idx == state->count) {
-		tevent_req_done(req);
-		return;
-	}
-
-	subreq = wbc_id_to_sid_send(state, state->ev, state->fd,
-				    &state->ids[state->idx].xid);
-	if (tevent_req_nomem(subreq, req)) {
-		return;
-	}
-	tevent_req_set_callback(subreq, wbc_ids_to_sids_done, req);
-}
-
-static int wbc_ids_to_sids_recv(struct tevent_req *req)
-{
-	int err;
-	if (tevent_req_is_unix_error(req, &err)) {
-		return err;
-	}
-	return 0;
-}
-
-NTSTATUS wbc_xids_to_sids(struct tevent_context *ev, struct id_map *ids,
-			  uint32_t count)
-{
-	struct tevent_req *req;
-	NTSTATUS status;
-	bool polled;
-	int ret, fd;
-
-	DEBUG(5, ("wbc_xids_to_sids called: %u ids\n", (unsigned)count));
-
-	fd = winbindd_pipe_sock();
-	if (fd == -1) {
-		status = map_nt_error_from_unix_common(errno);
-		DEBUG(10, ("winbindd_pipe_sock returned %s\n",
-			   strerror(errno)));
-		return status;
-	}
-
-	req = wbc_ids_to_sids_send(ev, ev, fd, ids, count);
-	if (req == NULL) {
-		status = NT_STATUS_NO_MEMORY;
-		goto done;
-	}
-
-	polled = tevent_req_poll(req, ev);
-	if (!polled) {
-		status = map_nt_error_from_unix_common(errno);
-		DEBUG(10, ("tevent_req_poll returned %s\n",
-			   strerror(errno)));
-		goto done;
-	}
-
-	ret = wbc_ids_to_sids_recv(req);
-	TALLOC_FREE(req);
-	if (ret != 0) {
-		status = map_nt_error_from_unix_common(ret);
-		DEBUG(10, ("tevent_req_poll returned %s\n",
-			   strerror(ret)));
-	} else {
-		status = NT_STATUS_OK;
-	}
-
-done:
-	close(fd);
-	return status;
-}
-- 
1.7.9.5


From 203c9b144fdf322db0aaba534a554390aeafb2aa Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:37 +0100
Subject: [PATCH 14/15] Revert "source4: Use wbc_sids_to_xids"

This reverts commit de7122ddc356697777cce95d22b3fab7697b30db.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/auth/unix_token.c                     |    6 +++++-
 source4/ntvfs/posix/pvfs_acl.c                |   11 +++++++----
 source4/ntvfs/posix/pvfs_acl_nfs4.c           |    8 +++++++-
 source4/rpc_server/unixinfo/dcesrv_unixinfo.c |   12 ++++++++++--
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/source4/auth/unix_token.c b/source4/auth/unix_token.c
index aee950d..3810945 100644
--- a/source4/auth/unix_token.c
+++ b/source4/auth/unix_token.c
@@ -36,6 +36,7 @@ NTSTATUS security_token_to_unix_token(TALLOC_CTX *mem_ctx,
 	uint32_t s, g;
 	NTSTATUS status;
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	/* we can't do unix security without a user and group */
 	if (token->num_sids < 2) {
@@ -55,7 +56,10 @@ NTSTATUS security_token_to_unix_token(TALLOC_CTX *mem_ctx,
 		ids[s].status = ID_UNKNOWN;
 	}
 
-	status = wbc_sids_to_xids(wbc_ctx->event_ctx, ids, token->num_sids);
+	ctx = wbc_sids_to_xids_send(wbc_ctx, ids, token->num_sids, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	status = wbc_sids_to_xids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	g = token->num_sids;
diff --git a/source4/ntvfs/posix/pvfs_acl.c b/source4/ntvfs/posix/pvfs_acl.c
index 2070fd1..730ad48 100644
--- a/source4/ntvfs/posix/pvfs_acl.c
+++ b/source4/ntvfs/posix/pvfs_acl.c
@@ -287,6 +287,7 @@ NTSTATUS pvfs_acl_set(struct pvfs_state *pvfs,
 	uid_t new_uid = -1;
 	gid_t new_gid = -1;
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	if (pvfs->acl_ops != NULL) {
 		status = pvfs->acl_ops->acl_load(pvfs, name, fd, req, &sd);
@@ -317,8 +318,9 @@ NTSTATUS pvfs_acl_set(struct pvfs_state *pvfs,
 		}
 		if (!dom_sid_equal(sd->owner_sid, new_sd->owner_sid)) {
 			ids->sid = new_sd->owner_sid;
-			status = wbc_sids_to_xids(pvfs->wbc_ctx->event_ctx,
-						  ids, 1);
+			ctx = wbc_sids_to_xids_send(pvfs->wbc_ctx, ids, 1, ids);
+			NT_STATUS_HAVE_NO_MEMORY(ctx);
+			status = wbc_sids_to_xids_recv(ctx, &ids);
 			NT_STATUS_NOT_OK_RETURN(status);
 
 			if (ids->xid.type == ID_TYPE_BOTH ||
@@ -335,8 +337,9 @@ NTSTATUS pvfs_acl_set(struct pvfs_state *pvfs,
 		}
 		if (!dom_sid_equal(sd->group_sid, new_sd->group_sid)) {
 			ids->sid = new_sd->group_sid;
-			status = wbc_sids_to_xids(pvfs->wbc_ctx->event_ctx,
-						  ids, 1);
+			ctx = wbc_sids_to_xids_send(pvfs->wbc_ctx, ids, 1, ids);
+			NT_STATUS_HAVE_NO_MEMORY(ctx);
+			status = wbc_sids_to_xids_recv(ctx, &ids);
 			NT_STATUS_NOT_OK_RETURN(status);
 
 			if (ids->xid.type == ID_TYPE_BOTH ||
diff --git a/source4/ntvfs/posix/pvfs_acl_nfs4.c b/source4/ntvfs/posix/pvfs_acl_nfs4.c
index bf4d9c2..bb88cbc 100644
--- a/source4/ntvfs/posix/pvfs_acl_nfs4.c
+++ b/source4/ntvfs/posix/pvfs_acl_nfs4.c
@@ -124,6 +124,7 @@ static NTSTATUS pvfs_acl_save_nfs4(struct pvfs_state *pvfs, struct pvfs_filename
 	int i;
 	TALLOC_CTX *tmp_ctx;
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	tmp_ctx = talloc_new(pvfs);
 	NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
@@ -158,7 +159,12 @@ static NTSTATUS pvfs_acl_save_nfs4(struct pvfs_state *pvfs, struct pvfs_filename
 		ids[i].status = ID_UNKNOWN;
 	}
 
-	status = wbc_sids_to_xids(pvfs->wbc_ctx->event_ctx, ids, acl.a_count);
+	ctx = wbc_sids_to_xids_send(pvfs->wbc_ctx,ids, acl.a_count, ids);
+	if (ctx == NULL) {
+		talloc_free(tmp_ctx);
+		return NT_STATUS_NO_MEMORY;
+	}
+	status = wbc_sids_to_xids_recv(ctx, &ids);
 	if (!NT_STATUS_IS_OK(status)) {
 		talloc_free(tmp_ctx);
 		return status;
diff --git a/source4/rpc_server/unixinfo/dcesrv_unixinfo.c b/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
index 260d5ab..b5b8a89 100644
--- a/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
+++ b/source4/rpc_server/unixinfo/dcesrv_unixinfo.c
@@ -50,6 +50,7 @@ static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
 						dce_call->context->private_data,
 						struct wbc_context);
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	DEBUG(5, ("dcesrv_unixinfo_SidToUid called\n"));
 
@@ -59,7 +60,10 @@ static NTSTATUS dcesrv_unixinfo_SidToUid(struct dcesrv_call_state *dce_call,
 	ids->sid = &r->in.sid;
 	ids->status = ID_UNKNOWN;
 	ZERO_STRUCT(ids->xid);
-	status = wbc_sids_to_xids(wbc_ctx->event_ctx, ids, 1);
+	ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	status = wbc_sids_to_xids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	if (ids->xid.type == ID_TYPE_BOTH ||
@@ -119,6 +123,7 @@ static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
 						dce_call->context->private_data,
 						struct wbc_context);
 	struct id_map *ids;
+	struct composite_context *ctx;
 
 	DEBUG(5, ("dcesrv_unixinfo_SidToGid called\n"));
 
@@ -128,7 +133,10 @@ static NTSTATUS dcesrv_unixinfo_SidToGid(struct dcesrv_call_state *dce_call,
 	ids->sid = &r->in.sid;
 	ids->status = ID_UNKNOWN;
 	ZERO_STRUCT(ids->xid);
-	status = wbc_sids_to_xids(wbc_ctx->event_ctx, ids, 1);
+	ctx = wbc_sids_to_xids_send(wbc_ctx, ids, 1, ids);
+	NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+	status = wbc_sids_to_xids_recv(ctx, &ids);
 	NT_STATUS_NOT_OK_RETURN(status);
 
 	if (ids->xid.type == ID_TYPE_BOTH ||
-- 
1.7.9.5


From 00928ffc8afc804bd0e3ab5c1d09c540f23e78a3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Feb 2014 09:50:44 +0100
Subject: [PATCH 15/15] Revert "libwbclient4: Add wbc_sids_to_xids"

This reverts commit fefc59619b58cb0c38bf7e6ac2ebcc25a5ebbd6c.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/libcli/wbclient/wbclient.c    |  167 ---------------------------------
 source4/libcli/wbclient/wbclient.h    |    5 -
 source4/libcli/wbclient/wscript_build |    2 +-
 3 files changed, 1 insertion(+), 173 deletions(-)

diff --git a/source4/libcli/wbclient/wbclient.c b/source4/libcli/wbclient/wbclient.c
index 5b95be1..4f50c10 100644
--- a/source4/libcli/wbclient/wbclient.c
+++ b/source4/libcli/wbclient/wbclient.c
@@ -22,10 +22,6 @@
 #include "includes.h"
 #include <tevent.h>
 #include "libcli/wbclient/wbclient.h"
-#include "nsswitch/wb_reqtrans.h"
-#include "system/network.h"
-#include "libcli/util/error.h"
-#include "libcli/security/dom_sid.h"
 
 /**
  * Initialize the wbclient context, talloc_free() when done.
@@ -198,166 +194,3 @@ NTSTATUS wbc_xids_to_sids_recv(struct composite_context *ctx,
 	return status;
 }
 
-static int wb_simple_trans(struct tevent_context *ev, int fd,
-			   struct winbindd_request *wb_req,
-			   TALLOC_CTX *mem_ctx,
-			   struct winbindd_response **resp, int *err)
-{
-	struct tevent_req *req;
-	bool polled;
-	int ret;
-
-	req = wb_simple_trans_send(ev, ev, NULL, fd, wb_req);
-	if (req == NULL) {
-		*err = ENOMEM;
-		return -1;
-	}
-
-	polled = tevent_req_poll(req, ev);
-	if (!polled) {
-		*err = errno;
-		DEBUG(10, ("tevent_req_poll returned %s\n",
-			   strerror(*err)));
-		return -1;
-	}
-
-	ret = wb_simple_trans_recv(req, mem_ctx, resp, err);
-	TALLOC_FREE(req);
-	return ret;
-}
-
-static const char *winbindd_socket_dir(void)
-{
-#ifdef SOCKET_WRAPPER
-	const char *env_dir;
-
-	env_dir = getenv(WINBINDD_SOCKET_DIR_ENVVAR);
-	if (env_dir) {
-		return env_dir;
-	}
-#endif
-
-	return WINBINDD_SOCKET_DIR;
-}
-
-static int winbindd_pipe_sock(void)
-{
-	struct sockaddr_un sunaddr = {};
-	int ret, fd;
-	char *path;
-
-	ret = asprintf(&path, "%s/%s", winbindd_socket_dir(),
-		       WINBINDD_SOCKET_NAME);
-	if (ret == -1) {
-		errno = ENOMEM;
-		return -1;
-	}
-	sunaddr.sun_family = AF_UNIX;
-	strlcpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path));
-	free(path);
-
-	fd = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (fd == -1) {
-		return -1;
-	}
-
-	ret = connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr));
-	if (ret == -1) {
-		int err = errno;
-		close(fd);
-		errno = err;
-		return -1;
-	}
-
-	return fd;
-}
-
-NTSTATUS wbc_sids_to_xids(struct tevent_context *ev, struct id_map *ids,
-			  uint32_t count)
-{
-	TALLOC_CTX *mem_ctx;
-	struct winbindd_request req = {};
-	struct winbindd_response *resp;
-	uint32_t i;
-	int fd, ret, err;
-	char *sids, *p;
-	size_t sidslen;
-
-	fd = winbindd_pipe_sock();
-	if (fd == -1) {
-		return map_nt_error_from_unix_common(errno);
-	}
-
-	mem_ctx = talloc_new(NULL);
-	if (mem_ctx == NULL) {
-		close(fd);
-		return NT_STATUS_NO_MEMORY;
-	}
-
-	sidslen = count * (DOM_SID_STR_BUFLEN + 1);
-
-	sids = talloc_array(mem_ctx, char, sidslen);
-	if (sids == NULL) {
-		close(fd);
-		TALLOC_FREE(mem_ctx);
-		return NT_STATUS_NO_MEMORY;
-	}
-
-	p = sids;
-	for (i=0; i<count; i++) {
-		p += dom_sid_string_buf(ids[i].sid, p, sidslen - (p - sids));
-		*p++ = '\n';
-	}
-	*p++ = '\0';
-
-	DEBUG(10, ("sids=\n%s", sids));
-
-	req.length = sizeof(struct winbindd_request);
-	req.cmd = WINBINDD_SIDS_TO_XIDS;
-	req.pid = getpid();
-	req.extra_data.data = sids;
-	req.extra_len = sidslen;
-
-	ret = wb_simple_trans(ev, fd, &req, mem_ctx, &resp, &err);
-	if (ret == -1) {
-		return map_nt_error_from_unix_common(err);
-	}
-
-	close(fd);
-
-	p = resp->extra_data.data;
-
-	for (i=0; i<count; i++) {
-		struct unixid *id = &ids[i].xid;
-		char *q;
-
-		switch (p[0]) {
-		case 'U':
-			id->type = ID_TYPE_UID;
-			id->id = strtoul(p+1, &q, 10);
-			break;
-		case 'G':
-			id->type = ID_TYPE_GID;
-			id->id = strtoul(p+1, &q, 10);
-			break;
-		case 'B':
-			id->type = ID_TYPE_BOTH;
-			id->id = strtoul(p+1, &q, 10);
-			break;
-		default:
-			id->type = ID_TYPE_NOT_SPECIFIED;
-			id->id = UINT32_MAX;
-			q = strchr(p, '\n');
-			break;
-		};
-		ids[i].status = ID_MAPPED;
-
-		if (q == NULL || q[0] != '\n') {
-			TALLOC_FREE(mem_ctx);
-			return NT_STATUS_INTERNAL_ERROR;
-		}
-		p = q+1;
-	}
-
-	return NT_STATUS_OK;
-}
diff --git a/source4/libcli/wbclient/wbclient.h b/source4/libcli/wbclient/wbclient.h
index 33a21f3..1fa2f59 100644
--- a/source4/libcli/wbclient/wbclient.h
+++ b/source4/libcli/wbclient/wbclient.h
@@ -39,9 +39,6 @@ struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
 NTSTATUS wbc_sids_to_xids_recv(struct composite_context *ctx,
 			       struct id_map **ids);
 
-NTSTATUS wbc_sids_to_xids(struct tevent_context *ev, struct id_map *ids,
-			  uint32_t count);
-
 struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
 						TALLOC_CTX *mem_ctx,
 						uint32_t count,
@@ -50,5 +47,3 @@ struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
 NTSTATUS wbc_xids_to_sids_recv(struct composite_context *ctx,
 			       struct id_map **ids);
 
-NTSTATUS wbc_xids_to_sids(struct tevent_context *ev, struct id_map *ids,
-			  uint32_t count);
diff --git a/source4/libcli/wbclient/wscript_build b/source4/libcli/wbclient/wscript_build
index 2c95a04..85439fc 100644
--- a/source4/libcli/wbclient/wscript_build
+++ b/source4/libcli/wbclient/wscript_build
@@ -3,7 +3,7 @@
 bld.SAMBA_LIBRARY('LIBWBCLIENT_OLD',
                   source='wbclient.c',
                   public_deps='errors events',
-                  deps='WB_REQTRANS NDR_WINBIND MESSAGING RPC_NDR_WINBIND',
+                  deps='NDR_WINBIND MESSAGING RPC_NDR_WINBIND',
                   private_library=True
 	)
 
-- 
1.7.9.5



More information about the samba-technical mailing list