s4-python: Move samdb_server_site_name to dsdb module.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 3 Apr 2010 22:21:09 +0000 (00:21 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 3 Apr 2010 22:21:09 +0000 (00:21 +0200)
source4/dsdb/pydsdb.c
source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py

index b365744e4214331257c491980c7665f23ec8e666..248bc1a07ac6728bbd31fab3dc24e14338d2f02b 100644 (file)
 #include <Python.h>
 #include "includes.h"
 #include "dsdb/samdb/samdb.h"
+#include "lib/ldb/pyldb.h"
+
+/* FIXME: These should be in a header file somewhere, once we finish moving
+ * away from SWIG .. */
+#define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
+/*     if (!PyLdb_Check(py_ldb)) { \
+               PyErr_SetString(py_ldb_get_exception(), "Ldb connection object required"); \
+               return NULL; \
+       } */\
+       ldb = PyLdb_AsLdbContext(py_ldb);
+
+static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb, *result;
+       struct ldb_context *ldb;
+       const char *site;
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       site = samdb_server_site_name(ldb, mem_ctx);
+       if (site == NULL) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       result = PyString_FromString(site);
+       talloc_free(mem_ctx);
+       return result;
+}
 
 static PyMethodDef py_dsdb_methods[] = {
+       { "server_site_name", (PyCFunction)py_samdb_server_site_name, METH_VARARGS,
+               "get the server site name as a string"},
        { NULL }
 };
 
index 08fc648d36a03020b1bc585d1557a5b706d029b5..5fa02b367ddcd4177ed536083765494b91649774 100644 (file)
@@ -557,33 +557,6 @@ static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
 }
 
 
-static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
-{
-       PyObject *py_ldb, *result;
-       struct ldb_context *ldb;
-       const char *site;
-       TALLOC_CTX *mem_ctx = talloc_new(NULL);
-
-       if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
-               talloc_free(mem_ctx);
-               return NULL;
-       }
-
-       PyErr_LDB_OR_RAISE(py_ldb, ldb);
-
-       site = samdb_server_site_name(ldb, mem_ctx);
-       if (site == NULL) {
-               PyErr_SetStringError("Failed to find server site");
-               talloc_free(mem_ctx);
-               return NULL;
-       }
-
-       result = PyString_FromString(site);
-       talloc_free(mem_ctx);
-       return result;
-}
-
-
 /*
   return the list of interface IPs we have configured
   takes an loadparm context, returns a list of IPs in string form
@@ -689,8 +662,6 @@ static PyMethodDef py_misc_methods[] = {
                "get the NTDS invocation ID GUID as a string"},
        { "samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID, METH_VARARGS,
                "get the NTDS objectGUID as a string"},
-       { "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name, METH_VARARGS,
-               "get the server site name as a string"},
        { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
                "get interface IP address list"},
        { NULL }
index 73c0ba6f126aede7018427e248a219814e644477..7299e113925d7269316ef4d1cfd6c526f79c98b5 100644 (file)
@@ -42,6 +42,7 @@ else:
 
 
 import ldb
+import dsdb
 import glue
 
 class Ldb(ldb.Ldb):
@@ -310,7 +311,7 @@ class Ldb(ldb.Ldb):
 
     def server_site_name(self):
         "Get the server site name"
-        return glue.samdb_server_site_name(self)
+        return dsdb.samdb_server_site_name(self)
 
     def set_opaque_integer(self, name, value):
         """Set an integer as an opaque (a flag or other value) value on the database