summaryrefslogtreecommitdiff
path: root/source4/dsdb
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-04-04 03:30:03 +0200
committerJelmer Vernooij <jelmer@samba.org>2010-04-07 17:39:59 +0200
commit21ab06f8a233b38bee750250e455416ac0bef13e (patch)
tree17a6e2a91ed88226f629444a30becd198edfcf6c /source4/dsdb
parentfe4b212eba1d7645c8be98240a2630759050197d (diff)
downloadsamba-21ab06f8a233b38bee750250e455416ac0bef13e.tar.gz
samba-21ab06f8a233b38bee750250e455416ac0bef13e.tar.bz2
samba-21ab06f8a233b38bee750250e455416ac0bef13e.zip
s4-python: Move samdb_ntds_objectGUID to pydsdb.
Diffstat (limited to 'source4/dsdb')
-rw-r--r--source4/dsdb/pydsdb.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index ac9b93cc27..b18c127776 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -21,6 +21,8 @@
#include "includes.h"
#include "dsdb/samdb/samdb.h"
#include "lib/ldb/pyldb.h"
+#include "libcli/security/security.h"
+#include "librpc/ndr/libndr.h"
/* FIXME: These should be in a header file somewhere, once we finish moving
* away from SWIG .. */
@@ -83,6 +85,138 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
return ret;
}
+static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
+{
+ PyObject *py_ldb, *py_sid;
+ struct ldb_context *ldb;
+ struct dom_sid *sid;
+ bool ret;
+
+ if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
+ return NULL;
+
+ PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+ sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
+
+ ret = samdb_set_domain_sid(ldb, sid);
+ if (!ret) {
+ PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
+ return NULL;
+ }
+ 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_ntds_invocation_id(PyObject *self, PyObject *args)
+{
+ PyObject *py_ldb, *result;
+ struct ldb_context *ldb;
+ TALLOC_CTX *mem_ctx;
+ const struct GUID *guid;
+
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+ guid = samdb_ntds_invocation_id(ldb);
+ if (guid == NULL) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Failed to find NTDS invocation ID");
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ result = PyString_FromString(GUID_string(mem_ctx, guid));
+ talloc_free(mem_ctx);
+ return result;
+}
+
+static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
+{
+ PyObject *py_ldb, *py_guid;
+ bool ret;
+ struct GUID guid;
+ struct ldb_context *ldb;
+ if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
+ return NULL;
+
+ PyErr_LDB_OR_RAISE(py_ldb, ldb);
+ GUID_from_string(PyString_AsString(py_guid), &guid);
+
+ ret = samdb_set_ntds_invocation_id(ldb, &guid);
+ if (!ret) {
+ PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
+{
+ PyObject *py_ldb, *result;
+ struct ldb_context *ldb;
+ TALLOC_CTX *mem_ctx;
+ const struct GUID *guid;
+
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+ guid = samdb_ntds_objectGUID(ldb);
+ if (guid == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ result = PyString_FromString(GUID_string(mem_ctx, guid));
+ talloc_free(mem_ctx);
+ return result;
+}
+
+
static PyMethodDef py_dsdb_methods[] = {
{ "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
METH_VARARGS, "Get the server site name as a string"},
@@ -90,6 +224,20 @@ static PyMethodDef py_dsdb_methods[] = {
(PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
"dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
"Create an OpenLDAP schema from a schema." },
+ { "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_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
+ METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
+ { "dsdb_set_ntds_invocation_id", (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
+ NULL },
+ { "samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID, METH_VARARGS,
+ "get the NTDS objectGUID as a string"},
{ NULL }
};