1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/lib/ldb/pyldb.h
Douglas Bagnall e075f52a75 pyldb: fork pyldb_Ldb_AsLdbContext macro to reflect unsafeness
In the Python/C API, conversion functions which check the types of their arguments
have names like:

double PyFloat_AsDouble(PyObject *pyfloat);

while conversion macros that don't check have names like:

PyFloat_AS_DOUBLE(pyfloat)

The pyldb_Ldb_AsLdbContext() macro looks like one of the checking functions
but it actually isn't. This has fooled us more than once. Here we fork
the macro into two -- one which performs checks and keeps the camel
case, and one with a shouty name that keeps the check-free behaviour.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-07-10 04:32:13 +00:00

118 lines
3.2 KiB
C

/*
Unix SMB/CIFS implementation.
Python 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 <talloc.h>
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_context *ldb_ctx;
} PyLdbObject;
/* pyldb_Ldb_AS_LDBCONTEXT() does not check argument validity,
pyldb_Ldb_AsLdbContext() does */
#define pyldb_Ldb_AS_LDBCONTEXT(pyobj) ((PyLdbObject *)pyobj)->ldb_ctx
#define pyldb_Ldb_AsLdbContext(pyobj) \
(pyldb_check_type(pyobj, "Ldb") ? \
pyldb_Ldb_AS_LDBCONTEXT(pyobj) : NULL)
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_dn *dn;
} PyLdbDnObject;
PyObject *pyldb_Dn_FromDn(struct ldb_dn *);
bool pyldb_Object_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb_ctx, struct ldb_dn **dn);
#define pyldb_Dn_AsDn(pyobj) ((PyLdbDnObject *)pyobj)->dn
bool pyldb_check_type(PyObject *obj, const char *type_name);
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_message *msg;
} PyLdbMessageObject;
#define pyldb_Message_AsMessage(pyobj) ((PyLdbMessageObject *)pyobj)->msg
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_module *mod;
} PyLdbModuleObject;
#define pyldb_Module_AsModule(pyobj) ((PyLdbModuleObject *)pyobj)->mod
/*
* NOTE: el (and so the return value of
* pyldb_MessageElement_AsMessageElement()) may not be a valid talloc
* context, it could be part of an array
*/
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_message_element *el;
} PyLdbMessageElementObject;
#define pyldb_MessageElement_AsMessageElement(pyobj) ((PyLdbMessageElementObject *)pyobj)->el
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_parse_tree *tree;
} PyLdbTreeObject;
#define pyldb_Tree_AsTree(pyobj) ((PyLdbTreeObject *)pyobj)->tree
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
PyObject *msgs;
PyObject *referals;
PyObject *controls;
} PyLdbResultObject;
typedef struct {
PyObject_HEAD
TALLOC_CTX *mem_ctx;
struct ldb_control *data;
} PyLdbControlObject;
#define PyErr_LDB_ERROR_IS_ERR_RAISE(err,ret,ldb) do { \
if (ret != LDB_SUCCESS) { \
PyErr_SetLdbError(err, ret, ldb); \
return NULL; \
} \
} while(0)
/* 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_ */