s4:pyglue Add a wrapper for loading the correct UTF8 casefolder
[ira/wip.git] / source4 / scripting / python / pyglue.c
index 95255dc1f67678c4947fe411b1be5345acb301f7..f5694e162c1be814d907f69f31c128d15dbef1e1 100644 (file)
@@ -1,6 +1,7 @@
 /* 
    Unix SMB/CIFS implementation.
    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
+   Copyright (C) Matthias Dieter Wallnöfer          2009
    
    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
@@ -19,6 +20,7 @@
 #include "includes.h"
 #include "ldb.h"
 #include "ldb_errors.h"
+#include "ldb_wrap.h"
 #include "param/param.h"
 #include "auth/credentials/credentials.h"
 #include "dsdb/samdb/samdb.h"
@@ -155,6 +157,21 @@ static PyObject *py_ldb_set_session_info(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
+static PyObject *py_ldb_set_utf8_casefold(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
+
+       Py_RETURN_NONE;
+}
+
 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
 { 
        PyObject *py_ldb, *py_sid;
@@ -286,7 +303,7 @@ static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
-static PyObject *py_dsdb_attach_schema_from_ldif(PyObject *self, PyObject *args)
+static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
 {
        WERROR result;
        char *pf, *df;
@@ -298,7 +315,7 @@ static PyObject *py_dsdb_attach_schema_from_ldif(PyObject *self, PyObject *args)
 
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
 
-       result = dsdb_attach_schema_from_ldif(ldb, pf, df);
+       result = dsdb_set_schema_from_ldif(ldb, pf, df);
        PyErr_WERROR_IS_ERR_RAISE(result);
 
        Py_RETURN_NONE;
@@ -327,6 +344,33 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self, PyObject *ar
        return ret;
 }
 
+static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       PyObject *py_from_ldb;
+       struct ldb_context *from_ldb;
+       struct dsdb_schema *schema;
+       int ret;
+       if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_from_ldb))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
+
+       schema = dsdb_get_schema(from_ldb);
+       if (!schema) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
+               return NULL;
+       }
+
+       ret = dsdb_reference_schema(ldb, schema, true);
+       PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
+
+       Py_RETURN_NONE;
+}
+
 static PyObject *py_dom_sid_to_rid(PyLdbObject *self, PyObject *args)
 {
        PyObject *py_sid;
@@ -369,13 +413,18 @@ static PyMethodDef py_misc_methods[] = {
        { "ldb_register_samba_handlers", (PyCFunction)py_ldb_register_samba_handlers, METH_VARARGS,
                "ldb_register_samba_handlers(ldb)\n"
                "Register Samba-specific LDB modules and schemas." },
+       { "ldb_set_utf8_casefold", (PyCFunction)py_ldb_set_utf8_casefold, METH_VARARGS,
+               "ldb_set_utf8_casefold(ldb)\n"
+               "Set the right Samba casefolding function for UTF8 charset." },
        { "dsdb_set_ntds_invocation_id", (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
                NULL },
        { "dsdb_set_opaque_integer", (PyCFunction)py_dsdb_set_opaque_integer, METH_VARARGS,
                NULL },
        { "dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema, METH_VARARGS,
                NULL },
-       { "dsdb_attach_schema_from_ldif", (PyCFunction)py_dsdb_attach_schema_from_ldif, METH_VARARGS,
+       { "dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
+               NULL },
+       { "dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
                NULL },
        { "dsdb_convert_schema_to_openldap", (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
                NULL },