/*
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
#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"
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;
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;
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_samdb_set_password(PyLdbObject *self, PyObject *args,
+ PyObject *kwargs)
+{
+ PyObject *py_sam, *py_user_dn, *py_dom_dn, *py_mod, *py_user_change;
+ char *new_password;
+ bool user_change;
+ DATA_BLOB new_pwd_blob;
+ struct ldb_context *sam_ctx;
+ struct ldb_dn *user_dn, *dom_dn;
+ struct ldb_message *mod;
+ TALLOC_CTX *mem_ctx;
+ NTSTATUS status;
+ const char * const kwnames[] = { "samdb", "user_dn", "dom_dn", "mod",
+ "new_password", "user_change", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOOsO",
+ discard_const_p(char *, kwnames),
+ &py_sam, &py_user_dn, &py_dom_dn, &py_mod, &new_password,
+ &py_user_change))
+ return NULL;
+
+ sam_ctx = PyLdb_AsLdbContext(py_sam);
+
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ }
+
+ if (!PyObject_AsDn(mem_ctx, py_user_dn, sam_ctx, &user_dn)) {
+ PyErr_SetString(PyExc_RuntimeError, "user_dn invalid!");
+ return NULL;
+ }
+
+ if (!PyObject_AsDn(mem_ctx, py_dom_dn, sam_ctx, &dom_dn)) {
+ PyErr_SetString(PyExc_RuntimeError, "dom_dn invalid!");
+ return NULL;
+ }
+
+ mod = PyLdbMessage_AsMessage(py_mod);
+
+ user_change = PyInt_AsLong(py_user_change);
+
+ new_pwd_blob.data = (uint8_t *) new_password;
+ new_pwd_blob.length = strlen((char *) new_pwd_blob.data);
+
+ status = samdb_set_password(sam_ctx, mem_ctx, user_dn, dom_dn, mod,
+ &new_pwd_blob, NULL, NULL, user_change, NULL, NULL);
+
+ talloc_free(mem_ctx);
+
+ PyErr_NTSTATUS_IS_ERR_RAISE(status);
+ Py_RETURN_NONE;
+}
+
static PyObject *py_ldb_register_samba_handlers(PyObject *self, PyObject *args)
{
PyObject *py_ldb;
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;
sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
- status = dom_sid_split_rid(NULL, sid, NULL, &rid);
+ status = dom_sid_split_rid(NULL, (const struct dom_sid *)sid, NULL,
+ &rid);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetString(PyExc_RuntimeError, "dom_sid_split_rid failed");
return NULL;
{ "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." },
+ { "samdb_set_password", (PyCFunction)py_samdb_set_password,
+ METH_VARARGS|METH_KEYWORDS,
+ "samdb_set_password(samdb, user_dn, dom_dn, mod, new_password, user_change)\n"
+ "Set the password of a user" },
{ "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_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 }
};