ldb-python: add a function to Dn object to compare the Dn with a base DN
authorMatthieu Patou <mat@matws.net>
Mon, 23 May 2011 21:30:15 +0000 (01:30 +0400)
committerAndrew Tridgell <tridge@samba.org>
Thu, 21 Jul 2011 01:44:34 +0000 (11:44 +1000)
lib/ldb/pyldb.c

index e2a2e7180e1de8bc2994a7752faeb934ece79d2b..4c71569f052b611844e170ea5e55e29024ce7ba7 100644 (file)
@@ -522,6 +522,21 @@ static PyObject *py_ldb_dn_add_base(PyLdbDnObject *self, PyObject *args)
        return ldb_dn_add_base(dn, other)?Py_True:Py_False;
 }
 
+static PyObject *py_ldb_dn_compare_base(PyLdbDnObject *self, PyObject *args)
+{
+       PyObject *py_base;
+       struct ldb_dn *dn, *base;
+       if (!PyArg_ParseTuple(args, "O", &py_base))
+               return NULL;
+
+       dn = PyLdbDn_AsDn((PyObject *)self);
+
+       if (!PyObject_AsDn(NULL, py_base, dn_ldb_ctx(dn), &base))
+               return NULL;
+
+       return PyInt_FromLong(ldb_dn_compare_base(base, dn));
+}
+
 static PyMethodDef py_ldb_dn_methods[] = {
        { "validate", (PyCFunction)py_ldb_dn_validate, METH_NOARGS, 
                "S.validate() -> bool\n"
@@ -540,6 +555,8 @@ static PyMethodDef py_ldb_dn_methods[] = {
        { "canonical_str", (PyCFunction)py_ldb_dn_canonical_str, METH_NOARGS,
                "S.canonical_str() -> string\n"
                "Canonical version of this DN (like a posix path)." },
+       { "compare_base", (PyCFunction)py_ldb_dn_compare_base, METH_VARARGS,
+               "S.compare_base(basedn) -> int\n\n"},
        { "canonical_ex_str", (PyCFunction)py_ldb_dn_canonical_ex_str, METH_NOARGS,
                "S.canonical_ex_str() -> string\n"
                "Canonical version of this DN (like a posix path, with terminating newline)." },