From b86c4faa19a85b4bd34d36e96fc7f10d9f1fccfc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Mar 2014 10:06:48 -0700 Subject: [PATCH] s3: lib: Back-port tevent_queue_wait_send/recv -> smbd_tevent_queue_wait_send/recv Required for bugfix: [Bug 10344] SessionLogoff on a signed connection with an outstanding notify request crashes smbd. https://bugzilla.samba.org/show_bug.cgi?id=10344 Signed-off-by: Jeremy Allison --- source3/Makefile.in | 2 +- source3/lib/smbd_tevent_queue.c | 81 +++++++++++++++++++++++++++++++++++++++++ source3/lib/smbd_tevent_queue.h | 34 +++++++++++++++++ source3/wscript_build | 1 + 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 source3/lib/smbd_tevent_queue.c create mode 100644 source3/lib/smbd_tevent_queue.h diff --git a/source3/Makefile.in b/source3/Makefile.in index 96727fcbc50..ad3112cb0fd 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -495,7 +495,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \ lib/fncall.o \ libads/krb5_errs.o lib/system_smbd.o lib/audit.o $(LIBNDR_OBJ) \ lib/file_id.o lib/idmap_cache.o \ - lib/tevent_wait.o \ + lib/tevent_wait.o lib/smbd_tevent_queue.o \ ../libcli/security/dom_sid.o ../libcli/security/security_descriptor.o \ ../libcli/security/security_token.o ../libcli/security/util_sid.o \ ../libcli/smb/util.o ../lib/util/idtree.o diff --git a/source3/lib/smbd_tevent_queue.c b/source3/lib/smbd_tevent_queue.c new file mode 100644 index 00000000000..421f77dca26 --- /dev/null +++ b/source3/lib/smbd_tevent_queue.c @@ -0,0 +1,81 @@ +/* + Unix SMB/CIFS implementation. + Infrastructure for async requests + Copyright (C) Volker Lendecke 2008 + Copyright (C) Stefan Metzmacher 2009 + + ** NOTE! The following LGPL license applies to the tevent + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see . +*/ + +/* Back-port of missing API from 4.2.x for tevent_queues. */ + +#include "replace.h" +#include +#include "source3/lib/smbd_tevent_queue.h" + +struct tevent_queue_wait_state { + uint8_t dummy; +}; + +static void tevent_queue_wait_trigger(struct tevent_req *req, + void *private_data); + +struct tevent_req *smbd_tevent_queue_wait_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tevent_queue *queue) +{ + struct tevent_req *req; + struct tevent_queue_wait_state *state; + bool ok; + + req = tevent_req_create(mem_ctx, &state, + struct tevent_queue_wait_state); + if (req == NULL) { + return NULL; + } + + ok = tevent_queue_add(queue, ev, req, + tevent_queue_wait_trigger, + NULL); + if (!ok) { + tevent_req_oom(req); + return tevent_req_post(req, ev); + } + + return req; +} + +static void tevent_queue_wait_trigger(struct tevent_req *req, + void *private_data) +{ + tevent_req_done(req); +} + +bool smbd_tevent_queue_wait_recv(struct tevent_req *req) +{ + enum tevent_req_state state; + uint64_t err; + + if (tevent_req_is_error(req, &state, &err)) { + tevent_req_received(req); + return false; + } + + tevent_req_received(req); + return true; +} diff --git a/source3/lib/smbd_tevent_queue.h b/source3/lib/smbd_tevent_queue.h new file mode 100644 index 00000000000..c919958ae1e --- /dev/null +++ b/source3/lib/smbd_tevent_queue.h @@ -0,0 +1,34 @@ +/* + Unix SMB/CIFS implementation. + Infrastructure for async requests + Copyright (C) Volker Lendecke 2008 + Copyright (C) Stefan Metzmacher 2009 + + ** NOTE! The following LGPL license applies to the tevent + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see . +*/ + +/* Back-port of missing API from 4.2 for tevent_queues. */ + +#ifndef _SMBD_TEVENT_QUEUE_H_ +#define _SMBD_TEVENT_QUEUE_H_ +struct tevent_req *smbd_tevent_queue_wait_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tevent_queue *queue); + +bool smbd_tevent_queue_wait_recv(struct tevent_req *req); +#endif diff --git a/source3/wscript_build b/source3/wscript_build index 924bde7b877..3e05fd6f099 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -67,6 +67,7 @@ LIB_SRC = ''' lib/fncall.c libads/krb5_errs.c lib/system_smbd.c lib/audit.c lib/tevent_wait.c + lib/smbd_tevent_queue.c lib/idmap_cache.c''' LIB_UTIL_SRC = ''' -- 2.11.4.GIT