mirror of
https://github.com/samba-team/samba.git
synced 2024-12-27 03:21:53 +03:00
f1c523939b
the talloc python interface for tp_alloc and tp_dealloc relies on a cast to a py_talloc_Object to find the talloc_ctx (see py_talloc_dealloc). This means we rely on the talloc_ctx for the object being directly after the PyObject_HEAD This fixes the talloc free with references bug in samba_dnsupdate The actual problem was the tp_alloc() call in PyCredentialCacheContainer_from_ccache_container() which used a cast from a py_talloc_Object to a PyCredentialCacheContainerObject. That case effectively changed the parent/child relationship between the talloc_ctx and the ccc ptr. This patch changes all the structures that follow this pattern to put the TALLOC_CTX directly after the PyObject_HEAD, to ensure that if anyone else decides to do a dangerous cast like this that it won't cause the same sort of subtle breakage. Pair-Programmed-With: Rusty Russell <rusty@samba.org>
98 lines
3.1 KiB
C
98 lines
3.1 KiB
C
/*
|
|
Unix SMB/CIFS implementation.
|
|
|
|
Swig interface to ldb.
|
|
|
|
Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
|
|
|
|
** NOTE! The following LGPL license applies to the ldb
|
|
** 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef _PYLDB_H_
|
|
#define _PYLDB_H_
|
|
|
|
#include <Python.h>
|
|
#include <talloc.h>
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
TALLOC_CTX *mem_ctx;
|
|
struct ldb_context *ldb_ctx;
|
|
} PyLdbObject;
|
|
|
|
#define PyLdb_AsLdbContext(pyobj) ((PyLdbObject *)pyobj)->ldb_ctx
|
|
#define PyLdb_Check(ob) PyObject_TypeCheck(ob, &PyLdb)
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
TALLOC_CTX *mem_ctx;
|
|
struct ldb_dn *dn;
|
|
} PyLdbDnObject;
|
|
|
|
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) ((PyLdbDnObject *)pyobj)->dn
|
|
#define PyLdbDn_Check(ob) PyObject_TypeCheck(ob, &PyLdbDn)
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
TALLOC_CTX *mem_ctx;
|
|
struct ldb_message *msg;
|
|
} PyLdbMessageObject;
|
|
#define PyLdbMessage_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessage)
|
|
#define PyLdbMessage_AsMessage(pyobj) ((PyLdbMessageObject *)pyobj)->msg
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
TALLOC_CTX *mem_ctx;
|
|
struct ldb_module *mod;
|
|
} PyLdbModuleObject;
|
|
PyObject *PyLdbMessage_FromMessage(struct ldb_message *message);
|
|
PyObject *PyLdbModule_FromModule(struct ldb_module *mod);
|
|
#define PyLdbModule_AsModule(pyobj) ((PyLdbModuleObject *)pyobj)->mod
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
TALLOC_CTX *mem_ctx;
|
|
struct ldb_message_element *el;
|
|
} PyLdbMessageElementObject;
|
|
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) ((PyLdbMessageElementObject *)pyobj)->el
|
|
#define PyLdbMessageElement_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessageElement)
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
TALLOC_CTX *mem_ctx;
|
|
struct ldb_parse_tree *tree;
|
|
} PyLdbTreeObject;
|
|
PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *);
|
|
#define PyLdbTree_AsTree(pyobj) ((PyLdbTreeObject *)pyobj)->tree
|
|
|
|
#define PyErr_LDB_ERROR_IS_ERR_RAISE(err,ret,ldb) \
|
|
if (ret != LDB_SUCCESS) { \
|
|
PyErr_SetLdbError(err, ret, ldb); \
|
|
return NULL; \
|
|
}
|
|
|
|
/* 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
|
|
|
|
#endif /* _PYLDB_H_ */
|