diff options
author | Andrew Bartlett <abartlet@samba.org> | 2008-04-09 12:03:36 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2008-04-09 12:03:36 +1000 |
commit | 5eda5e5197cce82ada6172e5246844f8b81dd1aa (patch) | |
tree | 3ea79faabf5627d167f11d63e9afddbde4253882 /source4/libnet/py_net.c | |
parent | 2f8ac9a4221e4b7731422bd2ce05e59b5d75fb0a (diff) | |
parent | 5c3e4797b68a6ecffd2eeafe1152da1f3cea344d (diff) | |
download | samba-5eda5e5197cce82ada6172e5246844f8b81dd1aa.tar.gz samba-5eda5e5197cce82ada6172e5246844f8b81dd1aa.tar.bz2 samba-5eda5e5197cce82ada6172e5246844f8b81dd1aa.zip |
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into 4-0-abartlet
(This used to be commit 58e00594d8c191f499225aa2755a06bac2937300)
Diffstat (limited to 'source4/libnet/py_net.c')
-rw-r--r-- | source4/libnet/py_net.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c new file mode 100644 index 0000000000..2fcbc5d156 --- /dev/null +++ b/source4/libnet/py_net.c @@ -0,0 +1,77 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include <Python.h> +#include "libnet.h" +#include "param/param.h" +#include "libcli/security/security.h" + +struct libnet_context *py_net_ctx(PyObject *obj) +{ + /* FIXME: Use obj */ + return libnet_context_init(NULL, global_loadparm); +} + +static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs) +{ + struct libnet_Join r; + NTSTATUS status; + PyObject *result; + TALLOC_CTX *mem_ctx; + struct libnet_context *libnet_ctx; + const char *kwnames[] = { "domain_name", "netbios_name", "join_type", "level", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ssii:Join", discard_const_p(char *, kwnames), + &r.in.domain_name, &r.in.netbios_name, + &r.in.join_type, &r.in.level)) + return NULL; + + mem_ctx = talloc_new(NULL); + + libnet_ctx = py_net_ctx(cls); + + status = libnet_Join(libnet_ctx, mem_ctx, &r); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetString(PyExc_RuntimeError, r.out.error_string); + talloc_free(mem_ctx); + return NULL; + } + + result = Py_BuildValue("sss", r.out.join_password, + dom_sid_string(mem_ctx, r.out.domain_sid), + r.out.domain_name); + + talloc_free(mem_ctx); + + if (result == NULL) + return NULL; + + return result; +} + +static struct PyMethodDef net_methods[] = { + {"Join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS}, + {NULL } +}; + +void initnet(void) +{ + Py_InitModule("net", net_methods); +} |