s4:py_net: PyArg_ParseTuple("i") requires an 'int' argument
[Samba.git] / source4 / libnet / py_net.c
blobb43f69bf0f9c56ba2ceb5ceaca0d6ae197fac68d
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008-2010
5 Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <Python.h>
22 #include "includes.h"
23 #include <ldb.h>
24 #include <pyldb.h>
25 #include "libnet.h"
26 #include "auth/credentials/pycredentials.h"
27 #include "libcli/security/security.h"
28 #include "lib/events/events.h"
29 #include "param/pyparam.h"
30 #include "auth/gensec/gensec.h"
31 #include "librpc/rpc/pyrpc_util.h"
32 #include "libcli/finddc.h"
33 #include "libcli/resolve/resolve.h"
35 void initnet(void);
37 typedef struct {
38 PyObject_HEAD
39 TALLOC_CTX *mem_ctx;
40 struct libnet_context *libnet_ctx;
41 struct tevent_context *ev;
42 } py_net_Object;
44 static PyObject *py_net_join_member(py_net_Object *self, PyObject *args, PyObject *kwargs)
46 struct libnet_Join_member r;
47 int _level = 0;
48 NTSTATUS status;
49 PyObject *result;
50 TALLOC_CTX *mem_ctx;
51 const char *kwnames[] = { "domain_name", "netbios_name", "level", NULL };
53 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssi:Join", discard_const_p(char *, kwnames),
54 &r.in.domain_name, &r.in.netbios_name,
55 &_level)) {
56 return NULL;
58 r.in.level = _level;
60 mem_ctx = talloc_new(self->mem_ctx);
61 if (mem_ctx == NULL) {
62 PyErr_NoMemory();
63 return NULL;
66 status = libnet_Join_member(self->libnet_ctx, mem_ctx, &r);
67 if (NT_STATUS_IS_ERR(status)) {
68 PyErr_SetString(PyExc_RuntimeError, r.out.error_string?r.out.error_string:nt_errstr(status));
69 talloc_free(mem_ctx);
70 return NULL;
73 result = Py_BuildValue("sss", r.out.join_password,
74 dom_sid_string(mem_ctx, r.out.domain_sid),
75 r.out.domain_name);
77 talloc_free(mem_ctx);
79 return result;
82 static const char py_net_join_member_doc[] = "join_member(domain_name, netbios_name, level) -> (join_password, domain_sid, domain_name)\n\n" \
83 "Join the domain with the specified name.";
85 static PyObject *py_net_change_password(py_net_Object *self, PyObject *args, PyObject *kwargs)
87 union libnet_ChangePassword r;
88 NTSTATUS status;
89 TALLOC_CTX *mem_ctx;
90 struct tevent_context *ev;
91 const char *kwnames[] = { "newpassword", NULL };
93 ZERO_STRUCT(r);
95 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:change_password",
96 discard_const_p(char *, kwnames),
97 &r.generic.in.newpassword)) {
98 return NULL;
101 r.generic.level = LIBNET_CHANGE_PASSWORD_GENERIC;
102 r.generic.in.account_name = cli_credentials_get_username(self->libnet_ctx->cred);
103 r.generic.in.domain_name = cli_credentials_get_domain(self->libnet_ctx->cred);
104 r.generic.in.oldpassword = cli_credentials_get_password(self->libnet_ctx->cred);
106 /* FIXME: we really need to get a context from the caller or we may end
107 * up with 2 event contexts */
108 ev = s4_event_context_init(NULL);
110 mem_ctx = talloc_new(ev);
111 if (mem_ctx == NULL) {
112 PyErr_NoMemory();
113 return NULL;
116 status = libnet_ChangePassword(self->libnet_ctx, mem_ctx, &r);
117 if (NT_STATUS_IS_ERR(status)) {
118 PyErr_SetString(PyExc_RuntimeError,
119 r.generic.out.error_string?r.generic.out.error_string:nt_errstr(status));
120 talloc_free(mem_ctx);
121 return NULL;
124 talloc_free(mem_ctx);
126 Py_RETURN_NONE;
129 static const char py_net_change_password_doc[] = "change_password(newpassword) -> True\n\n" \
130 "Change password for a user. You must supply credential with enough rights to do this.\n\n" \
131 "Sample usage is:\n" \
132 "net.set_password(newpassword=<new_password>\n";
135 static PyObject *py_net_set_password(py_net_Object *self, PyObject *args, PyObject *kwargs)
137 union libnet_SetPassword r;
138 NTSTATUS status;
139 TALLOC_CTX *mem_ctx;
140 struct tevent_context *ev;
141 const char *kwnames[] = { "account_name", "domain_name", "newpassword", NULL };
143 ZERO_STRUCT(r);
145 r.generic.level = LIBNET_SET_PASSWORD_GENERIC;
147 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss:set_password",
148 discard_const_p(char *, kwnames),
149 &r.generic.in.account_name,
150 &r.generic.in.domain_name,
151 &r.generic.in.newpassword)) {
152 return NULL;
155 /* FIXME: we really need to get a context from the caller or we may end
156 * up with 2 event contexts */
157 ev = s4_event_context_init(NULL);
159 mem_ctx = talloc_new(ev);
160 if (mem_ctx == NULL) {
161 PyErr_NoMemory();
162 return NULL;
165 status = libnet_SetPassword(self->libnet_ctx, mem_ctx, &r);
166 if (NT_STATUS_IS_ERR(status)) {
167 PyErr_SetString(PyExc_RuntimeError,
168 r.generic.out.error_string?r.generic.out.error_string:nt_errstr(status));
169 talloc_free(mem_ctx);
170 return NULL;
173 talloc_free(mem_ctx);
175 Py_RETURN_NONE;
178 static const char py_net_set_password_doc[] = "set_password(account_name, domain_name, newpassword) -> True\n\n" \
179 "Set password for a user. You must supply credential with enough rights to do this.\n\n" \
180 "Sample usage is:\n" \
181 "net.set_password(account_name=<account_name>,\n" \
182 " domain_name=domain_name,\n" \
183 " newpassword=new_pass)\n";
186 static PyObject *py_net_export_keytab(py_net_Object *self, PyObject *args, PyObject *kwargs)
188 struct libnet_export_keytab r;
189 TALLOC_CTX *mem_ctx;
190 const char *kwnames[] = { "keytab", NULL };
191 NTSTATUS status;
193 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:export_keytab", discard_const_p(char *, kwnames),
194 &r.in.keytab_name)) {
195 return NULL;
198 mem_ctx = talloc_new(self->mem_ctx);
199 if (mem_ctx == NULL) {
200 PyErr_NoMemory();
201 return NULL;
204 status = libnet_export_keytab(self->libnet_ctx, mem_ctx, &r);
205 if (NT_STATUS_IS_ERR(status)) {
206 PyErr_SetString(PyExc_RuntimeError,
207 r.out.error_string?r.out.error_string:nt_errstr(status));
208 talloc_free(mem_ctx);
209 return NULL;
212 talloc_free(mem_ctx);
214 Py_RETURN_NONE;
217 static const char py_net_export_keytab_doc[] = "export_keytab(keytab, name)\n\n"
218 "Export the DC keytab to a keytab file.";
220 static PyObject *py_net_time(py_net_Object *self, PyObject *args, PyObject *kwargs)
222 const char *kwnames[] = { "server_name", NULL };
223 union libnet_RemoteTOD r;
224 NTSTATUS status;
225 TALLOC_CTX *mem_ctx;
226 char timestr[64];
227 PyObject *ret;
228 struct tm *tm;
230 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s",
231 discard_const_p(char *, kwnames), &r.generic.in.server_name))
232 return NULL;
234 r.generic.level = LIBNET_REMOTE_TOD_GENERIC;
236 mem_ctx = talloc_new(NULL);
237 if (mem_ctx == NULL) {
238 PyErr_NoMemory();
239 return NULL;
242 status = libnet_RemoteTOD(self->libnet_ctx, mem_ctx, &r);
243 if (!NT_STATUS_IS_OK(status)) {
244 PyErr_SetString(PyExc_RuntimeError,
245 r.generic.out.error_string?r.generic.out.error_string:nt_errstr(status));
246 talloc_free(mem_ctx);
247 return NULL;
250 ZERO_STRUCT(timestr);
251 tm = localtime(&r.generic.out.time);
252 strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
254 ret = PyString_FromString(timestr);
256 talloc_free(mem_ctx);
258 return ret;
261 static const char py_net_time_doc[] = "time(server_name) -> timestr\n"
262 "Retrieve the remote time on a server";
264 static PyObject *py_net_user_create(py_net_Object *self, PyObject *args, PyObject *kwargs)
266 const char *kwnames[] = { "username", NULL };
267 NTSTATUS status;
268 TALLOC_CTX *mem_ctx;
269 struct libnet_CreateUser r;
271 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", discard_const_p(char *, kwnames),
272 &r.in.user_name))
273 return NULL;
275 r.in.domain_name = cli_credentials_get_domain(self->libnet_ctx->cred);
277 mem_ctx = talloc_new(NULL);
278 if (mem_ctx == NULL) {
279 PyErr_NoMemory();
280 return NULL;
283 status = libnet_CreateUser(self->libnet_ctx, mem_ctx, &r);
284 if (!NT_STATUS_IS_OK(status)) {
285 PyErr_SetString(PyExc_RuntimeError, r.out.error_string?r.out.error_string:nt_errstr(status));
286 talloc_free(mem_ctx);
287 return NULL;
290 talloc_free(mem_ctx);
292 Py_RETURN_NONE;
295 static const char py_net_create_user_doc[] = "create_user(username)\n"
296 "Create a new user.";
298 static PyObject *py_net_user_delete(py_net_Object *self, PyObject *args, PyObject *kwargs)
300 const char *kwnames[] = { "username", NULL };
301 NTSTATUS status;
302 TALLOC_CTX *mem_ctx;
303 struct libnet_DeleteUser r;
305 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", discard_const_p(char *, kwnames),
306 &r.in.user_name))
307 return NULL;
309 r.in.domain_name = cli_credentials_get_domain(self->libnet_ctx->cred);
311 mem_ctx = talloc_new(NULL);
312 if (mem_ctx == NULL) {
313 PyErr_NoMemory();
314 return NULL;
317 status = libnet_DeleteUser(self->libnet_ctx, mem_ctx, &r);
318 if (!NT_STATUS_IS_OK(status)) {
319 PyErr_SetString(PyExc_RuntimeError, r.out.error_string?r.out.error_string:nt_errstr(status));
320 talloc_free(mem_ctx);
321 return NULL;
324 talloc_free(mem_ctx);
326 Py_RETURN_NONE;
329 static const char py_net_delete_user_doc[] = "delete_user(username)\n"
330 "Delete a user.";
332 static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
334 PyObject *mod_security, *dom_sid_Type;
336 mod_security = PyImport_ImportModule("samba.dcerpc.security");
337 if (mod_security == NULL)
338 return NULL;
340 dom_sid_Type = PyObject_GetAttrString(mod_security, "dom_sid");
341 if (dom_sid_Type == NULL)
342 return NULL;
344 return py_talloc_reference((PyTypeObject *)dom_sid_Type, sid);
347 static PyObject *py_net_vampire(py_net_Object *self, PyObject *args, PyObject *kwargs)
349 const char *kwnames[] = { "domain", "target_dir", NULL };
350 NTSTATUS status;
351 TALLOC_CTX *mem_ctx;
352 PyObject *ret;
353 struct libnet_Vampire r;
355 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|z", discard_const_p(char *, kwnames),
356 &r.in.domain_name, &r.in.targetdir)) {
357 return NULL;
360 r.in.netbios_name = lpcfg_netbios_name(self->libnet_ctx->lp_ctx);
361 r.out.error_string = NULL;
363 mem_ctx = talloc_new(NULL);
364 if (mem_ctx == NULL) {
365 PyErr_NoMemory();
366 return NULL;
369 status = libnet_Vampire(self->libnet_ctx, mem_ctx, &r);
371 if (!NT_STATUS_IS_OK(status)) {
372 PyErr_SetString(PyExc_RuntimeError,
373 r.out.error_string ? r.out.error_string : nt_errstr(status));
374 talloc_free(mem_ctx);
375 return NULL;
378 ret = Py_BuildValue("(sO)", r.out.domain_name, py_dom_sid_FromSid(r.out.domain_sid));
380 talloc_free(mem_ctx);
382 return ret;
385 struct replicate_state {
386 void *vampire_state;
387 dcerpc_InterfaceObject *drs_pipe;
388 struct libnet_BecomeDC_StoreChunk chunk;
389 DATA_BLOB gensec_skey;
390 struct libnet_BecomeDC_Partition partition;
391 struct libnet_BecomeDC_Forest forest;
392 struct libnet_BecomeDC_DestDSA dest_dsa;
396 setup for replicate_chunk() calls
398 static PyObject *py_net_replicate_init(py_net_Object *self, PyObject *args, PyObject *kwargs)
400 const char *kwnames[] = { "samdb", "lp", "drspipe", NULL };
401 PyObject *py_ldb, *py_lp, *py_drspipe;
402 struct ldb_context *samdb;
403 struct loadparm_context *lp;
404 struct replicate_state *s;
405 NTSTATUS status;
407 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO",
408 discard_const_p(char *, kwnames),
409 &py_ldb, &py_lp, &py_drspipe)) {
410 return NULL;
413 s = talloc_zero(NULL, struct replicate_state);
414 if (!s) return NULL;
416 lp = lpcfg_from_py_object(s, py_lp);
417 if (lp == NULL) {
418 PyErr_SetString(PyExc_TypeError, "Expected lp object");
419 talloc_free(s);
420 return NULL;
423 samdb = pyldb_Ldb_AsLdbContext(py_ldb);
424 if (samdb == NULL) {
425 PyErr_SetString(PyExc_TypeError, "Expected ldb object");
426 talloc_free(s);
427 return NULL;
430 s->drs_pipe = (dcerpc_InterfaceObject *)(py_drspipe);
432 s->vampire_state = libnet_vampire_replicate_init(s, samdb, lp);
433 if (s->vampire_state == NULL) {
434 PyErr_SetString(PyExc_TypeError, "Failed to initialise vampire_state");
435 talloc_free(s);
436 return NULL;
439 status = gensec_session_key(s->drs_pipe->pipe->conn->security_state.generic_state,
441 &s->gensec_skey);
442 if (!NT_STATUS_IS_OK(status)) {
443 PyErr_Format(PyExc_RuntimeError, "Unable to get session key from drspipe: %s",
444 nt_errstr(status));
445 talloc_free(s);
446 return NULL;
449 s->forest.dns_name = lpcfg_dnsdomain(lp);
451 s->chunk.gensec_skey = &s->gensec_skey;
452 s->chunk.partition = &s->partition;
453 s->chunk.forest = &s->forest;
454 s->chunk.dest_dsa = &s->dest_dsa;
456 return PyCObject_FromTallocPtr(s);
461 process one replication chunk
463 static PyObject *py_net_replicate_chunk(py_net_Object *self, PyObject *args, PyObject *kwargs)
465 const char *kwnames[] = { "state", "level", "ctr", "schema", NULL };
466 PyObject *py_state, *py_ctr, *py_schema;
467 struct replicate_state *s;
468 unsigned level;
469 NTSTATUS (*chunk_handler)(void *private_data, const struct libnet_BecomeDC_StoreChunk *c);
470 NTSTATUS status;
472 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OIO|O",
473 discard_const_p(char *, kwnames),
474 &py_state, &level, &py_ctr, &py_schema)) {
475 return NULL;
478 s = talloc_get_type(PyCObject_AsVoidPtr(py_state), struct replicate_state);
479 if (!s) {
480 PyErr_SetString(PyExc_TypeError, "Expected replication_state");
481 return NULL;
484 switch (level) {
485 case 1:
486 if (!py_check_dcerpc_type(py_ctr, "samba.dcerpc.drsuapi", "DsGetNCChangesCtr1")) {
487 return NULL;
489 s->chunk.ctr1 = py_talloc_get_ptr(py_ctr);
490 s->partition.nc = *s->chunk.ctr1->naming_context;
491 s->partition.more_data = s->chunk.ctr1->more_data;
492 s->partition.source_dsa_guid = s->chunk.ctr1->source_dsa_guid;
493 s->partition.source_dsa_invocation_id = s->chunk.ctr1->source_dsa_invocation_id;
494 s->partition.highwatermark = s->chunk.ctr1->new_highwatermark;
495 break;
496 case 6:
497 if (!py_check_dcerpc_type(py_ctr, "samba.dcerpc.drsuapi", "DsGetNCChangesCtr6")) {
498 return NULL;
500 s->chunk.ctr6 = py_talloc_get_ptr(py_ctr);
501 s->partition.nc = *s->chunk.ctr6->naming_context;
502 s->partition.more_data = s->chunk.ctr6->more_data;
503 s->partition.source_dsa_guid = s->chunk.ctr6->source_dsa_guid;
504 s->partition.source_dsa_invocation_id = s->chunk.ctr6->source_dsa_invocation_id;
505 s->partition.highwatermark = s->chunk.ctr6->new_highwatermark;
506 break;
507 default:
508 PyErr_Format(PyExc_TypeError, "Bad level %u in replicate_chunk", level);
509 return NULL;
512 chunk_handler = libnet_vampire_cb_store_chunk;
513 if (py_schema) {
514 if (!PyBool_Check(py_schema)) {
515 PyErr_SetString(PyExc_TypeError, "Expected boolean schema");
516 return NULL;
518 if (py_schema == Py_True) {
519 chunk_handler = libnet_vampire_cb_schema_chunk;
523 s->chunk.ctr_level = level;
525 status = chunk_handler(s->vampire_state, &s->chunk);
526 if (!NT_STATUS_IS_OK(status)) {
527 PyErr_Format(PyExc_TypeError, "Failed to process chunk: %s", nt_errstr(status));
528 return NULL;
531 Py_RETURN_NONE;
536 find a DC given a domain name and server type
538 static PyObject *py_net_finddc(py_net_Object *self, PyObject *args)
540 const char *domain_name;
541 unsigned server_type;
542 NTSTATUS status;
543 struct finddcs *io;
544 TALLOC_CTX *mem_ctx;
545 PyObject *ret;
547 if (!PyArg_ParseTuple(args, "sI", &domain_name, &server_type)) {
548 return NULL;
551 mem_ctx = talloc_new(self->mem_ctx);
553 io = talloc_zero(mem_ctx, struct finddcs);
554 io->in.domain_name = domain_name;
555 io->in.minimum_dc_flags = server_type;
557 status = finddcs_cldap(io, io,
558 lpcfg_resolve_context(self->libnet_ctx->lp_ctx), self->ev);
559 if (NT_STATUS_IS_ERR(status)) {
560 PyErr_SetString(PyExc_RuntimeError, nt_errstr(status));
561 talloc_free(mem_ctx);
562 return NULL;
565 ret = py_return_ndr_struct("samba.dcerpc.nbt", "NETLOGON_SAM_LOGON_RESPONSE_EX",
566 io, &io->out.netlogon.data.nt5_ex);
567 talloc_free(mem_ctx);
569 return ret;
573 static const char py_net_vampire_doc[] = "vampire(domain, target_dir=None)\n"
574 "Vampire a domain.";
576 static const char py_net_replicate_init_doc[] = "replicate_init(samdb, lp, drspipe)\n"
577 "Setup for replicate_chunk calls.";
579 static const char py_net_replicate_chunk_doc[] = "replicate_chunk(state, level, ctr, schema)\n"
580 "Process replication for one chunk";
582 static const char py_net_finddc_doc[] = "finddc(domain, server_type)\n"
583 "find a DC with the specified server_type bits. Return the DNS name";
585 static PyMethodDef net_obj_methods[] = {
586 {"join_member", (PyCFunction)py_net_join_member, METH_VARARGS|METH_KEYWORDS, py_net_join_member_doc},
587 {"change_password", (PyCFunction)py_net_change_password, METH_VARARGS|METH_KEYWORDS, py_net_change_password_doc},
588 {"set_password", (PyCFunction)py_net_set_password, METH_VARARGS|METH_KEYWORDS, py_net_set_password_doc},
589 {"export_keytab", (PyCFunction)py_net_export_keytab, METH_VARARGS|METH_KEYWORDS, py_net_export_keytab_doc},
590 {"time", (PyCFunction)py_net_time, METH_VARARGS|METH_KEYWORDS, py_net_time_doc},
591 {"create_user", (PyCFunction)py_net_user_create, METH_VARARGS|METH_KEYWORDS, py_net_create_user_doc},
592 {"delete_user", (PyCFunction)py_net_user_delete, METH_VARARGS|METH_KEYWORDS, py_net_delete_user_doc},
593 {"vampire", (PyCFunction)py_net_vampire, METH_VARARGS|METH_KEYWORDS, py_net_vampire_doc},
594 {"replicate_init", (PyCFunction)py_net_replicate_init, METH_VARARGS|METH_KEYWORDS, py_net_replicate_init_doc},
595 {"replicate_chunk", (PyCFunction)py_net_replicate_chunk, METH_VARARGS|METH_KEYWORDS, py_net_replicate_chunk_doc},
596 {"finddc", (PyCFunction)py_net_finddc, METH_VARARGS, py_net_finddc_doc},
597 { NULL }
600 static void py_net_dealloc(py_net_Object *self)
602 talloc_free(self->mem_ctx);
603 PyObject_Del(self);
606 static PyObject *net_obj_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
608 PyObject *py_creds, *py_lp = Py_None;
609 const char *kwnames[] = { "creds", "lp", "server", NULL };
610 py_net_Object *ret;
611 struct loadparm_context *lp;
612 const char *server_address = NULL;
614 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oz",
615 discard_const_p(char *, kwnames), &py_creds, &py_lp,
616 &server_address))
617 return NULL;
619 ret = PyObject_New(py_net_Object, type);
620 if (ret == NULL) {
621 return NULL;
624 /* FIXME: we really need to get a context from the caller or we may end
625 * up with 2 event contexts */
626 ret->ev = s4_event_context_init(NULL);
627 ret->mem_ctx = talloc_new(ret->ev);
629 lp = lpcfg_from_py_object(ret->mem_ctx, py_lp);
630 if (lp == NULL) {
631 Py_DECREF(ret);
632 return NULL;
635 ret->libnet_ctx = libnet_context_init(ret->ev, lp);
636 if (ret->libnet_ctx == NULL) {
637 PyErr_SetString(PyExc_RuntimeError, "Unable to initialize net");
638 Py_DECREF(ret);
639 return NULL;
642 ret->libnet_ctx->server_address = server_address;
644 ret->libnet_ctx->cred = cli_credentials_from_py_object(py_creds);
645 if (ret->libnet_ctx->cred == NULL) {
646 PyErr_SetString(PyExc_TypeError, "Expected credentials object");
647 Py_DECREF(ret);
648 return NULL;
651 return (PyObject *)ret;
655 PyTypeObject py_net_Type = {
656 PyObject_HEAD_INIT(NULL) 0,
657 .tp_name = "net.Net",
658 .tp_basicsize = sizeof(py_net_Object),
659 .tp_dealloc = (destructor)py_net_dealloc,
660 .tp_methods = net_obj_methods,
661 .tp_new = net_obj_new,
664 void initnet(void)
666 PyObject *m;
668 if (PyType_Ready(&py_net_Type) < 0)
669 return;
671 m = Py_InitModule3("net", NULL, NULL);
672 if (m == NULL)
673 return;
675 Py_INCREF(&py_net_Type);
676 PyModule_AddObject(m, "Net", (PyObject *)&py_net_Type);
677 PyModule_AddObject(m, "LIBNET_JOINDOMAIN_AUTOMATIC", PyInt_FromLong(LIBNET_JOINDOMAIN_AUTOMATIC));
678 PyModule_AddObject(m, "LIBNET_JOINDOMAIN_SPECIFIED", PyInt_FromLong(LIBNET_JOINDOMAIN_SPECIFIED));
679 PyModule_AddObject(m, "LIBNET_JOIN_AUTOMATIC", PyInt_FromLong(LIBNET_JOIN_AUTOMATIC));
680 PyModule_AddObject(m, "LIBNET_JOIN_SPECIFIED", PyInt_FromLong(LIBNET_JOIN_SPECIFIED));