r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[samba.git] / source / python / py_tdb.c
index e525422a304367245c40eb0396b20fa61b217498..d72720f0ea3eb7dc0743a9e02a6a376c0871df36 100644 (file)
@@ -3,30 +3,33 @@
 
    Copyright (C) Tim Potter, 2002-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 2 of the License, or
-   (at your option) any later version.
+     ** NOTE! The following LGPL license applies to the tdb python
+     ** scripting library. This does NOT imply that all of Samba is 
+     ** released under the LGPL
    
-   This program is distributed in the hope that it will be useful,
+   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 General Public License for more details.
+   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 General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   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/>.
 */
 
-/* 
-   NOTE: Since tdb is licenced under the GPL any program that uses these bindings
-   must be distributed under the GPL license terms since this is what
-   the GPL requires.
+#include "includes.h"
 
-   http://www.gnu.org/licenses/gpl-faq.html#IfInterpreterIsGPL 
-*/
+/* This symbol is used in both includes.h and Python.h which causes an
+   annoying compiler warning. */
+
+#ifdef HAVE_FSTAT
+#undef HAVE_FSTAT
+#endif
 
-#include "includes.h"
 #include "Python.h"
 
 /* Tdb exception */
@@ -344,7 +347,7 @@ static BOOL make_lock_list(PyObject *py_keys, TDB_DATA **keys, int *num_keys)
                /* Turn python list into array of keys */
                
                *num_keys = PyList_Size(py_keys);
-               *keys = (TDB_DATA *)malloc(sizeof(TDB_DATA) * (*num_keys));
+               *keys = (TDB_DATA *)SMB_XMALLOC_ARRAY(TDB_DATA, (*num_keys));
                
                for (i = 0; i < *num_keys; i++) {
                        PyObject *key = PyList_GetItem(py_keys, i);
@@ -364,7 +367,7 @@ static BOOL make_lock_list(PyObject *py_keys, TDB_DATA **keys, int *num_keys)
 
                /* Turn python string into a single key */
 
-               *keys = (TDB_DATA *)malloc(sizeof(TDB_DATA));
+               *keys = (TDB_DATA *)SMB_XMALLOC_P(TDB_DATA);
                *num_keys = 1;
                PyArg_Parse(py_keys, "s#", &(*keys)->dptr, &(*keys)->dsize);
        }
@@ -372,49 +375,6 @@ static BOOL make_lock_list(PyObject *py_keys, TDB_DATA **keys, int *num_keys)
        return True;
 }
 
-PyObject *py_tdb_hnd_lock(PyObject *self, PyObject *args)
-{
-       tdb_hnd_object *obj = (tdb_hnd_object *)self;
-       PyObject *py_keys;
-       TDB_DATA *keys;
-       int num_keys, result;
-
-        if (!obj->tdb) {
-               PyErr_SetString(py_tdb_error, "tdb object has been closed"); 
-               return NULL;
-        }      
-
-       if (!PyArg_ParseTuple(args, "O", &py_keys))
-               return NULL;
-
-       if (!make_lock_list(py_keys, &keys, &num_keys))
-               return NULL;
-
-       result = tdb_lockkeys(obj->tdb, num_keys, keys);
-
-       free(keys);
-
-       return PyInt_FromLong(result != -1);
-}
-
-PyObject *py_tdb_hnd_unlock(PyObject *self, PyObject *args)
-{
-       tdb_hnd_object *obj = (tdb_hnd_object *)self;
-       
-        if (!obj->tdb) {
-               PyErr_SetString(py_tdb_error, "tdb object has been closed"); 
-               return NULL;
-        }      
-       
-       if (!PyArg_ParseTuple(args, ""))
-               return NULL;
-       
-       tdb_unlockkeys(obj->tdb);
-
-       Py_INCREF(Py_None);
-       return Py_None;
-}
-
 /*
  * tdb traversal
  */
@@ -533,7 +493,7 @@ PyObject *py_tdb_hnd_lock_bystring(PyObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, "s|i", &s, &timeout))
                return NULL;
 
-       result = tdb_lock_bystring(obj->tdb, s, timeout);
+       result = tdb_lock_bystring_with_timeout(obj->tdb, s, timeout);
 
        return PyInt_FromLong(result != -1);
 }
@@ -578,8 +538,6 @@ static PyMethodDef tdb_hnd_methods[] = {
        { "next_key", (PyCFunction)py_tdb_hnd_next_key, METH_VARARGS },
        { "lock_all", (PyCFunction)py_tdb_hnd_lock_all, METH_VARARGS },
        { "unlock_all", (PyCFunction)py_tdb_hnd_unlock_all, METH_VARARGS },
-       { "lock", (PyCFunction)py_tdb_hnd_lock, METH_VARARGS },
-       { "unlock", (PyCFunction)py_tdb_hnd_unlock, METH_VARARGS },
        { "traverse", (PyCFunction)py_tdb_hnd_traverse, METH_VARARGS | METH_KEYWORDS },
        { "chainlock", (PyCFunction)py_tdb_hnd_chainlock, METH_VARARGS | METH_KEYWORDS },
        { "chainunlock", (PyCFunction)py_tdb_hnd_chainunlock, METH_VARARGS | METH_KEYWORDS },