From 998d58819201954a78eb123d6f9d2bc0c6bd579c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 03:24:39 +0100 Subject: python/tevent: Remove use of pytalloc.h. --- lib/tevent/pytevent.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/tevent/pytevent.c b/lib/tevent/pytevent.c index 4f18c87a90..54f6799845 100644 --- a/lib/tevent/pytevent.c +++ b/lib/tevent/pytevent.c @@ -19,9 +19,13 @@ #include #include #include -#include <../talloc/pytalloc.h> #include +typedef struct { + PyObject_HEAD + struct event_context *ev_ctx; +} PyEventContextObject; + PyAPI_DATA(PyTypeObject) PyEventContext; static PyObject *py_set_default_backend(PyObject *self, PyObject *args) @@ -62,6 +66,7 @@ static PyObject *py_event_ctx_new(PyTypeObject *type, PyObject *args, PyObject * const char *kwnames[] = { "name", NULL }; char *name = NULL; struct event_context *ev_ctx; + PyEventContextObject *ret; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", (char **)kwnames, &name)) return NULL; @@ -70,17 +75,19 @@ static PyObject *py_event_ctx_new(PyTypeObject *type, PyObject *args, PyObject * else ev_ctx = event_context_init_byname(NULL, name); - return py_talloc_import(&PyEventContext, ev_ctx); + ret = (PyEventContextObject *)type->tp_alloc(type, 0); + ret->ev_ctx = ev_ctx; + return (PyObject *)ret; } -static PyObject *py_event_ctx_loop_once(py_talloc_Object *self) +static PyObject *py_event_ctx_loop_once(PyEventContextObject *self) { - return PyInt_FromLong(event_loop_once(self->ptr)); + return PyInt_FromLong(event_loop_once(self->ev_ctx)); } -static PyObject *py_event_ctx_loop_wait(py_talloc_Object *self) +static PyObject *py_event_ctx_loop_wait(PyEventContextObject *self) { - return PyInt_FromLong(event_loop_wait(self->ptr)); + return PyInt_FromLong(event_loop_wait(self->ev_ctx)); } static PyMethodDef py_event_ctx_methods[] = { @@ -91,11 +98,17 @@ static PyMethodDef py_event_ctx_methods[] = { { NULL } }; +static void py_event_ctx_dealloc(PyEventContextObject * self) +{ + talloc_free(self->ev_ctx); + self->ob_type->tp_free(self); +} + PyTypeObject PyEventContext = { .tp_name = "EventContext", .tp_methods = py_event_ctx_methods, - .tp_basicsize = sizeof(py_talloc_Object), - .tp_dealloc = py_talloc_dealloc, + .tp_basicsize = sizeof(PyEventContextObject), + .tp_dealloc = (destructor)py_event_ctx_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = py_event_ctx_new, }; -- cgit From bbc95fb1a866e8aa822b70a7f5cdf74f1446b1f0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 04:18:31 +0100 Subject: ldb: Fix linking against tevent library (rather than events) replace: Fix copyright for dlfcn.c. --- lib/replace/dlfcn.c | 1 + source4/lib/ldb/Makefile.in | 12 ++++++------ source4/lib/ldb/external/libevents.m4 | 12 ++++++------ source4/lib/ldb/ldb.mk | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/replace/dlfcn.c b/lib/replace/dlfcn.c index 3b109d7e40..88431ed576 100644 --- a/lib/replace/dlfcn.c +++ b/lib/replace/dlfcn.c @@ -3,6 +3,7 @@ Samba system utilities Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) Jeremy Allison 1998-2002 + Copyright (C) Jelmer Vernooij 2006 ** NOTE! The following LGPL license applies to the replace ** library. This does NOT imply that all of Samba is released diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index d97ca8bde3..5f59def4af 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -32,9 +32,9 @@ TDB_LIBS = @TDB_LIBS@ TDB_CFLAGS = @TDB_CFLAGS@ TDB_OBJ = @TDB_OBJ@ -EVENTS_LIBS = @EVENTS_LIBS@ -EVENTS_CFLAGS = @EVENTS_CFLAGS@ -EVENTS_OBJ = @EVENTS_OBJ@ +TEVENT_LIBS = @TEVENT_LIBS@ +TEVENT_CFLAGS = @TEVENT_CFLAGS@ +TEVENT_OBJ = @TEVENT_OBJ@ POPT_LIBS = @POPT_LIBS@ POPT_CFLAGS = @POPT_CFLAGS@ @@ -55,13 +55,13 @@ LIBS = @LIBS@ PICFLAG = @PICFLAG@ CFLAGS=-g -I$(srcdir)/include -Iinclude -I$(srcdir) -I$(srcdir)/.. \ - $(POPT_CFLAGS) $(TALLOC_CFLAGS) $(TDB_CFLAGS) $(EVENTS_CFLAGS) \ + $(POPT_CFLAGS) $(TALLOC_CFLAGS) $(TDB_CFLAGS) $(TEVENT_CFLAGS) \ -DLIBDIR=\"$(libdir)\" -DSHLIBEXT=\"$(SHLIBEXT)\" -DUSE_MMAP=1 @CFLAGS@ MDLD = @MDLD@ MDLD_FLAGS = @MDLD_FLAGS@ -OBJS = $(MODULES_OBJ) $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(EVENTS_OBJ) $(TALLOC_OBJ) $(POPT_OBJ) $(LDB_MAP_OBJ) @LIBREPLACEOBJ@ $(EXTRA_OBJ) +OBJS = $(MODULES_OBJ) $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(TEVENT_OBJ) $(TALLOC_OBJ) $(POPT_OBJ) $(LDB_MAP_OBJ) @LIBREPLACEOBJ@ $(EXTRA_OBJ) headers = $(srcdir)/include/ldb.h $(srcdir)/include/ldb_errors.h $(srcdir)/include/ldb_handlers.h @@ -95,7 +95,7 @@ lib/libnss_ldb.$(SHLIBEXT).2: $(NSS_OBJ) $(LIBSOLIB) $(SHLD) $(SHLD_FLAGS) -o $@ $(NSS_OBJ) $(LDFLAGS) $(LIBSOLIB) @SONAMEFLAG@libnss_ldb.$(SHLIBEXT).2 $(LIBSOLIB): $(OBJS) - $(SHLD) $(SHLD_FLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) $(TALLOC_LIBS) $(TDB_LIBS) $(EVENTS_LIBS) $(LIBDL) $(LDAP_LIBS) @SONAMEFLAG@$(SONAME) + $(SHLD) $(SHLD_FLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) $(TALLOC_LIBS) $(TDB_LIBS) $(TEVENT_LIBS) $(LIBDL) $(LDAP_LIBS) @SONAMEFLAG@$(SONAME) ln -sf libldb.$(SHLIBEXT).$(PACKAGE_VERSION) lib/libldb.$(SHLIBEXT) all: showflags dirs $(OBJS) $(STATICLIB) $(LIBSOLIB) $(BINS) $(EXAMPLES) manpages \ diff --git a/source4/lib/ldb/external/libevents.m4 b/source4/lib/ldb/external/libevents.m4 index 4fd2e71ec2..24534f2c21 100644 --- a/source4/lib/ldb/external/libevents.m4 +++ b/source4/lib/ldb/external/libevents.m4 @@ -1,7 +1,7 @@ -AC_SUBST(EVENTS_OBJ) -AC_SUBST(EVENTS_CFLAGS) -AC_SUBST(EVENTS_LIBS) +AC_SUBST(TEVENT_OBJ) +AC_SUBST(TEVENT_CFLAGS) +AC_SUBST(TEVENT_LIBS) -AC_CHECK_HEADER(events.h, - [AC_CHECK_LIB(events, event_context_init, [EVENTS_LIBS="-levents"]) ], - [PKG_CHECK_MODULES(EVENTS, events)]) +AC_CHECK_HEADER(tevent.h, + [AC_CHECK_LIB(tevent, event_context_init, [TEVENT_LIBS="-ltevent"]) ], + [PKG_CHECK_MODULES(TEVENT, tevent)]) diff --git a/source4/lib/ldb/ldb.mk b/source4/lib/ldb/ldb.mk index 66cdea15c2..ff8c1f3baf 100644 --- a/source4/lib/ldb/ldb.mk +++ b/source4/lib/ldb/ldb.mk @@ -1,7 +1,7 @@ LDB_LIB = -Llib -lldb LIB_FLAGS=$(LDFLAGS) $(LIBS) $(LDB_LIB) $(POPT_LIBS) $(TALLOC_LIBS) \ - $(TDB_LIBS) $(EVENTS_LIBS) $(LDAP_LIBS) $(LIBDL) + $(TDB_LIBS) $(TEVENT_LIBS) $(LDAP_LIBS) $(LIBDL) LDB_TDB_DIR=ldb_tdb LDB_TDB_OBJ=$(LDB_TDB_DIR)/ldb_tdb.o \ -- cgit From a7f64ba2f1d49b65cd96ba862f6b80b28c3e6dd2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 04:21:35 +0100 Subject: ldb: Include tevent.h rather than events.h. --- source4/lib/ldb/include/ldb_includes.h | 2 +- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- source4/lib/ldb/pyldb.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source4/lib/ldb/include/ldb_includes.h b/source4/lib/ldb/include/ldb_includes.h index 29c7b2dc5a..b55350a9d4 100644 --- a/source4/lib/ldb/include/ldb_includes.h +++ b/source4/lib/ldb/include/ldb_includes.h @@ -20,7 +20,7 @@ #include "system/filesys.h" #include "system/time.h" #include "talloc.h" -#include "events.h" +#include "tevent.h" #include "ldb.h" #include "ldb_errors.h" #include "ldb_private.h" diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index b17d063c0c..a95859276f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -44,7 +44,7 @@ #include "includes.h" #include "ldb_includes.h" -#include "lib/events/events.h" +#include "tevent.h" #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" #include "auth/auth.h" diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index dfabed54e3..7254772327 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -28,7 +28,7 @@ #include #include #include "pyldb.h" -#include "events.h" +#include "tevent.h" #include "ldb.h" #include "ldb_errors.h" #include "ldb_private.h" -- cgit From aaea68791cfea45c6fa69abc93ad6d0e832d0283 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 22 Dec 2008 20:08:14 -0800 Subject: In gcc version 4.3.2 we get warnings for functions declared with attribute warn_unused_result. Start to fix these. Jeremy. --- lib/socket_wrapper/socket_wrapper.c | 12 ++++++++++-- source3/libnet/libnet_join.c | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c index 9d61976950..dc0124bdb7 100644 --- a/lib/socket_wrapper/socket_wrapper.c +++ b/lib/socket_wrapper/socket_wrapper.c @@ -899,7 +899,10 @@ static int swrap_get_pcap_fd(const char *fname) file_hdr.frame_max_len = SWRAP_FRAME_LENGTH_MAX; file_hdr.link_type = 0x0065; /* 101 RAW IP */ - write(fd, &file_hdr, sizeof(file_hdr)); + if (write(fd, &file_hdr, sizeof(file_hdr)) != sizeof(file_hdr)) { + close(fd); + return -1; + } return fd; } @@ -1190,7 +1193,12 @@ static void swrap_dump_packet(struct socket_info *si, fd = swrap_get_pcap_fd(file_name); if (fd != -1) { - write(fd, packet, packet_len); + if (write(fd, packet, packet_len) != packet_len) { + close(fd); + free(packet); + return; + } + close(fd); } free(packet); diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index 691f6ff8eb..51d979074b 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -1019,8 +1019,7 @@ NTSTATUS libnet_join_ok(const char *netbios_domain_name, return NT_STATUS_NO_TRUST_LSA_SECRET; } - asprintf(&machine_account, "%s$", machine_name); - if (!machine_account) { + if (asprintf(&machine_account, "%s$", machine_name) == -1) { SAFE_FREE(machine_password); return NT_STATUS_NO_MEMORY; } -- cgit From 112feeaa35ace32da7620289c676c068dd9585e5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 05:07:29 +0100 Subject: pyldb: Avoid use of pytalloc, as it may not be available. --- source4/lib/ldb/pyldb.c | 234 ++++++++++++++++++++++++++++++++++++------------ source4/lib/ldb/pyldb.h | 56 ++++++++---- 2 files changed, 213 insertions(+), 77 deletions(-) diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 7254772327..4d4550eb72 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -25,19 +25,14 @@ License along with this library; if not, see . */ -#include -#include +#include "ldb_includes.h" #include "pyldb.h" -#include "tevent.h" -#include "ldb.h" -#include "ldb_errors.h" -#include "ldb_private.h" /* Picked out of thin air. To do this properly, we should probably have some part of the * errors in LDB be allocated to bindings ? */ #define LDB_ERR_PYTHON_EXCEPTION 142 -PyObject *PyExc_LdbError; +static PyObject *PyExc_LdbError; void PyErr_SetLdbError(int ret, struct ldb_context *ldb_ctx) { @@ -45,7 +40,7 @@ void PyErr_SetLdbError(int ret, struct ldb_context *ldb_ctx) return; /* Python exception should already be set, just keep that */ PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", ret, ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx))); } -PyObject *PyObject_FromLdbValue(struct ldb_context *ldb_ctx, +static PyObject *PyObject_FromLdbValue(struct ldb_context *ldb_ctx, struct ldb_message_element *el, struct ldb_val *val) { @@ -129,47 +124,47 @@ static struct ldb_result *PyLdbResult_AsResult(TALLOC_CTX *mem_ctx, PyObject *ob static PyObject *py_ldb_dn_validate(PyLdbDnObject *self) { - return PyBool_FromLong(ldb_dn_validate(self->ptr)); + return PyBool_FromLong(ldb_dn_validate(self->dn)); } static PyObject *py_ldb_dn_is_valid(PyLdbDnObject *self) { - return PyBool_FromLong(ldb_dn_is_valid(self->ptr)); + return PyBool_FromLong(ldb_dn_is_valid(self->dn)); } static PyObject *py_ldb_dn_is_special(PyLdbDnObject *self) { - return PyBool_FromLong(ldb_dn_is_special(self->ptr)); + return PyBool_FromLong(ldb_dn_is_special(self->dn)); } static PyObject *py_ldb_dn_is_null(PyLdbDnObject *self) { - return PyBool_FromLong(ldb_dn_is_null(self->ptr)); + return PyBool_FromLong(ldb_dn_is_null(self->dn)); } static PyObject *py_ldb_dn_get_casefold(PyLdbDnObject *self) { - return PyString_FromString(ldb_dn_get_casefold(self->ptr)); + return PyString_FromString(ldb_dn_get_casefold(self->dn)); } static PyObject *py_ldb_dn_get_linearized(PyLdbDnObject *self) { - return PyString_FromString(ldb_dn_get_linearized(self->ptr)); + return PyString_FromString(ldb_dn_get_linearized(self->dn)); } static PyObject *py_ldb_dn_canonical_str(PyLdbDnObject *self) { - return PyString_FromString(ldb_dn_canonical_string(self->ptr, self->ptr)); + return PyString_FromString(ldb_dn_canonical_string(self->dn, self->dn)); } static PyObject *py_ldb_dn_canonical_ex_str(PyLdbDnObject *self) { - return PyString_FromString(ldb_dn_canonical_ex_string(self->ptr, self->ptr)); + return PyString_FromString(ldb_dn_canonical_ex_string(self->dn, self->dn)); } static PyObject *py_ldb_dn_repr(PyLdbDnObject *self) { - return PyString_FromFormat("Dn(%s)", PyObject_REPR(PyString_FromString(ldb_dn_get_linearized(self->ptr)))); + return PyString_FromFormat("Dn(%s)", PyObject_REPR(PyString_FromString(ldb_dn_get_linearized(self->dn)))); } static PyObject *py_ldb_dn_check_special(PyLdbDnObject *self, PyObject *args) @@ -179,12 +174,12 @@ static PyObject *py_ldb_dn_check_special(PyLdbDnObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "s", &name)) return NULL; - return ldb_dn_check_special(self->ptr, name)?Py_True:Py_False; + return ldb_dn_check_special(self->dn, name)?Py_True:Py_False; } static int py_ldb_dn_compare(PyLdbDnObject *dn1, PyLdbDnObject *dn2) { - return ldb_dn_compare(dn1->ptr, dn2->ptr); + return ldb_dn_compare(dn1->dn, dn2->dn); } static PyObject *py_ldb_dn_get_parent(PyLdbDnObject *self) @@ -289,6 +284,7 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa char *str; PyObject *py_ldb; struct ldb_context *ldb_ctx; + PyLdbDnObject *py_ret; const char *kwnames[] = { "ldb", "dn", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os", (char **)kwnames, &py_ldb, &str)) @@ -306,12 +302,32 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa return NULL; } - return py_talloc_import(&PyLdbDn, ret); + py_ret = (PyLdbDnObject *)type->tp_alloc(type, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + py_ret->dn = ret; + return (PyObject *)py_ret; } PyObject *PyLdbDn_FromDn(struct ldb_dn *dn) { - return py_talloc_import(&PyLdbDn, dn); + PyLdbDnObject *py_ret; + py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0); + if (py_ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + py_ret->mem_ctx = talloc_new(NULL); + py_ret->dn = talloc_reference(py_ret->mem_ctx, dn); + return (PyObject *)py_ret; +} + +static void py_ldb_dn_dealloc(PyLdbDnObject *self) +{ + talloc_free(self->mem_ctx); + self->ob_type->tp_free(self); } PyTypeObject PyLdbDn = { @@ -323,7 +339,7 @@ PyTypeObject PyLdbDn = { .tp_as_sequence = &py_ldb_dn_seq, .tp_doc = "A LDB distinguished name.", .tp_new = py_ldb_dn_new, - .tp_dealloc = py_talloc_dealloc, + .tp_dealloc = (destructor)py_ldb_dn_dealloc, .tp_basicsize = sizeof(PyLdbObject), .tp_flags = Py_TPFLAGS_DEFAULT, }; @@ -345,7 +361,7 @@ static PyObject *py_ldb_set_debug(PyLdbObject *self, PyObject *args) Py_INCREF(cb); /* FIXME: Where do we DECREF cb ? */ - PyErr_LDB_ERROR_IS_ERR_RAISE(ldb_set_debug(self->ptr, py_ldb_debug, cb), PyLdb_AsLdbContext(self)); + PyErr_LDB_ERROR_IS_ERR_RAISE(ldb_set_debug(self->ldb_ctx, py_ldb_debug, cb), PyLdb_AsLdbContext(self)); return Py_None; } @@ -495,6 +511,7 @@ static int py_ldb_init(PyLdbObject *self, PyObject *args, PyObject *kwargs) static PyObject *py_ldb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { + PyLdbObject *ret; struct ldb_context *ldb; ldb = ldb_init(NULL, event_context_init(NULL)); if (ldb == NULL) { @@ -502,7 +519,13 @@ static PyObject *py_ldb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs return NULL; } - return py_talloc_import(type, ldb); + ret = (PyLdbObject *)type->tp_alloc(type, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + ret->ldb_ctx = ldb; + return (PyObject *)ret; } static PyObject *py_ldb_connect(PyLdbObject *self, PyObject *args, PyObject *kwargs) @@ -701,7 +724,7 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) return NULL; list = PyList_New(0); - while ((ldif = ldb_ldif_read_string(self->ptr, &s)) != NULL) { + while ((ldif = ldb_ldif_read_string(self->ldb_ctx, &s)) != NULL) { PyList_Append(list, ldb_ldif_to_pyobject(ldif)); } return PyObject_GetIter(list); @@ -949,7 +972,16 @@ static PyMethodDef py_ldb_methods[] = { PyObject *PyLdbModule_FromModule(struct ldb_module *mod) { - return py_talloc_import(&PyLdbModule, mod); + PyLdbModuleObject *ret; + + ret = (PyLdbModuleObject *)PyLdbModule.tp_alloc(&PyLdbModule, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + ret->mem_ctx = talloc_new(NULL); + ret->mod = talloc_reference(ret->mem_ctx, mod); + return (PyObject *)ret; } static PyObject *py_ldb_get_firstmodule(PyLdbObject *self, void *closure) @@ -992,7 +1024,22 @@ static PySequenceMethods py_ldb_seq = { PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx) { - return py_talloc_import(&PyLdb, ldb_ctx); + PyLdbObject *ret; + + ret = (PyLdbObject *)PyLdb.tp_alloc(&PyLdb, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + ret->mem_ctx = talloc_new(NULL); + ret->ldb_ctx = talloc_reference(ret->mem_ctx, ldb_ctx); + return (PyObject *)ret; +} + +static void py_ldb_dealloc(PyLdbObject *self) +{ + talloc_free(self->mem_ctx); + self->ob_type->tp_free(self); } PyTypeObject PyLdb = { @@ -1001,7 +1048,7 @@ PyTypeObject PyLdb = { .tp_repr = (reprfunc)py_ldb_repr, .tp_new = py_ldb_new, .tp_init = (initproc)py_ldb_init, - .tp_dealloc = py_talloc_dealloc, + .tp_dealloc = (destructor)py_ldb_dealloc, .tp_getset = py_ldb_getset, .tp_getattro = PyObject_GenericGetAttr, .tp_basicsize = sizeof(PyLdbObject), @@ -1049,7 +1096,7 @@ static PyObject *py_ldb_module_search(PyLdbModuleObject *self, PyObject *args, P &py_base, &scope, &py_tree, &py_attrs)) return NULL; - mod = self->ptr; + mod = self->mod; ret = ldb_build_search_req(&req, mod->ldb, NULL, PyLdbDn_AsDn(py_base), scope, NULL /* expr */, py_attrs == Py_None?NULL:PyList_AsStringList(req, py_attrs), @@ -1163,13 +1210,19 @@ static PyMethodDef py_ldb_module_methods[] = { { NULL }, }; +static void py_ldb_module_dealloc(PyLdbModuleObject *self) +{ + talloc_free(self->mem_ctx); + self->ob_type->tp_free(self); +} + PyTypeObject PyLdbModule = { .tp_name = "LdbModule", .tp_methods = py_ldb_module_methods, .tp_repr = (reprfunc)py_ldb_module_repr, .tp_str = (reprfunc)py_ldb_module_str, - .tp_basicsize = sizeof(py_talloc_Object), - .tp_dealloc = py_talloc_dealloc, + .tp_basicsize = sizeof(PyLdbModuleObject), + .tp_dealloc = (destructor)py_ldb_module_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, }; @@ -1210,7 +1263,7 @@ struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx, } -PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, +static PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, struct ldb_message_element *me) { int i; @@ -1227,7 +1280,7 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, return result; } -PyObject *py_ldb_msg_element_get(PyLdbMessageElementObject *self, PyObject *args) +static PyObject *py_ldb_msg_element_get(PyLdbMessageElementObject *self, PyObject *args) { int i; if (!PyArg_ParseTuple(args, "i", &i)) @@ -1277,7 +1330,15 @@ static PyObject *py_ldb_msg_element_iter(PyLdbMessageElementObject *self) PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *el, TALLOC_CTX *mem_ctx) { - return py_talloc_import_ex(&PyLdbMessageElement, mem_ctx, el); + PyLdbMessageElementObject *ret; + ret = (PyLdbMessageElementObject *)PyLdbMessageElement.tp_alloc(&PyLdbMessageElement, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + ret->mem_ctx = talloc_reference(mem_ctx, el); + ret->el = el; + return (PyObject *)ret; } static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) @@ -1287,6 +1348,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb int flags = 0; char *name = NULL; const char *kwnames[] = { "elements", "flags", "name", NULL }; + PyLdbMessageElementObject *ret; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Ois", (char **)kwnames, &py_elements, &flags, &name)) return NULL; @@ -1313,7 +1375,15 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb el->flags = flags; el->name = talloc_strdup(el, name); - return py_talloc_import(&PyLdbMessageElement, el); + ret = (PyLdbMessageElementObject *)PyLdbMessageElement.tp_alloc(&PyLdbMessageElement, 0); + if (ret == NULL) { + PyErr_NoMemory(); + talloc_free(el); + return NULL; + } + + ret->mem_ctx = ret->el = el; + return (PyObject *)ret; } static PyObject *py_ldb_msg_element_repr(PyLdbMessageElementObject *self) @@ -1348,10 +1418,16 @@ static PyObject *py_ldb_msg_element_str(PyLdbMessageElementObject *self) return Py_None; } +static void py_ldb_msg_element_dealloc(PyLdbMessageElementObject *self) +{ + talloc_free(self->mem_ctx); + self->ob_type->tp_free(self); +} + PyTypeObject PyLdbMessageElement = { .tp_name = "MessageElement", .tp_basicsize = sizeof(PyLdbMessageElementObject), - .tp_dealloc = py_talloc_dealloc, + .tp_dealloc = (destructor)py_ldb_msg_element_dealloc, .tp_repr = (reprfunc)py_ldb_msg_element_repr, .tp_str = (reprfunc)py_ldb_msg_element_str, .tp_methods = py_ldb_msg_element_methods, @@ -1368,7 +1444,7 @@ static PyObject *py_ldb_msg_remove_attr(PyLdbMessageObject *self, PyObject *args if (!PyArg_ParseTuple(args, "s", &name)) return NULL; - ldb_msg_remove_attr(self->ptr, name); + ldb_msg_remove_attr(self->msg, name); return Py_None; } @@ -1393,13 +1469,14 @@ static PyObject *py_ldb_msg_getitem_helper(PyLdbMessageObject *self, PyObject *p { struct ldb_message_element *el; char *name = PyString_AsString(py_name); + struct ldb_message *msg = PyLdbMessage_AsMessage(self); if (!strcmp(name, "dn")) - return PyLdbDn_FromDn(PyLdbMessage_AsMessage(self)->dn); - el = ldb_msg_find_element(PyLdbMessage_AsMessage(self), name); + return PyLdbDn_FromDn(msg->dn); + el = ldb_msg_find_element(msg, name); if (el == NULL) { return NULL; } - return (PyObject *)PyLdbMessageElement_FromMessageElement(el, self->talloc_ctx); + return (PyObject *)PyLdbMessageElement_FromMessageElement(el, msg); } static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name) @@ -1435,7 +1512,7 @@ static PyObject *py_ldb_msg_items(PyLdbMessageObject *self) j++; } for (i = 0; i < msg->num_elements; i++, j++) { - PyList_SetItem(l, j, Py_BuildValue("(sO)", msg->elements[i].name, PyLdbMessageElement_FromMessageElement(&msg->elements[i], self->talloc_ctx))); + PyList_SetItem(l, j, Py_BuildValue("(sO)", msg->elements[i].name, PyLdbMessageElement_FromMessageElement(&msg->elements[i], self->msg))); } return l; } @@ -1462,13 +1539,13 @@ static int py_ldb_msg_setitem(PyLdbMessageObject *self, PyObject *name, PyObject { char *attr_name = PyString_AsString(name); if (value == NULL) { - ldb_msg_remove_attr(self->ptr, attr_name); + ldb_msg_remove_attr(self->msg, attr_name); } else { struct ldb_message_element *el = PyObject_AsMessageElement(NULL, value, 0, attr_name); if (el == NULL) return -1; - talloc_steal(self->ptr, el); + talloc_steal(self->msg, el); ldb_msg_remove_attr(PyLdbMessage_AsMessage(self), attr_name); ldb_msg_add(PyLdbMessage_AsMessage(self), el, el->flags); } @@ -1491,6 +1568,7 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw const char *kwnames[] = { "dn", NULL }; struct ldb_message *ret; PyObject *pydn = NULL; + PyLdbMessageObject *py_ret; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", (char **)kwnames, &pydn)) return NULL; @@ -1504,12 +1582,28 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw if (!PyObject_AsDn(NULL, pydn, NULL, &ret->dn)) return NULL; - return py_talloc_import(type, ret); + py_ret = (PyLdbMessageObject *)type->tp_alloc(type, 0); + if (py_ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + + py_ret->mem_ctx = py_ret->msg = ret; + return (PyObject *)py_ret; } PyObject *PyLdbMessage_FromMessage(struct ldb_message *msg) { - return py_talloc_import(&PyLdbMessage, msg); + PyLdbMessageObject *ret; + + ret = (PyLdbMessageObject *)PyLdbMessage.tp_alloc(&PyLdbMessage, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + ret->mem_ctx = talloc_new(NULL); + ret->msg = talloc_reference(ret->mem_ctx, msg); + return (PyObject *)ret; } static PyObject *py_ldb_msg_get_dn(PyLdbMessageObject *self, void *closure) @@ -1538,13 +1632,19 @@ static PyObject *py_ldb_msg_repr(PyLdbMessageObject *self) return ret; } +static void py_ldb_msg_dealloc(PyLdbMessageObject *self) +{ + talloc_free(self->mem_ctx); + self->ob_type->tp_free(self); +} + PyTypeObject PyLdbMessage = { .tp_name = "Message", .tp_methods = py_ldb_msg_methods, .tp_getset = py_ldb_msg_getset, .tp_as_mapping = &py_ldb_msg_mapping, .tp_basicsize = sizeof(PyLdbMessageObject), - .tp_dealloc = py_talloc_dealloc, + .tp_dealloc = (destructor)py_ldb_msg_dealloc, .tp_new = py_ldb_msg_new, .tp_repr = (reprfunc)py_ldb_msg_repr, .tp_flags = Py_TPFLAGS_DEFAULT, @@ -1553,18 +1653,34 @@ PyTypeObject PyLdbMessage = { PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *tree) { - return py_talloc_import(&PyLdbTree, tree); + PyLdbTreeObject *ret; + + ret = (PyLdbTreeObject *)PyLdbTree.tp_alloc(&PyLdbTree, 0); + if (ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + + ret->mem_ctx = talloc_new(NULL); + ret->tree = talloc_reference(ret->mem_ctx, tree); + return (PyObject *)ret; +} + +static void py_ldb_tree_dealloc(PyLdbTreeObject *self) +{ + talloc_free(self->mem_ctx); + self->ob_type->tp_free(self); } PyTypeObject PyLdbTree = { .tp_name = "Tree", .tp_basicsize = sizeof(PyLdbTreeObject), - .tp_dealloc = py_talloc_dealloc, + .tp_dealloc = (destructor)py_ldb_tree_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, }; /* Ldb_module */ -int py_module_search(struct ldb_module *mod, struct ldb_request *req) +static int py_module_search(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result, *py_base, *py_attrs, *py_tree; @@ -1609,7 +1725,7 @@ int py_module_search(struct ldb_module *mod, struct ldb_request *req) return LDB_SUCCESS; } -int py_module_add(struct ldb_module *mod, struct ldb_request *req) +static int py_module_add(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result, *py_msg; @@ -1633,7 +1749,7 @@ int py_module_add(struct ldb_module *mod, struct ldb_request *req) return LDB_SUCCESS; } -int py_module_modify(struct ldb_module *mod, struct ldb_request *req) +static int py_module_modify(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result, *py_msg; @@ -1657,7 +1773,7 @@ int py_module_modify(struct ldb_module *mod, struct ldb_request *req) return LDB_SUCCESS; } -int py_module_del(struct ldb_module *mod, struct ldb_request *req) +static int py_module_del(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result, *py_dn; @@ -1678,7 +1794,7 @@ int py_module_del(struct ldb_module *mod, struct ldb_request *req) return LDB_SUCCESS; } -int py_module_rename(struct ldb_module *mod, struct ldb_request *req) +static int py_module_rename(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result, *py_olddn, *py_newdn; @@ -1707,7 +1823,7 @@ int py_module_rename(struct ldb_module *mod, struct ldb_request *req) return LDB_SUCCESS; } -int py_module_request(struct ldb_module *mod, struct ldb_request *req) +static int py_module_request(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result; @@ -1717,7 +1833,7 @@ int py_module_request(struct ldb_module *mod, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } -int py_module_extended(struct ldb_module *mod, struct ldb_request *req) +static int py_module_extended(struct ldb_module *mod, struct ldb_request *req) { PyObject *py_ldb = mod->private_data; PyObject *py_result; @@ -1727,7 +1843,7 @@ int py_module_extended(struct ldb_module *mod, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } -int py_module_start_transaction(struct ldb_module *mod) +static int py_module_start_transaction(struct ldb_module *mod) { PyObject *py_ldb = mod->private_data; PyObject *py_result; @@ -1743,7 +1859,7 @@ int py_module_start_transaction(struct ldb_module *mod) return LDB_SUCCESS; } -int py_module_end_transaction(struct ldb_module *mod) +static int py_module_end_transaction(struct ldb_module *mod) { PyObject *py_ldb = mod->private_data; PyObject *py_result; @@ -1759,7 +1875,7 @@ int py_module_end_transaction(struct ldb_module *mod) return LDB_SUCCESS; } -int py_module_del_transaction(struct ldb_module *mod) +static int py_module_del_transaction(struct ldb_module *mod) { PyObject *py_ldb = mod->private_data; PyObject *py_result; @@ -1781,7 +1897,7 @@ static int py_module_destructor(struct ldb_module *mod) return 0; } -int py_module_init (struct ldb_module *mod) +static int py_module_init (struct ldb_module *mod) { PyObject *py_class = mod->ops->private_data; PyObject *py_result, *py_next, *py_ldb; diff --git a/source4/lib/ldb/pyldb.h b/source4/lib/ldb/pyldb.h index b55bb68401..731911a387 100644 --- a/source4/lib/ldb/pyldb.h +++ b/source4/lib/ldb/pyldb.h @@ -27,48 +27,68 @@ #define _PYLDB_H_ #include -#include -#include -#include -#include -typedef py_talloc_Object PyLdbObject; +typedef struct { + PyObject_HEAD + struct ldb_context *ldb_ctx; + TALLOC_CTX *mem_ctx; +} PyLdbObject; + PyAPI_DATA(PyTypeObject) PyLdb; PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx); -#define PyLdb_AsLdbContext(pyobj) py_talloc_get_type(pyobj, struct ldb_context) +#define PyLdb_AsLdbContext(pyobj) ((PyLdbObject *)pyobj)->ldb_ctx #define PyLdb_Check(ob) PyObject_TypeCheck(ob, &PyLdb) -typedef py_talloc_Object PyLdbDnObject; +typedef struct { + PyObject_HEAD + struct ldb_dn *dn; + TALLOC_CTX *mem_ctx; +} PyLdbDnObject; + PyAPI_DATA(PyTypeObject) PyLdbDn; -struct ldb_dn *PyLdbDn_AsDn(PyObject *); PyObject *PyLdbDn_FromDn(struct ldb_dn *); bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb_ctx, struct ldb_dn **dn); -#define PyLdbDn_AsDn(pyobj) py_talloc_get_type(pyobj, struct ldb_dn) +#define PyLdbDn_AsDn(pyobj) ((PyLdbDnObject *)pyobj)->dn #define PyLdbDn_Check(ob) PyObject_TypeCheck(ob, &PyLdbDn) -typedef py_talloc_Object PyLdbMessageObject; +typedef struct { + PyObject_HEAD + struct ldb_message *msg; + TALLOC_CTX *mem_ctx; +} PyLdbMessageObject; PyAPI_DATA(PyTypeObject) PyLdbMessage; PyObject *PyLdbMessage_FromMessage(struct ldb_message *message); -struct ldb_message *PyLdbMessage_AsMessage(PyObject *obj); #define PyLdbMessage_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessage) -#define PyLdbMessage_AsMessage(pyobj) py_talloc_get_type(pyobj, struct ldb_message) +#define PyLdbMessage_AsMessage(pyobj) ((PyLdbMessageObject *)pyobj)->msg -typedef py_talloc_Object PyLdbModuleObject; +typedef struct { + PyObject_HEAD + struct ldb_module *mod; + TALLOC_CTX *mem_ctx; +} PyLdbModuleObject; PyAPI_DATA(PyTypeObject) PyLdbModule; PyObject *PyLdbModule_FromModule(struct ldb_module *mod); -#define PyLdbModule_AsModule(pyobj) ((struct ldb_module *)py_talloc_get_ptr(pyobj)) +#define PyLdbModule_AsModule(pyobj) ((PyLdbModuleObject *)pyobj)->mod -typedef py_talloc_Object PyLdbMessageElementObject; +typedef struct { + PyObject_HEAD + struct ldb_message_element *el; + TALLOC_CTX *mem_ctx; +} PyLdbMessageElementObject; PyAPI_DATA(PyTypeObject) PyLdbMessageElement; struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx, PyObject *obj, int flags, const char *name); PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *, TALLOC_CTX *mem_ctx); -#define PyLdbMessageElement_AsMessageElement(pyobj) ((struct ldb_message_element *)py_talloc_get_ptr(pyobj)) +#define PyLdbMessageElement_AsMessageElement(pyobj) ((PyLdbMessageElementObject *)pyobj)->el #define PyLdbMessageElement_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessageElement) -typedef py_talloc_Object PyLdbTreeObject; +typedef struct { + PyObject_HEAD + struct ldb_parse_tree *tree; + TALLOC_CTX *mem_ctx; +} PyLdbTreeObject; PyAPI_DATA(PyTypeObject) PyLdbTree; PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *); -#define PyLdbTree_AsTree(pyobj) py_talloc_get_type(pyobj, struct ldb_parse_tree) +#define PyLdbTree_AsTree(pyobj) ((PyLdbTreeObject *)pyobj)->tree void PyErr_SetLdbError(int ret, struct ldb_context *ldb_ctx); #define PyErr_LDB_ERROR_IS_ERR_RAISE(ret,ldb) \ -- cgit From 8ce77a57ccc4d5ff4a216d74c4fc58782fc9098c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 05:34:21 +0100 Subject: pyldb: Fix segfault because of incorrect reference counting. --- source4/lib/ldb/Makefile.in | 2 +- source4/lib/ldb/pyldb.c | 27 ++++++++++++++++++++------- source4/scripting/python/pyglue.c | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index 5f59def4af..6155f6e49c 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -88,7 +88,7 @@ STATICLIB = lib/libldb.a lib/$(SONAME): $(LIBSOLIB) ln -fs libldb.$(SHLIBEXT).$(PACKAGE_VERSION) $@ -lib/libldb.$(SHLIBEXT): $(LIBSOLIB) +lib/libldb.$(SHLIBEXT): $(LIBSOLIB) lib/$(SONAME) ln -fs libldb.$(SHLIBEXT).$(PACKAGE_VERSION) $@ lib/libnss_ldb.$(SHLIBEXT).2: $(NSS_OBJ) $(LIBSOLIB) diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 4d4550eb72..a60307c9eb 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -1243,14 +1243,16 @@ struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx, me->num_values = 1; me->values = talloc_array(me, struct ldb_val, me->num_values); me->values[0].length = PyString_Size(set_obj); - me->values[0].data = (uint8_t *)talloc_strdup(me->values, - PyString_AsString(set_obj)); + me->values[0].data = (uint8_t *)talloc_strndup(me->values, + PyString_AsString(set_obj), + me->values[0].length); } else if (PySequence_Check(set_obj)) { int i; me->num_values = PySequence_Size(set_obj); me->values = talloc_array(me, struct ldb_val, me->num_values); for (i = 0; i < me->num_values; i++) { PyObject *obj = PySequence_GetItem(set_obj, i); + me->values[i].length = PyString_Size(obj); me->values[i].data = (uint8_t *)PyString_AsString(obj); } @@ -1336,7 +1338,11 @@ PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *el, PyErr_NoMemory(); return NULL; } - ret->mem_ctx = talloc_reference(mem_ctx, el); + ret->mem_ctx = talloc_new(NULL); + if (talloc_reference(ret->mem_ctx, mem_ctx) == NULL) { + PyErr_NoMemory(); + return NULL; + } ret->el = el; return (PyObject *)ret; } @@ -1356,12 +1362,12 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb if (py_elements != NULL) { int i; - if (!PySequence_Check(py_elements)) { + if (PyString_Check(py_elements)) { el->num_values = 1; el->values = talloc_array(el, struct ldb_val, 1); el->values[0].data = (uint8_t *)PyString_AsString(py_elements); el->values[0].length = PyString_Size(py_elements); - } else { + } else if (PySequence_Check(py_elements)) { el->num_values = PySequence_Size(py_elements); el->values = talloc_array(el, struct ldb_val, el->num_values); for (i = 0; i < el->num_values; i++) { @@ -1369,6 +1375,11 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb el->values[i].data = (uint8_t *)PyString_AsString(item); el->values[i].length = PyString_Size(item); } + } else { + PyErr_SetString(PyExc_TypeError, + "Expected string or list"); + talloc_free(el); + return NULL; } } @@ -1382,7 +1393,8 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb return NULL; } - ret->mem_ctx = ret->el = el; + ret->mem_ctx = talloc_new(NULL); + ret->el = talloc_reference(ret->mem_ctx, el); return (PyObject *)ret; } @@ -1588,7 +1600,8 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw return NULL; } - py_ret->mem_ctx = py_ret->msg = ret; + py_ret->mem_ctx = talloc_new(NULL); + py_ret->msg = talloc_reference(py_ret->mem_ctx, ret); return (PyObject *)py_ret; } diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c index 1b59978477..c882240b63 100644 --- a/source4/scripting/python/pyglue.c +++ b/source4/scripting/python/pyglue.c @@ -18,6 +18,7 @@ #include "includes.h" #include "ldb.h" +#include "ldb_errors.h" #include "param/param.h" #include "auth/credentials/credentials.h" #include "dsdb/samdb/samdb.h" -- cgit From 4d02bbbfb4d74367bde0f768c02ddb99910ef62d Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Mon, 22 Dec 2008 22:35:24 -0800 Subject: s3: Fix stream marshalling to return the correct streaminfo status When there are enough streams on a file to fill up the max_data_count when responding to a trans2 streaminfo, samba is returning NT_STATUS_BUFFER_TOO_SMALL. Windows handles this by returning NT_STATUS_BUFFER_OVERFLOW while still sending as much of the data that it can fit into the buffer. When the windows client sees BUFFER_OVERFLOW, it retries the streaminfo with a larger buffer (2x). The windows client starts at 2K and will continue increasing the buffer size by two until it reaches 64K. If the streams don't fit in 64K the windows client seems to give up. This patch fixes marshall_stream_info to overfill the buffer by 1 stream so that send_trans2_replies can properly detect the overflow and return the correct status. --- source3/smbd/trans2.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 27e29515e4..1d724bafd8 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -3687,7 +3687,7 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams, unsigned int i; unsigned int ofs = 0; - for (i=0; i max_data_bytes) { - TALLOC_FREE(namebuf); - return NT_STATUS_BUFFER_TOO_SMALL; - } - SIVAL(data, ofs+4, namelen); SOFF_T(data, ofs+8, streams[i].size); SOFF_T(data, ofs+16, streams[i].alloc_size); @@ -3725,10 +3720,6 @@ static NTSTATUS marshall_stream_info(unsigned int num_streams, else { unsigned int align = ndr_align_size(next_offset, 8); - if (next_offset + align > max_data_bytes) { - return NT_STATUS_BUFFER_TOO_SMALL; - } - memset(data+next_offset, 0, align); next_offset += align; -- cgit From 58cfb1a9e1470b86f664e489e20cde7af294d07b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 11:25:06 +0100 Subject: python: Define Py_ssize_t if the Python library doesn't. --- source4/lib/ldb/pyldb.c | 6 ++++++ source4/param/pyparam.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index a60307c9eb..f4f43a3d0b 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -28,6 +28,12 @@ #include "ldb_includes.h" #include "pyldb.h" +/* There's no Py_ssize_t in 2.4, apparently */ +#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 +typedef int Py_ssize_t; +typedef inquiry lenfunc; +#endif + /* Picked out of thin air. To do this properly, we should probably have some part of the * errors in LDB be allocated to bindings ? */ #define LDB_ERR_PYTHON_EXCEPTION 142 diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index acadcc08b0..69c2613a09 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -25,6 +25,12 @@ #include "param/loadparm.h" #include "pytalloc.h" +/* There's no Py_ssize_t in 2.4, apparently */ +#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 +typedef int Py_ssize_t; +typedef inquiry lenfunc; +#endif + #define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_ptr(obj) PyAPI_DATA(PyTypeObject) PyLoadparmContext; -- cgit From 00b61ff2cfa145f9c0bcf74a7a2672e1172fb9c1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 11:44:10 +0100 Subject: samba.tests.samdb: Fix test after merger of samba.security and samba.dcerpc.security --- source4/scripting/python/samba/tests/samdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/scripting/python/samba/tests/samdb.py b/source4/scripting/python/samba/tests/samdb.py index 97be5672ce..cce6ea84d3 100644 --- a/source4/scripting/python/samba/tests/samdb.py +++ b/source4/scripting/python/samba/tests/samdb.py @@ -22,7 +22,7 @@ import os from samba.provision import setup_samdb, guess_names, setup_templatesdb, make_smbconf from samba.samdb import SamDB from samba.tests import cmdline_loadparm, TestCaseInTempDir -from samba import security +from samba.dcerpc import security from unittest import TestCase import uuid from samba import param -- cgit From 4bbd2cbab73d46d0f8e8ba3fe164b6802b379b06 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 11:48:14 +0100 Subject: pyldb: Provide replacement for sizeargfunc, not available before Python2.5. --- source4/lib/ldb/pyldb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index f4f43a3d0b..ed77added5 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -32,6 +32,7 @@ #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 typedef int Py_ssize_t; typedef inquiry lenfunc; +typedef intargfunc sizeargfunc; #endif /* Picked out of thin air. To do this properly, we should probably have some part of the -- cgit From 227c8000dfee4248fc2d13104382542e449a1897 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 12:14:25 +0100 Subject: Fix silly typo. --- source4/lib/ldb/pyldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index ed77added5..10b9691ae0 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -32,7 +32,7 @@ #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 typedef int Py_ssize_t; typedef inquiry lenfunc; -typedef intargfunc sizeargfunc; +typedef intargfunc ssizeargfunc; #endif /* Picked out of thin air. To do this properly, we should probably have some part of the -- cgit From cb7d7beb99ab7952b5187c05b2660283d93e59fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 09:50:10 -0800 Subject: Fix another "format not a string literal and no format arguments" warning. Jeremy --- source3/libnet/libnet_samsync_ldif.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source3/libnet/libnet_samsync_ldif.c b/source3/libnet/libnet_samsync_ldif.c index c72eadf03f..3068f8d3eb 100644 --- a/source3/libnet/libnet_samsync_ldif.c +++ b/source3/libnet/libnet_samsync_ldif.c @@ -586,7 +586,7 @@ static NTSTATUS fetch_account_info_to_ldif(TALLOC_CTX *mem_ctx, uchar zero_buf[16]; uint32 rid = 0, group_rid = 0, gidNumber = 0; time_t unix_time; - int i; + int i, ret; memset(zero_buf, '\0', sizeof(zero_buf)); @@ -660,7 +660,10 @@ static NTSTATUS fetch_account_info_to_ldif(TALLOC_CTX *mem_ctx, return NT_STATUS_UNSUCCESSFUL; } gidNumber = groupmap[i].gidNumber; - snprintf(sambaSID, sizeof(sambaSID), groupmap[i].sambaSID); + ret = snprintf(sambaSID, sizeof(sambaSID), "%s", groupmap[i].sambaSID); + if (ret < 0 || ret == sizeof(sambaSID)) { + return NT_STATUS_UNSUCCESSFUL; + } /* Set up sambaAcctFlags */ flags = pdb_encode_acct_ctrl(r->acct_flags, -- cgit From 7fd114bab72e4cc9bdb7a0017055b68ea7523f0a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 10:27:24 -0800 Subject: Fix more "warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result" Jeremy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/passdb/passdb.c | 85 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 8367d6a9ad..bb0daaa3f4 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -686,12 +686,16 @@ NTSTATUS local_password_change(const char *user_name, } if (!NT_STATUS_IS_OK(result)) { - asprintf(pp_err_str, "Failed to " "initialize account for user %s: %s\n", - user_name, nt_errstr(result)); + if (asprintf(pp_err_str, "Failed to " "initialize account for user %s: %s\n", + user_name, nt_errstr(result)) < 0) { + *pp_err_str = NULL; + } return result; } } else { - asprintf(pp_err_str, "Failed to find entry for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to find entry for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } return NT_STATUS_NO_SUCH_USER; } } else { @@ -704,19 +708,25 @@ NTSTATUS local_password_change(const char *user_name, other_acb = (pdb_get_acct_ctrl(sam_pass) & (~(ACB_WSTRUST|ACB_DOMTRUST|ACB_SVRTRUST|ACB_NORMAL))); if (local_flags & LOCAL_TRUST_ACCOUNT) { if (!pdb_set_acct_ctrl(sam_pass, ACB_WSTRUST | other_acb, PDB_CHANGED) ) { - asprintf(pp_err_str, "Failed to set 'trusted workstation account' flags for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to set 'trusted workstation account' flags for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } } else if (local_flags & LOCAL_INTERDOM_ACCOUNT) { if (!pdb_set_acct_ctrl(sam_pass, ACB_DOMTRUST | other_acb, PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to set 'domain trust account' flags for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to set 'domain trust account' flags for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } } else { if (!pdb_set_acct_ctrl(sam_pass, ACB_NORMAL | other_acb, PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to set 'normal account' flags for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to set 'normal account' flags for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } @@ -729,13 +739,17 @@ NTSTATUS local_password_change(const char *user_name, if (local_flags & LOCAL_DISABLE_USER) { if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_DISABLED, PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to set 'disabled' flag for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to set 'disabled' flag for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } } else if (local_flags & LOCAL_ENABLE_USER) { if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_DISABLED), PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to unset 'disabled' flag for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to unset 'disabled' flag for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } @@ -743,7 +757,9 @@ NTSTATUS local_password_change(const char *user_name, if (local_flags & LOCAL_SET_NO_PASSWORD) { if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_PWNOTREQ, PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to set 'no password required' flag for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to set 'no password required' flag for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } @@ -759,19 +775,25 @@ NTSTATUS local_password_change(const char *user_name, */ if ((pdb_get_lanman_passwd(sam_pass)==NULL) && (pdb_get_acct_ctrl(sam_pass)&ACB_DISABLED)) { if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_DISABLED), PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to unset 'disabled' flag for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to unset 'disabled' flag for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } } if (!pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_PWNOTREQ), PDB_CHANGED)) { - asprintf(pp_err_str, "Failed to unset 'no password required' flag for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to unset 'no password required' flag for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } if (!pdb_set_plaintext_passwd (sam_pass, new_passwd)) { - asprintf(pp_err_str, "Failed to set password for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to set password for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } @@ -779,34 +801,51 @@ NTSTATUS local_password_change(const char *user_name, if (local_flags & LOCAL_ADD_USER) { if (NT_STATUS_IS_OK(pdb_add_sam_account(sam_pass))) { - asprintf(pp_msg_str, "Added user %s.\n", user_name); + if (asprintf(pp_msg_str, "Added user %s.\n", user_name) < 0) { + *pp_msg_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_OK; } else { - asprintf(pp_err_str, "Failed to add entry for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to add entry for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } } else if (local_flags & LOCAL_DELETE_USER) { if (!NT_STATUS_IS_OK(pdb_delete_sam_account(sam_pass))) { - asprintf(pp_err_str, "Failed to delete entry for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to delete entry for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return NT_STATUS_UNSUCCESSFUL; } - asprintf(pp_msg_str, "Deleted user %s.\n", user_name); + if (asprintf(pp_msg_str, "Deleted user %s.\n", user_name) < 0) { + *pp_msg_str = NULL; + } } else { result = pdb_update_sam_account(sam_pass); if(!NT_STATUS_IS_OK(result)) { - asprintf(pp_err_str, "Failed to modify entry for user %s.\n", user_name); + if (asprintf(pp_err_str, "Failed to modify entry for user %s.\n", user_name) < 0) { + *pp_err_str = NULL; + } TALLOC_FREE(sam_pass); return result; } - if(local_flags & LOCAL_DISABLE_USER) - asprintf(pp_msg_str, "Disabled user %s.\n", user_name); - else if (local_flags & LOCAL_ENABLE_USER) - asprintf(pp_msg_str, "Enabled user %s.\n", user_name); - else if (local_flags & LOCAL_SET_NO_PASSWORD) - asprintf(pp_msg_str, "User %s password set to none.\n", user_name); + if(local_flags & LOCAL_DISABLE_USER) { + if (asprintf(pp_msg_str, "Disabled user %s.\n", user_name) < 0) { + *pp_msg_str = NULL; + } + } else if (local_flags & LOCAL_ENABLE_USER) { + if (asprintf(pp_msg_str, "Enabled user %s.\n", user_name) < 0) { + *pp_msg_str = NULL; + } + } else if (local_flags & LOCAL_SET_NO_PASSWORD) { + if (asprintf(pp_msg_str, "User %s password set to none.\n", user_name) < 0) { + *pp_msg_str = NULL; + } + } } TALLOC_FREE(sam_pass); -- cgit From 465f78021e609719bf25b7d2933c47b7ab1b6940 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 19:28:22 +0100 Subject: Move Samba4-specific file out of common libtevent. --- lib/tevent/config.mk | 2 +- lib/tevent/tevent_s4.c | 72 --------------------------------------- source4/lib/basic.mk | 1 + source4/lib/events/config.mk | 2 +- source4/lib/events/events_dummy.c | 4 --- source4/lib/events/tevent_s4.c | 72 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 78 deletions(-) delete mode 100644 lib/tevent/tevent_s4.c delete mode 100644 source4/lib/events/events_dummy.c create mode 100644 source4/lib/events/tevent_s4.c diff --git a/lib/tevent/config.mk b/lib/tevent/config.mk index bce92bb82d..01c628cd2c 100644 --- a/lib/tevent/config.mk +++ b/lib/tevent/config.mk @@ -41,7 +41,7 @@ CFLAGS = -I../lib/tevent # End SUBSYSTEM LIBTEVENT ################################################ -LIBTEVENT_OBJ_FILES = $(addprefix $(libteventsrcdir)/, tevent.o tevent_timed.o tevent_signal.o tevent_debug.o tevent_util.o tevent_s4.o) +LIBTEVENT_OBJ_FILES = $(addprefix $(libteventsrcdir)/, tevent.o tevent_timed.o tevent_signal.o tevent_debug.o tevent_util.o) PUBLIC_HEADERS += $(addprefix $(libteventsrcdir)/, tevent.h tevent_internal.h) diff --git a/lib/tevent/tevent_s4.c b/lib/tevent/tevent_s4.c deleted file mode 100644 index 80267fdd22..0000000000 --- a/lib/tevent/tevent_s4.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Copyright (C) Andrew Tridgell 2003 - - 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 . -*/ - -#include "includes.h" -#include "tevent.h" -#include "tevent_internal.h" - -/* - this is used to catch debug messages from events -*/ -static void ev_wrap_debug(void *context, enum ev_debug_level level, - const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0); - -static void ev_wrap_debug(void *context, enum ev_debug_level level, - const char *fmt, va_list ap) -{ - int samba_level = -1; - char *s = NULL; - switch (level) { - case EV_DEBUG_FATAL: - samba_level = 0; - break; - case EV_DEBUG_ERROR: - samba_level = 1; - break; - case EV_DEBUG_WARNING: - samba_level = 2; - break; - case EV_DEBUG_TRACE: - samba_level = 5; - break; - - }; - vasprintf(&s, fmt, ap); - if (!s) return; - DEBUG(samba_level, ("events: %s\n", s)); - free(s); -} - -/* - create a event_context structure. This must be the first events - call, and all subsequent calls pass this event_context as the first - element. Event handlers also receive this as their first argument. - - This samba4 specific call sets the samba4 debug handler. -*/ -struct event_context *s4_event_context_init(TALLOC_CTX *mem_ctx) -{ - struct event_context *ev; - - ev = event_context_init_byname(mem_ctx, NULL); - if (ev) { - ev_set_debug(ev, ev_wrap_debug, NULL); - } - return ev; -} - diff --git a/source4/lib/basic.mk b/source4/lib/basic.mk index 4d076684cd..4b40ed41d4 100644 --- a/source4/lib/basic.mk +++ b/source4/lib/basic.mk @@ -23,3 +23,4 @@ TDB_WRAP_OBJ_FILES = $(libsrcdir)/tdb_wrap.o PUBLIC_HEADERS += $(libsrcdir)/tdb_wrap.h SMBREADLINE_OBJ_LIST = $(SMBREADLINE_OBJ_FILES) + diff --git a/source4/lib/events/config.mk b/source4/lib/events/config.mk index b9d6879b3c..a1b2cd218a 100644 --- a/source4/lib/events/config.mk +++ b/source4/lib/events/config.mk @@ -2,6 +2,6 @@ PUBLIC_DEPENDENCIES = LIBTEVENT CFLAGS = -Ilib/events -LIBEVENTS_OBJ_FILES = $(addprefix $(libeventssrcdir)/, events_dummy.o) +LIBEVENTS_OBJ_FILES = $(addprefix $(libeventssrcdir)/, tevent_s4.o) PUBLIC_HEADERS += $(addprefix $(libeventssrcdir)/, events.h events_internal.h) diff --git a/source4/lib/events/events_dummy.c b/source4/lib/events/events_dummy.c deleted file mode 100644 index 15bb25e953..0000000000 --- a/source4/lib/events/events_dummy.c +++ /dev/null @@ -1,4 +0,0 @@ -void __events_dummy(void) -{ -} - diff --git a/source4/lib/events/tevent_s4.c b/source4/lib/events/tevent_s4.c new file mode 100644 index 0000000000..80267fdd22 --- /dev/null +++ b/source4/lib/events/tevent_s4.c @@ -0,0 +1,72 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) Andrew Tridgell 2003 + + 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 . +*/ + +#include "includes.h" +#include "tevent.h" +#include "tevent_internal.h" + +/* + this is used to catch debug messages from events +*/ +static void ev_wrap_debug(void *context, enum ev_debug_level level, + const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0); + +static void ev_wrap_debug(void *context, enum ev_debug_level level, + const char *fmt, va_list ap) +{ + int samba_level = -1; + char *s = NULL; + switch (level) { + case EV_DEBUG_FATAL: + samba_level = 0; + break; + case EV_DEBUG_ERROR: + samba_level = 1; + break; + case EV_DEBUG_WARNING: + samba_level = 2; + break; + case EV_DEBUG_TRACE: + samba_level = 5; + break; + + }; + vasprintf(&s, fmt, ap); + if (!s) return; + DEBUG(samba_level, ("events: %s\n", s)); + free(s); +} + +/* + create a event_context structure. This must be the first events + call, and all subsequent calls pass this event_context as the first + element. Event handlers also receive this as their first argument. + + This samba4 specific call sets the samba4 debug handler. +*/ +struct event_context *s4_event_context_init(TALLOC_CTX *mem_ctx) +{ + struct event_context *ev; + + ev = event_context_init_byname(mem_ctx, NULL); + if (ev) { + ev_set_debug(ev, ev_wrap_debug, NULL); + } + return ev; +} + -- cgit From aa4abac6b73db7be694bc9f6f097092271357d20 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 10:42:25 -0800 Subject: Fix more ‘asprintf’, declared with attribute warn_unused_result. Jeremy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/passdb/pdb_interface.c | 22 ++++++++++++++-------- source3/passdb/pdb_ldap.c | 7 ++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index 5a79f09db0..b13644bac3 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -179,20 +179,26 @@ static struct pdb_methods *pdb_get_methods_reload( bool reload ) pdb->free_private_data( &(pdb->private_data) ); if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) { char *msg = NULL; - asprintf(&msg, "pdb_get_methods_reload: " - "failed to get pdb methods for backend %s\n", - lp_passdb_backend()); - smb_panic(msg); + if (asprintf(&msg, "pdb_get_methods_reload: " + "failed to get pdb methods for backend %s\n", + lp_passdb_backend()) > 0) { + smb_panic(msg); + } else { + smb_panic("pdb_get_methods_reload"); + } } } if ( !pdb ) { if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) { char *msg = NULL; - asprintf(&msg, "pdb_get_methods_reload: " - "failed to get pdb methods for backend %s\n", - lp_passdb_backend()); - smb_panic(msg); + if (asprintf(&msg, "pdb_get_methods_reload: " + "failed to get pdb methods for backend %s\n", + lp_passdb_backend()) > 0) { + smb_panic(msg); + } else { + smb_panic("pdb_get_methods_reload"); + } } } diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c index 95e9a01ba3..f031483ea1 100644 --- a/source3/passdb/pdb_ldap.c +++ b/source3/passdb/pdb_ldap.c @@ -4184,9 +4184,10 @@ static char *get_ldap_filter(TALLOC_CTX *mem_ctx, const char *username) char *escaped = NULL; char *result = NULL; - asprintf(&filter, "(&%s(objectclass=%s))", - "(uid=%u)", LDAP_OBJ_SAMBASAMACCOUNT); - if (filter == NULL) goto done; + if (asprintf(&filter, "(&%s(objectclass=%s))", + "(uid=%u)", LDAP_OBJ_SAMBASAMACCOUNT) < 0) { + goto done; + } escaped = escape_ldap_string_alloc(username); if (escaped == NULL) goto done; -- cgit From 22703bf3ffc3692a719d6bd593d3705697045bea Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 19:39:52 +0100 Subject: standalone: Use more variables, preparing to include these files from main Samba 4 makefile. --- lib/talloc/talloc.mk | 9 +++++---- lib/tdb/tdb.mk | 11 ++++++----- lib/tevent/tevent.mk | 11 ++++++----- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/talloc/talloc.mk b/lib/talloc/talloc.mk index 7f0afed560..ce7784c8a2 100644 --- a/lib/talloc/talloc.mk +++ b/lib/talloc/talloc.mk @@ -2,20 +2,21 @@ TALLOC_OBJ = $(tallocdir)/talloc.o TALLOC_SOLIB = libtalloc.$(SHLIBEXT).$(PACKAGE_VERSION) TALLOC_SONAME = libtalloc.$(SHLIBEXT).1 +TALLOC_STLIB = libtalloc.a -all:: libtalloc.a $(TALLOC_SOLIB) testsuite +all:: $(TALLOC_STLIB) $(TALLOC_SOLIB) testsuite testsuite:: $(LIBOBJ) testsuite.o testsuite_main.o $(CC) $(CFLAGS) -o testsuite testsuite.o testsuite_main.o $(LIBOBJ) $(LIBS) -libtalloc.a: $(LIBOBJ) +$(TALLOC_STLIB): $(LIBOBJ) ar -rv $@ $(LIBOBJ) @-ranlib $@ install:: all ${INSTALLCMD} -d $(DESTDIR)$(libdir) ${INSTALLCMD} -d $(DESTDIR)$(libdir)/pkgconfig - ${INSTALLCMD} -m 755 libtalloc.a $(DESTDIR)$(libdir) + ${INSTALLCMD} -m 755 $(TALLOC_STLIB) $(DESTDIR)$(libdir) ${INSTALLCMD} -m 755 $(TALLOC_SOLIB) $(DESTDIR)$(libdir) ${INSTALLCMD} -d $(DESTDIR)${includedir} ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(DESTDIR)$(includedir) @@ -28,7 +29,7 @@ install:: all doc:: talloc.3 talloc.3.html clean:: - rm -f *~ $(LIBOBJ) $(TALLOC_SOLIB) libtalloc.a testsuite testsuite.o testsuite_main.o *.gc?? talloc.3 talloc.3.html + rm -f *~ $(LIBOBJ) $(TALLOC_SOLIB) $(TALLOC_STLIB) testsuite testsuite.o testsuite_main.o *.gc?? talloc.3 talloc.3.html test:: testsuite ./testsuite diff --git a/lib/tdb/tdb.mk b/lib/tdb/tdb.mk index 72f44e7211..b786bdbf54 100644 --- a/lib/tdb/tdb.mk +++ b/lib/tdb/tdb.mk @@ -7,8 +7,9 @@ ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL) TDB_SONAME = libtdb.$(SHLIBEXT).1 TDB_SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION) +TDB_STLIB = libtdb.a -TDB_LIB = libtdb.a +TDB_LIB = $(TDB_STLIB) bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB) $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm @@ -30,7 +31,7 @@ test:: bin/tdbtorture$(EXEEXT) $(TDB_SONAME) clean:: rm -f test.db test.tdb torture.tdb test.gdbm - rm -f $(TDB_SONAME) $(TDB_SOLIB) libtdb.a libtdb.$(SHLIBEXT) + rm -f $(TDB_SONAME) $(TDB_SOLIB) $(TDB_STLIB) libtdb.$(SHLIBEXT) rm -f $(ALL_PROGS) tdb.pc build-python:: tdb.$(SHLIBEXT) @@ -68,10 +69,10 @@ installheaders:: installdirs installlibs:: all installdirs cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig - cp libtdb.a $(TDB_SOLIB) $(DESTDIR)$(libdir) + cp $(TDB_STLIB) $(TDB_SOLIB) $(DESTDIR)$(libdir) -libtdb.a: $(TDB_OBJ) - ar -rv libtdb.a $(TDB_OBJ) +$(TDB_STLIB): $(TDB_OBJ) + ar -rv $(TDB_STLIB) $(TDB_OBJ) libtdb.$(SHLIBEXT): $(TDB_SOLIB) ln -fs $< $@ diff --git a/lib/tevent/tevent.mk b/lib/tevent/tevent.mk index 8b4c6ed27e..2e4d5a96af 100644 --- a/lib/tevent/tevent.mk +++ b/lib/tevent/tevent.mk @@ -1,8 +1,9 @@ TEVENT_SONAME = libtevent.$(SHLIBEXT).0 TEVENT_SOLIB = libtevent.$(SHLIBEXT).$(PACKAGE_VERSION) +TEVENT_STLIB = libtevent.a -libtevent.a: $(TEVENT_OBJ) - ar -rv libtevent.a $(TEVENT_OBJ) +$(TEVENT_STLIB): $(TEVENT_OBJ) + ar -rv $(TEVENT_STLIB) $(TEVENT_OBJ) libtevent.$(SHLIBEXT): $(TEVENT_SOLIB) ln -fs $< $@ @@ -23,14 +24,14 @@ installheaders:: installdirs installlibs:: installdirs cp tevent.pc $(DESTDIR)$(libdir)/pkgconfig - cp libtevent.a $(TEVENT_SOLIB) $(DESTDIR)$(libdir) + cp $(TEVENT_STLIB) $(TEVENT_SOLIB) $(DESTDIR)$(libdir) install:: all installdirs installheaders installlibs $(PYTHON_INSTALL_TARGET) clean:: - rm -f $(TEVENT_SONAME) $(TEVENT_SOLIB) libtevent.a libtevent.$(SHLIBEXT) + rm -f $(TEVENT_SONAME) $(TEVENT_SOLIB) $(TEVENT_STLIB) libtevent.$(SHLIBEXT) rm -f tevent.pc - rm -f _libtevent.$(SHLIBEXT) + rm -f tevent.$(SHLIBEXT) #python stuff -- cgit From 8b24da201b78ddda3738564f2d69c96ab4ed9919 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 19:59:57 +0100 Subject: Allow using external libtevent. --- lib/tevent/config.mk | 11 ----------- source4/build/smb_build/summary.pm | 1 + source4/configure.ac | 13 +++++++++++-- source4/main.mk | 1 - 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/tevent/config.mk b/lib/tevent/config.mk index 01c628cd2c..e4fb9a8088 100644 --- a/lib/tevent/config.mk +++ b/lib/tevent/config.mk @@ -44,14 +44,3 @@ CFLAGS = -I../lib/tevent LIBTEVENT_OBJ_FILES = $(addprefix $(libteventsrcdir)/, tevent.o tevent_timed.o tevent_signal.o tevent_debug.o tevent_util.o) PUBLIC_HEADERS += $(addprefix $(libteventsrcdir)/, tevent.h tevent_internal.h) - -# TODO: Change python stuff to tevent -[PYTHON::swig_events] -LIBRARY_REALNAME = tevent.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = LIBTEVENT PYTALLOC LIBSAMBA-UTIL - -swig_events_OBJ_FILES = $(libteventsrcdir)/pytevent.o - -$(swig_events_OBJ_FILES): CFLAGS+=$(CFLAG_NO_CAST_QUAL) - -PC_FILES += $(libteventsrcdir)/tevent.pc diff --git a/source4/build/smb_build/summary.pm b/source4/build/smb_build/summary.pm index f6c1c50550..c7916216ab 100644 --- a/source4/build/smb_build/summary.pm +++ b/source4/build/smb_build/summary.pm @@ -57,6 +57,7 @@ sub show($$) showisexternal($output, "popt", "LIBPOPT"); showisexternal($output, "talloc", "LIBTALLOC"); showisexternal($output, "tdb", "LIBTDB"); + showisexternal($output, "tevent", "LIBTEVENT"); showisexternal($output, "ldb", "LIBLDB"); print "Developer mode: ".(enabled($config->{developer})?"yes":"no")."\n"; print "Automatic dependencies: ". diff --git a/source4/configure.ac b/source4/configure.ac index aa5a3f3b3e..45154c8c88 100644 --- a/source4/configure.ac +++ b/source4/configure.ac @@ -34,7 +34,6 @@ m4_include(../nsswitch/nsstest.m4) m4_include(../pidl/config.m4) AC_CONFIG_FILES(lib/registry/registry.pc) -AC_CONFIG_FILES(../lib/tevent/tevent.pc) AC_CONFIG_FILES(librpc/dcerpc.pc) AC_CONFIG_FILES(../librpc/ndr.pc) AC_CONFIG_FILES(../lib/torture/torture.pc) @@ -61,6 +60,17 @@ SMB_EXT_LIB_FROM_PKGCONFIG(LIBTDB, tdb >= 1.1.3, SMB_INCLUDE_MK(../lib/tdb/python.mk) +SMB_EXT_LIB_FROM_PKGCONFIG(LIBTEVENT, tevent >= 1.0.0, + [], + [ + m4_include(../lib/tevent/libtevent.m4) + SMB_INCLUDE_MK(../lib/tevent/config.mk) + AC_CONFIG_FILES(../lib/tevent/tevent.pc) + ] +) + +SMB_INCLUDE_MK(../lib/tevent/python.mk) + SMB_EXT_LIB_FROM_PKGCONFIG(LIBLDB, ldb = 0.9.1, [ SMB_INCLUDE_MK(lib/ldb/ldb_ildap/config.mk) @@ -96,7 +106,6 @@ SMB_EXT_LIB_FROM_PKGCONFIG(LIBLDB, ldb = 0.9.1, SMB_INCLUDE_MK(lib/ldb/python.mk) m4_include(lib/tls/config.m4) -m4_include(../lib/tevent/libtevent.m4) dnl m4_include(auth/kerberos/config.m4) m4_include(auth/gensec/config.m4) diff --git a/source4/main.mk b/source4/main.mk index e54196a2f9..1d4ffc5d44 100644 --- a/source4/main.mk +++ b/source4/main.mk @@ -14,7 +14,6 @@ mkinclude lib/ldb-samba/config.mk mkinclude lib/tls/config.mk mkinclude lib/registry/config.mk mkinclude lib/messaging/config.mk -mkinclude ../lib/tevent/config.mk mkinclude lib/events/config.mk mkinclude lib/cmdline/config.mk mkinclude ../lib/socket_wrapper/config.mk -- cgit From 31dc07ee2868c99792e0f71239f79ba49062e7e2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 20:13:17 +0100 Subject: pytevent: Add missing file. --- lib/tevent/python.mk | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/tevent/python.mk diff --git a/lib/tevent/python.mk b/lib/tevent/python.mk new file mode 100644 index 0000000000..d48c4f5b9c --- /dev/null +++ b/lib/tevent/python.mk @@ -0,0 +1,10 @@ +# TODO: Change python stuff to tevent +[PYTHON::swig_events] +LIBRARY_REALNAME = tevent.$(SHLIBEXT) +PRIVATE_DEPENDENCIES = LIBTEVENT PYTALLOC LIBSAMBA-UTIL + +swig_events_OBJ_FILES = $(libteventsrcdir)/pytevent.o + +$(swig_events_OBJ_FILES): CFLAGS+=$(CFLAG_NO_CAST_QUAL) + +PC_FILES += $(libteventsrcdir)/tevent.pc -- cgit From 7c6a20a439e5e6e9b4149df77896eea57d931e73 Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Tue, 23 Dec 2008 20:17:59 +0100 Subject: Add missing includes, required for use of gensec by 3rd-party applications. --- source4/auth/gensec/gensec.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source4/auth/gensec/gensec.h b/source4/auth/gensec/gensec.h index 235d2008fb..87c9b4d169 100644 --- a/source4/auth/gensec/gensec.h +++ b/source4/auth/gensec/gensec.h @@ -23,6 +23,9 @@ #ifndef __GENSEC_H__ #define __GENSEC_H__ +#include "../lib/util/data_blob.h" +#include "libcli/util/ntstatus.h" + #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10" #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2" #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2" -- cgit From b143938b8afaa7c7759e09228cc0d92ff97121d0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 11:27:19 -0800 Subject: Fix more asprintf errors and error code paths. Jeremy. --- source3/libads/ldap.c | 14 +++++++++----- source3/libads/ldap_printer.c | 26 ++++++++++++++++++++++---- source3/printing/nt_printing.c | 8 +++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index cf8a7ebb1b..a598580941 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -603,7 +603,10 @@ got_connection: /* Must use the userPrincipalName value here or sAMAccountName and not servicePrincipalName; found by Guenther Deschner */ - asprintf(&ads->auth.user_name, "%s$", global_myname() ); + if (asprintf(&ads->auth.user_name, "%s$", global_myname() ) == -1) { + DEBUG(0,("ads_connect: asprintf fail.\n")); + ads->auth.user_name = NULL; + } } if (!ads->auth.realm) { @@ -619,10 +622,11 @@ got_connection: /* this is a really nasty hack to avoid ADS DNS problems. It needs a patch to MIT kerberos to work (tridge) */ { - char *env; - asprintf(&env, "KRB5_KDC_ADDRESS_%s", ads->config.realm); - setenv(env, ads->auth.kdc_server, 1); - free(env); + char *env = NULL; + if (asprintf(&env, "KRB5_KDC_ADDRESS_%s", ads->config.realm) > 0) { + setenv(env, ads->auth.kdc_server, 1); + free(env); + } } #endif diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 0a42f00b39..169c3bba1d 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -31,7 +31,7 @@ const char *servername) { ADS_STATUS status; - char *srv_dn, **srv_cn, *s; + char *srv_dn, **srv_cn, *s = NULL; const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; status = ads_find_machine_acct(ads, res, servername); @@ -41,25 +41,43 @@ return status; } if (ads_count_replies(ads, *res) != 1) { + if (res) { + ads_msgfree(ads, *res); + *res = NULL; + } return ADS_ERROR(LDAP_NO_SUCH_OBJECT); } srv_dn = ldap_get_dn(ads->ldap.ld, *res); if (srv_dn == NULL) { + if (res) { + ads_msgfree(ads, *res); + *res = NULL; + } return ADS_ERROR(LDAP_NO_MEMORY); } srv_cn = ldap_explode_dn(srv_dn, 1); if (srv_cn == NULL) { ldap_memfree(srv_dn); + if (res) { + ads_msgfree(ads, *res); + *res = NULL; + } return ADS_ERROR(LDAP_INVALID_DN_SYNTAX); } - ads_msgfree(ads, *res); + if (res) { + ads_msgfree(ads, *res); + *res = NULL; + } - asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer); + if (asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer) == -1) { + ldap_memfree(srv_dn); + return ADS_ERROR(LDAP_NO_MEMORY); + } status = ads_search(ads, res, s, attrs); ldap_memfree(srv_dn); ldap_value_free(srv_cn); - free(s); + SAFE_FREE(s); return status; } diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index ba1fb4352c..2b24fdd923 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -3381,7 +3381,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads, NT_PRINTER_INFO_LEVEL *printer) { ADS_STATUS ads_rc; - LDAPMessage *res; + LDAPMessage *res = NULL; char *prt_dn = NULL; DEBUG(5, ("unpublishing printer %s\n", printer->info_2->printername)); @@ -3390,7 +3390,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads, ads_rc = ads_find_printer_on_server(ads, &res, printer->info_2->sharename, global_myname()); - if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) { + if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) { prt_dn = ads_get_dn(ads, res); if (!prt_dn) { ads_msgfree(ads, res); @@ -3400,7 +3400,9 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads, ads_memfree(ads, prt_dn); } - ads_msgfree(ads, res); + if (res) { + ads_msgfree(ads, res); + } return WERR_OK; } -- cgit From 94df767f21003507f01b9b08d7c52b5b8819977f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 11:45:26 -0800 Subject: More asprintf warning fixes. Jeremy. --- source3/libads/krb5_setpw.c | 27 ++++++++++++++++++--------- source3/passdb/login_cache.c | 7 +++---- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/source3/libads/krb5_setpw.c b/source3/libads/krb5_setpw.c index 04ee6ee62a..5032ffd14c 100644 --- a/source3/libads/krb5_setpw.c +++ b/source3/libads/krb5_setpw.c @@ -605,7 +605,13 @@ ADS_STATUS ads_krb5_set_password(const char *kdc_host, const char *princ, } realm++; - asprintf(&princ_name, "kadmin/changepw@%s", realm); + if (asprintf(&princ_name, "kadmin/changepw@%s", realm) == -1) { + krb5_cc_close(context, ccache); + krb5_free_context(context); + DEBUG(1,("asprintf failed\n")); + return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + } + ret = smb_krb5_parse_name(context, princ_name, &creds.server); if (ret) { krb5_cc_close(context, ccache); @@ -736,8 +742,13 @@ static ADS_STATUS ads_krb5_chg_password(const char *kdc_host, krb5_get_init_creds_opt_set_proxiable(&opts, 0); /* We have to obtain an INITIAL changepw ticket for changing password */ - asprintf(&chpw_princ, "kadmin/changepw@%s", - (char *) krb5_princ_realm(context, princ)); + if (asprintf(&chpw_princ, "kadmin/changepw@%s", + (char *) krb5_princ_realm(context, princ)) == -1) { + krb5_free_context(context); + DEBUG(1,("ads_krb5_chg_password: asprintf fail\n")); + return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + } + password = SMB_STRDUP(oldpw); ret = krb5_get_init_creds_password(context, &creds, princ, password, kerb_prompter, NULL, @@ -807,16 +818,14 @@ ADS_STATUS ads_set_machine_password(ADS_STRUCT *ads, as otherwise the server might end up setting the password for a user instead */ - asprintf(&principal, "%s@%s", machine_account, ads->config.realm); + if (asprintf(&principal, "%s@%s", machine_account, ads->config.realm) < 0) { + return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + } status = ads_krb5_set_password(ads->auth.kdc_server, principal, password, ads->auth.time_offset); - free(principal); - + SAFE_FREE(principal); return status; } - - - #endif diff --git a/source3/passdb/login_cache.c b/source3/passdb/login_cache.c index 8222f77b95..4e14293e73 100644 --- a/source3/passdb/login_cache.c +++ b/source3/passdb/login_cache.c @@ -35,14 +35,13 @@ bool login_cache_init(void) /* skip file open if it's already opened */ if (cache) return True; - asprintf(&cache_fname, "%s/%s", lp_lockdir(), LOGIN_CACHE_FILE); - if (cache_fname) - DEBUG(5, ("Opening cache file at %s\n", cache_fname)); - else { + if (asprintf(&cache_fname, "%s/%s", lp_lockdir(), LOGIN_CACHE_FILE) == -1) { DEBUG(0, ("Filename allocation failed.\n")); return False; } + DEBUG(5, ("Opening cache file at %s\n", cache_fname)); + cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644); -- cgit From 1966a947d3f8d432d3af5a9c0004e27561ae7f65 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 11:56:48 -0800 Subject: More asprintf warning fixes. Jeremy. --- source3/libads/ads_struct.c | 11 ++++++++--- source3/libads/kerberos_keytab.c | 20 ++++++++++++++++---- source3/libads/ldap_user.c | 5 ++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index 8cc2f1215e..aef35ad822 100644 --- a/source3/libads/ads_struct.c +++ b/source3/libads/ads_struct.c @@ -57,12 +57,17 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int strlcat(ret, p, len); while ((p=strtok_r(NULL, sep, &saveptr)) != NULL) { - char *s; + int retval; + char *s = NULL; if (reverse) - asprintf(&s, "%s%s,%s", field, p, ret); + retval = asprintf(&s, "%s%s,%s", field, p, ret); else - asprintf(&s, "%s,%s%s", ret, field, p); + retval = asprintf(&s, "%s,%s%s", ret, field, p); free(ret); + if (retval == -1) { + free(r); + return NULL; + } ret = SMB_STRDUP(s); free(s); } diff --git a/source3/libads/kerberos_keytab.c b/source3/libads/kerberos_keytab.c index c4e67091dd..7c028cb78f 100644 --- a/source3/libads/kerberos_keytab.c +++ b/source3/libads/kerberos_keytab.c @@ -299,17 +299,29 @@ int ads_keytab_add_entry(ADS_STRUCT *ads, const char *srvPrinc) if (strchr_m(srvPrinc, '@')) { /* It's a fully-named principal. */ - asprintf(&princ_s, "%s", srvPrinc); + if (asprintf(&princ_s, "%s", srvPrinc) == -1) { + ret = -1; + goto out; + } } else if (srvPrinc[strlen(srvPrinc)-1] == '$') { /* It's the machine account, as used by smbclient clients. */ - asprintf(&princ_s, "%s@%s", srvPrinc, lp_realm()); + if (asprintf(&princ_s, "%s@%s", srvPrinc, lp_realm()) == -1) { + ret = -1; + goto out; + } } else { /* It's a normal service principal. Add the SPN now so that we * can obtain credentials for it and double-check the salt value * used to generate the service's keys. */ - asprintf(&princ_s, "%s/%s@%s", srvPrinc, my_fqdn, lp_realm()); - asprintf(&short_princ_s, "%s/%s@%s", srvPrinc, machine_name, lp_realm()); + if (asprintf(&princ_s, "%s/%s@%s", srvPrinc, my_fqdn, lp_realm()) == -1) { + ret = -1; + goto out; + } + if (asprintf(&short_princ_s, "%s/%s@%s", srvPrinc, machine_name, lp_realm()) == -1) { + ret = -1; + goto out; + } /* According to http://support.microsoft.com/kb/326985/en-us, certain principal names are automatically mapped to the host/... diff --git a/source3/libads/ldap_user.c b/source3/libads/ldap_user.c index bef2c91292..eecd9045e5 100644 --- a/source3/libads/ldap_user.c +++ b/source3/libads/ldap_user.c @@ -35,7 +35,10 @@ return ADS_ERROR(LDAP_NO_MEMORY); } - asprintf(&ldap_exp, "(samAccountName=%s)", escaped_user); + if (asprintf(&ldap_exp, "(samAccountName=%s)", escaped_user) == -1) { + SAFE_FREE(escaped_user); + return ADS_ERROR(LDAP_NO_MEMORY); + } status = ads_search(ads, res, ldap_exp, attrs); SAFE_FREE(ldap_exp); SAFE_FREE(escaped_user); -- cgit From d0eeb9aa8db42ed1fc18024614560820354e6dfa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 2008 12:11:12 -0800 Subject: Fix more asprintf warnings and some error path errors. Jeremy. --- source3/libads/util.c | 12 ++++++++++-- source3/locking/posix.c | 13 ++++++------- source3/printing/nt_printing.c | 22 +++++++++++----------- source3/printing/print_generic.c | 4 +++- source3/rpc_server/srv_lsa_hnd.c | 11 +++++++---- source3/smbd/fileio.c | 9 ++++++--- source3/smbd/seal.c | 3 +-- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/source3/libads/util.c b/source3/libads/util.c index 9866a15285..2c7ccfebd6 100644 --- a/source3/libads/util.c +++ b/source3/libads/util.c @@ -71,7 +71,11 @@ ADS_STATUS ads_guess_service_principal(ADS_STRUCT *ads, strlower_m(server); strupper_m(server_realm); - asprintf(&princ, "ldap/%s@%s", server, server_realm); + if (asprintf(&princ, "ldap/%s@%s", server, server_realm) == -1) { + SAFE_FREE(server); + SAFE_FREE(server_realm); + return ADS_ERROR(LDAP_NO_MEMORY); + } SAFE_FREE(server); SAFE_FREE(server_realm); @@ -93,7 +97,11 @@ ADS_STATUS ads_guess_service_principal(ADS_STRUCT *ads, strlower_m(server); strupper_m(server_realm); - asprintf(&princ, "ldap/%s@%s", server, server_realm); + if (asprintf(&princ, "ldap/%s@%s", server, server_realm) == -1) { + SAFE_FREE(server); + SAFE_FREE(server_realm); + return ADS_ERROR(LDAP_NO_MEMORY); + } SAFE_FREE(server); SAFE_FREE(server_realm); diff --git a/source3/locking/posix.c b/source3/locking/posix.c index c036ee597c..9b51c3aa6a 100644 --- a/source3/locking/posix.c +++ b/source3/locking/posix.c @@ -909,13 +909,12 @@ new: start=%.0f,size=%.0f\n", (double)l_curr->start, (double)l_curr->size, */ char *msg = NULL; - /* Don't check if alloc succeeds here - we're - * forcing a core dump anyway. */ - - asprintf(&msg, "logic flaw in cases: l_curr: start = %.0f, size = %.0f : \ -lock: start = %.0f, size = %.0f", (double)l_curr->start, (double)l_curr->size, (double)lock->start, (double)lock->size ); - - smb_panic(msg); + if (asprintf(&msg, "logic flaw in cases: l_curr: start = %.0f, size = %.0f : \ +lock: start = %.0f, size = %.0f", (double)l_curr->start, (double)l_curr->size, (double)lock->start, (double)lock->size ) != -1) { + smb_panic(msg); + } else { + smb_panic("posix_lock_list"); + } } } /* end for ( l_curr = lhead; l_curr;) */ } /* end for (i=0; isharename); + if (asprintf(&allocated_string, "\\\\%s\\%s", longname, info2->sharename) == -1) { + return false; + } map_sz_into_ctr(ctr, SPOOL_REG_UNCNAME, allocated_string); SAFE_FREE(allocated_string); @@ -3267,6 +3269,7 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, struct GUID guid; WERROR win_rc = WERR_OK; size_t converted_size; + int ret; DEBUG(5, ("publishing printer %s\n", printer->info_2->printername)); @@ -3278,27 +3281,23 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res); if (!srv_dn_utf8) { - ads_destroy(&ads); return WERR_SERVER_UNAVAILABLE; } ads_msgfree(ads, res); srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1); if (!srv_cn_utf8) { ldap_memfree(srv_dn_utf8); - ads_destroy(&ads); return WERR_SERVER_UNAVAILABLE; } /* Now convert to CH_UNIX. */ if (!pull_utf8_allocate(&srv_dn, srv_dn_utf8, &converted_size)) { ldap_memfree(srv_dn_utf8); ldap_memfree(srv_cn_utf8); - ads_destroy(&ads); return WERR_SERVER_UNAVAILABLE; } if (!pull_utf8_allocate(&srv_cn_0, srv_cn_utf8[0], &converted_size)) { ldap_memfree(srv_dn_utf8); ldap_memfree(srv_cn_utf8); - ads_destroy(&ads); SAFE_FREE(srv_dn); return WERR_SERVER_UNAVAILABLE; } @@ -3309,27 +3308,28 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0); if (!srv_cn_escaped) { SAFE_FREE(srv_cn_0); - ldap_memfree(srv_dn_utf8); - ads_destroy(&ads); + SAFE_FREE(srv_dn); return WERR_SERVER_UNAVAILABLE; } sharename_escaped = escape_rdn_val_string_alloc(printer->info_2->sharename); if (!sharename_escaped) { SAFE_FREE(srv_cn_escaped); SAFE_FREE(srv_cn_0); - ldap_memfree(srv_dn_utf8); - ads_destroy(&ads); + SAFE_FREE(srv_dn); return WERR_SERVER_UNAVAILABLE; } - - asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn); + ret = asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn); SAFE_FREE(srv_dn); SAFE_FREE(srv_cn_0); SAFE_FREE(srv_cn_escaped); SAFE_FREE(sharename_escaped); + if (ret == -1) { + return WERR_NOMEM; + } + /* build the ads mods */ ctx = talloc_init("nt_printer_publish_ads"); if (ctx == NULL) { diff --git a/source3/printing/print_generic.c b/source3/printing/print_generic.c index 5806b29206..b789354999 100644 --- a/source3/printing/print_generic.c +++ b/source3/printing/print_generic.c @@ -205,7 +205,9 @@ static int generic_job_submit(int snum, struct printjob *pjob) out: - chdir(wd); + if (chdir(wd) == -1) { + smb_panic("chdir failed in generic_job_submit"); + } TALLOC_FREE(current_directory); return ret; } diff --git a/source3/rpc_server/srv_lsa_hnd.c b/source3/rpc_server/srv_lsa_hnd.c index 377ed505b4..839833ce54 100644 --- a/source3/rpc_server/srv_lsa_hnd.c +++ b/source3/rpc_server/srv_lsa_hnd.c @@ -54,10 +54,13 @@ bool init_pipe_handle_list(pipes_struct *p, const char *pipe_name) (is_samr_lsa_pipe(plist->name) && is_samr_lsa_pipe(pipe_name))) { if (!plist->pipe_handles) { char *msg; - asprintf(&msg, "init_pipe_handles: NULL " - "pipe_handle pointer in pipe %s", - pipe_name); - smb_panic(msg); + if (asprintf(&msg, "init_pipe_handles: NULL " + "pipe_handle pointer in pipe %s", + pipe_name) != -1) { + smb_panic(msg); + } else { + smb_panic("init_pipe_handle_list"); + } } hl = plist->pipe_handles; break; diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index 60aeeef1e2..e67f926a04 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -867,11 +867,14 @@ void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size) /* The cache *must* have been flushed before we do this. */ if (fsp->wcp->data_size != 0) { char *msg; - asprintf(&msg, "set_filelen_write_cache: size change " + if (asprintf(&msg, "set_filelen_write_cache: size change " "on file %s with write cache size = %lu\n", fsp->fsp_name, - (unsigned long)fsp->wcp->data_size); - smb_panic(msg); + (unsigned long)fsp->wcp->data_size) != -1) { + smb_panic(msg); + } else { + smb_panic("set_filelen_write_cache"); + } } fsp->wcp->file_size = file_size; } diff --git a/source3/smbd/seal.c b/source3/smbd/seal.c index 3822ee191e..bd4d853885 100644 --- a/source3/smbd/seal.c +++ b/source3/smbd/seal.c @@ -128,8 +128,7 @@ static NTSTATUS get_srv_gss_creds(const char *service, gss_OID_desc nt_hostbased_service = {10, CONST_DISCARD(char *,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")}; - asprintf(&host_princ_s, "%s@%s", service, name); - if (host_princ_s == NULL) { + if (asprintf(&host_princ_s, "%s@%s", service, name) == -1) { return NT_STATUS_NO_MEMORY; } -- cgit From ef80d1b794a209ee446c7a586530a5fdd51175f2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 22:10:34 +0100 Subject: Fix use of "time offset" parameter, and add test to make sure I don't break it again :-) --- lib/util/tests/time.c | 16 ++++++++++++++++ lib/util/time.c | 5 ++++- lib/util/time.h | 3 +++ source3/lib/time.c | 2 -- source3/param/loadparm.c | 2 -- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/util/tests/time.c b/lib/util/tests/time.c index 4a31566b42..e24c5fe5ef 100644 --- a/lib/util/tests/time.c +++ b/lib/util/tests/time.c @@ -58,6 +58,21 @@ static bool test_timestring(struct torture_context *tctx) return true; } +static bool test_get_time_zone(struct torture_context *tctx) +{ + time_t t = time(NULL); + int old_extra_time_offset = extra_time_offset; + int old_offset, new_offset; + /* test that extra_time_offset works */ + + old_offset = get_time_zone(t); + extra_time_offset = 42; + new_offset = get_time_zone(t); + extra_time_offset = old_extra_time_offset; + torture_assert_int_equal(tctx, old_offset+60*42, new_offset, + "time offset not used"); + return true; +} struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx) @@ -65,6 +80,7 @@ struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx) struct torture_suite *suite = torture_suite_create(mem_ctx, "TIME"); torture_suite_add_simple_test(suite, "null_time", test_null_time); + torture_suite_add_simple_test(suite, "get_time_zone", test_get_time_zone); torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime); torture_suite_add_simple_test(suite, "http_timestring", test_http_timestring); diff --git a/lib/util/time.c b/lib/util/time.c index a001e5f66e..eadafe4562 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -628,6 +628,9 @@ static int tm_diff(struct tm *a, struct tm *b) return seconds; } + +int extra_time_offset=0; + /** return the UTC offset in seconds west of UTC, or 0 if it cannot be determined */ @@ -641,7 +644,7 @@ _PUBLIC_ int get_time_zone(time_t t) tm = localtime(&t); if (!tm) return 0; - return tm_diff(&tm_utc,tm); + return tm_diff(&tm_utc,tm)+60*extra_time_offset; } struct timespec nt_time_to_unix_timespec(NTTIME *nt) diff --git a/lib/util/time.h b/lib/util/time.h index 42644a3954..e40de2de3d 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -239,4 +239,7 @@ struct timespec convert_time_t_to_timespec(time_t t); bool null_timespec(struct timespec ts); +/** Extra minutes to add to the normal GMT to local time conversion. */ +extern int extra_time_offset; + #endif /* _SAMBA_TIME_H_ */ diff --git a/source3/lib/time.c b/source3/lib/time.c index db2266fcbf..cae6b479b0 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -131,8 +131,6 @@ time_t convert_uint32_to_time_t(uint32_t u) return (time_t)u; } -int extra_time_offset=0; - /**************************************************************************** Check if NTTIME is 0. ****************************************************************************/ diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 8f03ae8fd7..274c79904e 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -94,8 +94,6 @@ static int config_backend = CONFIG_BACKEND_FILE; #define USERSHARE_VALID 1 #define USERSHARE_PENDING_DELETE 2 -extern int extra_time_offset; - static bool defaults_saved = False; struct param_opt_struct { -- cgit From ff26cb4b1c1d0292231e1cfc0490f4be6040d3e3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Dec 2008 22:11:21 +0100 Subject: Fix compiler warnings in libnet. --- source4/libnet/groupinfo.c | 5 +---- source4/libnet/groupman.c | 4 +--- source4/libnet/libnet_become_dc.c | 4 ++-- source4/libnet/libnet_join.c | 2 ++ source4/libnet/userinfo.c | 5 +---- source4/libnet/userman.c | 7 ++----- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/source4/libnet/groupinfo.c b/source4/libnet/groupinfo.c index 5c94c34b1d..1779c2816e 100644 --- a/source4/libnet/groupinfo.c +++ b/source4/libnet/groupinfo.c @@ -24,13 +24,10 @@ #include "includes.h" #include "libcli/composite/composite.h" -#include "libnet/composite.h" #include "librpc/gen_ndr/security.h" #include "libcli/security/security.h" -#include "libnet/userman.h" -#include "libnet/groupinfo.h" +#include "libnet/libnet.h" #include "librpc/gen_ndr/ndr_samr_c.h" -#include "libnet/libnet_proto.h" struct groupinfo_state { diff --git a/source4/libnet/groupman.c b/source4/libnet/groupman.c index 4dfb2d8aab..0f54db9705 100644 --- a/source4/libnet/groupman.c +++ b/source4/libnet/groupman.c @@ -23,10 +23,8 @@ #include "includes.h" #include "libcli/composite/composite.h" -#include "libnet/composite.h" -#include "libnet/groupman.h" +#include "libnet/libnet.h" #include "librpc/gen_ndr/ndr_samr_c.h" -#include "libnet/libnet_proto.h" struct groupadd_state { diff --git a/source4/libnet/libnet_become_dc.c b/source4/libnet/libnet_become_dc.c index 6e7924248c..294ea4b79c 100644 --- a/source4/libnet/libnet_become_dc.c +++ b/source4/libnet/libnet_become_dc.c @@ -1511,8 +1511,8 @@ static void becomeDC_drsuapi_connect_send(struct libnet_BecomeDC_state *s, drsuapi->s = s; if (!drsuapi->binding) { - char *krb5_str = ""; - char *print_str = ""; + const char *krb5_str = ""; + const char *print_str = ""; /* * Note: Replication only works with Windows 2000 when 'krb5' is * passed as auth_type here. If NTLMSSP is used, Windows diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c index 70fcb4a894..0a4e357925 100644 --- a/source4/libnet/libnet_join.c +++ b/source4/libnet/libnet_join.c @@ -1223,6 +1223,8 @@ NTSTATUS libnet_Join(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct lib case SEC_CHAN_BDC: return libnet_Join_primary_domain(ctx, mem_ctx, r); case SEC_CHAN_DOMAIN: + case SEC_CHAN_DNS_DOMAIN: + case SEC_CHAN_NULL: break; } diff --git a/source4/libnet/userinfo.c b/source4/libnet/userinfo.c index 710154d41e..a718ab9e85 100644 --- a/source4/libnet/userinfo.c +++ b/source4/libnet/userinfo.c @@ -23,13 +23,10 @@ #include "includes.h" #include "libcli/composite/composite.h" -#include "libnet/composite.h" #include "librpc/gen_ndr/security.h" #include "libcli/security/security.h" -#include "libnet/userman.h" -#include "libnet/userinfo.h" +#include "libnet/libnet.h" #include "librpc/gen_ndr/ndr_samr_c.h" -#include "libnet/libnet_proto.h" struct userinfo_state { diff --git a/source4/libnet/userman.c b/source4/libnet/userman.c index c638d8af32..62d4e0edd2 100644 --- a/source4/libnet/userman.c +++ b/source4/libnet/userman.c @@ -23,11 +23,8 @@ #include "includes.h" #include "libcli/composite/composite.h" -#include "libnet/composite.h" -#include "libnet/userman.h" -#include "libnet/userinfo.h" +#include "libnet/libnet.h" #include "librpc/gen_ndr/ndr_samr_c.h" -#include "libnet/libnet_proto.h" /* * Composite USER ADD functionality @@ -684,7 +681,7 @@ static NTSTATUS usermod_change(struct composite_context *c, s->queryuser.in.user_handle = &s->user_handle; s->queryuser.in.level = level; s->queryuser.out.info = talloc(s, union samr_UserInfo *); - if (composite_nomem(s->queryuser.out.info, c)) return; + if (composite_nomem(s->queryuser.out.info, c)) return NT_STATUS_NO_MEMORY; /* send query user info request to retrieve complete data of -- cgit