Revert "s4: Let the "setpassword" script finally use the "samdb_set_password" routine"
[ira/wip.git] / source4 / scripting / python / pyglue.c
index d4db55431fe043b3ad7ff5c4bcf5199f31484902..42c04c1f3847a0d6095d286a974f2d5ede9f1fae 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"
@@ -91,6 +93,15 @@ static PyObject *py_unix2nttime(PyObject *self, PyObject *args)
        return PyInt_FromLong((uint64_t)nt);
 }
 
+static PyObject *py_set_debug_level(PyObject *self, PyObject *args)
+{
+       unsigned level;
+       if (!PyArg_ParseTuple(args, "I", &level))
+               return NULL;
+       (DEBUGLEVEL) = level;
+       Py_RETURN_NONE;
+}
+
 static PyObject *py_ldb_set_credentials(PyObject *self, PyObject *args)
 {
        PyObject *py_creds, *py_ldb;
@@ -155,6 +166,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;
@@ -177,6 +203,30 @@ static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
+static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
+{ 
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       const struct dom_sid *sid;
+       PyObject *ret;
+       char *retstr;
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb))
+               return NULL;
+       
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       sid = samdb_domain_sid(ldb);
+       if (!sid) {
+               PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
+               return NULL;
+       } 
+       retstr = dom_sid_string(NULL, sid);
+       ret = PyString_FromString(retstr);
+       talloc_free(retstr);
+       return ret;
+}
+
 static PyObject *py_ldb_register_samba_handlers(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb;
@@ -327,6 +377,30 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self, PyObject *ar
        return ret;
 }
 
+static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       WERROR result;
+       struct dsdb_schema *schema;
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       schema = dsdb_get_schema(ldb);
+       if (!schema) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
+               return NULL;
+       }
+
+       result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
+       PyErr_WERROR_IS_ERR_RAISE(result);
+
+       Py_RETURN_NONE;
+}
+
 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb;
@@ -393,9 +467,15 @@ static PyMethodDef py_misc_methods[] = {
        { "samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid, METH_VARARGS,
                "samdb_set_domain_sid(samdb, sid)\n"
                "Set SID of domain to use." },
+       { "samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid, METH_VARARGS,
+               "samdb_get_domain_sid(samdb)\n"
+               "Get SID of domain in use." },
        { "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,
@@ -404,12 +484,16 @@ static PyMethodDef py_misc_methods[] = {
                NULL },
        { "dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
                NULL },
+       { "dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, 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 },
        { "dom_sid_to_rid", (PyCFunction)py_dom_sid_to_rid, METH_VARARGS,
                NULL },
+       { "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
+               "set debug level" },
        { NULL }
 };