py_net/libnet: Remove C++-style comments, add more error checking, move
authorJelmer Vernooij <jelmer@samba.org>
Fri, 25 Dec 2009 13:48:45 +0000 (14:48 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 25 Dec 2009 13:48:45 +0000 (14:48 +0100)
initialization of dcerpc subsystem to libnet.

source4/libnet/libnet.c
source4/libnet/py_net.c

index b10fb65df605d9fe059a931bb42f9d443dc6ae36..86cf80b4da8742e4a314eb6e1affee75226f0bb6 100644 (file)
@@ -42,6 +42,9 @@ struct libnet_context *libnet_context_init(struct tevent_context *ev,
        ctx->event_ctx = ev;
        ctx->lp_ctx = lp_ctx;
 
+       /* make sure dcerpc is initialized */
+       dcerpc_init(lp_ctx);
+
        /* name resolution methods */
        ctx->resolve_ctx = lp_resolve_context(lp_ctx);
 
index 01afe595c4c51fac3f4d998a744c43ce6fe6be43..e5ca5e1c9788171a55d1302d3db45f8e8d8b3d34 100644 (file)
@@ -66,10 +66,16 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs)
        creds = cli_credentials_from_py_object(py_creds);
        if (creds == NULL) {
                PyErr_SetString(PyExc_TypeError, "Expected credentials object");
+               talloc_free(mem_ctx);
                return NULL;
        }
 
        libnet_ctx = py_net_ctx(cls, ev, creds);
+       if (libnet_ctx == NULL) {
+               PyErr_SetString(PyExc_RuntimeError, "Unable to initialize libnet");
+               talloc_free(mem_ctx);
+               return NULL;
+       }
 
        status = libnet_Join(libnet_ctx, mem_ctx, &r);
        if (NT_STATUS_IS_ERR(status)) {
@@ -109,8 +115,8 @@ static PyObject *py_net_set_password(PyObject *cls, PyObject *args, PyObject *kw
                return NULL;
        }
 
-       // FIXME: we really need to get a context from the caller or we may end
-       // up with 2 event contexts
+       /* FIXME: we really need to get a context from the caller or we may end
+        * up with 2 event contexts */
        ev = s4_event_context_init(NULL);
        mem_ctx = talloc_new(ev);
 
@@ -120,8 +126,6 @@ static PyObject *py_net_set_password(PyObject *cls, PyObject *args, PyObject *kw
                return NULL;
        }
 
-       dcerpc_init(py_default_loadparm_context(NULL));
-
        libnet_ctx = py_net_ctx(cls, ev, creds);
 
        status = libnet_SetPassword(libnet_ctx, mem_ctx, &r);
@@ -158,6 +162,6 @@ static struct PyMethodDef net_methods[] = {
 
 void initnet(void)
 {
-       Py_InitModule("net", net_methods);
+       Py_InitModule3("net", net_methods, NULL);
 }